viem 2.50.3 → 2.51.0
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 +28 -0
- package/_cjs/actions/index.js +5 -3
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/public/createAccessList.js +3 -0
- package/_cjs/actions/public/createAccessList.js.map +1 -1
- package/_cjs/actions/public/getBlockReceipts.js +19 -0
- package/_cjs/actions/public/getBlockReceipts.js.map +1 -0
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/chains/definitions/somnia.js +7 -0
- package/_cjs/chains/definitions/somnia.js.map +1 -1
- package/_cjs/chains/definitions/somniaTestnet.js +3 -2
- package/_cjs/chains/definitions/somniaTestnet.js.map +1 -1
- package/_cjs/clients/decorators/public.js +2 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/op-stack/actions/buildProveWithdrawal.js +10 -2
- package/_cjs/op-stack/actions/buildProveWithdrawal.js.map +1 -1
- package/_cjs/op-stack/actions/getGame.js.map +1 -1
- package/_cjs/op-stack/actions/getGames.js +3 -1
- package/_cjs/op-stack/actions/getGames.js.map +1 -1
- package/_cjs/op-stack/actions/getTimeToProve.js +3 -3
- package/_cjs/op-stack/actions/getTimeToProve.js.map +1 -1
- package/_cjs/op-stack/actions/getWithdrawalStatus.js +1 -1
- package/_cjs/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_cjs/op-stack/actions/waitToProve.js +4 -3
- package/_cjs/op-stack/actions/waitToProve.js.map +1 -1
- package/_cjs/op-stack/gameTypes.js +9 -0
- package/_cjs/op-stack/gameTypes.js.map +1 -0
- package/_cjs/op-stack/index.js +7 -1
- package/_cjs/op-stack/index.js.map +1 -1
- package/_cjs/op-stack/utils/getL2BlockNumberAtTimestamp.js +29 -0
- package/_cjs/op-stack/utils/getL2BlockNumberAtTimestamp.js.map +1 -0
- package/_cjs/tempo/Abis.js +477 -11
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Account.js +27 -1
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Decorator.js +17 -0
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/Transaction.js +10 -2
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/actions/channel.js +377 -0
- package/_cjs/tempo/actions/channel.js.map +1 -0
- package/_cjs/tempo/actions/index.js +2 -1
- package/_cjs/tempo/actions/index.js.map +1 -1
- package/_cjs/tempo/actions/token.js +57 -27
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/index.js +2 -1
- package/_cjs/tempo/index.js.map +1 -1
- package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/_cjs/utils/index.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/public/createAccessList.js +3 -0
- package/_esm/actions/public/createAccessList.js.map +1 -1
- package/_esm/actions/public/getBlockReceipts.js +39 -0
- package/_esm/actions/public/getBlockReceipts.js.map +1 -0
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/chains/definitions/somnia.js +7 -0
- package/_esm/chains/definitions/somnia.js.map +1 -1
- package/_esm/chains/definitions/somniaTestnet.js +3 -2
- package/_esm/chains/definitions/somniaTestnet.js.map +1 -1
- package/_esm/clients/decorators/public.js +2 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/op-stack/actions/buildProveWithdrawal.js +10 -2
- package/_esm/op-stack/actions/buildProveWithdrawal.js.map +1 -1
- package/_esm/op-stack/actions/getGame.js.map +1 -1
- package/_esm/op-stack/actions/getGames.js +3 -1
- package/_esm/op-stack/actions/getGames.js.map +1 -1
- package/_esm/op-stack/actions/getTimeToProve.js +3 -3
- package/_esm/op-stack/actions/getTimeToProve.js.map +1 -1
- package/_esm/op-stack/actions/getWithdrawalStatus.js +1 -1
- package/_esm/op-stack/actions/getWithdrawalStatus.js.map +1 -1
- package/_esm/op-stack/actions/waitToProve.js +4 -3
- package/_esm/op-stack/actions/waitToProve.js.map +1 -1
- package/_esm/op-stack/gameTypes.js +9 -0
- package/_esm/op-stack/gameTypes.js.map +1 -0
- package/_esm/op-stack/index.js +2 -0
- package/_esm/op-stack/index.js.map +1 -1
- package/_esm/op-stack/utils/getL2BlockNumberAtTimestamp.js +33 -0
- package/_esm/op-stack/utils/getL2BlockNumberAtTimestamp.js.map +1 -0
- package/_esm/tempo/Abis.js +476 -10
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Account.js +27 -2
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Decorator.js +17 -0
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/Transaction.js +16 -11
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/actions/channel.js +736 -0
- package/_esm/tempo/actions/channel.js.map +1 -0
- package/_esm/tempo/actions/index.js +1 -0
- package/_esm/tempo/actions/index.js.map +1 -1
- package/_esm/tempo/actions/token.js +61 -28
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/index.js +1 -1
- package/_esm/tempo/index.js.map +1 -1
- package/_esm/utils/formatters/transactionRequest.js.map +1 -1
- package/_esm/utils/index.js.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/public/createAccessList.d.ts +2 -1
- package/_types/actions/public/createAccessList.d.ts.map +1 -1
- package/_types/actions/public/getBlockReceipts.d.ts +53 -0
- package/_types/actions/public/getBlockReceipts.d.ts.map +1 -0
- package/_types/actions/wallet/prepareTransactionRequest.d.ts +4 -5
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/chains/definitions/somnia.d.ts +7 -10
- package/_types/chains/definitions/somnia.d.ts.map +1 -1
- package/_types/chains/definitions/somniaTestnet.d.ts +3 -3
- package/_types/chains/definitions/somniaTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/tempo.d.ts +8 -8
- package/_types/chains/definitions/tempoDevnet.d.ts +8 -8
- package/_types/chains/definitions/tempoLocalnet.d.ts +8 -8
- package/_types/chains/definitions/tempoModerato.d.ts +8 -8
- package/_types/chains/index.d.ts +44 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +23 -0
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +2 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/op-stack/actions/buildProveWithdrawal.d.ts +2 -1
- package/_types/op-stack/actions/buildProveWithdrawal.d.ts.map +1 -1
- package/_types/op-stack/actions/getGame.d.ts +7 -0
- package/_types/op-stack/actions/getGame.d.ts.map +1 -1
- package/_types/op-stack/actions/getGames.d.ts +7 -0
- package/_types/op-stack/actions/getGames.d.ts.map +1 -1
- package/_types/op-stack/actions/getTimeToProve.d.ts +4 -0
- package/_types/op-stack/actions/getTimeToProve.d.ts.map +1 -1
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts +4 -0
- package/_types/op-stack/actions/getWithdrawalStatus.d.ts.map +1 -1
- package/_types/op-stack/actions/waitToProve.d.ts +4 -0
- package/_types/op-stack/actions/waitToProve.d.ts.map +1 -1
- package/_types/op-stack/gameTypes.d.ts +7 -0
- package/_types/op-stack/gameTypes.d.ts.map +1 -0
- package/_types/op-stack/index.d.ts +2 -0
- package/_types/op-stack/index.d.ts.map +1 -1
- package/_types/op-stack/utils/getL2BlockNumberAtTimestamp.d.ts +21 -0
- package/_types/op-stack/utils/getL2BlockNumberAtTimestamp.d.ts.map +1 -0
- package/_types/tempo/Abis.d.ts +3784 -2271
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +32 -1
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +246 -1
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +339 -0
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/channel.d.ts +4390 -0
- package/_types/tempo/actions/channel.d.ts.map +1 -0
- package/_types/tempo/actions/dex.d.ts +140 -0
- package/_types/tempo/actions/dex.d.ts.map +1 -1
- package/_types/tempo/actions/fee.d.ts +0 -48
- package/_types/tempo/actions/fee.d.ts.map +1 -1
- package/_types/tempo/actions/index.d.ts +1 -0
- package/_types/tempo/actions/index.d.ts.map +1 -1
- package/_types/tempo/actions/reward.d.ts +74 -18
- package/_types/tempo/actions/reward.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts +629 -141
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/actions/virtualAddress.d.ts +11 -0
- package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
- package/_types/tempo/index.d.ts +1 -1
- package/_types/tempo/index.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +13 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/utils/formatters/transactionRequest.d.ts +6 -1
- package/_types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/_types/utils/index.d.ts +1 -1
- package/_types/utils/index.d.ts.map +1 -1
- package/actions/index.ts +6 -0
- package/actions/public/createAccessList.ts +4 -0
- package/actions/public/getBlockReceipts.ts +101 -0
- package/actions/wallet/prepareTransactionRequest.ts +7 -10
- package/chains/definitions/somnia.ts +7 -0
- package/chains/definitions/somniaTestnet.ts +3 -2
- package/chains/index.ts +50 -0
- package/clients/decorators/public.ts +30 -0
- package/errors/version.ts +1 -1
- package/index.ts +6 -0
- package/op-stack/actions/buildProveWithdrawal.ts +17 -2
- package/op-stack/actions/getGame.ts +7 -0
- package/op-stack/actions/getGames.ts +10 -1
- package/op-stack/actions/getTimeToProve.ts +7 -3
- package/op-stack/actions/getWithdrawalStatus.ts +6 -1
- package/op-stack/actions/waitToProve.ts +8 -3
- package/op-stack/gameTypes.ts +9 -0
- package/op-stack/index.ts +7 -1
- package/op-stack/utils/getL2BlockNumberAtTimestamp.ts +57 -0
- package/package.json +2 -2
- package/tempo/Abis.ts +477 -10
- package/tempo/Account.ts +67 -2
- package/tempo/Decorator.ts +299 -1
- package/tempo/Transaction.ts +18 -11
- package/tempo/actions/channel.ts +1197 -0
- package/tempo/actions/index.ts +1 -0
- package/tempo/actions/token.ts +85 -26
- package/tempo/index.ts +1 -0
- package/types/eip1193.ts +13 -0
- package/utils/formatters/transactionRequest.ts +13 -1
- package/utils/index.ts +1 -0
|
@@ -0,0 +1,1197 @@
|
|
|
1
|
+
import * as Address from 'ox/Address'
|
|
2
|
+
import * as Hex from 'ox/Hex'
|
|
3
|
+
import { Channel as ox_Channel, TokenId } from 'ox/tempo'
|
|
4
|
+
import type { Account } from '../../accounts/types.js'
|
|
5
|
+
import { parseAccount } from '../../accounts/utils/parseAccount.js'
|
|
6
|
+
import type { ReadContractReturnType } from '../../actions/public/readContract.js'
|
|
7
|
+
import { readContract } from '../../actions/public/readContract.js'
|
|
8
|
+
import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
|
|
9
|
+
import { writeContract } from '../../actions/wallet/writeContract.js'
|
|
10
|
+
import { writeContractSync } from '../../actions/wallet/writeContractSync.js'
|
|
11
|
+
import type { Client } from '../../clients/createClient.js'
|
|
12
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
13
|
+
import { zeroAddress } from '../../constants/address.js'
|
|
14
|
+
import type { BaseErrorType } from '../../errors/base.js'
|
|
15
|
+
import type { Chain } from '../../types/chain.js'
|
|
16
|
+
import type { GetEventArgs } from '../../types/contract.js'
|
|
17
|
+
import type { Log } from '../../types/log.js'
|
|
18
|
+
import type { Compute } from '../../types/utils.js'
|
|
19
|
+
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
20
|
+
import * as Abis from '../Abis.js'
|
|
21
|
+
import { signVoucher as signVoucher_ } from '../Account.js'
|
|
22
|
+
import type {
|
|
23
|
+
GetAccountParameter,
|
|
24
|
+
ReadParameters,
|
|
25
|
+
WriteParameters,
|
|
26
|
+
} from '../internal/types.js'
|
|
27
|
+
import { defineCall } from '../internal/utils.js'
|
|
28
|
+
import type { TransactionReceipt } from '../Transaction.js'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Closes a TIP-20 channel reserve channel from the payee or operator side.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { Actions } from 'viem/tempo'
|
|
36
|
+
*
|
|
37
|
+
* const hash = await Actions.channel.close(client, {
|
|
38
|
+
* captureAmount: 100n,
|
|
39
|
+
* cumulativeAmount: 100n,
|
|
40
|
+
* channel,
|
|
41
|
+
* signature: '0x...',
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param client - Client.
|
|
46
|
+
* @param parameters - Parameters.
|
|
47
|
+
* @returns The transaction hash.
|
|
48
|
+
*/
|
|
49
|
+
export async function close<
|
|
50
|
+
chain extends Chain | undefined,
|
|
51
|
+
account extends Account | undefined,
|
|
52
|
+
>(
|
|
53
|
+
client: Client<Transport, chain, account>,
|
|
54
|
+
parameters: close.Parameters<chain, account>,
|
|
55
|
+
): Promise<close.ReturnValue> {
|
|
56
|
+
return close.inner(writeContract, client, parameters)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export namespace close {
|
|
60
|
+
export type Parameters<
|
|
61
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
62
|
+
account extends Account | undefined = Account | undefined,
|
|
63
|
+
> = WriteParameters<chain, account> & Args
|
|
64
|
+
|
|
65
|
+
export type Args = {
|
|
66
|
+
/** Amount to capture for the payee during close. */
|
|
67
|
+
captureAmount: bigint
|
|
68
|
+
/** Total voucher amount signed for the channel. */
|
|
69
|
+
cumulativeAmount: bigint
|
|
70
|
+
/** TIP-20 channel. */
|
|
71
|
+
channel: ox_Channel.from.Value
|
|
72
|
+
/** Voucher signature. */
|
|
73
|
+
signature: Hex.Hex
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export type ReturnValue = WriteContractReturnType
|
|
77
|
+
|
|
78
|
+
// TODO: exhaustive error type
|
|
79
|
+
export type ErrorType = BaseErrorType
|
|
80
|
+
|
|
81
|
+
/** @internal */
|
|
82
|
+
export async function inner<
|
|
83
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
84
|
+
chain extends Chain | undefined,
|
|
85
|
+
account extends Account | undefined,
|
|
86
|
+
>(
|
|
87
|
+
action: action,
|
|
88
|
+
client: Client<Transport, chain, account>,
|
|
89
|
+
parameters: Parameters<chain, account>,
|
|
90
|
+
): Promise<ReturnType<action>> {
|
|
91
|
+
const { captureAmount, cumulativeAmount, channel, signature, ...rest } =
|
|
92
|
+
parameters
|
|
93
|
+
return (await action(client, {
|
|
94
|
+
...rest,
|
|
95
|
+
...close.call({
|
|
96
|
+
captureAmount,
|
|
97
|
+
cumulativeAmount,
|
|
98
|
+
channel,
|
|
99
|
+
signature,
|
|
100
|
+
}),
|
|
101
|
+
} as never)) as never
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Defines a call to the `close` function.
|
|
106
|
+
*
|
|
107
|
+
* @param args - Arguments.
|
|
108
|
+
* @returns The call.
|
|
109
|
+
*/
|
|
110
|
+
export function call(args: Args) {
|
|
111
|
+
const { captureAmount, cumulativeAmount, channel, signature } = args
|
|
112
|
+
return defineCall({
|
|
113
|
+
address: ox_Channel.address,
|
|
114
|
+
abi: Abis.tip20ChannelReserve,
|
|
115
|
+
functionName: 'close',
|
|
116
|
+
args: [
|
|
117
|
+
ox_Channel.from(channel),
|
|
118
|
+
cumulativeAmount,
|
|
119
|
+
captureAmount,
|
|
120
|
+
signature,
|
|
121
|
+
],
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Extracts the `ChannelClosed` event from logs.
|
|
127
|
+
*
|
|
128
|
+
* @param logs - The logs.
|
|
129
|
+
* @returns The `ChannelClosed` event.
|
|
130
|
+
*/
|
|
131
|
+
export function extractEvent(logs: Log[]) {
|
|
132
|
+
const [log] = parseEventLogs({
|
|
133
|
+
abi: Abis.tip20ChannelReserve,
|
|
134
|
+
logs,
|
|
135
|
+
eventName: 'ChannelClosed',
|
|
136
|
+
strict: true,
|
|
137
|
+
})
|
|
138
|
+
if (!log) throw new Error('`ChannelClosed` event not found.')
|
|
139
|
+
return log
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Closes a TIP-20 channel reserve channel and waits for the transaction receipt.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { Actions } from 'viem/tempo'
|
|
149
|
+
*
|
|
150
|
+
* const result = await Actions.channel.closeSync(client, {
|
|
151
|
+
* captureAmount: 100n,
|
|
152
|
+
* cumulativeAmount: 100n,
|
|
153
|
+
* channel,
|
|
154
|
+
* signature: '0x...',
|
|
155
|
+
* })
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @param client - Client.
|
|
159
|
+
* @param parameters - Parameters.
|
|
160
|
+
* @returns The transaction receipt and event data.
|
|
161
|
+
*/
|
|
162
|
+
export async function closeSync<
|
|
163
|
+
chain extends Chain | undefined,
|
|
164
|
+
account extends Account | undefined,
|
|
165
|
+
>(
|
|
166
|
+
client: Client<Transport, chain, account>,
|
|
167
|
+
parameters: closeSync.Parameters<chain, account>,
|
|
168
|
+
): Promise<closeSync.ReturnValue> {
|
|
169
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
170
|
+
const receipt = await close.inner(writeContractSync, client, {
|
|
171
|
+
...rest,
|
|
172
|
+
throwOnReceiptRevert,
|
|
173
|
+
} as never)
|
|
174
|
+
const { args } = close.extractEvent(receipt.logs)
|
|
175
|
+
return { ...args, receipt } as never
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export namespace closeSync {
|
|
179
|
+
export type Parameters<
|
|
180
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
181
|
+
account extends Account | undefined = Account | undefined,
|
|
182
|
+
> = close.Parameters<chain, account>
|
|
183
|
+
|
|
184
|
+
export type Args = close.Args
|
|
185
|
+
|
|
186
|
+
export type ReturnValue = Compute<
|
|
187
|
+
GetEventArgs<
|
|
188
|
+
typeof Abis.tip20ChannelReserve,
|
|
189
|
+
'ChannelClosed',
|
|
190
|
+
{ IndexedOnly: false; Required: true }
|
|
191
|
+
> & {
|
|
192
|
+
/** Transaction receipt. */
|
|
193
|
+
receipt: TransactionReceipt
|
|
194
|
+
}
|
|
195
|
+
>
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Gets TIP-20 channel reserve state for a channel ID or channel.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { createClient, http } from 'viem'
|
|
204
|
+
* import { tempo } from 'viem/chains'
|
|
205
|
+
* import { Actions } from 'viem/tempo'
|
|
206
|
+
*
|
|
207
|
+
* const client = createClient({
|
|
208
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
209
|
+
* transport: http(),
|
|
210
|
+
* })
|
|
211
|
+
*
|
|
212
|
+
* const state = await Actions.channel.getStates(client, {
|
|
213
|
+
* channel: '0x...',
|
|
214
|
+
* })
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
* @param client - Client.
|
|
218
|
+
* @param parameters - Parameters.
|
|
219
|
+
* @returns Channel state for a single channel, or channel states for multiple channels.
|
|
220
|
+
*/
|
|
221
|
+
export async function getStates<
|
|
222
|
+
chain extends Chain | undefined,
|
|
223
|
+
const channel extends getStates.Channel | readonly getStates.Channel[],
|
|
224
|
+
>(
|
|
225
|
+
client: Client<Transport, chain>,
|
|
226
|
+
parameters: getStates.Parameters<channel>,
|
|
227
|
+
): Promise<getStates.ReturnValue<channel>> {
|
|
228
|
+
const chainId = client.chain?.id
|
|
229
|
+
const { channel, ...rest } = parameters
|
|
230
|
+
|
|
231
|
+
return readContract(client, {
|
|
232
|
+
...rest,
|
|
233
|
+
...getStates.call({ channel, chainId } as never),
|
|
234
|
+
} as never) as never
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export namespace getStates {
|
|
238
|
+
export type Parameters<
|
|
239
|
+
channel extends Channel | readonly Channel[] = Channel | readonly Channel[],
|
|
240
|
+
> = ReadParameters & {
|
|
241
|
+
/** Channel ID, channel, or list of IDs and channels. */
|
|
242
|
+
channel: channel
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export type Args<
|
|
246
|
+
channel extends Channel | readonly Channel[] = Channel | readonly Channel[],
|
|
247
|
+
> = {
|
|
248
|
+
/**
|
|
249
|
+
* Chain ID used to compute IDs for channel inputs.
|
|
250
|
+
*
|
|
251
|
+
* Required for channel inputs when using `getStates.call` directly.
|
|
252
|
+
*/
|
|
253
|
+
chainId?: number | undefined
|
|
254
|
+
/** Channel ID, channel, or list of IDs and channels. */
|
|
255
|
+
channel: channel
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export type Channel = Hex.Hex | ox_Channel.from.Value
|
|
259
|
+
|
|
260
|
+
export type State = ReadContractReturnType<
|
|
261
|
+
typeof Abis.tip20ChannelReserve,
|
|
262
|
+
'getChannelState',
|
|
263
|
+
readonly [Hex.Hex]
|
|
264
|
+
>
|
|
265
|
+
|
|
266
|
+
export type ReturnValue<channel extends Channel | readonly Channel[]> =
|
|
267
|
+
channel extends readonly Channel[] ? readonly State[] : State
|
|
268
|
+
|
|
269
|
+
// TODO: exhaustive error type
|
|
270
|
+
export type ErrorType = BaseErrorType
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Defines a call to the `getChannelState` or `getChannelStatesBatch` function.
|
|
274
|
+
*
|
|
275
|
+
* Can be passed as a parameter to:
|
|
276
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
277
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
278
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
283
|
+
* import { tempo } from 'viem/chains'
|
|
284
|
+
* import { Actions } from 'viem/tempo'
|
|
285
|
+
*
|
|
286
|
+
* const client = createClient({
|
|
287
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
288
|
+
* transport: http(),
|
|
289
|
+
* }).extend(walletActions)
|
|
290
|
+
*
|
|
291
|
+
* const calls = [Actions.channel.getStates.call({ channel: '0x...' })]
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @param args - Arguments.
|
|
295
|
+
* @returns The call.
|
|
296
|
+
*/
|
|
297
|
+
export function call<const channel extends Channel | readonly Channel[]>(
|
|
298
|
+
args: Args<channel>,
|
|
299
|
+
) {
|
|
300
|
+
const { channel, chainId } = args
|
|
301
|
+
if (Array.isArray(channel)) {
|
|
302
|
+
const channelIds = (channel as readonly Channel[]).map((channel) => {
|
|
303
|
+
if (typeof channel === 'string') return channel
|
|
304
|
+
if (chainId === undefined)
|
|
305
|
+
throw new Error('`chainId` is required for channel inputs.')
|
|
306
|
+
return ox_Channel.computeId(channel, { chainId }) as Hex.Hex
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
return defineCall({
|
|
310
|
+
address: ox_Channel.address,
|
|
311
|
+
abi: Abis.tip20ChannelReserve,
|
|
312
|
+
args: [channelIds],
|
|
313
|
+
functionName: 'getChannelStatesBatch',
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const channel_ = channel as Channel
|
|
318
|
+
if (typeof channel_ === 'string')
|
|
319
|
+
return defineCall({
|
|
320
|
+
address: ox_Channel.address,
|
|
321
|
+
abi: Abis.tip20ChannelReserve,
|
|
322
|
+
args: [channel_],
|
|
323
|
+
functionName: 'getChannelState',
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
if (chainId === undefined)
|
|
327
|
+
throw new Error('`chainId` is required for channel inputs.')
|
|
328
|
+
|
|
329
|
+
return defineCall({
|
|
330
|
+
address: ox_Channel.address,
|
|
331
|
+
abi: Abis.tip20ChannelReserve,
|
|
332
|
+
args: [ox_Channel.computeId(channel_, { chainId }) as Hex.Hex],
|
|
333
|
+
functionName: 'getChannelState',
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Opens and funds a TIP-20 channel reserve channel.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* import { createClient, http } from 'viem'
|
|
344
|
+
* import { tempo } from 'viem/chains'
|
|
345
|
+
* import { Actions } from 'viem/tempo'
|
|
346
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
347
|
+
*
|
|
348
|
+
* const client = createClient({
|
|
349
|
+
* account: privateKeyToAccount('0x...'),
|
|
350
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
351
|
+
* transport: http(),
|
|
352
|
+
* })
|
|
353
|
+
*
|
|
354
|
+
* const hash = await Actions.channel.open(client, {
|
|
355
|
+
* deposit: 100n,
|
|
356
|
+
* payee: '0x...',
|
|
357
|
+
* token: 1n,
|
|
358
|
+
* })
|
|
359
|
+
* ```
|
|
360
|
+
*
|
|
361
|
+
* @param client - Client.
|
|
362
|
+
* @param parameters - Parameters.
|
|
363
|
+
* @returns The transaction hash.
|
|
364
|
+
*/
|
|
365
|
+
export async function open<
|
|
366
|
+
chain extends Chain | undefined,
|
|
367
|
+
account extends Account | undefined,
|
|
368
|
+
>(
|
|
369
|
+
client: Client<Transport, chain, account>,
|
|
370
|
+
parameters: open.Parameters<chain, account>,
|
|
371
|
+
): Promise<open.ReturnValue> {
|
|
372
|
+
return open.inner(writeContract, client, parameters)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export namespace open {
|
|
376
|
+
export type Parameters<
|
|
377
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
378
|
+
account extends Account | undefined = Account | undefined,
|
|
379
|
+
> = WriteParameters<chain, account> & Args
|
|
380
|
+
|
|
381
|
+
export type Args = {
|
|
382
|
+
/** Optional signer for vouchers. Zero means `payer` signs. @default zeroAddress */
|
|
383
|
+
authorizedSigner?: Address.Address | undefined
|
|
384
|
+
/** Amount of TIP-20 token to deposit. */
|
|
385
|
+
deposit: bigint
|
|
386
|
+
/** Optional relayer allowed to submit `settle` for the payee. @default zeroAddress */
|
|
387
|
+
operator?: Address.Address | undefined
|
|
388
|
+
/** Account that receives settled voucher payments. */
|
|
389
|
+
payee: Address.Address
|
|
390
|
+
/** User-supplied salt to distinguish otherwise identical channels. @default Hex.random(32) */
|
|
391
|
+
salt?: Hex.Hex | undefined
|
|
392
|
+
/** TIP-20 token address or ID held by the channel. */
|
|
393
|
+
token: TokenId.TokenIdOrAddress<Address.Address>
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export type ReturnValue = WriteContractReturnType
|
|
397
|
+
|
|
398
|
+
// TODO: exhaustive error type
|
|
399
|
+
export type ErrorType = BaseErrorType
|
|
400
|
+
|
|
401
|
+
/** @internal */
|
|
402
|
+
export async function inner<
|
|
403
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
404
|
+
chain extends Chain | undefined,
|
|
405
|
+
account extends Account | undefined,
|
|
406
|
+
>(
|
|
407
|
+
action: action,
|
|
408
|
+
client: Client<Transport, chain, account>,
|
|
409
|
+
parameters: Parameters<chain, account>,
|
|
410
|
+
): Promise<ReturnType<action>> {
|
|
411
|
+
const { authorizedSigner, deposit, operator, payee, salt, token, ...rest } =
|
|
412
|
+
parameters
|
|
413
|
+
return (await action(client, {
|
|
414
|
+
...rest,
|
|
415
|
+
...open.call({
|
|
416
|
+
authorizedSigner,
|
|
417
|
+
deposit,
|
|
418
|
+
operator,
|
|
419
|
+
payee,
|
|
420
|
+
salt,
|
|
421
|
+
token,
|
|
422
|
+
}),
|
|
423
|
+
} as never)) as never
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Defines a call to the `open` function.
|
|
428
|
+
*
|
|
429
|
+
* @param args - Arguments.
|
|
430
|
+
* @returns The call.
|
|
431
|
+
*/
|
|
432
|
+
export function call(args: Args) {
|
|
433
|
+
const {
|
|
434
|
+
authorizedSigner = zeroAddress,
|
|
435
|
+
deposit,
|
|
436
|
+
operator = zeroAddress,
|
|
437
|
+
payee,
|
|
438
|
+
salt = Hex.random(32),
|
|
439
|
+
token,
|
|
440
|
+
} = args
|
|
441
|
+
return defineCall({
|
|
442
|
+
address: ox_Channel.address,
|
|
443
|
+
abi: Abis.tip20ChannelReserve,
|
|
444
|
+
functionName: 'open',
|
|
445
|
+
args: [
|
|
446
|
+
Address.from(payee),
|
|
447
|
+
Address.from(operator),
|
|
448
|
+
TokenId.toAddress(token),
|
|
449
|
+
deposit,
|
|
450
|
+
salt,
|
|
451
|
+
Address.from(authorizedSigner),
|
|
452
|
+
],
|
|
453
|
+
})
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Extracts the `ChannelOpened` event from logs.
|
|
458
|
+
*
|
|
459
|
+
* @param logs - The logs.
|
|
460
|
+
* @returns The `ChannelOpened` event.
|
|
461
|
+
*/
|
|
462
|
+
export function extractEvent(logs: Log[]) {
|
|
463
|
+
const [log] = parseEventLogs({
|
|
464
|
+
abi: Abis.tip20ChannelReserve,
|
|
465
|
+
logs,
|
|
466
|
+
eventName: 'ChannelOpened',
|
|
467
|
+
strict: true,
|
|
468
|
+
})
|
|
469
|
+
if (!log) throw new Error('`ChannelOpened` event not found.')
|
|
470
|
+
return log
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Opens and funds a TIP-20 channel reserve channel and waits for the
|
|
476
|
+
* transaction receipt.
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```ts
|
|
480
|
+
* import { createClient, http } from 'viem'
|
|
481
|
+
* import { tempo } from 'viem/chains'
|
|
482
|
+
* import { Actions } from 'viem/tempo'
|
|
483
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
484
|
+
*
|
|
485
|
+
* const client = createClient({
|
|
486
|
+
* account: privateKeyToAccount('0x...'),
|
|
487
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
488
|
+
* transport: http(),
|
|
489
|
+
* })
|
|
490
|
+
*
|
|
491
|
+
* const result = await Actions.channel.openSync(client, {
|
|
492
|
+
* deposit: 100n,
|
|
493
|
+
* payee: '0x...',
|
|
494
|
+
* token: 1n,
|
|
495
|
+
* })
|
|
496
|
+
* ```
|
|
497
|
+
*
|
|
498
|
+
* @param client - Client.
|
|
499
|
+
* @param parameters - Parameters.
|
|
500
|
+
* @returns The transaction receipt and event data.
|
|
501
|
+
*/
|
|
502
|
+
export async function openSync<
|
|
503
|
+
chain extends Chain | undefined,
|
|
504
|
+
account extends Account | undefined,
|
|
505
|
+
>(
|
|
506
|
+
client: Client<Transport, chain, account>,
|
|
507
|
+
parameters: openSync.Parameters<chain, account>,
|
|
508
|
+
): Promise<openSync.ReturnValue> {
|
|
509
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
510
|
+
const receipt = await open.inner(writeContractSync, client, {
|
|
511
|
+
...rest,
|
|
512
|
+
throwOnReceiptRevert,
|
|
513
|
+
} as never)
|
|
514
|
+
const { args } = open.extractEvent(receipt.logs)
|
|
515
|
+
return { ...args, receipt } as never
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
export namespace openSync {
|
|
519
|
+
export type Parameters<
|
|
520
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
521
|
+
account extends Account | undefined = Account | undefined,
|
|
522
|
+
> = open.Parameters<chain, account>
|
|
523
|
+
|
|
524
|
+
export type Args = open.Args
|
|
525
|
+
|
|
526
|
+
export type ReturnValue = Compute<
|
|
527
|
+
GetEventArgs<
|
|
528
|
+
typeof Abis.tip20ChannelReserve,
|
|
529
|
+
'ChannelOpened',
|
|
530
|
+
{ IndexedOnly: false; Required: true }
|
|
531
|
+
> & {
|
|
532
|
+
/** Transaction receipt. */
|
|
533
|
+
receipt: TransactionReceipt
|
|
534
|
+
}
|
|
535
|
+
>
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Starts the payer close timer for a TIP-20 channel reserve channel.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* import { Actions } from 'viem/tempo'
|
|
544
|
+
*
|
|
545
|
+
* const hash = await Actions.channel.requestClose(client, {
|
|
546
|
+
* channel,
|
|
547
|
+
* })
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* @param client - Client.
|
|
551
|
+
* @param parameters - Parameters.
|
|
552
|
+
* @returns The transaction hash.
|
|
553
|
+
*/
|
|
554
|
+
export async function requestClose<
|
|
555
|
+
chain extends Chain | undefined,
|
|
556
|
+
account extends Account | undefined,
|
|
557
|
+
>(
|
|
558
|
+
client: Client<Transport, chain, account>,
|
|
559
|
+
parameters: requestClose.Parameters<chain, account>,
|
|
560
|
+
): Promise<requestClose.ReturnValue> {
|
|
561
|
+
return requestClose.inner(writeContract, client, parameters)
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export namespace requestClose {
|
|
565
|
+
export type Parameters<
|
|
566
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
567
|
+
account extends Account | undefined = Account | undefined,
|
|
568
|
+
> = WriteParameters<chain, account> & Args
|
|
569
|
+
|
|
570
|
+
export type Args = {
|
|
571
|
+
/** TIP-20 channel. */
|
|
572
|
+
channel: ox_Channel.from.Value
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export type ReturnValue = WriteContractReturnType
|
|
576
|
+
|
|
577
|
+
// TODO: exhaustive error type
|
|
578
|
+
export type ErrorType = BaseErrorType
|
|
579
|
+
|
|
580
|
+
/** @internal */
|
|
581
|
+
export async function inner<
|
|
582
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
583
|
+
chain extends Chain | undefined,
|
|
584
|
+
account extends Account | undefined,
|
|
585
|
+
>(
|
|
586
|
+
action: action,
|
|
587
|
+
client: Client<Transport, chain, account>,
|
|
588
|
+
parameters: Parameters<chain, account>,
|
|
589
|
+
): Promise<ReturnType<action>> {
|
|
590
|
+
const { channel, ...rest } = parameters
|
|
591
|
+
return (await action(client, {
|
|
592
|
+
...rest,
|
|
593
|
+
...requestClose.call({ channel }),
|
|
594
|
+
} as never)) as never
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* Defines a call to the `requestClose` function.
|
|
599
|
+
*
|
|
600
|
+
* @param args - Arguments.
|
|
601
|
+
* @returns The call.
|
|
602
|
+
*/
|
|
603
|
+
export function call(args: Args) {
|
|
604
|
+
const { channel } = args
|
|
605
|
+
return defineCall({
|
|
606
|
+
address: ox_Channel.address,
|
|
607
|
+
abi: Abis.tip20ChannelReserve,
|
|
608
|
+
functionName: 'requestClose',
|
|
609
|
+
args: [ox_Channel.from(channel)],
|
|
610
|
+
})
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Extracts the `CloseRequested` event from logs.
|
|
615
|
+
*
|
|
616
|
+
* @param logs - The logs.
|
|
617
|
+
* @returns The `CloseRequested` event.
|
|
618
|
+
*/
|
|
619
|
+
export function extractEvent(logs: Log[]) {
|
|
620
|
+
const [log] = parseEventLogs({
|
|
621
|
+
abi: Abis.tip20ChannelReserve,
|
|
622
|
+
logs,
|
|
623
|
+
eventName: 'CloseRequested',
|
|
624
|
+
strict: true,
|
|
625
|
+
})
|
|
626
|
+
if (!log) throw new Error('`CloseRequested` event not found.')
|
|
627
|
+
return log
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Starts the payer close timer and waits for the transaction receipt.
|
|
633
|
+
*
|
|
634
|
+
* @example
|
|
635
|
+
* ```ts
|
|
636
|
+
* import { Actions } from 'viem/tempo'
|
|
637
|
+
*
|
|
638
|
+
* const result = await Actions.channel.requestCloseSync(client, {
|
|
639
|
+
* channel,
|
|
640
|
+
* })
|
|
641
|
+
* ```
|
|
642
|
+
*
|
|
643
|
+
* @param client - Client.
|
|
644
|
+
* @param parameters - Parameters.
|
|
645
|
+
* @returns The transaction receipt and event data.
|
|
646
|
+
*/
|
|
647
|
+
export async function requestCloseSync<
|
|
648
|
+
chain extends Chain | undefined,
|
|
649
|
+
account extends Account | undefined,
|
|
650
|
+
>(
|
|
651
|
+
client: Client<Transport, chain, account>,
|
|
652
|
+
parameters: requestCloseSync.Parameters<chain, account>,
|
|
653
|
+
): Promise<requestCloseSync.ReturnValue> {
|
|
654
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
655
|
+
const receipt = await requestClose.inner(writeContractSync, client, {
|
|
656
|
+
...rest,
|
|
657
|
+
throwOnReceiptRevert,
|
|
658
|
+
} as never)
|
|
659
|
+
const { args } = requestClose.extractEvent(receipt.logs)
|
|
660
|
+
return { ...args, receipt } as never
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export namespace requestCloseSync {
|
|
664
|
+
export type Parameters<
|
|
665
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
666
|
+
account extends Account | undefined = Account | undefined,
|
|
667
|
+
> = requestClose.Parameters<chain, account>
|
|
668
|
+
|
|
669
|
+
export type Args = requestClose.Args
|
|
670
|
+
|
|
671
|
+
export type ReturnValue = Compute<
|
|
672
|
+
GetEventArgs<
|
|
673
|
+
typeof Abis.tip20ChannelReserve,
|
|
674
|
+
'CloseRequested',
|
|
675
|
+
{ IndexedOnly: false; Required: true }
|
|
676
|
+
> & {
|
|
677
|
+
/** Transaction receipt. */
|
|
678
|
+
receipt: TransactionReceipt
|
|
679
|
+
}
|
|
680
|
+
>
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Settles a TIP-20 channel reserve voucher.
|
|
685
|
+
*
|
|
686
|
+
* @example
|
|
687
|
+
* ```ts
|
|
688
|
+
* import { createClient, http } from 'viem'
|
|
689
|
+
* import { tempo } from 'viem/chains'
|
|
690
|
+
* import { Actions } from 'viem/tempo'
|
|
691
|
+
*
|
|
692
|
+
* const hash = await Actions.channel.settle(client, {
|
|
693
|
+
* cumulativeAmount: 100n,
|
|
694
|
+
* channel,
|
|
695
|
+
* signature: '0x...',
|
|
696
|
+
* })
|
|
697
|
+
* ```
|
|
698
|
+
*
|
|
699
|
+
* @param client - Client.
|
|
700
|
+
* @param parameters - Parameters.
|
|
701
|
+
* @returns The transaction hash.
|
|
702
|
+
*/
|
|
703
|
+
export async function settle<
|
|
704
|
+
chain extends Chain | undefined,
|
|
705
|
+
account extends Account | undefined,
|
|
706
|
+
>(
|
|
707
|
+
client: Client<Transport, chain, account>,
|
|
708
|
+
parameters: settle.Parameters<chain, account>,
|
|
709
|
+
): Promise<settle.ReturnValue> {
|
|
710
|
+
return settle.inner(writeContract, client, parameters)
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
export namespace settle {
|
|
714
|
+
export type Parameters<
|
|
715
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
716
|
+
account extends Account | undefined = Account | undefined,
|
|
717
|
+
> = WriteParameters<chain, account> & Args
|
|
718
|
+
|
|
719
|
+
export type Args = {
|
|
720
|
+
/** Total voucher amount signed for the channel. */
|
|
721
|
+
cumulativeAmount: bigint
|
|
722
|
+
/** TIP-20 channel. */
|
|
723
|
+
channel: ox_Channel.from.Value
|
|
724
|
+
/** Voucher signature. */
|
|
725
|
+
signature: Hex.Hex
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
export type ReturnValue = WriteContractReturnType
|
|
729
|
+
|
|
730
|
+
// TODO: exhaustive error type
|
|
731
|
+
export type ErrorType = BaseErrorType
|
|
732
|
+
|
|
733
|
+
/** @internal */
|
|
734
|
+
export async function inner<
|
|
735
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
736
|
+
chain extends Chain | undefined,
|
|
737
|
+
account extends Account | undefined,
|
|
738
|
+
>(
|
|
739
|
+
action: action,
|
|
740
|
+
client: Client<Transport, chain, account>,
|
|
741
|
+
parameters: Parameters<chain, account>,
|
|
742
|
+
): Promise<ReturnType<action>> {
|
|
743
|
+
const { cumulativeAmount, channel, signature, ...rest } = parameters
|
|
744
|
+
return (await action(client, {
|
|
745
|
+
...rest,
|
|
746
|
+
...settle.call({ cumulativeAmount, channel, signature }),
|
|
747
|
+
} as never)) as never
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Defines a call to the `settle` function.
|
|
752
|
+
*
|
|
753
|
+
* @param args - Arguments.
|
|
754
|
+
* @returns The call.
|
|
755
|
+
*/
|
|
756
|
+
export function call(args: Args) {
|
|
757
|
+
const { cumulativeAmount, channel, signature } = args
|
|
758
|
+
return defineCall({
|
|
759
|
+
address: ox_Channel.address,
|
|
760
|
+
abi: Abis.tip20ChannelReserve,
|
|
761
|
+
functionName: 'settle',
|
|
762
|
+
args: [ox_Channel.from(channel), cumulativeAmount, signature],
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Extracts the `Settled` event from logs.
|
|
768
|
+
*
|
|
769
|
+
* @param logs - The logs.
|
|
770
|
+
* @returns The `Settled` event.
|
|
771
|
+
*/
|
|
772
|
+
export function extractEvent(logs: Log[]) {
|
|
773
|
+
const [log] = parseEventLogs({
|
|
774
|
+
abi: Abis.tip20ChannelReserve,
|
|
775
|
+
logs,
|
|
776
|
+
eventName: 'Settled',
|
|
777
|
+
strict: true,
|
|
778
|
+
})
|
|
779
|
+
if (!log) throw new Error('`Settled` event not found.')
|
|
780
|
+
return log
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* Settles a TIP-20 channel reserve voucher and waits for the transaction receipt.
|
|
786
|
+
*
|
|
787
|
+
* @example
|
|
788
|
+
* ```ts
|
|
789
|
+
* import { Actions } from 'viem/tempo'
|
|
790
|
+
*
|
|
791
|
+
* const result = await Actions.channel.settleSync(client, {
|
|
792
|
+
* cumulativeAmount: 100n,
|
|
793
|
+
* channel,
|
|
794
|
+
* signature: '0x...',
|
|
795
|
+
* })
|
|
796
|
+
* ```
|
|
797
|
+
*
|
|
798
|
+
* @param client - Client.
|
|
799
|
+
* @param parameters - Parameters.
|
|
800
|
+
* @returns The transaction receipt and event data.
|
|
801
|
+
*/
|
|
802
|
+
export async function settleSync<
|
|
803
|
+
chain extends Chain | undefined,
|
|
804
|
+
account extends Account | undefined,
|
|
805
|
+
>(
|
|
806
|
+
client: Client<Transport, chain, account>,
|
|
807
|
+
parameters: settleSync.Parameters<chain, account>,
|
|
808
|
+
): Promise<settleSync.ReturnValue> {
|
|
809
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
810
|
+
const receipt = await settle.inner(writeContractSync, client, {
|
|
811
|
+
...rest,
|
|
812
|
+
throwOnReceiptRevert,
|
|
813
|
+
} as never)
|
|
814
|
+
const { args } = settle.extractEvent(receipt.logs)
|
|
815
|
+
return { ...args, receipt } as never
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
export namespace settleSync {
|
|
819
|
+
export type Parameters<
|
|
820
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
821
|
+
account extends Account | undefined = Account | undefined,
|
|
822
|
+
> = settle.Parameters<chain, account>
|
|
823
|
+
|
|
824
|
+
export type Args = settle.Args
|
|
825
|
+
|
|
826
|
+
export type ReturnValue = Compute<
|
|
827
|
+
GetEventArgs<
|
|
828
|
+
typeof Abis.tip20ChannelReserve,
|
|
829
|
+
'Settled',
|
|
830
|
+
{ IndexedOnly: false; Required: true }
|
|
831
|
+
> & {
|
|
832
|
+
/** Transaction receipt. */
|
|
833
|
+
receipt: TransactionReceipt
|
|
834
|
+
}
|
|
835
|
+
>
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Signs a TIP-20 channel reserve voucher.
|
|
840
|
+
*
|
|
841
|
+
* @example
|
|
842
|
+
* ```ts
|
|
843
|
+
* import { parseUnits } from 'viem'
|
|
844
|
+
* import { Actions } from 'viem/tempo'
|
|
845
|
+
*
|
|
846
|
+
* const signature = await Actions.channel.signVoucher(client, {
|
|
847
|
+
* channel,
|
|
848
|
+
* cumulativeAmount: parseUnits('40', 6),
|
|
849
|
+
* })
|
|
850
|
+
* ```
|
|
851
|
+
*
|
|
852
|
+
* @param client - Client.
|
|
853
|
+
* @param parameters - Parameters.
|
|
854
|
+
* @returns The voucher signature.
|
|
855
|
+
*/
|
|
856
|
+
export async function signVoucher<
|
|
857
|
+
chain extends Chain | undefined,
|
|
858
|
+
account extends Account | undefined,
|
|
859
|
+
>(
|
|
860
|
+
client: Client<Transport, chain, account>,
|
|
861
|
+
parameters: signVoucher.Parameters<account>,
|
|
862
|
+
): Promise<signVoucher.ReturnValue> {
|
|
863
|
+
const {
|
|
864
|
+
account: account_ = client.account,
|
|
865
|
+
chainId = client.chain?.id,
|
|
866
|
+
channel,
|
|
867
|
+
cumulativeAmount,
|
|
868
|
+
} = parameters
|
|
869
|
+
if (!account_) throw new Error('account is required.')
|
|
870
|
+
if (chainId === undefined) throw new Error('chainId is required.')
|
|
871
|
+
|
|
872
|
+
const parsed = parseAccount(account_)
|
|
873
|
+
if (!('sign' in parsed) || !parsed.sign)
|
|
874
|
+
throw new Error('account.sign is required.')
|
|
875
|
+
|
|
876
|
+
return signVoucher_(parsed as never, {
|
|
877
|
+
chainId,
|
|
878
|
+
channel,
|
|
879
|
+
cumulativeAmount,
|
|
880
|
+
})
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export namespace signVoucher {
|
|
884
|
+
export type Parameters<
|
|
885
|
+
account extends Account | undefined = Account | undefined,
|
|
886
|
+
> = GetAccountParameter<account> & Args
|
|
887
|
+
|
|
888
|
+
export type Args = {
|
|
889
|
+
/** Channel ID or channel. */
|
|
890
|
+
channel: getStates.Channel
|
|
891
|
+
/** The chain ID. @default client.chain.id */
|
|
892
|
+
chainId?: number | bigint | undefined
|
|
893
|
+
/** Total voucher amount signed for the channel. */
|
|
894
|
+
cumulativeAmount: bigint
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
export type ReturnValue = Hex.Hex
|
|
898
|
+
|
|
899
|
+
// TODO: exhaustive error type
|
|
900
|
+
export type ErrorType = BaseErrorType
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/**
|
|
904
|
+
* Adds deposit to a TIP-20 channel reserve channel.
|
|
905
|
+
*
|
|
906
|
+
* @example
|
|
907
|
+
* ```ts
|
|
908
|
+
* import { Actions } from 'viem/tempo'
|
|
909
|
+
*
|
|
910
|
+
* const hash = await Actions.channel.topUp(client, {
|
|
911
|
+
* additionalDeposit: 100n,
|
|
912
|
+
* channel,
|
|
913
|
+
* })
|
|
914
|
+
* ```
|
|
915
|
+
*
|
|
916
|
+
* @param client - Client.
|
|
917
|
+
* @param parameters - Parameters.
|
|
918
|
+
* @returns The transaction hash.
|
|
919
|
+
*/
|
|
920
|
+
export async function topUp<
|
|
921
|
+
chain extends Chain | undefined,
|
|
922
|
+
account extends Account | undefined,
|
|
923
|
+
>(
|
|
924
|
+
client: Client<Transport, chain, account>,
|
|
925
|
+
parameters: topUp.Parameters<chain, account>,
|
|
926
|
+
): Promise<topUp.ReturnValue> {
|
|
927
|
+
return topUp.inner(writeContract, client, parameters)
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
export namespace topUp {
|
|
931
|
+
export type Parameters<
|
|
932
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
933
|
+
account extends Account | undefined = Account | undefined,
|
|
934
|
+
> = WriteParameters<chain, account> & Args
|
|
935
|
+
|
|
936
|
+
export type Args = {
|
|
937
|
+
/** Additional deposit to lock in the channel. */
|
|
938
|
+
additionalDeposit: bigint
|
|
939
|
+
/** TIP-20 channel. */
|
|
940
|
+
channel: ox_Channel.from.Value
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
export type ReturnValue = WriteContractReturnType
|
|
944
|
+
|
|
945
|
+
// TODO: exhaustive error type
|
|
946
|
+
export type ErrorType = BaseErrorType
|
|
947
|
+
|
|
948
|
+
/** @internal */
|
|
949
|
+
export async function inner<
|
|
950
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
951
|
+
chain extends Chain | undefined,
|
|
952
|
+
account extends Account | undefined,
|
|
953
|
+
>(
|
|
954
|
+
action: action,
|
|
955
|
+
client: Client<Transport, chain, account>,
|
|
956
|
+
parameters: Parameters<chain, account>,
|
|
957
|
+
): Promise<ReturnType<action>> {
|
|
958
|
+
const { additionalDeposit, channel, ...rest } = parameters
|
|
959
|
+
return (await action(client, {
|
|
960
|
+
...rest,
|
|
961
|
+
...topUp.call({ additionalDeposit, channel }),
|
|
962
|
+
} as never)) as never
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Defines a call to the `topUp` function.
|
|
967
|
+
*
|
|
968
|
+
* @param args - Arguments.
|
|
969
|
+
* @returns The call.
|
|
970
|
+
*/
|
|
971
|
+
export function call(args: Args) {
|
|
972
|
+
const { additionalDeposit, channel } = args
|
|
973
|
+
return defineCall({
|
|
974
|
+
address: ox_Channel.address,
|
|
975
|
+
abi: Abis.tip20ChannelReserve,
|
|
976
|
+
functionName: 'topUp',
|
|
977
|
+
args: [ox_Channel.from(channel), additionalDeposit],
|
|
978
|
+
})
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Extracts the `TopUp` event from logs.
|
|
983
|
+
*
|
|
984
|
+
* @param logs - The logs.
|
|
985
|
+
* @returns The `TopUp` event.
|
|
986
|
+
*/
|
|
987
|
+
export function extractEvent(logs: Log[]) {
|
|
988
|
+
const [log] = parseEventLogs({
|
|
989
|
+
abi: Abis.tip20ChannelReserve,
|
|
990
|
+
logs,
|
|
991
|
+
eventName: 'TopUp',
|
|
992
|
+
strict: true,
|
|
993
|
+
})
|
|
994
|
+
if (!log) throw new Error('`TopUp` event not found.')
|
|
995
|
+
return log
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Adds deposit to a TIP-20 channel reserve channel and waits for the
|
|
1001
|
+
* transaction receipt.
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```ts
|
|
1005
|
+
* import { Actions } from 'viem/tempo'
|
|
1006
|
+
*
|
|
1007
|
+
* const result = await Actions.channel.topUpSync(client, {
|
|
1008
|
+
* additionalDeposit: 100n,
|
|
1009
|
+
* channel,
|
|
1010
|
+
* })
|
|
1011
|
+
* ```
|
|
1012
|
+
*
|
|
1013
|
+
* @param client - Client.
|
|
1014
|
+
* @param parameters - Parameters.
|
|
1015
|
+
* @returns The transaction receipt and event data.
|
|
1016
|
+
*/
|
|
1017
|
+
export async function topUpSync<
|
|
1018
|
+
chain extends Chain | undefined,
|
|
1019
|
+
account extends Account | undefined,
|
|
1020
|
+
>(
|
|
1021
|
+
client: Client<Transport, chain, account>,
|
|
1022
|
+
parameters: topUpSync.Parameters<chain, account>,
|
|
1023
|
+
): Promise<topUpSync.ReturnValue> {
|
|
1024
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
1025
|
+
const receipt = await topUp.inner(writeContractSync, client, {
|
|
1026
|
+
...rest,
|
|
1027
|
+
throwOnReceiptRevert,
|
|
1028
|
+
} as never)
|
|
1029
|
+
const { args } = topUp.extractEvent(receipt.logs)
|
|
1030
|
+
return { ...args, receipt } as never
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
export namespace topUpSync {
|
|
1034
|
+
export type Parameters<
|
|
1035
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1036
|
+
account extends Account | undefined = Account | undefined,
|
|
1037
|
+
> = topUp.Parameters<chain, account>
|
|
1038
|
+
|
|
1039
|
+
export type Args = topUp.Args
|
|
1040
|
+
|
|
1041
|
+
export type ReturnValue = Compute<
|
|
1042
|
+
GetEventArgs<
|
|
1043
|
+
typeof Abis.tip20ChannelReserve,
|
|
1044
|
+
'TopUp',
|
|
1045
|
+
{ IndexedOnly: false; Required: true }
|
|
1046
|
+
> & {
|
|
1047
|
+
/** Transaction receipt. */
|
|
1048
|
+
receipt: TransactionReceipt
|
|
1049
|
+
}
|
|
1050
|
+
>
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Withdraws payer funds after the close grace period elapses.
|
|
1055
|
+
*
|
|
1056
|
+
* @example
|
|
1057
|
+
* ```ts
|
|
1058
|
+
* import { Actions } from 'viem/tempo'
|
|
1059
|
+
*
|
|
1060
|
+
* const hash = await Actions.channel.withdraw(client, {
|
|
1061
|
+
* channel,
|
|
1062
|
+
* })
|
|
1063
|
+
* ```
|
|
1064
|
+
*
|
|
1065
|
+
* @param client - Client.
|
|
1066
|
+
* @param parameters - Parameters.
|
|
1067
|
+
* @returns The transaction hash.
|
|
1068
|
+
*/
|
|
1069
|
+
export async function withdraw<
|
|
1070
|
+
chain extends Chain | undefined,
|
|
1071
|
+
account extends Account | undefined,
|
|
1072
|
+
>(
|
|
1073
|
+
client: Client<Transport, chain, account>,
|
|
1074
|
+
parameters: withdraw.Parameters<chain, account>,
|
|
1075
|
+
): Promise<withdraw.ReturnValue> {
|
|
1076
|
+
return withdraw.inner(writeContract, client, parameters)
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
export namespace withdraw {
|
|
1080
|
+
export type Parameters<
|
|
1081
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1082
|
+
account extends Account | undefined = Account | undefined,
|
|
1083
|
+
> = WriteParameters<chain, account> & Args
|
|
1084
|
+
|
|
1085
|
+
export type Args = {
|
|
1086
|
+
/** TIP-20 channel. */
|
|
1087
|
+
channel: ox_Channel.from.Value
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
export type ReturnValue = WriteContractReturnType
|
|
1091
|
+
|
|
1092
|
+
// TODO: exhaustive error type
|
|
1093
|
+
export type ErrorType = BaseErrorType
|
|
1094
|
+
|
|
1095
|
+
/** @internal */
|
|
1096
|
+
export async function inner<
|
|
1097
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
1098
|
+
chain extends Chain | undefined,
|
|
1099
|
+
account extends Account | undefined,
|
|
1100
|
+
>(
|
|
1101
|
+
action: action,
|
|
1102
|
+
client: Client<Transport, chain, account>,
|
|
1103
|
+
parameters: Parameters<chain, account>,
|
|
1104
|
+
): Promise<ReturnType<action>> {
|
|
1105
|
+
const { channel, ...rest } = parameters
|
|
1106
|
+
return (await action(client, {
|
|
1107
|
+
...rest,
|
|
1108
|
+
...withdraw.call({ channel }),
|
|
1109
|
+
} as never)) as never
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Defines a call to the `withdraw` function.
|
|
1114
|
+
*
|
|
1115
|
+
* @param args - Arguments.
|
|
1116
|
+
* @returns The call.
|
|
1117
|
+
*/
|
|
1118
|
+
export function call(args: Args) {
|
|
1119
|
+
const { channel } = args
|
|
1120
|
+
return defineCall({
|
|
1121
|
+
address: ox_Channel.address,
|
|
1122
|
+
abi: Abis.tip20ChannelReserve,
|
|
1123
|
+
functionName: 'withdraw',
|
|
1124
|
+
args: [ox_Channel.from(channel)],
|
|
1125
|
+
})
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* Extracts the `ChannelClosed` event from logs.
|
|
1130
|
+
*
|
|
1131
|
+
* @param logs - The logs.
|
|
1132
|
+
* @returns The `ChannelClosed` event.
|
|
1133
|
+
*/
|
|
1134
|
+
export function extractEvent(logs: Log[]) {
|
|
1135
|
+
const [log] = parseEventLogs({
|
|
1136
|
+
abi: Abis.tip20ChannelReserve,
|
|
1137
|
+
logs,
|
|
1138
|
+
eventName: 'ChannelClosed',
|
|
1139
|
+
strict: true,
|
|
1140
|
+
})
|
|
1141
|
+
if (!log) throw new Error('`ChannelClosed` event not found.')
|
|
1142
|
+
return log
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Withdraws payer funds after the close grace period elapses and waits for the
|
|
1148
|
+
* transaction receipt.
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```ts
|
|
1152
|
+
* import { Actions } from 'viem/tempo'
|
|
1153
|
+
*
|
|
1154
|
+
* const result = await Actions.channel.withdrawSync(client, {
|
|
1155
|
+
* channel,
|
|
1156
|
+
* })
|
|
1157
|
+
* ```
|
|
1158
|
+
*
|
|
1159
|
+
* @param client - Client.
|
|
1160
|
+
* @param parameters - Parameters.
|
|
1161
|
+
* @returns The transaction receipt and event data.
|
|
1162
|
+
*/
|
|
1163
|
+
export async function withdrawSync<
|
|
1164
|
+
chain extends Chain | undefined,
|
|
1165
|
+
account extends Account | undefined,
|
|
1166
|
+
>(
|
|
1167
|
+
client: Client<Transport, chain, account>,
|
|
1168
|
+
parameters: withdrawSync.Parameters<chain, account>,
|
|
1169
|
+
): Promise<withdrawSync.ReturnValue> {
|
|
1170
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters
|
|
1171
|
+
const receipt = await withdraw.inner(writeContractSync, client, {
|
|
1172
|
+
...rest,
|
|
1173
|
+
throwOnReceiptRevert,
|
|
1174
|
+
} as never)
|
|
1175
|
+
const { args } = withdraw.extractEvent(receipt.logs)
|
|
1176
|
+
return { ...args, receipt } as never
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
export namespace withdrawSync {
|
|
1180
|
+
export type Parameters<
|
|
1181
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
1182
|
+
account extends Account | undefined = Account | undefined,
|
|
1183
|
+
> = withdraw.Parameters<chain, account>
|
|
1184
|
+
|
|
1185
|
+
export type Args = withdraw.Args
|
|
1186
|
+
|
|
1187
|
+
export type ReturnValue = Compute<
|
|
1188
|
+
GetEventArgs<
|
|
1189
|
+
typeof Abis.tip20ChannelReserve,
|
|
1190
|
+
'ChannelClosed',
|
|
1191
|
+
{ IndexedOnly: false; Required: true }
|
|
1192
|
+
> & {
|
|
1193
|
+
/** Transaction receipt. */
|
|
1194
|
+
receipt: TransactionReceipt
|
|
1195
|
+
}
|
|
1196
|
+
>
|
|
1197
|
+
}
|