@coinbase/cdp-sdk 1.20.0 → 1.22.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 +32 -0
- package/README.md +8 -0
- package/_cjs/accounts/evm/chainToNetworkMapper.js +33 -0
- package/_cjs/accounts/evm/chainToNetworkMapper.js.map +1 -0
- package/_cjs/accounts/evm/getBaseNodeRpcUrl.js +38 -0
- package/_cjs/accounts/evm/getBaseNodeRpcUrl.js.map +1 -0
- package/_cjs/accounts/evm/networkCapabilities.js +91 -0
- package/_cjs/accounts/evm/networkCapabilities.js.map +1 -0
- package/_cjs/accounts/evm/resolveViemClients.js +2 -35
- package/_cjs/accounts/evm/resolveViemClients.js.map +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +2 -2
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +86 -32
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +126 -2
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/sendUserOperation.js +8 -1
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
- package/_cjs/actions/evm/transfer/transferWithViem.js +2 -1
- package/_cjs/actions/evm/transfer/transferWithViem.js.map +1 -1
- package/_cjs/auth/utils/hash.js +17 -0
- package/_cjs/auth/utils/hash.js.map +1 -0
- package/_cjs/auth/utils/jwt.js +20 -55
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/client/cdp.js +6 -0
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +2 -2
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/solana/solana.js +74 -0
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/constants.js +18 -1
- package/_cjs/constants.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +10 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/chainToNetworkMapper.js +30 -0
- package/_esm/accounts/evm/chainToNetworkMapper.js.map +1 -0
- package/_esm/accounts/evm/getBaseNodeRpcUrl.js +35 -0
- package/_esm/accounts/evm/getBaseNodeRpcUrl.js.map +1 -0
- package/_esm/accounts/evm/networkCapabilities.js +86 -0
- package/_esm/accounts/evm/networkCapabilities.js.map +1 -0
- package/_esm/accounts/evm/resolveViemClients.js +1 -34
- package/_esm/accounts/evm/resolveViemClients.js.map +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 +2 -2
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +87 -33
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +126 -2
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/sendUserOperation.js +8 -1
- package/_esm/actions/evm/sendUserOperation.js.map +1 -1
- package/_esm/actions/evm/transfer/transferWithViem.js +2 -1
- package/_esm/actions/evm/transfer/transferWithViem.js.map +1 -1
- package/_esm/auth/utils/hash.js +13 -0
- package/_esm/auth/utils/hash.js.map +1 -0
- package/_esm/auth/utils/jwt.js +20 -22
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/client/cdp.js +6 -0
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +2 -2
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/solana/solana.js +71 -0
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/constants.js +17 -0
- package/_esm/constants.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +8 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/chainToNetworkMapper.d.ts +11 -0
- package/_types/accounts/evm/chainToNetworkMapper.d.ts.map +1 -0
- package/_types/accounts/evm/getBaseNodeRpcUrl.d.ts +8 -0
- package/_types/accounts/evm/getBaseNodeRpcUrl.d.ts.map +1 -0
- package/_types/accounts/evm/networkCapabilities.d.ts +103 -0
- package/_types/accounts/evm/networkCapabilities.d.ts.map +1 -0
- package/_types/accounts/evm/resolveViemClients.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts +3 -3
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts +9 -6
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +109 -14
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/actions/evm/fund/fund.d.ts +1 -1
- package/_types/actions/evm/fund/fund.d.ts.map +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -1
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transferWithViem.d.ts +1 -1
- package/_types/actions/evm/transfer/transferWithViem.d.ts.map +1 -1
- package/_types/auth/utils/hash.d.ts +9 -0
- package/_types/auth/utils/hash.d.ts.map +1 -0
- package/_types/auth/utils/jwt.d.ts.map +1 -1
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +1 -1
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +40 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +15 -1
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/constants.d.ts +4 -0
- package/_types/constants.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +5 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +10 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +24 -24
- package/_types/version.d.ts +1 -1
- package/accounts/evm/chainToNetworkMapper.ts +37 -0
- package/accounts/evm/getBaseNodeRpcUrl.ts +40 -0
- package/accounts/evm/networkCapabilities.ts +117 -0
- package/accounts/evm/resolveViemClients.ts +1 -38
- package/accounts/evm/toEvmServerAccount.ts +3 -3
- package/accounts/evm/toEvmSmartAccount.ts +3 -3
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +116 -44
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +178 -11
- package/accounts/evm/types.ts +253 -25
- package/actions/evm/fund/fund.ts +1 -1
- package/actions/evm/fund/quoteFund.ts +1 -1
- package/actions/evm/sendUserOperation.ts +9 -1
- package/actions/evm/transfer/transferWithViem.ts +4 -3
- package/auth/utils/hash.ts +13 -0
- package/auth/utils/jwt.ts +21 -24
- package/client/cdp.ts +9 -0
- package/client/evm/evm.ts +2 -2
- package/client/evm/evm.types.ts +1 -1
- package/client/solana/solana.ts +89 -0
- package/client/solana/solana.types.ts +16 -0
- package/constants.ts +18 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +20 -0
- package/package.json +2 -1
- package/version.ts +1 -1
- package/_cjs/client/evm/constants.js +0 -21
- package/_cjs/client/evm/constants.js.map +0 -1
- package/_esm/client/evm/constants.js +0 -18
- package/_esm/client/evm/constants.js.map +0 -1
- package/_types/client/evm/constants.d.ts +0 -5
- package/_types/client/evm/constants.d.ts.map +0 -1
- package/client/evm/constants.ts +0 -17
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
} from "../../actions/evm/waitForUserOperation.js";
|
|
36
36
|
import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
|
|
37
37
|
|
|
38
|
-
import type { EvmAccount, EvmSmartAccount } from "./types.js";
|
|
38
|
+
import type { EvmAccount, EvmSmartAccount, KnownEvmNetworks } from "./types.js";
|
|
39
39
|
import type {
|
|
40
40
|
SmartAccountQuoteSwapOptions,
|
|
41
41
|
SmartAccountQuoteSwapResult,
|
|
@@ -156,11 +156,11 @@ export function toEvmSmartAccount(
|
|
|
156
156
|
|
|
157
157
|
name: options.smartAccount.name,
|
|
158
158
|
type: "evm-smart",
|
|
159
|
-
|
|
159
|
+
useNetwork: async <Network extends KnownEvmNetworks>(network: Network) => {
|
|
160
160
|
return toNetworkScopedEvmSmartAccount(apiClient, {
|
|
161
161
|
smartAccount: account,
|
|
162
162
|
owner: options.owner,
|
|
163
|
-
network
|
|
163
|
+
network,
|
|
164
164
|
});
|
|
165
165
|
},
|
|
166
166
|
};
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { WaitForTransactionReceiptParameters } from "viem";
|
|
2
|
-
import { base, baseSepolia, sepolia } from "viem/chains";
|
|
2
|
+
import { base, baseSepolia, mainnet, sepolia } from "viem/chains";
|
|
3
3
|
|
|
4
|
+
import { mapChainToNetwork } from "./chainToNetworkMapper.js";
|
|
5
|
+
import { isMethodSupportedOnNetwork } from "./networkCapabilities.js";
|
|
4
6
|
import { resolveViemClients } from "./resolveViemClients.js";
|
|
5
|
-
import { RequestFaucetOptions } from "../../actions/evm/requestFaucet.js";
|
|
6
|
-
import { TransactionResult } from "../../actions/evm/sendTransaction.js";
|
|
7
7
|
import { transferWithViem } from "../../actions/evm/transfer/transferWithViem.js";
|
|
8
8
|
|
|
9
9
|
import type { EvmServerAccount, NetworkScopedEvmServerAccount } from "./types.js";
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
10
|
+
import type { FundOptions } from "../../actions/evm/fund/fund.js";
|
|
11
|
+
import type { QuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
|
|
12
|
+
import type { WaitForFundOperationOptions } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
|
|
13
|
+
import type { ListTokenBalancesOptions } from "../../actions/evm/listTokenBalances.js";
|
|
14
|
+
import type { RequestFaucetOptions } from "../../actions/evm/requestFaucet.js";
|
|
15
|
+
import type {
|
|
16
|
+
SendTransactionOptions,
|
|
17
|
+
TransactionResult,
|
|
18
|
+
} from "../../actions/evm/sendTransaction.js";
|
|
19
|
+
import type { AccountQuoteSwapOptions, AccountSwapOptions } from "../../actions/evm/swap/types.js";
|
|
20
|
+
import type { TransferOptions } from "../../actions/evm/transfer/types.js";
|
|
21
|
+
import type {
|
|
22
|
+
ListEvmTokenBalancesNetwork,
|
|
23
|
+
SendEvmTransactionBodyNetwork,
|
|
24
|
+
} from "../../openapi-client/index.js";
|
|
12
25
|
import type { Address, TransactionRequestEIP1559 } from "../../types/misc.js";
|
|
13
26
|
|
|
14
27
|
/**
|
|
@@ -25,24 +38,26 @@ export type ToNetworkScopedEvmServerAccountOptions = {
|
|
|
25
38
|
* Creates a Network-scoped Server-managed EvmAccount instance from an existing EvmAccount.
|
|
26
39
|
* Use this to interact with previously deployed EvmAccounts on a specific network.
|
|
27
40
|
*
|
|
28
|
-
* @param {CdpOpenApiClientType} apiClient - The API client.
|
|
29
41
|
* @param {ToNetworkScopedEvmServerAccountOptions} options - Configuration options.
|
|
30
42
|
* @param {EvmServerAccount} options.account - The EvmServerAccount that was previously created.
|
|
31
43
|
* @param {string} options.network - The network to scope the account to.
|
|
32
44
|
* @returns {NetworkScopedEvmServerAccount} A configured NetworkScopedEvmServerAccount instance ready for signing.
|
|
33
45
|
*/
|
|
34
|
-
export async function toNetworkScopedEvmServerAccount(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
): Promise<NetworkScopedEvmServerAccount> {
|
|
46
|
+
export async function toNetworkScopedEvmServerAccount<Network extends string>(
|
|
47
|
+
options: ToNetworkScopedEvmServerAccountOptions & { network: Network },
|
|
48
|
+
): Promise<NetworkScopedEvmServerAccount<Network>> {
|
|
38
49
|
const { publicClient, walletClient, chain } = await resolveViemClients({
|
|
39
50
|
networkOrNodeUrl: options.network,
|
|
40
51
|
account: options.account,
|
|
41
52
|
});
|
|
42
53
|
|
|
43
|
-
const
|
|
54
|
+
const shouldUseApiForSends =
|
|
55
|
+
chain.id === base.id ||
|
|
56
|
+
chain.id === baseSepolia.id ||
|
|
57
|
+
chain.id === mainnet.id ||
|
|
58
|
+
chain.id === sepolia.id;
|
|
44
59
|
|
|
45
|
-
const account
|
|
60
|
+
const account = {
|
|
46
61
|
address: options.account.address as Address,
|
|
47
62
|
network: options.network,
|
|
48
63
|
signMessage: options.account.signMessage,
|
|
@@ -52,35 +67,11 @@ export async function toNetworkScopedEvmServerAccount(
|
|
|
52
67
|
name: options.account.name,
|
|
53
68
|
type: "evm-server",
|
|
54
69
|
policies: options.account.policies,
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
throw new Error(
|
|
58
|
-
"Requesting a faucet is supported only on base-sepolia or ethereum-sepolia",
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
return options.account.requestFaucet({
|
|
62
|
-
...faucetOptions,
|
|
63
|
-
network: chain.id === baseSepolia.id ? "base-sepolia" : "ethereum-sepolia",
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
transfer: async transferArgs => {
|
|
67
|
-
if (shouldUseApi) {
|
|
68
|
-
return options.account.transfer({
|
|
69
|
-
...transferArgs,
|
|
70
|
-
network: (chain.id === base.id ? "base" : "base-sepolia") as Network,
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
return transferWithViem(walletClient, account, {
|
|
74
|
-
...transferArgs,
|
|
75
|
-
network: options.network as Network,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
sendTransaction: async txOpts => {
|
|
80
|
-
if (shouldUseApi) {
|
|
70
|
+
sendTransaction: async (txOpts: Omit<SendTransactionOptions, "address" | "network">) => {
|
|
71
|
+
if (shouldUseApiForSends) {
|
|
81
72
|
return options.account.sendTransaction({
|
|
82
73
|
...txOpts,
|
|
83
|
-
network: chain
|
|
74
|
+
network: mapChainToNetwork(chain) as SendEvmTransactionBodyNetwork,
|
|
84
75
|
});
|
|
85
76
|
} else {
|
|
86
77
|
const hash = await walletClient.sendTransaction(
|
|
@@ -89,17 +80,98 @@ export async function toNetworkScopedEvmServerAccount(
|
|
|
89
80
|
return { transactionHash: hash };
|
|
90
81
|
}
|
|
91
82
|
},
|
|
83
|
+
transfer: async (transferArgs: Omit<TransferOptions, "address" | "network">) => {
|
|
84
|
+
if (shouldUseApiForSends) {
|
|
85
|
+
return options.account.transfer({
|
|
86
|
+
...transferArgs,
|
|
87
|
+
network: mapChainToNetwork(chain) as SendEvmTransactionBodyNetwork,
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
return transferWithViem(walletClient, account, transferArgs);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
92
93
|
waitForTransactionReceipt: async (
|
|
93
|
-
|
|
94
|
+
waitOptions: WaitForTransactionReceiptParameters | TransactionResult,
|
|
94
95
|
) => {
|
|
95
|
-
if ("transactionHash" in
|
|
96
|
+
if ("transactionHash" in waitOptions) {
|
|
96
97
|
return publicClient.waitForTransactionReceipt({
|
|
97
|
-
hash:
|
|
98
|
+
hash: waitOptions.transactionHash,
|
|
98
99
|
});
|
|
99
100
|
}
|
|
100
|
-
return publicClient.waitForTransactionReceipt(
|
|
101
|
+
return publicClient.waitForTransactionReceipt(waitOptions);
|
|
101
102
|
},
|
|
102
|
-
}
|
|
103
|
+
} as NetworkScopedEvmServerAccount<Network>;
|
|
104
|
+
|
|
105
|
+
if (isMethodSupportedOnNetwork("listTokenBalances", options.network)) {
|
|
106
|
+
Object.assign(account, {
|
|
107
|
+
listTokenBalances: async (
|
|
108
|
+
listTokenBalancesOptions: Omit<ListTokenBalancesOptions, "address" | "network">,
|
|
109
|
+
) => {
|
|
110
|
+
return options.account.listTokenBalances({
|
|
111
|
+
...listTokenBalancesOptions,
|
|
112
|
+
network: options.network as ListEvmTokenBalancesNetwork,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (isMethodSupportedOnNetwork("requestFaucet", options.network)) {
|
|
119
|
+
Object.assign(account, {
|
|
120
|
+
requestFaucet: async (faucetOptions: Omit<RequestFaucetOptions, "address" | "network">) => {
|
|
121
|
+
return options.account.requestFaucet({
|
|
122
|
+
...faucetOptions,
|
|
123
|
+
network: chain.id === baseSepolia.id ? "base-sepolia" : "ethereum-sepolia",
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (isMethodSupportedOnNetwork("quoteFund", options.network)) {
|
|
130
|
+
Object.assign(account, {
|
|
131
|
+
quoteFund: async (quoteFundOptions: Omit<QuoteFundOptions, "address">) => {
|
|
132
|
+
return options.account.quoteFund({
|
|
133
|
+
...quoteFundOptions,
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (isMethodSupportedOnNetwork("fund", options.network)) {
|
|
140
|
+
Object.assign(account, {
|
|
141
|
+
fund: async (fundOptions: Omit<FundOptions, "address">) => {
|
|
142
|
+
return options.account.fund({
|
|
143
|
+
...fundOptions,
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
waitForFundOperationReceipt: async (waitOptions: WaitForFundOperationOptions) => {
|
|
147
|
+
return options.account.waitForFundOperationReceipt(waitOptions);
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (isMethodSupportedOnNetwork("transfer", options.network)) {
|
|
153
|
+
Object.assign(account, {
|
|
154
|
+
transfer: async (transferOptions: TransferOptions) => {
|
|
155
|
+
return options.account.transfer(transferOptions);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (isMethodSupportedOnNetwork("quoteSwap", options.network)) {
|
|
161
|
+
Object.assign(account, {
|
|
162
|
+
quoteSwap: async (quoteSwapOptions: AccountQuoteSwapOptions) => {
|
|
163
|
+
return options.account.quoteSwap(quoteSwapOptions);
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (isMethodSupportedOnNetwork("swap", options.network)) {
|
|
169
|
+
Object.assign(account, {
|
|
170
|
+
swap: async (swapOptions: AccountSwapOptions) => {
|
|
171
|
+
return options.account.swap(swapOptions);
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
}
|
|
103
175
|
|
|
104
176
|
return account;
|
|
105
177
|
}
|
|
@@ -1,14 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { getBaseNodeRpcUrl } from "./getBaseNodeRpcUrl.js";
|
|
2
|
+
import { isMethodSupportedOnNetwork } from "./networkCapabilities.js";
|
|
3
|
+
import { fund } from "../../actions/evm/fund/fund.js";
|
|
4
|
+
import { quoteFund } from "../../actions/evm/fund/quoteFund.js";
|
|
5
|
+
import { waitForFundOperationReceipt } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
|
|
6
|
+
import { getUserOperation } from "../../actions/evm/getUserOperation.js";
|
|
7
|
+
import { listTokenBalances } from "../../actions/evm/listTokenBalances.js";
|
|
8
|
+
import { requestFaucet } from "../../actions/evm/requestFaucet.js";
|
|
9
|
+
import { sendUserOperation } from "../../actions/evm/sendUserOperation.js";
|
|
10
|
+
import { createSwapQuote } from "../../actions/evm/swap/createSwapQuote.js";
|
|
11
|
+
import { sendSwapOperation } from "../../actions/evm/swap/sendSwapOperation.js";
|
|
12
|
+
import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
|
|
13
|
+
import { transfer } from "../../actions/evm/transfer/transfer.js";
|
|
14
|
+
import { waitForUserOperation } from "../../actions/evm/waitForUserOperation.js";
|
|
15
|
+
|
|
16
|
+
import type {
|
|
17
|
+
EvmAccount,
|
|
18
|
+
EvmSmartAccount,
|
|
19
|
+
KnownEvmNetworks,
|
|
20
|
+
NetworkScopedEvmSmartAccount,
|
|
21
|
+
} from "./types.js";
|
|
22
|
+
import type { FundOptions } from "../../actions/evm/fund/fund.js";
|
|
23
|
+
import type { QuoteFundOptions } from "../../actions/evm/fund/quoteFund.js";
|
|
24
|
+
import type { WaitForFundOperationOptions } from "../../actions/evm/fund/waitForFundOperationReceipt.js";
|
|
25
|
+
import type { ListTokenBalancesOptions } from "../../actions/evm/listTokenBalances.js";
|
|
26
|
+
import type { RequestFaucetOptions } from "../../actions/evm/requestFaucet.js";
|
|
27
|
+
import type { SendUserOperationOptions } from "../../actions/evm/sendUserOperation.js";
|
|
28
|
+
import type {
|
|
29
|
+
SmartAccountQuoteSwapOptions,
|
|
30
|
+
SmartAccountSwapNetwork,
|
|
31
|
+
SmartAccountSwapOptions,
|
|
32
|
+
} from "../../actions/evm/swap/types.js";
|
|
33
|
+
import type { SmartAccountTransferOptions } from "../../actions/evm/transfer/types.js";
|
|
34
|
+
import type { WaitForUserOperationOptions } from "../../actions/evm/waitForUserOperation.js";
|
|
35
|
+
import type { GetUserOperationOptions } from "../../client/evm/evm.types.js";
|
|
36
|
+
import type {
|
|
37
|
+
CdpOpenApiClientType,
|
|
38
|
+
EvmUserOperationNetwork,
|
|
39
|
+
ListEvmTokenBalancesNetwork,
|
|
40
|
+
} from "../../openapi-client/index.js";
|
|
3
41
|
|
|
4
42
|
/**
|
|
5
|
-
* Options for converting a pre-existing EvmSmartAccount and owner to a
|
|
43
|
+
* Options for converting a pre-existing EvmSmartAccount and owner to a NetworkScopedEvmSmartAccount
|
|
6
44
|
*/
|
|
7
|
-
export type
|
|
45
|
+
export type ToNetworkScopedEvmSmartAccountOptions = {
|
|
8
46
|
/** The pre-existing EvmSmartAccount. */
|
|
9
47
|
smartAccount: EvmSmartAccount;
|
|
10
48
|
/** The network to scope the smart account object to. */
|
|
11
|
-
network:
|
|
49
|
+
network: KnownEvmNetworks;
|
|
12
50
|
/** The owner of the smart account. */
|
|
13
51
|
owner: EvmAccount;
|
|
14
52
|
};
|
|
@@ -20,22 +58,151 @@ export type ToEvmSmartAccountOptions = {
|
|
|
20
58
|
* The owner must be the original owner of the evm smart account.
|
|
21
59
|
*
|
|
22
60
|
* @param {CdpOpenApiClientType} apiClient - The API client.
|
|
23
|
-
* @param {
|
|
61
|
+
* @param {ToNetworkScopedEvmSmartAccountOptions} options - Configuration options.
|
|
24
62
|
* @param {EvmSmartAccount} options.smartAccount - The deployed evm smart account.
|
|
25
63
|
* @param {EvmAccount} options.owner - The owner which signs for the smart account.
|
|
64
|
+
* @param {KnownEvmNetworks} options.network - The network to scope the smart account to.
|
|
26
65
|
* @returns {NetworkScopedEvmSmartAccount} A configured NetworkScopedEvmSmartAccount instance ready for user operation submission.
|
|
27
66
|
*/
|
|
28
|
-
export function toNetworkScopedEvmSmartAccount(
|
|
67
|
+
export async function toNetworkScopedEvmSmartAccount<Network extends KnownEvmNetworks>(
|
|
29
68
|
apiClient: CdpOpenApiClientType,
|
|
30
|
-
options:
|
|
31
|
-
): NetworkScopedEvmSmartAccount {
|
|
32
|
-
const
|
|
69
|
+
options: ToNetworkScopedEvmSmartAccountOptions & { network: Network },
|
|
70
|
+
): Promise<NetworkScopedEvmSmartAccount<Network>> {
|
|
71
|
+
const paymasterUrl = await (async () => {
|
|
72
|
+
if (options.network === "base") {
|
|
73
|
+
return getBaseNodeRpcUrl(options.network);
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
})();
|
|
77
|
+
|
|
78
|
+
const account = {
|
|
33
79
|
address: options.smartAccount.address,
|
|
34
80
|
network: options.network,
|
|
35
81
|
owners: [options.owner],
|
|
36
82
|
name: options.smartAccount.name,
|
|
37
83
|
type: "evm-smart",
|
|
38
|
-
|
|
84
|
+
sendUserOperation: async (
|
|
85
|
+
userOpOptions: Omit<SendUserOperationOptions<unknown[]>, "smartAccount" | "network">,
|
|
86
|
+
) => {
|
|
87
|
+
return sendUserOperation(apiClient, {
|
|
88
|
+
...userOpOptions,
|
|
89
|
+
smartAccount: options.smartAccount,
|
|
90
|
+
network: options.network as EvmUserOperationNetwork,
|
|
91
|
+
paymasterUrl: userOpOptions.paymasterUrl ?? paymasterUrl,
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
waitForUserOperation: async (
|
|
95
|
+
waitOptions: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
|
|
96
|
+
) => {
|
|
97
|
+
return waitForUserOperation(apiClient, {
|
|
98
|
+
...waitOptions,
|
|
99
|
+
smartAccountAddress: options.smartAccount.address,
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
getUserOperation: async (getOptions: Omit<GetUserOperationOptions, "smartAccount">) => {
|
|
103
|
+
return getUserOperation(apiClient, {
|
|
104
|
+
...getOptions,
|
|
105
|
+
smartAccount: options.smartAccount,
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
} as NetworkScopedEvmSmartAccount<Network>;
|
|
109
|
+
|
|
110
|
+
if (isMethodSupportedOnNetwork("transfer", options.network)) {
|
|
111
|
+
Object.assign(account, {
|
|
112
|
+
transfer: async (transferOptions: Omit<SmartAccountTransferOptions, "network">) => {
|
|
113
|
+
return transfer(
|
|
114
|
+
apiClient,
|
|
115
|
+
options.smartAccount,
|
|
116
|
+
{
|
|
117
|
+
...transferOptions,
|
|
118
|
+
network: options.network as EvmUserOperationNetwork,
|
|
119
|
+
paymasterUrl: transferOptions.paymasterUrl ?? paymasterUrl,
|
|
120
|
+
},
|
|
121
|
+
smartAccountTransferStrategy,
|
|
122
|
+
);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (isMethodSupportedOnNetwork("listTokenBalances", options.network)) {
|
|
128
|
+
Object.assign(account, {
|
|
129
|
+
listTokenBalances: async (
|
|
130
|
+
listOptions: Omit<ListTokenBalancesOptions, "address" | "network">,
|
|
131
|
+
) => {
|
|
132
|
+
return listTokenBalances(apiClient, {
|
|
133
|
+
...listOptions,
|
|
134
|
+
address: options.smartAccount.address,
|
|
135
|
+
network: options.network as ListEvmTokenBalancesNetwork,
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (isMethodSupportedOnNetwork("requestFaucet", options.network)) {
|
|
142
|
+
Object.assign(account, {
|
|
143
|
+
requestFaucet: async (faucetOptions: Omit<RequestFaucetOptions, "address" | "network">) => {
|
|
144
|
+
return requestFaucet(apiClient, {
|
|
145
|
+
...faucetOptions,
|
|
146
|
+
address: options.smartAccount.address,
|
|
147
|
+
network: options.network as "base-sepolia" | "ethereum-sepolia",
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (isMethodSupportedOnNetwork("quoteFund", options.network)) {
|
|
154
|
+
Object.assign(account, {
|
|
155
|
+
quoteFund: async (quoteOptions: Omit<QuoteFundOptions, "address">) => {
|
|
156
|
+
return quoteFund(apiClient, {
|
|
157
|
+
...quoteOptions,
|
|
158
|
+
address: options.smartAccount.address,
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (isMethodSupportedOnNetwork("fund", options.network)) {
|
|
165
|
+
Object.assign(account, {
|
|
166
|
+
fund: async (fundOptions: Omit<FundOptions, "address">) => {
|
|
167
|
+
return fund(apiClient, {
|
|
168
|
+
...fundOptions,
|
|
169
|
+
address: options.smartAccount.address,
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
waitForFundOperationReceipt: async (waitOptions: WaitForFundOperationOptions) => {
|
|
173
|
+
return waitForFundOperationReceipt(apiClient, waitOptions);
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (isMethodSupportedOnNetwork("quoteSwap", options.network)) {
|
|
179
|
+
Object.assign(account, {
|
|
180
|
+
quoteSwap: async (quoteSwapOptions: SmartAccountQuoteSwapOptions) => {
|
|
181
|
+
return createSwapQuote(apiClient, {
|
|
182
|
+
...quoteSwapOptions,
|
|
183
|
+
taker: options.smartAccount.address,
|
|
184
|
+
signerAddress: options.owner.address,
|
|
185
|
+
smartAccount: options.smartAccount,
|
|
186
|
+
network: options.network as SmartAccountSwapNetwork,
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (isMethodSupportedOnNetwork("swap", options.network)) {
|
|
193
|
+
Object.assign(account, {
|
|
194
|
+
swap: async (swapOptions: SmartAccountSwapOptions) => {
|
|
195
|
+
return sendSwapOperation(apiClient, {
|
|
196
|
+
...swapOptions,
|
|
197
|
+
smartAccount: options.smartAccount,
|
|
198
|
+
taker: options.smartAccount.address,
|
|
199
|
+
signerAddress: options.owner.address,
|
|
200
|
+
network: options.network as SmartAccountSwapNetwork,
|
|
201
|
+
paymasterUrl: swapOptions.paymasterUrl ?? paymasterUrl,
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
}
|
|
39
206
|
|
|
40
207
|
return account;
|
|
41
208
|
}
|