Skip to content

Commit

Permalink
feat: l2 estimate gas
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Nov 25, 2024
1 parent 50bec8c commit 589ead5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit 589ead5

Please sign in to comment.