From e9437acd40a1e0e614d92f2d430c7c851169d6c5 Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 23 May 2024 15:19:52 +0100 Subject: [PATCH 1/4] Fix method name in docs --- book/guide/6-unstake.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/book/guide/6-unstake.md b/book/guide/6-unstake.md index ea959cb..e1efc50 100644 --- a/book/guide/6-unstake.md +++ b/book/guide/6-unstake.md @@ -9,10 +9,10 @@ In order to unstake, there can be 2 scenarios: In the first scenario, the unstaking process is straightforward. These are the steps: -1. determine the maximum amount the user can unstake by calling the `getMaxWithdraw` method on the OpusPool instance. +1. determine the maximum amount the user can unstake by calling the `getMaxUnstakeForUserForVault` method on the OpusPool instance. ```typescript -const maxWithdraw = await pool.getMaxWithdraw(vaultAddress); +const maxWithdraw = await pool.getMaxUnstakeForUserForVault(vaultAddress); ``` The user can unstake up to the `maxWithdraw` amount, i.e. `amountToUnstake <= maxWithdraw` and `0 < maxWithdraw` @@ -64,7 +64,7 @@ const unstake = async ({ amount: bigint; }): Promise => { const pool = new OpusPool({ network, address: userAddress }); - const maxWithdraw = await pool.getMaxWithdraw(vaultAddress); + const maxWithdraw = await pool.getMaxUnstakeForUserForVault(vaultAddress); if (maxWithdraw === 0 || maxWithdraw < amountToUnstake) { // the user is trying to unstake more than they can @@ -103,16 +103,16 @@ const unstakeQueue = await pool.getUnstakeQueueForVault(vault); Here, `vault` refers to the address of your vault. The returned `unstakeQueue` contains an array of objects, each representing an item within the queue. These objects are structured as follows: -- `exitQueueIndex`: (Optional) The index position of the item within the unstake queue, represented as a `bigint`. -- `positionTicket`: A unique identifier for the queue item, also a `bigint`. -- `when`: The date and time when the item was added to the queue. -- `isWithdrawable`: A boolean flag indicating whether the assets are ready to be withdrawn. -- `totalShares`: The total amount of assets in the queue item, represented in shares, as a `bigint`. -- `totalAssets`: The total amount of assets, in token units, as a `bigint`. -- `leftShares`: The amount of assets, in shares, that remain non-withdrawable, as a `bigint`. -- `leftAssets`: The amount of assets, in token units, that cannot yet be withdrawn, as a `bigint`. -- `withdrawableShares`: The portion of assets, in shares, that are eligible for withdrawal, as a `bigint`. -- `withdrawableAssets`: The portion of assets, in token units, that can be withdrawn, as a `bigint`. +- `exitQueueIndex`: (Optional) The index position of the item within the unstake queue, represented as a `bigint`. +- `positionTicket`: A unique identifier for the queue item, also a `bigint`. +- `when`: The date and time when the item was added to the queue. +- `isWithdrawable`: A boolean flag indicating whether the assets are ready to be withdrawn. +- `totalShares`: The total amount of assets in the queue item, represented in shares, as a `bigint`. +- `totalAssets`: The total amount of assets, in token units, as a `bigint`. +- `leftShares`: The amount of assets, in shares, that remain non-withdrawable, as a `bigint`. +- `leftAssets`: The amount of assets, in token units, that cannot yet be withdrawn, as a `bigint`. +- `withdrawableShares`: The portion of assets, in shares, that are eligible for withdrawal, as a `bigint`. +- `withdrawableAssets`: The portion of assets, in token units, that can be withdrawn, as a `bigint`. Each item in the queue provides comprehensive details about the state of your unstaked assets, including their current withdrawability status and the precise amounts in both shares and token units. Monitoring these details is important for effectively managing your assets and planning your withdrawal strategy. From 1cec4cc2b485d07a15169bf8cb32a1f7d5641c0d Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 23 May 2024 15:56:10 +0100 Subject: [PATCH 2/4] Update `holesky` rpc url and docs on how to test --- README.md | 22 ++++++++++++++++++++++ hardhat.config.cjs | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e7db2c..6d3ba28 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,28 @@ non-custodial staking on Ethereum networks. The SDK interface is implemented as Typescript library `opus-pool`, which is distributed under Apache 2.0 license. +## To run tests + +**Load the environment variables** + +```bash +npx hardhat vars set INFURA_API_KEY +``` + +You'll be prompted to enter the value of the environment variable. + +**Start the hardhat node in a separate terminal** + +```bash +npx hardhat node +``` + +**Run the tests in a separate terminal** + +```bash +npx hardhat test +``` + ## Integration flow ![integration flow](./book/media/integration.png) diff --git a/hardhat.config.cjs b/hardhat.config.cjs index 8594c2a..f5b1da7 100644 --- a/hardhat.config.cjs +++ b/hardhat.config.cjs @@ -1,12 +1,14 @@ /** @type import('hardhat/config').HardhatUserConfig */ require('@nomicfoundation/hardhat-toolbox-viem'); +const INFURA_API_KEY = vars.get("INFURA_API_KEY"); + module.exports = { solidity: '0.8.20', networks: { hardhat: { forking: { - url: 'https://ethereum-holesky.publicnode.com', + url: 'https://holesky.infura.io/v3/' + INFURA_API_KEY, }, accounts: [ { From 3d818df166ea744ee81052b2d1933d97424144e4 Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 23 May 2024 16:03:24 +0100 Subject: [PATCH 3/4] Reduce # of mined blocks in test --- tests/stake.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/stake.test.ts b/tests/stake.test.ts index 74f210d..70c96a0 100644 --- a/tests/stake.test.ts +++ b/tests/stake.test.ts @@ -63,7 +63,7 @@ describe('Staking Integration Test', () => { maxFeePerGas: stakeTransactionData.maxFeePerGas, chain: hardhat, }); - await mine(10); + await mine(3); const receipt = await publicClient.getTransactionReceipt({ hash: txHash }); expect(receipt.status).toEqual('success'); From 3144e226861685d0157d1ccd703d018b5d9fa6ad Mon Sep 17 00:00:00 2001 From: maria Date: Thu, 23 May 2024 16:03:52 +0100 Subject: [PATCH 4/4] Add infura secret to ci --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59af6c8..ca10d23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,8 +18,10 @@ jobs: node-version: '20.x' - run: npm ci - name: Start Hardhat Node + env: + INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }} run: | - npx hardhat node > hardhat.log 2>&1 & + INFURA_API_KEY=$INFURA_API_KEY npx hardhat node > hardhat.log 2>&1 & echo "Hardhat_PID=$!" > hardhat_pid.env - name: Run Tests run: |