@aeternity/aepp-sdk 15.0.0 → 15.0.1
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/aepp-sdk.browser-script.cjs +1 -1
- package/dist/aepp-sdk.browser-script.cjs.map +1 -1
- package/dist/aepp-sdk.browser.cjs +1 -1
- package/dist/aepp-sdk.browser.cjs.map +1 -1
- package/dist/aepp-sdk.cjs +64 -24
- package/dist/aepp-sdk.cjs.map +1 -1
- package/es/contract/ga.js +3 -3
- package/es/contract/ga.js.map +1 -1
- package/es/index-browser.d.ts +1 -1
- package/es/index-browser.js +1 -1
- package/es/index-browser.js.map +1 -1
- package/es/tx/builder/constants.d.ts +3 -2
- package/es/tx/builder/constants.js +3 -2
- package/es/tx/builder/constants.js.map +1 -1
- package/es/tx/builder/field-types/abi-version.js +6 -4
- package/es/tx/builder/field-types/abi-version.js.map +1 -1
- package/es/tx/builder/field-types/ct-version.d.ts +5 -0
- package/es/tx/builder/field-types/ct-version.js +13 -1
- package/es/tx/builder/field-types/ct-version.js.map +1 -1
- package/es/tx/builder/field-types/fee.js +4 -4
- package/es/tx/builder/field-types/fee.js.map +1 -1
- package/es/tx/builder/field-types/gas-price.js +12 -8
- package/es/tx/builder/field-types/gas-price.js.map +1 -1
- package/es/tx/builder/protocol-parameters.d.ts +14 -3
- package/es/tx/builder/protocol-parameters.js +25 -5
- package/es/tx/builder/protocol-parameters.js.map +1 -1
- package/package.json +14 -2
package/dist/aepp-sdk.cjs
CHANGED
|
@@ -7373,6 +7373,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
7373
7373
|
getExecutionCostBySignedTx: () => (/* reexport */ getExecutionCostBySignedTx),
|
|
7374
7374
|
getExecutionCostUsingNode: () => (/* reexport */ getExecutionCostUsingNode),
|
|
7375
7375
|
getFileSystem: () => (/* reexport */ getFileSystem),
|
|
7376
|
+
getFloorGasPrice: () => (/* reexport */ getFloorGasPrice),
|
|
7376
7377
|
getGeneration: () => (/* reexport */ getGeneration),
|
|
7377
7378
|
getHeight: () => (/* reexport */ getHeight),
|
|
7378
7379
|
getKeyBlock: () => (/* reexport */ getKeyBlock),
|
|
@@ -9249,8 +9250,9 @@ const MAX_AUTH_FUN_GAS = 50000;
|
|
|
9249
9250
|
* The consensus minimum gas price as it was at the moment of the SDK release.
|
|
9250
9251
|
* @category transaction builder
|
|
9251
9252
|
* @deprecated a node may run another minimum gas price, and this constant is wrong on it. Use
|
|
9252
|
-
* `(await getCachedProtocolParameters(node))
|
|
9253
|
-
* reports
|
|
9253
|
+
* `getFloorGasPrice(await getCachedProtocolParameters(node))` to price a transaction for the
|
|
9254
|
+
* connected node — the consensus minimum it reports is below what its miner accepts on a public
|
|
9255
|
+
* network. `defaultProtocolParameters.minGasPrice` is this constant.
|
|
9254
9256
|
*/
|
|
9255
9257
|
const MIN_GAS_PRICE = 1e9; // TODO: don't use number for ae
|
|
9256
9258
|
/**
|
|
@@ -10101,6 +10103,18 @@ function getProtocolDetails(protocolVersion, type) {
|
|
|
10101
10103
|
abiVersion: protocol.abiVersion[0]
|
|
10102
10104
|
};
|
|
10103
10105
|
}
|
|
10106
|
+
|
|
10107
|
+
/**
|
|
10108
|
+
* Whether all known consensus protocols pick the same versions for `type`, so asking node for its
|
|
10109
|
+
* protocol can't change them.
|
|
10110
|
+
*/
|
|
10111
|
+
function isProtocolIndependent(type) {
|
|
10112
|
+
const [first, ...others] = Object.keys(ProtocolToVmAbi).map(protocol => getProtocolDetails(+protocol, type));
|
|
10113
|
+
return others.every(({
|
|
10114
|
+
vmVersion,
|
|
10115
|
+
abiVersion
|
|
10116
|
+
}) => vmVersion === first.vmVersion && abiVersion === first.abiVersion);
|
|
10117
|
+
}
|
|
10104
10118
|
/* harmony default export */ const ct_version = ({
|
|
10105
10119
|
serialize(value, params, {
|
|
10106
10120
|
consensusProtocolVersion = ConsensusProtocolVersion.Ceres
|
|
@@ -10113,7 +10127,7 @@ function getProtocolDetails(protocolVersion, type) {
|
|
|
10113
10127
|
options) {
|
|
10114
10128
|
if (value != null) return value;
|
|
10115
10129
|
if (options.consensusProtocolVersion != null) return undefined;
|
|
10116
|
-
if (
|
|
10130
|
+
if (isProtocolIndependent('contract-create')) return undefined;
|
|
10117
10131
|
if (options.onNode != null) {
|
|
10118
10132
|
return getProtocolDetails((await options.onNode.getNodeInfo()).consensusProtocolVersion, 'contract-create');
|
|
10119
10133
|
}
|
|
@@ -10148,10 +10162,12 @@ const serializeAsIsParam = Symbol('serializeAsIs');
|
|
|
10148
10162
|
;// ./src/tx/builder/field-types/abi-version.ts
|
|
10149
10163
|
|
|
10150
10164
|
|
|
10165
|
+
function getKind(tag) {
|
|
10166
|
+
return Tag.ContractCallTx === tag || Tag.GaMetaTx === tag ? 'contract-call' : 'oracle-call';
|
|
10167
|
+
}
|
|
10151
10168
|
/* harmony default export */ const abi_version = ({
|
|
10152
10169
|
_getProtocolDetails(c, tag) {
|
|
10153
|
-
|
|
10154
|
-
return getProtocolDetails(c, kind).abiVersion;
|
|
10170
|
+
return getProtocolDetails(c, getKind(tag)).abiVersion;
|
|
10155
10171
|
},
|
|
10156
10172
|
serialize(value, {
|
|
10157
10173
|
tag
|
|
@@ -10168,7 +10184,7 @@ const serializeAsIsParam = Symbol('serializeAsIs');
|
|
|
10168
10184
|
options) {
|
|
10169
10185
|
if (value != null) return value;
|
|
10170
10186
|
if (options.consensusProtocolVersion != null) return undefined;
|
|
10171
|
-
if (
|
|
10187
|
+
if (isProtocolIndependent(getKind(tag))) return undefined;
|
|
10172
10188
|
if (options.onNode != null) {
|
|
10173
10189
|
return this._getProtocolDetails((await options.onNode.getNodeInfo()).consensusProtocolVersion, tag);
|
|
10174
10190
|
}
|
|
@@ -10401,7 +10417,7 @@ const defaultProtocolParameters = freezeParameters({
|
|
|
10401
10417
|
[AbiVersion.Fate]: 5 * BASE_GAS
|
|
10402
10418
|
},
|
|
10403
10419
|
[Tag.ContractCallTx]: {
|
|
10404
|
-
[AbiVersion.Sophia]:
|
|
10420
|
+
[AbiVersion.Sophia]: 30 * BASE_GAS,
|
|
10405
10421
|
[AbiVersion.Fate]: 12 * BASE_GAS
|
|
10406
10422
|
},
|
|
10407
10423
|
[Tag.GaAttachTx]: {
|
|
@@ -10591,8 +10607,9 @@ function checkRaiseNotExcessive(what, raise) {
|
|
|
10591
10607
|
function checkParametersNotExcessive(parameters) {
|
|
10592
10608
|
const d = defaultProtocolParameters;
|
|
10593
10609
|
const defaultMinGasPrice = Number(d.minGasPrice);
|
|
10594
|
-
//
|
|
10595
|
-
//
|
|
10610
|
+
// no network runs a consensus minimum of 0 (node reports 1e6 since Minerva), and with a miner
|
|
10611
|
+
// minimum of 0 as well it makes every fee 0 and the `minFee / getFloorGasPrice` of the
|
|
10612
|
+
// demand-based fee a division by zero
|
|
10596
10613
|
if (parameters.minGasPrice < 1n) {
|
|
10597
10614
|
throw new NodeError(`Node reports the minimum gas price as ${parameters.minGasPrice}, a transaction can't be` + ' priced against it. Provide `protocolParameters` in options to build a transaction' + ' against these parameters anyway.');
|
|
10598
10615
|
}
|
|
@@ -10610,10 +10627,13 @@ function checkParametersNotExcessive(parameters) {
|
|
|
10610
10627
|
gasRaises.push(checkNotExcessive(`the base gas of ${Tag[+tag]}`, gas, defaultBaseGasOf(+tag)));
|
|
10611
10628
|
});
|
|
10612
10629
|
Object.entries(parameters.contractTxBaseGas).forEach(([tag, byAbiVersion]) => {
|
|
10613
|
-
const sdkValue = defaultBaseGasOf(+tag);
|
|
10614
10630
|
Object.entries(byAbiVersion).forEach(([abiVersion, gas]) => {
|
|
10615
10631
|
const name = `the base gas of ${Tag[+tag]} at abi version ${abiVersion}`;
|
|
10616
|
-
|
|
10632
|
+
// an abi version the SDK release prices is bounded by its own value — the budget of the
|
|
10633
|
+
// priciest one is not a budget for the others. An abi version it doesn't price is charged
|
|
10634
|
+
// the maximum of the ones it does, see `getTxBaseGas`
|
|
10635
|
+
const sdkValue = d.contractTxBaseGas[+tag]?.[+abiVersion];
|
|
10636
|
+
gasRaises.push(checkNotExcessive(name, gas, sdkValue !== null && sdkValue !== void 0 ? sdkValue : defaultBaseGasOf(+tag)));
|
|
10617
10637
|
});
|
|
10618
10638
|
});
|
|
10619
10639
|
const defaultStateGasRatio = defaultStateGasPerBlock.part / defaultStateGasPerBlock.whole;
|
|
@@ -10678,6 +10698,22 @@ function getGasLimitDivisor(parameters, tag) {
|
|
|
10678
10698
|
if (raises == null) return 1;
|
|
10679
10699
|
return tag === Tag.GaMetaTx ? raises.maxAuthFunGas : raises.blockGasLimit;
|
|
10680
10700
|
}
|
|
10701
|
+
|
|
10702
|
+
/**
|
|
10703
|
+
* Gas price the minimum fee is counted at and the `gasPrice` of a contract transaction defaults
|
|
10704
|
+
* to: the miner minimum when it is above the consensus one. Node reads the price a transaction
|
|
10705
|
+
* pays as the lower of its `gasPrice` and its fee over its fee gas, so pricing either below the
|
|
10706
|
+
* miner minimum gets it refused with `too_low_gas_price_for_miner`.
|
|
10707
|
+
* @category transaction builder
|
|
10708
|
+
* @param parameters - Parameters a transaction is built against
|
|
10709
|
+
*/
|
|
10710
|
+
function getFloorGasPrice(parameters) {
|
|
10711
|
+
const {
|
|
10712
|
+
minGasPrice,
|
|
10713
|
+
minMinerGasPrice
|
|
10714
|
+
} = parameters;
|
|
10715
|
+
return minMinerGasPrice > minGasPrice ? minMinerGasPrice : minGasPrice;
|
|
10716
|
+
}
|
|
10681
10717
|
function mapByTxType(entries, map) {
|
|
10682
10718
|
return Object.fromEntries(entries.map(([txType, value]) => [getTag(txType), map(value)])
|
|
10683
10719
|
// a transaction type the SDK doesn't implement, or won't ever build (`ChannelClientReconnectTx`)
|
|
@@ -10919,9 +10955,11 @@ async function getCachedIncreasedGasPrice(nodeOrProxy, parameters) {
|
|
|
10919
10955
|
const [protocolParameters, demandGasPrice] = await Promise.all([parameters !== null && parameters !== void 0 ? parameters : getCachedProtocolParameters(node), demandEntry.gasPrice]);
|
|
10920
10956
|
let gasPrice = demandGasPrice;
|
|
10921
10957
|
|
|
10922
|
-
// 0n means "the consensus minimum",
|
|
10923
|
-
const
|
|
10924
|
-
if (gasPrice <
|
|
10958
|
+
// 0n means "the consensus minimum", only a miner asking for more lifts it
|
|
10959
|
+
const floorGasPrice = getFloorGasPrice(protocolParameters);
|
|
10960
|
+
if (floorGasPrice > protocolParameters.minGasPrice && gasPrice < floorGasPrice) {
|
|
10961
|
+
gasPrice = floorGasPrice;
|
|
10962
|
+
}
|
|
10925
10963
|
|
|
10926
10964
|
// the ceiling goes down by the factor the parameters raise the fee gas by — see
|
|
10927
10965
|
// `getGasPriceDivisor`. Counted in thousandths so that a hard fork raising the gas a few percent
|
|
@@ -10962,11 +11000,13 @@ async function getCachedIncreasedGasPrice(nodeOrProxy, parameters) {
|
|
|
10962
11000
|
serializeAettos(value, params, {
|
|
10963
11001
|
protocolParameters = defaultProtocolParameters
|
|
10964
11002
|
}) {
|
|
10965
|
-
|
|
10966
|
-
|
|
11003
|
+
// defaulted and checked against the floor `prepare` applies, for a build that gets no
|
|
11004
|
+
// `prepare` — see `getFloorGasPrice`. Provide `protocolParameters` to build for another node
|
|
11005
|
+
const floorGasPrice = getFloorGasPrice(protocolParameters).toString();
|
|
11006
|
+
if (value == null) return floorGasPrice;
|
|
10967
11007
|
if (params[serializeAsIsParam] === true) return value;
|
|
10968
|
-
if (new (external_bignumber_js_default())(value).lt(
|
|
10969
|
-
throw new IllegalArgumentError(`Gas price ${value} must be bigger than ${
|
|
11008
|
+
if (new (external_bignumber_js_default())(value).lt(floorGasPrice)) {
|
|
11009
|
+
throw new IllegalArgumentError(`Gas price ${value} must be bigger than ${floorGasPrice}`);
|
|
10970
11010
|
}
|
|
10971
11011
|
return value;
|
|
10972
11012
|
}
|
|
@@ -11083,12 +11123,12 @@ function buildGas(builtTx, unpackTx, buildTx, protocolParameters) {
|
|
|
11083
11123
|
* @param rebuildTx - Callback to get built transaction with specific fee
|
|
11084
11124
|
*/
|
|
11085
11125
|
function calculateMinFee(rebuildTx, unpackTx, buildTx, protocolParameters) {
|
|
11086
|
-
const
|
|
11126
|
+
const floorGasPrice = new (external_bignumber_js_default())(getFloorGasPrice(protocolParameters).toString());
|
|
11087
11127
|
let fee = new (external_bignumber_js_default())(0);
|
|
11088
11128
|
let previousFee;
|
|
11089
11129
|
do {
|
|
11090
11130
|
previousFee = fee;
|
|
11091
|
-
fee =
|
|
11131
|
+
fee = floorGasPrice.times(buildGas(rebuildTx(fee), unpackTx, buildTx, protocolParameters));
|
|
11092
11132
|
} while (!fee.eq(previousFee));
|
|
11093
11133
|
return fee;
|
|
11094
11134
|
}
|
|
@@ -11126,7 +11166,7 @@ const gasPricePrefix = '_gas-price:';
|
|
|
11126
11166
|
const minFee = calculateMinFee(fee => rebuildTx({
|
|
11127
11167
|
_computingMinFee: fee
|
|
11128
11168
|
}), unpackTx, buildTx, protocolParameters);
|
|
11129
|
-
const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(protocolParameters.
|
|
11169
|
+
const value = _value?.startsWith(gasPricePrefix) === true ? minFee.dividedBy(getFloorGasPrice(protocolParameters).toString()).times(_value.replace(gasPricePrefix, '')) : new (external_bignumber_js_default())(_value !== null && _value !== void 0 ? _value : minFee);
|
|
11130
11170
|
if (minFee.gt(value)) {
|
|
11131
11171
|
if (_canIncreaseFee === true) return minFee.toFixed();
|
|
11132
11172
|
throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);
|
|
@@ -23885,9 +23925,9 @@ async function buildAuthTxHashInternal(transaction, {
|
|
|
23885
23925
|
let payload = hash(concatBuffers([Buffer.from(nodeNetworkId), decode(transaction)]));
|
|
23886
23926
|
if (fee == null) throw new ArgumentError('fee', 'provided (in Ceres)', fee);
|
|
23887
23927
|
if (gasPrice == null) throw new ArgumentError('gasPrice', 'provided (in Ceres)', gasPrice);
|
|
23888
|
-
// the entry checks `gasPrice`
|
|
23889
|
-
//
|
|
23890
|
-
//
|
|
23928
|
+
// the entry checks `gasPrice` the same way a transaction does, so it needs the same parameters
|
|
23929
|
+
// — without them a `gasPrice` correct for the network this node runs is rejected whenever that
|
|
23930
|
+
// network prices a transaction below the SDK release.
|
|
23891
23931
|
// Not requested at all when there is nothing to check, so that re-deriving the hash of an
|
|
23892
23932
|
// existing transaction needs no round trip and works on a transaction of another network
|
|
23893
23933
|
payload = hash(decode(packEntry({
|