@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Guru Fund
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# @guru-fund/sdk
|
|
2
|
+
|
|
3
|
+
Quote + transaction builders for Guru Protocol managed funds.
|
|
4
|
+
|
|
5
|
+
The SDK is submission-agnostic: every quote returns a `txData: TransactionRequest`
|
|
6
|
+
plus a `decodeLogs(logs)` closure. You sign and broadcast yourself. Simulation
|
|
7
|
+
is a caller-supplied callback so the SDK never reaches Alchemy / Tenderly /
|
|
8
|
+
your provider of choice directly.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @guru-fund/sdk ethers
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Peer-quality runtime deps: `ethers` (>=6.15) and `zod`. Zero internal /
|
|
17
|
+
proprietary deps — the SDK is meant to be standalone-publishable.
|
|
18
|
+
|
|
19
|
+
## Constructor
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { GuruProtocol } from '@guru-fund/sdk'
|
|
23
|
+
|
|
24
|
+
const protocol = new GuruProtocol({
|
|
25
|
+
rpcUrl: 'https://mainnet.infura.io/v3/<key>',
|
|
26
|
+
chainId: 1, // mainnet (1) and base (8453) are supported
|
|
27
|
+
})
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`new GuruProtocol({ rpcUrl, chainId })` is the only required surface. The constructor:
|
|
31
|
+
|
|
32
|
+
- Builds an internal `JsonRpcProvider(rpcUrl)`. Do not pass a provider in.
|
|
33
|
+
- Resolves the Guru Protocol contract addresses from the SDK's vendored registry. Do
|
|
34
|
+
not pass contracts in.
|
|
35
|
+
- Throws `UnsupportedChainError` for any chain outside `{ 1, 8453 }`.
|
|
36
|
+
|
|
37
|
+
Optional override slots (`GuruProtocolOptions`): `simulator`, `getSwapFeePercentage`,
|
|
38
|
+
`getPriceUsd1e18`, `veloraEndpoint`, `getPath`. Each has a sensible default —
|
|
39
|
+
see the no-sim pattern and the Alchemy pairing example below.
|
|
40
|
+
|
|
41
|
+
## Quote methods
|
|
42
|
+
|
|
43
|
+
Every quote method returns bigints natively. Stringify at your wire boundary
|
|
44
|
+
if you serialize to JSON.
|
|
45
|
+
|
|
46
|
+
| Method | Returns |
|
|
47
|
+
| -------------------------- | ------------------------------------------------------------------------------ |
|
|
48
|
+
| `protocol.quoteDeposit` | `{ sharesOutMin, extCalls, fees, referrerFeeBps, …, txData, decodeLogs }` |
|
|
49
|
+
| `protocol.quoteWithdrawal` | `{ proceeds, extCalls, routing, referrerFeeBps, …, txData, decodeLogs }` |
|
|
50
|
+
| `protocol.quoteTrade` | `Route + txData` for one-off manager trade execution |
|
|
51
|
+
| `protocol.quoteHarvest` | `{ extCalls, harvestableFraction, managementFee, txData, decodeLogs }` |
|
|
52
|
+
| `protocol.quoteRebalance` | `{ extCalls, trades, cumulativeSlippageBps, txData, decodeLogs, emptyReason }` |
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
const quote = await protocol.quoteDeposit({
|
|
56
|
+
ledger: '0xe93f393b987247530a94cef205070868924797e7',
|
|
57
|
+
account: '0xUserAddress',
|
|
58
|
+
coin: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC
|
|
59
|
+
amount: 1_000_000n, // 1 USDC (6 decimals)
|
|
60
|
+
referrerFeeBps: 0n, // see "Referrer fee policy" below
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// 1. Submit `quote.txData` from `account`. Approvals are out-of-band.
|
|
64
|
+
// 2. After execution (or sim), pipe receipt logs through quote.decodeLogs:
|
|
65
|
+
const decoded = quote.decodeLogs(receipt.logs)
|
|
66
|
+
// { expectedShares: 1234n } | null
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Referrer fee policy
|
|
70
|
+
|
|
71
|
+
`referrerFeeBps` is a required input on deposit / withdrawal. The SDK
|
|
72
|
+
range-validates `0 <= referrerFeeBps <= MAX_BPS (=10_000n)` but does NOT
|
|
73
|
+
derive it. Policies that depend on server-side data (governance-token
|
|
74
|
+
holdings, fund composition, holdings checks) belong outside the SDK — pass
|
|
75
|
+
the resolved bps in.
|
|
76
|
+
|
|
77
|
+
`slippageSettings` on deposit / withdrawal / harvest / rebalance are optional
|
|
78
|
+
per-token e3 slippage overrides (`"500"` = 0.5%). They become especially
|
|
79
|
+
important in no-sim mode, where callers may want explicit bounds instead of
|
|
80
|
+
the router defaults.
|
|
81
|
+
|
|
82
|
+
## Transaction builders
|
|
83
|
+
|
|
84
|
+
Static, synchronous calldata encoders. Use directly when you already know the
|
|
85
|
+
deposit / withdraw / harvest shape and want a `TransactionRequest` without
|
|
86
|
+
going through the quote.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
const tx = GuruProtocol.buildDepositTx({
|
|
90
|
+
controller, ledger, coin, amount, sharesOutMin, extCalls,
|
|
91
|
+
referrerFeeBps, from,
|
|
92
|
+
})
|
|
93
|
+
GuruProtocol.buildWithdrawTx({ controller, ledger, coin, amountIn, extCalls, …, from })
|
|
94
|
+
GuruProtocol.buildHarvestTx({ controller, ledger, coin, isManagementFeeEligible, extCalls, …, from })
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The quote methods call these builders internally — single source of truth for
|
|
98
|
+
calldata shape.
|
|
99
|
+
|
|
100
|
+
Approvals are NOT bundled into deposit txData — handle them yourself before
|
|
101
|
+
submitting the quote's `txData`.
|
|
102
|
+
|
|
103
|
+
## No-sim pattern
|
|
104
|
+
|
|
105
|
+
The default `simulator` callback returns `{ success: false }`, which causes
|
|
106
|
+
the Velora primary router to fall through to the caller-supplied slippage
|
|
107
|
+
without doing on-chain "highest-passing-amount" search. This is the
|
|
108
|
+
zero-config path — quotes still work, but they are degraded for real execution
|
|
109
|
+
quality because the SDK cannot validate route executability against current
|
|
110
|
+
liquidity conditions.
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const protocol = new GuruProtocol({ rpcUrl, chainId })
|
|
114
|
+
// simulator defaults to noop — callers get caller-supplied-slippage quotes
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Alchemy sim pairing example
|
|
118
|
+
|
|
119
|
+
Inject a custom simulator to recover the search behavior. Below uses Alchemy
|
|
120
|
+
Bundle Simulation; substitute Tenderly / your own provider with the same
|
|
121
|
+
callback shape.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { GuruProtocol, type SwapSimulator } from '@guru-fund/sdk'
|
|
125
|
+
import { Alchemy, Network } from 'alchemy-sdk'
|
|
126
|
+
|
|
127
|
+
const alchemy = new Alchemy({
|
|
128
|
+
apiKey: process.env.ALCHEMY_API_KEY!,
|
|
129
|
+
network: Network.ETH_MAINNET,
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const simulator: SwapSimulator = async ({
|
|
133
|
+
chainId,
|
|
134
|
+
from,
|
|
135
|
+
to,
|
|
136
|
+
callData,
|
|
137
|
+
blockNumber,
|
|
138
|
+
account,
|
|
139
|
+
amountIn,
|
|
140
|
+
tokenIn,
|
|
141
|
+
}) => {
|
|
142
|
+
try {
|
|
143
|
+
const bundle = await alchemy.transact.simulateExecutionBundle(
|
|
144
|
+
[
|
|
145
|
+
// optional ERC20 prelude funding the controller
|
|
146
|
+
{
|
|
147
|
+
from: account,
|
|
148
|
+
to: tokenIn,
|
|
149
|
+
value: '0x0',
|
|
150
|
+
data: encodeApprove(to, amountIn),
|
|
151
|
+
},
|
|
152
|
+
{ from, to, value: '0x0', data: callData },
|
|
153
|
+
],
|
|
154
|
+
{ blockNumber: `0x${blockNumber.toString(16)}` }
|
|
155
|
+
)
|
|
156
|
+
const target = bundle[bundle.length - 1]
|
|
157
|
+
return {
|
|
158
|
+
success: !target.error && !target.revertReason,
|
|
159
|
+
revertMessage: target.revertReason ?? target.error?.message,
|
|
160
|
+
}
|
|
161
|
+
} catch (err) {
|
|
162
|
+
return { success: false, revertMessage: String(err) }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const protocol = new GuruProtocol({ rpcUrl, chainId, simulator })
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`SimulateSwapParams` and `SimulateSwapResult` are exported types — the SDK
|
|
170
|
+
will only ever call your callback with the documented shape.
|
|
171
|
+
|
|
172
|
+
## Custom routing
|
|
173
|
+
|
|
174
|
+
By default the SDK fetches swap paths from Velora's DEX aggregator API. You might
|
|
175
|
+
override this if Velora changes endpoints, you have an API key for a private
|
|
176
|
+
instance, or you want to plug in a different routing backend entirely:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
// Just change the endpoint
|
|
180
|
+
const protocolWithCustomEndpoint = new GuruProtocol({
|
|
181
|
+
rpcUrl,
|
|
182
|
+
chainId,
|
|
183
|
+
veloraEndpoint: 'https://custom-velora.example/swap',
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
// Full custom path logic
|
|
187
|
+
import type { PathFetcher } from '@guru-fund/sdk'
|
|
188
|
+
|
|
189
|
+
const getPath: PathFetcher = async ({ chainId, dex, tokenIn, tokenOut }) => {
|
|
190
|
+
// your routing backend — return CachedPath or false
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const protocolWithCustomPath = new GuruProtocol({ rpcUrl, chainId, getPath })
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
`PathFetcher`, `GetPathParams`, and `CachedPath` are exported types.
|
|
197
|
+
|
|
198
|
+
## Decoding receipts
|
|
199
|
+
|
|
200
|
+
`decodeLogs(logs)` is a closure baked into each quote result. It reads the
|
|
201
|
+
contract event ABIs the SDK already has, so you don't have to assemble them
|
|
202
|
+
yourself. Returns `null` on miss (event not present) — pair it with a
|
|
203
|
+
sensible fallback in your code.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
const tx = await wallet.sendTransaction(quote.txData)
|
|
207
|
+
const receipt = await tx.wait()
|
|
208
|
+
const decoded = quote.decodeLogs(receipt!.logs) ?? {
|
|
209
|
+
expectedShares: quote.sharesOutMin, // sensible fallback
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Errors
|
|
214
|
+
|
|
215
|
+
- `UnsupportedChainError` — thrown by the constructor on `chainId` outside
|
|
216
|
+
`{ 1, 8453 }`.
|
|
217
|
+
- `z.ZodError` — thrown by quote methods on malformed inputs (zod schema at
|
|
218
|
+
the SDK boundary parses every quote method's input).
|
|
219
|
+
- `SdkError` — internal errors (e.g., `EVENT_NOT_FOUND` from the receipt
|
|
220
|
+
parser, `NETWORK_NOT_SUPPORTED` from the pool helper).
|
|
221
|
+
- Plain `Error` — semantic invariants like "coin is not a supported
|
|
222
|
+
stablecoin", "toll not applicable", "target weights do not sum to UNIT".
|
|
223
|
+
|
|
224
|
+
## License
|
|
225
|
+
|
|
226
|
+
MIT.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Provider } from 'ethers';
|
|
2
|
+
import { type GuruProtocolAddresses, type GuruProtocolChainId } from './addresses';
|
|
3
|
+
import type { GetPriceUsd1e18 } from './helpers/FundDataFetcher';
|
|
4
|
+
import { type QuoteDepositParams, type QuoteDepositResult } from './quotes/quoteDeposit';
|
|
5
|
+
import { type QuoteHarvestParams, type QuoteHarvestResult } from './quotes/quoteHarvest';
|
|
6
|
+
import { type QuoteRebalanceParams, type QuoteRebalanceResult } from './quotes/quoteRebalance';
|
|
7
|
+
import { type QuoteTradeParams, type QuoteTradeResult } from './quotes/quoteTrade';
|
|
8
|
+
import { type QuoteWithdrawalParams, type QuoteWithdrawalResult } from './quotes/quoteWithdrawal';
|
|
9
|
+
import { type PathFetcher } from './router/pathCache';
|
|
10
|
+
import type { SwapSimulator } from './router/simulation';
|
|
11
|
+
import buildDepositTx from './txBuilders/buildDepositTx';
|
|
12
|
+
import buildHarvestTx from './txBuilders/buildHarvestTx';
|
|
13
|
+
import buildTradeTx from './txBuilders/buildTradeTx';
|
|
14
|
+
import buildWithdrawTx from './txBuilders/buildWithdrawTx';
|
|
15
|
+
export interface GuruProtocolOptions {
|
|
16
|
+
rpcUrl: string;
|
|
17
|
+
chainId: number;
|
|
18
|
+
simulator?: SwapSimulator;
|
|
19
|
+
getSwapFeePercentage?: () => Promise<bigint>;
|
|
20
|
+
getPriceUsd1e18?: GetPriceUsd1e18;
|
|
21
|
+
veloraEndpoint?: string;
|
|
22
|
+
getPath?: PathFetcher;
|
|
23
|
+
}
|
|
24
|
+
export declare class GuruProtocol {
|
|
25
|
+
readonly chainId: GuruProtocolChainId;
|
|
26
|
+
readonly addresses: GuruProtocolAddresses;
|
|
27
|
+
readonly provider: Provider;
|
|
28
|
+
private readonly simulator;
|
|
29
|
+
private readonly getSwapFeePercentageFn;
|
|
30
|
+
private readonly getPriceUsd1e18Fn;
|
|
31
|
+
private readonly getPathFn;
|
|
32
|
+
constructor(options: GuruProtocolOptions);
|
|
33
|
+
private routerCtx;
|
|
34
|
+
quoteDeposit(params: QuoteDepositParams): Promise<QuoteDepositResult>;
|
|
35
|
+
quoteWithdrawal(params: QuoteWithdrawalParams): Promise<QuoteWithdrawalResult>;
|
|
36
|
+
quoteTrade(params: QuoteTradeParams): Promise<QuoteTradeResult>;
|
|
37
|
+
quoteHarvest(params: QuoteHarvestParams): Promise<QuoteHarvestResult>;
|
|
38
|
+
quoteRebalance(params: QuoteRebalanceParams): Promise<QuoteRebalanceResult>;
|
|
39
|
+
static buildDepositTx: typeof buildDepositTx;
|
|
40
|
+
static buildWithdrawTx: typeof buildWithdrawTx;
|
|
41
|
+
static buildHarvestTx: typeof buildHarvestTx;
|
|
42
|
+
static buildTradeTx: typeof buildTradeTx;
|
|
43
|
+
}
|
|
44
|
+
export default GuruProtocol;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { JsonRpcProvider } from 'ethers';
|
|
2
|
+
import { getGuruProtocolAddresses, isSupportedChainId, UnsupportedChainError, } from './addresses.js';
|
|
3
|
+
import quoteDeposit from './quotes/quoteDeposit.js';
|
|
4
|
+
import quoteHarvest from './quotes/quoteHarvest.js';
|
|
5
|
+
import quoteRebalance from './quotes/quoteRebalance.js';
|
|
6
|
+
import quoteTrade from './quotes/quoteTrade.js';
|
|
7
|
+
import quoteWithdrawal from './quotes/quoteWithdrawal.js';
|
|
8
|
+
import { getPriceUsd1e18 as defaultGetPriceUsd1e18 } from './router/index.js';
|
|
9
|
+
import { getPath as defaultGetPath } from './router/pathCache.js';
|
|
10
|
+
import buildDepositTx from './txBuilders/buildDepositTx.js';
|
|
11
|
+
import buildHarvestTx from './txBuilders/buildHarvestTx.js';
|
|
12
|
+
import buildTradeTx from './txBuilders/buildTradeTx.js';
|
|
13
|
+
import buildWithdrawTx from './txBuilders/buildWithdrawTx.js';
|
|
14
|
+
const noopSimulator = async () => ({ success: false });
|
|
15
|
+
const defaultSwapFeePercentage = async () => 200n;
|
|
16
|
+
export class GuruProtocol {
|
|
17
|
+
chainId;
|
|
18
|
+
addresses;
|
|
19
|
+
provider;
|
|
20
|
+
simulator;
|
|
21
|
+
getSwapFeePercentageFn;
|
|
22
|
+
getPriceUsd1e18Fn;
|
|
23
|
+
getPathFn;
|
|
24
|
+
constructor(options) {
|
|
25
|
+
if (!isSupportedChainId(options.chainId)) {
|
|
26
|
+
throw new UnsupportedChainError(options.chainId);
|
|
27
|
+
}
|
|
28
|
+
this.chainId = options.chainId;
|
|
29
|
+
this.addresses = getGuruProtocolAddresses(options.chainId);
|
|
30
|
+
this.provider = new JsonRpcProvider(options.rpcUrl);
|
|
31
|
+
this.simulator = options.simulator ?? noopSimulator;
|
|
32
|
+
this.getSwapFeePercentageFn =
|
|
33
|
+
options.getSwapFeePercentage ?? defaultSwapFeePercentage;
|
|
34
|
+
this.getPriceUsd1e18Fn =
|
|
35
|
+
options.getPriceUsd1e18 ??
|
|
36
|
+
((token) => defaultGetPriceUsd1e18(token, {
|
|
37
|
+
chainId: this.chainId,
|
|
38
|
+
provider: this.provider,
|
|
39
|
+
getSwapFeePercentage: this.getSwapFeePercentageFn,
|
|
40
|
+
}));
|
|
41
|
+
this.getPathFn =
|
|
42
|
+
options.getPath ??
|
|
43
|
+
((params) => defaultGetPath(params, options.veloraEndpoint));
|
|
44
|
+
}
|
|
45
|
+
routerCtx() {
|
|
46
|
+
return {
|
|
47
|
+
chainId: this.chainId,
|
|
48
|
+
provider: this.provider,
|
|
49
|
+
simulator: this.simulator,
|
|
50
|
+
getSwapFeePercentage: this.getSwapFeePercentageFn,
|
|
51
|
+
getPriceUsd1e18: this.getPriceUsd1e18Fn,
|
|
52
|
+
getPath: this.getPathFn,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
quoteDeposit(params) {
|
|
56
|
+
return quoteDeposit(params, this.routerCtx());
|
|
57
|
+
}
|
|
58
|
+
quoteWithdrawal(params) {
|
|
59
|
+
return quoteWithdrawal(params, this.routerCtx());
|
|
60
|
+
}
|
|
61
|
+
quoteTrade(params) {
|
|
62
|
+
return quoteTrade(params, this.routerCtx());
|
|
63
|
+
}
|
|
64
|
+
quoteHarvest(params) {
|
|
65
|
+
return quoteHarvest(params, this.routerCtx());
|
|
66
|
+
}
|
|
67
|
+
quoteRebalance(params) {
|
|
68
|
+
return quoteRebalance(params, this.routerCtx());
|
|
69
|
+
}
|
|
70
|
+
static buildDepositTx = buildDepositTx;
|
|
71
|
+
static buildWithdrawTx = buildWithdrawTx;
|
|
72
|
+
static buildHarvestTx = buildHarvestTx;
|
|
73
|
+
static buildTradeTx = buildTradeTx;
|
|
74
|
+
}
|
|
75
|
+
export default GuruProtocol;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type GuruProtocolChainId = 1 | 8453;
|
|
2
|
+
type AdapterKey = 'uniswapV2' | 'uniswapV3' | 'uniswapV4' | 'uniswapV4Hook' | 'pancakeV2' | 'pancakeV3' | 'aerodromeV2' | 'aerodromeV3';
|
|
3
|
+
type FactoryKey = AdapterKey | 'aerodromeV3Bis';
|
|
4
|
+
type RouterKey = AdapterKey;
|
|
5
|
+
type QuoterKey = 'uniswapV3' | 'uniswapV4' | 'pancakeV3' | 'aerodromeV3';
|
|
6
|
+
export type GuruProtocolAddresses = {
|
|
7
|
+
readonly chainId: GuruProtocolChainId;
|
|
8
|
+
readonly protocol: string;
|
|
9
|
+
readonly vaultImplementation: string;
|
|
10
|
+
readonly ledgerImplementation: string;
|
|
11
|
+
readonly controllers: Readonly<Partial<{
|
|
12
|
+
creation: string;
|
|
13
|
+
deposit: string;
|
|
14
|
+
withdrawal: string;
|
|
15
|
+
closure: string;
|
|
16
|
+
harvest: string;
|
|
17
|
+
transfer: string;
|
|
18
|
+
trade: string;
|
|
19
|
+
fund: string;
|
|
20
|
+
}>>;
|
|
21
|
+
readonly adapters: Readonly<Partial<Record<AdapterKey, string>>>;
|
|
22
|
+
readonly factories: Readonly<Partial<Record<FactoryKey, string>>>;
|
|
23
|
+
readonly routers: Readonly<Partial<Record<RouterKey, string>>>;
|
|
24
|
+
readonly quoters: Readonly<Partial<Record<QuoterKey, string>>>;
|
|
25
|
+
readonly tokens: Readonly<{
|
|
26
|
+
WETH: string;
|
|
27
|
+
USDC: string;
|
|
28
|
+
USDT: string;
|
|
29
|
+
}>;
|
|
30
|
+
readonly migrator?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare class UnsupportedChainError extends Error {
|
|
33
|
+
readonly chainId: number;
|
|
34
|
+
constructor(chainId: number);
|
|
35
|
+
}
|
|
36
|
+
export declare const GURU_PROTOCOL_ADDRESSES: Readonly<Record<GuruProtocolChainId, GuruProtocolAddresses>>;
|
|
37
|
+
export declare const SUPPORTED_CHAIN_IDS: readonly GuruProtocolChainId[];
|
|
38
|
+
export declare const isSupportedChainId: (chainId: number) => chainId is GuruProtocolChainId;
|
|
39
|
+
export declare function getGuruProtocolAddresses(chainId: number): GuruProtocolAddresses;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export class UnsupportedChainError extends Error {
|
|
2
|
+
chainId;
|
|
3
|
+
constructor(chainId) {
|
|
4
|
+
super(`[@guru-fund/sdk] chainId ${chainId} is not supported. Supported chainIds: ${SUPPORTED_CHAIN_IDS.join(', ')}`);
|
|
5
|
+
this.name = 'UnsupportedChainError';
|
|
6
|
+
this.chainId = chainId;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const MAINNET = {
|
|
10
|
+
chainId: 1,
|
|
11
|
+
protocol: '0x63d990618fe7f763b08a47d0295ba06207dc6b38',
|
|
12
|
+
vaultImplementation: '0x7a4087200216198482de0270998a9571813db300',
|
|
13
|
+
ledgerImplementation: '0xe52160f5f90c6bd910c9ef106911185445cdaf15',
|
|
14
|
+
controllers: {
|
|
15
|
+
creation: '0x1eecd3e1832a3a9abb618df8ee1900a6e7101cff',
|
|
16
|
+
deposit: '0x75aa804a208057b5d692cd213d39591a952a2aba',
|
|
17
|
+
withdrawal: '0x15da4363b3729c6f2befebd6f87d84bd8747dcce',
|
|
18
|
+
closure: '0x54ef8309cae3c5b134f864f9a582be8d87e488b3',
|
|
19
|
+
harvest: '0x81d60af23a90101e844fa8c919fb98a0ff1f8787',
|
|
20
|
+
transfer: '0x08377d07e09248a897695cc7286d26a4bf07e02f',
|
|
21
|
+
trade: '0x6912fa7cd7f15bdcab4c5dc5268025fb1b1d6aa8',
|
|
22
|
+
fund: '0xf9357a85e79c388c13fb83b237ff759675cc5977',
|
|
23
|
+
},
|
|
24
|
+
adapters: {
|
|
25
|
+
uniswapV2: '0xa8ddce8dbd35c65cf1de5d3be0df0e34e4c7edc2',
|
|
26
|
+
uniswapV3: '0xefccd55c1c4a471d72f37f84d65361ed708d22d7',
|
|
27
|
+
uniswapV4: '0xc53089118e3e988929a09286f73491bbca174fcb',
|
|
28
|
+
uniswapV4Hook: '0x8f6cba5d0ccda93ffd16b7c367a78f0d1f0fa374',
|
|
29
|
+
pancakeV2: '0x0dd3d063146a53878d25f6463d6347f8cd7a0629',
|
|
30
|
+
pancakeV3: '0x6eaa8a505f5d18563ef6881a4fd7811f4b6b9dca',
|
|
31
|
+
},
|
|
32
|
+
factories: {
|
|
33
|
+
uniswapV2: '0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f',
|
|
34
|
+
uniswapV3: '0x1f98431c8ad98523631ae4a59f267346ea31f984',
|
|
35
|
+
pancakeV2: '0x1097053fd2ea711dad45caccc45eff7548fcb362',
|
|
36
|
+
pancakeV3: '0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865',
|
|
37
|
+
},
|
|
38
|
+
routers: {
|
|
39
|
+
uniswapV2: '0x7a250d5630b4cf539739df2c5dacb4c659f2488d',
|
|
40
|
+
uniswapV3: '0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45',
|
|
41
|
+
pancakeV2: '0xeff92a263d31888d860bd50809a8d171709b7b1c',
|
|
42
|
+
pancakeV3: '0x1b81d678ffb9c0263b24a97847620c99d213eb14',
|
|
43
|
+
},
|
|
44
|
+
quoters: {
|
|
45
|
+
uniswapV3: '0x61ffe014ba17989e743c5f6cb21bf9697530b21e',
|
|
46
|
+
uniswapV4: '0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203',
|
|
47
|
+
pancakeV3: '0xb048bbc1ee6b733fffcfb9e9cef7375518e25997',
|
|
48
|
+
},
|
|
49
|
+
tokens: {
|
|
50
|
+
WETH: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
51
|
+
USDC: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
52
|
+
USDT: '0xdac17f958d2ee523a2206206994597c13d831ec7',
|
|
53
|
+
},
|
|
54
|
+
migrator: '0x616397d1e372023b5ac0498eeed2fd9fc9c06a79',
|
|
55
|
+
};
|
|
56
|
+
const BASE = {
|
|
57
|
+
chainId: 8453,
|
|
58
|
+
protocol: '0x7a4087200216198482de0270998a9571813db300',
|
|
59
|
+
vaultImplementation: '0xe52160f5f90c6bd910c9ef106911185445cdaf15',
|
|
60
|
+
ledgerImplementation: '0x1eecd3e1832a3a9abb618df8ee1900a6e7101cff',
|
|
61
|
+
controllers: {
|
|
62
|
+
fund: '0x70451b00c42a73ea2d9707ddc7413aff8620be85',
|
|
63
|
+
},
|
|
64
|
+
adapters: {
|
|
65
|
+
aerodromeV2: '0x581aa0ea01387e1b85d8bc3e14ec3475dee9c334',
|
|
66
|
+
aerodromeV3: '0x3d95d6cf7f41c905ec132020d3a39898a20977ae',
|
|
67
|
+
pancakeV3: '0x2d993c905426994a7dbb7115ca460ef33e384906',
|
|
68
|
+
uniswapV2: '0xefccd55c1c4a471d72f37f84d65361ed708d22d7',
|
|
69
|
+
uniswapV3: '0x0dd3d063146a53878d25f6463d6347f8cd7a0629',
|
|
70
|
+
uniswapV4: '0xe227ed4c09003a875432147379c334ce02c4d229',
|
|
71
|
+
},
|
|
72
|
+
factories: {
|
|
73
|
+
aerodromeV2: '0x420dd381b31aef6683db6b902084cb0ffece40da',
|
|
74
|
+
aerodromeV3: '0x5e7bb104d84c7cb9b682aac2f3d509f5f406809a',
|
|
75
|
+
aerodromeV3Bis: '0x9592cd9b267748cbfbde90ac9f7df3c437a6d51b',
|
|
76
|
+
uniswapV2: '0x8909dc15e40173ff4699343b6eb8132c65e18ec6',
|
|
77
|
+
uniswapV3: '0x33128a8fc17869897dce68ed026d694621f6fdfd',
|
|
78
|
+
pancakeV3: '0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865',
|
|
79
|
+
},
|
|
80
|
+
routers: {
|
|
81
|
+
aerodromeV2: '0xcf77a3ba9a5ca399b7c97c74d54e5b1beb874e43',
|
|
82
|
+
aerodromeV3: '0xbe6d8f0d05cc4be24d5167a3ef062215be6d18a5',
|
|
83
|
+
uniswapV2: '0x4752ba5dbc23f44d87826276bf6fd6b1c372ad24',
|
|
84
|
+
uniswapV3: '0x2626664c2603336e57b271c5c0b26f421741e481',
|
|
85
|
+
},
|
|
86
|
+
quoters: {
|
|
87
|
+
aerodromeV3: '0x254cf9e1e6e233aa1ac962cb9b05b2cfeaae15b0',
|
|
88
|
+
uniswapV3: '0x3d4e44eb1374240ce5f1b871ab261cd16335b76a',
|
|
89
|
+
uniswapV4: '0x0d5e0f971ed27fbff6c2837bf31316121532048d',
|
|
90
|
+
},
|
|
91
|
+
tokens: {
|
|
92
|
+
WETH: '0x4200000000000000000000000000000000000006',
|
|
93
|
+
USDC: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
|
|
94
|
+
USDT: '0xfde4c96c8593536e31f229ea8f37b2ada2699bb2',
|
|
95
|
+
},
|
|
96
|
+
migrator: '0x209656784c8eb405765288c8f447d11c0aa1a3d3',
|
|
97
|
+
};
|
|
98
|
+
export const GURU_PROTOCOL_ADDRESSES = {
|
|
99
|
+
1: MAINNET,
|
|
100
|
+
8453: BASE,
|
|
101
|
+
};
|
|
102
|
+
export const SUPPORTED_CHAIN_IDS = [
|
|
103
|
+
1, 8453,
|
|
104
|
+
];
|
|
105
|
+
export const isSupportedChainId = (chainId) => chainId === 1 || chainId === 8453;
|
|
106
|
+
export function getGuruProtocolAddresses(chainId) {
|
|
107
|
+
if (!isSupportedChainId(chainId)) {
|
|
108
|
+
throw new UnsupportedChainError(chainId);
|
|
109
|
+
}
|
|
110
|
+
return GURU_PROTOCOL_ADDRESSES[chainId];
|
|
111
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const DEFAULT_MANAGER_FEE_RATIO: bigint;
|
|
2
|
+
export declare const TOLL_DIVISOR_20BPS = 500n;
|
|
3
|
+
export declare const TOLL_DIVISOR_30BPS = 333n;
|
|
4
|
+
export declare const TOLL_DIVISOR_40BPS = 250n;
|
|
5
|
+
export declare const TOLL_DIVISOR_50BPS = 200n;
|
|
6
|
+
export declare const DEPOSIT_FEE_DIVISOR = 100n;
|
|
7
|
+
export declare const DEPOSIT_DISCOUNTED_FEE_DIVISOR = 200n;
|
|
8
|
+
export declare const SECONDS_PER_YEAR = 31536000n;
|
|
9
|
+
export declare const MAX_BPS = 10000n;
|
|
10
|
+
export declare const MANAGEMENT_FEE_DIVISOR_NUMERATOR: bigint;
|
|
11
|
+
export declare const MANAGEMENT_FEE_DIVISOR_2 = 1576800000n;
|
|
12
|
+
export declare const MANAGEMENT_FEE_DIVISOR_3 = 1051200000n;
|
|
13
|
+
export declare const MANAGEMENT_FEE_DIVISOR_4 = 788400000n;
|
|
14
|
+
export declare enum ManagementFee {
|
|
15
|
+
TWO_PERCENT = 0,
|
|
16
|
+
THREE_PERCENT = 1,
|
|
17
|
+
FOUR_PERCENT = 2
|
|
18
|
+
}
|
|
19
|
+
export declare const MANAGEMENT_FEE_COOLDOWN_DAYS = 30n;
|
|
20
|
+
export declare const MANAGEMENT_FEE_ELIGIBLE_GOVERNANCE_TOKEN_RATIO: bigint;
|
|
21
|
+
export declare const GURU_TOKEN_MAINNET = "0xaa7d24c3e14491abac746a98751a4883e9b70843";
|
|
22
|
+
export declare const UNIT: bigint;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const DEFAULT_MANAGER_FEE_RATIO = BigInt(0.1e18);
|
|
2
|
+
export const TOLL_DIVISOR_20BPS = 500n;
|
|
3
|
+
export const TOLL_DIVISOR_30BPS = 333n;
|
|
4
|
+
export const TOLL_DIVISOR_40BPS = 250n;
|
|
5
|
+
export const TOLL_DIVISOR_50BPS = 200n;
|
|
6
|
+
export const DEPOSIT_FEE_DIVISOR = 100n;
|
|
7
|
+
export const DEPOSIT_DISCOUNTED_FEE_DIVISOR = 200n;
|
|
8
|
+
export const SECONDS_PER_YEAR = 31536000n;
|
|
9
|
+
export const MAX_BPS = 10000n;
|
|
10
|
+
export const MANAGEMENT_FEE_DIVISOR_NUMERATOR = 100n * SECONDS_PER_YEAR;
|
|
11
|
+
export const MANAGEMENT_FEE_DIVISOR_2 = 1576800000n;
|
|
12
|
+
export const MANAGEMENT_FEE_DIVISOR_3 = 1051200000n;
|
|
13
|
+
export const MANAGEMENT_FEE_DIVISOR_4 = 788400000n;
|
|
14
|
+
export var ManagementFee;
|
|
15
|
+
(function (ManagementFee) {
|
|
16
|
+
ManagementFee[ManagementFee["TWO_PERCENT"] = 0] = "TWO_PERCENT";
|
|
17
|
+
ManagementFee[ManagementFee["THREE_PERCENT"] = 1] = "THREE_PERCENT";
|
|
18
|
+
ManagementFee[ManagementFee["FOUR_PERCENT"] = 2] = "FOUR_PERCENT";
|
|
19
|
+
})(ManagementFee || (ManagementFee = {}));
|
|
20
|
+
export const MANAGEMENT_FEE_COOLDOWN_DAYS = 30n;
|
|
21
|
+
export const MANAGEMENT_FEE_ELIGIBLE_GOVERNANCE_TOKEN_RATIO = BigInt(0.05e18);
|
|
22
|
+
export const GURU_TOKEN_MAINNET = '0xaa7d24c3e14491abac746a98751a4883e9b70843';
|
|
23
|
+
export const UNIT = BigInt(1e18);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Provider } from 'ethers';
|
|
2
|
+
import { Fund } from '../types/Fund';
|
|
3
|
+
export interface FundLedgerReadMethods {
|
|
4
|
+
balanceOf(account: string): Promise<bigint>;
|
|
5
|
+
decimals(): Promise<bigint>;
|
|
6
|
+
epochFeePerShare(price: bigint): Promise<bigint>;
|
|
7
|
+
getAssets(): Promise<string[]>;
|
|
8
|
+
totalSupply(): Promise<bigint>;
|
|
9
|
+
vault(): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
export type GetPriceUsd1e18 = (token: string) => Promise<bigint>;
|
|
12
|
+
export type FundDataFetcherConfig = {
|
|
13
|
+
chainId: number;
|
|
14
|
+
provider: Provider;
|
|
15
|
+
getPriceUsd1e18: GetPriceUsd1e18;
|
|
16
|
+
};
|
|
17
|
+
export declare const WEIGHT_DENOMINATOR = 100000n;
|
|
18
|
+
export default class FundDataFetcher {
|
|
19
|
+
private provider;
|
|
20
|
+
private getPriceUsd1e18;
|
|
21
|
+
constructor(config: FundDataFetcherConfig);
|
|
22
|
+
getUserTvlShare(ledger: FundLedgerReadMethods, account: string, tokenValue: bigint): Promise<bigint>;
|
|
23
|
+
fetchFundData(ledger: FundLedgerReadMethods): Promise<Fund.Overview>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { UNIT } from '../constants.js';
|
|
2
|
+
import { Token } from './Token.js';
|
|
3
|
+
export const WEIGHT_DENOMINATOR = 100000n;
|
|
4
|
+
export default class FundDataFetcher {
|
|
5
|
+
provider;
|
|
6
|
+
getPriceUsd1e18;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.provider = config.provider;
|
|
9
|
+
this.getPriceUsd1e18 = config.getPriceUsd1e18;
|
|
10
|
+
}
|
|
11
|
+
async getUserTvlShare(ledger, account, tokenValue) {
|
|
12
|
+
const [userBalance, decimals] = await Promise.all([
|
|
13
|
+
ledger.balanceOf(account),
|
|
14
|
+
ledger.decimals(),
|
|
15
|
+
]);
|
|
16
|
+
const unit = 10n ** decimals;
|
|
17
|
+
return (userBalance * tokenValue) / unit;
|
|
18
|
+
}
|
|
19
|
+
async fetchFundData(ledger) {
|
|
20
|
+
const [vault, assetAddresses, tokenTotalSupply] = await Promise.all([
|
|
21
|
+
ledger.vault(),
|
|
22
|
+
ledger.getAssets().then((a) => a.map((a) => a.toLowerCase())),
|
|
23
|
+
ledger.totalSupply(),
|
|
24
|
+
]);
|
|
25
|
+
const mapAssetValue = (values) => Object.fromEntries(values.map((value, index) => [assetAddresses[index], value]));
|
|
26
|
+
const [tokensByAddress, balancesByAddress, pricesByAddress] = await Promise.all([
|
|
27
|
+
Promise.all(assetAddresses.map((address) => new Token(address, this.provider).metadata())).then(mapAssetValue),
|
|
28
|
+
Promise.all(assetAddresses.map((address) => new Token(address, this.provider).balanceOf(vault))).then(mapAssetValue),
|
|
29
|
+
Promise.all(assetAddresses.map((address) => this.getPriceUsd1e18(address))).then(mapAssetValue),
|
|
30
|
+
]);
|
|
31
|
+
const assets = assetAddresses.map((address, index) => {
|
|
32
|
+
const token = tokensByAddress[address];
|
|
33
|
+
const balance = balancesByAddress[address];
|
|
34
|
+
const usd1e18Price = pricesByAddress[address];
|
|
35
|
+
const totalUsd1e18Value = (usd1e18Price * balance) / Token.unitFor(token.decimals);
|
|
36
|
+
return {
|
|
37
|
+
index,
|
|
38
|
+
token,
|
|
39
|
+
balance,
|
|
40
|
+
usd1e18Price,
|
|
41
|
+
totalUsd1e18Value,
|
|
42
|
+
weight: 0n,
|
|
43
|
+
depositWeight: 0n,
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const totalValueLocked = assets.reduce((total, asset) => total + asset.totalUsd1e18Value, 0n);
|
|
47
|
+
const tokenPrice = tokenTotalSupply === 0n
|
|
48
|
+
? 0n
|
|
49
|
+
: (totalValueLocked * UNIT) / tokenTotalSupply;
|
|
50
|
+
const tokenValue = tokenPrice - (await ledger.epochFeePerShare(tokenPrice));
|
|
51
|
+
const assetsWithWeights = assets.map(({ totalUsd1e18Value, ...asset }) => ({
|
|
52
|
+
...asset,
|
|
53
|
+
weight: totalValueLocked === 0n
|
|
54
|
+
? 0n
|
|
55
|
+
: (totalUsd1e18Value * WEIGHT_DENOMINATOR) /
|
|
56
|
+
totalValueLocked,
|
|
57
|
+
}));
|
|
58
|
+
return {
|
|
59
|
+
assets: assetsWithWeights,
|
|
60
|
+
tokenTotalSupply,
|
|
61
|
+
totalValueLocked,
|
|
62
|
+
tokenValue,
|
|
63
|
+
tokenPrice,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|