@@ -6,6 +6,7 @@ import { getSigner } from "./provider";
66import { MarketData } from "./types" ;
77import { getSwapQuote } from "./zerox_service" ;
88import { getGasEstimation } from "./gasEstimator" ;
9+ import { setAllowanceToAllowanceHolder } from "./erc20" ;
910
1011
1112
@@ -39,12 +40,20 @@ export const executeTrade = async (market: MarketData) => {
3940 return ;
4041 }
4142 }
43+
44+ if ( quote . data ?. issues ?. allowance ) {
45+ console . log ( 'setting allowance on sell token' ) ;
46+ const { actual, spender} = quote . data . issues ?. allowance ;
47+ await setAllowanceToAllowanceHolder ( { actual, spender, chainId : market . chainId , baseToken : sellToken } )
48+ }
49+
50+
4251 console . log ( `doing a buy a amount of ${ randomBuyAmount } base token` )
4352
4453
4554 if ( ! IS_SIMULATION ) {
4655 const gasEstimator = await getGasEstimation ( market . chainId ) ;
47- const { data, to, value, gas , gasPrice } = quote . data . transaction ;
56+ const { data, to, value} = quote . data . transaction ;
4857 const tx = await signer . sendTransaction ( { data, to, value, ...gasEstimator } ) ;
4958 console . log ( `waiting buy trade to be validated onchain: ` , tx )
5059 await tx . wait ( ) ;
@@ -73,7 +82,7 @@ export const executeTrade = async (market: MarketData) => {
7382 const sellAmount = parseUnits ( randomSellAmount . toFixed ( 6 ) , market . quoteTokenBalance . token . decimals ) . toString ( ) ;
7483 const quote = await getSwapQuote ( { sellAmount, sellToken, buyToken, taker, intentOnFill : false , slippagePercentage } , market . chainId ) ;
7584
76- console . log ( quote . data . gasPrice ) ;
85+
7786
7887 if ( BigNumber . from ( quote . data . sellAmount ) . lt ( market . baseTokenBalance . balance ) ) {
7988 //const sellAmount = market.baseTokenBalance.balance.toString();
@@ -87,12 +96,17 @@ export const executeTrade = async (market: MarketData) => {
8796 return ;
8897 }
8998 }
99+
90100 console . log ( `doing a sell a amount of ${ randomSellAmount } base token` )
91-
101+ if ( quote . data ?. issues ?. allowance ) {
102+ console . log ( 'setting allowance on sell token' ) ;
103+ const { actual, spender} = quote . data . issues ?. allowance ;
104+ await setAllowanceToAllowanceHolder ( { actual, spender, chainId : market . chainId , baseToken : sellToken } )
105+ }
92106
93107 if ( ! IS_SIMULATION ) {
94108 const gasEstimator = await getGasEstimation ( market . chainId ) ;
95- const { data, to, value, gas , gasPrice } = quote . data . transaction ;
109+ const { data, to, value } = quote . data . transaction ;
96110 const tx = await signer . sendTransaction ( { data, to, value, ...gasEstimator } ) ;
97111 console . log ( `waiting sell trade to be validated onchain:` , tx )
98112 await tx . wait ( ) ;
0 commit comments