@coinbase/cdp-sdk 1.29.0 → 1.30.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 +10 -0
- package/_cjs/accounts/evm/networkCapabilities.js +101 -0
- package/_cjs/accounts/evm/networkCapabilities.js.map +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +11 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +11 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +11 -1
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/getUserOperation.js +1 -0
- package/_cjs/actions/evm/getUserOperation.js.map +1 -1
- package/_cjs/actions/evm/spend-permissions/account.use.js +33 -0
- package/_cjs/actions/evm/spend-permissions/account.use.js.map +1 -0
- package/_cjs/actions/evm/spend-permissions/smartAccount.use.js +35 -0
- package/_cjs/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
- package/_cjs/actions/evm/spend-permissions/types.js +3 -0
- package/_cjs/actions/evm/spend-permissions/types.js.map +1 -0
- package/_cjs/actions/solana/sendTransaction.js +1 -0
- package/_cjs/actions/solana/sendTransaction.js.map +1 -1
- package/_cjs/actions/solana/signTransaction.js +1 -0
- package/_cjs/actions/solana/signTransaction.js.map +1 -1
- package/_cjs/auth/hooks/axios/withAuth.js +3 -0
- package/_cjs/auth/hooks/axios/withAuth.js.map +1 -1
- package/_cjs/auth/utils/http.js +2 -1
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/client/evm/evm.js +51 -1
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +5 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +41 -3
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +14 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +72 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +2 -0
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js +30 -0
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -0
- package/_cjs/openapi-client/generated/onramp/onramp.msw.js +98 -0
- package/_cjs/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js +15 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js +69 -0
- package/_cjs/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js.map +1 -0
- package/_cjs/openapi-client/index.js +2 -0
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/spend-permissions/constants.js +716 -0
- package/_cjs/spend-permissions/constants.js.map +1 -0
- package/_cjs/spend-permissions/types.js +3 -0
- package/_cjs/spend-permissions/types.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/networkCapabilities.js +101 -0
- package/_esm/accounts/evm/networkCapabilities.js.map +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +11 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +11 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +10 -0
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +10 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +11 -1
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/getUserOperation.js +1 -0
- package/_esm/actions/evm/getUserOperation.js.map +1 -1
- package/_esm/actions/evm/spend-permissions/account.use.js +30 -0
- package/_esm/actions/evm/spend-permissions/account.use.js.map +1 -0
- package/_esm/actions/evm/spend-permissions/smartAccount.use.js +32 -0
- package/_esm/actions/evm/spend-permissions/smartAccount.use.js.map +1 -0
- package/_esm/actions/evm/spend-permissions/types.js +2 -0
- package/_esm/actions/evm/spend-permissions/types.js.map +1 -0
- package/_esm/actions/solana/sendTransaction.js +1 -0
- package/_esm/actions/solana/sendTransaction.js.map +1 -1
- package/_esm/actions/solana/signTransaction.js +1 -0
- package/_esm/actions/solana/signTransaction.js.map +1 -1
- package/_esm/auth/hooks/axios/withAuth.js +3 -0
- package/_esm/auth/hooks/axios/withAuth.js.map +1 -1
- package/_esm/auth/utils/http.js +2 -1
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/client/evm/evm.js +51 -1
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/solana/solana.js +2 -2
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +2 -1
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +39 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +12 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +69 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +2 -0
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js +25 -0
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -0
- package/_esm/openapi-client/generated/onramp/onramp.msw.js +90 -0
- package/_esm/openapi-client/generated/onramp/onramp.msw.js.map +1 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js +11 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.js.map +1 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js +63 -0
- package/_esm/openapi-client/generated/x402-facilitator/x402-facilitator.msw.js.map +1 -0
- package/_esm/openapi-client/index.js +2 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/spend-permissions/constants.js +713 -0
- package/_esm/spend-permissions/constants.js.map +1 -0
- package/_esm/spend-permissions/types.js +2 -0
- package/_esm/spend-permissions/types.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/networkCapabilities.d.ts +101 -0
- package/_types/accounts/evm/networkCapabilities.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +6 -0
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/getUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/spend-permissions/account.use.d.ts +15 -0
- package/_types/actions/evm/spend-permissions/account.use.d.ts.map +1 -0
- package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts +15 -0
- package/_types/actions/evm/spend-permissions/smartAccount.use.d.ts.map +1 -0
- package/_types/actions/evm/spend-permissions/types.d.ts +13 -0
- package/_types/actions/evm/spend-permissions/types.d.ts.map +1 -0
- package/_types/actions/evm/types.d.ts +75 -0
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/sendTransaction.d.ts +8 -2
- package/_types/actions/solana/sendTransaction.d.ts.map +1 -1
- package/_types/actions/solana/signTransaction.d.ts +8 -2
- package/_types/actions/solana/signTransaction.d.ts.map +1 -1
- package/_types/actions/solana/types.d.ts +38 -3
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +19 -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/solana/solana.d.ts +5 -3
- 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/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +333 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +2 -0
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +28 -0
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -0
- package/_types/openapi-client/generated/onramp/onramp.msw.d.ts +8 -0
- package/_types/openapi-client/generated/onramp/onramp.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts +20 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.d.ts.map +1 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.msw.d.ts +6 -0
- package/_types/openapi-client/generated/x402-facilitator/x402-facilitator.msw.d.ts.map +1 -0
- package/_types/openapi-client/index.d.ts +4 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/spend-permissions/constants.d.ts +1357 -0
- package/_types/spend-permissions/constants.d.ts.map +1 -0
- package/_types/spend-permissions/types.d.ts +30 -0
- package/_types/spend-permissions/types.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/networkCapabilities.ts +101 -0
- package/accounts/evm/toEvmServerAccount.ts +15 -0
- package/accounts/evm/toEvmSmartAccount.ts +19 -4
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +15 -0
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +15 -0
- package/accounts/evm/types.ts +18 -0
- package/accounts/solana/toSolanaAccount.ts +17 -3
- package/actions/evm/getUserOperation.ts +1 -0
- package/actions/evm/spend-permissions/account.use.ts +48 -0
- package/actions/evm/spend-permissions/smartAccount.use.ts +49 -0
- package/actions/evm/spend-permissions/types.ts +13 -0
- package/actions/evm/types.ts +81 -0
- package/actions/solana/sendTransaction.ts +10 -2
- package/actions/solana/signTransaction.ts +10 -2
- package/actions/solana/types.ts +44 -2
- package/auth/hooks/axios/withAuth.ts +3 -0
- package/auth/utils/http.ts +2 -1
- package/client/evm/evm.ts +61 -1
- package/client/evm/evm.types.ts +31 -0
- package/client/solana/solana.ts +10 -5
- package/index.ts +6 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +375 -1
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +85 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +23 -0
- package/openapi-client/generated/index.msw.ts +2 -0
- package/openapi-client/generated/onramp/onramp.msw.ts +135 -0
- package/openapi-client/generated/onramp/onramp.ts +54 -0
- package/openapi-client/generated/x402-facilitator/x402-facilitator.msw.ts +85 -0
- package/openapi-client/generated/x402-facilitator/x402-facilitator.ts +34 -0
- package/openapi-client/index.ts +2 -0
- package/package.json +1 -1
- package/spend-permissions/constants.ts +713 -0
- package/spend-permissions/types.ts +42 -0
- package/version.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../spend-permissions/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gCAAgC,+CAA+C,CAAC;AAE7F,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAssB/B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Address, Hex } from "../types/misc.js";
|
|
2
|
+
/**
|
|
3
|
+
* A spend permission structure that defines authorization for spending tokens
|
|
4
|
+
*/
|
|
5
|
+
export type SpendPermission = {
|
|
6
|
+
/** The account address that owns the tokens */
|
|
7
|
+
account: Address;
|
|
8
|
+
/** The address that is authorized to spend the tokens */
|
|
9
|
+
spender: Address;
|
|
10
|
+
/** The token contract address (use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for ETH) */
|
|
11
|
+
token: Address;
|
|
12
|
+
/** The maximum amount that can be spent (in wei for ETH, or token's smallest unit) */
|
|
13
|
+
allowance: bigint;
|
|
14
|
+
/** Time period in seconds for the spending allowance */
|
|
15
|
+
period: number;
|
|
16
|
+
/** Start timestamp for when the permission becomes valid */
|
|
17
|
+
start: number;
|
|
18
|
+
/** End timestamp for when the permission expires */
|
|
19
|
+
end: number;
|
|
20
|
+
/** Unique salt to prevent replay attacks */
|
|
21
|
+
salt: bigint;
|
|
22
|
+
/** Additional data for the permission */
|
|
23
|
+
extraData: Hex;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Networks that the SpendPermissionManager contract supports.
|
|
27
|
+
* From https://github.com/coinbase/spend-permissions/blob/main/README.md#deployments
|
|
28
|
+
*/
|
|
29
|
+
export type SpendPermissionNetworks = "base" | "base-sepolia" | "ethereum" | "ethereum-sepolia" | "optimism" | "optimism-sepolia" | "arbitrum" | "avalanche" | "binance" | "polygon" | "zora";
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../spend-permissions/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,+CAA+C;IAC/C,OAAO,EAAE,OAAO,CAAC;IACjB,yDAAyD;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,0FAA0F;IAC1F,KAAK,EAAE,OAAO,CAAC;IACf,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,SAAS,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAC/B,MAAM,GACN,cAAc,GACd,UAAU,GACV,kBAAkB,GAClB,UAAU,GACV,kBAAkB,GAClB,UAAU,GACV,WAAW,GACX,SAAS,GACT,SAAS,GACT,MAAM,CAAC"}
|
package/_types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.30.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -18,6 +18,7 @@ export const NETWORK_CAPABILITIES = {
|
|
|
18
18
|
sendTransaction: true,
|
|
19
19
|
quoteSwap: true,
|
|
20
20
|
swap: true,
|
|
21
|
+
useSpendPermission: true,
|
|
21
22
|
},
|
|
22
23
|
"base-sepolia": {
|
|
23
24
|
listTokenBalances: true,
|
|
@@ -29,6 +30,7 @@ export const NETWORK_CAPABILITIES = {
|
|
|
29
30
|
sendTransaction: true,
|
|
30
31
|
quoteSwap: false,
|
|
31
32
|
swap: false,
|
|
33
|
+
useSpendPermission: true,
|
|
32
34
|
},
|
|
33
35
|
ethereum: {
|
|
34
36
|
listTokenBalances: true,
|
|
@@ -40,6 +42,7 @@ export const NETWORK_CAPABILITIES = {
|
|
|
40
42
|
sendTransaction: true,
|
|
41
43
|
quoteSwap: true,
|
|
42
44
|
swap: true,
|
|
45
|
+
useSpendPermission: true,
|
|
43
46
|
},
|
|
44
47
|
"ethereum-sepolia": {
|
|
45
48
|
listTokenBalances: false,
|
|
@@ -51,6 +54,7 @@ export const NETWORK_CAPABILITIES = {
|
|
|
51
54
|
sendTransaction: true,
|
|
52
55
|
quoteSwap: false,
|
|
53
56
|
swap: false,
|
|
57
|
+
useSpendPermission: true,
|
|
54
58
|
},
|
|
55
59
|
"ethereum-hoodi": {
|
|
56
60
|
listTokenBalances: false,
|
|
@@ -62,6 +66,103 @@ export const NETWORK_CAPABILITIES = {
|
|
|
62
66
|
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
63
67
|
quoteSwap: false,
|
|
64
68
|
swap: false,
|
|
69
|
+
useSpendPermission: false,
|
|
70
|
+
},
|
|
71
|
+
optimism: {
|
|
72
|
+
listTokenBalances: false,
|
|
73
|
+
requestFaucet: false,
|
|
74
|
+
quoteFund: false,
|
|
75
|
+
fund: false,
|
|
76
|
+
waitForFundOperationReceipt: false,
|
|
77
|
+
transfer: false,
|
|
78
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
79
|
+
quoteSwap: false,
|
|
80
|
+
swap: false,
|
|
81
|
+
useSpendPermission: true,
|
|
82
|
+
},
|
|
83
|
+
"optimism-sepolia": {
|
|
84
|
+
listTokenBalances: false,
|
|
85
|
+
requestFaucet: true,
|
|
86
|
+
quoteFund: false,
|
|
87
|
+
fund: false,
|
|
88
|
+
waitForFundOperationReceipt: false,
|
|
89
|
+
transfer: false,
|
|
90
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
91
|
+
quoteSwap: false,
|
|
92
|
+
swap: false,
|
|
93
|
+
useSpendPermission: true,
|
|
94
|
+
},
|
|
95
|
+
arbitrum: {
|
|
96
|
+
listTokenBalances: false,
|
|
97
|
+
requestFaucet: true,
|
|
98
|
+
quoteFund: false,
|
|
99
|
+
fund: false,
|
|
100
|
+
waitForFundOperationReceipt: false,
|
|
101
|
+
transfer: false,
|
|
102
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
103
|
+
quoteSwap: false,
|
|
104
|
+
swap: false,
|
|
105
|
+
useSpendPermission: true,
|
|
106
|
+
},
|
|
107
|
+
"arbitrum-sepolia": {
|
|
108
|
+
listTokenBalances: false,
|
|
109
|
+
requestFaucet: true,
|
|
110
|
+
quoteFund: false,
|
|
111
|
+
fund: false,
|
|
112
|
+
waitForFundOperationReceipt: false,
|
|
113
|
+
transfer: false,
|
|
114
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
115
|
+
quoteSwap: false,
|
|
116
|
+
swap: false,
|
|
117
|
+
useSpendPermission: true,
|
|
118
|
+
},
|
|
119
|
+
avalanche: {
|
|
120
|
+
listTokenBalances: false,
|
|
121
|
+
requestFaucet: false,
|
|
122
|
+
quoteFund: false,
|
|
123
|
+
fund: false,
|
|
124
|
+
waitForFundOperationReceipt: false,
|
|
125
|
+
transfer: false,
|
|
126
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
127
|
+
quoteSwap: false,
|
|
128
|
+
swap: false,
|
|
129
|
+
useSpendPermission: true,
|
|
130
|
+
},
|
|
131
|
+
binance: {
|
|
132
|
+
listTokenBalances: false,
|
|
133
|
+
requestFaucet: false,
|
|
134
|
+
quoteFund: false,
|
|
135
|
+
fund: false,
|
|
136
|
+
waitForFundOperationReceipt: false,
|
|
137
|
+
transfer: false,
|
|
138
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
139
|
+
quoteSwap: false,
|
|
140
|
+
swap: false,
|
|
141
|
+
useSpendPermission: true,
|
|
142
|
+
},
|
|
143
|
+
polygon: {
|
|
144
|
+
listTokenBalances: false,
|
|
145
|
+
requestFaucet: false,
|
|
146
|
+
quoteFund: false,
|
|
147
|
+
fund: false,
|
|
148
|
+
waitForFundOperationReceipt: false,
|
|
149
|
+
transfer: false,
|
|
150
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
151
|
+
quoteSwap: false,
|
|
152
|
+
swap: false,
|
|
153
|
+
useSpendPermission: true,
|
|
154
|
+
},
|
|
155
|
+
zora: {
|
|
156
|
+
listTokenBalances: false,
|
|
157
|
+
requestFaucet: false,
|
|
158
|
+
quoteFund: false,
|
|
159
|
+
fund: false,
|
|
160
|
+
waitForFundOperationReceipt: false,
|
|
161
|
+
transfer: false,
|
|
162
|
+
sendTransaction: true, // Always available (uses wallet client for non-base networks)
|
|
163
|
+
quoteSwap: false,
|
|
164
|
+
swap: false,
|
|
165
|
+
useSpendPermission: true,
|
|
65
166
|
},
|
|
66
167
|
} as const;
|
|
67
168
|
|
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
type RequestFaucetResult,
|
|
22
22
|
} from "../../actions/evm/requestFaucet.js";
|
|
23
23
|
import { sendTransaction } from "../../actions/evm/sendTransaction.js";
|
|
24
|
+
import { useSpendPermission } from "../../actions/evm/spend-permissions/account.use.js";
|
|
25
|
+
import { UseSpendPermissionOptions } from "../../actions/evm/spend-permissions/types.js";
|
|
24
26
|
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
25
27
|
import { sendSwapTransaction } from "../../actions/evm/swap/sendSwapTransaction.js";
|
|
26
28
|
import { accountTransferStrategy } from "../../actions/evm/transfer/accountTransferStrategy.js";
|
|
@@ -256,6 +258,19 @@ export function toEvmServerAccount(
|
|
|
256
258
|
taker: this.address, // Always use account's address as taker
|
|
257
259
|
});
|
|
258
260
|
},
|
|
261
|
+
async __experimental_useSpendPermission(
|
|
262
|
+
options: UseSpendPermissionOptions,
|
|
263
|
+
): Promise<TransactionResult> {
|
|
264
|
+
Analytics.trackAction({
|
|
265
|
+
action: "use_spend_permission",
|
|
266
|
+
accountType: "evm_server",
|
|
267
|
+
properties: {
|
|
268
|
+
network: options.network,
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
return useSpendPermission(apiClient, this.address, options);
|
|
273
|
+
},
|
|
259
274
|
name: options.account.name,
|
|
260
275
|
type: "evm-server",
|
|
261
276
|
policies: options.account.policies,
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
sendUserOperation,
|
|
20
20
|
} from "../../actions/evm/sendUserOperation.js";
|
|
21
21
|
import { signAndWrapTypedDataForSmartAccount } from "../../actions/evm/signAndWrapTypedDataForSmartAccount.js";
|
|
22
|
+
import { useSpendPermission } from "../../actions/evm/spend-permissions/smartAccount.use.js";
|
|
23
|
+
import { UseSpendPermissionOptions } from "../../actions/evm/spend-permissions/types.js";
|
|
22
24
|
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
23
25
|
import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
|
|
24
26
|
import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
|
|
@@ -41,6 +43,10 @@ import {
|
|
|
41
43
|
SignTypedDataOptions,
|
|
42
44
|
UserOperation,
|
|
43
45
|
} from "../../client/evm/evm.types.js";
|
|
46
|
+
import {
|
|
47
|
+
type CdpOpenApiClientType,
|
|
48
|
+
type EvmSmartAccount as EvmSmartAccountModel,
|
|
49
|
+
} from "../../openapi-client/index.js";
|
|
44
50
|
|
|
45
51
|
import type { EvmAccount, EvmSmartAccount, KnownEvmNetworks } from "./types.js";
|
|
46
52
|
import type {
|
|
@@ -49,10 +55,6 @@ import type {
|
|
|
49
55
|
SmartAccountSwapOptions,
|
|
50
56
|
SmartAccountSwapResult,
|
|
51
57
|
} from "../../actions/evm/swap/types.js";
|
|
52
|
-
import type {
|
|
53
|
-
CdpOpenApiClientType,
|
|
54
|
-
EvmSmartAccount as EvmSmartAccountModel,
|
|
55
|
-
} from "../../openapi-client/index.js";
|
|
56
58
|
import type { Address, Hex } from "../../types/misc.js";
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -258,6 +260,19 @@ export function toEvmSmartAccount(
|
|
|
258
260
|
});
|
|
259
261
|
return result.signature;
|
|
260
262
|
},
|
|
263
|
+
async __experimental_useSpendPermission(
|
|
264
|
+
options: UseSpendPermissionOptions,
|
|
265
|
+
): Promise<SendUserOperationReturnType> {
|
|
266
|
+
Analytics.trackAction({
|
|
267
|
+
action: "use_spend_permission",
|
|
268
|
+
accountType: "evm_smart",
|
|
269
|
+
properties: {
|
|
270
|
+
network: options.network,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
return useSpendPermission(apiClient, account, options);
|
|
275
|
+
},
|
|
261
276
|
|
|
262
277
|
name: options.smartAccount.name,
|
|
263
278
|
type: "evm-smart",
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
SendTransactionOptions,
|
|
17
17
|
TransactionResult,
|
|
18
18
|
} from "../../actions/evm/sendTransaction.js";
|
|
19
|
+
import type { UseSpendPermissionOptions } from "../../actions/evm/spend-permissions/types.js";
|
|
19
20
|
import type { AccountQuoteSwapOptions, AccountSwapOptions } from "../../actions/evm/swap/types.js";
|
|
20
21
|
import type { TransferOptions } from "../../actions/evm/transfer/types.js";
|
|
21
22
|
import type { WaitForFundOperationOptions } from "../../actions/waitForFundOperationReceipt.js";
|
|
@@ -23,6 +24,7 @@ import type {
|
|
|
23
24
|
ListEvmTokenBalancesNetwork,
|
|
24
25
|
SendEvmTransactionBodyNetwork,
|
|
25
26
|
} from "../../openapi-client/index.js";
|
|
27
|
+
import type { SpendPermissionNetworks } from "../../spend-permissions/types.js";
|
|
26
28
|
import type { Address, TransactionRequestEIP1559 } from "../../types/misc.js";
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -193,5 +195,18 @@ export async function toNetworkScopedEvmServerAccount<Network extends string>(
|
|
|
193
195
|
});
|
|
194
196
|
}
|
|
195
197
|
|
|
198
|
+
if (isMethodSupportedOnNetwork("useSpendPermission", resolvedNetworkName)) {
|
|
199
|
+
Object.assign(account, {
|
|
200
|
+
__experimental_useSpendPermission: async (
|
|
201
|
+
spendPermissionOptions: Omit<UseSpendPermissionOptions, "network">,
|
|
202
|
+
) => {
|
|
203
|
+
return options.account.__experimental_useSpendPermission({
|
|
204
|
+
...spendPermissionOptions,
|
|
205
|
+
network: options.network as SpendPermissionNetworks,
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
196
211
|
return account;
|
|
197
212
|
}
|
|
@@ -6,6 +6,7 @@ import { getUserOperation } from "../../actions/evm/getUserOperation.js";
|
|
|
6
6
|
import { listTokenBalances } from "../../actions/evm/listTokenBalances.js";
|
|
7
7
|
import { requestFaucet } from "../../actions/evm/requestFaucet.js";
|
|
8
8
|
import { sendUserOperation } from "../../actions/evm/sendUserOperation.js";
|
|
9
|
+
import { UseSpendPermissionOptions } from "../../actions/evm/spend-permissions/types.js";
|
|
9
10
|
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
10
11
|
import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
|
|
11
12
|
import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
|
|
@@ -39,6 +40,7 @@ import type {
|
|
|
39
40
|
EvmUserOperationNetwork,
|
|
40
41
|
ListEvmTokenBalancesNetwork,
|
|
41
42
|
} from "../../openapi-client/index.js";
|
|
43
|
+
import type { SpendPermissionNetworks } from "../../spend-permissions/types.js";
|
|
42
44
|
|
|
43
45
|
/**
|
|
44
46
|
* Options for converting a pre-existing EvmSmartAccount and owner to a NetworkScopedEvmSmartAccount
|
|
@@ -279,5 +281,18 @@ export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNet
|
|
|
279
281
|
});
|
|
280
282
|
}
|
|
281
283
|
|
|
284
|
+
if (isMethodSupportedOnNetwork("useSpendPermission", options.network)) {
|
|
285
|
+
Object.assign(account, {
|
|
286
|
+
__experimental_useSpendPermission: async (
|
|
287
|
+
spendPermissionOptions: Omit<UseSpendPermissionOptions, "network">,
|
|
288
|
+
) => {
|
|
289
|
+
return options.smartAccount.__experimental_useSpendPermission({
|
|
290
|
+
...spendPermissionOptions,
|
|
291
|
+
network: options.network as SpendPermissionNetworks,
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
282
297
|
return account;
|
|
283
298
|
}
|
package/accounts/evm/types.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
SendUserOperationOptions,
|
|
20
20
|
SendUserOperationReturnType,
|
|
21
21
|
} from "../../actions/evm/sendUserOperation.js";
|
|
22
|
+
import { UseSpendPermissionOptions } from "../../actions/evm/spend-permissions/types.js";
|
|
22
23
|
import {
|
|
23
24
|
AccountQuoteSwapOptions,
|
|
24
25
|
AccountQuoteSwapResult,
|
|
@@ -39,6 +40,7 @@ import {
|
|
|
39
40
|
WaitForFundOperationResult,
|
|
40
41
|
} from "../../actions/waitForFundOperationReceipt.js";
|
|
41
42
|
import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
|
|
43
|
+
import { SpendPermissionNetworks } from "../../spend-permissions/types.js";
|
|
42
44
|
|
|
43
45
|
import type {
|
|
44
46
|
SmartAccountTransferOptions,
|
|
@@ -242,6 +244,14 @@ export type NetworkSpecificSmartAccountActions<Network extends string> = Prettif
|
|
|
242
244
|
options: DistributedOmit<SmartAccountSwapOptions, "network">,
|
|
243
245
|
) => Promise<SmartAccountSwapResult>;
|
|
244
246
|
}
|
|
247
|
+
: EmptyObject) &
|
|
248
|
+
// Conditionally include useSpendPermission
|
|
249
|
+
(Network extends SpendPermissionNetworks
|
|
250
|
+
? {
|
|
251
|
+
__experimental_useSpendPermission: (
|
|
252
|
+
options: Omit<UseSpendPermissionOptions, "network">,
|
|
253
|
+
) => Promise<SendUserOperationReturnType>;
|
|
254
|
+
}
|
|
245
255
|
: EmptyObject)
|
|
246
256
|
>;
|
|
247
257
|
|
|
@@ -322,6 +332,14 @@ export type NetworkSpecificAccountActions<Network extends string> = Prettify<
|
|
|
322
332
|
? {
|
|
323
333
|
swap: (options: AccountSwapOptions) => Promise<AccountSwapResult>;
|
|
324
334
|
}
|
|
335
|
+
: EmptyObject) &
|
|
336
|
+
// Conditionally include useSpendPermission
|
|
337
|
+
(Network extends SpendPermissionNetworks
|
|
338
|
+
? {
|
|
339
|
+
__experimental_useSpendPermission: (
|
|
340
|
+
options: Omit<UseSpendPermissionOptions, "network">,
|
|
341
|
+
) => Promise<TransactionResult>;
|
|
342
|
+
}
|
|
325
343
|
: EmptyObject)
|
|
326
344
|
>;
|
|
327
345
|
|
|
@@ -3,8 +3,9 @@ import { SolanaQuote } from "../../actions/Quote.js";
|
|
|
3
3
|
import { SolanaFundOptions, fund } from "../../actions/solana/fund/fund.js";
|
|
4
4
|
import { SolanaQuoteFundOptions, quoteFund } from "../../actions/solana/fund/quoteFund.js";
|
|
5
5
|
import { requestFaucet } from "../../actions/solana/requestFaucet.js";
|
|
6
|
+
import { sendTransaction, SendTransactionResult } from "../../actions/solana/sendTransaction.js";
|
|
6
7
|
import { signMessage } from "../../actions/solana/signMessage.js";
|
|
7
|
-
import { signTransaction } from "../../actions/solana/signTransaction.js";
|
|
8
|
+
import { signTransaction, SignTransactionResult } from "../../actions/solana/signTransaction.js";
|
|
8
9
|
import { transfer, type TransferOptions } from "../../actions/solana/transfer.js";
|
|
9
10
|
import { FundOperationResult } from "../../actions/types.js";
|
|
10
11
|
import {
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
import { Analytics } from "../../analytics.js";
|
|
16
17
|
import {
|
|
17
18
|
RequestFaucetOptions,
|
|
19
|
+
SendTransactionOptions,
|
|
18
20
|
SignatureResult,
|
|
19
21
|
SignMessageOptions,
|
|
20
22
|
SignTransactionOptions,
|
|
@@ -44,6 +46,7 @@ export function toSolanaAccount(
|
|
|
44
46
|
const account: SolanaAccount = {
|
|
45
47
|
address: options.account.address,
|
|
46
48
|
name: options.account.name,
|
|
49
|
+
policies: options.account.policies,
|
|
47
50
|
async requestFaucet(options: Omit<RequestFaucetOptions, "address">): Promise<SignatureResult> {
|
|
48
51
|
Analytics.trackAction({
|
|
49
52
|
action: "request_faucet",
|
|
@@ -68,7 +71,7 @@ export function toSolanaAccount(
|
|
|
68
71
|
},
|
|
69
72
|
async signTransaction(
|
|
70
73
|
options: Omit<SignTransactionOptions, "address">,
|
|
71
|
-
): Promise<
|
|
74
|
+
): Promise<SignTransactionResult> {
|
|
72
75
|
Analytics.trackAction({
|
|
73
76
|
action: "sign_transaction",
|
|
74
77
|
accountType: "solana",
|
|
@@ -79,7 +82,18 @@ export function toSolanaAccount(
|
|
|
79
82
|
address: account.address,
|
|
80
83
|
});
|
|
81
84
|
},
|
|
82
|
-
|
|
85
|
+
async sendTransaction(
|
|
86
|
+
options: Omit<SendTransactionOptions, "address">,
|
|
87
|
+
): Promise<SendTransactionResult> {
|
|
88
|
+
Analytics.trackAction({
|
|
89
|
+
action: "send_transaction",
|
|
90
|
+
accountType: "solana",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return sendTransaction(apiClient, {
|
|
94
|
+
...options,
|
|
95
|
+
});
|
|
96
|
+
},
|
|
83
97
|
async transfer(options: Omit<TransferOptions, "from">): Promise<SignatureResult> {
|
|
84
98
|
Analytics.trackAction({
|
|
85
99
|
action: "transfer",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SPEND_PERMISSION_MANAGER_ABI,
|
|
5
|
+
SPEND_PERMISSION_MANAGER_ADDRESS,
|
|
6
|
+
} from "../../../spend-permissions/constants.js";
|
|
7
|
+
import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
|
|
8
|
+
|
|
9
|
+
import type { UseSpendPermissionOptions } from "./types.js";
|
|
10
|
+
import type {
|
|
11
|
+
CdpOpenApiClientType,
|
|
12
|
+
SendEvmTransactionBodyNetwork,
|
|
13
|
+
} from "../../../openapi-client/index.js";
|
|
14
|
+
import type { Address, Hex } from "../../../types/misc.js";
|
|
15
|
+
import type { TransactionResult } from "../sendTransaction.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Use a spend permission to spend tokens.
|
|
19
|
+
*
|
|
20
|
+
* @param apiClient - The API client to use.
|
|
21
|
+
* @param address - The address of the account to use the spend permission on.
|
|
22
|
+
* @param options - The options for the spend permission.
|
|
23
|
+
*
|
|
24
|
+
* @returns The transaction hash of the spend permission.
|
|
25
|
+
*/
|
|
26
|
+
export async function useSpendPermission(
|
|
27
|
+
apiClient: CdpOpenApiClientType,
|
|
28
|
+
address: Address,
|
|
29
|
+
options: UseSpendPermissionOptions,
|
|
30
|
+
): Promise<TransactionResult> {
|
|
31
|
+
const { spendPermission, value, network } = options;
|
|
32
|
+
|
|
33
|
+
const result = await apiClient.sendEvmTransaction(address, {
|
|
34
|
+
transaction: serializeEIP1559Transaction({
|
|
35
|
+
to: SPEND_PERMISSION_MANAGER_ADDRESS,
|
|
36
|
+
data: encodeFunctionData({
|
|
37
|
+
abi: SPEND_PERMISSION_MANAGER_ABI,
|
|
38
|
+
functionName: "spend",
|
|
39
|
+
args: [spendPermission, value],
|
|
40
|
+
}),
|
|
41
|
+
}),
|
|
42
|
+
network: network as SendEvmTransactionBodyNetwork,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
transactionHash: result.transactionHash as Hex,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { encodeFunctionData } from "viem";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
SPEND_PERMISSION_MANAGER_ABI,
|
|
5
|
+
SPEND_PERMISSION_MANAGER_ADDRESS,
|
|
6
|
+
} from "../../../spend-permissions/constants.js";
|
|
7
|
+
import { type SendUserOperationReturnType, sendUserOperation } from "../sendUserOperation.js";
|
|
8
|
+
|
|
9
|
+
import type { UseSpendPermissionOptions } from "./types.js";
|
|
10
|
+
import type { EvmSmartAccount } from "../../../accounts/evm/types.js";
|
|
11
|
+
import type {
|
|
12
|
+
CdpOpenApiClientType,
|
|
13
|
+
EvmUserOperationNetwork,
|
|
14
|
+
} from "../../../openapi-client/index.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Use a spend permission to spend tokens.
|
|
18
|
+
*
|
|
19
|
+
* @param apiClient - The API client to use.
|
|
20
|
+
* @param account - The smart account to use.
|
|
21
|
+
* @param options - The options for the spend permission.
|
|
22
|
+
*
|
|
23
|
+
* @returns The result of the spend permission.
|
|
24
|
+
*/
|
|
25
|
+
export function useSpendPermission(
|
|
26
|
+
apiClient: CdpOpenApiClientType,
|
|
27
|
+
account: EvmSmartAccount,
|
|
28
|
+
options: UseSpendPermissionOptions,
|
|
29
|
+
): Promise<SendUserOperationReturnType> {
|
|
30
|
+
const { spendPermission, value, network } = options;
|
|
31
|
+
|
|
32
|
+
const data = encodeFunctionData({
|
|
33
|
+
abi: SPEND_PERMISSION_MANAGER_ABI,
|
|
34
|
+
functionName: "spend",
|
|
35
|
+
args: [spendPermission, value],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return sendUserOperation(apiClient, {
|
|
39
|
+
smartAccount: account,
|
|
40
|
+
network: network as EvmUserOperationNetwork,
|
|
41
|
+
calls: [
|
|
42
|
+
{
|
|
43
|
+
to: SPEND_PERMISSION_MANAGER_ADDRESS,
|
|
44
|
+
data,
|
|
45
|
+
value: 0n,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SpendPermission, SpendPermissionNetworks } from "../../../spend-permissions/types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for using a spend permission
|
|
5
|
+
*/
|
|
6
|
+
export type UseSpendPermissionOptions = {
|
|
7
|
+
/** The spend permission to use */
|
|
8
|
+
spendPermission: SpendPermission;
|
|
9
|
+
/** The amount to spend (must be <= allowance) */
|
|
10
|
+
value: bigint;
|
|
11
|
+
/** The network to execute the transaction on */
|
|
12
|
+
network: SpendPermissionNetworks;
|
|
13
|
+
};
|
package/actions/evm/types.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from "../../client/evm/evm.types.js";
|
|
15
15
|
import { Hex } from "../../types/misc.js";
|
|
16
16
|
import { EvmQuote } from "../Quote.js";
|
|
17
|
+
import { UseSpendPermissionOptions } from "./spend-permissions/types.js";
|
|
17
18
|
|
|
18
19
|
import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
|
|
19
20
|
import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
|
|
@@ -353,6 +354,46 @@ export type AccountActions = Actions & {
|
|
|
353
354
|
* ```
|
|
354
355
|
*/
|
|
355
356
|
swap: (options: AccountSwapOptions) => Promise<AccountSwapResult>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
360
|
+
*
|
|
361
|
+
* Uses a spend permission to execute a transaction.
|
|
362
|
+
* This allows the account to spend tokens that have been approved via a spend permission.
|
|
363
|
+
*
|
|
364
|
+
* @param {UseSpendPermissionOptions} options - Configuration options for using the spend permission.
|
|
365
|
+
* @param {SpendPermission} options.spendPermission - The spend permission object containing authorization details.
|
|
366
|
+
* @param {bigint} options.value - The amount to spend (must not exceed the permission's allowance).
|
|
367
|
+
* @param {KnownEvmNetworks} options.network - The network to execute the transaction on.
|
|
368
|
+
*
|
|
369
|
+
* @returns A promise that resolves to the transaction result.
|
|
370
|
+
*
|
|
371
|
+
* @throws {Error} If the network doesn't support spend permissions via CDP API.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```typescript
|
|
375
|
+
* const spendPermission = {
|
|
376
|
+
* account: "0x1234...", // Smart account that owns the tokens
|
|
377
|
+
* spender: account.address, // This account that can spend
|
|
378
|
+
* token: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // ETH
|
|
379
|
+
* allowance: parseEther("0.01"),
|
|
380
|
+
* period: 86400, // 1 day
|
|
381
|
+
* start: 0,
|
|
382
|
+
* end: 281474976710655,
|
|
383
|
+
* salt: 0n,
|
|
384
|
+
* extraData: "0x",
|
|
385
|
+
* };
|
|
386
|
+
*
|
|
387
|
+
* const result = await account.__experimental_useSpendPermission({
|
|
388
|
+
* spendPermission,
|
|
389
|
+
* value: parseEther("0.001"), // Spend 0.001 ETH
|
|
390
|
+
* network: "base-sepolia",
|
|
391
|
+
* });
|
|
392
|
+
* ```
|
|
393
|
+
*/
|
|
394
|
+
__experimental_useSpendPermission: (
|
|
395
|
+
options: UseSpendPermissionOptions,
|
|
396
|
+
) => Promise<TransactionResult>;
|
|
356
397
|
};
|
|
357
398
|
|
|
358
399
|
export type SmartAccountActions = Actions & {
|
|
@@ -640,4 +681,44 @@ export type SmartAccountActions = Actions & {
|
|
|
640
681
|
signTypedData: (
|
|
641
682
|
options: Omit<SignTypedDataOptions, "address"> & { network: KnownEvmNetworks },
|
|
642
683
|
) => Promise<Hex>;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* @deprecated Experimental! This method name will change, and is subject to other breaking changes.
|
|
687
|
+
*
|
|
688
|
+
* Uses a spend permission to execute a transaction via user operation.
|
|
689
|
+
* This allows the smart account to spend tokens that have been approved via a spend permission.
|
|
690
|
+
*
|
|
691
|
+
* @param {UseSpendPermissionOptions} options - Configuration options for using the spend permission.
|
|
692
|
+
* @param {SpendPermission} options.spendPermission - The spend permission object containing authorization details.
|
|
693
|
+
* @param {bigint} options.value - The amount to spend (must not exceed the permission's allowance).
|
|
694
|
+
* @param {KnownEvmNetworks} options.network - The network to execute the transaction on.
|
|
695
|
+
*
|
|
696
|
+
* @returns A promise that resolves to the user operation result.
|
|
697
|
+
*
|
|
698
|
+
* @throws {Error} If the network doesn't support spend permissions via CDP API.
|
|
699
|
+
*
|
|
700
|
+
* @example
|
|
701
|
+
* ```typescript
|
|
702
|
+
* const spendPermission = {
|
|
703
|
+
* account: "0x1234...", // Smart account that owns the tokens
|
|
704
|
+
* spender: smartAccount.address, // This smart account that can spend
|
|
705
|
+
* token: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE", // ETH
|
|
706
|
+
* allowance: parseEther("0.01"),
|
|
707
|
+
* period: 86400, // 1 day
|
|
708
|
+
* start: 0,
|
|
709
|
+
* end: 281474976710655,
|
|
710
|
+
* salt: 0n,
|
|
711
|
+
* extraData: "0x",
|
|
712
|
+
* };
|
|
713
|
+
*
|
|
714
|
+
* const result = await smartAccount.__experimental_useSpendPermission({
|
|
715
|
+
* spendPermission,
|
|
716
|
+
* value: parseEther("0.001"), // Spend 0.001 ETH
|
|
717
|
+
* network: "base-sepolia",
|
|
718
|
+
* });
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
__experimental_useSpendPermission: (
|
|
722
|
+
options: UseSpendPermissionOptions,
|
|
723
|
+
) => Promise<SendUserOperationReturnType>;
|
|
643
724
|
};
|