A demo for a cross-chain lending using chainsight

Overview

demo-crosschain-lending

A demo of crosschain lending, using chainsight.

Overview

This demo shows how to use the chainsight protocol to deposit assets on one chain, and then lend token on another chain, using deposit assets as collateral. Also, it shows how to liquidate the collateral when the loan is not repaid. If the collateral is liquidated on the second chain, the deposit assets are released on the first chain to the liquidator. This is one of a series of demos that show how to use chainsight to build cross-chain applications.

overview

A working demo is available here.

Pre-requisites

Setup

yarn

And .env file is needed, which contains the following information:

# .env
# mnemonic
MNEMONIC=test test test test test test test test test test test test
# alchemy api key
ALCHEMY_OPTIMISM_KEY=xxx
ALCHEMY_ARBITRUM_KEY=xxx
# etherscan api key
ETHERSCAN_OPTIMISM_KEY=xxx
ETHERSCAN_ARBITRUM_KEY=xxx

Deploy and setup

Before setup, you need some ETH to pay for the gas fee on both chains(Optimism Goerli and Arbitrum Goerli) to run demo. You can get some test ETH from Optimism faucet and Arbitrum faucet. Send ETH to the first and second addresses in the mnemonic. The first user is the borrower, and the second is the liquidator.

  1. Deploy contracts on the first chain
npx hardhat run scripts/0_deploy.ts --network optimismTest

And verify contracts on the first chain

npx hardhat run scripts/verify.ts --network optimismTest
  1. Deploy contracts on the second chain
npx hardhat run scripts/0_deploy.ts --network arbitrumGoerli

And vefiry contracts on the second chain

npx hardhat run scripts/verify.ts --network arbitrumGoerli
  1. Start dfx local network
dfx start 
  1. Depoloy chainsight canisters on mainnet
./chainsight/scripts/0_update_addresses.sh
./chainsight/scripts/1_deploy_canisters.sh
  1. Setup canisters
./chainsight/scripts/2_subscribe.sh
./chainsight/scripts/3_send_ether.sh

Run demo

  1. Mint DAI on the first chain(Optimism Goerli) and lock it to another chain(Arbitrum Goerli)
npx hardhat run scripts/2_mint_and_lock.ts --network optimismTest
  1. Borrow TUSD on the second chain, using the locked DAI as collateral
npx hardhat run scripts/3_borrow_on_dst.sh --network arbitrumGoerli
cd chainsight && dfx canister call lock_indexer_arbitrumGoerli save_logs && cd .. 

And you confirm onLockCreated tx like this on the second chain. This transaction is sent by the lock_relayer_optimism canister on local ICP, which is subscribed to the lock event of the lock_indexer_optimism canister.

  1. Make TUSD oracle price high in order to liquidate the TUSD on the second chain
npx hardhat run scripts/4_set_price.ts --network arbitrumGoerli
  1. Liquidate the TUSD on the second chain on behalf of the second user
npx hardhat run scripts/5_liquidate_on_dst.sh --network arbitrumGoerli
cd chainsight && dfx canister call unlock_indexer_arbitrumGoerli save_logs && cd ..

And you can confirm unlock asset tx like this

This transaction is sent by the unlock_relayer_arbitrum canister on local ICP, which is subscribed to the unlock event of the unlock_indexer_arbitrum canister.

More information

You might also like...
On-chain query aggregator/batcher in Terra.
On-chain query aggregator/batcher in Terra.

Multicall On-chain query aggregator/batcher in Terra. Mainnet Code Id: 3758 Mainnet Address: terra1y60jx2jqh5qpmcnvgz3n0zg2p6ky4mr6ax2qa5 Testnet Code

Tooling and library for generation, validation and verification of supply chain metadata documents and frameworks

Spector Spector is both tooling and a library for the generation, validation and verification of supply chain metadata documents and frameworks. Many

Using BDK from nodejs using WASM webpack 🦀

BDK + nodejs = ❤️ This repository shows how to use the bdk library in nodejs. It's just a proof-of-concept, not a complete example, and as such, it's

Cross-platform Rust library for coloring and formatting terminal output
Cross-platform Rust library for coloring and formatting terminal output

Coloring terminal output Documentation term-painter is a cross-platform (i.e. also non-ANSI terminals) Rust library for coloring and formatting termin

Cross platform terminal library rust
Cross platform terminal library rust

Cross-platform Terminal Manipulation Library Crossterm is a pure-rust, terminal manipulation library that makes it possible to write cross-platform te

A cross platform minimalistic text user interface
A cross platform minimalistic text user interface

titik Titik is a crossplatform TUI widget library with the goal of being able to interact intuitively on these widgets. It uses crossterm as the under

Alacritty - A fast, cross-platform, OpenGL terminal emulator
Alacritty - A fast, cross-platform, OpenGL terminal emulator

Alacritty is a modern terminal emulator that comes with sensible defaults, but allows for extensive configuration. By integrating with other applications, rather than reimplementing their functionality, it manages to provide a flexible set of features with high performance. The supported platforms currently consist of BSD, Linux, macOS and Windows.

A cross-platform graphical process/system monitor with a customizable interface and a multitude of features
A cross-platform graphical process/system monitor with a customizable interface and a multitude of features

A cross-platform graphical process/system monitor with a customizable interface and a multitude of features. Supports Linux, macOS, and Windows. Inspired by both gtop and gotop.

Cross-platform terminal screen clearing library

ClearScreen Cross-platform terminal screen clearing library. API documentation. Dual-licensed with Apache 2.0 and MIT. Uses Caretaker Maintainership.

Owner
HorizonX
HorizonX
An anchor CPI client for the SPL token lending program

anchor-lending anchor-lending is an anchor CPI client for any program that implements or extends the instruction interface found in the spl token lend

Rohan Kapur 11 Oct 24, 2022
Demo app duplicated in 5 languages (Go/JavaScript/Python/Ruby/Rust) showing how to go from source code to container image using melange+apko

hello-melange-apko ?? This repo contains an example app duplicated across 5 languages showing how to: Package source code into APKs using melange Buil

Chainguard 16 Jan 23, 2023
A small cli demo of rust&wasm hostcall framework.

A Cli Example for Rust and WebAssembly Hostcall Usage # build wasms for ervery module in the `wasm` directory and move them to the root directory # ex

BC2022 3 Aug 29, 2022
Demo Rust Cursive crate for terminal user interface (TUI)

Demo Rust Cursive Demonstration of the Rust programming language and Cursvie crate for terminal user interface (TUI). Setup Create: cargo new demo Add

Joel Parker Henderson 5 Dec 27, 2022
Polyexen demo of Plonkish Arithmetiation Format (Plaf) on the zkevm-circuits

Plaf demo This is a demo of Plaf: Plonkish Arithmetiation Format on the zkevm-circuits Steps to run this: Clone these three repositories in the same f

Eduard S. 17 Apr 6, 2023
A simple demo to bind a TCP port with k8s exec channel.k8s.io websocket API.

k8s-webterm-connector Tired with web terminals? Let's use it with CLI! This is just a simple demo to bind a TCP port with k8s exec websocket API, whic

Chielo 4 Aug 11, 2023
A set of demo projects for the Fyrox Game Engine.

Fyrox Demo Projects A set of demo projects for the Fyrox Game Engine. Most of the projects located in this repository in the respective folders. Navig

Fyrox Engine 8 Oct 4, 2023
GraphQL Summit 2023 Workshop Demo for Federated Subscriptions in GraphOS.

Kahoot Clone Demo App - Subgraphs Welcome to the project for GraphQL Summit 2023 "Federated Subscriptions in GraphOS" workshop! ⚠️ Before the workshop

Apollo GraphQL 4 Oct 10, 2023
rust+slint+candle+openchat3.5 demo

Slint Chatbot Demo This is a demo of Rust + Slint + Candle + OpenChat LLM, it looks like this: Do it by yourself Make sure you have downloaded opencha

null 12 Dec 13, 2023
ufo2nft is a CLI Rust tool to automate creating on-chain SVG NFTs from UFO font sources

ufo2nft is a CLI Rust program created by Eli Heuer at the 2022 Seattle Solana Hacker House event. It uses Norad to create on-chain SVG images from UFO font sources, and prepares them for minting as Solana NFTs. For Ethereum NFTs the program can just export the SVGs and Ethereum NFTs can be built manually.

Eli Heuer 1 Feb 10, 2022