From 717bae2bc01d14abfb733a711d69299b2bc29859 Mon Sep 17 00:00:00 2001 From: Francisco Tobar Date: Mon, 9 Sep 2024 10:15:07 -0600 Subject: [PATCH] refactor: pr comments --- src/gasEstimator/gasEstimator.ts | 7 ++++--- src/gasEstimator/index.ts | 4 ++-- src/gasEstimator/utils.ts | 8 ++++---- test/gasEstimator/gasEstimator.test.ts | 10 +++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/gasEstimator/gasEstimator.ts b/src/gasEstimator/gasEstimator.ts index a78b8e7..1bcd56a 100644 --- a/src/gasEstimator/gasEstimator.ts +++ b/src/gasEstimator/gasEstimator.ts @@ -72,11 +72,12 @@ const estimateRelayMaxPossibleGas = async ( * - POST_DEPLOY_EXECUTION: when there is execution in deployment, an additional 1_500 are needed * - STORAGE_REFUND: After the nonces were already touched by a smart wallet deployment or smart wallet execution, we need to subtract 15_000 * - Manually subtract: - * - Without signature, we cannot analyze if there some of the gas costs should be included or not, to avoid underestimating the relay transaction + * - Without signature, we cannot analyze if some of the gas costs should be included or not, to avoid underestimating the relay transaction * the costs are included in all of them. These costs can be subtract by using the following constants: - * - POST_RELAY_DEPLOY_GAS_COST: transfer back cost is always included since we cannot know if the smart wallet is going + * - POST_RELAY_DEPLOY_GAS_COST: The transfer back cost is always included since we cannot know if the smart wallet is going * to have some balance after the execution - * - OWNER_ALREADY_TOUCHED: Owner already touched, the owner of the smart wallet was previously touched + * - ACCOUNT_ALREADY_CREATED: The owner address of the smart wallet was previously created. A utility function was included to check + * if the owner address of smart wallet was already created * @param relayRequest * @param signer * @param options diff --git a/src/gasEstimator/index.ts b/src/gasEstimator/index.ts index da9357e..df386d1 100644 --- a/src/gasEstimator/index.ts +++ b/src/gasEstimator/index.ts @@ -4,8 +4,8 @@ export { } from './gasEstimator'; export { standardMaxPossibleGasEstimation, - touchedAccount, + isAccountCreated, PRE_RELAY_GAS_COST, POST_RELAY_DEPLOY_GAS_COST, - OWNER_ALREADY_TOUCHED, + ACCOUNT_ALREADY_CREATED, } from './utils'; diff --git a/src/gasEstimator/utils.ts b/src/gasEstimator/utils.ts index cbdc6e3..5a96454 100644 --- a/src/gasEstimator/utils.ts +++ b/src/gasEstimator/utils.ts @@ -15,7 +15,7 @@ const POST_RELAY_DEPLOY_GAS_COST = 33_500; const POST_DEPLOY_EXECUTION = 1_500; const POST_DEPLOY_NO_EXECUTION = 4_000; const STORAGE_REFUND = 15_000; -const OWNER_ALREADY_TOUCHED = 25_000; +const ACCOUNT_ALREADY_CREATED = 25_000; const standardMaxPossibleGasEstimation = async ( { relayRequest, metadata: { signature } }: EnvelopingTxRequest, @@ -79,7 +79,7 @@ const resolveSmartWalletAddress = async ( : callForwarder; }; -const touchedAccount = async (address: string) => { +const isAccountCreated = async (address: string) => { const provider = getProvider(); const ownerBalance = await provider.getBalance(address); const ownerTx = await provider.getTransactionCount(address); @@ -90,11 +90,11 @@ const touchedAccount = async (address: string) => { export { standardMaxPossibleGasEstimation, resolveSmartWalletAddress, - touchedAccount, + isAccountCreated, PRE_RELAY_GAS_COST, POST_RELAY_DEPLOY_GAS_COST, POST_DEPLOY_EXECUTION, POST_DEPLOY_NO_EXECUTION, STORAGE_REFUND, - OWNER_ALREADY_TOUCHED, + ACCOUNT_ALREADY_CREATED, }; diff --git a/test/gasEstimator/gasEstimator.test.ts b/test/gasEstimator/gasEstimator.test.ts index 9dbad92..1378bf9 100644 --- a/test/gasEstimator/gasEstimator.test.ts +++ b/test/gasEstimator/gasEstimator.test.ts @@ -24,7 +24,7 @@ import { PRE_RELAY_GAS_COST, resolveSmartWalletAddress, standardMaxPossibleGasEstimation, - touchedAccount, + isAccountCreated, } from '../../src/gasEstimator/utils'; import { createRandomAddress } from '../utils'; import type { EnvelopingTxRequest } from '../../src'; @@ -447,7 +447,7 @@ describe('GasEstimator', function () { }); }); - describe('touchedAccount', function () { + describe('isAccountCreated', function () { let providerStub: SinonStubbedInstance; beforeEach(function () { @@ -462,13 +462,13 @@ describe('GasEstimator', function () { }); it('should return true if balance is not zero', async function () { - const touched = await touchedAccount(createRandomAddress()); + const touched = await isAccountCreated(createRandomAddress()); expect(touched).to.be.true; }); it('should return true if transaction count is greater than 0', async function () { - const touched = await touchedAccount(createRandomAddress()); + const touched = await isAccountCreated(createRandomAddress()); expect(touched).to.be.true; }); @@ -477,7 +477,7 @@ describe('GasEstimator', function () { providerStub.getBalance.resolves(BigNumber.from(0)); providerStub.getTransactionCount.resolves(0); - const touched = await touchedAccount(createRandomAddress()); + const touched = await isAccountCreated(createRandomAddress()); expect(touched).to.be.false; });