* FQT: Pack Protocol/source name into source ID (#162) * `@0x/contracts-zero-ex`: Encode protocol ID and source name in bridge source ID `@0x/asset-swapper`: Use new bridge source ID encoding. * fix linter issues * contracts cleanup (#164) * `@0x/contracts-zero-ex`: Add PancakeSwapFeature * `@0x/contracts-zero-ex`: Remove tokenspender/allowance target/greedy tokens stuff.' `@0x/contract-addresses`: Add BSC addresses. Remove exchangeProxyAllowanceTarget. `@0x/migrations`: Remove exchangeProxyAllowanceTarget. * Update contracts/zero-ex/contracts/src/features/IPancakeSwapFeature.sol Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> * `@0x/contracts-zero-ex`: Add sushiswap support to PancakeSwap * `@0x/contract-artifacts`: Regenerate artifacts `@0x/contract-wrappers`: Regenerate wrappers * `@0x/contract-addresses`: Add BSC addresses Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> * feat: Better chain support (#163) * feat: Better chain support * feat: better chain support refactor deployment constants (#166) * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * Rework WETH out, replacing with address(0) * wat * hack DeploymentConstants for now * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * remove duped network addresses * Rework the bridge source encoder * Use the constants NATIVE_FEE_TOKEN in EP consumer * `@0x/contract-addresses`: Fix WBNB address (#170) Co-authored-by: Lawrence Forman <lawrence@0xproject.com> * multichain enable cakez vip (#171) * feat: Better chain support * feat: better chain support refactor deployment constants (#166) * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * Rework WETH out, replacing with address(0) * wat * hack DeploymentConstants for now * proliferate the chainId * Refactor sampler to remove DeploymentConstants dependency and fixed addresses * remove duped network addresses * `asset-swapper`: enable pancake VIP route generation Co-authored-by: Jacob Evans <jacob@dekz.net> Co-authored-by: Lawrence Forman <me@merklejerk.com> * `@0x/contracts-zero-ex`: Fix `PancakeSwapFeature` sushi values (#172) * `@0x/contracts-zero-ex`: Fix `PancakeSwapFeature` sushi values * `@0x/contracts-zero-ex`: I am a bad protocologist Co-authored-by: Lawrence Forman <me@merklejerk.com> * feat: BSC Nerve + Dodo + Nerve + Ellipsis (#181) * feat: BSC Nerve + DODO v1 * CHANGELOGs * Remove extra balance fetch * Add Belt * Added Ellipsis * Update FQT address * `@0x/contracts-zero-ex`: Delete TokenSpenderFeature and get stuff compiling * `@0x/asset-swapper`: fix compilation * prettier * `@0x/asset-swapper`: Truncate LiquidityProvider source ID name * Update packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts Co-authored-by: Jacob Evans <jacob@dekz.net> * Update packages/asset-swapper/src/utils/market_operation_utils/sampler_operations.ts Co-authored-by: Jacob Evans <jacob@dekz.net> * `@0x/contracts-zero-ex`: Fix BakerySwap on PackageSwapFeature (#190) * address review comments Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com> Co-authored-by: Jacob Evans <jacob@dekz.net> Co-authored-by: Lawrence Forman <me@merklejerk.com>
111 lines
3.7 KiB
Solidity
111 lines
3.7 KiB
Solidity
// SPDX-License-Identifier: Apache-2.0
|
|
/*
|
|
|
|
Copyright 2020 ZeroEx Intl.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
pragma solidity ^0.6;
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
import "./interfaces/IEth2Dai.sol";
|
|
import "./SamplerUtils.sol";
|
|
|
|
|
|
contract Eth2DaiSampler is
|
|
SamplerUtils
|
|
{
|
|
/// @dev Base gas limit for Eth2Dai calls.
|
|
uint256 constant private ETH2DAI_CALL_GAS = 1000e3; // 1m
|
|
|
|
/// @dev Sample sell quotes from Eth2Dai/Oasis.
|
|
/// @param router Address of the Eth2Dai/Oasis contract
|
|
/// @param takerToken Address of the taker token (what to sell).
|
|
/// @param makerToken Address of the maker token (what to buy).
|
|
/// @param takerTokenAmounts Taker token sell amount for each sample.
|
|
/// @return makerTokenAmounts Maker amounts bought at each taker token
|
|
/// amount.
|
|
function sampleSellsFromEth2Dai(
|
|
address router,
|
|
address takerToken,
|
|
address makerToken,
|
|
uint256[] memory takerTokenAmounts
|
|
)
|
|
public
|
|
view
|
|
returns (uint256[] memory makerTokenAmounts)
|
|
{
|
|
_assertValidPair(makerToken, takerToken);
|
|
uint256 numSamples = takerTokenAmounts.length;
|
|
makerTokenAmounts = new uint256[](numSamples);
|
|
for (uint256 i = 0; i < numSamples; i++) {
|
|
try
|
|
IEth2Dai(router).getBuyAmount
|
|
{gas: ETH2DAI_CALL_GAS}
|
|
(makerToken, takerToken, takerTokenAmounts[i])
|
|
returns (uint256 amount)
|
|
{
|
|
makerTokenAmounts[i] = amount;
|
|
// Break early if there are 0 amounts
|
|
if (makerTokenAmounts[i] == 0) {
|
|
break;
|
|
}
|
|
} catch (bytes memory) {
|
|
// Swallow failures, leaving all results as zero.
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// @dev Sample buy quotes from Eth2Dai/Oasis.
|
|
/// @param router Address of the Eth2Dai/Oasis contract
|
|
/// @param takerToken Address of the taker token (what to sell).
|
|
/// @param makerToken Address of the maker token (what to buy).
|
|
/// @param takerTokenAmounts Maker token sell amount for each sample.
|
|
/// @return takerTokenAmounts Taker amounts sold at each maker token
|
|
/// amount.
|
|
function sampleBuysFromEth2Dai(
|
|
address router,
|
|
address takerToken,
|
|
address makerToken,
|
|
uint256[] memory makerTokenAmounts
|
|
)
|
|
public
|
|
view
|
|
returns (uint256[] memory takerTokenAmounts)
|
|
{
|
|
_assertValidPair(makerToken, takerToken);
|
|
uint256 numSamples = makerTokenAmounts.length;
|
|
takerTokenAmounts = new uint256[](numSamples);
|
|
for (uint256 i = 0; i < numSamples; i++) {
|
|
try
|
|
IEth2Dai(router).getPayAmount
|
|
{gas: ETH2DAI_CALL_GAS}
|
|
(takerToken, makerToken, makerTokenAmounts[i])
|
|
returns (uint256 amount)
|
|
{
|
|
takerTokenAmounts[i] = amount;
|
|
// Break early if there are 0 amounts
|
|
if (takerTokenAmounts[i] == 0) {
|
|
break;
|
|
}
|
|
} catch (bytes memory) {
|
|
// Swallow failures, leaving all results as zero.
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|