Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rainbow token contract update #460

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8d0421e
rainbows: test currency supply tracking with MC neg balances
chuck-h Apr 10, 2022
00e522a
Merge branch 'JoinSEEDS:master' into feature/rainbows
chuck-h Apr 15, 2022
77afda0
rainbows(mutual credit): improve max supply check
chuck-h Apr 18, 2022
a281394
rainbows (mutual credit): support un-opened account able to send tokens
chuck-h Apr 18, 2022
2ca795f
rainbows: link forgotton deletestake action
chuck-h Apr 18, 2022
9ec5ec5
rainbows: add unit test for deletestake
chuck-h Apr 20, 2022
76622c2
rainbows: re-enable some needed contract permissions
chuck-h Apr 20, 2022
e2bd7ae
rainbows: support token 'burn' without releasing backing (stake)
chuck-h Apr 20, 2022
bc938c0
Merge branch 'master' of https://github.com/JoinSEEDS/seeds-smart-con…
chuck-h Apr 21, 2022
d3e2c83
Merge branch 'JoinSEEDS-master' into feature/rainbows
chuck-h Apr 21, 2022
3805560
Rainbow: rename "stake" to "backing" step 1 (no change to wasm)
chuck-h May 2, 2022
0df28f6
Rainbow: rename "stake" to "backing" step 2 (update public interface)
chuck-h May 2, 2022
7cd98bb
Rainbows: retire "burn" flag -> "do_redeem" (invert logic)
chuck-h May 2, 2022
90da96c
Merge branch 'JoinSEEDS:master' into feature/rainbows
chuck-h May 22, 2022
057d7b9
rainbows: establish fee requirement to create token (WIP)
chuck-h May 23, 2022
7ae5671
rainbows: remove almost all issuer RAM requirements (contract pays)
chuck-h May 23, 2022
ae167cf
rainbows: improve insufficient fee error message
chuck-h May 23, 2022
b58c328
Merge pull request #12 from JoinSEEDS/master
chuck-h Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions include/seeds.rainbows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ using namespace eosio;

/**
* The opposite for issue action, if all validations succeed,
* it debits the statstable.supply amount. Any staked tokens are released from escrow in
* proportion to the quantity of tokens retired.
* it debits the statstable.supply amount. If `burn` flag is false,
* any staked tokens are released from escrow in proportion to the
* quantity of tokens retired.
*
* @param owner - the account containing tokens to retire,
* @param quantity - the quantity of tokens to retire,
* @param burn - if true, staked tokens are left in escrow,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I don't understand what burn parameter does. You'd think it burns token if this is true. But.... that's not what it does?

Copy link
Collaborator Author

@chuck-h chuck-h Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retire action on an ordinary token would just burn it, basically destroying value. But with "staked" or "backed" tokens, a retire action releases the staked value to the token holder and is more of a conversion of value. By setting the burn flag, a staked token is retired (value destroyed) but the staked value remains in escrow and is not released. Burn flag is a NOP on a plain token with no backing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can call it force_burn?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or... do_not_redeem?
Hmm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redeem_for_backing == true -> (burn == false)

? maybe describe the inverse, the positive ... so if the flag is true, the token holder receives the backing token for their retired tokens
?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"burn" flag is now "do_redeem" with inverted logic.

* @param memo - the memo string to accompany the transaction.
*
* @pre the redeem_locked_until configuration must be in the past (except that
Expand All @@ -228,7 +230,8 @@ using namespace eosio;
* 1. the proportional unstaking flag must be configured true, OR
* 2. the balance in the escrow account must meet the reserve_fraction criterion
*/
ACTION retire( const name& owner, const asset& quantity, const string& memo );
ACTION retire( const name& owner, const asset& quantity,
const bool& burn, const string& memo );

/**
* Allows `from` account to transfer to `to` account the `quantity` tokens.
Expand All @@ -247,9 +250,6 @@ using namespace eosio;
* credit if configured with credit_limit_symbol in `create` operation)
* @pre If configured with positive_limit_symbol in `create` operation, the transfer
* must not put the `to` account over its maximum limit
*
* Note: Transfer of zero tokens can effectively "open" an account (create a new
* balance entry in the `accounts` table) using `from` acct's ram.
*/
ACTION transfer( const name& from,
const name& to,
Expand Down Expand Up @@ -417,7 +417,7 @@ using namespace eosio;
};

EOSIO_DISPATCH(rainbows,
(create)(approve)(setstake)(setdisplay)(issue)(retire)(transfer)
(create)(approve)(setstake)(deletestake)(setdisplay)(issue)(retire)(transfer)
(open)(close)(freeze)(reset)(resetacct)
);

18 changes: 9 additions & 9 deletions scripts/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ var permissions = [{
// target: `${accounts.harvest.account}@active`,
// actor: `${accounts.history.account}@eosio.code`
// }, {
// target: `${accounts.token.account}@active`,
// actor: `${accounts.token.account}@eosio.code`
// }, {
target: `${accounts.token.account}@active`,
actor: `${accounts.token.account}@eosio.code`
}, {
// target: `${accounts.history.account}@active`,
// actor: `${accounts.accounts.account}@active`
// }, {
Expand Down Expand Up @@ -466,9 +466,9 @@ var permissions = [{
// }, {
// target: `${accounts.guardians.account}@application`,
// action: 'claim'
// }, {
// target: `${accounts.history.account}@active`,
// actor: `${accounts.token.account}@active`
}, {
target: `${accounts.history.account}@active`,
actor: `${accounts.token.account}@active`
// }, {
// target: `${accounts.acctcreator.account}@active`,
// actor: `${accounts.acctcreator.account}@eosio.code`
Expand Down Expand Up @@ -750,9 +750,9 @@ var permissions = [{
// }, {
// target: `${accounts.accounts.account}@addcbs`,
// action: 'addcbs'
// }, {
// target: `${accounts.pool.account}@active`,
// actor: `${accounts.pool.account}@eosio.code`
}, {
target: `${accounts.pool.account}@active`,
actor: `${accounts.pool.account}@eosio.code`
// }, {
// target: `${accounts.pool.account}@hrvst.pool`,
// actor: `${accounts.harvest.account}@eosio.code`,
Expand Down
55 changes: 35 additions & 20 deletions src/seeds.rainbows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ void rainbows::unstake_all( const name& owner, const asset& quantity ) {
}
}

void rainbows::retire( const name& owner, const asset& quantity, const string& memo )
void rainbows::retire( const name& owner, const asset& quantity,
const bool& burn, const string& memo )
{
auto sym = quantity.symbol;
check( sym.is_valid(), "invalid symbol name" );
Expand All @@ -335,20 +336,21 @@ void rainbows::retire( const name& owner, const asset& quantity, const string& m
stats statstable( get_self(), sym.code().raw() );
const auto& st = statstable.get( sym.code().raw(), "token with symbol does not exist" );
configs configtable( get_self(), sym.code().raw() );
const auto& cf = configtable.get();
if( cf.redeem_locked_until.time_since_epoch() < current_time_point().time_since_epoch() ) {
check( !cf.transfers_frozen, "transfers are frozen");
} else {
check( owner == st.issuer, "bearer redeem is disabled");
}
require_auth( owner );
check( quantity.is_valid(), "invalid quantity" );
check( quantity.amount > 0, "must retire positive quantity" );

check( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );

unstake_all( owner, quantity );

check( quantity.symbol == st.supply.symbol, "symbol or precision mismatch" );
if( !burn ) {
const auto& cf = configtable.get();
if( cf.redeem_locked_until.time_since_epoch() <
current_time_point().time_since_epoch() ) {
check( !cf.transfers_frozen, "transfers are frozen");
} else {
check( owner == st.issuer, "bearer redeem is disabled");
}

unstake_all( owner, quantity );
}
sub_balance( owner, quantity, symbol_code(0) );
statstable.modify( st, same_payer, [&]( auto& s ) {
s.supply -= quantity;
Expand Down Expand Up @@ -402,13 +404,16 @@ void rainbows::transfer( const name& from,
sub_balance( from, quantity, cf.cred_limit );
add_balance( to, quantity, payer, cf.positive_limit );

stats statstable2( get_self(), sym_code_raw ); // use updated statstable for supply value
const auto& st2 = statstable2.get( sym_code_raw );
check( st2.max_supply.amount >= st2.supply.amount, "new credit exceeds available supply");

}

void rainbows::sub_balance( const name& owner, const asset& value, const symbol_code& limit_symbol ) {
accounts from_acnts( get_self(), owner.value );

const auto& from = from_acnts.get( value.symbol.code().raw(), "no balance object found" );
uint64_t limit = 0;
int64_t limit = 0;
if( limit_symbol != symbol_code(0) ) {
auto cred = from_acnts.find( limit_symbol.raw() );
if( cred != from_acnts.end() ) {
Expand All @@ -417,15 +422,25 @@ void rainbows::sub_balance( const name& owner, const asset& value, const symbol_
limit = lim.balance.amount;
}
}
int64_t new_balance = from.balance.amount - value.amount;
check( new_balance + limit >= 0, "overdrawn balance" );
int64_t credit_increase = std::min( from.balance.amount, 0LL ) - std::min( new_balance, 0LL );
from_acnts.modify( from, same_payer, [&]( auto& a ) {
a.balance.amount = new_balance;
int64_t new_amount, old_amount;
const auto fr = from_acnts.find( value.symbol.code().raw() );
if( fr == from_acnts.end() ) {
old_amount = 0;
new_amount = -value.amount;
from_acnts.emplace( owner, [&]( auto& a ){
a.balance = asset{new_amount, value.symbol};
});
} else {
old_amount = fr->balance.amount;
new_amount = old_amount - value.amount;
from_acnts.modify( fr, same_payer, [&]( auto& a ) {
a.balance.amount = new_amount;
});
}
check( new_amount + limit >= 0, "overdrawn balance" );
int64_t credit_increase = std::min( old_amount, 0LL ) - std::min( new_amount, 0LL );
stats statstable( get_self(), value.symbol.code().raw() );
const auto& st = statstable.get( value.symbol.code().raw() );
check( credit_increase <= st.max_supply.amount - st.supply.amount, "new credit exceeds available supply");
statstable.modify( st, same_payer, [&]( auto& s ) {
s.supply.amount += credit_increase;
});
Expand Down
Loading