@paraswap/dex-lib 3.8.22 → 3.8.23
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/AaveV1_lending_pool.json +27 -0
- package/build/abi/Uncompressor.json +250 -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/abi/platypus/asset.json +490 -0
- package/build/abi/platypus/avax-pool.json +820 -0
- package/build/abi/platypus/oracle.json +119 -0
- package/build/abi/platypus/pool.json +677 -0
- package/build/abi/smardex/all/smardex-router.json +648 -0
- package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
- package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
- package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
- package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
- package/build/abi/swaap-v1/pool.json +1346 -0
- package/build/dex/aave-v1/aave-v1.d.ts +33 -0
- package/build/dex/aave-v1/aave-v1.js +158 -0
- package/build/dex/aave-v1/aave-v1.js.map +1 -0
- package/build/dex/aave-v1/config.d.ts +11 -0
- package/build/dex/aave-v1/config.js +20 -0
- package/build/dex/aave-v1/config.js.map +1 -0
- package/build/dex/aave-v1/tokens-mainnet.json +134 -0
- package/build/dex/aave-v1/tokens.d.ts +3 -0
- package/build/dex/aave-v1/tokens.js +50 -0
- package/build/dex/aave-v1/tokens.js.map +1 -0
- package/build/dex/aave-v1/types.d.ts +12 -0
- package/build/dex/aave-v1/types.js +3 -0
- package/build/dex/aave-v1/types.js.map +1 -0
- 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/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/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 +376 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +85 -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/maverick-v2/config.js +4 -0
- package/build/dex/maverick-v2/config.js.map +1 -1
- package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js +4 -0
- package/build/dex/maverick-v2/maverick-math/maverick-pool-math.js.map +1 -1
- package/build/dex/maverick-v2/maverick-v2-pool.d.ts +1 -1
- package/build/dex/maverick-v2/maverick-v2-pool.js +8 -8
- package/build/dex/maverick-v2/maverick-v2-pool.js.map +1 -1
- package/build/dex/maverick-v2/maverick-v2.d.ts +5 -4
- package/build/dex/maverick-v2/maverick-v2.js +73 -63
- package/build/dex/maverick-v2/maverick-v2.js.map +1 -1
- package/build/dex/maverick-v2/types.d.ts +4 -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/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/asset.d.ts +14 -0
- package/build/dex/platypus/asset.js +97 -0
- package/build/dex/platypus/asset.js.map +1 -0
- package/build/dex/platypus/config.d.ts +11 -0
- package/build/dex/platypus/config.js +69 -0
- package/build/dex/platypus/config.js.map +1 -0
- package/build/dex/platypus/platypus.d.ts +62 -0
- package/build/dex/platypus/platypus.js +442 -0
- package/build/dex/platypus/platypus.js.map +1 -0
- package/build/dex/platypus/pool-avax.d.ts +8 -0
- package/build/dex/platypus/pool-avax.js +54 -0
- package/build/dex/platypus/pool-avax.js.map +1 -0
- package/build/dex/platypus/pool-base.d.ts +19 -0
- package/build/dex/platypus/pool-base.js +86 -0
- package/build/dex/platypus/pool-base.js.map +1 -0
- package/build/dex/platypus/pool-pure.d.ts +8 -0
- package/build/dex/platypus/pool-pure.js +37 -0
- package/build/dex/platypus/pool-pure.js.map +1 -0
- package/build/dex/platypus/pool-subscriber.d.ts +14 -0
- package/build/dex/platypus/pool-subscriber.js +167 -0
- package/build/dex/platypus/pool-subscriber.js.map +1 -0
- package/build/dex/platypus/pool.d.ts +8 -0
- package/build/dex/platypus/pool.js +58 -0
- package/build/dex/platypus/pool.js.map +1 -0
- package/build/dex/platypus/types.d.ts +92 -0
- package/build/dex/platypus/types.js +10 -0
- package/build/dex/platypus/types.js.map +1 -0
- package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
- package/build/dex/quickswap/spiritswap-v3.js +19 -0
- package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
- 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/smardex/config.d.ts +4 -0
- package/build/dex/smardex/config.js +64 -0
- package/build/dex/smardex/config.js.map +1 -0
- package/build/dex/smardex/constants.d.ts +18 -0
- package/build/dex/smardex/constants.js +33 -0
- package/build/dex/smardex/constants.js.map +1 -0
- package/build/dex/smardex/sdk/constants.d.ts +6 -0
- package/build/dex/smardex/sdk/constants.js +13 -0
- package/build/dex/smardex/sdk/constants.js.map +1 -0
- package/build/dex/smardex/sdk/core.d.ts +113 -0
- package/build/dex/smardex/sdk/core.js +499 -0
- package/build/dex/smardex/sdk/core.js.map +1 -0
- package/build/dex/smardex/sdk/errors.d.ts +15 -0
- package/build/dex/smardex/sdk/errors.js +22 -0
- package/build/dex/smardex/sdk/errors.js.map +1 -0
- package/build/dex/smardex/sdk/types.d.ts +62 -0
- package/build/dex/smardex/sdk/types.js +3 -0
- package/build/dex/smardex/sdk/types.js.map +1 -0
- package/build/dex/smardex/sdk/utils.d.ts +44 -0
- package/build/dex/smardex/sdk/utils.js +133 -0
- package/build/dex/smardex/sdk/utils.js.map +1 -0
- package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
- package/build/dex/smardex/smardex-event-pool.js +119 -0
- package/build/dex/smardex/smardex-event-pool.js.map +1 -0
- package/build/dex/smardex/smardex.d.ts +65 -0
- package/build/dex/smardex/smardex.js +519 -0
- package/build/dex/smardex/smardex.js.map +1 -0
- package/build/dex/smardex/types.d.ts +55 -0
- package/build/dex/smardex/types.js +3 -0
- package/build/dex/smardex/types.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/solidly/forks-override/cone.d.ts +22 -0
- package/build/dex/solidly/forks-override/cone.js +53 -0
- package/build/dex/solidly/forks-override/cone.js.map +1 -0
- package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
- package/build/dex/solidly/forks-override/solisnek.js +15 -0
- package/build/dex/solidly/forks-override/solisnek.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/config.d.ts +17 -0
- package/build/dex/swaap-v1/config.js +56 -0
- package/build/dex/swaap-v1/config.js.map +1 -0
- package/build/dex/swaap-v1/constants.d.ts +6 -0
- package/build/dex/swaap-v1/constants.js +17 -0
- package/build/dex/swaap-v1/constants.js.map +1 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
- package/build/dex/swaap-v1/libraries/Const.js +26 -0
- package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
- package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
- package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
- package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
- package/build/dex/swaap-v1/libraries/Num.js +167 -0
- package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
- package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
- package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
- package/build/dex/swaap-v1/libraries/Struct.js +3 -0
- package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
- package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
- package/build/dex/swaap-v1/swaap-v1.d.ts +61 -0
- package/build/dex/swaap-v1/swaap-v1.js +369 -0
- package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
- package/build/dex/swaap-v1/types.d.ts +106 -0
- package/build/dex/swaap-v1/types.js +9 -0
- package/build/dex/swaap-v1/types.js.map +1 -0
- package/build/dex/trader-joe-v2.1/optimizer.js +1 -4
- package/build/dex/trader-joe-v2.1/optimizer.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/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/package.json +1 -1
- package/src/abi/maverick-v2/MaverickV2Router.json +778 -0
- package/src/dex/maverick-v2/config.ts +4 -0
- package/src/dex/maverick-v2/maverick-math/maverick-pool-math.ts +5 -0
- package/src/dex/maverick-v2/maverick-v2-e2e.test.ts +21 -43
- package/src/dex/maverick-v2/maverick-v2-integration.test.ts +100 -96
- package/src/dex/maverick-v2/maverick-v2-pool.ts +8 -8
- package/src/dex/maverick-v2/maverick-v2.ts +111 -81
- package/src/dex/maverick-v2/types.ts +4 -0
- package/tests/constants-e2e.ts +9 -0
- package/.idea/aws.xml +0 -17
- package/.idea/codeStyles/Project.xml +0 -19
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/paraswap-dex-lib.iml +0 -9
- package/.idea/prettier.xml +0 -7
- package/.idea/vcs.xml +0 -6
- 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
|
@@ -37,11 +37,13 @@ const maverick_v2_pool_1 = require("./maverick-v2-pool");
|
|
|
37
37
|
const constants_2 = require("../../constants");
|
|
38
38
|
const abi_1 = require("@ethersproject/abi");
|
|
39
39
|
const MaverickV2Pool_json_1 = __importDefault(require("../../abi/maverick-v2/MaverickV2Pool.json"));
|
|
40
|
+
const MaverickV2Router_json_1 = __importDefault(require("../../abi/maverick-v2/MaverickV2Router.json"));
|
|
40
41
|
const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
|
|
41
42
|
const utils_2 = require("../../executor/utils");
|
|
42
|
-
const
|
|
43
|
+
const POOL_LIST_CACHE_KEY = 'maverickv2-pool-list';
|
|
44
|
+
const POOL_LIST_TTL_SECONDS = 60;
|
|
43
45
|
class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
44
|
-
constructor(network, dexKey, dexHelper, adapters = {}, config = config_1.MaverickV2Config[dexKey][network], maverickV2Iface = new abi_1.Interface(MaverickV2Pool_json_1.default)) {
|
|
46
|
+
constructor(network, dexKey, dexHelper, adapters = {}, config = config_1.MaverickV2Config[dexKey][network], maverickV2Iface = new abi_1.Interface(MaverickV2Pool_json_1.default), maverickV2RouterIface = new abi_1.Interface(MaverickV2Router_json_1.default)) {
|
|
45
47
|
super(dexHelper, dexKey);
|
|
46
48
|
this.network = network;
|
|
47
49
|
this.dexKey = dexKey;
|
|
@@ -49,6 +51,7 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
49
51
|
this.adapters = adapters;
|
|
50
52
|
this.config = config;
|
|
51
53
|
this.maverickV2Iface = maverickV2Iface;
|
|
54
|
+
this.maverickV2RouterIface = maverickV2RouterIface;
|
|
52
55
|
this.pools = {};
|
|
53
56
|
this.hasConstantPriceLargeAmounts = false;
|
|
54
57
|
this.needWrapNative = true;
|
|
@@ -56,7 +59,7 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
56
59
|
this.logger = dexHelper.getLogger(dexKey);
|
|
57
60
|
}
|
|
58
61
|
async initializePricing(blockNumber) {
|
|
59
|
-
const pools = await this._queryPoolsAPI(
|
|
62
|
+
const pools = await this._queryPoolsAPI();
|
|
60
63
|
await Promise.all(pools.map(async (pool) => {
|
|
61
64
|
const eventPool = new maverick_v2_pool_1.MaverickV2EventPool(this.dexKey, this.network, this.dexHelper, this.logger, {
|
|
62
65
|
address: pool.tokenA.address,
|
|
@@ -74,29 +77,27 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
74
77
|
getAdapters(side) {
|
|
75
78
|
return null;
|
|
76
79
|
}
|
|
80
|
+
async getEventPools(srcToken, destToken) {
|
|
81
|
+
const fromToken = this.dexHelper.config.wrapETH(srcToken);
|
|
82
|
+
const toToken = this.dexHelper.config.wrapETH(destToken);
|
|
83
|
+
return Object.values(this.pools).filter((pool) => {
|
|
84
|
+
const tokenA = pool.tokenA.address.toLowerCase();
|
|
85
|
+
const tokenB = pool.tokenB.address.toLowerCase();
|
|
86
|
+
const fromAddress = fromToken.address.toLowerCase();
|
|
87
|
+
const toAddress = toToken.address.toLowerCase();
|
|
88
|
+
return ((tokenA === fromAddress && tokenB === toAddress) ||
|
|
89
|
+
(tokenA === toAddress && tokenB === fromAddress));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
77
92
|
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
78
|
-
// TODO:
|
|
79
|
-
if (side === constants_1.SwapSide.BUY)
|
|
80
|
-
return [];
|
|
81
93
|
const from = this.dexHelper.config.wrapETH(srcToken);
|
|
82
94
|
const to = this.dexHelper.config.wrapETH(destToken);
|
|
83
95
|
if (from.address.toLowerCase() === to.address.toLowerCase()) {
|
|
84
96
|
return [];
|
|
85
97
|
}
|
|
86
|
-
const pools = await this.
|
|
98
|
+
const pools = await this.getEventPools(from, to);
|
|
87
99
|
return pools.map(pool => pool.name);
|
|
88
100
|
}
|
|
89
|
-
async getPools(srcToken, destToken) {
|
|
90
|
-
srcToken = this.dexHelper.config.wrapETH(srcToken);
|
|
91
|
-
destToken = this.dexHelper.config.wrapETH(destToken);
|
|
92
|
-
return Object.values(this.pools).filter((pool) => {
|
|
93
|
-
return ((pool.tokenA.address.toLowerCase() === srcToken.address.toLowerCase() ||
|
|
94
|
-
pool.tokenA.address.toLowerCase() ===
|
|
95
|
-
destToken.address.toLowerCase()) &&
|
|
96
|
-
(pool.tokenB.address.toLowerCase() === srcToken.address.toLowerCase() ||
|
|
97
|
-
pool.tokenB.address.toLowerCase() === destToken.address.toLowerCase()));
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
101
|
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
101
102
|
try {
|
|
102
103
|
const from = this.dexHelper.config.wrapETH(srcToken);
|
|
@@ -104,19 +105,13 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
104
105
|
if (from.address.toLowerCase() === to.address.toLowerCase()) {
|
|
105
106
|
return null;
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
-
if (side === constants_1.SwapSide.BUY)
|
|
109
|
-
return null;
|
|
110
|
-
const allPools = await this.getPools(from, to);
|
|
108
|
+
const allPools = await this.getEventPools(from, to);
|
|
111
109
|
const allowedPools = limitPools
|
|
112
110
|
? allPools.filter(pool => limitPools.includes(pool.name))
|
|
113
111
|
: allPools;
|
|
114
112
|
if (!allowedPools.length)
|
|
115
113
|
return null;
|
|
116
|
-
|
|
117
|
-
// side === SwapSide.BUY ? to.decimals : from.decimals,
|
|
118
|
-
// );
|
|
119
|
-
const unitAmount = (0, utils_1.getBigIntPow)(from.decimals);
|
|
114
|
+
const unitAmount = (0, utils_1.getBigIntPow)(side === constants_1.SwapSide.BUY ? to.decimals : from.decimals);
|
|
120
115
|
const tasks = allowedPools.map(async (pool) => {
|
|
121
116
|
try {
|
|
122
117
|
const state = await pool.getOrGenerateState(blockNumber);
|
|
@@ -124,15 +119,13 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
124
119
|
this.logger.debug(`Received null state for pool ${pool.address}`);
|
|
125
120
|
return null;
|
|
126
121
|
}
|
|
127
|
-
|
|
128
|
-
const [unit] = pool.swap(unitAmount, from, to, false);
|
|
122
|
+
const [unit] = pool.swap(unitAmount, from, to, side === constants_1.SwapSide.BUY);
|
|
129
123
|
let lastOutput = 1n;
|
|
130
124
|
const dataList = amounts.map(amount => {
|
|
131
125
|
if (amount === 0n || lastOutput === 0n) {
|
|
132
126
|
return [0n, 0n];
|
|
133
127
|
}
|
|
134
|
-
|
|
135
|
-
const output = pool.swap(amount, from, to, false);
|
|
128
|
+
const output = pool.swap(amount, from, to, side === constants_1.SwapSide.BUY);
|
|
136
129
|
lastOutput = output[0];
|
|
137
130
|
return output;
|
|
138
131
|
});
|
|
@@ -178,36 +171,43 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
178
171
|
networkFee: '0',
|
|
179
172
|
};
|
|
180
173
|
}
|
|
181
|
-
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side
|
|
182
|
-
// TODO:
|
|
183
|
-
if (side === constants_1.SwapSide.BUY)
|
|
184
|
-
throw new Error(`Buy not supported`);
|
|
174
|
+
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
|
|
185
175
|
const { pool } = data;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
176
|
+
const from = this.dexHelper.config.wrapETH(srcToken);
|
|
177
|
+
const tokenAIn = data.tokenA.toLowerCase() === from.toLowerCase();
|
|
178
|
+
const tickLimit = tokenAIn
|
|
179
|
+
? BigInt(data.activeTick) + 100n
|
|
180
|
+
: BigInt(data.activeTick) - 100n;
|
|
181
|
+
if (side === constants_1.SwapSide.SELL) {
|
|
182
|
+
// Perform direct swap for SELL side
|
|
183
|
+
const exchangeData = this.maverickV2Iface.encodeFunctionData('swap', [
|
|
184
|
+
recipient,
|
|
185
|
+
{
|
|
186
|
+
amount: srcAmount,
|
|
187
|
+
tokenAIn,
|
|
188
|
+
exactOutput: false,
|
|
189
|
+
tickLimit,
|
|
190
|
+
},
|
|
191
|
+
'0x',
|
|
192
|
+
]);
|
|
193
|
+
return {
|
|
194
|
+
needWrapNative: this.needWrapNative,
|
|
195
|
+
transferSrcTokenBeforeSwap: pool,
|
|
196
|
+
skipApproval: true,
|
|
197
|
+
targetExchange: pool,
|
|
198
|
+
dexFuncHasRecipient: true,
|
|
199
|
+
exchangeData,
|
|
200
|
+
returnAmountPos: (0, utils_2.extractReturnAmountPosition)(this.maverickV2Iface, 'swap', 'amountOut'),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// perform "exactOutputSingleMinimal" via MaverickV2's Router
|
|
204
|
+
const exchangeData = this.maverickV2RouterIface.encodeFunctionData('exactOutputSingleMinimal', [recipient, pool, tokenAIn, destAmount, tickLimit]);
|
|
201
205
|
return {
|
|
202
206
|
needWrapNative: this.needWrapNative,
|
|
203
|
-
|
|
204
|
-
// skipApproval: true,
|
|
205
|
-
targetExchange: pool,
|
|
207
|
+
targetExchange: this.config.routerAddress,
|
|
206
208
|
dexFuncHasRecipient: true,
|
|
207
209
|
exchangeData,
|
|
208
|
-
returnAmountPos:
|
|
209
|
-
? (0, utils_2.extractReturnAmountPosition)(this.maverickV2Iface, 'swap', 'amountOut')
|
|
210
|
-
: undefined,
|
|
210
|
+
returnAmountPos: (0, utils_2.extractReturnAmountPosition)(this.maverickV2RouterIface, 'exactOutputSingleMinimal', 'amountOut_'),
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
213
|
// This is called once before getTopPoolsForToken is
|
|
@@ -221,13 +221,15 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
221
221
|
// Returns list of top pools based on liquidity. Max
|
|
222
222
|
// limit number pools should be returned.
|
|
223
223
|
async getTopPoolsForToken(tokenAddress, limit) {
|
|
224
|
-
const _tokenAddress = this.dexHelper.config
|
|
225
|
-
|
|
224
|
+
const _tokenAddress = this.dexHelper.config
|
|
225
|
+
.wrapETH(tokenAddress)
|
|
226
|
+
.toLowerCase();
|
|
227
|
+
const pools = await this._queryPoolsAPI();
|
|
226
228
|
if (!pools.length) {
|
|
227
229
|
this.logger.error(`Error_${this.dexKey}_Subgraph: couldn't fetch the pools from the subgraph`);
|
|
228
230
|
return [];
|
|
229
231
|
}
|
|
230
|
-
const filteredPools =
|
|
232
|
+
const filteredPools = pools.filter(pool => {
|
|
231
233
|
return (pool.tokenA.address.toLowerCase() === _tokenAddress ||
|
|
232
234
|
pool.tokenB.address.toLowerCase() === _tokenAddress);
|
|
233
235
|
});
|
|
@@ -244,15 +246,23 @@ class MaverickV2 extends simple_exchange_1.SimpleExchange {
|
|
|
244
246
|
decimals: token.decimals,
|
|
245
247
|
},
|
|
246
248
|
],
|
|
247
|
-
liquidityUSD: pool.tvl.amount
|
|
249
|
+
liquidityUSD: pool.tvl.amount,
|
|
248
250
|
};
|
|
249
251
|
});
|
|
250
|
-
|
|
252
|
+
const sortedPools = lodash_1.default.sortBy(labeledPools, [
|
|
253
|
+
pool => -1 * pool.liquidityUSD,
|
|
254
|
+
]);
|
|
255
|
+
return lodash_1.default.slice(sortedPools, 0, limit);
|
|
251
256
|
}
|
|
252
|
-
async _queryPoolsAPI(
|
|
257
|
+
async _queryPoolsAPI() {
|
|
258
|
+
let cachedPoolsJson = await this.dexHelper.cache.getAndCacheLocally(this.dexKey, this.network, POOL_LIST_CACHE_KEY, POOL_LIST_TTL_SECONDS);
|
|
259
|
+
if (cachedPoolsJson)
|
|
260
|
+
return JSON.parse(cachedPoolsJson);
|
|
253
261
|
try {
|
|
254
|
-
const res = await this.dexHelper.httpRequest.get(`${config_1.MAVERICK_API_URL}/api/v5/poolsNoBins/${this.network}`,
|
|
255
|
-
|
|
262
|
+
const res = await this.dexHelper.httpRequest.get(`${config_1.MAVERICK_API_URL}/api/v5/poolsNoBins/${this.network}`, constants_2.SUBGRAPH_TIMEOUT);
|
|
263
|
+
const pools = res.pools || [];
|
|
264
|
+
await this.dexHelper.cache.setex(this.dexKey, this.network, POOL_LIST_CACHE_KEY, POOL_LIST_TTL_SECONDS, JSON.stringify(pools));
|
|
265
|
+
return pools;
|
|
256
266
|
}
|
|
257
267
|
catch (e) {
|
|
258
268
|
this.logger.error(`${this.dexKey}: can not query subgraph: `, e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maverick-v2.js","sourceRoot":"","sources":["../../../src/dex/maverick-v2/maverick-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AAYvB,+CAAkE;AAClE,2EAA6D;AAC7D,uCAA4E;AAI5E,wDAAoD;AACpD,qCAKkB;AAClB,yDAAyD;AACzD,+CAAmD;AACnD,4CAA+C;AAC/C,oGAA0E;AAC1E,sEAA4C;AAC5C,gDAAmE;
|
|
1
|
+
{"version":3,"file":"maverick-v2.js","sourceRoot":"","sources":["../../../src/dex/maverick-v2/maverick-v2.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AAYvB,+CAAkE;AAClE,2EAA6D;AAC7D,uCAA4E;AAI5E,wDAAoD;AACpD,qCAKkB;AAClB,yDAAyD;AACzD,+CAAmD;AACnD,4CAA+C;AAC/C,oGAA0E;AAC1E,wGAA8E;AAC9E,sEAA4C;AAC5C,gDAAmE;AAEnE,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AACnD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAa,UAAW,SAAQ,gCAAc;IAc5C,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,EAAE,EACb,SAAS,yBAAgB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAC1C,kBAAkB,IAAI,eAAS,CAAC,6BAAiB,CAAC,EAClD,wBAAwB,IAAI,eAAS,CAAC,+BAAmB,CAAC;QAEpE,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QARhB,YAAO,GAAP,OAAO,CAAS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M,EACX,IAAI,CAAC,OAAO,EACZ,mBAAmB,EACnB,qBAAqB,CACtB,CAAC;QAEF,IAAI,eAAe;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAExD,IAAI;YACF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAC9C,GAAG,yBAAgB,uBAAuB,IAAI,CAAC,OAAO,EAAE,EACxD,4BAAgB,CACjB,CAAC;YAEF,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YAE9B,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAC9B,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CACtB,CAAC;YAEF,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,4BAA4B,EAAE,CAAC,CAAC,CAAC;YACjE,OAAO,EAAE,CAAC;SACX;IACH,CAAC;;AAnXH,gCAoXC;AA7We,6BAAkB,GAC9B,IAAA,6BAAqB,EAAC,yBAAgB,CAAC,CAAC;AAI5B,yBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC"}
|
|
@@ -112,6 +112,7 @@ export declare type MaverickV2Param = {
|
|
|
112
112
|
data: string;
|
|
113
113
|
};
|
|
114
114
|
export declare type DexParams = {
|
|
115
|
+
routerAddress: string;
|
|
115
116
|
quoterAddress: string;
|
|
116
117
|
poolLensAddress: string;
|
|
117
118
|
};
|
|
@@ -123,6 +124,9 @@ export declare type PoolAPIResponse = {
|
|
|
123
124
|
lowerTick: number;
|
|
124
125
|
tickSpacing: number;
|
|
125
126
|
id: string;
|
|
127
|
+
volume: {
|
|
128
|
+
amount: number;
|
|
129
|
+
};
|
|
126
130
|
tokenA: {
|
|
127
131
|
name: string;
|
|
128
132
|
symbol: string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { SwapSide } from '../constants';
|
|
3
|
+
import { AdapterExchangeParam, Address, SimpleExchangeParam } from '../types';
|
|
4
|
+
import { IDexTxBuilder } from './idex';
|
|
5
|
+
import { SimpleExchange } from './simple-exchange';
|
|
6
|
+
import { IDexHelper } from '../dex-helper';
|
|
7
|
+
export declare type OnebitData = {
|
|
8
|
+
router: Address;
|
|
9
|
+
};
|
|
10
|
+
declare type OnebitParam = [
|
|
11
|
+
srcToken: string,
|
|
12
|
+
destToken: string,
|
|
13
|
+
srcAmount: string,
|
|
14
|
+
destAmountMin: string,
|
|
15
|
+
to: string
|
|
16
|
+
];
|
|
17
|
+
export declare class Onebit extends SimpleExchange implements IDexTxBuilder<OnebitData, OnebitParam> {
|
|
18
|
+
static dexKeys: string[];
|
|
19
|
+
exchangeRouterInterface: Interface;
|
|
20
|
+
needWrapNative: boolean;
|
|
21
|
+
constructor(dexHelper: IDexHelper);
|
|
22
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OnebitData, side: SwapSide): AdapterExchangeParam;
|
|
23
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OnebitData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
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.Onebit = void 0;
|
|
7
|
+
const abi_1 = require("@ethersproject/abi");
|
|
8
|
+
const simple_exchange_1 = require("./simple-exchange");
|
|
9
|
+
const Onebit_json_1 = __importDefault(require("../abi/Onebit.json"));
|
|
10
|
+
var OnebitFunctions;
|
|
11
|
+
(function (OnebitFunctions) {
|
|
12
|
+
OnebitFunctions["swapTokensWithTrust"] = "swapTokensWithTrust";
|
|
13
|
+
})(OnebitFunctions || (OnebitFunctions = {}));
|
|
14
|
+
class Onebit extends simple_exchange_1.SimpleExchange {
|
|
15
|
+
constructor(dexHelper) {
|
|
16
|
+
super(dexHelper, 'omm1');
|
|
17
|
+
this.needWrapNative = true;
|
|
18
|
+
this.exchangeRouterInterface = new abi_1.Interface(Onebit_json_1.default);
|
|
19
|
+
}
|
|
20
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
21
|
+
return {
|
|
22
|
+
targetExchange: data.router,
|
|
23
|
+
payload: '0x',
|
|
24
|
+
networkFee: '0',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
28
|
+
const swapFunction = OnebitFunctions.swapTokensWithTrust;
|
|
29
|
+
const swapFunctionParams = [
|
|
30
|
+
srcToken,
|
|
31
|
+
destToken,
|
|
32
|
+
srcAmount,
|
|
33
|
+
destAmount,
|
|
34
|
+
this.augustusAddress,
|
|
35
|
+
];
|
|
36
|
+
const swapData = this.exchangeRouterInterface.encodeFunctionData(swapFunction, swapFunctionParams);
|
|
37
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, data.router);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Onebit = Onebit;
|
|
41
|
+
Onebit.dexKeys = ['omm1'];
|
|
42
|
+
//# sourceMappingURL=onebit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onebit.js","sourceRoot":"","sources":["../../src/dex/onebit.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA6D;AAK7D,uDAAmD;AACnD,qEAA2C;AAc3C,IAAK,eAEJ;AAFD,WAAK,eAAe;IAClB,8DAA2C,CAAA;AAC7C,CAAC,EAFI,eAAe,KAAf,eAAe,QAEnB;AAED,MAAa,MACX,SAAQ,gCAAc;IAOtB,YAAY,SAAqB;QAC/B,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAH3B,mBAAc,GAAG,IAAI,CAAC;QAIpB,IAAI,CAAC,uBAAuB,GAAG,IAAI,eAAS,CAAC,qBAA2B,CAAC,CAAC;IAC5E,CAAC;IAED,eAAe,CACb,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAgB,EAChB,IAAc;QAEd,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,MAAM;YAC3B,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAgB,EAChB,IAAc;QAEd,MAAM,YAAY,GAAG,eAAe,CAAC,mBAAmB,CAAC;QACzD,MAAM,kBAAkB,GAAgB;YACtC,QAAQ;YACR,SAAS;YACT,SAAS;YACT,UAAU;YACV,IAAI,CAAC,eAAe;SACrB,CAAC;QACF,MAAM,QAAQ,GAAG,IAAI,CAAC,uBAAuB,CAAC,kBAAkB,CAC9D,YAAY,EACZ,kBAAkB,CACnB,CAAC;QAEF,OAAO,IAAI,CAAC,qCAAqC,CAC/C,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,IAAI,CAAC,MAAM,CACZ,CAAC;IACJ,CAAC;;AAzDH,wBA0DC;AAtDQ,cAAO,GAAG,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -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,GAM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