// DinoChain.ts β Bitcoin Smart Contract (OPNet / AssemblyScript) // Deployed on Bitcoin L1 via OP_NET consensus layer import { OP20, Address, u256, Blockchain, Calldata, encodeSelector } from '@btc-vision/btc-runtime/runtime'; @final export class DinoChain extends OP20 { // Storage slots (deterministic on-chain state) private readonly _highScores: StoredMapU256; private readonly _totalRuns: StoredU256; private readonly _btcRewards: StoredMapU256; private readonly _blockReward: u256 = 625_000_000n; // 6.25 BTC sats constructor() { super('DinoChain Token', 'DINO', 18, 21_000_000n); this._highScores = new StoredMapU256(Pointer.CUSTOM_1); this._totalRuns = new StoredU256(Pointer.CUSTOM_2); this._btcRewards = new StoredMapU256(Pointer.CUSTOM_3); } // Submit verified game score to chain public submitScore(score: u256, proof: Uint8Array): void { const caller = Blockchain.tx.sender; // Verify score proof (prevents cheating) assert( this._verifyScoreProof(score, proof, caller), 'Invalid score proof' ); // Update high score if beaten const current = this._highScores.get(caller); if (score > current) { this._highScores.set(caller, score); this.emit(new NewHighScore(caller, score)); } // Calculate block reward (100 points = 1 block = 6.25 BTC) const blocks = score / 100n; const reward = blocks * this._blockReward; this._mintReward(caller, reward); this._totalRuns.set(this._totalRuns.value + 1n); } // Get high score for address public getHighScore(player: Address): u256 { return this._highScores.get(player); } // Global leaderboard query public getLeaderboard(): TopScore[] { return this._leaderboard.getTop(10); } // Internal: mint BTC reward tokens private _mintReward(to: Address, amount: u256): void { if (this.totalSupply() + amount <= this.maxSupply()) { this._mint(to, amount); this.emit(new RewardMinted(to, amount)); } } }