Skip to content

Commit de32fcb

Browse files
committed
Update Readme & Refactor
1 parent d42f199 commit de32fcb

7 files changed

Lines changed: 120 additions & 27 deletions

File tree

pricefeeder/price-feeder.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ tmrpc_endpoint = "http://localhost:26657"
1616
enable-hostname = true
1717
enable-hostname-label = true
1818
enable-service-label = true
19-
# This will not be enabled if default telemetry is already enabled in the cheqd app config
19+
# This will not be enabled if default telemetry is already enabled in the dm app config
2020
# and the pricefeeder is not running as a separate process (i.e., it is running within the app binary).
2121
# Pricefeeder metrics will still be recorded regardless.
2222
enabled = true
23-
global-labels = [["chain_id", "cheqd"]]
24-
# This service-name will not be used if default telemetry is already enabled in the cheqd app config
23+
global-labels = [["chain_id", "dmchain"]]
24+
# This service-name will not be used if default telemetry is already enabled in the dm app config
2525
# and the pricefeeder is not running as a separate process (i.e., it is running within the app binary).
2626
service-name = "price-feeder"
2727
prometheus-retention-time = 100

util/ptr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
)
66

77
const (
8-
CheqExponent = 9
8+
DmExponent = 9
99
UsdScaleExponent = 6
1010
)
1111

1212
var (
13-
CheqScale = sdkmath.NewIntWithDecimal(1, CheqExponent)
13+
DmScale = sdkmath.NewIntWithDecimal(1, DmExponent)
1414
UsdScale = sdkmath.NewIntWithDecimal(1, UsdScaleExponent)
1515
UsdFrom18To6 = sdkmath.NewInt(1_000_000_000_000)
1616
UsdExponent = sdkmath.NewIntWithDecimal(1, 18)

x/oracle/README.md

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,96 @@
1-
# Example Module
1+
# Oracle Module
22

3-
This is a module base generated with [`spawn`](https://github.com/rollchains/spawn).
3+
## Abstract
4+
5+
This module is a **fork of `ojo-network/x/oracle`**, refactored to utilize the **Cosmos SDK Collections** framework for state management. This ensures type-safety, improved performance through native binary codecs, and a more maintainable schema definition.
6+
7+
## Contents
8+
9+
1. **[Concepts](https://www.google.com/search?q=%23concepts)**
10+
2. **[State & Collections](https://www.google.com/search?q=%23state--collections)**
11+
3. **[End Block](https://www.google.com/search?q=%23end-block)**
12+
4. **[Messages](https://www.google.com/search?q=%23messages)**
13+
5. **[Events](https://www.google.com/search?q=%23events)**
14+
6. **[Parameters](https://www.google.com/search?q=%23params)**
15+
16+
## Concepts
17+
18+
### Voting Procedure
19+
20+
The Oracle module obtains consensus via a **Commit-Reveal scheme** over a `VotePeriod`.
21+
22+
* **Prevote and Vote**:
23+
* `MsgAggregateExchangeRatePrevote`: A SHA256 hash of the rates.
24+
* `MsgAggregateExchangeRateVote`: The salt and actual rates to reveal the previous period's commitment.
25+
26+
27+
* **Vote Tally**: At the end of `VotePeriod`, the module verifies hashes and calculates the **Median** exchange rate. Rates receiving less than `VoteThreshold` power are deleted.
28+
* **Ballot Rewards**: Winners (those within the `RewardBand`) are rewarded from the reward pool. In this fork, the `ValidatorRewardSet` is cached to optimize reward distribution across the `SlashWindow`.
29+
30+
### Slashing
31+
32+
Validators must maintain a `MinValidPerWindow` (e.g., 5%) success rate. Failure to vote on **all** assets in the `AcceptList` or voting outside the `RewardBand` results in a "miss." If the threshold is not met by the end of a `SlashWindow`, the validator is slashed and jailed.
33+
34+
## State & Collections
35+
36+
This module utilizes `cosmossdk.io/collections` for all on-chain storage. This removes manual byte-prefixing and Protobuf wrapping (e.g., `gogotypes.UInt64Value`) in favor of type-safe Maps and Items.
37+
38+
### Exchange Rates
39+
40+
Stored as a `math.LegacyDec`.
41+
42+
* `ExchangeRates`: `Map<string, math.LegacyDec>`
43+
* `HistoricPrices`: `Map<Pair<string, uint64>, math.LegacyDec>` (Denom + BlockHeight)
44+
45+
### Validator Management
46+
47+
* **FeederDelegation**: Maps a validator operator to a proxy "feeder" account.
48+
* `FeederDelegations`: `Map<sdk.ValAddress, sdk.AccAddress>`
49+
50+
51+
* **MissCounter**: Tracks missed vote periods.
52+
* `MissCounters`: `Map<sdk.ValAddress, uint64>`
53+
54+
55+
* **ValidatorRewardSet**: A singleton storing the active validators eligible for rewards.
56+
* `ValidatorRewardSet`: `Item<types.ValidatorRewardSet>`
57+
58+
59+
60+
### Voting State
61+
62+
* **AggregateExchangeRatePrevote**: `Map<sdk.ValAddress, types.AggregateExchangeRatePrevote>`
63+
* **AggregateExchangeRateVote**: `Map<sdk.ValAddress, types.AggregateExchangeRateVote>`
64+
65+
### Price Averages (dmchain specific)
66+
67+
The `dmchain` fork includes native support for computed averages:
68+
69+
* `Averages`: `Map<Pair<string, string>, math.LegacyDec>` (Denom + AvgType, e.g., "SMA", "EMA")
70+
71+
## End Block
72+
73+
At the end of every `VotePeriod`:
74+
75+
1. **Purge**: Expired exchange rates are cleared.
76+
2. **Organize**: Votes are grouped into ballots by denomination.
77+
3. **Tally**:
78+
* Calculate the **Median** and **Standard Deviation**.
79+
* Define the winners within the `RewardBand`.
80+
81+
82+
4. **Record**: Update `ExchangeRates` and compute `Averages` (SMA/EMA/WMA).
83+
5. **Slash/Reward**: Increment `MissCounters`, distribute rewards to `ValidatorRewardSet`, and jail underperforming validators at the end of the `SlashWindow`.
84+
6. **Cleanup**: Clear previous period votes and prevotes.
85+
86+
## Messages
87+
88+
The module supports the standard Ojo Oracle message set, including:
89+
90+
* `MsgAggregateExchangeRatePrevote`
91+
* `MsgAggregateExchangeRateVote`
92+
* `MsgDelegateFeedConsent`
93+
94+
## Params
95+
96+
Parameters are managed via the standard `Params` struct, typically updated via governance. Keys include `VotePeriod`, `VoteThreshold`, `RewardBand`, `SlashWindow`, and the `AcceptList` (denominations to provide prices for).

x/oracle/client/cli/query.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func GetCmdQueryAggregateVote() *cobra.Command {
7474
Long: strings.TrimSpace(`
7575
Query outstanding oracle aggregate vote.
7676
77-
$ cheqd-noded query oracle aggregate-votes
77+
$ simd query oracle aggregate-votes
7878
7979
Or, you can filter with voter address
8080
81-
$ cheqd-noded query oracle aggregate-votes cheqdvaloper...
81+
$ simd query oracle aggregate-votes cheqdvaloper...
8282
`),
8383
RunE: func(cmd *cobra.Command, args []string) error {
8484
clientCtx, err := client.GetClientQueryContext(cmd)
@@ -116,11 +116,11 @@ func GetCmdQueryAggregatePrevote() *cobra.Command {
116116
Long: strings.TrimSpace(`
117117
Query outstanding oracle aggregate prevotes.
118118
119-
$ cheqd-noded query oracle aggregate-prevotes
119+
$ simd query oracle aggregate-prevotes
120120
121121
Or, can filter with voter address
122122
123-
$ cheqd-noded query oracle aggregate-prevotes cheqdvaloper...
123+
$ simd query oracle aggregate-prevotes cheqdvaloper...
124124
`),
125125
RunE: func(cmd *cobra.Command, args []string) error {
126126
clientCtx, err := client.GetClientQueryContext(cmd)
@@ -158,7 +158,7 @@ func GetCmdQueryExchangeRates() *cobra.Command {
158158
Query the current exchange rates of assets based on USD.
159159
You can find the current list of active denoms by running
160160
161-
$ cheqd-noded query oracle exchange-rates
161+
$ simd query oracle exchange-rates
162162
`),
163163
RunE: func(cmd *cobra.Command, args []string) error {
164164
clientCtx, err := client.GetClientQueryContext(cmd)
@@ -185,7 +185,7 @@ func GetCmdQueryExchangeRate() *cobra.Command {
185185
Long: strings.TrimSpace(`
186186
Query the current exchange rates of an asset based on USD.
187187
188-
$ cheqd-noded query oracle exchange-rate ATOM
188+
$ simd query oracle exchange-rate ATOM
189189
`),
190190
RunE: func(cmd *cobra.Command, args []string) error {
191191
clientCtx, err := client.GetClientQueryContext(cmd)

x/oracle/types/codec.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ func init() {
2727
// RegisterLegacyAminoCodec registers the necessary x/oracle interfaces and concrete types
2828
// on the provided LegacyAmino codec. These types are used for Amino JSON serialization.
2929
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
30-
cdc.RegisterConcrete(&MsgAggregateExchangeRatePrevote{}, "cheqd/oracle/MsgAggregateExchangeRatePrevote", nil)
31-
cdc.RegisterConcrete(&MsgAggregateExchangeRateVote{}, "cheqd/oracle/MsgAggregateExchangeRateVote", nil)
32-
cdc.RegisterConcrete(&MsgDelegateFeedConsent{}, "cheqd/oracle/MsgDelegateFeedConsent", nil)
33-
cdc.RegisterConcrete(&MsgLegacyGovUpdateParams{}, "cheqd/oracle/MsgLegacyGovUpdateParams", nil)
34-
cdc.RegisterConcrete(&MsgGovUpdateParams{}, "cheqd/oracle/MsgGovUpdateParams", nil)
35-
cdc.RegisterConcrete(&MsgGovAddDenoms{}, "cheqd/oracle/MsgGovAddDenoms", nil)
36-
cdc.RegisterConcrete(&MsgGovRemoveCurrencyPairProviders{}, "cheqd/oracle/MsgGovRemoveCurrencyPairProviders", nil)
30+
cdc.RegisterConcrete(&MsgAggregateExchangeRatePrevote{}, "dmchain/oracle/MsgAggregateExchangeRatePrevote", nil)
31+
cdc.RegisterConcrete(&MsgAggregateExchangeRateVote{}, "dmchain/oracle/MsgAggregateExchangeRateVote", nil)
32+
cdc.RegisterConcrete(&MsgDelegateFeedConsent{}, "dmchain/oracle/MsgDelegateFeedConsent", nil)
33+
cdc.RegisterConcrete(&MsgLegacyGovUpdateParams{}, "dmchain/oracle/MsgLegacyGovUpdateParams", nil)
34+
cdc.RegisterConcrete(&MsgGovUpdateParams{}, "dmchain/oracle/MsgGovUpdateParams", nil)
35+
cdc.RegisterConcrete(&MsgGovAddDenoms{}, "dmchain/oracle/MsgGovAddDenoms", nil)
36+
cdc.RegisterConcrete(&MsgGovRemoveCurrencyPairProviders{}, "dmchain/oracle/MsgGovRemoveCurrencyPairProviders", nil)
3737
cdc.RegisterConcrete(
3838
&MsgGovRemoveCurrencyDeviationThresholds{},
39-
"cheqd/oracle/MsgGovRemoveCurrencyDeviationThresholds",
39+
"dmchain/oracle/MsgGovRemoveCurrencyDeviationThresholds",
4040
nil,
4141
)
4242
}

x/oracle/types/currency_pair_providers_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,38 @@ func TestCurrencyPairProvidersString(t *testing.T) {
3636

3737
func TestCurrencyPairProvidersEqual(t *testing.T) {
3838
cpp1 := CurrencyPairProviders{
39-
BaseDenom: "CHEQ",
39+
BaseDenom: "DM",
4040
QuoteDenom: "USD",
4141
Providers: []string{
4242
"binance",
4343
"coinbase",
4444
},
4545
}
4646
cpp2 := CurrencyPairProviders{
47-
BaseDenom: "CHEQ",
47+
BaseDenom: "DM",
4848
QuoteDenom: "USD",
4949
Providers: []string{
5050
"binance",
5151
"coinbase",
5252
},
5353
}
5454
cpp3 := CurrencyPairProviders{
55-
BaseDenom: "CHEQ",
55+
BaseDenom: "DM",
5656
QuoteDenom: "ATOM",
5757
Providers: []string{
5858
"binance",
5959
"coinbase",
6060
},
6161
}
6262
cpp4 := CurrencyPairProviders{
63-
BaseDenom: "CHEQ",
63+
BaseDenom: "DM",
6464
QuoteDenom: "USD",
6565
Providers: []string{
6666
"binance",
6767
},
6868
}
6969
cpp5 := CurrencyPairProviders{
70-
BaseDenom: "CHEQ",
70+
BaseDenom: "DM",
7171
QuoteDenom: "ATOM",
7272
Providers: []string{
7373
"binance",

x/oracle/types/params_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestAddDefaultRB(t *testing.T) {
304304
p := DefaultRewardBands()
305305
p.AddDefault("foo")
306306
require.Equal(t, p.String(),
307-
"symbol_denom: CHEQ\nreward_band: \"0.020000000000000000\"\n\n"+
307+
"symbol_denom: DM\nreward_band: \"0.020000000000000000\"\n\n"+
308308
"symbol_denom: USDT\nreward_band: \"0.020000000000000000\"\n\n"+
309309
"symbol_denom: USDC\nreward_band: \"0.020000000000000000\"\n\n"+
310310
"symbol_denom: foo\nreward_band: \"0.020000000000000000\"")

0 commit comments

Comments
 (0)