@coinbase/cdp-sdk 1.32.0 → 1.34.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/README.md +9 -7
- package/_cjs/accounts/evm/toEvmServerAccount.js +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +2 -2
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +2 -2
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/listSpendPermissions.js +19 -1
- package/_cjs/actions/evm/listSpendPermissions.js.map +1 -1
- package/_cjs/actions/evm/spend-permissions/resolveSpendPermission.js +64 -0
- package/_cjs/actions/evm/spend-permissions/resolveSpendPermission.js.map +1 -0
- package/_cjs/client/evm/evm.js +12 -11
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +57 -2
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +79 -20
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js +1 -2
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +1 -0
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.js +63 -0
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.js.map +1 -0
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.msw.js +139 -0
- package/_cjs/openapi-client/generated/onchain-data/onchain-data.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +94 -6
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +1 -0
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/evmSchema.js +18 -1
- package/_cjs/policies/evmSchema.js.map +1 -1
- package/_cjs/spend-permissions/utils.js +26 -0
- package/_cjs/spend-permissions/utils.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +2 -2
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +2 -2
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/listSpendPermissions.js +19 -1
- package/_esm/actions/evm/listSpendPermissions.js.map +1 -1
- package/_esm/actions/evm/spend-permissions/resolveSpendPermission.js +61 -0
- package/_esm/actions/evm/spend-permissions/resolveSpendPermission.js.map +1 -0
- package/_esm/client/evm/evm.js +13 -12
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +55 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +79 -20
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js +1 -2
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +1 -0
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/onchain-data/onchain-data.js +57 -0
- package/_esm/openapi-client/generated/onchain-data/onchain-data.js.map +1 -0
- package/_esm/openapi-client/generated/onchain-data/onchain-data.msw.js +129 -0
- package/_esm/openapi-client/generated/onchain-data/onchain-data.msw.js.map +1 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +88 -4
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +1 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/evmSchema.js +17 -0
- package/_esm/policies/evmSchema.js.map +1 -1
- package/_esm/spend-permissions/utils.js +23 -0
- package/_esm/spend-permissions/utils.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +5 -5
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/actions/evm/listSpendPermissions.d.ts +10 -2
- package/_types/actions/evm/listSpendPermissions.d.ts.map +1 -1
- package/_types/actions/evm/spend-permissions/resolveSpendPermission.d.ts +12 -0
- package/_types/actions/evm/spend-permissions/resolveSpendPermission.d.ts.map +1 -0
- package/_types/actions/evm/spend-permissions/types.d.ts +3 -2
- package/_types/actions/evm/spend-permissions/types.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +4 -8
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +3 -2
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +7 -44
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +198 -22
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts +1 -2
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +1 -0
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts +59 -0
- package/_types/openapi-client/generated/onchain-data/onchain-data.d.ts.map +1 -0
- package/_types/openapi-client/generated/onchain-data/onchain-data.msw.d.ts +10 -0
- package/_types/openapi-client/generated/onchain-data/onchain-data.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +1 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +170 -18
- package/_types/policies/evmSchema.d.ts.map +1 -1
- package/_types/policies/types.d.ts +152 -0
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/spend-permissions/types.d.ts +40 -5
- package/_types/spend-permissions/types.d.ts.map +1 -1
- package/_types/spend-permissions/utils.d.ts +12 -0
- package/_types/spend-permissions/utils.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +1 -3
- package/accounts/evm/toEvmSmartAccount.ts +1 -1
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +4 -4
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +4 -4
- package/accounts/evm/types.ts +5 -5
- package/actions/evm/listSpendPermissions.ts +42 -3
- package/actions/evm/spend-permissions/resolveSpendPermission.ts +85 -0
- package/actions/evm/spend-permissions/types.ts +3 -2
- package/actions/evm/types.ts +4 -12
- package/client/evm/evm.ts +25 -16
- package/client/evm/evm.types.ts +6 -48
- package/index.ts +2 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +227 -22
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +79 -20
- package/openapi-client/generated/evm-token-balances/evm-token-balances.ts +1 -2
- package/openapi-client/generated/index.msw.ts +1 -0
- package/openapi-client/generated/onchain-data/onchain-data.msw.ts +185 -0
- package/openapi-client/generated/onchain-data/onchain-data.ts +103 -0
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +101 -4
- package/openapi-client/index.ts +1 -0
- package/package.json +1 -1
- package/policies/evmSchema.ts +19 -0
- package/spend-permissions/types.ts +46 -16
- package/spend-permissions/utils.ts +35 -0
- package/version.ts +1 -1
|
@@ -1,5 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
CdpOpenApiClient,
|
|
3
|
+
ListResponse,
|
|
4
|
+
SpendPermissionResponseObject as SpendPermissionResponseObjectApi,
|
|
5
|
+
} from "../../openapi-client/index.js";
|
|
6
|
+
import type {
|
|
7
|
+
ListSpendPermissionsOptions,
|
|
8
|
+
SpendPermission,
|
|
9
|
+
} from "../../spend-permissions/types.js";
|
|
10
|
+
import type { Address, Hex } from "../../types/misc.js";
|
|
11
|
+
|
|
12
|
+
export type SpendPermissionResponseObject = Omit<
|
|
13
|
+
SpendPermissionResponseObjectApi,
|
|
14
|
+
"permission" | "permissionHash"
|
|
15
|
+
> & {
|
|
16
|
+
permissionHash: Hex;
|
|
17
|
+
permission: SpendPermission;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ListSpendPermissionsResult = ListResponse & {
|
|
21
|
+
spendPermissions: SpendPermissionResponseObject[];
|
|
22
|
+
};
|
|
3
23
|
|
|
4
24
|
/**
|
|
5
25
|
* Lists the spend permissions for a smart account.
|
|
@@ -13,8 +33,27 @@ export async function listSpendPermissions(
|
|
|
13
33
|
client: typeof CdpOpenApiClient,
|
|
14
34
|
options: ListSpendPermissionsOptions,
|
|
15
35
|
): Promise<ListSpendPermissionsResult> {
|
|
16
|
-
|
|
36
|
+
const result = await client.listSpendPermissions(options.address, {
|
|
17
37
|
pageSize: options.pageSize,
|
|
18
38
|
pageToken: options.pageToken,
|
|
19
39
|
});
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
spendPermissions: result.spendPermissions.map(permission => ({
|
|
43
|
+
...permission,
|
|
44
|
+
permissionHash: permission.permissionHash as Hex,
|
|
45
|
+
permission: {
|
|
46
|
+
...permission.permission,
|
|
47
|
+
account: permission.permission.account as Address,
|
|
48
|
+
spender: permission.permission.spender as Address,
|
|
49
|
+
token: permission.permission.token as Address,
|
|
50
|
+
allowance: BigInt(permission.permission.allowance),
|
|
51
|
+
period: Number(permission.permission.period),
|
|
52
|
+
start: Number(permission.permission.start),
|
|
53
|
+
end: Number(permission.permission.end),
|
|
54
|
+
salt: BigInt(permission.permission.salt),
|
|
55
|
+
extraData: permission.permission.extraData as Hex,
|
|
56
|
+
},
|
|
57
|
+
})),
|
|
58
|
+
};
|
|
20
59
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { UserInputValidationError } from "../../../errors.js";
|
|
2
|
+
import { resolveTokenAddress } from "../../../spend-permissions/utils.js";
|
|
3
|
+
|
|
4
|
+
import type { SpendPermissionNetwork } from "../../../openapi-client/index.js";
|
|
5
|
+
import type { SpendPermission, SpendPermissionInput } from "../../../spend-permissions/types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Generate a random salt using crypto.getRandomValues().
|
|
9
|
+
*
|
|
10
|
+
* @returns A random bigint salt.
|
|
11
|
+
*/
|
|
12
|
+
function generateRandomSalt(): bigint {
|
|
13
|
+
const randomBytes = new Uint8Array(32);
|
|
14
|
+
crypto.getRandomValues(randomBytes);
|
|
15
|
+
|
|
16
|
+
// Convert bytes to bigint
|
|
17
|
+
let result = 0n;
|
|
18
|
+
for (let i = 0; i < randomBytes.length; i++) {
|
|
19
|
+
result = (result << 8n) + BigInt(randomBytes[i]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Resolve a spend permission input to a spend permission.
|
|
27
|
+
*
|
|
28
|
+
* @param spendPermissionInput - The spend permission input to resolve.
|
|
29
|
+
* @param network - The network to resolve the spend permission for.
|
|
30
|
+
*
|
|
31
|
+
* @returns The resolved spend permission.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveSpendPermission(
|
|
34
|
+
spendPermissionInput: SpendPermissionInput,
|
|
35
|
+
network: SpendPermissionNetwork,
|
|
36
|
+
): SpendPermission {
|
|
37
|
+
// Validate that either period or periodInDays is provided, but not both
|
|
38
|
+
if (
|
|
39
|
+
spendPermissionInput.period !== undefined &&
|
|
40
|
+
spendPermissionInput.periodInDays !== undefined
|
|
41
|
+
) {
|
|
42
|
+
throw new UserInputValidationError(
|
|
43
|
+
"Cannot specify both 'period' and 'periodInDays'. Please provide only one.",
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (
|
|
48
|
+
spendPermissionInput.period === undefined &&
|
|
49
|
+
spendPermissionInput.periodInDays === undefined
|
|
50
|
+
) {
|
|
51
|
+
throw new UserInputValidationError(
|
|
52
|
+
"Must specify either 'period' (in seconds) or 'periodInDays'.",
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Convert periodInDays to period in seconds if provided
|
|
57
|
+
const period = spendPermissionInput.period ?? spendPermissionInput.periodInDays! * 24 * 60 * 60;
|
|
58
|
+
|
|
59
|
+
// Set defaults for start and end
|
|
60
|
+
const now = new Date();
|
|
61
|
+
const startDate = spendPermissionInput.start ?? now;
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* For end date default, we need to handle the max uint48 value carefully
|
|
65
|
+
* JavaScript Date max is around year 275760, but uint48 max (281474976710655) is much larger
|
|
66
|
+
* So we'll use the max uint48 value directly for end if no end date is provided
|
|
67
|
+
*/
|
|
68
|
+
const endDate = spendPermissionInput.end;
|
|
69
|
+
|
|
70
|
+
// Convert Date objects to seconds since epoch for the contract
|
|
71
|
+
const start = Math.floor(startDate.getTime() / 1000);
|
|
72
|
+
const end = endDate ? Math.floor(endDate.getTime() / 1000) : 281474976710655; // Max uint48 value (never expires)
|
|
73
|
+
|
|
74
|
+
const { periodInDays: _periodInDays, ...inputWithoutPeriodInDays } = spendPermissionInput;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
...inputWithoutPeriodInDays,
|
|
78
|
+
token: resolveTokenAddress(spendPermissionInput.token, network),
|
|
79
|
+
period,
|
|
80
|
+
start,
|
|
81
|
+
end,
|
|
82
|
+
salt: spendPermissionInput.salt ?? generateRandomSalt(),
|
|
83
|
+
extraData: spendPermissionInput.extraData ?? "0x",
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SpendPermissionNetwork } from "../../../openapi-client/index.js";
|
|
2
|
+
import type { SpendPermission } from "../../../spend-permissions/types.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Options for using a spend permission
|
|
@@ -9,5 +10,5 @@ export type UseSpendPermissionOptions = {
|
|
|
9
10
|
/** The amount to spend (must be <= allowance) */
|
|
10
11
|
value: bigint;
|
|
11
12
|
/** The network to execute the transaction on */
|
|
12
|
-
network:
|
|
13
|
+
network: SpendPermissionNetwork;
|
|
13
14
|
};
|
package/actions/evm/types.ts
CHANGED
|
@@ -356,8 +356,6 @@ export type AccountActions = Actions & {
|
|
|
356
356
|
swap: (options: AccountSwapOptions) => Promise<AccountSwapResult>;
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
360
|
-
*
|
|
361
359
|
* Uses a spend permission to execute a transaction.
|
|
362
360
|
* This allows the account to spend tokens that have been approved via a spend permission.
|
|
363
361
|
*
|
|
@@ -384,16 +382,14 @@ export type AccountActions = Actions & {
|
|
|
384
382
|
* extraData: "0x",
|
|
385
383
|
* };
|
|
386
384
|
*
|
|
387
|
-
* const result = await account.
|
|
385
|
+
* const result = await account.useSpendPermission({
|
|
388
386
|
* spendPermission,
|
|
389
387
|
* value: parseEther("0.001"), // Spend 0.001 ETH
|
|
390
388
|
* network: "base-sepolia",
|
|
391
389
|
* });
|
|
392
390
|
* ```
|
|
393
391
|
*/
|
|
394
|
-
|
|
395
|
-
options: UseSpendPermissionOptions,
|
|
396
|
-
) => Promise<TransactionResult>;
|
|
392
|
+
useSpendPermission: (options: UseSpendPermissionOptions) => Promise<TransactionResult>;
|
|
397
393
|
};
|
|
398
394
|
|
|
399
395
|
export type SmartAccountActions = Actions & {
|
|
@@ -683,8 +679,6 @@ export type SmartAccountActions = Actions & {
|
|
|
683
679
|
) => Promise<Hex>;
|
|
684
680
|
|
|
685
681
|
/**
|
|
686
|
-
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
687
|
-
*
|
|
688
682
|
* Uses a spend permission to execute a transaction via user operation.
|
|
689
683
|
* This allows the smart account to spend tokens that have been approved via a spend permission.
|
|
690
684
|
*
|
|
@@ -711,14 +705,12 @@ export type SmartAccountActions = Actions & {
|
|
|
711
705
|
* extraData: "0x",
|
|
712
706
|
* };
|
|
713
707
|
*
|
|
714
|
-
* const result = await smartAccount.
|
|
708
|
+
* const result = await smartAccount.useSpendPermission({
|
|
715
709
|
* spendPermission,
|
|
716
710
|
* value: parseEther("0.001"), // Spend 0.001 ETH
|
|
717
711
|
* network: "base-sepolia",
|
|
718
712
|
* });
|
|
719
713
|
* ```
|
|
720
714
|
*/
|
|
721
|
-
|
|
722
|
-
options: UseSpendPermissionOptions,
|
|
723
|
-
) => Promise<SendUserOperationReturnType>;
|
|
715
|
+
useSpendPermission: (options: UseSpendPermissionOptions) => Promise<SendUserOperationReturnType>;
|
|
724
716
|
};
|
package/client/evm/evm.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { type Address, getTypesForEIP712Domain } from "viem";
|
|
|
5
5
|
import {
|
|
6
6
|
CreateServerAccountOptions,
|
|
7
7
|
CreateSmartAccountOptions,
|
|
8
|
-
CreateSpendPermissionOptions,
|
|
9
|
-
RevokeSpendPermissionOptions,
|
|
10
8
|
CreateSwapQuoteOptions,
|
|
11
9
|
CreateSwapQuoteResult,
|
|
12
10
|
EvmClientInterface,
|
|
@@ -23,7 +21,6 @@ import {
|
|
|
23
21
|
ListServerAccountsOptions,
|
|
24
22
|
ListSmartAccountResult,
|
|
25
23
|
ListSmartAccountsOptions,
|
|
26
|
-
ListSpendPermissionsOptions,
|
|
27
24
|
PrepareUserOperationOptions,
|
|
28
25
|
ServerAccount,
|
|
29
26
|
SignatureResult,
|
|
@@ -41,7 +38,10 @@ import {
|
|
|
41
38
|
import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
|
|
42
39
|
import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
|
|
43
40
|
import { getUserOperation } from "../../actions/evm/getUserOperation.js";
|
|
44
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
listSpendPermissions,
|
|
43
|
+
ListSpendPermissionsResult,
|
|
44
|
+
} from "../../actions/evm/listSpendPermissions.js";
|
|
45
45
|
import {
|
|
46
46
|
listTokenBalances,
|
|
47
47
|
ListTokenBalancesOptions,
|
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
SendUserOperationOptions,
|
|
59
59
|
SendUserOperationReturnType,
|
|
60
60
|
} from "../../actions/evm/sendUserOperation.js";
|
|
61
|
+
import { resolveSpendPermission } from "../../actions/evm/spend-permissions/resolveSpendPermission.js";
|
|
61
62
|
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
62
63
|
import { getSwapPrice } from "../../actions/evm/swap/getSwapPrice.js";
|
|
63
64
|
import {
|
|
@@ -70,7 +71,6 @@ import { UserInputValidationError } from "../../errors.js";
|
|
|
70
71
|
import { APIError } from "../../openapi-client/errors.js";
|
|
71
72
|
import {
|
|
72
73
|
CdpOpenApiClient,
|
|
73
|
-
ListSpendPermissionsResult,
|
|
74
74
|
EIP712Message as OpenAPIEIP712Message,
|
|
75
75
|
} from "../../openapi-client/index.js";
|
|
76
76
|
import { SPEND_PERMISSION_MANAGER_ADDRESS } from "../../spend-permissions/constants.js";
|
|
@@ -81,6 +81,11 @@ import type {
|
|
|
81
81
|
SendTransactionOptions,
|
|
82
82
|
TransactionResult,
|
|
83
83
|
} from "../../actions/evm/sendTransaction.js";
|
|
84
|
+
import type {
|
|
85
|
+
CreateSpendPermissionOptions,
|
|
86
|
+
ListSpendPermissionsOptions,
|
|
87
|
+
RevokeSpendPermissionOptions,
|
|
88
|
+
} from "../../spend-permissions/types.js";
|
|
84
89
|
|
|
85
90
|
/**
|
|
86
91
|
* The namespace containing all EVM methods.
|
|
@@ -358,18 +363,22 @@ export class EvmClient implements EvmClientInterface {
|
|
|
358
363
|
action: "create_spend_permission",
|
|
359
364
|
});
|
|
360
365
|
|
|
366
|
+
const resolvedSpendPermission = resolveSpendPermission(
|
|
367
|
+
options.spendPermission,
|
|
368
|
+
options.network,
|
|
369
|
+
);
|
|
370
|
+
|
|
361
371
|
const userOperation = await CdpOpenApiClient.createSpendPermission(
|
|
362
|
-
|
|
372
|
+
resolvedSpendPermission.account,
|
|
363
373
|
{
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
extraData: options.spendPermission.extraData,
|
|
374
|
+
spender: resolvedSpendPermission.spender,
|
|
375
|
+
token: resolvedSpendPermission.token,
|
|
376
|
+
allowance: resolvedSpendPermission.allowance.toString(),
|
|
377
|
+
period: resolvedSpendPermission.period.toString(),
|
|
378
|
+
start: resolvedSpendPermission.start.toString(),
|
|
379
|
+
end: resolvedSpendPermission.end.toString(),
|
|
380
|
+
salt: resolvedSpendPermission.salt.toString(),
|
|
381
|
+
extraData: resolvedSpendPermission.extraData,
|
|
373
382
|
network: options.network,
|
|
374
383
|
paymasterUrl: options.paymasterUrl,
|
|
375
384
|
},
|
|
@@ -1436,7 +1445,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1436
1445
|
): Promise<SmartAccount> {
|
|
1437
1446
|
const owners = [options.owner.address];
|
|
1438
1447
|
|
|
1439
|
-
if (options.
|
|
1448
|
+
if (options.enableSpendPermissions) {
|
|
1440
1449
|
owners.push(SPEND_PERMISSION_MANAGER_ADDRESS);
|
|
1441
1450
|
}
|
|
1442
1451
|
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { SpendPermission } from "../../spend-permissions/types.js";
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
EvmAccount as Account,
|
|
5
3
|
EvmServerAccount as ServerAccount,
|
|
6
4
|
EvmSmartAccount as SmartAccount,
|
|
7
5
|
} from "../../accounts/evm/types.js";
|
|
6
|
+
import type { ListSpendPermissionsResult } from "../../actions/evm/listSpendPermissions.js";
|
|
8
7
|
import type {
|
|
9
8
|
ListTokenBalancesOptions,
|
|
10
9
|
ListTokenBalancesResult,
|
|
@@ -23,12 +22,12 @@ import type {
|
|
|
23
22
|
EvmSwapsNetwork,
|
|
24
23
|
EvmUserOperationNetwork,
|
|
25
24
|
EvmUserOperationStatus,
|
|
26
|
-
ListSpendPermissionsResult,
|
|
27
25
|
OpenApiEvmMethods,
|
|
28
26
|
UpdateEvmAccountBody as UpdateEvmAccount,
|
|
29
27
|
UpdateEvmSmartAccountBody as UpdateEvmSmartAccount,
|
|
30
28
|
UserOperationReceipt,
|
|
31
29
|
} from "../../openapi-client/index.js";
|
|
30
|
+
import type { ListSpendPermissionsOptions } from "../../spend-permissions/types.js";
|
|
32
31
|
import type { Calls } from "../../types/calls.js";
|
|
33
32
|
import type { Address, EIP712Message, Hex } from "../../types/misc.js";
|
|
34
33
|
import type { WaitOptions } from "../../utils/wait.js";
|
|
@@ -266,39 +265,6 @@ export interface CreateSwapQuoteResult {
|
|
|
266
265
|
execute: (options?: ExecuteSwapQuoteOptions) => Promise<ExecuteSwapQuoteResult>;
|
|
267
266
|
}
|
|
268
267
|
|
|
269
|
-
export interface CreateSpendPermissionOptions {
|
|
270
|
-
/** The spend permission. */
|
|
271
|
-
spendPermission: SpendPermission;
|
|
272
|
-
/** The network. */
|
|
273
|
-
network: EvmUserOperationNetwork;
|
|
274
|
-
/** The paymaster URL. */
|
|
275
|
-
paymasterUrl?: string;
|
|
276
|
-
/** The idempotency key. */
|
|
277
|
-
idempotencyKey?: string;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export interface ListSpendPermissionsOptions {
|
|
281
|
-
/** The address of the smart account. */
|
|
282
|
-
address: Address;
|
|
283
|
-
/** The page size to paginate through the spend permissions. */
|
|
284
|
-
pageSize?: number;
|
|
285
|
-
/** The page token to paginate through the spend permissions. */
|
|
286
|
-
pageToken?: string;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export interface RevokeSpendPermissionOptions {
|
|
290
|
-
/** The address of the smart account. */
|
|
291
|
-
address: Address;
|
|
292
|
-
/** The hash of the spend permission to revoke. */
|
|
293
|
-
permissionHash: Hex;
|
|
294
|
-
/** The network. */
|
|
295
|
-
network: EvmUserOperationNetwork;
|
|
296
|
-
/** The paymaster URL. */
|
|
297
|
-
paymasterUrl?: string;
|
|
298
|
-
/** The idempotency key. */
|
|
299
|
-
idempotencyKey?: string;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
268
|
/**
|
|
303
269
|
* Options for getting a user operation.
|
|
304
270
|
*/
|
|
@@ -439,12 +405,8 @@ export interface GetOrCreateSmartAccountOptions {
|
|
|
439
405
|
name: string;
|
|
440
406
|
/** The owner of the account. */
|
|
441
407
|
owner: Account;
|
|
442
|
-
/**
|
|
443
|
-
|
|
444
|
-
*
|
|
445
|
-
* The flag to enable spend permission.
|
|
446
|
-
*/
|
|
447
|
-
__experimental_enableSpendPermission?: boolean;
|
|
408
|
+
/** The flag to enable spend permissions. */
|
|
409
|
+
enableSpendPermissions?: boolean;
|
|
448
410
|
}
|
|
449
411
|
|
|
450
412
|
/**
|
|
@@ -540,12 +502,8 @@ export interface CreateSmartAccountOptions {
|
|
|
540
502
|
idempotencyKey?: string;
|
|
541
503
|
/** The name of the account. */
|
|
542
504
|
name?: string;
|
|
543
|
-
/**
|
|
544
|
-
|
|
545
|
-
*
|
|
546
|
-
* The flag to enable spend permission.
|
|
547
|
-
*/
|
|
548
|
-
__experimental_enableSpendPermission?: boolean;
|
|
505
|
+
/** The flag to enable spend permissions. */
|
|
506
|
+
enableSpendPermissions?: boolean;
|
|
549
507
|
}
|
|
550
508
|
|
|
551
509
|
/**
|
package/index.ts
CHANGED
|
@@ -8,7 +8,8 @@ export {
|
|
|
8
8
|
type UpdatePolicyBody,
|
|
9
9
|
} from "./policies/types.js";
|
|
10
10
|
export { NetworkError } from "./openapi-client/errors.js";
|
|
11
|
-
export type { SpendPermission } from "./spend-permissions/types.js";
|
|
11
|
+
export type { SpendPermission, SpendPermissionInput } from "./spend-permissions/types.js";
|
|
12
|
+
export type { SpendPermissionNetwork } from "./openapi-client/index.js";
|
|
12
13
|
export {
|
|
13
14
|
SPEND_PERMISSION_MANAGER_ABI as spendPermissionManagerAbi,
|
|
14
15
|
SPEND_PERMISSION_MANAGER_ADDRESS as spendPermissionManagerAddress,
|