Code Monkey home page Code Monkey logo

gusdbot's Introduction

Stablecoin By Mood Global Services B.V. for Gatochain Foundation


Stabilizing Algorithm

Mint And Burn Mechanism

-The protocol mints (adds) or burns (removes) supply from circulation in proportion to the coin's price deviation from the $1 peg. If the coin price > $1, the protocol mints coins. If the coin price < $1, the protocol burns coins.

-Keeps the price of stable coin at targeted price and also checks every 24 hour for the volatility feature to automatically adjust the target price based on market conditions, such as the average price over a certain period or the price of a basket of other stablecoins. This can make the bot more adaptive to changing market dynamics and reduce the need for manual intervention.

Idea Behind The Bot

The basic idea behind it is to adjust the supply of the stablecoin tokens to maintain a constant price in terms of the target asset. If the price of the stablecoin rises above the target price, the protocol will increase the supply of tokens by "minting" new tokens and distributing them to holders of the stablecoin. If the price of the stablecoin falls below the target price, the protocol will decrease the supply of tokens by "burning" existing tokens, effectively removing them from circulation.

The key advantage of using a this mechanism is that it allows the stablecoin to maintain its peg to the target asset without relying on centralized reserves of the target asset. Instead, the supply of the stablecoin is dynamically adjusted based on market conditions, which can help to prevent large fluctuations in price.

Preventions against FlashLoans

Using Time-Weighted Average Pricing (TWAP):

We can create a Custom Price oracle Contract wich calculates average price over time. Instead of using the latest price, you can use the average price over a certain period. This helps mitigate flash loan attacks as the attacker would have to manipulate prices over a longer duration(by Buying or selling large number of tokens)

We used the aggregator contract price oracle because it provides a decentralized, tamper-resistant, and reliable source of price data. The aggregator contract receives periodic data updates from a decentralized oracle network, which consists of multiple oracles.

Flowchart

graph TD
    A[Algorithm] -->|Check Current Price| B[Calculate Price Differential]
    B -->|Calculate New Token Supply| C[ MInt/Burn Tokens as Needed ]
    C -->|Mint| E[Mint if price exceeds threshold]   
    C -->|Burn| F[Burn if price falls below threshold]  
    E --> |Monitor market trend from custom oracle deployed| D[Check The Trend Of Market]
    F --> |Monitor market trend from custom oracle deployed | D
   D -->|Buy| G[Buy if Demand falls below threshold]   
    D -->|Sell| H[Sell if Demand exceeds threshold]  
Loading

Steps To Run Tests Bot with following Command on cmd

1. Initialize localnet

npx hardhat node

2. Run Tests

npx hardhat test test/BotTest.js --network localhost   

3.Results

+4 passing


Run Bot

- @@ Make Sure Stablecoin have some USDT in them before initializing Bot AND owner account have USDT in its wallet @@

+ Configure Gatochain in hardhat config in networks

0. Function for mintAdjust and burnAdjust

Stablecoin should have a onlyOwner function for mintAdjust and burnAdjust which does not require any usdt to give or recieve when minting and burning so that it can adjust supply of stablecoin

1. Change Usdt And Stablecoin Smart Contract Addresses in The Bot File

image

2. Change OwnerAddress and its privateKey of smart Contract

- @@ Make Sure to put them in an .env file in production environmnet @@

image

3. Change RPC endpoint (Infura Alchemy etc)

image

4. Copy USDT and StableCoin ABIs in script/Abi Folders respectively

image

5. Run Bot VIA command prompt

npx hardhat run scripts/Bot.js --network <networkName>

6. Change Schedule Timer as required (default to 1 minute)

node-cron expressions can be changed

gusdbot's People

Contributors

abuzarghazanfarkhan avatar gdbmood avatar

Watchers

 avatar

Forkers

hu050

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.