diff --git a/src/arns.lua b/src/arns.lua index 0865b5c..44f0d59 100644 --- a/src/arns.lua +++ b/src/arns.lua @@ -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 = {}, @@ -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") @@ -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) diff --git a/src/constants.lua b/src/constants.lua index e29771d..a5b264d 100644 --- a/src/constants.lua +++ b/src/constants.lua @@ -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 = { diff --git a/src/gar.lua b/src/gar.lua index e2f9b9b..db9535b 100644 --- a/src/gar.lua +++ b/src/gar.lua @@ -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 = {} @@ -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