Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

First pass at adding referral fee #73

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 deletions contracts/ETHRegistrarController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ contract ETHRegistrarController is Ownable {
PriceOracle prices;
uint public minCommitmentAge;
uint public maxCommitmentAge;
uint public referralFee;

mapping(bytes32=>uint) public commitments;

event NameRegistered(string name, bytes32 indexed label, address indexed owner, uint cost, uint expires);
event NameRenewed(string name, bytes32 indexed label, uint cost, uint expires);
event NewPriceOracle(address indexed oracle);
event NewReferralFee(address indexed fee);
event ReferralPaid(address referrer, uint fee);

constructor(BaseRegistrar _base, PriceOracle _prices, uint _minCommitmentAge, uint _maxCommitmentAge) public {
require(_maxCommitmentAge > _minCommitmentAge);
Expand Down Expand Up @@ -85,6 +88,14 @@ contract ETHRegistrarController is Ownable {
registerWithConfig(name, owner, duration, secret, address(0), address(0));
}

function registerWithReferral(string calldata name, address owner, uint duration, bytes32 secret, address referrer) external payable {
registerWithConfig(name, owner, duration, secret, address(0), address(0));

uint fee = referralFee * rentPrice(name, duration) / 1000;
emit ReferralPaid(referrer, fee)
referrer.transfer( fee );
}

function registerWithConfig(string memory name, address owner, uint duration, bytes32 secret, address resolver, address addr) public payable {
bytes32 commitment = makeCommitmentWithConfig(name, owner, secret, resolver, addr);
uint cost = _consumeCommitment(name, duration, commitment);
Expand Down Expand Up @@ -125,6 +136,16 @@ contract ETHRegistrarController is Ownable {
}
}

function renewWithReferral(string calldata name, uint duration, address referrer) external payable {
// standard renewal
renew(name, duration);

// fee is deducted from the revenue
uint fee = referralFee * rentPrice(name, duration) / 1000;
emit ReferralPaid(referrer, fee)
referrer.transfer(fee);
}

function renew(string calldata name, uint duration) external payable {
uint cost = rentPrice(name, duration);
require(msg.value >= cost);
Expand All @@ -139,6 +160,12 @@ contract ETHRegistrarController is Ownable {
emit NameRenewed(name, label, cost, expires);
}

function setReferralFee(uint _referralFee) public onlyOwner {
require(_referralFee <= 1000, "Fee cannot be over 100%");
referralFee = _referralFee;
emit newReferralFee(_referralFee);
}

function setPriceOracle(PriceOracle _prices) public onlyOwner {
prices = _prices;
emit NewPriceOracle(address(prices));
Expand Down