@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/strategy.js
CHANGED
|
@@ -1,93 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Strategy = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const decimals_1 = require("../tokens/decimals");
|
|
5
|
+
const token_1 = require("../tokens/token");
|
|
6
|
+
const price_1 = require("../utils/price");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
class Strategy {
|
|
9
|
+
apy;
|
|
10
|
+
name;
|
|
11
|
+
lpToken;
|
|
12
|
+
pools;
|
|
13
|
+
unleveragableCollateral;
|
|
14
|
+
leveragableCollateral;
|
|
15
|
+
baseAssets;
|
|
16
|
+
constructor(payload) {
|
|
11
17
|
this.apy = payload.apy;
|
|
12
18
|
this.name = payload.name;
|
|
13
19
|
this.lpToken = payload.lpToken.toLowerCase();
|
|
14
|
-
this.pools = payload.pools.map(
|
|
15
|
-
this.unleveragableCollateral = payload.unleveragableCollateral.map(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.leveragableCollateral = payload.leveragableCollateral.map(function (addr) {
|
|
19
|
-
return addr.toLowerCase();
|
|
20
|
-
});
|
|
21
|
-
this.baseAssets = payload.baseAssets.map(function (addr) { return addr.toLowerCase(); });
|
|
20
|
+
this.pools = payload.pools.map(addr => addr.toLowerCase());
|
|
21
|
+
this.unleveragableCollateral = payload.unleveragableCollateral.map(addr => addr.toLowerCase());
|
|
22
|
+
this.leveragableCollateral = payload.leveragableCollateral.map(addr => addr.toLowerCase());
|
|
23
|
+
this.baseAssets = payload.baseAssets.map(addr => addr.toLowerCase());
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return maxLeverage
|
|
28
|
-
}
|
|
29
|
-
|
|
25
|
+
static maxLeverage(lpToken, cms) {
|
|
26
|
+
const [maxThreshold] = maxLeverageThreshold(lpToken, cms);
|
|
27
|
+
const maxLeverage = (constants_1.PERCENTAGE_FACTOR * constants_1.LEVERAGE_DECIMALS) /
|
|
28
|
+
(constants_1.PERCENTAGE_FACTOR - maxThreshold);
|
|
29
|
+
return Number(maxLeverage - constants_1.LEVERAGE_DECIMALS);
|
|
30
|
+
}
|
|
31
|
+
maxAPY(baseAPY, maxLeverage, borrowAPY) {
|
|
30
32
|
return (baseAPY +
|
|
31
|
-
((baseAPY - borrowAPY) * (maxLeverage - constants_1.LEVERAGE_DECIMALS)) /
|
|
32
|
-
constants_1.LEVERAGE_DECIMALS);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return roi(apy, farmLev, leverage - constants_1.LEVERAGE_DECIMALS, borrowAPY);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return lqPrice.gte(0) ? lqPrice : ethers_1.BigNumber.from(0);
|
|
33
|
+
((baseAPY - borrowAPY) * (maxLeverage - Number(constants_1.LEVERAGE_DECIMALS))) /
|
|
34
|
+
Number(constants_1.LEVERAGE_DECIMALS));
|
|
35
|
+
}
|
|
36
|
+
overallAPY(apy, leverage, depositCollateral, borrowAPY) {
|
|
37
|
+
const farmLev = this.farmLev(leverage, depositCollateral);
|
|
38
|
+
return roi(apy, farmLev, leverage - Number(constants_1.LEVERAGE_DECIMALS), borrowAPY);
|
|
39
|
+
}
|
|
40
|
+
static liquidationPrice({ prices, liquidationThresholds, borrowed, underlyingToken, lpAmount, lpToken, }) {
|
|
41
|
+
const underlyingTokenAddressLC = underlyingToken.toLowerCase();
|
|
42
|
+
const underlyingTokenSymbol = token_1.tokenSymbolByAddress[underlyingTokenAddressLC];
|
|
43
|
+
const underlyingTokenDecimals = decimals_1.decimals[underlyingTokenSymbol];
|
|
44
|
+
const underlyingPrice = prices[underlyingTokenAddressLC] || constants_1.PRICE_DECIMALS;
|
|
45
|
+
const borrowedMoney = (0, price_1.calcTotalPrice)(underlyingPrice, borrowed, underlyingTokenDecimals);
|
|
46
|
+
const lpTokenAddressLC = lpToken.toLowerCase();
|
|
47
|
+
const lpTokenSymbol = token_1.tokenSymbolByAddress[lpTokenAddressLC];
|
|
48
|
+
const lpTokenDecimals = decimals_1.decimals[lpTokenSymbol];
|
|
49
|
+
const lpLT = liquidationThresholds[lpTokenAddressLC] || 0n;
|
|
50
|
+
const lpPrice = prices[lpTokenAddressLC] || constants_1.PRICE_DECIMALS;
|
|
51
|
+
const lpMoney = (0, price_1.calcTotalPrice)(lpPrice, lpAmount, lpTokenDecimals);
|
|
52
|
+
const lpLTMoney = (lpMoney * lpLT) / constants_1.PERCENTAGE_FACTOR;
|
|
53
|
+
if (lpLTMoney > 0) {
|
|
54
|
+
const lqPrice = (borrowedMoney * constants_1.WAD) / lpLTMoney;
|
|
55
|
+
return lqPrice >= 0 ? lqPrice : 0n;
|
|
55
56
|
}
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
|
|
57
|
+
return 0n;
|
|
58
|
+
}
|
|
59
|
+
farmLev(leverage, depositCollateral) {
|
|
59
60
|
return this.inBaseAssets(depositCollateral) ||
|
|
60
61
|
this.inLeveragableAssets(depositCollateral)
|
|
61
62
|
? leverage
|
|
62
|
-
: leverage - constants_1.LEVERAGE_DECIMALS;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return this.baseAssets.some(
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return this.leveragableCollateral.some(
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}());
|
|
63
|
+
: leverage - Number(constants_1.LEVERAGE_DECIMALS);
|
|
64
|
+
}
|
|
65
|
+
inBaseAssets(depositCollateral) {
|
|
66
|
+
return this.baseAssets.some(c => c === depositCollateral.toLowerCase());
|
|
67
|
+
}
|
|
68
|
+
inLeveragableAssets(depositCollateral) {
|
|
69
|
+
return this.leveragableCollateral.some(c => c === depositCollateral.toLowerCase());
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
72
|
exports.Strategy = Strategy;
|
|
73
73
|
function roi(apy, farmLev, debtLev, borrowAPY) {
|
|
74
|
-
return (apy * farmLev - borrowAPY * debtLev) / constants_1.LEVERAGE_DECIMALS;
|
|
74
|
+
return (apy * farmLev - borrowAPY * debtLev) / Number(constants_1.LEVERAGE_DECIMALS);
|
|
75
75
|
}
|
|
76
76
|
function maxLeverageThreshold(lpToken, cms) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
const lpTokenLC = lpToken.toLowerCase();
|
|
78
|
+
const ltByCM = cms.map(cm => {
|
|
79
|
+
const lt = cm.liquidationThresholds[lpTokenLC] || 0n;
|
|
80
80
|
return [cm.address, lt];
|
|
81
81
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
var ltB = _b[1];
|
|
85
|
-
if (ltA.gt(ltB))
|
|
82
|
+
const sorted = ltByCM.sort(([, ltA], [, ltB]) => {
|
|
83
|
+
if (ltA > ltB)
|
|
86
84
|
return 1;
|
|
87
|
-
if (ltB
|
|
85
|
+
if (ltB > ltA)
|
|
88
86
|
return -1;
|
|
89
87
|
return 0;
|
|
90
88
|
});
|
|
91
|
-
|
|
89
|
+
const [cm = "", lt = 0n] = sorted[0] || [];
|
|
92
90
|
return [lt, cm];
|
|
93
91
|
}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var lidoPayload = {
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const decimals_1 = require("../tokens/decimals");
|
|
5
|
+
const token_1 = require("../tokens/token");
|
|
6
|
+
const formatter_1 = require("../utils/formatter");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const strategy_1 = require("./strategy");
|
|
9
|
+
const lidoPayload = {
|
|
12
10
|
name: "Lido",
|
|
13
11
|
lpToken: token_1.tokenDataByNetwork.Mainnet.STETH,
|
|
14
12
|
apy: 38434,
|
|
@@ -21,8 +19,8 @@ var lidoPayload = {
|
|
|
21
19
|
leveragableCollateral: [],
|
|
22
20
|
baseAssets: [token_1.tokenDataByNetwork.Mainnet.WETH],
|
|
23
21
|
};
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const lidoStrategy = new strategy_1.Strategy(lidoPayload);
|
|
23
|
+
const pools = {
|
|
26
24
|
"0x1": {
|
|
27
25
|
borrowRate: 27543,
|
|
28
26
|
},
|
|
@@ -30,29 +28,29 @@ var pools = {
|
|
|
30
28
|
borrowRate: 5736,
|
|
31
29
|
},
|
|
32
30
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
describe("Strategy test",
|
|
44
|
-
it("maxAPY calculation is correct",
|
|
45
|
-
|
|
31
|
+
const prices = {
|
|
32
|
+
[token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: (0, formatter_1.toBN)("1738.11830000", constants_1.PRICE_DECIMALS_POW),
|
|
33
|
+
[token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: (0, formatter_1.toBN)("0.99941103", constants_1.PRICE_DECIMALS_POW),
|
|
34
|
+
[token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()]: (0, formatter_1.toBN)("1703.87588096", constants_1.PRICE_DECIMALS_POW),
|
|
35
|
+
};
|
|
36
|
+
const liquidationThresholds = {
|
|
37
|
+
[token_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: 9300n,
|
|
38
|
+
[token_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: 8500n,
|
|
39
|
+
[token_1.tokenDataByNetwork.Mainnet.STETH.toLowerCase()]: 9000n,
|
|
40
|
+
};
|
|
41
|
+
describe("Strategy test", () => {
|
|
42
|
+
it("maxAPY calculation is correct", () => {
|
|
43
|
+
const result = lidoStrategy.maxAPY(53203, 10 * Number(constants_1.LEVERAGE_DECIMALS), pools["0x1"].borrowRate);
|
|
46
44
|
(0, chai_1.expect)(result).to.be.eq(284143);
|
|
47
45
|
});
|
|
48
|
-
it("overallAPY calculation is correct",
|
|
49
|
-
|
|
46
|
+
it("overallAPY calculation is correct", () => {
|
|
47
|
+
const result = lidoStrategy.overallAPY(lidoStrategy.apy || 0, 10 * Number(constants_1.LEVERAGE_DECIMALS), token_1.tokenDataByNetwork.Mainnet.WETH, pools["0x2"].borrowRate);
|
|
50
48
|
(0, chai_1.expect)(result).to.be.eq(332716);
|
|
51
49
|
});
|
|
52
|
-
it("liquidationPrice calculation is correct",
|
|
53
|
-
|
|
54
|
-
liquidationThresholds
|
|
55
|
-
prices
|
|
50
|
+
it("liquidationPrice calculation is correct", () => {
|
|
51
|
+
const result = strategy_1.Strategy.liquidationPrice({
|
|
52
|
+
liquidationThresholds,
|
|
53
|
+
prices,
|
|
56
54
|
borrowed: (0, formatter_1.toBN)("350", decimals_1.decimals.WETH),
|
|
57
55
|
underlyingToken: token_1.tokenDataByNetwork.Mainnet.WETH,
|
|
58
56
|
lpAmount: (0, formatter_1.toBN)("400", decimals_1.decimals.STETH),
|
|
@@ -60,10 +58,10 @@ describe("Strategy test", function () {
|
|
|
60
58
|
});
|
|
61
59
|
(0, chai_1.expect)(Number((0, formatter_1.toSignificant)(result, constants_1.WAD_DECIMALS_POW)).toFixed(3)).to.be.eq("0.992");
|
|
62
60
|
});
|
|
63
|
-
it("maxLeverage is correct",
|
|
64
|
-
|
|
65
|
-
{ address: "0x1", liquidationThresholds
|
|
61
|
+
it("maxLeverage is correct", () => {
|
|
62
|
+
const result = strategy_1.Strategy.maxLeverage(token_1.tokenDataByNetwork.Mainnet.STETH, [
|
|
63
|
+
{ address: "0x1", liquidationThresholds },
|
|
66
64
|
]);
|
|
67
|
-
(0, chai_1.expect)(result).to.be.eq(9 * constants_1.LEVERAGE_DECIMALS);
|
|
65
|
+
(0, chai_1.expect)(result).to.be.eq(9 * Number(constants_1.LEVERAGE_DECIMALS));
|
|
68
66
|
});
|
|
69
67
|
});
|
package/lib/core/trade.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Signer } from "ethers";
|
|
2
2
|
import { AdapterInterface } from "../contracts/adapters";
|
|
3
3
|
import { MultiCall, PathFinderResult, SwapOperation } from "../pathfinder/core";
|
|
4
4
|
import { ICreditFacade } from "../types";
|
|
@@ -6,8 +6,8 @@ import { BaseAdapter } from "./adapter";
|
|
|
6
6
|
import { EVMTx } from "./eventOrTx";
|
|
7
7
|
interface BaseTradeInterface {
|
|
8
8
|
swapType: SwapOperation;
|
|
9
|
-
sourceAmount:
|
|
10
|
-
expectedAmount:
|
|
9
|
+
sourceAmount: bigint;
|
|
10
|
+
expectedAmount: bigint;
|
|
11
11
|
tokenFrom: string;
|
|
12
12
|
tokenTo: string;
|
|
13
13
|
operationName: TradeOperations;
|
|
@@ -23,9 +23,9 @@ export declare class Trade implements BaseTradeInterface {
|
|
|
23
23
|
readonly tradePath: PathFinderResult;
|
|
24
24
|
readonly creditFacade: string;
|
|
25
25
|
readonly swapType: SwapOperation;
|
|
26
|
-
readonly sourceAmount:
|
|
27
|
-
readonly expectedAmount:
|
|
28
|
-
readonly rate:
|
|
26
|
+
readonly sourceAmount: bigint;
|
|
27
|
+
readonly expectedAmount: bigint;
|
|
28
|
+
readonly rate: bigint;
|
|
29
29
|
readonly tokenFrom: string;
|
|
30
30
|
readonly tokenTo: string;
|
|
31
31
|
readonly operationName: TradeOperations;
|
package/lib/core/trade.js
CHANGED
|
@@ -1,122 +1,87 @@
|
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.Trade = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
4
|
+
const decimals_1 = require("../tokens/decimals");
|
|
5
|
+
const token_1 = require("../tokens/token");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const formatter_1 = require("../utils/formatter");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const transactions_1 = require("./transactions");
|
|
10
|
+
const OPERATION_NAMES = {
|
|
47
11
|
farmWithdraw: "Farm withdraw",
|
|
48
12
|
farmDeposit: "Farm deposit",
|
|
49
13
|
swap: "Swap",
|
|
50
14
|
unknownOperation: "Unknown operation",
|
|
51
15
|
};
|
|
52
|
-
|
|
53
|
-
|
|
16
|
+
class Trade {
|
|
17
|
+
helper;
|
|
18
|
+
tradePath;
|
|
19
|
+
creditFacade;
|
|
20
|
+
swapType;
|
|
21
|
+
sourceAmount;
|
|
22
|
+
expectedAmount;
|
|
23
|
+
rate;
|
|
24
|
+
tokenFrom;
|
|
25
|
+
tokenTo;
|
|
26
|
+
operationName;
|
|
27
|
+
constructor(props) {
|
|
54
28
|
this.helper = props.adapter;
|
|
55
29
|
this.tradePath = props.tradePath;
|
|
56
30
|
this.creditFacade = props.creditFacade;
|
|
57
31
|
this.swapType = props.swapType;
|
|
58
32
|
this.sourceAmount = props.sourceAmount;
|
|
59
33
|
this.expectedAmount = props.expectedAmount;
|
|
60
|
-
this.rate = constants_1.WAD
|
|
34
|
+
this.rate = (constants_1.WAD * props.expectedAmount) / props.sourceAmount;
|
|
61
35
|
this.tokenFrom = props.tokenFrom;
|
|
62
36
|
this.tokenTo = props.tokenTo;
|
|
63
37
|
this.operationName = props.operationName;
|
|
64
38
|
}
|
|
65
|
-
|
|
39
|
+
getName() {
|
|
66
40
|
return this.helper.name;
|
|
67
|
-
}
|
|
68
|
-
|
|
41
|
+
}
|
|
42
|
+
getAdapterInterface() {
|
|
69
43
|
return this.helper.adapterInterface;
|
|
70
|
-
}
|
|
71
|
-
|
|
44
|
+
}
|
|
45
|
+
getContractAddress() {
|
|
72
46
|
return this.helper.contractAddress;
|
|
73
|
-
}
|
|
74
|
-
|
|
47
|
+
}
|
|
48
|
+
getAdapterAddress() {
|
|
75
49
|
return this.helper.adapterAddress;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
amountFrom: this.sourceAmount,
|
|
90
|
-
amountTo: this.expectedAmount,
|
|
91
|
-
tokenFrom: this.tokenFrom,
|
|
92
|
-
tokenTo: this.tokenTo,
|
|
93
|
-
creditManager: this.helper.creditManager,
|
|
94
|
-
timestamp: 0,
|
|
95
|
-
})];
|
|
96
|
-
}
|
|
97
|
-
});
|
|
50
|
+
}
|
|
51
|
+
async execute(signer) {
|
|
52
|
+
const receipt = await Trade.executeMulticallPath(this.creditFacade, signer, this.tradePath.calls);
|
|
53
|
+
return new transactions_1.TXSwap({
|
|
54
|
+
txHash: receipt.hash,
|
|
55
|
+
protocol: this.helper.contractAddress,
|
|
56
|
+
operation: OPERATION_NAMES[this.operationName],
|
|
57
|
+
amountFrom: this.sourceAmount,
|
|
58
|
+
amountTo: this.expectedAmount,
|
|
59
|
+
tokenFrom: this.tokenFrom,
|
|
60
|
+
tokenTo: this.tokenTo,
|
|
61
|
+
creditManager: this.helper.creditManager,
|
|
62
|
+
timestamp: 0,
|
|
98
63
|
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
64
|
+
}
|
|
65
|
+
toString() {
|
|
66
|
+
const symbolFrom = token_1.tokenSymbolByAddress[this.tokenFrom.toLowerCase()];
|
|
67
|
+
const symbolTo = token_1.tokenSymbolByAddress[this.tokenTo.toLowerCase()];
|
|
103
68
|
if (!symbolFrom)
|
|
104
|
-
throw new Error(
|
|
69
|
+
throw new Error(`Unknown token: ${this.tokenFrom}`);
|
|
105
70
|
if (!symbolTo)
|
|
106
|
-
throw new Error(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
71
|
+
throw new Error(`Unknown token: ${this.tokenTo}`);
|
|
72
|
+
const decimalsFrom = decimals_1.decimals[symbolFrom];
|
|
73
|
+
const decimalsTo = decimals_1.decimals[symbolTo];
|
|
74
|
+
return `${this.operationName} ${(0, formatter_1.formatBN)(this.sourceAmount, decimalsFrom)} ${symbolFrom} ⇒ ${(0, formatter_1.formatBN)(this.expectedAmount, decimalsTo)} ${symbolTo} on ${this.helper.name}`;
|
|
75
|
+
}
|
|
76
|
+
static getOperationName(tokenInAddress, tokenOutAddress) {
|
|
77
|
+
const tokenInSymbol = token_1.tokenSymbolByAddress[tokenInAddress];
|
|
78
|
+
const tokenOutSymbol = token_1.tokenSymbolByAddress[tokenOutAddress];
|
|
79
|
+
const tokenInIsLp = (0, token_1.isLPToken)(tokenInSymbol);
|
|
80
|
+
const tokenOutIsLp = (0, token_1.isLPToken)(tokenOutSymbol);
|
|
116
81
|
if (!tokenInSymbol)
|
|
117
|
-
throw new Error(
|
|
82
|
+
throw new Error(`Unknown token: ${tokenInAddress}`);
|
|
118
83
|
if (!tokenOutSymbol)
|
|
119
|
-
throw new Error(
|
|
84
|
+
throw new Error(`Unknown token: ${tokenOutAddress}`);
|
|
120
85
|
if (tokenInIsLp && !tokenOutIsLp)
|
|
121
86
|
return "farmWithdraw";
|
|
122
87
|
if (!tokenInIsLp && tokenOutIsLp)
|
|
@@ -124,27 +89,17 @@ var Trade = /** @class */ (function () {
|
|
|
124
89
|
if (!tokenInIsLp && !tokenOutIsLp)
|
|
125
90
|
return "swap";
|
|
126
91
|
return "unknownOperation";
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
Trade.executeOnCreditFacade = function (calls, creditFacade) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
return __generator(this, function (_a) {
|
|
144
|
-
return [2 /*return*/, creditFacade.multicall(calls)];
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
return Trade;
|
|
149
|
-
}());
|
|
92
|
+
}
|
|
93
|
+
static async executeMulticallPath(creditFacade, signer, calls) {
|
|
94
|
+
if (calls.length < 1)
|
|
95
|
+
throw new Error("No path to execute");
|
|
96
|
+
const safeCreditFacade = typeof creditFacade === "string"
|
|
97
|
+
? types_1.ICreditFacade__factory.connect(creditFacade, signer)
|
|
98
|
+
: creditFacade;
|
|
99
|
+
return this.executeOnCreditFacade(calls, safeCreditFacade);
|
|
100
|
+
}
|
|
101
|
+
static async executeOnCreditFacade(calls, creditFacade) {
|
|
102
|
+
return creditFacade.multicall(calls);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
150
105
|
exports.Trade = Trade;
|