@coinbase/cdp-sdk 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +39 -3
- package/_cjs/accounts/evm/toEvmServerAccount.js +21 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +28 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/listTokenBalances.js +33 -0
- package/_cjs/actions/evm/listTokenBalances.js.map +1 -0
- package/_cjs/actions/evm/requestFaucet.js +18 -0
- package/_cjs/actions/evm/requestFaucet.js.map +1 -0
- package/_cjs/actions/evm/sendTransaction.js +29 -0
- package/_cjs/actions/evm/sendTransaction.js.map +1 -0
- package/_cjs/actions/evm/sendUserOperation.js +5 -6
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +4 -2
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/client/evm/evm.js +8 -40
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +21 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +28 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/listTokenBalances.js +30 -0
- package/_esm/actions/evm/listTokenBalances.js.map +1 -0
- package/_esm/actions/evm/requestFaucet.js +15 -0
- package/_esm/actions/evm/requestFaucet.js.map +1 -0
- package/_esm/actions/evm/sendTransaction.js +26 -0
- package/_esm/actions/evm/sendTransaction.js.map +1 -0
- package/_esm/actions/evm/sendUserOperation.js +5 -6
- package/_esm/actions/evm/sendUserOperation.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +4 -2
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/client/evm/evm.js +8 -40
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/version.js +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/types.d.ts +2 -2
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/actions/evm/listTokenBalances.d.ts +76 -0
- package/_types/actions/evm/listTokenBalances.d.ts.map +1 -0
- package/_types/actions/evm/requestFaucet.d.ts +34 -0
- package/_types/actions/evm/requestFaucet.d.ts.map +1 -0
- package/_types/actions/evm/sendTransaction.d.ts +42 -0
- package/_types/actions/evm/sendTransaction.d.ts.map +1 -0
- package/_types/actions/evm/sendUserOperation.d.ts +3 -2
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +143 -1
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +6 -3
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +11 -137
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +34 -0
- package/accounts/evm/toEvmSmartAccount.ts +52 -0
- package/accounts/types.ts +2 -2
- package/actions/evm/listTokenBalances.ts +107 -0
- package/actions/evm/requestFaucet.ts +46 -0
- package/actions/evm/sendTransaction.ts +73 -0
- package/actions/evm/sendUserOperation.ts +6 -6
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +4 -2
- package/actions/evm/types.ts +157 -1
- package/client/evm/evm.ts +25 -61
- package/client/evm/evm.types.ts +22 -149
- package/package.json +1 -1
- package/version.ts +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { CreateServerAccountOptions, GetServerAccountOptions, ListServerAccountsOptions, CreateSmartAccountOptions,
|
|
2
|
-
import {
|
|
1
|
+
import { CreateServerAccountOptions, GetServerAccountOptions, ListServerAccountsOptions, CreateSmartAccountOptions, WaitForUserOperationOptions, SignHashOptions, SignatureResult, SignMessageOptions, SignTransactionOptions, GetSmartAccountOptions, SmartAccount, ServerAccount, EvmClientInterface, ListServerAccountResult, PrepareUserOperationOptions, UserOperation, GetUserOperationOptions, ListSmartAccountResult, ListSmartAccountsOptions, GetOrCreateServerAccountOptions } from "./evm.types.js";
|
|
2
|
+
import { ListTokenBalancesResult, ListTokenBalancesOptions } from "../../actions/evm/listTokenBalances.js";
|
|
3
|
+
import { RequestFaucetOptions, RequestFaucetResult } from "../../actions/evm/requestFaucet.js";
|
|
4
|
+
import { SendUserOperationOptions, SendUserOperationReturnType } from "../../actions/evm/sendUserOperation.js";
|
|
3
5
|
import { WaitForUserOperationReturnType } from "../../actions/evm/waitForUserOperation.js";
|
|
6
|
+
import type { TransactionResult, SendTransactionOptions } from "../../actions/evm/sendTransaction.js";
|
|
4
7
|
/**
|
|
5
8
|
* The namespace containing all EVM methods.
|
|
6
9
|
*/
|
|
@@ -373,7 +376,7 @@ export declare class EvmClient implements EvmClientInterface {
|
|
|
373
376
|
* });
|
|
374
377
|
* ```
|
|
375
378
|
*/
|
|
376
|
-
sendUserOperation(options: SendUserOperationOptions): Promise<SendUserOperationReturnType>;
|
|
379
|
+
sendUserOperation(options: SendUserOperationOptions<unknown[]>): Promise<SendUserOperationReturnType>;
|
|
377
380
|
/**
|
|
378
381
|
* Signs an EVM hash.
|
|
379
382
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../../client/evm/evm.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,
|
|
1
|
+
{"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../../client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;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,eAAe,CAAC;IAchF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,oBAAoB,CACxB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,8BAA8B,CAAC;CAK3C"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { EvmAccount as Account, EvmServerAccount as ServerAccount, EvmSmartAccount as SmartAccount } from "../../accounts/types.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
1
|
+
import type { EvmAccount as Account, EvmServerAccount as ServerAccount, EvmSmartAccount as SmartAccount } from "../../accounts/types.js";
|
|
2
|
+
import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "../../actions/evm/listTokenBalances.js";
|
|
3
|
+
import type { RequestFaucetOptions, RequestFaucetResult } from "../../actions/evm/requestFaucet.js";
|
|
4
|
+
import type { TransactionResult, SendTransactionOptions } from "../../actions/evm/sendTransaction.js";
|
|
5
|
+
import type { SendUserOperationOptions, SendUserOperationReturnType } from "../../actions/evm/sendUserOperation.js";
|
|
6
|
+
import type { Actions } from "../../actions/evm/types.js";
|
|
7
|
+
import type { EvmUserOperationNetwork, EvmUserOperationStatus, OpenApiEvmMethods } from "../../openapi-client/index.js";
|
|
8
|
+
import type { Calls } from "../../types/calls.js";
|
|
9
|
+
import type { Address, Hex } from "../../types/misc.js";
|
|
10
|
+
import type { WaitOptions } from "../../utils/wait.js";
|
|
8
11
|
/**
|
|
9
12
|
* The EvmClient type, where all OpenApiEvmMethods methods are wrapped.
|
|
10
13
|
*/
|
|
@@ -21,7 +24,7 @@ export type EvmClientInterface = Omit<typeof OpenApiEvmMethods, "createEvmAccoun
|
|
|
21
24
|
prepareUserOperation: (options: PrepareUserOperationOptions) => Promise<UserOperation>;
|
|
22
25
|
requestFaucet: (options: RequestFaucetOptions) => Promise<RequestFaucetResult>;
|
|
23
26
|
sendTransaction: (options: SendTransactionOptions) => Promise<TransactionResult>;
|
|
24
|
-
sendUserOperation: (options: SendUserOperationOptions) => Promise<SendUserOperationReturnType>;
|
|
27
|
+
sendUserOperation: (options: SendUserOperationOptions<unknown[]>) => Promise<SendUserOperationReturnType>;
|
|
25
28
|
signHash: (options: SignHashOptions) => Promise<SignatureResult>;
|
|
26
29
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
27
30
|
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
@@ -177,63 +180,6 @@ export interface CreateSmartAccountOptions {
|
|
|
177
180
|
/** The idempotency key. */
|
|
178
181
|
idempotencyKey?: string;
|
|
179
182
|
}
|
|
180
|
-
/**
|
|
181
|
-
* Options for requesting funds from an EVM faucet.
|
|
182
|
-
*/
|
|
183
|
-
export interface RequestFaucetOptions {
|
|
184
|
-
/** The address of the account. */
|
|
185
|
-
address: string;
|
|
186
|
-
/** The network to request funds from. */
|
|
187
|
-
network: "base-sepolia" | "ethereum-sepolia";
|
|
188
|
-
/** The token to request funds for. */
|
|
189
|
-
token: "eth" | "usdc" | "eurc" | "cbbtc";
|
|
190
|
-
/** The idempotency key. */
|
|
191
|
-
idempotencyKey?: string;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* The result of requesting funds from an EVM faucet.
|
|
195
|
-
*/
|
|
196
|
-
export interface RequestFaucetResult {
|
|
197
|
-
/** The transaction hash. */
|
|
198
|
-
transactionHash: Hex;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Options for sending an EVM transaction.
|
|
202
|
-
*/
|
|
203
|
-
export interface SendTransactionOptions {
|
|
204
|
-
/** The address of the account. */
|
|
205
|
-
address: Address;
|
|
206
|
-
/**
|
|
207
|
-
* The transaction to send. The chainId is ignored in favor of the `network` field.
|
|
208
|
-
*
|
|
209
|
-
* This can be either:
|
|
210
|
-
* - An RLP-encoded transaction to sign and send, as a 0x-prefixed hex string, or
|
|
211
|
-
* - An EIP-1559 transaction request object.
|
|
212
|
-
*/
|
|
213
|
-
transaction: Hex | TransactionRequestEIP1559;
|
|
214
|
-
/**
|
|
215
|
-
* The network to send the transaction to.
|
|
216
|
-
* The chainId in the `transaction` field is ignored in favor of this field.
|
|
217
|
-
*/
|
|
218
|
-
network: SendEvmTransactionBodyNetwork;
|
|
219
|
-
/** The idempotency key. */
|
|
220
|
-
idempotencyKey?: string;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Options for sending a user operation.
|
|
224
|
-
*/
|
|
225
|
-
export interface SendUserOperationOptions {
|
|
226
|
-
/** The smart account. */
|
|
227
|
-
smartAccount: SmartAccount;
|
|
228
|
-
/** The network. */
|
|
229
|
-
network: EvmUserOperationNetwork;
|
|
230
|
-
/** The calls. */
|
|
231
|
-
calls: Call[];
|
|
232
|
-
/** The paymaster URL. */
|
|
233
|
-
paymasterUrl?: string;
|
|
234
|
-
/** The idempotency key. */
|
|
235
|
-
idempotencyKey?: string;
|
|
236
|
-
}
|
|
237
183
|
/**
|
|
238
184
|
* Options for signing an EVM hash.
|
|
239
185
|
*/
|
|
@@ -274,13 +220,6 @@ export interface SignatureResult {
|
|
|
274
220
|
/** The signature. */
|
|
275
221
|
signature: Hex;
|
|
276
222
|
}
|
|
277
|
-
/**
|
|
278
|
-
* Result of a transaction
|
|
279
|
-
*/
|
|
280
|
-
export interface TransactionResult {
|
|
281
|
-
/** The hash of the transaction. */
|
|
282
|
-
transactionHash: Hex;
|
|
283
|
-
}
|
|
284
223
|
/**
|
|
285
224
|
* Options for waiting for a user operation.
|
|
286
225
|
*/
|
|
@@ -292,69 +231,4 @@ export interface WaitForUserOperationOptions {
|
|
|
292
231
|
/** The wait options. */
|
|
293
232
|
waitOptions?: WaitOptions;
|
|
294
233
|
}
|
|
295
|
-
/**
|
|
296
|
-
* Options for listing EVM token balances.
|
|
297
|
-
*/
|
|
298
|
-
export interface ListTokenBalancesOptions {
|
|
299
|
-
/** The address of the account. */
|
|
300
|
-
address: Address;
|
|
301
|
-
/** The network. */
|
|
302
|
-
network: ListEvmTokenBalancesNetwork;
|
|
303
|
-
/** The page size to paginate through the token balances. */
|
|
304
|
-
pageSize?: number;
|
|
305
|
-
/** The page token to paginate through the token balances. */
|
|
306
|
-
pageToken?: string;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* A token on an EVM network, which is either an ERC-20 or a native token (i.e. ETH).
|
|
310
|
-
*/
|
|
311
|
-
export interface EvmToken {
|
|
312
|
-
/**
|
|
313
|
-
* The contract address of the token. For Ether, the contract address is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
|
|
314
|
-
* per EIP-7528. For ERC-20 tokens, this is the contract address where the token is deployed.
|
|
315
|
-
*/
|
|
316
|
-
contractAddress: Address;
|
|
317
|
-
/** The network the token is on. */
|
|
318
|
-
network: ListEvmTokenBalancesNetwork;
|
|
319
|
-
/**
|
|
320
|
-
* The symbol of the token, which is optional and non-unique. Note: This field
|
|
321
|
-
* may not be present for most tokens while the API is still under development.
|
|
322
|
-
*/
|
|
323
|
-
symbol?: string;
|
|
324
|
-
/**
|
|
325
|
-
* The name of the token, which is optional and non-unique. Note: This field
|
|
326
|
-
* may not be present for most tokens while the API is still under development.
|
|
327
|
-
*/
|
|
328
|
-
name?: string;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* A token amount on an EVM network.
|
|
332
|
-
*/
|
|
333
|
-
export interface EvmTokenAmount {
|
|
334
|
-
/** The amount of the token in the smallest indivisible unit of the token. */
|
|
335
|
-
amount: bigint;
|
|
336
|
-
/** The number of decimals in the token. */
|
|
337
|
-
decimals: bigint;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* An EVM token balance.
|
|
341
|
-
*/
|
|
342
|
-
export interface EvmTokenBalance {
|
|
343
|
-
/** The token. */
|
|
344
|
-
token: EvmToken;
|
|
345
|
-
/** The amount of the token. */
|
|
346
|
-
amount: EvmTokenAmount;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* The result of listing EVM token balances.
|
|
350
|
-
*/
|
|
351
|
-
export interface ListTokenBalancesResult {
|
|
352
|
-
/** The token balances. */
|
|
353
|
-
balances: EvmTokenBalance[];
|
|
354
|
-
/**
|
|
355
|
-
* The next page token to paginate through the token balances.
|
|
356
|
-
* If undefined, there are no more token balances to paginate through.
|
|
357
|
-
*/
|
|
358
|
-
nextPageToken?: string;
|
|
359
|
-
}
|
|
360
234
|
//# sourceMappingURL=evm.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evm.types.d.ts","sourceRoot":"","sources":["../../../client/evm/evm.types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"evm.types.d.ts","sourceRoot":"","sources":["../../../client/evm/evm.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,IAAI,OAAO,EACrB,gBAAgB,IAAI,aAAa,EACjC,eAAe,IAAI,YAAY,EAChC,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACpG,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAC5B,MAAM,wCAAwC,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EACV,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAA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E,WAAW,CAAC;CAC3B"}
|
package/_types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.6.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { type Hex, type TransactionSerializable, serializeTransaction } from "viem";
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
listTokenBalances,
|
|
5
|
+
type ListTokenBalancesResult,
|
|
6
|
+
type ListTokenBalancesOptions,
|
|
7
|
+
} from "../../actions/evm/listTokenBalances.js";
|
|
8
|
+
import {
|
|
9
|
+
requestFaucet,
|
|
10
|
+
type RequestFaucetOptions,
|
|
11
|
+
type RequestFaucetResult,
|
|
12
|
+
} from "../../actions/evm/requestFaucet.js";
|
|
13
|
+
import { sendTransaction } from "../../actions/evm/sendTransaction.js";
|
|
3
14
|
import { accountTransferStrategy } from "../../actions/evm/transfer/accountTransferStrategy.js";
|
|
4
15
|
import { transfer } from "../../actions/evm/transfer/transfer.js";
|
|
5
16
|
|
|
17
|
+
import type { SendTransactionOptions } from "../../actions/evm/sendTransaction.js";
|
|
6
18
|
import type { TransferResult } from "../../actions/evm/transfer/types.js";
|
|
7
19
|
import type { CdpOpenApiClientType, EvmAccount } from "../../openapi-client/index.js";
|
|
8
20
|
import type { Address, Hash } from "../../types/misc.js";
|
|
@@ -58,6 +70,28 @@ export function toEvmServerAccount(
|
|
|
58
70
|
async transfer(transferArgs): Promise<TransferResult> {
|
|
59
71
|
return transfer(apiClient, account, transferArgs, accountTransferStrategy);
|
|
60
72
|
},
|
|
73
|
+
async listTokenBalances(
|
|
74
|
+
options: Omit<ListTokenBalancesOptions, "address">,
|
|
75
|
+
): Promise<ListTokenBalancesResult> {
|
|
76
|
+
return listTokenBalances(apiClient, {
|
|
77
|
+
...options,
|
|
78
|
+
address: this.address,
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
async requestFaucet(
|
|
82
|
+
options: Omit<RequestFaucetOptions, "address">,
|
|
83
|
+
): Promise<RequestFaucetResult> {
|
|
84
|
+
return requestFaucet(apiClient, {
|
|
85
|
+
...options,
|
|
86
|
+
address: this.address,
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
async sendTransaction(options: Omit<SendTransactionOptions, "address">) {
|
|
90
|
+
return sendTransaction(apiClient, {
|
|
91
|
+
...options,
|
|
92
|
+
address: this.address,
|
|
93
|
+
});
|
|
94
|
+
},
|
|
61
95
|
name: options.account.name,
|
|
62
96
|
type: "evm-server",
|
|
63
97
|
};
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
listTokenBalances,
|
|
3
|
+
type ListTokenBalancesOptions,
|
|
4
|
+
type ListTokenBalancesResult,
|
|
5
|
+
} from "../../actions/evm/listTokenBalances.js";
|
|
6
|
+
import {
|
|
7
|
+
RequestFaucetResult,
|
|
8
|
+
RequestFaucetOptions,
|
|
9
|
+
requestFaucet,
|
|
10
|
+
} from "../../actions/evm/requestFaucet.js";
|
|
11
|
+
import {
|
|
12
|
+
type SendUserOperationOptions,
|
|
13
|
+
type SendUserOperationReturnType,
|
|
14
|
+
sendUserOperation,
|
|
15
|
+
} from "../../actions/evm/sendUserOperation.js";
|
|
1
16
|
import { smartAccountTransferStrategy } from "../../actions/evm/transfer/smartAccountTransferStrategy.js";
|
|
2
17
|
import { transfer } from "../../actions/evm/transfer/transfer.js";
|
|
18
|
+
import {
|
|
19
|
+
waitForUserOperation,
|
|
20
|
+
WaitForUserOperationOptions,
|
|
21
|
+
WaitForUserOperationReturnType,
|
|
22
|
+
} from "../../actions/evm/waitForUserOperation.js";
|
|
3
23
|
|
|
4
24
|
import type { TransferResult } from "../../actions/evm/transfer/types.js";
|
|
5
25
|
import type {
|
|
@@ -41,6 +61,38 @@ export function toEvmSmartAccount(
|
|
|
41
61
|
async transfer(transferArgs): Promise<TransferResult> {
|
|
42
62
|
return transfer(apiClient, account, transferArgs, smartAccountTransferStrategy);
|
|
43
63
|
},
|
|
64
|
+
async listTokenBalances(
|
|
65
|
+
options: Omit<ListTokenBalancesOptions, "address">,
|
|
66
|
+
): Promise<ListTokenBalancesResult> {
|
|
67
|
+
return listTokenBalances(apiClient, {
|
|
68
|
+
...options,
|
|
69
|
+
address: this.address,
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
async sendUserOperation(
|
|
73
|
+
options: Omit<SendUserOperationOptions<unknown[]>, "smartAccount">,
|
|
74
|
+
): Promise<SendUserOperationReturnType> {
|
|
75
|
+
return sendUserOperation(apiClient, {
|
|
76
|
+
...options,
|
|
77
|
+
smartAccount: account,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async waitForUserOperation(
|
|
81
|
+
options: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
|
|
82
|
+
): Promise<WaitForUserOperationReturnType> {
|
|
83
|
+
return waitForUserOperation(apiClient, {
|
|
84
|
+
...options,
|
|
85
|
+
smartAccountAddress: account.address,
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
async requestFaucet(
|
|
89
|
+
options: Omit<RequestFaucetOptions, "address">,
|
|
90
|
+
): Promise<RequestFaucetResult> {
|
|
91
|
+
return requestFaucet(apiClient, {
|
|
92
|
+
...options,
|
|
93
|
+
address: account.address,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
44
96
|
name: options.smartAccount.name,
|
|
45
97
|
type: "evm-smart",
|
|
46
98
|
};
|
package/accounts/types.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type EvmAccount = {
|
|
|
32
32
|
*/
|
|
33
33
|
export type EvmServerAccount = Prettify<
|
|
34
34
|
EvmAccount &
|
|
35
|
-
Actions & {
|
|
35
|
+
Omit<Actions, "sendUserOperation" | "waitForUserOperation"> & {
|
|
36
36
|
/** Optional name for the server account. */
|
|
37
37
|
name?: string;
|
|
38
38
|
/** Indicates this is a server-managed account. */
|
|
@@ -53,5 +53,5 @@ export type EvmSmartAccount = Prettify<
|
|
|
53
53
|
owners: EvmAccount[];
|
|
54
54
|
/** Identifier for the smart account type. */
|
|
55
55
|
type: "evm-smart";
|
|
56
|
-
} & Actions
|
|
56
|
+
} & Omit<Actions, "sendTransaction">
|
|
57
57
|
>;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
import { CdpOpenApiClientType, ListEvmTokenBalancesNetwork } from "../../openapi-client/index.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A token on an EVM network, which is either an ERC-20 or a native token (i.e. ETH).
|
|
7
|
+
*/
|
|
8
|
+
export interface EvmToken {
|
|
9
|
+
/**
|
|
10
|
+
* The contract address of the token. For Ether, the contract address is 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE
|
|
11
|
+
* per EIP-7528. For ERC-20 tokens, this is the contract address where the token is deployed.
|
|
12
|
+
*/
|
|
13
|
+
contractAddress: Address;
|
|
14
|
+
/** The network the token is on. */
|
|
15
|
+
network: ListEvmTokenBalancesNetwork;
|
|
16
|
+
/**
|
|
17
|
+
* The symbol of the token, which is optional and non-unique. Note: This field
|
|
18
|
+
* may not be present for most tokens while the API is still under development.
|
|
19
|
+
*/
|
|
20
|
+
symbol?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The name of the token, which is optional and non-unique. Note: This field
|
|
23
|
+
* may not be present for most tokens while the API is still under development.
|
|
24
|
+
*/
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A token amount on an EVM network.
|
|
30
|
+
*/
|
|
31
|
+
export interface EvmTokenAmount {
|
|
32
|
+
/** The amount of the token in the smallest indivisible unit of the token. */
|
|
33
|
+
amount: bigint;
|
|
34
|
+
/** The number of decimals in the token. */
|
|
35
|
+
decimals: bigint;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An EVM token balance.
|
|
39
|
+
*/
|
|
40
|
+
export interface EvmTokenBalance {
|
|
41
|
+
/** The token. */
|
|
42
|
+
token: EvmToken;
|
|
43
|
+
/** The amount of the token. */
|
|
44
|
+
amount: EvmTokenAmount;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Options for listing EVM token balances.
|
|
49
|
+
*/
|
|
50
|
+
export interface ListTokenBalancesOptions {
|
|
51
|
+
/** The address of the account. */
|
|
52
|
+
address: Address;
|
|
53
|
+
/** The network. */
|
|
54
|
+
network: ListEvmTokenBalancesNetwork;
|
|
55
|
+
/** The page size to paginate through the token balances. */
|
|
56
|
+
pageSize?: number;
|
|
57
|
+
/** The page token to paginate through the token balances. */
|
|
58
|
+
pageToken?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The result of listing EVM token balances.
|
|
63
|
+
*/
|
|
64
|
+
export interface ListTokenBalancesResult {
|
|
65
|
+
/** The token balances. */
|
|
66
|
+
balances: EvmTokenBalance[];
|
|
67
|
+
/**
|
|
68
|
+
* The next page token to paginate through the token balances.
|
|
69
|
+
* If undefined, there are no more token balances to paginate through.
|
|
70
|
+
*/
|
|
71
|
+
nextPageToken?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* List the token balances for an EVM account.
|
|
76
|
+
*
|
|
77
|
+
* @param client - The client to use to list the token balances.
|
|
78
|
+
* @param options - The options for listing the token balances.
|
|
79
|
+
* @returns The result of listing the token balances.
|
|
80
|
+
*/
|
|
81
|
+
export async function listTokenBalances(
|
|
82
|
+
client: CdpOpenApiClientType,
|
|
83
|
+
options: ListTokenBalancesOptions,
|
|
84
|
+
): Promise<ListTokenBalancesResult> {
|
|
85
|
+
const response = await client.listEvmTokenBalances(options.network, options.address, {
|
|
86
|
+
pageSize: options.pageSize,
|
|
87
|
+
pageToken: options.pageToken,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const balances = response.balances.map(balance => {
|
|
91
|
+
return {
|
|
92
|
+
token: {
|
|
93
|
+
network: balance.token.network,
|
|
94
|
+
contractAddress: balance.token.contractAddress as Address,
|
|
95
|
+
},
|
|
96
|
+
amount: {
|
|
97
|
+
amount: BigInt(balance.amount.amount),
|
|
98
|
+
decimals: BigInt(balance.amount.decimals),
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
balances,
|
|
105
|
+
nextPageToken: response.nextPageToken,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
2
|
+
import { Hex } from "../../types/misc.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for requesting funds from an EVM faucet.
|
|
6
|
+
*/
|
|
7
|
+
export interface RequestFaucetOptions {
|
|
8
|
+
/** The address of the account. */
|
|
9
|
+
address: string;
|
|
10
|
+
/** The network to request funds from. */
|
|
11
|
+
network: "base-sepolia" | "ethereum-sepolia";
|
|
12
|
+
/** The token to request funds for. */
|
|
13
|
+
token: "eth" | "usdc" | "eurc" | "cbbtc";
|
|
14
|
+
/** The idempotency key. */
|
|
15
|
+
idempotencyKey?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The result of requesting funds from an EVM faucet.
|
|
20
|
+
*/
|
|
21
|
+
export interface RequestFaucetResult {
|
|
22
|
+
/** The transaction hash. */
|
|
23
|
+
transactionHash: Hex;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Requests funds from an EVM faucet.
|
|
28
|
+
*
|
|
29
|
+
* @param apiClient - The API client.
|
|
30
|
+
* @param options - The options for requesting funds from the EVM faucet.
|
|
31
|
+
*
|
|
32
|
+
* @returns A promise that resolves to the transaction hash.
|
|
33
|
+
*/
|
|
34
|
+
export async function requestFaucet(
|
|
35
|
+
apiClient: CdpOpenApiClientType,
|
|
36
|
+
options: RequestFaucetOptions,
|
|
37
|
+
) {
|
|
38
|
+
const { transactionHash } = await apiClient.requestEvmFaucet(
|
|
39
|
+
{ address: options.address, network: options.network, token: options.token },
|
|
40
|
+
options.idempotencyKey,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
transactionHash: transactionHash as Hex,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { serializeTransaction, TransactionRequestEIP1559 } from "viem";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
CdpOpenApiClientType,
|
|
5
|
+
SendEvmTransactionBodyNetwork,
|
|
6
|
+
} from "../../openapi-client/index.js";
|
|
7
|
+
import type { Address, Hex } from "../../types/misc.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Options for sending an EVM transaction.
|
|
11
|
+
*/
|
|
12
|
+
export interface SendTransactionOptions {
|
|
13
|
+
/** The address of the account. */
|
|
14
|
+
address: Address;
|
|
15
|
+
/**
|
|
16
|
+
* The transaction to send. The chainId is ignored in favor of the `network` field.
|
|
17
|
+
*
|
|
18
|
+
* This can be either:
|
|
19
|
+
* - An RLP-encoded transaction to sign and send, as a 0x-prefixed hex string, or
|
|
20
|
+
* - An EIP-1559 transaction request object.
|
|
21
|
+
*/
|
|
22
|
+
transaction: Hex | TransactionRequestEIP1559;
|
|
23
|
+
/**
|
|
24
|
+
* The network to send the transaction to.
|
|
25
|
+
* The chainId in the `transaction` field is ignored in favor of this field.
|
|
26
|
+
*/
|
|
27
|
+
network: SendEvmTransactionBodyNetwork;
|
|
28
|
+
/** The idempotency key. */
|
|
29
|
+
idempotencyKey?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Result of a transaction
|
|
34
|
+
*/
|
|
35
|
+
export interface TransactionResult {
|
|
36
|
+
/** The hash of the transaction. */
|
|
37
|
+
transactionHash: Hex;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sends an EVM transaction.
|
|
42
|
+
*
|
|
43
|
+
* @param apiClient - The API client.
|
|
44
|
+
* @param options - The options for sending the transaction.
|
|
45
|
+
*
|
|
46
|
+
* @returns The result of the transaction.
|
|
47
|
+
*/
|
|
48
|
+
export async function sendTransaction(
|
|
49
|
+
apiClient: CdpOpenApiClientType,
|
|
50
|
+
options: SendTransactionOptions,
|
|
51
|
+
): Promise<TransactionResult> {
|
|
52
|
+
const { address, network, idempotencyKey } = options;
|
|
53
|
+
let transaction = options.transaction;
|
|
54
|
+
|
|
55
|
+
if (typeof transaction !== "string") {
|
|
56
|
+
transaction = serializeTransaction({
|
|
57
|
+
...transaction,
|
|
58
|
+
// chainId is ignored in favor of network
|
|
59
|
+
chainId: 1,
|
|
60
|
+
type: "eip1559",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await apiClient.sendEvmTransaction(
|
|
65
|
+
address,
|
|
66
|
+
{ transaction, network },
|
|
67
|
+
idempotencyKey,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
transactionHash: result.transactionHash as Hex,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -16,6 +16,8 @@ import type { Address, Hex } from "../../types/misc.js";
|
|
|
16
16
|
* @template T - Array type for the calls parameter.
|
|
17
17
|
*/
|
|
18
18
|
export type SendUserOperationOptions<T extends readonly unknown[]> = {
|
|
19
|
+
/** The smart account. */
|
|
20
|
+
smartAccount: EvmSmartAccount;
|
|
19
21
|
/**
|
|
20
22
|
* Array of contract calls to execute in the user operation.
|
|
21
23
|
* Each call can either be:
|
|
@@ -97,13 +99,11 @@ export type SendUserOperationReturnType = {
|
|
|
97
99
|
* ```
|
|
98
100
|
*
|
|
99
101
|
* @param {CdpOpenApiClientType} client - The client to use to send the user operation.
|
|
100
|
-
* @param {EvmSmartAccount} smartAccount - The smart account to send the user operation from.
|
|
101
102
|
* @param {SendUserOperationOptions<T>} options - The options for the user operation.
|
|
102
103
|
* @returns {Promise<SendUserOperationReturnType>} The result of the user operation.
|
|
103
104
|
*/
|
|
104
105
|
export async function sendUserOperation<T extends readonly unknown[]>(
|
|
105
106
|
client: CdpOpenApiClientType,
|
|
106
|
-
smartAccount: EvmSmartAccount,
|
|
107
107
|
options: SendUserOperationOptions<T>,
|
|
108
108
|
): Promise<SendUserOperationReturnType> {
|
|
109
109
|
const { calls, network, paymasterUrl } = options;
|
|
@@ -134,20 +134,20 @@ export async function sendUserOperation<T extends readonly unknown[]>(
|
|
|
134
134
|
};
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
-
const createOpResponse = await client.prepareUserOperation(smartAccount.address, {
|
|
137
|
+
const createOpResponse = await client.prepareUserOperation(options.smartAccount.address, {
|
|
138
138
|
network,
|
|
139
139
|
calls: encodedCalls,
|
|
140
140
|
paymasterUrl,
|
|
141
141
|
});
|
|
142
142
|
|
|
143
|
-
const owner = smartAccount.owners[0];
|
|
143
|
+
const owner = options.smartAccount.owners[0];
|
|
144
144
|
|
|
145
145
|
const signature = await owner.sign({
|
|
146
146
|
hash: createOpResponse.userOpHash as Hex,
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
const broadcastResponse = await client.sendUserOperation(
|
|
150
|
-
smartAccount.address,
|
|
150
|
+
options.smartAccount.address,
|
|
151
151
|
createOpResponse.userOpHash as Hex,
|
|
152
152
|
{
|
|
153
153
|
signature,
|
|
@@ -156,7 +156,7 @@ export async function sendUserOperation<T extends readonly unknown[]>(
|
|
|
156
156
|
);
|
|
157
157
|
|
|
158
158
|
return {
|
|
159
|
-
smartAccountAddress: smartAccount.address,
|
|
159
|
+
smartAccountAddress: options.smartAccount.address,
|
|
160
160
|
status: broadcastResponse.status,
|
|
161
161
|
userOpHash: createOpResponse.userOpHash,
|
|
162
162
|
} as SendUserOperationReturnType;
|