diff --git a/packages/asset-swapper/CHANGELOG.json b/packages/asset-swapper/CHANGELOG.json index 3fe00ec134..12b3dc00af 100644 --- a/packages/asset-swapper/CHANGELOG.json +++ b/packages/asset-swapper/CHANGELOG.json @@ -29,6 +29,10 @@ { "note": "Special case BNB in uni v1 sampler", "pr": 147 + }, + { + "note": "Create `FakeTaker` contract to get result data and gas used", + "pr": 151 } ] }, diff --git a/packages/asset-swapper/contracts/src/FakeTaker.sol b/packages/asset-swapper/contracts/src/FakeTaker.sol new file mode 100644 index 0000000000..086c5a1590 --- /dev/null +++ b/packages/asset-swapper/contracts/src/FakeTaker.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity ^0.6; +pragma experimental ABIEncoderV2; + +contract FakeTaker { + + struct Result { + bool success; + bytes resultData; + uint256 gasUsed; + } + + receive() payable external {} + + function execute(address payable to, bytes calldata data) + public + payable + returns (Result memory result) + { + uint256 gasBefore = gasleft(); + ( + result.success, + result.resultData + ) = to.call{ value: msg.value }(data); + result.gasUsed = gasBefore - gasleft(); + } +} diff --git a/packages/asset-swapper/package.json b/packages/asset-swapper/package.json index 7f89d1880f..bc2d7a6fe6 100644 --- a/packages/asset-swapper/package.json +++ b/packages/asset-swapper/package.json @@ -36,9 +36,9 @@ "publish:private": "yarn build && gitpkg publish" }, "config": { - "publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker", + "publicInterfaceContracts": "ERC20BridgeSampler,BalanceChecker,FakeTaker", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", - "abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BancorSampler|CurveSampler|DODOSampler|DeploymentConstants|DummyLiquidityProvider|ERC20BridgeSampler|Eth2DaiSampler|IBalancer|IBancor|ICurve|IEth2Dai|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IShell|IUniswapExchangeQuotes|IUniswapV2Router01|KyberSampler|LiquidityProviderSampler|MStableSampler|MooniswapSampler|MultiBridgeSampler|NativeOrderSampler|SamplerUtils|ShellSampler|SushiSwapSampler|TestERC20BridgeSampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UtilitySampler).json", + "abis": "./test/generated-artifacts/@(ApproximateBuys|BalanceChecker|BalancerSampler|BancorSampler|CurveSampler|DODOSampler|DeploymentConstants|DummyLiquidityProvider|ERC20BridgeSampler|Eth2DaiSampler|FakeTaker|IBalancer|IBancor|ICurve|IEth2Dai|IKyberNetwork|IMStable|IMooniswap|IMultiBridge|IShell|IUniswapExchangeQuotes|IUniswapV2Router01|KyberSampler|LiquidityProviderSampler|MStableSampler|MooniswapSampler|MultiBridgeSampler|NativeOrderSampler|SamplerUtils|ShellSampler|SushiSwapSampler|TestERC20BridgeSampler|TestNativeOrderSampler|TwoHopSampler|UniswapSampler|UniswapV2Sampler|UtilitySampler).json", "postpublish": { "assets": [] } diff --git a/packages/asset-swapper/src/artifacts.ts b/packages/asset-swapper/src/artifacts.ts index da0b6ac0cd..9ea4a461e9 100644 --- a/packages/asset-swapper/src/artifacts.ts +++ b/packages/asset-swapper/src/artifacts.ts @@ -7,7 +7,9 @@ import { ContractArtifact } from 'ethereum-types'; import * as BalanceChecker from '../generated-artifacts/BalanceChecker.json'; import * as ERC20BridgeSampler from '../generated-artifacts/ERC20BridgeSampler.json'; +import * as FakeTaker from '../generated-artifacts/FakeTaker.json'; export const artifacts = { ERC20BridgeSampler: ERC20BridgeSampler as ContractArtifact, BalanceChecker: BalanceChecker as ContractArtifact, + FakeTaker: FakeTaker as ContractArtifact, }; diff --git a/packages/asset-swapper/src/index.ts b/packages/asset-swapper/src/index.ts index 0aa21d14b5..4a3d8f2295 100644 --- a/packages/asset-swapper/src/index.ts +++ b/packages/asset-swapper/src/index.ts @@ -162,7 +162,7 @@ export { QuoteReportEntry, } from './utils/quote_report_generator'; export { QuoteRequestor } from './utils/quote_requestor'; -export { ERC20BridgeSamplerContract, BalanceCheckerContract } from './wrappers'; +export { ERC20BridgeSamplerContract, BalanceCheckerContract, FakeTakerContract } from './wrappers'; import { ERC20BridgeSource } from './utils/market_operation_utils/types'; export type Native = ERC20BridgeSource.Native; export type MultiHop = ERC20BridgeSource.MultiHop; diff --git a/packages/asset-swapper/src/wrappers.ts b/packages/asset-swapper/src/wrappers.ts index 5d8c796e4c..27b17d67ac 100644 --- a/packages/asset-swapper/src/wrappers.ts +++ b/packages/asset-swapper/src/wrappers.ts @@ -5,3 +5,4 @@ */ export * from '../generated-wrappers/balance_checker'; export * from '../generated-wrappers/erc20_bridge_sampler'; +export * from '../generated-wrappers/fake_taker'; diff --git a/packages/asset-swapper/test/artifacts.ts b/packages/asset-swapper/test/artifacts.ts index 331a918b4d..248337b925 100644 --- a/packages/asset-swapper/test/artifacts.ts +++ b/packages/asset-swapper/test/artifacts.ts @@ -15,6 +15,7 @@ import * as DODOSampler from '../test/generated-artifacts/DODOSampler.json'; import * as DummyLiquidityProvider from '../test/generated-artifacts/DummyLiquidityProvider.json'; import * as ERC20BridgeSampler from '../test/generated-artifacts/ERC20BridgeSampler.json'; import * as Eth2DaiSampler from '../test/generated-artifacts/Eth2DaiSampler.json'; +import * as FakeTaker from '../test/generated-artifacts/FakeTaker.json'; import * as IBalancer from '../test/generated-artifacts/IBalancer.json'; import * as IBancor from '../test/generated-artifacts/IBancor.json'; import * as ICurve from '../test/generated-artifacts/ICurve.json'; @@ -51,6 +52,7 @@ export const artifacts = { DeploymentConstants: DeploymentConstants as ContractArtifact, ERC20BridgeSampler: ERC20BridgeSampler as ContractArtifact, Eth2DaiSampler: Eth2DaiSampler as ContractArtifact, + FakeTaker: FakeTaker as ContractArtifact, KyberSampler: KyberSampler as ContractArtifact, LiquidityProviderSampler: LiquidityProviderSampler as ContractArtifact, MStableSampler: MStableSampler as ContractArtifact, diff --git a/packages/asset-swapper/test/wrappers.ts b/packages/asset-swapper/test/wrappers.ts index d1d06a5805..f5c72863ed 100644 --- a/packages/asset-swapper/test/wrappers.ts +++ b/packages/asset-swapper/test/wrappers.ts @@ -13,6 +13,7 @@ export * from '../test/generated-wrappers/deployment_constants'; export * from '../test/generated-wrappers/dummy_liquidity_provider'; export * from '../test/generated-wrappers/erc20_bridge_sampler'; export * from '../test/generated-wrappers/eth2_dai_sampler'; +export * from '../test/generated-wrappers/fake_taker'; export * from '../test/generated-wrappers/i_balancer'; export * from '../test/generated-wrappers/i_bancor'; export * from '../test/generated-wrappers/i_curve'; diff --git a/packages/asset-swapper/tsconfig.json b/packages/asset-swapper/tsconfig.json index 3603aae0c0..9f52b087c4 100644 --- a/packages/asset-swapper/tsconfig.json +++ b/packages/asset-swapper/tsconfig.json @@ -5,6 +5,7 @@ "files": [ "generated-artifacts/BalanceChecker.json", "generated-artifacts/ERC20BridgeSampler.json", + "generated-artifacts/FakeTaker.json", "test/generated-artifacts/ApproximateBuys.json", "test/generated-artifacts/BalanceChecker.json", "test/generated-artifacts/BalancerSampler.json", @@ -15,6 +16,7 @@ "test/generated-artifacts/DummyLiquidityProvider.json", "test/generated-artifacts/ERC20BridgeSampler.json", "test/generated-artifacts/Eth2DaiSampler.json", + "test/generated-artifacts/FakeTaker.json", "test/generated-artifacts/IBalancer.json", "test/generated-artifacts/IBancor.json", "test/generated-artifacts/ICurve.json",