xrpl 4.3.0-smartescrow.0 → 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 +5175 -1594
- package/build/xrpl-latest.js.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.d.ts +2 -1
- package/dist/npm/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/Wallet/defaultFaucets.js +5 -0
- package/dist/npm/Wallet/defaultFaucets.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/methods/subscribe.d.ts +2 -1
- package/dist/npm/models/methods/subscribe.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/Wallet/defaultFaucets.d.ts +2 -1
- package/dist/npm/src/Wallet/defaultFaucets.d.ts.map +1 -1
- package/dist/npm/src/Wallet/defaultFaucets.js +5 -0
- package/dist/npm/src/Wallet/defaultFaucets.js.map +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/methods/subscribe.d.ts +2 -1
- package/dist/npm/src/models/methods/subscribe.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/Wallet/defaultFaucets.ts +6 -0
- 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/methods/subscribe.ts +5 -1
- package/src/models/transactions/NFTokenMint.ts +37 -0
- package/src/models/transactions/escrowFinish.ts +2 -0
- package/src/sugar/autofill.ts +51 -41
@@ -30,6 +30,11 @@ export interface ServerStateResponse extends BaseResponse {
|
|
30
30
|
hash: string
|
31
31
|
reserve_base: number
|
32
32
|
reserve_inc: number
|
33
|
+
|
34
|
+
extension_compute: number
|
35
|
+
extension_size: number
|
36
|
+
gas_price: number
|
37
|
+
|
33
38
|
seq: number
|
34
39
|
}
|
35
40
|
io_latency_ms: number
|
@@ -69,6 +74,11 @@ export interface ServerStateResponse extends BaseResponse {
|
|
69
74
|
hash: string
|
70
75
|
reserve_base: number
|
71
76
|
reserve_inc: number
|
77
|
+
|
78
|
+
extension_compute: number
|
79
|
+
extension_size: number
|
80
|
+
gas_price: number
|
81
|
+
|
72
82
|
seq: number
|
73
83
|
}
|
74
84
|
validation_quorum: number
|
@@ -275,13 +275,17 @@ interface TransactionStreamBase<
|
|
275
275
|
* The approximate time this ledger was closed, in date time string format.
|
276
276
|
* Always uses the UTC time zone.
|
277
277
|
*/
|
278
|
-
close_time_iso: string
|
278
|
+
close_time_iso: Version extends typeof RIPPLED_API_V2 ? string : never
|
279
279
|
/** String Transaction result code. */
|
280
280
|
engine_result: string
|
281
281
|
/** Numeric transaction response code, if applicable. */
|
282
282
|
engine_result_code: number
|
283
283
|
/** Human-readable explanation for the transaction response. */
|
284
284
|
engine_result_message: string
|
285
|
+
/**
|
286
|
+
* The unique hash identifier of the transaction.
|
287
|
+
*/
|
288
|
+
hash?: Version extends typeof RIPPLED_API_V2 ? string : never
|
285
289
|
/**
|
286
290
|
* The ledger index of the current in-progress ledger version for which this
|
287
291
|
* transaction is currently proposed.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { ValidationError } from '../../errors'
|
2
|
+
import { Amount } from '../common'
|
2
3
|
import { isHex } from '../utils'
|
3
4
|
|
4
5
|
import {
|
@@ -6,6 +7,8 @@ import {
|
|
6
7
|
BaseTransaction,
|
7
8
|
GlobalFlags,
|
8
9
|
isAccount,
|
10
|
+
isAmount,
|
11
|
+
isNumber,
|
9
12
|
validateBaseTransaction,
|
10
13
|
validateOptionalField,
|
11
14
|
} from './common'
|
@@ -104,12 +107,34 @@ export interface NFTokenMint extends BaseTransaction {
|
|
104
107
|
* set to `undefined` value if you do not use it.
|
105
108
|
*/
|
106
109
|
URI?: string | null
|
110
|
+
/**
|
111
|
+
* Indicates the amount expected for the Token.
|
112
|
+
*
|
113
|
+
* The amount can be zero. This would indicate that the account is giving
|
114
|
+
* the token away free, either to anyone at all, or to the account identified
|
115
|
+
* by the Destination field.
|
116
|
+
*/
|
117
|
+
Amount?: Amount
|
118
|
+
/**
|
119
|
+
* Indicates the time after which the offer will no longer
|
120
|
+
* be valid. The value is the number of seconds since the
|
121
|
+
* Ripple Epoch.
|
122
|
+
*/
|
123
|
+
Expiration?: number
|
124
|
+
/**
|
125
|
+
* If present, indicates that this offer may only be
|
126
|
+
* accepted by the specified account. Attempts by other
|
127
|
+
* accounts to accept this offer MUST fail.
|
128
|
+
*/
|
129
|
+
Destination?: Account
|
107
130
|
Flags?: number | NFTokenMintFlagsInterface
|
108
131
|
}
|
109
132
|
|
110
133
|
export interface NFTokenMintMetadata extends TransactionMetadataBase {
|
111
134
|
// rippled 1.11.0 or later
|
112
135
|
nftoken_id?: string
|
136
|
+
// if Amount is present
|
137
|
+
offer_id?: string
|
113
138
|
}
|
114
139
|
|
115
140
|
/**
|
@@ -140,4 +165,16 @@ export function validateNFTokenMint(tx: Record<string, unknown>): void {
|
|
140
165
|
if (tx.NFTokenTaxon == null) {
|
141
166
|
throw new ValidationError('NFTokenMint: missing field NFTokenTaxon')
|
142
167
|
}
|
168
|
+
|
169
|
+
if (tx.Amount == null) {
|
170
|
+
if (tx.Expiration != null || tx.Destination != null) {
|
171
|
+
throw new ValidationError(
|
172
|
+
'NFTokenMint: Amount is required when Expiration or Destination is present',
|
173
|
+
)
|
174
|
+
}
|
175
|
+
}
|
176
|
+
|
177
|
+
validateOptionalField(tx, 'Amount', isAmount)
|
178
|
+
validateOptionalField(tx, 'Expiration', isNumber)
|
179
|
+
validateOptionalField(tx, 'Destination', isAccount)
|
143
180
|
}
|
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
|
*
|