Getting Invalid struct AssetId error in TS sdk

I have a contract with getter get_max_abs_position_size that takes trades address and token assetId, after building abi I got two of those types that are equivalent to AssetId and Address in Rust SDK

export type AddressInput = { value: string };
export type AssetIdInput = { value: string };

So I implemented func simulation this way

	const result = await clearingHouse.functions
			.get_max_abs_position_size(addressInput, baseAsset)
			.addContracts([
				contracts?.accountBalanceAbi,
				contracts?.proxyAbi,
				contracts?.clearingHouseAbi,
				contracts?.vaultAbi,
				contracts?.insuranceFundAbi,
			])
			.simulate();

But it fails with this error

Logs of my arguments

{value: '0x46553ae0c503dbd4a0a545280a4fe43ca8951a6a364131df8cc7a271c0cf2693'} 
{value: '0x26829bff466f19001665597228458372fd57cbd325864c7118b5eb5441c42157'}

Good find @sway , we are incorrectly encoding this type. I’ve created an issue for it, you can track the progress here.

1 Like

cool, maybe you can provide me fuels version with a fix? It’s really blocking me atm, same way fix for typegen was done in “fuels”: “0.0.0-pr-1468-20231129113808”

Of course, please use fuels@pr-1476 :slight_smile:

@sway Would be great if you could confirm if that PR version solves it for you also.

It doesn’t

Please try fuels@0.0.0-pr-1476-20231204212753

I got a different error, I am not sure if it’s related to wrong call, because there is nothing much to do wrong in simulate

updateMaxValueForMarket = async (clearingHouse: ClearingHouseAbi) => {
		this.setMaxAbsPositionSize({ long: new BN(71428571), short: new BN(71428571) });
		const { tradeStore, accountStore } = this.rootStore;
		const addressInput = accountStore.addressInput;
		const baseAsset = { value: TOKENS_BY_SYMBOL.BTC.assetId };
		const contracts = tradeStore.contractsToRead;
		if (addressInput == null || contracts == null) return;

		const result = await clearingHouse.functions
			.get_max_abs_position_size(addressInput, baseAsset)
			.addContracts([
				contracts?.accountBalanceAbi,
				contracts?.proxyAbi,
				contracts?.clearingHouseAbi,
				contracts?.vaultAbi,
				contracts?.insuranceFundAbi,
			])
			.simulate();
		console.log("result", result.value);
	};


this error

With the above example I am not able to recreate the problem. Are you able to reproduce in a minimalistic repository?

Sure, here it is

Okay so given this error is of type Revert we know that it is happening inside the script call (something within the contract), we know that the AssetId encoding fix is working. So the above issue has been resolved and let’s deal with the issue with the contract in isolation, outside of this forum post.

1 Like