@coinbase/cdp-sdk 1.31.0 → 1.32.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 +12 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +61 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +21 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/listSpendPermissions.js +18 -0
- package/_cjs/actions/evm/listSpendPermissions.js.map +1 -0
- package/_cjs/actions/evm/listTokenBalances.js +2 -0
- package/_cjs/actions/evm/listTokenBalances.js.map +1 -1
- package/_cjs/client/evm/evm.js +157 -60
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +72 -5
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/client/solana/solana.js +47 -27
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +3 -3
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +53 -2
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +215 -5
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/policies/{schema.js → evmSchema.js} +11 -112
- package/_cjs/policies/evmSchema.js.map +1 -0
- package/_cjs/policies/solanaSchema.js +183 -0
- package/_cjs/policies/solanaSchema.js.map +1 -0
- package/_cjs/policies/types.js +60 -0
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +61 -0
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +21 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/listSpendPermissions.js +15 -0
- package/_esm/actions/evm/listSpendPermissions.js.map +1 -0
- package/_esm/actions/evm/listTokenBalances.js +2 -0
- package/_esm/actions/evm/listTokenBalances.js.map +1 -1
- package/_esm/client/evm/evm.js +157 -60
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +70 -3
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/client/solana/solana.js +47 -27
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +51 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +197 -3
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/policies/{schema.js → evmSchema.js} +10 -111
- package/_esm/policies/evmSchema.js.map +1 -0
- package/_esm/policies/solanaSchema.js +180 -0
- package/_esm/policies/solanaSchema.js.map +1 -0
- package/_esm/policies/types.js +59 -1
- package/_esm/policies/types.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/actions/evm/listSpendPermissions.d.ts +12 -0
- package/_types/actions/evm/listSpendPermissions.d.ts.map +1 -0
- package/_types/actions/evm/listTokenBalances.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +66 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +2 -1
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts +69 -2
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/client/policies/policies.types.d.ts +1 -2
- package/_types/client/policies/policies.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +16 -0
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +140 -2
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +17 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +4367 -0
- package/_types/policies/evmSchema.d.ts.map +1 -0
- package/_types/policies/solanaSchema.d.ts +758 -0
- package/_types/policies/solanaSchema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +6591 -1
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +69 -0
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +22 -0
- package/actions/evm/listSpendPermissions.ts +20 -0
- package/actions/evm/listTokenBalances.ts +2 -0
- package/client/evm/evm.ts +200 -81
- package/client/evm/evm.types.ts +4 -0
- package/client/policies/policies.ts +70 -4
- package/client/policies/policies.types.ts +1 -2
- package/client/solana/solana.ts +60 -38
- package/index.ts +1 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +198 -1
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +285 -3
- package/package.json +1 -1
- package/policies/{schema.ts → evmSchema.ts} +9 -158
- package/policies/solanaSchema.ts +251 -0
- package/policies/types.ts +94 -1
- package/version.ts +1 -1
- package/_cjs/policies/schema.js.map +0 -1
- package/_esm/policies/schema.js.map +0 -1
- package/_types/policies/schema.d.ts +0 -11599
- package/_types/policies/schema.d.ts.map +0 -1
package/client/evm/evm.ts
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
CreateServerAccountOptions,
|
|
7
7
|
CreateSmartAccountOptions,
|
|
8
8
|
CreateSpendPermissionOptions,
|
|
9
|
+
RevokeSpendPermissionOptions,
|
|
9
10
|
CreateSwapQuoteOptions,
|
|
10
11
|
CreateSwapQuoteResult,
|
|
11
12
|
EvmClientInterface,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
ListServerAccountsOptions,
|
|
23
24
|
ListSmartAccountResult,
|
|
24
25
|
ListSmartAccountsOptions,
|
|
26
|
+
ListSpendPermissionsOptions,
|
|
25
27
|
PrepareUserOperationOptions,
|
|
26
28
|
ServerAccount,
|
|
27
29
|
SignatureResult,
|
|
@@ -39,6 +41,7 @@ import {
|
|
|
39
41
|
import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
|
|
40
42
|
import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
|
|
41
43
|
import { getUserOperation } from "../../actions/evm/getUserOperation.js";
|
|
44
|
+
import { listSpendPermissions } from "../../actions/evm/listSpendPermissions.js";
|
|
42
45
|
import {
|
|
43
46
|
listTokenBalances,
|
|
44
47
|
ListTokenBalancesOptions,
|
|
@@ -67,6 +70,7 @@ import { UserInputValidationError } from "../../errors.js";
|
|
|
67
70
|
import { APIError } from "../../openapi-client/errors.js";
|
|
68
71
|
import {
|
|
69
72
|
CdpOpenApiClient,
|
|
73
|
+
ListSpendPermissionsResult,
|
|
70
74
|
EIP712Message as OpenAPIEIP712Message,
|
|
71
75
|
} from "../../openapi-client/index.js";
|
|
72
76
|
import { SPEND_PERMISSION_MANAGER_ADDRESS } from "../../spend-permissions/constants.js";
|
|
@@ -122,21 +126,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
122
126
|
accountType: "evm_server",
|
|
123
127
|
});
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
{
|
|
127
|
-
name: options.name,
|
|
128
|
-
accountPolicy: options.accountPolicy,
|
|
129
|
-
},
|
|
130
|
-
options.idempotencyKey,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
134
|
-
account: openApiAccount,
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
138
|
-
|
|
139
|
-
return account;
|
|
129
|
+
return this._createAccountInternal(options);
|
|
140
130
|
}
|
|
141
131
|
|
|
142
132
|
/**
|
|
@@ -343,28 +333,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
343
333
|
accountType: "evm_smart",
|
|
344
334
|
});
|
|
345
335
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (options.__experimental_enableSpendPermission) {
|
|
349
|
-
owners.push(SPEND_PERMISSION_MANAGER_ADDRESS);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
353
|
-
{
|
|
354
|
-
owners: owners,
|
|
355
|
-
name: options.name,
|
|
356
|
-
},
|
|
357
|
-
options.idempotencyKey,
|
|
358
|
-
);
|
|
359
|
-
|
|
360
|
-
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
361
|
-
smartAccount: openApiSmartAccount,
|
|
362
|
-
owner: options.owner,
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
366
|
-
|
|
367
|
-
return smartAccount;
|
|
336
|
+
return this._createSmartAccountInternal(options);
|
|
368
337
|
}
|
|
369
338
|
|
|
370
339
|
/**
|
|
@@ -419,6 +388,53 @@ export class EvmClient implements EvmClientInterface {
|
|
|
419
388
|
};
|
|
420
389
|
}
|
|
421
390
|
|
|
391
|
+
/**
|
|
392
|
+
* Revokes a spend permission for a smart account.
|
|
393
|
+
*
|
|
394
|
+
* @param {RevokeSpendPermissionOptions} options - Parameters for revoking the spend permission.
|
|
395
|
+
* @param {string} options.address - The address of the smart account.
|
|
396
|
+
* @param {string} options.permissionHash - The hash of the spend permission to revoke.
|
|
397
|
+
* @param {string} options.network - The network of the spend permission.
|
|
398
|
+
* @param {string} [options.paymasterUrl] - The paymaster URL of the spend permission.
|
|
399
|
+
*
|
|
400
|
+
* @returns A promise that resolves to the user operation.
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```ts
|
|
404
|
+
* const userOperation = await cdp.evm.revokeSpendPermission({
|
|
405
|
+
* address: "0x1234567890123456789012345678901234567890",
|
|
406
|
+
* permissionHash: "0x1234567890123456789012345678901234567890123456789012345678901234",
|
|
407
|
+
* network: "base-sepolia",
|
|
408
|
+
* });
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
async revokeSpendPermission(options: RevokeSpendPermissionOptions): Promise<UserOperation> {
|
|
412
|
+
Analytics.trackAction({
|
|
413
|
+
action: "revoke_spend_permission",
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
const userOperation = await CdpOpenApiClient.revokeSpendPermission(
|
|
417
|
+
options.address,
|
|
418
|
+
{
|
|
419
|
+
network: options.network,
|
|
420
|
+
permissionHash: options.permissionHash,
|
|
421
|
+
paymasterUrl: options.paymasterUrl,
|
|
422
|
+
},
|
|
423
|
+
options.idempotencyKey,
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
network: userOperation.network,
|
|
428
|
+
userOpHash: userOperation.userOpHash as Hex,
|
|
429
|
+
status: userOperation.status,
|
|
430
|
+
calls: userOperation.calls.map(call => ({
|
|
431
|
+
to: call.to as Address,
|
|
432
|
+
value: BigInt(call.value),
|
|
433
|
+
data: call.data as Hex,
|
|
434
|
+
})),
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
422
438
|
/**
|
|
423
439
|
* Gets a CDP EVM account.
|
|
424
440
|
*
|
|
@@ -450,25 +466,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
450
466
|
accountType: "evm_server",
|
|
451
467
|
});
|
|
452
468
|
|
|
453
|
-
|
|
454
|
-
if (options.address) {
|
|
455
|
-
return CdpOpenApiClient.getEvmAccount(options.address);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (options.name) {
|
|
459
|
-
return CdpOpenApiClient.getEvmAccountByName(options.name);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
throw new UserInputValidationError("Either address or name must be provided");
|
|
463
|
-
})();
|
|
464
|
-
|
|
465
|
-
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
466
|
-
account: openApiAccount,
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
470
|
-
|
|
471
|
-
return account;
|
|
469
|
+
return this._getAccountInternal(options);
|
|
472
470
|
}
|
|
473
471
|
|
|
474
472
|
/**
|
|
@@ -498,23 +496,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
498
496
|
action: "get_smart_account",
|
|
499
497
|
});
|
|
500
498
|
|
|
501
|
-
|
|
502
|
-
if (options.address) {
|
|
503
|
-
return CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
504
|
-
} else if (options.name) {
|
|
505
|
-
return CdpOpenApiClient.getEvmSmartAccountByName(options.name);
|
|
506
|
-
}
|
|
507
|
-
throw new UserInputValidationError("Either address or name must be provided");
|
|
508
|
-
})();
|
|
509
|
-
|
|
510
|
-
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
511
|
-
smartAccount: openApiSmartAccount,
|
|
512
|
-
owner: options.owner,
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
516
|
-
|
|
517
|
-
return smartAccount;
|
|
499
|
+
return this._getSmartAccountInternal(options);
|
|
518
500
|
}
|
|
519
501
|
|
|
520
502
|
/**
|
|
@@ -539,20 +521,20 @@ export class EvmClient implements EvmClientInterface {
|
|
|
539
521
|
});
|
|
540
522
|
|
|
541
523
|
try {
|
|
542
|
-
const account = await this.
|
|
524
|
+
const account = await this._getAccountInternal(options);
|
|
543
525
|
return account;
|
|
544
526
|
} catch (error) {
|
|
545
527
|
// If it failed because the account doesn't exist, create it
|
|
546
528
|
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
547
529
|
if (doesAccountNotExist) {
|
|
548
530
|
try {
|
|
549
|
-
const account = await this.
|
|
531
|
+
const account = await this._createAccountInternal(options);
|
|
550
532
|
return account;
|
|
551
533
|
} catch (error) {
|
|
552
|
-
// If it failed because the account already exists,
|
|
534
|
+
// If it failed because the account already exists, get the existing account
|
|
553
535
|
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
554
536
|
if (doesAccountAlreadyExist) {
|
|
555
|
-
const account = await this.
|
|
537
|
+
const account = await this._getAccountInternal(options);
|
|
556
538
|
return account;
|
|
557
539
|
}
|
|
558
540
|
throw error;
|
|
@@ -588,20 +570,20 @@ export class EvmClient implements EvmClientInterface {
|
|
|
588
570
|
});
|
|
589
571
|
|
|
590
572
|
try {
|
|
591
|
-
const account = await this.
|
|
573
|
+
const account = await this._getSmartAccountInternal(options);
|
|
592
574
|
return account;
|
|
593
575
|
} catch (error) {
|
|
594
576
|
// If it failed because the account doesn't exist, create it
|
|
595
577
|
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
596
578
|
if (doesAccountNotExist) {
|
|
597
579
|
try {
|
|
598
|
-
const account = await this.
|
|
580
|
+
const account = await this._createSmartAccountInternal(options);
|
|
599
581
|
return account;
|
|
600
582
|
} catch (error) {
|
|
601
|
-
// If it failed because the account already exists,
|
|
583
|
+
// If it failed because the account already exists, get the existing account
|
|
602
584
|
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
603
585
|
if (doesAccountAlreadyExist) {
|
|
604
|
-
const account = await this.
|
|
586
|
+
const account = await this._getSmartAccountInternal(options);
|
|
605
587
|
return account;
|
|
606
588
|
}
|
|
607
589
|
throw error;
|
|
@@ -837,6 +819,26 @@ export class EvmClient implements EvmClientInterface {
|
|
|
837
819
|
};
|
|
838
820
|
}
|
|
839
821
|
|
|
822
|
+
/**
|
|
823
|
+
* Lists the spend permissions for a smart account.
|
|
824
|
+
*
|
|
825
|
+
* @param {ListSpendPermissionsOptions} options - Parameters for listing the spend permissions.
|
|
826
|
+
* @param {string} options.address - The address of the smart account.
|
|
827
|
+
* @param {number} [options.pageSize] - The number of spend permissions to return.
|
|
828
|
+
* @param {string} [options.pageToken] - The page token to return the next page of spend permissions.
|
|
829
|
+
*
|
|
830
|
+
* @returns A promise that resolves to the spend permissions.
|
|
831
|
+
*/
|
|
832
|
+
async listSpendPermissions(
|
|
833
|
+
options: ListSpendPermissionsOptions,
|
|
834
|
+
): Promise<ListSpendPermissionsResult> {
|
|
835
|
+
Analytics.trackAction({
|
|
836
|
+
action: "list_spend_permissions",
|
|
837
|
+
});
|
|
838
|
+
|
|
839
|
+
return listSpendPermissions(CdpOpenApiClient, options);
|
|
840
|
+
}
|
|
841
|
+
|
|
840
842
|
/**
|
|
841
843
|
* Prepares a user operation for a smart account.
|
|
842
844
|
*
|
|
@@ -1365,4 +1367,121 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1365
1367
|
...options,
|
|
1366
1368
|
});
|
|
1367
1369
|
}
|
|
1370
|
+
|
|
1371
|
+
/**
|
|
1372
|
+
* Internal method to create an account without tracking analytics.
|
|
1373
|
+
* Used internally by composite operations to avoid double-counting.
|
|
1374
|
+
*
|
|
1375
|
+
* @param {CreateServerAccountOptions} options - Parameters for creating the account.
|
|
1376
|
+
* @returns {Promise<ServerAccount>} A promise that resolves to the newly created account.
|
|
1377
|
+
*/
|
|
1378
|
+
private async _createAccountInternal(
|
|
1379
|
+
options: CreateServerAccountOptions = {},
|
|
1380
|
+
): Promise<ServerAccount> {
|
|
1381
|
+
const openApiAccount = await CdpOpenApiClient.createEvmAccount(
|
|
1382
|
+
{
|
|
1383
|
+
name: options.name,
|
|
1384
|
+
accountPolicy: options.accountPolicy,
|
|
1385
|
+
},
|
|
1386
|
+
options.idempotencyKey,
|
|
1387
|
+
);
|
|
1388
|
+
|
|
1389
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
1390
|
+
account: openApiAccount,
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
1394
|
+
|
|
1395
|
+
return account;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
/**
|
|
1399
|
+
* Internal method to get an account without tracking analytics.
|
|
1400
|
+
* Used internally by composite operations to avoid double-counting.
|
|
1401
|
+
*
|
|
1402
|
+
* @param {GetServerAccountOptions} options - Parameters for getting the account.
|
|
1403
|
+
* @returns {Promise<ServerAccount>} A promise that resolves to the account.
|
|
1404
|
+
*/
|
|
1405
|
+
private async _getAccountInternal(options: GetServerAccountOptions): Promise<ServerAccount> {
|
|
1406
|
+
const openApiAccount = await (() => {
|
|
1407
|
+
if (options.address) {
|
|
1408
|
+
return CdpOpenApiClient.getEvmAccount(options.address);
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
if (options.name) {
|
|
1412
|
+
return CdpOpenApiClient.getEvmAccountByName(options.name);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
1416
|
+
})();
|
|
1417
|
+
|
|
1418
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
1419
|
+
account: openApiAccount,
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
1423
|
+
|
|
1424
|
+
return account;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Internal method to create a smart account without tracking analytics.
|
|
1429
|
+
* Used internally by composite operations to avoid double-counting.
|
|
1430
|
+
*
|
|
1431
|
+
* @param {CreateSmartAccountOptions} options - Parameters for creating the smart account.
|
|
1432
|
+
* @returns {Promise<SmartAccount>} A promise that resolves to the newly created smart account.
|
|
1433
|
+
*/
|
|
1434
|
+
private async _createSmartAccountInternal(
|
|
1435
|
+
options: CreateSmartAccountOptions,
|
|
1436
|
+
): Promise<SmartAccount> {
|
|
1437
|
+
const owners = [options.owner.address];
|
|
1438
|
+
|
|
1439
|
+
if (options.__experimental_enableSpendPermission) {
|
|
1440
|
+
owners.push(SPEND_PERMISSION_MANAGER_ADDRESS);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
1444
|
+
{
|
|
1445
|
+
owners: owners,
|
|
1446
|
+
name: options.name,
|
|
1447
|
+
},
|
|
1448
|
+
options.idempotencyKey,
|
|
1449
|
+
);
|
|
1450
|
+
|
|
1451
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
1452
|
+
smartAccount: openApiSmartAccount,
|
|
1453
|
+
owner: options.owner,
|
|
1454
|
+
});
|
|
1455
|
+
|
|
1456
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
1457
|
+
|
|
1458
|
+
return smartAccount;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* Internal method to get a smart account without tracking analytics.
|
|
1463
|
+
* Used internally by composite operations to avoid double-counting.
|
|
1464
|
+
*
|
|
1465
|
+
* @param {GetSmartAccountOptions} options - Parameters for getting the smart account.
|
|
1466
|
+
* @returns {Promise<SmartAccount>} A promise that resolves to the smart account.
|
|
1467
|
+
*/
|
|
1468
|
+
private async _getSmartAccountInternal(options: GetSmartAccountOptions): Promise<SmartAccount> {
|
|
1469
|
+
const openApiSmartAccount = await (async () => {
|
|
1470
|
+
if (options.address) {
|
|
1471
|
+
return CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
1472
|
+
} else if (options.name) {
|
|
1473
|
+
return CdpOpenApiClient.getEvmSmartAccountByName(options.name);
|
|
1474
|
+
}
|
|
1475
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
1476
|
+
})();
|
|
1477
|
+
|
|
1478
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
1479
|
+
smartAccount: openApiSmartAccount,
|
|
1480
|
+
owner: options.owner,
|
|
1481
|
+
});
|
|
1482
|
+
|
|
1483
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
1484
|
+
|
|
1485
|
+
return smartAccount;
|
|
1486
|
+
}
|
|
1368
1487
|
}
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
EvmSwapsNetwork,
|
|
24
24
|
EvmUserOperationNetwork,
|
|
25
25
|
EvmUserOperationStatus,
|
|
26
|
+
ListSpendPermissionsResult,
|
|
26
27
|
OpenApiEvmMethods,
|
|
27
28
|
UpdateEvmAccountBody as UpdateEvmAccount,
|
|
28
29
|
UpdateEvmSmartAccountBody as UpdateEvmSmartAccount,
|
|
@@ -88,6 +89,9 @@ export type EvmClientInterface = Omit<
|
|
|
88
89
|
updateSmartAccount: (options: UpdateEvmSmartAccountOptions) => Promise<SmartAccount>;
|
|
89
90
|
listAccounts: (options: ListServerAccountsOptions) => Promise<ListServerAccountResult>;
|
|
90
91
|
listSmartAccounts: (options: ListSmartAccountsOptions) => Promise<ListSmartAccountResult>;
|
|
92
|
+
listSpendPermissions: (
|
|
93
|
+
options: ListSpendPermissionsOptions,
|
|
94
|
+
) => Promise<ListSpendPermissionsResult>;
|
|
91
95
|
listTokenBalances: (options: ListTokenBalancesOptions) => Promise<ListTokenBalancesResult>;
|
|
92
96
|
prepareUserOperation: (options: PrepareUserOperationOptions) => Promise<UserOperation>;
|
|
93
97
|
requestFaucet: (options: RequestFaucetOptions) => Promise<RequestFaucetResult>;
|
|
@@ -13,8 +13,7 @@ import {
|
|
|
13
13
|
CreatePolicyBody,
|
|
14
14
|
UpdatePolicyBody,
|
|
15
15
|
} from "../../openapi-client/index.js";
|
|
16
|
-
import { CreatePolicyBodySchema, UpdatePolicyBodySchema } from "../../policies/
|
|
17
|
-
import { Policy } from "../../policies/types.js";
|
|
16
|
+
import { Policy, CreatePolicyBodySchema, UpdatePolicyBodySchema } from "../../policies/types.js";
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* The namespace containing all Policy methods.
|
|
@@ -80,7 +79,7 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
80
79
|
* @returns {Promise<Policy>} The created policy
|
|
81
80
|
* @throws {ZodError<typeof CreatePolicyBodySchema>} When the policy is invalid
|
|
82
81
|
*
|
|
83
|
-
* @example **Creating a new policy**
|
|
82
|
+
* @example **Creating a new EVM policy**
|
|
84
83
|
* ```ts
|
|
85
84
|
* const policy = await cdp.policies.createPolicy({
|
|
86
85
|
* policy: {
|
|
@@ -103,6 +102,45 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
103
102
|
* });
|
|
104
103
|
* ```
|
|
105
104
|
*
|
|
105
|
+
* @example **Creating a new Solana policy**
|
|
106
|
+
* ```ts
|
|
107
|
+
* const policy = await cdp.policies.createPolicy({
|
|
108
|
+
* policy: {
|
|
109
|
+
* scope: "account",
|
|
110
|
+
* description: "Limits SOL transfers and SPL token operations",
|
|
111
|
+
* rules: [
|
|
112
|
+
* {
|
|
113
|
+
* action: "reject",
|
|
114
|
+
* operation: "signSolTransaction",
|
|
115
|
+
* criteria: [
|
|
116
|
+
* {
|
|
117
|
+
* type: "solValue",
|
|
118
|
+
* solValue: "1000000000", // 1 SOL in lamports
|
|
119
|
+
* operator: ">",
|
|
120
|
+
* },
|
|
121
|
+
* {
|
|
122
|
+
* type: "solAddress",
|
|
123
|
+
* addresses: ["9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"],
|
|
124
|
+
* operator: "in",
|
|
125
|
+
* },
|
|
126
|
+
* ],
|
|
127
|
+
* },
|
|
128
|
+
* {
|
|
129
|
+
* action: "accept",
|
|
130
|
+
* operation: "sendSolTransaction",
|
|
131
|
+
* criteria: [
|
|
132
|
+
* {
|
|
133
|
+
* type: "mintAddress",
|
|
134
|
+
* addresses: ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"], // USDC mint
|
|
135
|
+
* operator: "in",
|
|
136
|
+
* },
|
|
137
|
+
* ],
|
|
138
|
+
* },
|
|
139
|
+
* ],
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
106
144
|
* @example **With idempotency key**
|
|
107
145
|
* ```ts
|
|
108
146
|
* const idempotencyKey = uuidv4();
|
|
@@ -229,7 +267,7 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
229
267
|
* @returns {Promise<Policy>} The updated policy
|
|
230
268
|
* @throws {ZodError<typeof UpdatePolicyBodySchema>} When the updated policy is invalid
|
|
231
269
|
*
|
|
232
|
-
* @example **Updating
|
|
270
|
+
* @example **Updating an EVM policy**
|
|
233
271
|
* ```ts
|
|
234
272
|
* const updatedPolicy = await cdp.policies.updatePolicy({
|
|
235
273
|
* id: "__ID__",
|
|
@@ -252,6 +290,34 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
252
290
|
* });
|
|
253
291
|
* ```
|
|
254
292
|
*
|
|
293
|
+
* @example **Updating a Solana policy**
|
|
294
|
+
* ```ts
|
|
295
|
+
* const updatedPolicy = await cdp.policies.updatePolicy({
|
|
296
|
+
* id: "__ID__",
|
|
297
|
+
* policy: {
|
|
298
|
+
* description: "Updated Solana transaction limits",
|
|
299
|
+
* rules: [
|
|
300
|
+
* {
|
|
301
|
+
* action: "reject",
|
|
302
|
+
* operation: "signSolTransaction",
|
|
303
|
+
* criteria: [
|
|
304
|
+
* {
|
|
305
|
+
* type: "splValue",
|
|
306
|
+
* splValue: "1000000", // SPL token amount
|
|
307
|
+
* operator: ">=",
|
|
308
|
+
* },
|
|
309
|
+
* {
|
|
310
|
+
* type: "mintAddress",
|
|
311
|
+
* addresses: ["EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"], // USDC mint
|
|
312
|
+
* operator: "in",
|
|
313
|
+
* },
|
|
314
|
+
* ],
|
|
315
|
+
* },
|
|
316
|
+
* ],
|
|
317
|
+
* },
|
|
318
|
+
* });
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
255
321
|
* @example **With idempotency key**
|
|
256
322
|
* ```ts
|
|
257
323
|
* const idempotencyKey = uuidv4();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { OpenApiPoliciesMethods } from "../../openapi-client/index.js";
|
|
2
|
-
import { CreatePolicyBody, PolicyScope, UpdatePolicyBody } from "../../policies/
|
|
3
|
-
import { Policy } from "../../policies/types.js";
|
|
2
|
+
import { CreatePolicyBody, Policy, PolicyScope, UpdatePolicyBody } from "../../policies/types.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* The PoliciesClient type, where all OpenApiPoliciesMethods methods are wrapped.
|
package/client/solana/solana.ts
CHANGED
|
@@ -83,21 +83,7 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
83
83
|
accountType: "solana",
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
{
|
|
88
|
-
name: options.name,
|
|
89
|
-
accountPolicy: options.accountPolicy,
|
|
90
|
-
},
|
|
91
|
-
options.idempotencyKey,
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
95
|
-
account: openApiAccount,
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
99
|
-
|
|
100
|
-
return account;
|
|
86
|
+
return this._createAccountInternal(options);
|
|
101
87
|
}
|
|
102
88
|
|
|
103
89
|
/**
|
|
@@ -279,25 +265,7 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
279
265
|
accountType: "solana",
|
|
280
266
|
});
|
|
281
267
|
|
|
282
|
-
|
|
283
|
-
if (options.address) {
|
|
284
|
-
return CdpOpenApiClient.getSolanaAccount(options.address);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (options.name) {
|
|
288
|
-
return CdpOpenApiClient.getSolanaAccountByName(options.name);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
throw new UserInputValidationError("Either address or name must be provided");
|
|
292
|
-
})();
|
|
293
|
-
|
|
294
|
-
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
295
|
-
account: openApiAccount,
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
299
|
-
|
|
300
|
-
return account;
|
|
268
|
+
return this._getAccountInternal(options);
|
|
301
269
|
}
|
|
302
270
|
|
|
303
271
|
/**
|
|
@@ -322,20 +290,20 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
322
290
|
});
|
|
323
291
|
|
|
324
292
|
try {
|
|
325
|
-
const account = await this.
|
|
293
|
+
const account = await this._getAccountInternal(options);
|
|
326
294
|
return account;
|
|
327
295
|
} catch (error) {
|
|
328
296
|
// If it failed because the account doesn't exist, create it
|
|
329
297
|
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
330
298
|
if (doesAccountNotExist) {
|
|
331
299
|
try {
|
|
332
|
-
const account = await this.
|
|
300
|
+
const account = await this._createAccountInternal(options);
|
|
333
301
|
return account;
|
|
334
302
|
} catch (error) {
|
|
335
|
-
// If it failed because the account already exists,
|
|
303
|
+
// If it failed because the account already exists, get the existing account
|
|
336
304
|
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
337
305
|
if (doesAccountAlreadyExist) {
|
|
338
|
-
const account = await this.
|
|
306
|
+
const account = await this._getAccountInternal(options);
|
|
339
307
|
return account;
|
|
340
308
|
}
|
|
341
309
|
throw error;
|
|
@@ -643,4 +611,58 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
643
611
|
nextPageToken: tokenBalances.nextPageToken,
|
|
644
612
|
};
|
|
645
613
|
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Internal method to create a Solana account without tracking analytics.
|
|
617
|
+
* Used internally by composite operations to avoid double-counting.
|
|
618
|
+
*
|
|
619
|
+
* @param {CreateAccountOptions} options - Parameters for creating the account.
|
|
620
|
+
* @returns {Promise<SolanaAccount>} A promise that resolves to the newly created account.
|
|
621
|
+
*/
|
|
622
|
+
private async _createAccountInternal(options: CreateAccountOptions = {}): Promise<SolanaAccount> {
|
|
623
|
+
const openApiAccount = await CdpOpenApiClient.createSolanaAccount(
|
|
624
|
+
{
|
|
625
|
+
name: options.name,
|
|
626
|
+
accountPolicy: options.accountPolicy,
|
|
627
|
+
},
|
|
628
|
+
options.idempotencyKey,
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
632
|
+
account: openApiAccount,
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
636
|
+
|
|
637
|
+
return account;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Internal method to get a Solana account without tracking analytics.
|
|
642
|
+
* Used internally by composite operations to avoid double-counting.
|
|
643
|
+
*
|
|
644
|
+
* @param {GetAccountOptions} options - Parameters for getting the account.
|
|
645
|
+
* @returns {Promise<SolanaAccount>} A promise that resolves to the account.
|
|
646
|
+
*/
|
|
647
|
+
private async _getAccountInternal(options: GetAccountOptions): Promise<SolanaAccount> {
|
|
648
|
+
const openApiAccount = await (() => {
|
|
649
|
+
if (options.address) {
|
|
650
|
+
return CdpOpenApiClient.getSolanaAccount(options.address);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
if (options.name) {
|
|
654
|
+
return CdpOpenApiClient.getSolanaAccountByName(options.name);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
658
|
+
})();
|
|
659
|
+
|
|
660
|
+
const account = toSolanaAccount(CdpOpenApiClient, {
|
|
661
|
+
account: openApiAccount,
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
665
|
+
|
|
666
|
+
return account;
|
|
667
|
+
}
|
|
646
668
|
}
|
package/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export {
|
|
|
6
6
|
UpdatePolicyBodySchema,
|
|
7
7
|
type CreatePolicyBody,
|
|
8
8
|
type UpdatePolicyBody,
|
|
9
|
-
} from "./policies/
|
|
9
|
+
} from "./policies/types.js";
|
|
10
10
|
export { NetworkError } from "./openapi-client/errors.js";
|
|
11
11
|
export type { SpendPermission } from "./spend-permissions/types.js";
|
|
12
12
|
export {
|