@xyo-network/xl1-protocol 1.4.1 → 1.4.3
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/index.d.ts +53 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +94 -14
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/node/index.mjs +94 -14
- package/dist/node/index.mjs.map +1 -1
- package/dist/types/constants/TransactionGasCosts.d.ts +25 -6
- package/dist/types/constants/TransactionGasCosts.d.ts.map +1 -1
- package/dist/types/transaction/TransactionFeesFields.d.ts +1 -1
- package/dist/types/transaction/TransactionFeesFields.d.ts.map +1 -1
- package/dist/types/xl1/XL1.d.ts +31 -8
- package/dist/types/xl1/XL1.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/transaction/TransactionFeesFields.ts +9 -11
- package/src/xl1/XL1.ts +110 -9
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Hex } from '@xylabs/hex'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
xl1ConvertFactor,
|
|
6
|
-
} from '../xl1/index.ts'
|
|
3
|
+
import type { AttoXL1 } from '../xl1/index.ts'
|
|
4
|
+
import { MicroXL1 } from '../xl1/index.ts'
|
|
7
5
|
|
|
8
6
|
export interface TransactionFeesBigInt {
|
|
9
7
|
base: AttoXL1
|
|
@@ -21,15 +19,15 @@ export interface TransactionFeesFields {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export const minTransactionFees: TransactionFeesBigInt = {
|
|
24
|
-
base:
|
|
25
|
-
gasPrice:
|
|
26
|
-
gasLimit:
|
|
27
|
-
priority:
|
|
22
|
+
base: MicroXL1(1000n).toAtto(),
|
|
23
|
+
gasPrice: MicroXL1(1n).toAtto(),
|
|
24
|
+
gasLimit: MicroXL1(1000n).toAtto(),
|
|
25
|
+
priority: MicroXL1(0n).toAtto(),
|
|
28
26
|
} as const
|
|
29
27
|
|
|
30
28
|
export const defaultTransactionFees: TransactionFeesBigInt = {
|
|
31
29
|
base: minTransactionFees.base,
|
|
32
|
-
gasPrice:
|
|
33
|
-
gasLimit:
|
|
34
|
-
priority:
|
|
30
|
+
gasPrice: MicroXL1(10n).toAtto(),
|
|
31
|
+
gasLimit: MicroXL1(1_000_000n).toAtto(),
|
|
32
|
+
priority: minTransactionFees.priority,
|
|
35
33
|
} as const
|
package/src/xl1/XL1.ts
CHANGED
|
@@ -6,17 +6,103 @@ export type PicoXL1 = bigint & { readonly _tag: 'PicoXL1' } // 1e-6 [XL1 * 1e12
|
|
|
6
6
|
export type FemtoXL1 = bigint & { readonly _tag: 'FemtoXL1' } // 1e-3 [XL1 * 1e15 = femtoXL1] [femtoXL1 / 1e15 = XL1]
|
|
7
7
|
export type AttoXL1 = bigint & { readonly _tag: 'AttoXL1' } // 1e-0 [XL1 * 1e18 = attoXL1] [attoXL1 / 1e18 = XL1]
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
type XL1Units = 'xl1' | 'milli' | 'micro' | 'nano' | 'pico' | 'femto' | 'atto'
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export const PicoXL1: TypingFunc<PicoXL1> = (value: bigint): PicoXL1 => value as PicoXL1
|
|
16
|
-
export const FemtoXL1: TypingFunc<FemtoXL1> = (value: bigint): FemtoXL1 => value as FemtoXL1
|
|
17
|
-
export const AttoXL1: TypingFunc<AttoXL1> = (value: bigint): AttoXL1 => value as AttoXL1
|
|
11
|
+
export type TypingFunc<T extends bigint> = {
|
|
12
|
+
(value: bigint): T
|
|
13
|
+
toAtto: () => AttoXL1
|
|
14
|
+
}
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
export function XL1(value: bigint): XL1 & { toAtto(): AttoXL1 } {
|
|
17
|
+
const xl1Value = value as XL1
|
|
18
|
+
|
|
19
|
+
return new Proxy(xl1Value, {
|
|
20
|
+
get(target, prop) {
|
|
21
|
+
if (prop === 'toAtto') {
|
|
22
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.xl1)
|
|
23
|
+
}
|
|
24
|
+
return Reflect.get(target, prop)
|
|
25
|
+
},
|
|
26
|
+
}) as XL1 & { toAtto(): AttoXL1 }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function MilliXL1(value: bigint): MilliXL1 & { toAtto(): AttoXL1 } {
|
|
30
|
+
const xl1Value = value as MilliXL1
|
|
31
|
+
|
|
32
|
+
return new Proxy(xl1Value, {
|
|
33
|
+
get(target, prop) {
|
|
34
|
+
if (prop === 'toAtto') {
|
|
35
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.milli)
|
|
36
|
+
}
|
|
37
|
+
return Reflect.get(target, prop)
|
|
38
|
+
},
|
|
39
|
+
}) as MilliXL1 & { toAtto(): AttoXL1 }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function MicroXL1(value: bigint): MicroXL1 & { toAtto(): AttoXL1 } {
|
|
43
|
+
const xl1Value = value as MicroXL1
|
|
44
|
+
|
|
45
|
+
return new Proxy(xl1Value, {
|
|
46
|
+
get(target, prop) {
|
|
47
|
+
if (prop === 'toAtto') {
|
|
48
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.micro)
|
|
49
|
+
}
|
|
50
|
+
return Reflect.get(target, prop)
|
|
51
|
+
},
|
|
52
|
+
}) as MicroXL1 & { toAtto(): AttoXL1 }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function NanoXL1(value: bigint): NanoXL1 & { toAtto(): AttoXL1 } {
|
|
56
|
+
const xl1Value = value as NanoXL1
|
|
57
|
+
|
|
58
|
+
return new Proxy(xl1Value, {
|
|
59
|
+
get(target, prop) {
|
|
60
|
+
if (prop === 'toAtto') {
|
|
61
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.nano)
|
|
62
|
+
}
|
|
63
|
+
return Reflect.get(target, prop)
|
|
64
|
+
},
|
|
65
|
+
}) as NanoXL1 & { toAtto(): AttoXL1 }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function PicoXL1(value: bigint): PicoXL1 & { toAtto(): AttoXL1 } {
|
|
69
|
+
const xl1Value = value as PicoXL1
|
|
70
|
+
|
|
71
|
+
return new Proxy(xl1Value, {
|
|
72
|
+
get(target, prop) {
|
|
73
|
+
if (prop === 'toAtto') {
|
|
74
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.pico)
|
|
75
|
+
}
|
|
76
|
+
return Reflect.get(target, prop)
|
|
77
|
+
},
|
|
78
|
+
}) as PicoXL1 & { toAtto(): AttoXL1 }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function FemtoXL1(value: bigint): FemtoXL1 & { toAtto(): AttoXL1 } {
|
|
82
|
+
const xl1Value = value as FemtoXL1
|
|
83
|
+
|
|
84
|
+
return new Proxy(xl1Value, {
|
|
85
|
+
get(target, prop) {
|
|
86
|
+
if (prop === 'toAtto') {
|
|
87
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.femto)
|
|
88
|
+
}
|
|
89
|
+
return Reflect.get(target, prop)
|
|
90
|
+
},
|
|
91
|
+
}) as FemtoXL1 & { toAtto(): AttoXL1 }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function AttoXL1(value: bigint): AttoXL1 & { toAtto(): AttoXL1 } {
|
|
95
|
+
const xl1Value = value as AttoXL1
|
|
96
|
+
|
|
97
|
+
return new Proxy(xl1Value, {
|
|
98
|
+
get(target, prop) {
|
|
99
|
+
if (prop === 'toAtto') {
|
|
100
|
+
return () => AttoXL1(target * AttoXL1ConvertFactor.atto)
|
|
101
|
+
}
|
|
102
|
+
return Reflect.get(target, prop)
|
|
103
|
+
},
|
|
104
|
+
}) as AttoXL1 & { toAtto(): AttoXL1 }
|
|
105
|
+
}
|
|
20
106
|
|
|
21
107
|
/** @deprecated use XL1Places and xl1ConvertFactor(unit) instead */
|
|
22
108
|
export const XL1ConvertDict: Record<XL1Units, number> = {
|
|
@@ -39,6 +125,21 @@ export const XL1Places: Record<XL1Units, bigint> = {
|
|
|
39
125
|
atto: 0n,
|
|
40
126
|
} as const
|
|
41
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Convert factor by which a respective unit is multiplied to convert it to AttoXL1 or
|
|
130
|
+
* by which AttoXL1 is divided to convert it to respective unit is multiplied.
|
|
131
|
+
*/
|
|
132
|
+
export const AttoXL1ConvertFactor: Record<XL1Units, bigint> = {
|
|
133
|
+
xl1: 10n ** XL1Places.xl1,
|
|
134
|
+
milli: 10n ** XL1Places.milli,
|
|
135
|
+
micro: 10n ** XL1Places.micro,
|
|
136
|
+
nano: 10n ** XL1Places.nano,
|
|
137
|
+
pico: 10n ** XL1Places.pico,
|
|
138
|
+
femto: 10n ** XL1Places.femto,
|
|
139
|
+
atto: 10n ** XL1Places.atto,
|
|
140
|
+
} as const
|
|
141
|
+
|
|
142
|
+
/** @deprecated use AttoXL1ConvertFactor instead */
|
|
42
143
|
export function xl1ConvertFactor(unit: XL1Units) {
|
|
43
144
|
return 10n ** XL1Places[unit]
|
|
44
145
|
}
|