From 589ead546abb9422782ea9feca1c438d18224045 Mon Sep 17 00:00:00 2001 From: Evgeny Taktarov Date: Mon, 25 Nov 2024 21:10:43 +0700 Subject: [PATCH] feat: l2 estimate gas --- packages/sdk/src/l2/__test__/l2.test.ts | 11 +++++++++++ packages/sdk/src/l2/l2.ts | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/sdk/src/l2/__test__/l2.test.ts b/packages/sdk/src/l2/__test__/l2.test.ts index 8212f4a..5f0802c 100644 --- a/packages/sdk/src/l2/__test__/l2.test.ts +++ b/packages/sdk/src/l2/__test__/l2.test.ts @@ -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, @@ -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); @@ -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); diff --git a/packages/sdk/src/l2/l2.ts b/packages/sdk/src/l2/l2.ts index 28667ad..85095aa 100644 --- a/packages/sdk/src/l2/l2.ts +++ b/packages/sdk/src/l2/l2.ts @@ -141,6 +141,18 @@ export class LidoSDKL2 extends LidoSDKModule { }; } + @Logger('Utils:') + public async wrapWstethToStethEstimateGas( + props: WrapPropsWithoutCallback, + ): Promise { + 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, @@ -251,6 +263,19 @@ export class LidoSDKL2 extends LidoSDKModule { return request; } + @Logger('Utils:') + @ErrorHandler() + public async unwrapStethEstimateGas( + props: Omit, + ): Promise { + 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,