Skip to content

Commit

Permalink
Adapt snapshotModule for debt payment
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Dec 11, 2023
1 parent df2dec0 commit 899cf35
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
33 changes: 21 additions & 12 deletions contracts/modules/internal/ERC20SnapshotModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad


/**
@dev
list of scheduled snapshot (time)
This list is sorted in ascending order
* @dev
* list of scheduled snapshot (time)
* This list is sorted in ascending order
*/
uint256[] private _scheduledSnapshots;

Expand All @@ -36,8 +36,8 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad


/**
@dev Update balance and/or total supply snapshots before the values are modified. This is implemented
in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
* @dev Update balance and/or total supply snapshots before the values are modified. This is implemented
* in the _beforeTokenTransfer hook, which is executed for _mint, _burn, and _transfer operations.
*/
function _snapshotUpdate(
address from,
Expand All @@ -63,23 +63,32 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad


/**
@dev See {OpenZeppelin - ERC20Snapshot}
* @dev See {OpenZeppelin - ERC20Snapshot}
*/
function _updateAccountSnapshot(address account) private {
_updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
}

/**
@dev See {OpenZeppelin - ERC20Snapshot}
* @dev See {OpenZeppelin - ERC20Snapshot}
*/
function _updateTotalSupplySnapshot() private {
_updateSnapshot(_totalSupplySnapshots, totalSupply());
}

/**
* @notice Return snapshotBalanceOf and snapshotTotalSupply to avoid multiple calls
* @return ownerBalance , totalSupply - see snapshotBalanceOf and snapshotTotalSupply
*/
function getSnapshotInfoBatch(uint256 time, address owner) public view returns (uint256 ownerBalance, uint256 totalSupply) {
ownerBalance = snapshotBalanceOf(time, owner);
totalSupply = snapshotTotalSupply(time);
}


/**
@notice Return the number of tokens owned by the given owner at the time when the snapshot with the given time was created.
@return value stored in the snapshot, or the actual balance if no snapshot
* @notice Return the number of tokens owned by the given owner at the time when the snapshot with the given time was created.
* @return value stored in the snapshot, or the actual balance if no snapshot
*/
function snapshotBalanceOf(
uint256 time,
Expand All @@ -94,9 +103,9 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad
}

/**
@dev See {OpenZeppelin - ERC20Snapshot}
Retrieves the total supply at the specified time.
@return value stored in the snapshot, or the actual totalSupply if no snapshot
* @dev See {OpenZeppelin - ERC20Snapshot}
* Retrieves the total supply at the specified time.
* @return value stored in the snapshot, or the actual totalSupply if no snapshot
*/
function snapshotTotalSupply(uint256 time) public view returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function ERC20SnapshotModuleCommonGetNextSnapshot (
beforeEach(async function () {
this.currentTime = await time.latest()
})
it('can get all next snapshots', async function () {
it('testCanGetAllNextSnapshots', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(10))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(15))
Expand Down Expand Up @@ -49,7 +49,8 @@ function ERC20SnapshotModuleCommonGetNextSnapshot (
])
})

it('return empty array if all snapshots are in the past', async function () {
//
it('testCanReturnEmptyArrayIfAllSnapshotsAreInThePast', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(2))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(3))
Expand All @@ -71,7 +72,7 @@ function ERC20SnapshotModuleCommonGetNextSnapshot (
snapshots.length.should.equal(0)
})

it('return only future snapshots if some snapshots are in the past', async function () {
it('testCanReturnOnlyFutureSnapshotsIfSomeSnapshotsAreInThePast', async function () {
// Arrange
this.snapshotTime1 = this.currentTime.add(time.duration.seconds(2))
this.snapshotTime2 = this.currentTime.add(time.duration.seconds(20))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ async function checkSnapshot (time, totalSupply, addresses, balances) {
(await this.cmtat.snapshotTotalSupply(time)).should.be.bignumber.equal(
totalSupply
)

for (let i = 0; i < balances.length; ++i) {
(
await this.cmtat.snapshotBalanceOf(time, addresses[i])
).should.be.bignumber.equal(balances[i])
await this.cmtat.getSnapshotInfoBatch(time, addresses[i])
const { 0: ownerBalance, 1: totalSupplyGet } = await this.cmtat.getSnapshotInfoBatch(time, addresses[i])
//const [ownerBalance, totalSupplyGet]
ownerBalance.should.be.bignumber.equal(balances[i])
totalSupplyGet.should.be.bignumber.equal(totalSupply)
}
}

Expand Down

0 comments on commit 899cf35

Please sign in to comment.