@paraswap/dex-lib 3.10.3 → 3.11.0-bebop

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 (193) hide show
  1. package/build/abi/Aave_GSM.json +751 -0
  2. package/build/abi/USDM.json +807 -0
  3. package/build/abi/{integral/pool.json → cables/CablesMainnetRFQ.json} +563 -521
  4. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  5. package/build/abi/inception/inception-ineth.json +609 -0
  6. package/build/abi/inception/inception-ratio-feed.json +329 -0
  7. package/build/abi/inception/inception-vault.json +991 -0
  8. package/build/config.js +1 -0
  9. package/build/config.js.map +1 -1
  10. package/build/dex/aave-v1/aave-v1.d.ts +2 -1
  11. package/build/dex/aave-v1/aave-v1.js +22 -0
  12. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  13. package/build/dex/balancer-v2/config.js +1 -1
  14. package/build/dex/bebop/bebop.js +1 -1
  15. package/build/dex/bebop/bebop.js.map +1 -1
  16. package/build/dex/bebop/config.js +5 -0
  17. package/build/dex/bebop/config.js.map +1 -1
  18. package/build/dex/bebop/rate-fetcher.d.ts +3 -1
  19. package/build/dex/bebop/rate-fetcher.js +42 -2
  20. package/build/dex/bebop/rate-fetcher.js.map +1 -1
  21. package/build/dex/bebop/validators.d.ts +2 -0
  22. package/build/dex/bebop/validators.js +4 -1
  23. package/build/dex/bebop/validators.js.map +1 -1
  24. package/build/dex/bebop/websocket-fetcher.d.ts +35 -0
  25. package/build/dex/bebop/websocket-fetcher.js +87 -0
  26. package/build/dex/bebop/websocket-fetcher.js.map +1 -0
  27. package/build/dex/cables/cables.d.ts +57 -0
  28. package/build/dex/cables/cables.js +471 -0
  29. package/build/dex/cables/cables.js.map +1 -0
  30. package/build/dex/cables/config.d.ts +4 -0
  31. package/build/dex/cables/config.js +15 -0
  32. package/build/dex/cables/config.js.map +1 -0
  33. package/build/dex/cables/constants.d.ts +19 -0
  34. package/build/dex/cables/constants.js +26 -0
  35. package/build/dex/cables/constants.js.map +1 -0
  36. package/build/dex/cables/rate-fetcher.d.ts +34 -0
  37. package/build/dex/cables/rate-fetcher.js +106 -0
  38. package/build/dex/cables/rate-fetcher.js.map +1 -0
  39. package/build/dex/cables/types.d.ts +106 -0
  40. package/build/dex/cables/types.js +12 -0
  41. package/build/dex/cables/types.js.map +1 -0
  42. package/build/dex/cables/validators.d.ts +5 -0
  43. package/build/dex/cables/validators.js +49 -0
  44. package/build/dex/cables/validators.js.map +1 -0
  45. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  46. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  47. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  48. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  49. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  50. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  51. package/build/dex/idle-dao/scripts.d.ts +9 -0
  52. package/build/dex/idle-dao/scripts.js +552 -0
  53. package/build/dex/idle-dao/scripts.js.map +1 -0
  54. package/build/dex/inception/config.d.ts +4 -0
  55. package/build/dex/inception/config.js +109 -0
  56. package/build/dex/inception/config.js.map +1 -0
  57. package/build/dex/inception/inception-event-pool.d.ts +16 -0
  58. package/build/dex/inception/inception-event-pool.js +51 -0
  59. package/build/dex/inception/inception-event-pool.js.map +1 -0
  60. package/build/dex/{integral/integral.d.ts → inception/inception-native.d.ts} +21 -19
  61. package/build/dex/inception/inception-native.js +131 -0
  62. package/build/dex/inception/inception-native.js.map +1 -0
  63. package/build/dex/inception/inception-pool.d.ts +18 -0
  64. package/build/dex/inception/inception-pool.js +32 -0
  65. package/build/dex/inception/inception-pool.js.map +1 -0
  66. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  67. package/build/dex/inception/inception-price-feed.js +51 -0
  68. package/build/dex/inception/inception-price-feed.js.map +1 -0
  69. package/build/dex/inception/inception.d.ts +43 -0
  70. package/build/dex/inception/inception.js +204 -0
  71. package/build/dex/inception/inception.js.map +1 -0
  72. package/build/dex/inception/tokens.d.ts +9 -0
  73. package/build/dex/inception/tokens.js +28 -0
  74. package/build/dex/inception/tokens.js.map +1 -0
  75. package/build/dex/inception/types.d.ts +22 -0
  76. package/build/dex/inception/types.js +3 -0
  77. package/build/dex/inception/types.js.map +1 -0
  78. package/build/dex/inception/utils.d.ts +6 -0
  79. package/build/dex/inception/utils.js +37 -0
  80. package/build/dex/inception/utils.js.map +1 -0
  81. package/build/dex/jarvis.d.ts +2 -1
  82. package/build/dex/jarvis.js +58 -0
  83. package/build/dex/jarvis.js.map +1 -1
  84. package/build/dex/platypus/platypus.d.ts +2 -1
  85. package/build/dex/platypus/platypus.js +31 -0
  86. package/build/dex/platypus/platypus.js.map +1 -1
  87. package/build/dex/swaap-v1/swaap-v1.d.ts +2 -1
  88. package/build/dex/swaap-v1/swaap-v1.js +10 -0
  89. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  90. package/build/dex/zerox/index.d.ts +4 -26
  91. package/build/dex/zerox/index.js +50 -42
  92. package/build/dex/zerox/index.js.map +1 -1
  93. package/build/dex/zerox/types.d.ts +29 -0
  94. package/build/dex/zerox/types.js +8 -1
  95. package/build/dex/zerox/types.js.map +1 -1
  96. package/build/lib/fetcher/wsFetcher.d.ts +7 -3
  97. package/build/lib/fetcher/wsFetcher.js +64 -51
  98. package/build/lib/fetcher/wsFetcher.js.map +1 -1
  99. package/package.json +4 -2
  100. package/src/config.ts +1 -0
  101. package/src/dex/balancer-v2/config.ts +1 -1
  102. package/src/dex/bebop/bebop-e2e.test.ts +21 -0
  103. package/src/dex/bebop/bebop.proto +15 -0
  104. package/src/dex/bebop/bebop.ts +1 -1
  105. package/src/dex/bebop/config.ts +5 -0
  106. package/src/dex/bebop/rate-fetcher.ts +51 -6
  107. package/src/dex/bebop/validators.ts +4 -0
  108. package/src/lib/fetcher/wsFetcher.ts +79 -66
  109. package/.idea/aws.xml +0 -17
  110. package/.idea/codeStyles/Project.xml +0 -19
  111. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  112. package/.idea/misc.xml +0 -6
  113. package/.idea/modules.xml +0 -8
  114. package/.idea/paraswap-dex-lib.iml +0 -9
  115. package/.idea/prettier.xml +0 -7
  116. package/.idea/vcs.xml +0 -6
  117. package/build/abi/integral/factory.json +0 -333
  118. package/build/abi/integral/oracle.json +0 -501
  119. package/build/abi/integral/relayer.json +0 -1536
  120. package/build/dex/bProtocol.d.ts +0 -18
  121. package/build/dex/bProtocol.js +0 -39
  122. package/build/dex/bProtocol.js.map +0 -1
  123. package/build/dex/bancor.d.ts +0 -26
  124. package/build/dex/bancor.js +0 -58
  125. package/build/dex/bancor.js.map +0 -1
  126. package/build/dex/compound.d.ts +0 -18
  127. package/build/dex/compound.js +0 -46
  128. package/build/dex/compound.js.map +0 -1
  129. package/build/dex/curve-v2.d.ts +0 -58
  130. package/build/dex/curve-v2.js +0 -180
  131. package/build/dex/curve-v2.js.map +0 -1
  132. package/build/dex/dodo-v1.d.ts +0 -33
  133. package/build/dex/dodo-v1.js +0 -63
  134. package/build/dex/dodo-v1.js.map +0 -1
  135. package/build/dex/fluid-dex/fluid-dex-generate-pool.d.ts +0 -49
  136. package/build/dex/fluid-dex/fluid-dex-generate-pool.js +0 -104
  137. package/build/dex/fluid-dex/fluid-dex-generate-pool.js.map +0 -1
  138. package/build/dex/fluid-dex/fluid-dex-pool.d.ts +0 -47
  139. package/build/dex/fluid-dex/fluid-dex-pool.js +0 -119
  140. package/build/dex/fluid-dex/fluid-dex-pool.js.map +0 -1
  141. package/build/dex/integral/config.d.ts +0 -4
  142. package/build/dex/integral/config.js +0 -20
  143. package/build/dex/integral/config.js.map +0 -1
  144. package/build/dex/integral/context.d.ts +0 -40
  145. package/build/dex/integral/context.js +0 -158
  146. package/build/dex/integral/context.js.map +0 -1
  147. package/build/dex/integral/integral-factory.d.ts +0 -24
  148. package/build/dex/integral/integral-factory.js +0 -95
  149. package/build/dex/integral/integral-factory.js.map +0 -1
  150. package/build/dex/integral/integral-pool.d.ts +0 -50
  151. package/build/dex/integral/integral-pool.js +0 -149
  152. package/build/dex/integral/integral-pool.js.map +0 -1
  153. package/build/dex/integral/integral-pricing.d.ts +0 -18
  154. package/build/dex/integral/integral-pricing.js +0 -114
  155. package/build/dex/integral/integral-pricing.js.map +0 -1
  156. package/build/dex/integral/integral-relayer.d.ts +0 -42
  157. package/build/dex/integral/integral-relayer.js +0 -192
  158. package/build/dex/integral/integral-relayer.js.map +0 -1
  159. package/build/dex/integral/integral-token.d.ts +0 -27
  160. package/build/dex/integral/integral-token.js +0 -59
  161. package/build/dex/integral/integral-token.js.map +0 -1
  162. package/build/dex/integral/integral.js +0 -376
  163. package/build/dex/integral/integral.js.map +0 -1
  164. package/build/dex/integral/types.d.ts +0 -85
  165. package/build/dex/integral/types.js +0 -9
  166. package/build/dex/integral/types.js.map +0 -1
  167. package/build/dex/integral/utils-e2e.d.ts +0 -9
  168. package/build/dex/integral/utils-e2e.js +0 -131
  169. package/build/dex/integral/utils-e2e.js.map +0 -1
  170. package/build/dex/integral/utils.d.ts +0 -17
  171. package/build/dex/integral/utils.js +0 -94
  172. package/build/dex/integral/utils.js.map +0 -1
  173. package/build/dex/lido.d.ts +0 -19
  174. package/build/dex/lido.js +0 -42
  175. package/build/dex/lido.js.map +0 -1
  176. package/build/dex/onebit.d.ts +0 -25
  177. package/build/dex/onebit.js +0 -42
  178. package/build/dex/onebit.js.map +0 -1
  179. package/build/dex/smoothy.d.ts +0 -26
  180. package/build/dex/smoothy.js +0 -48
  181. package/build/dex/smoothy.js.map +0 -1
  182. package/build/dex/stable-pool.d.ts +0 -28
  183. package/build/dex/stable-pool.js +0 -62
  184. package/build/dex/stable-pool.js.map +0 -1
  185. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  186. package/build/dex/trader-joe-v2.1/optimizer.js +0 -47
  187. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  188. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  189. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  190. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  191. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  192. package/build/dex/trader-joe-v2.1.js +0 -79
  193. package/build/dex/trader-joe-v2.1.js.map +0 -1
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FluidDexCommonAddresses = void 0;
7
- const abi_1 = require("@ethersproject/abi");
8
- const utils_1 = require("../../utils");
9
- const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
- const resolver_abi_json_1 = __importDefault(require("../../abi/fluid-dex/resolver.abi.json"));
11
- const dexFactory_abi_json_1 = __importDefault(require("../../abi/fluid-dex/dexFactory.abi.json"));
12
- const decoders_1 = require("../../lib/decoders");
13
- const ethers_1 = require("ethers");
14
- class FluidDexCommonAddresses extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
- constructor(parentName, commonAddresses, network, dexHelper, logger) {
16
- super(parentName, 'getAllPools', dexHelper, logger);
17
- this.parentName = parentName;
18
- this.commonAddresses = commonAddresses;
19
- this.network = network;
20
- this.dexHelper = dexHelper;
21
- this.handlers = {};
22
- this.dexFactoryIface = new abi_1.Interface(dexFactory_abi_json_1.default);
23
- this.resolverIface = new abi_1.Interface(resolver_abi_json_1.default);
24
- this.decodePool = (result) => {
25
- return (0, decoders_1.generalDecoder)(result, ['tuple(address pool, address token0, address token1, uint256 fee)'], undefined, decoded => {
26
- return {
27
- address: decoded[0].toLowerCase(),
28
- token0: decoded[1].toLowerCase(),
29
- token1: decoded[2].toLowerCase(),
30
- };
31
- });
32
- };
33
- this.logDecoder = (log) => this.dexFactoryIface.parseLog(log);
34
- this.addressesSubscribed = [commonAddresses.dexFactory];
35
- // Add handlers
36
- this.handlers['DexDeployed'] = this.handleDexDeployed.bind(this);
37
- }
38
- /**
39
- * Handle a trade rate change on the pool.
40
- */
41
- async handleDexDeployed(event, state, log) {
42
- const blockNumber_ = await this.dexHelper.provider.getBlockNumber();
43
- return this.getStateOrGenerate(blockNumber_, false);
44
- }
45
- /**
46
- * The function is called every time any of the subscribed
47
- * addresses release log. The function accepts the current
48
- * state, updates the state according to the log, and returns
49
- * the updated state.
50
- * @param state - Current state of event subscriber
51
- * @param log - Log released by one of the subscribed addresses
52
- * @returns Updates state of the event subscriber after the log
53
- */
54
- async processLog(state, log) {
55
- try {
56
- let event;
57
- try {
58
- event = this.logDecoder(log);
59
- }
60
- catch (e) {
61
- return null;
62
- }
63
- if (event.name in this.handlers) {
64
- return await this.handlers[event.name](event, state, log);
65
- }
66
- }
67
- catch (e) {
68
- (0, utils_1.catchParseLogError)(e, this.logger);
69
- }
70
- return null;
71
- }
72
- async getStateOrGenerate(blockNumber, readonly = false) {
73
- let state = this.getState(blockNumber);
74
- if (!state) {
75
- state = await this.generateState(blockNumber);
76
- if (!readonly)
77
- this.setState(state, blockNumber);
78
- }
79
- return state;
80
- }
81
- /**
82
- * The function generates state using on-chain calls. This
83
- * function is called to regenerate state if the event based
84
- * system fails to fetch events and the local state is no
85
- * more correct.
86
- * @param blockNumber - Blocknumber for which the state should
87
- * should be generated
88
- * @returns state of the event subscriber at blocknumber
89
- */
90
- async generateState(blockNumber) {
91
- const resolverContract = new ethers_1.Contract(this.commonAddresses.resolver, resolver_abi_json_1.default, this.dexHelper.provider);
92
- const rawResult = await resolverContract.callStatic.getAllPools({
93
- blockTag: blockNumber,
94
- });
95
- const pools = rawResult.map((result) => ({
96
- address: result[0],
97
- token0: result[1],
98
- token1: result[2],
99
- }));
100
- return pools;
101
- }
102
- }
103
- exports.FluidDexCommonAddresses = FluidDexCommonAddresses;
104
- //# sourceMappingURL=fluid-dex-generate-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,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AAC,CAAC;SAClD;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,WAAmB;QACrC,MAAM,gBAAgB,GAAG,IAAI,iBAAQ,CACnC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAC7B,2BAAW,EACX,IAAI,CAAC,SAAS,CAAC,QAAQ,CACxB,CAAC;QACF,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,WAAW,CAAC;YAC9D,QAAQ,EAAE,WAAW;SACtB,CAAC,CAAC;QAEH,MAAM,KAAK,GAAW,SAAS,CAAC,GAAG,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,CAAC;YACpD,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;YAClB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;SAClB,CAAC,CAAC,CAAC;QAEJ,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA/HD,0DA+HC"}
@@ -1,47 +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 { CommonAddresses, FluidDexPoolState } from './types';
7
- import { Address } from '../../types';
8
- export declare class FluidDexEventPool extends StatefulEventSubscriber<FluidDexPoolState> {
9
- readonly parentName: string;
10
- readonly pool: Address;
11
- readonly commonAddresses: CommonAddresses;
12
- protected network: number;
13
- readonly dexHelper: IDexHelper;
14
- handlers: {
15
- [event: string]: (event: any, state: DeepReadonly<FluidDexPoolState>, log: Readonly<Log>) => Promise<DeepReadonly<FluidDexPoolState> | null>;
16
- };
17
- logDecoder: (log: Log) => any;
18
- addressesSubscribed: Address[];
19
- protected liquidityIface: Interface;
20
- constructor(parentName: string, pool: Address, commonAddresses: CommonAddresses, network: number, dexHelper: IDexHelper, logger: Logger);
21
- /**
22
- * Handle a trade rate change on the pool.
23
- */
24
- handleOperate(event: any, state: DeepReadonly<FluidDexPoolState>, log: Readonly<Log>): Promise<DeepReadonly<FluidDexPoolState> | null>;
25
- /**
26
- * The function is called every time any of the subscribed
27
- * addresses release log. The function accepts the current
28
- * state, updates the state according to the log, and returns
29
- * the updated state.
30
- * @param state - Current state of event subscriber
31
- * @param log - Log released by one of the subscribed addresses
32
- * @returns Updates state of the event subscriber after the log
33
- */
34
- processLog(state: DeepReadonly<FluidDexPoolState>, log: Readonly<Log>): Promise<DeepReadonly<FluidDexPoolState> | null>;
35
- getStateOrGenerate(blockNumber: number, readonly?: boolean): Promise<FluidDexPoolState>;
36
- /**
37
- * The function generates state using on-chain calls. This
38
- * function is called to regenerate state if the event based
39
- * system fails to fetch events and the local state is no
40
- * more correct.
41
- * @param blockNumber - Blocknumber for which the state should
42
- * should be generated
43
- * @returns state of the event subscriber at blocknumber
44
- */
45
- generateState(blockNumber: number): Promise<DeepReadonly<FluidDexPoolState>>;
46
- private convertToFluidDexPoolState;
47
- }
@@ -1,119 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FluidDexEventPool = void 0;
7
- const abi_1 = require("@ethersproject/abi");
8
- const utils_1 = require("../../utils");
9
- const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
- const resolver_abi_json_1 = __importDefault(require("../../abi/fluid-dex/resolver.abi.json"));
11
- const liquidityUserModule_abi_json_1 = __importDefault(require("../../abi/fluid-dex/liquidityUserModule.abi.json"));
12
- const ethers_1 = require("ethers");
13
- class FluidDexEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
14
- constructor(parentName, pool, commonAddresses, network, dexHelper, logger) {
15
- super(parentName, 'FluidDex_' + pool, dexHelper, logger);
16
- this.parentName = parentName;
17
- this.pool = pool;
18
- this.commonAddresses = commonAddresses;
19
- this.network = network;
20
- this.dexHelper = dexHelper;
21
- this.handlers = {};
22
- this.liquidityIface = new abi_1.Interface(liquidityUserModule_abi_json_1.default);
23
- this.logDecoder = (log) => this.liquidityIface.parseLog(log);
24
- this.addressesSubscribed = [commonAddresses.liquidityProxy];
25
- // Add handlers
26
- this.handlers['LogOperate'] = this.handleOperate.bind(this);
27
- }
28
- /**
29
- * Handle a trade rate change on the pool.
30
- */
31
- async handleOperate(event, state, log) {
32
- if (!(event.args.user in [this.pool])) {
33
- return null;
34
- }
35
- const resolverContract = new ethers_1.Contract(this.commonAddresses.resolver, resolver_abi_json_1.default, this.dexHelper.provider);
36
- const rawResult = await resolverContract.callStatic.getPoolReservesAdjusted(this.pool, {
37
- blockTag: this.dexHelper.provider,
38
- });
39
- const generatedState = this.convertToFluidDexPoolState(rawResult);
40
- this.setState(generatedState, await this.dexHelper.provider.getBlockNumber());
41
- return generatedState;
42
- }
43
- /**
44
- * The function is called every time any of the subscribed
45
- * addresses release log. The function accepts the current
46
- * state, updates the state according to the log, and returns
47
- * the updated state.
48
- * @param state - Current state of event subscriber
49
- * @param log - Log released by one of the subscribed addresses
50
- * @returns Updates state of the event subscriber after the log
51
- */
52
- async processLog(state, log) {
53
- try {
54
- const event = this.logDecoder(log);
55
- if (event.name in this.handlers) {
56
- return await this.handlers[event.name](event, state, log);
57
- }
58
- }
59
- catch (e) {
60
- (0, utils_1.catchParseLogError)(e, this.logger);
61
- }
62
- return null;
63
- }
64
- async getStateOrGenerate(blockNumber, readonly = false) {
65
- let state = this.getState(blockNumber);
66
- if (!state) {
67
- state = await this.generateState(blockNumber);
68
- if (!readonly)
69
- this.setState(state, blockNumber);
70
- }
71
- return state;
72
- }
73
- /**
74
- * The function generates state using on-chain calls. This
75
- * function is called to regenerate state if the event based
76
- * system fails to fetch events and the local state is no
77
- * more correct.
78
- * @param blockNumber - Blocknumber for which the state should
79
- * should be generated
80
- * @returns state of the event subscriber at blocknumber
81
- */
82
- async generateState(blockNumber) {
83
- const resolverContract = new ethers_1.Contract(this.commonAddresses.resolver, resolver_abi_json_1.default, this.dexHelper.provider);
84
- const rawResult = await resolverContract.callStatic.getPoolReservesAdjusted(this.pool, {
85
- blockTag: blockNumber,
86
- });
87
- const convertedResult = this.convertToFluidDexPoolState(rawResult);
88
- return convertedResult;
89
- }
90
- convertToFluidDexPoolState(input) {
91
- // Ignore the first three addresses
92
- const [, , , feeHex, collateralReservesHex, debtReservesHex] = input;
93
- // Convert fee from hex to number
94
- const fee = Number(feeHex.toString());
95
- // Convert collateral reserves
96
- const collateralReserves = {
97
- token0RealReserves: BigInt(collateralReservesHex[0].toString()),
98
- token1RealReserves: BigInt(collateralReservesHex[1].toString()),
99
- token0ImaginaryReserves: BigInt(collateralReservesHex[2].toString()),
100
- token1ImaginaryReserves: BigInt(collateralReservesHex[3].toString()),
101
- };
102
- // Convert debt reserves
103
- const debtReserves = {
104
- token0Debt: BigInt(debtReservesHex[0].toString()),
105
- token1Debt: BigInt(debtReservesHex[1].toString()),
106
- token0RealReserves: BigInt(debtReservesHex[2].toString()),
107
- token1RealReserves: BigInt(debtReservesHex[3].toString()),
108
- token0ImaginaryReserves: BigInt(debtReservesHex[4].toString()),
109
- token1ImaginaryReserves: BigInt(debtReservesHex[5].toString()),
110
- };
111
- return {
112
- collateralReserves,
113
- debtReserves,
114
- fee,
115
- };
116
- }
117
- }
118
- exports.FluidDexEventPool = FluidDexEventPool;
119
- //# sourceMappingURL=fluid-dex-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fluid-dex-pool.js","sourceRoot":"","sources":["../../../src/dex/fluid-dex/fluid-dex-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAE1E,8FAAgE;AAChE,oHAA4E;AAQ5E,mCAAkC;AAElC,MAAa,iBAAkB,SAAQ,mDAA0C;IAc/E,YACW,UAAkB,EAClB,IAAa,E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AAe,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC9D,uBAAuB,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;SAC/D,CAAC;QAEF,OAAO;YACL,kBAAkB;YAClB,YAAY;YACZ,GAAG;SACJ,CAAC;IACJ,CAAC;CACF;AAhKD,8CAgKC"}
@@ -1,4 +0,0 @@
1
- import { DexParams } from './types';
2
- import { DexConfigMap, AdapterMappings } from '../../types';
3
- export declare const IntegralConfig: DexConfigMap<DexParams>;
4
- export declare const Adapters: Record<number, AdapterMappings>;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Adapters = exports.IntegralConfig = void 0;
4
- const constants_1 = require("../../constants");
5
- exports.IntegralConfig = {
6
- Integral: {
7
- [constants_1.Network.MAINNET]: {
8
- factoryAddress: '0xC480b33eE5229DE3FbDFAD1D2DCD3F3BAD0C56c6',
9
- relayerAddress: '0xd17b3c9784510E33cD5B87b490E79253BcD81e2E',
10
- subgraphURL: 'ANd5QJuYtyfngmXvBMu9kZAv935vhcqp4xAGBkmCADN3',
11
- },
12
- [constants_1.Network.ARBITRUM]: {
13
- factoryAddress: '0x717EF162cf831db83c51134734A15D1EBe9E516a',
14
- relayerAddress: '0x3c6951FDB433b5b8442e7aa126D50fBFB54b5f42',
15
- subgraphURL: 'HXeVedRK7VgogXwbK5Sc4mjyLkhBAS5akskRvbSYnkHU',
16
- },
17
- },
18
- };
19
- exports.Adapters = {};
20
- //# sourceMappingURL=config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/integral/config.ts"],"names":[],"mappings":";;;AAEA,+CAA0C;AAE7B,QAAA,cAAc,GAA4B;IACrD,QAAQ,EAAE;QACR,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,cAAc,EAAE,4CAA4C;YAC5D,cAAc,EAAE,4CAA4C;YAC5D,WAAW,EAAE,8CAA8C;SAC5D;QACD,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE;YAClB,cAAc,EAAE,4CAA4C;YAC5D,cAAc,EAAE,4CAA4C;YAC5D,WAAW,EAAE,8CAA8C;SAC5D;KACF;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC,EAAE,CAAC"}
@@ -1,40 +0,0 @@
1
- import { Address } from '@paraswap/core';
2
- import { IntegralFactory } from './integral-factory';
3
- import { IntegralRelayer } from './integral-relayer';
4
- import { Network } from '../../constants';
5
- import { IDexHelper } from '../../dex-helper';
6
- import { Logger } from 'log4js';
7
- import { Interface } from '@ethersproject/abi';
8
- import { IntegralPool, PoolInitProps, RelayerPoolState } from './types';
9
- import { IntegralToken } from './integral-token';
10
- export declare class IntegralContext {
11
- readonly network: Network;
12
- readonly dexKey: string;
13
- readonly dexHelper: IDexHelper;
14
- readonly erc20Interface: Interface;
15
- readonly factoryAddress: Address;
16
- readonly relayerAddress: Address;
17
- static instances: {
18
- [network: number]: IntegralContext;
19
- };
20
- pools: {
21
- [poolId: string]: IntegralPool;
22
- };
23
- tokens: {
24
- [tokenAddress: Address]: IntegralToken;
25
- };
26
- factory: IntegralFactory;
27
- relayer: IntegralRelayer;
28
- logger: Logger;
29
- private constructor();
30
- addPools(pools: PoolInitProps, blockNumber: number, initPhase?: boolean): Promise<void>;
31
- getPoolAddresses(): string[];
32
- private removeDisabledPoolInitProps;
33
- static initialize(network: Network, dexKey: string, dexHelper: IDexHelper, erc20Interface: Interface, factoryAddress: Address, relayerAddress: Address): IntegralContext;
34
- static getInstance(network: Network): IntegralContext;
35
- onRelayerPoolEnabledSet(poolAddress: Address, state: RelayerPoolState, blockNumber: number): Promise<void>;
36
- onRebalanceSellOrderExecuted(blockNumber: number, orderId: bigint): void;
37
- onPoolCreatedAddPool(token0: Address, token1: Address, poolAddress: Address, blockNumber: number): Promise<void>;
38
- onPoolSwapForRelayer(blockNumber: number, poolAddress: Address, recipient: Address, amount0Out: bigint, amount1Out: bigint): Promise<void>;
39
- onTransferUpdateBalance(token: Address, from: Address, to: Address, amount: bigint, blockNumber: number): Promise<void>;
40
- }
@@ -1,158 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IntegralContext = void 0;
7
- const integral_pool_1 = require("./integral-pool");
8
- const integral_pricing_1 = require("./integral-pricing");
9
- const integral_factory_1 = require("./integral-factory");
10
- const integral_relayer_1 = require("./integral-relayer");
11
- const integral_token_1 = require("./integral-token");
12
- const utils_1 = require("./utils");
13
- const lodash_1 = __importDefault(require("lodash"));
14
- class IntegralContext {
15
- constructor(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
16
- this.network = network;
17
- this.dexKey = dexKey;
18
- this.dexHelper = dexHelper;
19
- this.erc20Interface = erc20Interface;
20
- this.factoryAddress = factoryAddress;
21
- this.relayerAddress = relayerAddress;
22
- this.pools = {};
23
- this.tokens = {};
24
- this.logger = dexHelper.getLogger(dexKey);
25
- this.factory = new integral_factory_1.IntegralFactory(dexHelper, dexKey, this.factoryAddress, this.onPoolCreatedAddPool, this.logger);
26
- this.relayer = new integral_relayer_1.IntegralRelayer(dexHelper, dexKey, this.erc20Interface, this.relayerAddress, {}, this.onRelayerPoolEnabledSet, this.logger);
27
- }
28
- async addPools(pools, blockNumber, initPhase = false) {
29
- this.relayer.addPools(pools);
30
- if (initPhase) {
31
- await this.relayer.initialize(blockNumber);
32
- }
33
- const _relayerState = this.relayer.getState(blockNumber);
34
- const relayerState = _relayerState
35
- ? _relayerState
36
- : await this.relayer.generateState(blockNumber);
37
- if (!_relayerState) {
38
- this.relayer.setState(relayerState, blockNumber);
39
- }
40
- const poolInitProps = this.removeDisabledPoolInitProps(relayerState, pools);
41
- const bases = Object.entries(poolInitProps).map(([poolAddress, p]) => {
42
- const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, p.token0, p.token1);
43
- const base = (this.pools[poolId] && this.pools[poolId].base) ||
44
- new integral_pool_1.IntegralEventPool(this.dexKey, this.network, this.dexHelper, poolAddress, p.token0, p.token1, this.logger);
45
- this.pools[poolId] = { base, enabled: true };
46
- return base;
47
- });
48
- await Promise.all(bases.map(base => !base.isInitialized && base.initialize(blockNumber)));
49
- const pricings = await Promise.all(bases.map(async (base) => {
50
- const _poolState = base.getState(blockNumber);
51
- const poolState = _poolState
52
- ? _poolState
53
- : await base.generateState(blockNumber);
54
- const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, base.token0, base.token1);
55
- const pricing = (this.pools[poolId] && this.pools[poolId].pricing) ||
56
- new integral_pricing_1.IntegralPricing(this.dexHelper, poolId, this.erc20Interface, poolState.uniswapPool, base.token0, base.token1, poolState.uniswapPoolFee, this.logger, this.network);
57
- this.pools[poolId].pricing = pricing;
58
- return pricing;
59
- }));
60
- await Promise.all(pricings.map(pricing => !pricing.isInitialized && pricing.initialize(blockNumber)));
61
- const initIntegralToken = (token) => new integral_token_1.IntegralToken(this.network, this.dexHelper, this.dexKey, this.erc20Interface, token, this.relayerAddress, this.onTransferUpdateBalance, this.logger);
62
- bases.map(base => {
63
- this.tokens[base.token0] =
64
- this.tokens[base.token0] || initIntegralToken(base.token0);
65
- this.tokens[base.token1] =
66
- this.tokens[base.token1] || initIntegralToken(base.token1);
67
- });
68
- await Promise.all(Object.values(this.tokens).map(token => !token.isInitialized && token.initialize(blockNumber)));
69
- }
70
- getPoolAddresses() {
71
- return Object.values(this.pools)
72
- .filter((pool) => !!pool.base && pool.enabled)
73
- .map(({ base }) => base.poolAddress);
74
- }
75
- removeDisabledPoolInitProps(state, props) {
76
- Object.entries(state.pools).forEach(([poolAddress, poolState]) => !poolState.isEnabled && delete props[poolAddress]);
77
- return props;
78
- }
79
- static initialize(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
80
- if (!this.instances[network]) {
81
- this.instances[network] = new IntegralContext(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress);
82
- }
83
- return this.instances[network];
84
- }
85
- static getInstance(network) {
86
- if (!this.instances[network]) {
87
- throw new Error('IntegralContext instance not initialized');
88
- }
89
- return this.instances[network];
90
- }
91
- async onRelayerPoolEnabledSet(poolAddress, state, blockNumber) {
92
- const poolEntry = (0, utils_1.getPoolBackReferencedFrom)(this, poolAddress);
93
- if (state.isEnabled && (!poolEntry || !poolEntry[1].enabled)) {
94
- const _factoryState = this.factory.getStaleState();
95
- const factoryState = _factoryState
96
- ? _factoryState
97
- : await this.factory.generateState(blockNumber);
98
- const { token0, token1 } = factoryState.pools[poolAddress];
99
- await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
100
- }
101
- else if (!state.isEnabled && poolEntry && poolEntry[1].enabled) {
102
- this.pools[poolEntry[0]].enabled = false;
103
- }
104
- }
105
- onRebalanceSellOrderExecuted(blockNumber, orderId) {
106
- this.relayer.executeOrder(orderId, blockNumber);
107
- }
108
- async onPoolCreatedAddPool(token0, token1, poolAddress, blockNumber) {
109
- await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
110
- }
111
- async onPoolSwapForRelayer(blockNumber, poolAddress, recipient, amount0Out, amount1Out) {
112
- if (recipient.toLowerCase() === this.relayerAddress.toLowerCase()) {
113
- const pools = this.relayer.getPools();
114
- if (pools[poolAddress.toLowerCase()]) {
115
- const token0 = pools[poolAddress.toLowerCase()].token0;
116
- const token1 = pools[poolAddress.toLowerCase()].token1;
117
- let _state = this.relayer.getStaleState();
118
- if (!_state) {
119
- _state = await this.relayer.generateState(blockNumber);
120
- this.relayer.setState(_state, blockNumber);
121
- return;
122
- }
123
- else {
124
- blockNumber = this.relayer.getStateBlockNumber();
125
- }
126
- const state = lodash_1.default.cloneDeep(_state);
127
- if (amount1Out > 0n) {
128
- state.tokens[token1].balance += amount1Out;
129
- }
130
- else {
131
- state.tokens[token0].balance += amount0Out;
132
- }
133
- this.relayer.setState(state, blockNumber);
134
- }
135
- else {
136
- this.logger.error('Integral Relayer: Pool address not found for', poolAddress);
137
- }
138
- }
139
- }
140
- async onTransferUpdateBalance(token, from, to, amount, blockNumber) {
141
- let _state = this.relayer.getStaleState();
142
- if (!_state) {
143
- this.logger.error('Integral Token: Relayer stale state not found');
144
- return;
145
- }
146
- const state = lodash_1.default.cloneDeep(_state);
147
- if (this.relayer.relayerAddress.toLowerCase() === from) {
148
- state.tokens[token].balance -= amount;
149
- }
150
- else if (this.relayer.relayerAddress.toLowerCase() === to) {
151
- state.tokens[token].balance += amount;
152
- }
153
- this.relayer.setState(state, blockNumber);
154
- }
155
- }
156
- exports.IntegralContext = IntegralContext;
157
- IntegralContext.instances = {};
158
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/dex/integral/context.ts"],"names":[],"mappings":";;;;;;AACA,mDAAoD;AACpD,yDAAqD;AACrD,yDAAqD;AACrD,yDAAqD;AAYrD,qDAAiD;AACjD,mCAAuE;AACvE,oDAAuB;AAEvB,MAAa,eAAe;IAU1B,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACrB,cAAyB,EACzB,cAAuB,EACvB,cAAuB;QALvB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACrB,mBAAc,GAAd,cAAc,CAAW;QACzB,mBAAc,GAAd,cAAc,CAAS;QACvB,mBAAc,GAAd,cAAc,CAAS;QAblC,UAAK,GAAuC,EAAE,CAAC;QAC/C,WAAM,GAA+C,EAAE,CAAC;QActD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,kCAAe,CAChC,SAAS,EACT,MAAM,EACN,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,MAAM,CACZ,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WAAmB;QAEnB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,OAAO;SACR;QACD,MAAM,KAAK,GAAiB,gBAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;YACtD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;SACvC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;YAC3D,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;SACvC;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;;AAzQH,0CA0QC;AAzQQ,yBAAS,GAA2C,EAAE,CAAC"}
@@ -1,24 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { LogDescription } from 'ethers/lib/utils';
3
- import { IDexHelper } from '../../dex-helper';
4
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
- import { Address, BlockHeader, Log, Logger } from '../../types';
6
- import { FactoryState } from './types';
7
- export declare type OnPoolCreatedCallback = (token0: Address, token1: Address, poolAddress: Address, blockNumber: number) => Promise<void>;
8
- export declare class IntegralFactory extends StatefulEventSubscriber<FactoryState> {
9
- readonly dexHelper: IDexHelper;
10
- protected readonly factoryAddress: Address;
11
- protected readonly onPoolCreated: OnPoolCreatedCallback;
12
- handlers: {
13
- [event: string]: (event: any, state: FactoryState, blockHeader: Readonly<BlockHeader>) => Promise<FactoryState>;
14
- };
15
- logDecoder: (log: Log) => any;
16
- readonly factoryIface: Interface;
17
- constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, onPoolCreated: OnPoolCreatedCallback, logger: Logger, mapKey?: string);
18
- protected getPoolIdentifierData(): {
19
- factory: string;
20
- };
21
- generateState(blockNumber?: number | 'latest'): Promise<FactoryState>;
22
- protected processLog(state: FactoryState, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
23
- handlePairCreated(event: LogDescription, state: FactoryState, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
24
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.IntegralFactory = void 0;
7
- const abi_1 = require("@ethersproject/abi");
8
- const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
9
- const factory_json_1 = __importDefault(require("../../abi/integral/factory.json"));
10
- const pool_json_1 = __importDefault(require("../../abi/integral/pool.json"));
11
- const decoders_1 = require("../../lib/decoders");
12
- class IntegralFactory extends stateful_event_subscriber_1.StatefulEventSubscriber {
13
- constructor(dexHelper, parentName, factoryAddress, onPoolCreated, logger, mapKey = '') {
14
- super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
15
- this.dexHelper = dexHelper;
16
- this.factoryAddress = factoryAddress;
17
- this.onPoolCreated = onPoolCreated;
18
- this.handlers = {};
19
- this.factoryIface = new abi_1.Interface(factory_json_1.default);
20
- this.addressesSubscribed = [factoryAddress];
21
- this.logDecoder = (log) => this.factoryIface.parseLog(log);
22
- this.handlers['PairCreated'] = this.handlePairCreated.bind(this);
23
- }
24
- getPoolIdentifierData() {
25
- return { factory: this.factoryAddress };
26
- }
27
- async generateState(blockNumber) {
28
- const factory = new this.dexHelper.web3Provider.eth.Contract(factory_json_1.default, this.factoryAddress);
29
- const poolCountResult = await factory.methods
30
- .allPairsLength()
31
- .call(undefined, blockNumber);
32
- const poolCount = Number(poolCountResult);
33
- const poolAddressCallDatas = [
34
- ...Array(poolCount),
35
- ].map((_, i) => {
36
- return {
37
- target: this.factoryAddress,
38
- callData: factory.methods.allPairs(i).encodeABI(),
39
- decodeFunction: decoders_1.addressDecode,
40
- };
41
- });
42
- const poolAddresses = await this.dexHelper.multiWrapper.tryAggregate(false, poolAddressCallDatas, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
43
- const poolIface = new abi_1.Interface(pool_json_1.default);
44
- const poolInfosCallDatas = poolAddresses
45
- .map(poolAddress => {
46
- return [
47
- {
48
- target: poolAddress.returnData,
49
- callData: poolIface.encodeFunctionData('token0', []),
50
- decodeFunction: decoders_1.addressDecode,
51
- },
52
- {
53
- target: poolAddress.returnData,
54
- callData: poolIface.encodeFunctionData('token1', []),
55
- decodeFunction: decoders_1.addressDecode,
56
- },
57
- ];
58
- })
59
- .flat();
60
- const poolInfos = await this.dexHelper.multiWrapper.aggregate(poolInfosCallDatas, blockNumber);
61
- const state = { pools: {} };
62
- poolAddresses.forEach((poolAddress, i) => {
63
- const tokens = [
64
- poolInfos[i * 2].toLowerCase(),
65
- poolInfos[i * 2 + 1].toLowerCase(),
66
- ];
67
- state.pools[poolAddress.returnData.toLowerCase()] = {
68
- token0: tokens[0],
69
- token1: tokens[1],
70
- };
71
- });
72
- return state;
73
- }
74
- async processLog(state, log, blockHeader) {
75
- const event = this.logDecoder(log);
76
- if (event.name in this.handlers) {
77
- return await this.handlers[event.name](event, state, blockHeader);
78
- }
79
- return state;
80
- }
81
- async handlePairCreated(event, state, blockHeader) {
82
- const tokens = [
83
- event.args.token0.toLowerCase(),
84
- event.args.token1.toLowerCase(),
85
- ];
86
- state.pools[event.args.pair.toLowerCase()] = {
87
- token0: tokens[0],
88
- token1: tokens[1],
89
- };
90
- await this.onPoolCreated(tokens[0], tokens[1], event.args.pair.toLowerCase(), blockHeader.number);
91
- return state;
92
- }
93
- }
94
- exports.IntegralFactory = IntegralFactory;
95
- //# sourceMappingURL=integral-factory.js.map