@coinbase/cdp-sdk 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +123 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js +26 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +35 -2
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/listTokenBalances.js +33 -0
- package/_cjs/actions/evm/listTokenBalances.js.map +1 -0
- package/_cjs/actions/evm/requestFaucet.js +18 -0
- package/_cjs/actions/evm/requestFaucet.js.map +1 -0
- package/_cjs/actions/evm/sendTransaction.js +29 -0
- package/_cjs/actions/evm/sendTransaction.js.map +1 -0
- package/_cjs/actions/evm/sendUserOperation.js +5 -6
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +72 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -0
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +67 -0
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -0
- package/_cjs/actions/evm/transfer/transfer.js +59 -0
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -0
- package/_cjs/actions/evm/transfer/types.js +3 -0
- package/_cjs/actions/evm/transfer/types.js.map +1 -0
- package/_cjs/actions/evm/transfer/utils.js +39 -0
- package/_cjs/actions/evm/transfer/utils.js.map +1 -0
- package/_cjs/actions/evm/types.js +3 -0
- package/_cjs/actions/evm/types.js.map +1 -0
- package/_cjs/client/evm/evm.js +52 -42
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/solana/solana.js +42 -0
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/utils/serializeTransaction.js +18 -0
- package/_cjs/utils/serializeTransaction.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +26 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +35 -2
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/listTokenBalances.js +30 -0
- package/_esm/actions/evm/listTokenBalances.js.map +1 -0
- package/_esm/actions/evm/requestFaucet.js +15 -0
- package/_esm/actions/evm/requestFaucet.js.map +1 -0
- package/_esm/actions/evm/sendTransaction.js +26 -0
- package/_esm/actions/evm/sendTransaction.js.map +1 -0
- package/_esm/actions/evm/sendUserOperation.js +5 -6
- package/_esm/actions/evm/sendUserOperation.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +69 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -0
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +64 -0
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -0
- package/_esm/actions/evm/transfer/transfer.js +56 -0
- package/_esm/actions/evm/transfer/transfer.js.map +1 -0
- package/_esm/actions/evm/transfer/types.js +2 -0
- package/_esm/actions/evm/transfer/types.js.map +1 -0
- package/_esm/actions/evm/transfer/utils.js +35 -0
- package/_esm/actions/evm/transfer/utils.js.map +1 -0
- package/_esm/actions/evm/types.js +2 -0
- package/_esm/actions/evm/types.js.map +1 -0
- package/_esm/client/evm/evm.js +52 -42
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/solana/solana.js +42 -0
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/utils/serializeTransaction.js +15 -0
- package/_esm/utils/serializeTransaction.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts +2 -2
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts +4 -4
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/types.d.ts +4 -3
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/actions/evm/listTokenBalances.d.ts +76 -0
- package/_types/actions/evm/listTokenBalances.d.ts.map +1 -0
- package/_types/actions/evm/requestFaucet.d.ts +34 -0
- package/_types/actions/evm/requestFaucet.d.ts.map +1 -0
- package/_types/actions/evm/sendTransaction.d.ts +42 -0
- package/_types/actions/evm/sendTransaction.d.ts.map +1 -0
- package/_types/actions/evm/sendUserOperation.d.ts +3 -2
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +4 -0
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -0
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +4 -0
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -0
- package/_types/actions/evm/transfer/transfer.d.ts +14 -0
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -0
- package/_types/actions/evm/transfer/types.d.ts +71 -0
- package/_types/actions/evm/transfer/types.d.ts.map +1 -0
- package/_types/actions/evm/transfer/utils.d.ts +631 -0
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -0
- package/_types/actions/evm/types.d.ts +230 -0
- package/_types/actions/evm/types.d.ts.map +1 -0
- package/_types/client/evm/evm.d.ts +22 -3
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +20 -137
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +17 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +8 -0
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/utils/serializeTransaction.d.ts +9 -0
- package/_types/utils/serializeTransaction.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +46 -6
- package/accounts/evm/toEvmSmartAccount.ts +68 -4
- package/accounts/types.ts +20 -16
- package/actions/evm/listTokenBalances.ts +107 -0
- package/actions/evm/requestFaucet.ts +46 -0
- package/actions/evm/sendTransaction.ts +73 -0
- package/actions/evm/sendUserOperation.ts +6 -6
- package/actions/evm/transfer/accountTransferStrategy.ts +84 -0
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +72 -0
- package/actions/evm/transfer/transfer.ts +71 -0
- package/actions/evm/transfer/types.ts +81 -0
- package/actions/evm/transfer/utils.ts +39 -0
- package/actions/evm/types.ts +244 -0
- package/client/evm/evm.ts +70 -63
- package/client/evm/evm.types.ts +32 -149
- package/client/solana/solana.ts +43 -0
- package/client/solana/solana.types.ts +9 -0
- package/package.json +1 -1
- package/utils/serializeTransaction.ts +17 -0
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# CDP SDK Changelog
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#99](https://github.com/coinbase/cdp-sdk/pull/99) [`0fd6d2b`](https://github.com/coinbase/cdp-sdk/commit/0fd6d2ba56b2da52c96eb19278dc782560b7680b) Thanks [@0xRAG](https://github.com/0xRAG)! - Added actions to EvmAccount and EvmSmartAccount:
|
|
8
|
+
|
|
9
|
+
- listTokenBalances
|
|
10
|
+
- requestFaucet
|
|
11
|
+
- sendTransaction (EvmAccount only)
|
|
12
|
+
- sendUserOperation (EvmSmartAccount only)
|
|
13
|
+
- waitForUserOperation (EvmSmartAccount only)
|
|
14
|
+
|
|
15
|
+
## 1.5.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#94](https://github.com/coinbase/cdp-sdk/pull/94) [`071515e`](https://github.com/coinbase/cdp-sdk/commit/071515e5c8222ba277e207e1c5507d73379ebe5e) Thanks [@sddioulde](https://github.com/sddioulde)! - Added a getOrCreateAccount function to the EVM and Solana clients
|
|
20
|
+
|
|
21
|
+
- [#90](https://github.com/coinbase/cdp-sdk/pull/90) [`2bf3dfb`](https://github.com/coinbase/cdp-sdk/commit/2bf3dfbd60a5a6b2f127454a5ce67ade5463eff9) Thanks [@0xRAG](https://github.com/0xRAG)! - Added transfer methods EvmAccount and EvmSmartAccount
|
|
22
|
+
|
|
3
23
|
## 1.4.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -102,13 +102,29 @@ const cdp = new CdpClient({
|
|
|
102
102
|
#### Create an EVM account as follows:
|
|
103
103
|
|
|
104
104
|
```typescript
|
|
105
|
-
const
|
|
105
|
+
const account = await cdp.evm.createAccount();
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
#### Create a Solana account as follows:
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
-
const
|
|
111
|
+
const account = await cdp.solana.createAccount();
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Get or Create an EVM account as follows:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const account = await cdp.evm.getOrCreateAccount({
|
|
118
|
+
name: "Account1",
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Get or Create a Solana account as follows:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const account = await cdp.solana.getOrCreateAccount({
|
|
126
|
+
name: "Account1",
|
|
127
|
+
});
|
|
112
128
|
```
|
|
113
129
|
|
|
114
130
|
### Testnet faucet
|
|
@@ -271,6 +287,111 @@ const userOperation = await cdp.sendUserOperation({
|
|
|
271
287
|
});
|
|
272
288
|
```
|
|
273
289
|
|
|
290
|
+
### Transferring tokens
|
|
291
|
+
|
|
292
|
+
For complete examples, check out [transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/transfer.ts) and [transferWithSmartWallet.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/transferWithSmartWallet.ts).
|
|
293
|
+
|
|
294
|
+
You can transfer tokens between accounts using the `transfer` function:
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
const sender = await cdp.evm.createAccount({ name: "Sender" });
|
|
298
|
+
|
|
299
|
+
const { status } = await sender.transfer({
|
|
300
|
+
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
301
|
+
amount: "0.01",
|
|
302
|
+
token: "usdc",
|
|
303
|
+
network: "base-sepolia",
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
Smart Accounts also have a `transfer` function:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const sender = await cdp.evm.createSmartAccount({
|
|
311
|
+
owner: privateKeyToAccount(generatePrivateKey()),
|
|
312
|
+
});
|
|
313
|
+
console.log("Created smart account", sender);
|
|
314
|
+
|
|
315
|
+
const { status } = await sender.transfer({
|
|
316
|
+
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
317
|
+
amount: "0.01",
|
|
318
|
+
token: "usdc",
|
|
319
|
+
network: "base-sepolia",
|
|
320
|
+
});
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
If you pass a decimal amount in a string, the SDK will parse it into a bigint based on the token's decimals. You can also pass a bigint directly:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const { status } = await sender.transfer({
|
|
327
|
+
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
328
|
+
amount: 10000n, // equivalent to 0.01 usdc
|
|
329
|
+
token: "usdc",
|
|
330
|
+
network: "base-sepolia",
|
|
331
|
+
});
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
You can pass `usdc` or `eth` as the token to transfer, or you can pass a contract address directly:
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
const { status } = await sender.transfer({
|
|
338
|
+
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
339
|
+
amount: "0.000001",
|
|
340
|
+
token: "0x4200000000000000000000000000000000000006", // WETH on Base Sepolia
|
|
341
|
+
network: "base-sepolia",
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
You can also pass another account as the `to` parameter:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
const sender = await cdp.evm.createAccount({ name: "Sender" });
|
|
349
|
+
const receiver = await cdp.evm.createAccount({ name: "Receiver" });
|
|
350
|
+
|
|
351
|
+
const { status } = await sender.transfer({
|
|
352
|
+
to: receiver,
|
|
353
|
+
amount: "0.01",
|
|
354
|
+
token: "usdc",
|
|
355
|
+
network: "base-sepolia",
|
|
356
|
+
});
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Account Actions
|
|
360
|
+
|
|
361
|
+
Account objects have actions that can be used to interact with the account. These can be used in place of the `cdp` client.
|
|
362
|
+
|
|
363
|
+
For example, instead of:
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
const balances = await cdp.evm.listTokenBalances({
|
|
367
|
+
address: account.address,
|
|
368
|
+
network: "base-sepolia",
|
|
369
|
+
});
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
You can use the `listTokenBalances` action:
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
const account = await cdp.evm.createAccount();
|
|
376
|
+
const balances = await account.listTokenBalances({ network: "base-sepolia" });
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
EvmAccount supports the following actions:
|
|
380
|
+
|
|
381
|
+
- `listTokenBalances`
|
|
382
|
+
- `requestFaucet`
|
|
383
|
+
- `signTransaction`
|
|
384
|
+
- `sendTransaction`
|
|
385
|
+
- `transfer`
|
|
386
|
+
|
|
387
|
+
EvmSmartAccount supports the following actions:
|
|
388
|
+
|
|
389
|
+
- `listTokenBalances`
|
|
390
|
+
- `requestFaucet`
|
|
391
|
+
- `sendUserOperation`
|
|
392
|
+
- `waitForUserOperation`
|
|
393
|
+
- `transfer`
|
|
394
|
+
|
|
274
395
|
## Authentication tools
|
|
275
396
|
|
|
276
397
|
This SDK also contains simple tools for authenticating REST API requests to the [Coinbase Developer Platform (CDP)](https://docs.cdp.coinbase.com/). See the [Auth README](src/auth/README.md) for more details.
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toEvmServerAccount = toEvmServerAccount;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
+
const listTokenBalances_js_1 = require("../../actions/evm/listTokenBalances.js");
|
|
6
|
+
const requestFaucet_js_1 = require("../../actions/evm/requestFaucet.js");
|
|
7
|
+
const sendTransaction_js_1 = require("../../actions/evm/sendTransaction.js");
|
|
8
|
+
const accountTransferStrategy_js_1 = require("../../actions/evm/transfer/accountTransferStrategy.js");
|
|
9
|
+
const transfer_js_1 = require("../../actions/evm/transfer/transfer.js");
|
|
5
10
|
/**
|
|
6
11
|
* Creates a Server-managed EvmAccount instance from an existing EvmAccount.
|
|
7
12
|
* Use this to interact with previously deployed EvmAccounts, rather than creating new ones.
|
|
@@ -35,6 +40,27 @@ function toEvmServerAccount(apiClient, options) {
|
|
|
35
40
|
async signTypedData() {
|
|
36
41
|
throw new Error("Not implemented");
|
|
37
42
|
},
|
|
43
|
+
async transfer(transferArgs) {
|
|
44
|
+
return (0, transfer_js_1.transfer)(apiClient, account, transferArgs, accountTransferStrategy_js_1.accountTransferStrategy);
|
|
45
|
+
},
|
|
46
|
+
async listTokenBalances(options) {
|
|
47
|
+
return (0, listTokenBalances_js_1.listTokenBalances)(apiClient, {
|
|
48
|
+
...options,
|
|
49
|
+
address: this.address,
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async requestFaucet(options) {
|
|
53
|
+
return (0, requestFaucet_js_1.requestFaucet)(apiClient, {
|
|
54
|
+
...options,
|
|
55
|
+
address: this.address,
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
async sendTransaction(options) {
|
|
59
|
+
return (0, sendTransaction_js_1.sendTransaction)(apiClient, {
|
|
60
|
+
...options,
|
|
61
|
+
address: this.address,
|
|
62
|
+
});
|
|
63
|
+
},
|
|
38
64
|
name: options.account.name,
|
|
39
65
|
type: "evm-server",
|
|
40
66
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toEvmServerAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmServerAccount.ts"],"names":[],"mappings":";;AAuCA,gDA4DC;AAnGD,+BAAoF;AAEpF,iFAIgD;AAChD,yEAI4C;AAC5C,6EAAuE;AACvE,sGAAgG;AAChG,wEAAkE;AAgBlE;;;;;;;;GAQG;AACH,SAAgB,kBAAkB,CAChC,SAA+B,EAC/B,OAAkC;IAElC,MAAM,OAAO,GAAqB;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAkB;QAC3C,KAAK,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE;YAC3B,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;gBACrE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;aAC5B,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,SAAgB,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,UAA0B;YACnC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;gBAClE,IAAI,EAAE,UAAU,CAAC,IAAI;aACtB,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,SAAgB,CAAC;QACjC,CAAC;QAED,KAAK,CAAC,eAAe,CAAC,WAAoC;YACxD,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE;gBACzE,WAAW,EAAE,IAAA,2BAAoB,EAAC,WAAW,CAAC;aAC/C,CAAC,CAAC;YACH,OAAO,MAAM,CAAC,iBAAwB,CAAC;QACzC,CAAC;QAED,KAAK,CAAC,aAAa;YACjB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,YAAY;YACzB,OAAO,IAAA,sBAAQ,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,oDAAuB,CAAC,CAAC;QAC7E,CAAC;QACD,KAAK,CAAC,iBAAiB,CACrB,OAAkD;YAElD,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CACjB,OAA8C;YAE9C,OAAO,IAAA,gCAAa,EAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,eAAe,CAAC,OAAgD;YACpE,OAAO,IAAA,oCAAe,EAAC,SAAS,EAAE;gBAChC,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,IAAI,EAAE,YAAY;KACnB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,22 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toEvmSmartAccount = toEvmSmartAccount;
|
|
4
|
+
const listTokenBalances_js_1 = require("../../actions/evm/listTokenBalances.js");
|
|
5
|
+
const requestFaucet_js_1 = require("../../actions/evm/requestFaucet.js");
|
|
6
|
+
const sendUserOperation_js_1 = require("../../actions/evm/sendUserOperation.js");
|
|
7
|
+
const smartAccountTransferStrategy_js_1 = require("../../actions/evm/transfer/smartAccountTransferStrategy.js");
|
|
8
|
+
const transfer_js_1 = require("../../actions/evm/transfer/transfer.js");
|
|
9
|
+
const waitForUserOperation_js_1 = require("../../actions/evm/waitForUserOperation.js");
|
|
4
10
|
/**
|
|
5
11
|
* Creates a EvmSmartAccount instance from an existing EvmSmartAccount and owner.
|
|
6
12
|
* Use this to interact with previously deployed EvmSmartAccounts, rather than creating new ones.
|
|
7
13
|
*
|
|
8
14
|
* The owner must be the original owner of the evm smart account.
|
|
9
15
|
*
|
|
16
|
+
* @param {CdpOpenApiClientType} apiClient - The API client.
|
|
10
17
|
* @param {ToEvmSmartAccountOptions} options - Configuration options.
|
|
11
18
|
* @param {EvmSmartAccount} options.smartAccount - The deployed evm smart account.
|
|
12
19
|
* @param {EvmAccount} options.owner - The owner which signs for the smart account.
|
|
13
20
|
* @returns {EvmSmartAccount} A configured EvmSmartAccount instance ready for user operation submission.
|
|
14
|
-
* @throws {Error} If the account is not an original owner of the smart account.
|
|
15
21
|
*/
|
|
16
|
-
function toEvmSmartAccount(options) {
|
|
22
|
+
function toEvmSmartAccount(apiClient, options) {
|
|
17
23
|
const account = {
|
|
18
24
|
address: options.smartAccount.address,
|
|
19
25
|
owners: [options.owner],
|
|
26
|
+
async transfer(transferArgs) {
|
|
27
|
+
return (0, transfer_js_1.transfer)(apiClient, account, transferArgs, smartAccountTransferStrategy_js_1.smartAccountTransferStrategy);
|
|
28
|
+
},
|
|
29
|
+
async listTokenBalances(options) {
|
|
30
|
+
return (0, listTokenBalances_js_1.listTokenBalances)(apiClient, {
|
|
31
|
+
...options,
|
|
32
|
+
address: this.address,
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
async sendUserOperation(options) {
|
|
36
|
+
return (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
37
|
+
...options,
|
|
38
|
+
smartAccount: account,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
async waitForUserOperation(options) {
|
|
42
|
+
return (0, waitForUserOperation_js_1.waitForUserOperation)(apiClient, {
|
|
43
|
+
...options,
|
|
44
|
+
smartAccountAddress: account.address,
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
async requestFaucet(options) {
|
|
48
|
+
return (0, requestFaucet_js_1.requestFaucet)(apiClient, {
|
|
49
|
+
...options,
|
|
50
|
+
address: account.address,
|
|
51
|
+
});
|
|
52
|
+
},
|
|
20
53
|
name: options.smartAccount.name,
|
|
21
54
|
type: "evm-smart",
|
|
22
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":";;AAqDA,8CA+CC;AApGD,iFAIgD;AAChD,yEAI4C;AAC5C,iFAIgD;AAChD,gHAA0G;AAC1G,wEAAkE;AAClE,uFAImD;AAoBnD;;;;;;;;;;;GAWG;AACH,SAAgB,iBAAiB,CAC/B,SAA+B,EAC/B,OAAiC;IAEjC,MAAM,OAAO,GAAoB;QAC/B,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,OAAkB;QAChD,MAAM,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,YAAY;YACzB,OAAO,IAAA,sBAAQ,EAAC,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,8DAA4B,CAAC,CAAC;QAClF,CAAC;QACD,KAAK,CAAC,iBAAiB,CACrB,OAAkD;YAElD,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,OAAO,EAAE,IAAI,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,iBAAiB,CACrB,OAAkE;YAElE,OAAO,IAAA,wCAAiB,EAAC,SAAS,EAAE;gBAClC,GAAG,OAAO;gBACV,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,oBAAoB,CACxB,OAAiE;YAEjE,OAAO,IAAA,8CAAoB,EAAC,SAAS,EAAE;gBACrC,GAAG,OAAO;gBACV,mBAAmB,EAAE,OAAO,CAAC,OAAO;aACrC,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,aAAa,CACjB,OAA8C;YAE9C,OAAO,IAAA,gCAAa,EAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listTokenBalances = listTokenBalances;
|
|
4
|
+
/**
|
|
5
|
+
* List the token balances for an EVM account.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The client to use to list the token balances.
|
|
8
|
+
* @param options - The options for listing the token balances.
|
|
9
|
+
* @returns The result of listing the token balances.
|
|
10
|
+
*/
|
|
11
|
+
async function listTokenBalances(client, options) {
|
|
12
|
+
const response = await client.listEvmTokenBalances(options.network, options.address, {
|
|
13
|
+
pageSize: options.pageSize,
|
|
14
|
+
pageToken: options.pageToken,
|
|
15
|
+
});
|
|
16
|
+
const balances = response.balances.map(balance => {
|
|
17
|
+
return {
|
|
18
|
+
token: {
|
|
19
|
+
network: balance.token.network,
|
|
20
|
+
contractAddress: balance.token.contractAddress,
|
|
21
|
+
},
|
|
22
|
+
amount: {
|
|
23
|
+
amount: BigInt(balance.amount.amount),
|
|
24
|
+
decimals: BigInt(balance.amount.decimals),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
balances,
|
|
30
|
+
nextPageToken: response.nextPageToken,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=listTokenBalances.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listTokenBalances.js","sourceRoot":"","sources":["../../../actions/evm/listTokenBalances.ts"],"names":[],"mappings":";;AAgFA,8CA0BC;AAjCD;;;;;;GAMG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAA4B,EAC5B,OAAiC;IAEjC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;QACnF,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QAC/C,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO;gBAC9B,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC,eAA0B;aAC1D;YACD,MAAM,EAAE;gBACN,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;gBACrC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;aAC1C;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;QACR,aAAa,EAAE,QAAQ,CAAC,aAAa;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestFaucet = requestFaucet;
|
|
4
|
+
/**
|
|
5
|
+
* Requests funds from an EVM faucet.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client.
|
|
8
|
+
* @param options - The options for requesting funds from the EVM faucet.
|
|
9
|
+
*
|
|
10
|
+
* @returns A promise that resolves to the transaction hash.
|
|
11
|
+
*/
|
|
12
|
+
async function requestFaucet(apiClient, options) {
|
|
13
|
+
const { transactionHash } = await apiClient.requestEvmFaucet({ address: options.address, network: options.network, token: options.token }, options.idempotencyKey);
|
|
14
|
+
return {
|
|
15
|
+
transactionHash: transactionHash,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=requestFaucet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestFaucet.js","sourceRoot":"","sources":["../../../actions/evm/requestFaucet.ts"],"names":[],"mappings":";;AAiCA,sCAYC;AApBD;;;;;;;GAOG;AACI,KAAK,UAAU,aAAa,CACjC,SAA+B,EAC/B,OAA6B;IAE7B,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAC1D,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,EAC5E,OAAO,CAAC,cAAc,CACvB,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,eAAsB;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendTransaction = sendTransaction;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
/**
|
|
6
|
+
* Sends an EVM transaction.
|
|
7
|
+
*
|
|
8
|
+
* @param apiClient - The API client.
|
|
9
|
+
* @param options - The options for sending the transaction.
|
|
10
|
+
*
|
|
11
|
+
* @returns The result of the transaction.
|
|
12
|
+
*/
|
|
13
|
+
async function sendTransaction(apiClient, options) {
|
|
14
|
+
const { address, network, idempotencyKey } = options;
|
|
15
|
+
let transaction = options.transaction;
|
|
16
|
+
if (typeof transaction !== "string") {
|
|
17
|
+
transaction = (0, viem_1.serializeTransaction)({
|
|
18
|
+
...transaction,
|
|
19
|
+
// chainId is ignored in favor of network
|
|
20
|
+
chainId: 1,
|
|
21
|
+
type: "eip1559",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const result = await apiClient.sendEvmTransaction(address, { transaction, network }, idempotencyKey);
|
|
25
|
+
return {
|
|
26
|
+
transactionHash: result.transactionHash,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=sendTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendTransaction.js","sourceRoot":"","sources":["../../../actions/evm/sendTransaction.ts"],"names":[],"mappings":";;AA+CA,0CAyBC;AAxED,+BAAuE;AAuCvE;;;;;;;GAOG;AACI,KAAK,UAAU,eAAe,CACnC,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IACrD,IAAI,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAEtC,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;QACpC,WAAW,GAAG,IAAA,2BAAoB,EAAC;YACjC,GAAG,WAAW;YACd,yCAAyC;YACzC,OAAO,EAAE,CAAC;YACV,IAAI,EAAE,SAAS;SAChB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAC/C,OAAO,EACP,EAAE,WAAW,EAAE,OAAO,EAAE,EACxB,cAAc,CACf,CAAC;IAEF,OAAO;QACL,eAAe,EAAE,MAAM,CAAC,eAAsB;KAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -39,11 +39,10 @@ const viem_1 = require("viem");
|
|
|
39
39
|
* ```
|
|
40
40
|
*
|
|
41
41
|
* @param {CdpOpenApiClientType} client - The client to use to send the user operation.
|
|
42
|
-
* @param {EvmSmartAccount} smartAccount - The smart account to send the user operation from.
|
|
43
42
|
* @param {SendUserOperationOptions<T>} options - The options for the user operation.
|
|
44
43
|
* @returns {Promise<SendUserOperationReturnType>} The result of the user operation.
|
|
45
44
|
*/
|
|
46
|
-
async function sendUserOperation(client,
|
|
45
|
+
async function sendUserOperation(client, options) {
|
|
47
46
|
const { calls, network, paymasterUrl } = options;
|
|
48
47
|
if (calls.length === 0) {
|
|
49
48
|
throw new Error("Calls array is empty");
|
|
@@ -67,20 +66,20 @@ async function sendUserOperation(client, smartAccount, options) {
|
|
|
67
66
|
value,
|
|
68
67
|
};
|
|
69
68
|
});
|
|
70
|
-
const createOpResponse = await client.prepareUserOperation(smartAccount.address, {
|
|
69
|
+
const createOpResponse = await client.prepareUserOperation(options.smartAccount.address, {
|
|
71
70
|
network,
|
|
72
71
|
calls: encodedCalls,
|
|
73
72
|
paymasterUrl,
|
|
74
73
|
});
|
|
75
|
-
const owner = smartAccount.owners[0];
|
|
74
|
+
const owner = options.smartAccount.owners[0];
|
|
76
75
|
const signature = await owner.sign({
|
|
77
76
|
hash: createOpResponse.userOpHash,
|
|
78
77
|
});
|
|
79
|
-
const broadcastResponse = await client.sendUserOperation(smartAccount.address, createOpResponse.userOpHash, {
|
|
78
|
+
const broadcastResponse = await client.sendUserOperation(options.smartAccount.address, createOpResponse.userOpHash, {
|
|
80
79
|
signature,
|
|
81
80
|
}, options.idempotencyKey);
|
|
82
81
|
return {
|
|
83
|
-
smartAccountAddress: smartAccount.address,
|
|
82
|
+
smartAccountAddress: options.smartAccount.address,
|
|
84
83
|
status: broadcastResponse.status,
|
|
85
84
|
userOpHash: createOpResponse.userOpHash,
|
|
86
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendUserOperation.js","sourceRoot":"","sources":["../../../actions/evm/sendUserOperation.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sendUserOperation.js","sourceRoot":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YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE7C,MAAM,SAAS,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC;QACjC,IAAI,EAAE,gBAAgB,CAAC,UAAiB;KACzC,CAAC,CAAC;IAEH,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,iBAAiB,CACtD,OAAO,CAAC,YAAY,CAAC,OAAO,EAC5B,gBAAgB,CAAC,UAAiB,EAClC;QACE,SAAS;KACV,EACD,OAAO,CAAC,cAAc,CACvB,CAAC;IAEF,OAAO;QACL,mBAAmB,EAAE,OAAO,CAAC,YAAY,CAAC,OAAO;QACjD,MAAM,EAAE,iBAAiB,CAAC,MAAM;QAChC,UAAU,EAAE,gBAAgB,CAAC,UAAU;KACT,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.accountTransferStrategy = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const serializeTransaction_js_1 = require("../../../utils/serializeTransaction.js");
|
|
7
|
+
exports.accountTransferStrategy = {
|
|
8
|
+
executeTransfer: async ({ apiClient, from, transferArgs, to, value }) => {
|
|
9
|
+
const transactionHash = await (async () => {
|
|
10
|
+
if (transferArgs.token === "eth") {
|
|
11
|
+
const result = await apiClient.sendEvmTransaction(from.address, {
|
|
12
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
13
|
+
value,
|
|
14
|
+
to,
|
|
15
|
+
}),
|
|
16
|
+
network: transferArgs.network,
|
|
17
|
+
});
|
|
18
|
+
return result.transactionHash;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const erc20Address = (0, utils_js_1.getErc20Address)(transferArgs.token, transferArgs.network);
|
|
22
|
+
await apiClient.sendEvmTransaction(from.address, {
|
|
23
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
24
|
+
to: erc20Address,
|
|
25
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
26
|
+
abi: viem_1.erc20Abi,
|
|
27
|
+
functionName: "approve",
|
|
28
|
+
args: [to, value],
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
31
|
+
network: transferArgs.network,
|
|
32
|
+
});
|
|
33
|
+
const result = await apiClient.sendEvmTransaction(from.address, {
|
|
34
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
35
|
+
to: erc20Address,
|
|
36
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
37
|
+
abi: viem_1.erc20Abi,
|
|
38
|
+
functionName: "transfer",
|
|
39
|
+
args: [to, value],
|
|
40
|
+
}),
|
|
41
|
+
}),
|
|
42
|
+
network: transferArgs.network,
|
|
43
|
+
});
|
|
44
|
+
return result.transactionHash;
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
return transactionHash;
|
|
48
|
+
},
|
|
49
|
+
waitForResult: async ({ publicClient, hash }) => {
|
|
50
|
+
let receipt;
|
|
51
|
+
try {
|
|
52
|
+
receipt = await publicClient.waitForTransactionReceipt({
|
|
53
|
+
hash,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
if (error instanceof viem_1.WaitForTransactionReceiptTimeoutError) {
|
|
58
|
+
throw new Error(`Transaction timed out. Check the transaction on the explorer: ${publicClient.chain.blockExplorers?.default.url}/tx/${hash}`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (receipt.status === "success") {
|
|
65
|
+
return { status: receipt.status, transactionHash: hash };
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error(`Transaction failed. Check the transaction on the explorer: ${publicClient.chain.blockExplorers?.default.url}/tx/${hash}`);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=accountTransferStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAMc;AAGd,yCAA6C;AAE7C,oFAAqF;AAExE,QAAA,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QACtE,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE;YACxC,IAAI,YAAY,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACjC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;oBAC9D,WAAW,EAAE,IAAA,qDAA2B,EAAC;wBACvC,KAAK;wBACL,EAAE;qBACH,CAAC;oBACF,OAAO,EAAE,YAAY,CAAC,OAAO;iBAC9B,CAAC,CAAC;gBACH,OAAO,MAAM,CAAC,eAAsB,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;gBAE/E,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;oBAC/C,WAAW,EAAE,IAAA,qDAA2B,EAAC;wBACvC,EAAE,EAAE,YAAY;wBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;4BACvB,GAAG,EAAE,eAAQ;4BACb,YAAY,EAAE,SAAS;4BACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;yBAClB,CAAC;qBACH,CAAC;oBACF,OAAO,EAAE,YAAY,CAAC,OAAO;iBAC9B,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,MAAM,SAAS,C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,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.smartAccountTransferStrategy = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const sendUserOperation_js_1 = require("../sendUserOperation.js");
|
|
7
|
+
const waitForUserOperation_js_1 = require("../waitForUserOperation.js");
|
|
8
|
+
exports.smartAccountTransferStrategy = {
|
|
9
|
+
executeTransfer: async ({ apiClient, from, transferArgs, to, value }) => {
|
|
10
|
+
const userOpHash = await (async () => {
|
|
11
|
+
if (transferArgs.token === "eth") {
|
|
12
|
+
const result = await (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
13
|
+
smartAccount: from,
|
|
14
|
+
network: transferArgs.network,
|
|
15
|
+
calls: [
|
|
16
|
+
{
|
|
17
|
+
to,
|
|
18
|
+
value,
|
|
19
|
+
data: "0x",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
return result.userOpHash;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const erc20Address = (0, utils_js_1.getErc20Address)(transferArgs.token, transferArgs.network);
|
|
27
|
+
const result = await (0, sendUserOperation_js_1.sendUserOperation)(apiClient, {
|
|
28
|
+
smartAccount: from,
|
|
29
|
+
network: transferArgs.network,
|
|
30
|
+
calls: [
|
|
31
|
+
{
|
|
32
|
+
to: erc20Address,
|
|
33
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
34
|
+
abi: viem_1.erc20Abi,
|
|
35
|
+
functionName: "approve",
|
|
36
|
+
args: [to, value],
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
to: erc20Address,
|
|
41
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
42
|
+
abi: viem_1.erc20Abi,
|
|
43
|
+
functionName: "transfer",
|
|
44
|
+
args: [to, value],
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
return result.userOpHash;
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
return userOpHash;
|
|
53
|
+
},
|
|
54
|
+
waitForResult: async ({ apiClient, publicClient, from, hash }) => {
|
|
55
|
+
const result = await (0, waitForUserOperation_js_1.waitForUserOperation)(apiClient, {
|
|
56
|
+
smartAccountAddress: from.address,
|
|
57
|
+
userOpHash: hash,
|
|
58
|
+
});
|
|
59
|
+
if (result.status === "complete") {
|
|
60
|
+
return { status: "success", transactionHash: hash };
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw new Error(`Transaction failed. Check the transaction on the explorer: ${publicClient.chain.blockExplorers?.default.url}/tx/${hash}`);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=smartAccountTransferStrategy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartAccountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/smartAccountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAAoD;AAGpD,yCAA6C;AAE7C,kEAA4D;AAC5D,wEAAkE;AAErD,QAAA,4BAA4B,GAA+C;IACtF,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;QACtE,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE;YACnC,IAAI,YAAY,CAAC,KAAK,KAAK,KAAK,EAAE,CAAC;gBACjC,MAAM,MAAM,GAAG,MAAM,IAAA,wCAAiB,EAAC,SAAS,EAAE;oBAChD,YAAY,EAAE,IAAI;oBAClB,OAAO,EAAE,YAAY,CAAC,OAAO;oBAC7B,KAAK,EAAE;wBACL;4BACE,EAAE;4BACF,KAAK;4BACL,IAAI,EAAE,IAAI;yBACX;qBAC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AC;YACN,MAAM,IAAI,KAAK,CACb,8DAA8D,YAAY,CAAC,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,OAAO,IAAI,EAAE,CAC1H,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transfer = transfer;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Transfer an amount of a token from an account to another account.
|
|
8
|
+
*
|
|
9
|
+
* @param apiClient - The client to use to send the transaction.
|
|
10
|
+
* @param from - The account to send the transaction from.
|
|
11
|
+
* @param transferArgs - The options for the transfer.
|
|
12
|
+
* @param transferStrategy - The strategy to use to execute the transfer.
|
|
13
|
+
* @returns The result of the transfer.
|
|
14
|
+
*/
|
|
15
|
+
async function transfer(apiClient, from, transferArgs, transferStrategy) {
|
|
16
|
+
const publicClient = (0, viem_1.createPublicClient)({
|
|
17
|
+
chain: (0, utils_js_1.mapNetworkToChain)(transferArgs.network),
|
|
18
|
+
transport: (0, viem_1.http)(),
|
|
19
|
+
});
|
|
20
|
+
const to = typeof transferArgs.to === "string" ? transferArgs.to : transferArgs.to.address;
|
|
21
|
+
const value = await (async () => {
|
|
22
|
+
// user supplied a bigint. otherwise, we need to convert the amount to a bigint
|
|
23
|
+
if (typeof transferArgs.amount !== "string") {
|
|
24
|
+
return transferArgs.amount;
|
|
25
|
+
}
|
|
26
|
+
const decimals = await (async () => {
|
|
27
|
+
if (transferArgs.token === "eth") {
|
|
28
|
+
return 18;
|
|
29
|
+
}
|
|
30
|
+
else if (transferArgs.token === "usdc") {
|
|
31
|
+
return 6;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return publicClient.readContract({
|
|
35
|
+
address: transferArgs.token,
|
|
36
|
+
abi: viem_1.erc20Abi,
|
|
37
|
+
functionName: "decimals",
|
|
38
|
+
args: [],
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
return (0, viem_1.parseUnits)(transferArgs.amount, decimals);
|
|
43
|
+
})();
|
|
44
|
+
const hash = await transferStrategy.executeTransfer({
|
|
45
|
+
apiClient,
|
|
46
|
+
from,
|
|
47
|
+
transferArgs,
|
|
48
|
+
to,
|
|
49
|
+
value,
|
|
50
|
+
});
|
|
51
|
+
const result = await transferStrategy.waitForResult({
|
|
52
|
+
apiClient,
|
|
53
|
+
publicClient,
|
|
54
|
+
from,
|
|
55
|
+
hash,
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=transfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transfer.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/transfer.ts"],"names":[],"mappings":";;AAgBA,4BAsDC;AAtED,+BAAiG;AAGjG,yCAA+C;AAI/C;;;;;;;;GAQG;AACI,KAAK,UAAU,QAAQ,CAC5B,SAA+B,EAC/B,IAAO,EACP,YAA6B,EAC7B,gBAA8C;IAE9C,MAAM,YAAY,GAAG,IAAA,yBAAkB,EAAmB;QACxD,KAAK,EAAE,IAAA,4BAAiB,EAAC,YAAY,CAAC,OAAO,CAAC;QAC9C,SAAS,EAAE,IAAA,WAAI,GAAE;KAClB,CAAC,CAAC;IAEH,MAAM,EAAE,GACN,OAAO,YAAY,CAAC,EAAE,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC,CAAE,YAAY,CAAC,EAAE,CAAC,OAAmB,CAAC;IAE/F,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE;QAC9B,+EAA+E;QAC/E,IAAI,OAAO,YAAY,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC5C,OAAO,YAAY,CAAC,MAAM,CAAC;QAC7B,CAAC;QAED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