diff --git a/generated/include/mmx/swap_info_t.hxx b/generated/include/mmx/swap_info_t.hxx index 91b420956..307733f59 100644 --- a/generated/include/mmx/swap_info_t.hxx +++ b/generated/include/mmx/swap_info_t.hxx @@ -24,6 +24,8 @@ struct MMX_EXPORT swap_info_t { std::array<::mmx::uint128, 2> fees_paid = {}; std::array<::mmx::uint128, 2> fees_claimed = {}; std::array<::mmx::uint128, 2> user_total = {}; + std::array avg_apy_1d = {}; + std::array avg_apy_7d = {}; static const vnx::Hash64 VNX_TYPE_HASH; static const vnx::Hash64 VNX_CODE_HASH; @@ -70,7 +72,7 @@ struct MMX_EXPORT swap_info_t { template void swap_info_t::accept_generic(T& _visitor) const { - _visitor.template type_begin(8); + _visitor.template type_begin(10); _visitor.type_field("name", 0); _visitor.accept(name); _visitor.type_field("address", 1); _visitor.accept(address); _visitor.type_field("tokens", 2); _visitor.accept(tokens); @@ -79,7 +81,9 @@ void swap_info_t::accept_generic(T& _visitor) const { _visitor.type_field("fees_paid", 5); _visitor.accept(fees_paid); _visitor.type_field("fees_claimed", 6); _visitor.accept(fees_claimed); _visitor.type_field("user_total", 7); _visitor.accept(user_total); - _visitor.template type_end(8); + _visitor.type_field("avg_apy_1d", 8); _visitor.accept(avg_apy_1d); + _visitor.type_field("avg_apy_7d", 9); _visitor.accept(avg_apy_7d); + _visitor.template type_end(10); } diff --git a/generated/src/Node_get_swap_info_return.cpp b/generated/src/Node_get_swap_info_return.cpp index 67694a64b..241384805 100644 --- a/generated/src/Node_get_swap_info_return.cpp +++ b/generated/src/Node_get_swap_info_return.cpp @@ -13,7 +13,7 @@ namespace mmx { const vnx::Hash64 Node_get_swap_info_return::VNX_TYPE_HASH(0x302116742171428ull); -const vnx::Hash64 Node_get_swap_info_return::VNX_CODE_HASH(0x506882e0fdd86d70ull); +const vnx::Hash64 Node_get_swap_info_return::VNX_CODE_HASH(0x985f6fd1925ad73eull); vnx::Hash64 Node_get_swap_info_return::get_type_hash() const { return VNX_TYPE_HASH; @@ -114,7 +114,7 @@ std::shared_ptr Node_get_swap_info_return::static_create_type_cod auto type_code = std::make_shared(); type_code->name = "mmx.Node.get_swap_info.return"; type_code->type_hash = vnx::Hash64(0x302116742171428ull); - type_code->code_hash = vnx::Hash64(0x506882e0fdd86d70ull); + type_code->code_hash = vnx::Hash64(0x985f6fd1925ad73eull); type_code->is_native = true; type_code->is_class = true; type_code->is_return = true; diff --git a/generated/src/Node_get_swaps_return.cpp b/generated/src/Node_get_swaps_return.cpp index c36d79038..0bfd16209 100644 --- a/generated/src/Node_get_swaps_return.cpp +++ b/generated/src/Node_get_swaps_return.cpp @@ -13,7 +13,7 @@ namespace mmx { const vnx::Hash64 Node_get_swaps_return::VNX_TYPE_HASH(0x6c94172788fc0d28ull); -const vnx::Hash64 Node_get_swaps_return::VNX_CODE_HASH(0xf8ce02560bcd40b8ull); +const vnx::Hash64 Node_get_swaps_return::VNX_CODE_HASH(0x22f3be524a088a8dull); vnx::Hash64 Node_get_swaps_return::get_type_hash() const { return VNX_TYPE_HASH; @@ -114,7 +114,7 @@ std::shared_ptr Node_get_swaps_return::static_create_type_code() auto type_code = std::make_shared(); type_code->name = "mmx.Node.get_swaps.return"; type_code->type_hash = vnx::Hash64(0x6c94172788fc0d28ull); - type_code->code_hash = vnx::Hash64(0xf8ce02560bcd40b8ull); + type_code->code_hash = vnx::Hash64(0x22f3be524a088a8dull); type_code->is_native = true; type_code->is_class = true; type_code->is_return = true; diff --git a/generated/src/swap_info_t.cpp b/generated/src/swap_info_t.cpp index 12e877931..cc1cf73db 100644 --- a/generated/src/swap_info_t.cpp +++ b/generated/src/swap_info_t.cpp @@ -14,7 +14,7 @@ namespace mmx { const vnx::Hash64 swap_info_t::VNX_TYPE_HASH(0x7586be908f15ae8ull); -const vnx::Hash64 swap_info_t::VNX_CODE_HASH(0x6968eccd619bc7d6ull); +const vnx::Hash64 swap_info_t::VNX_CODE_HASH(0x49bbbd84c9e78bdbull); vnx::Hash64 swap_info_t::get_type_hash() const { return VNX_TYPE_HASH; @@ -55,6 +55,8 @@ void swap_info_t::accept(vnx::Visitor& _visitor) const { _visitor.type_field(_type_code->fields[5], 5); vnx::accept(_visitor, fees_paid); _visitor.type_field(_type_code->fields[6], 6); vnx::accept(_visitor, fees_claimed); _visitor.type_field(_type_code->fields[7], 7); vnx::accept(_visitor, user_total); + _visitor.type_field(_type_code->fields[8], 8); vnx::accept(_visitor, avg_apy_1d); + _visitor.type_field(_type_code->fields[9], 9); vnx::accept(_visitor, avg_apy_7d); _visitor.type_end(*_type_code); } @@ -68,6 +70,8 @@ void swap_info_t::write(std::ostream& _out) const { _out << ", \"fees_paid\": "; vnx::write(_out, fees_paid); _out << ", \"fees_claimed\": "; vnx::write(_out, fees_claimed); _out << ", \"user_total\": "; vnx::write(_out, user_total); + _out << ", \"avg_apy_1d\": "; vnx::write(_out, avg_apy_1d); + _out << ", \"avg_apy_7d\": "; vnx::write(_out, avg_apy_7d); _out << "}"; } @@ -88,6 +92,8 @@ vnx::Object swap_info_t::to_object() const { _object["fees_paid"] = fees_paid; _object["fees_claimed"] = fees_claimed; _object["user_total"] = user_total; + _object["avg_apy_1d"] = avg_apy_1d; + _object["avg_apy_7d"] = avg_apy_7d; return _object; } @@ -95,6 +101,10 @@ void swap_info_t::from_object(const vnx::Object& _object) { for(const auto& _entry : _object.field) { if(_entry.first == "address") { _entry.second.to(address); + } else if(_entry.first == "avg_apy_1d") { + _entry.second.to(avg_apy_1d); + } else if(_entry.first == "avg_apy_7d") { + _entry.second.to(avg_apy_7d); } else if(_entry.first == "balance") { _entry.second.to(balance); } else if(_entry.first == "fees_claimed") { @@ -138,6 +148,12 @@ vnx::Variant swap_info_t::get_field(const std::string& _name) const { if(_name == "user_total") { return vnx::Variant(user_total); } + if(_name == "avg_apy_1d") { + return vnx::Variant(avg_apy_1d); + } + if(_name == "avg_apy_7d") { + return vnx::Variant(avg_apy_7d); + } return vnx::Variant(); } @@ -158,6 +174,10 @@ void swap_info_t::set_field(const std::string& _name, const vnx::Variant& _value _value.to(fees_claimed); } else if(_name == "user_total") { _value.to(user_total); + } else if(_name == "avg_apy_1d") { + _value.to(avg_apy_1d); + } else if(_name == "avg_apy_7d") { + _value.to(avg_apy_7d); } } @@ -185,11 +205,11 @@ std::shared_ptr swap_info_t::static_create_type_code() { auto type_code = std::make_shared(); type_code->name = "mmx.swap_info_t"; type_code->type_hash = vnx::Hash64(0x7586be908f15ae8ull); - type_code->code_hash = vnx::Hash64(0x6968eccd619bc7d6ull); + type_code->code_hash = vnx::Hash64(0x49bbbd84c9e78bdbull); type_code->is_native = true; type_code->native_size = sizeof(::mmx::swap_info_t); type_code->create_value = []() -> std::shared_ptr { return std::make_shared>(); }; - type_code->fields.resize(8); + type_code->fields.resize(10); { auto& field = type_code->fields[0]; field.is_extended = true; @@ -238,6 +258,18 @@ std::shared_ptr swap_info_t::static_create_type_code() { field.name = "user_total"; field.code = {11, 2, 11, 16, 1}; } + { + auto& field = type_code->fields[8]; + field.data_size = 16; + field.name = "avg_apy_1d"; + field.code = {11, 2, 10}; + } + { + auto& field = type_code->fields[9]; + field.data_size = 16; + field.name = "avg_apy_7d"; + field.code = {11, 2, 10}; + } type_code->build(); return type_code; } @@ -278,8 +310,14 @@ void read(TypeInput& in, ::mmx::swap_info_t& value, const TypeCode* type_code, c } } } - in.read(type_code->total_field_size); + const char* const _buf = in.read(type_code->total_field_size); if(type_code->is_matched) { + if(const auto* const _field = type_code->field_map[8]) { + vnx::read_value(_buf + _field->offset, value.avg_apy_1d, _field->code.data()); + } + if(const auto* const _field = type_code->field_map[9]) { + vnx::read_value(_buf + _field->offset, value.avg_apy_7d, _field->code.data()); + } } for(const auto* _field : type_code->ext_fields) { switch(_field->native_index) { @@ -309,6 +347,9 @@ void write(TypeOutput& out, const ::mmx::swap_info_t& value, const TypeCode* typ else if(code && code[0] == CODE_STRUCT) { type_code = type_code->depends[code[1]]; } + char* const _buf = out.write(32); + vnx::write_value(_buf + 0, value.avg_apy_1d); + vnx::write_value(_buf + 16, value.avg_apy_7d); vnx::write(out, value.name, type_code, type_code->fields[0].code.data()); vnx::write(out, value.address, type_code, type_code->fields[1].code.data()); vnx::write(out, value.tokens, type_code, type_code->fields[2].code.data()); diff --git a/interface/swap_info_t.vni b/interface/swap_info_t.vni index 89b280bd2..7e2a4f3a7 100644 --- a/interface/swap_info_t.vni +++ b/interface/swap_info_t.vni @@ -14,6 +14,9 @@ struct swap_info_t { uint128 fees_claimed[2]; uint128 user_total[2]; + double avg_apy_1d[2]; + double avg_apy_7d[2]; + double get_price() const; diff --git a/src/Node.cpp b/src/Node.cpp index 17af05af8..140cffd53 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -1287,6 +1287,22 @@ swap_info_t Node::get_swap_info(const addr_t& address) const for(size_t i = 0; i < 2 && i < user_total.size(); ++i) { out.user_total[i] = to_uint(user_total[i]); } + const auto height = get_height(); + const auto ref_fees_paid = to_ref(data["fees_paid"]); + { + const auto prev_fees_paid = read_storage_array(address, ref_fees_paid, height - std::min(8640u, height)); + for(size_t i = 0; i < 2; ++i) { + const uint256_t prev_i = i < prev_fees_paid.size() ? to_uint(prev_fees_paid[i]) : uint256_0; + out.avg_apy_1d[i] = uint128(365 * (out.fees_paid[i] - prev_i)).to_double() / out.user_total[i].to_double(); + } + } + { + const auto prev_fees_paid = read_storage_array(address, ref_fees_paid, height - std::min(60480u, height)); + for(size_t i = 0; i < 2; ++i) { + const uint256_t prev_i = i < prev_fees_paid.size() ? to_uint(prev_fees_paid[i]) : uint256_0; + out.avg_apy_7d[i] = uint128(52 * (out.fees_paid[i] - prev_i)).to_double() / out.user_total[i].to_double(); + } + } return out; } diff --git a/www/web-gui/public/swap.js b/www/web-gui/public/swap.js index 74a71892f..fb3fbbe2d 100644 --- a/www/web-gui/public/swap.js +++ b/www/web-gui/public/swap.js @@ -257,6 +257,8 @@ Vue.component('swap-info', { Pool Balance Symbol + APY (last day) + APY (last 7 days) Contract @@ -265,6 +267,8 @@ Vue.component('swap-info', { Token {{ parseFloat( (data.balance[0].value).toPrecision(6) ) }} {{data.symbols[0]}} + {{(data.avg_apy_1d[0] * 100).toFixed(2)}} % + {{(data.avg_apy_7d[0] * 100).toFixed(2)}} %