Skip to content

Commit

Permalink
Merge pull request #168 from thepower/feat/eth-transactions
Browse files Browse the repository at this point in the history
fix: fix autoAddFee
  • Loading branch information
jackkru69 authored Oct 24, 2024
2 parents 813e43d + 500c398 commit 68c779c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/tssdk/src/libs/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Abi,
AbiStateMutability,
} from 'abitype';
import { DecodeFunctionResultReturnType, EncodeFunctionDataParameters } from 'viem/utils';
import { DecodeFunctionResultReturnType, EncodeFunctionDataParameters, isAddress } from 'viem/utils';
import { ContractFunctionArgs, ContractFunctionName } from 'viem/_types/types/contract';
import { AddressApi } from '../address/address';
import { decodeReturnValue, encodeFunction } from '../../helpers/abi.helper';
Expand Down Expand Up @@ -424,11 +424,11 @@ export class NetworkApi {
) {
const { abi, functionName, args = [] } = parameters as EncodeFunctionDataParameters;

const addressHex = AddressApi.textAddressToHex(address);
const addressHex = isAddress(address) ? address : AddressApi.textAddressToEvmAddress(address);

const encodedFunction = encodeFunction({ functionName, args, abi });

const data = { call: '0x0', args: [encodedFunction], to: `0x${addressHex}` };
const data = { call: '0x0', args: [encodedFunction], to: addressHex };

const response = await this.askBlockchainTo(ChainAction.EXECUTE_CALL, {
data,
Expand Down
25 changes: 17 additions & 8 deletions packages/tssdk/src/libs/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,25 +396,34 @@ export const TransactionsApi = {
feeSettings.baseEx &&
feeSettings.kb
) {
feeSettings.fee = BigInt(feeSettings.fee);
feeSettings.baseEx = BigInt(feeSettings.baseEx);
feeSettings.kb = BigInt(feeSettings.kb);

body.p.push([TransactionPurpose.SRCFEE, feeSettings.feeCur, feeSettings.fee]);
let bodySize;
let bodySize: bigint;

do {
bodySize = msgPackEncoder.encode(body).length;
bodySize = BigInt(msgPackEncoder.encode(body).length);
if (bodySize > feeSettings.baseEx) {
body.p.find((item: any) => item[0] === TransactionPurpose.SRCFEE)[2] =
feeSettings.fee +
Math.floor(
((bodySize - feeSettings.baseEx) * feeSettings.kb) / 1024,
const srcFeeItem = body.p.find(
(item: any) => item[0] === TransactionPurpose.SRCFEE,
);

srcFeeItem[2] =
feeSettings.fee +
((bodySize - feeSettings.baseEx) * feeSettings.kb) / 1024n;
}
} while (bodySize !== msgPackEncoder.encode(body).length);
} while (
bodySize !== BigInt(msgPackEncoder.encode(body).length)
);
}

return body;
},

autoAddGas(body: any, gasSettings: any) {
body.p.push([TransactionPurpose.GAS, 'SK', 2000000000n]);
body.p.push([TransactionPurpose.GAS, 'SK', BigInt(2e18)]);
return body;
},

Expand Down

0 comments on commit 68c779c

Please sign in to comment.