-
Notifications
You must be signed in to change notification settings - Fork 858
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve scripts and update config and contracts to match new flow
- Loading branch information
Showing
10 changed files
with
336 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
PRIVATE_KEY_1 = '0x123...' | ||
PRIVATE_KEY_2 = '0x456...' | ||
PRIVATE_KEY_3 = '0x789...' | ||
# Make sure to rename this file to .env before adding your private keys!!! | ||
PRIVATE_KEY_1 = '' | ||
PRIVATE_KEY_2 = '' | ||
PRIVATE_KEY_3 = '' | ||
|
||
OP_DISPATCHER = '0xabcd...' | ||
BASE_DISPATCHER = '0xefgh...' | ||
# Contract addresses last updated on 2024-02-13, for Polymer Production Testnet | ||
OP_DISPATCHER = '0x9B056D1a889D98824A2917DaF70cC6890719E9FD' | ||
BASE_DISPATCHER = '0x52646d58B5ce673066764D47cb0C481fdd93ddb2' | ||
|
||
OP_UC_MW = '0xijkl...' | ||
BASE_UC_MW = '0mnop...' | ||
OP_UC_MW = '0x742D894d832cD4d1a454A248Ae638F37952c369C' | ||
BASE_UC_MW = '0xEd56F12D5270317cD517b800135B0427a8Ac9C4b' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,73 @@ | ||
# Sample Hardhat Project | ||
# Template for IBC enabled Soldity contracts | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
This tutorial enables to send an IBC packet from an "Xcounter" contract on either OP or Base. The packet will ensure that a counter variable on either contract remains in sync. | ||
|
||
Try running some of the following tasks: | ||
## Install dependencies | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.js | ||
To use the quickstart tutorial, make sure that you have all dependencies installed. | ||
|
||
From the root directory run: | ||
```bash | ||
forge install | ||
``` | ||
to install the [vIBC core smart contracts](https://github.com/open-ibc/vibc-core-smart-contracts) as a dependency. | ||
|
||
Again from root, run: | ||
```bash | ||
npm install | ||
``` | ||
to install some node modules as dependencies, specifically when you want to use Hardhat. | ||
|
||
## Set up your environment variables | ||
|
||
In the `.env` file (you'll find it as `.env.example`), add your private key(s) and rename to drop the "example" in the filename. The dispatcher addresses should be correct but you could use custom ones if required. | ||
|
||
Next, check the `config.json` file. This is where a lot of the parameters you need to deploy, create channels and send packets are stored. | ||
|
||
When using the default scripts, those fields will be mostly auto-populated. Only the contract types in the `deploy` field must be updated when you write your own contracts. | ||
|
||
## Run the scripts | ||
|
||
There's three types of scripts in the project: | ||
|
||
- `deploy.js` and `deploy-config.js` allow you to deploy your application contract | ||
- `create-channel.js` and `create-channel-config.js` creates a channel | ||
- `send-packet.js` sends packets over an existing channel | ||
|
||
For every script you'll find a field in the config.json!! | ||
|
||
Make sure to update the config with the intended files before running one of the scripts like so: | ||
```bash | ||
npx hardhat run scripts/send-packet.js --network optimism | ||
``` | ||
|
||
**NOTE** Make sure to align the `--network` flag value to be compatible with your config values either on optimism or base. | ||
|
||
## Deploy | ||
|
||
Run: | ||
```bash | ||
# format node scripts/deploy-config.js [source] [destination] | ||
node scripts/deploy-config.js optimism base | ||
``` | ||
|
||
To deploy instances of the contracts on optimism as the source and base as the destination chains. (You can also switch the order) | ||
|
||
Also this script will take the output of the deployment and update the config file with all the relevant information. | ||
|
||
Then run: | ||
```bash | ||
node scripts/create-channel-config.js | ||
``` | ||
|
||
To create a channel between base and optimism. Note that the **ORDER MATTERS**; if you picked optimism as the source chain (first argument) above, by default it will create the channel from optimism and vice versa. | ||
|
||
Also this script will take the output of the channel creation and update the config file with all the relevant information. | ||
|
||
Check out the [channel tab in the explorer](https://explorer.prod.testnet.polymer.zone/channels) to find out if the correct channel-id's related to your contracts were updated in the config. | ||
|
||
Finally run: | ||
```bash | ||
npx hardhat run scripts/send-packet.js --network optimism | ||
``` | ||
to send a packet. You can pick either optimism or base to send the packet from. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,39 @@ | ||
{ | ||
"deploy": { | ||
"optimism": "CustomChanIbcContract", | ||
"base": "CustomChanIbcContract" | ||
}, | ||
"createChannel": { | ||
"srcContractType": "IbcApp", | ||
"srcChain": "base", | ||
"srcAddr": "0x123...", | ||
"dstChain": "optimism", | ||
"dstAddr": "0xabc...", | ||
"version": "1.0", | ||
"ordering": 1, | ||
"fees": false | ||
"srcChain": "optimism", | ||
"srcAddr": "0x123", | ||
"dstChain": "base", | ||
"dstAddr": "0x456", | ||
"version": "1.0", | ||
"ordering": 1, | ||
"fees": false | ||
}, | ||
"sendPacket": { | ||
"srcAddr": "0x123...", | ||
"srcChannelId": "channel-0", | ||
"optimism": { | ||
"portAddr": "0x123", | ||
"channelId": "channel-n", | ||
"timeout": 36000 | ||
}, | ||
"base": { | ||
"portAddr": "0x456", | ||
"channelId": "channel-n", | ||
"timeout": 36000 | ||
} | ||
}, | ||
"sendUniversalPacket": { | ||
"srcAddr": "0x456...", | ||
"dstAddr": "0xdef...", | ||
"srcChannelId": "channel-1", | ||
"optimism": { | ||
"portAddr": "0xabc", | ||
"channelId": "channel-x", | ||
"timeout": 36000 | ||
}, | ||
"base": { | ||
"portAddr": "0xdef", | ||
"channelId": "channel-y", | ||
"timeout": 36000 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { exec } = require("child_process"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const config = require("../config.json"); | ||
|
||
// Function to update config.json | ||
function updateConfig(network, channel, cpNetwork, cpChannel) { | ||
const configPath = path.join(__dirname, '..', 'config.json'); | ||
const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); | ||
|
||
// Update the config object | ||
config["sendPacket"][`${network}`]["channelId"] = channel; | ||
config["sendPacket"][`${cpNetwork}`]["channelId"] = cpChannel; | ||
|
||
// Write the updated config back to the file | ||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); | ||
} | ||
|
||
// Function to run the deploy script and capture output | ||
function createChannelAndCapture() { | ||
exec(`npx hardhat run scripts/create-channel.js --network ${config.createChannel.srcChain}`, (error, stdout, stderr) => { | ||
if (error) { | ||
console.error(`exec error: ${error}`); | ||
return; | ||
} | ||
|
||
// Process stdout to find the contract address and network | ||
const output = stdout.trim(); | ||
const match = output.match(/Channel created: (\S+) with portID (\S+) on network (\S+), Counterparty: (\S+) on network (\S+)/); | ||
|
||
if (match) { | ||
const channel = match[1]; | ||
const portId = match[2]; | ||
const network = match[3]; | ||
const cpChannel = match[4]; | ||
const cpNetwork = match[5]; | ||
|
||
console.log(`Created channel: ${channel} with portID ${portId} on network ${network}, Counterparty: ${cpChannel} on network ${cpNetwork}`); | ||
|
||
// Update the config.json file | ||
updateConfig(network, channel, cpNetwork, cpChannel); | ||
console.log(`Updated config.json with ${channel} on network ${network} and ${cpChannel} on network ${cpNetwork}`); | ||
} else { | ||
console.error("Could not find required parameters in output"); | ||
} | ||
}); | ||
} | ||
|
||
createChannelAndCapture(); |
Oops, something went wrong.