calculate amount of collateral automatically when an order is placed#117
Merged
just-in-chang merged 2 commits intomasterfrom Jul 18, 2022
Merged
calculate amount of collateral automatically when an order is placed#117just-in-chang merged 2 commits intomasterfrom
just-in-chang merged 2 commits intomasterfrom
Conversation
codchen
reviewed
Jul 16, 2022
| return nil, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "insufficient funds to place order") | ||
| } | ||
| msg.Funds[0].Amount = calculatedCollateral.Mul(sdk.NewDecFromInt(sdk.NewInt(1000000))).RoundInt() | ||
| msg.Funds[0].Denom = msg.Orders[0].PriceDenom |
Collaborator
There was a problem hiding this comment.
normally the fund denom would be micro unit whereas price denom would be whole unit. We can add a helper like this in some util files:
func ConvertMicroToWholeDenom(amount sdk.Dec, denom string) (sdk.Dec, string) {
assert denom starts with a `u`
wholeDenom := denom[1:]
assert wholeDenom is a valid denom (whitelisted in AssetList)
return amount * 1000000, wholeDenom
}
|
|
||
| if msg.AutoCalculateDeposit { | ||
| // throw error if current funds amount is less than calculatedCollateral | ||
| if msg.Funds[0].Amount.LT(calculatedCollateral.Mul(sdk.NewDecFromInt(sdk.NewInt(1000000))).RoundInt()) { |
Collaborator
There was a problem hiding this comment.
I probably didn't describe this clearly enough, but we don't really care what's passed in msg.Funds by the user. As long as msg. AutoCalculateDeposit is true, and there are enough funds in the user's bank, we will execute line 58-59. To check user's bank balance you can do k.Keeper.BankKeeper.GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string)
fa64a30 to
92a57a3
Compare
codchen
reviewed
Jul 18, 2022
|
|
||
| ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
|
||
| calculatedCollateral := sdk.NewDecFromBigInt(big.NewInt(0)) |
Collaborator
There was a problem hiding this comment.
move inside the if block below
codchen
reviewed
Jul 18, 2022
|
|
||
| if msg.AutoCalculateDeposit { | ||
| // throw error if current funds amount is less than calculatedCollateral | ||
| if msg.Funds[0].Amount.LT(k.Keeper.BankKeeper.GetBalance(ctx, sdk.AccAddress(msg.GetCreator()), msg.Orders[0].PriceDenom).Amount) { |
Collaborator
There was a problem hiding this comment.
if calculatedCollateral.GT(k.Keeper.BankKeeper.GetBalance(...))
codchen
approved these changes
Jul 18, 2022
philipsu522
pushed a commit
that referenced
this pull request
Jul 19, 2022
…117) * calculate amount of collateral automatically when an order is placed * address comments
alg747
pushed a commit
to UXDProtocol/sei-chain
that referenced
this pull request
Jul 20, 2022
…ei-protocol#117) * calculate amount of collateral automatically when an order is placed * address comments
masih
added a commit
that referenced
this pull request
Oct 9, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.