@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,14 @@
|
|
|
1
|
+
import PoolHelper, { type FeeTier, type PoolRouteFinalizationContext } from './poolHelper';
|
|
2
|
+
import type { Route } from './types';
|
|
3
|
+
export interface QuoteWethTradeParams {
|
|
4
|
+
feeTier: FeeTier;
|
|
5
|
+
input: {
|
|
6
|
+
tokenIn: string;
|
|
7
|
+
tokenOut: string;
|
|
8
|
+
amountIn: bigint;
|
|
9
|
+
slippage: bigint;
|
|
10
|
+
};
|
|
11
|
+
poolHelper: PoolHelper;
|
|
12
|
+
finalization?: PoolRouteFinalizationContext;
|
|
13
|
+
}
|
|
14
|
+
export declare function quoteWethTrade({ feeTier, input, poolHelper, finalization, }: QuoteWethTradeParams): Promise<Route>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { solidityPacked } from 'ethers';
|
|
2
|
+
import compareAddresses from '../helpers/compareAddresses.js';
|
|
3
|
+
import { AerodromeV2Adapter__factory, UniswapV2Adapter__factory, UniswapV3Adapter__factory, } from '../typechain/index.js';
|
|
4
|
+
import { finalizeRouteQuote } from './finalizeRoute.js';
|
|
5
|
+
export async function quoteWethTrade({ feeTier, input, poolHelper, finalization, }) {
|
|
6
|
+
const weth = poolHelper.addresses.tokens.WETH;
|
|
7
|
+
const wethIn = compareAddresses(input.tokenIn, weth);
|
|
8
|
+
const wethOut = compareAddresses(input.tokenOut, weth);
|
|
9
|
+
if (!wethIn && !wethOut) {
|
|
10
|
+
throw new Error('quoteWethTrade: path does not include WETH');
|
|
11
|
+
}
|
|
12
|
+
const quote = await poolHelper.getBestQuote({
|
|
13
|
+
tokenAmount: input.amountIn,
|
|
14
|
+
path: [input.tokenIn, input.tokenOut],
|
|
15
|
+
slippage: finalization ? 0n : input.slippage,
|
|
16
|
+
});
|
|
17
|
+
const adapter = poolHelper.getLotusAdapter(quote.exchangeFactory);
|
|
18
|
+
const dex = poolHelper.getDexData(quote.exchangeFactory);
|
|
19
|
+
const deadline = Math.floor((Date.now() + 1000 * 60) / 1000);
|
|
20
|
+
let buildSwap;
|
|
21
|
+
if (dex.type === 'v2') {
|
|
22
|
+
if (dex.kind === 'aerodrome') {
|
|
23
|
+
const routes = [
|
|
24
|
+
{
|
|
25
|
+
from: input.tokenIn,
|
|
26
|
+
to: input.tokenOut,
|
|
27
|
+
stable: false,
|
|
28
|
+
factory: quote.exchangeFactory,
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
buildSwap = (amountToReceive) => {
|
|
32
|
+
const data = {
|
|
33
|
+
amountToSend: input.amountIn,
|
|
34
|
+
amountToReceive,
|
|
35
|
+
routes,
|
|
36
|
+
deadline,
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
data,
|
|
40
|
+
callData: AerodromeV2Adapter__factory.createInterface().encodeFunctionData('executeSwap', [data]),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
buildSwap = (amountToReceive) => {
|
|
46
|
+
const data = {
|
|
47
|
+
amountToSend: input.amountIn,
|
|
48
|
+
amountToReceive,
|
|
49
|
+
path: [input.tokenIn, input.tokenOut],
|
|
50
|
+
deadline,
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
data,
|
|
54
|
+
callData: UniswapV2Adapter__factory.createInterface().encodeFunctionData('executeSwap', [data]),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const tier = quote.feeTier || feeTier;
|
|
61
|
+
const path = solidityPacked(['address', 'uint24', 'address'], [input.tokenIn, tier, input.tokenOut]);
|
|
62
|
+
buildSwap = (amountToReceive) => {
|
|
63
|
+
const data = {
|
|
64
|
+
amountToSend: input.amountIn,
|
|
65
|
+
amountToReceive,
|
|
66
|
+
path,
|
|
67
|
+
deadline,
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
data,
|
|
71
|
+
callData: UniswapV3Adapter__factory.createInterface().encodeFunctionData('executeSwap', [data]),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
let finalized = {
|
|
76
|
+
...buildSwap(quote.amount),
|
|
77
|
+
finalTollAmount: quote.swapFee,
|
|
78
|
+
effectiveSlippageBps: undefined,
|
|
79
|
+
};
|
|
80
|
+
if (finalization) {
|
|
81
|
+
const context = {
|
|
82
|
+
chainId: poolHelper.chainId,
|
|
83
|
+
blockNumber: finalization.blockNumber,
|
|
84
|
+
controller: finalization.controller,
|
|
85
|
+
vault: finalization.vault,
|
|
86
|
+
adapter,
|
|
87
|
+
account: finalization.account,
|
|
88
|
+
path: dex.type === 'v2'
|
|
89
|
+
? [input.tokenIn, input.tokenOut]
|
|
90
|
+
: [
|
|
91
|
+
{
|
|
92
|
+
tokenIn: input.tokenIn,
|
|
93
|
+
tokenOut: input.tokenOut,
|
|
94
|
+
fee: String(quote.feeTier || feeTier),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
buildCallDataForAmount: (amountToReceive) => String(buildSwap(amountToReceive).callData),
|
|
98
|
+
simulator: finalization.simulator,
|
|
99
|
+
prefixTxs: finalization.prefixTxs,
|
|
100
|
+
};
|
|
101
|
+
const result = await finalizeRouteQuote({
|
|
102
|
+
context,
|
|
103
|
+
amountToSend: input.amountIn,
|
|
104
|
+
amountQuoted: quote.amount,
|
|
105
|
+
initialTollAmount: wethIn ? quote.swapFee : 0n,
|
|
106
|
+
maxSlippageE3: finalization.maxSlippageE3 ?? input.slippage,
|
|
107
|
+
});
|
|
108
|
+
finalized = {
|
|
109
|
+
...buildSwap(result.finalAmountToReceive),
|
|
110
|
+
finalTollAmount: result.finalTollAmount,
|
|
111
|
+
effectiveSlippageBps: result.effectiveSlippageBps,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
adapter,
|
|
116
|
+
data: finalized.data,
|
|
117
|
+
callData: finalized.callData,
|
|
118
|
+
toll: {
|
|
119
|
+
currency: weth,
|
|
120
|
+
amount: finalized.finalTollAmount,
|
|
121
|
+
},
|
|
122
|
+
hops: 1,
|
|
123
|
+
effectiveSlippageBps: finalized.effectiveSlippageBps,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { GuruProtocolChainId } from '../addresses';
|
|
2
|
+
import type { V2Path, V3Path, V4Path } from './types';
|
|
3
|
+
export interface PrefixTx {
|
|
4
|
+
from: string;
|
|
5
|
+
to: string;
|
|
6
|
+
callData: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SimulateSwapParams {
|
|
9
|
+
chainId: GuruProtocolChainId;
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
callData: string;
|
|
13
|
+
blockNumber: number;
|
|
14
|
+
account: string;
|
|
15
|
+
amountIn: bigint;
|
|
16
|
+
tokenIn: string;
|
|
17
|
+
prefixTxs?: PrefixTx[];
|
|
18
|
+
}
|
|
19
|
+
export interface SimulateSwapResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
revertMessage?: string;
|
|
22
|
+
}
|
|
23
|
+
export type SwapSimulator = (params: SimulateSwapParams) => Promise<SimulateSwapResult>;
|
|
24
|
+
export declare function encodeVaultExecute(adapter: string, swapCallData: string): string;
|
|
25
|
+
export interface SwapSimulationContext {
|
|
26
|
+
chainId: GuruProtocolChainId;
|
|
27
|
+
blockNumber: number;
|
|
28
|
+
controller: string;
|
|
29
|
+
vault: string;
|
|
30
|
+
adapter: string;
|
|
31
|
+
account: string;
|
|
32
|
+
path: V3Path | V2Path | V4Path;
|
|
33
|
+
buildCallDataForAmount: (amountToReceive: bigint) => string;
|
|
34
|
+
simulator: SwapSimulator;
|
|
35
|
+
prefixTxs?: PrefixTx[];
|
|
36
|
+
}
|
|
37
|
+
export interface FindMaxAmountParams extends SwapSimulationContext {
|
|
38
|
+
amountQuoted: bigint;
|
|
39
|
+
amountWithSlippage: bigint;
|
|
40
|
+
amountIn: bigint;
|
|
41
|
+
maxSlippageE3?: bigint;
|
|
42
|
+
}
|
|
43
|
+
export declare function findMaxPassingAmountToReceive({ chainId, blockNumber, controller, vault, adapter, buildCallDataForAmount, amountQuoted, amountWithSlippage, path, account, amountIn, maxSlippageE3, simulator, prefixTxs, }: FindMaxAmountParams): Promise<bigint>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { FundVault__factory } from '../typechain/index.js';
|
|
2
|
+
import { BUNDLE_SIMULATION_CANDIDATES, MAX_SLIPPAGE_SEARCH_E3, } from './constants.js';
|
|
3
|
+
import { withSlippageTolerance } from './helpers.js';
|
|
4
|
+
export function encodeVaultExecute(adapter, swapCallData) {
|
|
5
|
+
return FundVault__factory.createInterface().encodeFunctionData('execute', [
|
|
6
|
+
adapter,
|
|
7
|
+
swapCallData,
|
|
8
|
+
]);
|
|
9
|
+
}
|
|
10
|
+
function generateCandidates(high, low, count) {
|
|
11
|
+
const totalRange = high - low;
|
|
12
|
+
const numberOfIntervals = BigInt(count - 1);
|
|
13
|
+
const candidates = [];
|
|
14
|
+
for (let i = 0; i < count; i++) {
|
|
15
|
+
const stepDown = (totalRange * BigInt(i)) / numberOfIntervals;
|
|
16
|
+
const candidate = high - stepDown;
|
|
17
|
+
candidates.push(candidate);
|
|
18
|
+
}
|
|
19
|
+
return candidates;
|
|
20
|
+
}
|
|
21
|
+
export async function findMaxPassingAmountToReceive({ chainId, blockNumber, controller, vault, adapter, buildCallDataForAmount, amountQuoted, amountWithSlippage, path, account, amountIn, maxSlippageE3, simulator, prefixTxs, }) {
|
|
22
|
+
const high = amountWithSlippage;
|
|
23
|
+
if (high <= 0n)
|
|
24
|
+
return amountWithSlippage;
|
|
25
|
+
const low = withSlippageTolerance(amountQuoted, MAX_SLIPPAGE_SEARCH_E3) || 1n;
|
|
26
|
+
const tokenIn = typeof path[0] === 'string' ? path[0] : path[0].tokenIn;
|
|
27
|
+
const simulate = (callData) => simulator({
|
|
28
|
+
chainId,
|
|
29
|
+
from: controller,
|
|
30
|
+
to: vault,
|
|
31
|
+
callData,
|
|
32
|
+
blockNumber,
|
|
33
|
+
account,
|
|
34
|
+
amountIn,
|
|
35
|
+
tokenIn,
|
|
36
|
+
prefixTxs,
|
|
37
|
+
});
|
|
38
|
+
if (low >= high) {
|
|
39
|
+
const { success } = await simulate(encodeVaultExecute(adapter, buildCallDataForAmount(high)));
|
|
40
|
+
return success ? high : amountWithSlippage;
|
|
41
|
+
}
|
|
42
|
+
const candidates = generateCandidates(high, low, BUNDLE_SIMULATION_CANDIDATES);
|
|
43
|
+
const results = await Promise.all(candidates.map((amount) => simulate(encodeVaultExecute(adapter, buildCallDataForAmount(amount)))));
|
|
44
|
+
const successIndices = results
|
|
45
|
+
.map((result, index) => (result.success ? index : -1))
|
|
46
|
+
.filter((index) => index !== -1);
|
|
47
|
+
if (successIndices.length === 0) {
|
|
48
|
+
if (maxSlippageE3) {
|
|
49
|
+
const fallback = withSlippageTolerance(amountQuoted, maxSlippageE3);
|
|
50
|
+
console.warn(`[findMax] All ${BUNDLE_SIMULATION_CANDIDATES} simulation candidates failed. ` +
|
|
51
|
+
`Falling back to caller-provided max slippage (${Number(maxSlippageE3) / 1000}%).`, { amountQuoted, fallback, maxSlippageE3 });
|
|
52
|
+
return fallback;
|
|
53
|
+
}
|
|
54
|
+
console.warn('Found no successful simulations with correct slippage, returning initial slippage', {
|
|
55
|
+
chainId,
|
|
56
|
+
blockNumber,
|
|
57
|
+
controller,
|
|
58
|
+
vault,
|
|
59
|
+
adapter,
|
|
60
|
+
amountQuoted,
|
|
61
|
+
amountWithSlippage,
|
|
62
|
+
callData: encodeVaultExecute(adapter, buildCallDataForAmount(high)),
|
|
63
|
+
path,
|
|
64
|
+
});
|
|
65
|
+
return amountWithSlippage;
|
|
66
|
+
}
|
|
67
|
+
const [bestIndex, secondBestIndex] = successIndices;
|
|
68
|
+
const targetIndex = secondBestIndex ?? bestIndex;
|
|
69
|
+
return candidates[targetIndex];
|
|
70
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { SwapAeroV2Struct } from '../typechain/out/AerodromeV2Adapter';
|
|
2
|
+
import type { SwapV2Struct } from '../typechain/out/UniswapV2Adapter';
|
|
3
|
+
import type { SwapV3Struct } from '../typechain/out/UniswapV3Adapter';
|
|
4
|
+
import type { SwapV4Struct } from '../typechain/out/UniswapV4Adapter';
|
|
5
|
+
import type { GuruProtocolChainId } from '../addresses';
|
|
6
|
+
import type { PrefixTx } from './simulation';
|
|
7
|
+
export type V2Path = string[];
|
|
8
|
+
export type V4PathHop = {
|
|
9
|
+
tokenIn: string;
|
|
10
|
+
tokenOut: string;
|
|
11
|
+
fee: number;
|
|
12
|
+
tickSpacing: number;
|
|
13
|
+
hooks: string;
|
|
14
|
+
hookData: string;
|
|
15
|
+
};
|
|
16
|
+
export type V4Path = V4PathHop[];
|
|
17
|
+
export type V4HookPathKey = {
|
|
18
|
+
inputCurrency: string;
|
|
19
|
+
intermediateCurrency: string;
|
|
20
|
+
fee: number;
|
|
21
|
+
tickSpacing: number;
|
|
22
|
+
hook: string;
|
|
23
|
+
hookData: string;
|
|
24
|
+
};
|
|
25
|
+
export type SwapV4HookStruct = {
|
|
26
|
+
amountToSend: bigint;
|
|
27
|
+
amountToReceive: bigint;
|
|
28
|
+
currencyIn: string;
|
|
29
|
+
currencyOut: string;
|
|
30
|
+
path: V4HookPathKey[];
|
|
31
|
+
deadline: number;
|
|
32
|
+
};
|
|
33
|
+
export type V3PathHop = {
|
|
34
|
+
tokenIn: string;
|
|
35
|
+
tokenOut: string;
|
|
36
|
+
fee: string;
|
|
37
|
+
};
|
|
38
|
+
export type V3Path = V3PathHop[];
|
|
39
|
+
export type CachedPath = {
|
|
40
|
+
type: 'v2';
|
|
41
|
+
path: V2Path;
|
|
42
|
+
hops: number;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'v3';
|
|
45
|
+
path: V3Path;
|
|
46
|
+
hops: number;
|
|
47
|
+
} | {
|
|
48
|
+
type: 'v4';
|
|
49
|
+
path: V4Path;
|
|
50
|
+
hops: number;
|
|
51
|
+
} | false;
|
|
52
|
+
export interface RouteSearchParams {
|
|
53
|
+
chainId: GuruProtocolChainId;
|
|
54
|
+
tokenIn: string;
|
|
55
|
+
tokenInDecimals?: number;
|
|
56
|
+
tokenOut: string;
|
|
57
|
+
tokenOutDecimals?: number;
|
|
58
|
+
amountIn: bigint;
|
|
59
|
+
slippageE2?: number;
|
|
60
|
+
account: string;
|
|
61
|
+
vault: string;
|
|
62
|
+
prefixTxs?: PrefixTx[];
|
|
63
|
+
}
|
|
64
|
+
export interface Route {
|
|
65
|
+
adapter: string;
|
|
66
|
+
data: SwapV2Struct | SwapV3Struct | SwapAeroV2Struct | SwapV4Struct | SwapV4HookStruct;
|
|
67
|
+
callData: string | Uint8Array<ArrayBufferLike>;
|
|
68
|
+
toll: {
|
|
69
|
+
currency: string;
|
|
70
|
+
amount: bigint;
|
|
71
|
+
};
|
|
72
|
+
hops: number;
|
|
73
|
+
effectiveSlippageBps?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface VeloraRouteResponse<TData = unknown> {
|
|
76
|
+
priceRoute: VeloraPriceRoute<TData>;
|
|
77
|
+
}
|
|
78
|
+
export interface VeloraPriceRoute<TData = unknown> {
|
|
79
|
+
blockNumber: number;
|
|
80
|
+
network: number;
|
|
81
|
+
srcToken: string;
|
|
82
|
+
srcDecimals: number;
|
|
83
|
+
srcAmount: string;
|
|
84
|
+
destToken: string;
|
|
85
|
+
destDecimals: number;
|
|
86
|
+
destAmount: string;
|
|
87
|
+
bestRoute: VeloraBestRoute<TData>[];
|
|
88
|
+
gasCostUSD: string;
|
|
89
|
+
gasCost: string;
|
|
90
|
+
side: string;
|
|
91
|
+
version: string;
|
|
92
|
+
contractAddress: string;
|
|
93
|
+
tokenTransferProxy: string;
|
|
94
|
+
contractMethod: string;
|
|
95
|
+
}
|
|
96
|
+
export interface VeloraBestRoute<TData = unknown> {
|
|
97
|
+
percent: number;
|
|
98
|
+
swaps: VeloraSwap<TData>[];
|
|
99
|
+
}
|
|
100
|
+
export interface VeloraSwap<TData = unknown> {
|
|
101
|
+
srcToken: string;
|
|
102
|
+
srcDecimals: number;
|
|
103
|
+
destToken: string;
|
|
104
|
+
destDecimals: number;
|
|
105
|
+
swapExchanges: VeloraSwapExchange<TData>[];
|
|
106
|
+
}
|
|
107
|
+
export interface VeloraSwapExchange<TData = unknown> {
|
|
108
|
+
exchange: string;
|
|
109
|
+
srcAmount: string;
|
|
110
|
+
destAmount: string;
|
|
111
|
+
percent: number;
|
|
112
|
+
poolAddresses: string[];
|
|
113
|
+
poolIdentifiers: string[];
|
|
114
|
+
data: TData;
|
|
115
|
+
}
|
|
116
|
+
export interface VeloraDataV2 {
|
|
117
|
+
router: string;
|
|
118
|
+
path: string[];
|
|
119
|
+
factory: string;
|
|
120
|
+
initCode: string;
|
|
121
|
+
feeFactor: number;
|
|
122
|
+
gasUSD: string;
|
|
123
|
+
}
|
|
124
|
+
export interface VeloraDataV3 {
|
|
125
|
+
path: V3PathHop[];
|
|
126
|
+
gasUSD: string;
|
|
127
|
+
}
|
|
128
|
+
export interface VeloraV4Hop {
|
|
129
|
+
pool: {
|
|
130
|
+
id: string;
|
|
131
|
+
key: {
|
|
132
|
+
currency0: string;
|
|
133
|
+
currency1: string;
|
|
134
|
+
fee: string;
|
|
135
|
+
tickSpacing: number;
|
|
136
|
+
hooks: string;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
tokenIn: string;
|
|
140
|
+
tokenOut: string;
|
|
141
|
+
zeroForOne: boolean;
|
|
142
|
+
}
|
|
143
|
+
export interface VeloraDataV4 {
|
|
144
|
+
path: VeloraV4Hop[];
|
|
145
|
+
gasUSD?: string;
|
|
146
|
+
}
|
|
147
|
+
export type VeloraRouteResponseV2 = VeloraRouteResponse<VeloraDataV2>;
|
|
148
|
+
export type VeloraRouteResponseV3 = VeloraRouteResponse<VeloraDataV3>;
|
|
149
|
+
export type VeloraRouteResponseV4 = VeloraRouteResponse<VeloraDataV4>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Provider } from 'ethers';
|
|
2
|
+
import { type GuruProtocolChainId } from '../addresses';
|
|
3
|
+
import type { V4Path } from './types';
|
|
4
|
+
export interface V4PoolKey {
|
|
5
|
+
currency0: string;
|
|
6
|
+
currency1: string;
|
|
7
|
+
fee: number;
|
|
8
|
+
tickSpacing: number;
|
|
9
|
+
hooks: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function computeV4PoolId(key: V4PoolKey): string;
|
|
12
|
+
interface DexscreenerPair {
|
|
13
|
+
dexId?: string;
|
|
14
|
+
labels?: string[];
|
|
15
|
+
pairAddress?: string;
|
|
16
|
+
baseToken?: {
|
|
17
|
+
address?: string;
|
|
18
|
+
};
|
|
19
|
+
quoteToken?: {
|
|
20
|
+
address?: string;
|
|
21
|
+
};
|
|
22
|
+
liquidity?: {
|
|
23
|
+
usd?: number;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function selectV4PairPoolIds(pairs: DexscreenerPair[], tokenIn: string, tokenOut: string): string[];
|
|
27
|
+
export declare function stitchNativeBridgeV4Paths(firstLegs: V4Path[], secondLegs: V4Path[]): V4Path[];
|
|
28
|
+
export declare function discoverV4Paths(chainId: GuruProtocolChainId, tokenIn: string, tokenOut: string, provider: Provider, endpoint?: string): Promise<V4Path[]>;
|
|
29
|
+
export declare function _clearV4DiscoveryCache(): void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { AbiCoder, keccak256 } from 'ethers';
|
|
2
|
+
import { getGuruProtocolAddresses, } from '../addresses.js';
|
|
3
|
+
import compareAddresses from '../helpers/compareAddresses.js';
|
|
4
|
+
import { DEXSCREENER_ENDPOINT, V4_ZERO_ADDRESS, V4_DISCOVERY_MAX_POOLS, V4_DISCOVERY_MIN_LIQUIDITY_USD, VELORA_NEGATIVE_CACHE_TTL, VELORA_PATH_CACHE_TTL, } from './constants.js';
|
|
5
|
+
const V4_CHAIN_CONFIG = {
|
|
6
|
+
1: {
|
|
7
|
+
dexscreenerSlug: 'ethereum',
|
|
8
|
+
poolManager: '0x000000000004444c5dc75cb358380d2e3de08a90',
|
|
9
|
+
deployBlock: 21_600_000,
|
|
10
|
+
},
|
|
11
|
+
8453: {
|
|
12
|
+
dexscreenerSlug: 'base',
|
|
13
|
+
poolManager: '0x498581ff718922c3f8e6a244956af099b2652b2b',
|
|
14
|
+
deployBlock: 25_000_000,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
const POOL_INITIALIZE_TOPIC = '0xdd466e674ea557f56295e2d0218a125ea4b4f0f6f3307b95f85e6110838d6438';
|
|
18
|
+
export function computeV4PoolId(key) {
|
|
19
|
+
return keccak256(AbiCoder.defaultAbiCoder().encode(['address', 'address', 'uint24', 'int24', 'address'], [key.currency0, key.currency1, key.fee, key.tickSpacing, key.hooks]));
|
|
20
|
+
}
|
|
21
|
+
export function selectV4PairPoolIds(pairs, tokenIn, tokenOut) {
|
|
22
|
+
return pairs
|
|
23
|
+
.filter((pair) => {
|
|
24
|
+
const base = pair.baseToken?.address;
|
|
25
|
+
const quote = pair.quoteToken?.address;
|
|
26
|
+
if (!base || !quote || !pair.pairAddress)
|
|
27
|
+
return false;
|
|
28
|
+
const connects = (compareAddresses(base, tokenIn) &&
|
|
29
|
+
compareAddresses(quote, tokenOut)) ||
|
|
30
|
+
(compareAddresses(base, tokenOut) &&
|
|
31
|
+
compareAddresses(quote, tokenIn));
|
|
32
|
+
return (connects &&
|
|
33
|
+
pair.dexId === 'uniswap' &&
|
|
34
|
+
(pair.labels ?? []).includes('v4') &&
|
|
35
|
+
(pair.liquidity?.usd ?? 0) >= V4_DISCOVERY_MIN_LIQUIDITY_USD);
|
|
36
|
+
})
|
|
37
|
+
.sort((a, b) => (b.liquidity?.usd ?? 0) - (a.liquidity?.usd ?? 0))
|
|
38
|
+
.slice(0, V4_DISCOVERY_MAX_POOLS)
|
|
39
|
+
.map((pair) => pair.pairAddress.toLowerCase());
|
|
40
|
+
}
|
|
41
|
+
export function stitchNativeBridgeV4Paths(firstLegs, secondLegs) {
|
|
42
|
+
const paths = [];
|
|
43
|
+
for (const firstLeg of firstLegs) {
|
|
44
|
+
const firstHop = firstLeg.at(-1);
|
|
45
|
+
if (!firstHop || !compareAddresses(firstHop.tokenOut, V4_ZERO_ADDRESS)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
for (const secondLeg of secondLegs) {
|
|
49
|
+
const secondHop = secondLeg[0];
|
|
50
|
+
if (!secondHop || !compareAddresses(secondHop.tokenIn, V4_ZERO_ADDRESS)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
paths.push([...firstLeg, ...secondLeg]);
|
|
54
|
+
if (paths.length >= V4_DISCOVERY_MAX_POOLS)
|
|
55
|
+
return paths;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return paths;
|
|
59
|
+
}
|
|
60
|
+
const poolKeyCache = new Map();
|
|
61
|
+
async function resolvePoolKey(chainId, poolId, provider) {
|
|
62
|
+
const cacheKey = `${chainId}:${poolId}`;
|
|
63
|
+
const cached = poolKeyCache.get(cacheKey);
|
|
64
|
+
if (cached)
|
|
65
|
+
return cached;
|
|
66
|
+
const config = V4_CHAIN_CONFIG[chainId];
|
|
67
|
+
const logs = await provider.getLogs({
|
|
68
|
+
address: config.poolManager,
|
|
69
|
+
topics: [POOL_INITIALIZE_TOPIC, poolId],
|
|
70
|
+
fromBlock: config.deployBlock,
|
|
71
|
+
toBlock: 'latest',
|
|
72
|
+
});
|
|
73
|
+
const log = logs[0];
|
|
74
|
+
if (!log)
|
|
75
|
+
return null;
|
|
76
|
+
const [fee, tickSpacing, hooks] = AbiCoder.defaultAbiCoder().decode(['uint24', 'int24', 'address', 'uint160', 'int24'], log.data);
|
|
77
|
+
const key = {
|
|
78
|
+
currency0: '0x' + log.topics[2].slice(26),
|
|
79
|
+
currency1: '0x' + log.topics[3].slice(26),
|
|
80
|
+
fee: Number(fee),
|
|
81
|
+
tickSpacing: Number(tickSpacing),
|
|
82
|
+
hooks: String(hooks),
|
|
83
|
+
};
|
|
84
|
+
if (computeV4PoolId(key).toLowerCase() !== poolId.toLowerCase()) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
poolKeyCache.set(cacheKey, key);
|
|
88
|
+
return key;
|
|
89
|
+
}
|
|
90
|
+
const discoveryCache = new Map();
|
|
91
|
+
export async function discoverV4Paths(chainId, tokenIn, tokenOut, provider, endpoint = DEXSCREENER_ENDPOINT) {
|
|
92
|
+
const cacheKey = `${chainId}:${tokenIn.toLowerCase()}:${tokenOut.toLowerCase()}`;
|
|
93
|
+
const cached = discoveryCache.get(cacheKey);
|
|
94
|
+
const ttl = cached?.paths.length
|
|
95
|
+
? VELORA_PATH_CACHE_TTL
|
|
96
|
+
: VELORA_NEGATIVE_CACHE_TTL;
|
|
97
|
+
if (cached && Date.now() - cached.timestamp <= ttl)
|
|
98
|
+
return cached.paths;
|
|
99
|
+
let paths = await discoverDirectV4Paths(chainId, tokenIn, tokenOut, provider, endpoint, cached?.paths);
|
|
100
|
+
if (paths.length === 0 &&
|
|
101
|
+
!compareAddresses(tokenIn, V4_ZERO_ADDRESS) &&
|
|
102
|
+
!compareAddresses(tokenOut, V4_ZERO_ADDRESS)) {
|
|
103
|
+
const [firstLegs, secondLegs] = await Promise.all([
|
|
104
|
+
discoverDirectV4Paths(chainId, tokenIn, V4_ZERO_ADDRESS, provider, endpoint),
|
|
105
|
+
discoverDirectV4Paths(chainId, V4_ZERO_ADDRESS, tokenOut, provider, endpoint),
|
|
106
|
+
]);
|
|
107
|
+
paths = stitchNativeBridgeV4Paths(firstLegs, secondLegs);
|
|
108
|
+
}
|
|
109
|
+
discoveryCache.set(cacheKey, { paths, timestamp: Date.now() });
|
|
110
|
+
return paths;
|
|
111
|
+
}
|
|
112
|
+
async function discoverDirectV4Paths(chainId, tokenIn, tokenOut, provider, endpoint, cachedPaths) {
|
|
113
|
+
const config = V4_CHAIN_CONFIG[chainId];
|
|
114
|
+
const { tokens } = getGuruProtocolAddresses(chainId);
|
|
115
|
+
const majors = [tokens.WETH, tokens.USDC, tokens.USDT, V4_ZERO_ADDRESS];
|
|
116
|
+
const isMajor = (token) => majors.some((major) => compareAddresses(major, token));
|
|
117
|
+
const queryOrder = isMajor(tokenIn) ? [tokenOut, tokenIn] : [tokenIn, tokenOut];
|
|
118
|
+
let poolIds = [];
|
|
119
|
+
for (const queryToken of queryOrder) {
|
|
120
|
+
const response = await fetch(`${endpoint}/${config.dexscreenerSlug}/${queryToken}`);
|
|
121
|
+
if (!response.ok) {
|
|
122
|
+
return cachedPaths ?? [];
|
|
123
|
+
}
|
|
124
|
+
const pairs = (await response.json());
|
|
125
|
+
poolIds = selectV4PairPoolIds(pairs, tokenIn, tokenOut);
|
|
126
|
+
if (poolIds.length > 0)
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const keys = await Promise.all(poolIds.map((poolId) => resolvePoolKey(chainId, poolId, provider)));
|
|
130
|
+
const paths = keys
|
|
131
|
+
.filter((key) => key !== null)
|
|
132
|
+
.map((key) => [
|
|
133
|
+
{
|
|
134
|
+
tokenIn,
|
|
135
|
+
tokenOut,
|
|
136
|
+
fee: key.fee,
|
|
137
|
+
tickSpacing: key.tickSpacing,
|
|
138
|
+
hooks: key.hooks,
|
|
139
|
+
hookData: '0x',
|
|
140
|
+
},
|
|
141
|
+
]);
|
|
142
|
+
return paths;
|
|
143
|
+
}
|
|
144
|
+
export function _clearV4DiscoveryCache() {
|
|
145
|
+
discoveryCache.clear();
|
|
146
|
+
poolKeyCache.clear();
|
|
147
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Provider } from 'ethers';
|
|
2
|
+
import type { GuruProtocolAddresses, GuruProtocolChainId } from '../addresses';
|
|
3
|
+
import { type SupportedDex } from './constants';
|
|
4
|
+
import { type PrefixTx, type SwapSimulator } from './simulation';
|
|
5
|
+
import type { CachedPath, Route } from './types';
|
|
6
|
+
interface V2DexEntry {
|
|
7
|
+
adapter: string;
|
|
8
|
+
routerAddress: string;
|
|
9
|
+
}
|
|
10
|
+
interface V3DexEntry {
|
|
11
|
+
adapter: string;
|
|
12
|
+
quoterAddress: string;
|
|
13
|
+
}
|
|
14
|
+
interface VeloraDexConfig {
|
|
15
|
+
UniswapV2?: V2DexEntry;
|
|
16
|
+
PancakeSwapV2?: V2DexEntry;
|
|
17
|
+
UniswapV3?: V3DexEntry;
|
|
18
|
+
PancakeSwapV3?: V3DexEntry;
|
|
19
|
+
UniswapV4?: V3DexEntry;
|
|
20
|
+
}
|
|
21
|
+
export declare function buildVeloraDexConfig(addresses: GuruProtocolAddresses): VeloraDexConfig;
|
|
22
|
+
export declare function isDexConfigured(addresses: GuruProtocolAddresses, dex: SupportedDex): boolean;
|
|
23
|
+
export interface GetRouteFromPathParams {
|
|
24
|
+
chainId: GuruProtocolChainId;
|
|
25
|
+
addresses: GuruProtocolAddresses;
|
|
26
|
+
provider: Provider;
|
|
27
|
+
simulator: SwapSimulator;
|
|
28
|
+
dex: SupportedDex;
|
|
29
|
+
cachedPath: CachedPath;
|
|
30
|
+
amountIn: bigint;
|
|
31
|
+
toll: {
|
|
32
|
+
currency: string;
|
|
33
|
+
amount: bigint;
|
|
34
|
+
};
|
|
35
|
+
vault: string;
|
|
36
|
+
controller: string;
|
|
37
|
+
account: string;
|
|
38
|
+
maxSlippageE3?: bigint;
|
|
39
|
+
prefixTxs?: PrefixTx[];
|
|
40
|
+
}
|
|
41
|
+
export declare function getRouteFromPath({ chainId, addresses, provider, simulator, dex, cachedPath, amountIn, toll, vault, controller, account, maxSlippageE3, prefixTxs, }: GetRouteFromPathParams): Promise<Route>;
|
|
42
|
+
export {};
|