Skip to content

Commit

Permalink
Merge pull request #84 from lidofinance/develop
Browse files Browse the repository at this point in the history
3.0.1
  • Loading branch information
Jeday authored Dec 19, 2023
2 parents 0189e2d + c2d1731 commit 59c9fd3
Show file tree
Hide file tree
Showing 68 changed files with 8,416 additions and 197 deletions.
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ jobs:
TEST_PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
TEST_CHAIN_ID: ${{ vars.TEST_CHAIN_ID }}
TEST_RPC_URL: ${{ secrets.TEST_RPC_URL }}
TEST_SUBGRAPH_URL: ${{ secrets.TEST_SUBGRAPH_URL }}
4 changes: 2 additions & 2 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
cache: 'yarn'
- name: Setup Pages
id: config_pages
uses: actions/configure-pages@v3
uses: actions/configure-pages@v4
- name: Restore cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -78,4 +78,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v3
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@

The project is currently under development and may change in the future.

## Changelog

For changes between versions see [CHANGELOG.MD](packages/sdk/CHANGELOG.md)

## Migration

## Installation

You can install the Lido Ethereum SDK using npm or yarn:

[Docs SDK package](./packages/sdk/README.md)
[Docs SDK package](packages/sdk/README.md)

```bash
// SDK (stakes, wrap, withdrawals)
Expand Down Expand Up @@ -80,7 +86,7 @@ Replace "https://eth-goerli.alchemyapi.io/v2/{ALCHEMY_API_KEY}" with the address

## Examples

All examples and usage instructions can be found in the [Docs SDK package](./packages/sdk/README.md).
All examples and usage instructions can be found in the [Docs SDK package](packages/sdk/README.md).

```ts
const lidoSDK = new LidoSDK({
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
TEST_PRIVATE_KEY=0xeeeeeee
TEST_CHAIN_ID=17000
TEST_RPC_URL=
TEST_SKIP_SPENDING_TESTS=false
TEST_SKIP_SPENDING_TESTS=false
TEST_SUBGRAPH_URL=
25 changes: 25 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 3.0.1

## SDK

### Fixed

- modules constructors types did not allow `rpcProvider` passage
- increased default timeout on transaction confirmation
- account hoisting in `LidoSDKSteth` and `LidoSDKWSteth` for `signPermit` and `populatePermit`
- `LidoSDKRewards`:
- `getRewardsFromSubgraph` now returns APR in correct units(not in percent)
- `getRewardsFromSubgraph` now allows object to be returned from `getSubgraphUrl`
- `LidoSDKStatitstics` now has helper types
- `LidoSDKWithdraw`:
- now has more exported types
- `approveSimulateTx`,`requestWithdrawalSimulateTx`,`requestWithdrawalWithPermitSimulateTx` fixed account hoisting
- `getClaimableRequestsETHByAccount` now returns only claimable requests

## Playground

- Playground now has custom RPC input

## Tests

- All modules are covered by unit tests
7 changes: 6 additions & 1 deletion packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

The project is currently under active development and may experience breaking changes in the future.

## Changelog

For changes between versions see [CHANGELOG.MD](CHANGELOG.md)

## Migration

For breaking changes between versions see [MIGRATION.md](MIGRATION.md)
Expand Down Expand Up @@ -1348,7 +1352,8 @@ This method requires you to provide API URL to send subgraph requests to. It's b

#### Important notes

**to** is capped by last indexed block in subgraph. Block number is available in result object by `lastIndexedBlock`.
- **to** is capped by last indexed block in subgraph. Block number is available in result object by `lastIndexedBlock`.
- **getSubgraphUrl** can also return object of type `{url:string,requestHeaders?: Record<string,string> }` that is passed to `graphql-request` for extra configurability

```ts
const lidoSDK = new LidoSDK({
Expand Down
7 changes: 6 additions & 1 deletion packages/sdk/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
displayName: 'LidoSDK tests',
testEnvironment: 'node',
preset: 'ts-jest',
verbose: true,

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

export default jestConfig;
1 change: 1 addition & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
"@types/node-fetch": "^2.6.7",
"dotenv": "^16.3.1",
"fs-extra": "^11.1.1",
"ganache": "^7.9.1",
"jest": "^29.7.0",
"node-fetch": "^2.6.7",
"rimraf": "^5.0.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
overrides.maxFeePerGas = feeData.maxFeePerGas;
overrides.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
try {
overrides.gas = await getGasLimit(overrides);
overrides.gas = await getGasLimit({ ...overrides });
} catch {
// we retry without fees to see if tx will go trough
await withSDKError(
Expand All @@ -488,7 +488,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
callback({ stage: TransactionCallbackStage.SIGN, payload: overrides.gas });

const transactionHash = await withSDKError(
sendTransaction(overrides),
sendTransaction({ ...overrides }),
ERROR_CODE.TRANSACTION_ERROR,
);

Expand All @@ -505,6 +505,7 @@ export default class LidoSDKCore extends LidoSDKCacheable {
const transactionReceipt = await withSDKError(
this.rpcProvider.waitForTransactionReceipt({
hash: transactionHash,
timeout: 120_000,
}),
ERROR_CODE.TRANSACTION_ERROR,
);
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ type LidoSDKCorePropsRpcProps =

export type LidoSDKCoreProps = {
chainId: (typeof SUPPORTED_CHAINS)[number];
rpcUrls: string[];
web3Provider?: WalletClient;
rpcProvider?: undefined;
logMode?: LOG_MODE;
} & LidoSDKCorePropsRpcProps;

Expand Down
31 changes: 31 additions & 0 deletions packages/sdk/src/erc20/__tests__/steth-wallet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { beforeAll, describe } from '@jest/globals';
import { LidoSDKstETH } from '../steth.js';
import {
useRpcCore,
useWeb3Core,
} from '../../../tests/utils/fixtures/use-core.js';
import { expectERC20Wallet } from '../../../tests/utils/expect/expect-erc20-wallet.js';
import { LIDO_CONTRACT_NAMES } from '../../index.js';
import { useStake } from '../../../tests/utils/fixtures/use-stake.js';
import { useTestsEnvs } from '../../../tests/utils/fixtures/use-test-envs.js';
import { SPENDING_TIMEOUT } from '../../../tests/utils/test-spending.js';

describe('LidoSDKstETH', () => {
const rpcCore = useRpcCore();
const web3Core = useWeb3Core();
const stake = useStake();
const { skipSpendingTests } = useTestsEnvs();

const constructedWithRpcCore = new LidoSDKstETH({ core: rpcCore });
const constructedWithWeb3Core = new LidoSDKstETH({ core: web3Core });

beforeAll(async () => {
if (!skipSpendingTests) await stake.stakeEth({ value: 500n });
}, SPENDING_TIMEOUT);

expectERC20Wallet({
contractName: LIDO_CONTRACT_NAMES.lido,
constructedWithRpcCore,
constructedWithWeb3Core,
});
});
23 changes: 23 additions & 0 deletions packages/sdk/src/erc20/__tests__/steth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe } from '@jest/globals';
import { LidoSDKstETH } from '../steth.js';
import {
useRpcCore,
useWeb3Core,
} from '../../../tests/utils/fixtures/use-core.js';
import { expectERC20 } from '../../../tests/utils/expect/expect-erc20.js';
import { LIDO_CONTRACT_NAMES } from '../../index.js';

describe('LidoSDKstETH', () => {
const rpcCore = useRpcCore();
const web3Core = useWeb3Core();

const constructedWithRpcCore = new LidoSDKstETH({ core: rpcCore });
const constructedWithWeb3Core = new LidoSDKstETH({ core: web3Core });

expectERC20({
contractName: LIDO_CONTRACT_NAMES.lido,
constructedWithRpcCore,
constructedWithWeb3Core,
ModulePrototype: LidoSDKstETH,
});
});
31 changes: 31 additions & 0 deletions packages/sdk/src/erc20/__tests__/wsteth-wallet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { beforeAll, describe } from '@jest/globals';
import { LidoSDKwstETH } from '../wsteth.js';
import {
useRpcCore,
useWeb3Core,
} from '../../../tests/utils/fixtures/use-core.js';
import { expectERC20Wallet } from '../../../tests/utils/expect/expect-erc20-wallet.js';
import { LIDO_CONTRACT_NAMES } from '../../index.js';
import { SPENDING_TIMEOUT } from '../../../tests/utils/test-spending.js';
import { useWrap } from '../../../tests/utils/fixtures/use-wrap.js';
import { useTestsEnvs } from '../../../tests/utils/fixtures/use-test-envs.js';

describe('LidoSDKwstETH', () => {
const rpcCore = useRpcCore();
const web3Core = useWeb3Core();
const wrap = useWrap();
const { skipSpendingTests } = useTestsEnvs();

const constructedWithRpcCore = new LidoSDKwstETH({ core: rpcCore });
const constructedWithWeb3Core = new LidoSDKwstETH({ core: web3Core });

beforeAll(async () => {
if (!skipSpendingTests) await wrap.wrapEth({ value: 600n });
}, SPENDING_TIMEOUT);

expectERC20Wallet({
contractName: LIDO_CONTRACT_NAMES.wsteth,
constructedWithRpcCore,
constructedWithWeb3Core,
});
});
23 changes: 23 additions & 0 deletions packages/sdk/src/erc20/__tests__/wsteth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe } from '@jest/globals';
import { LidoSDKwstETH } from '../wsteth.js';
import {
useRpcCore,
useWeb3Core,
} from '../../../tests/utils/fixtures/use-core.js';
import { expectERC20 } from '../../../tests/utils/expect/expect-erc20.js';
import { LIDO_CONTRACT_NAMES } from '../../index.js';

describe('LidoSDKWsteth', () => {
const rpcCore = useRpcCore();
const web3Core = useWeb3Core();

const constructedWithRpcCore = new LidoSDKwstETH({ core: rpcCore });
const constructedWithWeb3Core = new LidoSDKwstETH({ core: web3Core });

expectERC20({
contractName: LIDO_CONTRACT_NAMES.wsteth,
constructedWithRpcCore,
constructedWithWeb3Core,
ModulePrototype: LidoSDKwstETH,
});
});
3 changes: 2 additions & 1 deletion packages/sdk/src/erc20/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export abstract class AbstractLidoSDKErc20 extends LidoSDKModule {
spender,
deadline = LidoSDKCore.INFINITY_DEADLINE_VALUE,
} = props;
const web3Provider = this.core.useWeb3Provider();
const contract = await this.getContract();
const domain = await this.erc721Domain();
const accountAddress = await this.core.getWeb3Address(account);
Expand All @@ -177,7 +178,7 @@ export abstract class AbstractLidoSDKErc20 extends LidoSDKModule {
};

return {
account: account ?? accountAddress,
account: account ?? web3Provider.account ?? accountAddress,
domain,
types: PERMIT_MESSAGE_TYPES,
primaryType: 'Permit',
Expand Down
Loading

0 comments on commit 59c9fd3

Please sign in to comment.