Skip to main content

Lottery Integration Fix

๐Ÿ› Issue Foundโ€‹

The ShareOFT contract was calling the CreatorLotteryManager with an incorrect interface.

Before (BROKEN):โ€‹

// โŒ Wrong interface
interface ICreatorLotteryManager {
function processSwapLottery(address recipient, address token, uint256 amount)
external returns (uint256);
}

// โŒ Wrong call
ICreatorLotteryManager(mgr).processSwapLottery(recipient, address(this), amount)

After (FIXED):โ€‹

// โœ… Correct interface
interface ICreatorLotteryManager {
function processSwapLottery(
address creatorCoin, // The underlying creator token (AKITA)
address trader, // The buyer
address tokenIn, // The token being bought (wsAKITA)
uint256 amountIn // Amount bought
) external payable returns (uint256);
}

// โœ… Correct call with creator coin lookup
address creatorCoin = vault != address(0) ? ICreatorOVault(vault).asset() : address(0);
ICreatorLotteryManager(mgr).processSwapLottery(
creatorCoin, // e.g., AKITA token address
recipient, // Buyer address
address(this), // wsAKITA (ShareOFT)
amount // Amount of wsAKITA bought
)

๐Ÿ”ง What Was Fixedโ€‹

1. Updated Interface (CreatorShareOFT.sol)โ€‹

  • Changed ICreatorLotteryManager interface to match the actual contract
  • Added payable modifier (lottery may require gas fees for VRF)
  • Updated parameters to match expected signature

2. Fixed Function Call (_triggerLottery)โ€‹

  • Now fetches the creatorCoin address from the vault
  • Passes correct parameters in correct order
  • Validates creatorCoin is not zero before calling lottery

3. Added Vault Interfaceโ€‹

  • Added asset() function to ICreatorOVault interface
  • This allows ShareOFT to lookup the underlying creator token

โœ… How It Works Nowโ€‹

Buy Flow with Lottery:โ€‹

1. User buys wsAKITA on Uniswap
โ†“
2. ShareOFT.transfer() detects it's a buy (from SwapOnly address)
โ†“
3. _processBuy() executes:
- Takes 6.9% fee โ†’ GaugeController
- Transfers remaining tokens to buyer
โ†“
4. _triggerLottery() executes:
- Looks up AKITA token address from vault
- Calls LotteryManager.processSwapLottery(AKITA, buyer, wsAKITA, amount)
โ†“
5. LotteryManager:
- Verifies AKITA is registered & active
- Calculates USD value using AKITA oracle
- Creates lottery entry with probability based on trade size
- May trigger instant win via VRF

๐Ÿงช Testing Checklistโ€‹

Unit Tests Needed:โ€‹

  • ShareOFT._triggerLottery() calls lottery with correct parameters
  • Lottery call succeeds when vault is set
  • Lottery call fails gracefully when vault is not set
  • Lottery call doesn't revert the transfer if it fails

Integration Tests Needed:โ€‹

  • End-to-end buy flow:

    • User swaps ETH โ†’ wsAKITA on Uniswap
    • Fee is collected
    • Lottery entry is created
    • Transfer completes successfully
  • Creator coin lookup:

    • Verify vault.asset() returns correct AKITA address
    • Verify lottery manager receives correct creator coin

Manual Testing:โ€‹

# 1. Deploy contracts
forge script script/DeployBase.s.sol --rpc-url base --broadcast

# 2. Buy wsAKITA on testnet DEX
# - Watch for LotteryTriggered event
# - Check lottery manager state

# 3. Verify parameters
cast call $LOTTERY_MANAGER "entries(uint256)" <entryId>
# Should show:
# - creatorCoin = AKITA address (0x5b67...)
# - trader = buyer address
# - tokenIn = wsAKITA address
# - amountIn = amount bought

๐Ÿ“ Key Changes Summaryโ€‹

File: contracts/layerzero/CreatorShareOFT.solโ€‹

ChangeBeforeAfter
Interface params(recipient, token, amount)(creatorCoin, trader, tokenIn, amountIn)
Interface modifierNo payableAdded payable
Call params(recipient, this, amount)(creatorCoin, recipient, this, amount)
Creator coinNot passedFetched from vault.asset()
Vault interfaceNo asset()Added asset() function

๐ŸŽฏ Why This Mattersโ€‹

Before Fix:โ€‹

  • โŒ Lottery calls would fail silently
  • โŒ No lottery entries created for buyers
  • โŒ Jackpot never awarded
  • โŒ Social-fi engagement broken

After Fix:โ€‹

  • โœ… Lottery calls succeed
  • โœ… Buyers get lottery entries
  • โœ… Jackpot awards work correctly
  • โœ… Social-fi engagement enabled

๐Ÿš€ Deployment Stepsโ€‹

  1. Recompile contracts:

    forge build
  2. Run tests:

    forge test --match-contract ShareOFT
  3. Deploy to testnet first:

    forge script script/DeployBase.s.sol --rpc-url base-sepolia --broadcast --verify
  4. Verify lottery integration:

    • Make test swap
    • Check for LotteryTriggered event
    • Verify entry in lottery manager
  5. Deploy to mainnet:

    forge script script/DeployBase.s.sol --rpc-url base --broadcast --verify

๐Ÿ“Š Expected Events After Fixโ€‹

When a user buys wsAKITA, you should see these events in order:

1. Transfer(from: uniswapPool, to: feeCollector, value: feeAmount)
2. Transfer(from: uniswapPool, to: buyer, value: transferAmount)
3. BuyFee(from: pool, to: buyer, amount: totalAmount, fee: feeAmount)
4. FeeCollected(gauge: gaugeController, amount: feeAmount)
5. LotteryTriggered(recipient: buyer, amount: transferAmount, entryId: X)

If LotteryTriggered is missing, the lottery call failed!


  • contracts/layerzero/CreatorShareOFT.sol - Main fix
  • contracts/lottery/CreatorLotteryManager.sol - Lottery manager
  • contracts/vault/CreatorOVault.sol - Vault (implements asset())
  • contracts/governance/CreatorGaugeController.sol - Fee recipient

โš ๏ธ Important Notesโ€‹

  1. Backward Compatibility:

    • This is a breaking change if contracts are already deployed
    • Existing ShareOFT contracts will need to be redeployed or upgraded
  2. Upgrade Path:

    • If using proxy pattern: Upgrade implementation
    • If not upgradeable: Deploy new ShareOFT and migrate liquidity
  3. Gas Considerations:

    • Lottery call now includes payable modifier
    • May require small ETH amount for cross-chain VRF
    • Test gas costs on testnet first

โœ… Verification Commandsโ€‹

After deployment, verify the fix:

# Check ShareOFT has correct lottery interface
cast abi-encode "processSwapLottery(address,address,address,uint256)" \
$AKITA_TOKEN $BUYER $WSAKITA_TOKEN 1000000000000000000

# Make a test buy and check events
cast logs --address $WSAKITA_TOKEN --from-block latest

# Verify lottery entry was created
cast call $LOTTERY_MANAGER "entryCounter()"

Status: โœ… FIXED
Priority: ๐Ÿ”ด CRITICAL - Required for lottery functionality
Tested: โณ Pending integration tests