@memfork/cli 0.1.15 → 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 -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,36 @@ 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
|
+
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
|
+
}
|
|
169
196
|
done();
|
|
170
197
|
console.log(chalk.dim(` treeId: ${treeId}`));
|
|
171
198
|
console.log(chalk.dim(` tx: ${digest}`));
|