Skip to content

Commit

Permalink
add events to builders (#24)
Browse files Browse the repository at this point in the history
* add events to builders

* add event tests
  • Loading branch information
YouStillAlive committed Apr 11, 2024
1 parent 6f6965b commit 6b7c2a3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions contracts/Builder/BuilderState.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "@poolzfinance/poolz-helper-v2/contracts/interfaces/ILockDealNFT.sol";
contract BuilderState {
ILockDealNFT public immutable lockDealNFT;

event MassPoolsCreated(address indexed token, IProvider indexed provider, uint256 firstPoolId, uint256 userLength);

constructor(ILockDealNFT _lockDealNFT) {
require(address(_lockDealNFT) != address(0), "BuilderState: lockDealNFT zero address");
lockDealNFT = _lockDealNFT;
Expand Down
1 change: 1 addition & 0 deletions contracts/SimpleBuilder/SimpleBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ contract SimpleBuilder is ERC721Holder, BuilderInternal, FirewallConsumer {
}
}
assert(locals.totalAmount == 0);
emit MassPoolsCreated(locals.token, locals.provider, locals.poolId, userData.userPools.length);
}
}
19 changes: 18 additions & 1 deletion contracts/SimpleRefundBuilder/SimpleRefundBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
contract SimpleRefundBuilder is RefundBuilderInternal, IERC721Receiver {
using CalcUtils for uint256;

event MassPoolsRebuilded(
address indexed token,
IProvider indexed provider,
uint256 collateralPoolId,
uint256 firstPoolId,
uint256 userLength
);

constructor(
ILockDealNFT _lockDealNFT,
IProvider _refund,
Expand Down Expand Up @@ -36,13 +44,21 @@ contract SimpleRefundBuilder is RefundBuilderInternal, IERC721Receiver {
locals.paramsData = _getParamsData(collateralPoolId, locals.userData.totalAmount, locals.userData.userPools[0].amount);
// one time transfer for decreasing the number of transactions
locals.tokenPoolId = _createFirstNFT(locals, operator);
locals.paramsData.refundParams = _registerRefundProvider(locals.tokenPoolId - 1, collateralPoolId);
uint256 firstPoolId = locals.tokenPoolId - 1;
locals.paramsData.refundParams = _registerRefundProvider(firstPoolId, collateralPoolId);
// update the collateral data and create another nft to transfer the mainСoin amount
_updateCollateralData(locals, operator, collateralPoolId + 3);
// create mass refund pools
_buildMassPools(locals);
// // transfer back the NFT to the user
lockDealNFT.transferFrom(address(this), user, collateralPoolId);
emit MassPoolsRebuilded(
locals.paramsData.token,
locals.paramsData.provider,
collateralPoolId,
firstPoolId,
locals.userData.userPools.length
);
}
return this.onERC721Received.selector;
}
Expand Down Expand Up @@ -71,5 +87,6 @@ contract SimpleRefundBuilder is RefundBuilderInternal, IERC721Receiver {
locals.tokenPoolId = _createFirstNFT(locals);
locals.paramsData.refundParams = _finalizeFirstNFT(locals, params[0][1]);
_buildMassPools(locals);
emit MassPoolsCreated(locals.paramsData.token, locals.paramsData.provider, locals.tokenPoolId - 1, userData.userPools.length);
}
}
12 changes: 12 additions & 0 deletions test/RebuildPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,16 @@ describe("onERC721Received Collateral tests", function () {
await expect(simpleRefundBuilder.deploy(lockDealNFT.address, refundProvider.address, ethers.constants.AddressZero)
).to.be.revertedWith("SimpleRefundBuilder: CollateralProvider zero address")
})

it("should emit rebuilder event", async () => {
const firstPoolId = await lockDealNFT.totalSupply()
const tx = await lockDealNFT["safeTransferFrom(address,address,uint256,bytes)"](
projectOwner.address,
simpleRefundBuilder.address,
collateralPoolId,
packedData
)
await expect(tx).to.emit(simpleRefundBuilder, "MassPoolsRebuilded")
.withArgs(token, lockProvider.address, collateralPoolId, firstPoolId, rebuildData.length)
})
})
7 changes: 7 additions & 0 deletions test/SimpleBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ describe('Simple Builder tests', function () {
finishTime = startTime.add(7 * ONE_DAY); // plus 7 days from `startTime`
});

it("should emit 'MassPoolsCreated' event", async () => {
const params = _createProviderParams(dealProvider.address);
const firstPoolId = await lockDealNFT.totalSupply();
const tx = await simpleBuilder.connect(projectOwner).buildMassPools(addressParams, userData, params, signature);
await expect(tx).to.emit(simpleBuilder, 'MassPoolsCreated').withArgs(token, dealProvider.address, firstPoolId, userData.userPools.length);
});

it('should create 10 dealProvider pools', async () => {
const userCount = '10';
const params = _createProviderParams(dealProvider.address);
Expand Down
7 changes: 7 additions & 0 deletions test/SimpleRefundBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ describe('Simple Refund Builder tests', function () {
poolId = (await lockDealNFT.totalSupply()).toNumber();
});

it("should emit 'MassPoolsCreated' event", async () => {
const params = _createProviderParams(dealProvider.address);
const tx = await simpleRefundBuilder.connect(projectOwner)
.buildMassPools(addressParams, userData, params, tokenSignature, mainCoinsignature, { gasLimit });
await expect(tx).to.emit(simpleRefundBuilder, 'MassPoolsCreated').withArgs(token, dealProvider.address, poolId, userData.userPools.length);
});

it('should create 10 simple refund pools with dealProvider', async () => {
const userCount = '10';
mainCoinAmount = ethers.utils.parseEther('10').mul(userCount);
Expand Down

0 comments on commit 6b7c2a3

Please sign in to comment.