Skip to content

Commit

Permalink
fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
ansigroup committed Mar 16, 2021
1 parent f45175e commit 4745736
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions build/contracts/eosio.system/eosio.system.abi
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@
},
{
"name": "ramlimit",
"type": "int64"
"type": "uint64"
}
]
},
Expand Down Expand Up @@ -1490,7 +1490,7 @@
},
{
"name": "bytes",
"type": "int64"
"type": "uint64"
}
]
},
Expand Down
Binary file modified build/contracts/eosio.system/eosio.system.wasm
Binary file not shown.
16 changes: 9 additions & 7 deletions contracts/eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1186,25 +1186,23 @@ namespace eosiosystem {
void undelegatebw( const name& from, const name& receiver,
const asset& unstake_net_quantity, const asset& unstake_cpu_quantity );




// PROTON RAM CHANGE:
// old actions `buyrambytes/buyram/sellram` renamed to `buyrambsys/buyramsys/sellramsys`
// old action `buyram` renamed to `buyramsys`
/**
* Buy ram action, increases receiver's ram quota based upon current price and quantity of SYS
* tokens provided. An inline transfer from receiver to system contract of
* tokens will be executed.
*
* @param payer - the ram buyer,
* @param receiver - the ram receiver,
* @param quant - the quntity of tokens to buy ram with.
* @param quant - the quantity of tokens to buy ram with.
*/
[[eosio::action]]
void buyramsys( const name& payer, const name& receiver, const asset& quant );


// PROTON RAM CHANGE
// old action `buyrambytes` renamed to `buyrambsys`
/**
* Buy a specific amount of ram bytes action. Increases receiver's ram in quantity of bytes provided.
* An inline transfer from receiver to system contract of tokens will be executed.
Expand All @@ -1218,6 +1216,7 @@ namespace eosiosystem {


// PROTON RAM CHANGE
// old actions `sellram` renamed to `sellramsys`
/**
* Sell ram action, reduces quota by bytes and then performs an inline transfer of tokens
* to receiver based upon the average purchase price of the original quota.
Expand All @@ -1230,6 +1229,7 @@ namespace eosiosystem {


// PROTON RAM CHANGE
// old action `buyram` renamed to `buyramsys`
/**
* Buy ram action, increases receiver's ram quota based upon fixed price and quantity of XPR
* tokens provided. An inline transfer from receiver to system contract of
Expand All @@ -1244,6 +1244,7 @@ namespace eosiosystem {


// PROTON RAM CHANGE
// old action `buyrambytes` renamed to `buyrambsys`
/**
* Buy a specific amount of ram bytes action. Increases receiver's ram in quantity of bytes provided.
* An inline transfer from payer to system contract of XPR tokens will be executed.
Expand All @@ -1257,6 +1258,7 @@ namespace eosiosystem {


// PROTON RAM CHANGE
// old action `sellram` renamed to `sellramsys`
/**
* Sell ram action, reduces quota by bytes and then performs an inline transfer of tokens
* to receiver based upon the fixed price.
Expand All @@ -1265,7 +1267,7 @@ namespace eosiosystem {
* @param bytes - the amount of ram to sell in bytes.
*/
[[eosio::action]]
void sellram( const name& account, int64_t bytes );
void sellram( const name& account, uint64_t bytes );


// PROTON RAM
Expand All @@ -1287,7 +1289,7 @@ namespace eosiosystem {
* @param bytes
*/
[[eosio::action]]
void ramlimitset( const name& account, int64_t ramlimit );
void ramlimitset( const name& account, uint64_t ramlimit );


/**
Expand Down
28 changes: 13 additions & 15 deletions contracts/eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ namespace eosiosystem {

// PROTON RAM
void system_contract::buyrambytes( const name& payer, const name& receiver, uint32_t bytes ) {
check(!(_gstateram.ram_price_per_byte.amount == 0), "Wrong price per byte. Buy RAM is not configured");
check(!(bytes == 0), "parameter bytes cannot be zero");

int64_t cost = _gstateram.ram_price_per_byte.amount * bytes;
int64_t costwfee = 100 * cost / (100 - (double)_gstateram.ram_fee_percent / (double)ram_fee_precision ) ;
const uint64_t cost = _gstateram.ram_price_per_byte.amount * bytes;

const double fee_percentage = ((double)_gstateram.ram_fee_percent / ram_fee_precision) / 100;

const int64_t costwfee = cost / (1.0 - fee_percentage);

buyram(payer, receiver, asset{ costwfee, _gstateram.ram_price_per_byte.symbol });
}

// PROTON RAM
void system_contract::buyram( const name& payer, const name& receiver, const asset& quant ){
require_auth(payer);
//update_ram_supply();

check(!(_gstateram.ram_price_per_byte.amount <= 0), "Wrong price per byte. Buy RAM is not configured");
check(quant.symbol == _gstateram.ram_price_per_byte.symbol, "must buy ram with " + _gstateram.ram_price_per_byte.symbol.code().to_string());
check(quant.amount > 0, "must purchase a positive amount");
update_ram_supply();

check(quant.symbol == _gstateram.ram_price_per_byte.symbol, "Buy ram using " + _gstateram.ram_price_per_byte.symbol.code().to_string());
check(quant.amount > 0, "must purchase a positive amount");

auto fee = quant;
fee.amount *= ((double)_gstateram.ram_fee_percent / (double)ram_fee_precision) / 100;

Expand All @@ -59,12 +59,11 @@ namespace eosiosystem {
transfer_act.send( payer, ramfee_account, fee, "ram fee" );
}

int64_t bytes_out = quant_after_fee.amount / _gstateram.ram_price_per_byte.amount;
const uint64_t bytes_out = quant_after_fee.amount / _gstateram.ram_price_per_byte.amount;

const auto& market = _rammarket.get(ramcore_symbol.raw(), "ram market does not exist");

check ( market.base.balance.amount >= bytes_out, "Out of RAM" );


_rammarket.modify( market, same_payer, [&]( auto& es ) {
es.base.balance -= asset(bytes_out, ram_symbol);
Expand Down Expand Up @@ -121,11 +120,11 @@ namespace eosiosystem {


// PROTON RAM
void system_contract::sellram( const name& account, int64_t bytes ) {
void system_contract::sellram( const name& account, uint64_t bytes ) {
require_auth( account );
update_ram_supply();
check( bytes > 0, "cannot sell negative byte" );

check(!(bytes == 0), "parameter bytes cannot be zero");

user_resources_table userres( get_self(), account.value );
auto res_itr = userres.find( account.value );
Expand All @@ -137,13 +136,12 @@ namespace eosiosystem {
check( resram_itr != userram.end(), "no purchased ram" );
check( resram_itr->ram >= bytes, "insufficient purchased quota" );

asset tokens_out = asset(0, _gstateram.ram_price_per_byte.symbol);
auto tokens_out = asset(0, _gstateram.ram_price_per_byte.symbol);

tokens_out.amount = bytes * resram_itr->quantity.amount / resram_itr->ram;

auto itr = _rammarket.find(ramcore_symbol.raw());
_rammarket.modify( itr, same_payer, [&]( auto& es ) {
//tokens_out = es.direct_convert(asset(bytes, ram_symbol), _gstateram.ram_price_per_byte.symbol);
es.base.balance += asset(bytes, ram_symbol);
});

Expand Down Expand Up @@ -230,7 +228,7 @@ namespace eosiosystem {
channel_to_rex( ramfee_account, fee );
}

int64_t bytes_out;
int64_t bytes_out = 0;

const auto& market = _rammarket.get(ramcore_symbol.raw(), "ram market does not exist");
_rammarket.modify( market, same_payer, [&]( auto& es ) {
Expand Down
6 changes: 2 additions & 4 deletions contracts/eosio.system/src/eosio.system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace eosiosystem {


// PROTON RAM
void system_contract::ramlimitset( const name& account, int64_t ramlimit ) {
void system_contract::ramlimitset( const name& account, uint64_t ramlimit ) {
require_auth(permission_level("admin.proton"_n, "light"_n));

userram_table userram( get_self(), account.value );
Expand All @@ -186,11 +186,9 @@ namespace eosiosystem {
});
} else {
userram.modify( resram_itr, account, [&]( auto& res ) {
res.ramlimit += ramlimit;
res.ramlimit = ramlimit;
});
}


}

void system_contract::setacctram( const name& account, const std::optional<int64_t>& ram_bytes ) {
Expand Down

0 comments on commit 4745736

Please sign in to comment.