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
20 changes: 12 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# Setup Rust environment
- name: Rust toolchain
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1 # stable
toolchain: 1.69.0
default: true
override: true
- uses: Swatinem/rust-cache@v1
target: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
# Set up Node environment
- name: Setup Node
uses: actions/setup-node@v3.1.1
Expand All @@ -43,15 +45,17 @@ jobs:
name: clippy and fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# Setup Rust environment
- name: Install stable toolchain
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.66.1 # stable
toolchain: 1.69.0
default: true
override: true
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2
# Run lint
- name: Test Format
run: cargo fmt -- --check
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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 @@ -36,5 +36,5 @@ exports.handler = async function (argv) {
});

console.log(outcome);
console.log('withdrawed');
console.log('withdrawn');
}
6 changes: 3 additions & 3 deletions contracts/linear/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub struct ContractV1_3_0 {
// --- Staking Farm ---
/// Farm tokens.
pub farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indexes 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 @@ -275,7 +275,7 @@ pub struct ContractV1_1_0 {
// --- Staking Farm ---
/// Farm tokens.
pub farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indexes 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 @@ -339,7 +339,7 @@ pub struct ContractV1_0_0 {
// --- Staking Farm ---
/// Farm tokens.
pub farms: Vector<Farm>,
/// Active farms: indicies into `farms`.
/// Active farms: indexes 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
2 changes: 1 addition & 1 deletion contracts/linear/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl LiquidStakingContract {
}

/// 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 acount'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 @@ -330,7 +330,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 @@ -654,7 +654,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) -> Promise {
self.assert_running();
self.assert_manager();
Expand Down Expand Up @@ -1339,7 +1339,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 @@ -1369,7 +1369,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 @@ -1640,7 +1640,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 @@ -1670,7 +1670,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
14 changes: 7 additions & 7 deletions tests/__tests__/linear/fungible-token.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertFailure,
registerFungibleTokenUser,
ONE_YOCTO,
epochHeightFastforward,
epochHeightFastForward,
deployDex,
test,
} from './helper';
Expand Down Expand Up @@ -193,7 +193,7 @@ test.skip('storage unregister', async (t) => {
);

// Force unregister Alice successfully.
// The $LiNEAR owned by Alice are all burnt. Now $LiNEAR price increased to 2 $NEAER.
// The $LiNEAR owned by Alice are all burnt. Now $LiNEAR price increased to 2 $NEAR.
await alice.call(
contract,
'storage_unregister',
Expand Down Expand Up @@ -237,8 +237,8 @@ test.skip('storage unregister', async (t) => {
ERR_UNREGISTER_POSITIVE_UNSTAKED,
);

// 4 epoches later, Alice withdraws 2 NEAR
await epochHeightFastforward(contract, alice);
// 4 epochs later, Alice withdraws 2 NEAR
await epochHeightFastForward(contract, alice);
await alice.call(contract, 'withdraw', { amount: NEAR.parse('2') });

// non-force unregister when Alice has some LiNEAR, should fail
Expand Down Expand Up @@ -282,7 +282,7 @@ test('ft_transfer_call LiNEAR', async (t) => {
{ attachedDeposit: stakeAmount },
);

// ft_transfer_call() with `ft_on_trasfer()` passed
// ft_transfer_call() with `ft_on_transfer()` passed
const transferAmount1 = NEAR.parse('1');
await transferCall(
contract,
Expand All @@ -297,7 +297,7 @@ test('ft_transfer_call LiNEAR', async (t) => {
stakeAmount.sub(transferAmount1).toString(),
);

// ft_transfer_call() with `ft_on_trasfer()` failed, all assets refunded
// ft_transfer_call() with `ft_on_transfer()` failed, all assets refunded
const transferAmount2 = NEAR.parse('2');
await transferCall(
contract,
Expand All @@ -312,7 +312,7 @@ test('ft_transfer_call LiNEAR', async (t) => {
stakeAmount.sub(transferAmount1).toString(),
);

// ft_transfer_call() with `ft_on_trasfer()` refunded, all assets refunded
// ft_transfer_call() with `ft_on_transfer()` refunded, all assets refunded
const transferAmount3 = NEAR.parse('3');
await transferCall(
contract,
Expand Down
6 changes: 3 additions & 3 deletions tests/__tests__/linear/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ export function parseNEAR(a: number): NEAR {
return NEAR.from(yoctoString);
}

export async function epochHeightFastforward(
export async function epochHeightFastForward(
contract: NearAccount,
user: NearAccount,
numEpoches = NUM_EPOCHS_TO_UNLOCK,
numEpochs = NUM_EPOCHS_TO_UNLOCK,
) {
// read current epoch
let epoch: number = await contract.view('read_epoch_height', {});
// increase epoch height
epoch += numEpoches;
epoch += numEpochs;
await user.call(contract, 'set_epoch_height', { epoch });
}

Expand Down
22 changes: 11 additions & 11 deletions tests/__tests__/linear/staking-pool-interface.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NEAR, Gas } from 'near-workspaces';
import {
initWorkspace,
assertFailure,
epochHeightFastforward,
epochHeightFastForward,
epochStake,
test,
} from './helper';
Expand Down Expand Up @@ -177,10 +177,10 @@ test('unstake and withdraw', async (t) => {
ERR_UNSTAKED_BALANCE_NOT_AVAILABLE,
);

// wait 4 epoches
await epochHeightFastforward(contract, alice);
// wait 4 epochs
await epochHeightFastForward(contract, alice);

// withdraw all after 4 epoches
// withdraw all after 4 epochs
await alice.call(contract, 'withdraw_all', {});

t.is(
Expand All @@ -204,10 +204,10 @@ test('unstake and withdraw', async (t) => {
stakeAmount.sub(unstakeAmount).toString(),
);

// wait 4 epoches
await epochHeightFastforward(contract, alice);
// wait 4 epochs
await epochHeightFastForward(contract, alice);

// withdraw all after 4 epoches
// withdraw all after 4 epochs
const withdrawAmount = NEAR.parse('1');
await alice.call(contract, 'withdraw', { amount: withdrawAmount.toString() });

Expand Down Expand Up @@ -238,15 +238,15 @@ test('late unstake and withdraw', async (t) => {
const unstakeAmount = NEAR.parse('5');
await alice.call(contract, 'unstake', { amount: unstakeAmount.toString() });

// withdraw available time should be 5 epoches later
// withdraw available time should be 5 epochs later
const account: any = await contract.view('get_account_details', {
account_id: alice.accountId,
});

t.is(account.unstaked_available_epoch_height, 15);

// cannot withdraw after 4 epoches
await epochHeightFastforward(contract, alice);
// cannot withdraw after 4 epochs
await epochHeightFastForward(contract, alice);

await assertFailure(
t,
Expand All @@ -255,7 +255,7 @@ test('late unstake and withdraw', async (t) => {
);

// wait for one more epoch
await epochHeightFastforward(contract, alice, 1);
await epochHeightFastForward(contract, alice, 1);

await alice.call(contract, 'withdraw', {
amount: unstakeAmount.toString(),
Expand Down
16 changes: 8 additions & 8 deletions tests/__tests__/linear/upgrade.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NearAccount, Worker } from 'near-workspaces';
import {
createAndDeploy,
createStakingPool,
epochHeightFastforward,
epochHeightFastForward,
epochStake,
epochUnstake,
epochWithdraw,
Expand Down Expand Up @@ -470,7 +470,7 @@ test.skip('upgrade from v1.5.1 to v1.6.0', async (t) => {
await stakeAll(manager, contract);

// wait 1 epoch
await epochHeightFastforward(contract, alice, 1);
await epochHeightFastForward(contract, alice, 1);

// upgrade linear contract to the latest
await upgrade(contract, owner);
Expand All @@ -482,11 +482,11 @@ test.skip('upgrade from v1.5.1 to v1.6.0', async (t) => {
// run epoch unstake
await unstakeAll(manager, contract);

// wait 4 epoches
await epochHeightFastforward(contract, alice);
// wait 4 epochs
await epochHeightFastForward(contract, alice);
await withdrawAll(manager, contract);

// withdraw all after 4 epoches
// withdraw all after 4 epochs
await alice.call(contract, 'withdraw_all', {});

t.is(
Expand All @@ -504,11 +504,11 @@ test.skip('upgrade from v1.5.1 to v1.6.0', async (t) => {
// run epoch unstake
await unstakeAll(manager, contract);

// wait 4 epoches
await epochHeightFastforward(contract, alice);
// wait 4 epochs
await epochHeightFastForward(contract, alice);
await withdrawAll(manager, contract);

// withdraw all after 4 epoches
// withdraw all after 4 epochs
const withdrawAmount = NEAR.parse('1');
await alice.call(contract, 'withdraw', { amount: withdrawAmount.toString() });

Expand Down
Loading