xrpl 4.3.0-smartescrow.1 → 4.3.0-smartescrow.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/build/xrpl-latest.js +5170 -1594
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/models/common/index.d.ts +4 -1
- package/dist/npm/models/common/index.d.ts.map +1 -1
- package/dist/npm/models/methods/serverInfo.d.ts +6 -0
- package/dist/npm/models/methods/serverInfo.d.ts.map +1 -1
- package/dist/npm/models/methods/serverState.d.ts +6 -0
- package/dist/npm/models/methods/serverState.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.d.ts +5 -0
- package/dist/npm/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/models/transactions/NFTokenMint.js +8 -0
- package/dist/npm/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.d.ts +1 -0
- package/dist/npm/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/snippets/tsconfig.tsbuildinfo +1 -1
- package/dist/npm/src/models/common/index.d.ts +4 -1
- package/dist/npm/src/models/common/index.d.ts.map +1 -1
- package/dist/npm/src/models/methods/serverInfo.d.ts +6 -0
- package/dist/npm/src/models/methods/serverInfo.d.ts.map +1 -1
- package/dist/npm/src/models/methods/serverState.d.ts +6 -0
- package/dist/npm/src/models/methods/serverState.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts +5 -0
- package/dist/npm/src/models/transactions/NFTokenMint.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/NFTokenMint.js +8 -0
- package/dist/npm/src/models/transactions/NFTokenMint.js.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.d.ts +1 -0
- package/dist/npm/src/models/transactions/escrowFinish.d.ts.map +1 -1
- package/dist/npm/src/models/transactions/escrowFinish.js.map +1 -1
- package/dist/npm/src/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/src/sugar/autofill.js +33 -16
- package/dist/npm/src/sugar/autofill.js.map +1 -1
- package/dist/npm/sugar/autofill.d.ts.map +1 -1
- package/dist/npm/sugar/autofill.js +33 -16
- package/dist/npm/sugar/autofill.js.map +1 -1
- package/package.json +3 -3
- package/src/models/common/index.ts +5 -1
- package/src/models/methods/serverInfo.ts +9 -0
- package/src/models/methods/serverState.ts +10 -0
- package/src/models/transactions/NFTokenMint.ts +37 -0
- package/src/models/transactions/escrowFinish.ts +2 -0
- package/src/sugar/autofill.ts +51 -41
package/src/sugar/autofill.ts
CHANGED
@@ -18,6 +18,8 @@ const LEDGER_OFFSET = 20
|
|
18
18
|
const RESTRICTED_NETWORKS = 1024
|
19
19
|
const REQUIRED_NETWORKID_VERSION = '1.11.0'
|
20
20
|
|
21
|
+
const MICRO_DROPS_PER_DROP = 1_000_000
|
22
|
+
|
21
23
|
/**
|
22
24
|
* Determines whether the source rippled version is not later than the target rippled version.
|
23
25
|
* Example usage: isNotLaterRippledVersion('1.10.0', '1.11.0') returns true.
|
@@ -230,13 +232,13 @@ export async function setNextValidSequenceNumber(
|
|
230
232
|
}
|
231
233
|
|
232
234
|
/**
|
233
|
-
* Fetches the
|
235
|
+
* Fetches the owner reserve fee from the server state using the provided client.
|
234
236
|
*
|
235
237
|
* @param client - The client object used to make the request.
|
236
|
-
* @returns A Promise that resolves to the
|
237
|
-
* @throws {Error} Throws an error if the
|
238
|
+
* @returns A Promise that resolves to the owner reserve fee as a BigNumber.
|
239
|
+
* @throws {Error} Throws an error if the owner reserve fee cannot be fetched.
|
238
240
|
*/
|
239
|
-
async function
|
241
|
+
async function fetchOwnerReserveFee(client: Client): Promise<BigNumber> {
|
240
242
|
const response = await client.request({ command: 'server_state' })
|
241
243
|
const fee = response.result.state.validated_ledger?.reserve_inc
|
242
244
|
|
@@ -247,6 +249,17 @@ async function fetchAccountDeleteFee(client: Client): Promise<BigNumber> {
|
|
247
249
|
return new BigNumber(fee)
|
248
250
|
}
|
249
251
|
|
252
|
+
async function fetchGasPrice(client: Client): Promise<BigNumber> {
|
253
|
+
const response = await client.request({ command: 'server_state' })
|
254
|
+
const gasPrice = response.result.state.validated_ledger?.gas_price
|
255
|
+
|
256
|
+
if (gasPrice == null) {
|
257
|
+
return Promise.reject(new Error('Could not fetch Owner Reserve.'))
|
258
|
+
}
|
259
|
+
|
260
|
+
return new BigNumber(gasPrice)
|
261
|
+
}
|
262
|
+
|
250
263
|
/**
|
251
264
|
* Calculates the fee per transaction type.
|
252
265
|
*
|
@@ -255,68 +268,65 @@ async function fetchAccountDeleteFee(client: Client): Promise<BigNumber> {
|
|
255
268
|
* @param [signersCount=0] - The number of signers (default is 0). Only used for multisigning.
|
256
269
|
* @returns A promise that resolves with void. Modifies the `tx` parameter to give it the calculated fee.
|
257
270
|
*/
|
271
|
+
// eslint-disable-next-line max-lines-per-function -- okay here
|
258
272
|
export async function calculateFeePerTransactionType(
|
259
273
|
client: Client,
|
260
274
|
tx: Transaction,
|
261
275
|
signersCount = 0,
|
262
276
|
): Promise<void> {
|
263
|
-
// netFee is usually 0.00001 XRP (10 drops)
|
264
277
|
const netFeeXRP = await getFeeXrp(client)
|
265
|
-
const netFeeDrops = xrpToDrops(netFeeXRP)
|
266
|
-
let baseFee =
|
267
|
-
|
268
|
-
// EscrowFinish Transaction with Fulfillment
|
269
|
-
if (tx.TransactionType === 'EscrowFinish'
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
278
|
+
const netFeeDrops = new BigNumber(xrpToDrops(netFeeXRP))
|
279
|
+
let baseFee = netFeeDrops
|
280
|
+
|
281
|
+
// EscrowFinish Transaction with Fulfillment/ComputationAllowance
|
282
|
+
if (tx.TransactionType === 'EscrowFinish') {
|
283
|
+
if (tx.Fulfillment != null) {
|
284
|
+
const fulfillmentBytesSize: number = Math.ceil(tx.Fulfillment.length / 2)
|
285
|
+
// BaseFee × (33 + (Fulfillment size in bytes / 16))
|
286
|
+
baseFee = netFeeDrops.multipliedBy(
|
287
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- expected use of magic numbers
|
288
|
+
33 + fulfillmentBytesSize / 16,
|
289
|
+
)
|
290
|
+
}
|
291
|
+
if (tx.ComputationAllowance != null) {
|
292
|
+
const gasPrice = await fetchGasPrice(client)
|
293
|
+
const extraFee: BigNumber = gasPrice
|
294
|
+
.multipliedBy(tx.ComputationAllowance)
|
295
|
+
.dividedBy(MICRO_DROPS_PER_DROP)
|
296
|
+
baseFee = baseFee.plus(extraFee)
|
297
|
+
}
|
277
298
|
}
|
278
299
|
// EscrowCreate transaction with FinishFunction
|
279
300
|
if (tx.TransactionType === 'EscrowCreate' && tx.FinishFunction != null) {
|
280
|
-
baseFee =
|
301
|
+
baseFee = baseFee.plus(1000)
|
281
302
|
}
|
282
303
|
|
283
|
-
|
284
|
-
tx.TransactionType
|
285
|
-
|
286
|
-
|
287
|
-
|
304
|
+
const isSpecialTxCost = ['AccountDelete', 'AMMCreate'].includes(
|
305
|
+
tx.TransactionType,
|
306
|
+
)
|
307
|
+
|
308
|
+
if (isSpecialTxCost) {
|
309
|
+
baseFee = await fetchOwnerReserveFee(client)
|
288
310
|
}
|
289
311
|
|
290
312
|
/*
|
291
313
|
* Multi-signed Transaction
|
292
|
-
*
|
314
|
+
* BaseFee × (1 + Number of Signatures Provided)
|
293
315
|
*/
|
294
316
|
if (signersCount > 0) {
|
295
|
-
baseFee = BigNumber.sum(baseFee,
|
317
|
+
baseFee = BigNumber.sum(baseFee, netFeeDrops.multipliedBy(1 + signersCount))
|
296
318
|
}
|
297
319
|
|
298
320
|
const maxFeeDrops = xrpToDrops(client.maxFeeXRP)
|
299
|
-
const totalFee =
|
300
|
-
|
301
|
-
|
302
|
-
: BigNumber.min(baseFee, maxFeeDrops)
|
321
|
+
const totalFee = isSpecialTxCost
|
322
|
+
? baseFee
|
323
|
+
: BigNumber.min(baseFee, maxFeeDrops)
|
303
324
|
|
304
325
|
// Round up baseFee and return it as a string
|
305
|
-
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-magic-numbers --
|
326
|
+
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-magic-numbers, require-atomic-updates -- safe reassignment.
|
306
327
|
tx.Fee = totalFee.dp(0, BigNumber.ROUND_CEIL).toString(10)
|
307
328
|
}
|
308
329
|
|
309
|
-
/**
|
310
|
-
* Scales the given value by multiplying it with the provided multiplier.
|
311
|
-
*
|
312
|
-
* @param value - The value to be scaled.
|
313
|
-
* @param multiplier - The multiplier to scale the value.
|
314
|
-
* @returns The scaled value as a string.
|
315
|
-
*/
|
316
|
-
function scaleValue(value, multiplier): string {
|
317
|
-
return new BigNumber(value).times(multiplier).toString()
|
318
|
-
}
|
319
|
-
|
320
330
|
/**
|
321
331
|
* Sets the latest validated ledger sequence for the transaction.
|
322
332
|
*
|