@coinbase/cdp-sdk 1.3.2 → 1.5.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 +14 -0
- package/README.md +87 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js +5 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +7 -2
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +72 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -0
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +65 -0
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -0
- package/_cjs/actions/evm/transfer/transfer.js +59 -0
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -0
- package/_cjs/actions/evm/transfer/types.js +3 -0
- package/_cjs/actions/evm/transfer/types.js.map +1 -0
- package/_cjs/actions/evm/transfer/utils.js +39 -0
- package/_cjs/actions/evm/transfer/utils.js.map +1 -0
- package/_cjs/actions/evm/types.js +3 -0
- package/_cjs/actions/evm/types.js.map +1 -0
- package/_cjs/auth/index.js +1 -0
- package/_cjs/auth/index.js.map +1 -1
- package/_cjs/auth/utils/http.js +2 -0
- package/_cjs/auth/utils/http.js.map +1 -1
- package/_cjs/auth/utils/index.js +1 -0
- package/_cjs/auth/utils/index.js.map +1 -1
- package/_cjs/auth/utils/jwt.js +16 -6
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/auth/utils/ws.js +31 -0
- package/_cjs/auth/utils/ws.js.map +1 -0
- package/_cjs/client/evm/evm.js +44 -2
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/solana/solana.js +42 -0
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/utils/serializeTransaction.js +18 -0
- package/_cjs/utils/serializeTransaction.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +5 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +7 -2
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +69 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -0
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +62 -0
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -0
- package/_esm/actions/evm/transfer/transfer.js +56 -0
- package/_esm/actions/evm/transfer/transfer.js.map +1 -0
- package/_esm/actions/evm/transfer/types.js +2 -0
- package/_esm/actions/evm/transfer/types.js.map +1 -0
- package/_esm/actions/evm/transfer/utils.js +35 -0
- package/_esm/actions/evm/transfer/utils.js.map +1 -0
- package/_esm/actions/evm/types.js +2 -0
- package/_esm/actions/evm/types.js.map +1 -0
- package/_esm/auth/index.js +1 -0
- package/_esm/auth/index.js.map +1 -1
- package/_esm/auth/utils/http.js +2 -1
- package/_esm/auth/utils/http.js.map +1 -1
- package/_esm/auth/utils/index.js +1 -0
- package/_esm/auth/utils/index.js.map +1 -1
- package/_esm/auth/utils/jwt.js +16 -6
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/auth/utils/ws.js +28 -0
- package/_esm/auth/utils/ws.js.map +1 -0
- package/_esm/client/evm/evm.js +44 -2
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/solana/solana.js +42 -0
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/utils/serializeTransaction.js +15 -0
- package/_esm/utils/serializeTransaction.js.map +1 -0
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts +2 -2
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts +4 -4
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/types.d.ts +4 -3
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +4 -0
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -0
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +4 -0
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -0
- package/_types/actions/evm/transfer/transfer.d.ts +14 -0
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -0
- package/_types/actions/evm/transfer/types.d.ts +71 -0
- package/_types/actions/evm/transfer/types.d.ts.map +1 -0
- package/_types/actions/evm/transfer/utils.d.ts +631 -0
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -0
- package/_types/actions/evm/types.d.ts +88 -0
- package/_types/actions/evm/types.d.ts.map +1 -0
- package/_types/auth/index.d.ts +1 -0
- package/_types/auth/index.d.ts.map +1 -1
- package/_types/auth/utils/http.d.ts +12 -0
- package/_types/auth/utils/http.d.ts.map +1 -1
- package/_types/auth/utils/index.d.ts +1 -0
- package/_types/auth/utils/index.d.ts.map +1 -1
- package/_types/auth/utils/jwt.d.ts +13 -7
- package/_types/auth/utils/jwt.d.ts.map +1 -1
- package/_types/auth/utils/ws.d.ts +45 -0
- package/_types/auth/utils/ws.d.ts.map +1 -0
- package/_types/client/evm/evm.d.ts +17 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +10 -1
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +17 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +8 -0
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/utils/serializeTransaction.d.ts +9 -0
- package/_types/utils/serializeTransaction.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +12 -6
- package/accounts/evm/toEvmSmartAccount.ts +16 -4
- package/accounts/types.ts +20 -16
- package/actions/evm/transfer/accountTransferStrategy.ts +84 -0
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +70 -0
- package/actions/evm/transfer/transfer.ts +71 -0
- package/actions/evm/transfer/types.ts +81 -0
- package/actions/evm/transfer/utils.ts +39 -0
- package/actions/evm/types.ts +88 -0
- package/auth/README.md +18 -3
- package/auth/index.ts +1 -0
- package/auth/utils/http.ts +7 -1
- package/auth/utils/index.ts +1 -0
- package/auth/utils/jwt.ts +36 -13
- package/auth/utils/ws.ts +76 -0
- package/client/evm/evm.ts +45 -2
- package/client/evm/evm.types.ts +11 -1
- package/client/solana/solana.ts +43 -0
- package/client/solana/solana.types.ts +9 -0
- package/package.json +1 -1
- package/utils/serializeTransaction.ts +17 -0
- package/version.ts +1 -1
package/client/evm/evm.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
ListTokenBalancesResult,
|
|
28
28
|
SendTransactionOptions,
|
|
29
29
|
TransactionResult,
|
|
30
|
+
GetOrCreateServerAccountOptions,
|
|
30
31
|
} from "./evm.types.js";
|
|
31
32
|
import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
|
|
32
33
|
import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
|
|
@@ -38,6 +39,7 @@ import {
|
|
|
38
39
|
waitForUserOperation,
|
|
39
40
|
WaitForUserOperationReturnType,
|
|
40
41
|
} from "../../actions/evm/waitForUserOperation.js";
|
|
42
|
+
import { APIError } from "../../openapi-client/errors.js";
|
|
41
43
|
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
42
44
|
import { Hex } from "../../types/misc.js";
|
|
43
45
|
|
|
@@ -145,7 +147,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
145
147
|
options.idempotencyKey,
|
|
146
148
|
);
|
|
147
149
|
|
|
148
|
-
return toEvmSmartAccount({
|
|
150
|
+
return toEvmSmartAccount(CdpOpenApiClient, {
|
|
149
151
|
smartAccount,
|
|
150
152
|
owner: options.owner,
|
|
151
153
|
});
|
|
@@ -216,12 +218,53 @@ export class EvmClient implements EvmClientInterface {
|
|
|
216
218
|
async getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount> {
|
|
217
219
|
const smartAccount = await CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
218
220
|
|
|
219
|
-
return toEvmSmartAccount({
|
|
221
|
+
return toEvmSmartAccount(CdpOpenApiClient, {
|
|
220
222
|
smartAccount,
|
|
221
223
|
owner: options.owner,
|
|
222
224
|
});
|
|
223
225
|
}
|
|
224
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Gets a CDP EVM account, or creates one if it doesn't exist.
|
|
229
|
+
*
|
|
230
|
+
* @param {GetOrCreateServerAccountOptions} options - Parameters for getting or creating the account.
|
|
231
|
+
* @param {string} [options.name] - The name of the account to get or create.
|
|
232
|
+
*
|
|
233
|
+
* @returns A promise that resolves to the account.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const account = await cdp.evm.getOrCreateAccount({
|
|
238
|
+
* name: "MyAccount",
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
async getOrCreateAccount(options: GetOrCreateServerAccountOptions): Promise<ServerAccount> {
|
|
243
|
+
try {
|
|
244
|
+
const account = await this.getAccount(options);
|
|
245
|
+
return account;
|
|
246
|
+
} catch (error) {
|
|
247
|
+
// If it failed because the account doesn't exist, create it
|
|
248
|
+
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
249
|
+
if (doesAccountNotExist) {
|
|
250
|
+
try {
|
|
251
|
+
const account = await this.createAccount(options);
|
|
252
|
+
return account;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
// If it failed because the account already exists, throw an error
|
|
255
|
+
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
256
|
+
if (doesAccountAlreadyExist) {
|
|
257
|
+
const account = await this.getAccount(options);
|
|
258
|
+
return account;
|
|
259
|
+
}
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
throw error;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
225
268
|
/**
|
|
226
269
|
* Gets a user operation for a smart account by user operation hash.
|
|
227
270
|
*
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
EvmSmartAccount as SmartAccount,
|
|
5
5
|
} from "../../accounts/types.js";
|
|
6
6
|
import { SendUserOperationReturnType } from "../../actions/evm/sendUserOperation.js";
|
|
7
|
+
import { Actions } from "../../actions/evm/types.js";
|
|
7
8
|
import {
|
|
8
9
|
EvmUserOperationNetwork,
|
|
9
10
|
EvmUserOperationStatus,
|
|
@@ -41,6 +42,7 @@ export type EvmClientInterface = Omit<
|
|
|
41
42
|
createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
|
|
42
43
|
getAccount: (options: GetServerAccountOptions) => Promise<ServerAccount>;
|
|
43
44
|
getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
|
|
45
|
+
getOrCreateAccount: (options: GetOrCreateServerAccountOptions) => Promise<ServerAccount>;
|
|
44
46
|
getUserOperation: (options: GetUserOperationOptions) => Promise<UserOperation>;
|
|
45
47
|
listAccounts: (options: ListServerAccountsOptions) => Promise<ListServerAccountResult>;
|
|
46
48
|
listSmartAccounts: (options: ListSmartAccountsOptions) => Promise<ListSmartAccountResult>;
|
|
@@ -146,6 +148,14 @@ export interface GetSmartAccountOptions {
|
|
|
146
148
|
owner: Account;
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Options for getting an EVM account, or creating one if it doesn't exist.
|
|
153
|
+
*/
|
|
154
|
+
export interface GetOrCreateServerAccountOptions {
|
|
155
|
+
/** The name of the account. */
|
|
156
|
+
name: string;
|
|
157
|
+
}
|
|
158
|
+
|
|
149
159
|
/**
|
|
150
160
|
* Options for listing EVM accounts.
|
|
151
161
|
*/
|
|
@@ -159,7 +169,7 @@ export interface ListServerAccountsOptions {
|
|
|
159
169
|
/**
|
|
160
170
|
* A smart account that only contains the owner address.
|
|
161
171
|
*/
|
|
162
|
-
export interface ReadonlySmartAccount extends Omit<SmartAccount, "owners"> {
|
|
172
|
+
export interface ReadonlySmartAccount extends Omit<SmartAccount, "owners" | keyof Actions> {
|
|
163
173
|
/** The owners of the smart account. */
|
|
164
174
|
owners: Address[];
|
|
165
175
|
}
|
package/client/solana/solana.ts
CHANGED
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
SignatureResult,
|
|
10
10
|
SignMessageOptions,
|
|
11
11
|
SignTransactionOptions,
|
|
12
|
+
GetOrCreateAccountOptions,
|
|
12
13
|
} from "./solana.types.js";
|
|
14
|
+
import { APIError } from "../../openapi-client/errors.js";
|
|
13
15
|
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
14
16
|
|
|
15
17
|
/**
|
|
@@ -87,6 +89,47 @@ export class SolanaClient implements SolanaClientInterface {
|
|
|
87
89
|
throw new Error("Either address or name must be provided");
|
|
88
90
|
}
|
|
89
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Gets a Solana account by its address.
|
|
94
|
+
*
|
|
95
|
+
* @param {GetOrCreateAccountOptions} options - Parameters for getting or creating the Solana account.
|
|
96
|
+
* @param {string} options.name - The name of the account.
|
|
97
|
+
*
|
|
98
|
+
* @returns A promise that resolves to the account.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const account = await cdp.solana.getOrCreateAccount({
|
|
103
|
+
* name: "MyAccount",
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
async getOrCreateAccount(options: GetOrCreateAccountOptions): Promise<Account> {
|
|
108
|
+
try {
|
|
109
|
+
const account = await this.getAccount(options);
|
|
110
|
+
return account;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
// If it failed because the account doesn't exist, create it
|
|
113
|
+
const doesAccountNotExist = error instanceof APIError && error.statusCode === 404;
|
|
114
|
+
if (doesAccountNotExist) {
|
|
115
|
+
try {
|
|
116
|
+
const account = await this.createAccount(options);
|
|
117
|
+
return account;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
// If it failed because the account already exists, throw an error
|
|
120
|
+
const doesAccountAlreadyExist = error instanceof APIError && error.statusCode === 409;
|
|
121
|
+
if (doesAccountAlreadyExist) {
|
|
122
|
+
const account = await this.getAccount(options);
|
|
123
|
+
return account;
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
90
133
|
/**
|
|
91
134
|
* Lists all Solana accounts.
|
|
92
135
|
*
|
|
@@ -17,6 +17,7 @@ export type SolanaClientInterface = Omit<
|
|
|
17
17
|
> & {
|
|
18
18
|
createAccount: (options: CreateAccountOptions) => Promise<Account>;
|
|
19
19
|
getAccount: (options: GetAccountOptions) => Promise<Account>;
|
|
20
|
+
getOrCreateAccount: (options: GetOrCreateAccountOptions) => Promise<Account>;
|
|
20
21
|
listAccounts: (options: ListAccountsOptions) => Promise<ListAccountsResult>;
|
|
21
22
|
requestFaucet: (options: RequestFaucetOptions) => Promise<SignatureResult>;
|
|
22
23
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
@@ -47,6 +48,14 @@ export interface GetAccountOptions {
|
|
|
47
48
|
name?: string;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Options for getting a Solana account.
|
|
53
|
+
*/
|
|
54
|
+
export interface GetOrCreateAccountOptions {
|
|
55
|
+
/** The name of the account. */
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
/**
|
|
51
60
|
* Options for listing Solana accounts.
|
|
52
61
|
*/
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { serializeTransaction } from "viem";
|
|
2
|
+
|
|
3
|
+
import { TransactionRequestEIP1559 } from "../types/misc.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Serializes a transaction for the Coinbase API.
|
|
7
|
+
*
|
|
8
|
+
* @param transaction - The transaction to serialize.
|
|
9
|
+
* @returns The serialized transaction.
|
|
10
|
+
*/
|
|
11
|
+
export function serializeEIP1559Transaction(transaction: TransactionRequestEIP1559) {
|
|
12
|
+
return serializeTransaction({
|
|
13
|
+
...transaction,
|
|
14
|
+
chainId: 1, // ignored by Coinbase API
|
|
15
|
+
type: "eip1559",
|
|
16
|
+
});
|
|
17
|
+
}
|
package/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.5.0";
|