eth-twc-sdk-js 0.1.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/README.md +29 -0
- package/dist/abi.cjs +286 -0
- package/dist/abi.d.cts +419 -0
- package/dist/abi.d.ts +419 -0
- package/dist/abi.js +259 -0
- package/dist/config.cjs +41 -0
- package/dist/config.d.cts +14 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +11 -0
- package/dist/selfTransfer/batch/index.cjs +373 -0
- package/dist/selfTransfer/batch/index.d.cts +24 -0
- package/dist/selfTransfer/batch/index.d.ts +24 -0
- package/dist/selfTransfer/batch/index.js +345 -0
- package/dist/selfTransfer/single/index.cjs +360 -0
- package/dist/selfTransfer/single/index.d.cts +20 -0
- package/dist/selfTransfer/single/index.d.ts +20 -0
- package/dist/selfTransfer/single/index.js +332 -0
- package/dist/selfTransfer/unified/index.cjs +372 -0
- package/dist/selfTransfer/unified/index.d.cts +24 -0
- package/dist/selfTransfer/unified/index.d.ts +24 -0
- package/dist/selfTransfer/unified/index.js +344 -0
- package/dist/signatureTransfer/batch/index.cjs +545 -0
- package/dist/signatureTransfer/batch/index.d.cts +100 -0
- package/dist/signatureTransfer/batch/index.d.ts +100 -0
- package/dist/signatureTransfer/batch/index.js +514 -0
- package/dist/signatureTransfer/cancelAuthorization/index.cjs +491 -0
- package/dist/signatureTransfer/cancelAuthorization/index.d.cts +49 -0
- package/dist/signatureTransfer/cancelAuthorization/index.d.ts +49 -0
- package/dist/signatureTransfer/cancelAuthorization/index.js +460 -0
- package/dist/signatureTransfer/single/index.cjs +528 -0
- package/dist/signatureTransfer/single/index.d.cts +84 -0
- package/dist/signatureTransfer/single/index.d.ts +84 -0
- package/dist/signatureTransfer/single/index.js +497 -0
- package/dist/signatureTransfer/unified/index.cjs +541 -0
- package/dist/signatureTransfer/unified/index.d.cts +95 -0
- package/dist/signatureTransfer/unified/index.d.ts +95 -0
- package/dist/signatureTransfer/unified/index.js +510 -0
- package/dist/types/transferDetail.cjs +62 -0
- package/dist/types/transferDetail.d.cts +15 -0
- package/dist/types/transferDetail.d.ts +15 -0
- package/dist/types/transferDetail.js +36 -0
- package/dist/types/utils.cjs +52 -0
- package/dist/types/utils.d.cts +12 -0
- package/dist/types/utils.d.ts +12 -0
- package/dist/types/utils.js +23 -0
- package/dist/utils.cjs +123 -0
- package/dist/utils.d.cts +21 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.js +90 -0
- package/dist/verify.cjs +366 -0
- package/dist/verify.d.cts +433 -0
- package/dist/verify.d.ts +433 -0
- package/dist/verify.js +339 -0
- package/package.json +100 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Hex } from 'viem';
|
|
2
|
+
import * as arktype_internal_variants_object_ts from 'arktype/internal/variants/object.ts';
|
|
3
|
+
|
|
4
|
+
declare const singleTransfer: arktype_internal_variants_object_ts.ObjectType<{
|
|
5
|
+
token: `0x${string}`;
|
|
6
|
+
to: `0x${string}`;
|
|
7
|
+
value: bigint;
|
|
8
|
+
commitment: `0x${string}`;
|
|
9
|
+
}, {}>;
|
|
10
|
+
declare const argsSchema: arktype_internal_variants_object_ts.ObjectType<{
|
|
11
|
+
token: `0x${string}`;
|
|
12
|
+
to: `0x${string}`;
|
|
13
|
+
value: bigint;
|
|
14
|
+
commitment: `0x${string}`;
|
|
15
|
+
}, {}>;
|
|
16
|
+
type SelfTransferSingleArgs = typeof singleTransfer.infer;
|
|
17
|
+
|
|
18
|
+
declare const sendTx: (publicClient: PublicClient, wallet: WalletClient, account: Hex, args: SelfTransferSingleArgs) => Promise<`0x${string}`>;
|
|
19
|
+
|
|
20
|
+
export { type SelfTransferSingleArgs, argsSchema, sendTx };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PublicClient, WalletClient, Hex } from 'viem';
|
|
2
|
+
import * as arktype_internal_variants_object_ts from 'arktype/internal/variants/object.ts';
|
|
3
|
+
|
|
4
|
+
declare const singleTransfer: arktype_internal_variants_object_ts.ObjectType<{
|
|
5
|
+
token: `0x${string}`;
|
|
6
|
+
to: `0x${string}`;
|
|
7
|
+
value: bigint;
|
|
8
|
+
commitment: `0x${string}`;
|
|
9
|
+
}, {}>;
|
|
10
|
+
declare const argsSchema: arktype_internal_variants_object_ts.ObjectType<{
|
|
11
|
+
token: `0x${string}`;
|
|
12
|
+
to: `0x${string}`;
|
|
13
|
+
value: bigint;
|
|
14
|
+
commitment: `0x${string}`;
|
|
15
|
+
}, {}>;
|
|
16
|
+
type SelfTransferSingleArgs = typeof singleTransfer.infer;
|
|
17
|
+
|
|
18
|
+
declare const sendTx: (publicClient: PublicClient, wallet: WalletClient, account: Hex, args: SelfTransferSingleArgs) => Promise<`0x${string}`>;
|
|
19
|
+
|
|
20
|
+
export { type SelfTransferSingleArgs, argsSchema, sendTx };
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
// twcConstants.ts
|
|
2
|
+
var transferWithCommitmentAddress = "0x5C260DD537A9c23Bbd42493e59F3CeA7da2DbC71";
|
|
3
|
+
|
|
4
|
+
// ../contracts/abi/generated.ts
|
|
5
|
+
var transferWithCommitmentAbi = [
|
|
6
|
+
{
|
|
7
|
+
type: "constructor",
|
|
8
|
+
inputs: [
|
|
9
|
+
{ name: "name", internalType: "string", type: "string" },
|
|
10
|
+
{ name: "version", internalType: "string", type: "string" }
|
|
11
|
+
],
|
|
12
|
+
stateMutability: "nonpayable"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
type: "function",
|
|
16
|
+
inputs: [],
|
|
17
|
+
name: "BATCH_TRANSFER_WITH_COMMIT_TYPEHASH",
|
|
18
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
19
|
+
stateMutability: "view"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: "function",
|
|
23
|
+
inputs: [],
|
|
24
|
+
name: "CANCEL_AUTHORIZATION_TYPEHASH",
|
|
25
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
26
|
+
stateMutability: "view"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: "function",
|
|
30
|
+
inputs: [],
|
|
31
|
+
name: "TRANSFER_WITH_COMMIT_TYPEHASH",
|
|
32
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
33
|
+
stateMutability: "view"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: "function",
|
|
37
|
+
inputs: [],
|
|
38
|
+
name: "UNI_COMMIT_TRANSFER_TYPEHASH",
|
|
39
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
40
|
+
stateMutability: "view"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "function",
|
|
44
|
+
inputs: [
|
|
45
|
+
{ name: "authorizer", internalType: "address", type: "address" },
|
|
46
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
47
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
48
|
+
],
|
|
49
|
+
name: "cancelAuthorization",
|
|
50
|
+
outputs: [],
|
|
51
|
+
stateMutability: "nonpayable"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "function",
|
|
55
|
+
inputs: [
|
|
56
|
+
{ name: "payer", internalType: "address", type: "address" },
|
|
57
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
58
|
+
],
|
|
59
|
+
name: "commitmentState",
|
|
60
|
+
outputs: [{ name: "", internalType: "bool", type: "bool" }],
|
|
61
|
+
stateMutability: "view"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "function",
|
|
65
|
+
inputs: [],
|
|
66
|
+
name: "eip712Domain",
|
|
67
|
+
outputs: [
|
|
68
|
+
{ name: "fields", internalType: "bytes1", type: "bytes1" },
|
|
69
|
+
{ name: "name", internalType: "string", type: "string" },
|
|
70
|
+
{ name: "version", internalType: "string", type: "string" },
|
|
71
|
+
{ name: "chainId", internalType: "uint256", type: "uint256" },
|
|
72
|
+
{ name: "verifyingContract", internalType: "address", type: "address" },
|
|
73
|
+
{ name: "salt", internalType: "bytes32", type: "bytes32" },
|
|
74
|
+
{ name: "extensions", internalType: "uint256[]", type: "uint256[]" }
|
|
75
|
+
],
|
|
76
|
+
stateMutability: "view"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: "function",
|
|
80
|
+
inputs: [
|
|
81
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
82
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
83
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
84
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
85
|
+
],
|
|
86
|
+
name: "transfer",
|
|
87
|
+
outputs: [],
|
|
88
|
+
stateMutability: "nonpayable"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "function",
|
|
92
|
+
inputs: [
|
|
93
|
+
{
|
|
94
|
+
name: "details",
|
|
95
|
+
internalType: "struct TransferDetail[]",
|
|
96
|
+
type: "tuple[]",
|
|
97
|
+
components: [
|
|
98
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
99
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
100
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
104
|
+
],
|
|
105
|
+
name: "transfer",
|
|
106
|
+
outputs: [],
|
|
107
|
+
stateMutability: "nonpayable"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
type: "function",
|
|
111
|
+
inputs: [
|
|
112
|
+
{
|
|
113
|
+
name: "details",
|
|
114
|
+
internalType: "struct CommittedTransferDetail[]",
|
|
115
|
+
type: "tuple[]",
|
|
116
|
+
components: [
|
|
117
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
118
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
119
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
120
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
name: "transfer",
|
|
125
|
+
outputs: [],
|
|
126
|
+
stateMutability: "nonpayable"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: "function",
|
|
130
|
+
inputs: [
|
|
131
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
132
|
+
{
|
|
133
|
+
name: "details",
|
|
134
|
+
internalType: "struct TransferDetail[]",
|
|
135
|
+
type: "tuple[]",
|
|
136
|
+
components: [
|
|
137
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
138
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
139
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
143
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
144
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
145
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
146
|
+
],
|
|
147
|
+
name: "transferWithAuthorization",
|
|
148
|
+
outputs: [],
|
|
149
|
+
stateMutability: "nonpayable"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
type: "function",
|
|
153
|
+
inputs: [
|
|
154
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
155
|
+
{
|
|
156
|
+
name: "details",
|
|
157
|
+
internalType: "struct CommittedTransferDetail[]",
|
|
158
|
+
type: "tuple[]",
|
|
159
|
+
components: [
|
|
160
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
161
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
162
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
163
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" }
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
167
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
168
|
+
{ name: "batchCommitment", internalType: "bytes32", type: "bytes32" },
|
|
169
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
170
|
+
],
|
|
171
|
+
name: "transferWithAuthorization",
|
|
172
|
+
outputs: [],
|
|
173
|
+
stateMutability: "nonpayable"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: "function",
|
|
177
|
+
inputs: [
|
|
178
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
179
|
+
{ name: "to", internalType: "address", type: "address" },
|
|
180
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
181
|
+
{ name: "value", internalType: "uint256", type: "uint256" },
|
|
182
|
+
{ name: "validAfter", internalType: "uint256", type: "uint256" },
|
|
183
|
+
{ name: "validBefore", internalType: "uint256", type: "uint256" },
|
|
184
|
+
{ name: "commitment", internalType: "bytes32", type: "bytes32" },
|
|
185
|
+
{ name: "signature", internalType: "bytes", type: "bytes" }
|
|
186
|
+
],
|
|
187
|
+
name: "transferWithAuthorization",
|
|
188
|
+
outputs: [],
|
|
189
|
+
stateMutability: "nonpayable"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: "event",
|
|
193
|
+
anonymous: false,
|
|
194
|
+
inputs: [
|
|
195
|
+
{
|
|
196
|
+
name: "payer",
|
|
197
|
+
internalType: "address",
|
|
198
|
+
type: "address",
|
|
199
|
+
indexed: true
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "commitment",
|
|
203
|
+
internalType: "bytes32",
|
|
204
|
+
type: "bytes32",
|
|
205
|
+
indexed: true
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
name: "CommitmentUsed"
|
|
209
|
+
},
|
|
210
|
+
{ type: "event", anonymous: false, inputs: [], name: "EIP712DomainChanged" },
|
|
211
|
+
{
|
|
212
|
+
type: "event",
|
|
213
|
+
anonymous: false,
|
|
214
|
+
inputs: [
|
|
215
|
+
{ name: "from", internalType: "address", type: "address", indexed: true },
|
|
216
|
+
{ name: "to", internalType: "address", type: "address", indexed: true },
|
|
217
|
+
{
|
|
218
|
+
name: "token",
|
|
219
|
+
internalType: "address",
|
|
220
|
+
type: "address",
|
|
221
|
+
indexed: true
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "value",
|
|
225
|
+
internalType: "uint256",
|
|
226
|
+
type: "uint256",
|
|
227
|
+
indexed: false
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
name: "commitment",
|
|
231
|
+
internalType: "bytes32",
|
|
232
|
+
type: "bytes32",
|
|
233
|
+
indexed: false
|
|
234
|
+
}
|
|
235
|
+
],
|
|
236
|
+
name: "TransferWithCommitmentSent"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
type: "error",
|
|
240
|
+
inputs: [
|
|
241
|
+
{ name: "token", internalType: "address", type: "address" },
|
|
242
|
+
{ name: "from", internalType: "address", type: "address" },
|
|
243
|
+
{ name: "value", internalType: "uint256", type: "uint256" }
|
|
244
|
+
],
|
|
245
|
+
name: "AllowanceNotEnough"
|
|
246
|
+
},
|
|
247
|
+
{ type: "error", inputs: [], name: "InvalidShortString" },
|
|
248
|
+
{ type: "error", inputs: [], name: "ReentrancyGuardReentrantCall" },
|
|
249
|
+
{
|
|
250
|
+
type: "error",
|
|
251
|
+
inputs: [{ name: "token", internalType: "address", type: "address" }],
|
|
252
|
+
name: "SafeERC20FailedOperation"
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
type: "error",
|
|
256
|
+
inputs: [{ name: "str", internalType: "string", type: "string" }],
|
|
257
|
+
name: "StringTooLong"
|
|
258
|
+
}
|
|
259
|
+
];
|
|
260
|
+
|
|
261
|
+
// utils.ts
|
|
262
|
+
var assertPublicWalletSameChain = (publicClient, wallet) => {
|
|
263
|
+
const publicId = publicClient.chain?.id;
|
|
264
|
+
const walletId = wallet.chain?.id;
|
|
265
|
+
if (publicId === void 0 || walletId === void 0) {
|
|
266
|
+
throw new Error(
|
|
267
|
+
"Chain is not set on public client and/or wallet client"
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (publicId !== walletId) {
|
|
271
|
+
throw new Error(
|
|
272
|
+
`PublicClient and WalletClient chain mismatch: ${publicId} vs ${walletId}`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
async function assertTransferContractDeployed(publicClient, contractAddress = transferWithCommitmentAddress) {
|
|
277
|
+
const code = await publicClient.getCode({ address: contractAddress });
|
|
278
|
+
if (code === void 0 || code === "0x") {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`TransferWithCommitment is not deployed at ${contractAddress} on this chain (no contract code). Deploy with CREATE2 (see contracts/TWC_CREATE2.md) or switch network.`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// selfTransfer/single/types.ts
|
|
286
|
+
import { type as type2 } from "arktype";
|
|
287
|
+
|
|
288
|
+
// types/utils.ts
|
|
289
|
+
import { type } from "arktype";
|
|
290
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
291
|
+
var uint256 = type("bigint").filter(
|
|
292
|
+
(v, ctx) => v <= UINT256_MAX && v >= 0n ? true : ctx.reject(`must be: 0n <= value <= ${UINT256_MAX}`)
|
|
293
|
+
);
|
|
294
|
+
var reBytes32 = /^0x[0-9a-fA-F]{64}$/;
|
|
295
|
+
var reBytes = /^0x[0-9a-fA-F]+$/;
|
|
296
|
+
var reAddress = /^0x[0-9a-fA-F]{40}$/;
|
|
297
|
+
var bytes32 = type("string").narrow(
|
|
298
|
+
(s) => reBytes32.test(s)
|
|
299
|
+
);
|
|
300
|
+
var bytes = type("string").narrow((s) => reBytes.test(s));
|
|
301
|
+
var address = type("string").narrow(
|
|
302
|
+
(s) => reAddress.test(s)
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
// selfTransfer/single/types.ts
|
|
306
|
+
var singleTransfer = type2({
|
|
307
|
+
token: address,
|
|
308
|
+
to: address,
|
|
309
|
+
value: uint256,
|
|
310
|
+
commitment: bytes32
|
|
311
|
+
});
|
|
312
|
+
var argsSchema = singleTransfer;
|
|
313
|
+
|
|
314
|
+
// selfTransfer/single/sendTx.ts
|
|
315
|
+
var sendTx = async (publicClient, wallet, account, args) => {
|
|
316
|
+
assertPublicWalletSameChain(publicClient, wallet);
|
|
317
|
+
await assertTransferContractDeployed(publicClient);
|
|
318
|
+
argsSchema.assert(args);
|
|
319
|
+
const { request } = await publicClient.simulateContract({
|
|
320
|
+
address: transferWithCommitmentAddress,
|
|
321
|
+
abi: transferWithCommitmentAbi,
|
|
322
|
+
functionName: "transfer",
|
|
323
|
+
args: [args.token, args.to, args.value, args.commitment],
|
|
324
|
+
account
|
|
325
|
+
});
|
|
326
|
+
const hash = await wallet.writeContract(request);
|
|
327
|
+
return hash;
|
|
328
|
+
};
|
|
329
|
+
export {
|
|
330
|
+
argsSchema,
|
|
331
|
+
sendTx
|
|
332
|
+
};
|