@@ -3,7 +3,7 @@ import type { OpenSeaClient } from "../client.js"
33import type { OutputFormat } from "../output.js"
44import { formatOutput } from "../output.js"
55import { parseFloatOption } from "../parse.js"
6- import { SwapsAPI } from "../sdk.js"
6+ import { resolveQuantity , SwapsAPI } from "../sdk.js"
77import type { SwapQuoteResponse } from "../types/index.js"
88import type { WalletProvider } from "../wallet/index.js"
99import { createWalletFromEnv , WALLET_PROVIDERS } from "../wallet/index.js"
@@ -31,7 +31,10 @@ export function swapsCommand(
3131 "--to-address <address>" ,
3232 "Contract address of the token to swap to" ,
3333 )
34- . requiredOption ( "--quantity <quantity>" , "Amount to swap (in token units)" )
34+ . requiredOption (
35+ "--quantity <quantity>" ,
36+ "Amount to swap (decimals like 0.1 are auto-converted to smallest units)" ,
37+ )
3538 . requiredOption ( "--address <address>" , "Wallet address executing the swap" )
3639 . option (
3740 "--slippage <slippage>" ,
@@ -53,14 +56,20 @@ export function swapsCommand(
5356 recipient ?: string
5457 } ) => {
5558 const client = getClient ( )
59+ const quantity = await resolveQuantity (
60+ client ,
61+ options . fromChain ,
62+ options . fromAddress ,
63+ options . quantity ,
64+ )
5665 const result = await client . get < SwapQuoteResponse > (
5766 "/api/v2/swap/quote" ,
5867 {
5968 from_chain : options . fromChain ,
6069 from_address : options . fromAddress ,
6170 to_chain : options . toChain ,
6271 to_address : options . toAddress ,
63- quantity : options . quantity ,
72+ quantity,
6473 address : options . address ,
6574 slippage : options . slippage
6675 ? parseFloatOption ( options . slippage , "--slippage" )
@@ -88,7 +97,10 @@ export function swapsCommand(
8897 "--to-address <address>" ,
8998 "Contract address of the token to swap to" ,
9099 )
91- . requiredOption ( "--quantity <quantity>" , "Amount to swap (in token units)" )
100+ . requiredOption (
101+ "--quantity <quantity>" ,
102+ "Amount to swap (decimals like 0.1 are auto-converted to smallest units)" ,
103+ )
92104 . option (
93105 "--slippage <slippage>" ,
94106 "Slippage tolerance (0.0 to 0.5, default: 0.01)" ,
@@ -120,7 +132,14 @@ export function swapsCommand(
120132 const address = await wallet . getAddress ( )
121133 console . error ( `Using ${ wallet . name } wallet: ${ address } ` )
122134
123- const swaps = new SwapsAPI ( getClient ( ) )
135+ const client = getClient ( )
136+ const quantity = await resolveQuantity (
137+ client ,
138+ options . fromChain ,
139+ options . fromAddress ,
140+ options . quantity ,
141+ )
142+ const swaps = new SwapsAPI ( client )
124143 const format = getFormat ( )
125144 const slippage = options . slippage
126145 ? parseFloatOption ( options . slippage , "--slippage" )
@@ -129,6 +148,7 @@ export function swapsCommand(
129148 if ( options . dryRun ) {
130149 const quote = await swaps . quote ( {
131150 ...options ,
151+ quantity,
132152 address,
133153 slippage,
134154 } )
@@ -139,6 +159,7 @@ export function swapsCommand(
139159 const results = await swaps . execute (
140160 {
141161 ...options ,
162+ quantity,
142163 address,
143164 slippage,
144165 } ,
0 commit comments