-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix(primary-names): add patch for adding demand factor data to primar… #408
Conversation
…nction and update the handler
baseNameOwner = record.processId, | ||
fundingPlan = fundingPlan, | ||
fundingResult = fundingResult, | ||
df = demand.getDemandFactorInfo(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
includes the df data
|
||
local function Send(msg, response) | ||
if msg.reply then | ||
--- Reference: https://github.com/permaweb/aos/blob/main/blueprints/patch-legacy-reply.lua | ||
msg.reply(response) | ||
else | ||
ao.send(response) | ||
end | ||
end | ||
|
||
local function assertValidFundFrom(fundFrom) | ||
if fundFrom == nil then | ||
return | ||
end | ||
local validFundFrom = utils.createLookupTable({ "any", "balance", "stakes" }) | ||
assert(validFundFrom[fundFrom], "Invalid fund from type. Must be one of: any, balance, stakes") | ||
end | ||
|
||
local function addPrimaryNameCounts(ioEvent) | ||
ioEvent:addField("Total-Primary-Names", utils.lengthOfTable(primaryNames.getUnsafePrimaryNames())) | ||
ioEvent:addField("Total-Primary-Name-Requests", utils.lengthOfTable(primaryNames.getUnsafePrimaryNameRequests())) | ||
end | ||
|
||
local function adjustSuppliesForFundingPlan(fundingPlan, rewardForInitiator) | ||
if not fundingPlan then | ||
return | ||
end | ||
rewardForInitiator = rewardForInitiator or 0 | ||
local totalActiveStakesUsed = utils.reduce(fundingPlan.stakes, function(acc, _, stakeSpendingPlan) | ||
return acc + stakeSpendingPlan.delegatedStake | ||
end, 0) | ||
local totalWithdrawStakesUsed = utils.reduce(fundingPlan.stakes, function(acc, _, stakeSpendingPlan) | ||
return acc | ||
+ utils.reduce(stakeSpendingPlan.vaults, function(acc2, _, vaultBalance) | ||
return acc2 + vaultBalance | ||
end, 0) | ||
end, 0) | ||
LastKnownStakedSupply = LastKnownStakedSupply - totalActiveStakesUsed | ||
LastKnownWithdrawSupply = LastKnownWithdrawSupply - totalWithdrawStakesUsed | ||
LastKnownCirculatingSupply = LastKnownCirculatingSupply - fundingPlan.balance + rewardForInitiator | ||
end | ||
|
||
local function addResultFundingPlanFields(ioEvent, result) | ||
ioEvent:addFieldsWithPrefixIfExist(result.fundingPlan, "FP-", { "balance" }) | ||
local fundingPlanVaultsCount = 0 | ||
local fundingPlanStakesAmount = utils.reduce( | ||
result.fundingPlan and result.fundingPlan.stakes or {}, | ||
function(acc, _, delegation) | ||
return acc | ||
+ delegation.delegatedStake | ||
+ utils.reduce(delegation.vaults, function(acc2, _, vaultAmount) | ||
fundingPlanVaultsCount = fundingPlanVaultsCount + 1 | ||
return acc2 + vaultAmount | ||
end, 0) | ||
end, | ||
0 | ||
) | ||
if fundingPlanStakesAmount > 0 then | ||
ioEvent:addField("FP-Stakes-Amount", fundingPlanStakesAmount) | ||
end | ||
if fundingPlanVaultsCount > 0 then | ||
ioEvent:addField("FP-Vaults-Count", fundingPlanVaultsCount) | ||
end | ||
local newWithdrawVaultsTallies = utils.reduce( | ||
result.fundingResult and result.fundingResult.newWithdrawVaults or {}, | ||
function(acc, _, newWithdrawVault) | ||
acc.totalBalance = acc.totalBalance | ||
+ utils.reduce(newWithdrawVault, function(acc2, _, vault) | ||
acc.count = acc.count + 1 | ||
return acc2 + vault.balance | ||
end, 0) | ||
return acc | ||
end, | ||
{ count = 0, totalBalance = 0 } | ||
) | ||
if newWithdrawVaultsTallies.count > 0 then | ||
ioEvent:addField("New-Withdraw-Vaults-Count", newWithdrawVaultsTallies.count) | ||
ioEvent:addField("New-Withdraw-Vaults-Total-Balance", newWithdrawVaultsTallies.totalBalance) | ||
end | ||
adjustSuppliesForFundingPlan(result.fundingPlan, result.returnedName and result.returnedName.rewardForInitiator) | ||
end | ||
|
||
--- @param ioEvent ARIOEvent | ||
--- @param primaryNameResult CreatePrimaryNameResult|PrimaryNameRequestApproval | ||
local function addPrimaryNameRequestData(ioEvent, primaryNameResult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, these all need to be added as they are not available in the global scope
-- add the demand factor data to the ioEvent | ||
if primaryNameResult.df and type(primaryNameResult.df) == "table" then | ||
ioEvent:addField("DF-Trailing-Period-Purchases", (primaryNameResult.df.trailingPeriodPurchases or {})) | ||
ioEvent:addField("DF-Trailing-Period-Revenues", (primaryNameResult.df.trailingPeriodRevenues or {})) | ||
ioEvent:addFieldsWithPrefixIfExist(primaryNameResult.df, "DF-", { | ||
"currentPeriod", | ||
"currentDemandFactor", | ||
"consecutivePeriodsWithMinDemandFactor", | ||
"revenueThisPeriod", | ||
"purchasesThisPeriod", | ||
}) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the DF data is now included in the event
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #408 +/- ##
========================================
Coverage 91.35% 91.35%
========================================
Files 10 10
Lines 3181 3182 +1
========================================
+ Hits 2906 2907 +1
Misses 275 275 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…y name requests
Steps to test: