Skip to content

Commit

Permalink
feat: init arns discount elgibility and fee caclulation PE-7060
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Nov 5, 2024
1 parent 75f5fa6 commit 96f1529
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/arns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local balances = require("balances")
local demand = require("demand")
local arns = {}
local Auction = require("auctions")
local gar = require("gar")

NameRegistry = NameRegistry or {
reserved = {},
Expand All @@ -25,8 +26,15 @@ function arns.buyRecord(name, purchaseType, years, from, timestamp, processId)

local baseRegistrationFee = demand.baseFeeForNameLength(#name)

local totalRegistrationFee =
arns.calculateRegistrationFee(purchaseType, baseRegistrationFee, years, demand.getDemandFactor())
local eligibleForArNSDiscount = gar.isEligibleForArNSDiscount(from)

local totalRegistrationFee = arns.calculateRegistrationFee(
purchaseType,
baseRegistrationFee,
years,
demand.getDemandFactor(),
eligibleForArNSDiscount
)

if balances.getBalance(from) < totalRegistrationFee then
error("Insufficient balance")
Expand Down Expand Up @@ -252,12 +260,20 @@ function arns.calculatePermabuyFee(baseFee, demandFactor)
return math.floor(demandFactor * permabuyPrice)
end

function arns.calculateRegistrationFee(purchaseType, baseFee, years, demandFactor)
function arns.calculateRegistrationFee(purchaseType, baseFee, years, demandFactor, isEligibleForArNSDiscount)
local fee = 0
if purchaseType == "lease" then
return arns.calculateLeaseFee(baseFee, years, demandFactor)
fee = arns.calculateLeaseFee(baseFee, years, demandFactor)
elseif purchaseType == "permabuy" then
return arns.calculatePermabuyFee(baseFee, demandFactor)
fee = arns.calculatePermabuyFee(baseFee, demandFactor)
end

if isEligibleForArNSDiscount then
local discount = math.floor(fee * constants.ARNS_DISCOUNT_PERCENTAGE)
fee = fee - discount
end

return fee
end

function arns.calculateUndernameCost(baseFee, increaseQty, registrationType, years, demandFactor)
Expand Down
3 changes: 3 additions & 0 deletions src/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ constants.UNDERNAME_PERMABUY_FEE_PERCENTAGE = 0.005
constants.oneYearMs = 31536000 * 1000
constants.gracePeriodMs = 14 * 24 * 60 * 60 * 1000 -- 2 weeks
constants.maxLeaseLengthYears = 5
constants.ARNS_DISCOUNT_PERCENTAGE = 0.2
constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_FACTOR = 1
constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_FACTOR = 0.85

-- DEMAND
constants.demandSettings = {
Expand Down
18 changes: 18 additions & 0 deletions src/gar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ function gar.isGatewayActiveBeforeTimestamp(startTimestamp, gateway)
local isNotLeaving = not gar.isGatewayLeaving(gateway)
return didStartBeforeEpoch and isNotLeaving
end

function gar.getActiveGatewaysBeforeTimestamp(startTimestamp)
local gateways = gar.getGateways()
local activeGatewayAddresses = {}
Expand Down Expand Up @@ -981,4 +982,21 @@ function gar.instantOperatorWithdrawal(from, vaultId, currentTimestamp)
}
end

function gar.isEligibleForArNSDiscount(from)
local gateway = gar.getGateway(from)
if gateway == nil then
return false
end

if gateway.weights == nil then
return false
end

local tenureWeight = gateway.weights.tenureWeight
local gatewayPerformanceRatio = gateway.weights.gatewayRewardRatioWeight

return tenureWeight >= constants.ARNS_DISCOUNT_TENURE_WEIGHT_ELIGIBILITY_FACTOR
and gatewayPerformanceRatio >= constants.ARNS_DISCOUNT_GATEWAY_PERFORMANCE_RATIO_ELIGIBILITY_FACTOR
end

return gar

0 comments on commit 96f1529

Please sign in to comment.