File tree 8 files changed +24
-30
lines changed
modules/initia_stdlib/sources
8 files changed +24
-30
lines changed Original file line number Diff line number Diff line change @@ -77,7 +77,10 @@ impl BuiltPackage {
77
77
new_config. architecture = None ;
78
78
new_config. generate_docs = false ;
79
79
new_config. generate_move_model = true ;
80
- new_config. compiler_config . known_attributes = metadata:: get_all_attribute_names ( ) . clone ( ) ;
80
+ new_config
81
+ . compiler_config
82
+ . known_attributes
83
+ . clone_from ( metadata:: get_all_attribute_names ( ) ) ;
81
84
82
85
let ( mut package, model_opt) =
83
86
new_config. compile_package_no_exit ( & package_path, & mut stderr ( ) ) ?;
Original file line number Diff line number Diff line change @@ -28,8 +28,10 @@ impl TestPackage {
28
28
new_build_config. test_mode = true ;
29
29
new_build_config. generate_docs = false ;
30
30
new_build_config. generate_move_model = true ;
31
- new_build_config. compiler_config . known_attributes =
32
- metadata:: get_all_attribute_names ( ) . clone ( ) ;
31
+ new_build_config
32
+ . compiler_config
33
+ . known_attributes
34
+ . clone_from ( metadata:: get_all_attribute_names ( ) ) ;
33
35
34
36
configure_for_unit_test ( ) ;
35
37
Original file line number Diff line number Diff line change 1
1
pub mod harness;
2
2
pub mod test_utils;
3
3
4
- use anyhow:: bail;
5
4
pub use harness:: * ;
6
- use move_package:: package_hooks:: PackageHooks ;
7
- use move_package:: source_package:: parsed_manifest:: CustomDepInfo ;
8
- use move_symbol_pool:: Symbol ;
9
5
10
6
#[ cfg( test) ]
11
7
mod tests;
12
-
13
- pub ( crate ) struct InitiaPackageHooks { }
14
- pub const UPGRADE_POLICY_CUSTOM_FIELD : & str = "upgrade_policy" ;
15
-
16
- impl PackageHooks for InitiaPackageHooks {
17
- fn custom_package_info_fields ( & self ) -> Vec < String > {
18
- vec ! [ UPGRADE_POLICY_CUSTOM_FIELD . to_string( ) ]
19
- }
20
-
21
- fn custom_dependency_key ( & self ) -> Option < String > {
22
- Some ( "initia" . to_string ( ) )
23
- }
24
-
25
- fn resolve_custom_dependency (
26
- & self ,
27
- _dep_name : Symbol ,
28
- _info : & CustomDepInfo ,
29
- ) -> anyhow:: Result < ( ) > {
30
- bail ! ( "not used" )
31
- }
32
- }
Original file line number Diff line number Diff line change @@ -391,7 +391,7 @@ impl MockStakingAPI {
391
391
metadata : AccountAddress ,
392
392
amount : u64 ,
393
393
) -> anyhow:: Result < u64 > {
394
- match self . validators . get ( & validator. to_vec ( ) ) {
394
+ match self . validators . get ( validator) {
395
395
Some ( ratios) => match ratios. get ( & metadata) {
396
396
Some ( ( s, a) ) => Ok ( amount * s / a) ,
397
397
None => Err ( anyhow ! ( "ratio not found" ) ) ,
@@ -406,7 +406,7 @@ impl MockStakingAPI {
406
406
metadata : AccountAddress ,
407
407
share : u64 ,
408
408
) -> anyhow:: Result < u64 > {
409
- match self . validators . get ( & validator. to_vec ( ) ) {
409
+ match self . validators . get ( validator) {
410
410
Some ( ratios) => match ratios. get ( & metadata) {
411
411
Some ( ( s, a) ) => Ok ( share * a / s) ,
412
412
None => Err ( anyhow ! ( "ratio not found" ) ) ,
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ pub trait Bytecode {
32
32
33
33
fn address_identifier_at ( & self , idx : AddressIdentifierIndex ) -> & AccountAddress ;
34
34
35
+ #[ allow( dead_code) ]
35
36
fn find_entry_function ( & self , name : & IdentStr ) -> Option < MoveFunction > ;
36
37
37
38
fn new_move_struct_field ( & self , def : & FieldDefinition ) -> MoveStructField {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ use anyhow::anyhow;
11
11
12
12
/// Access to the VM's backend storage, i.e. the chain
13
13
pub trait Storage {
14
+ #[ allow( dead_code) ]
14
15
/// Returns Err on error.
15
16
/// Returns Ok(None) when key does not exist.
16
17
/// Returns Ok(Some(Vec<u8>)) when key exists.
Original file line number Diff line number Diff line change @@ -204,8 +204,12 @@ module initia_std::dex {
204
204
/// All start_after must be provided or not
205
205
const ESTART_AFTER : u64 = 17 ;
206
206
207
+ // Cannot create pair with the same coin type
207
208
const ESAME_COIN_TYPE : u64 = 19 ;
208
209
210
+ /// Zero amount in the swap simulation is not allowed
211
+ const EZERO_AMOUNT_IN : u64 = 20 ;
212
+
209
213
// Constants
210
214
const MAX_LIMIT : u8 = 30 ;
211
215
@@ -1359,9 +1363,17 @@ module initia_std::dex {
1359
1363
amount_in: u64 ,
1360
1364
swap_fee_rate: Decimal128 ,
1361
1365
): (u64 , u64 ) {
1366
+ assert !(amount_in > 0 , error::invalid_argument (EZERO_AMOUNT_IN ));
1367
+
1362
1368
let one = decimal128::one ();
1363
1369
let exp = decimal128::from_ratio (decimal128::val (&weight_in), decimal128::val (&weight_out));
1370
+
1371
+ // avoid zero fee amount to prevent fee bypass attack
1364
1372
let fee_amount = decimal128::mul_u64 (&swap_fee_rate, amount_in);
1373
+ if (fee_amount == 0 ) {
1374
+ fee_amount = 1 ;
1375
+ };
1376
+
1365
1377
let adjusted_amount_in = amount_in - fee_amount;
1366
1378
let base = decimal128::from_ratio_u64 (pool_amount_in, pool_amount_in + adjusted_amount_in);
1367
1379
let sub_amount = pow (&base, &exp);
You can’t perform that action at this time.
0 commit comments