Purpose: Detect H€/HAu tokens, create AnyHedge contracts, mint/burn stable tokens, check pool capacity
Complexity: Medium - CashTokens integration + AnyHedge oracle interaction
The Stability Layer enables users to hold EUR/Gold-pegged tokens instead of volatile BCH:
Phase 0+: Optional feature (users choose BCH or H€/HAu)
Why? Venezuelan merchants want stable value, not BCH volatility speculation.
Definition: BCH smart contract where two parties bet on price movement
Participants:
Contract example:
- Elena locks 0.02 BCH (worth €100 today)
- Speculator locks 0.02 BCH (€100 collateral)
- Oracle reports BCH/EUR price every hour
- If BCH drops 10%: Elena keeps €100 worth, speculator gets remainder
- If BCH rises 10%: Elena still keeps €100 worth, speculator gets gains
Elena’s result: Always has €100 worth of BCH (stable value)
No middleman: Contract enforced by BCH script + oracle signatures
What: BCH native tokens (fungible, like ERC-20 but better)
H€ token:
Token {
category: H€_TOKEN_CATEGORY, // Fixed identifier
amount: 10000, // 100.00 H€ (2 decimal places)
nft: null // Fungible token (no NFT)
}
HAu token:
Token {
category: HAu_TOKEN_CATEGORY, // Different from H€
amount: 5000, // 50.00 HAu (2 decimal places)
nft: null
}
Storage: Tokens live in BCH UTXOs alongside satoshis
What: Check if user has H€/HAu tokens
Pseudocode:
function getStableTokenBalance():
wallet_utxos = getWalletUTXOs()
h€_balance = 0
hau_balance = 0
for utxo in wallet_utxos:
if utxo.token:
if utxo.token.category == H€_TOKEN_CATEGORY:
h€_balance += utxo.token.amount
else if utxo.token.category == HAu_TOKEN_CATEGORY:
hau_balance += utxo.token.amount
return {
h€: h€_balance / 100, // Convert to decimal (10000 → 100.00 H€)
hau: hau_balance / 100
}
Display in UI:
Wallet Balance:
- 0.05 BCH (€243.50)
- 100.00 H€ (€100.00)
- 50.00 HAu (€3,250.00 at current gold price)
User wants stability:
Trigger: User clicks “Convert BCH → H€”
Phase 0: Asgaya Bull Pool (Simplified)
What: Single liquidity pool provides speculator side of AnyHedge contracts
Capacity: ~€1,800 (60% of Phase 0 budget)
Pseudocode:
function checkBullPoolCapacity(amount_eur):
pool_capacity = queryBullPoolCapacity() // Background query, cached
if pool_capacity >= amount_eur:
return {available: true, capacity: pool_capacity}
else:
return {available: false, capacity: pool_capacity}
UI behavior:
Queue for fairness (Phase 0+):
if multiple_users_want_to_mint and pool_capacity_insufficient:
// First-come-first-served queue
queue_minting_request(user, amount_eur, timestamp)
when new_liquidity_added_to_pool:
process_queue_oldest_first()
Example:
Phase 0 allocation (reference implementation):
Phase 1+ alternative: Open Marketplace
For comparison, Phase 1+ could support open speculator marketplace:
function findAnyHedgeSpeculator(amount_eur, duration_hours):
// Query AnyHedge marketplace for available speculators
offers = anyHedgeQuery("marketplace.list_offers", {
type: "long", // Looking for speculators
currency: "EUR",
min_amount: amount_eur,
max_duration: duration_hours
})
if offers.length == 0:
return null // No speculator available
// Sort by best terms (lowest fees)
offers.sort(by: fee_percent, asc)
return offers[0]
Trade-off:
Phase 0 choice: Bull pool (simplicity over scale)
Step 2: Create AnyHedge contract
function createAnyHedgeContract(amount_eur, speculator_offer):
current_price = getOraclePrice("BCH/EUR")
bch_amount = amount_eur / current_price
contract = {
hedge_party: my_address,
long_party: speculator_offer.address,
hedge_amount: bch_amount,
long_amount: bch_amount, // 1:1 collateral ratio
start_price: current_price,
duration: speculator_offer.duration,
oracle: speculator_offer.oracle_pubkey,
settlement_type: "mutual" // Both parties can settle early
}
// Sign contract
contract_tx = buildAnyHedgeTx(contract)
signed_contract = signTransaction(contract_tx)
// Speculator signs their side
fully_signed = await_speculator_signature(signed_contract)
// Broadcast
tx_id = broadcast(fully_signed)
return {
contract_id: tx_id,
contract: contract
}
Step 3: Mint H€ tokens
function mintH€FromContract(contract_id, amount_eur):
// Create minting transaction
mint_tx = createTransaction({
inputs: [
{contract_utxo: contract_id} // Spend from AnyHedge contract
],
outputs: [
{
value: 1000, // Dust satoshis
script: p2pkh(my_address),
token: {
category: H€_TOKEN_CATEGORY,
amount: amount_eur * 100 // 100 EUR → 10000 token units
}
}
]
})
// Sign with contract terms (oracle signature required)
signed_mint = signWithOracleAttestation(mint_tx, contract_id)
broadcast(signed_mint)
return success("Minted " + amount_eur + " H€")
Result: User now has 100 H€ tokens in wallet (stable EUR value)
User wants BCH:
Trigger: User clicks “Convert H€ → BCH”
BUT: Trading is preferred over burning
Better option:
Burn economics (Phase 0):
Auto-renewing contracts:
Free burning at contract expiry:
Early exit fee (before expiry):
days_remaining = contract_expiry - now()
total_days = 7 // 7-day contract duration
early_exit_fee_percent = (days_remaining / total_days) * 0.5%
Example:
- Day 1 (6 days left): 6/7 × 0.5% = 0.43% fee
- Day 4 (3 days left): 3/7 × 0.5% = 0.21% fee
- Day 7 (0 days left): 0/7 × 0.5% = 0% fee (free)
Fee goes to: Bull pool speculator (compensation for early settlement)
Dual purpose of exit fee:
Effect: Natural nudge toward trading (instant + free) vs burning (delayed OR expensive)
Why this works:
Step 1: Settle AnyHedge contract
function settleAnyHedgeContract(contract_id):
contract = getContract(contract_id)
current_price = getOraclePrice("BCH/EUR")
start_price = contract.start_price
// Calculate payouts
if current_price < start_price:
// BCH dropped - hedge party gets more BCH
hedge_payout = (contract.hedge_amount * start_price) / current_price
long_payout = (contract.hedge_amount + contract.long_amount) - hedge_payout
else:
// BCH rose - hedge party gets less BCH (but same EUR value)
hedge_payout = (contract.hedge_amount * start_price) / current_price
long_payout = (contract.hedge_amount + contract.long_amount) - hedge_payout
// Build settlement transaction
settlement_tx = createTransaction({
inputs: [{contract_utxo: contract_id}],
outputs: [
{value: hedge_payout, script: p2pkh(contract.hedge_party)},
{value: long_payout, script: p2pkh(contract.long_party)}
]
})
// Sign with oracle attestation (proves price)
signed_settlement = signWithOracleAttestation(settlement_tx, current_price)
broadcast(signed_settlement)
return hedge_payout
Step 2: Burn H€ tokens
function burnH€(amount_h€):
// Find UTXOs with H€ tokens
h€_utxos = findTokenUTXOs(H€_TOKEN_CATEGORY, amount_h€ * 100)
// Create burn transaction (spend tokens, don't create new token output)
burn_tx = createTransaction({
inputs: h€_utxos,
outputs: [
{
value: sum(h€_utxos.value), // Dust satoshis return to user
script: p2pkh(my_address)
// No token field (tokens burned)
}
]
})
broadcast(burn_tx)
return success("Burned " + amount_h€ + " H€")
Result: User receives BCH (EUR-equivalent at current price)
Limited liquidity: AnyHedge speculators (long parties) have finite capital
Example:
Pseudocode:
function checkAnyHedgeCapacity(amount_eur, currency):
offers = anyHedgeQuery("marketplace.list_offers", {
type: "long",
currency: currency
})
total_capacity = 0
for offer in offers:
total_capacity += offer.max_amount
if total_capacity >= amount_eur:
return {available: true, capacity: total_capacity}
else:
return {available: false, capacity: total_capacity, shortage: amount_eur - total_capacity}
UI feedback:
if not capacity.available:
show_warning("Only €" + capacity.capacity + " available for hedging. Try smaller amount or wait.")
Definition: Trusted price feed (BCH/EUR, BCH/XAU)
AnyHedge oracles:
How it works:
Observation: Physical gold dealers could be natural HAu adopters
Why gold shops make sense:
Potential use cases:
Why HAu specifically:
Challenges:
Phase 0+ opportunity: Target 2-3 gold shops as pilot users, measure adoption
Pseudocode:
function getOraclePrice(pair):
// Query General Protocols oracle
response = http_get("https://oracle.generalprotocols.com/price/" + pair)
price_data = {
pair: pair,
price: response.price,
timestamp: response.timestamp,
signature: response.signature
}
// Verify signature
if not verify_oracle_signature(price_data):
return error("Invalid oracle signature")
return price_data.price
Response example:
{
"pair": "BCH/EUR",
"price": 485.32,
"timestamp": 1735689600,
"signature": "3045022100..."
}
Why General Protocols for Phase 0:
Option A: Custom Multi-Exchange Oracle
If General Protocols charges fees, build own oracle:
function getMultiExchangePrice(pair):
prices = []
// Query multiple exchanges
prices.push(krakenAPI.getPrice("BCH/EUR"))
prices.push(binanceAPI.getPrice("BCH/EUR"))
prices.push(coinbaseAPI.getPrice("BCH/EUR"))
prices.push(bitfinexAPI.getPrice("BCH/EUR"))
// Use median (resistant to single exchange manipulation)
median_price = median(prices)
return median_price
Advantages:
Disadvantages:
Option B: Asgaya as Oracle (Phase 2+)
Use Asgaya’s own transaction prices as oracle (requires high volume)
Requirements:
Attack vector:
Defense strategy:
function getAsgayaOraclePrice():
asgaya_vwap = calculate_vwap_last_100_transactions()
exchange_median = getMultiExchangePrice("BCH/EUR")
if abs(asgaya_vwap - exchange_median) > exchange_median * 0.05: // >5% divergence
log_alert("Price manipulation detected")
// Asgaya bot steps in (uses bull pool funds)
if asgaya_vwap < exchange_median:
// Asgaya price too low - buy BCH to raise price
asgaya_bot_buys_bch(amount_to_correct_price)
else:
// Asgaya price too high - sell BCH to lower price
asgaya_bot_sells_bch(amount_to_correct_price)
// Use external oracle until manipulation cleared
return exchange_median
return asgaya_vwap
Advantages:
Disadvantages:
Verdict: Phase 2+ only, when volume high + defense bot ready + community confident
if not findAnyHedgeSpeculator(amount, duration):
show_error("No speculators available for this amount. Try again later or reduce amount.")
suggest_action("Join Telegram channel for updates on speculator availability")
capacity = checkAnyHedgeCapacity(amount, currency)
if not capacity.available:
show_error("Only €" + capacity.capacity + " hedging capacity available (you need €" + amount + ")")
suggest_action("Hedge €" + capacity.capacity + " now, wait for more capacity later")
try:
price = getOraclePrice("BCH/EUR")
catch OracleTimeout:
show_error("Price oracle unavailable. Cannot create hedge contract.")
suggest_action("Try again in a few minutes")
try:
settleAnyHedgeContract(contract_id)
catch SettlementError:
// Contract might be liquidated (price moved too far)
show_error("Contract settlement failed. Check contract status.")
// Manual intervention needed
Included:
Deferred to Phase 1+:
Alternative client features (not Phase 0):
Why defer most features? Phase 0 focuses on remittance flow (BCH → BCH). Stability layer is enhancement, not critical path.
Uses:
Used by:
Optional for:
Status: Phase 0+ (optional feature)
Updated: 2026-06-25
Complexity: Medium (CashTokens + AnyHedge integration)
Research: See AnyHedge documentation, General Protocols API docs
—
| 🏠 Home | ↑ Android App | 📖 Glossary |