diff --git a/e2e/e2etests/test_solana_deposit_call.go b/e2e/e2etests/test_solana_deposit_call.go index 2692936a9e..0d7ef97975 100644 --- a/e2e/e2etests/test_solana_deposit_call.go +++ b/e2e/e2etests/test_solana_deposit_call.go @@ -31,5 +31,5 @@ func TestSolanaDepositAndCall(r *runner.E2ERunner, args []string) { utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) // check if example contract has been called, bar value should be set to amount - utils.MustHaveCalledExampleContract(r, contract, depositAmount) + utils.MustHaveCalledExampleContractWithMsg(r, contract, depositAmount, data) } diff --git a/e2e/e2etests/test_spl_deposit_and_call.go b/e2e/e2etests/test_spl_deposit_and_call.go index d7e11cd999..9c15c8c27f 100644 --- a/e2e/e2etests/test_spl_deposit_and_call.go +++ b/e2e/e2etests/test_spl_deposit_and_call.go @@ -51,7 +51,7 @@ func TestSPLDepositAndCall(r *runner.E2ERunner, args []string) { utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) // check if example contract has been called, bar value should be set to amount - utils.MustHaveCalledExampleContract(r, contract, big.NewInt(int64(amount))) + utils.MustHaveCalledExampleContractWithMsg(r, contract, big.NewInt(int64(amount)), data) // verify balances are updated pdaBalanceAfter, err := r.SolanaClient.GetTokenAccountBalance(r.Ctx, pdaAta, rpc.CommitmentFinalized) diff --git a/e2e/runner/solana.go b/e2e/runner/solana.go index bc940db79f..cc9e6dbe2b 100644 --- a/e2e/runner/solana.go +++ b/e2e/runner/solana.go @@ -36,12 +36,24 @@ func (r *E2ERunner) CreateDepositInstruction( data []byte, amount uint64, ) solana.Instruction { - depositData, err := borsh.Serialize(solanacontract.DepositInstructionParams{ - Discriminator: solanacontract.DiscriminatorDeposit, - Amount: amount, - Memo: append(receiver.Bytes(), data...), - }) - require.NoError(r, err) + var err error + var depositData []byte + if data == nil { + depositData, err = borsh.Serialize(solanacontract.DepositInstructionParams{ + Discriminator: solanacontract.DiscriminatorDeposit, + Amount: amount, + Receiver: receiver, + }) + require.NoError(r, err) + } else { + depositData, err = borsh.Serialize(solanacontract.DepositAndCallInstructionParams{ + Discriminator: solanacontract.DiscriminatorDepositAndCall, + Amount: amount, + Receiver: receiver, + Memo: data, + }) + require.NoError(r, err) + } return &solana.GenericInstruction{ ProgID: r.GatewayProgram, @@ -87,12 +99,24 @@ func (r *E2ERunner) CreateDepositSPLInstruction( receiver ethcommon.Address, data []byte, ) solana.Instruction { - depositSPLData, err := borsh.Serialize(solanacontract.DepositInstructionParams{ - Discriminator: solanacontract.DiscriminatorDepositSPL, - Amount: amount, - Memo: append(receiver.Bytes(), data...), - }) - require.NoError(r, err) + var err error + var depositSPLData []byte + if data == nil { + depositSPLData, err = borsh.Serialize(solanacontract.DepositSPLInstructionParams{ + Discriminator: solanacontract.DiscriminatorDepositSPL, + Amount: amount, + Receiver: receiver, + }) + require.NoError(r, err) + } else { + depositSPLData, err = borsh.Serialize(solanacontract.DepositSPLAndCallInstructionParams{ + Discriminator: solanacontract.DiscriminatorDepositSPLAndCall, + Amount: amount, + Receiver: receiver, + Memo: data, + }) + require.NoError(r, err) + } return &solana.GenericInstruction{ ProgID: r.GatewayProgram, diff --git a/e2e/utils/contracts.go b/e2e/utils/contracts.go index 7593253725..8953584b28 100644 --- a/e2e/utils/contracts.go +++ b/e2e/utils/contracts.go @@ -31,3 +31,26 @@ func MustHaveCalledExampleContract( amount.String(), ) } + +// MustHaveCalledExampleContractWithMsg checks if the contract has been called correctly with correct amount and msg +func MustHaveCalledExampleContractWithMsg( + t require.TestingT, + contract *testcontract.Example, + amount *big.Int, + msg []byte, +) { + bar, err := contract.Bar(&bind.CallOpts{}) + require.NoError(t, err) + require.Equal( + t, + 0, + bar.Cmp(amount), + "cross-chain call failed bar value %s should be equal to amount %s", + bar.String(), + amount.String(), + ) + + lastMsg, err := contract.LastMessage(&bind.CallOpts{}) + require.NoError(t, err) + require.Equal(t, string(msg), string(lastMsg)) +} diff --git a/pkg/contracts/solana/gateway.go b/pkg/contracts/solana/gateway.go index c1b859cd33..29d547d374 100644 --- a/pkg/contracts/solana/gateway.go +++ b/pkg/contracts/solana/gateway.go @@ -27,9 +27,15 @@ var ( // DiscriminatorDeposit returns the discriminator for Solana gateway 'deposit' instruction DiscriminatorDeposit = idlgateway.IDLGateway.GetDiscriminator("deposit") + // DiscriminatorDeposit returns the discriminator for Solana gateway 'deposit_and_call' instruction + DiscriminatorDepositAndCall = idlgateway.IDLGateway.GetDiscriminator("deposit_and_call") + // DiscriminatorDepositSPL returns the discriminator for Solana gateway 'deposit_spl_token' instruction DiscriminatorDepositSPL = idlgateway.IDLGateway.GetDiscriminator("deposit_spl_token") + // DiscriminatorDepositSPLAndCall returns the discriminator for Solana gateway 'deposit_spl_token_and_call' instruction + DiscriminatorDepositSPLAndCall = idlgateway.IDLGateway.GetDiscriminator("deposit_spl_token_and_call") + // DiscriminatorWithdraw returns the discriminator for Solana gateway 'withdraw' instruction DiscriminatorWithdraw = idlgateway.IDLGateway.GetDiscriminator("withdraw") diff --git a/pkg/contracts/solana/inbound.go b/pkg/contracts/solana/inbound.go index 3b2e153606..e4695e0b48 100644 --- a/pkg/contracts/solana/inbound.go +++ b/pkg/contracts/solana/inbound.go @@ -20,24 +20,39 @@ type Deposit struct { Asset string } -// ParseInboundAsDeposit tries to parse an instruction as a 'deposit'. -// It returns nil if the instruction can't be parsed as a 'deposit'. +// ParseInboundAsDeposit tries to parse an instruction as a 'deposit' or 'deposit_and_call'. +// It returns nil if the instruction can't be parsed. func ParseInboundAsDeposit( tx *solana.Transaction, instructionIndex int, slot uint64, +) (*Deposit, error) { + // first try to parse as deposit, then as deposit_and_call + deposit, err := tryParseAsDeposit(tx, instructionIndex, slot) + if deposit != nil || err != nil { + return deposit, err + } + + return tryParseAsDepositAndCall(tx, instructionIndex, slot) +} + +// tryParseAsDeposit tries to parse instruction as deposit +func tryParseAsDeposit( + tx *solana.Transaction, + instructionIndex int, + slot uint64, ) (*Deposit, error) { // get instruction by index instruction := tx.Message.Instructions[instructionIndex] // try deserializing instruction as a 'deposit' - var inst DepositInstructionParams + inst := DepositInstructionParams{} + err := borsh.Deserialize(&inst, instruction.Data) if err != nil { return nil, nil } - // check if the instruction is a deposit or not, if not, skip parsing if inst.Discriminator != DiscriminatorDeposit { return nil, nil } @@ -51,30 +66,81 @@ func ParseInboundAsDeposit( return &Deposit{ Sender: sender, Amount: inst.Amount, - Memo: inst.Memo, + Memo: inst.Receiver[:], + Slot: slot, + Asset: "", // no asset for gas token SOL + }, nil +} + +// tryParseAsDepositAndCall tries to parse instruction as deposit_and_call +func tryParseAsDepositAndCall( + tx *solana.Transaction, + instructionIndex int, + slot uint64, +) (*Deposit, error) { + // get instruction by index + instruction := tx.Message.Instructions[instructionIndex] + + // try deserializing instruction as a 'deposit_and_call' + instDepositAndCall := DepositAndCallInstructionParams{} + err := borsh.Deserialize(&instDepositAndCall, instruction.Data) + if err != nil { + return nil, nil + } + + // check if the instruction is a deposit_and_call or not, if not, skip parsing + if instDepositAndCall.Discriminator != DiscriminatorDepositAndCall { + return nil, nil + } + + // get the sender address (skip if unable to parse signer address) + sender, err := getSignerDeposit(tx, &instruction) + if err != nil { + return nil, err + } + return &Deposit{ + Sender: sender, + Amount: instDepositAndCall.Amount, + Memo: append(instDepositAndCall.Receiver[:], instDepositAndCall.Memo...), Slot: slot, Asset: "", // no asset for gas token SOL }, nil } -// ParseInboundAsDepositSPL tries to parse an instruction as a 'deposit_spl_token'. -// It returns nil if the instruction can't be parsed as a 'deposit_spl_token'. +// ParseInboundAsDepositSPL tries to parse an instruction as a 'deposit_spl' or 'deposit_spl_and_call'. +// It returns nil if the instruction can't be parsed as a 'deposit_spl'. func ParseInboundAsDepositSPL( tx *solana.Transaction, instructionIndex int, slot uint64, +) (*Deposit, error) { + // first try to parse as deposit_spl, then as deposit_spl_and_call + deposit, err := tryParseAsDepositSPL(tx, instructionIndex, slot) + if deposit != nil || err != nil { + return deposit, err + } + + return tryParseAsDepositSPLAndCall(tx, instructionIndex, slot) +} + +// tryParseAsDepositSPL tries to parse instruction as deposit_spl +func tryParseAsDepositSPL( + tx *solana.Transaction, + instructionIndex int, + slot uint64, ) (*Deposit, error) { // get instruction by index instruction := tx.Message.Instructions[instructionIndex] - // try deserializing instruction as a 'deposit_spl_token' + // try deserializing instruction as a 'deposit_spl' var inst DepositSPLInstructionParams + + // check if the instruction is a 'deposit_spl' or not, if not, try to parse as 'deposit_spl_and_call' err := borsh.Deserialize(&inst, instruction.Data) if err != nil { return nil, nil } - // check if the instruction is a deposit spl or not, if not, skip parsing if inst.Discriminator != DiscriminatorDepositSPL { return nil, nil } @@ -88,7 +154,42 @@ func ParseInboundAsDepositSPL( return &Deposit{ Sender: sender, Amount: inst.Amount, - Memo: inst.Memo, + Memo: inst.Receiver[:], + Slot: slot, + Asset: spl, + }, nil +} + +// tryParseAsDepositSPLAndCall tries to parse instruction as deposit_spl_and_call +func tryParseAsDepositSPLAndCall( + tx *solana.Transaction, + instructionIndex int, + slot uint64, +) (*Deposit, error) { + // get instruction by index + instruction := tx.Message.Instructions[instructionIndex] + + // try deserializing instruction as a 'deposit_spl_and_call' + instDepositAndCall := DepositSPLAndCallInstructionParams{} + err := borsh.Deserialize(&instDepositAndCall, instruction.Data) + if err != nil { + return nil, nil + } + + // check if the instruction is a 'deposit_spl_and_call' or not, if not, skip parsing + if instDepositAndCall.Discriminator != DiscriminatorDepositSPLAndCall { + return nil, nil + } + + // get the sender and spl addresses + sender, spl, err := getSignerAndSPLFromDepositSPLAccounts(tx, &instruction) + if err != nil { + return nil, err + } + return &Deposit{ + Sender: sender, + Amount: instDepositAndCall.Amount, + Memo: append(instDepositAndCall.Receiver[:], instDepositAndCall.Memo...), Slot: slot, Asset: spl, }, nil diff --git a/pkg/contracts/solana/inbound_test.go b/pkg/contracts/solana/inbound_test.go index b6550d99fd..a803ebf877 100644 --- a/pkg/contracts/solana/inbound_test.go +++ b/pkg/contracts/solana/inbound_test.go @@ -87,7 +87,7 @@ func Test_ParseInboundAsDeposit(t *testing.T) { data, err := borsh.Serialize(DepositInstructionParams{ Amount: inst.Amount, Discriminator: DiscriminatorDepositSPL, - Memo: inst.Memo, + Receiver: inst.Receiver, }) require.NoError(t, err) @@ -191,7 +191,7 @@ func Test_ParseInboundAsDepositSPL(t *testing.T) { data, err := borsh.Serialize(DepositInstructionParams{ Amount: inst.Amount, Discriminator: DiscriminatorDeposit, - Memo: inst.Memo, + Receiver: inst.Receiver, }) require.NoError(t, err) diff --git a/pkg/contracts/solana/instruction.go b/pkg/contracts/solana/instruction.go index e11116e35f..2c0b31c2b4 100644 --- a/pkg/contracts/solana/instruction.go +++ b/pkg/contracts/solana/instruction.go @@ -30,19 +30,49 @@ type DepositInstructionParams struct { // Amount is the lamports amount for the deposit Amount uint64 - // Memo is the memo for the deposit + // Receiver is the receiver for the deposit + Receiver [20]byte +} + +// DepositAndCallInstructionParams contains the parameters for a gateway deposit_and_call instruction +type DepositAndCallInstructionParams struct { + // Discriminator is the unique identifier for the deposit_and_call instruction + Discriminator [8]byte + + // Amount is the lamports amount for the deposit_and_call + Amount uint64 + + // Receiver is the receiver for the deposit_and_call + Receiver [20]byte + + // Memo is the memo for the deposit_and_call Memo []byte } -// DepositSPLInstructionParams contains the parameters for a gateway deposit spl instruction +// DepositSPLInstructionParams contains the parameters for a gateway deposit_spl instruction type DepositSPLInstructionParams struct { - // Discriminator is the unique identifier for the deposit instruction + // Discriminator is the unique identifier for the deposit_spl instruction Discriminator [8]byte - // Amount is the lamports amount for the deposit + // Amount is the lamports amount for the deposit_spl + Amount uint64 + + // Receiver is the receiver for the deposit_spl + Receiver [20]byte +} + +// DepositSPLAndCallInstructionParams contains the parameters for a gateway deposit_spl_and_call instruction +type DepositSPLAndCallInstructionParams struct { + // Discriminator is the unique identifier for the deposit_spl_and_call instruction + Discriminator [8]byte + + // Amount is the lamports amount for the deposit_spl_and_call Amount uint64 - // Memo is the memo for the deposit + // Receiver is the receiver for the deposit_spl_and_call + Receiver [20]byte + + // Memo is the memo for the deposit_spl_and_call Memo []byte } diff --git a/testutil/contracts/Example.abi b/testutil/contracts/Example.abi index 26031cc7cf..ccf6aa55a9 100644 --- a/testutil/contracts/Example.abi +++ b/testutil/contracts/Example.abi @@ -50,6 +50,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "lastMessage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/testutil/contracts/Example.bin b/testutil/contracts/Example.bin index 2243b22b87..e7a2293644 100644 --- a/testutil/contracts/Example.bin +++ b/testutil/contracts/Example.bin @@ -1 +1 @@ -6080604052348015600f57600080fd5b506000808190555061043f806100266000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063afc874d214610067578063d720cb4514610071578063dd8e556c1461007b578063de43156e14610085578063fd5ad965146100a1578063febb0f7e146100ab575b600080fd5b61006f6100c9565b005b6100796100fb565b005b610083610136565b005b61009f600480360381019061009a91906102be565b610179565b005b6100a9610187565b005b6100b3610191565b6040516100c09190610371565b60405180910390f35b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012d906103e9565b60405180910390fd5b6000610177576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161016e906103e9565b60405180910390fd5b565b826000819055505050505050565b6001600081905550565b60005481565b600080fd5b600080fd5b600080fd5b6000606082840312156101bc576101bb6101a1565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101f0826101c5565b9050919050565b610200816101e5565b811461020b57600080fd5b50565b60008135905061021d816101f7565b92915050565b6000819050919050565b61023681610223565b811461024157600080fd5b50565b6000813590506102538161022d565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f84011261027e5761027d610259565b5b8235905067ffffffffffffffff81111561029b5761029a61025e565b5b6020830191508360018202830111156102b7576102b6610263565b5b9250929050565b6000806000806000608086880312156102da576102d9610197565b5b600086013567ffffffffffffffff8111156102f8576102f761019c565b5b610304888289016101a6565b95505060206103158882890161020e565b945050604061032688828901610244565b935050606086013567ffffffffffffffff8111156103475761034661019c565b5b61035388828901610268565b92509250509295509295909350565b61036b81610223565b82525050565b60006020820190506103866000830184610362565b92915050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006103d360038361038c565b91506103de8261039d565b602082019050919050565b60006020820190508181036000830152610402816103c6565b905091905056fea2646970667358221220c9cedad580b18532a00be1e615813af1c20bb609a0a69b5f36d49ed76cc20b5064736f6c63430008190033 +6080604052348015600f57600080fd5b50600080819055506108e0806100266000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063dd8e556c1161005b578063dd8e556c146100b4578063de43156e146100be578063fd5ad965146100da578063febb0f7e146100e45761007d565b80633297071014610082578063afc874d2146100a0578063d720cb45146100aa575b600080fd5b61008a610102565b6040516100979190610300565b60405180910390f35b6100a8610190565b005b6100b26101c2565b005b6100bc6101fd565b005b6100d860048036038101906100d39190610449565b610240565b005b6100e2610260565b005b6100ec61026a565b6040516100f991906104fc565b60405180910390f35b6001805461010f90610546565b80601f016020809104026020016040519081016040528092919081815260200182805461013b90610546565b80156101885780601f1061015d57610100808354040283529160200191610188565b820191906000526020600020905b81548152906001019060200180831161016b57829003601f168201915b505050505081565b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101f4906105d4565b60405180910390fd5b600061023e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610235906105d4565b60405180910390fd5b565b826000819055508181600191826102589291906107da565b505050505050565b6001600081905550565b60005481565b600081519050919050565b600082825260208201905092915050565b60005b838110156102aa57808201518184015260208101905061028f565b60008484015250505050565b6000601f19601f8301169050919050565b60006102d282610270565b6102dc818561027b565b93506102ec81856020860161028c565b6102f5816102b6565b840191505092915050565b6000602082019050818103600083015261031a81846102c7565b905092915050565b600080fd5b600080fd5b600080fd5b6000606082840312156103475761034661032c565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061037b82610350565b9050919050565b61038b81610370565b811461039657600080fd5b50565b6000813590506103a881610382565b92915050565b6000819050919050565b6103c1816103ae565b81146103cc57600080fd5b50565b6000813590506103de816103b8565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f840112610409576104086103e4565b5b8235905067ffffffffffffffff811115610426576104256103e9565b5b602083019150836001820283011115610442576104416103ee565b5b9250929050565b60008060008060006080868803121561046557610464610322565b5b600086013567ffffffffffffffff81111561048357610482610327565b5b61048f88828901610331565b95505060206104a088828901610399565b94505060406104b1888289016103cf565b935050606086013567ffffffffffffffff8111156104d2576104d1610327565b5b6104de888289016103f3565b92509250509295509295909350565b6104f6816103ae565b82525050565b600060208201905061051160008301846104ed565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061055e57607f821691505b60208210810361057157610570610517565b5b50919050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006105be600383610577565b91506105c982610588565b602082019050919050565b600060208201905081810360008301526105ed816105b1565b9050919050565b600082905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026106907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610653565b61069a8683610653565b95508019841693508086168417925050509392505050565b6000819050919050565b60006106d76106d26106cd846103ae565b6106b2565b6103ae565b9050919050565b6000819050919050565b6106f1836106bc565b6107056106fd826106de565b848454610660565b825550505050565b600090565b61071a61070d565b6107258184846106e8565b505050565b5b818110156107495761073e600082610712565b60018101905061072b565b5050565b601f82111561078e5761075f8161062e565b61076884610643565b81016020851015610777578190505b61078b61078385610643565b83018261072a565b50505b505050565b600082821c905092915050565b60006107b160001984600802610793565b1980831691505092915050565b60006107ca83836107a0565b9150826002028217905092915050565b6107e483836105f4565b67ffffffffffffffff8111156107fd576107fc6105ff565b5b6108078254610546565b61081282828561074d565b6000601f831160018114610841576000841561082f578287013590505b61083985826107be565b8655506108a1565b601f19841661084f8661062e565b60005b8281101561087757848901358255600182019150602085019450602081019050610852565b868310156108945784890135610890601f8916826107a0565b8355505b6001600288020188555050505b5050505050505056fea26469706673582212202506bee512af2f3acd98556baafd9afc04b2d8c95f09bbb5e387fce570c9a32764736f6c634300081a0033 diff --git a/testutil/contracts/Example.go b/testutil/contracts/Example.go index ce9cab5826..62ff9a3530 100644 --- a/testutil/contracts/Example.go +++ b/testutil/contracts/Example.go @@ -26,6 +26,7 @@ var ( _ = common.Big1 _ = types.BloomLookup _ = event.NewSubscription + _ = abi.ConvertType ) // ExamplezContext is an auto generated low-level Go binding around an user-defined struct. @@ -37,8 +38,8 @@ type ExamplezContext struct { // ExampleMetaData contains all meta data concerning the Example contract. var ExampleMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"Foo\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"bar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevertWithMessage\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevertWithRequire\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doSucceed\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes\",\"name\":\"origin\",\"type\":\"bytes\"},{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chainID\",\"type\":\"uint256\"}],\"internalType\":\"structExample.zContext\",\"name\":\"context\",\"type\":\"tuple\"},{\"internalType\":\"address\",\"name\":\"zrc20\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"message\",\"type\":\"bytes\"}],\"name\":\"onCrossChainCall\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", - Bin: "0x6080604052348015600f57600080fd5b506000808190555061043f806100266000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063afc874d214610067578063d720cb4514610071578063dd8e556c1461007b578063de43156e14610085578063fd5ad965146100a1578063febb0f7e146100ab575b600080fd5b61006f6100c9565b005b6100796100fb565b005b610083610136565b005b61009f600480360381019061009a91906102be565b610179565b005b6100a9610187565b005b6100b3610191565b6040516100c09190610371565b60405180910390f35b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012d906103e9565b60405180910390fd5b6000610177576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161016e906103e9565b60405180910390fd5b565b826000819055505050505050565b6001600081905550565b60005481565b600080fd5b600080fd5b600080fd5b6000606082840312156101bc576101bb6101a1565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101f0826101c5565b9050919050565b610200816101e5565b811461020b57600080fd5b50565b60008135905061021d816101f7565b92915050565b6000819050919050565b61023681610223565b811461024157600080fd5b50565b6000813590506102538161022d565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f84011261027e5761027d610259565b5b8235905067ffffffffffffffff81111561029b5761029a61025e565b5b6020830191508360018202830111156102b7576102b6610263565b5b9250929050565b6000806000806000608086880312156102da576102d9610197565b5b600086013567ffffffffffffffff8111156102f8576102f761019c565b5b610304888289016101a6565b95505060206103158882890161020e565b945050604061032688828901610244565b935050606086013567ffffffffffffffff8111156103475761034661019c565b5b61035388828901610268565b92509250509295509295909350565b61036b81610223565b82525050565b60006020820190506103866000830184610362565b92915050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006103d360038361038c565b91506103de8261039d565b602082019050919050565b60006020820190508181036000830152610402816103c6565b905091905056fea2646970667358221220c9cedad580b18532a00be1e615813af1c20bb609a0a69b5f36d49ed76cc20b5064736f6c63430008190033", + ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"Foo\",\"type\":\"error\"},{\"inputs\":[],\"name\":\"bar\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevertWithMessage\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doRevertWithRequire\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"doSucceed\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lastMessage\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"components\":[{\"internalType\":\"bytes\",\"name\":\"origin\",\"type\":\"bytes\"},{\"internalType\":\"address\",\"name\":\"sender\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"chainID\",\"type\":\"uint256\"}],\"internalType\":\"structExample.zContext\",\"name\":\"context\",\"type\":\"tuple\"},{\"internalType\":\"address\",\"name\":\"zrc20\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"amount\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"message\",\"type\":\"bytes\"}],\"name\":\"onCrossChainCall\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + Bin: "0x6080604052348015600f57600080fd5b50600080819055506108e0806100266000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063dd8e556c1161005b578063dd8e556c146100b4578063de43156e146100be578063fd5ad965146100da578063febb0f7e146100e45761007d565b80633297071014610082578063afc874d2146100a0578063d720cb45146100aa575b600080fd5b61008a610102565b6040516100979190610300565b60405180910390f35b6100a8610190565b005b6100b26101c2565b005b6100bc6101fd565b005b6100d860048036038101906100d39190610449565b610240565b005b6100e2610260565b005b6100ec61026a565b6040516100f991906104fc565b60405180910390f35b6001805461010f90610546565b80601f016020809104026020016040519081016040528092919081815260200182805461013b90610546565b80156101885780601f1061015d57610100808354040283529160200191610188565b820191906000526020600020905b81548152906001019060200180831161016b57829003601f168201915b505050505081565b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101f4906105d4565b60405180910390fd5b600061023e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610235906105d4565b60405180910390fd5b565b826000819055508181600191826102589291906107da565b505050505050565b6001600081905550565b60005481565b600081519050919050565b600082825260208201905092915050565b60005b838110156102aa57808201518184015260208101905061028f565b60008484015250505050565b6000601f19601f8301169050919050565b60006102d282610270565b6102dc818561027b565b93506102ec81856020860161028c565b6102f5816102b6565b840191505092915050565b6000602082019050818103600083015261031a81846102c7565b905092915050565b600080fd5b600080fd5b600080fd5b6000606082840312156103475761034661032c565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061037b82610350565b9050919050565b61038b81610370565b811461039657600080fd5b50565b6000813590506103a881610382565b92915050565b6000819050919050565b6103c1816103ae565b81146103cc57600080fd5b50565b6000813590506103de816103b8565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f840112610409576104086103e4565b5b8235905067ffffffffffffffff811115610426576104256103e9565b5b602083019150836001820283011115610442576104416103ee565b5b9250929050565b60008060008060006080868803121561046557610464610322565b5b600086013567ffffffffffffffff81111561048357610482610327565b5b61048f88828901610331565b95505060206104a088828901610399565b94505060406104b1888289016103cf565b935050606086013567ffffffffffffffff8111156104d2576104d1610327565b5b6104de888289016103f3565b92509250509295509295909350565b6104f6816103ae565b82525050565b600060208201905061051160008301846104ed565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061055e57607f821691505b60208210810361057157610570610517565b5b50919050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006105be600383610577565b91506105c982610588565b602082019050919050565b600060208201905081810360008301526105ed816105b1565b9050919050565b600082905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026106907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610653565b61069a8683610653565b95508019841693508086168417925050509392505050565b6000819050919050565b60006106d76106d26106cd846103ae565b6106b2565b6103ae565b9050919050565b6000819050919050565b6106f1836106bc565b6107056106fd826106de565b848454610660565b825550505050565b600090565b61071a61070d565b6107258184846106e8565b505050565b5b818110156107495761073e600082610712565b60018101905061072b565b5050565b601f82111561078e5761075f8161062e565b61076884610643565b81016020851015610777578190505b61078b61078385610643565b83018261072a565b50505b505050565b600082821c905092915050565b60006107b160001984600802610793565b1980831691505092915050565b60006107ca83836107a0565b9150826002028217905092915050565b6107e483836105f4565b67ffffffffffffffff8111156107fd576107fc6105ff565b5b6108078254610546565b61081282828561074d565b6000601f831160018114610841576000841561082f578287013590505b61083985826107be565b8655506108a1565b601f19841661084f8661062e565b60005b8281101561087757848901358255600182019150602085019450602081019050610852565b868310156108945784890135610890601f8916826107a0565b8355505b6001600288020188555050505b5050505050505056fea26469706673582212202506bee512af2f3acd98556baafd9afc04b2d8c95f09bbb5e387fce570c9a32764736f6c634300081a0033", } // ExampleABI is the input ABI used to generate the binding from. @@ -163,11 +164,11 @@ func NewExampleFilterer(address common.Address, filterer bind.ContractFilterer) // bindExample binds a generic wrapper to an already deployed contract. func bindExample(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(ExampleABI)) + parsed, err := ExampleMetaData.GetAbi() if err != nil { return nil, err } - return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil + return bind.NewBoundContract(address, *parsed, caller, transactor, filterer), nil } // Call invokes the (constant) contract method with params as input values and @@ -239,6 +240,37 @@ func (_Example *ExampleCallerSession) Bar() (*big.Int, error) { return _Example.Contract.Bar(&_Example.CallOpts) } +// LastMessage is a free data retrieval call binding the contract method 0x32970710. +// +// Solidity: function lastMessage() view returns(bytes) +func (_Example *ExampleCaller) LastMessage(opts *bind.CallOpts) ([]byte, error) { + var out []interface{} + err := _Example.contract.Call(opts, &out, "lastMessage") + + if err != nil { + return *new([]byte), err + } + + out0 := *abi.ConvertType(out[0], new([]byte)).(*[]byte) + + return out0, err + +} + +// LastMessage is a free data retrieval call binding the contract method 0x32970710. +// +// Solidity: function lastMessage() view returns(bytes) +func (_Example *ExampleSession) LastMessage() ([]byte, error) { + return _Example.Contract.LastMessage(&_Example.CallOpts) +} + +// LastMessage is a free data retrieval call binding the contract method 0x32970710. +// +// Solidity: function lastMessage() view returns(bytes) +func (_Example *ExampleCallerSession) LastMessage() ([]byte, error) { + return _Example.Contract.LastMessage(&_Example.CallOpts) +} + // DoRevert is a paid mutator transaction binding the contract method 0xafc874d2. // // Solidity: function doRevert() returns() diff --git a/testutil/contracts/Example.json b/testutil/contracts/Example.json index 9c67ba2186..c41132ea94 100644 --- a/testutil/contracts/Example.json +++ b/testutil/contracts/Example.json @@ -51,6 +51,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "lastMessage", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -97,5 +110,5 @@ "type": "function" } ], - "bin": "6080604052348015600f57600080fd5b506000808190555061043f806100266000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c8063afc874d214610067578063d720cb4514610071578063dd8e556c1461007b578063de43156e14610085578063fd5ad965146100a1578063febb0f7e146100ab575b600080fd5b61006f6100c9565b005b6100796100fb565b005b610083610136565b005b61009f600480360381019061009a91906102be565b610179565b005b6100a9610187565b005b6100b3610191565b6040516100c09190610371565b60405180910390f35b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161012d906103e9565b60405180910390fd5b6000610177576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161016e906103e9565b60405180910390fd5b565b826000819055505050505050565b6001600081905550565b60005481565b600080fd5b600080fd5b600080fd5b6000606082840312156101bc576101bb6101a1565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101f0826101c5565b9050919050565b610200816101e5565b811461020b57600080fd5b50565b60008135905061021d816101f7565b92915050565b6000819050919050565b61023681610223565b811461024157600080fd5b50565b6000813590506102538161022d565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f84011261027e5761027d610259565b5b8235905067ffffffffffffffff81111561029b5761029a61025e565b5b6020830191508360018202830111156102b7576102b6610263565b5b9250929050565b6000806000806000608086880312156102da576102d9610197565b5b600086013567ffffffffffffffff8111156102f8576102f761019c565b5b610304888289016101a6565b95505060206103158882890161020e565b945050604061032688828901610244565b935050606086013567ffffffffffffffff8111156103475761034661019c565b5b61035388828901610268565b92509250509295509295909350565b61036b81610223565b82525050565b60006020820190506103866000830184610362565b92915050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006103d360038361038c565b91506103de8261039d565b602082019050919050565b60006020820190508181036000830152610402816103c6565b905091905056fea2646970667358221220c9cedad580b18532a00be1e615813af1c20bb609a0a69b5f36d49ed76cc20b5064736f6c63430008190033" + "bin": "6080604052348015600f57600080fd5b50600080819055506108e0806100266000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063dd8e556c1161005b578063dd8e556c146100b4578063de43156e146100be578063fd5ad965146100da578063febb0f7e146100e45761007d565b80633297071014610082578063afc874d2146100a0578063d720cb45146100aa575b600080fd5b61008a610102565b6040516100979190610300565b60405180910390f35b6100a8610190565b005b6100b26101c2565b005b6100bc6101fd565b005b6100d860048036038101906100d39190610449565b610240565b005b6100e2610260565b005b6100ec61026a565b6040516100f991906104fc565b60405180910390f35b6001805461010f90610546565b80601f016020809104026020016040519081016040528092919081815260200182805461013b90610546565b80156101885780601f1061015d57610100808354040283529160200191610188565b820191906000526020600020905b81548152906001019060200180831161016b57829003601f168201915b505050505081565b6040517fbfb4ebcf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101f4906105d4565b60405180910390fd5b600061023e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610235906105d4565b60405180910390fd5b565b826000819055508181600191826102589291906107da565b505050505050565b6001600081905550565b60005481565b600081519050919050565b600082825260208201905092915050565b60005b838110156102aa57808201518184015260208101905061028f565b60008484015250505050565b6000601f19601f8301169050919050565b60006102d282610270565b6102dc818561027b565b93506102ec81856020860161028c565b6102f5816102b6565b840191505092915050565b6000602082019050818103600083015261031a81846102c7565b905092915050565b600080fd5b600080fd5b600080fd5b6000606082840312156103475761034661032c565b5b81905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061037b82610350565b9050919050565b61038b81610370565b811461039657600080fd5b50565b6000813590506103a881610382565b92915050565b6000819050919050565b6103c1816103ae565b81146103cc57600080fd5b50565b6000813590506103de816103b8565b92915050565b600080fd5b600080fd5b600080fd5b60008083601f840112610409576104086103e4565b5b8235905067ffffffffffffffff811115610426576104256103e9565b5b602083019150836001820283011115610442576104416103ee565b5b9250929050565b60008060008060006080868803121561046557610464610322565b5b600086013567ffffffffffffffff81111561048357610482610327565b5b61048f88828901610331565b95505060206104a088828901610399565b94505060406104b1888289016103cf565b935050606086013567ffffffffffffffff8111156104d2576104d1610327565b5b6104de888289016103f3565b92509250509295509295909350565b6104f6816103ae565b82525050565b600060208201905061051160008301846104ed565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061055e57607f821691505b60208210810361057157610570610517565b5b50919050565b600082825260208201905092915050565b7f666f6f0000000000000000000000000000000000000000000000000000000000600082015250565b60006105be600383610577565b91506105c982610588565b602082019050919050565b600060208201905081810360008301526105ed816105b1565b9050919050565b600082905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b6000600883026106907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82610653565b61069a8683610653565b95508019841693508086168417925050509392505050565b6000819050919050565b60006106d76106d26106cd846103ae565b6106b2565b6103ae565b9050919050565b6000819050919050565b6106f1836106bc565b6107056106fd826106de565b848454610660565b825550505050565b600090565b61071a61070d565b6107258184846106e8565b505050565b5b818110156107495761073e600082610712565b60018101905061072b565b5050565b601f82111561078e5761075f8161062e565b61076884610643565b81016020851015610777578190505b61078b61078385610643565b83018261072a565b50505b505050565b600082821c905092915050565b60006107b160001984600802610793565b1980831691505092915050565b60006107ca83836107a0565b9150826002028217905092915050565b6107e483836105f4565b67ffffffffffffffff8111156107fd576107fc6105ff565b5b6108078254610546565b61081282828561074d565b6000601f831160018114610841576000841561082f578287013590505b61083985826107be565b8655506108a1565b601f19841661084f8661062e565b60005b8281101561087757848901358255600182019150602085019450602081019050610852565b868310156108945784890135610890601f8916826107a0565b8355505b6001600288020188555050505b5050505050505056fea26469706673582212202506bee512af2f3acd98556baafd9afc04b2d8c95f09bbb5e387fce570c9a32764736f6c634300081a0033" } diff --git a/testutil/contracts/Example.sol b/testutil/contracts/Example.sol index 1b36e7a15d..7109ebc60a 100644 --- a/testutil/contracts/Example.sol +++ b/testutil/contracts/Example.sol @@ -12,6 +12,7 @@ contract Example { } uint256 public bar; + bytes public lastMessage; constructor() { bar = 0; @@ -40,5 +41,6 @@ contract Example { bytes calldata message ) external { bar = amount; + lastMessage = message; } } \ No newline at end of file