Skip to content

Commit

Permalink
feat: add context to SystemContract onDepositAndCall (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 authored Aug 4, 2023
1 parent 14a502e commit bbfea49
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 33 deletions.
5 changes: 3 additions & 2 deletions contracts/zevm/SystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface SystemContractErrors {
error ZeroAddress();
}


/**
* @dev The system contract it's called by the protocol to interact with the blockchain.
* Also includes a lot of tools to make easier to interact with ZetaChain.
Expand Down Expand Up @@ -65,12 +66,12 @@ contract SystemContract is SystemContractErrors {
* @param target, contract address to make a call after deposit.
* @param message, calldata for a call.
*/
function depositAndCall(address zrc20, uint256 amount, address target, bytes calldata message) external {
function depositAndCall(Context calldata context, address zrc20, uint256 amount, address target, bytes calldata message) external {
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule();
if (target == FUNGIBLE_MODULE_ADDRESS || target == address(this)) revert InvalidTarget();

IZRC20(zrc20).deposit(target, amount);
zContract(target).onCrossChainCall(zrc20, amount, message);
zContract(target).onCrossChainCall(context, zrc20, amount, message);
}

/**
Expand Down
10 changes: 9 additions & 1 deletion contracts/zevm/interfaces/zContract.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

struct Context {
bytes origin;
address sender;
uint256 chainID;
}

interface zContract {
function onCrossChainCall(address zrc20, uint256 amount, bytes calldata message) external;
function onCrossChainCall(Context calldata context, address zrc20, uint256 amount, bytes calldata message) external;
}


33 changes: 20 additions & 13 deletions pkg/contracts/zevm/interfaces/zcontract.sol/zcontract.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 21 additions & 14 deletions pkg/contracts/zevm/systemcontract.sol/systemcontract.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ import type {
PromiseOrValue,
} from "../../../common";

export type ContextStruct = {
origin: PromiseOrValue<BytesLike>;
sender: PromiseOrValue<string>;
chainID: PromiseOrValue<BigNumberish>;
};

export type ContextStructOutput = [string, string, BigNumber] & {
origin: string;
sender: string;
chainID: BigNumber;
};

export interface SystemContractInterface extends utils.Interface {
functions: {
"FUNGIBLE_MODULE_ADDRESS()": FunctionFragment;
"depositAndCall(address,uint256,address,bytes)": FunctionFragment;
"depositAndCall((bytes,address,uint256),address,uint256,address,bytes)": FunctionFragment;
"gasCoinZRC20ByChainId(uint256)": FunctionFragment;
"gasPriceByChainId(uint256)": FunctionFragment;
"gasZetaPoolByChainId(uint256)": FunctionFragment;
Expand Down Expand Up @@ -72,6 +84,7 @@ export interface SystemContractInterface extends utils.Interface {
encodeFunctionData(
functionFragment: "depositAndCall",
values: [
ContextStruct,
PromiseOrValue<string>,
PromiseOrValue<BigNumberish>,
PromiseOrValue<string>,
Expand Down Expand Up @@ -303,6 +316,7 @@ export interface SystemContract extends BaseContract {
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<[string]>;

depositAndCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
target: PromiseOrValue<string>,
Expand Down Expand Up @@ -372,6 +386,7 @@ export interface SystemContract extends BaseContract {
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<string>;

depositAndCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
target: PromiseOrValue<string>,
Expand Down Expand Up @@ -441,6 +456,7 @@ export interface SystemContract extends BaseContract {
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<string>;

depositAndCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
target: PromiseOrValue<string>,
Expand Down Expand Up @@ -540,6 +556,7 @@ export interface SystemContract extends BaseContract {
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<BigNumber>;

depositAndCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
target: PromiseOrValue<string>,
Expand Down Expand Up @@ -612,6 +629,7 @@ export interface SystemContract extends BaseContract {
): Promise<PopulatedTransaction>;

depositAndCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
target: PromiseOrValue<string>,
Expand Down
20 changes: 19 additions & 1 deletion typechain-types/contracts/zevm/interfaces/ZContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,29 @@ import type {
PromiseOrValue,
} from "../../../common";

export type ContextStruct = {
origin: PromiseOrValue<BytesLike>;
sender: PromiseOrValue<string>;
chainID: PromiseOrValue<BigNumberish>;
};

export type ContextStructOutput = [string, string, BigNumber] & {
origin: string;
sender: string;
chainID: BigNumber;
};

export interface ZContractInterface extends utils.Interface {
functions: {
"onCrossChainCall(address,uint256,bytes)": FunctionFragment;
"onCrossChainCall((bytes,address,uint256),address,uint256,bytes)": FunctionFragment;
};

getFunction(nameOrSignatureOrTopic: "onCrossChainCall"): FunctionFragment;

encodeFunctionData(
functionFragment: "onCrossChainCall",
values: [
ContextStruct,
PromiseOrValue<string>,
PromiseOrValue<BigNumberish>,
PromiseOrValue<BytesLike>
Expand Down Expand Up @@ -75,6 +88,7 @@ export interface ZContract extends BaseContract {

functions: {
onCrossChainCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
message: PromiseOrValue<BytesLike>,
Expand All @@ -83,6 +97,7 @@ export interface ZContract extends BaseContract {
};

onCrossChainCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
message: PromiseOrValue<BytesLike>,
Expand All @@ -91,6 +106,7 @@ export interface ZContract extends BaseContract {

callStatic: {
onCrossChainCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
message: PromiseOrValue<BytesLike>,
Expand All @@ -102,6 +118,7 @@ export interface ZContract extends BaseContract {

estimateGas: {
onCrossChainCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
message: PromiseOrValue<BytesLike>,
Expand All @@ -111,6 +128,7 @@ export interface ZContract extends BaseContract {

populateTransaction: {
onCrossChainCall(
context: ContextStruct,
zrc20: PromiseOrValue<string>,
amount: PromiseOrValue<BigNumberish>,
message: PromiseOrValue<BytesLike>,
Expand Down
Loading

0 comments on commit bbfea49

Please sign in to comment.