Skip to content

Commit

Permalink
Merge branch 'main' into feat/use_gmp_executable
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy authored Oct 16, 2024
2 parents 8bccb1f + 402c6c6 commit da28bd2
Show file tree
Hide file tree
Showing 30 changed files with 912 additions and 567 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
EVM_PRIVATE_KEY=YOUR_PRIVATE_KEY_HERE

# For amplifier examples
GMP_API_URL=
ENVIRONMENT= # e.g. devnet-amplifier, testnet, or mainnet
CRT_PATH= # e.g. './client.crt'
KEY_PATH= # e.g. './client.key'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ chain-config/*.json
!./**/artifacts/send_receive.wasm

.multiversx

*.crt
*.key
322 changes: 114 additions & 208 deletions examples/amplifier/README.md

Large diffs are not rendered by default.

68 changes: 0 additions & 68 deletions examples/amplifier/amplifier.js

This file was deleted.

117 changes: 0 additions & 117 deletions examples/amplifier/amplifier.proto

This file was deleted.

22 changes: 0 additions & 22 deletions examples/amplifier/config.js

This file was deleted.

14 changes: 14 additions & 0 deletions examples/amplifier/config/chains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"devnet-amplifier": [
{
"name": "avalanche-fuji",
"rpc": "https://rpc.ankr.com/avalanche_fuji",
"gateway": "0xF128c84c3326727c3e155168daAa4C0156B87AD1"
},
{
"name": "xrpl-evm-sidechain",
"rpc": "https://rpc-evm-sidechain.xrpl.org",
"gateway": "0x48CF6E93C4C1b014F719Db2aeF049AA86A255fE2"
}
]
}
58 changes: 58 additions & 0 deletions examples/amplifier/config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require('fs');
const https = require('https');
const dotenv = require('dotenv');

// Load environment variables from .env file
dotenv.config();

// Load the certificate and key
const cert = fs.readFileSync(process.env.CRT_PATH);
const key = fs.readFileSync(process.env.KEY_PATH);

// Default configuration values
const defaults = {
// gRPC
HOST: 'localhost',
PORT: '50051',

// GMP API
GMP_API_URL: 'http://localhost:8080',
};

const chainsConfigFile = JSON.parse(fs.readFileSync('./examples/amplifier/config/chains.json', 'utf8'));
const environment = process.env.ENVIRONMENT;
const chainsConfig = chainsConfigFile[environment];

function getConfig() {
const serverHOST = process.env.HOST || defaults.HOST;
const serverPort = process.env.PORT || defaults.PORT;

const gmpAPIURL = process.env.GMP_API_URL || defaults.GMP_API_URL;

return {
serverHOST,
serverPort,
gmpAPIURL,
chains: chainsConfig,
httpsAgent: new https.Agent({
cert,
key,
rejectUnauthorized: false,
}),
};
}

function getChainConfig(chainName) {
const chainConfig = chainsConfig.find((c) => c.name === chainName);

if (!chainConfig) {
throw new Error(`RPC URL not found for chain: ${chainName}`);
}

return chainConfig;
}

module.exports = {
getConfig,
getChainConfig,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"01924dc4-698e-7ad2-9f9b-0bad962771ef"
42 changes: 42 additions & 0 deletions examples/amplifier/contracts/AmplifierGMPTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol';
import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol';

/**
* @title AmplifierGMPTest
* @notice Send a message from chain A to chain B and stores gmp message
*/
contract AmplifierGMPTest is AxelarExecutable {
string public message;
string public sourceChain;
string public sourceAddress;

constructor(address _gateway) AxelarExecutable(_gateway) {}

/**
* @notice Send message from chain A to chain B
* @dev message param is passed in as gmp message
* @param destinationChain name of the dest chain (ex. "Fantom")
* @param destinationAddress address on dest chain this tx is going to
* @param _message message to be sent
*/
function setRemoteValue(string calldata destinationChain, string calldata destinationAddress, string calldata _message) external {
bytes memory payload = abi.encode(_message);
gateway.callContract(destinationChain, destinationAddress, payload);
}

/**
* @notice logic to be executed on dest chain
* @dev this is triggered automatically by relayer
* @param _sourceChain blockchain where tx is originating from
* @param _sourceAddress address on src chain where tx is originating from
* @param _payload encoded gmp message sent from src chain
*/
function _execute(string calldata _sourceChain, string calldata _sourceAddress, bytes calldata _payload) internal override {
(message) = abi.decode(_payload, (string));
sourceChain = _sourceChain;
sourceAddress = _sourceAddress;
}
}
Loading

0 comments on commit da28bd2

Please sign in to comment.