diff --git a/projects/evm-tokenbridge/package.json b/projects/evm-tokenbridge/package.json index 7c3245b..ab5eb7a 100644 --- a/projects/evm-tokenbridge/package.json +++ b/projects/evm-tokenbridge/package.json @@ -1,7 +1,7 @@ { - "name": "xdapp-starter", + "name": "evm-tokenbridge-example", "version": "1.0.0", - "description": "A simple template for getting started with xDapps.", + "description": "A simple template for transferring tokens using EVM.", "main": "starter.js", "scripts": { "guardiand": "sh wormhole.sh", diff --git a/projects/xdapp-starter/README.md b/projects/xdapp-starter/README.md new file mode 100644 index 0000000..9f92c5b --- /dev/null +++ b/projects/xdapp-starter/README.md @@ -0,0 +1,12 @@ +# xDapp Starter +Simple starter template with Guardiand script and two EVM chains. + +## Dependencies +The javascript dependencies can be installed via `npm install` in this folder. + +You will also need Docker; you can get either [Docker Desktop](https://docs.docker.com/get-docker/) if you're developing on your computer or if you're in a headless vm, install [Docker Engine](https://docs.docker.com/engine/) + +## Run Guardiand +After you have the dependencies installed, we'll need to spin up the EVM chains, deploy the Wormhole contracts to them, then startup a Wormhole Guardian to observe and sign VAAs. We have provided a script to automate this all for you. + +Simply run `npm run guardiand` and wait while the Wormhole Guardian builds a docker image. The first time you run this command, it might take a while (up to 550 seconds on a modern laptop!). After the image is built however, it'll be relatively fast to bring it up and down. diff --git a/projects/xdapp-starter/package.json b/projects/xdapp-starter/package.json new file mode 100644 index 0000000..7c3245b --- /dev/null +++ b/projects/xdapp-starter/package.json @@ -0,0 +1,24 @@ +{ + "name": "xdapp-starter", + "version": "1.0.0", + "description": "A simple template for getting started with xDapps.", + "main": "starter.js", + "scripts": { + "guardiand": "sh wormhole.sh", + "cleanup": "docker kill guardiand && docker rm guardiand && npx pm2 kill", + "test": "sh tests/treasury_bridge.sh" + }, + "keywords": [], + "author": "", + "license": "MIT", + "workspaces": [], + "type": "module", + "dependencies": { + "@certusone/wormhole-sdk": "^0.3.3", + "byteify": "^2.0.10", + "ethers": "^5.6.9", + "ganache": "^7.3.1", + "node-fetch": "^3.2.6", + "pm2": "^5.2.0" + } +} diff --git a/projects/xdapp-starter/wormhole.sh b/projects/xdapp-starter/wormhole.sh new file mode 100644 index 0000000..e877dfa --- /dev/null +++ b/projects/xdapp-starter/wormhole.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +npm run cleanup +if [! docker info > /dev/null ] ; then + echo "This script uses docker, and it isn't running - please start docker and try again!" + exit 1 +fi + +# Check if wormhole/ repo exists. +# If it doens't then clone and build guardiand +if [ ! -d "./wormhole" ] +then + git clone https://github.com/certusone/wormhole + cd wormhole/ + DOCKER_BUILDKIT=1 docker build --target go-export -f Dockerfile.proto -o type=local,dest=node . + DOCKER_BUILDKIT=1 docker build --target node-export -f Dockerfile.proto -o type=local,dest=. . + cd node/ + echo "Have patience, this step takes upwards of 500 seconds!" + if [ $(uname -m) = "arm64" ]; then + echo "Building Guardian for linux/amd64" + DOCKER_BUILDKIT=1 docker build --platform linux/amd64 -f Dockerfile -t guardian . + else + echo "Building Guardian natively" + DOCKER_BUILDKIT=1 docker build -f Dockerfile -t guardian . + fi + cd ../../ +fi + +# Start EVM Chain 0 +npx pm2 start 'ganache -p 8545 -m "myth like bonus scare over problem client lizard pioneer submit female collect" --block-time 1' --name evm0 +# Start EVM Chain 1 +npx pm2 start 'ganache -p 8546 -m "myth like bonus scare over problem client lizard pioneer submit female collect" --block-time 1' --name evm1 +#Install Wormhole Eth Dependencies +cd wormhole/ethereum +npm i +cp .env.test .env + +npm run build + +# Deploy Wormhole Contracts to EVM Chain 0 +npm run migrate && npx truffle exec scripts/deploy_test_token.js && npx truffle exec scripts/register_solana_chain.js && npx truffle exec scripts/register_terra_chain.js && npx truffle exec scripts/register_bsc_chain.js && npx truffle exec scripts/register_algo_chain.js +# Deploy Wormhole Contracts to EVM Chain 1 +perl -pi -e 's/CHAIN_ID=0x2/CHAIN_ID=0x4/g' .env && perl -pi -e 's/8545/8546/g' truffle-config.js +npm run migrate && npx truffle exec scripts/deploy_test_token.js && npx truffle exec scripts/register_solana_chain.js && npx truffle exec scripts/register_terra_chain.js && npx truffle exec scripts/register_eth_chain.js && npx truffle exec scripts/register_algo_chain.js && nc -lkp 2000 0.0.0.0 +perl -pi -e 's/CHAIN_ID=0x4/CHAIN_ID=0x2/g' .env && perl -pi -e 's/8546/8545/g' truffle-config.js +cd ../../ + +# Run Guardiand +if [ $(uname -m) = "arm64" ]; then + docker run -d --name guardiand -p 7070:7070 -p 7071:7071 -p 7073:7073 --platform linux/amd64 --hostname guardian-0 --cap-add=IPC_LOCK --entrypoint /guardiand guardian node \ + --unsafeDevMode --guardianKey /tmp/bridge.key --publicRPC "[::]:7070" --publicWeb "[::]:7071" --adminSocket /tmp/admin.sock --dataDir /tmp/data \ + --ethRPC ws://host.docker.internal:8545 \ + --ethContract "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550" \ + --bscRPC ws://host.docker.internal:8546 \ + --bscContract "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550" \ + --polygonRPC ws://host.docker.internal:8545 \ + --avalancheRPC ws://host.docker.internal:8545 \ + --auroraRPC ws://host.docker.internal:8545 \ + --fantomRPC ws://host.docker.internal:8545 \ + --oasisRPC ws://host.docker.internal:8545 \ + --karuraRPC ws://host.docker.internal:8545 \ + --acalaRPC ws://host.docker.internal:8545 \ + --klaytnRPC ws://host.docker.internal:8545 \ + --celoRPC ws://host.docker.internal:8545 \ + --moonbeamRPC ws://host.docker.internal:8545 \ + --neonRPC ws://host.docker.internal:8545 \ + --terraWS ws://host.docker.internal:8545 \ + --terra2WS ws://host.docker.internal:8545 \ + --terraLCD https://host.docker.internal:1317 \ + --terra2LCD http://host.docker.internal:1317 \ + --terraContract terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 \ + --terra2Contract terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 \ + --solanaContract Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o \ + --solanaWS ws://host.docker.internal:8900 \ + --solanaRPC http://host.docker.internal:8899 \ + --algorandIndexerRPC ws://host.docker.internal:8545 \ + --algorandIndexerToken "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + --algorandAlgodToken "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + --algorandAlgodRPC https://host.docker.internal:4001 \ + --algorandAppID "4" +else + docker run -d --name guardiand --network host --hostname guardian-0 --cap-add=IPC_LOCK --entrypoint /guardiand guardian node \ + --unsafeDevMode --guardianKey /tmp/bridge.key --publicRPC "[::]:7070" --publicWeb "[::]:7071" --adminSocket /tmp/admin.sock --dataDir /tmp/data \ + --ethRPC ws://localhost:8545 \ + --ethContract "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550" \ + --bscRPC ws://localhost:8546 \ + --bscContract "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550" \ + --polygonRPC ws://localhost:8545 \ + --avalancheRPC ws://localhost:8545 \ + --auroraRPC ws://localhost:8545 \ + --fantomRPC ws://localhost:8545 \ + --oasisRPC ws://localhost:8545 \ + --karuraRPC ws://localhost:8545 \ + --acalaRPC ws://localhost:8545 \ + --klaytnRPC ws://localhost:8545 \ + --celoRPC ws://localhost:8545 \ + --moonbeamRPC ws://localhost:8545 \ + --neonRPC ws://localhost:8545 \ + --terraWS ws://localhost:8545 \ + --terra2WS ws://localhost:8545 \ + --terraLCD https://terra-terrad:1317 \ + --terra2LCD http://localhost:1317 \ + --terraContract terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 \ + --terra2Contract terra18vd8fpwxzck93qlwghaj6arh4p7c5n896xzem5 \ + --solanaContract Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o \ + --solanaWS ws://localhost:8900 \ + --solanaRPC http://localhost:8899 \ + --algorandIndexerRPC ws://localhost:8545 \ + --algorandIndexerToken "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + --algorandAlgodToken "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + --algorandAlgodRPC https://localhost:4001 \ + --algorandAppID "4" +fi +echo "Guardiand Running! To look at logs: \"docker logs guardiand -f\"" \ No newline at end of file diff --git a/projects/xdapp-starter/xdapp.config.json b/projects/xdapp-starter/xdapp.config.json new file mode 100644 index 0000000..11992c2 --- /dev/null +++ b/projects/xdapp-starter/xdapp.config.json @@ -0,0 +1,25 @@ +{ + "networks": { + "evm0": { + "type": "evm", + "wormholeChainId": 2, + "rpc": "http://localhost:8545", + "privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", + "bridgeAddress": "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550", + "tokenBridgeAddress": "0x0290FB167208Af455bB137780163b7B7a9a10C16", + "testToken": "0x2D8BE6BF0baA74e0A907016679CaE9190e80dD0A" + }, + "evm1": { + "type": "evm", + "wormholeChainId": 4, + "rpc": "http://localhost:8546", + "privateKey": "0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d", + "tokenBridgeAddress": "0x0290FB167208Af455bB137780163b7B7a9a10C16", + "bridgeAddress": "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550", + "testToken": "0x2D8BE6BF0baA74e0A907016679CaE9190e80dD0A" + } + }, + "wormhole": { + "restAddress": "http://localhost:7071" + } +} \ No newline at end of file diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 41b7b39..4da7346 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -64,56 +64,35 @@ - [Linux](./development/tilt/linux.md) - [Constants](./development/tilt/constants.md) - [Project Scaffold](./development/scaffold/overview.md) - - [EVM]() - - [Foundry]() - - [Solana]() - - [Solana CLI]() - - [Anchor]() - - [Algorand]() - - [CosmWasm]() - [Sending Messages](./development/messages/sending/overview.md) - [EVM](./development/messages/sending/evm.md) - - [Solana]() - - [Algorand]() - - [CosmWasm]() + - [Registering xDapps](./development/messages/registration/overview.md) - [EVM](./development/messages/registration/evm.md) - - [Solana]() - - [Algorand]() - - [CosmWasm]() - [Relaying Messages](./development/messages/relaying/overview.md) - [Manual Relays]() - [REST & Spy Relayer]() - [Generic Relayers]() - [Receving Messages](./development/messages/receiving/overview.md) - [EVM](./development/messages/receiving/evm.md) - - [Solana]() - - [Algorand]() - - [CosmWasm]() - [Projects](./projects/summary.md) - - [Messenger](./projects/messenger/introduction.md) - - [Prerequistes]() - - [EVM]() - - [Lever Puzzle]() --- # Portal Token Bridge -- [Portal]() +- [Portal](./development/portal/overview.md) + - [EVM]() + - [Attesting](./development/portal/evm/attestingToken.md) + - [Transfer Tokens](./development//portal/evm/tokenTransfer.md) - [Portal JS Client Transfers]() - - [Payload 1 Transfers]() - - [Payload 2 Attestations]() - - [Payload 3 Contract Controlled Transfers]() - - [Examples]() - [EVM to Solana Transfer]() - [Polygon to Oasis with Relayers]() - - [Portal Payloads]() +- [Portal Payloads]() --- # Other Resources -- [Glossary]() - [Reference]() - [Tools](./reference/tools.md) - [Github & Useful Links](./reference/github.md) diff --git a/src/development/scaffold/overview.md b/src/development/scaffold/overview.md index 00fceeb..6fd7a0b 100644 --- a/src/development/scaffold/overview.md +++ b/src/development/scaffold/overview.md @@ -19,3 +19,6 @@ This file parses command line args and filters calls to chain management handler ### xdapp.config.json The config file contains all the information about the network rpc nodes, accounts, and other constants used to communicate with contracts deployed to the selected chains. + +### wormhole.sh +This is a script that spins up chains using PM2 and guardiand via docker. It'll clone the wormhole repo. It is NOT necessary to do this for every project, if you're creating multiple xdapps, maybe have one folder that you run guardiand from so you're not rebuilding it every time you start a new project. \ No newline at end of file