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

Commit 3d2f183

Browse files
committed
Update exchangeRate to be expressed in PPM
1 parent 3a41d50 commit 3d2f183

File tree

7 files changed

+21
-24
lines changed

7 files changed

+21
-24
lines changed

apps/presale/contracts/Presale.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ contract Presale is EtherTokenConstant, IsContract, AragonApp {
8787
* @param _contributionToken The address of the token to be used to contribute
8888
* @param _goal The goal to be reached by the end of that presale [in contribution token wei]
8989
* @param _period The period within which to accept contribution for that presale
90-
* @param _exchangeRate The exchangeRate [= 1/price] at which [bonded] tokens are to be purchased for that presale
90+
* @param _exchangeRate The exchangeRate [= 1/price] at which [bonded] tokens are to be purchased for that presale [in PPM]
9191
* @param _vestingCliffPeriod The period during which purchased [bonded] tokens are to be cliffed
9292
* @param _vestingCompletePeriod The complete period during which purchased [bonded] tokens are to be vested
9393
* @param _supplyOfferedPct The percentage of the initial supply of [bonded] tokens to be offered during that presale [in PPM]
@@ -199,7 +199,7 @@ contract Presale is EtherTokenConstant, IsContract, AragonApp {
199199
* @param _value The amount of contribution tokens to be used in that computation
200200
*/
201201
function contributionToTokens(uint256 _value) public view isInitialized returns (uint256) {
202-
return _value.mul(exchangeRate);
202+
return _value.mul(exchangeRate).div(PPM);
203203
}
204204

205205
/**

apps/presale/test/Contribute.test.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,21 @@ contract('Presale, contribute() functionality', ([anyone, appManager, buyer1, bu
126126
})
127127

128128
it('Keeps track of independent purchases', async () => {
129-
(await this.presale.contributions(buyer1, 0)).should.be.bignumber.equal(contributionAmount)
129+
;(await this.presale.contributions(buyer1, 0)).should.be.bignumber.equal(contributionAmount)
130130
expect((await this.presale.contributions(buyer2, 0)).toNumber()).to.equal(1)
131131
expect((await this.presale.contributions(buyer2, 1)).toNumber()).to.equal(2)
132132
expect((await this.presale.contributions(buyer2, 2)).toNumber()).to.equal(3)
133133
})
134134

135135
if (!useETH) {
136-
it('Reverts when sending ETH in a contribution that\'s supposed to use ERC20 tokens', async () => {
137-
await assertRevert(
138-
contribute(buyer1, '10e18', true),
139-
'PRESALE_INCORRECT_ETH_VALUE'
140-
)
136+
it("Reverts when sending ETH in a contribution that's supposed to use ERC20 tokens", async () => {
137+
await assertRevert(contribute(buyer1, '10e18', true), 'PRESALE_INCORRECT_ETH_VALUE')
141138
})
142139
} else {
143140
it('Reverts if the ETH amount sent does not match the specified amount', async () => {
144141
const amount = 2
145-
await assertRevert(
146-
this.presale.contribute(buyer1, amount, { value: amount - 1 }),
147-
'PRESALE_INCORRECT_ETH_VALUE'
148-
)
149-
await assertRevert(
150-
this.presale.contribute(buyer1, amount, { value: amount + 1 }),
151-
'PRESALE_INCORRECT_ETH_VALUE'
152-
)
142+
await assertRevert(this.presale.contribute(buyer1, amount, { value: amount - 1 }), 'PRESALE_INCORRECT_ETH_VALUE')
143+
await assertRevert(this.presale.contribute(buyer1, amount, { value: amount + 1 }), 'PRESALE_INCORRECT_ETH_VALUE')
153144
})
154145
}
155146

apps/presale/test/Refund.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ contract('Presale, refund() functionality', ([anyone, appManager, buyer1, buyer2
5050
expect((await this.contributionToken.balanceOf(buyer2)).toNumber()).to.equal(0)
5151
expect((await this.contributionToken.balanceOf(buyer3)).toNumber()).to.equal(BUYER_BALANCE / 2)
5252

53-
expect((await this.projectToken.balanceOf(buyer1)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE).toNumber())
54-
expect((await this.projectToken.balanceOf(buyer2)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE).toNumber())
55-
expect((await this.projectToken.balanceOf(buyer3)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE / 2).toNumber())
53+
expect((await this.projectToken.balanceOf(buyer1)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE))
54+
expect((await this.projectToken.balanceOf(buyer2)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE))
55+
expect((await this.projectToken.balanceOf(buyer3)).toNumber()).to.equal(contributionToProjectTokens(BUYER_BALANCE / 2))
5656
})
5757

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

apps/presale/test/Vesting.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ contract('Presale, vesting functionality', ([anyone, appManager, buyer]) => {
3434

3535
it('Token manager registers the correct vested amount', async () => {
3636
const expectedAmount = contributionToProjectTokens(BUYER_BALANCE)
37-
expect(vestedAmount.toNumber()).to.equal(expectedAmount.toNumber())
37+
expect(vestedAmount.toNumber()).to.equal(expectedAmount)
3838
})
3939

4040
it('Token manager registers the correct vesting start date', async () => {

apps/presale/test/common/utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ const utils = {
44
getEvent: (tx, eventName) => tx.logs.filter(log => log.event.includes(eventName))[0],
55

66
contributionToProjectTokens: value => {
7-
return web3.toBigNumber(value).mul(utils.tokenExchangeRate())
7+
return Math.floor(
8+
web3
9+
.toBigNumber(value)
10+
.mul(utils.tokenExchangeRate())
11+
.div(PPM)
12+
.toNumber()
13+
)
814
},
915

1016
now: () => {

shared/test-helpers/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const PRESALE_STATE = {
2525
}
2626
const PRESALE_GOAL = '20000e18'
2727
const PRESALE_PERIOD = 14 * DAYS
28-
const PRESALE_EXCHANGE_RATE = 1
28+
const PRESALE_EXCHANGE_RATE = 1 * PPM
2929
const VESTING_CLIFF_PERIOD = 90 * DAYS
3030
const VESTING_COMPLETE_PERIOD = 360 * DAYS
3131
const PERCENT_SUPPLY_OFFERED = 0.9 * PPM // 90%

templates/multisig/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ template.installFundraisingApps(
8787

8888
- **goal** The presale goal
8989
- **period** The presale period
90-
- **exchangeRate** The presale exchange rate
90+
- **exchangeRate** The presale exchange rate [in PPM]
9191
- **vestingCliffPeriod** The cliff period for vested shares purchased during presale
9292
- **vestingCompletePeriod** The complete period for vested shares purchased during presale
9393
- **supplyOfferedPct** The percentage of the initial token supply offered to presale's contributors

0 commit comments

Comments
 (0)