Borrow any amount of liquidity instantly for near-zero fees & no collateral.
Local
$ eosio-cpp flash.sx.cpp -I include
$ shasum -a 256 flash.sx.wasm
c5c951f95c9fa420e68471e9372078313f03a7e5324eb3dd4bc02f15201509e1 flash.sx.wasm
EOS Mainnet
$ cleos -u https://api.eosn.io get code flash.sx
code hash: c5c951f95c9fa420e68471e9372078313f03a7e5324eb3dd4bc02f15201509e1
- 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.
🙏 Inspired by EOS Titan flashloans smart contract design.
Account requests to borrow quantity
- authority:
any
{name} receiver
- receiver of flash loan{extended_asset} amount
- 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}};
const name contract = "eosio.token"_n;
sx::flash::borrow_action borrow( "flash.sx"_n, { get_self(), "active"_n });
borrow.send( get_self(), extended_asset{quantity, contract}, "my memo", "notifyme" );
$ cleos push action flash.sx borrow '["myaccount", ["1.0000 EOS", "eosio.token"], "my memo", "notifyme"]' -p myaccount
Notifies recipient account via callback
action after transfer has been sent from borrow
action
- authority:
get_self()
{name} code
- flash loan contract{name} receiver
- receiver of flash loan{extended_asset} amount
- flash loan request amount{asset} fee
- flash loan fee{string} [memo=""]
- used for outgoing transfer{name} [notifier=""]
- callback notifier account
[[eosio::on_notify("flash.sx::callback")]]
void callback( const name code, const name receiver, const extended_asset amount, const asset fee, const string memo, const name notifier )
{
eosio::token::transfer_action transfer( amount.contract, { receiver, "active"_n });
transfer.send( receiver, code, amount.quantity + fee, memo );
}
Calculate processing fee
{name} code
- flash loan code{asset} quantity
- quantity input
const asset quantity = asset{10000, symbol{"EOS", 4}}; // 1.0000 EOS
const asset fee = sx::flash::calculate_fee( "flash.sx"_n, quantity );
// => 0.0002 EOS
{uint8_t} fee
- processing fee (bips 1/100 of 1%)
{
"fee": 2
}
{name} contract
- contract name{asset} balance
- balance amount
{
"contract": "eosio.token",
"balance": "1.0000 EOS"
}