Skip to content

Commit 8778267

Browse files
authored
Merge pull request #98 from lidofinance/develop
3.1.0
2 parents 59c9fd3 + e6a81d3 commit 8778267

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1446
-596
lines changed

.github/workflows/deploy-pages.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
id: config_pages
3838
uses: actions/configure-pages@v4
3939
- name: Restore cache
40-
uses: actions/cache@v3
40+
uses: actions/cache@v4
4141
with:
4242
path: |
4343
playground/.next/cache
@@ -64,7 +64,7 @@ jobs:
6464
env:
6565
NODE_NO_BUILD_DYNAMICS: true
6666
- name: Upload artifact
67-
uses: actions/upload-pages-artifact@v2
67+
uses: actions/upload-pages-artifact@v3
6868
with:
6969
path: ./playground/out
7070

@@ -78,4 +78,4 @@ jobs:
7878
steps:
7979
- name: Deploy to GitHub Pages
8080
id: deployment
81-
uses: actions/deploy-pages@v3
81+
uses: actions/deploy-pages@v4

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,24 @@ All examples and usage instructions can be found in the [Docs SDK package](packa
9292
const lidoSDK = new LidoSDK({
9393
chainId: 5,
9494
rpcUrls: ['https://eth-goerli.alchemyapi.io/v2/{ALCHEMY_API_KEY}'],
95+
web3Provider: provider,
9596
});
9697

97-
// Define default web3 provider in sdk (window.ethereum) if web3Provider is not defined in constructor
98-
lidoSDK.core.defineWeb3Provider();
99-
10098
// Views
10199
const balanceETH = await lidoSDK.core.balanceETH(address);
102100

103101
// Calls
104-
const stakeResult = await lidoSDK.stake.stakeEth({
102+
const stakeTx = await lidoSDK.stake.stakeEth({
105103
value,
106104
callback,
107105
referralAddress,
108106
account,
109107
});
110108

109+
// relevant results are returned with transaction
110+
const { stethReceived, sharesReceived } = stakeTx.result;
111+
111112
console.log(balanceETH.toString(), 'ETH balance');
112-
console.log(stakeResult, 'stake result');
113113
```
114114

115115
## Migration

packages/sdk/CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# 3.1.0
2+
3+
## SDK
4+
5+
### Added
6+
7+
- `viem` version up to `2.0.6`
8+
- Account hoisting support: methods no longer require address/account if it's hoisted to `walletClient` or available via `eth_requestAccounts`
9+
- Stake, Wrap, Withdraw Request & Claim transaction methods now return parsed transaction result
10+
- `waitForTransactionReceiptParameters` [optional config](https://viem.sh/docs/actions/public/waitForTransactionReceipt.html) added to all transaction methods props
11+
12+
### Fixed
13+
14+
- better multisig behavior for transactions
15+
- Simulate methods now have correct return types
16+
- `stakeEthPopulateTx` not does not calculate `gasLimit` which prevented usage when stake limit is reached
17+
18+
## Playground
19+
20+
- Upped `next` and `viem` versions
21+
122
# 3.0.1
223

324
## SDK

packages/sdk/README.md

+31-19
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ const addressStETH = await lidoSDK.stake.contractAddressStETH();
249249
const contractStETH = await lidoSDK.stake.getContractStETH();
250250

251251
// Calls
252-
const stakeResult = await lidoSDK.stake.stakeEth({
252+
const stakeTx = await lidoSDK.stake.stakeEth({
253253
value,
254254
callback,
255255
referralAddress,
256256
});
257257

258258
console.log(addressStETH, 'stETH contract address');
259259
console.log(contractStETH, 'stETH contract');
260-
console.log(stakeResult, 'stake result');
260+
console.log(stakeTx, 'stake tx result');
261261
```
262262

263263
### Withdraw example
@@ -276,15 +276,15 @@ const contractWithdrawalQueue =
276276
await lidoSDK.withdraw.contract.getContractWithdrawalQueue();
277277

278278
// Calls
279-
const requestResult = await lidoSDK.withdraw.request.requestByToken({
280-
account,
279+
const requestTx = await lidoSDK.withdraw.request.requestWithdrawalWithPermit({
281280
amount: 10000000n, // `10000000` string is accepted as well
282281
token: 'stETH',
282+
// account will be requested from provider
283283
});
284284

285285
console.log(addressWithdrawalQueue, 'Withdrawal Queue contract address');
286286
console.log(contractWithdrawalQueue, 'Withdrawal Queue contract');
287-
console.log(requestResult, 'request result');
287+
console.log(requestTx.result.requests, 'array of created requests');
288288
```
289289

290290
### Wrap example
@@ -301,14 +301,16 @@ const addressWstETH = await lidoSDK.wrap.contractAddressWstETH();
301301
const contractWstETH = await lidoSDK.withdraw.getContractWstETH();
302302

303303
// Calls
304-
const wrapResult = await lidoSDK.wrap.wrapEth({
304+
const wrapTx = await lidoSDK.wrap.wrapEth({
305305
value,
306306
account,
307307
});
308308

309+
const { stethWrapped, wstethReceived } = wrapTx.result;
310+
309311
console.log(addressWstETH, 'wstETH contract address');
310312
console.log(contractWstETH, 'wstETH contract');
311-
console.log(wrapResult, 'wrap result');
313+
console.log({ stethWrapped, wstethReceived }, 'wrap result');
312314
```
313315

314316
## Error Codes
@@ -397,16 +399,18 @@ const callback: StakeStageCallback = ({ stage, payload }) => {
397399
};
398400

399401
try {
400-
const stakeResult = await lidoSDK.stake.stakeEth({
402+
const stakeTx = await lidoSDK.stake.stakeEth({
401403
value,
402404
callback,
403405
referralAddress,
404406
account,
405407
});
406408

407409
console.log(
408-
stakeResult,
409-
'transaction hash, transaction receipt, confirmations',
410+
stakeTx,
411+
'transaction hash, transaction receipt, confirmations, stake result',
412+
stakeTx.result.stethReceived,
413+
stakeTx.result.sharesReceived,
410414
);
411415
} catch (error) {
412416
console.log((error as SDKError).errorMessage, (error as SDKError).code);
@@ -502,15 +506,17 @@ const callback: TransactionCallback = ({ stage, payload }) => {
502506
};
503507

504508
try {
505-
const wrapResult = await lidoSDK.staking.wrapETH({
509+
const wrapTx = await lidoSDK.staking.wrapETH({
506510
value,
507511
callback,
508512
account,
509513
});
510514

511515
console.log(
512-
stakeResult,
513-
'transaction hash, transaction receipt, confirmations',
516+
wrapTx,
517+
'transaction hash, transaction receipt, confirmations, wrap result',
518+
wrapTx.result.stethWrapped,
519+
wrapTx.result.wstethReceived,
514520
);
515521
} catch (error) {
516522
console.log((error as SDKError).errorMessage, (error as SDKError).code);
@@ -552,10 +558,12 @@ const wrapResult = await lidoSDK.wrap.wrapSteth({ value, callback });
552558

553559
```ts
554560
// unwrap wstETH to receive stETH
555-
const unwrapResult = await lidoSDK.wrap.unwrap({
561+
const unwrapTx = await lidoSDK.wrap.unwrap({
556562
value: unwrapAmount,
557563
callback,
558564
});
565+
566+
console.log(unwrapTx.result.stethReceived, unwrapTx.result.wstethUnwrapped);
559567
```
560568

561569
### Wrap utilities
@@ -636,16 +644,18 @@ const callback: TransactionCallback = ({ stage, payload }) => {
636644
};
637645

638646
try {
639-
const requestResult = await lidoSDK.withdrawals.request.requestWithPermit({
647+
const requestTx = await lidoSDK.withdrawals.request.requestWithPermit({
640648
requests,
641649
token, // 'stETH' | 'wstETH'
642650
callback,
643651
account,
644652
});
645653

646654
console.log(
655+
'transaction hash, transaction receipt, confirmations',
647656
requestResult,
648-
'transaction hash, transaction receipt, confirmations',
657+
'array of requests(nfts) created with ids, amounts,creator, owner'
658+
request.results.requests,
649659
);
650660
} catch (error) {
651661
console.log((error as SDKError).errorMessage, (error as SDKError).code);
@@ -709,7 +719,7 @@ const callback: TransactionCallback = ({ stage, payload }) => {
709719
};
710720

711721
try {
712-
const requestResult = await lidoSDK.withdrawals.request.requestWithoutPermit({
722+
const requestResult = await lidoSDK.withdrawals.request.requestWithdrawal({
713723
amount,
714724
token, // 'stETH' | 'wstETH'
715725
callback,
@@ -781,14 +791,16 @@ const callback: TransactionCallback = ({ stage, payload }) => {
781791
};
782792

783793
try {
784-
const claimResult = await lidoSDK.withdrawals.claim.claimRequests({
794+
const claimTx = await lidoSDK.withdrawals.claim.claimRequests({
785795
requestsIds,
786796
callback,
787797
});
788798

789799
console.log(
790-
claimResult,
800+
claimTx,
791801
'transaction hash, transaction receipt, confirmations',
802+
claim.result.requests,
803+
'array of claimed requests, with amounts of ETH claimed',
792804
);
793805
} catch (error) {
794806
console.log((error as SDKError).errorMessage, (error as SDKError).code);

packages/sdk/jest.config.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import type { JestConfigWithTsJest } from 'ts-jest';
33
const jestConfig: JestConfigWithTsJest = {
44
displayName: 'LidoSDK tests',
55
testEnvironment: 'node',
6+
// fix for leftover handles when running locally on macos
7+
detectOpenHandles: true,
8+
forceExit: true,
69
preset: 'ts-jest',
710
verbose: true,
8-
9-
detectOpenHandles: true,
1011
extensionsToTreatAsEsm: ['.ts'],
1112
moduleNameMapper: {
1213
'^(\\.{1,2}/.*)\\.js$': '$1',
@@ -22,6 +23,7 @@ const jestConfig: JestConfigWithTsJest = {
2223
},
2324
maxWorkers: 1,
2425
globalSetup: '<rootDir>/tests/global-setup.cjs',
26+
globalTeardown: '<rootDir>/tests/global-teardown.cjs',
2527
testTimeout: 300_000,
2628
};
2729

packages/sdk/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"@ethersproject/bytes": "^5.7.0",
146146
"graphql": "^16.8.1",
147147
"graphql-request": "^6.1.0",
148-
"viem": "^1.18.8"
148+
"viem": "^2.0.6"
149149
},
150150
"devDependencies": {
151151
"@jest/globals": "^29.7.0",

packages/sdk/src/common/decorators/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const ConsoleCss: Record<HeadMessage, string> = {
88
'Views:': 'color: aquamarine',
99
'Call:': 'color: orange',
1010
'Error:': 'color: red',
11+
'Deprecation:': 'color: red',
1112
'LOG:': 'color: lightblue',
1213
'Cache:': 'color: mediumvioletred',
1314
'Permit:': 'color: lime',

packages/sdk/src/common/decorators/logger.ts

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export const Logger = function (headMessage: HeadMessage = 'LOG:') {
1212
const methodName = String(context.name);
1313

1414
const replacementMethod = function (this: This, ...args: Args): Return {
15+
if (headMessage === 'Deprecation:')
16+
callConsoleMessage.call(
17+
this,
18+
headMessage,
19+
`Method '${methodName}' is being deprecated in the next major version`,
20+
);
21+
1522
callConsoleMessage.call(
1623
this,
1724
headMessage,

packages/sdk/src/common/decorators/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export type HeadMessage =
1212
| 'Permit:'
1313
| 'Events:'
1414
| 'Statistic:'
15-
| 'Rewards:';
15+
| 'Rewards:'
16+
| 'Deprecation:';

packages/sdk/src/common/utils/sdk-error.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ export class SDKError extends Error {
3838

3939
constructor({ code, error = {}, message }: SDKErrorProps) {
4040
super(message);
41-
Object.assign(this, error);
41+
if (error instanceof Error) {
42+
this.cause = error.cause;
43+
this.stack = error.stack;
44+
}
4245
this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;
4346
this.errorMessage = message;
4447
}

0 commit comments

Comments
 (0)