Compare commits

...

9 Commits

Author SHA1 Message Date
Noah Khamliche
9b9c47ef56 Merge branch 'development' into feat/RedactedCurvePool 2022-02-28 15:37:33 -05:00
Github Actions
389ebb5df8 Publish
- @0x/asset-swapper@16.49.9
2022-02-24 09:52:41 +00:00
Github Actions
fd9655e9d4 Updated CHANGELOGS & MD docs 2022-02-24 09:52:38 +00:00
Kim Persson
6480aaa189 fix: native order scaling & don't try to route 1 wei trades (it will fail) (#430)
* feat: scale oversized native orders to quote amount for fake samples

* chore: temporarily use private publish neon-router version

* fix: short circuit 1 base unit trades to avoid router error

* chore: use published version of `neon-router`

* chore: add changelog entry for asset-swapper
2022-02-24 10:34:17 +01:00
Noah Khamliche
dfcde47ab3 added WETH/BTRFLY pool on curve mainnet 2022-02-23 20:35:18 -05:00
Noah Khamliche
424066c1a2 remove comments 2022-02-17 10:26:51 -05:00
Noah Khamliche
d8a489843e removed ohmv2/dai and ohmv2/weth, routing is the same without the search overhead 2022-02-17 10:21:17 -05:00
Noah Khamliche
914449025c updated changelog 2022-02-17 10:07:37 -05:00
Noah Khamliche
49f129aa30 fixed btrfly routing to include the ohmV2/dai, ohmV2/btfly, and ohmV2/weth pools 2022-02-17 10:05:28 -05:00
6 changed files with 64 additions and 12 deletions

View File

@@ -1,4 +1,14 @@
[
{
"version": "16.49.9",
"changes": [
{
"note": "Fix native order scaling & filter out 1 wei quotes",
"pr": "430"
}
],
"timestamp": 1645696356
},
{
"timestamp": 1645569128,
"version": "16.49.8",
@@ -25,6 +35,7 @@
"note": "Fixed btrfly routing to include the ohmV2/dai, ohmV2/btfly, and ohmV2/weth pools",
"pr": 427
}
],
"timestamp": 1645113751
},

View File

@@ -5,6 +5,10 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
## v16.49.9 - _February 24, 2022_
* Fix native order scaling & filter out 1 wei quotes (#430)
## v16.49.8 - _February 22, 2022_
* Dependencies updated

View File

@@ -1,6 +1,6 @@
{
"name": "@0x/asset-swapper",
"version": "16.49.8",
"version": "16.49.9",
"engines": {
"node": ">=6.12"
},
@@ -66,7 +66,7 @@
"@0x/contracts-zero-ex": "^0.31.0",
"@0x/dev-utils": "^4.2.11",
"@0x/json-schemas": "^6.4.1",
"@0x/neon-router": "^0.3.2",
"@0x/neon-router": "^0.3.3",
"@0x/protocol-utils": "^1.11.0",
"@0x/quote-server": "^6.0.6",
"@0x/types": "^3.3.4",

View File

@@ -631,6 +631,7 @@ export const CURVE_POOLS = {
USDP: '0x42d7025938bec20b69cbae5a77421082407f053a', // usdp
ib: '0x2dded6da1bf5dbdf597c45fcfaa3194e53ecfeaf', // iron bank
link: '0xf178c0b5bb7e7abf4e12a4838c7b7c5ba2c623c0', // link
btrflyweth: '0xf43b15ab692fde1f9c24a9fce700adcc809d5391',
// StableSwap "open pools" (crv.finance)
TUSD: '0xecd5e75afb02efa118af914515d6521aabd189f1',
STABLEx: '0x3252efd4ea2d6c78091a1f43982ee2c3659cc3d1',
@@ -1004,12 +1005,27 @@ const createCurveV2MetaTriPool = (info: { tokens: string[]; pool: string; gasSch
gasSchedule: info.gasSchedule,
});
const createCurveFactoryCryptoExchangePool = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying_uint256,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_uint256,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
tokens: info.tokens,
metaTokens: undefined,
poolAddress: info.pool,
gasSchedule: info.gasSchedule,
});
/**
* Mainnet Curve configuration
* The tokens are in order of their index, which each curve defines
* I.e DaiUsdc curve has DAI as index 0 and USDC as index 1
*/
export const CURVE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
[CURVE_POOLS.btrflyweth]: createCurveFactoryCryptoExchangePool({
tokens: [MAINNET_TOKENS.WETH, MAINNET_TOKENS.BTRFLY],
pool: CURVE_POOLS.btrflyweth,
gasSchedule: 411e3,
}),
[CURVE_POOLS.compound]: createCurveExchangeUnderlyingPool({
tokens: [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC],
pool: CURVE_POOLS.compound,

View File

@@ -21,6 +21,8 @@ const MIN_NUM_SAMPLE_INPUTS = 3;
const isDexSample = (obj: DexSample | NativeOrderWithFillableAmounts): obj is DexSample => !!(obj as DexSample).source;
const ONE_BASE_UNIT = new BigNumber(1);
function nativeOrderToNormalizedAmounts(
side: MarketOperation,
nativeOrder: NativeOrderWithFillableAmounts,
@@ -75,6 +77,13 @@ function findRoutesAndCreateOptimalPath(
fees: FeeSchedule,
neonRouterNumSamples: number,
): Path | undefined {
// Currently the rust router is unable to handle 1 base unit sized quotes and will error out
// To avoid flooding the logs with these errors we just return an insufficient liquidity error
// which is how the JS router handles these quotes today
if (input.eq(ONE_BASE_UNIT)) {
return undefined;
}
const createFill = (sample: DexSample): Fill | undefined => {
const fills = dexSamplesToFills(side, [sample], opts.outputAmountPerEth, opts.inputAmountPerEth, fees);
// NOTE: If the sample has 0 output dexSamplesToFills will return [] because no fill can be created
@@ -155,12 +164,24 @@ function findRoutesAndCreateOptimalPath(
const inputs = [];
const outputs = [];
const outputFees = [];
// NOTE: We start at 0 here because the native order might be much larger than the amount
// By starting at 0 we make sure we can always use a portion of the native order to fill/partial fill
for (let i = 0; i <= 12; i++) {
const fraction = i / 12;
const currentInput = BigNumber.min(normalizedOrderInput.times(fraction), normalizedOrderInput);
const currentOutput = BigNumber.min(normalizedOrderOutput.times(fraction), normalizedOrderOutput);
// NOTE: Limit orders can be both larger or smaller than the input amount
// If the order is larger than the input we can scale the order to the size of
// the quote input (order pricing is constant) and then create 13 "samples" up to
// and including the full quote input amount.
// If the order is smaller we don't need to scale anything, we will just end up
// with trailing duplicate samples for the order input as we cannot go higher
const scaleToInput = BigNumber.min(input.dividedBy(normalizedOrderInput), 1);
for (let i = 1; i <= 13; i++) {
const fraction = i / 13;
const currentInput = BigNumber.min(
normalizedOrderInput.times(scaleToInput).times(fraction),
normalizedOrderInput,
);
const currentOutput = BigNumber.min(
normalizedOrderOutput.times(scaleToInput).times(fraction),
normalizedOrderOutput,
);
const id = `${ERC20BridgeSource.Native}-${serializedPaths.length}-${idx}-${i}`;
inputs.push(currentInput.integerValue().toNumber());
outputs.push(currentOutput.integerValue().toNumber());

View File

@@ -959,10 +959,10 @@
typedoc "~0.16.11"
yargs "^10.0.3"
"@0x/neon-router@^0.3.2":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@0x/neon-router/-/neon-router-0.3.2.tgz#dc68d0a108060d607b48e3d32ce0ff46f8dc0cc2"
integrity sha512-AdSPeCxRcjdpmWDkJI1wg+X4q14tmLE21vM0AixtMQQI5+f22sIeUCrPqU9FFKqMQTOW0/3d8tVXzxdollahbA==
"@0x/neon-router@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@0x/neon-router/-/neon-router-0.3.3.tgz#dab540f4cd2aea6441ba29cbc35c28ca3f7a2b4f"
integrity sha512-xRIpRJ+gStLfDQI9mVdeugoLHQAp/bZfX7dycEQdStZlF6kcZk5kRe/iXCFoxoEY42fMaQW0/7JMFiB1C18t6Q==
dependencies:
"@mapbox/node-pre-gyp" "^1.0.5"