feat(P02): Bread unit + Root Basket + Forge/Fold types

---ci---
project: oy
phase: 2
milestone: v0.1
status: execute
---/ci---

Phase 2 (Component 3: Bread & Root Basket) skeleton:
- x/bread: Bread unit scale (11 denominations: Grain to Earth, §4)
- x/forge: Forge/Fold types, Root Basket composition (§6)
- Root Basket: Treasuries 35%, IG corporate 25%, gold 20%, Bitcoin 10%, other RWA 10%
- Basket validation: sums to 100, no single asset >50%, no leverage/futures
- Forge errors: AssetNotSupported, StillActive, BelowMinimum, MirrorQuorumFailed
- 9 unit tests passing
- Lexicon compliant (fixed 'deposited' -> 'provided')
This commit is contained in:
CIAgent
2026-08-17 19:57:56 +00:00
parent d9a8b28cd3
commit 0131c0cbbb
4 changed files with 309 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
package types
import "encoding/json"
const (
ModuleName = "bread"
StoreKey = ModuleName
RouterKey = ModuleName
QuerierRoute = ModuleName
// Bread atomic unit = Grain (§4)
// 1 Bread = 10,000 Grain
GrainsPerBread = 10000
// Bread scale denominations (§4)
// Grain = 1 (atomic)
// Crumb = 100 Grain
// Bread = 10,000 Grain (~$1)
// Loaf = 10 Bread
// Batch = 100 Bread
// Cake = 1,000 Bread
// Bakery = 10,000 Bread
// Granary = 100,000 Bread
// Mill = 1,000,000 Bread
// Harvest = 10,000,000 Bread
// Earth = 100,000,000 Bread
)
// BreadScale defines the unit scale (§4)
type BreadScale struct {
Name string `json:"name" yaml:"name"`
GrainValue int64 `json:"grain_value" yaml:"grain_value"`
}
// BreadScaleAll returns all denominations (§4)
func BreadScaleAll() []BreadScale {
return []BreadScale{
{"Grain", 1},
{"Crumb", 100},
{"Bread", 10000},
{"Loaf", 100000},
{"Batch", 1000000},
{"Cake", 10000000},
{"Bakery", 100000000},
{"Granary", 1000000000},
{"Mill", 10000000000},
{"Harvest", 100000000000},
{"Earth", 1000000000000},
}
}
// Params for the bread module
type Params struct {
DenomGrain string `json:"denom_grain" yaml:"denom_grain"`
DenomBread string `json:"denom_bread" yaml:"denom_bread"`
}
func DefaultParams() Params {
return Params{
DenomGrain: "ugrain",
DenomBread: "ubread",
}
}
// GenesisState defines the bread module genesis state
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
}
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Params: DefaultParams(),
}
}
func ValidateGenesis(bz json.RawMessage) error { return nil }
+45
View File
@@ -0,0 +1,45 @@
package types_test
import (
"testing"
"github.com/oy/openyield/x/bread/types"
)
func TestGrainsPerBread(t *testing.T) {
if types.GrainsPerBread != 10000 {
t.Errorf("GrainsPerBread = %d, expected 10000 (§4: 1 Bread = 10,000 Grain)", types.GrainsPerBread)
}
}
func TestBreadScaleCount(t *testing.T) {
scale := types.BreadScaleAll()
if len(scale) != 11 {
t.Errorf("BreadScale length = %d, expected 11 denominations (§4)", len(scale))
}
}
func TestBreadScaleValues(t *testing.T) {
scale := types.BreadScaleAll()
expected := map[string]int64{
"Grain": 1, "Crumb": 100, "Bread": 10000, "Loaf": 100000,
"Batch": 1000000, "Cake": 10000000, "Bakery": 100000000,
"Granary": 1000000000, "Mill": 10000000000,
"Harvest": 100000000000, "Earth": 1000000000000,
}
for _, s := range scale {
if s.GrainValue != expected[s.Name] {
t.Errorf("%s = %d, expected %d", s.Name, s.GrainValue, expected[s.Name])
}
}
}
func TestDefaultDenoms(t *testing.T) {
params := types.DefaultParams()
if params.DenomGrain != "ugrain" {
t.Errorf("DenomGrain = %s, expected 'ugrain'", params.DenomGrain)
}
if params.DenomBread != "ubread" {
t.Errorf("DenomBread = %s, expected 'ubread'", params.DenomBread)
}
}