@coinbase/cdp-sdk 1.25.0 → 1.27.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 +20 -0
- package/README.md +58 -2
- package/_cjs/accounts/evm/networkToChainResolver.js +68 -0
- package/_cjs/accounts/evm/networkToChainResolver.js.map +1 -0
- package/_cjs/accounts/evm/resolveViemClients.js +6 -32
- package/_cjs/accounts/evm/resolveViemClients.js.map +1 -1
- package/_cjs/accounts/evm/toEvmServerAccount.js +84 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +93 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +19 -7
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +65 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +20 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/fund/fund.js +3 -2
- package/_cjs/actions/evm/fund/fund.js.map +1 -1
- package/_cjs/actions/evm/fund/quoteFund.js +3 -2
- package/_cjs/actions/evm/fund/quoteFund.js.map +1 -1
- package/_cjs/actions/solana/sendTransaction.js +32 -0
- package/_cjs/actions/solana/sendTransaction.js.map +1 -0
- package/_cjs/analytics.js +39 -3
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/auth/utils/jwt.js +6 -5
- package/_cjs/auth/utils/jwt.js.map +1 -1
- package/_cjs/client/cdp.js +4 -1
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +116 -10
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +22 -0
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/client/solana/solana.js +85 -8
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/constants.js +1 -1
- package/_cjs/constants.js.map +1 -1
- package/_cjs/errors.js +19 -1
- package/_cjs/errors.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +46 -6
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/errors.js +38 -9
- package/_cjs/openapi-client/errors.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +6 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js +34 -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 +18 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/networkToChainResolver.js +31 -0
- package/_esm/accounts/evm/networkToChainResolver.js.map +1 -0
- package/_esm/accounts/evm/resolveViemClients.js +4 -30
- package/_esm/accounts/evm/resolveViemClients.js.map +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +84 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +93 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +19 -7
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +65 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +20 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/fund/fund.js +3 -2
- package/_esm/actions/evm/fund/fund.js.map +1 -1
- package/_esm/actions/evm/fund/quoteFund.js +3 -2
- package/_esm/actions/evm/fund/quoteFund.js.map +1 -1
- package/_esm/actions/solana/sendTransaction.js +29 -0
- package/_esm/actions/solana/sendTransaction.js.map +1 -0
- package/_esm/analytics.js +39 -3
- package/_esm/analytics.js.map +1 -1
- package/_esm/auth/utils/jwt.js +3 -2
- package/_esm/auth/utils/jwt.js.map +1 -1
- package/_esm/client/cdp.js +4 -1
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +110 -4
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +22 -0
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/client/solana/solana.js +82 -5
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/constants.js +1 -1
- package/_esm/constants.js.map +1 -1
- package/_esm/errors.js +17 -0
- package/_esm/errors.js.map +1 -1
- package/_esm/index.js +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/cdpApiClient.js +47 -7
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/errors.js +36 -8
- package/_esm/openapi-client/errors.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +5 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +32 -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 +15 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/networkToChainResolver.d.ts +14 -0
- package/_types/accounts/evm/networkToChainResolver.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.map +1 -1
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/evm/types.d.ts +3 -3
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/fund/fund.d.ts.map +1 -1
- package/_types/actions/evm/fund/quoteFund.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +36 -3
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/sendTransaction.d.ts +23 -0
- package/_types/actions/solana/sendTransaction.d.ts.map +1 -0
- package/_types/analytics.d.ts +36 -1
- package/_types/analytics.d.ts.map +1 -1
- 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 +1 -0
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +21 -2
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +22 -3
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/constants.d.ts +1 -1
- package/_types/constants.d.ts.map +1 -1
- package/_types/errors.d.ts +11 -0
- package/_types/errors.d.ts.map +1 -1
- package/_types/index.d.ts +1 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/errors.d.ts +46 -9
- package/_types/openapi-client/errors.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +18 -0
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts +27 -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 +3 -1
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +2 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/networkToChainResolver.ts +34 -0
- package/accounts/evm/resolveViemClients.ts +6 -32
- package/accounts/evm/toEvmServerAccount.ts +98 -0
- package/accounts/evm/toEvmSmartAccount.ts +114 -2
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +22 -8
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +75 -0
- package/accounts/evm/types.ts +3 -3
- package/accounts/solana/toSolanaAccount.ts +24 -0
- package/actions/evm/fund/fund.ts +3 -2
- package/actions/evm/fund/quoteFund.ts +3 -2
- package/actions/evm/types.ts +41 -2
- package/actions/solana/sendTransaction.ts +38 -0
- package/analytics.ts +73 -4
- package/auth/utils/jwt.ts +5 -2
- package/client/cdp.ts +7 -1
- package/client/evm/evm.ts +135 -6
- package/client/policies/policies.ts +28 -0
- package/client/solana/solana.ts +97 -5
- package/client/solana/solana.types.ts +25 -1
- package/constants.ts +1 -1
- package/errors.ts +18 -0
- package/index.ts +1 -0
- package/openapi-client/cdpApiClient.ts +87 -17
- package/openapi-client/errors.ts +65 -10
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +24 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +32 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +43 -0
- package/package.json +1 -1
- package/version.ts +1 -1
package/analytics.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import md5 from "md5";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { UserInputValidationError } from "./errors.js";
|
|
4
|
+
import { APIError, NetworkError } from "./openapi-client/errors.js";
|
|
4
5
|
import { version } from "./version.js";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -25,7 +26,29 @@ type ErrorEventData = {
|
|
|
25
26
|
name: "error";
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The data in an action event
|
|
31
|
+
*/
|
|
32
|
+
type ActionEventData = {
|
|
33
|
+
/**
|
|
34
|
+
* The operation being performed, e.g. "transfer", "swap", "fund", "requestFaucet"
|
|
35
|
+
*/
|
|
36
|
+
action: string;
|
|
37
|
+
/**
|
|
38
|
+
* The account type, e.g. "evm-server", "evm-smart", "solana"
|
|
39
|
+
*/
|
|
40
|
+
accountType?: "evm_server" | "evm_smart" | "solana";
|
|
41
|
+
/**
|
|
42
|
+
* Additional properties specific to the action
|
|
43
|
+
*/
|
|
44
|
+
properties?: Record<string, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* The name of the event
|
|
47
|
+
*/
|
|
48
|
+
name: "action";
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type EventData = ErrorEventData | ActionEventData;
|
|
29
52
|
|
|
30
53
|
// This is a public client id for the analytics service
|
|
31
54
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
@@ -35,6 +58,7 @@ export const Analytics = {
|
|
|
35
58
|
wrapClassWithErrorTracking,
|
|
36
59
|
wrapObjectMethodsWithErrorTracking,
|
|
37
60
|
sendEvent,
|
|
61
|
+
trackAction,
|
|
38
62
|
};
|
|
39
63
|
|
|
40
64
|
/**
|
|
@@ -44,7 +68,11 @@ export const Analytics = {
|
|
|
44
68
|
* @returns Promise that resolves when the event is sent
|
|
45
69
|
*/
|
|
46
70
|
async function sendEvent(event: EventData): Promise<void> {
|
|
47
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
71
|
+
if (event.name === "error" && process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (event.name !== "error" && process.env.DISABLE_CDP_USAGE_TRACKING === "true") {
|
|
48
76
|
return;
|
|
49
77
|
}
|
|
50
78
|
|
|
@@ -89,6 +117,39 @@ async function sendEvent(event: EventData): Promise<void> {
|
|
|
89
117
|
});
|
|
90
118
|
}
|
|
91
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Track an action being performed
|
|
122
|
+
*
|
|
123
|
+
* @param params - The parameters for tracking an action
|
|
124
|
+
* @param params.action - The action being performed
|
|
125
|
+
* @param params.accountType - The type of account
|
|
126
|
+
* @param params.properties - Additional properties
|
|
127
|
+
*/
|
|
128
|
+
function trackAction(params: {
|
|
129
|
+
action: string;
|
|
130
|
+
accountType?: "evm_server" | "evm_smart" | "solana";
|
|
131
|
+
properties?: Record<string, unknown>;
|
|
132
|
+
}): void {
|
|
133
|
+
if (
|
|
134
|
+
params.properties?.network &&
|
|
135
|
+
typeof params.properties.network === "string" &&
|
|
136
|
+
params.properties.network.startsWith("http")
|
|
137
|
+
) {
|
|
138
|
+
const url = new URL(params.properties.network);
|
|
139
|
+
params.properties.customRpcHost = url.hostname;
|
|
140
|
+
params.properties.network = "custom";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
sendEvent({
|
|
144
|
+
action: params.action,
|
|
145
|
+
accountType: params.accountType,
|
|
146
|
+
properties: params.properties,
|
|
147
|
+
name: "action",
|
|
148
|
+
}).catch(() => {
|
|
149
|
+
// ignore error
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
92
153
|
/**
|
|
93
154
|
* Wraps all methods of a class with error tracking.
|
|
94
155
|
*
|
|
@@ -184,7 +245,15 @@ function shouldTrackError(error: unknown): boolean {
|
|
|
184
245
|
return false;
|
|
185
246
|
}
|
|
186
247
|
|
|
187
|
-
if (error instanceof
|
|
248
|
+
if (error instanceof UserInputValidationError) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (error instanceof NetworkError) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (error instanceof APIError && error.errorType !== "unexpected_error") {
|
|
188
257
|
return false;
|
|
189
258
|
}
|
|
190
259
|
|
package/auth/utils/jwt.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { SignJWT, importPKCS8, importJWK, JWTPayload } from "jose";
|
|
|
2
2
|
import { getRandomValues } from "uncrypto";
|
|
3
3
|
|
|
4
4
|
import { authHash } from "./hash.js";
|
|
5
|
+
import { UserInputValidationError } from "../../errors.js";
|
|
5
6
|
import { sortKeys } from "../../utils/sortKeys.js";
|
|
6
7
|
import { InvalidWalletSecretFormatError, UndefinedWalletSecretError } from "../errors.js";
|
|
7
8
|
|
|
@@ -164,7 +165,9 @@ export async function generateJwt(options: JwtOptions): Promise<string> {
|
|
|
164
165
|
randomNonce,
|
|
165
166
|
);
|
|
166
167
|
} else {
|
|
167
|
-
throw new
|
|
168
|
+
throw new UserInputValidationError(
|
|
169
|
+
"Invalid key format - must be either PEM EC key or base64 Ed25519 key",
|
|
170
|
+
);
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -306,7 +309,7 @@ async function buildEdwardsJWT(
|
|
|
306
309
|
// Decode the base64 key (expecting 64 bytes: 32 for seed + 32 for public key)
|
|
307
310
|
const decoded = Buffer.from(privateKey, "base64");
|
|
308
311
|
if (decoded.length !== 64) {
|
|
309
|
-
throw new
|
|
312
|
+
throw new UserInputValidationError("Invalid Ed25519 key length");
|
|
310
313
|
}
|
|
311
314
|
|
|
312
315
|
const seed = decoded.subarray(0, 32);
|
package/client/cdp.ts
CHANGED
|
@@ -121,8 +121,14 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
121
121
|
sourceVersion: version,
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
process.env.DISABLE_CDP_ERROR_REPORTING !== "true" ||
|
|
126
|
+
process.env.DISABLE_CDP_USAGE_TRACKING !== "true"
|
|
127
|
+
) {
|
|
125
128
|
Analytics.identifier = apiKeyId;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING !== "true") {
|
|
126
132
|
Analytics.wrapClassWithErrorTracking(CdpClient);
|
|
127
133
|
Analytics.wrapClassWithErrorTracking(EvmClient);
|
|
128
134
|
Analytics.wrapClassWithErrorTracking(SolanaClient);
|
package/client/evm/evm.ts
CHANGED
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
} from "../../actions/evm/waitForUserOperation.js";
|
|
63
63
|
import { Analytics } from "../../analytics.js";
|
|
64
64
|
import { ImportAccountPublicRSAKey } from "../../constants.js";
|
|
65
|
+
import { UserInputValidationError } from "../../errors.js";
|
|
65
66
|
import { APIError } from "../../openapi-client/errors.js";
|
|
66
67
|
import {
|
|
67
68
|
CdpOpenApiClient,
|
|
@@ -114,6 +115,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
114
115
|
* ```
|
|
115
116
|
*/
|
|
116
117
|
async createAccount(options: CreateServerAccountOptions = {}): Promise<ServerAccount> {
|
|
118
|
+
Analytics.trackAction({
|
|
119
|
+
action: "create_account",
|
|
120
|
+
accountType: "evm_server",
|
|
121
|
+
});
|
|
122
|
+
|
|
117
123
|
const openApiAccount = await CdpOpenApiClient.createEvmAccount(
|
|
118
124
|
{
|
|
119
125
|
name: options.name,
|
|
@@ -174,6 +180,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
174
180
|
* ```
|
|
175
181
|
*/
|
|
176
182
|
async importAccount(options: ImportServerAccountOptions): Promise<ServerAccount> {
|
|
183
|
+
Analytics.trackAction({
|
|
184
|
+
action: "import_account",
|
|
185
|
+
accountType: "evm_server",
|
|
186
|
+
});
|
|
187
|
+
|
|
177
188
|
const encryptionPublicKey = options.encryptionPublicKey || ImportAccountPublicRSAKey;
|
|
178
189
|
|
|
179
190
|
const privateKeyHex = options.privateKey.startsWith("0x")
|
|
@@ -181,7 +192,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
181
192
|
: options.privateKey;
|
|
182
193
|
|
|
183
194
|
if (!/^[0-9a-fA-F]+$/.test(privateKeyHex)) {
|
|
184
|
-
throw new
|
|
195
|
+
throw new UserInputValidationError("Private key must be a valid hexadecimal string");
|
|
185
196
|
}
|
|
186
197
|
|
|
187
198
|
try {
|
|
@@ -245,6 +256,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
245
256
|
* ```
|
|
246
257
|
*/
|
|
247
258
|
async exportAccount(options: ExportServerAccountOptions): Promise<string> {
|
|
259
|
+
Analytics.trackAction({
|
|
260
|
+
action: "export_account",
|
|
261
|
+
accountType: "evm_server",
|
|
262
|
+
});
|
|
263
|
+
|
|
248
264
|
const { publicKey, privateKey } = await generateExportEncryptionKeyPair();
|
|
249
265
|
|
|
250
266
|
const { encryptedPrivateKey } = await (async () => {
|
|
@@ -268,7 +284,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
268
284
|
);
|
|
269
285
|
}
|
|
270
286
|
|
|
271
|
-
throw new
|
|
287
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
272
288
|
})();
|
|
273
289
|
|
|
274
290
|
return decryptWithPrivateKey(privateKey, encryptedPrivateKey);
|
|
@@ -320,6 +336,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
320
336
|
* ```
|
|
321
337
|
*/
|
|
322
338
|
async createSmartAccount(options: CreateSmartAccountOptions): Promise<SmartAccount> {
|
|
339
|
+
Analytics.trackAction({
|
|
340
|
+
action: "create_smart_account",
|
|
341
|
+
accountType: "evm_smart",
|
|
342
|
+
});
|
|
343
|
+
|
|
323
344
|
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
324
345
|
{
|
|
325
346
|
owners: [options.owner.address],
|
|
@@ -364,6 +385,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
364
385
|
* ```
|
|
365
386
|
*/
|
|
366
387
|
async getAccount(options: GetServerAccountOptions): Promise<ServerAccount> {
|
|
388
|
+
Analytics.trackAction({
|
|
389
|
+
action: "get_account",
|
|
390
|
+
accountType: "evm_server",
|
|
391
|
+
});
|
|
392
|
+
|
|
367
393
|
const openApiAccount = await (() => {
|
|
368
394
|
if (options.address) {
|
|
369
395
|
return CdpOpenApiClient.getEvmAccount(options.address);
|
|
@@ -373,7 +399,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
373
399
|
return CdpOpenApiClient.getEvmAccountByName(options.name);
|
|
374
400
|
}
|
|
375
401
|
|
|
376
|
-
throw new
|
|
402
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
377
403
|
})();
|
|
378
404
|
|
|
379
405
|
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
@@ -408,13 +434,17 @@ export class EvmClient implements EvmClientInterface {
|
|
|
408
434
|
* ```
|
|
409
435
|
*/
|
|
410
436
|
async getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount> {
|
|
437
|
+
Analytics.trackAction({
|
|
438
|
+
action: "get_smart_account",
|
|
439
|
+
});
|
|
440
|
+
|
|
411
441
|
const openApiSmartAccount = await (async () => {
|
|
412
442
|
if (options.address) {
|
|
413
443
|
return CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
414
444
|
} else if (options.name) {
|
|
415
445
|
return CdpOpenApiClient.getEvmSmartAccountByName(options.name);
|
|
416
446
|
}
|
|
417
|
-
throw new
|
|
447
|
+
throw new UserInputValidationError("Either address or name must be provided");
|
|
418
448
|
})();
|
|
419
449
|
|
|
420
450
|
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
@@ -443,6 +473,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
443
473
|
* ```
|
|
444
474
|
*/
|
|
445
475
|
async getOrCreateAccount(options: GetOrCreateServerAccountOptions): Promise<ServerAccount> {
|
|
476
|
+
Analytics.trackAction({
|
|
477
|
+
action: "get_or_create_account",
|
|
478
|
+
accountType: "evm_server",
|
|
479
|
+
});
|
|
480
|
+
|
|
446
481
|
try {
|
|
447
482
|
const account = await this.getAccount(options);
|
|
448
483
|
return account;
|
|
@@ -463,7 +498,6 @@ export class EvmClient implements EvmClientInterface {
|
|
|
463
498
|
throw error;
|
|
464
499
|
}
|
|
465
500
|
}
|
|
466
|
-
|
|
467
501
|
throw error;
|
|
468
502
|
}
|
|
469
503
|
}
|
|
@@ -488,6 +522,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
488
522
|
* ```
|
|
489
523
|
*/
|
|
490
524
|
async getOrCreateSmartAccount(options: GetOrCreateSmartAccountOptions): Promise<SmartAccount> {
|
|
525
|
+
Analytics.trackAction({
|
|
526
|
+
action: "get_or_create_smart_account",
|
|
527
|
+
accountType: "evm_smart",
|
|
528
|
+
});
|
|
529
|
+
|
|
491
530
|
try {
|
|
492
531
|
const account = await this.getSmartAccount(options);
|
|
493
532
|
return account;
|
|
@@ -508,7 +547,6 @@ export class EvmClient implements EvmClientInterface {
|
|
|
508
547
|
throw error;
|
|
509
548
|
}
|
|
510
549
|
}
|
|
511
|
-
|
|
512
550
|
throw error;
|
|
513
551
|
}
|
|
514
552
|
}
|
|
@@ -534,6 +572,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
534
572
|
async getSwapPrice(
|
|
535
573
|
options: GetSwapPriceOptions,
|
|
536
574
|
): Promise<GetSwapPriceResult | SwapUnavailableResult> {
|
|
575
|
+
Analytics.trackAction({
|
|
576
|
+
action: "get_swap_price",
|
|
577
|
+
properties: {
|
|
578
|
+
network: options.network,
|
|
579
|
+
},
|
|
580
|
+
});
|
|
581
|
+
|
|
537
582
|
return getSwapPrice(CdpOpenApiClient, options);
|
|
538
583
|
}
|
|
539
584
|
|
|
@@ -558,6 +603,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
558
603
|
async createSwapQuote(
|
|
559
604
|
options: CreateSwapQuoteOptions,
|
|
560
605
|
): Promise<CreateSwapQuoteResult | SwapUnavailableResult> {
|
|
606
|
+
Analytics.trackAction({
|
|
607
|
+
action: "create_swap_quote",
|
|
608
|
+
properties: {
|
|
609
|
+
network: options.network,
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
|
|
561
613
|
return createSwapQuote(CdpOpenApiClient, options);
|
|
562
614
|
}
|
|
563
615
|
|
|
@@ -579,6 +631,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
579
631
|
* ```
|
|
580
632
|
*/
|
|
581
633
|
async getUserOperation(options: GetUserOperationOptions): Promise<UserOperation> {
|
|
634
|
+
Analytics.trackAction({
|
|
635
|
+
action: "get_user_operation",
|
|
636
|
+
});
|
|
637
|
+
|
|
582
638
|
return getUserOperation(CdpOpenApiClient, options);
|
|
583
639
|
}
|
|
584
640
|
|
|
@@ -607,6 +663,11 @@ export class EvmClient implements EvmClientInterface {
|
|
|
607
663
|
* ```
|
|
608
664
|
*/
|
|
609
665
|
async listAccounts(options: ListServerAccountsOptions = {}): Promise<ListServerAccountResult> {
|
|
666
|
+
Analytics.trackAction({
|
|
667
|
+
action: "list_accounts",
|
|
668
|
+
accountType: "evm_server",
|
|
669
|
+
});
|
|
670
|
+
|
|
610
671
|
const ethAccounts = await CdpOpenApiClient.listEvmAccounts({
|
|
611
672
|
pageSize: options.pageSize,
|
|
612
673
|
pageToken: options.pageToken,
|
|
@@ -661,6 +722,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
661
722
|
* }
|
|
662
723
|
*/
|
|
663
724
|
async listTokenBalances(options: ListTokenBalancesOptions): Promise<ListTokenBalancesResult> {
|
|
725
|
+
Analytics.trackAction({
|
|
726
|
+
action: "list_token_balances",
|
|
727
|
+
properties: {
|
|
728
|
+
network: options.network,
|
|
729
|
+
},
|
|
730
|
+
});
|
|
731
|
+
|
|
664
732
|
return listTokenBalances(CdpOpenApiClient, options);
|
|
665
733
|
}
|
|
666
734
|
|
|
@@ -686,8 +754,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
686
754
|
* while (page.nextPageToken) {
|
|
687
755
|
* page = await cdp.evm.listSmartAccounts({ pageToken: page.nextPageToken });
|
|
688
756
|
* }
|
|
757
|
+
* ```
|
|
689
758
|
*/
|
|
690
759
|
async listSmartAccounts(options: ListSmartAccountsOptions = {}): Promise<ListSmartAccountResult> {
|
|
760
|
+
Analytics.trackAction({
|
|
761
|
+
action: "list_smart_accounts",
|
|
762
|
+
});
|
|
763
|
+
|
|
691
764
|
const smartAccounts = await CdpOpenApiClient.listEvmSmartAccounts({
|
|
692
765
|
pageSize: options.pageSize,
|
|
693
766
|
pageToken: options.pageToken,
|
|
@@ -731,6 +804,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
731
804
|
* ```
|
|
732
805
|
*/
|
|
733
806
|
async prepareUserOperation(options: PrepareUserOperationOptions): Promise<UserOperation> {
|
|
807
|
+
Analytics.trackAction({
|
|
808
|
+
action: "prepare_user_operation",
|
|
809
|
+
properties: {
|
|
810
|
+
network: options.network,
|
|
811
|
+
},
|
|
812
|
+
});
|
|
813
|
+
|
|
734
814
|
const userOp = await CdpOpenApiClient.prepareUserOperation(options.smartAccount.address, {
|
|
735
815
|
network: options.network,
|
|
736
816
|
calls: options.calls.map(call => ({
|
|
@@ -774,6 +854,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
774
854
|
* ```
|
|
775
855
|
*/
|
|
776
856
|
async requestFaucet(options: RequestFaucetOptions): Promise<RequestFaucetResult> {
|
|
857
|
+
Analytics.trackAction({
|
|
858
|
+
action: "request_faucet",
|
|
859
|
+
properties: {
|
|
860
|
+
network: options.network,
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
|
|
777
864
|
return requestFaucet(CdpOpenApiClient, options);
|
|
778
865
|
}
|
|
779
866
|
|
|
@@ -824,6 +911,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
824
911
|
* ```
|
|
825
912
|
*/
|
|
826
913
|
async sendTransaction(options: SendTransactionOptions): Promise<TransactionResult> {
|
|
914
|
+
Analytics.trackAction({
|
|
915
|
+
action: "send_transaction",
|
|
916
|
+
properties: {
|
|
917
|
+
network: options.network,
|
|
918
|
+
},
|
|
919
|
+
});
|
|
920
|
+
|
|
827
921
|
return sendTransaction(CdpOpenApiClient, options);
|
|
828
922
|
}
|
|
829
923
|
|
|
@@ -858,6 +952,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
858
952
|
async sendUserOperation(
|
|
859
953
|
options: SendUserOperationOptions<unknown[]>,
|
|
860
954
|
): Promise<SendUserOperationReturnType> {
|
|
955
|
+
Analytics.trackAction({
|
|
956
|
+
action: "send_user_operation",
|
|
957
|
+
properties: {
|
|
958
|
+
network: options.network,
|
|
959
|
+
},
|
|
960
|
+
});
|
|
961
|
+
|
|
861
962
|
return sendUserOperation(CdpOpenApiClient, {
|
|
862
963
|
smartAccount: options.smartAccount,
|
|
863
964
|
network: options.network,
|
|
@@ -889,6 +990,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
889
990
|
* ```
|
|
890
991
|
*/
|
|
891
992
|
async signHash(options: SignHashOptions): Promise<SignatureResult> {
|
|
993
|
+
Analytics.trackAction({
|
|
994
|
+
action: "sign_hash",
|
|
995
|
+
});
|
|
996
|
+
|
|
892
997
|
const signature = await CdpOpenApiClient.signEvmHash(
|
|
893
998
|
options.address,
|
|
894
999
|
{
|
|
@@ -924,6 +1029,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
924
1029
|
* ```
|
|
925
1030
|
*/
|
|
926
1031
|
async signMessage(options: SignMessageOptions): Promise<SignatureResult> {
|
|
1032
|
+
Analytics.trackAction({
|
|
1033
|
+
action: "sign_message",
|
|
1034
|
+
});
|
|
1035
|
+
|
|
927
1036
|
const signature = await CdpOpenApiClient.signEvmMessage(
|
|
928
1037
|
options.address,
|
|
929
1038
|
{
|
|
@@ -983,6 +1092,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
983
1092
|
* ```
|
|
984
1093
|
*/
|
|
985
1094
|
async signTypedData(options: SignTypedDataOptions): Promise<SignatureResult> {
|
|
1095
|
+
Analytics.trackAction({
|
|
1096
|
+
action: "sign_typed_data",
|
|
1097
|
+
});
|
|
1098
|
+
|
|
986
1099
|
const { domain, message, primaryType } = options;
|
|
987
1100
|
const types = {
|
|
988
1101
|
EIP712Domain: getTypesForEIP712Domain({ domain }),
|
|
@@ -1038,6 +1151,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1038
1151
|
* ```
|
|
1039
1152
|
*/
|
|
1040
1153
|
async signTransaction(options: SignTransactionOptions): Promise<SignatureResult> {
|
|
1154
|
+
Analytics.trackAction({
|
|
1155
|
+
action: "sign_transaction",
|
|
1156
|
+
});
|
|
1157
|
+
|
|
1041
1158
|
const signature = await CdpOpenApiClient.signEvmTransaction(
|
|
1042
1159
|
options.address,
|
|
1043
1160
|
{
|
|
@@ -1093,6 +1210,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1093
1210
|
* ```
|
|
1094
1211
|
*/
|
|
1095
1212
|
async updateAccount(options: UpdateEvmAccountOptions): Promise<ServerAccount> {
|
|
1213
|
+
Analytics.trackAction({
|
|
1214
|
+
action: "update_account",
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1096
1217
|
const openApiAccount = await CdpOpenApiClient.updateEvmAccount(
|
|
1097
1218
|
options.address,
|
|
1098
1219
|
options.update,
|
|
@@ -1121,6 +1242,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1121
1242
|
* @returns A promise that resolves to the updated account.
|
|
1122
1243
|
*/
|
|
1123
1244
|
async updateSmartAccount(options: UpdateEvmSmartAccountOptions): Promise<SmartAccount> {
|
|
1245
|
+
Analytics.trackAction({
|
|
1246
|
+
action: "update_smart_account",
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1124
1249
|
const openApiSmartAccount = await CdpOpenApiClient.updateEvmSmartAccount(
|
|
1125
1250
|
options.address,
|
|
1126
1251
|
options.update,
|
|
@@ -1172,6 +1297,10 @@ export class EvmClient implements EvmClientInterface {
|
|
|
1172
1297
|
async waitForUserOperation(
|
|
1173
1298
|
options: WaitForUserOperationOptions,
|
|
1174
1299
|
): Promise<WaitForUserOperationReturnType> {
|
|
1300
|
+
Analytics.trackAction({
|
|
1301
|
+
action: "wait_for_user_operation",
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1175
1304
|
return waitForUserOperation(CdpOpenApiClient, {
|
|
1176
1305
|
...options,
|
|
1177
1306
|
});
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
DeletePolicyOptions,
|
|
8
8
|
UpdatePolicyOptions,
|
|
9
9
|
} from "./policies.types.js";
|
|
10
|
+
import { Analytics } from "../../analytics.js";
|
|
10
11
|
import {
|
|
11
12
|
CdpOpenApiClient,
|
|
12
13
|
CreatePolicyBody,
|
|
@@ -57,6 +58,13 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
57
58
|
* ```
|
|
58
59
|
*/
|
|
59
60
|
async listPolicies(options: ListPoliciesOptions = {}): Promise<ListPoliciesResult> {
|
|
61
|
+
Analytics.trackAction({
|
|
62
|
+
action: "list_policies",
|
|
63
|
+
properties: {
|
|
64
|
+
scope: options.scope,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
60
68
|
return CdpOpenApiClient.listPolicies(options) as Promise<ListPoliciesResult>;
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -129,10 +137,18 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
129
137
|
* ```
|
|
130
138
|
*/
|
|
131
139
|
async createPolicy(options: CreatePolicyOptions): Promise<Policy> {
|
|
140
|
+
Analytics.trackAction({
|
|
141
|
+
action: "create_policy",
|
|
142
|
+
properties: {
|
|
143
|
+
scope: options.policy.scope,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
132
147
|
CreatePolicyBodySchema.parse(options.policy);
|
|
133
148
|
return CdpOpenApiClient.createPolicy(
|
|
134
149
|
// There are arbitrary differences between the abitype Abi and the openapi Abi
|
|
135
150
|
options.policy as CreatePolicyBody,
|
|
151
|
+
|
|
136
152
|
options.idempotencyKey,
|
|
137
153
|
) as Promise<Policy>;
|
|
138
154
|
}
|
|
@@ -156,6 +172,10 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
156
172
|
* ```
|
|
157
173
|
*/
|
|
158
174
|
async getPolicyById(options: GetPolicyByIdOptions): Promise<Policy> {
|
|
175
|
+
Analytics.trackAction({
|
|
176
|
+
action: "get_policy_by_id",
|
|
177
|
+
});
|
|
178
|
+
|
|
159
179
|
return CdpOpenApiClient.getPolicyById(options.id) as Promise<Policy>;
|
|
160
180
|
}
|
|
161
181
|
|
|
@@ -188,6 +208,10 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
188
208
|
* ```
|
|
189
209
|
*/
|
|
190
210
|
async deletePolicy(options: DeletePolicyOptions): Promise<void> {
|
|
211
|
+
Analytics.trackAction({
|
|
212
|
+
action: "delete_policy",
|
|
213
|
+
});
|
|
214
|
+
|
|
191
215
|
return CdpOpenApiClient.deletePolicy(options.id, options.idempotencyKey);
|
|
192
216
|
}
|
|
193
217
|
|
|
@@ -244,6 +268,10 @@ export class PoliciesClient implements PoliciesClientInterface {
|
|
|
244
268
|
* ```
|
|
245
269
|
*/
|
|
246
270
|
async updatePolicy(options: UpdatePolicyOptions): Promise<Policy> {
|
|
271
|
+
Analytics.trackAction({
|
|
272
|
+
action: "update_policy",
|
|
273
|
+
});
|
|
274
|
+
|
|
247
275
|
UpdatePolicyBodySchema.parse(options.policy);
|
|
248
276
|
return CdpOpenApiClient.updatePolicy(
|
|
249
277
|
options.id,
|