Skip to content

Commit bbfea49

Browse files
feat: add context to SystemContract onDepositAndCall (#64)
1 parent 14a502e commit bbfea49

File tree

8 files changed

+136
-33
lines changed

8 files changed

+136
-33
lines changed

contracts/zevm/SystemContract.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface SystemContractErrors {
1515
error ZeroAddress();
1616
}
1717

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

7273
IZRC20(zrc20).deposit(target, amount);
73-
zContract(target).onCrossChainCall(zrc20, amount, message);
74+
zContract(target).onCrossChainCall(context, zrc20, amount, message);
7475
}
7576

7677
/**
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity 0.8.7;
33

4+
struct Context {
5+
bytes origin;
6+
address sender;
7+
uint256 chainID;
8+
}
9+
410
interface zContract {
5-
function onCrossChainCall(address zrc20, uint256 amount, bytes calldata message) external;
11+
function onCrossChainCall(Context calldata context, address zrc20, uint256 amount, bytes calldata message) external;
612
}
13+
14+

pkg/contracts/zevm/interfaces/zcontract.sol/zcontract.go

Lines changed: 20 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/contracts/zevm/systemcontract.sol/systemcontract.go

Lines changed: 21 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typechain-types/contracts/zevm/SystemContract.sol/SystemContract.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,22 @@ import type {
2727
PromiseOrValue,
2828
} from "../../../common";
2929

30+
export type ContextStruct = {
31+
origin: PromiseOrValue<BytesLike>;
32+
sender: PromiseOrValue<string>;
33+
chainID: PromiseOrValue<BigNumberish>;
34+
};
35+
36+
export type ContextStructOutput = [string, string, BigNumber] & {
37+
origin: string;
38+
sender: string;
39+
chainID: BigNumber;
40+
};
41+
3042
export interface SystemContractInterface extends utils.Interface {
3143
functions: {
3244
"FUNGIBLE_MODULE_ADDRESS()": FunctionFragment;
33-
"depositAndCall(address,uint256,address,bytes)": FunctionFragment;
45+
"depositAndCall((bytes,address,uint256),address,uint256,address,bytes)": FunctionFragment;
3446
"gasCoinZRC20ByChainId(uint256)": FunctionFragment;
3547
"gasPriceByChainId(uint256)": FunctionFragment;
3648
"gasZetaPoolByChainId(uint256)": FunctionFragment;
@@ -72,6 +84,7 @@ export interface SystemContractInterface extends utils.Interface {
7284
encodeFunctionData(
7385
functionFragment: "depositAndCall",
7486
values: [
87+
ContextStruct,
7588
PromiseOrValue<string>,
7689
PromiseOrValue<BigNumberish>,
7790
PromiseOrValue<string>,
@@ -303,6 +316,7 @@ export interface SystemContract extends BaseContract {
303316
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<[string]>;
304317

305318
depositAndCall(
319+
context: ContextStruct,
306320
zrc20: PromiseOrValue<string>,
307321
amount: PromiseOrValue<BigNumberish>,
308322
target: PromiseOrValue<string>,
@@ -372,6 +386,7 @@ export interface SystemContract extends BaseContract {
372386
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<string>;
373387

374388
depositAndCall(
389+
context: ContextStruct,
375390
zrc20: PromiseOrValue<string>,
376391
amount: PromiseOrValue<BigNumberish>,
377392
target: PromiseOrValue<string>,
@@ -441,6 +456,7 @@ export interface SystemContract extends BaseContract {
441456
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<string>;
442457

443458
depositAndCall(
459+
context: ContextStruct,
444460
zrc20: PromiseOrValue<string>,
445461
amount: PromiseOrValue<BigNumberish>,
446462
target: PromiseOrValue<string>,
@@ -540,6 +556,7 @@ export interface SystemContract extends BaseContract {
540556
FUNGIBLE_MODULE_ADDRESS(overrides?: CallOverrides): Promise<BigNumber>;
541557

542558
depositAndCall(
559+
context: ContextStruct,
543560
zrc20: PromiseOrValue<string>,
544561
amount: PromiseOrValue<BigNumberish>,
545562
target: PromiseOrValue<string>,
@@ -612,6 +629,7 @@ export interface SystemContract extends BaseContract {
612629
): Promise<PopulatedTransaction>;
613630

614631
depositAndCall(
632+
context: ContextStruct,
615633
zrc20: PromiseOrValue<string>,
616634
amount: PromiseOrValue<BigNumberish>,
617635
target: PromiseOrValue<string>,

typechain-types/contracts/zevm/interfaces/ZContract.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,29 @@ import type {
2323
PromiseOrValue,
2424
} from "../../../common";
2525

26+
export type ContextStruct = {
27+
origin: PromiseOrValue<BytesLike>;
28+
sender: PromiseOrValue<string>;
29+
chainID: PromiseOrValue<BigNumberish>;
30+
};
31+
32+
export type ContextStructOutput = [string, string, BigNumber] & {
33+
origin: string;
34+
sender: string;
35+
chainID: BigNumber;
36+
};
37+
2638
export interface ZContractInterface extends utils.Interface {
2739
functions: {
28-
"onCrossChainCall(address,uint256,bytes)": FunctionFragment;
40+
"onCrossChainCall((bytes,address,uint256),address,uint256,bytes)": FunctionFragment;
2941
};
3042

3143
getFunction(nameOrSignatureOrTopic: "onCrossChainCall"): FunctionFragment;
3244

3345
encodeFunctionData(
3446
functionFragment: "onCrossChainCall",
3547
values: [
48+
ContextStruct,
3649
PromiseOrValue<string>,
3750
PromiseOrValue<BigNumberish>,
3851
PromiseOrValue<BytesLike>
@@ -75,6 +88,7 @@ export interface ZContract extends BaseContract {
7588

7689
functions: {
7790
onCrossChainCall(
91+
context: ContextStruct,
7892
zrc20: PromiseOrValue<string>,
7993
amount: PromiseOrValue<BigNumberish>,
8094
message: PromiseOrValue<BytesLike>,
@@ -83,6 +97,7 @@ export interface ZContract extends BaseContract {
8397
};
8498

8599
onCrossChainCall(
100+
context: ContextStruct,
86101
zrc20: PromiseOrValue<string>,
87102
amount: PromiseOrValue<BigNumberish>,
88103
message: PromiseOrValue<BytesLike>,
@@ -91,6 +106,7 @@ export interface ZContract extends BaseContract {
91106

92107
callStatic: {
93108
onCrossChainCall(
109+
context: ContextStruct,
94110
zrc20: PromiseOrValue<string>,
95111
amount: PromiseOrValue<BigNumberish>,
96112
message: PromiseOrValue<BytesLike>,
@@ -102,6 +118,7 @@ export interface ZContract extends BaseContract {
102118

103119
estimateGas: {
104120
onCrossChainCall(
121+
context: ContextStruct,
105122
zrc20: PromiseOrValue<string>,
106123
amount: PromiseOrValue<BigNumberish>,
107124
message: PromiseOrValue<BytesLike>,
@@ -111,6 +128,7 @@ export interface ZContract extends BaseContract {
111128

112129
populateTransaction: {
113130
onCrossChainCall(
131+
context: ContextStruct,
114132
zrc20: PromiseOrValue<string>,
115133
amount: PromiseOrValue<BigNumberish>,
116134
message: PromiseOrValue<BytesLike>,

0 commit comments

Comments
 (0)