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
|
@@ -1,792 +1,792 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getLendingVaultsUserData = exports.initializeLendingVaultsUserData = exports.fetchLendingVaultsUserData = exports.getWhitelistState = exports.getWhitelistData = exports.initializeWhitelistData = exports.fetchWhitelist = exports.getLendingVaultData = exports.getLendingVaultsData = exports.initializeLendingVaultsData = exports.fetchLendingVaults = exports.getXimxData = exports.initializeXimxData = exports.getUserData = exports.initializeUserData = exports.fetchUserData = exports.getTvlData = exports.initializeTvlData = exports.getLendingPoolData = exports.getLendingPoolsData = exports.initializeLendingPoolsData = exports.fetchUniswapAPR = exports.fetchCurrentVolumeAndReserves = exports.fetchPastVolume = exports.fetchImpermaxChefRewardRates = exports.fetchLendingPoolsPast = exports.fetchLendingPools = exports.fetchBlockByTimestamp = exports.apolloFetcher = void 0;
|
|
16
|
-
const apollo_client_1 = __importDefault(require("apollo-client"));
|
|
17
|
-
const apollo_link_http_1 = require("apollo-link-http");
|
|
18
|
-
const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
|
|
19
|
-
const queries_1 = require("./queries");
|
|
20
|
-
const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
21
|
-
const subgraphs_1 = require("../config/subgraphs");
|
|
22
|
-
const types_1 = require("../config/types");
|
|
23
|
-
const amms_1 = require("../config/amms");
|
|
24
|
-
const
|
|
25
|
-
const impermax_factories_1 = require("../config/contracts/impermax-factories");
|
|
26
|
-
const SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
|
27
|
-
function apolloFetcher(subgraphUrl, query) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const client = new apollo_client_1.default({
|
|
30
|
-
link: new apollo_link_http_1.HttpLink({
|
|
31
|
-
uri: subgraphUrl,
|
|
32
|
-
}),
|
|
33
|
-
cache: new apollo_cache_inmemory_1.InMemoryCache(),
|
|
34
|
-
});
|
|
35
|
-
const result = yield client.query({
|
|
36
|
-
query: query,
|
|
37
|
-
fetchPolicy: 'cache-first',
|
|
38
|
-
});
|
|
39
|
-
return queries_1.QueryBuilderFactory.transformData(result);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
exports.apolloFetcher = apolloFetcher;
|
|
43
|
-
function fetchBlockByTimestamp(timestamp) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
try {
|
|
46
|
-
if (subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network].length == 0)
|
|
47
|
-
return null;
|
|
48
|
-
const subgraph = subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network];
|
|
49
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
50
|
-
const result = yield this.apolloFetcher(subgraph, query.blockQuery(timestamp));
|
|
51
|
-
// TODO: This is wrong in case of different endpoints?
|
|
52
|
-
console.log(result.data._meta.block.number);
|
|
53
|
-
if (!result.data.blocks[0])
|
|
54
|
-
return null;
|
|
55
|
-
return result.data.blocks[0].number;
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
console.log("can't fetch blocks by timestamp");
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
exports.fetchBlockByTimestamp = fetchBlockByTimestamp;
|
|
64
|
-
// Fetch Lending Pools
|
|
65
|
-
function fetchLendingPools() {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
const calls = [];
|
|
68
|
-
let factory;
|
|
69
|
-
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
70
|
-
// Multiple endpoints
|
|
71
|
-
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
72
|
-
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, [], this.network)));
|
|
73
|
-
}
|
|
74
|
-
const results = yield Promise.all(calls);
|
|
75
|
-
const lendingPools = {};
|
|
76
|
-
let i = 0;
|
|
77
|
-
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
78
|
-
lendingPools[factory] = results[i++].data.lendingPools;
|
|
79
|
-
}
|
|
80
|
-
return lendingPools;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
exports.fetchLendingPools = fetchLendingPools;
|
|
84
|
-
function fetchLendingPoolsPast(seconds) {
|
|
85
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
const timestamp = Math.floor((new Date).getTime() / 1000);
|
|
87
|
-
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
88
|
-
if (!blockNumber)
|
|
89
|
-
return null;
|
|
90
|
-
try {
|
|
91
|
-
const calls = [];
|
|
92
|
-
let factory;
|
|
93
|
-
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
94
|
-
const endpoints = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
95
|
-
// Not all endpoints might support this
|
|
96
|
-
const supportedEndpoints = endpoints.filter(endpoint => queries_1.QueryBuilderFactory.getQuery(endpoint).lendingPoolsPastQuery);
|
|
97
|
-
// Skip if no endpoints support past queries for this factory
|
|
98
|
-
if (supportedEndpoints.length === 0)
|
|
99
|
-
continue;
|
|
100
|
-
// Query only from supported endpoints
|
|
101
|
-
calls.push(this.endpointManager.fetch(supportedEndpoints, this.network, (queryBuilder) => queryBuilder.lendingPoolsPastQuery(blockNumber, this.whitelistedPairs[factory])));
|
|
102
|
-
}
|
|
103
|
-
const results = yield Promise.all(calls);
|
|
104
|
-
const lendingPools = {};
|
|
105
|
-
let i = 0;
|
|
106
|
-
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
107
|
-
lendingPools[factory] = results[i++].data.lendingPools;
|
|
108
|
-
}
|
|
109
|
-
return lendingPools;
|
|
110
|
-
}
|
|
111
|
-
catch (_a) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
exports.fetchLendingPoolsPast = fetchLendingPoolsPast;
|
|
117
|
-
// Farming APR
|
|
118
|
-
function fetchImpermaxChefRewardRates() {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
-
const subgraph = subgraphs_1.IMPERMAX_CHEF_SUBGRAPH_URL[this.network];
|
|
121
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
122
|
-
// `impermaxChefQuery` is optional, see `offchain/queries/interfaces/query-builder.ts`
|
|
123
|
-
// Since it's not part of core, one endpoint should suffice
|
|
124
|
-
if (!subgraph || !query.impermaxChefQuery)
|
|
125
|
-
return null;
|
|
126
|
-
const result = yield this.apolloFetcher(subgraph, query.impermaxChefQuery());
|
|
127
|
-
const rewards = {};
|
|
128
|
-
let rewardToken = result.data.impermaxChefs[0].rewardToken;
|
|
129
|
-
let rewardPerSec = parseFloat(result.data.impermaxChefs[0].rewardPerSec);
|
|
130
|
-
let totalAllocPoint = parseFloat(result.data.impermaxChefs[0].totalAllocPoint);
|
|
131
|
-
const impermaxRewarders = result.data.impermaxRewarders;
|
|
132
|
-
for (const pool of result.data.pools) {
|
|
133
|
-
rewards[pool.id] = [];
|
|
134
|
-
rewards[pool.id].push({
|
|
135
|
-
rewardToken,
|
|
136
|
-
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
for (const impermaxRewarder of impermaxRewarders) {
|
|
140
|
-
rewardToken = impermaxRewarder.rewardToken;
|
|
141
|
-
rewardPerSec = parseFloat(impermaxRewarder.rewardPerSec);
|
|
142
|
-
totalAllocPoint = parseFloat(impermaxRewarder.totalAllocPoint);
|
|
143
|
-
for (const pool of impermaxRewarder.pools) {
|
|
144
|
-
if (!(pool.borrowable in rewards))
|
|
145
|
-
rewards[pool.borrowable] = [];
|
|
146
|
-
rewards[pool.borrowable].push({
|
|
147
|
-
rewardToken,
|
|
148
|
-
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return rewards;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
exports.fetchImpermaxChefRewardRates = fetchImpermaxChefRewardRates;
|
|
156
|
-
// Uniswap APR
|
|
157
|
-
function fetchPastVolume(amm, lendingPools, seconds) {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const timestamp = Math.floor((new Date).getTime() / 1000);
|
|
160
|
-
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
161
|
-
if (!blockNumber)
|
|
162
|
-
return {};
|
|
163
|
-
let result;
|
|
164
|
-
const pastVolume = {};
|
|
165
|
-
try {
|
|
166
|
-
const subgraph = amms_1.AMM_SUBGRAPH_URLS[this.network][amm];
|
|
167
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
168
|
-
// Since it's not part of core, one endpoint should suffice
|
|
169
|
-
if (!query.pastVolumeQuery)
|
|
170
|
-
return {};
|
|
171
|
-
result = yield this.apolloFetcher(subgraph, query.pastVolumeQuery(blockNumber, lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
172
|
-
for (const pair of result.data.pairs) {
|
|
173
|
-
pastVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
catch (e) {
|
|
177
|
-
console.error(e);
|
|
178
|
-
}
|
|
179
|
-
return pastVolume;
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
exports.fetchPastVolume = fetchPastVolume;
|
|
183
|
-
function fetchCurrentVolumeAndReserves(amm, lendingPools) {
|
|
184
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
let result;
|
|
186
|
-
const currentVolume = {};
|
|
187
|
-
const currentReserve = {};
|
|
188
|
-
try {
|
|
189
|
-
const subgraph = amms_1.AMM_SUBGRAPH_URLS[this.network][amm];
|
|
190
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
191
|
-
// Since it's not part of core, one endpoint should suffice
|
|
192
|
-
if (!query.currentVolumeAndReservesQuery)
|
|
193
|
-
return { currentReserve, currentVolume };
|
|
194
|
-
result = yield this.apolloFetcher(subgraph, query.currentVolumeAndReservesQuery(lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
195
|
-
for (const pair of result.data.pairs) {
|
|
196
|
-
currentVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
197
|
-
currentReserve[pair.id] = parseInt(pair.reserveUSD);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (e) {
|
|
201
|
-
console.error(e);
|
|
202
|
-
}
|
|
203
|
-
return { currentReserve, currentVolume };
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
exports.fetchCurrentVolumeAndReserves = fetchCurrentVolumeAndReserves;
|
|
207
|
-
function fetchUniswapAPR(lendingPoolsByAmm, seconds = 60 * 60 * 24 * 7) {
|
|
208
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
const uniswapAPR = {};
|
|
210
|
-
const amms = Object.keys(lendingPoolsByAmm);
|
|
211
|
-
const promises = [];
|
|
212
|
-
for (const amm of amms) {
|
|
213
|
-
if (!amms_1.AMM_SUBGRAPH_URLS[this.network][amm])
|
|
214
|
-
continue;
|
|
215
|
-
const lendingPools = lendingPoolsByAmm[amm];
|
|
216
|
-
if (lendingPools === undefined)
|
|
217
|
-
continue;
|
|
218
|
-
promises.push(Promise.all([
|
|
219
|
-
amm,
|
|
220
|
-
this.fetchPastVolume(amm, lendingPools, seconds),
|
|
221
|
-
this.fetchCurrentVolumeAndReserves(amm, lendingPools)
|
|
222
|
-
]));
|
|
223
|
-
}
|
|
224
|
-
const ammsData = yield Promise.all(promises);
|
|
225
|
-
for (const data of ammsData) {
|
|
226
|
-
const [amm, pastVolume, { currentVolume, currentReserve },] = data;
|
|
227
|
-
const lendingPools = lendingPoolsByAmm[amm];
|
|
228
|
-
if (lendingPools === undefined)
|
|
229
|
-
continue;
|
|
230
|
-
for (const lendingPool of lendingPools) {
|
|
231
|
-
const uniswapV2PairAddress = lendingPool.pair.uniswapV2PairAddress;
|
|
232
|
-
if (!currentReserve[uniswapV2PairAddress]) {
|
|
233
|
-
uniswapAPR[lendingPool.id] = 0;
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
const cumVolumePast = pastVolume[uniswapV2PairAddress] ? pastVolume[uniswapV2PairAddress] : 0;
|
|
237
|
-
const cumVolumeNow = currentVolume[uniswapV2PairAddress];
|
|
238
|
-
const reserveUSD = currentReserve[uniswapV2PairAddress];
|
|
239
|
-
const volumeUSD = cumVolumeNow - cumVolumePast;
|
|
240
|
-
const yearlyVolume = volumeUSD * SECONDS_IN_YEAR / seconds;
|
|
241
|
-
const yearlyFee = yearlyVolume * amms_1.AMM_LP_FEE[this.network][amm];
|
|
242
|
-
uniswapAPR[lendingPool.id] = yearlyFee / reserveUSD;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return uniswapAPR;
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
exports.fetchUniswapAPR = fetchUniswapAPR;
|
|
249
|
-
// OffchainLendingPool Data
|
|
250
|
-
function initializeLendingPoolsData() {
|
|
251
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
-
const lendingPoolsData = {};
|
|
253
|
-
// Get raw data
|
|
254
|
-
const [lendingPools, lendingPoolsPast24h, lendingPoolsPast7d, impermaxChefRewardRates,] = yield Promise.all([
|
|
255
|
-
this.fetchLendingPools(),
|
|
256
|
-
this.fetchLendingPoolsPast(24 * 3600),
|
|
257
|
-
this.fetchLendingPoolsPast(7 * 24 * 3600),
|
|
258
|
-
this.fetchImpermaxChefRewardRates(),
|
|
259
|
-
]);
|
|
260
|
-
// Get Uniswap APR
|
|
261
|
-
const lendingPoolsByAmm = {};
|
|
262
|
-
for (const factory in lendingPools) {
|
|
263
|
-
for (const lendingPool of lendingPools[factory]) {
|
|
264
|
-
const amm = (0, amms_1.getAmmByFactory)(this.network, lendingPool.pair.uniswapV2Factory);
|
|
265
|
-
if (!amm)
|
|
266
|
-
continue;
|
|
267
|
-
if (!lendingPoolsByAmm[amm])
|
|
268
|
-
lendingPoolsByAmm[amm] = [];
|
|
269
|
-
const lendingPoolsOfAmm = lendingPoolsByAmm[amm];
|
|
270
|
-
lendingPoolsOfAmm.push(lendingPool);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
const uniswapAPR = yield this.fetchUniswapAPR(lendingPoolsByAmm);
|
|
274
|
-
// Organize lending pools data
|
|
275
|
-
for (const factory in lendingPools) {
|
|
276
|
-
for (const lendingPool of lendingPools[factory]) {
|
|
277
|
-
lendingPool.pair.uniswapAPR = uniswapAPR[lendingPool.id] || 0;
|
|
278
|
-
if (impermaxChefRewardRates) {
|
|
279
|
-
lendingPool.borrowable0.rewards = impermaxChefRewardRates[lendingPool.borrowable0.id];
|
|
280
|
-
lendingPool.borrowable1.rewards = impermaxChefRewardRates[lendingPool.borrowable1.id];
|
|
281
|
-
}
|
|
282
|
-
// If one of the price of the 2 tokens is 0, fix the collateral price by doubling it
|
|
283
|
-
if (parseFloat(lendingPool.borrowable0.underlying.derivedUSD) === 0 || parseFloat(lendingPool.borrowable1.underlying.derivedUSD) === 0) {
|
|
284
|
-
lendingPool.pair.derivedUSD = (parseFloat(lendingPool.pair.derivedUSD) * 2).toString();
|
|
285
|
-
}
|
|
286
|
-
if (!lendingPoolsData[factory])
|
|
287
|
-
lendingPoolsData[factory] = {};
|
|
288
|
-
lendingPoolsData[factory][lendingPool.id] = lendingPool;
|
|
289
|
-
}
|
|
290
|
-
// Add past data
|
|
291
|
-
if (lendingPoolsPast24h) {
|
|
292
|
-
const lendingPoolsPast24hOfFactory = lendingPoolsPast24h[factory];
|
|
293
|
-
if (lendingPoolsPast24hOfFactory) {
|
|
294
|
-
for (const lendingPool of lendingPoolsPast24hOfFactory) {
|
|
295
|
-
lendingPoolsData[factory][lendingPool.id].past24h = lendingPool;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (lendingPoolsPast7d) {
|
|
300
|
-
const lendingPoolsPast7dhOfFactory = lendingPoolsPast7d[factory];
|
|
301
|
-
if (lendingPoolsPast7dhOfFactory) {
|
|
302
|
-
for (const lendingPool of lendingPoolsPast7dhOfFactory) {
|
|
303
|
-
lendingPoolsData[factory][lendingPool.id].past7d = lendingPool;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
// Initialize OffchainLendingPool objects
|
|
309
|
-
this.lendingPools = {};
|
|
310
|
-
for (const factory in lendingPools) {
|
|
311
|
-
this.lendingPools[factory] = {};
|
|
312
|
-
for (const lendingPool of lendingPools[factory]) {
|
|
313
|
-
this.lendingPools[factory][lendingPool.id] =
|
|
314
|
-
new lendingPool_1.default(this, factory, lendingPool.id);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
// Quickfix for MIM and SPELL
|
|
318
|
-
if (this.network === types_1.Networks.Arbitrum) {
|
|
319
|
-
// const ETH_MIM = '0xa6e69dd0c36f3b59539e2c7afd274ef91b5c70f9';
|
|
320
|
-
// const ETH_SPELL = '0x35b44b303eacb71114aa62fe8dae6f9c5de0f680';
|
|
321
|
-
const ETH_gGOHM = '0x6d94f7e67c6ae0b0257c35754e059fdfb249d998';
|
|
322
|
-
const ETH_MAGIC = '0x88a0b00bbe918ee00e3482f71962070dc052984b';
|
|
323
|
-
const ETH_RDNT = '0xfb468ad210d427d65c9a765a480649d5754ca325';
|
|
324
|
-
// const LIZ_LIZ_ETH = '0x699c5e23357ab1bf658bd0b38070d746e37671f3';
|
|
325
|
-
// const LIZ_ETH_USDC = '0x1229aac120ae75301ab1c3a2a04ec14183493584';
|
|
326
|
-
// const LIZ_ETH_BTC = '0xce009c44e1645bc6d19c90ba440c618a42ae581d';
|
|
327
|
-
// const LIZ_LIZ_USDC = '0x463ec151258370a07431068bb3bdc98b5a6ba18f';
|
|
328
|
-
const lendingPoolsDataV2V1_1 = lendingPoolsData[types_1.Factory.V2V1_1];
|
|
329
|
-
if (lendingPoolsDataV2V1_1) {
|
|
330
|
-
if (lendingPoolsDataV2V1_1[ETH_gGOHM]) {
|
|
331
|
-
//lendingPoolsData[Factory.V2V1_1][ETH_SPELL].pair.rewards[0].rewardRate = '8.44';
|
|
332
|
-
//lendingPoolsData[Factory.V2V1_1][ETH_MIM].pair.rewards[0].rewardRate = '30.64';
|
|
333
|
-
//lendingPoolsData[Factory.V2V1_1][ETH_gGOHM].pair.rewards[0].rewardRate = '0.000009129';
|
|
334
|
-
lendingPoolsDataV2V1_1[ETH_MAGIC].pair.rewards[0].rewardRate = '0.135';
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
338
|
-
if (lendingPoolsDataV2V2) {
|
|
339
|
-
if (lendingPoolsDataV2V2[ETH_RDNT]) {
|
|
340
|
-
lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate = (parseFloat(lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate) / 2).toString();
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
/*if (lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH]) {
|
|
344
|
-
const LIZ = lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].borrowable0.underlying;
|
|
345
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.rewards = [{
|
|
346
|
-
id: '',
|
|
347
|
-
rewardsToken: LIZ,
|
|
348
|
-
rewardRate: '3.724',
|
|
349
|
-
periodFinish: '0',
|
|
350
|
-
}];
|
|
351
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.stakedTotalSupply = '40131.19426';
|
|
352
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.rewards = [{
|
|
353
|
-
id: '',
|
|
354
|
-
rewardsToken: LIZ,
|
|
355
|
-
rewardRate: '1.284',
|
|
356
|
-
periodFinish: '0',
|
|
357
|
-
}];
|
|
358
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.stakedTotalSupply = '0.182614';
|
|
359
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.rewards = [{
|
|
360
|
-
id: '',
|
|
361
|
-
rewardsToken: LIZ,
|
|
362
|
-
rewardRate: '0.159',
|
|
363
|
-
periodFinish: '0',
|
|
364
|
-
}];
|
|
365
|
-
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.stakedTotalSupply = '0.002468';
|
|
366
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.rewards = [{
|
|
367
|
-
id: '',
|
|
368
|
-
rewardsToken: LIZ,
|
|
369
|
-
rewardRate: '1.566',
|
|
370
|
-
periodFinish: '0',
|
|
371
|
-
}];
|
|
372
|
-
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.stakedTotalSupply = '0.568227';
|
|
373
|
-
}*/
|
|
374
|
-
}
|
|
375
|
-
if (this.network === types_1.Networks.Polygon) {
|
|
376
|
-
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
377
|
-
if (lendingPoolsDataV2V2) {
|
|
378
|
-
const GNS_DAI = '0xf9221c5edc736d26ffc4ddccddfa15a4b958862e';
|
|
379
|
-
if (lendingPoolsDataV2V2[GNS_DAI]) {
|
|
380
|
-
const GNS = lendingPoolsDataV2V2[GNS_DAI].borrowable1.underlying;
|
|
381
|
-
lendingPoolsDataV2V2[GNS_DAI].pair.rewards[0] = {
|
|
382
|
-
id: '',
|
|
383
|
-
rewardsToken: GNS,
|
|
384
|
-
rewardRate: '0.00608',
|
|
385
|
-
periodFinish: '0',
|
|
386
|
-
};
|
|
387
|
-
lendingPoolsDataV2V2[GNS_DAI].pair.stakedTotalSupply = '1640000';
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
if (this.network === types_1.Networks.Avalanche) {
|
|
392
|
-
const lendingPoolsDataV2V1_2 = lendingPoolsData[types_1.Factory.V2V1_2];
|
|
393
|
-
if (lendingPoolsDataV2V1_2) {
|
|
394
|
-
const QI_AVAX = '0x3e2a4dcd46e0e339aec603080d90bd939a163062';
|
|
395
|
-
if (lendingPoolsDataV2V1_2[QI_AVAX]) {
|
|
396
|
-
const QI = lendingPoolsDataV2V1_2[QI_AVAX].borrowable0.underlying;
|
|
397
|
-
lendingPoolsDataV2V1_2[QI_AVAX].pair.rewards[0] = {
|
|
398
|
-
id: '',
|
|
399
|
-
rewardsToken: QI,
|
|
400
|
-
rewardRate: '4.54',
|
|
401
|
-
periodFinish: '0',
|
|
402
|
-
};
|
|
403
|
-
// TODO -> this is wrong
|
|
404
|
-
lendingPoolsDataV2V1_2[QI_AVAX].pair.stakedTotalSupply = '0.000000992210460243'; //https://snowtrace.io/token/0xe530dc2095ef5653205cf5ea79f8979a7028065c?a=0x784da19e61cf348a8c54547531795ecfee2affd1
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
/*REWARD STOPPED const sAVAX_AVAX = '0x5b588f4481035b0f765393fc9f4752615a6d0498';
|
|
408
|
-
if (lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX]) {
|
|
409
|
-
const QI = lendingPoolsData[Factory.V2V1_2][QI_AVAX].borrowable0.underlying;
|
|
410
|
-
lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX].pair.rewards[1] = {
|
|
411
|
-
id: '',
|
|
412
|
-
rewardsToken: QI,
|
|
413
|
-
rewardRate: '1.74',
|
|
414
|
-
periodFinish: '0',
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
const UST_AVAX = '0xc6e68d77d0f4fa925a1cf2611dab6b10900eaf2b';
|
|
418
|
-
if (lendingPoolsData[Factory.V2V1_2][UST_AVAX]) {
|
|
419
|
-
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
420
|
-
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[0].rewardRate = '0.000099';
|
|
421
|
-
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[2] = {
|
|
422
|
-
id: '',
|
|
423
|
-
rewardsToken: AVAX,
|
|
424
|
-
rewardRate: '0.00047',
|
|
425
|
-
periodFinish: '0',
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
const UST_USDC = '0x69c1c44e8742b66d892294a7eeb9aac51891b0eb';
|
|
429
|
-
if (lendingPoolsData[Factory.V2V1_2][UST_USDC]) {
|
|
430
|
-
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
431
|
-
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[0].rewardRate = '0.000099';
|
|
432
|
-
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[2] = {
|
|
433
|
-
id: '',
|
|
434
|
-
rewardsToken: AVAX,
|
|
435
|
-
rewardRate: '0.00047',
|
|
436
|
-
periodFinish: '0',
|
|
437
|
-
};
|
|
438
|
-
}*/
|
|
439
|
-
}
|
|
440
|
-
return lendingPoolsData;
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
exports.initializeLendingPoolsData = initializeLendingPoolsData;
|
|
444
|
-
function getLendingPoolsData() {
|
|
445
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
-
if (!this.lendingPoolsData)
|
|
447
|
-
this.lendingPoolsData = this.initializeLendingPoolsData();
|
|
448
|
-
return this.lendingPoolsData;
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
exports.getLendingPoolsData = getLendingPoolsData;
|
|
452
|
-
function getLendingPoolData(factory, uniswapV2PairAddress) {
|
|
453
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
-
const lendingPoolsData = (yield this.getLendingPoolsData())[factory];
|
|
455
|
-
return lendingPoolsData[uniswapV2PairAddress.toLowerCase()];
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
exports.getLendingPoolData = getLendingPoolData;
|
|
459
|
-
// TVL Data
|
|
460
|
-
function initializeTvlData() {
|
|
461
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
462
|
-
const networks = [
|
|
463
|
-
types_1.Networks.Mainnet,
|
|
464
|
-
types_1.Networks.Arbitrum,
|
|
465
|
-
types_1.Networks.Polygon,
|
|
466
|
-
types_1.Networks.Avalanche,
|
|
467
|
-
// Networks.Moonriver,
|
|
468
|
-
types_1.Networks.Fantom,
|
|
469
|
-
// Networks.Canto,
|
|
470
|
-
types_1.Networks.ZksyncEra,
|
|
471
|
-
// Networks.Mantle,
|
|
472
|
-
types_1.Networks.Base,
|
|
473
|
-
types_1.Networks.Scroll,
|
|
474
|
-
types_1.Networks.Real,
|
|
475
|
-
types_1.Networks.Blast
|
|
476
|
-
]; // exclude ropsten
|
|
477
|
-
const calls = [];
|
|
478
|
-
for (const network of networks) {
|
|
479
|
-
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[network]) {
|
|
480
|
-
// Multiple endpoints
|
|
481
|
-
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[network][factory];
|
|
482
|
-
calls.push(this.endpointManager.fetch(subgraphs, network, (queryBuilder) => queryBuilder.tvlQuery()));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
let results;
|
|
486
|
-
try {
|
|
487
|
-
results = yield Promise.all(calls);
|
|
488
|
-
}
|
|
489
|
-
catch (e) {
|
|
490
|
-
console.log("can't initialize TVL data");
|
|
491
|
-
return {
|
|
492
|
-
crossChainTVLUSD: 0,
|
|
493
|
-
crossChainSupplyUSD: 0,
|
|
494
|
-
crossChainBorrowUSD: 0,
|
|
495
|
-
totalBalanceUSD: 0,
|
|
496
|
-
totalSupplyUSD: 0,
|
|
497
|
-
totalBorrowsUSD: 0,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
let crossChainTVLUSD = 0;
|
|
501
|
-
let crossChainSupplyUSD = 0;
|
|
502
|
-
let crossChainBorrowUSD = 0;
|
|
503
|
-
let thisChainTVLUSD = 0;
|
|
504
|
-
let thisChainSupplyUSD = 0;
|
|
505
|
-
let thisChainBorrowUSD = 0;
|
|
506
|
-
let i = 0;
|
|
507
|
-
for (const network of networks) {
|
|
508
|
-
for (const _ in subgraphs_1.IMPERMAX_SUBGRAPH_URL[network]) {
|
|
509
|
-
// Need to pluralize `impermaxFactory`
|
|
510
|
-
const data = queries_1.QueryBuilderFactory.getImpermaxFactory(results[i]);
|
|
511
|
-
if (data) {
|
|
512
|
-
crossChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
513
|
-
crossChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
514
|
-
crossChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
515
|
-
if (network === this.network) {
|
|
516
|
-
thisChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
517
|
-
thisChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
518
|
-
thisChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
i++;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (!networks.includes(this.network)) {
|
|
525
|
-
const calls = [];
|
|
526
|
-
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
527
|
-
// Multiple endpoints
|
|
528
|
-
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
529
|
-
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.tvlQuery()));
|
|
530
|
-
}
|
|
531
|
-
const results = yield Promise.all(calls);
|
|
532
|
-
i = 0;
|
|
533
|
-
for (const _ in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
534
|
-
// Need to pluralize `impermaxFactory`
|
|
535
|
-
const data = queries_1.QueryBuilderFactory.getImpermaxFactory(results[i]);
|
|
536
|
-
if (data) {
|
|
537
|
-
thisChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
538
|
-
thisChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
539
|
-
thisChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
540
|
-
}
|
|
541
|
-
i++;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
return {
|
|
545
|
-
crossChainTVLUSD,
|
|
546
|
-
crossChainSupplyUSD,
|
|
547
|
-
crossChainBorrowUSD,
|
|
548
|
-
totalBalanceUSD: thisChainTVLUSD,
|
|
549
|
-
totalSupplyUSD: thisChainSupplyUSD,
|
|
550
|
-
totalBorrowsUSD: thisChainBorrowUSD,
|
|
551
|
-
};
|
|
552
|
-
});
|
|
553
|
-
}
|
|
554
|
-
exports.initializeTvlData = initializeTvlData;
|
|
555
|
-
function getTvlData() {
|
|
556
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
557
|
-
if (!this.tvlData)
|
|
558
|
-
this.tvlData = this.initializeTvlData();
|
|
559
|
-
return this.tvlData;
|
|
560
|
-
});
|
|
561
|
-
}
|
|
562
|
-
exports.getTvlData = getTvlData;
|
|
563
|
-
// User Data
|
|
564
|
-
function fetchUserData(account) {
|
|
565
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
-
const positions = {};
|
|
567
|
-
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
568
|
-
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
569
|
-
// We pass network + factory to get the actual factory address in case we use multiple factories in 1 api
|
|
570
|
-
const result = yield this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.userQuery(account, this.network, factory));
|
|
571
|
-
const user = result.data.user;
|
|
572
|
-
if (!user)
|
|
573
|
-
continue;
|
|
574
|
-
positions[factory] = {
|
|
575
|
-
collateralPositions: user.collateralPositions,
|
|
576
|
-
supplyPositions: user.supplyPositions,
|
|
577
|
-
borrowPositions: user.borrowPositions,
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
return positions;
|
|
581
|
-
// TODO parallelize calls
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
exports.fetchUserData = fetchUserData;
|
|
585
|
-
function initializeUserData(account) {
|
|
586
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
587
|
-
const result = {};
|
|
588
|
-
const userData = yield this.fetchUserData(account);
|
|
589
|
-
if (!userData)
|
|
590
|
-
return null;
|
|
591
|
-
let factory;
|
|
592
|
-
for (factory in userData) {
|
|
593
|
-
result[factory] = {
|
|
594
|
-
collateralPositions: {},
|
|
595
|
-
supplyPositions: {},
|
|
596
|
-
borrowPositions: {},
|
|
597
|
-
};
|
|
598
|
-
const rawUserData = userData[factory];
|
|
599
|
-
for (const collateralPosition of rawUserData.collateralPositions) {
|
|
600
|
-
const resultOfFactory = result[factory];
|
|
601
|
-
resultOfFactory.collateralPositions[collateralPosition.collateral.lendingPool.id] = collateralPosition;
|
|
602
|
-
}
|
|
603
|
-
for (const supplyPositions of rawUserData.supplyPositions) {
|
|
604
|
-
const uniswapV2PairAddress = supplyPositions.borrowable.lendingPool.id;
|
|
605
|
-
const underlyingAddress = supplyPositions.borrowable.underlying.id;
|
|
606
|
-
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
607
|
-
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
608
|
-
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
609
|
-
const resultOfFactory = result[factory];
|
|
610
|
-
if (!(uniswapV2PairAddress in resultOfFactory.supplyPositions))
|
|
611
|
-
resultOfFactory.supplyPositions[uniswapV2PairAddress] = {};
|
|
612
|
-
resultOfFactory.supplyPositions[uniswapV2PairAddress][poolTokenType] = supplyPositions;
|
|
613
|
-
}
|
|
614
|
-
for (const borrowPositions of rawUserData.borrowPositions) {
|
|
615
|
-
const uniswapV2PairAddress = borrowPositions.borrowable.lendingPool.id;
|
|
616
|
-
const underlyingAddress = borrowPositions.borrowable.underlying.id;
|
|
617
|
-
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
618
|
-
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
619
|
-
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
620
|
-
const resultOfFactory = result[factory];
|
|
621
|
-
if (!(uniswapV2PairAddress in resultOfFactory.borrowPositions))
|
|
622
|
-
resultOfFactory.borrowPositions[uniswapV2PairAddress] = {};
|
|
623
|
-
resultOfFactory.borrowPositions[uniswapV2PairAddress][poolTokenType] = borrowPositions;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
return result;
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
exports.initializeUserData = initializeUserData;
|
|
630
|
-
function getUserData(account) {
|
|
631
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
632
|
-
if (!(account in this.usersData))
|
|
633
|
-
this.usersData[account] = this.initializeUserData(account);
|
|
634
|
-
return this.usersData[account];
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
exports.getUserData = getUserData;
|
|
638
|
-
// IMX Staking
|
|
639
|
-
function initializeXimxData() {
|
|
640
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
641
|
-
const subgraph = subgraphs_1.XIMX_SUBGRAPH_URL;
|
|
642
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
643
|
-
const result = yield apolloFetcher(subgraph, query.ximxQuery());
|
|
644
|
-
return result.data.ximxes[0];
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
exports.initializeXimxData = initializeXimxData;
|
|
648
|
-
function getXimxData() {
|
|
649
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
650
|
-
if (!this.ximxData)
|
|
651
|
-
this.ximxData = this.initializeXimxData();
|
|
652
|
-
return this.ximxData;
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
exports.getXimxData = getXimxData;
|
|
656
|
-
/**
|
|
657
|
-
* Lending Vault
|
|
658
|
-
**/
|
|
659
|
-
function fetchLendingVaults() {
|
|
660
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
661
|
-
const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
|
|
662
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
663
|
-
const result = yield this.apolloFetcher(subgraph, query.lendingVaultsQuery([]));
|
|
664
|
-
return result.data.lendingVaults;
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
exports.fetchLendingVaults = fetchLendingVaults;
|
|
668
|
-
function initializeLendingVaultsData() {
|
|
669
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
670
|
-
const lendingVaultsData = {};
|
|
671
|
-
const lendingVaults = yield this.fetchLendingVaults();
|
|
672
|
-
// Organize lending vaults data
|
|
673
|
-
for (const lendingVault of lendingVaults) {
|
|
674
|
-
lendingVaultsData[lendingVault.id] = lendingVault;
|
|
675
|
-
}
|
|
676
|
-
// Initialize OffchainLendingVault objects
|
|
677
|
-
this.
|
|
678
|
-
for (const lendingVault of lendingVaults) {
|
|
679
|
-
this.
|
|
680
|
-
new
|
|
681
|
-
}
|
|
682
|
-
return lendingVaultsData;
|
|
683
|
-
});
|
|
684
|
-
}
|
|
685
|
-
exports.initializeLendingVaultsData = initializeLendingVaultsData;
|
|
686
|
-
function getLendingVaultsData() {
|
|
687
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
688
|
-
if (!this.lendingVaultsData)
|
|
689
|
-
this.lendingVaultsData = this.initializeLendingVaultsData();
|
|
690
|
-
return this.lendingVaultsData;
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
exports.getLendingVaultsData = getLendingVaultsData;
|
|
694
|
-
function getLendingVaultData(lendingVaultAddress) {
|
|
695
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
696
|
-
const lendingVaultsData = yield this.getLendingVaultsData();
|
|
697
|
-
return lendingVaultsData[lendingVaultAddress.toLowerCase()];
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
exports.getLendingVaultData = getLendingVaultData;
|
|
701
|
-
/**
|
|
702
|
-
* Whitelist
|
|
703
|
-
*/
|
|
704
|
-
function fetchWhitelist() {
|
|
705
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
-
const subgraph = subgraphs_1.WHITELIST_SUBGRAPH_URL[this.network];
|
|
707
|
-
if (!subgraph)
|
|
708
|
-
return [];
|
|
709
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
710
|
-
if (!query.whitelistQuery)
|
|
711
|
-
return [];
|
|
712
|
-
const result = yield this.apolloFetcher(subgraph, query.whitelistQuery());
|
|
713
|
-
if (!result || !result.data.whitelistStates)
|
|
714
|
-
return [];
|
|
715
|
-
return result.data.whitelistStates;
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
|
-
exports.fetchWhitelist = fetchWhitelist;
|
|
719
|
-
function initializeWhitelistData() {
|
|
720
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
721
|
-
const whitelistData = {};
|
|
722
|
-
const whitelistPairsData = yield this.fetchWhitelist();
|
|
723
|
-
// Organize lending vaults data
|
|
724
|
-
for (const whitelistPairData of whitelistPairsData) {
|
|
725
|
-
const factory = (0, impermax_factories_1.getFactoryByAddress)(this.network, whitelistPairData.factory);
|
|
726
|
-
if (!factory)
|
|
727
|
-
continue;
|
|
728
|
-
if (!whitelistData[factory])
|
|
729
|
-
whitelistData[factory] = {};
|
|
730
|
-
const whitelistDataOfFactory = whitelistData[factory];
|
|
731
|
-
whitelistDataOfFactory[whitelistPairData.pair] = whitelistPairData.state;
|
|
732
|
-
}
|
|
733
|
-
return whitelistData;
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
exports.initializeWhitelistData = initializeWhitelistData;
|
|
737
|
-
function getWhitelistData() {
|
|
738
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
-
if (!this.whitelistData)
|
|
740
|
-
this.whitelistData = this.initializeWhitelistData();
|
|
741
|
-
return this.whitelistData;
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
exports.getWhitelistData = getWhitelistData;
|
|
745
|
-
function getWhitelistState(factory, pair) {
|
|
746
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
747
|
-
const whitelistData = yield this.getWhitelistData();
|
|
748
|
-
const whitelistDataOfFactory = whitelistData[factory];
|
|
749
|
-
if (!whitelistDataOfFactory)
|
|
750
|
-
return types_1.WhitelistState.Unlisted;
|
|
751
|
-
if (!whitelistDataOfFactory[pair.toLowerCase()])
|
|
752
|
-
return types_1.WhitelistState.Unlisted;
|
|
753
|
-
return whitelistDataOfFactory[pair.toLowerCase()];
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
exports.getWhitelistState = getWhitelistState;
|
|
757
|
-
/**
|
|
758
|
-
* User Data
|
|
759
|
-
*/
|
|
760
|
-
function fetchLendingVaultsUserData(account) {
|
|
761
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
762
|
-
const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
|
|
763
|
-
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
764
|
-
const result = yield this.apolloFetcher(subgraph, query.lendingVaultsUserQuery(account));
|
|
765
|
-
const user = result.data.user;
|
|
766
|
-
if (!user)
|
|
767
|
-
return null;
|
|
768
|
-
return result.data.user.positions;
|
|
769
|
-
});
|
|
770
|
-
}
|
|
771
|
-
exports.fetchLendingVaultsUserData = fetchLendingVaultsUserData;
|
|
772
|
-
function initializeLendingVaultsUserData(account) {
|
|
773
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
774
|
-
const positions = yield this.fetchLendingVaultsUserData(account);
|
|
775
|
-
if (!positions)
|
|
776
|
-
return null;
|
|
777
|
-
const result = {};
|
|
778
|
-
for (const position of positions) {
|
|
779
|
-
result[position.lendingVault.id] = position;
|
|
780
|
-
}
|
|
781
|
-
return result;
|
|
782
|
-
});
|
|
783
|
-
}
|
|
784
|
-
exports.initializeLendingVaultsUserData = initializeLendingVaultsUserData;
|
|
785
|
-
function getLendingVaultsUserData(account) {
|
|
786
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
787
|
-
if (!(account in this.lendingVaultsUsersData))
|
|
788
|
-
this.lendingVaultsUsersData[account] = this.initializeLendingVaultsUserData(account);
|
|
789
|
-
return yield this.lendingVaultsUsersData[account];
|
|
790
|
-
});
|
|
791
|
-
}
|
|
792
|
-
exports.getLendingVaultsUserData = getLendingVaultsUserData;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getLendingVaultsUserData = exports.initializeLendingVaultsUserData = exports.fetchLendingVaultsUserData = exports.getWhitelistState = exports.getWhitelistData = exports.initializeWhitelistData = exports.fetchWhitelist = exports.getLendingVaultData = exports.getLendingVaultsData = exports.initializeLendingVaultsData = exports.fetchLendingVaults = exports.getXimxData = exports.initializeXimxData = exports.getUserData = exports.initializeUserData = exports.fetchUserData = exports.getTvlData = exports.initializeTvlData = exports.getLendingPoolData = exports.getLendingPoolsData = exports.initializeLendingPoolsData = exports.fetchUniswapAPR = exports.fetchCurrentVolumeAndReserves = exports.fetchPastVolume = exports.fetchImpermaxChefRewardRates = exports.fetchLendingPoolsPast = exports.fetchLendingPools = exports.fetchBlockByTimestamp = exports.apolloFetcher = void 0;
|
|
16
|
+
const apollo_client_1 = __importDefault(require("apollo-client"));
|
|
17
|
+
const apollo_link_http_1 = require("apollo-link-http");
|
|
18
|
+
const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
|
|
19
|
+
const queries_1 = require("./queries");
|
|
20
|
+
const lendingPool_1 = __importDefault(require("./lendingPool"));
|
|
21
|
+
const subgraphs_1 = require("../config/subgraphs");
|
|
22
|
+
const types_1 = require("../config/types");
|
|
23
|
+
const amms_1 = require("../config/amms");
|
|
24
|
+
const offchainVault_1 = __importDefault(require("./vault/offchainVault"));
|
|
25
|
+
const impermax_factories_1 = require("../config/contracts/impermax-factories");
|
|
26
|
+
const SECONDS_IN_YEAR = 60 * 60 * 24 * 365;
|
|
27
|
+
function apolloFetcher(subgraphUrl, query) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const client = new apollo_client_1.default({
|
|
30
|
+
link: new apollo_link_http_1.HttpLink({
|
|
31
|
+
uri: subgraphUrl,
|
|
32
|
+
}),
|
|
33
|
+
cache: new apollo_cache_inmemory_1.InMemoryCache(),
|
|
34
|
+
});
|
|
35
|
+
const result = yield client.query({
|
|
36
|
+
query: query,
|
|
37
|
+
fetchPolicy: 'cache-first',
|
|
38
|
+
});
|
|
39
|
+
return queries_1.QueryBuilderFactory.transformData(result);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.apolloFetcher = apolloFetcher;
|
|
43
|
+
function fetchBlockByTimestamp(timestamp) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
if (subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network].length == 0)
|
|
47
|
+
return null;
|
|
48
|
+
const subgraph = subgraphs_1.BLOCKS_SUBGRAPH_URL[this.network];
|
|
49
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
50
|
+
const result = yield this.apolloFetcher(subgraph, query.blockQuery(timestamp));
|
|
51
|
+
// TODO: This is wrong in case of different endpoints?
|
|
52
|
+
console.log(result.data._meta.block.number);
|
|
53
|
+
if (!result.data.blocks[0])
|
|
54
|
+
return null;
|
|
55
|
+
return result.data.blocks[0].number;
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
console.log("can't fetch blocks by timestamp");
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.fetchBlockByTimestamp = fetchBlockByTimestamp;
|
|
64
|
+
// Fetch Lending Pools
|
|
65
|
+
function fetchLendingPools() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const calls = [];
|
|
68
|
+
let factory;
|
|
69
|
+
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
70
|
+
// Multiple endpoints
|
|
71
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
72
|
+
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.lendingPoolsQuery(factory, [], this.network)));
|
|
73
|
+
}
|
|
74
|
+
const results = yield Promise.all(calls);
|
|
75
|
+
const lendingPools = {};
|
|
76
|
+
let i = 0;
|
|
77
|
+
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
78
|
+
lendingPools[factory] = results[i++].data.lendingPools;
|
|
79
|
+
}
|
|
80
|
+
return lendingPools;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.fetchLendingPools = fetchLendingPools;
|
|
84
|
+
function fetchLendingPoolsPast(seconds) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const timestamp = Math.floor((new Date).getTime() / 1000);
|
|
87
|
+
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
88
|
+
if (!blockNumber)
|
|
89
|
+
return null;
|
|
90
|
+
try {
|
|
91
|
+
const calls = [];
|
|
92
|
+
let factory;
|
|
93
|
+
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
94
|
+
const endpoints = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
95
|
+
// Not all endpoints might support this
|
|
96
|
+
const supportedEndpoints = endpoints.filter(endpoint => queries_1.QueryBuilderFactory.getQuery(endpoint).lendingPoolsPastQuery);
|
|
97
|
+
// Skip if no endpoints support past queries for this factory
|
|
98
|
+
if (supportedEndpoints.length === 0)
|
|
99
|
+
continue;
|
|
100
|
+
// Query only from supported endpoints
|
|
101
|
+
calls.push(this.endpointManager.fetch(supportedEndpoints, this.network, (queryBuilder) => queryBuilder.lendingPoolsPastQuery(blockNumber, this.whitelistedPairs[factory])));
|
|
102
|
+
}
|
|
103
|
+
const results = yield Promise.all(calls);
|
|
104
|
+
const lendingPools = {};
|
|
105
|
+
let i = 0;
|
|
106
|
+
for (factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
107
|
+
lendingPools[factory] = results[i++].data.lendingPools;
|
|
108
|
+
}
|
|
109
|
+
return lendingPools;
|
|
110
|
+
}
|
|
111
|
+
catch (_a) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
exports.fetchLendingPoolsPast = fetchLendingPoolsPast;
|
|
117
|
+
// Farming APR
|
|
118
|
+
function fetchImpermaxChefRewardRates() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const subgraph = subgraphs_1.IMPERMAX_CHEF_SUBGRAPH_URL[this.network];
|
|
121
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
122
|
+
// `impermaxChefQuery` is optional, see `offchain/queries/interfaces/query-builder.ts`
|
|
123
|
+
// Since it's not part of core, one endpoint should suffice
|
|
124
|
+
if (!subgraph || !query.impermaxChefQuery)
|
|
125
|
+
return null;
|
|
126
|
+
const result = yield this.apolloFetcher(subgraph, query.impermaxChefQuery());
|
|
127
|
+
const rewards = {};
|
|
128
|
+
let rewardToken = result.data.impermaxChefs[0].rewardToken;
|
|
129
|
+
let rewardPerSec = parseFloat(result.data.impermaxChefs[0].rewardPerSec);
|
|
130
|
+
let totalAllocPoint = parseFloat(result.data.impermaxChefs[0].totalAllocPoint);
|
|
131
|
+
const impermaxRewarders = result.data.impermaxRewarders;
|
|
132
|
+
for (const pool of result.data.pools) {
|
|
133
|
+
rewards[pool.id] = [];
|
|
134
|
+
rewards[pool.id].push({
|
|
135
|
+
rewardToken,
|
|
136
|
+
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
for (const impermaxRewarder of impermaxRewarders) {
|
|
140
|
+
rewardToken = impermaxRewarder.rewardToken;
|
|
141
|
+
rewardPerSec = parseFloat(impermaxRewarder.rewardPerSec);
|
|
142
|
+
totalAllocPoint = parseFloat(impermaxRewarder.totalAllocPoint);
|
|
143
|
+
for (const pool of impermaxRewarder.pools) {
|
|
144
|
+
if (!(pool.borrowable in rewards))
|
|
145
|
+
rewards[pool.borrowable] = [];
|
|
146
|
+
rewards[pool.borrowable].push({
|
|
147
|
+
rewardToken,
|
|
148
|
+
rewardRate: parseFloat(pool.allocPoint) / totalAllocPoint * rewardPerSec
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return rewards;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports.fetchImpermaxChefRewardRates = fetchImpermaxChefRewardRates;
|
|
156
|
+
// Uniswap APR
|
|
157
|
+
function fetchPastVolume(amm, lendingPools, seconds) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const timestamp = Math.floor((new Date).getTime() / 1000);
|
|
160
|
+
const blockNumber = yield this.fetchBlockByTimestamp(timestamp - seconds);
|
|
161
|
+
if (!blockNumber)
|
|
162
|
+
return {};
|
|
163
|
+
let result;
|
|
164
|
+
const pastVolume = {};
|
|
165
|
+
try {
|
|
166
|
+
const subgraph = amms_1.AMM_SUBGRAPH_URLS[this.network][amm];
|
|
167
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
168
|
+
// Since it's not part of core, one endpoint should suffice
|
|
169
|
+
if (!query.pastVolumeQuery)
|
|
170
|
+
return {};
|
|
171
|
+
result = yield this.apolloFetcher(subgraph, query.pastVolumeQuery(blockNumber, lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
172
|
+
for (const pair of result.data.pairs) {
|
|
173
|
+
pastVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
console.error(e);
|
|
178
|
+
}
|
|
179
|
+
return pastVolume;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
exports.fetchPastVolume = fetchPastVolume;
|
|
183
|
+
function fetchCurrentVolumeAndReserves(amm, lendingPools) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
let result;
|
|
186
|
+
const currentVolume = {};
|
|
187
|
+
const currentReserve = {};
|
|
188
|
+
try {
|
|
189
|
+
const subgraph = amms_1.AMM_SUBGRAPH_URLS[this.network][amm];
|
|
190
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
191
|
+
// Since it's not part of core, one endpoint should suffice
|
|
192
|
+
if (!query.currentVolumeAndReservesQuery)
|
|
193
|
+
return { currentReserve, currentVolume };
|
|
194
|
+
result = yield this.apolloFetcher(subgraph, query.currentVolumeAndReservesQuery(lendingPools.map(lendingPool => lendingPool.pair.uniswapV2PairAddress)));
|
|
195
|
+
for (const pair of result.data.pairs) {
|
|
196
|
+
currentVolume[pair.id] = parseInt(pair.volumeUSD);
|
|
197
|
+
currentReserve[pair.id] = parseInt(pair.reserveUSD);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch (e) {
|
|
201
|
+
console.error(e);
|
|
202
|
+
}
|
|
203
|
+
return { currentReserve, currentVolume };
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
exports.fetchCurrentVolumeAndReserves = fetchCurrentVolumeAndReserves;
|
|
207
|
+
function fetchUniswapAPR(lendingPoolsByAmm, seconds = 60 * 60 * 24 * 7) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
const uniswapAPR = {};
|
|
210
|
+
const amms = Object.keys(lendingPoolsByAmm);
|
|
211
|
+
const promises = [];
|
|
212
|
+
for (const amm of amms) {
|
|
213
|
+
if (!amms_1.AMM_SUBGRAPH_URLS[this.network][amm])
|
|
214
|
+
continue;
|
|
215
|
+
const lendingPools = lendingPoolsByAmm[amm];
|
|
216
|
+
if (lendingPools === undefined)
|
|
217
|
+
continue;
|
|
218
|
+
promises.push(Promise.all([
|
|
219
|
+
amm,
|
|
220
|
+
this.fetchPastVolume(amm, lendingPools, seconds),
|
|
221
|
+
this.fetchCurrentVolumeAndReserves(amm, lendingPools)
|
|
222
|
+
]));
|
|
223
|
+
}
|
|
224
|
+
const ammsData = yield Promise.all(promises);
|
|
225
|
+
for (const data of ammsData) {
|
|
226
|
+
const [amm, pastVolume, { currentVolume, currentReserve },] = data;
|
|
227
|
+
const lendingPools = lendingPoolsByAmm[amm];
|
|
228
|
+
if (lendingPools === undefined)
|
|
229
|
+
continue;
|
|
230
|
+
for (const lendingPool of lendingPools) {
|
|
231
|
+
const uniswapV2PairAddress = lendingPool.pair.uniswapV2PairAddress;
|
|
232
|
+
if (!currentReserve[uniswapV2PairAddress]) {
|
|
233
|
+
uniswapAPR[lendingPool.id] = 0;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const cumVolumePast = pastVolume[uniswapV2PairAddress] ? pastVolume[uniswapV2PairAddress] : 0;
|
|
237
|
+
const cumVolumeNow = currentVolume[uniswapV2PairAddress];
|
|
238
|
+
const reserveUSD = currentReserve[uniswapV2PairAddress];
|
|
239
|
+
const volumeUSD = cumVolumeNow - cumVolumePast;
|
|
240
|
+
const yearlyVolume = volumeUSD * SECONDS_IN_YEAR / seconds;
|
|
241
|
+
const yearlyFee = yearlyVolume * amms_1.AMM_LP_FEE[this.network][amm];
|
|
242
|
+
uniswapAPR[lendingPool.id] = yearlyFee / reserveUSD;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return uniswapAPR;
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
exports.fetchUniswapAPR = fetchUniswapAPR;
|
|
249
|
+
// OffchainLendingPool Data
|
|
250
|
+
function initializeLendingPoolsData() {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
const lendingPoolsData = {};
|
|
253
|
+
// Get raw data
|
|
254
|
+
const [lendingPools, lendingPoolsPast24h, lendingPoolsPast7d, impermaxChefRewardRates,] = yield Promise.all([
|
|
255
|
+
this.fetchLendingPools(),
|
|
256
|
+
this.fetchLendingPoolsPast(24 * 3600),
|
|
257
|
+
this.fetchLendingPoolsPast(7 * 24 * 3600),
|
|
258
|
+
this.fetchImpermaxChefRewardRates(),
|
|
259
|
+
]);
|
|
260
|
+
// Get Uniswap APR
|
|
261
|
+
const lendingPoolsByAmm = {};
|
|
262
|
+
for (const factory in lendingPools) {
|
|
263
|
+
for (const lendingPool of lendingPools[factory]) {
|
|
264
|
+
const amm = (0, amms_1.getAmmByFactory)(this.network, lendingPool.pair.uniswapV2Factory);
|
|
265
|
+
if (!amm)
|
|
266
|
+
continue;
|
|
267
|
+
if (!lendingPoolsByAmm[amm])
|
|
268
|
+
lendingPoolsByAmm[amm] = [];
|
|
269
|
+
const lendingPoolsOfAmm = lendingPoolsByAmm[amm];
|
|
270
|
+
lendingPoolsOfAmm.push(lendingPool);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const uniswapAPR = yield this.fetchUniswapAPR(lendingPoolsByAmm);
|
|
274
|
+
// Organize lending pools data
|
|
275
|
+
for (const factory in lendingPools) {
|
|
276
|
+
for (const lendingPool of lendingPools[factory]) {
|
|
277
|
+
lendingPool.pair.uniswapAPR = uniswapAPR[lendingPool.id] || 0;
|
|
278
|
+
if (impermaxChefRewardRates) {
|
|
279
|
+
lendingPool.borrowable0.rewards = impermaxChefRewardRates[lendingPool.borrowable0.id];
|
|
280
|
+
lendingPool.borrowable1.rewards = impermaxChefRewardRates[lendingPool.borrowable1.id];
|
|
281
|
+
}
|
|
282
|
+
// If one of the price of the 2 tokens is 0, fix the collateral price by doubling it
|
|
283
|
+
if (parseFloat(lendingPool.borrowable0.underlying.derivedUSD) === 0 || parseFloat(lendingPool.borrowable1.underlying.derivedUSD) === 0) {
|
|
284
|
+
lendingPool.pair.derivedUSD = (parseFloat(lendingPool.pair.derivedUSD) * 2).toString();
|
|
285
|
+
}
|
|
286
|
+
if (!lendingPoolsData[factory])
|
|
287
|
+
lendingPoolsData[factory] = {};
|
|
288
|
+
lendingPoolsData[factory][lendingPool.id] = lendingPool;
|
|
289
|
+
}
|
|
290
|
+
// Add past data
|
|
291
|
+
if (lendingPoolsPast24h) {
|
|
292
|
+
const lendingPoolsPast24hOfFactory = lendingPoolsPast24h[factory];
|
|
293
|
+
if (lendingPoolsPast24hOfFactory) {
|
|
294
|
+
for (const lendingPool of lendingPoolsPast24hOfFactory) {
|
|
295
|
+
lendingPoolsData[factory][lendingPool.id].past24h = lendingPool;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (lendingPoolsPast7d) {
|
|
300
|
+
const lendingPoolsPast7dhOfFactory = lendingPoolsPast7d[factory];
|
|
301
|
+
if (lendingPoolsPast7dhOfFactory) {
|
|
302
|
+
for (const lendingPool of lendingPoolsPast7dhOfFactory) {
|
|
303
|
+
lendingPoolsData[factory][lendingPool.id].past7d = lendingPool;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
// Initialize OffchainLendingPool objects
|
|
309
|
+
this.lendingPools = {};
|
|
310
|
+
for (const factory in lendingPools) {
|
|
311
|
+
this.lendingPools[factory] = {};
|
|
312
|
+
for (const lendingPool of lendingPools[factory]) {
|
|
313
|
+
this.lendingPools[factory][lendingPool.id] =
|
|
314
|
+
new lendingPool_1.default(this, factory, lendingPool.id);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// Quickfix for MIM and SPELL
|
|
318
|
+
if (this.network === types_1.Networks.Arbitrum) {
|
|
319
|
+
// const ETH_MIM = '0xa6e69dd0c36f3b59539e2c7afd274ef91b5c70f9';
|
|
320
|
+
// const ETH_SPELL = '0x35b44b303eacb71114aa62fe8dae6f9c5de0f680';
|
|
321
|
+
const ETH_gGOHM = '0x6d94f7e67c6ae0b0257c35754e059fdfb249d998';
|
|
322
|
+
const ETH_MAGIC = '0x88a0b00bbe918ee00e3482f71962070dc052984b';
|
|
323
|
+
const ETH_RDNT = '0xfb468ad210d427d65c9a765a480649d5754ca325';
|
|
324
|
+
// const LIZ_LIZ_ETH = '0x699c5e23357ab1bf658bd0b38070d746e37671f3';
|
|
325
|
+
// const LIZ_ETH_USDC = '0x1229aac120ae75301ab1c3a2a04ec14183493584';
|
|
326
|
+
// const LIZ_ETH_BTC = '0xce009c44e1645bc6d19c90ba440c618a42ae581d';
|
|
327
|
+
// const LIZ_LIZ_USDC = '0x463ec151258370a07431068bb3bdc98b5a6ba18f';
|
|
328
|
+
const lendingPoolsDataV2V1_1 = lendingPoolsData[types_1.Factory.V2V1_1];
|
|
329
|
+
if (lendingPoolsDataV2V1_1) {
|
|
330
|
+
if (lendingPoolsDataV2V1_1[ETH_gGOHM]) {
|
|
331
|
+
//lendingPoolsData[Factory.V2V1_1][ETH_SPELL].pair.rewards[0].rewardRate = '8.44';
|
|
332
|
+
//lendingPoolsData[Factory.V2V1_1][ETH_MIM].pair.rewards[0].rewardRate = '30.64';
|
|
333
|
+
//lendingPoolsData[Factory.V2V1_1][ETH_gGOHM].pair.rewards[0].rewardRate = '0.000009129';
|
|
334
|
+
lendingPoolsDataV2V1_1[ETH_MAGIC].pair.rewards[0].rewardRate = '0.135';
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
338
|
+
if (lendingPoolsDataV2V2) {
|
|
339
|
+
if (lendingPoolsDataV2V2[ETH_RDNT]) {
|
|
340
|
+
lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate = (parseFloat(lendingPoolsDataV2V2[ETH_RDNT].pair.rewards[0].rewardRate) / 2).toString();
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/*if (lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH]) {
|
|
344
|
+
const LIZ = lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].borrowable0.underlying;
|
|
345
|
+
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.rewards = [{
|
|
346
|
+
id: '',
|
|
347
|
+
rewardsToken: LIZ,
|
|
348
|
+
rewardRate: '3.724',
|
|
349
|
+
periodFinish: '0',
|
|
350
|
+
}];
|
|
351
|
+
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_ETH].pair.stakedTotalSupply = '40131.19426';
|
|
352
|
+
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.rewards = [{
|
|
353
|
+
id: '',
|
|
354
|
+
rewardsToken: LIZ,
|
|
355
|
+
rewardRate: '1.284',
|
|
356
|
+
periodFinish: '0',
|
|
357
|
+
}];
|
|
358
|
+
lendingPoolsData[Factory.SOLV2][LIZ_ETH_USDC].pair.stakedTotalSupply = '0.182614';
|
|
359
|
+
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.rewards = [{
|
|
360
|
+
id: '',
|
|
361
|
+
rewardsToken: LIZ,
|
|
362
|
+
rewardRate: '0.159',
|
|
363
|
+
periodFinish: '0',
|
|
364
|
+
}];
|
|
365
|
+
lendingPoolsData[Factory.SOLV2][LIZ_ETH_BTC].pair.stakedTotalSupply = '0.002468';
|
|
366
|
+
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.rewards = [{
|
|
367
|
+
id: '',
|
|
368
|
+
rewardsToken: LIZ,
|
|
369
|
+
rewardRate: '1.566',
|
|
370
|
+
periodFinish: '0',
|
|
371
|
+
}];
|
|
372
|
+
lendingPoolsData[Factory.SOLV2][LIZ_LIZ_USDC].pair.stakedTotalSupply = '0.568227';
|
|
373
|
+
}*/
|
|
374
|
+
}
|
|
375
|
+
if (this.network === types_1.Networks.Polygon) {
|
|
376
|
+
const lendingPoolsDataV2V2 = lendingPoolsData[types_1.Factory.V2V2];
|
|
377
|
+
if (lendingPoolsDataV2V2) {
|
|
378
|
+
const GNS_DAI = '0xf9221c5edc736d26ffc4ddccddfa15a4b958862e';
|
|
379
|
+
if (lendingPoolsDataV2V2[GNS_DAI]) {
|
|
380
|
+
const GNS = lendingPoolsDataV2V2[GNS_DAI].borrowable1.underlying;
|
|
381
|
+
lendingPoolsDataV2V2[GNS_DAI].pair.rewards[0] = {
|
|
382
|
+
id: '',
|
|
383
|
+
rewardsToken: GNS,
|
|
384
|
+
rewardRate: '0.00608',
|
|
385
|
+
periodFinish: '0',
|
|
386
|
+
};
|
|
387
|
+
lendingPoolsDataV2V2[GNS_DAI].pair.stakedTotalSupply = '1640000';
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (this.network === types_1.Networks.Avalanche) {
|
|
392
|
+
const lendingPoolsDataV2V1_2 = lendingPoolsData[types_1.Factory.V2V1_2];
|
|
393
|
+
if (lendingPoolsDataV2V1_2) {
|
|
394
|
+
const QI_AVAX = '0x3e2a4dcd46e0e339aec603080d90bd939a163062';
|
|
395
|
+
if (lendingPoolsDataV2V1_2[QI_AVAX]) {
|
|
396
|
+
const QI = lendingPoolsDataV2V1_2[QI_AVAX].borrowable0.underlying;
|
|
397
|
+
lendingPoolsDataV2V1_2[QI_AVAX].pair.rewards[0] = {
|
|
398
|
+
id: '',
|
|
399
|
+
rewardsToken: QI,
|
|
400
|
+
rewardRate: '4.54',
|
|
401
|
+
periodFinish: '0',
|
|
402
|
+
};
|
|
403
|
+
// TODO -> this is wrong
|
|
404
|
+
lendingPoolsDataV2V1_2[QI_AVAX].pair.stakedTotalSupply = '0.000000992210460243'; //https://snowtrace.io/token/0xe530dc2095ef5653205cf5ea79f8979a7028065c?a=0x784da19e61cf348a8c54547531795ecfee2affd1
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
/*REWARD STOPPED const sAVAX_AVAX = '0x5b588f4481035b0f765393fc9f4752615a6d0498';
|
|
408
|
+
if (lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX]) {
|
|
409
|
+
const QI = lendingPoolsData[Factory.V2V1_2][QI_AVAX].borrowable0.underlying;
|
|
410
|
+
lendingPoolsData[Factory.V2V1_2][sAVAX_AVAX].pair.rewards[1] = {
|
|
411
|
+
id: '',
|
|
412
|
+
rewardsToken: QI,
|
|
413
|
+
rewardRate: '1.74',
|
|
414
|
+
periodFinish: '0',
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
const UST_AVAX = '0xc6e68d77d0f4fa925a1cf2611dab6b10900eaf2b';
|
|
418
|
+
if (lendingPoolsData[Factory.V2V1_2][UST_AVAX]) {
|
|
419
|
+
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
420
|
+
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[0].rewardRate = '0.000099';
|
|
421
|
+
lendingPoolsData[Factory.V2V1_2][UST_AVAX].pair.rewards[2] = {
|
|
422
|
+
id: '',
|
|
423
|
+
rewardsToken: AVAX,
|
|
424
|
+
rewardRate: '0.00047',
|
|
425
|
+
periodFinish: '0',
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
const UST_USDC = '0x69c1c44e8742b66d892294a7eeb9aac51891b0eb';
|
|
429
|
+
if (lendingPoolsData[Factory.V2V1_2][UST_USDC]) {
|
|
430
|
+
const AVAX = lendingPoolsData[Factory.V2V1_2][UST_AVAX].borrowable1.underlying;
|
|
431
|
+
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[0].rewardRate = '0.000099';
|
|
432
|
+
lendingPoolsData[Factory.V2V1_2][UST_USDC].pair.rewards[2] = {
|
|
433
|
+
id: '',
|
|
434
|
+
rewardsToken: AVAX,
|
|
435
|
+
rewardRate: '0.00047',
|
|
436
|
+
periodFinish: '0',
|
|
437
|
+
};
|
|
438
|
+
}*/
|
|
439
|
+
}
|
|
440
|
+
return lendingPoolsData;
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
exports.initializeLendingPoolsData = initializeLendingPoolsData;
|
|
444
|
+
function getLendingPoolsData() {
|
|
445
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
if (!this.lendingPoolsData)
|
|
447
|
+
this.lendingPoolsData = this.initializeLendingPoolsData();
|
|
448
|
+
return this.lendingPoolsData;
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
exports.getLendingPoolsData = getLendingPoolsData;
|
|
452
|
+
function getLendingPoolData(factory, uniswapV2PairAddress) {
|
|
453
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
const lendingPoolsData = (yield this.getLendingPoolsData())[factory];
|
|
455
|
+
return lendingPoolsData[uniswapV2PairAddress.toLowerCase()];
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
exports.getLendingPoolData = getLendingPoolData;
|
|
459
|
+
// TVL Data
|
|
460
|
+
function initializeTvlData() {
|
|
461
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
462
|
+
const networks = [
|
|
463
|
+
types_1.Networks.Mainnet,
|
|
464
|
+
types_1.Networks.Arbitrum,
|
|
465
|
+
types_1.Networks.Polygon,
|
|
466
|
+
types_1.Networks.Avalanche,
|
|
467
|
+
// Networks.Moonriver,
|
|
468
|
+
types_1.Networks.Fantom,
|
|
469
|
+
// Networks.Canto,
|
|
470
|
+
types_1.Networks.ZksyncEra,
|
|
471
|
+
// Networks.Mantle,
|
|
472
|
+
types_1.Networks.Base,
|
|
473
|
+
types_1.Networks.Scroll,
|
|
474
|
+
types_1.Networks.Real,
|
|
475
|
+
types_1.Networks.Blast
|
|
476
|
+
]; // exclude ropsten
|
|
477
|
+
const calls = [];
|
|
478
|
+
for (const network of networks) {
|
|
479
|
+
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[network]) {
|
|
480
|
+
// Multiple endpoints
|
|
481
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[network][factory];
|
|
482
|
+
calls.push(this.endpointManager.fetch(subgraphs, network, (queryBuilder) => queryBuilder.tvlQuery()));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
let results;
|
|
486
|
+
try {
|
|
487
|
+
results = yield Promise.all(calls);
|
|
488
|
+
}
|
|
489
|
+
catch (e) {
|
|
490
|
+
console.log("can't initialize TVL data");
|
|
491
|
+
return {
|
|
492
|
+
crossChainTVLUSD: 0,
|
|
493
|
+
crossChainSupplyUSD: 0,
|
|
494
|
+
crossChainBorrowUSD: 0,
|
|
495
|
+
totalBalanceUSD: 0,
|
|
496
|
+
totalSupplyUSD: 0,
|
|
497
|
+
totalBorrowsUSD: 0,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
let crossChainTVLUSD = 0;
|
|
501
|
+
let crossChainSupplyUSD = 0;
|
|
502
|
+
let crossChainBorrowUSD = 0;
|
|
503
|
+
let thisChainTVLUSD = 0;
|
|
504
|
+
let thisChainSupplyUSD = 0;
|
|
505
|
+
let thisChainBorrowUSD = 0;
|
|
506
|
+
let i = 0;
|
|
507
|
+
for (const network of networks) {
|
|
508
|
+
for (const _ in subgraphs_1.IMPERMAX_SUBGRAPH_URL[network]) {
|
|
509
|
+
// Need to pluralize `impermaxFactory`
|
|
510
|
+
const data = queries_1.QueryBuilderFactory.getImpermaxFactory(results[i]);
|
|
511
|
+
if (data) {
|
|
512
|
+
crossChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
513
|
+
crossChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
514
|
+
crossChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
515
|
+
if (network === this.network) {
|
|
516
|
+
thisChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
517
|
+
thisChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
518
|
+
thisChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
i++;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (!networks.includes(this.network)) {
|
|
525
|
+
const calls = [];
|
|
526
|
+
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
527
|
+
// Multiple endpoints
|
|
528
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
529
|
+
calls.push(this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.tvlQuery()));
|
|
530
|
+
}
|
|
531
|
+
const results = yield Promise.all(calls);
|
|
532
|
+
i = 0;
|
|
533
|
+
for (const _ in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
534
|
+
// Need to pluralize `impermaxFactory`
|
|
535
|
+
const data = queries_1.QueryBuilderFactory.getImpermaxFactory(results[i]);
|
|
536
|
+
if (data) {
|
|
537
|
+
thisChainTVLUSD += parseFloat(data.totalBalanceUSD);
|
|
538
|
+
thisChainSupplyUSD += parseFloat(data.totalSupplyUSD);
|
|
539
|
+
thisChainBorrowUSD += parseFloat(data.totalBorrowsUSD);
|
|
540
|
+
}
|
|
541
|
+
i++;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
crossChainTVLUSD,
|
|
546
|
+
crossChainSupplyUSD,
|
|
547
|
+
crossChainBorrowUSD,
|
|
548
|
+
totalBalanceUSD: thisChainTVLUSD,
|
|
549
|
+
totalSupplyUSD: thisChainSupplyUSD,
|
|
550
|
+
totalBorrowsUSD: thisChainBorrowUSD,
|
|
551
|
+
};
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
exports.initializeTvlData = initializeTvlData;
|
|
555
|
+
function getTvlData() {
|
|
556
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
557
|
+
if (!this.tvlData)
|
|
558
|
+
this.tvlData = this.initializeTvlData();
|
|
559
|
+
return this.tvlData;
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
exports.getTvlData = getTvlData;
|
|
563
|
+
// User Data
|
|
564
|
+
function fetchUserData(account) {
|
|
565
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
+
const positions = {};
|
|
567
|
+
for (const factory in subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network]) {
|
|
568
|
+
const subgraphs = subgraphs_1.IMPERMAX_SUBGRAPH_URL[this.network][factory];
|
|
569
|
+
// We pass network + factory to get the actual factory address in case we use multiple factories in 1 api
|
|
570
|
+
const result = yield this.endpointManager.fetch(subgraphs, this.network, (queryBuilder) => queryBuilder.userQuery(account, this.network, factory));
|
|
571
|
+
const user = result.data.user;
|
|
572
|
+
if (!user)
|
|
573
|
+
continue;
|
|
574
|
+
positions[factory] = {
|
|
575
|
+
collateralPositions: user.collateralPositions,
|
|
576
|
+
supplyPositions: user.supplyPositions,
|
|
577
|
+
borrowPositions: user.borrowPositions,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
return positions;
|
|
581
|
+
// TODO parallelize calls
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
exports.fetchUserData = fetchUserData;
|
|
585
|
+
function initializeUserData(account) {
|
|
586
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
587
|
+
const result = {};
|
|
588
|
+
const userData = yield this.fetchUserData(account);
|
|
589
|
+
if (!userData)
|
|
590
|
+
return null;
|
|
591
|
+
let factory;
|
|
592
|
+
for (factory in userData) {
|
|
593
|
+
result[factory] = {
|
|
594
|
+
collateralPositions: {},
|
|
595
|
+
supplyPositions: {},
|
|
596
|
+
borrowPositions: {},
|
|
597
|
+
};
|
|
598
|
+
const rawUserData = userData[factory];
|
|
599
|
+
for (const collateralPosition of rawUserData.collateralPositions) {
|
|
600
|
+
const resultOfFactory = result[factory];
|
|
601
|
+
resultOfFactory.collateralPositions[collateralPosition.collateral.lendingPool.id] = collateralPosition;
|
|
602
|
+
}
|
|
603
|
+
for (const supplyPositions of rawUserData.supplyPositions) {
|
|
604
|
+
const uniswapV2PairAddress = supplyPositions.borrowable.lendingPool.id;
|
|
605
|
+
const underlyingAddress = supplyPositions.borrowable.underlying.id;
|
|
606
|
+
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
607
|
+
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
608
|
+
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
609
|
+
const resultOfFactory = result[factory];
|
|
610
|
+
if (!(uniswapV2PairAddress in resultOfFactory.supplyPositions))
|
|
611
|
+
resultOfFactory.supplyPositions[uniswapV2PairAddress] = {};
|
|
612
|
+
resultOfFactory.supplyPositions[uniswapV2PairAddress][poolTokenType] = supplyPositions;
|
|
613
|
+
}
|
|
614
|
+
for (const borrowPositions of rawUserData.borrowPositions) {
|
|
615
|
+
const uniswapV2PairAddress = borrowPositions.borrowable.lendingPool.id;
|
|
616
|
+
const underlyingAddress = borrowPositions.borrowable.underlying.id;
|
|
617
|
+
const borrowableA = (yield this.getLendingPool(factory, uniswapV2PairAddress)).getPoolToken(types_1.PoolTokenType.BorrowableA);
|
|
618
|
+
const addressA = yield borrowableA.getUnderlyingAddress();
|
|
619
|
+
const poolTokenType = underlyingAddress === addressA ? types_1.PoolTokenType.BorrowableA : types_1.PoolTokenType.BorrowableB;
|
|
620
|
+
const resultOfFactory = result[factory];
|
|
621
|
+
if (!(uniswapV2PairAddress in resultOfFactory.borrowPositions))
|
|
622
|
+
resultOfFactory.borrowPositions[uniswapV2PairAddress] = {};
|
|
623
|
+
resultOfFactory.borrowPositions[uniswapV2PairAddress][poolTokenType] = borrowPositions;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
exports.initializeUserData = initializeUserData;
|
|
630
|
+
function getUserData(account) {
|
|
631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
632
|
+
if (!(account in this.usersData))
|
|
633
|
+
this.usersData[account] = this.initializeUserData(account);
|
|
634
|
+
return this.usersData[account];
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
exports.getUserData = getUserData;
|
|
638
|
+
// IMX Staking
|
|
639
|
+
function initializeXimxData() {
|
|
640
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
641
|
+
const subgraph = subgraphs_1.XIMX_SUBGRAPH_URL;
|
|
642
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
643
|
+
const result = yield apolloFetcher(subgraph, query.ximxQuery());
|
|
644
|
+
return result.data.ximxes[0];
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
exports.initializeXimxData = initializeXimxData;
|
|
648
|
+
function getXimxData() {
|
|
649
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
650
|
+
if (!this.ximxData)
|
|
651
|
+
this.ximxData = this.initializeXimxData();
|
|
652
|
+
return this.ximxData;
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
exports.getXimxData = getXimxData;
|
|
656
|
+
/**
|
|
657
|
+
* Lending Vault
|
|
658
|
+
**/
|
|
659
|
+
function fetchLendingVaults() {
|
|
660
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
661
|
+
const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
|
|
662
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
663
|
+
const result = yield this.apolloFetcher(subgraph, query.lendingVaultsQuery([]));
|
|
664
|
+
return result.data.lendingVaults;
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
exports.fetchLendingVaults = fetchLendingVaults;
|
|
668
|
+
function initializeLendingVaultsData() {
|
|
669
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
670
|
+
const lendingVaultsData = {};
|
|
671
|
+
const lendingVaults = yield this.fetchLendingVaults();
|
|
672
|
+
// Organize lending vaults data
|
|
673
|
+
for (const lendingVault of lendingVaults) {
|
|
674
|
+
lendingVaultsData[lendingVault.id] = lendingVault;
|
|
675
|
+
}
|
|
676
|
+
// Initialize OffchainLendingVault objects
|
|
677
|
+
this.vaults = {};
|
|
678
|
+
for (const lendingVault of lendingVaults) {
|
|
679
|
+
this.vaults[lendingVault.id] =
|
|
680
|
+
new offchainVault_1.default(this, lendingVault.id);
|
|
681
|
+
}
|
|
682
|
+
return lendingVaultsData;
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
exports.initializeLendingVaultsData = initializeLendingVaultsData;
|
|
686
|
+
function getLendingVaultsData() {
|
|
687
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
688
|
+
if (!this.lendingVaultsData)
|
|
689
|
+
this.lendingVaultsData = this.initializeLendingVaultsData();
|
|
690
|
+
return this.lendingVaultsData;
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
exports.getLendingVaultsData = getLendingVaultsData;
|
|
694
|
+
function getLendingVaultData(lendingVaultAddress) {
|
|
695
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
696
|
+
const lendingVaultsData = yield this.getLendingVaultsData();
|
|
697
|
+
return lendingVaultsData[lendingVaultAddress.toLowerCase()];
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
exports.getLendingVaultData = getLendingVaultData;
|
|
701
|
+
/**
|
|
702
|
+
* Whitelist
|
|
703
|
+
*/
|
|
704
|
+
function fetchWhitelist() {
|
|
705
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
+
const subgraph = subgraphs_1.WHITELIST_SUBGRAPH_URL[this.network];
|
|
707
|
+
if (!subgraph)
|
|
708
|
+
return [];
|
|
709
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
710
|
+
if (!query.whitelistQuery)
|
|
711
|
+
return [];
|
|
712
|
+
const result = yield this.apolloFetcher(subgraph, query.whitelistQuery());
|
|
713
|
+
if (!result || !result.data.whitelistStates)
|
|
714
|
+
return [];
|
|
715
|
+
return result.data.whitelistStates;
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
exports.fetchWhitelist = fetchWhitelist;
|
|
719
|
+
function initializeWhitelistData() {
|
|
720
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
721
|
+
const whitelistData = {};
|
|
722
|
+
const whitelistPairsData = yield this.fetchWhitelist();
|
|
723
|
+
// Organize lending vaults data
|
|
724
|
+
for (const whitelistPairData of whitelistPairsData) {
|
|
725
|
+
const factory = (0, impermax_factories_1.getFactoryByAddress)(this.network, whitelistPairData.factory);
|
|
726
|
+
if (!factory)
|
|
727
|
+
continue;
|
|
728
|
+
if (!whitelistData[factory])
|
|
729
|
+
whitelistData[factory] = {};
|
|
730
|
+
const whitelistDataOfFactory = whitelistData[factory];
|
|
731
|
+
whitelistDataOfFactory[whitelistPairData.pair] = whitelistPairData.state;
|
|
732
|
+
}
|
|
733
|
+
return whitelistData;
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
exports.initializeWhitelistData = initializeWhitelistData;
|
|
737
|
+
function getWhitelistData() {
|
|
738
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
739
|
+
if (!this.whitelistData)
|
|
740
|
+
this.whitelistData = this.initializeWhitelistData();
|
|
741
|
+
return this.whitelistData;
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
exports.getWhitelistData = getWhitelistData;
|
|
745
|
+
function getWhitelistState(factory, pair) {
|
|
746
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
747
|
+
const whitelistData = yield this.getWhitelistData();
|
|
748
|
+
const whitelistDataOfFactory = whitelistData[factory];
|
|
749
|
+
if (!whitelistDataOfFactory)
|
|
750
|
+
return types_1.WhitelistState.Unlisted;
|
|
751
|
+
if (!whitelistDataOfFactory[pair.toLowerCase()])
|
|
752
|
+
return types_1.WhitelistState.Unlisted;
|
|
753
|
+
return whitelistDataOfFactory[pair.toLowerCase()];
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
exports.getWhitelistState = getWhitelistState;
|
|
757
|
+
/**
|
|
758
|
+
* User Data
|
|
759
|
+
*/
|
|
760
|
+
function fetchLendingVaultsUserData(account) {
|
|
761
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
762
|
+
const subgraph = subgraphs_1.LENDING_VAULT_SUBGRAPH_URL[this.network];
|
|
763
|
+
const query = queries_1.QueryBuilderFactory.getQuery(subgraph);
|
|
764
|
+
const result = yield this.apolloFetcher(subgraph, query.lendingVaultsUserQuery(account));
|
|
765
|
+
const user = result.data.user;
|
|
766
|
+
if (!user)
|
|
767
|
+
return null;
|
|
768
|
+
return result.data.user.positions;
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
exports.fetchLendingVaultsUserData = fetchLendingVaultsUserData;
|
|
772
|
+
function initializeLendingVaultsUserData(account) {
|
|
773
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
774
|
+
const positions = yield this.fetchLendingVaultsUserData(account);
|
|
775
|
+
if (!positions)
|
|
776
|
+
return null;
|
|
777
|
+
const result = {};
|
|
778
|
+
for (const position of positions) {
|
|
779
|
+
result[position.lendingVault.id] = position;
|
|
780
|
+
}
|
|
781
|
+
return result;
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
exports.initializeLendingVaultsUserData = initializeLendingVaultsUserData;
|
|
785
|
+
function getLendingVaultsUserData(account) {
|
|
786
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
787
|
+
if (!(account in this.lendingVaultsUsersData))
|
|
788
|
+
this.lendingVaultsUsersData[account] = this.initializeLendingVaultsUserData(account);
|
|
789
|
+
return yield this.lendingVaultsUsersData[account];
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
exports.getLendingVaultsUserData = getLendingVaultsUserData;
|