Skip to content
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

ZkSync formatters #1361

Merged
merged 15 commits into from
Oct 26, 2023
5 changes: 5 additions & 0 deletions .changeset/tiny-dolls-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": minor
---

Added ZkSync formatters.
8 changes: 4 additions & 4 deletions src/actions/public/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ export async function call<TChain extends Chain | undefined>(
const blockNumberHex = blockNumber ? numberToHex(blockNumber) : undefined
const block = blockNumberHex || blockTag

const format =
client.chain?.formatters?.transactionRequest?.format ||
formatTransactionRequest
const chainFormat = client.chain?.formatters?.transactionRequest?.format
const format = chainFormat || formatTransactionRequest

const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format }),
...extract(rest, { format: chainFormat }),
from: account?.address,
accessList,
data,
Expand Down
8 changes: 4 additions & 4 deletions src/actions/public/estimateGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export async function estimateGas<

assertRequest(args as AssertRequestParameters)

const format =
client.chain?.formatters?.transactionRequest?.format ||
formatTransactionRequest
const chainFormat = client.chain?.formatters?.transactionRequest?.format
const format = chainFormat || formatTransactionRequest

const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format }),
...extract(rest, { format: chainFormat }),
from: account.address,
accessList,
data,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/public/simulateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export async function simulateContract<
TChain extends Chain | undefined,
const TAbi extends Abi | readonly unknown[],
TFunctionName extends string,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain>,
{
Expand Down
8 changes: 4 additions & 4 deletions src/actions/test/sendUnsignedTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ export async function sendUnsignedTransaction<
...rest
} = args

const format =
client.chain?.formatters?.transactionRequest?.format ||
formatTransactionRequest
const chainFormat = client.chain?.formatters?.transactionRequest?.format
const format = chainFormat || formatTransactionRequest

const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format }),
...extract(rest, { format: chainFormat }),
accessList,
data,
from,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/wallet/deployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function deployContract<
const TAbi extends Abi | readonly unknown[],
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
walletClient: Client<Transport, TChain, TAccount>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/actions/wallet/prepareTransactionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export type PrepareTransactionRequestErrorType =
export async function prepareTransactionRequest<
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
args: PrepareTransactionRequestParameters<TChain, TAccount, TChainOverride>,
Expand Down
9 changes: 5 additions & 4 deletions src/actions/wallet/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export type SendTransactionErrorType =
export async function sendTransaction<
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
args: SendTransactionParameters<TChain, TAccount, TChainOverride>,
Expand Down Expand Up @@ -200,11 +200,12 @@ export async function sendTransaction<
})
}

const format =
chain?.formatters?.transactionRequest?.format || formatTransactionRequest
const chainFormat = client.chain?.formatters?.transactionRequest?.format
const format = chainFormat || formatTransactionRequest

const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format }),
...extract(rest, { format: chainFormat }),
accessList,
data,
from: account.address,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/wallet/signTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export type SignTransactionErrorType =
export async function signTransaction<
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
args: SignTransactionParameters<TChain, TAccount, TChainOverride>,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/wallet/writeContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function writeContract<
TAccount extends Account | undefined,
const TAbi extends Abi | readonly unknown[],
TFunctionName extends string,
TChainOverride extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
{
Expand Down
58 changes: 32 additions & 26 deletions src/chains/definitions/zkSync.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import { defineChain } from '../../utils/chain.js'
import { formattersZkSync } from '../zksync/formatters.js'

export const zkSync = /*#__PURE__*/ defineChain({
id: 324,
name: 'zkSync Era',
network: 'zksync-era',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
rpcUrls: {
default: {
http: ['https://mainnet.era.zksync.io'],
webSocket: ['wss://mainnet.era.zksync.io/ws'],
export const zkSync = /*#__PURE__*/ defineChain(
{
id: 324,
name: 'zkSync Era',
network: 'zksync-era',
nativeCurrency: {
decimals: 18,
name: 'Ether',
symbol: 'ETH',
},
public: {
http: ['https://mainnet.era.zksync.io'],
webSocket: ['wss://mainnet.era.zksync.io/ws'],
rpcUrls: {
default: {
http: ['https://mainnet.era.zksync.io'],
webSocket: ['wss://mainnet.era.zksync.io/ws'],
},
public: {
http: ['https://mainnet.era.zksync.io'],
webSocket: ['wss://mainnet.era.zksync.io/ws'],
},
},
},
blockExplorers: {
default: {
name: 'zkExplorer',
url: 'https://explorer.zksync.io',
blockExplorers: {
default: {
name: 'zkExplorer',
url: 'https://explorer.zksync.io',
},
},
},
contracts: {
multicall3: {
address: '0xF9cda624FBC7e059355ce98a31693d299FACd963',
contracts: {
multicall3: {
address: '0xF9cda624FBC7e059355ce98a31693d299FACd963',
},
},
},
})
{
formatters: formattersZkSync,
},
)
52 changes: 29 additions & 23 deletions src/chains/definitions/zkSyncTestnet.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { defineChain } from '../../utils/chain.js'
import { formattersZkSync } from '../zksync/formatters.js'

export const zkSyncTestnet = /*#__PURE__*/ defineChain({
id: 280,
name: 'zkSync Era Testnet',
network: 'zksync-era-testnet',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['https://testnet.era.zksync.dev'],
webSocket: ['wss://testnet.era.zksync.dev/ws'],
export const zkSyncTestnet = /*#__PURE__*/ defineChain(
{
id: 280,
name: 'zkSync Era Testnet',
network: 'zksync-era-testnet',
nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
rpcUrls: {
default: {
http: ['https://testnet.era.zksync.dev'],
webSocket: ['wss://testnet.era.zksync.dev/ws'],
},
public: {
http: ['https://testnet.era.zksync.dev'],
webSocket: ['wss://testnet.era.zksync.dev/ws'],
},
},
public: {
http: ['https://testnet.era.zksync.dev'],
webSocket: ['wss://testnet.era.zksync.dev/ws'],
blockExplorers: {
default: {
name: 'zkExplorer',
url: 'https://goerli.explorer.zksync.io',
},
},
},
blockExplorers: {
default: {
name: 'zkExplorer',
url: 'https://goerli.explorer.zksync.io',
contracts: {
multicall3: {
address: '0xF9cda624FBC7e059355ce98a31693d299FACd963',
},
},
testnet: true,
},
contracts: {
multicall3: {
address: '0xF9cda624FBC7e059355ce98a31693d299FACd963',
},
{
formatters: formattersZkSync,
},
testnet: true,
})
)
1 change: 1 addition & 0 deletions src/chains/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('exports', () => {
"serializersCelo",
"parseTransactionCelo",
"formattersOptimism",
"formattersZkSync",
]
`)
})
14 changes: 14 additions & 0 deletions src/chains/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,17 @@ export type {
OptimismTransactionReceipt,
OptimismTransactionReceiptOverrides,
} from '../optimism/types.js'

export { formattersZkSync } from '../zksync/formatters.js'
export type {
TransactionEIP712,
ZkSyncBlock,
ZkSyncBlockOverrides,
ZkSyncRpcTransaction,
ZkSyncRpcTransactionReceiptOverrides,
ZkSyncRpcTransactionRequest,
ZkSyncTransaction,
ZkSyncTransactionReceipt,
ZkSyncTransactionReceiptOverrides,
ZkSyncTransactionRequest,
} from '../zksync/types.js'
Loading
Loading