@memfork/cli 0.1.14 → 0.1.16
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/commands/provision.js +36 -8
- package/package.json +1 -1
|
@@ -54,6 +54,10 @@ export async function autoProvision(opts) {
|
|
|
54
54
|
const privateKey = keypair.getSecretKey(); // bech32 suiprivkey1…
|
|
55
55
|
console.log(chalk.dim(` address: ${address}`));
|
|
56
56
|
// ── 2. Fund wallet ───────────────────────────────────────────────────────────
|
|
57
|
+
// sponsorBase = root URL, used for /drip and /sponsor paths.
|
|
58
|
+
// sponsorEndpoint = full URL the MemForksClient POSTs to (no path appended internally).
|
|
59
|
+
let sponsorBase;
|
|
60
|
+
let sponsorEndpoint;
|
|
57
61
|
if (network === "testnet") {
|
|
58
62
|
console.log(` ${chalk.dim("[2/6]")} Fund your testnet wallet`);
|
|
59
63
|
console.log();
|
|
@@ -66,14 +70,15 @@ export async function autoProvision(opts) {
|
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
72
|
else {
|
|
69
|
-
// Mainnet:
|
|
70
|
-
//
|
|
71
|
-
// All subsequent MemForks ops are covered by /sponsor, but those two calls
|
|
72
|
-
// happen before the tree exists and must self-pay.
|
|
73
|
+
// Mainnet: drip covers the two MemWal calls (createAccount + addDelegateKey).
|
|
74
|
+
// initTree (step 6) goes through /sponsor — the MemForksClient handles that path.
|
|
73
75
|
step(2, "Requesting mainnet gas from MemForks sponsor");
|
|
74
|
-
|
|
76
|
+
// Normalise: strip a trailing /sponsor so the base URL is always path-free.
|
|
77
|
+
sponsorBase = (process.env.MEMFORK_SPONSOR_URL ?? "https://memforks-sponsor-production.up.railway.app")
|
|
78
|
+
.replace(/\/sponsor\/?$/, "");
|
|
79
|
+
sponsorEndpoint = `${sponsorBase}/sponsor`;
|
|
75
80
|
try {
|
|
76
|
-
const res = await fetch(`${
|
|
81
|
+
const res = await fetch(`${sponsorBase}/drip`, {
|
|
77
82
|
method: "POST",
|
|
78
83
|
headers: { "Content-Type": "application/json" },
|
|
79
84
|
body: JSON.stringify({ address }),
|
|
@@ -93,7 +98,7 @@ export async function autoProvision(opts) {
|
|
|
93
98
|
}
|
|
94
99
|
catch (e) {
|
|
95
100
|
console.log(chalk.red("failed"));
|
|
96
|
-
throw new Error(`Could not get gas from sponsor (${
|
|
101
|
+
throw new Error(`Could not get gas from sponsor (${sponsorBase}/drip): ${String(e)}\n` +
|
|
97
102
|
` Fund the address manually then re-run:\n` +
|
|
98
103
|
` ${address}`);
|
|
99
104
|
}
|
|
@@ -158,13 +163,36 @@ export async function autoProvision(opts) {
|
|
|
158
163
|
signer: privateKey,
|
|
159
164
|
network,
|
|
160
165
|
packageId: consts.memforksPackageId,
|
|
166
|
+
// sponsorEndpoint is the full POST URL — MemForksClient appends no path.
|
|
167
|
+
...(sponsorEndpoint ? { sponsorUrl: sponsorEndpoint } : {}),
|
|
161
168
|
memwal: {
|
|
162
169
|
accountId,
|
|
163
170
|
delegateKey: delegate.privateKey,
|
|
164
171
|
serverUrl: consts.relayer,
|
|
165
172
|
},
|
|
166
173
|
});
|
|
167
|
-
|
|
174
|
+
let treeId;
|
|
175
|
+
let digest;
|
|
176
|
+
try {
|
|
177
|
+
({ treeId, digest } = await memClient.initTree(accountId, opts.defaultBranch ?? "main"));
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
const msg = String(e);
|
|
181
|
+
console.log(chalk.red("failed"));
|
|
182
|
+
if (msg.includes("429") || msg.toLowerCase().includes("rate limit")) {
|
|
183
|
+
throw new Error("Sponsor rate limit hit for init_tree (1/IP/day).\n" +
|
|
184
|
+
"Wait 24 h and run `memfork init --quick` again, or fund the wallet manually:\n" +
|
|
185
|
+
` ${address}`);
|
|
186
|
+
}
|
|
187
|
+
if (msg.includes("Sponsor error: 404")) {
|
|
188
|
+
throw new Error(`Sponsor endpoint not reachable (${sponsorEndpoint}).\n` +
|
|
189
|
+
"Set MEMFORK_SPONSOR_URL to your sponsor base URL and retry.");
|
|
190
|
+
}
|
|
191
|
+
throw new Error(`MemoryTree creation failed: ${msg}`);
|
|
192
|
+
}
|
|
193
|
+
if (!treeId) {
|
|
194
|
+
throw new Error("MemoryTree creation returned no treeId — check sponsor logs.");
|
|
195
|
+
}
|
|
168
196
|
done();
|
|
169
197
|
console.log(chalk.dim(` treeId: ${treeId}`));
|
|
170
198
|
console.log(chalk.dim(` tx: ${digest}`));
|