Skip to content

Commit

Permalink
Merge branch 'main' into tra70
Browse files Browse the repository at this point in the history
  • Loading branch information
shrenujb committed Mar 7, 2024
2 parents a78c68b + 5e0fd8b commit 7d63b0a
Show file tree
Hide file tree
Showing 55 changed files with 3,215 additions and 2,470 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ By clicking the above links to third-party clients, you will leave the dYdX Trad

`proto` — Contains all protocol buffers used by protocol and indexer.

`protocol` — Contains source code for the Cosmos SDK app that runs the protocol. See its [README](https://github.com/dydxprotocol/v4-chain/blob/main/indexer/README.md) for developer documentation.
`protocol` — Contains source code for the Cosmos SDK app that runs the protocol. See its [README](https://github.com/dydxprotocol/v4-chain/blob/main/protocol/README.md) for developer documentation.

`v4-proto-js` — Scripts for publishing proto package to [npm](https://www.npmjs.com/package/@dydxprotocol/v4-proto).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export interface Perpetual {
*/

fundingIndex: Uint8Array;
/** Total size of open long contracts, measured in base_quantums. */

openInterest: Uint8Array;
}
/** Perpetual represents a perpetual on the dYdX exchange. */

Expand All @@ -81,6 +84,9 @@ export interface PerpetualSDKType {
*/

funding_index: Uint8Array;
/** Total size of open long contracts, measured in base_quantums. */

open_interest: Uint8Array;
}
/**
* PerpetualParams represents the parameters of a perpetual on the dYdX
Expand Down Expand Up @@ -280,6 +286,19 @@ export interface LiquidityTier {
*/

impactNotional: Long;
/**
* Lower cap for Open Interest Margin Fracton (OIMF), in quote quantums.
* IMF is not affected when OI <= open_interest_lower_cap.
*/

openInterestLowerCap: Long;
/**
* Upper cap for Open Interest Margin Fracton (OIMF), in quote quantums.
* IMF scales linearly to 100% as OI approaches open_interest_upper_cap.
* If zero, then the IMF does not scale with OI.
*/

openInterestUpperCap: Long;
}
/** LiquidityTier stores margin information. */

Expand Down Expand Up @@ -323,12 +342,26 @@ export interface LiquidityTierSDKType {
*/

impact_notional: Long;
/**
* Lower cap for Open Interest Margin Fracton (OIMF), in quote quantums.
* IMF is not affected when OI <= open_interest_lower_cap.
*/

open_interest_lower_cap: Long;
/**
* Upper cap for Open Interest Margin Fracton (OIMF), in quote quantums.
* IMF scales linearly to 100% as OI approaches open_interest_upper_cap.
* If zero, then the IMF does not scale with OI.
*/

open_interest_upper_cap: Long;
}

function createBasePerpetual(): Perpetual {
return {
params: undefined,
fundingIndex: new Uint8Array()
fundingIndex: new Uint8Array(),
openInterest: new Uint8Array()
};
}

Expand All @@ -342,6 +375,10 @@ export const Perpetual = {
writer.uint32(18).bytes(message.fundingIndex);
}

if (message.openInterest.length !== 0) {
writer.uint32(26).bytes(message.openInterest);
}

return writer;
},

Expand All @@ -362,6 +399,10 @@ export const Perpetual = {
message.fundingIndex = reader.bytes();
break;

case 3:
message.openInterest = reader.bytes();
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -375,6 +416,7 @@ export const Perpetual = {
const message = createBasePerpetual();
message.params = object.params !== undefined && object.params !== null ? PerpetualParams.fromPartial(object.params) : undefined;
message.fundingIndex = object.fundingIndex ?? new Uint8Array();
message.openInterest = object.openInterest ?? new Uint8Array();
return message;
}

Expand Down Expand Up @@ -614,7 +656,9 @@ function createBaseLiquidityTier(): LiquidityTier {
initialMarginPpm: 0,
maintenanceFractionPpm: 0,
basePositionNotional: Long.UZERO,
impactNotional: Long.UZERO
impactNotional: Long.UZERO,
openInterestLowerCap: Long.UZERO,
openInterestUpperCap: Long.UZERO
};
}

Expand Down Expand Up @@ -644,6 +688,14 @@ export const LiquidityTier = {
writer.uint32(48).uint64(message.impactNotional);
}

if (!message.openInterestLowerCap.isZero()) {
writer.uint32(56).uint64(message.openInterestLowerCap);
}

if (!message.openInterestUpperCap.isZero()) {
writer.uint32(64).uint64(message.openInterestUpperCap);
}

return writer;
},

Expand Down Expand Up @@ -680,6 +732,14 @@ export const LiquidityTier = {
message.impactNotional = (reader.uint64() as Long);
break;

case 7:
message.openInterestLowerCap = (reader.uint64() as Long);
break;

case 8:
message.openInterestUpperCap = (reader.uint64() as Long);
break;

default:
reader.skipType(tag & 7);
break;
Expand All @@ -697,6 +757,8 @@ export const LiquidityTier = {
message.maintenanceFractionPpm = object.maintenanceFractionPpm ?? 0;
message.basePositionNotional = object.basePositionNotional !== undefined && object.basePositionNotional !== null ? Long.fromValue(object.basePositionNotional) : Long.UZERO;
message.impactNotional = object.impactNotional !== undefined && object.impactNotional !== null ? Long.fromValue(object.impactNotional) : Long.UZERO;
message.openInterestLowerCap = object.openInterestLowerCap !== undefined && object.openInterestLowerCap !== null ? Long.fromValue(object.openInterestLowerCap) : Long.UZERO;
message.openInterestUpperCap = object.openInterestUpperCap !== undefined && object.openInterestUpperCap !== null ? Long.fromValue(object.openInterestUpperCap) : Long.UZERO;
return message;
}

Expand Down
16 changes: 16 additions & 0 deletions proto/dydxprotocol/perpetuals/perpetual.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ message Perpetual {
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];

// Total size of open long contracts, measured in base_quantums.
bytes open_interest = 3 [
(gogoproto.customtype) =
"github.com/dydxprotocol/v4-chain/protocol/dtypes.SerializableInt",
(gogoproto.nullable) = false
];
}

enum PerpetualMarketType {
Expand Down Expand Up @@ -120,4 +127,13 @@ message LiquidityTier {
// - Impact ask price = average execution price for a market buy of the
// impact notional value.
uint64 impact_notional = 6;

// Lower cap for Open Interest Margin Fracton (OIMF), in quote quantums.
// IMF is not affected when OI <= open_interest_lower_cap.
uint64 open_interest_lower_cap = 7;

// Upper cap for Open Interest Margin Fracton (OIMF), in quote quantums.
// IMF scales linearly to 100% as OI approaches open_interest_upper_cap.
// If zero, then the IMF does not scale with OI.
uint64 open_interest_upper_cap = 8;
}
14 changes: 0 additions & 14 deletions protocol/app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import (
upgradetypes "cosmossdk.io/x/upgrade/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
v4_0_0 "github.com/dydxprotocol/v4-chain/protocol/app/upgrades/v4.0.0"
)

var (
// `Upgrades` defines the upgrade handlers and store loaders for the application.
// New upgrades should be added to this slice after they are implemented.
Upgrades = []upgrades.Upgrade{
v4_0_0.Upgrade,
v5_0_0.Upgrade,
}
Forks = []upgrades.Fork{}
Expand All @@ -24,18 +22,6 @@ var (
// setupUpgradeHandlers registers the upgrade handlers to perform custom upgrade
// logic and state migrations for software upgrades.
func (app *App) setupUpgradeHandlers() {
if app.UpgradeKeeper.HasHandler(v4_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v4_0_0.UpgradeName))
}
app.UpgradeKeeper.SetUpgradeHandler(
v4_0_0.UpgradeName,
v4_0_0.CreateUpgradeHandler(
app.ModuleManager,
app.configurator,
app.RatelimitKeeper,
),
)

if app.UpgradeKeeper.HasHandler(v5_0_0.UpgradeName) {
panic(fmt.Sprintf("Cannot register duplicate upgrade handler '%s'", v5_0_0.UpgradeName))
}
Expand Down
9 changes: 7 additions & 2 deletions protocol/app/upgrades/v5.0.0/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package v5_0_0
package v_5_0_0

import (
store "cosmossdk.io/store/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"

vaulttypes "github.com/dydxprotocol/v4-chain/protocol/x/vault/types"
)

const (
Expand All @@ -12,6 +14,9 @@ const (
var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},

Added: []string{
vaulttypes.StoreKey,
},
},
}
12 changes: 6 additions & 6 deletions protocol/app/upgrades/v5.0.0/upgrade.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v5_0_0
package v_5_0_0

import (
"context"
Expand All @@ -20,12 +20,10 @@ func perpetualsUpgrade(
) error {

// Set all perpetuals to cross market type
perpetuals, err := perpetualsKeeper.GetAllPerpetuals(ctx)
if err != nil {
panic(fmt.Sprintf("failed to get all perpetuals: %s", err))
}
perpetuals := perpetualsKeeper.GetAllPerpetuals(ctx)
for _, p := range perpetuals {
_, err = perpetualsKeeper.SetPerpetualMarketType(ctx, p.GetId(),
_, err := perpetualsKeeper.SetPerpetualMarketType(
ctx, p.GetId(),
perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS)
if err != nil {
panic(fmt.Sprintf("failed to set perpetual market type for perpetual %d: %s", p.GetId(), err))
Expand All @@ -47,6 +45,8 @@ func CreateUpgradeHandler(
// Set all perpetuals to cross market type
perpetualsUpgrade(sdkCtx, perpetualsKeeper)

// TODO(TRA-93): Initialize `x/vault` module.

return mm.RunMigrations(ctx, configurator, vm)
}
}
13 changes: 9 additions & 4 deletions protocol/mocks/ClobKeeper.go

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

16 changes: 16 additions & 0 deletions protocol/mocks/MemClob.go

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

18 changes: 9 additions & 9 deletions protocol/mocks/PerpetualsKeeper.go

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

Loading

0 comments on commit 7d63b0a

Please sign in to comment.