Merge branch 'feature/V2' of github.com:DODOEX/contractV2 into feature/V2
This commit is contained in:
40
contracts/SmartRoute/helper/DODOSwapCalcHelper.sol
Normal file
40
contracts/SmartRoute/helper/DODOSwapCalcHelper.sol
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
|
||||
Copyright 2020 DODO ZOO.
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity 0.6.9;
|
||||
|
||||
import {IDODOV1} from "../intf/IDODOV1.sol";
|
||||
import {IDODOSellHelper} from "./DODOSellHelper.sol";
|
||||
|
||||
contract DODOSwapCalcHelper {
|
||||
address public immutable _DODO_SELL_HELPER_;
|
||||
|
||||
constructor(address dodoSellHelper) public {
|
||||
_DODO_SELL_HELPER_ = dodoSellHelper;
|
||||
}
|
||||
|
||||
function calcReturnAmountV1(
|
||||
uint256 fromTokenAmount,
|
||||
address[] memory dodoPairs,
|
||||
uint8[] memory directions
|
||||
) external view returns (uint256 returnAmount,uint256[] memory midPrices) {
|
||||
returnAmount = fromTokenAmount;
|
||||
midPrices = new uint256[](dodoPairs.length);
|
||||
for (uint256 i = 0; i < dodoPairs.length; i++) {
|
||||
address curDodoPair = dodoPairs[i];
|
||||
if (directions[i] == 0) {
|
||||
returnAmount = IDODOV1(curDodoPair).querySellBaseToken(returnAmount);
|
||||
} else {
|
||||
returnAmount = IDODOSellHelper(_DODO_SELL_HELPER_).querySellQuoteToken(
|
||||
curDodoPair,
|
||||
returnAmount
|
||||
);
|
||||
}
|
||||
midPrices[i] = IDODOV1(curDodoPair).getMidPrice();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,4 +77,6 @@ interface IDODOV1 {
|
||||
function getExpectedTarget() external view returns (uint256 baseTarget, uint256 quoteTarget);
|
||||
|
||||
function getOraclePrice() external view returns (uint256);
|
||||
|
||||
function getMidPrice() external view returns (uint256 midPrice);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user