Last active
January 20, 2018 17:48
-
-
Save byronaltice/c4aa5bc59624a0dfefbea0e3e18eedaa to your computer and use it in GitHub Desktop.
Revisions
-
byronaltice revised this gist
Jan 20, 2018 . 1 changed file with 163 additions and 56 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,64 +6,146 @@ // Paste below line of code into chrome developer to pull directly from gist // function f() {var s = document.createElement('script');s.setAttribute('src', 'https://cdn.rawgit.com/byronaltice/c4aa5bc59624a0dfefbea0e3e18eedaa/raw/7f522ed173d7bc69db42b9d9e176f62d6a83e6bf/ethercraft.js');document.head.appendChild(s);return;}f(); var showIndividual = true, oneEth = 1000000000000000000, invested = 1.1, amountWithdrawn = .7, executed = false, nonZeroBalancesChecked = 0, items = {}, totals = { "King's Robe": { invested: 0.1, withdrawn: 0.196 }, "King's Crown": { invested: 0.1, withdrawn: 0.2105 }, "Powerful Acidic Solution": { invested: 0.01, withdrawn: 0 }, "Powerful Basic Solution": { invested: 0.01, withdrawn: 0 }, "Mana Crystal": { invested: 0.01, withdrawn: 0 }, "Mana Crystal Powder": { invested: 0.01, withdrawn: 0 }, "Merchant's Enchanted Amulet": { invested: 0.25, withdrawn: 0.275 }, "Merchant's Enchanted Bag": { invested: 0.1, withdrawn: 0.093 }, "Merchant's Enchanted Doublet": { invested: 0.1, withdrawn: 0.122 }, "Merchant's Enchanted Knickers": { invested: 0.1, withdrawn: 0.122 }, "Merchant's Enchanted Potion": { invested: 0.2, withdrawn: 0.313 }, "Merchant's Enchanted Shield": { invested: 0.1, withdrawn: 0.121 }, "Jolly Boots": { invested: 0.05, withdrawn: 0.064 }, "Stone Skin Amulet": { invested: 0.1, withdrawn: 0.123 }, "Jolly Suit": { invested: 0.05, withdrawn: 0.069 }, "Jolly Hat": { invested: 0.05, withdrawn: 0.076 } }, totalEnchantedItemsHeld = Object.keys(totals).length; function roundToDecimalPlaces(num, decimals) { var multiplier = 10 ^ decimals; return parseFloat(num).toFixed(decimals); } function addColumn(value, length, addColumnBar, addSpaceIfNotNegative) { var s = ""; var spaceAdded = addSpaceIfNotNegative && value.length > 0 && value.indexOf("-") != 0; if (spaceAdded) { s += " "; } s += value; var subtractLength = spaceAdded ? length - 1 : length; for (var i = 0; i < subtractLength - String(value).length; i++) { s += " "; } if (addColumnBar) { s += "|| "; } return s; } function getTotalBalance() { var totalBalance = 0; console.log("Name || Invested || Withdrawn || Balance || Profits || Percent Gained"); console.log("==============================||===========||=============||=============||==============||================"); for (item in totals) { var t = totals[item]; totalBalance += t.balance; t.profits = roundToDecimalPlaces(((t.balance + t.withdrawn) - t.invested), 4); t.profitsPercent = roundToDecimalPlaces((((t.balance + t.withdrawn) / t.invested) * 100) - 100, 4); var s = addColumn(item, 30, true); s += addColumn(t.invested + " ETH", 10, true); s += addColumn(t.withdrawn + " ETH", 12, true); s += addColumn(t.balance + " ETH", 12, true); s += addColumn(t.profits + " ETH", 13, true, true); s += addColumn(t.profitsPercent + "%", 14, false, true); console.log(s); } console.log("==============================||===========||=============||=============||==============||================"); return totalBalance } function getBalanceOwed(address, name) { var thisShop = web3.eth.contract(Enchanted).at(address); var accountAddress = web3.eth.defaultAccount; thisShop.object.call(function (err, tokenAddress) { var token = web3.eth.contract(ERC20).at(tokenAddress); thisShop.balanceOwed.call(accountAddress, function (err, balanceOwed) { @@ -72,16 +154,14 @@ function getBalanceOwed(address, name) { thisShop.itemReturn.call(function (err, itemReturn) { token.totalSupply.call(function (err, totalSupply) { thisShop.itemsOwned.call(accountAddress, function (err, itemsOwned) { var returnsUnaccounted = totalSupply.minus(latestBalanceCheck).dividedBy(oneEth).times(itemReturn).times(itemsOwned.dividedBy(oneEth)); var shopBalance = balanceOwed.plus(excessEth).plus(returnsUnaccounted); var balance = parseFloat(shopBalance.dividedBy(oneEth).toFixed(5)); if (balance != 0 || (totals[name] && totals[name].withdrawn > 0)) { totals[name].balance = balance; nonZeroBalancesChecked += 1; console.debug("Non-zero balances: " + nonZeroBalancesChecked); execute(); } }); }); @@ -92,8 +172,35 @@ function getBalanceOwed(address, name) { }); } function execute() { if (nonZeroBalancesChecked == totalEnchantedItemsHeld && !executed) { executed = true; var total = getTotalBalance(); console.log("Total balance: " + roundToDecimalPlaces(total, 4) + " ETH"); if (amountWithdrawn > 0) { console.log("Total withdrawn: " + roundToDecimalPlaces(amountWithdrawn, 4) + " ETH"); console.log("Total balance including withdrawn: " + roundToDecimalPlaces(total + amountWithdrawn, 4) + " ETH"); } if (invested != 0) { console.log("Total investment: " + roundToDecimalPlaces(invested, 4) + " ETH"); console.log("You're at " + roundToDecimalPlaces((((((total + amountWithdrawn) / invested)) * 100) - 100), 4) + '% of your initial investment.'); console.log("You've made " + roundToDecimalPlaces(total + amountWithdrawn - invested, 4) + " ETH."); } } } for (var t in totals) { if (totals.hasOwnProperty(t)) { amountWithdrawn += totals[t].withdrawn; invested += totals[t].invested; } } for (var i in itemDB) { var item = itemDB[i]; if (item.enchanted) { getBalanceOwed(item.address, item.strings[0].name); } } -
byronaltice revised this gist
Jan 16, 2018 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,9 @@ // Change the invested amount to your amount in ETH invested into the ethercraft website/game // https://ethercraft.io/#/inventory/0x87bf5750f4ca59dac8455ec37286967bb8388d13 // Paste below line of code into chrome developer to pull directly from gist // function f() {var s = document.createElement('script');s.setAttribute('src', 'https://cdn.rawgit.com/byronaltice/c4aa5bc59624a0dfefbea0e3e18eedaa/raw/7f522ed173d7bc69db42b9d9e176f62d6a83e6bf/ethercraft.js');document.head.appendChild(s);return;}f(); var showIndividual = false; var amountWithdrawn = 0.0; var invested = 1.0; @@ -17,6 +20,16 @@ function getTotalBalance() { } var executed = false; /** * Casey said to add the below block, but nothing is displayed if i do */ /* if (amountWithdrawn > 0) { console.log('why does this cause issues?'); console.log("Total including amount withdrawn: " + (total + amountWithdrawn)); } */ function execute() { if (nonZeroBalancesChecked == totalEnchantedItemsHeld && !executed) { executed = true; -
byronaltice revised this gist
Jan 16, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ // https://ethercraft.io/#/inventory/0x87bf5750f4ca59dac8455ec37286967bb8388d13 var showIndividual = false; var amountWithdrawn = 0.0; var invested = 1.0; var items = {}; -
byronaltice revised this gist
Jan 16, 2018 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,11 @@ //Written by Casey Scarborough //@caseyscarborough // Change the invested amount to your amount in ETH invested into the ethercraft website/game // https://ethercraft.io/#/inventory/0x87bf5750f4ca59dac8455ec37286967bb8388d13 var showIndividual = false; var amountWithdrawn = 0.057; var invested = 1.0; var items = {}; function getTotalBalance() { -
caseyscarborough revised this gist
Jan 16, 2018 . No changes.There are no files selected for viewing
-
caseyscarborough revised this gist
Jan 16, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ var showIndividual = false; var amountWithdrawn = 0.057; var invested = 1.1123; var items = {}; function getTotalBalance() { -
caseyscarborough revised this gist
Jan 15, 2018 . 2 changed files with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ var showIndividual = false; var amountWithdrawn = 0; var invested = 0; var items = {}; function getTotalBalance() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ -
caseyscarborough revised this gist
Jan 15, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ function getTotalBalance(){var e=0;for(item in items)e+=items[item];return e}function execute(){if(nonZeroBalancesChecked==totalEnchantedItemsHeld&&!executed){executed=!0;var e=getTotalBalance();console.log("Total balance: "+e),0!=invested&&console.log("You're at "+((e+amountWithdrawn)/invested*100-100)+"% of your initial investment.")}}function getBalanceOwed(e,t){var n=web3.eth.contract(Enchanted).at(e),a=web3.eth.defaultAccount,c=1e18;n.object.call(function(e,i){var o=web3.eth.contract(ERC20).at(i);n.balanceOwed.call(a,function(e,i){n.excessEth.call(a,function(e,l){n.latestBalanceCheck.call(a,function(e,d){n.itemReturn.call(function(e,s){o.totalSupply.call(function(e,o){n.itemsOwned.call(a,function(e,n){returnsUnaccounted=o.minus(d).dividedBy(c).times(s).times(n.dividedBy(c));var a=i.plus(l).plus(returnsUnaccounted),u=parseFloat(a.dividedBy(c).toFixed(5));0!=u&&(nonZeroBalancesChecked+=1,showIndividual&&console.log(t+" has a balance of "+u),items[t]=u,execute())})})})})})})})}var showIndividual=!1,amountWithdrawn=.057,invested=1.1123,items={},executed=!1,totalEnchantedItemsHeld=0;for(var i in itemDB)if(itemDB[i].enchanted){var enchantedShop=web3.eth.contract(Enchanted).at(itemDB[i].address);enchantedShop.object.call(function(e,t){var n=web3.eth.contract(ERC20).at(t),a=1e18;n.balanceOf.call(web3.eth.defaultAccount,function(e,t){var n=t.dividedBy(a);n>0&&(totalEnchantedItemsHeld+=1,execute())})})}var nonZeroBalancesChecked=0;for(var item in itemDB)itemDB[item].enchanted&&getBalanceOwed(itemDB[item].address,itemDB[item].strings[0].name); -
caseyscarborough revised this gist
Jan 15, 2018 . 1 changed file with 39 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ var showIndividual = false; var amountWithdrawn = 0.057; var invested = 1.1123; var items = {}; function getTotalBalance() { @@ -9,6 +11,37 @@ function getTotalBalance() { return totalBalance } var executed = false; function execute() { if (nonZeroBalancesChecked == totalEnchantedItemsHeld && !executed) { executed = true; var total = getTotalBalance(); console.log("Total balance: " + total); if (invested != 0) { console.log("You're at " + (((((total + amountWithdrawn) / invested)) * 100) - 100) + '% of your initial investment.'); } } } var totalEnchantedItemsHeld = 0; for (var i in itemDB) { if (itemDB[i].enchanted) { var enchantedShop = web3.eth.contract(Enchanted).at(itemDB[i].address); enchantedShop.object.call(function (err, tokenAddress) { var token = web3.eth.contract(ERC20).at(tokenAddress); var oneEth = 1000000000000000000 token.balanceOf.call(web3.eth.defaultAccount, function (err, balance) { var tokensHeld = balance.dividedBy(oneEth); if (tokensHeld > 0) { totalEnchantedItemsHeld += 1; execute(); } }); }); } } var nonZeroBalancesChecked = 0; function getBalanceOwed(address, name) { var thisShop = web3.eth.contract(Enchanted).at(address); var accountAddress = web3.eth.defaultAccount; @@ -23,14 +56,14 @@ function getBalanceOwed(address, name) { thisShop.itemsOwned.call(accountAddress, function (err, itemsOwned) { returnsUnaccounted = totalSupply.minus(latestBalanceCheck).dividedBy(oneEth).times(itemReturn).times(itemsOwned.dividedBy(oneEth)); var shopBalance = balanceOwed.plus(excessEth).plus(returnsUnaccounted); var balance = parseFloat(shopBalance.dividedBy(oneEth).toFixed(5)); if (balance != 0) { nonZeroBalancesChecked += 1; if (showIndividual) { console.log(name + " has a balance of " + balance); } items[name] = balance; execute(); } }); }); @@ -41,16 +74,8 @@ function getBalanceOwed(address, name) { }); } for (var item in itemDB) { if (itemDB[item].enchanted) { getBalanceOwed(itemDB[item].address, itemDB[item].strings[0].name); } } -
caseyscarborough revised this gist
Jan 15, 2018 . 1 changed file with 9 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,11 +2,11 @@ var showIndividual = false; var items = {}; function getTotalBalance() { var totalBalance = 0; for (item in items) { totalBalance += items[item]; } return totalBalance } function getBalanceOwed(address, name) { @@ -25,12 +25,12 @@ function getBalanceOwed(address, name) { var shopBalance = balanceOwed.plus(excessEth).plus(returnsUnaccounted); var results = 'Total balance owed to user: '; results += shopBalance.dividedBy(oneEth).toString();; var balance = parseFloat(shopBalance.dividedBy(oneEth).toFixed(5)); if (balance != 0) { if (showIndividual) { console.log(name + " has a balance of " + balance); } items[name] = balance; } }); }); -
caseyscarborough created this gist
Jan 15, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ var showIndividual = false; var items = {}; function getTotalBalance() { var totalBalance = 0; for (item in items) { totalBalance += items[item]; } return totalBalance } function getBalanceOwed(address, name) { var thisShop = web3.eth.contract(Enchanted).at(address); var accountAddress = web3.eth.defaultAccount; var oneEth = 1000000000000000000; thisShop.object.call(function (err, tokenAddress) { var token = web3.eth.contract(ERC20).at(tokenAddress); thisShop.balanceOwed.call(accountAddress, function (err, balanceOwed) { thisShop.excessEth.call(accountAddress, function (err, excessEth) { thisShop.latestBalanceCheck.call(accountAddress, function (err, latestBalanceCheck) { thisShop.itemReturn.call(function (err, itemReturn) { token.totalSupply.call(function (err, totalSupply) { thisShop.itemsOwned.call(accountAddress, function (err, itemsOwned) { returnsUnaccounted = totalSupply.minus(latestBalanceCheck).dividedBy(oneEth).times(itemReturn).times(itemsOwned.dividedBy(oneEth)); var shopBalance = balanceOwed.plus(excessEth).plus(returnsUnaccounted); var results = 'Total balance owed to user: '; results += shopBalance.dividedBy(oneEth).toString();; var balance = parseFloat(shopBalance.dividedBy(oneEth).toFixed(5)); if (balance != 0) { if (showIndividual) { console.log(name + " has a balance of " + balance); } items[name] = balance; } }); }); }); }); }); }); }); } function getAllBalances() { for (var item in itemDB) { if (itemDB[item].enchanted) { getBalanceOwed(itemDB[item].address, itemDB[item].strings[0].name); } } setTimeout(function () { console.log("Total balance: " + getTotalBalance()); }, 3000); return; } getAllBalances();