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

Self Serve Token Pool Factory Contract #1410

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e35a529
proof of concept v0 for token pool factory. Untested
jhweintraub Sep 4, 2024
264c483
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 4, 2024
45c205e
cleanup and solhint fixes
jhweintraub Sep 5, 2024
6b06dc7
Checkpoint a successful deployment workflow
jhweintraub Sep 10, 2024
034990c
Check in. Prediction mechanism working tentatively
jhweintraub Sep 11, 2024
986aeed
tests passing. Cleanup, Comments, and better formatting still needed
jhweintraub Sep 11, 2024
47cae4b
Cleanup and additional comments/natspec
jhweintraub Sep 13, 2024
10c5c66
cleanup shared token files
jhweintraub Sep 13, 2024
4b5719c
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 13, 2024
b263cd8
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 13, 2024
f4847a4
snapshot and compilation fix
jhweintraub Sep 13, 2024
05df3b3
update shared snapshot file for burnMintERC20 file
jhweintraub Sep 13, 2024
9e0b93c
linter
jhweintraub Sep 17, 2024
bdccab9
stack cleanup, add Create2, OZ library, comment fixes, etc.
jhweintraub Sep 17, 2024
30eef85
ccip-precommit
jhweintraub Sep 17, 2024
2faa130
add missing vendor files
jhweintraub Sep 17, 2024
9f76e1b
burn mint formatting
jhweintraub Sep 17, 2024
65395df
gas optimizations and formatting cleanup
jhweintraub Sep 18, 2024
58bdf08
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 18, 2024
1e8cbe2
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 20, 2024
8308646
snapshot update
jhweintraub Sep 20, 2024
3301bae
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 23, 2024
ddef2db
quality cleanup
jhweintraub Sep 23, 2024
6dd38d9
linter fix
jhweintraub Sep 23, 2024
f2984cb
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 23, 2024
edc5c27
revert empty parameter flag to the empty byte string
jhweintraub Sep 24, 2024
9c0d776
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 24, 2024
2ee8c29
gas snapshot fix
jhweintraub Sep 24, 2024
0f22eb0
refactor BurnMintERC677 to inherit from BurnMintERC20
jhweintraub Sep 25, 2024
706eb0b
linting
jhweintraub Sep 25, 2024
8c5285e
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 25, 2024
559bfee
fix a weird snapshot issue idek how this happened
jhweintraub Sep 25, 2024
a0982c2
Merge 559bfee2c9a82e1e38437e84de33b0e3820ef8fa into 390ee2334126e313c…
jhweintraub Sep 25, 2024
a997387
Update gethwrappers
app-token-issuer-infra-releng[bot] Sep 25, 2024
729dbb9
snapshotting
jhweintraub Sep 25, 2024
0688f98
formatting
jhweintraub Sep 25, 2024
90ee01d
Revert Changes to shared folders, will be in Chainlink repo
jhweintraub Sep 26, 2024
374b334
Merge 90ee01d2d42b23bc992fc5cd1b861d280761bbdc into 390ee2334126e313c…
jhweintraub Sep 26, 2024
34ac7c6
Update gethwrappers
app-token-issuer-infra-releng[bot] Sep 26, 2024
5c05b9d
remove stateful functions from tokenPoolFactory
jhweintraub Sep 26, 2024
ba1c74c
add support for lock-release pools
jhweintraub Sep 26, 2024
b3dc9c1
add comments and reomve unnec. initArgs parameter
jhweintraub Sep 27, 2024
d69fd9a
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Sep 30, 2024
e78543b
comment cleanup
jhweintraub Sep 30, 2024
bbabb8d
forge fmt
jhweintraub Sep 30, 2024
bf6d75d
CI cleanup
jhweintraub Oct 4, 2024
ae8a3c0
formatting CI is the bane of my existence
jhweintraub Oct 4, 2024
5fda354
fill in end-to-end coverage gaps
jhweintraub Oct 4, 2024
240b70f
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Oct 7, 2024
f03c94d
Merge 240b70f3357127d505ef29b25e2edff7afede58c into f77ff217862989836…
jhweintraub Oct 7, 2024
9f28740
Update gethwrappers
app-token-issuer-infra-releng[bot] Oct 7, 2024
e9da1df
rework lock-release pool deployment to be more stringent
jhweintraub Oct 10, 2024
752c290
when you forget to run the formatter before committing
jhweintraub Oct 10, 2024
a929fed
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Oct 10, 2024
ea77929
gas snapshotting
jhweintraub Oct 10, 2024
7dc40df
remove console log and silence compiler warning
jhweintraub Oct 10, 2024
b1c8c67
another attempt at snapshot fixing
jhweintraub Oct 10, 2024
005861f
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Oct 15, 2024
9355849
snapshot fix after a merge
jhweintraub Oct 15, 2024
7ce7ea7
fix wrapper changes previously
jhweintraub Oct 15, 2024
a8e6726
pragma fix, formatting, and remove unused files
jhweintraub Oct 15, 2024
0bd89b5
more formatting
jhweintraub Oct 15, 2024
ba9c004
formatting and naming fixes
jhweintraub Oct 22, 2024
b198018
Merge branch 'ccip-develop' into feature/selfServeFactory
jhweintraub Oct 22, 2024
d3ab628
*sighs in snapshotting*
jhweintraub Oct 22, 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
Prev Previous commit
Next Next commit
Cleanup and additional comments/natspec
  • Loading branch information
jhweintraub committed Sep 13, 2024
commit 47cae4bd9e8abde25b7cd663130705cc4fe6838a
6 changes: 6 additions & 0 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,12 @@ TokenPoolAndProxy:test_lockOrBurn_lockRelease_Success() (gas: 6319594)
TokenPoolAndProxy:test_setPreviousPool_Success() (gas: 3387124)
TokenPoolAndProxyMigration:test_tokenPoolMigration_Success_1_2() (gas: 6916278)
TokenPoolAndProxyMigration:test_tokenPoolMigration_Success_1_4() (gas: 7100303)
TokenPoolFactoryTests:test_TokenPoolFactory_Constructor_Revert() (gas: 4545462)
TokenPoolFactoryTests:test_createTokenPool_ExistingRemoteToken_AndPredictPool_Success() (gas: 16922060)
TokenPoolFactoryTests:test_createTokenPool_WithNoExistingRemoteContracts_predict_Success() (gas: 17197023)
TokenPoolFactoryTests:test_createTokenPool_WithNoExistingTokenOnRemoteChain_Success() (gas: 6281185)
TokenPoolFactoryTests:test_createTokenPool_WithRemoteTokenAndRemotePool_Success() (gas: 6428760)
TokenPoolFactoryTests:test_updateRemoteChainConfig_Success() (gas: 85581)
TokenPoolWithAllowList_applyAllowListUpdates:test_AllowListNotEnabled_Revert() (gas: 2209837)
TokenPoolWithAllowList_applyAllowListUpdates:test_OnlyOwner_Revert() (gas: 12089)
TokenPoolWithAllowList_applyAllowListUpdates:test_SetAllowListSkipsZero_Success() (gas: 23324)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ contract TokenPoolFactorySetup is TokenAdminRegistrySetup {
}

contract TokenPoolFactoryTests is TokenPoolFactorySetup {
function test_TokenPoolFactory_Constructor_Revert() public {
// Revert cause the tokenAdminRegistry is address(0)
vm.expectRevert(TokenPoolFactory.InvalidZeroAddress.selector);
new TokenPoolFactory(address(0), address(0), address(0), address(0));

new TokenPoolFactory(address(0xdeadbeef), address(0xdeadbeef), address(0xdeadbeef), address(0xdeadbeef));
}

function test_createTokenPool_WithNoExistingTokenOnRemoteChain_Success() public {
vm.startPrank(OWNER);

Expand All @@ -79,7 +87,7 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
);

(address tokenAddress, address poolAddress) = s_tokenPoolFactory.deployTokenAndTokenPool(
new TokenPoolFactory.ExistingTokenPool[](0), s_tokenInitCode, s_poolInitCode, poolCreationParams, s_salt
new TokenPoolFactory.RemoteTokenPoolInfo[](0), s_tokenInitCode, s_poolInitCode, poolCreationParams, s_salt
);

assertNotEq(address(0), tokenAddress, "Token Address should not be 0");
Expand Down Expand Up @@ -115,16 +123,22 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
TokenPoolFactory.RemoteChainConfig memory remoteChainConfig =
TokenPoolFactory.RemoteChainConfig(address(newTokenPoolFactory), address(s_destRouter), address(s_rmnProxy));

uint64[] memory chainIds = new uint64[](1);
chainIds[0] = DEST_CHAIN_SELECTOR;

TokenPoolFactory.RemoteChainConfig[] memory remoteChainConfigs = new TokenPoolFactory.RemoteChainConfig[](1);
remoteChainConfigs[0] = remoteChainConfig;

// Add the new token Factory to the remote chain config and set it for the simulated destination chain
s_tokenPoolFactory.updateRemoteChainConfig(DEST_CHAIN_SELECTOR, remoteChainConfig);
s_tokenPoolFactory.updateRemoteChainConfig(chainIds, remoteChainConfigs);

// Create an array of remote pools where nothing exists yet, but we want to predict the address for
// the new pool and token on DEST_CHAIN_SELECTOR
TokenPoolFactory.ExistingTokenPool[] memory remoteTokenPools = new TokenPoolFactory.ExistingTokenPool[](1);
TokenPoolFactory.RemoteTokenPoolInfo[] memory remoteTokenPools = new TokenPoolFactory.RemoteTokenPoolInfo[](1);

// The only field that matters is DEST_CHAIN_SELECTOR because we dont want any existing token pool or token
// on the remote chain
remoteTokenPools[0] = TokenPoolFactory.ExistingTokenPool(
remoteTokenPools[0] = TokenPoolFactory.RemoteTokenPoolInfo(
DEST_CHAIN_SELECTOR,
abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()),
abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()),
Expand All @@ -140,8 +154,7 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {

// Since the remote chain information was provided, we should be able to get the information from the newly
// deployed token pool using the available getter functions

(address tokenAddress, address poolAddress) = s_tokenPoolFactory.deployTokenAndTokenPool(
(, address poolAddress) = s_tokenPoolFactory.deployTokenAndTokenPool(
remoteTokenPools, s_tokenInitCode, s_poolInitCode, abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()), s_salt
);

Expand Down Expand Up @@ -176,7 +189,7 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
// On the new token pool factory, representing a destination chain,
// deploy a new token and a new pool
(address newTokenAddress, address newPoolAddress) = newTokenPoolFactory.deployTokenAndTokenPool(
new TokenPoolFactory.ExistingTokenPool[](0),
new TokenPoolFactory.RemoteTokenPoolInfo[](0),
s_tokenInitCode,
s_poolInitCode,
abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()),
Expand Down Expand Up @@ -214,19 +227,27 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {

newTokenAdminRegistry.addRegistryModule(address(newRegistryModule));

TokenPoolFactory.RemoteChainConfig memory remoteChainConfig =
TokenPoolFactory.RemoteChainConfig(address(newTokenPoolFactory), address(s_destRouter), address(s_rmnProxy));
{
TokenPoolFactory.RemoteChainConfig memory remoteChainConfig =
TokenPoolFactory.RemoteChainConfig(address(newTokenPoolFactory), address(s_destRouter), address(s_rmnProxy));

// Add the new token Factory to the remote chain config and set it for the simulated destination chain
s_tokenPoolFactory.updateRemoteChainConfig(DEST_CHAIN_SELECTOR, remoteChainConfig);
TokenPoolFactory.RemoteChainConfig[] memory remoteChainConfigs = new TokenPoolFactory.RemoteChainConfig[](1);
remoteChainConfigs[0] = remoteChainConfig;

uint64[] memory chainIds = new uint64[](1);
chainIds[0] = DEST_CHAIN_SELECTOR;

// Add the new token Factory to the remote chain config and set it for the simulated destination chain
s_tokenPoolFactory.updateRemoteChainConfig(chainIds, remoteChainConfigs);
}

// Create an array of remote pools where nothing exists yet, but we want to predict the address for
// the new pool and token on DEST_CHAIN_SELECTOR
TokenPoolFactory.ExistingTokenPool[] memory remoteTokenPools = new TokenPoolFactory.ExistingTokenPool[](1);
TokenPoolFactory.RemoteTokenPoolInfo[] memory remoteTokenPools = new TokenPoolFactory.RemoteTokenPoolInfo[](1);

// The only field that matters is DEST_CHAIN_SELECTOR because we dont want any existing token pool or token
// on the remote chain
remoteTokenPools[0] = TokenPoolFactory.ExistingTokenPool(
remoteTokenPools[0] = TokenPoolFactory.RemoteTokenPoolInfo(
DEST_CHAIN_SELECTOR,
abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()),
abi.encode(address(newRemoteToken)),
Expand All @@ -241,6 +262,8 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
remoteTokenPools, s_tokenInitCode, s_poolInitCode, abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()), s_salt
);

assertEq(address(TokenPool(poolAddress).getToken()), tokenAddress, "Token Address should have been set locally");

// Ensure that the remote Token was set to the one we predicted
assertEq(
abi.encode(address(newRemoteToken)),
Expand Down Expand Up @@ -271,27 +294,20 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {

// On the new token pool factory, representing a destination chain,
// deploy a new token and a new pool
(address newTokenAddress, address newPoolAddress) = newTokenPoolFactory.deployTokenPoolWithExistingToken(
address newPoolAddress = newTokenPoolFactory.deployTokenPoolWithExistingToken(
address(newRemoteToken),
new TokenPoolFactory.ExistingTokenPool[](0),
s_tokenInitCode,
new TokenPoolFactory.RemoteTokenPoolInfo[](0),
s_poolInitCode,
abi.encode(s_tokenPoolFactory.EMPTY_PARAMETER_FLAG()),
s_salt
);

assertEq(
abi.encode(newTokenAddress),
abi.encode(newRemoteToken),
TokenPool(poolAddress).getRemoteToken(DEST_CHAIN_SELECTOR),
"Remote Token Address should have been set correctly"
);

assertEq(
newTokenAddress,
address(newRemoteToken),
"Remote Token Address returned should be the same as the one we deployed"
);

assertEq(
TokenPool(poolAddress).getRemotePool(DEST_CHAIN_SELECTOR),
abi.encode(newPoolAddress),
Expand All @@ -314,16 +330,10 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
// Create the constructor params for the predicted pool
bytes memory poolCreationParams = abi.encode(predictedTokenAddress, new address[](0), s_rmnProxy, s_sourceRouter);

// Predict the address of the pool before we make the tx by using the init code and the params
bytes memory predictedPoolInitCode = abi.encodePacked(s_poolInitCode, poolCreationParams);
address predictedPoolAddress = DeterministicContractDeployer._predictAddressOfUndeployedContract(
predictedPoolInitCode, dynamicSalt, address(s_tokenPoolFactory)
);

// Create an array of remote pools with some fake addresses
TokenPoolFactory.ExistingTokenPool[] memory remoteTokenPools = new TokenPoolFactory.ExistingTokenPool[](1);
TokenPoolFactory.RemoteTokenPoolInfo[] memory remoteTokenPools = new TokenPoolFactory.RemoteTokenPoolInfo[](1);

remoteTokenPools[0] = TokenPoolFactory.ExistingTokenPool(
remoteTokenPools[0] = TokenPoolFactory.RemoteTokenPoolInfo(
DEST_CHAIN_SELECTOR,
RANDOM_POOL_ADDRESS,
RANDOM_TOKEN_ADDRESS,
Expand Down Expand Up @@ -363,13 +373,20 @@ contract TokenPoolFactoryTests is TokenPoolFactorySetup {
}

function test_updateRemoteChainConfig_Success() public {
uint64[] memory chainIds = new uint64[](1);
chainIds[0] = DEST_CHAIN_SELECTOR;

TokenPoolFactory.RemoteChainConfig[] memory remoteChainConfigs = new TokenPoolFactory.RemoteChainConfig[](1);

TokenPoolFactory.RemoteChainConfig memory remoteChainConfig = TokenPoolFactory.RemoteChainConfig({
remotePoolFactory: address(0x1234),
remoteRouter: address(0x5678),
remoteRMNProxy: address(0x9abc)
});

s_tokenPoolFactory.updateRemoteChainConfig(DEST_CHAIN_SELECTOR, remoteChainConfig);
remoteChainConfigs[0] = remoteChainConfig;

s_tokenPoolFactory.updateRemoteChainConfig(chainIds, remoteChainConfigs);

TokenPoolFactory.RemoteChainConfig memory updatedRemoteChainConfig =
s_tokenPoolFactory.getRemoteChainConfig(DEST_CHAIN_SELECTOR);
Expand Down
Loading
Loading