-
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.
- Loading branch information
Showing
68 changed files
with
1,238 additions
and
1,576 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
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/margin/types" | ||
) | ||
|
||
func (k Keeper) CalcMTPTakeProfitBorrowRate(ctx sdk.Context, mtp *types.MTP) (sdk.Dec, error) { | ||
// Check if there are any takeProfitCustodies to avoid division by zero | ||
if len(mtp.TakeProfitCustodies) == 0 { | ||
return sdk.ZeroDec(), nil | ||
} | ||
|
||
var totalTakeProfitBorrowRate sdk.Dec = sdk.ZeroDec() | ||
for takeProfitCustodyIndex, takeProfitCustody := range mtp.TakeProfitCustodies { | ||
// Calculate the borrow rate for this takeProfitCustody | ||
takeProfitBorrowRateInt := takeProfitCustody.Amount.Quo(mtp.Custodies[takeProfitCustodyIndex].Amount) | ||
|
||
// Convert takeProfitBorrowRateInt from sdk.Int to sdk.Dec | ||
takeProfitBorrowRateDec := sdk.NewDecFromInt(takeProfitBorrowRateInt) | ||
|
||
// Add this take profit borrow rate to the total | ||
totalTakeProfitBorrowRate = totalTakeProfitBorrowRate.Add(takeProfitBorrowRateDec) | ||
} | ||
|
||
// Calculate the average take profit borrow rate | ||
averageTakeProfitBorrowRate := totalTakeProfitBorrowRate.Quo(sdk.NewDec(int64(len(mtp.TakeProfitCustodies)))) | ||
|
||
// Get Margin Params | ||
params := k.GetParams(ctx) | ||
|
||
// Use TakeProfitBorrowInterestRateMin param as minimum take profit borrow rate | ||
averageTakeProfitBorrowRate = sdk.MaxDec(averageTakeProfitBorrowRate, params.TakeProfitBorrowInterestRateMin) | ||
|
||
return averageTakeProfitBorrowRate, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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() | ||
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.