-
-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: publicActionsL1 decorator for zkSync #2190
Merged
jxom
merged 20 commits into
wevm:main
from
txfusion:kiriyaga-txfusion-publicl1-decorator-zksync
May 20, 2024
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
eefe1eb
fix: tests
jxom 0a4f3b9
Merge branch 'wevm:main' into main
kiriyaga ba85c6d
Merge branch 'wevm:main' into main
kiriyaga-txfusion 54f0ef2
feat: publicActionsL1 decorator for zkSync
kiriyaga ce7b781
feat: add getBalanceL1 action to support and balance for ETH
kiriyaga 62ad63a
fix: rename address constants
kiriyaga 82f7ece
fix: run lint formatter and revert vscode settings.json
kiriyaga 07bb1c3
fix: run lint formatter and add new check for ETH tokens
kiriyaga 1150938
Merge branch 'wevm:main' into main
kiriyaga-txfusion 90a139c
Merge branch 'wevm:main' into main
kiriyaga-txfusion 3d4c095
Merge branch 'wevm:main' into main
nikola-bozin-txfusion b4bd301
Merge branch 'wevm:main' into main
nikola-bozin-txfusion f16e19f
Merge branch 'wevm:main' into main
nikola-bozin-txfusion 213a115
Merge branch main into kiriyaga-txfusion-publicl1-decorator-zksync
nikola-bozin-txfusion 30d67b5
chore: apply lint
nikola-bozin-txfusion fb662cf
Merge branch main into kiriyaga-txfusion-publicl1-decorator-zksync
nikola-bozin-txfusion 3468313
Merge branch 'main' into kiriyaga-txfusion-publicl1-decorator-zksync
jxom adf6509
chore: tweaks
jxom 03de09f
chore: format
jxom cf85fcb
chore: changeset
jxom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
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. | ||
--- | ||
|
||
# getAllowanceL1 | ||
|
||
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.getAllowanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
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 approved tokens. | ||
|
||
## Parameters | ||
|
||
### token | ||
|
||
- **Type:** `Address` | ||
|
||
The Ethereum address of the token. | ||
|
||
```ts | ||
const allowance = await publicClient.getAllowanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### bridgeAddress | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the bridge contract to be used. | ||
|
||
```ts | ||
const allowance = await publicClient.getAllowanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', // [!code focus] | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getAllowanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getAllowanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
bridgeAddress: '0x84DbCC0B82124bee38e3Ce9a92CdE2f943bab60D', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!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. | ||
--- | ||
|
||
# getBalanceL1 | ||
|
||
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.getBalanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
account | ||
}) | ||
``` | ||
|
||
```ts [example.ts (ETH balance)] | ||
import { account, publicClient } from './config' | ||
|
||
const balance = await publicClient.getBalanceL1({ | ||
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 | ||
|
||
### token (optional) | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the token. Defaults to ETH if not provided. | ||
|
||
```ts | ||
const balance = await publicClient.getBalanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getBalanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getBalanceL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!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. | ||
--- | ||
|
||
# getBalanceOfTokenL1 | ||
|
||
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.getBalanceOfTokenL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
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 | ||
|
||
### token | ||
|
||
- **Type:** `Address` | ||
|
||
The address of the token. | ||
|
||
```ts | ||
const balance = await publicClient.getBalanceOfTokenL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', // [!code focus] | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getBalanceOfTokenL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' // [!code focus] | ||
blockTag: 'latest', | ||
}) | ||
``` | ||
|
||
### 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.getBalanceOfTokenL1({ | ||
token: '0x5C221E77624690fff6dd741493D735a17716c26B', | ||
account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' | ||
blockTag: 'latest', // [!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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change