Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/__tests__/token-registry-functions/transfers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ describe.each(providers)('Transfers', async ({ Provider, ethersVersion, titleEsc
describe(`transfer holder with TR Version ${titleEscrowVersion} and ethers version ${ethersVersion}`, () => {
const params = isV5TT
? {
holderAddress: '0xholder',
newHolderAddress: '0xholder',
remarks: '0xencrypted_remarks',
tokenId: 1,
}
: {
holderAddress: '0xholder',
newHolderAddress: '0xholder',
tokenId: 1,
};
const txHash = isV5TT ? 'v5_transfer_holder_tx_hash' : 'v4_transfer_holder_tx_hash';
Expand Down
8 changes: 4 additions & 4 deletions src/token-registry-functions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const transferHolder = async (

if (!titleEscrowAddress) throw new Error('Token registry address is required');
if (!signer.provider) throw new Error('Provider is required');
const { holderAddress, remarks } = params;
const { newHolderAddress, remarks } = params;

// Connect V5 contract by default
// let titleEscrowContract: v5Contracts.TitleEscrow | v4Contracts.TitleEscrow =
Expand Down Expand Up @@ -121,7 +121,7 @@ const transferHolder = async (
// Check callStatic (dry run)
try {
const isV6 = isV6EthersProvider(signer.provider);
const args = isV5TT ? [holderAddress, encryptedRemarks] : [holderAddress];
const args = isV5TT ? [newHolderAddress, encryptedRemarks] : [newHolderAddress];

if (isV6) {
await (titleEscrowContract as ContractV6).transferHolder.staticCall(...args);
Expand All @@ -137,9 +137,9 @@ const transferHolder = async (
const txOptions = await getTxOptions(signer, chainId, maxFeePerGas, maxPriorityFeePerGas);
// Send the actual transaction
if (isV5TT) {
return await titleEscrowContract.transferHolder(holderAddress, encryptedRemarks, txOptions);
return await titleEscrowContract.transferHolder(newHolderAddress, encryptedRemarks, txOptions);
} else if (isV4TT) {
return await titleEscrowContract.transferHolder(holderAddress, txOptions);
return await titleEscrowContract.transferHolder(newHolderAddress, txOptions);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/token-registry-functions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type OwnerOfTokenOptions = {
};

export interface TransferHolderParams {
holderAddress: string;
newHolderAddress: string;
remarks?: string;
}
export interface TransferBeneficiaryParams {
Expand Down
18 changes: 15 additions & 3 deletions src/token-registry-functions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { isV6EthersProvider } from '../utils/ethers';
import { GasValue } from './types';
import { CHAIN_ID, SUPPORTED_CHAINS } from '@tradetrust-tt/tradetrust-utils';
import { Signer } from 'ethers';
import { Signer as SignerV6 } from 'ethersV6';
import { Signer as SignerV6, BigNumberish } from 'ethersV6';

const getTxOptions = async (
signer: SignerV6 | Signer,
chainId: CHAIN_ID,
maxFeePerGas: GasValue,
maxPriorityFeePerGas: GasValue,
) => {
): Promise<{ maxFeePerGas?: GasValue; maxPriorityFeePerGas?: GasValue }> => {
// If gas values are missing, query gas station if available
if (!maxFeePerGas || !maxPriorityFeePerGas) {
chainId = chainId ?? ((await getChainIdSafe(signer)) as unknown as CHAIN_ID);
Expand All @@ -21,7 +21,19 @@ const getTxOptions = async (
maxPriorityFeePerGas = gasFees?.maxPriorityFeePerGas ?? 0;
}
}
return maxFeePerGas && maxPriorityFeePerGas ? { maxFeePerGas, maxPriorityFeePerGas } : {};
if (maxFeePerGas && maxPriorityFeePerGas) {
if (isV6EthersProvider(signer.provider)) {
// For ethers v6, cast gas values as BigNumberish
return {
maxFeePerGas: maxFeePerGas as BigNumberish,
maxPriorityFeePerGas: maxPriorityFeePerGas as BigNumberish,
};
} else {
// For ethers v5, return as is
return { maxFeePerGas, maxPriorityFeePerGas };
}
}
return {};
};

// 🔍 Handles both Ethers v5 and v6 signer types
Expand Down