Skip to content

Commit

Permalink
added 0.5% devfee
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-triangle committed Jan 31, 2019
1 parent 693add7 commit cd5e307
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
7 changes: 6 additions & 1 deletion config-mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,13 @@
/* Pool fee as a percentage, i.e. 1 is 1% */
"poolFee": 0,

/* Pool development fee as a percentage, i.e. 0.5 is 0.5%
* Please consider leaving this fee in to support ongoing
* development of this open source pool. */
"devFee": 0.5,

/* Network fee in PASC, do not change this */
"devFee": 10.0000
"networkFee": 10.0000
},

/**
Expand Down
7 changes: 6 additions & 1 deletion config-testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,13 @@
/* Pool fee as a percentage, i.e. 1 is 1% */
"poolFee": 0,

/* Pool development fee as a percentage, i.e. 0.5 is 0.5%
* Please consider leaving this fee in to support ongoing
* development of this open source pool. */
"devFee": 0.5,

/* Network fee in PASC, do not change this */
"devFee": 0.2000
"networkFee": 0.2000
},

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ function collectStats() {
//ports: getPublicPorts(config.poolServer.ports),
algorithm: config.algorithm,
hashrateWindow: config.api.hashrateWindow,
fee: config.fees.poolFee,
devFee: config.fees.devFee,
fee: config.fees.poolFee ? config.fees.poolFee : 0,
devFee: config.fees.devFee ? config.fees.devFee : 0.5,
coin: config.coin,
symbol: config.symbol,
depth: config.blockUnlocker.depth,
Expand Down
18 changes: 15 additions & 3 deletions lib/blockUnlocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ function getBlockRpc(blocks, callback) {
return;
}

var networkFee = config.fees.networkFee ? config.fees.networkFee : 10;

block.mature = data.result.maturation < 2 ? 0 : 1;
block.orphaned = data.result.pow.toUpperCase() === block.hash.toUpperCase() ? 0 : 1;
block.unlocked = data.result.maturation >= config.blockUnlocker.depth;
block.pasaReward = Math.floor(parseInt(data.result.reward*10000) - parseInt(config.fees.devFee*10000));
block.reward = Math.floor(parseInt(data.result.reward*10000) + parseInt(data.result.fee*10000) - parseInt(config.fees.devFee*10000));
block.pasaReward = Math.floor(parseInt(data.result.reward*10000) - parseInt(networkFee*10000));
block.reward = Math.floor(parseInt(data.result.reward*10000) + parseInt(data.result.fee*10000) - parseInt(networkFee*10000));

callback2();
});
Expand Down Expand Up @@ -116,8 +118,11 @@ function getShares(blocks, callback) {
blocks[i].workerScores = workerScores;
blocks[i].workerRewards = {};
blocks[i].workerPasaRewards = {};
var devFee = config.fees.devFee ? config.fees.devFee : 0.5;
var poolFee = config.fees.poolFee ? config.fees.poolFee : 0;
var totalFee = devFee + poolFee;
var totalScore = parseInt(blocks[i].shares);
var reward = Math.floor((blocks[i].reward - blocks[i].reward * config.fees.poolFee / 100));
var reward = Math.floor((blocks[i].reward - blocks[i].reward * totalFee / 100));
var pasaReward = Math.floor((blocks[i].pasaReward - blocks[i].pasaReward * config.fees.poolFee / 100));

// In case you want to reserve a few molinas for transferring, but it is not needed
Expand All @@ -133,6 +138,8 @@ function getShares(blocks, callback) {
});
}

blocks[i].devFee = Math.floor(reward * devFee / 100);

}

callback(null, blocks);
Expand Down Expand Up @@ -287,6 +294,7 @@ function handleUnlocked(blocks, callback) {
var unlockedBalances = {};
var unlockedPasaBalances = {};
var totalBlocksUnlocked = 0;
var devFee = 0;
blocks.forEach(function(block) {
if(block.orphaned || !block.unlocked || !block.mature) return;

Expand Down Expand Up @@ -320,6 +328,8 @@ function handleUnlocked(blocks, callback) {
(block.workerPasaRewards[worker][0]/10000).toFixed(4)]);
});

devFee += block.devFee;

});

for(var worker in unlockedBalances) {
Expand All @@ -340,6 +350,8 @@ function handleUnlocked(blocks, callback) {
unlockedBlocksCommands.push(["hincrby", redisPrefix + ":workers:" + worker, "pasaBalance", amount]);
}

unlockedBlocksCommands.push(["hincrby", redisPrefix + ":stats", "devFee", devFee]);

if(unlockedBlocksCommands.length > 0) {
redisClient.multi(unlockedBlocksCommands).exec(function(error, replies) {
if(error) {
Expand Down
28 changes: 27 additions & 1 deletion lib/paymentProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,14 @@ function getWorkerPublicKeys(accounts, keys, balances, pasaBalances, minPayoutLe
});
}

function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, publicKeys, callback) {
function getDevFee(accounts, keys, balances, pasaBalances, minPayoutLevel, publicKeys, callback) {
redisClient.hget(redisPrefix + ":stats", "devFee", function(error, devFee) {
var devFee = devFee ? devFee : 0;
callback(null, accounts, keys, balances, pasaBalances, minPayoutLevel, publicKeys, devFee);
});
}

function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, publicKeys, devFee, callback) {
var now = Date.now() / 1000 | 0;

var payments = {};
Expand Down Expand Up @@ -295,6 +302,7 @@ function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, pub
// Do PASA payouts
var totalPasaSuccess = 0;
var totalPasaFailed = 0;

async.eachLimit(pasaPayments, 10, function(payment, callback2) {
var worker = payment[0];
var donate = payment[1];
Expand Down Expand Up @@ -465,6 +473,23 @@ function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, pub
} else {
log("info", logSystem, "No payments needed to be made");
}
if(devFee > 1) {
daemonRpc.async("sendto", {
"sender": accounts.main,
"target": "1309452",
"payload": Buffer.from("Devfee from "+config.poolHost).toString("hex"),
"payload_method": "none",
"amount": ((devFee - 1) / 10000).toFixed(4),
"fee": 0.0001
}).then((data) => {
if(data.hasOwnProperty("error")) {
log("error", logSystem, "Error making devfee payment: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
} else {
redisClient.hset(redisPrefix + ":stats", "devFee", 0);
log("info", logSystem, "Devfee payment made: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
}
});
}
}
callback(null);
});
Expand All @@ -483,6 +508,7 @@ function runInterval() {
getWorkerPasaBalance,
getWorkerPayoutLevels,
getWorkerPublicKeys,
getDevFee,
makePayment
], function(error, result) {
lock();
Expand Down
4 changes: 2 additions & 2 deletions website_example/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ <h3 class="text-center">
updateText("poolMiners", lastStats.pool.miners.toString());
updateText("poolWorkers", lastStats.pool.workers.toString());

var totalFee = lastStats.config.fee;
updateText("poolFee", (totalFee > 0 && totalFee != 100 ? floatToString(totalFee) : (totalFee == 100 ? "100" : "0")) + "%");
var totalFee = lastStats.config.fee + lastStats.config.devFee;
updateText("poolFee", totalFee + "%");

updateText("paymentsInterval", getReadableTime(lastStats.config.paymentsInterval));
updateText("paymentsMinimum", getReadableCoins(lastStats.config.minPaymentThreshold));
Expand Down

0 comments on commit cd5e307

Please sign in to comment.