Skip to content

Commit

Permalink
Merge pull request #132 from lidofinance/develop
Browse files Browse the repository at this point in the history
SDK v3.2.2
  • Loading branch information
Jeday authored May 29, 2024
2 parents c470d64 + 8a5153a commit b8f766f
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"parserOptions": {
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "react"],
"plugins": ["@typescript-eslint", "react", "deprecation"],
"rules": {
"deprecation/deprecation": "warn",
"@typescript-eslint/require-await": "off",
"react/display-name": "off",
"@typescript-eslint/no-shadow": "off",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-eslint-comments": "^3",
"eslint-plugin-import": "^2",
"eslint-plugin-jest": "^27",
Expand Down
11 changes: 11 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 3.2.2

## SDK

### Fixed

- fixed edge-case in `withdraw.views.findCheckpointHints` where last finalized request would fail assertion with `Cannot find hints for unfinalized request...`
- subsequently fixed same error in `withdraw.request-info`, `withdraw.claim` modules

# 3.2.0

# 3.2.1

## SDK
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/common/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { SDKError, type SDKErrorProps, ERROR_CODE } from './sdk-error.js';
export { isBigint } from './is-bigint.js';
// eslint-disable-next-line deprecation/deprecation
export { addressEqual } from './address-equal.js';
6 changes: 3 additions & 3 deletions packages/sdk/src/stake/stake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
encodeFunctionData,
decodeEventLog,
getAbiItem,
getEventSelector,
toEventHash,
isAddressEqual,
} from 'viem';

Expand Down Expand Up @@ -44,10 +44,10 @@ import { LidoSDKModule } from '../common/class-primitives/sdk-module.js';

export class LidoSDKStake extends LidoSDKModule {
// Precomputed event signatures
private static TRANSFER_SIGNATURE = getEventSelector(
private static TRANSFER_SIGNATURE = toEventHash(
getAbiItem({ abi: StethEventsPartialAbi, name: 'Transfer' }),
);
private static TRANSFER_SHARES_SIGNATURE = getEventSelector(
private static TRANSFER_SHARES_SIGNATURE = toEventHash(
getAbiItem({ abi: StethEventsPartialAbi, name: 'TransferShares' }),
);
// Contracts
Expand Down
31 changes: 30 additions & 1 deletion packages/sdk/src/withdraw/__test__/withdraw-views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { parseEther } from 'viem';
import { useWrap } from '../../../tests/utils/fixtures/use-wrap.js';
import { useAccount } from '../../../tests/utils/fixtures/use-wallet-client.js';
import { expectAddress } from '../../../tests/utils/expect/expect-address.js';
import { expectSDKError } from '../../../tests/utils/expect/expect-sdk-error.js';
import { ERROR_CODE } from '../../common/index.js';

describe('withdraw views', () => {
const withdraw = useWithdraw();
const wrap = useWrap();
const { views } = withdraw;
const { views, contract } = withdraw;
const { address } = useAccount();

const requestCount = 10;
Expand Down Expand Up @@ -87,6 +89,33 @@ describe('withdraw views', () => {
}
});

test('can findCheckpointHints for border requests', async () => {
const lastFinalizedRequestId = await (
await contract.getContractWithdrawalQueue()
).read.getLastFinalizedRequestId();

const lastCheckpointIndex = await views.getLastCheckpointIndex();

const [checkpointFirst, checkpointLast] = await views.findCheckpointHints({
sortedIds: [1n, lastFinalizedRequestId],
});

expect(checkpointFirst).toEqual(1n);
expect(checkpointLast).toEqual(lastCheckpointIndex);
});

test('findCheckpointHints errors for unfinalized requests', async () => {
const lastFinalizedRequestId = await (
await contract.getContractWithdrawalQueue()
).read.getLastFinalizedRequestId();

await expectSDKError(async () => {
await views.findCheckpointHints({
sortedIds: [lastFinalizedRequestId + 1n],
});
}, ERROR_CODE.INVALID_ARGUMENT);
});

test('can get withdrawal request ids and statues', async () => {
const ids = await views.getWithdrawalRequestsIds({ account: address });
expect(ids.length > 0).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/withdraw/claim/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
TransactionReceipt,
decodeEventLog,
getAbiItem,
getEventSelector,
toEventHash,
} from 'viem';

import { Logger, ErrorHandler } from '../../common/decorators/index.js';
Expand All @@ -26,7 +26,7 @@ import { PartialWithdrawalQueueEventsAbi } from '../abi/withdrawalQueue.js';

export class LidoSDKWithdrawClaim extends BusModule {
// Precomputed event signatures
private static CLAIM_SIGNATURE = getEventSelector(
private static CLAIM_SIGNATURE = toEventHash(
getAbiItem({
abi: PartialWithdrawalQueueEventsAbi,
name: 'WithdrawalClaimed',
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/withdraw/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ import {
encodeFunctionData,
formatEther,
getAbiItem,
getEventSelector,
toEventHash,
} from 'viem';
import { parseValue } from '../../common/utils/parse-value.js';
import { PartialWithdrawalQueueEventsAbi } from '../abi/withdrawalQueue.js';

export class LidoSDKWithdrawRequest extends BusModule {
// Precomputed event signatures
private static WITHDRAW_SIGNATURE = getEventSelector(
private static WITHDRAW_SIGNATURE = toEventHash(
getAbiItem({
abi: PartialWithdrawalQueueEventsAbi,
name: 'WithdrawalRequested',
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/withdraw/withdraw-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class LidoSDKWithdrawViews extends BusModule {
for (let index = sortedIds.length - 1; index >= 0; index--) {
const id = sortedIds[index];
invariantArgument(
id && id < lastFinalizedRequestId,
id && id <= lastFinalizedRequestId,
`Cannot find hints for unfinalized request ${id?.toString()}`,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/wrap/wrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TransactionReceipt,
decodeEventLog,
getAbiItem,
getEventSelector,
toEventHash,
isAddressEqual,
} from 'viem';

Expand Down Expand Up @@ -40,7 +40,7 @@ import { ERROR_CODE, invariant } from '../common/utils/sdk-error.js';
import { LidoSDKModule } from '../common/class-primitives/sdk-module.js';

export class LidoSDKWrap extends LidoSDKModule {
private static TRANSFER_SIGNATURE = getEventSelector(
private static TRANSFER_SIGNATURE = toEventHash(
getAbiItem({ abi: PartialTransferEventAbi, name: 'Transfer' }),
);

Expand Down
4 changes: 2 additions & 2 deletions playground/components/action/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { useWeb3 } from '@reef-knot/web3-react';
type ActionProps<TResult> = PropsWithChildren<{
action: () => Promise<TResult> | TResult;
title: string;
renderResult?: (result: TResult) => JSX.Element;
renderError?: (error: SDKError) => JSX.Element;
renderResult?: (result: TResult) => React.JSX.Element;
renderError?: (error: SDKError) => React.JSX.Element;
walletAction?: boolean;
}>;

Expand Down
4 changes: 2 additions & 2 deletions playground/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { AppProps } from 'next/app';
import { ToastContainer, CookiesTooltip } from '@lidofinance/lido-ui';
import Providers from 'providers';

const App = (props: AppProps): JSX.Element => {
const App = (props: AppProps): React.JSX.Element => {
const { Component, pageProps } = props;

return <Component {...pageProps} />;
};

const MemoApp = memo(App);

const AppWrapper = (props: AppProps): JSX.Element => {
const AppWrapper = (props: AppProps): React.JSX.Element => {
return (
<Providers>
<MemoApp {...props} />
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class MyDocument extends Document {
return `${host}/lido-preview.png`;
}

render(): JSX.Element {
render(): React.JSX.Element {
return (
<Html lang="en">
<Head>
Expand Down
Loading

0 comments on commit b8f766f

Please sign in to comment.