Skip to content

Commit

Permalink
Update oracle types
Browse files Browse the repository at this point in the history
  • Loading branch information
venkatesh authored and venkatesh committed Sep 5, 2021
1 parent 693bc30 commit 991f010
Show file tree
Hide file tree
Showing 10 changed files with 1,444 additions and 391 deletions.
33 changes: 33 additions & 0 deletions chain/oracle/types/band_ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package types

import (
bandprice "github.com/InjectiveLabs/sdk-go/bandchain/hooks/price"
bandobi "github.com/bandprotocol/bandchain-packet/obi"
bandPacket "github.com/bandprotocol/bandchain-packet/packet"
)

func NewOracleRequestPacketData(clientID string, calldata []byte, r *BandOracleRequest) bandPacket.OracleRequestPacketData {
return bandPacket.OracleRequestPacketData{
ClientID: clientID,
OracleScriptID: uint64(r.OracleScriptId),
Calldata: calldata,
AskCount: r.AskCount,
MinCount: r.MinCount,
FeeLimit: r.FeeLimit,
PrepareGas: r.PrepareGas,
ExecuteGas: r.ExecuteGas,
}
}

// GetCalldata gets the Band IBC request call data based on the symbols and multiplier.
func (r *BandOracleRequest) GetCalldata() []byte {

requestCallData := bandprice.Input{
Symbols: r.Symbols,
Multiplier: BandPriceMultiplier,
}

callData := bandobi.MustEncode(requestCallData)

return callData
}
2 changes: 2 additions & 0 deletions chain/oracle/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&GrantPriceFeederPrivilegeProposal{}, "oracle/GrantPriceFeederPrivilegeProposal", nil)
cdc.RegisterConcrete(&RevokePriceFeederPrivilegeProposal{}, "oracle/RevokePriceFeederPrivilegeProposal", nil)
cdc.RegisterConcrete(&AuthorizeBandOracleRequestProposal{}, "oracle/AuthorizeBandOracleRequestProposal", nil)
cdc.RegisterConcrete(&UpdateBandOracleRequestProposal{}, "oracle/UpdateBandOracleRequestProposal", nil)
cdc.RegisterConcrete(&EnableBandIBCProposal{}, "oracle/EnableBandIBCProposal", nil)

}
Expand All @@ -41,6 +42,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&GrantPriceFeederPrivilegeProposal{},
&RevokePriceFeederPrivilegeProposal{},
&AuthorizeBandOracleRequestProposal{},
&UpdateBandOracleRequestProposal{},
&EnableBandIBCProposal{},
)

Expand Down
2 changes: 2 additions & 0 deletions chain/oracle/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ var (
ErrInvalidPortID = sdkerrors.Register(ModuleName, 21, "invalid IBC Port ID")
ErrInvalidChannelID = sdkerrors.Register(ModuleName, 22, "invalid IBC Channel ID")
ErrBadRequestInterval = sdkerrors.Register(ModuleName, 23, "invalid Band IBC request interval")
ErrInvalidBandIBCUpdateRequest = sdkerrors.Register(ModuleName, 24, "Invalid Band IBC Update Request Proposal")
ErrBandIBCRequestNotFound = sdkerrors.Register(ModuleName, 25, "Band IBC Oracle Request not found")
)
174 changes: 109 additions & 65 deletions chain/oracle/types/genesis.pb.go

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

15 changes: 10 additions & 5 deletions chain/oracle/types/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ var (
CoinbasePriceKey = []byte{0x21}

// Band IBC
BandIBCPriceKey = []byte{0x31}
LatestClientIDKey = []byte{0x32}
BandIBCCallDataRecordKey = []byte{0x33}
BandIBCOracleRequestKey = []byte{0x34}
BandIBCParamsKey = []byte{0x35}
BandIBCPriceKey = []byte{0x31}
LatestClientIDKey = []byte{0x32}
BandIBCCallDataRecordKey = []byte{0x33}
BandIBCOracleRequestIDKey = []byte{0x34}
BandIBCParamsKey = []byte{0x35}
LatestRequestIDKey = []byte{0x36}
)

func GetBandPriceStoreKey(symbol string) []byte {
Expand All @@ -48,6 +49,10 @@ func GetBandRelayerStoreKey(relayer sdk.AccAddress) []byte {
return append(BandRelayerKey, relayer.Bytes()...)
}

func GetBandIBCOracleRequestIDKey(requestID uint64) []byte {
return append(BandIBCOracleRequestIDKey, sdk.Uint64ToBigEndian(requestID)...)
}

func GetBandIBCPriceStoreKey(symbol string) []byte {
return append(BandIBCPriceKey, []byte(symbol)...)
}
Expand Down
8 changes: 7 additions & 1 deletion chain/oracle/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ func (msg MsgRelayCoinbaseMessages) GetSigners() []sdk.AccAddress {
// NewMsgRequestBandIBCRates creates a new MsgRequestBandIBCRates instance.
func NewMsgRequestBandIBCRates(
sender sdk.AccAddress,
requestID uint64,
) *MsgRequestBandIBCRates {
return &MsgRequestBandIBCRates{
Sender: sender.String(),
Sender: sender.String(),
RequestId: requestID,
}
}

Expand All @@ -166,6 +168,10 @@ func (msg MsgRequestBandIBCRates) ValidateBasic() error {
if sender.Empty() {
return sdkerrors.Wrapf(ErrInvalidBandIBCRequest, "MsgRequestBandIBCRates: Sender address must not be empty.")
}

if msg.RequestId == 0 {
return sdkerrors.Wrapf(ErrInvalidBandIBCRequest, "MsgRequestBandIBCRates: requestID should be greater than zero")
}
return nil
}

Expand Down
Loading

0 comments on commit 991f010

Please sign in to comment.