From 4a4c04434f96f7db2d9db9f7ab4b7f7199d8e2e7 Mon Sep 17 00:00:00 2001 From: rdewilder Date: Sun, 31 Mar 2024 01:43:03 -0400 Subject: [PATCH 1/3] add buyramburn --- .../include/eosio.system/eosio.system.hpp | 12 +++++++++ .../eosio.system/src/delegate_bandwidth.cpp | 14 +++++++++++ tests/eosio.system_ram_tests.cpp | 25 +++++++++++++++++++ tests/eosio.system_tester.hpp | 5 ++++ 4 files changed, 56 insertions(+) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index d3dfc4b7..a817f574 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -1198,6 +1198,17 @@ namespace eosiosystem { [[eosio::action]] action_return_ramtransfer ramburn( const name& owner, int64_t bytes, const std::string& memo ); + /** + * Buy RAM and immediately burn RAM. + * An inline transfer from payer to system contract of tokens will be executed. + * + * @param payer - the payer of buy RAM & burn. + * @param quantity - the quantity of tokens to buy RAM & burn with. + * @param memo - the memo string to accompany the transaction. + */ + [[eosio::action]] + action_return_buyram buyramburn( const name& payer, const asset& quantity, const std::string& memo ); + /** * Logging for ram changes * @@ -1510,6 +1521,7 @@ namespace eosiosystem { using logsellram_action = eosio::action_wrapper<"logsellram"_n, &system_contract::logsellram>; using ramtransfer_action = eosio::action_wrapper<"ramtransfer"_n, &system_contract::ramtransfer>; using ramburn_action = eosio::action_wrapper<"ramburn"_n, &system_contract::ramburn>; + using buyramburn_action = eosio::action_wrapper<"buyramburn"_n, &system_contract::buyramburn>; using logramchange_action = eosio::action_wrapper<"logramchange"_n, &system_contract::logramchange>; using refund_action = eosio::action_wrapper<"refund"_n, &system_contract::refund>; using regproducer_action = eosio::action_wrapper<"regproducer"_n, &system_contract::regproducer>; diff --git a/contracts/eosio.system/src/delegate_bandwidth.cpp b/contracts/eosio.system/src/delegate_bandwidth.cpp index f9696edc..65ff7099 100644 --- a/contracts/eosio.system/src/delegate_bandwidth.cpp +++ b/contracts/eosio.system/src/delegate_bandwidth.cpp @@ -179,6 +179,20 @@ namespace eosiosystem { return ramtransfer( owner, null_account, bytes, memo ); } + /** + * This action will buy and then burn the purchased RAM bytes. + */ + action_return_buyram system_contract::buyramburn( const name& payer, const asset& quantity, const std::string& memo ) { + require_auth( payer ); + check( quantity.symbol == core_symbol(), "quantity must be core token" ); + check( quantity.amount > 0, "quantity must be positive" ); + + const auto return_buyram = buyram( payer, payer, quantity ); + ramtransfer( payer, null_account, return_buyram.bytes_purchased, memo ); + + return return_buyram; + } + [[eosio::action]] void system_contract::logramchange( const name& owner, int64_t bytes, int64_t ram_bytes ) { diff --git a/tests/eosio.system_ram_tests.cpp b/tests/eosio.system_ram_tests.cpp index b5b3e298..24202442 100644 --- a/tests/eosio.system_ram_tests.cpp +++ b/tests/eosio.system_ram_tests.cpp @@ -161,6 +161,31 @@ BOOST_FIXTURE_TEST_CASE( ram_burn, eosio_system_tester ) try { } FC_LOG_AND_RETHROW() +// buyramburn +BOOST_FIXTURE_TEST_CASE( buy_ram_burn, eosio_system_tester ) try { + const std::vector accounts = { "alice"_n }; + const account_name alice = accounts[0]; + const account_name null_account = "eosio.null"_n; + + create_accounts_with_resources( accounts ); + transfer( config::system_account_name, alice, core_sym::from_string("100.0000"), config::system_account_name ); + + BOOST_REQUIRE_EQUAL( success(), buyrambytes( alice, alice, 10000 ) ); + BOOST_REQUIRE_EQUAL( success(), buyrambytes( alice, null_account, 10000 ) ); + + const uint64_t null_before_buyramburn = get_total_stake( null_account )["ram_bytes"].as_uint64(); + const uint64_t alice_before_buyramburn = get_total_stake( alice )["ram_bytes"].as_uint64(); + const asset initial_alice_balance = get_balance(alice); + const asset ten_core_token = core_sym::from_string("10.0000"); + + // buy ram burn action + BOOST_REQUIRE_EQUAL( success(), buyramburn( alice, ten_core_token, "burn RAM burn memo" ) ); + const uint64_t alice_after_buyramburn = get_total_stake( alice )["ram_bytes"].as_uint64(); + const uint64_t null_after_buyramburn = get_total_stake( null_account )["ram_bytes"].as_uint64(); + BOOST_REQUIRE_EQUAL( alice_before_buyramburn, alice_after_buyramburn ); + BOOST_REQUIRE_EQUAL( true, null_before_buyramburn < null_after_buyramburn ); + BOOST_REQUIRE_EQUAL( initial_alice_balance - ten_core_token, get_balance(alice)); +} FC_LOG_AND_RETHROW() // buyramself BOOST_FIXTURE_TEST_CASE( buy_ram_self, eosio_system_tester ) try { diff --git a/tests/eosio.system_tester.hpp b/tests/eosio.system_tester.hpp index 93a8eb24..4ab85bcd 100644 --- a/tests/eosio.system_tester.hpp +++ b/tests/eosio.system_tester.hpp @@ -428,6 +428,11 @@ class eosio_system_tester : public TESTER { return ramburn(account_name(owner), bytes, memo); } + action_result buyramburn( const name& payer, const asset& quantity, const std::string& memo) + { + return push_action(payer, "buyramburn"_n, mvo()("payer", payer)("quantity", quantity)("memo", memo)); + } + void validate_ramburn_return(const account_name& owner, uint32_t bytes, const std::string& memo, const type_name& type, const std::string& json) { // create hex return from provided json From c3895f2c1ffd2d5d564cef5c6c129e5441bcf351 Mon Sep 17 00:00:00 2001 From: Denis Date: Sun, 31 Mar 2024 22:54:54 +0200 Subject: [PATCH 2/3] Update delegate_bandwidth.cpp --- contracts/eosio.system/src/delegate_bandwidth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/eosio.system/src/delegate_bandwidth.cpp b/contracts/eosio.system/src/delegate_bandwidth.cpp index 65ff7099..2db57acd 100644 --- a/contracts/eosio.system/src/delegate_bandwidth.cpp +++ b/contracts/eosio.system/src/delegate_bandwidth.cpp @@ -188,7 +188,7 @@ namespace eosiosystem { check( quantity.amount > 0, "quantity must be positive" ); const auto return_buyram = buyram( payer, payer, quantity ); - ramtransfer( payer, null_account, return_buyram.bytes_purchased, memo ); + ramburn( payer, return_buyram.bytes_purchased, memo ); return return_buyram; } From 267f7846b342322e9d6f7b4ada1ff7de6ad5ef7c Mon Sep 17 00:00:00 2001 From: rdewilder Date: Mon, 1 Apr 2024 21:20:28 -0400 Subject: [PATCH 3/3] added ricardian for buyramburn --- .../ricardian/eosio.system.contracts.md.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/contracts/eosio.system/ricardian/eosio.system.contracts.md.in b/contracts/eosio.system/ricardian/eosio.system.contracts.md.in index d82a209b..3890f490 100644 --- a/contracts/eosio.system/ricardian/eosio.system.contracts.md.in +++ b/contracts/eosio.system/ricardian/eosio.system.contracts.md.in @@ -454,6 +454,21 @@ Burn {{bytes}} bytes of unused RAM from account {{owner}}. {{memo}} {{/if}} +

buyramburn

+ +--- +spec_version: "0.2.0" +title: Buy and Burn RAM +summary: 'Buy and immediately Burn {{quantity}} of RAM from {{nowrap payer}}' +icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@ +--- + +Buy and Burn {{quantity}} of RAM from account {{payer}}. + +{{#if memo}}There is a memo attached to the action stating: +{{memo}} +{{/if}} +

sellrex

---