Skip to content

Commit

Permalink
CI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Nov 7, 2024
1 parent 1f80aac commit 7015f82
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 29 additions & 6 deletions e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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{})

Expand Down
6 changes: 0 additions & 6 deletions x/fungible/keeper/foreign_coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
35 changes: 18 additions & 17 deletions x/fungible/keeper/foreign_coins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions zetaclient/chains/solana/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 7015f82

Please sign in to comment.