@gearbox-protocol/sdk 0.0.60 → 0.0.63
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/core/contracts.js +4 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/pathfinder/path.js +9 -8
- package/lib/pathfinder/priority.d.ts +1 -1
- package/lib/pathfinder/priority.js +11 -11
- package/lib/tokens/convex.d.ts +2 -1
- package/lib/tokens/convex.js +11 -11
- package/lib/tokens/curveLP.d.ts +2 -1
- package/lib/tokens/curveLP.js +7 -7
- package/lib/tokens/gear.d.ts +2 -1
- package/lib/tokens/gear.js +6 -6
- package/lib/tokens/normal.d.ts +2 -1
- package/lib/tokens/normal.js +29 -29
- package/lib/tokens/token.d.ts +0 -12
- package/lib/tokens/token.js +7 -20
- package/lib/tokens/tokenType.d.ts +12 -0
- package/lib/tokens/tokenType.js +16 -0
- package/lib/tokens/yearn.d.ts +2 -1
- package/lib/tokens/yearn.js +7 -7
- package/package.json +1 -1
- package/src/core/contracts.ts +5 -5
- package/src/index.ts +1 -0
- package/src/pathfinder/path.ts +3 -2
- package/src/pathfinder/priority.ts +1 -1
- package/src/tokens/convex.ts +2 -1
- package/src/tokens/curveLP.ts +2 -1
- package/src/tokens/gear.ts +2 -1
- package/src/tokens/normal.ts +2 -1
- package/src/tokens/token.ts +6 -19
- package/src/tokens/tokenType.ts +12 -0
- package/src/tokens/yearn.ts +2 -1
- package/lib/core/pathfinder.d.ts +0 -54
- package/lib/core/pathfinder.js +0 -612
- package/lib/core/token.d.ts +0 -104
- package/lib/core/token.js +0 -1359
- package/lib/core/tokenData.d.ts +0 -24
- package/lib/core/tokenData.js +0 -57
- package/lib/pathfinder/connector.d.ts +0 -7
- package/lib/pathfinder/connector.js +0 -78
- package/lib/pathfinder/connectorPathAsset.d.ts +0 -7
- package/lib/pathfinder/connectorPathAsset.js +0 -144
- package/lib/pathfinder/convexLPTokenPathAsset.d.ts +0 -5
- package/lib/pathfinder/convexLPTokenPathAsset.js +0 -77
- package/lib/pathfinder/curveLPPathAsset.d.ts +0 -5
- package/lib/pathfinder/curveLPPathAsset.js +0 -72
- package/lib/pathfinder/curveMetaLP.d.ts +0 -5
- package/lib/pathfinder/curveMetaLP.js +0 -72
- package/lib/pathfinder/metaCurveLPPathAsset.d.ts +0 -5
- package/lib/pathfinder/metaCurveLPPathAsset.js +0 -72
- package/lib/pathfinder/normalToken.d.ts +0 -7
- package/lib/pathfinder/normalToken.js +0 -78
- package/lib/pathfinder/normalTokenPathAsset.d.ts +0 -5
- package/lib/pathfinder/normalTokenPathAsset.js +0 -136
- package/lib/pathfinder/notes.d.ts +0 -4
- package/lib/pathfinder/notes.js +0 -58
- package/lib/pathfinder/pathfinder.d.ts +0 -24
- package/lib/pathfinder/pathfinder.js +0 -132
- package/lib/pathfinder/yearnVaultOfCurveLPPathAsset.d.ts +0 -5
- package/lib/pathfinder/yearnVaultOfCurveLPPathAsset.js +0 -87
- package/lib/pathfinder/yearnVaultOfMetaCurveLPPathAsset.d.ts +0 -5
- package/lib/pathfinder/yearnVaultOfMetaCurveLPPathAsset.js +0 -87
- package/lib/pathfinder/yearnVaultPathAsset.d.ts +0 -5
- package/lib/pathfinder/yearnVaultPathAsset.js +0 -87
- package/lib/types/ACL.d.ts +0 -491
- package/lib/types/ACLTrait.d.ts +0 -148
- package/lib/types/ACLTraitTest.d.ts +0 -209
- package/lib/types/AccountFactory.d.ts +0 -716
- package/lib/types/AccountMining.d.ts +0 -222
- package/lib/types/AddressProvider.d.ts +0 -912
- package/lib/types/AggregatorV3Interface.d.ts +0 -234
- package/lib/types/ChainlinkPriceFeedMock.d.ts +0 -215
- package/lib/types/ContractsRegister.d.ts +0 -398
- package/lib/types/CreditAccount.d.ts +0 -443
- package/lib/types/CreditFilter.d.ts +0 -1609
- package/lib/types/CreditFilterMock.d.ts +0 -1687
- package/lib/types/CreditManager.d.ts +0 -1285
- package/lib/types/CreditManagerMockForFilter.d.ts +0 -605
- package/lib/types/CreditManagerMockForPoolTest.d.ts +0 -204
- package/lib/types/CurveMock.d.ts +0 -298
- package/lib/types/CurveV1Adapter.d.ts +0 -349
- package/lib/types/DataCompressor.d.ts +0 -1331
- package/lib/types/DieselToken.d.ts +0 -567
- package/lib/types/ERC165.d.ts +0 -116
- package/lib/types/ERC20.d.ts +0 -411
- package/lib/types/ERC20BlockingMock.d.ts +0 -568
- package/lib/types/ERC721.d.ts +0 -625
- package/lib/types/Errors.d.ts +0 -1854
- package/lib/types/ExecutorMock.d.ts +0 -140
- package/lib/types/FlashLoanAttacker.d.ts +0 -170
- package/lib/types/FuzzHarness.d.ts +0 -124
- package/lib/types/GearBeta.d.ts +0 -745
- package/lib/types/GearToken.d.ts +0 -888
- package/lib/types/IAccountFactory.d.ts +0 -317
- package/lib/types/IAccountMiner.d.ts +0 -124
- package/lib/types/IAppAddressProvider.d.ts +0 -198
- package/lib/types/IAppCreditManager.d.ts +0 -408
- package/lib/types/IAppERC20.d.ts +0 -309
- package/lib/types/IAppPoolService.d.ts +0 -166
- package/lib/types/ICreditAccount.d.ts +0 -430
- package/lib/types/ICreditFilter.d.ts +0 -1162
- package/lib/types/ICreditManager.d.ts +0 -971
- package/lib/types/ICurvePool.d.ts +0 -298
- package/lib/types/IDataCompressor.d.ts +0 -1231
- package/lib/types/IERC165.d.ts +0 -116
- package/lib/types/IERC20.d.ts +0 -294
- package/lib/types/IERC721.d.ts +0 -472
- package/lib/types/IERC721Enumerable.d.ts +0 -564
- package/lib/types/IERC721Metadata.d.ts +0 -523
- package/lib/types/IERC721Receiver.d.ts +0 -132
- package/lib/types/IGearToken.d.ts +0 -527
- package/lib/types/IInterestRateModel.d.ts +0 -121
- package/lib/types/IMerkleDistributor.d.ts +0 -190
- package/lib/types/IPoolService.d.ts +0 -772
- package/lib/types/IPriceOracle.d.ts +0 -211
- package/lib/types/IQuoter.d.ts +0 -269
- package/lib/types/ISwapRouter.d.ts +0 -404
- package/lib/types/IUniswapV2Migrator.d.ts +0 -134
- package/lib/types/IUniswapV2Router01.d.ts +0 -1119
- package/lib/types/IUniswapV2Router02.d.ts +0 -1432
- package/lib/types/IUniswapV3SwapCallback.d.ts +0 -127
- package/lib/types/IWETH.d.ts +0 -169
- package/lib/types/IWETHGateway.d.ts +0 -335
- package/lib/types/IYVault.d.ts +0 -558
- package/lib/types/LeveragedActions.d.ts +0 -772
- package/lib/types/LinearInterestRateModel.d.ts +0 -279
- package/lib/types/MockPoolService.d.ts +0 -1271
- package/lib/types/Multicall2.d.ts +0 -449
- package/lib/types/Ownable.d.ts +0 -169
- package/lib/types/PathFinder.d.ts +0 -379
- package/lib/types/Pausable.d.ts +0 -105
- package/lib/types/PercentageMathTest.d.ts +0 -154
- package/lib/types/PoolService.d.ts +0 -1174
- package/lib/types/PriceOracle.d.ts +0 -387
- package/lib/types/StepVesting.d.ts +0 -411
- package/lib/types/TestPoolService.d.ts +0 -1294
- package/lib/types/TokenDistributor.d.ts +0 -640
- package/lib/types/TokenFeeMock.d.ts +0 -544
- package/lib/types/TokenMock.d.ts +0 -531
- package/lib/types/TreasuryMock.d.ts +0 -86
- package/lib/types/UniswapRouterMock.d.ts +0 -1520
- package/lib/types/UniswapV2Adapter.d.ts +0 -1463
- package/lib/types/UniswapV3Adapter.d.ts +0 -455
- package/lib/types/WETHGateway.d.ts +0 -376
- package/lib/types/WETHMock.d.ts +0 -433
- package/lib/types/WadRayMathTest.d.ts +0 -316
- package/lib/types/YearnAdapter.d.ts +0 -609
- package/lib/types/YearnMock.d.ts +0 -795
- package/lib/types/YearnPriceFeed.d.ts +0 -399
- package/lib/types/commons.d.ts +0 -16
- package/lib/types/commons.js +0 -5
- package/lib/types/contracts/support/PathFinder.d.ts +0 -154
- package/lib/types/contracts/support/PathFinder.js +0 -2
- package/lib/types/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/ClaimZapFormatter.d.ts +0 -52
- package/lib/types/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/ClaimZapFormatter.js +0 -2
- package/lib/types/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/index.d.ts +0 -1
- package/lib/types/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/index.js +0 -2
- package/lib/types/factories/ACLTraitTest__factory.d.ts +0 -52
- package/lib/types/factories/ACLTraitTest__factory.js +0 -138
- package/lib/types/factories/ACLTrait__factory.d.ts +0 -31
- package/lib/types/factories/ACLTrait__factory.js +0 -75
- package/lib/types/factories/ACL__factory.d.ts +0 -45
- package/lib/types/factories/ACL__factory.js +0 -317
- package/lib/types/factories/AccountFactory__factory.d.ts +0 -72
- package/lib/types/factories/AccountFactory__factory.js +0 -508
- package/lib/types/factories/AccountMining__factory.d.ts +0 -56
- package/lib/types/factories/AccountMining__factory.js +0 -192
- package/lib/types/factories/AddressProvider__factory.d.ts +0 -52
- package/lib/types/factories/AddressProvider__factory.js +0 -582
- package/lib/types/factories/AggregatorV3Interface__factory.d.ts +0 -22
- package/lib/types/factories/AggregatorV3Interface__factory.js +0 -133
- package/lib/types/factories/ChainlinkPriceFeedMock__factory.d.ts +0 -42
- package/lib/types/factories/ChainlinkPriceFeedMock__factory.js +0 -193
- package/lib/types/factories/ContractsRegister__factory.d.ts +0 -56
- package/lib/types/factories/ContractsRegister__factory.js +0 -310
- package/lib/types/factories/CreditAccount__factory.d.ts +0 -32
- package/lib/types/factories/CreditAccount__factory.js +0 -262
- package/lib/types/factories/CreditFilterMock__factory.d.ts +0 -56
- package/lib/types/factories/CreditFilterMock__factory.js +0 -1083
- package/lib/types/factories/CreditFilter__factory.d.ts +0 -56
- package/lib/types/factories/CreditFilter__factory.js +0 -1047
- package/lib/types/factories/CreditManagerMockForFilter__factory.d.ts +0 -38
- package/lib/types/factories/CreditManagerMockForFilter__factory.js +0 -324
- package/lib/types/factories/CreditManagerMockForPoolTest__factory.d.ts +0 -48
- package/lib/types/factories/CreditManagerMockForPoolTest__factory.js +0 -131
- package/lib/types/factories/CreditManager__factory.d.ts +0 -77
- package/lib/types/factories/CreditManager__factory.js +0 -1030
- package/lib/types/factories/CurveMock__factory.d.ts +0 -42
- package/lib/types/factories/CurveMock__factory.js +0 -210
- package/lib/types/factories/CurveV1Adapter__factory.d.ts +0 -42
- package/lib/types/factories/CurveV1Adapter__factory.js +0 -254
- package/lib/types/factories/DataCompressor__factory.d.ts +0 -71
- package/lib/types/factories/DataCompressor__factory.js +0 -944
- package/lib/types/factories/DieselToken__factory.d.ts +0 -56
- package/lib/types/factories/DieselToken__factory.js +0 -432
- package/lib/types/factories/ERC165__factory.d.ts +0 -22
- package/lib/types/factories/ERC165__factory.js +0 -41
- package/lib/types/factories/ERC20BlockingMock__factory.d.ts +0 -56
- package/lib/types/factories/ERC20BlockingMock__factory.js +0 -429
- package/lib/types/factories/ERC20__factory.d.ts +0 -56
- package/lib/types/factories/ERC20__factory.js +0 -339
- package/lib/types/factories/ERC721__factory.d.ts +0 -56
- package/lib/types/factories/ERC721__factory.js +0 -468
- package/lib/types/factories/Errors__factory.d.ts +0 -28
- package/lib/types/factories/Errors__factory.js +0 -1015
- package/lib/types/factories/ExecutorMock__factory.d.ts +0 -38
- package/lib/types/factories/ExecutorMock__factory.js +0 -103
- package/lib/types/factories/FlashLoanAttacker__factory.d.ts +0 -48
- package/lib/types/factories/FlashLoanAttacker__factory.js +0 -117
- package/lib/types/factories/FuzzHarness__factory.d.ts +0 -38
- package/lib/types/factories/FuzzHarness__factory.js +0 -92
- package/lib/types/factories/GearBeta__factory.d.ts +0 -52
- package/lib/types/factories/GearBeta__factory.js +0 -527
- package/lib/types/factories/GearToken__factory.d.ts +0 -56
- package/lib/types/factories/GearToken__factory.js +0 -708
- package/lib/types/factories/IAccountFactory__factory.d.ts +0 -35
- package/lib/types/factories/IAccountFactory__factory.js +0 -226
- package/lib/types/factories/IAccountMiner__factory.d.ts +0 -28
- package/lib/types/factories/IAccountMiner__factory.js +0 -48
- package/lib/types/factories/IAppAddressProvider__factory.d.ts +0 -18
- package/lib/types/factories/IAppAddressProvider__factory.js +0 -100
- package/lib/types/factories/IAppCreditManager__factory.d.ts +0 -42
- package/lib/types/factories/IAppCreditManager__factory.js +0 -204
- package/lib/types/factories/IAppERC20__factory.d.ts +0 -22
- package/lib/types/factories/IAppERC20__factory.js +0 -194
- package/lib/types/factories/IAppPoolService__factory.d.ts +0 -22
- package/lib/types/factories/IAppPoolService__factory.js +0 -69
- package/lib/types/factories/ICreditAccount__factory.d.ts +0 -22
- package/lib/types/factories/ICreditAccount__factory.js +0 -218
- package/lib/types/factories/ICreditFilter__factory.d.ts +0 -35
- package/lib/types/factories/ICreditFilter__factory.js +0 -700
- package/lib/types/factories/ICreditManager__factory.d.ts +0 -56
- package/lib/types/factories/ICreditManager__factory.js +0 -720
- package/lib/types/factories/ICurvePool__factory.d.ts +0 -22
- package/lib/types/factories/ICurvePool__factory.js +0 -168
- package/lib/types/factories/IDataCompressor__factory.d.ts +0 -51
- package/lib/types/factories/IDataCompressor__factory.js +0 -826
- package/lib/types/factories/IERC165__factory.d.ts +0 -22
- package/lib/types/factories/IERC165__factory.js +0 -41
- package/lib/types/factories/IERC20__factory.d.ts +0 -35
- package/lib/types/factories/IERC20__factory.js +0 -205
- package/lib/types/factories/IERC721Enumerable__factory.d.ts +0 -35
- package/lib/types/factories/IERC721Enumerable__factory.js +0 -363
- package/lib/types/factories/IERC721Metadata__factory.d.ts +0 -35
- package/lib/types/factories/IERC721Metadata__factory.js +0 -352
- package/lib/types/factories/IERC721Receiver__factory.d.ts +0 -22
- package/lib/types/factories/IERC721Receiver__factory.js +0 -56
- package/lib/types/factories/IERC721__factory.d.ts +0 -35
- package/lib/types/factories/IERC721__factory.js +0 -307
- package/lib/types/factories/IGearToken__factory.d.ts +0 -35
- package/lib/types/factories/IGearToken__factory.js +0 -342
- package/lib/types/factories/IInterestRateModel__factory.d.ts +0 -22
- package/lib/types/factories/IInterestRateModel__factory.js +0 -46
- package/lib/types/factories/IMerkleDistributor__factory.d.ts +0 -35
- package/lib/types/factories/IMerkleDistributor__factory.js +0 -109
- package/lib/types/factories/IPoolService__factory.d.ts +0 -35
- package/lib/types/factories/IPoolService__factory.js +0 -580
- package/lib/types/factories/IPriceOracle__factory.d.ts +0 -35
- package/lib/types/factories/IPriceOracle__factory.js +0 -112
- package/lib/types/factories/IQuoter__factory.d.ts +0 -22
- package/lib/types/factories/IQuoter__factory.js +0 -148
- package/lib/types/factories/ISwapRouter__factory.d.ts +0 -27
- package/lib/types/factories/ISwapRouter__factory.js +0 -236
- package/lib/types/factories/IUniswapV2Migrator__factory.d.ts +0 -18
- package/lib/types/factories/IUniswapV2Migrator__factory.js +0 -55
- package/lib/types/factories/IUniswapV2Router01__factory.d.ts +0 -22
- package/lib/types/factories/IUniswapV2Router01__factory.js +0 -771
- package/lib/types/factories/IUniswapV2Router02__factory.d.ts +0 -22
- package/lib/types/factories/IUniswapV2Router02__factory.js +0 -973
- package/lib/types/factories/IUniswapV3SwapCallback__factory.d.ts +0 -18
- package/lib/types/factories/IUniswapV3SwapCallback__factory.js +0 -45
- package/lib/types/factories/IWETHGateway__factory.d.ts +0 -18
- package/lib/types/factories/IWETHGateway__factory.js +0 -150
- package/lib/types/factories/IWETH__factory.d.ts +0 -22
- package/lib/types/factories/IWETH__factory.js +0 -66
- package/lib/types/factories/IYVault__factory.d.ts +0 -35
- package/lib/types/factories/IYVault__factory.js +0 -411
- package/lib/types/factories/LeveragedActions__factory.d.ts +0 -84
- package/lib/types/factories/LeveragedActions__factory.js +0 -569
- package/lib/types/factories/LinearInterestRateModel__factory.d.ts +0 -42
- package/lib/types/factories/LinearInterestRateModel__factory.js +0 -209
- package/lib/types/factories/MockPoolService__factory.d.ts +0 -56
- package/lib/types/factories/MockPoolService__factory.js +0 -889
- package/lib/types/factories/Multicall2__factory.d.ts +0 -52
- package/lib/types/factories/Multicall2__factory.js +0 -364
- package/lib/types/factories/Ownable__factory.d.ts +0 -42
- package/lib/types/factories/Ownable__factory.js +0 -74
- package/lib/types/factories/PathFinder__factory.d.ts +0 -61
- package/lib/types/factories/PathFinder__factory.js +0 -302
- package/lib/types/factories/Pausable__factory.d.ts +0 -31
- package/lib/types/factories/Pausable__factory.js +0 -61
- package/lib/types/factories/PercentageMathTest__factory.d.ts +0 -32
- package/lib/types/factories/PercentageMathTest__factory.js +0 -101
- package/lib/types/factories/PoolService__factory.d.ts +0 -56
- package/lib/types/factories/PoolService__factory.js +0 -873
- package/lib/types/factories/PriceOracle__factory.d.ts +0 -56
- package/lib/types/factories/PriceOracle__factory.js +0 -290
- package/lib/types/factories/StepVesting__factory.d.ts +0 -52
- package/lib/types/factories/StepVesting__factory.js +0 -296
- package/lib/types/factories/TestPoolService__factory.d.ts +0 -56
- package/lib/types/factories/TestPoolService__factory.js +0 -932
- package/lib/types/factories/TokenDistributor__factory.d.ts +0 -82
- package/lib/types/factories/TokenDistributor__factory.js +0 -481
- package/lib/types/factories/TokenFeeMock__factory.d.ts +0 -56
- package/lib/types/factories/TokenFeeMock__factory.js +0 -427
- package/lib/types/factories/TokenMock__factory.d.ts +0 -56
- package/lib/types/factories/TokenMock__factory.js +0 -409
- package/lib/types/factories/TreasuryMock__factory.d.ts +0 -35
- package/lib/types/factories/TreasuryMock__factory.js +0 -70
- package/lib/types/factories/UniswapRouterMock__factory.d.ts +0 -32
- package/lib/types/factories/UniswapRouterMock__factory.js +0 -1046
- package/lib/types/factories/UniswapV2Adapter__factory.d.ts +0 -42
- package/lib/types/factories/UniswapV2Adapter__factory.js +0 -1059
- package/lib/types/factories/UniswapV3Adapter__factory.d.ts +0 -47
- package/lib/types/factories/UniswapV3Adapter__factory.js +0 -322
- package/lib/types/factories/WETHGateway__factory.d.ts +0 -70
- package/lib/types/factories/WETHGateway__factory.js +0 -241
- package/lib/types/factories/WETHMock__factory.d.ts +0 -52
- package/lib/types/factories/WETHMock__factory.js +0 -355
- package/lib/types/factories/WadRayMathTest__factory.d.ts +0 -32
- package/lib/types/factories/WadRayMathTest__factory.js +0 -239
- package/lib/types/factories/YearnAdapter__factory.d.ts +0 -56
- package/lib/types/factories/YearnAdapter__factory.js +0 -497
- package/lib/types/factories/YearnMock__factory.d.ts +0 -56
- package/lib/types/factories/YearnMock__factory.js +0 -598
- package/lib/types/factories/YearnPriceFeed__factory.d.ts +0 -56
- package/lib/types/factories/YearnPriceFeed__factory.js +0 -350
- package/lib/types/factories/contracts/support/PathFinder__factory.d.ts +0 -63
- package/lib/types/factories/contracts/support/PathFinder__factory.js +0 -319
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/ClaimZapFormatter__factory.d.ts +0 -34
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/ClaimZapFormatter__factory.js +0 -124
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/index.d.ts +0 -1
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexClaimZapFormatter.sol/index.js +0 -8
package/lib/core/pathfinder.js
DELETED
|
@@ -1,612 +0,0 @@
|
|
|
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 (_) 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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.YearnVaultOfMetaCurveLPPathAsset = exports.YearnVaultOfCurveLPPathAsset = exports.NormalTokenPathAsset = exports.MetaCurveLPPathAsset = exports.CurveLPPathAsset = exports.ConvexLPTokenPathAsset = exports.YearnVaultPathAsset = exports.ConnectorPathAsset = exports.Path = void 0;
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
41
|
-
var token_1 = require("./token");
|
|
42
|
-
var constants_1 = require("./constants");
|
|
43
|
-
var types_1 = require("../types");
|
|
44
|
-
var contracts_1 = require("./contracts");
|
|
45
|
-
var tradeTypes_1 = require("./tradeTypes");
|
|
46
|
-
// const path = new Path({gasUsed:0, balances: creditAccount.balances, })
|
|
47
|
-
// const closurePath = await path.getBestPath();
|
|
48
|
-
// closurePath.calls -> multicalls (!)
|
|
49
|
-
// closurePath.balances[path.pool] = (X)
|
|
50
|
-
// closurePath.balances[!path.pool] = 0 / 1;
|
|
51
|
-
var Path = /** @class */ (function () {
|
|
52
|
-
function Path(opts) {
|
|
53
|
-
this.calls = [];
|
|
54
|
-
this.balances = opts.balances;
|
|
55
|
-
this.pool = opts.pool;
|
|
56
|
-
this.creditManager = opts.creditManager;
|
|
57
|
-
this.creditAccount = opts.creditAccount;
|
|
58
|
-
this.networkType = opts.networkType;
|
|
59
|
-
this.provider = opts.provider;
|
|
60
|
-
this.totalGasLimit = opts.totalGasLimit;
|
|
61
|
-
}
|
|
62
|
-
Path.prototype.getBestPath = function () {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var existingTokens, nextToken, _a, connectorPathAsset, yearnVaultPathAsset, convexLPTokenPathAsset, curveLPPathAsset, metaCurveLPPathAsset, normalTokenPathAsset, yearnVaultOfCurveLPPathAsset, yearnVaultOfMetaCurveLPPathAsset;
|
|
65
|
-
return __generator(this, function (_b) {
|
|
66
|
-
switch (_b.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
existingTokens = Object.entries(this.balances).filter(function (_a) {
|
|
69
|
-
var balance = _a[1];
|
|
70
|
-
return balance.gt(1);
|
|
71
|
-
}).sort(function (_a, _b) {
|
|
72
|
-
var tokenA = _a[0];
|
|
73
|
-
var tokenB = _b[0];
|
|
74
|
-
if (token_1.priority[token_1.supportedTokens[tokenA].type] > token_1.priority[token_1.supportedTokens[tokenB].type]) {
|
|
75
|
-
return -1;
|
|
76
|
-
}
|
|
77
|
-
else if (token_1.priority[token_1.supportedTokens[tokenA].type] < token_1.priority[token_1.supportedTokens[tokenB].type]) {
|
|
78
|
-
return 1;
|
|
79
|
-
}
|
|
80
|
-
return 0;
|
|
81
|
-
});
|
|
82
|
-
if (existingTokens.length == 1) {
|
|
83
|
-
return [2 /*return*/, Promise.resolve(this)];
|
|
84
|
-
}
|
|
85
|
-
nextToken = existingTokens.at(0)[0];
|
|
86
|
-
_a = token_1.supportedTokens[nextToken].type;
|
|
87
|
-
switch (_a) {
|
|
88
|
-
case token_1.TokenType.CONNECTOR: return [3 /*break*/, 1];
|
|
89
|
-
case token_1.TokenType.YEARN_VAULT: return [3 /*break*/, 3];
|
|
90
|
-
case token_1.TokenType.CONVEX_LP_TOKEN: return [3 /*break*/, 5];
|
|
91
|
-
case token_1.TokenType.CURVE_LP: return [3 /*break*/, 7];
|
|
92
|
-
case token_1.TokenType.META_CURVE_LP: return [3 /*break*/, 9];
|
|
93
|
-
case token_1.TokenType.NORMAL_TOKEN: return [3 /*break*/, 11];
|
|
94
|
-
case token_1.TokenType.YEARN_VAULT_OF_CURVE_LP: return [3 /*break*/, 13];
|
|
95
|
-
case token_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP: return [3 /*break*/, 15];
|
|
96
|
-
}
|
|
97
|
-
return [3 /*break*/, 17];
|
|
98
|
-
case 1:
|
|
99
|
-
connectorPathAsset = new ConnectorPathAsset();
|
|
100
|
-
return [4 /*yield*/, connectorPathAsset.getBestPath(nextToken, this)];
|
|
101
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
102
|
-
case 3:
|
|
103
|
-
yearnVaultPathAsset = new YearnVaultPathAsset();
|
|
104
|
-
return [4 /*yield*/, yearnVaultPathAsset.getBestPath(nextToken, this)];
|
|
105
|
-
case 4: return [2 /*return*/, _b.sent()];
|
|
106
|
-
case 5:
|
|
107
|
-
convexLPTokenPathAsset = new ConvexLPTokenPathAsset();
|
|
108
|
-
return [4 /*yield*/, convexLPTokenPathAsset.getBestPath(nextToken, this)];
|
|
109
|
-
case 6: return [2 /*return*/, _b.sent()];
|
|
110
|
-
case 7:
|
|
111
|
-
curveLPPathAsset = new CurveLPPathAsset();
|
|
112
|
-
return [4 /*yield*/, curveLPPathAsset.getBestPath(nextToken, this)];
|
|
113
|
-
case 8: return [2 /*return*/, _b.sent()];
|
|
114
|
-
case 9:
|
|
115
|
-
metaCurveLPPathAsset = new MetaCurveLPPathAsset();
|
|
116
|
-
return [4 /*yield*/, metaCurveLPPathAsset.getBestPath(nextToken, this)];
|
|
117
|
-
case 10: return [2 /*return*/, _b.sent()];
|
|
118
|
-
case 11:
|
|
119
|
-
normalTokenPathAsset = new NormalTokenPathAsset();
|
|
120
|
-
return [4 /*yield*/, normalTokenPathAsset.getBestPath(nextToken, this)];
|
|
121
|
-
case 12: return [2 /*return*/, _b.sent()];
|
|
122
|
-
case 13:
|
|
123
|
-
yearnVaultOfCurveLPPathAsset = new YearnVaultOfCurveLPPathAsset();
|
|
124
|
-
return [4 /*yield*/, yearnVaultOfCurveLPPathAsset.getBestPath(nextToken, this)];
|
|
125
|
-
case 14: return [2 /*return*/, _b.sent()];
|
|
126
|
-
case 15:
|
|
127
|
-
yearnVaultOfMetaCurveLPPathAsset = new YearnVaultOfMetaCurveLPPathAsset();
|
|
128
|
-
return [4 /*yield*/, yearnVaultOfMetaCurveLPPathAsset.getBestPath(nextToken, this)];
|
|
129
|
-
case 16: return [2 /*return*/, _b.sent()];
|
|
130
|
-
case 17: throw new Error("Token type not supported yet");
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
return Path;
|
|
136
|
-
}());
|
|
137
|
-
exports.Path = Path;
|
|
138
|
-
var ConnectorPathAsset = /** @class */ (function () {
|
|
139
|
-
function ConnectorPathAsset() {
|
|
140
|
-
}
|
|
141
|
-
ConnectorPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
142
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
143
|
-
var currentBalance, currentTokenAddress, currentTokenData, nextToken, nextTokenAddress, deadline, callData, gasLimit, maxAmountOut, _i, _a, swapAction, actionType, actionContract, actionContractAddress, adapterAddress, call, amountOut, gasLimitTmp, _b, uniswapV2Adapter, path, amountsOut, uniswapV3Adapter, iQuoter, exactInputSingleOrder, curve3CrvPool, currentIndex, outputIndex;
|
|
144
|
-
return __generator(this, function (_c) {
|
|
145
|
-
switch (_c.label) {
|
|
146
|
-
case 0:
|
|
147
|
-
currentBalance = p.balances[currentToken].sub(1);
|
|
148
|
-
currentTokenAddress = token_1.tokenDataByNetwork[p.networkType][currentToken];
|
|
149
|
-
currentTokenData = token_1.supportedTokens[currentToken];
|
|
150
|
-
nextToken = p.pool;
|
|
151
|
-
nextTokenAddress = token_1.tokenDataByNetwork[p.networkType][nextToken];
|
|
152
|
-
deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
153
|
-
callData = {
|
|
154
|
-
targetContract: constants_1.ADDRESS_0x0,
|
|
155
|
-
callData: ""
|
|
156
|
-
};
|
|
157
|
-
gasLimit = ethers_1.BigNumber.from(0);
|
|
158
|
-
maxAmountOut = ethers_1.BigNumber.from(0);
|
|
159
|
-
_i = 0, _a = currentTokenData.swapActions;
|
|
160
|
-
_c.label = 1;
|
|
161
|
-
case 1:
|
|
162
|
-
if (!(_i < _a.length)) return [3 /*break*/, 15];
|
|
163
|
-
swapAction = _a[_i];
|
|
164
|
-
actionType = swapAction.type;
|
|
165
|
-
actionContract = swapAction.contract;
|
|
166
|
-
actionContractAddress = contracts_1.contractsByNetwork[p.networkType][actionContract];
|
|
167
|
-
adapterAddress = p.creditManager.adapters[actionContractAddress];
|
|
168
|
-
call = {
|
|
169
|
-
targetContract: constants_1.ADDRESS_0x0,
|
|
170
|
-
callData: ""
|
|
171
|
-
};
|
|
172
|
-
amountOut = ethers_1.BigNumber.from(0);
|
|
173
|
-
gasLimitTmp = ethers_1.BigNumber.from(0);
|
|
174
|
-
_b = actionType;
|
|
175
|
-
switch (_b) {
|
|
176
|
-
case tradeTypes_1.TradeType.UniswapV2Swap: return [3 /*break*/, 2];
|
|
177
|
-
case tradeTypes_1.TradeType.UniswapV3Swap: return [3 /*break*/, 5];
|
|
178
|
-
case tradeTypes_1.TradeType.CurveExchange: return [3 /*break*/, 8];
|
|
179
|
-
}
|
|
180
|
-
return [3 /*break*/, 12];
|
|
181
|
-
case 2:
|
|
182
|
-
uniswapV2Adapter = types_1.UniswapV2Adapter__factory.connect(adapterAddress, p.provider);
|
|
183
|
-
path = [currentTokenAddress, nextTokenAddress];
|
|
184
|
-
return [4 /*yield*/, uniswapV2Adapter.getAmountsOut(currentBalance, path)];
|
|
185
|
-
case 3:
|
|
186
|
-
amountsOut = _c.sent();
|
|
187
|
-
amountOut = amountsOut[amountsOut.length - 1];
|
|
188
|
-
call = {
|
|
189
|
-
targetContract: adapterAddress,
|
|
190
|
-
callData: types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [currentBalance, amountOut, path, p.creditAccount.addr, deadline])
|
|
191
|
-
};
|
|
192
|
-
return [4 /*yield*/, uniswapV2Adapter.estimateGas.swapExactTokensForTokens(currentBalance, amountOut, path, p.creditAccount.addr, deadline)];
|
|
193
|
-
case 4:
|
|
194
|
-
gasLimitTmp = _c.sent();
|
|
195
|
-
return [3 /*break*/, 13];
|
|
196
|
-
case 5:
|
|
197
|
-
uniswapV3Adapter = types_1.UniswapV3Adapter__factory.connect(adapterAddress, p.provider);
|
|
198
|
-
iQuoter = types_1.IQuoter__factory.connect(contracts_1.UNISWAP_V3_QUOTER, p.provider);
|
|
199
|
-
return [4 /*yield*/, iQuoter.callStatic.quoteExactInputSingle(currentTokenAddress, nextTokenAddress, 3000, currentBalance, 0)];
|
|
200
|
-
case 6:
|
|
201
|
-
amountOut = _c.sent();
|
|
202
|
-
exactInputSingleOrder = {
|
|
203
|
-
"tokenIn": currentTokenAddress,
|
|
204
|
-
"tokenOut": nextTokenAddress,
|
|
205
|
-
"fee": 3000,
|
|
206
|
-
"recipient": p.creditAccount.addr,
|
|
207
|
-
"amountIn": currentBalance,
|
|
208
|
-
"amountOutMinimum": amountOut,
|
|
209
|
-
"deadline": deadline,
|
|
210
|
-
"sqrtPriceLimitX96": 0
|
|
211
|
-
};
|
|
212
|
-
call = {
|
|
213
|
-
targetContract: adapterAddress,
|
|
214
|
-
callData: types_1.UniswapV3Adapter__factory.createInterface().encodeFunctionData("exactInputSingle", [exactInputSingleOrder])
|
|
215
|
-
};
|
|
216
|
-
return [4 /*yield*/, uniswapV3Adapter.estimateGas.exactInputSingle(exactInputSingleOrder)];
|
|
217
|
-
case 7:
|
|
218
|
-
gasLimitTmp = _c.sent();
|
|
219
|
-
return [3 /*break*/, 13];
|
|
220
|
-
case 8:
|
|
221
|
-
if (!swapAction.tokenOut.includes(p.pool)) return [3 /*break*/, 11];
|
|
222
|
-
curve3CrvPool = types_1.CurveV1Adapter__factory.connect(adapterAddress, p.provider);
|
|
223
|
-
currentIndex = token_1.Curve3CrvUnderlyingTokenIndex[currentToken];
|
|
224
|
-
outputIndex = token_1.Curve3CrvUnderlyingTokenIndex[p.pool];
|
|
225
|
-
return [4 /*yield*/, curve3CrvPool.get_dy_underlying(currentIndex, outputIndex, currentBalance)];
|
|
226
|
-
case 9:
|
|
227
|
-
amountOut = _c.sent();
|
|
228
|
-
call = {
|
|
229
|
-
targetContract: adapterAddress,
|
|
230
|
-
callData: types_1.CurveV1Adapter__factory.createInterface().encodeFunctionData("exchange_underlying", [currentIndex, outputIndex, currentBalance, amountOut])
|
|
231
|
-
};
|
|
232
|
-
return [4 /*yield*/, curve3CrvPool.estimateGas.exchange_underlying(currentIndex, outputIndex, currentBalance, amountOut)];
|
|
233
|
-
case 10:
|
|
234
|
-
gasLimitTmp = _c.sent();
|
|
235
|
-
_c.label = 11;
|
|
236
|
-
case 11: return [3 /*break*/, 13];
|
|
237
|
-
case 12: throw Error("TradeType not supported. ".concat(actionType));
|
|
238
|
-
case 13:
|
|
239
|
-
if (amountOut > maxAmountOut) {
|
|
240
|
-
callData = call;
|
|
241
|
-
maxAmountOut = amountOut;
|
|
242
|
-
gasLimit = gasLimitTmp;
|
|
243
|
-
}
|
|
244
|
-
_c.label = 14;
|
|
245
|
-
case 14:
|
|
246
|
-
_i++;
|
|
247
|
-
return [3 /*break*/, 1];
|
|
248
|
-
case 15:
|
|
249
|
-
if (callData.targetContract != constants_1.ADDRESS_0x0) {
|
|
250
|
-
p.balances[nextToken].add(maxAmountOut);
|
|
251
|
-
p.balances[currentToken] = ethers_1.BigNumber.from(1);
|
|
252
|
-
p.totalGasLimit.add(gasLimit);
|
|
253
|
-
p.calls.push(callData);
|
|
254
|
-
}
|
|
255
|
-
return [4 /*yield*/, p.getBestPath()];
|
|
256
|
-
case 16: return [2 /*return*/, _c.sent()];
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
// Only compute the maximum amount of pool token output, will not modify p.
|
|
262
|
-
ConnectorPathAsset.prototype.getMaxPoolAmount = function (currentToken, currentBalance, p) {
|
|
263
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
-
var currentTokenAddress, currentTokenData, nextToken, nextTokenAddress, deadline, gasLimit, maxAmountOut, _i, _a, swapAction, actionType, actionContract, actionContractAddress, adapterAddress, amountOut, gasLimitTmp, _b, uniswapV2Adapter, path, amountsOut, uniswapV3Adapter, iQuoter, exactInputSingleOrder, curve3CrvPool, currentIndex, outputIndex;
|
|
265
|
-
return __generator(this, function (_c) {
|
|
266
|
-
switch (_c.label) {
|
|
267
|
-
case 0:
|
|
268
|
-
currentTokenAddress = token_1.tokenDataByNetwork[p.networkType][currentToken];
|
|
269
|
-
currentTokenData = token_1.supportedTokens[currentToken];
|
|
270
|
-
nextToken = p.pool;
|
|
271
|
-
nextTokenAddress = token_1.tokenDataByNetwork[p.networkType][nextToken];
|
|
272
|
-
deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
273
|
-
gasLimit = ethers_1.BigNumber.from(0);
|
|
274
|
-
maxAmountOut = ethers_1.BigNumber.from(0);
|
|
275
|
-
_i = 0, _a = currentTokenData.swapActions;
|
|
276
|
-
_c.label = 1;
|
|
277
|
-
case 1:
|
|
278
|
-
if (!(_i < _a.length)) return [3 /*break*/, 15];
|
|
279
|
-
swapAction = _a[_i];
|
|
280
|
-
actionType = swapAction.type;
|
|
281
|
-
actionContract = swapAction.contract;
|
|
282
|
-
actionContractAddress = contracts_1.contractsByNetwork[p.networkType][actionContract];
|
|
283
|
-
adapterAddress = p.creditManager.adapters[actionContractAddress];
|
|
284
|
-
amountOut = ethers_1.BigNumber.from(0);
|
|
285
|
-
gasLimitTmp = ethers_1.BigNumber.from(0);
|
|
286
|
-
_b = actionType;
|
|
287
|
-
switch (_b) {
|
|
288
|
-
case tradeTypes_1.TradeType.UniswapV2Swap: return [3 /*break*/, 2];
|
|
289
|
-
case tradeTypes_1.TradeType.UniswapV3Swap: return [3 /*break*/, 5];
|
|
290
|
-
case tradeTypes_1.TradeType.CurveExchange: return [3 /*break*/, 8];
|
|
291
|
-
}
|
|
292
|
-
return [3 /*break*/, 12];
|
|
293
|
-
case 2:
|
|
294
|
-
uniswapV2Adapter = types_1.UniswapV2Adapter__factory.connect(adapterAddress, p.provider);
|
|
295
|
-
path = [currentTokenAddress, nextTokenAddress];
|
|
296
|
-
return [4 /*yield*/, uniswapV2Adapter.getAmountsOut(currentBalance, path)];
|
|
297
|
-
case 3:
|
|
298
|
-
amountsOut = _c.sent();
|
|
299
|
-
amountOut = amountsOut[amountsOut.length - 1];
|
|
300
|
-
return [4 /*yield*/, uniswapV2Adapter.estimateGas.swapExactTokensForTokens(currentBalance, amountOut, path, p.creditAccount.addr, deadline)];
|
|
301
|
-
case 4:
|
|
302
|
-
gasLimitTmp = _c.sent();
|
|
303
|
-
return [3 /*break*/, 13];
|
|
304
|
-
case 5:
|
|
305
|
-
uniswapV3Adapter = types_1.UniswapV3Adapter__factory.connect(adapterAddress, p.provider);
|
|
306
|
-
iQuoter = types_1.IQuoter__factory.connect(contracts_1.UNISWAP_V3_QUOTER, p.provider);
|
|
307
|
-
return [4 /*yield*/, iQuoter.callStatic.quoteExactInputSingle(currentTokenAddress, nextTokenAddress, 3000, currentBalance, 0)];
|
|
308
|
-
case 6:
|
|
309
|
-
amountOut = _c.sent();
|
|
310
|
-
exactInputSingleOrder = {
|
|
311
|
-
"tokenIn": currentTokenAddress,
|
|
312
|
-
"tokenOut": nextTokenAddress,
|
|
313
|
-
"fee": 3000,
|
|
314
|
-
"recipient": p.creditAccount.addr,
|
|
315
|
-
"amountIn": currentBalance,
|
|
316
|
-
"amountOutMinimum": amountOut,
|
|
317
|
-
"deadline": deadline,
|
|
318
|
-
"sqrtPriceLimitX96": 0
|
|
319
|
-
};
|
|
320
|
-
return [4 /*yield*/, uniswapV3Adapter.estimateGas.exactInputSingle(exactInputSingleOrder)];
|
|
321
|
-
case 7:
|
|
322
|
-
gasLimitTmp = _c.sent();
|
|
323
|
-
return [3 /*break*/, 13];
|
|
324
|
-
case 8:
|
|
325
|
-
if (!swapAction.tokenOut.includes(nextToken)) return [3 /*break*/, 11];
|
|
326
|
-
curve3CrvPool = types_1.CurveV1Adapter__factory.connect(adapterAddress, p.provider);
|
|
327
|
-
currentIndex = token_1.Curve3CrvUnderlyingTokenIndex[currentToken];
|
|
328
|
-
outputIndex = token_1.Curve3CrvUnderlyingTokenIndex[nextToken];
|
|
329
|
-
return [4 /*yield*/, curve3CrvPool.get_dy_underlying(currentIndex, outputIndex, currentBalance)];
|
|
330
|
-
case 9:
|
|
331
|
-
amountOut = _c.sent();
|
|
332
|
-
return [4 /*yield*/, curve3CrvPool.estimateGas.exchange_underlying(currentIndex, outputIndex, currentBalance, amountOut)];
|
|
333
|
-
case 10:
|
|
334
|
-
gasLimitTmp = _c.sent();
|
|
335
|
-
_c.label = 11;
|
|
336
|
-
case 11: return [3 /*break*/, 13];
|
|
337
|
-
case 12: throw Error("TradeType not supported. ".concat(actionType));
|
|
338
|
-
case 13:
|
|
339
|
-
if (amountOut > maxAmountOut) {
|
|
340
|
-
maxAmountOut = amountOut;
|
|
341
|
-
gasLimit = gasLimitTmp;
|
|
342
|
-
}
|
|
343
|
-
_c.label = 14;
|
|
344
|
-
case 14:
|
|
345
|
-
_i++;
|
|
346
|
-
return [3 /*break*/, 1];
|
|
347
|
-
case 15: return [2 /*return*/, [maxAmountOut, gasLimit]];
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
return ConnectorPathAsset;
|
|
353
|
-
}());
|
|
354
|
-
exports.ConnectorPathAsset = ConnectorPathAsset;
|
|
355
|
-
var YearnVaultPathAsset = /** @class */ (function () {
|
|
356
|
-
function YearnVaultPathAsset() {
|
|
357
|
-
}
|
|
358
|
-
YearnVaultPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
359
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
360
|
-
var currentBalance, currentTokenData, allowedContract, outputToken, adapterAddress, call, IYVault, price, gasLimit;
|
|
361
|
-
return __generator(this, function (_a) {
|
|
362
|
-
switch (_a.label) {
|
|
363
|
-
case 0:
|
|
364
|
-
currentBalance = p.balances[currentToken].sub(1);
|
|
365
|
-
currentTokenData = token_1.supportedTokens[currentToken];
|
|
366
|
-
allowedContract = contracts_1.contractsByNetwork[p.networkType][currentTokenData.lpActions[0].contract];
|
|
367
|
-
outputToken = currentTokenData.lpActions[0].tokenOut;
|
|
368
|
-
adapterAddress = p.creditManager.adapters[allowedContract];
|
|
369
|
-
call = {
|
|
370
|
-
targetContract: adapterAddress,
|
|
371
|
-
callData: types_1.YearnAdapter__factory.createInterface().encodeFunctionData('withdraw', [currentBalance, p.creditAccount.addr])
|
|
372
|
-
};
|
|
373
|
-
IYVault = types_1.YearnAdapter__factory.connect(allowedContract, p.provider);
|
|
374
|
-
return [4 /*yield*/, IYVault.pricePerShare()];
|
|
375
|
-
case 1:
|
|
376
|
-
price = _a.sent();
|
|
377
|
-
return [4 /*yield*/, IYVault.estimateGas["withdraw(uint256,address)"](currentBalance, p.creditAccount.addr)];
|
|
378
|
-
case 2:
|
|
379
|
-
gasLimit = _a.sent();
|
|
380
|
-
p.balances[outputToken].add(price.mul(currentBalance));
|
|
381
|
-
p.balances[currentToken] = ethers_1.BigNumber.from(1);
|
|
382
|
-
p.totalGasLimit.add(gasLimit);
|
|
383
|
-
p.calls.push(call);
|
|
384
|
-
return [4 /*yield*/, p.getBestPath()];
|
|
385
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
return YearnVaultPathAsset;
|
|
391
|
-
}());
|
|
392
|
-
exports.YearnVaultPathAsset = YearnVaultPathAsset;
|
|
393
|
-
var ConvexLPTokenPathAsset = /** @class */ (function () {
|
|
394
|
-
function ConvexLPTokenPathAsset() {
|
|
395
|
-
}
|
|
396
|
-
ConvexLPTokenPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
397
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
398
|
-
var currentBalance, currentTokenData, _i, _a, lpAction, actionContractAddress, adapterAddress, outputToken;
|
|
399
|
-
return __generator(this, function (_b) {
|
|
400
|
-
switch (_b.label) {
|
|
401
|
-
case 0: throw Error("Implementation not finished!");
|
|
402
|
-
case 1: return [2 /*return*/, _b.sent()];
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
};
|
|
407
|
-
return ConvexLPTokenPathAsset;
|
|
408
|
-
}());
|
|
409
|
-
exports.ConvexLPTokenPathAsset = ConvexLPTokenPathAsset;
|
|
410
|
-
var CurveLPPathAsset = /** @class */ (function () {
|
|
411
|
-
function CurveLPPathAsset() {
|
|
412
|
-
}
|
|
413
|
-
CurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
414
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
415
|
-
return __generator(this, function (_a) {
|
|
416
|
-
console.log(currentToken);
|
|
417
|
-
console.log(p);
|
|
418
|
-
throw Error("Not implemented yet.");
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
};
|
|
422
|
-
return CurveLPPathAsset;
|
|
423
|
-
}());
|
|
424
|
-
exports.CurveLPPathAsset = CurveLPPathAsset;
|
|
425
|
-
var MetaCurveLPPathAsset = /** @class */ (function () {
|
|
426
|
-
function MetaCurveLPPathAsset() {
|
|
427
|
-
}
|
|
428
|
-
MetaCurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
429
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
430
|
-
return __generator(this, function (_a) {
|
|
431
|
-
console.log(currentToken);
|
|
432
|
-
console.log(p);
|
|
433
|
-
throw Error("Not implemented yet.");
|
|
434
|
-
});
|
|
435
|
-
});
|
|
436
|
-
};
|
|
437
|
-
return MetaCurveLPPathAsset;
|
|
438
|
-
}());
|
|
439
|
-
exports.MetaCurveLPPathAsset = MetaCurveLPPathAsset;
|
|
440
|
-
var NormalTokenPathAsset = /** @class */ (function () {
|
|
441
|
-
function NormalTokenPathAsset() {
|
|
442
|
-
}
|
|
443
|
-
NormalTokenPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
444
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
445
|
-
var currentBalance, currentTokenAddress, currentTokenData, deadline, callData, nextToken, gasLimit, maxAmountOut, _i, ConnectorTokens_1, connToken, connTokenAddress, _a, _b, swapAction, actionType, actionContract, actionContractAddress, adapterAddress, call, amountOut, gasLimitTmp, _c, uniswapV2Adapter, path, amountsOut, uniswapV3Adapter, iQuoter, exactInputSingleOrder, curve3CrvPool, currentIndex, outputIndex, connectorPathAsset, _d, maxPoolAmount, gasLimitConn;
|
|
446
|
-
return __generator(this, function (_e) {
|
|
447
|
-
switch (_e.label) {
|
|
448
|
-
case 0:
|
|
449
|
-
currentBalance = p.balances[currentToken].sub(1);
|
|
450
|
-
currentTokenAddress = token_1.tokenDataByNetwork[p.networkType][currentToken];
|
|
451
|
-
currentTokenData = token_1.supportedTokens[currentToken];
|
|
452
|
-
deadline = Math.floor(Date.now() / 1000) + 1200;
|
|
453
|
-
callData = {
|
|
454
|
-
targetContract: constants_1.ADDRESS_0x0,
|
|
455
|
-
callData: ""
|
|
456
|
-
};
|
|
457
|
-
nextToken = p.pool;
|
|
458
|
-
gasLimit = ethers_1.BigNumber.from(0);
|
|
459
|
-
maxAmountOut = ethers_1.BigNumber.from(0);
|
|
460
|
-
_i = 0, ConnectorTokens_1 = token_1.ConnectorTokens;
|
|
461
|
-
_e.label = 1;
|
|
462
|
-
case 1:
|
|
463
|
-
if (!(_i < ConnectorTokens_1.length)) return [3 /*break*/, 19];
|
|
464
|
-
connToken = ConnectorTokens_1[_i];
|
|
465
|
-
connTokenAddress = token_1.tokenDataByNetwork[p.networkType][connToken];
|
|
466
|
-
_a = 0, _b = currentTokenData.swapActions;
|
|
467
|
-
_e.label = 2;
|
|
468
|
-
case 2:
|
|
469
|
-
if (!(_a < _b.length)) return [3 /*break*/, 18];
|
|
470
|
-
swapAction = _b[_a];
|
|
471
|
-
actionType = swapAction.type;
|
|
472
|
-
actionContract = swapAction.contract;
|
|
473
|
-
actionContractAddress = contracts_1.contractsByNetwork[p.networkType][actionContract];
|
|
474
|
-
adapterAddress = p.creditManager.adapters[actionContractAddress];
|
|
475
|
-
call = {
|
|
476
|
-
targetContract: constants_1.ADDRESS_0x0,
|
|
477
|
-
callData: ""
|
|
478
|
-
};
|
|
479
|
-
amountOut = ethers_1.BigNumber.from(0);
|
|
480
|
-
gasLimitTmp = ethers_1.BigNumber.from(0);
|
|
481
|
-
_c = actionType;
|
|
482
|
-
switch (_c) {
|
|
483
|
-
case tradeTypes_1.TradeType.UniswapV2Swap: return [3 /*break*/, 3];
|
|
484
|
-
case tradeTypes_1.TradeType.UniswapV3Swap: return [3 /*break*/, 6];
|
|
485
|
-
case tradeTypes_1.TradeType.CurveExchange: return [3 /*break*/, 9];
|
|
486
|
-
}
|
|
487
|
-
return [3 /*break*/, 13];
|
|
488
|
-
case 3:
|
|
489
|
-
uniswapV2Adapter = types_1.UniswapV2Adapter__factory.connect(adapterAddress, p.provider);
|
|
490
|
-
path = [currentTokenAddress, connTokenAddress];
|
|
491
|
-
return [4 /*yield*/, uniswapV2Adapter.getAmountsOut(currentBalance, path)];
|
|
492
|
-
case 4:
|
|
493
|
-
amountsOut = _e.sent();
|
|
494
|
-
amountOut = amountsOut[amountsOut.length - 1];
|
|
495
|
-
call = {
|
|
496
|
-
targetContract: adapterAddress,
|
|
497
|
-
callData: types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [currentBalance, amountOut, path, p.creditAccount.addr, deadline])
|
|
498
|
-
};
|
|
499
|
-
return [4 /*yield*/, uniswapV2Adapter.estimateGas.swapExactTokensForTokens(currentBalance, amountOut, path, p.creditAccount.addr, deadline)];
|
|
500
|
-
case 5:
|
|
501
|
-
gasLimitTmp = _e.sent();
|
|
502
|
-
return [3 /*break*/, 14];
|
|
503
|
-
case 6:
|
|
504
|
-
uniswapV3Adapter = types_1.UniswapV3Adapter__factory.connect(adapterAddress, p.provider);
|
|
505
|
-
iQuoter = types_1.IQuoter__factory.connect(contracts_1.UNISWAP_V3_QUOTER, p.provider);
|
|
506
|
-
return [4 /*yield*/, iQuoter.callStatic.quoteExactInputSingle(currentTokenAddress, connTokenAddress, 3000, currentBalance, 0)];
|
|
507
|
-
case 7:
|
|
508
|
-
amountOut = _e.sent();
|
|
509
|
-
exactInputSingleOrder = {
|
|
510
|
-
"tokenIn": currentTokenAddress,
|
|
511
|
-
"tokenOut": connTokenAddress,
|
|
512
|
-
"fee": 3000,
|
|
513
|
-
"recipient": p.creditAccount.addr,
|
|
514
|
-
"amountIn": currentBalance,
|
|
515
|
-
"amountOutMinimum": amountOut,
|
|
516
|
-
"deadline": deadline,
|
|
517
|
-
"sqrtPriceLimitX96": 0
|
|
518
|
-
};
|
|
519
|
-
call = {
|
|
520
|
-
targetContract: adapterAddress,
|
|
521
|
-
callData: types_1.UniswapV3Adapter__factory.createInterface().encodeFunctionData("exactInputSingle", [exactInputSingleOrder])
|
|
522
|
-
};
|
|
523
|
-
return [4 /*yield*/, uniswapV3Adapter.estimateGas.exactInputSingle(exactInputSingleOrder)];
|
|
524
|
-
case 8:
|
|
525
|
-
gasLimitTmp = _e.sent();
|
|
526
|
-
return [3 /*break*/, 14];
|
|
527
|
-
case 9:
|
|
528
|
-
if (!swapAction.tokenOut.includes(connToken)) return [3 /*break*/, 12];
|
|
529
|
-
curve3CrvPool = types_1.CurveV1Adapter__factory.connect(adapterAddress, p.provider);
|
|
530
|
-
currentIndex = token_1.Curve3CrvUnderlyingTokenIndex[currentToken];
|
|
531
|
-
outputIndex = token_1.Curve3CrvUnderlyingTokenIndex[connToken];
|
|
532
|
-
return [4 /*yield*/, curve3CrvPool.get_dy_underlying(currentIndex, outputIndex, currentBalance)];
|
|
533
|
-
case 10:
|
|
534
|
-
amountOut = _e.sent();
|
|
535
|
-
call = {
|
|
536
|
-
targetContract: adapterAddress,
|
|
537
|
-
callData: types_1.CurveV1Adapter__factory.createInterface().encodeFunctionData("exchange_underlying", [currentIndex, outputIndex, currentBalance, amountOut])
|
|
538
|
-
};
|
|
539
|
-
return [4 /*yield*/, curve3CrvPool.estimateGas.exchange_underlying(currentIndex, outputIndex, currentBalance, amountOut)];
|
|
540
|
-
case 11:
|
|
541
|
-
gasLimitTmp = _e.sent();
|
|
542
|
-
_e.label = 12;
|
|
543
|
-
case 12: return [3 /*break*/, 14];
|
|
544
|
-
case 13: throw Error("TradeType not supported. ".concat(actionType));
|
|
545
|
-
case 14:
|
|
546
|
-
if (!(connToken != p.pool)) return [3 /*break*/, 16];
|
|
547
|
-
connectorPathAsset = new ConnectorPathAsset();
|
|
548
|
-
return [4 /*yield*/, connectorPathAsset.getMaxPoolAmount(connToken, amountOut, p)];
|
|
549
|
-
case 15:
|
|
550
|
-
_d = _e.sent(), maxPoolAmount = _d[0], gasLimitConn = _d[1];
|
|
551
|
-
amountOut = maxPoolAmount;
|
|
552
|
-
gasLimitTmp.add(gasLimitConn);
|
|
553
|
-
_e.label = 16;
|
|
554
|
-
case 16:
|
|
555
|
-
if (amountOut > maxAmountOut) {
|
|
556
|
-
callData = call;
|
|
557
|
-
maxAmountOut = amountOut;
|
|
558
|
-
gasLimit = gasLimitTmp;
|
|
559
|
-
}
|
|
560
|
-
_e.label = 17;
|
|
561
|
-
case 17:
|
|
562
|
-
_a++;
|
|
563
|
-
return [3 /*break*/, 2];
|
|
564
|
-
case 18:
|
|
565
|
-
_i++;
|
|
566
|
-
return [3 /*break*/, 1];
|
|
567
|
-
case 19:
|
|
568
|
-
if (callData.targetContract != constants_1.ADDRESS_0x0) {
|
|
569
|
-
p.balances[nextToken].add(maxAmountOut);
|
|
570
|
-
p.balances[currentToken] = ethers_1.BigNumber.from(1);
|
|
571
|
-
p.totalGasLimit.add(gasLimit);
|
|
572
|
-
p.calls.push(callData);
|
|
573
|
-
}
|
|
574
|
-
return [4 /*yield*/, p.getBestPath()];
|
|
575
|
-
case 20: return [2 /*return*/, _e.sent()];
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
});
|
|
579
|
-
};
|
|
580
|
-
return NormalTokenPathAsset;
|
|
581
|
-
}());
|
|
582
|
-
exports.NormalTokenPathAsset = NormalTokenPathAsset;
|
|
583
|
-
var YearnVaultOfCurveLPPathAsset = /** @class */ (function () {
|
|
584
|
-
function YearnVaultOfCurveLPPathAsset() {
|
|
585
|
-
}
|
|
586
|
-
YearnVaultOfCurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
587
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
588
|
-
return __generator(this, function (_a) {
|
|
589
|
-
console.log(currentToken);
|
|
590
|
-
console.log(p);
|
|
591
|
-
throw Error("Not implemented yet.");
|
|
592
|
-
});
|
|
593
|
-
});
|
|
594
|
-
};
|
|
595
|
-
return YearnVaultOfCurveLPPathAsset;
|
|
596
|
-
}());
|
|
597
|
-
exports.YearnVaultOfCurveLPPathAsset = YearnVaultOfCurveLPPathAsset;
|
|
598
|
-
var YearnVaultOfMetaCurveLPPathAsset = /** @class */ (function () {
|
|
599
|
-
function YearnVaultOfMetaCurveLPPathAsset() {
|
|
600
|
-
}
|
|
601
|
-
YearnVaultOfMetaCurveLPPathAsset.prototype.getBestPath = function (currentToken, p) {
|
|
602
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
603
|
-
return __generator(this, function (_a) {
|
|
604
|
-
console.log(currentToken);
|
|
605
|
-
console.log(p);
|
|
606
|
-
throw Error("Not implemented yet.");
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
};
|
|
610
|
-
return YearnVaultOfMetaCurveLPPathAsset;
|
|
611
|
-
}());
|
|
612
|
-
exports.YearnVaultOfMetaCurveLPPathAsset = YearnVaultOfMetaCurveLPPathAsset;
|