phantasma-sdk-ts 0.8.1 → 0.8.2
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/cjs/types/carbon/blockchain/tx-helpers/fee-options.js +70 -10
- package/dist/cjs/types/carbon/blockchain/tx-helpers/mint-non-fungible-tx-helper.js +1 -1
- package/dist/cjs/types/carbon/blockchain/tx-helpers/mint-phantasma-non-fungible-tx-helper.js +1 -1
- package/dist/esm/types/carbon/blockchain/tx-helpers/fee-options.js +70 -10
- package/dist/esm/types/carbon/blockchain/tx-helpers/mint-non-fungible-tx-helper.js +1 -1
- package/dist/esm/types/carbon/blockchain/tx-helpers/mint-phantasma-non-fungible-tx-helper.js +1 -1
- package/dist/types/types/carbon/blockchain/tx-helpers/fee-options.d.ts +10 -1
- package/dist/types/types/carbon/blockchain/tx-helpers/fee-options.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -2,14 +2,76 @@
|
|
|
2
2
|
// namespace PhantasmaPhoenix.Protocol.Carbon.Blockchain.TxHelpers
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.MintNftFeeOptions = exports.CreateSeriesFeeOptions = exports.CreateTokenFeeOptions = exports.FeeOptions = void 0;
|
|
5
|
+
function assertArgCount(args, max, methodName) {
|
|
6
|
+
if (args.length > max) {
|
|
7
|
+
throw new TypeError(`${methodName} accepts at most ${max} argument${max === 1 ? '' : 's'}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function parsePositiveCount(value, methodName) {
|
|
11
|
+
if (typeof value === 'bigint') {
|
|
12
|
+
if (value <= 0n) {
|
|
13
|
+
throw new RangeError(`${methodName} count must be a positive integer`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'number') {
|
|
18
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
19
|
+
throw new RangeError(`${methodName} count must be a positive safe integer`);
|
|
20
|
+
}
|
|
21
|
+
return BigInt(value);
|
|
22
|
+
}
|
|
23
|
+
throw new TypeError(`${methodName} count must be a number or bigint`);
|
|
24
|
+
}
|
|
25
|
+
function parseOptionalCount(args, methodName) {
|
|
26
|
+
assertArgCount(args, 1, methodName);
|
|
27
|
+
return args.length === 0 ? 1n : parsePositiveCount(args[0], methodName);
|
|
28
|
+
}
|
|
29
|
+
function parseOptionalMintCount(args, methodName) {
|
|
30
|
+
assertArgCount(args, 1, methodName);
|
|
31
|
+
if (args.length === 0) {
|
|
32
|
+
return 1n;
|
|
33
|
+
}
|
|
34
|
+
const value = args[0];
|
|
35
|
+
return Array.isArray(value)
|
|
36
|
+
? parsePositiveCount(value.length, methodName)
|
|
37
|
+
: parsePositiveCount(value, methodName);
|
|
38
|
+
}
|
|
39
|
+
function assertNoMeaningfulCount(args, methodName) {
|
|
40
|
+
assertArgCount(args, 1, methodName);
|
|
41
|
+
if (args.length === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const count = parsePositiveCount(args[0], methodName);
|
|
45
|
+
if (count !== 1n) {
|
|
46
|
+
throw new RangeError(`${methodName} is not count-sensitive; count must be 1 when provided`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function parseOptionalSymbol(args, methodName) {
|
|
50
|
+
assertArgCount(args, 1, methodName);
|
|
51
|
+
if (args.length === 0) {
|
|
52
|
+
return '';
|
|
53
|
+
}
|
|
54
|
+
const value = args[0];
|
|
55
|
+
if (typeof value === 'string') {
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === 'object' &&
|
|
59
|
+
value !== null &&
|
|
60
|
+
'data' in value &&
|
|
61
|
+
typeof value.data === 'string') {
|
|
62
|
+
return value.data;
|
|
63
|
+
}
|
|
64
|
+
throw new TypeError(`${methodName} symbol must be a string or SmallString-like object`);
|
|
65
|
+
}
|
|
5
66
|
/** Base fee options with sensible defaults. */
|
|
6
67
|
class FeeOptions {
|
|
7
68
|
constructor(gasFeeBase = 10000n, feeMultiplier = 1000n) {
|
|
8
69
|
this.gasFeeBase = gasFeeBase;
|
|
9
70
|
this.feeMultiplier = feeMultiplier;
|
|
10
71
|
}
|
|
11
|
-
calculateMaxGas() {
|
|
12
|
-
|
|
72
|
+
calculateMaxGas(...args) {
|
|
73
|
+
const count = parseOptionalCount(args, 'FeeOptions.calculateMaxGas');
|
|
74
|
+
return this.gasFeeBase * this.feeMultiplier * count;
|
|
13
75
|
}
|
|
14
76
|
}
|
|
15
77
|
exports.FeeOptions = FeeOptions;
|
|
@@ -21,11 +83,7 @@ class CreateTokenFeeOptions extends FeeOptions {
|
|
|
21
83
|
this.gasFeeCreateTokenSymbol = gasFeeCreateTokenSymbol;
|
|
22
84
|
}
|
|
23
85
|
calculateMaxGas(...args) {
|
|
24
|
-
|
|
25
|
-
if (args.length > 0 && typeof args[0] === 'object' && args[0] !== null && 'data' in args[0]) {
|
|
26
|
-
const s = args[0];
|
|
27
|
-
symbol = s.data;
|
|
28
|
-
}
|
|
86
|
+
const symbol = parseOptionalSymbol(args, 'CreateTokenFeeOptions.calculateMaxGas');
|
|
29
87
|
const symbolLen = symbol.length;
|
|
30
88
|
const shift = symbolLen > 0 ? BigInt(symbolLen - 1) : 0n;
|
|
31
89
|
const symbolCost = this.gasFeeCreateTokenSymbol >> shift;
|
|
@@ -39,7 +97,8 @@ class CreateSeriesFeeOptions extends FeeOptions {
|
|
|
39
97
|
super(gasFeeBase, feeMultiplier);
|
|
40
98
|
this.gasFeeCreateSeriesBase = gasFeeCreateSeriesBase;
|
|
41
99
|
}
|
|
42
|
-
calculateMaxGas() {
|
|
100
|
+
calculateMaxGas(...args) {
|
|
101
|
+
assertNoMeaningfulCount(args, 'CreateSeriesFeeOptions.calculateMaxGas');
|
|
43
102
|
return (this.gasFeeBase + this.gasFeeCreateSeriesBase) * this.feeMultiplier;
|
|
44
103
|
}
|
|
45
104
|
}
|
|
@@ -49,8 +108,9 @@ class MintNftFeeOptions extends FeeOptions {
|
|
|
49
108
|
constructor(gasFeeBase = 10000n, feeMultiplier = 1000n) {
|
|
50
109
|
super(gasFeeBase, feeMultiplier);
|
|
51
110
|
}
|
|
52
|
-
calculateMaxGas() {
|
|
53
|
-
|
|
111
|
+
calculateMaxGas(...args) {
|
|
112
|
+
const count = parseOptionalMintCount(args, 'MintNftFeeOptions.calculateMaxGas');
|
|
113
|
+
return this.gasFeeBase * this.feeMultiplier * count;
|
|
54
114
|
}
|
|
55
115
|
}
|
|
56
116
|
exports.MintNftFeeOptions = MintNftFeeOptions;
|
|
@@ -15,7 +15,7 @@ class MintNonFungibleTxHelper {
|
|
|
15
15
|
// Build a Tx without signing
|
|
16
16
|
static buildTx(carbonTokenId, carbonSeriesId, senderPublicKey, receiverPublicKey, rom, ram, feeOptions, maxData, expiry) {
|
|
17
17
|
const fees = feeOptions ?? new fee_options_js_1.MintNftFeeOptions();
|
|
18
|
-
const maxGas = fees.calculateMaxGas();
|
|
18
|
+
const maxGas = fees.calculateMaxGas(1);
|
|
19
19
|
const msg = new tx_msg_js_1.TxMsg();
|
|
20
20
|
msg.type = tx_types_js_1.TxTypes.MintNonFungible;
|
|
21
21
|
msg.expiry = expiry ?? BigInt(Date.now() + 60000);
|
package/dist/cjs/types/carbon/blockchain/tx-helpers/mint-phantasma-non-fungible-tx-helper.js
CHANGED
|
@@ -43,7 +43,7 @@ class MintPhantasmaNonFungibleTxHelper {
|
|
|
43
43
|
}
|
|
44
44
|
static buildTxCore(tokenId, senderPublicKey, receiverPublicKey, tokens, feeOptions, maxData, expiry) {
|
|
45
45
|
const fees = feeOptions ?? new fee_options_js_1.MintNftFeeOptions();
|
|
46
|
-
const maxGas = fees.calculateMaxGas();
|
|
46
|
+
const maxGas = fees.calculateMaxGas(tokens);
|
|
47
47
|
// This helper only packages the Token.Call ABI surface.
|
|
48
48
|
const args = new index_js_2.MintPhantasmaNonFungibleArgs({
|
|
49
49
|
tokenId,
|
|
@@ -1,12 +1,74 @@
|
|
|
1
1
|
// namespace PhantasmaPhoenix.Protocol.Carbon.Blockchain.TxHelpers
|
|
2
|
+
function assertArgCount(args, max, methodName) {
|
|
3
|
+
if (args.length > max) {
|
|
4
|
+
throw new TypeError(`${methodName} accepts at most ${max} argument${max === 1 ? '' : 's'}`);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function parsePositiveCount(value, methodName) {
|
|
8
|
+
if (typeof value === 'bigint') {
|
|
9
|
+
if (value <= 0n) {
|
|
10
|
+
throw new RangeError(`${methodName} count must be a positive integer`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
16
|
+
throw new RangeError(`${methodName} count must be a positive safe integer`);
|
|
17
|
+
}
|
|
18
|
+
return BigInt(value);
|
|
19
|
+
}
|
|
20
|
+
throw new TypeError(`${methodName} count must be a number or bigint`);
|
|
21
|
+
}
|
|
22
|
+
function parseOptionalCount(args, methodName) {
|
|
23
|
+
assertArgCount(args, 1, methodName);
|
|
24
|
+
return args.length === 0 ? 1n : parsePositiveCount(args[0], methodName);
|
|
25
|
+
}
|
|
26
|
+
function parseOptionalMintCount(args, methodName) {
|
|
27
|
+
assertArgCount(args, 1, methodName);
|
|
28
|
+
if (args.length === 0) {
|
|
29
|
+
return 1n;
|
|
30
|
+
}
|
|
31
|
+
const value = args[0];
|
|
32
|
+
return Array.isArray(value)
|
|
33
|
+
? parsePositiveCount(value.length, methodName)
|
|
34
|
+
: parsePositiveCount(value, methodName);
|
|
35
|
+
}
|
|
36
|
+
function assertNoMeaningfulCount(args, methodName) {
|
|
37
|
+
assertArgCount(args, 1, methodName);
|
|
38
|
+
if (args.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const count = parsePositiveCount(args[0], methodName);
|
|
42
|
+
if (count !== 1n) {
|
|
43
|
+
throw new RangeError(`${methodName} is not count-sensitive; count must be 1 when provided`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function parseOptionalSymbol(args, methodName) {
|
|
47
|
+
assertArgCount(args, 1, methodName);
|
|
48
|
+
if (args.length === 0) {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
const value = args[0];
|
|
52
|
+
if (typeof value === 'string') {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === 'object' &&
|
|
56
|
+
value !== null &&
|
|
57
|
+
'data' in value &&
|
|
58
|
+
typeof value.data === 'string') {
|
|
59
|
+
return value.data;
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError(`${methodName} symbol must be a string or SmallString-like object`);
|
|
62
|
+
}
|
|
2
63
|
/** Base fee options with sensible defaults. */
|
|
3
64
|
export class FeeOptions {
|
|
4
65
|
constructor(gasFeeBase = 10000n, feeMultiplier = 1000n) {
|
|
5
66
|
this.gasFeeBase = gasFeeBase;
|
|
6
67
|
this.feeMultiplier = feeMultiplier;
|
|
7
68
|
}
|
|
8
|
-
calculateMaxGas() {
|
|
9
|
-
|
|
69
|
+
calculateMaxGas(...args) {
|
|
70
|
+
const count = parseOptionalCount(args, 'FeeOptions.calculateMaxGas');
|
|
71
|
+
return this.gasFeeBase * this.feeMultiplier * count;
|
|
10
72
|
}
|
|
11
73
|
}
|
|
12
74
|
/** Fee options for token creation transactions. */
|
|
@@ -17,11 +79,7 @@ export class CreateTokenFeeOptions extends FeeOptions {
|
|
|
17
79
|
this.gasFeeCreateTokenSymbol = gasFeeCreateTokenSymbol;
|
|
18
80
|
}
|
|
19
81
|
calculateMaxGas(...args) {
|
|
20
|
-
|
|
21
|
-
if (args.length > 0 && typeof args[0] === 'object' && args[0] !== null && 'data' in args[0]) {
|
|
22
|
-
const s = args[0];
|
|
23
|
-
symbol = s.data;
|
|
24
|
-
}
|
|
82
|
+
const symbol = parseOptionalSymbol(args, 'CreateTokenFeeOptions.calculateMaxGas');
|
|
25
83
|
const symbolLen = symbol.length;
|
|
26
84
|
const shift = symbolLen > 0 ? BigInt(symbolLen - 1) : 0n;
|
|
27
85
|
const symbolCost = this.gasFeeCreateTokenSymbol >> shift;
|
|
@@ -34,7 +92,8 @@ export class CreateSeriesFeeOptions extends FeeOptions {
|
|
|
34
92
|
super(gasFeeBase, feeMultiplier);
|
|
35
93
|
this.gasFeeCreateSeriesBase = gasFeeCreateSeriesBase;
|
|
36
94
|
}
|
|
37
|
-
calculateMaxGas() {
|
|
95
|
+
calculateMaxGas(...args) {
|
|
96
|
+
assertNoMeaningfulCount(args, 'CreateSeriesFeeOptions.calculateMaxGas');
|
|
38
97
|
return (this.gasFeeBase + this.gasFeeCreateSeriesBase) * this.feeMultiplier;
|
|
39
98
|
}
|
|
40
99
|
}
|
|
@@ -43,7 +102,8 @@ export class MintNftFeeOptions extends FeeOptions {
|
|
|
43
102
|
constructor(gasFeeBase = 10000n, feeMultiplier = 1000n) {
|
|
44
103
|
super(gasFeeBase, feeMultiplier);
|
|
45
104
|
}
|
|
46
|
-
calculateMaxGas() {
|
|
47
|
-
|
|
105
|
+
calculateMaxGas(...args) {
|
|
106
|
+
const count = parseOptionalMintCount(args, 'MintNftFeeOptions.calculateMaxGas');
|
|
107
|
+
return this.gasFeeBase * this.feeMultiplier * count;
|
|
48
108
|
}
|
|
49
109
|
}
|
|
@@ -12,7 +12,7 @@ export class MintNonFungibleTxHelper {
|
|
|
12
12
|
// Build a Tx without signing
|
|
13
13
|
static buildTx(carbonTokenId, carbonSeriesId, senderPublicKey, receiverPublicKey, rom, ram, feeOptions, maxData, expiry) {
|
|
14
14
|
const fees = feeOptions ?? new MintNftFeeOptions();
|
|
15
|
-
const maxGas = fees.calculateMaxGas();
|
|
15
|
+
const maxGas = fees.calculateMaxGas(1);
|
|
16
16
|
const msg = new TxMsg();
|
|
17
17
|
msg.type = TxTypes.MintNonFungible;
|
|
18
18
|
msg.expiry = expiry ?? BigInt(Date.now() + 60000);
|
package/dist/esm/types/carbon/blockchain/tx-helpers/mint-phantasma-non-fungible-tx-helper.js
CHANGED
|
@@ -40,7 +40,7 @@ export class MintPhantasmaNonFungibleTxHelper {
|
|
|
40
40
|
}
|
|
41
41
|
static buildTxCore(tokenId, senderPublicKey, receiverPublicKey, tokens, feeOptions, maxData, expiry) {
|
|
42
42
|
const fees = feeOptions ?? new MintNftFeeOptions();
|
|
43
|
-
const maxGas = fees.calculateMaxGas();
|
|
43
|
+
const maxGas = fees.calculateMaxGas(tokens);
|
|
44
44
|
// This helper only packages the Token.Call ABI surface.
|
|
45
45
|
const args = new MintPhantasmaNonFungibleArgs({
|
|
46
46
|
tokenId,
|
|
@@ -5,19 +5,25 @@ export interface FeeOptionsLike {
|
|
|
5
5
|
}
|
|
6
6
|
/** @deprecated Use `FeeOptionsLike` instead. This compatibility interface will be removed in v1.0. */
|
|
7
7
|
export type IFeeOptions = FeeOptionsLike;
|
|
8
|
+
type CountInput = number | bigint;
|
|
9
|
+
type SymbolInput = string | {
|
|
10
|
+
data: string;
|
|
11
|
+
};
|
|
8
12
|
/** Base fee options with sensible defaults. */
|
|
9
13
|
export declare class FeeOptions implements FeeOptionsLike {
|
|
10
14
|
gasFeeBase: bigint;
|
|
11
15
|
feeMultiplier: bigint;
|
|
12
16
|
constructor(gasFeeBase?: bigint, feeMultiplier?: bigint);
|
|
13
17
|
calculateMaxGas(): bigint;
|
|
18
|
+
calculateMaxGas(count: CountInput): bigint;
|
|
14
19
|
}
|
|
15
20
|
/** Fee options for token creation transactions. */
|
|
16
21
|
export declare class CreateTokenFeeOptions extends FeeOptions implements FeeOptionsLike {
|
|
17
22
|
gasFeeCreateTokenBase: bigint;
|
|
18
23
|
gasFeeCreateTokenSymbol: bigint;
|
|
19
24
|
constructor(gasFeeBase?: bigint, gasFeeCreateTokenBase?: bigint, gasFeeCreateTokenSymbol?: bigint, feeMultiplier?: bigint);
|
|
20
|
-
calculateMaxGas(
|
|
25
|
+
calculateMaxGas(): bigint;
|
|
26
|
+
calculateMaxGas(symbol: SymbolInput): bigint;
|
|
21
27
|
}
|
|
22
28
|
/** Fee options for creating a new series on an NFT token. */
|
|
23
29
|
export declare class CreateSeriesFeeOptions extends FeeOptions implements FeeOptionsLike {
|
|
@@ -29,5 +35,8 @@ export declare class CreateSeriesFeeOptions extends FeeOptions implements FeeOpt
|
|
|
29
35
|
export declare class MintNftFeeOptions extends FeeOptions implements FeeOptionsLike {
|
|
30
36
|
constructor(gasFeeBase?: bigint, feeMultiplier?: bigint);
|
|
31
37
|
calculateMaxGas(): bigint;
|
|
38
|
+
calculateMaxGas(count: CountInput): bigint;
|
|
39
|
+
calculateMaxGas(tokens: readonly unknown[]): bigint;
|
|
32
40
|
}
|
|
41
|
+
export {};
|
|
33
42
|
//# sourceMappingURL=fee-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fee-options.d.ts","sourceRoot":"","sources":["../../../../../../src/types/carbon/blockchain/tx-helpers/fee-options.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;CAC7C;AAED,sGAAsG;AACtG,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC;AAEzC,+CAA+C;AAC/C,qBAAa,UAAW,YAAW,cAAc;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;gBAEV,UAAU,GAAE,MAAgB,EAAE,aAAa,GAAE,MAAe;IAKxE,eAAe,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"fee-options.d.ts","sourceRoot":"","sources":["../../../../../../src/types/carbon/blockchain/tx-helpers/fee-options.ts"],"names":[],"mappings":"AAEA,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;CAC7C;AAED,sGAAsG;AACtG,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC;AAEzC,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAClC,KAAK,WAAW,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AA+E7C,+CAA+C;AAC/C,qBAAa,UAAW,YAAW,cAAc;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;gBAEV,UAAU,GAAE,MAAgB,EAAE,aAAa,GAAE,MAAe;IAKxE,eAAe,IAAI,MAAM;IACzB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;CAK3C;AAED,mDAAmD;AACnD,qBAAa,qBAAsB,SAAQ,UAAW,YAAW,cAAc;IAC7E,qBAAqB,EAAE,MAAM,CAAC;IAC9B,uBAAuB,EAAE,MAAM,CAAC;gBAG9B,UAAU,GAAE,MAAgB,EAC5B,qBAAqB,GAAE,MAAwB,EAC/C,uBAAuB,GAAE,MAAwB,EACjD,aAAa,GAAE,MAAgB;IAOxB,eAAe,IAAI,MAAM;IACzB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM;CAQtD;AAED,6DAA6D;AAC7D,qBAAa,sBAAuB,SAAQ,UAAW,YAAW,cAAc;IAC9E,sBAAsB,EAAE,MAAM,CAAC;gBAG7B,UAAU,GAAE,MAAgB,EAC5B,sBAAsB,GAAE,MAAuB,EAC/C,aAAa,GAAE,MAAgB;IAMxB,eAAe,IAAI,MAAM;CAKnC;AAED,mEAAmE;AACnE,qBAAa,iBAAkB,SAAQ,UAAW,YAAW,cAAc;gBAC7D,UAAU,GAAE,MAAgB,EAAE,aAAa,GAAE,MAAe;IAI/D,eAAe,IAAI,MAAM;IACzB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM;IAC1C,eAAe,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM;CAK7D"}
|