Skip to content

Commit

Permalink
Initial implementation attempt (not accurate)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Feb 12, 2025
1 parent 6d9bc9c commit 38b1ccf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions contracts/api/include/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ struct get_account_response
eosiosystem::voter_info vote;
};

struct get_rex_apy_response
{
double apy;
uint64_t total_lendable;
uint64_t current_rate_of_increase;
uint64_t proceeds;
};

struct get_available_response
{
name account;
Expand Down Expand Up @@ -82,6 +90,9 @@ class [[eosio::contract("api")]] api : public contract
[[eosio::action, eosio::read_only]] get_available_response available(const name account);
using available_action = action_wrapper<"available"_n, &api::available>;

[[eosio::action, eosio::read_only]] get_rex_apy_response rexapy();
using rexapy_action = action_wrapper<"rexapy"_n, &api::rexapy>;

[[eosio::action, eosio::read_only]] std::vector<asset>
balances(const name account, const std::vector<token_definition> tokens, const bool zerobalances);
using balances_action = action_wrapper<"balances"_n, &api::balances>;
Expand Down Expand Up @@ -122,6 +133,9 @@ class [[eosio::contract("api")]] api : public contract
[[eosio::action, eosio::read_only]] eosiosystem::rex_fund rexfund(const name account);
using rexfund_action = action_wrapper<"rexfund"_n, &api::rexfund>;

[[eosio::action, eosio::read_only]] eosiosystem::rex_return_pool rexretpool();
using rexretpool_action = action_wrapper<"rexretpool"_n, &api::rexretpool>;

[[eosio::action, eosio::read_only]] eosiosystem::voter_info votes(const name account);
using vote_action = action_wrapper<"votes"_n, &api::votes>;

Expand All @@ -136,6 +150,7 @@ class [[eosio::contract("api")]] api : public contract
eosiosystem::eosio_global_state get_global(const config_row config);
eosiosystem::exchange_state get_rammarket(const config_row config);
eosiosystem::rex_pool get_rex_pool(const config_row config);
eosiosystem::rex_return_pool get_rex_return_pool(const config_row config);
eosiosystem::powerup_state get_powerup(const config_row config);
eosiosystem::refund_request get_refund_request(const config_row config, const name account);
eosiosystem::rex_balance get_rex_balance(const config_row config, const name account);
Expand Down
31 changes: 31 additions & 0 deletions contracts/api/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,37 @@ api::balances(const name account, const std::vector<token_definition> tokens, co
return get_contract_hash(config, account);
}

eosiosystem::rex_return_pool api::get_rex_return_pool(const api::config_row config)
{
eosiosystem::rex_return_pool rexretpool;
eosiosystem::rex_return_pool_table rexretpool_table(config.system_contract, config.system_contract.value);
auto rexretpool_itr = rexretpool_table.begin();
if (rexretpool_itr != rexretpool_table.end()) {
rexretpool = *rexretpool_itr;
}
return rexretpool;
}

[[eosio::action, eosio::read_only]] eosiosystem::rex_return_pool api::rexretpool()
{
return get_rex_return_pool(get_config());
}

[[eosio::action, eosio::read_only]] get_rex_apy_response api::rexapy()
{
// NYI: CALCULATION INCORRECT
auto config = get_config();
auto pool = get_rex_pool(config);
auto retpool = get_rex_return_pool(config);
const auto apy = (((proceeds + current_rate_of_increase) / 30 * 365) / total_lendable * 100);
return {
.apy = apy,
.total_lendable = total_lendable,
.current_rate_of_increase = current_rate_of_increase,
.proceeds = proceeds,
};
}

[[eosio::action]] void api::setconfig(const name system_contract,
const name system_contract_msig,
const name system_token_contract,
Expand Down

0 comments on commit 38b1ccf

Please sign in to comment.