deploy for one evm chain works
This commit is contained in:
parent
179af2cf88
commit
dab5ca286f
|
@ -1,2 +1,4 @@
|
||||||
.DS_STORE
|
.DS_STORE
|
||||||
book
|
book
|
||||||
|
.github
|
||||||
|
CNAME
|
|
@ -0,0 +1,2 @@
|
||||||
|
cache/
|
||||||
|
out/
|
|
@ -0,0 +1,7 @@
|
||||||
|
[default]
|
||||||
|
src = 'src'
|
||||||
|
out = 'out'
|
||||||
|
libs = ['lib']
|
||||||
|
solc_version = '0.8.10'
|
||||||
|
|
||||||
|
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
|
|
@ -0,0 +1,53 @@
|
||||||
|
//SPDX-License-Identifier: Unlicense
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "./Wormhole/IWormhole.sol";
|
||||||
|
|
||||||
|
contract Messenger {
|
||||||
|
string private solana_msg;
|
||||||
|
address private wormhole_core_bridge_address = address(0xC89Ce4735882C9F0f0FE26686c53074E09B0D550);
|
||||||
|
IWormhole core_bridge = IWormhole(wormhole_core_bridge_address);
|
||||||
|
uint32 nonce = 0;
|
||||||
|
mapping(uint16 => bytes32) _applicationContracts;
|
||||||
|
address owner;
|
||||||
|
mapping(bytes32 => bool) _completedMessages;
|
||||||
|
|
||||||
|
constructor(){
|
||||||
|
owner = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendMsg(bytes memory str) public returns (uint64 sequence) {
|
||||||
|
sequence = core_bridge.publishMessage(nonce, str, 1);
|
||||||
|
nonce = nonce+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function recieveEncodedMsg(bytes memory encodedMsg) public {
|
||||||
|
(IWormhole.VM memory vm, bool valid, string memory reason) = core_bridge.parseAndVerifyVM(encodedMsg);
|
||||||
|
|
||||||
|
//1. Check Wormhole Guardian Signatures
|
||||||
|
// If the VM is NOT valid, will return the reason it's not valid
|
||||||
|
// If the VM IS valid, reason will be blank
|
||||||
|
require(valid, reason);
|
||||||
|
|
||||||
|
//2. Check if the Emitter Chain contract is registered
|
||||||
|
require(_applicationContracts[vm.emitterChainId] == vm.emitterAddress, "Invalid Emitter Address!");
|
||||||
|
|
||||||
|
//3. Check that the message hasn't already been processed
|
||||||
|
require(!_completedMessages[vm.hash], "Message already processed");
|
||||||
|
_completedMessages[vm.hash] = true;
|
||||||
|
|
||||||
|
//Do the thing
|
||||||
|
solana_msg = string(vm.payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSolanaMsg() public view returns (string memory){
|
||||||
|
return solana_msg;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
Registers it's sibling applications on other chains as the only ones that can send this instance messages
|
||||||
|
*/
|
||||||
|
function registerApplicationContracts(uint16 chainId, bytes32 applicationAddr) public {
|
||||||
|
require(msg.sender == owner, "Only owner can register new chains!");
|
||||||
|
_applicationContracts[chainId] = applicationAddr;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
// contracts/Messages.sol
|
||||||
|
// SPDX-License-Identifier: Apache 2
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
import "./Structs.sol";
|
||||||
|
|
||||||
|
interface IWormhole is Structs {
|
||||||
|
event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, uint8 consistencyLevel);
|
||||||
|
|
||||||
|
function publishMessage(
|
||||||
|
uint32 nonce,
|
||||||
|
bytes memory payload,
|
||||||
|
uint8 consistencyLevel
|
||||||
|
) external payable returns (uint64 sequence);
|
||||||
|
|
||||||
|
function parseAndVerifyVM(bytes calldata encodedVM) external view returns (Structs.VM memory vm, bool valid, string memory reason);
|
||||||
|
|
||||||
|
function verifyVM(Structs.VM memory vm) external view returns (bool valid, string memory reason);
|
||||||
|
|
||||||
|
function verifySignatures(bytes32 hash, Structs.Signature[] memory signatures, Structs.GuardianSet memory guardianSet) external pure returns (bool valid, string memory reason) ;
|
||||||
|
|
||||||
|
function parseVM(bytes memory encodedVM) external pure returns (Structs.VM memory vm);
|
||||||
|
|
||||||
|
function getGuardianSet(uint32 index) external view returns (Structs.GuardianSet memory) ;
|
||||||
|
|
||||||
|
function getCurrentGuardianSetIndex() external view returns (uint32) ;
|
||||||
|
|
||||||
|
function getGuardianSetExpiry() external view returns (uint32) ;
|
||||||
|
|
||||||
|
function governanceActionIsConsumed(bytes32 hash) external view returns (bool) ;
|
||||||
|
|
||||||
|
function isInitialized(address impl) external view returns (bool) ;
|
||||||
|
|
||||||
|
function chainId() external view returns (uint16) ;
|
||||||
|
|
||||||
|
function governanceChainId() external view returns (uint16);
|
||||||
|
|
||||||
|
function governanceContract() external view returns (bytes32);
|
||||||
|
|
||||||
|
function messageFee() external view returns (uint256) ;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
// contracts/Structs.sol
|
||||||
|
// SPDX-License-Identifier: Apache 2
|
||||||
|
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
|
||||||
|
interface Structs {
|
||||||
|
struct Provider {
|
||||||
|
uint16 chainId;
|
||||||
|
uint16 governanceChainId;
|
||||||
|
bytes32 governanceContract;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GuardianSet {
|
||||||
|
address[] keys;
|
||||||
|
uint32 expirationTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Signature {
|
||||||
|
bytes32 r;
|
||||||
|
bytes32 s;
|
||||||
|
uint8 v;
|
||||||
|
uint8 guardianIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VM {
|
||||||
|
uint8 version;
|
||||||
|
uint32 timestamp;
|
||||||
|
uint32 nonce;
|
||||||
|
uint16 emitterChainId;
|
||||||
|
bytes32 emitterAddress;
|
||||||
|
uint64 sequence;
|
||||||
|
uint8 consistencyLevel;
|
||||||
|
bytes payload;
|
||||||
|
|
||||||
|
uint32 guardianSetIndex;
|
||||||
|
Signature[] signatures;
|
||||||
|
|
||||||
|
bytes32 hash;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
import { exec } from "child_process";
|
||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
async function main(){
|
||||||
|
let config = JSON.parse(fs.readFileSync('./xdapp.config.json').toString());
|
||||||
|
|
||||||
|
if(process.argv[2] == "deploy"){
|
||||||
|
let network = config.networks[process.argv[3]];
|
||||||
|
if (!network){
|
||||||
|
throw new Error("Network not defined in config file.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if(network.type == "evm"){
|
||||||
|
console.log(`Deploying EVM network: ${process.argv[3]} to ${network.rpc}`);
|
||||||
|
exec(
|
||||||
|
`cd chains/evm && forge build && forge create --legacy --rpc-url ${network.rpc} --private-key ${network.privateKey} src/Messenger.sol:Messenger && exit`,
|
||||||
|
((err, out, errStr) => {
|
||||||
|
if(err){
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(out) {
|
||||||
|
console.log(out);
|
||||||
|
network.deployed_address = out.split("Deployed to: ")[1].split('\n')[0].trim();
|
||||||
|
config.networks[process.argv[3]] = network;
|
||||||
|
fs.writeFileSync('./xdapp.config.json', JSON.stringify(config, null, 4));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (process.argv[2] == "register_chain") {
|
||||||
|
|
||||||
|
} else if (process.argv[2] == "send_msg") {
|
||||||
|
|
||||||
|
} else if (process.argv[2] == "submit_vaa") {
|
||||||
|
|
||||||
|
} else if (process.argv[2] == "get_current_msg") {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.error("Unknown command!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "messenger",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"deploy evm": "node xdapp.js deploy evm"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"workspaces": [
|
||||||
|
"chains/evm"
|
||||||
|
],
|
||||||
|
"type": "module"
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"networks": {
|
||||||
|
"eth0": {
|
||||||
|
"type": "evm",
|
||||||
|
"rpc": "http://147.182.160.210:8545",
|
||||||
|
"privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d",
|
||||||
|
"deployed_address": "0x4cfb3f70bf6a80397c2e634e5bdd85bc0bb189ee"
|
||||||
|
},
|
||||||
|
"eth1": {
|
||||||
|
"type": "evm",
|
||||||
|
"rpc": "http://147.182.160.210:8546",
|
||||||
|
"privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,7 +26,10 @@
|
||||||
- [Linux]()
|
- [Linux]()
|
||||||
- [Project Scaffold]()
|
- [Project Scaffold]()
|
||||||
- [EVM]()
|
- [EVM]()
|
||||||
|
- [Foundry]()
|
||||||
- [Solana]()
|
- [Solana]()
|
||||||
|
- [Solana CLI]()
|
||||||
|
- [Anchor]()
|
||||||
- [Algorand]()
|
- [Algorand]()
|
||||||
- [Sending Messages]()
|
- [Sending Messages]()
|
||||||
- [EVM]()
|
- [EVM]()
|
||||||
|
@ -40,8 +43,10 @@
|
||||||
- [EVM]()
|
- [EVM]()
|
||||||
- [Solana]()
|
- [Solana]()
|
||||||
- [Algorand]()
|
- [Algorand]()
|
||||||
- [Projects]()
|
- [Projects](./projects/summary.md)
|
||||||
- [Messenger]()
|
- [Messenger](./projects/messenger/introduction.md)
|
||||||
|
- [Prerequistes]()
|
||||||
|
- [EVM]()
|
||||||
- [Lever Puzzle]()
|
- [Lever Puzzle]()
|
||||||
---
|
---
|
||||||
- [Wormhole Reference]()
|
- [Wormhole Reference]()
|
||||||
|
|
Loading…
Reference in New Issue