@coinbase/cdp-sdk 1.7.0 → 1.9.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 +326 -28
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +8 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +2 -39
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/evm/transfer/utils.js +0 -12
- package/_cjs/actions/evm/transfer/utils.js.map +1 -1
- package/_cjs/actions/solana/constants.js +9 -0
- package/_cjs/actions/solana/constants.js.map +1 -0
- package/_cjs/actions/solana/transfer.js +117 -0
- package/_cjs/actions/solana/transfer.js.map +1 -0
- package/_cjs/actions/solana/utils.js +66 -0
- package/_cjs/actions/solana/utils.js.map +1 -0
- package/_cjs/analytics.js +70 -8
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +9 -3
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +133 -15
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/index.js +6 -0
- package/_cjs/client/policies/index.js.map +1 -0
- package/_cjs/client/policies/policies.js +232 -0
- package/_cjs/client/policies/policies.js.map +1 -0
- package/_cjs/client/policies/policies.types.js +3 -0
- package/_cjs/client/policies/policies.types.js.map +1 -0
- package/_cjs/client/solana/solana.js +76 -19
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +4 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +35 -4
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +56 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +2 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +14 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +42 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +6 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +245 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/policies/types.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +4 -2
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +8 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +2 -39
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/evm/transfer/utils.js +0 -11
- package/_esm/actions/evm/transfer/utils.js.map +1 -1
- package/_esm/actions/solana/constants.js +6 -0
- package/_esm/actions/solana/constants.js.map +1 -0
- package/_esm/actions/solana/transfer.js +114 -0
- package/_esm/actions/solana/transfer.js.map +1 -0
- package/_esm/actions/solana/utils.js +61 -0
- package/_esm/actions/solana/utils.js.map +1 -0
- package/_esm/analytics.js +70 -7
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +10 -4
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +133 -15
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/index.js +2 -0
- package/_esm/client/policies/index.js.map +1 -0
- package/_esm/client/policies/policies.js +228 -0
- package/_esm/client/policies/policies.js.map +1 -0
- package/_esm/client/policies/policies.types.js +2 -0
- package/_esm/client/policies/policies.types.js.map +1 -0
- package/_esm/client/solana/solana.js +76 -19
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +34 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +51 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +2 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +12 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +39 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +5 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +242 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/policies/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -3
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +6 -4
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +8 -54
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/transfer/utils.d.ts +0 -619
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +140 -68
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/constants.d.ts +6 -0
- package/_types/actions/solana/constants.d.ts.map +1 -0
- package/_types/actions/solana/transfer.d.ts +36 -0
- package/_types/actions/solana/transfer.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +27 -0
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +34 -0
- package/_types/actions/solana/utils.d.ts.map +1 -0
- package/_types/analytics.d.ts +14 -5
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +3 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +89 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +33 -3
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/index.d.ts +2 -0
- package/_types/client/policies/index.d.ts.map +1 -0
- package/_types/client/policies/policies.d.ts +216 -0
- package/_types/client/policies/policies.d.ts.map +1 -0
- package/_types/client/policies/policies.types.d.ts +96 -0
- package/_types/client/policies/policies.types.d.ts.map +1 -0
- package/_types/client/solana/solana.d.ts +43 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +14 -2
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +176 -17
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +3 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +2 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +18 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +1552 -0
- package/_types/policies/schema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +19 -0
- package/_types/policies/types.d.ts.map +1 -0
- package/_types/types/misc.d.ts +39 -0
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +11 -7
- package/accounts/evm/toEvmSmartAccount.ts +1 -2
- package/accounts/evm/types.ts +6 -8
- package/accounts/solana/toSolanaAccount.ts +8 -0
- package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
- package/actions/evm/transfer/transfer.ts +10 -51
- package/actions/evm/transfer/types.ts +9 -67
- package/actions/evm/transfer/utils.ts +0 -13
- package/actions/evm/types.ts +143 -78
- package/actions/solana/constants.ts +6 -0
- package/actions/solana/transfer.ts +219 -0
- package/actions/solana/types.ts +28 -0
- package/actions/solana/utils.ts +79 -0
- package/analytics.ts +86 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +159 -17
- package/client/evm/evm.types.ts +38 -1
- package/client/policies/index.ts +1 -0
- package/client/policies/policies.ts +246 -0
- package/client/policies/policies.types.ts +109 -0
- package/client/solana/solana.ts +94 -20
- package/client/solana/solana.types.ts +16 -1
- package/index.ts +7 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +220 -18
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +102 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +43 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -1
- package/openapi-client/generated/index.msw.ts +2 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +75 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +23 -0
- package/openapi-client/index.ts +6 -0
- package/package.json +4 -2
- package/policies/schema.ts +349 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# CDP SDK Changelog
|
|
2
2
|
|
|
3
|
+
## 1.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#128](https://github.com/coinbase/cdp-sdk/pull/128) [`bd4d1d6`](https://github.com/coinbase/cdp-sdk/commit/bd4d1d6855627e24bd4b51937e40df27a2595559) Thanks [@0xRAG](https://github.com/0xRAG)! - Added transfer method to Solana account to easily send tokens on Solana
|
|
8
|
+
|
|
9
|
+
- [#133](https://github.com/coinbase/cdp-sdk/pull/133) [`438d967`](https://github.com/coinbase/cdp-sdk/commit/438d967401c06469bfc44c581a6c0994f77c0f9e) Thanks [@0xRAG](https://github.com/0xRAG)! - Updated Transfer API to allow users to wait for receipt and pass in a parsed amount to transfer
|
|
10
|
+
|
|
11
|
+
- [#141](https://github.com/coinbase/cdp-sdk/pull/141) [`c0273f9`](https://github.com/coinbase/cdp-sdk/commit/c0273f96769f74c78cddbbf0b109dc47cc16b7ca) Thanks [@sammccord](https://github.com/sammccord)! - Added SendEvmTransactionRule to Policy Rules
|
|
12
|
+
|
|
13
|
+
## 1.8.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#124](https://github.com/coinbase/cdp-sdk/pull/124) [`9b874f8`](https://github.com/coinbase/cdp-sdk/commit/9b874f85b8b21fa8f5ab2b724413cdd41a5423ea) Thanks [@sammccord](https://github.com/sammccord)! - Added all Policy Engine functionality; CRUD operations and zod schemas
|
|
18
|
+
|
|
19
|
+
- [#130](https://github.com/coinbase/cdp-sdk/pull/130) [`3274e09`](https://github.com/coinbase/cdp-sdk/commit/3274e099612209daf756e0c06857ea29f880318c) Thanks [@sammccord](https://github.com/sammccord)! - Added updateAccount for evm and solana namespaces, as well as account.policies on response types
|
|
20
|
+
|
|
21
|
+
- [#129](https://github.com/coinbase/cdp-sdk/pull/129) [`b4f6b43`](https://github.com/coinbase/cdp-sdk/commit/b4f6b43d936a9e87eed488ea236bf74851241d65) Thanks [@sddioulde](https://github.com/sddioulde)! - Added support for eip-712 signing
|
|
22
|
+
|
|
3
23
|
## 1.7.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- [Installation](#installation)
|
|
8
8
|
- [API Keys](#api-keys)
|
|
9
9
|
- [Usage](#usage)
|
|
10
|
+
- [Policy Management](#policy-management)
|
|
10
11
|
- [Authentication tools](#authentication-tools)
|
|
11
12
|
- [Error Reporting](#error-reporting)
|
|
12
13
|
- [License](#license)
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
|
|
21
22
|
## CDP SDK
|
|
22
23
|
|
|
23
|
-
This module contains the TypeScript CDP SDK, which is a library that provides a client for interacting with the [Coinbase Developer Platform (CDP)](https://docs.cdp.coinbase.com/). It includes a CDP Client for interacting with EVM and Solana APIs to create accounts and send transactions, as well as authentication tools for interacting directly with the CDP APIs.
|
|
24
|
+
This module contains the TypeScript CDP SDK, which is a library that provides a client for interacting with the [Coinbase Developer Platform (CDP)](https://docs.cdp.coinbase.com/). It includes a CDP Client for interacting with EVM and Solana APIs to create accounts and send transactions, policy APIs to govern transaction permissions, as well as authentication tools for interacting directly with the CDP APIs.
|
|
24
25
|
|
|
25
26
|
## Documentation
|
|
26
27
|
|
|
@@ -127,6 +128,32 @@ const account = await cdp.solana.getOrCreateAccount({
|
|
|
127
128
|
});
|
|
128
129
|
```
|
|
129
130
|
|
|
131
|
+
### Updating EVM or Solana accounts
|
|
132
|
+
|
|
133
|
+
#### Update an EVM account as follows:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const account = await cdp.evm.updateAccount({
|
|
137
|
+
addresss: account.address,
|
|
138
|
+
update: {
|
|
139
|
+
name: "Updated name",
|
|
140
|
+
accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412",
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Update a Solana account as follows:
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const account = await cdp.solana.updateAccount({
|
|
149
|
+
addresss: account.address,
|
|
150
|
+
update: {
|
|
151
|
+
name: "Updated name",
|
|
152
|
+
accountPolicy: "1622d4b7-9d60-44a2-9a6a-e9bbb167e412",
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
130
157
|
### Testnet faucet
|
|
131
158
|
|
|
132
159
|
You can use the faucet function to request testnet ETH or SOL from the CDP.
|
|
@@ -289,21 +316,37 @@ const userOperation = await cdp.sendUserOperation({
|
|
|
289
316
|
|
|
290
317
|
### Transferring tokens
|
|
291
318
|
|
|
292
|
-
|
|
319
|
+
#### EVM
|
|
320
|
+
|
|
321
|
+
For complete examples, check out [evm/account.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/account.transfer.ts) and [evm/smartAccount.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/evm/smartAccount.transfer.ts).
|
|
293
322
|
|
|
294
323
|
You can transfer tokens between accounts using the `transfer` function:
|
|
295
324
|
|
|
296
325
|
```typescript
|
|
297
326
|
const sender = await cdp.evm.createAccount({ name: "Sender" });
|
|
298
327
|
|
|
299
|
-
const {
|
|
328
|
+
const { transactionHash } = await sender.transfer({
|
|
300
329
|
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
301
|
-
amount:
|
|
330
|
+
amount: 10000n, // equivalent to 0.01 USDC
|
|
302
331
|
token: "usdc",
|
|
303
332
|
network: "base-sepolia",
|
|
304
333
|
});
|
|
305
334
|
```
|
|
306
335
|
|
|
336
|
+
You can then [wait for the transaction receipt with a viem Public Client](https://viem.sh/docs/actions/public/waitForTransactionReceipt#waitfortransactionreceipt):
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
import { createPublicClient, http } from "viem";
|
|
340
|
+
import { baseSepolia } from "viem/chains";
|
|
341
|
+
|
|
342
|
+
const publicClient = createPublicClient({
|
|
343
|
+
chain: baseSepolia,
|
|
344
|
+
transport: http(),
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: transactionHash });
|
|
348
|
+
```
|
|
349
|
+
|
|
307
350
|
Smart Accounts also have a `transfer` function:
|
|
308
351
|
|
|
309
352
|
```typescript
|
|
@@ -312,36 +355,48 @@ const sender = await cdp.evm.createSmartAccount({
|
|
|
312
355
|
});
|
|
313
356
|
console.log("Created smart account", sender);
|
|
314
357
|
|
|
315
|
-
const {
|
|
358
|
+
const { userOpHash } = await sender.transfer({
|
|
316
359
|
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
317
|
-
amount:
|
|
360
|
+
amount: 10000n, // equivalent to 0.01 USDC
|
|
318
361
|
token: "usdc",
|
|
319
362
|
network: "base-sepolia",
|
|
320
363
|
});
|
|
321
364
|
```
|
|
322
365
|
|
|
323
|
-
|
|
366
|
+
One difference is that the `transfer` function returns the user operation hash, which is different from the transaction hash. You can use the returned user operation hash in a call to `waitForUserOperation` to get the result of the transaction:
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
const receipt = await sender.waitForUserOperation({
|
|
370
|
+
hash: userOpHash,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
if (receipt.status === "complete") {
|
|
374
|
+
console.log(
|
|
375
|
+
`Transfer successful! Explorer link: https://sepolia.basescan.org/tx/${receipt.userOpHash}`,
|
|
376
|
+
);
|
|
377
|
+
} else {
|
|
378
|
+
console.log(`Something went wrong! User operation hash: ${receipt.userOpHash}`);
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Using Smart Accounts, you can also specify a paymaster URL:
|
|
324
383
|
|
|
325
384
|
```typescript
|
|
326
|
-
|
|
385
|
+
await sender.transfer({
|
|
327
386
|
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
328
387
|
amount: "0.01",
|
|
329
388
|
token: "usdc",
|
|
330
389
|
network: "base-sepolia",
|
|
331
390
|
paymasterUrl: "https://some-paymaster-url.com",
|
|
332
|
-
waitOptions: {
|
|
333
|
-
timeout: 30,
|
|
334
|
-
interval: 2,
|
|
335
|
-
},
|
|
336
391
|
});
|
|
337
392
|
```
|
|
338
393
|
|
|
339
|
-
|
|
394
|
+
Transfer amount must be passed as a bigint. To convert common tokens from whole units, you can use utilities such as [`parseEther`](https://viem.sh/docs/utilities/parseEther#parseether) and [`parseUnits`](https://viem.sh/docs/utilities/parseUnits#parseunits) from viem.
|
|
340
395
|
|
|
341
396
|
```typescript
|
|
342
|
-
|
|
397
|
+
await sender.transfer({
|
|
343
398
|
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
344
|
-
amount:
|
|
399
|
+
amount: parseUnits("0.01", 6), // USDC has 6 decimals
|
|
345
400
|
token: "usdc",
|
|
346
401
|
network: "base-sepolia",
|
|
347
402
|
});
|
|
@@ -350,9 +405,9 @@ const { status } = await sender.transfer({
|
|
|
350
405
|
You can pass `usdc` or `eth` as the token to transfer, or you can pass a contract address directly:
|
|
351
406
|
|
|
352
407
|
```typescript
|
|
353
|
-
|
|
408
|
+
await sender.transfer({
|
|
354
409
|
to: "0x9F663335Cd6Ad02a37B633602E98866CF944124d",
|
|
355
|
-
amount: "0.000001",
|
|
410
|
+
amount: parseUnits("0.000001", 18), // WETH has 18 decimals. equivalent to calling `parseEther("0.000001")`
|
|
356
411
|
token: "0x4200000000000000000000000000000000000006", // WETH on Base Sepolia
|
|
357
412
|
network: "base-sepolia",
|
|
358
413
|
});
|
|
@@ -364,26 +419,77 @@ You can also pass another account as the `to` parameter:
|
|
|
364
419
|
const sender = await cdp.evm.createAccount({ name: "Sender" });
|
|
365
420
|
const receiver = await cdp.evm.createAccount({ name: "Receiver" });
|
|
366
421
|
|
|
367
|
-
|
|
422
|
+
await sender.transfer({
|
|
368
423
|
to: receiver,
|
|
369
|
-
amount:
|
|
424
|
+
amount: 10000n, // equivalent to 0.01 USDC
|
|
370
425
|
token: "usdc",
|
|
371
426
|
network: "base-sepolia",
|
|
372
427
|
});
|
|
373
428
|
```
|
|
374
429
|
|
|
375
|
-
|
|
430
|
+
#### Solana
|
|
431
|
+
|
|
432
|
+
For complete examples, check out [solana/account.transfer.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/solana/account.transfer.ts).
|
|
433
|
+
|
|
434
|
+
You can transfer tokens between accounts using the `transfer` function, and wait for the transaction to be confirmed using the `confirmTransaction` function from `@solana/web3.js`:
|
|
376
435
|
|
|
377
436
|
```typescript
|
|
378
|
-
|
|
379
|
-
|
|
437
|
+
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
438
|
+
|
|
439
|
+
const sender = await cdp.solana.createAccount();
|
|
440
|
+
|
|
441
|
+
const connection = new Connection("https://api.devnet.solana.com");
|
|
442
|
+
|
|
443
|
+
const { signature } = await sender.transfer({
|
|
444
|
+
to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
|
|
445
|
+
amount: 0.01 * LAMPORTS_PER_SOL,
|
|
446
|
+
token: "sol",
|
|
447
|
+
network: connection,
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
|
|
451
|
+
|
|
452
|
+
const confirmation = await connection.confirmTransaction(
|
|
453
|
+
{
|
|
454
|
+
signature,
|
|
455
|
+
blockhash,
|
|
456
|
+
lastValidBlockHeight,
|
|
457
|
+
},
|
|
458
|
+
"confirmed",
|
|
459
|
+
);
|
|
460
|
+
|
|
461
|
+
if (confirmation.value.err) {
|
|
462
|
+
console.log(`Something went wrong! Error: ${confirmation.value.err.toString()}`);
|
|
463
|
+
} else {
|
|
464
|
+
console.log(
|
|
465
|
+
`Transaction confirmed: Link: https://explorer.solana.com/tx/${signature}?cluster=devnet`,
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
You can also easily send USDC:
|
|
471
|
+
|
|
472
|
+
```typescript
|
|
473
|
+
const { signature } = await sender.transfer({
|
|
474
|
+
to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
|
|
380
475
|
amount: "0.01",
|
|
381
476
|
token: "usdc",
|
|
382
|
-
network: "
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
477
|
+
network: "devnet",
|
|
478
|
+
});
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
If you want to use your own Connection, you can pass one to the `network` parameter:
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
import { Connection } from "@solana/web3.js";
|
|
485
|
+
|
|
486
|
+
const connection = new Connection("YOUR_RPC_URL");
|
|
487
|
+
|
|
488
|
+
const { signature } = await sender.transfer({
|
|
489
|
+
to: "3KzDtddx4i53FBkvCzuDmRbaMozTZoJBb1TToWhz3JfE",
|
|
490
|
+
amount: "0.01",
|
|
491
|
+
token: "usdc",
|
|
492
|
+
network: connection,
|
|
387
493
|
});
|
|
388
494
|
```
|
|
389
495
|
|
|
@@ -444,7 +550,7 @@ You can use the `signMessage` action:
|
|
|
444
550
|
```typescript
|
|
445
551
|
const account = await cdp.solana.createAccount();
|
|
446
552
|
const { signature } = await account.signMessage({
|
|
447
|
-
message: "Hello, world!"
|
|
553
|
+
message: "Hello, world!",
|
|
448
554
|
});
|
|
449
555
|
```
|
|
450
556
|
|
|
@@ -454,6 +560,198 @@ SolanaAccount supports the following actions:
|
|
|
454
560
|
- `signMessage`
|
|
455
561
|
- `signTransaction`
|
|
456
562
|
|
|
563
|
+
## Policy Management
|
|
564
|
+
|
|
565
|
+
You can use the policies SDK to manage sets of rules that govern the behavior of accounts and projects, such as enforce allowlists and denylists.
|
|
566
|
+
|
|
567
|
+
### Create a Project-level policy that applies to all accounts
|
|
568
|
+
|
|
569
|
+
This policy will accept any account sending less than a specific amount of ETH to a specific address.
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
const policy = await cdp.policies.createPolicy({
|
|
573
|
+
policy: {
|
|
574
|
+
scope: "project",
|
|
575
|
+
description: "Project-wide Allowlist Policy",
|
|
576
|
+
rules: [
|
|
577
|
+
{
|
|
578
|
+
action: "accept",
|
|
579
|
+
operation: "signEvmTransaction",
|
|
580
|
+
criteria: [
|
|
581
|
+
{
|
|
582
|
+
type: "ethValue",
|
|
583
|
+
ethValue: "1000000000000000000",
|
|
584
|
+
operator: "<=",
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
type: "evmAddress",
|
|
588
|
+
addresses: ["0x000000000000000000000000000000000000dEaD"],
|
|
589
|
+
operator: "in",
|
|
590
|
+
},
|
|
591
|
+
],
|
|
592
|
+
},
|
|
593
|
+
],
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### Create an Account-level policy
|
|
599
|
+
|
|
600
|
+
This policy will accept any transaction with a value less than or equal to 1 ETH to a specific address.
|
|
601
|
+
|
|
602
|
+
```typescript
|
|
603
|
+
const policy = await cdp.policies.createPolicy({
|
|
604
|
+
policy: {
|
|
605
|
+
scope: "account",
|
|
606
|
+
description: "Account Allowlist Policy",
|
|
607
|
+
rules: [
|
|
608
|
+
{
|
|
609
|
+
action: "accept",
|
|
610
|
+
operation: "signEvmTransaction",
|
|
611
|
+
criteria: [
|
|
612
|
+
{
|
|
613
|
+
type: "ethValue",
|
|
614
|
+
ethValue: "1000000000000000000",
|
|
615
|
+
operator: "<=",
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
type: "evmAddress",
|
|
619
|
+
addresses: ["0x000000000000000000000000000000000000dEaD"],
|
|
620
|
+
operator: "in",
|
|
621
|
+
},
|
|
622
|
+
],
|
|
623
|
+
},
|
|
624
|
+
],
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
```
|
|
628
|
+
|
|
629
|
+
### Create a Solana Allowlist Policy
|
|
630
|
+
|
|
631
|
+
```typescript
|
|
632
|
+
const policy = await cdp.policies.createPolicy({
|
|
633
|
+
policy: {
|
|
634
|
+
scope: "account",
|
|
635
|
+
description: "Account Allowlist Policy",
|
|
636
|
+
rules: [
|
|
637
|
+
{
|
|
638
|
+
action: "accept",
|
|
639
|
+
operation: "signSolTransaction",
|
|
640
|
+
criteria: [
|
|
641
|
+
{
|
|
642
|
+
type: "solAddress",
|
|
643
|
+
addresses: ["DtdSSG8ZJRZVv5Jx7K1MeWp7Zxcu19GD5wQRGRpQ9uMF"],
|
|
644
|
+
operator: "in",
|
|
645
|
+
},
|
|
646
|
+
],
|
|
647
|
+
},
|
|
648
|
+
],
|
|
649
|
+
},
|
|
650
|
+
});
|
|
651
|
+
```
|
|
652
|
+
|
|
653
|
+
### List Policies
|
|
654
|
+
|
|
655
|
+
You can filter by account:
|
|
656
|
+
|
|
657
|
+
```typescript
|
|
658
|
+
const policy = await cdp.policies.listPolicies({
|
|
659
|
+
scope: "account",
|
|
660
|
+
});
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
You can also filter by project:
|
|
664
|
+
|
|
665
|
+
```typescript
|
|
666
|
+
const policy = await cdp.policies.listPolicies({
|
|
667
|
+
scope: "project",
|
|
668
|
+
});
|
|
669
|
+
```
|
|
670
|
+
|
|
671
|
+
### Retrieve a Policy
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
const policy = await cdp.policies.getPolicyById({
|
|
675
|
+
id: "__POLICY_ID__",
|
|
676
|
+
});
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
### Update a Policy
|
|
680
|
+
|
|
681
|
+
This policy will update an existing policy to accept transactions to any address except one.
|
|
682
|
+
|
|
683
|
+
```typescript
|
|
684
|
+
const policy = await cdp.policies.updatePolicy({
|
|
685
|
+
id: "__POLICY_ID__",
|
|
686
|
+
policy: {
|
|
687
|
+
description: "Updated Account Denylist Policy",
|
|
688
|
+
rules: [
|
|
689
|
+
{
|
|
690
|
+
action: "accept",
|
|
691
|
+
operation: "signEvmTransaction",
|
|
692
|
+
criteria: [
|
|
693
|
+
{
|
|
694
|
+
type: "evmAddress",
|
|
695
|
+
addresses: ["0x000000000000000000000000000000000000dEaD"],
|
|
696
|
+
operator: "not in",
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
},
|
|
700
|
+
],
|
|
701
|
+
},
|
|
702
|
+
});
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
### Delete a Policy
|
|
706
|
+
|
|
707
|
+
> [!WARNING] Attempting to delete an account-level policy in-use by at least one account will fail.
|
|
708
|
+
|
|
709
|
+
```typescript
|
|
710
|
+
const policy = await cdp.policies.deletePolicy({
|
|
711
|
+
id: "__POLICY_ID__",
|
|
712
|
+
});
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
### Validate a Policy
|
|
716
|
+
|
|
717
|
+
If you're integrating policy editing into your application, you may find it useful to validate policies ahead of time to provide a user with feedback. The `CreatePolicyBodySchema` and `UpdatePolicyBodySchema` can be used to get actionable structured information about any issues with a policy. Read more about [handling ZodErrors](https://zod.dev/ERROR_HANDLING).
|
|
718
|
+
|
|
719
|
+
```ts
|
|
720
|
+
import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "@coinbase/cdp-sdk";
|
|
721
|
+
|
|
722
|
+
// Validate a new Policy with many issues, will throw a ZodError with actionable validation errors
|
|
723
|
+
try {
|
|
724
|
+
CreatePolicyBodySchema.parse({
|
|
725
|
+
description: "Bad description with !#@ characters, also is wayyyyy toooooo long!!",
|
|
726
|
+
rules: [
|
|
727
|
+
{
|
|
728
|
+
action: "acept",
|
|
729
|
+
operation: "unknownOperation",
|
|
730
|
+
criteria: [
|
|
731
|
+
{
|
|
732
|
+
type: "ethValue",
|
|
733
|
+
ethValue: "not a number",
|
|
734
|
+
operator: "<=",
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
type: "evmAddress",
|
|
738
|
+
addresses: ["not an address"],
|
|
739
|
+
operator: "in",
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
type: "evmAddress",
|
|
743
|
+
addresses: ["not an address"],
|
|
744
|
+
operator: "invalid operator",
|
|
745
|
+
},
|
|
746
|
+
],
|
|
747
|
+
},
|
|
748
|
+
],
|
|
749
|
+
});
|
|
750
|
+
} catch (e) {
|
|
751
|
+
console.error(e);
|
|
752
|
+
}
|
|
753
|
+
```
|
|
754
|
+
|
|
457
755
|
## Authentication tools
|
|
458
756
|
|
|
459
757
|
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.
|
|
@@ -37,8 +37,9 @@ function toEvmServerAccount(apiClient, options) {
|
|
|
37
37
|
});
|
|
38
38
|
return result.signedTransaction;
|
|
39
39
|
},
|
|
40
|
-
async signTypedData() {
|
|
41
|
-
|
|
40
|
+
async signTypedData(message) {
|
|
41
|
+
const result = await apiClient.signEvmTypedData(options.account.address, message);
|
|
42
|
+
return result.signature;
|
|
42
43
|
},
|
|
43
44
|
async transfer(transferArgs) {
|
|
44
45
|
return (0, transfer_js_1.transfer)(apiClient, account, transferArgs, accountTransferStrategy_js_1.accountTransferStrategy);
|
|
@@ -63,6 +64,7 @@ function toEvmServerAccount(apiClient, options) {
|
|
|
63
64
|
},
|
|
64
65
|
name: options.account.name,
|
|
65
66
|
type: "evm-server",
|
|
67
|
+
policies: options.account.policies,
|
|
66
68
|
};
|
|
67
69
|
return account;
|
|
68
70
|
}
|
|
@@ -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":";;AAyCA,gDA8DC;AAvGD,+BAA0E;AAE1E,iFAIgD;AAChD,yEAI4C;AAC5C,6EAAuE;AACvE,sGAAgG;AAChG,wEAAkE;AAkBlE;;;;;;;;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,CAAC,OAAsB;YACxC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAClF,OAAO,MAAM,CAAC,SAAgB,CAAC;QACjC,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;QAClB,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;KACnC,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -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":";;AAsDA,8CAuDC;AA7GD,+EAAyE;AACzE,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,gBAAgB,CACpB,OAAsD;YAEtD,OAAO,IAAA,sCAAgB,EAAC,SAAS,EAAE;gBACjC,GAAG,OAAO;gBACV,YAAY,EAAE,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,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"}
|
|
@@ -4,6 +4,7 @@ exports.toSolanaAccount = toSolanaAccount;
|
|
|
4
4
|
const requestFaucet_js_1 = require("../../actions/solana/requestFaucet.js");
|
|
5
5
|
const signMessage_js_1 = require("../../actions/solana/signMessage.js");
|
|
6
6
|
const signTransaction_js_1 = require("../../actions/solana/signTransaction.js");
|
|
7
|
+
const transfer_js_1 = require("../../actions/solana/transfer.js");
|
|
7
8
|
/**
|
|
8
9
|
* Creates a Solana account instance with actions from an existing Solana account.
|
|
9
10
|
* Use this to interact with previously deployed Solana accounts, rather than creating new ones.
|
|
@@ -35,6 +36,13 @@ function toSolanaAccount(apiClient, options) {
|
|
|
35
36
|
address: account.address,
|
|
36
37
|
});
|
|
37
38
|
},
|
|
39
|
+
policies: options.account.policies,
|
|
40
|
+
async transfer(options) {
|
|
41
|
+
return (0, transfer_js_1.transfer)(apiClient, {
|
|
42
|
+
...options,
|
|
43
|
+
from: account.address,
|
|
44
|
+
});
|
|
45
|
+
},
|
|
38
46
|
};
|
|
39
47
|
return account;
|
|
40
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":";;AA6BA,0CAqCC;AAjED,4EAAsE;AACtE,wEAAkE;AAClE,gFAA0E;AAC1E,kEAAkF;AAgBlF;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,OAAO,GAAkB;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;QAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,KAAK,CAAC,aAAa,CAAC,OAA8C;YAChE,OAAO,IAAA,gCAAa,EAAC,SAAS,EAAE;gBAC9B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,OAA4C;YAC5D,OAAO,IAAA,4BAAW,EAAC,SAAS,EAAE;gBAC5B,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,KAAK,CAAC,eAAe,CACnB,OAAgD;YAEhD,OAAO,IAAA,oCAAe,EAAC,SAAS,EAAE;gBAChC,GAAG,OAAO;gBACV,OAAO,EAAE,OAAO,CAAC,OAAO;aACzB,CAAC,CAAC;QACL,CAAC;QACD,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,KAAK,CAAC,QAAQ,CAAC,OAAsC;YACnD,OAAO,IAAA,sBAAQ,EAAC,SAAS,EAAE;gBACzB,GAAG,OAAO;gBACV,IAAI,EAAE,OAAO,CAAC,OAAO;aACtB,CAAC,CAAC;QACL,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -6,71 +6,38 @@ const utils_js_1 = require("./utils.js");
|
|
|
6
6
|
const serializeTransaction_js_1 = require("../../../utils/serializeTransaction.js");
|
|
7
7
|
exports.accountTransferStrategy = {
|
|
8
8
|
executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
network,
|
|
17
|
-
});
|
|
18
|
-
return result.transactionHash;
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
const erc20Address = (0, utils_js_1.getErc20Address)(token, 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,
|
|
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,
|
|
43
|
-
});
|
|
44
|
-
return result.transactionHash;
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
47
|
-
return transactionHash;
|
|
48
|
-
},
|
|
49
|
-
waitForResult: async ({ publicClient, hash, waitOptions }) => {
|
|
50
|
-
let receipt;
|
|
51
|
-
try {
|
|
52
|
-
receipt = await publicClient.waitForTransactionReceipt({
|
|
53
|
-
hash,
|
|
54
|
-
pollingInterval: waitOptions?.intervalSeconds
|
|
55
|
-
? waitOptions.intervalSeconds * 1000
|
|
56
|
-
: undefined,
|
|
57
|
-
timeout: waitOptions?.timeoutSeconds ? waitOptions.timeoutSeconds * 1000 : undefined,
|
|
9
|
+
if (token === "eth") {
|
|
10
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
11
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
12
|
+
value,
|
|
13
|
+
to,
|
|
14
|
+
}),
|
|
15
|
+
network,
|
|
58
16
|
});
|
|
59
17
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
18
|
+
const erc20Address = (0, utils_js_1.getErc20Address)(token, network);
|
|
19
|
+
await apiClient.sendEvmTransaction(from.address, {
|
|
20
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
21
|
+
to: erc20Address,
|
|
22
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
23
|
+
abi: viem_1.erc20Abi,
|
|
24
|
+
functionName: "approve",
|
|
25
|
+
args: [to, value],
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
network,
|
|
29
|
+
});
|
|
30
|
+
return apiClient.sendEvmTransaction(from.address, {
|
|
31
|
+
transaction: (0, serializeTransaction_js_1.serializeEIP1559Transaction)({
|
|
32
|
+
to: erc20Address,
|
|
33
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
34
|
+
abi: viem_1.erc20Abi,
|
|
35
|
+
functionName: "transfer",
|
|
36
|
+
args: [to, value],
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
network,
|
|
40
|
+
});
|
|
74
41
|
},
|
|
75
42
|
};
|
|
76
43
|
//# sourceMappingURL=accountTransferStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"accountTransferStrategy.js","sourceRoot":"","sources":["../../../../actions/evm/transfer/accountTransferStrategy.ts"],"names":[],"mappings":";;;AAAA,+BAAoD;AAEpD,yCAA6C;AAC7C,oFAAqF;AAMxE,QAAA,uBAAuB,GAA0C;IAC5E,eAAe,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;QACxE,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;gBAChD,WAAW,EAAE,IAAA,qDAA2B,EAAC;oBACvC,KAAK;oBACL,EAAE;iBACH,CAAC;gBACF,OAAO;aACR,CAA+B,CAAC;QACnC,CAAC;QAED,MAAM,YAAY,GAAG,IAAA,0BAAe,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAErD,MAAM,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAC/C,WAAW,EAAE,IAAA,qDAA2B,EAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;oBACvB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,SAAS;oBACvB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,EAAE;YAChD,WAAW,EAAE,IAAA,qDAA2B,EAAC;gBACvC,EAAE,EAAE,YAAY;gBAChB,IAAI,EAAE,IAAA,yBAAkB,EAAC;oBACvB,GAAG,EAAE,eAAQ;oBACb,YAAY,EAAE,UAAU;oBACxB,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC;iBAClB,CAAC;aACH,CAAC;YACF,OAAO;SACR,CAA+B,CAAC;IACnC,CAAC;CACF,CAAC"}
|