We develop a general cross-chain communication framework that uses the Kafka protocol for secure interaction.
- The Kafka network provider, who maintains the Kafka network.
- Developers, who develops cross-chain services (CC-SVCs) using an event- driven approach.
- End users, who deploy smart contracts and use the CC-SVCs for cross- chain operations.
Start Kafka with docker-compose
.
cd kafka
docker-compose up -d
# to stop after experiments
docker-compose down
Install Hyperledger Fabric.
cd fabric
./install.sh
Install go-ethereum and quorum.
cd ethereum
sudo ./install.sh
Register event handlers for different services.
ccsvc, err = cclib.NewEventService(
[]string{"zoolkeeper_nodes"},
"service_name",
)
check(err)
// register event handlers
ccsvc.Register("event_1", handleEvent1)
ccsvc.Register("event_2", handleEvent2)
err = ccsvc.Start() // start service
check(err)
Publish events with corresponding payloads
b, _ := json.Marshal(Event1Body{
Hash: hash,
// ...
})
ccsvc.Publish("event_1", b)
You can run the cross-chain flash loan demo by the following steps.
- Run Fabric.
cd fabric-samples/test-network
./network.sh up createChannel
# to stop fabric after experiment
./network.sh down
- Run ethereum.
cd ethereum/poa
./remove.sh
./init.sh
./start.sh
# to stop ethereum after experiment
./stop.sh
NOTE: Check log.txt
file to ensure that ethereum is running.
- Deploy contracts
fabric_erc20
andlender
on fabric.
cd fabric-samples/test-network
./network.sh deployCC -ccn token1 -ccp ../../contracts/fabric_erc20/chaincode/ -ccl go
./network.sh deployCC -ccn lender -ccp ../../contracts/fabric_lender/chaincode/ -ccl go
- Run
cclender
andccarbit
in two different terminals. They are the cross-chain exchange services responsible for relaying messages between two blockchains.
cd examples/flashloan/cclender
go build .
./cclender
cd examples/flashloan/ccarbit
go build .
./ccarbit
- Setup
tokens
andamm
exchanges usingcli
cd examples/flashloan/cli
go build .
# Deploy tokens and amm contracts and allocate initial coins.
./cli -c setup
- Setup flashloan contract
arbitrage
onethereum
.
cd examples/flashloan/arbitrageur
go build .
# Deploy arbitrage contract on ethereum.
# Setup both lender and arbitrage contract and generate a signature.
./arbitrageur -c setup
You can check the results in flash_loan.json
and commit_vote.json
in the flashloan
folder.
- Register the new flashloan to the cc services.
# from arbitrageur directory
./arbitrageur -c register
- Sign Commit Vote by
lender
.
cd examples/flashloan/lender
go build .
./lender -c sign
- Initialize flash-loan with commit vote by
lender
.
# from lender directory
./lender -c initialize
After this step, cross-chain services will detect lender initialization on fabric
and transfer loan to arbitrage
contract on ethereum
.
- Execute
arbitrage
byarbitrageur
.
./arbitrageur -c execute
If execute
is successful, the arbitrage
contract will transfer loan + intrest
to the cross-chain exchange and the cross-chain services will transfer loan + intrest
to the lender.
if execute
is failed, the lender
will still get refund of initial loan
on fabric.
You can check the token balances on both blockchains using this command.
# from cli directory
./cli -c display
You can run the auction example by the following steps.
- Run Fabric.
cd fabric-samples/test-network
./network.sh up createChannel
- Run Ethereum POA.
cd ethereum/poa
./remove.sh
./init.sh
./start.sh
- Run Quorum Raft.
cd ethereum/raft
./remove.sh
./init.sh
./start.sh
- Deploy
fabric_asset
onfabric
.
./network.sh deployCC -ccn asset -ccp ../../contracts/fabric_asset/chaincode -ccl go
- Run
relayer
crosschain service.
cd examples/auction/relayer
go build .
./relayer
- Run
signer
crosschain services.
cd examples/auction/signer
go build .
# on different terminals
./signer -t -p ethereum -eth localhost:8545 -key ../../keys/key1 -id 1
./signer -p ethereum -eth localhost:8545 -key ../../keys/key2 -id 2
./signer -p quorum -eth localhost:8546 -key ../../keys/key1 -id 1
./signer -p quorum -eth localhost:8546 -key ../../keys/key2 -id 2
- Run the
scenario
script.
cd examples/auction/scenario
go run .
The scenario script will do the following steps.
- Add a new asset on the fabric
asset
contract. - Deploy auction contracts on
ethereum
andquorum
. - Create a new auction for this asset on on fabric.
- Bid correspondingly on both
ethereum
andquorum
. - End auction on
fabric
and print out the winner info and final asset owner onfabric
.
You can run the auction example by the following steps.
- Run Fabric.
cd fabric-samples/test-network
./network.sh up createChannel
- Run Ethereum POW.
cd ethereum/pow
./remove.sh
./init.sh
./start.sh
- Deploy
fabric_asset_pow
onfabric
.
./network.sh deployCC -ccn asset -ccp ../../contracts/fabric_asset_pow/chaincode -ccl go
- Run
relayer
crosschain service.
cd examples/auction_pow/relayer
go build .
./relayer
- Run
end_listener
crosschain services.
cd examples/auction_pow/end_listener
go build .
./end_listener
- Run the
scenario
script.
cd examples/auction_pow/scenario
go run .
The scenario script will do the following steps.
- Add a new asset on the fabric
asset
contract. - Deploy auction contract on
ethereum
. - Create a new auction for this asset on on fabric.
- Bid on both
ethereum
. - End auction on
ethereum
. end_listener
will listen to ethereum auction ending and will publishon_end_auction
event with POW headers and merkle proof for auction wiiner.- On receiving
on_end_auction
event,relayer
will end auction on fabric.