Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add modify_total_fee #99

Merged
merged 3 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ref-exchange/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref-exchange"
version = "1.7.1"
version = "1.7.2"
authors = ["Illia Polosukhin <[email protected]>"]
edition = "2018"
publish = false
Expand Down
6 changes: 6 additions & 0 deletions ref-exchange/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes

### Version 1.7.2
```
9KuaBbp9FT1g17YCaCsaezGxWDuZkKrjPsXu1RCN8Ux7
```
1. add modify_total_fee;

### Version 1.7.1
```
6ZU3rmDwEs988pvYWyDxg6DJm7fP1F3FnAwHGo698ATw
Expand Down
14 changes: 13 additions & 1 deletion ref-exchange/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use near_contract_standards::fungible_token::core_impl::ext_fungible_token;
use crate::*;
use crate::rated_swap::rate::{global_register_rate, global_unregister_rate};
use crate::utils::{FEE_DIVISOR, MAX_ADMIN_FEE_BPS, GAS_FOR_BASIC_OP};
use crate::legacy::ContractV1;

#[near_bindgen]
impl Contract {
Expand Down Expand Up @@ -199,6 +198,19 @@ impl Contract {
self.admin_fee_bps = admin_fee_bps;
}

#[payable]
pub fn modify_total_fee(&mut self, pool_id: u64, total_fee: u32) {
assert_one_yocto();
assert!(self.is_owner_or_guardians(), "{}", ERR100_NOT_ALLOWED);
assert!(total_fee < FEE_DIVISOR, "{}", ERR62_FEE_ILLEGAL);
let mut pool = self.pools.get(pool_id).expect(ERR85_NO_POOL);
env::log(
format!("Modify total_fee pool_id {} from {} to {}", pool_id, pool.get_fee(), total_fee).as_bytes()
);
pool.modify_total_fee(total_fee);
self.pools.replace(pool_id, &pool);
}

/// Remove exchange fee liquidity to owner's inner account.
/// Owner's inner account storage should be prepared in advance.
#[payable]
Expand Down
8 changes: 8 additions & 0 deletions ref-exchange/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ impl Pool {
}
}

pub fn modify_total_fee(&mut self, total_fee: u32) {
match self {
Pool::SimplePool(pool) => pool.modify_total_fee(total_fee),
Pool::StableSwapPool(pool) => pool.modify_total_fee(total_fee),
Pool::RatedSwapPool(pool) => pool.modify_total_fee(total_fee),
}
}

/// Adds liquidity into underlying pool.
/// Updates amounts to amount kept in the pool.
pub fn add_liquidity(
Expand Down
4 changes: 4 additions & 0 deletions ref-exchange/src/rated_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl RatedSwapPool {
}
}

pub fn modify_total_fee(&mut self, total_fee: u32) {
self.total_fee = total_fee;
}

pub fn get_rates(&self) -> Vec<u128> {
self.token_account_ids
.iter()
Expand Down
4 changes: 4 additions & 0 deletions ref-exchange/src/simple_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl SimplePool {
}
}

pub fn modify_total_fee(&mut self, total_fee: u32) {
self.total_fee = total_fee;
}

/// See if the given account has been registered as a LP
pub fn share_has_registered(&self, account_id: &AccountId) -> bool {
self.shares.contains_key(account_id)
Expand Down
4 changes: 4 additions & 0 deletions ref-exchange/src/stable_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl StableSwapPool {
}
}

pub fn modify_total_fee(&mut self, total_fee: u32) {
self.total_fee = total_fee;
}

pub fn get_amounts(&self) ->Vec<u128> {
let mut amounts = self.c_amounts.clone();
for (index, value) in self.token_decimals.iter().enumerate() {
Expand Down
4 changes: 2 additions & 2 deletions ref-exchange/tests/test_migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::common::utils::*;
pub mod common;

near_sdk_sim::lazy_static_include::lazy_static_include_bytes! {
PREV_EXCHANGE_WASM_BYTES => "../releases/ref_exchange_release_v170.wasm",
PREV_EXCHANGE_WASM_BYTES => "../releases/ref_exchange_release_v171.wasm",
EXCHANGE_WASM_BYTES => "../res/ref_exchange.wasm",
}

Expand Down Expand Up @@ -47,7 +47,7 @@ fn test_upgrade() {
.assert_success();
let metadata = get_metadata(&pool);
// println!("{:#?}", metadata);
assert_eq!(metadata.version, "1.7.1".to_string());
assert_eq!(metadata.version, "1.7.2".to_string());
assert_eq!(metadata.admin_fee_bps, 5);
assert_eq!(metadata.state, RunningState::Running);

Expand Down
Binary file modified releases/ref_exchange_release.wasm
Binary file not shown.
Binary file removed releases/ref_exchange_release_v170.wasm
Binary file not shown.
Binary file added releases/ref_exchange_release_v171.wasm
Binary file not shown.
Loading