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