Skip to content
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
10 changes: 9 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"./ref-farming",
"./test-rated-token",
"./mock-boost-farming",
"./mock-burrowland",
"./mock-price-oracle",
"./mock-wnear",
"./mock-pyth"
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ else
RUSTFLAGS=$(RFLAGS) cargo test -p ref-exchange --lib -- --nocapture
endif

test: build-exchange mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth
test: build-exchange mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth mock-burrow
ifdef TF
RUSTFLAGS=$(RFLAGS) cargo test -p ref-exchange --test $(TF) -- --nocapture
else
RUSTFLAGS=$(RFLAGS) cargo test -p ref-exchange --tests
endif

test-exchange: build-exchange mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth
test-exchange: build-exchange mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth mock-burrow
RUSTFLAGS=$(RFLAGS) cargo test -p ref-exchange

test-farm: build-farm mock-ft
RUSTFLAGS=$(RFLAGS) cargo test -p ref_farming

test-release: mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth
test-release: mock-ft mock-rated mock-farming test-wnear test-price-oracle test-pyth mock-burrow
mkdir -p res
cp ./releases/ref_exchange_release.wasm ./res/ref_exchange.wasm
RUSTFLAGS=$(RFLAGS) cargo test -p ref-exchange
Expand All @@ -57,6 +57,12 @@ mock-farming: mock-boost-farming
mkdir -p res
cp target/wasm32-unknown-unknown/release/mock_boost_farming.wasm ./res/mock_boost_farming.wasm

mock-burrow: mock-burrowland
rustup target add wasm32-unknown-unknown
RUSTFLAGS=$(RFLAGS) cargo build -p mock-burrowland --target wasm32-unknown-unknown --release
mkdir -p res
cp target/wasm32-unknown-unknown/release/mock_burrowland.wasm ./res/mock_burrowland.wasm

test-wnear: mock-wnear
rustup target add wasm32-unknown-unknown
RUSTFLAGS=$(RFLAGS) cargo build -p mock-wnear --target wasm32-unknown-unknown --release
Expand Down
11 changes: 11 additions & 0 deletions mock-burrowland/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "mock-burrowland"
version = "0.1.0"
edition = "2018"
publish = false

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "3.1.0"
35 changes: 35 additions & 0 deletions mock-burrowland/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::json_types::U128;
use near_sdk::{near_bindgen, AccountId, PanicOnDefault};

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
pub struct Contract;

#[near_bindgen]
impl Contract {
#[init]
pub fn new() -> Self {
Self
}

#[allow(unused_variables)]
pub fn on_cast_shadow(
&mut self,
account_id: AccountId,
shadow_id: String,
amount: U128,
msg: String,
) {
}

#[allow(unused_variables)]
pub fn on_remove_shadow(
&mut self,
account_id: AccountId,
shadow_id: String,
amount: U128,
msg: String,
) {
}
}
5 changes: 3 additions & 2 deletions ref-exchange/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ref-exchange"
version = "1.9.18"
version = "1.9.19"
authors = ["Illia Polosukhin <illia.polosukhin@gmail.com>"]
edition = "2018"
publish = false
Expand All @@ -20,8 +20,9 @@ near-sdk-sim = "3.1.0"
test-token = { path = "../test-token" }
test-rated-token = { path = "../test-rated-token" }
mock-boost-farming = { path = "../mock-boost-farming" }
mock-burrowland = { path = "../mock-burrowland" }
mock-wnear = { path = "../mock-wnear" }
mock-price-oracle = { path = "../mock-price-oracle" }
mock-pyth = { path = "../mock-pyth" }
rand = "0.8"
rand_pcg = "0.3"
rand_pcg = "0.3"
7 changes: 7 additions & 0 deletions ref-exchange/release_notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes

### Version 1.9.19
```
AEAm8sQ5KYZRgnpq2CN2NhX6d8QV76iRtiDpy5Ai6zDX
```
1. prevent donation_share from donating shadow-locked shares.
2. validate token prices on all add_liquidity calls.

### Version 1.9.18
```
AqbqDX2n5AJ6zh7VEL7R49yPejgAE5YUySxWM6RepTiX
Expand Down
14 changes: 11 additions & 3 deletions ref-exchange/src/degen_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ impl DegenSwapPool {

// make amounts into comparable-amounts
let c_amounts = self.amounts_to_c_amounts(amounts);

if self.shares_total_supply == 0 {
// Bootstrapping the pool, request providing all non-zero balances,
// and all fee free.
self.assert_degens_valid();

for c_amount in &c_amounts {
assert!(*c_amount > 0, "{}", ERR65_INIT_TOKEN_BALANCE);
Expand Down Expand Up @@ -258,9 +257,17 @@ impl DegenSwapPool {
let n_coins = self.token_account_ids.len();
assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);

let degens = match degens {
Some(d) => d.clone(),
None => {
self.assert_degens_valid();
self.get_degens()
}
};

let (new_shares, _) = self.calc_add_liquidity_with_degens(
amounts,
degens.as_ref().unwrap_or(&self.get_degens()),
&degens,
fees
);

Expand All @@ -282,6 +289,7 @@ impl DegenSwapPool {
let n_coins = self.token_account_ids.len();
assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);

self.assert_degens_valid();
let (new_shares, fee_part) = self.calc_add_liquidity_with_degens(amounts, &self.get_degens(), fees);

//slippage check on the LP tokens.
Expand Down
11 changes: 9 additions & 2 deletions ref-exchange/src/donation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ impl Contract {
let account_id = env::predecessor_account_id();
let prev_storage = env::storage_usage();
let mut pool = self.pools.get(pool_id).expect(ERR85_NO_POOL);
let donation_amount = amount.map(|v| v.0).unwrap_or(pool.share_balances(&account_id));
assert!(donation_amount > 0, "Invalid amount");
let total_shares = pool.share_balances(&account_id);
let donation_amount = amount.map(|v| v.0).unwrap_or(total_shares);
assert!(donation_amount > 0 && donation_amount <= total_shares, "Invalid amount");
if let Some(account) = self.internal_get_account(&account_id) {
if let Some(record) = account.get_shadow_record(pool_id) {
let available_shares = record.free_shares(total_shares);
assert!(available_shares >= donation_amount, "Cannot donate shadow-locked shares");
}
}
pool.share_transfer(&account_id, &env::current_account_id(), donation_amount);
if unregister == Some(true) {
pool.share_unregister(&account_id);
Expand Down
12 changes: 10 additions & 2 deletions ref-exchange/src/rated_swap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ impl RatedSwapPool {
if self.shares_total_supply == 0 {
// Bootstrapping the pool, request providing all non-zero balances,
// and all fee free.
self.assert_rates_valid();

for c_amount in &c_amounts {
assert!(*c_amount > 0, "{}", ERR65_INIT_TOKEN_BALANCE);
Expand Down Expand Up @@ -256,9 +255,17 @@ impl RatedSwapPool {
let n_coins = self.token_account_ids.len();
assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);

let rates = match rates {
Some(r) => r.clone(),
None => {
self.assert_rates_valid();
self.get_rates()
}
};

let (new_shares, _) = self.calc_add_liquidity_with_rates(
amounts,
rates.as_ref().unwrap_or(&self.get_rates()),
&rates,
fees
);

Expand All @@ -280,6 +287,7 @@ impl RatedSwapPool {
let n_coins = self.token_account_ids.len();
assert_eq!(amounts.len(), n_coins, "{}", ERR64_TOKENS_COUNT_ILLEGAL);

self.assert_rates_valid();
let (new_shares, fee_part) = self.calc_add_liquidity_with_rates(amounts, &self.get_rates(), fees);

//slippage check on the LP tokens.
Expand Down
Loading