Skip to content

Commit

Permalink
refactor: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Sep 9, 2024
1 parent f85e4dc commit 717bae2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions src/gasEstimator/gasEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/gasEstimator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
8 changes: 4 additions & 4 deletions src/gasEstimator/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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,
};
10 changes: 5 additions & 5 deletions test/gasEstimator/gasEstimator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -447,7 +447,7 @@ describe('GasEstimator', function () {
});
});

describe('touchedAccount', function () {
describe('isAccountCreated', function () {
let providerStub: SinonStubbedInstance<providers.BaseProvider>;

beforeEach(function () {
Expand All @@ -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;
});
Expand All @@ -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;
});
Expand Down

0 comments on commit 717bae2

Please sign in to comment.