-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/derivatives fix command close potision #388
Changes from 2 commits
19d48d0
b2555fb
6c813cf
328a18b
e4d8be1
c5960c1
1879a64
12ed797
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,8 @@ jq '.app_state.pricefeed.params.markets = [ | |
{ "market_id": "ubtc:usd:30", "base_asset": "ubtc", "quote_asset": "usd", "oracles": [ "'$PRICEFEED_ADDRESS'" ], "active": true }, | ||
{ "market_id": "uusdc:usd", "base_asset": "uusdc", "quote_asset": "usd", "oracles": [ "'$PRICEFEED_ADDRESS'" ], "active": true }, | ||
{ "market_id": "uusdc:usd:30", "base_asset": "uusdc", "quote_asset": "usd", "oracles": [ "'$PRICEFEED_ADDRESS'" ], "active": true }, | ||
{"market_id": "uusdc:ubtc", "base_asset":"uusdc", "quote_asset":"ubtc", "oracles": ["'$PRICEFEED'"], "active": true} | ||
{ "market_id": "ubtc:uusdc", "base_asset":"ubtc", "quote_asset":"uusdc", "oracles": ["'$PRICEFEED_ADDRESS'"], "active": true}, | ||
{ "market_id": "ubtc:uusdc:30", "base_asset":"ubtc", "quote_asset":"uusdc", "oracles": ["'$PRICEFEED_ADDRESS'"], "active": true} | ||
]' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.derivatives.params.pool.base_lpt_mint_fee = "0.001"' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.derivatives.params.pool.base_lpt_redeem_fee = "0.001"' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
|
@@ -78,13 +79,17 @@ jq '.app_state.derivatives.params.perpetual_futures.commission_rate = "0.001"' $ | |
jq '.app_state.derivatives.params.perpetual_futures.margin_maintenance_rate = "0.5"' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.derivatives.params.perpetual_futures.imaginary_funding_rate_proportional_coefficient = "0.0005"' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.derivatives.params.perpetual_futures.markets = [{"base_denom": "ubtc", "quote_denom": "uusd" }]' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please change "uusd" to "uusdc". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
jq '.app_state.bank.denom_metadata = [{"base" : "ubtc" , "symbol": "ubtc"}, {"base" : "uusd", "symbol": "uusdc"}]' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.bank.denom_metadata = [ | ||
{"base" : "ubtc" , "symbol": "ubtc"}, | ||
{"base" : "uusd", "symbol": "uusdc"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz change "uusd" to "uusdc" here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
]' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
jq '.app_state.pricefeed.posted_prices = [ | ||
{"expiry": "2024-02-20T12:02:01Z","market_id": "ubtc:usd","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "0.024508410211260500"}, | ||
{"expiry": "2024-02-20T12:02:47Z","market_id": "ubtc:usd:30","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "0.005779087260702010"}, | ||
{"expiry": "2024-02-20T12:03:30Z","market_id": "uusdc:usd","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "0.000001001479651825"}, | ||
{"expiry": "2024-02-20T12:04:11Z","market_id": "uusdc:usd:30","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "0.000001002011358752"}, | ||
{"expiry": "2024-02-20T12:00:38Z","market_id": "ubtc:uusdc","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "24528.185864015486004064"} | ||
{"expiry": "2024-02-20T12:00:38Z","market_id": "ubtc:uusdc","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "24528.185864015486004064"}, | ||
{"expiry": "2024-02-20T12:00:38Z","market_id": "ubtc:uusdc:30","oracle_address": "ununifi1h7ulktk5p2gt7tnxwhqzlq0yegq47hum0fahcr","price": "24528.185864015486004064"} | ||
]' $NODE_HOME/config/genesis.json > temp.json ; mv temp.json $NODE_HOME/config/genesis.json; | ||
|
||
ununifid start --home=$NODE_HOME | ||
# ununifid start --home=$NODE_HOME |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package keeper | |
import ( | ||
"errors" | ||
"time" | ||
"fmt" | ||
"strconv" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
|
@@ -17,6 +19,23 @@ func (k Keeper) GetLastPositionId(ctx sdk.Context) string { | |
return string(bz) | ||
} | ||
|
||
func (k Keeper) GetLastPosition(ctx sdk.Context) (types.Position, error) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
||
position := types.Position{} | ||
|
||
it := sdk.KVStoreReversePrefixIterator(store, []byte(types.KeyPrefixPosition)) | ||
defer it.Close() | ||
|
||
for ; it.Valid(); it.Next() { | ||
position := types.Position{} | ||
k.cdc.Unmarshal(it.Value(), &position) | ||
return position, nil | ||
} | ||
|
||
return position, fmt.Errorf("position not found") | ||
} | ||
|
||
func (k Keeper) IncreaseLastPositionId(ctx sdk.Context) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
||
|
@@ -105,11 +124,21 @@ func (k Keeper) DeletePosition(ctx sdk.Context, address sdk.AccAddress, id strin | |
} | ||
|
||
func (k Keeper) OpenPosition(ctx sdk.Context, msg *types.MsgOpenPosition) error { | ||
sender := msg.Sender.AccAddress() | ||
lastPositionId := k.GetLastPositionId(ctx) | ||
// todo check sender amount for margin | ||
|
||
positionKey := types.AddressPositionWithIdKeyPrefix(sender, lastPositionId) | ||
positionId := string(positionKey) | ||
lastPosition, err := k.GetLastPosition(ctx) | ||
if err != nil { | ||
panic("failed to get last position") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe better to define Error case and return err, instead of executing panic? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case is usually not possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I made a mistake. |
||
} | ||
|
||
var positionId string | ||
if lastPosition.Id == "" { | ||
positionId = "0" | ||
} else { | ||
// increment position id | ||
lastPositionId, _ := strconv.Atoi(lastPosition.Id) | ||
positionId = strconv.Itoa(lastPositionId + 1) | ||
} | ||
|
||
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, msg.Sender.AccAddress(), types.ModuleName, sdk.NewCoins(msg.Margin)); err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plz change "uusd" to "uusdc" after the change of the markets values in genesis.json.
plz refer init.sh file comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uusdc does't work.
uusd is working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this modification (#388 (comment)), it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not work.
I have tried that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, needed one more modification.
#388 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's working