🙏Inspired by EOS Titan flashloans smart contract design.
Borrow any amount of liquidity instantly for zero fees & no collateral.
- account calls
borrow
action fromflash.sx
with a desiredquantity
.- contract gets initial balance of asset.
- contract sends quantity
to
account.
- account recieves notifications via
on_notify
and/orcallback
of incoming transfer.- account is free to use received quantity for any purposes.
- account returns loan back to contract.
- contract gets final balance of asset
- contract throws an error if initial balance is lower than final balance.
$ eosio-cpp flash.sx.cpp -I include
Account requests to borrow quantity
- authority:
any
{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
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" );
$ cleos push action flash.sx borrow '["myaccount", "eosio.token", "1.0000 EOS", "my memo", "notifyme"]' -p myaccount
Save existing balance of account
- authority:
any
{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 ] )
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 );
$ cleos push action flash.sx savebalance '["myaccount", [{"key": "EOS", "value": "eosio.token"}]]' -p myaccount
Throws error if account does not have equal or above previously saved balance
- authority:
any
{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 ] )
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 );
$ cleos push action flash.sx checkbalance '["myaccount", [{"key": "EOS", "value": "eosio.token"}]]' -p myaccount
Notifies recipient account via callback
action after transfer has been sent from borrow
action
- authority:
get_self()
{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
[[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 );
}