@guru-fund/sdk 0.1.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/LICENSE +21 -0
- package/README.md +226 -0
- package/dist/GuruProtocol.d.ts +44 -0
- package/dist/GuruProtocol.js +75 -0
- package/dist/addresses.d.ts +40 -0
- package/dist/addresses.js +111 -0
- package/dist/constants.d.ts +22 -0
- package/dist/constants.js +23 -0
- package/dist/helpers/FundDataFetcher.d.ts +24 -0
- package/dist/helpers/FundDataFetcher.js +66 -0
- package/dist/helpers/ReceiptParser.d.ts +23 -0
- package/dist/helpers/ReceiptParser.js +59 -0
- package/dist/helpers/Token.d.ts +18 -0
- package/dist/helpers/Token.js +43 -0
- package/dist/helpers/compareAddresses.d.ts +1 -0
- package/dist/helpers/compareAddresses.js +15 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +3 -0
- package/dist/quotes/quoteDeposit.d.ts +41 -0
- package/dist/quotes/quoteDeposit.js +186 -0
- package/dist/quotes/quoteHarvest.d.ts +34 -0
- package/dist/quotes/quoteHarvest.js +105 -0
- package/dist/quotes/quoteRebalance.d.ts +51 -0
- package/dist/quotes/quoteRebalance.js +201 -0
- package/dist/quotes/quoteTrade.d.ts +18 -0
- package/dist/quotes/quoteTrade.js +51 -0
- package/dist/quotes/quoteWithdrawal.d.ts +41 -0
- package/dist/quotes/quoteWithdrawal.js +113 -0
- package/dist/router/constants.d.ts +18 -0
- package/dist/router/constants.js +25 -0
- package/dist/router/finalizeRoute.d.ts +16 -0
- package/dist/router/finalizeRoute.js +29 -0
- package/dist/router/getFallbackRoutes.d.ts +10 -0
- package/dist/router/getFallbackRoutes.js +91 -0
- package/dist/router/getUniswapV4Route.d.ts +42 -0
- package/dist/router/getUniswapV4Route.js +324 -0
- package/dist/router/getVeloraRoute.d.ts +10 -0
- package/dist/router/getVeloraRoute.js +68 -0
- package/dist/router/helpers.d.ts +11 -0
- package/dist/router/helpers.js +30 -0
- package/dist/router/index.d.ts +22 -0
- package/dist/router/index.js +135 -0
- package/dist/router/pathCache.d.ts +16 -0
- package/dist/router/pathCache.js +116 -0
- package/dist/router/poolHelper.d.ts +126 -0
- package/dist/router/poolHelper.js +807 -0
- package/dist/router/quoteWethTrade.d.ts +14 -0
- package/dist/router/quoteWethTrade.js +125 -0
- package/dist/router/simulation.d.ts +43 -0
- package/dist/router/simulation.js +70 -0
- package/dist/router/types.d.ts +149 -0
- package/dist/router/types.js +1 -0
- package/dist/router/v4PoolDiscovery.d.ts +30 -0
- package/dist/router/v4PoolDiscovery.js +147 -0
- package/dist/router/velora.d.ts +42 -0
- package/dist/router/velora.js +279 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/schemas/index.js +6 -0
- package/dist/schemas/primitives.d.ts +3 -0
- package/dist/schemas/primitives.js +9 -0
- package/dist/schemas/quoteDeposit.d.ts +23 -0
- package/dist/schemas/quoteDeposit.js +10 -0
- package/dist/schemas/quoteHarvest.d.ts +17 -0
- package/dist/schemas/quoteHarvest.js +8 -0
- package/dist/schemas/quoteRebalance.d.ts +29 -0
- package/dist/schemas/quoteRebalance.js +10 -0
- package/dist/schemas/quoteTrade.d.ts +20 -0
- package/dist/schemas/quoteTrade.js +9 -0
- package/dist/schemas/quoteWithdrawal.d.ts +23 -0
- package/dist/schemas/quoteWithdrawal.js +10 -0
- package/dist/txBuilders/buildDepositTx.d.ts +17 -0
- package/dist/txBuilders/buildDepositTx.js +18 -0
- package/dist/txBuilders/buildHarvestTx.d.ts +16 -0
- package/dist/txBuilders/buildHarvestTx.js +17 -0
- package/dist/txBuilders/buildTradeTx.d.ts +9 -0
- package/dist/txBuilders/buildTradeTx.js +9 -0
- package/dist/txBuilders/buildWithdrawTx.d.ts +16 -0
- package/dist/txBuilders/buildWithdrawTx.js +17 -0
- package/dist/txBuilders/index.d.ts +8 -0
- package/dist/txBuilders/index.js +4 -0
- package/dist/typechain/common.d.ts +50 -0
- package/dist/typechain/common.js +1 -0
- package/dist/typechain/factories/include/IPancakeQuoterV2__factory.d.ts +225 -0
- package/dist/typechain/factories/include/IPancakeQuoterV2__factory.js +295 -0
- package/dist/typechain/factories/include/ISwapRouter02__factory.d.ts +826 -0
- package/dist/typechain/factories/include/ISwapRouter02__factory.js +1073 -0
- package/dist/typechain/factories/include/index.d.ts +2 -0
- package/dist/typechain/factories/include/index.js +2 -0
- package/dist/typechain/factories/index.d.ts +2 -0
- package/dist/typechain/factories/index.js +2 -0
- package/dist/typechain/factories/out/Adapter__factory.d.ts +31 -0
- package/dist/typechain/factories/out/Adapter__factory.js +43 -0
- package/dist/typechain/factories/out/AerodromeV2Adapter__factory.d.ts +179 -0
- package/dist/typechain/factories/out/AerodromeV2Adapter__factory.js +237 -0
- package/dist/typechain/factories/out/AerodromeV3Adapter__factory.d.ts +162 -0
- package/dist/typechain/factories/out/AerodromeV3Adapter__factory.js +215 -0
- package/dist/typechain/factories/out/AssetManager.sol/LedgerAssetManager__factory.d.ts +1032 -0
- package/dist/typechain/factories/out/AssetManager.sol/LedgerAssetManager__factory.js +1357 -0
- package/dist/typechain/factories/out/AssetManager.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/AssetManager.sol/index.js +1 -0
- package/dist/typechain/factories/out/Bookkeeper.sol/LedgerBookkeeper__factory.d.ts +950 -0
- package/dist/typechain/factories/out/Bookkeeper.sol/LedgerBookkeeper__factory.js +1250 -0
- package/dist/typechain/factories/out/Bookkeeper.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Bookkeeper.sol/index.js +1 -0
- package/dist/typechain/factories/out/Checkpoint.sol/CheckpointController__factory.d.ts +33 -0
- package/dist/typechain/factories/out/Checkpoint.sol/CheckpointController__factory.js +47 -0
- package/dist/typechain/factories/out/Checkpoint.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Checkpoint.sol/index.js +1 -0
- package/dist/typechain/factories/out/Closure.sol/ClosureController__factory.d.ts +459 -0
- package/dist/typechain/factories/out/Closure.sol/ClosureController__factory.js +603 -0
- package/dist/typechain/factories/out/Closure.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Closure.sol/index.js +1 -0
- package/dist/typechain/factories/out/ContextBuilder__factory.d.ts +671 -0
- package/dist/typechain/factories/out/ContextBuilder__factory.js +870 -0
- package/dist/typechain/factories/out/Control.sol/Controllable__factory.d.ts +107 -0
- package/dist/typechain/factories/out/Control.sol/Controllable__factory.js +141 -0
- package/dist/typechain/factories/out/Control.sol/Controller__factory.d.ts +21 -0
- package/dist/typechain/factories/out/Control.sol/Controller__factory.js +30 -0
- package/dist/typechain/factories/out/Control.sol/index.d.ts +2 -0
- package/dist/typechain/factories/out/Control.sol/index.js +2 -0
- package/dist/typechain/factories/out/Controller.sol/ClosureDelegate__factory.d.ts +57 -0
- package/dist/typechain/factories/out/Controller.sol/ClosureDelegate__factory.js +77 -0
- package/dist/typechain/factories/out/Controller.sol/CreationDelegate__factory.d.ts +58 -0
- package/dist/typechain/factories/out/Controller.sol/CreationDelegate__factory.js +77 -0
- package/dist/typechain/factories/out/Controller.sol/DepositDelegate__factory.d.ts +55 -0
- package/dist/typechain/factories/out/Controller.sol/DepositDelegate__factory.js +74 -0
- package/dist/typechain/factories/out/Controller.sol/FundController__factory.d.ts +703 -0
- package/dist/typechain/factories/out/Controller.sol/FundController__factory.js +911 -0
- package/dist/typechain/factories/out/Controller.sol/HarvestDelegate__factory.d.ts +234 -0
- package/dist/typechain/factories/out/Controller.sol/HarvestDelegate__factory.js +303 -0
- package/dist/typechain/factories/out/Controller.sol/TradeDelegate__factory.d.ts +61 -0
- package/dist/typechain/factories/out/Controller.sol/TradeDelegate__factory.js +81 -0
- package/dist/typechain/factories/out/Controller.sol/TransferDelegate__factory.d.ts +29 -0
- package/dist/typechain/factories/out/Controller.sol/TransferDelegate__factory.js +40 -0
- package/dist/typechain/factories/out/Controller.sol/WithdrawalDelegate__factory.d.ts +51 -0
- package/dist/typechain/factories/out/Controller.sol/WithdrawalDelegate__factory.js +69 -0
- package/dist/typechain/factories/out/Controller.sol/index.d.ts +8 -0
- package/dist/typechain/factories/out/Controller.sol/index.js +8 -0
- package/dist/typechain/factories/out/Cooldown.sol/LedgerCooldown__factory.d.ts +747 -0
- package/dist/typechain/factories/out/Cooldown.sol/LedgerCooldown__factory.js +982 -0
- package/dist/typechain/factories/out/Cooldown.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Cooldown.sol/index.js +1 -0
- package/dist/typechain/factories/out/Creation.sol/CreationController__factory.d.ts +172 -0
- package/dist/typechain/factories/out/Creation.sol/CreationController__factory.js +225 -0
- package/dist/typechain/factories/out/Creation.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Creation.sol/index.js +1 -0
- package/dist/typechain/factories/out/Deposit.sol/DepositController__factory.d.ts +162 -0
- package/dist/typechain/factories/out/Deposit.sol/DepositController__factory.js +223 -0
- package/dist/typechain/factories/out/Deposit.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Deposit.sol/index.js +1 -0
- package/dist/typechain/factories/out/Error__factory.d.ts +318 -0
- package/dist/typechain/factories/out/Error__factory.js +423 -0
- package/dist/typechain/factories/out/Harvest.sol/HarvestController__factory.d.ts +401 -0
- package/dist/typechain/factories/out/Harvest.sol/HarvestController__factory.js +527 -0
- package/dist/typechain/factories/out/Harvest.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Harvest.sol/index.js +1 -0
- package/dist/typechain/factories/out/IAerodromeRouter__factory.d.ts +85 -0
- package/dist/typechain/factories/out/IAerodromeRouter__factory.js +113 -0
- package/dist/typechain/factories/out/IAerodromeSwapRouter__factory.d.ts +89 -0
- package/dist/typechain/factories/out/IAerodromeSwapRouter__factory.js +119 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/IPermit2__factory.d.ts +29 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/IPermit2__factory.js +40 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/IUniversalRouter__factory.d.ts +25 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/IUniversalRouter__factory.js +35 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/index.d.ts +2 -0
- package/dist/typechain/factories/out/IUniswapV4.sol/index.js +2 -0
- package/dist/typechain/factories/out/IV0Fund__factory.d.ts +129 -0
- package/dist/typechain/factories/out/IV0Fund__factory.js +173 -0
- package/dist/typechain/factories/out/IV3SwapRouter__factory.d.ts +38 -0
- package/dist/typechain/factories/out/IV3SwapRouter__factory.js +53 -0
- package/dist/typechain/factories/out/Initializer.sol/LedgerInitializer__factory.d.ts +655 -0
- package/dist/typechain/factories/out/Initializer.sol/LedgerInitializer__factory.js +859 -0
- package/dist/typechain/factories/out/Initializer.sol/VaultInitializer__factory.d.ts +141 -0
- package/dist/typechain/factories/out/Initializer.sol/VaultInitializer__factory.js +185 -0
- package/dist/typechain/factories/out/Initializer.sol/index.d.ts +2 -0
- package/dist/typechain/factories/out/Initializer.sol/index.js +2 -0
- package/dist/typechain/factories/out/Ledger.sol/FundLedger__factory.d.ts +1502 -0
- package/dist/typechain/factories/out/Ledger.sol/FundLedger__factory.js +1959 -0
- package/dist/typechain/factories/out/Ledger.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Ledger.sol/index.js +1 -0
- package/dist/typechain/factories/out/LotusP2P__factory.d.ts +847 -0
- package/dist/typechain/factories/out/LotusP2P__factory.js +1095 -0
- package/dist/typechain/factories/out/MulticallStatic__factory.d.ts +29 -0
- package/dist/typechain/factories/out/MulticallStatic__factory.js +42 -0
- package/dist/typechain/factories/out/Operator.sol/VaultOperator__factory.d.ts +235 -0
- package/dist/typechain/factories/out/Operator.sol/VaultOperator__factory.js +308 -0
- package/dist/typechain/factories/out/Operator.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Operator.sol/index.js +1 -0
- package/dist/typechain/factories/out/P2PAdapter__factory.d.ts +216 -0
- package/dist/typechain/factories/out/P2PAdapter__factory.js +287 -0
- package/dist/typechain/factories/out/ProtocolMigrationExtension__factory.d.ts +1084 -0
- package/dist/typechain/factories/out/ProtocolMigrationExtension__factory.js +1409 -0
- package/dist/typechain/factories/out/ProtocolProvider__factory.d.ts +21 -0
- package/dist/typechain/factories/out/ProtocolProvider__factory.js +30 -0
- package/dist/typechain/factories/out/Protocol__factory.d.ts +1095 -0
- package/dist/typechain/factories/out/Protocol__factory.js +1424 -0
- package/dist/typechain/factories/out/Registrar.sol/LedgerRegistrar__factory.d.ts +1375 -0
- package/dist/typechain/factories/out/Registrar.sol/LedgerRegistrar__factory.js +1791 -0
- package/dist/typechain/factories/out/Registrar.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Registrar.sol/index.js +1 -0
- package/dist/typechain/factories/out/Settings.sol/SettingsController__factory.d.ts +143 -0
- package/dist/typechain/factories/out/Settings.sol/SettingsController__factory.js +188 -0
- package/dist/typechain/factories/out/Settings.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Settings.sol/index.js +1 -0
- package/dist/typechain/factories/out/Shares.sol/ICheckpointController__factory.d.ts +21 -0
- package/dist/typechain/factories/out/Shares.sol/ICheckpointController__factory.js +31 -0
- package/dist/typechain/factories/out/Shares.sol/ITransferController__factory.d.ts +25 -0
- package/dist/typechain/factories/out/Shares.sol/ITransferController__factory.js +35 -0
- package/dist/typechain/factories/out/Shares.sol/LedgerShares__factory.d.ts +829 -0
- package/dist/typechain/factories/out/Shares.sol/LedgerShares__factory.js +1089 -0
- package/dist/typechain/factories/out/Shares.sol/index.d.ts +3 -0
- package/dist/typechain/factories/out/Shares.sol/index.js +3 -0
- package/dist/typechain/factories/out/SignatureVerifier__factory.d.ts +171 -0
- package/dist/typechain/factories/out/SignatureVerifier__factory.js +224 -0
- package/dist/typechain/factories/out/Storage.sol/LedgerStorage__factory.d.ts +527 -0
- package/dist/typechain/factories/out/Storage.sol/LedgerStorage__factory.js +695 -0
- package/dist/typechain/factories/out/Storage.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Storage.sol/index.js +1 -0
- package/dist/typechain/factories/out/Trade.sol/TradeController__factory.d.ts +200 -0
- package/dist/typechain/factories/out/Trade.sol/TradeController__factory.js +262 -0
- package/dist/typechain/factories/out/Trade.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Trade.sol/index.js +1 -0
- package/dist/typechain/factories/out/Transfer.sol/TransferController__factory.d.ts +100 -0
- package/dist/typechain/factories/out/Transfer.sol/TransferController__factory.js +141 -0
- package/dist/typechain/factories/out/Transfer.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Transfer.sol/index.js +1 -0
- package/dist/typechain/factories/out/UniswapV2Adapter__factory.d.ts +162 -0
- package/dist/typechain/factories/out/UniswapV2Adapter__factory.js +215 -0
- package/dist/typechain/factories/out/UniswapV3Adapter__factory.d.ts +162 -0
- package/dist/typechain/factories/out/UniswapV3Adapter__factory.js +215 -0
- package/dist/typechain/factories/out/UniswapV3SwapRouter02Adapter__factory.d.ts +162 -0
- package/dist/typechain/factories/out/UniswapV3SwapRouter02Adapter__factory.js +215 -0
- package/dist/typechain/factories/out/UniswapV4Adapter__factory.d.ts +203 -0
- package/dist/typechain/factories/out/UniswapV4Adapter__factory.js +268 -0
- package/dist/typechain/factories/out/V0ToLotusMigrator__factory.d.ts +216 -0
- package/dist/typechain/factories/out/V0ToLotusMigrator__factory.js +284 -0
- package/dist/typechain/factories/out/Vault.sol/FundVault__factory.d.ts +258 -0
- package/dist/typechain/factories/out/Vault.sol/FundVault__factory.js +339 -0
- package/dist/typechain/factories/out/Vault.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Vault.sol/index.js +1 -0
- package/dist/typechain/factories/out/Withdrawal.sol/WithdrawalController__factory.d.ts +285 -0
- package/dist/typechain/factories/out/Withdrawal.sol/WithdrawalController__factory.js +377 -0
- package/dist/typechain/factories/out/Withdrawal.sol/index.d.ts +1 -0
- package/dist/typechain/factories/out/Withdrawal.sol/index.js +1 -0
- package/dist/typechain/factories/out/index.d.ts +43 -0
- package/dist/typechain/factories/out/index.js +43 -0
- package/dist/typechain/include/IPancakeQuoterV2.d.ts +223 -0
- package/dist/typechain/include/IPancakeQuoterV2.js +1 -0
- package/dist/typechain/include/ISwapRouter02.d.ts +682 -0
- package/dist/typechain/include/ISwapRouter02.js +1 -0
- package/dist/typechain/include/index.d.ts +2 -0
- package/dist/typechain/include/index.js +1 -0
- package/dist/typechain/index.d.ts +119 -0
- package/dist/typechain/index.js +58 -0
- package/dist/typechain/out/Adapter.d.ts +29 -0
- package/dist/typechain/out/Adapter.js +1 -0
- package/dist/typechain/out/AerodromeV2Adapter.d.ts +106 -0
- package/dist/typechain/out/AerodromeV2Adapter.js +1 -0
- package/dist/typechain/out/AerodromeV3Adapter.d.ts +87 -0
- package/dist/typechain/out/AerodromeV3Adapter.js +1 -0
- package/dist/typechain/out/AssetManager.sol/LedgerAssetManager.d.ts +604 -0
- package/dist/typechain/out/AssetManager.sol/LedgerAssetManager.js +1 -0
- package/dist/typechain/out/AssetManager.sol/index.d.ts +1 -0
- package/dist/typechain/out/AssetManager.sol/index.js +1 -0
- package/dist/typechain/out/Bookkeeper.sol/LedgerBookkeeper.d.ts +548 -0
- package/dist/typechain/out/Bookkeeper.sol/LedgerBookkeeper.js +1 -0
- package/dist/typechain/out/Bookkeeper.sol/index.d.ts +1 -0
- package/dist/typechain/out/Bookkeeper.sol/index.js +1 -0
- package/dist/typechain/out/Checkpoint.sol/CheckpointController.d.ts +29 -0
- package/dist/typechain/out/Checkpoint.sol/CheckpointController.js +1 -0
- package/dist/typechain/out/Checkpoint.sol/index.d.ts +1 -0
- package/dist/typechain/out/Checkpoint.sol/index.js +1 -0
- package/dist/typechain/out/Closure.sol/ClosureController.d.ts +273 -0
- package/dist/typechain/out/Closure.sol/ClosureController.js +1 -0
- package/dist/typechain/out/Closure.sol/index.d.ts +1 -0
- package/dist/typechain/out/Closure.sol/index.js +1 -0
- package/dist/typechain/out/ContextBuilder.d.ts +403 -0
- package/dist/typechain/out/ContextBuilder.js +1 -0
- package/dist/typechain/out/Control.sol/Controllable.d.ts +97 -0
- package/dist/typechain/out/Control.sol/Controllable.js +1 -0
- package/dist/typechain/out/Control.sol/Controller.d.ts +25 -0
- package/dist/typechain/out/Control.sol/Controller.js +1 -0
- package/dist/typechain/out/Control.sol/index.d.ts +2 -0
- package/dist/typechain/out/Control.sol/index.js +1 -0
- package/dist/typechain/out/Controller.sol/ClosureDelegate.d.ts +61 -0
- package/dist/typechain/out/Controller.sol/ClosureDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/CreationDelegate.d.ts +61 -0
- package/dist/typechain/out/Controller.sol/CreationDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/DepositDelegate.d.ts +56 -0
- package/dist/typechain/out/Controller.sol/DepositDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/FundController.d.ts +464 -0
- package/dist/typechain/out/Controller.sol/FundController.js +1 -0
- package/dist/typechain/out/Controller.sol/HarvestDelegate.d.ts +163 -0
- package/dist/typechain/out/Controller.sol/HarvestDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/TradeDelegate.d.ts +67 -0
- package/dist/typechain/out/Controller.sol/TradeDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/TransferDelegate.d.ts +37 -0
- package/dist/typechain/out/Controller.sol/TransferDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/WithdrawalDelegate.d.ts +53 -0
- package/dist/typechain/out/Controller.sol/WithdrawalDelegate.js +1 -0
- package/dist/typechain/out/Controller.sol/index.d.ts +8 -0
- package/dist/typechain/out/Controller.sol/index.js +1 -0
- package/dist/typechain/out/Cooldown.sol/LedgerCooldown.d.ts +446 -0
- package/dist/typechain/out/Cooldown.sol/LedgerCooldown.js +1 -0
- package/dist/typechain/out/Cooldown.sol/index.d.ts +1 -0
- package/dist/typechain/out/Cooldown.sol/index.js +1 -0
- package/dist/typechain/out/Creation.sol/CreationController.d.ts +102 -0
- package/dist/typechain/out/Creation.sol/CreationController.js +1 -0
- package/dist/typechain/out/Creation.sol/index.d.ts +1 -0
- package/dist/typechain/out/Creation.sol/index.js +1 -0
- package/dist/typechain/out/Deposit.sol/DepositController.d.ts +68 -0
- package/dist/typechain/out/Deposit.sol/DepositController.js +1 -0
- package/dist/typechain/out/Deposit.sol/index.d.ts +1 -0
- package/dist/typechain/out/Deposit.sol/index.js +1 -0
- package/dist/typechain/out/Error.d.ts +20 -0
- package/dist/typechain/out/Error.js +1 -0
- package/dist/typechain/out/Harvest.sol/HarvestController.d.ts +241 -0
- package/dist/typechain/out/Harvest.sol/HarvestController.js +1 -0
- package/dist/typechain/out/Harvest.sol/index.d.ts +1 -0
- package/dist/typechain/out/Harvest.sol/index.js +1 -0
- package/dist/typechain/out/IAerodromeRouter.d.ts +80 -0
- package/dist/typechain/out/IAerodromeRouter.js +1 -0
- package/dist/typechain/out/IAerodromeSwapRouter.d.ts +96 -0
- package/dist/typechain/out/IAerodromeSwapRouter.js +1 -0
- package/dist/typechain/out/IUniswapV4.sol/IPermit2.d.ts +39 -0
- package/dist/typechain/out/IUniswapV4.sol/IPermit2.js +1 -0
- package/dist/typechain/out/IUniswapV4.sol/IUniversalRouter.d.ts +37 -0
- package/dist/typechain/out/IUniswapV4.sol/IUniversalRouter.js +1 -0
- package/dist/typechain/out/IUniswapV4.sol/index.d.ts +2 -0
- package/dist/typechain/out/IUniswapV4.sol/index.js +1 -0
- package/dist/typechain/out/IV0Fund.d.ts +69 -0
- package/dist/typechain/out/IV0Fund.js +1 -0
- package/dist/typechain/out/IV3SwapRouter.d.ts +52 -0
- package/dist/typechain/out/IV3SwapRouter.js +1 -0
- package/dist/typechain/out/Initializer.sol/LedgerInitializer.d.ts +379 -0
- package/dist/typechain/out/Initializer.sol/LedgerInitializer.js +1 -0
- package/dist/typechain/out/Initializer.sol/VaultInitializer.d.ts +129 -0
- package/dist/typechain/out/Initializer.sol/VaultInitializer.js +1 -0
- package/dist/typechain/out/Initializer.sol/index.d.ts +2 -0
- package/dist/typechain/out/Initializer.sol/index.js +1 -0
- package/dist/typechain/out/Ledger.sol/FundLedger.d.ts +926 -0
- package/dist/typechain/out/Ledger.sol/FundLedger.js +1 -0
- package/dist/typechain/out/Ledger.sol/index.d.ts +1 -0
- package/dist/typechain/out/Ledger.sol/index.js +1 -0
- package/dist/typechain/out/LotusP2P.d.ts +610 -0
- package/dist/typechain/out/LotusP2P.js +1 -0
- package/dist/typechain/out/MulticallStatic.d.ts +25 -0
- package/dist/typechain/out/MulticallStatic.js +1 -0
- package/dist/typechain/out/Operator.sol/VaultOperator.d.ts +197 -0
- package/dist/typechain/out/Operator.sol/VaultOperator.js +1 -0
- package/dist/typechain/out/Operator.sol/index.d.ts +1 -0
- package/dist/typechain/out/Operator.sol/index.js +1 -0
- package/dist/typechain/out/P2PAdapter.d.ts +100 -0
- package/dist/typechain/out/P2PAdapter.js +1 -0
- package/dist/typechain/out/Protocol.d.ts +815 -0
- package/dist/typechain/out/Protocol.js +1 -0
- package/dist/typechain/out/ProtocolMigrationExtension.d.ts +806 -0
- package/dist/typechain/out/ProtocolMigrationExtension.js +1 -0
- package/dist/typechain/out/ProtocolProvider.d.ts +25 -0
- package/dist/typechain/out/ProtocolProvider.js +1 -0
- package/dist/typechain/out/Registrar.sol/LedgerRegistrar.d.ts +866 -0
- package/dist/typechain/out/Registrar.sol/LedgerRegistrar.js +1 -0
- package/dist/typechain/out/Registrar.sol/index.d.ts +1 -0
- package/dist/typechain/out/Registrar.sol/index.js +1 -0
- package/dist/typechain/out/Settings.sol/SettingsController.d.ts +97 -0
- package/dist/typechain/out/Settings.sol/SettingsController.js +1 -0
- package/dist/typechain/out/Settings.sol/index.d.ts +1 -0
- package/dist/typechain/out/Settings.sol/index.js +1 -0
- package/dist/typechain/out/Shares.sol/ICheckpointController.d.ts +29 -0
- package/dist/typechain/out/Shares.sol/ICheckpointController.js +1 -0
- package/dist/typechain/out/Shares.sol/ITransferController.d.ts +37 -0
- package/dist/typechain/out/Shares.sol/ITransferController.js +1 -0
- package/dist/typechain/out/Shares.sol/LedgerShares.d.ts +494 -0
- package/dist/typechain/out/Shares.sol/LedgerShares.js +1 -0
- package/dist/typechain/out/Shares.sol/index.d.ts +3 -0
- package/dist/typechain/out/Shares.sol/index.js +1 -0
- package/dist/typechain/out/SignatureVerifier.d.ts +139 -0
- package/dist/typechain/out/SignatureVerifier.js +1 -0
- package/dist/typechain/out/Storage.sol/LedgerStorage.d.ts +281 -0
- package/dist/typechain/out/Storage.sol/LedgerStorage.js +1 -0
- package/dist/typechain/out/Storage.sol/index.d.ts +1 -0
- package/dist/typechain/out/Storage.sol/index.js +1 -0
- package/dist/typechain/out/Trade.sol/TradeController.d.ts +137 -0
- package/dist/typechain/out/Trade.sol/TradeController.js +1 -0
- package/dist/typechain/out/Trade.sol/index.d.ts +1 -0
- package/dist/typechain/out/Trade.sol/index.js +1 -0
- package/dist/typechain/out/Transfer.sol/TransferController.d.ts +49 -0
- package/dist/typechain/out/Transfer.sol/TransferController.js +1 -0
- package/dist/typechain/out/Transfer.sol/index.d.ts +1 -0
- package/dist/typechain/out/Transfer.sol/index.js +1 -0
- package/dist/typechain/out/UniswapV2Adapter.d.ts +87 -0
- package/dist/typechain/out/UniswapV2Adapter.js +1 -0
- package/dist/typechain/out/UniswapV3Adapter.d.ts +87 -0
- package/dist/typechain/out/UniswapV3Adapter.js +1 -0
- package/dist/typechain/out/UniswapV3SwapRouter02Adapter.d.ts +87 -0
- package/dist/typechain/out/UniswapV3SwapRouter02Adapter.js +1 -0
- package/dist/typechain/out/UniswapV4Adapter.d.ts +110 -0
- package/dist/typechain/out/UniswapV4Adapter.js +1 -0
- package/dist/typechain/out/V0ToLotusMigrator.d.ts +94 -0
- package/dist/typechain/out/V0ToLotusMigrator.js +1 -0
- package/dist/typechain/out/Vault.sol/FundVault.d.ts +197 -0
- package/dist/typechain/out/Vault.sol/FundVault.js +1 -0
- package/dist/typechain/out/Vault.sol/index.d.ts +1 -0
- package/dist/typechain/out/Vault.sol/index.js +1 -0
- package/dist/typechain/out/Withdrawal.sol/WithdrawalController.d.ts +152 -0
- package/dist/typechain/out/Withdrawal.sol/WithdrawalController.js +1 -0
- package/dist/typechain/out/Withdrawal.sol/index.d.ts +1 -0
- package/dist/typechain/out/Withdrawal.sol/index.js +1 -0
- package/dist/typechain/out/index.d.ts +65 -0
- package/dist/typechain/out/index.js +1 -0
- package/dist/types/Fund.d.ts +27 -0
- package/dist/types/Fund.js +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
import { getGuruProtocolAddresses, } from '../addresses.js';
|
|
3
|
+
import { TOLL_DIVISOR_20BPS } from '../constants.js';
|
|
4
|
+
import { FundVault__factory, UniswapV4Adapter__factory } from '../typechain/index.js';
|
|
5
|
+
import { SWAP_DEADLINE_SECONDS, V4_ZERO_ADDRESS } from './constants.js';
|
|
6
|
+
import { finalizeRouteQuote } from './finalizeRoute.js';
|
|
7
|
+
import { resolveBaseToll } from './helpers.js';
|
|
8
|
+
import { discoverV4Paths } from './v4PoolDiscovery.js';
|
|
9
|
+
const V4_QUOTER_ABI = [
|
|
10
|
+
'function quoteExactInput((address exactCurrency, (address intermediateCurrency, uint24 fee, int24 tickSpacing, address hooks, bytes hookData)[] path, uint128 exactAmount) params) external returns (uint256 amountOut, uint256 gasEstimate)',
|
|
11
|
+
];
|
|
12
|
+
const V4_HOOK_ADAPTER_ABI = [
|
|
13
|
+
'function executeSwap((uint256 amountToSend,uint256 amountToReceive,address currencyIn,address currencyOut,(address inputCurrency,address intermediateCurrency,uint24 fee,int24 tickSpacing,address hook,bytes hookData)[] path,uint256 deadline) swap) returns ((address tokenIn,address tokenOut,uint256 amountIn,uint256 amountOut) trade)',
|
|
14
|
+
];
|
|
15
|
+
const V4_HOOK_LOCKED_SELECTOR = '0x0f2e5b6c';
|
|
16
|
+
export function connectV4Quoter(address, provider) {
|
|
17
|
+
return new Contract(address, V4_QUOTER_ABI, provider);
|
|
18
|
+
}
|
|
19
|
+
export function toAdapterPathKeys(path) {
|
|
20
|
+
return path.map((hop) => ({
|
|
21
|
+
intermediateCurrency: hop.tokenOut,
|
|
22
|
+
fee: hop.fee,
|
|
23
|
+
tickSpacing: hop.tickSpacing,
|
|
24
|
+
hooks: hop.hooks,
|
|
25
|
+
hookData: hop.hookData,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
function isV4HookLockedError(reason) {
|
|
29
|
+
const seen = new Set();
|
|
30
|
+
const stack = [reason];
|
|
31
|
+
while (stack.length > 0) {
|
|
32
|
+
const current = stack.pop();
|
|
33
|
+
if (typeof current === 'string' &&
|
|
34
|
+
current.toLowerCase().includes(V4_HOOK_LOCKED_SELECTOR)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (typeof current !== 'object' || current === null)
|
|
38
|
+
continue;
|
|
39
|
+
if (seen.has(current))
|
|
40
|
+
continue;
|
|
41
|
+
seen.add(current);
|
|
42
|
+
for (const key of Object.getOwnPropertyNames(current)) {
|
|
43
|
+
stack.push(current[key]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
export function applyV4Toll({ baseToll, quotedAmountToReceive, quoteSource, swapAmountIn, }) {
|
|
49
|
+
const toll = { ...baseToll };
|
|
50
|
+
let amountQuoted = quotedAmountToReceive;
|
|
51
|
+
let amountToSend = swapAmountIn;
|
|
52
|
+
let initialTollAmount = toll.amount;
|
|
53
|
+
if (toll.amount === 0n) {
|
|
54
|
+
if (quoteSource === 'quoter') {
|
|
55
|
+
toll.amount = quotedAmountToReceive / TOLL_DIVISOR_20BPS;
|
|
56
|
+
amountQuoted -= toll.amount;
|
|
57
|
+
}
|
|
58
|
+
initialTollAmount = 0n;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
amountToSend += toll.amount;
|
|
62
|
+
}
|
|
63
|
+
return { toll, amountQuoted, amountToSend, initialTollAmount };
|
|
64
|
+
}
|
|
65
|
+
async function previewV4AdapterOutput({ provider, controller, vault, adapter, tokenIn, amountToSend, path, deadline, }) {
|
|
66
|
+
const adapterIface = UniswapV4Adapter__factory.createInterface();
|
|
67
|
+
const vaultIface = FundVault__factory.createInterface();
|
|
68
|
+
const swapCallData = adapterIface.encodeFunctionData('executeSwap', [
|
|
69
|
+
{
|
|
70
|
+
amountToSend,
|
|
71
|
+
amountToReceive: 0n,
|
|
72
|
+
currencyIn: tokenIn,
|
|
73
|
+
path: toAdapterPathKeys(path),
|
|
74
|
+
deadline,
|
|
75
|
+
},
|
|
76
|
+
]);
|
|
77
|
+
const vaultCallData = vaultIface.encodeFunctionData('execute', [
|
|
78
|
+
adapter,
|
|
79
|
+
swapCallData,
|
|
80
|
+
]);
|
|
81
|
+
const encodedReturn = await provider.call({
|
|
82
|
+
from: controller,
|
|
83
|
+
to: vault,
|
|
84
|
+
data: vaultCallData,
|
|
85
|
+
});
|
|
86
|
+
const [adapterReturn] = vaultIface.decodeFunctionResult('execute', encodedReturn);
|
|
87
|
+
const [trade] = adapterIface.decodeFunctionResult('executeSwap', adapterReturn);
|
|
88
|
+
return BigInt(trade.amountOut);
|
|
89
|
+
}
|
|
90
|
+
export function toHookAdapterPathKeys(path) {
|
|
91
|
+
return path.map((hop) => ({
|
|
92
|
+
inputCurrency: hop.tokenIn,
|
|
93
|
+
intermediateCurrency: hop.tokenOut,
|
|
94
|
+
fee: hop.fee,
|
|
95
|
+
tickSpacing: hop.tickSpacing,
|
|
96
|
+
hook: hop.hooks,
|
|
97
|
+
hookData: hop.hookData,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
function resolveHookCurrencyOut(tokenOut, path) {
|
|
101
|
+
const lastHop = path[path.length - 1];
|
|
102
|
+
if (!lastHop)
|
|
103
|
+
return tokenOut;
|
|
104
|
+
return lastHop.tokenOut === V4_ZERO_ADDRESS ? tokenOut : lastHop.tokenOut;
|
|
105
|
+
}
|
|
106
|
+
function encodeV4HookAdapterSwap(swap) {
|
|
107
|
+
return new Contract(V4_ZERO_ADDRESS, V4_HOOK_ADAPTER_ABI).interface.encodeFunctionData('executeSwap', [swap]);
|
|
108
|
+
}
|
|
109
|
+
async function previewV4HookAdapterOutput({ provider, controller, vault, adapter, tokenIn, tokenOut, amountToSend, path, deadline, }) {
|
|
110
|
+
const hookAdapterIface = new Contract(V4_ZERO_ADDRESS, V4_HOOK_ADAPTER_ABI).interface;
|
|
111
|
+
const vaultIface = FundVault__factory.createInterface();
|
|
112
|
+
const swap = {
|
|
113
|
+
amountToSend,
|
|
114
|
+
amountToReceive: 0n,
|
|
115
|
+
currencyIn: tokenIn,
|
|
116
|
+
currencyOut: resolveHookCurrencyOut(tokenOut, path),
|
|
117
|
+
path: toHookAdapterPathKeys(path),
|
|
118
|
+
deadline,
|
|
119
|
+
};
|
|
120
|
+
const swapCallData = hookAdapterIface.encodeFunctionData('executeSwap', [
|
|
121
|
+
swap,
|
|
122
|
+
]);
|
|
123
|
+
const vaultCallData = vaultIface.encodeFunctionData('execute', [
|
|
124
|
+
adapter,
|
|
125
|
+
swapCallData,
|
|
126
|
+
]);
|
|
127
|
+
const encodedReturn = await provider.call({
|
|
128
|
+
from: controller,
|
|
129
|
+
to: vault,
|
|
130
|
+
data: vaultCallData,
|
|
131
|
+
});
|
|
132
|
+
const [adapterReturn] = vaultIface.decodeFunctionResult('execute', encodedReturn);
|
|
133
|
+
const [trade] = hookAdapterIface.decodeFunctionResult('executeSwap', adapterReturn);
|
|
134
|
+
return BigInt(trade.amountOut);
|
|
135
|
+
}
|
|
136
|
+
async function previewBestV4AdapterQuote(params) {
|
|
137
|
+
const previews = await Promise.allSettled(params.candidates.map((path) => previewV4AdapterOutput({ ...params, path })));
|
|
138
|
+
let best = null;
|
|
139
|
+
previews.forEach((result, i) => {
|
|
140
|
+
if (result.status !== 'fulfilled')
|
|
141
|
+
return;
|
|
142
|
+
const amountToReceive = result.value;
|
|
143
|
+
if (amountToReceive === 0n)
|
|
144
|
+
return;
|
|
145
|
+
if (!best || amountToReceive > best.amountToReceive) {
|
|
146
|
+
best = {
|
|
147
|
+
path: params.candidates[i],
|
|
148
|
+
amountToReceive,
|
|
149
|
+
source: 'adapter-preview',
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return best;
|
|
154
|
+
}
|
|
155
|
+
async function previewBestV4HookAdapterQuote(params) {
|
|
156
|
+
const previews = await Promise.allSettled(params.candidates.map((path) => previewV4HookAdapterOutput({ ...params, path })));
|
|
157
|
+
let best = null;
|
|
158
|
+
let sawLockedHook = false;
|
|
159
|
+
let sawHookFailure = false;
|
|
160
|
+
previews.forEach((result, i) => {
|
|
161
|
+
if (result.status !== 'fulfilled') {
|
|
162
|
+
sawLockedHook ||= isV4HookLockedError(result.reason);
|
|
163
|
+
sawHookFailure ||= params.candidates[i].some((hop) => hop.hooks !== V4_ZERO_ADDRESS);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const amountToReceive = result.value;
|
|
167
|
+
if (amountToReceive === 0n)
|
|
168
|
+
return;
|
|
169
|
+
if (!best || amountToReceive > best.amountToReceive) {
|
|
170
|
+
best = {
|
|
171
|
+
path: params.candidates[i],
|
|
172
|
+
amountToReceive,
|
|
173
|
+
source: 'adapter-preview',
|
|
174
|
+
adapter: params.adapter,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
if (!best && sawLockedHook) {
|
|
179
|
+
throw new Error('TOKEN_LOCKED_BY_V4_HOOK');
|
|
180
|
+
}
|
|
181
|
+
if (!best && sawHookFailure) {
|
|
182
|
+
throw new Error('UNISWAP_V4_HOOK_ROUTE_REVERTED');
|
|
183
|
+
}
|
|
184
|
+
return best;
|
|
185
|
+
}
|
|
186
|
+
export default async function getUniswapV4Route(params, ctx) {
|
|
187
|
+
const { chainId, tokenIn, tokenOut, amountIn, slippageE2, vault, account, prefixTxs, } = params;
|
|
188
|
+
const { provider, simulator } = ctx;
|
|
189
|
+
const addresses = getGuruProtocolAddresses(chainId);
|
|
190
|
+
const adapter = addresses.adapters.uniswapV4;
|
|
191
|
+
const hookAdapter = addresses.adapters.uniswapV4Hook;
|
|
192
|
+
const quoterAddress = addresses.quoters.uniswapV4;
|
|
193
|
+
if (!adapter || !quoterAddress) {
|
|
194
|
+
throw new Error(`UniswapV4 not supported on chainId ${chainId}`);
|
|
195
|
+
}
|
|
196
|
+
const maxSlippageE3 = slippageE2 != null ? BigInt(slippageE2) * 10n : undefined;
|
|
197
|
+
const { baseToll, swapAmountIn } = resolveBaseToll(addresses, tokenIn, tokenOut, amountIn);
|
|
198
|
+
const candidates = await discoverV4Paths(chainId, tokenIn, tokenOut, provider);
|
|
199
|
+
if (candidates.length === 0) {
|
|
200
|
+
throw new Error('NO_UNISWAP_V4_ROUTES_FOUND');
|
|
201
|
+
}
|
|
202
|
+
const quoter = connectV4Quoter(quoterAddress, provider);
|
|
203
|
+
const deadline = Math.floor(Date.now() / 1000) + SWAP_DEADLINE_SECONDS;
|
|
204
|
+
const [quotes, blockNumber, controller] = await Promise.all([
|
|
205
|
+
Promise.allSettled(candidates.map((path) => quoter.quoteExactInput.staticCall({
|
|
206
|
+
exactCurrency: tokenIn,
|
|
207
|
+
path: toAdapterPathKeys(path),
|
|
208
|
+
exactAmount: swapAmountIn,
|
|
209
|
+
}))),
|
|
210
|
+
provider.getBlockNumber(),
|
|
211
|
+
FundVault__factory.connect(vault, provider).controller(),
|
|
212
|
+
]);
|
|
213
|
+
let bestQuote = null;
|
|
214
|
+
quotes.forEach((result, i) => {
|
|
215
|
+
if (result.status !== 'fulfilled')
|
|
216
|
+
return;
|
|
217
|
+
const [amountOut] = result.value;
|
|
218
|
+
if (!bestQuote || amountOut > bestQuote.amountToReceive) {
|
|
219
|
+
bestQuote = {
|
|
220
|
+
path: candidates[i],
|
|
221
|
+
amountToReceive: amountOut,
|
|
222
|
+
source: 'quoter',
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
if (!bestQuote && !prefixTxs?.length) {
|
|
227
|
+
bestQuote = await previewBestV4AdapterQuote({
|
|
228
|
+
provider,
|
|
229
|
+
controller,
|
|
230
|
+
vault,
|
|
231
|
+
adapter,
|
|
232
|
+
tokenIn,
|
|
233
|
+
amountToSend: baseToll.amount === 0n ? swapAmountIn : amountIn,
|
|
234
|
+
deadline,
|
|
235
|
+
candidates,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (!bestQuote && hookAdapter && !prefixTxs?.length) {
|
|
239
|
+
bestQuote = await previewBestV4HookAdapterQuote({
|
|
240
|
+
provider,
|
|
241
|
+
controller,
|
|
242
|
+
vault,
|
|
243
|
+
adapter: hookAdapter,
|
|
244
|
+
tokenIn,
|
|
245
|
+
tokenOut,
|
|
246
|
+
amountToSend: baseToll.amount === 0n ? swapAmountIn : amountIn,
|
|
247
|
+
deadline,
|
|
248
|
+
candidates,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (!bestQuote || bestQuote.amountToReceive === 0n) {
|
|
252
|
+
throw new Error('NO_UNISWAP_V4_ROUTES_FOUND');
|
|
253
|
+
}
|
|
254
|
+
const selectedAdapter = bestQuote.adapter ?? adapter;
|
|
255
|
+
const bestPath = bestQuote.path;
|
|
256
|
+
const { toll, amountQuoted, amountToSend, initialTollAmount } = applyV4Toll({
|
|
257
|
+
baseToll,
|
|
258
|
+
quotedAmountToReceive: bestQuote.amountToReceive,
|
|
259
|
+
quoteSource: bestQuote.source,
|
|
260
|
+
swapAmountIn,
|
|
261
|
+
});
|
|
262
|
+
const pathKeys = toAdapterPathKeys(bestPath);
|
|
263
|
+
const hookPathKeys = toHookAdapterPathKeys(bestPath);
|
|
264
|
+
const buildCallDataForAmount = (amountToReceive) => selectedAdapter === hookAdapter
|
|
265
|
+
? encodeV4HookAdapterSwap({
|
|
266
|
+
amountToSend,
|
|
267
|
+
amountToReceive,
|
|
268
|
+
currencyIn: tokenIn,
|
|
269
|
+
currencyOut: resolveHookCurrencyOut(tokenOut, bestPath),
|
|
270
|
+
path: hookPathKeys,
|
|
271
|
+
deadline,
|
|
272
|
+
})
|
|
273
|
+
: UniswapV4Adapter__factory.createInterface().encodeFunctionData('executeSwap', [
|
|
274
|
+
{
|
|
275
|
+
amountToSend,
|
|
276
|
+
amountToReceive,
|
|
277
|
+
currencyIn: tokenIn,
|
|
278
|
+
path: pathKeys,
|
|
279
|
+
deadline,
|
|
280
|
+
},
|
|
281
|
+
]);
|
|
282
|
+
const context = {
|
|
283
|
+
chainId,
|
|
284
|
+
blockNumber,
|
|
285
|
+
controller,
|
|
286
|
+
vault,
|
|
287
|
+
adapter: selectedAdapter,
|
|
288
|
+
account,
|
|
289
|
+
path: bestPath,
|
|
290
|
+
buildCallDataForAmount,
|
|
291
|
+
simulator,
|
|
292
|
+
prefixTxs,
|
|
293
|
+
};
|
|
294
|
+
const { finalAmountToReceive, callData, effectiveSlippageBps, finalTollAmount, } = await finalizeRouteQuote({
|
|
295
|
+
context,
|
|
296
|
+
amountToSend,
|
|
297
|
+
amountQuoted,
|
|
298
|
+
initialTollAmount,
|
|
299
|
+
maxSlippageE3,
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
adapter: selectedAdapter,
|
|
303
|
+
data: selectedAdapter === hookAdapter
|
|
304
|
+
? {
|
|
305
|
+
amountToSend,
|
|
306
|
+
amountToReceive: finalAmountToReceive,
|
|
307
|
+
currencyIn: tokenIn,
|
|
308
|
+
currencyOut: resolveHookCurrencyOut(tokenOut, bestPath),
|
|
309
|
+
path: hookPathKeys,
|
|
310
|
+
deadline,
|
|
311
|
+
}
|
|
312
|
+
: {
|
|
313
|
+
amountToSend,
|
|
314
|
+
amountToReceive: finalAmountToReceive,
|
|
315
|
+
currencyIn: tokenIn,
|
|
316
|
+
path: pathKeys,
|
|
317
|
+
deadline,
|
|
318
|
+
},
|
|
319
|
+
callData,
|
|
320
|
+
toll: { ...toll, amount: finalTollAmount },
|
|
321
|
+
hops: bestPath.length,
|
|
322
|
+
effectiveSlippageBps,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Provider } from 'ethers';
|
|
2
|
+
import type { PathFetcher } from './pathCache';
|
|
3
|
+
import type { SwapSimulator } from './simulation';
|
|
4
|
+
import type { Route, RouteSearchParams } from './types';
|
|
5
|
+
export interface GetVeloraRouteContext {
|
|
6
|
+
provider: Provider;
|
|
7
|
+
simulator: SwapSimulator;
|
|
8
|
+
getPath: PathFetcher;
|
|
9
|
+
}
|
|
10
|
+
export default function getVeloraRoute(params: RouteSearchParams, ctx: GetVeloraRouteContext): Promise<Route>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getGuruProtocolAddresses, } from '../addresses.js';
|
|
2
|
+
import { Token } from '../helpers/Token.js';
|
|
3
|
+
import { FundVault__factory } from '../typechain/index.js';
|
|
4
|
+
import { MAX_ROUTE_HOPS, SUPPORTED_DEXS } from './constants.js';
|
|
5
|
+
import { resolveBaseToll } from './helpers.js';
|
|
6
|
+
import { getRouteFromPath, isDexConfigured } from './velora.js';
|
|
7
|
+
async function fetchDecimals(token, provider) {
|
|
8
|
+
const { decimals } = await new Token(token, provider)
|
|
9
|
+
.metadata()
|
|
10
|
+
.catch(() => ({ decimals: 0 }));
|
|
11
|
+
return decimals;
|
|
12
|
+
}
|
|
13
|
+
export default async function getVeloraRoute(params, ctx) {
|
|
14
|
+
const { chainId, tokenIn, tokenInDecimals, tokenOut, tokenOutDecimals, amountIn, slippageE2, vault, account, prefixTxs, } = params;
|
|
15
|
+
const { provider, simulator, getPath } = ctx;
|
|
16
|
+
const addresses = getGuruProtocolAddresses(chainId);
|
|
17
|
+
const maxSlippageE3 = slippageE2 != null ? BigInt(slippageE2) * 10n : undefined;
|
|
18
|
+
const [srcDecimals, destDecimals, controller] = await Promise.all([
|
|
19
|
+
tokenInDecimals ?? fetchDecimals(tokenIn, provider),
|
|
20
|
+
tokenOutDecimals ?? fetchDecimals(tokenOut, provider),
|
|
21
|
+
FundVault__factory.connect(vault, provider).controller(),
|
|
22
|
+
]);
|
|
23
|
+
const { baseToll, swapAmountIn } = resolveBaseToll(addresses, tokenIn, tokenOut, amountIn);
|
|
24
|
+
const routes = (await Promise.all(SUPPORTED_DEXS.map(async (dex) => {
|
|
25
|
+
try {
|
|
26
|
+
if (!isDexConfigured(addresses, dex))
|
|
27
|
+
return false;
|
|
28
|
+
const cachedPath = await getPath({
|
|
29
|
+
chainId,
|
|
30
|
+
dex,
|
|
31
|
+
tokenIn,
|
|
32
|
+
tokenOut,
|
|
33
|
+
srcDecimals: Number(srcDecimals),
|
|
34
|
+
destDecimals: Number(destDecimals),
|
|
35
|
+
vault,
|
|
36
|
+
});
|
|
37
|
+
if (!cachedPath)
|
|
38
|
+
return false;
|
|
39
|
+
if (cachedPath.hops > MAX_ROUTE_HOPS)
|
|
40
|
+
return false;
|
|
41
|
+
const toll = { ...baseToll };
|
|
42
|
+
return await getRouteFromPath({
|
|
43
|
+
chainId,
|
|
44
|
+
addresses,
|
|
45
|
+
provider,
|
|
46
|
+
simulator,
|
|
47
|
+
dex,
|
|
48
|
+
cachedPath,
|
|
49
|
+
amountIn: swapAmountIn,
|
|
50
|
+
toll,
|
|
51
|
+
vault,
|
|
52
|
+
controller,
|
|
53
|
+
account,
|
|
54
|
+
maxSlippageE3,
|
|
55
|
+
prefixTxs,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}))).filter((r) => !!r);
|
|
62
|
+
if (routes.length === 0) {
|
|
63
|
+
throw new Error('NO_VELORA_ROUTES_FOUND');
|
|
64
|
+
}
|
|
65
|
+
return routes.reduce((best, current) => BigInt(best.data.amountToReceive) < BigInt(current.data.amountToReceive)
|
|
66
|
+
? current
|
|
67
|
+
: best);
|
|
68
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { GuruProtocolAddresses } from '../addresses';
|
|
2
|
+
export declare function withSlippageTolerance(amount: bigint, slippage: bigint): bigint;
|
|
3
|
+
export interface BaseTollContext {
|
|
4
|
+
tollIn: boolean;
|
|
5
|
+
baseToll: {
|
|
6
|
+
currency: string;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
};
|
|
9
|
+
swapAmountIn: bigint;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveBaseToll(addresses: GuruProtocolAddresses, tokenIn: string, tokenOut: string, amountIn: bigint): BaseTollContext;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TOLL_DIVISOR_20BPS } from '../constants.js';
|
|
2
|
+
import compareAddresses from '../helpers/compareAddresses.js';
|
|
3
|
+
const PERCENTAGE_DENOMINATOR = 100000n;
|
|
4
|
+
export function withSlippageTolerance(amount, slippage) {
|
|
5
|
+
const tolerance = (amount * slippage) / PERCENTAGE_DENOMINATOR;
|
|
6
|
+
return amount - tolerance;
|
|
7
|
+
}
|
|
8
|
+
export function resolveBaseToll(addresses, tokenIn, tokenOut, amountIn) {
|
|
9
|
+
const tollableTokens = [
|
|
10
|
+
addresses.tokens.USDC.toLowerCase(),
|
|
11
|
+
addresses.tokens.USDT.toLowerCase(),
|
|
12
|
+
addresses.tokens.WETH.toLowerCase(),
|
|
13
|
+
];
|
|
14
|
+
const tollIn = tollableTokens.some((token) => compareAddresses(token, tokenIn));
|
|
15
|
+
const tollOut = !tollIn &&
|
|
16
|
+
tollableTokens.some((token) => compareAddresses(token, tokenOut));
|
|
17
|
+
if (!tollIn && !tollOut) {
|
|
18
|
+
throw new Error('INVALID_SWAP');
|
|
19
|
+
}
|
|
20
|
+
let swapAmountIn = amountIn;
|
|
21
|
+
const baseToll = {
|
|
22
|
+
currency: tollIn ? tokenIn : tokenOut,
|
|
23
|
+
amount: 0n,
|
|
24
|
+
};
|
|
25
|
+
if (tollIn) {
|
|
26
|
+
baseToll.amount = amountIn / TOLL_DIVISOR_20BPS;
|
|
27
|
+
swapAmountIn = amountIn - baseToll.amount;
|
|
28
|
+
}
|
|
29
|
+
return { tollIn, baseToll, swapAmountIn };
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Provider } from 'ethers';
|
|
2
|
+
import { type GuruProtocolChainId } from '../addresses';
|
|
3
|
+
import type { PathFetcher } from './pathCache';
|
|
4
|
+
import type { SwapSimulator } from './simulation';
|
|
5
|
+
import type { Route, RouteSearchParams } from './types';
|
|
6
|
+
export interface RouterContext {
|
|
7
|
+
provider: Provider;
|
|
8
|
+
simulator: SwapSimulator;
|
|
9
|
+
getSwapFeePercentage: () => Promise<bigint>;
|
|
10
|
+
getPath: PathFetcher;
|
|
11
|
+
}
|
|
12
|
+
export declare function veloraThenV4Discovery(velora: () => Promise<Route>, v4Discovery: () => Promise<Route>): Promise<Route>;
|
|
13
|
+
export declare function tryWithVeloraFallback<T>(velora: () => Promise<T>, fallback: () => Promise<T>): Promise<T>;
|
|
14
|
+
export declare function getRouteIn(params: RouteSearchParams, ctx: RouterContext): Promise<Route>;
|
|
15
|
+
export declare function getRouteOut(params: RouteSearchParams, ctx: RouterContext): Promise<Route>;
|
|
16
|
+
export declare function getPriceUsd1e18(token: string, ctx: {
|
|
17
|
+
chainId: GuruProtocolChainId;
|
|
18
|
+
provider: Provider;
|
|
19
|
+
getSwapFeePercentage: () => Promise<bigint>;
|
|
20
|
+
}): Promise<bigint>;
|
|
21
|
+
export type { Route, RouteSearchParams, V2Path, V3Path, V3PathHop, V4Path, V4PathHop, } from './types';
|
|
22
|
+
export type { SwapSimulator, SimulateSwapParams, SimulateSwapResult, } from './simulation';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { parseEther } from 'ethers';
|
|
2
|
+
import { getGuruProtocolAddresses, } from '../addresses.js';
|
|
3
|
+
import compareAddresses from '../helpers/compareAddresses.js';
|
|
4
|
+
import { Token } from '../helpers/Token.js';
|
|
5
|
+
import { getFallbackRouteIn, getFallbackRouteOut, } from './getFallbackRoutes.js';
|
|
6
|
+
import getUniswapV4Route, { connectV4Quoter, toAdapterPathKeys, } from './getUniswapV4Route.js';
|
|
7
|
+
import getVeloraRoute from './getVeloraRoute.js';
|
|
8
|
+
import PoolHelper from './poolHelper.js';
|
|
9
|
+
import { discoverV4Paths } from './v4PoolDiscovery.js';
|
|
10
|
+
export async function veloraThenV4Discovery(velora, v4Discovery) {
|
|
11
|
+
try {
|
|
12
|
+
return await velora();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return await v4Discovery();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function tryWithVeloraFallback(velora, fallback) {
|
|
19
|
+
try {
|
|
20
|
+
return await velora();
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (err instanceof Error &&
|
|
24
|
+
(err.message.includes('TOKEN_LOCKED_BY_V4_HOOK') ||
|
|
25
|
+
err.message.includes('UNISWAP_V4_HOOK_ROUTE_REVERTED'))) {
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
console.error('[@guru-fund/sdk] Velora route failed, retrying via fallback:', err);
|
|
29
|
+
return await fallback();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export async function getRouteIn(params, ctx) {
|
|
33
|
+
const veloraCtx = {
|
|
34
|
+
provider: ctx.provider,
|
|
35
|
+
simulator: ctx.simulator,
|
|
36
|
+
getPath: ctx.getPath,
|
|
37
|
+
};
|
|
38
|
+
const v4Ctx = {
|
|
39
|
+
provider: ctx.provider,
|
|
40
|
+
simulator: ctx.simulator,
|
|
41
|
+
};
|
|
42
|
+
const fallbackCtx = {
|
|
43
|
+
provider: ctx.provider,
|
|
44
|
+
simulator: ctx.simulator,
|
|
45
|
+
getSwapFeePercentage: ctx.getSwapFeePercentage,
|
|
46
|
+
};
|
|
47
|
+
return tryWithVeloraFallback(() => veloraThenV4Discovery(() => getVeloraRoute(params, veloraCtx), () => getUniswapV4Route(params, v4Ctx)), () => getFallbackRouteIn(params, fallbackCtx));
|
|
48
|
+
}
|
|
49
|
+
export async function getRouteOut(params, ctx) {
|
|
50
|
+
const veloraCtx = {
|
|
51
|
+
provider: ctx.provider,
|
|
52
|
+
simulator: ctx.simulator,
|
|
53
|
+
getPath: ctx.getPath,
|
|
54
|
+
};
|
|
55
|
+
const v4Ctx = {
|
|
56
|
+
provider: ctx.provider,
|
|
57
|
+
simulator: ctx.simulator,
|
|
58
|
+
};
|
|
59
|
+
const fallbackCtx = {
|
|
60
|
+
provider: ctx.provider,
|
|
61
|
+
simulator: ctx.simulator,
|
|
62
|
+
getSwapFeePercentage: ctx.getSwapFeePercentage,
|
|
63
|
+
};
|
|
64
|
+
return tryWithVeloraFallback(() => veloraThenV4Discovery(() => getVeloraRoute(params, veloraCtx), () => getUniswapV4Route(params, v4Ctx)), () => getFallbackRouteOut(params, fallbackCtx));
|
|
65
|
+
}
|
|
66
|
+
export async function getPriceUsd1e18(token, ctx) {
|
|
67
|
+
const addresses = getGuruProtocolAddresses(ctx.chainId);
|
|
68
|
+
const poolHelper = new PoolHelper({
|
|
69
|
+
chainId: ctx.chainId,
|
|
70
|
+
provider: ctx.provider,
|
|
71
|
+
getSwapFeePercentage: ctx.getSwapFeePercentage,
|
|
72
|
+
});
|
|
73
|
+
const { amount: wethUsdt } = await poolHelper.getBestQuote({
|
|
74
|
+
tokenAmount: parseEther('1'),
|
|
75
|
+
path: [addresses.tokens.WETH, addresses.tokens.USDT],
|
|
76
|
+
requireSwappable: false,
|
|
77
|
+
});
|
|
78
|
+
const wethUsd = wethUsdt * 10n ** 12n;
|
|
79
|
+
if (compareAddresses(token, addresses.tokens.WETH)) {
|
|
80
|
+
return wethUsd;
|
|
81
|
+
}
|
|
82
|
+
const { decimals } = await new Token(token, ctx.provider)
|
|
83
|
+
.metadata()
|
|
84
|
+
.catch(() => ({ decimals: 0 }));
|
|
85
|
+
const oneToken = 10n ** BigInt(decimals);
|
|
86
|
+
const WETH_UNIT = 10n ** 18n;
|
|
87
|
+
try {
|
|
88
|
+
const { amount: oneTokenInWeth } = await poolHelper.getBestQuote({
|
|
89
|
+
tokenAmount: oneToken,
|
|
90
|
+
path: [token, addresses.tokens.WETH],
|
|
91
|
+
requireSwappable: false,
|
|
92
|
+
});
|
|
93
|
+
return (oneTokenInWeth * wethUsd) / WETH_UNIT;
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
const v4Usd = await _priceViaV4Pools(token, oneToken, wethUsd, ctx);
|
|
97
|
+
if (v4Usd !== null)
|
|
98
|
+
return v4Usd;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function _priceViaV4Pools(token, oneToken, wethUsd, ctx) {
|
|
103
|
+
const addresses = getGuruProtocolAddresses(ctx.chainId);
|
|
104
|
+
const quoterAddress = addresses.quoters.uniswapV4;
|
|
105
|
+
if (!quoterAddress)
|
|
106
|
+
return null;
|
|
107
|
+
const quoter = connectV4Quoter(quoterAddress, ctx.provider);
|
|
108
|
+
const WETH_UNIT = 10n ** 18n;
|
|
109
|
+
const quoteVia = async (counterpart) => {
|
|
110
|
+
const paths = await discoverV4Paths(ctx.chainId, token, counterpart, ctx.provider).catch(() => []);
|
|
111
|
+
const quotes = await Promise.allSettled(paths.map((path) => quoter.quoteExactInput.staticCall({
|
|
112
|
+
exactCurrency: token,
|
|
113
|
+
path: toAdapterPathKeys(path),
|
|
114
|
+
exactAmount: oneToken,
|
|
115
|
+
})));
|
|
116
|
+
let best = 0n;
|
|
117
|
+
for (const result of quotes) {
|
|
118
|
+
if (result.status !== 'fulfilled')
|
|
119
|
+
continue;
|
|
120
|
+
const [amountOut] = result.value;
|
|
121
|
+
if (amountOut > best)
|
|
122
|
+
best = amountOut;
|
|
123
|
+
}
|
|
124
|
+
return best > 0n ? best : null;
|
|
125
|
+
};
|
|
126
|
+
const inUsdc = await quoteVia(addresses.tokens.USDC);
|
|
127
|
+
if (inUsdc !== null) {
|
|
128
|
+
return inUsdc * 10n ** 12n;
|
|
129
|
+
}
|
|
130
|
+
const inWeth = await quoteVia(addresses.tokens.WETH);
|
|
131
|
+
if (inWeth !== null) {
|
|
132
|
+
return (inWeth * wethUsd) / WETH_UNIT;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type SupportedDex } from './constants';
|
|
2
|
+
import type { CachedPath, VeloraRouteResponse, VeloraRouteResponseV4 } from './types';
|
|
3
|
+
export interface GetPathParams {
|
|
4
|
+
chainId: number;
|
|
5
|
+
dex: SupportedDex;
|
|
6
|
+
tokenIn: string;
|
|
7
|
+
tokenOut: string;
|
|
8
|
+
srcDecimals: number;
|
|
9
|
+
destDecimals: number;
|
|
10
|
+
vault: string;
|
|
11
|
+
}
|
|
12
|
+
export type PathFetcher = (params: GetPathParams) => Promise<CachedPath>;
|
|
13
|
+
export declare function extractPathFromResponse(dex: SupportedDex, response: VeloraRouteResponse<unknown>): CachedPath;
|
|
14
|
+
export declare function extractV4Path(response: VeloraRouteResponseV4): CachedPath;
|
|
15
|
+
export declare function getPath({ chainId, dex, tokenIn, tokenOut, srcDecimals, destDecimals, vault, }: GetPathParams, endpoint?: string): Promise<CachedPath>;
|
|
16
|
+
export declare function _clearPathCache(): void;
|