Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check mock oracle #135

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
bed5179
mock
DongLieu Nov 5, 2024
17c4a61
add jpy
DongLieu Nov 5, 2024
d09629f
Merge branch 'vault/allow-multiple-currency' into dong/mock-multi
DongLieu Nov 5, 2024
0a037d7
Merge branch 'vault/allow-multiple-currency' into dong/mock-multi
DongLieu Nov 6, 2024
38e07bc
time blocktime
DongLieu Nov 6, 2024
3e07830
ok
DongLieu Nov 6, 2024
b184aed
merge vault/allow-multiple-currency
DongLieu Nov 7, 2024
de44ece
merge vault/allow-multiple-currency
DongLieu Nov 8, 2024
27965fc
Merge branch 'vault/allow-multiple-currency' into dong/mock-multi
DongLieu Nov 11, 2024
f435b90
Merge branch 'main' into dong/mock-multi
DongLieu Nov 11, 2024
2e9fe50
Merge branch 'main' into HEAD
DongLieu Nov 29, 2024
70627ef
add symbol
DongLieu Nov 29, 2024
3fdae3a
Merge branch 'dong/FeePSMtoReseve' into dong/localtestnet
DongLieu Dec 7, 2024
f237fef
updates
DongLieu Dec 7, 2024
b51a488
merge main
DongLieu Dec 18, 2024
f195c88
resolve conflicts
DongLieu Dec 18, 2024
971a2f7
Merge branch 'dong/auction-querry-bids' into dong/localtestnet
DongLieu Dec 19, 2024
4fd8b23
Merge branch 'main' into dong/localtestnet
DongLieu Dec 19, 2024
85e3009
Merge branch 'dong/auction-querry-bids-by-addr' into dong/localtestnet
DongLieu Dec 19, 2024
f2f2d25
Merge branch 'dong/auction-querry-bids-by-addr' into dong/localtestnet
DongLieu Dec 19, 2024
274567c
Merge branch 'main' into dong/localtestnet
DongLieu Dec 19, 2024
6d8e165
Merge branch 'dong/querytotalvaultbydenom' into dong/localtestnet
DongLieu Dec 24, 2024
94c67ee
resolve conflicts
DongLieu Dec 24, 2024
72c38ba
Merge branch 'dong/cli-param-oracle' into dong/localtestnet
DongLieu Dec 26, 2024
0075382
Merge branch 'main' into dong/localtestnet
DongLieu Dec 26, 2024
f7e6d0d
Merge branch 'main' into dong/localtestnet
DongLieu Dec 26, 2024
19156ae
ok
DongLieu Dec 26, 2024
649573d
merge main
DongLieu Dec 26, 2024
67edb0c
updates
DongLieu Dec 30, 2024
909738a
merge main
DongLieu Jan 2, 2025
cf90962
ok
DongLieu Jan 2, 2025
772d199
Merge branch 'dong/rate' into dong/localtestnet
DongLieu Jan 2, 2025
018f4d5
resolve conflicts
DongLieu Jan 14, 2025
f00c766
update
DongLieu Jan 14, 2025
c2f63cf
Merge branch 'main' into dong/localtestnet
DongLieu Jan 16, 2025
9f14aa5
Merge branch 'main' into dong/localtestnet
DongLieu Jan 22, 2025
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
20 changes: 19 additions & 1 deletion proto/reserve/oracle/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ service Msg {

rpc UpdateBandParams(MsgUpdateBandParams) returns (MsgUpdateBandParamsResponse);

rpc SetPrice(MsgSetPrice) returns (MsgSetPriceResponse);

rpc UpdateBandOracleRequest(MsgUpdateBandOracleRequestRequest) returns (MsgUpdateBandOracleRequestResponse);

rpc DeleteBandOracleRequests(MsgDeleteBandOracleRequests) returns (MsgDeleteBandOracleRequestsResponse);
Expand Down Expand Up @@ -121,4 +123,20 @@ message MsgUpdateBandOracleRequestParamsRequest {
}

// MsgUpdateBandOracleRequestParamsResponse define the Msg/UpdateBandOracleRequestParams response type.
message MsgUpdateBandOracleRequestParamsResponse {}
message MsgUpdateBandOracleRequestParamsResponse {}

message MsgSetPrice{
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "reserve/x/oracle/MsgSetPrice";
string denom = 1;

bytes price = 2 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

string authority = 3;
}

message MsgSetPriceResponse {}
6 changes: 4 additions & 2 deletions script/proposal-psm.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"limit_total": "100000000000000000000000000000",
"fee_in": "0.001000000000000000",
"fee_out": "0.001000000000000000",
"oracle_script": "44"
"oracle_script": "44",
"symbol": "USD"
},
{
"@type": "/reserve.psm.v1.MsgAddStableCoin",
Expand All @@ -15,7 +16,8 @@
"limit_total": "100000000000000000000000000000",
"fee_in": "0.001000000000000000",
"fee_out": "0.001000000000000000",
"oracle_script": "44"
"oracle_script": "44",
"symbol": "USD"
}],
"deposit": "100000000stake",
"title": "My proposal",
Expand Down
31 changes: 31 additions & 0 deletions x/oracle/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strconv"

"cosmossdk.io/math"
errors "github.com/pkg/errors"
"github.com/spf13/cobra"

Expand All @@ -29,6 +30,7 @@ func GetTxCmd() *cobra.Command {

cmd.AddCommand(
NewRequestBandRatesTxCmd(),
NewSetPriceCmd(),
)

return cmd
Expand Down Expand Up @@ -73,3 +75,32 @@ func NewRequestBandRatesTxCmd() *cobra.Command {

return cmd
}

func NewSetPriceCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set-price [denom] [price]",
Args: cobra.ExactArgs(2),
Short: "set price for denom ",
Long: `set price for denomn.

Example:
$ onomyd tx mockoracel set-price usdt 1
`,

RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
price := math.LegacyMustNewDecFromStr(args[1])
addr := clientCtx.GetFromAddress()
msg := types.NewSetPrice(args[0], addr.String(), price)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
164 changes: 164 additions & 0 deletions x/oracle/keeper/band_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,3 +621,167 @@

return allPair
}

func (k Keeper) SetInitPrice(ctx context.Context) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
initPrice := []*types.BandPriceState{
// multiplier = 1000
{
Symbol: "fxUSD",
Rate: math.NewInt(10000), //1
ResolveTime: sdkCtx.BlockTime().Unix(),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "USD",
Rate: math.NewInt(10000), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "EUR",
Rate: math.NewInt(10910), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "JPY",
Rate: math.NewInt(66), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "fxEUR",
Rate: math.NewInt(10910), //1.091
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1.091"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "fxJPY",
Rate: math.NewInt(66), //0.0066
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.0066"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "anom",
Rate: math.NewInt(330), //0.03
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.03"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "NOM",
Rate: math.NewInt(330), //0.03
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.03"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "usdt",
Rate: math.NewInt(10000), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "USDT",
Rate: math.NewInt(10000), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "usdc",
Rate: math.NewInt(10000), //1
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "eurt",
Rate: math.NewInt(10910), //1.091
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1.091"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "jpyt",
Rate: math.NewInt(66), //0.0066
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.0066"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "uatom",
Rate: math.NewInt(80000), //8
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("8"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ATOM",
Rate: math.NewInt(80000), //8
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("8"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "uosmo",
Rate: math.NewInt(4500), //0.45
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.45"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "uusdt",
Rate: math.NewInt(10000), //0.45
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "atom",
Rate: math.NewInt(80000), //0.45
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("8"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ibc/E50A183716AB596378047D9688FE648CD3470C4D196FB4C2C8E61989DB48562E", //transfer/channel-10/transfer/channel-7/transfer/channel-143/erc20/tether/usdt
Rate: math.NewInt(10000),
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ibc/BE4C72028781730B9DF0542466EB26DEA6DDD42C32316D774F943151F6010320", // transfer/channel-5/usdt
Rate: math.NewInt(10000),
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ibc/ED07A3391A112B175915CD8FAF43A2DA8E4790EDE12566649D0C2F97716B8518", //transfer/channel-0/uosmo
Rate: math.NewInt(4500), //0.45
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("0.45"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2", //ibc-atom
Rate: math.NewInt(80000), //0.45
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("8"), sdkCtx.BlockTime().Unix()),
},
{
Symbol: "ibc/BC599B88586F8C22E408569D7F6FAD40AEBF808A67D2051B86958CBB5F0A16B0", //usdt
Rate: math.NewInt(10000),
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(math.LegacyMustNewDecFromStr("1"), sdkCtx.BlockTime().Unix()),
},
}

for _, i := range initPrice {
err := k.SetBandPriceState(ctx, i.Symbol, i)
if err != nil {
return err
}
}
return nil
}

func (k Keeper) SetPrice(goCtx context.Context, msg *types.MsgSetPrice) (*types.MsgSetPriceResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(goCtx)
k.SetBandPriceState(goCtx, msg.Denom, &types.BandPriceState{

Check failure on line 780 in x/oracle/keeper/band_oracle.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.SetBandPriceState` is not checked (errcheck)
Symbol: msg.Denom,
Rate: math.NewInt(10000).ToLegacyDec().Mul(msg.Price).TruncateInt(),
ResolveTime: (sdkCtx.BlockTime().Unix()),
PriceState: *types.NewPriceState(msg.Price, sdkCtx.BlockTime().Unix()),
})
return &types.MsgSetPriceResponse{}, nil
}
1 change: 1 addition & 0 deletions x/oracle/module/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
sdkCtx.Logger().Info("can not set band price state for symbol %s", bandPriceState.Symbol)
}
}
k.SetInitPrice(ctx)

Check failure on line 26 in x/oracle/module/genesis.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `k.SetInitPrice` is not checked (errcheck)

for _, bandOracleRequest := range genState.BandOracleRequests {
err := k.SetBandOracleRequest(ctx, *bandOracleRequest)
Expand Down
9 changes: 9 additions & 0 deletions x/oracle/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
errorsmod "cosmossdk.io/errors"
math "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down Expand Up @@ -90,3 +91,11 @@ func (msg MsgRequestBandRates) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}

func NewSetPrice(denom, authority string, price math.LegacyDec) MsgSetPrice {
return MsgSetPrice{
Denom: denom,
Price: price,
Authority: authority,
}
}
Loading
Loading