@elizaos/plugin-wallet 2.0.0-beta.1 → 2.0.3-beta.5
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
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SpendingPolicy — Programmable spending guardrails for AI agents.
|
|
3
|
+
*
|
|
4
|
+
* Beats PolicyLayer.com to market with:
|
|
5
|
+
* - MerchantAllowlist — allowlist-only merchant enforcement
|
|
6
|
+
* - RollingSpendCap — time-windowed spend limits
|
|
7
|
+
* - DraftThenApprove — human-in-the-loop for large transactions
|
|
8
|
+
* - AuditTrail — immutable local log of every payment attempt
|
|
9
|
+
* - FailClosed — policy errors always reject, never approve
|
|
10
|
+
*
|
|
11
|
+
* @module policy/SpendingPolicy
|
|
12
|
+
*/
|
|
13
|
+
/** A payment the agent wants to make. */
|
|
14
|
+
export interface PaymentIntent {
|
|
15
|
+
/** Merchant contract address or domain (e.g. "0xABC..." or "api.example.com") */
|
|
16
|
+
merchant: string;
|
|
17
|
+
/** Amount in the smallest token unit (e.g. USDC micro-cents = 6 decimals). Use number for JS safety in tests; real on-chain code passes BigInt via adapter. */
|
|
18
|
+
amount: number;
|
|
19
|
+
/** ISO-8601 timestamp string. Defaults to now if omitted. */
|
|
20
|
+
timestamp?: string;
|
|
21
|
+
/** Optional human-readable label */
|
|
22
|
+
description?: string;
|
|
23
|
+
}
|
|
24
|
+
export type PolicyStatus = "approved" | "rejected" | "draft";
|
|
25
|
+
/** Result returned by SpendingPolicy.check(). */
|
|
26
|
+
export interface PolicyResult {
|
|
27
|
+
status: PolicyStatus;
|
|
28
|
+
reason?: string;
|
|
29
|
+
draftId?: string;
|
|
30
|
+
}
|
|
31
|
+
/** A queued draft transaction awaiting approval. */
|
|
32
|
+
export interface DraftEntry {
|
|
33
|
+
draftId: string;
|
|
34
|
+
payment: PaymentIntent;
|
|
35
|
+
queuedAt: string;
|
|
36
|
+
approved: boolean;
|
|
37
|
+
rejected: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** Immutable record written to the audit log. */
|
|
40
|
+
export interface AuditEntry {
|
|
41
|
+
id: string;
|
|
42
|
+
timestamp: string;
|
|
43
|
+
merchant: string;
|
|
44
|
+
amount: number;
|
|
45
|
+
status: PolicyStatus;
|
|
46
|
+
reason?: string;
|
|
47
|
+
draftId?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Configuration passed to SpendingPolicy constructor. */
|
|
50
|
+
export interface SpendingPolicyConfig {
|
|
51
|
+
/**
|
|
52
|
+
* MerchantAllowlist: list of allowed contract addresses or domains.
|
|
53
|
+
* If provided and non-empty, only these merchants are allowed.
|
|
54
|
+
* Pass an empty array [] to disable allowlist enforcement (allow all).
|
|
55
|
+
*/
|
|
56
|
+
merchantAllowlist?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* RollingSpendCap: maximum cumulative spend in a rolling time window.
|
|
59
|
+
* Set to undefined to disable.
|
|
60
|
+
*/
|
|
61
|
+
rollingCap?: {
|
|
62
|
+
/** Max amount (same units as PaymentIntent.amount) */
|
|
63
|
+
maxAmount: number;
|
|
64
|
+
/** Window size in milliseconds (e.g. 86_400_000 for 24 h) */
|
|
65
|
+
windowMs: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* DraftThenApprove: payments above this threshold are placed in draft status
|
|
69
|
+
* for human (or another agent) approval rather than executed immediately.
|
|
70
|
+
* Set to undefined to disable.
|
|
71
|
+
*/
|
|
72
|
+
draftThreshold?: number;
|
|
73
|
+
}
|
|
74
|
+
export declare class SpendingPolicy {
|
|
75
|
+
private config;
|
|
76
|
+
private allowlist;
|
|
77
|
+
private spendWindow;
|
|
78
|
+
private auditLog;
|
|
79
|
+
private drafts;
|
|
80
|
+
constructor(config: SpendingPolicyConfig);
|
|
81
|
+
/**
|
|
82
|
+
* FailClosed: wraps the actual check logic so that ANY unhandled error
|
|
83
|
+
* produces a rejection rather than inadvertently approving a payment.
|
|
84
|
+
*/
|
|
85
|
+
check(payment: PaymentIntent): Promise<PolicyResult>;
|
|
86
|
+
/**
|
|
87
|
+
* Write a payment attempt to the immutable audit log.
|
|
88
|
+
*/
|
|
89
|
+
log(payment: PaymentIntent, result: PolicyResult): Promise<void>;
|
|
90
|
+
/** Return a copy of the current merchant allowlist. */
|
|
91
|
+
getMerchantAllowlist(): string[];
|
|
92
|
+
/** Add a merchant address/domain to the allowlist at runtime. */
|
|
93
|
+
addMerchant(address: string): void;
|
|
94
|
+
/** Return the full, immutable audit log (copy). */
|
|
95
|
+
getAuditLog(): AuditEntry[];
|
|
96
|
+
/** Approve a queued draft by its draftId. Returns false if not found. */
|
|
97
|
+
approveDraft(draftId: string): boolean;
|
|
98
|
+
/** Reject a queued draft by its draftId. Returns false if not found. */
|
|
99
|
+
rejectDraft(draftId: string): boolean;
|
|
100
|
+
/** Return all pending drafts awaiting approval or rejection. */
|
|
101
|
+
getPendingDrafts(): DraftEntry[];
|
|
102
|
+
/** Return all drafts. */
|
|
103
|
+
getAllDrafts(): DraftEntry[];
|
|
104
|
+
private _check;
|
|
105
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UptoBillingPolicy
|
|
3
|
+
*
|
|
4
|
+
* Local accounting for x402 "upto" flows where a buyer authorizes a maximum
|
|
5
|
+
* amount up front and the seller later settles only actual usage.
|
|
6
|
+
*
|
|
7
|
+
* The policy tracks three things:
|
|
8
|
+
* - the max amount authorized
|
|
9
|
+
* - the amount actually settled
|
|
10
|
+
* - ledger deltas for reservation, settlement, and release of unused capacity
|
|
11
|
+
*/
|
|
12
|
+
export type UptoAuthorizationStatus = "authorized" | "partially_settled" | "settled" | "released";
|
|
13
|
+
export interface UptoAuthorizationRequest {
|
|
14
|
+
authorizationId?: string;
|
|
15
|
+
service: string;
|
|
16
|
+
resource?: string;
|
|
17
|
+
network: string;
|
|
18
|
+
asset: string;
|
|
19
|
+
payTo: string;
|
|
20
|
+
maxAmount: bigint;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
authorizedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface UptoSettlementOptions {
|
|
25
|
+
settledAt?: string;
|
|
26
|
+
finalize?: boolean;
|
|
27
|
+
txHash?: string;
|
|
28
|
+
reference?: string;
|
|
29
|
+
metadata?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface UptoSettlementRecord {
|
|
32
|
+
settlementId: string;
|
|
33
|
+
authorizationId: string;
|
|
34
|
+
amount: bigint;
|
|
35
|
+
settledAt: string;
|
|
36
|
+
txHash?: string;
|
|
37
|
+
reference?: string;
|
|
38
|
+
metadata?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
export interface UptoAuthorizationRecord {
|
|
41
|
+
authorizationId: string;
|
|
42
|
+
service: string;
|
|
43
|
+
resource?: string;
|
|
44
|
+
network: string;
|
|
45
|
+
asset: string;
|
|
46
|
+
payTo: string;
|
|
47
|
+
maxAmount: bigint;
|
|
48
|
+
settledAmount: bigint;
|
|
49
|
+
releasedAmount: bigint;
|
|
50
|
+
remainingAmount: bigint;
|
|
51
|
+
authorizedAt: string;
|
|
52
|
+
finalizedAt?: string;
|
|
53
|
+
status: UptoAuthorizationStatus;
|
|
54
|
+
metadata?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface WalletLedgerDelta {
|
|
57
|
+
deltaId: string;
|
|
58
|
+
authorizationId: string;
|
|
59
|
+
type: "authorization" | "settlement" | "release";
|
|
60
|
+
timestamp: string;
|
|
61
|
+
reservedDelta: bigint;
|
|
62
|
+
settledDelta: bigint;
|
|
63
|
+
netWalletDelta: bigint;
|
|
64
|
+
txHash?: string;
|
|
65
|
+
reference?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface UptoBillingSnapshot {
|
|
68
|
+
authorization: UptoAuthorizationRecord;
|
|
69
|
+
settlements: UptoSettlementRecord[];
|
|
70
|
+
ledgerDeltas: WalletLedgerDelta[];
|
|
71
|
+
}
|
|
72
|
+
export declare class UptoBillingPolicy {
|
|
73
|
+
private authorizations;
|
|
74
|
+
private settlements;
|
|
75
|
+
private ledger;
|
|
76
|
+
authorize(request: UptoAuthorizationRequest): UptoAuthorizationRecord;
|
|
77
|
+
recordSettlement(authorizationId: string, amount: bigint, options?: UptoSettlementOptions): UptoBillingSnapshot;
|
|
78
|
+
finalizeAuthorization(authorizationId: string, finalizedAt?: string, reference?: string): UptoAuthorizationRecord;
|
|
79
|
+
getAuthorization(authorizationId: string): UptoAuthorizationRecord | null;
|
|
80
|
+
listAuthorizations(): UptoAuthorizationRecord[];
|
|
81
|
+
getSettlements(authorizationId: string): UptoSettlementRecord[];
|
|
82
|
+
getWalletLedgerDeltas(authorizationId: string): WalletLedgerDelta[];
|
|
83
|
+
getSnapshot(authorizationId: string): UptoBillingSnapshot;
|
|
84
|
+
getNetWalletDelta(authorizationId: string): bigint;
|
|
85
|
+
getReservedAmount(authorizationId: string): bigint;
|
|
86
|
+
private requireAuthorization;
|
|
87
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PaymentRouter — Three-rail payment architecture.
|
|
3
|
+
*
|
|
4
|
+
* Routes payments across three rails:
|
|
5
|
+
* 1. **x402** (crypto-native) — on-chain USDC payments via the x402 protocol. Optimal for
|
|
6
|
+
* micropayments, autonomous agents, and scenarios requiring on-chain audit trails.
|
|
7
|
+
* 2. **MPP** (Managed Payment Protocol / Stripe) — fiat-based payments with dispute resolution.
|
|
8
|
+
* Optimal for larger amounts, supervised agents, and high-frequency session batching.
|
|
9
|
+
* 3. **Google AP2** (Agent Payment Protocol) — reserved rail for Google's managed agent
|
|
10
|
+
* payment flow. Settlement on Base when explicitly marked live by configuration.
|
|
11
|
+
*
|
|
12
|
+
* Routing criteria:
|
|
13
|
+
* - Transaction amount (micropayments → x402, high-frequency → MPP)
|
|
14
|
+
* - Session context (ongoing session → MPP for batching efficiency)
|
|
15
|
+
* - Agent autonomy level (autonomous → x402, supervised → MPP)
|
|
16
|
+
* - Chain/ecosystem preference (Google ecosystem → AP2, Solana → x402-solana)
|
|
17
|
+
* - Rail availability
|
|
18
|
+
*
|
|
19
|
+
* @module router/PaymentRouter
|
|
20
|
+
*/
|
|
21
|
+
export type PaymentRail = "x402" | "mpp" | "x402-solana" | "google-ap2";
|
|
22
|
+
export type RailStatus = "live" | "planned" | "disabled";
|
|
23
|
+
export interface RailConfig {
|
|
24
|
+
rail: PaymentRail;
|
|
25
|
+
status: RailStatus;
|
|
26
|
+
/** Maximum per-transaction amount in USDC micro-units (6 decimals) */
|
|
27
|
+
maxAmount?: number;
|
|
28
|
+
/** Minimum per-transaction amount in USDC micro-units */
|
|
29
|
+
minAmount?: number;
|
|
30
|
+
}
|
|
31
|
+
export interface PaymentContext {
|
|
32
|
+
/** Amount in USDC micro-units (6 decimals). e.g. 1_000_000 = $1.00 */
|
|
33
|
+
amount: number;
|
|
34
|
+
/** Recipient address or merchant domain */
|
|
35
|
+
recipient: string;
|
|
36
|
+
/** Whether this payment is part of an active session with repeated transactions */
|
|
37
|
+
isSessionContext?: boolean;
|
|
38
|
+
/** Number of transactions in the current session (if applicable) */
|
|
39
|
+
sessionTxCount?: number;
|
|
40
|
+
/** Whether the agent is operating autonomously (no human in loop) */
|
|
41
|
+
autonomous?: boolean;
|
|
42
|
+
/** Preferred chain, if any */
|
|
43
|
+
preferredChain?: "base" | "solana" | "google-ap2";
|
|
44
|
+
}
|
|
45
|
+
export interface RoutingDecision {
|
|
46
|
+
rail: PaymentRail;
|
|
47
|
+
reason: string;
|
|
48
|
+
/** Estimated cost overhead (basis points) */
|
|
49
|
+
estimatedOverheadBps: number;
|
|
50
|
+
/** Whether this rail is currently live */
|
|
51
|
+
isLive: boolean;
|
|
52
|
+
}
|
|
53
|
+
export declare class PaymentRouter {
|
|
54
|
+
private rails;
|
|
55
|
+
/** Amount threshold (micro-units) below which x402 is preferred. Default: $1.00 */
|
|
56
|
+
private microPaymentThreshold;
|
|
57
|
+
/** Session tx count above which MPP is preferred for batching. Default: 5 */
|
|
58
|
+
private highFrequencyThreshold;
|
|
59
|
+
constructor(options?: {
|
|
60
|
+
rails?: RailConfig[];
|
|
61
|
+
microPaymentThreshold?: number;
|
|
62
|
+
highFrequencyThreshold?: number;
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Select the optimal payment rail for a given context.
|
|
66
|
+
*/
|
|
67
|
+
route(context: PaymentContext): RoutingDecision;
|
|
68
|
+
/**
|
|
69
|
+
* Get all available (live) rails.
|
|
70
|
+
*/
|
|
71
|
+
getLiveRails(): RailConfig[];
|
|
72
|
+
/**
|
|
73
|
+
* Check if a specific rail is available.
|
|
74
|
+
*/
|
|
75
|
+
isRailLive(rail: PaymentRail): boolean;
|
|
76
|
+
private getRail;
|
|
77
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module swap/SwapModule
|
|
3
|
+
* SwapModule — multi-chain Uniswap V3 token swap aggregator with 0.875% protocol fee.
|
|
4
|
+
*
|
|
5
|
+
* Supports Base, Arbitrum, Optimism, and Polygon. Automatically selects the best
|
|
6
|
+
* Uniswap V3 fee tier (0.01%, 0.05%, 0.3%, 1%) by quoting all tiers and choosing
|
|
7
|
+
* the highest output. Applies slippage protection and an optional protocol fee.
|
|
8
|
+
*
|
|
9
|
+
* Usage: construct with `chain` param or use `attachSwap(wallet, { chain: 'arbitrum' })`.
|
|
10
|
+
*/
|
|
11
|
+
import { type Address, type Hash, type PublicClient, type WalletClient } from "viem";
|
|
12
|
+
import { type SwapChain, type SwapModuleConfig, type SwapOptions, type SwapQuote, type SwapResult } from "./types.js";
|
|
13
|
+
/** Calculate protocol fee: floor(amount * feeBps / 100_000) */
|
|
14
|
+
export declare function calcProtocolFee(amount: bigint, feeBps: number): bigint;
|
|
15
|
+
/** Apply slippage: floor(amount * (10_000 - slippageBps) / 10_000) */
|
|
16
|
+
export declare function applySlippage(amount: bigint, slippageBps: number): bigint;
|
|
17
|
+
/** Encode deadline: block.timestamp + deadlineSecs */
|
|
18
|
+
export declare function calcDeadline(deadlineSecs: number): bigint;
|
|
19
|
+
export declare class SwapModule {
|
|
20
|
+
private readonly publicClient;
|
|
21
|
+
private readonly walletClient;
|
|
22
|
+
private readonly accountAddress;
|
|
23
|
+
private readonly config;
|
|
24
|
+
constructor(publicClient: PublicClient, walletClient: WalletClient, accountAddress: Address, config?: Partial<SwapModuleConfig> & {
|
|
25
|
+
chain?: SwapChain;
|
|
26
|
+
});
|
|
27
|
+
getQuote(tokenIn: Address, tokenOut: Address, amountIn: bigint, options?: Pick<SwapOptions, "slippageBps" | "feeTiers">): Promise<SwapQuote>;
|
|
28
|
+
ensureApproval(token: Address, spender: Address, amount: bigint): Promise<Hash | undefined>;
|
|
29
|
+
private transferFee;
|
|
30
|
+
swap(tokenIn: Address, tokenOut: Address, amountIn: bigint, options?: SwapOptions): Promise<SwapResult>;
|
|
31
|
+
getConfig(): SwapModuleConfig;
|
|
32
|
+
setFeeWallet(address: Address): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function attachSwap(wallet: {
|
|
35
|
+
address: Address;
|
|
36
|
+
publicClient: PublicClient;
|
|
37
|
+
walletClient: WalletClient;
|
|
38
|
+
}, config?: Partial<SwapModuleConfig> & {
|
|
39
|
+
chain?: SwapChain;
|
|
40
|
+
}): {
|
|
41
|
+
swapModule: SwapModule;
|
|
42
|
+
swap: (tokenIn: Address, tokenOut: Address, amountIn: bigint, options?: SwapOptions) => Promise<SwapResult>;
|
|
43
|
+
getQuote: (tokenIn: Address, tokenOut: Address, amountIn: bigint, options?: Pick<SwapOptions, "slippageBps" | "feeTiers">) => Promise<SwapQuote>;
|
|
44
|
+
address: Address;
|
|
45
|
+
publicClient: PublicClient;
|
|
46
|
+
walletClient: WalletClient;
|
|
47
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Uniswap V3 SwapRouter02 ABI — exactInputSingle */
|
|
2
|
+
export declare const UniswapV3RouterAbi: {
|
|
3
|
+
name: string;
|
|
4
|
+
type: string;
|
|
5
|
+
stateMutability: string;
|
|
6
|
+
inputs: {
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
components: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}[];
|
|
13
|
+
}[];
|
|
14
|
+
outputs: {
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
}[];
|
|
18
|
+
}[];
|
|
19
|
+
/** Uniswap V3 QuoterV2 ABI — quoteExactInputSingle */
|
|
20
|
+
export declare const UniswapV3QuoterV2Abi: {
|
|
21
|
+
name: string;
|
|
22
|
+
type: string;
|
|
23
|
+
stateMutability: string;
|
|
24
|
+
inputs: {
|
|
25
|
+
name: string;
|
|
26
|
+
type: string;
|
|
27
|
+
components: {
|
|
28
|
+
name: string;
|
|
29
|
+
type: string;
|
|
30
|
+
}[];
|
|
31
|
+
}[];
|
|
32
|
+
outputs: {
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}[];
|
|
36
|
+
}[];
|
|
37
|
+
/** Minimal ERC-20 ABI for allowance, approve, transferFrom */
|
|
38
|
+
export declare const ERC20Abi: {
|
|
39
|
+
name: string;
|
|
40
|
+
type: string;
|
|
41
|
+
stateMutability: string;
|
|
42
|
+
inputs: {
|
|
43
|
+
name: string;
|
|
44
|
+
type: string;
|
|
45
|
+
}[];
|
|
46
|
+
outputs: {
|
|
47
|
+
name: string;
|
|
48
|
+
type: string;
|
|
49
|
+
}[];
|
|
50
|
+
}[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module swap
|
|
3
|
+
* Re-exports for the SwapModule: multi-chain Uniswap V3 swaps.
|
|
4
|
+
*
|
|
5
|
+
* Supported chains: base, arbitrum, optimism, polygon.
|
|
6
|
+
* Use SwapModule directly or attachSwap(wallet, { chain }) for a wallet-bound instance.
|
|
7
|
+
*/
|
|
8
|
+
export { ERC20Abi, UniswapV3QuoterV2Abi, UniswapV3RouterAbi } from "./abi.js";
|
|
9
|
+
export { applySlippage, attachSwap, calcDeadline, calcProtocolFee, SwapModule, } from "./SwapModule.js";
|
|
10
|
+
export type { SwapChain, SwapModuleConfig, SwapOptions, SwapQuote, SwapResult, UniswapFeeTier, } from "./types.js";
|
|
11
|
+
export { ARBITRUM_TOKENS, BASE_TOKENS, DEFAULT_SLIPPAGE_BPS, OPTIMISM_TOKENS, POLYGON_TOKENS, PROTOCOL_FEE_BPS, PROTOCOL_FEE_COLLECTOR, UNISWAP_V3_ADDRESSES, } from "./types.js";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module swap/types
|
|
3
|
+
* Type definitions and constants for the multi-chain Uniswap V3 SwapModule.
|
|
4
|
+
*
|
|
5
|
+
* Supported swap chains: Base, Arbitrum, Optimism, Polygon.
|
|
6
|
+
* All router/quoter addresses verified against official Uniswap V3 deployment docs:
|
|
7
|
+
* - Base: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments
|
|
8
|
+
* - Arbitrum: https://docs.uniswap.org/contracts/v3/reference/deployments/arbitrum-deployments
|
|
9
|
+
* - Optimism: https://docs.uniswap.org/contracts/v3/reference/deployments/optimism-deployments
|
|
10
|
+
* - Polygon: https://docs.uniswap.org/contracts/v3/reference/deployments/polygon-deployments
|
|
11
|
+
*
|
|
12
|
+
* Note: Base uses a unique SwapRouter02 address; Arbitrum, Optimism, and Polygon
|
|
13
|
+
* share the same universal SwapRouter02 deployment address.
|
|
14
|
+
*/
|
|
15
|
+
import type { Address, Hash } from "viem";
|
|
16
|
+
/** Uniswap V3 fee tier options */
|
|
17
|
+
export type UniswapFeeTier = 100 | 500 | 3000 | 10000;
|
|
18
|
+
/** Chains supported for Uniswap V3 swap */
|
|
19
|
+
export type SwapChain = "base" | "arbitrum" | "optimism" | "polygon";
|
|
20
|
+
export interface SwapQuote {
|
|
21
|
+
tokenIn: Address;
|
|
22
|
+
tokenOut: Address;
|
|
23
|
+
amountInRaw: bigint;
|
|
24
|
+
amountInNet: bigint;
|
|
25
|
+
feeAmount: bigint;
|
|
26
|
+
amountOut: bigint;
|
|
27
|
+
amountOutMinimum: bigint;
|
|
28
|
+
poolFeeTier: UniswapFeeTier;
|
|
29
|
+
effectiveRate: number;
|
|
30
|
+
gasEstimate: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface SwapOptions {
|
|
33
|
+
slippageBps?: number;
|
|
34
|
+
feeTiers?: UniswapFeeTier[];
|
|
35
|
+
deadlineSecs?: number;
|
|
36
|
+
feeWallet?: Address;
|
|
37
|
+
}
|
|
38
|
+
export interface SwapResult {
|
|
39
|
+
txHash: Hash;
|
|
40
|
+
feeTxHash?: Hash;
|
|
41
|
+
quote: SwapQuote;
|
|
42
|
+
approvalRequired: boolean;
|
|
43
|
+
approvalTxHash?: Hash;
|
|
44
|
+
}
|
|
45
|
+
export interface SwapModuleConfig {
|
|
46
|
+
routerAddress: Address;
|
|
47
|
+
quoterAddress: Address;
|
|
48
|
+
feeBps: number;
|
|
49
|
+
feeWallet: Address;
|
|
50
|
+
/** Chain this SwapModule is configured for */
|
|
51
|
+
chain: SwapChain;
|
|
52
|
+
}
|
|
53
|
+
/** Well-known Base Mainnet token addresses */
|
|
54
|
+
export declare const BASE_TOKENS: {
|
|
55
|
+
USDC: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
56
|
+
WETH: "0x4200000000000000000000000000000000000006";
|
|
57
|
+
cbETH: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22";
|
|
58
|
+
WNATIVE: "0x4200000000000000000000000000000000000006";
|
|
59
|
+
};
|
|
60
|
+
/** Well-known Arbitrum token addresses */
|
|
61
|
+
export declare const ARBITRUM_TOKENS: {
|
|
62
|
+
USDC: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831";
|
|
63
|
+
WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
|
|
64
|
+
WNATIVE: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
|
|
65
|
+
};
|
|
66
|
+
/** Well-known Optimism token addresses */
|
|
67
|
+
export declare const OPTIMISM_TOKENS: {
|
|
68
|
+
USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85";
|
|
69
|
+
WETH: "0x4200000000000000000000000000000000000006";
|
|
70
|
+
OP: "0x4200000000000000000000000000000000000042";
|
|
71
|
+
WNATIVE: "0x4200000000000000000000000000000000000006";
|
|
72
|
+
};
|
|
73
|
+
/** Well-known Polygon token addresses */
|
|
74
|
+
export declare const POLYGON_TOKENS: {
|
|
75
|
+
USDC: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359";
|
|
76
|
+
WETH: "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
77
|
+
WMATIC: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";
|
|
78
|
+
WNATIVE: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270";
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Uniswap V3 router and quoter addresses.
|
|
82
|
+
*
|
|
83
|
+
* Base has a different router (SwapRouter02 deployed at a unique address due to BASE chain launch).
|
|
84
|
+
* Arbitrum, Optimism, and Polygon use the same universal SwapRouter02 address.
|
|
85
|
+
*
|
|
86
|
+
* Sources:
|
|
87
|
+
* - Base: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments
|
|
88
|
+
* - Arbitrum: https://docs.uniswap.org/contracts/v3/reference/deployments/arbitrum-deployments
|
|
89
|
+
* - Optimism: https://docs.uniswap.org/contracts/v3/reference/deployments/optimism-deployments
|
|
90
|
+
* - Polygon: https://docs.uniswap.org/contracts/v3/reference/deployments/polygon-deployments
|
|
91
|
+
*/
|
|
92
|
+
export declare const UNISWAP_V3_ADDRESSES: Record<SwapChain, {
|
|
93
|
+
ROUTER: Address;
|
|
94
|
+
QUOTER_V2: Address;
|
|
95
|
+
}>;
|
|
96
|
+
/** Protocol fee in bps — 0.875% */
|
|
97
|
+
export declare const PROTOCOL_FEE_BPS = 875;
|
|
98
|
+
/** Protocol fee collector address (all EVM chains) */
|
|
99
|
+
export declare const PROTOCOL_FEE_COLLECTOR: "0xff86829393C6C26A4EC122bE0Cc3E466Ef876AdD";
|
|
100
|
+
/** Default slippage in bps — 0.5% */
|
|
101
|
+
export declare const DEFAULT_SLIPPAGE_BPS = 50;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module tokens/decimals
|
|
3
|
+
* Token decimal normalization utilities for multi-token agent wallets.
|
|
4
|
+
*
|
|
5
|
+
* Handles safe conversion between human-readable amounts ("1.5") and raw
|
|
6
|
+
* on-chain bigint amounts (1500000n for USDC with 6 decimals). All arithmetic
|
|
7
|
+
* is done in integer domain to avoid floating point precision errors.
|
|
8
|
+
*/
|
|
9
|
+
import type { Address } from "viem";
|
|
10
|
+
/** Minimal token info required for formatting */
|
|
11
|
+
export interface TokenInfo {
|
|
12
|
+
symbol: string;
|
|
13
|
+
decimals: number;
|
|
14
|
+
address: Address;
|
|
15
|
+
name?: string;
|
|
16
|
+
chainId?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert a human-readable amount string to raw bigint (on-chain units).
|
|
20
|
+
*
|
|
21
|
+
* @param amount - Human-readable amount, e.g. "1.5" or "1000"
|
|
22
|
+
* @param decimals - Token decimal places (e.g. 6 for USDC, 18 for WETH)
|
|
23
|
+
* @returns Raw on-chain amount as bigint
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* toRaw("1.5", 6) // → 1500000n (1.5 USDC)
|
|
27
|
+
* toRaw("1.0", 18) // → 1000000000000000000n (1 WETH)
|
|
28
|
+
* toRaw("0.001", 8) // → 100000n (0.001 WBTC)
|
|
29
|
+
*/
|
|
30
|
+
export declare function toRaw(amount: string | bigint, decimals: number): bigint;
|
|
31
|
+
/**
|
|
32
|
+
* Convert a raw bigint on-chain amount to a human-readable string.
|
|
33
|
+
*
|
|
34
|
+
* @param amount - Raw on-chain amount
|
|
35
|
+
* @param decimals - Token decimal places
|
|
36
|
+
* @returns Human-readable string, trimmed trailing zeros
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* toHuman(1500000n, 6) // → "1.5"
|
|
40
|
+
* toHuman(1000000000000000000n, 18) // → "1.0"
|
|
41
|
+
* toHuman(0n, 6) // → "0.0"
|
|
42
|
+
*/
|
|
43
|
+
export declare function toHuman(amount: bigint, decimals: number): string;
|
|
44
|
+
/**
|
|
45
|
+
* Format a raw bigint amount with token symbol for display.
|
|
46
|
+
*
|
|
47
|
+
* @param amount - Raw on-chain amount
|
|
48
|
+
* @param token - Token info (symbol + decimals required)
|
|
49
|
+
* @param displayDecimals - Max decimal places to show (default: 4 for high-precision, 2 for stablecoins)
|
|
50
|
+
* @returns Formatted string e.g. "1.50 USDC" or "0.0023 WETH"
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* formatBalance(1500000n, { symbol: 'USDC', decimals: 6, address: '0x...' })
|
|
54
|
+
* // → "1.50 USDC"
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatBalance(amount: bigint, token: Pick<TokenInfo, "symbol" | "decimals">, displayDecimals?: number): string;
|
|
57
|
+
/**
|
|
58
|
+
* Parse amount that may be either a string (human-readable) or bigint (raw).
|
|
59
|
+
* Returns raw bigint. Used in transfer functions to accept flexible input.
|
|
60
|
+
*
|
|
61
|
+
* @param amount - Either a human-readable string "1.5" or a raw bigint
|
|
62
|
+
* @param decimals - Required only when amount is a string
|
|
63
|
+
*/
|
|
64
|
+
export declare function parseAmount(amount: string | bigint, decimals: number): bigint;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module tokens/registry
|
|
3
|
+
* TokenRegistry — multi-chain token address registry for AgentWallet v6.
|
|
4
|
+
*
|
|
5
|
+
* Ships pre-populated with top tokens for all 11 supported EVM chains.
|
|
6
|
+
* All addresses sourced from:
|
|
7
|
+
* - EVM: CoinGecko official token lists + chain explorers
|
|
8
|
+
* - USDC: https://developers.circle.com/stablecoins/usdc-contract-addresses
|
|
9
|
+
* - WBTC: https://wbtc.network/dashboard/order
|
|
10
|
+
* - WETH: official wrapped ETH contracts per chain
|
|
11
|
+
* - L2 native tokens: official L2 documentation
|
|
12
|
+
*
|
|
13
|
+
* Chain IDs follow the CHAIN_IDS map in src/types.ts.
|
|
14
|
+
*/
|
|
15
|
+
import type { Address } from "viem";
|
|
16
|
+
import type { TokenInfo } from "./decimals.js";
|
|
17
|
+
export type { TokenInfo };
|
|
18
|
+
/** Full token entry stored in the registry */
|
|
19
|
+
export interface TokenEntry extends TokenInfo {
|
|
20
|
+
chainId: number;
|
|
21
|
+
name: string;
|
|
22
|
+
isNative?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** Params for adding a custom token */
|
|
25
|
+
export interface AddTokenParams {
|
|
26
|
+
symbol: string;
|
|
27
|
+
address: Address;
|
|
28
|
+
decimals: number;
|
|
29
|
+
chainId: number;
|
|
30
|
+
name?: string;
|
|
31
|
+
isNative?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class TokenRegistry {
|
|
34
|
+
private readonly tokens;
|
|
35
|
+
constructor(initialTokens?: TokenEntry[]);
|
|
36
|
+
private _key;
|
|
37
|
+
private _store;
|
|
38
|
+
/**
|
|
39
|
+
* Add or overwrite a token in the registry.
|
|
40
|
+
*/
|
|
41
|
+
addToken(params: AddTokenParams): void;
|
|
42
|
+
/**
|
|
43
|
+
* Look up a token by symbol and chainId.
|
|
44
|
+
* Returns undefined if not found.
|
|
45
|
+
*/
|
|
46
|
+
getToken(symbol: string, chainId: number): TokenEntry | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* List all tokens registered for a given chainId.
|
|
49
|
+
*/
|
|
50
|
+
listTokens(chainId: number): TokenEntry[];
|
|
51
|
+
/**
|
|
52
|
+
* Find a token by its contract address on a given chain.
|
|
53
|
+
*/
|
|
54
|
+
getTokenByAddress(address: Address, chainId: number): TokenEntry | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Returns all registered tokens (all chains).
|
|
57
|
+
*/
|
|
58
|
+
getAllTokens(): TokenEntry[];
|
|
59
|
+
/**
|
|
60
|
+
* Returns number of registered tokens.
|
|
61
|
+
*/
|
|
62
|
+
size(): number;
|
|
63
|
+
}
|
|
64
|
+
/** Global registry with all supported chains pre-populated. */
|
|
65
|
+
export declare function getGlobalRegistry(): TokenRegistry;
|
|
66
|
+
/** Create a fresh registry pre-populated for a single chain.
|
|
67
|
+
* @internal — reserved for per-chain filtering API
|
|
68
|
+
*/
|
|
69
|
+
export declare function createChainRegistry(_chainId: number): TokenRegistry;
|
|
70
|
+
export declare const ETHEREUM_REGISTRY: TokenRegistry;
|
|
71
|
+
export declare const BASE_REGISTRY: TokenRegistry;
|
|
72
|
+
export declare const ARBITRUM_REGISTRY: TokenRegistry;
|
|
73
|
+
export declare const OPTIMISM_REGISTRY: TokenRegistry;
|
|
74
|
+
export declare const POLYGON_REGISTRY: TokenRegistry;
|
|
75
|
+
export declare const AVALANCHE_REGISTRY: TokenRegistry;
|
|
76
|
+
export declare const UNICHAIN_REGISTRY: TokenRegistry;
|
|
77
|
+
export declare const LINEA_REGISTRY: TokenRegistry;
|
|
78
|
+
export declare const SONIC_REGISTRY: TokenRegistry;
|
|
79
|
+
export declare const WORLDCHAIN_REGISTRY: TokenRegistry;
|
|
80
|
+
export declare const BASE_SEPOLIA_REGISTRY: TokenRegistry;
|
|
81
|
+
export declare function getNativeToken(chainId: number): TokenEntry | undefined;
|