diff --git a/changelog.md b/changelog.md index 805c6d4a26..5b9b767877 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ ### Features * [2984](https://github.com/zeta-chain/node/pull/2984) - add Whitelist message ability to whitelist SPL tokens on Solana * [3091](https://github.com/zeta-chain/node/pull/3091) - improve build reproducability. `make release{,-build-only}` checksums should now be stable. +* [3124](https://github.com/zeta-chain/node/pull/3124) - deposit spl integration ### Tests * [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert. diff --git a/e2e/runner/solana.go b/e2e/runner/solana.go index 69352cf6be..69d74cd9d2 100644 --- a/e2e/runner/solana.go +++ b/e2e/runner/solana.go @@ -9,7 +9,6 @@ import ( associatedtokenaccount "github.com/gagliardetto/solana-go/programs/associated-token-account" "github.com/gagliardetto/solana-go/programs/system" "github.com/gagliardetto/solana-go/programs/token" - "github.com/gagliardetto/solana-go/rpc" "github.com/near/borsh-go" "github.com/stretchr/testify/require" @@ -188,7 +187,11 @@ func (r *E2ERunner) CreateSignedTransaction( return tx } -func (r *E2ERunner) FindOrCreateAssociatedTokenAccount(payer solana.PrivateKey, owner solana.PublicKey, tokenAccount solana.PublicKey) solana.PublicKey { +func (r *E2ERunner) FindOrCreateAssociatedTokenAccount( + payer solana.PrivateKey, + owner solana.PublicKey, + tokenAccount solana.PublicKey, +) solana.PublicKey { pdaAta, _, err := solana.FindAssociatedTokenAddress(owner, tokenAccount) require.NoError(r, err) @@ -210,7 +213,13 @@ func (r *E2ERunner) FindOrCreateAssociatedTokenAccount(payer solana.PrivateKey, return pdaAta } -func (r *E2ERunner) DepositSPL(privateKey *solana.PrivateKey, amount uint64, tokenAccount solana.PublicKey, receiver ethcommon.Address, data []byte) solana.Signature { +func (r *E2ERunner) DepositSPL( + privateKey *solana.PrivateKey, + amount uint64, + tokenAccount solana.PublicKey, + receiver ethcommon.Address, + data []byte, +) solana.Signature { // ata for pda pda := r.ComputePdaAddress() pdaAta := r.FindOrCreateAssociatedTokenAccount(*privateKey, pda, tokenAccount) @@ -223,7 +232,16 @@ func (r *E2ERunner) DepositSPL(privateKey *solana.PrivateKey, amount uint64, tok whitelistEntryPDA, _, err := solana.FindProgramAddress(seed, r.GatewayProgram) require.NoError(r, err) - depositSPLInstruction := r.CreateDepositSPLInstruction(amount, privateKey.PublicKey(), whitelistEntryPDA, tokenAccount, ata, pdaAta, receiver, data) + depositSPLInstruction := r.CreateDepositSPLInstruction( + amount, + privateKey.PublicKey(), + whitelistEntryPDA, + tokenAccount, + ata, + pdaAta, + receiver, + data, + ) signedTx := r.CreateSignedTransaction( []solana.Instruction{depositSPLInstruction}, *privateKey, @@ -270,7 +288,8 @@ func (r *E2ERunner) DeploySPL(privateKey *solana.PrivateKey, whitelist bool, amo // minting some tokens to deployer for testing ata := r.FindOrCreateAssociatedTokenAccount(*privateKey, privateKey.PublicKey(), tokenAccount.PublicKey()) - mintToInstruction := token.NewMintToInstruction(amountToMint, tokenAccount.PublicKey(), ata, privateKey.PublicKey(), []solana.PublicKey{}).Build() + mintToInstruction := token.NewMintToInstruction(amountToMint, tokenAccount.PublicKey(), ata, privateKey.PublicKey(), []solana.PublicKey{}). + Build() signedTx = r.CreateSignedTransaction( []solana.Instruction{mintToInstruction}, *privateKey, @@ -296,7 +315,11 @@ func (r *E2ERunner) DeploySPL(privateKey *solana.PrivateKey, whitelist bool, amo } // create 'whitelist_spl_mint' instruction - instruction := r.CreateWhitelistSPLMintInstruction(privateKey.PublicKey(), whitelistEntryPDA, tokenAccount.PublicKey()) + instruction := r.CreateWhitelistSPLMintInstruction( + privateKey.PublicKey(), + whitelistEntryPDA, + tokenAccount.PublicKey(), + ) // create and sign the transaction signedTx := r.CreateSignedTransaction([]solana.Instruction{instruction}, *privateKey, []solana.PrivateKey{}) diff --git a/x/fungible/keeper/foreign_coins.go b/x/fungible/keeper/foreign_coins.go index 3851de88fd..23cd1b6375 100644 --- a/x/fungible/keeper/foreign_coins.go +++ b/x/fungible/keeper/foreign_coins.go @@ -109,14 +109,8 @@ func (k Keeper) GetGasCoinForForeignCoin(ctx sdk.Context, chainID int64) (types. // GetForeignCoinFromAsset returns the foreign coin for a given asset for a given chain func (k Keeper) GetForeignCoinFromAsset(ctx sdk.Context, asset string, chainID int64) (types.ForeignCoins, bool) { - // if !ethcommon.IsHexAddress(asset) { - // return types.ForeignCoins{}, false - // } - // assetAddr := ethcommon.HexToAddress(asset) - foreignCoinList := k.GetAllForeignCoinsForChain(ctx, chainID) for _, coin := range foreignCoinList { - // coinAssetAddr := ethcommon.HexToAddress(coin.Asset) if asset == coin.Asset && coin.ForeignChainId == chainID { return coin, true } diff --git a/x/fungible/keeper/foreign_coins_test.go b/x/fungible/keeper/foreign_coins_test.go index d02c3a29c9..8dda8c0204 100644 --- a/x/fungible/keeper/foreign_coins_test.go +++ b/x/fungible/keeper/foreign_coins_test.go @@ -136,23 +136,24 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) { require.False(t, found) }) - t.Run("can get foreign coin with non-checksum address", func(t *testing.T) { - k, ctx, _, _ := keepertest.FungibleKeeper(t) - - setForeignCoins(ctx, k, - types.ForeignCoins{ - Zrc20ContractAddress: sample.EthAddress().String(), - Asset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", - ForeignChainId: 1, - CoinType: coin.CoinType_ERC20, - Name: "foo", - }, - ) - - fc, found := k.GetForeignCoinFromAsset(ctx, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 1) - require.True(t, found) - require.Equal(t, "foo", fc.Name) - }) + // TODO: add validation per chain on setting foreign coin, not when getting + // t.Run("can get foreign coin with non-checksum address", func(t *testing.T) { + // k, ctx, _, _ := keepertest.FungibleKeeper(t) + + // setForeignCoins(ctx, k, + // types.ForeignCoins{ + // Zrc20ContractAddress: sample.EthAddress().String(), + // Asset: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", + // ForeignChainId: 1, + // CoinType: coin.CoinType_ERC20, + // Name: "foo", + // }, + // ) + + // fc, found := k.GetForeignCoinFromAsset(ctx, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 1) + // require.True(t, found) + // require.Equal(t, "foo", fc.Name) + // }) } func TestKeeperGetAllForeignCoinMap(t *testing.T) { diff --git a/zetaclient/chains/solana/observer/inbound.go b/zetaclient/chains/solana/observer/inbound.go index abe6fb6a09..0a1f82193e 100644 --- a/zetaclient/chains/solana/observer/inbound.go +++ b/zetaclient/chains/solana/observer/inbound.go @@ -398,10 +398,17 @@ func (ob *Observer) GetSignerDeposit(tx *solana.Transaction, inst *solana.Compil return tx.Message.AccountKeys[signerIndex].String(), nil } -func (ob *Observer) GetFromDepositSPLAccounts(tx *solana.Transaction, inst *solana.CompiledInstruction) (string, string, error) { +func (ob *Observer) GetFromDepositSPLAccounts( + tx *solana.Transaction, + inst *solana.CompiledInstruction, +) (string, string, error) { // there should be 7 accounts for a deposit spl instruction if len(inst.Accounts) != solanacontracts.AccountsNumberDepositSPL { - return "", "", fmt.Errorf("want %d accounts, got %d", solanacontracts.AccountsNumberDepositSPL, len(inst.Accounts)) + return "", "", fmt.Errorf( + "want %d accounts, got %d", + solanacontracts.AccountsNumberDepositSPL, + len(inst.Accounts), + ) } // the accounts are [signer, pda, whitelist_entry, mint_account, token_program, from, to]