Skip to content
Draft
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ needed to include double quotes around the hexadecimal string.
- [#2172](https://github.com/NibiruChain/nibiru/pull/2172) - chore: close iterator in IterateEpochInfo
- [#2173](https://github.com/NibiruChain/nibiru/pull/2173) - fix(evm): clear `StateDB` between calls
- [#2177](https://github.com/NibiruChain/nibiru/pull/2177) - fix(cmd): Continue from #2127 and unwire vesting flags and logic from genaccounts.go
- [#2181](https://github.com/NibiruChain/nibiru/pull/2181) - fix: change pair delimiter
- [#2176](https://github.com/NibiruChain/nibiru/pull/2176) - tests(evm): add dirty state tests from code4rena audit
- [#2180](https://github.com/NibiruChain/nibiru/pull/2180) - fix(evm): apply gas consumption across the entire EVM codebase at `CallContractWithInput`
- [#2183](https://github.com/NibiruChain/nibiru/pull/2183) - fix(evm): bank keeper extension gas meter type
Expand Down
4 changes: 2 additions & 2 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ add_genesis_param '.app_state.sudo.sudoers.root = "'"$val_address"'"'
# hack for localnet since we don't have a pricefeeder yet
price_btc="50000"
price_eth="2000"
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc@uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].exchange_rate = "'"$price_btc"'"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth@uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].exchange_rate = "'"$price_eth"'"'

# ------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion evm-e2e/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const deployContractNibiruOracleChainLinkLike = async (): Promise<{
deploymentTransaction(): ContractTransactionResponse;
};
}> => {
const oraclePair = 'ueth:uuusd';
const oraclePair = 'ueth@uuusd';
const factory = new NibiruOracleChainLinkLike__factory(account);
const contract = await factory.deploy(oraclePair, toBigInt(8));
await contract.waitForDeployment();
Expand Down
10 changes: 5 additions & 5 deletions x/common/asset/pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ type Pair string

func NewPair(base string, quote string) Pair {
// validate as denom
ap := fmt.Sprintf("%s%s%s", base, ":", quote)
ap := fmt.Sprintf("%s%s%s", base, "@", quote)
return Pair(ap)
}

// TryNewPair New returns a new asset pair instance if the pair is valid.
// The form, "token0:token1", is expected for 'pair'.
// Use this function to return an error instead of panicking.
func TryNewPair(pair string) (Pair, error) {
split := strings.Split(pair, ":")
split := strings.Split(pair, "@")
splitLen := len(split)
if splitLen != 2 {
if splitLen == 1 {
Expand Down Expand Up @@ -72,12 +72,12 @@ func (pair Pair) Inverse() Pair {
}

func (pair Pair) BaseDenom() string {
split := strings.Split(pair.String(), ":")
split := strings.Split(pair.String(), "@")
return split[0]
}

func (pair Pair) QuoteDenom() string {
split := strings.Split(pair.String(), ":")
split := strings.Split(pair.String(), "@")
return split[1]
}

Expand All @@ -87,7 +87,7 @@ func (pair Pair) Validate() error {
return ErrInvalidTokenPair.Wrap("pair is empty")
}

split := strings.Split(pair.String(), ":")
split := strings.Split(pair.String(), "@")
if len(split) != 2 {
return ErrInvalidTokenPair.Wrap(pair.String())
}
Expand Down
45 changes: 27 additions & 18 deletions x/common/asset/pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestTryNewPair(t *testing.T) {
},
{
"more than 2 tokens",
fmt.Sprintf("%s:%s:%s", denoms.NIBI, denoms.NUSD, denoms.USDC),
fmt.Sprintf("%s@%s@%s", denoms.NIBI, denoms.NUSD, denoms.USDC),
asset.ErrInvalidTokenPair,
},
{
Expand All @@ -37,22 +37,27 @@ func TestTryNewPair(t *testing.T) {
},
{
"correct pair",
fmt.Sprintf("%s:%s", denoms.NIBI, denoms.NUSD),
fmt.Sprintf("%s@%s", denoms.NIBI, denoms.NUSD),
nil,
},
{
"correct pair 2",
fmt.Sprintf("%s:@%s", denoms.NIBI, denoms.NUSD),
nil,
},
{
"empty token identifier",
fmt.Sprintf(":%s", denoms.ETH),
fmt.Sprintf("@%s", denoms.ETH),
fmt.Errorf("empty token identifiers are not allowed"),
},
{
"invalid denom 1",
"-invalid1:valid",
"-invalid1@valid",
fmt.Errorf("invalid denom"),
},
{
"invalid denom 2",
"valid:-invalid2",
"valid@-invalid2",
fmt.Errorf("invalid denom"),
},
}
Expand All @@ -71,17 +76,17 @@ func TestTryNewPair(t *testing.T) {
}

func TestGetDenoms(t *testing.T) {
pair := asset.MustNewPair("uatom:unibi")
pair := asset.MustNewPair("uatom@unibi")

require.Equal(t, "uatom", pair.BaseDenom())
require.Equal(t, "unibi", pair.QuoteDenom())
}

func TestEquals(t *testing.T) {
pair := asset.MustNewPair("abc:xyz")
matchingOther := asset.MustNewPair("abc:xyz")
mismatchToken1 := asset.MustNewPair("abc:abc")
inversePair := asset.MustNewPair("xyz:abc")
pair := asset.MustNewPair("abc@xyz")
matchingOther := asset.MustNewPair("abc@xyz")
mismatchToken1 := asset.MustNewPair("abc@abc")
inversePair := asset.MustNewPair("xyz@abc")

require.True(t, pair.Equal(matchingOther))
require.False(t, pair.Equal(inversePair))
Expand All @@ -90,16 +95,20 @@ func TestEquals(t *testing.T) {

func TestMustNewAssetPair(t *testing.T) {
require.Panics(t, func() {
asset.MustNewPair("aaa:bbb:ccc")
asset.MustNewPair("aaa@bbb@ccc")
})

require.NotPanics(t, func() {
require.Panics(t, func() {
asset.MustNewPair("aaa:bbb")
})

require.NotPanics(t, func() {
asset.MustNewPair("aaa@bbb")
})
}

func TestInverse(t *testing.T) {
pair := asset.MustNewPair("abc:xyz")
pair := asset.MustNewPair("abc@xyz")
inverse := pair.Inverse()
require.Equal(t, "xyz", inverse.BaseDenom())
require.Equal(t, "abc", inverse.QuoteDenom())
Expand All @@ -113,8 +122,8 @@ func TestMarshalJSON(t *testing.T) {
input asset.Pair
strOutput string
}{
{name: "happy-0", input: asset.Pair("abc:xyz"), strOutput: "\"abc:xyz\""},
{name: "happy-1", input: asset.Pair("abc:xyz:foo"), strOutput: "\"abc:xyz:foo\""},
{name: "happy-0", input: asset.Pair("abc@xyz"), strOutput: "\"abc@xyz\""},
{name: "happy-1", input: asset.Pair("abc@xyz@foo"), strOutput: "\"abc@xyz@foo\""},
{name: "happy-2", input: asset.Pair("abc"), strOutput: "\"abc\""},
{name: "empty", input: asset.Pair(""), strOutput: "\"\""},
}
Expand Down Expand Up @@ -156,9 +165,9 @@ func TestPairsUtils(t *testing.T) {
pairStrs []string
expectPanic bool
}{
{pairStrs: []string{"eth:usd", "btc:usd", "atom:usd"}, expectPanic: false},
{pairStrs: []string{"eth:usd", "", "abc"}, expectPanic: true},
{pairStrs: []string{"eth:usd:ftt", "btc:usd"}, expectPanic: true},
{pairStrs: []string{"eth@usd", "btc@usd", "atom@usd"}, expectPanic: false},
{pairStrs: []string{"eth@usd", "", "abc"}, expectPanic: true},
{pairStrs: []string{"eth@usd@ftt", "btc@usd"}, expectPanic: true},
}

var panicTestFn func(t require.TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{})
Expand Down
4 changes: 2 additions & 2 deletions x/common/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func TestCombineErrorsGeneric(t *testing.T) {
{name: "type=[]string | mixed", in: []string{"", "abc", ""}, out: errors.New(": abc: ")},

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

// cases: []fmt.Stringer
{
name: "type=[]fmt.Stringer | happy",
in: []fmt.Stringer{asset.Registry.Pair(denoms.BTC, denoms.NUSD), asset.Registry.Pair(denoms.ETH, denoms.NUSD)},
out: errors.New("ubtc:unusd: ueth:unusd"),
out: errors.New("ubtc@unusd: ueth@unusd"),
},
{name: "type=[]fmt.Stringer | empty", in: []fmt.Stringer{}, out: nil},
}
Expand Down
2 changes: 1 addition & 1 deletion x/common/omap/omap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ type DummyValue struct{}
// TestPair tests an SortedMap where the key is an asset.Pair.
func (s *Suite) TestPair() {
pairStrs := []string{
"abc:xyz", "abc:abc", "aaa:bbb", "xyz:xyz", "bbb:ccc", "xyz:abc",
"abc@xyz", "abc@abc", "aaa@bbb", "xyz@xyz", "bbb@ccc", "xyz@abc",
}
sortedKeyStrs := []string{}
sortedKeyStrs = append(sortedKeyStrs, pairStrs...)
Expand Down
6 changes: 3 additions & 3 deletions x/evm/precompile/oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *OracleSuite) TestOracle_HappyPath() {
) {
contractInput, err := embeds.SmartContract_Oracle.ABI.Pack(
string(precompile.OracleMethod_queryExchangeRate),
"unibi:uusd",
"unibi@uusd",
)
s.Require().NoError(err)
evmObj, _ := deps.NewEVM()
Expand All @@ -84,7 +84,7 @@ func (s *OracleSuite) TestOracle_HappyPath() {
// 69 seconds + 420 nanoseconds === 69000 milliseconds for the
// return value from the UnixMilli() function
deps.Ctx = deps.Ctx.WithBlockTime(time.Unix(69, 420)).WithBlockHeight(69)
deps.App.OracleKeeper.SetPrice(deps.Ctx, "unibi:uusd", sdk.MustNewDecFromStr("0.067"))
deps.App.OracleKeeper.SetPrice(deps.Ctx, "unibi@uusd", sdk.MustNewDecFromStr("0.067"))

resp, err := runQuery(deps.Ctx)
s.NoError(err)
Expand Down Expand Up @@ -129,7 +129,7 @@ func (s *OracleSuite) TestOracle_HappyPath() {

contractInput, err := embeds.SmartContract_Oracle.ABI.Pack(
string(precompile.OracleMethod_chainLinkLatestRoundData),
"unibi:uusd",
"unibi@uusd",
)
s.Require().NoError(err)
evmObj, _ := deps.NewEVM()
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ func TestExportInitGenesis(t *testing.T) {

input.OracleKeeper.Params.Set(input.Ctx, types.DefaultParams())
input.OracleKeeper.FeederDelegations.Insert(input.Ctx, keeper.ValAddrs[0], keeper.Addrs[1])
input.OracleKeeper.ExchangeRates.Insert(input.Ctx, "pair1:pair2",
input.OracleKeeper.ExchangeRates.Insert(input.Ctx, "pair1@pair2",
types.ExchangeRateAtBlock{
ExchangeRate: math.LegacyNewDec(123),
CreatedBlock: 0,
BlockTimestampMs: 0,
})
input.OracleKeeper.Prevotes.Insert(input.Ctx, keeper.ValAddrs[0], types.NewAggregateExchangeRatePrevote(types.AggregateVoteHash{123}, keeper.ValAddrs[0], uint64(2)))
input.OracleKeeper.Votes.Insert(input.Ctx, keeper.ValAddrs[0], types.NewAggregateExchangeRateVote(types.ExchangeRateTuples{{Pair: "foo", ExchangeRate: math.LegacyNewDec(123)}}, keeper.ValAddrs[0]))
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, "pair1:pair1")
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, "pair2:pair2")
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, "pair1@pair1")
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, "pair2@pair2")
input.OracleKeeper.MissCounters.Insert(input.Ctx, keeper.ValAddrs[0], 10)
input.OracleKeeper.Rewards.Insert(input.Ctx, 0, types.Rewards{
Id: 0,
Expand Down
24 changes: 12 additions & 12 deletions x/oracle/keeper/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (s *TestSuite) SetupTest() {
s.cfg.GenesisState[types.ModuleName] = s.cfg.Codec.MustMarshalJSON(func() codec.ProtoMarshaler {
gs := types.DefaultGenesisState()
gs.Params.Whitelist = []asset.Pair{
"nibi:usdc",
"btc:usdc",
"nibi@usdc",
"btc@usdc",
}

return gs
Expand Down Expand Up @@ -72,20 +72,20 @@ func (s *TestSuite) TestSuccessfulVoting() {
// then the number picked is the one in the middle always.
prices := []map[asset.Pair]sdk.Dec{
{
"nibi:usdc": math.LegacyOneDec(),
"btc:usdc": math.LegacyMustNewDecFromStr("100203.0"),
"nibi@usdc": math.LegacyOneDec(),
"btc@usdc": math.LegacyMustNewDecFromStr("100203.0"),
},
{
"nibi:usdc": math.LegacyOneDec(),
"btc:usdc": math.LegacyMustNewDecFromStr("100150.5"),
"nibi@usdc": math.LegacyOneDec(),
"btc@usdc": math.LegacyMustNewDecFromStr("100150.5"),
},
{
"nibi:usdc": math.LegacyOneDec(),
"btc:usdc": math.LegacyMustNewDecFromStr("100200.9"),
"nibi@usdc": math.LegacyOneDec(),
"btc@usdc": math.LegacyMustNewDecFromStr("100200.9"),
},
{
"nibi:usdc": math.LegacyOneDec(),
"btc:usdc": math.LegacyMustNewDecFromStr("100300.9"),
"nibi@usdc": math.LegacyOneDec(),
"btc@usdc": math.LegacyMustNewDecFromStr("100300.9"),
},
}
votes := s.sendPrevotes(prices)
Expand All @@ -99,8 +99,8 @@ func (s *TestSuite) TestSuccessfulVoting() {
gotPrices := s.currentPrices()
require.Equal(s.T(),
map[asset.Pair]sdk.Dec{
"nibi:usdc": math.LegacyOneDec(),
"btc:usdc": math.LegacyMustNewDecFromStr("100200.9"),
"nibi@usdc": math.LegacyOneDec(),
"btc@usdc": math.LegacyMustNewDecFromStr("100200.9"),
},
gotPrices,
)
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func TestQueryVoteTargets(t *testing.T) {
input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p)
}

voteTargets := []asset.Pair{"denom1:denom2", "denom3:denom4", "denom5:denom6"}
voteTargets := []asset.Pair{"denom1@denom2", "denom3@denom4", "denom5@denom6"}
for _, target := range voteTargets {
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, target)
}
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestAggregatePrevoteVote(t *testing.T) {
ExchangeRate: math.LegacyMustNewDecFromStr("0.29"),
},
{
Pair: "BTC:CNY",
Pair: "BTC@CNY",
ExchangeRate: math.LegacyMustNewDecFromStr("0.27"),
},
}
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/sudo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *SuiteOracleSudo) TestEditOracleParams() {
votePeriod := math.NewInt(1_234)
voteThreshold := math.LegacyMustNewDecFromStr("0.4")
rewardBand := math.LegacyMustNewDecFromStr("0.5")
whitelist := []string{"aave:usdc", "sol:usdc"}
whitelist := []string{"aave@usdc", "sol@usdc"}
slashFraction := math.LegacyMustNewDecFromStr("0.5")
slashWindow := math.NewInt(2_000)
minValidPerWindow := math.LegacyMustNewDecFromStr("0.5")
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/whitelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func TestKeeper_GetVoteTargets(t *testing.T) {
panicCases := []TestCase{
{name: "blank pair", in: []asset.Pair{""}, panic: true},
{name: "blank pair and others", in: []asset.Pair{"", "x", "abc", "defafask"}, panic: true},
{name: "denom len too short", in: []asset.Pair{"x:y", "xx:yy"}, panic: true},
{name: "denom len too short", in: []asset.Pair{"x@y", "xx@yy"}, panic: true},
}
happyCases := []TestCase{
{name: "happy", in: []asset.Pair{"foo:bar", "whoo:whoo"}},
{name: "happy", in: []asset.Pair{"foo@bar", "whoo@whoo"}},
}

for _, testCase := range append(panicCases, happyCases...) {
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestKeeper_GetVoteTargets(t *testing.T) {
input.OracleKeeper.WhitelistedPairs.Delete(input.Ctx, p)
}

expectedTargets := []asset.Pair{"foo:bar", "whoo:whoo"}
expectedTargets := []asset.Pair{"foo@bar", "whoo@whoo"}
for _, target := range expectedTargets {
input.OracleKeeper.WhitelistedPairs.Insert(input.Ctx, target)
}
Expand Down
8 changes: 4 additions & 4 deletions x/oracle/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ func TestMsgAggregateExchangeRateVote(t *testing.T) {

exchangeRates := types.ExchangeRateTuples{
{
Pair: "FOO:USD",
Pair: "FOO@USD",
ExchangeRate: math.LegacyMustNewDecFromStr("1.0"),
},
{
Pair: "BAR:USD",
Pair: "BAR@USD",
ExchangeRate: math.LegacyMustNewDecFromStr("1232.132"),
},
}

abstainExchangeRates := types.ExchangeRateTuples{
{
Pair: "FOO:USD",
Pair: "FOO@USD",
ExchangeRate: math.LegacyZeroDec(),
},
{
Pair: "BAR:USD",
Pair: "BAR@USD",
ExchangeRate: math.LegacyMustNewDecFromStr("1232.132"),
},
}
Expand Down
Loading
Loading