From 7b6d9df7414a58ba0198c7e59863f1254baed579 Mon Sep 17 00:00:00 2001 From: audsssy Date: Fri, 8 Dec 2023 09:03:59 +0800 Subject: [PATCH] add events --- src/KaliCurve.sol | 37 +++++++++++++++++++++++++++++++------ test/KaliCurve.t.sol | 1 - 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/KaliCurve.sol b/src/KaliCurve.sol index 5aad00f..404e164 100644 --- a/src/KaliCurve.sol +++ b/src/KaliCurve.sol @@ -20,6 +20,22 @@ contract KaliCurve is Storage { /// Events /// ----------------------------------------------------------------------- + event Donated(uint256 curveId, address patron, uint256 donation, uint256 curveSupply); + event Left(uint256 curveId, address patron, uint256 curveSupply); + event CurveCreated( + uint256 curveId, + CurveType curveType, + bool canMint, + bool daoTreasury, + address owner, + uint96 scale, + uint16 burnRatio, + uint48 constant_a, + uint48 constant_b, + uint48 constant_c + ); + event ImpactDaoSummoned(address dao); + /// ----------------------------------------------------------------------- /// Custom Error /// ----------------------------------------------------------------------- @@ -98,6 +114,10 @@ contract KaliCurve is Storage { // Increment curve supply to start at 1. incrementCurveSupply(curveId); + + emit CurveCreated( + curveId, curveType, canMint, daoTreasury, owner, scale, burnRatio, constant_a, constant_b, constant_c + ); } /// ----------------------------------------------------------------------- @@ -204,7 +224,8 @@ contract KaliCurve is Storage { addUnclaimed(this.getCurveTreasury(curveId) ? impactDAO : owner, totalDonation); // Increment curve supply. - incrementCurveSupply(curveId); + + emit Donated(curveId, patron, donation, incrementCurveSupply(curveId)); } /// @notice Burn ImpactDAO tokens. @@ -221,7 +242,9 @@ contract KaliCurve is Storage { IKaliTokenManager(impactDAO).burnTokens(patron, 1 ether); // Decrement supply. - decrementCurveSupply(curveId); + // uint256 supply = ; + + emit Left(curveId, patron, decrementCurveSupply(curveId)); } /// ----------------------------------------------------------------------- @@ -288,6 +311,8 @@ contract KaliCurve is Storage { /// @notice . function setImpactDao(uint256 curveId, address impactDao) internal { _setAddress(keccak256(abi.encode(curveId, ".impactDao")), impactDao); + + emit ImpactDaoSummoned(impactDao); } /// ----------------------------------------------------------------------- @@ -395,13 +420,13 @@ contract KaliCurve is Storage { } /// @notice Internal function to increment supply of a curve. - function incrementCurveSupply(uint256 curveId) internal { - addUint(keccak256(abi.encode(curveId, ".supply")), 1); + function incrementCurveSupply(uint256 curveId) internal returns (uint256) { + return addUint(keccak256(abi.encode(curveId, ".supply")), 1); } /// @notice Internal function to decrement supply of a curve. - function decrementCurveSupply(uint256 curveId) internal { - subUint(keccak256(abi.encode(curveId, ".supply")), 1); + function decrementCurveSupply(uint256 curveId) internal returns (uint256) { + return subUint(keccak256(abi.encode(curveId, ".supply")), 1); } /// ----------------------------------------------------------------------- diff --git a/test/KaliCurve.t.sol b/test/KaliCurve.t.sol index d0e630d..7dc09a4 100644 --- a/test/KaliCurve.t.sol +++ b/test/KaliCurve.t.sol @@ -348,7 +348,6 @@ contract KaliCurveTest is Test { kaliCurve.donate(1, bob, amount + 1 ether); } - // todo: try to refactor this beast // todo: and add custom errors tests function testLeave_NewUsers() public payable { testDonateWithDaoTreasury_NewUsers();