Skip to content

Commit

Permalink
Merge branch 'release/v23' into feat/disable-eip-1559
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis authored Dec 4, 2024
2 parents 415f9b6 + d3c2598 commit c80f61b
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 177 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
4 changes: 2 additions & 2 deletions e2e/e2etests/test_spl_withdraw_and_create_receiver_ata.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

// TestSPLWithdrawAndCreateReceiverAta withdraws spl, but letting gateway to create receiver ata using rent payer
// instead of providing receiver that has it already created
// TestSPLWithdrawAndCreateReceiverAta withdraws SPL, but letting gateway program to create receiver ATA
// using PDA funds, instead of providing already created ATA
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
14 changes: 2 additions & 12 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 Expand Up @@ -110,12 +99,13 @@ func (r *E2ERunner) CreateDepositSPLInstruction(
DataBytes: depositSPLData,
AccountValues: []*solana.AccountMeta{
solana.Meta(signer).WRITE().SIGNER(),
solana.Meta(r.ComputePdaAddress()),
solana.Meta(r.ComputePdaAddress()).WRITE(),
solana.Meta(whitelistEntry),
solana.Meta(mint),
solana.Meta(solana.TokenProgramID),
solana.Meta(from).WRITE(),
solana.Meta(to).WRITE(),
solana.Meta(solana.SystemProgramID),
},
}
}
Expand Down
19 changes: 2 additions & 17 deletions pkg/contracts/solana/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,19 @@ 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

// AccountsNumberOfDeposit is the number of accounts required for Solana gateway deposit spl instruction
// [signer, pda, whitelist_entry, mint_account, token_program, from, to]
accountsNumberDepositSPL = 7
// [signer, pda, whitelist_entry, mint_account, token_program, from, to, system_program]
accountsNumberDepositSPL = 8
)

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
}
106 changes: 15 additions & 91 deletions pkg/contracts/solana/gateway.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
},
{
"name": "pda",
"writable": true,
"pda": {
"seeds": [
{
Expand Down Expand Up @@ -196,6 +197,10 @@
{
"name": "to",
"writable": true
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
Expand Down Expand Up @@ -234,6 +239,7 @@
},
{
"name": "pda",
"writable": true,
"pda": {
"seeds": [
{
Expand Down Expand Up @@ -287,6 +293,10 @@
{
"name": "to",
"writable": true
},
{
"name": "system_program",
"address": "11111111111111111111111111111111"
}
],
"args": [
Expand Down Expand Up @@ -365,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 @@ -868,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 @@ -956,19 +895,6 @@
94
]
},
{
"name": "RentPayerPda",
"discriminator": [
48,
247,
192,
150,
46,
218,
14,
121
]
},
{
"name": "WhitelistEntry",
"discriminator": [
Expand Down Expand Up @@ -1033,6 +959,11 @@
"code": 6009,
"name": "SPLAtaAndMintAddressMismatch",
"msg": "SPLAtaAndMintAddressMismatch"
},
{
"code": 6010,
"name": "EmptyReceiver",
"msg": "EmptyReceiver"
}
],
"types": [
Expand Down Expand Up @@ -1069,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"8vquQi8xNxxBTsohf1u8xQHYbo7Fv8BEWCJz63RJSaeE",
"4GddKQ7baJpMyKna7bPPnhh7UQtpzfSGL1FgZ31hj4mp",
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"11111111111111111111111111111111",
"94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"
],
"header": {
Expand All @@ -24,15 +25,16 @@
"recentBlockhash": "5ZB2NWKwp86t47ojCHPjRyd5vMKSWBdhxqDdtSZVPUj",
"instructions": [
{
"programIdIndex": 7,
"programIdIndex": 8,
"accounts": [
0,
3,
4,
5,
6,
1,
2
2,
7
],
"data": "5JndgWCNHDyr2qQccK9VM1NxJFrVbUDvG2hfAxRC5z6nPPAVPsj7q3A"
}
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
Loading

0 comments on commit c80f61b

Please sign in to comment.