Skip to content

Commit

Permalink
Merge crowdsale
Browse files Browse the repository at this point in the history
  • Loading branch information
tiero committed Oct 15, 2017
1 parent 514b293 commit 39645a2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 34 deletions.
4 changes: 2 additions & 2 deletions dao/contracts/agent/Agent.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity ^0.4.15;

import "./AgentInterface.sol";
import "../marketjob/MarketJobInterface.sol";
// import "../marketjob/MarketJobInterface.sol";
import "../ownership/ownable.sol";

contract Agent is AgentInterface, ownable {
Expand All @@ -24,7 +24,7 @@ contract Agent is AgentInterface, ownable {
return packets[id];
}

function setJob(MarketJobInterface _job) external returns (address) {
function setJob(MarketJob _job) external returns (address) {
job = _job;
}

Expand Down
4 changes: 3 additions & 1 deletion dao/contracts/agent/AgentInterface.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pragma solidity ^0.4.15;

import "../marketJob/MarketJob.sol";

contract AgentInterface {

function sendPacket(address target, bytes packet) external;
function appendPacket(bytes packet) external;
function getPacket(uint id) external constant returns (bytes);
function appendJob(address[] agents, uint[] amounts, address payer, bytes firstPacket, bytes lastPacket) external constant returns (address);
function setJob(MarketJob _job) external returns (address);

}
2 changes: 1 addition & 1 deletion dao/contracts/marketjob/MarketJob.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.15;

import "./ownership/ownable.sol";
import "../ownership/ownable.sol";
import "./MarketJobInterface.sol";

contract MarketJob is MarketJobInterface, ownable {
Expand Down
7 changes: 3 additions & 4 deletions dao/contracts/registries/AgentRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract AgentRegistry is AgentRegistryInterface {

address[] public agents;

mapping (uint => Service) services;
mapping (uint => Service[]) services;

mapping (uint => uint[]) agentsForService;

Expand All @@ -24,9 +24,8 @@ contract AgentRegistry is AgentRegistryInterface {
}

function addAgent(uint service, uint unit, uint price, address agent) external {
require(services[service].unit == 0 && services[service].pricePerUnit == 0);

services[service] = Service(unit, price);
// require(services[service].unit == 0 && services[service].pricePerUnit == 0);
services[service].push(Service(unit, price));

uint id = agents.length;

Expand Down
19 changes: 4 additions & 15 deletions dao/migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
const fs = require('fs')

const Escrow = artifacts.require('Escrow.sol')
const Agent = artifacts.require('agent/Agent.sol')
const AgentFactory = artifacts.require('agent/AgentFactory.sol')
const MarketJob = artifacts.require('MarketJob.sol')
const ownable = artifacts.require('ownership/ownable.sol')
const AgentFactory = artifacts.require('agent/AgentFactory.sol')
const AgentRegistry = artifacts.require('registries/AgentRegistry.sol')
const SingularityNetToken = artifacts.require('tokens/SingularityNetToken.sol')
const Escrow = artifacts.require('Escrow.sol')
const ownable = artifacts.require('ownership/ownable.sol')
const AgiCrowdsale = artifacts.require("AgiCrowdsale.sol")

module.exports = function(deployer, network, accounts) {
const startTime = 1 // one second in the future
const endTime = startTime + (86400 * 20) // 20 days
const rate = 10000000
const wallet = accounts[0]
const goal = 8 * 1000
const cap = 10 * 1000
console.log(startTime,endTime,rate,cap,goal,wallet)


deployer.deploy([
Agent,
Escrow,
ownable,
MarketJob,
AgentFactory,
AgentRegistry,
SingularityNetToken,
// [AgiCrowdsale, startTime, endTime, rate, goal, cap, wallet]
SingularityNetToken
]).then(() => {
const fileName = "addresses.json"
const content = {
Expand Down
31 changes: 31 additions & 0 deletions dao/migrations/3_deploy_crowdsale_contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs')
const AgiCrowdsale = artifacts.require("AgiCrowdsale.sol")

module.exports = function(deployer, network, accounts) {
const startTime = web3.eth.getBlock(web3.eth.blockNumber).timestamp + 1 // one second in the future
const endTime = startTime + (86400 * 20) // 20 days
const rate = new web3.BigNumber(1000)
const wallet = accounts[0]
const goal = 8 * 1000
const cap = 10 * 1000

console.log(startTime,endTime,cap,goal,wallet)

deployer.deploy(
AgiCrowdsale, startTime, endTime, rate, goal, cap, wallet
).then(() => {
const fileName = "addresses.json"

fs.readFile(fileName, (err, data) => {
if (!err) {
let content = JSON.parse(data.toString())
content["AgiCrowdsale"] = AgiCrowdsale.address

fs.writeFile(fileName, JSON.stringify(content), 'utf-8', (err) => {
if (err) { throw err }
console.log("Added AgiCrowdsale to " + fileName)
})
}
})
})
};
24 changes: 13 additions & 11 deletions dao/test/TestAgent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Agent = artifacts.require('agent/Agent.sol')
const Market = artifacts.require('MarketJob.sol')
const Market = artifacts.require('marketJob/MarketJob.sol')

contract('Agent', function (accounts) {

Expand Down Expand Up @@ -42,19 +42,21 @@ contract('Agent', function (accounts) {
})

it('verifies that master agent can create a Market Job', async () => {
let market = await agent.appendJob(
[agent.address, "0x1", "0x2", "0x3"], // agents
[30, 20, 30, 20], // amounts
accounts[2], // payer address
"0x0", "0x0101" // first and last packet
)

assert.isNotNull(market)
let marketJob = await Market.new(
[agent.address, accounts[1], accounts[2], accounts[3]], // agents
[30, 20, 30, 20], // amounts
accounts[4], // payer address
"0x0", "0x0101", // first and last packet)
{value: 2000}
)
// let market = await agent.setJob(marketJob)

assert.isNotNull(marketJob)
})

it('verifies that any agent allowed can be payed for its job', async () => {
let market = await Market.new(
[accounts[0], accounts[1], accounts[2], accounts[3]], // agents
[agent.address, accounts[1], accounts[2], accounts[3]], // agents
[30, 20, 30, 20], // amounts
accounts[4], // payer address
"0x0", "0x0101", // first and last packet
Expand All @@ -63,7 +65,7 @@ contract('Agent', function (accounts) {

await market.setJobCompleted()

let result = await market.withdraw({from: accounts[0], value: 30})
let result = await market.withdraw({from: accounts[1]})

assert.isNotNull(result)
})
Expand Down

0 comments on commit 39645a2

Please sign in to comment.