@coinbase/cdp-sdk 1.15.0 → 1.16.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 +82 -20
- package/_cjs/accounts/evm/toEvmServerAccount.js +13 -7
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_cjs/accounts/evm/toEvmSmartAccount.js +18 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -1
- 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/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 +14 -8
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -1
- package/_esm/accounts/evm/toEvmSmartAccount.js +18 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -1
- 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/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/types.d.ts +4 -4
- 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 +32 -6
- package/_types/client/evm/evm.types.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 +33 -15
- package/accounts/evm/toEvmSmartAccount.ts +25 -0
- package/accounts/evm/types.ts +14 -6
- 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 +33 -6
- package/package.json +1 -1
- package/utils/uuidV4.ts +23 -0
- package/version.ts +1 -1
package/client/evm/evm.types.ts
CHANGED
|
@@ -106,14 +106,18 @@ export interface CreateSwapQuoteOptions {
|
|
|
106
106
|
fromToken: Address;
|
|
107
107
|
/** The amount to send in atomic units of the token. */
|
|
108
108
|
fromAmount: bigint;
|
|
109
|
-
/** The address
|
|
110
|
-
taker
|
|
111
|
-
/** The
|
|
109
|
+
/** The address receiving the output of the swap. */
|
|
110
|
+
taker: Address;
|
|
111
|
+
/** The address signing the swap (only needed if taker is a smart contract, i.e. for smart account swaps). */
|
|
112
112
|
signerAddress?: Address;
|
|
113
|
-
/** The
|
|
113
|
+
/** The smart account object (required for smart account execution context only). */
|
|
114
|
+
smartAccount?: SmartAccount;
|
|
115
|
+
/** The price per unit of gas in wei. */
|
|
114
116
|
gasPrice?: bigint;
|
|
115
117
|
/** The slippage tolerance in basis points (0-10000). */
|
|
116
118
|
slippageBps?: number;
|
|
119
|
+
/** The idempotency key. */
|
|
120
|
+
idempotencyKey?: string;
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
/**
|
|
@@ -136,6 +140,8 @@ export interface GetSwapPriceOptions {
|
|
|
136
140
|
gasPrice?: bigint;
|
|
137
141
|
/** The slippage tolerance in basis points (0-10000). */
|
|
138
142
|
slippageBps?: number;
|
|
143
|
+
/** The idempotency key. */
|
|
144
|
+
idempotencyKey?: string;
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
/**
|
|
@@ -186,8 +192,14 @@ export interface ExecuteSwapQuoteOptions {
|
|
|
186
192
|
* Result of executing a swap quote.
|
|
187
193
|
*/
|
|
188
194
|
export interface ExecuteSwapQuoteResult {
|
|
189
|
-
/** The transaction hash of the executed swap. */
|
|
190
|
-
transactionHash
|
|
195
|
+
/** The transaction hash of the executed swap (for EOA swaps). */
|
|
196
|
+
transactionHash?: Hex;
|
|
197
|
+
/** The user operation hash of the executed swap (for smart account swaps). */
|
|
198
|
+
userOpHash?: Hex;
|
|
199
|
+
/** The address of the smart account (for smart account swaps). */
|
|
200
|
+
smartAccountAddress?: Address;
|
|
201
|
+
/** The status of the user operation (for smart accounts swaps). */
|
|
202
|
+
status?: typeof EvmUserOperationStatus.broadcast;
|
|
191
203
|
}
|
|
192
204
|
|
|
193
205
|
/**
|
|
@@ -599,3 +611,18 @@ export type GetSwapQuoteOptions = GetSwapPriceOptions;
|
|
|
599
611
|
export type GetSwapQuoteResult = GetSwapPriceResult;
|
|
600
612
|
export type SwapQuoteUnavailableResult = SwapUnavailableResult;
|
|
601
613
|
export type SwapPriceUnavailableResult = SwapUnavailableResult;
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Options for signing and wrapping EIP-712 typed data with a smart account.
|
|
617
|
+
* This method handles the full smart account signature flow including replay-safe hashing.
|
|
618
|
+
*/
|
|
619
|
+
export interface SmartAccountSignAndWrapTypedDataOptions {
|
|
620
|
+
/** The chain ID for the signature (used for replay protection). */
|
|
621
|
+
chainId: bigint;
|
|
622
|
+
/** The EIP-712 typed data message to sign. */
|
|
623
|
+
typedData: EIP712Message;
|
|
624
|
+
/** The index of the owner to sign with (defaults to 0). */
|
|
625
|
+
ownerIndex?: bigint;
|
|
626
|
+
/** Optional idempotency key for the signing request. */
|
|
627
|
+
idempotencyKey?: string;
|
|
628
|
+
}
|
package/package.json
CHANGED
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.16.0";
|