A provably fair, cross-chain lottery system for the DRAGON protocol. Users who swap Wrapped Sonic (wS) for DRAGON tokens are automatically entered into a jackpot lottery with a chance to win based on their swap amount and ve69LP holdings.
The DRAGON lottery system utilizes several key components:
- Provably Fair Randomness: Cross-chain VRF implementation using Chainlink via LayerZero
- Dynamic Probability: User's chance scales with swap size and ve69LP holdings
- Self-Funding Jackpot: 6.9% of all DRAGON buy/sell fees go to the jackpot
- Sustainable Distribution: 69% goes to winners, 31% seeds the next jackpot
The lottery uses a dual-component probability system:
-
USD-Based Linear Probability:
- $1 swap = 0.0004% chance (4 in 1,000,000)
- $10,000 swap = 4% chance (4 in 100)
- Linear scaling between these points
-
ve69LP Voting Power Boost:
- Up to 2.5x multiplier based on ve69LP voting power
- Cube root scaling for fair distribution and diminishing returns
The DRAGON lottery jackpot typically averages:
- ~$18,000-$25,000 total jackpot
- ~$12,500-$17,250 payout to winners (69%)
- 31% retention to seed the next jackpot
The lottery implementation includes several critical security features:
- Source Verification: Only accepts randomness from authorized sources
- Cross-Chain Security: LayerZero provides secure message passing
- tx.origin Check: Prevents contracts from entering on behalf of users
- Sybil Attack Prevention: Minimum swap threshold and natural gas disincentives
- contracts/: Smart contract implementations
- vrf/: VRF implementation contracts
- lottery/: Lottery-specific contracts
- interfaces/: Contract interfaces
- docs/: Comprehensive documentation
- lottery/: Lottery system documentation
- test/: Test suite for lottery and VRF functionality
- DragonSwapTriggerV2.sol: Main lottery contract that detects swaps and processes randomness
- SonicVRFConsumer.sol: Handles VRF requests on Sonic chain
- ArbitrumVRFRequester.sol: Interfaces with Chainlink VRF on Arbitrum
- DragonJackpotVault.sol: Manages jackpot accumulation from fees
┌─────────────────┐ ┌───────────────┐ ┌──────────────────┐
│ │ │ │ │ │
│ Sonic Chain │ ──── │ LayerZero │ ──── │ Arbitrum Chain │
│ (Lottery) │ │ (Bridge) │ │ (VRF Source) │
│ │ │ │ │ │
└─────────────────┘ └───────────────┘ └──────────────────┘
MIT
This repository includes comprehensive testing for native token swapping across multiple chains. The framework ensures consistent swap behavior, lottery mechanics, and fee application across all supported chains.
- CrossChainTokenSwapTest.js: Main test suite for cross-chain token swapping
- Mock Contracts:
MockWETH.sol: Simulates wrapped native tokensMockVRFConsumer.sol: Mocks randomness generationMockJackpotVault.solandMockVe69LPFeeDistributor.sol: Mock fee receiversMockLzEndpoint.sol: Simulates LayerZero cross-chain communication
# Run the complete test framework
node scripts/test-native-token-swap.js
# Run individual tests
npx hardhat test test/CrossChainTokenSwapTest.jsFor more details, see NATIVE-TOKEN-SWAP-TESTING.md.
This repository has been cleaned up and organized for better maintainability:
contracts/: Smart contract source codemath/: Math libraries and utilitiesinterfaces/: Contract interfaces
test/: Test files for contractsmath/: Mathematical function tests
docs/: Project documentationguides/: Usage and implementation guidestesting/: Testing procedures and results
config/: All configuration filesdocs/: Documentation configurationhardhat-backups/: Backup configuration filesworkflows/: GitHub workflow configurations
scripts/: Deployment and utility scriptsrun-tests.sh: Helper script to run tests
lib/: External libraries and dependencies
# Run math library tests
./scripts/run-tests.sh math
# Run all tests
./scripts/run-tests.sh all