Skip to content

Commit

Permalink
Adding circulating (supply - locked)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Jan 31, 2025
1 parent 5b72cfa commit fe25a54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 5 additions & 4 deletions contracts/api/include/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ struct token_definition

struct token_supply
{
token_definition def = {.contract = name("eosio.token"), .symbol = symbol("EOS", 4)};
asset locked = asset(0, symbol("EOS", 4));
asset max = asset(0, symbol("EOS", 4));
asset supply = asset(0, symbol("EOS", 4));
token_definition def = {.contract = name("eosio.token"), .symbol = symbol("EOS", 4)};
asset circulating = asset(0, symbol("EOS", 4));
asset locked = asset(0, symbol("EOS", 4));
asset max = asset(0, symbol("EOS", 4));
asset supply = asset(0, symbol("EOS", 4));
};

struct get_network_response
Expand Down
15 changes: 9 additions & 6 deletions contracts/api/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,26 @@ token_supply api::get_token_supply(const token_definition def)
auto config = _config.get_or_default();

token_supply ts = {
.def = def,
.locked = asset(0, def.symbol),
.max = asset(0, def.symbol),
.supply = asset(0, def.symbol),
.def = def,
.circulating = asset(0, def.symbol),
.locked = asset(0, def.symbol),
.max = asset(0, def.symbol),
.supply = asset(0, def.symbol),
};

eosio::token::stats stats_table(def.contract, def.symbol.code().raw());
auto stats_itr = stats_table.find(def.symbol.code().raw());
if (stats_itr != stats_table.end()) {
ts.supply = stats_itr->supply;
ts.max = stats_itr->max_supply;
ts.supply = stats_itr->supply;
ts.max = stats_itr->max_supply;
ts.circulating = ts.supply;
}

eosio::token::accounts _accounts(def.contract, config.system_contract.value);
auto balance_itr = _accounts.find(def.symbol.code().raw());
if (balance_itr != _accounts.end()) {
ts.locked = balance_itr->balance;
ts.circulating -= ts.locked;
}

return ts;
Expand Down

0 comments on commit fe25a54

Please sign in to comment.