Skip to content

Commit

Permalink
SnapshotModule - update snapshotInfoBatch
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Apr 10, 2024
1 parent 2abaa06 commit 3944650
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 8 additions & 0 deletions contracts/interfaces/ICMTATSnapshot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ interface ICMTATSnapshot {
* @return ownerBalances array with the balance of each address, the total supply
*/
function snapshotInfoBatch(uint256 time, address[] calldata addresses) external view returns (uint256[] memory ownerBalances, uint256 totalSupply);

/**
* @notice Return snapshotBalanceOf for each address in the array and the total supply
* @return ownerBalances array with the balance of each address, the total supply
*/
function snapshotInfoBatch(uint256[] calldata times, address[] calldata addresses) external view returns (uint256[][] memory ownerBalances, uint256[] memory totalSupply);


}
17 changes: 17 additions & 0 deletions contracts/modules/internal/ERC20SnapshotModuleInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ abstract contract ERC20SnapshotModuleInternal is SnapshotModuleBase, ERC20Upgrad
totalSupply = snapshotTotalSupply(time);
}

/**
* @notice Return snapshotBalanceOf for each address in the array and the total supply
* @return ownerBalances array with the balance of each address, the total supply
*/
function snapshotInfoBatch(uint256[] calldata times, address[] calldata addresses) public view returns (uint256[][] memory ownerBalances, uint256[] memory totalSupply) {
ownerBalances = new uint256[][](times.length);
totalSupply = new uint256[](times.length);
for(uint256 iT = 0; iT < times.length; ++iT){
/*ownerBalances[iT] = new uint256[](addresses.length);
for(uint256 jA = 0; jA < addresses.length; ++jA){
ownerBalances[iT][jA] = snapshotBalanceOf(times[iT], addresses[jA]);
}
totalSupply[iT] = snapshotTotalSupply(times[iT]);*/
(ownerBalances[iT], totalSupply[iT]) = snapshotInfoBatch(times[iT],addresses);
}
}

/**
* @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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { BN } = require('@openzeppelin/test-helpers')
const getUnixTimestamp = () => {
return Math.round(new Date().getTime() / 1000)
}
Expand All @@ -10,20 +11,24 @@ async function checkSnapshot (time, totalSupply, addresses, balances) {
// Values before the snapshot
(await this.cmtat.snapshotTotalSupply(time)).should.be.bignumber.equal(
totalSupply
)
const result = await this.cmtat.snapshotInfoBatch(time, addresses)
);
const result = await this.cmtat.methods['snapshotInfoBatch(uint256,address[])'](time, addresses);
const times = [time]
const result2 = await this.cmtat.methods['snapshotInfoBatch(uint256[],address[])'](times, addresses);
for (let i = 0; i < balances.length; ++i) {
(
await this.cmtat.snapshotBalanceOf(time, addresses[i])
).should.be.bignumber.equal(balances[i])
await this.cmtat.snapshotInfo(time, addresses[i])
const { 0: ownerBalance, 1: totalSupplyGet } = await this.cmtat.snapshotInfo(time, addresses[i])
await this.cmtat.snapshotInfo(time, addresses[i]);
const { 0: ownerBalance, 1: totalSupplyGet } = await this.cmtat.snapshotInfo(time, addresses[i]);
// const [ownerBalance, totalSupplyGet]
ownerBalance.should.be.bignumber.equal(balances[i])
result[0][i].should.be.bignumber.equal(balances[i])
result2[0][0][i].should.be.bignumber.equal(balances[i]);
totalSupplyGet.should.be.bignumber.equal(totalSupply)
}
result[1].should.be.bignumber.equal(totalSupply)
result[1].should.be.bignumber.equal(totalSupply);
result2[1][0].should.be.bignumber.equal(totalSupply);
}

async function checkArraySnapshot (snapshots, snapshotsValue) {
Expand Down

0 comments on commit 3944650

Please sign in to comment.