Update sampler artifacts/wrappers

This commit is contained in:
Michael Zhu 2020-06-11 11:51:51 -07:00
parent 44262bf747
commit cd14a45414
8 changed files with 240 additions and 17 deletions

View File

@ -77,10 +77,6 @@ export class MarketOperationUtils {
} }
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts }; const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]);
const optionalSources = (this._liquidityProviderRegistry !== NULL_ADDRESS
? [ERC20BridgeSource.LiquidityProvider]
: []
).concat(this._multiBridge !== NULL_ADDRESS ? [ERC20BridgeSource.MultiBridge] : []);
// Call the sampler contract. // Call the sampler contract.
const samplerPromise = this._sampler.executeAsync( const samplerPromise = this._sampler.executeAsync(
@ -94,7 +90,7 @@ export class MarketOperationUtils {
), ),
// Get ETH -> maker token price. // Get ETH -> maker token price.
DexOrderSampler.ops.getMedianSellRate( DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES.concat(optionalSources), _opts.excludedSources), difference(FEE_QUOTE_SOURCES.concat(this._optionalSources()), _opts.excludedSources),
makerToken, makerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,
@ -104,7 +100,7 @@ export class MarketOperationUtils {
), ),
// Get sell quotes for taker -> maker. // Get sell quotes for taker -> maker.
DexOrderSampler.ops.getSellQuotes( DexOrderSampler.ops.getSellQuotes(
difference(SELL_SOURCES.concat(optionalSources), _opts.excludedSources), difference(SELL_SOURCES.concat(this._optionalSources()), _opts.excludedSources),
makerToken, makerToken,
takerToken, takerToken,
getSampleAmounts(takerAmount, _opts.numSamples, _opts.sampleDistributionBase), getSampleAmounts(takerAmount, _opts.numSamples, _opts.sampleDistributionBase),
@ -163,10 +159,6 @@ export class MarketOperationUtils {
} }
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts }; const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts };
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]); const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]);
const optionalSources = (this._liquidityProviderRegistry !== NULL_ADDRESS
? [ERC20BridgeSource.LiquidityProvider]
: []
).concat(this._multiBridge !== NULL_ADDRESS ? [ERC20BridgeSource.MultiBridge] : []);
// Call the sampler contract. // Call the sampler contract.
const samplerPromise = this._sampler.executeAsync( const samplerPromise = this._sampler.executeAsync(
// Get native order fillable amounts. // Get native order fillable amounts.
@ -179,7 +171,7 @@ export class MarketOperationUtils {
), ),
// Get ETH -> taker token price. // Get ETH -> taker token price.
DexOrderSampler.ops.getMedianSellRate( DexOrderSampler.ops.getMedianSellRate(
difference(FEE_QUOTE_SOURCES.concat(optionalSources), _opts.excludedSources), difference(FEE_QUOTE_SOURCES.concat(this._optionalSources()), _opts.excludedSources),
takerToken, takerToken,
this._wethAddress, this._wethAddress,
ONE_ETHER, ONE_ETHER,
@ -403,6 +395,12 @@ export class MarketOperationUtils {
shouldBatchBridgeOrders: !!opts.shouldBatchBridgeOrders, shouldBatchBridgeOrders: !!opts.shouldBatchBridgeOrders,
}); });
} }
private _optionalSources(): ERC20BridgeSource[] {
return (this._liquidityProviderRegistry !== NULL_ADDRESS ? [ERC20BridgeSource.LiquidityProvider] : []).concat(
this._multiBridge !== NULL_ADDRESS ? [ERC20BridgeSource.MultiBridge] : [],
);
}
} }
// tslint:disable: max-file-line-count // tslint:disable: max-file-line-count

View File

@ -524,3 +524,4 @@ export const samplerOperations = {
}; };
}, },
}; };
// tslint:disable max-file-line-count

View File

@ -25,6 +25,10 @@
{ {
"note": "Added `ERC20BridgeSampler.sampleSellsFromUniswapV2", "note": "Added `ERC20BridgeSampler.sampleSellsFromUniswapV2",
"pr": 2595 "pr": 2595
},
{
"note": "Added `ERC20BridgeSampler.sampleSellsFromMultiBridge",
"pr": 2593
} }
] ]
}, },

File diff suppressed because one or more lines are too long

View File

@ -244,6 +244,21 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"constant": true,
"inputs": [
{ "internalType": "address", "name": "multibridge", "type": "address" },
{ "internalType": "address", "name": "takerToken", "type": "address" },
{ "internalType": "address", "name": "intermediateToken", "type": "address" },
{ "internalType": "address", "name": "makerToken", "type": "address" },
{ "internalType": "uint256[]", "name": "takerTokenAmounts", "type": "uint256[]" }
],
"name": "sampleSellsFromMultiBridge",
"outputs": [{ "internalType": "uint256[]", "name": "makerTokenAmounts", "type": "uint256[]" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{ {
"constant": true, "constant": true,
"inputs": [ "inputs": [
@ -396,6 +411,17 @@
}, },
"return": "makerTokenAmounts Maker amounts bought at each taker token amount." "return": "makerTokenAmounts Maker amounts bought at each taker token amount."
}, },
"sampleSellsFromMultiBridge(address,address,address,address,uint256[])": {
"details": "Sample sell quotes from MultiBridge.",
"params": {
"intermediateToken": "The address of the intermediate token to use in an indirect route.",
"makerToken": "Address of the maker token (what to buy).",
"multibridge": "Address of the MultiBridge contract.",
"takerToken": "Address of the taker token (what to sell).",
"takerTokenAmounts": "Taker token sell amount for each sample."
},
"return": "makerTokenAmounts Maker amounts bought at each taker token amount."
},
"sampleSellsFromUniswap(address,address,uint256[])": { "sampleSellsFromUniswap(address,address,uint256[])": {
"details": "Sample sell quotes from Uniswap.", "details": "Sample sell quotes from Uniswap.",
"params": { "params": {

View File

@ -29,6 +29,10 @@
{ {
"note": "Added `ERC20BridgeSampler.sampleSellsFromUniswapV2", "note": "Added `ERC20BridgeSampler.sampleSellsFromUniswapV2",
"pr": 2595 "pr": 2595
},
{
"note": "Added `ERC20BridgeSampler.sampleSellsFromMultiBridge",
"pr": 2593
} }
] ]
}, },

View File

@ -731,6 +731,41 @@ export class ERC20BridgeSamplerContract extends BaseContract {
stateMutability: 'view', stateMutability: 'view',
type: 'function', type: 'function',
}, },
{
constant: true,
inputs: [
{
name: 'multibridge',
type: 'address',
},
{
name: 'takerToken',
type: 'address',
},
{
name: 'intermediateToken',
type: 'address',
},
{
name: 'makerToken',
type: 'address',
},
{
name: 'takerTokenAmounts',
type: 'uint256[]',
},
],
name: 'sampleSellsFromMultiBridge',
outputs: [
{
name: 'makerTokenAmounts',
type: 'uint256[]',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{ {
constant: true, constant: true,
inputs: [ inputs: [
@ -1230,7 +1265,7 @@ export class ERC20BridgeSamplerContract extends BaseContract {
} }
/** /**
* Sample buy quotes from UniswapV2. * Sample buy quotes from UniswapV2.
* @param path Token route. * @param path Token route. Should be takerToken -> makerToken.
* @param makerTokenAmounts Maker token buy amount for each sample. * @param makerTokenAmounts Maker token buy amount for each sample.
* @returns takerTokenAmounts Taker amounts sold at each maker token amount. * @returns takerTokenAmounts Taker amounts sold at each maker token amount.
*/ */
@ -1459,6 +1494,53 @@ export class ERC20BridgeSamplerContract extends BaseContract {
}, },
}; };
} }
/**
* Sample sell quotes from MultiBridge.
* @param multibridge Address of the MultiBridge contract.
* @param takerToken Address of the taker token (what to sell).
* @param intermediateToken The address of the intermediate token to use
* in an indirect route.
* @param makerToken Address of the maker token (what to buy).
* @param takerTokenAmounts Taker token sell amount for each sample.
* @returns makerTokenAmounts Maker amounts bought at each taker token amount.
*/
public sampleSellsFromMultiBridge(
multibridge: string,
takerToken: string,
intermediateToken: string,
makerToken: string,
takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[]> {
const self = (this as any) as ERC20BridgeSamplerContract;
assert.isString('multibridge', multibridge);
assert.isString('takerToken', takerToken);
assert.isString('intermediateToken', intermediateToken);
assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromMultiBridge(address,address,address,address,uint256[])';
return {
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
},
getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [
multibridge.toLowerCase(),
takerToken.toLowerCase(),
intermediateToken.toLowerCase(),
makerToken.toLowerCase(),
takerTokenAmounts,
]);
},
};
}
/** /**
* Sample sell quotes from Uniswap. * Sample sell quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).
@ -1499,7 +1581,7 @@ export class ERC20BridgeSamplerContract extends BaseContract {
} }
/** /**
* Sample sell quotes from UniswapV2. * Sample sell quotes from UniswapV2.
* @param path Token route. * @param path Token route. Should be takerToken -> makerToken
* @param takerTokenAmounts Taker token sell amount for each sample. * @param takerTokenAmounts Taker token sell amount for each sample.
* @returns makerTokenAmounts Maker amounts bought at each taker token amount. * @returns makerTokenAmounts Maker amounts bought at each taker token amount.
*/ */

View File

@ -679,6 +679,41 @@ export class IERC20BridgeSamplerContract extends BaseContract {
stateMutability: 'view', stateMutability: 'view',
type: 'function', type: 'function',
}, },
{
constant: true,
inputs: [
{
name: 'multibridge',
type: 'address',
},
{
name: 'takerToken',
type: 'address',
},
{
name: 'intermediateToken',
type: 'address',
},
{
name: 'makerToken',
type: 'address',
},
{
name: 'takerTokenAmounts',
type: 'uint256[]',
},
],
name: 'sampleSellsFromMultiBridge',
outputs: [
{
name: 'makerTokenAmounts',
type: 'uint256[]',
},
],
payable: false,
stateMutability: 'view',
type: 'function',
},
{ {
constant: true, constant: true,
inputs: [ inputs: [
@ -1362,6 +1397,53 @@ export class IERC20BridgeSamplerContract extends BaseContract {
}, },
}; };
} }
/**
* Sample sell quotes from MultiBridge.
* @param multibridge Address of the MultiBridge contract.
* @param takerToken Address of the taker token (what to sell).
* @param intermediateToken The address of the intermediate token to use
* in an indirect route.
* @param makerToken Address of the maker token (what to buy).
* @param takerTokenAmounts Taker token sell amount for each sample.
* @returns makerTokenAmounts Maker amounts bought at each taker token amount.
*/
public sampleSellsFromMultiBridge(
multibridge: string,
takerToken: string,
intermediateToken: string,
makerToken: string,
takerTokenAmounts: BigNumber[],
): ContractFunctionObj<BigNumber[]> {
const self = (this as any) as IERC20BridgeSamplerContract;
assert.isString('multibridge', multibridge);
assert.isString('takerToken', takerToken);
assert.isString('intermediateToken', intermediateToken);
assert.isString('makerToken', makerToken);
assert.isArray('takerTokenAmounts', takerTokenAmounts);
const functionSignature = 'sampleSellsFromMultiBridge(address,address,address,address,uint256[])';
return {
async callAsync(callData: Partial<CallData> = {}, defaultBlock?: BlockParam): Promise<BigNumber[]> {
BaseContract._assertCallParams(callData, defaultBlock);
const rawCallResult = await self._performCallAsync(
{ ...callData, data: this.getABIEncodedTransactionData() },
defaultBlock,
);
const abiEncoder = self._lookupAbiEncoder(functionSignature);
BaseContract._throwIfUnexpectedEmptyCallResult(rawCallResult, abiEncoder);
return abiEncoder.strictDecodeReturnValue<BigNumber[]>(rawCallResult);
},
getABIEncodedTransactionData(): string {
return self._strictEncodeArguments(functionSignature, [
multibridge.toLowerCase(),
takerToken.toLowerCase(),
intermediateToken.toLowerCase(),
makerToken.toLowerCase(),
takerTokenAmounts,
]);
},
};
}
/** /**
* Sample sell quotes from Uniswap. * Sample sell quotes from Uniswap.
* @param takerToken Address of the taker token (what to sell). * @param takerToken Address of the taker token (what to sell).