@paraswap/dex-lib 2.21.2 → 2.22.0

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.
Files changed (40) hide show
  1. package/.idea/aws.xml +17 -0
  2. package/.idea/codeStyles/Project.xml +19 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/misc.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/paraswap-dex-lib.iml +9 -0
  7. package/.idea/vcs.xml +6 -0
  8. package/build/dex/index.js +2 -0
  9. package/build/dex/index.js.map +1 -1
  10. package/build/dex/pancakeswap-v3/types.d.ts +14 -0
  11. package/build/dex/{test-dex → pancakeswap-v3}/types.js.map +1 -1
  12. package/build/dex/solidly/config.js +13 -0
  13. package/build/dex/solidly/config.js.map +1 -1
  14. package/build/dex/solidly/forks-override/chronos.d.ts +23 -0
  15. package/build/dex/solidly/forks-override/chronos.js +132 -0
  16. package/build/dex/solidly/forks-override/chronos.js.map +1 -0
  17. package/build/dex/solidly/solidly.js +1 -0
  18. package/build/dex/solidly/solidly.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/dex/index.ts +2 -0
  21. package/src/dex/solidly/config.ts +14 -0
  22. package/src/dex/solidly/forks-override/chronos.ts +206 -0
  23. package/src/dex/solidly/solidly-e2e.test.ts +105 -0
  24. package/src/dex/solidly/solidly-integration.test.ts +141 -0
  25. package/src/dex/solidly/solidly.ts +1 -0
  26. package/tests/constants-e2e.ts +5 -0
  27. package/build/dex/test-dex/config.d.ts +0 -4
  28. package/build/dex/test-dex/config.js +0 -15
  29. package/build/dex/test-dex/config.js.map +0 -1
  30. package/build/dex/test-dex/test-dex-pool.d.ts +0 -39
  31. package/build/dex/test-dex/test-dex-pool.js +0 -63
  32. package/build/dex/test-dex/test-dex-pool.js.map +0 -1
  33. package/build/dex/test-dex/test-dex.d.ts +0 -37
  34. package/build/dex/test-dex/test-dex.js +0 -126
  35. package/build/dex/test-dex/test-dex.js.map +0 -1
  36. package/build/dex/test-dex/types.d.ts +0 -6
  37. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +0 -16
  38. package/build/dex/woo-fi-v2/woo-fi-math.js +0 -137
  39. package/build/dex/woo-fi-v2/woo-fi-math.js.map +0 -1
  40. /package/build/dex/{test-dex → pancakeswap-v3}/types.js +0 -0
@@ -0,0 +1,206 @@
1
+ import { Solidly } from '../solidly';
2
+ import { SolidlyPair } from '../types';
3
+ import { Network, SUBGRAPH_TIMEOUT } from '../../../constants';
4
+ import { IDexHelper } from '../../../dex-helper';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import { getDexKeysWithNetwork } from '../../../utils';
7
+ import { SolidlyConfig } from '../config';
8
+ import _ from 'lodash';
9
+ import { Address, PoolLiquidity } from '../../../types';
10
+ import BigNumber from 'bignumber.js';
11
+
12
+ const ChronosFactoryABI = [
13
+ {
14
+ inputs: [{ internalType: 'bool', name: '_stable', type: 'bool' }],
15
+ name: 'getFee',
16
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
17
+ stateMutability: 'view',
18
+ type: 'function',
19
+ },
20
+ ];
21
+
22
+ const chronosFactoryIface = new Interface(ChronosFactoryABI);
23
+
24
+ type ChronosSubgraphPool = {
25
+ id: string;
26
+ isStable: boolean;
27
+ token0: { id: string; decimals: string };
28
+ reserve0: string;
29
+ reserve1: string;
30
+ token1: { id: string; decimals: string; };
31
+ };
32
+
33
+ export class Chronos extends Solidly {
34
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
35
+ getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Chronos']));
36
+
37
+ constructor(
38
+ protected network: Network,
39
+ dexKey: string,
40
+ protected dexHelper: IDexHelper,
41
+ ) {
42
+ super(
43
+ network,
44
+ dexKey,
45
+ dexHelper,
46
+ true, // dynamic fees
47
+ );
48
+ }
49
+
50
+ protected getFeesMultiCallData(pair: SolidlyPair) {
51
+ const callEntry = {
52
+ target: this.factoryAddress,
53
+ callData: chronosFactoryIface.encodeFunctionData('getFee', [pair.stable]),
54
+ };
55
+ const callDecoder = (values: any[]) =>
56
+ parseInt(
57
+ chronosFactoryIface
58
+ .decodeFunctionResult('getFee', values)[0]
59
+ .toString(),
60
+ );
61
+
62
+ return {
63
+ callEntry,
64
+ callDecoder,
65
+ };
66
+ }
67
+
68
+ async getTopPoolsForToken(
69
+ tokenAddress: Address,
70
+ count: number,
71
+ ): Promise<PoolLiquidity[]> {
72
+ if (!this.subgraphURL) return [];
73
+
74
+ const query = `query ($token: Bytes!, $count: Int) {
75
+ pools0: pairs(first: $count, orderBy: reserve0, orderDirection: desc, where: {token0: $token, reserve0_gt: 1, reserve1_gt: 1}) {
76
+ id
77
+ isStable
78
+ token0 {
79
+ id
80
+ decimals
81
+ }
82
+ token1 {
83
+ id
84
+ decimals
85
+ }
86
+ reserve0,
87
+ reserve1,
88
+ }
89
+ pools1: pairs(first: $count, orderBy: reserve1, orderDirection: desc, where: {token1: $token, reserve0_gt: 1, reserve1_gt: 1}) {
90
+ id
91
+ isStable
92
+ token0 {
93
+ id
94
+ decimals
95
+ }
96
+ token1 {
97
+ id
98
+ decimals
99
+ },
100
+ reserve0,
101
+ reserve1,
102
+ }
103
+ }`;
104
+
105
+ const { data } = await this.dexHelper.httpRequest.post(
106
+ this.subgraphURL,
107
+ {
108
+ query,
109
+ variables: { token: tokenAddress.toLowerCase(), count },
110
+ },
111
+ SUBGRAPH_TIMEOUT,
112
+ );
113
+
114
+ if (!(data && data.pools0 && data.pools1))
115
+ throw new Error("Couldn't fetch the pools from the subgraph");
116
+
117
+ const pools0 = await this.prepareSubgraphPools(data.pools0, (pool,{
118
+ address1, decimals1, liquidityUSDToken0, liquidityUSDToken1,
119
+ }) => ({
120
+ exchange: this.dexKey,
121
+ stable: pool.isStable,
122
+ address: pool.id.toLowerCase(),
123
+ connectorTokens: [
124
+ {
125
+ address: address1,
126
+ decimals: decimals1,
127
+ },
128
+ ],
129
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
130
+ }));
131
+
132
+ const pools1 = await this.prepareSubgraphPools(data.pools1, (pool,{
133
+ address0, decimals0, liquidityUSDToken0, liquidityUSDToken1,
134
+ }) => ({
135
+ exchange: this.dexKey,
136
+ stable: pool.isStable,
137
+ address: pool.id.toLowerCase(),
138
+ connectorTokens: [
139
+ {
140
+ address: address0,
141
+ decimals: decimals0,
142
+ },
143
+ ],
144
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
145
+ }));
146
+
147
+ return _.slice(
148
+ _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
149
+ 0,
150
+ count,
151
+ );
152
+ }
153
+
154
+ private async prepareSubgraphPools(
155
+ pools: ChronosSubgraphPool[],
156
+ iterator: (
157
+ pool: ChronosSubgraphPool, {
158
+ address0,
159
+ address1,
160
+ decimals0,
161
+ decimals1,
162
+ reserve0,
163
+ reserve1,
164
+ liquidityUSDToken0,
165
+ liquidityUSDToken1,
166
+ }: {
167
+ address0: string,
168
+ address1: string,
169
+ decimals0: number,
170
+ decimals1: number,
171
+ reserve0: bigint,
172
+ reserve1: bigint,
173
+ liquidityUSDToken0: number,
174
+ liquidityUSDToken1: number,
175
+ }) => PoolLiquidity
176
+ ): Promise<PoolLiquidity[]> {
177
+ return Promise.all(pools.map(async (
178
+ pool: ChronosSubgraphPool,
179
+ ) => {
180
+ const address0 = pool.token0.id.toLowerCase();
181
+ const address1 = pool.token1.id.toLowerCase();
182
+
183
+ const decimals0 = parseInt(pool.token0.decimals);
184
+ const decimals1 = parseInt(pool.token1.decimals);
185
+
186
+ const reserve0 = BigInt(new BigNumber(pool.reserve0).multipliedBy(10 ** decimals0).toFixed());
187
+ const reserve1 = BigInt(new BigNumber(pool.reserve1).multipliedBy(10 ** decimals1).toFixed());
188
+
189
+ const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice({
190
+ address: address0,
191
+ decimals: decimals0,
192
+ }, reserve0);
193
+
194
+ const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice({
195
+ address: address1,
196
+ decimals: decimals1,
197
+ }, reserve1);
198
+
199
+ return iterator(
200
+ pool, {
201
+ address0, address1, decimals0, decimals1, reserve0, reserve1, liquidityUSDToken0, liquidityUSDToken1,
202
+ },
203
+ );
204
+ }));
205
+ }
206
+ }
@@ -1075,4 +1075,109 @@ describe('Solidly E2E', () => {
1075
1075
  });
1076
1076
  });
1077
1077
  });
1078
+
1079
+ describe('Arbitrum', () => {
1080
+ const network = Network.ARBITRUM;
1081
+ const tokens = Tokens[network];
1082
+ const holders = Holders[network];
1083
+ const provider = new StaticJsonRpcProvider(
1084
+ generateConfig(network).privateHttpProvider,
1085
+ network,
1086
+ );
1087
+
1088
+ describe(`Chronos`, () => {
1089
+ const dexKey = 'Chronos';
1090
+
1091
+ const sideToContractMethods = new Map([
1092
+ [
1093
+ SwapSide.SELL,
1094
+ [
1095
+ ContractMethod.simpleSwap,
1096
+ ContractMethod.multiSwap,
1097
+ ContractMethod.megaSwap,
1098
+ ],
1099
+ ],
1100
+ ]);
1101
+
1102
+ const pairs: { name: string; sellAmount: string }[][] = [
1103
+ [
1104
+ {
1105
+ name: 'ETH',
1106
+ sellAmount: '1000000000000000000',
1107
+ },
1108
+ {
1109
+ name: 'USDC',
1110
+ sellAmount: '100000000',
1111
+ },
1112
+ ],
1113
+ [
1114
+ {
1115
+ name: 'USDT',
1116
+ sellAmount: '100000000',
1117
+ },
1118
+ {
1119
+ name: 'USDC',
1120
+ sellAmount: '100000000',
1121
+ },
1122
+ ],
1123
+ [
1124
+ {
1125
+ name: 'USDC',
1126
+ sellAmount: '100000000',
1127
+ },
1128
+ {
1129
+ name: 'DAI',
1130
+ sellAmount: '100000000000000000000',
1131
+ },
1132
+ ],
1133
+ [
1134
+ {
1135
+ name: 'ARB',
1136
+ sellAmount: '100000000',
1137
+ },
1138
+ {
1139
+ name: 'ETH',
1140
+ sellAmount: '100000000000000000000',
1141
+ },
1142
+ ],
1143
+ ];
1144
+
1145
+ sideToContractMethods.forEach((contractMethods, side) =>
1146
+ describe(`${side}`, () => {
1147
+ contractMethods.forEach((contractMethod: ContractMethod) => {
1148
+ pairs.forEach(pair => {
1149
+ describe(`${contractMethod}`, () => {
1150
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
1151
+ await testE2E(
1152
+ tokens[pair[0].name],
1153
+ tokens[pair[1].name],
1154
+ holders[pair[0].name],
1155
+ pair[0].sellAmount,
1156
+ side,
1157
+ dexKey,
1158
+ contractMethod,
1159
+ network,
1160
+ provider,
1161
+ );
1162
+ });
1163
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
1164
+ await testE2E(
1165
+ tokens[pair[1].name],
1166
+ tokens[pair[0].name],
1167
+ holders[pair[1].name],
1168
+ pair[1].sellAmount,
1169
+ side,
1170
+ dexKey,
1171
+ contractMethod,
1172
+ network,
1173
+ provider,
1174
+ );
1175
+ });
1176
+ });
1177
+ });
1178
+ });
1179
+ }),
1180
+ );
1181
+ });
1182
+ });
1078
1183
  });
@@ -11,6 +11,7 @@ import { Interface, Result } from '@ethersproject/abi';
11
11
  import solidlyPairABI from '../../abi/solidly/SolidlyPair.json';
12
12
  import { SpiritSwapV2 } from './forks-override/spiritSwapV2';
13
13
  import { Cone } from './forks-override/cone';
14
+ import { Chronos } from './forks-override/chronos';
14
15
 
15
16
  const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
16
17
  const amounts6 = [0n, BI_POWS[6], 2000000n];
@@ -628,4 +629,144 @@ describe('Solidly integration tests', () => {
628
629
  });
629
630
  });
630
631
  });
632
+
633
+ describe('Arbitrum', () => {
634
+ const network = Network.ARBITRUM;
635
+ const dexHelper = new DummyDexHelper(network);
636
+ const checkOnChainPricing = constructCheckOnChainPricing(dexHelper);
637
+
638
+ describe('Chronos', function () {
639
+ const dexKey = 'Chronos';
640
+ const chronos = new Chronos(network, dexKey, dexHelper);
641
+
642
+ describe('UniswapV2 like pool', function () {
643
+ const TokenASymbol = 'USDC';
644
+ const tokenA = Tokens[network][TokenASymbol];
645
+ const TokenBSymbol = 'WETH';
646
+ const tokenB = Tokens[network][TokenBSymbol];
647
+
648
+ const amounts = amounts18;
649
+
650
+ it('getPoolIdentifiers and getPricesVolume', async function () {
651
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
652
+ const pools = await chronos.getPoolIdentifiers(
653
+ tokenA,
654
+ tokenB,
655
+ SwapSide.SELL,
656
+ blocknumber,
657
+ );
658
+ console.log(
659
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
660
+ pools,
661
+ );
662
+
663
+ expect(pools.length).toBeGreaterThan(0);
664
+
665
+ const poolPrices = await chronos.getPricesVolume(
666
+ tokenA,
667
+ tokenB,
668
+ amounts,
669
+ SwapSide.SELL,
670
+ blocknumber,
671
+ pools,
672
+ );
673
+ console.log(
674
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
675
+ poolPrices,
676
+ );
677
+
678
+ expect(poolPrices).not.toBeNull();
679
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
680
+
681
+ // Check if onchain pricing equals to calculated ones
682
+
683
+ for (const i in poolPrices || []) {
684
+ await checkOnChainPricing(
685
+ chronos,
686
+ 'getAmountOut',
687
+ blocknumber,
688
+ poolPrices![i].prices,
689
+ poolPrices![i].poolAddresses![0],
690
+ tokenA.address,
691
+ amounts,
692
+ );
693
+ }
694
+ });
695
+
696
+ it('getTopPoolsForToken', async function () {
697
+ const poolLiquidity = await chronos.getTopPoolsForToken(
698
+ tokenA.address,
699
+ 10,
700
+ );
701
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
702
+
703
+ checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
704
+ });
705
+ });
706
+
707
+ describe('Curve like stable pool', function () {
708
+ const TokenASymbol = 'USDT';
709
+ const tokenA = Tokens[network][TokenASymbol];
710
+ const TokenBSymbol = 'USDC';
711
+ const tokenB = Tokens[network][TokenBSymbol];
712
+
713
+ const amounts = amounts6;
714
+
715
+ it('getPoolIdentifiers and getPricesVolume', async function () {
716
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
717
+ const pools = await chronos.getPoolIdentifiers(
718
+ tokenA,
719
+ tokenB,
720
+ SwapSide.SELL,
721
+ blocknumber,
722
+ );
723
+ console.log(
724
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
725
+ pools,
726
+ );
727
+
728
+ expect(pools.length).toBeGreaterThan(0);
729
+
730
+ const poolPrices = await chronos.getPricesVolume(
731
+ tokenA,
732
+ tokenB,
733
+ amounts,
734
+ SwapSide.SELL,
735
+ blocknumber,
736
+ pools,
737
+ );
738
+ console.log(
739
+ `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
740
+ poolPrices,
741
+ );
742
+
743
+ expect(poolPrices).not.toBeNull();
744
+ checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
745
+
746
+ // Check if onchain pricing equals to calculated ones
747
+ for (const i in poolPrices || []) {
748
+ await checkOnChainPricing(
749
+ chronos,
750
+ 'getAmountOut',
751
+ blocknumber,
752
+ poolPrices![i].prices,
753
+ poolPrices![i].poolAddresses![0],
754
+ tokenA.address,
755
+ amounts,
756
+ );
757
+ }
758
+ });
759
+
760
+ it('getTopPoolsForToken', async function () {
761
+ const poolLiquidity = await chronos.getTopPoolsForToken(
762
+ tokenA.address,
763
+ 10,
764
+ );
765
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
766
+
767
+ checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
768
+ });
769
+ });
770
+ });
771
+ });
631
772
  });
@@ -71,6 +71,7 @@ export class Solidly extends UniswapV2 {
71
71
  'SolidlyV2',
72
72
  'Thena',
73
73
  'SoliSnek',
74
+ 'Chronos',
74
75
  ]),
75
76
  );
76
77
 
@@ -704,6 +704,10 @@ export const Tokens: {
704
704
  address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
705
705
  decimals: 18,
706
706
  },
707
+ ARB: {
708
+ address: '0x912ce59144191c1204e64559fe8253a0e49e6548',
709
+ decimals: 18,
710
+ },
707
711
  WETH: {
708
712
  address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
709
713
  decimals: 18,
@@ -987,6 +991,7 @@ export const Holders: {
987
991
  YUSD: '0x6c1a5ef2acde1fd2fc68def440d2c1eb35bae24a',
988
992
  },
989
993
  [Network.ARBITRUM]: {
994
+ ARB: '0xb65edba80a3d81903ecd499c8eb9cf0e19096bd0',
990
995
  ETH: '0xF977814e90dA44bFA03b6295A0616a897441aceC',
991
996
  DAI: '0x07d7f291e731a41d3f0ea4f1ae5b6d920ffb3fe0',
992
997
  WETH: '0xc31e54c7a869b9fcbecc14363cf510d1c41fa443',
@@ -1,4 +0,0 @@
1
- import { DexParams } from './types';
2
- import { DexConfigMap, AdapterMappings } from '../../types';
3
- export declare const TestDexConfig: DexConfigMap<DexParams>;
4
- export declare const Adapters: Record<number, AdapterMappings>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Adapters = exports.TestDexConfig = void 0;
4
- const constants_1 = require("../../constants");
5
- exports.TestDexConfig = {
6
- TestDex: {
7
- // TODO: complete me!
8
- },
9
- };
10
- exports.Adapters = {
11
- // TODO: add adapters for each chain
12
- // This is an example to copy
13
- [constants_1.Network.MAINNET]: { [constants_1.SwapSide.SELL]: [{ name: '', index: 0 }] },
14
- };
15
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/test-dex/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,aAAa,GAA4B;IACpD,OAAO,EAAE;IACP,qBAAqB;KACtB;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC;IACvD,oCAAoC;IACpC,6BAA6B;IAC7B,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE;CACjE,CAAC"}
@@ -1,39 +0,0 @@
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 TestDexEventPool extends StatefulEventSubscriber<PoolState> {
8
- protected parentName: string;
9
- protected network: number;
10
- protected dexHelper: IDexHelper;
11
- protected testDexIface: 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, testDexIface?: 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
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestDexEventPool = 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 TestDexEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
8
- constructor(parentName, network, dexHelper, logger, testDexIface = new abi_1.Interface('' /* TODO: Import and put here TestDex ABI */)) {
9
- super(parentName, logger);
10
- this.parentName = parentName;
11
- this.network = network;
12
- this.dexHelper = dexHelper;
13
- this.testDexIface = testDexIface;
14
- this.handlers = {};
15
- // TODO: make logDecoder decode logs that
16
- this.logDecoder = (log) => this.testDexIface.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.TestDexEventPool = TestDexEventPool;
63
- //# sourceMappingURL=test-dex-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"test-dex-pool.js","sourceRoot":"","sources":["../../../src/dex/test-dex/test-dex-pool.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAI1E,MAAa,gBAAiB,SAAQ,mDAAkC;IAWtE,YACY,UAAkB,EAClB,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,eAAe,IAAI,eAAS,CACpC,EAAE,CAAC,2CAA2C,CAC/C;QAED,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QARhB,eAAU,GAAV,UAAU,CAAQ;QAClB,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAErB,iBAAY,GAAZ,YAAY,CAErB;QAjBH,aAAQ,GAIJ,EAAE,CAAC;QAiBL,yCAAyC;QACzC,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAChE,IAAI,CAAC,mBAAmB,GAAG;QACzB,0BAA0B;SAC3B,CAAC;QAEF,eAAe;QACf,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;OAQG;IACO,UAAU,CAClB,KAA8B,EAC9B,GAAkB;QAElB,IAAI;YACF,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;gBAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;aACrD;SACF;QAAC,OAAO,CAAC,EAAE;YACV,IAAA,0BAAkB,EAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SACpC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,qBAAqB;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,2BAA2B;IAC3B,aAAa,CACX,KAAU,EACV,KAA8B,EAC9B,GAAkB;QAElB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA/ED,4CA+EC"}
@@ -1,37 +0,0 @@
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 { TestDexData } from './types';
7
- import { SimpleExchange } from '../simple-exchange';
8
- import { TestDexEventPool } from './test-dex-pool';
9
- export declare class TestDex extends SimpleExchange implements IDex<TestDexData> {
10
- readonly network: Network;
11
- readonly dexKey: string;
12
- readonly dexHelper: IDexHelper;
13
- protected adapters: import("../../types").AdapterMappings;
14
- protected eventPools: TestDexEventPool;
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<TestDexData>>;
31
- getCalldataGasCost(poolPrices: PoolPrices<TestDexData>): number | number[];
32
- getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: TestDexData, side: SwapSide): AdapterExchangeParam;
33
- getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: TestDexData, side: SwapSide): Promise<SimpleExchangeParam>;
34
- updatePoolState(): Promise<void>;
35
- getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
36
- releaseResources(): AsyncOrSync<void>;
37
- }