Skip to content

Commit

Permalink
feat: skip onZetaMessage and onZetaRevert if no args (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev authored May 7, 2024
1 parent 03064a5 commit d657a69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
3 changes: 3 additions & 0 deletions packages/tasks/src/processTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ const prepareData = (args: any) => {

const feesNative = args.fees === "native";

const argsListNotEmpty = argsList.length > 0;

return {
args,
arguments: {
argsListNotEmpty,
casts,
feesNative,
names,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.so
import "@zetachain/protocol-contracts/contracts/evm/Zeta.eth.sol";
{{/unless}}

contract {{contractName}} is ZetaInteractor, ZetaReceiver {
error InvalidMessageType();
contract {{contractName}} is ZetaInteractor{{#if arguments.argsListNotEmpty}}, ZetaReceiver{{/if}} {
{{#unless arguments.feesNative}}
error ErrorTransferringZeta();
{{/unless}}

{{#if arguments.argsListNotEmpty}}
event {{contractName}}Event({{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}});
event {{contractName}}RevertedEvent({{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}});

bytes32 public constant {{contractNameUnderscore}}_MESSAGE_TYPE =
keccak256("CROSS_CHAIN_{{contractNameUnderscore}}");
{{/if}}

{{#if arguments.feesNative}}
ZetaTokenConsumer private immutable _zetaConsumer;
{{/if}}
Expand Down Expand Up @@ -53,37 +52,35 @@ contract {{contractName}} is ZetaInteractor, ZetaReceiver {
destinationChainId: destinationChainId,
destinationAddress: interactorsByChainId[destinationChainId],
destinationGasLimit: 300000,
message: abi.encode({{contractNameUnderscore}}_MESSAGE_TYPE{{#if arguments.pairs}}, {{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[0]}}{{/each}}{{/if}}),
message: abi.encode({{#if arguments.pairs}}{{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[0]}}{{/each}}{{/if}}),
zetaValueAndGas: zetaValueAndGas,
zetaParams: abi.encode("")
})
);
}

{{#if arguments.argsListNotEmpty}}

function onZetaMessage(
ZetaInterfaces.ZetaMessage calldata zetaMessage
) external override isValidMessageCall(zetaMessage) {
(bytes32 messageType{{#if arguments.pairsWithDataLocation}}, {{#each arguments.pairsWithDataLocation}}{{#if @index}}, {{/if}}{{this.[1]}} {{this.[0]}}{{/each}}{{/if}}) = abi.decode(
zetaMessage.message, (bytes32{{#if arguments.pairs}}, {{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}}{{/if}})
({{#each arguments.pairsWithDataLocation}}{{#if @index}}, {{/if}}{{this.[1]}} {{this.[0]}} {{/each}}) = abi.decode(
zetaMessage.message, ({{#if arguments.pairs}}{{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}}{{/if}})
);

if (messageType != {{contractNameUnderscore}}_MESSAGE_TYPE)
revert InvalidMessageType();

emit {{contractName}}Event({{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[0]}}{{/each}});
}

function onZetaRevert(
ZetaInterfaces.ZetaRevert calldata zetaRevert
) external override isValidRevertCall(zetaRevert) {
(bytes32 messageType{{#if arguments.pairsWithDataLocation}}, {{#each arguments.pairsWithDataLocation}}{{#if @index}}, {{/if}}{{this.[1]}} {{this.[0]}}{{/each}}{{/if}}) = abi.decode(
({{#if arguments.pairsWithDataLocation}}{{#each arguments.pairsWithDataLocation}}{{#if @index}}, {{/if}}{{this.[1]}} {{this.[0]}}{{/each}}{{/if}}) = abi.decode(
zetaRevert.message,
(bytes32{{#if arguments.pairs}}, {{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}}{{/if}})
({{#if arguments.pairs}}{{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[1]}}{{/each}}{{/if}})
);

if (messageType != {{contractNameUnderscore}}_MESSAGE_TYPE)
revert InvalidMessageType();

emit {{contractName}}RevertedEvent({{#each arguments.pairs}}{{#if @index}}, {{/if}}{{this.[0]}}{{/each}});
}

{{/if}}
}
2 changes: 1 addition & 1 deletion packages/tasks/templates/messaging/tasks/deploy.ts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
networks.map(async (networkName: ParamChainName) => {
contracts[networkName] = await deployContract(
hre,
networkName,
networkName as ParamChainName,
args.json,
args.gasLimit
);
Expand Down

0 comments on commit d657a69

Please sign in to comment.