@oracle-agent/oracle 0.13.1 → 0.14.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/CONTRIBUTING.md +99 -0
- package/README.md +20 -14
- package/SECURITY.md +6 -8
- package/SETUP.md +25 -27
- package/bin/desk-server.mjs +473 -0
- package/bin/oracle-data-mcp.mjs +1252 -0
- package/bin/oracle-equities.mjs +168 -0
- package/bin/oracle-init.mjs +525 -0
- package/bin/oracle-public-server.mjs +36 -0
- package/bin/oracle-route.mjs +254 -0
- package/bin/oracle-scan.mjs +192 -0
- package/bin/oracle-upgrade.mjs +42 -0
- package/bin/oracle.mjs +34 -0
- package/docs/adding-a-chain.md +229 -0
- package/docs/architecture.md +139 -0
- package/docs/buzz-integration.md +115 -0
- package/docs/cli.md +143 -0
- package/docs/connectors.md +13 -0
- package/docs/hyperliquid-builder-code.md +50 -0
- package/docs/locals-only-fee-waiver.md +34 -0
- package/docs/oracle-pack-standard.md +29 -0
- package/docs/profiles.md +151 -0
- package/docs/public-surface.md +206 -0
- package/examples/add-a-chain.mjs +65 -0
- package/examples/oracle-pack-template.mjs +38 -0
- package/examples/research-a-token.mjs +70 -0
- package/package.json +78 -32
- package/plugins/oracle-owner-gate/__init__.py +288 -0
- package/plugins/oracle-owner-gate/plugin.yaml +9 -0
- package/{dist/assets/profiles → profiles}/oracle/SOUL.md +0 -14
- package/protocols/templates/safe-erc20/SECURITY.md +16 -0
- package/protocols/templates/safe-erc20/foundry.toml +12 -0
- package/protocols/templates/safe-erc20/remappings.txt +2 -0
- package/protocols/templates/safe-erc20/src/SafeERC20.sol +53 -0
- package/protocols/templates/safe-erc20/test/SafeERC20.t.sol +72 -0
- package/public/oracle-splash/_variants/ice.html +3 -3
- package/public/oracle-splash/_variants/ivory.html +3 -3
- package/public/oracle-splash/downloads/index.html +34 -223
- package/public/oracle-splash/index.html +11 -11
- package/scripts/adversarial-bench.mjs +114 -0
- package/scripts/build-dist.mjs +119 -0
- package/scripts/build-inscription.py +230 -0
- package/scripts/check-doc-drift.mjs +123 -0
- package/scripts/check-test-count.mjs +105 -0
- package/scripts/e2e-hl-markets.mjs +21 -0
- package/scripts/e2e-hl-perps.mjs +48 -0
- package/scripts/e2e-hypercore-staking.mjs +128 -0
- package/scripts/e2e-solana-bitcoin.mjs +183 -0
- package/scripts/guard-publish.mjs +22 -0
- package/scripts/protocol-template-gate.mjs +15 -0
- package/scripts/public-api-scan.mjs +23 -0
- package/scripts/publish-dist.mjs +67 -0
- package/scripts/record-hero-cli.sh +80 -0
- package/scripts/secret-scan.mjs +168 -0
- package/scripts/smoke-dist-bins.mjs +89 -0
- package/scripts/verify-dist.mjs +29 -0
- package/scripts/verify-v3-venues.mjs +233 -0
- package/skins/oracle.yaml +56 -0
- package/src/action-receipts.mjs +265 -0
- package/src/action-semantics.mjs +62 -0
- package/src/address-book.mjs +208 -0
- package/src/agent-auth.mjs +206 -0
- package/src/approval-guard.mjs +282 -0
- package/src/attestation-secret.mjs +94 -0
- package/src/audit-log.mjs +196 -0
- package/src/auth/oauth.mjs +672 -0
- package/src/auto-slippage.mjs +378 -0
- package/src/capability-posture.mjs +125 -0
- package/src/cards.mjs +422 -0
- package/src/chains.mjs +62 -0
- package/src/cli/chain-catalog.mjs +215 -0
- package/src/cli/chain-state.mjs +74 -0
- package/src/cli/commands/auth.mjs +193 -0
- package/src/cli/commands/bootstrap.mjs +87 -0
- package/src/cli/commands/chain.mjs +143 -0
- package/src/cli/commands/chat.mjs +465 -0
- package/src/cli/commands/credential.mjs +9 -0
- package/src/cli/commands/data-mcp.mjs +18 -0
- package/src/cli/commands/data.mjs +75 -0
- package/src/cli/commands/doctor.mjs +136 -0
- package/src/cli/commands/equities.mjs +41 -0
- package/src/cli/commands/farm.mjs +129 -0
- package/src/cli/commands/fees.mjs +109 -0
- package/src/cli/commands/follow.mjs +130 -0
- package/src/cli/commands/harness.mjs +63 -0
- package/src/cli/commands/help.mjs +7 -0
- package/src/cli/commands/init.mjs +27 -0
- package/src/cli/commands/mcp.mjs +154 -0
- package/src/cli/commands/model.mjs +106 -0
- package/src/cli/commands/plugins.mjs +241 -0
- package/src/cli/commands/prepare.mjs +12 -0
- package/src/cli/commands/public.mjs +20 -0
- package/src/cli/commands/resolve.mjs +64 -0
- package/src/cli/commands/route.mjs +12 -0
- package/src/cli/commands/runner.mjs +9 -0
- package/src/cli/commands/scan.mjs +12 -0
- package/src/cli/commands/setup.mjs +294 -0
- package/src/cli/commands/sign.mjs +21 -0
- package/src/cli/commands/signer.mjs +9 -0
- package/src/cli/commands/swap.mjs +102 -0
- package/src/cli/commands/upgrade.mjs +12 -0
- package/src/cli/commands/vault.mjs +9 -0
- package/src/cli/commands/version.mjs +22 -0
- package/src/cli/first-run.mjs +23 -0
- package/src/cli/kernel.mjs +262 -0
- package/src/cli/mcp-targets/chatgpt.mjs +51 -0
- package/src/cli/mcp-targets/claude-code.mjs +39 -0
- package/src/cli/mcp-targets/claude-desktop.mjs +24 -0
- package/src/cli/mcp-targets/codex.mjs +41 -0
- package/src/cli/mcp-targets/cursor.mjs +32 -0
- package/src/cli/mcp-targets/shared.mjs +71 -0
- package/src/cli/mcp-targets/vscode.mjs +39 -0
- package/src/cli/messaging-platforms.mjs +217 -0
- package/src/cli/model-config.mjs +78 -0
- package/src/cli/operator-dispatch.mjs +257 -0
- package/src/cli/oracle-harness.py +415 -0
- package/src/cli/paths.mjs +107 -0
- package/src/cli/runtime.mjs +351 -0
- package/src/cli/setup-state.mjs +168 -0
- package/src/cli/spawn-child.mjs +43 -0
- package/src/data/catalog.mjs +858 -0
- package/src/data/desk-data.mjs +877 -0
- package/src/data/http.mjs +253 -0
- package/src/data/names.mjs +188 -0
- package/src/data/provider-endpoint.mjs +94 -0
- package/src/data/providers/aave-v3.mjs +139 -0
- package/src/data/providers/across-bridge.mjs +41 -0
- package/src/data/providers/aerodrome.mjs +245 -0
- package/src/data/providers/aevo.mjs +33 -0
- package/src/data/providers/approval-indexer.mjs +133 -0
- package/src/data/providers/approvals.mjs +594 -0
- package/src/data/providers/babylon-staking.mjs +149 -0
- package/src/data/providers/balancer.mjs +209 -0
- package/src/data/providers/beefy-yields.mjs +45 -0
- package/src/data/providers/birdeye-tokens.mjs +33 -0
- package/src/data/providers/bisq-markets.mjs +145 -0
- package/src/data/providers/bitcoin-esplora.mjs +216 -0
- package/src/data/providers/bitcoin-meta.mjs +378 -0
- package/src/data/providers/blockscout.mjs +14 -0
- package/src/data/providers/bob-rootstock.mjs +198 -0
- package/src/data/providers/braiins-insights.mjs +103 -0
- package/src/data/providers/bridge-aggregator.mjs +259 -0
- package/src/data/providers/bridges.mjs +242 -0
- package/src/data/providers/bungee.mjs +29 -0
- package/src/data/providers/celestia-da.mjs +38 -0
- package/src/data/providers/changenow.mjs +135 -0
- package/src/data/providers/compound.mjs +32 -0
- package/src/data/providers/connext.mjs +28 -0
- package/src/data/providers/convex.mjs +30 -0
- package/src/data/providers/cow-protocol.mjs +110 -0
- package/src/data/providers/cowswap.mjs +415 -0
- package/src/data/providers/curve.mjs +201 -0
- package/src/data/providers/das-assets.mjs +59 -0
- package/src/data/providers/debridge.mjs +109 -0
- package/src/data/providers/defillama.mjs +88 -0
- package/src/data/providers/dexscreener.mjs +43 -0
- package/src/data/providers/drift.mjs +32 -0
- package/src/data/providers/dydx.mjs +41 -0
- package/src/data/providers/evm-rpc.mjs +225 -0
- package/src/data/providers/farming.mjs +291 -0
- package/src/data/providers/geckoterminal.mjs +34 -0
- package/src/data/providers/gmx.mjs +496 -0
- package/src/data/providers/hiro-stacks.mjs +150 -0
- package/src/data/providers/hl-assets.mjs +165 -0
- package/src/data/providers/hl-info.mjs +108 -0
- package/src/data/providers/hl-markets.mjs +210 -0
- package/src/data/providers/hl-outcome.mjs +61 -0
- package/src/data/providers/hl-perps.mjs +419 -0
- package/src/data/providers/hl-staking.mjs +353 -0
- package/src/data/providers/hl-ws.mjs +119 -0
- package/src/data/providers/hyperevm-dex.mjs +49 -0
- package/src/data/providers/jito-mev.mjs +117 -0
- package/src/data/providers/jupiter-venues.mjs +119 -0
- package/src/data/providers/jupiter.mjs +315 -0
- package/src/data/providers/kamino-strategies.mjs +143 -0
- package/src/data/providers/l2beat-tvl.mjs +42 -0
- package/src/data/providers/lifi.mjs +166 -0
- package/src/data/providers/liquid-esplora.mjs +152 -0
- package/src/data/providers/magiceden-ordinals.mjs +141 -0
- package/src/data/providers/magiceden-sol.mjs +406 -0
- package/src/data/providers/mempool-lightning.mjs +144 -0
- package/src/data/providers/mempool-mining.mjs +142 -0
- package/src/data/providers/meteora-dlmm.mjs +168 -0
- package/src/data/providers/morpho.mjs +177 -0
- package/src/data/providers/nft-gallery.mjs +163 -0
- package/src/data/providers/nft-portfolio.mjs +494 -0
- package/src/data/providers/odos.mjs +156 -0
- package/src/data/providers/ondo.mjs +31 -0
- package/src/data/providers/oneinch.mjs +174 -0
- package/src/data/providers/opensea-multichain.mjs +136 -0
- package/src/data/providers/opensea-nft.mjs +371 -0
- package/src/data/providers/orca.mjs +29 -0
- package/src/data/providers/ordinals-runes.mjs +180 -0
- package/src/data/providers/pancakeswap.mjs +28 -0
- package/src/data/providers/paraswap.mjs +125 -0
- package/src/data/providers/pendle.mjs +188 -0
- package/src/data/providers/poly-clob.mjs +283 -0
- package/src/data/providers/poly-public.mjs +96 -0
- package/src/data/providers/poly-ws.mjs +103 -0
- package/src/data/providers/polygon-staking.mjs +227 -0
- package/src/data/providers/portfolio-history.mjs +394 -0
- package/src/data/providers/portfolio.mjs +600 -0
- package/src/data/providers/pyth-price-feeds.mjs +172 -0
- package/src/data/providers/raydium.mjs +35 -0
- package/src/data/providers/relayscan-mev.mjs +72 -0
- package/src/data/providers/rfq.mjs +15 -0
- package/src/data/providers/rh-agent.mjs +59 -0
- package/src/data/providers/sanctum-lst.mjs +180 -0
- package/src/data/providers/satflow.mjs +341 -0
- package/src/data/providers/signed-material-guard.mjs +108 -0
- package/src/data/providers/solana-rpc.mjs +197 -0
- package/src/data/providers/solend-lending.mjs +166 -0
- package/src/data/providers/spark-lend.mjs +42 -0
- package/src/data/providers/squid-router.mjs +29 -0
- package/src/data/providers/stargate.mjs +29 -0
- package/src/data/providers/sushiswap.mjs +30 -0
- package/src/data/providers/symbiotic-restaking.mjs +41 -0
- package/src/data/providers/thorchain.mjs +36 -0
- package/src/data/providers/traderjoe.mjs +28 -0
- package/src/data/providers/twap.mjs +152 -0
- package/src/data/providers/uniswap-v3.mjs +457 -0
- package/src/data/providers/uniswap-v4.mjs +414 -0
- package/src/data/providers/vertex.mjs +41 -0
- package/src/data/providers/wallet-watch.mjs +264 -0
- package/src/data/providers/wormhole.mjs +28 -0
- package/src/data/providers/yearn.mjs +31 -0
- package/src/data/providers/zerox.mjs +167 -0
- package/src/data/public-api-scan.mjs +61 -0
- package/src/data/quote-placeholder.mjs +31 -0
- package/src/desk/swap-prepare.mjs +194 -0
- package/src/equities/bridge.mjs +388 -0
- package/src/equities/fixtures/bridge_routes.json +159 -0
- package/src/equities/fixtures/dst_transitions.json +29 -0
- package/src/equities/fixtures/equity_dex_pools.json +154 -0
- package/src/equities/fixtures/hip3_l2books.json +2711 -0
- package/src/equities/fixtures/nyse_holidays.json +1 -0
- package/src/equities/fixtures/oracles.json +100 -0
- package/src/equities/fixtures/rh_pool_state.json +244 -0
- package/src/equities/fixtures/solana_xstocks.json +704 -0
- package/src/equities/fixtures/ton_xstocks.json +35 -0
- package/src/equities/fixtures/universe.json +411 -0
- package/src/equities/fixtures/venues.json +3542 -0
- package/src/equities/fixtures.mjs +405 -0
- package/src/equities/funding.mjs +142 -0
- package/src/equities/index.mjs +166 -0
- package/src/equities/liveness.mjs +148 -0
- package/src/equities/marketHours.mjs +249 -0
- package/src/equities/normalize.mjs +295 -0
- package/src/equities/num.mjs +146 -0
- package/src/equities/prepare.mjs +95 -0
- package/src/equities/rank.mjs +260 -0
- package/src/equities/sourceNum.mjs +69 -0
- package/src/equities/types.mjs +220 -0
- package/src/equities/venues/arcus-perp.mjs +84 -0
- package/src/equities/venues/arcus-spot.mjs +105 -0
- package/src/equities/venues/hyperliquid-hip3.mjs +224 -0
- package/src/equities/venues/rh-uniswap.mjs +216 -0
- package/src/equities/venues/solana-xstocks.mjs +139 -0
- package/src/equities/venues/ton-stonfi.mjs +139 -0
- package/src/exact-integer.mjs +72 -0
- package/src/exec-policy.mjs +419 -0
- package/src/flags.mjs +15 -0
- package/src/fresh-window.mjs +76 -0
- package/src/gmx-attestation.mjs +176 -0
- package/src/index.mjs +107 -0
- package/src/licensing/locals-only.mjs +25 -0
- package/src/nft-gas-war-guard.mjs +139 -0
- package/src/onboarding/agent-keys.mjs +161 -0
- package/src/onboarding/harness-configs.mjs +102 -0
- package/src/onboarding/index.mjs +18 -0
- package/src/onboarding/tiers.mjs +139 -0
- package/src/oracle-env.mjs +55 -0
- package/src/package-manifest.mjs +42 -0
- package/src/plugins/agent-plugin-loader.mjs +225 -0
- package/src/portfolio-risk.mjs +170 -0
- package/src/prepare-envelope.mjs +204 -0
- package/src/profile-upgrade.mjs +277 -0
- package/src/protocol-execution.mjs +84 -0
- package/src/protocol-templates/gate.mjs +179 -0
- package/src/protocol-templates/prepare-deploy.mjs +81 -0
- package/src/public-api/agent-grants.mjs +57 -0
- package/src/public-api/buzz-integration.mjs +267 -0
- package/src/public-api/connect-agent.mjs +424 -0
- package/src/public-api/grants.mjs +142 -0
- package/src/public-api/http.mjs +707 -0
- package/src/public-api/metering.mjs +111 -0
- package/src/public-control/aa-adapter.mjs +402 -0
- package/src/public-control/build-registry.mjs +227 -0
- package/src/public-control/bundler-client.mjs +357 -0
- package/src/public-control/grant-indexer.mjs +296 -0
- package/src/public-control/policy-render.mjs +69 -0
- package/src/public-control/policy-schema.mjs +322 -0
- package/src/public-control/runtime-config.mjs +275 -0
- package/src/public-control/session-key-model.mjs +379 -0
- package/src/public-control/session-orchestrator.mjs +418 -0
- package/src/rfq/intent.mjs +180 -0
- package/src/rfq/sources.mjs +181 -0
- package/src/route-attestation.mjs +132 -0
- package/src/router/best-execution.mjs +326 -0
- package/src/router/index.mjs +250 -0
- package/src/router/integrator-fee.mjs +135 -0
- package/src/router/prepare-bridge.mjs +293 -0
- package/src/router/prepare-route.mjs +398 -0
- package/src/router/proposal.mjs +311 -0
- package/src/router/risk-classifier.mjs +119 -0
- package/src/router/route-sources.mjs +364 -0
- package/src/scanner/chains.config.mjs +543 -0
- package/src/scanner/contract.mjs +270 -0
- package/src/scanner/evm-scanner.mjs +394 -0
- package/src/scanner/index.mjs +9 -0
- package/src/scanner/v2-venue.mjs +351 -0
- package/src/scanner/v3-venue.mjs +308 -0
- package/src/scopes.mjs +44 -0
- package/src/sell-simulation.mjs +167 -0
- package/src/signals/engine.mjs +146 -0
- package/src/signals/index.mjs +1 -0
- package/src/token-transfer-guard.mjs +188 -0
- package/src/tui/app.mjs +438 -0
- package/src/tui/backend.mjs +215 -0
- package/src/tui/format.mjs +272 -0
- package/src/tui/gateway-client.mjs +177 -0
- package/src/tui/input.mjs +501 -0
- package/src/tui/memory.mjs +105 -0
- package/src/tui/meta-learn.mjs +85 -0
- package/src/tui/renderer.mjs +443 -0
- package/src/tui/scheduler.mjs +205 -0
- package/src/tui/skills-loader.mjs +140 -0
- package/src/tui/standalone-client.mjs +752 -0
- package/src/tui/theme.mjs +81 -0
- package/src/vault-attestation.mjs +146 -0
- package/src/venues.mjs +206 -0
- package/src/watch-preferences.mjs +85 -0
- package/dist/action-receipts.mjs +0 -1
- package/dist/action-semantics.mjs +0 -1
- package/dist/address-book.mjs +0 -2
- package/dist/bin/desk-server.mjs +0 -59
- package/dist/bin/oracle-data-mcp.mjs +0 -8
- package/dist/bin/oracle-equities.mjs +0 -20
- package/dist/bin/oracle-init.mjs +0 -24
- package/dist/bin/oracle-public-server.mjs +0 -5
- package/dist/bin/oracle-route.mjs +0 -22
- package/dist/bin/oracle-scan.mjs +0 -18
- package/dist/bin/oracle-upgrade.mjs +0 -21
- package/dist/bin/oracle.mjs +0 -76
- package/dist/chains.mjs +0 -1
- package/dist/cli/commands/auth.mjs +0 -16
- package/dist/cli/commands/bootstrap.mjs +0 -18
- package/dist/cli/commands/chain.mjs +0 -21
- package/dist/cli/commands/chat.mjs +0 -45
- package/dist/cli/commands/credential.mjs +0 -1
- package/dist/cli/commands/data-mcp.mjs +0 -2
- package/dist/cli/commands/data.mjs +0 -12
- package/dist/cli/commands/doctor.mjs +0 -5
- package/dist/cli/commands/equities.mjs +0 -15
- package/dist/cli/commands/farm.mjs +0 -59
- package/dist/cli/commands/follow.mjs +0 -28
- package/dist/cli/commands/gate.mjs +0 -13
- package/dist/cli/commands/harness.mjs +0 -15
- package/dist/cli/commands/help.mjs +0 -1
- package/dist/cli/commands/init.mjs +0 -3
- package/dist/cli/commands/mcp.mjs +0 -60
- package/dist/cli/commands/model.mjs +0 -54
- package/dist/cli/commands/plugins.mjs +0 -38
- package/dist/cli/commands/prepare.mjs +0 -2
- package/dist/cli/commands/public.mjs +0 -3
- package/dist/cli/commands/resolve.mjs +0 -23
- package/dist/cli/commands/route.mjs +0 -2
- package/dist/cli/commands/runner.mjs +0 -1
- package/dist/cli/commands/scan.mjs +0 -2
- package/dist/cli/commands/setup.mjs +0 -34
- package/dist/cli/commands/sign.mjs +0 -21
- package/dist/cli/commands/signer.mjs +0 -1
- package/dist/cli/commands/swap.mjs +0 -36
- package/dist/cli/commands/upgrade.mjs +0 -2
- package/dist/cli/commands/vault.mjs +0 -1
- package/dist/cli/commands/version.mjs +0 -2
- package/dist/data/desk-data.mjs +0 -55
- package/dist/data/names.mjs +0 -2
- package/dist/data/providers/farming.mjs +0 -2
- package/dist/equities/index.mjs +0 -1
- package/dist/index.mjs +0 -60
- package/dist/nft-gas-war-guard.mjs +0 -1
- package/dist/onboarding/harness-configs.mjs +0 -4
- package/dist/portfolio-risk.mjs +0 -1
- package/dist/prepare-envelope.mjs +0 -1
- package/dist/public-api/agent-grants.mjs +0 -3
- package/dist/public-control/policy-schema.mjs +0 -1
- package/dist/router/index.mjs +0 -2
- package/dist/scanner/index.mjs +0 -4
- package/dist/signals/index.mjs +0 -1
- package/dist/watch-preferences.mjs +0 -1
- /package/{dist/assets/profiles → profiles}/_template/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/_template/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/bitcoin-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/bitcoin-agent/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/hyperliquid-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/hyperliquid-agent/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/oracle/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/polymarket-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/polymarket-agent/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/profile.schema.json +0 -0
- /package/{dist/assets/profiles → profiles}/protocol-builder/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/protocol-builder/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/robinhood-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/robinhood-agent/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/solana-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/solana-agent/profile.json +0 -0
- /package/{dist/assets/profiles → profiles}/stable-agent/SOUL.md +0 -0
- /package/{dist/assets/profiles → profiles}/stable-agent/profile.json +0 -0
- /package/{dist/assets/skills → skills}/balance/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/bitcoin-l1.md +0 -0
- /package/{dist/assets/skills → skills}/chain-defi-ecosystem-profiling.md +0 -0
- /package/{dist/assets/skills → skills}/evm-contract-research.md +0 -0
- /package/{dist/assets/skills → skills}/hyperliquid.md +0 -0
- /package/{dist/assets/skills → skills}/multichain-exec-desk.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-action-semantics/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-best-execution/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-best-execution.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-bitcoin/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-chain-graphs-telegram-cards/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-chat/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-chat/chain.SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-chat/setup.SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-circuit-breaker/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-contract-research/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-desk/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-desk.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-dex-launch/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-equities/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-grants/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-hypercore-staking/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-hyperliquid/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-meme-token-sniper/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-multichain-nft-launch/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-multichain-token-launch/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-nft-gacha-launch/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-nft-mint-gas-war/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-polymarket/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-protocol-builder/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-protocol-security/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-public-product/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-receipts/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-receipts.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-rfq-tokenized-assets/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-smart-wallet-scanner/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-solana/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-solana-nft/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/oracle-token-research/SKILL.md +0 -0
- /package/{dist/assets/skills → skills}/solana.md +0 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Symbol normalization for Oracle Equities.
|
|
2
|
+
//
|
|
3
|
+
// Every venue names the same underlying differently. This module resolves all of
|
|
4
|
+
// those forms to ONE canonical Oracle symbol so the ranking engine compares like
|
|
5
|
+
// with like.
|
|
6
|
+
//
|
|
7
|
+
// The governing rule is FAIL CLOSED. A wrong symbol match does not produce a
|
|
8
|
+
// missing row, it produces a FABRICATED one: two different assets get differenced
|
|
9
|
+
// and printed as an arbitrage that does not exist. Concretely, in the captured
|
|
10
|
+
// fixtures the ticker "LIT" appears on hyperliquid_hip3 (dex hyna, mark 3.37) and
|
|
11
|
+
// on arcus perps (mark 2.0379). A naive canonicalization merges them and prints a
|
|
12
|
+
// ~6536bp spread. Those are two different underlyings sharing three letters. The
|
|
13
|
+
// same trap exists for SKHX (1169.2) versus SKHY (153.61), both live on dex xyz.
|
|
14
|
+
//
|
|
15
|
+
// So: we never guess. Unknown or contested input returns
|
|
16
|
+
// { ambiguous: true, candidates: [...] } and the caller must either supply an
|
|
17
|
+
// explicit assetClass assertion or drop the row.
|
|
18
|
+
//
|
|
19
|
+
// Zero runtime dependencies. Node builtins only, via src/fixtures.mjs.
|
|
20
|
+
|
|
21
|
+
import { getUniverse, getVenues } from './fixtures.mjs';
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// canonical universe, sourced from fixtures/universe.json (the authority)
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
let canonicalSet;
|
|
28
|
+
function canonical() {
|
|
29
|
+
canonicalSet ??= new Set(Object.keys(getUniverse()));
|
|
30
|
+
return canonicalSet;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let dexSet;
|
|
34
|
+
function knownDexs() {
|
|
35
|
+
dexSet ??= new Set(Object.keys(getVenues().venues.hyperliquid_hip3.dexs));
|
|
36
|
+
return dexSet;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Symbols that mean genuinely DIFFERENT underlyings on different venues.
|
|
41
|
+
* Listed explicitly. Each entry must be disambiguated by the caller with an
|
|
42
|
+
* assetClass assertion, and even then the result is never cross venue comparable.
|
|
43
|
+
*/
|
|
44
|
+
export const CONTESTED_SYMBOLS = Object.freeze({
|
|
45
|
+
LIT: Object.freeze([
|
|
46
|
+
Object.freeze({
|
|
47
|
+
assetClass: 'etf',
|
|
48
|
+
description: 'Global X Lithium and Battery Tech ETF, an equity basket',
|
|
49
|
+
venues: Object.freeze(['hyperliquid_hip3']),
|
|
50
|
+
}),
|
|
51
|
+
Object.freeze({
|
|
52
|
+
assetClass: 'crypto',
|
|
53
|
+
description: 'a crypto perp listed under the same three letters',
|
|
54
|
+
venues: Object.freeze(['arcus']),
|
|
55
|
+
}),
|
|
56
|
+
]),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Venue unique names: pre IPO markets and synthetic baskets that exist on exactly
|
|
61
|
+
* ONE venue in the captured fixtures. They map to themselves. They can never be
|
|
62
|
+
* cross venue ranked because there is no second venue to compare against.
|
|
63
|
+
*
|
|
64
|
+
* Derived from fixtures/venues.json: symbols on dex vntl that appear nowhere else.
|
|
65
|
+
* NOTE: WHEAT is on vntl AND xyz, so it is deliberately excluded here.
|
|
66
|
+
*/
|
|
67
|
+
export const VENUE_UNIQUE_SYMBOLS = Object.freeze([
|
|
68
|
+
'SPACEX',
|
|
69
|
+
'OPENAI',
|
|
70
|
+
'ANTHROPIC',
|
|
71
|
+
'MAG7',
|
|
72
|
+
'SEMIS',
|
|
73
|
+
'ROBOT',
|
|
74
|
+
'INFOTECH',
|
|
75
|
+
'NUCLEAR',
|
|
76
|
+
'DEFENSE',
|
|
77
|
+
'ENERGY',
|
|
78
|
+
'BIOTECH',
|
|
79
|
+
'GOLDJM',
|
|
80
|
+
'SILVERJM',
|
|
81
|
+
'SOY',
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
const VENUE_UNIQUE_SET = new Set(VENUE_UNIQUE_SYMBOLS);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Allowlist for the lowercase x suffix (Solana xStocks style: NVDAx -> NVDA).
|
|
88
|
+
* The suffix is stripped ONLY for these bases, so a genuine ticker ending in a
|
|
89
|
+
* lowercase x is never mangled. No fixture currently exercises this with real
|
|
90
|
+
* data (no Solana or TON venue was captured), but the rule is cheap and correct
|
|
91
|
+
* and a future adapter needs it.
|
|
92
|
+
*/
|
|
93
|
+
export const XSTOCK_BASE_ALLOWLIST = Object.freeze([
|
|
94
|
+
'NVDA',
|
|
95
|
+
'TSLA',
|
|
96
|
+
'SPY',
|
|
97
|
+
'AAPL',
|
|
98
|
+
'COIN',
|
|
99
|
+
'AMZN',
|
|
100
|
+
'GOOGL',
|
|
101
|
+
'MSFT',
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
const XSTOCK_BASE_SET = new Set(XSTOCK_BASE_ALLOWLIST);
|
|
105
|
+
|
|
106
|
+
const QUOTE_SUFFIXES = Object.freeze(['-USD', '-USDC', '-USDT', '-PERP']);
|
|
107
|
+
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// result shape
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
function resolved(symbolRaw, symbol, extra = {}) {
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
ok: true,
|
|
115
|
+
ambiguous: false,
|
|
116
|
+
symbol,
|
|
117
|
+
symbolRaw,
|
|
118
|
+
dex: extra.dex ?? null,
|
|
119
|
+
applied: Object.freeze(extra.applied ?? []),
|
|
120
|
+
venueUnique: extra.venueUnique ?? false,
|
|
121
|
+
contested: extra.contested ?? false,
|
|
122
|
+
crossVenueComparable: extra.crossVenueComparable ?? true,
|
|
123
|
+
candidates: Object.freeze([]),
|
|
124
|
+
reason: null,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function unresolved(symbolRaw, reason, candidates = []) {
|
|
129
|
+
return Object.freeze({
|
|
130
|
+
ok: false,
|
|
131
|
+
ambiguous: true,
|
|
132
|
+
symbol: null,
|
|
133
|
+
symbolRaw: typeof symbolRaw === 'string' ? symbolRaw : null,
|
|
134
|
+
dex: null,
|
|
135
|
+
applied: Object.freeze([]),
|
|
136
|
+
venueUnique: false,
|
|
137
|
+
contested: false,
|
|
138
|
+
crossVenueComparable: false,
|
|
139
|
+
candidates: Object.freeze(candidates.map((c) => Object.freeze({ ...c }))),
|
|
140
|
+
reason,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// public helpers
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
export function listCanonicalSymbols() {
|
|
149
|
+
return [...canonical()];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function isCanonical(symbol) {
|
|
153
|
+
return typeof symbol === 'string' && canonical().has(symbol);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Resolve a venue specific symbol form to its canonical Oracle symbol.
|
|
158
|
+
*
|
|
159
|
+
* @param {string} input raw venue symbol, e.g. "xyz:NVDA", "NVDA-USD", "NVDAx"
|
|
160
|
+
* @param {object} [options]
|
|
161
|
+
* @param {string} [options.assetClass] explicit assertion required to resolve a
|
|
162
|
+
* contested ticker. Never inferred.
|
|
163
|
+
* @returns {object} frozen resolution record. Check `.ok` before using `.symbol`.
|
|
164
|
+
*/
|
|
165
|
+
export function normalizeSymbol(input, options = {}) {
|
|
166
|
+
if (typeof input !== 'string') {
|
|
167
|
+
return unresolved(input, 'input must be a string');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const trimmed = input.trim();
|
|
171
|
+
if (trimmed.length === 0) {
|
|
172
|
+
return unresolved(input, 'input must be a nonempty symbol');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const applied = [];
|
|
176
|
+
let working = trimmed;
|
|
177
|
+
let dex = null;
|
|
178
|
+
|
|
179
|
+
// 1. dex namespace strip, allowlisted against the real HIP-3 dex list.
|
|
180
|
+
const colon = working.indexOf(':');
|
|
181
|
+
if (colon !== -1) {
|
|
182
|
+
const prefix = working.slice(0, colon);
|
|
183
|
+
const rest = working.slice(colon + 1);
|
|
184
|
+
if (prefix.length === 0 || rest.length === 0) {
|
|
185
|
+
return unresolved(input, 'malformed dex namespace');
|
|
186
|
+
}
|
|
187
|
+
if (!knownDexs().has(prefix)) {
|
|
188
|
+
return unresolved(input, `unknown dex namespace "${prefix}"`, [
|
|
189
|
+
{
|
|
190
|
+
assetClass: 'unknown',
|
|
191
|
+
description: `no HIP-3 dex named "${prefix}" in the captured fixtures`,
|
|
192
|
+
venues: [],
|
|
193
|
+
},
|
|
194
|
+
]);
|
|
195
|
+
}
|
|
196
|
+
dex = prefix;
|
|
197
|
+
working = rest;
|
|
198
|
+
applied.push('dex-namespace-strip');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// 2. quote suffix strip (-USD and friends), case insensitive on the suffix only.
|
|
202
|
+
for (const suffix of QUOTE_SUFFIXES) {
|
|
203
|
+
if (working.length > suffix.length && working.toUpperCase().endsWith(suffix)) {
|
|
204
|
+
working = working.slice(0, working.length - suffix.length);
|
|
205
|
+
applied.push('quote-suffix-strip');
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 3. lowercase x suffix strip, allowlist gated so a real ticker ending in a
|
|
211
|
+
// lowercase x is never mangled. Uppercase X is NOT a suffix (see SKHX).
|
|
212
|
+
if (working.endsWith('x')) {
|
|
213
|
+
const base = working.slice(0, -1);
|
|
214
|
+
if (XSTOCK_BASE_SET.has(base)) {
|
|
215
|
+
working = base;
|
|
216
|
+
applied.push('xstock-suffix-strip');
|
|
217
|
+
}
|
|
218
|
+
// Not allowlisted: leave it alone and let the canonical check decide.
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (working.length === 0) {
|
|
222
|
+
return unresolved(input, 'symbol empty after transforms');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 4. venue unique names (pre IPO, baskets) map to themselves.
|
|
226
|
+
if (VENUE_UNIQUE_SET.has(working)) {
|
|
227
|
+
return resolved(trimmed, working, {
|
|
228
|
+
dex,
|
|
229
|
+
applied,
|
|
230
|
+
venueUnique: true,
|
|
231
|
+
crossVenueComparable: false,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// 5. contested tickers: never guessed, require an explicit assetClass.
|
|
236
|
+
if (Object.hasOwn(CONTESTED_SYMBOLS, working)) {
|
|
237
|
+
const candidates = CONTESTED_SYMBOLS[working];
|
|
238
|
+
const asserted = options.assetClass;
|
|
239
|
+
if (typeof asserted !== 'string' || asserted.length === 0) {
|
|
240
|
+
return unresolved(
|
|
241
|
+
input,
|
|
242
|
+
`"${working}" names different underlyings on different venues, ` +
|
|
243
|
+
'caller must assert assetClass',
|
|
244
|
+
candidates,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
const match = candidates.find((c) => c.assetClass === asserted);
|
|
248
|
+
if (!match) {
|
|
249
|
+
return unresolved(
|
|
250
|
+
input,
|
|
251
|
+
`assetClass "${asserted}" matches no known underlying for "${working}"`,
|
|
252
|
+
candidates,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return resolved(trimmed, working, {
|
|
256
|
+
dex,
|
|
257
|
+
applied,
|
|
258
|
+
contested: true,
|
|
259
|
+
crossVenueComparable: false,
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// 6. canonical universe check. This is the fail closed gate.
|
|
264
|
+
if (canonical().has(working)) {
|
|
265
|
+
return resolved(trimmed, working, { dex, applied });
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return unresolved(
|
|
269
|
+
input,
|
|
270
|
+
`"${working}" is not in the canonical universe, refusing to guess`,
|
|
271
|
+
nearMissCandidates(working),
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Suggest canonical symbols a caller might have meant, WITHOUT resolving to them.
|
|
277
|
+
* Suggestions are diagnostic only. They are deliberately not auto applied: that is
|
|
278
|
+
* exactly the fuzzy step that fabricates spreads.
|
|
279
|
+
*/
|
|
280
|
+
function nearMissCandidates(working) {
|
|
281
|
+
const upper = working.toUpperCase();
|
|
282
|
+
const out = [];
|
|
283
|
+
for (const symbol of canonical()) {
|
|
284
|
+
if (symbol === upper) continue;
|
|
285
|
+
if (symbol.startsWith(upper) || upper.startsWith(symbol)) {
|
|
286
|
+
out.push({
|
|
287
|
+
assetClass: 'unknown',
|
|
288
|
+
description: `canonical "${symbol}" shares a prefix, not auto applied`,
|
|
289
|
+
venues: [],
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (out.length >= 5) break;
|
|
293
|
+
}
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const MAX_SCALE = 1000;
|
|
2
|
+
const TEN_THOUSAND = Object.freeze({ mantissa: 10000n, scale: 0 });
|
|
3
|
+
|
|
4
|
+
function assertScale(scale) {
|
|
5
|
+
if (!Number.isSafeInteger(scale) || scale < 0 || scale > MAX_SCALE) {
|
|
6
|
+
throw new RangeError(`scale must be a safe integer from 0 through ${MAX_SCALE}`);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function fixed(mantissa, scale) {
|
|
11
|
+
if (typeof mantissa !== 'bigint') {
|
|
12
|
+
throw new TypeError('mantissa must be a bigint');
|
|
13
|
+
}
|
|
14
|
+
assertScale(scale);
|
|
15
|
+
return Object.freeze({ mantissa, scale });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function assertFixed(value, name = 'value') {
|
|
19
|
+
if (value === null || typeof value !== 'object') {
|
|
20
|
+
throw new TypeError(`${name} must be a fixed point value`);
|
|
21
|
+
}
|
|
22
|
+
if (typeof value.mantissa !== 'bigint') {
|
|
23
|
+
throw new TypeError(`${name}.mantissa must be a bigint`);
|
|
24
|
+
}
|
|
25
|
+
assertScale(value.scale);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function pow10(scale) {
|
|
29
|
+
assertScale(scale);
|
|
30
|
+
return 10n ** BigInt(scale);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parseDecimal(value) {
|
|
34
|
+
if (typeof value !== 'string' || !/^[+-]?\d+(?:\.\d+)?$/.test(value)) {
|
|
35
|
+
throw new TypeError('value must be a plain decimal string');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const negative = value.startsWith('-');
|
|
39
|
+
const unsigned = value[0] === '-' || value[0] === '+' ? value.slice(1) : value;
|
|
40
|
+
const [whole, fraction = ''] = unsigned.split('.');
|
|
41
|
+
const digits = `${whole}${fraction}`;
|
|
42
|
+
const mantissa = BigInt(digits) * (negative ? -1n : 1n);
|
|
43
|
+
|
|
44
|
+
return fixed(mantissa, fraction.length);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function fromScaledInteger(value, scale) {
|
|
48
|
+
assertScale(scale);
|
|
49
|
+
if (typeof value === 'bigint') {
|
|
50
|
+
return fixed(value, scale);
|
|
51
|
+
}
|
|
52
|
+
if (typeof value !== 'string' || !/^[+-]?\d+$/.test(value)) {
|
|
53
|
+
throw new TypeError('value must be an integer string or bigint');
|
|
54
|
+
}
|
|
55
|
+
return fixed(BigInt(value), scale);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function toString(value) {
|
|
59
|
+
assertFixed(value);
|
|
60
|
+
const negative = value.mantissa < 0n;
|
|
61
|
+
const digits = (negative ? -value.mantissa : value.mantissa).toString();
|
|
62
|
+
|
|
63
|
+
if (value.scale === 0) {
|
|
64
|
+
return `${negative ? '-' : ''}${digits}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const padded = digits.padStart(value.scale + 1, '0');
|
|
68
|
+
const splitAt = padded.length - value.scale;
|
|
69
|
+
return `${negative ? '-' : ''}${padded.slice(0, splitAt)}.${padded.slice(splitAt)}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function rescale(value, targetScale) {
|
|
73
|
+
assertFixed(value);
|
|
74
|
+
assertScale(targetScale);
|
|
75
|
+
|
|
76
|
+
if (targetScale === value.scale) {
|
|
77
|
+
return fixed(value.mantissa, value.scale);
|
|
78
|
+
}
|
|
79
|
+
if (targetScale > value.scale) {
|
|
80
|
+
return fixed(value.mantissa * pow10(targetScale - value.scale), targetScale);
|
|
81
|
+
}
|
|
82
|
+
return fixed(value.mantissa / pow10(value.scale - targetScale), targetScale);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function align(left, right) {
|
|
86
|
+
assertFixed(left, 'left');
|
|
87
|
+
assertFixed(right, 'right');
|
|
88
|
+
const scale = Math.max(left.scale, right.scale);
|
|
89
|
+
return [rescale(left, scale), rescale(right, scale), scale];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function add(left, right) {
|
|
93
|
+
const [a, b, scale] = align(left, right);
|
|
94
|
+
return fixed(a.mantissa + b.mantissa, scale);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function sub(left, right) {
|
|
98
|
+
const [a, b, scale] = align(left, right);
|
|
99
|
+
return fixed(a.mantissa - b.mantissa, scale);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function mul(left, right) {
|
|
103
|
+
assertFixed(left, 'left');
|
|
104
|
+
assertFixed(right, 'right');
|
|
105
|
+
const scale = left.scale + right.scale;
|
|
106
|
+
assertScale(scale);
|
|
107
|
+
return fixed(left.mantissa * right.mantissa, scale);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function div(left, right, resultScale = Math.max(left?.scale ?? 0, right?.scale ?? 0)) {
|
|
111
|
+
assertFixed(left, 'left');
|
|
112
|
+
assertFixed(right, 'right');
|
|
113
|
+
assertScale(resultScale);
|
|
114
|
+
if (right.mantissa === 0n) {
|
|
115
|
+
throw new RangeError('division by zero');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const numerator = left.mantissa * pow10(right.scale + resultScale);
|
|
119
|
+
const denominator = right.mantissa * pow10(left.scale);
|
|
120
|
+
return fixed(numerator / denominator, resultScale);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function cmp(left, right) {
|
|
124
|
+
const [a, b] = align(left, right);
|
|
125
|
+
if (a.mantissa < b.mantissa) return -1;
|
|
126
|
+
if (a.mantissa > b.mantissa) return 1;
|
|
127
|
+
return 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function spreadBps(value, reference, resultScale = 8) {
|
|
131
|
+
const delta = sub(value, reference);
|
|
132
|
+
return div(mul(delta, TEN_THOUSAND), reference, resultScale);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function applyBps(value, bps, resultScale = value?.scale ?? 0) {
|
|
136
|
+
assertFixed(value);
|
|
137
|
+
assertFixed(bps, 'bps');
|
|
138
|
+
assertScale(resultScale);
|
|
139
|
+
|
|
140
|
+
const factor = fixed(10000n * pow10(bps.scale) + bps.mantissa, bps.scale);
|
|
141
|
+
return div(mul(value, factor), TEN_THOUSAND, resultScale);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function formatUsd(value) {
|
|
145
|
+
return `$${toString(rescale(value, 2))}`;
|
|
146
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Prepare-only artifact builder for RH Uniswap routes.
|
|
2
|
+
// Emits unsigned transaction descriptors. Contains zero signing code and zero
|
|
3
|
+
// key handling by construction. Refuses quote-only routes and stale quotes.
|
|
4
|
+
|
|
5
|
+
import { quote as rhQuote } from './venues/rh-uniswap.mjs';
|
|
6
|
+
import { getRhPoolState } from './fixtures.mjs';
|
|
7
|
+
|
|
8
|
+
export const FRESHNESS_MS = 120_000;
|
|
9
|
+
|
|
10
|
+
// Uniswap V3 SwapRouter02 style exactInputSingle selector, placeholder encoding.
|
|
11
|
+
// The real calldata builder lands when a full router address is pinned. For v1
|
|
12
|
+
// we emit a structured intent the user wallet / higher layer can encode.
|
|
13
|
+
const V3_ROUTER = '0x0000000000000000000000000000000000000000'; // not yet pinned
|
|
14
|
+
const V4_POOL_MANAGER = '0x84b75b19A3cdf8E2F56d0507d22D442847B2053C';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Prepare an unsigned swap artifact for a RH Uniswap equity pool.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} opts
|
|
20
|
+
* @param {string} opts.symbol
|
|
21
|
+
* @param {'buy'|'sell'} [opts.side]
|
|
22
|
+
* @param {object} [opts.sizeUsd] fixed point
|
|
23
|
+
* @param {number} [opts.nowMs]
|
|
24
|
+
* @param {string} opts.recipient user wallet, required
|
|
25
|
+
*/
|
|
26
|
+
export function prepare(opts = {}) {
|
|
27
|
+
const { symbol, side = 'buy', sizeUsd = null, recipient, nowMs = Date.now() } = opts;
|
|
28
|
+
|
|
29
|
+
if (typeof symbol !== 'string' || !symbol) {
|
|
30
|
+
throw new TypeError('symbol is required');
|
|
31
|
+
}
|
|
32
|
+
if (typeof recipient !== 'string' || !/^0x[0-9a-fA-F]{40}$/.test(recipient)) {
|
|
33
|
+
throw new TypeError('recipient must be a 0x-prefixed 20 byte address');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const q = rhQuote({ symbol, side, sizeUsd });
|
|
37
|
+
if (q === null) {
|
|
38
|
+
throw new Error(`no RH Uniswap pool for ${symbol}`);
|
|
39
|
+
}
|
|
40
|
+
if (q.tier !== 'prepare') {
|
|
41
|
+
throw new Error(`route tier is ${q.tier}, only prepare tier can be prepared`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ageMs = nowMs - q.capturedAt;
|
|
45
|
+
if (ageMs > FRESHNESS_MS) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`quote is stale (${ageMs}ms old, bound ${FRESHNESS_MS}ms); re-quote before preparing`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const state = getRhPoolState();
|
|
52
|
+
const pool = state.pools[symbol];
|
|
53
|
+
const to = pool.version === 'v4' ? V4_POOL_MANAGER : V3_ROUTER;
|
|
54
|
+
|
|
55
|
+
// Approval target is the router/pool manager, NEVER the destination of funds.
|
|
56
|
+
const spender = to;
|
|
57
|
+
const token = side === 'buy' ? pool.quoteAddr : pool.token;
|
|
58
|
+
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
artifactKind: 'unsigned-tx',
|
|
61
|
+
chainId: 4663,
|
|
62
|
+
to,
|
|
63
|
+
data: '0x', // calldata encoding is a follow up; structure is the contract
|
|
64
|
+
value: '0',
|
|
65
|
+
requiresApproval: {
|
|
66
|
+
spender,
|
|
67
|
+
token,
|
|
68
|
+
amount: null, // exact amount filled by the caller from size
|
|
69
|
+
},
|
|
70
|
+
requiresWalletSignature: true,
|
|
71
|
+
backendSigner: false,
|
|
72
|
+
unsigned: true,
|
|
73
|
+
houseSigned: false,
|
|
74
|
+
quoteRef: {
|
|
75
|
+
venue: q.venue,
|
|
76
|
+
symbol: q.symbol,
|
|
77
|
+
symbolRaw: q.symbolRaw,
|
|
78
|
+
capturedAt: q.capturedAt,
|
|
79
|
+
blockOrSeq: q.blockOrSeq,
|
|
80
|
+
mid: q.mid,
|
|
81
|
+
version: pool.version,
|
|
82
|
+
pair: pool.pair,
|
|
83
|
+
},
|
|
84
|
+
quoteAgeMs: ageMs,
|
|
85
|
+
recipient,
|
|
86
|
+
side,
|
|
87
|
+
notes: [
|
|
88
|
+
'prepare-only: user wallet must sign',
|
|
89
|
+
'calldata encoding is deferred; this artifact is the bound intent',
|
|
90
|
+
pool.version === 'v4'
|
|
91
|
+
? 'V4 route via PoolManager'
|
|
92
|
+
: 'V3 route via SwapRouter (address not yet pinned)',
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
}
|