-
-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publicActionsL1 decorator for zkSync (#2190)
* fix: tests * feat: publicActionsL1 decorator for zkSync * feat: add getBalanceL1 action to support and balance for ETH * fix: rename address constants * fix: run lint formatter and revert vscode settings.json * fix: run lint formatter and add new check for ETH tokens * chore: apply lint * chore: tweaks * chore: format * chore: changeset --------- Co-authored-by: moxey.eth <jakemoxey@gmail.com> Co-authored-by: Marko Arambasic <38253493+kiriyaga@users.noreply.github.com> Co-authored-by: Marko Arambasic <makiarambasic@gmail.com> Co-authored-by: nikola-bozin-txfusion <147805948+nikola-bozin-txfusion@users.noreply.github.com> Co-authored-by: nikola-bozin-txfusion <nikolabozin@txfusion.io>
- Loading branch information
1 parent
5e917a6
commit 698f922
Showing
24 changed files
with
1,450 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"viem": minor | ||
--- | ||
|
||
**zkSync Extension:** Added L1 Public Actions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
description: Determines the amount of approved tokens for a specific L1 bridge. | ||
--- | ||
|
||
# getL1Allowance | ||
|
||
Determines the amount of approved tokens for a specific L1 bridge. | ||
|
||
## Usage | ||
|
||
:::code-group | ||
|
||
```ts [example.ts] | ||
import { account, publicClient } from './config' | ||
|
||
const allowance = await publicClient.getL1Allowance({ | ||
account | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
}) | ||
``` | ||
|
||
```ts [config.ts] | ||
import { createPublicClient, custom } from 'viem' | ||
import { privateKeyToAccount } from 'viem/accounts' | ||
import { mainnet } from 'viem/chains' | ||
import { publicActionsL1 } from 'viem/zksync' | ||
|
||
export const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: custom(window.ethereum) | ||
}).extend(publicActionsL1()) | ||
|
||
// JSON-RPC Account | ||
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
// Local Account | ||
export const account = privateKeyToAccount(...) | ||
``` | ||
|
||
::: | ||
|
||
## Returns | ||
|
||
`bigint` | ||
|
||
Returns the amount of approved tokens. | ||
|
||
## Parameters | ||
|
||
### account | ||
|
||
- **Type:** `Account | Address` | ||
|
||
The Account used for check. | ||
|
||
Accepts a [JSON-RPC Account](/docs/clients/wallet#json-rpc-accounts) or [Local Account (Private Key, etc)](/docs/clients/wallet#local-accounts-private-key-mnemonic-etc). | ||
|
||
```ts | ||
const allowance = await publicClient.getL1Allowance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### blockTag (optional) | ||
|
||
- **Type:** `BlockTag | undefined` | ||
|
||
In which block an allowance should be checked on. The latest processed one is the default option. | ||
|
||
```ts | ||
const allowance = await publicClient.getL1Allowance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!code focus] | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### bridgeAddress | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the bridge contract to be used. | ||
|
||
```ts | ||
const allowance = await publicClient.getL1Allowance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', // [!code focus] | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### token | ||
|
||
- **Type:** `Address` | ||
|
||
The Ethereum address of the token. | ||
|
||
```ts | ||
const allowance = await publicClient.getL1Allowance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
description: Returns the amount of the token held by the account on the L1 network. | ||
--- | ||
|
||
# getL1Balance | ||
|
||
Returns the amount of the token held by the account on the L1 network. | ||
|
||
## Usage | ||
|
||
:::code-group | ||
|
||
```ts [example.ts (token balance)] | ||
import { account, publicClient } from './config' | ||
|
||
const balance = await publicClient.getL1Balance({ | ||
account | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
```ts [example.ts (ETH balance)] | ||
import { account, publicClient } from './config' | ||
|
||
const balance = await publicClient.getL1Balance({ | ||
account | ||
}) | ||
``` | ||
|
||
```ts [config.ts] | ||
import { createPublicClient, custom } from 'viem' | ||
import { privateKeyToAccount } from 'viem/accounts' | ||
import { mainnet } from 'viem/chains' | ||
import { publicActionsL1 } from 'viem/zksync' | ||
|
||
export const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: custom(window.ethereum) | ||
}).extend(publicActionsL1()) | ||
|
||
// JSON-RPC Account | ||
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
// Local Account | ||
export const account = privateKeyToAccount(...) | ||
``` | ||
|
||
::: | ||
|
||
## Returns | ||
|
||
`bigint` | ||
|
||
Returns the amount of the tokens. | ||
|
||
## Parameters | ||
|
||
### account (optional) | ||
|
||
- **Type:** `Account | Address` | ||
|
||
The Account used for check. | ||
|
||
Accepts a [JSON-RPC Account](/docs/clients/wallet#json-rpc-accounts) or [Local Account (Private Key, etc)](/docs/clients/wallet#local-accounts-private-key-mnemonic-etc). | ||
|
||
```ts | ||
const balance = await publicClient.getL1Balance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### blockTag (optional) | ||
|
||
- **Type:** `BlockTag | undefined` | ||
|
||
In which block an balance should be checked on. The latest processed one is the default option. | ||
|
||
```ts | ||
const balance = await publicClient.getL1Balance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!code focus] | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### token (optional) | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the token. Defaults to ETH if not provided. | ||
|
||
```ts | ||
const balance = await publicClient.getL1Balance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
description: Retrieve the token balance held by the contract on L1. | ||
--- | ||
|
||
# getL1TokenBalance | ||
|
||
Retrieve the token balance held by the contract on L1. | ||
|
||
## Usage | ||
|
||
:::code-group | ||
|
||
```ts [example.ts] | ||
import { account, publicClient } from './config' | ||
|
||
const balance = await publicClient.getL1TokenBalance({ | ||
account | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
```ts [config.ts] | ||
import { createPublicClient, custom } from 'viem' | ||
import { privateKeyToAccount } from 'viem/accounts' | ||
import { mainnet } from 'viem/chains' | ||
import { publicActionsL1 } from 'viem/zksync' | ||
|
||
export const publicClient = createPublicClient({ | ||
chain: mainnet, | ||
transport: custom(window.ethereum) | ||
}).extend(publicActionsL1()) | ||
|
||
// JSON-RPC Account | ||
export const account = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
// Local Account | ||
export const account = privateKeyToAccount(...) | ||
``` | ||
|
||
::: | ||
|
||
## Returns | ||
|
||
`bigint` | ||
|
||
Returns the amount of the tokens. | ||
|
||
## Parameters | ||
|
||
### account | ||
|
||
- **Type:** `Account | Address` | ||
|
||
The Account used for check. | ||
|
||
Accepts a [JSON-RPC Account](/docs/clients/wallet#json-rpc-accounts) or [Local Account (Private Key, etc)](/docs/clients/wallet#local-accounts-private-key-mnemonic-etc). | ||
|
||
```ts | ||
const balance = await publicClient.getL1TokenBalance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### blockTag (optional) | ||
|
||
- **Type:** `BlockTag | undefined` | ||
|
||
In which block an balance should be checked on. The latest processed one is the default option. | ||
|
||
```ts | ||
const balance = await publicClient.getL1TokenBalance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!code focus] | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
}) | ||
``` | ||
|
||
### token | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the token. | ||
|
||
```ts | ||
const balance = await publicClient.getL1TokenBalance({ | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.