@coinbase/cdp-sdk 1.44.1 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +117 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js +27 -0
- package/_cjs/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js +127 -55
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +111 -45
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/solana/toSolanaAccount.js +49 -19
- package/_cjs/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js +37 -0
- package/_cjs/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_cjs/analytics.js +10 -228
- package/_cjs/analytics.js.map +1 -1
- package/_cjs/client/cdp.js +0 -6
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/evm/evm.js +482 -227
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +41 -11
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/client/solana/solana.js +177 -106
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +137 -5
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +30 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js +15 -1
- package/_cjs/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_cjs/policies/evmSchema.js +127 -1
- package/_cjs/policies/evmSchema.js.map +1 -1
- package/_cjs/policies/solanaSchema.js +102 -1
- package/_cjs/policies/solanaSchema.js.map +1 -1
- package/_cjs/policies/types.js +7 -0
- package/_cjs/policies/types.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmDelegatedAccount.js +24 -0
- package/_esm/accounts/evm/toEvmDelegatedAccount.js.map +1 -0
- package/_esm/accounts/evm/toEvmServerAccount.js +127 -55
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +111 -45
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/solana/toSolanaAccount.js +49 -19
- package/_esm/accounts/solana/toSolanaAccount.js.map +1 -1
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js +34 -0
- package/_esm/actions/evm/waitForEvmEip7702DelegationStatus.js.map +1 -0
- package/_esm/analytics.js +9 -227
- package/_esm/analytics.js.map +1 -1
- package/_esm/client/cdp.js +0 -6
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/evm/evm.js +482 -227
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +41 -11
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/client/solana/solana.js +177 -106
- 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 +134 -3
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +27 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/onramp/onramp.js +13 -0
- package/_esm/openapi-client/generated/onramp/onramp.js.map +1 -1
- package/_esm/policies/evmSchema.js +126 -0
- package/_esm/policies/evmSchema.js.map +1 -1
- package/_esm/policies/solanaSchema.js +101 -0
- package/_esm/policies/solanaSchema.js.map +1 -1
- package/_esm/policies/types.js +9 -2
- package/_esm/policies/types.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts +13 -0
- package/_types/accounts/evm/toEvmDelegatedAccount.d.ts.map +1 -0
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -1
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -1
- package/_types/accounts/solana/toSolanaAccount.d.ts.map +1 -1
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts +32 -0
- package/_types/actions/evm/waitForEvmEip7702DelegationStatus.d.ts.map +1 -0
- package/_types/analytics.d.ts +5 -38
- package/_types/analytics.d.ts.map +1 -1
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts +54 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +29 -2
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/client/solana/solana.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 +436 -10
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +21 -1
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts +8 -1
- package/_types/openapi-client/generated/onramp/onramp.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +4 -0
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/evmSchema.d.ts +2717 -601
- package/_types/policies/evmSchema.d.ts.map +1 -1
- package/_types/policies/solanaSchema.d.ts +1411 -47
- package/_types/policies/solanaSchema.d.ts.map +1 -1
- package/_types/policies/types.d.ts +8427 -2942
- package/_types/policies/types.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmDelegatedAccount.ts +26 -0
- package/accounts/evm/toEvmServerAccount.ts +115 -67
- package/accounts/evm/toEvmSmartAccount.ts +100 -56
- package/accounts/solana/toSolanaAccount.ts +44 -24
- package/actions/evm/waitForEvmEip7702DelegationStatus.ts +57 -0
- package/analytics.ts +8 -294
- package/client/cdp.ts +0 -7
- package/client/evm/evm.ts +517 -282
- package/client/evm/evm.types.ts +41 -0
- package/client/policies/policies.ts +41 -16
- package/client/solana/solana.ts +195 -141
- package/index.ts +5 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +580 -11
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +49 -0
- package/openapi-client/generated/onramp/onramp.ts +24 -0
- package/package.json +1 -1
- package/policies/evmSchema.ts +164 -0
- package/policies/solanaSchema.ts +130 -0
- package/policies/types.ts +14 -0
- package/version.ts +1 -1
|
@@ -37,7 +37,13 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
37
37
|
network: transferArgs.network,
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
try {
|
|
41
|
+
return transfer(apiClient, account, transferArgs, smartAccountTransferStrategy);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
Analytics.trackError(error, "transfer");
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
41
47
|
},
|
|
42
48
|
async listTokenBalances(options) {
|
|
43
49
|
Analytics.trackAction({
|
|
@@ -47,10 +53,16 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
47
53
|
network: options.network,
|
|
48
54
|
},
|
|
49
55
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
try {
|
|
57
|
+
return listTokenBalances(apiClient, {
|
|
58
|
+
...options,
|
|
59
|
+
address: this.address,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
Analytics.trackError(error, "listTokenBalances");
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
54
66
|
},
|
|
55
67
|
async sendUserOperation(options) {
|
|
56
68
|
Analytics.trackAction({
|
|
@@ -60,30 +72,48 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
60
72
|
network: options.network,
|
|
61
73
|
},
|
|
62
74
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
try {
|
|
76
|
+
return sendUserOperation(apiClient, {
|
|
77
|
+
...options,
|
|
78
|
+
smartAccount: account,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
Analytics.trackError(error, "sendUserOperation");
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
67
85
|
},
|
|
68
86
|
async waitForUserOperation(options) {
|
|
69
87
|
Analytics.trackAction({
|
|
70
88
|
action: "wait_for_user_operation",
|
|
71
89
|
accountType: "evm_smart",
|
|
72
90
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
try {
|
|
92
|
+
return waitForUserOperation(apiClient, {
|
|
93
|
+
...options,
|
|
94
|
+
smartAccountAddress: account.address,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
Analytics.trackError(error, "waitForUserOperation");
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
77
101
|
},
|
|
78
102
|
async getUserOperation(options) {
|
|
79
103
|
Analytics.trackAction({
|
|
80
104
|
action: "get_user_operation",
|
|
81
105
|
accountType: "evm_smart",
|
|
82
106
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
try {
|
|
108
|
+
return getUserOperation(apiClient, {
|
|
109
|
+
...options,
|
|
110
|
+
smartAccount: account,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
Analytics.trackError(error, "getUserOperation");
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
87
117
|
},
|
|
88
118
|
async requestFaucet(options) {
|
|
89
119
|
Analytics.trackAction({
|
|
@@ -93,10 +123,16 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
93
123
|
network: options.network,
|
|
94
124
|
},
|
|
95
125
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
126
|
+
try {
|
|
127
|
+
return requestFaucet(apiClient, {
|
|
128
|
+
...options,
|
|
129
|
+
address: account.address,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
Analytics.trackError(error, "requestFaucet");
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
100
136
|
},
|
|
101
137
|
async quoteSwap(options) {
|
|
102
138
|
Analytics.trackAction({
|
|
@@ -106,12 +142,18 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
106
142
|
network: options.network,
|
|
107
143
|
},
|
|
108
144
|
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
145
|
+
try {
|
|
146
|
+
return createSwapQuote(apiClient, {
|
|
147
|
+
...options,
|
|
148
|
+
taker: this.address, // Always use smart account's address as taker
|
|
149
|
+
signerAddress: this.owners[0].address, // Always use owner's address as signer
|
|
150
|
+
smartAccount: account, // Pass smart account for execute method support
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
Analytics.trackError(error, "quoteSwap");
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
115
157
|
},
|
|
116
158
|
async swap(options) {
|
|
117
159
|
Analytics.trackAction({
|
|
@@ -121,12 +163,18 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
121
163
|
network: "network" in options ? options.network : undefined,
|
|
122
164
|
},
|
|
123
165
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
166
|
+
try {
|
|
167
|
+
return sendSwapOperation(apiClient, {
|
|
168
|
+
...options,
|
|
169
|
+
smartAccount: account,
|
|
170
|
+
taker: this.address, // Always use smart account's address as taker
|
|
171
|
+
signerAddress: this.owners[0].address, // Always use owner's address as signer
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
Analytics.trackError(error, "swap");
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
130
178
|
},
|
|
131
179
|
async signTypedData(options) {
|
|
132
180
|
Analytics.trackAction({
|
|
@@ -136,12 +184,18 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
136
184
|
network: options.network,
|
|
137
185
|
},
|
|
138
186
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
187
|
+
try {
|
|
188
|
+
const result = await signAndWrapTypedDataForSmartAccount(apiClient, {
|
|
189
|
+
chainId: BigInt(resolveNetworkToChain(options.network).id),
|
|
190
|
+
smartAccount: account,
|
|
191
|
+
typedData: options,
|
|
192
|
+
});
|
|
193
|
+
return result.signature;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
Analytics.trackError(error, "signTypedData");
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
145
199
|
},
|
|
146
200
|
async useSpendPermission(options) {
|
|
147
201
|
Analytics.trackAction({
|
|
@@ -151,7 +205,13 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
151
205
|
network: options.network,
|
|
152
206
|
},
|
|
153
207
|
});
|
|
154
|
-
|
|
208
|
+
try {
|
|
209
|
+
return useSpendPermission(apiClient, account, options);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
Analytics.trackError(error, "useSpendPermission");
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
155
215
|
},
|
|
156
216
|
name: options.smartAccount.name,
|
|
157
217
|
type: "evm-smart",
|
|
@@ -163,11 +223,17 @@ export function toEvmSmartAccount(apiClient, options) {
|
|
|
163
223
|
network,
|
|
164
224
|
},
|
|
165
225
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
226
|
+
try {
|
|
227
|
+
return toNetworkScopedEvmSmartAccount(apiClient, {
|
|
228
|
+
smartAccount: account,
|
|
229
|
+
owner: options.owner,
|
|
230
|
+
network,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
Analytics.trackError(error, "useNetwork");
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
171
237
|
},
|
|
172
238
|
};
|
|
173
239
|
return account;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toEvmSmartAccount.js","sourceRoot":"","sources":["../../../accounts/evm/toEvmSmartAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EACL,iBAAiB,GAGlB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAGL,aAAa,GACd,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAGL,iBAAiB,GAClB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,mCAAmC,EAAE,MAAM,0DAA0D,CAAC;AAC/G,OAAO,EAAE,kBAAkB,EAAE,MAAM,yDAAyD,CAAC;AAE7F,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAChF,OAAO,EAAE,4BAA4B,EAAE,MAAM,4DAA4D,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAC;AAClE,OAAO,EACL,oBAAoB,GAGrB,M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CAAC;gBAC7C,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QACD,KAAK,CAAC,kBAAkB,CACtB,OAAkC;YAElC,SAAS,CAAC,WAAW,CAAC;gBACpB,MAAM,EAAE,sBAAsB;gBAC9B,WAAW,EAAE,WAAW;gBACxB,UAAU,EAAE;oBACV,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB;aACF,CAAC,CAAC;YACH,IAAI,CAAC;gBACH,OAAO,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACzD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;gBAClD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;QAED,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,IAAI;QAC/B,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,KAAK,EAAoC,OAAgB,EAAE,EAAE;YACvE,SAAS,CAAC,WAAW,CAAC;gBACpB,MAAM,EAAE,aAAa;gBACrB,WAAW,EAAE,WAAW;gBACxB,UAAU,EAAE;oBACV,OAAO;iBACR;aACF,CAAC,CAAC;YACH,IAAI,CAAC;gBACH,OAAO,8BAA8B,CAAC,SAAS,EAAE;oBAC/C,YAAY,EAAE,OAAO;oBACrB,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;gBAC1C,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -23,39 +23,63 @@ export function toSolanaAccount(apiClient, options) {
|
|
|
23
23
|
action: "request_faucet",
|
|
24
24
|
accountType: "solana",
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
try {
|
|
27
|
+
return requestFaucet(apiClient, {
|
|
28
|
+
...options,
|
|
29
|
+
address: account.address,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
Analytics.trackError(error, "requestFaucet");
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
30
36
|
},
|
|
31
37
|
async signMessage(options) {
|
|
32
38
|
Analytics.trackAction({
|
|
33
39
|
action: "sign_message",
|
|
34
40
|
accountType: "solana",
|
|
35
41
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
try {
|
|
43
|
+
return signMessage(apiClient, {
|
|
44
|
+
...options,
|
|
45
|
+
address: account.address,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
Analytics.trackError(error, "signMessage");
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
40
52
|
},
|
|
41
53
|
async signTransaction(options) {
|
|
42
54
|
Analytics.trackAction({
|
|
43
55
|
action: "sign_transaction",
|
|
44
56
|
accountType: "solana",
|
|
45
57
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
try {
|
|
59
|
+
return signTransaction(apiClient, {
|
|
60
|
+
...options,
|
|
61
|
+
address: account.address,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
Analytics.trackError(error, "signTransaction");
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
50
68
|
},
|
|
51
69
|
async sendTransaction(options) {
|
|
52
70
|
Analytics.trackAction({
|
|
53
71
|
action: "send_transaction",
|
|
54
72
|
accountType: "solana",
|
|
55
73
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
try {
|
|
75
|
+
return sendTransaction(apiClient, {
|
|
76
|
+
...options,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
Analytics.trackError(error, "sendTransaction");
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
59
83
|
},
|
|
60
84
|
async transfer(options) {
|
|
61
85
|
Analytics.trackAction({
|
|
@@ -65,10 +89,16 @@ export function toSolanaAccount(apiClient, options) {
|
|
|
65
89
|
network: options.network,
|
|
66
90
|
},
|
|
67
91
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
try {
|
|
93
|
+
return transfer(apiClient, {
|
|
94
|
+
...options,
|
|
95
|
+
from: account.address,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
Analytics.trackError(error, "transfer");
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
72
102
|
},
|
|
73
103
|
};
|
|
74
104
|
return account;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toSolanaAccount.js","sourceRoot":"","sources":["../../../accounts/solana/toSolanaAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAyB,MAAM,yCAAyC,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAyB,MAAM,yCAAyC,CAAC;AACjG,OAAO,EAAE,QAAQ,EAAwB,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAiB/C;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,OAAO,GAAkB;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO;QAChC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,IAAI;QAC1B,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ;QAClC,KAAK,CAAC,aAAa,CA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AC;gBACpB,MAAM,EAAE,UAAU;gBAClB,WAAW,EAAE,QAAQ;gBACrB,UAAU,EAAE;oBACV,OAAO,EAAE,OAAO,CAAC,OAAO;iBACzB;aACF,CAAC,CAAC;YACH,IAAI,CAAC;gBACH,OAAO,QAAQ,CAAC,SAAS,EAAE;oBACzB,GAAG,OAAO;oBACV,IAAI,EAAE,OAAO,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;gBACxC,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EvmEip7702DelegationOperationStatus, } from "../../openapi-client/index.js";
|
|
2
|
+
import { wait } from "../../utils/wait.js";
|
|
3
|
+
/**
|
|
4
|
+
* Polls getEvmEip7702DelegationOperationById until the status is COMPLETED or FAILED, or a timeout occurs.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { waitForEvmEip7702DelegationOperationStatus } from "@coinbase/cdp-sdk";
|
|
9
|
+
*
|
|
10
|
+
* const operation = await waitForEvmEip7702DelegationOperationStatus(client, {
|
|
11
|
+
* delegationOperationId: "delegation-op-123",
|
|
12
|
+
* waitOptions: {
|
|
13
|
+
* timeoutSeconds: 60,
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param {CdpOpenApiClientType} client - The client to use.
|
|
19
|
+
* @param {WaitForEvmEip7702DelegationOperationStatusOptions} options - The options for the wait operation.
|
|
20
|
+
* @returns {Promise<EvmEip7702DelegationOperation>} The delegation operation once it reaches a terminal status.
|
|
21
|
+
*/
|
|
22
|
+
export async function waitForEvmEip7702DelegationOperationStatus(client, options) {
|
|
23
|
+
const { delegationOperationId } = options;
|
|
24
|
+
const reload = async () => {
|
|
25
|
+
return client.getEvmEip7702DelegationOperationById(delegationOperationId);
|
|
26
|
+
};
|
|
27
|
+
const isTerminal = (operation) => {
|
|
28
|
+
return (operation.status === EvmEip7702DelegationOperationStatus.COMPLETED ||
|
|
29
|
+
operation.status === EvmEip7702DelegationOperationStatus.FAILED);
|
|
30
|
+
};
|
|
31
|
+
const waitOptions = options.waitOptions ?? { timeoutSeconds: 60 };
|
|
32
|
+
return await wait(reload, isTerminal, s => s, waitOptions);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=waitForEvmEip7702DelegationStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForEvmEip7702DelegationStatus.js","sourceRoot":"","sources":["../../../actions/evm/waitForEvmEip7702DelegationStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mCAAmC,GACpC,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,IAAI,EAAe,MAAM,qBAAqB,CAAC;AAYxD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,0CAA0C,CAC9D,MAA4B,EAC5B,OAA0D;IAE1D,MAAM,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAC;IAE1C,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;QACxB,OAAO,MAAM,CAAC,oCAAoC,CAAC,qBAAqB,CAAC,CAAC;IAC5E,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,CAAC,SAAwC,EAAW,EAAE;QACvE,OAAO,CACL,SAAS,CAAC,MAAM,KAAK,mCAAmC,CAAC,SAAS;YAClE,SAAS,CAAC,MAAM,KAAK,mCAAmC,CAAC,MAAM,CAChE,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;IAElE,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAC7D,CAAC"}
|
package/_esm/analytics.js
CHANGED
|
@@ -2,32 +2,13 @@ import md5 from "md5";
|
|
|
2
2
|
import { UserInputValidationError } from "./errors.js";
|
|
3
3
|
import { APIError, NetworkError } from "./openapi-client/errors.js";
|
|
4
4
|
import { version } from "./version.js";
|
|
5
|
-
// Symbol to store the original method on wrapped functions
|
|
6
|
-
const ORIGINAL_METHOD = Symbol("originalMethod");
|
|
7
5
|
// This is a public client id for the analytics service
|
|
8
6
|
const publicClientId = "54f2ee2fb3d2b901a829940d70fbfc13";
|
|
9
7
|
export const Analytics = {
|
|
10
8
|
identifier: "", // set in cdp.ts
|
|
11
|
-
wrapClassWithErrorTracking,
|
|
12
|
-
wrapObjectMethodsWithErrorTracking,
|
|
13
|
-
sendEvent,
|
|
14
|
-
trackAction,
|
|
15
|
-
};
|
|
16
|
-
/*
|
|
17
|
-
* Deprecated implementation - kept for test compatibility
|
|
18
|
-
* Shares the same identifier reference as Analytics
|
|
19
|
-
*/
|
|
20
|
-
export const AnalyticsDeprecated = {
|
|
21
|
-
get identifier() {
|
|
22
|
-
return Analytics.identifier;
|
|
23
|
-
},
|
|
24
|
-
set identifier(value) {
|
|
25
|
-
Analytics.identifier = value;
|
|
26
|
-
},
|
|
27
|
-
wrapClassWithErrorTracking: wrapClassWithErrorTrackingDeprecated,
|
|
28
|
-
wrapObjectMethodsWithErrorTracking: wrapObjectMethodsWithErrorTrackingDeprecated,
|
|
29
9
|
sendEvent,
|
|
30
10
|
trackAction,
|
|
11
|
+
trackError,
|
|
31
12
|
};
|
|
32
13
|
/**
|
|
33
14
|
* Sends an analytics event to the default endpoint
|
|
@@ -102,217 +83,18 @@ function trackAction(params) {
|
|
|
102
83
|
});
|
|
103
84
|
}
|
|
104
85
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* @param method - The method to get the original version of.
|
|
108
|
-
* @returns The original unwrapped method, or the method itself if it's not wrapped.
|
|
109
|
-
*/
|
|
110
|
-
function getOriginalMethod(method) {
|
|
111
|
-
return (method[ORIGINAL_METHOD] || method);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Creates an interceptor function that prevents recursive calls by checking if the instance is already executing.
|
|
115
|
-
*
|
|
116
|
-
* @param executingInstances - A WeakSet tracking instances that are currently executing.
|
|
117
|
-
* @param fallbackMethod - The method to call if recursion is not detected.
|
|
118
|
-
* @returns A function that intercepts calls and prevents recursion.
|
|
119
|
-
*/
|
|
120
|
-
function createRecursiveInterceptor(executingInstances, fallbackMethod) {
|
|
121
|
-
return function (...callArgs) {
|
|
122
|
-
if (executingInstances.has(this)) {
|
|
123
|
-
return Promise.resolve(callArgs[0]);
|
|
124
|
-
}
|
|
125
|
-
return fallbackMethod.apply(this, callArgs);
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Handles an error that occurred in a method by sending an analytics event and rethrowing the error.
|
|
130
|
-
*
|
|
131
|
-
* @param error - The error that occurred.
|
|
132
|
-
* @param methodName - The name of the method where the error occurred.
|
|
133
|
-
*/
|
|
134
|
-
async function handleMethodError(error, methodName) {
|
|
135
|
-
if (!shouldTrackError(error)) {
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
const { message, stack } = error;
|
|
139
|
-
sendEvent({
|
|
140
|
-
method: methodName,
|
|
141
|
-
message,
|
|
142
|
-
stack,
|
|
143
|
-
name: "error",
|
|
144
|
-
}).catch(() => {
|
|
145
|
-
// ignore error
|
|
146
|
-
});
|
|
147
|
-
throw error;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Creates a wrapper function that adds error tracking and recursion protection to a method.
|
|
151
|
-
*
|
|
152
|
-
* The recursion protection works by temporarily replacing the method with an interceptor
|
|
153
|
-
* during the synchronous phase of execution. Any recursive calls (e.g., a method calling
|
|
154
|
-
* itself via `this.method()` or `Class.prototype.method()`) happen synchronously and will
|
|
155
|
-
* hit the interceptor. After the synchronous phase completes (i.e., `originalMethod.apply()`
|
|
156
|
-
* returns a Promise), the method is immediately restored so that concurrent calls arriving
|
|
157
|
-
* after an `await` suspension go through the full wrapper instead of being intercepted.
|
|
158
|
-
*
|
|
159
|
-
* @param originalMethod - The original method to wrap.
|
|
160
|
-
* @param methodName - The name of the method being wrapped.
|
|
161
|
-
* @param executingInstances - A WeakSet tracking instances that are currently executing.
|
|
162
|
-
* @param setMethod - A function to set the method implementation.
|
|
163
|
-
* @param getMethod - A function to get the current method implementation.
|
|
164
|
-
* @returns A wrapped version of the method with error tracking and recursion protection.
|
|
165
|
-
*/
|
|
166
|
-
function createErrorTrackingWrapper(originalMethod, methodName, executingInstances, setMethod, getMethod) {
|
|
167
|
-
return async function (...args) {
|
|
168
|
-
const previousMethod = getMethod();
|
|
169
|
-
const recursiveInterceptor = createRecursiveInterceptor(executingInstances, previousMethod);
|
|
170
|
-
setMethod(recursiveInterceptor);
|
|
171
|
-
executingInstances.add(this);
|
|
172
|
-
try {
|
|
173
|
-
/*
|
|
174
|
-
* Start executing the original method. The synchronous portion runs immediately.
|
|
175
|
-
* Any recursive calls (e.g., this.method() or Class.prototype.method()) during
|
|
176
|
-
* this synchronous phase will hit the recursiveInterceptor.
|
|
177
|
-
*/
|
|
178
|
-
const resultPromise = originalMethod.apply(this, args);
|
|
179
|
-
/*
|
|
180
|
-
* Restore the method immediately after the synchronous phase completes.
|
|
181
|
-
* This ensures concurrent calls (arriving after an await suspension) go through
|
|
182
|
-
* the full wrapper chain instead of being short-circuited by the interceptor.
|
|
183
|
-
*/
|
|
184
|
-
setMethod(previousMethod);
|
|
185
|
-
executingInstances.delete(this);
|
|
186
|
-
return await resultPromise;
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
setMethod(previousMethod);
|
|
190
|
-
executingInstances.delete(this);
|
|
191
|
-
return handleMethodError(error, methodName);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Wraps all methods of a class with error tracking.
|
|
86
|
+
* Track an error that occurred in a method
|
|
197
87
|
*
|
|
198
|
-
* @param
|
|
88
|
+
* @param error - The error to track
|
|
89
|
+
* @param method - The method name where the error occurred
|
|
199
90
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
91
|
+
function trackError(error, method) {
|
|
92
|
+
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true")
|
|
203
93
|
return;
|
|
204
|
-
|
|
205
|
-
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
206
|
-
for (const method of methods) {
|
|
207
|
-
const currentMethod = ClassToWrap.prototype[method];
|
|
208
|
-
const originalMethod = getOriginalMethod(currentMethod);
|
|
209
|
-
const executingInstances = new WeakSet();
|
|
210
|
-
const wrappedMethod = createErrorTrackingWrapper(originalMethod, method, executingInstances, newMethod => {
|
|
211
|
-
ClassToWrap.prototype[method] = newMethod;
|
|
212
|
-
}, () => ClassToWrap.prototype[method]);
|
|
213
|
-
wrappedMethod[ORIGINAL_METHOD] = originalMethod;
|
|
214
|
-
ClassToWrap.prototype[method] = wrappedMethod;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Wraps all methods of an object with error tracking.
|
|
219
|
-
*
|
|
220
|
-
* @param object - The object whose methods should be wrapped.
|
|
221
|
-
*/
|
|
222
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
223
|
-
function wrapObjectMethodsWithErrorTracking(object) {
|
|
224
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
94
|
+
if (!shouldTrackError(error))
|
|
225
95
|
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
for (const method of methods) {
|
|
229
|
-
const currentMethod = object[method];
|
|
230
|
-
const originalMethod = getOriginalMethod(currentMethod);
|
|
231
|
-
const executingInstances = new WeakSet();
|
|
232
|
-
const wrappedMethod = createErrorTrackingWrapper(originalMethod, method, executingInstances, newMethod => {
|
|
233
|
-
object[method] = newMethod;
|
|
234
|
-
}, () => object[method]);
|
|
235
|
-
wrappedMethod[ORIGINAL_METHOD] = originalMethod;
|
|
236
|
-
object[method] = wrappedMethod;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Wraps all methods of a class with error tracking.
|
|
241
|
-
*
|
|
242
|
-
* @deprecated This is the old implementation that has a bug with methods calling themselves via prototype.
|
|
243
|
-
* Use Analytics.wrapClassWithErrorTracking instead.
|
|
244
|
-
* Kept for test compatibility.
|
|
245
|
-
*
|
|
246
|
-
* @param ClassToWrap - The class whose prototype methods should be wrapped.
|
|
247
|
-
*/
|
|
248
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
-
function wrapClassWithErrorTrackingDeprecated(ClassToWrap) {
|
|
250
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
const methods = Object.getOwnPropertyNames(ClassToWrap.prototype).filter(name => name !== "constructor" && typeof ClassToWrap.prototype[name] === "function");
|
|
254
|
-
for (const method of methods) {
|
|
255
|
-
const originalMethod = ClassToWrap.prototype[method];
|
|
256
|
-
ClassToWrap.prototype[method] = async function (...args) {
|
|
257
|
-
try {
|
|
258
|
-
return await originalMethod.apply(this, args);
|
|
259
|
-
}
|
|
260
|
-
catch (error) {
|
|
261
|
-
if (!shouldTrackError(error)) {
|
|
262
|
-
throw error;
|
|
263
|
-
}
|
|
264
|
-
const { message, stack } = error;
|
|
265
|
-
sendEvent({
|
|
266
|
-
method,
|
|
267
|
-
message,
|
|
268
|
-
stack,
|
|
269
|
-
name: "error",
|
|
270
|
-
}).catch(() => {
|
|
271
|
-
// ignore error
|
|
272
|
-
});
|
|
273
|
-
throw error;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Wraps all methods of an object with error tracking.
|
|
280
|
-
*
|
|
281
|
-
* @deprecated This is the old implementation that has a bug with methods calling themselves via object property.
|
|
282
|
-
* Use Analytics.wrapObjectMethodsWithErrorTracking instead.
|
|
283
|
-
* Kept for test compatibility.
|
|
284
|
-
*
|
|
285
|
-
* @param object - The object whose methods should be wrapped.
|
|
286
|
-
*/
|
|
287
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
288
|
-
function wrapObjectMethodsWithErrorTrackingDeprecated(object) {
|
|
289
|
-
if (process.env.DISABLE_CDP_ERROR_REPORTING === "true") {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const methods = Object.getOwnPropertyNames(object).filter(name => name !== "constructor" && typeof object[name] === "function");
|
|
293
|
-
for (const method of methods) {
|
|
294
|
-
const originalMethod = object[method];
|
|
295
|
-
object[method] = async function (...args) {
|
|
296
|
-
try {
|
|
297
|
-
return await originalMethod.apply(this, args);
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
if (!shouldTrackError(error)) {
|
|
301
|
-
throw error;
|
|
302
|
-
}
|
|
303
|
-
const { message, stack } = error;
|
|
304
|
-
sendEvent({
|
|
305
|
-
method,
|
|
306
|
-
message,
|
|
307
|
-
stack,
|
|
308
|
-
name: "error",
|
|
309
|
-
}).catch(() => {
|
|
310
|
-
// ignore error
|
|
311
|
-
});
|
|
312
|
-
throw error;
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
}
|
|
96
|
+
const { message, stack } = error;
|
|
97
|
+
sendEvent({ method, message, stack, name: "error" }).catch(() => { });
|
|
316
98
|
}
|
|
317
99
|
/**
|
|
318
100
|
* Filters out non-errors and API errors
|