@gearbox-protocol/sdk 1.22.4 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/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 +2 -2
- package/lib/core/rewardClaimer.js +5 -48
- package/lib/core/rewardConvex.js +54 -114
- package/lib/core/rewardConvex.spec.js +41 -43
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe("PathOptionFactory test",
|
|
7
|
-
it("next works correctly",
|
|
8
|
-
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const token_1 = require("../tokens/token");
|
|
5
|
+
const pathOptions_1 = require("./pathOptions");
|
|
6
|
+
describe("PathOptionFactory test", () => {
|
|
7
|
+
it("next works correctly", () => {
|
|
8
|
+
const serie = [
|
|
9
9
|
{
|
|
10
10
|
target: token_1.tokenDataByNetwork.Mainnet["3Crv"],
|
|
11
11
|
option: 0,
|
|
@@ -22,9 +22,9 @@ describe("PathOptionFactory test", function () {
|
|
|
22
22
|
totalOptions: 2,
|
|
23
23
|
},
|
|
24
24
|
];
|
|
25
|
-
|
|
25
|
+
const expectedNext = JSON.parse(JSON.stringify(serie));
|
|
26
26
|
expectedNext[2].option = 1;
|
|
27
|
-
|
|
27
|
+
let next = pathOptions_1.PathOptionFactory.next(serie);
|
|
28
28
|
(0, chai_1.expect)(next).to.be.eql(expectedNext);
|
|
29
29
|
expectedNext[1].option = 1;
|
|
30
30
|
expectedNext[2].option = 0;
|
|
@@ -55,17 +55,16 @@ describe("PathOptionFactory test", function () {
|
|
|
55
55
|
next = pathOptions_1.PathOptionFactory.next(next);
|
|
56
56
|
(0, chai_1.expect)(next).to.be.eql(expectedNext);
|
|
57
57
|
});
|
|
58
|
-
it("generatePathOptions works correctly",
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var expected = [
|
|
58
|
+
it("generatePathOptions works correctly", () => {
|
|
59
|
+
const balances = {
|
|
60
|
+
[token_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
61
|
+
[token_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
62
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
63
|
+
[token_1.tokenDataByNetwork.Mainnet.FRAX3CRV]: 200,
|
|
64
|
+
[token_1.tokenDataByNetwork.Mainnet.LUSD3CRV]: 200,
|
|
65
|
+
};
|
|
66
|
+
const result = pathOptions_1.PathOptionFactory.generatePathOptions(balances, 4);
|
|
67
|
+
const expected = [
|
|
69
68
|
{
|
|
70
69
|
target: token_1.tokenDataByNetwork.Mainnet["3Crv"],
|
|
71
70
|
option: 0,
|
|
@@ -82,62 +81,61 @@ describe("PathOptionFactory test", function () {
|
|
|
82
81
|
totalOptions: 2,
|
|
83
82
|
},
|
|
84
83
|
];
|
|
85
|
-
for (
|
|
84
|
+
for (let i = 0; i < 3; i++) {
|
|
86
85
|
expected[0].option = i;
|
|
87
86
|
(0, chai_1.expect)(expected).to.be.eql(result[i]);
|
|
88
87
|
}
|
|
89
88
|
});
|
|
90
|
-
it(" getCurvePools works correctly",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var expectedCurvePools = [
|
|
89
|
+
it(" getCurvePools works correctly", () => {
|
|
90
|
+
let balances = {
|
|
91
|
+
[token_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
92
|
+
[token_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
93
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
94
|
+
[token_1.tokenDataByNetwork.Mainnet.FRAX3CRV]: 200,
|
|
95
|
+
[token_1.tokenDataByNetwork.Mainnet.LUSD3CRV]: 200,
|
|
96
|
+
};
|
|
97
|
+
let expectedCurvePools = [
|
|
100
98
|
"3Crv",
|
|
101
99
|
"FRAX3CRV",
|
|
102
100
|
"LUSD3CRV",
|
|
103
101
|
];
|
|
104
102
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
105
|
-
balances =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
balances = {
|
|
104
|
+
[token_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
105
|
+
[token_1.tokenDataByNetwork.Mainnet["3Crv"]]: 200,
|
|
106
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
107
|
+
[token_1.tokenDataByNetwork.Mainnet.yvCurve_FRAX]: 200,
|
|
108
|
+
[token_1.tokenDataByNetwork.Mainnet.yvCurve_stETH]: 200,
|
|
109
|
+
};
|
|
112
110
|
expectedCurvePools = ["3Crv", "FRAX3CRV", "steCRV"];
|
|
113
111
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
114
|
-
balances =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
112
|
+
balances = {
|
|
113
|
+
[token_1.tokenDataByNetwork.Mainnet["1INCH"]]: 100,
|
|
114
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
115
|
+
[token_1.tokenDataByNetwork.Mainnet.cvx3Crv]: 200,
|
|
116
|
+
[token_1.tokenDataByNetwork.Mainnet.cvxFRAX3CRV]: 200,
|
|
117
|
+
};
|
|
120
118
|
expectedCurvePools = ["3Crv", "FRAX3CRV"];
|
|
121
119
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
122
|
-
balances =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
balances = {
|
|
121
|
+
[token_1.tokenDataByNetwork.Mainnet.wstETH]: 100,
|
|
122
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
123
|
+
[token_1.tokenDataByNetwork.Mainnet.stkcvx3Crv]: 200,
|
|
124
|
+
[token_1.tokenDataByNetwork.Mainnet.stkcvxFRAX3CRV]: 200,
|
|
125
|
+
};
|
|
128
126
|
expectedCurvePools = ["3Crv", "FRAX3CRV"];
|
|
129
127
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
130
|
-
balances =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
balances = {
|
|
129
|
+
[token_1.tokenDataByNetwork.Mainnet["3Crv"]]: 100,
|
|
130
|
+
[token_1.tokenDataByNetwork.Mainnet.USDC]: 200,
|
|
131
|
+
[token_1.tokenDataByNetwork.Mainnet.stkcvx3Crv]: 200,
|
|
132
|
+
[token_1.tokenDataByNetwork.Mainnet.cvx3Crv]: 200,
|
|
133
|
+
[token_1.tokenDataByNetwork.Mainnet.yvCurve_stETH]: 200,
|
|
134
|
+
};
|
|
137
135
|
expectedCurvePools = ["3Crv", "steCRV"];
|
|
138
136
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
|
|
139
137
|
});
|
|
140
|
-
it("detectNetwork works correctly",
|
|
138
|
+
it("detectNetwork works correctly", () => {
|
|
141
139
|
(0, chai_1.expect)(pathOptions_1.PathOptionFactory.detectNetwork(token_1.tokenDataByNetwork.Mainnet["1INCH"])).to.be.eq("Mainnet");
|
|
142
140
|
});
|
|
143
141
|
});
|
|
@@ -6,9 +6,9 @@ import { SupportedToken } from "../tokens/token";
|
|
|
6
6
|
import { IRouter } from "../types/@gearbox-protocol/router/contracts/interfaces/IRouter";
|
|
7
7
|
import { MultiCall, PathFinderCloseResult, PathFinderOpenStrategyResult, PathFinderResult, SwapOperation } from "./core";
|
|
8
8
|
export interface CloseResult {
|
|
9
|
-
amount:
|
|
9
|
+
amount: bigint;
|
|
10
10
|
calls: Array<MultiCall>;
|
|
11
|
-
gasUsage:
|
|
11
|
+
gasUsage: bigint;
|
|
12
12
|
}
|
|
13
13
|
export declare class PathFinder {
|
|
14
14
|
pathFinder: IRouter;
|
|
@@ -40,5 +40,5 @@ export declare class PathFinder {
|
|
|
40
40
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
41
41
|
*/
|
|
42
42
|
findBestClosePath(creditAccount: CreditAccountData, slippage: number, noConcurency?: boolean): Promise<PathFinderCloseResult>;
|
|
43
|
-
static compare(r1: CloseResult, r2: CloseResult, gasPriceRAY:
|
|
43
|
+
static compare(r1: CloseResult, r2: CloseResult, gasPriceRAY: bigint): CloseResult;
|
|
44
44
|
}
|
|
@@ -1,114 +1,63 @@
|
|
|
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.PathFinder = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
4
|
+
const constants_1 = require("../core/constants");
|
|
5
|
+
const token_1 = require("../tokens/token");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const formatter_1 = require("../utils/formatter");
|
|
8
|
+
const pathOptions_1 = require("./pathOptions");
|
|
9
|
+
const MAX_GAS_PER_ROUTE = 200e6;
|
|
10
|
+
const GAS_PER_BLOCK = 400e6;
|
|
11
|
+
class PathFinder {
|
|
12
|
+
pathFinder;
|
|
13
|
+
network;
|
|
14
|
+
static connectors = ["USDC", "WETH", "DAI"];
|
|
15
|
+
_connectors;
|
|
16
|
+
constructor(address, provider, network = "Mainnet", connectors) {
|
|
51
17
|
this.pathFinder = types_1.IRouter__factory.connect(address, provider);
|
|
52
18
|
this.network = network;
|
|
53
|
-
this._connectors = (connectors || PathFinder.connectors).map(
|
|
19
|
+
this._connectors = (connectors || PathFinder.connectors).map(c => token_1.tokenDataByNetwork[this.network][c]);
|
|
54
20
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
slippage: slippage,
|
|
70
|
-
externalSlippage: false,
|
|
71
|
-
};
|
|
72
|
-
return [4 /*yield*/, this.pathFinder.callStatic.findAllSwaps(swapTask, {
|
|
73
|
-
gasLimit: GAS_PER_BLOCK,
|
|
74
|
-
})];
|
|
75
|
-
case 1:
|
|
76
|
-
results = _a.sent();
|
|
77
|
-
unique = {};
|
|
78
|
-
results.forEach(function (r) {
|
|
79
|
-
var key = "".concat(r.amount.toHexString()).concat(r.calls
|
|
80
|
-
.map(function (c) { return "".concat(c.target.toLowerCase()).concat(c.callData); })
|
|
81
|
-
.join("-"));
|
|
82
|
-
unique[key] = {
|
|
83
|
-
amount: ethers_1.BigNumber.from(r.amount),
|
|
84
|
-
calls: r.calls,
|
|
85
|
-
};
|
|
86
|
-
});
|
|
87
|
-
return [2 /*return*/, Object.values(unique)];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
21
|
+
async findAllSwaps(creditAccount, swapOperation, tokenIn, tokenOut, amount, slippage) {
|
|
22
|
+
const swapTask = {
|
|
23
|
+
swapOperation: swapOperation,
|
|
24
|
+
creditAccount: creditAccount.addr,
|
|
25
|
+
tokenIn: token_1.tokenDataByNetwork[this.network][tokenIn] || tokenIn,
|
|
26
|
+
tokenOut: token_1.tokenDataByNetwork[this.network][tokenOut] ||
|
|
27
|
+
tokenOut,
|
|
28
|
+
connectors: this._connectors,
|
|
29
|
+
amount: amount,
|
|
30
|
+
slippage,
|
|
31
|
+
externalSlippage: false,
|
|
32
|
+
};
|
|
33
|
+
const results = await this.pathFinder.callStatic.findAllSwaps(swapTask, {
|
|
34
|
+
gasLimit: GAS_PER_BLOCK,
|
|
90
35
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
gasLimit: GAS_PER_BLOCK,
|
|
101
|
-
})];
|
|
102
|
-
case 1:
|
|
103
|
-
result = _a.sent();
|
|
104
|
-
return [2 /*return*/, {
|
|
105
|
-
amount: ethers_1.BigNumber.from(result.amount),
|
|
106
|
-
calls: result.calls,
|
|
107
|
-
}];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
36
|
+
const unique = {};
|
|
37
|
+
results.forEach(r => {
|
|
38
|
+
const key = `${r.amount.toHexString()}${r.calls
|
|
39
|
+
.map(c => `${c.target.toLowerCase()}${c.callData}`)
|
|
40
|
+
.join("-")}`;
|
|
41
|
+
unique[key] = {
|
|
42
|
+
amount: (0, formatter_1.toBigInt)(r.amount),
|
|
43
|
+
calls: r.calls,
|
|
44
|
+
};
|
|
110
45
|
});
|
|
111
|
-
|
|
46
|
+
return Object.values(unique);
|
|
47
|
+
}
|
|
48
|
+
async findOneTokenPath(creditAccount, tokenIn, tokenOut, amount, slippage) {
|
|
49
|
+
const tokenInAddr = token_1.tokenDataByNetwork[this.network][tokenIn] || tokenIn;
|
|
50
|
+
// if (creditAccount.balances[tokenInAddr.toLowerCase()].lt(amount)) {
|
|
51
|
+
// throw new Error(`Not enough balance for token ${tokenIn}`);
|
|
52
|
+
// }
|
|
53
|
+
const result = await this.pathFinder.callStatic.findOneTokenPath(tokenInAddr, amount, token_1.tokenDataByNetwork[this.network][tokenOut] || tokenOut, creditAccount.addr, this._connectors, slippage, {
|
|
54
|
+
gasLimit: GAS_PER_BLOCK,
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
amount: (0, formatter_1.toBigInt)(result.amount),
|
|
58
|
+
calls: result.calls,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
112
61
|
/**
|
|
113
62
|
* @dev Finds the best path for opening credit account and converting all NORMAL tokens and LP token in the way to TARGET
|
|
114
63
|
* @param cm CreditManagerData which represents credit manager you want to use to open credit account
|
|
@@ -120,41 +69,29 @@ var PathFinder = /** @class */ (function () {
|
|
|
120
69
|
* @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
121
70
|
* @returns PathFinderOpenStrategyResult which
|
|
122
71
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}, {});
|
|
137
|
-
balances = cm.collateralTokens.map(function (token) { return ({
|
|
138
|
-
token: token,
|
|
139
|
-
balance: expectedBalancesAddr[token] || 0,
|
|
140
|
-
}); });
|
|
141
|
-
return [4 /*yield*/, this.pathFinder.callStatic.findOpenStrategyPath(cm.address, balances, targetAddr, this._connectors, slippage, {
|
|
142
|
-
gasLimit: GAS_PER_BLOCK,
|
|
143
|
-
})];
|
|
144
|
-
case 1:
|
|
145
|
-
result = _a.sent();
|
|
146
|
-
balancesAfter = result[0].reduce(function (acc, b) {
|
|
147
|
-
acc[b.token.toLowerCase()] = ethers_1.BigNumber.from(b.balance);
|
|
148
|
-
return acc;
|
|
149
|
-
}, {});
|
|
150
|
-
return [2 /*return*/, {
|
|
151
|
-
balances: balancesAfter,
|
|
152
|
-
calls: result[1].calls,
|
|
153
|
-
}];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
72
|
+
async findOpenStrategyPath(cm, expectedBalances, target, slippage) {
|
|
73
|
+
const targetAddr = token_1.tokenDataByNetwork[this.network][target] || target;
|
|
74
|
+
const expectedBalancesAddr = Object.entries(expectedBalances).reduce((acc, [token, balance]) => {
|
|
75
|
+
const tokenAddr = token_1.tokenDataByNetwork[this.network][token] || token;
|
|
76
|
+
acc[tokenAddr.toLowerCase()] = balance;
|
|
77
|
+
return acc;
|
|
78
|
+
}, {});
|
|
79
|
+
const balances = cm.collateralTokens.map(token => ({
|
|
80
|
+
token,
|
|
81
|
+
balance: expectedBalancesAddr[token] || 0,
|
|
82
|
+
}));
|
|
83
|
+
const result = await this.pathFinder.callStatic.findOpenStrategyPath(cm.address, balances, targetAddr, this._connectors, slippage, {
|
|
84
|
+
gasLimit: GAS_PER_BLOCK,
|
|
156
85
|
});
|
|
157
|
-
|
|
86
|
+
const balancesAfter = result[0].reduce((acc, b) => {
|
|
87
|
+
acc[b.token.toLowerCase()] = (0, formatter_1.toBigInt)(b.balance);
|
|
88
|
+
return acc;
|
|
89
|
+
}, {});
|
|
90
|
+
return {
|
|
91
|
+
balances: balancesAfter,
|
|
92
|
+
calls: result[1].calls,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
158
95
|
/**
|
|
159
96
|
* @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
|
|
160
97
|
* Can bu used for closing credit account and for liquidations as well.
|
|
@@ -164,71 +101,41 @@ var PathFinder = /** @class */ (function () {
|
|
|
164
101
|
* - underlyingBalance - total balance of underlying token
|
|
165
102
|
* - calls - list of calls which should be done to swap & unwrap everything to underlying token
|
|
166
103
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
_i++;
|
|
193
|
-
return [3 /*break*/, 1];
|
|
194
|
-
case 4: return [3 /*break*/, 7];
|
|
195
|
-
case 5:
|
|
196
|
-
requests = pathOptions.map(function (po) {
|
|
197
|
-
return _this.pathFinder.callStatic.findBestClosePath(creditAccount.addr, _this._connectors, slippage, po, loopsPerTx, false, {
|
|
198
|
-
gasLimit: GAS_PER_BLOCK,
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
return [4 /*yield*/, Promise.all(requests)];
|
|
202
|
-
case 6:
|
|
203
|
-
results = _c.sent();
|
|
204
|
-
_c.label = 7;
|
|
205
|
-
case 7:
|
|
206
|
-
bestResult = results.reduce(function (best, _a) {
|
|
207
|
-
var pathFinderResult = _a[0], gasPriceRAY = _a[1];
|
|
208
|
-
return PathFinder.compare(best, pathFinderResult, gasPriceRAY);
|
|
209
|
-
}, {
|
|
210
|
-
amount: ethers_1.BigNumber.from(0),
|
|
211
|
-
gasUsage: 0,
|
|
212
|
-
calls: [],
|
|
213
|
-
});
|
|
214
|
-
return [2 /*return*/, {
|
|
215
|
-
underlyingBalance: ethers_1.BigNumber.from(bestResult.amount).add(creditAccount.allBalances[creditAccount.underlyingToken.toLowerCase()]),
|
|
216
|
-
calls: bestResult.calls,
|
|
217
|
-
}];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
104
|
+
async findBestClosePath(creditAccount, slippage, noConcurency = false) {
|
|
105
|
+
const loopsPerTx = Math.floor(GAS_PER_BLOCK / MAX_GAS_PER_ROUTE);
|
|
106
|
+
const pathOptions = pathOptions_1.PathOptionFactory.generatePathOptions(creditAccount.allBalances, loopsPerTx);
|
|
107
|
+
let results = [];
|
|
108
|
+
if (noConcurency) {
|
|
109
|
+
for (const po of pathOptions) {
|
|
110
|
+
results.push(await this.pathFinder.callStatic.findBestClosePath(creditAccount.addr, this._connectors, slippage, po, loopsPerTx, false, {
|
|
111
|
+
gasLimit: GAS_PER_BLOCK,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const requests = pathOptions.map(po => this.pathFinder.callStatic.findBestClosePath(creditAccount.addr, this._connectors, slippage, po, loopsPerTx, false, {
|
|
117
|
+
gasLimit: GAS_PER_BLOCK,
|
|
118
|
+
}));
|
|
119
|
+
results = await Promise.all(requests);
|
|
120
|
+
}
|
|
121
|
+
const bestResult = results.reduce((best, [pathFinderResult, gasPriceRAY]) => PathFinder.compare(best, {
|
|
122
|
+
calls: pathFinderResult.calls,
|
|
123
|
+
amount: (0, formatter_1.toBigInt)(pathFinderResult.amount),
|
|
124
|
+
gasUsage: (0, formatter_1.toBigInt)(pathFinderResult.gasUsage),
|
|
125
|
+
}, (0, formatter_1.toBigInt)(gasPriceRAY)), {
|
|
126
|
+
amount: 0n,
|
|
127
|
+
gasUsage: 0n,
|
|
128
|
+
calls: [],
|
|
220
129
|
});
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return ethers_1.BigNumber.from(amount).sub(ethers_1.BigNumber.from(gasUsage).mul(gasPrice).div(constants_1.RAY));
|
|
130
|
+
return {
|
|
131
|
+
underlyingBalance: bestResult.amount +
|
|
132
|
+
creditAccount.allBalances[creditAccount.underlyingToken.toLowerCase()],
|
|
133
|
+
calls: bestResult.calls,
|
|
226
134
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}());
|
|
135
|
+
}
|
|
136
|
+
static compare(r1, r2, gasPriceRAY) {
|
|
137
|
+
const comparator = ({ amount, gasUsage }, gasPrice) => amount - (gasUsage * gasPrice) / constants_1.RAY;
|
|
138
|
+
return comparator(r1, gasPriceRAY) > comparator(r2, gasPriceRAY) ? r1 : r2;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
234
141
|
exports.PathFinder = PathFinder;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
describe("PathFinder test",
|
|
7
|
-
it("compare works correctly",
|
|
8
|
-
|
|
9
|
-
amount:
|
|
10
|
-
gasUsage:
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const constants_1 = require("../core/constants");
|
|
5
|
+
const pathfinder_1 = require("./pathfinder");
|
|
6
|
+
describe("PathFinder test", () => {
|
|
7
|
+
it("compare works correctly", () => {
|
|
8
|
+
const r1 = {
|
|
9
|
+
amount: 2000n,
|
|
10
|
+
gasUsage: 1000n,
|
|
11
11
|
calls: [],
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
amount:
|
|
15
|
-
gasUsage:
|
|
13
|
+
const r2 = {
|
|
14
|
+
amount: 3000n,
|
|
15
|
+
gasUsage: 2000n,
|
|
16
16
|
calls: [],
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
let result = pathfinder_1.PathFinder.compare(r1, r2, constants_1.RAY);
|
|
19
19
|
(0, chai_1.expect)(result).to.be.eql(r2);
|
|
20
|
-
result = pathfinder_1.PathFinder.compare(r1, r2, constants_1.RAY
|
|
20
|
+
result = pathfinder_1.PathFinder.compare(r1, r2, constants_1.RAY * 2n);
|
|
21
21
|
(0, chai_1.expect)(result).to.be.eql(r1);
|
|
22
22
|
});
|
|
23
23
|
});
|