Skip to content

Commit

Permalink
Merge pull request #88 from 1inch/feature/patch-trackReceivedTokenAndTx
Browse files Browse the repository at this point in the history
Patch trackReceivedTokenAndTx method
  • Loading branch information
ZumZoom authored Jun 28, 2023
2 parents 47e1997 + 0b99f78 commit 068fc83
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "2.3.0",
"version": "2.3.1",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"repository": {
Expand Down
17 changes: 8 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { constants } from './prelude';
import hre, { ethers } from 'hardhat';
import { time } from '@nomicfoundation/hardhat-network-helpers';
import { providers, Wallet, Contract, Bytes, ContractTransaction, BigNumberish, BigNumber } from 'ethers';
import { providers, Wallet, Contract, Bytes, ContractReceipt, ContractTransaction, BigNumberish, BigNumber } from 'ethers';
import { DeployOptions, DeployResult } from 'hardhat-deploy/types';

interface DeployContractOptions {
Expand Down Expand Up @@ -90,19 +90,18 @@ export async function trackReceivedTokenAndTx<T extends unknown[]>(
const getBalance = 'balanceOf' in token ? token.balanceOf : provider.getBalance;

const preBalance = await getBalance(wallet);
const txResult = await txPromise(...args);
const postBalance = await getBalance(wallet);
let txResult: ContractTransaction | ContractReceipt = await txPromise(...args);
let txFees = 0n;

if ('wait' in txResult) {
const txReceipt = await txResult.wait();
const txFees =
txResult = await txResult.wait();
txFees =
wallet.toLowerCase() === txResult.from.toLowerCase() && isETH
? txReceipt.gasUsed.toBigInt() * txReceipt.effectiveGasPrice.toBigInt()
? txResult.gasUsed.toBigInt() * txResult.effectiveGasPrice.toBigInt()
: 0n;
return [postBalance.sub(preBalance).add(txFees), txReceipt];
} else {
return [postBalance.sub(preBalance), txResult];
}
const postBalance = await getBalance(wallet);
return [postBalance.sub(preBalance).add(txFees), txResult];
}

export function fixSignature(signature: string) {
Expand Down

0 comments on commit 068fc83

Please sign in to comment.