-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Solana todos #16391
Solana todos #16391
Changes from all commits
aaab52e
f19598e
87f6e75
4bf2980
6712ecd
a1e15fa
827ccd6
29f6dc4
dfe582d
4699cc9
9b53d65
3e6ce6a
484898f
d44f0fd
89569b4
9f812a3
bfb4b4d
d2dbd83
2bcd2bb
933df94
b0c3e65
7815ee8
f111442
ef7b6f3
efa54a2
315659c
9c6497b
e3314a7
fed8aba
659f04e
7a2b83f
243089f
e69844e
1f6dd17
a2e5f3e
565af6e
94a7d69
a352b09
a9e966d
9eee32a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"fmt" | ||
"strconv" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/gagliardetto/solana-go" | ||
|
||
solOffRamp "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_offramp" | ||
|
@@ -71,8 +72,19 @@ func (cfg AddRemoteChainToSolanaConfig) Validate(e deployment.Environment) error | |
if remote == routerConfigAccount.SvmChainSelector { | ||
return fmt.Errorf("cannot add remote chain %d with same chain selector as current chain %d", remote, cfg.ChainSelector) | ||
} | ||
if err := state.ValidateRamp(remote, cs.OnRamp); err != nil { | ||
return err | ||
} | ||
routerDestChainPDA, err := solState.FindDestChainStatePDA(remote, chainState.Router) | ||
if err != nil { | ||
return fmt.Errorf("failed to find dest chain state pda for remote chain %d: %w", remote, err) | ||
} | ||
var destChainStateAccount solRouter.DestChain | ||
err = chain.GetAccountDataBorshInto(context.Background(), routerDestChainPDA, &destChainStateAccount) | ||
if err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this right condition? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, if the err is nil, that means the remote chain has already been configured and the routerDestChainPDA has already been initialised. |
||
return fmt.Errorf("remote %d is already configured on solana chain %d", remote, cfg.ChainSelector) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -111,17 +123,15 @@ func doAddRemoteChainToSolana( | |
var onRampBytes [64]byte | ||
// already verified, skipping errcheck | ||
remoteChainFamily, _ := chainsel.GetSelectorFamily(remoteChainSel) | ||
var addressBytes []byte | ||
switch remoteChainFamily { | ||
case chainsel.FamilySolana: | ||
return fmt.Errorf("support for solana chain as remote chain is not implemented yet %d", remoteChainSel) | ||
addressBytes, _ = s.SolChains[remoteChainSel].OnRampBytes() | ||
case chainsel.FamilyEVM: | ||
onRampAddress := s.Chains[remoteChainSel].OnRamp.Address().String() | ||
if onRampAddress == "" { | ||
return fmt.Errorf("onramp address not found for chain %d", remoteChainSel) | ||
} | ||
addressBytes := []byte(onRampAddress) | ||
copy(onRampBytes[:], addressBytes) | ||
addressBytes, _ = s.Chains[remoteChainSel].OnRampBytes() | ||
} | ||
addressBytes = common.LeftPadBytes(addressBytes, 64) | ||
copy(onRampBytes[:], addressBytes) | ||
|
||
// verified while loading state | ||
fqDestChainPDA, _, _ := solState.FindFqDestChainPDA(remoteChainSel, feeQuoterID) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,65 +121,72 @@ func TestAddTokenPool(t *testing.T) { | |
|
||
state, err := ccipChangeset.LoadOnchainStateSolana(e) | ||
require.NoError(t, err) | ||
tokenAddress := state.SolChains[solChain].SPL2022Tokens[0] | ||
|
||
// TODO: can test this with solana.SolMint as well (WSOL) | ||
// https://smartcontract-it.atlassian.net/browse/INTAUTO-440 | ||
e, err = commonchangeset.Apply(t, e, nil, | ||
commonchangeset.Configure( | ||
deployment.CreateLegacyChangeSet(changeset_solana.AddTokenPool), | ||
changeset_solana.TokenPoolConfig{ | ||
ChainSelector: solChain, | ||
TokenPubKey: tokenAddress.String(), | ||
TokenProgramName: deployment.SPL2022Tokens, | ||
PoolType: solTestTokenPool.LockAndRelease_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: e.SolChains[solChain].DeployerKey.PublicKey().String(), | ||
}, | ||
), | ||
commonchangeset.Configure( | ||
deployment.CreateLegacyChangeSet(changeset_solana.SetupTokenPoolForRemoteChain), | ||
changeset_solana.RemoteChainTokenPoolConfig{ | ||
SolChainSelector: solChain, | ||
RemoteChainSelector: evmChain, | ||
SolTokenPubKey: tokenAddress.String(), | ||
RemoteConfig: solTestTokenPool.RemoteConfig{ | ||
// TODO:this can be potentially read from the state if we are given the token symbol | ||
PoolAddresses: []solTestTokenPool.RemoteAddress{{Address: []byte{1, 2, 3}}}, | ||
TokenAddress: solTestTokenPool.RemoteAddress{Address: []byte{4, 5, 6}}, | ||
Decimals: 9, | ||
}, | ||
InboundRateLimit: solTestTokenPool.RateLimitConfig{ | ||
Enabled: true, | ||
Capacity: uint64(1000), | ||
Rate: 1, | ||
newTokenAddress := state.SolChains[solChain].SPL2022Tokens[0] | ||
|
||
remoteConfig := solTestTokenPool.RemoteConfig{ | ||
PoolAddresses: []solTestTokenPool.RemoteAddress{{Address: []byte{1, 2, 3}}}, | ||
TokenAddress: solTestTokenPool.RemoteAddress{Address: []byte{4, 5, 6}}, | ||
Decimals: 9, | ||
} | ||
inboundConfig := solTestTokenPool.RateLimitConfig{ | ||
Enabled: true, | ||
Capacity: uint64(1000), | ||
Rate: 1, | ||
} | ||
outboundConfig := solTestTokenPool.RateLimitConfig{ | ||
Enabled: false, | ||
Capacity: 0, | ||
Rate: 0, | ||
} | ||
|
||
tokenMap := map[string]solana.PublicKey{ | ||
deployment.SPL2022Tokens: newTokenAddress, | ||
deployment.SPLTokens: state.SolChains[solChain].WSOL, | ||
} | ||
|
||
for tokenProgramName, tokenAddress := range tokenMap { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit : how about you update the CS input to receive multiple token programs and token addresses. IRL you might also need to do it for multiple tokens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am refraining from doing that for token pool changesets as we should not be deploying more than a couple. |
||
e, err = commonchangeset.Apply(t, e, nil, | ||
commonchangeset.Configure( | ||
deployment.CreateLegacyChangeSet(changeset_solana.AddTokenPool), | ||
changeset_solana.TokenPoolConfig{ | ||
ChainSelector: solChain, | ||
TokenPubKey: tokenAddress.String(), | ||
TokenProgramName: tokenProgramName, | ||
PoolType: solTestTokenPool.LockAndRelease_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: e.SolChains[solChain].DeployerKey.PublicKey().String(), | ||
}, | ||
OutboundRateLimit: solTestTokenPool.RateLimitConfig{ | ||
Enabled: false, | ||
Capacity: 0, | ||
Rate: 0, | ||
), | ||
commonchangeset.Configure( | ||
deployment.CreateLegacyChangeSet(changeset_solana.SetupTokenPoolForRemoteChain), | ||
changeset_solana.RemoteChainTokenPoolConfig{ | ||
SolChainSelector: solChain, | ||
RemoteChainSelector: evmChain, | ||
SolTokenPubKey: tokenAddress.String(), | ||
RemoteConfig: remoteConfig, | ||
InboundRateLimit: inboundConfig, | ||
OutboundRateLimit: outboundConfig, | ||
}, | ||
}, | ||
), | ||
) | ||
require.NoError(t, err) | ||
|
||
// test AddTokenPool results | ||
poolConfigPDA, err := solTokenUtil.TokenPoolConfigAddress(tokenAddress, state.SolChains[solChain].TokenPool) | ||
require.NoError(t, err) | ||
var configAccount solTestTokenPool.State | ||
err = e.SolChains[solChain].GetAccountDataBorshInto(ctx, poolConfigPDA, &configAccount) | ||
require.NoError(t, err) | ||
require.Equal(t, solTestTokenPool.LockAndRelease_PoolType, configAccount.PoolType) | ||
require.Equal(t, tokenAddress, configAccount.Config.Mint) | ||
// try minting after this and see if the pool or the deployer key is the authority | ||
|
||
// test SetupTokenPoolForRemoteChain results | ||
remoteChainConfigPDA, _, _ := solTokenUtil.TokenPoolChainConfigPDA(evmChain, tokenAddress, state.SolChains[solChain].TokenPool) | ||
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) | ||
), | ||
) | ||
require.NoError(t, err) | ||
|
||
// test AddTokenPool results | ||
poolConfigPDA, err := solTokenUtil.TokenPoolConfigAddress(tokenAddress, state.SolChains[solChain].TokenPool) | ||
require.NoError(t, err) | ||
var configAccount solTestTokenPool.State | ||
err = e.SolChains[solChain].GetAccountDataBorshInto(ctx, poolConfigPDA, &configAccount) | ||
require.NoError(t, err) | ||
require.Equal(t, solTestTokenPool.LockAndRelease_PoolType, configAccount.PoolType) | ||
require.Equal(t, tokenAddress, configAccount.Config.Mint) | ||
|
||
// test SetupTokenPoolForRemoteChain results | ||
remoteChainConfigPDA, _, _ := solTokenUtil.TokenPoolChainConfigPDA(evmChain, tokenAddress, state.SolChains[solChain].TokenPool) | ||
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) { | ||
|
@@ -345,7 +352,6 @@ func TestTokenAdminRegistry(t *testing.T) { | |
require.Equal(t, tokenAdminRegistryAdminPrivKey.PublicKey(), tokenAdminRegistryAccount.Administrator) | ||
require.Equal(t, solana.PublicKey{}, tokenAdminRegistryAccount.PendingAdministrator) | ||
|
||
// TODO: transfer and accept is breaking | ||
newTokenAdminRegistryAdminPrivKey, _ := solana.NewRandomPrivateKey() | ||
tt-cll marked this conversation as resolved.
Show resolved
Hide resolved
|
||
e, err = commonchangeset.Apply(t, e, nil, | ||
commonchangeset.Configure( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should make
AddRemoteChainToSolana
idempotent. Doesn't have to be in this PR