Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK 3.2.0 #118

Merged
merged 24 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
967061a
fix: fix package field 'url'
DiRaiks Mar 5, 2024
93d42a2
build: update publish-alpha wf
DiRaiks Mar 5, 2024
9a20e3d
Merge pull request #113 from lidofinance/feature/fix_package_fields
DiRaiks Mar 6, 2024
70723ae
build(deps): bump follow-redirects from 1.15.5 to 1.15.6
dependabot[bot] Mar 17, 2024
92c8411
feat: add Sepolia testnet
DiRaiks Mar 20, 2024
931bcb0
fix: add real token rebased block for Sepolia
DiRaiks Mar 20, 2024
a540f0a
feat: added withdrawal waiting time methods, tests, playground exampl…
Tarens2 Mar 20, 2024
d441261
feat: add Sepolia support in playground
DiRaiks Mar 20, 2024
79abdc0
feat: docs update
Tarens2 Mar 21, 2024
7392dbc
feat: docs update
Tarens2 Mar 21, 2024
3592dd5
feat: update types
Tarens2 Mar 21, 2024
d8556a5
feat: update request by ids
Tarens2 Mar 21, 2024
878e574
feat: update types
Tarens2 Mar 21, 2024
e2f6a06
feat: added fetch options, updated types
Tarens2 Mar 22, 2024
67bc8e5
Merge pull request #114 from lidofinance/dependabot/npm_and_yarn/foll…
Jeday Mar 25, 2024
fdc6018
feat: update function parameters
Tarens2 Mar 25, 2024
54ecf8f
fix: bigint update
Tarens2 Mar 25, 2024
f652414
docs: update changelog
DiRaiks Mar 25, 2024
74277fe
Merge pull request #116 from lidofinance/feature/si-1323-add-sepolia-…
Jeday Mar 26, 2024
9f48ab9
Merge branch 'develop' into feature/si-1215-add-wwt
Tarens2 Mar 26, 2024
70038c8
docs: added changelog
Tarens2 Mar 26, 2024
242310a
feat: added unsupported chain error
Tarens2 Mar 26, 2024
1a6bed0
fix: custom errors
Tarens2 Mar 26, 2024
5506c95
Merge pull request #117 from lidofinance/feature/si-1215-add-wwt
Jeday Mar 26, 2024
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
8 changes: 8 additions & 0 deletions .github/workflows/publish-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ jobs:
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: yarn npm audit

- name: Authenticate in npm
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
echo "workspaces-update=false" >> .npmrc
echo "provenance=true" >> .npmrc
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish Alpha
run: yarn multi-semantic-release --deps.bump=override --deps.release=patch --sequential-init
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ console.log(balanceETH.toString(), 'ETH balance');

## Migration

For breaking changes between versions see [MIGRATION.md](MIGRATION.md)
For breaking changes between versions see [MIGRATION.md](packages/sdk/MIGRATION.md)

## Documentation

Expand Down
15 changes: 15 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 3.2.0

## SDK

### Added

- `Sepolia` testnet
- New method `getWithdrawalWaitingTimeByAmount` for fetching withdrawal waiting time for amount of eth
- New method `getWithdrawalWaitingTimeByRequestIds` for fetching withdrawal waiting time for earlier created requests by their ids

## Playground

- Support for `Sepolia` testnet
- Added blocks with new methods `getWithdrawalWaitingTimeByAmount` and `getWithdrawalWaitingTimeByRequestIds`

# 3.1.0

## SDK
Expand Down
52 changes: 51 additions & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ For breaking changes between versions see [MIGRATION.md](MIGRATION.md)
- [Views](#views)
- [Constants](#constants)
- [Requests info](#requests-info)
- [Waiting time](#waiting-time)
- [Get time by amount](#get-time-by-amount)
- [Get time by request ids](#get-time-by-request-ids)
- [(w)stETH](#wsteth)
- [unstETH NFT](#unsteth-nft)
- [Shares](#shares)
Expand Down Expand Up @@ -654,7 +657,7 @@ try {
console.log(
'transaction hash, transaction receipt, confirmations',
requestResult,
'array of requests(nfts) created with ids, amounts,creator, owner'
'array of requests(nfts) created with ids, amounts,creator, owner',
request.results.requests,
);
} catch (error) {
Expand Down Expand Up @@ -1010,6 +1013,53 @@ try {
- `pendingRequests` (Type: Array[RequestStatusWithId]): A list of requests pending finalization.
- `pendingAmountStETH` (Type: bigint): The amount of ETH pending claiming.

### Waiting time

#### Methods

##### Get time by amount

###### `getWithdrawalWaitingTimeByAmount`

###### Input Parameters:

- `props: { amount?: bigint }`
- `amount?` (Type: bigint **optional**): The amount of withdrawable eth. In case when it is not passed, it is calculated as default information about queue.

##### Output Parameters:

- Type: Object
- Structure:
- `requestInfo` (Type: Object): Information about withdrawal request
- `finalizationIn` (Type: number): The time needed for withdrawal in milliseconds.
- `finalizationAt` (Type: string): The time when request finalized for withdrawal.
- `type` (Type: WaitingTimeCalculationType): Type of final source of eth for withdrawal.
- `status` (Type: WaitingTimeStatus): Status of withdrawal request.
- `nextCalculationAt` (Type: string): Time when next calculation can be changed.

##### Get time by request ids

###### `getWithdrawalWaitingTimeByRequestIds`

###### Input Parameters:

- `props: { ids: bigint[] }`
- `ids` (ids: Array[bigint]): The ids of withdrawal requests.

##### Output Parameters:

- Type: Array of WithdrawalWaitingTimeRequestInfo objects
- Structure of each object:
- `requestInfo` (Type: RequestByIdInfoDto): Information about withdrawal request.
- `finalizationIn` (Type: number): The time needed for withdrawal in milliseconds.
- `finalizationAt` (Type: string): The time when request finalized for withdrawal.
- `requestId` (Type: string): The request id.
- `requestedAt` (Type: string): The time when withdrawal requested.
- `type` (Type: WaitingTimeCalculationType): Type of final source of eth for withdrawal.
- `status` (Type: WaitingTimeStatus): Status of withdrawal request.
- `nextCalculationAt` (Type: string): Time when next calculation can be changed.


## (w)stETH

stETH and wstETH tokens functionality is presented trough modules with same ERC20 interface that exposes balances, allowances, transfers and ERC2612 permits signing.
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"homepage": "https://github.com/lidofinance/lido-ethereum-sdk",
"repository": {
"type": "git",
"url": "https://github.com/lidofinance/lido-ethereum-sdk.git",
"url": "git+https://github.com/lidofinance/lido-ethereum-sdk.git",
"directory": "packages/sdk"
},
"bugs": {
Expand Down
15 changes: 14 additions & 1 deletion packages/sdk/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { type Address, type Chain } from 'viem';
import { goerli, mainnet, holesky } from 'viem/chains';
import { goerli, mainnet, holesky, sepolia } from 'viem/chains';

export enum CHAINS {
Goerli = 5,
Mainnet = 1,
Holesky = 17000,
Sepolia = 11155111,
}

export const APPROX_BLOCKS_BY_DAY = 7600n;
Expand All @@ -13,6 +14,7 @@ export const SUPPORTED_CHAINS: CHAINS[] = [
CHAINS.Goerli,
CHAINS.Mainnet,
CHAINS.Holesky,
CHAINS.Sepolia,
];

export const SUBMIT_EXTRA_GAS_TRANSACTION_RATIO = 1.05;
Expand All @@ -25,6 +27,7 @@ export const LIDO_LOCATOR_BY_CHAIN: {
[CHAINS.Mainnet]: '0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb',
[CHAINS.Goerli]: '0x1eDf09b5023DC86737b59dE68a8130De878984f5',
[CHAINS.Holesky]: '0x28FAB2059C713A7F9D8c86Db49f9bb0e96Af1ef8',
[CHAINS.Sepolia]: '0x8f6254332f69557A72b0DA2D5F0Bc07d4CA991E7',
};

export const SUBRGRAPH_ID_BY_CHAIN: {
Expand All @@ -33,6 +36,7 @@ export const SUBRGRAPH_ID_BY_CHAIN: {
[CHAINS.Mainnet]: 'Sxx812XgeKyzQPaBpR5YZWmGV5fZuBaPdh7DFhzSwiQ',
[CHAINS.Goerli]: 'QmeDfGTuNbSoZ71zi3Ch4WNRbzALfiFPnJMYUFPinLiFNa',
[CHAINS.Holesky]: null,
[CHAINS.Sepolia]: null,
};

export const EARLIEST_TOKEN_REBASED_EVENT: {
Expand All @@ -41,6 +45,7 @@ export const EARLIEST_TOKEN_REBASED_EVENT: {
[CHAINS.Mainnet]: 17272708n,
[CHAINS.Goerli]: 8712039n,
[CHAINS.Holesky]: 52174n,
[CHAINS.Sepolia]: 5434668n,
} as const;

export const LIDO_TOKENS = {
Expand Down Expand Up @@ -104,4 +109,12 @@ export const VIEM_CHAINS: { [key in CHAINS]: Chain } = {
[CHAINS.Mainnet]: mainnet,
[CHAINS.Goerli]: goerli,
[CHAINS.Holesky]: holesky,
[CHAINS.Sepolia]: sepolia,
};

export const WQ_API_URLS: { [key in CHAINS]: string | null } = {
[CHAINS.Mainnet]: 'https://wq-api.lido.fi',
[CHAINS.Goerli]: 'https://wq-api.testnet.fi',
[CHAINS.Holesky]: 'https://wq-api-holesky.testnet.fi',
[CHAINS.Sepolia]: null,
};
1 change: 1 addition & 0 deletions packages/sdk/src/common/decorators/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const ConsoleCss: Record<HeadMessage, string> = {
'Events:': 'color: salmon',
'Statistic:': 'color: purple',
'Rewards:': 'color: greenyellow',
'API:': 'color: mediumpurple',
'Init:':
'color: #33F3FF;text-shadow: 0px 0px 0 #899CD5, 1px 1px 0 #8194CD, 2px 2px 0 #788BC4, 3px 3px 0 #6F82BB, 4px 4px 0 #677AB3, 5px 5px 0 #5E71AA, 6px 6px 0 #5568A1, 7px 7px 0 #4C5F98, 8px 8px 0 #445790, 9px 9px 0 #3B4E87, 10px 10px 0 #32457E, 11px 11px 0 #2A3D76, 12px 12px 0 #21346D, 13px 13px 0 #182B64, 14px 14px 0 #0F225B, 15px 15px 0 #071A53, 16px 16px 0 #02114A, 17px 17px 0 #0B0841, 18px 18px 0 #130039, 19px 19px 0 #1C0930, 20px 20px 0 #251227, 21px 21px 20px rgba(0,0,0,1), 21px 21px 1px rgba(0,0,0,0.5), 0px 0px 20px rgba(0,0,0,.2);font-size: 50px;',
};
3 changes: 2 additions & 1 deletion packages/sdk/src/common/decorators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export type HeadMessage =
| 'Events:'
| 'Statistic:'
| 'Rewards:'
| 'Deprecation:';
| 'Deprecation:'
| 'API:';
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, describe, test } from '@jest/globals';
import { useWithdraw } from '../../../tests/utils/fixtures/use-withdraw.js';
import { WithdrawalWaitingTimeByRequestIdsParams } from '../types.js';

describe('withdraw waiting time', () => {
const withdraw = useWithdraw();
const { waitingTime } = withdraw;

test('can get withdrawal waiting time by amount', async () => {
const amount = 110n;
const requestInfos = await waitingTime.getWithdrawalWaitingTimeByAmount({
amount,
});
expect(typeof requestInfos.status).toEqual('string');
});

test('can get withdrawal waiting time by request ids', async () => {
const requestsIds = [1234n, 1235n];

const requestInfos = await waitingTime.getWithdrawalWaitingTimeByRequestIds(
{
ids: requestsIds,
} as WithdrawalWaitingTimeByRequestIdsParams,
);

expect(Array.isArray(requestInfos)).toEqual(true);
expect(requestInfos.length).toEqual(requestsIds.length);
});
});
14 changes: 14 additions & 0 deletions packages/sdk/src/withdraw/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
LidoSDKWithdrawApprove,
} from './request/index.js';
import { LidoSDKModule } from '../common/class-primitives/sdk-module.js';
import { LidoSDKWithdrawWaitingTime } from './withdraw-waiting-time.js';

export class Bus extends LidoSDKModule {
private version: string | undefined;
Expand All @@ -17,6 +18,7 @@ export class Bus extends LidoSDKModule {
private approvalInstance: LidoSDKWithdrawApprove | undefined;
private claimInstance: LidoSDKWithdrawClaim | undefined;
private requestInstance: LidoSDKWithdrawRequest | undefined;
private waitingTimeInstance: LidoSDKWithdrawWaitingTime | undefined;

// Contract

Expand Down Expand Up @@ -89,4 +91,16 @@ export class Bus extends LidoSDKModule {
}
return this.requestInstance;
}

// Waiting Time

get waitingTime(): LidoSDKWithdrawWaitingTime {
if (!this.waitingTimeInstance) {
this.waitingTimeInstance = new LidoSDKWithdrawWaitingTime({
bus: this,
version: this.version,
});
}
return this.waitingTimeInstance;
}
}
60 changes: 60 additions & 0 deletions packages/sdk/src/withdraw/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Address } from 'viem';
import type { Bus } from './bus.js';
import type { AccountValue } from '../index.js';
import { CHAINS } from '../index.js';

export type LidoSDKWithdrawModuleProps = { bus: Bus; version?: string };

Expand Down Expand Up @@ -51,3 +52,62 @@ export type GetWithdrawalRequestsInfoReturnType = {
pendingInfo: GetPendingRequestsInfoReturnType;
claimableETH: GetClaimableRequestsETHByAccountReturnType;
};

export type WqApiCustomUrlGetter = (
defaultUrl: string | null,
chainId: CHAINS,
) => string;

export type WithdrawalWaitingTimeByAmountParams = {
amount?: bigint;
getCustomApiUrl?: WqApiCustomUrlGetter;
};

export type RequestInfo = {
finalizationIn: number;
finalizationAt: string;
type: WaitingTimeCalculationType;
};

export type WithdrawalWaitingTimeByAmountResponse = {
requestInfo: RequestInfo;
status: WaitingTimeStatus;
nextCalculationAt: string;
};

export type WithdrawalWaitingTimeByRequestIdsParams = {
ids: readonly bigint[];
requestDelay?: number;
getCustomApiUrl?: WqApiCustomUrlGetter;
};

export type RequestByIdInfo = {
finalizationIn: number;
finalizationAt: string;
requestId?: string;
requestedAt?: string;
type: WaitingTimeCalculationType;
};

export type WithdrawalWaitingTimeRequestInfo = {
requestInfo: RequestByIdInfo;
status: WaitingTimeStatus;
nextCalculationAt: string;
};

export enum WaitingTimeStatus {
initializing = 'initializing',
calculating = 'calculating',
finalized = 'finalized',
calculated = 'calculated',
}

export enum WaitingTimeCalculationType {
buffer = 'buffer',
bunker = 'bunker',
vaultsBalance = 'vaultsBalance',
rewardsOnly = 'rewardsOnly',
validatorBalances = 'validatorBalances',
requestTimestampMargin = 'requestTimestampMargin',
exitValidators = 'exitValidators',
}
Loading