Skip to content

Commit dec92e9

Browse files
committed
add comments to the donation functions.
1 parent 2146efb commit dec92e9

File tree

9 files changed

+22
-7
lines changed

9 files changed

+22
-7
lines changed

ref-exchange/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
### Version 1.9.7
44
```
5-
BQRaMGsoRafZXJuSb1X66MuXw9vXvSWb4mHQPeaH9uDq
5+
CMN4goNWHQjsXevLbqAC9nXKTw1yeJqysEfB647uuyro
66
```
77
1. fix identity verification for the whitelisted_postfix related functions.
88
2. add donation functions.

ref-exchange/src/degen_swap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl DegenSwapPool {
721721
/// The storage should be refunded to the user.
722722
pub fn share_unregister(&mut self, account_id: &AccountId) {
723723
let shares = self.shares.remove(account_id);
724-
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_LP_NOT_EMPTY);
724+
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_NONZERO_LP_SHARES);
725725
}
726726

727727
/// Transfers shares from predecessor to receiver.

ref-exchange/src/donation.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ use crate::*;
22

33
#[near_bindgen]
44
impl Contract {
5+
/// The user donates the shares they hold to the protocol.
6+
///
7+
/// # Arguments
8+
///
9+
/// * `pool_id` - The pool id where the shares are located.
10+
/// * `amount` - The donation amount; if it's None, the entire amount will be donated.
11+
/// * `unregister` - If `Some(true)`, Will attempt to unregister the shares and refund the user’s storage fees.
12+
/// The storage fee will be refunded to the user's internal account first;
13+
/// if there is no internal account, a transfer will be initiated.
514
#[payable]
615
pub fn donation_share(&mut self, pool_id: u64, amount: Option<U128>, unregister: Option<bool>) {
716
assert_one_yocto();
@@ -28,6 +37,13 @@ impl Contract {
2837
event::Event::DonationShare { account_id: &account_id, pool_id, amount: U128(donation_amount) }.emit();
2938
}
3039

40+
/// The user donates the tokens they hold to the owner.
41+
///
42+
/// # Arguments
43+
///
44+
/// * `token_id` - The id of the donated token.
45+
/// * `amount` - The donation amount; if it's None, the entire amount will be donated.
46+
/// * `unregister` - If `Some(true)`, Will attempt to unregister the tokens.
3147
#[payable]
3248
pub fn donation_token(&mut self, token_id: ValidAccountId, amount: Option<U128>, unregister: Option<bool>) {
3349
assert_one_yocto();

ref-exchange/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub const ERR15_NO_STORAGE_CAN_WITHDRAW: &str = "E15: no storage can withdraw";
99
pub const ERR16_STORAGE_WITHDRAW_TOO_MUCH: &str = "E16: storage withdraw too much";
1010
pub const ERR17_DEPOSIT_LESS_THAN_MIN_STORAGE: &str = "E17: deposit less than min storage";
1111
pub const ERR18_TOKENS_NOT_EMPTY: &str = "E18: storage unregister tokens not empty";
12-
pub const ERR19_LP_NOT_EMPTY: &str = "E19: LP not empty";
12+
pub const ERR19_NONZERO_LP_SHARES: &str = "E19: Nonzero LP shares";
1313

1414
// Accounts.
1515

ref-exchange/src/owner.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ impl Contract {
300300
assert!(amount > 0, "{}", ERR29_ILLEGAL_WITHDRAW_AMOUNT);
301301
let owner_id = self.owner_id.clone();
302302
let mut account = self.internal_unwrap_account(&owner_id);
303-
// Note: subtraction and deregistration will be reverted if the promise fails.
304303
account.withdraw(&token_id, amount);
305304
self.accounts.insert(&owner_id, &account.into());
306305
self.internal_send_tokens(&owner_id, &token_id, amount, skip_unwrap_near)

ref-exchange/src/rated_swap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl RatedSwapPool {
719719
/// The storage should be refunded to the user.
720720
pub fn share_unregister(&mut self, account_id: &AccountId) {
721721
let shares = self.shares.remove(account_id);
722-
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_LP_NOT_EMPTY);
722+
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_NONZERO_LP_SHARES);
723723
}
724724

725725
/// Transfers shares from predecessor to receiver.

ref-exchange/src/simple_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl SimplePool {
8686
/// The storage should be refunded to the user.
8787
pub fn share_unregister(&mut self, account_id: &AccountId) {
8888
let shares = self.shares.remove(account_id);
89-
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_LP_NOT_EMPTY);
89+
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_NONZERO_LP_SHARES);
9090
}
9191

9292
/// Transfers shares from predecessor to receiver.

ref-exchange/src/stable_swap/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl StableSwapPool {
629629
/// The storage should be refunded to the user.
630630
pub fn share_unregister(&mut self, account_id: &AccountId) {
631631
let shares = self.shares.remove(account_id);
632-
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_LP_NOT_EMPTY);
632+
assert!(shares.expect(ERR13_LP_NOT_REGISTERED) == 0, "{}", ERR19_NONZERO_LP_SHARES);
633633
}
634634

635635
/// Transfers shares from predecessor to receiver.

releases/ref_exchange_release.wasm

10 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)