This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
asset-swapper: RFQ-T indicative quotes #2555
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
957e3eb
asset-swapper: Restructure RFQ-T request options
feuGeneA 80c8712
asset-swapper: Rm unused field in SwapQuoterOpts
feuGeneA 33fdfdc
asset-swapper: Extract method inferQueryParams
feuGeneA d6d4d29
asset-swapper: RFQ-T indicative quotes
feuGeneA 45bc967
asset-swapper: Differentiate RFQT warning messages
feuGeneA 2456adc
asset-swapper: validate RFQT indicative quotes
feuGeneA 464c918
asset-swapper: test RFQT indicative quote handling
feuGeneA 4cc9cea
asset-swapper: Rm unused ERC20BridgeSource.Rfqt
feuGeneA 5effc6e
asset-swapper: extract method
feuGeneA ad7868e
asset-s: clean up order faking for indicative RFQT
feuGeneA 8875f92
asset-s: test requestRfqtIndicativeQuotesAsync
feuGeneA 245b6da
asset-s: Require RfqtRequestOpts.intentOnFilling
feuGeneA ba2ac6a
asset-s: Clarify indicative quote enablement
feuGeneA 83289bc
asset-s: consider falsey takerAddress as absent
feuGeneA 2c97208
asset-s: simplify type with `?`, not `|undefined`
feuGeneA 03ed3ac
Merge branch 'development' into rfq-t-indicative
feuGeneA e8ff5da
asset-swapper: update CHANGELOG
feuGeneA 11622c5
asset-s: Add RfqtRequestOpts.isIndicative
feuGeneA 153533f
Fix bug in prior revision: wrong asset data
feuGeneA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ import { SignedOrder } from '@0x/types'; | |
import { BigNumber } from '@0x/utils'; | ||
|
||
import { GetMarketOrdersOpts } from './utils/market_operation_utils/types'; | ||
import { QuoteRequestor } from './utils/quote_requestor'; | ||
|
||
/** | ||
* expiryBufferMs: The number of seconds to add when calculating whether an order is expired or not. Defaults to 300s (5m). | ||
|
@@ -188,16 +187,20 @@ export interface SwapQuoteOrdersBreakdown { | |
[source: string]: BigNumber; | ||
} | ||
|
||
export interface RfqtRequestOpts { | ||
takerAddress: string; | ||
apiKey: string; | ||
intentOnFilling: boolean; | ||
isIndicative?: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit but would prefer for this to be required |
||
makerEndpointMaxResponseTimeMs?: number; | ||
} | ||
|
||
/** | ||
* gasPrice: gas price to determine protocolFee amount, default to ethGasStation fast amount | ||
*/ | ||
export interface SwapQuoteRequestOpts extends CalculateSwapQuoteOpts { | ||
gasPrice?: BigNumber; | ||
apiKey?: string; | ||
rfqt?: { | ||
takerAddress: string; | ||
intentOnFilling: boolean; | ||
}; | ||
rfqt?: RfqtRequestOpts; | ||
} | ||
|
||
/** | ||
|
@@ -223,7 +226,6 @@ export interface SwapQuoterOpts extends OrderPrunerOpts { | |
takerApiKeyWhitelist: string[]; | ||
makerEndpoints: string[]; | ||
}; | ||
quoteRequestor?: QuoteRequestor; | ||
} | ||
|
||
/** | ||
|
@@ -274,14 +276,23 @@ export enum OrderPrunerPermittedFeeTypes { | |
TakerDenominatedTakerFee = 'TAKER_DENOMINATED_TAKER_FEE', | ||
} | ||
|
||
export interface RfqtFirmQuoteRequestOpts { | ||
makerEndpointMaxResponseTimeMs?: number; | ||
/** | ||
* Represents a mocked RFQT maker responses. | ||
*/ | ||
export interface MockedRfqtFirmQuoteResponse { | ||
endpoint: string; | ||
requestApiKey: string; | ||
requestParams: { | ||
[key: string]: string | undefined; | ||
}; | ||
responseData: any; | ||
responseCode: number; | ||
} | ||
|
||
/** | ||
* Represents a mocked RFQT maker responses. | ||
*/ | ||
export interface MockedRfqtFirmQuoteResponse { | ||
export interface MockedRfqtIndicativeQuoteResponse { | ||
endpoint: string; | ||
requestApiKey: string; | ||
requestParams: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { SignedOrder } from '@0x/types'; | |
import { BigNumber, NULL_ADDRESS } from '@0x/utils'; | ||
|
||
import { MarketOperation } from '../../types'; | ||
import { RfqtIndicativeQuoteResponse } from '../quote_requestor'; | ||
import { difference } from '../utils'; | ||
|
||
import { BUY_SOURCES, DEFAULT_GET_MARKET_ORDERS_OPTS, FEE_QUOTE_SOURCES, ONE_ETHER, SELL_SOURCES } from './constants'; | ||
|
@@ -13,7 +14,12 @@ import { | |
getPathAdjustedSlippage, | ||
getPathSize, | ||
} from './fills'; | ||
import { createOrdersFromPath, createSignedOrdersWithFillableAmounts, getNativeOrderTokens } from './orders'; | ||
import { | ||
createOrdersFromPath, | ||
createSignedOrdersFromRfqtIndicativeQuotes, | ||
createSignedOrdersWithFillableAmounts, | ||
getNativeOrderTokens, | ||
} from './orders'; | ||
import { findOptimalPath } from './path_optimizer'; | ||
import { DexOrderSampler, getSampleAmounts } from './sampler'; | ||
import { | ||
|
@@ -26,6 +32,26 @@ import { | |
OrderDomain, | ||
} from './types'; | ||
|
||
async function getRfqtIndicativeQuotesAsync( | ||
makerAssetData: string, | ||
takerAssetData: string, | ||
marketOperation: MarketOperation, | ||
assetFillAmount: BigNumber, | ||
opts: Partial<GetMarketOrdersOpts>, | ||
): Promise<RfqtIndicativeQuoteResponse[]> { | ||
if (opts.rfqt && opts.rfqt.isIndicative === true && opts.rfqt.quoteRequestor) { | ||
return opts.rfqt.quoteRequestor.requestRfqtIndicativeQuotesAsync( | ||
makerAssetData, | ||
takerAssetData, | ||
assetFillAmount, | ||
marketOperation, | ||
opts.rfqt, | ||
); | ||
} else { | ||
return Promise.resolve<RfqtIndicativeQuoteResponse[]>([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we just Note: this is a nit, don't need to change |
||
} | ||
} | ||
|
||
export class MarketOperationUtils { | ||
private readonly _wethAddress: string; | ||
|
||
|
@@ -57,12 +83,7 @@ export class MarketOperationUtils { | |
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts }; | ||
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]); | ||
// Call the sampler contract. | ||
const [ | ||
orderFillableAmounts, | ||
liquidityProviderAddress, | ||
ethToMakerAssetRate, | ||
dexQuotes, | ||
] = await this._sampler.executeAsync( | ||
const samplerPromise = this._sampler.executeAsync( | ||
// Get native order fillable amounts. | ||
DexOrderSampler.ops.getOrderFillableTakerAmounts(nativeOrders), | ||
// Get the custom liquidity provider from registry. | ||
|
@@ -92,10 +113,22 @@ export class MarketOperationUtils { | |
this._liquidityProviderRegistry, | ||
), | ||
); | ||
const rfqtPromise = getRfqtIndicativeQuotesAsync( | ||
nativeOrders[0].makerAssetData, | ||
nativeOrders[0].takerAssetData, | ||
MarketOperation.Sell, | ||
takerAmount, | ||
_opts, | ||
); | ||
const [ | ||
[orderFillableAmounts, liquidityProviderAddress, ethToMakerAssetRate, dexQuotes], | ||
rfqtIndicativeQuotes, | ||
] = await Promise.all([samplerPromise, rfqtPromise]); | ||
return this._generateOptimizedOrders({ | ||
orderFillableAmounts, | ||
nativeOrders, | ||
dexQuotes, | ||
rfqtIndicativeQuotes, | ||
liquidityProviderAddress, | ||
inputToken: takerToken, | ||
outputToken: makerToken, | ||
|
@@ -130,12 +163,7 @@ export class MarketOperationUtils { | |
const _opts = { ...DEFAULT_GET_MARKET_ORDERS_OPTS, ...opts }; | ||
const [makerToken, takerToken] = getNativeOrderTokens(nativeOrders[0]); | ||
// Call the sampler contract. | ||
const [ | ||
orderFillableAmounts, | ||
liquidityProviderAddress, | ||
ethToTakerAssetRate, | ||
dexQuotes, | ||
] = await this._sampler.executeAsync( | ||
const samplerPromise = this._sampler.executeAsync( | ||
// Get native order fillable amounts. | ||
DexOrderSampler.ops.getOrderFillableMakerAmounts(nativeOrders), | ||
// Get the custom liquidity provider from registry. | ||
|
@@ -165,11 +193,23 @@ export class MarketOperationUtils { | |
this._liquidityProviderRegistry, | ||
), | ||
); | ||
const rfqtPromise = getRfqtIndicativeQuotesAsync( | ||
nativeOrders[0].makerAssetData, | ||
nativeOrders[0].takerAssetData, | ||
MarketOperation.Buy, | ||
makerAmount, | ||
_opts, | ||
); | ||
const [ | ||
[orderFillableAmounts, liquidityProviderAddress, ethToTakerAssetRate, dexQuotes], | ||
rfqtIndicativeQuotes, | ||
] = await Promise.all([samplerPromise, rfqtPromise]); | ||
|
||
return this._generateOptimizedOrders({ | ||
orderFillableAmounts, | ||
nativeOrders, | ||
dexQuotes, | ||
rfqtIndicativeQuotes, | ||
liquidityProviderAddress, | ||
inputToken: makerToken, | ||
outputToken: takerToken, | ||
|
@@ -246,6 +286,7 @@ export class MarketOperationUtils { | |
orderFillableAmounts, | ||
nativeOrders, | ||
dexQuotes, | ||
rfqtIndicativeQuotes: [], | ||
inputToken: makerToken, | ||
outputToken: takerToken, | ||
side: MarketOperation.Buy, | ||
|
@@ -274,6 +315,7 @@ export class MarketOperationUtils { | |
nativeOrders: SignedOrder[]; | ||
orderFillableAmounts: BigNumber[]; | ||
dexQuotes: DexSample[][]; | ||
rfqtIndicativeQuotes: RfqtIndicativeQuoteResponse[]; | ||
runLimit?: number; | ||
ethToOutputRate?: BigNumber; | ||
bridgeSlippage?: number; | ||
|
@@ -290,7 +332,10 @@ export class MarketOperationUtils { | |
const paths = createFillPaths({ | ||
side, | ||
// Augment native orders with their fillable amounts. | ||
orders: createSignedOrdersWithFillableAmounts(side, opts.nativeOrders, opts.orderFillableAmounts), | ||
orders: [ | ||
...createSignedOrdersWithFillableAmounts(side, opts.nativeOrders, opts.orderFillableAmounts), | ||
...createSignedOrdersFromRfqtIndicativeQuotes(opts.rfqtIndicativeQuotes), | ||
feuGeneA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
dexQuotes: opts.dexQuotes, | ||
targetInput: inputAmount, | ||
ethToOutputRate: opts.ethToOutputRate, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont need this undefined check