Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
moodlezoup committed Feb 21, 2020
1 parent e7a07e4 commit 11f3ff1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract ERC20BridgeSampler is
/// @dev Base gas limit for Curve calls. Some Curves have multiple tokens
/// So a reasonable ceil is 150k per token. Biggest Curve has 4 tokens.
uint256 constant internal CURVE_CALL_GAS = 600e3; // 600k
/// @dev Defaukt gas limit for liquidity provider calls.
/// @dev Default gas limit for liquidity provider calls.
uint256 constant internal DEFAULT_CALL_GAS = 200e3; // 200k

/// @dev Call multiple public functions on this contract in a single transaction.
Expand Down Expand Up @@ -451,41 +451,12 @@ contract ERC20BridgeSampler is
public
view
returns (uint256[] memory makerTokenAmounts)
{
return sampleSellsFromLiquidityProvider(
providerAddress,
takerToken,
makerToken,
takerTokenAmounts,
DEFAULT_CALL_GAS
);
}

/// @dev Sample sell quotes from an arbitrary on-chain liquidity provider.
/// @param providerAddress Address of the liquidity provider contract.
/// @param takerToken Address of the taker token (what to sell).
/// @param makerToken Address of the maker token (what to buy).
/// @param takerTokenAmounts Taker token sell amount for each sample.
/// @param callGasLimit Gas limit to use for calls to the provider's
/// `getSellQuote` method.
/// @return makerTokenAmounts Maker amounts bought at each taker token
/// amount.
function sampleSellsFromLiquidityProvider(
address providerAddress,
address takerToken,
address makerToken,
uint256[] memory takerTokenAmounts,
uint256 callGasLimit
)
public
view
returns (uint256[] memory makerTokenAmounts)
{
uint256 numSamples = takerTokenAmounts.length;
makerTokenAmounts = new uint256[](numSamples);
for (uint256 i = 0; i < numSamples; i++) {
(bool didSucceed, bytes memory resultData) =
providerAddress.staticcall.gas(callGasLimit)(
providerAddress.staticcall.gas(DEFAULT_CALL_GAS)(
abi.encodeWithSelector(
ILiquidityProvider(0).getSellQuote.selector,
takerToken,
Expand All @@ -496,6 +467,7 @@ contract ERC20BridgeSampler is
if (didSucceed) {
buyAmount = abi.decode(resultData, (uint256));
} else {
// Exit early if the amount is too high for the liquidity provider to serve
break;
}
makerTokenAmounts[i] = buyAmount;
Expand All @@ -519,42 +491,12 @@ contract ERC20BridgeSampler is
public
view
returns (uint256[] memory takerTokenAmounts)
{
return sampleBuysFromLiquidityProvider(
providerAddress,
takerToken,
makerToken,
makerTokenAmounts,
DEFAULT_CALL_GAS
);
}

/// @dev Sample buy quotes from an arbitrary on-chain liquidity provider.
/// Calls the provider contract with the default gas limit (200k).
/// @param providerAddress Address of the liquidity provider contract.
/// @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.
/// @param callGasLimit Gas limit to use for calls to the provider's
/// `getBuyQuote` method.
/// @return takerTokenAmounts Taker amounts sold at each maker token
/// amount.
function sampleBuysFromLiquidityProvider(
address providerAddress,
address takerToken,
address makerToken,
uint256[] memory makerTokenAmounts,
uint256 callGasLimit
)
public
view
returns (uint256[] memory takerTokenAmounts)
{
uint256 numSamples = makerTokenAmounts.length;
takerTokenAmounts = new uint256[](numSamples);
for (uint256 i = 0; i < numSamples; i++) {
(bool didSucceed, bytes memory resultData) =
providerAddress.staticcall.gas(callGasLimit)(
providerAddress.staticcall.gas(DEFAULT_CALL_GAS)(
abi.encodeWithSelector(
ILiquidityProvider(0).getBuyQuote.selector,
takerToken,
Expand All @@ -565,6 +507,7 @@ contract ERC20BridgeSampler is
if (didSucceed) {
sellAmount = abi.decode(resultData, (uint256));
} else {
// Exit early if the amount is too high for the liquidity provider to serve
break;
}
takerTokenAmounts[i] = sellAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,40 @@ interface IERC20BridgeSampler {
external
view
returns (uint256[] memory makerTokenAmounts);

/// @dev Sample sell quotes from an arbitrary on-chain liquidity provider.
/// Calls the provider contract with the default gas limit (200k).
/// @param providerAddress Address of the liquidity provider contract.
/// @param takerToken Address of the taker token (what to sell).
/// @param makerToken Address of the maker token (what to buy).
/// @param takerTokenAmounts Taker token sell amount for each sample.
/// @return makerTokenAmounts Maker amounts bought at each taker token
/// amount.
function sampleSellsFromLiquidityProvider(
address providerAddress,
address takerToken,
address makerToken,
uint256[] memory takerTokenAmounts
)
public
view
returns (uint256[] memory makerTokenAmounts);

/// @dev Sample buy quotes from an arbitrary on-chain liquidity provider.
/// Calls the provider contract with the default gas limit (200k).
/// @param providerAddress Address of the liquidity provider contract.
/// @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 takerTokenAmounts Taker amounts sold at each maker token
/// amount.
function sampleBuysFromLiquidityProvider(
address providerAddress,
address takerToken,
address makerToken,
uint256[] memory makerTokenAmounts
)
public
view
returns (uint256[] memory takerTokenAmounts);
}

0 comments on commit 11f3ff1

Please sign in to comment.