Giter Club home page Giter Club logo

sx.flash's Introduction

SX Flashloans ⚡️ - EOSIO Smart Contract

🙏Inspired by EOS Titan flashloans smart contract design.

Borrow any amount of liquidity instantly for zero fees & no collateral.

Table of Content

Concept

  1. account calls borrow action from flash.sx with a desired quantity.
    • contract gets initial balance of asset.
    • contract sends quantity to account.
  2. account recieves notifications via on_notify and/or callback of incoming transfer.
    • account is free to use received quantity for any purposes.
    • account returns loan back to contract.
  3. contract gets final balance of asset
    • contract throws an error if initial balance is lower than final balance.

Examples

Build

$ eosio-cpp flash.sx.cpp -I include

ACTION borrow

Account requests to borrow quantity

  • authority: any

params

  • {name} to - receiver of flash loan
  • {name} contract - token contract account
  • {asset} quantity - flash loan request amount
  • {string} [memo=""] - (optional) transfer memo
  • {name} [notifier=""] - (optional) notify accounts after transfer has been sent

Example 1

const asset quantity = asset{10000, symbol{"EOS", 4}};
flash::borrow_action borrow( "flash.sx"_n, { get_self(), "active"_n });
borrow.send( get_self(), "eosio.token"_n, quantity, "my memo", "notifyme" );

Example 2

$ cleos push action flash.sx borrow '["myaccount", "eosio.token", "1.0000 EOS", "my memo", "notifyme"]' -p myaccount

ACTION savebalance

Save existing balance of account

  • authority: any

params

  • {name} account - account to save balance from
  • {map<symbol_code, name>} symcodes - map of symbol code & contract names (ex: [ symbol_code{"EOS"}, "eosio.token"_n ] )

Example 1

const name account = "myaccount"_n;
map<symbol_code, name> symcodes;
symcodes[symbol_code{"EOS"}] = "eosio.token"_n;

flash::savebalance_action savebalance( "flash.sx"_n, { account, "active"_n });
savebalance.send( account, symcodes );

Example 2

$ cleos push action flash.sx savebalance '["myaccount", [{"key": "EOS", "value": "eosio.token"}]]' -p myaccount

ACTION checkbalance

Throws error if account does not have equal or above previously saved balance

  • authority: any

params

  • {name} account - account to check if minimum balance is available
  • {map<symbol_code, name>} symcodes - map of symbol code & contract names (ex: [ symbol_code{"EOS"}, "eosio.token"_n ] )

Example 1

const name account = "myaccount"_n;
map<symbol_code, name> symcodes;
symcodes[symbol_code{"EOS"}] = "eosio.token"_n;

flash::checkbalance_action checkbalance( "flash.sx"_n, { account, "active"_n });
checkbalance.send( account, symcodes );

Example 2

$ cleos push action flash.sx checkbalance '["myaccount", [{"key": "EOS", "value": "eosio.token"}]]' -p myaccount

ACTION callback

Notifies recipient account via callback action after transfer has been sent from borrow action

  • authority: get_self()

params

  • {name} to - receiver of flash loan
  • {name} contract - token contract account
  • {asset} quantity - flash loan request amount
  • {string} memo - used for outgoing transfer
  • {name} recipient - callback recipient

Example

[[eosio::on_notify("flash.sx::callback")]]
void callback( const name to, const name contract, asset quantity, const string memo, const name recipient )
{
    token::transfer_action transfer( contract, { get_self(), "active"_n });
    transfer.send( get_self(), "flash.sx"_n, quantity, memo );
}

sx.flash's People

Contributors

deniscarriere avatar dario2202 avatar

Watchers

James Cloos 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.