@coinbase/cdp-sdk 1.44.1 → 1.45.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 +14 -0
- package/README.md +117 -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 +111 -45
- package/_cjs/accounts/evm/toEvmSmartAccount.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/analytics.js +10 -228
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +0 -6
- package/_cjs/client/cdp.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 +177 -106
- 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/generated/coinbaseDeveloperPlatformAPIs.schemas.js +137 -5
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.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/onramp/onramp.js +15 -1
- package/_cjs/openapi-client/generated/onramp/onramp.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/version.js +1 -1
- 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 +111 -45
- package/_esm/accounts/evm/toEvmSmartAccount.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/analytics.js +9 -227
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +0 -6
- package/_esm/client/cdp.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 +177 -106
- 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 +134 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.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/onramp/onramp.js +13 -0
- package/_esm/openapi-client/generated/onramp/onramp.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/version.js +1 -1
- 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/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/analytics.d.ts +5 -38
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.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.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 +436 -10
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +21 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +8 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +4 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +2717 -601
- 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/version.d.ts +1 -1
- package/accounts/evm/toEvmDelegatedAccount.ts +26 -0
- package/accounts/evm/toEvmServerAccount.ts +115 -67
- package/accounts/evm/toEvmSmartAccount.ts +100 -56
- package/accounts/solana/toSolanaAccount.ts +44 -24
- package/actions/evm/waitForEvmEip7702DelegationStatus.ts +57 -0
- package/analytics.ts +8 -294
- package/client/cdp.ts +0 -7
- package/client/evm/evm.ts +517 -282
- package/client/evm/evm.types.ts +41 -0
- package/client/policies/policies.ts +41 -16
- package/client/solana/solana.ts +195 -141
- package/index.ts +5 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +580 -11
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +49 -0
- package/openapi-client/generated/onramp/onramp.ts +24 -0
- package/package.json +1 -1
- package/policies/evmSchema.ts +164 -0
- package/policies/solanaSchema.ts +130 -0
- package/policies/types.ts +14 -0
- package/version.ts +1 -1
package/client/evm/evm.types.ts
CHANGED
|
@@ -24,6 +24,9 @@ import type {
|
|
|
24
24
|
} from "../../actions/evm/sendUserOperation.js";
|
|
25
25
|
import type { SmartAccountActions } from "../../actions/evm/types.js";
|
|
26
26
|
import type {
|
|
27
|
+
CreateEvmEip7702DelegationResult as CreateEvmEip7702DelegationResultApi,
|
|
28
|
+
EvmEip7702DelegationNetwork,
|
|
29
|
+
EvmEip7702DelegationOperation,
|
|
27
30
|
EvmSwapsNetwork,
|
|
28
31
|
EvmUserOperationNetwork,
|
|
29
32
|
EvmUserOperationStatus,
|
|
@@ -37,6 +40,9 @@ import type { Calls } from "../../types/calls.js";
|
|
|
37
40
|
import type { Address, EIP712Message, Hex } from "../../types/misc.js";
|
|
38
41
|
import type { WaitOptions } from "../../utils/wait.js";
|
|
39
42
|
|
|
43
|
+
/** Result of createEvmEip7702Delegation with delegationOperationId. */
|
|
44
|
+
export type CreateEvmEip7702DelegationResult = CreateEvmEip7702DelegationResultApi;
|
|
45
|
+
|
|
40
46
|
/**
|
|
41
47
|
* The EvmClient type, where all OpenApiEvmMethods methods are wrapped.
|
|
42
48
|
*/
|
|
@@ -75,6 +81,8 @@ export type EvmClientInterface = Omit<
|
|
|
75
81
|
| "exportEvmAccount"
|
|
76
82
|
| "exportEvmAccountByName"
|
|
77
83
|
| "updateEvmSmartAccount" // 🚧 Coming soon
|
|
84
|
+
| "createEvmEip7702Delegation" // mapped to options-based createEvmEip7702Delegation
|
|
85
|
+
| "getEvmEip7702DelegationOperationById" // wrapped as getEvmEip7702DelegationOperationById
|
|
78
86
|
> & {
|
|
79
87
|
createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
|
|
80
88
|
createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
|
|
@@ -111,6 +119,15 @@ export type EvmClientInterface = Omit<
|
|
|
111
119
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
112
120
|
signTypedData: (options: SignTypedDataOptions) => Promise<SignatureResult>;
|
|
113
121
|
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
122
|
+
createEvmEip7702Delegation: (
|
|
123
|
+
options: CreateEvmEip7702DelegationOptions,
|
|
124
|
+
) => Promise<CreateEvmEip7702DelegationResult>;
|
|
125
|
+
getEvmEip7702DelegationOperationById: (
|
|
126
|
+
delegationOperationId: string,
|
|
127
|
+
) => Promise<EvmEip7702DelegationOperation>;
|
|
128
|
+
waitForEvmEip7702DelegationOperationStatus: (
|
|
129
|
+
options: WaitForEvmEip7702DelegationOperationStatusOptions,
|
|
130
|
+
) => Promise<EvmEip7702DelegationOperation>;
|
|
114
131
|
};
|
|
115
132
|
|
|
116
133
|
export type { ServerAccount, SmartAccount };
|
|
@@ -483,6 +500,30 @@ export interface UpdateEvmSmartAccountOptions {
|
|
|
483
500
|
owner: Account;
|
|
484
501
|
}
|
|
485
502
|
|
|
503
|
+
/**
|
|
504
|
+
* Options for creating an EIP-7702 delegation for an EVM EOA account.
|
|
505
|
+
*/
|
|
506
|
+
export interface CreateEvmEip7702DelegationOptions {
|
|
507
|
+
/** The address of the EOA account. */
|
|
508
|
+
address: Address;
|
|
509
|
+
/** The network for the EIP-7702 delegation. */
|
|
510
|
+
network: EvmEip7702DelegationNetwork;
|
|
511
|
+
/** Whether to configure spend permissions for the upgraded, delegated account. When enabled, the account can grant permissions for third parties to spend on its behalf. Defaults to false. */
|
|
512
|
+
enableSpendPermissions?: boolean;
|
|
513
|
+
/** Optional idempotency key. */
|
|
514
|
+
idempotencyKey?: string;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Options for waiting for an EIP-7702 delegation operation to complete.
|
|
519
|
+
*/
|
|
520
|
+
export interface WaitForEvmEip7702DelegationOperationStatusOptions {
|
|
521
|
+
/** The delegation operation ID returned by createEvmEip7702Delegation. */
|
|
522
|
+
delegationOperationId: string;
|
|
523
|
+
/** Optional options for the wait operation. */
|
|
524
|
+
waitOptions?: WaitOptions;
|
|
525
|
+
}
|
|
526
|
+
|
|
486
527
|
/**
|
|
487
528
|
* The result of listing EVM smart accounts.
|
|
488
529
|
*/
|
|
@@ -68,7 +68,12 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
try {
|
|
72
|
+
return CdpOpenApiClient.listPolicies(options) as Promise<ListPoliciesResult>;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
Analytics.trackError(error, "listPolicies");
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
/**
|
|
@@ -186,13 +191,18 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
186
191
|
},
|
|
187
192
|
});
|
|
188
193
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
try {
|
|
195
|
+
CreatePolicyBodySchema.parse(options.policy);
|
|
196
|
+
return CdpOpenApiClient.createPolicy(
|
|
197
|
+
// There are arbitrary differences between the abitype Abi and the openapi Abi
|
|
198
|
+
options.policy as CreatePolicyBody,
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
options.idempotencyKey,
|
|
201
|
+
) as Promise<Policy>;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
Analytics.trackError(error, "createPolicy");
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
196
206
|
}
|
|
197
207
|
|
|
198
208
|
/**
|
|
@@ -218,7 +228,12 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
218
228
|
action: "get_policy_by_id",
|
|
219
229
|
});
|
|
220
230
|
|
|
221
|
-
|
|
231
|
+
try {
|
|
232
|
+
return CdpOpenApiClient.getPolicyById(options.id) as Promise<Policy>;
|
|
233
|
+
} catch (error) {
|
|
234
|
+
Analytics.trackError(error, "getPolicyById");
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
222
237
|
}
|
|
223
238
|
|
|
224
239
|
/**
|
|
@@ -254,7 +269,12 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
254
269
|
action: "delete_policy",
|
|
255
270
|
});
|
|
256
271
|
|
|
257
|
-
|
|
272
|
+
try {
|
|
273
|
+
return CdpOpenApiClient.deletePolicy(options.id, options.idempotencyKey);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
Analytics.trackError(error, "deletePolicy");
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
258
278
|
}
|
|
259
279
|
|
|
260
280
|
/**
|
|
@@ -342,12 +362,17 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
342
362
|
action: "update_policy",
|
|
343
363
|
});
|
|
344
364
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
365
|
+
try {
|
|
366
|
+
UpdatePolicyBodySchema.parse(options.policy);
|
|
367
|
+
return CdpOpenApiClient.updatePolicy(
|
|
368
|
+
options.id,
|
|
369
|
+
// There are arbitrary differences between the abitype Abi and the openapi Abi
|
|
370
|
+
options.policy as UpdatePolicyBody,
|
|
371
|
+
options.idempotencyKey,
|
|
372
|
+
) as Promise<Policy>;
|
|
373
|
+
} catch (error) {
|
|
374
|
+
Analytics.trackError(error, "updatePolicy");
|
|
375
|
+
throw error;
|
|
376
|
+
}
|
|
352
377
|
}
|
|
353
378
|
}
|
package/client/solana/solana.ts
CHANGED
|
@@ -87,7 +87,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
87
87
|
accountType: "solana",
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
try {
|
|
91
|
+
return this._createAccountInternal(options);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
Analytics.trackError(error, "createAccount");
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
91
96
|
}
|
|
92
97
|
|
|
93
98
|
/**
|
|
@@ -120,34 +125,41 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
120
125
|
accountType: "solana",
|
|
121
126
|
});
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
try {
|
|
129
|
+
const { publicKey, privateKey } = await generateExportEncryptionKeyPair();
|
|
130
|
+
|
|
131
|
+
const { encryptedPrivateKey } = await (async () => {
|
|
132
|
+
if (options.address) {
|
|
133
|
+
return CdpOpenApiClient.exportSolanaAccount(
|
|
134
|
+
options.address,
|
|
135
|
+
{
|
|
136
|
+
exportEncryptionKey: publicKey,
|
|
137
|
+
},
|
|
138
|
+
options.idempotencyKey,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
135
141
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
if (options.name) {
|
|
143
|
+
return CdpOpenApiClient.exportSolanaAccountByName(
|
|
144
|
+
options.name,
|
|
145
|
+
{
|
|
146
|
+
exportEncryptionKey: publicKey,
|
|
147
|
+
},
|
|
148
|
+
options.idempotencyKey,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
145
151
|
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
153
|
+
})();
|
|
148
154
|
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
const decryptedPrivateKey = decryptWithPrivateKey(privateKey, encryptedPrivateKey);
|
|
156
|
+
return formatSolanaPrivateKey(decryptedPrivateKey);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (!(error instanceof UserInputValidationError)) {
|
|
159
|
+
Analytics.trackError(error, "exportAccount");
|
|
160
|
+
}
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
151
163
|
}
|
|
152
164
|
|
|
153
165
|
/**
|
|
@@ -194,48 +206,53 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
194
206
|
accountType: "solana",
|
|
195
207
|
});
|
|
196
208
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (typeof options.privateKey === "string") {
|
|
200
|
-
privateKeyBytes = bs58.decode(options.privateKey);
|
|
201
|
-
} else {
|
|
202
|
-
privateKeyBytes = options.privateKey;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (privateKeyBytes.length !== 32 && privateKeyBytes.length !== 64) {
|
|
206
|
-
throw new UserInputValidationError("Invalid private key length");
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (privateKeyBytes.length === 64) {
|
|
210
|
-
privateKeyBytes = privateKeyBytes.subarray(0, 32);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const encryptionPublicKey = options.encryptionPublicKey || ImportAccountPublicRSAKey;
|
|
209
|
+
try {
|
|
210
|
+
let privateKeyBytes: Uint8Array = new Uint8Array();
|
|
214
211
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
},
|
|
221
|
-
privateKeyBytes,
|
|
222
|
-
);
|
|
212
|
+
if (typeof options.privateKey === "string") {
|
|
213
|
+
privateKeyBytes = bs58.decode(options.privateKey);
|
|
214
|
+
} else {
|
|
215
|
+
privateKeyBytes = options.privateKey;
|
|
216
|
+
}
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
name: options.name,
|
|
228
|
-
},
|
|
229
|
-
options.idempotencyKey,
|
|
230
|
-
);
|
|
218
|
+
if (privateKeyBytes.length !== 32 && privateKeyBytes.length !== 64) {
|
|
219
|
+
throw new UserInputValidationError("Invalid private key length");
|
|
220
|
+
}
|
|
231
221
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
222
|
+
if (privateKeyBytes.length === 64) {
|
|
223
|
+
privateKeyBytes = privateKeyBytes.subarray(0, 32);
|
|
224
|
+
}
|
|
235
225
|
|
|
236
|
-
|
|
226
|
+
const encryptionPublicKey = options.encryptionPublicKey || ImportAccountPublicRSAKey;
|
|
227
|
+
|
|
228
|
+
const encryptedPrivateKey = publicEncrypt(
|
|
229
|
+
{
|
|
230
|
+
key: encryptionPublicKey,
|
|
231
|
+
padding: constants.RSA_PKCS1_OAEP_PADDING,
|
|
232
|
+
oaepHash: "sha256",
|
|
233
|
+
},
|
|
234
|
+
privateKeyBytes,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
const openApiAccount = await CdpOpenApiClient.importSolanaAccount(
|
|
238
|
+
{
|
|
239
|
+
encryptedPrivateKey: encryptedPrivateKey.toString("base64"),
|
|
240
|
+
name: options.name,
|
|
241
|
+
},
|
|
242
|
+
options.idempotencyKey,
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
246
|
+
account: openApiAccount,
|
|
247
|
+
});
|
|
237
248
|
|
|
238
|
-
|
|
249
|
+
return account;
|
|
250
|
+
} catch (error) {
|
|
251
|
+
if (!(error instanceof UserInputValidationError)) {
|
|
252
|
+
Analytics.trackError(error, "importAccount");
|
|
253
|
+
}
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
239
256
|
}
|
|
240
257
|
|
|
241
258
|
/**
|
|
@@ -269,7 +286,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
269
286
|
accountType: "solana",
|
|
270
287
|
});
|
|
271
288
|
|
|
272
|
-
|
|
289
|
+
try {
|
|
290
|
+
return this._getAccountInternal(options);
|
|
291
|
+
} catch (error) {
|
|
292
|
+
Analytics.trackError(error, "getAccount");
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
273
295
|
}
|
|
274
296
|
|
|
275
297
|
/**
|
|
@@ -294,26 +316,31 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
294
316
|
});
|
|
295
317
|
|
|
296
318
|
try {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
} catch (error) {
|
|
307
|
-
// If it failed because the account already exists, get the existing account
|
|
308
|
-
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
309
|
-
if (doesAccountAlreadyExist) {
|
|
310
|
-
const account = await this._getAccountInternal(options);
|
|
319
|
+
try {
|
|
320
|
+
const account = await this._getAccountInternal(options);
|
|
321
|
+
return account;
|
|
322
|
+
} catch (error) {
|
|
323
|
+
// If it failed because the account doesn't exist, create it
|
|
324
|
+
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
325
|
+
if (doesAccountNotExist) {
|
|
326
|
+
try {
|
|
327
|
+
const account = await this._createAccountInternal(options);
|
|
311
328
|
return account;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
// If it failed because the account already exists, get the existing account
|
|
331
|
+
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
332
|
+
if (doesAccountAlreadyExist) {
|
|
333
|
+
const account = await this._getAccountInternal(options);
|
|
334
|
+
return account;
|
|
335
|
+
}
|
|
336
|
+
throw error;
|
|
312
337
|
}
|
|
313
|
-
throw error;
|
|
314
338
|
}
|
|
315
|
-
}
|
|
316
339
|
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
} catch (error) {
|
|
343
|
+
Analytics.trackError(error, "getOrCreateAccount");
|
|
317
344
|
throw error;
|
|
318
345
|
}
|
|
319
346
|
}
|
|
@@ -352,23 +379,26 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
352
379
|
accountType: "solana",
|
|
353
380
|
});
|
|
354
381
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
382
|
+
try {
|
|
383
|
+
const solAccounts = await CdpOpenApiClient.listSolanaAccounts({
|
|
384
|
+
pageSize: options.pageSize,
|
|
385
|
+
pageToken: options.pageToken,
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
return {
|
|
389
|
+
accounts: solAccounts.accounts.map(account => {
|
|
390
|
+
const solanaAccount = toSolanaAccount(CdpOpenApiClient, {
|
|
391
|
+
account,
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
return solanaAccount;
|
|
395
|
+
}),
|
|
396
|
+
nextPageToken: solAccounts.nextPageToken,
|
|
397
|
+
};
|
|
398
|
+
} catch (error) {
|
|
399
|
+
Analytics.trackError(error, "listAccounts");
|
|
400
|
+
throw error;
|
|
401
|
+
}
|
|
372
402
|
}
|
|
373
403
|
|
|
374
404
|
/**
|
|
@@ -395,7 +425,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
395
425
|
accountType: "solana",
|
|
396
426
|
});
|
|
397
427
|
|
|
398
|
-
|
|
428
|
+
try {
|
|
429
|
+
return requestFaucet(CdpOpenApiClient, options);
|
|
430
|
+
} catch (error) {
|
|
431
|
+
Analytics.trackError(error, "requestFaucet");
|
|
432
|
+
throw error;
|
|
433
|
+
}
|
|
399
434
|
}
|
|
400
435
|
|
|
401
436
|
/**
|
|
@@ -426,7 +461,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
426
461
|
accountType: "solana",
|
|
427
462
|
});
|
|
428
463
|
|
|
429
|
-
|
|
464
|
+
try {
|
|
465
|
+
return signMessage(CdpOpenApiClient, options);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
Analytics.trackError(error, "signMessage");
|
|
468
|
+
throw error;
|
|
469
|
+
}
|
|
430
470
|
}
|
|
431
471
|
|
|
432
472
|
/**
|
|
@@ -468,7 +508,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
468
508
|
accountType: "solana",
|
|
469
509
|
});
|
|
470
510
|
|
|
471
|
-
|
|
511
|
+
try {
|
|
512
|
+
return signTransaction(CdpOpenApiClient, options);
|
|
513
|
+
} catch (error) {
|
|
514
|
+
Analytics.trackError(error, "signTransaction");
|
|
515
|
+
throw error;
|
|
516
|
+
}
|
|
472
517
|
}
|
|
473
518
|
|
|
474
519
|
/**
|
|
@@ -518,19 +563,22 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
518
563
|
accountType: "solana",
|
|
519
564
|
});
|
|
520
565
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
528
|
-
account: openApiAccount,
|
|
529
|
-
});
|
|
566
|
+
try {
|
|
567
|
+
const openApiAccount = await CdpOpenApiClient.updateSolanaAccount(
|
|
568
|
+
options.address,
|
|
569
|
+
options.update,
|
|
570
|
+
options.idempotencyKey,
|
|
571
|
+
);
|
|
530
572
|
|
|
531
|
-
|
|
573
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
574
|
+
account: openApiAccount,
|
|
575
|
+
});
|
|
532
576
|
|
|
533
|
-
|
|
577
|
+
return account;
|
|
578
|
+
} catch (error) {
|
|
579
|
+
Analytics.trackError(error, "updateAccount");
|
|
580
|
+
throw error;
|
|
581
|
+
}
|
|
534
582
|
}
|
|
535
583
|
|
|
536
584
|
/**
|
|
@@ -560,7 +608,12 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
560
608
|
},
|
|
561
609
|
});
|
|
562
610
|
|
|
563
|
-
|
|
611
|
+
try {
|
|
612
|
+
return sendTransaction(CdpOpenApiClient, options);
|
|
613
|
+
} catch (error) {
|
|
614
|
+
Analytics.trackError(error, "sendTransaction");
|
|
615
|
+
throw error;
|
|
616
|
+
}
|
|
564
617
|
}
|
|
565
618
|
|
|
566
619
|
/**
|
|
@@ -589,31 +642,36 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
589
642
|
},
|
|
590
643
|
});
|
|
591
644
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
amount:
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
645
|
+
try {
|
|
646
|
+
const tokenBalances = await CdpOpenApiClient.listSolanaTokenBalances(
|
|
647
|
+
options.network || "solana",
|
|
648
|
+
options.address,
|
|
649
|
+
{
|
|
650
|
+
pageSize: options.pageSize,
|
|
651
|
+
pageToken: options.pageToken,
|
|
652
|
+
},
|
|
653
|
+
);
|
|
654
|
+
|
|
655
|
+
return {
|
|
656
|
+
balances: tokenBalances.balances.map(balance => {
|
|
657
|
+
return {
|
|
658
|
+
amount: {
|
|
659
|
+
amount: BigInt(balance.amount.amount),
|
|
660
|
+
decimals: balance.amount.decimals,
|
|
661
|
+
},
|
|
662
|
+
token: {
|
|
663
|
+
mintAddress: balance.token.mintAddress,
|
|
664
|
+
name: balance.token.name,
|
|
665
|
+
symbol: balance.token.symbol,
|
|
666
|
+
},
|
|
667
|
+
};
|
|
668
|
+
}),
|
|
669
|
+
nextPageToken: tokenBalances.nextPageToken,
|
|
670
|
+
};
|
|
671
|
+
} catch (error) {
|
|
672
|
+
Analytics.trackError(error, "listTokenBalances");
|
|
673
|
+
throw error;
|
|
674
|
+
}
|
|
617
675
|
}
|
|
618
676
|
|
|
619
677
|
/**
|
|
@@ -636,8 +694,6 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
636
694
|
account: openApiAccount,
|
|
637
695
|
});
|
|
638
696
|
|
|
639
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
640
|
-
|
|
641
697
|
return account;
|
|
642
698
|
}
|
|
643
699
|
|
|
@@ -665,8 +721,6 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
665
721
|
account: openApiAccount,
|
|
666
722
|
});
|
|
667
723
|
|
|
668
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
669
|
-
|
|
670
724
|
return account;
|
|
671
725
|
}
|
|
672
726
|
}
|
package/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export { CdpClient } from "./client/cdp.js";
|
|
2
|
+
export { toEvmDelegatedAccount } from "./accounts/evm/toEvmDelegatedAccount.js";
|
|
2
3
|
export type { EvmServerAccount, EvmSmartAccount } from "./accounts/evm/types.js";
|
|
4
|
+
export type {
|
|
5
|
+
CreateEvmEip7702DelegationResult,
|
|
6
|
+
WaitForEvmEip7702DelegationOperationStatusOptions,
|
|
7
|
+
} from "./client/evm/evm.types.js";
|
|
3
8
|
export type { Policy } from "./policies/types.js";
|
|
4
9
|
export {
|
|
5
10
|
CreatePolicyBodySchema,
|