viem 2.55.1 → 2.55.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/_cjs/chains/definitions/mainnet.js +1 -1
- package/_cjs/chains/definitions/mainnet.js.map +1 -1
- package/_cjs/chains/definitions/robinhood.js +1 -0
- package/_cjs/chains/definitions/robinhood.js.map +1 -1
- package/_cjs/chains/definitions/xLayer.js +1 -0
- package/_cjs/chains/definitions/xLayer.js.map +1 -1
- package/_cjs/clients/createClient.js +1 -0
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +78 -14
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +9 -0
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/utils.js +5 -0
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_cjs/utils/abi/decodeAbiParameters.js +1 -2
- package/_cjs/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_cjs/utils/unit/Value.js +118 -0
- package/_cjs/utils/unit/Value.js.map +1 -0
- package/_cjs/utils/unit/formatEther.js +2 -3
- package/_cjs/utils/unit/formatEther.js.map +1 -1
- package/_cjs/utils/unit/formatGwei.js +2 -3
- package/_cjs/utils/unit/formatGwei.js.map +1 -1
- package/_cjs/utils/unit/formatUnits.js +2 -11
- package/_cjs/utils/unit/formatUnits.js.map +1 -1
- package/_cjs/utils/unit/parseEther.js +2 -3
- package/_cjs/utils/unit/parseEther.js.map +1 -1
- package/_cjs/utils/unit/parseGwei.js +2 -3
- package/_cjs/utils/unit/parseGwei.js.map +1 -1
- package/_cjs/utils/unit/parseUnits.js +2 -34
- package/_cjs/utils/unit/parseUnits.js.map +1 -1
- package/_esm/chains/definitions/mainnet.js +1 -1
- package/_esm/chains/definitions/mainnet.js.map +1 -1
- package/_esm/chains/definitions/robinhood.js +1 -0
- package/_esm/chains/definitions/robinhood.js.map +1 -1
- package/_esm/chains/definitions/xLayer.js +1 -0
- package/_esm/chains/definitions/xLayer.js.map +1 -1
- package/_esm/clients/createClient.js +4 -3
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/actions/zone.js +141 -17
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/chainConfig.js +10 -0
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/utils.js +5 -0
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_esm/utils/abi/decodeAbiParameters.js +1 -2
- package/_esm/utils/abi/decodeAbiParameters.js.map +1 -1
- package/_esm/utils/unit/Value.js +240 -0
- package/_esm/utils/unit/Value.js.map +1 -0
- package/_esm/utils/unit/formatEther.js +2 -3
- package/_esm/utils/unit/formatEther.js.map +1 -1
- package/_esm/utils/unit/formatGwei.js +2 -3
- package/_esm/utils/unit/formatGwei.js.map +1 -1
- package/_esm/utils/unit/formatUnits.js +2 -11
- package/_esm/utils/unit/formatUnits.js.map +1 -1
- package/_esm/utils/unit/parseEther.js +2 -3
- package/_esm/utils/unit/parseEther.js.map +1 -1
- package/_esm/utils/unit/parseGwei.js +2 -3
- package/_esm/utils/unit/parseGwei.js.map +1 -1
- package/_esm/utils/unit/parseUnits.js +2 -36
- package/_esm/utils/unit/parseUnits.js.map +1 -1
- package/_types/chains/definitions/mainnet.d.ts +1 -1
- package/_types/chains/definitions/robinhood.d.ts +1 -1
- package/_types/chains/definitions/robinhood.d.ts.map +1 -1
- package/_types/chains/definitions/xLayer.d.ts +1 -1
- package/_types/chains/definitions/xLayer.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +3 -3
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Decorator.d.ts +7 -1
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +133 -11
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/types.d.ts +1 -0
- package/_types/tempo/internal/types.d.ts.map +1 -1
- package/_types/tempo/internal/utils.d.ts +5 -0
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/_types/utils/abi/decodeAbiParameters.d.ts +1 -2
- package/_types/utils/abi/decodeAbiParameters.d.ts.map +1 -1
- package/_types/utils/unit/Value.d.ts +115 -0
- package/_types/utils/unit/Value.d.ts.map +1 -0
- package/_types/utils/unit/formatEther.d.ts +1 -1
- package/_types/utils/unit/formatEther.d.ts.map +1 -1
- package/_types/utils/unit/formatGwei.d.ts +1 -1
- package/_types/utils/unit/formatGwei.d.ts.map +1 -1
- package/_types/utils/unit/formatUnits.d.ts.map +1 -1
- package/_types/utils/unit/parseEther.d.ts +1 -1
- package/_types/utils/unit/parseEther.d.ts.map +1 -1
- package/_types/utils/unit/parseGwei.d.ts +1 -1
- package/_types/utils/unit/parseGwei.d.ts.map +1 -1
- package/_types/utils/unit/parseUnits.d.ts.map +1 -1
- package/chains/definitions/mainnet.ts +1 -1
- package/chains/definitions/robinhood.ts +1 -0
- package/chains/definitions/xLayer.ts +1 -0
- package/clients/createClient.ts +4 -3
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/tempo/Decorator.ts +21 -2
- package/tempo/actions/zone.ts +305 -33
- package/tempo/chainConfig.ts +10 -0
- package/tempo/internal/types.ts +8 -0
- package/tempo/internal/utils.ts +6 -0
- package/utils/abi/decodeAbiParameters.ts +1 -3
- package/utils/unit/Value.ts +278 -0
- package/utils/unit/formatEther.ts +3 -4
- package/utils/unit/formatGwei.ts +3 -4
- package/utils/unit/formatUnits.ts +2 -15
- package/utils/unit/parseEther.ts +3 -4
- package/utils/unit/parseGwei.ts +3 -4
- package/utils/unit/parseUnits.ts +2 -40
package/tempo/actions/zone.ts
CHANGED
|
@@ -12,6 +12,12 @@ import {
|
|
|
12
12
|
multicall,
|
|
13
13
|
} from '../../actions/public/multicall.js'
|
|
14
14
|
import { readContract } from '../../actions/public/readContract.js'
|
|
15
|
+
import {
|
|
16
|
+
type PrepareTransactionRequestErrorType,
|
|
17
|
+
type PrepareTransactionRequestRequest,
|
|
18
|
+
type PrepareTransactionRequestReturnType,
|
|
19
|
+
prepareTransactionRequest,
|
|
20
|
+
} from '../../actions/wallet/prepareTransactionRequest.js'
|
|
15
21
|
import {
|
|
16
22
|
type SendTransactionReturnType,
|
|
17
23
|
sendTransaction,
|
|
@@ -21,7 +27,7 @@ import type { Client } from '../../clients/createClient.js'
|
|
|
21
27
|
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
22
28
|
import { zeroHash } from '../../constants/bytes.js'
|
|
23
29
|
import type { BaseErrorType } from '../../errors/base.js'
|
|
24
|
-
import type { Chain } from '../../types/chain.js'
|
|
30
|
+
import type { Chain, GetChainParameter } from '../../types/chain.js'
|
|
25
31
|
import type { Compute, UnionOmit } from '../../types/utils.js'
|
|
26
32
|
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
|
27
33
|
import { type ObserveErrorType, observe } from '../../utils/observe.js'
|
|
@@ -38,8 +44,13 @@ import type {
|
|
|
38
44
|
GetAccountParameter,
|
|
39
45
|
ReadParameters,
|
|
40
46
|
WriteParameters,
|
|
47
|
+
WriteSyncParameters,
|
|
41
48
|
} from '../internal/types.js'
|
|
42
|
-
import {
|
|
49
|
+
import {
|
|
50
|
+
defineCall,
|
|
51
|
+
pickWriteParameters,
|
|
52
|
+
pickWriteSyncParameters,
|
|
53
|
+
} from '../internal/utils.js'
|
|
43
54
|
import * as Storage from '../Storage.js'
|
|
44
55
|
import type { TransactionReceipt } from '../Transaction.js'
|
|
45
56
|
import * as ZoneAbis from '../zones/Abis.js'
|
|
@@ -72,6 +83,19 @@ export type PreparedEncryptedDeposit = {
|
|
|
72
83
|
zoneId: number
|
|
73
84
|
}
|
|
74
85
|
|
|
86
|
+
export type PreparedEncryptedDepositRecipient = {
|
|
87
|
+
/** Parent chain ID (e.g. `42431` for moderato). */
|
|
88
|
+
chainId: number
|
|
89
|
+
/** Encrypted recipient and memo payload. */
|
|
90
|
+
encrypted: EncryptedPayload
|
|
91
|
+
/** Encryption key index from the portal contract. */
|
|
92
|
+
keyIndex: bigint
|
|
93
|
+
/** Zone portal address on the parent chain. */
|
|
94
|
+
portalAddress: Address
|
|
95
|
+
/** Zone ID (e.g. `7`). */
|
|
96
|
+
zoneId: number
|
|
97
|
+
}
|
|
98
|
+
|
|
75
99
|
/**
|
|
76
100
|
* Deposits tokens into a zone on the parent Tempo chain.
|
|
77
101
|
* Batches approve and deposit into a single transaction.
|
|
@@ -626,6 +650,93 @@ export namespace encryptedDeposit {
|
|
|
626
650
|
export type ErrorType = getEncryptionKey.ErrorType | BaseErrorType
|
|
627
651
|
}
|
|
628
652
|
|
|
653
|
+
/**
|
|
654
|
+
* Prepares encrypted Zone recipient instructions without constructing a token
|
|
655
|
+
* deposit.
|
|
656
|
+
*
|
|
657
|
+
* Use this when another contract or service controls the token movement and
|
|
658
|
+
* only needs the ZonePortal `keyIndex` and encrypted recipient payload.
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```ts
|
|
662
|
+
* import { createClient, http } from 'viem'
|
|
663
|
+
* import { tempoModerato } from 'viem/chains'
|
|
664
|
+
* import { Actions } from 'viem/tempo'
|
|
665
|
+
*
|
|
666
|
+
* const client = createClient({
|
|
667
|
+
* chain: tempoModerato,
|
|
668
|
+
* transport: http(),
|
|
669
|
+
* })
|
|
670
|
+
*
|
|
671
|
+
* const recipient = await Actions.zone.encryptedDeposit.prepareRecipient(client, {
|
|
672
|
+
* recipient: '0x...',
|
|
673
|
+
* zoneId: 7,
|
|
674
|
+
* })
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @param client - Public client connected to the parent Tempo chain.
|
|
678
|
+
* @param parameters - Encrypted recipient preparation parameters.
|
|
679
|
+
* @returns Prepared encrypted recipient instructions.
|
|
680
|
+
*/
|
|
681
|
+
export async function prepareRecipient<
|
|
682
|
+
chain extends Chain | undefined,
|
|
683
|
+
account extends Account | undefined,
|
|
684
|
+
>(
|
|
685
|
+
client: Client<Transport, chain, account>,
|
|
686
|
+
parameters: prepareRecipient.Parameters,
|
|
687
|
+
): Promise<prepareRecipient.ReturnValue> {
|
|
688
|
+
const chainId = client.chain?.id
|
|
689
|
+
if (!chainId) throw new Error('`chain` is required.')
|
|
690
|
+
|
|
691
|
+
const {
|
|
692
|
+
memo,
|
|
693
|
+
portalAddress: portalAddress_,
|
|
694
|
+
recipient,
|
|
695
|
+
zoneId,
|
|
696
|
+
...rest
|
|
697
|
+
} = parameters
|
|
698
|
+
const portalAddress = portalAddress_ ?? getPortalAddress(chainId, zoneId)
|
|
699
|
+
const { keyIndex, publicKey } = await getEncryptionKey(client, {
|
|
700
|
+
...rest,
|
|
701
|
+
portalAddress,
|
|
702
|
+
zoneId,
|
|
703
|
+
})
|
|
704
|
+
const encrypted = await encryptDepositPayload(
|
|
705
|
+
publicKey,
|
|
706
|
+
recipient,
|
|
707
|
+
portalAddress,
|
|
708
|
+
keyIndex,
|
|
709
|
+
memo,
|
|
710
|
+
)
|
|
711
|
+
|
|
712
|
+
return {
|
|
713
|
+
chainId,
|
|
714
|
+
encrypted,
|
|
715
|
+
keyIndex,
|
|
716
|
+
portalAddress,
|
|
717
|
+
zoneId,
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
export namespace prepareRecipient {
|
|
722
|
+
export type Parameters = ReadParameters & Args
|
|
723
|
+
|
|
724
|
+
export type Args = {
|
|
725
|
+
/** Optional deposit memo. @default `0x00...00` */
|
|
726
|
+
memo?: Hex.Hex | undefined
|
|
727
|
+
/** Zone portal address. @default resolved via the portal registry. */
|
|
728
|
+
portalAddress?: Address | undefined
|
|
729
|
+
/** Recipient address in the zone. */
|
|
730
|
+
recipient: Address
|
|
731
|
+
/** Zone ID (e.g. `7`). */
|
|
732
|
+
zoneId: number
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export type ReturnValue = PreparedEncryptedDepositRecipient
|
|
736
|
+
|
|
737
|
+
export type ErrorType = getEncryptionKey.ErrorType | BaseErrorType
|
|
738
|
+
}
|
|
739
|
+
|
|
629
740
|
/**
|
|
630
741
|
* Defines the calls to approve and deposit tokens into a zone (encrypted).
|
|
631
742
|
*
|
|
@@ -731,6 +842,7 @@ export async function encryptedDepositSync<
|
|
|
731
842
|
}
|
|
732
843
|
const receipt = await sendTransactionSync(client, {
|
|
733
844
|
...pickWriteParameters(parameters as never),
|
|
845
|
+
...pickWriteSyncParameters(parameters as never),
|
|
734
846
|
throwOnReceiptRevert,
|
|
735
847
|
calls: encryptedDeposit.calls({
|
|
736
848
|
...parameters,
|
|
@@ -764,7 +876,8 @@ export namespace encryptedDepositSync {
|
|
|
764
876
|
export type Parameters<
|
|
765
877
|
chain extends Chain | undefined = Chain | undefined,
|
|
766
878
|
account extends Account | undefined = Account | undefined,
|
|
767
|
-
> = encryptedDeposit.Parameters<chain, account>
|
|
879
|
+
> = encryptedDeposit.Parameters<chain, account> &
|
|
880
|
+
WriteSyncParameters<chain, account>
|
|
768
881
|
|
|
769
882
|
export type Args = encryptedDeposit.Args
|
|
770
883
|
|
|
@@ -1047,7 +1160,8 @@ export namespace waitForDepositStatus {
|
|
|
1047
1160
|
}
|
|
1048
1161
|
|
|
1049
1162
|
/**
|
|
1050
|
-
* Returns the fee required for a withdrawal from a zone, given a gas
|
|
1163
|
+
* Returns the fee required for a withdrawal from a zone, given a callback gas
|
|
1164
|
+
* limit.
|
|
1051
1165
|
*
|
|
1052
1166
|
* The client must be connected to the **zone chain**.
|
|
1053
1167
|
*
|
|
@@ -1066,7 +1180,7 @@ export namespace waitForDepositStatus {
|
|
|
1066
1180
|
* ```
|
|
1067
1181
|
*
|
|
1068
1182
|
* @param client - Zone client.
|
|
1069
|
-
* @param parameters - Optional gas limit parameter.
|
|
1183
|
+
* @param parameters - Optional callback gas limit parameter.
|
|
1070
1184
|
* @returns The withdrawal fee as a bigint.
|
|
1071
1185
|
*/
|
|
1072
1186
|
export async function getWithdrawalFee<
|
|
@@ -1076,20 +1190,20 @@ export async function getWithdrawalFee<
|
|
|
1076
1190
|
client: Client<Transport, chain, account>,
|
|
1077
1191
|
parameters: getWithdrawalFee.Parameters = {},
|
|
1078
1192
|
): Promise<getWithdrawalFee.ReturnType> {
|
|
1079
|
-
const {
|
|
1193
|
+
const { callbackGas = 0n, ...rest } = parameters
|
|
1080
1194
|
return readContract(client, {
|
|
1081
1195
|
...rest,
|
|
1082
1196
|
address: Addresses.zoneOutbox,
|
|
1083
1197
|
abi: ZoneAbis.zoneOutbox,
|
|
1084
1198
|
functionName: 'calculateWithdrawalFee',
|
|
1085
|
-
args: [
|
|
1199
|
+
args: [callbackGas],
|
|
1086
1200
|
})
|
|
1087
1201
|
}
|
|
1088
1202
|
|
|
1089
1203
|
export namespace getWithdrawalFee {
|
|
1090
1204
|
export type Parameters = ReadParameters & {
|
|
1091
|
-
/** Gas limit for the withdrawal callback. @default `0n` */
|
|
1092
|
-
|
|
1205
|
+
/** Gas limit reserved for the withdrawal callback on the parent chain. @default `0n` */
|
|
1206
|
+
callbackGas?: bigint | undefined
|
|
1093
1207
|
}
|
|
1094
1208
|
|
|
1095
1209
|
export type ReturnType = bigint
|
|
@@ -1192,7 +1306,7 @@ export async function requestWithdrawal<
|
|
|
1192
1306
|
client: Client<Transport, chain, account>,
|
|
1193
1307
|
parameters: requestWithdrawal.Parameters<chain, account>,
|
|
1194
1308
|
): Promise<requestWithdrawal.ReturnValue> {
|
|
1195
|
-
const { account = client.account
|
|
1309
|
+
const { account = client.account } = parameters
|
|
1196
1310
|
|
|
1197
1311
|
const account_ = account ? parseAccount(account) : undefined
|
|
1198
1312
|
if (!account) throw new Error('`account` is required.')
|
|
@@ -1202,7 +1316,7 @@ export async function requestWithdrawal<
|
|
|
1202
1316
|
|
|
1203
1317
|
const args = { ...parameters, to }
|
|
1204
1318
|
return sendTransaction(client, {
|
|
1205
|
-
...
|
|
1319
|
+
...pickWriteParameters(parameters as never),
|
|
1206
1320
|
calls: requestWithdrawal.calls(args),
|
|
1207
1321
|
} as never) as never
|
|
1208
1322
|
}
|
|
@@ -1220,12 +1334,12 @@ export namespace requestWithdrawal {
|
|
|
1220
1334
|
export type Args = {
|
|
1221
1335
|
/** Amount of tokens to withdraw. */
|
|
1222
1336
|
amount: bigint
|
|
1337
|
+
/** Gas limit reserved for the withdrawal callback on the parent chain. @default `0n` */
|
|
1338
|
+
callbackGas?: bigint | undefined
|
|
1223
1339
|
/** Optional callback data for the recipient. @default `'0x'` */
|
|
1224
1340
|
data?: Hex.Hex | undefined
|
|
1225
1341
|
/** Fallback address if callback fails. @default `to` */
|
|
1226
1342
|
fallbackRecipient?: Address | undefined
|
|
1227
|
-
/** Gas limit reserved for the withdrawal callback on the parent chain. @default `0n` */
|
|
1228
|
-
gas?: bigint | undefined
|
|
1229
1343
|
/** Optional withdrawal memo. @default `0x00...00` */
|
|
1230
1344
|
memo?: Hex.Hex | undefined
|
|
1231
1345
|
/** Recipient address on the parent Tempo chain. */
|
|
@@ -1248,9 +1362,9 @@ export namespace requestWithdrawal {
|
|
|
1248
1362
|
export function calls(args: Args) {
|
|
1249
1363
|
const {
|
|
1250
1364
|
amount,
|
|
1365
|
+
callbackGas = 0n,
|
|
1251
1366
|
data = '0x',
|
|
1252
1367
|
fallbackRecipient = args.to,
|
|
1253
|
-
gas = 0n,
|
|
1254
1368
|
memo = zeroHash,
|
|
1255
1369
|
to,
|
|
1256
1370
|
token,
|
|
@@ -1271,7 +1385,7 @@ export namespace requestWithdrawal {
|
|
|
1271
1385
|
to,
|
|
1272
1386
|
amount,
|
|
1273
1387
|
memo,
|
|
1274
|
-
|
|
1388
|
+
callbackGas,
|
|
1275
1389
|
fallbackRecipient,
|
|
1276
1390
|
data,
|
|
1277
1391
|
'0x',
|
|
@@ -1279,8 +1393,166 @@ export namespace requestWithdrawal {
|
|
|
1279
1393
|
}),
|
|
1280
1394
|
]
|
|
1281
1395
|
}
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Prepares a zone withdrawal transaction request without broadcasting it.
|
|
1399
|
+
*
|
|
1400
|
+
* Use this to inspect or modify the populated ZoneOutbox transaction request
|
|
1401
|
+
* and its maximum transaction fee before submitting a withdrawal.
|
|
1402
|
+
*
|
|
1403
|
+
* @example
|
|
1404
|
+
* ```ts
|
|
1405
|
+
* import { createClient } from 'viem'
|
|
1406
|
+
* import { http, zoneModerato } from 'viem/tempo/zones'
|
|
1407
|
+
* import { Actions } from 'viem/tempo'
|
|
1408
|
+
*
|
|
1409
|
+
* const client = createClient({
|
|
1410
|
+
* chain: zoneModerato(7),
|
|
1411
|
+
* transport: http(),
|
|
1412
|
+
* })
|
|
1413
|
+
*
|
|
1414
|
+
* const prepared = await Actions.zone.requestWithdrawal.prepare(client, {
|
|
1415
|
+
* token: '0x20c0...0001',
|
|
1416
|
+
* amount: 1_000_000n,
|
|
1417
|
+
* to: '0x...',
|
|
1418
|
+
* })
|
|
1419
|
+
*
|
|
1420
|
+
* console.log(prepared.maxFee)
|
|
1421
|
+
* console.log(prepared.request.gas)
|
|
1422
|
+
* ```
|
|
1423
|
+
*
|
|
1424
|
+
* @param client - Zone client.
|
|
1425
|
+
* @param parameters - Withdrawal preparation parameters.
|
|
1426
|
+
* @returns The prepared transaction request, maximum fee, and withdrawal details.
|
|
1427
|
+
*/
|
|
1428
|
+
export async function prepare<
|
|
1429
|
+
chain extends Chain | undefined,
|
|
1430
|
+
account extends Account | undefined,
|
|
1431
|
+
chainOverride extends Chain | undefined = undefined,
|
|
1432
|
+
accountOverride extends Account | Address | undefined = undefined,
|
|
1433
|
+
>(
|
|
1434
|
+
client: Client<Transport, chain, account>,
|
|
1435
|
+
parameters: prepare.Parameters<
|
|
1436
|
+
chain,
|
|
1437
|
+
account,
|
|
1438
|
+
chainOverride,
|
|
1439
|
+
accountOverride
|
|
1440
|
+
>,
|
|
1441
|
+
): Promise<
|
|
1442
|
+
prepare.ReturnType<chain, account, chainOverride, accountOverride>
|
|
1443
|
+
> {
|
|
1444
|
+
const {
|
|
1445
|
+
account = client.account,
|
|
1446
|
+
amount,
|
|
1447
|
+
callbackGas = 0n,
|
|
1448
|
+
data = '0x',
|
|
1449
|
+
fallbackRecipient,
|
|
1450
|
+
memo = zeroHash,
|
|
1451
|
+
to: to_,
|
|
1452
|
+
token,
|
|
1453
|
+
...transactionRequest
|
|
1454
|
+
} = parameters
|
|
1455
|
+
|
|
1456
|
+
const account_ = account ? parseAccount(account) : undefined
|
|
1457
|
+
const to = to_ ?? account_?.address
|
|
1458
|
+
if (!to) throw new Error('`to` is required.')
|
|
1459
|
+
|
|
1460
|
+
const request = await prepareTransactionRequest(client, {
|
|
1461
|
+
...transactionRequest,
|
|
1462
|
+
account,
|
|
1463
|
+
calls: requestWithdrawal.calls({
|
|
1464
|
+
amount,
|
|
1465
|
+
callbackGas,
|
|
1466
|
+
data,
|
|
1467
|
+
fallbackRecipient,
|
|
1468
|
+
memo,
|
|
1469
|
+
to,
|
|
1470
|
+
token,
|
|
1471
|
+
}),
|
|
1472
|
+
} as never)
|
|
1473
|
+
const feePerGas = request.maxFeePerGas ?? request.gasPrice
|
|
1474
|
+
if (typeof request.gas !== 'bigint' || typeof feePerGas !== 'bigint')
|
|
1475
|
+
throw new Error('Prepared transaction fee parameters are unavailable.')
|
|
1476
|
+
const maxFee = ceilDiv(request.gas * feePerGas, 1_000_000_000_000n)
|
|
1477
|
+
|
|
1478
|
+
return {
|
|
1479
|
+
amount,
|
|
1480
|
+
callbackGas,
|
|
1481
|
+
data,
|
|
1482
|
+
fallbackRecipient: fallbackRecipient ?? to,
|
|
1483
|
+
maxFee,
|
|
1484
|
+
memo,
|
|
1485
|
+
request,
|
|
1486
|
+
to,
|
|
1487
|
+
token,
|
|
1488
|
+
} as never
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
export namespace prepare {
|
|
1492
|
+
export type Parameters<
|
|
1493
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1494
|
+
account extends Account | undefined = Account | undefined,
|
|
1495
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
1496
|
+
accountOverride extends Account | Address | undefined =
|
|
1497
|
+
| Account
|
|
1498
|
+
| Address
|
|
1499
|
+
| undefined,
|
|
1500
|
+
> = UnionOmit<
|
|
1501
|
+
WriteParameters<chain, account>,
|
|
1502
|
+
'account' | 'chain' | 'throwOnReceiptRevert'
|
|
1503
|
+
> &
|
|
1504
|
+
GetAccountParameter<account, accountOverride, false> &
|
|
1505
|
+
GetChainParameter<chain, chainOverride> &
|
|
1506
|
+
PrepareArgs
|
|
1507
|
+
|
|
1508
|
+
export type PrepareArgs = Omit<Args, 'to'> & {
|
|
1509
|
+
/** Recipient address on the parent Tempo chain. @default `account.address` */
|
|
1510
|
+
to?: Address | undefined
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
export type ReturnType<
|
|
1514
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1515
|
+
account extends Account | undefined = Account | undefined,
|
|
1516
|
+
chainOverride extends Chain | undefined = Chain | undefined,
|
|
1517
|
+
accountOverride extends Account | Address | undefined =
|
|
1518
|
+
| Account
|
|
1519
|
+
| Address
|
|
1520
|
+
| undefined,
|
|
1521
|
+
> = Compute<{
|
|
1522
|
+
/** Amount of tokens to withdraw. */
|
|
1523
|
+
amount: bigint
|
|
1524
|
+
/** Gas limit reserved for the callback on the parent chain. */
|
|
1525
|
+
callbackGas: bigint
|
|
1526
|
+
/** Callback data for the recipient. */
|
|
1527
|
+
data: Hex.Hex
|
|
1528
|
+
/** Fallback address if the callback fails. */
|
|
1529
|
+
fallbackRecipient: Address
|
|
1530
|
+
/** Maximum Zone transaction fee in fee-token base units. */
|
|
1531
|
+
maxFee: bigint
|
|
1532
|
+
/** Withdrawal memo. */
|
|
1533
|
+
memo: Hex.Hex
|
|
1534
|
+
/** Prepared Zone transaction request. */
|
|
1535
|
+
request: PrepareTransactionRequestReturnType<
|
|
1536
|
+
chain,
|
|
1537
|
+
account,
|
|
1538
|
+
chainOverride,
|
|
1539
|
+
accountOverride,
|
|
1540
|
+
PrepareTransactionRequestRequest<chain, chainOverride> & {
|
|
1541
|
+
calls: WithdrawalCalls
|
|
1542
|
+
}
|
|
1543
|
+
>
|
|
1544
|
+
/** Recipient address on the parent Tempo chain. */
|
|
1545
|
+
to: Address
|
|
1546
|
+
/** Token address or ID to withdraw. */
|
|
1547
|
+
token: TokenId.TokenIdOrAddress
|
|
1548
|
+
}>
|
|
1549
|
+
|
|
1550
|
+
export type ErrorType = PrepareTransactionRequestErrorType | BaseErrorType
|
|
1551
|
+
}
|
|
1282
1552
|
}
|
|
1283
1553
|
|
|
1554
|
+
type WithdrawalCalls = ReturnType<typeof requestWithdrawal.calls>
|
|
1555
|
+
|
|
1284
1556
|
/**
|
|
1285
1557
|
* Requests a withdrawal from a zone to the parent Tempo chain and waits for
|
|
1286
1558
|
* the transaction receipt.
|
|
@@ -1315,11 +1587,7 @@ export async function requestWithdrawalSync<
|
|
|
1315
1587
|
client: Client<Transport, chain, account>,
|
|
1316
1588
|
parameters: requestWithdrawalSync.Parameters<chain, account>,
|
|
1317
1589
|
): Promise<requestWithdrawalSync.ReturnValue> {
|
|
1318
|
-
const {
|
|
1319
|
-
account = client.account,
|
|
1320
|
-
throwOnReceiptRevert = true,
|
|
1321
|
-
...rest
|
|
1322
|
-
} = parameters
|
|
1590
|
+
const { account = client.account, throwOnReceiptRevert = true } = parameters
|
|
1323
1591
|
|
|
1324
1592
|
const account_ = account ? parseAccount(account) : undefined
|
|
1325
1593
|
if (!account) throw new Error('`account` is required.')
|
|
@@ -1329,7 +1597,8 @@ export async function requestWithdrawalSync<
|
|
|
1329
1597
|
|
|
1330
1598
|
const args = { ...parameters, to }
|
|
1331
1599
|
const receipt = await sendTransactionSync(client, {
|
|
1332
|
-
...
|
|
1600
|
+
...pickWriteParameters(parameters as never),
|
|
1601
|
+
...pickWriteSyncParameters(parameters as never),
|
|
1333
1602
|
calls: requestWithdrawal.calls(args),
|
|
1334
1603
|
throwOnReceiptRevert,
|
|
1335
1604
|
} as never)
|
|
@@ -1340,7 +1609,8 @@ export namespace requestWithdrawalSync {
|
|
|
1340
1609
|
export type Parameters<
|
|
1341
1610
|
chain extends Chain | undefined = Chain | undefined,
|
|
1342
1611
|
account extends Account | undefined = Account | undefined,
|
|
1343
|
-
> = requestWithdrawal.Parameters<chain, account>
|
|
1612
|
+
> = requestWithdrawal.Parameters<chain, account> &
|
|
1613
|
+
WriteSyncParameters<chain, account>
|
|
1344
1614
|
|
|
1345
1615
|
export type Args = requestWithdrawal.Args
|
|
1346
1616
|
|
|
@@ -1391,7 +1661,7 @@ export async function requestVerifiableWithdrawal<
|
|
|
1391
1661
|
client: Client<Transport, chain, account>,
|
|
1392
1662
|
parameters: requestVerifiableWithdrawal.Parameters<chain, account>,
|
|
1393
1663
|
): Promise<requestVerifiableWithdrawal.ReturnValue> {
|
|
1394
|
-
const { account = client.account
|
|
1664
|
+
const { account = client.account } = parameters
|
|
1395
1665
|
|
|
1396
1666
|
const account_ = account ? parseAccount(account) : undefined
|
|
1397
1667
|
if (!account) throw new Error('`account` is required.')
|
|
@@ -1401,7 +1671,7 @@ export async function requestVerifiableWithdrawal<
|
|
|
1401
1671
|
|
|
1402
1672
|
const args = { ...parameters, to }
|
|
1403
1673
|
return sendTransaction(client, {
|
|
1404
|
-
...
|
|
1674
|
+
...pickWriteParameters(parameters as never),
|
|
1405
1675
|
calls: requestVerifiableWithdrawal.calls(args),
|
|
1406
1676
|
} as never) as never
|
|
1407
1677
|
}
|
|
@@ -1435,9 +1705,9 @@ export namespace requestVerifiableWithdrawal {
|
|
|
1435
1705
|
export function calls(args: Args) {
|
|
1436
1706
|
const {
|
|
1437
1707
|
amount,
|
|
1708
|
+
callbackGas = 0n,
|
|
1438
1709
|
data = '0x',
|
|
1439
1710
|
fallbackRecipient = args.to,
|
|
1440
|
-
gas = 0n,
|
|
1441
1711
|
memo = zeroHash,
|
|
1442
1712
|
revealTo,
|
|
1443
1713
|
to,
|
|
@@ -1459,7 +1729,7 @@ export namespace requestVerifiableWithdrawal {
|
|
|
1459
1729
|
to,
|
|
1460
1730
|
amount,
|
|
1461
1731
|
memo,
|
|
1462
|
-
|
|
1732
|
+
callbackGas,
|
|
1463
1733
|
fallbackRecipient,
|
|
1464
1734
|
data,
|
|
1465
1735
|
revealTo,
|
|
@@ -1504,11 +1774,7 @@ export async function requestVerifiableWithdrawalSync<
|
|
|
1504
1774
|
client: Client<Transport, chain, account>,
|
|
1505
1775
|
parameters: requestVerifiableWithdrawalSync.Parameters<chain, account>,
|
|
1506
1776
|
): Promise<requestVerifiableWithdrawalSync.ReturnValue> {
|
|
1507
|
-
const {
|
|
1508
|
-
account = client.account,
|
|
1509
|
-
throwOnReceiptRevert = true,
|
|
1510
|
-
...rest
|
|
1511
|
-
} = parameters
|
|
1777
|
+
const { account = client.account, throwOnReceiptRevert = true } = parameters
|
|
1512
1778
|
|
|
1513
1779
|
const account_ = account ? parseAccount(account) : undefined
|
|
1514
1780
|
if (!account) throw new Error('`account` is required.')
|
|
@@ -1518,7 +1784,8 @@ export async function requestVerifiableWithdrawalSync<
|
|
|
1518
1784
|
|
|
1519
1785
|
const args = { ...parameters, to }
|
|
1520
1786
|
const receipt = await sendTransactionSync(client, {
|
|
1521
|
-
...
|
|
1787
|
+
...pickWriteParameters(parameters as never),
|
|
1788
|
+
...pickWriteSyncParameters(parameters as never),
|
|
1522
1789
|
calls: requestVerifiableWithdrawal.calls(args),
|
|
1523
1790
|
throwOnReceiptRevert,
|
|
1524
1791
|
} as never)
|
|
@@ -1529,7 +1796,8 @@ export namespace requestVerifiableWithdrawalSync {
|
|
|
1529
1796
|
export type Parameters<
|
|
1530
1797
|
chain extends Chain | undefined = Chain | undefined,
|
|
1531
1798
|
account extends Account | undefined = Account | undefined,
|
|
1532
|
-
> = requestVerifiableWithdrawal.Parameters<chain, account>
|
|
1799
|
+
> = requestVerifiableWithdrawal.Parameters<chain, account> &
|
|
1800
|
+
WriteSyncParameters<chain, account>
|
|
1533
1801
|
|
|
1534
1802
|
export type Args = requestVerifiableWithdrawal.Args
|
|
1535
1803
|
|
|
@@ -1738,3 +2006,7 @@ function buildDepositHkdfInfo(
|
|
|
1738
2006
|
Bytes.from(ephemeralPubkeyX),
|
|
1739
2007
|
)
|
|
1740
2008
|
}
|
|
2009
|
+
|
|
2010
|
+
function ceilDiv(numerator: bigint, denominator: bigint) {
|
|
2011
|
+
return (numerator + denominator - 1n) / denominator
|
|
2012
|
+
}
|
package/tempo/chainConfig.ts
CHANGED
|
@@ -22,6 +22,14 @@ import * as Transaction from './Transaction.js'
|
|
|
22
22
|
|
|
23
23
|
const maxExpirySecs = 25
|
|
24
24
|
|
|
25
|
+
/** Returns random past seconds to distinguish otherwise-identical expiring transactions. */
|
|
26
|
+
function randomValidAfter(): number {
|
|
27
|
+
const now = BigInt(Math.floor(Date.now() / 1_000))
|
|
28
|
+
const latest = now - 60n
|
|
29
|
+
if (latest <= 0n) return 0
|
|
30
|
+
return Number(BigInt(Hex.random(8)) % latest)
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
export const chainConfig = {
|
|
26
34
|
blockTime: 1_000,
|
|
27
35
|
extendSchema: extendSchema<{
|
|
@@ -160,6 +168,8 @@ export const chainConfig = {
|
|
|
160
168
|
if (useExpiringNonce) {
|
|
161
169
|
request.nonceKey = maxUint256
|
|
162
170
|
request.nonce = 0
|
|
171
|
+
if (typeof request.validAfter === 'undefined')
|
|
172
|
+
request.validAfter = randomValidAfter()
|
|
163
173
|
if (typeof request.validBefore === 'undefined')
|
|
164
174
|
request.validBefore = Math.floor(Date.now() / 1000) + maxExpirySecs
|
|
165
175
|
} else if (typeof request.nonceKey !== 'undefined') {
|
package/tempo/internal/types.ts
CHANGED
|
@@ -77,3 +77,11 @@ export type WriteParameters<
|
|
|
77
77
|
| 'validAfter'
|
|
78
78
|
| 'validBefore'
|
|
79
79
|
>
|
|
80
|
+
|
|
81
|
+
export type WriteSyncParameters<
|
|
82
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
83
|
+
account extends Account | undefined = Account | undefined,
|
|
84
|
+
> = UnionPick<
|
|
85
|
+
viem_WriteContractSyncParameters<never, never, never, chain, account>,
|
|
86
|
+
'pollingInterval' | 'timeout'
|
|
87
|
+
>
|
package/tempo/internal/utils.ts
CHANGED
|
@@ -216,6 +216,12 @@ export function pickWriteParameters(parameters: Record<string, unknown>) {
|
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
/** @internal */
|
|
220
|
+
export function pickWriteSyncParameters(parameters: Record<string, unknown>) {
|
|
221
|
+
const { pollingInterval, timeout } = parameters
|
|
222
|
+
return { pollingInterval, timeout }
|
|
223
|
+
}
|
|
224
|
+
|
|
219
225
|
/**
|
|
220
226
|
* Parameters of an action's `.call` builder: the call arguments, optionally
|
|
221
227
|
* preceded by a Client. The Client is used to resolve token symbols declared
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
} from '../cursor.js'
|
|
23
23
|
import { type SizeErrorType, size } from '../data/size.js'
|
|
24
24
|
import { type SliceBytesErrorType, sliceBytes } from '../data/slice.js'
|
|
25
|
-
import { type TrimErrorType, trim } from '../data/trim.js'
|
|
26
25
|
import {
|
|
27
26
|
type BytesToBigIntErrorType,
|
|
28
27
|
type BytesToBoolErrorType,
|
|
@@ -355,7 +354,6 @@ function decodeTuple(
|
|
|
355
354
|
type DecodeStringErrorType =
|
|
356
355
|
| BytesToNumberErrorType
|
|
357
356
|
| BytesToStringErrorType
|
|
358
|
-
| TrimErrorType
|
|
359
357
|
| ErrorType
|
|
360
358
|
|
|
361
359
|
function decodeString(
|
|
@@ -378,7 +376,7 @@ function decodeString(
|
|
|
378
376
|
}
|
|
379
377
|
|
|
380
378
|
const data = cursor.readBytes(length, 32)
|
|
381
|
-
const value = bytesToString(
|
|
379
|
+
const value = bytesToString(data)
|
|
382
380
|
|
|
383
381
|
// As we have gone wondering, restore to the original position + next slot.
|
|
384
382
|
cursor.setPosition(staticPosition + 32)
|