Skip to content

[Contract] Royalty reduction, remove sunset, struct optimization (#38 Group A) #41

@realproject7

Description

@realproject7

Summary

Group A of #38. Three tightly coupled changes to StoryFactory.sol — royalty rate, sunset removal, and struct packing. These must be done together because struct layout changes affect all three.

Parent issue: #38


Changes

1. Reduce Mint/Burn Royalty: 5% → 1%

// Before
uint16 public constant MINT_ROYALTY = 500;
uint16 public constant BURN_ROYALTY = 500;

// After
uint16 public constant MINT_ROYALTY = 100;
uint16 public constant BURN_ROYALTY = 100;

2. Remove sunset Variable — Derive from lastPlotTime

  • Remove bool sunset from Storyline struct
  • Remove require(!s.sunset, "Storyline sunset") from chainPlot()
  • The deadline check already handles this: require(block.timestamp <= s.lastPlotTime + 168 hours, "Deadline passed")
  • Add view function:
    function hasSunset(uint256 storylineId) external view returns (bool) {
        Storyline storage s = storylines[storylineId];
        return s.hasDeadline && block.timestamp > s.lastPlotTime + 168 hours;
    }

3. Struct Storage Optimization (5 slots → 2 slots)

struct Storyline {
    address writer;       // slot 1: 160 bits
    address token;        // slot 2: 160 bits
    uint24 plotCount;     // slot 2: +24 = 184 bits (max 16.7M plots)
    uint40 lastPlotTime;  // slot 2: +40 = 224 bits (max year 36,812)
    bool hasDeadline;     // slot 2: +8 = 232 bits
}

Update all references:

  • plotCount: uint256uint24
  • lastPlotTime: uint256uint40
  • Cast block.timestamp to uint40 when assigning
  • plotIndex in events can remain uint256

Tests

  • Update existing unit tests for removed sunset field
  • Add test for hasSunset() view function
  • Update royalty-related assertions if any exist
  • Log gas comparison: before/after struct optimization
  • forge test passes

Branch

task/{issue-number}-royalty-struct-sunset

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agentenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions