Skip to content

Commit

Permalink
Copy contracts over from ccip
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Aug 28, 2024
1 parent 2a0662a commit 7341b06
Show file tree
Hide file tree
Showing 42 changed files with 1,449 additions and 244 deletions.
35 changes: 23 additions & 12 deletions contracts/src/v0.8/ccip/FeeQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
}

/// @inheritdoc IPriceRegistry
function getTokenPrices(
address[] calldata tokens
) external view override returns (Internal.TimestampedPackedUint224[] memory) {
function getTokenPrices(address[] calldata tokens)
external
view
override
returns (Internal.TimestampedPackedUint224[] memory)
{
uint256 length = tokens.length;
Internal.TimestampedPackedUint224[] memory tokenPrices = new Internal.TimestampedPackedUint224[](length);
for (uint256 i = 0; i < length; ++i) {
Expand All @@ -253,16 +256,22 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
}

/// @inheritdoc IFeeQuoter
function getTokenPriceFeedConfig(
address token
) external view override returns (IFeeQuoter.TokenPriceFeedConfig memory) {
function getTokenPriceFeedConfig(address token)
external
view
override
returns (IFeeQuoter.TokenPriceFeedConfig memory)
{
return s_usdPriceFeedsPerToken[token];
}

/// @inheritdoc IPriceRegistry
function getDestinationChainGasPrice(
uint64 destChainSelector
) external view override returns (Internal.TimestampedPackedUint224 memory) {
function getDestinationChainGasPrice(uint64 destChainSelector)
external
view
override
returns (Internal.TimestampedPackedUint224 memory)
{
return s_usdPerUnitGasByDestChainSelector[destChainSelector];
}

Expand Down Expand Up @@ -310,9 +319,11 @@ contract FeeQuoter is AuthorizedCallers, IFeeQuoter, ITypeAndVersion, IReceiver,
/// @notice Gets the token price from a data feed address, rebased to the same units as s_usdPerToken
/// @param priceFeedConfig token data feed configuration with valid data feed address (used to retrieve price & timestamp)
/// @return tokenPrice data feed price answer rebased to s_usdPerToken units, with latest block timestamp
function _getTokenPriceFromDataFeed(
IFeeQuoter.TokenPriceFeedConfig memory priceFeedConfig
) internal view returns (Internal.TimestampedPackedUint224 memory tokenPrice) {
function _getTokenPriceFromDataFeed(IFeeQuoter.TokenPriceFeedConfig memory priceFeedConfig)
internal
view
returns (Internal.TimestampedPackedUint224 memory tokenPrice)
{
AggregatorV3Interface dataFeedContract = AggregatorV3Interface(priceFeedConfig.dataFeedAddress);
(
/* uint80 roundID */
Expand Down
8 changes: 5 additions & 3 deletions contracts/src/v0.8/ccip/MultiAggregateRateLimiter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ contract MultiAggregateRateLimiter is IMessageInterceptor, AuthorizedCallers, IT
/// @param remoteChainSelector chain selector to get rate limit tokens for.
/// @return localTokens The local chain representation of the tokens that are rate limited.
/// @return remoteTokens The remote representation of the tokens that are rate limited.
function getAllRateLimitTokens(
uint64 remoteChainSelector
) external view returns (address[] memory localTokens, bytes[] memory remoteTokens) {
function getAllRateLimitTokens(uint64 remoteChainSelector)
external
view
returns (address[] memory localTokens, bytes[] memory remoteTokens)
{
uint256 tokenCount = s_rateLimitedTokensLocalToRemote[remoteChainSelector].length();

localTokens = new address[](tokenCount);
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/v0.8/ccip/RMN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,11 @@ contract RMN is IRMN, OwnerIsCreator, ITypeAndVersion {
/// @return accumulatedWeight sum of weights of voters, will be zero if voting took place with an older config version
/// @return blessed will be accurate regardless of when voting took place
/// @dev This is a helper method for offchain code so efficiency is not really a concern.
function getBlessProgress(
IRMN.TaggedRoot calldata taggedRoot
) external view returns (address[] memory blessVoteAddrs, uint16 accumulatedWeight, bool blessed) {
function getBlessProgress(IRMN.TaggedRoot calldata taggedRoot)
external
view
returns (address[] memory blessVoteAddrs, uint16 accumulatedWeight, bool blessed)
{
bytes32 taggedRootHash = _taggedRootHash(taggedRoot);
BlessVoteProgress memory progress = s_blessVoteProgressByTaggedRootHash[taggedRootHash];
blessed = progress.weightThresholdMet;
Expand All @@ -760,9 +762,7 @@ contract RMN is IRMN, OwnerIsCreator, ITypeAndVersion {
/// @return cursed might be true even if the owner has no active vote and accumulatedWeight < curseWeightThreshold,
/// due to a retained curse from a prior config
/// @dev This is a helper method for offchain code so efficiency is not really a concern.
function getCurseProgress(
bytes16 subject
)
function getCurseProgress(bytes16 subject)
external
view
returns (address[] memory curseVoteAddrs, bytes28[] memory cursesHashes, uint16 accumulatedWeight, bool cursed)
Expand Down
10 changes: 7 additions & 3 deletions contracts/src/v0.8/ccip/applications/CCIPClientExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ contract CCIPClientExample is CCIPReceiver, OwnerIsCreator {
delete s_chains[chainSelector];
}

function ccipReceive(
Client.Any2EVMMessage calldata message
) external virtual override onlyRouter validChain(message.sourceChainSelector) {
function ccipReceive(Client.Any2EVMMessage calldata message)
external
virtual
override
onlyRouter
validChain(message.sourceChainSelector)
{
// Extremely important to ensure only router calls this.
// Tokens in message if any will be transferred to this contract
// TODO: Validate sender/origin chain and process message and/or tokens.
Expand Down
17 changes: 11 additions & 6 deletions contracts/src/v0.8/ccip/applications/DefensiveExample.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ contract DefensiveExample is CCIPClientExample {
/// never revert, all errors should be handled internally in this contract.
/// @param message The message to process.
/// @dev Extremely important to ensure only router calls this.
function ccipReceive(
Client.Any2EVMMessage calldata message
) external override onlyRouter validChain(message.sourceChainSelector) {
function ccipReceive(Client.Any2EVMMessage calldata message)
external
override
onlyRouter
validChain(message.sourceChainSelector)
{
try this.processMessage(message) {}
catch (bytes memory err) {
// Could set different error codes based on the caught error. Each could be
Expand All @@ -67,9 +70,11 @@ contract DefensiveExample is CCIPClientExample {
/// @dev This example just sends the tokens to the owner of this contracts. More
/// interesting functions could be implemented.
/// @dev It has to be external because of the try/catch.
function processMessage(
Client.Any2EVMMessage calldata message
) external onlySelf validChain(message.sourceChainSelector) {
function processMessage(Client.Any2EVMMessage calldata message)
external
onlySelf
validChain(message.sourceChainSelector)
{
// Simulate a revert
if (s_simRevert) revert ErrorCase();

Expand Down
8 changes: 5 additions & 3 deletions contracts/src/v0.8/ccip/applications/EtherSenderReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ contract EtherSenderReceiver is CCIPReceiver, ITypeAndVersion {
/// @notice Validate the message content.
/// @dev Only allows a single token to be sent. Always overwritten to be address(i_weth)
/// and receiver is always msg.sender.
function _validatedMessage(
Client.EVM2AnyMessage calldata message
) internal view returns (Client.EVM2AnyMessage memory) {
function _validatedMessage(Client.EVM2AnyMessage calldata message)
internal
view
returns (Client.EVM2AnyMessage memory)
{
Client.EVM2AnyMessage memory validatedMessage = message;

if (validatedMessage.tokenAmounts.length != 1) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/applications/PingPongDemo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ contract PingPongDemo is CCIPReceiver, OwnerIsCreator, ITypeAndVersion {
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: Client._argsToBytes(
Client.EVMExtraArgsV2({gasLimit: uint256(DEFAULT_GAS_LIMIT), allowOutOfOrderExecution: s_outOfOrderExecution})
),
),
feeToken: address(s_feeToken)
});
IRouterClient(getRouter()).ccipSend(s_counterpartChainSelector, message);
Expand Down
4 changes: 1 addition & 3 deletions contracts/src/v0.8/ccip/capability/CCIPConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,7 @@ contract CCIPConfig is ITypeAndVersion, ICapabilityConfiguration, OwnerIsCreator
/// @param ocr3Configs The OCR3 configurations to group.
/// @return commitConfigs The commit configurations.
/// @return execConfigs The execution configurations.
function _groupByPluginType(
CCIPConfigTypes.OCR3Config[] memory ocr3Configs
)
function _groupByPluginType(CCIPConfigTypes.OCR3Config[] memory ocr3Configs)
internal
pure
returns (CCIPConfigTypes.OCR3Config[] memory commitConfigs, CCIPConfigTypes.OCR3Config[] memory execConfigs)
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/v0.8/ccip/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ interface IPoolV1 is IERC165 {
/// @notice Lock tokens into the pool or burn the tokens.
/// @param lockOrBurnIn Encoded data fields for the processing of tokens on the source chain.
/// @return lockOrBurnOut Encoded data fields for the processing of tokens on the destination chain.
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external returns (Pool.LockOrBurnOutV1 memory lockOrBurnOut);
function lockOrBurn(Pool.LockOrBurnInV1 calldata lockOrBurnIn)
external
returns (Pool.LockOrBurnOutV1 memory lockOrBurnOut);

/// @notice Releases or mints tokens to the receiver address.
/// @param releaseOrMintIn All data required to release or mint tokens.
/// @return releaseOrMintOut The amount of tokens released or minted on the local chain, denominated
/// in the local token's decimals.
/// @dev The offramp asserts that the balanceOf of the receiver has been incremented by exactly the number
/// of tokens that is returned in ReleaseOrMintOutV1.destinationAmount. If the amounts do not match, the tx reverts.
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external returns (Pool.ReleaseOrMintOutV1 memory);
function releaseOrMint(Pool.ReleaseOrMintInV1 calldata releaseOrMintIn)
external
returns (Pool.ReleaseOrMintOutV1 memory);

/// @notice Checks whether a remote chain is supported in the token pool.
/// @param remoteChainSelector The selector of the remote chain.
Expand Down
7 changes: 4 additions & 3 deletions contracts/src/v0.8/ccip/interfaces/IPriceRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ interface IPriceRegistry {
/// PriceRegistry does not contain chain-specific logic to parse destination chain price components.
/// @param destChainSelector The destination chain to get the price for.
/// @return gasPrice The encoded gasPrice for the given destination chain ID.
function getDestinationChainGasPrice(
uint64 destChainSelector
) external view returns (Internal.TimestampedPackedUint224 memory);
function getDestinationChainGasPrice(uint64 destChainSelector)
external
view
returns (Internal.TimestampedPackedUint224 memory);

/// @notice Gets the fee token price and the gas price, both denominated in dollars.
/// @param token The source token to get the price for.
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
uint64 indexed sourceChainSelector,
uint64 indexed sequenceNumber,
bytes32 indexed messageId,
bytes32 messageHash,
Internal.MessageExecutionState state,
bytes returnData,
uint256 gasUsed
Expand Down Expand Up @@ -473,6 +474,7 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
sourceChainSelector,
message.header.sequenceNumber,
message.header.messageId,
hashedLeaves[i],
newState,
returnData,
gasStart - gasleft()
Expand Down
8 changes: 5 additions & 3 deletions contracts/src/v0.8/ccip/onRamp/EVM2EVMOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,11 @@ contract EVM2EVMOnRamp is IEVM2AnyOnRamp, ILinkAvailable, AggregateRateLimiter,
}

/// @notice Gets the transfer fee config for a given token.
function getTokenTransferFeeConfig(
address token
) external view returns (TokenTransferFeeConfig memory tokenTransferFeeConfig) {
function getTokenTransferFeeConfig(address token)
external
view
returns (TokenTransferFeeConfig memory tokenTransferFeeConfig)
{
return s_tokenTransferFeeConfig[token];
}

Expand Down
18 changes: 12 additions & 6 deletions contracts/src/v0.8/ccip/pools/BurnMintTokenPoolAbstract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ abstract contract BurnMintTokenPoolAbstract is TokenPool {

/// @notice Burn the token in the pool
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
function lockOrBurn(Pool.LockOrBurnInV1 calldata lockOrBurnIn)
external
virtual
override
returns (Pool.LockOrBurnOutV1 memory)
{
_validateLockOrBurn(lockOrBurnIn);

_burn(lockOrBurnIn.amount);
Expand All @@ -28,9 +31,12 @@ abstract contract BurnMintTokenPoolAbstract is TokenPool {

/// @notice Mint tokens from the pool to the recipient
/// @dev The _validateReleaseOrMint check is an essential security check
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
function releaseOrMint(Pool.ReleaseOrMintInV1 calldata releaseOrMintIn)
external
virtual
override
returns (Pool.ReleaseOrMintOutV1 memory)
{
_validateReleaseOrMint(releaseOrMintIn);

// Mint to the receiver
Expand Down
18 changes: 12 additions & 6 deletions contracts/src/v0.8/ccip/pools/BurnMintTokenPoolAndProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ contract BurnMintTokenPoolAndProxy is ITypeAndVersion, LegacyPoolWrapper {

/// @notice Burn the token in the pool
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
function lockOrBurn(Pool.LockOrBurnInV1 calldata lockOrBurnIn)
external
virtual
override
returns (Pool.LockOrBurnOutV1 memory)
{
_validateLockOrBurn(lockOrBurnIn);

if (!_hasLegacyPool()) {
Expand All @@ -37,9 +40,12 @@ contract BurnMintTokenPoolAndProxy is ITypeAndVersion, LegacyPoolWrapper {

/// @notice Mint tokens from the pool to the recipient
/// @dev The _validateReleaseOrMint check is an essential security check
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
function releaseOrMint(Pool.ReleaseOrMintInV1 calldata releaseOrMintIn)
external
virtual
override
returns (Pool.ReleaseOrMintOutV1 memory)
{
_validateReleaseOrMint(releaseOrMintIn);

if (!_hasLegacyPool()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ contract BurnWithFromMintTokenPoolAndProxy is ITypeAndVersion, LegacyPoolWrapper

/// @notice Burn the token in the pool
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
function lockOrBurn(Pool.LockOrBurnInV1 calldata lockOrBurnIn)
external
virtual
override
returns (Pool.LockOrBurnOutV1 memory)
{
_validateLockOrBurn(lockOrBurnIn);

if (!_hasLegacyPool()) {
Expand All @@ -45,9 +48,12 @@ contract BurnWithFromMintTokenPoolAndProxy is ITypeAndVersion, LegacyPoolWrapper

/// @notice Mint tokens from the pool to the recipient
/// @dev The _validateReleaseOrMint check is an essential security check
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
function releaseOrMint(Pool.ReleaseOrMintInV1 calldata releaseOrMintIn)
external
virtual
override
returns (Pool.ReleaseOrMintOutV1 memory)
{
_validateReleaseOrMint(releaseOrMintIn);

if (!_hasLegacyPool()) {
Expand Down
18 changes: 12 additions & 6 deletions contracts/src/v0.8/ccip/pools/LockReleaseTokenPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion

/// @notice Locks the token in the pool
/// @dev The _validateLockOrBurn check is an essential security check
function lockOrBurn(
Pool.LockOrBurnInV1 calldata lockOrBurnIn
) external virtual override returns (Pool.LockOrBurnOutV1 memory) {
function lockOrBurn(Pool.LockOrBurnInV1 calldata lockOrBurnIn)
external
virtual
override
returns (Pool.LockOrBurnOutV1 memory)
{
_validateLockOrBurn(lockOrBurnIn);

emit Locked(msg.sender, lockOrBurnIn.amount);
Expand All @@ -56,9 +59,12 @@ contract LockReleaseTokenPool is TokenPool, ILiquidityContainer, ITypeAndVersion

/// @notice Release tokens from the pool to the recipient
/// @dev The _validateReleaseOrMint check is an essential security check
function releaseOrMint(
Pool.ReleaseOrMintInV1 calldata releaseOrMintIn
) external virtual override returns (Pool.ReleaseOrMintOutV1 memory) {
function releaseOrMint(Pool.ReleaseOrMintInV1 calldata releaseOrMintIn)
external
virtual
override
returns (Pool.ReleaseOrMintOutV1 memory)
{
_validateReleaseOrMint(releaseOrMintIn);

// Release to the recipient
Expand Down
Loading

0 comments on commit 7341b06

Please sign in to comment.