@oracle-agent/oracle 0.1.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 +98 -0
- package/LICENSE +202 -0
- package/README.md +384 -0
- package/SECURITY.md +89 -0
- package/SETUP.md +235 -0
- package/artifacts/inscription/oracle-was-here-preview.png +0 -0
- package/artifacts/inscription/oracle-was-here.svg +1 -0
- package/artifacts/specialist-packs/oracle-full-crypto.json +273 -0
- package/bin/desk-server.mjs +438 -0
- package/bin/oracle-data-mcp.mjs +603 -0
- package/bin/oracle-init.mjs +423 -0
- package/bin/oracle-public-server.mjs +36 -0
- package/bin/oracle-route.mjs +254 -0
- package/bin/oracle-scan.mjs +192 -0
- package/docs/adding-a-chain.md +229 -0
- package/docs/architecture.md +135 -0
- package/docs/profiles.md +132 -0
- package/examples/add-a-chain.mjs +65 -0
- package/examples/research-a-token.mjs +70 -0
- package/package.json +90 -0
- package/profiles/_template/SOUL.md +47 -0
- package/profiles/_template/profile.json +22 -0
- package/profiles/bitcoin-agent/SOUL.md +31 -0
- package/profiles/bitcoin-agent/profile.json +32 -0
- package/profiles/hyperliquid-agent/SOUL.md +34 -0
- package/profiles/hyperliquid-agent/profile.json +37 -0
- package/profiles/oracle/SOUL.md +65 -0
- package/profiles/oracle/profile.json +35 -0
- package/profiles/polymarket-agent/SOUL.md +35 -0
- package/profiles/polymarket-agent/profile.json +34 -0
- package/profiles/profile.schema.json +90 -0
- package/profiles/protocol-builder/SOUL.md +50 -0
- package/profiles/protocol-builder/profile.json +37 -0
- package/profiles/robinhood-agent/SOUL.md +45 -0
- package/profiles/robinhood-agent/profile.json +39 -0
- package/profiles/solana-agent/SOUL.md +37 -0
- package/profiles/solana-agent/profile.json +37 -0
- package/profiles/stable-agent/SOUL.md +43 -0
- package/profiles/stable-agent/profile.json +37 -0
- package/public/oracle-console/app.js +272 -0
- package/public/oracle-console/bitcoin-wallets.js +206 -0
- package/public/oracle-console/index.html +91 -0
- package/public/oracle-console/styles.css +239 -0
- package/public/oracle-splash/index.html +931 -0
- package/scripts/build-inscription.py +230 -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/public-api-scan.mjs +23 -0
- package/scripts/secret-scan.mjs +181 -0
- package/scripts/verify-v3-venues.mjs +192 -0
- package/skills/oracle-best-execution/SKILL.md +127 -0
- package/skills/oracle-bitcoin/SKILL.md +53 -0
- package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +59 -0
- package/skills/oracle-circuit-breaker/SKILL.md +51 -0
- package/skills/oracle-contract-research/SKILL.md +55 -0
- package/skills/oracle-desk/SKILL.md +58 -0
- package/skills/oracle-dex-launch/SKILL.md +38 -0
- package/skills/oracle-grants/SKILL.md +69 -0
- package/skills/oracle-hypercore-staking/SKILL.md +57 -0
- package/skills/oracle-hyperliquid/SKILL.md +56 -0
- package/skills/oracle-meme-token-sniper/SKILL.md +73 -0
- package/skills/oracle-nft-gacha-launch/SKILL.md +48 -0
- package/skills/oracle-nft-mint-gas-war/SKILL.md +63 -0
- package/skills/oracle-polymarket/SKILL.md +60 -0
- package/skills/oracle-protocol-builder/SKILL.md +38 -0
- package/skills/oracle-protocol-security/SKILL.md +60 -0
- package/skills/oracle-public-product/SKILL.md +44 -0
- package/skills/oracle-receipts/SKILL.md +52 -0
- package/skills/oracle-rfq-tokenized-assets/SKILL.md +69 -0
- package/skills/oracle-smart-wallet-scanner/SKILL.md +49 -0
- package/skills/oracle-solana/SKILL.md +65 -0
- package/skills/oracle-solana-nft/SKILL.md +54 -0
- package/skills/oracle-token-research/SKILL.md +67 -0
- package/src/agent-auth.mjs +191 -0
- package/src/approval-guard.mjs +282 -0
- package/src/attestation-secret.mjs +88 -0
- package/src/audit-log.mjs +196 -0
- package/src/auto-slippage.mjs +378 -0
- package/src/capability-posture.mjs +125 -0
- package/src/chains.mjs +62 -0
- package/src/data/catalog.mjs +495 -0
- package/src/data/desk-data.mjs +623 -0
- package/src/data/http.mjs +200 -0
- package/src/data/provider-endpoint.mjs +94 -0
- package/src/data/providers/aerodrome.mjs +244 -0
- package/src/data/providers/balancer.mjs +208 -0
- package/src/data/providers/bitcoin-esplora.mjs +230 -0
- package/src/data/providers/bitcoin-meta.mjs +378 -0
- package/src/data/providers/blockscout.mjs +14 -0
- package/src/data/providers/bridges.mjs +241 -0
- package/src/data/providers/cowswap.mjs +501 -0
- package/src/data/providers/curve.mjs +200 -0
- package/src/data/providers/defillama.mjs +88 -0
- package/src/data/providers/dexscreener.mjs +43 -0
- package/src/data/providers/evm-rpc.mjs +203 -0
- package/src/data/providers/geckoterminal.mjs +34 -0
- package/src/data/providers/gmx.mjs +495 -0
- package/src/data/providers/hl-info.mjs +102 -0
- package/src/data/providers/hl-markets.mjs +210 -0
- package/src/data/providers/hl-perps.mjs +382 -0
- package/src/data/providers/hl-staking.mjs +352 -0
- package/src/data/providers/hl-ws.mjs +119 -0
- package/src/data/providers/hyperevm-dex.mjs +49 -0
- package/src/data/providers/jupiter.mjs +182 -0
- package/src/data/providers/lifi.mjs +150 -0
- package/src/data/providers/magiceden-sol.mjs +355 -0
- package/src/data/providers/morpho.mjs +173 -0
- package/src/data/providers/odos.mjs +155 -0
- package/src/data/providers/oneinch.mjs +173 -0
- package/src/data/providers/opensea-multichain.mjs +136 -0
- package/src/data/providers/opensea-nft.mjs +99 -0
- package/src/data/providers/paraswap.mjs +117 -0
- package/src/data/providers/pendle.mjs +187 -0
- package/src/data/providers/poly-public.mjs +96 -0
- package/src/data/providers/poly-ws.mjs +103 -0
- package/src/data/providers/rh-agent.mjs +59 -0
- package/src/data/providers/satflow.mjs +336 -0
- package/src/data/providers/solana-rpc.mjs +186 -0
- package/src/data/providers/uniswap-v3.mjs +303 -0
- package/src/data/providers/zerox.mjs +166 -0
- package/src/data/public-api-scan.mjs +61 -0
- package/src/data/quote-placeholder.mjs +31 -0
- package/src/exact-integer.mjs +72 -0
- package/src/exec-policy.mjs +444 -0
- package/src/flags.mjs +15 -0
- package/src/fresh-window.mjs +76 -0
- package/src/gmx-attestation.mjs +175 -0
- package/src/index.mjs +50 -0
- package/src/nft-gas-war-guard.mjs +139 -0
- package/src/onboarding/agent-keys.mjs +157 -0
- package/src/onboarding/index.mjs +18 -0
- package/src/onboarding/tiers.mjs +139 -0
- package/src/oracle-env.mjs +38 -0
- package/src/protocol-execution.mjs +84 -0
- package/src/public-api/buzz-integration.mjs +256 -0
- package/src/public-api/connect-agent.mjs +397 -0
- package/src/public-api/grants.mjs +142 -0
- package/src/public-api/http.mjs +374 -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 +372 -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 +318 -0
- package/src/public-control/runtime-config.mjs +265 -0
- package/src/public-control/session-key-model.mjs +374 -0
- package/src/public-control/session-orchestrator.mjs +412 -0
- package/src/route-attestation.mjs +132 -0
- package/src/router/best-execution.mjs +221 -0
- package/src/router/index.mjs +185 -0
- package/src/router/prepare-bridge.mjs +288 -0
- package/src/router/prepare-route.mjs +341 -0
- package/src/router/proposal.mjs +311 -0
- package/src/router/risk-classifier.mjs +119 -0
- package/src/router/route-sources.mjs +292 -0
- package/src/scanner/chains.config.mjs +381 -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 +335 -0
- package/src/scanner/v3-venue.mjs +290 -0
- package/src/scopes.mjs +44 -0
- package/src/sell-simulation.mjs +167 -0
- package/src/token-transfer-guard.mjs +188 -0
- package/src/vault-attestation.mjs +145 -0
- package/src/venues.mjs +206 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
// GMX v2 public API + guarded async order-intent prepare. Arbitrum + Avalanche, no key.
|
|
2
|
+
// GMX order creation is asynchronous: user tx creates an order, keepers later execute/cancel it.
|
|
3
|
+
// This provider prepares reviewed calldata + approval metadata only; executionReady stays false until a separate signer-bound GMX policy exists.
|
|
4
|
+
import { Interface, getAddress, isAddress } from "ethers";
|
|
5
|
+
import { httpJson } from "../http.mjs";
|
|
6
|
+
import { rpcCall as defaultRpcCall, transactionReceipt } from "./evm-rpc.mjs";
|
|
7
|
+
|
|
8
|
+
export const GMX_API = Object.freeze({
|
|
9
|
+
42161: "https://arbitrum-api.gmxinfra.io",
|
|
10
|
+
43114: "https://avalanche-api.gmxinfra.io",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export const GMX_V2_CHAINS = Object.freeze({
|
|
14
|
+
42161: {
|
|
15
|
+
name: "arbitrum",
|
|
16
|
+
api: GMX_API[42161],
|
|
17
|
+
exchangeRouter: "0x1C3fa76e6E1088bCE750f23a5BFcffa1efEF6A41",
|
|
18
|
+
router: "0x7452c558d45f8afC8c83dAe62C3f8A5BE19c71f6",
|
|
19
|
+
orderVault: "0x31eF83a530Fde1B38EE9A18093A333D8Bbbc40D5",
|
|
20
|
+
dataStore: "0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8",
|
|
21
|
+
reader: "0x470fbC46bcC0f16532691Df360A07d8Bf5ee0789",
|
|
22
|
+
eventEmitter: "0xC8ee91A54287DB53897056e12D9819156D3822Fb",
|
|
23
|
+
wnt: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
24
|
+
usdc: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
25
|
+
},
|
|
26
|
+
43114: {
|
|
27
|
+
name: "avalanche",
|
|
28
|
+
api: GMX_API[43114],
|
|
29
|
+
exchangeRouter: "0x8f550E53DFe96C055D5Bdb267c21F268fCAF63B2",
|
|
30
|
+
router: "0x820F5FfC5b525cD4d88Cd91aCf2c28F16530Cc68",
|
|
31
|
+
orderVault: "0xD3D60D22d415aD43b7e64b510D86A30f19B1B12C",
|
|
32
|
+
dataStore: "0x2F0b22339414ADeD7D5F06f9D604c7fF5b2fe3f6",
|
|
33
|
+
reader: "0x62Cb8740E6986B29dC671B2EB596676f60590A5B",
|
|
34
|
+
eventEmitter: "0xDb17B211c34240B014ab6d61d4A31FA0C0e20c26",
|
|
35
|
+
wnt: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
|
|
36
|
+
usdc: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const ZERO = "0x0000000000000000000000000000000000000000";
|
|
41
|
+
const ZERO_BYTES32 = `0x${"0".repeat(64)}`;
|
|
42
|
+
|
|
43
|
+
const ORDER_TYPES = Object.freeze({
|
|
44
|
+
marketSwap: 0,
|
|
45
|
+
limitSwap: 1,
|
|
46
|
+
marketIncrease: 2,
|
|
47
|
+
limitIncrease: 3,
|
|
48
|
+
marketDecrease: 4,
|
|
49
|
+
limitDecrease: 5,
|
|
50
|
+
stopLossDecrease: 6,
|
|
51
|
+
stopIncrease: 8,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const DECREASE_SWAP_TYPES = Object.freeze({
|
|
55
|
+
noSwap: 0,
|
|
56
|
+
swapPnlTokenToCollateralToken: 1,
|
|
57
|
+
swapCollateralTokenToPnlToken: 2,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const GMX_EXCHANGE_ROUTER_IFACE = new Interface([
|
|
61
|
+
"function multicall(bytes[] data) payable returns (bytes[] results)",
|
|
62
|
+
"function sendTokens(address token,address receiver,uint256 amount) payable",
|
|
63
|
+
"function sendWnt(address receiver,uint256 amount) payable",
|
|
64
|
+
"function createOrder(((address receiver,address cancellationReceiver,address callbackContract,address uiFeeReceiver,address market,address initialCollateralToken,address[] swapPath) addresses,(uint256 sizeDeltaUsd,uint256 initialCollateralDeltaAmount,uint256 triggerPrice,uint256 acceptablePrice,uint256 executionFee,uint256 callbackGasLimit,uint256 minOutputAmount,uint256 validFromTime) numbers,uint8 orderType,uint8 decreasePositionSwapType,bool isLong,bool shouldUnwrapNativeToken,bool autoCancel,bytes32 referralCode,bytes32[] dataList) params) payable returns (bytes32)",
|
|
65
|
+
"function cancelOrder(bytes32 key) payable",
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const GMX_READER_IFACE = new Interface([
|
|
69
|
+
"function getAccountPositions(address dataStore,address account,uint256 start,uint256 end) view returns (bytes)",
|
|
70
|
+
"function getAccountOrders(address dataStore,address account,uint256 start,uint256 end) view returns (bytes)",
|
|
71
|
+
"function getOrder(address dataStore,bytes32 key) view returns (bytes)",
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const GMX_EVENT_IFACE = new Interface([
|
|
75
|
+
"event EventLog1(address msgSender,string eventName,string indexed eventNameHash,bytes32 indexed topic1,((tuple(string key,address value)[] items,tuple(string key,address[] value)[] arrayItems),(tuple(string key,uint256 value)[] items,tuple(string key,uint256[] value)[] arrayItems),(tuple(string key,int256 value)[] items,tuple(string key,int256[] value)[] arrayItems),(tuple(string key,bool value)[] items,tuple(string key,bool[] value)[] arrayItems),(tuple(string key,bytes32 value)[] items,tuple(string key,bytes32[] value)[] arrayItems),(tuple(string key,bytes value)[] items,tuple(string key,bytes[] value)[] arrayItems),(tuple(string key,string value)[] items,tuple(string key,string[] value)[] arrayItems)) eventData)",
|
|
76
|
+
"event EventLog2(address msgSender,string eventName,string indexed eventNameHash,bytes32 indexed topic1,bytes32 indexed topic2,((tuple(string key,address value)[] items,tuple(string key,address[] value)[] arrayItems),(tuple(string key,uint256 value)[] items,tuple(string key,uint256[] value)[] arrayItems),(tuple(string key,int256 value)[] items,tuple(string key,int256[] value)[] arrayItems),(tuple(string key,bool value)[] items,tuple(string key,bool[] value)[] arrayItems),(tuple(string key,bytes32 value)[] items,tuple(string key,bytes32[] value)[] arrayItems),(tuple(string key,bytes value)[] items,tuple(string key,bytes[] value)[] arrayItems),(tuple(string key,string value)[] items,tuple(string key,string[] value)[] arrayItems)) eventData)",
|
|
77
|
+
]);
|
|
78
|
+
|
|
79
|
+
const ORDER_LIFECYCLE_STATUS = Object.freeze({
|
|
80
|
+
OrderCreated: "created",
|
|
81
|
+
OrderUpdated: "updated",
|
|
82
|
+
OrderExecuted: "executed",
|
|
83
|
+
OrderCancelled: "cancelled",
|
|
84
|
+
OrderFrozen: "frozen",
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
function metaFor(chainId) {
|
|
88
|
+
const id = Number(chainId ?? 42161);
|
|
89
|
+
const meta = GMX_V2_CHAINS[id];
|
|
90
|
+
if (!meta) throw new Error(`gmx: unsupported chainId ${chainId} (supported: ${Object.keys(GMX_V2_CHAINS).join(", ")})`);
|
|
91
|
+
return { chainId: id, ...meta };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function base(chainId, o = {}) {
|
|
95
|
+
const meta = metaFor(chainId);
|
|
96
|
+
return (o.baseUrl || meta.api).replace(/\/$/, "");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function addr(value, label) {
|
|
100
|
+
if (!isAddress(value)) throw new Error(`${label} must be a valid EVM address`);
|
|
101
|
+
return getAddress(value);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function lower(value) {
|
|
105
|
+
return getAddress(value).toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function positive(value, label) {
|
|
109
|
+
let n;
|
|
110
|
+
try {
|
|
111
|
+
n = BigInt(String(value));
|
|
112
|
+
} catch {
|
|
113
|
+
throw new Error(`${label} must be an integer string`);
|
|
114
|
+
}
|
|
115
|
+
if (n <= 0n) throw new Error(`${label} must be positive`);
|
|
116
|
+
return n;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function nonnegative(value, label) {
|
|
120
|
+
let n;
|
|
121
|
+
try {
|
|
122
|
+
n = BigInt(String(value ?? "0"));
|
|
123
|
+
} catch {
|
|
124
|
+
throw new Error(`${label} must be an integer string`);
|
|
125
|
+
}
|
|
126
|
+
if (n < 0n) throw new Error(`${label} must be non-negative`);
|
|
127
|
+
return n;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function bps(value, fallback = 50) {
|
|
131
|
+
const n = Number(value ?? fallback);
|
|
132
|
+
if (!Number.isFinite(n) || n < 0 || n > 100) throw new Error("gmx maxSlippageBps must be 0..100");
|
|
133
|
+
return Math.floor(n);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function orderType(value) {
|
|
137
|
+
const key = String(value || "marketIncrease").trim();
|
|
138
|
+
if (!(key in ORDER_TYPES)) throw new Error(`gmx unsupported orderType ${key}`);
|
|
139
|
+
if (!["marketIncrease", "marketDecrease"].includes(key)) {
|
|
140
|
+
throw new Error("gmx prepare currently supports marketIncrease and marketDecrease only");
|
|
141
|
+
}
|
|
142
|
+
return { key, code: ORDER_TYPES[key] };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function decreaseSwapType(value) {
|
|
146
|
+
const key = String(value || "noSwap").trim();
|
|
147
|
+
if (!(key in DECREASE_SWAP_TYPES)) throw new Error(`gmx unsupported decreasePositionSwapType ${key}`);
|
|
148
|
+
return { key, code: DECREASE_SWAP_TYPES[key] };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function asList(data, field) {
|
|
152
|
+
if (Array.isArray(data)) return data;
|
|
153
|
+
if (Array.isArray(data?.[field])) return data[field];
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function findMarket(markets, marketAddress) {
|
|
158
|
+
const target = lower(marketAddress);
|
|
159
|
+
return markets.find((m) => lower(m.marketToken || m.market || m.address) === target) || null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function tickerFor(tickers, token) {
|
|
163
|
+
const target = lower(token);
|
|
164
|
+
return tickers.find((t) => lower(t.tokenAddress || t.address) === target) || null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function priceWithSlippage({ ticker, isLong, typeKey, maxSlippageBps }) {
|
|
168
|
+
const min = positive(ticker?.minPrice, "gmx minPrice");
|
|
169
|
+
const max = positive(ticker?.maxPrice, "gmx maxPrice");
|
|
170
|
+
const slip = BigInt(maxSlippageBps);
|
|
171
|
+
const denom = 10_000n;
|
|
172
|
+
if (typeKey === "marketIncrease") {
|
|
173
|
+
return (isLong ? (max * (denom + slip)) / denom : (min * (denom - slip)) / denom).toString();
|
|
174
|
+
}
|
|
175
|
+
return (isLong ? (min * (denom - slip)) / denom : (max * (denom + slip)) / denom).toString();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function liquidityFor(market, isLong) {
|
|
179
|
+
const raw = isLong ? market.availableLiquidityLong : market.availableLiquidityShort;
|
|
180
|
+
try {
|
|
181
|
+
return BigInt(String(raw ?? "0"));
|
|
182
|
+
} catch {
|
|
183
|
+
return 0n;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function bytes32Address(value) {
|
|
188
|
+
const text = String(value || "").toLowerCase();
|
|
189
|
+
if (!/^0x[0-9a-f]{64}$/.test(text)) return null;
|
|
190
|
+
return `0x${text.slice(-40)}`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function itemValue(section, key, normalizer = (x) => x) {
|
|
194
|
+
const items = Array.from(section?.items || section?.[0] || []);
|
|
195
|
+
const found = items.find((item) => String(item?.key ?? item?.[0] ?? "") === key);
|
|
196
|
+
return found ? normalizer(found.value ?? found[1]) : null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function dataItems(eventData = {}) {
|
|
200
|
+
const addressItems = eventData.addressItems || eventData[0];
|
|
201
|
+
const uintItems = eventData.uintItems || eventData[1];
|
|
202
|
+
const boolItems = eventData.boolItems || eventData[3];
|
|
203
|
+
const bytes32Items = eventData.bytes32Items || eventData[4];
|
|
204
|
+
const stringItems = eventData.stringItems || eventData[6];
|
|
205
|
+
return {
|
|
206
|
+
account: itemValue(addressItems, "account", (v) => lower(v)),
|
|
207
|
+
market: itemValue(addressItems, "market", (v) => lower(v)),
|
|
208
|
+
initialCollateralToken: itemValue(addressItems, "initialCollateralToken", (v) => lower(v)),
|
|
209
|
+
key: itemValue(bytes32Items, "key", (v) => String(v).toLowerCase()),
|
|
210
|
+
reason: itemValue(stringItems, "reason", (v) => String(v)),
|
|
211
|
+
sizeDeltaUsd: itemValue(uintItems, "sizeDeltaUsd", (v) => BigInt(v).toString()),
|
|
212
|
+
initialCollateralDeltaAmount: itemValue(uintItems, "initialCollateralDeltaAmount", (v) => BigInt(v).toString()),
|
|
213
|
+
executionFee: itemValue(uintItems, "executionFee", (v) => BigInt(v).toString()),
|
|
214
|
+
acceptablePrice: itemValue(uintItems, "acceptablePrice", (v) => BigInt(v).toString()),
|
|
215
|
+
isLong: itemValue(boolItems, "isLong", (v) => Boolean(v)),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function parseGmxLifecycleEvent(log = {}, meta) {
|
|
220
|
+
if (lower(log.address) !== lower(meta.eventEmitter)) return null;
|
|
221
|
+
let parsed;
|
|
222
|
+
try {
|
|
223
|
+
parsed = GMX_EVENT_IFACE.parseLog({ topics: log.topics, data: log.data });
|
|
224
|
+
} catch {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const eventName = String(parsed?.args?.eventName || "");
|
|
228
|
+
const status = ORDER_LIFECYCLE_STATUS[eventName];
|
|
229
|
+
if (!status) return null;
|
|
230
|
+
const items = dataItems(parsed.args.eventData || {});
|
|
231
|
+
const orderKey = (items.key || String(parsed.args.topic1 || "")).toLowerCase();
|
|
232
|
+
const account = items.account || bytes32Address(parsed.args.topic2);
|
|
233
|
+
return {
|
|
234
|
+
eventName,
|
|
235
|
+
status,
|
|
236
|
+
orderKey,
|
|
237
|
+
account: account ? lower(account) : null,
|
|
238
|
+
market: items.market,
|
|
239
|
+
initialCollateralToken: items.initialCollateralToken,
|
|
240
|
+
sizeDeltaUsd: items.sizeDeltaUsd,
|
|
241
|
+
initialCollateralDeltaAmount: items.initialCollateralDeltaAmount,
|
|
242
|
+
executionFee: items.executionFee,
|
|
243
|
+
acceptablePrice: items.acceptablePrice,
|
|
244
|
+
isLong: items.isLong,
|
|
245
|
+
reason: items.reason,
|
|
246
|
+
logIndex: log.logIndex == null ? null : Number.parseInt(String(log.logIndex), 16),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function lifecycleRank(status) {
|
|
251
|
+
return { executed: 5, cancelled: 4, frozen: 3, created: 2, updated: 1 }[status] || 0;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function parseGmxOrderEvents(logs = [], { chainId } = {}) {
|
|
255
|
+
const meta = metaFor(chainId);
|
|
256
|
+
return (Array.isArray(logs) ? logs : [])
|
|
257
|
+
.map((log) => parseGmxLifecycleEvent(log, meta))
|
|
258
|
+
.filter(Boolean)
|
|
259
|
+
.sort((a, b) => (a.logIndex ?? 0) - (b.logIndex ?? 0));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export async function gmxMarkets(args = {}, opts = {}) {
|
|
263
|
+
return httpJson(`${base(args.chainId ?? 42161, opts)}/markets`, {
|
|
264
|
+
fetchImpl: opts.fetchImpl,
|
|
265
|
+
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export async function gmxMarketsInfo(args = {}, opts = {}) {
|
|
270
|
+
return httpJson(`${base(args.chainId ?? 42161, opts)}/markets/info`, {
|
|
271
|
+
fetchImpl: opts.fetchImpl,
|
|
272
|
+
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export async function gmxTokens(args = {}, opts = {}) {
|
|
277
|
+
return httpJson(`${base(args.chainId ?? 42161, opts)}/tokens`, {
|
|
278
|
+
fetchImpl: opts.fetchImpl,
|
|
279
|
+
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export async function gmxTickers(args = {}, opts = {}) {
|
|
284
|
+
return httpJson(`${base(args.chainId ?? 42161, opts)}/prices/tickers`, {
|
|
285
|
+
fetchImpl: opts.fetchImpl,
|
|
286
|
+
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export async function gmxHealth(opts = {}) {
|
|
291
|
+
const data = await gmxTickers({ chainId: 42161 }, opts);
|
|
292
|
+
return { ok: Array.isArray(data) && data.length > 0, tickerSample: Array.isArray(data) ? data.length : 0 };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export async function gmxPositions(args = {}, opts = {}) {
|
|
296
|
+
const meta = metaFor(args.chainId ?? 42161);
|
|
297
|
+
const account = addr(args.account || args.owner || args.user, "gmx account");
|
|
298
|
+
const start = nonnegative(args.start ?? 0, "gmx start");
|
|
299
|
+
const end = nonnegative(args.end ?? args.limit ?? 20, "gmx end");
|
|
300
|
+
const data = GMX_READER_IFACE.encodeFunctionData("getAccountPositions", [meta.dataStore, account, start, end]);
|
|
301
|
+
const call = opts.rpcCall || defaultRpcCall;
|
|
302
|
+
const raw = await call(meta.chainId, "eth_call", [{ to: meta.reader, data }, args.blockTag || "latest"], opts);
|
|
303
|
+
return { provider: "gmx", chainId: meta.chainId, reader: lower(meta.reader), dataStore: lower(meta.dataStore), account: lower(account), raw };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export async function gmxOrderStatus(args = {}, opts = {}) {
|
|
307
|
+
const meta = metaFor(args.chainId ?? 42161);
|
|
308
|
+
const key = String(args.key || args.orderKey || "").trim();
|
|
309
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(key)) throw new Error("gmx order key must be bytes32 hex");
|
|
310
|
+
const data = GMX_READER_IFACE.encodeFunctionData("getOrder", [meta.dataStore, key]);
|
|
311
|
+
const call = opts.rpcCall || defaultRpcCall;
|
|
312
|
+
const raw = await call(meta.chainId, "eth_call", [{ to: meta.reader, data }, args.blockTag || "latest"], opts);
|
|
313
|
+
return { provider: "gmx", chainId: meta.chainId, reader: lower(meta.reader), dataStore: lower(meta.dataStore), key, raw };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export async function gmxVerifyOrderReceipt(args = {}, opts = {}) {
|
|
317
|
+
const meta = metaFor(args.chainId ?? 42161);
|
|
318
|
+
const receipt = opts.receipt || await transactionReceipt({
|
|
319
|
+
chainId: meta.chainId,
|
|
320
|
+
txHash: args.txHash,
|
|
321
|
+
expectedTo: args.expectedTo || meta.exchangeRouter,
|
|
322
|
+
}, opts);
|
|
323
|
+
const txHash = String(args.txHash || receipt.txHash || "").toLowerCase();
|
|
324
|
+
if (receipt.ok !== true) {
|
|
325
|
+
return { ok: false, provider: "gmx", chainId: meta.chainId, txHash, status: receipt.status || "unknown", reason: receipt.reason || "receipt not successful", receipt };
|
|
326
|
+
}
|
|
327
|
+
const events = parseGmxOrderEvents(receipt.logs || [], { chainId: meta.chainId });
|
|
328
|
+
const expectedKey = args.expectedOrderKey || args.orderKey ? String(args.expectedOrderKey || args.orderKey).toLowerCase() : null;
|
|
329
|
+
const relevant = expectedKey ? events.filter((event) => event.orderKey === expectedKey) : events;
|
|
330
|
+
if (relevant.length === 0) {
|
|
331
|
+
return { ok: false, provider: "gmx", chainId: meta.chainId, txHash, status: "unknown", reason: expectedKey ? "order key not found in GMX EventEmitter logs" : "no GMX order lifecycle event found", events, receipt };
|
|
332
|
+
}
|
|
333
|
+
const best = relevant.reduce((prev, event) => lifecycleRank(event.status) >= lifecycleRank(prev.status) ? event : prev, relevant[0]);
|
|
334
|
+
const expectedAccount = args.expectedAccount || args.account ? lower(args.expectedAccount || args.account) : null;
|
|
335
|
+
if (expectedAccount && best.account !== expectedAccount) {
|
|
336
|
+
return { ok: false, provider: "gmx", chainId: meta.chainId, txHash, status: best.status, reason: `account mismatch: expected ${expectedAccount}, got ${best.account || "null"}`, orderKey: best.orderKey, account: best.account, events, receipt };
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
ok: true,
|
|
340
|
+
provider: "gmx",
|
|
341
|
+
chainId: meta.chainId,
|
|
342
|
+
txHash,
|
|
343
|
+
status: best.status,
|
|
344
|
+
orderKey: best.orderKey,
|
|
345
|
+
account: best.account,
|
|
346
|
+
market: best.market,
|
|
347
|
+
eventEmitter: lower(meta.eventEmitter),
|
|
348
|
+
events: relevant,
|
|
349
|
+
receipt,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export async function gmxPrepareOrder(args = {}, opts = {}) {
|
|
354
|
+
const meta = metaFor(args.chainId ?? 42161);
|
|
355
|
+
const type = orderType(args.orderType || args.type);
|
|
356
|
+
const decSwap = decreaseSwapType(args.decreasePositionSwapType);
|
|
357
|
+
const account = addr(args.account || args.owner || args.from || args.sender || args.receiver, "gmx account");
|
|
358
|
+
const receiver = addr(args.receiver || account, "gmx receiver");
|
|
359
|
+
const cancellationReceiver = addr(args.cancellationReceiver || receiver, "gmx cancellationReceiver");
|
|
360
|
+
const callbackContract = args.callbackContract ? addr(args.callbackContract, "gmx callbackContract") : ZERO;
|
|
361
|
+
const uiFeeReceiver = args.uiFeeReceiver ? addr(args.uiFeeReceiver, "gmx uiFeeReceiver") : ZERO;
|
|
362
|
+
const marketAddress = addr(args.market || args.marketToken, "gmx market");
|
|
363
|
+
const collateral = addr(args.initialCollateralToken || args.collateralToken || meta.usdc, "gmx initialCollateralToken");
|
|
364
|
+
const collateralAmount = type.key === "marketIncrease"
|
|
365
|
+
? positive(args.initialCollateralDeltaAmount ?? args.collateralAmount ?? args.amountIn, "gmx initialCollateralDeltaAmount")
|
|
366
|
+
: nonnegative(args.initialCollateralDeltaAmount ?? args.collateralAmount ?? "0", "gmx initialCollateralDeltaAmount");
|
|
367
|
+
const sizeDeltaUsd = positive(args.sizeDeltaUsd, "gmx sizeDeltaUsd");
|
|
368
|
+
const executionFee = positive(args.executionFee, "gmx executionFee");
|
|
369
|
+
const maxExecutionFeeWei = BigInt(String(args.maxExecutionFeeWei ?? "10000000000000000"));
|
|
370
|
+
if (executionFee > maxExecutionFeeWei) throw new Error("gmx executionFee exceeds maxExecutionFeeWei");
|
|
371
|
+
const maxSizeDeltaUsd = BigInt(String(args.maxSizeDeltaUsd ?? "50000000000000000000000000000000000"));
|
|
372
|
+
if (sizeDeltaUsd > maxSizeDeltaUsd) throw new Error("gmx sizeDeltaUsd exceeds maxSizeDeltaUsd");
|
|
373
|
+
const slip = bps(args.maxSlippageBps ?? args.slippageBps, 50);
|
|
374
|
+
const isLong = args.isLong == null ? true : Boolean(args.isLong);
|
|
375
|
+
|
|
376
|
+
const [marketEnvelope, tickers] = await Promise.all([
|
|
377
|
+
gmxMarketsInfo({ chainId: meta.chainId }, opts),
|
|
378
|
+
gmxTickers({ chainId: meta.chainId }, opts),
|
|
379
|
+
]);
|
|
380
|
+
const market = findMarket(asList(marketEnvelope, "markets"), marketAddress);
|
|
381
|
+
if (!market) throw new Error("gmx market not found in public registry");
|
|
382
|
+
if (market.isListed === false) throw new Error("gmx market is not listed");
|
|
383
|
+
const indexToken = addr(market.indexToken, "gmx market indexToken");
|
|
384
|
+
const longToken = addr(market.longToken, "gmx market longToken");
|
|
385
|
+
const shortToken = addr(market.shortToken, "gmx market shortToken");
|
|
386
|
+
const collLower = lower(collateral);
|
|
387
|
+
if (![lower(longToken), lower(shortToken)].includes(collLower)) {
|
|
388
|
+
throw new Error("gmx collateral token must match market longToken or shortToken for this guarded slice");
|
|
389
|
+
}
|
|
390
|
+
const available = liquidityFor(market, isLong);
|
|
391
|
+
if (available > 0n && sizeDeltaUsd > available) throw new Error("gmx sizeDeltaUsd exceeds available market liquidity");
|
|
392
|
+
const ticker = tickerFor(tickers, indexToken);
|
|
393
|
+
if (!ticker) throw new Error("gmx index ticker not found");
|
|
394
|
+
const acceptablePrice = args.acceptablePrice
|
|
395
|
+
? positive(args.acceptablePrice, "gmx acceptablePrice").toString()
|
|
396
|
+
: priceWithSlippage({ ticker, isLong, typeKey: type.key, maxSlippageBps: slip });
|
|
397
|
+
|
|
398
|
+
const swapPath = (args.swapPath || []).map((x) => addr(x, "gmx swapPath market"));
|
|
399
|
+
if (swapPath.length > 3) throw new Error("gmx swapPath too long for guarded slice");
|
|
400
|
+
const triggerPrice = nonnegative(args.triggerPrice ?? "0", "gmx triggerPrice");
|
|
401
|
+
const callbackGasLimit = nonnegative(args.callbackGasLimit ?? "0", "gmx callbackGasLimit");
|
|
402
|
+
const minOutputAmount = nonnegative(args.minOutputAmount ?? "0", "gmx minOutputAmount");
|
|
403
|
+
const validFromTime = nonnegative(args.validFromTime ?? "0", "gmx validFromTime");
|
|
404
|
+
const shouldUnwrapNativeToken = Boolean(args.shouldUnwrapNativeToken);
|
|
405
|
+
const autoCancel = args.autoCancel == null ? true : Boolean(args.autoCancel);
|
|
406
|
+
const referralCode = String(args.referralCode || ZERO_BYTES32);
|
|
407
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(referralCode)) throw new Error("gmx referralCode must be bytes32 hex");
|
|
408
|
+
const dataList = Array.isArray(args.dataList) ? args.dataList : [];
|
|
409
|
+
for (const item of dataList) if (!/^0x[0-9a-fA-F]{64}$/.test(String(item))) throw new Error("gmx dataList entries must be bytes32 hex");
|
|
410
|
+
|
|
411
|
+
const params = {
|
|
412
|
+
addresses: {
|
|
413
|
+
receiver,
|
|
414
|
+
cancellationReceiver,
|
|
415
|
+
callbackContract,
|
|
416
|
+
uiFeeReceiver,
|
|
417
|
+
market: marketAddress,
|
|
418
|
+
initialCollateralToken: collateral,
|
|
419
|
+
swapPath,
|
|
420
|
+
},
|
|
421
|
+
numbers: {
|
|
422
|
+
sizeDeltaUsd,
|
|
423
|
+
initialCollateralDeltaAmount: collateralAmount,
|
|
424
|
+
triggerPrice,
|
|
425
|
+
acceptablePrice: BigInt(acceptablePrice),
|
|
426
|
+
executionFee,
|
|
427
|
+
callbackGasLimit,
|
|
428
|
+
minOutputAmount,
|
|
429
|
+
validFromTime,
|
|
430
|
+
},
|
|
431
|
+
orderType: type.code,
|
|
432
|
+
decreasePositionSwapType: decSwap.code,
|
|
433
|
+
isLong,
|
|
434
|
+
shouldUnwrapNativeToken,
|
|
435
|
+
autoCancel,
|
|
436
|
+
referralCode,
|
|
437
|
+
dataList,
|
|
438
|
+
};
|
|
439
|
+
const calls = [];
|
|
440
|
+
if (type.key === "marketIncrease" && collateralAmount > 0n) {
|
|
441
|
+
calls.push(GMX_EXCHANGE_ROUTER_IFACE.encodeFunctionData("sendTokens", [collateral, meta.orderVault, collateralAmount]));
|
|
442
|
+
}
|
|
443
|
+
calls.push(GMX_EXCHANGE_ROUTER_IFACE.encodeFunctionData("sendWnt", [meta.orderVault, executionFee]));
|
|
444
|
+
calls.push(GMX_EXCHANGE_ROUTER_IFACE.encodeFunctionData("createOrder", [params]));
|
|
445
|
+
const data = GMX_EXCHANGE_ROUTER_IFACE.encodeFunctionData("multicall", [calls]);
|
|
446
|
+
const gmxGuard = {
|
|
447
|
+
mode: "gmx-order",
|
|
448
|
+
provider: "gmx",
|
|
449
|
+
chainId: meta.chainId,
|
|
450
|
+
chain: meta.name,
|
|
451
|
+
orderType: type.key,
|
|
452
|
+
orderTypeCode: type.code,
|
|
453
|
+
decreasePositionSwapType: decSwap.key,
|
|
454
|
+
account: lower(account),
|
|
455
|
+
receiver: lower(receiver),
|
|
456
|
+
exchangeRouter: lower(meta.exchangeRouter),
|
|
457
|
+
router: lower(meta.router),
|
|
458
|
+
orderVault: lower(meta.orderVault),
|
|
459
|
+
market: lower(marketAddress),
|
|
460
|
+
indexToken: lower(indexToken),
|
|
461
|
+
initialCollateralToken: lower(collateral),
|
|
462
|
+
initialCollateralDeltaAmount: collateralAmount.toString(),
|
|
463
|
+
sizeDeltaUsd: sizeDeltaUsd.toString(),
|
|
464
|
+
executionFee: executionFee.toString(),
|
|
465
|
+
acceptablePrice,
|
|
466
|
+
maxSlippageBps: slip,
|
|
467
|
+
isLong,
|
|
468
|
+
asyncExecution: true,
|
|
469
|
+
issuedAtMs: Number(opts.nowMs ?? Date.now()),
|
|
470
|
+
};
|
|
471
|
+
return {
|
|
472
|
+
provider: "gmx",
|
|
473
|
+
chainId: meta.chainId,
|
|
474
|
+
chain: meta.name,
|
|
475
|
+
orderReady: true,
|
|
476
|
+
executionReady: false,
|
|
477
|
+
asyncExecution: true,
|
|
478
|
+
orderType: type.key,
|
|
479
|
+
market: lower(marketAddress),
|
|
480
|
+
requiresApproval: type.key === "marketIncrease" && collateralAmount > 0n ? {
|
|
481
|
+
token: lower(collateral),
|
|
482
|
+
spender: lower(meta.router),
|
|
483
|
+
amount: collateralAmount.toString(),
|
|
484
|
+
} : null,
|
|
485
|
+
gmxGuard,
|
|
486
|
+
transaction: {
|
|
487
|
+
chainId: meta.chainId,
|
|
488
|
+
from: lower(account),
|
|
489
|
+
to: lower(meta.exchangeRouter),
|
|
490
|
+
data,
|
|
491
|
+
value: executionFee.toString(),
|
|
492
|
+
gmxGuard,
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Hyperliquid public info client — read-only, no agent key.
|
|
2
|
+
|
|
3
|
+
import { httpJson } from "../http.mjs";
|
|
4
|
+
|
|
5
|
+
export const HL_INFO_MAINNET = "https://api.hyperliquid.xyz/info";
|
|
6
|
+
export const HL_INFO_TESTNET = "https://api.hyperliquid-testnet.xyz/info";
|
|
7
|
+
|
|
8
|
+
function infoUrl({ testnet, baseUrl } = {}) {
|
|
9
|
+
if (baseUrl) {
|
|
10
|
+
return baseUrl.replace(/\/$/, "").endsWith("/info")
|
|
11
|
+
? baseUrl
|
|
12
|
+
: `${baseUrl.replace(/\/$/, "")}/info`;
|
|
13
|
+
}
|
|
14
|
+
if (process.env.HL_INFO_URL) return process.env.HL_INFO_URL;
|
|
15
|
+
if (process.env.HL_API_URL) {
|
|
16
|
+
const b = process.env.HL_API_URL.replace(/\/$/, "");
|
|
17
|
+
return b.endsWith("/info") ? b : `${b}/info`;
|
|
18
|
+
}
|
|
19
|
+
return testnet || process.env.HL_TESTNET === "1" ? HL_INFO_TESTNET : HL_INFO_MAINNET;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function hlInfo(body, opts = {}) {
|
|
23
|
+
if (!body || !body.type) throw new Error("hlInfo requires body.type");
|
|
24
|
+
const url = infoUrl(opts);
|
|
25
|
+
return httpJson(url, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
body,
|
|
28
|
+
fetchImpl: opts.fetchImpl,
|
|
29
|
+
timeoutMs: opts.timeoutMs,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function hlHealth(opts = {}) {
|
|
34
|
+
const mids = await hlInfo({ type: "allMids" }, opts);
|
|
35
|
+
const n = mids && typeof mids === "object" ? Object.keys(mids).length : 0;
|
|
36
|
+
return { ok: n > 0, midCount: n };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function hlAllMids(opts = {}) {
|
|
40
|
+
return hlInfo({ type: "allMids" }, opts);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function hlL2Book(coin, opts = {}) {
|
|
44
|
+
if (!coin) throw new Error("hlL2Book requires coin");
|
|
45
|
+
return hlInfo({ type: "l2Book", coin: String(coin) }, opts);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function hlOutcomeMeta(opts = {}) {
|
|
49
|
+
return hlInfo({ type: "outcomeMeta" }, opts);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function hlClearinghouse(user, opts = {}) {
|
|
53
|
+
if (!user) throw new Error("hlClearinghouse requires user address");
|
|
54
|
+
return hlInfo({ type: "spotClearinghouseState", user }, opts);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function hlUserFills(user, opts = {}) {
|
|
58
|
+
if (!user) throw new Error("hlUserFills requires user address");
|
|
59
|
+
return hlInfo({ type: "userFills", user }, opts);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// D1 expansions
|
|
63
|
+
export async function hlMeta(opts = {}) {
|
|
64
|
+
return hlInfo({ type: "meta" }, opts);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function hlMetaAndAssetCtxs(opts = {}) {
|
|
68
|
+
return hlInfo({ type: "metaAndAssetCtxs" }, opts);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function hlCandleSnapshot({ coin, interval = "1h", startTime, endTime }, opts = {}) {
|
|
72
|
+
if (!coin) throw new Error("hlCandleSnapshot requires coin");
|
|
73
|
+
const req = {
|
|
74
|
+
type: "candleSnapshot",
|
|
75
|
+
req: {
|
|
76
|
+
coin: String(coin),
|
|
77
|
+
interval,
|
|
78
|
+
startTime: startTime ?? Date.now() - 24 * 3600 * 1000,
|
|
79
|
+
endTime: endTime ?? Date.now(),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return hlInfo(req, opts);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function hlOpenOrders(user, opts = {}) {
|
|
86
|
+
if (!user) throw new Error("hlOpenOrders requires user");
|
|
87
|
+
return hlInfo({ type: "openOrders", user }, opts);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function hlFrontendOpenOrders(user, opts = {}) {
|
|
91
|
+
if (!user) throw new Error("hlFrontendOpenOrders requires user");
|
|
92
|
+
return hlInfo({ type: "frontendOpenOrders", user }, opts);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function hlUserState(user, opts = {}) {
|
|
96
|
+
if (!user) throw new Error("hlUserState requires user");
|
|
97
|
+
return hlInfo({ type: "clearinghouseState", user }, opts);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export async function hlSpotMeta(opts = {}) {
|
|
101
|
+
return hlInfo({ type: "spotMeta" }, opts);
|
|
102
|
+
}
|