Skip to content

Commit

Permalink
Merge branch 'main' into qs-dev3-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightjl authored Sep 29, 2023
2 parents de32def + 50cbc67 commit 68bc74a
Show file tree
Hide file tree
Showing 91 changed files with 3,351 additions and 2,735 deletions.
Binary file modified public/images/chainlink-functions/requestAndReceive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/chainlink-functions/subscription/addConsumer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";

/**
* @title Functions contract used for Automation.
* @notice This contract is a demonstration of using Functions and Automation.
* @notice NOT FOR PRODUCTION USE
*/
contract AutomatedFunctionsConsumerExample is FunctionsClient, ConfirmedOwner {
address public upkeepContract;
bytes public request;
uint64 public subscriptionId;
uint32 public gasLimit;
bytes32 public jobId;
bytes32 public s_lastRequestId;
bytes public s_lastResponse;
bytes public s_lastError;

error NotAllowedCaller(
address caller,
address owner,
address automationRegistry
);
error UnexpectedRequestID(bytes32 requestId);

event Response(bytes32 indexed requestId, bytes response, bytes err);

constructor(
address router
) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

/**
* @notice Reverts if called by anyone other than the contract owner or automation registry.
*/
modifier onlyAllowed() {
if (msg.sender != owner() && msg.sender != upkeepContract)
revert NotAllowedCaller(msg.sender, owner(), upkeepContract);
_;
}

function setAutomationCronContract(
address _upkeepContract
) external onlyOwner {
upkeepContract = _upkeepContract;
}

/// @notice Update the request settings
/// @dev Only callable by the owner of the contract
/// @param _request The new encoded CBOR request to be set. The request is encoded off-chain
/// @param _subscriptionId The new subscription ID to be set
/// @param _gasLimit The new gas limit to be set
/// @param _jobId The new job ID to be set
function updateRequest(
bytes memory _request,
uint64 _subscriptionId,
uint32 _gasLimit,
bytes32 _jobId
) external onlyOwner {
request = _request;
subscriptionId = _subscriptionId;
gasLimit = _gasLimit;
jobId = _jobId;
}

/**
* @notice Send a pre-encoded CBOR request
* @return requestId The ID of the sent request
*/
function sendRequestCBOR()
external
onlyAllowed
returns (bytes32 requestId)
{
s_lastRequestId = _sendRequest(
request,
subscriptionId,
gasLimit,
jobId
);
return s_lastRequestId;
}

/**
* @notice Store latest result/error
* @param requestId The request ID, returned by sendRequest()
* @param response Aggregated response from the user code
* @param err Aggregated error from the user code or from the execution pipeline
* Either response or error parameter will be set, but never both
*/
function fulfillRequest(
bytes32 requestId,
bytes memory response,
bytes memory err
) internal override {
if (s_lastRequestId != requestId) {
revert UnexpectedRequestID(requestId);
}
s_lastResponse = response;
s_lastError = err;
emit Response(requestId, s_lastResponse, s_lastError);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol";
import {AutomationCompatibleInterface} from "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";

/**
* @title Functions contract used for Automation.
* @notice This contract is a demonstration of using Functions and Automation.
* @notice NOT FOR PRODUCTION USE
*/
contract CustomAutomatedFunctionsConsumerExample is
FunctionsClient,
AutomationCompatibleInterface,
ConfirmedOwner
{
uint256 public lastBlockNumber;
bytes public request;
uint64 public subscriptionId;
uint32 public gasLimit;
bytes32 public jobId;
bytes32 public s_lastRequestId;
bytes public s_lastResponse;
bytes public s_lastError;

error UnexpectedRequestID(bytes32 requestId);

event Response(bytes32 indexed requestId, bytes response, bytes err);

constructor(
address router
) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

/**
* @notice Checks if upkeep is needed based on the difference between the current and the last block number.
* @dev This function checks if the current block number has incremented since the last recorded block number and returns a boolean indicating if upkeep is needed.
* @return upkeepNeeded A boolean indicating if upkeep is needed (true if the current block number has incremented since the last recorded block number).
* @return performData An empty bytes value since no additional data is needed for the upkeep in this implementation.
*/
function checkUpkeep(
bytes calldata /* checkData */
)
external
view
override
returns (bool upkeepNeeded, bytes memory performData)
{
upkeepNeeded = block.number - lastBlockNumber > 0; // Check if the current block number has incremented since the last recorded block number
// We don't use the checkData in this example. The checkData is defined when the Upkeep was registered.
return (upkeepNeeded, ""); // Return an empty bytes value for performData
}

/**
* @notice Send a pre-encoded CBOR request if the current block number has incremented since the last recorded block number.
* @dev We highly recommend revalidating the upkeep in the performUpkeep function. The performData is generated by the Automation Node's call to your checkUpkeep function and is not used in this implementation.
*/
function performUpkeep(bytes calldata /* performData */) external override {
//We highly recommend revalidating the upkeep in the performUpkeep function
if (block.number - lastBlockNumber > 0) {
s_lastRequestId = _sendRequest(
request,
subscriptionId,
gasLimit,
jobId
);
lastBlockNumber = block.number;
}
// We don't use the performData in this example. The performData is generated by the Automation Node's call to your checkUpkeep function
}

/// @notice Update the request settings
/// @dev Only callable by the owner of the contract
/// @param _request The new encoded CBOR request to be set. The request is encoded off-chain
/// @param _subscriptionId The new subscription ID to be set
/// @param _gasLimit The new gas limit to be set
/// @param _jobId The new job ID to be set
function updateRequest(
bytes memory _request,
uint64 _subscriptionId,
uint32 _gasLimit,
bytes32 _jobId
) external onlyOwner {
request = _request;
subscriptionId = _subscriptionId;
gasLimit = _gasLimit;
jobId = _jobId;
}

/**
* @notice Store latest result/error
* @param requestId The request ID, returned by sendRequest()
* @param response Aggregated response from the user code
* @param err Aggregated error from the user code or from the execution pipeline
* Either response or error parameter will be set, but never both
*/
function fulfillRequest(
bytes32 requestId,
bytes memory response,
bytes memory err
) internal override {
if (s_lastRequestId != requestId) {
revert UnexpectedRequestID(requestId);
}
s_lastResponse = response;
s_lastError = err;
emit Response(requestId, s_lastResponse, s_lastError);
}
}
112 changes: 112 additions & 0 deletions public/samples/ChainlinkFunctions/FunctionsConsumerExample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {FunctionsClient} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/FunctionsClient.sol";
import {ConfirmedOwner} from "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
import {FunctionsRequest} from "@chainlink/contracts/src/v0.8/functions/dev/v1_0_0/libraries/FunctionsRequest.sol";

/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/
contract FunctionsConsumerExample is FunctionsClient, ConfirmedOwner {
using FunctionsRequest for FunctionsRequest.Request;

bytes32 public s_lastRequestId;
bytes public s_lastResponse;
bytes public s_lastError;

error UnexpectedRequestID(bytes32 requestId);

event Response(bytes32 indexed requestId, bytes response, bytes err);

constructor(
address router
) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

/**
* @notice Send a simple request
* @param source JavaScript source code
* @param encryptedSecretsUrls Encrypted URLs where to fetch user secrets
* @param donHostedSecretsSlotID Don hosted secrets slotId
* @param donHostedSecretsVersion Don hosted secrets version
* @param args List of arguments accessible from within the source code
* @param bytesArgs Array of bytes arguments, represented as hex strings
* @param subscriptionId Billing ID
*/
function sendRequest(
string memory source,
bytes memory encryptedSecretsUrls,
uint8 donHostedSecretsSlotID,
uint64 donHostedSecretsVersion,
string[] memory args,
bytes[] memory bytesArgs,
uint64 subscriptionId,
uint32 gasLimit,
bytes32 jobId
) external onlyOwner returns (bytes32 requestId) {
FunctionsRequest.Request memory req;
req.initializeRequestForInlineJavaScript(source);
if (encryptedSecretsUrls.length > 0)
req.addSecretsReference(encryptedSecretsUrls);
else if (donHostedSecretsVersion > 0) {
req.addDONHostedSecrets(
donHostedSecretsSlotID,
donHostedSecretsVersion
);
}
if (args.length > 0) req.setArgs(args);
if (bytesArgs.length > 0) req.setBytesArgs(bytesArgs);
s_lastRequestId = _sendRequest(
req.encodeCBOR(),
subscriptionId,
gasLimit,
jobId
);
return s_lastRequestId;
}

/**
* @notice Send a pre-encoded CBOR request
* @param request CBOR-encoded request data
* @param subscriptionId Billing ID
* @param gasLimit The maximum amount of gas the request can consume
* @param jobId ID of the job to be invoked
* @return requestId The ID of the sent request
*/
function sendRequestCBOR(
bytes memory request,
uint64 subscriptionId,
uint32 gasLimit,
bytes32 jobId
) external onlyOwner returns (bytes32 requestId) {
s_lastRequestId = _sendRequest(
request,
subscriptionId,
gasLimit,
jobId
);
return s_lastRequestId;
}

/**
* @notice Store latest result/error
* @param requestId The request ID, returned by sendRequest()
* @param response Aggregated response from the user code
* @param err Aggregated error from the user code or from the execution pipeline
* Either response or error parameter will be set, but never both
*/
function fulfillRequest(
bytes32 requestId,
bytes memory response,
bytes memory err
) internal override {
if (s_lastRequestId != requestId) {
revert UnexpectedRequestID(requestId);
}
s_lastResponse = response;
s_lastError = err;
emit Response(requestId, s_lastResponse, s_lastError);
}
}
22 changes: 11 additions & 11 deletions src/config/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ export const MENU: MenuItems = {
section: "dataFeeds",
},
{
text: "VRF",
link: "/vrf/v2/introduction",
section: "vrf",
},
{
text: "Automation",
link: "/chainlink-automation/introduction",
section: "automation",
text: "Functions",
link: "/chainlink-functions",
section: "chainlinkFunctions",
},
{
text: "CCIP",
link: "/ccip",
section: "ccip",
},
{
text: "Functions",
link: "/chainlink-functions",
section: "chainlinkFunctions",
text: "Automation",
link: "/chainlink-automation/introduction",
section: "automation",
},
{
text: "VRF",
link: "/vrf/v2/introduction",
section: "vrf",
},
{
text: "Nodes",
Expand Down
Loading

0 comments on commit 68bc74a

Please sign in to comment.