Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix autoAddFee #168

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading