@paraswap/dex-lib 3.8.2 → 3.8.3-integral-dex
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/config.js +1 -1
- 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-v1-factory/config.js +10 -47
- package/build/dex/curve-v1-factory/config.js.map +1 -1
- package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +2 -2
- package/build/dex/curve-v1-factory/curve-v1-factory.js +36 -96
- package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js +1 -13
- package/build/dex/curve-v1-factory/price-handlers/functions/get_dx.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +2 -2
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +3 -4
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +9 -24
- package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
- package/build/dex/curve-v1-factory/types.d.ts +4 -20
- package/build/dex/curve-v1-factory/types.js +3 -11
- package/build/dex/curve-v1-factory/types.js.map +1 -1
- package/build/dex/curve-v1-stable-ng/config.js +0 -18
- package/build/dex/curve-v1-stable-ng/config.js.map +1 -1
- 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/index.js +21 -3
- package/build/dex/index.js.map +1 -1
- package/build/dex/integral/config.d.ts +4 -0
- package/build/dex/integral/config.js +20 -0
- package/build/dex/integral/config.js.map +1 -0
- package/build/dex/integral/context.d.ts +40 -0
- package/build/dex/integral/context.js +158 -0
- package/build/dex/integral/context.js.map +1 -0
- package/build/dex/integral/helpers.d.ts +17 -0
- package/build/dex/integral/helpers.js +157 -0
- package/build/dex/integral/helpers.js.map +1 -0
- package/build/dex/integral/integral-factory.d.ts +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 +24 -0
- package/build/dex/integral/integral-token.js +56 -0
- package/build/dex/integral/integral-token.js.map +1 -0
- package/build/dex/integral/integral.d.ts +41 -0
- package/build/dex/integral/integral.js +377 -0
- package/build/dex/integral/integral.js.map +1 -0
- package/build/dex/integral/types.d.ts +84 -0
- package/build/dex/integral/types.js +9 -0
- package/build/dex/integral/types.js.map +1 -0
- package/build/dex/integral/utils-e2e.d.ts +9 -0
- package/build/dex/integral/utils-e2e.js +131 -0
- package/build/dex/integral/utils-e2e.js.map +1 -0
- package/build/dex/integral/utils.d.ts +17 -0
- package/build/dex/integral/utils.js +94 -0
- package/build/dex/integral/utils.js.map +1 -0
- package/build/dex/lido.d.ts +19 -0
- package/build/dex/lido.js +42 -0
- package/build/dex/lido.js.map +1 -0
- package/build/dex/onebit.d.ts +25 -0
- package/build/dex/onebit.js +42 -0
- package/build/dex/onebit.js.map +1 -0
- package/build/dex/oswap/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/paraswap-limit-orders/paraswap-limit-orders.js +0 -3
- package/build/dex/paraswap-limit-orders/paraswap-limit-orders.js.map +1 -1
- 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.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/dex/uniswap-v3/contract-math/Oracle.js +4 -4
- package/build/dex/uniswap-v3/contract-math/Oracle.js.map +1 -1
- package/build/executor/compressor/Compressor.d.ts +23 -0
- package/build/executor/compressor/Compressor.js +144 -0
- package/build/executor/compressor/Compressor.js.map +1 -0
- package/build/executor/compressor/compress.d.ts +17 -0
- package/build/executor/compressor/compress.js +187 -0
- package/build/executor/compressor/compress.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
- package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
- package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
- package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
- package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
- package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
- package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
- package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
- package/build/executor/compressor/fetchSaved.d.ts +0 -0
- package/build/executor/compressor/fetchSaved.js +17 -0
- package/build/executor/compressor/fetchSaved.js.map +1 -0
- package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
- package/build/executor/compressor/utils/computeCostL2.js +14 -0
- package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
- package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
- package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
- package/build/executor/compressor/utils/getAllIndexes.js +12 -0
- package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
- package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
- package/build/executor/compressor/utils/getByteForAddress.js +14 -0
- package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
- package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
- package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
- package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
- package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
- package/build/executor/compressor/utils/intToByte.d.ts +2 -0
- package/build/executor/compressor/utils/intToByte.js +10 -0
- package/build/executor/compressor/utils/intToByte.js.map +1 -0
- package/build/generic-swap-transaction-builder.js +3 -1
- package/build/generic-swap-transaction-builder.js.map +1 -1
- package/build/router/simpleswap.js +3 -1
- package/build/router/simpleswap.js.map +1 -1
- package/package.json +2 -2
- package/src/abi/BProtocol.json +1155 -0
- package/src/abi/Jarvis.json +1172 -0
- package/src/abi/MStableAsset.json +1545 -0
- package/src/abi/OneInchLp.json +1304 -0
- package/src/abi/Onebit.json +736 -0
- package/src/abi/Shell.json +1294 -0
- package/src/abi/TraderJoeV2Router.json +50 -0
- package/src/abi/integral/factory.json +333 -0
- package/src/abi/integral/oracle.json +501 -0
- package/src/abi/integral/pool.json +1041 -0
- package/src/abi/integral/relayer.json +1536 -0
- package/src/abi/zrx.v2.json +1967 -0
- package/src/abi/zrx.v3.json +3454 -0
- package/src/abi/zrx.v4.json +2193 -0
- package/src/config.ts +1 -1
- package/src/dex/OneInchLp.ts +84 -0
- package/src/dex/bProtocol/bProtocol-e2e.test.ts +93 -0
- package/src/dex/bProtocol/bProtocol.ts +108 -0
- package/src/dex/bProtocol/types.ts +13 -0
- package/src/dex/curve-v1-factory/config.ts +10 -47
- package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +16 -92
- package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +5 -125
- package/src/dex/curve-v1-factory/curve-v1-factory.ts +45 -137
- package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +2 -0
- package/src/dex/curve-v1-factory/price-handlers/functions/get_dx.ts +1 -24
- package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +2 -3
- package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +0 -1
- package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +10 -31
- package/src/dex/curve-v1-factory/types.ts +6 -22
- package/src/dex/curve-v1-stable-ng/config.ts +0 -18
- package/src/dex/curve-v1-stable-ng/curve-v1-stable-ng-e2e.test.ts +0 -17
- package/src/dex/index.ts +20 -3
- package/src/dex/integral/config.ts +20 -0
- package/src/dex/integral/context.ts +287 -0
- package/src/dex/integral/integral-e2e.test.ts +86 -0
- package/src/dex/integral/integral-events.test.ts +412 -0
- package/src/dex/integral/integral-factory.ts +146 -0
- package/src/dex/integral/integral-integration.test.ts +221 -0
- package/src/dex/integral/integral-pool.ts +198 -0
- package/src/dex/integral/integral-pricing.ts +190 -0
- package/src/dex/integral/integral-relayer.ts +285 -0
- package/src/dex/integral/integral-token.ts +95 -0
- package/src/dex/integral/integral.ts +523 -0
- package/src/dex/integral/test-artifacts/configs.json +1 -0
- package/src/dex/integral/test-artifacts/logs.json +1 -0
- package/src/dex/integral/test-artifacts/states.json +1 -0
- package/src/dex/integral/types.ts +88 -0
- package/src/dex/integral/utils-e2e.ts +194 -0
- package/src/dex/integral/utils.ts +146 -0
- package/src/dex/jarvis.ts +262 -0
- package/src/dex/mStable.ts +147 -0
- package/src/dex/onebit/onebit.ts +113 -0
- package/src/dex/onebit/types.ts +17 -0
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders-e2e.test.ts +68 -152
- package/src/dex/paraswap-limit-orders/paraswap-limit-orders.ts +0 -3
- package/src/dex/shell.ts +84 -0
- package/src/dex/trader-joe-v2.ts +148 -0
- package/src/dex/uniswap-v3/contract-math/Oracle.ts +5 -4
- package/src/dex/zerox/config.ts +31 -0
- package/src/dex/zerox/index.ts +328 -0
- package/src/dex/zerox/order.ts +62 -0
- package/src/dex/zerox/types.ts +82 -0
- package/src/dex/zerox/zerox-e2e.test.ts +110 -0
- package/src/generic-swap-transaction-builder.ts +3 -1
- package/src/router/simpleswap.ts +3 -1
- package/tests/constants-e2e.ts +2 -2
- package/tests/utils-e2e.ts +0 -2
- 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/src/abi/curve-v1-factory/CurveV1Router.abi.json +0 -331
- package/src/dex/curve-v1-factory/optimizer.ts +0 -61
package/build/dex/index.js
CHANGED
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DexAdapterService = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
8
|
const curve_v2_1 = require("./curve-v2/curve-v2");
|
|
9
|
+
const jarvis_1 = require("./jarvis");
|
|
9
10
|
const jarvis_v6_1 = require("./jarvis-v6/jarvis-v6");
|
|
10
11
|
const stable_pool_1 = require("./stable-pool/stable-pool");
|
|
11
12
|
const weth_1 = require("./weth/weth");
|
|
12
13
|
const polygon_migrator_1 = require("./polygon-migrator/polygon-migrator");
|
|
14
|
+
const zerox_1 = require("./zerox");
|
|
13
15
|
const uniswap_v3_1 = require("./uniswap-v3/uniswap-v3");
|
|
14
16
|
const balancer_v2_1 = require("./balancer-v2/balancer-v2");
|
|
15
17
|
const optimizer_1 = require("./balancer-v2/optimizer");
|
|
@@ -20,10 +22,15 @@ const biswap_1 = require("./uniswap-v2/biswap");
|
|
|
20
22
|
const mdex_1 = require("./uniswap-v2/mdex");
|
|
21
23
|
const dfyn_1 = require("./uniswap-v2/dfyn");
|
|
22
24
|
const bancor_1 = require("./bancor/bancor");
|
|
25
|
+
const bProtocol_1 = require("./bProtocol/bProtocol");
|
|
26
|
+
const mStable_1 = require("./mStable");
|
|
27
|
+
const shell_1 = require("./shell");
|
|
28
|
+
const onebit_1 = require("./onebit/onebit");
|
|
23
29
|
const compound_1 = require("./compound/compound");
|
|
24
30
|
const aave_v2_1 = require("./aave-v2/aave-v2");
|
|
25
31
|
const aave_v3_1 = require("./aave-v3/aave-v3");
|
|
26
32
|
const idle_dao_1 = require("./idle-dao/idle-dao");
|
|
33
|
+
const OneInchLp_1 = require("./OneInchLp");
|
|
27
34
|
const dodo_v1_1 = require("./dodo-v1/dodo-v1");
|
|
28
35
|
const dodo_v2_1 = require("./dodo-v2");
|
|
29
36
|
const smoothy_1 = require("./smoothy/smoothy");
|
|
@@ -57,7 +64,6 @@ const curve_forks_1 = require("./curve-v1/forks/curve-forks/curve-forks");
|
|
|
57
64
|
const swerve_1 = require("./curve-v1/forks/swerve/swerve");
|
|
58
65
|
const curve_v1_factory_1 = require("./curve-v1-factory/curve-v1-factory");
|
|
59
66
|
const curve_v1_stable_ng_1 = require("./curve-v1-stable-ng/curve-v1-stable-ng");
|
|
60
|
-
const optimizer_4 = require("./curve-v1-factory/optimizer");
|
|
61
67
|
const generic_rfq_1 = require("./generic-rfq/generic-rfq");
|
|
62
68
|
const wsteth_1 = require("./wsteth/wsteth");
|
|
63
69
|
const camelot_1 = require("./camelot/camelot");
|
|
@@ -67,6 +73,7 @@ const maverick_v1_1 = require("./maverick-v1/maverick-v1");
|
|
|
67
73
|
const maverick_v2_1 = require("./maverick-v2/maverick-v2");
|
|
68
74
|
const quickswap_v3_1 = require("./quickswap/quickswap-v3");
|
|
69
75
|
const thena_fusion_1 = require("./quickswap/thena-fusion");
|
|
76
|
+
const trader_joe_v2_1 = require("./trader-joe-v2");
|
|
70
77
|
const swaap_v2_1 = require("./swaap-v2/swaap-v2");
|
|
71
78
|
const trader_joe_v2_1_1 = require("./trader-joe-v2.1/trader-joe-v2.1");
|
|
72
79
|
const pancakeswap_v3_1 = require("./pancakeswap-v3/pancakeswap-v3");
|
|
@@ -78,6 +85,7 @@ const nomiswap_v2_1 = require("./uniswap-v2/nomiswap-v2");
|
|
|
78
85
|
const dexalot_1 = require("./dexalot/dexalot");
|
|
79
86
|
const wombat_1 = require("./wombat/wombat");
|
|
80
87
|
const swell_1 = require("./swell/swell");
|
|
88
|
+
const integral_1 = require("./integral/integral");
|
|
81
89
|
const pharaohV1_1 = require("./solidly/forks-override/pharaohV1");
|
|
82
90
|
const etherfi_1 = require("./etherfi");
|
|
83
91
|
const spark_1 = require("./spark/spark");
|
|
@@ -87,13 +95,21 @@ const LegacyDexes = [
|
|
|
87
95
|
curve_v2_1.CurveV2,
|
|
88
96
|
stable_pool_1.StablePool,
|
|
89
97
|
smoothy_1.Smoothy,
|
|
98
|
+
zerox_1.ZeroX,
|
|
90
99
|
bancor_1.Bancor,
|
|
100
|
+
bProtocol_1.BProtocol,
|
|
101
|
+
mStable_1.MStable,
|
|
102
|
+
shell_1.Shell,
|
|
103
|
+
onebit_1.Onebit,
|
|
91
104
|
compound_1.Compound,
|
|
105
|
+
OneInchLp_1.OneInchLp,
|
|
92
106
|
dodo_v1_1.DodoV1,
|
|
93
107
|
dodo_v2_1.DodoV2,
|
|
94
108
|
quickswap_v3_1.QuickSwapV3,
|
|
95
109
|
thena_fusion_1.ThenaFusion,
|
|
110
|
+
trader_joe_v2_1.TraderJoeV2,
|
|
96
111
|
trader_joe_v2_1_1.TraderJoeV21,
|
|
112
|
+
jarvis_1.Jarvis,
|
|
97
113
|
lido_1.Lido,
|
|
98
114
|
augustus_rfq_1.AugustusRFQOrder,
|
|
99
115
|
etherfi_1.EtherFi,
|
|
@@ -154,6 +170,7 @@ const Dexes = [
|
|
|
154
170
|
solidly_v3_1.SolidlyV3,
|
|
155
171
|
wombat_1.Wombat,
|
|
156
172
|
swell_1.Swell,
|
|
173
|
+
integral_1.Integral,
|
|
157
174
|
pharaohV1_1.PharaohV1,
|
|
158
175
|
spark_1.Spark,
|
|
159
176
|
aave_v3_stata_1.AaveV3Stata,
|
|
@@ -174,7 +191,6 @@ class DexAdapterService {
|
|
|
174
191
|
optimizer_3.balancerV1Merge,
|
|
175
192
|
optimizer_1.balancerV2Merge,
|
|
176
193
|
optimizer_2.uniswapMerge,
|
|
177
|
-
optimizer_4.curveV1Merge,
|
|
178
194
|
];
|
|
179
195
|
LegacyDexes.forEach(DexAdapter => {
|
|
180
196
|
DexAdapter.dexKeys.forEach(key => {
|
|
@@ -271,7 +287,9 @@ class DexAdapterService {
|
|
|
271
287
|
if (this.genericRFQDexKeys.has(dexKey)) {
|
|
272
288
|
return dexKey;
|
|
273
289
|
}
|
|
274
|
-
if (
|
|
290
|
+
if (!isAdapters && /^paraswappool(.*)/i.test(dexKey))
|
|
291
|
+
return 'zerox';
|
|
292
|
+
else if ('uniswapforkoptimized' === dexKey) {
|
|
275
293
|
if (!this.uniswapV2Alias)
|
|
276
294
|
throw new Error(`${dexKey} dex is not supported for network(${this.network})!`);
|
|
277
295
|
return this.uniswapV2Alias;
|
package/build/dex/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dex/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,kDAA8C;AAE9C,qDAAiD;AACjD,2DAAuD;AACvD,sCAAmC;AACnC,0EAAsE;AACtE,wDAAoD;AACpD,2DAAuD;AACvD,uDAA0D;AAC1D,wDAAoD;AACpD,sDAAwD;AACxD,sDAAsD;AACtD,gDAA6C;AAC7C,4CAAyC;AACzC,4CAAyC;AACzC,4CAAyC;AACzC,kDAA+C;AAC/C,+CAA2C;AAC3C,+CAA2C;AAC3C,kDAA8C;AAC9C,+CAA2C;AAC3C,uCAAmC;AACnC,+CAA4C;AAC5C,yCAAsC;AAEtC,4CAAwC;AAExC,sCAAmC;AACnC,sDAAmD;AACnD,qDAAiD;AACjD,kDAA+C;AAC/C,mCAAgC;AAChC,qDAAgD;AAChD,yFAAoF;AACpF,iDAAkD;AAClD,+CAA4C;AAC5C,wDAAoD;AACpD,4DAAyD;AACzD,0DAAuD;AACvD,8DAA2D;AAC3D,kEAA+D;AAC/D,sEAAmE;AACnE,kEAA+D;AAC/D,wEAAqE;AACrE,qDAAkD;AAClD,0DAAuD;AACvD,kEAA+D;AAC/D,sEAAmE;AACnE,2DAAuD;AACvD,uDAA0D;AAC1D,kDAA8C;AAC9C,0EAAqE;AACrE,2DAAwD;AACxD,0EAAqE;AACrE,gFAA0E;AAC1E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dex/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,kDAA8C;AAE9C,qCAAkC;AAClC,qDAAiD;AACjD,2DAAuD;AACvD,sCAAmC;AACnC,0EAAsE;AACtE,mCAAgC;AAChC,wDAAoD;AACpD,2DAAuD;AACvD,uDAA0D;AA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CAAC;QAC9B,IAAI,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACtC,OAAO,MAAM,CAAC;SACf;QACD,IAAI,CAAC,UAAU,IAAI,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,OAAO,OAAO,CAAC;aAChE,IAAI,sBAAsB,KAAK,MAAM,EAAE;YAC1C,IAAI,CAAC,IAAI,CAAC,cAAc;gBACtB,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,qCAAqC,IAAI,CAAC,OAAO,IAAI,CAC/D,CAAC;YACJ,OAAO,IAAI,CAAC,cAAc,CAAC;SAC5B;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,UAAU,CAAC,MAAc,EAAE,IAAc;QACvC,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC1D,OAAO,IAAI,KAAK,oBAAQ,CAAC,IAAI;YAC3B,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;YAClC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACtC,CAAC;IAED,qCAAqC,CAAC,MAAc;QAClD,IAAI;YACF,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,CAAC,CAAC,GAAG,CAAC,4BAA4B,CAAC;SAC3C;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF;AApLD,8CAoLC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Adapters = exports.IntegralConfig = void 0;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
exports.IntegralConfig = {
|
|
6
|
+
Integral: {
|
|
7
|
+
[constants_1.Network.MAINNET]: {
|
|
8
|
+
factoryAddress: '0xC480b33eE5229DE3FbDFAD1D2DCD3F3BAD0C56c6',
|
|
9
|
+
relayerAddress: '0xd17b3c9784510E33cD5B87b490E79253BcD81e2E',
|
|
10
|
+
subgraphURL: 'ANd5QJuYtyfngmXvBMu9kZAv935vhcqp4xAGBkmCADN3',
|
|
11
|
+
},
|
|
12
|
+
[constants_1.Network.ARBITRUM]: {
|
|
13
|
+
factoryAddress: '0x717EF162cf831db83c51134734A15D1EBe9E516a',
|
|
14
|
+
relayerAddress: '0x3c6951FDB433b5b8442e7aa126D50fBFB54b5f42',
|
|
15
|
+
subgraphURL: 'HXeVedRK7VgogXwbK5Sc4mjyLkhBAS5akskRvbSYnkHU',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
exports.Adapters = {};
|
|
20
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/integral/config.ts"],"names":[],"mappings":";;;AAEA,+CAA0C;AAE7B,QAAA,cAAc,GAA4B;IACrD,QAAQ,EAAE;QACR,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,cAAc,EAAE,4CAA4C;YAC5D,cAAc,EAAE,4CAA4C;YAC5D,WAAW,EAAE,8CAA8C;SAC5D;QACD,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE;YAClB,cAAc,EAAE,4CAA4C;YAC5D,cAAc,EAAE,4CAA4C;YAC5D,WAAW,EAAE,8CAA8C;SAC5D;KACF;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC,EAAE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Address } from '@paraswap/core';
|
|
2
|
+
import { IntegralFactory } from './integral-factory';
|
|
3
|
+
import { IntegralRelayer } from './integral-relayer';
|
|
4
|
+
import { Network } from '../../constants';
|
|
5
|
+
import { IDexHelper } from '../../dex-helper';
|
|
6
|
+
import { Logger } from 'log4js';
|
|
7
|
+
import { Interface } from '@ethersproject/abi';
|
|
8
|
+
import { IntegralPool, PoolInitProps, RelayerPoolState } from './types';
|
|
9
|
+
import { IntegralToken } from './integral-token';
|
|
10
|
+
export declare class IntegralContext {
|
|
11
|
+
readonly network: Network;
|
|
12
|
+
readonly dexKey: string;
|
|
13
|
+
readonly dexHelper: IDexHelper;
|
|
14
|
+
readonly erc20Interface: Interface;
|
|
15
|
+
readonly factoryAddress: Address;
|
|
16
|
+
readonly relayerAddress: Address;
|
|
17
|
+
static instances: {
|
|
18
|
+
[network: number]: IntegralContext;
|
|
19
|
+
};
|
|
20
|
+
pools: {
|
|
21
|
+
[poolId: string]: IntegralPool;
|
|
22
|
+
};
|
|
23
|
+
tokens: {
|
|
24
|
+
[tokenAddress: Address]: IntegralToken;
|
|
25
|
+
};
|
|
26
|
+
factory: IntegralFactory;
|
|
27
|
+
relayer: IntegralRelayer;
|
|
28
|
+
logger: Logger;
|
|
29
|
+
private constructor();
|
|
30
|
+
addPools(pools: PoolInitProps, blockNumber: number, initPhase?: boolean): Promise<void>;
|
|
31
|
+
getPoolAddresses(): string[];
|
|
32
|
+
private removeDisabledPoolInitProps;
|
|
33
|
+
static initialize(network: Network, dexKey: string, dexHelper: IDexHelper, erc20Interface: Interface, factoryAddress: Address, relayerAddress: Address): IntegralContext;
|
|
34
|
+
static getInstance(network: Network): IntegralContext;
|
|
35
|
+
onRelayerPoolEnabledSet(poolAddress: Address, state: RelayerPoolState, blockNumber: number): Promise<void>;
|
|
36
|
+
onRebalanceSellOrderExecuted(blockNumber: number, orderId: bigint): void;
|
|
37
|
+
onPoolCreatedAddPool(token0: Address, token1: Address, poolAddress: Address, blockNumber: number): Promise<void>;
|
|
38
|
+
onPoolSwapForRelayer(blockNumber: number, poolAddress: Address, recipient: Address, amount0Out: bigint, amount1Out: bigint): Promise<void>;
|
|
39
|
+
onTransferUpdateBalance(token: Address, from: Address, to: Address, amount: bigint, blockNumber: number): Promise<void>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
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.IntegralContext = void 0;
|
|
7
|
+
const integral_pool_1 = require("./integral-pool");
|
|
8
|
+
const integral_pricing_1 = require("./integral-pricing");
|
|
9
|
+
const integral_factory_1 = require("./integral-factory");
|
|
10
|
+
const integral_relayer_1 = require("./integral-relayer");
|
|
11
|
+
const integral_token_1 = require("./integral-token");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
+
class IntegralContext {
|
|
15
|
+
constructor(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
|
|
16
|
+
this.network = network;
|
|
17
|
+
this.dexKey = dexKey;
|
|
18
|
+
this.dexHelper = dexHelper;
|
|
19
|
+
this.erc20Interface = erc20Interface;
|
|
20
|
+
this.factoryAddress = factoryAddress;
|
|
21
|
+
this.relayerAddress = relayerAddress;
|
|
22
|
+
this.pools = {};
|
|
23
|
+
this.tokens = {};
|
|
24
|
+
this.logger = dexHelper.getLogger(dexKey);
|
|
25
|
+
this.factory = new integral_factory_1.IntegralFactory(dexHelper, dexKey, this.factoryAddress, this.onPoolCreatedAddPool, this.logger);
|
|
26
|
+
this.relayer = new integral_relayer_1.IntegralRelayer(dexHelper, dexKey, this.erc20Interface, this.relayerAddress, {}, this.onRelayerPoolEnabledSet, this.logger);
|
|
27
|
+
}
|
|
28
|
+
async addPools(pools, blockNumber, initPhase = false) {
|
|
29
|
+
this.relayer.addPools(pools);
|
|
30
|
+
if (initPhase) {
|
|
31
|
+
await this.relayer.initialize(blockNumber);
|
|
32
|
+
}
|
|
33
|
+
const _relayerState = this.relayer.getState(blockNumber);
|
|
34
|
+
const relayerState = _relayerState
|
|
35
|
+
? _relayerState
|
|
36
|
+
: await this.relayer.generateState(blockNumber);
|
|
37
|
+
if (!_relayerState) {
|
|
38
|
+
this.relayer.setState(relayerState, blockNumber);
|
|
39
|
+
}
|
|
40
|
+
const poolInitProps = this.removeDisabledPoolInitProps(relayerState, pools);
|
|
41
|
+
const bases = Object.entries(poolInitProps).map(([poolAddress, p]) => {
|
|
42
|
+
const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, p.token0, p.token1);
|
|
43
|
+
const base = (this.pools[poolId] && this.pools[poolId].base) ||
|
|
44
|
+
new integral_pool_1.IntegralEventPool(this.dexKey, this.network, this.dexHelper, poolAddress, p.token0, p.token1, this.logger);
|
|
45
|
+
this.pools[poolId] = { base, enabled: true };
|
|
46
|
+
return base;
|
|
47
|
+
});
|
|
48
|
+
await Promise.all(bases.map(base => !base.isInitialized && base.initialize(blockNumber)));
|
|
49
|
+
const pricings = await Promise.all(bases.map(async (base) => {
|
|
50
|
+
const _poolState = base.getState(blockNumber);
|
|
51
|
+
const poolState = _poolState
|
|
52
|
+
? _poolState
|
|
53
|
+
: await base.generateState(blockNumber);
|
|
54
|
+
const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, base.token0, base.token1);
|
|
55
|
+
const pricing = (this.pools[poolId] && this.pools[poolId].pricing) ||
|
|
56
|
+
new integral_pricing_1.IntegralPricing(this.dexHelper, poolId, this.erc20Interface, poolState.uniswapPool, base.token0, base.token1, poolState.uniswapPoolFee, this.logger, this.network);
|
|
57
|
+
this.pools[poolId].pricing = pricing;
|
|
58
|
+
return pricing;
|
|
59
|
+
}));
|
|
60
|
+
await Promise.all(pricings.map(pricing => !pricing.isInitialized && pricing.initialize(blockNumber)));
|
|
61
|
+
const initIntegralToken = (token) => new integral_token_1.IntegralToken(this.network, this.dexHelper, this.dexKey, this.erc20Interface, token, this.relayerAddress, this.onTransferUpdateBalance, this.logger);
|
|
62
|
+
bases.map(base => {
|
|
63
|
+
this.tokens[base.token0] =
|
|
64
|
+
this.tokens[base.token0] || initIntegralToken(base.token0);
|
|
65
|
+
this.tokens[base.token1] =
|
|
66
|
+
this.tokens[base.token1] || initIntegralToken(base.token1);
|
|
67
|
+
});
|
|
68
|
+
await Promise.all(Object.values(this.tokens).map(token => !token.isInitialized && token.initialize(blockNumber)));
|
|
69
|
+
}
|
|
70
|
+
getPoolAddresses() {
|
|
71
|
+
return Object.values(this.pools)
|
|
72
|
+
.filter((pool) => !!pool.base && pool.enabled)
|
|
73
|
+
.map(({ base }) => base.poolAddress);
|
|
74
|
+
}
|
|
75
|
+
removeDisabledPoolInitProps(state, props) {
|
|
76
|
+
Object.entries(state.pools).forEach(([poolAddress, poolState]) => !poolState.isEnabled && delete props[poolAddress]);
|
|
77
|
+
return props;
|
|
78
|
+
}
|
|
79
|
+
static initialize(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
|
|
80
|
+
if (!this.instances[network]) {
|
|
81
|
+
this.instances[network] = new IntegralContext(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress);
|
|
82
|
+
}
|
|
83
|
+
return this.instances[network];
|
|
84
|
+
}
|
|
85
|
+
static getInstance(network) {
|
|
86
|
+
if (!this.instances[network]) {
|
|
87
|
+
throw new Error('IntegralContext instance not initialized');
|
|
88
|
+
}
|
|
89
|
+
return this.instances[network];
|
|
90
|
+
}
|
|
91
|
+
async onRelayerPoolEnabledSet(poolAddress, state, blockNumber) {
|
|
92
|
+
const poolEntry = (0, utils_1.getPoolBackReferencedFrom)(this, poolAddress);
|
|
93
|
+
if (state.isEnabled && (!poolEntry || !poolEntry[1].enabled)) {
|
|
94
|
+
const _factoryState = this.factory.getStaleState();
|
|
95
|
+
const factoryState = _factoryState
|
|
96
|
+
? _factoryState
|
|
97
|
+
: await this.factory.generateState(blockNumber);
|
|
98
|
+
const { token0, token1 } = factoryState.pools[poolAddress];
|
|
99
|
+
await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
|
|
100
|
+
}
|
|
101
|
+
else if (!state.isEnabled && poolEntry && poolEntry[1].enabled) {
|
|
102
|
+
this.pools[poolEntry[0]].enabled = false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
onRebalanceSellOrderExecuted(blockNumber, orderId) {
|
|
106
|
+
this.relayer.executeOrder(orderId, blockNumber);
|
|
107
|
+
}
|
|
108
|
+
async onPoolCreatedAddPool(token0, token1, poolAddress, blockNumber) {
|
|
109
|
+
await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
|
|
110
|
+
}
|
|
111
|
+
async onPoolSwapForRelayer(blockNumber, poolAddress, recipient, amount0Out, amount1Out) {
|
|
112
|
+
if (recipient.toLowerCase() === this.relayerAddress.toLowerCase()) {
|
|
113
|
+
const pools = this.relayer.getPools();
|
|
114
|
+
if (pools[poolAddress.toLowerCase()]) {
|
|
115
|
+
const token0 = pools[poolAddress.toLowerCase()].token0;
|
|
116
|
+
const token1 = pools[poolAddress.toLowerCase()].token1;
|
|
117
|
+
let _state = this.relayer.getStaleState();
|
|
118
|
+
if (!_state) {
|
|
119
|
+
_state = await this.relayer.generateState(blockNumber);
|
|
120
|
+
this.relayer.setState(_state, blockNumber);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
blockNumber = this.relayer.getStateBlockNumber();
|
|
125
|
+
}
|
|
126
|
+
const state = lodash_1.default.cloneDeep(_state);
|
|
127
|
+
if (amount1Out > 0n) {
|
|
128
|
+
state.tokens[token1].balance += amount1Out;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
state.tokens[token0].balance += amount0Out;
|
|
132
|
+
}
|
|
133
|
+
this.relayer.setState(state, blockNumber);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
this.logger.error('Integral Relayer: Pool address not found for', poolAddress);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async onTransferUpdateBalance(token, from, to, amount, blockNumber) {
|
|
141
|
+
let _state = this.relayer.getStaleState();
|
|
142
|
+
if (!_state) {
|
|
143
|
+
this.logger.error('Integral Token: Relayer stale state not found');
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const state = lodash_1.default.cloneDeep(_state);
|
|
147
|
+
if (this.relayer.relayerAddress.toLowerCase() === from) {
|
|
148
|
+
state.tokens[token].balance -= amount;
|
|
149
|
+
}
|
|
150
|
+
else if (this.relayer.relayerAddress.toLowerCase() === to) {
|
|
151
|
+
state.tokens[token].balance += amount;
|
|
152
|
+
}
|
|
153
|
+
this.relayer.setState(state, blockNumber);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.IntegralContext = IntegralContext;
|
|
157
|
+
IntegralContext.instances = {};
|
|
158
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/dex/integral/context.ts"],"names":[],"mappings":";;;;;;AACA,mDAAoD;AACpD,yDAAqD;AACrD,yDAAqD;AACrD,yDAAqD;AAYrD,qDAAiD;AACjD,mCAAuE;AACvE,oDAAuB;AAEvB,MAAa,eAAe;IAU1B,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACrB,cAAyB,EACzB,cAAuB,EACvB,cAAuB;QALvB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACrB,mBAAc,GAAd,cAAc,CAAW;QACzB,mBAAc,GAAd,cAAc,CAAS;QACvB,mBAAc,GAAd,cAAc,CAAS;QAblC,UAAK,GAAuC,EAAE,CAAC;QAC/C,WAAM,GAA+C,EAAE,CAAC;QActD,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,IAAI,kCAAe,CAChC,SAAS,EACT,MAAM,EACN,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,oBAAoB,EACzB,IAAI,CAAC,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,MAAc,EACd,WAAmB;QAEnB,IAAI,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC1C,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;YACnE,OAAO;SACR;QACD,MAAM,KAAK,GAAiB,gBAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;YACtD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;SACvC;aAAM,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;YAC3D,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;SACvC;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;;AAzQH,0CA0QC;AAzQQ,yBAAS,GAA2C,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Address } from '../../types';
|
|
2
|
+
import { PoolState as UniswapPoolState } from '../uniswap-v3/types';
|
|
3
|
+
import { IntegralContext } from './context';
|
|
4
|
+
import { PoolStates, RelayerPoolState } from './types';
|
|
5
|
+
export declare function sortTokens(srcAddress: Address, destAddress: Address): string[];
|
|
6
|
+
export declare function getDecimalsConverter(decimals0: number, decimals1: number, inverted: boolean): bigint;
|
|
7
|
+
export declare function getPrice(states: PoolStates, inverted: boolean): bigint;
|
|
8
|
+
export declare function getSpotPrice(pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
|
|
9
|
+
export declare function getAveragePrice(relayer: RelayerPoolState, pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
|
|
10
|
+
export declare function getTickCumulatives(poolState: UniswapPoolState, secondsAgos: bigint[]): bigint[];
|
|
11
|
+
export declare function isInverted(tokenIn: Address, tokenOut: Address): boolean;
|
|
12
|
+
export declare function getPoolIdentifier(dexKey: string, srcAddress: Address, destAddress: Address): string;
|
|
13
|
+
export declare function onPoolSwapForRelayer(blockNumber: number, poolAddress: Address, recipient: Address, amount0Out: bigint, amount1Out: bigint, _context?: IntegralContext): Promise<void>;
|
|
14
|
+
export declare function onRelayerPoolEnabledSet(poolAddress: Address, state: RelayerPoolState, blockNumber: number): Promise<void>;
|
|
15
|
+
export declare function onRebalanceSellOrderExecuted(blockNumber: number, orderId: bigint): void;
|
|
16
|
+
export declare function onPoolCreatedAddPool(token0: Address, token1: Address, poolAddress: Address, blockNumber: number): Promise<void>;
|
|
17
|
+
export declare function onTransferUpdateBalance(token: Address, from: Address, to: Address, amount: bigint, blockNumber: number, _context?: IntegralContext): Promise<void>;
|
|
@@ -0,0 +1,157 @@
|
|
|
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.onTransferUpdateBalance = exports.onPoolCreatedAddPool = exports.onRebalanceSellOrderExecuted = exports.onRelayerPoolEnabledSet = exports.onPoolSwapForRelayer = exports.getPoolIdentifier = exports.isInverted = exports.getTickCumulatives = exports.getAveragePrice = exports.getSpotPrice = exports.getPrice = exports.getDecimalsConverter = exports.sortTokens = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
const FullMath_1 = require("../uniswap-v3/contract-math/FullMath");
|
|
10
|
+
const Oracle_1 = require("../uniswap-v3/contract-math/Oracle");
|
|
11
|
+
const TickMath_1 = require("../uniswap-v3/contract-math/TickMath");
|
|
12
|
+
const context_1 = require("./context");
|
|
13
|
+
function sortTokens(srcAddress, destAddress) {
|
|
14
|
+
return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
|
|
15
|
+
}
|
|
16
|
+
exports.sortTokens = sortTokens;
|
|
17
|
+
function getDecimalsConverter(decimals0, decimals1, inverted) {
|
|
18
|
+
return (10n **
|
|
19
|
+
(18n + BigInt(inverted ? decimals1 - decimals0 : decimals0 - decimals1)));
|
|
20
|
+
}
|
|
21
|
+
exports.getDecimalsConverter = getDecimalsConverter;
|
|
22
|
+
function getPrice(states, inverted) {
|
|
23
|
+
const { base, pricing, relayer } = states;
|
|
24
|
+
const decimalsConverter = getDecimalsConverter(base.decimals0, base.decimals1, false);
|
|
25
|
+
const spotPrice = getSpotPrice(pricing, decimalsConverter);
|
|
26
|
+
const averagePrice = getAveragePrice(relayer, pricing, decimalsConverter);
|
|
27
|
+
if (inverted) {
|
|
28
|
+
return 10n ** 36n / (spotPrice > averagePrice ? spotPrice : averagePrice);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return spotPrice < averagePrice ? spotPrice : averagePrice;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.getPrice = getPrice;
|
|
35
|
+
function getSpotPrice(pricing, decimalsConverter) {
|
|
36
|
+
const sqrtPriceX96 = pricing.slot0.sqrtPriceX96;
|
|
37
|
+
const priceX128 = FullMath_1.FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 2n ** 64n);
|
|
38
|
+
return FullMath_1.FullMath.mulDiv(priceX128, decimalsConverter, 2n ** 128n);
|
|
39
|
+
}
|
|
40
|
+
exports.getSpotPrice = getSpotPrice;
|
|
41
|
+
function getAveragePrice(relayer, pricing, decimalsConverter) {
|
|
42
|
+
(0, utils_1._require)(relayer.twapInterval > 0, 'Twap Interval not set');
|
|
43
|
+
const secondsAgo = BigInt(relayer.twapInterval);
|
|
44
|
+
const secondsAgos = [secondsAgo, 0n];
|
|
45
|
+
const tickCumulatives = getTickCumulatives(pricing, secondsAgos);
|
|
46
|
+
const delta = tickCumulatives[1] - tickCumulatives[0];
|
|
47
|
+
let arithmeticMeanTick = delta / secondsAgo;
|
|
48
|
+
if (delta < 0 && delta % secondsAgo != 0n) {
|
|
49
|
+
--arithmeticMeanTick;
|
|
50
|
+
}
|
|
51
|
+
const sqrtRatioX96 = TickMath_1.TickMath.getSqrtRatioAtTick(arithmeticMeanTick);
|
|
52
|
+
const ratioX128 = FullMath_1.FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 2n ** 64n);
|
|
53
|
+
return FullMath_1.FullMath.mulDiv(ratioX128, decimalsConverter, 2n ** 128n);
|
|
54
|
+
}
|
|
55
|
+
exports.getAveragePrice = getAveragePrice;
|
|
56
|
+
function getTickCumulatives(poolState, secondsAgos) {
|
|
57
|
+
const { tickCumulatives } = secondsAgos.reduce((memo, secondsAgo, i) => {
|
|
58
|
+
[memo.tickCumulatives[i], memo.secondsPerLiquidityCumulativeX128s[i]] =
|
|
59
|
+
Oracle_1.Oracle.observeSingle(poolState, BigInt.asUintN(32, poolState.blockTimestamp), secondsAgo, poolState.slot0.tick, poolState.slot0.observationIndex, poolState.liquidity, poolState.slot0.observationCardinality);
|
|
60
|
+
return memo;
|
|
61
|
+
}, {
|
|
62
|
+
tickCumulatives: Array(secondsAgos.length),
|
|
63
|
+
secondsPerLiquidityCumulativeX128s: Array(secondsAgos.length),
|
|
64
|
+
});
|
|
65
|
+
return tickCumulatives;
|
|
66
|
+
}
|
|
67
|
+
exports.getTickCumulatives = getTickCumulatives;
|
|
68
|
+
function isInverted(tokenIn, tokenOut) {
|
|
69
|
+
const [, token1] = tokenIn.toLowerCase() < tokenOut.toLowerCase()
|
|
70
|
+
? [tokenIn, tokenOut]
|
|
71
|
+
: [tokenOut, tokenIn];
|
|
72
|
+
return tokenIn === token1;
|
|
73
|
+
}
|
|
74
|
+
exports.isInverted = isInverted;
|
|
75
|
+
function getPoolIdentifier(dexKey, srcAddress, destAddress) {
|
|
76
|
+
const tokenAddresses = sortTokens(srcAddress.toLowerCase(), destAddress.toLowerCase()).join('_');
|
|
77
|
+
return `${dexKey}_${tokenAddresses}`;
|
|
78
|
+
}
|
|
79
|
+
exports.getPoolIdentifier = getPoolIdentifier;
|
|
80
|
+
async function onPoolSwapForRelayer(blockNumber, poolAddress, recipient, amount0Out, amount1Out, _context) {
|
|
81
|
+
const context = _context || context_1.IntegralContext.getInstance();
|
|
82
|
+
if (recipient.toLowerCase() === context.relayerAddress.toLowerCase()) {
|
|
83
|
+
const pools = context.relayer.getPools();
|
|
84
|
+
if (pools[poolAddress.toLowerCase()]) {
|
|
85
|
+
const token0 = pools[poolAddress.toLowerCase()].token0;
|
|
86
|
+
const token1 = pools[poolAddress.toLowerCase()].token1;
|
|
87
|
+
let _state = context.relayer.getStaleState();
|
|
88
|
+
if (!_state) {
|
|
89
|
+
_state = await context.relayer.generateState(blockNumber);
|
|
90
|
+
context.relayer.setState(_state, blockNumber);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
blockNumber = context.relayer.getStateBlockNumber();
|
|
95
|
+
}
|
|
96
|
+
const state = lodash_1.default.cloneDeep(_state);
|
|
97
|
+
if (amount1Out > 0n) {
|
|
98
|
+
state.tokens[token1].balance += amount1Out;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
state.tokens[token0].balance += amount0Out;
|
|
102
|
+
}
|
|
103
|
+
context.relayer.setState(state, blockNumber);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
context.logger.error('Integral Relayer: Pool address not found for', poolAddress);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.onPoolSwapForRelayer = onPoolSwapForRelayer;
|
|
111
|
+
function getPoolBackReferencedFrom(context, poolAddress) {
|
|
112
|
+
return Object.entries(context.pools).find(([, pool]) => pool.base?.poolAddress === poolAddress);
|
|
113
|
+
}
|
|
114
|
+
async function onRelayerPoolEnabledSet(poolAddress, state, blockNumber) {
|
|
115
|
+
const context = context_1.IntegralContext.getInstance();
|
|
116
|
+
const poolEntry = getPoolBackReferencedFrom(context, poolAddress);
|
|
117
|
+
if (state.isEnabled && (!poolEntry || !poolEntry[1].enabled)) {
|
|
118
|
+
const _factoryState = context.factory.getStaleState();
|
|
119
|
+
const factoryState = _factoryState
|
|
120
|
+
? _factoryState
|
|
121
|
+
: await context.factory.generateState(blockNumber);
|
|
122
|
+
const { token0, token1 } = factoryState.pools[poolAddress];
|
|
123
|
+
await context.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
|
|
124
|
+
}
|
|
125
|
+
else if (!state.isEnabled && poolEntry && poolEntry[1].enabled) {
|
|
126
|
+
context.pools[poolEntry[0]].enabled = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.onRelayerPoolEnabledSet = onRelayerPoolEnabledSet;
|
|
130
|
+
function onRebalanceSellOrderExecuted(blockNumber, orderId) {
|
|
131
|
+
const context = context_1.IntegralContext.getInstance();
|
|
132
|
+
context.relayer.executeOrder(orderId, blockNumber);
|
|
133
|
+
}
|
|
134
|
+
exports.onRebalanceSellOrderExecuted = onRebalanceSellOrderExecuted;
|
|
135
|
+
async function onPoolCreatedAddPool(token0, token1, poolAddress, blockNumber) {
|
|
136
|
+
const context = context_1.IntegralContext.getInstance();
|
|
137
|
+
await context.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
|
|
138
|
+
}
|
|
139
|
+
exports.onPoolCreatedAddPool = onPoolCreatedAddPool;
|
|
140
|
+
async function onTransferUpdateBalance(token, from, to, amount, blockNumber, _context) {
|
|
141
|
+
const context = _context || context_1.IntegralContext.getInstance();
|
|
142
|
+
let _state = context.relayer.getStaleState();
|
|
143
|
+
if (!_state) {
|
|
144
|
+
context.logger.error('Integral Token: Relayer stale state not found');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const state = lodash_1.default.cloneDeep(_state);
|
|
148
|
+
if (context.relayer.relayerAddress.toLowerCase() === from) {
|
|
149
|
+
state.tokens[token].balance -= amount;
|
|
150
|
+
}
|
|
151
|
+
else if (context.relayer.relayerAddress.toLowerCase() === to) {
|
|
152
|
+
state.tokens[token].balance += amount;
|
|
153
|
+
}
|
|
154
|
+
context.relayer.setState(state, blockNumber);
|
|
155
|
+
}
|
|
156
|
+
exports.onTransferUpdateBalance = onTransferUpdateBalance;
|
|
157
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/dex/integral/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,uCAAuC;AACvC,mEAAgE;AAChE,+DAA4D;AAC5D,mEAAgE;AAEhE,uCAA4C;AAG5C,SAAgB,UAAU,CAAC,UAAmB,EAAE,WAAoB;IAClE,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC;AAFD,gCAEC;AAED,SAAgB,oBAAoB,CAClC,SAAiB,EACjB,SAAiB,EACjB,QAAiB;IAEjB,OAAO,CACL,GAAG;QACH,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CAAC,CACzE,CAAC;AACJ,CAAC;AATD,oDASC;AAED,SAAgB,QAAQ,CAAC,MAAkB,EAAE,QAAiB;IAC5D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAC1C,MAAM,iBAAiB,GAAG,oBAAoB,CAC5C,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,SAAS,EACd,KAAK,CACN,CAAC;IACF,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,iBAAi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CAAC,aAAa,EAAE,CAAC;IAC7C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACtE,OAAO;KACR;IACD,MAAM,KAAK,GAAiB,gBAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QACzD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;KACvC;SAAM,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QAC9D,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;KACvC;IACD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC;AArBD,0DAqBC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { LogDescription } from 'ethers/lib/utils';
|
|
3
|
+
import { IDexHelper } from '../../dex-helper';
|
|
4
|
+
import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
|
|
5
|
+
import { Address, BlockHeader, Log, Logger } from '../../types';
|
|
6
|
+
import { FactoryState } from './types';
|
|
7
|
+
export declare type OnPoolCreatedCallback = (token0: Address, token1: Address, poolAddress: Address, blockNumber: number) => Promise<void>;
|
|
8
|
+
export declare class IntegralFactory extends StatefulEventSubscriber<FactoryState> {
|
|
9
|
+
readonly dexHelper: IDexHelper;
|
|
10
|
+
protected readonly factoryAddress: Address;
|
|
11
|
+
protected readonly onPoolCreated: OnPoolCreatedCallback;
|
|
12
|
+
handlers: {
|
|
13
|
+
[event: string]: (event: any, state: FactoryState, blockHeader: Readonly<BlockHeader>) => Promise<FactoryState>;
|
|
14
|
+
};
|
|
15
|
+
logDecoder: (log: Log) => any;
|
|
16
|
+
readonly factoryIface: Interface;
|
|
17
|
+
constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, onPoolCreated: OnPoolCreatedCallback, logger: Logger, mapKey?: string);
|
|
18
|
+
generateState(blockNumber?: number | 'latest'): Promise<FactoryState>;
|
|
19
|
+
protected processLog(state: FactoryState, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
|
|
20
|
+
handlePairCreated(event: LogDescription, state: FactoryState, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
|
|
21
|
+
}
|