@coinbase/cdp-sdk 1.6.0 → 1.8.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 +23 -0
- package/README.md +284 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +7 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/types.js.map +1 -0
- package/_cjs/accounts/solana/toSolanaAccount.js +42 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -0
- package/_cjs/accounts/solana/types.js +3 -0
- package/_cjs/accounts/solana/types.js.map +1 -0
- package/_cjs/actions/evm/getUserOperation.js +36 -0
- package/_cjs/actions/evm/getUserOperation.js.map +1 -0
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +11 -7
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +7 -3
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/solana/requestFaucet.js +29 -0
- package/_cjs/actions/solana/requestFaucet.js.map +1 -0
- package/_cjs/actions/solana/signMessage.js +29 -0
- package/_cjs/actions/solana/signMessage.js.map +1 -0
- package/_cjs/actions/solana/signTransaction.js +46 -0
- package/_cjs/actions/solana/signTransaction.js.map +1 -0
- package/_cjs/actions/solana/types.js +3 -0
- package/_cjs/actions/solana/types.js.map +1 -0
- package/_cjs/analytics.js +68 -8
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +9 -3
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +135 -27
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/index.js +6 -0
- package/_cjs/client/policies/index.js.map +1 -0
- package/_cjs/client/policies/policies.js +232 -0
- package/_cjs/client/policies/policies.js.map +1 -0
- package/_cjs/client/policies/policies.types.js +3 -0
- package/_cjs/client/policies/policies.types.js.map +1 -0
- package/_cjs/client/solana/solana.js +84 -22
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +4 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +59 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +27 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +56 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +3 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js +56 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +284 -0
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +14 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +42 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/index.js +7 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +186 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/{accounts → policies}/types.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +4 -2
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +7 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/types.js.map +1 -0
- package/_esm/accounts/solana/toSolanaAccount.js +39 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -0
- package/_esm/accounts/solana/types.js +2 -0
- package/_esm/accounts/solana/types.js.map +1 -0
- package/_esm/actions/evm/getUserOperation.js +33 -0
- package/_esm/actions/evm/getUserOperation.js.map +1 -0
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +11 -7
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +9 -6
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +7 -3
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/solana/requestFaucet.js +26 -0
- package/_esm/actions/solana/requestFaucet.js.map +1 -0
- package/_esm/actions/solana/signMessage.js +26 -0
- package/_esm/actions/solana/signMessage.js.map +1 -0
- package/_esm/actions/solana/signTransaction.js +43 -0
- package/_esm/actions/solana/signTransaction.js.map +1 -0
- package/_esm/actions/solana/types.js +2 -0
- package/_esm/actions/solana/types.js.map +1 -0
- package/_esm/analytics.js +68 -7
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +10 -4
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +135 -27
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/index.js +2 -0
- package/_esm/client/policies/index.js.map +1 -0
- package/_esm/client/policies/policies.js +228 -0
- package/_esm/client/policies/policies.js.map +1 -0
- package/_esm/client/policies/policies.types.js +2 -0
- package/_esm/client/policies/policies.types.js.map +1 -0
- package/_esm/client/solana/solana.js +84 -22
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +58 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +24 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +51 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +3 -1
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +3 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js +48 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.js.map +1 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +259 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +12 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +39 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/index.js +6 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +183 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/{accounts → policies}/types.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmServerAccount.d.ts +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/{types.d.ts → evm/types.d.ts} +10 -7
- package/_types/accounts/evm/types.d.ts.map +1 -0
- package/_types/accounts/solana/toSolanaAccount.d.ts +20 -0
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -0
- package/_types/accounts/solana/types.d.ts +12 -0
- package/_types/accounts/solana/types.d.ts.map +1 -0
- package/_types/actions/evm/getUserOperation.d.ts +22 -0
- package/_types/actions/evm/getUserOperation.d.ts.map +1 -0
- package/_types/actions/evm/sendUserOperation.d.ts +1 -1
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts +1 -1
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +3 -3
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +39 -6
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +28 -5
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/requestFaucet.d.ts +23 -0
- package/_types/actions/solana/requestFaucet.d.ts.map +1 -0
- package/_types/actions/solana/signMessage.d.ts +23 -0
- package/_types/actions/solana/signMessage.d.ts.map +1 -0
- package/_types/actions/solana/signTransaction.d.ts +38 -0
- package/_types/actions/solana/signTransaction.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +80 -0
- package/_types/actions/solana/types.d.ts.map +1 -0
- package/_types/analytics.d.ts +14 -5
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts +3 -0
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +89 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +36 -6
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/index.d.ts +2 -0
- package/_types/client/policies/index.d.ts.map +1 -0
- package/_types/client/policies/policies.d.ts +216 -0
- package/_types/client/policies/policies.d.ts.map +1 -0
- package/_types/client/policies/policies.types.d.ts +96 -0
- package/_types/client/policies/policies.types.d.ts.map +1 -0
- package/_types/client/solana/solana.d.ts +47 -4
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +21 -12
- package/_types/client/solana/solana.types.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 +299 -0
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +13 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +3 -1
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +3 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts +43 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.d.ts.map +1 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +25 -0
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +7 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +2 -0
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +19 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +922 -0
- package/_types/policies/schema.d.ts.map +1 -0
- package/_types/policies/types.d.ts +19 -0
- package/_types/policies/types.d.ts.map +1 -0
- package/_types/types/misc.d.ts +39 -0
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +7 -4
- package/accounts/evm/toEvmSmartAccount.ts +11 -1
- package/accounts/{types.ts → evm/types.ts} +10 -12
- package/accounts/solana/toSolanaAccount.ts +60 -0
- package/accounts/solana/types.ts +13 -0
- package/actions/evm/getUserOperation.ts +40 -0
- package/actions/evm/sendUserOperation.ts +1 -1
- package/actions/evm/transfer/accountTransferStrategy.ts +12 -8
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +10 -7
- package/actions/evm/transfer/transfer.ts +17 -6
- package/actions/evm/transfer/types.ts +54 -11
- package/actions/evm/types.ts +37 -5
- package/actions/solana/requestFaucet.ts +35 -0
- package/actions/solana/signMessage.ts +36 -0
- package/actions/solana/signTransaction.ts +53 -0
- package/actions/solana/types.ts +87 -0
- package/analytics.ts +84 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +162 -33
- package/client/evm/evm.types.ts +42 -4
- package/client/policies/index.ts +1 -0
- package/client/policies/policies.ts +246 -0
- package/client/policies/policies.types.ts +109 -0
- package/client/solana/solana.ts +107 -38
- package/client/solana/solana.types.ts +25 -15
- package/index.ts +8 -1
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +360 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +102 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +43 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -1
- package/openapi-client/generated/index.msw.ts +3 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +404 -0
- package/openapi-client/generated/policy-engine/policy-engine.ts +95 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +75 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +23 -0
- package/openapi-client/index.ts +7 -0
- package/package.json +3 -2
- package/policies/schema.ts +266 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
- package/_types/accounts/types.d.ts.map +0 -1
- /package/_cjs/accounts/{types.js → evm/types.js} +0 -0
- /package/_esm/accounts/{types.js → evm/types.js} +0 -0
package/actions/evm/types.ts
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SendUserOperationOptions, SendUserOperationReturnType } from "./sendUserOperation.js";
|
|
2
|
+
import { GetUserOperationOptions, UserOperation } from "../../client/evm/evm.types.js";
|
|
3
|
+
import { EvmAccount, EvmSmartAccount } from "../../openapi-client/index.js";
|
|
2
4
|
|
|
3
|
-
import type {
|
|
5
|
+
import type { ListTokenBalancesOptions, ListTokenBalancesResult } from "./listTokenBalances.js";
|
|
4
6
|
import type { RequestFaucetOptions, RequestFaucetResult } from "./requestFaucet.js";
|
|
5
7
|
import type { SendTransactionOptions, TransactionResult } from "./sendTransaction.js";
|
|
6
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
AccountTransferOptions,
|
|
10
|
+
SmartAccountTransferOptions,
|
|
11
|
+
TransferResult,
|
|
12
|
+
} from "./transfer/types.js";
|
|
7
13
|
import type {
|
|
8
14
|
WaitForUserOperationOptions,
|
|
9
15
|
WaitForUserOperationReturnType,
|
|
10
16
|
} from "./waitForUserOperation.js";
|
|
11
|
-
|
|
17
|
+
|
|
18
|
+
type Actions<T extends EvmAccount | EvmSmartAccount> = {
|
|
12
19
|
/**
|
|
13
20
|
* Transfer an amount of a token from an account to another account.
|
|
14
21
|
*
|
|
@@ -92,7 +99,9 @@ export type Actions = {
|
|
|
92
99
|
* });
|
|
93
100
|
* ```
|
|
94
101
|
*/
|
|
95
|
-
transfer: (
|
|
102
|
+
transfer: (
|
|
103
|
+
options: T extends EvmSmartAccount ? SmartAccountTransferOptions : AccountTransferOptions,
|
|
104
|
+
) => Promise<TransferResult>;
|
|
96
105
|
|
|
97
106
|
/**
|
|
98
107
|
* List the token balances of an account.
|
|
@@ -132,7 +141,9 @@ export type Actions = {
|
|
|
132
141
|
* ```
|
|
133
142
|
*/
|
|
134
143
|
requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<RequestFaucetResult>;
|
|
144
|
+
};
|
|
135
145
|
|
|
146
|
+
export type AccountActions = Actions<EvmAccount> & {
|
|
136
147
|
/**
|
|
137
148
|
* Signs an EVM transaction and sends it to the specified network using the Coinbase API.
|
|
138
149
|
* This method handles nonce management and gas estimation automatically.
|
|
@@ -178,7 +189,9 @@ export type Actions = {
|
|
|
178
189
|
* ```
|
|
179
190
|
*/
|
|
180
191
|
sendTransaction: (options: Omit<SendTransactionOptions, "address">) => Promise<TransactionResult>;
|
|
192
|
+
};
|
|
181
193
|
|
|
194
|
+
export type SmartAccountActions = Actions<EvmSmartAccount> & {
|
|
182
195
|
/**
|
|
183
196
|
* Sends a user operation.
|
|
184
197
|
*
|
|
@@ -241,4 +254,23 @@ export type Actions = {
|
|
|
241
254
|
waitForUserOperation: (
|
|
242
255
|
options: Omit<WaitForUserOperationOptions, "smartAccountAddress">,
|
|
243
256
|
) => Promise<WaitForUserOperationReturnType>;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Gets a user operation by its hash.
|
|
260
|
+
*
|
|
261
|
+
* @param {GetUserOperationOptions} options - Parameters for getting the user operation.
|
|
262
|
+
* @param {string} options.userOpHash - The user operation hash.
|
|
263
|
+
*
|
|
264
|
+
* @returns A promise that resolves to the user operation.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const userOp = await smartAccount.getUserOperation({
|
|
269
|
+
* userOpHash: "0x1234567890123456789012345678901234567890",
|
|
270
|
+
* });
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
getUserOperation: (
|
|
274
|
+
options: Omit<GetUserOperationOptions, "smartAccount">,
|
|
275
|
+
) => Promise<UserOperation>;
|
|
244
276
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { RequestFaucetOptions, SignatureResult } from "../../client/solana/solana.types.js";
|
|
2
|
+
import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Requests funds from a Solana faucet.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client.
|
|
8
|
+
* @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
|
|
9
|
+
* @param {string} options.address - The address to request funds for.
|
|
10
|
+
* @param {string} options.token - The token to request funds for.
|
|
11
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
12
|
+
*
|
|
13
|
+
* @returns A promise that resolves to the transaction signature.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const signature = await requestFaucet(cdp.solana, {
|
|
18
|
+
* address: "1234567890123456789012345678901234567890",
|
|
19
|
+
* token: "sol",
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export async function requestFaucet(
|
|
24
|
+
apiClient: CdpOpenApiClientType,
|
|
25
|
+
options: RequestFaucetOptions,
|
|
26
|
+
): Promise<SignatureResult> {
|
|
27
|
+
const signature = await apiClient.requestSolanaFaucet(
|
|
28
|
+
{ address: options.address, token: options.token },
|
|
29
|
+
options.idempotencyKey,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
signature: signature.transactionSignature,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SignMessageOptions, SignatureResult } from "../../client/solana/solana.types.js";
|
|
2
|
+
import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sign a message.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client.
|
|
8
|
+
* @param {SignMessageOptions} options - Parameters for signing the message.
|
|
9
|
+
* @param {string} options.address - The address to sign the message for.
|
|
10
|
+
* @param {string} options.message - The message to sign.
|
|
11
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
12
|
+
*
|
|
13
|
+
* @returns A promise that resolves to the transaction signature.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const signature = await signMessage(cdp.solana, {
|
|
18
|
+
* address: "1234567890123456789012345678901234567890",
|
|
19
|
+
* message: "Hello, world!",
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export async function signMessage(
|
|
24
|
+
apiClient: CdpOpenApiClientType,
|
|
25
|
+
options: SignMessageOptions,
|
|
26
|
+
): Promise<SignatureResult> {
|
|
27
|
+
const signature = await apiClient.signSolanaMessage(
|
|
28
|
+
options.address,
|
|
29
|
+
{ message: options.message },
|
|
30
|
+
options.idempotencyKey,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
signature: signature.signature,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SignTransactionOptions, SignatureResult } from "../../client/solana/solana.types.js";
|
|
2
|
+
import { CdpOpenApiClientType } from "../../openapi-client/index.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Signs a transaction.
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient - The API client.
|
|
8
|
+
* @param {SignTransactionOptions} options - Parameters for signing the transaction.
|
|
9
|
+
* @param {string} options.address - The address to sign the transaction for.
|
|
10
|
+
* @param {string} options.transaction - The transaction to sign.
|
|
11
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
12
|
+
*
|
|
13
|
+
* @returns A promise that resolves to the signature.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Create a Solana account
|
|
18
|
+
* const account = await cdp.solana.createAccount();
|
|
19
|
+
*
|
|
20
|
+
* // Add your transaction instructions here
|
|
21
|
+
* const transaction = new Transaction()
|
|
22
|
+
*
|
|
23
|
+
* // Make sure to set requireAllSignatures to false, since signing will be done through the API
|
|
24
|
+
* const serializedTransaction = transaction.serialize({
|
|
25
|
+
* requireAllSignatures: false,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Base64 encode the serialized transaction
|
|
29
|
+
* const transaction = Buffer.from(serializedTransaction).toString("base64");
|
|
30
|
+
*
|
|
31
|
+
* // When you want to sign a transaction, you can do so by address and base64 encoded transaction
|
|
32
|
+
* const signature = await signTransaction(cdp.solana, {
|
|
33
|
+
* address: account.address,
|
|
34
|
+
* transaction,
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function signTransaction(
|
|
39
|
+
apiClient: CdpOpenApiClientType,
|
|
40
|
+
options: SignTransactionOptions,
|
|
41
|
+
): Promise<SignatureResult> {
|
|
42
|
+
const signature = await apiClient.signSolanaTransaction(
|
|
43
|
+
options.address,
|
|
44
|
+
{
|
|
45
|
+
transaction: options.transaction,
|
|
46
|
+
},
|
|
47
|
+
options.idempotencyKey,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
signature: signature.signedTransaction,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RequestFaucetOptions,
|
|
3
|
+
SignatureResult,
|
|
4
|
+
SignMessageOptions,
|
|
5
|
+
SignTransactionOptions,
|
|
6
|
+
} from "../../client/solana/solana.types.js";
|
|
7
|
+
|
|
8
|
+
export type AccountActions = {
|
|
9
|
+
/**
|
|
10
|
+
* Requests funds from a Solana faucet.
|
|
11
|
+
*
|
|
12
|
+
* @param {RequestFaucetOptions} options - Parameters for requesting funds from the Solana faucet.
|
|
13
|
+
* @param {string} options.token - The token to request funds for.
|
|
14
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
15
|
+
*
|
|
16
|
+
* @returns A promise that resolves to the transaction hash.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* // Create a Solana account
|
|
21
|
+
* const account = await cdp.solana.createAccount();
|
|
22
|
+
*
|
|
23
|
+
* // Request funds from the Solana faucet
|
|
24
|
+
* const result = await account.requestFaucet({
|
|
25
|
+
* token: "sol",
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
requestFaucet: (options: Omit<RequestFaucetOptions, "address">) => Promise<SignatureResult>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Signs a message.
|
|
33
|
+
*
|
|
34
|
+
* @param {SignMessageOptions} options - Parameters for signing the message.
|
|
35
|
+
* @param {string} options.address - The address to sign the message for.
|
|
36
|
+
* @param {string} options.message - The message to sign.
|
|
37
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
38
|
+
*
|
|
39
|
+
* @returns A promise that resolves to the signature.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // Create a Solana account
|
|
44
|
+
* const account = await cdp.solana.createAccount();
|
|
45
|
+
*
|
|
46
|
+
* // Sign a message
|
|
47
|
+
* const { signature } = await account.signMessage({
|
|
48
|
+
* message: "Hello, world!",
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
signMessage: (options: Omit<SignMessageOptions, "address">) => Promise<SignatureResult>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Signs a transaction.
|
|
56
|
+
*
|
|
57
|
+
* @param {SignTransactionOptions} options - Parameters for signing the transaction.
|
|
58
|
+
* @param {string} options.address - The address to sign the transaction for.
|
|
59
|
+
* @param {string} options.transaction - The transaction to sign.
|
|
60
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
61
|
+
*
|
|
62
|
+
* @returns A promise that resolves to the signature.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* // Create a Solana account
|
|
67
|
+
* const account = await cdp.solana.createAccount();
|
|
68
|
+
*
|
|
69
|
+
* // Add your transaction instructions here
|
|
70
|
+
* const transaction = new Transaction()
|
|
71
|
+
*
|
|
72
|
+
* // Make sure to set requireAllSignatures to false, since signing will be done through the API
|
|
73
|
+
* const serializedTransaction = transaction.serialize({
|
|
74
|
+
* requireAllSignatures: false,
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Base64 encode the serialized transaction
|
|
78
|
+
* const transaction = Buffer.from(serializedTransaction).toString("base64");
|
|
79
|
+
*
|
|
80
|
+
* // When you want to sign a transaction, you can do so by address and base64 encoded transaction
|
|
81
|
+
* const { signature } = await account.signTransaction({
|
|
82
|
+
* transaction,
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
signTransaction: (options: Omit<SignTransactionOptions, "address">) => Promise<SignatureResult>;
|
|
87
|
+
};
|
package/analytics.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import md5 from "md5";
|
|
2
2
|
|
|
3
|
+
import { APIError } from "./openapi-client/errors.js";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* The data in an error event
|
|
5
7
|
*/
|
|
@@ -22,24 +24,33 @@ type ErrorEventData = {
|
|
|
22
24
|
name: "error";
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
type EventData = ErrorEventData
|
|
26
|
-
apiKeyId: string;
|
|
27
|
-
};
|
|
27
|
+
type EventData = ErrorEventData;
|
|
28
28
|
|
|
29
29
|
// This is a public client id for the analytics service
|
|
30
30
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
31
31
|
|
|
32
|
+
export const Analytics = {
|
|
33
|
+
identifier: "", // set in cdp.ts
|
|
34
|
+
wrapClassWithErrorTracking,
|
|
35
|
+
wrapObjectMethodsWithErrorTracking,
|
|
36
|
+
sendEvent,
|
|
37
|
+
};
|
|
38
|
+
|
|
32
39
|
/**
|
|
33
40
|
* Sends an analytics event to the default endpoint
|
|
34
41
|
*
|
|
35
42
|
* @param event - The event data containing event-specific fields
|
|
36
43
|
* @returns Promise that resolves when the event is sent
|
|
37
44
|
*/
|
|
38
|
-
|
|
45
|
+
async function sendEvent(event: EventData): Promise<void> {
|
|
46
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
const timestamp = Date.now();
|
|
40
51
|
|
|
41
52
|
const enhancedEvent = {
|
|
42
|
-
user_id:
|
|
53
|
+
user_id: Analytics.identifier,
|
|
43
54
|
event_type: event.name,
|
|
44
55
|
platform: "server",
|
|
45
56
|
timestamp,
|
|
@@ -80,10 +91,13 @@ export async function sendEvent(event: EventData): Promise<void> {
|
|
|
80
91
|
* Wraps all methods of a class with error tracking.
|
|
81
92
|
*
|
|
82
93
|
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
83
|
-
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
84
94
|
*/
|
|
85
95
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
|
|
96
|
+
function wrapClassWithErrorTracking(ClassToWrap: any): void {
|
|
97
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
87
101
|
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(
|
|
88
102
|
name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function",
|
|
89
103
|
);
|
|
@@ -94,14 +108,13 @@ export function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string):
|
|
|
94
108
|
try {
|
|
95
109
|
return await originalMethod.apply(this, args);
|
|
96
110
|
} catch (error) {
|
|
97
|
-
if (!(error
|
|
98
|
-
|
|
111
|
+
if (!shouldTrackError(error)) {
|
|
112
|
+
throw error;
|
|
99
113
|
}
|
|
100
114
|
|
|
101
|
-
const { message, stack } = error;
|
|
115
|
+
const { message, stack } = error as Error;
|
|
102
116
|
|
|
103
117
|
sendEvent({
|
|
104
|
-
apiKeyId,
|
|
105
118
|
method,
|
|
106
119
|
message,
|
|
107
120
|
stack,
|
|
@@ -115,3 +128,63 @@ export function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string):
|
|
|
115
128
|
};
|
|
116
129
|
}
|
|
117
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Wraps all methods of an object with error tracking.
|
|
134
|
+
*
|
|
135
|
+
* @param object - The object whose methods should be wrapped.
|
|
136
|
+
*/
|
|
137
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
138
|
+
function wrapObjectMethodsWithErrorTracking(object: any): void {
|
|
139
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const methods = Object.getOwnPropertyNames(object).filter(
|
|
144
|
+
name => name !== "constructor" && typeof object[name] === "function",
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
for (const method of methods) {
|
|
148
|
+
const originalMethod = object[method];
|
|
149
|
+
object[method] = async function (...args: unknown[]) {
|
|
150
|
+
try {
|
|
151
|
+
return await originalMethod.apply(this, args);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (!shouldTrackError(error)) {
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { message, stack } = error as Error;
|
|
158
|
+
|
|
159
|
+
sendEvent({
|
|
160
|
+
method,
|
|
161
|
+
message,
|
|
162
|
+
stack,
|
|
163
|
+
name: "error",
|
|
164
|
+
}).catch(() => {
|
|
165
|
+
// ignore error
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Filters out non-errors and API errors
|
|
176
|
+
*
|
|
177
|
+
* @param error - The error to check.
|
|
178
|
+
* @returns True if the error should be tracked, false otherwise.
|
|
179
|
+
*/
|
|
180
|
+
function shouldTrackError(error: unknown): boolean {
|
|
181
|
+
if (!(error instanceof Error)) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (error instanceof APIError) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return true;
|
|
190
|
+
}
|
package/client/cdp.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Analytics } from "../analytics.js";
|
|
2
2
|
import { CdpOpenApiClient } from "../openapi-client/index.js";
|
|
3
3
|
import { version } from "../version.js";
|
|
4
4
|
import { EvmClient } from "./evm/evm.js";
|
|
5
|
+
import { PoliciesClient } from "./policies/policies.js";
|
|
5
6
|
import { SolanaClient } from "./solana/solana.js";
|
|
6
7
|
|
|
7
8
|
interface CdpClientOptions {
|
|
@@ -27,6 +28,9 @@ export class CdpClient {
|
|
|
27
28
|
/** Namespace containing all Solana methods. */
|
|
28
29
|
public solana: SolanaClient;
|
|
29
30
|
|
|
31
|
+
/** Namespace containing all Policies methods. */
|
|
32
|
+
public policies: PoliciesClient;
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* The CdpClient is the main class for interacting with the CDP API.
|
|
32
36
|
*
|
|
@@ -109,12 +113,15 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
109
113
|
});
|
|
110
114
|
|
|
111
115
|
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
112
|
-
|
|
113
|
-
wrapClassWithErrorTracking(
|
|
114
|
-
wrapClassWithErrorTracking(
|
|
116
|
+
Analytics.identifier = apiKeyId;
|
|
117
|
+
Analytics.wrapClassWithErrorTracking(CdpClient);
|
|
118
|
+
Analytics.wrapClassWithErrorTracking(EvmClient);
|
|
119
|
+
Analytics.wrapClassWithErrorTracking(SolanaClient);
|
|
120
|
+
Analytics.wrapClassWithErrorTracking(PoliciesClient);
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
this.evm = new EvmClient();
|
|
118
124
|
this.solana = new SolanaClient();
|
|
125
|
+
this.policies = new PoliciesClient();
|
|
119
126
|
}
|
|
120
127
|
}
|