From c70ffca68048bfb8b86bdcb800cdd849a2704a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Tue, 20 Feb 2018 12:46:54 +0100 Subject: [PATCH 1/5] feat: Generate contract manifest from the ABIs. Trim artifacts on build. BREAKING CHANGE: The contract interfaces now folllow the ABIs 1-on-1 --- package.json | 9 +- scripts/contracts/Artifact.js | 25 +++ scripts/contracts/Artifacts.js | 44 ++++ scripts/contracts/ContractFile.js | 58 +++++ scripts/contracts/Formatter.js | 25 +++ scripts/contracts/IndexFile.js | 56 +++++ scripts/contracts/Manifest.js | 21 ++ scripts/contracts/index.js | 81 +++++++ scripts/contracts/utils.js | 71 ++++++ src/contracts/DecentralandVesting.js | 36 +--- src/contracts/LANDRegistry.js | 60 +----- src/contracts/LANDTerraformSale.js | 24 --- src/contracts/LANDTestSale.js | 4 - src/contracts/MANAToken.js | 16 +- src/contracts/ReturnMANA.js | 35 --- src/contracts/TerraformReserve.js | 8 +- src/contracts/artifacts/MANAToken.json | 2 +- src/contracts/index.js | 288 ++++++++++++++++++++++++- src/ethereum/Contract.js | 10 + src/ethereum/eth.js | 2 +- 20 files changed, 692 insertions(+), 183 deletions(-) create mode 100644 scripts/contracts/Artifact.js create mode 100644 scripts/contracts/Artifacts.js create mode 100644 scripts/contracts/ContractFile.js create mode 100644 scripts/contracts/Formatter.js create mode 100644 scripts/contracts/IndexFile.js create mode 100644 scripts/contracts/Manifest.js create mode 100755 scripts/contracts/index.js create mode 100644 scripts/contracts/utils.js diff --git a/package.json b/package.json index 654706e..0a66553 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,13 @@ "docs": "npx jsdoc -c conf.json -r src/**/*.js", "lint": "npx eslint .", "lint:fix": "npx eslint --fix .", - "init": "mkdir dist", - "contracts": "mkdir -p dist/contracts/artifacts && cp -r src/contracts/artifacts dist/contracts", + "init": "mkdir -p dist", + "trim-artifacts": "./scripts/contracts/index.js trim-artifacts --write", + "copy-contracts": "mkdir -p dist/contracts/artifacts && cp -r src/contracts/artifacts dist/contracts", + "contracts-manifest": "./scripts/contracts/index.js generate-manifest --write", + "contracts": "npm run trim-artifacts && npm run copy-contracts && npm run contracts-manifest", "clean": "rm -rf dist", - "prebuild": "npm run lint && npm run test && npm run clean && npm run init && npm run contracts", + "prebuild": "npm run clean && npm run lint && npm run contracts && npm run test && npm run init", "build": "babel ./src -d ./dist --ignore specs", "fastbuild": "npm run clean && npm run init && babel ./src -d ./dist --ignore specs", "test": "npx mocha -r babel-register -r specs/spec_utils.js specs/*.spec.js", diff --git a/scripts/contracts/Artifact.js b/scripts/contracts/Artifact.js new file mode 100644 index 0000000..8bd48cf --- /dev/null +++ b/scripts/contracts/Artifact.js @@ -0,0 +1,25 @@ +import path from 'path' +import { fsReadFilePromise } from './utils' + +export class Artifact { + static PROPERTY_BLACKLIST = [ + 'bytecode', + 'sourceMap', + 'deployedSourceMap', + 'sourcePath', + 'ast', + 'compiler' + ] + + constructor(filePath) { + this.path = filePath + this.name = path.basename(filePath, path.extname(filePath)) + } + + async trim() { + let content = await fsReadFilePromise(this.path) + content = JSON.parse(content) + Artifact.PROPERTY_BLACKLIST.forEach(prop => delete content[prop]) + return JSON.stringify(content, null, 2) + } +} diff --git a/scripts/contracts/Artifacts.js b/scripts/contracts/Artifacts.js new file mode 100644 index 0000000..1876bc4 --- /dev/null +++ b/scripts/contracts/Artifacts.js @@ -0,0 +1,44 @@ +import path from 'path' +import { Artifact } from './Artifact' +import { findFolderPath, globPromise, fsWriteFilePromise } from './utils' + +const DEFAULT_FOLDER_PATH = 'src/contracts/artifacts' + +export class Artifacts { + static PROPERTY_BLACKLIST = [ + 'bytecode', + 'sourceMap', + 'deployedSourceMap', + 'sourcePath', + 'ast', + 'compiler' + ] + + constructor(folderPath) { + folderPath = folderPath || findFolderPath(DEFAULT_FOLDER_PATH) + this.folderPath = folderPath + this.collection = [] + } + + async buildCollection() { + const paths = await this.getPaths() + this.collection = paths.map(path => new Artifact(path)) + return this.collection + } + + async getPaths() { + const artifactsPattern = path.join(this.folderPath, 'MANAToken.json') + return await globPromise(artifactsPattern) + } + + async trim() { + return await Promise.all(this.collection.map(artifact => artifact.trim())) + } + + async write() { + for (const artifact of this.collection) { + const content = await artifact.trim() + await fsWriteFilePromise(artifact.path, content) + } + } +} diff --git a/scripts/contracts/ContractFile.js b/scripts/contracts/ContractFile.js new file mode 100644 index 0000000..95add47 --- /dev/null +++ b/scripts/contracts/ContractFile.js @@ -0,0 +1,58 @@ +import path from 'path' + +export class ContractFile { + constructor(filePath) { + this.path = filePath + this.name = path.basename(filePath, path.extname(filePath)) + this.abi = this.getAbi() + } + + isIndex() { + return this.name === 'index' + } + + getAbi() { + if (this.isIndex()) return + + try { + const Contract = require(this.path)[this.name] + return Contract.getDefaultAbi() + } catch (error) { + console.log( + `Could not find an artifact for "${this.path}"`, + error.message + ) + } + } + + getExtensions() { + const extensions = {} + + for (const method of this.abi) { + const { name, inputs, stateMutability, type } = method + + switch (type) { + case 'function': { + const args = [...inputs.map(input => input.name), '...args'].join( + ', ' + ) + + if (stateMutability === 'view') { + extensions[name] = `function(${args}) { + return this.call('${name}', ${args}) + }` + } else if (stateMutability === 'nonpayable') { + extensions[name] = `function(${args}) { + return this.transaction('${name}', ${args}) + }` + } + break + } + default: + break + } + } + + return extensions + } +} diff --git a/scripts/contracts/Formatter.js b/scripts/contracts/Formatter.js new file mode 100644 index 0000000..dd069a1 --- /dev/null +++ b/scripts/contracts/Formatter.js @@ -0,0 +1,25 @@ +import fs from 'fs' +import prettier from 'prettier' + +import { walkUp } from './utils' + +export class Formatter { + format(text) { + return prettier.format(text, this.getPrettierOptions()) + } + + getPrettierOptions() { + let eslintRules = null + + walkUp('.eslintrc', function(eslintrcPath) { + if (fs.existsSync(eslintrcPath)) { + const eslintrcText = fs.readFileSync(eslintrcPath, 'utf8') + eslintRules = JSON.parse(eslintrcText).rules + + return true + } + }) + + return eslintRules ? eslintRules['prettier/prettier'][1] : {} + } +} diff --git a/scripts/contracts/IndexFile.js b/scripts/contracts/IndexFile.js new file mode 100644 index 0000000..40a4048 --- /dev/null +++ b/scripts/contracts/IndexFile.js @@ -0,0 +1,56 @@ +import { ContractFile } from './ContractFile' + +export class IndexFile { + constructor(contractPaths) { + this.contractPaths = contractPaths + this.contracts = this.instantiateContracts() + } + + instantiateContracts() { + return this.contractPaths + .map(path => new ContractFile(path)) + .filter(contract => !!contract.abi) + } + + build() { + return ` +// This is auto-generated code +// Changes here will be lost + +${this.buildImports()} + +${this.buildDefinitions()} + +${this.buildExports()}` + } + + buildImports() { + return this.contracts + .map(contract => `import { ${contract.name} } from './${contract.name}'`) + .join('\n') + } + + buildDefinitions() { + return this.contracts + .map(contract => { + const extensions = contract.getExtensions() + const extensionObject = Object.keys(extensions) + .map(name => `${name}: ${extensions[name]}`) + .join(',\n\t\t') + + return `Object.assign( + ${contract.name}.prototype, { + ${extensionObject} + }, + ${contract.name}.prototype + )` + }) + .join('\n\n') + } + + buildExports() { + return `export { + ${this.contracts.map(contract => contract.name)} + }` + } +} diff --git a/scripts/contracts/Manifest.js b/scripts/contracts/Manifest.js new file mode 100644 index 0000000..a0d66fd --- /dev/null +++ b/scripts/contracts/Manifest.js @@ -0,0 +1,21 @@ +import path from 'path' +import { findFolderPath, globPromise, fsWriteFilePromise } from './utils' + +const DEFAULT_FOLDER_PATH = 'src/contracts' + +export class Manifest { + constructor(folderPath) { + folderPath = folderPath || findFolderPath(DEFAULT_FOLDER_PATH) + this.folderPath = folderPath + } + + getPaths() { + const contractsPattern = path.join(this.folderPath, '*.js') + return globPromise(contractsPattern) + } + + write(text = '') { + const manifestPath = path.join(this.folderPath, 'index.js') + return fsWriteFilePromise(manifestPath, text) + } +} diff --git a/scripts/contracts/index.js b/scripts/contracts/index.js new file mode 100755 index 0000000..e9fc7b2 --- /dev/null +++ b/scripts/contracts/index.js @@ -0,0 +1,81 @@ +#!/usr/bin/env babel-node + +import program from 'commander' + +import { Manifest } from './Manifest' +import { Artifacts } from './Artifacts' +import { IndexFile } from './IndexFile' +import { Formatter } from './Formatter' + +export function main() { + program + .command('generate-manifest') + .option( + '--folderPath [folderPath]', + 'Folder containing the contract files. By default it will try to find the nearest src/contracts folder' + ) + .option( + '--write', + 'Whether write the file or just print it. Defaults to false', + false + ) + .action(async options => { + const manifest = new Manifest(options.folderPath) + const indexFile = await generateIndex(manifest) + + if (options.write) { + await manifest.write(indexFile) + console.log(`index file written on "${manifest.folderPath}"`) + } else { + console.log(indexFile) + } + }) + + program + .command('trim-artifacts') + .option( + '--folderPath [folderPath]', + 'Folder containing the contract files. By default it will try to find the nearest src/contracts folder' + ) + .option( + '--write', + 'Whether write the file or just print it. Defaults to false', + false + ) + .action(async options => { + const artifacts = new Artifacts(options.folderPath) + await artifacts.buildCollection() + + console.log(`Trimming artifacts on ${artifacts.folderPath}`) + + if (options.write) { + await artifacts.write() + console.log(`artifacts written on "${artifacts.folderPath}"`) + } else { + const content = await artifacts.trim() + console.log(content) + } + }) + + program.parse(process.argv) +} + +async function generateIndex(manifest) { + console.log(`Geneating manifest for "${manifest.folderPath}"`) + + const contractPaths = await manifest.getPaths() + + console.log(`Found ${contractPaths.length} contracts`) + console.log('Building index file') + + const index = new IndexFile(contractPaths) + const indexFile = index.build() + + console.log('Index built successufully') + + return new Formatter().format(indexFile) +} + +if (require.main === module) { + main() +} diff --git a/scripts/contracts/utils.js b/scripts/contracts/utils.js new file mode 100644 index 0000000..7eade83 --- /dev/null +++ b/scripts/contracts/utils.js @@ -0,0 +1,71 @@ +import fs from 'fs' +import path from 'path' +import glob from 'glob' + +export function findFolderPath(destination) { + let folderPath = null + + walkUp(destination, function(contractsPath) { + if (fs.existsSync(contractsPath)) { + folderPath = contractsPath + + return true + } + }) + + return folderPath +} + +export function walkUp(destination, callback) { + let destinationPath = '' + let parents = [] + + while (parents.length <= 3) { + destinationPath = path.resolve(...parents, destination) + + const result = callback(destinationPath) + + if (result) break + + parents.push('..') + } + + return destinationPath +} + +export function globPromise(pattern, options) { + return new Promise((resolve, reject) => { + glob(pattern, options, function(error, paths) { + if (error || paths.length === 0) { + error = error || `Could not find any contracts for "${pattern}"` + reject(error) + } else { + resolve(paths) + } + }) + }) +} + +export function fsReadFilePromise(path) { + return new Promise((resolve, reject) => { + fs.readFile(path, 'utf8', function(error, text) { + if (error) { + reject(error) + } else { + resolve(text) + } + }) + }) +} + +export function fsWriteFilePromise(path, text) { + return new Promise((resolve, reject) => { + fs.writeFile(path, text, 'utf8', function(error) { + if (error) { + reject(error) + } else { + resolve() + } + }) + }) +} diff --git a/src/contracts/DecentralandVesting.js b/src/contracts/DecentralandVesting.js index 2dadf05..a12fe79 100644 --- a/src/contracts/DecentralandVesting.js +++ b/src/contracts/DecentralandVesting.js @@ -16,57 +16,33 @@ export class DecentralandVesting extends Contract { return abi } - async getDuration() { + async duration() { const bigNumber = await this.call('duration') return bigNumber.toNumber() } - async getCliff() { + async cliff() { const bigNumber = await this.call('cliff') return bigNumber.toNumber() } - getBeneficiary() { - return this.call('beneficiary') - } - - async getVestedAmount() { + async vestedAmount() { const bigNumber = await this.call('vestedAmount') return eth.utils.fromWei(bigNumber.toNumber()) } - async getReleasableAmount() { + async releasableAmount() { const bigNumber = await this.call('releasableAmount') return eth.utils.fromWei(bigNumber.toNumber()) } - isRevoked() { - return this.call('revoked') - } - - isRevocable() { - return this.call('revocable') - } - - getOwner() { - return this.call('owner') - } - - async getReleased() { + async released() { const bigNumber = await this.call('released') return eth.utils.fromWei(bigNumber.toNumber()) } - async getStart() { + async start() { const bigNumber = await this.call('start') return bigNumber.toNumber() } - - release() { - return this.transaction('release') - } - - changeBeneficiary(address) { - return this.transaction('changeBeneficiary', address) - } } diff --git a/src/contracts/LANDRegistry.js b/src/contracts/LANDRegistry.js index 46264a9..557cc54 100644 --- a/src/contracts/LANDRegistry.js +++ b/src/contracts/LANDRegistry.js @@ -68,66 +68,10 @@ export class LANDRegistry extends Contract { return abi } - getData(x, y) { - return this.call('landData', x, y) - } - - updateLandData(x, y, data) { - return this.transaction('updateLandData', x, y, data) - } - - updateManyLandData(coordinates, data) { + updateManyLandData(coordinates, data, opts = {}) { const x = coordinates.map(coor => coor.x) const y = coordinates.map(coor => coor.y) - return this.transaction('updateManyLandData', x, y, data) - } - - getOwner(x, y) { - return this.call('ownerOfLand', x, y) - } - - encodeTokenId(x, y) { - return this.call('encodeTokenId', x, y) - } - - decodeTokenId(value) { - return this.call('decodeTokenId', value) - } - - ping(x, y) { - return this.transaction('ping', x, y) - } - - exists(x, y) { - return this.call('exists', x, y) - } - - authorizeOperator(operator, isAuthorized) { - return this.transaction('authorizeOperator', operator, isAuthorized) - } - - isOperatorAuthorizedFor(operator, holder) { - return this.transaction('isOperatorAuthorizedFor', operator, holder) - } - - transferTo(x, y, newOwner) { - return this.transaction('transferLand', x, y, newOwner) - } - - assetsOf(address) { - return this.transaction('assetsOf', address) - } - - ownerOfLand(x, y) { - return this.call('ownerOfLand', x, y) - } - - ownerOfLandMany(x, y) { - return this.call('ownerOfLandMany', x, y) - } - - landOf(owner) { - return this.call('landOf', owner) + return this.transaction('updateManyLandData', x, y, data, opts) } assignNewParcel(x, y, address, opts = {}) { diff --git a/src/contracts/LANDTerraformSale.js b/src/contracts/LANDTerraformSale.js index dc0cdef..f25cdb7 100644 --- a/src/contracts/LANDTerraformSale.js +++ b/src/contracts/LANDTerraformSale.js @@ -1,9 +1,6 @@ import { abi } from './artifacts/LANDTerraformSale.json' import { Contract } from '../ethereum' import { env } from '../env' -import { Log } from '../log' - -const log = new Log('LANDTerraformSale') /** LANDTerraformSale contract class */ export class LANDTerraformSale extends Contract { @@ -18,25 +15,4 @@ export class LANDTerraformSale extends Contract { static getDefaultAbi() { return abi } - - buyMany(buyer, xList, yList, totalCost) { - log.info(`(buyMany) LAND for ${buyer}`) - return this.transaction('buyMany', buyer, xList, yList, totalCost, { - gas: 120000 - }) - } - - transferBackMANA(address, amount) { - log.info(`(transferBackMANA) ${amount} to ${address}`) - return this.transaction('transferBackMANA', address, amount, { - gas: 120000 - }) - } - - transferBackMANAMany(addresses, amounts) { - log.info(`(transferBackMANAMany) ${amounts} to ${addresses}`) - return this.transaction('transferBackMANAMany', addresses, amounts, { - gas: 120000 - }) - } } diff --git a/src/contracts/LANDTestSale.js b/src/contracts/LANDTestSale.js index 82efc5a..2de2af6 100644 --- a/src/contracts/LANDTestSale.js +++ b/src/contracts/LANDTestSale.js @@ -15,8 +15,4 @@ export class LANDTestSale extends Contract { static getDefaultAbi() { return abi } - - buy(x, y) { - return this.transaction('buy', x, y, { gas: 120000 }) - } } diff --git a/src/contracts/MANAToken.js b/src/contracts/MANAToken.js index 2bede18..9f85c20 100644 --- a/src/contracts/MANAToken.js +++ b/src/contracts/MANAToken.js @@ -20,21 +20,13 @@ export class MANAToken extends Contract { return this.transaction('approve', spender, eth.utils.toWei(mana)) } - async getAllowance(owner, spender) { - const assigned = await this.getAllowanceWei(owner, spender) + async allowance(owner, spender) { + const assigned = await this.call('allowance', owner, spender) return eth.utils.fromWei(assigned) } - getAllowanceWei(owner, spender) { - return this.call('allowance', owner, spender) - } - - async getBalance(owner) { - const manaBalance = await this.getBalanceWei(owner) + async balanceOf(owner) { + const manaBalance = await this.call('balanceOf', owner) return eth.utils.fromWei(manaBalance) } - - getBalanceWei(owner) { - return this.call('balanceOf', owner) - } } diff --git a/src/contracts/ReturnMANA.js b/src/contracts/ReturnMANA.js index 9554f50..c799181 100644 --- a/src/contracts/ReturnMANA.js +++ b/src/contracts/ReturnMANA.js @@ -1,9 +1,6 @@ import { abi } from './artifacts/ReturnMANA.json' import { Contract } from '../ethereum' import { env } from '../env' -import { Log } from '../log' - -const log = new Log('ReturnMANA') /** ReturnMANA contract class */ export class ReturnMANA extends Contract { @@ -18,36 +15,4 @@ export class ReturnMANA extends Contract { static getDefaultAbi() { return abi } - - burn(amount, opts = {}) { - log.info(`(burn) ${amount} MANA`) - - return this.transaction( - 'burn', - amount, - Object.assign({}, { gas: 120000 }, opts) - ) - } - - transferBackMANA(address, amount, opts = {}) { - log.info(`(transferBackMANA) ${amount} to ${address}`) - - return this.transaction( - 'transferBackMANA', - address, - amount, - Object.assign({}, { gas: 120000 }, opts) - ) - } - - transferBackMANAMany(addresses, amounts, opts = {}) { - log.info(`(transferBackMANAMany) ${amounts} to ${addresses}`) - - return this.transaction( - 'transferBackMANAMany', - addresses, - amounts, - Object.assign({}, { gas: 120000 }, opts) - ) - } } diff --git a/src/contracts/TerraformReserve.js b/src/contracts/TerraformReserve.js index cc09398..ceb73f9 100644 --- a/src/contracts/TerraformReserve.js +++ b/src/contracts/TerraformReserve.js @@ -1,9 +1,6 @@ import { abi } from './artifacts/TerraformReserve.json' import { eth, Contract } from '../ethereum' import { env } from '../env' -import { Log } from '../log' - -const log = new Log('TerraformReserve') /** TerraformReserve contract class */ export class TerraformReserve extends Contract { @@ -23,9 +20,8 @@ export class TerraformReserve extends Contract { return this.lockManaWei(sender, eth.utils.toWei(mana)) } - lockManaWei(sender, mana) { - log.info(`Locking ${mana}MANA for ${eth.getAddress()}`) + lockManaWei(sender, mana, opts = { gas: 1200 }) { eth.unlockAccount() - return this.transaction('lockMana', sender, mana, { gas: 120000 }) + return this.transaction('lockMana', sender, mana, opts) } } diff --git a/src/contracts/artifacts/MANAToken.json b/src/contracts/artifacts/MANAToken.json index 08b0e77..d32afa6 100644 --- a/src/contracts/artifacts/MANAToken.json +++ b/src/contracts/artifacts/MANAToken.json @@ -389,4 +389,4 @@ "networks": {}, "schema_version": "0.0.5", "updated_at": 1506676883426 -} +} \ No newline at end of file diff --git a/src/contracts/index.js b/src/contracts/index.js index f9528b0..cb59ca9 100644 --- a/src/contracts/index.js +++ b/src/contracts/index.js @@ -1,9 +1,279 @@ -// Abi accessible using the `.abi` property -export { DecentralandVesting } from './DecentralandVesting' -export { LANDRegistry } from './LANDRegistry' -export { LANDTerraformSale } from './LANDTerraformSale' -export { LANDTestSale } from './LANDTestSale' -export { MANAToken } from './MANAToken' -export { Marketplace } from './Marketplace' -export { ReturnMANA } from './ReturnMANA' -export { TerraformReserve } from './TerraformReserve' +// This is auto-generated code +// Changes here will be lost + +import { DecentralandVesting } from './DecentralandVesting' +import { LANDRegistry } from './LANDRegistry' +import { LANDTerraformSale } from './LANDTerraformSale' +import { LANDTestSale } from './LANDTestSale' +import { MANAToken } from './MANAToken' +import { Marketplace } from './Marketplace' +import { ReturnMANA } from './ReturnMANA' +import { TerraformReserve } from './TerraformReserve' + +Object.assign( + DecentralandVesting.prototype, + { + duration: function(...args) { + return this.call('duration', ...args) + }, + cliff: function(...args) { + return this.call('cliff', ...args) + }, + beneficiary: function(...args) { + return this.call('beneficiary', ...args) + }, + terraformReserve: function(...args) { + return this.call('terraformReserve', ...args) + }, + returnVesting: function(...args) { + return this.call('returnVesting', ...args) + }, + vestedAmount: function(...args) { + return this.call('vestedAmount', ...args) + }, + releasableAmount: function(...args) { + return this.call('releasableAmount', ...args) + }, + revoked: function(...args) { + return this.call('revoked', ...args) + }, + release: function(...args) { + return this.transaction('release', ...args) + }, + revocable: function(...args) { + return this.call('revocable', ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + released: function(...args) { + return this.call('released', ...args) + }, + releaseForeignToken: function(_token, amount, ...args) { + return this.transaction('releaseForeignToken', _token, amount, ...args) + }, + revoke: function(...args) { + return this.transaction('revoke', ...args) + }, + start: function(...args) { + return this.call('start', ...args) + }, + lockMana: function(amount, ...args) { + return this.transaction('lockMana', amount, ...args) + }, + releaseTo: function(target, ...args) { + return this.transaction('releaseTo', target, ...args) + }, + changeBeneficiary: function(target, ...args) { + return this.transaction('changeBeneficiary', target, ...args) + }, + transferOwnership: function(newOwner, ...args) { + return this.transaction('transferOwnership', newOwner, ...args) + }, + token: function(...args) { + return this.call('token', ...args) + } + }, + DecentralandVesting.prototype +) + +Object.assign( + LANDRegistry.prototype, + { + proxyOwner: function(...args) { + return this.call('proxyOwner', ...args) + }, + name: function(...args) { + return this.call('name', ...args) + }, + totalSupply: function(...args) { + return this.call('totalSupply', ...args) + }, + assetsOf: function(holder, ...args) { + return this.call('assetsOf', holder, ...args) + }, + safeHolderOf: function(assetId, ...args) { + return this.call('safeHolderOf', assetId, ...args) + }, + isOperatorAuthorizedFor: function(operator, assetHolder, ...args) { + return this.call( + 'isOperatorAuthorizedFor', + operator, + assetHolder, + ...args + ) + }, + currentContract: function(...args) { + return this.call('currentContract', ...args) + }, + description: function(...args) { + return this.call('description', ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + symbol: function(...args) { + return this.call('symbol', ...args) + }, + transfer: function(to, assetId, userData, operatorData, ...args) { + return this.transaction( + 'transfer', + to, + assetId, + userData, + operatorData, + ...args + ) + }, + assetData: function(assetId, ...args) { + return this.call('assetData', assetId, ...args) + }, + authorizeOperator: function(operator, authorized, ...args) { + return this.transaction( + 'authorizeOperator', + operator, + authorized, + ...args + ) + }, + safeAssetData: function(assetId, ...args) { + return this.call('safeAssetData', assetId, ...args) + }, + assetCount: function(holder, ...args) { + return this.call('assetCount', holder, ...args) + }, + assetByIndex: function(holder, index, ...args) { + return this.call('assetByIndex', holder, index, ...args) + }, + holderOf: function(assetId, ...args) { + return this.call('holderOf', assetId, ...args) + }, + transferOwnership: function(_newOwner, ...args) { + return this.transaction('transferOwnership', _newOwner, ...args) + }, + initialize: function(data, ...args) { + return this.transaction('initialize', data, ...args) + }, + authorizeDeploy: function(beneficiary, ...args) { + return this.transaction('authorizeDeploy', beneficiary, ...args) + }, + forbidDeploy: function(beneficiary, ...args) { + return this.transaction('forbidDeploy', beneficiary, ...args) + }, + assignNewParcel: function(x, y, beneficiary, ...args) { + return this.transaction('assignNewParcel', x, y, beneficiary, ...args) + }, + assignMultipleParcels: function(x, y, beneficiary, ...args) { + return this.transaction( + 'assignMultipleParcels', + x, + y, + beneficiary, + ...args + ) + }, + destroy: function(assetId, ...args) { + return this.transaction('destroy', assetId, ...args) + }, + ping: function(...args) { + return this.transaction('ping', ...args) + }, + setLatestToNow: function(user, ...args) { + return this.transaction('setLatestToNow', user, ...args) + }, + clearLand: function(x, y, ...args) { + return this.transaction('clearLand', x, y, ...args) + }, + encodeTokenId: function(x, y, ...args) { + return this.call('encodeTokenId', x, y, ...args) + }, + decodeTokenId: function(value, ...args) { + return this.call('decodeTokenId', value, ...args) + }, + exists: function(assetId, ...args) { + return this.call('exists', assetId, ...args) + }, + ownerOfLand: function(x, y, ...args) { + return this.call('ownerOfLand', x, y, ...args) + }, + ownerOfLandMany: function(x, y, ...args) { + return this.call('ownerOfLandMany', x, y, ...args) + }, + landOf: function(owner, ...args) { + return this.call('landOf', owner, ...args) + }, + landData: function(x, y, ...args) { + return this.call('landData', x, y, ...args) + }, + transferLand: function(x, y, to, ...args) { + return this.transaction('transferLand', x, y, to, ...args) + }, + transferManyLand: function(x, y, to, ...args) { + return this.transaction('transferManyLand', x, y, to, ...args) + }, + updateLandData: function(x, y, data, ...args) { + return this.transaction('updateLandData', x, y, data, ...args) + }, + updateManyLandData: function(x, y, data, ...args) { + return this.transaction('updateManyLandData', x, y, data, ...args) + } + }, + LANDRegistry.prototype +) + +Object.assign(LANDTerraformSale.prototype, {}, LANDTerraformSale.prototype) + +Object.assign(LANDTestSale.prototype, {}, LANDTestSale.prototype) + +Object.assign(MANAToken.prototype, {}, MANAToken.prototype) + +Object.assign(Marketplace.prototype, {}, Marketplace.prototype) + +Object.assign( + ReturnMANA.prototype, + { + transferBackMANAMany: function(_addresses, _amounts, ...args) { + return this.transaction( + 'transferBackMANAMany', + _addresses, + _amounts, + ...args + ) + }, + terraformReserve: function(...args) { + return this.call('terraformReserve', ...args) + }, + returnVesting: function(...args) { + return this.call('returnVesting', ...args) + }, + burnMana: function(_amount, ...args) { + return this.transaction('burnMana', _amount, ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + transferBackMANA: function(_address, _amount, ...args) { + return this.transaction('transferBackMANA', _address, _amount, ...args) + }, + transferOwnership: function(newOwner, ...args) { + return this.transaction('transferOwnership', newOwner, ...args) + }, + token: function(...args) { + return this.call('token', ...args) + } + }, + ReturnMANA.prototype +) + +Object.assign(TerraformReserve.prototype, {}, TerraformReserve.prototype) + +export { + DecentralandVesting, + LANDRegistry, + LANDTerraformSale, + LANDTestSale, + MANAToken, + Marketplace, + ReturnMANA, + TerraformReserve +} diff --git a/src/ethereum/Contract.js b/src/ethereum/Contract.js index fbd4f1e..1ee1999 100644 --- a/src/ethereum/Contract.js +++ b/src/ethereum/Contract.js @@ -28,6 +28,16 @@ export class Contract { throw new Error('Not implemented, please override `getDefaultAbi`') } + /** + * Get the contract events from the abi + * @return {Array} - events + */ + static getEvents() { + return this.getDefaultAbi() + .filter(method => method.type === 'event') + .map(event => event.name) + } + /** * Checks if an address is actually 0 in hex or a falsy value * @param {string} address diff --git a/src/ethereum/eth.js b/src/ethereum/eth.js index d19b267..f84cdd7 100644 --- a/src/ethereum/eth.js +++ b/src/ethereum/eth.js @@ -141,7 +141,7 @@ export const eth = { if (!this.contracts[name]) { const contractNames = Object.keys(this.contracts) throw new Error( - `The contract ${name} not found.\nDid you add it to the '.connect()' call?\nAvailable contracts are ${contractNames}` + `The contract ${name} not found.\nDid you add it to the '.connect()' call?\nAvailable contracts are "${contractNames}"` ) } From a38cb1d8ef68d5ea5b562456c91e3df439a3b8e5 Mon Sep 17 00:00:00 2001 From: Ariel Barmat Date: Tue, 20 Feb 2018 20:47:59 -0300 Subject: [PATCH 2/5] chore: remove unused contracts and update ABIs versions --- src/contracts/LANDTerraformSale.js | 18 -- src/contracts/LANDTestSale.js | 18 -- .../artifacts/LANDContinuousSale.json | 181 ------------ .../artifacts/LANDTerraformSale.json | 270 ------------------ src/contracts/artifacts/LANDTestSale.json | 69 ----- src/contracts/artifacts/MANAToken.json | 104 ++++--- src/contracts/artifacts/TerraformReserve.json | 20 +- 7 files changed, 77 insertions(+), 603 deletions(-) delete mode 100644 src/contracts/LANDTerraformSale.js delete mode 100644 src/contracts/LANDTestSale.js delete mode 100644 src/contracts/artifacts/LANDContinuousSale.json delete mode 100644 src/contracts/artifacts/LANDTerraformSale.json delete mode 100644 src/contracts/artifacts/LANDTestSale.json diff --git a/src/contracts/LANDTerraformSale.js b/src/contracts/LANDTerraformSale.js deleted file mode 100644 index f25cdb7..0000000 --- a/src/contracts/LANDTerraformSale.js +++ /dev/null @@ -1,18 +0,0 @@ -import { abi } from './artifacts/LANDTerraformSale.json' -import { Contract } from '../ethereum' -import { env } from '../env' - -/** LANDTerraformSale contract class */ -export class LANDTerraformSale extends Contract { - static getContractName() { - return 'LANDTerraformSale' - } - - static getDefaultAddress() { - return env.universalGet('LAND_TERRAFORM_SALE_CONTRACT_ADDRESS') - } - - static getDefaultAbi() { - return abi - } -} diff --git a/src/contracts/LANDTestSale.js b/src/contracts/LANDTestSale.js deleted file mode 100644 index 2de2af6..0000000 --- a/src/contracts/LANDTestSale.js +++ /dev/null @@ -1,18 +0,0 @@ -import { abi } from './artifacts/LANDTestSale.json' -import { Contract } from '../ethereum' -import { env } from '../env' - -/** LANDTestSale contract class */ -export class LANDTestSale extends Contract { - static getContractName() { - return 'LANDTestSale' - } - - static getDefaultAddress() { - return env.universalGet('LAND_TEST_SALE_CONTRACT_ADDRESS') - } - - static getDefaultAbi() { - return abi - } -} diff --git a/src/contracts/artifacts/LANDContinuousSale.json b/src/contracts/artifacts/LANDContinuousSale.json deleted file mode 100644 index 49fb943..0000000 --- a/src/contracts/artifacts/LANDContinuousSale.json +++ /dev/null @@ -1,181 +0,0 @@ -{ - "contract_name": "LANDContinuousSale", - "abi": [ - { - "constant": true, - "inputs": [ - { - "name": "_x", - "type": "uint256" - }, - { - "name": "_y", - "type": "uint256" - } - ], - "name": "buildTokenId", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "LAND_MANA_COST", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_x", - "type": "uint256" - }, - { - "name": "_y", - "type": "uint256" - } - ], - "name": "exists", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "land", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "owner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_x", - "type": "uint256" - }, - { - "name": "_y", - "type": "uint256" - }, - { - "name": "_data", - "type": "string" - } - ], - "name": "buy", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "token", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "inputs": [ - { - "name": "_token", - "type": "address" - }, - { - "name": "_land", - "type": "address" - } - ], - "payable": false, - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "info", - "type": "string" - } - ], - "name": "Log", - "type": "event" - } - ], - "networks": {}, - "schema_version": "0.0.5", - "updated_at": 1510180090541 -} diff --git a/src/contracts/artifacts/LANDTerraformSale.json b/src/contracts/artifacts/LANDTerraformSale.json deleted file mode 100644 index 4aa1f41..0000000 --- a/src/contracts/artifacts/LANDTerraformSale.json +++ /dev/null @@ -1,270 +0,0 @@ -{ - "contract_name": "LANDTerraformSale", - "abi": [ - { - "constant": false, - "inputs": [ - { - "name": "_buyer", - "type": "address" - }, - { - "name": "_x", - "type": "uint256" - }, - { - "name": "_y", - "type": "uint256" - }, - { - "name": "_cost", - "type": "uint256" - } - ], - "name": "buy", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "x", - "type": "uint256" - }, - { - "name": "y", - "type": "uint256" - } - ], - "name": "buildTokenId", - "outputs": [ - { - "name": "", - "type": "uint256" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "terraformReserve", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "x", - "type": "uint256" - }, - { - "name": "y", - "type": "uint256" - } - ], - "name": "exists", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_buyer", - "type": "address" - }, - { - "name": "_x", - "type": "uint256[]" - }, - { - "name": "_y", - "type": "uint256[]" - }, - { - "name": "_totalCost", - "type": "uint256" - } - ], - "name": "buyMany", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "land", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "owner", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_address", - "type": "address" - }, - { - "name": "_amount", - "type": "uint256" - } - ], - "name": "transferBackMANA", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "returnRegistry", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_newOwner", - "type": "address" - } - ], - "name": "transferLandOwnership", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "EMPTY_METADATA", - "outputs": [ - { - "name": "", - "type": "string" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "token", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "inputs": [ - { - "name": "_token", - "type": "address" - }, - { - "name": "_terraformReserve", - "type": "address" - }, - { - "name": "_returnRegistry", - "type": "address" - } - ], - "payable": false, - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "name": "info", - "type": "string" - } - ], - "name": "Log", - "type": "event" - } - ], - "networks": {}, - "schema_version": "0.0.5", - "updated_at": 1509562879434 -} diff --git a/src/contracts/artifacts/LANDTestSale.json b/src/contracts/artifacts/LANDTestSale.json deleted file mode 100644 index 7a2f46f..0000000 --- a/src/contracts/artifacts/LANDTestSale.json +++ /dev/null @@ -1,69 +0,0 @@ -{ - "contract_name": "LANDTestSale", - "abi": [ - { - "constant": true, - "inputs": [], - "name": "land", - "outputs": [ - { - "name": "", - "type": "address" - } - ], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_x", - "type": "uint256" - }, - { - "name": "_y", - "type": "uint256" - }, - { - "name": "_data", - "type": "string" - } - ], - "name": "buy", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "beneficiary", - "type": "address" - }, - { - "name": "tokenId", - "type": "uint256" - } - ], - "name": "claimForgottenParcel", - "outputs": [], - "payable": false, - "type": "function" - }, - { - "inputs": [ - { - "name": "_land", - "type": "address" - } - ], - "payable": false, - "type": "constructor" - } - ], - "networks": {}, - "schema_version": "0.0.5", - "updated_at": 1510568621893 -} diff --git a/src/contracts/artifacts/MANAToken.json b/src/contracts/artifacts/MANAToken.json index d32afa6..f28f7b4 100644 --- a/src/contracts/artifacts/MANAToken.json +++ b/src/contracts/artifacts/MANAToken.json @@ -1,5 +1,5 @@ { - "contract_name": "MANAToken", + "contractName": "MANAToken", "abi": [ { "constant": true, @@ -12,6 +12,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -25,6 +26,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -47,6 +49,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -60,6 +63,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -86,6 +90,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -99,6 +104,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -112,6 +118,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -134,6 +141,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -147,6 +155,7 @@ "name": "burn", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -160,24 +169,7 @@ } ], "payable": false, - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "name": "_owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "name": "balance", - "type": "uint256" - } - ], - "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -191,6 +183,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -204,6 +197,7 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -217,6 +211,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -230,28 +225,7 @@ } ], "payable": false, - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "name": "_to", - "type": "address" - }, - { - "name": "_value", - "type": "uint256" - } - ], - "name": "transfer", - "outputs": [ - { - "name": "", - "type": "bool" - } - ], - "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -274,6 +248,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -287,6 +262,7 @@ "name": "transferOwnership", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -384,9 +360,51 @@ ], "name": "Transfer", "type": "event" + }, + { + "constant": true, + "inputs": [ + { + "name": "_owner", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "balance", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "_to", + "type": "address" + }, + { + "name": "_value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" } ], "networks": {}, - "schema_version": "0.0.5", - "updated_at": 1506676883426 + "schemaVersion": "1.0.1", + "updatedAt": "2018-02-20T20:47:14.751Z" } \ No newline at end of file diff --git a/src/contracts/artifacts/TerraformReserve.json b/src/contracts/artifacts/TerraformReserve.json index 6282b5b..4ece10a 100644 --- a/src/contracts/artifacts/TerraformReserve.json +++ b/src/contracts/artifacts/TerraformReserve.json @@ -1,5 +1,5 @@ { - "contract_name": "TerraformReserve", + "contractName": "TerraformReserve", "abi": [ { "constant": false, @@ -12,6 +12,7 @@ "name": "setTargetContract", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -25,6 +26,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -38,6 +40,7 @@ "name": "changeContractState", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -55,6 +58,7 @@ "name": "lockMana", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -68,6 +72,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -81,6 +86,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -94,6 +100,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -112,6 +119,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -125,6 +133,7 @@ } ], "payable": false, + "stateMutability": "view", "type": "function" }, { @@ -138,6 +147,7 @@ "name": "transferOwnership", "outputs": [], "payable": false, + "stateMutability": "nonpayable", "type": "function" }, { @@ -148,10 +158,12 @@ } ], "payable": false, + "stateMutability": "nonpayable", "type": "constructor" }, { "payable": true, + "stateMutability": "payable", "type": "fallback" }, { @@ -219,6 +231,6 @@ } ], "networks": {}, - "schema_version": "0.0.5", - "updated_at": 1506660336299 -} + "schemaVersion": "1.0.1", + "updatedAt": "2018-02-20T20:47:14.761Z" +} \ No newline at end of file From 5c3323789e92dd4319dca29483a2fc72d1eb2ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Wed, 21 Feb 2018 12:37:42 +0100 Subject: [PATCH 3/5] chore: Build new contracts --- scripts/contracts/ContractFile.js | 7 +- src/contracts/index.js | 110 +++++++++++++++++++++++++++--- 2 files changed, 104 insertions(+), 13 deletions(-) diff --git a/scripts/contracts/ContractFile.js b/scripts/contracts/ContractFile.js index 95add47..df5c3df 100644 --- a/scripts/contracts/ContractFile.js +++ b/scripts/contracts/ContractFile.js @@ -33,9 +33,10 @@ export class ContractFile { switch (type) { case 'function': { - const args = [...inputs.map(input => input.name), '...args'].join( - ', ' - ) + const args = [ + ...inputs.map((input, index) => input.name || `input${index}`), + '...args' + ].join(', ') if (stateMutability === 'view') { extensions[name] = `function(${args}) { diff --git a/src/contracts/index.js b/src/contracts/index.js index cb59ca9..17e5a3c 100644 --- a/src/contracts/index.js +++ b/src/contracts/index.js @@ -3,8 +3,6 @@ import { DecentralandVesting } from './DecentralandVesting' import { LANDRegistry } from './LANDRegistry' -import { LANDTerraformSale } from './LANDTerraformSale' -import { LANDTestSale } from './LANDTestSale' import { MANAToken } from './MANAToken' import { Marketplace } from './Marketplace' import { ReturnMANA } from './ReturnMANA' @@ -221,11 +219,66 @@ Object.assign( LANDRegistry.prototype ) -Object.assign(LANDTerraformSale.prototype, {}, LANDTerraformSale.prototype) - -Object.assign(LANDTestSale.prototype, {}, LANDTestSale.prototype) - -Object.assign(MANAToken.prototype, {}, MANAToken.prototype) +Object.assign( + MANAToken.prototype, + { + mintingFinished: function(...args) { + return this.call('mintingFinished', ...args) + }, + name: function(...args) { + return this.call('name', ...args) + }, + approve: function(_spender, _value, ...args) { + return this.transaction('approve', _spender, _value, ...args) + }, + totalSupply: function(...args) { + return this.call('totalSupply', ...args) + }, + transferFrom: function(_from, _to, _value, ...args) { + return this.transaction('transferFrom', _from, _to, _value, ...args) + }, + decimals: function(...args) { + return this.call('decimals', ...args) + }, + unpause: function(...args) { + return this.transaction('unpause', ...args) + }, + mint: function(_to, _amount, ...args) { + return this.transaction('mint', _to, _amount, ...args) + }, + burn: function(_value, ...args) { + return this.transaction('burn', _value, ...args) + }, + paused: function(...args) { + return this.call('paused', ...args) + }, + finishMinting: function(...args) { + return this.transaction('finishMinting', ...args) + }, + pause: function(...args) { + return this.transaction('pause', ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + symbol: function(...args) { + return this.call('symbol', ...args) + }, + allowance: function(_owner, _spender, ...args) { + return this.call('allowance', _owner, _spender, ...args) + }, + transferOwnership: function(newOwner, ...args) { + return this.transaction('transferOwnership', newOwner, ...args) + }, + balanceOf: function(_owner, ...args) { + return this.call('balanceOf', _owner, ...args) + }, + transfer: function(_to, _value, ...args) { + return this.transaction('transfer', _to, _value, ...args) + } + }, + MANAToken.prototype +) Object.assign(Marketplace.prototype, {}, Marketplace.prototype) @@ -265,13 +318,50 @@ Object.assign( ReturnMANA.prototype ) -Object.assign(TerraformReserve.prototype, {}, TerraformReserve.prototype) +Object.assign( + TerraformReserve.prototype, + { + setTargetContract: function(target, ...args) { + return this.transaction('setTargetContract', target, ...args) + }, + totalLocked: function(...args) { + return this.call('totalLocked', ...args) + }, + changeContractState: function(_acceptingDeposits, ...args) { + return this.transaction( + 'changeContractState', + _acceptingDeposits, + ...args + ) + }, + lockMana: function(_from, mana, ...args) { + return this.transaction('lockMana', _from, mana, ...args) + }, + manaToken: function(...args) { + return this.call('manaToken', ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + landClaim: function(...args) { + return this.call('landClaim', ...args) + }, + lockedBalance: function(input0, ...args) { + return this.call('lockedBalance', input0, ...args) + }, + acceptingDeposits: function(...args) { + return this.call('acceptingDeposits', ...args) + }, + transferOwnership: function(newOwner, ...args) { + return this.transaction('transferOwnership', newOwner, ...args) + } + }, + TerraformReserve.prototype +) export { DecentralandVesting, LANDRegistry, - LANDTerraformSale, - LANDTestSale, MANAToken, Marketplace, ReturnMANA, From 7dcf3746e9d882ba2a329bb1203dcc98bdf59af4 Mon Sep 17 00:00:00 2001 From: Ariel Barmat Date: Thu, 22 Feb 2018 10:21:46 -0300 Subject: [PATCH 4/5] chore: update ABI of Marketplace contract --- src/contracts/artifacts/Marketplace.json | 294 ++++++++++++++++++++++- 1 file changed, 290 insertions(+), 4 deletions(-) diff --git a/src/contracts/artifacts/Marketplace.json b/src/contracts/artifacts/Marketplace.json index 3511c8e..0661c9f 100644 --- a/src/contracts/artifacts/Marketplace.json +++ b/src/contracts/artifacts/Marketplace.json @@ -1,8 +1,294 @@ { "contractName": "Marketplace", - "abi": [], - "compiler": {}, + "abi": [ + { + "constant": false, + "inputs": [ + { + "name": "ownerCut", + "type": "uint8" + } + ], + "name": "setOwnerCut", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "assetId", + "type": "uint256" + } + ], + "name": "cancelOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "uint256" + } + ], + "name": "auctionList", + "outputs": [ + { + "name": "seller", + "type": "address" + }, + { + "name": "price", + "type": "uint256" + }, + { + "name": "startedAt", + "type": "uint256" + }, + { + "name": "expiresAt", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "ownerCutPercentage", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "owner", + "outputs": [ + { + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "assetId", + "type": "uint256" + } + ], + "name": "executeOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "assetId", + "type": "uint256" + }, + { + "name": "priceInWei", + "type": "uint256" + }, + { + "name": "expiresAt", + "type": "uint256" + } + ], + "name": "createOrder", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "publicationFeeInWei", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "publicationFee", + "type": "uint256" + } + ], + "name": "setPublicationFee", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "name": "_acceptedToken", + "type": "address" + }, + { + "name": "_nonFungibleRegistry", + "type": "address" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "assetId", + "type": "uint256" + }, + { + "indexed": true, + "name": "creator", + "type": "address" + }, + { + "indexed": false, + "name": "priceInWei", + "type": "uint256" + }, + { + "indexed": false, + "name": "expiresAt", + "type": "uint256" + } + ], + "name": "AuctionCreated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "assetId", + "type": "uint256" + }, + { + "indexed": false, + "name": "totalPrice", + "type": "uint256" + }, + { + "indexed": true, + "name": "winner", + "type": "address" + } + ], + "name": "AuctionSuccessful", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "assetId", + "type": "uint256" + } + ], + "name": "AuctionCancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "publicationFee", + "type": "uint256" + } + ], + "name": "ChangedPublicationFee", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "name": "ownerCut", + "type": "uint256" + } + ], + "name": "ChangedOwnerCut", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + } + ], + "compiler": { + "name": "solc", + "version": "0.4.19+commit.c4cbbb05.Emscripten.clang" + }, "networks": {}, "schemaVersion": "1.0.1", - "updatedAt": "2018-01-20T20:59:16.190Z" -} + "updatedAt": "2018-02-22T03:32:21.886Z" +} \ No newline at end of file From 450242b46d526b735d8ada58c4689fd33d18006e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Thu, 22 Feb 2018 14:30:05 +0100 Subject: [PATCH 5/5] chore: Build contracts --- src/contracts/index.js | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/contracts/index.js b/src/contracts/index.js index 17e5a3c..29e43d9 100644 --- a/src/contracts/index.js +++ b/src/contracts/index.js @@ -280,7 +280,48 @@ Object.assign( MANAToken.prototype ) -Object.assign(Marketplace.prototype, {}, Marketplace.prototype) +Object.assign( + Marketplace.prototype, + { + setOwnerCut: function(ownerCut, ...args) { + return this.transaction('setOwnerCut', ownerCut, ...args) + }, + cancelOrder: function(assetId, ...args) { + return this.transaction('cancelOrder', assetId, ...args) + }, + auctionList: function(input0, ...args) { + return this.call('auctionList', input0, ...args) + }, + ownerCutPercentage: function(...args) { + return this.call('ownerCutPercentage', ...args) + }, + owner: function(...args) { + return this.call('owner', ...args) + }, + executeOrder: function(assetId, ...args) { + return this.transaction('executeOrder', assetId, ...args) + }, + createOrder: function(assetId, priceInWei, expiresAt, ...args) { + return this.transaction( + 'createOrder', + assetId, + priceInWei, + expiresAt, + ...args + ) + }, + publicationFeeInWei: function(...args) { + return this.call('publicationFeeInWei', ...args) + }, + setPublicationFee: function(publicationFee, ...args) { + return this.transaction('setPublicationFee', publicationFee, ...args) + }, + transferOwnership: function(newOwner, ...args) { + return this.transaction('transferOwnership', newOwner, ...args) + } + }, + Marketplace.prototype +) Object.assign( ReturnMANA.prototype,