Skip to content

Commit

Permalink
Rename function name and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kourin1996 committed Feb 17, 2025
1 parent 6bc87ba commit d98f203
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions e2e_test/js-tests/test_viem_tx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const testNonceBump = async (
const firstTxHash = await walletClient.sendTransaction({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: await getIntrinsicGasForCustomCurrency(21000, firstCurrency),
gas: await getIntrinsicGasForFeeCurrency(21000, firstCurrency),
maxFeePerGas: firstCap,
maxPriorityFeePerGas: firstCap,
nonce: syncBarrierRequest.nonce + 1,
Expand All @@ -39,7 +39,7 @@ const testNonceBump = async (
secondTxHash = await walletClient.sendTransaction({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 3,
gas: await getIntrinsicGasForCustomCurrency(21000, secondCurrency),
gas: await getIntrinsicGasForFeeCurrency(21000, secondCurrency),
maxFeePerGas: secondCap,
maxPriorityFeePerGas: secondCap,
nonce: syncBarrierRequest.nonce + 1,
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("viem send tx", () => {
const request = await walletClient.prepareTransactionRequest({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: await getIntrinsicGasForCustomCurrency(21000, process.env.FEE_CURRENCY),
gas: await getIntrinsicGasForFeeCurrency(21000, process.env.FEE_CURRENCY),
feeCurrency: process.env.FEE_CURRENCY,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: tip,
Expand All @@ -120,7 +120,7 @@ describe("viem send tx", () => {
const request = await walletClient.prepareTransactionRequest({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: await getIntrinsicGasForCustomCurrency(21000, process.env.FEE_CURRENCY),
gas: await getIntrinsicGasForFeeCurrency(21000, process.env.FEE_CURRENCY),
feeCurrency: process.env.FEE_CURRENCY,
});

Expand Down Expand Up @@ -296,7 +296,7 @@ describe("viem send tx", () => {
const request = await walletClient.prepareTransactionRequest({
to: "0x00000000000000000000000000000000DeaDBeef",
value: 2,
gas: await getIntrinsicGasForCustomCurrency(21000, fc),
gas: await getIntrinsicGasForFeeCurrency(21000, fc),
feeCurrency: fc,
maxFeePerGas: maxFeePerGas,
maxPriorityFeePerGas: 2n,
Expand Down Expand Up @@ -326,12 +326,14 @@ async function getRate(feeCurrencyAddress) {
};
}

async function getIntrinsicGasForCustomCurrency(baseIntrinsicGas, feeCurrency) {
// getIntrinsicGasForFeeCurrency calculates intrinsic gas by adding extra intrinsic gas to the base intrinsic gas and additional cost
async function getIntrinsicGasForFeeCurrency(baseIntrinsicGas, feeCurrency) {
if (!feeCurrency) return baseIntrinsicGas
const extraFee = await getExtraCustomFeeCurrencyIntrinsicGas(feeCurrency)
return BigInt(baseIntrinsicGas) + extraFee;
}

// getExtraCustomFeeCurrencyIntrinsicGas retrieves extra intrinsic gas from the smart contract for custom fee currency.
async function getExtraCustomFeeCurrencyIntrinsicGas(feeCurrency) {
const abi = parseAbi(['function getCurrencyConfig(address token) public view returns (address oracle, uint256 intrinsicGas)']);
const [_, intrinsicGas] = await publicClient.readContract({
Expand Down

0 comments on commit d98f203

Please sign in to comment.