viem 2.50.4 → 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 +22 -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/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/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,736 @@
|
|
|
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 { parseAccount } from '../../accounts/utils/parseAccount.js';
|
|
5
|
+
import { readContract } from '../../actions/public/readContract.js';
|
|
6
|
+
import { writeContract } from '../../actions/wallet/writeContract.js';
|
|
7
|
+
import { writeContractSync } from '../../actions/wallet/writeContractSync.js';
|
|
8
|
+
import { zeroAddress } from '../../constants/address.js';
|
|
9
|
+
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
|
|
10
|
+
import * as Abis from '../Abis.js';
|
|
11
|
+
import { signVoucher as signVoucher_ } from '../Account.js';
|
|
12
|
+
import { defineCall } from '../internal/utils.js';
|
|
13
|
+
/**
|
|
14
|
+
* Closes a TIP-20 channel reserve channel from the payee or operator side.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { Actions } from 'viem/tempo'
|
|
19
|
+
*
|
|
20
|
+
* const hash = await Actions.channel.close(client, {
|
|
21
|
+
* captureAmount: 100n,
|
|
22
|
+
* cumulativeAmount: 100n,
|
|
23
|
+
* channel,
|
|
24
|
+
* signature: '0x...',
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param client - Client.
|
|
29
|
+
* @param parameters - Parameters.
|
|
30
|
+
* @returns The transaction hash.
|
|
31
|
+
*/
|
|
32
|
+
export async function close(client, parameters) {
|
|
33
|
+
return close.inner(writeContract, client, parameters);
|
|
34
|
+
}
|
|
35
|
+
(function (close) {
|
|
36
|
+
/** @internal */
|
|
37
|
+
async function inner(action, client, parameters) {
|
|
38
|
+
const { captureAmount, cumulativeAmount, channel, signature, ...rest } = parameters;
|
|
39
|
+
return (await action(client, {
|
|
40
|
+
...rest,
|
|
41
|
+
...close.call({
|
|
42
|
+
captureAmount,
|
|
43
|
+
cumulativeAmount,
|
|
44
|
+
channel,
|
|
45
|
+
signature,
|
|
46
|
+
}),
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
close.inner = inner;
|
|
50
|
+
/**
|
|
51
|
+
* Defines a call to the `close` function.
|
|
52
|
+
*
|
|
53
|
+
* @param args - Arguments.
|
|
54
|
+
* @returns The call.
|
|
55
|
+
*/
|
|
56
|
+
function call(args) {
|
|
57
|
+
const { captureAmount, cumulativeAmount, channel, signature } = args;
|
|
58
|
+
return defineCall({
|
|
59
|
+
address: ox_Channel.address,
|
|
60
|
+
abi: Abis.tip20ChannelReserve,
|
|
61
|
+
functionName: 'close',
|
|
62
|
+
args: [
|
|
63
|
+
ox_Channel.from(channel),
|
|
64
|
+
cumulativeAmount,
|
|
65
|
+
captureAmount,
|
|
66
|
+
signature,
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
close.call = call;
|
|
71
|
+
/**
|
|
72
|
+
* Extracts the `ChannelClosed` event from logs.
|
|
73
|
+
*
|
|
74
|
+
* @param logs - The logs.
|
|
75
|
+
* @returns The `ChannelClosed` event.
|
|
76
|
+
*/
|
|
77
|
+
function extractEvent(logs) {
|
|
78
|
+
const [log] = parseEventLogs({
|
|
79
|
+
abi: Abis.tip20ChannelReserve,
|
|
80
|
+
logs,
|
|
81
|
+
eventName: 'ChannelClosed',
|
|
82
|
+
strict: true,
|
|
83
|
+
});
|
|
84
|
+
if (!log)
|
|
85
|
+
throw new Error('`ChannelClosed` event not found.');
|
|
86
|
+
return log;
|
|
87
|
+
}
|
|
88
|
+
close.extractEvent = extractEvent;
|
|
89
|
+
})(close || (close = {}));
|
|
90
|
+
/**
|
|
91
|
+
* Closes a TIP-20 channel reserve channel and waits for the transaction receipt.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { Actions } from 'viem/tempo'
|
|
96
|
+
*
|
|
97
|
+
* const result = await Actions.channel.closeSync(client, {
|
|
98
|
+
* captureAmount: 100n,
|
|
99
|
+
* cumulativeAmount: 100n,
|
|
100
|
+
* channel,
|
|
101
|
+
* signature: '0x...',
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @param client - Client.
|
|
106
|
+
* @param parameters - Parameters.
|
|
107
|
+
* @returns The transaction receipt and event data.
|
|
108
|
+
*/
|
|
109
|
+
export async function closeSync(client, parameters) {
|
|
110
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
111
|
+
const receipt = await close.inner(writeContractSync, client, {
|
|
112
|
+
...rest,
|
|
113
|
+
throwOnReceiptRevert,
|
|
114
|
+
});
|
|
115
|
+
const { args } = close.extractEvent(receipt.logs);
|
|
116
|
+
return { ...args, receipt };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Gets TIP-20 channel reserve state for a channel ID or channel.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { createClient, http } from 'viem'
|
|
124
|
+
* import { tempo } from 'viem/chains'
|
|
125
|
+
* import { Actions } from 'viem/tempo'
|
|
126
|
+
*
|
|
127
|
+
* const client = createClient({
|
|
128
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
129
|
+
* transport: http(),
|
|
130
|
+
* })
|
|
131
|
+
*
|
|
132
|
+
* const state = await Actions.channel.getStates(client, {
|
|
133
|
+
* channel: '0x...',
|
|
134
|
+
* })
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @param client - Client.
|
|
138
|
+
* @param parameters - Parameters.
|
|
139
|
+
* @returns Channel state for a single channel, or channel states for multiple channels.
|
|
140
|
+
*/
|
|
141
|
+
export async function getStates(client, parameters) {
|
|
142
|
+
const chainId = client.chain?.id;
|
|
143
|
+
const { channel, ...rest } = parameters;
|
|
144
|
+
return readContract(client, {
|
|
145
|
+
...rest,
|
|
146
|
+
...getStates.call({ channel, chainId }),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
(function (getStates) {
|
|
150
|
+
/**
|
|
151
|
+
* Defines a call to the `getChannelState` or `getChannelStatesBatch` function.
|
|
152
|
+
*
|
|
153
|
+
* Can be passed as a parameter to:
|
|
154
|
+
* - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
|
|
155
|
+
* - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
|
|
156
|
+
* - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { createClient, http, walletActions } from 'viem'
|
|
161
|
+
* import { tempo } from 'viem/chains'
|
|
162
|
+
* import { Actions } from 'viem/tempo'
|
|
163
|
+
*
|
|
164
|
+
* const client = createClient({
|
|
165
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
166
|
+
* transport: http(),
|
|
167
|
+
* }).extend(walletActions)
|
|
168
|
+
*
|
|
169
|
+
* const calls = [Actions.channel.getStates.call({ channel: '0x...' })]
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @param args - Arguments.
|
|
173
|
+
* @returns The call.
|
|
174
|
+
*/
|
|
175
|
+
function call(args) {
|
|
176
|
+
const { channel, chainId } = args;
|
|
177
|
+
if (Array.isArray(channel)) {
|
|
178
|
+
const channelIds = channel.map((channel) => {
|
|
179
|
+
if (typeof channel === 'string')
|
|
180
|
+
return channel;
|
|
181
|
+
if (chainId === undefined)
|
|
182
|
+
throw new Error('`chainId` is required for channel inputs.');
|
|
183
|
+
return ox_Channel.computeId(channel, { chainId });
|
|
184
|
+
});
|
|
185
|
+
return defineCall({
|
|
186
|
+
address: ox_Channel.address,
|
|
187
|
+
abi: Abis.tip20ChannelReserve,
|
|
188
|
+
args: [channelIds],
|
|
189
|
+
functionName: 'getChannelStatesBatch',
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
const channel_ = channel;
|
|
193
|
+
if (typeof channel_ === 'string')
|
|
194
|
+
return defineCall({
|
|
195
|
+
address: ox_Channel.address,
|
|
196
|
+
abi: Abis.tip20ChannelReserve,
|
|
197
|
+
args: [channel_],
|
|
198
|
+
functionName: 'getChannelState',
|
|
199
|
+
});
|
|
200
|
+
if (chainId === undefined)
|
|
201
|
+
throw new Error('`chainId` is required for channel inputs.');
|
|
202
|
+
return defineCall({
|
|
203
|
+
address: ox_Channel.address,
|
|
204
|
+
abi: Abis.tip20ChannelReserve,
|
|
205
|
+
args: [ox_Channel.computeId(channel_, { chainId })],
|
|
206
|
+
functionName: 'getChannelState',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
getStates.call = call;
|
|
210
|
+
})(getStates || (getStates = {}));
|
|
211
|
+
/**
|
|
212
|
+
* Opens and funds a TIP-20 channel reserve channel.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { createClient, http } from 'viem'
|
|
217
|
+
* import { tempo } from 'viem/chains'
|
|
218
|
+
* import { Actions } from 'viem/tempo'
|
|
219
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
220
|
+
*
|
|
221
|
+
* const client = createClient({
|
|
222
|
+
* account: privateKeyToAccount('0x...'),
|
|
223
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
224
|
+
* transport: http(),
|
|
225
|
+
* })
|
|
226
|
+
*
|
|
227
|
+
* const hash = await Actions.channel.open(client, {
|
|
228
|
+
* deposit: 100n,
|
|
229
|
+
* payee: '0x...',
|
|
230
|
+
* token: 1n,
|
|
231
|
+
* })
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @param client - Client.
|
|
235
|
+
* @param parameters - Parameters.
|
|
236
|
+
* @returns The transaction hash.
|
|
237
|
+
*/
|
|
238
|
+
export async function open(client, parameters) {
|
|
239
|
+
return open.inner(writeContract, client, parameters);
|
|
240
|
+
}
|
|
241
|
+
(function (open) {
|
|
242
|
+
/** @internal */
|
|
243
|
+
async function inner(action, client, parameters) {
|
|
244
|
+
const { authorizedSigner, deposit, operator, payee, salt, token, ...rest } = parameters;
|
|
245
|
+
return (await action(client, {
|
|
246
|
+
...rest,
|
|
247
|
+
...open.call({
|
|
248
|
+
authorizedSigner,
|
|
249
|
+
deposit,
|
|
250
|
+
operator,
|
|
251
|
+
payee,
|
|
252
|
+
salt,
|
|
253
|
+
token,
|
|
254
|
+
}),
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
open.inner = inner;
|
|
258
|
+
/**
|
|
259
|
+
* Defines a call to the `open` function.
|
|
260
|
+
*
|
|
261
|
+
* @param args - Arguments.
|
|
262
|
+
* @returns The call.
|
|
263
|
+
*/
|
|
264
|
+
function call(args) {
|
|
265
|
+
const { authorizedSigner = zeroAddress, deposit, operator = zeroAddress, payee, salt = Hex.random(32), token, } = args;
|
|
266
|
+
return defineCall({
|
|
267
|
+
address: ox_Channel.address,
|
|
268
|
+
abi: Abis.tip20ChannelReserve,
|
|
269
|
+
functionName: 'open',
|
|
270
|
+
args: [
|
|
271
|
+
Address.from(payee),
|
|
272
|
+
Address.from(operator),
|
|
273
|
+
TokenId.toAddress(token),
|
|
274
|
+
deposit,
|
|
275
|
+
salt,
|
|
276
|
+
Address.from(authorizedSigner),
|
|
277
|
+
],
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
open.call = call;
|
|
281
|
+
/**
|
|
282
|
+
* Extracts the `ChannelOpened` event from logs.
|
|
283
|
+
*
|
|
284
|
+
* @param logs - The logs.
|
|
285
|
+
* @returns The `ChannelOpened` event.
|
|
286
|
+
*/
|
|
287
|
+
function extractEvent(logs) {
|
|
288
|
+
const [log] = parseEventLogs({
|
|
289
|
+
abi: Abis.tip20ChannelReserve,
|
|
290
|
+
logs,
|
|
291
|
+
eventName: 'ChannelOpened',
|
|
292
|
+
strict: true,
|
|
293
|
+
});
|
|
294
|
+
if (!log)
|
|
295
|
+
throw new Error('`ChannelOpened` event not found.');
|
|
296
|
+
return log;
|
|
297
|
+
}
|
|
298
|
+
open.extractEvent = extractEvent;
|
|
299
|
+
})(open || (open = {}));
|
|
300
|
+
/**
|
|
301
|
+
* Opens and funds a TIP-20 channel reserve channel and waits for the
|
|
302
|
+
* transaction receipt.
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```ts
|
|
306
|
+
* import { createClient, http } from 'viem'
|
|
307
|
+
* import { tempo } from 'viem/chains'
|
|
308
|
+
* import { Actions } from 'viem/tempo'
|
|
309
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
310
|
+
*
|
|
311
|
+
* const client = createClient({
|
|
312
|
+
* account: privateKeyToAccount('0x...'),
|
|
313
|
+
* chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
|
|
314
|
+
* transport: http(),
|
|
315
|
+
* })
|
|
316
|
+
*
|
|
317
|
+
* const result = await Actions.channel.openSync(client, {
|
|
318
|
+
* deposit: 100n,
|
|
319
|
+
* payee: '0x...',
|
|
320
|
+
* token: 1n,
|
|
321
|
+
* })
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @param client - Client.
|
|
325
|
+
* @param parameters - Parameters.
|
|
326
|
+
* @returns The transaction receipt and event data.
|
|
327
|
+
*/
|
|
328
|
+
export async function openSync(client, parameters) {
|
|
329
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
330
|
+
const receipt = await open.inner(writeContractSync, client, {
|
|
331
|
+
...rest,
|
|
332
|
+
throwOnReceiptRevert,
|
|
333
|
+
});
|
|
334
|
+
const { args } = open.extractEvent(receipt.logs);
|
|
335
|
+
return { ...args, receipt };
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Starts the payer close timer for a TIP-20 channel reserve channel.
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* import { Actions } from 'viem/tempo'
|
|
343
|
+
*
|
|
344
|
+
* const hash = await Actions.channel.requestClose(client, {
|
|
345
|
+
* channel,
|
|
346
|
+
* })
|
|
347
|
+
* ```
|
|
348
|
+
*
|
|
349
|
+
* @param client - Client.
|
|
350
|
+
* @param parameters - Parameters.
|
|
351
|
+
* @returns The transaction hash.
|
|
352
|
+
*/
|
|
353
|
+
export async function requestClose(client, parameters) {
|
|
354
|
+
return requestClose.inner(writeContract, client, parameters);
|
|
355
|
+
}
|
|
356
|
+
(function (requestClose) {
|
|
357
|
+
/** @internal */
|
|
358
|
+
async function inner(action, client, parameters) {
|
|
359
|
+
const { channel, ...rest } = parameters;
|
|
360
|
+
return (await action(client, {
|
|
361
|
+
...rest,
|
|
362
|
+
...requestClose.call({ channel }),
|
|
363
|
+
}));
|
|
364
|
+
}
|
|
365
|
+
requestClose.inner = inner;
|
|
366
|
+
/**
|
|
367
|
+
* Defines a call to the `requestClose` function.
|
|
368
|
+
*
|
|
369
|
+
* @param args - Arguments.
|
|
370
|
+
* @returns The call.
|
|
371
|
+
*/
|
|
372
|
+
function call(args) {
|
|
373
|
+
const { channel } = args;
|
|
374
|
+
return defineCall({
|
|
375
|
+
address: ox_Channel.address,
|
|
376
|
+
abi: Abis.tip20ChannelReserve,
|
|
377
|
+
functionName: 'requestClose',
|
|
378
|
+
args: [ox_Channel.from(channel)],
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
requestClose.call = call;
|
|
382
|
+
/**
|
|
383
|
+
* Extracts the `CloseRequested` event from logs.
|
|
384
|
+
*
|
|
385
|
+
* @param logs - The logs.
|
|
386
|
+
* @returns The `CloseRequested` event.
|
|
387
|
+
*/
|
|
388
|
+
function extractEvent(logs) {
|
|
389
|
+
const [log] = parseEventLogs({
|
|
390
|
+
abi: Abis.tip20ChannelReserve,
|
|
391
|
+
logs,
|
|
392
|
+
eventName: 'CloseRequested',
|
|
393
|
+
strict: true,
|
|
394
|
+
});
|
|
395
|
+
if (!log)
|
|
396
|
+
throw new Error('`CloseRequested` event not found.');
|
|
397
|
+
return log;
|
|
398
|
+
}
|
|
399
|
+
requestClose.extractEvent = extractEvent;
|
|
400
|
+
})(requestClose || (requestClose = {}));
|
|
401
|
+
/**
|
|
402
|
+
* Starts the payer close timer and waits for the transaction receipt.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* import { Actions } from 'viem/tempo'
|
|
407
|
+
*
|
|
408
|
+
* const result = await Actions.channel.requestCloseSync(client, {
|
|
409
|
+
* channel,
|
|
410
|
+
* })
|
|
411
|
+
* ```
|
|
412
|
+
*
|
|
413
|
+
* @param client - Client.
|
|
414
|
+
* @param parameters - Parameters.
|
|
415
|
+
* @returns The transaction receipt and event data.
|
|
416
|
+
*/
|
|
417
|
+
export async function requestCloseSync(client, parameters) {
|
|
418
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
419
|
+
const receipt = await requestClose.inner(writeContractSync, client, {
|
|
420
|
+
...rest,
|
|
421
|
+
throwOnReceiptRevert,
|
|
422
|
+
});
|
|
423
|
+
const { args } = requestClose.extractEvent(receipt.logs);
|
|
424
|
+
return { ...args, receipt };
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Settles a TIP-20 channel reserve voucher.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* import { createClient, http } from 'viem'
|
|
432
|
+
* import { tempo } from 'viem/chains'
|
|
433
|
+
* import { Actions } from 'viem/tempo'
|
|
434
|
+
*
|
|
435
|
+
* const hash = await Actions.channel.settle(client, {
|
|
436
|
+
* cumulativeAmount: 100n,
|
|
437
|
+
* channel,
|
|
438
|
+
* signature: '0x...',
|
|
439
|
+
* })
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* @param client - Client.
|
|
443
|
+
* @param parameters - Parameters.
|
|
444
|
+
* @returns The transaction hash.
|
|
445
|
+
*/
|
|
446
|
+
export async function settle(client, parameters) {
|
|
447
|
+
return settle.inner(writeContract, client, parameters);
|
|
448
|
+
}
|
|
449
|
+
(function (settle) {
|
|
450
|
+
/** @internal */
|
|
451
|
+
async function inner(action, client, parameters) {
|
|
452
|
+
const { cumulativeAmount, channel, signature, ...rest } = parameters;
|
|
453
|
+
return (await action(client, {
|
|
454
|
+
...rest,
|
|
455
|
+
...settle.call({ cumulativeAmount, channel, signature }),
|
|
456
|
+
}));
|
|
457
|
+
}
|
|
458
|
+
settle.inner = inner;
|
|
459
|
+
/**
|
|
460
|
+
* Defines a call to the `settle` function.
|
|
461
|
+
*
|
|
462
|
+
* @param args - Arguments.
|
|
463
|
+
* @returns The call.
|
|
464
|
+
*/
|
|
465
|
+
function call(args) {
|
|
466
|
+
const { cumulativeAmount, channel, signature } = args;
|
|
467
|
+
return defineCall({
|
|
468
|
+
address: ox_Channel.address,
|
|
469
|
+
abi: Abis.tip20ChannelReserve,
|
|
470
|
+
functionName: 'settle',
|
|
471
|
+
args: [ox_Channel.from(channel), cumulativeAmount, signature],
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
settle.call = call;
|
|
475
|
+
/**
|
|
476
|
+
* Extracts the `Settled` event from logs.
|
|
477
|
+
*
|
|
478
|
+
* @param logs - The logs.
|
|
479
|
+
* @returns The `Settled` event.
|
|
480
|
+
*/
|
|
481
|
+
function extractEvent(logs) {
|
|
482
|
+
const [log] = parseEventLogs({
|
|
483
|
+
abi: Abis.tip20ChannelReserve,
|
|
484
|
+
logs,
|
|
485
|
+
eventName: 'Settled',
|
|
486
|
+
strict: true,
|
|
487
|
+
});
|
|
488
|
+
if (!log)
|
|
489
|
+
throw new Error('`Settled` event not found.');
|
|
490
|
+
return log;
|
|
491
|
+
}
|
|
492
|
+
settle.extractEvent = extractEvent;
|
|
493
|
+
})(settle || (settle = {}));
|
|
494
|
+
/**
|
|
495
|
+
* Settles a TIP-20 channel reserve voucher and waits for the transaction receipt.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* import { Actions } from 'viem/tempo'
|
|
500
|
+
*
|
|
501
|
+
* const result = await Actions.channel.settleSync(client, {
|
|
502
|
+
* cumulativeAmount: 100n,
|
|
503
|
+
* channel,
|
|
504
|
+
* signature: '0x...',
|
|
505
|
+
* })
|
|
506
|
+
* ```
|
|
507
|
+
*
|
|
508
|
+
* @param client - Client.
|
|
509
|
+
* @param parameters - Parameters.
|
|
510
|
+
* @returns The transaction receipt and event data.
|
|
511
|
+
*/
|
|
512
|
+
export async function settleSync(client, parameters) {
|
|
513
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
514
|
+
const receipt = await settle.inner(writeContractSync, client, {
|
|
515
|
+
...rest,
|
|
516
|
+
throwOnReceiptRevert,
|
|
517
|
+
});
|
|
518
|
+
const { args } = settle.extractEvent(receipt.logs);
|
|
519
|
+
return { ...args, receipt };
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Signs a TIP-20 channel reserve voucher.
|
|
523
|
+
*
|
|
524
|
+
* @example
|
|
525
|
+
* ```ts
|
|
526
|
+
* import { parseUnits } from 'viem'
|
|
527
|
+
* import { Actions } from 'viem/tempo'
|
|
528
|
+
*
|
|
529
|
+
* const signature = await Actions.channel.signVoucher(client, {
|
|
530
|
+
* channel,
|
|
531
|
+
* cumulativeAmount: parseUnits('40', 6),
|
|
532
|
+
* })
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @param client - Client.
|
|
536
|
+
* @param parameters - Parameters.
|
|
537
|
+
* @returns The voucher signature.
|
|
538
|
+
*/
|
|
539
|
+
export async function signVoucher(client, parameters) {
|
|
540
|
+
const { account: account_ = client.account, chainId = client.chain?.id, channel, cumulativeAmount, } = parameters;
|
|
541
|
+
if (!account_)
|
|
542
|
+
throw new Error('account is required.');
|
|
543
|
+
if (chainId === undefined)
|
|
544
|
+
throw new Error('chainId is required.');
|
|
545
|
+
const parsed = parseAccount(account_);
|
|
546
|
+
if (!('sign' in parsed) || !parsed.sign)
|
|
547
|
+
throw new Error('account.sign is required.');
|
|
548
|
+
return signVoucher_(parsed, {
|
|
549
|
+
chainId,
|
|
550
|
+
channel,
|
|
551
|
+
cumulativeAmount,
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Adds deposit to a TIP-20 channel reserve channel.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```ts
|
|
559
|
+
* import { Actions } from 'viem/tempo'
|
|
560
|
+
*
|
|
561
|
+
* const hash = await Actions.channel.topUp(client, {
|
|
562
|
+
* additionalDeposit: 100n,
|
|
563
|
+
* channel,
|
|
564
|
+
* })
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @param client - Client.
|
|
568
|
+
* @param parameters - Parameters.
|
|
569
|
+
* @returns The transaction hash.
|
|
570
|
+
*/
|
|
571
|
+
export async function topUp(client, parameters) {
|
|
572
|
+
return topUp.inner(writeContract, client, parameters);
|
|
573
|
+
}
|
|
574
|
+
(function (topUp) {
|
|
575
|
+
/** @internal */
|
|
576
|
+
async function inner(action, client, parameters) {
|
|
577
|
+
const { additionalDeposit, channel, ...rest } = parameters;
|
|
578
|
+
return (await action(client, {
|
|
579
|
+
...rest,
|
|
580
|
+
...topUp.call({ additionalDeposit, channel }),
|
|
581
|
+
}));
|
|
582
|
+
}
|
|
583
|
+
topUp.inner = inner;
|
|
584
|
+
/**
|
|
585
|
+
* Defines a call to the `topUp` function.
|
|
586
|
+
*
|
|
587
|
+
* @param args - Arguments.
|
|
588
|
+
* @returns The call.
|
|
589
|
+
*/
|
|
590
|
+
function call(args) {
|
|
591
|
+
const { additionalDeposit, channel } = args;
|
|
592
|
+
return defineCall({
|
|
593
|
+
address: ox_Channel.address,
|
|
594
|
+
abi: Abis.tip20ChannelReserve,
|
|
595
|
+
functionName: 'topUp',
|
|
596
|
+
args: [ox_Channel.from(channel), additionalDeposit],
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
topUp.call = call;
|
|
600
|
+
/**
|
|
601
|
+
* Extracts the `TopUp` event from logs.
|
|
602
|
+
*
|
|
603
|
+
* @param logs - The logs.
|
|
604
|
+
* @returns The `TopUp` event.
|
|
605
|
+
*/
|
|
606
|
+
function extractEvent(logs) {
|
|
607
|
+
const [log] = parseEventLogs({
|
|
608
|
+
abi: Abis.tip20ChannelReserve,
|
|
609
|
+
logs,
|
|
610
|
+
eventName: 'TopUp',
|
|
611
|
+
strict: true,
|
|
612
|
+
});
|
|
613
|
+
if (!log)
|
|
614
|
+
throw new Error('`TopUp` event not found.');
|
|
615
|
+
return log;
|
|
616
|
+
}
|
|
617
|
+
topUp.extractEvent = extractEvent;
|
|
618
|
+
})(topUp || (topUp = {}));
|
|
619
|
+
/**
|
|
620
|
+
* Adds deposit to a TIP-20 channel reserve channel and waits for the
|
|
621
|
+
* transaction receipt.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* import { Actions } from 'viem/tempo'
|
|
626
|
+
*
|
|
627
|
+
* const result = await Actions.channel.topUpSync(client, {
|
|
628
|
+
* additionalDeposit: 100n,
|
|
629
|
+
* channel,
|
|
630
|
+
* })
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* @param client - Client.
|
|
634
|
+
* @param parameters - Parameters.
|
|
635
|
+
* @returns The transaction receipt and event data.
|
|
636
|
+
*/
|
|
637
|
+
export async function topUpSync(client, parameters) {
|
|
638
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
639
|
+
const receipt = await topUp.inner(writeContractSync, client, {
|
|
640
|
+
...rest,
|
|
641
|
+
throwOnReceiptRevert,
|
|
642
|
+
});
|
|
643
|
+
const { args } = topUp.extractEvent(receipt.logs);
|
|
644
|
+
return { ...args, receipt };
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Withdraws payer funds after the close grace period elapses.
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* ```ts
|
|
651
|
+
* import { Actions } from 'viem/tempo'
|
|
652
|
+
*
|
|
653
|
+
* const hash = await Actions.channel.withdraw(client, {
|
|
654
|
+
* channel,
|
|
655
|
+
* })
|
|
656
|
+
* ```
|
|
657
|
+
*
|
|
658
|
+
* @param client - Client.
|
|
659
|
+
* @param parameters - Parameters.
|
|
660
|
+
* @returns The transaction hash.
|
|
661
|
+
*/
|
|
662
|
+
export async function withdraw(client, parameters) {
|
|
663
|
+
return withdraw.inner(writeContract, client, parameters);
|
|
664
|
+
}
|
|
665
|
+
(function (withdraw) {
|
|
666
|
+
/** @internal */
|
|
667
|
+
async function inner(action, client, parameters) {
|
|
668
|
+
const { channel, ...rest } = parameters;
|
|
669
|
+
return (await action(client, {
|
|
670
|
+
...rest,
|
|
671
|
+
...withdraw.call({ channel }),
|
|
672
|
+
}));
|
|
673
|
+
}
|
|
674
|
+
withdraw.inner = inner;
|
|
675
|
+
/**
|
|
676
|
+
* Defines a call to the `withdraw` function.
|
|
677
|
+
*
|
|
678
|
+
* @param args - Arguments.
|
|
679
|
+
* @returns The call.
|
|
680
|
+
*/
|
|
681
|
+
function call(args) {
|
|
682
|
+
const { channel } = args;
|
|
683
|
+
return defineCall({
|
|
684
|
+
address: ox_Channel.address,
|
|
685
|
+
abi: Abis.tip20ChannelReserve,
|
|
686
|
+
functionName: 'withdraw',
|
|
687
|
+
args: [ox_Channel.from(channel)],
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
withdraw.call = call;
|
|
691
|
+
/**
|
|
692
|
+
* Extracts the `ChannelClosed` event from logs.
|
|
693
|
+
*
|
|
694
|
+
* @param logs - The logs.
|
|
695
|
+
* @returns The `ChannelClosed` event.
|
|
696
|
+
*/
|
|
697
|
+
function extractEvent(logs) {
|
|
698
|
+
const [log] = parseEventLogs({
|
|
699
|
+
abi: Abis.tip20ChannelReserve,
|
|
700
|
+
logs,
|
|
701
|
+
eventName: 'ChannelClosed',
|
|
702
|
+
strict: true,
|
|
703
|
+
});
|
|
704
|
+
if (!log)
|
|
705
|
+
throw new Error('`ChannelClosed` event not found.');
|
|
706
|
+
return log;
|
|
707
|
+
}
|
|
708
|
+
withdraw.extractEvent = extractEvent;
|
|
709
|
+
})(withdraw || (withdraw = {}));
|
|
710
|
+
/**
|
|
711
|
+
* Withdraws payer funds after the close grace period elapses and waits for the
|
|
712
|
+
* transaction receipt.
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```ts
|
|
716
|
+
* import { Actions } from 'viem/tempo'
|
|
717
|
+
*
|
|
718
|
+
* const result = await Actions.channel.withdrawSync(client, {
|
|
719
|
+
* channel,
|
|
720
|
+
* })
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* @param client - Client.
|
|
724
|
+
* @param parameters - Parameters.
|
|
725
|
+
* @returns The transaction receipt and event data.
|
|
726
|
+
*/
|
|
727
|
+
export async function withdrawSync(client, parameters) {
|
|
728
|
+
const { throwOnReceiptRevert = true, ...rest } = parameters;
|
|
729
|
+
const receipt = await withdraw.inner(writeContractSync, client, {
|
|
730
|
+
...rest,
|
|
731
|
+
throwOnReceiptRevert,
|
|
732
|
+
});
|
|
733
|
+
const { args } = withdraw.extractEvent(receipt.logs);
|
|
734
|
+
return { ...args, receipt };
|
|
735
|
+
}
|
|
736
|
+
//# sourceMappingURL=channel.js.map
|