@actalink/commonlib 0.0.1
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/dist/index.cjs +1984 -0
- package/dist/index.d.cts +9242 -0
- package/dist/index.d.ts +9242 -0
- package/dist/index.js +1939 -0
- package/package.json +54 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1939 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/tokens.ts
|
|
42
|
+
import { getAddress, zeroAddress } from "viem";
|
|
43
|
+
import {
|
|
44
|
+
arbitrum as arbitrum2,
|
|
45
|
+
base as base2,
|
|
46
|
+
bsc as bsc2,
|
|
47
|
+
mainnet as mainnet2,
|
|
48
|
+
linea,
|
|
49
|
+
optimism as optimism2,
|
|
50
|
+
polygon as polygon2
|
|
51
|
+
} from "viem/chains";
|
|
52
|
+
|
|
53
|
+
// src/chains.ts
|
|
54
|
+
import { arbitrum, base, bsc, optimism, polygon, mainnet } from "viem/chains";
|
|
55
|
+
var supportedChains = [
|
|
56
|
+
arbitrum,
|
|
57
|
+
base,
|
|
58
|
+
bsc,
|
|
59
|
+
mainnet,
|
|
60
|
+
optimism,
|
|
61
|
+
polygon
|
|
62
|
+
];
|
|
63
|
+
function getChainById(chainId) {
|
|
64
|
+
const chain = supportedChains.find((c) => c.id === chainId);
|
|
65
|
+
if (!chain) throw new Error(`Chain ${chainId} not supported.`);
|
|
66
|
+
return chain;
|
|
67
|
+
}
|
|
68
|
+
function getChainExplorerByChainId(chainId) {
|
|
69
|
+
switch (chainId) {
|
|
70
|
+
case arbitrum.id:
|
|
71
|
+
return "https://arbiscan.io";
|
|
72
|
+
case base.id:
|
|
73
|
+
return "https://basescan.org";
|
|
74
|
+
case bsc.id:
|
|
75
|
+
return "https://bscscan.com";
|
|
76
|
+
case mainnet.id:
|
|
77
|
+
return "https://etherscan.io";
|
|
78
|
+
case optimism.id:
|
|
79
|
+
return "https://optimistic.etherscan.io";
|
|
80
|
+
case polygon.id:
|
|
81
|
+
return "https://polygonscan.com";
|
|
82
|
+
default:
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/types.ts
|
|
88
|
+
var TokenLogo = /* @__PURE__ */ ((TokenLogo2) => {
|
|
89
|
+
TokenLogo2["ETH"] = "https://pay.daimo.com/chain-logos/ethereum.png";
|
|
90
|
+
TokenLogo2["WETH"] = "https://pay.daimo.com/coin-logos/weth.png";
|
|
91
|
+
TokenLogo2["USDC"] = "https://pay.daimo.com/coin-logos/usdc.png";
|
|
92
|
+
TokenLogo2["EURC"] = "https://pay.daimo.com/coin-logos/eurc.png";
|
|
93
|
+
TokenLogo2["USDT"] = "https://pay.daimo.com/coin-logos/usdt.png";
|
|
94
|
+
TokenLogo2["DAI"] = "https://pay.daimo.com/coin-logos/dai.png";
|
|
95
|
+
TokenLogo2["POL"] = "https://pay.daimo.com/coin-logos/pol.png";
|
|
96
|
+
TokenLogo2["BNB"] = "https://pay.daimo.com/coin-logos/bnb.png";
|
|
97
|
+
return TokenLogo2;
|
|
98
|
+
})(TokenLogo || {});
|
|
99
|
+
var ConnectorType = /* @__PURE__ */ ((ConnectorType2) => {
|
|
100
|
+
ConnectorType2["SELF_CUSTODY"] = "Self-Custody";
|
|
101
|
+
ConnectorType2["CEX"] = "CEX";
|
|
102
|
+
return ConnectorType2;
|
|
103
|
+
})(ConnectorType || {});
|
|
104
|
+
var PolicyFlags = /* @__PURE__ */ ((PolicyFlags2) => {
|
|
105
|
+
PolicyFlags2["FOR_ALL_VALIDATION"] = "0x0000";
|
|
106
|
+
PolicyFlags2["NOT_FOR_VALIDATE_USEROP"] = "0x0001";
|
|
107
|
+
PolicyFlags2["NOT_FOR_VALIDATE_SIG"] = "0x0002";
|
|
108
|
+
return PolicyFlags2;
|
|
109
|
+
})(PolicyFlags || {});
|
|
110
|
+
|
|
111
|
+
// src/tokens.ts
|
|
112
|
+
var arbitrumETH = nativeETH(arbitrum2.id);
|
|
113
|
+
var arbitrumWETH = token({
|
|
114
|
+
chainId: arbitrum2.id,
|
|
115
|
+
address: getAddress("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"),
|
|
116
|
+
decimals: 18,
|
|
117
|
+
name: "Wrapped Ether",
|
|
118
|
+
symbol: "WETH",
|
|
119
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
120
|
+
});
|
|
121
|
+
var arbitrumUSDC = token({
|
|
122
|
+
chainId: arbitrum2.id,
|
|
123
|
+
address: getAddress("0xaf88d065e77c8cC2239327C5EDb3A432268e5831"),
|
|
124
|
+
name: "USD Coin",
|
|
125
|
+
symbol: "USDC",
|
|
126
|
+
fiatISO: "USD",
|
|
127
|
+
decimals: 6,
|
|
128
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
129
|
+
});
|
|
130
|
+
var arbitrumDAI = token({
|
|
131
|
+
chainId: arbitrum2.id,
|
|
132
|
+
address: getAddress("0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"),
|
|
133
|
+
decimals: 18,
|
|
134
|
+
fiatISO: "USD",
|
|
135
|
+
name: "Dai Stablecoin",
|
|
136
|
+
symbol: "DAI",
|
|
137
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
138
|
+
});
|
|
139
|
+
var arbitrumUSDT = token({
|
|
140
|
+
chainId: arbitrum2.id,
|
|
141
|
+
address: getAddress("0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"),
|
|
142
|
+
decimals: 6,
|
|
143
|
+
fiatISO: "USD",
|
|
144
|
+
name: "Tether USD",
|
|
145
|
+
symbol: "USDT",
|
|
146
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
147
|
+
});
|
|
148
|
+
var arbitrumUSDCe = token({
|
|
149
|
+
chainId: arbitrum2.id,
|
|
150
|
+
address: getAddress("0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8"),
|
|
151
|
+
decimals: 6,
|
|
152
|
+
fiatISO: "USD",
|
|
153
|
+
name: "Bridged USD Coin",
|
|
154
|
+
symbol: "USDCe",
|
|
155
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
156
|
+
});
|
|
157
|
+
var arbitrumTokens = [arbitrumUSDC, arbitrumUSDT];
|
|
158
|
+
var baseETH = nativeETH(base2.id);
|
|
159
|
+
var baseWETH = token({
|
|
160
|
+
chainId: base2.id,
|
|
161
|
+
address: getAddress("0x4200000000000000000000000000000000000006"),
|
|
162
|
+
decimals: 18,
|
|
163
|
+
name: "Wrapped Ether",
|
|
164
|
+
symbol: "WETH",
|
|
165
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
166
|
+
});
|
|
167
|
+
var baseUSDC = token({
|
|
168
|
+
chainId: base2.id,
|
|
169
|
+
address: getAddress("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"),
|
|
170
|
+
name: "USD Coin",
|
|
171
|
+
symbol: "USDC",
|
|
172
|
+
fiatISO: "USD",
|
|
173
|
+
decimals: 6,
|
|
174
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
175
|
+
});
|
|
176
|
+
var baseEURC = token({
|
|
177
|
+
chainId: base2.id,
|
|
178
|
+
address: getAddress("0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42"),
|
|
179
|
+
decimals: 6,
|
|
180
|
+
fiatISO: "EUR",
|
|
181
|
+
name: "EURC",
|
|
182
|
+
symbol: "EURC",
|
|
183
|
+
logoURI: "https://pay.daimo.com/coin-logos/eurc.png" /* EURC */
|
|
184
|
+
});
|
|
185
|
+
var baseUSDbC = token({
|
|
186
|
+
chainId: base2.id,
|
|
187
|
+
address: getAddress("0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA"),
|
|
188
|
+
name: "Bridged USD Coin",
|
|
189
|
+
symbol: "USDbC",
|
|
190
|
+
fiatISO: "USD",
|
|
191
|
+
decimals: 6,
|
|
192
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdbc.png"
|
|
193
|
+
});
|
|
194
|
+
var baseDAI = token({
|
|
195
|
+
chainId: base2.id,
|
|
196
|
+
address: getAddress("0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb"),
|
|
197
|
+
name: "Dai Stablecoin",
|
|
198
|
+
symbol: "DAI",
|
|
199
|
+
fiatISO: "USD",
|
|
200
|
+
decimals: 18,
|
|
201
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
202
|
+
});
|
|
203
|
+
var baseUSDT = token({
|
|
204
|
+
chainId: base2.id,
|
|
205
|
+
address: getAddress("0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2"),
|
|
206
|
+
name: "Tether USD",
|
|
207
|
+
symbol: "USDT",
|
|
208
|
+
fiatISO: "USD",
|
|
209
|
+
decimals: 6,
|
|
210
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
211
|
+
});
|
|
212
|
+
var baseTokens = [baseUSDC, baseUSDT];
|
|
213
|
+
var bscBNB = nativeToken({
|
|
214
|
+
chainId: bsc2.id,
|
|
215
|
+
name: "BNB",
|
|
216
|
+
symbol: "BNB",
|
|
217
|
+
logoURI: "https://pay.daimo.com/coin-logos/bnb.png" /* BNB */
|
|
218
|
+
});
|
|
219
|
+
var bscWBNB = token({
|
|
220
|
+
chainId: bsc2.id,
|
|
221
|
+
address: getAddress("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"),
|
|
222
|
+
decimals: 18,
|
|
223
|
+
name: "Wrapped BNB",
|
|
224
|
+
symbol: "WBNB",
|
|
225
|
+
logoURI: "https://pay.daimo.com/coin-logos/bnb.png" /* BNB */
|
|
226
|
+
});
|
|
227
|
+
var bscUSDC = token({
|
|
228
|
+
chainId: bsc2.id,
|
|
229
|
+
address: getAddress("0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d"),
|
|
230
|
+
decimals: 18,
|
|
231
|
+
fiatISO: "USD",
|
|
232
|
+
name: "USD Coin",
|
|
233
|
+
symbol: "USDC",
|
|
234
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
235
|
+
});
|
|
236
|
+
var bscUSDT = token({
|
|
237
|
+
chainId: bsc2.id,
|
|
238
|
+
address: getAddress("0x55d398326f99059fF775485246999027B3197955"),
|
|
239
|
+
decimals: 18,
|
|
240
|
+
fiatISO: "USD",
|
|
241
|
+
name: "Tether USD",
|
|
242
|
+
symbol: "USDT",
|
|
243
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
244
|
+
});
|
|
245
|
+
var bscTokens = [bscUSDT];
|
|
246
|
+
var ethereumETH = nativeETH(mainnet2.id);
|
|
247
|
+
var ethereumWETH = token({
|
|
248
|
+
chainId: mainnet2.id,
|
|
249
|
+
address: getAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
250
|
+
decimals: 18,
|
|
251
|
+
name: "Wrapped Ether",
|
|
252
|
+
symbol: "WETH",
|
|
253
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
254
|
+
});
|
|
255
|
+
var ethereumUSDC = token({
|
|
256
|
+
chainId: mainnet2.id,
|
|
257
|
+
address: getAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
|
|
258
|
+
decimals: 6,
|
|
259
|
+
fiatISO: "USD",
|
|
260
|
+
name: "USD Coin",
|
|
261
|
+
symbol: "USDC",
|
|
262
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
263
|
+
});
|
|
264
|
+
var ethereumDAI = token({
|
|
265
|
+
chainId: mainnet2.id,
|
|
266
|
+
address: getAddress("0x6B175474E89094C44Da98b954EedeAC495271d0F"),
|
|
267
|
+
decimals: 18,
|
|
268
|
+
fiatISO: "USD",
|
|
269
|
+
name: "Dai Stablecoin",
|
|
270
|
+
symbol: "DAI",
|
|
271
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
272
|
+
});
|
|
273
|
+
var ethereumUSDT = token({
|
|
274
|
+
chainId: mainnet2.id,
|
|
275
|
+
address: getAddress("0xdAC17F958D2ee523a2206206994597C13D831ec7"),
|
|
276
|
+
decimals: 6,
|
|
277
|
+
fiatISO: "USD",
|
|
278
|
+
name: "Tether USD",
|
|
279
|
+
symbol: "USDT",
|
|
280
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
281
|
+
});
|
|
282
|
+
var ethereumEURC = token({
|
|
283
|
+
chainId: mainnet2.id,
|
|
284
|
+
address: getAddress("0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c"),
|
|
285
|
+
decimals: 6,
|
|
286
|
+
fiatISO: "EUR",
|
|
287
|
+
name: "EURC",
|
|
288
|
+
symbol: "EURC",
|
|
289
|
+
logoURI: "https://pay.daimo.com/coin-logos/eurc.png" /* EURC */
|
|
290
|
+
});
|
|
291
|
+
var ethereumTokens = [ethereumUSDC, ethereumUSDT];
|
|
292
|
+
var lineaETH = nativeETH(linea.id);
|
|
293
|
+
var lineaWETH = token({
|
|
294
|
+
chainId: linea.id,
|
|
295
|
+
address: getAddress("0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f"),
|
|
296
|
+
decimals: 18,
|
|
297
|
+
name: "Wrapped Ether",
|
|
298
|
+
symbol: "WETH",
|
|
299
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
300
|
+
});
|
|
301
|
+
var lineaUSDC = token({
|
|
302
|
+
chainId: linea.id,
|
|
303
|
+
address: getAddress("0x176211869cA2b568f2A7D4EE941E073a821EE1ff"),
|
|
304
|
+
decimals: 6,
|
|
305
|
+
fiatISO: "USD",
|
|
306
|
+
name: "USD Coin",
|
|
307
|
+
symbol: "USDC",
|
|
308
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
309
|
+
});
|
|
310
|
+
var lineaDAI = token({
|
|
311
|
+
chainId: linea.id,
|
|
312
|
+
address: getAddress("0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5"),
|
|
313
|
+
decimals: 18,
|
|
314
|
+
fiatISO: "USD",
|
|
315
|
+
name: "Dai Stablecoin",
|
|
316
|
+
symbol: "DAI",
|
|
317
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
318
|
+
});
|
|
319
|
+
var optimismETH = nativeETH(optimism2.id);
|
|
320
|
+
var optimismWETH = token({
|
|
321
|
+
chainId: optimism2.id,
|
|
322
|
+
address: getAddress("0x4200000000000000000000000000000000000006"),
|
|
323
|
+
decimals: 18,
|
|
324
|
+
name: "Wrapped Ether",
|
|
325
|
+
symbol: "WETH",
|
|
326
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
327
|
+
});
|
|
328
|
+
var optimismUSDC = token({
|
|
329
|
+
chainId: optimism2.id,
|
|
330
|
+
address: getAddress("0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85"),
|
|
331
|
+
decimals: 6,
|
|
332
|
+
fiatISO: "USD",
|
|
333
|
+
name: "USD Coin",
|
|
334
|
+
symbol: "USDC",
|
|
335
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
336
|
+
});
|
|
337
|
+
var optimismDAI = token({
|
|
338
|
+
chainId: optimism2.id,
|
|
339
|
+
address: getAddress("0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"),
|
|
340
|
+
decimals: 18,
|
|
341
|
+
fiatISO: "USD",
|
|
342
|
+
name: "Dai Stablecoin",
|
|
343
|
+
symbol: "DAI",
|
|
344
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
345
|
+
});
|
|
346
|
+
var optimismUSDT = token({
|
|
347
|
+
chainId: optimism2.id,
|
|
348
|
+
address: getAddress("0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"),
|
|
349
|
+
decimals: 6,
|
|
350
|
+
fiatISO: "USD",
|
|
351
|
+
name: "Tether USD",
|
|
352
|
+
symbol: "USDT",
|
|
353
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
354
|
+
});
|
|
355
|
+
var optimismUSDCe = token({
|
|
356
|
+
chainId: optimism2.id,
|
|
357
|
+
address: getAddress("0x7F5c764cBc14f9669B88837ca1490cCa17c31607"),
|
|
358
|
+
decimals: 6,
|
|
359
|
+
fiatISO: "USD",
|
|
360
|
+
name: "Bridged USD Coin",
|
|
361
|
+
symbol: "USDCe",
|
|
362
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
363
|
+
});
|
|
364
|
+
var optimismTokens = [optimismUSDC, optimismUSDT];
|
|
365
|
+
var polygonPOL = nativeToken({
|
|
366
|
+
chainId: polygon2.id,
|
|
367
|
+
name: "Polygon",
|
|
368
|
+
symbol: "POL",
|
|
369
|
+
logoURI: "https://pay.daimo.com/coin-logos/pol.png" /* POL */
|
|
370
|
+
});
|
|
371
|
+
var polygonWPOL = token({
|
|
372
|
+
chainId: polygon2.id,
|
|
373
|
+
address: getAddress("0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270"),
|
|
374
|
+
decimals: 18,
|
|
375
|
+
name: "Wrapped Polygon",
|
|
376
|
+
symbol: "WPOL",
|
|
377
|
+
logoURI: "https://pay.daimo.com/coin-logos/pol.png" /* POL */
|
|
378
|
+
});
|
|
379
|
+
var polygonWETH = token({
|
|
380
|
+
chainId: polygon2.id,
|
|
381
|
+
address: getAddress("0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619"),
|
|
382
|
+
decimals: 18,
|
|
383
|
+
name: "Wrapped Ether",
|
|
384
|
+
symbol: "WETH",
|
|
385
|
+
logoURI: "https://pay.daimo.com/coin-logos/weth.png" /* WETH */
|
|
386
|
+
});
|
|
387
|
+
var polygonUSDC = token({
|
|
388
|
+
chainId: polygon2.id,
|
|
389
|
+
address: getAddress("0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"),
|
|
390
|
+
decimals: 6,
|
|
391
|
+
fiatISO: "USD",
|
|
392
|
+
name: "USD Coin",
|
|
393
|
+
symbol: "USDC",
|
|
394
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
395
|
+
});
|
|
396
|
+
var polygonDAI = token({
|
|
397
|
+
chainId: polygon2.id,
|
|
398
|
+
address: getAddress("0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063"),
|
|
399
|
+
decimals: 18,
|
|
400
|
+
fiatISO: "USD",
|
|
401
|
+
name: "Dai Stablecoin",
|
|
402
|
+
symbol: "DAI",
|
|
403
|
+
logoURI: "https://pay.daimo.com/coin-logos/dai.png" /* DAI */
|
|
404
|
+
});
|
|
405
|
+
var polygonUSDT = token({
|
|
406
|
+
chainId: polygon2.id,
|
|
407
|
+
address: getAddress("0xc2132D05D31c914a87C6611C10748AEb04B58e8F"),
|
|
408
|
+
decimals: 6,
|
|
409
|
+
fiatISO: "USD",
|
|
410
|
+
name: "Tether USD",
|
|
411
|
+
symbol: "USDT",
|
|
412
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdt.png" /* USDT */
|
|
413
|
+
});
|
|
414
|
+
var polygonUSDCe = token({
|
|
415
|
+
chainId: polygon2.id,
|
|
416
|
+
address: getAddress("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"),
|
|
417
|
+
decimals: 6,
|
|
418
|
+
fiatISO: "USD",
|
|
419
|
+
name: "USD Coin (PoS)",
|
|
420
|
+
symbol: "USDCe",
|
|
421
|
+
logoURI: "https://pay.daimo.com/coin-logos/usdc.png" /* USDC */
|
|
422
|
+
});
|
|
423
|
+
var polygonTokens = [polygonUSDC, polygonUSDT];
|
|
424
|
+
var supportedTokensByChain = /* @__PURE__ */ new Map([
|
|
425
|
+
[arbitrum2.id, arbitrumTokens],
|
|
426
|
+
//done
|
|
427
|
+
[base2.id, baseTokens],
|
|
428
|
+
//done
|
|
429
|
+
[bsc2.id, bscTokens],
|
|
430
|
+
//done
|
|
431
|
+
[mainnet2.id, ethereumTokens],
|
|
432
|
+
//done
|
|
433
|
+
[optimism2.id, optimismTokens],
|
|
434
|
+
//done
|
|
435
|
+
[polygon2.id, polygonTokens]
|
|
436
|
+
//done
|
|
437
|
+
]);
|
|
438
|
+
function nativeETH(chainId) {
|
|
439
|
+
return nativeToken({
|
|
440
|
+
chainId,
|
|
441
|
+
name: "Ether",
|
|
442
|
+
symbol: "ETH",
|
|
443
|
+
logoURI: "https://pay.daimo.com/chain-logos/ethereum.png" /* ETH */
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
function nativeToken({
|
|
447
|
+
chainId,
|
|
448
|
+
name,
|
|
449
|
+
symbol,
|
|
450
|
+
logoURI,
|
|
451
|
+
address = zeroAddress,
|
|
452
|
+
decimals = 18
|
|
453
|
+
}) {
|
|
454
|
+
return {
|
|
455
|
+
chainId,
|
|
456
|
+
address,
|
|
457
|
+
name,
|
|
458
|
+
decimals,
|
|
459
|
+
symbol,
|
|
460
|
+
logoURI,
|
|
461
|
+
logoSourceURI: logoURI
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function token({
|
|
465
|
+
chainId,
|
|
466
|
+
address,
|
|
467
|
+
name,
|
|
468
|
+
symbol,
|
|
469
|
+
decimals,
|
|
470
|
+
fiatISO,
|
|
471
|
+
logoURI
|
|
472
|
+
}) {
|
|
473
|
+
return {
|
|
474
|
+
chainId,
|
|
475
|
+
address,
|
|
476
|
+
name,
|
|
477
|
+
symbol,
|
|
478
|
+
decimals,
|
|
479
|
+
fiatISO,
|
|
480
|
+
logoURI,
|
|
481
|
+
logoSourceURI: logoURI
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function getTokenByChainIdAndSymbol(chainId, symbol) {
|
|
485
|
+
const chain = getChainById(chainId);
|
|
486
|
+
if (!chain) throw new Error(`Chain ${chainId} not supported.`);
|
|
487
|
+
const tokens = supportedTokensByChain.get(chain.id);
|
|
488
|
+
if (!tokens) throw new Error(`Tokens not found for chain ${chainId}.`);
|
|
489
|
+
const token2 = tokens.find((t) => t.symbol === symbol);
|
|
490
|
+
if (!token2)
|
|
491
|
+
throw new Error(`Token ${symbol} not found for chain ${chainId}.`);
|
|
492
|
+
return token2;
|
|
493
|
+
}
|
|
494
|
+
var tokensCommonSymbols = [
|
|
495
|
+
"USDC",
|
|
496
|
+
"USDT",
|
|
497
|
+
"DAI",
|
|
498
|
+
"ETH",
|
|
499
|
+
"WETH",
|
|
500
|
+
"BNB",
|
|
501
|
+
"WBNB",
|
|
502
|
+
"USDCe",
|
|
503
|
+
"USDbC",
|
|
504
|
+
"EURC",
|
|
505
|
+
"POL",
|
|
506
|
+
"WPOL"
|
|
507
|
+
];
|
|
508
|
+
|
|
509
|
+
// src/deposit.ts
|
|
510
|
+
import { toHex as toHex2, zeroAddress as zeroAddress4 } from "viem";
|
|
511
|
+
|
|
512
|
+
// src/account.ts
|
|
513
|
+
import {
|
|
514
|
+
http as http2,
|
|
515
|
+
getAddress as getAddress2,
|
|
516
|
+
parseAbi as parseAbi2
|
|
517
|
+
} from "viem";
|
|
518
|
+
import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
|
|
519
|
+
import {
|
|
520
|
+
createPaymasterClient,
|
|
521
|
+
formatUserOperationRequest
|
|
522
|
+
} from "viem/account-abstraction";
|
|
523
|
+
import { addressToEmptyAccount, createKernelAccount as createKernelAccount2 } from "@zerodev/sdk";
|
|
524
|
+
import { getEntryPoint, KERNEL_V3_1 } from "@zerodev/sdk/constants";
|
|
525
|
+
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator";
|
|
526
|
+
import { createSmartAccountClient } from "permissionless";
|
|
527
|
+
import { createPimlicoClient } from "permissionless/clients/pimlico";
|
|
528
|
+
import { prepareUserOperationForErc20Paymaster } from "permissionless/experimental/pimlico";
|
|
529
|
+
|
|
530
|
+
// src/rpc.ts
|
|
531
|
+
function getRpcByChainId(chainId) {
|
|
532
|
+
switch (chainId) {
|
|
533
|
+
case 1:
|
|
534
|
+
return "https://eth-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
535
|
+
case 10:
|
|
536
|
+
return "https://opt-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
537
|
+
case 56:
|
|
538
|
+
return "https://bsc-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
539
|
+
case 137:
|
|
540
|
+
return "https://polygon-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
541
|
+
case 8453:
|
|
542
|
+
return "https://base-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
543
|
+
case 42161:
|
|
544
|
+
return "https://arbitrum-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
545
|
+
case 59144:
|
|
546
|
+
return "https://linea-mainnet.g.alchemy.com/v2/2uxlNSyeU1IcP7HMKteJM21td0IAHroW";
|
|
547
|
+
default:
|
|
548
|
+
return void 0;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function getPimlicoRpcByChainId(chainId) {
|
|
552
|
+
switch (chainId) {
|
|
553
|
+
case 1:
|
|
554
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
555
|
+
case 10:
|
|
556
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
557
|
+
case 56:
|
|
558
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
559
|
+
case 137:
|
|
560
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
561
|
+
case 8453:
|
|
562
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
563
|
+
case 42161:
|
|
564
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
565
|
+
case 59144:
|
|
566
|
+
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=pim_kJYDesTFhp9siAfj9W868S`;
|
|
567
|
+
default:
|
|
568
|
+
return void 0;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/viemClient.ts
|
|
573
|
+
import {
|
|
574
|
+
http,
|
|
575
|
+
createPublicClient,
|
|
576
|
+
parseAbi,
|
|
577
|
+
encodeFunctionData
|
|
578
|
+
} from "viem";
|
|
579
|
+
var ViemClient = class {
|
|
580
|
+
constructor(chainId, walletClient) {
|
|
581
|
+
this.chainId = chainId;
|
|
582
|
+
this.walletClient = walletClient;
|
|
583
|
+
}
|
|
584
|
+
publicClient() {
|
|
585
|
+
return createPublicClient({
|
|
586
|
+
chain: getChainById(this.chainId),
|
|
587
|
+
transport: http(getRpcByChainId(this.chainId))
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
checkTokenAllowance(token2, owner, spender) {
|
|
591
|
+
return __async(this, null, function* () {
|
|
592
|
+
const allowance = yield this.publicClient().readContract({
|
|
593
|
+
address: token2.address,
|
|
594
|
+
abi: parseAbi([
|
|
595
|
+
"function allowance(address,address) view returns (uint256)"
|
|
596
|
+
]),
|
|
597
|
+
functionName: "allowance",
|
|
598
|
+
args: [owner, spender]
|
|
599
|
+
});
|
|
600
|
+
return allowance;
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
checkAndApproveToken(token2, spender, amount) {
|
|
604
|
+
return __async(this, null, function* () {
|
|
605
|
+
var _a;
|
|
606
|
+
if (this.walletClient === void 0) {
|
|
607
|
+
throw new Error("Wallet client is required");
|
|
608
|
+
}
|
|
609
|
+
const signerAddress = (_a = this.walletClient.account) == null ? void 0 : _a.address;
|
|
610
|
+
console.log("signerAddress", signerAddress);
|
|
611
|
+
if (signerAddress === void 0) {
|
|
612
|
+
throw new Error("Signer address is required");
|
|
613
|
+
}
|
|
614
|
+
const allowance = yield this.checkTokenAllowance(
|
|
615
|
+
token2,
|
|
616
|
+
signerAddress,
|
|
617
|
+
spender
|
|
618
|
+
);
|
|
619
|
+
if (allowance < amount) {
|
|
620
|
+
const txn = yield this.walletClient.sendTransaction({
|
|
621
|
+
to: token2.address,
|
|
622
|
+
account: signerAddress,
|
|
623
|
+
chain: getChainById(token2.chainId),
|
|
624
|
+
value: BigInt(0),
|
|
625
|
+
data: encodeFunctionData({
|
|
626
|
+
abi: parseAbi(["function approve(address,uint)"]),
|
|
627
|
+
functionName: "approve",
|
|
628
|
+
args: [spender, amount]
|
|
629
|
+
})
|
|
630
|
+
});
|
|
631
|
+
const receipt = yield this.publicClient().waitForTransactionReceipt({
|
|
632
|
+
hash: txn,
|
|
633
|
+
confirmations: token2.chainId === 1 ? 1 : 5
|
|
634
|
+
});
|
|
635
|
+
return amount;
|
|
636
|
+
}
|
|
637
|
+
return allowance;
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/utils.ts
|
|
643
|
+
import {
|
|
644
|
+
constants,
|
|
645
|
+
fixSignedData,
|
|
646
|
+
toSigner,
|
|
647
|
+
KernelV3AccountAbi,
|
|
648
|
+
KernelFactoryStakerAbi,
|
|
649
|
+
KernelV3FactoryAbi,
|
|
650
|
+
KernelV3_1AccountAbi,
|
|
651
|
+
createKernelAccount
|
|
652
|
+
} from "@zerodev/sdk";
|
|
653
|
+
import {
|
|
654
|
+
toKernelPluginManager
|
|
655
|
+
} from "@zerodev/sdk/accounts";
|
|
656
|
+
import {
|
|
657
|
+
concat,
|
|
658
|
+
encodeAbiParameters,
|
|
659
|
+
keccak256,
|
|
660
|
+
slice,
|
|
661
|
+
zeroAddress as zeroAddress2,
|
|
662
|
+
decodeFunctionData
|
|
663
|
+
} from "viem";
|
|
664
|
+
import {
|
|
665
|
+
toAccount,
|
|
666
|
+
privateKeyToAccount
|
|
667
|
+
} from "viem/accounts";
|
|
668
|
+
import { getChainId, readContract } from "viem/actions";
|
|
669
|
+
import { getAction } from "viem/utils";
|
|
670
|
+
import {
|
|
671
|
+
getUserOperationHash
|
|
672
|
+
} from "viem/account-abstraction";
|
|
673
|
+
import {
|
|
674
|
+
toCallPolicy,
|
|
675
|
+
toGasPolicy,
|
|
676
|
+
toRateLimitPolicy,
|
|
677
|
+
toSignatureCallerPolicy,
|
|
678
|
+
toSudoPolicy,
|
|
679
|
+
toTimestampPolicy
|
|
680
|
+
} from "@zerodev/permissions/policies";
|
|
681
|
+
import { coerce, gt } from "semver";
|
|
682
|
+
var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
|
|
683
|
+
var toSignerId = (signer) => {
|
|
684
|
+
return encodeAbiParameters(
|
|
685
|
+
[{ name: "signerData", type: "bytes" }],
|
|
686
|
+
[concat([signer.signerContractAddress, signer.getSignerData()])]
|
|
687
|
+
);
|
|
688
|
+
};
|
|
689
|
+
function toECDSASigner(_0) {
|
|
690
|
+
return __async(this, arguments, function* (signer, signerContractAddress = ECDSA_SIGNER_CONTRACT) {
|
|
691
|
+
const viemSigner = yield toSigner({ signer });
|
|
692
|
+
const account = toAccount({
|
|
693
|
+
address: viemSigner.address,
|
|
694
|
+
signMessage(_02) {
|
|
695
|
+
return __async(this, arguments, function* ({ message }) {
|
|
696
|
+
return fixSignedData(yield viemSigner.signMessage({ message }));
|
|
697
|
+
});
|
|
698
|
+
},
|
|
699
|
+
signTransaction(_, __) {
|
|
700
|
+
return __async(this, null, function* () {
|
|
701
|
+
throw new Error("Smart account signer doesn't need to sign transactions");
|
|
702
|
+
});
|
|
703
|
+
},
|
|
704
|
+
signTypedData(typedData) {
|
|
705
|
+
return __async(this, null, function* () {
|
|
706
|
+
return fixSignedData(
|
|
707
|
+
yield viemSigner.signTypedData(__spreadValues({}, typedData))
|
|
708
|
+
);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
return {
|
|
713
|
+
account,
|
|
714
|
+
signerContractAddress,
|
|
715
|
+
getSignerData: () => {
|
|
716
|
+
return viemSigner.address;
|
|
717
|
+
},
|
|
718
|
+
getDummySignature: () => constants.DUMMY_ECDSA_SIG
|
|
719
|
+
};
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
var toPolicyId = (policies) => {
|
|
723
|
+
return encodeAbiParameters(
|
|
724
|
+
[{ name: "policiesData", type: "bytes[]" }],
|
|
725
|
+
[
|
|
726
|
+
policies.map(
|
|
727
|
+
(policy) => concat([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
|
|
728
|
+
)
|
|
729
|
+
]
|
|
730
|
+
);
|
|
731
|
+
};
|
|
732
|
+
function toPermissionValidator(_0, _1) {
|
|
733
|
+
return __async(this, arguments, function* (client, {
|
|
734
|
+
signer,
|
|
735
|
+
policies,
|
|
736
|
+
entryPoint,
|
|
737
|
+
kernelVersion: _,
|
|
738
|
+
flag = "0x0000" /* FOR_ALL_VALIDATION */
|
|
739
|
+
}) {
|
|
740
|
+
const chainId = client.chain ? client.chain.id : yield getChainId(client);
|
|
741
|
+
if (entryPoint.version !== "0.7") {
|
|
742
|
+
throw new Error("Only EntryPoint 0.7 is supported");
|
|
743
|
+
}
|
|
744
|
+
const getEnableData = (_kernelAccountAddress) => __async(null, null, function* () {
|
|
745
|
+
const enableData = encodeAbiParameters(
|
|
746
|
+
[{ name: "policyAndSignerData", type: "bytes[]" }],
|
|
747
|
+
[
|
|
748
|
+
[
|
|
749
|
+
...policies.map(
|
|
750
|
+
(policy) => concat([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
|
|
751
|
+
),
|
|
752
|
+
concat([flag, signer.signerContractAddress, signer.getSignerData()])
|
|
753
|
+
]
|
|
754
|
+
]
|
|
755
|
+
);
|
|
756
|
+
return enableData;
|
|
757
|
+
});
|
|
758
|
+
const getPermissionId = () => {
|
|
759
|
+
const pIdData = encodeAbiParameters(
|
|
760
|
+
[{ name: "policyAndSignerData", type: "bytes[]" }],
|
|
761
|
+
[[toPolicyId(policies), flag, toSignerId(signer)]]
|
|
762
|
+
);
|
|
763
|
+
return slice(keccak256(pIdData), 0, 4);
|
|
764
|
+
};
|
|
765
|
+
return __spreadProps(__spreadValues({}, signer.account), {
|
|
766
|
+
supportedKernelVersions: ">=0.3.0",
|
|
767
|
+
validatorType: "PERMISSION",
|
|
768
|
+
address: zeroAddress2,
|
|
769
|
+
source: "PermissionValidator",
|
|
770
|
+
getEnableData,
|
|
771
|
+
getIdentifier: getPermissionId,
|
|
772
|
+
signMessage: (_02) => __async(null, [_02], function* ({ message }) {
|
|
773
|
+
return concat(["0xff", yield signer.account.signMessage({ message })]);
|
|
774
|
+
}),
|
|
775
|
+
signTypedData: (typedData) => __async(null, null, function* () {
|
|
776
|
+
return concat(["0xff", yield signer.account.signTypedData(typedData)]);
|
|
777
|
+
}),
|
|
778
|
+
signUserOperation: (userOperation) => __async(null, null, function* () {
|
|
779
|
+
const userOpHash = getUserOperationHash({
|
|
780
|
+
userOperation: __spreadProps(__spreadValues({}, userOperation), {
|
|
781
|
+
signature: "0x"
|
|
782
|
+
}),
|
|
783
|
+
entryPointAddress: entryPoint.address,
|
|
784
|
+
entryPointVersion: entryPoint.version,
|
|
785
|
+
chainId
|
|
786
|
+
});
|
|
787
|
+
const signature = yield signer.account.signMessage({
|
|
788
|
+
message: { raw: userOpHash }
|
|
789
|
+
});
|
|
790
|
+
return concat(["0xff", signature]);
|
|
791
|
+
}),
|
|
792
|
+
getNonceKey(_accountAddress, customNonceKey) {
|
|
793
|
+
return __async(this, null, function* () {
|
|
794
|
+
if (customNonceKey) {
|
|
795
|
+
return customNonceKey;
|
|
796
|
+
}
|
|
797
|
+
return BigInt(0);
|
|
798
|
+
});
|
|
799
|
+
},
|
|
800
|
+
getStubSignature(_userOperation) {
|
|
801
|
+
return __async(this, null, function* () {
|
|
802
|
+
return concat(["0xff", signer.getDummySignature()]);
|
|
803
|
+
});
|
|
804
|
+
},
|
|
805
|
+
getPluginSerializationParams: () => {
|
|
806
|
+
return {
|
|
807
|
+
policies
|
|
808
|
+
};
|
|
809
|
+
},
|
|
810
|
+
isEnabled: (kernelAccountAddress, _selector) => __async(null, null, function* () {
|
|
811
|
+
try {
|
|
812
|
+
const permissionConfig = yield getAction(
|
|
813
|
+
client,
|
|
814
|
+
readContract,
|
|
815
|
+
"readContract"
|
|
816
|
+
)({
|
|
817
|
+
abi: KernelV3AccountAbi,
|
|
818
|
+
address: kernelAccountAddress,
|
|
819
|
+
functionName: "permissionConfig",
|
|
820
|
+
args: [getPermissionId()]
|
|
821
|
+
});
|
|
822
|
+
return permissionConfig.signer === signer.signerContractAddress;
|
|
823
|
+
} catch (error) {
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
})
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
function bytesToBase64(bytes) {
|
|
831
|
+
const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join("");
|
|
832
|
+
return btoa(binString);
|
|
833
|
+
}
|
|
834
|
+
function isPermissionValidatorPlugin(plugin) {
|
|
835
|
+
return (plugin == null ? void 0 : plugin.getPluginSerializationParams) !== void 0;
|
|
836
|
+
}
|
|
837
|
+
var serializePermissionAccountParams = (params) => {
|
|
838
|
+
const replacer = (_, value) => {
|
|
839
|
+
if (typeof value === "bigint") {
|
|
840
|
+
return value.toString();
|
|
841
|
+
}
|
|
842
|
+
return value;
|
|
843
|
+
};
|
|
844
|
+
const jsonString = JSON.stringify(params, replacer);
|
|
845
|
+
const uint8Array = new TextEncoder().encode(jsonString);
|
|
846
|
+
const base64String = bytesToBase64(uint8Array);
|
|
847
|
+
return base64String;
|
|
848
|
+
};
|
|
849
|
+
var serializePermissionAccount = (account, privateKey, enableSignature, eip7702Auth) => __async(null, null, function* () {
|
|
850
|
+
if (!isPermissionValidatorPlugin(account.kernelPluginManager))
|
|
851
|
+
throw new Error("Account plugin is not a permission validator");
|
|
852
|
+
const permissionParams = account.kernelPluginManager.getPluginSerializationParams();
|
|
853
|
+
const action = account.kernelPluginManager.getAction();
|
|
854
|
+
const validityData = account.kernelPluginManager.getValidityData();
|
|
855
|
+
const _enableSignature = enableSignature != null ? enableSignature : yield account.kernelPluginManager.getPluginEnableSignature(
|
|
856
|
+
account.address
|
|
857
|
+
);
|
|
858
|
+
const _eip7702Auth = account.authorization ? eip7702Auth != null ? eip7702Auth : yield account == null ? void 0 : account.eip7702Auth : void 0;
|
|
859
|
+
const accountParams = {
|
|
860
|
+
initCode: yield account.generateInitCode(),
|
|
861
|
+
accountAddress: account.address
|
|
862
|
+
};
|
|
863
|
+
const paramsToBeSerialized = {
|
|
864
|
+
permissionParams,
|
|
865
|
+
action,
|
|
866
|
+
validityData,
|
|
867
|
+
accountParams,
|
|
868
|
+
enableSignature: _enableSignature,
|
|
869
|
+
privateKey,
|
|
870
|
+
eip7702Auth: _eip7702Auth
|
|
871
|
+
};
|
|
872
|
+
return serializePermissionAccountParams(paramsToBeSerialized);
|
|
873
|
+
});
|
|
874
|
+
var isKernelVersionAfter = (kernelVersion, version) => {
|
|
875
|
+
const coercedKernelVersion = coerce(kernelVersion);
|
|
876
|
+
if (!coercedKernelVersion) return false;
|
|
877
|
+
return gt(coercedKernelVersion, version);
|
|
878
|
+
};
|
|
879
|
+
function base64ToBytes(base64) {
|
|
880
|
+
const binString = atob(base64);
|
|
881
|
+
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
882
|
+
}
|
|
883
|
+
var deserializePermissionAccountParams = (params) => {
|
|
884
|
+
const uint8Array = base64ToBytes(params);
|
|
885
|
+
const jsonString = new TextDecoder().decode(uint8Array);
|
|
886
|
+
return JSON.parse(jsonString);
|
|
887
|
+
};
|
|
888
|
+
var deserializePermissionAccount = (client, entryPoint, kernelVersion, modularPermissionAccountParams, modularSigner) => __async(null, null, function* () {
|
|
889
|
+
var _a;
|
|
890
|
+
if (entryPoint.version !== "0.7") {
|
|
891
|
+
throw new Error("Only EntryPoint 0.7 is supported");
|
|
892
|
+
}
|
|
893
|
+
const params = deserializePermissionAccountParams(
|
|
894
|
+
modularPermissionAccountParams
|
|
895
|
+
);
|
|
896
|
+
let signer;
|
|
897
|
+
if (params.privateKey)
|
|
898
|
+
signer = yield toECDSASigner(privateKeyToAccount(params.privateKey));
|
|
899
|
+
else if (modularSigner) signer = modularSigner;
|
|
900
|
+
else throw new Error("No signer or serialized sessionKey provided");
|
|
901
|
+
const modularPermissionPlugin = yield toPermissionValidator(client, {
|
|
902
|
+
signer,
|
|
903
|
+
policies: yield Promise.all(
|
|
904
|
+
((_a = params.permissionParams.policies) == null ? void 0 : _a.map(
|
|
905
|
+
(policy) => createPolicyFromParams(policy)
|
|
906
|
+
)) || []
|
|
907
|
+
),
|
|
908
|
+
entryPoint,
|
|
909
|
+
kernelVersion
|
|
910
|
+
});
|
|
911
|
+
const { index, validatorInitData, useMetaFactory } = decodeParamsFromInitCode(
|
|
912
|
+
params.accountParams.initCode,
|
|
913
|
+
kernelVersion
|
|
914
|
+
);
|
|
915
|
+
const kernelPluginManager = yield toKernelPluginManager(client, __spreadValues({
|
|
916
|
+
regular: modularPermissionPlugin,
|
|
917
|
+
pluginEnableSignature: params.enableSignature,
|
|
918
|
+
validatorInitData,
|
|
919
|
+
action: params.action,
|
|
920
|
+
entryPoint,
|
|
921
|
+
kernelVersion
|
|
922
|
+
}, params.validityData));
|
|
923
|
+
return createKernelAccount(client, {
|
|
924
|
+
entryPoint,
|
|
925
|
+
kernelVersion,
|
|
926
|
+
plugins: kernelPluginManager,
|
|
927
|
+
index,
|
|
928
|
+
address: params.accountParams.accountAddress,
|
|
929
|
+
useMetaFactory,
|
|
930
|
+
eip7702Auth: params.eip7702Auth
|
|
931
|
+
});
|
|
932
|
+
});
|
|
933
|
+
var createPolicyFromParams = (policy) => __async(null, null, function* () {
|
|
934
|
+
switch (policy.policyParams.type) {
|
|
935
|
+
case "call":
|
|
936
|
+
return yield toCallPolicy(policy.policyParams);
|
|
937
|
+
case "gas":
|
|
938
|
+
return yield toGasPolicy(policy.policyParams);
|
|
939
|
+
case "rate-limit":
|
|
940
|
+
return yield toRateLimitPolicy(policy.policyParams);
|
|
941
|
+
case "signature-caller":
|
|
942
|
+
return yield toSignatureCallerPolicy(policy.policyParams);
|
|
943
|
+
case "sudo":
|
|
944
|
+
return yield toSudoPolicy(policy.policyParams);
|
|
945
|
+
case "timestamp":
|
|
946
|
+
return yield toTimestampPolicy(policy.policyParams);
|
|
947
|
+
default:
|
|
948
|
+
throw new Error("Unsupported policy type");
|
|
949
|
+
}
|
|
950
|
+
});
|
|
951
|
+
var decodeParamsFromInitCode = (initCode, kernelVersion) => {
|
|
952
|
+
let index;
|
|
953
|
+
let validatorInitData;
|
|
954
|
+
let deployWithFactoryFunctionData;
|
|
955
|
+
let useMetaFactory = true;
|
|
956
|
+
if (initCode === "0x") {
|
|
957
|
+
return {
|
|
958
|
+
index: void 0,
|
|
959
|
+
validatorInitData: void 0,
|
|
960
|
+
useMetaFactory: true
|
|
961
|
+
};
|
|
962
|
+
}
|
|
963
|
+
try {
|
|
964
|
+
deployWithFactoryFunctionData = decodeFunctionData({
|
|
965
|
+
abi: KernelFactoryStakerAbi,
|
|
966
|
+
data: initCode
|
|
967
|
+
});
|
|
968
|
+
} catch (error) {
|
|
969
|
+
deployWithFactoryFunctionData = decodeFunctionData({
|
|
970
|
+
abi: KernelV3FactoryAbi,
|
|
971
|
+
data: initCode
|
|
972
|
+
});
|
|
973
|
+
useMetaFactory = false;
|
|
974
|
+
}
|
|
975
|
+
if (!deployWithFactoryFunctionData) throw new Error("Invalid initCode");
|
|
976
|
+
if (deployWithFactoryFunctionData.functionName === "deployWithFactory") {
|
|
977
|
+
index = BigInt(deployWithFactoryFunctionData.args[2]);
|
|
978
|
+
let initializeFunctionData;
|
|
979
|
+
if (kernelVersion === "0.3.0") {
|
|
980
|
+
initializeFunctionData = decodeFunctionData({
|
|
981
|
+
abi: KernelV3AccountAbi,
|
|
982
|
+
data: deployWithFactoryFunctionData.args[1]
|
|
983
|
+
});
|
|
984
|
+
} else {
|
|
985
|
+
initializeFunctionData = decodeFunctionData({
|
|
986
|
+
abi: KernelV3_1AccountAbi,
|
|
987
|
+
data: deployWithFactoryFunctionData.args[1]
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
if (!initializeFunctionData) throw new Error("Invalid initCode");
|
|
991
|
+
if (initializeFunctionData.functionName === "initialize") {
|
|
992
|
+
validatorInitData = {
|
|
993
|
+
validatorAddress: initializeFunctionData.args[0],
|
|
994
|
+
identifier: initializeFunctionData.args[0],
|
|
995
|
+
enableData: initializeFunctionData.args[2],
|
|
996
|
+
initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
} else if (deployWithFactoryFunctionData.functionName === "createAccount") {
|
|
1000
|
+
index = BigInt(deployWithFactoryFunctionData.args[1]);
|
|
1001
|
+
let initializeFunctionData;
|
|
1002
|
+
if (kernelVersion === "0.3.0") {
|
|
1003
|
+
initializeFunctionData = decodeFunctionData({
|
|
1004
|
+
abi: KernelV3AccountAbi,
|
|
1005
|
+
data: deployWithFactoryFunctionData.args[0]
|
|
1006
|
+
});
|
|
1007
|
+
} else {
|
|
1008
|
+
initializeFunctionData = decodeFunctionData({
|
|
1009
|
+
abi: KernelV3_1AccountAbi,
|
|
1010
|
+
data: deployWithFactoryFunctionData.args[0]
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
if (!initializeFunctionData) throw new Error("Invalid initCode");
|
|
1014
|
+
if (initializeFunctionData.functionName === "initialize") {
|
|
1015
|
+
validatorInitData = {
|
|
1016
|
+
validatorAddress: initializeFunctionData.args[0],
|
|
1017
|
+
identifier: initializeFunctionData.args[0],
|
|
1018
|
+
enableData: initializeFunctionData.args[2],
|
|
1019
|
+
initConfig: isKernelVersionAfter(kernelVersion, "0.3.1") && Array.isArray(initializeFunctionData.args[4]) ? [...initializeFunctionData.args[4]] : void 0
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (index === void 0 || validatorInitData === void 0)
|
|
1024
|
+
throw new Error("Invalid initCode");
|
|
1025
|
+
return { index, validatorInitData, useMetaFactory };
|
|
1026
|
+
};
|
|
1027
|
+
var getPeriodInterval = (periodUnit) => {
|
|
1028
|
+
switch (periodUnit) {
|
|
1029
|
+
case "5mins":
|
|
1030
|
+
return 5 * 60;
|
|
1031
|
+
case "day":
|
|
1032
|
+
return 24 * 60 * 60;
|
|
1033
|
+
case "week":
|
|
1034
|
+
return 7 * 24 * 60 * 60;
|
|
1035
|
+
case "month":
|
|
1036
|
+
return 28 * 24 * 60 * 60;
|
|
1037
|
+
case "year":
|
|
1038
|
+
return 365 * 24 * 60 * 60;
|
|
1039
|
+
default:
|
|
1040
|
+
throw new Error("Invalid period unit");
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
1044
|
+
// src/account.ts
|
|
1045
|
+
import {
|
|
1046
|
+
toCallPolicy as toCallPolicy2,
|
|
1047
|
+
CallPolicyVersion,
|
|
1048
|
+
ParamCondition
|
|
1049
|
+
} from "@zerodev/permissions/policies";
|
|
1050
|
+
var ActaAccount = class {
|
|
1051
|
+
constructor(chainId, publicClient, signer) {
|
|
1052
|
+
this.chainId = chainId;
|
|
1053
|
+
this.signer = signer;
|
|
1054
|
+
this.publicClient = publicClient;
|
|
1055
|
+
}
|
|
1056
|
+
createAccount() {
|
|
1057
|
+
return __async(this, null, function* () {
|
|
1058
|
+
const kernelVersion = KERNEL_V3_1;
|
|
1059
|
+
const entryPoint = getEntryPoint("0.7");
|
|
1060
|
+
const ecdsaValidator = yield signerToEcdsaValidator(this.publicClient, {
|
|
1061
|
+
signer: this.signer,
|
|
1062
|
+
entryPoint,
|
|
1063
|
+
kernelVersion
|
|
1064
|
+
});
|
|
1065
|
+
const account = yield createKernelAccount2(this.publicClient, {
|
|
1066
|
+
plugins: {
|
|
1067
|
+
sudo: ecdsaValidator
|
|
1068
|
+
},
|
|
1069
|
+
entryPoint,
|
|
1070
|
+
kernelVersion
|
|
1071
|
+
});
|
|
1072
|
+
return account;
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
createAccountHelpers() {
|
|
1076
|
+
return __async(this, null, function* () {
|
|
1077
|
+
const account = yield this.createAccount();
|
|
1078
|
+
const entryPoint = getEntryPoint("0.7");
|
|
1079
|
+
const paymasterClient = createPaymasterClient({
|
|
1080
|
+
transport: http2(getPimlicoRpcByChainId(this.chainId))
|
|
1081
|
+
});
|
|
1082
|
+
const pimlicoClient = createPimlicoClient({
|
|
1083
|
+
chain: getChainById(this.chainId),
|
|
1084
|
+
transport: http2(getPimlicoRpcByChainId(this.chainId)),
|
|
1085
|
+
entryPoint
|
|
1086
|
+
});
|
|
1087
|
+
const accountClient = createSmartAccountClient({
|
|
1088
|
+
account,
|
|
1089
|
+
chain: getChainById(this.chainId),
|
|
1090
|
+
paymaster: paymasterClient,
|
|
1091
|
+
bundlerTransport: http2(getPimlicoRpcByChainId(this.chainId)),
|
|
1092
|
+
userOperation: {
|
|
1093
|
+
estimateFeesPerGas: () => __async(this, null, function* () {
|
|
1094
|
+
return (yield pimlicoClient.getUserOperationGasPrice()).fast;
|
|
1095
|
+
}),
|
|
1096
|
+
prepareUserOperation: prepareUserOperationForErc20Paymaster(pimlicoClient)
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
return { paymasterClient, pimlicoClient, accountClient };
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
estimateSinglePaymentGas(parameters) {
|
|
1103
|
+
return __async(this, null, function* () {
|
|
1104
|
+
const {
|
|
1105
|
+
signerAddress,
|
|
1106
|
+
chainId,
|
|
1107
|
+
token: tokenSymbol,
|
|
1108
|
+
amount,
|
|
1109
|
+
receiver
|
|
1110
|
+
} = parameters;
|
|
1111
|
+
if (amount <= BigInt(0)) {
|
|
1112
|
+
throw new Error("Amount must be greater than 0.");
|
|
1113
|
+
}
|
|
1114
|
+
if (receiver === signerAddress) {
|
|
1115
|
+
throw new Error("Receiver cannot be the same as the signer.");
|
|
1116
|
+
}
|
|
1117
|
+
const account = yield this.createAccount();
|
|
1118
|
+
const { accountClient, pimlicoClient } = yield this.createAccountHelpers();
|
|
1119
|
+
const fromAddress = signerAddress;
|
|
1120
|
+
const smartAccountAddress = account.address;
|
|
1121
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1122
|
+
if (!token2) {
|
|
1123
|
+
throw new Error("Token not found.");
|
|
1124
|
+
}
|
|
1125
|
+
const quotes = yield pimlicoClient.getTokenQuotes({
|
|
1126
|
+
tokens: [token2.address],
|
|
1127
|
+
chain: getChainById(chainId)
|
|
1128
|
+
});
|
|
1129
|
+
const { postOpGas, exchangeRate, paymaster } = quotes[0];
|
|
1130
|
+
const userOperation = yield accountClient.prepareUserOperation({
|
|
1131
|
+
calls: [
|
|
1132
|
+
{
|
|
1133
|
+
to: getAddress2(token2.address),
|
|
1134
|
+
abi: parseAbi2(["function transferFrom(address,address,uint)"]),
|
|
1135
|
+
functionName: "transferFrom",
|
|
1136
|
+
args: [fromAddress, smartAccountAddress, BigInt(0)]
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
to: getAddress2(token2.address),
|
|
1140
|
+
abi: parseAbi2(["function approve(address,uint)"]),
|
|
1141
|
+
functionName: "approve",
|
|
1142
|
+
args: [paymaster, BigInt(0)]
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
to: getAddress2(token2.address),
|
|
1146
|
+
abi: parseAbi2(["function transfer(address,uint)"]),
|
|
1147
|
+
functionName: "transfer",
|
|
1148
|
+
args: [
|
|
1149
|
+
"0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
|
|
1150
|
+
BigInt(0)
|
|
1151
|
+
]
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
to: getAddress2(token2.address),
|
|
1155
|
+
abi: parseAbi2(["function transfer(address,uint)"]),
|
|
1156
|
+
functionName: "transfer",
|
|
1157
|
+
args: [receiver, BigInt(0)]
|
|
1158
|
+
}
|
|
1159
|
+
]
|
|
1160
|
+
});
|
|
1161
|
+
const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
|
|
1162
|
+
const userOperationMaxCost = BigInt(
|
|
1163
|
+
userOperationMaxGas * userOperation.maxFeePerGas
|
|
1164
|
+
);
|
|
1165
|
+
const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
|
|
1166
|
+
const ActalinkFeesInToken = amount * BigInt(20) / BigInt(1e4);
|
|
1167
|
+
const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
|
|
1168
|
+
const feeInclusiveAmountInToken = amount - estimatedTotalFeesInToken;
|
|
1169
|
+
const feeExclusiveAmountInToken = amount + estimatedTotalFeesInToken;
|
|
1170
|
+
return {
|
|
1171
|
+
estimatedGasCostInToken,
|
|
1172
|
+
ActalinkFeesInToken,
|
|
1173
|
+
estimatedTotalFeesInToken,
|
|
1174
|
+
feeInclusiveAmountInToken,
|
|
1175
|
+
feeExclusiveAmountInToken,
|
|
1176
|
+
paymaster,
|
|
1177
|
+
userOperation
|
|
1178
|
+
};
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
signSinglePaymentOperation(singlePaymentParams) {
|
|
1182
|
+
return __async(this, null, function* () {
|
|
1183
|
+
try {
|
|
1184
|
+
if (!this.signer) {
|
|
1185
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1186
|
+
}
|
|
1187
|
+
const {
|
|
1188
|
+
signerAddress,
|
|
1189
|
+
chainId,
|
|
1190
|
+
token: tokenSymbol,
|
|
1191
|
+
amount,
|
|
1192
|
+
receiver,
|
|
1193
|
+
feeInclusive
|
|
1194
|
+
} = singlePaymentParams;
|
|
1195
|
+
if (amount <= BigInt(0)) {
|
|
1196
|
+
throw new Error("Amount must be greater than 0.");
|
|
1197
|
+
}
|
|
1198
|
+
if (receiver === signerAddress) {
|
|
1199
|
+
throw new Error("Receiver cannot be the same as the signer.");
|
|
1200
|
+
}
|
|
1201
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1202
|
+
if (!token2) {
|
|
1203
|
+
throw new Error("Token not found.");
|
|
1204
|
+
}
|
|
1205
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1206
|
+
const {
|
|
1207
|
+
estimatedGasCostInToken,
|
|
1208
|
+
ActalinkFeesInToken,
|
|
1209
|
+
feeInclusiveAmountInToken,
|
|
1210
|
+
feeExclusiveAmountInToken,
|
|
1211
|
+
estimatedTotalFeesInToken,
|
|
1212
|
+
paymaster
|
|
1213
|
+
} = yield this.estimateSinglePaymentGas({
|
|
1214
|
+
signerAddress,
|
|
1215
|
+
chainId,
|
|
1216
|
+
token: tokenSymbol,
|
|
1217
|
+
amount,
|
|
1218
|
+
receiver,
|
|
1219
|
+
feeInclusive
|
|
1220
|
+
});
|
|
1221
|
+
const account = yield this.createAccount();
|
|
1222
|
+
const { accountClient } = yield this.createAccountHelpers();
|
|
1223
|
+
const fromAddress = signerAddress;
|
|
1224
|
+
const smartAccountAddress = account.address;
|
|
1225
|
+
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1226
|
+
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1227
|
+
yield viemClient.checkAndApproveToken(
|
|
1228
|
+
token2,
|
|
1229
|
+
smartAccountAddress,
|
|
1230
|
+
amountToTransfer
|
|
1231
|
+
);
|
|
1232
|
+
const userOperation = yield accountClient.prepareUserOperation({
|
|
1233
|
+
calls: [
|
|
1234
|
+
{
|
|
1235
|
+
to: getAddress2(token2.address),
|
|
1236
|
+
abi: parseAbi2(["function transferFrom(address,address,uint)"]),
|
|
1237
|
+
functionName: "transferFrom",
|
|
1238
|
+
args: [fromAddress, smartAccountAddress, amountToTransfer]
|
|
1239
|
+
},
|
|
1240
|
+
{
|
|
1241
|
+
to: getAddress2(token2.address),
|
|
1242
|
+
abi: parseAbi2(["function approve(address,uint)"]),
|
|
1243
|
+
functionName: "approve",
|
|
1244
|
+
args: [paymaster, estimatedGasCostInToken]
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
to: getAddress2(token2.address),
|
|
1248
|
+
abi: parseAbi2(["function transfer(address,uint)"]),
|
|
1249
|
+
functionName: "transfer",
|
|
1250
|
+
args: [
|
|
1251
|
+
"0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
|
|
1252
|
+
ActalinkFeesInToken
|
|
1253
|
+
]
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
to: getAddress2(token2.address),
|
|
1257
|
+
abi: parseAbi2(["function transfer(address,uint)"]),
|
|
1258
|
+
functionName: "transfer",
|
|
1259
|
+
args: [receiver, receiverAmount]
|
|
1260
|
+
}
|
|
1261
|
+
],
|
|
1262
|
+
paymasterContext: {
|
|
1263
|
+
token: token2.address
|
|
1264
|
+
}
|
|
1265
|
+
});
|
|
1266
|
+
const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
|
|
1267
|
+
chainId: this.chainId
|
|
1268
|
+
}));
|
|
1269
|
+
const rpcParameters = formatUserOperationRequest(__spreadProps(__spreadValues({}, userOperation), {
|
|
1270
|
+
signature
|
|
1271
|
+
}));
|
|
1272
|
+
return rpcParameters;
|
|
1273
|
+
} catch (error) {
|
|
1274
|
+
if (error instanceof Error) {
|
|
1275
|
+
throw new Error(error.message);
|
|
1276
|
+
}
|
|
1277
|
+
throw new Error("Failed to sign single payment operation.");
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
signRecurringPayments(recurringPaymentParams) {
|
|
1282
|
+
return __async(this, null, function* () {
|
|
1283
|
+
if (!this.signer) {
|
|
1284
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1285
|
+
}
|
|
1286
|
+
const {
|
|
1287
|
+
signerAddress,
|
|
1288
|
+
chainId,
|
|
1289
|
+
token: tokenSymbol,
|
|
1290
|
+
amount,
|
|
1291
|
+
receiver,
|
|
1292
|
+
feeInclusive,
|
|
1293
|
+
count,
|
|
1294
|
+
intervalUnit,
|
|
1295
|
+
startDate,
|
|
1296
|
+
endDate
|
|
1297
|
+
} = recurringPaymentParams;
|
|
1298
|
+
if (amount <= BigInt(0)) {
|
|
1299
|
+
throw new Error("Amount must be greater than 0.");
|
|
1300
|
+
}
|
|
1301
|
+
if (receiver === signerAddress) {
|
|
1302
|
+
throw new Error("Receiver cannot be the same as the signer.");
|
|
1303
|
+
}
|
|
1304
|
+
if (!intervalUnit) {
|
|
1305
|
+
throw new Error("Interval unit is required.");
|
|
1306
|
+
}
|
|
1307
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1308
|
+
if (!token2) {
|
|
1309
|
+
throw new Error("Token not found.");
|
|
1310
|
+
}
|
|
1311
|
+
const kernelVersion = KERNEL_V3_1;
|
|
1312
|
+
const entryPoint = getEntryPoint("0.7");
|
|
1313
|
+
const paymentCount = count != null ? count : 24;
|
|
1314
|
+
const account = yield this.createAccount();
|
|
1315
|
+
const smartAccountAddress = account.address;
|
|
1316
|
+
const viemClient = new ViemClient(this.chainId, this.signer);
|
|
1317
|
+
const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
|
|
1318
|
+
const sessionKeySigner = yield toECDSASigner(
|
|
1319
|
+
privateKeyToAccount2(
|
|
1320
|
+
"0x8519baaeb81ebbcf3597d93c2f9790d1eda37097121e844e1b88c1ab77b67ae2"
|
|
1321
|
+
)
|
|
1322
|
+
);
|
|
1323
|
+
const ecdsaValidator = yield signerToEcdsaValidator(
|
|
1324
|
+
viemClient.publicClient(),
|
|
1325
|
+
{
|
|
1326
|
+
entryPoint,
|
|
1327
|
+
kernelVersion,
|
|
1328
|
+
signer: this.signer
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
const sessionKeyAddress = "0x0744F720fe178AC21F25a30263B6269a1C0bB106";
|
|
1332
|
+
const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
|
|
1333
|
+
const emptySessionKeySigner = yield toECDSASigner(emptyAccount);
|
|
1334
|
+
const {
|
|
1335
|
+
paymaster,
|
|
1336
|
+
ActalinkFeesInToken,
|
|
1337
|
+
feeInclusiveAmountInToken,
|
|
1338
|
+
feeExclusiveAmountInToken,
|
|
1339
|
+
estimatedTotalFeesInToken,
|
|
1340
|
+
userOperation,
|
|
1341
|
+
estimatedGasCostInToken
|
|
1342
|
+
} = yield this.estimateSinglePaymentGas({
|
|
1343
|
+
signerAddress,
|
|
1344
|
+
chainId,
|
|
1345
|
+
token: tokenSymbol,
|
|
1346
|
+
amount,
|
|
1347
|
+
receiver,
|
|
1348
|
+
feeInclusive
|
|
1349
|
+
});
|
|
1350
|
+
const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
|
|
1351
|
+
const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
|
|
1352
|
+
yield viemClient.checkAndApproveToken(
|
|
1353
|
+
token2,
|
|
1354
|
+
smartAccountAddress,
|
|
1355
|
+
amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount)
|
|
1356
|
+
);
|
|
1357
|
+
const callPolicy = toCallPolicy2({
|
|
1358
|
+
policyVersion: CallPolicyVersion.V0_0_4,
|
|
1359
|
+
permissions: [
|
|
1360
|
+
{
|
|
1361
|
+
target: token2.address,
|
|
1362
|
+
valueLimit: BigInt(0),
|
|
1363
|
+
abi: parseAbi2(["function transferFrom(address,address,uint)"]),
|
|
1364
|
+
functionName: "transferFrom",
|
|
1365
|
+
args: [
|
|
1366
|
+
{
|
|
1367
|
+
condition: ParamCondition.EQUAL,
|
|
1368
|
+
value: signerAddress
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
condition: ParamCondition.EQUAL,
|
|
1372
|
+
value: smartAccountAddress
|
|
1373
|
+
},
|
|
1374
|
+
{
|
|
1375
|
+
condition: ParamCondition.GREATER_THAN_OR_EQUAL,
|
|
1376
|
+
value: 0
|
|
1377
|
+
}
|
|
1378
|
+
]
|
|
1379
|
+
},
|
|
1380
|
+
{
|
|
1381
|
+
target: token2.address,
|
|
1382
|
+
valueLimit: BigInt(0),
|
|
1383
|
+
abi: parseAbi2(["function approve(address,uint)"]),
|
|
1384
|
+
functionName: "approve",
|
|
1385
|
+
args: [
|
|
1386
|
+
{
|
|
1387
|
+
condition: ParamCondition.EQUAL,
|
|
1388
|
+
value: paymaster
|
|
1389
|
+
},
|
|
1390
|
+
{
|
|
1391
|
+
condition: ParamCondition.GREATER_THAN_OR_EQUAL,
|
|
1392
|
+
value: 0
|
|
1393
|
+
}
|
|
1394
|
+
]
|
|
1395
|
+
},
|
|
1396
|
+
{
|
|
1397
|
+
target: token2.address,
|
|
1398
|
+
valueLimit: BigInt(0),
|
|
1399
|
+
abi: parseAbi2(["function transfer(address,uint)"]),
|
|
1400
|
+
functionName: "transfer",
|
|
1401
|
+
args: [
|
|
1402
|
+
{
|
|
1403
|
+
condition: ParamCondition.ONE_OF,
|
|
1404
|
+
value: ["0xbDCBee616C26D5282227a672C3d0B87EA477A3fe", receiver]
|
|
1405
|
+
},
|
|
1406
|
+
{
|
|
1407
|
+
condition: ParamCondition.GREATER_THAN_OR_EQUAL,
|
|
1408
|
+
value: 0
|
|
1409
|
+
}
|
|
1410
|
+
]
|
|
1411
|
+
}
|
|
1412
|
+
]
|
|
1413
|
+
});
|
|
1414
|
+
const permissionPlugin = yield toPermissionValidator(
|
|
1415
|
+
viemClient.publicClient(),
|
|
1416
|
+
{
|
|
1417
|
+
entryPoint,
|
|
1418
|
+
kernelVersion,
|
|
1419
|
+
signer: emptySessionKeySigner,
|
|
1420
|
+
policies: [callPolicy]
|
|
1421
|
+
}
|
|
1422
|
+
);
|
|
1423
|
+
const serializedSessionKeyAccount = yield createKernelAccount2(
|
|
1424
|
+
viemClient.publicClient(),
|
|
1425
|
+
{
|
|
1426
|
+
entryPoint,
|
|
1427
|
+
kernelVersion,
|
|
1428
|
+
plugins: {
|
|
1429
|
+
sudo: ecdsaValidator,
|
|
1430
|
+
regular: permissionPlugin
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
);
|
|
1434
|
+
const approval = yield serializePermissionAccount(
|
|
1435
|
+
serializedSessionKeyAccount
|
|
1436
|
+
);
|
|
1437
|
+
return approval;
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
|
|
1442
|
+
// src/api.ts
|
|
1443
|
+
import { toHex } from "viem";
|
|
1444
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
1445
|
+
HttpMethod2["Get"] = "get";
|
|
1446
|
+
HttpMethod2["Post"] = "post";
|
|
1447
|
+
HttpMethod2["Delete"] = "delete";
|
|
1448
|
+
HttpMethod2["Update"] = "update";
|
|
1449
|
+
return HttpMethod2;
|
|
1450
|
+
})(HttpMethod || {});
|
|
1451
|
+
function sendRequest(_0) {
|
|
1452
|
+
return __async(this, arguments, function* ({
|
|
1453
|
+
url,
|
|
1454
|
+
method,
|
|
1455
|
+
body,
|
|
1456
|
+
headers = {}
|
|
1457
|
+
}) {
|
|
1458
|
+
var _a;
|
|
1459
|
+
const response = yield fetch(url, {
|
|
1460
|
+
method,
|
|
1461
|
+
headers: __spreadProps(__spreadValues({}, headers), {
|
|
1462
|
+
Accept: "application/json",
|
|
1463
|
+
"Content-Type": "application/json"
|
|
1464
|
+
}),
|
|
1465
|
+
body: JSON.stringify(body)
|
|
1466
|
+
});
|
|
1467
|
+
let jsonResponse;
|
|
1468
|
+
const res = yield response.json();
|
|
1469
|
+
if (!response.ok) {
|
|
1470
|
+
jsonResponse = {
|
|
1471
|
+
error: {
|
|
1472
|
+
code: response.status,
|
|
1473
|
+
message: response.statusText
|
|
1474
|
+
},
|
|
1475
|
+
data: void 0
|
|
1476
|
+
};
|
|
1477
|
+
return jsonResponse;
|
|
1478
|
+
}
|
|
1479
|
+
if (!res) {
|
|
1480
|
+
jsonResponse = {
|
|
1481
|
+
error: {
|
|
1482
|
+
code: 400,
|
|
1483
|
+
message: "No response received."
|
|
1484
|
+
},
|
|
1485
|
+
data: void 0
|
|
1486
|
+
};
|
|
1487
|
+
return jsonResponse;
|
|
1488
|
+
}
|
|
1489
|
+
if (res == null ? void 0 : res.error) {
|
|
1490
|
+
jsonResponse = {
|
|
1491
|
+
error: {
|
|
1492
|
+
code: response.status,
|
|
1493
|
+
message: res.error
|
|
1494
|
+
},
|
|
1495
|
+
data: void 0
|
|
1496
|
+
};
|
|
1497
|
+
return jsonResponse;
|
|
1498
|
+
}
|
|
1499
|
+
jsonResponse = {
|
|
1500
|
+
data: res.data,
|
|
1501
|
+
message: (_a = res.message) != null ? _a : "Success",
|
|
1502
|
+
error: void 0
|
|
1503
|
+
};
|
|
1504
|
+
return jsonResponse;
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
function createSessionAPICall(url, sessionBodyParams) {
|
|
1508
|
+
return __async(this, null, function* () {
|
|
1509
|
+
const response = yield sendRequest({
|
|
1510
|
+
url,
|
|
1511
|
+
method: "post" /* Post */,
|
|
1512
|
+
body: sessionBodyParams
|
|
1513
|
+
});
|
|
1514
|
+
return response.data;
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function verifySessionAPICall(url, sessionId) {
|
|
1518
|
+
return __async(this, null, function* () {
|
|
1519
|
+
const response = yield sendRequest({
|
|
1520
|
+
url,
|
|
1521
|
+
method: "get" /* Get */
|
|
1522
|
+
});
|
|
1523
|
+
return response.data;
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
function scheduleRecurringPaymentsAPICall(url, params) {
|
|
1527
|
+
return __async(this, null, function* () {
|
|
1528
|
+
const parsedParams = __spreadProps(__spreadValues({}, params), {
|
|
1529
|
+
amount: toHex(params.amount)
|
|
1530
|
+
});
|
|
1531
|
+
const response = yield sendRequest({
|
|
1532
|
+
url,
|
|
1533
|
+
method: "post" /* Post */,
|
|
1534
|
+
body: parsedParams
|
|
1535
|
+
});
|
|
1536
|
+
return response.data;
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceParams) {
|
|
1540
|
+
return __async(this, null, function* () {
|
|
1541
|
+
const params = {
|
|
1542
|
+
userOperation,
|
|
1543
|
+
paymentParams,
|
|
1544
|
+
serviceParams
|
|
1545
|
+
};
|
|
1546
|
+
const response = yield sendRequest({
|
|
1547
|
+
url,
|
|
1548
|
+
method: "post" /* Post */,
|
|
1549
|
+
body: params
|
|
1550
|
+
});
|
|
1551
|
+
return response.data;
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/deposit.ts
|
|
1556
|
+
var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
|
|
1557
|
+
var depositServiceUrl = "https://api.acta.link/deposit/v1/";
|
|
1558
|
+
var ActaDeposit = class {
|
|
1559
|
+
constructor(parameters) {
|
|
1560
|
+
this.count = 0;
|
|
1561
|
+
this.intervalUnit = void 0;
|
|
1562
|
+
this.startDate = void 0;
|
|
1563
|
+
this.endDate = void 0;
|
|
1564
|
+
this.serviceSessionParams = void 0;
|
|
1565
|
+
this.depositSessionId = "";
|
|
1566
|
+
this.status = "not_started";
|
|
1567
|
+
this.serviceType = "deposit";
|
|
1568
|
+
var _a;
|
|
1569
|
+
this.connectorType = parameters.connectorType;
|
|
1570
|
+
this.walletClient = parameters.walletClient;
|
|
1571
|
+
this.signerAddress = parameters.signerAddress;
|
|
1572
|
+
this.chainId = parameters.chainId;
|
|
1573
|
+
this.token = parameters.token;
|
|
1574
|
+
this.amount = parameters.amount;
|
|
1575
|
+
this.receiver = parameters.receiver;
|
|
1576
|
+
this.feeInclusive = parameters.feeInclusive;
|
|
1577
|
+
this.paymentType = parameters.paymentType;
|
|
1578
|
+
this.count = parameters.count;
|
|
1579
|
+
this.intervalUnit = parameters.intervalUnit;
|
|
1580
|
+
this.startDate = parameters.startDate;
|
|
1581
|
+
this.endDate = parameters.endDate;
|
|
1582
|
+
this.depositSessionId = (_a = parameters.depositSessionId) != null ? _a : "";
|
|
1583
|
+
this.viemClient = new ViemClient(this.chainId, this.walletClient);
|
|
1584
|
+
this.account = new ActaAccount(
|
|
1585
|
+
this.chainId,
|
|
1586
|
+
this.viemClient.publicClient(),
|
|
1587
|
+
this.walletClient
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
createSession(serviceSessionparams) {
|
|
1591
|
+
return __async(this, null, function* () {
|
|
1592
|
+
try {
|
|
1593
|
+
if (!this.signerAddress || this.signerAddress === zeroAddress4) {
|
|
1594
|
+
throw new Error("Signer address is required.");
|
|
1595
|
+
}
|
|
1596
|
+
if (this.paymentType !== "single" && this.paymentType !== "choose" && this.paymentType !== "recurring") {
|
|
1597
|
+
throw new Error("Invalid payment type.");
|
|
1598
|
+
}
|
|
1599
|
+
if (!this.receiver || this.receiver === zeroAddress4) {
|
|
1600
|
+
throw new Error("Receiver is required.");
|
|
1601
|
+
}
|
|
1602
|
+
if (this.paymentType === "recurring" && (this.count === void 0 || this.count === 0)) {
|
|
1603
|
+
throw new Error("Count is required for recurring payments.");
|
|
1604
|
+
}
|
|
1605
|
+
if (this.paymentType === "recurring" && this.intervalUnit === void 0) {
|
|
1606
|
+
throw new Error("Interval unit is required for recurring payments.");
|
|
1607
|
+
}
|
|
1608
|
+
if (this.depositSessionId !== "") {
|
|
1609
|
+
const session2 = yield verifySessionAPICall(
|
|
1610
|
+
`${depositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
|
|
1611
|
+
this.depositSessionId
|
|
1612
|
+
);
|
|
1613
|
+
this.depositSessionId = session2.sessionId;
|
|
1614
|
+
return session2.sessionId;
|
|
1615
|
+
}
|
|
1616
|
+
const token2 = getTokenByChainIdAndSymbol(this.chainId, this.token);
|
|
1617
|
+
if (!token2) {
|
|
1618
|
+
throw new Error("Token not supported.");
|
|
1619
|
+
}
|
|
1620
|
+
const session = yield createSessionAPICall(
|
|
1621
|
+
`${depositServiceUrl}session`,
|
|
1622
|
+
{
|
|
1623
|
+
paymentParams: {
|
|
1624
|
+
signerAddress: this.signerAddress,
|
|
1625
|
+
chainId: this.chainId,
|
|
1626
|
+
token: token2.address,
|
|
1627
|
+
amount: toHex2(this.amount),
|
|
1628
|
+
receiver: this.receiver,
|
|
1629
|
+
feeInclusive: this.feeInclusive,
|
|
1630
|
+
serviceType: "deposit",
|
|
1631
|
+
paymentType: this.paymentType,
|
|
1632
|
+
count: this.count,
|
|
1633
|
+
intervalUnit: this.intervalUnit,
|
|
1634
|
+
startDate: this.startDate,
|
|
1635
|
+
endDate: this.endDate
|
|
1636
|
+
},
|
|
1637
|
+
serviceSessionParams: serviceSessionparams
|
|
1638
|
+
}
|
|
1639
|
+
);
|
|
1640
|
+
this.depositSessionId = session.sessionId;
|
|
1641
|
+
this.status = "session_created";
|
|
1642
|
+
const sessionId = session.sessionId;
|
|
1643
|
+
return sessionId;
|
|
1644
|
+
} catch (error) {
|
|
1645
|
+
this.status = "session_fetch_failed";
|
|
1646
|
+
if (error instanceof Error) {
|
|
1647
|
+
throw new Error(error.message);
|
|
1648
|
+
}
|
|
1649
|
+
throw new Error("Failed to create deposit session.");
|
|
1650
|
+
}
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1653
|
+
estimateSinglePaymentGas(parameters) {
|
|
1654
|
+
return __async(this, null, function* () {
|
|
1655
|
+
try {
|
|
1656
|
+
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
1657
|
+
throw new Error("Only self custody payments are supported.");
|
|
1658
|
+
}
|
|
1659
|
+
const {
|
|
1660
|
+
estimatedGasCostInToken,
|
|
1661
|
+
ActalinkFeesInToken,
|
|
1662
|
+
feeInclusiveAmountInToken,
|
|
1663
|
+
feeExclusiveAmountInToken,
|
|
1664
|
+
estimatedTotalFeesInToken,
|
|
1665
|
+
paymaster,
|
|
1666
|
+
userOperation
|
|
1667
|
+
} = yield this.account.estimateSinglePaymentGas(parameters);
|
|
1668
|
+
return {
|
|
1669
|
+
estimatedGasCostInToken,
|
|
1670
|
+
ActalinkFeesInToken,
|
|
1671
|
+
feeInclusiveAmountInToken,
|
|
1672
|
+
feeExclusiveAmountInToken,
|
|
1673
|
+
estimatedTotalFeesInToken,
|
|
1674
|
+
paymaster,
|
|
1675
|
+
userOperation
|
|
1676
|
+
};
|
|
1677
|
+
} catch (error) {
|
|
1678
|
+
if (error instanceof Error) {
|
|
1679
|
+
throw new Error(error.message);
|
|
1680
|
+
}
|
|
1681
|
+
throw new Error("Failed to estimate single payment gas.");
|
|
1682
|
+
}
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
createPayment(servicePaymentParams) {
|
|
1686
|
+
return __async(this, null, function* () {
|
|
1687
|
+
try {
|
|
1688
|
+
if (this.paymentType === "single") {
|
|
1689
|
+
const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
|
|
1690
|
+
depositSessionId: this.depositSessionId
|
|
1691
|
+
}) : servicePaymentParams;
|
|
1692
|
+
const id = yield this.createSinglePayment(paymentParams);
|
|
1693
|
+
return id;
|
|
1694
|
+
}
|
|
1695
|
+
if (this.paymentType === "choose") {
|
|
1696
|
+
}
|
|
1697
|
+
if (this.paymentType === "recurring") {
|
|
1698
|
+
const paymentParams = this.serviceType === "deposit" ? __spreadProps(__spreadValues({}, servicePaymentParams), {
|
|
1699
|
+
depositSessionId: this.depositSessionId
|
|
1700
|
+
}) : servicePaymentParams;
|
|
1701
|
+
const id = yield this.createRecurringPayments(paymentParams);
|
|
1702
|
+
return id;
|
|
1703
|
+
}
|
|
1704
|
+
} catch (error) {
|
|
1705
|
+
this.status = "payment_failed";
|
|
1706
|
+
if (error instanceof Error) {
|
|
1707
|
+
throw new Error(error.message);
|
|
1708
|
+
}
|
|
1709
|
+
throw new Error("Failed to create payment.");
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
createSinglePayment(servicePaymentParams) {
|
|
1714
|
+
return __async(this, null, function* () {
|
|
1715
|
+
try {
|
|
1716
|
+
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
1717
|
+
throw new Error("Only self custody payments are supported.");
|
|
1718
|
+
}
|
|
1719
|
+
if (!this.depositSessionId || this.depositSessionId === "") {
|
|
1720
|
+
throw new Error("Deposit session ID is required.");
|
|
1721
|
+
}
|
|
1722
|
+
if (this.depositSessionId !== "") {
|
|
1723
|
+
const session = yield verifySessionAPICall(
|
|
1724
|
+
`${depositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
|
|
1725
|
+
this.depositSessionId
|
|
1726
|
+
);
|
|
1727
|
+
this.depositSessionId = session.sessionId;
|
|
1728
|
+
}
|
|
1729
|
+
const signerAddress = this.signerAddress;
|
|
1730
|
+
const chainId = this.chainId;
|
|
1731
|
+
const tokenSymbol = this.token;
|
|
1732
|
+
const amount = this.amount;
|
|
1733
|
+
const receiver = this.receiver;
|
|
1734
|
+
const feeInclusive = this.feeInclusive;
|
|
1735
|
+
const serviceType = this.serviceType;
|
|
1736
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1737
|
+
if (!token2) {
|
|
1738
|
+
throw new Error("Token not supported.");
|
|
1739
|
+
}
|
|
1740
|
+
const rpcParameters = yield this.account.signSinglePaymentOperation({
|
|
1741
|
+
signerAddress,
|
|
1742
|
+
chainId,
|
|
1743
|
+
token: tokenSymbol,
|
|
1744
|
+
amount,
|
|
1745
|
+
receiver,
|
|
1746
|
+
feeInclusive
|
|
1747
|
+
});
|
|
1748
|
+
const txn = yield executeSinglePaymentAPICall(
|
|
1749
|
+
`${transactionServiceUrl}execute/single`,
|
|
1750
|
+
rpcParameters,
|
|
1751
|
+
{
|
|
1752
|
+
senderAddress: signerAddress,
|
|
1753
|
+
receiverAddress: receiver,
|
|
1754
|
+
chainId,
|
|
1755
|
+
tokenAddress: token2.address,
|
|
1756
|
+
amount: toHex2(amount),
|
|
1757
|
+
feeInclusive,
|
|
1758
|
+
serviceType
|
|
1759
|
+
},
|
|
1760
|
+
servicePaymentParams
|
|
1761
|
+
);
|
|
1762
|
+
return txn.transaction.id;
|
|
1763
|
+
} catch (error) {
|
|
1764
|
+
if (error instanceof Error) {
|
|
1765
|
+
throw new Error(error.message);
|
|
1766
|
+
}
|
|
1767
|
+
throw new Error("Failed to create payment.");
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
// private async pollPayment(interval: number) {
|
|
1772
|
+
// const intervalId = setInterval(async () => {
|
|
1773
|
+
// const result = await fetch(
|
|
1774
|
+
// `${this.serviceUrl}/v1/${this.serviceType}/status?id=${this.depositSessionId}`,
|
|
1775
|
+
// {
|
|
1776
|
+
// method: "GET",
|
|
1777
|
+
// headers: {
|
|
1778
|
+
// "Content-Type": "application/json",
|
|
1779
|
+
// },
|
|
1780
|
+
// }
|
|
1781
|
+
// );
|
|
1782
|
+
// const res = await result.json();
|
|
1783
|
+
// const status = res.data.status;
|
|
1784
|
+
// if (status === "success" || status === "failed") {
|
|
1785
|
+
// this.status =
|
|
1786
|
+
// status === "success" ? "payment_completed" : "payment_failed";
|
|
1787
|
+
// clearInterval(intervalId);
|
|
1788
|
+
// }
|
|
1789
|
+
// }, interval);
|
|
1790
|
+
// return () => clearInterval(intervalId);
|
|
1791
|
+
// }
|
|
1792
|
+
createRecurringPayments(servicePaymentParams) {
|
|
1793
|
+
return __async(this, null, function* () {
|
|
1794
|
+
if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
|
|
1795
|
+
throw new Error("Only self custody payments are supported.");
|
|
1796
|
+
}
|
|
1797
|
+
if (!this.depositSessionId || this.depositSessionId === "") {
|
|
1798
|
+
throw new Error("Deposit session ID is required.");
|
|
1799
|
+
}
|
|
1800
|
+
if (!this.walletClient) {
|
|
1801
|
+
throw new Error("Signer is required for self custody payments.");
|
|
1802
|
+
}
|
|
1803
|
+
if (this.depositSessionId !== "") {
|
|
1804
|
+
const session = yield verifySessionAPICall(
|
|
1805
|
+
`${depositServiceUrl}verify-session?sessionId=${this.depositSessionId}`,
|
|
1806
|
+
this.depositSessionId
|
|
1807
|
+
);
|
|
1808
|
+
this.depositSessionId = session.sessionId;
|
|
1809
|
+
}
|
|
1810
|
+
const signerAddress = this.signerAddress;
|
|
1811
|
+
const chainId = this.chainId;
|
|
1812
|
+
const tokenSymbol = this.token;
|
|
1813
|
+
const amount = this.amount;
|
|
1814
|
+
const receiver = this.receiver;
|
|
1815
|
+
const feeInclusive = this.feeInclusive;
|
|
1816
|
+
const count = this.count;
|
|
1817
|
+
const intervalUnit = this.intervalUnit;
|
|
1818
|
+
const startDate = this.startDate;
|
|
1819
|
+
const endDate = this.endDate;
|
|
1820
|
+
const serviceType = this.serviceType;
|
|
1821
|
+
const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
|
|
1822
|
+
if (!token2) {
|
|
1823
|
+
throw new Error("Token not supported.");
|
|
1824
|
+
}
|
|
1825
|
+
if (!chainId || !count || !intervalUnit || !startDate || !endDate) {
|
|
1826
|
+
throw new Error("Invalid parameters.");
|
|
1827
|
+
}
|
|
1828
|
+
const approval = yield this.account.signRecurringPayments({
|
|
1829
|
+
signerAddress,
|
|
1830
|
+
chainId,
|
|
1831
|
+
token: tokenSymbol,
|
|
1832
|
+
amount,
|
|
1833
|
+
feeInclusive,
|
|
1834
|
+
count,
|
|
1835
|
+
intervalUnit,
|
|
1836
|
+
startDate,
|
|
1837
|
+
endDate,
|
|
1838
|
+
receiver
|
|
1839
|
+
});
|
|
1840
|
+
const txn = yield scheduleRecurringPaymentsAPICall(
|
|
1841
|
+
`${transactionServiceUrl}schedule/recurring`,
|
|
1842
|
+
{
|
|
1843
|
+
amount,
|
|
1844
|
+
chainId,
|
|
1845
|
+
feeInclusive,
|
|
1846
|
+
intervalCount: count,
|
|
1847
|
+
intervalUnit,
|
|
1848
|
+
senderAddress: signerAddress,
|
|
1849
|
+
receiverAddress: receiver,
|
|
1850
|
+
tokenAddress: token2.address,
|
|
1851
|
+
startAt: startDate,
|
|
1852
|
+
endAt: endDate,
|
|
1853
|
+
approval,
|
|
1854
|
+
serviceParams: servicePaymentParams,
|
|
1855
|
+
serviceType
|
|
1856
|
+
}
|
|
1857
|
+
);
|
|
1858
|
+
return txn.recurringTransaction.id;
|
|
1859
|
+
});
|
|
1860
|
+
}
|
|
1861
|
+
};
|
|
1862
|
+
export {
|
|
1863
|
+
ActaAccount,
|
|
1864
|
+
ActaDeposit,
|
|
1865
|
+
ConnectorType,
|
|
1866
|
+
HttpMethod,
|
|
1867
|
+
PolicyFlags,
|
|
1868
|
+
TokenLogo,
|
|
1869
|
+
ViemClient,
|
|
1870
|
+
arbitrumDAI,
|
|
1871
|
+
arbitrumETH,
|
|
1872
|
+
arbitrumUSDC,
|
|
1873
|
+
arbitrumUSDCe,
|
|
1874
|
+
arbitrumUSDT,
|
|
1875
|
+
arbitrumWETH,
|
|
1876
|
+
base64ToBytes,
|
|
1877
|
+
baseDAI,
|
|
1878
|
+
baseETH,
|
|
1879
|
+
baseEURC,
|
|
1880
|
+
baseUSDC,
|
|
1881
|
+
baseUSDT,
|
|
1882
|
+
baseUSDbC,
|
|
1883
|
+
baseWETH,
|
|
1884
|
+
bscBNB,
|
|
1885
|
+
bscUSDC,
|
|
1886
|
+
bscUSDT,
|
|
1887
|
+
bscWBNB,
|
|
1888
|
+
bytesToBase64,
|
|
1889
|
+
createPolicyFromParams,
|
|
1890
|
+
createSessionAPICall,
|
|
1891
|
+
decodeParamsFromInitCode,
|
|
1892
|
+
deserializePermissionAccount,
|
|
1893
|
+
deserializePermissionAccountParams,
|
|
1894
|
+
ethereumDAI,
|
|
1895
|
+
ethereumETH,
|
|
1896
|
+
ethereumEURC,
|
|
1897
|
+
ethereumUSDC,
|
|
1898
|
+
ethereumUSDT,
|
|
1899
|
+
ethereumWETH,
|
|
1900
|
+
executeSinglePaymentAPICall,
|
|
1901
|
+
getChainById,
|
|
1902
|
+
getChainExplorerByChainId,
|
|
1903
|
+
getPeriodInterval,
|
|
1904
|
+
getPimlicoRpcByChainId,
|
|
1905
|
+
getRpcByChainId,
|
|
1906
|
+
getTokenByChainIdAndSymbol,
|
|
1907
|
+
isKernelVersionAfter,
|
|
1908
|
+
isPermissionValidatorPlugin,
|
|
1909
|
+
lineaDAI,
|
|
1910
|
+
lineaETH,
|
|
1911
|
+
lineaUSDC,
|
|
1912
|
+
lineaWETH,
|
|
1913
|
+
optimismDAI,
|
|
1914
|
+
optimismETH,
|
|
1915
|
+
optimismUSDC,
|
|
1916
|
+
optimismUSDCe,
|
|
1917
|
+
optimismUSDT,
|
|
1918
|
+
optimismWETH,
|
|
1919
|
+
polygonDAI,
|
|
1920
|
+
polygonPOL,
|
|
1921
|
+
polygonUSDC,
|
|
1922
|
+
polygonUSDCe,
|
|
1923
|
+
polygonUSDT,
|
|
1924
|
+
polygonWETH,
|
|
1925
|
+
polygonWPOL,
|
|
1926
|
+
scheduleRecurringPaymentsAPICall,
|
|
1927
|
+
sendRequest,
|
|
1928
|
+
serializePermissionAccount,
|
|
1929
|
+
serializePermissionAccountParams,
|
|
1930
|
+
supportedChains,
|
|
1931
|
+
supportedTokensByChain,
|
|
1932
|
+
toECDSASigner,
|
|
1933
|
+
toPermissionValidator,
|
|
1934
|
+
toPolicyId,
|
|
1935
|
+
toSignerId,
|
|
1936
|
+
token,
|
|
1937
|
+
tokensCommonSymbols,
|
|
1938
|
+
verifySessionAPICall
|
|
1939
|
+
};
|