Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Jan 7, 2025
2 parents 5544cff + be2f41f commit e6e121c
Show file tree
Hide file tree
Showing 25 changed files with 602 additions and 215 deletions.
4 changes: 2 additions & 2 deletions proto/reserve/auction/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ message MsgBid {
cosmos.base.v1beta1.Coin amount = 3
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

// recive_price defines the price that the bid is willing to pay
string recive_price = 4 [ (cosmos_proto.scalar) = "cosmos.Dec" ];
// recive_rate defines the price that the bid is willing to pay
string recive_rate = 4 [ (cosmos_proto.scalar) = "cosmos.Dec" ];
}

// MsgBidResponse defines the response structure for executing a
Expand Down
5 changes: 5 additions & 0 deletions proto/reserve/psm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ message MsgAddStableCoin {
(gogoproto.nullable) = false
];
int64 oracle_script = 9;
uint64 stable_decimal = 10;
uint64 mint_decimal = 11;
}

message MsgAddStableCoinResponse {}
Expand Down Expand Up @@ -112,6 +114,9 @@ message MsgUpdatesStableCoin {
];

int64 oracle_script = 7;

uint64 stable_decimal = 8;
uint64 mint_decimal = 9;
}

message MsgUpdatesStableCoinResponse {}
Expand Down
5 changes: 5 additions & 0 deletions proto/reserve/vaults/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ message MsgActiveCollateral {
string mint_denom = 11;
string mint_symbol = 12;
int64 mint_oracle_script = 13;

uint64 collateral_decimals = 14;
uint64 mint_decimals = 15;
}

// MsgActiveCollateralResponse defines the Msg/ActiveCollateral response type.
Expand Down Expand Up @@ -184,6 +187,8 @@ message MsgUpdatesCollateral {
string symbol = 11;
string mint_denom = 12;
int64 mint_oracle_script = 13;
uint64 collateral_decimals = 14;
uint64 mint_decimals = 15;
}

// MsgActiveCollateralResponse defines the Msg/ActiveCollateral response type.
Expand Down
8 changes: 4 additions & 4 deletions x/auction/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func GetTxCmd() *cobra.Command {

func NewBidCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bid [auction-id] [amount] [recive-price]",
Use: "bid [auction-id] [amount] [recive_rate]",
Args: cobra.ExactArgs(3),
Short: "create vaults ",
Long: `create vaults.
Short: "create new bid",
Long: `create new bid.
Example:
$ onomyd tx bid 0 1000nomUSD 0.8 --from mykey
$ onomyd tx bid 0 1000nomUSD 0.95 --from mykey
`,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
5 changes: 4 additions & 1 deletion x/auction/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"cosmossdk.io/collections"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/onomyprotocol/reserve/x/auction/types"
)
Expand Down Expand Up @@ -72,11 +73,13 @@ func (k msgServer) Bid(ctx context.Context, msg *types.MsgBid) (*types.MsgBidRes
return nil, err
}

recivePrice := math.LegacyMustNewDecFromStr(auction.InitialPrice).Mul(math.LegacyMustNewDecFromStr(msg.ReciveRate))
// auction.InitialPrice.
bid := types.Bid{
BidId: newBidId,
Bidder: msg.Bidder,
Amount: msg.Amount,
RecivePrice: msg.RecivePrice,
RecivePrice: recivePrice.String(),
IsHandle: false,
}
err = k.AddBidEntry(ctx, msg.AuctionId, bidderAddr, bid)
Expand Down
10 changes: 5 additions & 5 deletions x/auction/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ var (
Msg_serviceDesc = _Msg_serviceDesc
)

func NewMsgBid(addr string, auctionID uint64, amount sdk.Coin, RecivePrice string) MsgBid {
func NewMsgBid(addr string, auctionID uint64, amount sdk.Coin, ReciveRate string) MsgBid {
return MsgBid{
Bidder: addr,
AuctionId: auctionID,
RecivePrice: RecivePrice,
Amount: amount,
Bidder: addr,
AuctionId: auctionID,
ReciveRate: ReciveRate,
Amount: amount,
}
}

Expand Down
96 changes: 48 additions & 48 deletions x/auction/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 28 additions & 2 deletions x/oracle/keeper/band_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,12 @@ func (k Keeper) GetPrice(ctx context.Context, base, quote string) (price math.Le
return price, fmt.Errorf("symbol base %s old price state", base)
}
if quote == types.QuoteUSD || quote == vaultstypes.DefaultMintDenoms[0] {
return basePriceState.PriceState.Price, nil
pairDecimalsRate, err := k.GetPairDecimalsRate(ctx, base, quote)
if err != nil {
return price, err
}

return basePriceState.PriceState.Price.Mul(pairDecimalsRate), nil
}

quotePriceState := k.GetBandPriceState(ctx, quote)
Expand All @@ -346,7 +351,12 @@ func (k Keeper) GetPrice(ctx context.Context, base, quote string) (price math.Le
return price, fmt.Errorf("get price error validate for baseRate %s(%s) or quoteRate %s(%s)", base, baseRate.String(), quote, quoteRate.String())
}

price = baseRate.Quo(quoteRate)
pairDecimalsRate, err := k.GetPairDecimalsRate(ctx, base, quote)
if err != nil {
return price, err
}

price = baseRate.Quo(quoteRate).Mul(pairDecimalsRate)
return price, nil
}

Expand Down Expand Up @@ -580,3 +590,19 @@ func (k *Keeper) getPreviousRecordIDs(ctx context.Context, clientID uint64) []ui

return staleIDs
}

func (k Keeper) SetPairDecimalsRate(ctx context.Context, base, quote string, baseDecimals, quoteDecimals uint64) error {
store := k.storeService.OpenKVStore(ctx)
rate := math.LegacyNewDec(10).Power(quoteDecimals).Quo(math.LegacyNewDec(10).Power(baseDecimals))
bz := []byte(rate.String())
return store.Set(types.GetPairDecimalsKey(base, quote), bz)
}

func (k Keeper) GetPairDecimalsRate(ctx context.Context, base, quote string) (math.LegacyDec, error) {
store := k.storeService.OpenKVStore(ctx)
bz, err := store.Get(types.GetPairDecimalsKey(base, quote))
if err != nil {
return math.LegacyZeroDec(), err
}
return math.LegacyMustNewDecFromStr(string(bz)), nil
}
Loading

0 comments on commit e6e121c

Please sign in to comment.