Skip to content

Commit 7913a7f

Browse files
refactor(oracle): remove dead code from asset registry (#2353)
* chore(oracle): add USDa stable coin to the oracle registry * fix: linter * fix: linter * Update x/common/denoms/denoms.go Co-authored-by: Unique Divine <[email protected]> * fix(asset-registry): make "uusd" denoms.UUSD and add denoms.USDA * chore: linter and the remainder of dead code changes --------- Co-authored-by: Unique Divine <[email protected]> Co-authored-by: Unique Divine <[email protected]>
1 parent 62c03bf commit 7913a7f

32 files changed

+198
-336
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ changelog format](https://keepachangelog.com/en/1.0.0/).
4646
See https://github.com/dangoslen/changelog-enforcer.
4747
-->
4848

49+
- [#2353](https://github.com/NibiruChain/nibiru/pull/2353) - refactor(oracle): remove dead code from asset registry
50+
4951
### Dependencies
5052
- Bump `base-x` from 3.0.10 to 3.0.11 ([#2355](https://github.com/NibiruChain/nibiru/pull/2355))
5153

@@ -59,6 +61,7 @@ See https://github.com/dangoslen/changelog-enforcer.
5961
- [#2348](https://github.com/NibiruChain/nibiru/pull/2348) - fix(oracle): max expiration a label rather than an invalidation for additional query liveness
6062
- [#2350](https://github.com/NibiruChain/nibiru/pull/2350) - fix(simapp): sim tests with empty validator set panic
6163
- [#2352](https://github.com/NibiruChain/nibiru/pull/2352) - chore(token-registry): Add bank coin versions of USDC and USDT from Stargate and LayerZero, and update ErisEvm.sol to fix redeem
64+
- [#2354](https://github.com/NibiruChain/nibiru/pull/2354) - chore: linter upgrade to v2
6265
- [#2357](https://github.com/NibiruChain/nibiru/pull/2357) - fix: proper statedb isolation in nibiru bank_extension
6366

6467
### Dependencies

INSTALL.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ This guide will explain how to install the Nibiru Chain binary, `nibid`, onto yo
1010
- [4. Clone the Nibiru Repository](#4-clone-the-nibiru-repository)
1111
- [Upgrade](#upgrade)
1212
- [Troubleshooting](#troubleshooting)
13-
- [Contributing](#contributing)
14-
- [Troubleshooting](#troubleshooting-1)
13+
- [Contributing](#contributing)
1514
- [Error when running `make install` on MacOS](#error-when-running-make-install-on-macos)
1615

1716
## 1. Update the system
@@ -86,7 +85,7 @@ export PATH=$PATH:$(go env GOPATH)/bin
8685

8786
B. New commands you've made on the `nibid` don't show up. Your `nibid` probably just isn't updated again after the code changes, to recompile nibid run `make install` in the root
8887

89-
## Contributing
88+
### Contributing
9089

9190
The code for `nibid` is located in the `/cmd/nibid` folder.
9291

@@ -110,8 +109,6 @@ nibid tx --help
110109
nibid query oracle --help
111110
```
112111

113-
## Troubleshooting
114-
115112
### Error when running `make install` on MacOS
116113

117114
If you get an error like this when running `make install` on MacOS:

eth/chain_id_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestParseChainID_Happy(t *testing.T) {
4040
for _, tc := range testCases {
4141
chainIDEpoch, err := ParseEthChainIDStrict(tc.chainID)
4242
require.NoError(t, err, tc.name)
43-
var errMsg = ""
43+
errMsg := ""
4444
if err != nil {
4545
errMsg = err.Error()
4646
}

eth/rpc/rpcapi/tx_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (b *Backend) GetTransactionReceipt(hash gethcommon.Hash) (*TransactionRecei
266266
}
267267
cumulativeGasUsed += res.CumulativeGasUsed
268268

269-
var status = gethcore.ReceiptStatusSuccessful
269+
status := gethcore.ReceiptStatusSuccessful
270270
if res.Failed {
271271
status = gethcore.ReceiptStatusFailed
272272
}

gosdk/gosdk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (s *TestSuite) DoTestBroadcastMsgsGrpc() (txHashHex string) {
135135
txHashHex = s.AssertTxResponseSuccess(txResp)
136136

137137
base := 10
138-
var txRespCode = strconv.FormatUint(uint64(txResp.Code), base)
138+
txRespCode := strconv.FormatUint(uint64(txResp.Code), base)
139139
s.EqualValuesf(txResp.Code, 0,
140140
"code: %v\nraw log: %s", txRespCode, txResp.RawLog)
141141
return txHashHex

x/common/asset/registry.go

Lines changed: 7 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,12 @@ package asset
22

33
import (
44
"github.com/NibiruChain/nibiru/v2/x/common/denoms"
5-
"github.com/NibiruChain/nibiru/v2/x/common/set"
65
)
76

8-
type registry map[string]set.Set[string]
9-
10-
var Registry registry
11-
12-
func init() {
13-
// map of base asset to supported quote assets
14-
// quote assets are usually stables
15-
Registry = map[string]set.Set[string]{
16-
denoms.BTC: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
17-
denoms.ETH: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
18-
denoms.NIBI: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
19-
denoms.ATOM: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
20-
denoms.OSMO: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
21-
denoms.AVAX: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
22-
denoms.SOL: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
23-
denoms.BNB: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
24-
denoms.ADA: set.New(denoms.USDC, denoms.NUSD, denoms.USD, denoms.USDT),
25-
denoms.NUSD: set.New(denoms.USD, denoms.USDC),
26-
denoms.USDC: set.New(denoms.USD, denoms.NUSD),
27-
denoms.USDT: set.New(denoms.USD, denoms.NUSD, denoms.USDC),
28-
}
29-
}
30-
31-
func (r registry) Pair(base string, quote string) Pair {
32-
for q := range r[base] {
33-
if q == quote {
34-
return NewPair(string(base), string(quote))
35-
}
36-
}
37-
38-
return ""
39-
}
40-
41-
// Returns all supported base denoms
42-
func (r registry) BaseDenoms() set.Set[string] {
43-
baseSet := make(set.Set[string])
44-
for d := range r {
45-
baseSet.Add(d)
46-
}
47-
return baseSet
48-
}
49-
50-
// Returns all supported quote denoms
51-
func (r registry) QuoteDenoms() set.Set[string] {
52-
quoteSet := make(set.Set[string])
53-
for base := range r {
54-
for q := range r[base] {
55-
quoteSet.Add(q)
56-
}
57-
}
58-
return quoteSet
59-
}
60-
61-
// Checks if the provided denom is a supported base denom
62-
func (r registry) IsSupportedBaseDenom(denom string) bool {
63-
_, ok := r[denom]
64-
return ok
65-
}
66-
67-
// Checks if the provided denom is a supported quote denom
68-
func (r registry) IsSupportedQuoteDenom(denom string) bool {
69-
return r.QuoteDenoms().Has(denom)
70-
}
71-
72-
// Checks if the provided denom is a supported denom
73-
func (r registry) IsSupportedDenom(denom string) bool {
74-
return r.IsSupportedBaseDenom(string(denom)) || r.IsSupportedQuoteDenom(string(denom))
75-
}
76-
77-
// Checks if the provided base and quote denoms are a supported pair
78-
func (r registry) IsSupportedPair(base string, quote string) bool {
79-
return r.IsSupportedBaseDenom(base) && r.IsSupportedQuoteDenom(quote)
80-
}
7+
const (
8+
PAIR_BTC Pair = denoms.BTC + ":" + denoms.UUSD
9+
PAIR_ETH Pair = denoms.ETH + ":" + denoms.UUSD
10+
PAIR_ATOM Pair = denoms.ATOM + ":" + denoms.UUSD
11+
PAIR_USDC Pair = denoms.USDC + ":" + denoms.UUSD
12+
PAIR_USDT Pair = denoms.USDT + ":" + denoms.UUSD
13+
)

x/common/asset/registry_test.go

Lines changed: 0 additions & 81 deletions
This file was deleted.

x/common/dec.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func MustSqrtDec(dec sdkmath.LegacyDec) sdkmath.LegacyDec {
5454
// large as 10**99.
5555
func SqrtDec(dec sdkmath.LegacyDec) (sdkmath.LegacyDec, error) {
5656
var sqrtDec sdkmath.LegacyDec
57-
var panicErr = TryCatch(func() {
57+
panicErr := TryCatch(func() {
5858
sqrtDec = MustSqrtDec(dec)
5959
})()
6060
return sqrtDec, panicErr
@@ -71,7 +71,7 @@ func MustSqrtBigInt(i *big.Int) *big.Int {
7171
// SqrtBigInt is the panic-safe version of MustSqrtBigInt
7272
func SqrtBigInt(i *big.Int) (*big.Int, error) {
7373
sqrtInt := new(big.Int)
74-
var panicErr = TryCatch(func() {
74+
panicErr := TryCatch(func() {
7575
*sqrtInt = *MustSqrtBigInt(i)
7676
})()
7777
return sqrtInt, panicErr

x/common/denoms/denoms.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
package denoms
22

3+
// Post Nibiru v2.6.0
4+
const (
5+
// NOTE: US dollars. Use `denoms.USD` instead of `denoms.UUSD` going forward.
6+
USD = "usd"
7+
// Avalon Finance overcollateralized stablecoin.
8+
// https://github.com/NibiruChain/pricefeeder/pull/64
9+
USDA = "usda"
10+
SUSDA = "susda"
11+
)
12+
13+
// Legacy denoms - These each include an unnecessary "u" prefix for micro.
14+
315
const ( // stablecoins
416
USDC = "uusdc"
517
NUSD = "unusd"
6-
USD = "uusd"
18+
UUSD = "uusd"
719
USDT = "uusdt"
820
)
921

x/common/error_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ func TestCombineErrorsGeneric(t *testing.T) {
8888
{name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")},
8989

9090
// cases: fmt.Stringer
91-
{name: "type=fmt.Stringer |", in: asset.Registry.Pair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")},
91+
{name: "type=fmt.Stringer |", in: asset.NewPair(denoms.USDC, denoms.NUSD), out: errors.New("uusdc:unusd")},
9292

9393
// cases: []fmt.Stringer
9494
{
9595
name: "type=[]fmt.Stringer | happy",
96-
in: []fmt.Stringer{asset.Registry.Pair(denoms.BTC, denoms.NUSD), asset.Registry.Pair(denoms.ETH, denoms.NUSD)},
97-
out: errors.New("ubtc:unusd: ueth:unusd"),
96+
in: []fmt.Stringer{
97+
asset.NewPair(denoms.BTC, denoms.NUSD),
98+
asset.NewPair(denoms.ETH, denoms.NUSD),
99+
},
100+
out: errors.New("ubtc:unusd: ueth:unusd"),
98101
},
99102
{name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil},
100103
}

0 commit comments

Comments
 (0)