Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove buy hypha tokens with HUSD function #366

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions include/dao.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,23 +434,13 @@ namespace pricing {
if (get_first_receiver() == pegContract &&
to == get_self() &&
from != get_self()) {
//Buying Hypha tokens with HUSD
if (memo == "buy") {

EOS_CHECK(
quantity.symbol == hypha::common::S_HUSD,
"Buying HYPHA is only available with HUSD tokens"
)

on_husd(from, to, quantity, memo);
}
else if (memo == "redeem") {
if (memo == "redeem") {
onCashTokenTransfer(from, to, quantity, memo);
}
else {
EOS_CHECK(
false,
"No available actions, please specify in the memo string [buy|redeem]"
"No available actions, please specify in the memo string [redeem]"
)
}
}
Expand Down Expand Up @@ -527,8 +517,6 @@ namespace pricing {
std::optional<TimeShare>& lastUsedTimeShare,
int64_t initTimeShare);

void on_husd(const name& from, const name& to, const asset& quantity, const string& memo);

void onCashTokenTransfer(const name& from, const name& to, const asset& quantity, const string& memo);

void onNativeTokenTransfer(const name& from, const name& to, const asset& quantity, const string& memo);
Expand Down
37 changes: 0 additions & 37 deletions src/dao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3117,43 +3117,6 @@ void dao::onRewardTransfer(const name& from, const name& to, const asset& amount
}
}

void dao::on_husd(const name& from, const name& to, const asset& quantity, const string& memo) {

EOS_CHECK(quantity.amount > 0, "quantity must be > 0");
EOS_CHECK(quantity.is_valid(), "quantity invalid");

asset hyphaUsdVal = getSettingOrFail<eosio::asset>(common::HYPHA_USD_VALUE);

EOS_CHECK(
hyphaUsdVal.symbol.precision() == 4,
to_str("Expected hypha_usd_value precision to be 4, but got:", hyphaUsdVal.symbol.precision())
);

double factor = (hyphaUsdVal.amount / 10000.0);

EOS_CHECK(common::S_HUSD.precision() == common::S_HYPHA.precision(), "unexpected precision mismatch");

asset hyphaAmount = asset(quantity.amount / factor, common::S_HYPHA);

auto hyphaID = getDAOID("hypha"_n);

EOS_CHECK(
hyphaID.has_value(),
"Missing hypha DAO entry"
);

auto daoSettings = getSettingsDocument(*hyphaID);

auto daoTokens = AssetBatch{
.reward = daoSettings->getOrFail<asset>(common::REWARD_TOKEN),
.peg = daoSettings->getOrFail<asset>(common::PEG_TOKEN),
.voice = daoSettings->getOrFail<asset>(common::VOICE_TOKEN)
};

std::unique_ptr<Payer> payer = std::unique_ptr<Payer>(PayerFactory::Factory(*this, daoSettings, hyphaAmount.symbol, eosio::name{ 0 }, daoTokens));
payer->pay(from, hyphaAmount, string("Buy HYPHA for " + quantity.to_string()));
}

void dao::updateDaoURL(name dao, const Content::FlexValue& newURL)
{
auto newUrlCon = Content{to_str(common::URL, "_", dao), newURL};
Expand Down
Loading