-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathassertions.ts
More file actions
34 lines (28 loc) · 833 Bytes
/
assertions.ts
File metadata and controls
34 lines (28 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { BN_ASSERT_DECIMALS_OP } from '@/enums'
import { assert } from '@/helpers'
import { BN } from './bn'
export const assertDecimals = (
currentDecimals: number,
targetDecimals: number,
op: BN_ASSERT_DECIMALS_OP,
) => {
assertDecimalsInteger(currentDecimals)
assert(
targetDecimals < BN.precision,
'Target decimals cannot be greater than the BN config precision',
)
if (op === BN_ASSERT_DECIMALS_OP.GREATER) {
assert(
targetDecimals > currentDecimals,
'Target decimals cannot be less than the current decimals',
)
return
}
assert(
targetDecimals < currentDecimals,
'Target decimals cannot be greater than the current decimals',
)
}
export const assertDecimalsInteger = (decimals: number) => {
assert(Number.isInteger(decimals), 'Decimals must be an integer')
}