Inspiration

Our main goal is to build cross-chain lending. So first we have to build a protocol or a bridge between chains to be able to exchange crypto. GoldenStar swap is a demo for this main product, the first two chains we aim to be Ethereum and local chain that built with Peggy.We want to make Peggy a bridge between existing chains

What it does

GoldenStar swap allows you to convert between Erc-20s, ETH on Ethereum to assets in our local chain (that built with Peggy). Currently, GoldenStarSwap can only convert erc20, ETH from Ethereum to local chain and vice versa, however, it will open a door to turn this local chain into an intermediate bridge to be able to swap tokens. between different blockchains.

Architecture

How I built it

  • Smart Contracts on Ethereum

The set of smart contracts on Ethereum is called by a user to lock ETH and ERC20 Tokens into it

  • Relayer

After the set of smart contracts on Ethereum successfully locks ETH / ERC20 it issues an event. Relayer captures the event and processes it to get the transaction information in that event and and call to Cosmos chain.

  • Cosmos chain

Cosmos chain mint a corresponding amount of tokens for the cosmos receiver.

Setup project

1. Make tool

In the project root directory

make

Then create the following folders in cmd/ebrelayer/contract/generated/bindings/:

  • BridgeBank
  • BridgeRegistry
  • CosmosBridge
  • Oracle
  • Valset

2. Setup cosmos chain

# Initialize the genesis.json file that will help you to bootstrap the network
ebd init local --chain-id=peggy

# Configure your cli to use the keyring-backend test so that you don't need to enter a password
# **_NOTE_** Don't use the test backend on production
ebcli config keyring-backend test

# Add some more configuration to avoid using flags
ebcli config chain-id peggy
ebcli config trust-node true
ebcli config indent true
ebcli config output json

# Create a key to hold your validator account and for another test account
ebcli keys add validator --output json > validator.json
ebcli keys add testuser --output json > testuser.json

# Initialize the genesis account and transaction
ebd add-genesis-account $(ebcli keys show validator -a) 1000000000stake,1000000000atom

# Create genesis transaction
ebd gentx --name validator --keyring-backend test

# Collect genesis transaction
ebd collect-gentxs

# Now its safe to start `ebd`
ebd start

Open new terminal

3. Deploy smart contract to ropsten

In the project root directory

ebcli tx send validator \$(ebcli keys show testuser -a) 10stake --yes
yarn peggy:all

Check Contracts Address

cd testnet-contracts
npx truffle network

Format Result

Network: ropsten (id: 3)
BridgeBank: 0x32f82eeB46ed9c2AA0114e4B961cfcEBF18384Df
BridgeRegistry: 0x14d268ed94340f757b253CdeBd3b3528B83aBdb1
BridgeToken: 0x032A87fa8BA6031A4358213648B5eD5E72813A33
CosmosBridge: 0x86C41cb7CbCC55919dFf52Ac9b8ac84D4ddBE2DA
Migrations: 0x00c3b1ba15c5dD86Cf9253CA6b05e4617eeD3d3E
Oracle: 0xad0023F9ebEF7741F399136F9Ca9276F3028b52B
Valset: 0x1b8E9eBE7685D3d5a6f7Ce012f2e9738cD1E9Ef7

4. Run relayer

ebrelayer generate
ebrelayer init tcp://localhost:26657 wss://ropsten.infura.io/ws/v3/[Infura-Project-ID] [BridgeRegistry-ContractAddress] validator --chain-id=peggy

Open new terminal

5. Transfer money

5.1 Tranfer ETH/ERC20 from Ethereum to Cosmos

Run bellow command to get testuser Address

ebcli query account \$(ebcli keys show testuser -a)

Format result

{
  "type": "cosmos-sdk/Account",
  "value": {
    "address": "cosmos1pgkwvwezfy3qkh99hjnf35ek3znzs79mwqf48y",
    "coins": [
      {
        "denom": "stake",
        "amount": "10"
      }
    ],
    "public_key": "cosmospub1addwnpepqwpznlktnvxvyxccslnp58janc6zk83huww6aynzq77ur2dvsfskct0atl9",
    "account_number": 3,
    "sequence": 7
  }
}

Transfer ETH

yarn peggy:lock cosmos1pgkwvwezfy3qkh99hjnf35ek3znzs79mwqf48y 1000 eth --network ropsten

Transfer ERC20

yarn token:lockERC20 cosmos1pgkwvwezfy3qkh99hjnf35ek3znzs79mwqf48y 1000 dai --network ropsten

Query Account

ebcli query account \$(ebcli keys show testuser -a)
{
  "type": "cosmos-sdk/Account",
  "value": {
    "address": "cosmos1pgkwvwezfy3qkh99hjnf35ek3znzs79mwqf48y",
    "coins": [
      {
        "denom": "stake",
        "amount": "10"
      },
      {
        "denom": "eth",
        "amount": "1000"
      },
      {
        "denom": "eth",
        "amount": "1000"
      }
    ],
    "public_key": "cosmospub1addwnpepqwpznlktnvxvyxccslnp58janc6zk83huww6aynzq77ur2dvsfskct0atl9",
    "account_number": 3,
    "sequence": 9
  }
}

6. Rest server

ebcli rest-server --unsafe-cors

7. Run Client

cd ui
yarn start

Challenges I ran into

The Coin data structure in Peggy is not really stable yet so we cannot go beyond the int64 data type, so we cannot transfer more than 10e18 wei per token conversion between Ethereum and Peggychain.Besides, the peggy code currently has a lot of bugs, so we had to fix a lot of small errors in the setup.

Accomplishments that I'm proud of

All the team members tried their best to come up with a product that could compete in a short time. Although the project is just a small use case in the product that we are researching and building, we have worked together to build a complete demo.

What I learned

After completing this project, the entire team has clearly improved their skills in writing smart contracts, know more about how cosmos works through its Peggy-based construction.

What's next for GoldenStarSwap

As mentioned above the goldenstar swap is a demo of the product we are looking to build: Lending cross-chain. We have built a bridge between Harmony and Ethereum (you can check it out: https://youtu.be/rJkLLacbc_Q and live project: https://goldenstarswap.web.app/), in fact, from which we can develop a bridge between other blockchain platforms by taking etherum as a center, but then there will be a lot of building. bridges between ethereum and other blockchains. Therefore we want to turn peggy into a single intermediary bridge between different blockchain platforms.

  • Cosmos hub (with native token Atom) Build up an interface for the user to provide liquidity to receive farming tokens.
  • Connect peggy to blockchain platforms that are structurally similar to ethereum such as Tomochain, Harmony

Built With

+ 69 more
Share this project:

Updates