Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 0 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
[submodule "lazer/evm/lib/forge-std"]
path = lazer/evm/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lazer/evm/lib/pyth-crosschain"]
path = lazer/evm/lib/pyth-crosschain
url = https://github.com/pyth-network/pyth-crosschain
[submodule "lazer/evm/lib/openzeppelin-contracts-upgradeable"]
path = lazer/evm/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "price_feeds/evm/pyth_sample/lib/forge-std"]
path = price_feeds/evm/pyth_sample/lib/forge-std
url = https://github.com/foundry-rs/forge-std
14 changes: 14 additions & 0 deletions entropy/moonshot-crash-game/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Compiler files
cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

# Docs
docs/

# Dotenv file
.env
81 changes: 81 additions & 0 deletions entropy/moonshot-crash-game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Moonshot Crash — Pyth Entropy Integration Example

## Overview

**Moonshot Crash** is an on-chain Crash-style betting game that demonstrates how to integrate **Pyth Entropy** to provide verifiable randomness in decentralized gaming.
The project is deployed on **Base Sepolia** and runs fully autonomously, powered by **Chainlink Automation** for round management and **Pyth Entropy** for crash point randomness.

**Checkout the main repo:** https://github.com/drescher-christoph/Moonshot-Crash-Game

This example focuses on the **Pyth Entropy integration** used in the smart contract [`CrashGame.sol`](./CrashGame.sol).

---

## Motivation

Traditional on-chain games often rely on centralized servers or manipulable pseudo-random numbers.
Moonshot demonstrates how to build a **fair, transparent, and unpredictable on-chain game** using **Pyth Entropy** as a provably fair randomness source.

The system implements the popular “Crash” mechanic:

- Players bet on a rocket’s multiplier.
- The multiplier increases continuously as the rocket ascends.
- The game ends (crashes) at a **random multiplier**, determined by **Pyth Entropy**.
- If a player’s chosen target multiplier is lower than the crash multiplier, they win their payout on-chain.

This mechanic combines **financial logic** (risk/reward balance) with **provably fair randomness**, all executed **transparently on-chain**.

---

## How Pyth Entropy Is Used

**Pyth Entropy** is a verifiable randomness oracle that delivers **unpredictable `bytes32` values** directly to the contract via a callback.
Moonshot integrates Entropy through a simple 3-step process:

---

### 1️⃣ Requesting Entropy

When a round transitions from `OPEN` → `LOCKED`, the contract requests a random value from the Pyth Entropy provider:

```solidity
function requestRandom() internal {
uint128 requestFee = entropy.getFeeV2();
uint64 sequenceNumber = entropy.requestV2{value: requestFee}();
emit FlipRequested(sequenceNumber);
}
```

This function:

- Retrieves the current request fee from the Entropy provider
- Pays the fee and triggers an on-chain randomness request
- Stores the sequence number for reference and emits an event

### 2️⃣ Receiving Entropy

Once the randomness is ready, Pyth calls back via the `entropyCallback()` function required by the `IEntropyConsumer` interface:

```solidity
function entropyCallback(
uint64 sequenceNumber,
address _providerAddress,
bytes32 randomNumber
) internal override {
require(s_rounds[s_currentRoundId].state == RoundState.LOCKED);
uint256 crashMultiplier = _calculateCrashResult(randomNumber);
s_rounds[s_currentRoundId].crashMultiplier = crashMultiplier;
s_rounds[s_currentRoundId].crashTime = block.timestamp;
s_rounds[s_currentRoundId].state = RoundState.RESOLVED;

emit RoundCrashed(s_currentRoundId, block.timestamp, crashMultiplier);
}
```

The random number is passed as a `bytes32` value that the contract transforms into a numeric multiplier.

## Author

Christoph Drescher
ETHGlobal Online 2025 — Pyth Entropy Track Submission
GitHub: @drescher-christoph
12 changes: 12 additions & 0 deletions entropy/moonshot-crash-game/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

remappings = ['@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/', '@solmate=lib/solmate/src/', '@pythnetwork/entropy-sdk-solidity/=node_modules/@pythnetwork/entropy-sdk-solidity', '@openzeppelin/contracts=lib/openzeppelin-contracts/contracts']
fs_permissions = [
{ access = "read", path = "./broadcast" },
{ access = "read", path = "./reports" },
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## 🚨 Read Before Submitting 🚨

🔹 This repository is **only a copy of contracts** from the main [Chainlink repository](https://github.com/smartcontractkit/chainlink).

🔹 **If your issue is related to the contracts themselves**, please **DO NOT** open an issue here.
🔹 Instead, submit it to the **official Chainlink repository**:
👉 [Chainlink Issues Page](https://github.com/smartcontractkit/chainlink/issues)

🔹 If this issue is related to file syncing, structure, or documentation specific to this repo, continue below.

---

### Description
_A clear and concise description of the problem._

### Expected behavior
_What did you expect to happen?_

### Additional context
_Any extra details that might help understand the issue._

### Checklist
- [ ] This change is **not related to the contracts themselves**.
- [ ] I understand that contract-related issues should be submitted to [Chainlink](https://github.com/smartcontractkit/chainlink).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Default Template
about: Provides instructions for issues
title: ''
labels: ''
assignees: ''

---

## 🚨 Read Before Submitting 🚨

🔹 This repository is **only a copy of contracts** from the main [Chainlink repository](https://github.com/smartcontractkit/chainlink).

🔹 **If your issue is related to the contracts themselves**, please **DO NOT** open an issue here.
🔹 Instead, submit it to the **official Chainlink repository**:
👉 [Chainlink Issues Page](https://github.com/smartcontractkit/chainlink/issues)

🔹 If this issue is related to file syncing, structure, or documentation specific to this repo, continue below.

---

### Description
_A clear and concise description of the problem._

### Expected behavior
_What did you expect to happen?_

### Additional context
_Any extra details that might help understand the issue._

### Checklist
- [ ] This change is **not related to the contracts themselves**.
- [ ] I understand that contract-related issues should be submitted to [Chainlink](https://github.com/smartcontractkit/chainlink).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## 🚨 Read Before Submitting 🚨

🔹 This repository is **only a copy of contracts** from the main [Chainlink repository](https://github.com/smartcontractkit/chainlink).

🔹 **If your changes are related to the contracts themselves**, please **DO NOT** open a PR here.
🔹 Instead, submit it to the **official Chainlink repository**:
👉 [Chainlink Pulls Page](https://github.com/smartcontractkit/chainlink/pulls)

🔹 If this PR is related to file syncing, structure, or documentation specific to this repo, continue below.

---

### Description
_A brief description of the changes in this PR._

### Checklist
- [ ] This change is **not related to the contracts themselves**.
- [ ] I understand that contract-related PRs should be submitted to [Chainlink](https://github.com/smartcontractkit/chainlink).
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Update repo to match @chainlink/contracts

on:
push:
schedule:
# Everyday at 3AM
- cron: "0 3 * * *"
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "debug"
type: choice
options:
- info
- warning
- debug
jobs:
check-update-version-and-release:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- name: Checkout
uses: actions/checkout@v2
# - name: Get Current Version
# run: current_version_var=$(cat version.txt) && echo "::set-output name=current_verision::${current_version_var}"
# id: get_current_version
# - name: print current version
# run: echo "Current @chainlink/contracts version is ${{steps.get_current_version.outputs.current_verision}}"
- name: Check npm version
run: yarn outdated
continue-on-error: true
id: check_outdated
- name: Get Updated Version
if: steps.check_outdated.outcome != 'success'
id: get_updated
run: |
yarn upgrade --latest
rm -rf contracts/*
cp -r node_modules/@chainlink/contracts/* contracts/
jq '.dependencies."@chainlink/contracts"' package.json | sed 's/"//g' | sed 's/\^//g' > version.txt
version=$(cat version.txt)
echo "::set-output name=version::${version}"
- name: add and commit
if: steps.check_outdated.outcome != 'success'
uses: stefanzweifel/git-auto-commit-action@v4
with:
tagging_message: ${{steps.get_updated.outputs.version}}
commit_message: ${{steps.get_updated.outputs.version}}
- name: Create Release
if: steps.check_outdated.outcome != 'success'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{steps.get_updated.outputs.version}}
release_name: ${{steps.get_updated.outputs.version}}
draft: false
prerelease: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# dependencies
node_modules/
tmp/
.pnp
.pnp.js
tools/bin/abigen

/chainlink
core/chainlink

# GUI
operator_ui/dist
operator_ui/artifacts
*-packr.go


# SQLite
tools/clroot/db.sqlite3-shm
tools/clroot/db.sqlite3-wal

# Tooling caches
*.tsbuildinfo
.eslintcache

# Log files
*.log

# misc
.DS_Store
.envrc
.env*

# codeship
*.aes
dockercfg
env
credentials.env
gcr_creds.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Overview
This repository is a slimmed down version of Chainlink's official repo. It clones *only* the Chainlink `contracts` folder and the repo automatically updates every time there is a new NPM release.

- NPM's latest release can be found here: https://www.npmjs.com/package/@chainlink/contracts
- Chainlink's official repo: https://github.com/smartcontractkit/chainlink

# chainlink-brownie-contracts

A minimal repo that is a copy of the npm package [@chainlink/contracts](https://www.npmjs.com/package/@chainlink/contracts). These contracts are taken from the [core chainlink github](https://github.com/smartcontractkit/chainlink), compressed, and deployed to npm.

Everyday at 3AM, the latest version of the package is updated here, this way, you can use the Chainlink contracts with foundry without having to use npm/yarn. This also makes other third party packages like Brownie and Ape easier to work with.

## Usage

### Foundry

1. Run this in your projects root directory.

```bash
forge install smartcontractkit/chainlink-brownie-contracts --no-commit
```

2. Then, update your `foundry.toml` to include the following in the `remappings`.

```
remappings = [
'@chainlink/contracts/=lib/chainlink-brownie-contracts/contracts/',
]
```

>! IMPORTANT
There were compatibility issues with `1.0.0`, `1.1.0` and `1.2.0`, where there were originally 2 versions of each version. We have deleted the deprecated and outdated versions so that there is no longer any conflict.

All the releases of this package are going to match the [@chainlink/contracts NPM tags](https://www.npmjs.com/package/@chainlink/contracts).
So the versioning will look "backwards", but we are starting with v0.2.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
artifacts
cache
node_modules
solc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# folders
artifacts/
cache/**
node_modules/
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"printWidth": 120,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all",
"overrides": [
{
"files": "*.sol",
"options": {
"tabWidth": 4
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "solhint:recommended",
"plugins": [],
"rules": {
"quotes": ["error", "double"],
"avoid-suicide": "warn",
"avoid-sha3": "warn",
"avoid-low-level-calls": "warn",
"compiler-version": ["off", "^0.4.24"],
"avoid-throw": false,
"var-name-mixedcase": false,
"mark-callable-contracts": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
Loading