@paraswap/dex-lib 4.1.21 → 4.1.22
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/build/dex/angle-transmuter/angle-transmuter.d.ts +3 -4
- package/build/dex/angle-transmuter/angle-transmuter.js +7 -5
- package/build/dex/angle-transmuter/angle-transmuter.js.map +1 -1
- package/build/dex/cables/cables.js +4 -0
- package/build/dex/cables/cables.js.map +1 -1
- package/build/dex/uniswap-v3/uniswap-v3-new.d.ts +94 -0
- package/build/dex/uniswap-v3/uniswap-v3-new.js +923 -0
- package/build/dex/uniswap-v3/uniswap-v3-new.js.map +1 -0
- package/build/dex/zerox/index.d.ts +1 -1
- package/build/dex/zerox/index.js.map +1 -1
- package/package.json +1 -1
- package/build/abi/AaveV1_lending_pool.json +0 -27
- package/build/abi/Aave_GSM.json +0 -751
- package/build/abi/Balancer.json +0 -257
- package/build/abi/BalancerV2.json +0 -1179
- package/build/abi/RamsesV2Pool.abi.json +0 -1554
- package/build/abi/RamsesV2Quoter.abi.json +0 -274
- package/build/abi/USDM.json +0 -807
- package/build/abi/UniswapV2Router.json +0 -397
- package/build/abi/angle-transmuter/ChainlinkAccessControlledOffchainAggregator.json +0 -1246
- package/build/abi/angle-transmuter/ChainlinkEACAggregatorProxy.json +0 -509
- package/build/abi/curve-v1/CurveBUSDv2.abi.json +0 -1356
- package/build/abi/curve-v1/CurveTokenV1.json +0 -305
- package/build/abi/curve-v1/CurveTokenV2.json +0 -318
- package/build/abi/curve-v1/CurveV1StableNg.json +0 -1452
- package/build/abi/curve-v1/CurveV2Swap.json +0 -700
- package/build/abi/curve-v1/FactoryCryptoRegistry.json +0 -316
- package/build/abi/curve-v1/FactoryRegistry.json +0 -508
- package/build/abi/curve-v1/StableSwapAave.json +0 -1152
- package/build/abi/curve-v1/StableSwapBUSD.json +0 -814
- package/build/abi/curve-v1/StableSwapCompound.json +0 -814
- package/build/abi/curve-v1/StableSwapIDLE.json +0 -1253
- package/build/abi/curve-v1/StableSwapPax.json +0 -865
- package/build/abi/curve-v1/StableSwapSnow.json +0 -900
- package/build/abi/curve-v1/StableSwapUSDN.json +0 -1004
- package/build/abi/curve-v1/StableSwapUSDT.json +0 -814
- package/build/abi/curve-v1/StableSwapY.json +0 -814
- package/build/abi/inception/inception-ineth-pool.json +0 -1062
- package/build/abi/inception/inception-ineth.json +0 -609
- package/build/abi/inception/inception-ratio-feed.json +0 -329
- package/build/abi/inception/inception-vault.json +0 -991
- package/build/abi/kyberdmm/kyber-storage.abi.json +0 -824
- package/build/abi/kyberdmm.abi.json +0 -1148
- package/build/abi/maverick-v2/MaverickV2Quoter.json +0 -278
- package/build/abi/nerve/nerve-metapool.json +0 -790
- package/build/abi/platypus/asset.json +0 -490
- package/build/abi/platypus/avax-pool.json +0 -820
- package/build/abi/platypus/oracle.json +0 -119
- package/build/abi/platypus/pool.json +0 -677
- package/build/abi/smardex/all/smardex-router.json +0 -648
- package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
- package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
- package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
- package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
- package/build/abi/swaap-v1/pool.json +0 -1346
- package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
- package/build/abi/velodrome-slipstream/VelodromeSlipstreamQuoterV2.abi.json +0 -267
- package/build/dex/aave-v1/aave-v1.d.ts +0 -34
- package/build/dex/aave-v1/aave-v1.js +0 -180
- package/build/dex/aave-v1/aave-v1.js.map +0 -1
- package/build/dex/aave-v1/config.d.ts +0 -11
- package/build/dex/aave-v1/config.js +0 -20
- package/build/dex/aave-v1/config.js.map +0 -1
- package/build/dex/aave-v1/tokens-mainnet.json +0 -134
- package/build/dex/aave-v1/tokens.d.ts +0 -3
- package/build/dex/aave-v1/tokens.js +0 -50
- package/build/dex/aave-v1/tokens.js.map +0 -1
- package/build/dex/aave-v1/types.d.ts +0 -12
- package/build/dex/aave-v1/types.js +0 -3
- package/build/dex/aave-v1/types.js.map +0 -1
- package/build/dex/balancer-v1/balancer-pools.json +0 -33333
- package/build/dex/bebop/websocket-fetcher.d.ts +0 -35
- package/build/dex/bebop/websocket-fetcher.js +0 -87
- package/build/dex/bebop/websocket-fetcher.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pool.d.ts +0 -56
- package/build/dex/idle-dao/idle-dao-pool.js +0 -176
- package/build/dex/idle-dao/idle-dao-pool.js.map +0 -1
- package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +0 -16
- package/build/dex/idle-dao/idle-dao-pooling-pool.js +0 -57
- package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +0 -1
- package/build/dex/idle-dao/scripts.d.ts +0 -9
- package/build/dex/idle-dao/scripts.js +0 -552
- package/build/dex/idle-dao/scripts.js.map +0 -1
- package/build/dex/inception/config.d.ts +0 -4
- package/build/dex/inception/config.js +0 -109
- package/build/dex/inception/config.js.map +0 -1
- package/build/dex/inception/inception-event-pool.d.ts +0 -16
- package/build/dex/inception/inception-event-pool.js +0 -51
- package/build/dex/inception/inception-event-pool.js.map +0 -1
- package/build/dex/inception/inception-native.d.ts +0 -43
- package/build/dex/inception/inception-native.js +0 -131
- package/build/dex/inception/inception-native.js.map +0 -1
- package/build/dex/inception/inception-pool.d.ts +0 -18
- package/build/dex/inception/inception-pool.js +0 -32
- package/build/dex/inception/inception-pool.js.map +0 -1
- package/build/dex/inception/inception-price-feed.d.ts +0 -19
- package/build/dex/inception/inception-price-feed.js +0 -51
- package/build/dex/inception/inception-price-feed.js.map +0 -1
- package/build/dex/inception/inception.d.ts +0 -43
- package/build/dex/inception/inception.js +0 -204
- package/build/dex/inception/inception.js.map +0 -1
- package/build/dex/inception/tokens.d.ts +0 -9
- package/build/dex/inception/tokens.js +0 -28
- package/build/dex/inception/tokens.js.map +0 -1
- package/build/dex/inception/types.d.ts +0 -22
- package/build/dex/inception/types.js +0 -3
- package/build/dex/inception/types.js.map +0 -1
- package/build/dex/inception/utils.d.ts +0 -6
- package/build/dex/inception/utils.js +0 -37
- package/build/dex/inception/utils.js.map +0 -1
- package/build/dex/platypus/asset.d.ts +0 -14
- package/build/dex/platypus/asset.js +0 -97
- package/build/dex/platypus/asset.js.map +0 -1
- package/build/dex/platypus/config.d.ts +0 -11
- package/build/dex/platypus/config.js +0 -69
- package/build/dex/platypus/config.js.map +0 -1
- package/build/dex/platypus/platypus.d.ts +0 -63
- package/build/dex/platypus/platypus.js +0 -473
- package/build/dex/platypus/platypus.js.map +0 -1
- package/build/dex/platypus/pool-avax.d.ts +0 -8
- package/build/dex/platypus/pool-avax.js +0 -54
- package/build/dex/platypus/pool-avax.js.map +0 -1
- package/build/dex/platypus/pool-base.d.ts +0 -19
- package/build/dex/platypus/pool-base.js +0 -86
- package/build/dex/platypus/pool-base.js.map +0 -1
- package/build/dex/platypus/pool-pure.d.ts +0 -8
- package/build/dex/platypus/pool-pure.js +0 -37
- package/build/dex/platypus/pool-pure.js.map +0 -1
- package/build/dex/platypus/pool-subscriber.d.ts +0 -14
- package/build/dex/platypus/pool-subscriber.js +0 -167
- package/build/dex/platypus/pool-subscriber.js.map +0 -1
- package/build/dex/platypus/pool.d.ts +0 -8
- package/build/dex/platypus/pool.js +0 -58
- package/build/dex/platypus/pool.js.map +0 -1
- package/build/dex/platypus/types.d.ts +0 -92
- package/build/dex/platypus/types.js +0 -10
- package/build/dex/platypus/types.js.map +0 -1
- package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
- package/build/dex/quickswap/spiritswap-v3.js +0 -19
- package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
- package/build/dex/smardex/config.d.ts +0 -4
- package/build/dex/smardex/config.js +0 -64
- package/build/dex/smardex/config.js.map +0 -1
- package/build/dex/smardex/constants.d.ts +0 -18
- package/build/dex/smardex/constants.js +0 -33
- package/build/dex/smardex/constants.js.map +0 -1
- package/build/dex/smardex/sdk/constants.d.ts +0 -6
- package/build/dex/smardex/sdk/constants.js +0 -13
- package/build/dex/smardex/sdk/constants.js.map +0 -1
- package/build/dex/smardex/sdk/core.d.ts +0 -113
- package/build/dex/smardex/sdk/core.js +0 -499
- package/build/dex/smardex/sdk/core.js.map +0 -1
- package/build/dex/smardex/sdk/errors.d.ts +0 -15
- package/build/dex/smardex/sdk/errors.js +0 -22
- package/build/dex/smardex/sdk/errors.js.map +0 -1
- package/build/dex/smardex/sdk/types.d.ts +0 -62
- package/build/dex/smardex/sdk/types.js +0 -3
- package/build/dex/smardex/sdk/types.js.map +0 -1
- package/build/dex/smardex/sdk/utils.d.ts +0 -44
- package/build/dex/smardex/sdk/utils.js +0 -133
- package/build/dex/smardex/sdk/utils.js.map +0 -1
- package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
- package/build/dex/smardex/smardex-event-pool.js +0 -119
- package/build/dex/smardex/smardex-event-pool.js.map +0 -1
- package/build/dex/smardex/smardex.d.ts +0 -65
- package/build/dex/smardex/smardex.js +0 -519
- package/build/dex/smardex/smardex.js.map +0 -1
- package/build/dex/smardex/types.d.ts +0 -55
- package/build/dex/smardex/types.js +0 -3
- package/build/dex/smardex/types.js.map +0 -1
- package/build/dex/solidly/forks-override/cone.d.ts +0 -22
- package/build/dex/solidly/forks-override/cone.js +0 -53
- package/build/dex/solidly/forks-override/cone.js.map +0 -1
- package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
- package/build/dex/solidly/forks-override/solisnek.js +0 -15
- package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
- package/build/dex/swaap-v1/config.d.ts +0 -17
- package/build/dex/swaap-v1/config.js +0 -56
- package/build/dex/swaap-v1/config.js.map +0 -1
- package/build/dex/swaap-v1/constants.d.ts +0 -6
- package/build/dex/swaap-v1/constants.js +0 -17
- package/build/dex/swaap-v1/constants.js.map +0 -1
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
- package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
- package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
- package/build/dex/swaap-v1/libraries/Const.js +0 -26
- package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
- package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
- package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
- package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
- package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
- package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
- package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
- package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
- package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
- package/build/dex/swaap-v1/libraries/Num.js +0 -167
- package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
- package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
- package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
- package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
- package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
- package/build/dex/swaap-v1/libraries/Struct.js +0 -3
- package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
- package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
- package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
- package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
- package/build/dex/swaap-v1/swaap-v1.d.ts +0 -62
- package/build/dex/swaap-v1/swaap-v1.js +0 -379
- package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
- package/build/dex/swaap-v1/types.d.ts +0 -106
- package/build/dex/swaap-v1/types.js +0 -9
- package/build/dex/swaap-v1/types.js.map +0 -1
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -16
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-eth-steth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-steth-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-eth-usdc.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-eth.json +0 -9
- package/build/executor/fixtures/executor01/exchange-params/price-route-simpleSwap-univ3-usdc-usdt.json +0 -9
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -12
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-eth-usdc.json +0 -7
- package/build/executor/fixtures/executor01/maybe-weth-calldata/price-route-simpleSwap-univ3-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-curvev1-eth-usdc-gusd.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-balancerv1-sushiv3-wbtc-eth-sushi.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-eth-usdc-gusd.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-curvev1-gusd-usdc-eth.json +0 -78
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-dai-usdc-eth.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-eth-usdc-dai.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdc-eth-wbtc.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-multiswap-sushiv3-usdt-usdc-dai.json +0 -81
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-eth-usdc.json +0 -64
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-eth.json +0 -85
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-balancerv1-usdc-wbtc.json +0 -64
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-eth-steth.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-steth-eth.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-curvev1-usdc-usdt.json +0 -52
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-eth-usdc.json +0 -55
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-eth.json +0 -55
- package/build/executor/fixtures/executor01/routes/price-route-simpleSwap-univ3-usdc-usdt.json +0 -55
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -37
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -51
- package/build/executor/fixtures/executor02/exchange-params/price-route-multiswap-univ3-usdt-dai-eth.json +0 -58
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -23
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -9
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -16
- package/build/executor/fixtures/executor02/exchange-params/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -23
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -12
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-multiswap-univ3-usdt-dai-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -7
- package/build/executor/fixtures/executor02/maybe-weth-calldata/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -7
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-balancerv1-sushiv3-univ3-bal-eth-sushi.json +0 -130
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-maverickv1-sushiv3-univ3-eth-usdc-mav.json +0 -136
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-sushi-eth-wbtc.json +0 -100
- package/build/executor/fixtures/executor02/routes/price-route-multiSwap-univ3-sushiv3-wbtc-eth-sushi.json +0 -100
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-curvev1-univ3-dai-usdc-eth.json +0 -166
- package/build/executor/fixtures/executor02/routes/price-route-multiswap-univ3-usdt-dai-eth.json +0 -190
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-eth-usdc.json +0 -114
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-balancerv1-usdc-eth.json +0 -114
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-eth-sushi.json +0 -55
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-sushiv3-univ3-sushi-eth.json +0 -73
- package/build/executor/fixtures/executor02/routes/price-route-simpleSwap-univ3-curvev1-usdt-dai.json +0 -82
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var _a;
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.LogExpMath = void 0;
|
|
5
|
-
const bigint_constants_1 = require("../../../bigint-constants");
|
|
6
|
-
const _require = (b, message) => {
|
|
7
|
-
if (!b)
|
|
8
|
-
throw new Error(message);
|
|
9
|
-
};
|
|
10
|
-
/* solhint-disable */
|
|
11
|
-
/**
|
|
12
|
-
* @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).
|
|
13
|
-
*
|
|
14
|
-
* Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural
|
|
15
|
-
* exponentiation and logarithm (where the base is Euler's number).
|
|
16
|
-
*
|
|
17
|
-
* @author Fernando Martinelli - @fernandomartinelli
|
|
18
|
-
* @author Sergio Yuhjtman - @sergioyuhjtman
|
|
19
|
-
* @author Daniel Fernandez - @dmf7z
|
|
20
|
-
*/
|
|
21
|
-
class LogExpMath {
|
|
22
|
-
/**
|
|
23
|
-
* @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.
|
|
24
|
-
*
|
|
25
|
-
* Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.
|
|
26
|
-
*/
|
|
27
|
-
static pow(x, y) {
|
|
28
|
-
if (y == 0n) {
|
|
29
|
-
// We solve the 0^0 indetermination by making it equal one.
|
|
30
|
-
return this.ONE_18;
|
|
31
|
-
}
|
|
32
|
-
if (x == 0n) {
|
|
33
|
-
return 0n;
|
|
34
|
-
}
|
|
35
|
-
// Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to
|
|
36
|
-
// arrive at that result. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means
|
|
37
|
-
// x^y = exp(y * ln(x)).
|
|
38
|
-
// The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.
|
|
39
|
-
_require(x < 2n ** 255n, 'Err.X_OUT_OF_BOUNDS');
|
|
40
|
-
const x_int256 = x;
|
|
41
|
-
// We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In
|
|
42
|
-
// both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.
|
|
43
|
-
// This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.
|
|
44
|
-
_require(y < this.MILD_EXPONENT_BOUND, 'Err.Y_OUT_OF_BOUNDS');
|
|
45
|
-
const y_int256 = y;
|
|
46
|
-
let logx_times_y;
|
|
47
|
-
if (this.LN_36_LOWER_BOUND < x_int256 &&
|
|
48
|
-
x_int256 < this.LN_36_UPPER_BOUND) {
|
|
49
|
-
const ln_36_x = this._ln_36(x_int256);
|
|
50
|
-
// ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just
|
|
51
|
-
// bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal
|
|
52
|
-
// multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the
|
|
53
|
-
// (downscaled) last 18 decimals.
|
|
54
|
-
logx_times_y =
|
|
55
|
-
(ln_36_x / this.ONE_18) * y_int256 +
|
|
56
|
-
((ln_36_x % this.ONE_18) * y_int256) / this.ONE_18;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
logx_times_y = this._ln(x_int256) * y_int256;
|
|
60
|
-
}
|
|
61
|
-
logx_times_y /= this.ONE_18;
|
|
62
|
-
// Finally, we compute exp(y * ln(x)) to arrive at x^y
|
|
63
|
-
_require(this.MIN_NATURAL_EXPONENT <= logx_times_y &&
|
|
64
|
-
logx_times_y <= this.MAX_NATURAL_EXPONENT, 'Err.PRODUCT_OUT_OF_BOUNDS');
|
|
65
|
-
return this.exp(logx_times_y);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.
|
|
69
|
-
*
|
|
70
|
-
* Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.
|
|
71
|
-
*/
|
|
72
|
-
static exp(x) {
|
|
73
|
-
_require(x >= this.MIN_NATURAL_EXPONENT && x <= this.MAX_NATURAL_EXPONENT, 'Err.INVALID_EXPONENT');
|
|
74
|
-
if (x < 0) {
|
|
75
|
-
// We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it
|
|
76
|
-
// fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).
|
|
77
|
-
// Fixed point division requires multiplying by ONE_18.
|
|
78
|
-
return (this.ONE_18 * this.ONE_18) / this.exp(-x);
|
|
79
|
-
}
|
|
80
|
-
// First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,
|
|
81
|
-
// where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7
|
|
82
|
-
// because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the
|
|
83
|
-
// decomposition.
|
|
84
|
-
// At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this
|
|
85
|
-
// decomposition, which will be lower than the smallest x_n.
|
|
86
|
-
// exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.
|
|
87
|
-
// We mutate x by subtracting x_n, making it the remainder of the decomposition.
|
|
88
|
-
// The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause
|
|
89
|
-
// intermediate overflows. Instead we store them as plain integers, with 0 decimals.
|
|
90
|
-
// Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the
|
|
91
|
-
// decomposition.
|
|
92
|
-
// For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct
|
|
93
|
-
// it and compute the accumulated product.
|
|
94
|
-
let firstAN;
|
|
95
|
-
if (x >= this.x0) {
|
|
96
|
-
x -= this.x0;
|
|
97
|
-
firstAN = this.a0;
|
|
98
|
-
}
|
|
99
|
-
else if (x >= this.x1) {
|
|
100
|
-
x -= this.x1;
|
|
101
|
-
firstAN = this.a1;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
firstAN = 1n; // One with no decimal places
|
|
105
|
-
}
|
|
106
|
-
// We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the
|
|
107
|
-
// smaller terms.
|
|
108
|
-
x *= 100n;
|
|
109
|
-
// `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point
|
|
110
|
-
// one. Recall that fixed point multiplication requires dividing by ONE_20.
|
|
111
|
-
let product = this.ONE_20;
|
|
112
|
-
if (x >= this.x2) {
|
|
113
|
-
x -= this.x2;
|
|
114
|
-
product = (product * this.a2) / this.ONE_20;
|
|
115
|
-
}
|
|
116
|
-
if (x >= this.x3) {
|
|
117
|
-
x -= this.x3;
|
|
118
|
-
product = (product * this.a3) / this.ONE_20;
|
|
119
|
-
}
|
|
120
|
-
if (x >= this.x4) {
|
|
121
|
-
x -= this.x4;
|
|
122
|
-
product = (product * this.a4) / this.ONE_20;
|
|
123
|
-
}
|
|
124
|
-
if (x >= this.x5) {
|
|
125
|
-
x -= this.x5;
|
|
126
|
-
product = (product * this.a5) / this.ONE_20;
|
|
127
|
-
}
|
|
128
|
-
if (x >= this.x6) {
|
|
129
|
-
x -= this.x6;
|
|
130
|
-
product = (product * this.a6) / this.ONE_20;
|
|
131
|
-
}
|
|
132
|
-
if (x >= this.x7) {
|
|
133
|
-
x -= this.x7;
|
|
134
|
-
product = (product * this.a7) / this.ONE_20;
|
|
135
|
-
}
|
|
136
|
-
if (x >= this.x8) {
|
|
137
|
-
x -= this.x8;
|
|
138
|
-
product = (product * this.a8) / this.ONE_20;
|
|
139
|
-
}
|
|
140
|
-
if (x >= this.x9) {
|
|
141
|
-
x -= this.x9;
|
|
142
|
-
product = (product * this.a9) / this.ONE_20;
|
|
143
|
-
}
|
|
144
|
-
// x10 and x11 are unnecessary here since we have high enough precision already.
|
|
145
|
-
// Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series
|
|
146
|
-
// expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).
|
|
147
|
-
let seriesSum = this.ONE_20; // The initial one in the sum, with 20 decimal places.
|
|
148
|
-
let term; // Each term in the sum, where the nth term is (x^n / n!).
|
|
149
|
-
// The first term is simply x.
|
|
150
|
-
term = x;
|
|
151
|
-
seriesSum += term;
|
|
152
|
-
// Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,
|
|
153
|
-
// multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.
|
|
154
|
-
term = (term * x) / this.ONE_20 / 2n;
|
|
155
|
-
seriesSum += term;
|
|
156
|
-
term = (term * x) / this.ONE_20 / 3n;
|
|
157
|
-
seriesSum += term;
|
|
158
|
-
term = (term * x) / this.ONE_20 / 4n;
|
|
159
|
-
seriesSum += term;
|
|
160
|
-
term = (term * x) / this.ONE_20 / 5n;
|
|
161
|
-
seriesSum += term;
|
|
162
|
-
term = (term * x) / this.ONE_20 / 6n;
|
|
163
|
-
seriesSum += term;
|
|
164
|
-
term = (term * x) / this.ONE_20 / 7n;
|
|
165
|
-
seriesSum += term;
|
|
166
|
-
term = (term * x) / this.ONE_20 / 8n;
|
|
167
|
-
seriesSum += term;
|
|
168
|
-
term = (term * x) / this.ONE_20 / 9n;
|
|
169
|
-
seriesSum += term;
|
|
170
|
-
term = (term * x) / this.ONE_20 / 10n;
|
|
171
|
-
seriesSum += term;
|
|
172
|
-
term = (term * x) / this.ONE_20 / 11n;
|
|
173
|
-
seriesSum += term;
|
|
174
|
-
term = (term * x) / this.ONE_20 / 12n;
|
|
175
|
-
seriesSum += term;
|
|
176
|
-
// 12 Taylor terms are sufficient for 18 decimal precision.
|
|
177
|
-
// We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor
|
|
178
|
-
// approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply
|
|
179
|
-
// all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),
|
|
180
|
-
// and then drop two digits to return an 18 decimal value.
|
|
181
|
-
return (((product * seriesSum) / this.ONE_20) * firstAN) / 100n;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* @dev Logarithm (log(arg, base), with signed 18 decimal fixed point base and argument.
|
|
185
|
-
*/
|
|
186
|
-
static log(arg, base) {
|
|
187
|
-
// This performs a simple base change: log(arg, base) = ln(arg) / ln(base).
|
|
188
|
-
// Both logBase and logArg are computed as 36 decimal fixed point numbers, either by using ln_36, or by
|
|
189
|
-
// upscaling.
|
|
190
|
-
let logBase;
|
|
191
|
-
if (this.LN_36_LOWER_BOUND < base && base < this.LN_36_UPPER_BOUND) {
|
|
192
|
-
logBase = this._ln_36(base);
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
logBase = this._ln(base) * this.ONE_18;
|
|
196
|
-
}
|
|
197
|
-
let logArg;
|
|
198
|
-
if (this.LN_36_LOWER_BOUND < arg && arg < this.LN_36_UPPER_BOUND) {
|
|
199
|
-
logArg = this._ln_36(arg);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
logArg = this._ln(arg) * this.ONE_18;
|
|
203
|
-
}
|
|
204
|
-
// When dividing, we multiply by ONE_18 to arrive at a result with 18 decimal places
|
|
205
|
-
return (logArg * this.ONE_18) / logBase;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
|
|
209
|
-
*/
|
|
210
|
-
static ln(a) {
|
|
211
|
-
// The real natural logarithm is not defined for negative numbers or zero.
|
|
212
|
-
_require(a > 0, 'Err.OUT_OF_BOUNDS');
|
|
213
|
-
if (this.LN_36_LOWER_BOUND < a && a < this.LN_36_UPPER_BOUND) {
|
|
214
|
-
return this._ln_36(a) / this.ONE_18;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
return this._ln(a);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.
|
|
222
|
-
*/
|
|
223
|
-
static _ln(a) {
|
|
224
|
-
if (a < this.ONE_18) {
|
|
225
|
-
// Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less
|
|
226
|
-
// than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.
|
|
227
|
-
// Fixed point division requires multiplying by ONE_18.
|
|
228
|
-
return -this._ln((this.ONE_18 * this.ONE_18) / a);
|
|
229
|
-
}
|
|
230
|
-
// First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which
|
|
231
|
-
// we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,
|
|
232
|
-
// ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot
|
|
233
|
-
// be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.
|
|
234
|
-
// At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this
|
|
235
|
-
// decomposition, which will be lower than the smallest a_n.
|
|
236
|
-
// ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.
|
|
237
|
-
// We mutate a by subtracting a_n, making it the remainder of the decomposition.
|
|
238
|
-
// For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point
|
|
239
|
-
// numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by
|
|
240
|
-
// ONE_18 to convert them to fixed point.
|
|
241
|
-
// For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide
|
|
242
|
-
// by it and compute the accumulated sum.
|
|
243
|
-
let sum = 0n;
|
|
244
|
-
if (a >= this.a0 * this.ONE_18) {
|
|
245
|
-
a /= this.a0; // Integer, not fixed point division
|
|
246
|
-
sum += this.x0;
|
|
247
|
-
}
|
|
248
|
-
if (a >= this.a1 * this.ONE_18) {
|
|
249
|
-
a /= this.a1; // Integer, not fixed point division
|
|
250
|
-
sum += this.x1;
|
|
251
|
-
}
|
|
252
|
-
// All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.
|
|
253
|
-
sum *= 100n;
|
|
254
|
-
a *= 100n;
|
|
255
|
-
// Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.
|
|
256
|
-
if (a >= this.a2) {
|
|
257
|
-
a = (a * this.ONE_20) / this.a2;
|
|
258
|
-
sum += this.x2;
|
|
259
|
-
}
|
|
260
|
-
if (a >= this.a3) {
|
|
261
|
-
a = (a * this.ONE_20) / this.a3;
|
|
262
|
-
sum += this.x3;
|
|
263
|
-
}
|
|
264
|
-
if (a >= this.a4) {
|
|
265
|
-
a = (a * this.ONE_20) / this.a4;
|
|
266
|
-
sum += this.x4;
|
|
267
|
-
}
|
|
268
|
-
if (a >= this.a5) {
|
|
269
|
-
a = (a * this.ONE_20) / this.a5;
|
|
270
|
-
sum += this.x5;
|
|
271
|
-
}
|
|
272
|
-
if (a >= this.a6) {
|
|
273
|
-
a = (a * this.ONE_20) / this.a6;
|
|
274
|
-
sum += this.x6;
|
|
275
|
-
}
|
|
276
|
-
if (a >= this.a7) {
|
|
277
|
-
a = (a * this.ONE_20) / this.a7;
|
|
278
|
-
sum += this.x7;
|
|
279
|
-
}
|
|
280
|
-
if (a >= this.a8) {
|
|
281
|
-
a = (a * this.ONE_20) / this.a8;
|
|
282
|
-
sum += this.x8;
|
|
283
|
-
}
|
|
284
|
-
if (a >= this.a9) {
|
|
285
|
-
a = (a * this.ONE_20) / this.a9;
|
|
286
|
-
sum += this.x9;
|
|
287
|
-
}
|
|
288
|
-
if (a >= this.a10) {
|
|
289
|
-
a = (a * this.ONE_20) / this.a10;
|
|
290
|
-
sum += this.x10;
|
|
291
|
-
}
|
|
292
|
-
if (a >= this.a11) {
|
|
293
|
-
a = (a * this.ONE_20) / this.a11;
|
|
294
|
-
sum += this.x11;
|
|
295
|
-
}
|
|
296
|
-
// a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series
|
|
297
|
-
// that converges rapidly for values of `a` close to one - the same one used in ln_36.
|
|
298
|
-
// Let z = (a - 1) / (a + 1).
|
|
299
|
-
// ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
|
|
300
|
-
// Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires
|
|
301
|
-
// division by ONE_20.
|
|
302
|
-
const z = ((a - this.ONE_20) * this.ONE_20) / (a + this.ONE_20);
|
|
303
|
-
const z_squared = (z * z) / this.ONE_20;
|
|
304
|
-
// num is the numerator of the series: the z^(2 * n + 1) term
|
|
305
|
-
let num = z;
|
|
306
|
-
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
|
|
307
|
-
let seriesSum = num;
|
|
308
|
-
// In each step, the numerator is multiplied by z^2
|
|
309
|
-
num = (num * z_squared) / this.ONE_20;
|
|
310
|
-
seriesSum += num / 3n;
|
|
311
|
-
num = (num * z_squared) / this.ONE_20;
|
|
312
|
-
seriesSum += num / 5n;
|
|
313
|
-
num = (num * z_squared) / this.ONE_20;
|
|
314
|
-
seriesSum += num / 7n;
|
|
315
|
-
num = (num * z_squared) / this.ONE_20;
|
|
316
|
-
seriesSum += num / 9n;
|
|
317
|
-
num = (num * z_squared) / this.ONE_20;
|
|
318
|
-
seriesSum += num / 11n;
|
|
319
|
-
// 6 Taylor terms are sufficient for 36 decimal precision.
|
|
320
|
-
// Finally, we multiply by 2 (non fixed point) to compute ln(remainder)
|
|
321
|
-
seriesSum *= 2n;
|
|
322
|
-
// We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both
|
|
323
|
-
// with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal
|
|
324
|
-
// value.
|
|
325
|
-
return (sum + seriesSum) / 100n;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,
|
|
329
|
-
* for x close to one.
|
|
330
|
-
*
|
|
331
|
-
* Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.
|
|
332
|
-
*/
|
|
333
|
-
static _ln_36(x) {
|
|
334
|
-
// Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits
|
|
335
|
-
// worthwhile.
|
|
336
|
-
// First, we transform x to a 36 digit fixed point value.
|
|
337
|
-
x *= this.ONE_18;
|
|
338
|
-
// We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).
|
|
339
|
-
// ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))
|
|
340
|
-
// Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires
|
|
341
|
-
// division by ONE_36.
|
|
342
|
-
const z = ((x - this.ONE_36) * this.ONE_36) / (x + this.ONE_36);
|
|
343
|
-
const z_squared = (z * z) / this.ONE_36;
|
|
344
|
-
// num is the numerator of the series: the z^(2 * n + 1) term
|
|
345
|
-
let num = z;
|
|
346
|
-
// seriesSum holds the accumulated sum of each term in the series, starting with the initial z
|
|
347
|
-
let seriesSum = num;
|
|
348
|
-
// In each step, the numerator is multiplied by z^2
|
|
349
|
-
num = (num * z_squared) / this.ONE_36;
|
|
350
|
-
seriesSum += num / 3n;
|
|
351
|
-
num = (num * z_squared) / this.ONE_36;
|
|
352
|
-
seriesSum += num / 5n;
|
|
353
|
-
num = (num * z_squared) / this.ONE_36;
|
|
354
|
-
seriesSum += num / 7n;
|
|
355
|
-
num = (num * z_squared) / this.ONE_36;
|
|
356
|
-
seriesSum += num / 9n;
|
|
357
|
-
num = (num * z_squared) / this.ONE_36;
|
|
358
|
-
seriesSum += num / 11n;
|
|
359
|
-
num = (num * z_squared) / this.ONE_36;
|
|
360
|
-
seriesSum += num / 13n;
|
|
361
|
-
num = (num * z_squared) / this.ONE_36;
|
|
362
|
-
seriesSum += num / 15n;
|
|
363
|
-
// 8 Taylor terms are sufficient for 36 decimal precision.
|
|
364
|
-
// All that remains is multiplying by 2 (non fixed point).
|
|
365
|
-
return seriesSum * 2n;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
exports.LogExpMath = LogExpMath;
|
|
369
|
-
_a = LogExpMath;
|
|
370
|
-
// All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying
|
|
371
|
-
// two numbers, and multiply by ONE when dividing them.
|
|
372
|
-
// All arguments and return values are 18 decimal fixed point numbers.
|
|
373
|
-
LogExpMath.ONE_18 = bigint_constants_1.BI_POWS[18];
|
|
374
|
-
// Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the
|
|
375
|
-
// case of ln36, 36 decimals.
|
|
376
|
-
LogExpMath.ONE_20 = bigint_constants_1.BI_POWS[20];
|
|
377
|
-
LogExpMath.ONE_36 = bigint_constants_1.BI_POWS[36];
|
|
378
|
-
// The domain of natural exponentiation is bound by the word size and number of decimals used.
|
|
379
|
-
//
|
|
380
|
-
// Because internally the result will be stored using 20 decimals, the largest possible result is
|
|
381
|
-
// (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.
|
|
382
|
-
// The smallest possible result is 10^(-18), which makes largest negative argument
|
|
383
|
-
// ln(10^(-18)) = -41.446531673892822312.
|
|
384
|
-
// We use 130.0 and -41.0 to have some safety margin.
|
|
385
|
-
LogExpMath.MAX_NATURAL_EXPONENT = 130n * bigint_constants_1.BI_POWS[18];
|
|
386
|
-
LogExpMath.MIN_NATURAL_EXPONENT = -41n * bigint_constants_1.BI_POWS[18];
|
|
387
|
-
// Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point
|
|
388
|
-
// 256 bit integer.
|
|
389
|
-
LogExpMath.LN_36_LOWER_BOUND = _a.ONE_18 - bigint_constants_1.BI_POWS[17];
|
|
390
|
-
LogExpMath.LN_36_UPPER_BOUND = _a.ONE_18 + bigint_constants_1.BI_POWS[17];
|
|
391
|
-
LogExpMath.MILD_EXPONENT_BOUND = 2n ** 254n / _a.ONE_20;
|
|
392
|
-
// 18 decimalants
|
|
393
|
-
LogExpMath.x0 = 128000000000000000000n; // 2ˆ7
|
|
394
|
-
LogExpMath.a0 = 38877084059945950922200000000000000000000000000000000000n; // eˆ(x0) (no decimals)
|
|
395
|
-
LogExpMath.x1 = 64000000000000000000n; // 2ˆ6
|
|
396
|
-
LogExpMath.a1 = 6235149080811616882910000000n; // eˆ(x1) (no decimals)
|
|
397
|
-
// 20 decimalants
|
|
398
|
-
LogExpMath.x2 = 3200000000000000000000n; // 2ˆ5
|
|
399
|
-
LogExpMath.a2 = 7896296018268069516100000000000000n; // eˆ(x2)
|
|
400
|
-
LogExpMath.x3 = 1600000000000000000000n; // 2ˆ4
|
|
401
|
-
LogExpMath.a3 = 888611052050787263676000000n; // eˆ(x3)
|
|
402
|
-
LogExpMath.x4 = 800000000000000000000n; // 2ˆ3
|
|
403
|
-
LogExpMath.a4 = 298095798704172827474000n; // eˆ(x4)
|
|
404
|
-
LogExpMath.x5 = 400000000000000000000n; // 2ˆ2
|
|
405
|
-
LogExpMath.a5 = 5459815003314423907810n; // eˆ(x5)
|
|
406
|
-
LogExpMath.x6 = 200000000000000000000n; // 2ˆ1
|
|
407
|
-
LogExpMath.a6 = 738905609893065022723n; // eˆ(x6)
|
|
408
|
-
LogExpMath.x7 = 100000000000000000000n; // 2ˆ0
|
|
409
|
-
LogExpMath.a7 = 271828182845904523536n; // eˆ(x7)
|
|
410
|
-
LogExpMath.x8 = 50000000000000000000n; // 2ˆ-1
|
|
411
|
-
LogExpMath.a8 = 164872127070012814685n; // eˆ(x8)
|
|
412
|
-
LogExpMath.x9 = 25000000000000000000n; // 2ˆ-2
|
|
413
|
-
LogExpMath.a9 = 128402541668774148407n; // eˆ(x9)
|
|
414
|
-
LogExpMath.x10 = 12500000000000000000n; // 2ˆ-3
|
|
415
|
-
LogExpMath.a10 = 113314845306682631683n; // eˆ(x10)
|
|
416
|
-
LogExpMath.x11 = 6250000000000000000n; // 2ˆ-4
|
|
417
|
-
LogExpMath.a11 = 106449445891785942956n; // eˆ(x11)
|
|
418
|
-
//# sourceMappingURL=LogExpMath.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LogExpMath.js","sourceRoot":"","sources":["../../../../src/dex/swaap-v1/libraries/LogExpMath.ts"],"names":[],"mappings":";;;;AAAA,gEAAgE;AAEhE,MAAM,QAAQ,GAAG,CAAC,CAAU,EAAE,OAAe,EAAE,EAAE;IAC/C,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,qBAAqB;AAErB;;;;;;;;;GASG;AACH,MAAa,UAAU;IAyDrB;;;;OAIG;IACH,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,CAAS;QAC7B,IAAI,CAAC,IAAI,EAAE,EAAE;YACX,2DAA2D;YAC3D,OAAO,IAAI,CAAC,MAAM,CAAC;SACpB;QAED,IAAI,CAAC,IAAI,EAAE,EAAE;YACX,OAAO,EAAE,CAAC;SACX;QAED,2GAA2G;QAC3G,4FAA4F;QAC5F,wBAAwB;QAExB,oGAAoG;QACpG,QAAQ,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,qBAAqB,CAAC,CAAC;QAChD,MAAM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sBAAsB,CAAC,CAAC,SAAS;AACtC,cAAG,GAAG,qBAAqB,CAAC,CAAC,OAAO;AACpC,cAAG,GAAG,sBAAsB,CAAC,CAAC,UAAU;AACxC,cAAG,GAAG,oBAAoB,CAAC,CAAC,OAAO;AACnC,cAAG,GAAG,sBAAsB,CAAC,CAAC,UAAU"}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import * as Struct from './Struct';
|
|
2
|
-
import { ChainLinkData } from '../types';
|
|
3
|
-
export declare class MathMMM {
|
|
4
|
-
/**********************************************************************************************
|
|
5
|
-
// calcSpotPrice //
|
|
6
|
-
// sP = spotPrice //
|
|
7
|
-
// bI = tokenBalanceIn ( bI * w0 ) //
|
|
8
|
-
// bO = tokenBalanceOut sP = ------------------------ //
|
|
9
|
-
// wI = tokenWeightIn ( bO * wI ) * ( 1 - sF ) //
|
|
10
|
-
// wO = tokenWeightOut //
|
|
11
|
-
// sF = swapFee //
|
|
12
|
-
**********************************************************************************************/
|
|
13
|
-
static calcSpotPrice(tokenBalanceIn: bigint, tokenWeightIn: bigint, tokenBalanceOut: bigint, tokenWeightOut: bigint, swapFee: bigint): bigint;
|
|
14
|
-
/**********************************************************************************************
|
|
15
|
-
// calcOutGivenIn //
|
|
16
|
-
// aO = tokenAmountOut //
|
|
17
|
-
// bO = tokenBalanceOut //
|
|
18
|
-
// bI = tokenBalanceIn / / bI \ (wI / wO) \ //
|
|
19
|
-
// aI = tokenAmountIn aO = bO * | 1 - | -------------------------- | ^ | //
|
|
20
|
-
// wI = tokenWeightIn \ \ ( bI + ( aI * ( 1 - sF )) / / //
|
|
21
|
-
// wO = tokenWeightOut //
|
|
22
|
-
// sF = swapFee //
|
|
23
|
-
**********************************************************************************************/
|
|
24
|
-
static calcOutGivenIn(tokenBalanceIn: bigint, tokenWeightIn: bigint, tokenBalanceOut: bigint, tokenWeightOut: bigint, tokenAmountIn: bigint, swapFee: bigint): bigint;
|
|
25
|
-
/**********************************************************************************************
|
|
26
|
-
// calcInGivenOut //
|
|
27
|
-
// aI = tokenAmountIn //
|
|
28
|
-
// bO = tokenBalanceOut / / bO \ (wO / wI) \ //
|
|
29
|
-
// bI = tokenBalanceIn bI * | | ------------ | ^ - 1 | //
|
|
30
|
-
// aO = tokenAmountOut aI = \ \ ( bO - aO ) / / //
|
|
31
|
-
// wI = tokenWeightIn -------------------------------------------- //
|
|
32
|
-
// wO = tokenWeightOut ( 1 - sF ) //
|
|
33
|
-
// sF = swapFee //
|
|
34
|
-
**********************************************************************************************/
|
|
35
|
-
static calcInGivenOut(tokenBalanceIn: bigint, tokenWeightIn: bigint, tokenBalanceOut: bigint, tokenWeightOut: bigint, tokenAmountOut: bigint, swapFee: bigint): bigint;
|
|
36
|
-
/**
|
|
37
|
-
* @notice Computes the amount of tokenIn needed in order to receive a given amount of tokenOut
|
|
38
|
-
* @dev A spread is applied as soon as entering a "shortage of tokenOut" phase
|
|
39
|
-
* cf whitepaper: https://www.swaap.finance/whitepaper.pdf
|
|
40
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
41
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
42
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
43
|
-
* @param swapParameters Amount of token out and swap fee
|
|
44
|
-
* @param gbmParameters The GBM forecast parameters (Z, horizon)
|
|
45
|
-
* @param hpParameters The parameters for historical prices retrieval
|
|
46
|
-
* @return swapResult The swap result (amount in, spread and tax base in)
|
|
47
|
-
*/
|
|
48
|
-
static calcInGivenOutMMM(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, relativePrice: bigint, swapParameters: Struct.SwapParameters, gbmParameters: Struct.GBMParameters, hpParameters: Struct.HistoricalPricesParameters, historicalPricesIn: ChainLinkData, historicalPricesOut: ChainLinkData, currentTimestamp: bigint): Struct.SwapResult;
|
|
49
|
-
/**
|
|
50
|
-
* @notice Implements 'calcInGivenOutMMM' in the case of abundance of tokenOut
|
|
51
|
-
* @dev Two cases to consider:
|
|
52
|
-
* 1) amount of tokenIn won't drive the pool from abundance of tokenOut to shortage ==> 1 pricing (no spread)
|
|
53
|
-
* 2) amount of tokenIn will drive the pool from abundance of tokenOut to shortage ==> 2 pricing, one for each phase
|
|
54
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
55
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
56
|
-
* @param swapParameters The parameters of the swap
|
|
57
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
58
|
-
* @param adjustedTokenWeightOut The spread-augmented tokenOut's weight
|
|
59
|
-
* @return tokenAmountIn The total amount of tokenIn needed for the swap
|
|
60
|
-
* @return taxBaseIn The amount of tokenIn swapped when in shortage of tokenOut
|
|
61
|
-
*/
|
|
62
|
-
static _calcInGivenOutMMMMixed(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, swapParameters: Struct.SwapParameters, relativePrice: bigint, adjustedTokenWeightOut: bigint, balanceOutAtEquilibrium: bigint, currentTimestamp: bigint): [bigint, bigint];
|
|
63
|
-
/**
|
|
64
|
-
* @notice Implements calcOutGivenInMMM in the case of abundance of tokenOut
|
|
65
|
-
* @dev A spread is applied as soon as entering a "shortage of tokenOut" phase
|
|
66
|
-
* cf whitepaper: https://www.swaap.finance/whitepaper.pdf
|
|
67
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
68
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
69
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
70
|
-
* @param tokenAmountOut The amount of tokenOut that will be received
|
|
71
|
-
* @param baseFee The base fee
|
|
72
|
-
* @param fallbackSpread The default spread in case the it couldn't be calculated using oracle prices
|
|
73
|
-
* @return tokenAmountIn The amount of tokenIn needed for the swap
|
|
74
|
-
*/
|
|
75
|
-
static _calcInGivenOutMMMAbundance(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, tokenAmountOut: bigint, baseFee: bigint): bigint;
|
|
76
|
-
/**
|
|
77
|
-
* @notice Computes the net value of a given tokenIn amount in tokenOut terms
|
|
78
|
-
* @dev A spread is applied as soon as entering a "shortage of tokenOut" phase
|
|
79
|
-
* cf whitepaper: https://www.swaap.finance/whitepaper.pdf
|
|
80
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
81
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
82
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
83
|
-
* @param swapParameters Amount of token in and swap fee
|
|
84
|
-
* @param gbmParameters The GBM forecast parameters (Z, horizon)
|
|
85
|
-
* @param hpParameters The parameters for historical prices retrieval
|
|
86
|
-
* @return swapResult The swap result (amount out, spread and tax base in)
|
|
87
|
-
*/
|
|
88
|
-
static calcOutGivenInMMM(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, relativePrice: bigint, swapParameters: Struct.SwapParameters, gbmParameters: Struct.GBMParameters, hpParameters: Struct.HistoricalPricesParameters, historicalPricesIn: ChainLinkData, historicalPricesOut: ChainLinkData, currentTimestamp: bigint): Struct.SwapResult;
|
|
89
|
-
/**
|
|
90
|
-
* @notice Implements 'calcOutGivenInMMM' in the case of mixed regime of tokenOut (abundance then shortage)
|
|
91
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
92
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
93
|
-
* @param swapParameters The parameters of the swap
|
|
94
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
95
|
-
* @param adjustedTokenWeightOut The spread-augmented tokenOut's weight
|
|
96
|
-
* @param balanceInAtEquilibrium TokenIn balance at equilibrium
|
|
97
|
-
* @return tokenAmountOut The total amount of token out
|
|
98
|
-
* @return taxBaseIn The amount of tokenIn swapped when in shortage of tokenOut
|
|
99
|
-
*/
|
|
100
|
-
static _calcOutGivenInMMMMixed(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, swapParameters: Struct.SwapParameters, relativePrice: bigint, adjustedTokenWeightOut: bigint, balanceInAtEquilibrium: bigint, currentTimestamp: bigint): [bigint, bigint];
|
|
101
|
-
/**
|
|
102
|
-
* @notice Implements calcOutGivenInMMM in the case of abundance of tokenOut
|
|
103
|
-
* @dev A spread is applied as soon as entering a "shortage of tokenOut" phase
|
|
104
|
-
* cf whitepaper: https://www.swaap.finance/whitepaper.pdf
|
|
105
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
106
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
107
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
108
|
-
* @param tokenAmountIn The amount of tokenIn that will be swaped
|
|
109
|
-
* @param baseFee The base fee
|
|
110
|
-
* @param fallbackSpread The default spread in case the it couldn't be calculated using oracle prices
|
|
111
|
-
* @return tokenAmountOut The tokenAmountOut when the tokenOut is in abundance
|
|
112
|
-
*/
|
|
113
|
-
static _calcOutGivenInMMMAbundance(tokenGlobalIn: Struct.TokenGlobal, tokenGlobalOut: Struct.TokenGlobal, relativePrice: bigint, tokenAmountIn: bigint, baseFee: bigint, fallbackSpread: bigint, currentTimestamp: bigint): bigint;
|
|
114
|
-
/**
|
|
115
|
-
* @notice Computes the log spread factor
|
|
116
|
-
* @dev We define it as the log of the p-quantile of a GBM process (log-normal distribution),
|
|
117
|
-
* which is given by the following:
|
|
118
|
-
* mean * horizon + z * sqrt(2 * variance * horizon)
|
|
119
|
-
* where z = ierf(2p - 1), with ierf being the inverse error function.
|
|
120
|
-
* GBM: https://en.wikipedia.org/wiki/Geometric_Brownian_motion
|
|
121
|
-
* Log-normal distribution: https://en.wikipedia.org/wiki/Log-normal_distribution
|
|
122
|
-
* erf: https://en.wikipedia.org/wiki/Error_function
|
|
123
|
-
* @param mean The percentage drift
|
|
124
|
-
* @param variance The percentage volatility
|
|
125
|
-
* @param horizon The GBM forecast horizon parameter
|
|
126
|
-
* @param z The GBM forecast z parameter
|
|
127
|
-
* @return x The log spread factor
|
|
128
|
-
*/
|
|
129
|
-
static getLogSpreadFactor(mean: bigint, variance: bigint, horizon: bigint, z: bigint): bigint;
|
|
130
|
-
/**
|
|
131
|
-
* @notice Apply to the tokenWeight a 'spread' factor
|
|
132
|
-
* @dev The spread factor is defined as the maximum between:
|
|
133
|
-
a) the expected relative tokenOut increase in tokenIn terms
|
|
134
|
-
b) 1
|
|
135
|
-
* The function multiplies the tokenWeight by the spread factor if
|
|
136
|
-
* the token is in shortage, or divides it by the spread factor if it is in abundance
|
|
137
|
-
* @param shortage true when the token is in shortage, false if in abundance
|
|
138
|
-
* @param fallbackSpread The default spread in case the it couldn't be calculated using oracle prices
|
|
139
|
-
* @param tokenWeight The token's weight
|
|
140
|
-
* @param gbmEstimation The GBM's 2 first moments estimation
|
|
141
|
-
* @param gbmParameters The GBM forecast parameters (Z, horizon)
|
|
142
|
-
* @return adjustedWeight The adjusted weight based on spread
|
|
143
|
-
* @return spread The spread
|
|
144
|
-
*/
|
|
145
|
-
static getMMMWeight(shortage: boolean, fallbackSpread: bigint, tokenWeight: bigint, gbmEstimation: Struct.GBMEstimation, gbmParameters: Struct.GBMParameters): [adjustedWeight: bigint, spread: bigint];
|
|
146
|
-
/**
|
|
147
|
-
* @notice Computes the fee amount that will ensure we maintain the pool's value, according to oracle prices.
|
|
148
|
-
* @dev We apply this fee regime only if Out-In price increased in the same block as now.
|
|
149
|
-
* @param tokenGlobalIn The pool global information on tokenIn
|
|
150
|
-
* @param tokenAmountIn The swap desired amount for tokenIn
|
|
151
|
-
* @param tokenGlobalOut The pool global information on tokenOut
|
|
152
|
-
* @param tokenAmountOut The swap desired amount for tokenOut
|
|
153
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
154
|
-
* @param baseFee The base fee amount
|
|
155
|
-
* @param fallbackSpread The default spread in case the it couldn't be calculated using oracle prices
|
|
156
|
-
* @return alpha The potentially augmented fee amount
|
|
157
|
-
*/
|
|
158
|
-
/**
|
|
159
|
-
* @notice Computes the balance of token1 the pool must have in order to have token1/token2 at equilibrium
|
|
160
|
-
* while satisfying the pricing curve prod^k balance_k^w_k = K
|
|
161
|
-
* @dev We only rely on the following equations:
|
|
162
|
-
* a) priceTokenOutOutInTokenIn = balance_in / balance_out * w_out / w_in
|
|
163
|
-
* b) tokenBalanceOut = (K / prod_k!=in balance_k^w_k)^(1/w_out) = (localInvariant / balance_in^w_in)^(1/w_out)
|
|
164
|
-
* with localInvariant = balance_in^w_in * balance_out^w_out which can be computed with only In/Out
|
|
165
|
-
* @param tokenBalance1 The balance of token1 initially
|
|
166
|
-
* @param tokenWeight1 The weight of token1
|
|
167
|
-
* @param tokenBalance2 The balance of token2 initially
|
|
168
|
-
* @param tokenWeight2 The weight of token2
|
|
169
|
-
* @param relativePrice The price of tokenOut in tokenIn terms
|
|
170
|
-
* @return balance1AtEquilibrium The balance of token1 in order to have a token1/token2 at equilibrium
|
|
171
|
-
*/
|
|
172
|
-
static getTokenBalanceAtEquilibrium(tokenBalance1: bigint, tokenWeight1: bigint, tokenBalance2: bigint, tokenWeight2: bigint, relativePrice: bigint): bigint;
|
|
173
|
-
/**
|
|
174
|
-
* @notice Computes the fee needed to maintain the pool's value constant
|
|
175
|
-
* @dev We use oracle to evaluate pool's value
|
|
176
|
-
* @param tokenBalanceIn The balance of tokenIn initially
|
|
177
|
-
* @param tokenAmountIn The amount of tokenIn to be added
|
|
178
|
-
* @param tokenWeightIn The weight of tokenIn
|
|
179
|
-
* @param tokenBalanceOut The balance of tokenOut initially
|
|
180
|
-
* @param tokenAmountOut The amount of tokenOut to be removed from the pool
|
|
181
|
-
* @param tokenWeightOut The weight of tokenOut
|
|
182
|
-
* @return adaptiveFee The computed adaptive fee to be added to the base fees
|
|
183
|
-
*/
|
|
184
|
-
static calcAdaptiveFeeGivenInAndOut(tokenBalanceIn: bigint, tokenAmountIn: bigint, tokenWeightIn: bigint, tokenBalanceOut: bigint, tokenAmountOut: bigint, tokenWeightOut: bigint): bigint;
|
|
185
|
-
}
|