Skip to content

Commit

Permalink
Merge pull request #833 from comdex-official/auctionsV2-refactor
Browse files Browse the repository at this point in the history
Auctions v2 refactor
  • Loading branch information
dheerajkd30 authored Aug 14, 2023
2 parents f5e76bf + dcafebd commit a7c948d
Show file tree
Hide file tree
Showing 22 changed files with 3,070 additions and 506 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ func (a *App) registerUpgradeHandlers() {
case upgradeInfo.Name == mv12.UpgradeName:
a.UpgradeKeeper.SetUpgradeHandler(
mv12.UpgradeName,
mv12.CreateUpgradeHandlerV12(a.mm, a.configurator, a.ICQKeeper, a.NewliqKeeper, a.NewaucKeeper, a.BankKeeper, a.CollectorKeeper, a.LendKeeper, a.AuctionKeeper, a.LiquidationKeeper),
mv12.CreateUpgradeHandlerV12(a.mm, a.configurator, a.ICQKeeper, a.NewliqKeeper, a.NewaucKeeper, a.BankKeeper, a.CollectorKeeper, a.LendKeeper, a.AuctionKeeper, a.LiquidationKeeper, a.AssetKeeper),
)
}

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/mainnet/v12/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v12

const (
UpgradeName = "v12.rc2"
UpgradeName = "v12.rc3"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
Expand Down
84 changes: 77 additions & 7 deletions app/upgrades/mainnet/v12/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package v12

import (
"fmt"
assetkeeper "github.com/comdex-official/comdex/x/asset/keeper"
assettypes "github.com/comdex-official/comdex/x/asset/types"
auctionkeeperold "github.com/comdex-official/comdex/x/auction/keeper"
auctiontypes "github.com/comdex-official/comdex/x/auction/types"
auctionkeeper "github.com/comdex-official/comdex/x/auctionsV2/keeper"
Expand Down Expand Up @@ -37,6 +39,7 @@ func CreateUpgradeHandlerV12(
lendKeeper lendkeeper.Keeper,
auctionKeeperOld auctionkeeperold.Keeper,
liquidationKeeperOld liquidationkeeperold.Keeper,
assetKeeper assetkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("Applying main net upgrade - v.12.0.0")
Expand All @@ -49,38 +52,105 @@ func CreateUpgradeHandlerV12(
if err != nil {
return nil, err
}
UpdateLendParams(ctx, lendKeeper, assetKeeper)
InitializeStates(ctx, liquidationKeeper, auctionKeeper)
Refund(ctx, bankKeeper, collectorKeeper)
RemoveFaultyAuctions(ctx, lendKeeper, auctionKeeperOld, liquidationKeeperOld, bankKeeper)
return vm, err
}
}

func dec(num string) sdk.Dec {
decVal, _ := sdk.NewDecFromStr(num)
return decVal
}

func UpdateLendParams(
ctx sdk.Context,
lendKeeper lendkeeper.Keeper,
assetKeeper assetkeeper.Keeper,
) {

cSTATOM := assettypes.Asset{
Name: "CSTATOM",
Denom: "ucstatom",
Decimals: sdk.NewInt(1000000),
IsOnChain: true,
IsOraclePriceRequired: false,
IsCdpMintable: true,
}
err := assetKeeper.AddAssetRecords(ctx, cSTATOM)
if err != nil {
fmt.Println(err)
}
assetID := assetKeeper.GetAssetID(ctx)

assetRatesParamsSTAtom := lendtypes.AssetRatesParams{
AssetID: 14,
UOptimal: dec("0.75"),
Base: dec("0.002"),
Slope1: dec("0.07"),
Slope2: dec("1.25"),
EnableStableBorrow: false,
Ltv: dec("0.7"),
LiquidationThreshold: dec("0.75"),
LiquidationPenalty: dec("0.05"),
LiquidationBonus: dec("0.05"),
ReserveFactor: dec("0.2"),
CAssetID: assetID,
IsIsolated: false,
}
lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsSTAtom)

assetRatesParamsCmdx, _ := lendKeeper.GetAssetRatesParams(ctx, 2)
assetRatesParamsCmdx.LiquidationPenalty = dec("0.075")
assetRatesParamsCmdx.LiquidationBonus = dec("0.075")
lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsCmdx)

assetRatesParamsCmst, _ := lendKeeper.GetAssetRatesParams(ctx, 3)
assetRatesParamsCmst.LiquidationPenalty = dec("0.05")
assetRatesParamsCmst.LiquidationBonus = dec("0.05")
lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsCmst)

cAXLUSDC := assettypes.Asset{
Name: "CAXLUSDC",
Denom: "ucaxlusdc",
Decimals: sdk.NewInt(1000000),
IsOnChain: true,
IsOraclePriceRequired: false,
IsCdpMintable: true,
}
err = assetKeeper.AddAssetRecords(ctx, cAXLUSDC)
if err != nil {
fmt.Println(err)
}
}

func InitializeStates(
ctx sdk.Context,
liquidationKeeper liquidationkeeper.Keeper,
auctionKeeper auctionkeeper.Keeper,
) {
dutchAuctionParams := liquidationtypes.DutchAuctionParam{
Premium: newDec("1.2"),
Premium: newDec("1.15"),
Discount: newDec("0.7"),
DecrementFactor: sdk.NewInt(1),
}
englishAuctionParams := liquidationtypes.EnglishAuctionParam{DecrementFactor: sdk.NewInt(1)}

harborParams := liquidationtypes.LiquidationWhiteListing{
AppId: 2,
Initiator: false,
Initiator: true,
IsDutchActivated: true,
DutchAuctionParam: &dutchAuctionParams,
IsEnglishActivated: false,
IsEnglishActivated: true,
EnglishAuctionParam: &englishAuctionParams,
KeeeperIncentive: sdk.ZeroDec(),
}

commodoParams := liquidationtypes.LiquidationWhiteListing{
AppId: 3,
Initiator: false,
Initiator: true,
IsDutchActivated: true,
DutchAuctionParam: &dutchAuctionParams,
IsEnglishActivated: false,
Expand Down Expand Up @@ -108,10 +178,10 @@ func InitializeStates(
auctionParams := auctionsV2types.AuctionParams{
AuctionDurationSeconds: 18000,
Step: newDec("0.1"),
WithdrawalFee: newDec("0.0"),
ClosingFee: newDec("0.0"),
WithdrawalFee: newDec("0.0005"),
ClosingFee: newDec("0.0005"),
MinUsdValueLeft: 100000,
BidFactor: newDec("0.1"),
BidFactor: newDec("0.01"),
LiquidationPenalty: newDec("0.1"),
AuctionBonus: newDec("0.0"),
}
Expand Down
48 changes: 45 additions & 3 deletions proto/comdex/auctionsV2/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ message QueryAuctionsResponse {

message QueryBidsRequest {
string bidder = 1;
bool history = 2;
cosmos.base.query.v1beta1.PageRequest pagination = 3
uint64 bid_type = 2;
bool history = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 4
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

Expand Down Expand Up @@ -154,6 +155,41 @@ message QueryLimitBidProtocolDataWithUserResponse {
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryBidsFilterRequest {
string bidder = 1;
uint64 bid_type = 2;
bool history = 3;
cosmos.base.query.v1beta1.PageRequest pagination = 4
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryBidsFilterResponse {
string bidder = 1 [
(gogoproto.moretags) = "yaml:\"bidder\""
];
repeated Bid bids = 2 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"bids\""
];
cosmos.base.query.v1beta1.PageResponse pagination = 3
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryAuctionsHistoryRequest {
uint64 auction_type = 1;
cosmos.base.query.v1beta1.PageRequest pagination = 2
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryAuctionsHistoryResponse {
repeated AuctionHistorical auctions = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"auctions\""
];
cosmos.base.query.v1beta1.PageResponse pagination = 2
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/comdex/auctions/v2/params";
Expand All @@ -165,7 +201,7 @@ service Query {
option (google.api.http).get = "/comdex/auctions/v2/auctions/{auction_type}/{history}";
}
rpc Bids(QueryBidsRequest) returns (QueryBidsResponse) {
option (google.api.http).get = "/comdex/auctions/v2/bids/{bidder}/{history}";
option (google.api.http).get = "/comdex/auctions/v2/bids/{bidder}/{bid_type}/{history}";
}
rpc AuctionParams(QueryAuctionParamsRequest) returns (QueryAuctionParamsResponse) {
option (google.api.http).get = "/comdex/auctions/v2/auction_params";
Expand All @@ -185,4 +221,10 @@ service Query {
rpc LimitBidProtocolDataWithUser(QueryLimitBidProtocolDataWithUserRequest) returns (QueryLimitBidProtocolDataWithUserResponse) {
option (google.api.http).get = "/comdex/auctions/v2/limit_bid_protocol_data_with_user/{bidder}";
}
rpc BidsFilter(QueryBidsFilterRequest) returns (QueryBidsFilterResponse) {
option (google.api.http).get = "/comdex/auctions/v2/bids_filter/{bidder}/{bid_type}/{history}";
}
rpc AuctionsHistory(QueryAuctionsHistoryRequest) returns (QueryAuctionsHistoryResponse) {
option (google.api.http).get = "/comdex/auctions/v2/auctions_history/{auction_type}";
}
}
19 changes: 19 additions & 0 deletions proto/comdex/lend/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ message QueryBorrowInterestResponse {
];
}

message QueryAllBorrowByOwnerAndDebtPoolRequest {
string owner = 1 [(gogoproto.moretags) = "yaml:\"owner\""];
uint64 pool_id = 2 [(gogoproto.moretags) = "yaml:\"pool_id\""];
cosmos.base.query.v1beta1.PageRequest pagination = 3
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

message QueryAllBorrowByOwnerAndDebtPoolResponse {
repeated BorrowAsset borrows = 1 [
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"borrows\""];
cosmos.base.query.v1beta1.PageResponse pagination = 2
[(gogoproto.moretags) = "yaml:\"pagination\""];
}

service Query {
rpc QueryLends(QueryLendsRequest) returns (QueryLendsResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/lends";
Expand Down Expand Up @@ -418,5 +433,9 @@ service Query {
rpc QueryBorrowInterest(QueryBorrowInterestRequest) returns (QueryBorrowInterestResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/borrow_interest";
};

rpc QueryAllBorrowByOwnerAndDebtPool(QueryAllBorrowByOwnerAndDebtPoolRequest) returns (QueryAllBorrowByOwnerAndDebtPoolResponse) {
option (google.api.http).get = "/comdex/lend/v1beta1/borrows_by_owner_debt_pool/{owner}/{pool_id}";
}
}

14 changes: 7 additions & 7 deletions proto/comdex/liquidationsV2/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ message QueryAppReserveFundsTxDataResponse {

service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/comdex-official/comdex/liquidationsV2/params";
option (google.api.http).get = "/comdex/liquidations/v2/params";
}
rpc QueryLockedVault(QueryLockedVaultRequest) returns (QueryLockedVaultResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/locked_vault/{app_id}/{id}";
option (google.api.http).get = "/comdex/liquidations/v2/locked_vault/{app_id}/{id}";
}
rpc QueryLockedVaults(QueryLockedVaultsRequest) returns (QueryLockedVaultsResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/locked_vaults";
option (google.api.http).get = "/comdex/liquidations/v2/locked_vaults";
}
rpc QueryLiquidationWhiteListing(QueryLiquidationWhiteListingRequest) returns (QueryLiquidationWhiteListingResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/liquidation_whiteListing/{app_id}";
option (google.api.http).get = "/comdex/liquidations/v2/liquidation_whiteListing/{app_id}";
}
rpc QueryLiquidationWhiteListings(QueryLiquidationWhiteListingsRequest) returns (QueryLiquidationWhiteListingsResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/liquidation_whiteListings";
option (google.api.http).get = "/comdex/liquidations/v2/liquidation_whiteListings";
}
rpc QueryLockedVaultsHistory(QueryLockedVaultsHistoryRequest) returns (QueryLockedVaultsHistoryResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/locked_vaults_history";
option (google.api.http).get = "/comdex/liquidations/v2/locked_vaults_history";
}
rpc QueryAppReserveFundsTxData(QueryAppReserveFundsTxDataRequest) returns (QueryAppReserveFundsTxDataResponse) {
option (google.api.http).get = "/comdex/liquidationsV2/v1beta1/app_reserve_funds_tx_data/{app_id}";
option (google.api.http).get = "/comdex/liquidations/v2/app_reserve_funds_tx_data/{app_id}";
}
}
Loading

0 comments on commit a7c948d

Please sign in to comment.