@elizaos/plugin-wallet 2.0.0-beta.1 → 2.0.3-beta.6
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/README.md +70 -45
- package/auto-enable.ts +1 -1
- package/dist/actions/failure-codes.d.ts +12 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/analytics/birdeye/actions/wallet-search-address.d.ts +7 -0
- package/dist/analytics/birdeye/birdeye-task.d.ts +27 -0
- package/dist/analytics/birdeye/birdeye.d.ts +140 -0
- package/dist/analytics/birdeye/constants.d.ts +68 -0
- package/dist/analytics/birdeye/providers/agent-portfolio-provider.d.ts +8 -0
- package/dist/analytics/birdeye/providers/market.d.ts +18 -0
- package/dist/analytics/birdeye/providers/portfolio-factory.d.ts +10 -0
- package/dist/analytics/birdeye/providers/trending.d.ts +19 -0
- package/dist/analytics/birdeye/providers/wallet.d.ts +5 -0
- package/dist/analytics/birdeye/search-category.d.ts +52 -0
- package/dist/analytics/birdeye/service.d.ts +94 -0
- package/dist/analytics/birdeye/types/api/common.d.ts +199 -0
- package/dist/analytics/birdeye/types/api/defi.d.ts +187 -0
- package/dist/analytics/birdeye/types/api/pair.d.ts +182 -0
- package/dist/analytics/birdeye/types/api/search.d.ts +64 -0
- package/dist/analytics/birdeye/types/api/token.d.ts +580 -0
- package/dist/analytics/birdeye/types/api/trader.d.ts +70 -0
- package/dist/analytics/birdeye/types/api/wallet.d.ts +161 -0
- package/dist/analytics/birdeye/types/shared.d.ts +83 -0
- package/dist/analytics/birdeye/utils.d.ts +74 -0
- package/dist/analytics/dexscreener/errors.d.ts +2 -0
- package/dist/analytics/dexscreener/index.d.ts +3 -0
- package/dist/analytics/dexscreener/search-category.d.ts +3 -0
- package/dist/analytics/dexscreener/service.d.ts +34 -0
- package/dist/analytics/dexscreener/types.d.ts +131 -0
- package/dist/analytics/lpinfo/index.d.ts +31 -0
- package/dist/analytics/lpinfo/kamino/index.d.ts +7 -0
- package/dist/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.d.ts +6 -0
- package/dist/analytics/lpinfo/kamino/providers/kaminoPoolProvider.d.ts +6 -0
- package/dist/analytics/lpinfo/kamino/providers/kaminoProvider.d.ts +6 -0
- package/dist/analytics/lpinfo/kamino/services/kaminoLiquidityService.d.ts +203 -0
- package/dist/analytics/lpinfo/kamino/services/kaminoService.d.ts +171 -0
- package/dist/analytics/lpinfo/steer/index.d.ts +7 -0
- package/dist/analytics/lpinfo/steer/providers/steerLiquidityProvider.d.ts +6 -0
- package/dist/analytics/lpinfo/steer/services/steerLiquidityService.d.ts +208 -0
- package/dist/analytics/lpinfo/steer/steer-display-types.d.ts +97 -0
- package/dist/analytics/news/index.d.ts +32 -0
- package/dist/analytics/news/interfaces/types.d.ts +177 -0
- package/dist/analytics/news/providers/defiNewsProvider.d.ts +106 -0
- package/dist/analytics/news/services/newsDataService.d.ts +72 -0
- package/dist/analytics/news/utils/formatters.d.ts +54 -0
- package/dist/analytics/token-info/action.d.ts +6 -0
- package/dist/analytics/token-info/index.d.ts +3 -0
- package/dist/analytics/token-info/params.d.ts +10 -0
- package/dist/analytics/token-info/providers.d.ts +4 -0
- package/dist/analytics/token-info/service.d.ts +19 -0
- package/dist/analytics/token-info/types.d.ts +45 -0
- package/dist/api/wallet-routes.d.ts +100 -0
- package/dist/audit/audit-log.d.ts +29 -0
- package/dist/browser-shim/build-shim.d.ts +31 -0
- package/dist/browser-shim/index.d.ts +1 -0
- package/dist/chains/evm/actions/helpers.d.ts +31 -0
- package/dist/chains/evm/actions/swap.d.ts +53 -0
- package/dist/chains/evm/actions/transfer.d.ts +10 -0
- package/dist/chains/evm/bridge-router.d.ts +44 -0
- package/dist/chains/evm/build.d.ts +2 -0
- package/dist/chains/evm/chain-handler.d.ts +37 -0
- package/dist/chains/evm/constants.d.ts +16 -0
- package/dist/chains/evm/dex/aerodrome/index.d.ts +6 -0
- package/dist/chains/evm/dex/aerodrome/services/AerodromeLpService.d.ts +27 -0
- package/dist/chains/evm/dex/aerodrome/types.d.ts +435 -0
- package/dist/chains/evm/dex/pancakeswp/index.d.ts +6 -0
- package/dist/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.d.ts +28 -0
- package/dist/chains/evm/dex/pancakeswp/types.d.ts +19 -0
- package/dist/chains/evm/dex/uniswap/index.d.ts +6 -0
- package/dist/chains/evm/dex/uniswap/services/UniswapV3LpService.d.ts +28 -0
- package/dist/chains/evm/dex/uniswap/types.d.ts +458 -0
- package/dist/chains/evm/generated/specs/spec-helpers.d.ts +35 -0
- package/dist/chains/evm/generated/specs/specs.d.ts +99 -0
- package/dist/chains/evm/gov-router.d.ts +6 -0
- package/dist/chains/evm/index.browser.d.ts +3 -0
- package/dist/chains/evm/index.d.ts +6 -0
- package/dist/chains/evm/prompts.d.ts +24 -0
- package/dist/chains/evm/providers/get-balance.d.ts +2 -0
- package/dist/chains/evm/providers/wallet.d.ts +35 -0
- package/dist/chains/evm/routes/sign.d.ts +13 -0
- package/dist/chains/evm/rpc-providers.d.ts +26 -0
- package/dist/chains/evm/service.d.ts +26 -0
- package/dist/chains/evm/templates/index.d.ts +1 -0
- package/dist/chains/evm/types/index.d.ts +296 -0
- package/dist/chains/evm/vitest.config.d.ts +2 -0
- package/dist/chains/registry.d.ts +3 -0
- package/dist/chains/solana/actions/confirmation.d.ts +9 -0
- package/dist/chains/solana/bn.d.ts +6 -0
- package/dist/chains/solana/build.d.ts +2 -0
- package/dist/chains/solana/constants.d.ts +2 -0
- package/dist/chains/solana/dex/meteora/e2e/scenarios.d.ts +10 -0
- package/dist/chains/solana/dex/meteora/e2e/test-utils.d.ts +28 -0
- package/dist/chains/solana/dex/meteora/index.d.ts +3 -0
- package/dist/chains/solana/dex/meteora/providers/positionProvider.d.ts +9 -0
- package/dist/chains/solana/dex/meteora/services/MeteoraLpService.d.ts +37 -0
- package/dist/chains/solana/dex/meteora/utils/dlmm.d.ts +6 -0
- package/dist/chains/solana/dex/meteora/utils/loadWallet.d.ts +14 -0
- package/dist/chains/solana/dex/meteora/utils/sendTransaction.d.ts +2 -0
- package/dist/chains/solana/dex/orca/index.d.ts +6 -0
- package/dist/chains/solana/dex/orca/providers/positionProvider.d.ts +10 -0
- package/dist/chains/solana/dex/orca/services/srv_orca.d.ts +10 -0
- package/dist/chains/solana/dex/orca/types.d.ts +61 -0
- package/dist/chains/solana/dex/orca/utils/loadWallet.d.ts +1 -0
- package/dist/chains/solana/dex/orca/utils/sendTransaction.d.ts +2 -0
- package/dist/chains/solana/dex/raydium/index.d.ts +6 -0
- package/dist/chains/solana/dex/raydium/providers/positionProvider.d.ts +10 -0
- package/dist/chains/solana/dex/raydium/services/srv_raydium.d.ts +104 -0
- package/dist/chains/solana/dex/raydium/types.d.ts +42 -0
- package/dist/chains/solana/environment.d.ts +15 -0
- package/dist/chains/solana/generated/specs/spec-helpers.d.ts +35 -0
- package/dist/chains/solana/generated/specs/specs.d.ts +73 -0
- package/dist/chains/solana/index.browser.d.ts +3 -0
- package/dist/chains/solana/index.d.ts +7 -0
- package/dist/chains/solana/keypairUtils.d.ts +7 -0
- package/dist/chains/solana/prompts.d.ts +12 -0
- package/dist/chains/solana/providers/wallet.d.ts +2 -0
- package/dist/chains/solana/routes/index.d.ts +2 -0
- package/dist/chains/solana/routes/sign.d.ts +16 -0
- package/dist/chains/solana/service.d.ts +237 -0
- package/dist/chains/solana/types.d.ts +377 -0
- package/dist/chains/solana/vitest.config.d.ts +2 -0
- package/dist/chains/wallet-action.d.ts +3 -0
- package/dist/contracts.d.ts +58 -0
- package/dist/core-augmentation.d.ts +9 -0
- package/dist/index.d.mts +27 -34727
- package/dist/index.d.ts +27 -0
- package/dist/index.mjs +28246 -21186
- package/dist/index.mjs.map +153 -0
- package/dist/lib/server-wallet-trade.d.ts +22 -0
- package/dist/lib/server-wallet-trade.js +333 -0
- package/dist/lib/server-wallet-trade.js.map +11 -0
- package/dist/lib/wallet-export-guard.d.ts +45 -0
- package/dist/lp/actions/liquidity.d.ts +2 -0
- package/dist/lp/e2e/real-token-tests.d.ts +6 -0
- package/dist/lp/e2e/scenarios.d.ts +9 -0
- package/dist/lp/e2e/test-utils.d.ts +28 -0
- package/dist/lp/lp-manager-entry.d.ts +18 -0
- package/dist/lp/services/ConcentratedLiquidityService.d.ts +32 -0
- package/dist/lp/services/DexInteractionService.d.ts +34 -0
- package/dist/lp/services/LpManagementService.d.ts +116 -0
- package/dist/lp/services/UserLpProfileService.d.ts +18 -0
- package/dist/lp/services/VaultService.d.ts +21 -0
- package/dist/lp/services/YieldOptimizationService.d.ts +59 -0
- package/dist/lp/services/__tests__/MockLpService.d.ts +17 -0
- package/dist/lp/types.d.ts +439 -0
- package/dist/lp/utils/solanaClient.d.ts +26 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/policy/policy.d.ts +14 -0
- package/dist/providers/canonical-provider.d.ts +19 -0
- package/dist/providers/wallet-provider.d.ts +5 -0
- package/dist/register-routes.d.ts +1 -0
- package/dist/routes/plugin.d.ts +14 -0
- package/dist/routes/wallet-market-overview-route.d.ts +7 -0
- package/dist/sdk/abi.d.ts +396 -0
- package/dist/sdk/bridge/abis.d.ts +63 -0
- package/dist/sdk/bridge/client.d.ts +48 -0
- package/dist/sdk/bridge/index.d.ts +14 -0
- package/dist/sdk/bridge/solana.d.ts +131 -0
- package/dist/sdk/bridge/types.d.ts +92 -0
- package/dist/sdk/convenience.d.ts +104 -0
- package/dist/sdk/escrow/MutualStakeEscrow.d.ts +75 -0
- package/dist/sdk/escrow/types.d.ts +58 -0
- package/dist/sdk/escrow/verifiers.d.ts +25 -0
- package/dist/sdk/identity/erc8004.d.ts +304 -0
- package/dist/sdk/identity/reputation.d.ts +317 -0
- package/dist/sdk/identity/uaid.d.ts +192 -0
- package/dist/sdk/identity/validation.d.ts +282 -0
- package/dist/sdk/index.d.ts +133 -0
- package/dist/sdk/index.js +5284 -0
- package/dist/sdk/index.js.map +40 -0
- package/dist/sdk/policy/SpendingPolicy.d.ts +105 -0
- package/dist/sdk/policy/UptoBillingPolicy.d.ts +87 -0
- package/dist/sdk/router/PaymentRouter.d.ts +77 -0
- package/dist/sdk/router/index.d.ts +2 -0
- package/dist/sdk/swap/SwapModule.d.ts +47 -0
- package/dist/sdk/swap/abi.d.ts +50 -0
- package/dist/sdk/swap/index.d.ts +11 -0
- package/dist/sdk/swap/types.d.ts +101 -0
- package/dist/sdk/tokens/decimals.d.ts +64 -0
- package/dist/sdk/tokens/registry.d.ts +81 -0
- package/dist/sdk/tokens/solana.d.ts +107 -0
- package/dist/sdk/tokens/transfers.d.ts +94 -0
- package/dist/sdk/types.d.ts +129 -0
- package/dist/sdk/wallet-core.d.ts +29450 -0
- package/dist/sdk/x402/budget.d.ts +51 -0
- package/dist/sdk/x402/chains/abstract/index.d.ts +134 -0
- package/dist/sdk/x402/client.d.ts +66 -0
- package/dist/sdk/x402/index.d.ts +8 -0
- package/dist/sdk/x402/middleware.d.ts +37 -0
- package/dist/sdk/x402/multi-asset.d.ts +53 -0
- package/dist/sdk/x402/types.d.ts +109 -0
- package/dist/security/wallet-context-safety.d.ts +7 -0
- package/dist/security/wallet-financial-confirmation.d.ts +23 -0
- package/dist/services/wallet-backend-service.d.ts +39 -0
- package/dist/types/wallet-router.d.ts +130 -0
- package/dist/utils/intent-trajectory.d.ts +34 -0
- package/dist/wallet/backend.d.ts +41 -0
- package/dist/wallet/errors.d.ts +17 -0
- package/dist/wallet/index.d.ts +6 -0
- package/dist/wallet/local-eoa-backend.d.ts +37 -0
- package/dist/wallet/pending.d.ts +47 -0
- package/dist/wallet/select-backend.d.ts +11 -0
- package/dist/wallet/steward-backend.d.ts +22 -0
- package/dist/wallet-action.d.ts +1 -0
- package/dist/wallet-action.js +6292 -0
- package/dist/wallet-action.js.map +44 -0
- package/package.json +35 -21
- package/registry-entry.json +134 -0
- package/src/analytics/birdeye/actions/wallet-search-address.ts +85 -5
- package/src/analytics/birdeye/birdeye-task.ts +25 -9
- package/src/analytics/birdeye/birdeye.ts +6 -7
- package/src/analytics/birdeye/constants.ts +0 -1
- package/src/analytics/birdeye/providers/agent-portfolio-provider.ts +0 -1
- package/src/analytics/birdeye/providers/market.ts +51 -45
- package/src/analytics/birdeye/providers/portfolio-factory.ts +79 -38
- package/src/analytics/birdeye/providers/trending.ts +43 -46
- package/src/analytics/birdeye/providers/wallet.ts +0 -1
- package/src/analytics/birdeye/search-category.test.ts +1 -1
- package/src/analytics/birdeye/search-category.ts +77 -12
- package/src/analytics/birdeye/service.test.ts +146 -0
- package/src/analytics/birdeye/service.ts +220 -105
- package/src/analytics/birdeye/types/api/common.ts +0 -1
- package/src/analytics/birdeye/types/api/defi.ts +0 -1
- package/src/analytics/birdeye/types/api/pair.ts +0 -1
- package/src/analytics/birdeye/types/api/search.ts +0 -1
- package/src/analytics/birdeye/types/api/token.ts +0 -1
- package/src/analytics/birdeye/types/api/trader.ts +0 -1
- package/src/analytics/birdeye/types/api/wallet.ts +0 -1
- package/src/analytics/birdeye/types/shared.ts +0 -11
- package/src/analytics/birdeye/utils.test.ts +69 -0
- package/src/analytics/birdeye/utils.ts +11 -8
- package/src/analytics/dexscreener/search-category.ts +0 -1
- package/src/analytics/dexscreener/service.ts +7 -12
- package/src/analytics/dexscreener/types.ts +0 -1
- package/src/analytics/lpinfo/index.ts +5 -2
- package/src/analytics/lpinfo/kamino/README.md +2 -2
- package/src/analytics/lpinfo/kamino/index.ts +9 -2
- package/src/analytics/lpinfo/kamino/providers/kaminoLiquidityProvider.ts +6 -26
- package/src/analytics/lpinfo/kamino/providers/kaminoPoolProvider.ts +11 -12
- package/src/analytics/lpinfo/kamino/providers/kaminoProvider.ts +76 -32
- package/src/analytics/lpinfo/kamino/services/kaminoLiquidityService.ts +78 -38
- package/src/analytics/lpinfo/kamino/services/kaminoService.ts +71 -31
- package/src/analytics/lpinfo/steer/index.ts +7 -2
- package/src/analytics/lpinfo/steer/providers/steerLiquidityProvider.ts +25 -26
- package/src/analytics/lpinfo/steer/services/steerLiquidityService.ts +367 -149
- package/src/analytics/news/index.ts +7 -2
- package/src/analytics/news/interfaces/types.ts +0 -1
- package/src/analytics/news/providers/defiNewsProvider.ts +17 -44
- package/src/analytics/news/services/newsDataService.ts +1 -22
- package/src/analytics/news/utils/formatters.test.ts +60 -0
- package/src/analytics/news/utils/formatters.ts +0 -1
- package/src/analytics/token-info/action.ts +52 -212
- package/src/analytics/token-info/index.ts +1 -1
- package/src/analytics/token-info/params.test.ts +69 -0
- package/src/analytics/token-info/params.ts +13 -11
- package/src/analytics/token-info/providers.ts +46 -17
- package/src/analytics/token-info/service.ts +3 -3
- package/src/analytics/token-info/types.ts +2 -2
- package/src/api/wallet-routes.test.ts +56 -0
- package/src/api/wallet-routes.ts +1728 -0
- package/src/audit/audit-log.ts +57 -2
- package/src/browser-shim/build-shim.ts +1 -1
- package/src/browser-shim/shim.template.js +107 -117
- package/src/chains/{wallet-router.test.ts → __tests__/wallet-router.test.ts} +57 -10
- package/src/chains/evm/actions/helpers.ts +9 -7
- package/src/chains/evm/actions/swap.ts +176 -22
- package/src/chains/evm/actions/transfer.ts +29 -22
- package/src/chains/evm/biome.json +1 -1
- package/src/chains/evm/build.ts +6 -1
- package/src/chains/evm/constants.ts +19 -0
- package/src/chains/evm/contracts/artifacts/OZGovernor.json +25 -1682
- package/src/chains/evm/dex/aerodrome/index.ts +6 -1
- package/src/chains/evm/dex/aerodrome/services/AerodromeLpService.ts +41 -15
- package/src/chains/evm/dex/aerodrome/types.ts +1 -2
- package/src/chains/evm/dex/pancakeswp/index.ts +6 -1
- package/src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts +54 -17
- package/src/chains/evm/dex/pancakeswp/types.ts +1 -2
- package/src/chains/evm/dex/uniswap/index.ts +6 -1
- package/src/chains/evm/dex/uniswap/services/UniswapV3LpService.ts +20 -9
- package/src/chains/evm/dex/uniswap/types.ts +1 -2
- package/src/chains/evm/gov-router.ts +3 -1
- package/src/chains/evm/index.browser.ts +1 -1
- package/src/chains/evm/index.ts +5 -1
- package/src/chains/evm/prompts.ts +5 -0
- package/src/chains/evm/providers/get-balance.ts +1 -1
- package/src/chains/evm/providers/wallet.ts +80 -9
- package/src/chains/evm/routes/sign.ts +35 -26
- package/src/chains/evm/rpc-providers.ts +1 -1
- package/src/chains/evm/types/index.ts +22 -2
- package/src/chains/registry.ts +1 -1
- package/src/chains/wallet-action.ts +301 -91
- package/src/index.ts +9 -5
- package/src/lib/wallet-export-guard.test.ts +233 -0
- package/src/lib/wallet-export-guard.ts +1 -1
- package/src/lp/actions/liquidity.ts +53 -26
- package/src/lp/e2e/real-token-tests.ts +0 -1
- package/src/lp/e2e/scenarios.ts +1 -2
- package/src/lp/e2e/test-utils.ts +20 -7
- package/src/lp/lp-manager-entry.ts +2 -5
- package/src/lp/services/ConcentratedLiquidityService.ts +3 -10
- package/src/lp/services/DexInteractionService.ts +1 -2
- package/src/lp/services/LpManagementService.test.ts +0 -1
- package/src/lp/services/LpManagementService.ts +75 -35
- package/src/lp/services/UserLpProfileService.ts +2 -3
- package/src/lp/services/VaultService.ts +10 -4
- package/src/lp/services/YieldOptimizationService.ts +29 -13
- package/src/lp/services/__tests__/MockLpService.ts +1 -2
- package/src/lp/types.ts +9 -13
- package/src/lp/utils/solanaClient.ts +4 -2
- package/src/plugin.routes.test.ts +24 -0
- package/src/plugin.ts +30 -13
- package/src/providers/canonical-provider.ts +1 -1
- package/src/providers/{unified-wallet-provider.ts → wallet-provider.ts} +3 -3
- package/src/routes/__fixtures__/coingecko-markets.recorded.json +97 -0
- package/src/routes/wallet-market-overview-route.ts +1 -1
- package/src/routes/wallet-market-overview.contract.test.ts +139 -0
- package/src/routes/wallet-market-overview.real.test.ts +83 -0
- package/src/sdk/escrow/MutualStakeEscrow.ts +1 -2
- package/src/sdk/identity/erc8004.ts +1 -1
- package/src/sdk/identity/validation.ts +3 -4
- package/src/sdk/index.ts +2 -2
- package/src/sdk/policy/SpendingPolicy.ts +1 -1
- package/src/sdk/router/PaymentRouter.ts +8 -11
- package/src/sdk/swap/SwapModule.ts +1 -1
- package/src/sdk/tokens/registry.ts +1 -1
- package/src/sdk/x402/middleware.ts +2 -8
- package/src/security/__tests__/wallet-context-safety.test.ts +79 -0
- package/src/security/__tests__/wallet-financial-confirmation.test.ts +88 -0
- package/src/security/wallet-context-safety.ts +128 -0
- package/src/security/wallet-financial-confirmation.ts +150 -0
- package/src/services/wallet-backend-service.ts +15 -1
- package/src/utils/intent-trajectory.ts +2 -2
- package/src/wallet/steward-backend.ts +4 -4
- package/dist/LpManagementService-BWrQ5-cO.mjs +0 -353
- package/dist/MockLpService-D_Apn4Fd.mjs +0 -99
- package/dist/aerodrome-CfnESC32.mjs +0 -890
- package/dist/chunk-hT5z_Zn9.mjs +0 -35
- package/dist/lib/server-wallet-trade.d.mts +0 -34
- package/dist/lib/server-wallet-trade.mjs +0 -306
- package/dist/meteora-BPX39hZo.mjs +0 -22640
- package/dist/orca-Bybp1HXO.mjs +0 -249
- package/dist/pancakeswp-CkEXlXti.mjs +0 -604
- package/dist/plugin-ZO_MTyd0.mjs +0 -529
- package/dist/raydium-rfaM9yEf.mjs +0 -539
- package/dist/sdk/index.d.mts +0 -32492
- package/dist/sdk/index.mjs +0 -6415
- package/dist/types-D5252NZk.mjs +0 -487
- package/dist/uniswap-CReXgXVN.mjs +0 -573
- package/dist/wallet-action.d.mts +0 -6
- package/dist/wallet-action.mjs +0 -820
- package/src/analytics/birdeye/tasks/birdeye.ts +0 -232
- package/src/analytics/lpinfo/index.d.ts +0 -7
- package/src/chains/evm/contracts/artifacts/TimelockController.json +0 -1007
- package/src/chains/evm/contracts/artifacts/VoteToken.json +0 -895
- package/src/lp/tasks/LpAutoRebalanceTask.ts +0 -117
- package/src/lp/tasks/__tests__/LpAutoRebalanceTask.test.ts +0 -370
|
@@ -1,604 +0,0 @@
|
|
|
1
|
-
import { n as __exportAll } from "./chunk-hT5z_Zn9.mjs";
|
|
2
|
-
import { o as registerLpProtocolProvider, r as createEvmLpProtocolProvider } from "./LpManagementService-BWrQ5-cO.mjs";
|
|
3
|
-
import { a as UNISWAP_V3_POOL_ABI, o as UNISWAP_V3_POSITION_MANAGER_ABI, r as UNISWAP_V3_FACTORY_ABI, t as ERC20_ABI } from "./types-D5252NZk.mjs";
|
|
4
|
-
import { Service, logger } from "@elizaos/core";
|
|
5
|
-
import { createPublicClient, createWalletClient, http, maxUint128 } from "viem";
|
|
6
|
-
import * as viemChains from "viem/chains";
|
|
7
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
8
|
-
//#region src/chains/evm/dex/pancakeswp/types.ts
|
|
9
|
-
/**
|
|
10
|
-
* PancakeSwap V3 specific types
|
|
11
|
-
* PancakeSwap V3 is based on Uniswap V3 with some modifications
|
|
12
|
-
*/
|
|
13
|
-
const PANCAKESWAP_V3_FEE_TIERS = {
|
|
14
|
-
LOWEST: 100,
|
|
15
|
-
LOW: 500,
|
|
16
|
-
MEDIUM: 2500,
|
|
17
|
-
HIGH: 1e4
|
|
18
|
-
};
|
|
19
|
-
const PANCAKESWAP_V3_ADDRESSES = {
|
|
20
|
-
56: {
|
|
21
|
-
factory: "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865",
|
|
22
|
-
nonfungiblePositionManager: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364",
|
|
23
|
-
swapRouter: "0x1b81D678ffb9C0263b24A97847620C99d213eB14",
|
|
24
|
-
quoter: "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997"
|
|
25
|
-
},
|
|
26
|
-
1: {
|
|
27
|
-
factory: "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865",
|
|
28
|
-
nonfungiblePositionManager: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364",
|
|
29
|
-
swapRouter: "0x1b81D678ffb9C0263b24A97847620C99d213eB14",
|
|
30
|
-
quoter: "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997"
|
|
31
|
-
},
|
|
32
|
-
42161: {
|
|
33
|
-
factory: "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865",
|
|
34
|
-
nonfungiblePositionManager: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364",
|
|
35
|
-
swapRouter: "0x1b81D678ffb9C0263b24A97847620C99d213eB14",
|
|
36
|
-
quoter: "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997"
|
|
37
|
-
},
|
|
38
|
-
8453: {
|
|
39
|
-
factory: "0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865",
|
|
40
|
-
nonfungiblePositionManager: "0x46A15B0b27311cedF172AB29E4f4766fbE7F4364",
|
|
41
|
-
swapRouter: "0x1b81D678ffb9C0263b24A97847620C99d213eB14",
|
|
42
|
-
quoter: "0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997"
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/chains/evm/dex/pancakeswp/services/PancakeSwapV3LpService.ts
|
|
47
|
-
const SUPPORTED_CHAIN_IDS = [
|
|
48
|
-
56,
|
|
49
|
-
1,
|
|
50
|
-
42161,
|
|
51
|
-
8453
|
|
52
|
-
];
|
|
53
|
-
function getViemChain(chainId) {
|
|
54
|
-
const chain = {
|
|
55
|
-
1: viemChains.mainnet,
|
|
56
|
-
56: viemChains.bsc,
|
|
57
|
-
42161: viemChains.arbitrum,
|
|
58
|
-
8453: viemChains.base
|
|
59
|
-
}[chainId];
|
|
60
|
-
if (!chain) throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
61
|
-
return chain;
|
|
62
|
-
}
|
|
63
|
-
var PancakeSwapV3LpService = class PancakeSwapV3LpService extends Service {
|
|
64
|
-
static serviceType = "pancakeswap-v3-lp";
|
|
65
|
-
capabilityDescription = "Provides PancakeSwap V3 liquidity pool management for EVM chains.";
|
|
66
|
-
publicClients = /* @__PURE__ */ new Map();
|
|
67
|
-
walletClients = /* @__PURE__ */ new Map();
|
|
68
|
-
rpcUrls = /* @__PURE__ */ new Map();
|
|
69
|
-
constructor(runtime) {
|
|
70
|
-
super(runtime);
|
|
71
|
-
if (runtime) this.initializeRpcUrls();
|
|
72
|
-
}
|
|
73
|
-
initializeRpcUrls() {
|
|
74
|
-
for (const [chainId, envKeys] of Object.entries({
|
|
75
|
-
1: [
|
|
76
|
-
"ETHEREUM_RPC_URL",
|
|
77
|
-
"ETH_RPC_URL",
|
|
78
|
-
"EVM_PROVIDER_MAINNET"
|
|
79
|
-
],
|
|
80
|
-
56: [
|
|
81
|
-
"BSC_RPC_URL",
|
|
82
|
-
"BNB_RPC_URL",
|
|
83
|
-
"EVM_PROVIDER_BSC"
|
|
84
|
-
],
|
|
85
|
-
42161: ["ARBITRUM_RPC_URL", "EVM_PROVIDER_ARBITRUM"],
|
|
86
|
-
8453: ["BASE_RPC_URL", "EVM_PROVIDER_BASE"]
|
|
87
|
-
})) for (const key of envKeys) {
|
|
88
|
-
const rpcUrl = this.runtime.getSetting(key);
|
|
89
|
-
if (rpcUrl && typeof rpcUrl === "string") {
|
|
90
|
-
this.rpcUrls.set(Number(chainId), rpcUrl);
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
getPublicClient(chainId) {
|
|
96
|
-
let client = this.publicClients.get(chainId);
|
|
97
|
-
if (client) return client;
|
|
98
|
-
const rpcUrl = this.rpcUrls.get(chainId);
|
|
99
|
-
client = createPublicClient({
|
|
100
|
-
chain: getViemChain(chainId),
|
|
101
|
-
transport: rpcUrl ? http(rpcUrl) : http()
|
|
102
|
-
});
|
|
103
|
-
this.publicClients.set(chainId, client);
|
|
104
|
-
return client;
|
|
105
|
-
}
|
|
106
|
-
getWalletClient(chainId, privateKey) {
|
|
107
|
-
const cacheKey = chainId;
|
|
108
|
-
let client = this.walletClients.get(cacheKey);
|
|
109
|
-
if (client) return client;
|
|
110
|
-
const rpcUrl = this.rpcUrls.get(chainId);
|
|
111
|
-
const chain = getViemChain(chainId);
|
|
112
|
-
const account = privateKeyToAccount(privateKey);
|
|
113
|
-
client = createWalletClient({
|
|
114
|
-
chain,
|
|
115
|
-
transport: rpcUrl ? http(rpcUrl) : http(),
|
|
116
|
-
account
|
|
117
|
-
});
|
|
118
|
-
this.walletClients.set(cacheKey, client);
|
|
119
|
-
return client;
|
|
120
|
-
}
|
|
121
|
-
static async start(runtime) {
|
|
122
|
-
const service = new PancakeSwapV3LpService(runtime);
|
|
123
|
-
logger.info("[PancakeSwapV3LpService] started");
|
|
124
|
-
return service;
|
|
125
|
-
}
|
|
126
|
-
async stop() {
|
|
127
|
-
this.publicClients.clear();
|
|
128
|
-
this.walletClients.clear();
|
|
129
|
-
logger.info("[PancakeSwapV3LpService] stopped");
|
|
130
|
-
}
|
|
131
|
-
getDexName() {
|
|
132
|
-
return "pancakeswap";
|
|
133
|
-
}
|
|
134
|
-
getSupportedChainIds() {
|
|
135
|
-
return SUPPORTED_CHAIN_IDS.filter((chainId) => PANCAKESWAP_V3_ADDRESSES[chainId] !== void 0);
|
|
136
|
-
}
|
|
137
|
-
supportsChain(chainId) {
|
|
138
|
-
return this.getSupportedChainIds().includes(chainId);
|
|
139
|
-
}
|
|
140
|
-
async getPools(chainId, tokenA, tokenB, feeTier) {
|
|
141
|
-
if (!this.supportsChain(chainId)) {
|
|
142
|
-
logger.warn(`[PancakeSwapV3LpService] Chain ${chainId} not supported`);
|
|
143
|
-
return [];
|
|
144
|
-
}
|
|
145
|
-
const addresses = PANCAKESWAP_V3_ADDRESSES[chainId];
|
|
146
|
-
if (!addresses) return [];
|
|
147
|
-
const client = this.getPublicClient(chainId);
|
|
148
|
-
const pools = [];
|
|
149
|
-
if (tokenA && tokenB) {
|
|
150
|
-
const feeTiers = feeTier ? [feeTier] : Object.values(PANCAKESWAP_V3_FEE_TIERS);
|
|
151
|
-
for (const fee of feeTiers) try {
|
|
152
|
-
const poolAddress = await client.readContract({
|
|
153
|
-
address: addresses.factory,
|
|
154
|
-
abi: UNISWAP_V3_FACTORY_ABI,
|
|
155
|
-
functionName: "getPool",
|
|
156
|
-
args: [
|
|
157
|
-
tokenA,
|
|
158
|
-
tokenB,
|
|
159
|
-
fee
|
|
160
|
-
]
|
|
161
|
-
});
|
|
162
|
-
if (poolAddress && poolAddress !== "0x0000000000000000000000000000000000000000") {
|
|
163
|
-
const poolInfo = await this.getPoolInfo(chainId, poolAddress);
|
|
164
|
-
if (poolInfo) pools.push(poolInfo);
|
|
165
|
-
}
|
|
166
|
-
} catch (_error) {
|
|
167
|
-
logger.debug(`[PancakeSwapV3LpService] No pool found for ${tokenA}/${tokenB} at fee ${fee}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return pools;
|
|
171
|
-
}
|
|
172
|
-
async getPoolInfo(chainId, poolAddress) {
|
|
173
|
-
const client = this.getPublicClient(chainId);
|
|
174
|
-
const chain = getViemChain(chainId);
|
|
175
|
-
try {
|
|
176
|
-
const [token0, token1, fee, tickSpacing, _liquidity, slot0] = await Promise.all([
|
|
177
|
-
client.readContract({
|
|
178
|
-
address: poolAddress,
|
|
179
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
180
|
-
functionName: "token0"
|
|
181
|
-
}),
|
|
182
|
-
client.readContract({
|
|
183
|
-
address: poolAddress,
|
|
184
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
185
|
-
functionName: "token1"
|
|
186
|
-
}),
|
|
187
|
-
client.readContract({
|
|
188
|
-
address: poolAddress,
|
|
189
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
190
|
-
functionName: "fee"
|
|
191
|
-
}),
|
|
192
|
-
client.readContract({
|
|
193
|
-
address: poolAddress,
|
|
194
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
195
|
-
functionName: "tickSpacing"
|
|
196
|
-
}),
|
|
197
|
-
client.readContract({
|
|
198
|
-
address: poolAddress,
|
|
199
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
200
|
-
functionName: "liquidity"
|
|
201
|
-
}),
|
|
202
|
-
client.readContract({
|
|
203
|
-
address: poolAddress,
|
|
204
|
-
abi: UNISWAP_V3_POOL_ABI,
|
|
205
|
-
functionName: "slot0"
|
|
206
|
-
})
|
|
207
|
-
]);
|
|
208
|
-
const [symbol0, decimals0, symbol1, decimals1] = await Promise.all([
|
|
209
|
-
client.readContract({
|
|
210
|
-
address: token0,
|
|
211
|
-
abi: ERC20_ABI,
|
|
212
|
-
functionName: "symbol"
|
|
213
|
-
}).catch(() => "UNKNOWN"),
|
|
214
|
-
client.readContract({
|
|
215
|
-
address: token0,
|
|
216
|
-
abi: ERC20_ABI,
|
|
217
|
-
functionName: "decimals"
|
|
218
|
-
}).catch(() => 18),
|
|
219
|
-
client.readContract({
|
|
220
|
-
address: token1,
|
|
221
|
-
abi: ERC20_ABI,
|
|
222
|
-
functionName: "symbol"
|
|
223
|
-
}).catch(() => "UNKNOWN"),
|
|
224
|
-
client.readContract({
|
|
225
|
-
address: token1,
|
|
226
|
-
abi: ERC20_ABI,
|
|
227
|
-
functionName: "decimals"
|
|
228
|
-
}).catch(() => 18)
|
|
229
|
-
]);
|
|
230
|
-
return {
|
|
231
|
-
id: poolAddress,
|
|
232
|
-
dex: "pancakeswap",
|
|
233
|
-
chainId,
|
|
234
|
-
chainName: chain.name,
|
|
235
|
-
poolAddress,
|
|
236
|
-
tokenA: {
|
|
237
|
-
address: token0,
|
|
238
|
-
symbol: symbol0,
|
|
239
|
-
decimals: Number(decimals0)
|
|
240
|
-
},
|
|
241
|
-
tokenB: {
|
|
242
|
-
address: token1,
|
|
243
|
-
symbol: symbol1,
|
|
244
|
-
decimals: Number(decimals1)
|
|
245
|
-
},
|
|
246
|
-
feeTier: Number(fee),
|
|
247
|
-
tickSpacing: Number(tickSpacing),
|
|
248
|
-
currentTick: Number(slot0[1]),
|
|
249
|
-
sqrtPriceX96: slot0[0],
|
|
250
|
-
fee: Number(fee) / 1e6,
|
|
251
|
-
displayName: `${symbol0}/${symbol1} (${Number(fee) / 1e4}%)`
|
|
252
|
-
};
|
|
253
|
-
} catch (error) {
|
|
254
|
-
logger.error(`[PancakeSwapV3LpService] Error fetching pool info for ${poolAddress}:`, error);
|
|
255
|
-
return null;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async addLiquidity(params) {
|
|
259
|
-
if (!this.supportsChain(params.chainId)) return {
|
|
260
|
-
success: false,
|
|
261
|
-
error: `Chain ${params.chainId} not supported`
|
|
262
|
-
};
|
|
263
|
-
const addresses = PANCAKESWAP_V3_ADDRESSES[params.chainId];
|
|
264
|
-
if (!addresses) return {
|
|
265
|
-
success: false,
|
|
266
|
-
error: "PancakeSwap V3 not deployed on this chain"
|
|
267
|
-
};
|
|
268
|
-
try {
|
|
269
|
-
const publicClient = this.getPublicClient(params.chainId);
|
|
270
|
-
const walletClient = this.getWalletClient(params.chainId, params.wallet.privateKey);
|
|
271
|
-
const poolInfo = await this.getPoolInfo(params.chainId, params.poolAddress);
|
|
272
|
-
if (!poolInfo) return {
|
|
273
|
-
success: false,
|
|
274
|
-
error: "Pool not found"
|
|
275
|
-
};
|
|
276
|
-
const slippageMultiplier = BigInt(1e4 - params.slippageBps);
|
|
277
|
-
const amount0Min = params.tokenAAmount * slippageMultiplier / 10000n;
|
|
278
|
-
const amount1Min = (params.tokenBAmount ?? 0n) * slippageMultiplier / 10000n;
|
|
279
|
-
await this.approveToken(params.chainId, params.wallet.privateKey, poolInfo.tokenA.address, addresses.nonfungiblePositionManager, params.tokenAAmount);
|
|
280
|
-
if (params.tokenBAmount && params.tokenBAmount > 0n) await this.approveToken(params.chainId, params.wallet.privateKey, poolInfo.tokenB.address, addresses.nonfungiblePositionManager, params.tokenBAmount);
|
|
281
|
-
const deadline = params.deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 1800);
|
|
282
|
-
const tickLower = params.tickLower ?? poolInfo.currentTick - 1e3;
|
|
283
|
-
const tickUpper = params.tickUpper ?? poolInfo.currentTick + 1e3;
|
|
284
|
-
const tickSpacing = poolInfo.tickSpacing ?? 50;
|
|
285
|
-
const alignedTickLower = Math.floor(tickLower / tickSpacing) * tickSpacing;
|
|
286
|
-
const alignedTickUpper = Math.ceil(tickUpper / tickSpacing) * tickSpacing;
|
|
287
|
-
const mintParams = {
|
|
288
|
-
token0: poolInfo.tokenA.address,
|
|
289
|
-
token1: poolInfo.tokenB.address,
|
|
290
|
-
fee: poolInfo.feeTier,
|
|
291
|
-
tickLower: alignedTickLower,
|
|
292
|
-
tickUpper: alignedTickUpper,
|
|
293
|
-
amount0Desired: params.tokenAAmount,
|
|
294
|
-
amount1Desired: params.tokenBAmount ?? 0n,
|
|
295
|
-
amount0Min,
|
|
296
|
-
amount1Min,
|
|
297
|
-
recipient: params.wallet.address,
|
|
298
|
-
deadline
|
|
299
|
-
};
|
|
300
|
-
const { request } = await publicClient.simulateContract({
|
|
301
|
-
address: addresses.nonfungiblePositionManager,
|
|
302
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
303
|
-
functionName: "mint",
|
|
304
|
-
args: [mintParams],
|
|
305
|
-
account: walletClient.account
|
|
306
|
-
});
|
|
307
|
-
const hash = await walletClient.writeContract(request);
|
|
308
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
309
|
-
return {
|
|
310
|
-
success: receipt.status === "success",
|
|
311
|
-
transactionId: hash,
|
|
312
|
-
hash,
|
|
313
|
-
chainId: params.chainId,
|
|
314
|
-
blockNumber: receipt.blockNumber,
|
|
315
|
-
gasUsed: receipt.gasUsed,
|
|
316
|
-
data: {
|
|
317
|
-
poolAddress: params.poolAddress,
|
|
318
|
-
tickLower: alignedTickLower,
|
|
319
|
-
tickUpper: alignedTickUpper
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
} catch (error) {
|
|
323
|
-
logger.error("[PancakeSwapV3LpService] Error adding liquidity:", error);
|
|
324
|
-
return {
|
|
325
|
-
success: false,
|
|
326
|
-
error: error instanceof Error ? error.message : "Unknown error adding liquidity"
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async removeLiquidity(params) {
|
|
331
|
-
if (!this.supportsChain(params.chainId)) return {
|
|
332
|
-
success: false,
|
|
333
|
-
error: `Chain ${params.chainId} not supported`
|
|
334
|
-
};
|
|
335
|
-
const addresses = PANCAKESWAP_V3_ADDRESSES[params.chainId];
|
|
336
|
-
if (!addresses) return {
|
|
337
|
-
success: false,
|
|
338
|
-
error: "PancakeSwap V3 not deployed on this chain"
|
|
339
|
-
};
|
|
340
|
-
if (!params.tokenId) return {
|
|
341
|
-
success: false,
|
|
342
|
-
error: "Position token ID required for PancakeSwap V3"
|
|
343
|
-
};
|
|
344
|
-
try {
|
|
345
|
-
const publicClient = this.getPublicClient(params.chainId);
|
|
346
|
-
const walletClient = this.getWalletClient(params.chainId, params.wallet.privateKey);
|
|
347
|
-
const position = await this.getPositionFromContract(params.chainId, params.tokenId);
|
|
348
|
-
if (!position) return {
|
|
349
|
-
success: false,
|
|
350
|
-
error: "Position not found"
|
|
351
|
-
};
|
|
352
|
-
let liquidityToRemove = position.liquidity;
|
|
353
|
-
if (params.percentageToRemove && params.percentageToRemove < 100) liquidityToRemove = position.liquidity * BigInt(params.percentageToRemove) / 100n;
|
|
354
|
-
const deadline = params.deadline ?? BigInt(Math.floor(Date.now() / 1e3) + 1800);
|
|
355
|
-
const decreaseParams = {
|
|
356
|
-
tokenId: params.tokenId,
|
|
357
|
-
liquidity: liquidityToRemove,
|
|
358
|
-
amount0Min: 0n,
|
|
359
|
-
amount1Min: 0n,
|
|
360
|
-
deadline
|
|
361
|
-
};
|
|
362
|
-
const { request: decreaseRequest } = await publicClient.simulateContract({
|
|
363
|
-
address: addresses.nonfungiblePositionManager,
|
|
364
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
365
|
-
functionName: "decreaseLiquidity",
|
|
366
|
-
args: [decreaseParams],
|
|
367
|
-
account: walletClient.account
|
|
368
|
-
});
|
|
369
|
-
const decreaseHash = await walletClient.writeContract(decreaseRequest);
|
|
370
|
-
await publicClient.waitForTransactionReceipt({ hash: decreaseHash });
|
|
371
|
-
const collectParams = {
|
|
372
|
-
tokenId: params.tokenId,
|
|
373
|
-
recipient: params.wallet.address,
|
|
374
|
-
amount0Max: maxUint128,
|
|
375
|
-
amount1Max: maxUint128
|
|
376
|
-
};
|
|
377
|
-
const { request: collectRequest } = await publicClient.simulateContract({
|
|
378
|
-
address: addresses.nonfungiblePositionManager,
|
|
379
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
380
|
-
functionName: "collect",
|
|
381
|
-
args: [collectParams],
|
|
382
|
-
account: walletClient.account
|
|
383
|
-
});
|
|
384
|
-
const collectHash = await walletClient.writeContract(collectRequest);
|
|
385
|
-
const receipt = await publicClient.waitForTransactionReceipt({ hash: collectHash });
|
|
386
|
-
if (params.percentageToRemove === 100 || !params.percentageToRemove) try {
|
|
387
|
-
const { request: burnRequest } = await publicClient.simulateContract({
|
|
388
|
-
address: addresses.nonfungiblePositionManager,
|
|
389
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
390
|
-
functionName: "burn",
|
|
391
|
-
args: [params.tokenId],
|
|
392
|
-
account: walletClient.account
|
|
393
|
-
});
|
|
394
|
-
await walletClient.writeContract(burnRequest);
|
|
395
|
-
} catch (burnError) {
|
|
396
|
-
logger.debug("[PancakeSwapV3LpService] Could not burn position NFT:", burnError);
|
|
397
|
-
}
|
|
398
|
-
return {
|
|
399
|
-
success: receipt.status === "success",
|
|
400
|
-
transactionId: collectHash,
|
|
401
|
-
hash: collectHash,
|
|
402
|
-
chainId: params.chainId,
|
|
403
|
-
blockNumber: receipt.blockNumber,
|
|
404
|
-
gasUsed: receipt.gasUsed
|
|
405
|
-
};
|
|
406
|
-
} catch (error) {
|
|
407
|
-
logger.error("[PancakeSwapV3LpService] Error removing liquidity:", error);
|
|
408
|
-
return {
|
|
409
|
-
success: false,
|
|
410
|
-
error: error instanceof Error ? error.message : "Unknown error removing liquidity"
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
async getPositionFromContract(chainId, tokenId) {
|
|
415
|
-
const addresses = PANCAKESWAP_V3_ADDRESSES[chainId];
|
|
416
|
-
if (!addresses) return null;
|
|
417
|
-
const client = this.getPublicClient(chainId);
|
|
418
|
-
try {
|
|
419
|
-
const result = await client.readContract({
|
|
420
|
-
address: addresses.nonfungiblePositionManager,
|
|
421
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
422
|
-
functionName: "positions",
|
|
423
|
-
args: [tokenId]
|
|
424
|
-
});
|
|
425
|
-
return {
|
|
426
|
-
tokenId,
|
|
427
|
-
nonce: result[0],
|
|
428
|
-
operator: result[1],
|
|
429
|
-
token0: result[2],
|
|
430
|
-
token1: result[3],
|
|
431
|
-
fee: result[4],
|
|
432
|
-
tickLower: result[5],
|
|
433
|
-
tickUpper: result[6],
|
|
434
|
-
liquidity: result[7],
|
|
435
|
-
feeGrowthInside0LastX128: result[8],
|
|
436
|
-
feeGrowthInside1LastX128: result[9],
|
|
437
|
-
tokensOwed0: result[10],
|
|
438
|
-
tokensOwed1: result[11]
|
|
439
|
-
};
|
|
440
|
-
} catch (error) {
|
|
441
|
-
logger.error(`[PancakeSwapV3LpService] Error fetching position ${tokenId}:`, error);
|
|
442
|
-
return null;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async getPositionDetails(chainId, owner, poolAddress, tokenId) {
|
|
446
|
-
if (!this.supportsChain(chainId)) return null;
|
|
447
|
-
if (tokenId) {
|
|
448
|
-
const position = await this.getPositionFromContract(chainId, tokenId);
|
|
449
|
-
if (!position) return null;
|
|
450
|
-
const client = this.getPublicClient(chainId);
|
|
451
|
-
const [symbol0, decimals0, symbol1, decimals1] = await Promise.all([
|
|
452
|
-
client.readContract({
|
|
453
|
-
address: position.token0,
|
|
454
|
-
abi: ERC20_ABI,
|
|
455
|
-
functionName: "symbol"
|
|
456
|
-
}).catch(() => "UNKNOWN"),
|
|
457
|
-
client.readContract({
|
|
458
|
-
address: position.token0,
|
|
459
|
-
abi: ERC20_ABI,
|
|
460
|
-
functionName: "decimals"
|
|
461
|
-
}).catch(() => 18),
|
|
462
|
-
client.readContract({
|
|
463
|
-
address: position.token1,
|
|
464
|
-
abi: ERC20_ABI,
|
|
465
|
-
functionName: "symbol"
|
|
466
|
-
}).catch(() => "UNKNOWN"),
|
|
467
|
-
client.readContract({
|
|
468
|
-
address: position.token1,
|
|
469
|
-
abi: ERC20_ABI,
|
|
470
|
-
functionName: "decimals"
|
|
471
|
-
}).catch(() => 18)
|
|
472
|
-
]);
|
|
473
|
-
return {
|
|
474
|
-
poolId: poolAddress,
|
|
475
|
-
dex: "pancakeswap",
|
|
476
|
-
chainId,
|
|
477
|
-
owner,
|
|
478
|
-
tokenId: position.tokenId,
|
|
479
|
-
tickLower: position.tickLower,
|
|
480
|
-
tickUpper: position.tickUpper,
|
|
481
|
-
liquidity: position.liquidity,
|
|
482
|
-
lpTokenBalance: {
|
|
483
|
-
address: poolAddress,
|
|
484
|
-
balance: position.liquidity.toString(),
|
|
485
|
-
decimals: 0,
|
|
486
|
-
symbol: `PCS-V3-${symbol0}/${symbol1}`
|
|
487
|
-
},
|
|
488
|
-
underlyingTokens: [{
|
|
489
|
-
address: position.token0,
|
|
490
|
-
balance: position.tokensOwed0.toString(),
|
|
491
|
-
decimals: Number(decimals0),
|
|
492
|
-
symbol: symbol0
|
|
493
|
-
}, {
|
|
494
|
-
address: position.token1,
|
|
495
|
-
balance: position.tokensOwed1.toString(),
|
|
496
|
-
decimals: Number(decimals1),
|
|
497
|
-
symbol: symbol1
|
|
498
|
-
}]
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
return (await this.getAllPositions(chainId, owner)).find((p) => p.poolId.toLowerCase() === poolAddress.toLowerCase()) ?? null;
|
|
502
|
-
}
|
|
503
|
-
async getAllPositions(chainId, owner) {
|
|
504
|
-
if (!this.supportsChain(chainId)) return [];
|
|
505
|
-
const addresses = PANCAKESWAP_V3_ADDRESSES[chainId];
|
|
506
|
-
if (!addresses) return [];
|
|
507
|
-
const client = this.getPublicClient(chainId);
|
|
508
|
-
const positions = [];
|
|
509
|
-
try {
|
|
510
|
-
const balance = await client.readContract({
|
|
511
|
-
address: addresses.nonfungiblePositionManager,
|
|
512
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
513
|
-
functionName: "balanceOf",
|
|
514
|
-
args: [owner]
|
|
515
|
-
});
|
|
516
|
-
for (let i = 0; i < Number(balance); i++) {
|
|
517
|
-
const tokenId = await client.readContract({
|
|
518
|
-
address: addresses.nonfungiblePositionManager,
|
|
519
|
-
abi: UNISWAP_V3_POSITION_MANAGER_ABI,
|
|
520
|
-
functionName: "tokenOfOwnerByIndex",
|
|
521
|
-
args: [owner, BigInt(i)]
|
|
522
|
-
});
|
|
523
|
-
const position = await this.getPositionFromContract(chainId, tokenId);
|
|
524
|
-
if (position && position.liquidity > 0n) {
|
|
525
|
-
const poolAddress = await client.readContract({
|
|
526
|
-
address: addresses.factory,
|
|
527
|
-
abi: UNISWAP_V3_FACTORY_ABI,
|
|
528
|
-
functionName: "getPool",
|
|
529
|
-
args: [
|
|
530
|
-
position.token0,
|
|
531
|
-
position.token1,
|
|
532
|
-
position.fee
|
|
533
|
-
]
|
|
534
|
-
});
|
|
535
|
-
if (poolAddress) {
|
|
536
|
-
const details = await this.getPositionDetails(chainId, owner, poolAddress, tokenId);
|
|
537
|
-
if (details) positions.push(details);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
} catch (error) {
|
|
542
|
-
logger.error("[PancakeSwapV3LpService] Error fetching all positions:", error);
|
|
543
|
-
}
|
|
544
|
-
return positions;
|
|
545
|
-
}
|
|
546
|
-
async getMarketData(poolAddresses) {
|
|
547
|
-
const result = {};
|
|
548
|
-
for (const address of poolAddresses) for (const chainId of this.getSupportedChainIds()) try {
|
|
549
|
-
const poolInfo = await this.getPoolInfo(chainId, address);
|
|
550
|
-
if (poolInfo) {
|
|
551
|
-
result[address] = poolInfo;
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
} catch {}
|
|
555
|
-
return result;
|
|
556
|
-
}
|
|
557
|
-
async approveToken(chainId, privateKey, tokenAddress, spenderAddress, amount) {
|
|
558
|
-
const publicClient = this.getPublicClient(chainId);
|
|
559
|
-
const walletClient = this.getWalletClient(chainId, privateKey);
|
|
560
|
-
if (await publicClient.readContract({
|
|
561
|
-
address: tokenAddress,
|
|
562
|
-
abi: ERC20_ABI,
|
|
563
|
-
functionName: "allowance",
|
|
564
|
-
args: [walletClient.account?.address, spenderAddress]
|
|
565
|
-
}) >= amount) return;
|
|
566
|
-
logger.info(`[PancakeSwapV3LpService] Approving ${tokenAddress} for ${spenderAddress}`);
|
|
567
|
-
const { request } = await publicClient.simulateContract({
|
|
568
|
-
address: tokenAddress,
|
|
569
|
-
abi: ERC20_ABI,
|
|
570
|
-
functionName: "approve",
|
|
571
|
-
args: [spenderAddress, amount],
|
|
572
|
-
account: walletClient.account
|
|
573
|
-
});
|
|
574
|
-
const hash = await walletClient.writeContract(request);
|
|
575
|
-
await publicClient.waitForTransactionReceipt({ hash });
|
|
576
|
-
logger.info(`[PancakeSwapV3LpService] Token approved: ${hash}`);
|
|
577
|
-
}
|
|
578
|
-
};
|
|
579
|
-
//#endregion
|
|
580
|
-
//#region src/chains/evm/dex/pancakeswp/index.ts
|
|
581
|
-
var pancakeswp_exports = /* @__PURE__ */ __exportAll({
|
|
582
|
-
PANCAKESWAP_V3_ADDRESSES: () => PANCAKESWAP_V3_ADDRESSES,
|
|
583
|
-
PANCAKESWAP_V3_FEE_TIERS: () => PANCAKESWAP_V3_FEE_TIERS,
|
|
584
|
-
PancakeSwapV3LpService: () => PancakeSwapV3LpService,
|
|
585
|
-
default: () => pancakeswapPlugin,
|
|
586
|
-
pancakeswapPlugin: () => pancakeswapPlugin
|
|
587
|
-
});
|
|
588
|
-
const pancakeswapPlugin = {
|
|
589
|
-
name: "@elizaos/plugin-lp-manager/pancakeswap",
|
|
590
|
-
description: "PancakeSwap V3 liquidity pool management plugin",
|
|
591
|
-
services: [PancakeSwapV3LpService],
|
|
592
|
-
actions: [],
|
|
593
|
-
providers: [],
|
|
594
|
-
init: async (_config, runtime) => {
|
|
595
|
-
console.info("PancakeSwap V3 Plugin initialized");
|
|
596
|
-
await registerLpProtocolProvider(runtime, createEvmLpProtocolProvider({
|
|
597
|
-
dex: "pancakeswap",
|
|
598
|
-
label: "PancakeSwap V3",
|
|
599
|
-
service: runtime.getService(PancakeSwapV3LpService.serviceType) ?? await PancakeSwapV3LpService.start(runtime)
|
|
600
|
-
}));
|
|
601
|
-
}
|
|
602
|
-
};
|
|
603
|
-
//#endregion
|
|
604
|
-
export { pancakeswp_exports as n, PancakeSwapV3LpService as r, pancakeswapPlugin as t };
|