feat: Enable partial Native order fills. Union intermediary tokens (#309)
* feat: Enable partial Native order fills * change intermediary tokens to be a UNION. Hint to cvxCRV and CRV * Pin asset-swapper to use contracts-zero-ex 0.27.0 for now * feat: Retire Eth2Dai/Oasis
This commit is contained in:
@@ -15,12 +15,10 @@ import * as DODOSampler from '../test/generated-artifacts/DODOSampler.json';
|
||||
import * as DODOV2Sampler from '../test/generated-artifacts/DODOV2Sampler.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';
|
||||
import * as IEth2Dai from '../test/generated-artifacts/IEth2Dai.json';
|
||||
import * as IKyberNetwork from '../test/generated-artifacts/IKyberNetwork.json';
|
||||
import * as IMooniswap from '../test/generated-artifacts/IMooniswap.json';
|
||||
import * as IMStable from '../test/generated-artifacts/IMStable.json';
|
||||
@@ -58,7 +56,6 @@ export const artifacts = {
|
||||
DODOSampler: DODOSampler as ContractArtifact,
|
||||
DODOV2Sampler: DODOV2Sampler as ContractArtifact,
|
||||
ERC20BridgeSampler: ERC20BridgeSampler as ContractArtifact,
|
||||
Eth2DaiSampler: Eth2DaiSampler as ContractArtifact,
|
||||
FakeTaker: FakeTaker as ContractArtifact,
|
||||
KyberDmmSampler: KyberDmmSampler as ContractArtifact,
|
||||
KyberSampler: KyberSampler as ContractArtifact,
|
||||
@@ -80,7 +77,6 @@ export const artifacts = {
|
||||
IBalancer: IBalancer as ContractArtifact,
|
||||
IBancor: IBancor as ContractArtifact,
|
||||
ICurve: ICurve as ContractArtifact,
|
||||
IEth2Dai: IEth2Dai as ContractArtifact,
|
||||
IKyberNetwork: IKyberNetwork as ContractArtifact,
|
||||
IMStable: IMStable as ContractArtifact,
|
||||
IMooniswap: IMooniswap as ContractArtifact,
|
||||
|
||||
@@ -27,7 +27,6 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
const MAX_DECIMALS = 20;
|
||||
const WETH_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
||||
const KYBER_SALT = '0x0ff3ca9d46195c39f9a12afb74207b4970349fb3cfb1e459bbf170298d326bc7';
|
||||
const ETH2DAI_SALT = '0xb713b61bb9bb2958a0f5d1534b21e94fc68c4c0c034b0902ed844f2f6cd1b4f7';
|
||||
const UNISWAP_BASE_SALT = '0x1d6a6a0506b0b4a554b907a4c29d9f4674e461989d9c1921feb17b26716385ab';
|
||||
const UNISWAP_V2_SALT = '0xadc7fcb33c735913b8635927e66896b356a53a912ab2ceff929e60a04b53b3c1';
|
||||
const INVALID_TOKEN_PAIR_ERROR = 'ERC20BridgeSampler/INVALID_TOKEN_PAIR';
|
||||
@@ -36,7 +35,6 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
const INTERMEDIATE_TOKEN = randomAddress();
|
||||
const KYBER_RESERVE_OFFSET = new BigNumber(0);
|
||||
let KYBER_ADDRESS = '';
|
||||
let ETH2DAI_ADDRESS = '';
|
||||
let UNISWAP_ADDRESS = '';
|
||||
let UNISWAP_V2_ROUTER = '';
|
||||
|
||||
@@ -49,7 +47,6 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
);
|
||||
UNISWAP_V2_ROUTER = await testContract.uniswapV2Router().callAsync();
|
||||
KYBER_ADDRESS = await testContract.kyber().callAsync();
|
||||
ETH2DAI_ADDRESS = await testContract.eth2Dai().callAsync();
|
||||
UNISWAP_ADDRESS = await testContract.uniswap().callAsync();
|
||||
});
|
||||
|
||||
@@ -152,15 +149,8 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
for (const source of sources) {
|
||||
const sampleOutputs = [];
|
||||
for (const amount of sampleAmounts) {
|
||||
if (source === 'Kyber' || source === 'Eth2Dai') {
|
||||
sampleOutputs.push(
|
||||
getDeterministicSellQuote(
|
||||
source === 'Kyber' ? KYBER_SALT : ETH2DAI_SALT,
|
||||
sellToken,
|
||||
buyToken,
|
||||
amount,
|
||||
),
|
||||
);
|
||||
if (source === 'Kyber') {
|
||||
sampleOutputs.push(getDeterministicSellQuote(KYBER_SALT, sellToken, buyToken, amount));
|
||||
} else if (source === 'Uniswap') {
|
||||
sampleOutputs.push(getDeterministicUniswapSellQuote(sellToken, buyToken, amount));
|
||||
}
|
||||
@@ -180,15 +170,8 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
for (const source of sources) {
|
||||
const sampleOutputs = [];
|
||||
for (const amount of sampleAmounts) {
|
||||
if (source === 'Kyber' || source === 'Eth2Dai') {
|
||||
sampleOutputs.push(
|
||||
getDeterministicBuyQuote(
|
||||
source === 'Kyber' ? KYBER_SALT : ETH2DAI_SALT,
|
||||
sellToken,
|
||||
buyToken,
|
||||
amount,
|
||||
),
|
||||
);
|
||||
if (source === 'Kyber') {
|
||||
sampleOutputs.push(getDeterministicBuyQuote(KYBER_SALT, sellToken, buyToken, amount));
|
||||
} else if (source === 'Uniswap') {
|
||||
sampleOutputs.push(getDeterministicUniswapBuyQuote(sellToken, buyToken, amount));
|
||||
}
|
||||
@@ -510,156 +493,6 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('sampleSellsFromEth2Dai()', () => {
|
||||
before(async () => {
|
||||
await testContract.createTokenExchanges([MAKER_TOKEN, TAKER_TOKEN]).awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('throws if tokens are the same', async () => {
|
||||
const tx = testContract.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, MAKER_TOKEN, MAKER_TOKEN, []).callAsync();
|
||||
return expect(tx).to.revertWith(INVALID_TOKEN_PAIR_ERROR);
|
||||
});
|
||||
|
||||
it('can return no quotes', async () => {
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, [])
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq([]);
|
||||
});
|
||||
|
||||
it('can quote token -> token', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicSellQuotes(TAKER_TOKEN, MAKER_TOKEN, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if token -> token fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('can quote token -> ETH', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicSellQuotes(TAKER_TOKEN, WETH_ADDRESS, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, WETH_ADDRESS, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if token -> ETH fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, WETH_ADDRESS, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('can quote ETH -> token', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicSellQuotes(WETH_ADDRESS, TAKER_TOKEN, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, WETH_ADDRESS, TAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if ETH -> token fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(TAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, WETH_ADDRESS, TAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('sampleBuysFromEth2Dai()', () => {
|
||||
before(async () => {
|
||||
await testContract.createTokenExchanges([MAKER_TOKEN, TAKER_TOKEN]).awaitTransactionSuccessAsync();
|
||||
});
|
||||
|
||||
it('throws if tokens are the same', async () => {
|
||||
const tx = testContract.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, MAKER_TOKEN, MAKER_TOKEN, []).callAsync();
|
||||
return expect(tx).to.revertWith(INVALID_TOKEN_PAIR_ERROR);
|
||||
});
|
||||
|
||||
it('can return no quotes', async () => {
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, [])
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq([]);
|
||||
});
|
||||
|
||||
it('can quote token -> token', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicBuyQuotes(TAKER_TOKEN, MAKER_TOKEN, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if token -> token fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, MAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('can quote token -> ETH', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicBuyQuotes(TAKER_TOKEN, WETH_ADDRESS, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, WETH_ADDRESS, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if token -> ETH fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, WETH_ADDRESS, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('can quote ETH -> token', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const [expectedQuotes] = getDeterministicBuyQuotes(WETH_ADDRESS, TAKER_TOKEN, ['Eth2Dai'], sampleAmounts);
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, WETH_ADDRESS, TAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
|
||||
it('returns zero if ETH -> token fails', async () => {
|
||||
const sampleAmounts = getSampleAmounts(MAKER_TOKEN);
|
||||
const expectedQuotes = _.times(sampleAmounts.length, () => constants.ZERO_AMOUNT);
|
||||
await enableFailTriggerAsync();
|
||||
const quotes = await testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, WETH_ADDRESS, TAKER_TOKEN, sampleAmounts)
|
||||
.callAsync();
|
||||
expect(quotes).to.deep.eq(expectedQuotes);
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('sampleSellsFromUniswap()', () => {
|
||||
const UNISWAP_ETH_ADDRESS = NULL_ADDRESS;
|
||||
before(async () => {
|
||||
@@ -1094,35 +927,15 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
.sampleSellsFromUniswapV2(UNISWAP_V2_ROUTER, uniswapV2SecondHopPath, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
|
||||
const eth2DaiFirstHop = testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, INTERMEDIATE_TOKEN, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
const eth2DaiSecondHop = testContract
|
||||
.sampleSellsFromEth2Dai(ETH2DAI_ADDRESS, INTERMEDIATE_TOKEN, MAKER_TOKEN, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
|
||||
const firstHopQuotes = [
|
||||
getDeterministicSellQuote(ETH2DAI_SALT, TAKER_TOKEN, INTERMEDIATE_TOKEN, sellAmount),
|
||||
getDeterministicUniswapV2SellQuote(uniswapV2FirstHopPath, sellAmount),
|
||||
];
|
||||
const firstHopQuotes = [getDeterministicUniswapV2SellQuote(uniswapV2FirstHopPath, sellAmount)];
|
||||
const expectedIntermediateAssetAmount = BigNumber.max(...firstHopQuotes);
|
||||
const secondHopQuotes = [
|
||||
getDeterministicSellQuote(
|
||||
ETH2DAI_SALT,
|
||||
INTERMEDIATE_TOKEN,
|
||||
MAKER_TOKEN,
|
||||
expectedIntermediateAssetAmount,
|
||||
),
|
||||
getDeterministicUniswapV2SellQuote(uniswapV2SecondHopPath, expectedIntermediateAssetAmount),
|
||||
];
|
||||
const expectedBuyAmount = BigNumber.max(...secondHopQuotes);
|
||||
|
||||
const [firstHop, secondHop, buyAmount] = await testContract
|
||||
.sampleTwoHopSell(
|
||||
[eth2DaiFirstHop, uniswapV2FirstHop],
|
||||
[eth2DaiSecondHop, uniswapV2SecondHop],
|
||||
sellAmount,
|
||||
)
|
||||
.sampleTwoHopSell([uniswapV2FirstHop], [uniswapV2SecondHop], sellAmount)
|
||||
.callAsync();
|
||||
expect(firstHop.sourceIndex, 'First hop source index').to.bignumber.equal(
|
||||
firstHopQuotes.findIndex(quote => quote.isEqualTo(expectedIntermediateAssetAmount)),
|
||||
@@ -1145,36 +958,16 @@ blockchainTests('erc20-bridge-sampler', env => {
|
||||
.sampleBuysFromUniswapV2(UNISWAP_V2_ROUTER, uniswapV2SecondHopPath, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
|
||||
const eth2DaiFirstHop = testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, TAKER_TOKEN, INTERMEDIATE_TOKEN, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
const eth2DaiSecondHop = testContract
|
||||
.sampleBuysFromEth2Dai(ETH2DAI_ADDRESS, INTERMEDIATE_TOKEN, MAKER_TOKEN, [constants.ZERO_AMOUNT])
|
||||
.getABIEncodedTransactionData();
|
||||
|
||||
const secondHopQuotes = [
|
||||
getDeterministicBuyQuote(ETH2DAI_SALT, INTERMEDIATE_TOKEN, MAKER_TOKEN, buyAmount),
|
||||
getDeterministicUniswapV2BuyQuote(uniswapV2SecondHopPath, buyAmount),
|
||||
];
|
||||
const secondHopQuotes = [getDeterministicUniswapV2BuyQuote(uniswapV2SecondHopPath, buyAmount)];
|
||||
const expectedIntermediateAssetAmount = BigNumber.min(...secondHopQuotes);
|
||||
|
||||
const firstHopQuotes = [
|
||||
getDeterministicBuyQuote(
|
||||
ETH2DAI_SALT,
|
||||
TAKER_TOKEN,
|
||||
INTERMEDIATE_TOKEN,
|
||||
expectedIntermediateAssetAmount,
|
||||
),
|
||||
getDeterministicUniswapV2BuyQuote(uniswapV2FirstHopPath, expectedIntermediateAssetAmount),
|
||||
];
|
||||
const expectedSellAmount = BigNumber.min(...firstHopQuotes);
|
||||
|
||||
const [firstHop, secondHop, sellAmount] = await testContract
|
||||
.sampleTwoHopBuy(
|
||||
[eth2DaiFirstHop, uniswapV2FirstHop],
|
||||
[eth2DaiSecondHop, uniswapV2SecondHop],
|
||||
buyAmount,
|
||||
)
|
||||
.sampleTwoHopBuy([uniswapV2FirstHop], [uniswapV2SecondHop], buyAmount)
|
||||
.callAsync();
|
||||
expect(firstHop.sourceIndex, 'First hop source index').to.bignumber.equal(
|
||||
firstHopQuotes.findIndex(quote => quote.isEqualTo(expectedSellAmount)),
|
||||
|
||||
@@ -264,39 +264,6 @@ describe('DexSampler tests', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('getEth2DaiSellQuotes()', 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({
|
||||
sampleSellsFromEth2Dai: (_router, takerToken, makerToken, fillAmounts) => {
|
||||
expect(takerToken).to.eq(expectedTakerToken);
|
||||
expect(makerToken).to.eq(expectedMakerToken);
|
||||
expect(fillAmounts).to.deep.eq(expectedTakerFillAmounts);
|
||||
return expectedMakerFillAmounts;
|
||||
},
|
||||
});
|
||||
const dexOrderSampler = new DexOrderSampler(
|
||||
chainId,
|
||||
sampler,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
async () => undefined,
|
||||
);
|
||||
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
||||
dexOrderSampler.getEth2DaiSellQuotes(
|
||||
randomAddress(),
|
||||
expectedMakerToken,
|
||||
expectedTakerToken,
|
||||
expectedTakerFillAmounts,
|
||||
),
|
||||
);
|
||||
expect(fillableAmounts).to.deep.eq(expectedMakerFillAmounts);
|
||||
});
|
||||
|
||||
it('getUniswapSellQuotes()', async () => {
|
||||
const expectedTakerToken = randomAddress();
|
||||
const expectedMakerToken = randomAddress();
|
||||
@@ -361,39 +328,6 @@ describe('DexSampler tests', () => {
|
||||
expect(fillableAmounts).to.deep.eq(expectedMakerFillAmounts);
|
||||
});
|
||||
|
||||
it('getEth2DaiBuyQuotes()', 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({
|
||||
sampleBuysFromEth2Dai: (_router, takerToken, makerToken, fillAmounts) => {
|
||||
expect(takerToken).to.eq(expectedTakerToken);
|
||||
expect(makerToken).to.eq(expectedMakerToken);
|
||||
expect(fillAmounts).to.deep.eq(expectedMakerFillAmounts);
|
||||
return expectedTakerFillAmounts;
|
||||
},
|
||||
});
|
||||
const dexOrderSampler = new DexOrderSampler(
|
||||
chainId,
|
||||
sampler,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
async () => undefined,
|
||||
);
|
||||
const [fillableAmounts] = await dexOrderSampler.executeAsync(
|
||||
dexOrderSampler.getEth2DaiBuyQuotes(
|
||||
randomAddress(),
|
||||
expectedMakerToken,
|
||||
expectedTakerToken,
|
||||
expectedMakerFillAmounts,
|
||||
),
|
||||
);
|
||||
expect(fillableAmounts).to.deep.eq(expectedTakerFillAmounts);
|
||||
});
|
||||
|
||||
it('getUniswapBuyQuotes()', async () => {
|
||||
const expectedTakerToken = randomAddress();
|
||||
const expectedMakerToken = randomAddress();
|
||||
@@ -434,17 +368,15 @@ describe('DexSampler tests', () => {
|
||||
it('getSellQuotes()', async () => {
|
||||
const expectedTakerToken = randomAddress();
|
||||
const expectedMakerToken = randomAddress();
|
||||
const sources = [ERC20BridgeSource.Eth2Dai, ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
||||
const sources = [ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
||||
const ratesBySource: RatesBySource = {
|
||||
[ERC20BridgeSource.Kyber]: getRandomFloat(0, 100),
|
||||
[ERC20BridgeSource.Eth2Dai]: getRandomFloat(0, 100),
|
||||
[ERC20BridgeSource.Uniswap]: getRandomFloat(0, 100),
|
||||
[ERC20BridgeSource.UniswapV2]: getRandomFloat(0, 100),
|
||||
};
|
||||
const expectedTakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 3);
|
||||
let uniswapRouter: string;
|
||||
let uniswapV2Router: string;
|
||||
let eth2DaiRouter: string;
|
||||
const sampler = new MockSamplerContract({
|
||||
sampleSellsFromUniswap: (router, takerToken, makerToken, fillAmounts) => {
|
||||
uniswapRouter = router;
|
||||
@@ -453,13 +385,6 @@ describe('DexSampler tests', () => {
|
||||
expect(fillAmounts).to.deep.eq(expectedTakerFillAmounts);
|
||||
return fillAmounts.map(a => a.times(ratesBySource[ERC20BridgeSource.Uniswap]).integerValue());
|
||||
},
|
||||
sampleSellsFromEth2Dai: (router, takerToken, makerToken, fillAmounts) => {
|
||||
eth2DaiRouter = router;
|
||||
expect(takerToken).to.eq(expectedTakerToken);
|
||||
expect(makerToken).to.eq(expectedMakerToken);
|
||||
expect(fillAmounts).to.deep.eq(expectedTakerFillAmounts);
|
||||
return fillAmounts.map(a => a.times(ratesBySource[ERC20BridgeSource.Eth2Dai]).integerValue());
|
||||
},
|
||||
sampleSellsFromUniswapV2: (router, path, fillAmounts) => {
|
||||
uniswapV2Router = router;
|
||||
if (path.length === 2) {
|
||||
@@ -502,9 +427,6 @@ describe('DexSampler tests', () => {
|
||||
tokenAddressPath: [expectedTakerToken, expectedMakerToken],
|
||||
};
|
||||
}
|
||||
if (s === ERC20BridgeSource.Eth2Dai) {
|
||||
return { router: eth2DaiRouter };
|
||||
}
|
||||
// TODO jacob pass through
|
||||
if (s === ERC20BridgeSource.Uniswap) {
|
||||
return { router: uniswapRouter };
|
||||
@@ -532,16 +454,14 @@ describe('DexSampler tests', () => {
|
||||
it('getBuyQuotes()', async () => {
|
||||
const expectedTakerToken = randomAddress();
|
||||
const expectedMakerToken = randomAddress();
|
||||
const sources = [ERC20BridgeSource.Eth2Dai, ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
||||
const sources = [ERC20BridgeSource.Uniswap, ERC20BridgeSource.UniswapV2];
|
||||
const ratesBySource: RatesBySource = {
|
||||
[ERC20BridgeSource.Eth2Dai]: getRandomFloat(0, 100),
|
||||
[ERC20BridgeSource.Uniswap]: getRandomFloat(0, 100),
|
||||
[ERC20BridgeSource.UniswapV2]: getRandomFloat(0, 100),
|
||||
};
|
||||
const expectedMakerFillAmounts = getSampleAmounts(new BigNumber(100e18), 3);
|
||||
let uniswapRouter: string;
|
||||
let uniswapV2Router: string;
|
||||
let eth2DaiRouter: string;
|
||||
const sampler = new MockSamplerContract({
|
||||
sampleBuysFromUniswap: (router, takerToken, makerToken, fillAmounts) => {
|
||||
uniswapRouter = router;
|
||||
@@ -550,13 +470,6 @@ describe('DexSampler tests', () => {
|
||||
expect(fillAmounts).to.deep.eq(expectedMakerFillAmounts);
|
||||
return fillAmounts.map(a => a.times(ratesBySource[ERC20BridgeSource.Uniswap]).integerValue());
|
||||
},
|
||||
sampleBuysFromEth2Dai: (router, takerToken, makerToken, fillAmounts) => {
|
||||
eth2DaiRouter = router;
|
||||
expect(takerToken).to.eq(expectedTakerToken);
|
||||
expect(makerToken).to.eq(expectedMakerToken);
|
||||
expect(fillAmounts).to.deep.eq(expectedMakerFillAmounts);
|
||||
return fillAmounts.map(a => a.times(ratesBySource[ERC20BridgeSource.Eth2Dai]).integerValue());
|
||||
},
|
||||
sampleBuysFromUniswapV2: (router, path, fillAmounts) => {
|
||||
uniswapV2Router = router;
|
||||
if (path.length === 2) {
|
||||
@@ -594,9 +507,6 @@ describe('DexSampler tests', () => {
|
||||
tokenAddressPath: [expectedTakerToken, expectedMakerToken],
|
||||
};
|
||||
}
|
||||
if (s === ERC20BridgeSource.Eth2Dai) {
|
||||
return { router: eth2DaiRouter };
|
||||
}
|
||||
if (s === ERC20BridgeSource.Uniswap) {
|
||||
return { router: uniswapRouter };
|
||||
}
|
||||
|
||||
@@ -53,26 +53,6 @@ describe('Path', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('Removes partial Native orders', () => {
|
||||
const targetInput = new BigNumber(100);
|
||||
const path = Path.create(
|
||||
MarketOperation.Sell,
|
||||
[
|
||||
createFill(ERC20BridgeSource.Uniswap),
|
||||
createFill(ERC20BridgeSource.LiquidityProvider),
|
||||
createFill(ERC20BridgeSource.Native),
|
||||
],
|
||||
targetInput,
|
||||
);
|
||||
const fallback = Path.create(MarketOperation.Sell, [createFill(ERC20BridgeSource.Kyber)], targetInput);
|
||||
path.addFallback(fallback);
|
||||
const sources = path.fills.map(f => f.source);
|
||||
expect(sources).to.deep.eq([
|
||||
ERC20BridgeSource.Uniswap,
|
||||
ERC20BridgeSource.LiquidityProvider,
|
||||
ERC20BridgeSource.Kyber,
|
||||
]);
|
||||
});
|
||||
it('Handles duplicates', () => {
|
||||
const targetInput = new BigNumber(100);
|
||||
const path = Path.create(
|
||||
@@ -85,7 +65,7 @@ describe('Path', () => {
|
||||
const sources = path.fills.map(f => f.source);
|
||||
expect(sources).to.deep.eq([ERC20BridgeSource.Uniswap, ERC20BridgeSource.LiquidityProvider]);
|
||||
});
|
||||
it('Removes partial Native orders and replaces with unused fills', () => {
|
||||
it('Moves Native orders to the front and appends with unused fills', () => {
|
||||
const targetInput = new BigNumber(100);
|
||||
const path = Path.create(
|
||||
MarketOperation.Sell,
|
||||
@@ -105,6 +85,6 @@ describe('Path', () => {
|
||||
);
|
||||
path.addFallback(fallback);
|
||||
const sources = path.fills.map(f => f.source);
|
||||
expect(sources).to.deep.eq([ERC20BridgeSource.Uniswap, ERC20BridgeSource.Uniswap]);
|
||||
expect(sources).to.deep.eq([ERC20BridgeSource.Native, ERC20BridgeSource.Uniswap, ERC20BridgeSource.Uniswap]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,10 +72,8 @@ interface Handlers {
|
||||
getLimitOrderFillableTakerAssetAmounts: GetOrderFillableAssetAmountHandler;
|
||||
sampleSellsFromKyberNetwork: SampleSellsKyberHandler;
|
||||
sampleSellsFromLiquidityProvider: SampleSellsLPHandler;
|
||||
sampleSellsFromEth2Dai: SampleSellsEth2DaiHandler;
|
||||
sampleSellsFromUniswap: SampleSellsUniswapHandler;
|
||||
sampleSellsFromUniswapV2: SampleUniswapV2Handler;
|
||||
sampleBuysFromEth2Dai: SampleBuysEth2DaiHandler;
|
||||
sampleBuysFromUniswap: SampleBuysUniswapHandler;
|
||||
sampleBuysFromUniswapV2: SampleUniswapV2Handler;
|
||||
sampleBuysFromLiquidityProvider: SampleSellsLPHandler;
|
||||
@@ -141,22 +139,6 @@ export class MockSamplerContract extends ERC20BridgeSamplerContract {
|
||||
);
|
||||
}
|
||||
|
||||
public sampleSellsFromEth2Dai(
|
||||
router: string,
|
||||
takerToken: string,
|
||||
makerToken: string,
|
||||
takerAssetAmounts: BigNumber[],
|
||||
): ContractTxFunctionObj<BigNumber[]> {
|
||||
return this._wrapCall(
|
||||
super.sampleSellsFromEth2Dai,
|
||||
this._handlers.sampleSellsFromEth2Dai,
|
||||
router,
|
||||
takerToken,
|
||||
makerToken,
|
||||
takerAssetAmounts,
|
||||
);
|
||||
}
|
||||
|
||||
public sampleSellsFromUniswap(
|
||||
router: string,
|
||||
takerToken: string,
|
||||
@@ -203,22 +185,6 @@ export class MockSamplerContract extends ERC20BridgeSamplerContract {
|
||||
);
|
||||
}
|
||||
|
||||
public sampleBuysFromEth2Dai(
|
||||
router: string,
|
||||
takerToken: string,
|
||||
makerToken: string,
|
||||
makerAssetAmounts: BigNumber[],
|
||||
): ContractTxFunctionObj<BigNumber[]> {
|
||||
return this._wrapCall(
|
||||
super.sampleBuysFromEth2Dai,
|
||||
this._handlers.sampleBuysFromEth2Dai,
|
||||
router,
|
||||
takerToken,
|
||||
makerToken,
|
||||
makerAssetAmounts,
|
||||
);
|
||||
}
|
||||
|
||||
public sampleBuysFromUniswap(
|
||||
router: string,
|
||||
takerToken: string,
|
||||
|
||||
@@ -13,12 +13,10 @@ export * from '../test/generated-wrappers/d_o_d_o_sampler';
|
||||
export * from '../test/generated-wrappers/d_o_d_o_v2_sampler';
|
||||
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';
|
||||
export * from '../test/generated-wrappers/i_eth2_dai';
|
||||
export * from '../test/generated-wrappers/i_kyber_network';
|
||||
export * from '../test/generated-wrappers/i_m_stable';
|
||||
export * from '../test/generated-wrappers/i_mooniswap';
|
||||
|
||||
Reference in New Issue
Block a user