Skip to content

Commit aa041bc

Browse files
authored
erc-20 interface update (#180)
1 parent 3442040 commit aa041bc

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

contracts/UFragments.sol

+15
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,21 @@ contract UFragments is ERC20Detailed, Ownable {
155155
return _gonBalances[who].div(_gonsPerFragment);
156156
}
157157

158+
/**
159+
* @param who The address to query.
160+
* @return The gon balance of the specified address.
161+
*/
162+
function scaledBalanceOf(address who) public view returns (uint256) {
163+
return _gonBalances[who];
164+
}
165+
166+
/**
167+
* @return the total number of gons.
168+
*/
169+
function scaledTotalSupply() public view returns (uint256) {
170+
return TOTAL_GONS;
171+
}
172+
158173
/**
159174
* @dev Transfer tokens to a specified address.
160175
* @param to The address to transfer to.

test/unit/UFragments.ts

+101
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const toUFrgDenomination = (ample: string): BigNumber =>
77

88
const DECIMALS = 9
99
const INITIAL_SUPPLY = ethers.utils.parseUnits('50', 6 + DECIMALS)
10+
const MAX_UINT256 = ethers.BigNumber.from(2).pow(256).sub(1)
11+
const MAX_INT256 = ethers.BigNumber.from(2).pow(255).sub(1)
12+
const TOTAL_GONS = MAX_UINT256.sub(MAX_UINT256.mod(INITIAL_SUPPLY))
13+
1014
const transferAmount = toUFrgDenomination('10')
1115
const unitTokenAmount = toUFrgDenomination('1')
1216

@@ -51,10 +55,20 @@ describe('UFragments:Initialization', () => {
5155
)
5256
})
5357

58+
it("should set the deployer's scaled balance", async function () {
59+
expect(await uFragments.scaledBalanceOf(await deployer.getAddress())).to.eq(
60+
TOTAL_GONS,
61+
)
62+
})
63+
5464
it('should set the totalSupply to 50M', async function () {
5565
expect(await uFragments.totalSupply()).to.eq(INITIAL_SUPPLY)
5666
})
5767

68+
it('should set the scaledTotalSupply', async function () {
69+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
70+
})
71+
5872
it('should set the owner', async function () {
5973
expect(await uFragments.owner()).to.eq(await deployer.getAddress())
6074
})
@@ -154,6 +168,22 @@ describe('UFragments:Rebase:Expansion', async () => {
154168
await uFragments
155169
.connect(deployer)
156170
.transfer(await B.getAddress(), toUFrgDenomination('250'))
171+
172+
expect(await uFragments.totalSupply()).to.eq(INITIAL_SUPPLY)
173+
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
174+
toUFrgDenomination('750'),
175+
)
176+
expect(await uFragments.balanceOf(await B.getAddress())).to.eq(
177+
toUFrgDenomination('250'),
178+
)
179+
180+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
181+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
182+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
183+
)
184+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
185+
'578960446186580977117854925043439539266349923328202820197287750000000000',
186+
)
157187
})
158188

159189
it('should emit Rebase', async function () {
@@ -166,6 +196,10 @@ describe('UFragments:Rebase:Expansion', async () => {
166196
expect(await uFragments.totalSupply()).to.eq(initialSupply.add(rebaseAmt))
167197
})
168198

199+
it('should NOT CHANGE the scaledTotalSupply', async function () {
200+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
201+
})
202+
169203
it('should increase individual balances', async function () {
170204
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
171205
toUFrgDenomination('825'),
@@ -175,6 +209,15 @@ describe('UFragments:Rebase:Expansion', async () => {
175209
)
176210
})
177211

212+
it('should NOT CHANGE the individual scaled balances', async function () {
213+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
214+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
215+
)
216+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
217+
'578960446186580977117854925043439539266349923328202820197287750000000000',
218+
)
219+
})
220+
178221
it('should return the new supply', async function () {
179222
const returnVal = await uFragments
180223
.connect(policy)
@@ -251,6 +294,22 @@ describe('UFragments:Rebase:NoChange', function () {
251294
await uFragments
252295
.connect(deployer)
253296
.transfer(await B.getAddress(), toUFrgDenomination('250'))
297+
298+
expect(await uFragments.totalSupply()).to.eq(INITIAL_SUPPLY)
299+
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
300+
toUFrgDenomination('750'),
301+
)
302+
expect(await uFragments.balanceOf(await B.getAddress())).to.eq(
303+
toUFrgDenomination('250'),
304+
)
305+
306+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
307+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
308+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
309+
)
310+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
311+
'578960446186580977117854925043439539266349923328202820197287750000000000',
312+
)
254313
})
255314

256315
it('should emit Rebase', async function () {
@@ -263,6 +322,10 @@ describe('UFragments:Rebase:NoChange', function () {
263322
expect(await uFragments.totalSupply()).to.eq(initialSupply)
264323
})
265324

325+
it('should NOT CHANGE the scaledTotalSupply', async function () {
326+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
327+
})
328+
266329
it('should NOT CHANGE individual balances', async function () {
267330
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
268331
toUFrgDenomination('750'),
@@ -271,6 +334,15 @@ describe('UFragments:Rebase:NoChange', function () {
271334
toUFrgDenomination('250'),
272335
)
273336
})
337+
338+
it('should NOT CHANGE the individual scaled balances', async function () {
339+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
340+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
341+
)
342+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
343+
'578960446186580977117854925043439539266349923328202820197287750000000000',
344+
)
345+
})
274346
})
275347

276348
describe('UFragments:Rebase:Contraction', function () {
@@ -292,6 +364,22 @@ describe('UFragments:Rebase:Contraction', function () {
292364
await uFragments
293365
.connect(deployer)
294366
.transfer(await B.getAddress(), toUFrgDenomination('250'))
367+
368+
expect(await uFragments.totalSupply()).to.eq(INITIAL_SUPPLY)
369+
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
370+
toUFrgDenomination('750'),
371+
)
372+
expect(await uFragments.balanceOf(await B.getAddress())).to.eq(
373+
toUFrgDenomination('250'),
374+
)
375+
376+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
377+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
378+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
379+
)
380+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
381+
'578960446186580977117854925043439539266349923328202820197287750000000000',
382+
)
295383
})
296384

297385
it('should emit Rebase', async function () {
@@ -304,6 +392,10 @@ describe('UFragments:Rebase:Contraction', function () {
304392
expect(await uFragments.totalSupply()).to.eq(initialSupply.sub(rebaseAmt))
305393
})
306394

395+
it('should NOT. CHANGE the scaledTotalSupply', async function () {
396+
expect(await uFragments.scaledTotalSupply()).to.eq(TOTAL_GONS)
397+
})
398+
307399
it('should decrease individual balances', async function () {
308400
expect(await uFragments.balanceOf(await A.getAddress())).to.eq(
309401
toUFrgDenomination('675'),
@@ -312,6 +404,15 @@ describe('UFragments:Rebase:Contraction', function () {
312404
toUFrgDenomination('225'),
313405
)
314406
})
407+
408+
it('should NOT CHANGE the individual scaled balances', async function () {
409+
expect(await uFragments.scaledBalanceOf(await A.getAddress())).to.eq(
410+
'1736881338559742931353564775130318617799049769984608460591863250000000000',
411+
)
412+
expect(await uFragments.scaledBalanceOf(await B.getAddress())).to.eq(
413+
'578960446186580977117854925043439539266349923328202820197287750000000000',
414+
)
415+
})
315416
})
316417

317418
describe('UFragments:Transfer', function () {

0 commit comments

Comments
 (0)