Skip to content

Commit

Permalink
Merge pull request #5 from chuck-h/dev
Browse files Browse the repository at this point in the history
merge v0.7
  • Loading branch information
chuck-h committed Nov 17, 2021
2 parents a75151f + de8a997 commit 3365184
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 76 deletions.
74 changes: 61 additions & 13 deletions RainbowC/include/rainbow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <eosio/asset.hpp>
#include <eosio/eosio.hpp>
#include <eosio/singleton.hpp>
#include <eosio/system.hpp>

#include <string>
Expand Down Expand Up @@ -78,15 +79,17 @@ namespace eosio {


/**
* By this action the contract owner approves the creation of the token. Until
* this approval, no tokens may be issued.
* By this action the contract owner approves or rejects the creation of the token. Until
* this approval, no tokens may be issued. If rejected, and no issued tokens are outstanding,
* the table entries for this token are deleted.
*
* @param symbolcode - the symbol_code of the token to execute the close action for.
* @param reject_and_clear - if this flag is true, delete token; if false, approve creation
*
* @pre The symbol must have been created.
*/
[[eosio::action]]
void approve( const symbol_code& symbolcode );
void approve( const symbol_code& symbolcode, const bool& reject_and_clear );


/**
Expand All @@ -102,6 +105,8 @@ namespace eosio {
* @param stake_token_contract - the staked token contract account (e.g. token.seeds),
* @param stake_to - the escrow account where stake is held, or `deletestake`
* to remove a row from the stakes table
* @param deferred - staking relationship does not transfer stake to escrow.
* @param proportional - redeem by proportion of escrow rather than by staking ratio.
* @param memo - the memo string to accompany the transaction.
*
* @pre Token symbol must have already been created by this issuer
Expand All @@ -117,9 +122,37 @@ namespace eosio {
const asset& stake_per_bucket,
const name& stake_token_contract,
const name& stake_to,
const bool& deferred,
const bool& proportional,
const string& memo);

/**
* This action issues a `quantity` of tokens to the issuer account.
* Allows `issuer` account to create or update display metadata for a token. All fields
* except `name` and `json_meta` are expected to be urls. Issuer pays for RAM.
* The currency_display table is intended for apps to access (e.g. via nodeos chain API).
*
* @param issuer - the account that created the token,
* @param symbol_code - the token,
* @param memo - the memo string to accompany the transaction.
*
* @pre Token symbol must have already been created by this issuer
* @pre String parameters must be within length limits
* name < 32 char, json_meta < 1024 char, all others < 256 char
*/
[[eosio::action]]
void setdisplay( const name& issuer,
const symbol_code& symbolcode,
const string& name,
const string& logo,
const string& logo_lg,
const string& web_link,
const string& background,
const string& json_meta
);

/**
* This action issues a `quantity` of tokens to the issuer account, and transfers
* a proportional amount of stake to escrow if staking is configured.
*
* @param to - the account to issue tokens to, it must be the same as the issuer,
* @param quantity - the amount of tokens to be issued,
Expand Down Expand Up @@ -232,6 +265,7 @@ namespace eosio {
using create_action = eosio::action_wrapper<"create"_n, &token::create>;
using approve_action = eosio::action_wrapper<"approve"_n, &token::approve>;
using setstake_action = eosio::action_wrapper<"setstake"_n, &token::setstake>;
using setdisplay_action = eosio::action_wrapper<"setdisplay"_n, &token::setdisplay>;
using issue_action = eosio::action_wrapper<"issue"_n, &token::issue>;
using retire_action = eosio::action_wrapper<"retire"_n, &token::retire>;
using transfer_action = eosio::action_wrapper<"transfer"_n, &token::transfer>;
Expand All @@ -243,21 +277,22 @@ namespace eosio {
const name allowallacct = "allowallacct"_n;
const name deletestakeacct = "deletestake"_n;
const int max_stake_count = 8; // don't use too much cpu time to complete transaction
struct [[eosio::table]] account {

struct [[eosio::table]] account { // scoped on account name
asset balance;

uint64_t primary_key()const { return balance.symbol.code().raw(); }
};

struct [[eosio::table]] currency_stats {
struct [[eosio::table]] currency_stats { // scoped on token symbol code
asset supply;
asset max_supply;
name issuer;

uint64_t primary_key()const { return supply.symbol.code().raw(); }
};

struct [[eosio::table]] currency_config {
struct [[eosio::table]] currency_config { // scoped on token symbol code
name membership_mgr;
name withdrawal_mgr;
name withdraw_to;
Expand All @@ -266,16 +301,26 @@ namespace eosio {
time_point config_locked_until;
bool transfers_frozen;
bool approved;
};

uint64_t primary_key()const { return 0; } // single row per scope
struct [[eosio::table]] currency_display { // scoped on token symbol code
string name;
string logo;
string logo_lg;
string web_link;
string background;
string json_meta;
};


struct [[eosio::table]] stake_stats {
uint64_t index;
asset token_bucket;
asset stake_per_bucket;
name stake_token_contract;
name stake_to;
bool deferred;
bool proportional;

uint64_t primary_key()const { return index; };
uint128_t by_secondary() const {
Expand All @@ -285,7 +330,10 @@ namespace eosio {

typedef eosio::multi_index< "accounts"_n, account > accounts;
typedef eosio::multi_index< "stat"_n, currency_stats > stats;
typedef eosio::multi_index< "configs"_n, currency_config > configs;
typedef eosio::singleton< "configs"_n, currency_config > configs;
typedef eosio::multi_index< "configs"_n, currency_config > dump_for_config;
typedef eosio::singleton< "displays"_n, currency_display > displays;
typedef eosio::multi_index< "displays"_n, currency_display > dump_for_display;
typedef eosio::multi_index
< "stakes"_n, stake_stats, indexed_by
< "staketoken"_n,
Expand All @@ -295,10 +343,10 @@ namespace eosio {

void sub_balance( const name& owner, const asset& value );
void add_balance( const name& owner, const asset& value, const name& ram_payer );
void stake_all( const currency_stats st, const uint64_t amount );
void unstake_all( const currency_stats st, const name& owner, const uint64_t amount );
void stake_one( const currency_stats st, const stake_stats sk, const uint64_t amount );
void unstake_one( const currency_stats st, const stake_stats sk, const name& owner, const uint64_t amount );
void stake_all( const name& owner, const asset& quantity );
void unstake_all( const name& owner, const asset& quantity );
void stake_one( const stake_stats& sk, const name& owner, const asset& quantity );
void unstake_one( const stake_stats& sk, const name& owner, const asset& quantity );

};

Expand Down
18 changes: 16 additions & 2 deletions RainbowC/ricardian/rainbow.contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
---
spec_version: "0.2.0"
title: Approve Created Token
summary: 'Approve characteristics of a newly created token'
summary: 'Approve characteristics of a newly created token, or reject it'
icon: @ICON_BASE_URL@/@TOKEN_ICON_URI@
---

The contract owner allows the issuer to begin issuing tokens under a newly created {{symbol_to_symbol_code symbol}}.
Once approved, the issuer may modify the token configuration without any further approval action required.
If {{reject_and_clear}} is true, and there are no outstanding issued tokens, the token is deleted.

<<h1 class="contract">close</h1>

Expand Down Expand Up @@ -78,7 +79,7 @@ RAM will be deducted from the token manager (issuer) resources to create the nec

This action does not allow the total quantity to exceed the max allowed supply of the token.

A proportionate number of staking tokens are transferred from issuer's account to the stake_to escrow account for each stake listed in the stake stats table.
A proportionate number of staking tokens are transferred from issuer's account to the stake_to escrow account for each non-deferred stake listed in the stake stats table.

<h1 class="contract">open</h1>

Expand Down Expand Up @@ -124,6 +125,19 @@ A proportionate number of staking tokens are transferred from the stake_to escro
{{memo}}
{{/if}}

<h1 class="contract">setdisplay</h1>

---
spec_version: "0.2.0"
title: Create or Update Display Metadata for a Token
summary: 'Set display metadata'
icon: @ICON_BASE_URL@/@TOKEN_ICON_URI@
---

{{issuer}} agrees to associate a set of display metadata with an existing token {{symbol_code}}.

RAM will deducted from {{issuer}}’s resources to update the necessary records.

<h1 class="contract">setstake</h1>

---
Expand Down
Loading

0 comments on commit 3365184

Please sign in to comment.