@paraswap/dex-lib 3.8.13 → 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 +16 -0
- package/.vscode/settings.json +3 -0
- package/build/abi/Uncompressor.json +250 -0
- package/build/abi/concentrator/arUSD5115.json +1746 -0
- package/build/abi/fx-protocol/FxMarket.json +1284 -0
- 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/{inception/inception-ineth-pool.json → integral/pool.json} +522 -543
- package/build/abi/integral/relayer.json +1536 -0
- package/build/abi/maverick-v2/MaverickV2Router.json +778 -0
- package/build/dex/aave-v1/aave-v1.d.ts +1 -2
- package/build/dex/aave-v1/aave-v1.js +0 -22
- package/build/dex/aave-v1/aave-v1.js.map +1 -1
- package/build/dex/bProtocol.d.ts +18 -0
- package/build/dex/bProtocol.js +39 -0
- package/build/dex/bProtocol.js.map +1 -0
- package/build/dex/bancor.d.ts +26 -0
- package/build/dex/bancor.js +58 -0
- package/build/dex/bancor.js.map +1 -0
- package/build/dex/compound.d.ts +18 -0
- package/build/dex/compound.js +46 -0
- package/build/dex/compound.js.map +1 -0
- 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 +6 -3
- package/build/dex/concentrator-arusd/concentrator-arusd.js +45 -41
- package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -1
- package/build/dex/concentrator-arusd/config.d.ts +1 -2
- package/build/dex/concentrator-arusd/config.js +2 -6
- package/build/dex/concentrator-arusd/config.js.map +1 -1
- package/build/dex/concentrator-arusd/types.d.ts +7 -3
- 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/curve-v2.d.ts +58 -0
- package/build/dex/curve-v2.js +180 -0
- package/build/dex/curve-v2.js.map +1 -0
- package/build/dex/dodo-v1.d.ts +33 -0
- package/build/dex/dodo-v1.js +63 -0
- package/build/dex/dodo-v1.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 +1 -2
- package/build/dex/fx-protocol-rusd/config.js +3 -6
- package/build/dex/fx-protocol-rusd/config.js.map +1 -1
- 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 +10 -10
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +75 -70
- package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -1
- package/build/dex/fx-protocol-rusd/types.d.ts +6 -3
- 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/{infusion → integral}/config.d.ts +1 -1
- 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/{inception/inception-native.d.ts → integral/integral.d.ts} +19 -21
- 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/lido.d.ts +19 -0
- package/build/dex/lido.js +42 -0
- package/build/dex/lido.js.map +1 -0
- package/build/dex/onebit.d.ts +25 -0
- package/build/dex/onebit.js +42 -0
- package/build/dex/onebit.js.map +1 -0
- package/build/dex/oswap/oswap.js +4 -1
- package/build/dex/oswap/oswap.js.map +1 -1
- package/build/dex/platypus/platypus.d.ts +1 -2
- package/build/dex/platypus/platypus.js +0 -31
- 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.d.ts +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/smoothy.d.ts +26 -0
- package/build/dex/smoothy.js +48 -0
- package/build/dex/smoothy.js.map +1 -0
- package/build/dex/stable-pool.d.ts +28 -0
- package/build/dex/stable-pool.js +62 -0
- package/build/dex/stable-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.d.ts +1 -2
- package/build/dex/swaap-v1/swaap-v1.js +0 -10
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
- package/build/dex/trader-joe-v2.1.d.ts +43 -0
- package/build/dex/trader-joe-v2.1.js +79 -0
- package/build/dex/trader-joe-v2.1.js.map +1 -0
- package/build/executor/Executor01BytecodeBuilder.js +4 -5
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +2 -3
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.js +24 -14
- package/build/executor/Executor03BytecodeBuilder.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.d.ts +0 -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/build/generic-swap-transaction-builder.d.ts +1 -1
- package/build/generic-swap-transaction-builder.js +10 -10
- package/build/generic-swap-transaction-builder.js.map +1 -1
- 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/src/executor/Executor01BytecodeBuilder.ts +4 -8
- package/src/executor/Executor02BytecodeBuilder.ts +2 -7
- package/src/executor/Executor03BytecodeBuilder.ts +34 -19
- package/src/generic-swap-transaction-builder.ts +3 -5
- package/tests/constants-e2e.ts +10 -0
- package/build/abi/inception/inception-ineth.json +0 -609
- package/build/abi/inception/inception-ratio-feed.json +0 -93
- package/build/abi/inception/inception-vault.json +0 -991
- package/build/abi/infusion/InfusionFactory.json +0 -147
- package/build/abi/infusion/InfusionPair.json +0 -658
- package/build/abi/infusion/InfusionRouter.json +0 -442
- package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
- package/build/dex/idle-dao/idle-dao-pool.js +0 -176
- package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
- package/build/dex/idle-dao/scripts.d.ts +0 -9
- package/build/dex/idle-dao/scripts.js +0 -552
- package/build/dex/idle-dao/scripts.js.map +0 -1
- package/build/dex/inception/config.d.ts +0 -5
- package/build/dex/inception/config.js +0 -112
- package/build/dex/inception/config.js.map +0 -1
- package/build/dex/inception/inception-event-pool.d.ts +0 -23
- package/build/dex/inception/inception-event-pool.js +0 -34
- package/build/dex/inception/inception-event-pool.js.map +0 -1
- package/build/dex/inception/inception-native.js +0 -131
- package/build/dex/inception/inception-native.js.map +0 -1
- package/build/dex/inception/inception-pool.d.ts +0 -18
- package/build/dex/inception/inception-pool.js +0 -32
- package/build/dex/inception/inception-pool.js.map +0 -1
- package/build/dex/inception/inception-price-feed.d.ts +0 -19
- package/build/dex/inception/inception-price-feed.js +0 -51
- package/build/dex/inception/inception-price-feed.js.map +0 -1
- package/build/dex/inception/inception.d.ts +0 -44
- package/build/dex/inception/inception.js +0 -162
- package/build/dex/inception/inception.js.map +0 -1
- package/build/dex/inception/tokens.d.ts +0 -9
- package/build/dex/inception/tokens.js +0 -28
- package/build/dex/inception/tokens.js.map +0 -1
- package/build/dex/inception/types.d.ts +0 -22
- package/build/dex/inception/types.js +0 -3
- package/build/dex/inception/types.js.map +0 -1
- package/build/dex/inception/utils.d.ts +0 -7
- package/build/dex/inception/utils.js +0 -58
- package/build/dex/inception/utils.js.map +0 -1
- package/build/dex/infusion/config.js +0 -25
- package/build/dex/infusion/config.js.map +0 -1
- package/build/dex/infusion/infusion-stable-pool.d.ts +0 -4
- package/build/dex/infusion/infusion-stable-pool.js +0 -74
- package/build/dex/infusion/infusion-stable-pool.js.map +0 -1
- package/build/dex/infusion/infusion.d.ts +0 -54
- package/build/dex/infusion/infusion.js +0 -532
- package/build/dex/infusion/infusion.js.map +0 -1
- package/build/dex/infusion/types.d.ts +0 -47
- package/build/dex/infusion/types.js +0 -3
- package/build/dex/infusion/types.js.map +0 -1
- package/build/dex/infusion/utils/isStablePair.d.ts +0 -2
- package/build/dex/infusion/utils/isStablePair.js +0 -18
- package/build/dex/infusion/utils/isStablePair.js.map +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Adapters = exports.SDaiConfig = void 0;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const core_1 = require("@paraswap/core");
|
|
6
|
+
exports.SDaiConfig = {
|
|
7
|
+
sdai: {
|
|
8
|
+
[constants_1.Network.MAINNET]: {
|
|
9
|
+
sdaiAddress: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
|
|
10
|
+
daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
|
|
11
|
+
potAddress: '0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
exports.Adapters = {
|
|
16
|
+
[constants_1.Network.MAINNET]: {
|
|
17
|
+
[core_1.SwapSide.SELL]: [{ name: 'Adapter06', index: 1 }],
|
|
18
|
+
[core_1.SwapSide.BUY]: [{ name: 'BuyAdapter02', index: 4 }],
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/sdai/config.ts"],"names":[],"mappings":";;;AAEA,+CAA0C;AAC1C,yCAA0C;AAE7B,QAAA,UAAU,GAA6B;IAClD,IAAI,EAAE;QACJ,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,UAAU,EAAE,4CAA4C;YACxD,UAAU,EAAE,4CAA4C;SACzD;KACF;CACF,CAAC;AAEW,QAAA,QAAQ,GAIjB;IACF,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;QACjB,CAAC,eAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAClD,CAAC,eAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KACrD;CACF,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDAI_REDEEM_GAS_COST = exports.SDAI_DEPOSIT_GAS_COST = void 0;
|
|
4
|
+
exports.SDAI_DEPOSIT_GAS_COST = 165000;
|
|
5
|
+
exports.SDAI_REDEEM_GAS_COST = 90000;
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/sdai/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,MAAO,CAAC;AAChC,QAAA,oBAAoB,GAAG,KAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
/* eslint-disable no-console */
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
+
dotenv_1.default.config();
|
|
9
|
+
const constants_1 = require("../../../constants");
|
|
10
|
+
const dex_helper_1 = require("../../../dex-helper");
|
|
11
|
+
const ethers_1 = require("ethers");
|
|
12
|
+
const sdai_1 = require("../sdai");
|
|
13
|
+
const config_1 = require("../config");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const abi_1 = require("@ethersproject/abi");
|
|
16
|
+
const pot_json_1 = __importDefault(require("../../../abi/maker-psm/pot.json"));
|
|
17
|
+
const network = constants_1.Network.MAINNET;
|
|
18
|
+
const dexKey = 'sdai';
|
|
19
|
+
const { potAddress } = config_1.SDaiConfig[dexKey][network];
|
|
20
|
+
const blockHeaders = {};
|
|
21
|
+
const dexHelper = new dex_helper_1.DummyDexHelper(network);
|
|
22
|
+
const logger = dexHelper.getLogger(dexKey);
|
|
23
|
+
function preprocessField(value) {
|
|
24
|
+
if (typeof value === 'bigint' ||
|
|
25
|
+
typeof value === 'number' ||
|
|
26
|
+
ethers_1.ethers.BigNumber.isBigNumber(value)) {
|
|
27
|
+
return value.toString();
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function compareAndLogDifferences(obj1, obj2, keyNames, checkEachKey = false) {
|
|
32
|
+
let isValid = true;
|
|
33
|
+
let keys = keyNames;
|
|
34
|
+
if (checkEachKey) {
|
|
35
|
+
// find common keys
|
|
36
|
+
const keys1 = Object.keys(obj1);
|
|
37
|
+
const keys2 = new Set(Object.keys(obj2));
|
|
38
|
+
keys = keys1.filter(key => keys2.has(key));
|
|
39
|
+
}
|
|
40
|
+
for (let fieldName of keys) {
|
|
41
|
+
const value1 = preprocessField(obj1[fieldName]);
|
|
42
|
+
const value2 = preprocessField(obj2[fieldName]);
|
|
43
|
+
if (value1 !== value2) {
|
|
44
|
+
console.log(`${fieldName.toString()} mismatch: actual: ${value1} vs pool: ${value2}`);
|
|
45
|
+
isValid = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return isValid;
|
|
49
|
+
}
|
|
50
|
+
async function isPoolStateEqualToReal(state, blockNumber) {
|
|
51
|
+
const expected = await (0, utils_1.getOnChainState)(dexHelper.multiContract, potAddress, new abi_1.Interface(pot_json_1.default), blockNumber);
|
|
52
|
+
const isValidState = compareAndLogDifferences(state, expected, [
|
|
53
|
+
'rho',
|
|
54
|
+
'dsr',
|
|
55
|
+
'dsr',
|
|
56
|
+
]);
|
|
57
|
+
return isValidState;
|
|
58
|
+
}
|
|
59
|
+
async function checkPoolStateForBlockRange(startBlockNumber, endBlockNumber) {
|
|
60
|
+
const network = constants_1.Network.MAINNET;
|
|
61
|
+
const dexKey = 'sdai';
|
|
62
|
+
const dexHelper = new dex_helper_1.DummyDexHelper(network);
|
|
63
|
+
const sdai = new sdai_1.SDai(network, dexKey, dexHelper);
|
|
64
|
+
const pool = await sdai.eventPool;
|
|
65
|
+
const logsToDispatch = await dexHelper.provider.getLogs({
|
|
66
|
+
fromBlock: startBlockNumber,
|
|
67
|
+
toBlock: endBlockNumber,
|
|
68
|
+
address: potAddress,
|
|
69
|
+
});
|
|
70
|
+
console.log(logsToDispatch.length);
|
|
71
|
+
// group logs by block number
|
|
72
|
+
const logsByBlockNumber = {};
|
|
73
|
+
for (let log of logsToDispatch) {
|
|
74
|
+
if (!logsByBlockNumber[log.blockNumber]) {
|
|
75
|
+
logsByBlockNumber[log.blockNumber] = [];
|
|
76
|
+
}
|
|
77
|
+
logsByBlockNumber[log.blockNumber].push(log);
|
|
78
|
+
}
|
|
79
|
+
const sortedBlocks = Object.keys(logsByBlockNumber)
|
|
80
|
+
.map(Number)
|
|
81
|
+
.sort((a, b) => Number(a) - Number(b));
|
|
82
|
+
for (let blockNumber of sortedBlocks) {
|
|
83
|
+
if (!blockHeaders[blockNumber]) {
|
|
84
|
+
blockHeaders[blockNumber] = await dexHelper.web3Provider.eth.getBlock(blockNumber);
|
|
85
|
+
}
|
|
86
|
+
await pool?.update(logsByBlockNumber[blockNumber], {
|
|
87
|
+
[blockNumber]: blockHeaders[blockNumber],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const state = pool?.getState(startBlockNumber);
|
|
91
|
+
return isPoolStateEqualToReal(state, endBlockNumber);
|
|
92
|
+
}
|
|
93
|
+
async function main() {
|
|
94
|
+
// use findBreakingBlock to find the block where the state is broken
|
|
95
|
+
// console.log(await findBreakingBlock(startBlockNumber, endBlockNumber));
|
|
96
|
+
// previously broken block 150502863
|
|
97
|
+
console.log(await checkPoolStateForBlockRange(19199247 - 10000, 19199247));
|
|
98
|
+
}
|
|
99
|
+
main()
|
|
100
|
+
.then(() => console.log('Done'))
|
|
101
|
+
.catch(e => console.error(e));
|
|
102
|
+
//# sourceMappingURL=validate-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-state.js","sourceRoot":"","sources":["../../../../src/dex/sdai/scripts/validate-state.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,oDAA4B;AAC5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,kDAA6C;AAC7C,oDAAqD;AAGrD,mCAAgC;AAChC,kCAA+B;AAC/B,sCAAuC;AACvC,oCAA2C;AAC3C,4CAA+C;AAC/C,+EAAqD;AAErD,MAAM,OAAO,GAAG,mBAAO,CAAC,OAAO,CAAC;AAChC,MAAM,MAAM,GAAG,MAAM,CAAC;AAEtB,MAAM,EAAE,UAAU,EAAE,GAAG,mBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;AACnD,MAAM,YAAY,GAAgC,EAAE,CAAC;AAErD,MAAM,SAAS,GAAG,IAAI,2BAAc,CAAC,OAAO,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAE3C,SAAS,eAAe,CAAC,KAAU;IACjC,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,eAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EACnC;QACA,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,wBAAwB,CAC/B,IAAO,EACP,IAAO,EACP,QAAkC,EAClC,YAAY,GAAG,KAAK;IAEpB,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,IAAI,GAAG,QAAQ,CAAC;IAEpB,IAAI,YAAY,EAAE;QAChB,mBAAmB;QACnB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAA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,CAAC;AACvD,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,oEAAoE;IACpE,0EAA0E;IAC1E,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAAC,MAAM,2BAA2B,CAAC,QAAQ,GAAG,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC/B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
2
|
+
import { Interface } from '@ethersproject/abi';
|
|
3
|
+
import type { IDexHelper } from '../../dex-helper';
|
|
4
|
+
import type { AsyncOrSync, DeepReadonly } from 'ts-essentials';
|
|
5
|
+
import type { Address, BlockHeader, Log, Logger } from '../../types';
|
|
6
|
+
import type { SDaiPoolState } from './types';
|
|
7
|
+
export declare class SDaiEventPool extends StatefulEventSubscriber<SDaiPoolState> {
|
|
8
|
+
protected dexHelper: IDexHelper;
|
|
9
|
+
private potAddress;
|
|
10
|
+
private potInterface;
|
|
11
|
+
constructor(parentName: string, dexHelper: IDexHelper, potAddress: Address, potInterface: Interface, logger: Logger);
|
|
12
|
+
protected processLog(state: DeepReadonly<SDaiPoolState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): AsyncOrSync<DeepReadonly<SDaiPoolState> | null>;
|
|
13
|
+
generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<SDaiPoolState>>;
|
|
14
|
+
convertToSDai(daiAmount: bigint, blockNumber: number): bigint;
|
|
15
|
+
convertToDai(sdaiAmount: bigint, blockNumber: number): bigint;
|
|
16
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDaiEventPool = void 0;
|
|
4
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
5
|
+
const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const RAY = bigint_constants_1.BI_POWS[27];
|
|
8
|
+
const ZERO = BigInt(0);
|
|
9
|
+
const TWO = BigInt(2);
|
|
10
|
+
const HALF = RAY / TWO;
|
|
11
|
+
// function file(bytes32,uint256)
|
|
12
|
+
const FILE_TOPICHASH = `0x29ae811400000000000000000000000000000000000000000000000000000000`;
|
|
13
|
+
// function drip()
|
|
14
|
+
const DRIP_TOPICHASH = `0x9f678cca00000000000000000000000000000000000000000000000000000000`;
|
|
15
|
+
// function cage()
|
|
16
|
+
const CAGE_TOPICHASH = `0x6924500900000000000000000000000000000000000000000000000000000000`;
|
|
17
|
+
// bytes32 repr of "dsr" string
|
|
18
|
+
const DSR_TOPIC = `0x6473720000000000000000000000000000000000000000000000000000000000`;
|
|
19
|
+
const rpow = (x, n) => {
|
|
20
|
+
if (!x && !n)
|
|
21
|
+
return RAY;
|
|
22
|
+
if (!x)
|
|
23
|
+
return ZERO;
|
|
24
|
+
let z = n % TWO > ZERO ? x : RAY;
|
|
25
|
+
for (n = n / TWO; n; n /= TWO) {
|
|
26
|
+
x = (x * x + HALF) / RAY;
|
|
27
|
+
if (n % TWO > ZERO) {
|
|
28
|
+
z = (z * x + HALF) / RAY;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return z;
|
|
32
|
+
};
|
|
33
|
+
const calcChi = (state, currentTimestamp) => {
|
|
34
|
+
currentTimestamp || (currentTimestamp = Math.floor(Date.now() / 1000));
|
|
35
|
+
if (!state.live)
|
|
36
|
+
return RAY;
|
|
37
|
+
const { dsr: dsr_, chi: chi_, rho: rho_ } = state;
|
|
38
|
+
const now = BigInt(currentTimestamp);
|
|
39
|
+
const rho = BigInt(rho_);
|
|
40
|
+
const dsr = BigInt(dsr_);
|
|
41
|
+
const chi = BigInt(chi_);
|
|
42
|
+
return now > rho ? (rpow(dsr, now - rho) * chi) / RAY : chi;
|
|
43
|
+
};
|
|
44
|
+
class SDaiEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
|
|
45
|
+
constructor(parentName, dexHelper, potAddress, potInterface, logger) {
|
|
46
|
+
super(parentName, 'sdai', dexHelper, logger);
|
|
47
|
+
this.dexHelper = dexHelper;
|
|
48
|
+
this.potAddress = potAddress;
|
|
49
|
+
this.potInterface = potInterface;
|
|
50
|
+
this.addressesSubscribed = [potAddress];
|
|
51
|
+
}
|
|
52
|
+
processLog(state, log, blockHeader) {
|
|
53
|
+
if (log.topics[0] === FILE_TOPICHASH && log.topics[2] === DSR_TOPIC) {
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
56
|
+
dsr: BigInt(log.topics[3]).toString(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (log.topics[0] === DRIP_TOPICHASH) {
|
|
60
|
+
return {
|
|
61
|
+
...state,
|
|
62
|
+
rho: blockHeader.timestamp.toString(),
|
|
63
|
+
chi: calcChi(state, +blockHeader.timestamp).toString(),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
async generateState(blockNumber = 'latest') {
|
|
69
|
+
return (0, utils_1.getOnChainState)(this.dexHelper.multiContract, this.potAddress, this.potInterface, blockNumber);
|
|
70
|
+
}
|
|
71
|
+
convertToSDai(daiAmount, blockNumber) {
|
|
72
|
+
const state = this.getState(blockNumber);
|
|
73
|
+
if (!state)
|
|
74
|
+
throw new Error(`SDai state at ${blockNumber} does not exists`);
|
|
75
|
+
return (daiAmount * RAY) / calcChi(state);
|
|
76
|
+
}
|
|
77
|
+
convertToDai(sdaiAmount, blockNumber) {
|
|
78
|
+
const state = this.getState(blockNumber);
|
|
79
|
+
if (!state)
|
|
80
|
+
throw new Error(`SDai state at ${blockNumber} does not exists`);
|
|
81
|
+
return (sdaiAmount * calcChi(state)) / RAY;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.SDaiEventPool = SDaiEventPool;
|
|
85
|
+
//# sourceMappingURL=sdai-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdai-pool.js","sourceRoot":"","sources":["../../../src/dex/sdai/sdai-pool.ts"],"names":[],"mappings":";;;AAAA,6DAAiD;AACjD,+EAA0E;AAO1E,mCAA0C;AAE1C,MAAM,GAAG,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;AACxB,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACtB,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;AAEvB,iCAAiC;AACjC,MAAM,cAAc,GAAG,oEAAoE,CAAC;AAC5F,kBAAkB;AAClB,MAAM,cAAc,GAAG,oEAAoE,CAAC;AAC5F,kBAAkB;AAClB,MAAM,cAAc,GAAG,oEAAoE,CAAC;AAC5F,+BAA+B;AAC/B,MAAM,SAAS,GAAG,oEAAoE,CAAC;AAEvF,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE;IAC5C,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACzB,IAAI,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpB,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAEjC,KAAK,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE;QAC7B,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC;QACzB,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,EAA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AW,kBAAkB,CAAC,CAAC;QAE5E,OAAO,CAAC,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC;IAC7C,CAAC;CACF;AA3DD,sCA2DC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
2
|
+
import { IDex } from '../idex';
|
|
3
|
+
import { SDaiParams, SDaiData } from './types';
|
|
4
|
+
import { Network, SwapSide } from '../../constants';
|
|
5
|
+
import { AdapterExchangeParam, Address, ExchangePrices, Logger, PoolLiquidity, PoolPrices, SimpleExchangeParam, Token } from '../../types';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper';
|
|
7
|
+
import { Interface } from 'ethers/lib/utils';
|
|
8
|
+
import { SDaiEventPool } from './sdai-pool';
|
|
9
|
+
export declare class SDai extends SimpleExchange implements IDex<SDaiData, SDaiParams> {
|
|
10
|
+
protected network: Network;
|
|
11
|
+
protected dexHelper: IDexHelper;
|
|
12
|
+
readonly daiAddress: string;
|
|
13
|
+
readonly sdaiAddress: string;
|
|
14
|
+
readonly potAddress: string;
|
|
15
|
+
protected adapters: {
|
|
16
|
+
[side: string]: {
|
|
17
|
+
name: string;
|
|
18
|
+
index: number;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
protected sdaiInterface: Interface;
|
|
22
|
+
protected potInterface: Interface;
|
|
23
|
+
readonly hasConstantPriceLargeAmounts = true;
|
|
24
|
+
readonly isFeeOnTransferSupported = false;
|
|
25
|
+
static dexKeysWithNetwork: {
|
|
26
|
+
key: string;
|
|
27
|
+
networks: Network[];
|
|
28
|
+
}[];
|
|
29
|
+
readonly eventPool: SDaiEventPool;
|
|
30
|
+
logger: Logger;
|
|
31
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, daiAddress?: string, sdaiAddress?: string, potAddress?: string, adapters?: {
|
|
32
|
+
[side: string]: {
|
|
33
|
+
name: string;
|
|
34
|
+
index: number;
|
|
35
|
+
}[];
|
|
36
|
+
}, sdaiInterface?: Interface, potInterface?: Interface);
|
|
37
|
+
getAdapters(side: SwapSide): {
|
|
38
|
+
name: string;
|
|
39
|
+
index: number;
|
|
40
|
+
}[] | null;
|
|
41
|
+
isSDai(tokenAddress: Address): boolean;
|
|
42
|
+
isDai(tokenAddress: Address): boolean;
|
|
43
|
+
isAppropriatePair(srcToken: Token, destToken: Token): boolean;
|
|
44
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
45
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
46
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<SDaiData>>;
|
|
47
|
+
getCalldataGasCost(poolPrices: PoolPrices<SDaiData>): number | number[];
|
|
48
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
49
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: SDaiData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
50
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: SDaiData, side: SwapSide): AdapterExchangeParam;
|
|
51
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
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.SDai = void 0;
|
|
30
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
31
|
+
const types_1 = require("./types");
|
|
32
|
+
const constants_1 = require("../../constants");
|
|
33
|
+
const utils_1 = require("../../utils");
|
|
34
|
+
const config_1 = require("./config");
|
|
35
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
36
|
+
const pot_json_1 = __importDefault(require("../../abi/maker-psm/pot.json"));
|
|
37
|
+
const SavingsDai_abi_json_1 = __importDefault(require("../../abi/sdai/SavingsDai.abi.json"));
|
|
38
|
+
const utils_2 = require("ethers/lib/utils");
|
|
39
|
+
const sdai_pool_1 = require("./sdai-pool");
|
|
40
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
41
|
+
const constants_2 = require("./constants");
|
|
42
|
+
class SDai extends simple_exchange_1.SimpleExchange {
|
|
43
|
+
constructor(network, dexKey, dexHelper, daiAddress = config_1.SDaiConfig[dexKey][network].daiAddress, sdaiAddress = config_1.SDaiConfig[dexKey][network].sdaiAddress, potAddress = config_1.SDaiConfig[dexKey][network].potAddress, adapters = config_1.Adapters[network] || {}, sdaiInterface = new utils_2.Interface(SavingsDai_abi_json_1.default), potInterface = new utils_2.Interface(pot_json_1.default)) {
|
|
44
|
+
super(dexHelper, dexKey);
|
|
45
|
+
this.network = network;
|
|
46
|
+
this.dexHelper = dexHelper;
|
|
47
|
+
this.daiAddress = daiAddress;
|
|
48
|
+
this.sdaiAddress = sdaiAddress;
|
|
49
|
+
this.potAddress = potAddress;
|
|
50
|
+
this.adapters = adapters;
|
|
51
|
+
this.sdaiInterface = sdaiInterface;
|
|
52
|
+
this.potInterface = potInterface;
|
|
53
|
+
this.hasConstantPriceLargeAmounts = true;
|
|
54
|
+
this.isFeeOnTransferSupported = false;
|
|
55
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
56
|
+
this.eventPool = new sdai_pool_1.SDaiEventPool(this.dexKey, dexHelper, this.potAddress, this.potInterface, this.logger);
|
|
57
|
+
}
|
|
58
|
+
getAdapters(side) {
|
|
59
|
+
return this.adapters[side] || null;
|
|
60
|
+
}
|
|
61
|
+
isSDai(tokenAddress) {
|
|
62
|
+
return this.sdaiAddress.toLowerCase() === tokenAddress.toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
isDai(tokenAddress) {
|
|
65
|
+
return this.daiAddress.toLowerCase() === tokenAddress.toLowerCase();
|
|
66
|
+
}
|
|
67
|
+
isAppropriatePair(srcToken, destToken) {
|
|
68
|
+
return ((this.isDai(srcToken.address) && this.isSDai(destToken.address)) ||
|
|
69
|
+
(this.isDai(destToken.address) && this.isSDai(srcToken.address)));
|
|
70
|
+
}
|
|
71
|
+
async initializePricing(blockNumber) {
|
|
72
|
+
await this.eventPool.initialize(blockNumber);
|
|
73
|
+
}
|
|
74
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
75
|
+
return this.isAppropriatePair(srcToken, destToken)
|
|
76
|
+
? [`${this.dexKey}_${this.sdaiAddress}`]
|
|
77
|
+
: [];
|
|
78
|
+
}
|
|
79
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
80
|
+
if (!this.isAppropriatePair(srcToken, destToken))
|
|
81
|
+
return null;
|
|
82
|
+
if (!this.eventPool.getState(blockNumber))
|
|
83
|
+
return null;
|
|
84
|
+
if (side === constants_1.SwapSide.SELL) {
|
|
85
|
+
const calcSellFn = (blockNumber, amountIn) => this.isDai(srcToken.address)
|
|
86
|
+
? this.eventPool.convertToSDai(amountIn, blockNumber)
|
|
87
|
+
: this.eventPool.convertToDai(amountIn, blockNumber);
|
|
88
|
+
return [
|
|
89
|
+
{
|
|
90
|
+
prices: amounts.map(amount => calcSellFn(blockNumber, amount)),
|
|
91
|
+
unit: calcSellFn(blockNumber, bigint_constants_1.BI_POWS[18]),
|
|
92
|
+
gasCost: constants_2.SDAI_DEPOSIT_GAS_COST,
|
|
93
|
+
exchange: this.dexKey,
|
|
94
|
+
data: { exchange: `${this.sdaiAddress}` },
|
|
95
|
+
poolAddresses: [`${this.sdaiAddress}`],
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const calcBuyFn = (blockNumber, amountIn) => this.isDai(srcToken.address)
|
|
101
|
+
? this.eventPool.convertToDai(amountIn, blockNumber)
|
|
102
|
+
: this.eventPool.convertToSDai(amountIn, blockNumber);
|
|
103
|
+
return [
|
|
104
|
+
{
|
|
105
|
+
prices: amounts.map(amount => calcBuyFn(blockNumber, amount)),
|
|
106
|
+
unit: calcBuyFn(blockNumber, bigint_constants_1.BI_POWS[18]),
|
|
107
|
+
gasCost: constants_2.SDAI_REDEEM_GAS_COST,
|
|
108
|
+
exchange: this.dexKey,
|
|
109
|
+
data: { exchange: `${this.sdaiAddress}` },
|
|
110
|
+
poolAddresses: [`${this.sdaiAddress}`],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
116
|
+
getCalldataGasCost(poolPrices) {
|
|
117
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
118
|
+
}
|
|
119
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
120
|
+
if (!this.isDai(tokenAddress) && !this.isSDai(tokenAddress))
|
|
121
|
+
return [];
|
|
122
|
+
return [
|
|
123
|
+
{
|
|
124
|
+
exchange: this.dexKey,
|
|
125
|
+
address: this.sdaiAddress,
|
|
126
|
+
connectorTokens: [
|
|
127
|
+
{
|
|
128
|
+
decimals: 18,
|
|
129
|
+
address: this.isDai(tokenAddress)
|
|
130
|
+
? this.sdaiAddress
|
|
131
|
+
: this.daiAddress,
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
}
|
|
138
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
139
|
+
const isSell = side === constants_1.SwapSide.SELL;
|
|
140
|
+
const { exchange } = data;
|
|
141
|
+
let swapData;
|
|
142
|
+
if (this.isDai(srcToken)) {
|
|
143
|
+
swapData = this.sdaiInterface.encodeFunctionData(isSell ? types_1.SDaiFunctions.deposit : types_1.SDaiFunctions.mint, [isSell ? srcAmount : destAmount, this.augustusAddress]);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
swapData = this.sdaiInterface.encodeFunctionData(isSell ? types_1.SDaiFunctions.redeem : types_1.SDaiFunctions.withdraw, [
|
|
147
|
+
isSell ? srcAmount : destAmount,
|
|
148
|
+
this.augustusAddress,
|
|
149
|
+
this.augustusAddress,
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, exchange);
|
|
153
|
+
}
|
|
154
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
155
|
+
const { exchange } = data;
|
|
156
|
+
const payload = this.abiCoder.encodeParameter({
|
|
157
|
+
ParentStruct: {
|
|
158
|
+
toStaked: 'bool',
|
|
159
|
+
},
|
|
160
|
+
}, {
|
|
161
|
+
toStaked: this.isDai(srcToken),
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
targetExchange: exchange,
|
|
165
|
+
payload,
|
|
166
|
+
networkFee: '0',
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.SDai = SDai;
|
|
171
|
+
SDai.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.SDaiConfig);
|
|
172
|
+
//# sourceMappingURL=sdai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdai.js","sourceRoot":"","sources":["../../../src/dex/sdai/sdai.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAoD;AAEpD,mCAA8D;AAC9D,+CAAoD;AACpD,uCAAoD;AACpD,qCAAgD;AAYhD,2EAA6D;AAC7D,4EAAkD;AAClD,6FAA+D;AAC/D,4CAA6C;AAC7C,2CAA4C;AAC5C,6DAAiD;AACjD,2CAA0E;AAE1E,MAAa,IAAK,SAAQ,gCAAc;IAUtC,YACY,OAAgB,EAC1B,MAAc,EACJ,SAAqB,EAEtB,aAAqB,mBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAC3D,cAAsB,mBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAC7D,aAAqB,mBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAE1D,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAClC,gBAAgB,IAAI,iBAAS,CAAC,6BAAa,CAAC,EAC5C,eAAe,IAAI,iBAAS,CAAC,kBAAM,CAAC;QAE9C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAZf,YAAO,GAAP,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AQ,EACR,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,eAAe,CACb,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAc,EACd,IAAc;QAEd,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAC3C;YACE,YAAY,EAAE;gBACZ,QAAQ,EAAE,MAAM;aACjB;SACF,EACD;YACE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;SAC/B,CACF,CAAC;QAEF,OAAO;YACL,cAAc,EAAE,QAAQ;YACxB,OAAO;YACP,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;;AA9MH,oBA+MC;AA3Me,uBAAkB,GAC9B,IAAA,6BAAqB,EAAC,mBAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
export declare type SDaiData = {
|
|
3
|
+
exchange: Address;
|
|
4
|
+
};
|
|
5
|
+
export declare type SDaiParams = {
|
|
6
|
+
sdaiAddress: Address;
|
|
7
|
+
daiAddress: Address;
|
|
8
|
+
potAddress: Address;
|
|
9
|
+
};
|
|
10
|
+
export declare enum SDaiFunctions {
|
|
11
|
+
deposit = "deposit",
|
|
12
|
+
redeem = "redeem",
|
|
13
|
+
withdraw = "withdraw",
|
|
14
|
+
mint = "mint"
|
|
15
|
+
}
|
|
16
|
+
export declare type SDaiPoolState = {
|
|
17
|
+
rho: string;
|
|
18
|
+
chi: string;
|
|
19
|
+
dsr: string;
|
|
20
|
+
live: boolean;
|
|
21
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDaiFunctions = void 0;
|
|
4
|
+
var SDaiFunctions;
|
|
5
|
+
(function (SDaiFunctions) {
|
|
6
|
+
SDaiFunctions["deposit"] = "deposit";
|
|
7
|
+
SDaiFunctions["redeem"] = "redeem";
|
|
8
|
+
SDaiFunctions["withdraw"] = "withdraw";
|
|
9
|
+
SDaiFunctions["mint"] = "mint";
|
|
10
|
+
})(SDaiFunctions = exports.SDaiFunctions || (exports.SDaiFunctions = {}));
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/sdai/types.ts"],"names":[],"mappings":";;;AAUA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,kCAAiB,CAAA;IACjB,sCAAqB,CAAA;IACrB,8BAAa,CAAA;AACf,CAAC,EALW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAKxB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Contract } from 'web3-eth-contract';
|
|
2
|
+
import { SDaiPoolState } from './types';
|
|
3
|
+
import { Interface } from '@ethersproject/abi';
|
|
4
|
+
export declare function getOnChainState(multiContract: Contract, potAddress: string, potInterface: Interface, blockNumber: number | 'latest'): Promise<SDaiPoolState>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOnChainState = void 0;
|
|
4
|
+
const abi_1 = require("@ethersproject/abi");
|
|
5
|
+
const coder = new abi_1.AbiCoder();
|
|
6
|
+
// - `dsr`: the Dai Savings Rate
|
|
7
|
+
// - `chi`: the Rate Accumulator
|
|
8
|
+
// - `rho`: time of last drip
|
|
9
|
+
async function getOnChainState(multiContract, potAddress, potInterface, blockNumber) {
|
|
10
|
+
const data = await multiContract.methods
|
|
11
|
+
.aggregate([
|
|
12
|
+
{
|
|
13
|
+
target: potAddress,
|
|
14
|
+
callData: potInterface.encodeFunctionData('dsr', []),
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
target: potAddress,
|
|
18
|
+
callData: potInterface.encodeFunctionData('chi', []),
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
target: potAddress,
|
|
22
|
+
callData: potInterface.encodeFunctionData('rho', []),
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
target: potAddress,
|
|
26
|
+
callData: potInterface.encodeFunctionData('live', []),
|
|
27
|
+
},
|
|
28
|
+
])
|
|
29
|
+
.call({}, blockNumber);
|
|
30
|
+
const [dsr, chi, rho, live] = data.returnData.map(item => coder.decode(['uint256'], item)[0].toString());
|
|
31
|
+
return {
|
|
32
|
+
live: !!live,
|
|
33
|
+
dsr,
|
|
34
|
+
chi,
|
|
35
|
+
rho,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
exports.getOnChainState = getOnChainState;
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dex/sdai/utils.ts"],"names":[],"mappings":";;;AAEA,4CAAyD;AAGzD,MAAM,KAAK,GAAG,IAAI,cAAQ,EAAE,CAAC;AAE7B,gCAAgC;AAChC,gCAAgC;AAChC,6BAA6B;AACtB,KAAK,UAAU,eAAe,CACnC,aAAuB,EACvB,UAAkB,EAClB,YAAuB,EACvB,WAA8B;IAE9B,MAAM,IAAI,GAA0B,MAAM,aAAa,CAAC,OAAO;SAC5D,SAAS,CAAC;QACT;YACE,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,CAAC;SACrD;QACD;YACE,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,CAAC;SACrD;QACD;YACE,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,YAAY,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,CAAC;SACrD;QACD;YACE,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,YAAY,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC;SACtD;KACF,CAAC;SACD,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAEzB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CACvD,KAAK,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAC9C,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,GAAG;QACH,GAAG;QACH,GAAG;KACJ,CAAC;AACJ,CAAC;AArCD,0CAqCC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../constants';
|
|
3
|
+
import { AdapterExchangeParam, NumberAsString, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { IDexTxBuilder } from './idex';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
6
|
+
import { IDexHelper } from '../dex-helper';
|
|
7
|
+
declare type SmoothyData = {
|
|
8
|
+
exchange: string;
|
|
9
|
+
i: string;
|
|
10
|
+
j: string;
|
|
11
|
+
};
|
|
12
|
+
declare type SmoothyParam = [
|
|
13
|
+
bTokenIdxIn: NumberAsString,
|
|
14
|
+
bTokenIdxOut: NumberAsString,
|
|
15
|
+
bTokenInAmount: NumberAsString,
|
|
16
|
+
bTokenOutMin: NumberAsString
|
|
17
|
+
];
|
|
18
|
+
export declare class Smoothy extends SimpleExchange implements IDexTxBuilder<SmoothyData, SmoothyParam> {
|
|
19
|
+
static dexKeys: string[];
|
|
20
|
+
exchangeRouterInterface: Interface;
|
|
21
|
+
minConversionRate: string;
|
|
22
|
+
constructor(dexHelper: IDexHelper);
|
|
23
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: SmoothyData, side: SwapSide): AdapterExchangeParam;
|
|
24
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: SmoothyData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|