Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8b17106
add ccip contracts package and update copyArtifacts script
koteld Feb 27, 2024
0fdd242
add CCIP Router artifact as external artifact
koteld Feb 27, 2024
ed72913
add CCIP routers to the registry
koteld Feb 27, 2024
91a5046
update networks registry: add ccip chain selector, add new networks
koteld Feb 27, 2024
45a89e4
add wrapper for CCIP router contract
koteld Feb 27, 2024
0778377
update HRE with CCIP router class, code refactoring
koteld Feb 27, 2024
210d7a6
update service files with CCIP router functionality
koteld Feb 27, 2024
afbedfe
update inquirers and interactive registries
koteld Feb 27, 2024
79b06fa
update hardhat tasks and subtasks with CCIP router functionality
koteld Feb 27, 2024
8eb0a6f
bump package version to 0.0.5
koteld Feb 27, 2024
b87fffe
add gas estimation for CCIP Receiver
koteld Mar 13, 2024
b4f774a
add hardhat-toolbox to project dependencies
koteld Mar 26, 2024
6bc4e2d
add SimpleCCIPReceiver.sol as example CCIP Receiver contract
koteld Mar 26, 2024
f4e3c3c
introduce CCIP Receiver module in sandbox
koteld Mar 26, 2024
6da7e60
add types associated with CCIP Receiver
koteld Mar 26, 2024
d449de5
update inquirers so it can handle boolean variables in more convenien…
koteld Mar 26, 2024
8d555ea
add CCIP Receiver module to Hardhat Extended Environment as Sandbox s…
koteld Mar 26, 2024
11f4570
introduce tasks for CCIP Receiver module
koteld Mar 26, 2024
6411ba4
update tasks helpers in order to handle boolean values
koteld Mar 26, 2024
a3c40a9
add CCIP Receiver tasks description as subtasks
koteld Mar 26, 2024
aa85bc9
register CCIP Receiver module as subtasks
koteld Mar 26, 2024
522a088
update package.json
koteld May 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions contracts/SimpleCCIPReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {CCIPReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/applications/CCIPReceiver.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.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.
*/

/// @title - A simple contract for receiving string data across chains.
contract SimpleCCIPReceiver is CCIPReceiver, OwnerIsCreator {
error SourceChainNotAllowed(uint64 sourceChainSelector); // Used when the source chain has not been allowlisted by the contract owner.
error SenderNotAllowed(address sender); // Used when the sender has not been allowlisted by the contract owner.

// Event emitted when a message is received from another chain.
event MessageReceived(
bytes32 indexed messageId, // The unique ID of the message.
uint64 indexed sourceChainSelector, // The chain selector of the source chain.
address sender, // The address of the sender from the source chain.
uint256 iterationsInput, // The number of iterations to be executed.
uint256 iterationsDone, // The number of iterations executed.
uint256 result // The result of the iterations.
);

// Mapping to keep track of allowlisted source chains.
mapping(uint64 => bool) public allowlistedSourceChains;

// Mapping to keep track of allowlisted senders.
mapping(address => bool) public allowlistedSenders;

/// @dev Modifier that checks if the chain with the given sourceChainSelector is allowlisted and if the sender is allowlisted.
/// @param _sourceChainSelector The selector of the destination chain.
/// @param _sender The address of the sender.
modifier onlyAllowlisted(uint64 _sourceChainSelector, address _sender) {
if (!allowlistedSourceChains[_sourceChainSelector])
revert SourceChainNotAllowed(_sourceChainSelector);
if (!allowlistedSenders[_sender]) revert SenderNotAllowed(_sender);
_;
}

/// @notice Constructor initializes the contract with the router address.
/// @param router The address of the router contract.
constructor(address router) CCIPReceiver(router) {}

/// @dev Updates the allowlist status of a source chain
/// @notice This function can only be called by the owner.
/// @param _sourceChainSelector The selector of the source chain to be updated.
/// @param allowed The allowlist status to be set for the source chain.
function allowlistSourceChain(
uint64 _sourceChainSelector,
bool allowed
) external onlyOwner {
allowlistedSourceChains[_sourceChainSelector] = allowed;
}

/// @dev Updates the allowlist status of a sender for transactions.
/// @notice This function can only be called by the owner.
/// @param _sender The address of the sender to be updated.
/// @param allowed The allowlist status to be set for the sender.
function allowlistSender(address _sender, bool allowed) external onlyOwner {
allowlistedSenders[_sender] = allowed;
}

/// handle a received message
function _ccipReceive(
Client.Any2EVMMessage memory any2EvmMessage
) internal override {
uint256 iterations = abi.decode(any2EvmMessage.data, (uint256)); // abi-decoding of the receiver number of iterations

uint256 result = iterations;
uint256 maxIterations = iterations % 100;
for (uint256 i = 0; i < maxIterations; i++) {
result += i;
}

emit MessageReceived(
any2EvmMessage.messageId, // fetch the message id
any2EvmMessage.sourceChainSelector, // fetch the source chain identifier (aka selector)
abi.decode(any2EvmMessage.sender, (address)), // abi-decoding of the sender address,
iterations, // the number of iterations
maxIterations, // the number of iterations executed
result // the result of the iterations
);
}
}
2 changes: 2 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const config: HardhatUserConfig = {
"./chainlink-artifacts/TypeAndVersionInterface.json",
"./chainlink-artifacts/OptimismSequencerUptimeFeed.json",
"./chainlink-artifacts/VRFCoordinatorV2.json",
"./chainlink-artifacts/Router.json",
"./chainlink-artifacts/CCIPReceiver.json",
],
},
};
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chainlink/hardhat-chainlink",
"version": "0.0.4",
"version": "0.0.5",
"description": "Hardhat plugin that adds interaction with Chainlink services to Hardhat projects",
"repository": "https://github.com/smartcontractkit/hardhat-chainlink.git",
"license": "MIT",
Expand All @@ -26,8 +26,8 @@
"test:automationRegistry": "mocha --exit 'test/automationRegistry.test.ts'",
"test:functions": "mocha --exit 'test/functionsRouter.test.ts'",
"test:functionsSimulation": "mocha --exit 'test/functionsSimulation.test.ts'",
"test": "yarn test:prepare && yarn test:dataFeed && yarn test:dataFeedProxy && yarn test:ensFeedsResolver && yarn test:feedRegistry && yarn test:l2FeedUptimeSequencer && yarn test:vrfCoordinator && yarn test:automationRegistrar && yarn test:automationRegistry && yarn test:functions",
"copyArtifacts": "copyfiles -a -f ./node_modules/@chainlink/contracts/abi/**/* chainlink-artifacts",
"test": "yarn test:prepare && yarn test:dataFeed && yarn test:dataFeedProxy && yarn test:ensFeedsResolver && yarn test:feedRegistry && yarn test:vrfCoordinator && yarn test:automationRegistrar && yarn test:automationRegistry && yarn test:functions",
"copyArtifacts": "copyfiles -a -f ./node_modules/@chainlink/contracts/abi/**/* ./node_modules/@chainlink/contracts-ccip/abi/**/* chainlink-artifacts",
"removeArtifacts": "rm -rf chainlink-artifacts",
"compile": "hardhat compile",
"prebuild": "npm run copyArtifacts && npm run compile && npm run removeArtifacts",
Expand All @@ -44,7 +44,7 @@
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "1.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.8",
"@nomicfoundation/hardhat-toolbox": "2.0.2",
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.1.7",
"@typechain/ethers-v5": "^10.1.1",
"@typechain/hardhat": "^6.1.6",
Expand All @@ -55,7 +55,7 @@
"chai-as-promised": "^7.1.1",
"copyfiles": "^2.4.1",
"hardhat": "^2.17.3",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-gas-reporter": "^1.0.8",
"mocha": "^10.2.0",
"mocha-suppress-logs": "^0.3.1",
"prettier": "^2.8.8",
Expand All @@ -69,6 +69,7 @@
},
"dependencies": {
"@chainlink/contracts": "0.8.0",
"@chainlink/contracts-ccip": "1.2.1",
"@chainlink/functions-toolkit": "0.2.6",
"@inquirer/confirm": "^2.0.6",
"@inquirer/input": "^1.2.5",
Expand Down
Loading