@coinbase/cdp-sdk 1.28.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 +16 -0
- package/_cjs/accounts/evm/networkCapabilities.js +101 -0
- package/_cjs/accounts/evm/networkCapabilities.js.map +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +12 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +12 -1
- 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 +11 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +41 -1
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/Quote.js +106 -0
- package/_cjs/actions/Quote.js.map +1 -0
- package/_cjs/actions/evm/fund/fund.js +5 -5
- package/_cjs/actions/evm/fund/fund.js.map +1 -1
- package/_cjs/actions/evm/fund/quoteFund.js +7 -7
- package/_cjs/actions/evm/fund/quoteFund.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.map +1 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +1 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/solana/fund/fund.js +50 -0
- package/_cjs/actions/solana/fund/fund.js.map +1 -0
- package/_cjs/actions/solana/fund/quoteFund.js +47 -0
- package/_cjs/actions/solana/fund/quoteFund.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/actions/types.js +3 -0
- package/{_esm/actions/evm/fund → _cjs/actions}/types.js.map +1 -1
- package/_cjs/actions/{evm/fund/waitForFundOperationReceipt.js → waitForFundOperationReceipt.js} +2 -2
- package/_cjs/actions/waitForFundOperationReceipt.js.map +1 -0
- 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 +54 -7
- 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 +76 -4
- 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/{actions/evm/fund → spend-permissions}/types.js.map +1 -1
- 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 +12 -1
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +12 -1
- 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 +11 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +41 -1
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/Quote.js +101 -0
- package/_esm/actions/Quote.js.map +1 -0
- package/_esm/actions/evm/fund/fund.js +5 -5
- package/_esm/actions/evm/fund/fund.js.map +1 -1
- package/_esm/actions/evm/fund/quoteFund.js +7 -7
- package/_esm/actions/evm/fund/quoteFund.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.map +1 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +1 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/solana/fund/fund.js +47 -0
- package/_esm/actions/solana/fund/fund.js.map +1 -0
- package/_esm/actions/solana/fund/quoteFund.js +44 -0
- package/_esm/actions/solana/fund/quoteFund.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/actions/types.js +2 -0
- package/_esm/actions/types.js.map +1 -0
- package/_esm/actions/{evm/fund/waitForFundOperationReceipt.js → waitForFundOperationReceipt.js} +2 -2
- package/_esm/actions/waitForFundOperationReceipt.js.map +1 -0
- 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 +52 -5
- 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 +73 -3
- 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 +15 -9
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/Quote.d.ts +97 -0
- package/_types/actions/Quote.d.ts.map +1 -0
- package/_types/actions/evm/fund/fund.d.ts +3 -7
- package/_types/actions/evm/fund/fund.d.ts.map +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts +4 -7
- package/_types/actions/evm/fund/quoteFund.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/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +82 -7
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/fund/fund.d.ts +19 -0
- package/_types/actions/solana/fund/fund.d.ts.map +1 -0
- package/_types/actions/solana/fund/quoteFund.d.ts +20 -0
- package/_types/actions/solana/fund/quoteFund.d.ts.map +1 -0
- 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 +99 -3
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/types.d.ts +37 -0
- package/_types/actions/types.d.ts.map +1 -0
- package/_types/actions/{evm/fund/waitForFundOperationReceipt.d.ts → waitForFundOperationReceipt.d.ts} +2 -2
- package/_types/actions/waitForFundOperationReceipt.d.ts.map +1 -0
- 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 +356 -20
- 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 +26 -11
- package/accounts/evm/toEvmSmartAccount.ts +30 -15
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +20 -5
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +21 -6
- package/accounts/evm/types.ts +34 -12
- package/accounts/solana/toSolanaAccount.ts +58 -3
- package/actions/Quote.ts +154 -0
- package/actions/evm/fund/fund.ts +10 -14
- package/actions/evm/fund/quoteFund.ts +13 -16
- 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/transfer/accountTransferStrategy.ts +2 -0
- package/actions/evm/types.ts +88 -7
- package/actions/solana/fund/fund.ts +71 -0
- package/actions/solana/fund/quoteFund.ts +77 -0
- package/actions/solana/sendTransaction.ts +10 -2
- package/actions/solana/signTransaction.ts +10 -2
- package/actions/solana/types.ts +113 -2
- package/actions/types.ts +39 -0
- package/actions/{evm/fund/waitForFundOperationReceipt.ts → waitForFundOperationReceipt.ts} +2 -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 +400 -26
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +89 -3
- 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
- package/_cjs/actions/evm/fund/Quote.js +0 -63
- package/_cjs/actions/evm/fund/Quote.js.map +0 -1
- package/_cjs/actions/evm/fund/waitForFundOperationReceipt.js.map +0 -1
- package/_esm/actions/evm/fund/Quote.js +0 -59
- package/_esm/actions/evm/fund/Quote.js.map +0 -1
- package/_esm/actions/evm/fund/waitForFundOperationReceipt.js.map +0 -1
- package/_types/actions/evm/fund/Quote.d.ts +0 -51
- package/_types/actions/evm/fund/Quote.d.ts.map +0 -1
- package/_types/actions/evm/fund/types.d.ts +0 -16
- package/_types/actions/evm/fund/types.d.ts.map +0 -1
- package/_types/actions/evm/fund/waitForFundOperationReceipt.d.ts.map +0 -1
- package/actions/evm/fund/Quote.ts +0 -83
- package/actions/evm/fund/types.ts +0 -16
- /package/_cjs/actions/evm/{fund → spend-permissions}/types.js +0 -0
- /package/_esm/actions/evm/{fund → spend-permissions}/types.js +0 -0
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { Account, SolanaAccount } from "./types.js";
|
|
2
|
+
import { SolanaQuote } from "../../actions/Quote.js";
|
|
3
|
+
import { SolanaFundOptions, fund } from "../../actions/solana/fund/fund.js";
|
|
4
|
+
import { SolanaQuoteFundOptions, quoteFund } from "../../actions/solana/fund/quoteFund.js";
|
|
2
5
|
import { requestFaucet } from "../../actions/solana/requestFaucet.js";
|
|
6
|
+
import { sendTransaction, SendTransactionResult } from "../../actions/solana/sendTransaction.js";
|
|
3
7
|
import { signMessage } from "../../actions/solana/signMessage.js";
|
|
4
|
-
import { signTransaction } from "../../actions/solana/signTransaction.js";
|
|
8
|
+
import { signTransaction, SignTransactionResult } from "../../actions/solana/signTransaction.js";
|
|
5
9
|
import { transfer, type TransferOptions } from "../../actions/solana/transfer.js";
|
|
10
|
+
import { FundOperationResult } from "../../actions/types.js";
|
|
11
|
+
import {
|
|
12
|
+
WaitForFundOperationOptions,
|
|
13
|
+
WaitForFundOperationResult,
|
|
14
|
+
waitForFundOperationReceipt,
|
|
15
|
+
} from "../../actions/waitForFundOperationReceipt.js";
|
|
6
16
|
import { Analytics } from "../../analytics.js";
|
|
7
17
|
import {
|
|
8
18
|
RequestFaucetOptions,
|
|
19
|
+
SendTransactionOptions,
|
|
9
20
|
SignatureResult,
|
|
10
21
|
SignMessageOptions,
|
|
11
22
|
SignTransactionOptions,
|
|
@@ -35,6 +46,7 @@ export function toSolanaAccount(
|
|
|
35
46
|
const account: SolanaAccount = {
|
|
36
47
|
address: options.account.address,
|
|
37
48
|
name: options.account.name,
|
|
49
|
+
policies: options.account.policies,
|
|
38
50
|
async requestFaucet(options: Omit<RequestFaucetOptions, "address">): Promise<SignatureResult> {
|
|
39
51
|
Analytics.trackAction({
|
|
40
52
|
action: "request_faucet",
|
|
@@ -59,7 +71,7 @@ export function toSolanaAccount(
|
|
|
59
71
|
},
|
|
60
72
|
async signTransaction(
|
|
61
73
|
options: Omit<SignTransactionOptions, "address">,
|
|
62
|
-
): Promise<
|
|
74
|
+
): Promise<SignTransactionResult> {
|
|
63
75
|
Analytics.trackAction({
|
|
64
76
|
action: "sign_transaction",
|
|
65
77
|
accountType: "solana",
|
|
@@ -70,7 +82,18 @@ export function toSolanaAccount(
|
|
|
70
82
|
address: account.address,
|
|
71
83
|
});
|
|
72
84
|
},
|
|
73
|
-
|
|
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
|
+
},
|
|
74
97
|
async transfer(options: Omit<TransferOptions, "from">): Promise<SignatureResult> {
|
|
75
98
|
Analytics.trackAction({
|
|
76
99
|
action: "transfer",
|
|
@@ -85,6 +108,38 @@ export function toSolanaAccount(
|
|
|
85
108
|
from: account.address,
|
|
86
109
|
});
|
|
87
110
|
},
|
|
111
|
+
async quoteFund(options: Omit<SolanaQuoteFundOptions, "address">): Promise<SolanaQuote> {
|
|
112
|
+
Analytics.trackAction({
|
|
113
|
+
action: "quote_fund",
|
|
114
|
+
accountType: "solana",
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return quoteFund(apiClient, {
|
|
118
|
+
...options,
|
|
119
|
+
address: account.address,
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
async fund(options: Omit<SolanaFundOptions, "address">): Promise<FundOperationResult> {
|
|
123
|
+
Analytics.trackAction({
|
|
124
|
+
action: "fund",
|
|
125
|
+
accountType: "solana",
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return fund(apiClient, {
|
|
129
|
+
...options,
|
|
130
|
+
address: account.address,
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
async waitForFundOperationReceipt(
|
|
134
|
+
options: WaitForFundOperationOptions,
|
|
135
|
+
): Promise<WaitForFundOperationResult> {
|
|
136
|
+
Analytics.trackAction({
|
|
137
|
+
action: "wait_for_fund_operation_receipt",
|
|
138
|
+
accountType: "solana",
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return waitForFundOperationReceipt(apiClient, options);
|
|
142
|
+
},
|
|
88
143
|
};
|
|
89
144
|
|
|
90
145
|
return account;
|
package/actions/Quote.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { FundOperationResult } from "./types.js";
|
|
2
|
+
import { CdpOpenApiClientType } from "../openapi-client/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class representing a funding quote that can be executed.
|
|
6
|
+
*/
|
|
7
|
+
abstract class BaseQuote {
|
|
8
|
+
/** Quote for the transfer. */
|
|
9
|
+
public quoteId: string;
|
|
10
|
+
/** The amount in fiat currency. */
|
|
11
|
+
public fiatAmount: string;
|
|
12
|
+
/** The fiat currency. */
|
|
13
|
+
public fiatCurrency: string;
|
|
14
|
+
/** The amount in the token to transfer. */
|
|
15
|
+
public tokenAmount: string;
|
|
16
|
+
/** The token to transfer. */
|
|
17
|
+
public token: string;
|
|
18
|
+
/** Fees in the token to transfer. */
|
|
19
|
+
public fees: {
|
|
20
|
+
/** The type of fee. */
|
|
21
|
+
type: "exchange_fee" | "network_fee";
|
|
22
|
+
amount: string;
|
|
23
|
+
currency: string;
|
|
24
|
+
}[];
|
|
25
|
+
|
|
26
|
+
protected apiClient: CdpOpenApiClientType;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new BaseQuote instance.
|
|
30
|
+
*
|
|
31
|
+
* @param apiClient - The API client.
|
|
32
|
+
* @param quoteId - The quote ID.
|
|
33
|
+
* @param fiatAmount - The amount in fiat currency.
|
|
34
|
+
* @param fiatCurrency - The fiat currency.
|
|
35
|
+
* @param tokenAmount - The amount in the token to transfer.
|
|
36
|
+
* @param token - The token to transfer.
|
|
37
|
+
* @param fees - Fees for the transfer.
|
|
38
|
+
*/
|
|
39
|
+
constructor(
|
|
40
|
+
apiClient: CdpOpenApiClientType,
|
|
41
|
+
quoteId: string,
|
|
42
|
+
fiatAmount: string,
|
|
43
|
+
fiatCurrency: string,
|
|
44
|
+
tokenAmount: string,
|
|
45
|
+
token: string,
|
|
46
|
+
fees: {
|
|
47
|
+
type: "exchange_fee" | "network_fee";
|
|
48
|
+
amount: string;
|
|
49
|
+
currency: string;
|
|
50
|
+
}[],
|
|
51
|
+
) {
|
|
52
|
+
this.apiClient = apiClient;
|
|
53
|
+
this.quoteId = quoteId;
|
|
54
|
+
this.fiatAmount = fiatAmount;
|
|
55
|
+
this.fiatCurrency = fiatCurrency;
|
|
56
|
+
this.tokenAmount = tokenAmount;
|
|
57
|
+
this.token = token;
|
|
58
|
+
this.fees = fees;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Executes the quote to perform the actual fund transfer.
|
|
63
|
+
*
|
|
64
|
+
* @returns A promise that resolves to the result of the executed quote.
|
|
65
|
+
*/
|
|
66
|
+
async execute(): Promise<FundOperationResult> {
|
|
67
|
+
const transfer = await this.apiClient.executePaymentTransferQuote(this.quoteId);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
id: transfer.id,
|
|
71
|
+
network: transfer.target.network,
|
|
72
|
+
targetAmount: transfer.targetAmount,
|
|
73
|
+
targetCurrency: transfer.targetCurrency,
|
|
74
|
+
status: transfer.status,
|
|
75
|
+
transactionHash: transfer.transactionHash,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* A class representing an EVM funding quote that can be executed.
|
|
82
|
+
*/
|
|
83
|
+
export class EvmQuote extends BaseQuote {
|
|
84
|
+
/** Network to transfer the funds to (EVM networks). */
|
|
85
|
+
public network: "base" | "ethereum";
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new EvmQuote instance.
|
|
89
|
+
*
|
|
90
|
+
* @param apiClient - The API client.
|
|
91
|
+
* @param quoteId - The quote ID.
|
|
92
|
+
* @param network - The EVM network to transfer funds to.
|
|
93
|
+
* @param fiatAmount - The amount in fiat currency.
|
|
94
|
+
* @param fiatCurrency - The fiat currency.
|
|
95
|
+
* @param tokenAmount - The amount in the token to transfer.
|
|
96
|
+
* @param token - The token to transfer.
|
|
97
|
+
* @param fees - Fees for the transfer.
|
|
98
|
+
*/
|
|
99
|
+
constructor(
|
|
100
|
+
apiClient: CdpOpenApiClientType,
|
|
101
|
+
quoteId: string,
|
|
102
|
+
network: "base" | "ethereum",
|
|
103
|
+
fiatAmount: string,
|
|
104
|
+
fiatCurrency: string,
|
|
105
|
+
tokenAmount: string,
|
|
106
|
+
token: string,
|
|
107
|
+
fees: {
|
|
108
|
+
type: "exchange_fee" | "network_fee";
|
|
109
|
+
amount: string;
|
|
110
|
+
currency: string;
|
|
111
|
+
}[],
|
|
112
|
+
) {
|
|
113
|
+
super(apiClient, quoteId, fiatAmount, fiatCurrency, tokenAmount, token, fees);
|
|
114
|
+
this.network = network;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A class representing a Solana funding quote that can be executed.
|
|
120
|
+
*/
|
|
121
|
+
export class SolanaQuote extends BaseQuote {
|
|
122
|
+
/** Network to transfer the funds to (Solana). */
|
|
123
|
+
public network: "solana";
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Creates a new SolanaQuote instance.
|
|
127
|
+
*
|
|
128
|
+
* @param apiClient - The API client.
|
|
129
|
+
* @param quoteId - The quote ID.
|
|
130
|
+
* @param network - The Solana network to transfer funds to.
|
|
131
|
+
* @param fiatAmount - The amount in fiat currency.
|
|
132
|
+
* @param fiatCurrency - The fiat currency.
|
|
133
|
+
* @param tokenAmount - The amount in the token to transfer.
|
|
134
|
+
* @param token - The token to transfer.
|
|
135
|
+
* @param fees - Fees for the transfer.
|
|
136
|
+
*/
|
|
137
|
+
constructor(
|
|
138
|
+
apiClient: CdpOpenApiClientType,
|
|
139
|
+
quoteId: string,
|
|
140
|
+
network: "solana",
|
|
141
|
+
fiatAmount: string,
|
|
142
|
+
fiatCurrency: string,
|
|
143
|
+
tokenAmount: string,
|
|
144
|
+
token: string,
|
|
145
|
+
fees: {
|
|
146
|
+
type: "exchange_fee" | "network_fee";
|
|
147
|
+
amount: string;
|
|
148
|
+
currency: string;
|
|
149
|
+
}[],
|
|
150
|
+
) {
|
|
151
|
+
super(apiClient, quoteId, fiatAmount, fiatCurrency, tokenAmount, token, fees);
|
|
152
|
+
this.network = network;
|
|
153
|
+
}
|
|
154
|
+
}
|
package/actions/evm/fund/fund.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { formatUnits } from "viem";
|
|
2
2
|
|
|
3
|
-
import { FundOperationResult } from "./types.js";
|
|
4
3
|
import { UserInputValidationError } from "../../../errors.js";
|
|
5
4
|
import {
|
|
6
5
|
CreatePaymentTransferQuoteBodySourceType,
|
|
7
6
|
CreatePaymentTransferQuoteBodyTargetType,
|
|
8
7
|
type CdpOpenApiClientType,
|
|
9
8
|
} from "../../../openapi-client/index.js";
|
|
9
|
+
import { BaseFundOptions, FundOperationResult } from "../../types.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Options for funding an EVM account.
|
|
13
13
|
*/
|
|
14
|
-
export interface
|
|
15
|
-
/** The address of the account. */
|
|
16
|
-
address: string;
|
|
14
|
+
export interface EvmFundOptions extends BaseFundOptions {
|
|
17
15
|
/** The network to request funds from. */
|
|
18
16
|
network: "base" | "ethereum";
|
|
19
|
-
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
20
|
-
amount: bigint;
|
|
21
17
|
/** The token to request funds for. */
|
|
22
18
|
token: "eth" | "usdc";
|
|
23
19
|
}
|
|
@@ -32,8 +28,15 @@ export interface FundOptions {
|
|
|
32
28
|
*/
|
|
33
29
|
export async function fund(
|
|
34
30
|
apiClient: CdpOpenApiClientType,
|
|
35
|
-
options:
|
|
31
|
+
options: EvmFundOptions,
|
|
36
32
|
): Promise<FundOperationResult> {
|
|
33
|
+
if (options.token !== "eth" && options.token !== "usdc") {
|
|
34
|
+
throw new UserInputValidationError("Invalid token, must be eth or usdc");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const decimals = options.token === "eth" ? 18 : 6;
|
|
38
|
+
const amount = formatUnits(options.amount, decimals);
|
|
39
|
+
|
|
37
40
|
const paymentMethods = await apiClient.getPaymentMethods();
|
|
38
41
|
const cardPaymentMethod = paymentMethods.find(
|
|
39
42
|
method => method.type === "card" && method.actions.includes("source"),
|
|
@@ -43,13 +46,6 @@ export async function fund(
|
|
|
43
46
|
throw new Error("No card found to fund account");
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
if (options.token !== "eth" && options.token !== "usdc") {
|
|
47
|
-
throw new UserInputValidationError("Invalid token, must be eth or usdc");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const decimals = options.token === "eth" ? 18 : 6;
|
|
51
|
-
const amount = formatUnits(options.amount, decimals);
|
|
52
|
-
|
|
53
49
|
const response = await apiClient.createPaymentTransferQuote({
|
|
54
50
|
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
55
51
|
source: {
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import { formatUnits } from "viem";
|
|
2
2
|
|
|
3
|
-
import { Quote } from "./Quote.js";
|
|
4
3
|
import { UserInputValidationError } from "../../../errors.js";
|
|
5
4
|
import {
|
|
6
5
|
CreatePaymentTransferQuoteBodySourceType,
|
|
7
6
|
CreatePaymentTransferQuoteBodyTargetType,
|
|
8
7
|
type CdpOpenApiClientType,
|
|
9
8
|
} from "../../../openapi-client/index.js";
|
|
9
|
+
import { EvmQuote } from "../../Quote.js";
|
|
10
|
+
import { BaseQuoteFundOptions } from "../../types.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Options for getting a quote to fund an EVM account.
|
|
13
14
|
*/
|
|
14
|
-
export interface
|
|
15
|
-
/** The address of the account. */
|
|
16
|
-
address: string;
|
|
15
|
+
export interface EvmQuoteFundOptions extends BaseQuoteFundOptions {
|
|
17
16
|
/** The network to request funds from. */
|
|
18
17
|
network: "base" | "ethereum";
|
|
19
|
-
/** The amount to fund the account with, in atomic units (wei) of the token. */
|
|
20
|
-
amount: bigint;
|
|
21
18
|
/** The token to request funds for. */
|
|
22
19
|
token: "eth" | "usdc";
|
|
23
20
|
}
|
|
@@ -32,8 +29,15 @@ export interface QuoteFundOptions {
|
|
|
32
29
|
*/
|
|
33
30
|
export async function quoteFund(
|
|
34
31
|
apiClient: CdpOpenApiClientType,
|
|
35
|
-
options:
|
|
36
|
-
): Promise<
|
|
32
|
+
options: EvmQuoteFundOptions,
|
|
33
|
+
): Promise<EvmQuote> {
|
|
34
|
+
if (options.token !== "eth" && options.token !== "usdc") {
|
|
35
|
+
throw new UserInputValidationError("Invalid token, must be eth or usdc");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const decimals = options.token === "eth" ? 18 : 6;
|
|
39
|
+
const amount = formatUnits(options.amount, decimals);
|
|
40
|
+
|
|
37
41
|
const paymentMethods = await apiClient.getPaymentMethods();
|
|
38
42
|
const cardPaymentMethod = paymentMethods.find(
|
|
39
43
|
method => method.type === "card" && method.actions.includes("source"),
|
|
@@ -43,13 +47,6 @@ export async function quoteFund(
|
|
|
43
47
|
throw new Error("No card found to fund account");
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
if (options.token !== "eth" && options.token !== "usdc") {
|
|
47
|
-
throw new UserInputValidationError("Invalid token, must be eth or usdc");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const decimals = options.token === "eth" ? 18 : 6;
|
|
51
|
-
const amount = formatUnits(options.amount, decimals);
|
|
52
|
-
|
|
53
50
|
const response = await apiClient.createPaymentTransferQuote({
|
|
54
51
|
sourceType: CreatePaymentTransferQuoteBodySourceType.payment_method,
|
|
55
52
|
source: {
|
|
@@ -65,7 +62,7 @@ export async function quoteFund(
|
|
|
65
62
|
currency: options.token,
|
|
66
63
|
});
|
|
67
64
|
|
|
68
|
-
return new
|
|
65
|
+
return new EvmQuote(
|
|
69
66
|
apiClient,
|
|
70
67
|
response.transfer.id,
|
|
71
68
|
options.network,
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
2
|
|
|
3
3
|
import { getErc20Address } from "./utils.js";
|
|
4
|
+
import { SendEvmTransactionBodyNetwork } from "../../../openapi-client/index.js";
|
|
4
5
|
import { serializeEIP1559Transaction } from "../../../utils/serializeTransaction.js";
|
|
5
6
|
|
|
6
7
|
import type { TransferExecutionStrategy } from "./types.js";
|
|
@@ -9,6 +10,7 @@ import type { TransactionResult } from "../sendTransaction.js";
|
|
|
9
10
|
|
|
10
11
|
export const accountTransferStrategy: TransferExecutionStrategy<EvmAccount> = {
|
|
11
12
|
executeTransfer: async ({ apiClient, from, to, value, token, network }) => {
|
|
13
|
+
network = network as SendEvmTransactionBodyNetwork;
|
|
12
14
|
if (token === "eth") {
|
|
13
15
|
return apiClient.sendEvmTransaction(from.address, {
|
|
14
16
|
transaction: serializeEIP1559Transaction({
|
package/actions/evm/types.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Quote } from "./fund/Quote.js";
|
|
3
|
-
import { QuoteFundOptions } from "./fund/quoteFund.js";
|
|
4
|
-
import { FundOperationResult } from "./fund/types.js";
|
|
1
|
+
import { FundOperationResult } from "../types.js";
|
|
5
2
|
import {
|
|
6
3
|
WaitForFundOperationOptions,
|
|
7
4
|
WaitForFundOperationResult,
|
|
8
|
-
} from "
|
|
5
|
+
} from "../waitForFundOperationReceipt.js";
|
|
6
|
+
import { EvmFundOptions } from "./fund/fund.js";
|
|
7
|
+
import { EvmQuoteFundOptions } from "./fund/quoteFund.js";
|
|
9
8
|
import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
|
|
10
9
|
import { KnownEvmNetworks } from "../../accounts/evm/types.js";
|
|
11
10
|
import {
|
|
@@ -14,6 +13,8 @@ import {
|
|
|
14
13
|
UserOperation,
|
|
15
14
|
} from "../../client/evm/evm.types.js";
|
|
16
15
|
import { Hex } from "../../types/misc.js";
|
|
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";
|
|
@@ -95,7 +96,7 @@ export type Actions = {
|
|
|
95
96
|
* });
|
|
96
97
|
* ```
|
|
97
98
|
*/
|
|
98
|
-
quoteFund: (options: Omit<
|
|
99
|
+
quoteFund: (options: Omit<EvmQuoteFundOptions, "address">) => Promise<EvmQuote>;
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
102
|
* Funds an EVM account with the specified token amount.
|
|
@@ -118,7 +119,7 @@ export type Actions = {
|
|
|
118
119
|
* });
|
|
119
120
|
* ```
|
|
120
121
|
*/
|
|
121
|
-
fund: (options: Omit<
|
|
122
|
+
fund: (options: Omit<EvmFundOptions, "address">) => Promise<FundOperationResult>;
|
|
122
123
|
|
|
123
124
|
/**
|
|
124
125
|
* Waits for a fund operation to complete and returns the transfer receipt.
|
|
@@ -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
|
};
|