@paraswap/dex-lib 3.8.14 → 3.8.15
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.
- package/.vscode/launch.json +6 -43
- package/.vscode/settings.json +2 -1
- package/build/abi/Uncompressor.json +250 -0
- package/build/abi/concentrator/arUSD.json +568 -0
- package/build/abi/concentrator/arUSD5115.json +1746 -0
- package/build/abi/fx-protocol/FxMarket.json +1284 -0
- package/build/abi/{wombat/pool.json → fx-protocol/FxUSD.json} +541 -603
- package/build/abi/fx-protocol/weETHOralce.json +676 -0
- package/build/abi/integral/factory.json +333 -0
- package/build/abi/integral/oracle.json +501 -0
- package/build/abi/integral/pool.json +1041 -0
- package/build/abi/integral/relayer.json +1536 -0
- package/build/abi/oswap/oswap.abi.json +452 -0
- package/build/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -23
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/compound.js +1 -1
- package/build/dex/compound.js.map +1 -1
- package/build/dex/concentrator-arusd/concentrator-arusd-event.d.ts +17 -0
- package/build/dex/concentrator-arusd/concentrator-arusd-event.js +66 -0
- package/build/dex/concentrator-arusd/concentrator-arusd-event.js.map +1 -0
- package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +41 -0
- package/build/dex/concentrator-arusd/concentrator-arusd.js +188 -0
- package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -0
- package/build/dex/concentrator-arusd/config.d.ts +3 -0
- package/build/dex/concentrator-arusd/config.js +14 -0
- package/build/dex/concentrator-arusd/config.js.map +1 -0
- package/build/dex/concentrator-arusd/types.d.ts +14 -0
- package/build/dex/concentrator-arusd/types.js +3 -0
- package/build/dex/concentrator-arusd/types.js.map +1 -0
- package/build/dex/concentrator-arusd/utils.d.ts +4 -0
- package/build/dex/concentrator-arusd/utils.js +27 -0
- package/build/dex/concentrator-arusd/utils.js.map +1 -0
- package/build/dex/etherfi/etherfi.d.ts +26 -0
- package/build/dex/etherfi/etherfi.js +96 -0
- package/build/dex/etherfi/etherfi.js.map +1 -0
- package/build/dex/fx-protocol-rusd/config.d.ts +3 -0
- package/build/dex/fx-protocol-rusd/config.js +15 -0
- package/build/dex/fx-protocol-rusd/config.js.map +1 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.d.ts +18 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js +71 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js.map +1 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +39 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +201 -0
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -0
- package/build/dex/fx-protocol-rusd/types.d.ts +13 -0
- package/build/dex/fx-protocol-rusd/types.js +3 -0
- package/build/dex/fx-protocol-rusd/types.js.map +1 -0
- package/build/dex/fx-protocol-rusd/utils.d.ts +4 -0
- package/build/dex/fx-protocol-rusd/utils.js +26 -0
- package/build/dex/fx-protocol-rusd/utils.js.map +1 -0
- package/build/dex/index.js +4 -0
- package/build/dex/index.js.map +1 -1
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +40 -0
- package/build/dex/integral/context.js +158 -0
- package/build/dex/integral/context.js.map +1 -0
- package/build/dex/integral/helpers.d.ts +17 -0
- package/build/dex/integral/helpers.js +157 -0
- package/build/dex/integral/helpers.js.map +1 -0
- package/build/dex/integral/integral-factory.d.ts +24 -0
- package/build/dex/integral/integral-factory.js +95 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +50 -0
- package/build/dex/integral/integral-pool.js +149 -0
- package/build/dex/integral/integral-pool.js.map +1 -0
- package/build/dex/integral/integral-pricing.d.ts +18 -0
- package/build/dex/integral/integral-pricing.js +114 -0
- package/build/dex/integral/integral-pricing.js.map +1 -0
- package/build/dex/integral/integral-relayer.d.ts +42 -0
- package/build/dex/integral/integral-relayer.js +192 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +27 -0
- package/build/dex/integral/integral-token.js +59 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/integral/integral.d.ts +41 -0
- package/build/dex/integral/integral.js +377 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +84 -0
- package/build/dex/integral/types.js +9 -0
- package/build/dex/integral/types.js.map +1 -0
- package/build/dex/integral/utils-e2e.d.ts +9 -0
- package/build/dex/integral/utils-e2e.js +131 -0
- package/build/dex/integral/utils-e2e.js.map +1 -0
- package/build/dex/integral/utils.d.ts +17 -0
- package/build/dex/integral/utils.js +94 -0
- package/build/dex/integral/utils.js.map +1 -0
- package/build/dex/oswap/config.d.ts +5 -0
- package/build/dex/oswap/config.js +31 -0
- package/build/dex/oswap/config.js.map +1 -0
- package/build/dex/oswap/oswap-pool.d.ts +51 -0
- package/build/dex/oswap/oswap-pool.js +150 -0
- package/build/dex/oswap/oswap-pool.js.map +1 -0
- package/build/dex/oswap/oswap.d.ts +46 -0
- package/build/dex/oswap/oswap.js +266 -0
- package/build/dex/oswap/oswap.js.map +1 -0
- package/build/dex/oswap/types.d.ts +20 -0
- package/build/dex/oswap/types.js +3 -0
- package/build/dex/oswap/types.js.map +1 -0
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -45
- package/build/dex/platypus/platypus.js.map +1 -1
- package/build/dex/sdai/config.d.ts +11 -0
- package/build/dex/sdai/config.js +21 -0
- package/build/dex/sdai/config.js.map +1 -0
- package/build/dex/sdai/constants.d.ts +2 -0
- package/build/dex/sdai/constants.js +6 -0
- package/build/dex/sdai/constants.js.map +1 -0
- package/build/dex/sdai/scripts/validate-state.js +102 -0
- package/build/dex/sdai/scripts/validate-state.js.map +1 -0
- package/build/dex/sdai/sdai-pool.d.ts +16 -0
- package/build/dex/sdai/sdai-pool.js +85 -0
- package/build/dex/sdai/sdai-pool.js.map +1 -0
- package/build/dex/sdai/sdai.d.ts +51 -0
- package/build/dex/sdai/sdai.js +172 -0
- package/build/dex/sdai/sdai.js.map +1 -0
- package/build/dex/sdai/types.d.ts +21 -0
- package/build/dex/sdai/types.js +11 -0
- package/build/dex/sdai/types.js.map +1 -0
- package/build/dex/sdai/utils.d.ts +4 -0
- package/build/dex/sdai/utils.js +39 -0
- package/build/dex/sdai/utils.js.map +1 -0
- package/build/dex/stable-pool.js +8 -1
- package/build/dex/stable-pool.js.map +1 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -14
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/executor/compressor/Compressor.d.ts +23 -0
- package/build/executor/compressor/Compressor.js +144 -0
- package/build/executor/compressor/Compressor.js.map +1 -0
- package/build/executor/compressor/compress.d.ts +17 -0
- package/build/executor/compressor/compress.js +187 -0
- package/build/executor/compressor/compress.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
- package/build/executor/compressor/fetchSaved.js +17 -0
- package/build/executor/compressor/fetchSaved.js.map +1 -0
- package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
- package/build/executor/compressor/utils/computeCostL2.js +14 -0
- package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
- package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
- package/build/executor/compressor/utils/getAllIndexes.js +12 -0
- package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
- package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
- package/build/executor/compressor/utils/getByteForAddress.js +14 -0
- package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
- package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
- package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
- package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intToByte.d.ts +2 -0
- package/build/executor/compressor/utils/intToByte.js +10 -0
- package/build/executor/compressor/utils/intToByte.js.map +1 -0
- package/package.json +1 -1
- package/src/abi/concentrator/arUSD.json +568 -0
- package/src/abi/concentrator/arUSD5115.json +1746 -0
- package/src/abi/fx-protocol/FxMarket.json +1284 -0
- package/src/abi/fx-protocol/FxUSD.json +1227 -0
- package/src/abi/fx-protocol/weETHOralce.json +676 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +92 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +100 -0
- package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +104 -0
- package/src/dex/concentrator-arusd/concentrator-arusd.ts +269 -0
- package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +97 -0
- package/src/dex/concentrator-arusd/config.ts +13 -0
- package/src/dex/concentrator-arusd/types.ts +16 -0
- package/src/dex/concentrator-arusd/utils.ts +36 -0
- package/src/dex/fx-protocol-rusd/config.ts +14 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +96 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +101 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +104 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +112 -0
- package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +282 -0
- package/src/dex/fx-protocol-rusd/types.ts +16 -0
- package/src/dex/fx-protocol-rusd/utils.ts +47 -0
- package/src/dex/index.ts +4 -0
- package/src/dex/wsteth/wsteth-integration.test.ts +0 -1
- package/tests/constants-e2e.ts +10 -0
- package/.vscode/tasks.json +0 -15
- package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
- package/build/dex/aave-v2/tokens-avalanche.json +0 -44
- package/build/dex/aave-v2/tokens-mainnet.json +0 -188
- package/build/dex/aave-v2/tokens-polygon.json +0 -44
- package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
- package/build/dex/maker-psm/scripts/validate-state.js +0 -185
- package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
- package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
- package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
- package/build/dex/trader-joe-v2.1/base.d.ts +0 -18
- package/build/dex/trader-joe-v2.1/base.js +0 -99
- package/build/dex/trader-joe-v2.1/base.js.map +0 -1
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
- package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
- package/build/dex/trader-joe-v2.1/trader-joe-v2.2.d.ts +0 -7
- package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js +0 -20
- package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
- package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
- package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
- package/config.ts +0 -1946
- package/src/dex/dexs.txt +0 -58
- /package/build/dex/{solidly-v3/scripts/check-event-pool-event.d.ts → sdai/scripts/validate-state.d.ts} +0 -0
- /package/build/{dex/maker-psm/scripts/validate-state.d.ts → executor/compressor/fetchSaved.d.ts} +0 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPoolBackReferencedFrom = exports.getPoolIdentifier = exports.isInverted = exports.getTickCumulatives = exports.getAveragePrice = exports.getSpotPrice = exports.getPrice = exports.getDecimalsConverter = exports.sortTokens = exports.uint32ToNumber = exports.ceil_div = void 0;
|
|
4
|
+
const decoders_1 = require("../../lib/decoders");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const FullMath_1 = require("../uniswap-v3/contract-math/FullMath");
|
|
7
|
+
const Oracle_1 = require("../uniswap-v3/contract-math/Oracle");
|
|
8
|
+
const TickMath_1 = require("../uniswap-v3/contract-math/TickMath");
|
|
9
|
+
function ceil_div(a, b) {
|
|
10
|
+
const c = a / b;
|
|
11
|
+
if (a != b * c) {
|
|
12
|
+
return c + 1n;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return c;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ceil_div = ceil_div;
|
|
19
|
+
const uint32ToNumber = (result) => {
|
|
20
|
+
return (0, decoders_1.generalDecoder)(result, ['uint32'], 0, value => parseInt(value[0].toString(), 10));
|
|
21
|
+
};
|
|
22
|
+
exports.uint32ToNumber = uint32ToNumber;
|
|
23
|
+
function sortTokens(srcAddress, destAddress) {
|
|
24
|
+
return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
|
|
25
|
+
}
|
|
26
|
+
exports.sortTokens = sortTokens;
|
|
27
|
+
function getDecimalsConverter(decimals0, decimals1, inverted) {
|
|
28
|
+
return (10n **
|
|
29
|
+
(18n + BigInt(inverted ? decimals1 - decimals0 : decimals0 - decimals1)));
|
|
30
|
+
}
|
|
31
|
+
exports.getDecimalsConverter = getDecimalsConverter;
|
|
32
|
+
function getPrice(states, inverted) {
|
|
33
|
+
const { base, pricing, relayer } = states;
|
|
34
|
+
const decimalsConverter = getDecimalsConverter(base.decimals0, base.decimals1, false);
|
|
35
|
+
const spotPrice = getSpotPrice(pricing, decimalsConverter);
|
|
36
|
+
const averagePrice = getAveragePrice(relayer, pricing, decimalsConverter);
|
|
37
|
+
if (inverted) {
|
|
38
|
+
return 10n ** 36n / (spotPrice > averagePrice ? spotPrice : averagePrice);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
return spotPrice < averagePrice ? spotPrice : averagePrice;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.getPrice = getPrice;
|
|
45
|
+
function getSpotPrice(pricing, decimalsConverter) {
|
|
46
|
+
const sqrtPriceX96 = pricing.slot0.sqrtPriceX96;
|
|
47
|
+
const priceX128 = FullMath_1.FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 2n ** 64n);
|
|
48
|
+
return FullMath_1.FullMath.mulDiv(priceX128, decimalsConverter, 2n ** 128n);
|
|
49
|
+
}
|
|
50
|
+
exports.getSpotPrice = getSpotPrice;
|
|
51
|
+
function getAveragePrice(relayer, pricing, decimalsConverter) {
|
|
52
|
+
(0, utils_1._require)(relayer.twapInterval > 0, 'Twap Interval not set');
|
|
53
|
+
const secondsAgo = BigInt(relayer.twapInterval);
|
|
54
|
+
const secondsAgos = [secondsAgo, 0n];
|
|
55
|
+
const tickCumulatives = getTickCumulatives(pricing, secondsAgos);
|
|
56
|
+
const delta = tickCumulatives[1] - tickCumulatives[0];
|
|
57
|
+
let arithmeticMeanTick = delta / secondsAgo;
|
|
58
|
+
if (delta < 0 && delta % secondsAgo != 0n) {
|
|
59
|
+
--arithmeticMeanTick;
|
|
60
|
+
}
|
|
61
|
+
const sqrtRatioX96 = TickMath_1.TickMath.getSqrtRatioAtTick(arithmeticMeanTick);
|
|
62
|
+
const ratioX128 = FullMath_1.FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 2n ** 64n);
|
|
63
|
+
return FullMath_1.FullMath.mulDiv(ratioX128, decimalsConverter, 2n ** 128n);
|
|
64
|
+
}
|
|
65
|
+
exports.getAveragePrice = getAveragePrice;
|
|
66
|
+
function getTickCumulatives(poolState, secondsAgos) {
|
|
67
|
+
const { tickCumulatives } = secondsAgos.reduce((memo, secondsAgo, i) => {
|
|
68
|
+
[memo.tickCumulatives[i], memo.secondsPerLiquidityCumulativeX128s[i]] =
|
|
69
|
+
Oracle_1.Oracle.observeSingle(poolState, BigInt.asUintN(32, poolState.blockTimestamp), secondsAgo, poolState.slot0.tick, poolState.slot0.observationIndex, poolState.liquidity, poolState.slot0.observationCardinality);
|
|
70
|
+
return memo;
|
|
71
|
+
}, {
|
|
72
|
+
tickCumulatives: Array(secondsAgos.length),
|
|
73
|
+
secondsPerLiquidityCumulativeX128s: Array(secondsAgos.length),
|
|
74
|
+
});
|
|
75
|
+
return tickCumulatives;
|
|
76
|
+
}
|
|
77
|
+
exports.getTickCumulatives = getTickCumulatives;
|
|
78
|
+
function isInverted(tokenIn, tokenOut) {
|
|
79
|
+
const [, token1] = tokenIn.toLowerCase() < tokenOut.toLowerCase()
|
|
80
|
+
? [tokenIn, tokenOut]
|
|
81
|
+
: [tokenOut, tokenIn];
|
|
82
|
+
return tokenIn === token1;
|
|
83
|
+
}
|
|
84
|
+
exports.isInverted = isInverted;
|
|
85
|
+
function getPoolIdentifier(dexKey, srcAddress, destAddress) {
|
|
86
|
+
const tokenAddresses = sortTokens(srcAddress.toLowerCase(), destAddress.toLowerCase()).join('_');
|
|
87
|
+
return `${dexKey}_${tokenAddresses}`;
|
|
88
|
+
}
|
|
89
|
+
exports.getPoolIdentifier = getPoolIdentifier;
|
|
90
|
+
function getPoolBackReferencedFrom(context, poolAddress) {
|
|
91
|
+
return Object.entries(context.pools).find(([, pool]) => pool.base?.poolAddress === poolAddress);
|
|
92
|
+
}
|
|
93
|
+
exports.getPoolBackReferencedFrom = getPoolBackReferencedFrom;
|
|
94
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dex/integral/utils.ts"],"names":[],"mappings":";;;AAEA,iDAAoD;AAGpD,uCAAuC;AAC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AU,CAAC,OAAgB,EAAE,QAAiB;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC,GACd,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE;QAC5C,CAAC,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC;QACrB,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1B,OAAO,OAAO,KAAK,MAAM,CAAC;AAC5B,CAAC;AAND,gCAMC;AAED,SAAgB,iBAAiB,CAC/B,MAAc,EACd,UAAmB,EACnB,WAAoB;IAEpB,MAAM,cAAc,GAAG,UAAU,CAC/B,UAAU,CAAC,WAAW,EAAE,EACxB,WAAW,CAAC,WAAW,EAAE,CAC1B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,MAAM,IAAI,cAAc,EAAE,CAAC;AACvC,CAAC;AAVD,8CAUC;AAED,SAAgB,yBAAyB,CACvC,OAAwB,EACxB,WAAoB;IAEpB,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CACvC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,KAAK,WAAW,CACrD,CAAC;AACJ,CAAC;AAPD,8DAOC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DexParams } from './types';
|
|
2
|
+
import { DexConfigMap, AdapterMappings } from '../../types';
|
|
3
|
+
export declare const OSWAP_GAS_COST = 80000;
|
|
4
|
+
export declare const OSwapConfig: DexConfigMap<DexParams>;
|
|
5
|
+
export declare const Adapters: Record<number, AdapterMappings>;
|
|
@@ -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
|
+
//# sourceMappingURL=oswap-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oswap-pool.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap-pool.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAG1E,iDAAqD;AAErD,oFAAsD;AACtD,8EAAgD;AAEhD,MAAa,cAAe,SAAQ,mDAAuC;IAazE,YACW,UAAkB,EAClB,IAAe,EACd,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,SAAS,IAAI,eAAS,CAAC,wBAAQ,CAAC,EAChC,SAAS,IAAI,eAAS,CAAC,wBAAQ,CAAC;QAE1C,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QARrC,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAW;QACd,YAAO,GAAP,OAAO,CAAQ;QACf,cAAS,GAAT,SAAS,CAAY;QAErB,WAAM,GAAN,MAAM,CAA0B;QAChC,WAAM,GAAN,MAAM,CAA0B;QAnB5C,aAAQ,GAMJ,EAAE,CAAC;QAiBL,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEnD,IAAI,CAAC,mBAAmB,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAA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;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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
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): 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
|
+
}
|