From 82d89d58f5cf03668ce099a39b074af47b97c86b Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:05:45 +0800 Subject: [PATCH 1/5] fix: typos in project --- README.md | 2 +- bin/commands/withdraw.js | 2 +- contracts/linear/src/legacy.rs | 6 ++--- contracts/linear/src/utils.rs | 2 +- contracts/linear/src/validator_pool.rs | 12 +++++----- tests/__tests__/linear/fungible-token.ava.ts | 14 ++++++------ tests/__tests__/linear/helper.ts | 6 ++--- .../linear/staking-pool-interface.ava.ts | 22 +++++++++---------- tests/__tests__/linear/upgrade.ava.ts | 16 +++++++------- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index da66ebad..fe6096ac 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,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 diff --git a/bin/commands/withdraw.js b/bin/commands/withdraw.js index e21db0e6..c94eed29 100644 --- a/bin/commands/withdraw.js +++ b/bin/commands/withdraw.js @@ -36,5 +36,5 @@ exports.handler = async function (argv) { }); console.log(outcome); - console.log('withdrawed'); + console.log('withdrawn'); } diff --git a/contracts/linear/src/legacy.rs b/contracts/linear/src/legacy.rs index e7e56fe4..9e53d850 100644 --- a/contracts/linear/src/legacy.rs +++ b/contracts/linear/src/legacy.rs @@ -165,7 +165,7 @@ pub struct ContractV1_3_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indicies into `farms`. + /// Active farms: indices into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens. @@ -275,7 +275,7 @@ pub struct ContractV1_1_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indicies into `farms`. + /// Active farms: indices into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens. @@ -339,7 +339,7 @@ pub struct ContractV1_0_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indicies into `farms`. + /// Active farms: indices into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens. diff --git a/contracts/linear/src/utils.rs b/contracts/linear/src/utils.rs index f86d220a..ef9d8e78 100644 --- a/contracts/linear/src/utils.rs +++ b/contracts/linear/src/utils.rs @@ -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 } diff --git a/contracts/linear/src/validator_pool.rs b/contracts/linear/src/validator_pool.rs index cf8407a2..0ee9e9d6 100644 --- a/contracts/linear/src/validator_pool.rs +++ b/contracts/linear/src/validator_pool.rs @@ -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 } } @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/tests/__tests__/linear/fungible-token.ava.ts b/tests/__tests__/linear/fungible-token.ava.ts index 1e03a3ff..6660da78 100644 --- a/tests/__tests__/linear/fungible-token.ava.ts +++ b/tests/__tests__/linear/fungible-token.ava.ts @@ -4,7 +4,7 @@ import { assertFailure, registerFungibleTokenUser, ONE_YOCTO, - epochHeightFastforward, + epochHeightFastForward, deployDex, test, } from './helper'; @@ -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', @@ -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 @@ -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, @@ -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, @@ -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, diff --git a/tests/__tests__/linear/helper.ts b/tests/__tests__/linear/helper.ts index 2cc2386a..a584d878 100644 --- a/tests/__tests__/linear/helper.ts +++ b/tests/__tests__/linear/helper.ts @@ -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 }); } diff --git a/tests/__tests__/linear/staking-pool-interface.ava.ts b/tests/__tests__/linear/staking-pool-interface.ava.ts index 7a1ccd26..1607ecff 100644 --- a/tests/__tests__/linear/staking-pool-interface.ava.ts +++ b/tests/__tests__/linear/staking-pool-interface.ava.ts @@ -2,7 +2,7 @@ import { NEAR, Gas } from 'near-workspaces'; import { initWorkspace, assertFailure, - epochHeightFastforward, + epochHeightFastForward, epochStake, test, } from './helper'; @@ -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( @@ -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() }); @@ -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, @@ -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(), diff --git a/tests/__tests__/linear/upgrade.ava.ts b/tests/__tests__/linear/upgrade.ava.ts index 7a3f8902..c45fad08 100644 --- a/tests/__tests__/linear/upgrade.ava.ts +++ b/tests/__tests__/linear/upgrade.ava.ts @@ -4,7 +4,7 @@ import { NearAccount, Worker } from 'near-workspaces'; import { createAndDeploy, createStakingPool, - epochHeightFastforward, + epochHeightFastForward, epochStake, epochUnstake, epochWithdraw, @@ -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); @@ -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( @@ -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() }); From 404a3965cc0c83f7b8dc06e8b58887e20a0a1557 Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Mon, 14 Apr 2025 13:10:18 +0800 Subject: [PATCH 2/5] chore: add rust-toolchain --- rust-toolchain.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..3689107e --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,6 @@ +[toolchain] +# This specifies the version of Rust we use to build. +# Individual crates in the workspace may support a lower version, as indicated by `rust-version` field in each crate's `Cargo.toml`. +# The version specified below, should be at least as high as the maximum `rust-version` within the workspace. +channel = "1.69.0" +components = ["rustfmt", "clippy", "rust-analyzer"] From 44297ebc991a376f024baecd4a88a1f1dcb4c74d Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Mon, 14 Apr 2025 13:25:22 +0800 Subject: [PATCH 3/5] chore: update github workflow --- .github/workflows/test.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2defa338..9e5ffcd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 From 3acddf11ed2537ffbccbacd47c1eb4bad3041c3f Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Mon, 14 Apr 2025 13:47:06 +0800 Subject: [PATCH 4/5] chore: remove rust-analyzer component --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3689107e..74c4f099 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -3,4 +3,4 @@ # Individual crates in the workspace may support a lower version, as indicated by `rust-version` field in each crate's `Cargo.toml`. # The version specified below, should be at least as high as the maximum `rust-version` within the workspace. channel = "1.69.0" -components = ["rustfmt", "clippy", "rust-analyzer"] +components = ["rustfmt", "clippy"] From 42d8d7fb2481ef7cc8e6f078faf794a753162c2f Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Mon, 14 Apr 2025 16:00:23 +0800 Subject: [PATCH 5/5] fix: indexes typo --- contracts/linear/src/legacy.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/linear/src/legacy.rs b/contracts/linear/src/legacy.rs index 9e53d850..1bc873c4 100644 --- a/contracts/linear/src/legacy.rs +++ b/contracts/linear/src/legacy.rs @@ -165,7 +165,7 @@ pub struct ContractV1_3_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indices into `farms`. + /// Active farms: indexes into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens. @@ -275,7 +275,7 @@ pub struct ContractV1_1_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indices into `farms`. + /// Active farms: indexes into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens. @@ -339,7 +339,7 @@ pub struct ContractV1_0_0 { // --- Staking Farm --- /// Farm tokens. pub farms: Vector, - /// Active farms: indices into `farms`. + /// Active farms: indexes into `farms`. pub active_farms: Vec, /// Authorized users, allowed to add farms. /// This is done to prevent farm spam with random tokens.