Skip to content

Commit 77c622f

Browse files
committed
chore: explain provider oracle
1 parent 00cd31c commit 77c622f

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Oracle",
3+
"position": 5,
4+
"link": {
5+
"type": "doc",
6+
"id":"index"
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Oracle
2+
3+
Prerequisite: [Injective Oracle Module](../../../develop/modules/injective/oracle/).
4+
5+
## Oracle Provider
6+
7+
The goal of this section is to provide users a guide on how to launch and maintain a oracle provider on Injective. These oracles can be used for various purposes, like Perpetual Markets, Expiry Futures Markets, [Binary Options markets](../../../develop/modules/injective/exchange/02_binary_options_markets.md), etc.
8+
9+
First, what is an oracle provider? It's an oracle **TYPE** which allows external parties to relay price feed to the Injective chain. These external parties are called providers. Each external party is identified by a provider and all of the price feeds provided on the chain are stored under that particular provider. This allows custom price feed to be created on Injective which can power creative and advanced markets being launched on Injective.
10+
11+
The first thing developers need to do is register their provider under the Oracle Provider type. You can do that by submitting a `GrantProviderPrivilegeProposal` governance proposal. Once the proposal passes, your provider will be registered and you'll be able to relay price feeds. You can do it in a CLI environment using `injectived` (`grant-provider-privilege-proposal [providerName] [relayers] --title [title] --description [desc] [flags]`) or using any of our SDKs to create the message and broadcast it to the chain.
12+
13+
Note: the `relayers` of the `GrantProviderPrivilegeProposal` are addresses which will be whitelisted to submit the price feeds to Injective.
14+
15+
Once the proposal passes, the `relayers` can use the `MsgRelayProviderPrices` to submit prices for a base/quote pair within their provider namespace of the Oracle Provider Type oracle on Injective. You can do it in a CLI environment using `injectived` (`relay-provider-prices [providerName] [symbol:prices] [flags]`) or using any of our SDKs to create the message and broadcast it to the chain.
16+
17+
Finally, you can use these price feeds to create your Derivative Markets.

docs/develop/modules/injective/exchange/02_binary_options_markets.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Alice buys 1 contract at $0.20 (margined with $0.20) against Bob who sells 1 con
1919

2020
- Alice wins $0.80 if the market settles at $1 and Bob wins $0.2 if the market settles at $0.
2121

22-
### Oracle
22+
## Oracle
2323

2424
Binary options markets are tightly coupled to the Provider Oracle type, which allows a governance-registered provider to relay price feed data for arbitrary new price feeds under the provider's subtype without the need for extra governance for adding successively new price feeds. Each binary options market is comprised of the following oracle parameters:
2525
* Oracle symbol (e.g. UFC-KHABIB-TKO-09082022)
@@ -35,7 +35,23 @@ Oracle can also post the final price of **-1**, which is the flag price than tri
3535

3636
Further documentation on the oracle provider type can be found in the Oracle module documentation.
3737

38+
### Registering an oracle provider
39+
40+
To register your oracle provider, you need to submit a `GrantProviderPrivilegeProposal` governance proposal. This proposal will register your provider and will allow your address to relay price feeds.
41+
42+
```go
43+
type GrantProviderPrivilegeProposal struct {
44+
Title string
45+
Description string
46+
Provider string // the name of the provider, should be specific to you
47+
Relayers []string // addresses which will be able to relay prices
48+
}
49+
```
50+
51+
Once the proposal passes, your provider will be registered and you'll be able to relay your price feeds (example below).
52+
3853
## Market Lifecycle
54+
3955
### Market Creation
4056
A binary options market can be created through an instant launch (through a `MsgInstantBinaryOptionsMarketLaunch`) or through governance (through a `BinaryOptionsMarketLaunchProposal`).
4157

@@ -50,3 +66,50 @@ Pertinently, binary options markets also have a characteristic `ExpirationTimest
5066
* **Expired** = trading is closed, open orders are cancelled, no change to positions.
5167
* **Demolished** = positions are settled / refunded (depending on the settlement), market is demolished
5268

69+
The nature of the status transitions for binary options markets are as follows:
70+
71+
| Status Change | Workflow |
72+
| --- | --- |
73+
| Active → Expired | Expiration is part of the standard workflow for a market. Trading is halted immediately for the market and all open orders are cancelled. The market can now be settled immediately (forcefully) by the admin or oracle or be settled naturally using the latest oracle price when we reach SettlementTimestamp.
74+
| Expired → Demolished (Settlement) | All positions are settled at either the price set by forceful settlement or natural settlement. The market can never be traded on or reactivated again. For natural settlement, upon the SettlementTimestamp time, the last oracle price is recorded and used for settlement. For ‘force-settle’, Admin should post the MarketUpdate msg with SettlementPrice in it being set in a price band of [0, 1].
75+
| Active/Expired → Demolished (Refund) | All positions get refunded. The market can never be traded on or reactivated again. Admin should post the MarketUpdate msg with SettlementPrice in it being set to -1. |
76+
77+
78+
### Market Settlement
79+
80+
The settlement price options are explained above in the [oracle](#oracle) section.
81+
82+
Settling a market can be achieved using one of these two options:
83+
1. Using the registered provider oracle for the particular market. Once the provider oracle is granted privileges to relay prices (explained above), the address with the privileges can relay prices for a particular price feed using the `MsgRelayProviderPrices` message.
84+
```go
85+
// MsgRelayProviderPrices defines a SDK message for setting a price through the provider oracle.
86+
type MsgRelayProviderPrices struct {
87+
Sender string
88+
Provider string
89+
Symbols []string
90+
Prices []cosmossdk_io_math.LegacyDec
91+
}
92+
```
93+
94+
2. Using the `MsgAdminUpdateBinaryOptionsMarket` which allows the market's admin (creator) to submit a settlement price directly to the market.
95+
```go
96+
type MsgAdminUpdateBinaryOptionsMarket struct {
97+
// new price at which market will be settled
98+
SettlementPrice *Dec
99+
// expiration timestamp
100+
ExpirationTimestamp int64
101+
// expiration timestamp
102+
SettlementTimestamp int64
103+
// Status of the market
104+
Status MarketStatus
105+
}
106+
107+
// Where Status can be one of these options
108+
enum MarketStatus {
109+
Unspecified = 0;
110+
Active = 1;
111+
Paused = 2;
112+
Demolished = 3;
113+
Expired = 4;
114+
}
115+
```

docs/develop/modules/injective/oracle/03_messages.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,27 @@ This message is expected to fail if:
164164
- the Relayer (`sender`) is not an authorized oracle publisher or if `assetId` is not unique amongst the provided asset pairs
165165
- ECDSA signature verification fails for the `SignedPriceOfAssetPair`
166166
- the difference between timestamps exceeds the `MaxStorkTimestampIntervalNano` (500 milliseconds).
167+
168+
## MsgRelayProviderPrices
169+
170+
Relayers of a particular Provider can send the price feed using `MsgRelayProviderPrices` message.
171+
172+
```protobuf
173+
// MsgRelayProviderPrice defines a SDK message for setting a price through the provider oracle.
174+
message MsgRelayProviderPrices {
175+
option (amino.name) = "oracle/MsgRelayProviderPrices";
176+
option (gogoproto.equal) = false;
177+
option (gogoproto.goproto_getters) = false;
178+
option (cosmos.msg.v1.signer) = "sender";
179+
180+
string sender = 1;
181+
string provider = 2;
182+
repeated string symbols = 3;
183+
repeated string prices = 4 [
184+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
185+
(gogoproto.nullable) = false
186+
];
187+
}
188+
```
189+
190+
This message is expected to fail if the Relayer (`Sender`) is not an authorized pricefeed relayer for the given Base Quote pair or if the price is greater than 10000000.

0 commit comments

Comments
 (0)