added weth/eth support to sampler
This commit is contained in:
parent
9b131199ad
commit
fd69a0c273
@ -28,6 +28,8 @@ contract BancorV3Sampler
|
|||||||
/// @dev Gas limit for BancorV3 calls.
|
/// @dev Gas limit for BancorV3 calls.
|
||||||
uint256 constant private BancorV3_CALL_GAS = 150e3; // 150k
|
uint256 constant private BancorV3_CALL_GAS = 150e3; // 150k
|
||||||
|
|
||||||
|
address constant public ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
|
||||||
|
|
||||||
/// @dev Sample sell quotes from BancorV3.
|
/// @dev Sample sell quotes from BancorV3.
|
||||||
/// @param router Router to look up tokens and amounts
|
/// @param router Router to look up tokens and amounts
|
||||||
/// @param path Token route. Should be takerToken -> makerToken
|
/// @param path Token route. Should be takerToken -> makerToken
|
||||||
@ -35,6 +37,7 @@ contract BancorV3Sampler
|
|||||||
/// @return makerTokenAmounts Maker amounts bought at each taker token
|
/// @return makerTokenAmounts Maker amounts bought at each taker token
|
||||||
/// amount.
|
/// amount.
|
||||||
function sampleSellsFromBancorV3(
|
function sampleSellsFromBancorV3(
|
||||||
|
address weth,
|
||||||
address router,
|
address router,
|
||||||
address[] memory path,
|
address[] memory path,
|
||||||
uint256[] memory takerTokenAmounts
|
uint256[] memory takerTokenAmounts
|
||||||
@ -45,6 +48,14 @@ contract BancorV3Sampler
|
|||||||
{
|
{
|
||||||
uint256 numSamples = takerTokenAmounts.length;
|
uint256 numSamples = takerTokenAmounts.length;
|
||||||
makerTokenAmounts = new uint256[](numSamples);
|
makerTokenAmounts = new uint256[](numSamples);
|
||||||
|
|
||||||
|
if(path[0] == weth){
|
||||||
|
path[0] = ETH;
|
||||||
|
}
|
||||||
|
if(path[1] == weth){
|
||||||
|
path[1] = ETH;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint256 i = 0; i < numSamples; i++) {
|
for (uint256 i = 0; i < numSamples; i++) {
|
||||||
try
|
try
|
||||||
IBancorV3(router).tradeOutputBySourceAmount(path[0], path[1], takerTokenAmounts[i])
|
IBancorV3(router).tradeOutputBySourceAmount(path[0], path[1], takerTokenAmounts[i])
|
||||||
@ -69,6 +80,7 @@ contract BancorV3Sampler
|
|||||||
/// @return takerTokenAmounts Taker amounts sold at each maker token
|
/// @return takerTokenAmounts Taker amounts sold at each maker token
|
||||||
/// amount.
|
/// amount.
|
||||||
function sampleBuysFromBancorV3(
|
function sampleBuysFromBancorV3(
|
||||||
|
address weth,
|
||||||
address router,
|
address router,
|
||||||
address[] memory path,
|
address[] memory path,
|
||||||
uint256[] memory makerTokenAmounts
|
uint256[] memory makerTokenAmounts
|
||||||
@ -79,6 +91,14 @@ contract BancorV3Sampler
|
|||||||
{
|
{
|
||||||
uint256 numSamples = makerTokenAmounts.length;
|
uint256 numSamples = makerTokenAmounts.length;
|
||||||
takerTokenAmounts = new uint256[](numSamples);
|
takerTokenAmounts = new uint256[](numSamples);
|
||||||
|
|
||||||
|
if(path[0] == weth){
|
||||||
|
path[0] = ETH;
|
||||||
|
}
|
||||||
|
if(path[1] == weth){
|
||||||
|
path[1] = ETH;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint256 i = 0; i < numSamples; i++) {
|
for (uint256 i = 0; i < numSamples; i++) {
|
||||||
try
|
try
|
||||||
IBancorV3(router).tradeInputByTargetAmount(path[0], path[1], makerTokenAmounts[i])
|
IBancorV3(router).tradeInputByTargetAmount(path[0], path[1], makerTokenAmounts[i])
|
||||||
|
@ -47,6 +47,7 @@ import {
|
|||||||
SELL_SOURCE_FILTER_BY_CHAIN_ID,
|
SELL_SOURCE_FILTER_BY_CHAIN_ID,
|
||||||
UNISWAPV1_ROUTER_BY_CHAIN_ID,
|
UNISWAPV1_ROUTER_BY_CHAIN_ID,
|
||||||
UNISWAPV3_CONFIG_BY_CHAIN_ID,
|
UNISWAPV3_CONFIG_BY_CHAIN_ID,
|
||||||
|
MAINNET_TOKENS,
|
||||||
ZERO_AMOUNT,
|
ZERO_AMOUNT,
|
||||||
} from './constants';
|
} from './constants';
|
||||||
import { getGeistInfoForPair } from './geist_utils';
|
import { getGeistInfoForPair } from './geist_utils';
|
||||||
@ -722,7 +723,7 @@ export class SamplerOperations {
|
|||||||
fillData: { networkAddress, path},
|
fillData: { networkAddress, path},
|
||||||
contract: this._samplerContract,
|
contract: this._samplerContract,
|
||||||
function: this._samplerContract.sampleBuysFromBancorV3,
|
function: this._samplerContract.sampleBuysFromBancorV3,
|
||||||
params: [networkInfoAddress, path, takerFillAmounts],
|
params: [MAINNET_TOKENS.WETH, networkInfoAddress, path, takerFillAmounts],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,7 +739,7 @@ export class SamplerOperations {
|
|||||||
fillData: { networkAddress, path},
|
fillData: { networkAddress, path},
|
||||||
contract: this._samplerContract,
|
contract: this._samplerContract,
|
||||||
function: this._samplerContract.sampleBuysFromBancorV3,
|
function: this._samplerContract.sampleBuysFromBancorV3,
|
||||||
params: [networkInfoAddress, path, makerFillAmounts],
|
params: [MAINNET_TOKENS.WETH, networkInfoAddress, path, makerFillAmounts],
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user