Skip to content

Commit

Permalink
fix: token distribution (#490)
Browse files Browse the repository at this point in the history
* fix token distribution

* fix test assert

Co-authored-by: David Roon <[email protected]>
  • Loading branch information
fforbeck and adridadou authored Feb 1, 2022
1 parent a7e41b0 commit b1f0c09
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
10 changes: 5 additions & 5 deletions contracts/adapters/Distribute.sol
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ contract DistributeContract is IDistribute, AdapterGuard, Reimbursable {
unitHolderAddr,
blockNumber
);
require(memberTokens != 0, "not enough tokens");
require(memberTokens > 0, "not enough tokens");
// Distributes the funds to 1 unit holder only
bank.internalTransfer(
dao,
Expand Down Expand Up @@ -338,16 +338,16 @@ contract DistributeContract is IDistribute, AdapterGuard, Reimbursable {
//slither-disable-next-line calls-loop
address memberAddr = dao.getMemberAddress(i);
//slither-disable-next-line calls-loop
uint256 memberUnits = bank.getPriorAmount(
uint256 memberTokens = DaoHelper.priorMemberTokens(
bank,
memberAddr,
DaoHelper.UNITS,
blockNumber
);
if (memberUnits > 0) {
if (memberTokens > 0) {
//slither-disable-next-line calls-loop
uint256 amountToDistribute = FairShareHelper.calc(
amount,
memberUnits,
memberTokens,
totalTokens
);

Expand Down
1 change: 1 addition & 0 deletions migrations/configs/contracts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export const contracts: Array<ContractConfig> = [
{
id: "dao-factory",
name: "DaoFactory",
alias: "daoFactory",
path: "../../contracts/core/DaoFactory",
enabled: true,
skipAutoDeploy: true,
Expand Down
16 changes: 11 additions & 5 deletions test/adapters/distribute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ function getProposalCounter() {

describe("Adapter - Distribute", () => {
before("deploy dao", async () => {
const { dao, adapters, extensions } = await deployDefaultDao({
const { dao, adapters, extensions, factories } = await deployDefaultDao({
owner: daoOwner,
creator: daoCreator,
});
this.dao = dao;
this.adapters = adapters;
this.extensions = extensions;
this.factories = factories;
this.snapshotId = await takeChainSnapshot();
});

Expand Down Expand Up @@ -269,12 +270,17 @@ describe("Adapter - Distribute", () => {
gasPrice: toBN("0"),
});

memberABalance = await bank.balanceOf(daoMemberA, ETH_TOKEN);
expect(memberABalance.toString()).equal("4"); //4.9999... rounded to 4
memberBBalance = await bank.balanceOf(daoMemberB, ETH_TOKEN);
expect(memberBBalance.toString()).equal("9"); //9.9999... rounded to 9
let ownerBalance = await bank.balanceOf(daoOwner, ETH_TOKEN);
expect(ownerBalance.toString()).equal("0");
let factoryBalance = await bank.balanceOf(
this.factories.daoFactory.address,
ETH_TOKEN
);
expect(factoryBalance.toString()).equal("0");
memberBBalance = await bank.balanceOf(daoMemberB, ETH_TOKEN);
expect(memberBBalance.toString()).equal("9"); //9.9999... rounded to 9
memberABalance = await bank.balanceOf(daoMemberA, ETH_TOKEN);
expect(memberABalance.toString()).equal("4"); //4.9999... rounded to 4
});

it("should not be possible to create a proposal with the amount.toEquals to 0", async () => {
Expand Down
8 changes: 4 additions & 4 deletions test/adapters/lend-nft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe("Adapter - LendNFT", () => {
await lendNFT.sendNFTBack(dao.address, proposalId, { from: nftOwner });

unitBalance = await bank.balanceOf(nftOwner, UNITS);
expect(toNumber(unitBalance.toString())).to.be.closeTo(100, 2);
expect(toNumber(unitBalance.toString())).to.be.closeTo(100, 5);

await advanceTime(10000);
//process the second proposal
Expand All @@ -166,22 +166,22 @@ describe("Adapter - LendNFT", () => {
expect(balanceOf.toString()).equal("1");

unitBalance = await bank.balanceOf(nftOwner, UNITS);
expect(toNumber(unitBalance.toString())).to.be.closeTo(25100, 2);
expect(toNumber(unitBalance.toString())).to.be.closeTo(25100, 5);

await advanceTime(100);

//after 100 seconds, get the second NFT back
await lendNFT.sendNFTBack(dao.address, proposalId2, { from: nftOwner });
unitBalance = await bank.balanceOf(nftOwner, UNITS);
expect(toNumber(unitBalance.toString())).to.be.closeTo(350, 2);
expect(toNumber(unitBalance.toString())).to.be.closeTo(350, 5);

const balance = await erc1155Token.balanceOf(nftOwner, tokenId2);
expect(balance.toString()).equal("1");

await advanceTime(1000);

unitBalance = await bank.balanceOf(nftOwner, UNITS);
expect(toNumber(unitBalance.toString())).to.be.closeTo(350, 2);
expect(toNumber(unitBalance.toString())).to.be.closeTo(350, 5);
});

it("should not be possible to send ETH to the adapter via receive function", async () => {
Expand Down

0 comments on commit b1f0c09

Please sign in to comment.