|
|
@@ -302,12 +302,13 @@ export class Web3Service {
|
|
|
Logger.log(`poolAddress: ${poolAddress}`, 'addLiquiditySyncSwap')
|
|
|
|
|
|
const router = new web3.eth.Contract(SyncSwapRouterAbi, config.syncSwapRouterAddress)
|
|
|
+ const value = ethers.utils.parseEther(amount).toHexString()
|
|
|
const addLiquidity = router.methods.addLiquidity2(
|
|
|
// @ts-ignore
|
|
|
poolAddress,
|
|
|
[
|
|
|
- [ethers.constants.AddressZero, ethers.utils.parseEther(amount).toString()],
|
|
|
- [config.zkUsdcAddress, ethers.utils.parseUnits('0', 6).toString()]
|
|
|
+ [ethers.constants.AddressZero, value],
|
|
|
+ [config.zkUsdcAddress, ethers.utils.parseUnits('0', 6).toHexString()]
|
|
|
],
|
|
|
//encode abi
|
|
|
ethers.utils.defaultAbiCoder.encode(['uint256'], [zkWallet.address]),
|
|
|
@@ -324,10 +325,13 @@ export class Web3Service {
|
|
|
// from: wallet.address,
|
|
|
to: config.syncSwapRouterAddress,
|
|
|
data: addLiquidity.encodeABI(),
|
|
|
- value: ethers.utils.parseEther(amount).toString(),
|
|
|
+ value: value,
|
|
|
gasLimit
|
|
|
})
|
|
|
Logger.log(`transaction sent: ${tx.hash}`, 'addLiquiditySyncSwap')
|
|
|
+ account.addLiuidityNum = (account.addLiuidityNum || 0) + 1
|
|
|
+ account.lastAddLiuidity = new Date()
|
|
|
+ await this.accountService.save([account])
|
|
|
return new Web3Result(account.address, tx.hash, config, true)
|
|
|
}
|
|
|
|
|
|
@@ -370,6 +374,9 @@ export class Web3Service {
|
|
|
gasLimit
|
|
|
})
|
|
|
Logger.log(`transaction sent: ${tx.hash}`, 'removeLiquiditySyncSwap')
|
|
|
+ account.removeLiuidityNum = (account.removeLiuidityNum || 0) + 1
|
|
|
+ account.lastRemoveLiuidity = new Date()
|
|
|
+ await this.accountService.save([account])
|
|
|
return new Web3Result(account.address, tx.hash, config, true)
|
|
|
}
|
|
|
|
|
|
@@ -650,15 +657,11 @@ export class Web3Service {
|
|
|
const poolFactory = new web3.eth.Contract(SyncSwapPoolFactoryAbi, config.syncSwapPoolFactoryAddress)
|
|
|
// @ts-ignore
|
|
|
const poolAddress = await poolFactory.methods.getPool(config.syncSwapWethAddress, config.zkUsdcAddress).call()
|
|
|
- Logger.log(`poolAddress: ${poolAddress}`, 'addLiquiditySyncSwap')
|
|
|
+ Logger.log(`poolAddress: ${poolAddress}`, 'swapSyncSwap')
|
|
|
|
|
|
const router = new web3.eth.Contract(SyncSwapRouterAbi, config.syncSwapRouterAddress)
|
|
|
- const value =
|
|
|
- inputToken === 'eth'
|
|
|
- ? ethers.utils.parseEther(amount).toString()
|
|
|
- : ethers.utils.parseUnits(amount, 6).toString()
|
|
|
- const swap = router.methods.swap(
|
|
|
- // @ts-ignore
|
|
|
+ const value = inputToken === 'eth' ? ethers.utils.parseEther(amount) : ethers.utils.parseUnits(amount, 6)
|
|
|
+ const params = [
|
|
|
[
|
|
|
[
|
|
|
[
|
|
|
@@ -677,12 +680,17 @@ export class Web3Service {
|
|
|
]
|
|
|
],
|
|
|
inputToken === 'eth' ? ethers.constants.AddressZero : config.zkUsdcAddress,
|
|
|
- value
|
|
|
+ value.toHexString()
|
|
|
]
|
|
|
],
|
|
|
0,
|
|
|
- ethers.constants.AddressZero,
|
|
|
- '0x'
|
|
|
+ Math.floor(new Date().getTime() / 1000 + 60 * 30) + ''
|
|
|
+ ]
|
|
|
+ const swap = router.methods.swap(
|
|
|
+ // @ts-ignore
|
|
|
+ params[0],
|
|
|
+ params[1],
|
|
|
+ params[2]
|
|
|
)
|
|
|
|
|
|
const gasLimit = await swap.estimateGas({
|
|
|
@@ -692,10 +700,13 @@ export class Web3Service {
|
|
|
// from: wallet.address,
|
|
|
to: config.syncSwapRouterAddress,
|
|
|
data: swap.encodeABI(),
|
|
|
- value: value,
|
|
|
+ value: inputToken === 'eth' ? value : '0x00',
|
|
|
gasLimit
|
|
|
})
|
|
|
Logger.log(`transaction sent: ${tx.hash}`, 'swapSyncSwap')
|
|
|
+ account.swapNum = (account.swapNum || 0) + 1
|
|
|
+ account.lastSwap = new Date()
|
|
|
+ await this.accountService.save([account])
|
|
|
return new Web3Result(account.address, tx.hash, config, true)
|
|
|
}
|
|
|
|