@ballkidz/defifa 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -266,8 +266,9 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
266
266
  if (context.cashOutCount > 0) revert JB721Hook_UnexpectedTokenCashedOut();
267
267
 
268
268
  // Fetch the cash out hook metadata using the corresponding metadata ID.
269
- (bool metadataExists, bytes memory metadata) =
270
- JBMetadataResolver.getDataFor(JBMetadataResolver.getId("cashOut", codeOrigin), context.metadata);
269
+ (bool metadataExists, bytes memory metadata) = JBMetadataResolver.getDataFor({
270
+ id: JBMetadataResolver.getId({purpose: "cashOut", target: codeOrigin}), metadata: context.metadata
271
+ });
271
272
 
272
273
  uint256[] memory decodedTokenIds;
273
274
 
@@ -283,7 +284,8 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
283
284
 
284
285
  // Use this contract as the only cash out hook.
285
286
  hookSpecifications = new JBCashOutHookSpecification[](1);
286
- hookSpecifications[0] = JBCashOutHookSpecification(this, 0, abi.encode(_cumulativeMintPrice));
287
+ hookSpecifications[0] =
288
+ JBCashOutHookSpecification({hook: this, amount: 0, metadata: abi.encode(_cumulativeMintPrice)});
287
289
 
288
290
  // Compute the cash out count based on the game phase.
289
291
  cashOutCount = DefifaHookLib.computeCashOutCount({
@@ -573,7 +575,7 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
573
575
  _tokenId = _tokenIds[_i];
574
576
 
575
577
  // Mint the token.
576
- _mint(_reservedTokenBeneficiary, _tokenId);
578
+ _mint({to: _reservedTokenBeneficiary, tokenId: _tokenId});
577
579
 
578
580
  emit MintReservedToken(_tokenId, tierId, _reservedTokenBeneficiary, msg.sender);
579
581
 
@@ -614,9 +616,10 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
614
616
  ) revert JB721Hook_InvalidCashOut();
615
617
 
616
618
  // Fetch the cash out hook metadata using the corresponding metadata ID.
617
- (bool metadataExists, bytes memory metadata) = JBMetadataResolver.getDataFor(
618
- JBMetadataResolver.getId("cashOut", METADATA_ID_TARGET), context.cashOutMetadata
619
- );
619
+ (bool metadataExists, bytes memory metadata) = JBMetadataResolver.getDataFor({
620
+ id: JBMetadataResolver.getId({purpose: "cashOut", target: METADATA_ID_TARGET}),
621
+ metadata: context.cashOutMetadata
622
+ });
620
623
 
621
624
  if (!metadataExists) {
622
625
  revert();
@@ -865,7 +868,7 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
865
868
  _tokenId = _tokenIds[_i];
866
869
 
867
870
  // Mint the tokens.
868
- _mint(_beneficiary, _tokenId);
871
+ _mint({to: _beneficiary, tokenId: _tokenId});
869
872
 
870
873
  emit Mint(_tokenId, _mintTierIds[_i], _beneficiary, _amount, msg.sender);
871
874
 
@@ -889,8 +892,9 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
889
892
  // Get the current amount for the sending delegate.
890
893
  uint208 _current = _delegateTierCheckpoints[_from][_tierId].latest();
891
894
  // Set the new amount for the sending delegate.
892
- (uint256 _oldValue, uint256 _newValue) =
893
- _delegateTierCheckpoints[_from][_tierId].push(uint48(block.timestamp), _current - uint208(_amount));
895
+ (uint256 _oldValue, uint256 _newValue) = _delegateTierCheckpoints[_from][_tierId].push({
896
+ key: uint48(block.timestamp), value: _current - uint208(_amount)
897
+ });
894
898
  emit TierDelegateAttestationsChanged(_from, _tierId, _oldValue, _newValue, msg.sender);
895
899
  }
896
900
 
@@ -899,8 +903,9 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
899
903
  // Get the current amount for the receiving delegate.
900
904
  uint208 _current = _delegateTierCheckpoints[_to][_tierId].latest();
901
905
  // Set the new amount for the receiving delegate.
902
- (uint256 _oldValue, uint256 _newValue) =
903
- _delegateTierCheckpoints[_to][_tierId].push(uint48(block.timestamp), _current + uint208(_amount));
906
+ (uint256 _oldValue, uint256 _newValue) = _delegateTierCheckpoints[_to][_tierId].push({
907
+ key: uint48(block.timestamp), value: _current + uint208(_amount)
908
+ });
904
909
  emit TierDelegateAttestationsChanged(_to, _tierId, _oldValue, _newValue, msg.sender);
905
910
  }
906
911
  }
@@ -912,8 +917,9 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
912
917
  if (context.amount.currency != pricingCurrency) revert DefifaHook_WrongCurrency();
913
918
 
914
919
  // Resolve the metadata.
915
- (bool found, bytes memory metadata) =
916
- JBMetadataResolver.getDataFor(JBMetadataResolver.getId("pay", codeOrigin), context.payerMetadata);
920
+ (bool found, bytes memory metadata) = JBMetadataResolver.getDataFor({
921
+ id: JBMetadataResolver.getId({purpose: "pay", target: codeOrigin}), metadata: context.payerMetadata
922
+ });
917
923
 
918
924
  if (!found) revert DefifaHook_NothingToMint();
919
925
 
@@ -987,13 +993,13 @@ contract DefifaHook is JB721Hook, Ownable, IDefifaHook {
987
993
  // If minting, add to the total tier checkpoints.
988
994
  if (_from == address(0)) {
989
995
  // slither-disable-next-line unused-return
990
- _totalTierCheckpoints[_tierId].push(uint48(block.timestamp), _current + uint208(_amount));
996
+ _totalTierCheckpoints[_tierId].push({key: uint48(block.timestamp), value: _current + uint208(_amount)});
991
997
  }
992
998
 
993
999
  // If burning, subtract from the total tier checkpoints.
994
1000
  if (_to == address(0)) {
995
1001
  // slither-disable-next-line unused-return
996
- _totalTierCheckpoints[_tierId].push(uint48(block.timestamp), _current - uint208(_amount));
1002
+ _totalTierCheckpoints[_tierId].push({key: uint48(block.timestamp), value: _current - uint208(_amount)});
997
1003
  }
998
1004
  }
999
1005
 
@@ -160,8 +160,9 @@ contract DefifaTokenUriResolver is IDefifaTokenUriResolver, IJB721TokenUriResolv
160
160
  }
161
161
 
162
162
  if (_gamePhase == DefifaGamePhase.SCORING || _gamePhase == DefifaGamePhase.COMPLETE) {
163
- uint256 _potPortion =
164
- mulDiv(_gamePot, _hook.cashOutWeightOf(_tokenId), _hook.TOTAL_CASHOUT_WEIGHT());
163
+ uint256 _potPortion = mulDiv({
164
+ x: _gamePot, y: _hook.cashOutWeightOf(_tokenId), denominator: _hook.TOTAL_CASHOUT_WEIGHT()
165
+ });
165
166
  _valueText = !_hook.cashOutWeightIsSet()
166
167
  ? "Awaiting scorecard..."
167
168
  : _formatBalance({
@@ -2,7 +2,6 @@
2
2
  pragma solidity 0.8.26;
3
3
 
4
4
  import {DefifaLaunchProjectData} from "../structs/DefifaLaunchProjectData.sol";
5
- import {DefifaOpsData} from "../structs/DefifaOpsData.sol";
6
5
  import {IDefifaHook} from "./IDefifaHook.sol";
7
6
  import {IDefifaGovernor} from "./IDefifaGovernor.sol";
8
7
 
@@ -3,7 +3,6 @@ pragma solidity 0.8.26;
3
3
 
4
4
  import {DefifaScorecardState} from "../enums/DefifaScorecardState.sol";
5
5
  import {DefifaTierCashOutWeight} from "../structs/DefifaTierCashOutWeight.sol";
6
- import {IDefifaHook} from "./IDefifaHook.sol";
7
6
  import {IJBController} from "@bananapus/core-v6/src/interfaces/IJBController.sol";
8
7
 
9
8
  /// @notice Manages the ratification of Defifa scorecards through attestation-based governance.
@@ -2,8 +2,6 @@
2
2
  pragma solidity 0.8.26;
3
3
 
4
4
  import {ITypeface} from "lib/typeface/contracts/interfaces/ITypeface.sol";
5
- import {IDefifaHook} from "./IDefifaHook.sol";
6
- import {IDefifaGamePhaseReporter} from "./IDefifaGamePhaseReporter.sol";
7
5
 
8
6
  interface IDefifaTokenUriResolver {
9
7
  function typeface() external view returns (ITypeface);
@@ -248,7 +248,9 @@ library DefifaHookLib {
248
248
  cashOutCount = cumulativeMintPrice;
249
249
  } else {
250
250
  // If the game is in its scoring or complete phase, reclaim amount is based on the tier weights.
251
- cashOutCount = mulDiv(surplusValue + _amountRedeemed, cumulativeCashOutWeight, TOTAL_CASHOUT_WEIGHT);
251
+ cashOutCount = mulDiv({
252
+ x: surplusValue + _amountRedeemed, y: cumulativeCashOutWeight, denominator: TOTAL_CASHOUT_WEIGHT
253
+ });
252
254
  }
253
255
  }
254
256
 
@@ -348,8 +350,8 @@ library DefifaHookLib {
348
350
  uint256 defifaAmount = _defifaToken.balanceOf(address(this)) * shareToBeneficiary / outOfTotal;
349
351
 
350
352
  // If there is an amount we should send, send it.
351
- if (defifaAmount != 0) _defifaToken.safeTransfer(_beneficiary, defifaAmount);
352
- if (baseProtocolAmount != 0) _baseProtocolToken.safeTransfer(_beneficiary, baseProtocolAmount);
353
+ if (defifaAmount != 0) _defifaToken.safeTransfer({to: _beneficiary, value: defifaAmount});
354
+ if (baseProtocolAmount != 0) _baseProtocolToken.safeTransfer({to: _beneficiary, value: baseProtocolAmount});
353
355
 
354
356
  emit ClaimedTokens(_beneficiary, defifaAmount, baseProtocolAmount, msg.sender);
355
357
 
@@ -2,9 +2,7 @@
2
2
  pragma solidity 0.8.26;
3
3
 
4
4
  import {DefifaTierParams} from "./DefifaTierParams.sol";
5
- import {DefifaOpsData} from "./DefifaOpsData.sol";
6
5
 
7
- import {JBLaunchProjectConfig} from "@bananapus/721-hook-v6/src/structs/JBLaunchProjectConfig.sol";
8
6
  import {JBAccountingContext} from "@bananapus/core-v6/src/structs/JBAccountingContext.sol";
9
7
  import {IJB721TiersHookStore} from "@bananapus/721-hook-v6/src/interfaces/IJB721TiersHookStore.sol";
10
8
  import {IJB721TokenUriResolver} from "@bananapus/721-hook-v6/src/interfaces/IJB721TokenUriResolver.sol";
@@ -463,7 +463,7 @@ contract DefifaFeeAccountingTest is JBTest, TestBaseWorkflow {
463
463
  /// @notice Mint 1 NFT per tier, set delegation, return array of user addresses.
464
464
  function _mintAllTiers(
465
465
  DefifaHook _nft,
466
- DefifaGovernor _governor,
466
+ DefifaGovernor,
467
467
  uint256 projectId,
468
468
  uint8 nTiers
469
469
  )
@@ -499,7 +499,7 @@ contract DefifaFeeAccountingTest is JBTest, TestBaseWorkflow {
499
499
  address[] memory users,
500
500
  DefifaHook _nft,
501
501
  DefifaGovernor _governor,
502
- uint256 projectId,
502
+ uint256,
503
503
  uint8 nTiers
504
504
  )
505
505
  internal
@@ -541,7 +541,7 @@ contract DefifaFeeAccountingTest is JBTest, TestBaseWorkflow {
541
541
  return (_tierId * 1_000_000_000) + _tokenNumber;
542
542
  }
543
543
 
544
- function _buildPayMetadata(bytes memory metadata) internal returns (bytes memory) {
544
+ function _buildPayMetadata(bytes memory metadata) internal view returns (bytes memory) {
545
545
  bytes[] memory data = new bytes[](1);
546
546
  data[0] = metadata;
547
547
  bytes4[] memory ids = new bytes4[](1);
@@ -549,7 +549,7 @@ contract DefifaFeeAccountingTest is JBTest, TestBaseWorkflow {
549
549
  return metadataHelper().createMetadata(ids, data);
550
550
  }
551
551
 
552
- function _buildCashOutMetadata(bytes memory metadata) internal returns (bytes memory) {
552
+ function _buildCashOutMetadata(bytes memory metadata) internal view returns (bytes memory) {
553
553
  bytes[] memory data = new bytes[](1);
554
554
  data[0] = metadata;
555
555
  bytes4[] memory ids = new bytes4[](1);
@@ -631,7 +631,6 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
631
631
  JB721Tier memory _tier = _hook.store().tierOf(address(_hook), 1, false);
632
632
  uint256 _cost = _tier.price;
633
633
 
634
- address _delegateUser = address(bytes20(keccak256("_delegateUser")));
635
634
  address _refundUser = address(bytes20(keccak256("refund_user")));
636
635
  // The user should have no balance
637
636
  assertEq(_hook.balanceOf(_refundUser), 0);
@@ -931,8 +930,6 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
931
930
  _durationUntilProjectLaunch > 2 && _mintPeriodDuration > 1 && _inBetweenMintAndFifa > 1 && _fifaDuration > 1
932
931
  );
933
932
  uint48 _launchProjectAt = uint48(block.timestamp) + _durationUntilProjectLaunch;
934
- uint48 _end =
935
- _launchProjectAt + uint48(_mintPeriodDuration) + uint48(_inBetweenMintAndFifa) + uint48(_fifaDuration);
936
933
  DefifaTierParams[] memory tierParams = new DefifaTierParams[](1);
937
934
  tierParams[0] = DefifaTierParams({
938
935
  reservedRate: 1001,
@@ -988,12 +985,10 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
988
985
 
989
986
  function testWhenScorecardIsSubmittedWithUnmintedTier() public {
990
987
  uint8 nTiers = 10;
991
- address[] memory _users = new address[](nTiers);
992
988
  DefifaLaunchProjectData memory defifaData = getBasicDefifaLaunchData(nTiers);
993
- (uint256 _projectId, DefifaHook _nft, DefifaGovernor _governor) = createDefifaProject(defifaData);
989
+ (,, DefifaGovernor _governor) = createDefifaProject(defifaData);
994
990
  // Phase 1: Mint
995
991
  vm.warp(defifaData.start - defifaData.mintPeriodDuration - defifaData.refundPeriodDuration);
996
- //deployer.queueNextPhaseOf(_projectId);
997
992
 
998
993
  // Warp to scoring phase (past start time)
999
994
  vm.warp(defifaData.start + 1);
@@ -1007,7 +1002,7 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
1007
1002
 
1008
1003
  vm.expectRevert(abi.encodeWithSignature("DefifaGovernor_UnownedProposedCashoutValue()"));
1009
1004
  // Forward time so proposals can be created
1010
- uint256 _proposalId = _governor.submitScorecardFor(_gameId, scorecards);
1005
+ _governor.submitScorecardFor(_gameId, scorecards);
1011
1006
  }
1012
1007
 
1013
1008
  // function testWhenPhaseIsAlreadyQueued() public {
@@ -1256,7 +1251,6 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
1256
1251
  assertEq(_refundUser.balance, 0);
1257
1252
  // The user should have have a token
1258
1253
  assertEq(_hook.balanceOf(_refundUser), 1);
1259
- uint256 _numberBurned = _hook.store().numberOfBurnedFor(address(_hook), _tierId);
1260
1254
  // Craft the metadata: redeem the tokenId
1261
1255
  bytes memory cashOutMetadata;
1262
1256
  {
@@ -1305,7 +1299,7 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
1305
1299
  return (_tierId * 1_000_000_000) + _tokenNumber;
1306
1300
  }
1307
1301
 
1308
- function _buildPayMetadata(bytes memory metadata) internal returns (bytes memory) {
1302
+ function _buildPayMetadata(bytes memory metadata) internal view returns (bytes memory) {
1309
1303
  // Build the metadata using the tiers to mint and the overspending flag.
1310
1304
  bytes[] memory data = new bytes[](1);
1311
1305
  data[0] = metadata;
@@ -1318,7 +1312,7 @@ contract DefifaGovernorTest is JBTest, TestBaseWorkflow {
1318
1312
  return metadataHelper().createMetadata(ids, data);
1319
1313
  }
1320
1314
 
1321
- function _buildCashOutMetadata(bytes memory metadata) internal returns (bytes memory) {
1315
+ function _buildCashOutMetadata(bytes memory metadata) internal view returns (bytes memory) {
1322
1316
  // Build the metadata using the tiers to mint and the overspending flag.
1323
1317
  bytes[] memory data = new bytes[](1);
1324
1318
  data[0] = metadata;
@@ -30,18 +30,18 @@ import {DefifaTierParams} from "../src/structs/DefifaTierParams.sol";
30
30
  import {DefifaTierCashOutWeight} from "../src/structs/DefifaTierCashOutWeight.sol";
31
31
 
32
32
  /// @dev Helper to read block.timestamp via an external call, bypassing the via-ir optimizer's timestamp caching.
33
- contract TimestampReaderAudit {
33
+ contract TimestampReaderRegressions {
34
34
  function timestamp() external view returns (uint256) {
35
35
  return block.timestamp;
36
36
  }
37
37
  }
38
38
 
39
- /// @title DefifaHook_AuditFindings
39
+ /// @title DefifaHookRegressions
40
40
  /// @notice Regression tests for audit findings in DefifaHook.
41
- contract DefifaHook_AuditFindings is JBTest, TestBaseWorkflow {
41
+ contract DefifaHookRegressions is JBTest, TestBaseWorkflow {
42
42
  using JBRulesetMetadataResolver for JBRuleset;
43
43
 
44
- TimestampReaderAudit private _tsReader = new TimestampReaderAudit();
44
+ TimestampReaderRegressions private _tsReader = new TimestampReaderRegressions();
45
45
 
46
46
  address _protocolFeeProjectTokenAccount;
47
47
  address _defifaProjectTokenAccount;
@@ -364,7 +364,7 @@ contract DefifaHook_AuditFindings is JBTest, TestBaseWorkflow {
364
364
  return (_tierId * 1_000_000_000) + _tokenNumber;
365
365
  }
366
366
 
367
- function _buildPayMetadata(bytes memory metadata) internal returns (bytes memory) {
367
+ function _buildPayMetadata(bytes memory metadata) internal view returns (bytes memory) {
368
368
  bytes[] memory data = new bytes[](1);
369
369
  data[0] = metadata;
370
370
  bytes4[] memory ids = new bytes4[](1);
@@ -892,7 +892,7 @@ contract DefifaNoContestTest is JBTest, TestBaseWorkflow {
892
892
  });
893
893
  }
894
894
 
895
- function _cashOutMeta(uint256 tid, uint256 tnum) internal returns (bytes memory) {
895
+ function _cashOutMeta(uint256 tid, uint256 tnum) internal view returns (bytes memory) {
896
896
  uint256[] memory cid = new uint256[](1);
897
897
  cid[0] = (tid * 1_000_000_000) + tnum;
898
898
  bytes[] memory data = new bytes[](1);
@@ -678,7 +678,7 @@ contract DefifaSecurityTest is JBTest, TestBaseWorkflow {
678
678
  });
679
679
  }
680
680
 
681
- function _cashOutMeta(uint256 tid, uint256 tnum) internal returns (bytes memory) {
681
+ function _cashOutMeta(uint256 tid, uint256 tnum) internal view returns (bytes memory) {
682
682
  uint256[] memory cid = new uint256[](1);
683
683
  cid[0] = (tid * 1_000_000_000) + tnum;
684
684
  bytes[] memory data = new bytes[](1);