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

referals program rc #24

Merged
merged 4 commits into from
Jul 18, 2022
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
1,744 changes: 1,744 additions & 0 deletions ProxyAdmin.json

Large diffs are not rendered by default.

42 changes: 9 additions & 33 deletions build/contracts/ProxyAdmin.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,14 @@
"ast": {
"absolutePath": "contracts/upgradeability/ProxyAdmin.sol",
"exportedSymbols": {
"ProxyAdmin": [
6019
]
"ProxyAdmin": [6019]
},
"id": 6020,
"nodeType": "SourceUnit",
"nodes": [
{
"id": 5898,
"literals": [
"solidity",
"^",
"0.5",
".0"
],
"literals": ["solidity", "^", "0.5", ".0"],
"nodeType": "PragmaDirective",
"src": "0:23:40"
},
Expand Down Expand Up @@ -236,17 +229,12 @@
"src": "282:27:40"
}
],
"contractDependencies": [
5493
],
"contractDependencies": [5493],
"contractKind": "contract",
"documentation": "@title ProxyAdmin\n@dev This contract is the admin of a proxy, and is in charge\nof upgrading it as well as transferring it to another admin.",
"fullyImplemented": true,
"id": 6019,
"linearizedBaseContracts": [
6019,
5493
],
"linearizedBaseContracts": [6019, 5493],
"name": "ProxyAdmin",
"nodeType": "ContractDefinition",
"nodes": [
Expand All @@ -257,10 +245,7 @@
"src": "612:310:40",
"statements": [
{
"assignments": [
5910,
5912
],
"assignments": [5910, 5912],
"declarations": [
{
"constant": false,
Expand Down Expand Up @@ -455,10 +440,7 @@
"id": 5920,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6466,
6467
],
"overloadedDeclarations": [6466, 6467],
"referencedDeclaration": 6466,
"src": "855:7:40",
"typeDescriptions": {
Expand Down Expand Up @@ -682,10 +664,7 @@
"src": "1152:301:40",
"statements": [
{
"assignments": [
5940,
5942
],
"assignments": [5940, 5942],
"declarations": [
{
"constant": false,
Expand Down Expand Up @@ -880,10 +859,7 @@
"id": 5950,
"name": "require",
"nodeType": "Identifier",
"overloadedDeclarations": [
6466,
6467
],
"overloadedDeclarations": [6466, 6467],
"referencedDeclaration": 6466,
"src": "1386:7:40",
"typeDescriptions": {
Expand Down Expand Up @@ -1765,4 +1741,4 @@
"schemaVersion": "3.4.7",
"updatedAt": "2022-06-12T20:11:50.046Z",
"networkType": "ethereum"
}
}
99 changes: 94 additions & 5 deletions contracts/GameManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@ contract GameManager is PausableUpgradeable, Shares {
mapping (address => bool) private allowlist;
uint256 public allowlistLimit;

uint256[42] private ______gm_gap_1;
struct ReferrerSettings {
uint64 discount;
uint64 reward;
}

mapping (address => mapping (address => bool)) referrals;
mapping (address => uint256) public referralsCount;
mapping (address => uint256) public referrerEarned;
mapping (address => ReferrerSettings) public referrerSettings;
mapping (address => address) public referrers;

uint256[37] private ______gm_gap_1;

struct LandData {
uint256 deprecated1;
Expand Down Expand Up @@ -313,8 +324,31 @@ contract GameManager is PausableUpgradeable, Shares {
* Cost of minting for `tokenCount` tokens
* 0xfcee45f4
*/
function _getFee(uint256 tokenCount, address referrer) private view returns (uint256) {
uint256 fee = price * tokenCount;

if (referrer == address(0)) {
referrer = referrers[msg.sender];
}

// no referrer in function args and no referrer stored in past
if (referrer == address(0)) {
return fee;
}

uint64 discount = referrerSettings[referrer].discount;
if (discount == 0) discount = 10; // default value

uint256 feeWithDiscount = fee - fee * discount /100;
return feeWithDiscount;
}

function getFee(uint256 tokenCount) public view returns (uint256) {
return price * tokenCount;
return _getFee(tokenCount, address(0));
}

function getFee(uint256 tokenCount, address referrer) public view returns (uint256) {
return _getFee(tokenCount, referrer);
}

/**
Expand All @@ -341,19 +375,59 @@ contract GameManager is PausableUpgradeable, Shares {
MintBurnInterface(MCAddress).mint(_address, tokenId);
}


/**
* Mints several tokens
*/
function claim(uint256[] calldata tokenIds) external payable nonReentrant whenNotPaused {
function _claim(uint256[] calldata tokenIds, address referrer) internal whenNotPaused {
require (tokenIds.length != 0, "You can't claim 0 tokens");
require (msg.value == getFee(tokenIds.length), 'Wrong claiming fee');

if (referrer != address(0)) {
setReferrer(referrer);
} else if (referrers[msg.sender] != address(0)) {
referrer = referrers[msg.sender];
}

uint256 fee = getFee(tokenIds.length, referrer);

require (msg.value == fee, 'Wrong claiming fee');
updatePool(CLNYAddress);
for (uint8 i = 0; i < tokenIds.length; i++) {
mintLand(msg.sender, tokenIds[i]);
}

if (referrer == address(0)) {
// 0x7162DF6d2c1be22E61b19973Fe4E7D086a2DA6A4 - creatorsDAO
(bool success, ) = payable(0x7162DF6d2c1be22E61b19973Fe4E7D086a2DA6A4).call{ value: msg.value }('');
require(success, 'Transfer failed');
return;
}

// we have a referrer, pay shares to dao and to referrer
uint64 referrerReward = referrerSettings[referrer].reward;
if (referrerReward == 0) referrerReward = 20; // 20% referal reward by default

uint256 referrerValueShare = msg.value * (referrerReward) / 100;
uint256 daoValueShare = msg.value - referrerValueShare;

// 0x7162DF6d2c1be22E61b19973Fe4E7D086a2DA6A4 - creatorsDAO
(bool success, ) = payable(0x7162DF6d2c1be22E61b19973Fe4E7D086a2DA6A4).call{ value: msg.value }('');
(bool success, ) = payable(0x7162DF6d2c1be22E61b19973Fe4E7D086a2DA6A4).call{ value: daoValueShare }('');
require(success, 'Transfer failed');

(success, ) = payable(referrer).call{ value: referrerValueShare }('');
require(success, 'Transfer failed');

referrerEarned[referrer] += referrerValueShare;
}


function claim(uint256[] calldata tokenIds) external payable nonReentrant whenNotPaused {
_claim(tokenIds, address(0));
}


function claim(uint256[] calldata tokenIds, address referrer) external payable nonReentrant whenNotPaused {
_claim(tokenIds, referrer);
}

/**
Expand Down Expand Up @@ -671,6 +745,7 @@ contract GameManager is PausableUpgradeable, Shares {
require (block.timestamp > startCLNYDate, 'CLNY not started');
require (tokenIds.length != 0, 'Empty array');
updatePool(CLNYAddress);

for (uint8 i = 0; i < tokenIds.length; i++) {
require (msg.sender == MintBurnInterface(MCAddress).ownerOf(tokenIds[i]));
uint256 toUser = claimClnyWithoutPoolUpdate(tokenIds[i], CLNYAddress);
Expand Down Expand Up @@ -702,4 +777,18 @@ contract GameManager is PausableUpgradeable, Shares {
landInfo[tokenIds[i]].rewardDebt = accColonyPerShare / 1e12;
}
}

// referrers

function setReferrerSettings(address referrer, uint64 discount, uint64 reward) external onlyDAO {
referrerSettings[referrer] = ReferrerSettings({discount: discount, reward: reward});
}

function setReferrer(address referrer) private {
require(referrer != address(0), "referrer can not be 0");
referrers[msg.sender] = referrer;
referrals[referrer][msg.sender] = true;
referralsCount[referrer]++;
}

}
23 changes: 11 additions & 12 deletions migrations/3_gm_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
* ```
*/

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const { ether, BN } = require('openzeppelin-test-helpers');
const { deployProxy } = require("@openzeppelin/truffle-upgrades");
// const { ether, BN } = require('openzeppelin-test-helpers');

const GameManager = artifacts.require('GameManager');
const AM = artifacts.require('AvatarManager');
const MM = artifacts.require('MissionManager');
const MC = artifacts.require('MC');
const CLNY = artifacts.require('CLNY');
const MartianColonists = artifacts.require('MartianColonists');
const SalesManager = artifacts.require('SalesManager');
const ProxyAdmin = artifacts.require('ProxyAdmin');
const GameManager = artifacts.require("GameManager");
const AM = artifacts.require("AvatarManager");
const MM = artifacts.require("MissionManager");
const MC = artifacts.require("MC");
const CLNY = artifacts.require("CLNY");
const MartianColonists = artifacts.require("MartianColonists");
const SalesManager = artifacts.require("SalesManager");
const ProxyAdmin = artifacts.require("ProxyAdmin");

module.exports = async (deployer, network, addresses) => {
if (network === 'development') {
if (network === "development") {
return; // this file for manual migrations; pass in tests
}
console.log(addresses);

};
Loading