Add default liquidity provider registry and allow gas costs to be a function of tokens (#196)
This commit is contained in:
@@ -5,6 +5,10 @@
|
||||
{
|
||||
"note": "Add Kyber DMM to Ethereum mainnet",
|
||||
"pr": 194
|
||||
},
|
||||
{
|
||||
"note": "Add default LiquidityProvider registry and allow LiquidityProvider gasCost to be a function of tokens",
|
||||
"pr": 196
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -236,6 +236,9 @@ export const TOKENS = {
|
||||
sEUR: '0xd71ecff9342a5ced620049e616c5035f1db98620',
|
||||
sETH: '0x5e74c9036fb86bd7ecdcb084a0673efc32ea31cb',
|
||||
LINK: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
||||
MANA: '0x0f5d2fb29fb7d3cfee444a200298f468908cc942',
|
||||
KNC: '0xdd974d5c2e2928dea5f71b9825b8b646686bd200',
|
||||
AAVE: '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9',
|
||||
// Mirror Protocol
|
||||
UST: '0xa47c8bf37f92abed4a126bda807a7b7498661acd',
|
||||
MIR: '0x09a3ecafa817268f77be1283176b946c4ff2e608',
|
||||
@@ -612,7 +615,30 @@ export const KYBER_CONFIG_BY_CHAIN_ID = valueByChainId<KyberSamplerOpts>(
|
||||
},
|
||||
);
|
||||
|
||||
export const LIQUIDITY_PROVIDER_REGISTRY: LiquidityProviderRegistry = {};
|
||||
export const LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID = valueByChainId<LiquidityProviderRegistry>(
|
||||
{
|
||||
[ChainId.Mainnet]: {
|
||||
['0x1d0d407c5af8c86f0a6494de86e56ae21e46a951']: {
|
||||
tokens: [
|
||||
TOKENS.WETH,
|
||||
TOKENS.USDC,
|
||||
TOKENS.USDT,
|
||||
TOKENS.WBTC,
|
||||
TOKENS.PAX,
|
||||
TOKENS.LINK,
|
||||
TOKENS.KNC,
|
||||
TOKENS.MANA,
|
||||
TOKENS.DAI,
|
||||
TOKENS.BUSD,
|
||||
TOKENS.AAVE,
|
||||
],
|
||||
gasCost: (takerToken: string, makerToken: string) =>
|
||||
[takerToken, makerToken].includes(TOKENS.WETH) ? 160e3 : 280e3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
export const UNISWAPV1_ROUTER_BY_CHAIN_ID = valueByChainId<string>(
|
||||
{
|
||||
|
||||
@@ -5,8 +5,22 @@ export function getLiquidityProvidersForPair(
|
||||
registry: LiquidityProviderRegistry,
|
||||
takerToken: string,
|
||||
makerToken: string,
|
||||
): string[] {
|
||||
): Array<{ providerAddress: string; gasCost: number }> {
|
||||
return Object.entries(registry)
|
||||
.filter(([, plp]) => [makerToken, takerToken].every(t => plp.tokens.includes(t)))
|
||||
.map(([providerAddress]) => providerAddress);
|
||||
.map(([providerAddress]) => {
|
||||
let gasCost: number;
|
||||
if (typeof registry[providerAddress].gasCost === 'number') {
|
||||
gasCost = registry[providerAddress].gasCost as number;
|
||||
} else {
|
||||
gasCost = (registry[providerAddress].gasCost as (takerToken: string, makerToken: string) => number)(
|
||||
takerToken,
|
||||
makerToken,
|
||||
);
|
||||
}
|
||||
return {
|
||||
providerAddress,
|
||||
gasCost,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
DODOV2_FACTORIES_BY_CHAIN_ID,
|
||||
KYBER_CONFIG_BY_CHAIN_ID,
|
||||
LINKSWAP_ROUTER_BY_CHAIN_ID,
|
||||
LIQUIDITY_PROVIDER_REGISTRY,
|
||||
LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID,
|
||||
MAKER_PSM_INFO_BY_CHAIN_ID,
|
||||
MAX_UINT256,
|
||||
MOONISWAP_REGISTRIES_BY_CHAIN_ID,
|
||||
@@ -87,6 +87,7 @@ export const BATCH_SOURCE_FILTERS = SourceFilters.all().exclude([ERC20BridgeSour
|
||||
* for use with `DexOrderSampler.executeAsync()`.
|
||||
*/
|
||||
export class SamplerOperations {
|
||||
public readonly liquidityProviderRegistry: LiquidityProviderRegistry;
|
||||
protected _bancorService?: BancorService;
|
||||
public static constant<T>(result: T): BatchedOperation<T> {
|
||||
return {
|
||||
@@ -102,9 +103,13 @@ export class SamplerOperations {
|
||||
public readonly balancerPoolsCache: BalancerPoolsCache = new BalancerPoolsCache(),
|
||||
public readonly creamPoolsCache: CreamPoolsCache = new CreamPoolsCache(),
|
||||
protected readonly tokenAdjacencyGraph: TokenAdjacencyGraph = { default: [] },
|
||||
public readonly liquidityProviderRegistry: LiquidityProviderRegistry = LIQUIDITY_PROVIDER_REGISTRY,
|
||||
liquidityProviderRegistry: LiquidityProviderRegistry = {},
|
||||
bancorServiceFn: () => Promise<BancorService | undefined> = async () => undefined,
|
||||
) {
|
||||
this.liquidityProviderRegistry = {
|
||||
...LIQUIDITY_PROVIDER_REGISTRY_BY_CHAIN_ID[chainId],
|
||||
...liquidityProviderRegistry,
|
||||
};
|
||||
// Initialize the Bancor service, fetching paths in the background
|
||||
bancorServiceFn()
|
||||
.then(service => (this._bancorService = service))
|
||||
@@ -277,12 +282,13 @@ export class SamplerOperations {
|
||||
makerToken: string,
|
||||
takerToken: string,
|
||||
takerFillAmounts: BigNumber[],
|
||||
gasCost: number,
|
||||
): SourceQuoteOperation<LiquidityProviderFillData> {
|
||||
return new SamplerContractOperation({
|
||||
source: ERC20BridgeSource.LiquidityProvider,
|
||||
fillData: {
|
||||
poolAddress: providerAddress,
|
||||
gasCost: this.liquidityProviderRegistry[providerAddress].gasCost,
|
||||
gasCost,
|
||||
},
|
||||
contract: this._samplerContract,
|
||||
function: this._samplerContract.sampleSellsFromLiquidityProvider,
|
||||
@@ -295,12 +301,13 @@ export class SamplerOperations {
|
||||
makerToken: string,
|
||||
takerToken: string,
|
||||
makerFillAmounts: BigNumber[],
|
||||
gasCost: number,
|
||||
): SourceQuoteOperation<LiquidityProviderFillData> {
|
||||
return new SamplerContractOperation({
|
||||
source: ERC20BridgeSource.LiquidityProvider,
|
||||
fillData: {
|
||||
poolAddress: providerAddress,
|
||||
gasCost: this.liquidityProviderRegistry[providerAddress].gasCost,
|
||||
gasCost,
|
||||
},
|
||||
contract: this._samplerContract,
|
||||
function: this._samplerContract.sampleBuysFromLiquidityProvider,
|
||||
@@ -1061,8 +1068,14 @@ export class SamplerOperations {
|
||||
this.liquidityProviderRegistry,
|
||||
takerToken,
|
||||
makerToken,
|
||||
).map(pool =>
|
||||
this.getLiquidityProviderSellQuotes(pool, makerToken, takerToken, takerFillAmounts),
|
||||
).map(({ providerAddress, gasCost }) =>
|
||||
this.getLiquidityProviderSellQuotes(
|
||||
providerAddress,
|
||||
makerToken,
|
||||
takerToken,
|
||||
takerFillAmounts,
|
||||
gasCost,
|
||||
),
|
||||
);
|
||||
case ERC20BridgeSource.MStable:
|
||||
return isValidAddress(MSTABLE_ROUTER_BY_CHAIN_ID[this.chainId])
|
||||
@@ -1253,8 +1266,14 @@ export class SamplerOperations {
|
||||
this.liquidityProviderRegistry,
|
||||
takerToken,
|
||||
makerToken,
|
||||
).map(pool =>
|
||||
this.getLiquidityProviderBuyQuotes(pool, makerToken, takerToken, makerFillAmounts),
|
||||
).map(({ providerAddress, gasCost }) =>
|
||||
this.getLiquidityProviderBuyQuotes(
|
||||
providerAddress,
|
||||
makerToken,
|
||||
takerToken,
|
||||
makerFillAmounts,
|
||||
gasCost,
|
||||
),
|
||||
);
|
||||
case ERC20BridgeSource.MStable:
|
||||
return isValidAddress(MSTABLE_ROUTER_BY_CHAIN_ID[this.chainId])
|
||||
|
||||
@@ -440,7 +440,7 @@ export interface TokenAdjacencyGraph {
|
||||
export interface LiquidityProviderRegistry {
|
||||
[address: string]: {
|
||||
tokens: string[];
|
||||
gasCost: number;
|
||||
gasCost: number | ((takerToken: string, makerToken: string) => number);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user