node icon indicating copy to clipboard operation
node copied to clipboard

Add ability to handle on ZetaChain results from connected chain calls

Open lumtis opened this issue 1 year ago • 0 comments

Describe the Issue

New smart contract architecture provides ability to perform abritrary smart contract call on connected. To fully take advantage of this feature, we should add ability to handle the result from the smart contract.

On smart contract

The solution would contains a lot of similarities with the revert management. We first define a new interface called:

interface ResultReceiver {
    function onResult(ResultContext calldata resultContext, bytes calldata result) external;
}

The resultContext can store various data, but in particular, like revertContext, would contains an arbitrary message for the smart contract to be able to understand the origin, what call, the result belongs to

struct ResultContext {
    bytes resultMessage;
}

A resultOptions can be provided to instruct how to handle the results:

struct ResultOptions {
    address resultReceiver;
    bytes resultMessage;
}

The interface of call and withdrawAndCall is extended to allow provided a resultOptions. When provided result is processed.

During the calls, the gateway would include the result as part of the emitted event

        bytes memory result = _execute(destination, data);

        emit Executed(destination, msg.value, data, result);

On protocol

The protocol (ZetaClient included), read the result as part of the event, this data is added in the CCTX object along with the resultOptions

When resultOptions instructs to process result, at the outbound processing stage, the protocol calls the onResult hook.

A new CCTX status should be added: something like OutboundResultProcessingFailed

lumtis avatar Aug 19 '24 09:08 lumtis