@paraswap/dex-lib 3.8.18 → 3.8.20-lite-psm

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 (171) hide show
  1. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  2. package/build/abi/inception/inception-ineth.json +609 -0
  3. package/build/abi/inception/inception-ratio-feed.json +93 -0
  4. package/build/abi/inception/inception-vault.json +991 -0
  5. package/build/abi/infusion/InfusionFactory.json +147 -0
  6. package/build/abi/infusion/InfusionPair.json +658 -0
  7. package/build/abi/infusion/InfusionRouter.json +442 -0
  8. package/build/abi/lite-psm/psm.json +468 -0
  9. package/build/abi/oswap/oswap.abi.json +452 -0
  10. package/build/dex/aave-v1/aave-v1.js +0 -1
  11. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  12. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  13. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  14. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  15. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  16. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  17. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  18. package/build/dex/idle-dao/scripts.d.ts +9 -0
  19. package/build/dex/idle-dao/scripts.js +552 -0
  20. package/build/dex/idle-dao/scripts.js.map +1 -0
  21. package/build/dex/inception/config.d.ts +5 -0
  22. package/build/dex/inception/config.js +112 -0
  23. package/build/dex/inception/config.js.map +1 -0
  24. package/build/dex/inception/inception-event-pool.d.ts +23 -0
  25. package/build/dex/inception/inception-event-pool.js +34 -0
  26. package/build/dex/inception/inception-event-pool.js.map +1 -0
  27. package/build/dex/inception/inception-native.d.ts +43 -0
  28. package/build/dex/inception/inception-native.js +131 -0
  29. package/build/dex/inception/inception-native.js.map +1 -0
  30. package/build/dex/inception/inception-pool.d.ts +18 -0
  31. package/build/dex/inception/inception-pool.js +32 -0
  32. package/build/dex/inception/inception-pool.js.map +1 -0
  33. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  34. package/build/dex/inception/inception-price-feed.js +51 -0
  35. package/build/dex/inception/inception-price-feed.js.map +1 -0
  36. package/build/dex/inception/inception.d.ts +44 -0
  37. package/build/dex/inception/inception.js +162 -0
  38. package/build/dex/inception/inception.js.map +1 -0
  39. package/build/dex/inception/tokens.d.ts +9 -0
  40. package/build/dex/inception/tokens.js +28 -0
  41. package/build/dex/inception/tokens.js.map +1 -0
  42. package/build/dex/inception/types.d.ts +22 -0
  43. package/build/dex/inception/types.js +3 -0
  44. package/build/dex/inception/types.js.map +1 -0
  45. package/build/dex/inception/utils.d.ts +7 -0
  46. package/build/dex/inception/utils.js +58 -0
  47. package/build/dex/inception/utils.js.map +1 -0
  48. package/build/dex/index.js +4 -0
  49. package/build/dex/index.js.map +1 -1
  50. package/build/dex/infusion/config.d.ts +4 -0
  51. package/build/dex/infusion/config.js +25 -0
  52. package/build/dex/infusion/config.js.map +1 -0
  53. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  54. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  55. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  56. package/build/dex/infusion/infusion.d.ts +54 -0
  57. package/build/dex/infusion/infusion.js +510 -0
  58. package/build/dex/infusion/infusion.js.map +1 -0
  59. package/build/dex/infusion/types.d.ts +47 -0
  60. package/build/dex/infusion/types.js +3 -0
  61. package/build/dex/infusion/types.js.map +1 -0
  62. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  63. package/build/dex/infusion/utils/isStablePair.js +18 -0
  64. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  65. package/build/dex/lite-psm/config.d.ts +3 -0
  66. package/build/dex/lite-psm/config.js +29 -0
  67. package/build/dex/lite-psm/config.js.map +1 -0
  68. package/build/dex/lite-psm/lite-psm-event-pool.d.ts +29 -0
  69. package/build/dex/lite-psm/lite-psm-event-pool.js +158 -0
  70. package/build/dex/lite-psm/lite-psm-event-pool.js.map +1 -0
  71. package/build/dex/lite-psm/lite-psm.d.ts +53 -0
  72. package/build/dex/lite-psm/lite-psm.js +365 -0
  73. package/build/dex/lite-psm/lite-psm.js.map +1 -0
  74. package/build/dex/lite-psm/types.d.ts +40 -0
  75. package/build/dex/lite-psm/types.js +3 -0
  76. package/build/dex/lite-psm/types.js.map +1 -0
  77. package/build/dex/maker-psm/maker-psm.js +3 -2
  78. package/build/dex/maker-psm/maker-psm.js.map +1 -1
  79. package/build/dex/oswap/config.d.ts +5 -0
  80. package/build/dex/oswap/config.js +31 -0
  81. package/build/dex/oswap/config.js.map +1 -0
  82. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  83. package/build/dex/oswap/oswap-pool.js +150 -0
  84. package/build/dex/oswap/oswap-pool.js.map +1 -0
  85. package/build/dex/oswap/oswap.d.ts +46 -0
  86. package/build/dex/oswap/oswap.js +273 -0
  87. package/build/dex/oswap/oswap.js.map +1 -0
  88. package/build/dex/oswap/types.d.ts +20 -0
  89. package/build/dex/oswap/types.js +3 -0
  90. package/build/dex/oswap/types.js.map +1 -0
  91. package/build/dex/platypus/platypus.js +3 -17
  92. package/build/dex/platypus/platypus.js.map +1 -1
  93. package/build/dex/swaap-v1/swaap-v1.js +0 -4
  94. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  95. package/build/dex/trader-joe-v2.1/config.d.ts +3 -0
  96. package/build/dex/trader-joe-v2.1/config.js +5 -1
  97. package/build/dex/trader-joe-v2.1/config.js.map +1 -1
  98. package/build/dex/trader-joe-v2.1/trader-joe-v2.1.d.ts +2 -14
  99. package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js +3 -85
  100. package/build/dex/trader-joe-v2.1/trader-joe-v2.1.js.map +1 -1
  101. package/package.json +1 -1
  102. package/src/abi/lite-psm/psm.json +468 -0
  103. package/src/dex/index.ts +4 -0
  104. package/src/dex/lite-psm/config.ts +29 -0
  105. package/src/dex/lite-psm/lite-psm-e2e.test.ts +79 -0
  106. package/src/dex/lite-psm/lite-psm-event-pool.ts +213 -0
  107. package/src/dex/lite-psm/lite-psm-events.test.ts +61 -0
  108. package/src/dex/lite-psm/lite-psm-integration.test.ts +96 -0
  109. package/src/dex/lite-psm/lite-psm.ts +578 -0
  110. package/src/dex/lite-psm/types.ts +46 -0
  111. package/src/dex/maker-psm/maker-psm.ts +3 -2
  112. package/src/dex/trader-joe-v2.1/base.ts +178 -0
  113. package/src/dex/trader-joe-v2.1/config.ts +5 -0
  114. package/src/dex/trader-joe-v2.1/trader-joe-v2.1.ts +8 -165
  115. package/src/dex/trader-joe-v2.1/trader-joe-v2.2.ts +23 -0
  116. package/.vscode/launch.json +0 -53
  117. package/.vscode/settings.json +0 -2
  118. package/.vscode/tasks.json +0 -15
  119. package/build/abi/maverick-v2/MaverickV2Router.json +0 -778
  120. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  121. package/build/abi/wombat/pool.json +0 -1289
  122. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  123. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  124. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  125. package/build/dex/bProtocol.d.ts +0 -18
  126. package/build/dex/bProtocol.js +0 -39
  127. package/build/dex/bProtocol.js.map +0 -1
  128. package/build/dex/bancor.d.ts +0 -26
  129. package/build/dex/bancor.js +0 -58
  130. package/build/dex/bancor.js.map +0 -1
  131. package/build/dex/compound.d.ts +0 -18
  132. package/build/dex/compound.js +0 -46
  133. package/build/dex/compound.js.map +0 -1
  134. package/build/dex/curve-v2.d.ts +0 -58
  135. package/build/dex/curve-v2.js +0 -180
  136. package/build/dex/curve-v2.js.map +0 -1
  137. package/build/dex/dodo-v1.d.ts +0 -33
  138. package/build/dex/dodo-v1.js +0 -63
  139. package/build/dex/dodo-v1.js.map +0 -1
  140. package/build/dex/lido.d.ts +0 -19
  141. package/build/dex/lido.js +0 -42
  142. package/build/dex/lido.js.map +0 -1
  143. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  144. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  145. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  146. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  147. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  148. package/build/dex/onebit.d.ts +0 -25
  149. package/build/dex/onebit.js +0 -42
  150. package/build/dex/onebit.js.map +0 -1
  151. package/build/dex/smoothy.d.ts +0 -26
  152. package/build/dex/smoothy.js +0 -48
  153. package/build/dex/smoothy.js.map +0 -1
  154. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  155. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  156. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  157. package/build/dex/stable-pool.d.ts +0 -28
  158. package/build/dex/stable-pool.js +0 -55
  159. package/build/dex/stable-pool.js.map +0 -1
  160. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  161. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  162. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  163. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  164. package/build/dex/trader-joe-v2.1.js +0 -79
  165. package/build/dex/trader-joe-v2.1.js.map +0 -1
  166. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  167. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  168. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  169. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  170. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  171. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
@@ -0,0 +1,79 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { testE2E } from '../../../tests/utils-e2e';
5
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
6
+ import { Network, ContractMethod, SwapSide } from '../../constants';
7
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
+ import { generateConfig } from '../../config';
9
+
10
+ describe('LitePsm E2E', () => {
11
+ const dexKey = 'LitePsm';
12
+
13
+ describe('LitePsm MAINNET_V6', () => {
14
+ const network = Network.MAINNET;
15
+ const tokens = Tokens[network];
16
+ const holders = Holders[network];
17
+ const provider = new StaticJsonRpcProvider(
18
+ generateConfig(network).privateHttpProvider,
19
+ network,
20
+ );
21
+
22
+ const tokenASymbol: string = 'USDC';
23
+ const tokenBSymbol: string = 'DAI';
24
+
25
+ const tokenAAmount: string = '10000000';
26
+ const tokenBAmount: string = '10000000000000000';
27
+
28
+ const sideToContractMethods = new Map([
29
+ [
30
+ SwapSide.SELL,
31
+ [
32
+ ContractMethod.swapExactAmountIn,
33
+ ContractMethod.swapExactAmountInOutOnMakerPSM,
34
+ ],
35
+ ],
36
+ [
37
+ SwapSide.BUY,
38
+ [
39
+ ContractMethod.swapExactAmountOut,
40
+ ContractMethod.swapExactAmountInOutOnMakerPSM,
41
+ ],
42
+ ],
43
+ ]);
44
+
45
+ sideToContractMethods.forEach((contractMethods, side) =>
46
+ contractMethods.forEach((contractMethod: ContractMethod) => {
47
+ describe(`${contractMethod}`, () => {
48
+ it(`${side}:${tokenASymbol} -> ${tokenBSymbol}`, async () => {
49
+ await testE2E(
50
+ tokens[tokenASymbol],
51
+ tokens[tokenBSymbol],
52
+ holders[tokenASymbol],
53
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
54
+ side,
55
+ dexKey,
56
+ contractMethod,
57
+ network,
58
+ provider,
59
+ );
60
+ });
61
+
62
+ it(`${side}:${tokenBSymbol} -> ${tokenASymbol}`, async () => {
63
+ await testE2E(
64
+ tokens[tokenBSymbol],
65
+ tokens[tokenASymbol],
66
+ holders[tokenBSymbol],
67
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
68
+ side,
69
+ dexKey,
70
+ contractMethod,
71
+ network,
72
+ provider,
73
+ );
74
+ });
75
+ });
76
+ }),
77
+ );
78
+ });
79
+ });
@@ -0,0 +1,213 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Contract } from 'web3-eth-contract';
4
+ import { Address, Log, Logger } from '../../types';
5
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
+ import { getBigIntPow } from '../../utils';
7
+ import { IDexHelper } from '../../dex-helper/idex-helper';
8
+ import { PoolState, PoolConfig } from './types';
9
+ import { LitePsmConfig } from './config';
10
+ import PsmABI from '../../abi/maker-psm/psm.json';
11
+ import VatABI from '../../abi/maker-psm/vat.json';
12
+ import { erc20Iface } from '../../lib/tokens/utils';
13
+
14
+ const vatInterface = new Interface(VatABI);
15
+ const psmInterface = new Interface(PsmABI);
16
+
17
+ const bigIntify = (b: any) => BigInt(b.toString());
18
+
19
+ export async function getOnChainState(
20
+ multiContract: Contract,
21
+ poolConfigs: PoolConfig[],
22
+ vatAddress: Address,
23
+ blockNumber: number | 'latest',
24
+ daiAddress: Address,
25
+ ): Promise<PoolState[]> {
26
+ const callData = poolConfigs
27
+ .map(c => [
28
+ {
29
+ target: c.psmAddress,
30
+ callData: psmInterface.encodeFunctionData('tin', []),
31
+ },
32
+ {
33
+ target: c.psmAddress,
34
+ callData: psmInterface.encodeFunctionData('tout', []),
35
+ },
36
+ {
37
+ target: vatAddress,
38
+ callData: vatInterface.encodeFunctionData('ilks', [c.identifier]),
39
+ },
40
+ // dai liquidity
41
+ // ceiling for `sellGem`
42
+ {
43
+ target: daiAddress,
44
+ callData: erc20Iface.encodeFunctionData('balanceOf', [c.psmAddress]),
45
+ },
46
+ // gem liquidity
47
+ // ceiling for `buyGem`
48
+ {
49
+ target: c.gem.address,
50
+ callData: erc20Iface.encodeFunctionData('balanceOf', [c.pocketAddress]),
51
+ },
52
+ ])
53
+ .flat();
54
+
55
+ const res = await multiContract.methods
56
+ .aggregate(callData)
57
+ .call({}, blockNumber);
58
+
59
+ let i = 0;
60
+ const result = poolConfigs.map(c => {
61
+ const tin = bigIntify(
62
+ psmInterface.decodeFunctionResult('tin', res.returnData[i++])[0],
63
+ );
64
+ const tout = bigIntify(
65
+ psmInterface.decodeFunctionResult('tout', res.returnData[i++])[0],
66
+ );
67
+ const ilks = vatInterface.decodeFunctionResult('ilks', res.returnData[i++]);
68
+ const rate = bigIntify(ilks.rate);
69
+ const daiBalance = bigIntify(
70
+ erc20Iface.decodeFunctionResult('balanceOf', res.returnData[i++])[0],
71
+ );
72
+ const gemBalance = bigIntify(
73
+ erc20Iface.decodeFunctionResult('balanceOf', res.returnData[i++])[0],
74
+ );
75
+ const response = {
76
+ tin,
77
+ tout,
78
+ daiBalance,
79
+ gemBalance,
80
+ rate,
81
+ };
82
+
83
+ return response;
84
+ });
85
+
86
+ return result;
87
+ }
88
+
89
+ export class LitePsmEventPool extends StatefulEventSubscriber<PoolState> {
90
+ handlers: {
91
+ [event: string]: (event: any, pool: PoolState, log: Log) => PoolState;
92
+ } = {};
93
+
94
+ logDecoder: (log: Log) => any;
95
+
96
+ to18ConversionFactor: bigint;
97
+ bytes32Tout =
98
+ '0x746f757400000000000000000000000000000000000000000000000000000000'; // bytes32('tout')
99
+ bytes32Tin =
100
+ '0x74696e0000000000000000000000000000000000000000000000000000000000'; // bytes32('tin')
101
+
102
+ daiAddress: Address;
103
+
104
+ constructor(
105
+ parentName: string,
106
+ protected network: number,
107
+ protected dexHelper: IDexHelper,
108
+ logger: Logger,
109
+ public poolConfig: PoolConfig,
110
+ protected vatAddress: Address,
111
+ ) {
112
+ super(parentName, poolConfig.identifier, dexHelper, logger);
113
+
114
+ this.daiAddress =
115
+ LitePsmConfig[this.parentName][this.network].dai.address.toLowerCase();
116
+ this.logDecoder = (log: Log) => {
117
+ const logAddress = log.address.toLowerCase();
118
+ if (
119
+ logAddress === this.daiAddress ||
120
+ logAddress === this.poolConfig.gem.address
121
+ ) {
122
+ return erc20Iface.parseLog(log);
123
+ } else {
124
+ return psmInterface.parseLog(log);
125
+ }
126
+ };
127
+ this.addressesSubscribed = [
128
+ poolConfig.psmAddress,
129
+ this.daiAddress,
130
+ this.poolConfig.gem.address,
131
+ ];
132
+ this.to18ConversionFactor = getBigIntPow(18 - poolConfig.gem.decimals);
133
+
134
+ // Add handlers
135
+ this.handlers['File'] = this.handleFile.bind(this);
136
+ this.handlers['Transfer'] = this.handleTransfer.bind(this);
137
+ }
138
+
139
+ handleFile(event: any, pool: PoolState, log: Log): PoolState {
140
+ if (event.args.what === this.bytes32Tin) {
141
+ pool.tin = bigIntify(event.args.data);
142
+ } else if (event.args.what === this.bytes32Tout) {
143
+ pool.tout = bigIntify(event.args.data);
144
+ }
145
+ return pool;
146
+ }
147
+
148
+ handleTransfer(event: any, pool: PoolState, log: Log): PoolState {
149
+ if (log.address.toLowerCase() === this.daiAddress) {
150
+ return this.handleTransferDAI(event, pool, log);
151
+ } else if (log.address.toLowerCase() === this.poolConfig.gem.address) {
152
+ return this.handleTransferGEM(event, pool, log);
153
+ }
154
+ return pool;
155
+ }
156
+
157
+ handleTransferDAI(event: any, pool: PoolState, log: Log): PoolState {
158
+ if (event.args?.from?.toLowerCase() === this.poolConfig.psmAddress) {
159
+ pool.daiBalance -= bigIntify(event.args.value);
160
+ } else if (event.args?.to?.toLowerCase() === this.poolConfig.psmAddress) {
161
+ pool.daiBalance += bigIntify(event.args.value);
162
+ }
163
+ return pool;
164
+ }
165
+
166
+ handleTransferGEM(event: any, pool: PoolState, log: Log): PoolState {
167
+ if (event.args?.from?.toLowerCase() === this.poolConfig.pocketAddress) {
168
+ pool.gemBalance -= bigIntify(event.args.value);
169
+ } else if (
170
+ event.args?.to?.toLowerCase() === this.poolConfig.pocketAddress
171
+ ) {
172
+ pool.gemBalance += bigIntify(event.args.value);
173
+ }
174
+ return pool;
175
+ }
176
+
177
+ getIdentifier(): string {
178
+ return `${this.parentName}_${this.poolConfig.psmAddress}`.toLowerCase();
179
+ }
180
+
181
+ protected processLog(
182
+ state: DeepReadonly<PoolState>,
183
+ log: Readonly<Log>,
184
+ ): DeepReadonly<PoolState> | null {
185
+ try {
186
+ const event = this.logDecoder(log);
187
+ if (event.name in this.handlers) {
188
+ return this.handlers[event.name](event, state, log);
189
+ }
190
+ return state;
191
+ } catch (e) {
192
+ this.logger.error(
193
+ `Error_${this.parentName}_processLog could not parse the log with topic ${log.topics}:`,
194
+ e,
195
+ );
196
+ return null;
197
+ }
198
+ }
199
+
200
+ async generateState(
201
+ blockNumber: number | 'latest',
202
+ ): Promise<Readonly<PoolState>> {
203
+ return (
204
+ await getOnChainState(
205
+ this.dexHelper.multiContract,
206
+ [this.poolConfig],
207
+ this.vatAddress,
208
+ blockNumber,
209
+ this.daiAddress,
210
+ )
211
+ )[0];
212
+ }
213
+ }
@@ -0,0 +1,61 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { LitePsmEventPool } from './lite-psm-event-pool';
5
+ import { LitePsmConfig } from './config';
6
+ import { Network } from '../../constants';
7
+ import { DummyDexHelper } from '../../dex-helper/index';
8
+ import { testEventSubscriber } from '../../../tests/utils-events';
9
+ import { PoolState } from './types';
10
+
11
+ jest.setTimeout(50 * 1000);
12
+ const dexKey = 'LitePsm';
13
+ const network = Network.MAINNET;
14
+ const config = LitePsmConfig[dexKey][network];
15
+
16
+ function fetchPoolState(
17
+ makerPsmPool: LitePsmEventPool,
18
+ blockNumber: number,
19
+ ): Promise<PoolState> {
20
+ return makerPsmPool.generateState(blockNumber);
21
+ }
22
+
23
+ describe('LitePsm Event', function () {
24
+ const blockNumbers: { [eventName: string]: number[] } = {
25
+ // File: [], // never happened
26
+ SellGem: [20559136, 20559876, 20561086, 20563099, 20563672, 20563887],
27
+ BuyGem: [
28
+ 20554181, 20555354, 20555452, 20555880, 20556086, 20556431, 20558791,
29
+ ],
30
+ };
31
+
32
+ describe('LitePsmEventPool', function () {
33
+ Object.keys(blockNumbers).forEach((event: string) => {
34
+ blockNumbers[event].forEach((blockNumber: number) => {
35
+ it(`Should return the correct state after the ${blockNumber}:${event}`, async function () {
36
+ const dexHelper = new DummyDexHelper(network);
37
+ const logger = dexHelper.getLogger(dexKey);
38
+
39
+ const makerPsmPool = new LitePsmEventPool(
40
+ dexKey,
41
+ network,
42
+ dexHelper,
43
+ logger,
44
+ config.pools[0],
45
+ config.vatAddress,
46
+ );
47
+
48
+ await testEventSubscriber(
49
+ makerPsmPool,
50
+ makerPsmPool.addressesSubscribed,
51
+ (_blockNumber: number) =>
52
+ fetchPoolState(makerPsmPool, _blockNumber),
53
+ blockNumber,
54
+ `${dexKey}_${config.pools[0].psmAddress}`,
55
+ dexHelper.provider,
56
+ );
57
+ });
58
+ });
59
+ });
60
+ });
61
+ });
@@ -0,0 +1,96 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { DummyDexHelper } from '../../dex-helper/index';
5
+ import { Network, SwapSide } from '../../constants';
6
+ import { LitePsm } from './lite-psm';
7
+ import { checkPoolPrices, checkPoolsLiquidity } from '../../../tests/utils';
8
+ import { Tokens } from '../../../tests/constants-e2e';
9
+ import { BI_POWS } from '../../bigint-constants';
10
+
11
+ const network = Network.MAINNET;
12
+ const TokenASymbol = 'USDC';
13
+ const TokenA = Tokens[network][TokenASymbol];
14
+
15
+ const TokenBSymbol = 'DAI';
16
+ const TokenB = Tokens[network][TokenBSymbol];
17
+
18
+ const tokenAAmounts = [0n, BI_POWS[8], 200000000n];
19
+
20
+ const tokenBAmounts = [0n, BI_POWS[18], 2000000000000000000n];
21
+
22
+ const dexKey = 'LitePsm';
23
+
24
+ describe('LitePsm', function () {
25
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
26
+ const dexHelper = new DummyDexHelper(network);
27
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
28
+ const litePsm = new LitePsm(network, dexKey, dexHelper);
29
+
30
+ await litePsm.initializePricing(blocknumber);
31
+
32
+ const pools = await litePsm.getPoolIdentifiers(
33
+ TokenA,
34
+ TokenB,
35
+ SwapSide.SELL,
36
+ blocknumber,
37
+ );
38
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
39
+
40
+ expect(pools.length).toBeGreaterThan(0);
41
+
42
+ const poolPrices = await litePsm.getPricesVolume(
43
+ TokenA,
44
+ TokenB,
45
+ tokenAAmounts,
46
+ SwapSide.SELL,
47
+ blocknumber,
48
+ pools,
49
+ );
50
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
51
+
52
+ expect(poolPrices).not.toBeNull();
53
+ checkPoolPrices(poolPrices!, tokenAAmounts, SwapSide.SELL, dexKey);
54
+ });
55
+
56
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
57
+ const dexHelper = new DummyDexHelper(network);
58
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
59
+ const litePsm = new LitePsm(network, dexKey, dexHelper);
60
+
61
+ await litePsm.initializePricing(blocknumber);
62
+
63
+ const pools = await litePsm.getPoolIdentifiers(
64
+ TokenA,
65
+ TokenB,
66
+ SwapSide.BUY,
67
+ blocknumber,
68
+ );
69
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `, pools);
70
+
71
+ expect(pools.length).toBeGreaterThan(0);
72
+
73
+ const poolPrices = await litePsm.getPricesVolume(
74
+ TokenA,
75
+ TokenB,
76
+ tokenBAmounts,
77
+ SwapSide.BUY,
78
+ blocknumber,
79
+ pools,
80
+ );
81
+ console.log(`${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `, poolPrices);
82
+
83
+ expect(poolPrices).not.toBeNull();
84
+ checkPoolPrices(poolPrices!, tokenBAmounts, SwapSide.BUY, dexKey);
85
+ });
86
+
87
+ it('getTopPoolsForToken', async function () {
88
+ const dexHelper = new DummyDexHelper(network);
89
+ const litePsm = new LitePsm(network, dexKey, dexHelper);
90
+
91
+ const poolLiquidity = await litePsm.getTopPoolsForToken(TokenA.address, 10);
92
+ console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
93
+
94
+ checkPoolsLiquidity(poolLiquidity, TokenA.address, dexKey);
95
+ });
96
+ });