Offboard/clean up Oasis, CoFix, and legacy Kyber [TKR-405] (#482)
* Remove Oasis * Remove CoFix code * Remove MixinKyber * Remove Kyber from asset-swapper * Delete unused imports, interface, and etc. * Fix the test failure issue when it's run with neon-router * Update CHANGELOG.json
This commit is contained in:
parent
4057bdab91
commit
2d16f83e37
@ -40,7 +40,6 @@ import "./mixins/MixinMakerPSM.sol";
|
|||||||
import "./mixins/MixinMooniswap.sol";
|
import "./mixins/MixinMooniswap.sol";
|
||||||
import "./mixins/MixinMStable.sol";
|
import "./mixins/MixinMStable.sol";
|
||||||
import "./mixins/MixinNerve.sol";
|
import "./mixins/MixinNerve.sol";
|
||||||
import "./mixins/MixinOasis.sol";
|
|
||||||
import "./mixins/MixinPlatypus.sol";
|
import "./mixins/MixinPlatypus.sol";
|
||||||
import "./mixins/MixinShell.sol";
|
import "./mixins/MixinShell.sol";
|
||||||
import "./mixins/MixinUniswap.sol";
|
import "./mixins/MixinUniswap.sol";
|
||||||
@ -68,7 +67,6 @@ contract BridgeAdapter is
|
|||||||
MixinMooniswap,
|
MixinMooniswap,
|
||||||
MixinMStable,
|
MixinMStable,
|
||||||
MixinNerve,
|
MixinNerve,
|
||||||
MixinOasis,
|
|
||||||
MixinPlatypus,
|
MixinPlatypus,
|
||||||
MixinShell,
|
MixinShell,
|
||||||
MixinUniswap,
|
MixinUniswap,
|
||||||
@ -94,7 +92,6 @@ contract BridgeAdapter is
|
|||||||
MixinMooniswap(weth)
|
MixinMooniswap(weth)
|
||||||
MixinMStable()
|
MixinMStable()
|
||||||
MixinNerve()
|
MixinNerve()
|
||||||
MixinOasis()
|
|
||||||
MixinPlatypus()
|
MixinPlatypus()
|
||||||
MixinShell()
|
MixinShell()
|
||||||
MixinUniswap(weth)
|
MixinUniswap(weth)
|
||||||
@ -187,13 +184,6 @@ contract BridgeAdapter is
|
|||||||
sellAmount,
|
sellAmount,
|
||||||
order.bridgeData
|
order.bridgeData
|
||||||
);
|
);
|
||||||
} else if (protocolId == BridgeProtocols.OASIS) {
|
|
||||||
boughtAmount = _tradeOasis(
|
|
||||||
sellToken,
|
|
||||||
buyToken,
|
|
||||||
sellAmount,
|
|
||||||
order.bridgeData
|
|
||||||
);
|
|
||||||
} else if (protocolId == BridgeProtocols.SHELL) {
|
} else if (protocolId == BridgeProtocols.SHELL) {
|
||||||
boughtAmount = _tradeShell(
|
boughtAmount = _tradeShell(
|
||||||
sellToken,
|
sellToken,
|
||||||
|
@ -32,16 +32,16 @@ library BridgeProtocols {
|
|||||||
uint128 internal constant UNISWAPV2 = 2;
|
uint128 internal constant UNISWAPV2 = 2;
|
||||||
uint128 internal constant UNISWAP = 3;
|
uint128 internal constant UNISWAP = 3;
|
||||||
uint128 internal constant BALANCER = 4;
|
uint128 internal constant BALANCER = 4;
|
||||||
uint128 internal constant KYBER = 5;
|
uint128 internal constant KYBER = 5; // Not used: deprecated.
|
||||||
uint128 internal constant MOONISWAP = 6;
|
uint128 internal constant MOONISWAP = 6;
|
||||||
uint128 internal constant MSTABLE = 7;
|
uint128 internal constant MSTABLE = 7;
|
||||||
uint128 internal constant OASIS = 8;
|
uint128 internal constant OASIS = 8; // Not used: deprecated.
|
||||||
uint128 internal constant SHELL = 9;
|
uint128 internal constant SHELL = 9;
|
||||||
uint128 internal constant DODO = 10;
|
uint128 internal constant DODO = 10;
|
||||||
uint128 internal constant DODOV2 = 11;
|
uint128 internal constant DODOV2 = 11;
|
||||||
uint128 internal constant CRYPTOCOM = 12;
|
uint128 internal constant CRYPTOCOM = 12;
|
||||||
uint128 internal constant BANCOR = 13;
|
uint128 internal constant BANCOR = 13;
|
||||||
uint128 internal constant COFIX = 14;
|
uint128 internal constant COFIX = 14; // Not used: deprecated.
|
||||||
uint128 internal constant NERVE = 15;
|
uint128 internal constant NERVE = 15;
|
||||||
uint128 internal constant MAKERPSM = 16;
|
uint128 internal constant MAKERPSM = 16;
|
||||||
uint128 internal constant BALANCERV2 = 17;
|
uint128 internal constant BALANCERV2 = 17;
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
// 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.5;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
|
||||||
|
|
||||||
|
|
||||||
interface ICoFiXRouter {
|
|
||||||
// msg.value = fee
|
|
||||||
function swapExactTokensForETH(
|
|
||||||
address token,
|
|
||||||
uint amountIn,
|
|
||||||
uint amountOutMin,
|
|
||||||
address to,
|
|
||||||
address rewardTo,
|
|
||||||
uint deadline
|
|
||||||
) external payable returns (uint _amountIn, uint _amountOut);
|
|
||||||
|
|
||||||
// msg.value = amountIn + fee
|
|
||||||
function swapExactETHForTokens(
|
|
||||||
address token,
|
|
||||||
uint amountIn,
|
|
||||||
uint amountOutMin,
|
|
||||||
address to,
|
|
||||||
address rewardTo,
|
|
||||||
uint deadline
|
|
||||||
) external payable returns (uint _amountIn, uint _amountOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ICoFiXPair {
|
|
||||||
|
|
||||||
function swapWithExact(address outToken, address to)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (
|
|
||||||
uint amountIn,
|
|
||||||
uint amountOut,
|
|
||||||
uint oracleFeeChange,
|
|
||||||
uint256[4] memory tradeInfo
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
contract MixinCoFiX {
|
|
||||||
|
|
||||||
using LibERC20TokenV06 for IERC20TokenV06;
|
|
||||||
|
|
||||||
function _tradeCoFiX(
|
|
||||||
IERC20TokenV06 sellToken,
|
|
||||||
IERC20TokenV06 buyToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
bytes memory bridgeData
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
returns (uint256 boughtAmount)
|
|
||||||
{
|
|
||||||
(uint256 fee, ICoFiXPair pool) = abi.decode(bridgeData, (uint256, ICoFiXPair));
|
|
||||||
// Transfer tokens into the pool
|
|
||||||
LibERC20TokenV06.compatTransfer(
|
|
||||||
sellToken,
|
|
||||||
address(pool),
|
|
||||||
sellAmount
|
|
||||||
);
|
|
||||||
// Call the swap exact with the tokens now in the pool
|
|
||||||
// pay the NEST Oracle fee with ETH
|
|
||||||
(/* In */, boughtAmount, , ) = pool.swapWithExact{value: fee}(
|
|
||||||
address(buyToken),
|
|
||||||
address(this)
|
|
||||||
);
|
|
||||||
|
|
||||||
return boughtAmount;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,124 +0,0 @@
|
|||||||
// 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.5;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/IEtherTokenV06.sol";
|
|
||||||
import "../IBridgeAdapter.sol";
|
|
||||||
|
|
||||||
interface IKyberNetworkProxy {
|
|
||||||
|
|
||||||
/// @dev Sells `sellTokenAddress` tokens for `buyTokenAddress` tokens
|
|
||||||
/// using a hint for the reserve.
|
|
||||||
/// @param sellToken Token to sell.
|
|
||||||
/// @param sellAmount Amount of tokens to sell.
|
|
||||||
/// @param buyToken Token to buy.
|
|
||||||
/// @param recipientAddress Address to send bought tokens to.
|
|
||||||
/// @param maxBuyTokenAmount A limit on the amount of tokens to buy.
|
|
||||||
/// @param minConversionRate The minimal conversion rate. If actual rate
|
|
||||||
/// is lower, trade is canceled.
|
|
||||||
/// @param walletId The wallet ID to send part of the fees
|
|
||||||
/// @param hint The hint for the selective inclusion (or exclusion) of reserves
|
|
||||||
/// @return boughtAmount Amount of tokens bought.
|
|
||||||
function tradeWithHint(
|
|
||||||
IERC20TokenV06 sellToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
IERC20TokenV06 buyToken,
|
|
||||||
address payable recipientAddress,
|
|
||||||
uint256 maxBuyTokenAmount,
|
|
||||||
uint256 minConversionRate,
|
|
||||||
address payable walletId,
|
|
||||||
bytes calldata hint
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (uint256 boughtAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
contract MixinKyber {
|
|
||||||
|
|
||||||
using LibERC20TokenV06 for IERC20TokenV06;
|
|
||||||
|
|
||||||
/// @dev Address indicating the trade is using ETH
|
|
||||||
IERC20TokenV06 private immutable KYBER_ETH_ADDRESS =
|
|
||||||
IERC20TokenV06(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
|
|
||||||
/// @dev Mainnet address of the WETH contract.
|
|
||||||
IEtherTokenV06 private immutable WETH;
|
|
||||||
|
|
||||||
constructor(IEtherTokenV06 weth)
|
|
||||||
public
|
|
||||||
{
|
|
||||||
WETH = weth;
|
|
||||||
}
|
|
||||||
|
|
||||||
function _tradeKyber(
|
|
||||||
IERC20TokenV06 sellToken,
|
|
||||||
IERC20TokenV06 buyToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
bytes memory bridgeData
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
returns (uint256 boughtAmount)
|
|
||||||
{
|
|
||||||
(IKyberNetworkProxy kyber, bytes memory hint) =
|
|
||||||
abi.decode(bridgeData, (IKyberNetworkProxy, bytes));
|
|
||||||
|
|
||||||
uint256 payableAmount = 0;
|
|
||||||
if (sellToken != WETH) {
|
|
||||||
// If the input token is not WETH, grant an allowance to the exchange
|
|
||||||
// to spend them.
|
|
||||||
sellToken.approveIfBelow(
|
|
||||||
address(kyber),
|
|
||||||
sellAmount
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
// If the input token is WETH, unwrap it and attach it to the call.
|
|
||||||
payableAmount = sellAmount;
|
|
||||||
WETH.withdraw(payableAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to sell all of this contract's input token balance through
|
|
||||||
// `KyberNetworkProxy.trade()`.
|
|
||||||
boughtAmount = kyber.tradeWithHint{ value: payableAmount }(
|
|
||||||
// Input token.
|
|
||||||
sellToken == WETH ? KYBER_ETH_ADDRESS : sellToken,
|
|
||||||
// Sell amount.
|
|
||||||
sellAmount,
|
|
||||||
// Output token.
|
|
||||||
buyToken == WETH ? KYBER_ETH_ADDRESS : buyToken,
|
|
||||||
// Transfer to this contract
|
|
||||||
address(uint160(address(this))),
|
|
||||||
// Buy as much as possible.
|
|
||||||
uint256(-1),
|
|
||||||
// Lowest minimum conversion rate
|
|
||||||
1,
|
|
||||||
// No affiliate address.
|
|
||||||
address(0),
|
|
||||||
hint
|
|
||||||
);
|
|
||||||
// If receving ETH, wrap it to WETH.
|
|
||||||
if (buyToken == WETH) {
|
|
||||||
WETH.deposit{ value: boughtAmount }();
|
|
||||||
}
|
|
||||||
return boughtAmount;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
// 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.5;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
|
|
||||||
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
|
|
||||||
import "../IBridgeAdapter.sol";
|
|
||||||
|
|
||||||
interface IOasis {
|
|
||||||
|
|
||||||
/// @dev Sell `sellAmount` of `sellToken` token and receive `buyToken` token.
|
|
||||||
/// @param sellToken The token being sold.
|
|
||||||
/// @param sellAmount The amount of `sellToken` token being sold.
|
|
||||||
/// @param buyToken The token being bought.
|
|
||||||
/// @param minBoughtAmount Minimum amount of `buyToken` token to buy.
|
|
||||||
/// @return boughtAmount Amount of `buyToken` bought.
|
|
||||||
function sellAllAmount(
|
|
||||||
IERC20TokenV06 sellToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
IERC20TokenV06 buyToken,
|
|
||||||
uint256 minBoughtAmount
|
|
||||||
)
|
|
||||||
external
|
|
||||||
returns (uint256 boughtAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
contract MixinOasis {
|
|
||||||
|
|
||||||
using LibERC20TokenV06 for IERC20TokenV06;
|
|
||||||
|
|
||||||
function _tradeOasis(
|
|
||||||
IERC20TokenV06 sellToken,
|
|
||||||
IERC20TokenV06 buyToken,
|
|
||||||
uint256 sellAmount,
|
|
||||||
bytes memory bridgeData
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
returns (uint256 boughtAmount)
|
|
||||||
{
|
|
||||||
|
|
||||||
(IOasis oasis) = abi.decode(bridgeData, (IOasis));
|
|
||||||
|
|
||||||
// Grant an allowance to the exchange to spend `sellToken` token.
|
|
||||||
sellToken.approveIfBelow(
|
|
||||||
address(oasis),
|
|
||||||
sellAmount
|
|
||||||
);
|
|
||||||
// Try to sell all of this contract's `sellToken` token balance.
|
|
||||||
boughtAmount = oasis.sellAllAmount(
|
|
||||||
sellToken,
|
|
||||||
sellAmount,
|
|
||||||
buyToken,
|
|
||||||
// min fill amount
|
|
||||||
1
|
|
||||||
);
|
|
||||||
return boughtAmount;
|
|
||||||
}
|
|
||||||
}
|
|
@ -43,7 +43,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,BridgeAdapter,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature",
|
"publicInterfaceContracts": "IZeroEx,ZeroEx,FullMigration,InitialMigration,IFlashWallet,IERC20Transformer,IOwnableFeature,ISimpleFunctionRegistryFeature,ITransformERC20Feature,FillQuoteTransformer,PayTakerTransformer,PositiveSlippageFeeTransformer,WethTransformer,OwnableFeature,SimpleFunctionRegistryFeature,TransformERC20Feature,AffiliateFeeTransformer,MetaTransactionsFeature,LogMetadataTransformer,BridgeAdapter,LiquidityProviderFeature,ILiquidityProviderFeature,NativeOrdersFeature,INativeOrdersFeature,FeeCollectorController,FeeCollector,CurveLiquidityProvider,BatchFillNativeOrdersFeature,IBatchFillNativeOrdersFeature,MultiplexFeature,IMultiplexFeature,OtcOrdersFeature,IOtcOrdersFeature",
|
||||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||||
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBalancerV2Batch|MixinBancor|MixinCoFiX|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyber|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinOasis|MixinPlatypus|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
|
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|BatchFillNativeOrdersFeature|BootstrapFeature|BridgeAdapter|BridgeProtocols|CurveLiquidityProvider|ERC1155OrdersFeature|ERC165Feature|ERC721OrdersFeature|FeeCollector|FeeCollectorController|FillQuoteTransformer|FixinCommon|FixinEIP712|FixinERC1155Spender|FixinERC721Spender|FixinProtocolFees|FixinReentrancyGuard|FixinTokenSpender|FlashWallet|FullMigration|FundRecoveryFeature|IBatchFillNativeOrdersFeature|IBootstrapFeature|IBridgeAdapter|IERC1155OrdersFeature|IERC1155Token|IERC165Feature|IERC20Bridge|IERC20Transformer|IERC721OrdersFeature|IERC721Token|IFeature|IFeeRecipient|IFlashWallet|IFundRecoveryFeature|ILiquidityProvider|ILiquidityProviderFeature|ILiquidityProviderSandbox|IMetaTransactionsFeature|IMooniswapPool|IMultiplexFeature|INativeOrdersEvents|INativeOrdersFeature|IOtcOrdersFeature|IOwnableFeature|IPancakeSwapFeature|IPropertyValidator|ISimpleFunctionRegistryFeature|IStaking|ITakerCallback|ITestSimpleFunctionRegistryFeature|ITokenSpenderFeature|ITransformERC20Feature|IUniswapFeature|IUniswapV2Pair|IUniswapV3Feature|IUniswapV3Pool|IZeroEx|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC1155OrdersStorage|LibERC20Transformer|LibERC721OrdersStorage|LibFeeCollector|LibLiquidityProviderRichErrors|LibMetaTransactionsRichErrors|LibMetaTransactionsStorage|LibMigrate|LibNFTOrder|LibNFTOrdersRichErrors|LibNativeOrder|LibNativeOrdersRichErrors|LibNativeOrdersStorage|LibOtcOrdersStorage|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibReentrancyGuardStorage|LibSignature|LibSignatureRichErrors|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|LiquidityProviderFeature|LiquidityProviderSandbox|LogMetadataTransformer|MetaTransactionsFeature|MixinAaveV2|MixinBalancer|MixinBalancerV2|MixinBalancerV2Batch|MixinBancor|MixinCompound|MixinCryptoCom|MixinCurve|MixinCurveV2|MixinDodo|MixinDodoV2|MixinGMX|MixinKyberDmm|MixinLido|MixinMStable|MixinMakerPSM|MixinMooniswap|MixinNerve|MixinPlatypus|MixinShell|MixinUniswap|MixinUniswapV2|MixinUniswapV3|MixinZeroExBridge|MooniswapLiquidityProvider|MultiplexFeature|MultiplexLiquidityProvider|MultiplexOtc|MultiplexRfq|MultiplexTransformERC20|MultiplexUniswapV2|MultiplexUniswapV3|NFTOrders|NativeOrdersCancellation|NativeOrdersFeature|NativeOrdersInfo|NativeOrdersProtocolFees|NativeOrdersSettlement|OtcOrdersFeature|OwnableFeature|PancakeSwapFeature|PayTakerTransformer|PermissionlessTransformerDeployer|PositiveSlippageFeeTransformer|SimpleFunctionRegistryFeature|TestBridge|TestCallTarget|TestCurve|TestDelegateCaller|TestFeeCollectorController|TestFeeRecipient|TestFillQuoteTransformerBridge|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFixinProtocolFees|TestFixinTokenSpender|TestFullMigration|TestInitialMigration|TestLibNativeOrder|TestLibSignature|TestLiquidityProvider|TestMetaTransactionsNativeOrdersFeature|TestMetaTransactionsTransformERC20Feature|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC1155Token|TestMintableERC20Token|TestMintableERC721Token|TestMooniswap|TestNFTOrderPresigner|TestNativeOrdersFeature|TestNoEthRecipient|TestOrderSignerRegistryWithContractWallet|TestPermissionlessTransformerDeployerSuicidal|TestPermissionlessTransformerDeployerTransformer|TestPropertyValidator|TestRfqOriginRegistration|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestStaking|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestUniswapV2Factory|TestUniswapV2Pool|TestUniswapV3Factory|TestUniswapV3Feature|TestUniswapV3Pool|TestWeth|TestWethTransformerHost|TestZeroExFeature|TransformERC20Feature|Transformer|TransformerDeployer|UniswapFeature|UniswapV3Feature|WethTransformer|ZeroEx|ZeroExOptimized).json"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -103,7 +103,6 @@ import * as MixinBalancer from '../test/generated-artifacts/MixinBalancer.json';
|
|||||||
import * as MixinBalancerV2 from '../test/generated-artifacts/MixinBalancerV2.json';
|
import * as MixinBalancerV2 from '../test/generated-artifacts/MixinBalancerV2.json';
|
||||||
import * as MixinBalancerV2Batch from '../test/generated-artifacts/MixinBalancerV2Batch.json';
|
import * as MixinBalancerV2Batch from '../test/generated-artifacts/MixinBalancerV2Batch.json';
|
||||||
import * as MixinBancor from '../test/generated-artifacts/MixinBancor.json';
|
import * as MixinBancor from '../test/generated-artifacts/MixinBancor.json';
|
||||||
import * as MixinCoFiX from '../test/generated-artifacts/MixinCoFiX.json';
|
|
||||||
import * as MixinCompound from '../test/generated-artifacts/MixinCompound.json';
|
import * as MixinCompound from '../test/generated-artifacts/MixinCompound.json';
|
||||||
import * as MixinCryptoCom from '../test/generated-artifacts/MixinCryptoCom.json';
|
import * as MixinCryptoCom from '../test/generated-artifacts/MixinCryptoCom.json';
|
||||||
import * as MixinCurve from '../test/generated-artifacts/MixinCurve.json';
|
import * as MixinCurve from '../test/generated-artifacts/MixinCurve.json';
|
||||||
@ -111,14 +110,12 @@ import * as MixinCurveV2 from '../test/generated-artifacts/MixinCurveV2.json';
|
|||||||
import * as MixinDodo from '../test/generated-artifacts/MixinDodo.json';
|
import * as MixinDodo from '../test/generated-artifacts/MixinDodo.json';
|
||||||
import * as MixinDodoV2 from '../test/generated-artifacts/MixinDodoV2.json';
|
import * as MixinDodoV2 from '../test/generated-artifacts/MixinDodoV2.json';
|
||||||
import * as MixinGMX from '../test/generated-artifacts/MixinGMX.json';
|
import * as MixinGMX from '../test/generated-artifacts/MixinGMX.json';
|
||||||
import * as MixinKyber from '../test/generated-artifacts/MixinKyber.json';
|
|
||||||
import * as MixinKyberDmm from '../test/generated-artifacts/MixinKyberDmm.json';
|
import * as MixinKyberDmm from '../test/generated-artifacts/MixinKyberDmm.json';
|
||||||
import * as MixinLido from '../test/generated-artifacts/MixinLido.json';
|
import * as MixinLido from '../test/generated-artifacts/MixinLido.json';
|
||||||
import * as MixinMakerPSM from '../test/generated-artifacts/MixinMakerPSM.json';
|
import * as MixinMakerPSM from '../test/generated-artifacts/MixinMakerPSM.json';
|
||||||
import * as MixinMooniswap from '../test/generated-artifacts/MixinMooniswap.json';
|
import * as MixinMooniswap from '../test/generated-artifacts/MixinMooniswap.json';
|
||||||
import * as MixinMStable from '../test/generated-artifacts/MixinMStable.json';
|
import * as MixinMStable from '../test/generated-artifacts/MixinMStable.json';
|
||||||
import * as MixinNerve from '../test/generated-artifacts/MixinNerve.json';
|
import * as MixinNerve from '../test/generated-artifacts/MixinNerve.json';
|
||||||
import * as MixinOasis from '../test/generated-artifacts/MixinOasis.json';
|
|
||||||
import * as MixinPlatypus from '../test/generated-artifacts/MixinPlatypus.json';
|
import * as MixinPlatypus from '../test/generated-artifacts/MixinPlatypus.json';
|
||||||
import * as MixinShell from '../test/generated-artifacts/MixinShell.json';
|
import * as MixinShell from '../test/generated-artifacts/MixinShell.json';
|
||||||
import * as MixinUniswap from '../test/generated-artifacts/MixinUniswap.json';
|
import * as MixinUniswap from '../test/generated-artifacts/MixinUniswap.json';
|
||||||
@ -318,7 +315,6 @@ export const artifacts = {
|
|||||||
MixinBalancerV2: MixinBalancerV2 as ContractArtifact,
|
MixinBalancerV2: MixinBalancerV2 as ContractArtifact,
|
||||||
MixinBalancerV2Batch: MixinBalancerV2Batch as ContractArtifact,
|
MixinBalancerV2Batch: MixinBalancerV2Batch as ContractArtifact,
|
||||||
MixinBancor: MixinBancor as ContractArtifact,
|
MixinBancor: MixinBancor as ContractArtifact,
|
||||||
MixinCoFiX: MixinCoFiX as ContractArtifact,
|
|
||||||
MixinCompound: MixinCompound as ContractArtifact,
|
MixinCompound: MixinCompound as ContractArtifact,
|
||||||
MixinCryptoCom: MixinCryptoCom as ContractArtifact,
|
MixinCryptoCom: MixinCryptoCom as ContractArtifact,
|
||||||
MixinCurve: MixinCurve as ContractArtifact,
|
MixinCurve: MixinCurve as ContractArtifact,
|
||||||
@ -326,14 +322,12 @@ export const artifacts = {
|
|||||||
MixinDodo: MixinDodo as ContractArtifact,
|
MixinDodo: MixinDodo as ContractArtifact,
|
||||||
MixinDodoV2: MixinDodoV2 as ContractArtifact,
|
MixinDodoV2: MixinDodoV2 as ContractArtifact,
|
||||||
MixinGMX: MixinGMX as ContractArtifact,
|
MixinGMX: MixinGMX as ContractArtifact,
|
||||||
MixinKyber: MixinKyber as ContractArtifact,
|
|
||||||
MixinKyberDmm: MixinKyberDmm as ContractArtifact,
|
MixinKyberDmm: MixinKyberDmm as ContractArtifact,
|
||||||
MixinLido: MixinLido as ContractArtifact,
|
MixinLido: MixinLido as ContractArtifact,
|
||||||
MixinMStable: MixinMStable as ContractArtifact,
|
MixinMStable: MixinMStable as ContractArtifact,
|
||||||
MixinMakerPSM: MixinMakerPSM as ContractArtifact,
|
MixinMakerPSM: MixinMakerPSM as ContractArtifact,
|
||||||
MixinMooniswap: MixinMooniswap as ContractArtifact,
|
MixinMooniswap: MixinMooniswap as ContractArtifact,
|
||||||
MixinNerve: MixinNerve as ContractArtifact,
|
MixinNerve: MixinNerve as ContractArtifact,
|
||||||
MixinOasis: MixinOasis as ContractArtifact,
|
|
||||||
MixinPlatypus: MixinPlatypus as ContractArtifact,
|
MixinPlatypus: MixinPlatypus as ContractArtifact,
|
||||||
MixinShell: MixinShell as ContractArtifact,
|
MixinShell: MixinShell as ContractArtifact,
|
||||||
MixinUniswap: MixinUniswap as ContractArtifact,
|
MixinUniswap: MixinUniswap as ContractArtifact,
|
||||||
|
@ -101,7 +101,6 @@ export * from '../test/generated-wrappers/mixin_balancer';
|
|||||||
export * from '../test/generated-wrappers/mixin_balancer_v2';
|
export * from '../test/generated-wrappers/mixin_balancer_v2';
|
||||||
export * from '../test/generated-wrappers/mixin_balancer_v2_batch';
|
export * from '../test/generated-wrappers/mixin_balancer_v2_batch';
|
||||||
export * from '../test/generated-wrappers/mixin_bancor';
|
export * from '../test/generated-wrappers/mixin_bancor';
|
||||||
export * from '../test/generated-wrappers/mixin_co_fi_x';
|
|
||||||
export * from '../test/generated-wrappers/mixin_compound';
|
export * from '../test/generated-wrappers/mixin_compound';
|
||||||
export * from '../test/generated-wrappers/mixin_crypto_com';
|
export * from '../test/generated-wrappers/mixin_crypto_com';
|
||||||
export * from '../test/generated-wrappers/mixin_curve';
|
export * from '../test/generated-wrappers/mixin_curve';
|
||||||
@ -109,14 +108,12 @@ export * from '../test/generated-wrappers/mixin_curve_v2';
|
|||||||
export * from '../test/generated-wrappers/mixin_dodo';
|
export * from '../test/generated-wrappers/mixin_dodo';
|
||||||
export * from '../test/generated-wrappers/mixin_dodo_v2';
|
export * from '../test/generated-wrappers/mixin_dodo_v2';
|
||||||
export * from '../test/generated-wrappers/mixin_g_m_x';
|
export * from '../test/generated-wrappers/mixin_g_m_x';
|
||||||
export * from '../test/generated-wrappers/mixin_kyber';
|
|
||||||
export * from '../test/generated-wrappers/mixin_kyber_dmm';
|
export * from '../test/generated-wrappers/mixin_kyber_dmm';
|
||||||
export * from '../test/generated-wrappers/mixin_lido';
|
export * from '../test/generated-wrappers/mixin_lido';
|
||||||
export * from '../test/generated-wrappers/mixin_m_stable';
|
export * from '../test/generated-wrappers/mixin_m_stable';
|
||||||
export * from '../test/generated-wrappers/mixin_maker_p_s_m';
|
export * from '../test/generated-wrappers/mixin_maker_p_s_m';
|
||||||
export * from '../test/generated-wrappers/mixin_mooniswap';
|
export * from '../test/generated-wrappers/mixin_mooniswap';
|
||||||
export * from '../test/generated-wrappers/mixin_nerve';
|
export * from '../test/generated-wrappers/mixin_nerve';
|
||||||
export * from '../test/generated-wrappers/mixin_oasis';
|
|
||||||
export * from '../test/generated-wrappers/mixin_platypus';
|
export * from '../test/generated-wrappers/mixin_platypus';
|
||||||
export * from '../test/generated-wrappers/mixin_shell';
|
export * from '../test/generated-wrappers/mixin_shell';
|
||||||
export * from '../test/generated-wrappers/mixin_uniswap';
|
export * from '../test/generated-wrappers/mixin_uniswap';
|
||||||
|
@ -134,7 +134,6 @@
|
|||||||
"test/generated-artifacts/MixinBalancerV2.json",
|
"test/generated-artifacts/MixinBalancerV2.json",
|
||||||
"test/generated-artifacts/MixinBalancerV2Batch.json",
|
"test/generated-artifacts/MixinBalancerV2Batch.json",
|
||||||
"test/generated-artifacts/MixinBancor.json",
|
"test/generated-artifacts/MixinBancor.json",
|
||||||
"test/generated-artifacts/MixinCoFiX.json",
|
|
||||||
"test/generated-artifacts/MixinCompound.json",
|
"test/generated-artifacts/MixinCompound.json",
|
||||||
"test/generated-artifacts/MixinCryptoCom.json",
|
"test/generated-artifacts/MixinCryptoCom.json",
|
||||||
"test/generated-artifacts/MixinCurve.json",
|
"test/generated-artifacts/MixinCurve.json",
|
||||||
@ -142,14 +141,12 @@
|
|||||||
"test/generated-artifacts/MixinDodo.json",
|
"test/generated-artifacts/MixinDodo.json",
|
||||||
"test/generated-artifacts/MixinDodoV2.json",
|
"test/generated-artifacts/MixinDodoV2.json",
|
||||||
"test/generated-artifacts/MixinGMX.json",
|
"test/generated-artifacts/MixinGMX.json",
|
||||||
"test/generated-artifacts/MixinKyber.json",
|
|
||||||
"test/generated-artifacts/MixinKyberDmm.json",
|
"test/generated-artifacts/MixinKyberDmm.json",
|
||||||
"test/generated-artifacts/MixinLido.json",
|
"test/generated-artifacts/MixinLido.json",
|
||||||
"test/generated-artifacts/MixinMStable.json",
|
"test/generated-artifacts/MixinMStable.json",
|
||||||
"test/generated-artifacts/MixinMakerPSM.json",
|
"test/generated-artifacts/MixinMakerPSM.json",
|
||||||
"test/generated-artifacts/MixinMooniswap.json",
|
"test/generated-artifacts/MixinMooniswap.json",
|
||||||
"test/generated-artifacts/MixinNerve.json",
|
"test/generated-artifacts/MixinNerve.json",
|
||||||
"test/generated-artifacts/MixinOasis.json",
|
|
||||||
"test/generated-artifacts/MixinPlatypus.json",
|
"test/generated-artifacts/MixinPlatypus.json",
|
||||||
"test/generated-artifacts/MixinShell.json",
|
"test/generated-artifacts/MixinShell.json",
|
||||||
"test/generated-artifacts/MixinUniswap.json",
|
"test/generated-artifacts/MixinUniswap.json",
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"version": "16.61.0",
|
||||||
|
"changes": [
|
||||||
|
{
|
||||||
|
"note": "Offboard/clean up Oasis, CoFix, and legacy Kyber",
|
||||||
|
"pr": 482
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "16.60.1",
|
"version": "16.60.1",
|
||||||
"changes": [
|
"changes": [
|
||||||
|
@ -29,7 +29,6 @@ import "./CurveSampler.sol";
|
|||||||
import "./DODOSampler.sol";
|
import "./DODOSampler.sol";
|
||||||
import "./DODOV2Sampler.sol";
|
import "./DODOV2Sampler.sol";
|
||||||
import "./GMXSampler.sol";
|
import "./GMXSampler.sol";
|
||||||
import "./KyberSampler.sol";
|
|
||||||
import "./KyberDmmSampler.sol";
|
import "./KyberDmmSampler.sol";
|
||||||
import "./LidoSampler.sol";
|
import "./LidoSampler.sol";
|
||||||
import "./LiquidityProviderSampler.sol";
|
import "./LiquidityProviderSampler.sol";
|
||||||
@ -57,7 +56,6 @@ contract ERC20BridgeSampler is
|
|||||||
DODOSampler,
|
DODOSampler,
|
||||||
DODOV2Sampler,
|
DODOV2Sampler,
|
||||||
GMXSampler,
|
GMXSampler,
|
||||||
KyberSampler,
|
|
||||||
KyberDmmSampler,
|
KyberDmmSampler,
|
||||||
LidoSampler,
|
LidoSampler,
|
||||||
LiquidityProviderSampler,
|
LiquidityProviderSampler,
|
||||||
|
@ -1,301 +0,0 @@
|
|||||||
// 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/IKyberNetwork.sol";
|
|
||||||
import "./ApproximateBuys.sol";
|
|
||||||
import "./SamplerUtils.sol";
|
|
||||||
|
|
||||||
|
|
||||||
contract KyberSampler is
|
|
||||||
SamplerUtils,
|
|
||||||
ApproximateBuys
|
|
||||||
{
|
|
||||||
/// @dev Gas limit for Kyber calls.
|
|
||||||
uint256 constant private KYBER_CALL_GAS = 500e3; // 500k
|
|
||||||
/// @dev Kyber ETH pseudo-address.
|
|
||||||
address constant internal KYBER_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
|
||||||
|
|
||||||
struct KyberSamplerOpts {
|
|
||||||
uint256 reserveOffset;
|
|
||||||
address hintHandler;
|
|
||||||
address networkProxy;
|
|
||||||
address weth;
|
|
||||||
bytes hint;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Sample sell quotes from Kyber.
|
|
||||||
/// @param opts KyberSamplerOpts The nth reserve
|
|
||||||
/// @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 reserveId The id of the reserve found at reserveOffset
|
|
||||||
/// @return hint The hint for the selected reserve
|
|
||||||
/// @return makerTokenAmounts Maker amounts bought at each taker token amount.
|
|
||||||
function sampleSellsFromKyberNetwork(
|
|
||||||
KyberSamplerOpts memory opts,
|
|
||||||
address takerToken,
|
|
||||||
address makerToken,
|
|
||||||
uint256[] memory takerTokenAmounts
|
|
||||||
)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (bytes32 reserveId, bytes memory hint, uint256[] memory makerTokenAmounts)
|
|
||||||
{
|
|
||||||
_assertValidPair(makerToken, takerToken);
|
|
||||||
reserveId = _getNextReserveId(opts, takerToken, makerToken);
|
|
||||||
if (reserveId == 0x0) {
|
|
||||||
return (reserveId, hint, makerTokenAmounts);
|
|
||||||
}
|
|
||||||
opts.hint = this.encodeKyberHint(opts, reserveId, takerToken, makerToken);
|
|
||||||
hint = opts.hint;
|
|
||||||
|
|
||||||
uint256 numSamples = takerTokenAmounts.length;
|
|
||||||
makerTokenAmounts = new uint256[](numSamples);
|
|
||||||
for (uint256 i = 0; i < numSamples; i++) {
|
|
||||||
uint256 value = this.sampleSellFromKyberNetwork(
|
|
||||||
opts,
|
|
||||||
takerToken,
|
|
||||||
makerToken,
|
|
||||||
takerTokenAmounts[i]
|
|
||||||
);
|
|
||||||
makerTokenAmounts[i] = value;
|
|
||||||
// Break early if there are 0 amounts
|
|
||||||
if (makerTokenAmounts[i] == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Sample buy quotes from Kyber.
|
|
||||||
/// @param opts KyberSamplerOpts The nth reserve
|
|
||||||
/// @param takerToken Address of the taker token (what to sell).
|
|
||||||
/// @param makerToken Address of the maker token (what to buy).
|
|
||||||
/// @param makerTokenAmounts Maker token buy amount for each sample.
|
|
||||||
/// @return reserveId The id of the reserve found at reserveOffset
|
|
||||||
/// @return hint The hint for the selected reserve
|
|
||||||
/// @return takerTokenAmounts Taker amounts sold at each maker token amount.
|
|
||||||
function sampleBuysFromKyberNetwork(
|
|
||||||
KyberSamplerOpts memory opts,
|
|
||||||
address takerToken,
|
|
||||||
address makerToken,
|
|
||||||
uint256[] memory makerTokenAmounts
|
|
||||||
)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (bytes32 reserveId, bytes memory hint, uint256[] memory takerTokenAmounts)
|
|
||||||
{
|
|
||||||
_assertValidPair(makerToken, takerToken);
|
|
||||||
|
|
||||||
reserveId = _getNextReserveId(opts, takerToken, makerToken);
|
|
||||||
if (reserveId == 0x0) {
|
|
||||||
return (reserveId, hint, takerTokenAmounts);
|
|
||||||
}
|
|
||||||
opts.hint = this.encodeKyberHint(opts, reserveId, takerToken, makerToken);
|
|
||||||
hint = opts.hint;
|
|
||||||
|
|
||||||
takerTokenAmounts = _sampleApproximateBuys(
|
|
||||||
ApproximateBuyQuoteOpts({
|
|
||||||
makerTokenData: abi.encode(makerToken, opts),
|
|
||||||
takerTokenData: abi.encode(takerToken, opts),
|
|
||||||
getSellQuoteCallback: _sampleSellForApproximateBuyFromKyber
|
|
||||||
}),
|
|
||||||
makerTokenAmounts
|
|
||||||
);
|
|
||||||
return (reserveId, hint, takerTokenAmounts);
|
|
||||||
}
|
|
||||||
|
|
||||||
function encodeKyberHint(
|
|
||||||
KyberSamplerOpts memory opts,
|
|
||||||
bytes32 reserveId,
|
|
||||||
address takerToken,
|
|
||||||
address makerToken
|
|
||||||
)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (bytes memory hint)
|
|
||||||
{
|
|
||||||
// Build a hint selecting the single reserve
|
|
||||||
IKyberHintHandler kyberHint = IKyberHintHandler(opts.hintHandler);
|
|
||||||
|
|
||||||
// All other reserves should be ignored with this hint
|
|
||||||
bytes32[] memory selectedReserves = new bytes32[](1);
|
|
||||||
selectedReserves[0] = reserveId;
|
|
||||||
uint256[] memory emptySplits = new uint256[](0);
|
|
||||||
|
|
||||||
if (takerToken == opts.weth) {
|
|
||||||
// ETH to Token
|
|
||||||
try
|
|
||||||
kyberHint.buildEthToTokenHint
|
|
||||||
{gas: KYBER_CALL_GAS}
|
|
||||||
(
|
|
||||||
makerToken,
|
|
||||||
IKyberHintHandler.TradeType.MaskIn,
|
|
||||||
selectedReserves,
|
|
||||||
emptySplits
|
|
||||||
)
|
|
||||||
returns (bytes memory result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
} catch (bytes memory) {
|
|
||||||
// Swallow failures, leaving all results as zero.
|
|
||||||
}
|
|
||||||
} else if (makerToken == opts.weth) {
|
|
||||||
// Token to ETH
|
|
||||||
try
|
|
||||||
kyberHint.buildTokenToEthHint
|
|
||||||
{gas: KYBER_CALL_GAS}
|
|
||||||
(
|
|
||||||
takerToken,
|
|
||||||
IKyberHintHandler.TradeType.MaskIn,
|
|
||||||
selectedReserves,
|
|
||||||
emptySplits
|
|
||||||
)
|
|
||||||
returns (bytes memory result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
} catch (bytes memory) {
|
|
||||||
// Swallow failures, leaving all results as zero.
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Token to Token
|
|
||||||
// We use the same reserve both ways
|
|
||||||
try
|
|
||||||
kyberHint.buildTokenToTokenHint
|
|
||||||
{gas: KYBER_CALL_GAS}
|
|
||||||
(
|
|
||||||
takerToken,
|
|
||||||
IKyberHintHandler.TradeType.MaskIn,
|
|
||||||
selectedReserves,
|
|
||||||
emptySplits,
|
|
||||||
makerToken,
|
|
||||||
IKyberHintHandler.TradeType.MaskIn,
|
|
||||||
selectedReserves,
|
|
||||||
emptySplits
|
|
||||||
)
|
|
||||||
returns (bytes memory result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
} catch (bytes memory) {
|
|
||||||
// Swallow failures, leaving all results as zero.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _sampleSellForApproximateBuyFromKyber(
|
|
||||||
bytes memory takerTokenData,
|
|
||||||
bytes memory makerTokenData,
|
|
||||||
uint256 sellAmount
|
|
||||||
)
|
|
||||||
private
|
|
||||||
view
|
|
||||||
returns (uint256)
|
|
||||||
{
|
|
||||||
(address makerToken, KyberSamplerOpts memory opts) =
|
|
||||||
abi.decode(makerTokenData, (address, KyberSamplerOpts));
|
|
||||||
(address takerToken, ) =
|
|
||||||
abi.decode(takerTokenData, (address, KyberSamplerOpts));
|
|
||||||
try
|
|
||||||
this.sampleSellFromKyberNetwork
|
|
||||||
(opts, takerToken, makerToken, sellAmount)
|
|
||||||
returns (uint256 amount)
|
|
||||||
{
|
|
||||||
return amount;
|
|
||||||
} catch (bytes memory) {
|
|
||||||
// Swallow failures, leaving all results as zero.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function sampleSellFromKyberNetwork(
|
|
||||||
KyberSamplerOpts memory opts,
|
|
||||||
address takerToken,
|
|
||||||
address makerToken,
|
|
||||||
uint256 takerTokenAmount
|
|
||||||
)
|
|
||||||
public
|
|
||||||
view
|
|
||||||
returns (uint256 makerTokenAmount)
|
|
||||||
{
|
|
||||||
// If there is no hint do not continue
|
|
||||||
if (opts.hint.length == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
IKyberNetworkProxy(opts.networkProxy).getExpectedRateAfterFee
|
|
||||||
{gas: KYBER_CALL_GAS}
|
|
||||||
(
|
|
||||||
takerToken == opts.weth ? KYBER_ETH_ADDRESS : takerToken,
|
|
||||||
makerToken == opts.weth ? KYBER_ETH_ADDRESS : makerToken,
|
|
||||||
takerTokenAmount,
|
|
||||||
0, // fee
|
|
||||||
opts.hint
|
|
||||||
)
|
|
||||||
returns (uint256 rate)
|
|
||||||
{
|
|
||||||
uint256 makerTokenDecimals = _getTokenDecimals(makerToken);
|
|
||||||
uint256 takerTokenDecimals = _getTokenDecimals(takerToken);
|
|
||||||
makerTokenAmount =
|
|
||||||
rate *
|
|
||||||
takerTokenAmount *
|
|
||||||
10 ** makerTokenDecimals /
|
|
||||||
10 ** takerTokenDecimals /
|
|
||||||
10 ** 18;
|
|
||||||
return makerTokenAmount;
|
|
||||||
} catch (bytes memory) {
|
|
||||||
// Swallow failures, leaving all results as zero.
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _getNextReserveId(
|
|
||||||
KyberSamplerOpts memory opts,
|
|
||||||
address takerToken,
|
|
||||||
address makerToken
|
|
||||||
)
|
|
||||||
internal
|
|
||||||
view
|
|
||||||
returns (bytes32 reserveId)
|
|
||||||
{
|
|
||||||
// Fetch the registered reserves for this pair
|
|
||||||
IKyberHintHandler kyberHint = IKyberHintHandler(opts.hintHandler);
|
|
||||||
(bytes32[] memory reserveIds, ,) = kyberHint.getTradingReserves(
|
|
||||||
takerToken == opts.weth ? KYBER_ETH_ADDRESS : takerToken,
|
|
||||||
makerToken == opts.weth ? KYBER_ETH_ADDRESS : makerToken,
|
|
||||||
true,
|
|
||||||
new bytes(0) // empty hint
|
|
||||||
);
|
|
||||||
|
|
||||||
if (opts.reserveOffset >= reserveIds.length) {
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
reserveId = reserveIds[opts.reserveOffset];
|
|
||||||
// Ignore Kyber Bridged Reserves (0xbb)
|
|
||||||
if (uint256(reserveId >> 248) == 0xbb) {
|
|
||||||
return 0x0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return reserveId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
// 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;
|
|
||||||
|
|
||||||
// Keepin everything together
|
|
||||||
interface IKyberNetwork {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface IKyberNetworkProxy {
|
|
||||||
|
|
||||||
function getExpectedRateAfterFee(
|
|
||||||
address src,
|
|
||||||
address dest,
|
|
||||||
uint256 srcQty,
|
|
||||||
uint256 platformFeeBps,
|
|
||||||
bytes calldata hint
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (uint256 expectedRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IKyberHintHandler {
|
|
||||||
|
|
||||||
enum TradeType {BestOfAll, MaskIn, MaskOut, Split}
|
|
||||||
|
|
||||||
enum ProcessWithRate {NotRequired, Required}
|
|
||||||
|
|
||||||
function getTradingReserves(
|
|
||||||
address tokenSrc,
|
|
||||||
address tokenDest,
|
|
||||||
bool isTokenToToken,
|
|
||||||
bytes calldata hint
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (
|
|
||||||
bytes32[] memory reserveIds,
|
|
||||||
uint256[] memory splitValuesBps,
|
|
||||||
ProcessWithRate processWithRate
|
|
||||||
);
|
|
||||||
|
|
||||||
function buildTokenToEthHint(
|
|
||||||
address tokenSrc,
|
|
||||||
TradeType tokenToEthType,
|
|
||||||
bytes32[] calldata tokenToEthReserveIds,
|
|
||||||
uint256[] calldata tokenToEthSplits
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes memory hint);
|
|
||||||
|
|
||||||
function buildEthToTokenHint(
|
|
||||||
address tokenDest,
|
|
||||||
TradeType ethToTokenType,
|
|
||||||
bytes32[] calldata ethToTokenReserveIds,
|
|
||||||
uint256[] calldata ethToTokenSplits
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes memory hint);
|
|
||||||
|
|
||||||
function buildTokenToTokenHint(
|
|
||||||
address tokenSrc,
|
|
||||||
TradeType tokenToEthType,
|
|
||||||
bytes32[] calldata tokenToEthReserveIds,
|
|
||||||
uint256[] calldata tokenToEthSplits,
|
|
||||||
address tokenDest,
|
|
||||||
TradeType ethToTokenType,
|
|
||||||
bytes32[] calldata ethToTokenReserveIds,
|
|
||||||
uint256[] calldata ethToTokenSplits
|
|
||||||
)
|
|
||||||
external
|
|
||||||
view
|
|
||||||
returns (bytes memory hint);
|
|
||||||
}
|
|
@ -39,7 +39,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker,FakeTaker",
|
"publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker,FakeTaker",
|
||||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||||
"abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2BatchSampler|BalancerV2Common|BalancerV2Sampler|BancorSampler|CompoundSampler|CurveSampler|DODOSampler|DODOV2Sampler|ERC20BridgeSampler|FakeTaker|GMXSampler|IBalancer|IBalancerV2Vault|IBancor|ICurve|IGMX|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IPlatypus|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|KyberSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|NativeOrderSampler|PlatypusSampler|SamplerUtils|ShellSampler|SmoothySampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json",
|
"abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BalancerV2BatchSampler|BalancerV2Common|BalancerV2Sampler|BancorSampler|CompoundSampler|CurveSampler|DODOSampler|DODOV2Sampler|ERC20BridgeSampler|FakeTaker|GMXSampler|IBalancer|IBalancerV2Vault|IBancor|ICurve|IGMX|IMStable|IMooniswap|IMultiBridge|IPlatypus|IShell|ISmoothy|IUniswapExchangeQuotes|IUniswapV2Router01|KyberDmmSampler|LidoSampler|LiquidityProviderSampler|MStableSampler|MakerPSMSampler|MooniswapSampler|NativeOrderSampler|PlatypusSampler|SamplerUtils|ShellSampler|SmoothySampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UniswapV3Sampler|UtilitySampler).json",
|
||||||
"postpublish": {
|
"postpublish": {
|
||||||
"assets": []
|
"assets": []
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,6 @@ export {
|
|||||||
Fill,
|
Fill,
|
||||||
FillData,
|
FillData,
|
||||||
GetMarketOrdersRfqOpts,
|
GetMarketOrdersRfqOpts,
|
||||||
KyberFillData,
|
|
||||||
LiquidityProviderFillData,
|
LiquidityProviderFillData,
|
||||||
LiquidityProviderRegistry,
|
LiquidityProviderRegistry,
|
||||||
MarketDepth,
|
MarketDepth,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChainId } from '@0x/contract-addresses';
|
import { ChainId } from '@0x/contract-addresses';
|
||||||
import { BigNumber, NULL_BYTES } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ACRYPTOS_BSC_INFOS,
|
ACRYPTOS_BSC_INFOS,
|
||||||
@ -28,10 +28,7 @@ import {
|
|||||||
IRONSWAP_POLYGON_INFOS,
|
IRONSWAP_POLYGON_INFOS,
|
||||||
JETSWAP_ROUTER_BY_CHAIN_ID,
|
JETSWAP_ROUTER_BY_CHAIN_ID,
|
||||||
JULSWAP_ROUTER_BY_CHAIN_ID,
|
JULSWAP_ROUTER_BY_CHAIN_ID,
|
||||||
KYBER_BANNED_RESERVES,
|
|
||||||
KYBER_BRIDGED_LIQUIDITY_PREFIX,
|
|
||||||
MAX_DODOV2_POOLS_QUERIED,
|
MAX_DODOV2_POOLS_QUERIED,
|
||||||
MAX_KYBER_RESERVES_QUERIED,
|
|
||||||
MOBIUSMONEY_CELO_INFOS,
|
MOBIUSMONEY_CELO_INFOS,
|
||||||
MORPHEUSSWAP_ROUTER_BY_CHAIN_ID,
|
MORPHEUSSWAP_ROUTER_BY_CHAIN_ID,
|
||||||
MSTABLE_POOLS_BY_CHAIN_ID,
|
MSTABLE_POOLS_BY_CHAIN_ID,
|
||||||
@ -66,32 +63,11 @@ import {
|
|||||||
} from './constants';
|
} from './constants';
|
||||||
import { CurveInfo, ERC20BridgeSource, PlatypusInfo } from './types';
|
import { CurveInfo, ERC20BridgeSource, PlatypusInfo } from './types';
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter Kyber reserves which should not be used (0xbb bridged reserves)
|
|
||||||
* @param reserveId Kyber reserveId
|
|
||||||
*/
|
|
||||||
export function isAllowedKyberReserveId(reserveId: string): boolean {
|
|
||||||
return (
|
|
||||||
reserveId !== NULL_BYTES &&
|
|
||||||
!reserveId.startsWith(KYBER_BRIDGED_LIQUIDITY_PREFIX) &&
|
|
||||||
!KYBER_BANNED_RESERVES.includes(reserveId)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// tslint:disable-next-line: completed-docs ban-types
|
// tslint:disable-next-line: completed-docs ban-types
|
||||||
export function isValidAddress(address: string | String): address is string {
|
export function isValidAddress(address: string | String): address is string {
|
||||||
return (typeof address === 'string' || address instanceof String) && address.toString() !== NULL_ADDRESS;
|
return (typeof address === 'string' || address instanceof String) && address.toString() !== NULL_ADDRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the offsets to be used to discover Kyber reserves
|
|
||||||
*/
|
|
||||||
export function getKyberOffsets(): BigNumber[] {
|
|
||||||
return Array(MAX_KYBER_RESERVES_QUERIED)
|
|
||||||
.fill(0)
|
|
||||||
.map((_v, i) => new BigNumber(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// tslint:disable completed-docs
|
// tslint:disable completed-docs
|
||||||
export function getDodoV2Offsets(): BigNumber[] {
|
export function getDodoV2Offsets(): BigNumber[] {
|
||||||
return Array(MAX_DODOV2_POOLS_QUERIED)
|
return Array(MAX_DODOV2_POOLS_QUERIED)
|
||||||
|
@ -22,7 +22,6 @@ import {
|
|||||||
GeistFillData,
|
GeistFillData,
|
||||||
GetMarketOrdersOpts,
|
GetMarketOrdersOpts,
|
||||||
isFinalUniswapV3FillData,
|
isFinalUniswapV3FillData,
|
||||||
KyberSamplerOpts,
|
|
||||||
LidoInfo,
|
LidoInfo,
|
||||||
LiquidityProviderFillData,
|
LiquidityProviderFillData,
|
||||||
LiquidityProviderRegistry,
|
LiquidityProviderRegistry,
|
||||||
@ -80,7 +79,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
|||||||
ERC20BridgeSource.Native,
|
ERC20BridgeSource.Native,
|
||||||
ERC20BridgeSource.Uniswap,
|
ERC20BridgeSource.Uniswap,
|
||||||
ERC20BridgeSource.UniswapV2,
|
ERC20BridgeSource.UniswapV2,
|
||||||
ERC20BridgeSource.Kyber,
|
|
||||||
ERC20BridgeSource.Curve,
|
ERC20BridgeSource.Curve,
|
||||||
ERC20BridgeSource.Balancer,
|
ERC20BridgeSource.Balancer,
|
||||||
ERC20BridgeSource.BalancerV2,
|
ERC20BridgeSource.BalancerV2,
|
||||||
@ -111,7 +109,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
|||||||
// ERC20BridgeSource.Compound,
|
// ERC20BridgeSource.Compound,
|
||||||
]),
|
]),
|
||||||
[ChainId.Ropsten]: new SourceFilters([
|
[ChainId.Ropsten]: new SourceFilters([
|
||||||
ERC20BridgeSource.Kyber,
|
|
||||||
ERC20BridgeSource.Native,
|
ERC20BridgeSource.Native,
|
||||||
ERC20BridgeSource.SushiSwap,
|
ERC20BridgeSource.SushiSwap,
|
||||||
ERC20BridgeSource.Uniswap,
|
ERC20BridgeSource.Uniswap,
|
||||||
@ -226,7 +223,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
|||||||
ERC20BridgeSource.Native,
|
ERC20BridgeSource.Native,
|
||||||
ERC20BridgeSource.Uniswap,
|
ERC20BridgeSource.Uniswap,
|
||||||
ERC20BridgeSource.UniswapV2,
|
ERC20BridgeSource.UniswapV2,
|
||||||
ERC20BridgeSource.Kyber,
|
|
||||||
ERC20BridgeSource.Curve,
|
ERC20BridgeSource.Curve,
|
||||||
ERC20BridgeSource.Balancer,
|
ERC20BridgeSource.Balancer,
|
||||||
ERC20BridgeSource.BalancerV2,
|
ERC20BridgeSource.BalancerV2,
|
||||||
@ -257,7 +253,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
|||||||
// ERC20BridgeSource.Compound,
|
// ERC20BridgeSource.Compound,
|
||||||
]),
|
]),
|
||||||
[ChainId.Ropsten]: new SourceFilters([
|
[ChainId.Ropsten]: new SourceFilters([
|
||||||
ERC20BridgeSource.Kyber,
|
|
||||||
ERC20BridgeSource.Native,
|
ERC20BridgeSource.Native,
|
||||||
ERC20BridgeSource.SushiSwap,
|
ERC20BridgeSource.SushiSwap,
|
||||||
ERC20BridgeSource.Uniswap,
|
ERC20BridgeSource.Uniswap,
|
||||||
@ -1847,35 +1842,6 @@ export const PLATYPUS_AVALANCHE_INFOS: { [name: string]: PlatypusInfo } = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Kyber reserve prefixes
|
|
||||||
* 0xff Fed price reserve
|
|
||||||
* 0xaa Automated price reserve
|
|
||||||
* 0xbb Bridged price reserve (i.e Uniswap/Curve)
|
|
||||||
*/
|
|
||||||
export const KYBER_BRIDGED_LIQUIDITY_PREFIX = '0xbb';
|
|
||||||
export const KYBER_BANNED_RESERVES = ['0xff4f6e65426974205175616e7400000000000000000000000000000000000000'];
|
|
||||||
export const MAX_KYBER_RESERVES_QUERIED = 5;
|
|
||||||
export const KYBER_CONFIG_BY_CHAIN_ID = valueByChainId<KyberSamplerOpts>(
|
|
||||||
{
|
|
||||||
[ChainId.Mainnet]: {
|
|
||||||
networkProxy: '0x9aab3f75489902f3a48495025729a0af77d4b11e',
|
|
||||||
hintHandler: '0xa1C0Fa73c39CFBcC11ec9Eb1Afc665aba9996E2C',
|
|
||||||
weth: MAINNET_TOKENS.WETH,
|
|
||||||
},
|
|
||||||
[ChainId.Ropsten]: {
|
|
||||||
networkProxy: '0x818e6fecd516ecc3849daf6845e3ec868087b755',
|
|
||||||
hintHandler: '0x63f773c026093eef988e803bdd5772dd235a8e71',
|
|
||||||
weth: getContractAddressesForChainOrThrow(ChainId.Ropsten).etherToken,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
networkProxy: NULL_ADDRESS,
|
|
||||||
hintHandler: NULL_ADDRESS,
|
|
||||||
weth: NULL_ADDRESS,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
export const LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID = valueByChainId<LiquidityProviderRegistry>(
|
export const LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID = valueByChainId<LiquidityProviderRegistry>(
|
||||||
{
|
{
|
||||||
[ChainId.Mainnet]: {
|
[ChainId.Mainnet]: {
|
||||||
@ -1980,13 +1946,6 @@ export const MSTABLE_POOLS_BY_CHAIN_ID = valueByChainId(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const OASIS_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
|
|
||||||
{
|
|
||||||
[ChainId.Mainnet]: '0x5e3e0548935a83ad29fb2a9153d331dc6d49020f',
|
|
||||||
},
|
|
||||||
NULL_ADDRESS,
|
|
||||||
);
|
|
||||||
|
|
||||||
export const KYBER_DMM_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
|
export const KYBER_DMM_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
|
||||||
{
|
{
|
||||||
[ChainId.Mainnet]: '0x1c87257f5e8609940bc751a07bb085bb7f8cdbe6',
|
[ChainId.Mainnet]: '0x1c87257f5e8609940bc751a07bb085bb7f8cdbe6',
|
||||||
@ -2471,7 +2430,6 @@ export const DEFAULT_GAS_SCHEDULE: Required<FeeSchedule> = {
|
|||||||
[ERC20BridgeSource.LiquidityProvider]: fillData => {
|
[ERC20BridgeSource.LiquidityProvider]: fillData => {
|
||||||
return (fillData as LiquidityProviderFillData).gasCost || 100e3;
|
return (fillData as LiquidityProviderFillData).gasCost || 100e3;
|
||||||
},
|
},
|
||||||
[ERC20BridgeSource.Kyber]: () => 450e3,
|
|
||||||
[ERC20BridgeSource.Curve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
[ERC20BridgeSource.Curve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
||||||
[ERC20BridgeSource.CurveV2]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
[ERC20BridgeSource.CurveV2]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
||||||
[ERC20BridgeSource.Nerve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
[ERC20BridgeSource.Nerve]: fillData => (fillData as CurveFillData).pool.gasSchedule,
|
||||||
|
@ -23,7 +23,6 @@ import {
|
|||||||
GenericRouterFillData,
|
GenericRouterFillData,
|
||||||
GMXFillData,
|
GMXFillData,
|
||||||
KyberDmmFillData,
|
KyberDmmFillData,
|
||||||
KyberFillData,
|
|
||||||
LidoFillData,
|
LidoFillData,
|
||||||
LiquidityProviderFillData,
|
LiquidityProviderFillData,
|
||||||
MakerPsmFillData,
|
MakerPsmFillData,
|
||||||
@ -92,8 +91,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
|
|||||||
return encodeBridgeSourceId(BridgeProtocol.BalancerV2Batch, 'BalancerV2');
|
return encodeBridgeSourceId(BridgeProtocol.BalancerV2Batch, 'BalancerV2');
|
||||||
case ERC20BridgeSource.Bancor:
|
case ERC20BridgeSource.Bancor:
|
||||||
return encodeBridgeSourceId(BridgeProtocol.Bancor, 'Bancor');
|
return encodeBridgeSourceId(BridgeProtocol.Bancor, 'Bancor');
|
||||||
// case ERC20BridgeSource.CoFiX:
|
|
||||||
// return encodeBridgeSourceId(BridgeProtocol.CoFiX, 'CoFiX');
|
|
||||||
case ERC20BridgeSource.Curve:
|
case ERC20BridgeSource.Curve:
|
||||||
return encodeBridgeSourceId(BridgeProtocol.Curve, 'Curve');
|
return encodeBridgeSourceId(BridgeProtocol.Curve, 'Curve');
|
||||||
case ERC20BridgeSource.Cream:
|
case ERC20BridgeSource.Cream:
|
||||||
@ -102,8 +99,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
|
|||||||
return encodeBridgeSourceId(BridgeProtocol.CryptoCom, 'CryptoCom');
|
return encodeBridgeSourceId(BridgeProtocol.CryptoCom, 'CryptoCom');
|
||||||
case ERC20BridgeSource.Dodo:
|
case ERC20BridgeSource.Dodo:
|
||||||
return encodeBridgeSourceId(BridgeProtocol.Dodo, 'Dodo');
|
return encodeBridgeSourceId(BridgeProtocol.Dodo, 'Dodo');
|
||||||
case ERC20BridgeSource.Kyber:
|
|
||||||
return encodeBridgeSourceId(BridgeProtocol.Kyber, 'Kyber');
|
|
||||||
case ERC20BridgeSource.LiquidityProvider:
|
case ERC20BridgeSource.LiquidityProvider:
|
||||||
// "LiquidityProvider" is too long to encode (17 characters).
|
// "LiquidityProvider" is too long to encode (17 characters).
|
||||||
return encodeBridgeSourceId(BridgeProtocol.Unknown, 'LP');
|
return encodeBridgeSourceId(BridgeProtocol.Unknown, 'LP');
|
||||||
@ -305,10 +300,6 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
|
|||||||
const uniswapV2FillData = (order as OptimizedMarketBridgeOrder<UniswapV2FillData>).fillData;
|
const uniswapV2FillData = (order as OptimizedMarketBridgeOrder<UniswapV2FillData>).fillData;
|
||||||
bridgeData = encoder.encode([uniswapV2FillData.router, uniswapV2FillData.tokenAddressPath]);
|
bridgeData = encoder.encode([uniswapV2FillData.router, uniswapV2FillData.tokenAddressPath]);
|
||||||
break;
|
break;
|
||||||
case ERC20BridgeSource.Kyber:
|
|
||||||
const kyberFillData = (order as OptimizedMarketBridgeOrder<KyberFillData>).fillData;
|
|
||||||
bridgeData = encoder.encode([kyberFillData.networkProxy, kyberFillData.hint]);
|
|
||||||
break;
|
|
||||||
case ERC20BridgeSource.Mooniswap:
|
case ERC20BridgeSource.Mooniswap:
|
||||||
const mooniswapFillData = (order as OptimizedMarketBridgeOrder<MooniswapFillData>).fillData;
|
const mooniswapFillData = (order as OptimizedMarketBridgeOrder<MooniswapFillData>).fillData;
|
||||||
bridgeData = encoder.encode([mooniswapFillData.poolAddress]);
|
bridgeData = encoder.encode([mooniswapFillData.poolAddress]);
|
||||||
@ -490,10 +481,6 @@ export const BRIDGE_ENCODERS: {
|
|||||||
{ name: 'provider', type: 'address' },
|
{ name: 'provider', type: 'address' },
|
||||||
{ name: 'data', type: 'bytes' },
|
{ name: 'data', type: 'bytes' },
|
||||||
]),
|
]),
|
||||||
[ERC20BridgeSource.Kyber]: AbiEncoder.create([
|
|
||||||
{ name: 'kyberNetworkProxy', type: 'address' },
|
|
||||||
{ name: 'hint', type: 'bytes' },
|
|
||||||
]),
|
|
||||||
[ERC20BridgeSource.Dodo]: AbiEncoder.create([
|
[ERC20BridgeSource.Dodo]: AbiEncoder.create([
|
||||||
{ name: 'helper', type: 'address' },
|
{ name: 'helper', type: 'address' },
|
||||||
{ name: 'poolAddress', type: 'address' },
|
{ name: 'poolAddress', type: 'address' },
|
||||||
|
@ -13,10 +13,8 @@ import { BancorService } from './bancor_service';
|
|||||||
import {
|
import {
|
||||||
getCurveLikeInfosForPair,
|
getCurveLikeInfosForPair,
|
||||||
getDodoV2Offsets,
|
getDodoV2Offsets,
|
||||||
getKyberOffsets,
|
|
||||||
getPlatypusInfoForPair,
|
getPlatypusInfoForPair,
|
||||||
getShellLikeInfosForPair,
|
getShellLikeInfosForPair,
|
||||||
isAllowedKyberReserveId,
|
|
||||||
isBadTokenForSource,
|
isBadTokenForSource,
|
||||||
isValidAddress,
|
isValidAddress,
|
||||||
uniswapV2LikeRouterAddress,
|
uniswapV2LikeRouterAddress,
|
||||||
@ -35,7 +33,6 @@ import {
|
|||||||
GMX_READER_BY_CHAIN_ID,
|
GMX_READER_BY_CHAIN_ID,
|
||||||
GMX_ROUTER_BY_CHAIN_ID,
|
GMX_ROUTER_BY_CHAIN_ID,
|
||||||
GMX_VAULT_BY_CHAIN_ID,
|
GMX_VAULT_BY_CHAIN_ID,
|
||||||
KYBER_CONFIG_BY_CHAIN_ID,
|
|
||||||
KYBER_DMM_ROUTER_BY_CHAIN_ID,
|
KYBER_DMM_ROUTER_BY_CHAIN_ID,
|
||||||
LIDO_INFO_BY_CHAIN,
|
LIDO_INFO_BY_CHAIN,
|
||||||
LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID,
|
LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID,
|
||||||
@ -44,7 +41,6 @@ import {
|
|||||||
MOONISWAP_REGISTRIES_BY_CHAIN_ID,
|
MOONISWAP_REGISTRIES_BY_CHAIN_ID,
|
||||||
NATIVE_FEE_TOKEN_BY_CHAIN_ID,
|
NATIVE_FEE_TOKEN_BY_CHAIN_ID,
|
||||||
NULL_ADDRESS,
|
NULL_ADDRESS,
|
||||||
NULL_BYTES,
|
|
||||||
PLATYPUS_ROUTER_BY_CHAIN_ID,
|
PLATYPUS_ROUTER_BY_CHAIN_ID,
|
||||||
SELL_SOURCE_FILTER_BY_CHAIN_ID,
|
SELL_SOURCE_FILTER_BY_CHAIN_ID,
|
||||||
UNISWAPV1_ROUTER_BY_CHAIN_ID,
|
UNISWAPV1_ROUTER_BY_CHAIN_ID,
|
||||||
@ -81,8 +77,6 @@ import {
|
|||||||
GMXFillData,
|
GMXFillData,
|
||||||
HopInfo,
|
HopInfo,
|
||||||
KyberDmmFillData,
|
KyberDmmFillData,
|
||||||
KyberFillData,
|
|
||||||
KyberSamplerOpts,
|
|
||||||
LidoFillData,
|
LidoFillData,
|
||||||
LidoInfo,
|
LidoInfo,
|
||||||
LiquidityProviderFillData,
|
LiquidityProviderFillData,
|
||||||
@ -266,54 +260,6 @@ export class SamplerOperations {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getKyberSellQuotes(
|
|
||||||
kyberOpts: KyberSamplerOpts,
|
|
||||||
reserveOffset: BigNumber,
|
|
||||||
makerToken: string,
|
|
||||||
takerToken: string,
|
|
||||||
takerFillAmounts: BigNumber[],
|
|
||||||
): SourceQuoteOperation {
|
|
||||||
return new SamplerContractOperation({
|
|
||||||
source: ERC20BridgeSource.Kyber,
|
|
||||||
contract: this._samplerContract,
|
|
||||||
function: this._samplerContract.sampleSellsFromKyberNetwork,
|
|
||||||
params: [{ ...kyberOpts, reserveOffset, hint: NULL_BYTES }, takerToken, makerToken, takerFillAmounts],
|
|
||||||
callback: (callResults: string, fillData: KyberFillData): BigNumber[] => {
|
|
||||||
const [reserveId, hint, samples] = this._samplerContract.getABIDecodedReturnData<
|
|
||||||
[string, string, BigNumber[]]
|
|
||||||
>('sampleSellsFromKyberNetwork', callResults);
|
|
||||||
fillData.hint = hint;
|
|
||||||
fillData.reserveId = reserveId;
|
|
||||||
fillData.networkProxy = kyberOpts.networkProxy;
|
|
||||||
return isAllowedKyberReserveId(reserveId) ? samples : [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKyberBuyQuotes(
|
|
||||||
kyberOpts: KyberSamplerOpts,
|
|
||||||
reserveOffset: BigNumber,
|
|
||||||
makerToken: string,
|
|
||||||
takerToken: string,
|
|
||||||
makerFillAmounts: BigNumber[],
|
|
||||||
): SourceQuoteOperation {
|
|
||||||
return new SamplerContractOperation({
|
|
||||||
source: ERC20BridgeSource.Kyber,
|
|
||||||
contract: this._samplerContract,
|
|
||||||
function: this._samplerContract.sampleBuysFromKyberNetwork,
|
|
||||||
params: [{ ...kyberOpts, reserveOffset, hint: NULL_BYTES }, takerToken, makerToken, makerFillAmounts],
|
|
||||||
callback: (callResults: string, fillData: KyberFillData): BigNumber[] => {
|
|
||||||
const [reserveId, hint, samples] = this._samplerContract.getABIDecodedReturnData<
|
|
||||||
[string, string, BigNumber[]]
|
|
||||||
>('sampleBuysFromKyberNetwork', callResults);
|
|
||||||
fillData.hint = hint;
|
|
||||||
fillData.reserveId = reserveId;
|
|
||||||
fillData.networkProxy = kyberOpts.networkProxy;
|
|
||||||
return isAllowedKyberReserveId(reserveId) ? samples : [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public getKyberDmmSellQuotes(
|
public getKyberDmmSellQuotes(
|
||||||
router: string,
|
router: string,
|
||||||
tokenAddressPath: string[],
|
tokenAddressPath: string[],
|
||||||
@ -1479,16 +1425,6 @@ export class SamplerOperations {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return this.getKyberDmmSellQuotes(kyberDmmRouter, [takerToken, makerToken], takerFillAmounts);
|
return this.getKyberDmmSellQuotes(kyberDmmRouter, [takerToken, makerToken], takerFillAmounts);
|
||||||
case ERC20BridgeSource.Kyber:
|
|
||||||
return getKyberOffsets().map(offset =>
|
|
||||||
this.getKyberSellQuotes(
|
|
||||||
KYBER_CONFIG_BY_CHAIN_ID[this.chainId],
|
|
||||||
offset,
|
|
||||||
makerToken,
|
|
||||||
takerToken,
|
|
||||||
takerFillAmounts,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case ERC20BridgeSource.Curve:
|
case ERC20BridgeSource.Curve:
|
||||||
case ERC20BridgeSource.CurveV2:
|
case ERC20BridgeSource.CurveV2:
|
||||||
case ERC20BridgeSource.Nerve:
|
case ERC20BridgeSource.Nerve:
|
||||||
@ -1810,16 +1746,6 @@ export class SamplerOperations {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
return this.getKyberDmmBuyQuotes(kyberDmmRouter, [takerToken, makerToken], makerFillAmounts);
|
return this.getKyberDmmBuyQuotes(kyberDmmRouter, [takerToken, makerToken], makerFillAmounts);
|
||||||
case ERC20BridgeSource.Kyber:
|
|
||||||
return getKyberOffsets().map(offset =>
|
|
||||||
this.getKyberBuyQuotes(
|
|
||||||
KYBER_CONFIG_BY_CHAIN_ID[this.chainId],
|
|
||||||
offset,
|
|
||||||
makerToken,
|
|
||||||
takerToken,
|
|
||||||
makerFillAmounts,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case ERC20BridgeSource.Curve:
|
case ERC20BridgeSource.Curve:
|
||||||
case ERC20BridgeSource.CurveV2:
|
case ERC20BridgeSource.CurveV2:
|
||||||
case ERC20BridgeSource.Nerve:
|
case ERC20BridgeSource.Nerve:
|
||||||
|
@ -38,7 +38,6 @@ export enum ERC20BridgeSource {
|
|||||||
Native = 'Native',
|
Native = 'Native',
|
||||||
Uniswap = 'Uniswap',
|
Uniswap = 'Uniswap',
|
||||||
UniswapV2 = 'Uniswap_V2',
|
UniswapV2 = 'Uniswap_V2',
|
||||||
Kyber = 'Kyber',
|
|
||||||
Curve = 'Curve',
|
Curve = 'Curve',
|
||||||
LiquidityProvider = 'LiquidityProvider',
|
LiquidityProvider = 'LiquidityProvider',
|
||||||
MultiBridge = 'MultiBridge',
|
MultiBridge = 'MultiBridge',
|
||||||
@ -262,12 +261,6 @@ export interface BancorFillData extends FillData {
|
|||||||
networkAddress: string;
|
networkAddress: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KyberFillData extends FillData {
|
|
||||||
hint: string;
|
|
||||||
reserveId: string;
|
|
||||||
networkProxy: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MooniswapFillData extends FillData {
|
export interface MooniswapFillData extends FillData {
|
||||||
poolAddress: string;
|
poolAddress: string;
|
||||||
}
|
}
|
||||||
@ -693,9 +686,3 @@ export interface GenerateOptimizedOrdersOpts {
|
|||||||
export interface ComparisonPrice {
|
export interface ComparisonPrice {
|
||||||
wholeOrder: BigNumber | undefined;
|
wholeOrder: BigNumber | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KyberSamplerOpts {
|
|
||||||
networkProxy: string;
|
|
||||||
hintHandler: string;
|
|
||||||
weth: string;
|
|
||||||
}
|
|
||||||
|
@ -24,7 +24,6 @@ import * as IBalancerV2Vault from '../test/generated-artifacts/IBalancerV2Vault.
|
|||||||
import * as IBancor from '../test/generated-artifacts/IBancor.json';
|
import * as IBancor from '../test/generated-artifacts/IBancor.json';
|
||||||
import * as ICurve from '../test/generated-artifacts/ICurve.json';
|
import * as ICurve from '../test/generated-artifacts/ICurve.json';
|
||||||
import * as IGMX from '../test/generated-artifacts/IGMX.json';
|
import * as IGMX from '../test/generated-artifacts/IGMX.json';
|
||||||
import * as IKyberNetwork from '../test/generated-artifacts/IKyberNetwork.json';
|
|
||||||
import * as IMooniswap from '../test/generated-artifacts/IMooniswap.json';
|
import * as IMooniswap from '../test/generated-artifacts/IMooniswap.json';
|
||||||
import * as IMStable from '../test/generated-artifacts/IMStable.json';
|
import * as IMStable from '../test/generated-artifacts/IMStable.json';
|
||||||
import * as IMultiBridge from '../test/generated-artifacts/IMultiBridge.json';
|
import * as IMultiBridge from '../test/generated-artifacts/IMultiBridge.json';
|
||||||
@ -34,7 +33,6 @@ import * as ISmoothy from '../test/generated-artifacts/ISmoothy.json';
|
|||||||
import * as IUniswapExchangeQuotes from '../test/generated-artifacts/IUniswapExchangeQuotes.json';
|
import * as IUniswapExchangeQuotes from '../test/generated-artifacts/IUniswapExchangeQuotes.json';
|
||||||
import * as IUniswapV2Router01 from '../test/generated-artifacts/IUniswapV2Router01.json';
|
import * as IUniswapV2Router01 from '../test/generated-artifacts/IUniswapV2Router01.json';
|
||||||
import * as KyberDmmSampler from '../test/generated-artifacts/KyberDmmSampler.json';
|
import * as KyberDmmSampler from '../test/generated-artifacts/KyberDmmSampler.json';
|
||||||
import * as KyberSampler from '../test/generated-artifacts/KyberSampler.json';
|
|
||||||
import * as LidoSampler from '../test/generated-artifacts/LidoSampler.json';
|
import * as LidoSampler from '../test/generated-artifacts/LidoSampler.json';
|
||||||
import * as LiquidityProviderSampler from '../test/generated-artifacts/LiquidityProviderSampler.json';
|
import * as LiquidityProviderSampler from '../test/generated-artifacts/LiquidityProviderSampler.json';
|
||||||
import * as MakerPSMSampler from '../test/generated-artifacts/MakerPSMSampler.json';
|
import * as MakerPSMSampler from '../test/generated-artifacts/MakerPSMSampler.json';
|
||||||
@ -67,7 +65,6 @@ export const artifacts = {
|
|||||||
FakeTaker: FakeTaker as ContractArtifact,
|
FakeTaker: FakeTaker as ContractArtifact,
|
||||||
GMXSampler: GMXSampler as ContractArtifact,
|
GMXSampler: GMXSampler as ContractArtifact,
|
||||||
KyberDmmSampler: KyberDmmSampler as ContractArtifact,
|
KyberDmmSampler: KyberDmmSampler as ContractArtifact,
|
||||||
KyberSampler: KyberSampler as ContractArtifact,
|
|
||||||
LidoSampler: LidoSampler as ContractArtifact,
|
LidoSampler: LidoSampler as ContractArtifact,
|
||||||
LiquidityProviderSampler: LiquidityProviderSampler as ContractArtifact,
|
LiquidityProviderSampler: LiquidityProviderSampler as ContractArtifact,
|
||||||
MStableSampler: MStableSampler as ContractArtifact,
|
MStableSampler: MStableSampler as ContractArtifact,
|
||||||
@ -88,7 +85,6 @@ export const artifacts = {
|
|||||||
IBancor: IBancor as ContractArtifact,
|
IBancor: IBancor as ContractArtifact,
|
||||||
ICurve: ICurve as ContractArtifact,
|
ICurve: ICurve as ContractArtifact,
|
||||||
IGMX: IGMX as ContractArtifact,
|
IGMX: IGMX as ContractArtifact,
|
||||||
IKyberNetwork: IKyberNetwork as ContractArtifact,
|
|
||||||
IMStable: IMStable as ContractArtifact,
|
IMStable: IMStable as ContractArtifact,
|
||||||
IMooniswap: IMooniswap as ContractArtifact,
|
IMooniswap: IMooniswap as ContractArtifact,
|
||||||
IMultiBridge: IMultiBridge as ContractArtifact,
|
IMultiBridge: IMultiBridge as ContractArtifact,
|
||||||
|
@ -21,8 +21,8 @@ const GAS_PRICE = new BigNumber(50e9); // 50 gwei
|
|||||||
const NATIVE_ORDER_FEE = new BigNumber(220e3); // 220K gas
|
const NATIVE_ORDER_FEE = new BigNumber(220e3); // 220K gas
|
||||||
|
|
||||||
// DEX samples to fill in MarketSideLiquidity
|
// DEX samples to fill in MarketSideLiquidity
|
||||||
const kyberSample1: DexSample = {
|
const curveSample: DexSample = {
|
||||||
source: ERC20BridgeSource.Kyber,
|
source: ERC20BridgeSource.Curve,
|
||||||
input: new BigNumber(10000),
|
input: new BigNumber(10000),
|
||||||
output: new BigNumber(10001),
|
output: new BigNumber(10001),
|
||||||
fillData: {},
|
fillData: {},
|
||||||
@ -33,7 +33,7 @@ const uniswapSample1: DexSample = {
|
|||||||
output: new BigNumber(10004),
|
output: new BigNumber(10004),
|
||||||
fillData: {},
|
fillData: {},
|
||||||
};
|
};
|
||||||
const dexQuotes: DexSample[] = [kyberSample1, uniswapSample1];
|
const dexQuotes: DexSample[] = [curveSample, uniswapSample1];
|
||||||
|
|
||||||
const feeSchedule = {
|
const feeSchedule = {
|
||||||
[ERC20BridgeSource.Native]: _.constant(GAS_PRICE.times(NATIVE_ORDER_FEE)),
|
[ERC20BridgeSource.Native]: _.constant(GAS_PRICE.times(NATIVE_ORDER_FEE)),
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { ChainId } from '@0x/contract-addresses';
|
|
||||||
import { blockchainTests, describe, expect, toBaseUnitAmount, Web3ProviderEngine } from '@0x/contracts-test-utils';
|
import { blockchainTests, describe, expect, toBaseUnitAmount, Web3ProviderEngine } from '@0x/contracts-test-utils';
|
||||||
import { RPCSubprovider } from '@0x/subproviders';
|
import { RPCSubprovider } from '@0x/subproviders';
|
||||||
import { BigNumber, NULL_BYTES, providerUtils } from '@0x/utils';
|
import { BigNumber, providerUtils } from '@0x/utils';
|
||||||
|
|
||||||
import { KYBER_CONFIG_BY_CHAIN_ID, MAINNET_TOKENS } from '../../src/utils/market_operation_utils/constants';
|
|
||||||
import { artifacts } from '../artifacts';
|
import { artifacts } from '../artifacts';
|
||||||
import { ERC20BridgeSamplerContract } from '../wrappers';
|
import { ERC20BridgeSamplerContract } from '../wrappers';
|
||||||
|
|
||||||
@ -79,60 +77,4 @@ blockchainTests.skip('Mainnet Sampler Tests', env => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('Kyber', () => {
|
|
||||||
const WETH = MAINNET_TOKENS.WETH;
|
|
||||||
const DAI = MAINNET_TOKENS.DAI;
|
|
||||||
const USDC = MAINNET_TOKENS.USDC;
|
|
||||||
const RESERVE_OFFSET = new BigNumber(0);
|
|
||||||
const KYBER_OPTS = {
|
|
||||||
...KYBER_CONFIG_BY_CHAIN_ID[ChainId.Mainnet],
|
|
||||||
reserveOffset: RESERVE_OFFSET,
|
|
||||||
hint: NULL_BYTES,
|
|
||||||
};
|
|
||||||
describe('sampleSellsFromKyberNetwork()', () => {
|
|
||||||
it('samples sells from Kyber DAI->WETH', async () => {
|
|
||||||
const [, samples] = await testContract
|
|
||||||
.sampleSellsFromKyberNetwork(KYBER_OPTS, DAI, WETH, [toBaseUnitAmount(1)])
|
|
||||||
.callAsync({ overrides });
|
|
||||||
expect(samples.length).to.be.bignumber.greaterThan(0);
|
|
||||||
expect(samples[0]).to.be.bignumber.greaterThan(0);
|
|
||||||
});
|
|
||||||
it('samples sells from Kyber WETH->DAI', async () => {
|
|
||||||
const [, samples] = await testContract
|
|
||||||
.sampleSellsFromKyberNetwork(KYBER_OPTS, WETH, DAI, [toBaseUnitAmount(1)])
|
|
||||||
.callAsync({ overrides });
|
|
||||||
expect(samples.length).to.be.bignumber.greaterThan(0);
|
|
||||||
expect(samples[0]).to.be.bignumber.greaterThan(0);
|
|
||||||
});
|
|
||||||
it('samples sells from Kyber DAI->USDC', async () => {
|
|
||||||
const [, samples] = await testContract
|
|
||||||
.sampleSellsFromKyberNetwork(KYBER_OPTS, DAI, USDC, [toBaseUnitAmount(1)])
|
|
||||||
.callAsync({ overrides });
|
|
||||||
expect(samples.length).to.be.bignumber.greaterThan(0);
|
|
||||||
expect(samples[0]).to.be.bignumber.greaterThan(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sampleBuysFromKyber()', () => {
|
|
||||||
it('samples buys from Kyber WETH->DAI', async () => {
|
|
||||||
// From ETH to DAI
|
|
||||||
// I want to buy 1 DAI
|
|
||||||
const [, samples] = await testContract
|
|
||||||
.sampleBuysFromKyberNetwork(KYBER_OPTS, WETH, DAI, [toBaseUnitAmount(1)])
|
|
||||||
.callAsync({ overrides });
|
|
||||||
expect(samples.length).to.be.bignumber.greaterThan(0);
|
|
||||||
expect(samples[0]).to.be.bignumber.greaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('samples buys from Kyber DAI->WETH', async () => {
|
|
||||||
// From USDC to DAI
|
|
||||||
// I want to buy 1 WETH
|
|
||||||
const [, samples] = await testContract
|
|
||||||
.sampleBuysFromKyberNetwork(KYBER_OPTS, DAI, WETH, [toBaseUnitAmount(1)])
|
|
||||||
.callAsync({ overrides });
|
|
||||||
expect(samples.length).to.be.bignumber.greaterThan(0);
|
|
||||||
expect(samples[0]).to.be.bignumber.greaterThan(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@ import { generatePseudoRandomSalt } from './utils/utils';
|
|||||||
const CHAIN_ID = 1;
|
const CHAIN_ID = 1;
|
||||||
const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||||
// tslint:disable: custom-no-magic-numbers
|
// tslint:disable: custom-no-magic-numbers
|
||||||
describe.skip('DexSampler tests', () => {
|
describe('DexSampler tests', () => {
|
||||||
const MAKER_TOKEN = randomAddress();
|
const MAKER_TOKEN = randomAddress();
|
||||||
const TAKER_TOKEN = randomAddress();
|
const TAKER_TOKEN = randomAddress();
|
||||||
const chainId = ChainId.Mainnet;
|
const chainId = ChainId.Mainnet;
|
||||||
@ -142,40 +142,6 @@ describe.skip('DexSampler tests', () => {
|
|||||||
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
expect(fillableAmounts).to.deep.eq(expectedFillableAmounts);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('getKyberSellQuotes()', async () => {
|
|
||||||
const expectedTakerToken = randomAddress();
|
|
||||||
const expectedMakerToken = randomAddress();
|
|
||||||
const expectedTakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 10);
|
|
||||||
const expectedMakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 10);
|
|
||||||
const sampler = new MockSamplerContract({
|
|
||||||
sampleSellsFromKyberNetwork: (_reserveOffset, takerToken, makerToken, fillAmounts) => {
|
|
||||||
expect(takerToken).to.eq(expectedTakerToken);
|
|
||||||
expect(makerToken).to.eq(expectedMakerToken);
|
|
||||||
expect(fillAmounts).to.deep.eq(expectedTakerFillAmounts);
|
|
||||||
return ['0x', '0x', expectedMakerFillAmounts];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const dexOrderSampler = new DexOrderSampler(
|
|
||||||
chainId,
|
|
||||||
sampler,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
async () => undefined,
|
|
||||||
);
|
|
||||||
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
|
||||||
dexOrderSampler.getKyberSellQuotes(
|
|
||||||
{ hintHandler: randomAddress(), networkProxy: randomAddress(), weth: randomAddress() },
|
|
||||||
new BigNumber(0),
|
|
||||||
expectedMakerToken,
|
|
||||||
expectedTakerToken,
|
|
||||||
expectedTakerFillAmounts,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(fillableAmounts).to.deep.eq(expectedMakerFillAmounts);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('getLiquidityProviderSellQuotes()', async () => {
|
it('getLiquidityProviderSellQuotes()', async () => {
|
||||||
const expectedMakerToken = randomAddress();
|
const expectedMakerToken = randomAddress();
|
||||||
const expectedTakerToken = randomAddress();
|
const expectedTakerToken = randomAddress();
|
||||||
@ -370,7 +336,6 @@ describe.skip('DexSampler tests', () => {
|
|||||||
const expectedMakerToken = randomAddress();
|
const expectedMakerToken = randomAddress();
|
||||||
const sources = [ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
const sources = [ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
||||||
const ratesBySource: RatesBySource = {
|
const ratesBySource: RatesBySource = {
|
||||||
[ERC20BridgeSource.Kyber]: getRandomFloat(0, 100),
|
|
||||||
[ERC20BridgeSource.Uniswap]: getRandomFloat(0, 100),
|
[ERC20BridgeSource.Uniswap]: getRandomFloat(0, 100),
|
||||||
[ERC20BridgeSource.UniswapV2]: getRandomFloat(0, 100),
|
[ERC20BridgeSource.UniswapV2]: getRandomFloat(0, 100),
|
||||||
};
|
};
|
||||||
|
@ -50,9 +50,9 @@ const TAKER_TOKEN = randomAddress();
|
|||||||
|
|
||||||
const DEFAULT_INCLUDED = [
|
const DEFAULT_INCLUDED = [
|
||||||
ERC20BridgeSource.SushiSwap,
|
ERC20BridgeSource.SushiSwap,
|
||||||
ERC20BridgeSource.Kyber,
|
|
||||||
ERC20BridgeSource.Native,
|
ERC20BridgeSource.Native,
|
||||||
ERC20BridgeSource.Uniswap,
|
ERC20BridgeSource.Uniswap,
|
||||||
|
ERC20BridgeSource.Curve,
|
||||||
];
|
];
|
||||||
|
|
||||||
const DEFAULT_EXCLUDED = SELL_SOURCE_FILTER_BY_CHAIN_ID[ChainId.Mainnet].sources.filter(
|
const DEFAULT_EXCLUDED = SELL_SOURCE_FILTER_BY_CHAIN_ID[ChainId.Mainnet].sources.filter(
|
||||||
@ -321,7 +321,7 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
[ERC20BridgeSource.Native]: createDecreasingRates(NUM_SAMPLES),
|
[ERC20BridgeSource.Native]: createDecreasingRates(NUM_SAMPLES),
|
||||||
[ERC20BridgeSource.SushiSwap]: createDecreasingRates(NUM_SAMPLES),
|
[ERC20BridgeSource.SushiSwap]: createDecreasingRates(NUM_SAMPLES),
|
||||||
[ERC20BridgeSource.Uniswap]: createDecreasingRates(NUM_SAMPLES),
|
[ERC20BridgeSource.Uniswap]: createDecreasingRates(NUM_SAMPLES),
|
||||||
[ERC20BridgeSource.Kyber]: createDecreasingRates(NUM_SAMPLES),
|
[ERC20BridgeSource.Curve]: createDecreasingRates(NUM_SAMPLES),
|
||||||
};
|
};
|
||||||
|
|
||||||
interface FillDataBySource {
|
interface FillDataBySource {
|
||||||
@ -337,7 +337,6 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
deadline: Math.floor(Date.now() / 1000) + 300,
|
deadline: Math.floor(Date.now() / 1000) + 300,
|
||||||
},
|
},
|
||||||
[ERC20BridgeSource.Bancor]: { path: [], networkAddress: randomAddress() },
|
[ERC20BridgeSource.Bancor]: { path: [], networkAddress: randomAddress() },
|
||||||
[ERC20BridgeSource.Kyber]: { hint: '0x', reserveId: '0x', networkAddress: randomAddress() },
|
|
||||||
[ERC20BridgeSource.Curve]: {
|
[ERC20BridgeSource.Curve]: {
|
||||||
pool: {
|
pool: {
|
||||||
poolAddress: randomAddress(),
|
poolAddress: randomAddress(),
|
||||||
@ -1034,7 +1033,7 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
rates[ERC20BridgeSource.Native] = [0.4, 0.3, 0.2, 0.1];
|
rates[ERC20BridgeSource.Native] = [0.4, 0.3, 0.2, 0.1];
|
||||||
rates[ERC20BridgeSource.Uniswap] = [0.5, 0.05, 0.05, 0.05];
|
rates[ERC20BridgeSource.Uniswap] = [0.5, 0.05, 0.05, 0.05];
|
||||||
rates[ERC20BridgeSource.SushiSwap] = [0.6, 0.05, 0.05, 0.05];
|
rates[ERC20BridgeSource.SushiSwap] = [0.6, 0.05, 0.05, 0.05];
|
||||||
rates[ERC20BridgeSource.Kyber] = [0, 0, 0, 0]; // unused
|
rates[ERC20BridgeSource.Curve] = [0, 0, 0, 0]; // unused
|
||||||
replaceSamplerOps({
|
replaceSamplerOps({
|
||||||
getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates),
|
getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates),
|
||||||
});
|
});
|
||||||
@ -1066,7 +1065,6 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
[ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, 0.93, 0.92, 0.91]
|
[ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, 0.93, 0.92, 0.91]
|
||||||
[ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1],
|
|
||||||
};
|
};
|
||||||
const feeSchedule = {
|
const feeSchedule = {
|
||||||
[ERC20BridgeSource.Native]: _.constant(
|
[ERC20BridgeSource.Native]: _.constant(
|
||||||
@ -1097,12 +1095,10 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('factors in fees for dexes', async () => {
|
it('factors in fees for dexes', async () => {
|
||||||
// Kyber will have the best rates but will have fees,
|
|
||||||
// dropping its effective rates.
|
|
||||||
const uniswapFeeRate = 0.2;
|
const uniswapFeeRate = 0.2;
|
||||||
const rates: RatesBySource = {
|
const rates: RatesBySource = {
|
||||||
[ERC20BridgeSource.Native]: [0.95, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.Native]: [0.95, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.Curve]: [0.1, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.SushiSwap]: [0.92, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.SushiSwap]: [0.92, 0.1, 0.1, 0.1],
|
||||||
// Effectively [0.8, ~0.5, ~0, ~0]
|
// Effectively [0.8, ~0.5, ~0, ~0]
|
||||||
[ERC20BridgeSource.Uniswap]: [1, 0.7, 0.2, 0.2],
|
[ERC20BridgeSource.Uniswap]: [1, 0.7, 0.2, 0.2],
|
||||||
@ -1136,7 +1132,7 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
|
|
||||||
it('can mix one concave source', async () => {
|
it('can mix one concave source', async () => {
|
||||||
const rates: RatesBySource = {
|
const rates: RatesBySource = {
|
||||||
[ERC20BridgeSource.Kyber]: [0, 0, 0, 0], // Won't use
|
[ERC20BridgeSource.Curve]: [0, 0, 0, 0], // Won't use
|
||||||
[ERC20BridgeSource.SushiSwap]: [0.5, 0.85, 0.75, 0.75], // Concave
|
[ERC20BridgeSource.SushiSwap]: [0.5, 0.85, 0.75, 0.75], // Concave
|
||||||
[ERC20BridgeSource.Uniswap]: [0.96, 0.2, 0.1, 0.1],
|
[ERC20BridgeSource.Uniswap]: [0.96, 0.2, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.Native]: [0.95, 0.2, 0.2, 0.1],
|
[ERC20BridgeSource.Native]: [0.95, 0.2, 0.2, 0.1],
|
||||||
@ -1168,7 +1164,7 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
rates[ERC20BridgeSource.Native] = [1, 1, 0.01, 0.01];
|
rates[ERC20BridgeSource.Native] = [1, 1, 0.01, 0.01];
|
||||||
rates[ERC20BridgeSource.Uniswap] = [1, 1, 0.01, 0.01];
|
rates[ERC20BridgeSource.Uniswap] = [1, 1, 0.01, 0.01];
|
||||||
rates[ERC20BridgeSource.SushiSwap] = [0.49, 0.49, 0.49, 0.49];
|
rates[ERC20BridgeSource.SushiSwap] = [0.49, 0.49, 0.49, 0.49];
|
||||||
rates[ERC20BridgeSource.Kyber] = [0.35, 0.2, 0.01, 0.01];
|
rates[ERC20BridgeSource.Curve] = [0.35, 0.2, 0.01, 0.01];
|
||||||
replaceSamplerOps({
|
replaceSamplerOps({
|
||||||
getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates),
|
getSellQuotes: createGetMultipleSellQuotesOperationFromRates(rates),
|
||||||
});
|
});
|
||||||
@ -1517,7 +1513,7 @@ describe('MarketOperationUtils tests', () => {
|
|||||||
[ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, ~0.93, ~0.92, ~0.91]
|
[ERC20BridgeSource.Native]: [1, 0.99, 0.98, 0.97], // Effectively [0.94, ~0.93, ~0.92, ~0.91]
|
||||||
[ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.Uniswap]: [0.96, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.SushiSwap]: [0.95, 0.1, 0.1, 0.1],
|
||||||
[ERC20BridgeSource.Kyber]: [0.1, 0.1, 0.1, 0.1],
|
[ERC20BridgeSource.Curve]: [0.1, 0.1, 0.1, 0.1],
|
||||||
};
|
};
|
||||||
const feeSchedule = {
|
const feeSchedule = {
|
||||||
[ERC20BridgeSource.Native]: _.constant(
|
[ERC20BridgeSource.Native]: _.constant(
|
||||||
|
@ -58,8 +58,8 @@ describe('generateQuoteReport', async () => {
|
|||||||
it('should generate report properly for sell', () => {
|
it('should generate report properly for sell', () => {
|
||||||
const marketOperation: MarketOperation = MarketOperation.Sell;
|
const marketOperation: MarketOperation = MarketOperation.Sell;
|
||||||
|
|
||||||
const kyberSample2: DexSample = {
|
const balancerSample2: DexSample = {
|
||||||
source: ERC20BridgeSource.Kyber,
|
source: ERC20BridgeSource.BalancerV2,
|
||||||
input: new BigNumber(10003),
|
input: new BigNumber(10003),
|
||||||
output: new BigNumber(10004),
|
output: new BigNumber(10004),
|
||||||
fillData: {},
|
fillData: {},
|
||||||
@ -117,15 +117,15 @@ describe('generateQuoteReport', async () => {
|
|||||||
sourcePathId: hexUtils.random(),
|
sourcePathId: hexUtils.random(),
|
||||||
type: FillQuoteTransformerOrderType.Bridge,
|
type: FillQuoteTransformerOrderType.Bridge,
|
||||||
};
|
};
|
||||||
const kyber2Fill: CollapsedFill = {
|
const balancer2Fill: CollapsedFill = {
|
||||||
...kyberSample2,
|
...balancerSample2,
|
||||||
subFills: [],
|
subFills: [],
|
||||||
sourcePathId: hexUtils.random(),
|
sourcePathId: hexUtils.random(),
|
||||||
type: FillQuoteTransformerOrderType.Bridge,
|
type: FillQuoteTransformerOrderType.Bridge,
|
||||||
};
|
};
|
||||||
const orderbookOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(orderbookOrder2);
|
const orderbookOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(orderbookOrder2);
|
||||||
const rfqtOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(rfqtOrder2);
|
const rfqtOrder2Fill: CollapsedFill = collapsedFillFromNativeOrder(rfqtOrder2);
|
||||||
const pathGenerated: CollapsedFill[] = [rfqtOrder2Fill, orderbookOrder2Fill, uniswap2Fill, kyber2Fill];
|
const pathGenerated: CollapsedFill[] = [rfqtOrder2Fill, orderbookOrder2Fill, uniswap2Fill, balancer2Fill];
|
||||||
|
|
||||||
// quote generator mock
|
// quote generator mock
|
||||||
const quoteRequestor = TypeMoq.Mock.ofType<QuoteRequestor>();
|
const quoteRequestor = TypeMoq.Mock.ofType<QuoteRequestor>();
|
||||||
@ -190,10 +190,10 @@ describe('generateQuoteReport', async () => {
|
|||||||
takerAmount: uniswapSample2.input,
|
takerAmount: uniswapSample2.input,
|
||||||
fillData: {},
|
fillData: {},
|
||||||
};
|
};
|
||||||
const kyber2Source: BridgeQuoteReportEntry = {
|
const balancer2Source: BridgeQuoteReportEntry = {
|
||||||
liquiditySource: ERC20BridgeSource.Kyber,
|
liquiditySource: ERC20BridgeSource.BalancerV2,
|
||||||
makerAmount: kyberSample2.output,
|
makerAmount: balancerSample2.output,
|
||||||
takerAmount: kyberSample2.input,
|
takerAmount: balancerSample2.input,
|
||||||
fillData: {},
|
fillData: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ describe('generateQuoteReport', async () => {
|
|||||||
rfqtOrder2Source,
|
rfqtOrder2Source,
|
||||||
orderbookOrder2Source,
|
orderbookOrder2Source,
|
||||||
uniswap2Source,
|
uniswap2Source,
|
||||||
kyber2Source,
|
balancer2Source,
|
||||||
];
|
];
|
||||||
expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`);
|
expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`);
|
||||||
expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`);
|
expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`);
|
||||||
@ -210,8 +210,8 @@ describe('generateQuoteReport', async () => {
|
|||||||
});
|
});
|
||||||
it('should handle properly for buy without quoteRequestor', () => {
|
it('should handle properly for buy without quoteRequestor', () => {
|
||||||
const marketOperation: MarketOperation = MarketOperation.Buy;
|
const marketOperation: MarketOperation = MarketOperation.Buy;
|
||||||
const kyberSample1: DexSample = {
|
const balancerSample1: DexSample = {
|
||||||
source: ERC20BridgeSource.Kyber,
|
source: ERC20BridgeSource.BalancerV2,
|
||||||
input: new BigNumber(10000),
|
input: new BigNumber(10000),
|
||||||
output: new BigNumber(10001),
|
output: new BigNumber(10001),
|
||||||
fillData: {},
|
fillData: {},
|
||||||
@ -248,13 +248,13 @@ describe('generateQuoteReport', async () => {
|
|||||||
sourcePathId: hexUtils.random(),
|
sourcePathId: hexUtils.random(),
|
||||||
type: FillQuoteTransformerOrderType.Bridge,
|
type: FillQuoteTransformerOrderType.Bridge,
|
||||||
};
|
};
|
||||||
const kyber1Fill: CollapsedFill = {
|
const balancer1Fill: CollapsedFill = {
|
||||||
...kyberSample1,
|
...balancerSample1,
|
||||||
subFills: [],
|
subFills: [],
|
||||||
sourcePathId: hexUtils.random(),
|
sourcePathId: hexUtils.random(),
|
||||||
type: FillQuoteTransformerOrderType.Bridge,
|
type: FillQuoteTransformerOrderType.Bridge,
|
||||||
};
|
};
|
||||||
const pathGenerated: CollapsedFill[] = [orderbookOrder1Fill, uniswap1Fill, kyber1Fill];
|
const pathGenerated: CollapsedFill[] = [orderbookOrder1Fill, uniswap1Fill, balancer1Fill];
|
||||||
|
|
||||||
const orderReport = generateQuoteReport(marketOperation, nativeOrders, pathGenerated);
|
const orderReport = generateQuoteReport(marketOperation, nativeOrders, pathGenerated);
|
||||||
|
|
||||||
@ -274,16 +274,16 @@ describe('generateQuoteReport', async () => {
|
|||||||
takerAmount: uniswapSample1.output,
|
takerAmount: uniswapSample1.output,
|
||||||
fillData: {},
|
fillData: {},
|
||||||
};
|
};
|
||||||
const kyber1Source: BridgeQuoteReportEntry = {
|
const balancer1Source: BridgeQuoteReportEntry = {
|
||||||
liquiditySource: ERC20BridgeSource.Kyber,
|
liquiditySource: ERC20BridgeSource.BalancerV2,
|
||||||
makerAmount: kyberSample1.input,
|
makerAmount: balancerSample1.input,
|
||||||
takerAmount: kyberSample1.output,
|
takerAmount: balancerSample1.output,
|
||||||
fillData: {},
|
fillData: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
// No order is considered here because only Native RFQ orders are considered.
|
// No order is considered here because only Native RFQ orders are considered.
|
||||||
const expectedSourcesConsidered: QuoteReportEntry[] = [];
|
const expectedSourcesConsidered: QuoteReportEntry[] = [];
|
||||||
const expectedSourcesDelivered: QuoteReportEntry[] = [orderbookOrder1Source, uniswap1Source, kyber1Source];
|
const expectedSourcesDelivered: QuoteReportEntry[] = [orderbookOrder1Source, uniswap1Source, balancer1Source];
|
||||||
expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`);
|
expectEqualQuoteReportEntries(orderReport.sourcesConsidered, expectedSourcesConsidered, `sourcesConsidered`);
|
||||||
expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`);
|
expectEqualQuoteReportEntries(orderReport.sourcesDelivered, expectedSourcesDelivered, `sourcesDelivered`);
|
||||||
});
|
});
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import { ContractTxFunctionObj } from '@0x/base-contract';
|
import { ContractTxFunctionObj } from '@0x/base-contract';
|
||||||
import { constants } from '@0x/contracts-test-utils';
|
import { constants } from '@0x/contracts-test-utils';
|
||||||
import { LimitOrderFields, Signature } from '@0x/protocol-utils';
|
import { LimitOrderFields, Signature } from '@0x/protocol-utils';
|
||||||
import { BigNumber, hexUtils, NULL_BYTES } from '@0x/utils';
|
import { BigNumber, hexUtils } from '@0x/utils';
|
||||||
|
|
||||||
import { SamplerCallResult } from '../../src/types';
|
import { SamplerCallResult } from '../../src/types';
|
||||||
import { KyberSamplerOpts } from '../../src/utils/market_operation_utils/types';
|
|
||||||
import { ERC20BridgeSamplerContract } from '../../src/wrappers';
|
import { ERC20BridgeSamplerContract } from '../../src/wrappers';
|
||||||
|
|
||||||
export type GetOrderFillableAssetAmountResult = BigNumber[];
|
export type GetOrderFillableAssetAmountResult = BigNumber[];
|
||||||
@ -39,18 +38,6 @@ export type SampleBuysEth2DaiHandler = (
|
|||||||
makerToken: string,
|
makerToken: string,
|
||||||
makerTokenAmounts: BigNumber[],
|
makerTokenAmounts: BigNumber[],
|
||||||
) => SampleResults;
|
) => SampleResults;
|
||||||
export type SampleSellsKyberHandler = (
|
|
||||||
opts: KyberSamplerOpts,
|
|
||||||
takerToken: string,
|
|
||||||
makerToken: string,
|
|
||||||
takerTokenAmounts: BigNumber[],
|
|
||||||
) => [string, string, SampleResults];
|
|
||||||
export type SampleBuysKyberHandler = (
|
|
||||||
reserveId: string,
|
|
||||||
takerToken: string,
|
|
||||||
makerToken: string,
|
|
||||||
makerTokenAmounts: BigNumber[],
|
|
||||||
) => [string, SampleResults];
|
|
||||||
export type SampleUniswapV2Handler = (router: string, path: string[], assetAmounts: BigNumber[]) => SampleResults;
|
export type SampleUniswapV2Handler = (router: string, path: string[], assetAmounts: BigNumber[]) => SampleResults;
|
||||||
export type SampleBuysMultihopHandler = (path: string[], takerTokenAmounts: BigNumber[]) => SampleResults;
|
export type SampleBuysMultihopHandler = (path: string[], takerTokenAmounts: BigNumber[]) => SampleResults;
|
||||||
export type SampleSellsLPHandler = (
|
export type SampleSellsLPHandler = (
|
||||||
@ -70,7 +57,6 @@ const DUMMY_PROVIDER = {
|
|||||||
interface Handlers {
|
interface Handlers {
|
||||||
getLimitOrderFillableMakerAssetAmounts: GetOrderFillableAssetAmountHandler;
|
getLimitOrderFillableMakerAssetAmounts: GetOrderFillableAssetAmountHandler;
|
||||||
getLimitOrderFillableTakerAssetAmounts: GetOrderFillableAssetAmountHandler;
|
getLimitOrderFillableTakerAssetAmounts: GetOrderFillableAssetAmountHandler;
|
||||||
sampleSellsFromKyberNetwork: SampleSellsKyberHandler;
|
|
||||||
sampleSellsFromLiquidityProvider: SampleSellsLPHandler;
|
sampleSellsFromLiquidityProvider: SampleSellsLPHandler;
|
||||||
sampleSellsFromUniswap: SampleSellsUniswapHandler;
|
sampleSellsFromUniswap: SampleSellsUniswapHandler;
|
||||||
sampleSellsFromUniswapV2: SampleUniswapV2Handler;
|
sampleSellsFromUniswapV2: SampleUniswapV2Handler;
|
||||||
@ -123,22 +109,6 @@ export class MockSamplerContract extends ERC20BridgeSamplerContract {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public sampleSellsFromKyberNetwork(
|
|
||||||
opts: KyberSamplerOpts,
|
|
||||||
takerToken: string,
|
|
||||||
makerToken: string,
|
|
||||||
takerAssetAmounts: BigNumber[],
|
|
||||||
): ContractTxFunctionObj<[string, string, BigNumber[]]> {
|
|
||||||
return this._wrapCall(
|
|
||||||
super.sampleSellsFromKyberNetwork,
|
|
||||||
this._handlers.sampleSellsFromKyberNetwork,
|
|
||||||
{ ...opts, reserveOffset: new BigNumber(1), hint: NULL_BYTES },
|
|
||||||
takerToken,
|
|
||||||
makerToken,
|
|
||||||
takerAssetAmounts,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public sampleSellsFromUniswap(
|
public sampleSellsFromUniswap(
|
||||||
router: string,
|
router: string,
|
||||||
takerToken: string,
|
takerToken: string,
|
||||||
|
@ -21,7 +21,6 @@ export * from '../test/generated-wrappers/i_balancer';
|
|||||||
export * from '../test/generated-wrappers/i_balancer_v2_vault';
|
export * from '../test/generated-wrappers/i_balancer_v2_vault';
|
||||||
export * from '../test/generated-wrappers/i_bancor';
|
export * from '../test/generated-wrappers/i_bancor';
|
||||||
export * from '../test/generated-wrappers/i_curve';
|
export * from '../test/generated-wrappers/i_curve';
|
||||||
export * from '../test/generated-wrappers/i_kyber_network';
|
|
||||||
export * from '../test/generated-wrappers/i_m_stable';
|
export * from '../test/generated-wrappers/i_m_stable';
|
||||||
export * from '../test/generated-wrappers/i_mooniswap';
|
export * from '../test/generated-wrappers/i_mooniswap';
|
||||||
export * from '../test/generated-wrappers/i_multi_bridge';
|
export * from '../test/generated-wrappers/i_multi_bridge';
|
||||||
@ -32,7 +31,6 @@ export * from '../test/generated-wrappers/i_uniswap_exchange_quotes';
|
|||||||
export * from '../test/generated-wrappers/i_uniswap_v2_router01';
|
export * from '../test/generated-wrappers/i_uniswap_v2_router01';
|
||||||
export * from '../test/generated-wrappers/igmx';
|
export * from '../test/generated-wrappers/igmx';
|
||||||
export * from '../test/generated-wrappers/kyber_dmm_sampler';
|
export * from '../test/generated-wrappers/kyber_dmm_sampler';
|
||||||
export * from '../test/generated-wrappers/kyber_sampler';
|
|
||||||
export * from '../test/generated-wrappers/lido_sampler';
|
export * from '../test/generated-wrappers/lido_sampler';
|
||||||
export * from '../test/generated-wrappers/liquidity_provider_sampler';
|
export * from '../test/generated-wrappers/liquidity_provider_sampler';
|
||||||
export * from '../test/generated-wrappers/m_stable_sampler';
|
export * from '../test/generated-wrappers/m_stable_sampler';
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
"test/generated-artifacts/IBancor.json",
|
"test/generated-artifacts/IBancor.json",
|
||||||
"test/generated-artifacts/ICurve.json",
|
"test/generated-artifacts/ICurve.json",
|
||||||
"test/generated-artifacts/IGMX.json",
|
"test/generated-artifacts/IGMX.json",
|
||||||
"test/generated-artifacts/IKyberNetwork.json",
|
|
||||||
"test/generated-artifacts/IMStable.json",
|
"test/generated-artifacts/IMStable.json",
|
||||||
"test/generated-artifacts/IMooniswap.json",
|
"test/generated-artifacts/IMooniswap.json",
|
||||||
"test/generated-artifacts/IMultiBridge.json",
|
"test/generated-artifacts/IMultiBridge.json",
|
||||||
@ -35,7 +34,6 @@
|
|||||||
"test/generated-artifacts/IUniswapExchangeQuotes.json",
|
"test/generated-artifacts/IUniswapExchangeQuotes.json",
|
||||||
"test/generated-artifacts/IUniswapV2Router01.json",
|
"test/generated-artifacts/IUniswapV2Router01.json",
|
||||||
"test/generated-artifacts/KyberDmmSampler.json",
|
"test/generated-artifacts/KyberDmmSampler.json",
|
||||||
"test/generated-artifacts/KyberSampler.json",
|
|
||||||
"test/generated-artifacts/LidoSampler.json",
|
"test/generated-artifacts/LidoSampler.json",
|
||||||
"test/generated-artifacts/LiquidityProviderSampler.json",
|
"test/generated-artifacts/LiquidityProviderSampler.json",
|
||||||
"test/generated-artifacts/MStableSampler.json",
|
"test/generated-artifacts/MStableSampler.json",
|
||||||
|
@ -114,16 +114,13 @@ export enum BridgeProtocol {
|
|||||||
UniswapV2,
|
UniswapV2,
|
||||||
Uniswap,
|
Uniswap,
|
||||||
Balancer,
|
Balancer,
|
||||||
Kyber,
|
|
||||||
Mooniswap,
|
Mooniswap,
|
||||||
MStable,
|
MStable,
|
||||||
Oasis,
|
|
||||||
Shell,
|
Shell,
|
||||||
Dodo,
|
Dodo,
|
||||||
DodoV2,
|
DodoV2,
|
||||||
CryptoCom,
|
CryptoCom,
|
||||||
Bancor,
|
Bancor,
|
||||||
CoFiX,
|
|
||||||
Nerve,
|
Nerve,
|
||||||
MakerPsm,
|
MakerPsm,
|
||||||
BalancerV2,
|
BalancerV2,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user