Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 13 additions & 13 deletions book/guide/6-unstake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -64,7 +64,7 @@ const unstake = async ({
amount: bigint;
}): Promise<Hex> => {
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
Expand Down Expand Up @@ -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.

Expand Down
4 changes: 3 additions & 1 deletion hardhat.config.cjs
Original file line number Diff line number Diff line change
@@ -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: [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/stake.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down