Skip to content

Commit

Permalink
integrate withdraw spl create ata fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Dec 3, 2024
1 parent 30924dc commit fdd215c
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 165 deletions.
Binary file modified contrib/localnet/solana/gateway.so
Binary file not shown.
3 changes: 1 addition & 2 deletions contrib/localnet/solana/start-solana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ echo "starting solana test validator..."
solana-test-validator &

sleep 5
# airdrop to e2e sol account and rent payer (used to generate atas for withdraw spl receivers if they don't exist)
# airdrop to e2e sol account
solana airdrop 100
solana airdrop 100 37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ
solana airdrop 100 C6KPvGDYfNusoE4yfRP21F8wK35bxCBMT69xk4xo3X79
solana program deploy gateway.so


Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/test_spl_withdraw_and_create_receiver_ata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

// TestSPLWithdrawAndCreateReceiverAta withdraws spl, but letting gateway to create receiver ata using rent payer
// TestSPLWithdrawAndCreateReceiverAta withdraws spl, but letting gateway to create receiver ata
// instead of providing receiver that has it already created
func TestSPLWithdrawAndCreateReceiverAta(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)
Expand Down
24 changes: 0 additions & 24 deletions e2e/runner/setup_solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,6 @@ func (r *E2ERunner) SetupSolana(gatewayID, deployerPrivateKey string) {
require.NoError(r, err)
r.Logger.Info("initial PDA balance: %d lamports", balance.Value)

// initialize rent payer
var instRentPayer solana.GenericInstruction
rentPayerPdaComputed := r.SolanaRentPayerPDA()

// create 'initialize_rent_payer' instruction
accountSlice = []*solana.AccountMeta{}
accountSlice = append(accountSlice, solana.Meta(rentPayerPdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(privkey.PublicKey()).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
instRentPayer.ProgID = r.GatewayProgram
instRentPayer.AccountValues = accountSlice

instRentPayer.DataBytes, err = borsh.Serialize(solanacontracts.InitializeRentPayerParams{
Discriminator: solanacontracts.DiscriminatorInitializeRentPayer,
})
require.NoError(r, err)

// create and sign the transaction
signedTx = r.CreateSignedTransaction([]solana.Instruction{&instRentPayer}, privkey, []solana.PrivateKey{})

// broadcast the transaction and wait for finalization
_, out = r.BroadcastTxSync(signedTx)
r.Logger.Info("initialize_rent_payer logs: %v", out.Meta.LogMessages)

err = r.ensureSolanaChainParams()
require.NoError(r, err)

Expand Down
11 changes: 0 additions & 11 deletions e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ func (r *E2ERunner) ComputePdaAddress() solana.PublicKey {
return pdaComputed
}

// SolanaRentPayerPDA computes the rent payer PDA (Program Derived Address) address for the gateway program
func (r *E2ERunner) SolanaRentPayerPDA() solana.PublicKey {
seed := []byte(solanacontract.RentPayerPDASeed)
pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, r.GatewayProgram)
require.NoError(r, err)

r.Logger.Info("computed rent payer pda: %s, bump %d\n", pdaComputed, bump)

return pdaComputed
}

// CreateDepositInstruction creates a 'deposit' instruction
func (r *E2ERunner) CreateDepositInstruction(
signer solana.PublicKey,
Expand Down
15 changes: 0 additions & 15 deletions pkg/contracts/solana/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const (
// PDASeed is the seed for the Solana gateway program derived address
PDASeed = "meta"

// RentPayerPDASeed is the seed for the Solana gateway program derived address
RentPayerPDASeed = "rent-payer"

// AccountsNumberOfDeposit is the number of accounts required for Solana gateway deposit instruction
// [signer, pda, system_program]
accountsNumDeposit = 3
Expand All @@ -27,9 +24,6 @@ var (
// DiscriminatorInitialize returns the discriminator for Solana gateway 'initialize' instruction
DiscriminatorInitialize = idlgateway.IDLGateway.GetDiscriminator("initialize")

// DiscriminatorInitializeRentPayer returns the discriminator for Solana gateway 'initialize_rent_payer' instruction
DiscriminatorInitializeRentPayer = idlgateway.IDLGateway.GetDiscriminator("initialize_rent_payer")

// DiscriminatorDeposit returns the discriminator for Solana gateway 'deposit' instruction
DiscriminatorDeposit = idlgateway.IDLGateway.GetDiscriminator("deposit")

Expand Down Expand Up @@ -62,12 +56,3 @@ func ParseGatewayWithPDA(gatewayAddress string) (solana.PublicKey, solana.Public

return gatewayID, pda, err
}

// ParseRentPayerPDA parses the rent payer program derived address from the given string
func RentPayerPDA(gateway solana.PublicKey) (solana.PublicKey, error) {
var rentPayerPda solana.PublicKey
seed := []byte(RentPayerPDASeed)
rentPayerPda, _, err := solana.FindProgramAddress([][]byte{seed}, gateway)

return rentPayerPda, err
}
91 changes: 0 additions & 91 deletions pkg/contracts/solana/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,54 +375,6 @@
}
]
},
{
"name": "initialize_rent_payer",
"discriminator": [
225,
73,
166,
180,
25,
245,
183,
96
],
"accounts": [
{
"name": "rent_payer_pda",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
114,
101,
110,
116,
45,
112,
97,
121,
101,
114
]
}
]
}
},
{
"name": "authority",
"writable": true,
"signer": true
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": []
},
{
"name": "set_deposit_paused",
"discriminator": [
Expand Down Expand Up @@ -878,29 +830,6 @@
],
"writable": true
},
{
"name": "rent_payer_pda",
"writable": true,
"pda": {
"seeds": [
{
"kind": "const",
"value": [
114,
101,
110,
116,
45,
112,
97,
121,
101,
114
]
}
]
}
},
{
"name": "token_program",
"address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
Expand Down Expand Up @@ -966,19 +895,6 @@
94
]
},
{
"name": "RentPayerPda",
"discriminator": [
48,
247,
192,
150,
46,
218,
14,
121
]
},
{
"name": "WhitelistEntry",
"discriminator": [
Expand Down Expand Up @@ -1084,13 +1000,6 @@
]
}
},
{
"name": "RentPayerPda",
"type": {
"kind": "struct",
"fields": []
}
},
{
"name": "WhitelistEntry",
"type": {
Expand Down
6 changes: 0 additions & 6 deletions pkg/contracts/solana/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ type InitializeParams struct {
ChainID uint64
}

// InitializeRentPayerParams contains the parameters for a gateway initialize_rent_payer instruction
type InitializeRentPayerParams struct {
// Discriminator is the unique identifier for the initialize_rent_payer instruction
Discriminator [8]byte
}

// DepositInstructionParams contains the parameters for a gateway deposit instruction
type DepositInstructionParams struct {
// Discriminator is the unique identifier for the deposit instruction
Expand Down
18 changes: 4 additions & 14 deletions zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ type Signer struct {

// pda is the program derived address of the gateway program
pda solana.PublicKey

// rent payer pda is the program derived address of the gateway program to pay rent for creating atas
rentPayerPda solana.PublicKey
}

// NewSigner creates a new Solana signer
Expand All @@ -68,19 +65,12 @@ func NewSigner(
return nil, errors.Wrapf(err, "cannot parse gateway address %s", chainParams.GatewayAddress)
}

// parse rent payer PDA, used in case receiver ATA should be created in gateway
rentPayerPda, err := contracts.RentPayerPDA(gatewayID)
if err != nil {
return nil, errors.Wrapf(err, "cannot parse gateway address %s", chainParams.GatewayAddress)
}

// create Solana signer
signer := &Signer{
Signer: baseSigner,
client: solClient,
gatewayID: gatewayID,
pda: pda,
rentPayerPda: rentPayerPda,
Signer: baseSigner,
client: solClient,
gatewayID: gatewayID,
pda: pda,
}

// construct Solana private key if present
Expand Down
1 change: 0 additions & 1 deletion zetaclient/chains/solana/signer/withdraw_spl.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ func (signer *Signer) signWithdrawSPLTx(
solana.Meta(msg.MintAccount()),
solana.Meta(msg.To()),
solana.Meta(recipientAta).WRITE(),
solana.Meta(signer.rentPayerPda).WRITE(),
solana.Meta(solana.TokenProgramID),
solana.Meta(solana.SPLAssociatedTokenAccountProgramID),
solana.Meta(solana.SystemProgramID),
Expand Down

0 comments on commit fdd215c

Please sign in to comment.