Skip to content

Commit

Permalink
Merge pull request #124 from fioprotocol/feature/FIP-21-Staking-fio-c…
Browse files Browse the repository at this point in the history
…ontracts-develop-03212021

FIP-21 -- Implement FIO staking.
  • Loading branch information
ericbutz authored Jul 13, 2021
2 parents 5634ce5 + 5e7c4a1 commit e8dc9fb
Show file tree
Hide file tree
Showing 18 changed files with 1,272 additions and 80 deletions.
1 change: 1 addition & 0 deletions contracts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ add_subdirectory(fio.fee)
add_subdirectory(fio.request.obt)
add_subdirectory(fio.tpid)
add_subdirectory(fio.treasury)
add_subdirectory(fio.staking)
4 changes: 2 additions & 2 deletions contracts/fio.address/fio.address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1694,9 +1694,9 @@ namespace fioio {
void decrcounter(const string &fio_address, const int32_t &step) {

check(step > 0, "step must be greater than 0");
check((has_auth(AddressContract) || has_auth(TokenContract) || has_auth(TREASURYACCOUNT) ||
check((has_auth(AddressContract) || has_auth(TokenContract) || has_auth(TREASURYACCOUNT) || has_auth(STAKINGACCOUNT) ||
has_auth(REQOBTACCOUNT) || has_auth(SYSTEMACCOUNT) || has_auth(FeeContract)),
"missing required authority of fio.address, fio.token, fio.fee, fio.treasury, fio.reqobt, fio.system");
"missing required authority of fio.address, fio.token, fio.fee, fio.treasury, fio.reqobt, fio.system, fio.staking ");

auto namesbyname = fionames.get_index<"byname"_n>();
auto fioname_iter = namesbyname.find(string_to_uint128_hash(fio_address.c_str()));
Expand Down
2 changes: 2 additions & 0 deletions contracts/fio.common/fio.accounts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ namespace fioio {

static const name REQOBTACCOUNT = name("fio.reqobt");
static const name FeeContract = name("fio.fee");
static const name StakingContract = name("fio.staking");
static const name AddressContract = name("fio.address");
static const name TPIDContract = name("fio.tpid");
static const name TokenContract = name("fio.token");
static const name FOUNDATIONACCOUNT = name("tw4tjkmo4eyd");
static const name TREASURYACCOUNT = name("fio.treasury");
static const name STAKINGACCOUNT = name("fio.staking");
static const name FIOSYSTEMACCOUNT= name("fio.system");
static const name FIOACCOUNT = name("fio");

Expand Down
67 changes: 62 additions & 5 deletions contracts/fio.common/fio.common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
#define MAXBPS 42
#define MAXACTIVEBPS 21
#define DEFAULTBUNDLEAMT 100
//staking
#define COMBINEDTOKENPOOLMINIMUM 1000000000000000 // 1M FIO SUFS
#define STAKINGREWARDSRESERVEMAXIMUM 25000000000000000 // 25M FIO SUFS.
#define DAILYSTAKINGMINTTHRESHOLD 25000000000000 //25k FIO threshold for MINTING staking rewards.

#define STAKE_FIO_TOKENS_ENDPOINT "stake_fio_tokens"
#define UNSTAKE_FIO_TOKENS_ENDPOINT "unstake_fio_tokens"
#define REGISTER_ADDRESS_ENDPOINT "register_fio_address"
#define REGISTER_DOMAIN_ENDPOINT "register_fio_domain"
#define RENEW_ADDRESS_ENDPOINT "renew_fio_address"
Expand Down Expand Up @@ -235,6 +241,25 @@ namespace fioio {

typedef singleton<"bounties"_n, bounty> bounties_table;

//this will call update tpid in the tpid contract,
//add the info to the tpid table for this TPID and also set up the auto proxy if needed.
void set_auto_proxy(const string &tpid, const uint64_t &amount, const name &auth, const name &actor){
fionames_table fionames(AddressContract, AddressContract.value);
uint128_t fioaddhash = string_to_uint128_hash(tpid.c_str());

auto namesbyname = fionames.get_index<"byname"_n>();
auto fionamefound = namesbyname.find(fioaddhash);

if (fionamefound != namesbyname.end()) {
action(
permission_level{auth, "active"_n},
TPIDContract,
"updatetpid"_n,
std::make_tuple(tpid, actor, amount)
).send();
}
}

void process_rewards(const string &tpid, const uint64_t &amount, const name &auth, const name &actor) {

action(
Expand Down Expand Up @@ -282,15 +307,27 @@ namespace fioio {
permission_level{auth, "active"_n},
TREASURYACCOUNT,
"bprewdupdate"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .85))
std::make_tuple((uint64_t)(static_cast<double>(amount) * .60))
).send();
action(
permission_level{auth, "active"_n},
STAKINGACCOUNT,
"incgrewards"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .25))
).send();

} else {
action(
permission_level{auth, "active"_n},
TREASURYACCOUNT,
"bprewdupdate"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .95))
std::make_tuple((uint64_t)(static_cast<double>(amount) * .70))
).send();
action(
permission_level{auth, "active"_n},
STAKINGACCOUNT,
"incgrewards"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .25))
).send();
}
}
Expand Down Expand Up @@ -344,15 +381,27 @@ namespace fioio {
permission_level{auth, "active"_n},
TREASURYACCOUNT,
"bppoolupdate"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .85))
std::make_tuple((uint64_t)(static_cast<double>(amount) * .60))
).send();
action(
permission_level{auth, "active"_n},
STAKINGACCOUNT,
"incgrewards"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .25))
).send();
} else {

action(
permission_level{auth, "active"_n},
TREASURYACCOUNT,
"bppoolupdate"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .95))
std::make_tuple((uint64_t)(static_cast<double>(amount) * .70))
).send();
action(
permission_level{auth, "active"_n},
STAKINGACCOUNT,
"incgrewards"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .25))
).send();
}
}
Expand All @@ -366,7 +415,13 @@ namespace fioio {
permission_level{actor, "active"_n},
TREASURYACCOUNT,
"bprewdupdate"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .95))
std::make_tuple((uint64_t)(static_cast<double>(amount) * .70))
).send();
action(
permission_level{actor, "active"_n},
STAKINGACCOUNT,
"incgrewards"_n,
std::make_tuple((uint64_t)(static_cast<double>(amount) * .25))
).send();

action(
Expand Down Expand Up @@ -404,6 +459,8 @@ namespace fioio {
static const uint64_t INITIALACCOUNTRAM = 25600;
static const uint64_t ADDITIONALRAMBPDESCHEDULING = 25600;

static const uint64_t STAKEFIOTOKENSRAM = 1024; //integrated.
static const uint64_t UNSTAKEFIOTOKENSRAM = 1024; //integrated.
static const uint64_t REGDOMAINRAM = 2560; //integrated.
static const uint64_t REGADDRESSRAM = 2560; //integrated.
static const uint64_t ADDADDRESSRAM = 512; //integrated.
Expand Down
14 changes: 14 additions & 0 deletions contracts/fio.staking/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
add_contract(fio.staking fio.staking ${CMAKE_CURRENT_SOURCE_DIR}/fio.staking.cpp)

target_include_directories(fio.staking
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../fio.system/include
${CMAKE_CURRENT_SOURCE_DIR}/../
${CMAKE_CURRENT_SOURCE_DIR}/../fio.token/include
)


set_target_properties(fio.staking
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
224 changes: 224 additions & 0 deletions contracts/fio.staking/fio.staking.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT Thu Jun 13 20:29:09 2019",
"version": "eosio::abi/1.1",
"structs": [

{
"name": "global_staking_state",
"base": "",
"fields": [
{
"name": "staked_token_pool",
"type": "uint64"
},
{
"name": "combined_token_pool",
"type": "uint64"
},
{
"name": "rewards_token_pool",
"type": "uint64"
},
{
"name": "global_srp_count",
"type": "uint64"
},
{
"name": "daily_staking_rewards",
"type": "uint64"
},
{
"name": "staking_rewards_reserves_minted",
"type": "uint64"
}
]
},{
"name": "account_staking_info",
"base": "",
"fields": [
{
"name": "id",
"type": "uint64"
},
{
"name": "account",
"type": "name"
},
{
"name": "total_srp",
"type": "uint64"
},
{
"name": "total_staked_fio",
"type": "uint64"
}
]
},{
"name": "decgstake",
"base": "",
"fields": [
{
"name": "fiostakedsufs",
"type": "int64"
},
{
"name": "fiorewardedsufs",
"type": "int64"
},
{
"name": "srpcountsus",
"type": "int64"
}
]
},{
"name": "incgstake",
"base": "",
"fields": [
{
"name": "fiostakedsufs",
"type": "int64"
},
{
"name": "srpcountsus",
"type": "int64"
}
]
},{
"name": "incacctstake",
"base": "",
"fields": [
{
"name": "owner",
"type": "name"
},
{
"name": "fiostakedsufs",
"type": "int64"
},
{
"name": "srpaawardedsus",
"type": "int64"
}
]
},{
"name": "decacctstake",
"base": "",
"fields": [
{
"name": "owner",
"type": "name"
},
{
"name": "fiostakedsufs",
"type": "int64"
},
{
"name": "srprewardedsus",
"type": "int64"
}
]
},{
"name": "stakefio",
"base": "",
"fields": [
{
"name": "fio_address",
"type": "string"
},
{
"name": "amount",
"type": "int64"
},
{
"name": "max_fee",
"type": "int64"
},
{
"name": "tpid",
"type": "string"
},
{
"name": "actor",
"type": "name"
}
]
},{
"name": "unstakefio",
"base": "",
"fields": [
{
"name": "fio_address",
"type": "string"
},
{
"name": "amount",
"type": "int64"
},
{
"name": "max_fee",
"type": "int64"
},
{
"name": "tpid",
"type": "string"
},
{
"name": "actor",
"type": "name"
}
]
}
],
"types": [],
"actions": [
{
"name": "decgstake",
"type": "decgstake",
"ricardian_contract": ""
},
{
"name": "incgstake",
"type": "incgstake",
"ricardian_contract": ""
},
{
"name": "incacctstake",
"type": "incacctstake",
"ricardian_contract": ""
},
{
"name": "decacctstake",
"type": "decacctstake",
"ricardian_contract": ""
},
{
"name": "stakefio",
"type": "stakefio",
"ricardian_contract": ""
},
{
"name": "unstakefio",
"type": "unstakefio",
"ricardian_contract": ""
}
],
"tables": [
{
"name": "staking",
"type": "global_staking_state",
"index_type": "i64",
"key_names": [],
"key_types": []
},
{
"name": "accountstake",
"type": "account_staking_info",
"index_type": "i64",
"key_names": [],
"key_types": []
}
],
"ricardian_clauses": [],
"variants": [],
"abi_extensions": []
}
Loading

0 comments on commit e8dc9fb

Please sign in to comment.