-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: tp calc and update * fix: types * test: fix * test: fix * test: fix
- Loading branch information
1 parent
547de88
commit b63ab1f
Showing
12 changed files
with
262 additions
and
15 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,30 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/margin/types" | ||
) | ||
|
||
func (k Keeper) CalcMTPTakeProfitLiability(ctx sdk.Context, mtp *types.MTP, baseCurrency string) (sdk.Int, error) { | ||
takeProfitLiabilities := sdk.ZeroInt() | ||
if types.IsTakeProfitPriceInifite(mtp) { | ||
return takeProfitLiabilities, nil | ||
} | ||
for _, takeProfitCustody := range mtp.TakeProfitCustodies { | ||
takeProfitCustodyAsset := takeProfitCustody.Denom | ||
// Retrieve AmmPool | ||
ammPool, err := k.GetAmmPool(ctx, mtp.AmmPoolId, takeProfitCustodyAsset) | ||
if err != nil { | ||
return sdk.ZeroInt(), err | ||
} | ||
|
||
// convert custody amount to base currency | ||
C, err := k.EstimateSwapGivenOut(ctx, takeProfitCustody, baseCurrency, ammPool) | ||
if err != nil { | ||
return sdk.ZeroInt(), err | ||
} | ||
takeProfitLiabilities = takeProfitLiabilities.Add(C) | ||
} | ||
|
||
return takeProfitLiabilities, nil | ||
} |
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
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,16 @@ | ||
package types | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func CalcMTPTakeProfitCustodies(mtp *MTP) sdk.Coins { | ||
takeProfitCustodies := mtp.TakeProfitCustodies | ||
if IsTakeProfitPriceInifite(mtp) { | ||
return takeProfitCustodies | ||
} | ||
for custodyIndex := range mtp.Custodies { | ||
takeProfitCustodies[custodyIndex].Amount = sdk.NewDecFromInt(mtp.Liabilities).Quo(mtp.TakeProfitPrice).TruncateInt() | ||
} | ||
return takeProfitCustodies | ||
} |
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,5 @@ | ||
package types | ||
|
||
func IsTakeProfitPriceInifite(mtp *MTP) bool { | ||
return mtp.TakeProfitPrice.TruncateInt().String() == TakeProfitPriceDefault | ||
} |
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