FuelLabs / fuels-ts

Fuel Network Typescript SDK
https://docs.fuel.network/docs/fuels-ts/
Apache License 2.0
44.05k stars 1.35k forks source link

Provide better ergonomics for proxied contract calls #3145

Closed arboleya closed 1 month ago

arboleya commented 1 month ago

We should provide a type-safe API that can work behind proxied contracts.

This should go in tandem with:

Original request:

danielbate commented 1 month ago

At face value I think this should work out of the box with addContracts however we'll get type errors, consider the following example:

const myContract = new Contract('0x01', MyContractAbi, wallet);
const myProxyContract = new Contract('0x02', MyProxyAbi, wallet);

await myContract.functions.myContractXyz().addContracts([myProxyContract]).call();

The proxy and it's ABI is added to the call so can use it and it's logs. However, the ABI is only really useful for logged types. For proxy calls, we also want to be able to call methods available to myProxyContact.

The solution addProxyContract should perform everything addContracts can, but also allow us to safely perform functions from the proxy.

await myContract.functions.myProxyContractXyz().addProxyContracts([myProxyContract]).call();

I'd recommend testing this first with a proxy contract and seeing how it works with the current SDK before informing the solution.

arboleya commented 1 month ago

It turns out that proxy contracts are supported out of the box.

The only thing that needs handling is proxy deployments: