@paraswap/dex-lib 2.15.1 → 2.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/modules.xml +1 -1
- package/.vscode/launch.json +21 -0
- package/build/dex/aave-v3/tokens/arbitrum.json +20 -20
- package/build/dex/aave-v3/tokens/avalanche.json +20 -44
- package/build/dex/aave-v3/tokens/fantom.json +30 -30
- package/build/dex/aave-v3/tokens/mainnet.json +44 -0
- package/build/dex/aave-v3/tokens/optimism.json +18 -18
- package/build/dex/aave-v3/tokens/polygon.json +42 -60
- package/build/dex/balancer-v2/VirtualBoostedPool.d.ts +79 -0
- package/build/dex/balancer-v2/VirtualBoostedPool.js +382 -0
- package/build/dex/balancer-v2/VirtualBoostedPool.js.map +1 -0
- package/build/dex/generic-rfq/rate-fetcher.js +2 -2
- package/build/dex/generic-rfq/rate-fetcher.js.map +1 -1
- package/build/dex/hashflow/hashflow.js.map +1 -1
- package/build/dex/hashflow/validators.js.map +1 -1
- package/build/dex/test-aave-v3/config.d.ts +4 -0
- package/build/dex/test-aave-v3/config.js +15 -0
- package/build/dex/test-aave-v3/config.js.map +1 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.d.ts +39 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.js +63 -0
- package/build/dex/test-aave-v3/test-aave-v3-pool.js.map +1 -0
- package/build/dex/test-aave-v3/test-aave-v3.d.ts +37 -0
- package/build/dex/test-aave-v3/test-aave-v3.js +126 -0
- package/build/dex/test-aave-v3/test-aave-v3.js.map +1 -0
- package/build/dex/test-aave-v3/types.d.ts +6 -0
- package/build/dex/test-aave-v3/types.js +3 -0
- package/build/dex/test-aave-v3/types.js.map +1 -0
- package/build/lib/fetcher/fetcher.js +1 -2
- package/build/lib/fetcher/fetcher.js.map +1 -1
- package/package.json +1 -1
- package/src/dex/generic-rfq/generic-rfq-e2e.test.ts +26 -10
- package/src/dex/generic-rfq/rate-fetcher.ts +8 -4
- package/src/dex/hashflow/hashflow.ts +1 -1
- package/src/dex/hashflow/validators.ts +18 -14
- package/src/lib/fetcher/fetcher.ts +40 -35
- package/tests/constants-e2e.ts +4 -0
- package/tests/utils-e2e.ts +35 -11
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/runConfigurations.xml +0 -10
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
3
|
+
import { Log, Logger } from '../../types';
|
|
4
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
6
|
+
import { PoolState } from './types';
|
|
7
|
+
export declare class TestAaveV3EventPool extends StatefulEventSubscriber<PoolState> {
|
|
8
|
+
protected parentName: string;
|
|
9
|
+
protected network: number;
|
|
10
|
+
protected dexHelper: IDexHelper;
|
|
11
|
+
protected testAaveV3Iface: Interface;
|
|
12
|
+
handlers: {
|
|
13
|
+
[event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>) => DeepReadonly<PoolState> | null;
|
|
14
|
+
};
|
|
15
|
+
logDecoder: (log: Log) => any;
|
|
16
|
+
addressesSubscribed: string[];
|
|
17
|
+
constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, testAaveV3Iface?: Interface);
|
|
18
|
+
/**
|
|
19
|
+
* The function is called every time any of the subscribed
|
|
20
|
+
* addresses release log. The function accepts the current
|
|
21
|
+
* state, updates the state according to the log, and returns
|
|
22
|
+
* the updated state.
|
|
23
|
+
* @param state - Current state of event subscriber
|
|
24
|
+
* @param log - Log released by one of the subscribed addresses
|
|
25
|
+
* @returns Updates state of the event subscriber after the log
|
|
26
|
+
*/
|
|
27
|
+
protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
|
|
28
|
+
/**
|
|
29
|
+
* The function generates state using on-chain calls. This
|
|
30
|
+
* function is called to regenerate state if the event based
|
|
31
|
+
* system fails to fetch events and the local state is no
|
|
32
|
+
* more correct.
|
|
33
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
34
|
+
* should be generated
|
|
35
|
+
* @returns state of the event subscriber at blocknumber
|
|
36
|
+
*/
|
|
37
|
+
generateState(blockNumber: number): Promise<DeepReadonly<PoolState>>;
|
|
38
|
+
handleMyEvent(event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
|
|
39
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestAaveV3EventPool = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
7
|
+
class TestAaveV3EventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
8
|
+
constructor(parentName, network, dexHelper, logger, testAaveV3Iface = new abi_1.Interface('' /* TODO: Import and put here TestAaveV3 ABI */)) {
|
|
9
|
+
super(parentName, logger);
|
|
10
|
+
this.parentName = parentName;
|
|
11
|
+
this.network = network;
|
|
12
|
+
this.dexHelper = dexHelper;
|
|
13
|
+
this.testAaveV3Iface = testAaveV3Iface;
|
|
14
|
+
this.handlers = {};
|
|
15
|
+
// TODO: make logDecoder decode logs that
|
|
16
|
+
this.logDecoder = (log) => this.testAaveV3Iface.parseLog(log);
|
|
17
|
+
this.addressesSubscribed = [
|
|
18
|
+
/* subscribed addresses */
|
|
19
|
+
];
|
|
20
|
+
// Add handlers
|
|
21
|
+
this.handlers['myEvent'] = this.handleMyEvent.bind(this);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The function is called every time any of the subscribed
|
|
25
|
+
* addresses release log. The function accepts the current
|
|
26
|
+
* state, updates the state according to the log, and returns
|
|
27
|
+
* the updated state.
|
|
28
|
+
* @param state - Current state of event subscriber
|
|
29
|
+
* @param log - Log released by one of the subscribed addresses
|
|
30
|
+
* @returns Updates state of the event subscriber after the log
|
|
31
|
+
*/
|
|
32
|
+
processLog(state, log) {
|
|
33
|
+
try {
|
|
34
|
+
const event = this.logDecoder(log);
|
|
35
|
+
if (event.name in this.handlers) {
|
|
36
|
+
return this.handlers[event.name](event, state, log);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
(0, utils_1.catchParseLogError)(e, this.logger);
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The function generates state using on-chain calls. This
|
|
46
|
+
* function is called to regenerate state if the event based
|
|
47
|
+
* system fails to fetch events and the local state is no
|
|
48
|
+
* more correct.
|
|
49
|
+
* @param blockNumber - Blocknumber for which the state should
|
|
50
|
+
* should be generated
|
|
51
|
+
* @returns state of the event subscriber at blocknumber
|
|
52
|
+
*/
|
|
53
|
+
async generateState(blockNumber) {
|
|
54
|
+
// TODO: complete me!
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
// Its just a dummy example
|
|
58
|
+
handleMyEvent(event, state, log) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.TestAaveV3EventPool = TestAaveV3EventPool;
|
|
63
|
+
//# sourceMappingURL=test-aave-v3-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-aave-v3-pool.js","sourceRoot":"","sources":["../../../src/dex/test-aave-v3/test-aave-v3-pool.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAI1E,MAAa,mBAAoB,SAAQ,mDAAkC;IAWzE,YACY,UAAkB,EAClB,OAAe,EACf,SAAqB,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,CAAC;IACd,CAAC;CACF;AA/ED,kDA+EC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
2
|
+
import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, SimpleExchangeParam, PoolLiquidity, Logger } from '../../types';
|
|
3
|
+
import { SwapSide, Network } from '../../constants';
|
|
4
|
+
import { IDex } from '../../dex/idex';
|
|
5
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
6
|
+
import { TestAaveV3Data } from './types';
|
|
7
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
8
|
+
import { TestAaveV3EventPool } from './test-aave-v3-pool';
|
|
9
|
+
export declare class TestAaveV3 extends SimpleExchange implements IDex<TestAaveV3Data> {
|
|
10
|
+
readonly network: Network;
|
|
11
|
+
readonly dexKey: string;
|
|
12
|
+
readonly dexHelper: IDexHelper;
|
|
13
|
+
protected adapters: import("../../types").AdapterMappings;
|
|
14
|
+
protected eventPools: TestAaveV3EventPool;
|
|
15
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
16
|
+
readonly needWrapNative = true;
|
|
17
|
+
readonly isFeeOnTransferSupported = false;
|
|
18
|
+
static dexKeysWithNetwork: {
|
|
19
|
+
key: string;
|
|
20
|
+
networks: Network[];
|
|
21
|
+
}[];
|
|
22
|
+
logger: Logger;
|
|
23
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
|
|
24
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
25
|
+
getAdapters(side: SwapSide): {
|
|
26
|
+
name: string;
|
|
27
|
+
index: number;
|
|
28
|
+
}[] | null;
|
|
29
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
30
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<TestAaveV3Data>>;
|
|
31
|
+
getCalldataGasCost(poolPrices: PoolPrices<TestAaveV3Data>): number | number[];
|
|
32
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: TestAaveV3Data, side: SwapSide): AdapterExchangeParam;
|
|
33
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: TestAaveV3Data, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
34
|
+
updatePoolState(): Promise<void>;
|
|
35
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
36
|
+
releaseResources(): AsyncOrSync<void>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.TestAaveV3 = void 0;
|
|
27
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
28
|
+
const utils_1 = require("../../utils");
|
|
29
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
30
|
+
const config_1 = require("./config");
|
|
31
|
+
const test_aave_v3_pool_1 = require("./test-aave-v3-pool");
|
|
32
|
+
class TestAaveV3 extends simple_exchange_1.SimpleExchange {
|
|
33
|
+
constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
|
|
34
|
+
super(dexHelper, dexKey);
|
|
35
|
+
this.network = network;
|
|
36
|
+
this.dexKey = dexKey;
|
|
37
|
+
this.dexHelper = dexHelper;
|
|
38
|
+
this.adapters = adapters;
|
|
39
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
40
|
+
// TODO: set true here if protocols works only with wrapped asset
|
|
41
|
+
this.needWrapNative = true;
|
|
42
|
+
this.isFeeOnTransferSupported = false;
|
|
43
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
44
|
+
this.eventPools = new test_aave_v3_pool_1.TestAaveV3EventPool(dexKey, network, dexHelper, this.logger);
|
|
45
|
+
}
|
|
46
|
+
// Initialize pricing is called once in the start of
|
|
47
|
+
// pricing service. It is intended to setup the integration
|
|
48
|
+
// for pricing requests. It is optional for a DEX to
|
|
49
|
+
// implement this function
|
|
50
|
+
async initializePricing(blockNumber) {
|
|
51
|
+
// TODO: complete me!
|
|
52
|
+
}
|
|
53
|
+
// Returns the list of contract adapters (name and index)
|
|
54
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
55
|
+
getAdapters(side) {
|
|
56
|
+
return this.adapters[side] ? this.adapters[side] : null;
|
|
57
|
+
}
|
|
58
|
+
// Returns list of pool identifiers that can be used
|
|
59
|
+
// for a given swap. poolIdentifiers must be unique
|
|
60
|
+
// across DEXes. It is recommended to use
|
|
61
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
62
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
63
|
+
// TODO: complete me!
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
// Returns pool prices for amounts.
|
|
67
|
+
// If limitPools is defined only pools in limitPools
|
|
68
|
+
// should be used. If limitPools is undefined then
|
|
69
|
+
// any pools can be used.
|
|
70
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
71
|
+
// TODO: complete me!
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
75
|
+
getCalldataGasCost(poolPrices) {
|
|
76
|
+
// TODO: update if there is any payload in getAdapterParam
|
|
77
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
78
|
+
}
|
|
79
|
+
// Encode params required by the exchange adapter
|
|
80
|
+
// Used for multiSwap, buy & megaSwap
|
|
81
|
+
// Hint: abiCoder.encodeParameter() could be useful
|
|
82
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
83
|
+
// TODO: complete me!
|
|
84
|
+
const { exchange } = data;
|
|
85
|
+
// Encode here the payload for adapter
|
|
86
|
+
const payload = '';
|
|
87
|
+
return {
|
|
88
|
+
targetExchange: exchange,
|
|
89
|
+
payload,
|
|
90
|
+
networkFee: '0',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Encode call data used by simpleSwap like routers
|
|
94
|
+
// Used for simpleSwap & simpleBuy
|
|
95
|
+
// Hint: this.buildSimpleParamWithoutWETHConversion
|
|
96
|
+
// could be useful
|
|
97
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
98
|
+
// TODO: complete me!
|
|
99
|
+
const { exchange } = data;
|
|
100
|
+
// Encode here the transaction arguments
|
|
101
|
+
const swapData = '';
|
|
102
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, exchange);
|
|
103
|
+
}
|
|
104
|
+
// This is called once before getTopPoolsForToken is
|
|
105
|
+
// called for multiple tokens. This can be helpful to
|
|
106
|
+
// update common state required for calculating
|
|
107
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
108
|
+
// to implement this
|
|
109
|
+
async updatePoolState() {
|
|
110
|
+
// TODO: complete me!
|
|
111
|
+
}
|
|
112
|
+
// Returns list of top pools based on liquidity. Max
|
|
113
|
+
// limit number pools should be returned.
|
|
114
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
115
|
+
//TODO: complete me!
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
// This is optional function in case if your implementation has acquired any resources
|
|
119
|
+
// you need to release for graceful shutdown. For example, it may be any interval timer
|
|
120
|
+
releaseResources() {
|
|
121
|
+
// TODO: complete me!
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.TestAaveV3 = TestAaveV3;
|
|
125
|
+
TestAaveV3.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.TestAaveV3Config);
|
|
126
|
+
//# sourceMappingURL=test-aave-v3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-aave-v3.js","sourceRoot":"","sources":["../../../src/dex/test-aave-v3/test-aave-v3.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,2EAA6D;AAC7D,uCAAoD;AAIpD,wDAAoD;AACpD,qCAAsD;AACtD,2DAA0D;AAE1D,MAAa,UACX,SAAQ,gCAAc;IAgBtB,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ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SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAoB,EACpB,IAAc;QAEd,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,sCAAsC;QACtC,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,OAAO;YACL,cAAc,EAAE,QAAQ;YACxB,OAAO;YACP,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;IAED,mDAAmD;IACnD,kCAAkC;IAClC,mDAAmD;IACnD,kBAAkB;IAClB,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAoB,EACpB,IAAc;QAEd,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,wCAAwC;QACxC,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,OAAO,IAAI,CAAC,qCAAqC,CAC/C,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,oDAAoD;IACpD,qDAAqD;IACrD,+CAA+C;IAC/C,gDAAgD;IAChD,oBAAoB;IACpB,KAAK,CAAC,eAAe;QACnB,qBAAqB;IACvB,CAAC;IAED,oDAAoD;IACpD,yCAAyC;IACzC,KAAK,CAAC,mBAAmB,CACvB,YAAqB,EACrB,KAAa;QAEb,oBAAoB;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB;QACd,qBAAqB;IACvB,CAAC;;AAhKH,gCAiKC;AArJe,6BAAkB,GAC9B,IAAA,6BAAqB,EAAC,yBAAgB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/test-aave-v3/types.ts"],"names":[],"mappings":""}
|
|
@@ -11,7 +11,6 @@ class SkippingRequest {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.SkippingRequest = SkippingRequest;
|
|
14
|
-
;
|
|
15
14
|
class Fetcher {
|
|
16
15
|
constructor(requestWrapper, requestsInfo, pollIntervalMs, logger) {
|
|
17
16
|
this.requestWrapper = requestWrapper;
|
|
@@ -107,7 +106,7 @@ class Fetcher {
|
|
|
107
106
|
reqInfo.handler(parsedData);
|
|
108
107
|
}
|
|
109
108
|
catch (e) {
|
|
110
|
-
this.logger.
|
|
109
|
+
this.logger.info(`(${options.url}) received incorrect data ${JSON.stringify(response.data).replace(/(?:\r\n|\r|\n)/g, ' ')}`, e);
|
|
111
110
|
return;
|
|
112
111
|
}
|
|
113
112
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../../src/lib/fetcher/fetcher.ts"],"names":[],"mappings":";;;AAGA,mCAAoC;AAEpC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9C,MAAa,eAAe;IAC1B,
|
|
1
|
+
{"version":3,"file":"fetcher.js","sourceRoot":"","sources":["../../../src/lib/fetcher/fetcher.ts"],"names":[],"mappings":";;;AAGA,mCAAoC;AAEpC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AACnC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,2BAA2B,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9C,MAAa,eAAe;IAC1B,YAAmB,UAAU,EAAE;QAAZ,YAAO,GAAP,OAAO,CAAK;IAAG,CAAC;CACpC;AAFD,0CAEC;AAiBD,MAAa,OAAO;IAMlB,YACU,cAA+B,EACvC,YAAqE,EAC7D,cAAsB,EACtB,MAAc;QAHd,mBAAc,GAAd,cAAc,CAAiB;QAE/B,mBAAc,GAAd,cAAc,CAAQ;QACtB,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CAAC,UAAU,CAAC,CAAC;aAC7B;YAAC,OAAO,CAAC,EAAE;gBACV,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,IAAI,OAAO,CAAC,GAAG,6BAA6B,IAAI,CAAC,SAAS,CACxD,QAAQ,CAAC,IAAI,CACd,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,EACnC,CAAC,CACF,CAAC;gBACF,OAAO;aACR;QACH,CAAC,CAAC,CAAC;QACL,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAEvD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,OAAO;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,GAAI,CAAC,CAAC;IAC9D,CAAC;IAED,YAAY;QACV,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,WAAW;QACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,SAAS;QACP,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;IACpB,CAAC;CACF;AA1JD,0BA0JC"}
|
package/package.json
CHANGED
|
@@ -5,9 +5,15 @@ import { ethers } from 'ethers';
|
|
|
5
5
|
import { Network, ContractMethod, SwapSide, MAX_UINT } from '../../constants';
|
|
6
6
|
import { generateConfig } from '../../config';
|
|
7
7
|
import { newTestE2E, getEnv } from '../../../tests/utils-e2e';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
SmartTokens,
|
|
10
|
+
GENERIC_ADDR1,
|
|
11
|
+
Tokens,
|
|
12
|
+
} from '../../../tests/constants-e2e';
|
|
9
13
|
import { RFQConfig } from './types';
|
|
10
14
|
import { testConfig } from './e2e-test-config';
|
|
15
|
+
import { SmartToken } from '../../../tests/smart-tokens';
|
|
16
|
+
import { Token } from '../../types';
|
|
11
17
|
|
|
12
18
|
const PK_KEY = process.env.TEST_PK_KEY;
|
|
13
19
|
|
|
@@ -85,22 +91,32 @@ const dexKey = 'YOUR_NAME';
|
|
|
85
91
|
describe(`GenericRFQ ${dexKey} E2E`, () => {
|
|
86
92
|
for (const [_network, testCases] of Object.entries(testConfig)) {
|
|
87
93
|
const network = parseInt(_network, 10);
|
|
94
|
+
const tokens = Tokens[network];
|
|
88
95
|
const smartTokens = SmartTokens[network];
|
|
89
96
|
const config = generateConfig(network);
|
|
90
97
|
|
|
91
98
|
config.rfqConfigs[dexKey] = buildConfigForGenericRFQ();
|
|
92
99
|
describe(`${Network[network]}`, () => {
|
|
93
100
|
for (const testCase of testCases) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
let srcToken: Token | SmartToken, destToken: Token | SmartToken;
|
|
102
|
+
|
|
103
|
+
if (SKIP_TENDERLY) {
|
|
104
|
+
srcToken = tokens[testCase.srcToken];
|
|
105
|
+
destToken = tokens[testCase.destToken];
|
|
106
|
+
} else {
|
|
107
|
+
if (!smartTokens.hasOwnProperty(testCase.srcToken)) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Please add "addBalance" and "addAllowance" functions for ${testCase.srcToken} on ${Network[network]} (in constants-e2e.ts).`,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (!smartTokens.hasOwnProperty(testCase.destToken)) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Please add "addBalance" and "addAllowance" functions for ${testCase.destToken} on ${Network[network]} (in constants-e2e.ts).`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
srcToken = smartTokens[testCase.srcToken];
|
|
118
|
+
destToken = smartTokens[testCase.destToken];
|
|
102
119
|
|
|
103
|
-
if (!SKIP_TENDERLY) {
|
|
104
120
|
srcToken.addBalance(testAccount.address, MAX_UINT);
|
|
105
121
|
srcToken.addAllowance(
|
|
106
122
|
testAccount.address,
|
|
@@ -401,13 +401,17 @@ export class RateFetcher {
|
|
|
401
401
|
this.firmRateAuth(payload);
|
|
402
402
|
delete payload.secret;
|
|
403
403
|
}
|
|
404
|
-
|
|
405
|
-
|
|
404
|
+
this.logger.info(
|
|
405
|
+
'FirmRate Request:',
|
|
406
|
+
JSON.stringify(payload).replace(/(?:\r\n|\r|\n)/g, ' '),
|
|
407
|
+
);
|
|
406
408
|
const { data } = await this.dexHelper.httpRequest.request<unknown>(
|
|
407
409
|
payload,
|
|
408
410
|
);
|
|
409
|
-
this.logger.info(
|
|
410
|
-
|
|
411
|
+
this.logger.info(
|
|
412
|
+
'FirmRate Response: ',
|
|
413
|
+
JSON.stringify(data).replace(/(?:\r\n|\r|\n)/g, ' '),
|
|
414
|
+
);
|
|
411
415
|
const firmRateResp = validateAndCast<RFQFirmRateResponse>(
|
|
412
416
|
data,
|
|
413
417
|
firmRateResponseValidator,
|
|
@@ -115,7 +115,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
|
|
|
115
115
|
rateConfig: {
|
|
116
116
|
pricesIntervalMs: HASHFLOW_API_PRICES_POLLING_INTERVAL_MS,
|
|
117
117
|
markerMakersIntervalMs:
|
|
118
|
-
|
|
118
|
+
HASHFLOW_API_MARKET_MAKERS_POLLING_INTERVAL_MS,
|
|
119
119
|
marketMakersReqParams: {
|
|
120
120
|
url: `${HASHFLOW_API_URL}/taker/v1/marketMakers`,
|
|
121
121
|
params: {
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import joi from 'joi';
|
|
2
2
|
|
|
3
|
-
export const levelValidator = joi.array().items(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export const levelValidator = joi.array().items(
|
|
4
|
+
joi.object({
|
|
5
|
+
pair: joi.object({
|
|
6
|
+
baseTokenName: joi.string().min(1).required(),
|
|
7
|
+
quoteTokenName: joi.string().min(1).required(),
|
|
8
|
+
baseToken: joi.string().min(1).required(),
|
|
9
|
+
quoteToken: joi.string().min(1).required(),
|
|
10
|
+
baseTokenDecimals: joi.number().min(1).required(),
|
|
11
|
+
quoteTokenDecimals: joi.number().min(1).required(),
|
|
12
|
+
}),
|
|
13
|
+
levels: joi.array().items(
|
|
14
|
+
joi.object({
|
|
15
|
+
level: joi.string().min(1).required(),
|
|
16
|
+
price: joi.string().min(1).required(),
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
includesFees: joi.boolean().required(),
|
|
11
20
|
}),
|
|
12
|
-
|
|
13
|
-
level: joi.string().min(1).required(),
|
|
14
|
-
price: joi.string().min(1).required(),
|
|
15
|
-
})),
|
|
16
|
-
includesFees: joi.boolean().required(),
|
|
17
|
-
}));
|
|
21
|
+
);
|
|
18
22
|
|
|
19
23
|
export const pricesResponseValidator = joi.object({
|
|
20
24
|
status: joi.string().required(),
|
|
@@ -8,13 +8,13 @@ const FETCH_FAIL_MAX_ATTEMPT = 5;
|
|
|
8
8
|
const FETCH_FAIL_RETRY_TIMEOUT_MS = 60 * 1000;
|
|
9
9
|
|
|
10
10
|
export class SkippingRequest {
|
|
11
|
-
constructor(
|
|
12
|
-
|
|
13
|
-
) {}
|
|
14
|
-
};
|
|
11
|
+
constructor(public message = '') {}
|
|
12
|
+
}
|
|
15
13
|
|
|
16
14
|
export type RequestInfo<T> = {
|
|
17
|
-
requestFunc?: (
|
|
15
|
+
requestFunc?: (
|
|
16
|
+
options: RequestConfig,
|
|
17
|
+
) => Promise<Response<T> | SkippingRequest>;
|
|
18
18
|
requestOptions: RequestConfig;
|
|
19
19
|
caster: (data: unknown) => T;
|
|
20
20
|
authenticate?: (options: RequestConfig) => RequestConfig;
|
|
@@ -60,35 +60,35 @@ export class Fetcher<T> {
|
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const promises = this.requests.map<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
const promises = this.requests.map<
|
|
64
|
+
Promise<Error | Response<T> | SkippingRequest>
|
|
65
|
+
>(async (reqInfo: RequestInfoWithHandler<T>) => {
|
|
66
|
+
const info = reqInfo.info;
|
|
67
|
+
let options = info.requestOptions;
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (info.authenticate) {
|
|
70
|
+
info.authenticate(options);
|
|
71
|
+
}
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return result;
|
|
87
|
-
} catch (e) {
|
|
88
|
-
return e as Error;
|
|
73
|
+
try {
|
|
74
|
+
let result;
|
|
75
|
+
if (isFunction(info.requestFunc)) {
|
|
76
|
+
result = await info.requestFunc({
|
|
77
|
+
timeout: FETCH_TIMEOUT_MS,
|
|
78
|
+
...options,
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
result = await this.requestWrapper.request({
|
|
82
|
+
timeout: FETCH_TIMEOUT_MS,
|
|
83
|
+
...options,
|
|
84
|
+
});
|
|
89
85
|
}
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
} catch (e) {
|
|
89
|
+
return e as Error;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
92
|
const results = await Promise.all(promises);
|
|
93
93
|
const failures = results
|
|
94
94
|
.map((_, i) => i)
|
|
@@ -99,7 +99,7 @@ export class Fetcher<T> {
|
|
|
99
99
|
.filter(i => results[i] instanceof SkippingRequest);
|
|
100
100
|
|
|
101
101
|
results.map(result => {
|
|
102
|
-
if(!(result instanceof Error || result instanceof SkippingRequest)) {
|
|
102
|
+
if (!(result instanceof Error || result instanceof SkippingRequest)) {
|
|
103
103
|
this.logger.info(
|
|
104
104
|
'Results Data:',
|
|
105
105
|
JSON.stringify((result as any).data)
|
|
@@ -131,7 +131,12 @@ export class Fetcher<T> {
|
|
|
131
131
|
|
|
132
132
|
results
|
|
133
133
|
.map((_, i) => i)
|
|
134
|
-
.filter(
|
|
134
|
+
.filter(
|
|
135
|
+
i =>
|
|
136
|
+
!(
|
|
137
|
+
results[i] instanceof Error || results[i] instanceof SkippingRequest
|
|
138
|
+
),
|
|
139
|
+
)
|
|
135
140
|
.forEach(i => {
|
|
136
141
|
const response = results[i] as Response<T>;
|
|
137
142
|
const reqInfo = this.requests[i];
|
|
@@ -143,10 +148,10 @@ export class Fetcher<T> {
|
|
|
143
148
|
const parsedData = info.caster(response.data);
|
|
144
149
|
reqInfo.handler(parsedData);
|
|
145
150
|
} catch (e) {
|
|
146
|
-
this.logger.
|
|
151
|
+
this.logger.info(
|
|
147
152
|
`(${options.url}) received incorrect data ${JSON.stringify(
|
|
148
153
|
response.data,
|
|
149
|
-
)}`,
|
|
154
|
+
).replace(/(?:\r\n|\r|\n)/g, ' ')}`,
|
|
150
155
|
e,
|
|
151
156
|
);
|
|
152
157
|
return;
|
package/tests/constants-e2e.ts
CHANGED
|
@@ -695,6 +695,8 @@ export const Tokens: {
|
|
|
695
695
|
WETH: {
|
|
696
696
|
address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
|
|
697
697
|
decimals: 18,
|
|
698
|
+
addBalance: _balancesFn,
|
|
699
|
+
addAllowance: _allowancesFn,
|
|
698
700
|
},
|
|
699
701
|
ETH: { address: ETHER_ADDRESS, decimals: 18 },
|
|
700
702
|
USDC: {
|
|
@@ -704,6 +706,8 @@ export const Tokens: {
|
|
|
704
706
|
USDT: {
|
|
705
707
|
address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9',
|
|
706
708
|
decimals: 6,
|
|
709
|
+
addBalance: _balancesFn,
|
|
710
|
+
addAllowance: _allowancesFn,
|
|
707
711
|
},
|
|
708
712
|
FRAX: {
|
|
709
713
|
address: '0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F',
|