@oracle-agent/oracle 0.11.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 +66 -84
- 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/index.html +11 -1
- package/CONTRIBUTING.md +0 -98
- package/bin/desk-server.mjs +0 -440
- package/bin/oracle-data-mcp.mjs +0 -1019
- 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 -138
- 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 -151
- package/docs/public-surface.md +0 -133
- 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 -123
- 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 -265
- 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 -75
- package/src/cli/commands/doctor.mjs +0 -136
- 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 -585
- package/src/data/desk-data.mjs +0 -695
- 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 -225
- 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-venues.mjs +0 -119
- package/src/data/providers/jupiter.mjs +0 -315
- package/src/data/providers/lifi.mjs +0 -151
- package/src/data/providers/magiceden-sol.mjs +0 -406
- package/src/data/providers/morpho.mjs +0 -177
- 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 -188
- 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 -341
- package/src/data/providers/signed-material-guard.mjs +0 -108
- package/src/data/providers/solana-rpc.mjs +0 -197
- package/src/data/providers/uniswap-v3.mjs +0 -349
- package/src/data/providers/uniswap-v4.mjs +0 -414
- 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 -204
- 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 -398
- package/src/router/proposal.mjs +0 -311
- package/src/router/risk-classifier.mjs +0 -119
- package/src/router/route-sources.mjs +0 -364
- 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
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
// OpenSea NFT floors — uses OPENSEA_API_KEY from env or ~/.config/locals-only/opensea.env
|
|
2
|
-
|
|
3
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
4
|
-
import { getAddress } from "ethers";
|
|
5
|
-
import { httpJson } from "../http.mjs";
|
|
6
|
-
import { resolveProviderEndpoint, credentialedHeaders } from "../provider-endpoint.mjs";
|
|
7
|
-
import { stampPrepared } from "../../prepare-envelope.mjs";
|
|
8
|
-
|
|
9
|
-
export const OPENSEA_API = "https://api.opensea.io/api/v2";
|
|
10
|
-
|
|
11
|
-
export const OPENSEA_ACCOUNT_CHAINS = Object.freeze([
|
|
12
|
-
"blast",
|
|
13
|
-
"base",
|
|
14
|
-
"ethereum",
|
|
15
|
-
"zora",
|
|
16
|
-
"arbitrum",
|
|
17
|
-
"sei",
|
|
18
|
-
"avalanche",
|
|
19
|
-
"polygon",
|
|
20
|
-
"optimism",
|
|
21
|
-
"ape_chain",
|
|
22
|
-
"flow",
|
|
23
|
-
"b3",
|
|
24
|
-
"soneium",
|
|
25
|
-
"ronin",
|
|
26
|
-
"bera_chain",
|
|
27
|
-
"solana",
|
|
28
|
-
"shape",
|
|
29
|
-
"unichain",
|
|
30
|
-
"gunzilla",
|
|
31
|
-
"abstract",
|
|
32
|
-
"animechain",
|
|
33
|
-
"hyperevm",
|
|
34
|
-
"somnia",
|
|
35
|
-
"monad",
|
|
36
|
-
"hyperliquid",
|
|
37
|
-
"megaeth",
|
|
38
|
-
"ink",
|
|
39
|
-
"robinhood",
|
|
40
|
-
"stablechain",
|
|
41
|
-
]);
|
|
42
|
-
|
|
43
|
-
const OPENSEA_CHAIN_SET = new Set(OPENSEA_ACCOUNT_CHAINS);
|
|
44
|
-
const OPENSEA_NON_EVM_CHAINS = new Set(["solana", "flow"]);
|
|
45
|
-
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
46
|
-
|
|
47
|
-
function loadKeyFromDisk() {
|
|
48
|
-
const p = process.env.OPENSEA_ENV_FILE || `${process.env.HOME || ""}/.config/locals-only/opensea.env`;
|
|
49
|
-
if (!existsSync(p)) return "";
|
|
50
|
-
try {
|
|
51
|
-
for (const ln of readFileSync(p, "utf8").split("\n")) {
|
|
52
|
-
const m = ln.match(/^\s*OPENSEA_API_KEY\s*=\s*(.+)\s*$/);
|
|
53
|
-
if (m) return m[1].replace(/^["']|["']$/g, "").trim();
|
|
54
|
-
}
|
|
55
|
-
} catch {
|
|
56
|
-
/* ignore */
|
|
57
|
-
}
|
|
58
|
-
return "";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function apiKey(opts = {}) {
|
|
62
|
-
return opts.apiKey || process.env.OPENSEA_API_KEY || process.env.OPEN_SEA_API_KEY || loadKeyFromDisk();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function endpoint(opts = {}) {
|
|
66
|
-
return resolveProviderEndpoint({
|
|
67
|
-
provider: "opensea",
|
|
68
|
-
defaultUrl: OPENSEA_API,
|
|
69
|
-
hosts: ["api.opensea.io", "testnets-api.opensea.io"],
|
|
70
|
-
url: opts.baseUrl || process.env.OPENSEA_API_URL,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function base(opts = {}) {
|
|
75
|
-
return endpoint(opts).baseUrl;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function headers(opts = {}) {
|
|
79
|
-
// x-api-key is attached only for a pinned OpenSea host.
|
|
80
|
-
return credentialedHeaders({ accept: "application/json" }, { "x-api-key": apiKey(opts) }, endpoint(opts).trusted);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function accountChain(value) {
|
|
84
|
-
const chain = String(value || "ethereum").trim().toLowerCase();
|
|
85
|
-
if (!OPENSEA_CHAIN_SET.has(chain)) throw new Error(`opensea: unsupported account chain ${chain}`);
|
|
86
|
-
return chain;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function evmAddress(value, label = "address") {
|
|
90
|
-
try {
|
|
91
|
-
return getAddress(String(value || "").trim().toLowerCase());
|
|
92
|
-
} catch {
|
|
93
|
-
throw new Error(`opensea: invalid ${label}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function accountAddress(value, chain = null) {
|
|
98
|
-
const address = String(value || "").trim();
|
|
99
|
-
if (!address) throw new Error("opensea: account address required");
|
|
100
|
-
if (chain && !OPENSEA_NON_EVM_CHAINS.has(chain)) return evmAddress(address, "account address");
|
|
101
|
-
if (!chain && /^0x[0-9a-fA-F]{40}$/.test(address)) return evmAddress(address, "account address");
|
|
102
|
-
if (!/^[1-9A-HJ-NP-Za-km-z]{32,64}$/.test(address)) throw new Error("opensea: invalid account address");
|
|
103
|
-
return address;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function positiveDecimal(value, label) {
|
|
107
|
-
const text = String(value ?? "").trim();
|
|
108
|
-
if (!/^(?:0|[1-9]\d*)(?:\.\d+)?$/.test(text) || Number(text) <= 0) {
|
|
109
|
-
throw new Error(`opensea: ${label} must be a positive plain decimal`);
|
|
110
|
-
}
|
|
111
|
-
return text;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function positiveInteger(value, label) {
|
|
115
|
-
const n = Number(value);
|
|
116
|
-
if (!Number.isSafeInteger(n) || n <= 0) throw new Error(`opensea: ${label} must be a positive integer`);
|
|
117
|
-
return n;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function isoTime(value, label) {
|
|
121
|
-
const text = String(value || "").trim();
|
|
122
|
-
const ms = Date.parse(text);
|
|
123
|
-
if (!text || !Number.isFinite(ms)) throw new Error(`opensea: ${label} must be an ISO 8601 timestamp`);
|
|
124
|
-
return { text: new Date(ms).toISOString(), ms };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function normalizeAccountNft(raw = {}, chain, owner) {
|
|
128
|
-
return {
|
|
129
|
-
chain,
|
|
130
|
-
owner,
|
|
131
|
-
contract: raw.contract || null,
|
|
132
|
-
tokenId: raw.identifier == null ? null : String(raw.identifier),
|
|
133
|
-
tokenStandard: raw.token_standard || null,
|
|
134
|
-
collection: raw.collection || null,
|
|
135
|
-
name: raw.name || null,
|
|
136
|
-
description: raw.description || null,
|
|
137
|
-
imageUrl: raw.display_image_url || raw.image_url || raw.original_image_url || null,
|
|
138
|
-
originalImageUrl: raw.original_image_url || raw.image_url || null,
|
|
139
|
-
animationUrl: raw.display_animation_url || raw.original_animation_url || null,
|
|
140
|
-
metadataUrl: raw.metadata_url || null,
|
|
141
|
-
marketplaceUrl: raw.opensea_url || null,
|
|
142
|
-
estimatedValueUsd: raw.estimated_value_usd != null && Number.isFinite(Number(raw.estimated_value_usd))
|
|
143
|
-
? Number(raw.estimated_value_usd)
|
|
144
|
-
: null,
|
|
145
|
-
spam: raw.is_disabled === true || raw.is_nsfw === true,
|
|
146
|
-
disabled: raw.is_disabled === true,
|
|
147
|
-
nsfw: raw.is_nsfw === true,
|
|
148
|
-
traits: Array.isArray(raw.traits) ? raw.traits : [],
|
|
149
|
-
updatedAt: raw.updated_at || null,
|
|
150
|
-
acquisitionCost: null,
|
|
151
|
-
itemPnl: {
|
|
152
|
-
status: "unavailable",
|
|
153
|
-
reason: "OpenSea account inventory does not expose trustworthy per-item acquisition cost",
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Shared request context for the multichain scanner. */
|
|
159
|
-
export function openseaContext(opts = {}) {
|
|
160
|
-
return {
|
|
161
|
-
base: base(opts),
|
|
162
|
-
headers: headers(opts),
|
|
163
|
-
fetchImpl: opts.fetchImpl,
|
|
164
|
-
timeoutMs: opts.timeoutMs,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function openseaHealth(opts = {}) {
|
|
169
|
-
if (!apiKey(opts)) {
|
|
170
|
-
return { ok: false, configured: false, error: "OPENSEA_API_KEY not set" };
|
|
171
|
-
}
|
|
172
|
-
try {
|
|
173
|
-
const c = await openseaCollection("boredapeyachtclub", opts);
|
|
174
|
-
return { ok: true, configured: true, name: c.name || c.collection };
|
|
175
|
-
} catch (e) {
|
|
176
|
-
return { ok: false, configured: true, error: String(e.message || e).slice(0, 160) };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export async function openseaCollection(slug, opts = {}) {
|
|
181
|
-
if (!slug) throw new Error("collection slug required");
|
|
182
|
-
if (!apiKey(opts)) throw new Error("OPENSEA_API_KEY required");
|
|
183
|
-
return httpJson(`${base(opts)}/collections/${encodeURIComponent(slug)}`, {
|
|
184
|
-
headers: headers(opts),
|
|
185
|
-
fetchImpl: opts.fetchImpl,
|
|
186
|
-
timeoutMs: opts.timeoutMs ?? 15_000,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Best-effort floor from collection stats / collection payload. */
|
|
191
|
-
export async function openseaFloor(slug, opts = {}) {
|
|
192
|
-
const c = await openseaCollection(slug, opts);
|
|
193
|
-
const stats = c.stats || c.total || {};
|
|
194
|
-
const floor =
|
|
195
|
-
c.floor_price ??
|
|
196
|
-
c.floorPrice ??
|
|
197
|
-
stats.floor_price ??
|
|
198
|
-
stats.floorPrice ??
|
|
199
|
-
null;
|
|
200
|
-
return {
|
|
201
|
-
slug: c.collection || slug,
|
|
202
|
-
name: c.name || null,
|
|
203
|
-
floor,
|
|
204
|
-
totalSupply: c.total_supply ?? stats.total_supply ?? null,
|
|
205
|
-
numOwners: c.num_owners ?? stats.num_owners ?? null,
|
|
206
|
-
raw: {
|
|
207
|
-
contracts: c.contracts,
|
|
208
|
-
fees: c.fees,
|
|
209
|
-
category: c.category,
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/** Paginated account NFT inventory for one OpenSea-supported chain. */
|
|
215
|
-
export async function openseaAccountNfts(args = {}, opts = {}) {
|
|
216
|
-
if (!apiKey(opts)) throw new Error("OPENSEA_API_KEY required");
|
|
217
|
-
const chain = accountChain(args.chain);
|
|
218
|
-
const owner = accountAddress(args.address || args.owner, chain);
|
|
219
|
-
const pageSize = Math.min(Math.max(Number(args.pageSize ?? args.limit ?? 200) || 200, 1), 200);
|
|
220
|
-
const maxPages = Math.min(Math.max(Number(args.maxPages ?? 5) || 5, 1), 25);
|
|
221
|
-
const nfts = [];
|
|
222
|
-
let next = args.next ? String(args.next) : null;
|
|
223
|
-
let pages = 0;
|
|
224
|
-
|
|
225
|
-
do {
|
|
226
|
-
const url = new URL(`${base(opts)}/chain/${encodeURIComponent(chain)}/account/${encodeURIComponent(owner)}/nfts`);
|
|
227
|
-
url.searchParams.set("limit", String(pageSize));
|
|
228
|
-
if (args.collection) url.searchParams.set("collection", String(args.collection));
|
|
229
|
-
if (next) url.searchParams.set("next", next);
|
|
230
|
-
const raw = await httpJson(url.toString(), {
|
|
231
|
-
headers: headers(opts),
|
|
232
|
-
fetchImpl: opts.fetchImpl,
|
|
233
|
-
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
234
|
-
});
|
|
235
|
-
for (const item of Array.isArray(raw?.nfts) ? raw.nfts : []) {
|
|
236
|
-
nfts.push(normalizeAccountNft(item, chain, owner));
|
|
237
|
-
}
|
|
238
|
-
next = raw?.next ? String(raw.next) : null;
|
|
239
|
-
pages += 1;
|
|
240
|
-
} while (next && pages < maxPages);
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
provider: "opensea-nft",
|
|
244
|
-
source: "opensea-account-inventory",
|
|
245
|
-
chain,
|
|
246
|
-
owner,
|
|
247
|
-
count: nfts.length,
|
|
248
|
-
pages,
|
|
249
|
-
complete: !next,
|
|
250
|
-
next,
|
|
251
|
-
nfts,
|
|
252
|
-
exec: false,
|
|
253
|
-
readOnly: true,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/** OpenSea-indexed account PnL. This is account-level, not per-NFT cost basis. */
|
|
258
|
-
export async function openseaAccountPnl(args = {}, opts = {}) {
|
|
259
|
-
if (!apiKey(opts)) throw new Error("OPENSEA_API_KEY required");
|
|
260
|
-
const address = accountAddress(args.address || args.owner);
|
|
261
|
-
const raw = await httpJson(`${base(opts)}/account/${encodeURIComponent(address)}/pnl`, {
|
|
262
|
-
headers: headers(opts),
|
|
263
|
-
fetchImpl: opts.fetchImpl,
|
|
264
|
-
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
265
|
-
});
|
|
266
|
-
return {
|
|
267
|
-
provider: "opensea-nft",
|
|
268
|
-
source: "opensea-indexed-account-pnl",
|
|
269
|
-
address,
|
|
270
|
-
scope: "OpenSea-indexed account trading PnL across supported currencies, not per-item NFT cost basis",
|
|
271
|
-
methodology: "provider-indexed",
|
|
272
|
-
realizedPnlUsd: raw?.realized_pnl_usd ?? null,
|
|
273
|
-
unrealizedPnlUsd: raw?.unrealized_pnl_usd ?? null,
|
|
274
|
-
totalPnlUsd: raw?.total_pnl_usd ?? null,
|
|
275
|
-
netInvestedUsd: raw?.net_invested_usd ?? null,
|
|
276
|
-
currentValueUsd: raw?.current_value_usd ?? null,
|
|
277
|
-
returnPercentage: raw?.return_percentage ?? null,
|
|
278
|
-
itemLevelPnlAvailable: false,
|
|
279
|
-
raw,
|
|
280
|
-
exec: false,
|
|
281
|
-
readOnly: true,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function normalizeListingItem(raw = {}) {
|
|
286
|
-
const chain = accountChain(raw.chain);
|
|
287
|
-
if (OPENSEA_NON_EVM_CHAINS.has(chain)) {
|
|
288
|
-
throw new Error("opensea: listing actions currently require an EVM NFT chain");
|
|
289
|
-
}
|
|
290
|
-
const start = raw.startTime || raw.start_time
|
|
291
|
-
? isoTime(raw.startTime || raw.start_time, "startTime")
|
|
292
|
-
: { text: new Date().toISOString(), ms: Date.now() };
|
|
293
|
-
const end = isoTime(raw.endTime || raw.end_time, "endTime");
|
|
294
|
-
if (end.ms <= start.ms) throw new Error("opensea: endTime must be after startTime");
|
|
295
|
-
const tokenId = String(raw.tokenId ?? raw.token_id ?? "").trim();
|
|
296
|
-
if (!/^\d+$/.test(tokenId)) throw new Error("opensea: tokenId must be an unsigned integer string");
|
|
297
|
-
return {
|
|
298
|
-
chain,
|
|
299
|
-
contract: evmAddress(raw.contract, "NFT contract"),
|
|
300
|
-
token_id: tokenId,
|
|
301
|
-
quantity: positiveInteger(raw.quantity ?? 1, "quantity"),
|
|
302
|
-
price: {
|
|
303
|
-
amount: positiveDecimal(raw.price?.amount ?? raw.amount ?? raw.priceAmount, "price amount"),
|
|
304
|
-
currency: evmAddress(raw.price?.currency ?? raw.currency ?? ZERO_ADDRESS, "price currency"),
|
|
305
|
-
},
|
|
306
|
-
start_time: start.text,
|
|
307
|
-
end_time: end.text,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function containsApprovalStep(steps = []) {
|
|
312
|
-
return steps.some((step) => /approv|setapprovalforall/i.test(JSON.stringify(step)));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Ask OpenSea for approval and Seaport signing actions. Nothing is signed,
|
|
317
|
-
* submitted, or broadcast. The user's wallet handles every returned action.
|
|
318
|
-
*/
|
|
319
|
-
export async function openseaPrepareList(args = {}, opts = {}) {
|
|
320
|
-
if (!apiKey(opts)) throw new Error("OPENSEA_API_KEY required");
|
|
321
|
-
if (args.userConfirmed !== true) {
|
|
322
|
-
throw new Error("opensea: userConfirmed=true required after NFT, marketplace, price, currency, and expiry review");
|
|
323
|
-
}
|
|
324
|
-
const seller = evmAddress(args.seller || args.address || args.owner, "seller");
|
|
325
|
-
const sourceItems = Array.isArray(args.items) && args.items.length ? args.items : [args];
|
|
326
|
-
if (sourceItems.length > 50) throw new Error("opensea: at most 50 listing items per preparation");
|
|
327
|
-
const items = sourceItems.map(normalizeListingItem);
|
|
328
|
-
const chains = new Set(items.map((item) => item.chain));
|
|
329
|
-
if (chains.size !== 1) throw new Error("opensea: all prepared listing items must be on one chain");
|
|
330
|
-
const useCreatorFee = args.useCreatorFee !== false;
|
|
331
|
-
const request = {
|
|
332
|
-
address: seller,
|
|
333
|
-
items,
|
|
334
|
-
use_creator_fee: useCreatorFee,
|
|
335
|
-
};
|
|
336
|
-
if (args.taker) request.taker = evmAddress(args.taker, "taker");
|
|
337
|
-
|
|
338
|
-
const raw = await httpJson(`${base(opts)}/listings/actions`, {
|
|
339
|
-
method: "POST",
|
|
340
|
-
headers: headers(opts),
|
|
341
|
-
body: request,
|
|
342
|
-
fetchImpl: opts.fetchImpl,
|
|
343
|
-
timeoutMs: opts.timeoutMs ?? 25_000,
|
|
344
|
-
retries: 0,
|
|
345
|
-
dedupe: false,
|
|
346
|
-
});
|
|
347
|
-
const steps = Array.isArray(raw?.steps) ? raw.steps : [];
|
|
348
|
-
if (!steps.length) throw new Error("opensea: listing action response contained no wallet steps");
|
|
349
|
-
|
|
350
|
-
return stampPrepared({
|
|
351
|
-
provider: "opensea-nft",
|
|
352
|
-
marketplace: "opensea",
|
|
353
|
-
chain: items[0].chain,
|
|
354
|
-
kind: "nft-list-actions",
|
|
355
|
-
prepareReady: true,
|
|
356
|
-
executionReady: false,
|
|
357
|
-
signingReady: false,
|
|
358
|
-
broadcastReady: false,
|
|
359
|
-
requiresUserSignature: true,
|
|
360
|
-
requiresSeparateApproval: containsApprovalStep(steps),
|
|
361
|
-
seller,
|
|
362
|
-
items,
|
|
363
|
-
useCreatorFee,
|
|
364
|
-
taker: request.taker || null,
|
|
365
|
-
feeDisclosure: useCreatorFee
|
|
366
|
-
? "Creator fees requested. Inspect the returned Seaport consideration recipients and wallet simulation before signing."
|
|
367
|
-
: "Creator fees disabled by explicit request. Marketplace protocol fees may still apply and must be inspected before signing.",
|
|
368
|
-
steps,
|
|
369
|
-
note: "Execute approvals separately, then sign the Seaport order in the user's wallet. Oracle does not submit or broadcast the listing.",
|
|
370
|
-
});
|
|
371
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// ParaSwap/Velora public market API — keyless price routes, quote-only here.
|
|
2
|
-
import { httpJson } from "../http.mjs";
|
|
3
|
-
import { attachAutoSlippage, bindAutoSlippageGuardToCall } from "../../auto-slippage.mjs";
|
|
4
|
-
import { stampPrepared } from "../../prepare-envelope.mjs";
|
|
5
|
-
|
|
6
|
-
export const PARASWAP_API = "https://api.paraswap.io";
|
|
7
|
-
const base = (o = {}) => (o.baseUrl || process.env.PARASWAP_API_URL || PARASWAP_API).replace(/\/$/, "");
|
|
8
|
-
function token(value, name) {
|
|
9
|
-
const s = String(value || "");
|
|
10
|
-
if (!/^0x[0-9a-fA-F]{40}$/.test(s)) throw new Error(`${name} must be a 20-byte token address`);
|
|
11
|
-
return s.toLowerCase();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function paraswapTokens(args = {}, opts = {}) {
|
|
15
|
-
const chainId = Number(args.chainId || 1);
|
|
16
|
-
return httpJson(`${base(opts)}/tokens/${chainId}`, { fetchImpl: opts.fetchImpl, timeoutMs: opts.timeoutMs });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function paraswapPrice(args = {}, opts = {}) {
|
|
20
|
-
const chainId = Number(args.chainId || args.network || 1);
|
|
21
|
-
if (args.amount == null) throw new Error("amount required");
|
|
22
|
-
const params = new URLSearchParams({
|
|
23
|
-
srcToken: token(args.srcToken, "srcToken"),
|
|
24
|
-
destToken: token(args.destToken, "destToken"),
|
|
25
|
-
amount: String(args.amount),
|
|
26
|
-
srcDecimals: String(Number(args.srcDecimals)),
|
|
27
|
-
destDecimals: String(Number(args.destDecimals)),
|
|
28
|
-
side: String(args.side || "SELL").toUpperCase(),
|
|
29
|
-
network: String(chainId),
|
|
30
|
-
version: String(args.version || "6.2"),
|
|
31
|
-
});
|
|
32
|
-
if (args.includeDEXS) params.set("includeDEXS", String(args.includeDEXS));
|
|
33
|
-
if (args.excludeDEXS) params.set("excludeDEXS", String(args.excludeDEXS));
|
|
34
|
-
const result = await httpJson(`${base(opts)}/prices?${params}`, {
|
|
35
|
-
fetchImpl: opts.fetchImpl,
|
|
36
|
-
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
37
|
-
});
|
|
38
|
-
const amountOut = result?.priceRoute?.destAmount;
|
|
39
|
-
if (!amountOut) return { ...result, executionReady: false };
|
|
40
|
-
return {
|
|
41
|
-
...attachAutoSlippage(result, {
|
|
42
|
-
chainId,
|
|
43
|
-
venue: result?.priceRoute?.contractAddress || "paraswap-quote",
|
|
44
|
-
amountOut,
|
|
45
|
-
liquidityUsd: args.liquidityUsd,
|
|
46
|
-
priceChange5m: args.priceChange5m,
|
|
47
|
-
quoteAgeMs: 0,
|
|
48
|
-
requestedCapBps: args.maxSlippageBps ?? args.slippageBps,
|
|
49
|
-
}),
|
|
50
|
-
executionReady: false,
|
|
51
|
-
executionBlocker: "call prepare to bind the price route to a validated transaction",
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function paraswapPrepare(args = {}, opts = {}) {
|
|
56
|
-
if (String(args.side || "SELL").toUpperCase() !== "SELL") {
|
|
57
|
-
throw new Error("paraswap: agentic prepare currently supports exact-input SELL only");
|
|
58
|
-
}
|
|
59
|
-
const chainId = Number(args.chainId || args.network || 1);
|
|
60
|
-
const userAddress = token(args.userAddress, "userAddress");
|
|
61
|
-
const quote = await paraswapPrice(args, opts);
|
|
62
|
-
const priceRoute = quote?.priceRoute;
|
|
63
|
-
const expectedTarget = String(priceRoute?.contractAddress || "").toLowerCase();
|
|
64
|
-
if (!expectedTarget) throw new Error("paraswap: price route missing contractAddress");
|
|
65
|
-
const body = {
|
|
66
|
-
srcToken: token(args.srcToken, "srcToken"),
|
|
67
|
-
destToken: token(args.destToken, "destToken"),
|
|
68
|
-
srcAmount: String(priceRoute.srcAmount || args.amount),
|
|
69
|
-
// ParaSwap treats destAmount as the on-chain minimum for SELL routes.
|
|
70
|
-
destAmount: String(quote.amountOutMinimum),
|
|
71
|
-
priceRoute,
|
|
72
|
-
userAddress,
|
|
73
|
-
ignoreChecks: false,
|
|
74
|
-
ignoreGasEstimate: false,
|
|
75
|
-
};
|
|
76
|
-
if (args.receiver) body.receiver = token(args.receiver, "receiver");
|
|
77
|
-
const tx = await httpJson(`${base(opts)}/transactions/${chainId}`, {
|
|
78
|
-
method: "POST",
|
|
79
|
-
body,
|
|
80
|
-
fetchImpl: opts.fetchImpl,
|
|
81
|
-
timeoutMs: opts.timeoutMs ?? 25_000,
|
|
82
|
-
});
|
|
83
|
-
if (Number(tx.chainId ?? chainId) !== chainId) throw new Error("paraswap: transaction chain mismatch");
|
|
84
|
-
if (String(tx.to || "").toLowerCase() !== expectedTarget) throw new Error("paraswap: transaction target mismatch");
|
|
85
|
-
if (tx.from && String(tx.from).toLowerCase() !== userAddress) throw new Error("paraswap: transaction sender mismatch");
|
|
86
|
-
return stampPrepared({
|
|
87
|
-
provider: "paraswap",
|
|
88
|
-
calldataReady: true,
|
|
89
|
-
// NOT executable authority. The bytes are assembled but nothing is signed:
|
|
90
|
-
// the user's wallet is still the only thing that can authorize this. The
|
|
91
|
-
// previous `executionReady: true` read as "cleared to execute" and trained
|
|
92
|
-
// agents to treat a quote as permission.
|
|
93
|
-
requiresUserSignature: true,
|
|
94
|
-
signingReady: false,
|
|
95
|
-
broadcastReady: false,
|
|
96
|
-
chainId,
|
|
97
|
-
quote,
|
|
98
|
-
autoSlippage: quote.autoSlippage,
|
|
99
|
-
requiresApproval: body.srcToken !== "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
|
|
100
|
-
? { token: body.srcToken, spender: priceRoute.tokenTransferProxy || expectedTarget, amount: body.srcAmount }
|
|
101
|
-
: null,
|
|
102
|
-
transaction: {
|
|
103
|
-
chainId,
|
|
104
|
-
from: tx.from || userAddress,
|
|
105
|
-
to: tx.to,
|
|
106
|
-
data: tx.data,
|
|
107
|
-
value: tx.value ?? "0x0",
|
|
108
|
-
...(tx.gas != null ? { gasLimit: tx.gas } : {}),
|
|
109
|
-
slippageGuard: bindAutoSlippageGuardToCall(quote.autoSlippage, { chainId, venue: tx.to, data: tx.data }),
|
|
110
|
-
},
|
|
111
|
-
}, { provider: "paraswap", kind: "paraswap-tx" });
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function paraswapHealth(opts = {}) {
|
|
115
|
-
const data = await paraswapTokens({ chainId: 1 }, opts);
|
|
116
|
-
const count = Array.isArray(data?.tokens) ? data.tokens.length : Object.keys(data?.tokens || {}).length;
|
|
117
|
-
return { ok: count > 0, tokenSample: count };
|
|
118
|
-
}
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// Pendle public core API — markets and Hosted SDK Convert tx builder, no key.
|
|
2
|
-
import { getAddress } from "ethers";
|
|
3
|
-
import { httpJson } from "../http.mjs";
|
|
4
|
-
import { attachAutoSlippage, bindAutoSlippageGuardToCall, resolveAutoSlippage } from "../../auto-slippage.mjs";
|
|
5
|
-
import { stampPrepared } from "../../prepare-envelope.mjs";
|
|
6
|
-
|
|
7
|
-
export const PENDLE_API = "https://api-v2.pendle.finance/core";
|
|
8
|
-
|
|
9
|
-
// Official Pendle Router from deployment docs. Bytecode checked via eth_getCode
|
|
10
|
-
// on Arbitrum/Base 2026-07-23.
|
|
11
|
-
export const PENDLE_ROUTER_BY_CHAIN = Object.freeze({
|
|
12
|
-
42161: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
13
|
-
8453: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const ZERO = "0x0000000000000000000000000000000000000000";
|
|
17
|
-
const NATIVE = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
18
|
-
|
|
19
|
-
const base = (o = {}) => (o.baseUrl || process.env.PENDLE_API_URL || PENDLE_API).replace(/\/$/, "");
|
|
20
|
-
|
|
21
|
-
function checksum(value, label) {
|
|
22
|
-
try {
|
|
23
|
-
return getAddress(value);
|
|
24
|
-
} catch {
|
|
25
|
-
throw new Error(`${label} must be a valid EVM address`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function normal(value, label) {
|
|
30
|
-
return checksum(value, label).toLowerCase();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isNative(value) {
|
|
34
|
-
const v = String(value || "").toLowerCase();
|
|
35
|
-
return v === "native" || v === "eth" || v === NATIVE || v === ZERO;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function amountString(value, label) {
|
|
39
|
-
let amount;
|
|
40
|
-
try {
|
|
41
|
-
amount = BigInt(String(value));
|
|
42
|
-
} catch {
|
|
43
|
-
throw new Error(`${label} must be an integer string`);
|
|
44
|
-
}
|
|
45
|
-
if (amount <= 0n) throw new Error(`${label} must be positive`);
|
|
46
|
-
return amount.toString();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function normalizeInputs(inputs) {
|
|
50
|
-
if (!Array.isArray(inputs) || inputs.length === 0) throw new Error("pendle convert requires inputs[]");
|
|
51
|
-
return inputs.map((input, i) => ({
|
|
52
|
-
token: checksum(input.token, `pendle input ${i} token`),
|
|
53
|
-
amount: amountString(input.amount, `pendle input ${i} amount`),
|
|
54
|
-
}));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function normalizeOutputs(outputs) {
|
|
58
|
-
if (!Array.isArray(outputs) || outputs.length === 0) throw new Error("pendle convert requires outputs[]");
|
|
59
|
-
return outputs.map((token, i) => checksum(token, `pendle output ${i} token`));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function routerFor(chainId) {
|
|
63
|
-
const router = PENDLE_ROUTER_BY_CHAIN[Number(chainId)];
|
|
64
|
-
if (!router) throw new Error(`Pendle prepare not enabled for chainId ${chainId}`);
|
|
65
|
-
return router;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function firstOutputAmount(result) {
|
|
69
|
-
const amount = result?.routes?.[0]?.outputs?.[0]?.amount || result?.outputs?.[0]?.amount;
|
|
70
|
-
if (!amount) throw new Error("Pendle convert response missing output amount");
|
|
71
|
-
return amountString(amount, "pendle output amount");
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function normalizeRequiredApprovals(requiredApprovals, spender) {
|
|
75
|
-
const approvals = (Array.isArray(requiredApprovals) ? requiredApprovals : [])
|
|
76
|
-
.filter((approval) => approval?.token && approval?.amount && !isNative(approval.token))
|
|
77
|
-
.map((approval) => ({
|
|
78
|
-
token: normal(approval.token, "pendle approval token"),
|
|
79
|
-
spender: normal(spender, "pendle approval spender"),
|
|
80
|
-
amount: amountString(approval.amount, "pendle approval amount"),
|
|
81
|
-
}));
|
|
82
|
-
if (!approvals.length) return null;
|
|
83
|
-
return approvals.length === 1 ? approvals[0] : approvals;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function pendleMarkets(args = {}, opts = {}) {
|
|
87
|
-
const chainId = Number(args.chainId || 42161);
|
|
88
|
-
const p = new URLSearchParams({
|
|
89
|
-
limit: String(Math.min(100, Math.max(1, Number(args.limit || 20)))),
|
|
90
|
-
skip: String(Math.max(0, Number(args.skip || 0))),
|
|
91
|
-
});
|
|
92
|
-
if (args.isExpired != null) p.set("isExpired", String(Boolean(args.isExpired)));
|
|
93
|
-
return httpJson(`${base(opts)}/v1/${chainId}/markets?${p}`, {
|
|
94
|
-
fetchImpl: opts.fetchImpl,
|
|
95
|
-
timeoutMs: opts.timeoutMs,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export async function pendleHealth(opts = {}) {
|
|
100
|
-
const data = await pendleMarkets({ chainId: 42161, limit: 1 }, opts);
|
|
101
|
-
return { ok: Array.isArray(data?.results), marketSample: data?.results?.length || 0 };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function pendlePrepare(q = {}, opts = {}) {
|
|
105
|
-
const chainId = Number(q.chainId ?? 42161);
|
|
106
|
-
const router = routerFor(chainId);
|
|
107
|
-
const from = q.from || q.fromAddress || q.userAddress || q.taker || q.receiver;
|
|
108
|
-
if (!from) throw new Error("pendlePrepare requires from/receiver");
|
|
109
|
-
const receiver = checksum(q.receiver || from, "pendle receiver");
|
|
110
|
-
const inputs = normalizeInputs(q.inputs);
|
|
111
|
-
const outputs = normalizeOutputs(q.outputs);
|
|
112
|
-
if (q.enableAggregator === true || (Array.isArray(q.aggregators) && q.aggregators.length)) {
|
|
113
|
-
throw new Error("Pendle aggregator paths are disabled by policy; use direct convert only");
|
|
114
|
-
}
|
|
115
|
-
const selected = resolveAutoSlippage({
|
|
116
|
-
liquidityUsd: q.liquidityUsd,
|
|
117
|
-
priceChange5m: q.priceChange5m,
|
|
118
|
-
requestedCapBps: q.maxSlippageBps ?? q.slippageBps,
|
|
119
|
-
});
|
|
120
|
-
if (!selected.executable) {
|
|
121
|
-
throw new Error(`Pendle: route requires ${selected.requiredBps} bps above cap ${selected.capBps}`);
|
|
122
|
-
}
|
|
123
|
-
const body = {
|
|
124
|
-
receiver,
|
|
125
|
-
slippage: selected.selectedBps / 10_000,
|
|
126
|
-
enableAggregator: false,
|
|
127
|
-
useLimitOrder: false,
|
|
128
|
-
inputs,
|
|
129
|
-
outputs,
|
|
130
|
-
...(q.redeemRewards != null ? { redeemRewards: Boolean(q.redeemRewards) } : {}),
|
|
131
|
-
...(q.needScale != null ? { needScale: Boolean(q.needScale) } : {}),
|
|
132
|
-
...(q.additionalData ? { additionalData: String(q.additionalData) } : {}),
|
|
133
|
-
};
|
|
134
|
-
const raw = await httpJson(`${base(opts)}/v3/sdk/${chainId}/convert`, {
|
|
135
|
-
method: "POST",
|
|
136
|
-
body,
|
|
137
|
-
fetchImpl: opts.fetchImpl,
|
|
138
|
-
timeoutMs: opts.timeoutMs ?? 25_000,
|
|
139
|
-
});
|
|
140
|
-
const route = raw?.routes?.[0];
|
|
141
|
-
const tx = route?.tx;
|
|
142
|
-
if (!tx?.to || !tx?.data) throw new Error("Pendle convert returned no executable tx");
|
|
143
|
-
if (normal(tx.to, "pendle tx target") !== normal(router, "pendle router")) {
|
|
144
|
-
throw new Error("Pendle convert returned unexpected router target");
|
|
145
|
-
}
|
|
146
|
-
if (tx.from && normal(tx.from, "pendle tx sender") !== normal(from, "pendle sender")) {
|
|
147
|
-
throw new Error("Pendle convert transaction sender mismatch");
|
|
148
|
-
}
|
|
149
|
-
const amountOut = firstOutputAmount(raw);
|
|
150
|
-
const quote = attachAutoSlippage(raw, {
|
|
151
|
-
chainId,
|
|
152
|
-
venue: tx.to,
|
|
153
|
-
amountOut,
|
|
154
|
-
liquidityUsd: q.liquidityUsd,
|
|
155
|
-
priceChange5m: q.priceChange5m,
|
|
156
|
-
requestedCapBps: q.maxSlippageBps ?? q.slippageBps,
|
|
157
|
-
});
|
|
158
|
-
return stampPrepared({
|
|
159
|
-
provider: "pendle",
|
|
160
|
-
calldataReady: true,
|
|
161
|
-
// NOT executable authority. The bytes are assembled but nothing is signed:
|
|
162
|
-
// the user's wallet is still the only thing that can authorize this. The
|
|
163
|
-
// previous `executionReady: true` read as "cleared to execute" and trained
|
|
164
|
-
// agents to treat a quote as permission.
|
|
165
|
-
requiresUserSignature: true,
|
|
166
|
-
signingReady: false,
|
|
167
|
-
broadcastReady: false,
|
|
168
|
-
chainId,
|
|
169
|
-
action: raw.action || null,
|
|
170
|
-
quote,
|
|
171
|
-
autoSlippage: quote.autoSlippage,
|
|
172
|
-
requiresApproval: normalizeRequiredApprovals(raw.requiredApprovals, tx.to),
|
|
173
|
-
transaction: {
|
|
174
|
-
chainId,
|
|
175
|
-
from: tx.from || from,
|
|
176
|
-
to: tx.to,
|
|
177
|
-
data: tx.data,
|
|
178
|
-
value: tx.value ?? "0x0",
|
|
179
|
-
slippageGuard: bindAutoSlippageGuardToCall(quote.autoSlippage, { chainId, venue: tx.to, data: tx.data }),
|
|
180
|
-
},
|
|
181
|
-
}, { provider: "pendle", kind: "pendle-swap" });
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export async function pendleQuote(q = {}, opts = {}) {
|
|
185
|
-
const prepared = await pendlePrepare(q, opts);
|
|
186
|
-
const { transaction: _transaction, ...quote } = prepared;
|
|
187
|
-
return quote;
|
|
188
|
-
}
|