@oracle-agent/oracle 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +115 -201
- package/README.md +82 -91
- package/SECURITY.md +37 -12
- package/SETUP.md +207 -272
- package/dist/action-receipts.mjs +1 -0
- package/dist/action-semantics.mjs +1 -0
- package/dist/address-book.mjs +2 -0
- package/dist/bin/desk-server.mjs +14 -0
- package/dist/bin/oracle-data-mcp.mjs +8 -0
- package/dist/bin/oracle-init.mjs +24 -0
- package/dist/bin/oracle-public-server.mjs +5 -0
- package/dist/bin/oracle-route.mjs +22 -0
- package/dist/bin/oracle-scan.mjs +18 -0
- package/dist/bin/oracle-upgrade.mjs +21 -0
- package/dist/bin/oracle.mjs +68 -0
- package/dist/chains.mjs +1 -0
- package/dist/cli/commands/auth.mjs +16 -0
- package/dist/cli/commands/bootstrap.mjs +18 -0
- package/dist/cli/commands/chain.mjs +21 -0
- package/dist/cli/commands/chat.mjs +35 -0
- package/dist/cli/commands/credential.mjs +1 -0
- package/dist/cli/commands/data-mcp.mjs +2 -0
- package/dist/cli/commands/data.mjs +12 -0
- package/dist/cli/commands/doctor.mjs +5 -0
- package/dist/cli/commands/gate.mjs +13 -0
- package/dist/cli/commands/help.mjs +1 -0
- package/dist/cli/commands/init.mjs +3 -0
- package/dist/cli/commands/mcp.mjs +33 -0
- package/dist/cli/commands/model.mjs +44 -0
- package/dist/cli/commands/prepare.mjs +2 -0
- package/dist/cli/commands/public.mjs +3 -0
- package/dist/cli/commands/route.mjs +2 -0
- package/dist/cli/commands/runner.mjs +1 -0
- package/dist/cli/commands/scan.mjs +2 -0
- package/dist/cli/commands/setup.mjs +34 -0
- package/dist/cli/commands/sign.mjs +4 -0
- package/dist/cli/commands/signer.mjs +1 -0
- package/dist/cli/commands/upgrade.mjs +2 -0
- package/dist/cli/commands/vault.mjs +1 -0
- package/dist/cli/commands/version.mjs +2 -0
- package/dist/data/desk-data.mjs +12 -0
- package/dist/index.mjs +17 -0
- package/dist/nft-gas-war-guard.mjs +1 -0
- package/dist/onboarding/harness-configs.mjs +4 -0
- package/dist/portfolio-risk.mjs +1 -0
- package/dist/prepare-envelope.mjs +1 -0
- package/dist/public-control/policy-schema.mjs +1 -0
- package/dist/router/index.mjs +2 -0
- package/dist/scanner/index.mjs +4 -0
- package/dist/signals/index.mjs +1 -0
- package/dist/watch-preferences.mjs +1 -0
- package/package.json +27 -65
- package/public/oracle-splash/assets/cli-chain-hyperliquid.jpg +0 -0
- package/public/oracle-splash/brand/aave.webp +0 -0
- package/public/oracle-splash/brand/aavev2.webp +0 -0
- package/public/oracle-splash/brand/aborean.webp +0 -0
- package/public/oracle-splash/brand/across.webp +0 -0
- package/public/oracle-splash/brand/aerodrome.webp +0 -0
- package/public/oracle-splash/brand/afi.webp +0 -0
- package/public/oracle-splash/brand/arcus.webp +0 -0
- package/public/oracle-splash/brand/aster.webp +0 -0
- package/public/oracle-splash/brand/avant.webp +0 -0
- package/public/oracle-splash/brand/balancer.webp +0 -0
- package/public/oracle-splash/brand/beefy.webp +0 -0
- package/public/oracle-splash/brand/benqi.webp +0 -0
- package/public/oracle-splash/brand/bestinslot.ico +0 -0
- package/public/oracle-splash/brand/bitfi.webp +0 -0
- package/public/oracle-splash/brand/bonkswap.webp +0 -0
- package/public/oracle-splash/brand/bouncebit.webp +0 -0
- package/public/oracle-splash/brand/camelot.webp +0 -0
- package/public/oracle-splash/brand/compound.webp +0 -0
- package/public/oracle-splash/brand/concrete.webp +0 -0
- package/public/oracle-splash/brand/cow.webp +0 -0
- package/public/oracle-splash/brand/curve.webp +0 -0
- package/public/oracle-splash/brand/derive.webp +0 -0
- package/public/oracle-splash/brand/dolomite.webp +0 -0
- package/public/oracle-splash/brand/eigenlayer.webp +0 -0
- package/public/oracle-splash/brand/ekubo.webp +0 -0
- package/public/oracle-splash/brand/ethena.webp +0 -0
- package/public/oracle-splash/brand/etherfi.webp +0 -0
- package/public/oracle-splash/brand/etherfiborrow.webp +0 -0
- package/public/oracle-splash/brand/felix.webp +0 -0
- package/public/oracle-splash/brand/fluid.webp +0 -0
- package/public/oracle-splash/brand/fluxbeam.webp +0 -0
- package/public/oracle-splash/brand/folks.webp +0 -0
- package/public/oracle-splash/brand/fortyacres.webp +0 -0
- package/public/oracle-splash/brand/gainsnetwork.webp +0 -0
- package/public/oracle-splash/brand/gassss.webp +0 -0
- package/public/oracle-splash/brand/gmx.webp +0 -0
- package/public/oracle-splash/brand/harmonix.webp +0 -0
- package/public/oracle-splash/brand/hlorderbook.webp +0 -0
- package/public/oracle-splash/brand/hlp.webp +0 -0
- package/public/oracle-splash/brand/hop.webp +0 -0
- package/public/oracle-splash/brand/hyperbeat.webp +0 -0
- package/public/oracle-splash/brand/hyperlend.webp +0 -0
- package/public/oracle-splash/brand/hyperliquid.webp +0 -0
- package/public/oracle-splash/brand/hyperliquidhpl.webp +0 -0
- package/public/oracle-splash/brand/hyperliquidspot.webp +0 -0
- package/public/oracle-splash/brand/hyperswap.webp +0 -0
- package/public/oracle-splash/brand/hypha.webp +0 -0
- package/public/oracle-splash/brand/joedex.webp +0 -0
- package/public/oracle-splash/brand/jupiter.webp +0 -0
- package/public/oracle-splash/brand/kelp.webp +0 -0
- package/public/oracle-splash/brand/kinetiq.webp +0 -0
- package/public/oracle-splash/brand/kmhype.webp +0 -0
- package/public/oracle-splash/brand/kona.webp +0 -0
- package/public/oracle-splash/brand/konalend.webp +0 -0
- package/public/oracle-splash/brand/lfj.webp +0 -0
- package/public/oracle-splash/brand/lido.webp +0 -0
- package/public/oracle-splash/brand/lifi.webp +0 -0
- package/public/oracle-splash/brand/lighter.webp +0 -0
- package/public/oracle-splash/brand/lista.webp +0 -0
- package/public/oracle-splash/brand/loopedhype.webp +0 -0
- package/public/oracle-splash/brand/lorenzo.webp +0 -0
- package/public/oracle-splash/brand/magic-eden.webp +0 -0
- package/public/oracle-splash/brand/magiceden.webp +0 -0
- package/public/oracle-splash/brand/mempool.png +0 -0
- package/public/oracle-splash/brand/meteora.webp +0 -0
- package/public/oracle-splash/brand/morpho.webp +0 -0
- package/public/oracle-splash/brand/myriad.webp +0 -0
- package/public/oracle-splash/brand/noxa.webp +0 -0
- package/public/oracle-splash/brand/odos.webp +0 -0
- package/public/oracle-splash/brand/oneinch.webp +0 -0
- package/public/oracle-splash/brand/openbook.webp +0 -0
- package/public/oracle-splash/brand/opensea.webp +0 -0
- package/public/oracle-splash/brand/orca.webp +0 -0
- package/public/oracle-splash/brand/ordinals.png +0 -0
- package/public/oracle-splash/brand/ostium.webp +0 -0
- package/public/oracle-splash/brand/pancakeswap.webp +0 -0
- package/public/oracle-splash/brand/pendle.webp +0 -0
- package/public/oracle-splash/brand/perena.webp +0 -0
- package/public/oracle-splash/brand/pharaoh.webp +0 -0
- package/public/oracle-splash/brand/phoenix.webp +0 -0
- package/public/oracle-splash/brand/polymarket.webp +0 -0
- package/public/oracle-splash/brand/polynomial.webp +0 -0
- package/public/oracle-splash/brand/projectx.webp +0 -0
- package/public/oracle-splash/brand/pumpfun.webp +0 -0
- package/public/oracle-splash/brand/quickswap.webp +0 -0
- package/public/oracle-splash/brand/rain.webp +0 -0
- package/public/oracle-splash/brand/raydium.webp +0 -0
- package/public/oracle-splash/brand/relay.webp +0 -0
- package/public/oracle-splash/brand/rocketpool.webp +0 -0
- package/public/oracle-splash/brand/saber.webp +0 -0
- package/public/oracle-splash/brand/sakuraswap.webp +0 -0
- package/public/oracle-splash/brand/sanctum.webp +0 -0
- package/public/oracle-splash/brand/satflow.png +0 -0
- package/public/oracle-splash/brand/sierra.webp +0 -0
- package/public/oracle-splash/brand/sky.webp +0 -0
- package/public/oracle-splash/brand/solv.webp +0 -0
- package/public/oracle-splash/brand/spark.webp +0 -0
- package/public/oracle-splash/brand/sparksavings.webp +0 -0
- package/public/oracle-splash/brand/sphere.webp +0 -0
- package/public/oracle-splash/brand/ssv.webp +0 -0
- package/public/oracle-splash/brand/stabble.webp +0 -0
- package/public/oracle-splash/brand/stableswap.webp +0 -0
- package/public/oracle-splash/brand/stakewise.webp +0 -0
- package/public/oracle-splash/brand/stargate.webp +0 -0
- package/public/oracle-splash/brand/sthype.webp +0 -0
- package/public/oracle-splash/brand/sushiswap.webp +0 -0
- package/public/oracle-splash/brand/unisat.png +0 -0
- package/public/oracle-splash/brand/uniswap.webp +0 -0
- package/public/oracle-splash/brand/uniswapv2.webp +0 -0
- package/public/oracle-splash/brand/uniswapv4.webp +0 -0
- package/public/oracle-splash/brand/unit.webp +0 -0
- package/public/oracle-splash/brand/velodrome.webp +0 -0
- package/public/oracle-splash/brand/velora.webp +0 -0
- package/public/oracle-splash/brand/venus.webp +0 -0
- package/public/oracle-splash/brand/wbeth.webp +0 -0
- package/public/oracle-splash/brand/xsy.webp +0 -0
- package/public/oracle-splash/brand/yieldyak.webp +0 -0
- package/public/oracle-splash/brand/zerobase.webp +0 -0
- package/public/oracle-splash/brand/zerox.webp +0 -0
- package/public/oracle-splash/index.html +246 -169
- package/CONTRIBUTING.md +0 -98
- package/bin/desk-server.mjs +0 -440
- package/bin/oracle-data-mcp.mjs +0 -1010
- package/bin/oracle-init.mjs +0 -496
- package/bin/oracle-public-server.mjs +0 -36
- package/bin/oracle-route.mjs +0 -254
- package/bin/oracle-scan.mjs +0 -192
- package/bin/oracle-upgrade.mjs +0 -42
- package/bin/oracle.mjs +0 -33
- package/docs/adding-a-chain.md +0 -229
- package/docs/architecture.md +0 -136
- package/docs/cli.md +0 -47
- package/docs/connectors.md +0 -13
- package/docs/oracle-pack-standard.md +0 -29
- package/docs/profiles.md +0 -154
- package/examples/add-a-chain.mjs +0 -65
- package/examples/oracle-pack-template.mjs +0 -38
- package/examples/research-a-token.mjs +0 -70
- package/plugins/oracle-owner-gate/__init__.py +0 -227
- package/plugins/oracle-owner-gate/plugin.yaml +0 -9
- package/profiles/_template/SOUL.md +0 -54
- package/profiles/_template/profile.json +0 -22
- package/profiles/bitcoin-agent/SOUL.md +0 -31
- package/profiles/bitcoin-agent/profile.json +0 -32
- package/profiles/hyperliquid-agent/SOUL.md +0 -34
- package/profiles/hyperliquid-agent/profile.json +0 -37
- package/profiles/oracle/SOUL.md +0 -107
- package/profiles/oracle/profile.json +0 -39
- package/profiles/polymarket-agent/SOUL.md +0 -35
- package/profiles/polymarket-agent/profile.json +0 -34
- package/profiles/profile.schema.json +0 -90
- package/profiles/protocol-builder/SOUL.md +0 -57
- package/profiles/protocol-builder/profile.json +0 -39
- package/profiles/robinhood-agent/SOUL.md +0 -53
- package/profiles/robinhood-agent/profile.json +0 -40
- package/profiles/solana-agent/SOUL.md +0 -37
- package/profiles/solana-agent/profile.json +0 -37
- package/profiles/stable-agent/SOUL.md +0 -43
- package/profiles/stable-agent/profile.json +0 -37
- package/protocols/templates/safe-erc20/SECURITY.md +0 -16
- package/protocols/templates/safe-erc20/foundry.toml +0 -12
- package/protocols/templates/safe-erc20/remappings.txt +0 -2
- package/protocols/templates/safe-erc20/src/SafeERC20.sol +0 -53
- package/protocols/templates/safe-erc20/test/SafeERC20.t.sol +0 -72
- package/scripts/adversarial-bench.mjs +0 -114
- package/scripts/build-inscription.py +0 -230
- package/scripts/check-doc-drift.mjs +0 -112
- package/scripts/check-test-count.mjs +0 -105
- package/scripts/e2e-hl-markets.mjs +0 -21
- package/scripts/e2e-hl-perps.mjs +0 -48
- package/scripts/e2e-hypercore-staking.mjs +0 -128
- package/scripts/e2e-solana-bitcoin.mjs +0 -183
- package/scripts/protocol-template-gate.mjs +0 -15
- package/scripts/public-api-scan.mjs +0 -23
- package/scripts/secret-scan.mjs +0 -181
- package/scripts/verify-v3-venues.mjs +0 -192
- package/skills/balance/SKILL.md +0 -176
- package/skills/oracle-action-semantics/SKILL.md +0 -40
- package/skills/oracle-best-execution/SKILL.md +0 -127
- package/skills/oracle-bitcoin/SKILL.md +0 -53
- package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +0 -59
- package/skills/oracle-chat/SKILL.md +0 -61
- package/skills/oracle-chat/chain.SKILL.md +0 -31
- package/skills/oracle-chat/setup.SKILL.md +0 -37
- package/skills/oracle-circuit-breaker/SKILL.md +0 -51
- package/skills/oracle-contract-research/SKILL.md +0 -55
- package/skills/oracle-desk/SKILL.md +0 -58
- package/skills/oracle-dex-launch/SKILL.md +0 -38
- package/skills/oracle-grants/SKILL.md +0 -69
- package/skills/oracle-hypercore-staking/SKILL.md +0 -57
- package/skills/oracle-hyperliquid/SKILL.md +0 -56
- package/skills/oracle-meme-token-sniper/SKILL.md +0 -73
- package/skills/oracle-multichain-nft-launch/SKILL.md +0 -338
- package/skills/oracle-multichain-token-launch/SKILL.md +0 -300
- package/skills/oracle-nft-gacha-launch/SKILL.md +0 -48
- package/skills/oracle-nft-mint-gas-war/SKILL.md +0 -63
- package/skills/oracle-polymarket/SKILL.md +0 -60
- package/skills/oracle-protocol-builder/SKILL.md +0 -59
- package/skills/oracle-protocol-security/SKILL.md +0 -60
- package/skills/oracle-public-product/SKILL.md +0 -44
- package/skills/oracle-receipts/SKILL.md +0 -52
- package/skills/oracle-rfq-tokenized-assets/SKILL.md +0 -69
- package/skills/oracle-smart-wallet-scanner/SKILL.md +0 -49
- package/skills/oracle-solana/SKILL.md +0 -65
- package/skills/oracle-solana-nft/SKILL.md +0 -54
- package/skills/oracle-token-research/SKILL.md +0 -67
- package/skins/oracle.yaml +0 -56
- package/src/action-receipts.mjs +0 -168
- package/src/action-semantics.mjs +0 -62
- package/src/address-book.mjs +0 -208
- package/src/agent-auth.mjs +0 -206
- package/src/approval-guard.mjs +0 -282
- package/src/attestation-secret.mjs +0 -88
- package/src/audit-log.mjs +0 -196
- package/src/auth/oauth.mjs +0 -672
- package/src/auto-slippage.mjs +0 -378
- package/src/capability-posture.mjs +0 -125
- package/src/chains.mjs +0 -62
- package/src/cli/chain-catalog.mjs +0 -215
- package/src/cli/chain-state.mjs +0 -74
- package/src/cli/commands/auth.mjs +0 -193
- package/src/cli/commands/bootstrap.mjs +0 -87
- package/src/cli/commands/chain.mjs +0 -143
- package/src/cli/commands/chat.mjs +0 -434
- package/src/cli/commands/credential.mjs +0 -9
- package/src/cli/commands/data-mcp.mjs +0 -18
- package/src/cli/commands/data.mjs +0 -73
- package/src/cli/commands/doctor.mjs +0 -126
- package/src/cli/commands/help.mjs +0 -7
- package/src/cli/commands/init.mjs +0 -27
- package/src/cli/commands/mcp.mjs +0 -142
- package/src/cli/commands/model.mjs +0 -99
- package/src/cli/commands/prepare.mjs +0 -12
- package/src/cli/commands/public.mjs +0 -20
- package/src/cli/commands/route.mjs +0 -12
- package/src/cli/commands/runner.mjs +0 -9
- package/src/cli/commands/scan.mjs +0 -12
- package/src/cli/commands/setup.mjs +0 -275
- package/src/cli/commands/sign.mjs +0 -21
- package/src/cli/commands/signer.mjs +0 -9
- package/src/cli/commands/upgrade.mjs +0 -12
- package/src/cli/commands/vault.mjs +0 -9
- package/src/cli/commands/version.mjs +0 -22
- package/src/cli/first-run.mjs +0 -23
- package/src/cli/kernel.mjs +0 -239
- package/src/cli/mcp-targets/chatgpt.mjs +0 -51
- package/src/cli/mcp-targets/claude-code.mjs +0 -39
- package/src/cli/mcp-targets/claude-desktop.mjs +0 -24
- package/src/cli/mcp-targets/codex.mjs +0 -41
- package/src/cli/mcp-targets/shared.mjs +0 -61
- package/src/cli/messaging-platforms.mjs +0 -209
- package/src/cli/model-config.mjs +0 -70
- package/src/cli/operator-dispatch.mjs +0 -258
- package/src/cli/oracle-harness.py +0 -415
- package/src/cli/paths.mjs +0 -83
- package/src/cli/runtime.mjs +0 -351
- package/src/cli/setup-state.mjs +0 -168
- package/src/cli/spawn-child.mjs +0 -43
- package/src/data/catalog.mjs +0 -554
- package/src/data/desk-data.mjs +0 -683
- package/src/data/http.mjs +0 -253
- package/src/data/provider-endpoint.mjs +0 -94
- package/src/data/providers/aerodrome.mjs +0 -245
- package/src/data/providers/balancer.mjs +0 -209
- package/src/data/providers/bitcoin-esplora.mjs +0 -216
- package/src/data/providers/bitcoin-meta.mjs +0 -378
- package/src/data/providers/blockscout.mjs +0 -14
- package/src/data/providers/bridges.mjs +0 -242
- package/src/data/providers/cowswap.mjs +0 -415
- package/src/data/providers/curve.mjs +0 -201
- package/src/data/providers/defillama.mjs +0 -88
- package/src/data/providers/dexscreener.mjs +0 -43
- package/src/data/providers/evm-rpc.mjs +0 -222
- package/src/data/providers/geckoterminal.mjs +0 -34
- package/src/data/providers/gmx.mjs +0 -496
- package/src/data/providers/hl-assets.mjs +0 -165
- package/src/data/providers/hl-info.mjs +0 -108
- package/src/data/providers/hl-markets.mjs +0 -210
- package/src/data/providers/hl-outcome.mjs +0 -61
- package/src/data/providers/hl-perps.mjs +0 -387
- package/src/data/providers/hl-staking.mjs +0 -353
- package/src/data/providers/hl-ws.mjs +0 -119
- package/src/data/providers/hyperevm-dex.mjs +0 -49
- package/src/data/providers/jupiter.mjs +0 -183
- package/src/data/providers/lifi.mjs +0 -151
- package/src/data/providers/magiceden-sol.mjs +0 -393
- package/src/data/providers/morpho.mjs +0 -173
- package/src/data/providers/nft-gallery.mjs +0 -163
- package/src/data/providers/nft-portfolio.mjs +0 -494
- package/src/data/providers/odos.mjs +0 -156
- package/src/data/providers/oneinch.mjs +0 -174
- package/src/data/providers/opensea-multichain.mjs +0 -136
- package/src/data/providers/opensea-nft.mjs +0 -371
- package/src/data/providers/paraswap.mjs +0 -118
- package/src/data/providers/pendle.mjs +0 -187
- package/src/data/providers/poly-clob.mjs +0 -283
- package/src/data/providers/poly-public.mjs +0 -96
- package/src/data/providers/poly-ws.mjs +0 -103
- package/src/data/providers/portfolio-history.mjs +0 -394
- package/src/data/providers/portfolio.mjs +0 -594
- package/src/data/providers/rfq.mjs +0 -15
- package/src/data/providers/rh-agent.mjs +0 -59
- package/src/data/providers/satflow.mjs +0 -338
- package/src/data/providers/solana-rpc.mjs +0 -197
- package/src/data/providers/uniswap-v3.mjs +0 -320
- package/src/data/providers/zerox.mjs +0 -167
- package/src/data/public-api-scan.mjs +0 -61
- package/src/data/quote-placeholder.mjs +0 -31
- package/src/exact-integer.mjs +0 -72
- package/src/exec-policy.mjs +0 -455
- package/src/flags.mjs +0 -15
- package/src/fresh-window.mjs +0 -76
- package/src/gmx-attestation.mjs +0 -176
- package/src/index.mjs +0 -100
- package/src/nft-gas-war-guard.mjs +0 -139
- package/src/onboarding/agent-keys.mjs +0 -161
- package/src/onboarding/harness-configs.mjs +0 -102
- package/src/onboarding/index.mjs +0 -18
- package/src/onboarding/tiers.mjs +0 -139
- package/src/oracle-env.mjs +0 -47
- package/src/portfolio-risk.mjs +0 -170
- package/src/prepare-envelope.mjs +0 -186
- package/src/profile-upgrade.mjs +0 -277
- package/src/protocol-execution.mjs +0 -84
- package/src/protocol-templates/gate.mjs +0 -179
- package/src/protocol-templates/prepare-deploy.mjs +0 -81
- package/src/public-api/buzz-integration.mjs +0 -256
- package/src/public-api/connect-agent.mjs +0 -416
- package/src/public-api/grants.mjs +0 -142
- package/src/public-api/http.mjs +0 -389
- package/src/public-control/aa-adapter.mjs +0 -402
- package/src/public-control/build-registry.mjs +0 -227
- package/src/public-control/bundler-client.mjs +0 -357
- package/src/public-control/grant-indexer.mjs +0 -296
- package/src/public-control/policy-render.mjs +0 -69
- package/src/public-control/policy-schema.mjs +0 -318
- package/src/public-control/runtime-config.mjs +0 -275
- package/src/public-control/session-key-model.mjs +0 -374
- package/src/public-control/session-orchestrator.mjs +0 -412
- package/src/rfq/intent.mjs +0 -180
- package/src/rfq/sources.mjs +0 -181
- package/src/route-attestation.mjs +0 -132
- package/src/router/best-execution.mjs +0 -326
- package/src/router/index.mjs +0 -226
- package/src/router/prepare-bridge.mjs +0 -289
- package/src/router/prepare-route.mjs +0 -381
- package/src/router/proposal.mjs +0 -311
- package/src/router/risk-classifier.mjs +0 -119
- package/src/router/route-sources.mjs +0 -329
- package/src/scanner/chains.config.mjs +0 -430
- package/src/scanner/contract.mjs +0 -270
- package/src/scanner/evm-scanner.mjs +0 -394
- package/src/scanner/index.mjs +0 -9
- package/src/scanner/v2-venue.mjs +0 -335
- package/src/scanner/v3-venue.mjs +0 -290
- package/src/scopes.mjs +0 -44
- package/src/sell-simulation.mjs +0 -167
- package/src/signals/engine.mjs +0 -146
- package/src/signals/index.mjs +0 -1
- package/src/token-transfer-guard.mjs +0 -188
- package/src/tui/app.mjs +0 -438
- package/src/tui/backend.mjs +0 -145
- package/src/tui/format.mjs +0 -272
- package/src/tui/gateway-client.mjs +0 -177
- package/src/tui/input.mjs +0 -501
- package/src/tui/renderer.mjs +0 -443
- package/src/tui/standalone-client.mjs +0 -666
- package/src/tui/theme.mjs +0 -81
- package/src/vault-attestation.mjs +0 -146
- package/src/venues.mjs +0 -206
- package/src/watch-preferences.mjs +0 -85
package/src/onboarding/tiers.mjs
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// Product onboarding tiers — multi-user, non-custodial.
|
|
2
|
-
// Tier chooses default scopes. Higher tiers never put user private keys on our box.
|
|
3
|
-
|
|
4
|
-
import { DEFAULT_SCOPES, EXECUTE_SCOPE } from "../scopes.mjs";
|
|
5
|
-
import { createAgentKey, listAgentKeys, revokeAgentKey, authenticateAgentKey } from "./agent-keys.mjs";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Tier catalog (product story):
|
|
9
|
-
* - observer: read-only market/position data
|
|
10
|
-
* - preparer: can prepare trades/mints (unsigned / advisory)
|
|
11
|
-
* - shadow: paper/shadow agent loops
|
|
12
|
-
* - executor: live agent:execute — ONLY if owner is on controller allowlist
|
|
13
|
-
* - local_signer: no API key needed for signing; user signs off-infra (docs only)
|
|
14
|
-
*/
|
|
15
|
-
export const TIERS = {
|
|
16
|
-
observer: {
|
|
17
|
-
id: "observer",
|
|
18
|
-
label: "Observer",
|
|
19
|
-
description: "Read markets, NFTs, positions. No prepare/execute.",
|
|
20
|
-
scopes: ["read:markets", "read:nfts", "read:positions"],
|
|
21
|
-
custody: "none",
|
|
22
|
-
canExecute: false,
|
|
23
|
-
},
|
|
24
|
-
preparer: {
|
|
25
|
-
id: "preparer",
|
|
26
|
-
label: "Preparer",
|
|
27
|
-
description: "Prepare trades/mints; user or operator co-signs. No live execute scope.",
|
|
28
|
-
scopes: [...DEFAULT_SCOPES].filter((s) => s !== "agent:shadow"),
|
|
29
|
-
custody: "none",
|
|
30
|
-
canExecute: false,
|
|
31
|
-
},
|
|
32
|
-
shadow: {
|
|
33
|
-
id: "shadow",
|
|
34
|
-
label: "Shadow agent",
|
|
35
|
-
description: "Full prepare + agent:shadow paper loops. Still no live execute.",
|
|
36
|
-
scopes: [...DEFAULT_SCOPES],
|
|
37
|
-
custody: "none",
|
|
38
|
-
canExecute: false,
|
|
39
|
-
},
|
|
40
|
-
executor: {
|
|
41
|
-
id: "executor",
|
|
42
|
-
label: "Executor (controller)",
|
|
43
|
-
description:
|
|
44
|
-
"Live agent:execute on the owner's own wallet only. Owner must be an executor controller. Key is NOT a wallet key.",
|
|
45
|
-
scopes: [...DEFAULT_SCOPES, EXECUTE_SCOPE],
|
|
46
|
-
custody: "none — scoped API key only; user wallet key never stored",
|
|
47
|
-
canExecute: true,
|
|
48
|
-
},
|
|
49
|
-
local_signer: {
|
|
50
|
-
id: "local_signer",
|
|
51
|
-
label: "Local signer",
|
|
52
|
-
description:
|
|
53
|
-
"User keeps keys on their device. Desk issues prepare-only key; signing happens off our infra.",
|
|
54
|
-
scopes: ["read:markets", "read:positions", "prepare:trade", "prepare:mint"],
|
|
55
|
-
custody: "none — signing off-box",
|
|
56
|
-
canExecute: false,
|
|
57
|
-
mintKey: true,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export function listTiers() {
|
|
62
|
-
return Object.values(TIERS).map((t) => ({
|
|
63
|
-
id: t.id,
|
|
64
|
-
label: t.label,
|
|
65
|
-
description: t.description,
|
|
66
|
-
scopes: t.scopes,
|
|
67
|
-
custody: t.custody,
|
|
68
|
-
canExecute: t.canExecute,
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function getTier(id) {
|
|
73
|
-
const t = TIERS[id];
|
|
74
|
-
if (!t) throw new Error(`Unknown tier: ${id}`);
|
|
75
|
-
return t;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Onboard a user wallet onto a tier. Returns one-time raw API key (except pure docs).
|
|
80
|
-
* NEVER accepts or stores a private key.
|
|
81
|
-
*/
|
|
82
|
-
export function onboardUser({
|
|
83
|
-
owner,
|
|
84
|
-
tier = "observer",
|
|
85
|
-
name,
|
|
86
|
-
controllerAllowlist = [],
|
|
87
|
-
storePath,
|
|
88
|
-
scopes, // optional override
|
|
89
|
-
} = {}) {
|
|
90
|
-
if (owner && typeof owner === "object" && owner.privateKey) {
|
|
91
|
-
throw new Error("Refusing privateKey — non-custodial onboarding accepts owner address only");
|
|
92
|
-
}
|
|
93
|
-
const t = getTier(tier);
|
|
94
|
-
const finalScopes = scopes || t.scopes;
|
|
95
|
-
const result = createAgentKey({
|
|
96
|
-
owner,
|
|
97
|
-
name: name || `${t.label} key`,
|
|
98
|
-
scopes: finalScopes,
|
|
99
|
-
tier: t.id,
|
|
100
|
-
controllerAllowlist,
|
|
101
|
-
storePath,
|
|
102
|
-
});
|
|
103
|
-
return {
|
|
104
|
-
tier: t.id,
|
|
105
|
-
custody: t.custody,
|
|
106
|
-
canExecute: t.canExecute && finalScopes.includes(EXECUTE_SCOPE),
|
|
107
|
-
key: result.key, // show once
|
|
108
|
-
record: result.record,
|
|
109
|
-
nextSteps:
|
|
110
|
-
t.id === "local_signer"
|
|
111
|
-
? [
|
|
112
|
-
"Store the API key for prepare/read calls only",
|
|
113
|
-
"Keep your wallet key on your device / hardware signer",
|
|
114
|
-
"Submit prepared payloads to your local signer — never upload the key here",
|
|
115
|
-
]
|
|
116
|
-
: t.canExecute
|
|
117
|
-
? [
|
|
118
|
-
"Store the API key securely",
|
|
119
|
-
"Live execute still requires MAD_EXECUTE_ENABLED=1 on the operator side",
|
|
120
|
-
"This key can only act on YOUR owner wallet (custody firewall)",
|
|
121
|
-
]
|
|
122
|
-
: [
|
|
123
|
-
"Store the API key securely",
|
|
124
|
-
"Use with getSigner({ identity: auth.identity, venue }) after authenticateAgentKey",
|
|
125
|
-
],
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function onboardAuthenticate(rawKey, opts) {
|
|
130
|
-
return authenticateAgentKey(rawKey, opts);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export function onboardListKeys(owner, opts) {
|
|
134
|
-
return listAgentKeys(owner, opts);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function onboardRevoke(opts) {
|
|
138
|
-
return revokeAgentKey(opts);
|
|
139
|
-
}
|
package/src/oracle-env.mjs
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
export const ORACLE_CONFIG_DIR = join(homedir(), ".config", "oracle");
|
|
6
|
-
// Legacy config dir from before the rename. Kept so existing installs keep
|
|
7
|
-
// working; new installs only ever see ~/.config/oracle.
|
|
8
|
-
export const LEGACY_CONFIG_DIR = join(homedir(), ".config", "mad-desk");
|
|
9
|
-
|
|
10
|
-
export function env(primary, legacy, fallback = "") {
|
|
11
|
-
const pv = process.env[primary];
|
|
12
|
-
if (pv != null && String(pv).trim() !== "") return pv;
|
|
13
|
-
const lv = legacy ? process.env[legacy] : undefined;
|
|
14
|
-
if (lv != null && String(lv).trim() !== "") return lv;
|
|
15
|
-
return fallback;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function envFlag(primary, legacy, defaultValue = false) {
|
|
19
|
-
const fallback = defaultValue ? "1" : "";
|
|
20
|
-
return String(env(primary, legacy, fallback)).trim() === "1";
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const DISABLE_WORDS = ["0", "false", "off", "no"];
|
|
24
|
-
|
|
25
|
-
// Reading a flag that may default ON. Only an explicit disable word turns it
|
|
26
|
-
// off, and an unset value keeps `defaultValue`.
|
|
27
|
-
//
|
|
28
|
-
// The old shape (`!== "0"`) inverted with a false default: ORACLE_ONBOARD_HTTP
|
|
29
|
-
// defaults off, so a user writing `false` to keep it off actually ENABLED it,
|
|
30
|
-
// because "false" is not "0". A disable word must never enable a surface.
|
|
31
|
-
export function envEnabled(primary, legacy, defaultValue = true) {
|
|
32
|
-
const raw = String(env(primary, legacy, "")).trim().toLowerCase();
|
|
33
|
-
if (raw === "") return defaultValue;
|
|
34
|
-
return !DISABLE_WORDS.includes(raw);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function csvEnv(primary, legacy) {
|
|
38
|
-
return String(env(primary, legacy, ""));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function configPath(file, primary, legacy) {
|
|
42
|
-
const explicit = env(primary, legacy, "");
|
|
43
|
-
if (explicit) return explicit;
|
|
44
|
-
const oraclePath = join(ORACLE_CONFIG_DIR, file);
|
|
45
|
-
if (existsSync(oraclePath)) return oraclePath;
|
|
46
|
-
return join(LEGACY_CONFIG_DIR, file);
|
|
47
|
-
}
|
package/src/portfolio-risk.mjs
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// Pure portfolio exposure and coverage summary. This module performs no I/O.
|
|
2
|
-
|
|
3
|
-
export const DEFAULT_RISK_THRESHOLDS = Object.freeze({
|
|
4
|
-
assetHighPct: 50,
|
|
5
|
-
assetMediumPct: 25,
|
|
6
|
-
chainHighPct: 75,
|
|
7
|
-
venueHighPct: 60,
|
|
8
|
-
stablecoinHighPct: 70,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const STABLECOINS = new Set(["USDC", "USDT", "USDT0", "DAI", "FRAX", "LUSD", "TUSD", "USDP", "GUSD", "PYUSD", "USDE"]);
|
|
12
|
-
|
|
13
|
-
function finite(value) {
|
|
14
|
-
if (value === null || value === "" || value === undefined) return null;
|
|
15
|
-
const number = Number(value);
|
|
16
|
-
return Number.isFinite(number) && number >= 0 ? number : null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function rounded(value) {
|
|
20
|
-
return Math.round((value + Number.EPSILON) * 1e8) / 1e8;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function pct(value, total) {
|
|
24
|
-
return total > 0 ? rounded((value / total) * 100) : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function addressOf(snapshot) {
|
|
28
|
-
return snapshot.address || snapshot.owner || snapshot.walletAddress || snapshot.wallet?.address || null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function labelIndex(labels) {
|
|
32
|
-
const entries = Array.isArray(labels) ? labels : Array.isArray(labels?.entries) ? labels.entries : [];
|
|
33
|
-
const index = new Map();
|
|
34
|
-
for (const entry of entries) {
|
|
35
|
-
if (!entry?.address) continue;
|
|
36
|
-
const key = String(entry.address).toLowerCase();
|
|
37
|
-
if (!index.has(key)) index.set(key, entry);
|
|
38
|
-
}
|
|
39
|
-
return index;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function addAsset(output, raw, context = {}) {
|
|
43
|
-
if (!raw || typeof raw !== "object") return;
|
|
44
|
-
const symbol = String(raw.symbol ?? raw.coin ?? raw.name ?? raw.collection ?? raw.tokenId ?? "unknown");
|
|
45
|
-
const value = finite(raw.usdValue ?? raw.valueUsd ?? raw.knownUsd ?? raw.estimatedValueUsd ?? raw.floorValueUsd);
|
|
46
|
-
const kind = raw.kind === "nft" || raw.type === "nft" || raw.collection || raw.tokenId != null ? "nft" : "fungible";
|
|
47
|
-
output.push({
|
|
48
|
-
symbol,
|
|
49
|
-
usdValue: value,
|
|
50
|
-
chain: String(raw.chain ?? raw.chainName ?? context.chain ?? "unknown"),
|
|
51
|
-
venue: String(raw.venue ?? raw.protocol ?? raw.platform ?? context.venue ?? "wallet"),
|
|
52
|
-
address: raw.address ?? context.address ?? null,
|
|
53
|
-
kind,
|
|
54
|
-
stablecoin: raw.stablecoin === true || STABLECOINS.has(symbol.toUpperCase()),
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function assetsFromSnapshot(snapshot) {
|
|
59
|
-
const output = [];
|
|
60
|
-
const rootAddress = addressOf(snapshot);
|
|
61
|
-
for (const asset of snapshot.assets || snapshot.holdings || []) addAsset(output, asset, { address: rootAddress, chain: snapshot.chain, venue: snapshot.venue });
|
|
62
|
-
for (const chain of snapshot.chains || []) {
|
|
63
|
-
const chainName = chain.chain ?? chain.name ?? chain.slug ?? (chain.chainId != null ? String(chain.chainId) : chain.family) ?? "unknown";
|
|
64
|
-
const context = { address: chain.address ?? rootAddress, chain: chainName, venue: chain.venue };
|
|
65
|
-
if (chain.native && (chain.native.amount == null || Number(chain.native.amount) !== 0)) {
|
|
66
|
-
addAsset(output, { ...chain.native, symbol: chain.native.symbol ?? chain.symbol ?? chainName }, context);
|
|
67
|
-
}
|
|
68
|
-
for (const asset of chain.assets || chain.fungibleTokens?.assets || []) addAsset(output, asset, context);
|
|
69
|
-
for (const asset of chain.collectibles?.assets || chain.nfts || []) addAsset(output, { ...asset, kind: "nft" }, context);
|
|
70
|
-
for (const asset of chain.spot?.balances || []) addAsset(output, asset, { ...context, venue: "Hyperliquid spot" });
|
|
71
|
-
const accountValue = finite(chain.perps?.accountValueUsd);
|
|
72
|
-
if (accountValue != null) addAsset(output, { symbol: "perps account", usdValue: accountValue }, { ...context, venue: "Hyperliquid perps" });
|
|
73
|
-
}
|
|
74
|
-
for (const item of snapshot.inventory?.items || snapshot.nfts?.items || []) addAsset(output, { ...item, kind: "nft" }, { address: rootAddress, chain: item.chain ?? snapshot.chain, venue: item.marketplace ?? snapshot.venue });
|
|
75
|
-
return output;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function snapshotKey(snapshot, index) {
|
|
79
|
-
const address = addressOf(snapshot);
|
|
80
|
-
const chain = snapshot.chain ?? snapshot.chainId ?? snapshot.family ?? "*";
|
|
81
|
-
return address ? `${String(address).toLowerCase()}|${String(chain).toLowerCase()}` : `snapshot:${index}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function buckets(assets, property, total) {
|
|
85
|
-
const map = new Map();
|
|
86
|
-
for (const asset of assets) {
|
|
87
|
-
if (asset.usdValue == null) continue;
|
|
88
|
-
const name = asset[property];
|
|
89
|
-
map.set(name, (map.get(name) || 0) + asset.usdValue);
|
|
90
|
-
}
|
|
91
|
-
return [...map].map(([name, knownUsd]) => ({ name, knownUsd: rounded(knownUsd), percentOfKnown: pct(knownUsd, total) }))
|
|
92
|
-
.sort((a, b) => b.knownUsd - a.knownUsd || a.name.localeCompare(b.name));
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Summarize already-fetched portfolio snapshots. Accepts either
|
|
97
|
-
* `{ snapshots, labels, thresholds }` or an array plus an options object.
|
|
98
|
-
*/
|
|
99
|
-
export function summarizePortfolioRisk(input = {}, options = {}) {
|
|
100
|
-
const snapshots = Array.isArray(input) ? input : Array.isArray(input.snapshots) ? input.snapshots : input.snapshot ? [input.snapshot] : [];
|
|
101
|
-
const labels = labelIndex(options.labels ?? options.addressBook ?? input.labels ?? input.addressBook);
|
|
102
|
-
const thresholds = { ...DEFAULT_RISK_THRESHOLDS, ...(input.thresholds || {}), ...(options.thresholds || {}) };
|
|
103
|
-
const unique = [];
|
|
104
|
-
const seen = new Set();
|
|
105
|
-
let duplicatesIgnored = 0;
|
|
106
|
-
snapshots.forEach((snapshot, index) => {
|
|
107
|
-
if (!snapshot || typeof snapshot !== "object") return;
|
|
108
|
-
const key = snapshotKey(snapshot, index);
|
|
109
|
-
if (seen.has(key)) duplicatesIgnored += 1;
|
|
110
|
-
else { seen.add(key); unique.push(snapshot); }
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const assets = unique.flatMap(assetsFromSnapshot);
|
|
114
|
-
const priced = assets.filter((asset) => asset.usdValue != null);
|
|
115
|
-
const unknown = assets.filter((asset) => asset.usdValue == null);
|
|
116
|
-
const explicitUnknown = unique.reduce((sum, snapshot) => sum + Number(snapshot.valuation?.unpricedNonzeroItems || snapshot.unpricedNonzeroItems || 0), 0);
|
|
117
|
-
const totalKnownUsd = rounded(priced.reduce((sum, asset) => sum + asset.usdValue, 0));
|
|
118
|
-
const unknownItemCount = unknown.length + explicitUnknown;
|
|
119
|
-
const chainExposures = buckets(priced, "chain", totalKnownUsd);
|
|
120
|
-
const venueExposures = buckets(priced, "venue", totalKnownUsd);
|
|
121
|
-
const groupedAssets = buckets(priced, "symbol", totalKnownUsd);
|
|
122
|
-
for (const row of chainExposures) row.chain = row.name;
|
|
123
|
-
for (const row of venueExposures) row.venue = row.name;
|
|
124
|
-
for (const row of groupedAssets) {
|
|
125
|
-
row.asset = row.name;
|
|
126
|
-
row.symbol = row.name;
|
|
127
|
-
}
|
|
128
|
-
const stablecoinKnownUsd = rounded(priced.filter((asset) => asset.stablecoin).reduce((sum, asset) => sum + asset.usdValue, 0));
|
|
129
|
-
const nftAssets = assets.filter((asset) => asset.kind === "nft");
|
|
130
|
-
const snapshotNftUnvalued = unique.reduce((sum, snapshot) => sum + Number(snapshot.valuation?.nftUnvaluedItems || 0), 0);
|
|
131
|
-
const nftUnvaluedItems = nftAssets.filter((asset) => asset.usdValue == null).length + snapshotNftUnvalued;
|
|
132
|
-
const nftValuedItems = nftAssets.filter((asset) => asset.usdValue != null).length;
|
|
133
|
-
const top = groupedAssets[0] || null;
|
|
134
|
-
const concentrationLevel = !top ? "unknown" : top.percentOfKnown >= thresholds.assetHighPct ? "high" : top.percentOfKnown >= thresholds.assetMediumPct ? "medium" : "low";
|
|
135
|
-
const warnings = [];
|
|
136
|
-
if (unknownItemCount) warnings.push(`${unknownItemCount} nonzero holding(s) have unknown USD value; they are excluded from totals and percentages.`);
|
|
137
|
-
if (nftUnvaluedItems) warnings.push("NFT valuation coverage is partial; estimates are not executable bids and unvalued NFTs are not treated as zero.");
|
|
138
|
-
if (duplicatesIgnored) warnings.push(`${duplicatesIgnored} duplicate address/chain snapshot(s) were ignored.`);
|
|
139
|
-
if (top && concentrationLevel !== "low") warnings.push(`Asset concentration is ${concentrationLevel}: ${top.name} is ${top.percentOfKnown}% of known value.`);
|
|
140
|
-
if (chainExposures[0]?.percentOfKnown >= thresholds.chainHighPct) warnings.push(`Chain concentration is high: ${chainExposures[0].name} is ${chainExposures[0].percentOfKnown}% of known value.`);
|
|
141
|
-
if (venueExposures[0]?.percentOfKnown >= thresholds.venueHighPct) warnings.push(`Venue concentration is high: ${venueExposures[0].name} is ${venueExposures[0].percentOfKnown}% of known value.`);
|
|
142
|
-
|
|
143
|
-
const addresses = unique.map(addressOf).filter(Boolean).map((address) => {
|
|
144
|
-
const entry = labels.get(String(address).toLowerCase());
|
|
145
|
-
return { address, label: entry?.label ?? null, who: entry?.who ?? null, role: entry?.role ?? null };
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
totalKnownUsd,
|
|
149
|
-
coverage: {
|
|
150
|
-
complete: unique.length > 0 && unknownItemCount === 0 && unique.every((snapshot) => snapshot.valuation?.complete !== false && snapshot.coverage?.complete !== false),
|
|
151
|
-
label: unknownItemCount === 0 && unique.length && unique.every((snapshot) => snapshot.valuation?.complete !== false && snapshot.coverage?.complete !== false)
|
|
152
|
-
? "complete for the supplied snapshots" : "known priced value only; portfolio coverage is partial or unverified",
|
|
153
|
-
unknownUsd: unknownItemCount ? null : 0,
|
|
154
|
-
pricedItemCount: priced.length,
|
|
155
|
-
unknownItemCount,
|
|
156
|
-
snapshotCount: unique.length,
|
|
157
|
-
duplicatesIgnored,
|
|
158
|
-
},
|
|
159
|
-
chainExposures,
|
|
160
|
-
venueExposures,
|
|
161
|
-
topAssets: groupedAssets.slice(0, Math.max(1, Number(options.topAssets ?? input.topAssets ?? 10))),
|
|
162
|
-
concentrationRisk: { level: concentrationLevel, topAsset: top?.name ?? null, topAssetPercent: top?.percentOfKnown ?? null, thresholds: { mediumPct: thresholds.assetMediumPct, highPct: thresholds.assetHighPct } },
|
|
163
|
-
stablecoinExposure: { knownUsd: stablecoinKnownUsd, percentOfKnown: pct(stablecoinKnownUsd, totalKnownUsd), high: totalKnownUsd > 0 && pct(stablecoinKnownUsd, totalKnownUsd) >= thresholds.stablecoinHighPct },
|
|
164
|
-
nftCoverage: { status: nftAssets.length || snapshotNftUnvalued ? (nftUnvaluedItems ? "partial" : "valued") : "not-observed", valuedItems: nftValuedItems, unvaluedItems: nftUnvaluedItems, knownUsd: rounded(nftAssets.filter((asset) => asset.usdValue != null).reduce((sum, asset) => sum + asset.usdValue, 0)) },
|
|
165
|
-
addresses,
|
|
166
|
-
warnings: [...new Set(warnings)],
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export const portfolioRiskSummary = summarizePortfolioRisk;
|
package/src/prepare-envelope.mjs
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
// Canonical prepare envelope shared by Oracle prepare helpers and the local operator.
|
|
2
|
-
// The versioned checksum binds payload and freshness metadata. It detects mutation.
|
|
3
|
-
// Optional HMAC (ORACLE_STAMP_HMAC_SECRET) adds keyed integrity when configured.
|
|
4
|
-
// Signer-owned policy, not this public checksum alone, authorizes execution.
|
|
5
|
-
|
|
6
|
-
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
7
|
-
|
|
8
|
-
export const PREPARE_VERSION = 2;
|
|
9
|
-
/** Default max age for a prepared envelope at sign time (ms). */
|
|
10
|
-
export const PREPARE_MAX_AGE_MS = 5 * 60 * 1000;
|
|
11
|
-
/**
|
|
12
|
-
* Hard ceiling for maxAgeMs. Caller/agent cannot widen past this.
|
|
13
|
-
* Override upward only via signer-process env ORACLE_PREPARE_HARD_MAX_AGE_MS.
|
|
14
|
-
*/
|
|
15
|
-
export const PREPARE_HARD_MAX_AGE_MS = (() => {
|
|
16
|
-
const n = Number(process.env.ORACLE_PREPARE_HARD_MAX_AGE_MS);
|
|
17
|
-
return Number.isFinite(n) && n > 0 ? n : 30 * 60 * 1000; // 30 minutes
|
|
18
|
-
})();
|
|
19
|
-
|
|
20
|
-
/** Resolve max age: default 5m, never above hard max (even if caller passes MAX_SAFE_INTEGER). */
|
|
21
|
-
export function resolvePrepareMaxAgeMs(requested) {
|
|
22
|
-
const base =
|
|
23
|
-
requested == null || requested === ""
|
|
24
|
-
? PREPARE_MAX_AGE_MS
|
|
25
|
-
: Number(requested);
|
|
26
|
-
if (!Number.isFinite(base) || base < 0) return PREPARE_MAX_AGE_MS;
|
|
27
|
-
return Math.min(base, PREPARE_HARD_MAX_AGE_MS);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function stableStringify(value) {
|
|
31
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
32
|
-
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
33
|
-
const keys = Object.keys(value).sort();
|
|
34
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(value[k])}`).join(",")}}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function stampSecret(env = process.env) {
|
|
38
|
-
const s = String(env.ORACLE_STAMP_HMAC_SECRET || "").trim();
|
|
39
|
-
return s.length >= 16 ? s : "";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function requireMac(env = process.env) {
|
|
43
|
-
return String(env.ORACLE_STAMP_REQUIRE_MAC || "").trim() === "1";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Fields that bind the envelope (must not include the stamp fields themselves). */
|
|
47
|
-
export function prepareBodyForHash(prepared) {
|
|
48
|
-
const {
|
|
49
|
-
oraclePrepared,
|
|
50
|
-
prepareHash,
|
|
51
|
-
prepareMac,
|
|
52
|
-
note,
|
|
53
|
-
...body
|
|
54
|
-
} = prepared || {};
|
|
55
|
-
return body;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function computePrepareHash(prepared) {
|
|
59
|
-
const body = prepareBodyForHash(prepared);
|
|
60
|
-
return createHash("sha256").update(stableStringify(body)).digest("hex");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function computePrepareMac(prepareHash, secret = stampSecret()) {
|
|
64
|
-
if (!secret) return "";
|
|
65
|
-
return createHmac("sha256", secret).update(String(prepareHash)).digest("hex");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function safeEqualHex(a, b) {
|
|
69
|
-
try {
|
|
70
|
-
const ba = Buffer.from(String(a), "hex");
|
|
71
|
-
const bb = Buffer.from(String(b), "hex");
|
|
72
|
-
if (ba.length === 0 || ba.length !== bb.length) return false;
|
|
73
|
-
return timingSafeEqual(ba, bb);
|
|
74
|
-
} catch {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Stamp a prepare result. Call at the end of every prepare helper.
|
|
81
|
-
* @param {object} payload provider-specific prepare fields (action/tx/psbt/...)
|
|
82
|
-
*/
|
|
83
|
-
export function stampPrepared(payload, { provider, kind, env = process.env } = {}) {
|
|
84
|
-
if (!payload || typeof payload !== "object") throw new Error("stampPrepared: payload object required");
|
|
85
|
-
const base = {
|
|
86
|
-
...payload,
|
|
87
|
-
provider: payload.provider || provider,
|
|
88
|
-
kind: payload.kind || kind,
|
|
89
|
-
requiresUserSignature: payload.requiresUserSignature !== false,
|
|
90
|
-
signingReady: false,
|
|
91
|
-
broadcastReady: false,
|
|
92
|
-
executionReady: false,
|
|
93
|
-
};
|
|
94
|
-
if (!base.provider) throw new Error("stampPrepared: provider required");
|
|
95
|
-
if (!base.kind) throw new Error("stampPrepared: kind required");
|
|
96
|
-
const preparedAt = Date.now();
|
|
97
|
-
const expiresAt = preparedAt + PREPARE_MAX_AGE_MS;
|
|
98
|
-
const prepareVersion = PREPARE_VERSION;
|
|
99
|
-
const withMeta = { ...base, preparedAt, expiresAt, prepareVersion };
|
|
100
|
-
const prepareHash = computePrepareHash(withMeta);
|
|
101
|
-
const secret = stampSecret(env);
|
|
102
|
-
const prepareMac = secret ? computePrepareMac(prepareHash, secret) : undefined;
|
|
103
|
-
const out = {
|
|
104
|
-
...withMeta,
|
|
105
|
-
oraclePrepared: true,
|
|
106
|
-
prepareHash,
|
|
107
|
-
};
|
|
108
|
-
if (prepareMac) out.prepareMac = prepareMac;
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Verify a prepared envelope before operator sign.
|
|
114
|
-
* @throws on mismatch / expiry / missing stamp
|
|
115
|
-
*/
|
|
116
|
-
export function assertPreparedEnvelope(prepared, {
|
|
117
|
-
maxAgeMs = PREPARE_MAX_AGE_MS,
|
|
118
|
-
nowMs = Date.now(),
|
|
119
|
-
providers = null,
|
|
120
|
-
kinds = null,
|
|
121
|
-
label = "operator",
|
|
122
|
-
env = process.env,
|
|
123
|
-
} = {}) {
|
|
124
|
-
if (!prepared || typeof prepared !== "object") {
|
|
125
|
-
throw new Error(`${label}: prepared envelope object required`);
|
|
126
|
-
}
|
|
127
|
-
if (prepared.oraclePrepared !== true) {
|
|
128
|
-
throw new Error(
|
|
129
|
-
`${label}: prepared integrity envelope missing — use an @oracle-agent/oracle prepare result`,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
if (Number(prepared.prepareVersion) !== PREPARE_VERSION) {
|
|
133
|
-
throw new Error(`${label}: unsupported prepareVersion ${prepared.prepareVersion}`);
|
|
134
|
-
}
|
|
135
|
-
const expected = computePrepareHash(prepared);
|
|
136
|
-
if (String(prepared.prepareHash || "") !== expected) {
|
|
137
|
-
throw new Error(`${label}: prepareHash mismatch — payload was altered after prepare`);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const secret = stampSecret(env);
|
|
141
|
-
const mac = String(prepared.prepareMac || "");
|
|
142
|
-
if (requireMac(env) || mac) {
|
|
143
|
-
if (!secret) {
|
|
144
|
-
throw new Error(
|
|
145
|
-
`${label}: prepareMac present or ORACLE_STAMP_REQUIRE_MAC=1 but ORACLE_STAMP_HMAC_SECRET missing in signer`,
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
const expectedMac = computePrepareMac(expected, secret);
|
|
149
|
-
if (!mac || !safeEqualHex(mac, expectedMac)) {
|
|
150
|
-
throw new Error(`${label}: prepareMac mismatch — stamp not from trusted preparer`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const preparedAt = Number(prepared.preparedAt);
|
|
155
|
-
const expiresAt = Number(prepared.expiresAt);
|
|
156
|
-
const effectiveMax = resolvePrepareMaxAgeMs(maxAgeMs);
|
|
157
|
-
const age = nowMs - preparedAt;
|
|
158
|
-
const lifetime = expiresAt - preparedAt;
|
|
159
|
-
if (
|
|
160
|
-
!Number.isFinite(age) ||
|
|
161
|
-
!Number.isFinite(expiresAt) ||
|
|
162
|
-
!Number.isFinite(lifetime) ||
|
|
163
|
-
age < 0 ||
|
|
164
|
-
lifetime <= 0 ||
|
|
165
|
-
lifetime > PREPARE_HARD_MAX_AGE_MS ||
|
|
166
|
-
age > effectiveMax ||
|
|
167
|
-
nowMs > expiresAt
|
|
168
|
-
) {
|
|
169
|
-
throw new Error(
|
|
170
|
-
`${label}: prepare envelope expired or clock-skewed (ageMs=${age}, max=${effectiveMax})`,
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
if (providers) {
|
|
174
|
-
const allow = new Set(providers);
|
|
175
|
-
if (!allow.has(prepared.provider)) {
|
|
176
|
-
throw new Error(`${label}: provider ${prepared.provider} not allowed here`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (kinds) {
|
|
180
|
-
const allow = new Set(kinds);
|
|
181
|
-
if (!allow.has(prepared.kind)) {
|
|
182
|
-
throw new Error(`${label}: kind ${prepared.kind} not allowed here`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return true;
|
|
186
|
-
}
|