deploy cfx

This commit is contained in:
Attens1423
2023-05-12 14:40:39 +08:00
parent 0e29bcc832
commit 5b293b91fb
6 changed files with 164 additions and 19 deletions

View File

@@ -16,34 +16,42 @@ contract UniAdapter is IDODOAdapter {
using SafeMath for uint;
//fromToken == token0
function sellBase(address to, address pool, bytes memory) external override {
function sellBase(address to, address pool, bytes memory data) external override {
address baseToken = IUni(pool).token0();
(uint reserveIn, uint reserveOut,) = IUni(pool).getReserves();
uint receiveQuoteAmount;
{
(uint256 fee, uint256 denFee) = abi.decode(data, (uint256, uint256));
require(reserveIn > 0 && reserveOut > 0, 'UniAdapter: INSUFFICIENT_LIQUIDITY');
uint balance0 = IERC20(baseToken).balanceOf(pool);
uint sellBaseAmount = balance0 - reserveIn;
uint sellBaseAmountWithFee = sellBaseAmount.mul(997);
uint sellBaseAmountWithFee = sellBaseAmount.mul(denFee - fee);
uint numerator = sellBaseAmountWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(sellBaseAmountWithFee);
uint receiveQuoteAmount = numerator / denominator;
uint denominator = reserveIn.mul(denFee).add(sellBaseAmountWithFee);
receiveQuoteAmount = numerator / denominator;
}
IUni(pool).swap(0, receiveQuoteAmount, to, new bytes(0));
}
//fromToken == token1
function sellQuote(address to, address pool, bytes memory) external override {
function sellQuote(address to, address pool, bytes memory data) external override {
address quoteToken = IUni(pool).token1();
(uint reserveOut, uint reserveIn,) = IUni(pool).getReserves();
uint receiveBaseAmount;
{
(uint256 fee, uint256 denFee) = abi.decode(data, (uint256, uint256));
require(reserveIn > 0 && reserveOut > 0, 'UniAdapter: INSUFFICIENT_LIQUIDITY');
uint balance1 = IERC20(quoteToken).balanceOf(pool);
uint sellQuoteAmount = balance1 - reserveIn;
uint sellQuoteAmountWithFee = sellQuoteAmount.mul(997);
uint sellQuoteAmountWithFee = sellQuoteAmount.mul(denFee - fee);
uint numerator = sellQuoteAmountWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(sellQuoteAmountWithFee);
uint receiveBaseAmount = numerator / denominator;
uint denominator = reserveIn.mul(denFee).add(sellQuoteAmountWithFee);
receiveBaseAmount = numerator / denominator;
}
IUni(pool).swap(receiveBaseAmount, 0, to, new bytes(0));
}
}

View File

@@ -1,4 +1,5 @@
pragma solidity 0.6.9;
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface