@solana-mobile/dapp-store-cli 0.14.0 → 0.15.0
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/lib/CliUtils.js +1 -1
- package/lib/package.json +2 -2
- package/lib/upload/TurboStorageDriver.js +27 -5
- package/package.json +2 -2
- package/src/CliUtils.ts +1 -1
- package/src/upload/TurboStorageDriver.ts +36 -7
package/lib/CliUtils.js
CHANGED
|
@@ -156,7 +156,7 @@ export var Constants = function Constants() {
|
|
|
156
156
|
"use strict";
|
|
157
157
|
_class_call_check(this, Constants);
|
|
158
158
|
};
|
|
159
|
-
_define_property(Constants, "CLI_VERSION", "0.
|
|
159
|
+
_define_property(Constants, "CLI_VERSION", "0.15.0");
|
|
160
160
|
_define_property(Constants, "CONFIG_FILE_NAME", "config.yaml");
|
|
161
161
|
_define_property(Constants, "DEFAULT_RPC_DEVNET", "https://api.devnet.solana.com");
|
|
162
162
|
_define_property(Constants, "DEFAULT_PRIORITY_FEE", 500000);
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana-mobile/dapp-store-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@ardrive/turbo-sdk": "^1.31.1",
|
|
55
55
|
"@aws-sdk/client-s3": "^3.321.1",
|
|
56
56
|
"@metaplex-foundation/js-plugin-aws": "^0.20.0",
|
|
57
|
-
"@solana-mobile/dapp-store-publishing-tools": "workspace:0.
|
|
57
|
+
"@solana-mobile/dapp-store-publishing-tools": "workspace:0.15.0",
|
|
58
58
|
"@solana/web3.js": "1.92.1",
|
|
59
59
|
"@types/semver": "^7.3.13",
|
|
60
60
|
"ajv": "^8.11.0",
|
|
@@ -248,11 +248,16 @@ import { TurboFactory, lamportToTokenAmount } from "@ardrive/turbo-sdk";
|
|
|
248
248
|
import bs58 from "bs58";
|
|
249
249
|
import debugModule from "debug";
|
|
250
250
|
var debug = debugModule("cli:turbo-storage");
|
|
251
|
+
var SOL_IN_LAMPORTS = 1000000000;
|
|
252
|
+
var MIN_TOP_UP_LAMPORTS = 1000000;
|
|
253
|
+
var MIN_TOP_UP_SOL = MIN_TOP_UP_LAMPORTS / SOL_IN_LAMPORTS;
|
|
251
254
|
var CONSTANTS = {
|
|
252
255
|
FREE_UPLOAD_LIMIT: 97280,
|
|
253
256
|
UPLOAD_DELAY_MS: 2000,
|
|
254
257
|
MAX_RETRIES: 5,
|
|
255
|
-
SOL_IN_LAMPORTS:
|
|
258
|
+
SOL_IN_LAMPORTS: SOL_IN_LAMPORTS,
|
|
259
|
+
MIN_TOP_UP_SOL: MIN_TOP_UP_SOL,
|
|
260
|
+
MIN_TOP_UP_LAMPORTS: MIN_TOP_UP_LAMPORTS,
|
|
256
261
|
BACKOFF: {
|
|
257
262
|
BASE_MS: 500,
|
|
258
263
|
MAX_MS: 8000
|
|
@@ -427,6 +432,12 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
|
|
|
427
432
|
switch(_state.label){
|
|
428
433
|
case 0:
|
|
429
434
|
_this = this;
|
|
435
|
+
if (wincAmount === 0n) {
|
|
436
|
+
debug("No Winston Credits requested; skipping top-up.");
|
|
437
|
+
return [
|
|
438
|
+
2
|
|
439
|
+
];
|
|
440
|
+
}
|
|
430
441
|
_state.label = 1;
|
|
431
442
|
case 1:
|
|
432
443
|
_state.trys.push([
|
|
@@ -439,7 +450,7 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
|
|
|
439
450
|
4,
|
|
440
451
|
this.withRetry(function() {
|
|
441
452
|
return _async_to_generator(function() {
|
|
442
|
-
var _this_turbo_getWincForToken, _this_turbo, _this_turbo_topUpWithTokens, _this_turbo1, exchangeRate, wincPerSol,
|
|
453
|
+
var _this_turbo_getWincForToken, _this_turbo, _this_turbo_topUpWithTokens, _this_turbo1, exchangeRate, wincPerSol, solInLamports, numerator, lamportsCalculated, minLamports, lamportsToUse, solAmount;
|
|
443
454
|
return _ts_generator(this, function(_state) {
|
|
444
455
|
switch(_state.label){
|
|
445
456
|
case 0:
|
|
@@ -455,12 +466,23 @@ export var TurboStorageDriver = /*#__PURE__*/ function() {
|
|
|
455
466
|
throw new Error("Unable to get Winston Credits exchange rate");
|
|
456
467
|
}
|
|
457
468
|
wincPerSol = BigInt(String(exchangeRate.winc));
|
|
458
|
-
|
|
459
|
-
|
|
469
|
+
if (wincPerSol <= 0n) {
|
|
470
|
+
throw new Error("Invalid Winston Credits exchange rate");
|
|
471
|
+
}
|
|
472
|
+
solInLamports = BigInt(CONSTANTS.SOL_IN_LAMPORTS);
|
|
473
|
+
numerator = wincAmount * solInLamports;
|
|
474
|
+
lamportsCalculated = (numerator + (wincPerSol - 1n)) / wincPerSol;
|
|
475
|
+
minLamports = BigInt(CONSTANTS.MIN_TOP_UP_LAMPORTS);
|
|
476
|
+
lamportsToUse = lamportsCalculated < minLamports ? minLamports : lamportsCalculated;
|
|
477
|
+
if (lamportsToUse > lamportsCalculated) {
|
|
478
|
+
debug("Applying minimum top-up of ".concat(CONSTANTS.MIN_TOP_UP_SOL, " SOL (").concat(CONSTANTS.MIN_TOP_UP_LAMPORTS, " lamports)"));
|
|
479
|
+
}
|
|
480
|
+
solAmount = Number(lamportsToUse) / CONSTANTS.SOL_IN_LAMPORTS;
|
|
481
|
+
debug("Buying at least ".concat(wincAmount, " Winston Credits (~").concat(solAmount.toFixed(9), " SOL / ").concat(lamportsToUse, " lamports)"));
|
|
460
482
|
return [
|
|
461
483
|
4,
|
|
462
484
|
(_this_turbo_topUpWithTokens = (_this_turbo1 = this.turbo).topUpWithTokens) === null || _this_turbo_topUpWithTokens === void 0 ? void 0 : _this_turbo_topUpWithTokens.call(_this_turbo1, {
|
|
463
|
-
tokenAmount: String(lamportToTokenAmount(
|
|
485
|
+
tokenAmount: String(lamportToTokenAmount(lamportsToUse.toString()))
|
|
464
486
|
})
|
|
465
487
|
];
|
|
466
488
|
case 2:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana-mobile/dapp-store-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@ardrive/turbo-sdk": "^1.31.1",
|
|
48
48
|
"@aws-sdk/client-s3": "^3.321.1",
|
|
49
49
|
"@metaplex-foundation/js-plugin-aws": "^0.20.0",
|
|
50
|
-
"@solana-mobile/dapp-store-publishing-tools": "0.
|
|
50
|
+
"@solana-mobile/dapp-store-publishing-tools": "0.15.0",
|
|
51
51
|
"@solana/web3.js": "1.92.1",
|
|
52
52
|
"@types/semver": "^7.3.13",
|
|
53
53
|
"ajv": "^8.11.0",
|
package/src/CliUtils.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { awsStorage } from "@metaplex-foundation/js-plugin-aws";
|
|
|
17
17
|
import { S3StorageManager } from "./config/index.js";
|
|
18
18
|
|
|
19
19
|
export class Constants {
|
|
20
|
-
static CLI_VERSION = "0.
|
|
20
|
+
static CLI_VERSION = "0.15.0";
|
|
21
21
|
static CONFIG_FILE_NAME = "config.yaml";
|
|
22
22
|
static DEFAULT_RPC_DEVNET = "https://api.devnet.solana.com";
|
|
23
23
|
static DEFAULT_PRIORITY_FEE = 500000;
|
|
@@ -22,11 +22,17 @@ interface TurboClient {
|
|
|
22
22
|
}): Promise<{ id: string }>;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const SOL_IN_LAMPORTS = 1_000_000_000;
|
|
26
|
+
const MIN_TOP_UP_LAMPORTS = 1_000_000;
|
|
27
|
+
const MIN_TOP_UP_SOL = MIN_TOP_UP_LAMPORTS / SOL_IN_LAMPORTS;
|
|
28
|
+
|
|
25
29
|
const CONSTANTS = {
|
|
26
30
|
FREE_UPLOAD_LIMIT: 97_280, // 95 KiB
|
|
27
31
|
UPLOAD_DELAY_MS: 2000,
|
|
28
32
|
MAX_RETRIES: 5,
|
|
29
|
-
SOL_IN_LAMPORTS
|
|
33
|
+
SOL_IN_LAMPORTS,
|
|
34
|
+
MIN_TOP_UP_SOL,
|
|
35
|
+
MIN_TOP_UP_LAMPORTS,
|
|
30
36
|
BACKOFF: {
|
|
31
37
|
BASE_MS: 500,
|
|
32
38
|
MAX_MS: 8000,
|
|
@@ -131,6 +137,11 @@ export class TurboStorageDriver {
|
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
private async topUpCredits(wincAmount: bigint): Promise<void> {
|
|
140
|
+
if (wincAmount === 0n) {
|
|
141
|
+
debug("No Winston Credits requested; skipping top-up.");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
try {
|
|
135
146
|
await this.withRetry(async () => {
|
|
136
147
|
const exchangeRate = await this.turbo.getWincForToken?.({
|
|
@@ -142,17 +153,35 @@ export class TurboStorageDriver {
|
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
const wincPerSol = BigInt(String(exchangeRate.winc));
|
|
145
|
-
|
|
146
|
-
|
|
156
|
+
if (wincPerSol <= 0n) {
|
|
157
|
+
throw new Error("Invalid Winston Credits exchange rate");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const solInLamports = BigInt(CONSTANTS.SOL_IN_LAMPORTS);
|
|
161
|
+
const numerator = wincAmount * solInLamports;
|
|
162
|
+
const lamportsCalculated =
|
|
163
|
+
(numerator + (wincPerSol - 1n)) / wincPerSol;
|
|
164
|
+
|
|
165
|
+
const minLamports = BigInt(CONSTANTS.MIN_TOP_UP_LAMPORTS);
|
|
166
|
+
const lamportsToUse =
|
|
167
|
+
lamportsCalculated < minLamports ? minLamports : lamportsCalculated;
|
|
168
|
+
|
|
169
|
+
if (lamportsToUse > lamportsCalculated) {
|
|
170
|
+
debug(
|
|
171
|
+
`Applying minimum top-up of ${CONSTANTS.MIN_TOP_UP_SOL} SOL (${CONSTANTS.MIN_TOP_UP_LAMPORTS} lamports)`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
const solAmount =
|
|
175
|
+
Number(lamportsToUse) / CONSTANTS.SOL_IN_LAMPORTS;
|
|
147
176
|
|
|
148
177
|
debug(
|
|
149
|
-
`Buying ${wincAmount} Winston Credits
|
|
150
|
-
Number(lamportsNeeded) / 1e9
|
|
151
|
-
} SOL`
|
|
178
|
+
`Buying at least ${wincAmount} Winston Credits (~${solAmount.toFixed(9)} SOL / ${lamportsToUse} lamports)`
|
|
152
179
|
);
|
|
153
180
|
|
|
154
181
|
await this.turbo.topUpWithTokens?.({
|
|
155
|
-
tokenAmount: String(
|
|
182
|
+
tokenAmount: String(
|
|
183
|
+
lamportToTokenAmount(lamportsToUse.toString())
|
|
184
|
+
),
|
|
156
185
|
});
|
|
157
186
|
|
|
158
187
|
debug(`Top-up initiated for ${wincAmount} Winston Credits`);
|