@oracle-agent/oracle 0.2.1 → 0.2.3
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oracle-agent/oracle",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Oracle: prepare-only multichain agent control plane. Policy-bounded intents for a user-signed wallet. Self-custody by default
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Oracle: prepare-only multichain agent control plane. Policy-bounded intents for a user-signed wallet. Self-custody by default — the public package never takes your key. Built for Hermes; no model key required.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { stampPrepared } from "../../prepare-envelope.mjs";
|
|
2
|
-
// Polymarket CLOB — prepare
|
|
3
|
-
//
|
|
4
|
-
// Sign/post
|
|
2
|
+
// Polymarket CLOB — prepare-only for Oracle.
|
|
3
|
+
// Builds unsigned EIP-712 order envelopes (no keys).
|
|
4
|
+
// Sign/post live in @oracle-agent/operator poly-exec only.
|
|
5
|
+
// Deep-import sign/post helpers hard-refuse here.
|
|
5
6
|
|
|
6
7
|
import { createHmac, randomInt } from "node:crypto";
|
|
7
8
|
import {
|
|
8
|
-
Wallet,
|
|
9
9
|
keccak256,
|
|
10
10
|
concat,
|
|
11
|
-
hexlify,
|
|
12
|
-
toUtf8Bytes,
|
|
13
11
|
zeroPadValue,
|
|
14
12
|
getCreate2Address,
|
|
15
13
|
AbiCoder,
|
|
@@ -226,204 +224,29 @@ export function buildOrderV2Message(params = {}) {
|
|
|
226
224
|
};
|
|
227
225
|
}
|
|
228
226
|
|
|
229
|
-
/**
|
|
230
|
-
export async function signOrderV2_1271(
|
|
231
|
-
|
|
232
|
-
"
|
|
233
|
-
"uint256 makerAmount,uint256 takerAmount,uint8 side,uint8 signatureType," +
|
|
234
|
-
"uint256 timestamp,bytes32 metadata,bytes32 builder)";
|
|
235
|
-
const ORDER_TYPE_HASH = keccak256(toUtf8Bytes(ORDER_TYPE_STRING));
|
|
236
|
-
const DOMAIN_TYPE_HASH = keccak256(
|
|
237
|
-
toUtf8Bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
|
|
227
|
+
/** Deep-import refuse: signing lives in @oracle-agent/operator. */
|
|
228
|
+
export async function signOrderV2_1271() {
|
|
229
|
+
throw new Error(
|
|
230
|
+
"poly-clob.signOrderV2_1271 refused: @oracle-agent/oracle is prepare-only. Sign via @oracle-agent/operator poly-exec."
|
|
238
231
|
);
|
|
239
|
-
const NAME_HASH = keccak256(toUtf8Bytes(EIP712_DOMAIN_V2.name));
|
|
240
|
-
const VERSION_HASH = keccak256(toUtf8Bytes(EIP712_DOMAIN_V2.version));
|
|
241
|
-
|
|
242
|
-
const appDomainSep = keccak256(
|
|
243
|
-
AbiCoder.defaultAbiCoder().encode(
|
|
244
|
-
["bytes32", "bytes32", "bytes32", "uint256", "address"],
|
|
245
|
-
[DOMAIN_TYPE_HASH, NAME_HASH, VERSION_HASH, BigInt(POLY_CHAIN_ID), exchangeAddress]
|
|
246
|
-
)
|
|
247
|
-
);
|
|
248
|
-
|
|
249
|
-
const contentsHash = keccak256(
|
|
250
|
-
AbiCoder.defaultAbiCoder().encode(
|
|
251
|
-
[
|
|
252
|
-
"bytes32",
|
|
253
|
-
"uint256",
|
|
254
|
-
"address",
|
|
255
|
-
"address",
|
|
256
|
-
"uint256",
|
|
257
|
-
"uint256",
|
|
258
|
-
"uint256",
|
|
259
|
-
"uint8",
|
|
260
|
-
"uint8",
|
|
261
|
-
"uint256",
|
|
262
|
-
"bytes32",
|
|
263
|
-
"bytes32",
|
|
264
|
-
],
|
|
265
|
-
[
|
|
266
|
-
ORDER_TYPE_HASH,
|
|
267
|
-
BigInt(orderMessage.salt),
|
|
268
|
-
orderMessage.maker,
|
|
269
|
-
orderMessage.signer,
|
|
270
|
-
BigInt(orderMessage.tokenId),
|
|
271
|
-
BigInt(orderMessage.makerAmount),
|
|
272
|
-
BigInt(orderMessage.takerAmount),
|
|
273
|
-
orderMessage.side,
|
|
274
|
-
orderMessage.signatureType,
|
|
275
|
-
BigInt(orderMessage.timestamp),
|
|
276
|
-
orderMessage.metadata,
|
|
277
|
-
orderMessage.builder,
|
|
278
|
-
]
|
|
279
|
-
)
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
const innerSig = await wallet.signTypedData(
|
|
283
|
-
{ ...EIP712_DOMAIN_V2, verifyingContract: exchangeAddress },
|
|
284
|
-
{
|
|
285
|
-
TypedDataSign: [
|
|
286
|
-
{ name: "contents", type: "Order" },
|
|
287
|
-
{ name: "name", type: "string" },
|
|
288
|
-
{ name: "version", type: "string" },
|
|
289
|
-
{ name: "chainId", type: "uint256" },
|
|
290
|
-
{ name: "verifyingContract", type: "address" },
|
|
291
|
-
{ name: "salt", type: "bytes32" },
|
|
292
|
-
],
|
|
293
|
-
Order: ORDER_TYPES_V2.Order,
|
|
294
|
-
},
|
|
295
|
-
{
|
|
296
|
-
contents: orderMessage,
|
|
297
|
-
name: "DepositWallet",
|
|
298
|
-
version: "1",
|
|
299
|
-
chainId: POLY_CHAIN_ID,
|
|
300
|
-
verifyingContract: orderMessage.maker, // deposit wallet (ERC-1271)
|
|
301
|
-
salt: BYTES32_ZERO,
|
|
302
|
-
}
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
const orderTypeHex = hexlify(toUtf8Bytes(ORDER_TYPE_STRING));
|
|
306
|
-
const lenHex = "0x" + (186).toString(16).padStart(4, "0");
|
|
307
|
-
return concat([innerSig, appDomainSep, contentsHash, orderTypeHex, lenHex]);
|
|
308
232
|
}
|
|
309
233
|
|
|
310
234
|
/**
|
|
311
|
-
*
|
|
312
|
-
* mode:
|
|
313
|
-
* - eoa (0): maker=funder or wallet
|
|
314
|
-
* - deposit (3): maker=signer=deriveDepositWallet(eoa) [default auto for desk agent]
|
|
235
|
+
* Deep-import refuse: signed order build lives in @oracle-agent/operator.
|
|
315
236
|
*/
|
|
316
|
-
export async function buildSignedOrderV2(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// Auto deposit-wallet flow when requested or when env forces it
|
|
322
|
-
const preferDeposit =
|
|
323
|
-
params.useDepositWallet === true ||
|
|
324
|
-
process.env.MAD_POLY_USE_DEPOSIT_WALLET === "1" ||
|
|
325
|
-
signatureType === 3;
|
|
326
|
-
|
|
327
|
-
if (preferDeposit || signatureType === undefined) {
|
|
328
|
-
// default path for accounts that reject EOA maker: try deposit wallet
|
|
329
|
-
if (preferDeposit || process.env.MAD_POLY_USE_DEPOSIT_WALLET !== "0") {
|
|
330
|
-
const dw = deriveDepositWallet(eoa);
|
|
331
|
-
// if caller didn't force eoa-only, use deposit when useDepositWallet or auto
|
|
332
|
-
if (preferDeposit || params.autoDeposit !== false) {
|
|
333
|
-
// keep eoa as default unless deposit forced — placeLimitOrder sets useDepositWallet on retry
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (params.useDepositWallet || signatureType === 3) {
|
|
339
|
-
funder = deriveDepositWallet(eoa);
|
|
340
|
-
signatureType = 3;
|
|
341
|
-
} else {
|
|
342
|
-
signatureType = signatureType ?? 0;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// sigType 3: maker = deposit wallet; signer = EOA (must match API key address)
|
|
346
|
-
// (CLOB: "order signer address has to be the address of the API KEY")
|
|
347
|
-
const orderSigner = eoa;
|
|
348
|
-
const built = buildOrderV2Message({
|
|
349
|
-
...params,
|
|
350
|
-
maker: funder,
|
|
351
|
-
signer: orderSigner,
|
|
352
|
-
signatureType,
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
const signature =
|
|
356
|
-
signatureType === 3
|
|
357
|
-
? await signOrderV2_1271(wallet, built.value, built.exchange)
|
|
358
|
-
: await wallet.signTypedData(built.domain, built.types, built.value);
|
|
359
|
-
|
|
360
|
-
return {
|
|
361
|
-
order: {
|
|
362
|
-
salt: parseInt(built.value.salt, 10),
|
|
363
|
-
maker: built.value.maker,
|
|
364
|
-
signer: built.value.signer,
|
|
365
|
-
tokenId: built.value.tokenId,
|
|
366
|
-
makerAmount: built.value.makerAmount,
|
|
367
|
-
takerAmount: built.value.takerAmount,
|
|
368
|
-
side: built.side,
|
|
369
|
-
signatureType: built.value.signatureType,
|
|
370
|
-
timestamp: built.value.timestamp,
|
|
371
|
-
metadata: built.value.metadata,
|
|
372
|
-
builder: built.value.builder,
|
|
373
|
-
expiration: "0",
|
|
374
|
-
signature,
|
|
375
|
-
},
|
|
376
|
-
owner: null,
|
|
377
|
-
orderType: built.orderType,
|
|
378
|
-
_meta: {
|
|
379
|
-
exchange: built.exchange,
|
|
380
|
-
notionalUsdc: built.notionalUsdc,
|
|
381
|
-
domain: built.domain,
|
|
382
|
-
types: built.types,
|
|
383
|
-
value: built.value,
|
|
384
|
-
depositWallet: signatureType === 3 ? funder : null,
|
|
385
|
-
eoa,
|
|
386
|
-
},
|
|
387
|
-
};
|
|
237
|
+
export async function buildSignedOrderV2() {
|
|
238
|
+
throw new Error(
|
|
239
|
+
"poly-clob.buildSignedOrderV2 refused: @oracle-agent/oracle is prepare-only. Sign via @oracle-agent/operator poly-exec."
|
|
240
|
+
);
|
|
388
241
|
}
|
|
389
242
|
|
|
390
243
|
/**
|
|
391
|
-
*
|
|
244
|
+
* Deep-import refuse: CLOB submit lives in @oracle-agent/operator.
|
|
392
245
|
*/
|
|
393
|
-
export async function postClobOrder({
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
clobRest = POLY_CLOB_REST,
|
|
398
|
-
fetchImpl = globalThis.fetch,
|
|
399
|
-
} = {}) {
|
|
400
|
-
if (!creds?.key || !creds?.secret || !creds?.passphrase) {
|
|
401
|
-
throw new Error("L2 creds required (key/secret/passphrase)");
|
|
402
|
-
}
|
|
403
|
-
const body = JSON.stringify(payload);
|
|
404
|
-
const path = "/order";
|
|
405
|
-
const headers = buildL2Headers(creds, address, "POST", path, body);
|
|
406
|
-
const res = await fetchImpl(`${clobRest.replace(/\/$/, "")}${path}`, {
|
|
407
|
-
method: "POST",
|
|
408
|
-
headers,
|
|
409
|
-
body,
|
|
410
|
-
});
|
|
411
|
-
const text = await res.text();
|
|
412
|
-
let data;
|
|
413
|
-
try {
|
|
414
|
-
data = JSON.parse(text);
|
|
415
|
-
} catch {
|
|
416
|
-
data = { raw: text };
|
|
417
|
-
}
|
|
418
|
-
if (!res.ok) {
|
|
419
|
-
const err = new Error(
|
|
420
|
-
`CLOB POST /order failed (${res.status}): ${text.slice(0, 300)}`
|
|
421
|
-
);
|
|
422
|
-
err.status = res.status;
|
|
423
|
-
err.body = data;
|
|
424
|
-
throw err;
|
|
425
|
-
}
|
|
426
|
-
return data;
|
|
246
|
+
export async function postClobOrder() {
|
|
247
|
+
throw new Error(
|
|
248
|
+
"poly-clob.postClobOrder refused: @oracle-agent/oracle is prepare-only. Submit via @oracle-agent/operator poly-exec."
|
|
249
|
+
);
|
|
427
250
|
}
|
|
428
251
|
|
|
429
252
|
/** Max notional USDC for a single desk order (env MAD_POLY_MAX_NOTIONAL, default 25). */
|
|
@@ -27,10 +27,12 @@ export async function solanaRpc(method, params = [], opts = {}) {
|
|
|
27
27
|
if (
|
|
28
28
|
methodName === "sendTransaction" ||
|
|
29
29
|
methodName === "sendRawTransaction" ||
|
|
30
|
-
methodName === "
|
|
30
|
+
methodName === "requestAirdrop" ||
|
|
31
|
+
methodName === "requestAirDrop" ||
|
|
32
|
+
/airdrop/i.test(methodName) ||
|
|
31
33
|
/^send/i.test(methodName)
|
|
32
34
|
) {
|
|
33
|
-
throw new Error(`solana-rpc: ${methodName} refused — @oracle-agent/oracle is prepare-only (no broadcast)`);
|
|
35
|
+
throw new Error(`solana-rpc: ${methodName} refused — @oracle-agent/oracle is prepare-only (no broadcast/airdrop)`);
|
|
34
36
|
}
|
|
35
37
|
const result = await httpJson(rpcUrl(opts), {
|
|
36
38
|
method: "POST",
|