-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #549 from comdex-official/hbrefactor
Hbrefactor
- Loading branch information
Showing
107 changed files
with
7,638 additions
and
2,679 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package v5_0_0 //nolint:revive,stylecheck | ||
|
||
const ( | ||
UpgradeNameBeta = "v5.0.0.beta" | ||
UpgradeHeight = "" // replace this height | ||
UpgradeInfo = `'{ | ||
"binaries": { | ||
"darwin/arm64":"", | ||
"darwin/x86_64":"", | ||
"linux/arm64":"", | ||
"linux/x86_64":"", | ||
"windows/x86_64":"" | ||
} | ||
}'` | ||
) |
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,82 @@ | ||
package v5_0_0 //nolint:revive,stylecheck | ||
|
||
import ( | ||
lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" | ||
"github.com/comdex-official/comdex/x/lend/types" | ||
liquidationkeeper "github.com/comdex-official/comdex/x/liquidation/keeper" | ||
vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// SetVaultLengthCounter - Set vault length for liquidation check | ||
func SetVaultLengthCounter( | ||
ctx sdk.Context, | ||
vaultkeeper vaultkeeper.Keeper, | ||
) { | ||
var count uint64 | ||
appExtendedPairVaultData, found := vaultkeeper.GetAppMappingData(ctx, 2) | ||
if found { | ||
for _, data := range appExtendedPairVaultData { | ||
count += uint64(len(data.VaultIds)) | ||
} | ||
} | ||
vaultkeeper.SetLengthOfVault(ctx, count) | ||
} | ||
|
||
// FuncMigrateLiquidatedBorrow - Migrate all liquidated borrow to new borrow struct and make is_liquidated field to true | ||
func FuncMigrateLiquidatedBorrow(ctx sdk.Context, k lendkeeper.Keeper, liqK liquidationkeeper.Keeper) error { | ||
liqBorrow := liqK.GetLockedVaultByApp(ctx, 3) | ||
for _, v := range liqBorrow { | ||
if v.AmountIn.GT(sdk.ZeroInt()) && v.AmountOut.GT(sdk.ZeroInt()) { | ||
borrowMetaData := v.GetBorrowMetaData() | ||
pair, _ := k.GetLendPair(ctx, v.ExtendedPairId) | ||
assetIn, _ := k.Asset.GetAsset(ctx, pair.AssetIn) | ||
assetOut, _ := k.Asset.GetAsset(ctx, pair.AssetOut) | ||
amountIn := sdk.NewCoin(assetIn.Denom, v.AmountIn) | ||
amountOut := sdk.NewCoin(assetOut.Denom, v.AmountOut) | ||
var cpoolName string | ||
if pair.AssetOutPoolID == 1 { | ||
cpoolName = "CMDX-ATOM-CMST" | ||
} else { | ||
cpoolName = "OSMO-ATOM-CMST" | ||
} | ||
|
||
globalIndex, _ := sdk.NewDecFromStr("0.002") | ||
|
||
newBorrow := types.BorrowAsset{ | ||
ID: v.OriginalVaultId, | ||
LendingID: borrowMetaData.LendingId, | ||
IsStableBorrow: borrowMetaData.IsStableBorrow, | ||
PairID: v.ExtendedPairId, | ||
AmountIn: amountIn, | ||
AmountOut: amountOut, | ||
BridgedAssetAmount: borrowMetaData.BridgedAssetAmount, | ||
BorrowingTime: ctx.BlockTime(), | ||
StableBorrowRate: borrowMetaData.StableBorrowRate, | ||
InterestAccumulated: sdk.NewDecFromInt(v.InterestAccumulated), | ||
GlobalIndex: globalIndex, | ||
ReserveGlobalIndex: sdk.OneDec(), | ||
LastInteractionTime: ctx.BlockTime(), | ||
CPoolName: cpoolName, | ||
IsLiquidated: false, | ||
} | ||
lend, _ := k.GetLend(ctx, newBorrow.LendingID) | ||
k.UpdateBorrowStats(ctx, pair, newBorrow.IsStableBorrow, v.AmountOut, true) | ||
|
||
poolAssetLBMappingData, _ := k.GetAssetStatsByPoolIDAndAssetID(ctx, pair.AssetOutPoolID, pair.AssetOut) | ||
poolAssetLBMappingData.BorrowIds = append(poolAssetLBMappingData.BorrowIds, newBorrow.ID) | ||
k.SetAssetStatsByPoolIDAndAssetID(ctx, poolAssetLBMappingData) | ||
|
||
k.SetUserBorrowIDCounter(ctx, newBorrow.ID) | ||
k.SetBorrow(ctx, newBorrow) | ||
|
||
mappingData, _ := k.GetUserLendBorrowMapping(ctx, lend.Owner, newBorrow.LendingID) | ||
mappingData.BorrowId = append(mappingData.BorrowId, newBorrow.ID) | ||
k.SetUserLendBorrowMapping(ctx, mappingData) | ||
} else { | ||
// delete faulty lockedVault | ||
liqK.DeleteLockedVault(ctx, 3, v.LockedVaultId) | ||
} | ||
} | ||
return 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,31 @@ | ||
package v5_0_0 //nolint:revive,stylecheck | ||
|
||
import ( | ||
lendkeeper "github.com/comdex-official/comdex/x/lend/keeper" | ||
liquidationkeeper "github.com/comdex-official/comdex/x/liquidation/keeper" | ||
vaultkeeper "github.com/comdex-official/comdex/x/vault/keeper" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
func CreateUpgradeHandlerV5Beta( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
lk lendkeeper.Keeper, | ||
liqk liquidationkeeper.Keeper, | ||
vaultkeeper vaultkeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
vm, err := mm.RunMigrations(ctx, configurator, fromVM) | ||
if err != nil { | ||
return nil, err | ||
} | ||
SetVaultLengthCounter(ctx, vaultkeeper) | ||
err = FuncMigrateLiquidatedBorrow(ctx, lk, liqk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return vm, err | ||
} | ||
} |
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
Oops, something went wrong.