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: | 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/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. 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: [ { 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');