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

feat: l2 estimate gas #177

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions packages/sdk/src/l2/__test__/l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { expectContract } from '../../../tests/utils/expect/expect-contract.js';
import {
expectAlmostEqualBn,
expectNonNegativeBn,
expectPositiveBn,
} from '../../../tests/utils/expect/expect-bn.js';
import {
SPENDING_TIMEOUT,
Expand Down Expand Up @@ -147,6 +148,11 @@ describe('LidoSDKL2 wrap', () => {
expectAddress(tx.address, stethAddress);
});

testSpending('wrap estimate gas', async () => {
const gas = await l2.wrapWstethToStethEstimateGas({ value });
expectPositiveBn(gas);
});

testSpending('wrap wsteth to steth', async () => {
const stethValue = await l2.steth.convertToSteth(value);
const stethBalanceBefore = await l2.steth.balance(account.address);
Expand Down Expand Up @@ -193,6 +199,11 @@ describe('LidoSDKL2 wrap', () => {
expectAddress(tx.address, stethAddress);
});

testSpending('unwrap estimate gas', async () => {
const gas = await l2.unwrapStethEstimateGas({ value });
expectPositiveBn(gas);
});

testSpending('unwrap', async () => {
const stethValue = await l2.steth.convertToSteth(value);
const stethBalanceBefore = await l2.steth.balance(account.address);
Expand Down
25 changes: 25 additions & 0 deletions packages/sdk/src/l2/l2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ export class LidoSDKL2 extends LidoSDKModule {
};
}

@Logger('Utils:')
public async wrapWstethToStethEstimateGas(
props: WrapPropsWithoutCallback,
): Promise<bigint> {
const { value, account } = await this.parseProps(props);
const contract = await this.getContract();

return contract.estimateGas.wrap([value], {
account,
});
}

@Logger('Utils:')
private async wrapWstethToStethParseEvents(
receipt: TransactionReceipt,
Expand Down Expand Up @@ -251,6 +263,19 @@ export class LidoSDKL2 extends LidoSDKModule {
return request;
}

@Logger('Utils:')
@ErrorHandler()
public async unwrapStethEstimateGas(
props: Omit<WrapProps, 'callback'>,
): Promise<bigint> {
const { value, account } = await this.parseProps(props);
const contract = await this.getContract();

return contract.estimateGas.unwrap([value], {
account,
});
}

@Logger('Utils:')
private async unwrapParseEvents(
receipt: TransactionReceipt,
Expand Down