@coinbase/cdp-sdk 1.7.0 → 1.9.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 +326 -28
- package/_cjs/accounts/evm/toEvmServerAccount.js +4 -2
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +8 -0
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js +30 -63
- package/_cjs/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_cjs/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_cjs/actions/evm/transfer/transfer.js +2 -39
- package/_cjs/actions/evm/transfer/transfer.js.map +1 -1
- package/_cjs/actions/evm/transfer/utils.js +0 -12
- package/_cjs/actions/evm/transfer/utils.js.map +1 -1
- package/_cjs/actions/solana/constants.js +9 -0
- package/_cjs/actions/solana/constants.js.map +1 -0
- package/_cjs/actions/solana/transfer.js +117 -0
- package/_cjs/actions/solana/transfer.js.map +1 -0
- package/_cjs/actions/solana/utils.js +66 -0
- package/_cjs/actions/solana/utils.js.map +1 -0
- package/_cjs/analytics.js +70 -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 +133 -15
- 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 +76 -19
- 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 +35 -4
- 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 +2 -2
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +121 -36
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- 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 +6 -1
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/policies/schema.js +245 -0
- package/_cjs/policies/schema.js.map +1 -0
- package/_cjs/policies/types.js +3 -0
- package/_cjs/policies/types.js.map +1 -0
- 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.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +8 -0
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/transfer/accountTransferStrategy.js +31 -64
- package/_esm/actions/evm/transfer/accountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js +39 -56
- package/_esm/actions/evm/transfer/smartAccountTransferStrategy.js.map +1 -1
- package/_esm/actions/evm/transfer/transfer.js +2 -39
- package/_esm/actions/evm/transfer/transfer.js.map +1 -1
- package/_esm/actions/evm/transfer/utils.js +0 -11
- package/_esm/actions/evm/transfer/utils.js.map +1 -1
- package/_esm/actions/solana/constants.js +6 -0
- package/_esm/actions/solana/constants.js.map +1 -0
- package/_esm/actions/solana/transfer.js +114 -0
- package/_esm/actions/solana/transfer.js.map +1 -0
- package/_esm/actions/solana/utils.js +61 -0
- package/_esm/actions/solana/utils.js.map +1 -0
- package/_esm/analytics.js +70 -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 +133 -15
- 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 +76 -19
- 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 +34 -3
- 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 +2 -2
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +116 -35
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- 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 +5 -0
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/policies/schema.js +242 -0
- package/_esm/policies/schema.js.map +1 -0
- package/_esm/policies/types.js +2 -0
- package/_esm/policies/types.js.map +1 -0
- 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/evm/types.d.ts +6 -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/transfer/accountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/accountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts +2 -2
- package/_types/actions/evm/transfer/smartAccountTransferStrategy.d.ts.map +1 -1
- package/_types/actions/evm/transfer/transfer.d.ts +6 -4
- package/_types/actions/evm/transfer/transfer.d.ts.map +1 -1
- package/_types/actions/evm/transfer/types.d.ts +8 -54
- package/_types/actions/evm/transfer/types.d.ts.map +1 -1
- package/_types/actions/evm/transfer/utils.d.ts +0 -619
- package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +140 -68
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/actions/solana/constants.d.ts +6 -0
- package/_types/actions/solana/constants.d.ts.map +1 -0
- package/_types/actions/solana/transfer.d.ts +36 -0
- package/_types/actions/solana/transfer.d.ts.map +1 -0
- package/_types/actions/solana/types.d.ts +27 -0
- package/_types/actions/solana/types.d.ts.map +1 -1
- package/_types/actions/solana/utils.d.ts +34 -0
- package/_types/actions/solana/utils.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 +33 -3
- 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 +43 -1
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +14 -2
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +176 -17
- 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 +2 -2
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +5 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts.map +1 -1
- 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 +18 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +1552 -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 +11 -7
- package/accounts/evm/toEvmSmartAccount.ts +1 -2
- package/accounts/evm/types.ts +6 -8
- package/accounts/solana/toSolanaAccount.ts +8 -0
- package/actions/evm/transfer/accountTransferStrategy.ts +38 -78
- package/actions/evm/transfer/smartAccountTransferStrategy.ts +43 -63
- package/actions/evm/transfer/transfer.ts +10 -51
- package/actions/evm/transfer/types.ts +9 -67
- package/actions/evm/transfer/utils.ts +0 -13
- package/actions/evm/types.ts +143 -78
- package/actions/solana/constants.ts +6 -0
- package/actions/solana/transfer.ts +219 -0
- package/actions/solana/types.ts +28 -0
- package/actions/solana/utils.ts +79 -0
- package/analytics.ts +86 -11
- package/client/cdp.ts +11 -4
- package/client/evm/evm.ts +159 -17
- package/client/evm/evm.types.ts +38 -1
- 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 +94 -20
- package/client/solana/solana.types.ts +16 -1
- package/index.ts +7 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +220 -18
- 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 +2 -2
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +199 -56
- 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 +6 -0
- package/package.json +4 -2
- package/policies/schema.ts +349 -0
- package/policies/types.ts +19 -0
- package/types/misc.ts +41 -0
- package/version.ts +1 -1
package/analytics.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import md5 from "md5";
|
|
2
2
|
|
|
3
|
+
import { APIError } from "./openapi-client/errors.js";
|
|
4
|
+
import { version } from "./version.js";
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* The data in an error event
|
|
5
8
|
*/
|
|
@@ -22,30 +25,40 @@ type ErrorEventData = {
|
|
|
22
25
|
name: "error";
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
type EventData = ErrorEventData
|
|
26
|
-
apiKeyId: string;
|
|
27
|
-
};
|
|
28
|
+
type EventData = ErrorEventData;
|
|
28
29
|
|
|
29
30
|
// This is a public client id for the analytics service
|
|
30
31
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
31
32
|
|
|
33
|
+
export const Analytics = {
|
|
34
|
+
identifier: "", // set in cdp.ts
|
|
35
|
+
wrapClassWithErrorTracking,
|
|
36
|
+
wrapObjectMethodsWithErrorTracking,
|
|
37
|
+
sendEvent,
|
|
38
|
+
};
|
|
39
|
+
|
|
32
40
|
/**
|
|
33
41
|
* Sends an analytics event to the default endpoint
|
|
34
42
|
*
|
|
35
43
|
* @param event - The event data containing event-specific fields
|
|
36
44
|
* @returns Promise that resolves when the event is sent
|
|
37
45
|
*/
|
|
38
|
-
|
|
46
|
+
async function sendEvent(event: EventData): Promise<void> {
|
|
47
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
const timestamp = Date.now();
|
|
40
52
|
|
|
41
53
|
const enhancedEvent = {
|
|
42
|
-
user_id:
|
|
54
|
+
user_id: Analytics.identifier,
|
|
43
55
|
event_type: event.name,
|
|
44
56
|
platform: "server",
|
|
45
57
|
timestamp,
|
|
46
58
|
event_properties: {
|
|
47
59
|
project_name: "cdp-sdk",
|
|
48
60
|
cdp_sdk_language: "typescript",
|
|
61
|
+
version,
|
|
49
62
|
...event,
|
|
50
63
|
},
|
|
51
64
|
};
|
|
@@ -80,10 +93,13 @@ export async function sendEvent(event: EventData): Promise<void> {
|
|
|
80
93
|
* Wraps all methods of a class with error tracking.
|
|
81
94
|
*
|
|
82
95
|
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
83
|
-
* @param apiKeyId - The API key ID to use for the error tracking.
|
|
84
96
|
*/
|
|
85
97
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
|
-
|
|
98
|
+
function wrapClassWithErrorTracking(ClassToWrap: any): void {
|
|
99
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
87
103
|
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(
|
|
88
104
|
name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function",
|
|
89
105
|
);
|
|
@@ -94,14 +110,13 @@ export function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string):
|
|
|
94
110
|
try {
|
|
95
111
|
return await originalMethod.apply(this, args);
|
|
96
112
|
} catch (error) {
|
|
97
|
-
if (!(error
|
|
98
|
-
|
|
113
|
+
if (!shouldTrackError(error)) {
|
|
114
|
+
throw error;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
const { message, stack } = error;
|
|
117
|
+
const { message, stack } = error as Error;
|
|
102
118
|
|
|
103
119
|
sendEvent({
|
|
104
|
-
apiKeyId,
|
|
105
120
|
method,
|
|
106
121
|
message,
|
|
107
122
|
stack,
|
|
@@ -115,3 +130,63 @@ export function wrapClassWithErrorTracking(ClassToWrap: any, apiKeyId: string):
|
|
|
115
130
|
};
|
|
116
131
|
}
|
|
117
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Wraps all methods of an object with error tracking.
|
|
136
|
+
*
|
|
137
|
+
* @param object - The object whose methods should be wrapped.
|
|
138
|
+
*/
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
140
|
+
function wrapObjectMethodsWithErrorTracking(object: any): void {
|
|
141
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const methods = Object.getOwnPropertyNames(object).filter(
|
|
146
|
+
name => name !== "constructor" && typeof object[name] === "function",
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
for (const method of methods) {
|
|
150
|
+
const originalMethod = object[method];
|
|
151
|
+
object[method] = async function (...args: unknown[]) {
|
|
152
|
+
try {
|
|
153
|
+
return await originalMethod.apply(this, args);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!shouldTrackError(error)) {
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const { message, stack } = error as Error;
|
|
160
|
+
|
|
161
|
+
sendEvent({
|
|
162
|
+
method,
|
|
163
|
+
message,
|
|
164
|
+
stack,
|
|
165
|
+
name: "error",
|
|
166
|
+
}).catch(() => {
|
|
167
|
+
// ignore error
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Filters out non-errors and API errors
|
|
178
|
+
*
|
|
179
|
+
* @param error - The error to check.
|
|
180
|
+
* @returns True if the error should be tracked, false otherwise.
|
|
181
|
+
*/
|
|
182
|
+
function shouldTrackError(error: unknown): boolean {
|
|
183
|
+
if (!(error instanceof Error)) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (error instanceof APIError) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return true;
|
|
192
|
+
}
|
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
|
}
|
package/client/evm/evm.ts
CHANGED
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
ListSmartAccountResult,
|
|
22
22
|
ListSmartAccountsOptions,
|
|
23
23
|
GetOrCreateServerAccountOptions,
|
|
24
|
+
SignTypedDataOptions,
|
|
25
|
+
UpdateEvmAccountOptions,
|
|
24
26
|
} from "./evm.types.js";
|
|
25
27
|
import { toEvmServerAccount } from "../../accounts/evm/toEvmServerAccount.js";
|
|
26
28
|
import { toEvmSmartAccount } from "../../accounts/evm/toEvmSmartAccount.js";
|
|
@@ -45,6 +47,7 @@ import {
|
|
|
45
47
|
waitForUserOperation,
|
|
46
48
|
WaitForUserOperationReturnType,
|
|
47
49
|
} from "../../actions/evm/waitForUserOperation.js";
|
|
50
|
+
import { Analytics } from "../../analytics.js";
|
|
48
51
|
import { APIError } from "../../openapi-client/errors.js";
|
|
49
52
|
import { CdpOpenApiClient } from "../../openapi-client/index.js";
|
|
50
53
|
import { Hex } from "../../types/misc.js";
|
|
@@ -93,16 +96,20 @@ export class EvmClient implements EvmClientInterface {
|
|
|
93
96
|
* ```
|
|
94
97
|
*/
|
|
95
98
|
async createAccount(options: CreateServerAccountOptions = {}): Promise<ServerAccount> {
|
|
96
|
-
const
|
|
99
|
+
const openApiAccount = await CdpOpenApiClient.createEvmAccount(
|
|
97
100
|
{
|
|
98
101
|
name: options.name,
|
|
99
102
|
},
|
|
100
103
|
options.idempotencyKey,
|
|
101
104
|
);
|
|
102
105
|
|
|
103
|
-
|
|
104
|
-
account,
|
|
106
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
107
|
+
account: openApiAccount,
|
|
105
108
|
});
|
|
109
|
+
|
|
110
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
111
|
+
|
|
112
|
+
return account;
|
|
106
113
|
}
|
|
107
114
|
|
|
108
115
|
/**
|
|
@@ -151,17 +158,21 @@ export class EvmClient implements EvmClientInterface {
|
|
|
151
158
|
* ```
|
|
152
159
|
*/
|
|
153
160
|
async createSmartAccount(options: CreateSmartAccountOptions): Promise<SmartAccount> {
|
|
154
|
-
const
|
|
161
|
+
const openApiSmartAccount = await CdpOpenApiClient.createEvmSmartAccount(
|
|
155
162
|
{
|
|
156
163
|
owners: [options.owner.address],
|
|
157
164
|
},
|
|
158
165
|
options.idempotencyKey,
|
|
159
166
|
);
|
|
160
167
|
|
|
161
|
-
|
|
162
|
-
smartAccount,
|
|
168
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
169
|
+
smartAccount: openApiSmartAccount,
|
|
163
170
|
owner: options.owner,
|
|
164
171
|
});
|
|
172
|
+
|
|
173
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
174
|
+
|
|
175
|
+
return smartAccount;
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
/**
|
|
@@ -190,7 +201,7 @@ export class EvmClient implements EvmClientInterface {
|
|
|
190
201
|
* ```
|
|
191
202
|
*/
|
|
192
203
|
async getAccount(options: GetServerAccountOptions): Promise<ServerAccount> {
|
|
193
|
-
const
|
|
204
|
+
const openApiAccount = await (() => {
|
|
194
205
|
if (options.address) {
|
|
195
206
|
return CdpOpenApiClient.getEvmAccount(options.address);
|
|
196
207
|
}
|
|
@@ -202,9 +213,13 @@ export class EvmClient implements EvmClientInterface {
|
|
|
202
213
|
throw new Error("Either address or name must be provided");
|
|
203
214
|
})();
|
|
204
215
|
|
|
205
|
-
|
|
206
|
-
account,
|
|
216
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
217
|
+
account: openApiAccount,
|
|
207
218
|
});
|
|
219
|
+
|
|
220
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
221
|
+
|
|
222
|
+
return account;
|
|
208
223
|
}
|
|
209
224
|
|
|
210
225
|
/**
|
|
@@ -227,12 +242,16 @@ export class EvmClient implements EvmClientInterface {
|
|
|
227
242
|
* ```
|
|
228
243
|
*/
|
|
229
244
|
async getSmartAccount(options: GetSmartAccountOptions): Promise<SmartAccount> {
|
|
230
|
-
const
|
|
245
|
+
const openApiSmartAccount = await CdpOpenApiClient.getEvmSmartAccount(options.address);
|
|
231
246
|
|
|
232
|
-
|
|
233
|
-
smartAccount,
|
|
247
|
+
const smartAccount = toEvmSmartAccount(CdpOpenApiClient, {
|
|
248
|
+
smartAccount: openApiSmartAccount,
|
|
234
249
|
owner: options.owner,
|
|
235
250
|
});
|
|
251
|
+
|
|
252
|
+
Analytics.wrapObjectMethodsWithErrorTracking(smartAccount);
|
|
253
|
+
|
|
254
|
+
return smartAccount;
|
|
236
255
|
}
|
|
237
256
|
|
|
238
257
|
/**
|
|
@@ -328,11 +347,15 @@ export class EvmClient implements EvmClientInterface {
|
|
|
328
347
|
});
|
|
329
348
|
|
|
330
349
|
return {
|
|
331
|
-
accounts: ethAccounts.accounts.map(account =>
|
|
332
|
-
toEvmServerAccount(CdpOpenApiClient, {
|
|
333
|
-
account
|
|
334
|
-
})
|
|
335
|
-
|
|
350
|
+
accounts: ethAccounts.accounts.map(account => {
|
|
351
|
+
const evmAccount = toEvmServerAccount(CdpOpenApiClient, {
|
|
352
|
+
account,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
Analytics.wrapObjectMethodsWithErrorTracking(evmAccount);
|
|
356
|
+
|
|
357
|
+
return evmAccount;
|
|
358
|
+
}),
|
|
336
359
|
nextPageToken: ethAccounts.nextPageToken,
|
|
337
360
|
};
|
|
338
361
|
}
|
|
@@ -647,6 +670,68 @@ export class EvmClient implements EvmClientInterface {
|
|
|
647
670
|
};
|
|
648
671
|
}
|
|
649
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Signs an EIP-712 message.
|
|
675
|
+
*
|
|
676
|
+
* @param {SignTypedDataOptions} options - Parameters for signing the EIP-712 message.
|
|
677
|
+
* @returns A promise that resolves to the signature.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts
|
|
681
|
+
* const signature = await cdp.evm.signTypedData({
|
|
682
|
+
* address: account.address,
|
|
683
|
+
* domain: {
|
|
684
|
+
* name: "Permit2",
|
|
685
|
+
* chainId: 1,
|
|
686
|
+
* verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
687
|
+
* },
|
|
688
|
+
* types: {
|
|
689
|
+
* EIP712Domain: [
|
|
690
|
+
* { name: "name", type: "string" },
|
|
691
|
+
* { name: "chainId", type: "uint256" },
|
|
692
|
+
* { name: "verifyingContract", type: "address" },
|
|
693
|
+
* ],
|
|
694
|
+
* PermitTransferFrom: [
|
|
695
|
+
* { name: "permitted", type: "TokenPermissions" },
|
|
696
|
+
* { name: "spender", type: "address" },
|
|
697
|
+
* { name: "nonce", type: "uint256" },
|
|
698
|
+
* { name: "deadline", type: "uint256" },
|
|
699
|
+
* ],
|
|
700
|
+
* TokenPermissions: [
|
|
701
|
+
* { name: "token", type: "address" },
|
|
702
|
+
* { name: "amount", type: "uint256" },
|
|
703
|
+
* ],
|
|
704
|
+
* },
|
|
705
|
+
* primaryType: "PermitTransferFrom",
|
|
706
|
+
* message: {
|
|
707
|
+
* permitted: {
|
|
708
|
+
* token: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
709
|
+
* amount: "1000000",
|
|
710
|
+
* },
|
|
711
|
+
* spender: "0xFfFfFfFFfFFfFFfFFfFFFFFffFFFffffFfFFFfFf",
|
|
712
|
+
* nonce: "0",
|
|
713
|
+
* deadline: "1717123200",
|
|
714
|
+
* },
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
async signTypedData(options: SignTypedDataOptions): Promise<SignatureResult> {
|
|
719
|
+
const signature = await CdpOpenApiClient.signEvmTypedData(
|
|
720
|
+
options.address,
|
|
721
|
+
{
|
|
722
|
+
domain: options.domain,
|
|
723
|
+
types: options.types,
|
|
724
|
+
primaryType: options.primaryType,
|
|
725
|
+
message: options.message,
|
|
726
|
+
},
|
|
727
|
+
options.idempotencyKey,
|
|
728
|
+
);
|
|
729
|
+
|
|
730
|
+
return {
|
|
731
|
+
signature: signature.signature as Hex,
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
650
735
|
/**
|
|
651
736
|
* Signs an EVM transaction.
|
|
652
737
|
*
|
|
@@ -691,6 +776,63 @@ export class EvmClient implements EvmClientInterface {
|
|
|
691
776
|
};
|
|
692
777
|
}
|
|
693
778
|
|
|
779
|
+
/**
|
|
780
|
+
* Updates a CDP EVM account.
|
|
781
|
+
*
|
|
782
|
+
* @param {UpdateEvmAccountOptions} [options] - Optional parameters for creating the account.
|
|
783
|
+
* @param {string} options.address - The address of the account to update
|
|
784
|
+
* @param {UpdateEvmAccountBody} options.update - An object containing account fields to update.
|
|
785
|
+
* @param {string} [options.update.name] - The new name for the account.
|
|
786
|
+
* @param {string} [options.update.accountPolicy] - The ID of a Policy to apply to the account.
|
|
787
|
+
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
788
|
+
*
|
|
789
|
+
* @returns A promise that resolves to the updated account.
|
|
790
|
+
*
|
|
791
|
+
* @example **With a name**
|
|
792
|
+
* ```ts
|
|
793
|
+
* const account = await cdp.evm.updateAccount({ address: "0x...", update: { name: "New Name" } });
|
|
794
|
+
* ```
|
|
795
|
+
*
|
|
796
|
+
* @example **With an account policy**
|
|
797
|
+
* ```ts
|
|
798
|
+
* const account = await cdp.evm.updateAccount({ address: "0x...", update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" } });
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @example **With an idempotency key**
|
|
802
|
+
* ```ts
|
|
803
|
+
* const idempotencyKey = uuidv4();
|
|
804
|
+
*
|
|
805
|
+
* // First call
|
|
806
|
+
* await cdp.evm.updateAccount({
|
|
807
|
+
* address: "0x...",
|
|
808
|
+
* update: { accountPolicy: "73bcaeeb-d7af-4615-b064-42b5fe83a31e" },
|
|
809
|
+
* idempotencyKey,
|
|
810
|
+
* });
|
|
811
|
+
*
|
|
812
|
+
* // Second call with the same idempotency key will not update
|
|
813
|
+
* await cdp.evm.updateAccount({
|
|
814
|
+
* address: '0x...',
|
|
815
|
+
* update: { name: "" },
|
|
816
|
+
* idempotencyKey,
|
|
817
|
+
* });
|
|
818
|
+
* ```
|
|
819
|
+
*/
|
|
820
|
+
async updateAccount(options: UpdateEvmAccountOptions): Promise<ServerAccount> {
|
|
821
|
+
const openApiAccount = await CdpOpenApiClient.updateEvmAccount(
|
|
822
|
+
options.address,
|
|
823
|
+
options.update,
|
|
824
|
+
options.idempotencyKey,
|
|
825
|
+
);
|
|
826
|
+
|
|
827
|
+
const account = toEvmServerAccount(CdpOpenApiClient, {
|
|
828
|
+
account: openApiAccount,
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
Analytics.wrapObjectMethodsWithErrorTracking(account);
|
|
832
|
+
|
|
833
|
+
return account;
|
|
834
|
+
}
|
|
835
|
+
|
|
694
836
|
/**
|
|
695
837
|
* Waits for a user operation to complete or fail.
|
|
696
838
|
*
|
package/client/evm/evm.types.ts
CHANGED
|
@@ -21,9 +21,10 @@ import type {
|
|
|
21
21
|
EvmUserOperationNetwork,
|
|
22
22
|
EvmUserOperationStatus,
|
|
23
23
|
OpenApiEvmMethods,
|
|
24
|
+
UpdateEvmAccountBody,
|
|
24
25
|
} from "../../openapi-client/index.js";
|
|
25
26
|
import type { Calls } from "../../types/calls.js";
|
|
26
|
-
import type { Address, Hex } from "../../types/misc.js";
|
|
27
|
+
import type { Address, EIP712Message, Hex } from "../../types/misc.js";
|
|
27
28
|
import type { WaitOptions } from "../../utils/wait.js";
|
|
28
29
|
|
|
29
30
|
/**
|
|
@@ -37,6 +38,7 @@ export type EvmClientInterface = Omit<
|
|
|
37
38
|
| "getEvmAccountByName" // mapped to getAccount
|
|
38
39
|
| "getEvmSmartAccount" // mapped to getSmartAccount
|
|
39
40
|
| "getUserOperation"
|
|
41
|
+
| "updateEvmAccount" // mapped to updateAccount
|
|
40
42
|
| "listEvmAccounts" // mapped to listAccounts
|
|
41
43
|
| "listEvmSmartAccounts" // mapped to listSmartAccounts
|
|
42
44
|
| "listEvmTokenBalances" // mapped to listTokenBalances
|
|
@@ -46,7 +48,10 @@ export type EvmClientInterface = Omit<
|
|
|
46
48
|
| "signEvmHash" // mapped to signHash
|
|
47
49
|
| "signEvmMessage" // mapped to signMessage
|
|
48
50
|
| "signEvmTransaction" // mapped to signTransaction
|
|
51
|
+
| "signEvmTypedData" // mapped to signTypedData
|
|
49
52
|
| "sendEvmTransaction" // mapped to sendTransaction
|
|
53
|
+
| "signEvmTypedData" // mapped to signTypedData
|
|
54
|
+
| "updateEvmAccount" // mapped to updateAccount
|
|
50
55
|
> & {
|
|
51
56
|
createAccount: (options: CreateServerAccountOptions) => Promise<ServerAccount>;
|
|
52
57
|
createSmartAccount: (options: CreateSmartAccountOptions) => Promise<SmartAccount>;
|
|
@@ -54,6 +59,7 @@ export type EvmClientInterface = Omit<
|
|
|
54
59
|
getSmartAccount: (options: GetSmartAccountOptions) => Promise<SmartAccount>;
|
|
55
60
|
getOrCreateAccount: (options: GetOrCreateServerAccountOptions) => Promise<ServerAccount>;
|
|
56
61
|
getUserOperation: (options: GetUserOperationOptions) => Promise<UserOperation>;
|
|
62
|
+
updateAccount: (options: UpdateEvmAccountOptions) => Promise<ServerAccount>;
|
|
57
63
|
listAccounts: (options: ListServerAccountsOptions) => Promise<ListServerAccountResult>;
|
|
58
64
|
listSmartAccounts: (options: ListSmartAccountsOptions) => Promise<ListSmartAccountResult>;
|
|
59
65
|
listTokenBalances: (options: ListTokenBalancesOptions) => Promise<ListTokenBalancesResult>;
|
|
@@ -65,6 +71,7 @@ export type EvmClientInterface = Omit<
|
|
|
65
71
|
) => Promise<SendUserOperationReturnType>;
|
|
66
72
|
signHash: (options: SignHashOptions) => Promise<SignatureResult>;
|
|
67
73
|
signMessage: (options: SignMessageOptions) => Promise<SignatureResult>;
|
|
74
|
+
signTypedData: (options: SignTypedDataOptions) => Promise<SignatureResult>;
|
|
68
75
|
signTransaction: (options: SignTransactionOptions) => Promise<SignatureResult>;
|
|
69
76
|
};
|
|
70
77
|
|
|
@@ -187,6 +194,18 @@ export interface ReadonlySmartAccount
|
|
|
187
194
|
owners: Address[];
|
|
188
195
|
}
|
|
189
196
|
|
|
197
|
+
/**
|
|
198
|
+
* Options for creating an EVM server account.
|
|
199
|
+
*/
|
|
200
|
+
export interface UpdateEvmAccountOptions {
|
|
201
|
+
/** The address of the account. */
|
|
202
|
+
address: string;
|
|
203
|
+
/** The updates to apply to the account */
|
|
204
|
+
update: UpdateEvmAccountBody;
|
|
205
|
+
/** The idempotency key. */
|
|
206
|
+
idempotencyKey?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
190
209
|
/**
|
|
191
210
|
* The result of listing EVM smart accounts.
|
|
192
211
|
*/
|
|
@@ -259,6 +278,24 @@ export interface SignMessageOptions {
|
|
|
259
278
|
idempotencyKey?: string;
|
|
260
279
|
}
|
|
261
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Options for signing an EVM message.
|
|
283
|
+
*/
|
|
284
|
+
export interface SignTypedDataOptions {
|
|
285
|
+
/** The address of the account. */
|
|
286
|
+
address: Address;
|
|
287
|
+
/** The domain of the message. */
|
|
288
|
+
domain: EIP712Message["domain"];
|
|
289
|
+
/** The types of the message. */
|
|
290
|
+
types: EIP712Message["types"];
|
|
291
|
+
/** The primary type of the message. This is the name of the struct in the `types` object that is the root of the message. */
|
|
292
|
+
primaryType: EIP712Message["primaryType"];
|
|
293
|
+
/** The message to sign. The structure of this message must match the `primaryType` struct in the `types` object. */
|
|
294
|
+
message: EIP712Message["message"];
|
|
295
|
+
/** The idempotency key. */
|
|
296
|
+
idempotencyKey?: string;
|
|
297
|
+
}
|
|
298
|
+
|
|
262
299
|
/**
|
|
263
300
|
* Options for signing an EVM transaction.
|
|
264
301
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PoliciesClient } from "./policies.js";
|