Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permissionless token pools #652

Merged
merged 48 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b111359
rm tokens from ramps
RensR Mar 1, 2024
60b19b0
add remote pool config to pool
RensR Mar 4, 2024
5ad0364
token setup
RensR Mar 4, 2024
0c2b602
fix pool return values & parsing
RensR Mar 4, 2024
1657c8c
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Mar 20, 2024
8e0fe16
add mapping for token -> pool in token setup
RensR Mar 21, 2024
9fea02d
rm pools and tokens from offRamp unit
RensR Mar 21, 2024
123638a
fix offramp setting TokenDataPayload
RensR Mar 21, 2024
a84800a
fix usdc & lockRelease pool
RensR Mar 21, 2024
fbda5e7
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Mar 28, 2024
208c889
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 2, 2024
62d8b62
rm s_destPools
RensR Apr 2, 2024
3325c86
improve MaybeRevertingBurnMintTokenPool
RensR Apr 2, 2024
7b0a7f7
fix event generation
RensR Apr 2, 2024
8d73c06
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 2, 2024
1c15e67
fix tests & solhint
RensR Apr 3, 2024
4ba8886
Update rebalancer.gas-snapshot
RensR Apr 3, 2024
6cd835a
refactor with more explicit arguments
RensR Apr 3, 2024
f50dca5
add tests for get/set pool
RensR Apr 3, 2024
c89ff60
increase coverage
RensR Apr 3, 2024
4367860
add tests and resolve todos
RensR Apr 4, 2024
85e7a66
add custom errors for the pool checks
RensR Apr 4, 2024
573e213
let the pool return the token on releaseOrMint
RensR Apr 4, 2024
a95c6a8
golfing
RensR Apr 4, 2024
e8e3892
add tests for get/set pool
RensR Apr 4, 2024
a054ee4
keep ccipSend event the same
RensR Apr 4, 2024
9c73d96
Gen wrappers for all token contract
RensR Apr 4, 2024
f35ca89
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 4, 2024
0a1544f
init 1.5 onramp logic
RensR Apr 4, 2024
796c4d4
add getAllConfiguredTokens to registry
RensR Apr 4, 2024
e8bce92
use a single return value
RensR Apr 5, 2024
91311e9
gen wrappers
RensR Apr 5, 2024
927f404
integration test setup with TokenAdminRegistry
RensR Apr 5, 2024
9268032
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 5, 2024
08c1880
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 8, 2024
15425a7
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 8, 2024
d19790d
add weth to dest fee tokens & ignore getTokensPrices no price in reg
RensR Apr 8, 2024
b6053c1
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 9, 2024
a51ceac
fix lint
RensR Apr 9, 2024
985e372
refactor smoke tests
RensR Apr 9, 2024
2156bd5
fix struct packing
RensR Apr 9, 2024
a8959ec
add better logging
RensR Apr 9, 2024
7dde9bd
Ccip 1993 update smoke test with permissionless token pools (#701)
AnieeG Apr 10, 2024
eb8873d
Add full legacy testsuite for 1.4 lanes
RensR Apr 10, 2024
8721682
add comments
RensR Apr 10, 2024
eb57271
rm old events/errors
RensR Apr 10, 2024
6bb2e73
offchain cleanup
RensR Apr 11, 2024
52d559a
Merge branch 'ccip-develop' into permissionless-token-pools-demo
RensR Apr 11, 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
5 changes: 5 additions & 0 deletions .changeset/healthy-years-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ccip": minor
---

Support self serve token pools
5 changes: 5 additions & 0 deletions contracts/.changeset/shy-crabs-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts-ccip": minor
---

permissionless token pools
468 changes: 231 additions & 237 deletions contracts/gas-snapshots/ccip.gas-snapshot

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions contracts/gas-snapshots/rebalancer.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ OptimismL1BridgeAdapter_finalizeWithdrawERC20:testFinalizeWithdrawERC20Reverts()
OptimismL1BridgeAdapter_finalizeWithdrawERC20:testfinalizeWithdrawERC20FinalizeSuccess() (gas: 16860)
OptimismL1BridgeAdapter_finalizeWithdrawERC20:testfinalizeWithdrawERC20proveWithdrawalSuccess() (gas: 20650)
Rebalancer__report:test_EmptyReportReverts() (gas: 11181)
Rebalancer_addLiquidity:test_addLiquiditySuccess() (gas: 284793)
Rebalancer_addLiquidity:test_addLiquiditySuccess() (gas: 284776)
Rebalancer_rebalanceLiquidity:test_InsufficientLiquidityReverts() (gas: 19579)
Rebalancer_rebalanceLiquidity:test_InvalidRemoteChainReverts() (gas: 197579)
Rebalancer_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess() (gas: 8207096)
Rebalancer_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess_AlreadyFinalized() (gas: 7711369)
Rebalancer_rebalanceLiquidity:test_rebalanceLiquiditySuccess() (gas: 384907)
Rebalancer_rebalanceLiquidity:test_rebalanceBetweenPoolsSuccess_AlreadyFinalized() (gas: 8077825)
Rebalancer_rebalanceLiquidity:test_rebalanceLiquiditySuccess() (gas: 384924)
Rebalancer_removeLiquidity:test_InsufficientLiquidityReverts() (gas: 191702)
Rebalancer_removeLiquidity:test_OnlyOwnerReverts() (gas: 10923)
Rebalancer_removeLiquidity:test_removeLiquiditySuccess() (gas: 243250)
Rebalancer_removeLiquidity:test_removeLiquiditySuccess() (gas: 243268)
Rebalancer_setCrossChainRebalancer:test_OnlyOwnerReverts() (gas: 16997)
Rebalancer_setCrossChainRebalancer:test_ZeroAddressReverts() (gas: 21624)
Rebalancer_setCrossChainRebalancer:test_ZeroChainSelectorReverts() (gas: 13099)
Rebalancer_setCrossChainRebalancer:test_setCrossChainRebalancerSuccess() (gas: 162244)
Rebalancer_setLocalLiquidityContainer:test_OnlyOwnerReverts() (gas: 10986)
Rebalancer_setLocalLiquidityContainer:test_setLocalLiquidityContainerSuccess() (gas: 2887358)
Rebalancer_setLocalLiquidityContainer:test_setLocalLiquidityContainerSuccess() (gas: 3254087)
Rebalancer_setMinimumLiquidity:test_OnlyOwnerReverts() (gas: 10925)
Rebalancer_setMinimumLiquidity:test_setMinimumLiquiditySuccess() (gas: 36422)
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_ccip
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ compileContract ccip/pools/TokenPool.sol
compileContract shared/token/ERC677/BurnMintERC677.sol
compileContract ccip/ARM.sol
compileContract ccip/ARMProxy.sol
compileContract ccip/pools/TokenAdminRegistry.sol

# Test helpers
compileContract ccip/test/helpers/BurnMintERC677Helper.sol
Expand Down
7 changes: 0 additions & 7 deletions contracts/src/v0.8/ccip/interfaces/IEVM2AnyOnRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity ^0.8.0;

import {IEVM2AnyOnRampClient} from "./IEVM2AnyOnRampClient.sol";

import {Internal} from "../libraries/Internal.sol";

interface IEVM2AnyOnRamp is IEVM2AnyOnRampClient {
/// @notice Gets the next sequence number to be used in the onRamp
/// @return the next sequence number to be used
Expand All @@ -14,9 +12,4 @@ interface IEVM2AnyOnRamp is IEVM2AnyOnRampClient {
/// @param sender The sender to get the nonce for
/// @return nonce The next nonce for the sender
function getSenderNonce(address sender) external view returns (uint64 nonce);

/// @notice Adds and removed token pools.
/// @param removes The tokens and pools to be removed
/// @param adds The tokens and pools to be added.
function applyPoolUpdates(Internal.PoolUpdate[] memory removes, Internal.PoolUpdate[] memory adds) external;
}
11 changes: 11 additions & 0 deletions contracts/src/v0.8/ccip/interfaces/ITokenAdminRegistry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

interface ITokenAdminRegistry {
/// @notice Returns the pool for the given token.
function getPool(address token) external view returns (address);

/// @notice Returns every token that has ever been configured. This includes tokens
/// that are no longer configured or do not have a pool configured.
function getAllConfiguredTokens() external view returns (address[] memory);
}
26 changes: 20 additions & 6 deletions contracts/src/v0.8/ccip/interfaces/pools/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,55 @@ import {IERC20} from "../../../vendor/openzeppelin-solidity/v4.8.3/contracts/tok
// Shared public interface for multiple pool types.
// Each pool type handles a different child token model (lock/unlock, mint/burn.)
interface IPool {
struct SourceTokenData {
bytes sourcePoolAddress;
justinkaseman marked this conversation as resolved.
Show resolved Hide resolved
bytes destPoolAddress;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: what do you think of the alternative option to pass the destToken instead of the pool? This way we can validate more strictly by querying getPool(destToken) via the registry on the dest chain - and we can always be sure that the pool represents the token correctly

In this case the mapping on the src chain would have to change to token => chainSelector => token address (bytes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds an additional 5.8k gas for a single msg token and increases the size of the contract. Probably not worth it

bytes extraData;
}

/// @notice Lock tokens into the pool or burn the tokens.
/// @param originalSender Original sender of the tokens.
/// @param receiver Receiver of the tokens on destination chain.
/// @param amount Amount to lock or burn.
/// @param remoteChainSelector Destination chain Id.
/// @param extraArgs Additional data passed in by sender for lockOrBurn processing
/// in custom pools on source chain.
/// @return retData Optional field that contains bytes. Unused for now but already
/// implemented to allow future upgrades while preserving the interface.
/// @return poolReturnData Versioned, encoded data fields for the processing of tokens
/// on the destination chain.
function lockOrBurn(
address originalSender,
bytes calldata receiver,
uint256 amount,
uint64 remoteChainSelector,
bytes calldata extraArgs
) external returns (bytes memory);
) external returns (bytes memory poolReturnData);

/// @notice Releases or mints tokens to the receiver address.
/// @param originalSender Original sender of the tokens.
/// @param receiver Receiver of the tokens.
/// @param amount Amount to release or mint.
/// @param remoteChainSelector Source chain Id.
/// @param extraData Additional data supplied offchain for releaseOrMint processing in
/// @param sourceTokenData The source and dest pool addresses, as well as any additional data
/// from calling lockOrBurn on the source chain.
/// @param offchainTokenData Additional data supplied offchain for releaseOrMint processing in
/// custom pools on dest chain. This could be an attestation that was retrieved through a
/// third party API.
/// @dev offchainData can come from any untrusted source.
/// @return localToken The address of the local token.
function releaseOrMint(
bytes memory originalSender,
address receiver,
uint256 amount,
uint64 remoteChainSelector,
bytes memory extraData
) external;
SourceTokenData memory sourceTokenData,
bytes memory offchainTokenData
) external returns (address localToken);

/// @notice Gets the IERC20 token that this pool can lock or burn.
/// @return token The IERC20 token representation.
function getToken() external view returns (IERC20 token);

/// @notice Gets the pool address on the remote chain.
/// @param remoteChainSelector Destination chain selector.
function getRemotePool(uint64 remoteChainSelector) external view returns (bytes memory);
}
26 changes: 13 additions & 13 deletions contracts/src/v0.8/ccip/libraries/Internal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ library Internal {
/// @notice The cross chain message that gets committed to EVM chains.
/// @dev RMN depends on this struct, if changing, please notify the RMN maintainers.
struct EVM2EVMMessage {
uint64 sourceChainSelector; // ─────────╮ the chain selector of the source chain, note: not chainId
address sender; // ─────────────────────╯ sender address on the source chain
address receiver; // ───────────────────╮ receiver address on the destination chain
uint64 sequenceNumber; // ──────────────╯ sequence number, not unique across lanes
uint256 gasLimit; // user supplied maximum gas amount available for dest chain execution
bool strict; // ────────────────────────╮ DEPRECATED
uint64 nonce; // │ nonce for this lane for this sender, not unique across senders/lanes
address feeToken; // ───────────────────╯ fee token
uint256 feeTokenAmount; // fee token amount
bytes data; // arbitrary data payload supplied by the message sender
Client.EVMTokenAmount[] tokenAmounts; // array of tokens and amounts to transfer
bytes[] sourceTokenData; // array of token pool return values, one per token
bytes32 messageId; // a hash of the message data
uint64 sourceChainSelector; // ───────────╮ the chain selector of the source chain, note: not chainId
address sender; // ───────────────────────╯ sender address on the source chain
address receiver; // ─────────────────────╮ receiver address on the destination chain
uint64 sequenceNumber; // ────────────────╯ sequence number, not unique across lanes
uint256 gasLimit; // user supplied maximum gas amount available for dest chain execution
bool strict; // ──────────────────────────╮ DEPRECATED
uint64 nonce; // │ nonce for this lane for this sender, not unique across senders/lanes
address feeToken; // ─────────────────────╯ fee token
uint256 feeTokenAmount; // fee token amount
bytes data; // arbitrary data payload supplied by the message sender
Client.EVMTokenAmount[] tokenAmounts; // array of tokens and amounts to transfer
bytes[] sourceTokenData; // array of token data, one per token
bytes32 messageId; // a hash of the message data
}

/// @dev EVM2EVMMessage struct has 13 fields, including 3 variable arrays.
Expand Down
24 changes: 24 additions & 0 deletions contracts/src/v0.8/ccip/libraries/Pool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library Pool {
// bytes4(keccak256("POOL_RETURN_DATA_V1_TAG"))
bytes4 public constant POOL_RETURN_DATA_V1_TAG = 0x179fa694;
RensR marked this conversation as resolved.
Show resolved Hide resolved

struct PoolReturnDataV1 {
bytes destPoolAddress;
bytes destPoolData;
}

function _generatePoolReturnDataV1(
bytes memory remotePoolAddress,
bytes memory destPoolData
) internal pure returns (bytes memory) {
return abi.encode(PoolReturnDataV1({destPoolAddress: remotePoolAddress, destPoolData: destPoolData}));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: second return will be skipped?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address the tag logic in the next follow up PR, this one is too large already an it is technically not required for any current functionality. Good catch though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment


// TODO next PR: actually use the tag
return abi.encodeWithSelector(
POOL_RETURN_DATA_V1_TAG, PoolReturnDataV1({destPoolAddress: remotePoolAddress, destPoolData: destPoolData})
);
}
}
Loading
Loading