Skip to content

Commit

Permalink
add events
Browse files Browse the repository at this point in the history
  • Loading branch information
audsssy committed Dec 8, 2023
1 parent 90565d9 commit 7b6d9df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
37 changes: 31 additions & 6 deletions src/KaliCurve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -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
);
}

/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -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.
Expand All @@ -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));
}

/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}

/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -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);
}

/// -----------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion test/KaliCurve.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7b6d9df

Please sign in to comment.