@paraswap/dex-lib 3.8.2 → 3.8.3
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 +13 -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/aave-v3/aave-v3.js +2 -1
- package/build/dex/aave-v3/aave-v3.js.map +1 -1
- package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
- package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
- package/build/dex/angle-staked-stable/angle-staked-stable.js +4 -1
- package/build/dex/angle-staked-stable/angle-staked-stable.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/compound.js +2 -1
- package/build/dex/compound/compound.js.map +1 -1
- 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/etherfi.js +4 -1
- package/build/dex/etherfi.js.map +1 -1
- package/build/dex/idle-dao/idle-dao.js +1 -0
- package/build/dex/idle-dao/idle-dao.js.map +1 -1
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +33 -0
- package/build/dex/integral/context.js +98 -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 +21 -0
- package/build/dex/integral/integral-factory.js +92 -0
- package/build/dex/integral/integral-factory.js.map +1 -0
- package/build/dex/integral/integral-pool.d.ts +46 -0
- package/build/dex/integral/integral-pool.js +143 -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 +39 -0
- package/build/dex/integral/integral-relayer.js +189 -0
- package/build/dex/integral/integral-relayer.js.map +1 -0
- package/build/dex/integral/integral-token.d.ts +22 -0
- package/build/dex/integral/integral-token.js +55 -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 +382 -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.d.ts +6 -0
- package/build/dex/integral/utils.js +23 -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/mStable.js +1 -1
- package/build/dex/mStable.js.map +1 -1
- 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/simple-exchange.d.ts +1 -1
- package/build/dex/simple-exchange.js +4 -2
- package/build/dex/simple-exchange.js.map +1 -1
- 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/spark/spark.js +2 -1
- package/build/dex/spark/spark.js.map +1 -1
- 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.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 +3 -1
- package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor02BytecodeBuilder.js +3 -1
- package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
- package/build/executor/Executor03BytecodeBuilder.js +2 -0
- package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
- package/build/executor/ExecutorBytecodeBuilder.js +2 -0
- package/build/executor/ExecutorBytecodeBuilder.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/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/dex/aave-v3/aave-v3-e2e.test.ts +4 -9
- package/src/dex/aave-v3/aave-v3.ts +5 -0
- package/src/dex/aave-v3-stata/aave-v3-stata.ts +1 -0
- package/src/dex/angle-staked-stable/angle-staked-stable.ts +8 -0
- package/src/dex/compound/compound.ts +5 -0
- package/src/dex/etherfi.ts +5 -0
- package/src/dex/idle-dao/idle-dao.ts +1 -0
- package/src/dex/simple-exchange.ts +5 -5
- package/src/dex/spark/spark-e2e.test.ts +9 -1
- package/src/dex/spark/spark.ts +5 -0
- package/src/executor/Executor01BytecodeBuilder.ts +3 -1
- package/src/executor/Executor02BytecodeBuilder.ts +3 -1
- package/src/executor/Executor03BytecodeBuilder.ts +2 -0
- package/src/executor/ExecutorBytecodeBuilder.ts +2 -0
- package/src/executor/executor01-bytecode-builder-e2e.test.ts +25 -0
- package/src/executor/executor02-bytecode-builder-e2e.test.ts +29 -0
- package/src/types.ts +1 -0
- package/tests/constants-e2e.ts +13 -13
- package/tests/utils-e2e.ts +1 -1
- 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
|
@@ -0,0 +1,442 @@
|
|
|
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.Platypus = void 0;
|
|
30
|
+
const abi_1 = require("@ethersproject/abi");
|
|
31
|
+
const constants_1 = require("../../constants");
|
|
32
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
33
|
+
const utils_1 = require("../../utils");
|
|
34
|
+
const types_1 = require("./types");
|
|
35
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
36
|
+
const config_1 = require("./config");
|
|
37
|
+
const chainlink_1 = require("../../lib/chainlink");
|
|
38
|
+
const pool_1 = require("./pool");
|
|
39
|
+
const pool_pure_1 = require("./pool-pure");
|
|
40
|
+
const pool_avax_1 = require("./pool-avax");
|
|
41
|
+
const erc20_json_1 = __importDefault(require("../../abi/erc20.json"));
|
|
42
|
+
const pool_json_1 = __importDefault(require("../../abi/platypus/pool.json"));
|
|
43
|
+
const avax_pool_json_1 = __importDefault(require("../../abi/platypus/avax-pool.json"));
|
|
44
|
+
const asset_json_1 = __importDefault(require("../../abi/platypus/asset.json"));
|
|
45
|
+
const oracle_json_1 = __importDefault(require("../../abi/platypus/oracle.json"));
|
|
46
|
+
class Platypus extends simple_exchange_1.SimpleExchange {
|
|
47
|
+
constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network]) {
|
|
48
|
+
super(dexHelper, dexKey);
|
|
49
|
+
this.network = network;
|
|
50
|
+
this.dexHelper = dexHelper;
|
|
51
|
+
this.adapters = adapters;
|
|
52
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
53
|
+
this.isFeeOnTransferSupported = false;
|
|
54
|
+
this.config = config_1.PlatypusConfig[dexKey][network];
|
|
55
|
+
this.logger = dexHelper.getLogger(`${dexKey}-${network}`);
|
|
56
|
+
}
|
|
57
|
+
async generateConfigInfo(blockNumber) {
|
|
58
|
+
const cfgInfo = {
|
|
59
|
+
poolAddresses: [],
|
|
60
|
+
pools: {},
|
|
61
|
+
};
|
|
62
|
+
// Need to filter pools in case we are testing against an old block where the pool didn't exist!
|
|
63
|
+
for (const p of this.config.pools) {
|
|
64
|
+
// When there's no code, getCode should return '0x' but could return '0x0' instead
|
|
65
|
+
if ((await this.dexHelper.web3Provider.eth.getCode(p.address, blockNumber))
|
|
66
|
+
.length > 3) {
|
|
67
|
+
const poolAddress = p.address.toLowerCase();
|
|
68
|
+
cfgInfo.poolAddresses.push(poolAddress);
|
|
69
|
+
if (p.oracleType === types_1.PlatypusOracleType.None) {
|
|
70
|
+
cfgInfo.pools[poolAddress] = {
|
|
71
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
72
|
+
tokenAddresses: [],
|
|
73
|
+
tokens: {},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else if (p.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
77
|
+
cfgInfo.pools[poolAddress] = {
|
|
78
|
+
oracleType: types_1.PlatypusOracleType.ChainLink,
|
|
79
|
+
priceOracleAddress: '',
|
|
80
|
+
tokenAddresses: [],
|
|
81
|
+
tokens: {},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else if (p.oracleType === types_1.PlatypusOracleType.StakedAvax) {
|
|
85
|
+
cfgInfo.pools[poolAddress] = {
|
|
86
|
+
oracleType: types_1.PlatypusOracleType.StakedAvax,
|
|
87
|
+
priceOracleAddress: '',
|
|
88
|
+
tokenAddresses: [],
|
|
89
|
+
tokens: {},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw new Error(`Invalid pool oracle type in ${this.dexKey}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
let inputs = [];
|
|
98
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
99
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
100
|
+
if (pool.oracleType !== types_1.PlatypusOracleType.None) {
|
|
101
|
+
inputs.push({
|
|
102
|
+
target: poolAddress,
|
|
103
|
+
callData: Platypus.poolInterface.encodeFunctionData('getPriceOracle'),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
inputs.push({
|
|
107
|
+
target: poolAddress,
|
|
108
|
+
callData: Platypus.poolInterface.encodeFunctionData('getTokenAddresses'),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
let returnData = (await this.dexHelper.multiContract.methods
|
|
112
|
+
.aggregate(inputs)
|
|
113
|
+
.call({}, blockNumber)).returnData;
|
|
114
|
+
let i = 0;
|
|
115
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
116
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
117
|
+
if (pool.oracleType !== types_1.PlatypusOracleType.None) {
|
|
118
|
+
pool.priceOracleAddress = Platypus.poolInterface
|
|
119
|
+
.decodeFunctionResult('getPriceOracle', returnData[i++])[0]
|
|
120
|
+
.toLowerCase();
|
|
121
|
+
}
|
|
122
|
+
pool.tokenAddresses = Platypus.poolInterface
|
|
123
|
+
.decodeFunctionResult('getTokenAddresses', returnData[i++])[0]
|
|
124
|
+
.map((a) => a.toLowerCase());
|
|
125
|
+
}
|
|
126
|
+
inputs = [];
|
|
127
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
128
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
129
|
+
for (const tokenAddress of pool.tokenAddresses) {
|
|
130
|
+
inputs.push({
|
|
131
|
+
target: tokenAddress,
|
|
132
|
+
callData: Platypus.erc20Interface.encodeFunctionData('symbol'),
|
|
133
|
+
});
|
|
134
|
+
inputs.push({
|
|
135
|
+
target: tokenAddress,
|
|
136
|
+
callData: Platypus.erc20Interface.encodeFunctionData('decimals'),
|
|
137
|
+
});
|
|
138
|
+
inputs.push({
|
|
139
|
+
target: poolAddress,
|
|
140
|
+
callData: Platypus.poolInterface.encodeFunctionData('assetOf', [
|
|
141
|
+
tokenAddress,
|
|
142
|
+
]),
|
|
143
|
+
});
|
|
144
|
+
if (pool.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
145
|
+
inputs.push({
|
|
146
|
+
target: pool.priceOracleAddress,
|
|
147
|
+
callData: Platypus.oracleInterface.encodeFunctionData('getSourceOfAsset', [tokenAddress]),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
returnData = (await this.dexHelper.multiContract.methods
|
|
153
|
+
.aggregate(inputs)
|
|
154
|
+
.call({}, blockNumber)).returnData;
|
|
155
|
+
i = 0;
|
|
156
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
157
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
158
|
+
for (const tokenAddress of pool.tokenAddresses) {
|
|
159
|
+
const tokenSymbol = Platypus.erc20Interface.decodeFunctionResult('symbol', returnData[i++])[0];
|
|
160
|
+
const tokenDecimals = Platypus.erc20Interface.decodeFunctionResult('decimals', returnData[i++])[0];
|
|
161
|
+
const assetAddress = Platypus.poolInterface
|
|
162
|
+
.decodeFunctionResult('assetOf', returnData[i++])[0]
|
|
163
|
+
.toLowerCase();
|
|
164
|
+
if (pool.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
165
|
+
const proxyAddress = Platypus.oracleInterface
|
|
166
|
+
.decodeFunctionResult('getSourceOfAsset', returnData[i++])[0]
|
|
167
|
+
.toLowerCase();
|
|
168
|
+
pool.tokens[tokenAddress] = {
|
|
169
|
+
tokenSymbol,
|
|
170
|
+
tokenDecimals,
|
|
171
|
+
assetAddress,
|
|
172
|
+
chainlink: {
|
|
173
|
+
proxyAddress,
|
|
174
|
+
aggregatorAddress: '',
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
pool.tokens[tokenAddress] = {
|
|
180
|
+
tokenSymbol,
|
|
181
|
+
tokenDecimals,
|
|
182
|
+
assetAddress,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
inputs = [];
|
|
188
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
189
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
190
|
+
if (pool.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
191
|
+
for (const tokenAddress of pool.tokenAddresses) {
|
|
192
|
+
inputs.push(chainlink_1.ChainLinkSubscriber.getReadAggregatorMultiCallInput(pool.tokens[tokenAddress].chainlink.proxyAddress));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
returnData = (await this.dexHelper.multiContract.methods
|
|
197
|
+
.aggregate(inputs)
|
|
198
|
+
.call({}, blockNumber)).returnData;
|
|
199
|
+
i = 0;
|
|
200
|
+
for (const poolAddress of cfgInfo.poolAddresses) {
|
|
201
|
+
const pool = cfgInfo.pools[poolAddress];
|
|
202
|
+
if (pool.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
203
|
+
for (const tokenAddress of pool.tokenAddresses) {
|
|
204
|
+
pool.tokens[tokenAddress].chainlink.aggregatorAddress =
|
|
205
|
+
chainlink_1.ChainLinkSubscriber.readAggregator(returnData[i++]).toLowerCase();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return cfgInfo;
|
|
210
|
+
}
|
|
211
|
+
async init(blockNumber) {
|
|
212
|
+
if (this.cfgInfo)
|
|
213
|
+
return;
|
|
214
|
+
this.cfgInfo = await this.generateConfigInfo(blockNumber);
|
|
215
|
+
}
|
|
216
|
+
// Initialize pricing is called once in the start of
|
|
217
|
+
// pricing service. It is intended to setup the integration
|
|
218
|
+
// for pricing requests. It is optional for a DEX to
|
|
219
|
+
// implement this function
|
|
220
|
+
async initializePricing(blockNumber) {
|
|
221
|
+
await this.init(blockNumber);
|
|
222
|
+
if (!this.cfgInfo)
|
|
223
|
+
throw new Error(`initializePricing: ${this.dexKey} cfgInfo still null after init`);
|
|
224
|
+
const eventPools = {};
|
|
225
|
+
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
226
|
+
const cfgPool = this.cfgInfo.pools[poolAddress];
|
|
227
|
+
const poolName = this.config.pools.find(p => p.address.toLowerCase() === poolAddress).name;
|
|
228
|
+
let pool;
|
|
229
|
+
if (cfgPool.oracleType === types_1.PlatypusOracleType.None) {
|
|
230
|
+
pool = new pool_pure_1.PlatypusPurePool(this.dexKey, this.network, poolName, poolAddress, cfgPool, this.dexHelper);
|
|
231
|
+
}
|
|
232
|
+
else if (cfgPool.oracleType === types_1.PlatypusOracleType.ChainLink) {
|
|
233
|
+
pool = new pool_1.PlatypusPool(this.dexKey, this.network, poolName, poolAddress, cfgPool, this.dexHelper);
|
|
234
|
+
}
|
|
235
|
+
else if (cfgPool.oracleType === types_1.PlatypusOracleType.StakedAvax) {
|
|
236
|
+
pool = new pool_avax_1.PlatypusAvaxPool(this.dexKey, this.network, poolName, poolAddress, cfgPool, this.dexHelper);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
throw new Error(`${this.dexKey} cfgInfo invalid pool type`);
|
|
240
|
+
}
|
|
241
|
+
await pool.initialize(blockNumber);
|
|
242
|
+
eventPools[poolAddress] = pool;
|
|
243
|
+
}
|
|
244
|
+
this.eventPools = eventPools;
|
|
245
|
+
}
|
|
246
|
+
// Returns the list of contract adapters (name and index)
|
|
247
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
248
|
+
getAdapters(side) {
|
|
249
|
+
return this.adapters[side];
|
|
250
|
+
}
|
|
251
|
+
findPools(srcTokenAddress, destTokenAddress) {
|
|
252
|
+
if (!this.cfgInfo)
|
|
253
|
+
return [];
|
|
254
|
+
return Object.entries(this.cfgInfo.pools)
|
|
255
|
+
.filter(([poolAddress, poolConfig]) => poolConfig.tokenAddresses.includes(srcTokenAddress) &&
|
|
256
|
+
poolConfig.tokenAddresses.includes(destTokenAddress))
|
|
257
|
+
.map(([poolAddress, poolConfig]) => poolAddress);
|
|
258
|
+
}
|
|
259
|
+
getPoolIdentifier(poolAddress) {
|
|
260
|
+
return `${this.dexKey}_${poolAddress}`;
|
|
261
|
+
}
|
|
262
|
+
// Returns list of pool identifiers that can be used
|
|
263
|
+
// for a given swap. poolIdentifers must be unique
|
|
264
|
+
// across DEXes. It is recommended to use
|
|
265
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
266
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
267
|
+
if (side === constants_1.SwapSide.BUY)
|
|
268
|
+
return [];
|
|
269
|
+
return this.findPools(this.dexHelper.config.wrapETH(srcToken).address.toLowerCase(), this.dexHelper.config.wrapETH(destToken).address.toLowerCase()).map(p => this.getPoolIdentifier(p));
|
|
270
|
+
}
|
|
271
|
+
// Returns pool prices for amounts.
|
|
272
|
+
// If limitPools is defined only pools in limitPools
|
|
273
|
+
// should be used. If limitPools is undefined then
|
|
274
|
+
// any pools can be used.
|
|
275
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
276
|
+
if (side === constants_1.SwapSide.BUY)
|
|
277
|
+
return null;
|
|
278
|
+
if (!this.eventPools) {
|
|
279
|
+
this.logger.error(`Missing event pools for ${this.dexKey} in getPricesVolume`);
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
const srcTokenAddress = this.dexHelper.config
|
|
283
|
+
.wrapETH(srcToken)
|
|
284
|
+
.address.toLowerCase();
|
|
285
|
+
const destTokenAddress = this.dexHelper.config
|
|
286
|
+
.wrapETH(destToken)
|
|
287
|
+
.address.toLowerCase();
|
|
288
|
+
if (srcTokenAddress === destTokenAddress)
|
|
289
|
+
return null;
|
|
290
|
+
return (await Promise.all(this.findPools(srcTokenAddress, destTokenAddress)
|
|
291
|
+
.filter(poolAddress => !limitPools ||
|
|
292
|
+
limitPools.includes(this.getPoolIdentifier(poolAddress)))
|
|
293
|
+
.map(poolAddress => (async (pool) => {
|
|
294
|
+
let state = pool.getState(blockNumber);
|
|
295
|
+
if (!state) {
|
|
296
|
+
state = await pool.generateState(blockNumber);
|
|
297
|
+
pool.setState(state, blockNumber);
|
|
298
|
+
}
|
|
299
|
+
if (state.params.paused)
|
|
300
|
+
return null;
|
|
301
|
+
const [unit, ...prices] = pool.computePrices({
|
|
302
|
+
address: srcTokenAddress,
|
|
303
|
+
decimals: srcToken.decimals,
|
|
304
|
+
}, {
|
|
305
|
+
address: destTokenAddress,
|
|
306
|
+
decimals: destToken.decimals,
|
|
307
|
+
}, [(0, utils_1.getBigIntPow)(srcToken.decimals), ...amounts], state);
|
|
308
|
+
const ret = {
|
|
309
|
+
prices,
|
|
310
|
+
unit,
|
|
311
|
+
data: {
|
|
312
|
+
pool: poolAddress,
|
|
313
|
+
},
|
|
314
|
+
poolAddresses: [poolAddress],
|
|
315
|
+
exchange: this.dexKey,
|
|
316
|
+
gasCost: 260 * 1000,
|
|
317
|
+
poolIdentifier: this.getPoolIdentifier(poolAddress),
|
|
318
|
+
};
|
|
319
|
+
return ret;
|
|
320
|
+
})(this.eventPools[poolAddress])))).filter((p) => !!p);
|
|
321
|
+
}
|
|
322
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
323
|
+
getCalldataGasCost(poolPrices) {
|
|
324
|
+
return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
|
|
325
|
+
}
|
|
326
|
+
// Encode params required by the exchange adapter
|
|
327
|
+
// Used for multiSwap, buy & megaSwap
|
|
328
|
+
// Hint: abiCoder.encodeParameter() couls be useful
|
|
329
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
330
|
+
return {
|
|
331
|
+
targetExchange: data.pool,
|
|
332
|
+
payload: '0x',
|
|
333
|
+
networkFee: '0',
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// Encode call data used by simpleSwap like routers
|
|
337
|
+
// Used for simpleSwap & simpleBuy
|
|
338
|
+
// Hint: this.buildSimpleParamWithoutWETHConversion
|
|
339
|
+
// could be useful
|
|
340
|
+
async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
341
|
+
return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, (0, utils_1.isETHAddress)(srcToken)
|
|
342
|
+
? Platypus.avaxPoolInterface.encodeFunctionData('swapFromETH', [
|
|
343
|
+
destToken,
|
|
344
|
+
1,
|
|
345
|
+
this.augustusAddress,
|
|
346
|
+
(0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
347
|
+
])
|
|
348
|
+
: (0, utils_1.isETHAddress)(destToken)
|
|
349
|
+
? Platypus.avaxPoolInterface.encodeFunctionData('swapToETH', [
|
|
350
|
+
srcToken,
|
|
351
|
+
srcAmount,
|
|
352
|
+
1,
|
|
353
|
+
this.augustusAddress,
|
|
354
|
+
(0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
355
|
+
])
|
|
356
|
+
: Platypus.poolInterface.encodeFunctionData('swap', [
|
|
357
|
+
srcToken,
|
|
358
|
+
destToken,
|
|
359
|
+
srcAmount,
|
|
360
|
+
1,
|
|
361
|
+
this.augustusAddress,
|
|
362
|
+
(0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)(),
|
|
363
|
+
]), data.pool);
|
|
364
|
+
}
|
|
365
|
+
// This is called once before getTopPoolsForToken is
|
|
366
|
+
// called for multiple tokens. This can be helpful to
|
|
367
|
+
// update common state required for calculating
|
|
368
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
369
|
+
// to implement this
|
|
370
|
+
async updatePoolState() {
|
|
371
|
+
const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
|
|
372
|
+
await this.init(blockNumber);
|
|
373
|
+
if (!this.cfgInfo)
|
|
374
|
+
throw new Error('updatePoolState: Platypus cfgInfo still null after init');
|
|
375
|
+
// All tokens are USD stablecoins so to estimate liquidity can just add
|
|
376
|
+
// the cash balances of all the tokens
|
|
377
|
+
const poolLiquidityUSD = {};
|
|
378
|
+
let inputs = [];
|
|
379
|
+
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
380
|
+
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
381
|
+
.tokenAddresses) {
|
|
382
|
+
inputs.push({
|
|
383
|
+
target: this.cfgInfo.pools[poolAddress].tokens[tokenAddress].assetAddress,
|
|
384
|
+
callData: Platypus.assetInterface.encodeFunctionData('cash'),
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const returnData = (await this.dexHelper.multiContract.methods
|
|
389
|
+
.aggregate(inputs)
|
|
390
|
+
.call({}, blockNumber)).returnData;
|
|
391
|
+
const usdPromises = [];
|
|
392
|
+
let i = 0;
|
|
393
|
+
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
394
|
+
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
395
|
+
.tokenAddresses) {
|
|
396
|
+
usdPromises.push(this.dexHelper.getTokenUSDPrice({
|
|
397
|
+
address: tokenAddress,
|
|
398
|
+
decimals: this.cfgInfo.pools[poolAddress].tokens[tokenAddress]
|
|
399
|
+
.tokenDecimals,
|
|
400
|
+
}, BigInt(Platypus.assetInterface
|
|
401
|
+
.decodeFunctionResult('cash', returnData[i++])[0]
|
|
402
|
+
.toString())));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const usdValues = await Promise.all(usdPromises);
|
|
406
|
+
i = 0;
|
|
407
|
+
for (const poolAddress of this.cfgInfo.poolAddresses) {
|
|
408
|
+
poolLiquidityUSD[poolAddress] = 0;
|
|
409
|
+
for (const tokenAddress of this.cfgInfo.pools[poolAddress]
|
|
410
|
+
.tokenAddresses) {
|
|
411
|
+
poolLiquidityUSD[poolAddress] += usdValues[i++];
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
this.poolLiquidityUSD = poolLiquidityUSD;
|
|
415
|
+
}
|
|
416
|
+
// Returns list of top pools based on liquidity. Max
|
|
417
|
+
// limit number pools should be returned.
|
|
418
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
419
|
+
if (!this.cfgInfo || !this.poolLiquidityUSD)
|
|
420
|
+
await this.updatePoolState();
|
|
421
|
+
tokenAddress = tokenAddress.toLowerCase();
|
|
422
|
+
const pools = this.cfgInfo.poolAddresses.filter(poolAddress => !!this.cfgInfo.pools[poolAddress].tokens[tokenAddress]);
|
|
423
|
+
pools.sort((a, b) => this.poolLiquidityUSD[b] - this.poolLiquidityUSD[a]);
|
|
424
|
+
return pools.slice(0, limit).map(poolAddress => ({
|
|
425
|
+
exchange: this.dexKey,
|
|
426
|
+
address: poolAddress,
|
|
427
|
+
connectorTokens: this.cfgInfo.pools[poolAddress].tokenAddresses.filter(t => t !== tokenAddress).map(t => ({
|
|
428
|
+
decimals: this.cfgInfo.pools[poolAddress].tokens[t].tokenDecimals,
|
|
429
|
+
address: t,
|
|
430
|
+
})),
|
|
431
|
+
liquidityUSD: this.poolLiquidityUSD[poolAddress],
|
|
432
|
+
}));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
exports.Platypus = Platypus;
|
|
436
|
+
Platypus.erc20Interface = new abi_1.Interface(erc20_json_1.default);
|
|
437
|
+
Platypus.poolInterface = new abi_1.Interface(pool_json_1.default);
|
|
438
|
+
Platypus.avaxPoolInterface = new abi_1.Interface(avax_pool_json_1.default);
|
|
439
|
+
Platypus.assetInterface = new abi_1.Interface(asset_json_1.default);
|
|
440
|
+
Platypus.oracleInterface = new abi_1.Interface(oracle_json_1.default);
|
|
441
|
+
Platypus.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.PlatypusConfig);
|
|
442
|
+
//# sourceMappingURL=platypus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platypus.js","sourceRoot":"","sources":["../../../src/dex/platypus/platypus.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAY/C,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAgF;AAGhF,mCAKiB;AACjB,wDAG4B;A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QAAQ,EAAE,IAAI,CAAC,OAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,aAAa;gBAClE,OAAO,EAAE,CAAC;aACX,CAAC,CAAC;YACH,YAAY,EAAE,IAAI,CAAC,gBAAiB,CAAC,WAAW,CAAC;SAClD,CAAC,CAAC,CAAC;IACN,CAAC;;AA1hBH,4BA2hBC;AA1hBiB,uBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC;AACzC,sBAAa,GAAG,IAAI,eAAS,CAAC,mBAAO,CAAC,CAAC;AACvC,0BAAiB,GAAG,IAAI,eAAS,CAAC,wBAAW,CAAC,CAAC;AAC/C,uBAAc,GAAG,IAAI,eAAS,CAAC,oBAAQ,CAAC,CAAC;AACzC,wBAAe,GAAG,IAAI,eAAS,CAAC,qBAAS,CAAC,CAAC;AAa7C,2BAAkB,GAC9B,IAAA,6BAAqB,EAAC,uBAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Address, Token } from '../../types';
|
|
2
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
3
|
+
import { PlatypusAvaxPoolState, PlatypusAvaxPoolConfigInfo } from './types';
|
|
4
|
+
import { PlatypusPoolBase } from './pool-base';
|
|
5
|
+
export declare class PlatypusAvaxPool extends PlatypusPoolBase<PlatypusAvaxPoolState> {
|
|
6
|
+
constructor(dexKey: string, network: number, name: string, poolAddress: Address, poolCfg: PlatypusAvaxPoolConfigInfo, dexHelper: IDexHelper);
|
|
7
|
+
computePrices(srcToken: Token, destToken: Token, amounts: bigint[], state: PlatypusAvaxPoolState): bigint[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatypusAvaxPool = void 0;
|
|
4
|
+
const lens_1 = require("../../lens");
|
|
5
|
+
const staked_avax_1 = require("../../lib/benqi/staked-avax");
|
|
6
|
+
const asset_1 = require("./asset");
|
|
7
|
+
const pool_subscriber_1 = require("./pool-subscriber");
|
|
8
|
+
const pool_base_1 = require("./pool-base");
|
|
9
|
+
class PlatypusAvaxPool extends pool_base_1.PlatypusPoolBase {
|
|
10
|
+
constructor(dexKey, network, name, poolAddress, poolCfg, dexHelper) {
|
|
11
|
+
super(dexKey, network, name, dexHelper, [
|
|
12
|
+
new pool_subscriber_1.PlatypusPoolSubscriber(poolAddress, (0, lens_1.lens)().params, dexHelper.getLogger(`${dexKey}-${network} Params ${name}`)),
|
|
13
|
+
new staked_avax_1.StakedAvaxSubscriber(poolCfg.priceOracleAddress, (0, lens_1.lens)().stakedAvax, dexHelper.getLogger(`Staked AVAX for ${dexKey}-${network} ${name}`)),
|
|
14
|
+
...Object.entries(poolCfg.tokens).map(([tokenAddress, c]) => new asset_1.PlatypusAssetSubscriber(c.assetAddress, (0, lens_1.lens)().asset[tokenAddress], dexHelper.getLogger(`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`))),
|
|
15
|
+
], {
|
|
16
|
+
params: {
|
|
17
|
+
paused: false,
|
|
18
|
+
slippageParamK: 0n,
|
|
19
|
+
slippageParamN: 0n,
|
|
20
|
+
c1: 0n,
|
|
21
|
+
xThreshold: 0n,
|
|
22
|
+
haircutRate: 0n,
|
|
23
|
+
retentionRatio: 0n,
|
|
24
|
+
maxPriceDeviation: 0n,
|
|
25
|
+
},
|
|
26
|
+
asset: {},
|
|
27
|
+
stakedAvax: {
|
|
28
|
+
totalPooledAvax: 0n,
|
|
29
|
+
totalShares: 0n,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
computePrices(srcToken, destToken, amounts, state) {
|
|
34
|
+
let fromShares;
|
|
35
|
+
if (this.dexHelper.config.isWETH(destToken.address)) {
|
|
36
|
+
fromShares = true;
|
|
37
|
+
}
|
|
38
|
+
else if (this.dexHelper.config.isWETH(srcToken.address)) {
|
|
39
|
+
fromShares = false;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new Error(`Unexpected tokens being swapped in ${this.name}`);
|
|
43
|
+
}
|
|
44
|
+
const sAvaxRate = staked_avax_1.StakedAvaxSubscriber.getPooledAvaxByShares(pool_base_1.WAD, state.stakedAvax);
|
|
45
|
+
return amounts.map(fromAmount => {
|
|
46
|
+
const idealToAmount = fromShares
|
|
47
|
+
? (0, pool_base_1.wmul)(fromAmount, sAvaxRate)
|
|
48
|
+
: (0, pool_base_1.wdiv)(fromAmount, sAvaxRate);
|
|
49
|
+
return (0, pool_base_1.calcPrice)(srcToken, destToken, fromAmount, idealToAmount, state);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.PlatypusAvaxPool = PlatypusAvaxPool;
|
|
54
|
+
//# sourceMappingURL=pool-avax.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool-avax.js","sourceRoot":"","sources":["../../../src/dex/platypus/pool-avax.ts"],"names":[],"mappings":";;;AAEA,qCAAkC;AAClC,6DAAmE;AACnE,mCAAkD;AAClD,uDAA2D;AAG3D,2CAA2E;AAE3E,MAAa,gBAAiB,SAAQ,4BAAuC;IAC3E,YACE,MAAc,EACd,OAAe,EACf,IAAY,EACZ,WAAoB,EACpB,OAAmC,EACnC,SAAqB;QAErB,KAAK,CACH,MAAM,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT;YACE,IAAI,wCAAsB,CACxB,WAAW,EACX,IAAA,WAAI,GAAuC,CAAC,MAAM,EAClD,SAAS,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,OAAO,WAAW,IAAI,EAAE,CAAC,CAC3D;YACD,IAAI,kCAAoB,CACtB,OAAO,CAAC,kBAAkB,EAC1B,IAAA,WAAI,GAAuC,CAAC,UAAU,EACtD,SAAS,CAAC,SAAS,CAAC,mBAAmB,MAAM,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC,CACp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,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YAC9B,MAAM,aAAa,GAAG,UAAU;gBAC9B,CAAC,CAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,SAAS,CAAC;gBAC7B,CAAC,CAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;YAChC,OAAO,IAAA,qBAAS,EAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAjFD,4CAiFC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { PartialEventSubscriber, ComposedEventSubscriber } from '../../composed-event-subscriber';
|
|
3
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
4
|
+
import { PlatypusPoolStateCommon } from './types';
|
|
5
|
+
import { Token } from '../../types';
|
|
6
|
+
export declare const ETH_UNIT: bigint;
|
|
7
|
+
export declare const WAD: bigint;
|
|
8
|
+
export declare const RAY: bigint;
|
|
9
|
+
export declare function wmul(x: bigint, y: bigint): bigint;
|
|
10
|
+
export declare function wdiv(x: bigint, y: bigint): bigint;
|
|
11
|
+
export declare function rmul(x: bigint, y: bigint): bigint;
|
|
12
|
+
export declare function rpow(x: bigint, n: bigint): bigint;
|
|
13
|
+
export declare function calcPrice(srcToken: Token, destToken: Token, fromAmount: bigint, idealToAmount: bigint, state: PlatypusPoolStateCommon): bigint;
|
|
14
|
+
export declare abstract class PlatypusPoolBase<State extends PlatypusPoolStateCommon> extends ComposedEventSubscriber<State> {
|
|
15
|
+
readonly dexKey: string;
|
|
16
|
+
protected readonly network: number;
|
|
17
|
+
constructor(dexKey: string, network: number, name: string, dexHelper: IDexHelper, parts: PartialEventSubscriber<State, any>[], blankState: DeepReadonly<State>);
|
|
18
|
+
abstract computePrices(srcToken: Token, destToken: Token, amounts: bigint[], state: State): bigint[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlatypusPoolBase = exports.calcPrice = exports.rpow = exports.rmul = exports.wdiv = exports.wmul = exports.RAY = exports.WAD = exports.ETH_UNIT = void 0;
|
|
4
|
+
const composed_event_subscriber_1 = require("../../composed-event-subscriber");
|
|
5
|
+
const bigint_constants_1 = require("../../bigint-constants");
|
|
6
|
+
exports.ETH_UNIT = bigint_constants_1.BI_POWS[18];
|
|
7
|
+
exports.WAD = bigint_constants_1.BI_POWS[18];
|
|
8
|
+
exports.RAY = bigint_constants_1.BI_POWS[27];
|
|
9
|
+
function wmul(x, y) {
|
|
10
|
+
return (x * y + exports.WAD / 2n) / exports.WAD;
|
|
11
|
+
}
|
|
12
|
+
exports.wmul = wmul;
|
|
13
|
+
function wdiv(x, y) {
|
|
14
|
+
return (x * exports.WAD + y / 2n) / y;
|
|
15
|
+
}
|
|
16
|
+
exports.wdiv = wdiv;
|
|
17
|
+
function rmul(x, y) {
|
|
18
|
+
return (x * y + exports.RAY / 2n) / exports.RAY;
|
|
19
|
+
}
|
|
20
|
+
exports.rmul = rmul;
|
|
21
|
+
function rpow(x, n) {
|
|
22
|
+
let z = n % 2n !== 0n ? x : exports.RAY;
|
|
23
|
+
for (n /= 2n; n !== 0n; n /= 2n) {
|
|
24
|
+
x = rmul(x, x);
|
|
25
|
+
if (n % 2n !== 0n) {
|
|
26
|
+
z = rmul(z, x);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return z;
|
|
30
|
+
}
|
|
31
|
+
exports.rpow = rpow;
|
|
32
|
+
function slippageFunc(k, n, c1, xThreshold, x) {
|
|
33
|
+
if (x < xThreshold) {
|
|
34
|
+
return c1 - x;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return wdiv(k, (rpow((x * exports.RAY) / exports.WAD, n) * exports.WAD) / exports.RAY);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function calcSlippage(k, n, c1, xThreshold, cash, liability, cashChange, addCash) {
|
|
41
|
+
const covBefore = wdiv(cash, liability);
|
|
42
|
+
let covAfter;
|
|
43
|
+
if (addCash) {
|
|
44
|
+
covAfter = wdiv(cash + cashChange, liability);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
covAfter = wdiv(cash - cashChange, liability);
|
|
48
|
+
}
|
|
49
|
+
if (covBefore === covAfter) {
|
|
50
|
+
return 0n;
|
|
51
|
+
}
|
|
52
|
+
const slippageBefore = slippageFunc(k, n, c1, xThreshold, covBefore);
|
|
53
|
+
const slippageAfter = slippageFunc(k, n, c1, xThreshold, covAfter);
|
|
54
|
+
if (covBefore > covAfter) {
|
|
55
|
+
return wdiv(slippageAfter - slippageBefore, covBefore - covAfter);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return wdiv(slippageBefore - slippageAfter, covAfter - covBefore);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function calcSwappingSlippage(si, sj) {
|
|
62
|
+
return exports.WAD + si - sj;
|
|
63
|
+
}
|
|
64
|
+
function calcHaircut(amount, rate) {
|
|
65
|
+
return wmul(amount, rate);
|
|
66
|
+
}
|
|
67
|
+
function calcPrice(srcToken, destToken, fromAmount, idealToAmount, state) {
|
|
68
|
+
if (state.asset[destToken.address].cash < idealToAmount)
|
|
69
|
+
return 0n;
|
|
70
|
+
const slippageFrom = calcSlippage(state.params.slippageParamK, state.params.slippageParamN, state.params.c1, state.params.xThreshold, state.asset[srcToken.address].cash, state.asset[srcToken.address].liability, fromAmount, true);
|
|
71
|
+
const slippageTo = calcSlippage(state.params.slippageParamK, state.params.slippageParamN, state.params.c1, state.params.xThreshold, state.asset[destToken.address].cash, state.asset[destToken.address].liability, idealToAmount, false);
|
|
72
|
+
const swappingSlippage = calcSwappingSlippage(slippageFrom, slippageTo);
|
|
73
|
+
const toAmount = wmul(idealToAmount, swappingSlippage);
|
|
74
|
+
const haircut = calcHaircut(toAmount, state.params.haircutRate);
|
|
75
|
+
return toAmount - haircut;
|
|
76
|
+
}
|
|
77
|
+
exports.calcPrice = calcPrice;
|
|
78
|
+
class PlatypusPoolBase extends composed_event_subscriber_1.ComposedEventSubscriber {
|
|
79
|
+
constructor(dexKey, network, name, dexHelper, parts, blankState) {
|
|
80
|
+
super(dexKey, name, dexHelper.getLogger(`${dexKey}-${network} ${name}`), dexHelper, parts, blankState);
|
|
81
|
+
this.dexKey = dexKey;
|
|
82
|
+
this.network = network;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.PlatypusPoolBase = PlatypusPoolBase;
|
|
86
|
+
//# sourceMappingURL=pool-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool-base.js","sourceRoot":"","sources":["../../../src/dex/platypus/pool-base.ts"],"names":[],"mappings":";;;AACA,+EAGyC;AAIzC,6DAAiD;AAEpC,QAAA,QAAQ,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;AACvB,QAAA,GAAG,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;AAClB,QAAA,GAAG,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;AAE/B,SAAgB,IAAI,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,WAAG,GAAG,EAAE,CAAC,GAAG,WAAG,CAAC;AAClC,CAAC;AAFD,oBAEC;AAED,SAAgB,IAAI,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,GAAG,WAAG,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC;AAFD,oBAEC;AAED,SAAgB,IAAI,CAAC,CAAS,EAAE,CAAS;IACvC,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,WAAG,GAAG,EAAE,CAAC,GAAG,WAAG,CAAC;AAClC,CAAC;AAFD,oBAEC;AAED,SAAgB,IA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