Commit 97af36f 1 parent b984829 commit 97af36f Copy full SHA for 97af36f
File tree 1 file changed +10
-5
lines changed
contracts/suilend/sources
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ module suilend::decimal {
14
14
}
15
15
}
16
16
17
+ public fun from_u128 (v: u128 ): Decimal {
18
+ Decimal {
19
+ value: (v as u256 ) * WAD
20
+ }
21
+ }
22
+
17
23
public fun from_percent (v: u8 ): Decimal {
18
24
Decimal {
19
25
value: (v as u256 ) * WAD / 100 ,
@@ -159,7 +165,8 @@ module suilend::decimal_tests {
159
165
from,
160
166
from_percent,
161
167
saturating_sub,
162
- saturating_floor
168
+ saturating_floor,
169
+ from_u128
163
170
};
164
171
165
172
#[test]
@@ -180,10 +187,8 @@ module suilend::decimal_tests {
180
187
assert !(saturating_sub (a, b) == from (0 ), 0 );
181
188
assert !(saturating_sub (b, a) == from (1 ), 0 );
182
189
assert !(saturating_floor (from (18446744073709551615 )) == 18446744073709551615 , 0 );
183
- assert !(
184
- saturating_floor (add (from (18446744073709551615 ), from (1 ))) == 18446744073709551615 ,
185
- 0 ,
186
- );
190
+ assert !(saturating_floor (add (from (18446744073709551615 ), from (1 ))) == 18446744073709551615 , 0 );
191
+ assert !(from_u128 (340282366920938463463374607431768211455 ).add (from (1 )).to_scaled_val () == 340282366920938463463374607431768211456 * 1000000000000000000 , 0 );
187
192
}
188
193
189
194
#[test]
You can’t perform that action at this time.
0 commit comments