Skip to content

Commit

Permalink
Merge pull request #39 from harpagon210/dekegation-mainnet
Browse files Browse the repository at this point in the history
Delegation mainnet
  • Loading branch information
harpagon210 authored Jun 17, 2019
2 parents aafe690 + 912cd11 commit 8ed1c35
Show file tree
Hide file tree
Showing 15 changed files with 1,775 additions and 2,031 deletions.
53 changes: 22 additions & 31 deletions contracts/bootstrap/Bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Base64 } = require('js-base64');
const fs = require('fs-extra');
const { Transaction } = require('../../libs/Transaction');
const BP_CONSTANTS = require('../../libs/BlockProduction.contants').CONSTANTS;
const { CONSTANTS } = require('../../libs/Constants');

class Bootstrap {
static async getBootstrapTransactions(genesisSteemBlock) {
Expand All @@ -11,22 +11,13 @@ class Bootstrap {
let base64ContractCode;
let contractPayload;

const FORK_BLOCK_NUMBER = 30896500;
const FORK_BLOCK_NUMBER_TWO = 30983000;
const FORK_BLOCK_NUMBER_THREE = 31992326;
const ACCOUNT_RECEIVING_FEES = 'steemsc';
const STEEM_PEGGED_ACCOUNT = 'steem-peg';
const INITIAL_TOKEN_CREATION_FEE = '100';
const SSC_STORE_PRICE = '0.001';
const SSC_STORE_QTY = '0.001';

// tokens contract
contractCode = await fs.readFileSync('./contracts/bootstrap/tokens.js');
contractCode = contractCode.toString();

contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_PRECISION\}\$'/g, BP_CONSTANTS.UTILITY_TOKEN_PRECISION);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_SYMBOL\}\$'/g, BP_CONSTANTS.UTILITY_TOKEN_SYMBOL);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER\}\$'/g, FORK_BLOCK_NUMBER);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_PRECISION\}\$'/g, CONSTANTS.UTILITY_TOKEN_PRECISION);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_SYMBOL\}\$'/g, CONSTANTS.UTILITY_TOKEN_SYMBOL);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER\}\$'/g, CONSTANTS.FORK_BLOCK_NUMBER);

base64ContractCode = Base64.encode(contractCode);

Expand All @@ -42,11 +33,11 @@ class Bootstrap {
contractCode = await fs.readFileSync('./contracts/bootstrap/sscstore.js');
contractCode = contractCode.toString();

contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_PRECISION\}\$'/g, BP_CONSTANTS.UTILITY_TOKEN_PRECISION);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_SYMBOL\}\$'/g, BP_CONSTANTS.UTILITY_TOKEN_SYMBOL);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER\}\$'/g, FORK_BLOCK_NUMBER);
contractCode = contractCode.replace(/'\$\{SSC_STORE_PRICE\}\$'/g, SSC_STORE_PRICE);
contractCode = contractCode.replace(/'\$\{SSC_STORE_QTY\}\$'/g, SSC_STORE_QTY);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_PRECISION\}\$'/g, CONSTANTS.UTILITY_TOKEN_PRECISION);
contractCode = contractCode.replace(/'\$\{BP_CONSTANTS.UTILITY_TOKEN_SYMBOL\}\$'/g, CONSTANTS.UTILITY_TOKEN_SYMBOL);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER\}\$'/g, CONSTANTS.FORK_BLOCK_NUMBER);
contractCode = contractCode.replace(/'\$\{SSC_STORE_PRICE\}\$'/g, CONSTANTS.SSC_STORE_PRICE);
contractCode = contractCode.replace(/'\$\{SSC_STORE_QTY\}\$'/g, CONSTANTS.SSC_STORE_QTY);

base64ContractCode = Base64.encode(contractCode);

Expand All @@ -62,7 +53,7 @@ class Bootstrap {
contractCode = await fs.readFileSync('./contracts/bootstrap/steempegged.js');
contractCode = contractCode.toString();

contractCode = contractCode.replace(/'\$\{ACCOUNT_RECEIVING_FEES\}\$'/g, ACCOUNT_RECEIVING_FEES);
contractCode = contractCode.replace(/'\$\{ACCOUNT_RECEIVING_FEES\}\$'/g, CONSTANTS.ACCOUNT_RECEIVING_FEES);

base64ContractCode = Base64.encode(contractCode);

Expand All @@ -72,13 +63,13 @@ class Bootstrap {
code: base64ContractCode,
};

transactions.push(new Transaction(genesisSteemBlock, 0, STEEM_PEGGED_ACCOUNT, 'contract', 'deploy', JSON.stringify(contractPayload)));
transactions.push(new Transaction(genesisSteemBlock, 0, CONSTANTS.STEEM_PEGGED_ACCOUNT, 'contract', 'deploy', JSON.stringify(contractPayload)));

contractCode = await fs.readFileSync('./contracts/bootstrap/market.js');
contractCode = contractCode.toString();

contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER_TWO\}\$'/g, FORK_BLOCK_NUMBER_TWO);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER_THREE\}\$'/g, FORK_BLOCK_NUMBER_THREE);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER_TWO\}\$'/g, CONSTANTS.FORK_BLOCK_NUMBER_TWO);
contractCode = contractCode.replace(/'\$\{FORK_BLOCK_NUMBER_THREE\}\$'/g, CONSTANTS.FORK_BLOCK_NUMBER_THREE);

base64ContractCode = Base64.encode(contractCode);

Expand Down Expand Up @@ -108,13 +99,13 @@ class Bootstrap {


// bootstrap transactions
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'create', `{ "name": "Steem Engine Token", "symbol": "ENG", "precision": 8, "maxSupply": ${Number.MAX_SAFE_INTEGER} }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'updateMetadata', '{"symbol":"ENG", "metadata": { "url":"https://steem-engine.com", "icon": "https://s3.amazonaws.com/steem-engine/images/icon_steem-engine_gradient.svg", "desc": "ENG is the native token for the Steem Engine platform" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', '{ "symbol": "ENG", "to": "steemsc", "quantity": 2000000, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', '{ "symbol": "ENG", "to": "harpagon", "quantity": 1000000, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', '{ "symbol": "ENG", "to": "steemmonsters", "quantity": 1000000, "isSignedWithActiveKey": true }'));
transactions.push(new Transaction(genesisSteemBlock, 0, STEEM_PEGGED_ACCOUNT, 'tokens', 'create', '{ "name": "STEEM Pegged", "symbol": "STEEMP", "precision": 3, "maxSupply": 1000000000000 }'));
transactions.push(new Transaction(genesisSteemBlock, 0, STEEM_PEGGED_ACCOUNT, 'tokens', 'updateMetadata', '{"symbol":"STEEMP", "metadata": { "desc": "STEEM backed by the steem-engine team" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'create', `{ "name": "Steem Engine Token", "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "precision": ${CONSTANTS.UTILITY_TOKEN_PRECISION}, "maxSupply": ${Number.MAX_SAFE_INTEGER} }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'updateMetadata', `{"symbol":"${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "metadata": { "url":"https://steem-engine.com", "icon": "https://s3.amazonaws.com/steem-engine/images/icon_steem-engine_gradient.svg", "desc": "ENG is the native token for the Steem Engine platform" }}`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', `{ "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "to": "steemsc", "quantity": 2000000, "isSignedWithActiveKey": true }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', `{ "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "to": "harpagon", "quantity": 1000000, "isSignedWithActiveKey": true }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'null', 'tokens', 'issue', `{ "symbol": "${CONSTANTS.UTILITY_TOKEN_SYMBOL}", "to": "steemmonsters", "quantity": 1000000, "isSignedWithActiveKey": true }`));
transactions.push(new Transaction(genesisSteemBlock, 0, CONSTANTS.STEEM_PEGGED_ACCOUNT, 'tokens', 'create', '{ "name": "STEEM Pegged", "symbol": "STEEMP", "precision": 3, "maxSupply": 1000000000000 }'));
transactions.push(new Transaction(genesisSteemBlock, 0, CONSTANTS.STEEM_PEGGED_ACCOUNT, 'tokens', 'updateMetadata', '{"symbol":"STEEMP", "metadata": { "desc": "STEEM backed by the steem-engine team" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'btcpeg', 'tokens', 'create', '{ "name": "BITCOIN Pegged", "symbol": "BTCP", "precision": 8, "maxSupply": 1000000000000 }'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'btcpeg', 'tokens', 'updateMetadata', '{"symbol":"BTCP", "metadata": { "desc": "BITCOIN backed by the steem-engine team" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'ltcp', 'tokens', 'create', '{ "name": "LITECOIN Pegged", "symbol": "LTCP", "precision": 8, "maxSupply": 1000000000000 }'));
Expand All @@ -123,8 +114,8 @@ class Bootstrap {
transactions.push(new Transaction(genesisSteemBlock, 0, 'dogep', 'tokens', 'updateMetadata', '{"symbol":"DOGEP", "metadata": { "desc": "DOGECOIN backed by the steem-engine team" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'bchp', 'tokens', 'create', '{ "name": "BITCOIN CASH Pegged", "symbol": "BCHP", "precision": 8, "maxSupply": 1000000000000 }'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'bchp', 'tokens', 'updateMetadata', '{"symbol":"BCHP", "metadata": { "desc": "BITCOIN CASH backed by the steem-engine team" }}'));
transactions.push(new Transaction(genesisSteemBlock, 0, 'steemsc', 'tokens', 'updateParams', `{ "tokenCreationFee": "${INITIAL_TOKEN_CREATION_FEE}" }`));
transactions.push(new Transaction(genesisSteemBlock, 0, STEEM_PEGGED_ACCOUNT, 'tokens', 'issue', `{ "symbol": "STEEMP", "to": "${STEEM_PEGGED_ACCOUNT}", "quantity": 1000000000000, "isSignedWithActiveKey": true }`));
transactions.push(new Transaction(genesisSteemBlock, 0, 'steemsc', 'tokens', 'updateParams', `{ "tokenCreationFee": "${CONSTANTS.INITIAL_TOKEN_CREATION_FEE}" }`));
transactions.push(new Transaction(genesisSteemBlock, 0, CONSTANTS.STEEM_PEGGED_ACCOUNT, 'tokens', 'issue', `{ "symbol": "STEEMP", "to": "${CONSTANTS.STEEM_PEGGED_ACCOUNT}", "quantity": 1000000000000, "isSignedWithActiveKey": true }`));

return transactions;
}
Expand Down
12 changes: 7 additions & 5 deletions contracts/market.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const findMatchingSellOrders = async (order, tokenPrecision) => {
}

// add the trade to the history
await updateTradesHistory('buy', symbol, buyOrder.quantity, sellOrder.price, qtyTokensToSend);
await updateTradesHistory('buy', account, sellOrder.account, symbol, buyOrder.quantity, sellOrder.price, qtyTokensToSend);

// update the volume
volumeTraded = api.BigNumber(volumeTraded).plus(qtyTokensToSend);
Expand Down Expand Up @@ -343,7 +343,7 @@ const findMatchingSellOrders = async (order, tokenPrecision) => {
}

// add the trade to the history
await updateTradesHistory('buy', symbol, sellOrder.quantity, sellOrder.price, qtyTokensToSend);
await updateTradesHistory('buy', account, sellOrder.account, symbol, sellOrder.quantity, sellOrder.price, qtyTokensToSend);

// update the volume
volumeTraded = api.BigNumber(volumeTraded).plus(qtyTokensToSend);
Expand Down Expand Up @@ -473,7 +473,7 @@ const findMatchingBuyOrders = async (order, tokenPrecision) => {
}

// add the trade to the history
await updateTradesHistory('sell', symbol, sellOrder.quantity, buyOrder.price, qtyTokensToSend);
await updateTradesHistory('sell', buyOrder.account, account, symbol, sellOrder.quantity, buyOrder.price, qtyTokensToSend);

// update the volume
volumeTraded = api.BigNumber(volumeTraded).plus(qtyTokensToSend);
Expand Down Expand Up @@ -537,7 +537,7 @@ const findMatchingBuyOrders = async (order, tokenPrecision) => {
}

// add the trade to the history
await updateTradesHistory('sell', symbol, buyOrder.quantity, buyOrder.price, qtyTokensToSend);
await updateTradesHistory('sell', buyOrder.account, account, symbol, buyOrder.quantity, buyOrder.price, qtyTokensToSend);

// update the volume
volumeTraded = api.BigNumber(volumeTraded).plus(qtyTokensToSend);
Expand Down Expand Up @@ -745,7 +745,7 @@ const updateAskMetric = async (symbol) => {
await api.db.update('metrics', metric);
};

const updateTradesHistory = async (type, symbol, quantity, price, volume) => {
const updateTradesHistory = async (type, buyer, seller, symbol, quantity, price, volume) => {
const blockDate = new Date(`${api.steemBlockTimestamp}.000Z`);
const timestampSec = blockDate.getTime() / 1000;
const timestampMinus24hrs = blockDate.setDate(blockDate.getDate() - 1) / 1000;
Expand Down Expand Up @@ -782,6 +782,8 @@ const updateTradesHistory = async (type, symbol, quantity, price, volume) => {
// add order to the history
const newTrade = {};
newTrade.type = type;
newTrade.buyer = buyer;
newTrade.seller = seller;
newTrade.symbol = symbol;
newTrade.quantity = quantity;
newTrade.price = price;
Expand Down
Loading

0 comments on commit 8ed1c35

Please sign in to comment.