Skip to content

Commit

Permalink
add token pool ixns
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-cll committed Feb 26, 2025
1 parent fab3f96 commit 4d2b2ce
Show file tree
Hide file tree
Showing 4 changed files with 561 additions and 140 deletions.
2 changes: 2 additions & 0 deletions deployment/ccip/changeset/solana/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type MCMSConfigSolana struct {
RouterOwnedByTimelock bool
FeeQuoterOwnedByTimelock bool
OffRampOwnedByTimelock bool
// Assumes whatever token pool we're operating on
TokenPoolOwnedByTimelock bool
}

// HELPER FUNCTIONS
Expand Down
93 changes: 0 additions & 93 deletions deployment/ccip/changeset/solana/cs_chain_contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import (
"github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/require"

solBaseTokenPool "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/base_token_pool"
solOffRamp "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_offramp"
solRouter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_router"
solFeeQuoter "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/fee_quoter"
solTestTokenPool "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/test_token_pool"
solCommonUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
solState "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/state"
solTokenUtil "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext"

Expand Down Expand Up @@ -228,96 +225,6 @@ func TestDeployCCIPContracts(t *testing.T) {
testhelpers.DeployCCIPContractsTest(t, 1)
}

func TestAddTokenPool(t *testing.T) {
t.Parallel()
ctx := testcontext.Get(t)
tenv, _ := testhelpers.NewMemoryEnvironment(t, testhelpers.WithSolChains(1))

evmChain := tenv.Env.AllChainSelectors()[0]
solChain := tenv.Env.AllChainSelectorsSolana()[0]
e, newTokenAddress, err := deployToken(t, tenv.Env, solChain)
require.NoError(t, err)
state, err := ccipChangeset.LoadOnchainStateSolana(e)
require.NoError(t, err)
remoteConfig := solBaseTokenPool.RemoteConfig{
PoolAddresses: []solTestTokenPool.RemoteAddress{{Address: []byte{1, 2, 3}}},
TokenAddress: solTestTokenPool.RemoteAddress{Address: []byte{4, 5, 6}},
Decimals: 9,
}
inboundConfig := solBaseTokenPool.RateLimitConfig{
Enabled: true,
Capacity: uint64(1000),
Rate: 1,
}
outboundConfig := solBaseTokenPool.RateLimitConfig{
Enabled: false,
Capacity: 0,
Rate: 0,
}

tokenMap := map[deployment.ContractType]solana.PublicKey{
ccipChangeset.SPL2022Tokens: newTokenAddress,
ccipChangeset.SPLTokens: state.SolChains[solChain].WSOL,
}

type poolTestType struct {
poolType solTestTokenPool.PoolType
poolAddress solana.PublicKey
}
testCases := []poolTestType{
{
poolType: solTestTokenPool.BurnAndMint_PoolType,
poolAddress: state.SolChains[solChain].BurnMintTokenPool,
},
{
poolType: solTestTokenPool.LockAndRelease_PoolType,
poolAddress: state.SolChains[solChain].LockReleaseTokenPool,
},
}
for _, testCase := range testCases {
for _, tokenAddress := range tokenMap {
e, err = commonchangeset.Apply(t, e, nil,
commonchangeset.Configure(
deployment.CreateLegacyChangeSet(ccipChangesetSolana.AddTokenPool),
ccipChangesetSolana.TokenPoolConfig{
ChainSelector: solChain,
TokenPubKey: tokenAddress.String(),
PoolType: testCase.poolType,
// this works for testing, but if we really want some other authority we need to pass in a private key for signing purposes
Authority: tenv.Env.SolChains[solChain].DeployerKey.PublicKey().String(),
},
),
commonchangeset.Configure(
deployment.CreateLegacyChangeSet(ccipChangesetSolana.SetupTokenPoolForRemoteChain),
ccipChangesetSolana.RemoteChainTokenPoolConfig{
SolChainSelector: solChain,
RemoteChainSelector: evmChain,
SolTokenPubKey: tokenAddress.String(),
RemoteConfig: remoteConfig,
InboundRateLimit: inboundConfig,
OutboundRateLimit: outboundConfig,
PoolType: testCase.poolType,
},
),
)
require.NoError(t, err)
// test AddTokenPool results
configAccount := solTestTokenPool.State{}
poolConfigPDA, _ := solTokenUtil.TokenPoolConfigAddress(tokenAddress, testCase.poolAddress)
err = e.SolChains[solChain].GetAccountDataBorshInto(ctx, poolConfigPDA, &configAccount)
require.NoError(t, err)
require.Equal(t, tokenAddress, configAccount.Config.Mint)
// test SetupTokenPoolForRemoteChain results
remoteChainConfigPDA, _, _ := solTokenUtil.TokenPoolChainConfigPDA(evmChain, tokenAddress, testCase.poolAddress)
var remoteChainConfigAccount solTestTokenPool.ChainConfig
err = e.SolChains[solChain].GetAccountDataBorshInto(ctx, remoteChainConfigPDA, &remoteChainConfigAccount)
require.NoError(t, err)
require.Equal(t, uint8(9), remoteChainConfigAccount.Base.Remote.Decimals)
}
}

}

func TestBilling(t *testing.T) {
t.Parallel()
tests := []struct {
Expand Down
Loading

0 comments on commit 4d2b2ce

Please sign in to comment.