@sherwoodagent/cli 0.58.3 → 0.58.4
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/dist/index.js +84 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -226,6 +226,8 @@ async function cloneTemplate(template) {
|
|
|
226
226
|
]);
|
|
227
227
|
const account = getAccount();
|
|
228
228
|
const chain = getChain();
|
|
229
|
+
const publicClient = getPublicClient();
|
|
230
|
+
const creationNonce = await publicClient.getTransactionCount({ address: account.address });
|
|
229
231
|
const hash = await sendTxWithRetry({
|
|
230
232
|
account,
|
|
231
233
|
chain,
|
|
@@ -236,9 +238,41 @@ async function cloneTemplate(template) {
|
|
|
236
238
|
if (!receipt.contractAddress) {
|
|
237
239
|
throw new Error(`Clone deployment failed \u2014 no contract address in receipt (tx: ${hash})`);
|
|
238
240
|
}
|
|
239
|
-
return { clone: receipt.contractAddress, hash };
|
|
241
|
+
return { clone: receipt.contractAddress, hash, creationNonce };
|
|
240
242
|
}
|
|
241
243
|
|
|
244
|
+
// src/grid/strategy-abi.ts
|
|
245
|
+
var HYPERLIQUID_GRID_STRATEGY_ABI = [
|
|
246
|
+
{
|
|
247
|
+
type: "function",
|
|
248
|
+
name: "updateParams",
|
|
249
|
+
inputs: [{ name: "data", type: "bytes" }],
|
|
250
|
+
outputs: [],
|
|
251
|
+
stateMutability: "nonpayable"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
type: "function",
|
|
255
|
+
name: "maxOrdersPerTick",
|
|
256
|
+
inputs: [],
|
|
257
|
+
outputs: [{ type: "uint32" }],
|
|
258
|
+
stateMutability: "view"
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
// Registers the clone with HyperCore so ERC-20 USDC transfers auto-credit
|
|
262
|
+
// HC spot. Call post-init with variant=0 (Create) and the deployer's nonce
|
|
263
|
+
// at clone creation time. Required before _execute() will pass the spot check.
|
|
264
|
+
type: "function",
|
|
265
|
+
name: "finalizeForHyperCore",
|
|
266
|
+
inputs: [
|
|
267
|
+
{ name: "token", type: "uint64" },
|
|
268
|
+
{ name: "variant", type: "uint8" },
|
|
269
|
+
{ name: "createNonce", type: "uint64" }
|
|
270
|
+
],
|
|
271
|
+
outputs: [],
|
|
272
|
+
stateMutability: "nonpayable"
|
|
273
|
+
}
|
|
274
|
+
];
|
|
275
|
+
|
|
242
276
|
// src/lib/batch.ts
|
|
243
277
|
function formatBatch(calls) {
|
|
244
278
|
return calls.map((call, i) => {
|
|
@@ -1318,10 +1352,12 @@ function registerStrategyTemplateCommands(strategy2) {
|
|
|
1318
1352
|
const cloneSpinner = ora(`Cloning ${def.name} template...`).start();
|
|
1319
1353
|
let clone;
|
|
1320
1354
|
let cloneHash;
|
|
1355
|
+
let creationNonce;
|
|
1321
1356
|
try {
|
|
1322
1357
|
const result = await cloneTemplate(templateAddr);
|
|
1323
1358
|
clone = result.clone;
|
|
1324
1359
|
cloneHash = result.hash;
|
|
1360
|
+
creationNonce = result.creationNonce;
|
|
1325
1361
|
cloneSpinner.succeed(`Cloned: ${chalk.green(clone)}`);
|
|
1326
1362
|
console.log(chalk.dim(` Tx: ${getExplorerUrl(cloneHash)}`));
|
|
1327
1363
|
} catch (err) {
|
|
@@ -1351,6 +1387,27 @@ function registerStrategyTemplateCommands(strategy2) {
|
|
|
1351
1387
|
console.error(chalk.red(formatContractError(err)));
|
|
1352
1388
|
process.exit(1);
|
|
1353
1389
|
}
|
|
1390
|
+
if (templateKey === "hyperliquid-grid") {
|
|
1391
|
+
const hcSpinner = ora("Registering clone with HyperCore...").start();
|
|
1392
|
+
try {
|
|
1393
|
+
const account = getAccount();
|
|
1394
|
+
const hcHash = await writeContractWithRetry({
|
|
1395
|
+
account,
|
|
1396
|
+
chain: getChain(),
|
|
1397
|
+
address: clone,
|
|
1398
|
+
abi: HYPERLIQUID_GRID_STRATEGY_ABI,
|
|
1399
|
+
functionName: "finalizeForHyperCore",
|
|
1400
|
+
args: [0n, 0, BigInt(creationNonce)]
|
|
1401
|
+
// token=USDC, variant=Create(0), nonce
|
|
1402
|
+
});
|
|
1403
|
+
await waitForReceipt(hcHash);
|
|
1404
|
+
hcSpinner.succeed("HyperCore registration sent (active after next block)");
|
|
1405
|
+
console.log(chalk.dim(` Creation nonce: ${creationNonce}`));
|
|
1406
|
+
} catch (err) {
|
|
1407
|
+
hcSpinner.warn("HyperCore registration failed \u2014 run finalizeForHyperCore manually");
|
|
1408
|
+
console.error(chalk.yellow(formatContractError(err)));
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1354
1411
|
console.log();
|
|
1355
1412
|
console.log(chalk.bold("Strategy clone ready:"), chalk.green(clone));
|
|
1356
1413
|
console.log(chalk.dim("Use this address in your proposal batch calls."));
|
|
@@ -1457,9 +1514,11 @@ function registerStrategyTemplateCommands(strategy2) {
|
|
|
1457
1514
|
}
|
|
1458
1515
|
const cloneSpinner = ora(`Cloning ${def.name} template...`).start();
|
|
1459
1516
|
let clone;
|
|
1517
|
+
let proposeCreationNonce;
|
|
1460
1518
|
try {
|
|
1461
1519
|
const result = await cloneTemplate(templateAddr);
|
|
1462
1520
|
clone = result.clone;
|
|
1521
|
+
proposeCreationNonce = result.creationNonce;
|
|
1463
1522
|
cloneSpinner.succeed(`Cloned: ${chalk.green(clone)}`);
|
|
1464
1523
|
console.log(chalk.dim(` Tx: ${getExplorerUrl(result.hash)}`));
|
|
1465
1524
|
} catch (err) {
|
|
@@ -1494,6 +1553,30 @@ function registerStrategyTemplateCommands(strategy2) {
|
|
|
1494
1553
|
console.error(chalk.red(formatContractError(err)));
|
|
1495
1554
|
process.exit(1);
|
|
1496
1555
|
}
|
|
1556
|
+
if (templateKey === "hyperliquid-grid") {
|
|
1557
|
+
const hcSpinner = ora("Registering clone with HyperCore...").start();
|
|
1558
|
+
try {
|
|
1559
|
+
const hcHash = await writeContractWithRetry({
|
|
1560
|
+
account,
|
|
1561
|
+
chain: getChain(),
|
|
1562
|
+
address: clone,
|
|
1563
|
+
abi: HYPERLIQUID_GRID_STRATEGY_ABI,
|
|
1564
|
+
functionName: "finalizeForHyperCore",
|
|
1565
|
+
args: [0n, 0, BigInt(proposeCreationNonce)]
|
|
1566
|
+
});
|
|
1567
|
+
await waitForReceipt(hcHash);
|
|
1568
|
+
hcSpinner.succeed("HyperCore registration sent (active after next block)");
|
|
1569
|
+
} catch (err) {
|
|
1570
|
+
hcSpinner.fail("HyperCore registration failed \u2014 aborting proposal submission");
|
|
1571
|
+
console.error(chalk.red(formatContractError(err)));
|
|
1572
|
+
console.error(
|
|
1573
|
+
chalk.yellow(
|
|
1574
|
+
`Retry by calling finalizeForHyperCore(0, 0, ${proposeCreationNonce}) on ${clone}, then re-run propose.`
|
|
1575
|
+
)
|
|
1576
|
+
);
|
|
1577
|
+
process.exit(1);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1497
1580
|
const { executeCalls, settleCalls } = buildCallsForTemplate(
|
|
1498
1581
|
templateKey,
|
|
1499
1582
|
clone,
|
|
@@ -5555,24 +5638,6 @@ function gridCloid(strategy2, assetIndex, isBuy, levelIndex, nonce) {
|
|
|
5555
5638
|
return BigInt(top16);
|
|
5556
5639
|
}
|
|
5557
5640
|
|
|
5558
|
-
// src/grid/strategy-abi.ts
|
|
5559
|
-
var HYPERLIQUID_GRID_STRATEGY_ABI = [
|
|
5560
|
-
{
|
|
5561
|
-
type: "function",
|
|
5562
|
-
name: "updateParams",
|
|
5563
|
-
inputs: [{ name: "data", type: "bytes" }],
|
|
5564
|
-
outputs: [],
|
|
5565
|
-
stateMutability: "nonpayable"
|
|
5566
|
-
},
|
|
5567
|
-
{
|
|
5568
|
-
type: "function",
|
|
5569
|
-
name: "maxOrdersPerTick",
|
|
5570
|
-
inputs: [],
|
|
5571
|
-
outputs: [{ type: "uint32" }],
|
|
5572
|
-
stateMutability: "view"
|
|
5573
|
-
}
|
|
5574
|
-
];
|
|
5575
|
-
|
|
5576
5641
|
// src/grid/onchain-executor.ts
|
|
5577
5642
|
var UINT64_MAX = 18446744073709551615n;
|
|
5578
5643
|
var ACTION_PLACE_GRID = 1;
|