Offboard Cream (#546)
* offboard cream * changelog * remove BalancerFillData (unused)
This commit is contained in:
parent
08e0c2ebb9
commit
b35dccd43d
@ -1,4 +1,13 @@
|
||||
[
|
||||
{
|
||||
"version": "16.66.4",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Offboard Cream",
|
||||
"pr": 546
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1660093941,
|
||||
"version": "16.66.3",
|
||||
|
@ -84,7 +84,6 @@
|
||||
"axios": "^0.21.1",
|
||||
"axios-mock-adapter": "^1.19.0",
|
||||
"balancer-labs-sor-v1": "npm:@balancer-labs/sor@0.3.2",
|
||||
"cream-sor": "^0.3.3",
|
||||
"ethereum-types": "^3.7.0",
|
||||
"graphql": "^15.4.0",
|
||||
"graphql-request": "^3.4.0",
|
||||
|
@ -144,7 +144,7 @@ export class SwapQuoter {
|
||||
this.chainId,
|
||||
samplerContract,
|
||||
samplerOverrides,
|
||||
undefined, // pools caches for balancer and cream
|
||||
undefined, // pools caches for balancer
|
||||
tokenAdjacencyGraph,
|
||||
liquidityProviderRegistry,
|
||||
this.chainId === ChainId.Mainnet // Enable Bancor only on Mainnet
|
||||
|
@ -95,7 +95,6 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
||||
ERC20BridgeSource.MultiHop,
|
||||
ERC20BridgeSource.Dodo,
|
||||
ERC20BridgeSource.DodoV2,
|
||||
ERC20BridgeSource.Cream,
|
||||
ERC20BridgeSource.LiquidityProvider,
|
||||
ERC20BridgeSource.CryptoCom,
|
||||
ERC20BridgeSource.Lido,
|
||||
@ -247,7 +246,6 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
|
||||
ERC20BridgeSource.MultiHop,
|
||||
ERC20BridgeSource.Dodo,
|
||||
ERC20BridgeSource.DodoV2,
|
||||
ERC20BridgeSource.Cream,
|
||||
ERC20BridgeSource.Lido,
|
||||
ERC20BridgeSource.LiquidityProvider,
|
||||
ERC20BridgeSource.CryptoCom,
|
||||
@ -2520,7 +2518,6 @@ export const DEFAULT_GAS_SCHEDULE: Required<GasSchedule> = {
|
||||
[ERC20BridgeSource.BalancerV2]: (fillData?: FillData) => {
|
||||
return 100e3 + ((fillData as BalancerV2BatchSwapFillData).swapSteps.length - 1) * 50e3;
|
||||
},
|
||||
[ERC20BridgeSource.Cream]: () => 120e3,
|
||||
[ERC20BridgeSource.MStable]: () => 200e3,
|
||||
[ERC20BridgeSource.MakerPsm]: (fillData?: FillData) => {
|
||||
const psmFillData = fillData as MakerPsmFillData;
|
||||
|
@ -8,7 +8,6 @@ import { MAX_UINT256, ZERO_AMOUNT } from './constants';
|
||||
import {
|
||||
AaveV2FillData,
|
||||
AggregationError,
|
||||
BalancerFillData,
|
||||
BalancerV2BatchSwapFillData,
|
||||
BalancerV2FillData,
|
||||
BancorFillData,
|
||||
@ -101,8 +100,6 @@ export function getErc20BridgeSourceToBridgeSource(source: ERC20BridgeSource): s
|
||||
return encodeBridgeSourceId(BridgeProtocol.Bancor, 'Bancor');
|
||||
case ERC20BridgeSource.Curve:
|
||||
return encodeBridgeSourceId(BridgeProtocol.Curve, 'Curve');
|
||||
case ERC20BridgeSource.Cream:
|
||||
return encodeBridgeSourceId(BridgeProtocol.Balancer, 'Cream');
|
||||
case ERC20BridgeSource.CryptoCom:
|
||||
return encodeBridgeSourceId(BridgeProtocol.CryptoCom, 'CryptoCom');
|
||||
case ERC20BridgeSource.Dodo:
|
||||
@ -258,10 +255,6 @@ export function createBridgeDataForBridgeOrder(order: OptimizedMarketBridgeOrder
|
||||
]);
|
||||
break;
|
||||
case ERC20BridgeSource.Balancer:
|
||||
case ERC20BridgeSource.Cream:
|
||||
const balancerFillData = (order as OptimizedMarketBridgeOrder<BalancerFillData>).fillData;
|
||||
bridgeData = encoder.encode([balancerFillData.poolAddress]);
|
||||
break;
|
||||
case ERC20BridgeSource.BalancerV2:
|
||||
{
|
||||
const balancerV2FillData = (order as OptimizedMarketBridgeOrder<BalancerV2BatchSwapFillData>).fillData;
|
||||
@ -505,7 +498,6 @@ export const BRIDGE_ENCODERS: {
|
||||
[ERC20BridgeSource.Mooniswap]: poolEncoder,
|
||||
[ERC20BridgeSource.MStable]: poolEncoder,
|
||||
[ERC20BridgeSource.Balancer]: poolEncoder,
|
||||
[ERC20BridgeSource.Cream]: poolEncoder,
|
||||
[ERC20BridgeSource.Uniswap]: poolEncoder,
|
||||
// Custom integrations
|
||||
[ERC20BridgeSource.MakerPsm]: makerPsmEncoder,
|
||||
|
@ -1,36 +0,0 @@
|
||||
import { ChainId } from '@0x/contract-addresses';
|
||||
import { Pool } from 'balancer-labs-sor-v1/dist/types';
|
||||
import { getPoolsWithTokens, parsePoolData } from 'cream-sor';
|
||||
|
||||
import { BALANCER_MAX_POOLS_FETCHED } from '../constants';
|
||||
|
||||
import { NoOpPoolsCache } from './no_op_pools_cache';
|
||||
import { AbstractPoolsCache, CacheValue, PoolsCache } from './pools_cache';
|
||||
|
||||
export class CreamPoolsCache extends AbstractPoolsCache {
|
||||
public static create(chainId: ChainId): PoolsCache {
|
||||
if (chainId !== ChainId.Mainnet) {
|
||||
return new NoOpPoolsCache();
|
||||
}
|
||||
|
||||
return new CreamPoolsCache();
|
||||
}
|
||||
protected async _fetchPoolsForPairAsync(takerToken: string, makerToken: string): Promise<Pool[]> {
|
||||
try {
|
||||
const poolData = (await getPoolsWithTokens(takerToken, makerToken)).pools;
|
||||
// Sort by maker token balance (descending)
|
||||
const pools = parsePoolData(poolData, takerToken, makerToken).sort((a, b) =>
|
||||
b.balanceOut.minus(a.balanceOut).toNumber(),
|
||||
);
|
||||
return pools.slice(0, this.maxPoolsFetched);
|
||||
} catch (err) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
private constructor(
|
||||
_cache: Map<string, CacheValue> = new Map(),
|
||||
private readonly maxPoolsFetched: number = BALANCER_MAX_POOLS_FETCHED,
|
||||
) {
|
||||
super(_cache);
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
export { BalancerPoolsCache } from './balancer_pools_cache';
|
||||
export { BalancerV2PoolsCache } from './balancer_v2_pools_cache';
|
||||
export { CreamPoolsCache } from './cream_pools_cache';
|
||||
export { AbstractPoolsCache, PoolsCache } from './pools_cache';
|
||||
|
@ -58,7 +58,7 @@ import {
|
||||
} from './constants';
|
||||
import { getGeistInfoForPair } from './geist_utils';
|
||||
import { getLiquidityProvidersForPair } from './liquidity_provider_utils';
|
||||
import { BalancerPoolsCache, BalancerV2PoolsCache, CreamPoolsCache, PoolsCache } from './pools_cache';
|
||||
import { BalancerPoolsCache, BalancerV2PoolsCache, PoolsCache } from './pools_cache';
|
||||
import { BalancerV2SwapInfoCache } from './pools_cache/balancer_v2_swap_info_cache';
|
||||
import { SamplerContractOperation } from './sampler_contract_operation';
|
||||
import { SamplerNoOperation } from './sampler_no_operation';
|
||||
@ -120,7 +120,6 @@ export interface PoolsCacheMap {
|
||||
[ERC20BridgeSource.Balancer]: PoolsCache;
|
||||
[ERC20BridgeSource.BalancerV2]: BalancerV2SwapInfoCache | undefined;
|
||||
[ERC20BridgeSource.Beethovenx]: PoolsCache;
|
||||
[ERC20BridgeSource.Cream]: PoolsCache;
|
||||
}
|
||||
|
||||
// tslint:disable:no-inferred-empty-object-type no-unbound-method
|
||||
@ -160,7 +159,6 @@ export class SamplerOperations {
|
||||
: {
|
||||
[ERC20BridgeSource.Beethovenx]: BalancerV2PoolsCache.createBeethovenXPoolCache(chainId),
|
||||
[ERC20BridgeSource.Balancer]: BalancerPoolsCache.create(chainId),
|
||||
[ERC20BridgeSource.Cream]: CreamPoolsCache.create(chainId),
|
||||
[ERC20BridgeSource.BalancerV2]:
|
||||
BALANCER_V2_VAULT_ADDRESS_BY_CHAIN[chainId] === NULL_ADDRESS
|
||||
? undefined
|
||||
@ -1668,18 +1666,6 @@ export class SamplerOperations {
|
||||
),
|
||||
);
|
||||
}
|
||||
case ERC20BridgeSource.Cream:
|
||||
return this.poolsCaches[ERC20BridgeSource.Cream]
|
||||
.getPoolAddressesForPair(takerToken, makerToken)
|
||||
.map(creamPool =>
|
||||
this.getBalancerSellQuotes(
|
||||
creamPool,
|
||||
makerToken,
|
||||
takerToken,
|
||||
takerFillAmounts,
|
||||
ERC20BridgeSource.Cream,
|
||||
),
|
||||
);
|
||||
case ERC20BridgeSource.Dodo:
|
||||
if (!isValidAddress(DODOV1_CONFIG_BY_CHAIN_ID[this.chainId].registry)) {
|
||||
return [];
|
||||
@ -2031,18 +2017,6 @@ export class SamplerOperations {
|
||||
),
|
||||
);
|
||||
}
|
||||
case ERC20BridgeSource.Cream:
|
||||
return this.poolsCaches[ERC20BridgeSource.Cream]
|
||||
.getPoolAddressesForPair(takerToken, makerToken)
|
||||
.map(poolAddress =>
|
||||
this.getBalancerBuyQuotes(
|
||||
poolAddress,
|
||||
makerToken,
|
||||
takerToken,
|
||||
makerFillAmounts,
|
||||
ERC20BridgeSource.Cream,
|
||||
),
|
||||
);
|
||||
case ERC20BridgeSource.Dodo:
|
||||
if (!isValidAddress(DODOV1_CONFIG_BY_CHAIN_ID[this.chainId].registry)) {
|
||||
return [];
|
||||
|
@ -44,7 +44,6 @@ export enum ERC20BridgeSource {
|
||||
MultiBridge = 'MultiBridge',
|
||||
Balancer = 'Balancer',
|
||||
BalancerV2 = 'Balancer_V2',
|
||||
Cream = 'CREAM',
|
||||
Bancor = 'Bancor',
|
||||
MakerPsm = 'MakerPsm',
|
||||
MStable = 'mStable',
|
||||
|
@ -107,7 +107,7 @@ class MockPoolsCache extends AbstractPoolsCache {
|
||||
}
|
||||
}
|
||||
|
||||
// Return some pool so that sampling functions are called for Balancer, BalancerV2, and Cream
|
||||
// Return some pool so that sampling functions are called for Balancer and BalancerV2
|
||||
// tslint:disable:custom-no-magic-numbers
|
||||
const mockPoolsCache = new MockPoolsCache((_takerToken: string, _makerToken: string) => {
|
||||
return [
|
||||
@ -361,7 +361,6 @@ describe('MarketOperationUtils tests', () => {
|
||||
[ERC20BridgeSource.MultiHop]: {},
|
||||
[ERC20BridgeSource.Shell]: { poolAddress: randomAddress() },
|
||||
[ERC20BridgeSource.Component]: { poolAddress: randomAddress() },
|
||||
[ERC20BridgeSource.Cream]: { poolAddress: randomAddress() },
|
||||
[ERC20BridgeSource.Dodo]: {},
|
||||
[ERC20BridgeSource.DodoV2]: {},
|
||||
[ERC20BridgeSource.CryptoCom]: { tokenAddressPath: [] },
|
||||
@ -401,7 +400,6 @@ describe('MarketOperationUtils tests', () => {
|
||||
poolsCaches: {
|
||||
[ERC20BridgeSource.BalancerV2]: mockPoolsCache,
|
||||
[ERC20BridgeSource.Balancer]: mockPoolsCache,
|
||||
[ERC20BridgeSource.Cream]: mockPoolsCache,
|
||||
},
|
||||
liquidityProviderRegistry: {},
|
||||
chainId: CHAIN_ID,
|
||||
|
@ -2,12 +2,7 @@ import { ChainId } from '@0x/contract-addresses';
|
||||
import * as chai from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import {
|
||||
BalancerPoolsCache,
|
||||
BalancerV2PoolsCache,
|
||||
CreamPoolsCache,
|
||||
PoolsCache,
|
||||
} from '../src/utils/market_operation_utils/pools_cache';
|
||||
import { BalancerPoolsCache, BalancerV2PoolsCache, PoolsCache } from '../src/utils/market_operation_utils/pools_cache';
|
||||
|
||||
import { chaiSetup } from './utils/chai_setup';
|
||||
|
||||
@ -17,7 +12,6 @@ const expect = chai.expect;
|
||||
const usdcAddress = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
|
||||
const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';
|
||||
const wethAddress = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
||||
const creamAddress = '0x2ba592f78db6436527729929aaf6c908497cb200';
|
||||
|
||||
const timeoutMs = 5000;
|
||||
const poolKeys: string[] = ['id', 'balanceIn', 'balanceOut', 'weightIn', 'weightOut', 'swapFee'];
|
||||
@ -63,17 +57,4 @@ describe('Pools Caches for Balancer-based sampling', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CreamPoolsCache', () => {
|
||||
const cache = CreamPoolsCache.create(ChainId.Mainnet);
|
||||
it('fetches pools', async () => {
|
||||
const pairs = [
|
||||
[usdcAddress, creamAddress],
|
||||
[creamAddress, wethAddress],
|
||||
];
|
||||
await Promise.all(
|
||||
pairs.map(async ([takerToken, makerToken]) => fetchAndAssertPoolsAsync(cache, takerToken, makerToken)),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4905,13 +4905,6 @@ crc-32@^1.2.0:
|
||||
exit-on-epipe "~1.0.1"
|
||||
printj "~1.1.0"
|
||||
|
||||
cream-sor@^0.3.3:
|
||||
version "0.3.3"
|
||||
resolved "https://registry.yarnpkg.com/cream-sor/-/cream-sor-0.3.3.tgz#ae7ab50c68cfd36a89e2101187ceebbb79e1b14c"
|
||||
dependencies:
|
||||
bignumber.js "^9.0.0"
|
||||
isomorphic-fetch "^2.2.1"
|
||||
|
||||
create-ecdh@^4.0.0:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.4.tgz#d6e7f4bffa66736085a0762fd3a632684dabcc4e"
|
||||
|
Loading…
x
Reference in New Issue
Block a user