@paraswap/dex-lib 3.8.12 → 3.8.13

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 (172) hide show
  1. package/build/abi/concentrator/arUSD.json +568 -0
  2. package/build/abi/{wombat/pool.json → fx-protocol/FxUSD.json} +541 -603
  3. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  4. package/build/abi/inception/inception-ineth.json +609 -0
  5. package/build/abi/inception/inception-ratio-feed.json +93 -0
  6. package/build/abi/inception/inception-vault.json +991 -0
  7. package/build/abi/infusion/InfusionFactory.json +147 -0
  8. package/build/abi/infusion/InfusionPair.json +658 -0
  9. package/build/abi/infusion/InfusionRouter.json +442 -0
  10. package/build/abi/oswap/oswap.abi.json +452 -0
  11. package/build/config.js +6 -6
  12. package/build/dex/aave-v1/aave-v1.js +0 -1
  13. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  14. package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +38 -0
  15. package/build/dex/concentrator-arusd/concentrator-arusd.js +184 -0
  16. package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -0
  17. package/build/dex/concentrator-arusd/config.d.ts +4 -0
  18. package/build/dex/concentrator-arusd/config.js +18 -0
  19. package/build/dex/concentrator-arusd/config.js.map +1 -0
  20. package/build/dex/concentrator-arusd/types.d.ts +10 -0
  21. package/build/dex/concentrator-arusd/types.js +3 -0
  22. package/build/dex/concentrator-arusd/types.js.map +1 -0
  23. package/build/dex/fx-protocol-rusd/config.d.ts +4 -0
  24. package/build/dex/fx-protocol-rusd/config.js +18 -0
  25. package/build/dex/fx-protocol-rusd/config.js.map +1 -0
  26. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +39 -0
  27. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +196 -0
  28. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -0
  29. package/build/dex/fx-protocol-rusd/types.d.ts +10 -0
  30. package/build/dex/fx-protocol-rusd/types.js +3 -0
  31. package/build/dex/fx-protocol-rusd/types.js.map +1 -0
  32. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  33. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  34. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  35. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  36. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  37. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  38. package/build/dex/idle-dao/scripts.d.ts +9 -0
  39. package/build/dex/idle-dao/scripts.js +552 -0
  40. package/build/dex/idle-dao/scripts.js.map +1 -0
  41. package/build/dex/inception/config.d.ts +5 -0
  42. package/build/dex/inception/config.js +112 -0
  43. package/build/dex/inception/config.js.map +1 -0
  44. package/build/dex/inception/inception-event-pool.d.ts +23 -0
  45. package/build/dex/inception/inception-event-pool.js +34 -0
  46. package/build/dex/inception/inception-event-pool.js.map +1 -0
  47. package/build/dex/inception/inception-native.d.ts +43 -0
  48. package/build/dex/inception/inception-native.js +131 -0
  49. package/build/dex/inception/inception-native.js.map +1 -0
  50. package/build/dex/inception/inception-pool.d.ts +18 -0
  51. package/build/dex/inception/inception-pool.js +32 -0
  52. package/build/dex/inception/inception-pool.js.map +1 -0
  53. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  54. package/build/dex/inception/inception-price-feed.js +51 -0
  55. package/build/dex/inception/inception-price-feed.js.map +1 -0
  56. package/build/dex/inception/inception.d.ts +44 -0
  57. package/build/dex/inception/inception.js +162 -0
  58. package/build/dex/inception/inception.js.map +1 -0
  59. package/build/dex/inception/tokens.d.ts +9 -0
  60. package/build/dex/inception/tokens.js +28 -0
  61. package/build/dex/inception/tokens.js.map +1 -0
  62. package/build/dex/inception/types.d.ts +22 -0
  63. package/build/dex/inception/types.js +3 -0
  64. package/build/dex/inception/types.js.map +1 -0
  65. package/build/dex/inception/utils.d.ts +7 -0
  66. package/build/dex/inception/utils.js +58 -0
  67. package/build/dex/inception/utils.js.map +1 -0
  68. package/build/dex/infusion/config.d.ts +4 -0
  69. package/build/dex/infusion/config.js +25 -0
  70. package/build/dex/infusion/config.js.map +1 -0
  71. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  72. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  73. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  74. package/build/dex/infusion/infusion.d.ts +54 -0
  75. package/build/dex/infusion/infusion.js +532 -0
  76. package/build/dex/infusion/infusion.js.map +1 -0
  77. package/build/dex/infusion/types.d.ts +47 -0
  78. package/build/dex/infusion/types.js +3 -0
  79. package/build/dex/infusion/types.js.map +1 -0
  80. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  81. package/build/dex/infusion/utils/isStablePair.js +18 -0
  82. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  83. package/build/dex/oswap/config.d.ts +5 -0
  84. package/build/dex/oswap/config.js +31 -0
  85. package/build/dex/oswap/config.js.map +1 -0
  86. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  87. package/build/dex/oswap/oswap-pool.js +150 -0
  88. package/build/dex/oswap/oswap-pool.js.map +1 -0
  89. package/build/dex/oswap/oswap.d.ts +46 -0
  90. package/build/dex/oswap/oswap.js +263 -0
  91. package/build/dex/oswap/oswap.js.map +1 -0
  92. package/build/dex/oswap/types.d.ts +20 -0
  93. package/build/dex/oswap/types.js +3 -0
  94. package/build/dex/oswap/types.js.map +1 -0
  95. package/build/dex/platypus/platypus.js +3 -17
  96. package/build/dex/platypus/platypus.js.map +1 -1
  97. package/build/dex/solidly-v3/config.js +39 -0
  98. package/build/dex/solidly-v3/config.js.map +1 -1
  99. package/build/dex/swaap-v1/swaap-v1.js +0 -4
  100. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  101. package/build/implementations/local-paraswap-sdk.d.ts +2 -0
  102. package/build/implementations/local-paraswap-sdk.js +7 -0
  103. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  104. package/package.json +1 -1
  105. package/src/config.ts +6 -6
  106. package/src/dex/solidly-v3/config.ts +42 -0
  107. package/src/dex/solidly-v3/solidly-v3-e2e.test.ts +114 -3
  108. package/src/implementations/local-paraswap-sdk.ts +8 -0
  109. package/tests/constants-e2e.ts +1 -1
  110. package/.vscode/launch.json +0 -53
  111. package/.vscode/settings.json +0 -2
  112. package/.vscode/tasks.json +0 -15
  113. package/build/abi/maverick-v2/MaverickV2Router.json +0 -778
  114. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  115. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  116. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  117. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  118. package/build/dex/bProtocol.d.ts +0 -18
  119. package/build/dex/bProtocol.js +0 -39
  120. package/build/dex/bProtocol.js.map +0 -1
  121. package/build/dex/bancor.d.ts +0 -26
  122. package/build/dex/bancor.js +0 -58
  123. package/build/dex/bancor.js.map +0 -1
  124. package/build/dex/compound.d.ts +0 -18
  125. package/build/dex/compound.js +0 -46
  126. package/build/dex/compound.js.map +0 -1
  127. package/build/dex/curve-v2.d.ts +0 -58
  128. package/build/dex/curve-v2.js +0 -180
  129. package/build/dex/curve-v2.js.map +0 -1
  130. package/build/dex/dodo-v1.d.ts +0 -33
  131. package/build/dex/dodo-v1.js +0 -63
  132. package/build/dex/dodo-v1.js.map +0 -1
  133. package/build/dex/lido.d.ts +0 -19
  134. package/build/dex/lido.js +0 -42
  135. package/build/dex/lido.js.map +0 -1
  136. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  137. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  138. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  139. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  140. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  141. package/build/dex/onebit.d.ts +0 -25
  142. package/build/dex/onebit.js +0 -42
  143. package/build/dex/onebit.js.map +0 -1
  144. package/build/dex/smoothy.d.ts +0 -26
  145. package/build/dex/smoothy.js +0 -48
  146. package/build/dex/smoothy.js.map +0 -1
  147. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  148. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  149. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  150. package/build/dex/stable-pool.d.ts +0 -28
  151. package/build/dex/stable-pool.js +0 -55
  152. package/build/dex/stable-pool.js.map +0 -1
  153. package/build/dex/trader-joe-v2.1/base.d.ts +0 -18
  154. package/build/dex/trader-joe-v2.1/base.js +0 -99
  155. package/build/dex/trader-joe-v2.1/base.js.map +0 -1
  156. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  157. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  158. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  159. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.d.ts +0 -7
  160. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js +0 -20
  161. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js.map +0 -1
  162. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  163. package/build/dex/trader-joe-v2.1.js +0 -79
  164. package/build/dex/trader-joe-v2.1.js.map +0 -1
  165. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  166. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  167. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  168. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  169. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  170. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  171. package/config.ts +0 -1946
  172. package/src/dex/dexs.txt +0 -58
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Adapters = exports.OSwapConfig = exports.OSWAP_GAS_COST = void 0;
4
+ const constants_1 = require("../../constants");
5
+ exports.OSWAP_GAS_COST = 80000;
6
+ // Important:
7
+ // - All addresses should be lower case.
8
+ // - Only tokens with 18 decimals are supported.
9
+ exports.OSwapConfig = {
10
+ OSwap: {
11
+ [constants_1.Network.MAINNET]: {
12
+ pools: [
13
+ {
14
+ id: 'OSwap_0x85b78aca6deae198fbf201c82daf6ca21942acc6',
15
+ address: '0x85b78aca6deae198fbf201c82daf6ca21942acc6',
16
+ token0: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
17
+ token1: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', // STETH
18
+ },
19
+ ],
20
+ },
21
+ },
22
+ };
23
+ exports.Adapters = {
24
+ [constants_1.Network.MAINNET]: {
25
+ // Note: We re-use the SmarDex adapters since it implements
26
+ // an Uniswap V2 router compatible interface, which OSwap supports.
27
+ [constants_1.SwapSide.SELL]: [{ name: 'Adapter04', index: 6 }],
28
+ [constants_1.SwapSide.BUY]: [{ name: 'BuyAdapter02', index: 2 }],
29
+ },
30
+ };
31
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,51 @@
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
+ }
@@ -0,0 +1,150 @@
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
+ //# sour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Prices, 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): bigint;
38
+ checkLiquidity(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: 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
+ }
@@ -0,0 +1,263 @@
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
+ class OSwap extends simple_exchange_1.SimpleExchange {
39
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
40
+ super(dexHelper, dexKey);
41
+ this.network = network;
42
+ this.dexKey = dexKey;
43
+ this.dexHelper = dexHelper;
44
+ this.adapters = adapters;
45
+ this.eventPools = {};
46
+ this.hasConstantPriceLargeAmounts = false;
47
+ // This may change in the future, but currently OSwap does not support native ETH.
48
+ this.needWrapNative = true;
49
+ this.isFeeOnTransferSupported = false;
50
+ this.logger = dexHelper.getLogger(dexKey);
51
+ this.iOSwap = new abi_1.Interface(oswap_abi_json_1.default);
52
+ this.pools = config_1.OSwapConfig[dexKey][network].pools;
53
+ // Create an OSwapEventPool per pool, to track each pool's state by subscribing to on-chain events.
54
+ for (const pool of this.pools) {
55
+ this.eventPools[pool.id] = new oswap_pool_1.OSwapEventPool(dexKey, pool, network, dexHelper, this.logger);
56
+ }
57
+ }
58
+ // Returns the list of contract adapters (name and index)
59
+ // for a buy/sell. Return null if there are no adapters.
60
+ getAdapters(side) {
61
+ return null;
62
+ }
63
+ // Returns the pool matching the specified token pair or null if none found.
64
+ // Note: OSwap V1 does not support more than 1 pool per pair.
65
+ getPoolByTokenPair(srcToken, destToken) {
66
+ const srcAddress = srcToken.address.toLowerCase();
67
+ const destAddress = destToken.address.toLowerCase();
68
+ // A pair must have 2 different tokens.
69
+ if (srcAddress === destAddress)
70
+ return null;
71
+ for (const pool of this.pools) {
72
+ if ((srcAddress === pool.token0 && destAddress === pool.token1) ||
73
+ (srcAddress === pool.token1 && destAddress === pool.token0)) {
74
+ return pool;
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+ getPoolById(id) {
80
+ for (const pool of this.pools) {
81
+ if (pool.id === id)
82
+ return pool;
83
+ }
84
+ return null;
85
+ }
86
+ // Returns a list of pool using the token.
87
+ getPoolsByTokenAddress(tokenAddress) {
88
+ const address = tokenAddress.toLowerCase();
89
+ let pools = [];
90
+ for (const pool of this.pools) {
91
+ if (address === pool.token0 || address === pool.token1) {
92
+ pools.push(pool);
93
+ }
94
+ }
95
+ return pools;
96
+ }
97
+ // Returns the list of pool identifiers that can be used
98
+ // for a given swap. poolIdentifiers must be unique
99
+ // across DEXes. It is recommended to use
100
+ // ${dexKey}_${poolAddress} as a poolIdentifier
101
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
102
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
103
+ return pool ? [pool.id] : [];
104
+ }
105
+ // Sell: Given "amount" of "from" token, how much of "to" token will be received by the trader.
106
+ // Buy: Given "amount" of "dest" token, how much of "to" token is required from the trader.
107
+ // Note: OSwap traderate is at precision 36.
108
+ calcPrice(pool, state, from, amount, side) {
109
+ const rate = from.address.toLowerCase() === pool.token0
110
+ ? state.traderate0
111
+ : state.traderate1;
112
+ return side === constants_1.SwapSide.SELL
113
+ ? (amount * rate) / (0, utils_1.getBigIntPow)(36)
114
+ : (amount * (0, utils_1.getBigIntPow)(36)) / rate;
115
+ }
116
+ // Returns true if the pool has enough liquidity for the swap. False otherwise.
117
+ checkLiquidity(pool, state, from, amount, side) {
118
+ if (side === constants_1.SwapSide.SELL) {
119
+ const needed = this.calcPrice(pool, state, from, amount, side);
120
+ return from.address.toLowerCase() === pool.token0
121
+ ? needed <= state.balance1
122
+ : needed <= state.balance0;
123
+ }
124
+ // SwapSide.BUY
125
+ return from.address.toLowerCase() === pool.token0
126
+ ? amount <= state.balance1
127
+ : amount <= state.balance0;
128
+ }
129
+ // Returns pool prices for amounts.
130
+ // If limitPools is defined only pools in limitPools
131
+ // should be used. If limitPools is undefined then
132
+ // any pool can be used.
133
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
134
+ // Get the pool to use.
135
+ const pool = this.getPoolByTokenPair(srcToken, destToken);
136
+ if (!pool)
137
+ return null;
138
+ // Make sure the pool meets the optional limitPools filter.
139
+ if (limitPools && !limitPools.includes(pool.id))
140
+ return null;
141
+ const eventPool = this.eventPools[pool.id];
142
+ if (!eventPool)
143
+ throw new Error(`OSwap pool ${pool.id}: No EventPool found.`);
144
+ const state = await eventPool.getStateOrGenerate(blockNumber);
145
+ // Ensure there is enough liquidity in the pool to process all the requested swaps.
146
+ const totalAmount = amounts.reduce((a, b) => a + b, BigInt(0));
147
+ if (!this.checkLiquidity(pool, state, srcToken, totalAmount, side)) {
148
+ return null;
149
+ }
150
+ // Calculate the prices
151
+ const unitAmount = (0, utils_1.getBigIntPow)(18);
152
+ const unitPrice = this.calcPrice(pool, state, srcToken, unitAmount, side);
153
+ const prices = amounts.map(amount => this.calcPrice(pool, state, srcToken, amount, side));
154
+ return [
155
+ {
156
+ prices,
157
+ unit: unitPrice,
158
+ data: {
159
+ pool: pool.address,
160
+ path: [srcToken.address, destToken.address],
161
+ },
162
+ exchange: this.dexKey,
163
+ poolIdentifier: pool.id,
164
+ gasCost: config_1.OSWAP_GAS_COST,
165
+ poolAddresses: [pool.address],
166
+ },
167
+ ];
168
+ }
169
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
170
+ getCalldataGasCost(poolPrices) {
171
+ return (CALLDATA_GAS_COST.DEX_OVERHEAD +
172
+ // ParentStruct header
173
+ CALLDATA_GAS_COST.OFFSET_SMALL +
174
+ // ParentStruct -> path[] header
175
+ CALLDATA_GAS_COST.OFFSET_SMALL +
176
+ // ParentStruct -> path length
177
+ CALLDATA_GAS_COST.LENGTH_SMALL +
178
+ // ParentStruct -> path[0]
179
+ CALLDATA_GAS_COST.ADDRESS +
180
+ // ParentStruct -> path[1]
181
+ CALLDATA_GAS_COST.ADDRESS +
182
+ // ParentStruct -> receiver header
183
+ CALLDATA_GAS_COST.OFFSET_SMALL +
184
+ // ParentStruct -> receiver
185
+ CALLDATA_GAS_COST.ADDRESS);
186
+ }
187
+ // Encode params required by the exchange adapter
188
+ // Used for multiSwap, buy & megaSwap
189
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
190
+ return {
191
+ targetExchange: data.pool,
192
+ payload: '',
193
+ networkFee: '0',
194
+ };
195
+ }
196
+ // Encode call data used by simpleSwap like routers
197
+ // Used for simpleSwap & simpleBuy
198
+ getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
199
+ let method;
200
+ let args;
201
+ const deadline = (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)();
202
+ if (side === constants_1.SwapSide.SELL) {
203
+ method = 'swapExactTokensForTokens';
204
+ args = [srcAmount, destAmount, data.path, recipient, deadline];
205
+ }
206
+ else {
207
+ method = 'swapTokensForExactTokens';
208
+ args = [destAmount, srcAmount, data.path, recipient, deadline];
209
+ }
210
+ const swapData = this.iOSwap.encodeFunctionData(method, args);
211
+ return {
212
+ needWrapNative: this.needWrapNative,
213
+ dexFuncHasRecipient: true,
214
+ exchangeData: swapData,
215
+ targetExchange: data.pool,
216
+ returnAmountPos: undefined,
217
+ };
218
+ }
219
+ // This is called once before getTopPoolsForToken is
220
+ // called for multiple tokens. This can be helpful to
221
+ // update common state required for calculating
222
+ // getTopPoolsForToken. It is optional for a DEX
223
+ // to implement this
224
+ async updatePoolState() {
225
+ return Promise.resolve();
226
+ }
227
+ // Returns a list of top pools based on liquidity. Max
228
+ // limit number pools should be returned.
229
+ async getTopPoolsForToken(tokenAddress, limit) {
230
+ // Get the list of pools using the token.
231
+ const pools = this.getPoolsByTokenAddress(tokenAddress);
232
+ if (!pools.length)
233
+ return [];
234
+ const results = await Promise.all(pools.map(async (pool) => {
235
+ // Get the pool's balance and its USD value.
236
+ const eventPool = this.eventPools[pool.id];
237
+ const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
238
+ const state = await eventPool.getStateOrGenerate(blockNumber);
239
+ const usd0 = await this.dexHelper.getTokenUSDPrice({ address: pool.token0, decimals: 18 }, state.balance0);
240
+ const usd1 = await this.dexHelper.getTokenUSDPrice({ address: pool.token1, decimals: 18 }, state.balance1);
241
+ // Get the other token in the pair.
242
+ const pairedToken = pool.token0 === tokenAddress.toLowerCase()
243
+ ? { address: pool.token1, decimals: 18 }
244
+ : { address: pool.token0, decimals: 18 };
245
+ return {
246
+ exchange: this.dexKey,
247
+ address: pool.address,
248
+ connectorTokens: [pairedToken],
249
+ liquidityUSD: usd0 + usd1,
250
+ };
251
+ }));
252
+ return results
253
+ .filter(r => r)
254
+ .sort((a, b) => a.liquidityUSD - b.liquidityUSD)
255
+ .slice(0, limit);
256
+ }
257
+ // This is optional function in case if your implementation has acquired any resources
258
+ // you need to release for graceful shutdown. For example, it may be any interval timer
259
+ releaseResources() { }
260
+ }
261
+ exports.OSwap = OSwap;
262
+ OSwap.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.OSwapConfig);
263
+ //# sourceMappingURL=oswap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oswap.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAc/C,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAkE;AAIlE,wDAG4B;AAC5B,qCAAiE;AACjE,6CAA8C;AAC9C,oFAAsD;AAEtD,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,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,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;;AAzU1C,sBA0UC;AAhUe,wBAAkB,GAC9B,IAAA,6BAAqB,EAAC,oBAAW,CAAC,CAAC"}
@@ -0,0 +1,20 @@
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
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/oswap/types.ts"],"names":[],"mappings":""}
@@ -43,7 +43,6 @@ const pool_json_1 = __importDefault(require("../../abi/platypus/pool.json"));
43
43
  const avax_pool_json_1 = __importDefault(require("../../abi/platypus/avax-pool.json"));
44
44
  const asset_json_1 = __importDefault(require("../../abi/platypus/asset.json"));
45
45
  const oracle_json_1 = __importDefault(require("../../abi/platypus/oracle.json"));
46
- const utils_2 = require("../../executor/utils");
47
46
  class Platypus extends simple_exchange_1.SimpleExchange {
48
47
  constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network]) {
49
48
  super(dexHelper, dexKey);
@@ -364,32 +363,22 @@ class Platypus extends simple_exchange_1.SimpleExchange {
364
363
  ]), data.pool);
365
364
  }
366
365
  getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
367
- const iface = (0, utils_1.isETHAddress)(srcToken)
368
- ? Platypus.avaxPoolInterface
369
- : (0, utils_1.isETHAddress)(destToken)
370
- ? Platypus.avaxPoolInterface
371
- : Platypus.poolInterface;
372
- const swapFunction = (0, utils_1.isETHAddress)(srcToken)
373
- ? 'swapFromETH'
374
- : (0, utils_1.isETHAddress)(destToken)
375
- ? 'swapToETH'
376
- : 'swap';
377
366
  const swapData = (0, utils_1.isETHAddress)(srcToken)
378
- ? iface.encodeFunctionData(swapFunction, [
367
+ ? Platypus.avaxPoolInterface.encodeFunctionData('swapFromETH', [
379
368
  destToken,
380
369
  1,
381
370
  recipient,
382
371
  (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
383
372
  ])
384
373
  : (0, utils_1.isETHAddress)(destToken)
385
- ? iface.encodeFunctionData(swapFunction, [
374
+ ? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
386
375
  srcToken,
387
376
  srcAmount,
388
377
  1,
389
378
  recipient,
390
379
  (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
391
380
  ])
392
- : iface.encodeFunctionData(swapFunction, [
381
+ : Platypus.poolInterface.encodeFunctionData('swap', [
393
382
  srcToken,
394
383
  destToken,
395
384
  srcAmount,
@@ -402,9 +391,6 @@ class Platypus extends simple_exchange_1.SimpleExchange {
402
391
  dexFuncHasRecipient: true,
403
392
  exchangeData: swapData,
404
393
  targetExchange: data.pool,
405
- returnAmountPos: side === constants_1.SwapSide.SELL
406
- ? (0, utils_2.extractReturnAmountPosition)(iface, swapFunction, 'actualToAmount')
407
- : undefined,
408
394
  };
409
395
  }
410
396
  // This is called once before getTopPoolsForToken is