Skip to content

Commit

Permalink
Merge pull request #96 from renproject/feat/integration-ava
Browse files Browse the repository at this point in the history
Feat/integration ava
  • Loading branch information
roynalnaruto authored May 25, 2021
2 parents aaaad49 + 8adf326 commit 154f458
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 5 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -124,6 +129,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -243,6 +253,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -361,6 +376,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -479,6 +499,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -597,6 +622,11 @@ jobs:
with:
submodules: recursive

- name: Configure git for Private Modules
env:
TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: git config --global url."https://roynalnaruto:${TOKEN}@github.com".insteadOf "https://github.com"

- name: Caching modules
uses: actions/cache@v1
with:
Expand Down Expand Up @@ -722,6 +752,8 @@ jobs:
with:
push: true
tags: renbot/multichain:latest
build-args: |
GITHUB_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ RUN apt-get update && \
ENV GO111MODULE=on
ENV GOPROXY=https://proxy.golang.org

ARG GITHUB_TOKEN
RUN git config --global url."https://${GITHUB_TOKEN}:[email protected]/".insteadOf "https://github.com/"
ENV GOPRIVATE=github.com/renproject/ren-solana

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

Expand All @@ -39,6 +43,6 @@ RUN mkdir -p src/github.com/renproject
WORKDIR $GOPATH/src/github.com/renproject
RUN git clone https://github.com/renproject/solana-ffi
WORKDIR $GOPATH/src/github.com/renproject/solana-ffi
RUN git checkout df7838d724f5eaf262ed77ed93b35b3f1f652bd3
RUN git checkout f6521b8a1af44f4d468bc8e7e67ba3766a5602ef
RUN make clean && make
RUN go install ./...
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Adding a `Chain`:
// human-readable string to this set of enumerated values. Chains must be listed
// in alphabetical order.
const (
Acala = Chain("Acala")
Bitcoin = Chain("Bitcoin")
BitcoinCash = Chain("BitcoinCash")
Dogecoin = Chain("Dogecoin") // (This is our new chain!)
Expand Down
11 changes: 11 additions & 0 deletions infra/.env
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,14 @@ export TERRA_ADDRESS=terra10s4mg25tu6termrk8egltfyme4q7sg3hl8s38u
# access to plenty of testing funds.
export ZCASH_PK=cNSVbbsAcBQ6BAmMr6yH6DLWr7QTDptHwdzpy4GYxGDkNZeKnczK
export ZCASH_ADDRESS=tmCTReBSJEDMWfFCkXXPMSB3EfuPg6SE9dw

#
# Avalanche
#
export AVAX_USERNAME="Username"
export AVAX_PASSWORD="Few43!r389hfweu32"
export AVAX_PK="PrivateKey-ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN"
export AVAX_ADDRESS="X-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
export C_AVAX_PK="0xb8c1b5c1d81f9475fdf2e334517d29f733bdfa40682207571b12fc1142cbf329"
export C_AVAX_HEX_ADDRESS="0xa0df350d2637096571F7A701CBc1C5fdE30dF76A"
export C_AVAX_BECH32_ADDRESS="C-local18jma8ppw3nhx5r4ap8clazz0dps7rv5u00z96u"
26 changes: 26 additions & 0 deletions infra/avalanche/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:groovy

RUN apt update -y
RUN apt-get install -y wget curl build-essential

# INSTALL GO AND RUST
RUN wget -c https://golang.org/dl/go1.15.5.linux-amd64.tar.gz
RUN tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz
ENV PATH=$PATH:/usr/local/go/bin

# Fetch avalanchego
WORKDIR /app
RUN wget https://github.com/ava-labs/avalanchego/releases/download/v1.4.5/avalanchego-linux-amd64-v1.4.5.tar.gz
RUN tar -xzf avalanchego-linux-amd64-v1.4.5.tar.gz
RUN rm avalanchego-linux-amd64-v1.4.5.tar.gz
ENV PATH=$PATH:/app/avalanchego-v1.4.5

# COPY run script
COPY run.sh run.sh
RUN chmod +x run.sh

# RPC SERVER PORT
EXPOSE 9650

# RUN
ENTRYPOINT [ "./run.sh" ]
103 changes: 103 additions & 0 deletions infra/avalanche/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

AVAX_USERNAME=$1
AVAX_PASSWORD=$2
AVAX_PK=$3
AVAX_ADDRESS=$4
C_AVAX_PK=$5
C_AVAX_HEX_ADDRESS=$6
C_AVAX_BECH32_ADDRESS=$7

avalanchego \
--assertions-enabled=true \
--tx-fee=1000000 \
--public-ip=0.0.0.0 \
--network-id=local \
--signature-verification-enabled=true \
--api-admin-enabled=true \
--api-ipcs-enabled=true \
--api-keystore-enabled=true \
--api-metrics-enabled=true \
--http-host=0.0.0.0 \
--http-port=9650 \
--http-tls-enabled=false \
--plugin-dir=/app/avalanchego-v1.4.5/avalanchego-latest/plugins \
--log-level=info \
--snow-avalanche-batch-size=30 \
--snow-avalanche-num-parents=5 \
--snow-sample-size=1 \
--snow-quorum-size=1 \
--snow-virtuous-commit-threshold=1 \
--snow-rogue-commit-threshold=4 \
--staking-enabled=false \
--staking-port=9651 \
--api-auth-required=false &

# create a new user
sleep 10
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"keystore.createUser",
"params" :{
"username":"'"$AVAX_USERNAME"'",
"password":"'"$AVAX_PASSWORD"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/keystore

# import private key that contains AVAX into X-chain
sleep 1
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avm.importKey",
"params" :{
"username":"'"$AVAX_USERNAME"'",
"password":"'"$AVAX_PASSWORD"'",
"privateKey":"'"$AVAX_PK"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X

# import private key into C-chain
sleep 1
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.importKey",
"params" :{
"username" :"'"$AVAX_USERNAME"'",
"password":"'"$AVAX_PASSWORD"'",
"privateKey":"'"$AVAX_PK"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax

# export the AVAX to C-chain
sleep 1
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avm.exportAVAX",
"params" :{
"to":"'"$C_AVAX_BECH32_ADDRESS"'",
"destinationChain": "C",
"amount": 5000000000000,
"username":"'"$AVAX_USERNAME"'",
"password":"'"$AVAX_PASSWORD"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X

# import AVAX to the hex address
sleep 1
curl -X POST --data '{
"jsonrpc":"2.0",
"id" :1,
"method" :"avax.importAVAX",
"params" :{
"to":"'"$C_AVAX_HEX_ADDRESS"'",
"sourceChain":"X",
"username":"'"$AVAX_USERNAME"'",
"password":"'"$AVAX_PASSWORD"'"
}
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/C/avax

wait %1
18 changes: 18 additions & 0 deletions infra/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,21 @@ services:
- "0.0.0.0:9944:9944"
- "0.0.0.0:9933:9933"
command: --dev --ws-external --rpc-external

#
# Avalanche
#
avalanche:
build:
context: ./avalanche
ports:
- "0.0.0.0:9650:9650"
entrypoint:
- "./run.sh"
- "${AVAX_USERNAME}"
- "${AVAX_PASSWORD}"
- "${AVAX_PK}"
- "${AVAX_ADDRESS}"
- "${C_AVAX_PK}"
- "${C_AVAX_HEX_ADDRESS}"
- "${C_AVAX_BECH32_ADDRESS}"
11 changes: 8 additions & 3 deletions multichain.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type Asset string
// from an existing chain, you must add a human-readable string to this set of
// enumerated values. Assets must be listed in alphabetical order.
const (
AVAX = Asset("AVAX") // Avalanche
BCH = Asset("BCH") // Bitcoin Cash
BNB = Asset("BNB") // Binance Coin
BTC = Asset("BTC") // Bitcoin
Expand All @@ -125,6 +126,8 @@ const (
// the origin chain of BTC is Bitcoin.
func (asset Asset) OriginChain() Chain {
switch asset {
case AVAX:
return Avalanche
case BCH:
return BitcoinCash
case BNB:
Expand Down Expand Up @@ -172,7 +175,7 @@ func (asset Asset) ChainType() ChainType {
switch asset {
case BCH, BTC, DGB, DOGE, ZEC:
return ChainTypeUTXOBased
case BNB, ETH, FIL, GLMR, LUNA, MATIC:
case AVAX, BNB, ETH, FIL, GLMR, LUNA, MATIC:
return ChainTypeAccountBased

// These assets are handled separately because they are mock assets. These
Expand Down Expand Up @@ -211,7 +214,7 @@ type Chain string
// human-readable string to this set of enumerated values. Chains must be listed
// in alphabetical order.
const (
Acala = Chain("Acala")
Avalanche = Chain("Avalanche")
BinanceSmartChain = Chain("BinanceSmartChain")
Bitcoin = Chain("Bitcoin")
BitcoinCash = Chain("BitcoinCash")
Expand Down Expand Up @@ -258,7 +261,7 @@ func (chain Chain) ChainType() ChainType {
switch chain {
case Bitcoin, BitcoinCash, DigiByte, Dogecoin, Zcash:
return ChainTypeUTXOBased
case BinanceSmartChain, Ethereum, Fantom, Filecoin, Moonbeam, Polygon, Solana, Terra:
case Avalanche, BinanceSmartChain, Ethereum, Fantom, Filecoin, Moonbeam, Polygon, Solana, Terra:
return ChainTypeAccountBased

// These chains are handled separately because they are mock chains. These
Expand Down Expand Up @@ -290,6 +293,8 @@ func (chain Chain) IsUTXOBased() bool {
// root asset of Bitcoin chain is BTC.
func (chain Chain) NativeAsset() Asset {
switch chain {
case Avalanche:
return AVAX
case BinanceSmartChain:
return BNB
case BitcoinCash:
Expand Down
4 changes: 4 additions & 0 deletions multichain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ var _ = Describe("Multichain", func() {
chain multichain.Chain
asset multichain.Asset
}{
{
multichain.Avalanche,
multichain.AVAX,
},
{
multichain.Fantom,
multichain.FTM,
Expand Down

0 comments on commit 154f458

Please sign in to comment.