@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { AsyncOrSync } from 'ts-essentials';
|
|
3
|
+
import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, Logger, NumberAsString, DexExchangeParam } from '../../types';
|
|
4
|
+
import { SwapSide, Network } from '../../constants';
|
|
5
|
+
import { Context, IDex } from '../../dex/idex';
|
|
6
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
7
|
+
import { OSwapData, OSwapPool, OSwapPoolState } from './types';
|
|
8
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
9
|
+
import { OSwapEventPool } from './oswap-pool';
|
|
10
|
+
export declare class OSwap extends SimpleExchange implements IDex<OSwapData> {
|
|
11
|
+
readonly network: Network;
|
|
12
|
+
readonly dexKey: string;
|
|
13
|
+
readonly dexHelper: IDexHelper;
|
|
14
|
+
protected adapters: import("../../types").AdapterMappings;
|
|
15
|
+
readonly eventPools: {
|
|
16
|
+
[id: string]: OSwapEventPool;
|
|
17
|
+
};
|
|
18
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
19
|
+
readonly needWrapNative = true;
|
|
20
|
+
readonly isFeeOnTransferSupported = false;
|
|
21
|
+
static dexKeysWithNetwork: {
|
|
22
|
+
key: string;
|
|
23
|
+
networks: Network[];
|
|
24
|
+
}[];
|
|
25
|
+
logger: Logger;
|
|
26
|
+
readonly iOSwap: Interface;
|
|
27
|
+
readonly pools: [OSwapPool];
|
|
28
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
|
|
29
|
+
getAdapters(side: SwapSide): {
|
|
30
|
+
name: string;
|
|
31
|
+
index: number;
|
|
32
|
+
}[] | null;
|
|
33
|
+
getPoolByTokenPair(srcToken: Token, destToken: Token): OSwapPool | null;
|
|
34
|
+
getPoolById(id: string): OSwapPool | null;
|
|
35
|
+
getPoolsByTokenAddress(tokenAddress: Address): OSwapPool[];
|
|
36
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
37
|
+
calcPrice(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, side: SwapSide): bigint;
|
|
38
|
+
checkLiquidity(pool: OSwapPool, state: OSwapPoolState, from: Token, amount: bigint, side: SwapSide): boolean;
|
|
39
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<OSwapData>>;
|
|
40
|
+
getCalldataGasCost(poolPrices: PoolPrices<OSwapData>): number | number[];
|
|
41
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: OSwapData, side: SwapSide): AdapterExchangeParam;
|
|
42
|
+
getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: OSwapData, side: SwapSide, _: Context, executorAddress: Address): DexExchangeParam;
|
|
43
|
+
updatePoolState(): Promise<void>;
|
|
44
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
45
|
+
releaseResources(): AsyncOrSync<void>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.OSwap = void 0;
|
|
30
|
+
const abi_1 = require("@ethersproject/abi");
|
|
31
|
+
const constants_1 = require("../../constants");
|
|
32
|
+
const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
|
|
33
|
+
const utils_1 = require("../../utils");
|
|
34
|
+
const simple_exchange_1 = require("../simple-exchange");
|
|
35
|
+
const config_1 = require("./config");
|
|
36
|
+
const oswap_pool_1 = require("./oswap-pool");
|
|
37
|
+
const oswap_abi_json_1 = __importDefault(require("../../abi/oswap/oswap.abi.json"));
|
|
38
|
+
const utils_2 = require("../../executor/utils");
|
|
39
|
+
class OSwap extends simple_exchange_1.SimpleExchange {
|
|
40
|
+
constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
|
|
41
|
+
super(dexHelper, dexKey);
|
|
42
|
+
this.network = network;
|
|
43
|
+
this.dexKey = dexKey;
|
|
44
|
+
this.dexHelper = dexHelper;
|
|
45
|
+
this.adapters = adapters;
|
|
46
|
+
this.eventPools = {};
|
|
47
|
+
this.hasConstantPriceLargeAmounts = false;
|
|
48
|
+
// This may change in the future, but currently OSwap does not support native ETH.
|
|
49
|
+
this.needWrapNative = true;
|
|
50
|
+
this.isFeeOnTransferSupported = false;
|
|
51
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
52
|
+
this.iOSwap = new abi_1.Interface(oswap_abi_json_1.default);
|
|
53
|
+
this.pools = config_1.OSwapConfig[dexKey][network].pools;
|
|
54
|
+
// Create an OSwapEventPool per pool, to track each pool's state by subscribing to on-chain events.
|
|
55
|
+
for (const pool of this.pools) {
|
|
56
|
+
this.eventPools[pool.id] = new oswap_pool_1.OSwapEventPool(dexKey, pool, network, dexHelper, this.logger);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// Returns the list of contract adapters (name and index)
|
|
60
|
+
// for a buy/sell. Return null if there are no adapters.
|
|
61
|
+
getAdapters(side) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// Returns the pool matching the specified token pair or null if none found.
|
|
65
|
+
// Note: OSwap V1 does not support more than 1 pool per pair.
|
|
66
|
+
getPoolByTokenPair(srcToken, destToken) {
|
|
67
|
+
const srcAddress = srcToken.address.toLowerCase();
|
|
68
|
+
const destAddress = destToken.address.toLowerCase();
|
|
69
|
+
// A pair must have 2 different tokens.
|
|
70
|
+
if (srcAddress === destAddress)
|
|
71
|
+
return null;
|
|
72
|
+
for (const pool of this.pools) {
|
|
73
|
+
if ((srcAddress === pool.token0 && destAddress === pool.token1) ||
|
|
74
|
+
(srcAddress === pool.token1 && destAddress === pool.token0)) {
|
|
75
|
+
return pool;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
getPoolById(id) {
|
|
81
|
+
for (const pool of this.pools) {
|
|
82
|
+
if (pool.id === id)
|
|
83
|
+
return pool;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
// Returns a list of pool using the token.
|
|
88
|
+
getPoolsByTokenAddress(tokenAddress) {
|
|
89
|
+
const address = tokenAddress.toLowerCase();
|
|
90
|
+
let pools = [];
|
|
91
|
+
for (const pool of this.pools) {
|
|
92
|
+
if (address === pool.token0 || address === pool.token1) {
|
|
93
|
+
pools.push(pool);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return pools;
|
|
97
|
+
}
|
|
98
|
+
// Returns the list of pool identifiers that can be used
|
|
99
|
+
// for a given swap. poolIdentifiers must be unique
|
|
100
|
+
// across DEXes. It is recommended to use
|
|
101
|
+
// ${dexKey}_${poolAddress} as a poolIdentifier
|
|
102
|
+
async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
|
|
103
|
+
const pool = this.getPoolByTokenPair(srcToken, destToken);
|
|
104
|
+
return pool ? [pool.id] : [];
|
|
105
|
+
}
|
|
106
|
+
// Sell: Given "amount" of "from" token, how much of "to" token will be received by the trader.
|
|
107
|
+
// Buy: Given "amount" of "dest" token, how much of "to" token is required from the trader.
|
|
108
|
+
// Note: OSwap traderate is at precision 36.
|
|
109
|
+
calcPrice(pool, state, from, amount, side) {
|
|
110
|
+
const rate = from.address.toLowerCase() === pool.token0
|
|
111
|
+
? state.traderate0
|
|
112
|
+
: state.traderate1;
|
|
113
|
+
return side === constants_1.SwapSide.SELL
|
|
114
|
+
? (amount * rate) / (0, utils_1.getBigIntPow)(36)
|
|
115
|
+
: (amount * (0, utils_1.getBigIntPow)(36)) / rate;
|
|
116
|
+
}
|
|
117
|
+
// Returns true if the pool has enough liquidity for the swap. False otherwise.
|
|
118
|
+
checkLiquidity(pool, state, from, amount, side) {
|
|
119
|
+
if (side === constants_1.SwapSide.SELL) {
|
|
120
|
+
const needed = this.calcPrice(pool, state, from, amount, side);
|
|
121
|
+
return from.address.toLowerCase() === pool.token0
|
|
122
|
+
? needed <= state.balance1
|
|
123
|
+
: needed <= state.balance0;
|
|
124
|
+
}
|
|
125
|
+
// SwapSide.BUY
|
|
126
|
+
return from.address.toLowerCase() === pool.token0
|
|
127
|
+
? amount <= state.balance1
|
|
128
|
+
: amount <= state.balance0;
|
|
129
|
+
}
|
|
130
|
+
// Returns pool prices for amounts.
|
|
131
|
+
// If limitPools is defined only pools in limitPools
|
|
132
|
+
// should be used. If limitPools is undefined then
|
|
133
|
+
// any pool can be used.
|
|
134
|
+
async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
|
|
135
|
+
// Get the pool to use.
|
|
136
|
+
const pool = this.getPoolByTokenPair(srcToken, destToken);
|
|
137
|
+
if (!pool)
|
|
138
|
+
return null;
|
|
139
|
+
// Make sure the pool meets the optional limitPools filter.
|
|
140
|
+
if (limitPools && !limitPools.includes(pool.id))
|
|
141
|
+
return null;
|
|
142
|
+
const eventPool = this.eventPools[pool.id];
|
|
143
|
+
if (!eventPool)
|
|
144
|
+
throw new Error(`OSwap pool ${pool.id}: No EventPool found.`);
|
|
145
|
+
const state = await eventPool.getStateOrGenerate(blockNumber);
|
|
146
|
+
// Ensure there is enough liquidity in the pool to process all the requested swaps.
|
|
147
|
+
const totalAmount = amounts.reduce((a, b) => a + b, BigInt(0));
|
|
148
|
+
if (!this.checkLiquidity(pool, state, srcToken, totalAmount, side)) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
// Calculate the prices
|
|
152
|
+
const unitAmount = (0, utils_1.getBigIntPow)(18);
|
|
153
|
+
const unitPrice = this.calcPrice(pool, state, srcToken, unitAmount, side);
|
|
154
|
+
const prices = amounts.map(amount => this.calcPrice(pool, state, srcToken, amount, side));
|
|
155
|
+
return [
|
|
156
|
+
{
|
|
157
|
+
prices,
|
|
158
|
+
unit: unitPrice,
|
|
159
|
+
data: {
|
|
160
|
+
pool: pool.address,
|
|
161
|
+
path: [srcToken.address, destToken.address],
|
|
162
|
+
},
|
|
163
|
+
exchange: this.dexKey,
|
|
164
|
+
poolIdentifier: pool.id,
|
|
165
|
+
gasCost: config_1.OSWAP_GAS_COST,
|
|
166
|
+
poolAddresses: [pool.address],
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
// Returns estimated gas cost of calldata for this DEX in multiSwap
|
|
171
|
+
getCalldataGasCost(poolPrices) {
|
|
172
|
+
return (CALLDATA_GAS_COST.DEX_OVERHEAD +
|
|
173
|
+
// ParentStruct header
|
|
174
|
+
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
175
|
+
// ParentStruct -> path[] header
|
|
176
|
+
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
177
|
+
// ParentStruct -> path length
|
|
178
|
+
CALLDATA_GAS_COST.LENGTH_SMALL +
|
|
179
|
+
// ParentStruct -> path[0]
|
|
180
|
+
CALLDATA_GAS_COST.ADDRESS +
|
|
181
|
+
// ParentStruct -> path[1]
|
|
182
|
+
CALLDATA_GAS_COST.ADDRESS +
|
|
183
|
+
// ParentStruct -> receiver header
|
|
184
|
+
CALLDATA_GAS_COST.OFFSET_SMALL +
|
|
185
|
+
// ParentStruct -> receiver
|
|
186
|
+
CALLDATA_GAS_COST.ADDRESS);
|
|
187
|
+
}
|
|
188
|
+
// Encode params required by the exchange adapter
|
|
189
|
+
// Used for multiSwap, buy & megaSwap
|
|
190
|
+
getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
|
|
191
|
+
return {
|
|
192
|
+
targetExchange: data.pool,
|
|
193
|
+
payload: '',
|
|
194
|
+
networkFee: '0',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
// Encode call data used by simpleSwap like routers
|
|
198
|
+
// Used for simpleSwap & simpleBuy
|
|
199
|
+
getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, _, executorAddress) {
|
|
200
|
+
let method;
|
|
201
|
+
let args;
|
|
202
|
+
let returnAmountPos = undefined;
|
|
203
|
+
const deadline = (0, simple_exchange_1.getLocalDeadlineAsFriendlyPlaceholder)();
|
|
204
|
+
if (side === constants_1.SwapSide.SELL) {
|
|
205
|
+
method = 'swapExactTokensForTokens';
|
|
206
|
+
returnAmountPos = (0, utils_2.extractReturnAmountPosition)(this.iOSwap, method, 'amounts', 1);
|
|
207
|
+
args = [srcAmount, destAmount, data.path, recipient, deadline];
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
method = 'swapTokensForExactTokens';
|
|
211
|
+
args = [destAmount, srcAmount, data.path, recipient, deadline];
|
|
212
|
+
}
|
|
213
|
+
const swapData = this.iOSwap.encodeFunctionData(method, args);
|
|
214
|
+
return {
|
|
215
|
+
needWrapNative: this.needWrapNative,
|
|
216
|
+
dexFuncHasRecipient: true,
|
|
217
|
+
exchangeData: swapData,
|
|
218
|
+
targetExchange: data.pool,
|
|
219
|
+
returnAmountPos,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
// This is called once before getTopPoolsForToken is
|
|
223
|
+
// called for multiple tokens. This can be helpful to
|
|
224
|
+
// update common state required for calculating
|
|
225
|
+
// getTopPoolsForToken. It is optional for a DEX
|
|
226
|
+
// to implement this
|
|
227
|
+
async updatePoolState() {
|
|
228
|
+
return Promise.resolve();
|
|
229
|
+
}
|
|
230
|
+
// Returns a list of top pools based on liquidity. Max
|
|
231
|
+
// limit number pools should be returned.
|
|
232
|
+
async getTopPoolsForToken(tokenAddress, limit) {
|
|
233
|
+
// Get the list of pools using the token.
|
|
234
|
+
const pools = this.getPoolsByTokenAddress(tokenAddress);
|
|
235
|
+
if (!pools.length)
|
|
236
|
+
return [];
|
|
237
|
+
const results = await Promise.all(pools.map(async (pool) => {
|
|
238
|
+
// Get the pool's balance and its USD value.
|
|
239
|
+
const eventPool = this.eventPools[pool.id];
|
|
240
|
+
const blockNumber = await this.dexHelper.web3Provider.eth.getBlockNumber();
|
|
241
|
+
const state = await eventPool.getStateOrGenerate(blockNumber);
|
|
242
|
+
const usd0 = await this.dexHelper.getTokenUSDPrice({ address: pool.token0, decimals: 18 }, state.balance0);
|
|
243
|
+
const usd1 = await this.dexHelper.getTokenUSDPrice({ address: pool.token1, decimals: 18 }, state.balance1);
|
|
244
|
+
// Get the other token in the pair.
|
|
245
|
+
const pairedToken = pool.token0 === tokenAddress.toLowerCase()
|
|
246
|
+
? { address: pool.token1, decimals: 18 }
|
|
247
|
+
: { address: pool.token0, decimals: 18 };
|
|
248
|
+
return {
|
|
249
|
+
exchange: this.dexKey,
|
|
250
|
+
address: pool.address,
|
|
251
|
+
connectorTokens: [pairedToken],
|
|
252
|
+
liquidityUSD: usd0 + usd1,
|
|
253
|
+
};
|
|
254
|
+
}));
|
|
255
|
+
return results
|
|
256
|
+
.filter(r => r)
|
|
257
|
+
.sort((a, b) => a.liquidityUSD - b.liquidityUSD)
|
|
258
|
+
.slice(0, limit);
|
|
259
|
+
}
|
|
260
|
+
// This is optional function in case if your implementation has acquired any resources
|
|
261
|
+
// you need to release for graceful shutdown. For example, it may be any interval timer
|
|
262
|
+
releaseResources() { }
|
|
263
|
+
}
|
|
264
|
+
exports.OSwap = OSwap;
|
|
265
|
+
OSwap.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.OSwapConfig);
|
|
266
|
+
//# sourceMappingURL=oswap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oswap.js","sourceRoot":"","sources":["../../../src/dex/oswap/oswap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA+C;AAc/C,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAkE;AAIlE,wDAG4B;AAC5B,qCAAiE;AACjE,6CAA8C;AAC9C,oFAAsD;AACtD,gDAAmE;AAEnE,MAAa,KAAM,SAAQ,gCAAc;IAmBvC,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAA0B;QAtBrC,eAAU,GAAqC,EAAE,CAAC;QAElD,iCAA4B,GAAG,KAAK,CAAC;QAE9C,kFAAkF;QACzE,mBAAc,GAAG,IAAI,CAAC;QAEtB,6BAAwB,GAAG,KAAK,CAAC;QAkBxC,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,S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AC;YACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAChD,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,EACtC,KAAK,CAAC,QAAQ,CACf,CAAC;YAEF,mCAAmC;YACnC,MAAM,WAAW,GACf,IAAI,CAAC,MAAM,KAAK,YAAY,CAAC,WAAW,EAAE;gBACxC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACxC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAE7C,OAAO;gBACL,QAAQ,EAAE,IAAI,CAAC,MAAM;gBACrB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,eAAe,EAAE,CAAC,WAAW,CAAC;gBAC9B,YAAY,EAAE,IAAI,GAAG,IAAI;aAC1B,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;QACF,OAAO,OAAO;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;aACd,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,CAAC;aAC/C,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB,KAAuB,CAAC;;AAhV1C,sBAiVC;AAvUe,wBAAkB,GAC9B,IAAA,6BAAqB,EAAC,oBAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
export declare type OSwapPoolState = {
|
|
3
|
+
traderate0: bigint;
|
|
4
|
+
traderate1: bigint;
|
|
5
|
+
balance0: bigint;
|
|
6
|
+
balance1: bigint;
|
|
7
|
+
};
|
|
8
|
+
export declare type OSwapData = {
|
|
9
|
+
pool: Address;
|
|
10
|
+
path: Address[];
|
|
11
|
+
};
|
|
12
|
+
export declare type OSwapPool = {
|
|
13
|
+
id: string;
|
|
14
|
+
address: Address;
|
|
15
|
+
token0: Address;
|
|
16
|
+
token1: Address;
|
|
17
|
+
};
|
|
18
|
+
export declare type DexParams = {
|
|
19
|
+
pools: [OSwapPool];
|
|
20
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/oswap/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeepReadonly } from 'ts-essentials';
|
|
2
|
+
import { PartialEventSubscriber } from '../../composed-event-subscriber';
|
|
3
|
+
import { Address, BlockHeader, Log, Logger, MultiCallInput, MultiCallOutput } from '../../types';
|
|
4
|
+
import { Lens } from '../../lens';
|
|
5
|
+
import { Interface } from '@ethersproject/abi';
|
|
6
|
+
import { PlatypusAssetState } from './types';
|
|
7
|
+
export declare class PlatypusAssetSubscriber<State> extends PartialEventSubscriber<State, PlatypusAssetState> {
|
|
8
|
+
private asset;
|
|
9
|
+
static readonly assetInterface: Interface;
|
|
10
|
+
constructor(asset: Address, lens: Lens<DeepReadonly<State>, DeepReadonly<PlatypusAssetState>>, logger: Logger);
|
|
11
|
+
processLog(state: DeepReadonly<PlatypusAssetState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PlatypusAssetState> | null;
|
|
12
|
+
getGenerateStateMultiCallInputs(): MultiCallInput[];
|
|
13
|
+
generateState(multicallOutputs: MultiCallOutput[], blockNumber?: number | 'latest'): DeepReadonly<PlatypusAssetState>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
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.PlatypusAssetSubscriber = void 0;
|
|
7
|
+
const composed_event_subscriber_1 = require("../../composed-event-subscriber");
|
|
8
|
+
const abi_1 = require("@ethersproject/abi");
|
|
9
|
+
const asset_json_1 = __importDefault(require("../../abi/platypus/asset.json"));
|
|
10
|
+
class PlatypusAssetSubscriber extends composed_event_subscriber_1.PartialEventSubscriber {
|
|
11
|
+
constructor(asset, lens, logger) {
|
|
12
|
+
super([asset], lens, logger);
|
|
13
|
+
this.asset = asset;
|
|
14
|
+
}
|
|
15
|
+
processLog(state, log, blockHeader) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = PlatypusAssetSubscriber.assetInterface.parseLog(log);
|
|
18
|
+
switch (parsed.name) {
|
|
19
|
+
case 'CashAdded': {
|
|
20
|
+
const previousCashPosition = BigInt(parsed.args.previousCashPosition.toString());
|
|
21
|
+
const cashBeingAdded = BigInt(parsed.args.cashBeingAdded.toString());
|
|
22
|
+
if (state.cash !== previousCashPosition) {
|
|
23
|
+
this.logger.error('state.cash !== previousCashPosition');
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
cash: previousCashPosition + cashBeingAdded,
|
|
27
|
+
liability: state.liability,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
case 'CashRemoved': {
|
|
31
|
+
const previousCashPosition = BigInt(parsed.args.previousCashPosition.toString());
|
|
32
|
+
const cashBeingRemoved = BigInt(parsed.args.cashBeingRemoved.toString());
|
|
33
|
+
if (state.cash !== previousCashPosition) {
|
|
34
|
+
this.logger.error('state.cash !== previousCashPosition');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
cash: previousCashPosition - cashBeingRemoved,
|
|
38
|
+
liability: state.liability,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
case 'LiabilityAdded': {
|
|
42
|
+
const previousLiabilityPosition = BigInt(parsed.args.previousLiabilityPosition.toString());
|
|
43
|
+
const liabilityBeingAdded = BigInt(parsed.args.liabilityBeingAdded.toString());
|
|
44
|
+
if (state.liability !== previousLiabilityPosition) {
|
|
45
|
+
this.logger.error('state.liability !== previousLiabilityPosition');
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
cash: state.cash,
|
|
49
|
+
liability: previousLiabilityPosition + liabilityBeingAdded,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
case 'LiabilityRemoved': {
|
|
53
|
+
const previousLiabilityPosition = BigInt(parsed.args.previousLiabilityPosition.toString());
|
|
54
|
+
const liabilityBeingRemoved = BigInt(parsed.args.liabilityBeingRemoved.toString());
|
|
55
|
+
if (state.liability !== previousLiabilityPosition) {
|
|
56
|
+
this.logger.error('state.liability !== previousLiabilityPosition');
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
cash: state.cash,
|
|
60
|
+
liability: previousLiabilityPosition - liabilityBeingRemoved,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
this.logger.error('Failed to parse log', e);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
getGenerateStateMultiCallInputs() {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
target: this.asset,
|
|
76
|
+
callData: PlatypusAssetSubscriber.assetInterface.encodeFunctionData('cash'),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
target: this.asset,
|
|
80
|
+
callData: PlatypusAssetSubscriber.assetInterface.encodeFunctionData('liability'),
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
generateState(multicallOutputs, blockNumber) {
|
|
85
|
+
return {
|
|
86
|
+
cash: BigInt(PlatypusAssetSubscriber.assetInterface
|
|
87
|
+
.decodeFunctionResult('cash', multicallOutputs[0])[0]
|
|
88
|
+
.toString()),
|
|
89
|
+
liability: BigInt(PlatypusAssetSubscriber.assetInterface
|
|
90
|
+
.decodeFunctionResult('liability', multicallOutputs[1])[0]
|
|
91
|
+
.toString()),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.PlatypusAssetSubscriber = PlatypusAssetSubscriber;
|
|
96
|
+
PlatypusAssetSubscriber.assetInterface = new abi_1.Interface(asset_json_1.default);
|
|
97
|
+
//# sourceMappingURL=asset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset.js","sourceRoot":"","sources":["../../../src/dex/platypus/asset.ts"],"names":[],"mappings":";;;;;;AACA,+EAAyE;AAUzE,4CAA+C;AAC/C,+EAAqD;AAGrD,MAAa,uBAA+B,SAAQ,kDAGnD;IAGC,YACU,KAAc,EACtB,IAAiE,EACjE,MAAc;QAEd,KAAK,CAAC,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAJrB,UAAK,GAAL,KAAK,CAAS;IAKxB,CAAC;IAEM,UAAU,CACf,KAAuC,EACvC,GAAkB,EAClB,WAAkC;QAElC,IAAI;YACF,MAAM,MAAM,GAAG,uBAAuB,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACpE,QAAQ,MAAM,CAAC,IAAI,EAAE;gBACnB,KAAK,WAAW,CAAC,CAAC;oBAChB,MAAM,oBAAoB,GAAG,MAAM,CACjC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CAC5C,CAAC;oBACF,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC;oBACrE,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE;wBACvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;qBAC1D;oBACD,OAAO;wBACL,IAAI,EAAE,oBAAoB,GAAG,cAAc;wBAC3C,SAAS,EAAE,K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ap } from '../../types';
|
|
3
|
+
export declare const PlatypusConfig: DexConfigMap<DexParams>;
|
|
4
|
+
export declare const Adapters: {
|
|
5
|
+
[chainId: number]: {
|
|
6
|
+
[side: string]: {
|
|
7
|
+
name: string;
|
|
8
|
+
index: number;
|
|
9
|
+
}[] | null;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Adapters = exports.PlatypusConfig = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
exports.PlatypusConfig = {
|
|
7
|
+
Platypus: {
|
|
8
|
+
[constants_1.Network.AVALANCHE]: {
|
|
9
|
+
pools: [
|
|
10
|
+
{
|
|
11
|
+
address: '0xbe52548488992Cc76fFA1B42f3A58F646864df45',
|
|
12
|
+
name: 'Main USD Pool',
|
|
13
|
+
oracleType: types_1.PlatypusOracleType.ChainLink,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
address: '0xB8E567fc23c39C94a1f6359509D7b43D1Fbed824',
|
|
17
|
+
name: 'Alt Pool Frax',
|
|
18
|
+
oracleType: types_1.PlatypusOracleType.ChainLink,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
address: '0x30C30d826be87Cd0A4b90855C2F38f7FcfE4eaA7',
|
|
22
|
+
name: 'Alt Pool MIM',
|
|
23
|
+
oracleType: types_1.PlatypusOracleType.ChainLink,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
address: '0x39dE4e02F76Dbd4352Ec2c926D8d64Db8aBdf5b2',
|
|
27
|
+
name: 'Alt Pool BTC',
|
|
28
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
address: '0x4658EA7e9960D6158a261104aAA160cC953bb6ba',
|
|
32
|
+
name: 'Alt Pool sAVAX',
|
|
33
|
+
oracleType: types_1.PlatypusOracleType.StakedAvax,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
address: '0xC828D995C686AaBA78A4aC89dfc8eC0Ff4C5be83',
|
|
37
|
+
name: 'Alt Pool YUSD',
|
|
38
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
address: '0x233Ba46B01d2FbF1A31bDBc500702E286d6de218',
|
|
42
|
+
name: 'Factory Pool H2O',
|
|
43
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
address: '0x27912AE6Ba9a54219d8287C3540A8969FF35500B',
|
|
47
|
+
name: 'Factory Pool MONEY',
|
|
48
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
address: '0x91BB10D68C72d64a7cE10482b453153eEa03322C',
|
|
52
|
+
name: 'Factory Pool TSD',
|
|
53
|
+
oracleType: types_1.PlatypusOracleType.None,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
exports.Adapters = {
|
|
60
|
+
[constants_1.Network.AVALANCHE]: {
|
|
61
|
+
[constants_1.SwapSide.SELL]: [
|
|
62
|
+
{
|
|
63
|
+
name: 'AvalancheAdapter01',
|
|
64
|
+
index: 10,
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/platypus/config.ts"],"names":[],"mappings":";;;AAAA,mCAAwD;AAExD,+CAAoD;AAEvC,QAAA,cAAc,GAA4B;IACrD,QAAQ,EAAE;QACR,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE;YACnB,KAAK,EAAE;gBACL;oBACE,OAAO,EAAE,4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Address, ExchangePrices, PoolPrices, AdapterExchangeParam, SimpleExchangeParam, PoolLiquidity, Logger } from '../../types';
|
|
3
|
+
import { SwapSide, Network } from '../../constants';
|
|
4
|
+
import { IDex } from '../../dex/idex';
|
|
5
|
+
import { IDexHelper } from '../../dex-helper/idex-helper';
|
|
6
|
+
import { DexParams, PlatypusData, PlatypusConfigInfo } from './types';
|
|
7
|
+
import { SimpleExchange } from '../simple-exchange';
|
|
8
|
+
import { PlatypusPool } from './pool';
|
|
9
|
+
import { PlatypusPurePool } from './pool-pure';
|
|
10
|
+
import { PlatypusAvaxPool } from './pool-avax';
|
|
11
|
+
export declare class Platypus extends SimpleExchange implements IDex<PlatypusData> {
|
|
12
|
+
protected network: Network;
|
|
13
|
+
protected dexHelper: IDexHelper;
|
|
14
|
+
protected adapters: {
|
|
15
|
+
[side: string]: {
|
|
16
|
+
name: string;
|
|
17
|
+
index: number;
|
|
18
|
+
}[] | null;
|
|
19
|
+
};
|
|
20
|
+
static readonly erc20Interface: Interface;
|
|
21
|
+
static readonly poolInterface: Interface;
|
|
22
|
+
static readonly avaxPoolInterface: Interface;
|
|
23
|
+
static readonly assetInterface: Interface;
|
|
24
|
+
static readonly oracleInterface: Interface;
|
|
25
|
+
protected config: DexParams;
|
|
26
|
+
protected cfgInfo?: PlatypusConfigInfo;
|
|
27
|
+
protected poolLiquidityUSD?: {
|
|
28
|
+
[poolAddress: string]: number;
|
|
29
|
+
};
|
|
30
|
+
protected eventPools?: {
|
|
31
|
+
[poolAddress: string]: PlatypusPool | PlatypusPurePool | PlatypusAvaxPool;
|
|
32
|
+
};
|
|
33
|
+
readonly hasConstantPriceLargeAmounts = false;
|
|
34
|
+
readonly isFeeOnTransferSupported = false;
|
|
35
|
+
static dexKeysWithNetwork: {
|
|
36
|
+
key: string;
|
|
37
|
+
networks: Network[];
|
|
38
|
+
}[];
|
|
39
|
+
logger: Logger;
|
|
40
|
+
constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: {
|
|
41
|
+
[side: string]: {
|
|
42
|
+
name: string;
|
|
43
|
+
index: number;
|
|
44
|
+
}[] | null;
|
|
45
|
+
});
|
|
46
|
+
generateConfigInfo(blockNumber: number): Promise<PlatypusConfigInfo>;
|
|
47
|
+
init(blockNumber: number): Promise<void>;
|
|
48
|
+
initializePricing(blockNumber: number): Promise<void>;
|
|
49
|
+
getAdapters(side: SwapSide): {
|
|
50
|
+
name: string;
|
|
51
|
+
index: number;
|
|
52
|
+
}[] | null;
|
|
53
|
+
protected findPools(srcTokenAddress: Address, destTokenAddress: Address): Address[];
|
|
54
|
+
protected getPoolIdentifier(poolAddress: Address): string;
|
|
55
|
+
getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
|
|
56
|
+
getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<PlatypusData>>;
|
|
57
|
+
getCalldataGasCost(poolPrices: PoolPrices<PlatypusData>): number | number[];
|
|
58
|
+
getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: PlatypusData, side: SwapSide): AdapterExchangeParam;
|
|
59
|
+
getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: PlatypusData, side: SwapSide): Promise<SimpleExchangeParam>;
|
|
60
|
+
updatePoolState(): Promise<void>;
|
|
61
|
+
getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
|
|
62
|
+
}
|