You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
import{PairV2,RouteV2,TradeV2,LB_ROUTER_ADDRESS,LBRouterABI}from'@traderjoe-xyz/sdk-v2'import{Token,ChainId,TokenAmount,JSBI,Percent,WAVAX}from'@traderjoe-xyz/sdk'// WAVAX_ITEM: _WAVAX_ITEM,import{Wallet}from'ethers'import{Contract}from'@ethersproject/contracts'import{parseUnits}from'@ethersproject/units'import{JsonRpcProvider}from'@ethersproject/providers'constAVAX_URL='https://api.avax.network/ext/bc/C/rpc'console.log(ChainId)constCHAIN_ID=ChainId.AVALANCHEconstPROVIDER=newJsonRpcProvider(AVAX_URL)constWALLET_PK="<><><>"constSIGNER=newWallet(WALLET_PK,PROVIDER)constACCOUNT=awaitSIGNER.getAddress()console.log("Addres is")console.log(ACCOUNT)// initialize tokensconsole.log("WAVAX")console.log(WAVAX)console.log("CHain id")console.log(CHAIN_ID)constWAVAX_ITEM=WAVAX[CHAIN_ID]// Token instance of WAVAX_ITEMconstUSDC=newToken(CHAIN_ID,'0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',6,'USDC','USD Coin')constUSDT=newToken(CHAIN_ID,'0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7',6,'USDT','Tether USD')// declare bases used to generate trade routesconstBASES=[WAVAX_ITEM,USDC,USDT]// the input token in the tradeconstinputToken=USDC// the output token in the tradeconstoutputToken=WAVAX_ITEM// specify whether user gave an exact inputToken or outputToken value for the tradeconstisExactIn=true// user string input; in this case representing 20 USDCconsttypedValueIn='20'// parse user input into inputToken's decimal precision, which is 6 for USDCconsttypedValueInParsed=parseUnits(typedValueIn,inputToken.decimals).toString()// returns 20000000// wrap into TokenAmountconstamountIn=newTokenAmount(inputToken,JSBI.BigInt(typedValueInParsed))console.log("Input")console.log(inputToken)console.log("Output")console.log(outputToken)console.log("Bases")console.log(BASES)// get all [Token, Token] combinations constallTokenPairs=PairV2.createAllTokenPairs(inputToken,outputToken,BASES)// init PairV2 instances for the [Token, Token] pairsconstallPairs=PairV2.initPairs(allTokenPairs)// generates all possible routes to considerconstallRoutes=RouteV2.createAllRoutes(allPairs,inputToken,outputToken,2// maxHops )constisAvaxIn=false// set to 'true' if swapping from AVAX; otherwise, 'false'constisAvaxOut=true// set to 'true' if swapping to AVAX; otherwise, 'false'// generates all possible TradeV2 instancesconsttrades=awaitTradeV2.getTradesExactIn(allRoutes,amountIn,outputToken,isAvaxIn,isAvaxOut,PROVIDER,CHAIN_ID)// chooses the best trade constbestTrade=TradeV2.chooseBestTrade(trades,isExactIn)// print useful information about the trade, such as the quote, executionPrice, fees, etcconsole.log(bestTrade.toLog())// get trade fee informationconst{ totalFeePct, feeAmountIn }=awaitbestTrade.getTradeFee(PROVIDER)console.log('Total fees percentage',totalFeePct.toSignificant(6),'%')console.log(`Fee: ${feeAmountIn.toSignificant(6)}${feeAmountIn.token.symbol}`)// set slippage toleranceconstuserSlippageTolerance=newPercent(JSBI.BigInt(50),JSBI.BigInt(10000))// 0.5%// set deadline for the transactionconstcurrenTimeInSec=Math.floor((newDate().getTime())/1000)constdeadline=currenTimeInSec+3600// set swap optionsconstswapOptions={recipient: ACCOUNT,allowedSlippage: userSlippageTolerance,
deadline,feeOnTransfer: false// or true}// generate swap method and parameters for contract callconst{
methodName,// e.g. swapExactTokensForAVAX,
args,// e.g.[amountIn, amountOut, binSteps, path, to, deadline]
value // e.g. 0x0}=bestTrade.swapCallParameters(swapOptions)console.log("LB ROUTer address")console.log(LB_ROUTER_ADDRESS)console.log(LB_ROUTER_ADDRESS[CHAIN_ID])console.log("LBRouter API")console.log(LBRouterABI)console.log("signer")console.log(SIGNER)console.log('signer done')// init router contractconstrouter=newContract(LB_ROUTER_ADDRESS[CHAIN_ID],LBRouterABI,SIGNER)// estimate gasconstgasOptions=value&&!isZero(value) ? { value } : {}constgasEstimate=awaitrouter.estimateGas[methodName](...args,options)// execute swapconstoptions=value&&!isZero(value)
? { value,from: ACCOUNT}
: {from: ACCOUNT}awaitrouter[methodName](...args,{gasLimit: calculateGasMargin(gasEstimate),
...options})
and are getting this error. I don't think it is from my side. Any advice on them?
Tutorial isn't working at all.
Besides primitive errors in naming (at one place variable is named "daedline", on the other "deadline"), there are more than 9 fatal errors.
Any suggestions on how can we use your sdk?
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hey tried to run this script:
and are getting this error. I don't think it is from my side. Any advice on them?
The text was updated successfully, but these errors were encountered: