@gearbox-protocol/sdk 1.22.4 → 1.23.1
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/apy/convexAPY.d.ts +10 -10
- package/lib/apy/convexAPY.js +100 -121
- package/lib/apy/curveAPY.d.ts +3 -4
- package/lib/apy/curveAPY.js +57 -111
- package/lib/apy/index.js +4 -6
- package/lib/apy/lidoAPY.d.ts +1 -2
- package/lib/apy/lidoAPY.js +14 -62
- package/lib/apy/yearnAPY.d.ts +2 -3
- package/lib/apy/yearnAPY.js +26 -82
- package/lib/contracts/contracts.js +9 -22
- package/lib/contracts/contractsRegister.js +39 -51
- package/lib/contracts/protocols.js +10 -11
- package/lib/core/adapter.js +9 -4
- package/lib/core/assets.d.ts +6 -7
- package/lib/core/assets.js +60 -70
- package/lib/core/chains.js +30 -80
- package/lib/core/constants.d.ts +9 -10
- package/lib/core/constants.js +9 -12
- package/lib/core/creditAccount.d.ts +20 -20
- package/lib/core/creditAccount.js +123 -134
- package/lib/core/creditAccount.spec.js +50 -52
- package/lib/core/creditManager.d.ts +26 -26
- package/lib/core/creditManager.js +172 -136
- package/lib/core/creditManager.spec.js +59 -61
- package/lib/core/creditSession.d.ts +12 -13
- package/lib/core/creditSession.js +120 -77
- package/lib/core/errors.d.ts +2 -3
- package/lib/core/errors.js +11 -27
- package/lib/core/eventOrTx.js +35 -73
- package/lib/core/events.d.ts +19 -20
- package/lib/core/events.js +698 -711
- package/lib/core/operations.js +11 -5
- package/lib/core/pool/data.d.ts +29 -29
- package/lib/core/pool/data.js +153 -112
- package/lib/core/pool/operation.d.ts +1 -2
- package/lib/core/pool/operation.js +23 -35
- package/lib/core/priceOracle.d.ts +6 -6
- package/lib/core/priceOracle.js +23 -29
- package/lib/core/rewardClaimer.d.ts +3 -3
- package/lib/core/rewardClaimer.js +5 -48
- package/lib/core/rewardConvex.d.ts +1 -1
- package/lib/core/rewardConvex.js +58 -118
- package/lib/core/rewardConvex.spec.js +56 -58
- package/lib/core/strategy.d.ts +5 -6
- package/lib/core/strategy.js +67 -69
- package/lib/core/strategy.spec.js +32 -34
- package/lib/core/tokenDistributor.d.ts +1 -2
- package/lib/core/trade.d.ts +6 -6
- package/lib/core/trade.js +70 -115
- package/lib/core/transactions.d.ts +21 -22
- package/lib/core/transactions.js +285 -308
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -2
- package/lib/oracles/oracles.d.ts +1 -2
- package/lib/oracles/priceFeeds.js +2 -3
- package/lib/parsers/ERC20Parser.js +20 -38
- package/lib/parsers/abstractParser.js +33 -31
- package/lib/parsers/addressProviderParser.js +12 -30
- package/lib/parsers/airdropDistributorParser.js +12 -30
- package/lib/parsers/convexBaseRewardPoolAdapterParser.js +24 -42
- package/lib/parsers/convexBaseRewardPoolAdapterParser.spec.js +11 -11
- package/lib/parsers/convexBoosterAdapterParser.js +26 -44
- package/lib/parsers/convexBoosterAdapterParser.spec.js +10 -10
- package/lib/parsers/convextRewardPoolParser.js +12 -30
- package/lib/parsers/creditFacadeParser.js +26 -45
- package/lib/parsers/creditFacadeParser.spec.js +13 -13
- package/lib/parsers/creditManagerParser.js +12 -30
- package/lib/parsers/curveAdapterParser.js +60 -78
- package/lib/parsers/curveAdapterParser.spec.js +20 -27
- package/lib/parsers/dataCompressorParser.js +12 -30
- package/lib/parsers/lidoAdapterParser.js +15 -33
- package/lib/parsers/lidoAdapterParser.spec.js +9 -9
- package/lib/parsers/lidoOracleParser.js +12 -30
- package/lib/parsers/lidoSTETHParser.js +19 -37
- package/lib/parsers/multicallParser.js +16 -34
- package/lib/parsers/offchainOracleParser.js +13 -31
- package/lib/parsers/poolParser.js +11 -29
- package/lib/parsers/priceOracleParser.js +13 -31
- package/lib/parsers/txParser.js +86 -96
- package/lib/parsers/uniV2AdapterParser.js +35 -55
- package/lib/parsers/uniV2AdapterParser.spec.js +15 -16
- package/lib/parsers/uniV3AdapterParser.js +56 -74
- package/lib/parsers/uniV3AdapterParser.spec.js +23 -24
- package/lib/parsers/wstETHAdapterParser.js +25 -43
- package/lib/parsers/wstETHAdapterParser.spec.js +11 -11
- package/lib/parsers/yearnAdapterParser.spec.js +17 -17
- package/lib/parsers/yearnV2AdapterParser.js +25 -43
- package/lib/pathfinder/core.d.ts +3 -4
- package/lib/pathfinder/pathOptions.js +52 -101
- package/lib/pathfinder/pathOptions.spec.js +55 -57
- package/lib/pathfinder/pathfinder.d.ts +3 -3
- package/lib/pathfinder/pathfinder.js +109 -202
- package/lib/pathfinder/pathfinder.spec.js +13 -13
- package/lib/strategies/convex.js +111 -123
- package/lib/strategies/creditFacade.js +34 -37
- package/lib/strategies/curve.js +74 -80
- package/lib/strategies/lido.js +26 -32
- package/lib/strategies/uniswapV2.js +21 -24
- package/lib/strategies/uniswapV3.js +33 -36
- package/lib/strategies/yearn.js +47 -59
- package/lib/tokens/balancer.js +3 -5
- package/lib/tokens/convex.js +14 -29
- package/lib/tokens/curveLP.js +22 -28
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.js +3 -5
- package/lib/tokens/token.js +29 -35
- package/lib/tokens/tokenData.d.ts +0 -9
- package/lib/tokens/tokenData.js +17 -15
- package/lib/tokens/yearn.js +3 -5
- package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface__factory.js +9 -12
- package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface__factory.js +9 -12
- package/lib/types/factories/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACLEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACLExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IACL.sol/IACL__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactoryEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactoryGetters__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAccountFactory.sol/IAccountFactory__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAddressProvider.sol/IAddressProviderEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAddressProvider.sol/IAddressProvider__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAirdropDistributor.sol/IAirdropDistributorEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IAirdropDistributor.sol/IAirdropDistributor__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IContractsRegister.sol/IContractsRegisterEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IContractsRegister.sol/IContractsRegister__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditAccount.sol/ICrediAccountExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditAccount.sol/ICreditAccount__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfiguratorEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfiguratorExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditConfigurator.sol/ICreditConfigurator__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacadeExtended__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditFacade.sol/ICreditFacade__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2Events__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2Exceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ICreditManagerV2.sol/ICreditManagerV2__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressorExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDataCompressor.sol/IDataCompressor__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenDistributor.sol/IDegenDistributorEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenDistributor.sol/IDegenDistributor__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFTEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFTExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDegenNFT.sol/IDegenNFT__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDieselToken.sol/IDieselTokenExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IDieselToken.sol/IDieselToken__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IInterestRateModel__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeedEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeedExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/ILPPriceFeed.sol/ILPPriceFeed__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPhantomERC20__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPoolService.sol/IPoolServiceEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPoolService.sol/IPoolService__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceFeedType__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Events__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Exceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2Ext__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IPriceOracle.sol/IPriceOracleV2__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IVersion__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/IWETHGateway__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/V1/ICreditFilter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/V1/ICreditManager__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IAdapter.sol/IAdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IAdapter.sol/IAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IUniversalAdapter.sol/IUniversalAdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/adapters/IUniversalAdapter.sol/IUniversalAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/interfaces/external/IWETH__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/pool/PoolService__factory.js +27 -50
- package/lib/types/factories/@gearbox-protocol/core-v2/contracts/test/interfaces/ITokenTestSuite__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBaseRewardPool__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IBooster__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IClaimZap__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IConvexToken__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IRewards.sol/IBasicRewards__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/IRewards.sol/IRewards__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICrvDeposit__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICurveGauge__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ICurveVoteEscrow__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IDeposit__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IFeeDistro__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IMinter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IPools__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRegistry__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRewardFactory__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IRewards__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStaker__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStashFactory__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IStash__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ITokenFactory__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/ITokenMinter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IVestedEscrow__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IVoting__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/convex/Interfaces.sol/IWalletChecker__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePoolStETH__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_2.sol/ICurvePool2Assets__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_3.sol/ICurvePool3Assets__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool_4.sol/ICurvePool4Assets__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurvePool__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/curve/ICurveRegistry__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/ILidoOracle__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IstETH.sol/IstETHGetters__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IstETH.sol/IstETH__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETH.sol/IwstETHGetters__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETH.sol/IwstETH__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IwstETHGateway.sol/IwstETHGateWay__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IQuoter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV2Router01__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV2Router02__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/uniswap/IUniswapV3.sol/ISwapRouter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/integrations/yearn/IYVault__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BaseRewardPoolAdapter.sol/IConvexV1BaseRewardPoolAdapterErrors__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BaseRewardPoolAdapter.sol/IConvexV1BaseRewardPoolAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/convex/IConvexV1BoosterAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1Adapter.sol/ICurveV1AdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1Adapter.sol/ICurveV1Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_2AssetsAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_3AssetsAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/curve/ICurveV1_4AssetsAdapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1AdapterEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1AdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/ILidoV1Adapter.sol/ILidoV1Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/lido/IwstETHV1Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapPathChecker__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV2Adapter.sol/IUniswapV2AdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV2Adapter.sol/IUniswapV2Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV3Adapter.sol/IUniswapV3AdapterExceptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/uniswap/IUniswapV3Adapter.sol/IUniswapV3Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/interfaces/yearn/IYearnV2Adapter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/test/config/SupportedContracts.sol/ISupportedContracts__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/integrations-v2/contracts/test/mocks/integrations/LidoMock.sol/ILidoMockEvents__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IClosePathResolver__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IDepositor.sol/IDepositorOptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IDepositor.sol/IDepositor__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IGasPricer__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ILPWorker.sol/ILPWorkerOptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ILPWorker.sol/ILPWorker__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IPathResolver__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IRouterComponent__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IRouter__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ISwapAggregator__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/ISwapper__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWithdrawer.sol/IWithdrawerOptions__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWithdrawer.sol/IWithdrawer__factory.js +9 -12
- package/lib/types/factories/@gearbox-protocol/router/contracts/interfaces/IWrapper__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/token/ERC20/IERC20__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/token/ERC721/IERC721Receiver__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/token/ERC721/IERC721__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata__factory.js +9 -12
- package/lib/types/factories/@openzeppelin/contracts/utils/introspection/IERC165__factory.js +9 -12
- package/lib/types/factories/contracts/IGas__factory.js +9 -12
- package/lib/types/factories/contracts/IGnosisSafeSignatureValidator__factory.js +9 -12
- package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributorEvents__factory.js +9 -12
- package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributorExceptions__factory.js +9 -12
- package/lib/types/factories/contracts/ITokenDistributor.sol/ITokenDistributor__factory.js +9 -12
- package/lib/types/factories/contracts/support/IOffchainOracle__factory.js +9 -12
- package/lib/types/factories/contracts/support/MultiCall.sol/Multicall2__factory.js +27 -50
- package/lib/utils/errors.js +1 -1
- package/lib/utils/extracter.js +4 -4
- package/lib/utils/formatter.d.ts +8 -8
- package/lib/utils/formatter.js +73 -87
- package/lib/utils/loading.js +3 -3
- package/lib/utils/mappers.js +7 -34
- package/lib/utils/math.d.ts +10 -7
- package/lib/utils/math.js +22 -25
- package/lib/utils/multicall.js +32 -98
- package/lib/utils/price.d.ts +3 -4
- package/lib/utils/price.js +8 -20
- package/lib/utils/repeater.js +12 -53
- package/lib/utils/validate.js +2 -2
- package/lib/watchers/creditAccountWatcher.js +136 -237
- package/lib/watchers/creditAccountWatcher.spec.js +51 -68
- package/lib/watchers/creditManagerWatcher.js +21 -71
- package/lib/watchers/creditManagerWatcher.spec.js +20 -23
- package/package.json +2 -2
- package/lib/core/history.d.ts +0 -42
- package/lib/core/history.js +0 -2
- package/lib/core/wcOperation/abstractOperations.d.ts +0 -23
- package/lib/core/wcOperation/abstractOperations.js +0 -39
- package/lib/core/wcOperation/index.d.ts +0 -11
- package/lib/core/wcOperation/index.js +0 -30
- package/lib/core/wcOperation/operations.d.ts +0 -88
- package/lib/core/wcOperation/operations.js +0 -146
- package/lib/core/wcOperation/types.d.ts +0 -15
- package/lib/core/wcOperation/types.js +0 -2
package/lib/core/chains.js
CHANGED
|
@@ -1,46 +1,9 @@
|
|
|
1
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var _a;
|
|
39
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
3
|
exports.detectNetwork = exports.isSupportedNetwork = exports.getNetworkType = exports.CHAINS = exports.ARBITRUM_NETWORK = exports.HARDHAT_NETWORK = exports.TENDERLY_NETWORK = exports.LOCAL_NETWORK = exports.POLYGON_NETWORK = exports.OPTIMISM_NETWORK = exports.GOERLI_NETWORK = exports.MAINNET_NETWORK = void 0;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
4
|
+
const token_1 = require("../tokens/token");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
44
7
|
exports.MAINNET_NETWORK = 1;
|
|
45
8
|
exports.GOERLI_NETWORK = 5;
|
|
46
9
|
exports.OPTIMISM_NETWORK = 10;
|
|
@@ -59,15 +22,16 @@ exports.CHAINS = {
|
|
|
59
22
|
Polygon: exports.POLYGON_NETWORK,
|
|
60
23
|
Arbiturum: exports.ARBITRUM_NETWORK,
|
|
61
24
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
25
|
+
const SUPPORTED_CHAINS = {
|
|
26
|
+
[exports.CHAINS.Mainnet]: "Mainnet",
|
|
27
|
+
[exports.CHAINS.Goerli]: "Goerli",
|
|
28
|
+
[exports.CHAINS.Local]: "Mainnet",
|
|
29
|
+
[exports.CHAINS.Tenderly]: "Mainnet",
|
|
30
|
+
// [CHAINS.Optimism]: "Optimism",
|
|
31
|
+
// [CHAINS.Polygon]: "Polygon",
|
|
32
|
+
};
|
|
33
|
+
const getNetworkType = (chainId, localAs = "Mainnet") => {
|
|
34
|
+
const chainType = SUPPORTED_CHAINS[chainId];
|
|
71
35
|
if (chainId === exports.CHAINS.Local) {
|
|
72
36
|
return localAs;
|
|
73
37
|
}
|
|
@@ -77,37 +41,23 @@ var getNetworkType = function (chainId, localAs) {
|
|
|
77
41
|
throw new Error("Unsupported network");
|
|
78
42
|
};
|
|
79
43
|
exports.getNetworkType = getNetworkType;
|
|
80
|
-
|
|
44
|
+
const isSupportedNetwork = (chainId) => chainId !== undefined && !!SUPPORTED_CHAINS[chainId];
|
|
81
45
|
exports.isSupportedNetwork = isSupportedNetwork;
|
|
82
|
-
function detectNetwork(provider) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
_c.trys.push([3, 5, , 6]);
|
|
99
|
-
usdcMainnet = types_1.IERC20__factory.connect(token_1.tokenDataByNetwork.Goerli.USDC, provider);
|
|
100
|
-
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
|
|
101
|
-
case 4:
|
|
102
|
-
_c.sent();
|
|
103
|
-
return [2 /*return*/, "Goerli"];
|
|
104
|
-
case 5:
|
|
105
|
-
_b = _c.sent();
|
|
106
|
-
throw new Error("Unsupported network");
|
|
107
|
-
case 6: return [3 /*break*/, 7];
|
|
108
|
-
case 7: return [2 /*return*/];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
46
|
+
async function detectNetwork(provider) {
|
|
47
|
+
try {
|
|
48
|
+
const usdcMainnet = types_1.IERC20__factory.connect(token_1.tokenDataByNetwork.Mainnet.USDC, provider);
|
|
49
|
+
await usdcMainnet.balanceOf(constants_1.ADDRESS_0X0);
|
|
50
|
+
return "Mainnet";
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
try {
|
|
54
|
+
const usdcMainnet = types_1.IERC20__factory.connect(token_1.tokenDataByNetwork.Goerli.USDC, provider);
|
|
55
|
+
await usdcMainnet.balanceOf(constants_1.ADDRESS_0X0);
|
|
56
|
+
return "Goerli";
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
throw new Error("Unsupported network");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
112
62
|
}
|
|
113
63
|
exports.detectNetwork = detectNetwork;
|
package/lib/core/constants.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const MAX_INT: BigNumber;
|
|
1
|
+
export declare const MAX_INT: bigint;
|
|
3
2
|
export declare const RAY_DECIMALS_POW = 27;
|
|
4
|
-
export declare const RAY:
|
|
5
|
-
export declare const halfRAY:
|
|
3
|
+
export declare const RAY: bigint;
|
|
4
|
+
export declare const halfRAY: bigint;
|
|
6
5
|
export declare const WAD_DECIMALS_POW = 18;
|
|
7
|
-
export declare const WAD:
|
|
6
|
+
export declare const WAD: bigint;
|
|
8
7
|
export declare const PRICE_DECIMALS_POW = 8;
|
|
9
|
-
export declare const PRICE_DECIMALS:
|
|
8
|
+
export declare const PRICE_DECIMALS: bigint;
|
|
10
9
|
export declare const SECONDS_PER_YEAR: number;
|
|
11
10
|
export declare const MS_PER_YEAR: number;
|
|
12
|
-
export declare const PERCENTAGE_DECIMALS =
|
|
13
|
-
export declare const PERCENTAGE_FACTOR =
|
|
11
|
+
export declare const PERCENTAGE_DECIMALS = 100n;
|
|
12
|
+
export declare const PERCENTAGE_FACTOR = 10000n;
|
|
14
13
|
export declare const timeRanges: Record<string, number>;
|
|
15
|
-
export declare const LEVERAGE_DECIMALS =
|
|
16
|
-
export declare const SLIPPAGE_DECIMALS =
|
|
14
|
+
export declare const LEVERAGE_DECIMALS = 100n;
|
|
15
|
+
export declare const SLIPPAGE_DECIMALS = 100n;
|
|
17
16
|
export declare const ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
|
18
17
|
export declare const DUMB_ADDRESS = "0xC4375B7De8af5a38a93548eb8453a498222C4fF2";
|
|
19
18
|
export declare const DUMB_ADDRESS2 = "0x93548eB8453a498222C4FF2C4375b7De8af5A38a";
|
package/lib/core/constants.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DUMB_ADDRESS4 = exports.DUMB_ADDRESS3 = exports.DUMB_ADDRESS2 = exports.DUMB_ADDRESS = exports.ADDRESS_0X0 = exports.SLIPPAGE_DECIMALS = exports.LEVERAGE_DECIMALS = exports.timeRanges = exports.PERCENTAGE_FACTOR = exports.PERCENTAGE_DECIMALS = exports.MS_PER_YEAR = exports.SECONDS_PER_YEAR = exports.PRICE_DECIMALS = exports.PRICE_DECIMALS_POW = exports.WAD = exports.WAD_DECIMALS_POW = exports.halfRAY = exports.RAY = exports.RAY_DECIMALS_POW = exports.MAX_INT = void 0;
|
|
4
|
-
|
|
5
|
-
exports.MAX_INT = ethers_1.BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
4
|
+
exports.MAX_INT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
6
5
|
exports.RAY_DECIMALS_POW = 27;
|
|
7
|
-
exports.RAY =
|
|
8
|
-
exports.halfRAY = exports.RAY
|
|
6
|
+
exports.RAY = 10n ** BigInt(exports.RAY_DECIMALS_POW);
|
|
7
|
+
exports.halfRAY = exports.RAY / 2n;
|
|
9
8
|
exports.WAD_DECIMALS_POW = 18;
|
|
10
|
-
exports.WAD =
|
|
9
|
+
exports.WAD = 10n ** BigInt(exports.WAD_DECIMALS_POW);
|
|
11
10
|
exports.PRICE_DECIMALS_POW = 8;
|
|
12
|
-
exports.PRICE_DECIMALS =
|
|
11
|
+
exports.PRICE_DECIMALS = 10n ** BigInt(exports.PRICE_DECIMALS_POW);
|
|
13
12
|
exports.SECONDS_PER_YEAR = 365 * 24 * 3600;
|
|
14
13
|
exports.MS_PER_YEAR = exports.SECONDS_PER_YEAR * 1000;
|
|
15
|
-
exports.PERCENTAGE_DECIMALS =
|
|
16
|
-
exports.PERCENTAGE_FACTOR =
|
|
17
|
-
// export const LIQUIDATION_DISCOUNTED_SUM = 9600;
|
|
18
|
-
// export const UNDERLYING_TOKEN_LIQUIDATION_THRESHOLD = 9400;
|
|
14
|
+
exports.PERCENTAGE_DECIMALS = 100n;
|
|
15
|
+
exports.PERCENTAGE_FACTOR = 10000n;
|
|
19
16
|
exports.timeRanges = {
|
|
20
17
|
// "1H": 3600,
|
|
21
18
|
"1D": 3600 * 24,
|
|
@@ -23,8 +20,8 @@ exports.timeRanges = {
|
|
|
23
20
|
"1M": 3600 * 24 * 30,
|
|
24
21
|
"1Y": 3600 * 24 * 365,
|
|
25
22
|
};
|
|
26
|
-
exports.LEVERAGE_DECIMALS =
|
|
27
|
-
exports.SLIPPAGE_DECIMALS =
|
|
23
|
+
exports.LEVERAGE_DECIMALS = 100n;
|
|
24
|
+
exports.SLIPPAGE_DECIMALS = 100n;
|
|
28
25
|
exports.ADDRESS_0X0 = "0x0000000000000000000000000000000000000000";
|
|
29
26
|
// Used in tests
|
|
30
27
|
exports.DUMB_ADDRESS = "0xC4375B7De8af5a38a93548eb8453a498222C4fF2";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
1
|
import { LpTokensAPY } from "../apy";
|
|
3
2
|
import { CreditAccountDataPayload } from "../payload/creditAccount";
|
|
4
3
|
import { TokenData } from "../tokens/tokenData";
|
|
@@ -12,41 +11,42 @@ export declare class CreditAccountData {
|
|
|
12
11
|
readonly creditManager: string;
|
|
13
12
|
readonly underlyingToken: string;
|
|
14
13
|
readonly since: number;
|
|
15
|
-
readonly cumulativeIndexAtOpen:
|
|
16
|
-
readonly borrowedAmount:
|
|
17
|
-
readonly borrowedAmountPlusInterestAndFees:
|
|
18
|
-
borrowedAmountPlusInterest:
|
|
19
|
-
totalValue:
|
|
14
|
+
readonly cumulativeIndexAtOpen: bigint;
|
|
15
|
+
readonly borrowedAmount: bigint;
|
|
16
|
+
readonly borrowedAmountPlusInterestAndFees: bigint;
|
|
17
|
+
borrowedAmountPlusInterest: bigint;
|
|
18
|
+
totalValue: bigint;
|
|
20
19
|
healthFactor: number;
|
|
21
20
|
borrowRate: number;
|
|
22
21
|
readonly collateralTokens: Array<string>;
|
|
23
22
|
readonly allTokens: Array<string>;
|
|
24
|
-
balances: Record<string,
|
|
25
|
-
allBalances: Record<string,
|
|
23
|
+
balances: Record<string, bigint>;
|
|
24
|
+
allBalances: Record<string, bigint>;
|
|
26
25
|
isDeleting: boolean;
|
|
27
|
-
enabledTokenMask:
|
|
26
|
+
enabledTokenMask: bigint;
|
|
28
27
|
readonly version: number;
|
|
29
|
-
readonly repayAmount:
|
|
30
|
-
readonly liquidationAmount:
|
|
28
|
+
readonly repayAmount: bigint;
|
|
29
|
+
readonly liquidationAmount: bigint;
|
|
31
30
|
readonly canBeClosed: boolean;
|
|
32
31
|
constructor(payload: CreditAccountDataPayload);
|
|
33
|
-
balancesSorted(prices: Record<string,
|
|
34
|
-
calcBorrowAmountPlusInterestRate(currentCumulativeIndex:
|
|
35
|
-
updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex:
|
|
36
|
-
static
|
|
32
|
+
balancesSorted(prices: Record<string, bigint>, tokens: Record<string, TokenData>): Array<Asset>;
|
|
33
|
+
calcBorrowAmountPlusInterestRate(currentCumulativeIndex: bigint): bigint;
|
|
34
|
+
updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex: bigint, priceOracle: PriceOracleData): void;
|
|
35
|
+
static isTokenEnabled(index: number, enabledTokenMask: bigint): boolean;
|
|
36
|
+
static calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: bigint, maxLeverageFactor: number, underlyingLT: number, minHf?: bigint): bigint;
|
|
37
37
|
get id(): string;
|
|
38
38
|
hash(): string;
|
|
39
39
|
static hash(creditManager: string, borrower: string): string;
|
|
40
40
|
}
|
|
41
|
-
export declare function sortBalances(balances: Record<string,
|
|
41
|
+
export declare function sortBalances(balances: Record<string, bigint>, prices: Record<string, bigint>, tokens: Record<string, TokenData>): Array<[string, bigint]>;
|
|
42
42
|
export declare function tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
|
|
43
|
-
export declare function amountAbcComparator(t1:
|
|
43
|
+
export declare function amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
|
|
44
44
|
export interface CalcOverallAPYProps {
|
|
45
45
|
caAssets: Array<Asset>;
|
|
46
46
|
lpAPY: LpTokensAPY | undefined;
|
|
47
|
-
prices: Record<string,
|
|
48
|
-
totalValue:
|
|
49
|
-
debt:
|
|
47
|
+
prices: Record<string, bigint>;
|
|
48
|
+
totalValue: bigint | undefined;
|
|
49
|
+
debt: bigint | undefined;
|
|
50
50
|
borrowRate: number;
|
|
51
51
|
underlyingToken: string;
|
|
52
52
|
}
|
|
@@ -1,124 +1,121 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calcOverallAPY = exports.amountAbcComparator = exports.tokensAbcComparator = exports.sortBalances = exports.CreditAccountData = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
const apy_1 = require("../apy");
|
|
5
|
+
const decimals_1 = require("../tokens/decimals");
|
|
6
|
+
const token_1 = require("../tokens/token");
|
|
7
|
+
const formatter_1 = require("../utils/formatter");
|
|
8
|
+
const price_1 = require("../utils/price");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
class CreditAccountData {
|
|
11
|
+
addr;
|
|
12
|
+
borrower;
|
|
13
|
+
inUse;
|
|
14
|
+
creditManager;
|
|
15
|
+
underlyingToken;
|
|
16
|
+
since;
|
|
17
|
+
cumulativeIndexAtOpen;
|
|
18
|
+
borrowedAmount;
|
|
19
|
+
borrowedAmountPlusInterestAndFees;
|
|
20
|
+
borrowedAmountPlusInterest;
|
|
21
|
+
totalValue;
|
|
22
|
+
healthFactor;
|
|
23
|
+
borrowRate;
|
|
24
|
+
collateralTokens = [];
|
|
25
|
+
allTokens = [];
|
|
26
|
+
balances = {};
|
|
27
|
+
allBalances = {};
|
|
28
|
+
isDeleting;
|
|
29
|
+
enabledTokenMask;
|
|
30
|
+
version = 1;
|
|
31
|
+
/// V1 Artifacts
|
|
32
|
+
repayAmount;
|
|
33
|
+
liquidationAmount;
|
|
34
|
+
canBeClosed;
|
|
35
|
+
constructor(payload) {
|
|
19
36
|
this.addr = payload.addr.toLowerCase();
|
|
20
37
|
this.borrower = payload.borrower.toLowerCase();
|
|
21
38
|
this.inUse = payload.inUse;
|
|
22
39
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
23
40
|
this.underlyingToken = payload.underlying.toLowerCase();
|
|
24
|
-
this.since =
|
|
25
|
-
this.cumulativeIndexAtOpen = payload.cumulativeIndexAtOpen;
|
|
26
|
-
this.borrowedAmount = payload.borrowedAmount;
|
|
27
|
-
this.borrowedAmountPlusInterest = payload.borrowedAmountPlusInterest;
|
|
28
|
-
this.borrowedAmountPlusInterestAndFees =
|
|
29
|
-
|
|
30
|
-
this.totalValue = payload.totalValue;
|
|
41
|
+
this.since = Number((0, formatter_1.toBigInt)(payload.since || 0));
|
|
42
|
+
this.cumulativeIndexAtOpen = (0, formatter_1.toBigInt)(payload.cumulativeIndexAtOpen || 0);
|
|
43
|
+
this.borrowedAmount = (0, formatter_1.toBigInt)(payload.borrowedAmount || 0);
|
|
44
|
+
this.borrowedAmountPlusInterest = (0, formatter_1.toBigInt)(payload.borrowedAmountPlusInterest || 0);
|
|
45
|
+
this.borrowedAmountPlusInterestAndFees = (0, formatter_1.toBigInt)(payload.borrowedAmountPlusInterestAndFees || 0);
|
|
46
|
+
this.totalValue = (0, formatter_1.toBigInt)(payload.totalValue || 0);
|
|
31
47
|
this.healthFactor = payload.healthFactor.toNumber();
|
|
32
|
-
this.borrowRate = payload.borrowRate
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var tokenLC = b.token.toLowerCase();
|
|
48
|
+
this.borrowRate = Number(((0, formatter_1.toBigInt)(payload.borrowRate || 0) *
|
|
49
|
+
constants_1.PERCENTAGE_FACTOR *
|
|
50
|
+
constants_1.PERCENTAGE_DECIMALS) /
|
|
51
|
+
constants_1.RAY);
|
|
52
|
+
payload.balances.forEach(b => {
|
|
53
|
+
const tokenLC = b.token.toLowerCase();
|
|
39
54
|
if (b.isAllowed) {
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
this.balances[tokenLC] = (0, formatter_1.toBigInt)(b.balance || 0);
|
|
56
|
+
this.collateralTokens.push(tokenLC);
|
|
42
57
|
}
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
this.allBalances[tokenLC] = (0, formatter_1.toBigInt)(b.balance || 0);
|
|
59
|
+
this.allTokens.push(tokenLC);
|
|
45
60
|
});
|
|
46
|
-
this.enabledTokenMask = payload.enabledTokenMask;
|
|
61
|
+
this.enabledTokenMask = (0, formatter_1.toBigInt)(payload.enabledTokenMask || 0);
|
|
47
62
|
this.isDeleting = false;
|
|
48
63
|
this.version = payload.version;
|
|
49
|
-
this.repayAmount = payload.repayAmount;
|
|
50
|
-
this.liquidationAmount = payload.liquidationAmount;
|
|
64
|
+
this.repayAmount = (0, formatter_1.toBigInt)(payload.repayAmount || 0);
|
|
65
|
+
this.liquidationAmount = (0, formatter_1.toBigInt)(payload.liquidationAmount || 0);
|
|
51
66
|
this.canBeClosed = payload.canBeClosed;
|
|
52
67
|
}
|
|
53
|
-
|
|
54
|
-
return sortBalances(this.balances, prices, tokens).map(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.reduce(function (a, b) { return a.add(b); });
|
|
76
|
-
this.healthFactor = priceOracle
|
|
77
|
-
.convertFromUSD(twvUSDValue, this.underlyingToken)
|
|
78
|
-
.div(this.calcBorrowAmountPlusInterestRate(currentCumulativeIndex))
|
|
79
|
-
.toNumber();
|
|
80
|
-
};
|
|
81
|
-
CreditAccountData.calcMaxIncreaseBorrow = function (healthFactor, borrowAmountPlusInterest, maxLeverageFactor, underlyingLT, minHf) {
|
|
82
|
-
if (minHf === void 0) { minHf = constants_1.PERCENTAGE_FACTOR; }
|
|
83
|
-
var minHealthFactor = maxLeverageFactor > 0
|
|
84
|
-
? Math.floor((underlyingLT * (maxLeverageFactor + constants_1.LEVERAGE_DECIMALS)) /
|
|
68
|
+
balancesSorted(prices, tokens) {
|
|
69
|
+
return sortBalances(this.balances, prices, tokens).map(([token, balance]) => ({ token, balance }));
|
|
70
|
+
}
|
|
71
|
+
calcBorrowAmountPlusInterestRate(currentCumulativeIndex) {
|
|
72
|
+
return ((this.borrowedAmount * currentCumulativeIndex) /
|
|
73
|
+
this.cumulativeIndexAtOpen);
|
|
74
|
+
}
|
|
75
|
+
updateHealthFactor(creditManager, currentCumulativeIndex, priceOracle) {
|
|
76
|
+
const twvUSDValue = this.collateralTokens
|
|
77
|
+
.filter((_, num) => CreditAccountData.isTokenEnabled(num, this.enabledTokenMask))
|
|
78
|
+
.map(token => priceOracle.convertToUSD(this.balances[token], token) *
|
|
79
|
+
creditManager.liquidationThresholds[token])
|
|
80
|
+
.reduce((a, b) => a + b);
|
|
81
|
+
this.healthFactor = Number(priceOracle.convertFromUSD(twvUSDValue, this.underlyingToken) /
|
|
82
|
+
this.calcBorrowAmountPlusInterestRate(currentCumulativeIndex));
|
|
83
|
+
}
|
|
84
|
+
static isTokenEnabled(index, enabledTokenMask) {
|
|
85
|
+
return ((2n ** BigInt(index)) & enabledTokenMask) !== 0n;
|
|
86
|
+
}
|
|
87
|
+
static calcMaxIncreaseBorrow(healthFactor, borrowAmountPlusInterest, maxLeverageFactor, underlyingLT, minHf = constants_1.PERCENTAGE_FACTOR) {
|
|
88
|
+
const minHealthFactor = maxLeverageFactor > 0
|
|
89
|
+
? Math.floor((underlyingLT * (maxLeverageFactor + Number(constants_1.LEVERAGE_DECIMALS))) /
|
|
85
90
|
maxLeverageFactor)
|
|
86
|
-
: minHf;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
},
|
|
96
|
-
enumerable: false,
|
|
97
|
-
configurable: true
|
|
98
|
-
});
|
|
99
|
-
CreditAccountData.prototype.hash = function () {
|
|
91
|
+
: Number(minHf);
|
|
92
|
+
const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHealthFactor)) /
|
|
93
|
+
BigInt(minHealthFactor - underlyingLT);
|
|
94
|
+
return result < 0 ? 0n : result;
|
|
95
|
+
}
|
|
96
|
+
get id() {
|
|
97
|
+
return this.creditManager;
|
|
98
|
+
}
|
|
99
|
+
hash() {
|
|
100
100
|
return CreditAccountData.hash(this.creditManager, this.borrower);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}());
|
|
101
|
+
}
|
|
102
|
+
static hash(creditManager, borrower) {
|
|
103
|
+
return `${creditManager.toLowerCase()}:${borrower.toLowerCase()}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
107
106
|
exports.CreditAccountData = CreditAccountData;
|
|
108
107
|
function sortBalances(balances, prices, tokens) {
|
|
109
|
-
return Object.entries(balances).sort(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (totalPrice1.eq(totalPrice2)) {
|
|
121
|
-
return amount1.eq(amount2)
|
|
108
|
+
return Object.entries(balances).sort(([addr1, amount1], [addr2, amount2]) => {
|
|
109
|
+
const addr1Lc = addr1.toLowerCase();
|
|
110
|
+
const addr2Lc = addr2.toLowerCase();
|
|
111
|
+
const token1 = tokens[addr1Lc];
|
|
112
|
+
const token2 = tokens[addr2Lc];
|
|
113
|
+
const price1 = prices[addr1Lc] || constants_1.PRICE_DECIMALS;
|
|
114
|
+
const price2 = prices[addr2Lc] || constants_1.PRICE_DECIMALS;
|
|
115
|
+
const totalPrice1 = (0, price_1.calcTotalPrice)(price1, amount1, token1?.decimals);
|
|
116
|
+
const totalPrice2 = (0, price_1.calcTotalPrice)(price2, amount2, token2?.decimals);
|
|
117
|
+
if (totalPrice1 === totalPrice2) {
|
|
118
|
+
return amount1 === amount2
|
|
122
119
|
? tokensAbcComparator(token1, token2)
|
|
123
120
|
: amountAbcComparator(amount1, amount2);
|
|
124
121
|
}
|
|
@@ -127,51 +124,43 @@ function sortBalances(balances, prices, tokens) {
|
|
|
127
124
|
}
|
|
128
125
|
exports.sortBalances = sortBalances;
|
|
129
126
|
function tokensAbcComparator(t1, t2) {
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
const { symbol: symbol1 = "" } = t1 || {};
|
|
128
|
+
const { symbol: symbol2 = "" } = t2 || {};
|
|
132
129
|
return symbol1 > symbol2 ? 1 : -1;
|
|
133
130
|
}
|
|
134
131
|
exports.tokensAbcComparator = tokensAbcComparator;
|
|
135
132
|
function amountAbcComparator(t1, t2) {
|
|
136
|
-
return t1
|
|
133
|
+
return t1 > t2 ? -1 : 1;
|
|
137
134
|
}
|
|
138
135
|
exports.amountAbcComparator = amountAbcComparator;
|
|
139
|
-
function calcOverallAPY(
|
|
140
|
-
|
|
141
|
-
if (!lpAPY ||
|
|
142
|
-
!totalValue ||
|
|
143
|
-
totalValue.lte(0) ||
|
|
144
|
-
!debt ||
|
|
145
|
-
totalValue.lte(debt))
|
|
136
|
+
function calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }) {
|
|
137
|
+
if (!lpAPY || !totalValue || totalValue <= 0n || !debt || totalValue <= debt)
|
|
146
138
|
return undefined;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var symbol = token_1.tokenSymbolByAddress[tokenAddressLC];
|
|
139
|
+
const assetAPYMoney = caAssets.reduce((acc, { token: tokenAddress, balance: amount }) => {
|
|
140
|
+
const tokenAddressLC = tokenAddress.toLowerCase();
|
|
141
|
+
const symbol = token_1.tokenSymbolByAddress[tokenAddressLC];
|
|
151
142
|
if (!(0, apy_1.isTokenWithAPY)(symbol))
|
|
152
143
|
return acc;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return acc
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
144
|
+
const apy = lpAPY[symbol] || 0;
|
|
145
|
+
const price = prices[tokenAddressLC] || 0n;
|
|
146
|
+
const tokenDecimals = decimals_1.decimals[symbol];
|
|
147
|
+
const money = (0, price_1.calcTotalPrice)(price, amount, tokenDecimals);
|
|
148
|
+
const apyMoney = money * BigInt(apy);
|
|
149
|
+
return acc + apyMoney;
|
|
150
|
+
}, 0n);
|
|
151
|
+
const underlyingTokenAddressLC = underlyingToken.toLowerCase();
|
|
152
|
+
const underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC] || "";
|
|
153
|
+
const underlyingTokenDecimals = decimals_1.decimals[underlyingTokenSymbol] || 18;
|
|
154
|
+
const underlyingPrice = prices[underlyingTokenAddressLC] || constants_1.PRICE_DECIMALS;
|
|
155
|
+
const assetAPYAmountInUnderlying = (0, price_1.convertByPrice)(assetAPYMoney, {
|
|
165
156
|
price: underlyingPrice,
|
|
166
157
|
decimals: underlyingTokenDecimals,
|
|
167
158
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
.div(yourAssets)
|
|
174
|
-
.div(constants_1.PERCENTAGE_FACTOR);
|
|
159
|
+
const debtAPY = debt * BigInt(borrowRate);
|
|
160
|
+
const yourAssets = totalValue - debt;
|
|
161
|
+
const apyInPercent = ((assetAPYAmountInUnderlying - debtAPY) * constants_1.WAD) /
|
|
162
|
+
yourAssets /
|
|
163
|
+
constants_1.PERCENTAGE_FACTOR;
|
|
175
164
|
return Number((0, formatter_1.toSignificant)(apyInPercent, constants_1.WAD_DECIMALS_POW));
|
|
176
165
|
}
|
|
177
166
|
exports.calcOverallAPY = calcOverallAPY;
|