Skip to content

Commit

Permalink
Merge pull request #119 from P-U-D-G-E/mod/sr_ob_merge
Browse files Browse the repository at this point in the history
Renames Orderbook module to Strategic Reserve
  • Loading branch information
3eyedraga committed Mar 21, 2023
2 parents 5f969f8 + c3b1d62 commit 28a1cd4
Show file tree
Hide file tree
Showing 149 changed files with 8,433 additions and 13,524 deletions.
46 changes: 13 additions & 33 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ import (
marketmodulekeeper "github.com/sge-network/sge/x/market/keeper"
marketmoduletypes "github.com/sge-network/sge/x/market/types"

strategicreservemodule "github.com/sge-network/sge/x/strategicreserve"
strategicreservemodulekeeper "github.com/sge-network/sge/x/strategicreserve/keeper"
strategicreservemoduletypes "github.com/sge-network/sge/x/strategicreserve/types"

dvmmodule "github.com/sge-network/sge/x/dvm"
dvmmodulekeeper "github.com/sge-network/sge/x/dvm/keeper"
dvmmoduletypes "github.com/sge-network/sge/x/dvm/types"
Expand All @@ -71,9 +67,9 @@ import (
housemodulekeeper "github.com/sge-network/sge/x/house/keeper"
housemoduletypes "github.com/sge-network/sge/x/house/types"

orderbookmodule "github.com/sge-network/sge/x/orderbook"
orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper"
orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types"
strategicreservemodule "github.com/sge-network/sge/x/strategicreserve"
strategicreservemodulekeeper "github.com/sge-network/sge/x/strategicreserve/keeper"
strategicreservemoduletypes "github.com/sge-network/sge/x/strategicreserve/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
Expand Down Expand Up @@ -105,16 +101,14 @@ type AppKeepers struct {
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper

StrategicReserveKeeper strategicreservemodulekeeper.Keeper
MarketKeeper marketmodulekeeper.Keeper
BetKeeper betmodulekeeper.Keeper
DVMKeeper dvmmodulekeeper.Keeper
OrderBookKeeper orderbookmodulekeeper.Keeper
StrategicReserveKeeper strategicreservemodulekeeper.Keeper
HouseKeeper housemodulekeeper.Keeper
MarketModule marketmodule.AppModule
StrategicReserveModule strategicreservemodule.AppModule
BetModule betmodule.AppModule
OrderBookModule orderbookmodule.AppModule
StrategicReserveModule strategicreservemodule.AppModule
HouseModule housemodule.AppModule

// modules
Expand Down Expand Up @@ -212,13 +206,13 @@ func NewAppKeeper(
appKeepers.StrategicReserveKeeper = *strategicreservemodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[strategicreservemoduletypes.StoreKey],
appKeepers.keys[strategicreservemoduletypes.MemStoreKey],
appKeepers.GetSubspace(strategicreservemoduletypes.ModuleName),
strategicreservemodulekeeper.ExpectedKeepers{
strategicreservemodulekeeper.SdkExpectedKeepers{
BankKeeper: appKeepers.BankKeeper,
AccountKeeper: appKeepers.AccountKeeper,
},
)
appKeepers.StrategicReserveModule = strategicreservemodule.NewAppModule(appCodec, appKeepers.StrategicReserveKeeper)

appKeepers.MintKeeper = *mintkeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -346,47 +340,34 @@ func NewAppKeeper(
)
appKeepers.DVMModule = dvmmodule.NewAppModule(appCodec, appKeepers.DVMKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper)

appKeepers.OrderBookKeeper = *orderbookmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[orderbookmoduletypes.StoreKey],
appKeepers.GetSubspace(orderbookmoduletypes.ModuleName),
orderbookmodulekeeper.SdkExpectedKeepers{
BankKeeper: appKeepers.BankKeeper,
AccountKeeper: appKeepers.AccountKeeper,
},
)
appKeepers.OrderBookModule = orderbookmodule.NewAppModule(appCodec, appKeepers.OrderBookKeeper)

appKeepers.MarketKeeper = *marketmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[marketmoduletypes.StoreKey],
appKeepers.keys[marketmoduletypes.MemStoreKey],
appKeepers.GetSubspace(marketmoduletypes.ModuleName),
)
appKeepers.MarketKeeper.SetDVMKeeper(appKeepers.DVMKeeper)
appKeepers.MarketKeeper.SetOrderBookKeeper(appKeepers.OrderBookKeeper)
appKeepers.MarketKeeper.SetSRKeeper(appKeepers.StrategicReserveKeeper)
appKeepers.MarketModule = marketmodule.NewAppModule(appCodec, appKeepers.MarketKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.DVMKeeper)

appKeepers.StrategicReserveModule = strategicreservemodule.NewAppModule(appCodec, appKeepers.StrategicReserveKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper)

appKeepers.BetKeeper = *betmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[betmoduletypes.StoreKey],
appKeepers.keys[betmoduletypes.MemStoreKey],
appKeepers.GetSubspace(betmoduletypes.ModuleName),
)
appKeepers.BetKeeper.SetMarketKeeper(appKeepers.MarketKeeper)
appKeepers.BetKeeper.SetOrderBookKeeper(appKeepers.OrderBookKeeper)
appKeepers.BetKeeper.SetSRKeeper(appKeepers.StrategicReserveKeeper)
appKeepers.BetKeeper.SetDVMKeeper(appKeepers.DVMKeeper)
appKeepers.BetModule = betmodule.NewAppModule(appCodec, appKeepers.BetKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.MarketKeeper, appKeepers.OrderBookKeeper, appKeepers.DVMKeeper)
appKeepers.BetModule = betmodule.NewAppModule(appCodec, appKeepers.BetKeeper, appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.MarketKeeper, appKeepers.StrategicReserveKeeper, appKeepers.DVMKeeper)

appKeepers.OrderBookKeeper.SetBetKeeper(appKeepers.BetKeeper)
appKeepers.OrderBookKeeper.SetMarketKeeper(appKeepers.MarketKeeper)
appKeepers.StrategicReserveKeeper.SetBetKeeper(appKeepers.BetKeeper)
appKeepers.StrategicReserveKeeper.SetMarketKeeper(appKeepers.MarketKeeper)

appKeepers.HouseKeeper = *housemodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[housemoduletypes.StoreKey],
appKeepers.OrderBookKeeper,
appKeepers.StrategicReserveKeeper,
appKeepers.GetSubspace(housemoduletypes.ModuleName),
)
appKeepers.HouseModule = housemodule.NewAppModule(appCodec, appKeepers.HouseKeeper)
Expand Down Expand Up @@ -431,7 +412,6 @@ func initParamsKeeper(appCodec codec.BinaryCodec,
paramsKeeper.Subspace(marketmoduletypes.ModuleName)
paramsKeeper.Subspace(strategicreservemoduletypes.ModuleName)
paramsKeeper.Subspace(dvmmoduletypes.ModuleName)
paramsKeeper.Subspace(orderbookmoduletypes.ModuleName)
paramsKeeper.Subspace(housemoduletypes.ModuleName)

return paramsKeeper
Expand Down
2 changes: 0 additions & 2 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
housemoduletypes "github.com/sge-network/sge/x/house/types"
marketmoduletypes "github.com/sge-network/sge/x/market/types"
minttypes "github.com/sge-network/sge/x/mint/types"
orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types"
strategicreservemoduletypes "github.com/sge-network/sge/x/strategicreserve/types"

// unnamed import of statik for swagger UI support
Expand All @@ -47,7 +46,6 @@ func (appKeepers *AppKeepers) GenerateKeys() {
betmoduletypes.StoreKey,
marketmoduletypes.StoreKey,
dvmmoduletypes.StoreKey,
orderbookmoduletypes.StoreKey,
housemoduletypes.StoreKey,
)

Expand Down
37 changes: 14 additions & 23 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,26 @@ import (
housemodule "github.com/sge-network/sge/x/house"
housemoduletypes "github.com/sge-network/sge/x/house/types"

orderbookmodule "github.com/sge-network/sge/x/orderbook"
orderbookmoduletypes "github.com/sge-network/sge/x/orderbook/types"

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
)

// module account permissions
var mAccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
strategicreservemoduletypes.SRPoolName: nil,
strategicreservemoduletypes.BetReserveName: nil,
betmoduletypes.ModuleName: nil,
orderbookmoduletypes.SRProfitName: nil,
orderbookmoduletypes.BookLiquidityName: nil,
housemoduletypes.HouseParticipationFeeName: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
strategicreservemoduletypes.SRPoolName: nil,
strategicreservemoduletypes.BetReserveName: nil,
strategicreservemoduletypes.SRProfitName: nil,
strategicreservemoduletypes.BookLiquidityName: nil,
betmoduletypes.ModuleName: nil,
housemoduletypes.HouseParticipationFeeName: nil,
}

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
Expand Down Expand Up @@ -111,7 +108,6 @@ var ModuleBasics = module.NewBasicManager(
strategicreservemodule.AppModuleBasic{},
dvmmodule.AppModuleBasic{},
housemodule.AppModuleBasic{},
orderbookmodule.AppModuleBasic{},
)

func appModules(
Expand Down Expand Up @@ -152,7 +148,6 @@ func appModules(
app.StrategicReserveModule,
app.DVMModule,
app.HouseModule,
app.OrderBookModule,
// this line is u
}
}
Expand Down Expand Up @@ -184,7 +179,6 @@ func simulationModules(

app.BetModule,
app.MarketModule,
app.StrategicReserveModule,
app.DVMModule,
}
}
Expand Down Expand Up @@ -218,7 +212,6 @@ func orderBeginBlockers() []string {
strategicreservemoduletypes.ModuleName,
dvmmoduletypes.ModuleName,
housemoduletypes.ModuleName,
orderbookmoduletypes.ModuleName,
}
}

Expand Down Expand Up @@ -248,7 +241,6 @@ func orderEndBlockers() []string {
strategicreservemoduletypes.ModuleName,
dvmmoduletypes.ModuleName,
housemoduletypes.ModuleName,
orderbookmoduletypes.ModuleName,
}
}

Expand Down Expand Up @@ -278,6 +270,5 @@ func orderInitBlockers() []string {
strategicreservemoduletypes.ModuleName,
dvmmoduletypes.ModuleName,
housemoduletypes.ModuleName,
orderbookmoduletypes.ModuleName,
}
}
3 changes: 0 additions & 3 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ genesis:
{ inflation: "0.100000000000000000", year_coefficient: "1" },
]
exclude_amount: "500000000000"
strategicreserve:
params:
committee_members: []
market:
params:
min_bet_amount: "1000000"
Expand Down
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* [DVM](specs/DVM/01_Overview.md)
* [Mint](specs/Mint/01_Overview.md)
* [Market](specs/Market/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
2 changes: 1 addition & 1 deletion docs/specs/Bet/01_Overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# **Overview**

The Bet module is responsible for receiving and processing requests to place and settle bets. In the case of placement, it validates the request and places the bet, and in the case of settlement, it checks the result of the market, determines the bet result, and settles the bet using `OrderBook` module.
The Bet module is responsible for receiving and processing requests to place and settle bets. In the case of placement, it validates the request and places the bet, and in the case of settlement, it checks the result of the market, determines the bet result, and settles the bet using `StrategicReserve` module.
6 changes: 3 additions & 3 deletions docs/specs/Bet/02_Concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Before accepting bet some validation should take place:
After a bet is accepted:

- Corresponding betting fee will be deducted from total bet amount
- Betting fee will be transferred to the module account of bet module. this is done by the order book module.
- The rest of bet amount will be transferred and locked in Order Book module
- Betting fee will be transferred to the module account of bet module. this is done by the strategic reserve module.
- The rest of bet amount will be transferred and locked in Strategic Reserve module

For bet placement user can raise a request to place a single bet. Also, the same for bet settlement, it can be done for a single bet only.

When a user is raising a transaction to place a bet, the creator of the transaction is the owner of the bet. But in the case of bet settlement transaction, creator of the transaction can be different from owner of the bet, means that anyone can raise a settlement request for any bet.

> Bet settlement is not going to be done automatically in Blockchain, a transaction needs to be done to settle bets, by the owner or by anyone else on the behalf of user. In this TX payout is done and fund is transferred from Order Book to bettor's account.
> Bet settlement is not going to be done automatically in Blockchain, a transaction needs to be done to settle bets, by the owner or by anyone else on the behalf of user. In this TX payout is done and fund is transferred from Strategic Reserve to bettor's account.
## Supported Odds Types

Expand Down
8 changes: 4 additions & 4 deletions docs/specs/Bet/05_State_Transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section defines the state transitions of the bet module's KVStore in all sc
When this is processed:

- If the ticket is valid a new bet will be created with the given data and will be added to the `bet module's KVStore`.
- Order Book module bet placement processor will calculate and transfer bet amount to the corresponding module account.
- Strategic Reserve module bet placement processor will calculate and transfer bet amount to the corresponding module account.

```go
newBet := &types.Bet{
Expand All @@ -25,7 +25,7 @@ newBet := &types.Bet{
Verified: true,
CreatedAt: <current timestamp of block time>,
MaxLossMultiplier: <the coefficient of multiplicitation of the maximum loss>,
BetFulfillment: <bet fulfilment by the order book>
BetFulfillment: <bet fulfilment by the strategic reserve>
}
```

Expand All @@ -49,7 +49,7 @@ When this is processed:
bet.Status = types.Bet_STATUS_RESULT_DECLARED
```

- Call `Order Book module` to unlock fund and payout user based on the bet's result, and update the bet's `Status` field to indicate it is settled:
- Call `Strategic Reserve module` to unlock fund and payout user based on the bet's result, and update the bet's `Status` field to indicate it is settled:

```go
bet.Status = types.Bet_STATUS_SETTLED
Expand All @@ -67,5 +67,5 @@ Batch bet settlement happens in the end-blocker of the bet module:
- for each market:
1. Settle the bets one by by querying the market bets.
2. Remove the resolved market from the list if there is no more active bet.
3. Call order book method to set the order book as settled
3. Call strategic reserve's method to set the order book as settled
2. Check the `BatchSettlementCount` parameter of bet module and let the rest of bets for the nex block.
4 changes: 2 additions & 2 deletions docs/specs/Bet/06_Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ The transaction will fail if:
- Bet amount is less than minimum allowed amount
- The creator address is not valid
- There is an error in AddPayoutProfitToMarket in market module
- There is an error in ProcessBetPlacement in Order Book module
- There is an error in ProcessBetPlacement in Strategic Reserve module

### **What Happens if bet fails**

Expand Down Expand Up @@ -164,7 +164,7 @@ The transaction will fail if:
```

- Resolve the bet result based on the market result, and update field `Result` to indicate won or lost, and field `Status` to indicate result is declared.
- Call `Order Book module` to unlock fund and payout user based on the bet's result, and update the bet's `Status` field to indicate it is settled.
- Call `Strategic Reserve module` to unlock fund and payout user based on the bet's result, and update the bet's `Status` field to indicate it is settled.
- Store the updated bet in the module state.

---
3 changes: 1 addition & 2 deletions docs/specs/Bet/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
* [DVM](specs/DVM/01_Overview.md)
* [Mint](specs/Mint/01_Overview.md)
* [Market](specs/Market/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Order Book](specs/OrderBook/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
3 changes: 1 addition & 2 deletions docs/specs/DVM/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
* [Events](specs/DVM/05_Events.md)
* [Mint](specs/Mint/01_Overview.md)
* [Market](specs/Market/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Order Book](specs/OrderBook/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
2 changes: 1 addition & 1 deletion docs/specs/House/04_State_transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ When this is processed:
bet.TotalWithdrawalAmount = bet.TotalWithdrawalAmount + Withdrawal Amount
```

- the order book participation will create in the backgroud and its index will be assigned to the deposit
- the order book participation will create in the background and its index will be assigned to the deposit
3 changes: 1 addition & 2 deletions docs/specs/House/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
* [DVM](specs/DVM/01_Overview.md)
* [Mint](specs/Mint/01_Overview.md)
* [Market](specs/Market/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Overview](specs/House/01_Overview.md)
* [Concepts](specs/House/02_Concepts.md)
* [State](specs/House/03_State.md)
* [State Transitions](specs/House/04_State_Transitions.md)
* [Messages](specs/House/05_Messages.md)
* [Events](specs/House/06_Events.md)
* [Order Book](specs/OrderBook/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
3 changes: 1 addition & 2 deletions docs/specs/Market/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
* [Messages](specs/Market/03_Messages.md)
* [Events](specs/Market/04_Events.md)
* [State Transitions](specs/Market/05_State_Transitions.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Order Book](specs/OrderBook/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
3 changes: 1 addition & 2 deletions docs/specs/Mint/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
* [Events](specs/Mint/05_Events.md)
* [Parameters](specs/Mint/06_Parameters.md)
* [Market](specs/Market/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
* [House](specs/House/01_Overview.md)
* [Order Book](specs/OrderBook/01_Overview.md)
* [Strategic Reserve](specs/StrategicReserve/01_Overview.md)
3 changes: 0 additions & 3 deletions docs/specs/OrderBook/01_Overview.md

This file was deleted.

23 changes: 0 additions & 23 deletions docs/specs/OrderBook/02_Concepts.md

This file was deleted.

Loading

0 comments on commit 28a1cd4

Please sign in to comment.