@coinbase/cdp-sdk 1.44.1 → 1.46.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 +28 -2
- package/README.md +164 -43
- package/_cjs/accounts/evm/eip6492.js +49 -0
- package/_cjs/accounts/evm/eip6492.js.map +1 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js +27 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js +127 -55
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +115 -45
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +31 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +49 -19
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js +37 -0
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_cjs/actions/solana/transfer.js.map +1 -1
- package/_cjs/actions/solana/utils.js +9 -9
- package/_cjs/actions/solana/utils.js.map +1 -1
- package/_cjs/analytics.js +10 -228
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/auth/utils/http.js +1 -0
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/client/cdp.js +4 -7
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/end-user/endUser.js +385 -4
- package/_cjs/client/end-user/endUser.js.map +1 -1
- package/_cjs/client/end-user/toEndUserAccount.js +201 -23
- package/_cjs/client/end-user/toEndUserAccount.js.map +1 -1
- package/_cjs/client/evm/evm.js +482 -227
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +41 -11
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/client/solana/solana.js +215 -118
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +32 -0
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +178 -9
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js +261 -0
- package/_cjs/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +1 -0
- package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +30 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_cjs/openapi-client/generated/faucets/faucets.js +6 -5
- package/_cjs/openapi-client/generated/faucets/faucets.js.map +1 -1
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js +15 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-token-balances/solana-token-balances.js.map +1 -1
- package/_cjs/openapi-client/generated/sql-api/sql-api.js +75 -0
- package/_cjs/openapi-client/generated/sql-api/sql-api.js.map +1 -0
- package/_cjs/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -1
- package/_cjs/openapi-client/index.js +4 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/evmSchema.js +127 -1
- package/_cjs/policies/evmSchema.js.map +1 -1
- package/_cjs/policies/solanaSchema.js +102 -1
- package/_cjs/policies/solanaSchema.js.map +1 -1
- package/_cjs/policies/types.js +7 -0
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/utils/export.js +6 -5
- package/_cjs/utils/export.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/eip6492.js +46 -0
- package/_esm/accounts/evm/eip6492.js.map +1 -0
- package/_esm/accounts/evm/toEvmDelegatedAccount.js +24 -0
- package/_esm/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_esm/accounts/evm/toEvmServerAccount.js +127 -55
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +115 -45
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +31 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +49 -19
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js +34 -0
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_esm/actions/solana/transfer.js.map +1 -1
- package/_esm/actions/solana/utils.js +9 -9
- package/_esm/actions/solana/utils.js.map +1 -1
- package/_esm/analytics.js +9 -227
- package/_esm/analytics.js.map +1 -1
- package/_esm/auth/utils/http.js +1 -0
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/client/cdp.js +4 -7
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/end-user/endUser.js +385 -4
- package/_esm/client/end-user/endUser.js.map +1 -1
- package/_esm/client/end-user/toEndUserAccount.js +201 -23
- package/_esm/client/end-user/toEndUserAccount.js.map +1 -1
- package/_esm/client/evm/evm.js +482 -227
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +41 -11
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/client/solana/solana.js +215 -118
- 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/cdpApiClient.js +32 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +175 -7
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js +243 -0
- package/_esm/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +1 -0
- package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +27 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-swaps/evm-swaps.js.map +1 -1
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_esm/openapi-client/generated/faucets/faucets.js +6 -5
- package/_esm/openapi-client/generated/faucets/faucets.js.map +1 -1
- package/_esm/openapi-client/generated/onchain-data/onchain-data.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js +13 -0
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-token-balances/solana-token-balances.js.map +1 -1
- package/_esm/openapi-client/generated/sql-api/sql-api.js +70 -0
- package/_esm/openapi-client/generated/sql-api/sql-api.js.map +1 -0
- package/_esm/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -1
- package/_esm/openapi-client/index.js +4 -1
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/evmSchema.js +126 -0
- package/_esm/policies/evmSchema.js.map +1 -1
- package/_esm/policies/solanaSchema.js +101 -0
- package/_esm/policies/solanaSchema.js.map +1 -1
- package/_esm/policies/types.js +9 -2
- package/_esm/policies/types.js.map +1 -1
- package/_esm/utils/export.js +6 -5
- package/_esm/utils/export.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/eip6492.d.ts +17 -0
- package/_types/accounts/evm/eip6492.d.ts.map +1 -0
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts +13 -0
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts.map +1 -0
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts +4 -4
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +3 -2
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts +32 -0
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts.map +1 -0
- package/_types/actions/solana/transfer.d.ts +3 -4
- package/_types/actions/solana/transfer.d.ts.map +1 -1
- package/_types/actions/solana/types.d.ts +79 -29
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +10 -9
- package/_types/actions/solana/utils.d.ts.map +1 -1
- package/_types/analytics.d.ts +5 -38
- package/_types/analytics.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +4 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/end-user/endUser.d.ts +272 -1
- package/_types/client/end-user/endUser.d.ts.map +1 -1
- package/_types/client/end-user/endUser.types.d.ts +491 -1
- package/_types/client/end-user/endUser.types.d.ts.map +1 -1
- package/_types/client/end-user/toEndUserAccount.d.ts +4 -1
- package/_types/client/end-user/toEndUserAccount.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +54 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +29 -2
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +38 -12
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/index.d.ts +3 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +884 -90
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts +163 -0
- package/_types/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts.map +1 -0
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts +9 -9
- package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +35 -15
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +14 -14
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts +3 -3
- package/_types/openapi-client/generated/evm-swaps/evm-swaps.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts +2 -2
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts.map +1 -1
- package/_types/openapi-client/generated/faucets/faucets.d.ts +9 -8
- package/_types/openapi-client/generated/faucets/faucets.d.ts.map +1 -1
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts +3 -3
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +12 -5
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +6 -6
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +12 -12
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-token-balances/solana-token-balances.d.ts +2 -2
- package/_types/openapi-client/generated/solana-token-balances/solana-token-balances.d.ts.map +1 -1
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts +73 -0
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts.map +1 -0
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts +6 -6
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts.map +1 -1
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts +4 -4
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +23 -3
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +3128 -1064
- package/_types/policies/evmSchema.d.ts.map +1 -1
- package/_types/policies/solanaSchema.d.ts +1411 -47
- package/_types/policies/solanaSchema.d.ts.map +1 -1
- package/_types/policies/types.d.ts +8427 -2942
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/types/contract.d.ts.map +1 -1
- package/_types/utils/export.d.ts +1 -1
- package/_types/utils/export.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/eip6492.ts +60 -0
- package/accounts/evm/toEvmDelegatedAccount.ts +26 -0
- package/accounts/evm/toEvmServerAccount.ts +115 -67
- package/accounts/evm/toEvmSmartAccount.ts +114 -57
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +44 -5
- package/accounts/evm/types.ts +8 -3
- package/accounts/solana/toSolanaAccount.ts +44 -24
- package/actions/evm/waitForEvmEip7702DelegationStatus.ts +57 -0
- package/actions/solana/transfer.ts +3 -3
- package/actions/solana/types.ts +79 -29
- package/actions/solana/utils.ts +13 -11
- package/analytics.ts +8 -294
- package/auth/utils/http.ts +1 -0
- package/client/cdp.ts +6 -8
- package/client/end-user/endUser.ts +513 -4
- package/client/end-user/endUser.types.ts +598 -0
- package/client/end-user/toEndUserAccount.ts +330 -26
- package/client/evm/evm.ts +517 -282
- package/client/evm/evm.types.ts +45 -2
- package/client/policies/policies.ts +41 -16
- package/client/solana/solana.ts +233 -153
- package/index.ts +36 -1
- package/openapi-client/cdpApiClient.ts +34 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +1155 -172
- package/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.ts +455 -0
- package/openapi-client/generated/end-user-accounts/end-user-accounts.ts +12 -9
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +66 -14
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +16 -16
- package/openapi-client/generated/evm-swaps/evm-swaps.ts +3 -3
- package/openapi-client/generated/evm-token-balances/evm-token-balances.ts +2 -2
- package/openapi-client/generated/faucets/faucets.ts +9 -8
- package/openapi-client/generated/onchain-data/onchain-data.ts +3 -3
- package/openapi-client/generated/onramp/onramp.ts +28 -4
- package/openapi-client/generated/policy-engine/policy-engine.ts +12 -6
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +12 -12
- package/openapi-client/generated/solana-token-balances/solana-token-balances.ts +2 -2
- package/openapi-client/generated/sql-api/sql-api.ts +92 -0
- package/openapi-client/generated/webhooks/webhooks.ts +6 -6
- package/openapi-client/generated/x402-facilitator/x402-facilitator.ts +6 -4
- package/openapi-client/index.ts +4 -1
- package/package.json +7 -8
- package/policies/evmSchema.ts +164 -0
- package/policies/solanaSchema.ts +130 -0
- package/policies/types.ts +14 -0
- package/types/contract.ts +2 -4
- package/utils/export.ts +6 -5
- package/version.ts +1 -1
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +0 -55
- package/_cjs/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +0 -1
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js +0 -50
- package/_esm/openapi-client/generated/sql-api-alpha/sql-api-alpha.js.map +0 -1
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts +0 -53
- package/_types/openapi-client/generated/sql-api-alpha/sql-api-alpha.d.ts.map +0 -1
- package/openapi-client/generated/sql-api-alpha/sql-api-alpha.ts +0 -72
package/client/evm/evm.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { constants, publicEncrypt } from "crypto";
|
|
|
7
7
|
import { type Address, getTypesForEIP712Domain } from "viem";
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
+
CreateEvmEip7702DelegationResult,
|
|
10
11
|
CreateServerAccountOptions,
|
|
11
12
|
CreateSmartAccountOptions,
|
|
12
13
|
CreateSwapQuoteOptions,
|
|
@@ -67,6 +68,7 @@ import {
|
|
|
67
68
|
import { resolveSpendPermission } from "../../actions/evm/spend-permissions/resolveSpendPermission.js";
|
|
68
69
|
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
69
70
|
import { getSwapPrice } from "../../actions/evm/swap/getSwapPrice.js";
|
|
71
|
+
import { waitForEvmEip7702DelegationOperationStatus } from "../../actions/evm/waitForEvmEip7702DelegationStatus.js";
|
|
70
72
|
import {
|
|
71
73
|
waitForUserOperation,
|
|
72
74
|
WaitForUserOperationReturnType,
|
|
@@ -77,6 +79,7 @@ import { UserInputValidationError } from "../../errors.js";
|
|
|
77
79
|
import { APIError } from "../../openapi-client/errors.js";
|
|
78
80
|
import {
|
|
79
81
|
CdpOpenApiClient,
|
|
82
|
+
EvmEip7702DelegationOperation,
|
|
80
83
|
EvmUserOperationStatus,
|
|
81
84
|
EIP712Message as OpenAPIEIP712Message,
|
|
82
85
|
} from "../../openapi-client/index.js";
|
|
@@ -84,6 +87,10 @@ import { SPEND_PERMISSION_MANAGER_ADDRESS } from "../../spend-permissions/consta
|
|
|
84
87
|
import { Hex } from "../../types/misc.js";
|
|
85
88
|
import { decryptWithPrivateKey, generateExportEncryptionKeyPair } from "../../utils/export.js";
|
|
86
89
|
|
|
90
|
+
import type {
|
|
91
|
+
CreateEvmEip7702DelegationOptions,
|
|
92
|
+
WaitForEvmEip7702DelegationOperationStatusOptions,
|
|
93
|
+
} from "./evm.types.js";
|
|
87
94
|
import type {
|
|
88
95
|
SendTransactionOptions,
|
|
89
96
|
TransactionResult,
|
|
@@ -138,7 +145,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
138
145
|
accountType: "evm_server",
|
|
139
146
|
});
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
try {
|
|
149
|
+
return await this._createAccountInternal(options);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
Analytics.trackError(error, "createAccount");
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
142
154
|
}
|
|
143
155
|
|
|
144
156
|
/**
|
|
@@ -189,17 +201,17 @@ export class EvmClient implements EvmClientInterface {
|
|
|
189
201
|
accountType: "evm_server",
|
|
190
202
|
});
|
|
191
203
|
|
|
192
|
-
|
|
204
|
+
try {
|
|
205
|
+
const encryptionPublicKey = options.encryptionPublicKey || ImportAccountPublicRSAKey;
|
|
193
206
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
207
|
+
const privateKeyHex = options.privateKey.startsWith("0x")
|
|
208
|
+
? options.privateKey.slice(2)
|
|
209
|
+
: options.privateKey;
|
|
197
210
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
211
|
+
if (!/^[0-9a-fA-F]+$/.test(privateKeyHex)) {
|
|
212
|
+
throw new UserInputValidationError("Private key must be a valid hexadecimal string");
|
|
213
|
+
}
|
|
201
214
|
|
|
202
|
-
try {
|
|
203
215
|
const privateKeyBytes = Buffer.from(privateKeyHex, "hex");
|
|
204
216
|
|
|
205
217
|
const encryptedPrivateKey = publicEncrypt(
|
|
@@ -223,10 +235,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
223
235
|
account: openApiAccount,
|
|
224
236
|
});
|
|
225
237
|
|
|
226
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
227
|
-
|
|
228
238
|
return account;
|
|
229
239
|
} catch (error) {
|
|
240
|
+
if (!(error instanceof UserInputValidationError)) {
|
|
241
|
+
Analytics.trackError(error, "importAccount");
|
|
242
|
+
}
|
|
243
|
+
|
|
230
244
|
if (error instanceof APIError) {
|
|
231
245
|
throw error;
|
|
232
246
|
}
|
|
@@ -265,33 +279,40 @@ export class EvmClient implements EvmClientInterface {
|
|
|
265
279
|
accountType: "evm_server",
|
|
266
280
|
});
|
|
267
281
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
282
|
+
try {
|
|
283
|
+
const { publicKey, privateKey } = await generateExportEncryptionKeyPair();
|
|
284
|
+
|
|
285
|
+
const { encryptedPrivateKey } = await (async () => {
|
|
286
|
+
if (options.address) {
|
|
287
|
+
return CdpOpenApiClient.exportEvmAccount(
|
|
288
|
+
options.address,
|
|
289
|
+
{
|
|
290
|
+
exportEncryptionKey: publicKey,
|
|
291
|
+
},
|
|
292
|
+
options.idempotencyKey,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
280
295
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
296
|
+
if (options.name) {
|
|
297
|
+
return CdpOpenApiClient.exportEvmAccountByName(
|
|
298
|
+
options.name,
|
|
299
|
+
{
|
|
300
|
+
exportEncryptionKey: publicKey,
|
|
301
|
+
},
|
|
302
|
+
options.idempotencyKey,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
290
305
|
|
|
291
|
-
|
|
292
|
-
|
|
306
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
307
|
+
})();
|
|
293
308
|
|
|
294
|
-
|
|
309
|
+
return decryptWithPrivateKey(privateKey, encryptedPrivateKey);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (!(error instanceof UserInputValidationError)) {
|
|
312
|
+
Analytics.trackError(error, "exportAccount");
|
|
313
|
+
}
|
|
314
|
+
throw error;
|
|
315
|
+
}
|
|
295
316
|
}
|
|
296
317
|
|
|
297
318
|
/**
|
|
@@ -345,7 +366,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
345
366
|
accountType: "evm_smart",
|
|
346
367
|
});
|
|
347
368
|
|
|
348
|
-
|
|
369
|
+
try {
|
|
370
|
+
return await this._createSmartAccountInternal(options);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
Analytics.trackError(error, "createSmartAccount");
|
|
373
|
+
throw error;
|
|
374
|
+
}
|
|
349
375
|
}
|
|
350
376
|
|
|
351
377
|
/**
|
|
@@ -370,38 +396,43 @@ export class EvmClient implements EvmClientInterface {
|
|
|
370
396
|
action: "create_spend_permission",
|
|
371
397
|
});
|
|
372
398
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
399
|
+
try {
|
|
400
|
+
const resolvedSpendPermission = resolveSpendPermission(
|
|
401
|
+
options.spendPermission,
|
|
402
|
+
options.network,
|
|
403
|
+
);
|
|
377
404
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
405
|
+
const userOperation = await CdpOpenApiClient.createSpendPermission(
|
|
406
|
+
resolvedSpendPermission.account,
|
|
407
|
+
{
|
|
408
|
+
spender: resolvedSpendPermission.spender,
|
|
409
|
+
token: resolvedSpendPermission.token,
|
|
410
|
+
allowance: resolvedSpendPermission.allowance.toString(),
|
|
411
|
+
period: resolvedSpendPermission.period.toString(),
|
|
412
|
+
start: resolvedSpendPermission.start.toString(),
|
|
413
|
+
end: resolvedSpendPermission.end.toString(),
|
|
414
|
+
salt: resolvedSpendPermission.salt.toString(),
|
|
415
|
+
extraData: resolvedSpendPermission.extraData,
|
|
416
|
+
network: options.network,
|
|
417
|
+
paymasterUrl: options.paymasterUrl,
|
|
418
|
+
},
|
|
419
|
+
options.idempotencyKey,
|
|
420
|
+
);
|
|
394
421
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
422
|
+
return {
|
|
423
|
+
network: userOperation.network,
|
|
424
|
+
userOpHash: userOperation.userOpHash as Hex,
|
|
425
|
+
status: userOperation.status,
|
|
426
|
+
calls: userOperation.calls.map(call => ({
|
|
427
|
+
to: call.to as Address,
|
|
428
|
+
value: BigInt(call.value),
|
|
429
|
+
data: call.data as Hex,
|
|
430
|
+
})),
|
|
431
|
+
};
|
|
432
|
+
} catch (error) {
|
|
433
|
+
Analytics.trackError(error, "createSpendPermission");
|
|
434
|
+
throw error;
|
|
435
|
+
}
|
|
405
436
|
}
|
|
406
437
|
|
|
407
438
|
/**
|
|
@@ -429,26 +460,31 @@ export class EvmClient implements EvmClientInterface {
|
|
|
429
460
|
action: "revoke_spend_permission",
|
|
430
461
|
});
|
|
431
462
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
463
|
+
try {
|
|
464
|
+
const userOperation = await CdpOpenApiClient.revokeSpendPermission(
|
|
465
|
+
options.address,
|
|
466
|
+
{
|
|
467
|
+
network: options.network,
|
|
468
|
+
permissionHash: options.permissionHash,
|
|
469
|
+
paymasterUrl: options.paymasterUrl,
|
|
470
|
+
},
|
|
471
|
+
options.idempotencyKey,
|
|
472
|
+
);
|
|
441
473
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
474
|
+
return {
|
|
475
|
+
network: userOperation.network,
|
|
476
|
+
userOpHash: userOperation.userOpHash as Hex,
|
|
477
|
+
status: userOperation.status,
|
|
478
|
+
calls: userOperation.calls.map(call => ({
|
|
479
|
+
to: call.to as Address,
|
|
480
|
+
value: BigInt(call.value),
|
|
481
|
+
data: call.data as Hex,
|
|
482
|
+
})),
|
|
483
|
+
};
|
|
484
|
+
} catch (error) {
|
|
485
|
+
Analytics.trackError(error, "revokeSpendPermission");
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
452
488
|
}
|
|
453
489
|
|
|
454
490
|
/**
|
|
@@ -482,7 +518,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
482
518
|
accountType: "evm_server",
|
|
483
519
|
});
|
|
484
520
|
|
|
485
|
-
|
|
521
|
+
try {
|
|
522
|
+
return await this._getAccountInternal(options);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
Analytics.trackError(error, "getAccount");
|
|
525
|
+
throw error;
|
|
526
|
+
}
|
|
486
527
|
}
|
|
487
528
|
|
|
488
529
|
/**
|
|
@@ -512,7 +553,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
512
553
|
action: "get_smart_account",
|
|
513
554
|
});
|
|
514
555
|
|
|
515
|
-
|
|
556
|
+
try {
|
|
557
|
+
return await this._getSmartAccountInternal(options);
|
|
558
|
+
} catch (error) {
|
|
559
|
+
Analytics.trackError(error, "getSmartAccount");
|
|
560
|
+
throw error;
|
|
561
|
+
}
|
|
516
562
|
}
|
|
517
563
|
|
|
518
564
|
/**
|
|
@@ -537,25 +583,30 @@ export class EvmClient implements EvmClientInterface {
|
|
|
537
583
|
});
|
|
538
584
|
|
|
539
585
|
try {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
} catch (error) {
|
|
550
|
-
// If it failed because the account already exists, get the existing account
|
|
551
|
-
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
552
|
-
if (doesAccountAlreadyExist) {
|
|
553
|
-
const account = await this._getAccountInternal(options);
|
|
586
|
+
try {
|
|
587
|
+
const account = await this._getAccountInternal(options);
|
|
588
|
+
return account;
|
|
589
|
+
} catch (error) {
|
|
590
|
+
// If it failed because the account doesn't exist, create it
|
|
591
|
+
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
592
|
+
if (doesAccountNotExist) {
|
|
593
|
+
try {
|
|
594
|
+
const account = await this._createAccountInternal(options);
|
|
554
595
|
return account;
|
|
596
|
+
} catch (error) {
|
|
597
|
+
// If it failed because the account already exists, get the existing account
|
|
598
|
+
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
599
|
+
if (doesAccountAlreadyExist) {
|
|
600
|
+
const account = await this._getAccountInternal(options);
|
|
601
|
+
return account;
|
|
602
|
+
}
|
|
603
|
+
throw error;
|
|
555
604
|
}
|
|
556
|
-
throw error;
|
|
557
605
|
}
|
|
606
|
+
throw error;
|
|
558
607
|
}
|
|
608
|
+
} catch (error) {
|
|
609
|
+
Analytics.trackError(error, "getOrCreateAccount");
|
|
559
610
|
throw error;
|
|
560
611
|
}
|
|
561
612
|
}
|
|
@@ -586,25 +637,30 @@ export class EvmClient implements EvmClientInterface {
|
|
|
586
637
|
});
|
|
587
638
|
|
|
588
639
|
try {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
} catch (error) {
|
|
599
|
-
// If it failed because the account already exists, get the existing account
|
|
600
|
-
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
601
|
-
if (doesAccountAlreadyExist) {
|
|
602
|
-
const account = await this._getSmartAccountInternal(options);
|
|
640
|
+
try {
|
|
641
|
+
const account = await this._getSmartAccountInternal(options);
|
|
642
|
+
return account;
|
|
643
|
+
} catch (error) {
|
|
644
|
+
// If it failed because the account doesn't exist, create it
|
|
645
|
+
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
646
|
+
if (doesAccountNotExist) {
|
|
647
|
+
try {
|
|
648
|
+
const account = await this._createSmartAccountInternal(options);
|
|
603
649
|
return account;
|
|
650
|
+
} catch (error) {
|
|
651
|
+
// If it failed because the account already exists, get the existing account
|
|
652
|
+
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
653
|
+
if (doesAccountAlreadyExist) {
|
|
654
|
+
const account = await this._getSmartAccountInternal(options);
|
|
655
|
+
return account;
|
|
656
|
+
}
|
|
657
|
+
throw error;
|
|
604
658
|
}
|
|
605
|
-
throw error;
|
|
606
659
|
}
|
|
660
|
+
throw error;
|
|
607
661
|
}
|
|
662
|
+
} catch (error) {
|
|
663
|
+
Analytics.trackError(error, "getOrCreateSmartAccount");
|
|
608
664
|
throw error;
|
|
609
665
|
}
|
|
610
666
|
}
|
|
@@ -637,7 +693,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
637
693
|
},
|
|
638
694
|
});
|
|
639
695
|
|
|
640
|
-
|
|
696
|
+
try {
|
|
697
|
+
return await getSwapPrice(CdpOpenApiClient, options);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
Analytics.trackError(error, "getSwapPrice");
|
|
700
|
+
throw error;
|
|
701
|
+
}
|
|
641
702
|
}
|
|
642
703
|
|
|
643
704
|
/**
|
|
@@ -668,7 +729,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
668
729
|
},
|
|
669
730
|
});
|
|
670
731
|
|
|
671
|
-
|
|
732
|
+
try {
|
|
733
|
+
return await createSwapQuote(CdpOpenApiClient, options);
|
|
734
|
+
} catch (error) {
|
|
735
|
+
Analytics.trackError(error, "createSwapQuote");
|
|
736
|
+
throw error;
|
|
737
|
+
}
|
|
672
738
|
}
|
|
673
739
|
|
|
674
740
|
/**
|
|
@@ -693,7 +759,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
693
759
|
action: "get_user_operation",
|
|
694
760
|
});
|
|
695
761
|
|
|
696
|
-
|
|
762
|
+
try {
|
|
763
|
+
return await getUserOperation(CdpOpenApiClient, options);
|
|
764
|
+
} catch (error) {
|
|
765
|
+
Analytics.trackError(error, "getUserOperation");
|
|
766
|
+
throw error;
|
|
767
|
+
}
|
|
697
768
|
}
|
|
698
769
|
|
|
699
770
|
/**
|
|
@@ -726,23 +797,26 @@ export class EvmClient implements EvmClientInterface {
|
|
|
726
797
|
accountType: "evm_server",
|
|
727
798
|
});
|
|
728
799
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
return {
|
|
735
|
-
accounts: ethAccounts.accounts.map(account => {
|
|
736
|
-
const evmAccount = toEvmServerAccount(CdpOpenApiClient, {
|
|
737
|
-
account,
|
|
738
|
-
});
|
|
800
|
+
try {
|
|
801
|
+
const ethAccounts = await CdpOpenApiClient.listEvmAccounts({
|
|
802
|
+
pageSize: options.pageSize,
|
|
803
|
+
pageToken: options.pageToken,
|
|
804
|
+
});
|
|
739
805
|
|
|
740
|
-
|
|
806
|
+
return {
|
|
807
|
+
accounts: ethAccounts.accounts.map(account => {
|
|
808
|
+
const evmAccount = toEvmServerAccount(CdpOpenApiClient, {
|
|
809
|
+
account,
|
|
810
|
+
});
|
|
741
811
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
812
|
+
return evmAccount;
|
|
813
|
+
}),
|
|
814
|
+
nextPageToken: ethAccounts.nextPageToken,
|
|
815
|
+
};
|
|
816
|
+
} catch (error) {
|
|
817
|
+
Analytics.trackError(error, "listAccounts");
|
|
818
|
+
throw error;
|
|
819
|
+
}
|
|
746
820
|
}
|
|
747
821
|
|
|
748
822
|
/**
|
|
@@ -787,7 +861,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
787
861
|
},
|
|
788
862
|
});
|
|
789
863
|
|
|
790
|
-
|
|
864
|
+
try {
|
|
865
|
+
return await listTokenBalances(CdpOpenApiClient, options);
|
|
866
|
+
} catch (error) {
|
|
867
|
+
Analytics.trackError(error, "listTokenBalances");
|
|
868
|
+
throw error;
|
|
869
|
+
}
|
|
791
870
|
}
|
|
792
871
|
|
|
793
872
|
/**
|
|
@@ -819,20 +898,25 @@ export class EvmClient implements EvmClientInterface {
|
|
|
819
898
|
action: "list_smart_accounts",
|
|
820
899
|
});
|
|
821
900
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
901
|
+
try {
|
|
902
|
+
const smartAccounts = await CdpOpenApiClient.listEvmSmartAccounts({
|
|
903
|
+
pageSize: options.pageSize,
|
|
904
|
+
pageToken: options.pageToken,
|
|
905
|
+
});
|
|
826
906
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
907
|
+
return {
|
|
908
|
+
accounts: smartAccounts.accounts.map(account => ({
|
|
909
|
+
address: account.address as Address,
|
|
910
|
+
owners: [account.owners[0] as Address],
|
|
911
|
+
type: "evm-smart",
|
|
912
|
+
policies: account.policies,
|
|
913
|
+
})),
|
|
914
|
+
nextPageToken: smartAccounts.nextPageToken,
|
|
915
|
+
};
|
|
916
|
+
} catch (error) {
|
|
917
|
+
Analytics.trackError(error, "listSmartAccounts");
|
|
918
|
+
throw error;
|
|
919
|
+
}
|
|
836
920
|
}
|
|
837
921
|
|
|
838
922
|
/**
|
|
@@ -852,7 +936,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
852
936
|
action: "list_spend_permissions",
|
|
853
937
|
});
|
|
854
938
|
|
|
855
|
-
|
|
939
|
+
try {
|
|
940
|
+
return await listSpendPermissions(CdpOpenApiClient, options);
|
|
941
|
+
} catch (error) {
|
|
942
|
+
Analytics.trackError(error, "listSpendPermissions");
|
|
943
|
+
throw error;
|
|
944
|
+
}
|
|
856
945
|
}
|
|
857
946
|
|
|
858
947
|
/**
|
|
@@ -889,28 +978,33 @@ export class EvmClient implements EvmClientInterface {
|
|
|
889
978
|
},
|
|
890
979
|
});
|
|
891
980
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
981
|
+
try {
|
|
982
|
+
const userOp = await CdpOpenApiClient.prepareUserOperation(options.smartAccount.address, {
|
|
983
|
+
network: options.network,
|
|
984
|
+
calls: options.calls.map(call => ({
|
|
985
|
+
to: call.to as Address,
|
|
986
|
+
value: call.value.toString(),
|
|
987
|
+
data: call.data as Hex,
|
|
988
|
+
overrideGasLimit: call.overrideGasLimit,
|
|
989
|
+
})),
|
|
990
|
+
paymasterUrl: options.paymasterUrl,
|
|
991
|
+
dataSuffix: options.dataSuffix,
|
|
992
|
+
});
|
|
903
993
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
994
|
+
return {
|
|
995
|
+
network: userOp.network,
|
|
996
|
+
userOpHash: userOp.userOpHash as Hex,
|
|
997
|
+
status: userOp.status,
|
|
998
|
+
calls: userOp.calls.map(call => ({
|
|
999
|
+
to: call.to as Address,
|
|
1000
|
+
value: BigInt(call.value),
|
|
1001
|
+
data: call.data as Hex,
|
|
1002
|
+
})),
|
|
1003
|
+
};
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
Analytics.trackError(error, "prepareUserOperation");
|
|
1006
|
+
throw error;
|
|
1007
|
+
}
|
|
914
1008
|
}
|
|
915
1009
|
|
|
916
1010
|
/**
|
|
@@ -949,25 +1043,30 @@ export class EvmClient implements EvmClientInterface {
|
|
|
949
1043
|
},
|
|
950
1044
|
});
|
|
951
1045
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1046
|
+
try {
|
|
1047
|
+
const userOp = await CdpOpenApiClient.prepareAndSendUserOperation(
|
|
1048
|
+
options.smartAccount.address,
|
|
1049
|
+
{
|
|
1050
|
+
network: options.network,
|
|
1051
|
+
calls: options.calls.map(call => ({
|
|
1052
|
+
to: call.to as Address,
|
|
1053
|
+
value: call.value.toString(),
|
|
1054
|
+
data: call.data as Hex,
|
|
1055
|
+
})),
|
|
1056
|
+
paymasterUrl: options.paymasterUrl,
|
|
1057
|
+
},
|
|
1058
|
+
options.idempotencyKey,
|
|
1059
|
+
);
|
|
965
1060
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
1061
|
+
return {
|
|
1062
|
+
smartAccountAddress: options.smartAccount.address as Address,
|
|
1063
|
+
userOpHash: userOp.userOpHash as Hex,
|
|
1064
|
+
status: userOp.status as typeof EvmUserOperationStatus.broadcast,
|
|
1065
|
+
};
|
|
1066
|
+
} catch (error) {
|
|
1067
|
+
Analytics.trackError(error, "prepareAndSendUserOperation");
|
|
1068
|
+
throw error;
|
|
1069
|
+
}
|
|
971
1070
|
}
|
|
972
1071
|
|
|
973
1072
|
/**
|
|
@@ -998,7 +1097,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
998
1097
|
},
|
|
999
1098
|
});
|
|
1000
1099
|
|
|
1001
|
-
|
|
1100
|
+
try {
|
|
1101
|
+
return await requestFaucet(CdpOpenApiClient, options);
|
|
1102
|
+
} catch (error) {
|
|
1103
|
+
Analytics.trackError(error, "requestFaucet");
|
|
1104
|
+
throw error;
|
|
1105
|
+
}
|
|
1002
1106
|
}
|
|
1003
1107
|
|
|
1004
1108
|
/**
|
|
@@ -1055,7 +1159,12 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1055
1159
|
},
|
|
1056
1160
|
});
|
|
1057
1161
|
|
|
1058
|
-
|
|
1162
|
+
try {
|
|
1163
|
+
return await sendTransaction(CdpOpenApiClient, options);
|
|
1164
|
+
} catch (error) {
|
|
1165
|
+
Analytics.trackError(error, "sendTransaction");
|
|
1166
|
+
throw error;
|
|
1167
|
+
}
|
|
1059
1168
|
}
|
|
1060
1169
|
|
|
1061
1170
|
/**
|
|
@@ -1096,14 +1205,19 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1096
1205
|
},
|
|
1097
1206
|
});
|
|
1098
1207
|
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1208
|
+
try {
|
|
1209
|
+
return await sendUserOperation(CdpOpenApiClient, {
|
|
1210
|
+
smartAccount: options.smartAccount,
|
|
1211
|
+
network: options.network,
|
|
1212
|
+
calls: options.calls,
|
|
1213
|
+
paymasterUrl: options.paymasterUrl,
|
|
1214
|
+
idempotencyKey: options.idempotencyKey,
|
|
1215
|
+
dataSuffix: options.dataSuffix,
|
|
1216
|
+
});
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
Analytics.trackError(error, "sendUserOperation");
|
|
1219
|
+
throw error;
|
|
1220
|
+
}
|
|
1107
1221
|
}
|
|
1108
1222
|
|
|
1109
1223
|
/**
|
|
@@ -1132,17 +1246,22 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1132
1246
|
action: "sign_hash",
|
|
1133
1247
|
});
|
|
1134
1248
|
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1249
|
+
try {
|
|
1250
|
+
const signature = await CdpOpenApiClient.signEvmHash(
|
|
1251
|
+
options.address,
|
|
1252
|
+
{
|
|
1253
|
+
hash: options.hash,
|
|
1254
|
+
},
|
|
1255
|
+
options.idempotencyKey,
|
|
1256
|
+
);
|
|
1142
1257
|
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1258
|
+
return {
|
|
1259
|
+
signature: signature.signature as Hex,
|
|
1260
|
+
};
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
Analytics.trackError(error, "signHash");
|
|
1263
|
+
throw error;
|
|
1264
|
+
}
|
|
1146
1265
|
}
|
|
1147
1266
|
|
|
1148
1267
|
/**
|
|
@@ -1171,17 +1290,22 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1171
1290
|
action: "sign_message",
|
|
1172
1291
|
});
|
|
1173
1292
|
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1293
|
+
try {
|
|
1294
|
+
const signature = await CdpOpenApiClient.signEvmMessage(
|
|
1295
|
+
options.address,
|
|
1296
|
+
{
|
|
1297
|
+
message: options.message,
|
|
1298
|
+
},
|
|
1299
|
+
options.idempotencyKey,
|
|
1300
|
+
);
|
|
1181
1301
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1302
|
+
return {
|
|
1303
|
+
signature: signature.signature as Hex,
|
|
1304
|
+
};
|
|
1305
|
+
} catch (error) {
|
|
1306
|
+
Analytics.trackError(error, "signMessage");
|
|
1307
|
+
throw error;
|
|
1308
|
+
}
|
|
1185
1309
|
}
|
|
1186
1310
|
|
|
1187
1311
|
/**
|
|
@@ -1234,28 +1358,33 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1234
1358
|
action: "sign_typed_data",
|
|
1235
1359
|
});
|
|
1236
1360
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1361
|
+
try {
|
|
1362
|
+
const { domain, message, primaryType } = options;
|
|
1363
|
+
const types = {
|
|
1364
|
+
EIP712Domain: getTypesForEIP712Domain({ domain }),
|
|
1365
|
+
...options.types,
|
|
1366
|
+
};
|
|
1367
|
+
|
|
1368
|
+
const openApiMessage: OpenAPIEIP712Message = {
|
|
1369
|
+
domain,
|
|
1370
|
+
types,
|
|
1371
|
+
primaryType,
|
|
1372
|
+
message,
|
|
1373
|
+
};
|
|
1374
|
+
|
|
1375
|
+
const signature = await CdpOpenApiClient.signEvmTypedData(
|
|
1376
|
+
options.address,
|
|
1377
|
+
openApiMessage,
|
|
1378
|
+
options.idempotencyKey,
|
|
1379
|
+
);
|
|
1255
1380
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1381
|
+
return {
|
|
1382
|
+
signature: signature.signature as Hex,
|
|
1383
|
+
};
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
Analytics.trackError(error, "signTypedData");
|
|
1386
|
+
throw error;
|
|
1387
|
+
}
|
|
1259
1388
|
}
|
|
1260
1389
|
|
|
1261
1390
|
/**
|
|
@@ -1293,17 +1422,22 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1293
1422
|
action: "sign_transaction",
|
|
1294
1423
|
});
|
|
1295
1424
|
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1425
|
+
try {
|
|
1426
|
+
const signature = await CdpOpenApiClient.signEvmTransaction(
|
|
1427
|
+
options.address,
|
|
1428
|
+
{
|
|
1429
|
+
transaction: options.transaction,
|
|
1430
|
+
},
|
|
1431
|
+
options.idempotencyKey,
|
|
1432
|
+
);
|
|
1303
1433
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1434
|
+
return {
|
|
1435
|
+
signature: signature.signedTransaction as Hex,
|
|
1436
|
+
};
|
|
1437
|
+
} catch (error) {
|
|
1438
|
+
Analytics.trackError(error, "signTransaction");
|
|
1439
|
+
throw error;
|
|
1440
|
+
}
|
|
1307
1441
|
}
|
|
1308
1442
|
|
|
1309
1443
|
/**
|
|
@@ -1352,19 +1486,22 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1352
1486
|
action: "update_account",
|
|
1353
1487
|
});
|
|
1354
1488
|
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
1362
|
-
account: openApiAccount,
|
|
1363
|
-
});
|
|
1489
|
+
try {
|
|
1490
|
+
const openApiAccount = await CdpOpenApiClient.updateEvmAccount(
|
|
1491
|
+
options.address,
|
|
1492
|
+
options.update,
|
|
1493
|
+
options.idempotencyKey,
|
|
1494
|
+
);
|
|
1364
1495
|
|
|
1365
|
-
|
|
1496
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
1497
|
+
account: openApiAccount,
|
|
1498
|
+
});
|
|
1366
1499
|
|
|
1367
|
-
|
|
1500
|
+
return account;
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
Analytics.trackError(error, "updateAccount");
|
|
1503
|
+
throw error;
|
|
1504
|
+
}
|
|
1368
1505
|
}
|
|
1369
1506
|
|
|
1370
1507
|
/**
|
|
@@ -1384,20 +1521,121 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1384
1521
|
action: "update_smart_account",
|
|
1385
1522
|
});
|
|
1386
1523
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1524
|
+
try {
|
|
1525
|
+
const openApiSmartAccount = await CdpOpenApiClient.updateEvmSmartAccount(
|
|
1526
|
+
options.address,
|
|
1527
|
+
options.update,
|
|
1528
|
+
options.idempotencyKey,
|
|
1529
|
+
);
|
|
1392
1530
|
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1531
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
1532
|
+
smartAccount: openApiSmartAccount,
|
|
1533
|
+
owner: options.owner,
|
|
1534
|
+
});
|
|
1535
|
+
|
|
1536
|
+
return smartAccount;
|
|
1537
|
+
} catch (error) {
|
|
1538
|
+
Analytics.trackError(error, "updateSmartAccount");
|
|
1539
|
+
throw error;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
/**
|
|
1544
|
+
* Creates an EIP-7702 delegation for an EVM EOA account, upgrading it with smart account capabilities.
|
|
1545
|
+
* The delegation allows the EVM EOA to be used as a smart account, which enables batched transactions and gas sponsorship via paymaster.
|
|
1546
|
+
*
|
|
1547
|
+
* @param {CreateEvmEip7702DelegationOptions} options - The delegation parameters (address and network required, enableSpendPermissions and idempotencyKey optional).
|
|
1548
|
+
* @returns A promise that resolves to the delegation result including the delegation operation ID.
|
|
1549
|
+
*
|
|
1550
|
+
* @example
|
|
1551
|
+
* ```ts
|
|
1552
|
+
* const result = await cdp.evm.createEvmEip7702Delegation({
|
|
1553
|
+
* address: account.address,
|
|
1554
|
+
* network: "base-sepolia",
|
|
1555
|
+
* enableSpendPermissions: false,
|
|
1556
|
+
* });
|
|
1557
|
+
* console.log(result.delegationOperationId);
|
|
1558
|
+
* ```
|
|
1559
|
+
*/
|
|
1560
|
+
async createEvmEip7702Delegation(
|
|
1561
|
+
options: CreateEvmEip7702DelegationOptions,
|
|
1562
|
+
): Promise<CreateEvmEip7702DelegationResult> {
|
|
1563
|
+
Analytics.trackAction({
|
|
1564
|
+
action: "create_eip7702_delegation",
|
|
1396
1565
|
});
|
|
1397
1566
|
|
|
1398
|
-
|
|
1567
|
+
try {
|
|
1568
|
+
const { address, network, enableSpendPermissions, idempotencyKey } = options;
|
|
1569
|
+
const body = {
|
|
1570
|
+
network,
|
|
1571
|
+
...(enableSpendPermissions !== undefined && { enableSpendPermissions }),
|
|
1572
|
+
};
|
|
1573
|
+
return await CdpOpenApiClient.createEvmEip7702Delegation(address, body, idempotencyKey);
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
Analytics.trackError(error, "createEvmEip7702Delegation");
|
|
1576
|
+
throw error;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1399
1579
|
|
|
1400
|
-
|
|
1580
|
+
/**
|
|
1581
|
+
* Gets the EIP-7702 delegation operation status.
|
|
1582
|
+
*
|
|
1583
|
+
* @param {string} delegationOperationId - The delegation operation ID returned by createEvmEip7702Delegation.
|
|
1584
|
+
* @returns A promise that resolves to the delegation operation status.
|
|
1585
|
+
*
|
|
1586
|
+
* @example
|
|
1587
|
+
* ```ts
|
|
1588
|
+
* const operation = await cdp.evm.getEvmEip7702DelegationOperationById(
|
|
1589
|
+
* "delegation-op-123",
|
|
1590
|
+
* );
|
|
1591
|
+
* console.log(operation.status); // "PENDING" | "SUBMITTED" | "COMPLETED" | "FAILED"
|
|
1592
|
+
* ```
|
|
1593
|
+
*/
|
|
1594
|
+
async getEvmEip7702DelegationOperationById(
|
|
1595
|
+
delegationOperationId: string,
|
|
1596
|
+
): Promise<EvmEip7702DelegationOperation> {
|
|
1597
|
+
Analytics.trackAction({
|
|
1598
|
+
action: "get_eip7702_delegation_operation_by_id",
|
|
1599
|
+
});
|
|
1600
|
+
|
|
1601
|
+
try {
|
|
1602
|
+
return await CdpOpenApiClient.getEvmEip7702DelegationOperationById(delegationOperationId);
|
|
1603
|
+
} catch (error) {
|
|
1604
|
+
Analytics.trackError(error, "getEvmEip7702DelegationOperationById");
|
|
1605
|
+
throw error;
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/**
|
|
1610
|
+
* Polls the EIP-7702 delegation operation status until the status is COMPLETED or a timeout occurs.
|
|
1611
|
+
*
|
|
1612
|
+
* @param {WaitForEvmEip7702DelegationOperationStatusOptions} options - Parameters for waiting, including delegationOperationId and optional wait configuration.
|
|
1613
|
+
* @param {string} options.delegationOperationId - The delegation operation ID returned by createEvmEip7702Delegation.
|
|
1614
|
+
* @param {WaitOptions} [options.waitOptions] - Optional parameters for the wait operation.
|
|
1615
|
+
*
|
|
1616
|
+
* @returns A promise that resolves to the delegation operation once it reaches COMPLETED.
|
|
1617
|
+
*
|
|
1618
|
+
* @example
|
|
1619
|
+
* ```ts
|
|
1620
|
+
* const operation = await cdp.evm.waitForEvmEip7702DelegationOperationStatus({
|
|
1621
|
+
* delegationOperationId: "delegation-op-123",
|
|
1622
|
+
* });
|
|
1623
|
+
* console.log(operation.status); // "COMPLETED"
|
|
1624
|
+
* ```
|
|
1625
|
+
*/
|
|
1626
|
+
async waitForEvmEip7702DelegationOperationStatus(
|
|
1627
|
+
options: WaitForEvmEip7702DelegationOperationStatusOptions,
|
|
1628
|
+
): Promise<EvmEip7702DelegationOperation> {
|
|
1629
|
+
Analytics.trackAction({
|
|
1630
|
+
action: "wait_for_eip7702_delegation_operation_status",
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
try {
|
|
1634
|
+
return await waitForEvmEip7702DelegationOperationStatus(CdpOpenApiClient, options);
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
Analytics.trackError(error, "waitForEvmEip7702DelegationOperationStatus");
|
|
1637
|
+
throw error;
|
|
1638
|
+
}
|
|
1401
1639
|
}
|
|
1402
1640
|
|
|
1403
1641
|
/**
|
|
@@ -1439,9 +1677,14 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1439
1677
|
action: "wait_for_user_operation",
|
|
1440
1678
|
});
|
|
1441
1679
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1680
|
+
try {
|
|
1681
|
+
return await waitForUserOperation(CdpOpenApiClient, {
|
|
1682
|
+
...options,
|
|
1683
|
+
});
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
Analytics.trackError(error, "waitForUserOperation");
|
|
1686
|
+
throw error;
|
|
1687
|
+
}
|
|
1445
1688
|
}
|
|
1446
1689
|
|
|
1447
1690
|
/**
|
|
@@ -1466,8 +1709,6 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1466
1709
|
account: openApiAccount,
|
|
1467
1710
|
});
|
|
1468
1711
|
|
|
1469
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
1470
|
-
|
|
1471
1712
|
return account;
|
|
1472
1713
|
}
|
|
1473
1714
|
|
|
@@ -1495,8 +1736,6 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1495
1736
|
account: openApiAccount,
|
|
1496
1737
|
});
|
|
1497
1738
|
|
|
1498
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
1499
|
-
|
|
1500
1739
|
return account;
|
|
1501
1740
|
}
|
|
1502
1741
|
|
|
@@ -1529,8 +1768,6 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1529
1768
|
owner: options.owner,
|
|
1530
1769
|
});
|
|
1531
1770
|
|
|
1532
|
-
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
1533
|
-
|
|
1534
1771
|
return smartAccount;
|
|
1535
1772
|
}
|
|
1536
1773
|
|
|
@@ -1566,8 +1803,6 @@ Provided Owner Address: ${options.owner.address}\n`,
|
|
|
1566
1803
|
owner: options.owner,
|
|
1567
1804
|
});
|
|
1568
1805
|
|
|
1569
|
-
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
1570
|
-
|
|
1571
1806
|
return smartAccount;
|
|
1572
1807
|
}
|
|
1573
1808
|
}
|