Skip to content

Commit

Permalink
Merge branch 'develop' into lev
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmic-vagabond authored Jun 26, 2024
2 parents 77accb8 + 2191fb3 commit ece8bef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/delete-branch-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- name: Retrieve post upgrade snapshot generator binary
run: |
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.2
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.5
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}
curl -L $DOWNLOAD_URL -o $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH && chmod +x $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/software-upgrade-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Retrieve post upgrade snapshot generator binary
run: |
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.2
POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION=v0.2.5
DOWNLOAD_URL=https://github.com/elys-network/post-upgrade-snapshot-generator/releases/download/${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}-linux-amd64
POST_UPGRADE_SNAPSHOT_GENERATOR_PATH=/tmp/post-upgrade-snapshot-generator-${POST_UPGRADE_SNAPSHOT_GENERATOR_VERSION}
curl -L $DOWNLOAD_URL -o $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH && chmod +x $POST_UPGRADE_SNAPSHOT_GENERATOR_PATH
Expand Down
13 changes: 13 additions & 0 deletions x/stablestake/keeper/debt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/elys-network/elys/x/stablestake/types"
)

Expand Down Expand Up @@ -81,6 +82,18 @@ func (k Keeper) Borrow(ctx sdk.Context, addr sdk.AccAddress, amount sdk.Coin) er
if depositDenom != amount.Denom {
return types.ErrInvalidBorrowDenom
}

// For security reasons, we should avoid borrowing more than 90% in total to the stablestake pool.
moduleAddr := authtypes.NewModuleAddress(types.ModuleName)
params := k.GetParams(ctx)
balance := k.bk.GetBalance(ctx, moduleAddr, depositDenom)

borrowed := params.TotalValue.Sub(balance.Amount).ToLegacyDec().Add(amount.Amount.ToLegacyDec())
maxAllowed := params.TotalValue.ToLegacyDec().Mul(sdk.NewDec(9)).Quo(sdk.NewDec(10))
if borrowed.GT(maxAllowed) {
return types.ErrMaxBorrowAmount
}

debt := k.UpdateInterestStackedByAddress(ctx, addr)
debt.Borrowed = debt.Borrowed.Add(amount.Amount)
k.SetDebt(ctx, debt)
Expand Down
1 change: 1 addition & 0 deletions x/stablestake/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var (
ErrInvalidBorrowDenom = errorsmod.Register(ModuleName, 2, "invalid borrow denom")
ErrRedemptionRateIsZero = errorsmod.Register(ModuleName, 3, "redemption rate is zero")
ErrNegativeBorrowed = errorsmod.Register(ModuleName, 4, "negative borrowed amount")
ErrMaxBorrowAmount = errorsmod.Register(ModuleName, 5, "cannot borrow more than 90% of total stablestake pool.")
)

0 comments on commit ece8bef

Please sign in to comment.