Skip to content

Commit

Permalink
changing max unstaking and undelegation cooldowns from 365 to 18250 days
Browse files Browse the repository at this point in the history
  • Loading branch information
harpagon210 committed Jul 3, 2019
1 parent 4ba7769 commit 3d0aa1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 63 deletions.
59 changes: 3 additions & 56 deletions contracts/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,59 +52,6 @@ actions.createSSC = async () => {
token.undelegationCooldown = 7;
await api.db.update('tokens', token);
}

// fix delegations to accounts with whitespaces
const balances = await api.db.find('balances', {
$and: [
{
delegationsIn: {
$exists: true,
},
},
{
delegationsIn: {
$ne: '0',
},
},
],
});

for (let index = 0; index < balances.length; index += 1) {
const balance = balances[index];

if (balance.account.trim() !== balance.account) {
const delegations = await api.db.find('delegations', { to: balance.account, symbol: balance.symbol });

for (let idx = 0; idx < delegations.length; idx += 1) {
const delegation = delegations[idx];
const balanceFrom = await api.db.findOne('balances', { account: delegation.from, symbol: delegation.symbol });

const tkn = await api.db.findOne('tokens', { symbol: balance.symbol });

// update the balanceFrom
balanceFrom.stake = calculateBalance(
balanceFrom.stake, delegation.quantity, tkn.precision, true,
);
balanceFrom.delegationsOut = calculateBalance(
balanceFrom.delegationsOut, delegation.quantity, tkn.precision, false,
);

// update balance
balance.delegationsIn = calculateBalance(
balance.delegationsIn, delegation.quantity, tkn.precision, false,
);

await api.db.update('balances', balanceFrom);
await api.db.remove('delegations', delegation);

if (api.BigNumber(balance.balance).eq(0) && api.BigNumber(balance.delegationsIn).eq(0)) {
await api.db.remove('balances', balance);
} else {
await api.db.update('balances', balance);
}
}
}
}
};

actions.updateParams = async (payload) => {
Expand Down Expand Up @@ -602,8 +549,8 @@ actions.enableStaking = async (payload) => {

if (api.assert(isSignedWithActiveKey === true, 'you must use a custom_json signed with your active key')
&& api.assert(symbol && typeof symbol === 'string', 'invalid symbol')
&& api.assert(unstakingCooldown && Number.isInteger(unstakingCooldown) && unstakingCooldown > 0 && unstakingCooldown <= 365, 'unstakingCooldown must be an integer between 1 and 365')
&& api.assert(numberTransactions && Number.isInteger(numberTransactions) && numberTransactions > 0 && numberTransactions <= 365, 'numberTransactions must be an integer between 1 and 365')) {
&& api.assert(unstakingCooldown && Number.isInteger(unstakingCooldown) && unstakingCooldown > 0 && unstakingCooldown <= 18250, 'unstakingCooldown must be an integer between 1 and 18250')
&& api.assert(numberTransactions && Number.isInteger(numberTransactions) && numberTransactions > 0 && numberTransactions <= 18250, 'numberTransactions must be an integer between 1 and 18250')) {
const token = await api.db.findOne('tokens', { symbol });

if (api.assert(token !== null, 'symbol does not exist')
Expand Down Expand Up @@ -928,7 +875,7 @@ actions.enableDelegation = async (payload) => {

if (api.assert(isSignedWithActiveKey === true, 'you must use a custom_json signed with your active key')
&& api.assert(symbol && typeof symbol === 'string', 'invalid symbol')
&& api.assert(undelegationCooldown && Number.isInteger(undelegationCooldown) && undelegationCooldown > 0 && undelegationCooldown <= 365, 'undelegationCooldown must be an integer between 1 and 365')) {
&& api.assert(undelegationCooldown && Number.isInteger(undelegationCooldown) && undelegationCooldown > 0 && undelegationCooldown <= 18250, 'undelegationCooldown must be an integer between 1 and 18250')) {
const token = await api.db.findOne('tokens', { symbol });

if (api.assert(token !== null, 'symbol does not exist')
Expand Down
14 changes: 7 additions & 7 deletions test/smarttokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ describe('smart tokens', function () {
transactions.push(new Transaction(12345678901, 'TXID1236', 'harpagon', 'tokens', 'create', '{ "isSignedWithActiveKey": true, "name": "token", "symbol": "NKT", "precision": 8, "maxSupply": "1000", "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1238', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 7, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1240', 'satoshi', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 365, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1240', 'satoshi', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 18250, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1241', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 0, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1242', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 366, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1242', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 18251, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1243', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1244', 'harpagon', 'tokens', 'enableDelegation', '{ "symbol": "TKN", "undelegationCooldown": 7, "isSignedWithActiveKey": true }'));

Expand All @@ -213,8 +213,8 @@ describe('smart tokens', function () {

assert.equal(JSON.parse(txs[4].logs).errors[0], 'staking not enabled');
assert.equal(JSON.parse(txs[6].logs).errors[0], 'must be the issuer');
assert.equal(JSON.parse(txs[7].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 365');
assert.equal(JSON.parse(txs[8].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 365');
assert.equal(JSON.parse(txs[7].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 18250');
assert.equal(JSON.parse(txs[8].logs).errors[0], 'undelegationCooldown must be an integer between 1 and 18250');
assert.equal(JSON.parse(txs[10].logs).errors[0], 'delegation already enabled');

resolve();
Expand Down Expand Up @@ -915,7 +915,7 @@ describe('smart tokens', function () {
transactions.push(new Transaction(12345678901, 'TXID1236', 'harpagon', 'tokens', 'create', '{ "isSignedWithActiveKey": true, "name": "token", "symbol": "NKT", "precision": 8, "maxSupply": "1000", "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1237', 'satoshi', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 7, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1238', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 0, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 366, "numberTransactions": 1, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(12345678901, 'TXID1239', 'harpagon', 'tokens', 'enableStaking', '{ "symbol": "TKN", "unstakingCooldown": 18251, "numberTransactions": 1, "isSignedWithActiveKey": true }'));

let block = {
refSteemBlockNumber: 12345678901,
Expand Down Expand Up @@ -953,8 +953,8 @@ describe('smart tokens', function () {
let txs = res.payload.transactions;

assert.equal(JSON.parse(txs[4].logs).errors[0], 'must be the issuer');
assert.equal(JSON.parse(txs[5].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 365');
assert.equal(JSON.parse(txs[6].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 365');
assert.equal(JSON.parse(txs[5].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 18250');
assert.equal(JSON.parse(txs[6].logs).errors[0], 'unstakingCooldown must be an integer between 1 and 18250');

resolve();
})
Expand Down

0 comments on commit 3d0aa1f

Please sign in to comment.