11import BigNumber from "bignumber.js" ;
2- import { ethers } from "ethers" ;
2+ import { ethers , TransactionLike } from "ethers" ;
33import { type Curve , OLD_CHAINS } from "./curve.js" ;
44import { IChainId , IDict , IRoute , IRouteOutputAndCost , IRouteStep } from "./interfaces" ;
55import {
@@ -459,7 +459,7 @@ export async function swap(this: Curve, inputCoin: string, outputCoin: string, a
459459 }
460460}
461461
462- export async function swapCalldata ( this : Curve , inputCoin : string , outputCoin : string , amount : number | string , slippage = 0.5 ) : Promise < string > {
462+ export async function populateSwap ( this : Curve , inputCoin : string , outputCoin : string , amount : number | string , slippage = 0.5 ) : Promise < TransactionLike > {
463463 console . log ( inputCoin , outputCoin , amount , slippage ) ;
464464 const [ inputCoinAddress , outputCoinAddress ] = _getCoinAddresses . call ( this , inputCoin , outputCoin ) ;
465465 const [ inputCoinDecimals , outputCoinDecimals ] = _getCoinDecimals . call ( this , inputCoinAddress , outputCoinAddress ) ;
@@ -476,16 +476,7 @@ export async function swapCalldata(this: Curve, inputCoin: string, outputCoin: s
476476 const _minRecvAmount = fromBN ( minRecvAmountBN , outputCoinDecimals ) ;
477477
478478 const contract = this . contracts [ this . constants . ALIASES . router ] . contract ;
479- const value = isEth ( inputCoinAddress ) ? _amount : this . parseUnits ( "0" ) ;
480-
481- let populatedTx ;
482- if ( _pools ) {
483- populatedTx = await contract . exchange . populateTransaction ( _route , _swapParams , _amount , _minRecvAmount , _pools , { value } ) ;
484- } else {
485- populatedTx = await contract . exchange . populateTransaction ( _route , _swapParams , _amount , _minRecvAmount , { value } ) ;
486- }
487-
488- return populatedTx . data as string ;
479+ return await contract . exchange . populateTransaction ( ...[ _route , _swapParams , _amount , _minRecvAmount , ..._pools ? [ _pools ] : [ ] , { value : isEth ( inputCoinAddress ) ? _amount : this . parseUnits ( "0" ) } ] )
489480}
490481
491482export async function getSwappedAmount ( this : Curve , tx : ethers . ContractTransactionResponse , outputCoin : string ) : Promise < string > {
0 commit comments