【发布时间】:2022-11-04 02:11:13
【问题描述】:
找到了一个代码,其中交换通过多边形 uniswap v3 上的确切池。需要更改方法以在路由器中使用不同的池,具体取决于价格。现在所有事务都使用 ExactOutputSingle。如果有人知道如何改变它,请帮助
async split(signer: Signer): Promise<void> {
const address = await signer.getAddress();
const { buyToken, sellToken, buyAmount } = await this.calculateSplitPurchase(address);
if (buyAmount.lessThan(0) || buyAmount.equalTo(0)) {
return;
}
console.log(`Buying ${buyAmount.toFixed()} ${buyToken.name} with ${sellToken.name}`);
const route = new Route([this.pool], sellToken, buyToken);
const amountIn = await this.quoter.callStatic.quoteExactOutputSingle(
sellToken.isNative ? WETH_ADDRESS : sellToken.address,
buyToken.isNative ? WETH_ADDRESS : buyToken.address,
this.pool.fee,
buyAmount.quotient.toString(10),
0,
);
const trade = Trade.createUncheckedTrade({
route,
tradeType: TradeType.EXACT_OUTPUT,
inputAmount: CurrencyAmount.fromRawAmount(sellToken, amountIn.toString()),
outputAmount: CurrencyAmount.fromRawAmount(buyToken, buyAmount.quotient.toString(10)),
});
const params = SwapRouter.swapCallParameters([trade], {
slippageTolerance: new Percent(2, 1000),
recipient: address,
deadline: ethers.constants.MaxUint256.toString(),
});
await this.swap(signer, params);
}
async swap(signer: Signer, params: MethodParameters): Promise<void> {
const tx = await signer.sendTransaction({
to: this.router.address,
from: await signer.getAddress(),
data: params.calldata,
value: params.value,
//gasPrice: await getFastGasPrice(),
//gasLimit: 1300000,
});
await tx.wait(3);
}
【问题讨论】:
标签: typescript ethers.js uniswap