diff --git a/contracts/IdaFactory.sol b/contracts/IdaFactory.sol index f7d76b7..bdf9501 100644 --- a/contracts/IdaFactory.sol +++ b/contracts/IdaFactory.sol @@ -17,14 +17,14 @@ contract IdaFactory { event IdaCreated(address indexed ida); - SimpleTokenSellerFactory simpleTokenSellerFactory; ImpactPromiseFactory impactPromiseFactory; FluidEscrowFactory fluidEscrowFactory; ClaimsRegistry public claimsRegistry; + SimpleTokenSeller public simpleTokenSeller; - constructor(SimpleTokenSellerFactory _simpleTokenSellerFactory, ImpactPromiseFactory _impactPromiseFactory, FluidEscrowFactory _fluidEscrowFactory, ClaimsRegistry _claimsRegistry) public { - simpleTokenSellerFactory = _simpleTokenSellerFactory; + constructor(SimpleTokenSellerFactory _stsFactory, ImpactPromiseFactory _impactPromiseFactory, FluidEscrowFactory _fluidEscrowFactory, ClaimsRegistry _claimsRegistry) public { + simpleTokenSeller = _stsFactory.createSimpleTokenSeller(); impactPromiseFactory = _impactPromiseFactory; fluidEscrowFactory = _fluidEscrowFactory; claimsRegistry = _claimsRegistry; @@ -45,8 +45,7 @@ contract IdaFactory { Ida ida = new Ida(_paymentToken, promiseToken, escrow, claimsRegistry, _name, _outcomesNumber, _outcomesPrice, _validator, _endTime, msg.sender); escrow.transferOwnership(address(ida)); promiseToken.addMinter(address(ida)); - //SimpleTokenSeller sts = simpleTokenSellerFactory.createSimpleTokenSeller(ida.paymentToken(), ida.paymentRights(), msg.sender); - + simpleTokenSeller.addMarket(msg.sender, PaymentRights(escrow.recipient()), _paymentToken); emit IdaCreated(address(ida)); return ida; } diff --git a/contracts/SimpleTokenSeller.sol b/contracts/SimpleTokenSeller.sol index 3704299..376e937 100644 --- a/contracts/SimpleTokenSeller.sol +++ b/contracts/SimpleTokenSeller.sol @@ -9,7 +9,7 @@ import './PaymentRights.sol'; * by automatically deploying and linking payment rights seller contract * */ -contract SimpleTokenSeller is Ownable { +contract SimpleTokenSeller { using SafeMath for uint256; event MarketAdded(address indexed operator, PaymentRights offeredToken, ERC20 indexed paymentToken); @@ -27,7 +27,7 @@ contract SimpleTokenSeller is Ownable { mapping (address => Market) public markets; - function addMarket(address _operator, PaymentRights _offeredToken, ERC20 _paymentToken) public onlyOwner { + function addMarket(address _operator, PaymentRights _offeredToken, ERC20 _paymentToken) public { markets[_operator] = Market(_paymentToken, _offeredToken, 0, 0); emit MarketAdded(_operator, _offeredToken, _paymentToken); } @@ -81,6 +81,20 @@ contract SimpleTokenSeller is Ownable { return FULL_PERCENTAGE.sub(market.discount).mul(unRedeemedAmount).div(FULL_PERCENTAGE); } + function getSupply(address operator) public view returns(uint256) { + Market storage market = markets[operator]; + require(address(market.paymentToken) != address(0), "There is no market defined for a given Ida"); + + return market.supply; + } + + function getDiscount(address operator) public view returns(uint256) { + Market storage market = markets[operator]; + require(address(market.paymentToken) != address(0), "There is no market defined for a given Ida"); + + return market.discount; + } + } contract SimpleTokenSellerFactory { diff --git a/test/ida-factory.test.js b/test/ida-factory.test.js index f661923..79d6be1 100644 --- a/test/ida-factory.test.js +++ b/test/ida-factory.test.js @@ -31,17 +31,16 @@ contract('Ida Factory', function ([owner, validator, investor, unauthorised]) { let escrowFactory = await FluidEscrowFactory.new(); claimsRegistry = await ClaimsRegistry.new(); factory = await IdaFactory.new(stsFactory.address, impactPromiseFactory.address, escrowFactory.address, claimsRegistry.address, {gas: 6500000}); + sts = await Sts.at(await factory.simpleTokenSeller()); }); it("should create a new Ida", async function () { let end = (await time.latest()).add(time.duration.years(1)); - let tx = await factory.createIda(usd.address, "TEST", 10, 100, validator, end, {gas: 7000000}); + let tx = await factory.createIda(usd.address, "TEST", 10, 100, validator, end, {gas: 6000000}); console.log("Gas used: " + tx.receipt.gasUsed); let idaAddress = tx.receipt.logs[0].args.ida; - let stsAddress = tx.receipt.logs[0].args.sts; ida = await Ida.at(idaAddress); - sts = await Sts.at(stsAddress); paymentRights = await FluidToken.at(await ida.paymentRights()); (await paymentRights.balanceOf(owner)).should.be.bignumber.equal('1000'); @@ -60,7 +59,7 @@ contract('Ida Factory', function ([owner, validator, investor, unauthorised]) { it("should not allow buying before price is set up", async function () { await usd.mint(investor, 100); - await sts.buy(100, {from: investor}).shouldBeReverted(); + await sts.buy(owner, 100, {from: investor}).shouldBeReverted(); }); @@ -73,15 +72,15 @@ contract('Ida Factory', function ([owner, validator, investor, unauthorised]) { it("should allow updating conditions by owner", async function () { await sts.updateConditions(100, 50, {from: owner}); - (await sts.currentSupply()).should.be.bignumber.equal('100'); - (await sts.currentDiscount()).should.be.bignumber.equal('50'); + (await sts.getSupply(owner)).should.be.bignumber.equal('100'); + (await sts.getDiscount(owner)).should.be.bignumber.equal('50'); }); it("should buy tokens by investor", async function () { await usd.approve(sts.address, 100, {from:investor}); - await sts.buy(50, {from: investor}); + await sts.buy(owner, 50, {from: investor}); (await usd.balanceOf(owner)).should.be.bignumber.equal('25'); (await usd.balanceOf(investor)).should.be.bignumber.equal('75'); diff --git a/test/ida.test.js b/test/ida.test.js index 4e9e3d3..5685bc3 100644 --- a/test/ida.test.js +++ b/test/ida.test.js @@ -28,6 +28,7 @@ contract('Impact Delivery Agreement', function ([owner, validator, funder, inves let escrowFactory = await FluidEscrowFactory.new(); claimsRegistry = await ClaimsRegistry.new(); factory = await IdaFactory.new(stsFactory.address, impactPromiseFactory.address, escrowFactory.address, claimsRegistry.address, {gas: 6500000}); + sts = await Sts.at(await factory.simpleTokenSeller()); }); @@ -37,9 +38,7 @@ contract('Impact Delivery Agreement', function ([owner, validator, funder, inves console.log("Gas used for Ida deployment: " + tx.receipt.gasUsed); let idaAddress = tx.receipt.logs[0].args.ida; - let stsAddress = tx.receipt.logs[0].args.sts; ida = await Ida.at(idaAddress); - sts = await Sts.at(stsAddress); paymentRights = await FluidToken.at(await ida.paymentRights()); (await paymentRights.balanceOf(owner)).should.be.bignumber.equal('1000'); @@ -68,7 +67,7 @@ contract('Impact Delivery Agreement', function ([owner, validator, funder, inves (await ausd.balanceOf(investor)).should.be.bignumber.equal('100'); (await paymentRights.balanceOf(investor)).should.be.bignumber.equal('0'); - await sts.buy(100, {from: investor}); + await sts.buy(owner, 100, {from: investor}); (await ausd.balanceOf(owner)).should.be.bignumber.equal('50'); (await ausd.balanceOf(investor)).should.be.bignumber.equal('50');