Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Update exchangeRate to be expressed in PPM
Browse files Browse the repository at this point in the history
  • Loading branch information
osarrouy committed Sep 20, 2019
1 parent 3a41d50 commit 3d2f183
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions apps/presale/contracts/Presale.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract Presale is EtherTokenConstant, IsContract, AragonApp {
* @param _contributionToken The address of the token to be used to contribute
* @param _goal The goal to be reached by the end of that presale [in contribution token wei]
* @param _period The period within which to accept contribution for that presale
* @param _exchangeRate The exchangeRate [= 1/price] at which [bonded] tokens are to be purchased for that presale
* @param _exchangeRate The exchangeRate [= 1/price] at which [bonded] tokens are to be purchased for that presale [in PPM]
* @param _vestingCliffPeriod The period during which purchased [bonded] tokens are to be cliffed
* @param _vestingCompletePeriod The complete period during which purchased [bonded] tokens are to be vested
* @param _supplyOfferedPct The percentage of the initial supply of [bonded] tokens to be offered during that presale [in PPM]
Expand Down Expand Up @@ -199,7 +199,7 @@ contract Presale is EtherTokenConstant, IsContract, AragonApp {
* @param _value The amount of contribution tokens to be used in that computation
*/
function contributionToTokens(uint256 _value) public view isInitialized returns (uint256) {
return _value.mul(exchangeRate);
return _value.mul(exchangeRate).div(PPM);
}

/**
Expand Down
19 changes: 5 additions & 14 deletions apps/presale/test/Contribute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,30 +126,21 @@ contract('Presale, contribute() functionality', ([anyone, appManager, buyer1, bu
})

it('Keeps track of independent purchases', async () => {
(await this.presale.contributions(buyer1, 0)).should.be.bignumber.equal(contributionAmount)
;(await this.presale.contributions(buyer1, 0)).should.be.bignumber.equal(contributionAmount)
expect((await this.presale.contributions(buyer2, 0)).toNumber()).to.equal(1)
expect((await this.presale.contributions(buyer2, 1)).toNumber()).to.equal(2)
expect((await this.presale.contributions(buyer2, 2)).toNumber()).to.equal(3)
})

if (!useETH) {
it('Reverts when sending ETH in a contribution that\'s supposed to use ERC20 tokens', async () => {
await assertRevert(
contribute(buyer1, '10e18', true),
'PRESALE_INCORRECT_ETH_VALUE'
)
it("Reverts when sending ETH in a contribution that's supposed to use ERC20 tokens", async () => {
await assertRevert(contribute(buyer1, '10e18', true), 'PRESALE_INCORRECT_ETH_VALUE')
})
} else {
it('Reverts if the ETH amount sent does not match the specified amount', async () => {
const amount = 2
await assertRevert(
this.presale.contribute(buyer1, amount, { value: amount - 1 }),
'PRESALE_INCORRECT_ETH_VALUE'
)
await assertRevert(
this.presale.contribute(buyer1, amount, { value: amount + 1 }),
'PRESALE_INCORRECT_ETH_VALUE'
)
await assertRevert(this.presale.contribute(buyer1, amount, { value: amount - 1 }), 'PRESALE_INCORRECT_ETH_VALUE')
await assertRevert(this.presale.contribute(buyer1, amount, { value: amount + 1 }), 'PRESALE_INCORRECT_ETH_VALUE')
})
}

Expand Down
8 changes: 4 additions & 4 deletions apps/presale/test/Refund.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ contract('Presale, refund() functionality', ([anyone, appManager, buyer1, buyer2
expect((await this.contributionToken.balanceOf(buyer2)).toNumber()).to.equal(0)
expect((await this.contributionToken.balanceOf(buyer3)).toNumber()).to.equal(BUYER_BALANCE / 2)

expect((await this.projectToken.balanceOf(buyer1)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE).toNumber())
expect((await this.projectToken.balanceOf(buyer2)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE).toNumber())
expect((await this.projectToken.balanceOf(buyer3)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE / 2).toNumber())
expect((await this.projectToken.balanceOf(buyer1)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE))
expect((await this.projectToken.balanceOf(buyer2)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE))
expect((await this.projectToken.balanceOf(buyer3)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE / 2))
})

it('Allows a buyer who made a single purchase to get refunded', async () => {
Expand All @@ -74,7 +74,7 @@ contract('Presale, refund() functionality', ([anyone, appManager, buyer1, buyer2
expect(event).to.exist
expect(event.args.contributor).to.equal(buyer5)
expect(event.args.value.toNumber()).to.equal(1)
expect(event.args.amount.toNumber()).to.equal(expectedAmount.toNumber())
expect(event.args.amount.toNumber()).to.equal(expectedAmount)
expect(event.args.vestedPurchaseId.toNumber()).to.equal(0)
})

Expand Down
2 changes: 1 addition & 1 deletion apps/presale/test/Vesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract('Presale, vesting functionality', ([anyone, appManager, buyer]) => {

it('Token manager registers the correct vested amount', async () => {
const expectedAmount = contributionToProjectTokens(BUYER_BALANCE)
expect(vestedAmount.toNumber()).to.equal(expectedAmount.toNumber())
expect(vestedAmount.toNumber()).to.equal(expectedAmount)
})

it('Token manager registers the correct vesting start date', async () => {
Expand Down
8 changes: 7 additions & 1 deletion apps/presale/test/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const utils = {
getEvent: (tx, eventName) => tx.logs.filter(log => log.event.includes(eventName))[0],

contributionToProjectTokens: value => {
return web3.toBigNumber(value).mul(utils.tokenExchangeRate())
return Math.floor(
web3
.toBigNumber(value)
.mul(utils.tokenExchangeRate())
.div(PPM)
.toNumber()
)
},

now: () => {
Expand Down
2 changes: 1 addition & 1 deletion shared/test-helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const PRESALE_STATE = {
}
const PRESALE_GOAL = '20000e18'
const PRESALE_PERIOD = 14 * DAYS
const PRESALE_EXCHANGE_RATE = 1
const PRESALE_EXCHANGE_RATE = 1 * PPM
const VESTING_CLIFF_PERIOD = 90 * DAYS
const VESTING_COMPLETE_PERIOD = 360 * DAYS
const PERCENT_SUPPLY_OFFERED = 0.9 * PPM // 90%
Expand Down
2 changes: 1 addition & 1 deletion templates/multisig/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ template.installFundraisingApps(

- **goal** The presale goal
- **period** The presale period
- **exchangeRate** The presale exchange rate
- **exchangeRate** The presale exchange rate [in PPM]
- **vestingCliffPeriod** The cliff period for vested shares purchased during presale
- **vestingCompletePeriod** The complete period for vested shares purchased during presale
- **supplyOfferedPct** The percentage of the initial token supply offered to presale's contributors
Expand Down

0 comments on commit 3d2f183

Please sign in to comment.