@paraswap/dex-lib 3.8.22-infusion → 3.8.22

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 (235) 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/prettier.xml +7 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/build/abi/maverick-v2/MaverickV2Router.json +778 -0
  10. package/build/dex/index.js +0 -2
  11. package/build/dex/index.js.map +1 -1
  12. package/build/dex/lite-psm/lite-psm.js +1 -1
  13. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  14. package/build/dex/maker-psm/maker-psm.js +1 -1
  15. package/build/dex/trader-joe-v2.1/optimizer.d.ts +2 -0
  16. package/build/dex/trader-joe-v2.1/optimizer.js +47 -0
  17. package/build/dex/trader-joe-v2.1/optimizer.js.map +1 -0
  18. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +7 -0
  19. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +20 -0
  20. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +1 -0
  21. package/package.json +1 -1
  22. package/src/dex/index.ts +0 -2
  23. package/src/dex/lite-psm/lite-psm.ts +1 -1
  24. package/src/dex/maker-psm/maker-psm.ts +1 -1
  25. package/tests/constants-e2e.ts +1 -1
  26. package/build/abi/AaveV1_lending_pool.json +0 -27
  27. package/build/abi/inception/inception-ineth-pool.json +0 -1062
  28. package/build/abi/inception/inception-ineth.json +0 -609
  29. package/build/abi/inception/inception-ratio-feed.json +0 -93
  30. package/build/abi/inception/inception-vault.json +0 -991
  31. package/build/abi/infusion/InfusionFactory.json +0 -147
  32. package/build/abi/infusion/InfusionPair.json +0 -658
  33. package/build/abi/infusion/InfusionRouter.json +0 -442
  34. package/build/abi/oswap/oswap.abi.json +0 -452
  35. package/build/abi/platypus/asset.json +0 -490
  36. package/build/abi/platypus/avax-pool.json +0 -820
  37. package/build/abi/platypus/oracle.json +0 -119
  38. package/build/abi/platypus/pool.json +0 -677
  39. package/build/abi/smardex/all/smardex-router.json +0 -648
  40. package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
  41. package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
  42. package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
  43. package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
  44. package/build/abi/swaap-v1/pool.json +0 -1346
  45. package/build/dex/aave-v1/aave-v1.d.ts +0 -34
  46. package/build/dex/aave-v1/aave-v1.js +0 -180
  47. package/build/dex/aave-v1/aave-v1.js.map +0 -1
  48. package/build/dex/aave-v1/config.d.ts +0 -11
  49. package/build/dex/aave-v1/config.js +0 -20
  50. package/build/dex/aave-v1/config.js.map +0 -1
  51. package/build/dex/aave-v1/tokens-mainnet.json +0 -134
  52. package/build/dex/aave-v1/tokens.d.ts +0 -3
  53. package/build/dex/aave-v1/tokens.js +0 -50
  54. package/build/dex/aave-v1/tokens.js.map +0 -1
  55. package/build/dex/aave-v1/types.d.ts +0 -12
  56. package/build/dex/aave-v1/types.js +0 -3
  57. package/build/dex/aave-v1/types.js.map +0 -1
  58. package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
  59. package/build/dex/idle-dao/idle-dao-pool.js +0 -176
  60. package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
  61. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
  62. package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
  63. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
  64. package/build/dex/idle-dao/scripts.d.ts +0 -9
  65. package/build/dex/idle-dao/scripts.js +0 -552
  66. package/build/dex/idle-dao/scripts.js.map +0 -1
  67. package/build/dex/inception/config.d.ts +0 -5
  68. package/build/dex/inception/config.js +0 -112
  69. package/build/dex/inception/config.js.map +0 -1
  70. package/build/dex/inception/inception-event-pool.d.ts +0 -23
  71. package/build/dex/inception/inception-event-pool.js +0 -34
  72. package/build/dex/inception/inception-event-pool.js.map +0 -1
  73. package/build/dex/inception/inception-native.d.ts +0 -43
  74. package/build/dex/inception/inception-native.js +0 -131
  75. package/build/dex/inception/inception-native.js.map +0 -1
  76. package/build/dex/inception/inception-pool.d.ts +0 -18
  77. package/build/dex/inception/inception-pool.js +0 -32
  78. package/build/dex/inception/inception-pool.js.map +0 -1
  79. package/build/dex/inception/inception-price-feed.d.ts +0 -19
  80. package/build/dex/inception/inception-price-feed.js +0 -51
  81. package/build/dex/inception/inception-price-feed.js.map +0 -1
  82. package/build/dex/inception/inception.d.ts +0 -44
  83. package/build/dex/inception/inception.js +0 -162
  84. package/build/dex/inception/inception.js.map +0 -1
  85. package/build/dex/inception/tokens.d.ts +0 -9
  86. package/build/dex/inception/tokens.js +0 -28
  87. package/build/dex/inception/tokens.js.map +0 -1
  88. package/build/dex/inception/types.d.ts +0 -22
  89. package/build/dex/inception/types.js +0 -3
  90. package/build/dex/inception/types.js.map +0 -1
  91. package/build/dex/inception/utils.d.ts +0 -7
  92. package/build/dex/inception/utils.js +0 -58
  93. package/build/dex/inception/utils.js.map +0 -1
  94. package/build/dex/infusion/config.d.ts +0 -4
  95. package/build/dex/infusion/config.js +0 -25
  96. package/build/dex/infusion/config.js.map +0 -1
  97. package/build/dex/infusion/infusion-stable-pool.d.ts +0 -4
  98. package/build/dex/infusion/infusion-stable-pool.js +0 -74
  99. package/build/dex/infusion/infusion-stable-pool.js.map +0 -1
  100. package/build/dex/infusion/infusion.d.ts +0 -54
  101. package/build/dex/infusion/infusion.js +0 -510
  102. package/build/dex/infusion/infusion.js.map +0 -1
  103. package/build/dex/infusion/types.d.ts +0 -47
  104. package/build/dex/infusion/types.js +0 -3
  105. package/build/dex/infusion/types.js.map +0 -1
  106. package/build/dex/infusion/utils/isStablePair.d.ts +0 -2
  107. package/build/dex/infusion/utils/isStablePair.js +0 -18
  108. package/build/dex/infusion/utils/isStablePair.js.map +0 -1
  109. package/build/dex/oswap/config.d.ts +0 -5
  110. package/build/dex/oswap/config.js +0 -31
  111. package/build/dex/oswap/config.js.map +0 -1
  112. package/build/dex/oswap/oswap-pool.d.ts +0 -51
  113. package/build/dex/oswap/oswap-pool.js +0 -150
  114. package/build/dex/oswap/oswap-pool.js.map +0 -1
  115. package/build/dex/oswap/oswap.d.ts +0 -46
  116. package/build/dex/oswap/oswap.js +0 -273
  117. package/build/dex/oswap/oswap.js.map +0 -1
  118. package/build/dex/oswap/types.d.ts +0 -20
  119. package/build/dex/oswap/types.js +0 -3
  120. package/build/dex/oswap/types.js.map +0 -1
  121. package/build/dex/platypus/asset.d.ts +0 -14
  122. package/build/dex/platypus/asset.js +0 -97
  123. package/build/dex/platypus/asset.js.map +0 -1
  124. package/build/dex/platypus/config.d.ts +0 -11
  125. package/build/dex/platypus/config.js +0 -69
  126. package/build/dex/platypus/config.js.map +0 -1
  127. package/build/dex/platypus/platypus.d.ts +0 -63
  128. package/build/dex/platypus/platypus.js +0 -473
  129. package/build/dex/platypus/platypus.js.map +0 -1
  130. package/build/dex/platypus/pool-avax.d.ts +0 -8
  131. package/build/dex/platypus/pool-avax.js +0 -54
  132. package/build/dex/platypus/pool-avax.js.map +0 -1
  133. package/build/dex/platypus/pool-base.d.ts +0 -19
  134. package/build/dex/platypus/pool-base.js +0 -86
  135. package/build/dex/platypus/pool-base.js.map +0 -1
  136. package/build/dex/platypus/pool-pure.d.ts +0 -8
  137. package/build/dex/platypus/pool-pure.js +0 -37
  138. package/build/dex/platypus/pool-pure.js.map +0 -1
  139. package/build/dex/platypus/pool-subscriber.d.ts +0 -14
  140. package/build/dex/platypus/pool-subscriber.js +0 -167
  141. package/build/dex/platypus/pool-subscriber.js.map +0 -1
  142. package/build/dex/platypus/pool.d.ts +0 -8
  143. package/build/dex/platypus/pool.js +0 -58
  144. package/build/dex/platypus/pool.js.map +0 -1
  145. package/build/dex/platypus/types.d.ts +0 -92
  146. package/build/dex/platypus/types.js +0 -10
  147. package/build/dex/platypus/types.js.map +0 -1
  148. package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
  149. package/build/dex/quickswap/spiritswap-v3.js +0 -19
  150. package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
  151. package/build/dex/smardex/config.d.ts +0 -4
  152. package/build/dex/smardex/config.js +0 -64
  153. package/build/dex/smardex/config.js.map +0 -1
  154. package/build/dex/smardex/constants.d.ts +0 -18
  155. package/build/dex/smardex/constants.js +0 -33
  156. package/build/dex/smardex/constants.js.map +0 -1
  157. package/build/dex/smardex/sdk/constants.d.ts +0 -6
  158. package/build/dex/smardex/sdk/constants.js +0 -13
  159. package/build/dex/smardex/sdk/constants.js.map +0 -1
  160. package/build/dex/smardex/sdk/core.d.ts +0 -113
  161. package/build/dex/smardex/sdk/core.js +0 -499
  162. package/build/dex/smardex/sdk/core.js.map +0 -1
  163. package/build/dex/smardex/sdk/errors.d.ts +0 -15
  164. package/build/dex/smardex/sdk/errors.js +0 -22
  165. package/build/dex/smardex/sdk/errors.js.map +0 -1
  166. package/build/dex/smardex/sdk/types.d.ts +0 -62
  167. package/build/dex/smardex/sdk/types.js +0 -3
  168. package/build/dex/smardex/sdk/types.js.map +0 -1
  169. package/build/dex/smardex/sdk/utils.d.ts +0 -44
  170. package/build/dex/smardex/sdk/utils.js +0 -133
  171. package/build/dex/smardex/sdk/utils.js.map +0 -1
  172. package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
  173. package/build/dex/smardex/smardex-event-pool.js +0 -119
  174. package/build/dex/smardex/smardex-event-pool.js.map +0 -1
  175. package/build/dex/smardex/smardex.d.ts +0 -65
  176. package/build/dex/smardex/smardex.js +0 -519
  177. package/build/dex/smardex/smardex.js.map +0 -1
  178. package/build/dex/smardex/types.d.ts +0 -55
  179. package/build/dex/smardex/types.js +0 -3
  180. package/build/dex/smardex/types.js.map +0 -1
  181. package/build/dex/solidly/forks-override/cone.d.ts +0 -22
  182. package/build/dex/solidly/forks-override/cone.js +0 -53
  183. package/build/dex/solidly/forks-override/cone.js.map +0 -1
  184. package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
  185. package/build/dex/solidly/forks-override/solisnek.js +0 -15
  186. package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
  187. package/build/dex/swaap-v1/config.d.ts +0 -17
  188. package/build/dex/swaap-v1/config.js +0 -56
  189. package/build/dex/swaap-v1/config.js.map +0 -1
  190. package/build/dex/swaap-v1/constants.d.ts +0 -6
  191. package/build/dex/swaap-v1/constants.js +0 -17
  192. package/build/dex/swaap-v1/constants.js.map +0 -1
  193. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
  194. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
  195. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
  196. package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
  197. package/build/dex/swaap-v1/libraries/Const.js +0 -26
  198. package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
  199. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
  200. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
  201. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
  202. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
  203. package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
  204. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
  205. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
  206. package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
  207. package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
  208. package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
  209. package/build/dex/swaap-v1/libraries/Num.js +0 -167
  210. package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
  211. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
  212. package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
  213. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
  214. package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
  215. package/build/dex/swaap-v1/libraries/Struct.js +0 -3
  216. package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
  217. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
  218. package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
  219. package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
  220. package/build/dex/swaap-v1/swaap-v1.d.ts +0 -62
  221. package/build/dex/swaap-v1/swaap-v1.js +0 -379
  222. package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
  223. package/build/dex/swaap-v1/types.d.ts +0 -106
  224. package/build/dex/swaap-v1/types.js +0 -9
  225. package/build/dex/swaap-v1/types.js.map +0 -1
  226. package/src/abi/infusion/InfusionFactory.json +0 -147
  227. package/src/abi/infusion/InfusionPair.json +0 -658
  228. package/src/abi/infusion/InfusionRouter.json +0 -442
  229. package/src/dex/infusion/config.ts +0 -27
  230. package/src/dex/infusion/infusion-e2e.test.ts +0 -110
  231. package/src/dex/infusion/infusion-integration.test.ts +0 -232
  232. package/src/dex/infusion/infusion-stable-pool.ts +0 -91
  233. package/src/dex/infusion/infusion.ts +0 -749
  234. package/src/dex/infusion/types.ts +0 -60
  235. package/src/dex/infusion/utils/isStablePair.ts +0 -18
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/oswap/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,cAAc,GAAG,KAAM,CAAC;AAErC,aAAa;AACb,yCAAyC;AACzC,iDAAiD;AACpC,QAAA,WAAW,GAA4B;IAClD,KAAK,EAAE;QACL,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,KAAK,EAAE;gBACL;oBACE,EAAE,EAAE,kDAAkD;oBACtD,OAAO,EAAE,4CAA4C;oBACrD,MAAM,EAAE,4CAA4C;oBACpD,MAAM,EAAE,4CAA4C,EAAE,QAAQ;iBAC/D;aACF;SACF;KACF;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC;IACvD,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;QACjB,2DAA2D;QAC3D,mEAAmE;QACnE,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAClD,CAAC,oBAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KACrD;CACF,CAAC"}
@@ -1,51 +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 { OSwapPool, OSwapPoolState } from './types';
7
- export declare class OSwapEventPool extends StatefulEventSubscriber<OSwapPoolState> {
8
- readonly parentName: string;
9
- readonly pool: OSwapPool;
10
- protected network: number;
11
- protected dexHelper: IDexHelper;
12
- protected iOSwap: Interface;
13
- protected iERC20: Interface;
14
- handlers: {
15
- [event: string]: (event: any, state: DeepReadonly<OSwapPoolState>, log: Readonly<Log>) => DeepReadonly<OSwapPoolState> | null;
16
- };
17
- logDecoder: (log: Log) => any;
18
- addressesSubscribed: string[];
19
- constructor(parentName: string, pool: OSwapPool, network: number, dexHelper: IDexHelper, logger: Logger, iOSwap?: Interface, iERC20?: Interface);
20
- protected parseLog(log: Log): import("@ethersproject/abi").LogDescription;
21
- /**
22
- * The function is called every time any of the subscribed
23
- * addresses release log. The function accepts the current
24
- * state, updates the state according to the log, and returns
25
- * the updated state.
26
- * @param state - Current state of event subscriber
27
- * @param log - Log released by one of the subscribed addresses
28
- * @returns Updates state of the event subscriber after the log
29
- */
30
- protected processLog(state: DeepReadonly<OSwapPoolState>, log: Readonly<Log>): DeepReadonly<OSwapPoolState> | null;
31
- /**
32
- * The function generates state using on-chain calls. This
33
- * function is called to regenerate state if the event based
34
- * system fails to fetch events and the local state is no
35
- * more correct.
36
- * @param blockNumber - Blocknumber for which the state should
37
- * should be generated
38
- * @returns state of the event subscriber at blocknumber
39
- */
40
- generateState(blockNumber: number): Promise<DeepReadonly<OSwapPoolState>>;
41
- getStateOrGenerate(blockNumber: number, readonly?: boolean): Promise<OSwapPoolState>;
42
- /**
43
- * Handle a trade rate change on the pool.
44
- */
45
- handleTraderateChanged(event: any, state: DeepReadonly<OSwapPoolState>, log: Readonly<Log>): DeepReadonly<OSwapPoolState> | null;
46
- /**
47
- * Process the transfer events for tokens in/out of the pool
48
- * to keep the state's token balances up to date.
49
- */
50
- handleTransfer(event: any, state: DeepReadonly<OSwapPoolState>, log: Readonly<Log>): DeepReadonly<OSwapPoolState> | null;
51
- }
@@ -1,150 +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.OSwapEventPool = 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 decoders_1 = require("../../lib/decoders");
11
- const oswap_abi_json_1 = __importDefault(require("../../abi/oswap/oswap.abi.json"));
12
- const ERC20_abi_json_1 = __importDefault(require("../../abi/ERC20.abi.json"));
13
- class OSwapEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
14
- constructor(parentName, pool, network, dexHelper, logger, iOSwap = new abi_1.Interface(oswap_abi_json_1.default), iERC20 = new abi_1.Interface(ERC20_abi_json_1.default)) {
15
- super(parentName, pool.id, dexHelper, logger);
16
- this.parentName = parentName;
17
- this.pool = pool;
18
- this.network = network;
19
- this.dexHelper = dexHelper;
20
- this.iOSwap = iOSwap;
21
- this.iERC20 = iERC20;
22
- this.handlers = {};
23
- this.logDecoder = (log) => this.parseLog(log);
24
- this.addressesSubscribed = [pool.address, pool.token0, pool.token1];
25
- this.handlers['TraderateChanged'] = this.handleTraderateChanged.bind(this);
26
- this.handlers['Transfer'] = this.handleTransfer.bind(this);
27
- }
28
- parseLog(log) {
29
- if (log.address.toLowerCase() === this.pool.address) {
30
- return this.iOSwap.parseLog(log);
31
- }
32
- return this.iERC20.parseLog(log);
33
- }
34
- /**
35
- * The function is called every time any of the subscribed
36
- * addresses release log. The function accepts the current
37
- * state, updates the state according to the log, and returns
38
- * the updated state.
39
- * @param state - Current state of event subscriber
40
- * @param log - Log released by one of the subscribed addresses
41
- * @returns Updates state of the event subscriber after the log
42
- */
43
- processLog(state, log) {
44
- try {
45
- const event = this.logDecoder(log);
46
- if (event.name in this.handlers) {
47
- return this.handlers[event.name](event, state, log);
48
- }
49
- }
50
- catch (e) {
51
- (0, utils_1.catchParseLogError)(e, this.logger);
52
- }
53
- return null;
54
- }
55
- /**
56
- * The function generates state using on-chain calls. This
57
- * function is called to regenerate state if the event based
58
- * system fails to fetch events and the local state is no
59
- * more correct.
60
- * @param blockNumber - Blocknumber for which the state should
61
- * should be generated
62
- * @returns state of the event subscriber at blocknumber
63
- */
64
- async generateState(blockNumber) {
65
- const iERC20 = new abi_1.Interface(ERC20_abi_json_1.default);
66
- const callData = [
67
- {
68
- target: this.pool.token0,
69
- callData: iERC20.encodeFunctionData('balanceOf', [this.pool.address]),
70
- decodeFunction: decoders_1.uint256ToBigInt,
71
- },
72
- {
73
- target: this.pool.token1,
74
- callData: iERC20.encodeFunctionData('balanceOf', [this.pool.address]),
75
- decodeFunction: decoders_1.uint256ToBigInt,
76
- },
77
- {
78
- target: this.pool.address,
79
- callData: this.iOSwap.encodeFunctionData('traderate0', []),
80
- decodeFunction: decoders_1.uint256ToBigInt,
81
- },
82
- {
83
- target: this.pool.address,
84
- callData: this.iOSwap.encodeFunctionData('traderate1', []),
85
- decodeFunction: decoders_1.uint256ToBigInt,
86
- },
87
- ];
88
- const results = await this.dexHelper.multiWrapper.aggregate(callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize);
89
- return {
90
- balance0: results[0],
91
- balance1: results[1],
92
- traderate0: results[2],
93
- traderate1: results[3],
94
- };
95
- }
96
- async getStateOrGenerate(blockNumber, readonly = true) {
97
- let state = this.getState(blockNumber);
98
- if (!state) {
99
- state = await this.generateState(blockNumber);
100
- if (!readonly)
101
- this.setState(state, blockNumber);
102
- }
103
- return state;
104
- }
105
- /**
106
- * Handle a trade rate change on the pool.
107
- */
108
- handleTraderateChanged(event, state, log) {
109
- return {
110
- ...state,
111
- traderate0: event.args.traderate0.toBigInt(),
112
- traderate1: event.args.traderate1.toBigInt(),
113
- };
114
- }
115
- /**
116
- * Process the transfer events for tokens in/out of the pool
117
- * to keep the state's token balances up to date.
118
- */
119
- handleTransfer(event, state, log) {
120
- let balance0 = state.balance0;
121
- let balance1 = state.balance1;
122
- const tokenAddress = log.address.toLowerCase();
123
- const fromAddress = event.args.from.toLowerCase();
124
- const toAddress = event.args.to.toLowerCase();
125
- const amount = event.args.value.toBigInt();
126
- if (fromAddress == this.pool.address) {
127
- if (tokenAddress === this.pool.token0) {
128
- balance0 -= amount;
129
- }
130
- else if (tokenAddress === this.pool.token1) {
131
- balance1 -= amount;
132
- }
133
- }
134
- else if (toAddress == this.pool.address) {
135
- if (tokenAddress === this.pool.token0) {
136
- balance0 += amount;
137
- }
138
- else if (tokenAddress === this.pool.token1) {
139
- balance1 += amount;
140
- }
141
- }
142
- return {
143
- ...state,
144
- balance0,
145
- balance1,
146
- };
147
- }
148
- }
149
- exports.OSwapEventPool = OSwapEventPool;
150
- //# sourceMappingURL=oswap-pool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oswap-pool.js","sourceRoot":"","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,EACnC,GAAkB;QAElB,IAAI,QAAQ,GAAW,KAAK,CAAC,QAAQ,CAAC;QACtC,IAAI,QAAQ,GAAW,KAAK,CAAC,QAAQ,CAAC;QAEtC,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAC/C,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAE3C,IAAI,WAAW,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACpC,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACrC,QAAQ,IAAI,MAAM,CAAC;aACpB;iBAAM,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5C,QAAQ,IAAI,MAAM,CAAC;aACpB;SACF;aAAM,IAAI,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACzC,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBACrC,QAAQ,IAAI,MAAM,CAAC;aACpB;iBAAM,IAAI,YAAY,KAAK,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5C,QAAQ,IAAI,MAAM,CAAC;aACpB;SACF;QAED,OAAO;YACL,GAAG,KAAK;YACR,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;CACF;AAjLD,wCAiLC"}
@@ -1,46 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { AsyncOrSync } from 'ts-essentials';
3
- import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString, DexExchangeParam } from '../../types';
4
- import { SwapSide, Network } from '../../constants';
5
- import { Context, IDex } from '../../dex/idex';
6
- import { IDexHelper } from '../../dex-helper/idex-helper';
7
- import { OSwapData, OSwapPool, OSwapPoolState } from './types';
8
- import { SimpleExchange } from '../simple-exchange';
9
- import { OSwapEventPool } from './oswap-pool';
10
- export declare class OSwap extends SimpleExchange implements IDex<OSwapData> {
11
- readonly network: Network;
12
- readonly dexKey: string;
13
- readonly dexHelper: IDexHelper;
14
- protected adapters: import("../../types").AdapterMappings;
15
- readonly eventPools: {
16
- [id: string]: OSwapEventPool;
17
- };
18
- readonly hasConstantPriceLargeAmounts = false;
19
- readonly needWrapNative = true;
20
- readonly isFeeOnTransferSupported = false;
21
- static dexKeysWithNetwork: {
22
- key: string;
23
- networks: Network[];
24
- }[];
25
- logger: Logger;
26
- readonly iOSwap: Interface;
27
- readonly pools: [OSwapPool];
28
- constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
29
- getAdapters(side: SwapSide): {
30
- name: string;
31
- index: number;
32
- }[] | null;
33
- getPoolByTokenPair(srcToken: Token, destToken: Token): OSwapPool | null;
34
- getPoolById(id: string): OSwapPool | null;
35
- getPoolsByTokenAddress(tokenAddress: Address): OSwapPool[];
36
- getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
37
- calcPrice(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, side: SwapSide, checkLiquidity?: boolean): bigint;
38
- hasEnoughLiquidity(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, needed: bigint, side: SwapSide): boolean;
39
- getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<OSwapData>>;
40
- getCalldataGasCost(poolPrices: PoolPrices<OSwapData>): number | number[];
41
- getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OSwapData, side: SwapSide): AdapterExchangeParam;
42
- getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: OSwapData, side: SwapSide, _: Context, executorAddress: Address): DexExchangeParam;
43
- updatePoolState(): Promise<void>;
44
- getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
45
- releaseResources(): AsyncOrSync<void>;
46
- }
@@ -1,273 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.OSwap = void 0;
30
- const abi_1 = require("@ethersproject/abi");
31
- const constants_1 = require("../../constants");
32
- const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
33
- const utils_1 = require("../../utils");
34
- const simple_exchange_1 = require("../simple-exchange");
35
- const config_1 = require("./config");
36
- const oswap_pool_1 = require("./oswap-pool");
37
- const oswap_abi_json_1 = __importDefault(require("../../abi/oswap/oswap.abi.json"));
38
- const utils_2 = require("../../executor/utils");
39
- class OSwap extends simple_exchange_1.SimpleExchange {
40
- constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
41
- super(dexHelper, dexKey);
42
- this.network = network;
43
- this.dexKey = dexKey;
44
- this.dexHelper = dexHelper;
45
- this.adapters = adapters;
46
- this.eventPools = {};
47
- this.hasConstantPriceLargeAmounts = false;
48
- // This may change in the future, but currently OSwap does not support native ETH.
49
- this.needWrapNative = true;
50
- this.isFeeOnTransferSupported = false;
51
- this.logger = dexHelper.getLogger(dexKey);
52
- this.iOSwap = new abi_1.Interface(oswap_abi_json_1.default);
53
- this.pools = config_1.OSwapConfig[dexKey][network].pools;
54
- // Create an OSwapEventPool per pool, to track each pool's state by subscribing to on-chain events.
55
- for (const pool of this.pools) {
56
- this.eventPools[pool.id] = new oswap_pool_1.OSwapEventPool(dexKey, pool, network, dexHelper, this.logger);
57
- }
58
- }
59
- // Returns the list of contract adapters (name and index)
60
- // for a buy/sell. Return null if there are no adapters.
61
- getAdapters(side) {
62
- return null;
63
- }
64
- // Returns the pool matching the specified token pair or null if none found.
65
- // Note: OSwap V1 does not support more than 1 pool per pair.
66
- getPoolByTokenPair(srcToken, destToken) {
67
- const srcAddress = srcToken.address.toLowerCase();
68
- const destAddress = destToken.address.toLowerCase();
69
- // A pair must have 2 different tokens.
70
- if (srcAddress === destAddress)
71
- return null;
72
- for (const pool of this.pools) {
73
- if ((srcAddress === pool.token0 && destAddress === pool.token1) ||
74
- (srcAddress === pool.token1 && destAddress === pool.token0)) {
75
- return pool;
76
- }
77
- }
78
- return null;
79
- }
80
- getPoolById(id) {
81
- for (const pool of this.pools) {
82
- if (pool.id === id)
83
- return pool;
84
- }
85
- return null;
86
- }
87
- // Returns a list of pool using the token.
88
- getPoolsByTokenAddress(tokenAddress) {
89
- const address = tokenAddress.toLowerCase();
90
- let pools = [];
91
- for (const pool of this.pools) {
92
- if (address === pool.token0 || address === pool.token1) {
93
- pools.push(pool);
94
- }
95
- }
96
- return pools;
97
- }
98
- // Returns the list of pool identifiers that can be used
99
- // for a given swap. poolIdentifiers must be unique
100
- // across DEXes. It is recommended to use
101
- // ${dexKey}_${poolAddress} as a poolIdentifier
102
- async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
103
- const pool = this.getPoolByTokenPair(srcToken, destToken);
104
- return pool ? [pool.id] : [];
105
- }
106
- // Sell: Given "amount" of "from" token, how much of "to" token will be received by the trader.
107
- // Buy: Given "amount" of "dest" token, how much of "to" token is required from the trader.
108
- // Note: OSwap traderate is at precision 36.
109
- calcPrice(pool, state, from, amount, side, checkLiquidity = true) {
110
- const rate = from.address.toLowerCase() === pool.token0
111
- ? state.traderate0
112
- : state.traderate1;
113
- const price = side === constants_1.SwapSide.SELL
114
- ? (amount * rate) / (0, utils_1.getBigIntPow)(36)
115
- : (amount * (0, utils_1.getBigIntPow)(36)) / rate;
116
- if (checkLiquidity &&
117
- !this.hasEnoughLiquidity(pool, state, from, amount, price, side)) {
118
- throw new Error('Not enough liquidity');
119
- }
120
- return price;
121
- }
122
- // Returns true if the pool has enough liquidity for the swap. False otherwise.
123
- hasEnoughLiquidity(pool, state, from, amount, needed, side) {
124
- if (side === constants_1.SwapSide.SELL) {
125
- return from.address.toLowerCase() === pool.token0
126
- ? needed <= state.balance1
127
- : needed <= state.balance0;
128
- }
129
- // SwapSide.BUY
130
- return from.address.toLowerCase() === pool.token0
131
- ? amount <= state.balance1
132
- : amount <= state.balance0;
133
- }
134
- // Returns pool prices for amounts.
135
- // If limitPools is defined only pools in limitPools
136
- // should be used. If limitPools is undefined then
137
- // any pool can be used.
138
- async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
139
- try {
140
- // Get the pool to use.
141
- const pool = this.getPoolByTokenPair(srcToken, destToken);
142
- if (!pool)
143
- return null;
144
- // Make sure the pool meets the optional limitPools filter.
145
- if (limitPools && !limitPools.includes(pool.id))
146
- return null;
147
- const eventPool = this.eventPools[pool.id];
148
- if (!eventPool) {
149
- this.logger.error(`OSwap pool ${pool.id}: No EventPool found.`);
150
- return null;
151
- }
152
- const state = await eventPool.getStateOrGenerate(blockNumber);
153
- // Calculate the prices
154
- const unitAmount = (0, utils_1.getBigIntPow)(18);
155
- const unitPrice = this.calcPrice(pool, state, srcToken, unitAmount, side, false);
156
- const prices = amounts.map(amount => this.calcPrice(pool, state, srcToken, amount, side));
157
- return [
158
- {
159
- prices,
160
- unit: unitPrice,
161
- data: {
162
- pool: pool.address,
163
- path: [srcToken.address, destToken.address],
164
- },
165
- exchange: this.dexKey,
166
- poolIdentifier: pool.id,
167
- gasCost: config_1.OSWAP_GAS_COST,
168
- poolAddresses: [pool.address],
169
- },
170
- ];
171
- }
172
- catch (e) {
173
- this.logger.error(`Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${destToken.address || destToken.symbol}, ${side}:`, e);
174
- return null;
175
- }
176
- }
177
- // Returns estimated gas cost of calldata for this DEX in multiSwap
178
- getCalldataGasCost(poolPrices) {
179
- return (CALLDATA_GAS_COST.DEX_OVERHEAD +
180
- // ParentStruct header
181
- CALLDATA_GAS_COST.OFFSET_SMALL +
182
- // ParentStruct -> path[] header
183
- CALLDATA_GAS_COST.OFFSET_SMALL +
184
- // ParentStruct -> path length
185
- CALLDATA_GAS_COST.LENGTH_SMALL +
186
- // ParentStruct -> path[0]
187
- CALLDATA_GAS_COST.ADDRESS +
188
- // ParentStruct -> path[1]
189
- CALLDATA_GAS_COST.ADDRESS +
190
- // ParentStruct -> receiver header
191
- CALLDATA_GAS_COST.OFFSET_SMALL +
192
- // ParentStruct -> receiver
193
- CALLDATA_GAS_COST.ADDRESS);
194
- }
195
- // Encode params required by the exchange adapter
196
- // Used for multiSwap, buy & megaSwap
197
- getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
198
- return {
199
- targetExchange: data.pool,
200
- payload: '',
201
- networkFee: '0',
202
- };
203
- }
204
- // Encode call data used by simpleSwap like routers
205
- // Used for simpleSwap & simpleBuy
206
- getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
207
- let method;
208
- let args;
209
- let returnAmountPos = undefined;
210
- const deadline = (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)();
211
- if (side === constants_1.SwapSide.SELL) {
212
- method = 'swapExactTokensForTokens';
213
- returnAmountPos = (0, utils_2.extractReturnAmountPosition)(this.iOSwap, method, 'amounts', 1);
214
- args = [srcAmount, destAmount, data.path, recipient, deadline];
215
- }
216
- else {
217
- method = 'swapTokensForExactTokens';
218
- args = [destAmount, srcAmount, data.path, recipient, deadline];
219
- }
220
- const swapData = this.iOSwap.encodeFunctionData(method, args);
221
- return {
222
- needWrapNative: this.needWrapNative,
223
- dexFuncHasRecipient: true,
224
- exchangeData: swapData,
225
- targetExchange: data.pool,
226
- returnAmountPos,
227
- };
228
- }
229
- // This is called once before getTopPoolsForToken is
230
- // called for multiple tokens. This can be helpful to
231
- // update common state required for calculating
232
- // getTopPoolsForToken. It is optional for a DEX
233
- // to implement this
234
- async updatePoolState() {
235
- return Promise.resolve();
236
- }
237
- // Returns a list of top pools based on liquidity. Max
238
- // limit number pools should be returned.
239
- async getTopPoolsForToken(tokenAddress, limit) {
240
- // Get the list of pools using the token.
241
- const pools = this.getPoolsByTokenAddress(tokenAddress);
242
- if (!pools.length)
243
- return [];
244
- const results = await Promise.all(pools.map(async (pool) => {
245
- // Get the pool's balance and its USD value.
246
- const eventPool = this.eventPools[pool.id];
247
- const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
248
- const state = await eventPool.getStateOrGenerate(blockNumber);
249
- const usd0 = await this.dexHelper.getTokenUSDPrice({ address: pool.token0, decimals: 18 }, state.balance0);
250
- const usd1 = await this.dexHelper.getTokenUSDPrice({ address: pool.token1, decimals: 18 }, state.balance1);
251
- // Get the other token in the pair.
252
- const pairedToken = pool.token0 === tokenAddress.toLowerCase()
253
- ? { address: pool.token1, decimals: 18 }
254
- : { address: pool.token0, decimals: 18 };
255
- return {
256
- exchange: this.dexKey,
257
- address: pool.address,
258
- connectorTokens: [pairedToken],
259
- liquidityUSD: usd0 + usd1,
260
- };
261
- }));
262
- return results
263
- .filter(r => r)
264
- .sort((a, b) => a.liquidityUSD - b.liquidityUSD)
265
- .slice(0, limit);
266
- }
267
- // This is optional function in case if your implementation has acquired any resources
268
- // you need to release for graceful shutdown. For example, it may be any interval timer
269
- releaseResources() { }
270
- }
271
- exports.OSwap = OSwap;
272
- OSwap.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.OSwapConfig);
273
- //# sourceMappingURL=oswap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"oswap.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAa/C,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAkE;AAIlE,wDAG4B;AAC5B,qCAAiE;AACjE,6CAA8C;AAC9C,oFAAsD;AACtD,gDAAmE;AAEnE,MAAa,KAAM,SAAQ,gCAAc;IAmBvC,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,GAAR,QAAQ,CAA0B;QAtBrC,eAAU,GAAqC,EAAE,CAAC;QAElD,iCAA4B,GAAG,KAAK,CAAC;QAE9C,kFAAkF;QACzE,mBAAc,GAAG,IAAI,CAAC;QAEtB,6BAAwB,GAAG,KAAK,CAAC;QAkBxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAS,CAAC,wBAAQ,CAAC,CAAC;QAEtC,IAAI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EAAE,EACtC,KAAK,CAAC,QAAQ,CACf,CAAC;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAChD,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,EACtC,KAAK,CAAC,QAAQ,CACf,CAAC;YAEF,mCAAmC;YACnC,MAAM,WAAW,GACf,IAAI,CAAC,MAAM,KAAK,YAAY,CAAC,WAAW,EAAE;gBACxC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACxC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAE7C,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,MAAM;gBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,eAAe,EAAE,CAAC,WAAW,CAAC;gBAC9B,YAAY,EAAE,IAAI,GAAG,IAAI;aAC1B,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;QACF,OAAO,OAAO;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACd,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;aAC/C,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB,KAAuB,CAAC;;AA1W1C,sBA2WC;AAjWe,wBAAkB,GAC9B,IAAA,6BAAqB,EAAC,oBAAW,CAAC,CAAC"}
@@ -1,20 +0,0 @@
1
- import { Address } from '../../types';
2
- export declare type OSwapPoolState = {
3
- traderate0: bigint;
4
- traderate1: bigint;
5
- balance0: bigint;
6
- balance1: bigint;
7
- };
8
- export declare type OSwapData = {
9
- pool: Address;
10
- path: Address[];
11
- };
12
- export declare type OSwapPool = {
13
- id: string;
14
- address: Address;
15
- token0: Address;
16
- token1: Address;
17
- };
18
- export declare type DexParams = {
19
- pools: [OSwapPool];
20
- };
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/oswap/types.ts"],"names":[],"mappings":""}
@@ -1,14 +0,0 @@
1
- import { DeepReadonly } from 'ts-essentials';
2
- import { PartialEventSubscriber } from '../../composed-event-subscriber';
3
- import { Address, BlockHeader, Log, Logger, MultiCallInput, MultiCallOutput } from '../../types';
4
- import { Lens } from '../../lens';
5
- import { Interface } from '@ethersproject/abi';
6
- import { PlatypusAssetState } from './types';
7
- export declare class PlatypusAssetSubscriber<State> extends PartialEventSubscriber<State, PlatypusAssetState> {
8
- private asset;
9
- static readonly assetInterface: Interface;
10
- constructor(asset: Address, lens: Lens<DeepReadonly<State>, DeepReadonly<PlatypusAssetState>>, logger: Logger);
11
- processLog(state: DeepReadonly<PlatypusAssetState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PlatypusAssetState> | null;
12
- getGenerateStateMultiCallInputs(): MultiCallInput[];
13
- generateState(multicallOutputs: MultiCallOutput[], blockNumber?: number | 'latest'): DeepReadonly<PlatypusAssetState>;
14
- }