GithubHelp home page GithubHelp logo

goums / sovryn-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from distributedcollective/sovryn-node

0.0 0.0 0.0 959 KB

JavaScript 97.23% HTML 1.21% TypeScript 0.15% CSS 0.05% Shell 0.15% Solidity 1.21%

sovryn-node's Introduction

Sovryn node

The Sovryn node reads all open positions from the Sovryn marginTrade contracts and continuously monitors for changes. The app has three main functions: Liquidation of expired positions, rollover of open positions and taking advantage of arbitrage opportunities on the amm.

1. Liquidation handling

If margin < maintenance, it initiates liquidation on the contract.
If it fails, it checks if the liquidation criteria are still met.
If not, it keeps observing.
If yes, it sends an error notification to a telegram group for manual processing.
If the tx was not confirmed after 10 minutes, it resends the transaction with a higher gas fee.

The liquidator needs considerable funds in all currencies provided to be able to liquidate a position. He needs to allow the protocol contract to access his tokens in advance (Approve token transfers of all involved Erc20 tokens) and have enough RBTC to cover transaction costs.

2. Rollover

When the maximum loan duration has been exceeded, the position will need to be rolled over. The function "rollover" on the protocol contract extends the loan duration by the maximum term (28 days for margin trades at the moment of writing) and pays the interest to the lender. The callers reward is 0.1% of the position size and receives 2 * the gas cost using the fast gas price as base for the calculation as well as 0.1% .

3. Arbitrage

Earn $ through arbitrage: if the expected price from the amm deviates more than 2 % from the oracle price buy the side which is off and exchange the money back on money onchain.

Requirements

NodeJs > 12.1
Nodemon
Webpack

Install

1. npm install
2. npm install -g mocha nodemon
3. To build the client create an empty directory "public/dist" and run "npm run build-client"
4. Create empty directories "logs" and "db" in the project root
5. Create directory "secrets" and within a file accounts.js with the credentials of the liquidator/rollover/arbitrage wallets
ks = encrypted keystore file in v3 standard.
(alternatively, you can specify pKey instead of ks to just use the private key)

export default {
    "liquidator": [{
        adr: "",
        ks: ""
    }],
    "rollover": [{
        adr: "",
        ks: ""
    }],
    "arbitrage": [{
        adr: "",
        ks: ""
    }],
}

To receive notifications on telegram about new transactions and errors create a telegram bot-token-id and write in in a file /secrets/telegram.js
export default "[telegram-bot-token]";
export default ""; for no notifications

6. Charge the Sovryn node wallets with all relevant tokens and enough Rbtc to cover tx cost.
7. Execute node -r esm util/approval.js to approve the Sovryn smart contract to spend Doc on behalf of the Sovryn node wallets as well as the swap network contract to spend tokens on behalf of the arbitrage wallet.

Start

npm run start:[main || test] [wallet-password]

Check
http://your-ip:3000/ to see some liquidation processing info

Logging

The Sovryn node uses pm2 for log handling.
To enable Log-rotationdo "pm2 install pm2-logrotate" and afterwards "pm2 set pm2-logrotate:max_size 1000K"

Developer

To develop the frontend with Hot Reload run npm run dev

Hardhat tests

Sovryn-Node includes tests created with Hardhat. To run them, first npm install this package, then follow the instructions in integration-tests/README.md.

License

MIT Free Software, Hell Yeah!

sovryn-node's People

Contributors

bitcoinera avatar jamiemadrox779 avatar koirikivi avatar thorodinson01010101 avatar

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.