@coinbase/cdp-sdk 1.15.0 → 1.17.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 +82 -20
- package/_cjs/accounts/evm/toEvmServerAccount.js +20 -7
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +26 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js +28 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js +26 -0
- package/_cjs/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -0
- package/_cjs/actions/evm/signAndWrapTypedDataForSmartAccount.js +186 -0
- package/_cjs/actions/evm/signAndWrapTypedDataForSmartAccount.js.map +1 -0
- package/_cjs/actions/evm/swap/createSwapQuote.js +26 -8
- package/_cjs/actions/evm/swap/createSwapQuote.js.map +1 -1
- package/_cjs/actions/evm/swap/getSwapPrice.js +3 -2
- package/_cjs/actions/evm/swap/getSwapPrice.js.map +1 -1
- package/_cjs/actions/evm/swap/sendSwapOperation.js +153 -0
- package/_cjs/actions/evm/swap/sendSwapOperation.js.map +1 -0
- package/_cjs/actions/evm/swap/sendSwapTransaction.js +16 -2
- package/_cjs/actions/evm/swap/sendSwapTransaction.js.map +1 -1
- package/_cjs/client/evm/evm.js +13 -6
- package/_cjs/client/evm/evm.js.map +1 -1
- package/_cjs/client/policies/policies.js +6 -2
- package/_cjs/client/policies/policies.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +45 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +48 -0
- 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.msw.js +35 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/index.msw.js +5 -5
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js +342 -1
- package/_cjs/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js +40 -0
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_cjs/policies/schema.js +83 -2
- package/_cjs/policies/schema.js.map +1 -1
- package/_cjs/utils/uuidV4.js +26 -0
- package/_cjs/utils/uuidV4.js.map +1 -0
- package/_cjs/version.js +1 -1
- package/_esm/accounts/evm/toEvmServerAccount.js +21 -8
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +26 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js +25 -0
- package/_esm/accounts/evm/toNetworkScopedEvmServerAccount.js.map +1 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js +23 -0
- package/_esm/accounts/evm/toNetworkScopedEvmSmartAccount.js.map +1 -0
- package/_esm/actions/evm/signAndWrapTypedDataForSmartAccount.js +181 -0
- package/_esm/actions/evm/signAndWrapTypedDataForSmartAccount.js.map +1 -0
- package/_esm/actions/evm/swap/createSwapQuote.js +26 -8
- package/_esm/actions/evm/swap/createSwapQuote.js.map +1 -1
- package/_esm/actions/evm/swap/getSwapPrice.js +3 -2
- package/_esm/actions/evm/swap/getSwapPrice.js.map +1 -1
- package/_esm/actions/evm/swap/sendSwapOperation.js +150 -0
- package/_esm/actions/evm/swap/sendSwapOperation.js.map +1 -0
- package/_esm/actions/evm/swap/sendSwapTransaction.js +16 -2
- package/_esm/actions/evm/swap/sendSwapTransaction.js.map +1 -1
- package/_esm/client/evm/evm.js +14 -7
- package/_esm/client/evm/evm.js.map +1 -1
- package/_esm/client/policies/policies.js +7 -3
- package/_esm/client/policies/policies.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +44 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +48 -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.msw.js +35 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -1
- package/_esm/openapi-client/generated/index.msw.js +5 -5
- package/_esm/openapi-client/generated/index.msw.js.map +1 -1
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js +321 -0
- package/_esm/openapi-client/generated/policy-engine/policy-engine.msw.js.map +1 -1
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +40 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -1
- package/_esm/policies/schema.js +83 -2
- package/_esm/policies/schema.js.map +1 -1
- package/_esm/utils/uuidV4.js +23 -0
- package/_esm/utils/uuidV4.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/toNetworkScopedEvmServerAccount.d.ts +23 -0
- package/_types/accounts/evm/toNetworkScopedEvmServerAccount.d.ts.map +1 -0
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts +27 -0
- package/_types/accounts/evm/toNetworkScopedEvmSmartAccount.d.ts.map +1 -0
- package/_types/accounts/evm/types.d.ts +26 -9
- package/_types/accounts/evm/types.d.ts.map +1 -1
- package/_types/actions/evm/signAndWrapTypedDataForSmartAccount.d.ts +133 -0
- package/_types/actions/evm/signAndWrapTypedDataForSmartAccount.d.ts.map +1 -0
- package/_types/actions/evm/swap/createSwapQuote.d.ts.map +1 -1
- package/_types/actions/evm/swap/getSwapPrice.d.ts +2 -1
- package/_types/actions/evm/swap/getSwapPrice.d.ts.map +1 -1
- package/_types/actions/evm/swap/sendSwapOperation.d.ts +64 -0
- package/_types/actions/evm/swap/sendSwapOperation.d.ts.map +1 -0
- package/_types/actions/evm/swap/sendSwapTransaction.d.ts.map +1 -1
- package/_types/actions/evm/swap/types.d.ts +131 -5
- package/_types/actions/evm/swap/types.d.ts.map +1 -1
- package/_types/actions/evm/types.d.ts +112 -21
- package/_types/actions/evm/types.d.ts.map +1 -1
- package/_types/client/evm/evm.d.ts.map +1 -1
- package/_types/client/evm/evm.types.d.ts +33 -7
- package/_types/client/evm/evm.types.d.ts.map +1 -1
- package/_types/client/policies/policies.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +182 -2
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -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.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/index.msw.d.ts +5 -5
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -1
- package/_types/openapi-client/generated/policy-engine/policy-engine.msw.d.ts +21 -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.msw.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/policies/schema.d.ts +3780 -7
- package/_types/policies/schema.d.ts.map +1 -1
- package/_types/utils/uuidV4.d.ts +10 -0
- package/_types/utils/uuidV4.d.ts.map +1 -0
- package/_types/version.d.ts +1 -1
- package/accounts/evm/toEvmServerAccount.ts +40 -15
- package/accounts/evm/toEvmSmartAccount.ts +33 -0
- package/accounts/evm/toNetworkScopedEvmServerAccount.ts +42 -0
- package/accounts/evm/toNetworkScopedEvmSmartAccount.ts +41 -0
- package/accounts/evm/types.ts +46 -17
- package/actions/evm/signAndWrapTypedDataForSmartAccount.ts +246 -0
- package/actions/evm/swap/createSwapQuote.ts +42 -17
- package/actions/evm/swap/getSwapPrice.ts +15 -11
- package/actions/evm/swap/sendSwapOperation.ts +182 -0
- package/actions/evm/swap/sendSwapTransaction.ts +18 -2
- package/actions/evm/swap/types.ts +154 -5
- package/actions/evm/types.ts +123 -21
- package/client/evm/evm.ts +19 -8
- package/client/evm/evm.types.ts +34 -7
- package/client/policies/policies.ts +12 -3
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +221 -2
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +48 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +35 -0
- package/openapi-client/generated/faucets/faucets.ts +4 -4
- package/openapi-client/generated/index.msw.ts +5 -5
- package/openapi-client/generated/policy-engine/policy-engine.msw.ts +434 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +40 -0
- package/package.json +1 -1
- package/policies/schema.ts +94 -6
- package/utils/uuidV4.ts +23 -0
- package/version.ts +1 -1
package/policies/schema.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address } from "abitype/zod";
|
|
1
|
+
import { Abi, Address } from "abitype/zod";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -121,6 +121,90 @@ export const EvmMessageCriterionSchema = z.object({
|
|
|
121
121
|
});
|
|
122
122
|
export type EvmMessageCriterion = z.infer<typeof EvmMessageCriterionSchema>;
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* A list of comparables to apply against encoded arguments in the transaction's `data` field.
|
|
126
|
+
*/
|
|
127
|
+
export const EvmDataParameterConditionListSchema = z.object({
|
|
128
|
+
/**
|
|
129
|
+
* The name of the parameter to check against a transaction's calldata.
|
|
130
|
+
* If name is unknown, or is not named, you may supply an array index, e.g., `0` for first parameter.
|
|
131
|
+
*/
|
|
132
|
+
name: z.union([z.string().min(1), z.string().regex(/^\d+$/)]),
|
|
133
|
+
/**
|
|
134
|
+
* The operator to use for the comparison. The value resolved at the `name` will be on the
|
|
135
|
+
* left-hand side of the operator, and the `values` field will be on the right-hand side.
|
|
136
|
+
*/
|
|
137
|
+
operator: z.enum(["in", "not in"]),
|
|
138
|
+
/**
|
|
139
|
+
* Values to compare against the resolved `name` value.
|
|
140
|
+
* All values are encoded as strings. Refer to the table in the documentation for how values
|
|
141
|
+
* should be encoded, and which operators are supported for each type.
|
|
142
|
+
*/
|
|
143
|
+
values: z.array(z.string()),
|
|
144
|
+
});
|
|
145
|
+
export type EvmDataParameterConditionList = z.infer<typeof EvmDataParameterConditionListSchema>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* A single condition to apply against encoded arguments in the transaction's `data` field.
|
|
149
|
+
*/
|
|
150
|
+
export const EvmDataParameterConditionSchema = z.object({
|
|
151
|
+
/**
|
|
152
|
+
* The name of the parameter to check against a transaction's calldata.
|
|
153
|
+
* If name is unknown, or is not named, you may supply an array index, e.g., `0` for first parameter.
|
|
154
|
+
*/
|
|
155
|
+
name: z.union([z.string().min(1), z.string().regex(/^\d+$/)]),
|
|
156
|
+
/**
|
|
157
|
+
* The operator to use for the comparison. The value resolved at the `name` will be on the
|
|
158
|
+
* left-hand side of the operator, and the `value` field will be on the right-hand side.
|
|
159
|
+
*/
|
|
160
|
+
operator: EthValueOperatorEnum,
|
|
161
|
+
/**
|
|
162
|
+
* A single value to compare the value resolved at `name` to.
|
|
163
|
+
* All values are encoded as strings. Refer to the table in the documentation for how values
|
|
164
|
+
* should be encoded, and which operators are supported for each type.
|
|
165
|
+
*/
|
|
166
|
+
value: z.string(),
|
|
167
|
+
});
|
|
168
|
+
export type EvmDataParameterCondition = z.infer<typeof EvmDataParameterConditionSchema>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A single condition to apply against the function and encoded arguments in the transaction's `data` field.
|
|
172
|
+
* Each `parameter` configuration must be successfully evaluated against the corresponding function argument
|
|
173
|
+
* in order for a policy to be accepted.
|
|
174
|
+
*/
|
|
175
|
+
export const EvmDataConditionSchema = z.object({
|
|
176
|
+
/**
|
|
177
|
+
* The name of a smart contract function being called.
|
|
178
|
+
*/
|
|
179
|
+
function: z.string().min(1),
|
|
180
|
+
/**
|
|
181
|
+
* An optional list of parameter conditions to apply against encoded arguments in the transaction's `data` field.
|
|
182
|
+
*/
|
|
183
|
+
params: z
|
|
184
|
+
.array(z.union([EvmDataParameterConditionSchema, EvmDataParameterConditionListSchema]))
|
|
185
|
+
.min(1)
|
|
186
|
+
.optional(),
|
|
187
|
+
});
|
|
188
|
+
export type EvmDataCondition = z.infer<typeof EvmDataConditionSchema>;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Schema for EVM data criterion
|
|
192
|
+
*/
|
|
193
|
+
export const EvmDataCriterionSchema = z.object({
|
|
194
|
+
/** The type of criterion, must be "evmData" for EVM transaction rules. */
|
|
195
|
+
type: z.literal("evmData"),
|
|
196
|
+
/**
|
|
197
|
+
* The ABI of the smart contract being called. This can be a partial structure with only specific functions.
|
|
198
|
+
*/
|
|
199
|
+
abi: z.union([z.enum(["erc20", "erc721", "erc1155"]), Abi]),
|
|
200
|
+
/**
|
|
201
|
+
* A list of conditions to apply against the function and encoded arguments in the transaction's `data` field.
|
|
202
|
+
* Each condition must be met in order for this policy to be accepted or rejected.
|
|
203
|
+
*/
|
|
204
|
+
conditions: z.array(EvmDataConditionSchema).min(1),
|
|
205
|
+
});
|
|
206
|
+
export type EvmDataCriterion = z.infer<typeof EvmDataCriterionSchema>;
|
|
207
|
+
|
|
124
208
|
/**
|
|
125
209
|
* Schema for Solana address criterions
|
|
126
210
|
*/
|
|
@@ -145,7 +229,13 @@ export type SolAddressCriterion = z.infer<typeof SolAddressCriterionSchema>;
|
|
|
145
229
|
* Schema for criteria used in SignEvmTransaction operations
|
|
146
230
|
*/
|
|
147
231
|
export const SignEvmTransactionCriteriaSchema = z
|
|
148
|
-
.array(
|
|
232
|
+
.array(
|
|
233
|
+
z.discriminatedUnion("type", [
|
|
234
|
+
EthValueCriterionSchema,
|
|
235
|
+
EvmAddressCriterionSchema,
|
|
236
|
+
EvmDataCriterionSchema,
|
|
237
|
+
]),
|
|
238
|
+
)
|
|
149
239
|
.max(10)
|
|
150
240
|
.min(1);
|
|
151
241
|
/**
|
|
@@ -176,15 +266,13 @@ export const SendEvmTransactionCriteriaSchema = z
|
|
|
176
266
|
EthValueCriterionSchema,
|
|
177
267
|
EvmAddressCriterionSchema,
|
|
178
268
|
EvmNetworkCriterionSchema,
|
|
269
|
+
EvmDataCriterionSchema,
|
|
179
270
|
]),
|
|
180
271
|
)
|
|
181
272
|
.max(10)
|
|
182
273
|
.min(1);
|
|
183
274
|
|
|
184
|
-
|
|
185
|
-
* Type representing a set of criteria for the sendEvmTransaction operation.
|
|
186
|
-
* Can contain up to 10 individual criterion objects of ETH value or EVM address types.
|
|
187
|
-
*/
|
|
275
|
+
// Type representing a set of criteria for the sendEvmTransaction operation. Can contain up to 10 individual criterion objects of ETH value or EVM address types.
|
|
188
276
|
export type SendEvmTransactionCriteria = z.infer<typeof SendEvmTransactionCriteriaSchema>;
|
|
189
277
|
|
|
190
278
|
/**
|
package/utils/uuidV4.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Deterministically generates a UUIDv4 from a given input string.
|
|
5
|
+
* This is necessary when we need to generate downstream idempotency keys for operations that have multiple calls.
|
|
6
|
+
*
|
|
7
|
+
* @param input - The input string to derive from
|
|
8
|
+
* @param salt - Optional salt to append to the input (defaults to "salt")
|
|
9
|
+
* @returns A UUIDv4 formatted string
|
|
10
|
+
*/
|
|
11
|
+
export function createDeterministicUuidV4(input: string, salt = "salt"): string {
|
|
12
|
+
const hash = createHash("sha256")
|
|
13
|
+
.update(input + "-" + salt)
|
|
14
|
+
.digest("hex");
|
|
15
|
+
// Format as UUIDv4: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
16
|
+
return [
|
|
17
|
+
hash.slice(0, 8),
|
|
18
|
+
hash.slice(8, 12),
|
|
19
|
+
"4" + hash.slice(13, 16), // Version 4
|
|
20
|
+
((parseInt(hash.slice(16, 17), 16) & 0x3) | 0x8).toString(16) + hash.slice(17, 20), // Variant bits
|
|
21
|
+
hash.slice(20, 32),
|
|
22
|
+
].join("-");
|
|
23
|
+
}
|
package/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "1.
|
|
1
|
+
export const version = "1.17.0";
|