Skip to content

Commit

Permalink
Merge pull request #98 from lidofinance/develop
Browse files Browse the repository at this point in the history
3.1.0
  • Loading branch information
Jeday authored Jan 26, 2024
2 parents 59c9fd3 + e6a81d3 commit 8778267
Show file tree
Hide file tree
Showing 52 changed files with 1,446 additions and 596 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
id: config_pages
uses: actions/configure-pages@v4
- name: Restore cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
playground/.next/cache
Expand All @@ -64,7 +64,7 @@ jobs:
env:
NODE_NO_BUILD_DYNAMICS: true
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: ./playground/out

Expand All @@ -78,4 +78,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v3
uses: actions/deploy-pages@v4
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,24 @@ All examples and usage instructions can be found in the [Docs SDK package](packa
const lidoSDK = new LidoSDK({
chainId: 5,
rpcUrls: ['https://eth-goerli.alchemyapi.io/v2/{ALCHEMY_API_KEY}'],
web3Provider: provider,
});

// Define default web3 provider in sdk (window.ethereum) if web3Provider is not defined in constructor
lidoSDK.core.defineWeb3Provider();

// Views
const balanceETH = await lidoSDK.core.balanceETH(address);

// Calls
const stakeResult = await lidoSDK.stake.stakeEth({
const stakeTx = await lidoSDK.stake.stakeEth({
value,
callback,
referralAddress,
account,
});

// relevant results are returned with transaction
const { stethReceived, sharesReceived } = stakeTx.result;

console.log(balanceETH.toString(), 'ETH balance');
console.log(stakeResult, 'stake result');
```

## Migration
Expand Down
21 changes: 21 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# 3.1.0

## SDK

### Added

- `viem` version up to `2.0.6`
- Account hoisting support: methods no longer require address/account if it's hoisted to `walletClient` or available via `eth_requestAccounts`
- Stake, Wrap, Withdraw Request & Claim transaction methods now return parsed transaction result
- `waitForTransactionReceiptParameters` [optional config](https://viem.sh/docs/actions/public/waitForTransactionReceipt.html) added to all transaction methods props

### Fixed

- better multisig behavior for transactions
- Simulate methods now have correct return types
- `stakeEthPopulateTx` not does not calculate `gasLimit` which prevented usage when stake limit is reached

## Playground

- Upped `next` and `viem` versions

# 3.0.1

## SDK
Expand Down
50 changes: 31 additions & 19 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ const addressStETH = await lidoSDK.stake.contractAddressStETH();
const contractStETH = await lidoSDK.stake.getContractStETH();

// Calls
const stakeResult = await lidoSDK.stake.stakeEth({
const stakeTx = await lidoSDK.stake.stakeEth({
value,
callback,
referralAddress,
});

console.log(addressStETH, 'stETH contract address');
console.log(contractStETH, 'stETH contract');
console.log(stakeResult, 'stake result');
console.log(stakeTx, 'stake tx result');
```

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

// Calls
const requestResult = await lidoSDK.withdraw.request.requestByToken({
account,
const requestTx = await lidoSDK.withdraw.request.requestWithdrawalWithPermit({
amount: 10000000n, // `10000000` string is accepted as well
token: 'stETH',
// account will be requested from provider
});

console.log(addressWithdrawalQueue, 'Withdrawal Queue contract address');
console.log(contractWithdrawalQueue, 'Withdrawal Queue contract');
console.log(requestResult, 'request result');
console.log(requestTx.result.requests, 'array of created requests');
```

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

// Calls
const wrapResult = await lidoSDK.wrap.wrapEth({
const wrapTx = await lidoSDK.wrap.wrapEth({
value,
account,
});

const { stethWrapped, wstethReceived } = wrapTx.result;

console.log(addressWstETH, 'wstETH contract address');
console.log(contractWstETH, 'wstETH contract');
console.log(wrapResult, 'wrap result');
console.log({ stethWrapped, wstethReceived }, 'wrap result');
```

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

try {
const stakeResult = await lidoSDK.stake.stakeEth({
const stakeTx = await lidoSDK.stake.stakeEth({
value,
callback,
referralAddress,
account,
});

console.log(
stakeResult,
'transaction hash, transaction receipt, confirmations',
stakeTx,
'transaction hash, transaction receipt, confirmations, stake result',
stakeTx.result.stethReceived,
stakeTx.result.sharesReceived,
);
} catch (error) {
console.log((error as SDKError).errorMessage, (error as SDKError).code);
Expand Down Expand Up @@ -502,15 +506,17 @@ const callback: TransactionCallback = ({ stage, payload }) => {
};

try {
const wrapResult = await lidoSDK.staking.wrapETH({
const wrapTx = await lidoSDK.staking.wrapETH({
value,
callback,
account,
});

console.log(
stakeResult,
'transaction hash, transaction receipt, confirmations',
wrapTx,
'transaction hash, transaction receipt, confirmations, wrap result',
wrapTx.result.stethWrapped,
wrapTx.result.wstethReceived,
);
} catch (error) {
console.log((error as SDKError).errorMessage, (error as SDKError).code);
Expand Down Expand Up @@ -552,10 +558,12 @@ const wrapResult = await lidoSDK.wrap.wrapSteth({ value, callback });

```ts
// unwrap wstETH to receive stETH
const unwrapResult = await lidoSDK.wrap.unwrap({
const unwrapTx = await lidoSDK.wrap.unwrap({
value: unwrapAmount,
callback,
});

console.log(unwrapTx.result.stethReceived, unwrapTx.result.wstethUnwrapped);
```

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

try {
const requestResult = await lidoSDK.withdrawals.request.requestWithPermit({
const requestTx = await lidoSDK.withdrawals.request.requestWithPermit({
requests,
token, // 'stETH' | 'wstETH'
callback,
account,
});

console.log(
'transaction hash, transaction receipt, confirmations',
requestResult,
'transaction hash, transaction receipt, confirmations',
'array of requests(nfts) created with ids, amounts,creator, owner'
request.results.requests,
);
} catch (error) {
console.log((error as SDKError).errorMessage, (error as SDKError).code);
Expand Down Expand Up @@ -709,7 +719,7 @@ const callback: TransactionCallback = ({ stage, payload }) => {
};

try {
const requestResult = await lidoSDK.withdrawals.request.requestWithoutPermit({
const requestResult = await lidoSDK.withdrawals.request.requestWithdrawal({
amount,
token, // 'stETH' | 'wstETH'
callback,
Expand Down Expand Up @@ -781,14 +791,16 @@ const callback: TransactionCallback = ({ stage, payload }) => {
};

try {
const claimResult = await lidoSDK.withdrawals.claim.claimRequests({
const claimTx = await lidoSDK.withdrawals.claim.claimRequests({
requestsIds,
callback,
});

console.log(
claimResult,
claimTx,
'transaction hash, transaction receipt, confirmations',
claim.result.requests,
'array of claimed requests, with amounts of ETH claimed',
);
} catch (error) {
console.log((error as SDKError).errorMessage, (error as SDKError).code);
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import type { JestConfigWithTsJest } from 'ts-jest';
const jestConfig: JestConfigWithTsJest = {
displayName: 'LidoSDK tests',
testEnvironment: 'node',
// fix for leftover handles when running locally on macos
detectOpenHandles: true,
forceExit: true,
preset: 'ts-jest',
verbose: true,

detectOpenHandles: true,
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
Expand All @@ -22,6 +23,7 @@ const jestConfig: JestConfigWithTsJest = {
},
maxWorkers: 1,
globalSetup: '<rootDir>/tests/global-setup.cjs',
globalTeardown: '<rootDir>/tests/global-teardown.cjs',
testTimeout: 300_000,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"@ethersproject/bytes": "^5.7.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"viem": "^1.18.8"
"viem": "^2.0.6"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
Expand Down
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 @@ -8,6 +8,7 @@ export const ConsoleCss: Record<HeadMessage, string> = {
'Views:': 'color: aquamarine',
'Call:': 'color: orange',
'Error:': 'color: red',
'Deprecation:': 'color: red',
'LOG:': 'color: lightblue',
'Cache:': 'color: mediumvioletred',
'Permit:': 'color: lime',
Expand Down
7 changes: 7 additions & 0 deletions packages/sdk/src/common/decorators/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export const Logger = function (headMessage: HeadMessage = 'LOG:') {
const methodName = String(context.name);

const replacementMethod = function (this: This, ...args: Args): Return {
if (headMessage === 'Deprecation:')
callConsoleMessage.call(
this,
headMessage,
`Method '${methodName}' is being deprecated in the next major version`,
);

callConsoleMessage.call(
this,
headMessage,
Expand Down
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 @@ -12,4 +12,5 @@ export type HeadMessage =
| 'Permit:'
| 'Events:'
| 'Statistic:'
| 'Rewards:';
| 'Rewards:'
| 'Deprecation:';
5 changes: 4 additions & 1 deletion packages/sdk/src/common/utils/sdk-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export class SDKError extends Error {

constructor({ code, error = {}, message }: SDKErrorProps) {
super(message);
Object.assign(this, error);
if (error instanceof Error) {
this.cause = error.cause;
this.stack = error.stack;
}
this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;
this.errorMessage = message;
}
Expand Down
Loading

0 comments on commit 8778267

Please sign in to comment.