Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add localnet logic back #9

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 107 additions & 1 deletion packages/localnet/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,113 @@ export const initLocalnet = async (port: number) => {
fungibleModuleSigner
);

await provider.send("evm_mine", []);
// Listen to contracts events
// event Called(address indexed sender, uint256 indexed chainId, bytes receiver, bytes message);
protocolContracts.gatewayZEVM.on("Called", async (...args: Array<any>) => {
console.log("Worker: Called event on GatewayZEVM.");
console.log("Worker: Calling ReceiverEVM through GatewayEVM...");
try {
(deployer as NonceManager).reset();

const receiver = args[2];
const message = args[3];

const executeTx = await protocolContracts.gatewayEVM
.connect(deployer)
.execute(receiver, message, deployOpts);
await executeTx.wait();
} catch (e) {
console.error("failed:", e);
}
});

// event Withdrawn(address indexed sender, uint256 indexed chainId, bytes receiver, address zrc20, uint256 value, uint256 gasfee, uint256 protocolFlatFee, bytes message);
protocolContracts.gatewayZEVM.on("Withdrawn", async (...args: Array<any>) => {
console.log("Worker: Withdrawn event on GatewayZEVM.");
console.log("Worker: Calling ReceiverEVM through GatewayEVM...");
try {
const receiver = args[2];
const message = args[7];
(deployer as NonceManager).reset();

if (message != "0x") {
const executeTx = await protocolContracts.gatewayEVM
.connect(deployer)
.execute(receiver, message, deployOpts);
await executeTx.wait();
}
} catch (e) {
console.error("failed:", e);
}
});

// testContracts.receiverEVM.on("ReceivedPayable", () => {
// console.log("ReceiverEVM: receivePayable called!");
// });

// event Called(address indexed sender, address indexed receiver, bytes payload);
protocolContracts.gatewayEVM.on("Called", async (...args: Array<any>) => {
console.log("Worker: Called event on GatewayEVM.");
console.log("Worker: Calling TestUniversalContract through GatewayZEVM...");
try {
const universalContract = args[1];
const payload = args[2];
(deployer as NonceManager).reset();
// Encode the parameters
const origin = protocolContracts.gatewayZEVM.target;
const sender = await fungibleModuleSigner.getAddress();
const chainID = 1;

// Call the execute function
const executeTx = await protocolContracts.gatewayZEVM
.connect(fungibleModuleSigner)
.execute(
{
origin,
sender,
chainID,
},
testContracts.zrc20.target,
1,
universalContract,
payload,
deployOpts
);
await executeTx.wait();
} catch (e) {
console.error("failed:", e);
}
});

// event Deposited(address indexed sender, address indexed receiver, uint256 amount, address asset, bytes payload);
protocolContracts.gatewayEVM.on("Deposited", async (...args: Array<any>) => {
console.log("Worker: Deposited event on GatewayEVM.");
console.log("Worker: Calling TestUniversalContract through GatewayZEVM...");
try {
const receiver = args[1];
const asset = args[3];
const payload = args[4];
if (payload != "0x") {
const executeTx = await (protocolContracts.gatewayZEVM as any)
.connect(fungibleModuleSigner)
.execute(
[
protocolContracts.gatewayZEVM.target,
await fungibleModuleSigner.getAddress(),
1,
],
asset,
1,
receiver,
payload,
deployOpts
);
await executeTx.wait();
}
} catch (e) {
console.error("failed:", e);
}
});

process.stdin.resume();

Expand Down
Loading