Discover updated to the working version

This commit is contained in:
George Spasov 2019-07-03 13:09:57 +03:00
parent 988b19d2f6
commit 6a98700dd0
7 changed files with 37 additions and 26 deletions

View File

@ -19,7 +19,7 @@ Builds the app into the `build` directory.
**Ropsten contracts:**
1. SNT - 0x2764b5da3696E3613Ef9864E9B4613f9fA478E75
2. Discover - 0x9591a20b9B601651eDF1072A1Dda994C0B1a5bBf
2. Discover - 0xd34aae5b764d720ba5b438b29d60e5e9601cf3a9
**Manual needed steps:**
Once embark is running:

View File

@ -74,9 +74,9 @@ module.exports = {
SafeMath: { deploy: false },
TestBancorFormula: { deploy: false },
MiniMeToken: {
address: '0x2764b5da3696e3613ef9864e9b4613f9fa478e75'
address: '0x25B1bD06fBfC2CbDbFc174e10f1B78b1c91cc77B'
},
Discover: { address: '0xbe3d6825bf6e19b6d783cc1041256962708b7b8d' },
Discover: { address: '0xd34aae5b764d720ba5b438b29d60e5e9601cf3a9' },
// MiniMeToken: {
// args: [
// '$MiniMeTokenFactory',

View File

@ -21,9 +21,6 @@ contract Discover is ApproveAndCallFallBack, BancorFormula {
// The max amount of tokens it is possible to stake, as a percentage of the total in circulation
uint public max;
// Need to multiply by 10^18 because tokens on Ethereum...
uint public maxCheck;
// Decimal precision for this contract
uint public decimals;
@ -60,7 +57,7 @@ contract Discover is ApproveAndCallFallBack, BancorFormula {
ceiling = 292; // See here for more: https://observablehq.com/@andytudhope/dapp-store-snt-curation-mechanism
decimals = 1000000; // 4 decimal points for %, 2 because we only use 1/100th of total in existence
decimals = 1000000; // 4 decimal points for %, 2 because we only use 1/100th of total in circulation
max = total.mul(ceiling).div(decimals);
@ -227,7 +224,7 @@ contract Discover is ApproveAndCallFallBack, BancorFormula {
*/
function upvoteEffect(bytes32 _id, uint _amount) external view returns(uint effect) {
Data memory d = _getDAppById(_id);
require(d.balance.add(_amount) <= maxCheck, "You cannot upvote by this much, try with a lower amount");
require(d.balance.add(_amount) <= safeMax, "You cannot upvote by this much, try with a lower amount");
// Special case - no downvotes yet cast
if (d.votesCast == 0) {

View File

@ -7,10 +7,12 @@ import BlockchainService from '../blockchain-service'
import DiscoverValidator from './discover-validator'
import DiscoverContract from '../../../../embarkArtifacts/contracts/Discover'
const BN = require('bn.js')
class DiscoverService extends BlockchainService {
constructor(sharedContext) {
super(sharedContext, DiscoverContract, DiscoverValidator)
this.decimalMultiplier = 1000000000000000000
this.decimalMultiplier = new BN('1000000000000000000', 10)
}
// View methods
@ -110,7 +112,7 @@ class DiscoverService extends BlockchainService {
// Transaction methods
async createDApp(amount, metadata) {
const tokenAmount = amount * this.decimalMultiplier
const tokenAmount = this.decimalMultiplier.mul(new BN(amount, 10))
const ConnectedDiscoverContract = await super.__unlockServiceAccount(
DiscoverContract,
@ -140,8 +142,9 @@ class DiscoverService extends BlockchainService {
}
async upVote(id, amount) {
const tokenAmount = amount * this.decimalMultiplier
await this.validator.validateUpVoting(id, amount)
const tokenAmount = this.decimalMultiplier.mul(new BN(amount, 10))
await this.validator.validateUpVoting(id, tokenAmount)
const callData = DiscoverContract.methods
.upvote(id, tokenAmount)
@ -157,8 +160,14 @@ class DiscoverService extends BlockchainService {
const dapp = await this.getDAppById(id)
const amount = (await this.downVoteCost(dapp.id)).c
console.log(amount)
const tokenAmount = this.decimalMultiplier.mul(new BN(amount, 10))
console.log(tokenAmount.toString())
const callData = DiscoverContract.methods
.downvote(dapp.id, amount)
.downvote(dapp.id, tokenAmount)
.encodeABI()
return this.sharedContext.SNTService.approveAndCall(
this.contract,
@ -168,7 +177,7 @@ class DiscoverService extends BlockchainService {
}
async withdraw(id, amount) {
const tokenAmount = amount * this.decimalMultiplier
const tokenAmount = this.decimalMultiplier.mul(new BN(amount, 10))
const ConnectedDiscoverContract = await super.__unlockServiceAccount(
DiscoverContract,
)

View File

@ -1,14 +1,19 @@
const BN = require('bn.js')
class DiscoverValidator {
constructor(service) {
this.service = service
this.decimalMultiplier = 1000000000000000000
this.decimalMultiplier = new BN('1000000000000000000', 10)
}
async validateUpVoteEffect(id, amount) {
const dapp = await this.service.getDAppById(id)
const safeMax = await this.service.safeMax()
if (Number(dapp.balance) + amount / this.decimalMultiplier > safeMax) {
if (
Number(dapp.balance) + amount.div(this.decimalMultiplier).toNumber() >
safeMax
) {
throw new Error(
`You cannot upvote by this much, try with a lower amount. Maximum upvote amount:
${Number(safeMax) - Number(dapp.balance)}`,
@ -22,14 +27,14 @@ class DiscoverValidator {
throw new Error('You must submit a unique ID')
}
if (amount <= 0) {
if (amount.lte(0)) {
throw new Error(
'You must spend some SNT to submit a ranking in order to avoid spam',
)
}
const safeMax = await this.service.safeMax()
if (amount / this.decimalMultiplier > safeMax) {
if (amount.div(this.decimalMultiplier).toNumber() > safeMax) {
throw new Error('You cannot stake more SNT than the ceiling dictates')
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,14 +1,14 @@
module.exports = {
Controlled: require('./Controlled').default,
BancorFormula: require('./BancorFormula').default,
SafeMath: require('./SafeMath').default,
TestBancorFormula: require('./TestBancorFormula').default,
ApproveAndCallFallBack: require('./ApproveAndCallFallBack').default,
SafeMath: require('./SafeMath').default,
MiniMeTokenFactory: require('./MiniMeTokenFactory').default,
Discover: require('./Discover').default,
TokenController: require('./TokenController').default,
ERC20Token: require('./ERC20Token').default,
MiniMeTokenInterface: require('./MiniMeTokenInterface').default,
MiniMeTokenFactory: require('./MiniMeTokenFactory').default,
MiniMeToken: require('./MiniMeToken').default,
TokenController: require('./TokenController').default,
TokenFactory: require('./TokenFactory').default,
Discover: require('./Discover').default,
MiniMeToken: require('./MiniMeToken').default,
}