From 1f642f31ad6ce4074ec954b55ea87362beb20cd5 Mon Sep 17 00:00:00 2001 From: danijelTxFusion Date: Sun, 12 May 2024 02:24:05 +0200 Subject: [PATCH] feat(go): add bridgehub --- content/sdk/11.go/03.clients.md | 213 ++++++++++- content/sdk/11.go/04.accounts.md | 506 ++++++++++++++++++++++--- content/sdk/11.go/types/01.accounts.md | 68 ++-- content/sdk/11.go/types/04.types.md | 50 ++- 4 files changed, 757 insertions(+), 80 deletions(-) diff --git a/content/sdk/11.go/03.clients.md b/content/sdk/11.go/03.clients.md index 680f9a18..6fffa88b 100644 --- a/content/sdk/11.go/03.clients.md +++ b/content/sdk/11.go/03.clients.md @@ -50,14 +50,14 @@ ZkSyncEraProvider := "https://testnet.era.zksync.dev" ZkSyncEraWSProvider := "ws://testnet.era.zksync.dev:3051" // Connect to zkSync network -client, err := clients.Dial(ZkSyncEraProvider) +client, err := clients.DialBase(ZkSyncEraProvider) if err != nil { log.Panic(err) } defer client.Close() // Connect to zkSync network using Web Socket -wsClient, err := clients.Dial(ZkSyncEraWSProvider) +wsClient, err := clients.DialBase(ZkSyncEraWSProvider) if err != nil { log.Panic(err) } @@ -448,6 +448,30 @@ if err != nil { } ``` +### `BridgehubContractAddress` + +Returns the Bridgehub smart contract address. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +BridgehubContractAddress(ctx context.Context) (common.Address, error) +``` + +#### Example + +```go +address, err := client.BridgehubContractAddress(context.Background()) +if err != nil { + log.Panic() +} +fmt.Println("Bridgehub address: ", address) +``` + ### `MainContractAddress` Returns the address of the zkSync Era contract. @@ -520,6 +544,82 @@ if err != nil { fmt.Println("Bridge contracts: ", contracts) ``` +### `BaseTokenContractAddress` + +Returns the L1 base token address. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +BaseTokenContractAddress(ctx context.Context) (common.Address, error) +``` + +#### Example + +```go +address, err := client.BaseTokenContractAddress(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Println("Base token address: ", address) +``` + +### `IsEthBasedChain` + +Returns whether the chain is ETH-based. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +IsEthBasedChain(ctx context.Context) (bool, error) +``` + +#### Example + +```go +isEthBased, err := client.IsEthBasedChain(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Println("Is ETH-based chain: ", isEthBased) +``` + +### `IsBaseToken` + +returns whether the token is the base token. + +#### Inputs + +| Parameter | Type | Description | +|-----------|-------------------|----------------| +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | Token address. | + +```go +IsBaseToken(ctx context.Context, token common.Address) (bool, error) +``` + +#### Example + +```go +isBaseToken, err := client.IsBaseToken( + context.Background(), + common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") + ) +if err != nil { + log.Panic(err) +} +fmt.Println("Is base token: ", isBaseToken) +``` + ### `ContractAccountInfo` Returns the version of the supported account abstraction and nonce ordering from a given contract address. @@ -696,6 +796,75 @@ if err != nil { fmt.Printf("Transaction details: %+v\n", *txDetails) ``` +### `BytecodeByHash` + +returns bytecode of a contract given by its hash. + +#### Inputs + +| Parameter | Type | Description | +|----------------| ----------------- |----------------| +| `ctx` | `context.Context` | Context. | +| `bytecodeHash` | `common.Hash` | Bytecode hash. | + +```go +BytecodeByHash(ctx context.Context, bytecodeHash common.Hash) ([]byte, error) +``` + +#### Example + +```go +testnetPaymaster, err := client.TestnetPaymaster(context.Background()) +if err != nil { + log.Panic(err) +} +testnetPaymasterBytecode, err := client.CodeAt(context.Background(), testnetPaymaster, nil) +if err != nil { + log.Panic(err) +} + +testnetPaymasterBytecodeHash, err := utils.HashBytecode(testnetPaymasterBytecode) +if err != nil { + log.Panic(err) +} + +bytecode, err := client.BytecodeByHash(context.Background(), common.BytesToHash(testnetPaymasterBytecodeHash)) +if err != nil { + log.Panic(err) +} +fmt.Println("Bytecode: ", bytecode) +``` + +### `RawBlockTransactions` + +Returns data of transactions in a block. + +#### Inputs + +| Parameter | Type | Description | +|-----------|-------------------|---------------| +| `ctx` | `context.Context` | Context. | +| `number` | `uin64` | Block number. | + +```go +RawBlockTransactions(ctx context.Context, number uint64) ([]zkTypes.RawBlockTransaction, error) +``` + +#### Example + +```go +blockNumber, err := client.BlockNumber(context.Background()) +if err != nil { + log.Panic(err) +} + +rawBlockTransactions, err := client.RawBlockTransactions(context.Background(), blockNumber) +if err != nil { + log.Panic(err) +} +fmt.Println("Raw block transactions: ", rawBlockTransactions) +``` + ### `LogProof` Returns the proof for a transaction's L2 to L1 log sent via the L1Messenger system contract. @@ -761,6 +930,38 @@ if err != nil { fmt.Printf("L2 transaction: %+v\n", l2Tx) ``` +### `PriorityOpConfirmation` + +Returns the transaction confirmation data that is part of `L2->L1` message. +The txHash is the hash of the L2 transaction where the message was initiated. +The index is used in case there were multiple transactions in one message, you may pass an index of the +transaction which confirmation data should be fetched. + +#### Inputs + +| Parameter | Type | Description | +|-----------|-------------------|--------------------| +| `ctx` | `context.Context` | Context. | +| `txHash` | `common.Hash` | Transaction hash. | +| `index` | `int` | Transaction index. | + +```go +PriorityOpConfirmation(ctx context.Context, txHash common.Hash, index int) (*zkTypes.PriorityOpConfirmation, error) +``` + +#### Example + +```go +// Any L2 -> L1 transaction can be used. +// In this case, withdrawal transaction is used. +txHash := common.HexToHash("0x2a1c6c74b184965c0cb015aae9ea134fd96215d2e4f4979cfec12563295f610e") +l1Receipt, err := client.PriorityOpConfirmation(context.Background(), txHash, 0) +if err != nil { + log.Panic(err) +} +fmt.Printf("Confirmation data: %+v\n", *l2Tx) +``` + ### `ConfirmedTokens` Returns {address, symbol, name, and decimal} information of all tokens within a range of ids given by @@ -800,9 +1001,9 @@ ETH address is set to zero address. #### Inputs | Parameter | Type | Description | -| --------- | ----------------- | ----------------- | +|-----------| ----------------- | ----------------- | | `ctx` | `context.Context` | Context. | -| `address` | `common.Address` | L1 token address. | +| `token` | `common.Address` | L1 token address. | ```go L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error) @@ -827,9 +1028,9 @@ ETH address is set to zero address. #### Inputs | Parameter | Type | Description | -| --------- | ----------------- | ----------------- | +|-----------| ----------------- | ----------------- | | `ctx` | `context.Context` | Context. | -| `address` | `common.Address` | L2 token address. | +| `token` | `common.Address` | L2 token address. | ```go L1TokenAddress(ctx context.Context, token common.Address) (common.Address, error) diff --git a/content/sdk/11.go/04.accounts.md b/content/sdk/11.go/04.accounts.md index 84c0306d..17742117 100644 --- a/content/sdk/11.go/04.accounts.md +++ b/content/sdk/11.go/04.accounts.md @@ -161,6 +161,29 @@ if err != nil { } ``` +### `BridgehubContract` + +Returns the Bridgehub L1 smart contract. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +BridgehubContract(_ context.Context) (*bridgehub.IBridgehub, error) +``` + +#### Example + +```go +bridgehub, err := wallet.BridgehubContract(context.Background()) +if err != nil { + log.Panic(err) +} +``` + ### `L1BridgeContracts` Returns L1 bridge contracts. @@ -184,6 +207,54 @@ if err != nil { } ``` +### `BaseToken` + +Returns the address of the base token on L1. + +#### Inputs + +| Parameter | Type | Description | +|-----------|----------------------------------------------------------| ----------- | +| `opts` | [`CallOpts`](./types/01.accounts.md#callopts) (optional) | Call options. | + +```go +BaseToken(opts *CallOpts) (common.Address, error) +``` + +#### Example + +```go +baseToken, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} +fmt.Println("Base token: ", baseToken) +``` + +### `IsEthBasedChain` + +Returns whether the chain is ETH-based. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- | ----------- | +| `ctx` | `context.Context` | Context. | + +```go +IsEthBasedChain(ctx context.Context) (bool, error) +``` + +#### Example + +```go +isEthBased, err := wallet.IsEthBasedChain(context.Background()) +if err != nil { + log.Panic(err) +} +fmt.Println("Is ETH-based chain: ", isEthBased) +``` + ### `BalanceL1` Returns the balance of the specified token on L1 that can be either ETH or any ERC20 token. @@ -228,17 +299,9 @@ AllowanceL1(opts *CallOpts, token common.Address, bridgeAddress common.Address) #### Example ```go -ZkSyncEraProvider := "https://testnet.era.zksync.dev" // The Crown token on testnet TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - - contracts, err := client.BridgeContracts(context.Background()) if err != nil { log.Panic(err) @@ -295,17 +358,9 @@ ApproveERC20(auth *TransactOpts, token common.Address, amount *big.Int, bridgeAd #### Example ```go -ZkSyncEraProvider := "https://testnet.era.zksync.dev" // The Crown token on testnet TokenAddress := common.HexToAddress("0x927488F48ffbc32112F1fF721759649A89721F8F") -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - - contracts, err := client.BridgeContracts(context.Background()) if err != nil { log.Panic(err) @@ -336,6 +391,162 @@ BaseCost(opts *CallOpts, gasLimit, gasPerPubdataByte, gasPrice *big.Int) (*big.I #### Example +```go +gasPrice, err := client.SuggestGasPrice(context.Background()) +if err != nil { + log.Panic(err) +} + +baseCost, err := wallet.BaseCost(nil, big.NewInt(9000), utils.RequiredL1ToL2GasPerPubdataLimit, gasPrice) +if err != nil { + log.Panic(err) +} +fmt.Println("Base cost: ", baseCost) +``` + +### `DepositAllowanceParams` + +Returns the parameters for the approval token transaction based on the deposit token and amount. +Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; +allowance is calculated solely based on the specified amount. + +#### Inputs + +| Parameter | Type | Description | +|---------------------| ---------------------------------------- | -------------------------------------------------------------------------------------- | +| `opts` | [`CallOpts`](./types/01.accounts.md#callopts) (optional) | Call options. | +| `msg` | [`DepositCallMsg`](./types/01.accounts.md#depositcallmsg) | Deposit call parameters. | + +```go +DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([]struct { + Token common.Address + Allowance *big.Int +}, error) +``` + +#### Example + +Get allowance parameters for depositing token on ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: common.HexToAddress(""), + To: Receiver, + Amount: big.NewInt(5), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing ETH on non-ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: utils.LegacyEthAddress, + To: Receiver, + Amount: big.NewInt(7_000_000_000), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing base token on non-ETH-based chain. + +```go +token, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} + +msg := accounts.DepositCallMsg{ + Token: token, + To: Receiver, + Amount: big.NewInt(7_000_000_000), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + +Get allowance parameters for depositing non-base token on non-ETH-based chain. + +```go +msg := accounts.DepositCallMsg{ + Token: common.HexToAddress(""), + To: Receiver, + Amount: big.NewInt(5), +} + +allowanceParams, err := wallet.DepositAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} +approveTx, err := wallet.ApproveERC20(nil, allowanceParams[0].Token, allowanceParams[0].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +approveTx, err = wallet.ApproveERC20(nil, allowanceParams[1].Token, allowanceParams[1].Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + ```go ZkSyncEraProvider := "https://testnet.era.zksync.dev" @@ -361,7 +572,8 @@ fmt.Println("Base cost: ", baseCost) Transfers the specified token from the associated account on the L1 network to the target account on the L2 network. The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with the -specified L1 bridge (default one or the one defined in `BridgeAddress`). In this case, `ApproveERC20` can be enabled +specified L1 bridge (default one or the one defined in `BridgeAddress`). In this case, depending on is the chain +ETH-based or not `ApproveERC20` or `ApproveBaseERC20` can be enabled to perform token approval. to perform token approval. If there are already enough approved tokens for the L1 bridge, token approval will be skipped. To check the amount of approved tokens for a specific bridge, use the [`AllowanceL1`](#allowancel1) method. @@ -378,16 +590,159 @@ Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error) #### Example +Deposit ETH on ETH-based chain. + ```go tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ - Token: utils.EthAddress, - Amount: big.NewInt(2_000_000_000_000_000_000), - To: common.HexToAddress(""), + To: wallet.Address(), + Token: utils.LegacyEthAddress, + Amount: amount, + RefundRecipient: wallet.Address(), }) if err != nil { - log.Panic(err) + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit token on ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: L1Dai, + Amount: amount, + ApproveERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit ETH on non-ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: utils.LegacyEthAddress, + Amount: amount, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit base token on non-ETH-based chain. + +```go +baseToken, err := wallet.BaseToken(nil) +if err != nil { + log.Panic(err) +} + +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: baseToken, + Amount: amount, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) +} +``` + +Deposit non-base token on non-ETH-based chain. + +```go +tx, err := wallet.Deposit(nil, accounts.DepositTransaction{ + To: wallet.Address(), + Token: L1Dai, + Amount: amount, + ApproveERC20: true, + ApproveBaseERC20: true, + RefundRecipient: wallet.Address(), +}) +if err != nil { + log.Panic(err) +} + +l1Receipt, err := bind.WaitMined(context.Background(), ethClient, tx) +if err != nil { + log.Panic(err) +} + +l2Tx, err := client.L2TransactionFromPriorityOp(context.Background(), l1Receipt) +if err != nil { + log.Panic(err) +} + +l2Receipt, err := client.WaitMined(context.Background(), l2Tx.Hash) +if err != nil { + log.Panic(err) } -fmt.Println("L1 deposit transaction: ", tx.Hash()) ``` ### `EstimateGasDeposit` @@ -524,7 +879,7 @@ ClaimFailedDeposit(auth *TransactOpts, depositHash common.Hash) (*types.Transact ```go failedDepositL2Hash := common.HexToHash("") -cfdTx, err := w.ClaimFailedDeposit(nil, failedDepositL2Hash) +cfdTx, err := wallet.ClaimFailedDeposit(nil, failedDepositL2Hash) if err != nil { log.Panic(err) } @@ -595,6 +950,51 @@ if err != nil { fmt.Println("Gas: ", gas) ``` +### `RequestExecuteAllowanceParams` + +Returns the parameters for the approval token transaction based on the request execute transaction. +Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction. + +#### Inputs + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------- | -------------------------------- | +| `opts` | [`CallOpts`](./types/01.accounts.md#callopts) (optional) | Call options. | +| `msg` | [`RequestExecuteCallMsg`](./types/01.accounts.md#requestexecutecallmsg) | Request execute call parameters. | + +```go +RequestExecuteAllowanceParams(opts *CallOpts, msg RequestExecuteCallMsg) (AllowanceParams, error) +``` + +#### Example + +```go +msg := accounts.RequestExecuteCallMsg{ + ContractAddress: wallet.Address(), + L2Value: big.NewInt(7_000_000_000), + Value: big.NewInt(0), +} +allowanceParams, err := wallet.RequestExecuteAllowanceParams(nil, msg) +if err != nil { + log.Panic(err) +} + +bridgeContracts, err := client.BridgeContracts(context.Background()) +if err != nil { + log.Panic(err) +} + +approveTx, err := wallet.ApproveERC20(nil, allowanceParams.Token, allowanceParams.Allowance, bridgeContracts.L1SharedBridge) +if err != nil { + log.Panic(err) +} + +_, err = bind.WaitMined(context.Background(), ethClient, approveTx) +if err != nil { + log.Panic(err) +} +``` + ### `EstimateCustomBridgeDepositL2Gas` Used by [`EstimateDefaultBridgeDepositL2Gas`](#estimatedefaultbridgedepositl2gas) to estimate L2 gas @@ -777,7 +1177,7 @@ Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error #### Example ```go -balance, err := w.Balance(context.Background(), utils.EthAddress, nil) +balance, err := wallet.Balance(context.Background(), utils.EthAddress, nil) if err != nil { log.Panic(err) } @@ -854,6 +1254,34 @@ if err != nil { } ``` +### `IsBaseToken` + +Returns whether the token is the base token. + +#### Inputs + +| Parameter | Type | Description | +| --------- | ----------------- |----------------| +| `ctx` | `context.Context` | Context. | +| `token` | `common.Address` | Token address. | + +```go +IsBaseToken(ctx context.Context, token common.Address) (bool, error) +``` + +#### Example + +```go +isBaseToken, err := wallet.IsBaseToken( + context.Background(), + common.HexToAddress("0x5C221E77624690fff6dd741493D735a17716c26B") +) +if err != nil { + log.Panic(err) +} +fmt.Println("Is base token: ", isBaseToken) +``` + ### `Withdraw` Initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network @@ -931,7 +1359,7 @@ Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error) #### Example ```go -tx, err := w.Transfer(nil, accounts.TransferTransaction{ +tx, err := wallet.Transfer(nil, accounts.TransferTransaction{ To: common.HexToAddress(""), Amount: big.NewInt(7_000_000_000), Token: utils.EthAddress, @@ -1214,7 +1642,7 @@ if err != nil { } //Deploy smart contract -hash, err := w.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode}) +hash, err := wallet.Deploy(nil, accounts.Create2Transaction{Bytecode: bytecode}) if err != nil { panic(err) } @@ -1245,7 +1673,7 @@ if err != nil { } //Deploy smart contract -hash, err := w.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode}) +hash, err := wallet.DeployWithCreate(nil, accounts.CreateTransaction{Bytecode: bytecode}) if err != nil { panic(err) } @@ -1285,7 +1713,7 @@ if err != nil { } // Deploy paymaster contract -hash, err := w.DeployAccount(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor}) +hash, err := wallet.DeployAccount(nil, accounts.Create2Transaction{Bytecode: bytecode, Calldata: constructor}) if err != nil { log.Panic(err) } @@ -1328,7 +1756,7 @@ if err != nil { } // Deploy paymaster contract -hash, err := w.DeployAccountWithCreate(nil, accounts.CreateTransaction{ +hash, err := wallet.DeployAccountWithCreate(nil, accounts.CreateTransaction{ Bytecode: bytecode, Calldata: constructor, }) @@ -1480,34 +1908,18 @@ ConnectL1(client *ethclient.Client) (*Wallet, error) #### Example ```go -PrivateKey := os.Getenv("PRIVATE_KEY") -ZkSyncEraProvider := "https://sepolia.era.zksync.dev" -EthereumProvider := "https://rpc.ankr.com/eth_sepolia" - -client, err := clients.Dial(ZkSyncEraProvider) -if err != nil { - log.Panic(err) -} -defer client.Close() - chainID, err := client.ChainID(context.Background()) if err != nil { log.Panic(err) } -wallet, err := accounts.NewRandomWallet(chainID, nil, nil) -if err != nil { - log.Panic(err) -} - -ethClient, err := ethclient.Dial(EthereumProvider) +wallet, err = accounts.NewRandomWallet(chainID, nil, nil) if err != nil { log.Panic(err) } -defer ethClient.Close() // create new wallet with connection to L1 -w, err = w.Connect(ðClient) +wallet, err = wallet.Connect(ðClient) if err != nil { log.Panic(err) } diff --git a/content/sdk/11.go/types/01.accounts.md b/content/sdk/11.go/types/01.accounts.md index d7d04337..30a09411 100644 --- a/content/sdk/11.go/types/01.accounts.md +++ b/content/sdk/11.go/types/01.accounts.md @@ -1,5 +1,16 @@ # `accounts` Package +### `AllowanceParams` + +Contains the parameters required for approval of an ERC20 token. + +```go +type AllowanceParams struct { + Token common.Address // Token address + Allowance *big.Int // Allowance amount +} +``` + ### `CallOpts` Is the collection of options to fine tune a contract call request from an account associated with @@ -152,7 +163,8 @@ type RequestExecuteCallMsg struct { ContractAddress common.Address // The L2 receiver address. Calldata []byte // The input of the L2 transaction. L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2. - L2Value *big.Int // `msg.value` of L2 transaction. + MintValue *big.Int // The amount of base token that needs to be minted on non-ETH-based L2. + L2Value *big.Int // `msg.value` of L2 transaction. FactoryDeps [][]byte // An array of L2 bytecodes that will be marked as known on L2. // If the ETH value passed with the transaction is not explicitly stated Value, @@ -177,7 +189,9 @@ type RequestExecuteCallMsg struct { } func (m *RequestExecuteCallMsg) ToRequestExecuteTransaction() RequestExecuteTransaction +// Deprecated in favor of ToCallMsgWithChainID func (m *RequestExecuteCallMsg) ToCallMsg(from common.Address) (ethereum.CallMsg, error) +func (m *RequestExecuteCallMsg) ToCallMsgWithChainID(from common.Address, chainID *big.Int) (ethereum.CallMsg, error) func (m *RequestExecuteCallMsg) ToTransactOpts() TransactOpts ``` @@ -270,7 +284,8 @@ type RequestExecuteTransaction struct { ContractAddress common.Address // The L2 receiver address. Calldata []byte // The input of the L2 transaction. L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2. - L2Value *big.Int // `msg.value` of L2 transaction. + MintValue *big.Int // The amount of base token that needs to be minted on non-ETH-based L2. + L2Value *big.Int // `msg.value` of L2 transaction. FactoryDeps [][]byte // An array of L2 bytecodes that will be marked as known on L2. // If the ETH value passed with the transaction is not explicitly stated Auth.Value, @@ -296,38 +311,45 @@ Represents a deposit transaction on L2 from L1 initiated by the account associat ```go type DepositTransaction struct { - To common.Address // The address of the token to deposit. - Token common.Address // The address of the token to deposit. - Amount *big.Int // The amount of the token to be deposited. + To common.Address // The address of the token to deposit. + Token common.Address // The address of the token to deposit. + Amount *big.Int // The amount of the token to be deposited. - // If the ETH value passed with the transaction is not explicitly stated Auth.Value, - // this field will be equal to the tip the operator will receive on top of the base cost - // of the transaction. - OperatorTip *big.Int + // If the ETH value passed with the transaction is not explicitly stated Auth.Value, + // this field will be equal to the tip the operator will receive on top of the base cost + // of the transaction. + OperatorTip *big.Int - // The address of the bridge contract to be used. Defaults to the default zkSync bridge - // (either L1EthBridge or L1Erc20Bridge). - BridgeAddress *common.Address + // The address of the bridge contract to be used. Defaults to the default zkSync bridge + // (either L1EthBridge or L1Erc20Bridge). + BridgeAddress *common.Address - // Whether should the token approval be performed under the hood. Set this flag to true if you - // bridge an ERC20 token and didn't call the approveERC20 function beforehand. - ApproveERC20 bool + // Whether should the token approval be performed under the hood. Set this flag to true if you + // bridge an ERC20 token and didn't call the approveERC20 function beforehand. + ApproveERC20 bool - L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2. + // Whether should the base token approval be performed under the hood. Set this flag to true if you + // bridge an ERC20 token and didn't call the approveERC20 function beforehand. + ApproveBaseERC20 bool - // The maximum amount L2 gas that the operator may charge the user for single byte of pubdata. - GasPerPubdataByte *big.Int + L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2. - // The address on L2 that will receive the refund for the transaction. - // If the transaction fails, it will also be the address to receive L2Value. - RefundRecipient common.Address + // The maximum amount L2 gas that the operator may charge the user for single byte of pubdata. + GasPerPubdataByte *big.Int + + // The address on L2 that will receive the refund for the transaction. + // If the transaction fails, it will also be the address to receive L2Value. + RefundRecipient common.Address + + CustomBridgeData []byte // Additional data that can be sent to the bridge. - CustomBridgeData []byte // Additional data that can be sent to a bridge. - ApproveAuth *TransactOpts // Authorization data for the approval token transaction. + ApproveAuth *TransactOpts // Authorization data for the token approval transaction. + ApproveBaseAuth *TransactOpts // Authorization data for the base token approval transaction. } func (t *DepositTransaction) ToRequestExecuteTransaction() *RequestExecuteTransaction func (t *DepositTransaction) ToDepositCallMsg(opts *TransactOpts) DepositCallMsg +func (t *DepositTransaction) PopulateEmptyFields(from common.Address) ``` ### `DeploymentType` diff --git a/content/sdk/11.go/types/04.types.md b/content/sdk/11.go/types/04.types.md index 58cdc664..cc6a8912 100644 --- a/content/sdk/11.go/types/04.types.md +++ b/content/sdk/11.go/types/04.types.md @@ -116,8 +116,12 @@ Represents the addresses of default bridge contracts for both L1 and L2. ```go type BridgeContracts struct { - L1Erc20DefaultBridge common.Address `json:"l1Erc20DefaultBridge"` // Default L1Bridge contract address. - L2Erc20DefaultBridge common.Address `json:"l2Erc20DefaultBridge"` // Default L2Bridge contract address. + L1Erc20DefaultBridge common.Address `json:"l1Erc20DefaultBridge"` // Default L1Bridge contract address. + L2Erc20DefaultBridge common.Address `json:"l2Erc20DefaultBridge"` // Default L2Bridge contract address. + L1WethBridge common.Address `json:"l1WethBridge"` // WETH L1Bridge contract address. + L2WethBridge common.Address `json:"l2WethBridge"` // WETH L2Bridge contract address. + L1SharedBridge common.Address `json:"l1SharedDefaultBridge"` // Default L1SharedBridge contract address. + L2SharedBridge common.Address `json:"l2SharedDefaultBridge"` // Default L2SharedBridge contract address. } ``` @@ -185,7 +189,8 @@ Represents the L1 bridge contracts. ```go type L1BridgeContracts struct { - Erc20 *l1bridge.IL1Bridge // Default L1Bridge contract. + Erc20 *l1bridge.IL1Bridge // Default L1Bridge contract. + Shared *l1sharedbridge.IL1SharedBridge // L1SharedBridge contract. } ``` @@ -195,7 +200,8 @@ Represents the L2 bridge contracts. ```go type L2BridgeContracts struct { - Erc20 *l2bridge.IL2Bridge // Default L2Bridge contract. + Erc20 *l2bridge.IL2Bridge // Default L2Bridge contract. + Shared *l2bridge.IL2Bridge // Shared L2Bridge contract. } ``` @@ -244,6 +250,42 @@ type MessageProof struct { } ``` +### `RawBlockTransaction` + +Represents a raw block transaction. + +```go +type RawBlockTransaction struct { + CommonData struct { + L1 struct { + CanonicalTxHash common.Hash `json:"canonicalTxHash"` + DeadlineBlock *big.Int `json:"deadlineBlock"` + EthBlock *big.Int `json:"ethBlock"` + EthHash common.Hash `json:"ethHash"` + FullFee hexutil.Big `json:"fullFee"` + GasLimit hexutil.Big `json:"gasLimit"` + GasPerPubdataLimit hexutil.Big `json:"gasPerPubdataLimit"` + Layer2TipFee hexutil.Big `json:"layer2TipFee"` + MaxFeePerGas hexutil.Big `json:"maxFeePerGas"` + OpProcessingType string `json:"opProcessingType"` + PriorityQueueType string `json:"priorityQueueType"` + RefundRecipient common.Address `json:"refundRecipient"` + Sender common.Address `json:"sender"` + SerialId *big.Int `json:"serialId"` + ToMint string `json:"toMint"` + } `json:"L1"` + } `json:"common_data"` + Execute struct { + Calldata hexutil.Bytes `json:"calldata"` + ContractAddress common.Address `json:"contractAddress"` + FactoryDeps []hexutil.Bytes `json:"factoryDeps"` + Value hexutil.Big `json:"value"` + } `json:"execute"` + ReceivedTimestampMs uint64 `json:"received_timestamp_ms"` +} + +``` + ### `Receipt` Extends the [`types.Receipt`](https://pkg.go.dev/github.com/ethereum/go-ethereum@v1.12.0/core/types#Receipts)