Skip to content
Closed
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ among others.
1. Make sure there is currently no unstaked balance on it. If there is, call `epoch_withdraw` to withdraw.
2. Set validator weight to 0, which can be done by either removing this validator from nodes list or set its weight to 0 directly. Run `set-node` command to update the weight.
3. Run `drain-unstake` to unstake all funds from the validator.
4. After 4 epoches, run `drain-withdraw` to withdraw and restake those funds.
4. After 4 epochs, run `drain-withdraw` to withdraw and restake those funds.

## Design

Expand Down
2 changes: 1 addition & 1 deletion bin/commands/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ exports.handler = async function (argv) {
});

console.log(outcome);
console.log('withdrawed');
console.log('withdrawn');
}
4 changes: 2 additions & 2 deletions contracts/linear/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// initialization
pub const ERR_ALREADY_INITIALZED: &str = "Already initialized";
pub const ERR_ALREADY_INITIALIZED: &str = "Already initialized";
pub const ERR_ACCOUNT_STAKING_WHILE_INIT: &str =
"The current account has staking balance while initialization";
pub const ERR_NO_ENOUGH_INIT_DEPOSIT: &str =
Expand Down Expand Up @@ -66,7 +66,7 @@ pub const ERR_NO_ENOUGH_UNSTAKED_BALANCE_TO_WITHDRAW: &str =
"Not enough unstaked balance to withdraw";
pub const ERR_UNSTAKED_BALANCE_NOT_AVAILABLE: &str =
"The unstaked balance is not yet available due to unstaking delay";
pub const ERR_INCONSISTANT_BALANCE: &str = "Contract balance less than liquidity pool balance";
pub const ERR_INCONSISTENT_BALANCE: &str = "Contract balance less than liquidity pool balance";
pub const ERR_NO_ENOUGH_CONTRACT_BALANCE: &str =
"No enough balance in contract to perform withdraw";

Expand Down
2 changes: 1 addition & 1 deletion contracts/linear/src/farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DENOMINATOR: u128 = 1_000_000_000_000_000_000_000_000;

/// Amount of gas for fungible token transfers.
const GAS_FOR_FT_TRANSFER: Gas = Gas(10 * TGAS);
/// hotfix_insuffient_gas_for_mft_resolve_transfer, increase from 5T to 20T
/// hotfix_insufficient_gas_for_mft_resolve_transfer, increase from 5T to 20T
const GAS_FOR_RESOLVE_TRANSFER: Gas = Gas(20 * TGAS);
/// Gas for calling `get_owner` method.
const GAS_FOR_GET_OWNER: Gas = Gas(10 * TGAS);
Expand Down
2 changes: 1 addition & 1 deletion contracts/linear/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl LiquidStakingContract {
// Note that account locked balance should not be included.
let available_balance = env::account_balance()
.checked_sub(self.liquidity_pool.amounts[0])
.expect(ERR_INCONSISTANT_BALANCE);
.expect(ERR_INCONSISTENT_BALANCE);

// at least 1 NEAR should be left to cover storage/gas.
require!(
Expand Down
6 changes: 3 additions & 3 deletions contracts/linear/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct ContractV1_3_0 {
// --- Staking Farm ---
/// Farm tokens.
farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indices into `farms`.
active_farms: Vec<u64>,
/// Authorized users, allowed to add farms.
/// This is done to prevent farm spam with random tokens.
Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct ContractV1_1_0 {
// --- Staking Farm ---
/// Farm tokens.
pub farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indices into `farms`.
pub active_farms: Vec<u64>,
/// Authorized users, allowed to add farms.
/// This is done to prevent farm spam with random tokens.
Expand Down Expand Up @@ -226,7 +226,7 @@ pub struct ContractV1_0_0 {
// --- Staking Farm ---
/// Farm tokens.
pub farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indices into `farms`.
pub active_farms: Vec<u64>,
/// Authorized users, allowed to add farms.
/// This is done to prevent farm spam with random tokens.
Expand Down
4 changes: 2 additions & 2 deletions contracts/linear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub struct LiquidStakingContract {
// --- Staking Farm ---
/// Farm tokens.
farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indices into `farms`.
active_farms: Vec<u64>,
/// Authorized users, allowed to add farms.
/// This is done to prevent farm spam with random tokens.
Expand All @@ -121,7 +121,7 @@ impl LiquidStakingContract {
/// It prevents inflating the price of the share too much.
#[init]
pub fn new(owner_id: AccountId) -> Self {
require!(!env::state_exists(), ERR_ALREADY_INITIALZED);
require!(!env::state_exists(), ERR_ALREADY_INITIALIZED);
require!(
env::account_locked_balance() == 0,
ERR_ACCOUNT_STAKING_WHILE_INIT
Expand Down
2 changes: 1 addition & 1 deletion contracts/linear/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) fn staked_amount_from_num_shares_rounded_down(
}

/// The absolute diff between left and right is not greater than epsilon.
/// This is useful when user submit requests that approximaitely equal to the acount's NEAR/LiNEAR balance
/// This is useful when user submit requests that approximately equal to the account's NEAR/LiNEAR balance
pub(crate) fn abs_diff_eq(left: u128, right: u128, epsilon: u128) -> bool {
left <= right + epsilon && right <= left + epsilon
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/linear/src/validator_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ impl ValidatorPool {
}

// no enough available validators to unstake
// double the unstake wating time
// double the unstake waiting time
2 * NUM_EPOCHS_TO_UNLOCK
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ trait ValidatorDrainCallbacks {
impl LiquidStakingContract {
/// This method is designed to drain a validator.
/// The weight of target validator should be set to 0 before calling this.
/// And a following call to drain_withdraw MUST be made after 4 epoches.
/// And a following call to drain_withdraw MUST be made after 4 epochs.
pub fn drain_unstake(&mut self, validator_id: AccountId) {
self.assert_running();
self.assert_manager();
Expand Down Expand Up @@ -1061,7 +1061,7 @@ mod tests {
.insert(&zoo.account_id, &zoo.clone().into());

// we have currently 100 in total, 50 already staked, 50 to stake,
// the total stake amount is less than total base stake amount, satisfay base stake amount first.
// the total stake amount is less than total base stake amount, satisfy base stake amount first.
// thus foo is the most unbalanced one.

let candidate = validator_pool.get_candidate_to_stake(50 * ONE_NEAR, 100 * ONE_NEAR);
Expand Down Expand Up @@ -1091,7 +1091,7 @@ mod tests {
.insert(&zoo.account_id, &zoo.clone().into());

// we have currently 150 in total, 100 already staked, 50 to stake,
// the total stake amount is less than total base stake amount, satisfay base stake amount first.
// the total stake amount is less than total base stake amount, satisfy base stake amount first.
// thus bar is the most unbalanced one.

let candidate = validator_pool.get_candidate_to_stake(50 * ONE_NEAR, 150 * ONE_NEAR);
Expand Down Expand Up @@ -1273,7 +1273,7 @@ mod tests {
.insert(&zoo.account_id, &zoo.clone().into());

// we have currently 450 already staked, 250 to unstake, target total 200,
// the total stake amount is less than total base stake amount, satisfay base stake amount first,
// the total stake amount is less than total base stake amount, satisfy base stake amount first,
// thus zoo is the most unbalanced one.

let candidate = validator_pool.get_candidate_to_unstake(200 * ONE_NEAR, 200 * ONE_NEAR);
Expand Down Expand Up @@ -1303,7 +1303,7 @@ mod tests {
.insert(&zoo.account_id, &zoo.clone().into());

// we have currently 300 already staked, 150 to unstake, target total 150,
// the total stake amount is less than total base stake amount, satisfay base stake amount first,
// the total stake amount is less than total base stake amount, satisfy base stake amount first,
// thus bar is the most unbalanced one.

let candidate = validator_pool.get_candidate_to_unstake(150 * ONE_NEAR, 150 * ONE_NEAR);
Expand Down
18 changes: 18 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"dictionaryDefinitions": [
{
"name": "project-words",
"path": "./project-words.txt",
"addWords": true
}
],
"dictionaries": ["project-words"],
"ignorePaths": [
"Cargo.toml",
"./*.json",
"./.*"
],
"useGitignore": true
}
1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ clean:
lint:
cargo fmt -- --check
cargo clippy --tests -- -D clippy::all
npx cspell --words-only --unique "**"

test: test-unit test-linear test-mock-staking-pool test-mock-fungible-token

Expand Down
Loading