-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove sequential ID requirement on liquidity tiers (#279)
- Loading branch information
Showing
8 changed files
with
234 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package liquidity_tier | ||
|
||
import ( | ||
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" | ||
) | ||
|
||
type LtModifierOption func(cp *perptypes.LiquidityTier) | ||
|
||
func WithId(id uint32) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.Id = id | ||
} | ||
} | ||
|
||
func WithName(name string) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.Name = name | ||
} | ||
} | ||
|
||
func WithInitialMarginPpm(initialMarginPpm uint32) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.InitialMarginPpm = initialMarginPpm | ||
} | ||
} | ||
|
||
func WithMaitenanceMarginFraction(maitenanceMarginFraction uint32) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.MaintenanceFractionPpm = maitenanceMarginFraction | ||
} | ||
} | ||
|
||
func WithBasePositionNotional(basePositionNotional uint64) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.BasePositionNotional = basePositionNotional | ||
} | ||
} | ||
|
||
func WithImpactNotional(impactNotional uint64) LtModifierOption { | ||
return func(lt *perptypes.LiquidityTier) { | ||
lt.ImpactNotional = impactNotional | ||
} | ||
} | ||
|
||
// GenerateLiquidityTier returns a `LiquidityTier` object set to default values. | ||
// Passing in `LtModifierOption` methods alters the value of the `LiquidityTier` returned. | ||
// It will start with the default, valid `LiquidityTier` value defined within the method | ||
// and make the requested modifications before returning the object. | ||
// | ||
// Example usage: | ||
// `GenerateLiquidityTier(WithId(7))` | ||
// This will start with the default `LiquidityTier` object defined within the method and | ||
// return the newly-created object after overriding the values of `Id` to 7. | ||
func GenerateLiquidityTier(optionalModifications ...LtModifierOption) *perptypes.LiquidityTier { | ||
lt := &perptypes.LiquidityTier{ | ||
Id: 0, | ||
Name: "Large-Cap", | ||
InitialMarginPpm: 1_000_000, | ||
MaintenanceFractionPpm: 1_000_000, | ||
BasePositionNotional: 1_000_000, | ||
ImpactNotional: 500_000_000, | ||
} | ||
|
||
for _, opt := range optionalModifications { | ||
opt(lt) | ||
} | ||
|
||
return lt | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.