impermax-sdk 1.2.112 → 2.0.0
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/lib/abis/ImpermaxABI.d.ts +2 -2
- package/lib/abis/ImpermaxABI.js +3 -3
- package/lib/abis/contracts/ClaimAggregator.json +2015 -2015
- package/lib/abis/contracts/IAllowanceTransfer.json +3772 -0
- package/lib/abis/contracts/IBorrowable.json +13207 -13207
- package/lib/abis/contracts/IClaimable.json +406 -406
- package/lib/abis/contracts/ICollateral.json +9052 -9052
- package/lib/abis/contracts/IERC20.json +2376 -2376
- package/lib/abis/contracts/IERC721.json +3515 -0
- package/lib/abis/contracts/IFactory.json +3660 -3660
- package/lib/abis/contracts/IFarmingPool.json +3584 -3584
- package/lib/abis/contracts/ILendingVaultV1.json +8358 -8358
- package/lib/abis/contracts/IMerkleDistributor.json +1134 -1134
- package/lib/abis/contracts/IRouter02.json +7283 -7283
- package/lib/abis/contracts/ISimpleUniswapOracle.json +1469 -1469
- package/lib/abis/contracts/IStakedLPToken.json +7309 -7309
- package/lib/abis/contracts/IStakingRewards.json +1036 -1036
- package/lib/abis/contracts/ITokenizedUniswapV2Position.json +4167 -0
- package/lib/abis/contracts/ITokenizedUniswapV3Position.json +5539 -0
- package/lib/abis/contracts/IUniswapV2Factory.json +1690 -1690
- package/lib/abis/contracts/IUniswapV2Pair.json +6761 -6761
- package/lib/abis/contracts/IUniswapV3Pool.json +6606 -0
- package/lib/abis/contracts/ImpermaxChef.json +20945 -20945
- package/lib/abis/contracts/ImpermaxConfigManager.json +31595 -31595
- package/lib/abis/contracts/ImpermaxV3Borrowable.json +22131 -0
- package/lib/abis/contracts/ImpermaxV3Collateral.json +22988 -0
- package/lib/abis/contracts/ImpermaxV3Factory.json +17645 -0
- package/lib/abis/contracts/ImpermaxV3UniV2Router01.json +32488 -0
- package/lib/abis/contracts/ImpermaxV3UniV3Router01.json +37742 -0
- package/lib/abis/contracts/LendingVaultWatcher01.json +4076 -4076
- package/lib/abis/contracts/PoolTokenRouter01.json +9058 -0
- package/lib/config/amms.d.ts +102 -104
- package/lib/config/amms.js +433 -436
- package/lib/config/chainId.d.ts +2 -0
- package/lib/config/chainId.js +26 -0
- package/lib/config/contracts/claim-aggregators.d.ts +2 -2
- package/lib/config/contracts/claim-aggregators.js +26 -26
- package/lib/config/contracts/impermax-chef.d.ts +2 -2
- package/lib/config/contracts/impermax-chef.js +27 -27
- package/lib/config/contracts/impermax-config-manager.d.ts +2 -2
- package/lib/config/contracts/impermax-config-manager.js +26 -26
- package/lib/config/contracts/impermax-factories.d.ts +4 -4
- package/lib/config/contracts/impermax-factories.js +87 -87
- package/lib/config/contracts/imxes.d.ts +2 -2
- package/lib/config/contracts/imxes.js +26 -26
- package/lib/config/contracts/lending-vault-watcher.d.ts +2 -2
- package/lib/config/contracts/lending-vault-watcher.js +26 -26
- package/lib/config/contracts/merkle-distributors.d.ts +4 -4
- package/lib/config/contracts/merkle-distributors.js +70 -70
- package/lib/config/contracts/routers.d.ts +4 -3
- package/lib/config/contracts/routers.js +118 -94
- package/lib/config/contracts/simple-uniswap-oracles.d.ts +2 -2
- package/lib/config/contracts/simple-uniswap-oracles.js +49 -49
- package/lib/config/contracts/weths.d.ts +2 -2
- package/lib/config/contracts/weths.js +27 -27
- package/lib/config/debank-ids.d.ts +2 -2
- package/lib/config/debank-ids.js +26 -26
- package/lib/config/endpoints/merkle-distributors.d.ts +4 -4
- package/lib/config/endpoints/merkle-distributors.js +70 -70
- package/lib/config/eth.d.ts +3 -3
- package/lib/config/eth.js +48 -48
- package/lib/config/factories.d.ts +7 -7
- package/lib/config/factories.js +31 -30
- package/lib/config/farms.d.ts +109 -111
- package/lib/config/farms.js +207 -210
- package/lib/config/general.d.ts +5 -5
- package/lib/config/general.js +8 -8
- package/lib/config/subgraphs.d.ts +45 -45
- package/lib/config/subgraphs.js +187 -187
- package/lib/config/types.d.ts +85 -72
- package/lib/config/types.js +72 -58
- package/lib/index.d.ts +36 -35
- package/lib/index.js +159 -152
- package/lib/offchain/account/index.d.ts +9 -7
- package/lib/offchain/account/index.js +43 -39
- package/lib/offchain/account/lendingPool/borrowable.d.ts +14 -0
- package/lib/offchain/account/lendingPool/borrowable.js +73 -0
- package/lib/offchain/account/lendingPool/collateral.d.ts +12 -0
- package/lib/offchain/account/lendingPool/collateral.js +42 -0
- package/lib/offchain/account/lendingPool/index.d.ts +6 -5
- package/lib/offchain/account/lendingPool/index.js +14 -12
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.d.ts +14 -17
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +45 -71
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.d.ts +11 -13
- package/lib/offchain/account/lendingPool/offchainAccountCollateral.js +31 -43
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.d.ts +28 -21
- package/lib/offchain/account/lendingPool/offchainAccountLendingPool.js +69 -68
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.d.ts +25 -0
- package/lib/offchain/account/lendingPool/offchainLeveragedPosition.js +116 -0
- package/lib/offchain/account/lendingVault.d.ts +11 -0
- package/lib/offchain/account/lendingVault.js +38 -0
- package/lib/offchain/account/offchainAccount.d.ts +25 -25
- package/lib/offchain/account/offchainAccount.js +129 -129
- package/lib/offchain/account/offchainAccountLendingVault.d.ts +16 -16
- package/lib/offchain/account/offchainAccountLendingVault.js +64 -64
- package/lib/offchain/account/offchainAccountPoolToken.d.ts +7 -7
- package/lib/offchain/account/offchainAccountPoolToken.js +24 -24
- package/lib/offchain/account/offchainMultichainAccount.d.ts +34 -0
- package/lib/offchain/account/offchainMultichainAccount.js +66 -0
- package/lib/offchain/account/poolToken.d.ts +6 -0
- package/lib/offchain/account/poolToken.js +21 -0
- package/lib/offchain/account/vault/index.d.ts +3 -0
- package/lib/offchain/account/vault/index.js +7 -0
- package/lib/offchain/account/vault/offchainAccountVault.d.ts +16 -0
- package/lib/offchain/account/vault/offchainAccountVault.js +64 -0
- package/lib/offchain/configManager/index.d.ts +5 -5
- package/lib/offchain/configManager/index.js +12 -12
- package/lib/offchain/configManager/offchainConfigManager.d.ts +25 -25
- package/lib/offchain/configManager/offchainConfigManager.js +76 -76
- package/lib/offchain/configManager/offchainConfigManagerInitializer.d.ts +6 -6
- package/lib/offchain/configManager/offchainConfigManagerInitializer.js +53 -53
- package/lib/offchain/configManager/offchainPairConfig.d.ts +40 -40
- package/lib/offchain/configManager/offchainPairConfig.js +86 -86
- package/lib/offchain/configManager/offchainProposal.d.ts +17 -17
- package/lib/offchain/configManager/offchainProposal.js +53 -53
- package/lib/offchain/index.d.ts +15 -14
- package/lib/offchain/index.js +55 -53
- package/lib/offchain/initializer.d.ts +32 -0
- package/lib/offchain/initializer.js +627 -0
- package/lib/offchain/lendingPool/borrowable.d.ts +55 -0
- package/lib/offchain/lendingPool/borrowable.js +351 -0
- package/lib/offchain/lendingPool/collateral.d.ts +17 -0
- package/lib/offchain/lendingPool/collateral.js +72 -0
- package/lib/offchain/lendingPool/index.d.ts +5 -5
- package/lib/offchain/lendingPool/index.js +12 -12
- package/lib/offchain/lendingPool/offchainBorrowable.d.ts +59 -59
- package/lib/offchain/lendingPool/offchainBorrowable.js +366 -366
- package/lib/offchain/lendingPool/offchainCollateral.d.ts +20 -19
- package/lib/offchain/lendingPool/offchainCollateral.js +81 -75
- package/lib/offchain/lendingPool/offchainLendingPool.d.ts +60 -47
- package/lib/offchain/lendingPool/offchainLendingPool.js +277 -230
- package/lib/offchain/lendingVault.d.ts +22 -0
- package/lib/offchain/lendingVault.js +115 -0
- package/lib/offchain/offchain.d.ts +106 -113
- package/lib/offchain/offchain.js +248 -251
- package/lib/offchain/offchainAPRHelper.d.ts +45 -45
- package/lib/offchain/offchainAPRHelper.js +239 -239
- package/lib/offchain/offchainEndpointManager.d.ts +25 -25
- package/lib/offchain/offchainEndpointManager.js +126 -126
- package/lib/offchain/offchainInitializer.d.ts +52 -52
- package/lib/offchain/offchainInitializer.js +792 -792
- package/lib/offchain/offchainLendingVault.d.ts +25 -25
- package/lib/offchain/offchainLendingVault.js +114 -114
- package/lib/offchain/offchainMultichain.d.ts +50 -0
- package/lib/offchain/offchainMultichain.js +75 -0
- package/lib/offchain/offchainPoolToken.d.ts +21 -21
- package/lib/offchain/offchainPoolToken.js +128 -128
- package/lib/offchain/offchainPriceHelper.d.ts +22 -22
- package/lib/offchain/offchainPriceHelper.js +364 -364
- package/lib/offchain/offchainSolidexHelper.d.ts +16 -16
- package/lib/offchain/offchainSolidexHelper.js +58 -58
- package/lib/offchain/offchainTypes.d.ts +212 -212
- package/lib/offchain/offchainTypes.js +3 -3
- package/lib/offchain/poolToken.d.ts +20 -0
- package/lib/offchain/poolToken.js +120 -0
- package/lib/offchain/priceHelper.d.ts +21 -0
- package/lib/offchain/priceHelper.js +195 -0
- package/lib/offchain/queries/apis/ponder/index.d.ts +14 -14
- package/lib/offchain/queries/apis/ponder/index.js +281 -281
- package/lib/offchain/queries/apis/thegraph/index.d.ts +19 -19
- package/lib/offchain/queries/apis/thegraph/index.js +355 -355
- package/lib/offchain/queries/index.d.ts +20 -20
- package/lib/offchain/queries/index.js +51 -51
- package/lib/offchain/queries/interfaces/query-builder.d.ts +19 -19
- package/lib/offchain/queries/interfaces/query-builder.js +2 -2
- package/lib/offchain/queries/interfaces/transformers.js +9 -9
- package/lib/offchain/query.d.ts +15 -0
- package/lib/offchain/query.js +323 -0
- package/lib/offchain/solidexHelper.d.ts +16 -0
- package/lib/offchain/solidexHelper.js +58 -0
- package/lib/offchain/types.d.ts +150 -0
- package/lib/offchain/types.js +3 -0
- package/lib/offchain/vault/index.d.ts +6 -0
- package/lib/offchain/vault/index.js +14 -0
- package/lib/offchain/vault/offchainHedgedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainHedgedVault.js +57 -0
- package/lib/offchain/vault/offchainLendingVault.d.ts +16 -0
- package/lib/offchain/vault/offchainLendingVault.js +73 -0
- package/lib/offchain/vault/offchainLeveragedVault.d.ts +9 -0
- package/lib/offchain/vault/offchainLeveragedVault.js +57 -0
- package/lib/offchain/vault/offchainVault.d.ts +34 -0
- package/lib/offchain/vault/offchainVault.js +130 -0
- package/lib/onchain/account/index.d.ts +6 -6
- package/lib/onchain/account/index.js +38 -38
- package/lib/onchain/account/interactions/index.d.ts +28 -0
- package/lib/onchain/account/interactions/index.js +158 -0
- package/lib/onchain/account/interactions/lendingPool/borrowable.d.ts +16 -0
- package/lib/onchain/account/interactions/lendingPool/borrowable.js +49 -0
- package/lib/onchain/account/interactions/lendingPool/collateral.d.ts +15 -0
- package/lib/onchain/account/interactions/lendingPool/collateral.js +33 -0
- package/lib/onchain/account/interactions/lendingPool/index.d.ts +41 -0
- package/lib/onchain/account/interactions/lendingPool/index.js +120 -0
- package/lib/onchain/account/interactions/lendingVault.d.ts +10 -0
- package/lib/onchain/account/interactions/lendingVault.js +12 -0
- package/lib/onchain/account/interactions/poolToken.d.ts +33 -0
- package/lib/onchain/account/interactions/poolToken.js +180 -0
- package/lib/onchain/account/lendingPool/borrowable.d.ts +29 -0
- package/lib/onchain/account/lendingPool/borrowable.js +135 -0
- package/lib/onchain/account/lendingPool/collateral.d.ts +15 -0
- package/lib/onchain/account/lendingPool/collateral.js +66 -0
- package/lib/onchain/account/lendingPool/index.d.ts +12 -5
- package/lib/onchain/account/lendingPool/index.js +49 -12
- package/lib/onchain/account/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.d.ts +7 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlp.js +12 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +13 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.d.ts +39 -34
- package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +131 -176
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +55 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.d.ts +10 -0
- package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +28 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.d.ts +10 -23
- package/lib/onchain/account/lendingPool/onchainAccountCollateral.js +26 -109
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.d.ts +25 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +99 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.d.ts +18 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.d.ts +42 -57
- package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +142 -352
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.d.ts +44 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +285 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.d.ts +27 -0
- package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV3.js +32 -0
- package/lib/onchain/account/lendingVault.d.ts +10 -0
- package/lib/onchain/account/lendingVault.js +35 -0
- package/lib/onchain/account/onchainAccount.d.ts +32 -32
- package/lib/onchain/account/onchainAccount.js +166 -167
- package/lib/onchain/account/onchainAccountLendingVault.d.ts +19 -19
- package/lib/onchain/account/onchainAccountLendingVault.js +48 -48
- package/lib/onchain/account/onchainAccountPoolToken.d.ts +30 -30
- package/lib/onchain/account/onchainAccountPoolToken.js +86 -86
- package/lib/onchain/account/poolToken.d.ts +24 -0
- package/lib/onchain/account/poolToken.js +84 -0
- package/lib/onchain/configManager/index.d.ts +5 -5
- package/lib/onchain/configManager/index.js +12 -12
- package/lib/onchain/configManager/onchainConfigManager.d.ts +12 -12
- package/lib/onchain/configManager/onchainConfigManager.js +38 -38
- package/lib/onchain/configManager/onchainPairConfig.d.ts +38 -38
- package/lib/onchain/configManager/onchainPairConfig.js +85 -85
- package/lib/onchain/configManager/onchainProposal.d.ts +17 -17
- package/lib/onchain/configManager/onchainProposal.js +55 -55
- package/lib/onchain/contractsHelper.d.ts +29 -0
- package/lib/onchain/contractsHelper.js +52 -0
- package/lib/onchain/impermaxFactory/index.d.ts +7 -5
- package/lib/onchain/impermaxFactory/index.js +39 -35
- package/lib/onchain/impermaxFactory/lendingPool/borrowable.d.ts +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/borrowable.js +153 -0
- package/lib/onchain/impermaxFactory/lendingPool/collateral.d.ts +17 -0
- package/lib/onchain/impermaxFactory/lendingPool/collateral.js +59 -0
- package/lib/onchain/impermaxFactory/lendingPool/index.d.ts +12 -5
- package/lib/onchain/impermaxFactory/lendingPool/index.js +50 -12
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.d.ts +22 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlp.js +19 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.d.ts +24 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +90 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +38 -34
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +137 -156
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.d.ts +9 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV2.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.d.ts +7 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowableV3.js +23 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.d.ts +8 -19
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateral.js +24 -61
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.d.ts +20 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +58 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.d.ts +13 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV3.js +36 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +43 -58
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +81 -367
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.d.ts +76 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV2.js +338 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.d.ts +42 -0
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPoolV3.js +39 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.d.ts +26 -16
- package/lib/onchain/impermaxFactory/onchainImpermaxFactory.js +42 -52
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV2.js +81 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.d.ts +16 -0
- package/lib/onchain/impermaxFactory/onchainImpermaxFactoryV3.js +88 -0
- package/lib/onchain/index.d.ts +10 -10
- package/lib/onchain/index.js +49 -49
- package/lib/onchain/interactions/index.d.ts +8 -8
- package/lib/onchain/interactions/index.js +41 -41
- package/lib/onchain/interactions/lendingPool/borrowable.d.ts +14 -0
- package/lib/onchain/interactions/lendingPool/borrowable.js +47 -0
- package/lib/onchain/interactions/lendingPool/collateral.d.ts +13 -0
- package/lib/onchain/interactions/lendingPool/collateral.js +31 -0
- package/lib/onchain/interactions/lendingPool/index.d.ts +12 -5
- package/lib/onchain/interactions/lendingPool/index.js +49 -12
- package/lib/onchain/interactions/lendingPool/nftlp/index.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/index.js +11 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.d.ts +7 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlp.js +12 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.d.ts +4 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.d.ts +17 -21
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowable.js +24 -56
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.d.ts +15 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV2.js +63 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.d.ts +9 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsBorrowableV3.js +14 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.d.ts +7 -19
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateral.js +11 -43
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.d.ts +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV2.js +48 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.d.ts +13 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsCollateralV3.js +20 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.d.ts +31 -46
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.js +53 -135
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.d.ts +42 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +114 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.d.ts +27 -0
- package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV3.js +32 -0
- package/lib/onchain/interactions/lendingVault.d.ts +8 -0
- package/lib/onchain/interactions/lendingVault.js +15 -0
- package/lib/onchain/interactions/onchainInteractions.d.ts +31 -31
- package/lib/onchain/interactions/onchainInteractions.js +136 -137
- package/lib/onchain/interactions/onchainInteractionsConfigManager.d.ts +17 -17
- package/lib/onchain/interactions/onchainInteractionsConfigManager.js +44 -44
- package/lib/onchain/interactions/onchainInteractionsLendingVault.d.ts +14 -14
- package/lib/onchain/interactions/onchainInteractionsLendingVault.js +21 -21
- package/lib/onchain/interactions/onchainInteractionsPoolToken.d.ts +35 -35
- package/lib/onchain/interactions/onchainInteractionsPoolToken.js +134 -186
- package/lib/onchain/interactions/poolToken.d.ts +31 -0
- package/lib/onchain/interactions/poolToken.js +181 -0
- package/lib/onchain/lendingVault.d.ts +17 -0
- package/lib/onchain/lendingVault.js +56 -0
- package/lib/onchain/onchain.d.ts +38 -35
- package/lib/onchain/onchain.js +78 -70
- package/lib/onchain/onchainContractsHelper.d.ts +42 -31
- package/lib/onchain/onchainContractsHelper.js +90 -56
- package/lib/onchain/onchainLendingVault.d.ts +22 -22
- package/lib/onchain/onchainLendingVault.js +69 -69
- package/lib/onchain/onchainPermitHelper.d.ts +21 -0
- package/lib/onchain/onchainPermitHelper.js +198 -0
- package/lib/onchain/onchainPoolToken.d.ts +35 -35
- package/lib/onchain/onchainPoolToken.js +129 -129
- package/lib/onchain/onchainTypes.d.ts +70 -64
- package/lib/onchain/onchainTypes.js +14 -14
- package/lib/onchain/poolToken.d.ts +32 -0
- package/lib/onchain/poolToken.js +121 -0
- package/lib/onchain/types.d.ts +45 -0
- package/lib/onchain/types.js +14 -0
- package/lib/utils/ether-utils.d.ts +5 -5
- package/lib/utils/ether-utils.js +26 -26
- package/lib/utils/index.d.ts +3 -3
- package/lib/utils/index.js +16 -16
- package/lib/utils/lliquidity-math.d.ts +30 -30
- package/lib/utils/lliquidity-math.js +139 -139
- package/lib/utils/price-from-reserves.d.ts +2 -0
- package/lib/utils/price-from-reserves.js +19 -0
- package/package.json +36 -36
package/lib/utils/ether-utils.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.address = exports.decimalToBalance = exports.formatToDecimals = exports.balanceToDecimal = void 0;
|
|
4
|
-
const utils_1 = require("ethers/lib/utils");
|
|
5
|
-
function balanceToDecimal(s) {
|
|
6
|
-
return (0, utils_1.formatUnits)(s);
|
|
7
|
-
}
|
|
8
|
-
exports.balanceToDecimal = balanceToDecimal;
|
|
9
|
-
function formatToDecimals(n, decimals = 2) {
|
|
10
|
-
if (n === null || n === undefined || isNaN(n))
|
|
11
|
-
return "-";
|
|
12
|
-
if (n == Infinity)
|
|
13
|
-
return "Infinity"; //return "∞";
|
|
14
|
-
return (Math.round(n * (Math.pow(10, decimals))) / (Math.pow(10, decimals))).toFixed(decimals);
|
|
15
|
-
}
|
|
16
|
-
exports.formatToDecimals = formatToDecimals;
|
|
17
|
-
function decimalToBalance(d, decimals = 18) {
|
|
18
|
-
const n = parseFloat(d.toString());
|
|
19
|
-
const s = formatToDecimals(Math.max(n, 0), decimals);
|
|
20
|
-
return (0, utils_1.parseUnits)(s, decimals);
|
|
21
|
-
}
|
|
22
|
-
exports.decimalToBalance = decimalToBalance;
|
|
23
|
-
function address(n) {
|
|
24
|
-
return `0x${n.toString(16).padStart(40, '0')}`;
|
|
25
|
-
}
|
|
26
|
-
exports.address = address;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.address = exports.decimalToBalance = exports.formatToDecimals = exports.balanceToDecimal = void 0;
|
|
4
|
+
const utils_1 = require("ethers/lib/utils");
|
|
5
|
+
function balanceToDecimal(s) {
|
|
6
|
+
return (0, utils_1.formatUnits)(s);
|
|
7
|
+
}
|
|
8
|
+
exports.balanceToDecimal = balanceToDecimal;
|
|
9
|
+
function formatToDecimals(n, decimals = 2) {
|
|
10
|
+
if (n === null || n === undefined || isNaN(n))
|
|
11
|
+
return "-";
|
|
12
|
+
if (n == Infinity)
|
|
13
|
+
return "Infinity"; //return "∞";
|
|
14
|
+
return (Math.round(n * (Math.pow(10, decimals))) / (Math.pow(10, decimals))).toFixed(decimals);
|
|
15
|
+
}
|
|
16
|
+
exports.formatToDecimals = formatToDecimals;
|
|
17
|
+
function decimalToBalance(d, decimals = 18) {
|
|
18
|
+
const n = parseFloat(d.toString());
|
|
19
|
+
const s = formatToDecimals(Math.max(n, 0), decimals);
|
|
20
|
+
return (0, utils_1.parseUnits)(s, decimals);
|
|
21
|
+
}
|
|
22
|
+
exports.decimalToBalance = decimalToBalance;
|
|
23
|
+
function address(n) {
|
|
24
|
+
return `0x${n.toString(16).padStart(40, '0')}`;
|
|
25
|
+
}
|
|
26
|
+
exports.address = address;
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare function toAPR(n: number): number;
|
|
2
|
-
export declare function impermanentLoss(priceSwing: number): number;
|
|
3
|
-
export declare function isValidNumber(n: number): boolean;
|
|
1
|
+
export declare function toAPR(n: number): number;
|
|
2
|
+
export declare function impermanentLoss(priceSwing: number): number;
|
|
3
|
+
export declare function isValidNumber(n: number): boolean;
|
package/lib/utils/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidNumber = exports.impermanentLoss = exports.toAPR = void 0;
|
|
4
|
-
function toAPR(n) {
|
|
5
|
-
const SECONDS_IN_YEAR = 365 * 24 * 3600;
|
|
6
|
-
return n * SECONDS_IN_YEAR;
|
|
7
|
-
}
|
|
8
|
-
exports.toAPR = toAPR;
|
|
9
|
-
function impermanentLoss(priceSwing) {
|
|
10
|
-
return Math.sqrt(priceSwing) / (priceSwing + 1) * 2;
|
|
11
|
-
}
|
|
12
|
-
exports.impermanentLoss = impermanentLoss;
|
|
13
|
-
function isValidNumber(n) {
|
|
14
|
-
return !(n === null || n === undefined || isNaN(n));
|
|
15
|
-
}
|
|
16
|
-
exports.isValidNumber = isValidNumber;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidNumber = exports.impermanentLoss = exports.toAPR = void 0;
|
|
4
|
+
function toAPR(n) {
|
|
5
|
+
const SECONDS_IN_YEAR = 365 * 24 * 3600;
|
|
6
|
+
return n * SECONDS_IN_YEAR;
|
|
7
|
+
}
|
|
8
|
+
exports.toAPR = toAPR;
|
|
9
|
+
function impermanentLoss(priceSwing) {
|
|
10
|
+
return Math.sqrt(priceSwing) / (priceSwing + 1) * 2;
|
|
11
|
+
}
|
|
12
|
+
exports.impermanentLoss = impermanentLoss;
|
|
13
|
+
function isValidNumber(n) {
|
|
14
|
+
return !(n === null || n === undefined || isNaN(n));
|
|
15
|
+
}
|
|
16
|
+
exports.isValidNumber = isValidNumber;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Calculate X/Y price
|
|
3
|
-
*/
|
|
4
|
-
export declare function uniswapV2_getPriceFromReserves(x: number, y: number, priceInverted?: boolean): number;
|
|
5
|
-
/**
|
|
6
|
-
* Find liquidation threshold given X/Y price decrease
|
|
7
|
-
* Returns a price ratio in the [0,1] range
|
|
8
|
-
* - 0 meaning it will never get liquidated
|
|
9
|
-
* - 1 meaning it is liquidatable
|
|
10
|
-
*/
|
|
11
|
-
export declare function uniswapV2_getLiquidatableXPriceDecrease(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
12
|
-
/**
|
|
13
|
-
* Calculate X/Y price
|
|
14
|
-
*/
|
|
15
|
-
export declare function solidlyStable_getPriceFromReserves(x: number, y: number, priceInverted?: boolean): number;
|
|
16
|
-
export declare function solidlyStable_k(x: number, y: number): number;
|
|
17
|
-
/**
|
|
18
|
-
* Calculate output from reserves y given input from x
|
|
19
|
-
*/
|
|
20
|
-
export declare function solidlyStable_yOut(xIn: number, x0: number, y0: number): number;
|
|
21
|
-
export declare function solidlyStable_getEquityValue(x: number, y: number, debtX: number, debtY: number): number;
|
|
22
|
-
/**
|
|
23
|
-
* Find xIn input amount that would bring the equity to negative
|
|
24
|
-
*/
|
|
25
|
-
export declare function solidlyStable_getXInMargin(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
26
|
-
/**
|
|
27
|
-
* Find liquidation threshold given X/Y price decrease
|
|
28
|
-
* Returns a price ratio in the [0,1] range
|
|
29
|
-
*/
|
|
30
|
-
export declare function solidlyStable_getLiquidatableXPriceDecrease(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
1
|
+
/**
|
|
2
|
+
* Calculate X/Y price
|
|
3
|
+
*/
|
|
4
|
+
export declare function uniswapV2_getPriceFromReserves(x: number, y: number, priceInverted?: boolean): number;
|
|
5
|
+
/**
|
|
6
|
+
* Find liquidation threshold given X/Y price decrease
|
|
7
|
+
* Returns a price ratio in the [0,1] range
|
|
8
|
+
* - 0 meaning it will never get liquidated
|
|
9
|
+
* - 1 meaning it is liquidatable
|
|
10
|
+
*/
|
|
11
|
+
export declare function uniswapV2_getLiquidatableXPriceDecrease(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
12
|
+
/**
|
|
13
|
+
* Calculate X/Y price
|
|
14
|
+
*/
|
|
15
|
+
export declare function solidlyStable_getPriceFromReserves(x: number, y: number, priceInverted?: boolean): number;
|
|
16
|
+
export declare function solidlyStable_k(x: number, y: number): number;
|
|
17
|
+
/**
|
|
18
|
+
* Calculate output from reserves y given input from x
|
|
19
|
+
*/
|
|
20
|
+
export declare function solidlyStable_yOut(xIn: number, x0: number, y0: number): number;
|
|
21
|
+
export declare function solidlyStable_getEquityValue(x: number, y: number, debtX: number, debtY: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Find xIn input amount that would bring the equity to negative
|
|
24
|
+
*/
|
|
25
|
+
export declare function solidlyStable_getXInMargin(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Find liquidation threshold given X/Y price decrease
|
|
28
|
+
* Returns a price ratio in the [0,1] range
|
|
29
|
+
*/
|
|
30
|
+
export declare function solidlyStable_getLiquidatableXPriceDecrease(x0: number, y0: number, debtX: number, debtY: number): number;
|
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.solidlyStable_getLiquidatableXPriceDecrease = exports.solidlyStable_getXInMargin = exports.solidlyStable_getEquityValue = exports.solidlyStable_yOut = exports.solidlyStable_k = exports.solidlyStable_getPriceFromReserves = exports.uniswapV2_getLiquidatableXPriceDecrease = exports.uniswapV2_getPriceFromReserves = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Calculate X/Y price
|
|
6
|
-
*/
|
|
7
|
-
function uniswapV2_getPriceFromReserves(x, y, priceInverted = false) {
|
|
8
|
-
const price = y / x;
|
|
9
|
-
return !priceInverted ? price : 1 / price;
|
|
10
|
-
}
|
|
11
|
-
exports.uniswapV2_getPriceFromReserves = uniswapV2_getPriceFromReserves;
|
|
12
|
-
/**
|
|
13
|
-
* Find liquidation threshold given X/Y price decrease
|
|
14
|
-
* Returns a price ratio in the [0,1] range
|
|
15
|
-
* - 0 meaning it will never get liquidated
|
|
16
|
-
* - 1 meaning it is liquidatable
|
|
17
|
-
*/
|
|
18
|
-
function uniswapV2_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
19
|
-
if (debtX == 0 && debtY == 0)
|
|
20
|
-
return 0;
|
|
21
|
-
if (x0 == 0 || y0 == 0)
|
|
22
|
-
return 1;
|
|
23
|
-
const k = x0 * y0;
|
|
24
|
-
const x = k / debtY * (1 + Math.sqrt(1 - debtY * debtX / k));
|
|
25
|
-
if (!x)
|
|
26
|
-
return 1;
|
|
27
|
-
if (x <= x0)
|
|
28
|
-
return 1;
|
|
29
|
-
if (x == Infinity)
|
|
30
|
-
return 0;
|
|
31
|
-
const y = k / x;
|
|
32
|
-
const price0 = uniswapV2_getPriceFromReserves(x0, y0);
|
|
33
|
-
const price = uniswapV2_getPriceFromReserves(x, y);
|
|
34
|
-
if (price >= price0)
|
|
35
|
-
return 1;
|
|
36
|
-
return price / price0;
|
|
37
|
-
}
|
|
38
|
-
exports.uniswapV2_getLiquidatableXPriceDecrease = uniswapV2_getLiquidatableXPriceDecrease;
|
|
39
|
-
/**
|
|
40
|
-
* Calculate X/Y price
|
|
41
|
-
*/
|
|
42
|
-
function solidlyStable_getPriceFromReserves(x, y, priceInverted = false) {
|
|
43
|
-
const N = 3 * Math.pow(x, 2) * y + Math.pow(y, 3);
|
|
44
|
-
const D = 3 * Math.pow(y, 2) * x + Math.pow(x, 3);
|
|
45
|
-
const price = N / D;
|
|
46
|
-
return !priceInverted ? price : 1 / price;
|
|
47
|
-
}
|
|
48
|
-
exports.solidlyStable_getPriceFromReserves = solidlyStable_getPriceFromReserves;
|
|
49
|
-
function solidlyStable_k(x, y) {
|
|
50
|
-
return Math.pow(x, 3) * y + Math.pow(y, 3) * x;
|
|
51
|
-
}
|
|
52
|
-
exports.solidlyStable_k = solidlyStable_k;
|
|
53
|
-
/**
|
|
54
|
-
* Calculate output from reserves y given input from x
|
|
55
|
-
*/
|
|
56
|
-
function solidlyStable_yOut(xIn, x0, y0) {
|
|
57
|
-
const k0 = solidlyStable_k(x0, y0);
|
|
58
|
-
const x = x0 + xIn;
|
|
59
|
-
let y = y0;
|
|
60
|
-
// search for new y
|
|
61
|
-
for (let i = 0; i < 16; i++) {
|
|
62
|
-
const yPrev = y;
|
|
63
|
-
const k = solidlyStable_k(x, y);
|
|
64
|
-
const d = 3 * x * Math.pow(y, 2) + Math.pow(x, 3);
|
|
65
|
-
if (k < k0) {
|
|
66
|
-
const dy = (k0 - k) / d;
|
|
67
|
-
y = y + dy;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
const dy = (k - k0) / d;
|
|
71
|
-
y = y - dy;
|
|
72
|
-
}
|
|
73
|
-
if (Math.abs((y - yPrev) / y) < 1e-10) {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return y0 - y;
|
|
78
|
-
}
|
|
79
|
-
exports.solidlyStable_yOut = solidlyStable_yOut;
|
|
80
|
-
function solidlyStable_getEquityValue(x, y, debtX, debtY) {
|
|
81
|
-
if ((x == 0 || y == 0) && (debtX > 0 || debtY > 0))
|
|
82
|
-
return -Infinity;
|
|
83
|
-
const price = solidlyStable_getPriceFromReserves(x, y);
|
|
84
|
-
const lpValue = x * price + y;
|
|
85
|
-
const debtValue = debtX * price + debtY;
|
|
86
|
-
return lpValue - debtValue;
|
|
87
|
-
}
|
|
88
|
-
exports.solidlyStable_getEquityValue = solidlyStable_getEquityValue;
|
|
89
|
-
/**
|
|
90
|
-
* Find xIn input amount that would bring the equity to negative
|
|
91
|
-
*/
|
|
92
|
-
function solidlyStable_getXInMargin(x0, y0, debtX, debtY) {
|
|
93
|
-
if (debtX == 0 && debtY == 0)
|
|
94
|
-
return Infinity;
|
|
95
|
-
if (x0 == 0 || y0 == 0)
|
|
96
|
-
return 0;
|
|
97
|
-
if (solidlyStable_getEquityValue(x0, y0, debtX, debtY) < 0)
|
|
98
|
-
return 0;
|
|
99
|
-
const STARTING_POINT = x0 * 1e9;
|
|
100
|
-
let xIn = STARTING_POINT;
|
|
101
|
-
let xInPrev = 0;
|
|
102
|
-
// binary search for xIn
|
|
103
|
-
for (let i = 0; i < 1000; i++) {
|
|
104
|
-
const x = x0 + xIn;
|
|
105
|
-
const y = y0 - solidlyStable_yOut(xIn, x0, y0);
|
|
106
|
-
const jump = Math.abs(xIn - xInPrev) / 2;
|
|
107
|
-
if (Math.abs(jump / x0) < 1e-10)
|
|
108
|
-
break;
|
|
109
|
-
xInPrev = xIn;
|
|
110
|
-
if (solidlyStable_getEquityValue(x, y, debtX, debtY) < 0)
|
|
111
|
-
xIn -= jump;
|
|
112
|
-
else {
|
|
113
|
-
if (xIn == STARTING_POINT)
|
|
114
|
-
return Infinity;
|
|
115
|
-
xIn += jump;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return xIn;
|
|
119
|
-
}
|
|
120
|
-
exports.solidlyStable_getXInMargin = solidlyStable_getXInMargin;
|
|
121
|
-
/**
|
|
122
|
-
* Find liquidation threshold given X/Y price decrease
|
|
123
|
-
* Returns a price ratio in the [0,1] range
|
|
124
|
-
*/
|
|
125
|
-
function solidlyStable_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
126
|
-
const xIn = solidlyStable_getXInMargin(x0, y0, debtX, debtY);
|
|
127
|
-
if (xIn == 0)
|
|
128
|
-
return 1;
|
|
129
|
-
if (xIn == Infinity)
|
|
130
|
-
return 0;
|
|
131
|
-
const x = x0 + xIn;
|
|
132
|
-
const y = y0 - solidlyStable_yOut(xIn, x0, y0);
|
|
133
|
-
const price0 = solidlyStable_getPriceFromReserves(x0, y0);
|
|
134
|
-
const price = solidlyStable_getPriceFromReserves(x, y);
|
|
135
|
-
if (price >= price0)
|
|
136
|
-
return 1;
|
|
137
|
-
return price / price0;
|
|
138
|
-
}
|
|
139
|
-
exports.solidlyStable_getLiquidatableXPriceDecrease = solidlyStable_getLiquidatableXPriceDecrease;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.solidlyStable_getLiquidatableXPriceDecrease = exports.solidlyStable_getXInMargin = exports.solidlyStable_getEquityValue = exports.solidlyStable_yOut = exports.solidlyStable_k = exports.solidlyStable_getPriceFromReserves = exports.uniswapV2_getLiquidatableXPriceDecrease = exports.uniswapV2_getPriceFromReserves = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate X/Y price
|
|
6
|
+
*/
|
|
7
|
+
function uniswapV2_getPriceFromReserves(x, y, priceInverted = false) {
|
|
8
|
+
const price = y / x;
|
|
9
|
+
return !priceInverted ? price : 1 / price;
|
|
10
|
+
}
|
|
11
|
+
exports.uniswapV2_getPriceFromReserves = uniswapV2_getPriceFromReserves;
|
|
12
|
+
/**
|
|
13
|
+
* Find liquidation threshold given X/Y price decrease
|
|
14
|
+
* Returns a price ratio in the [0,1] range
|
|
15
|
+
* - 0 meaning it will never get liquidated
|
|
16
|
+
* - 1 meaning it is liquidatable
|
|
17
|
+
*/
|
|
18
|
+
function uniswapV2_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
19
|
+
if (debtX == 0 && debtY == 0)
|
|
20
|
+
return 0;
|
|
21
|
+
if (x0 == 0 || y0 == 0)
|
|
22
|
+
return 1;
|
|
23
|
+
const k = x0 * y0;
|
|
24
|
+
const x = k / debtY * (1 + Math.sqrt(1 - debtY * debtX / k));
|
|
25
|
+
if (!x)
|
|
26
|
+
return 1;
|
|
27
|
+
if (x <= x0)
|
|
28
|
+
return 1;
|
|
29
|
+
if (x == Infinity)
|
|
30
|
+
return 0;
|
|
31
|
+
const y = k / x;
|
|
32
|
+
const price0 = uniswapV2_getPriceFromReserves(x0, y0);
|
|
33
|
+
const price = uniswapV2_getPriceFromReserves(x, y);
|
|
34
|
+
if (price >= price0)
|
|
35
|
+
return 1;
|
|
36
|
+
return price / price0;
|
|
37
|
+
}
|
|
38
|
+
exports.uniswapV2_getLiquidatableXPriceDecrease = uniswapV2_getLiquidatableXPriceDecrease;
|
|
39
|
+
/**
|
|
40
|
+
* Calculate X/Y price
|
|
41
|
+
*/
|
|
42
|
+
function solidlyStable_getPriceFromReserves(x, y, priceInverted = false) {
|
|
43
|
+
const N = 3 * Math.pow(x, 2) * y + Math.pow(y, 3);
|
|
44
|
+
const D = 3 * Math.pow(y, 2) * x + Math.pow(x, 3);
|
|
45
|
+
const price = N / D;
|
|
46
|
+
return !priceInverted ? price : 1 / price;
|
|
47
|
+
}
|
|
48
|
+
exports.solidlyStable_getPriceFromReserves = solidlyStable_getPriceFromReserves;
|
|
49
|
+
function solidlyStable_k(x, y) {
|
|
50
|
+
return Math.pow(x, 3) * y + Math.pow(y, 3) * x;
|
|
51
|
+
}
|
|
52
|
+
exports.solidlyStable_k = solidlyStable_k;
|
|
53
|
+
/**
|
|
54
|
+
* Calculate output from reserves y given input from x
|
|
55
|
+
*/
|
|
56
|
+
function solidlyStable_yOut(xIn, x0, y0) {
|
|
57
|
+
const k0 = solidlyStable_k(x0, y0);
|
|
58
|
+
const x = x0 + xIn;
|
|
59
|
+
let y = y0;
|
|
60
|
+
// search for new y
|
|
61
|
+
for (let i = 0; i < 16; i++) {
|
|
62
|
+
const yPrev = y;
|
|
63
|
+
const k = solidlyStable_k(x, y);
|
|
64
|
+
const d = 3 * x * Math.pow(y, 2) + Math.pow(x, 3);
|
|
65
|
+
if (k < k0) {
|
|
66
|
+
const dy = (k0 - k) / d;
|
|
67
|
+
y = y + dy;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const dy = (k - k0) / d;
|
|
71
|
+
y = y - dy;
|
|
72
|
+
}
|
|
73
|
+
if (Math.abs((y - yPrev) / y) < 1e-10) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return y0 - y;
|
|
78
|
+
}
|
|
79
|
+
exports.solidlyStable_yOut = solidlyStable_yOut;
|
|
80
|
+
function solidlyStable_getEquityValue(x, y, debtX, debtY) {
|
|
81
|
+
if ((x == 0 || y == 0) && (debtX > 0 || debtY > 0))
|
|
82
|
+
return -Infinity;
|
|
83
|
+
const price = solidlyStable_getPriceFromReserves(x, y);
|
|
84
|
+
const lpValue = x * price + y;
|
|
85
|
+
const debtValue = debtX * price + debtY;
|
|
86
|
+
return lpValue - debtValue;
|
|
87
|
+
}
|
|
88
|
+
exports.solidlyStable_getEquityValue = solidlyStable_getEquityValue;
|
|
89
|
+
/**
|
|
90
|
+
* Find xIn input amount that would bring the equity to negative
|
|
91
|
+
*/
|
|
92
|
+
function solidlyStable_getXInMargin(x0, y0, debtX, debtY) {
|
|
93
|
+
if (debtX == 0 && debtY == 0)
|
|
94
|
+
return Infinity;
|
|
95
|
+
if (x0 == 0 || y0 == 0)
|
|
96
|
+
return 0;
|
|
97
|
+
if (solidlyStable_getEquityValue(x0, y0, debtX, debtY) < 0)
|
|
98
|
+
return 0;
|
|
99
|
+
const STARTING_POINT = x0 * 1e9;
|
|
100
|
+
let xIn = STARTING_POINT;
|
|
101
|
+
let xInPrev = 0;
|
|
102
|
+
// binary search for xIn
|
|
103
|
+
for (let i = 0; i < 1000; i++) {
|
|
104
|
+
const x = x0 + xIn;
|
|
105
|
+
const y = y0 - solidlyStable_yOut(xIn, x0, y0);
|
|
106
|
+
const jump = Math.abs(xIn - xInPrev) / 2;
|
|
107
|
+
if (Math.abs(jump / x0) < 1e-10)
|
|
108
|
+
break;
|
|
109
|
+
xInPrev = xIn;
|
|
110
|
+
if (solidlyStable_getEquityValue(x, y, debtX, debtY) < 0)
|
|
111
|
+
xIn -= jump;
|
|
112
|
+
else {
|
|
113
|
+
if (xIn == STARTING_POINT)
|
|
114
|
+
return Infinity;
|
|
115
|
+
xIn += jump;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return xIn;
|
|
119
|
+
}
|
|
120
|
+
exports.solidlyStable_getXInMargin = solidlyStable_getXInMargin;
|
|
121
|
+
/**
|
|
122
|
+
* Find liquidation threshold given X/Y price decrease
|
|
123
|
+
* Returns a price ratio in the [0,1] range
|
|
124
|
+
*/
|
|
125
|
+
function solidlyStable_getLiquidatableXPriceDecrease(x0, y0, debtX, debtY) {
|
|
126
|
+
const xIn = solidlyStable_getXInMargin(x0, y0, debtX, debtY);
|
|
127
|
+
if (xIn == 0)
|
|
128
|
+
return 1;
|
|
129
|
+
if (xIn == Infinity)
|
|
130
|
+
return 0;
|
|
131
|
+
const x = x0 + xIn;
|
|
132
|
+
const y = y0 - solidlyStable_yOut(xIn, x0, y0);
|
|
133
|
+
const price0 = solidlyStable_getPriceFromReserves(x0, y0);
|
|
134
|
+
const price = solidlyStable_getPriceFromReserves(x, y);
|
|
135
|
+
if (price >= price0)
|
|
136
|
+
return 1;
|
|
137
|
+
return price / price0;
|
|
138
|
+
}
|
|
139
|
+
exports.solidlyStable_getLiquidatableXPriceDecrease = solidlyStable_getLiquidatableXPriceDecrease;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// return X/Y price
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getPriceFromReservesSolidlyStable = exports.getPriceFromReservesUniswapV2 = void 0;
|
|
5
|
+
/*
|
|
6
|
+
* X/Y price is given by dividing Y reserves by X reserves
|
|
7
|
+
*/
|
|
8
|
+
function getPriceFromReservesUniswapV2(x, y, priceInverted = true) {
|
|
9
|
+
const price = y / x;
|
|
10
|
+
return !priceInverted ? price : 1 / price;
|
|
11
|
+
}
|
|
12
|
+
exports.getPriceFromReservesUniswapV2 = getPriceFromReservesUniswapV2;
|
|
13
|
+
function getPriceFromReservesSolidlyStable(x, y, priceInverted = false) {
|
|
14
|
+
const N = 3 * Math.pow(x, 2) * y + Math.pow(y, 3);
|
|
15
|
+
const D = 3 * Math.pow(y, 2) * x + Math.pow(x, 3);
|
|
16
|
+
const price = N / D;
|
|
17
|
+
return !priceInverted ? price : 1 / price;
|
|
18
|
+
}
|
|
19
|
+
exports.getPriceFromReservesSolidlyStable = getPriceFromReservesSolidlyStable;
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "impermax-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./lib/index.js",
|
|
6
|
-
"module": "./lib/index.js",
|
|
7
|
-
"files": [
|
|
8
|
-
"lib/"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"test": "mocha --timeout 15000",
|
|
12
|
-
"tsc": "tsc -p tsconfig.json",
|
|
13
|
-
"prepublishOnly": "npm run tsc"
|
|
14
|
-
},
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"ts-loader": "^8.0.14",
|
|
19
|
-
"typescript": "^4.0.3",
|
|
20
|
-
"@truffle/hdwallet-provider": "^2.1.15"
|
|
21
|
-
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"apollo-cache-inmemory": "^1.6.6",
|
|
24
|
-
"apollo-client": "^2.6.10",
|
|
25
|
-
"apollo-link-http": "^1.5.17",
|
|
26
|
-
"chai": "^4.3.8",
|
|
27
|
-
"ethers": "^5.0.26",
|
|
28
|
-
"graphql": "^15.4.0",
|
|
29
|
-
"graphql-tag": "^2.11.0",
|
|
30
|
-
"mocha": "^10.2.0",
|
|
31
|
-
"web3": "^1.3.1"
|
|
32
|
-
},
|
|
33
|
-
"engines": {
|
|
34
|
-
"node": ">=18.14"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "impermax-sdk",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"module": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "mocha --timeout 15000",
|
|
12
|
+
"tsc": "tsc -p tsconfig.json",
|
|
13
|
+
"prepublishOnly": "npm run tsc"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"ts-loader": "^8.0.14",
|
|
19
|
+
"typescript": "^4.0.3",
|
|
20
|
+
"@truffle/hdwallet-provider": "^2.1.15"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"apollo-cache-inmemory": "^1.6.6",
|
|
24
|
+
"apollo-client": "^2.6.10",
|
|
25
|
+
"apollo-link-http": "^1.5.17",
|
|
26
|
+
"chai": "^4.3.8",
|
|
27
|
+
"ethers": "^5.0.26",
|
|
28
|
+
"graphql": "^15.4.0",
|
|
29
|
+
"graphql-tag": "^2.11.0",
|
|
30
|
+
"mocha": "^10.2.0",
|
|
31
|
+
"web3": "^1.3.1"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.14"
|
|
35
|
+
}
|
|
36
|
+
}
|