@memfork/cli 0.1.15 → 0.1.17
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 +50 -9
- package/package.json +1 -1
|
@@ -54,7 +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
|
-
|
|
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;
|
|
58
61
|
if (network === "testnet") {
|
|
59
62
|
console.log(` ${chalk.dim("[2/6]")} Fund your testnet wallet`);
|
|
60
63
|
console.log();
|
|
@@ -67,13 +70,15 @@ export async function autoProvision(opts) {
|
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
else {
|
|
70
|
-
// Mainnet:
|
|
71
|
-
//
|
|
72
|
-
// initTree (step 6) is a MemForks call — it goes through /sponsor directly.
|
|
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,14 +163,50 @@ export async function autoProvision(opts) {
|
|
|
158
163
|
signer: privateKey,
|
|
159
164
|
network,
|
|
160
165
|
packageId: consts.memforksPackageId,
|
|
161
|
-
|
|
166
|
+
// sponsorEndpoint is the full POST URL — MemForksClient appends no path.
|
|
167
|
+
...(sponsorEndpoint ? { sponsorUrl: sponsorEndpoint } : {}),
|
|
162
168
|
memwal: {
|
|
163
169
|
accountId,
|
|
164
170
|
delegateKey: delegate.privateKey,
|
|
165
171
|
serverUrl: consts.relayer,
|
|
166
172
|
},
|
|
167
173
|
});
|
|
168
|
-
|
|
174
|
+
let treeId;
|
|
175
|
+
let digest;
|
|
176
|
+
// Retry once on a transient gas-coin version race: the sponsor refreshes its
|
|
177
|
+
// pool after the drip, but if initTree lands before that completes the
|
|
178
|
+
// fullnode may report a stale-object error. A short wait + retry clears it.
|
|
179
|
+
const maxAttempts = 2;
|
|
180
|
+
for (let attempt = 1;; attempt++) {
|
|
181
|
+
try {
|
|
182
|
+
({ treeId, digest } = await memClient.initTree(accountId, opts.defaultBranch ?? "main"));
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
const msg = String(e);
|
|
187
|
+
const isTransient = msg.includes("needs to be rebuilt") ||
|
|
188
|
+
msg.includes("unavailable for consumption") ||
|
|
189
|
+
msg.includes("object version");
|
|
190
|
+
if (isTransient && attempt < maxAttempts) {
|
|
191
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
console.log(chalk.red("failed"));
|
|
195
|
+
if (msg.includes("429") || msg.toLowerCase().includes("rate limit")) {
|
|
196
|
+
throw new Error("Sponsor rate limit hit for init_tree (1/IP/day).\n" +
|
|
197
|
+
"Wait 24 h and run `memfork init --quick` again, or fund the wallet manually:\n" +
|
|
198
|
+
` ${address}`);
|
|
199
|
+
}
|
|
200
|
+
if (msg.includes("Sponsor error: 404")) {
|
|
201
|
+
throw new Error(`Sponsor endpoint not reachable (${sponsorEndpoint}).\n` +
|
|
202
|
+
"Set MEMFORK_SPONSOR_URL to your sponsor base URL and retry.");
|
|
203
|
+
}
|
|
204
|
+
throw new Error(`MemoryTree creation failed: ${msg}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!treeId) {
|
|
208
|
+
throw new Error("MemoryTree creation returned no treeId — check sponsor logs.");
|
|
209
|
+
}
|
|
169
210
|
done();
|
|
170
211
|
console.log(chalk.dim(` treeId: ${treeId}`));
|
|
171
212
|
console.log(chalk.dim(` tx: ${digest}`));
|