Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: loan pool #63

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c04456e
cleanup account id
SterlynLee May 26, 2023
296139e
pool pending storage
SterlynLee May 26, 2023
7717e83
ignite scaffold loan module
SterlynLee May 26, 2023
e08f6e0
new type LoanPool
SterlynLee May 29, 2023
1f5d4b4
new type Cridit
SterlynLee May 29, 2023
3ee0ac2
add field LoanStrategy/LoanPledged/LastRewardat in type Pledge
SterlynLee May 29, 2023
f908ed9
add field LastChargedAt in type LoanPool
SterlynLee May 29, 2023
93fc0f8
loanpool deposit and withdraw
SterlynLee May 30, 2023
704ac93
loan and repay
SterlynLee Jun 5, 2023
8bfbf2c
interest debt
SterlynLee Jun 5, 2023
16baac5
fix default params, query credit return amount
SterlynLee Jun 9, 2023
cc95539
add migrations
SterlynLee Jun 9, 2023
10302f8
fix
SterlynLee Jun 9, 2023
3d676c2
Merge remote-tracking branch 'origin/develop' into st/loan
SterlynLee Jun 12, 2023
761be1a
fix renew extra pledge
SterlynLee Jun 12, 2023
7f857a0
Merge remote-tracking branch 'origin/develop' into st/loan
SterlynLee Jun 13, 2023
c4cc5ff
Merge remote-tracking branch 'origin/develop' into st/loan
SterlynLee Jun 14, 2023
bc10c94
fix vstorage pledge amount
SterlynLee Jun 14, 2023
712e9af
refactor vstorage pledge
SterlynLee Jun 14, 2023
803b865
Merge branch 'develop' of github.com:SaoNetwork/sao-consensus into st…
SterlynLee Jun 15, 2023
6a0d510
Merge remote-tracking branch 'origin/develop' into st/loan
SterlynLee Jun 15, 2023
2ef60f4
add token slt as loan pool token
SterlynLee Jun 16, 2023
a43f0f5
disable loan pledge until baseline is reached
SterlynLee Jun 19, 2023
c15fb09
query available sao from loan pool
SterlynLee Jun 19, 2023
1ca7bfd
v0.1.7 migiration
SterlynLee Jun 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<a name="unreleased"></a>
## [Unreleased]


<a name="v0.1.6"></a>
## [v0.1.6](https://github.com/SAONetwork/sao-consensus/compare/v0.1.5...v0.1.6) (2023-06-15)

### Features
- add total storage and used storage in pledge ([#58](https://github.com/SAONetwork/sao-consensus/issues/58))
- allow sp to declare delegation with validator for higher order priority ([#54](https://github.com/SAONetwork/sao-consensus/issues/54))

* proof of existence ([#57](https://github.com/SAONetwork/sao-consensus/issues/57)) *#57*
* add total storage and used storage in pledge ([#58](https://github.com/SAONetwork/sao-consensus/issues/58)) *#58*
* allow sp to declare delegation with validator for higher order priority ([#54](https://github.com/SAONetwork/sao-consensus/issues/54)) *#54*

### Bug Fixes

* add shard pledge field to record order pledge ([#60](https://github.com/SAONetwork/sao-consensus/issues/60)) *#60*


<a name="v0.1.5"></a>
Expand Down
44 changes: 44 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"fmt"
v017 "github.com/SaoNetwork/sao/app/upgrades/v0_1_7"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -113,6 +114,9 @@ import (
didmodule "github.com/SaoNetwork/sao/x/did"
didmodulekeeper "github.com/SaoNetwork/sao/x/did/keeper"
didmoduletypes "github.com/SaoNetwork/sao/x/did/types"
loanmodule "github.com/SaoNetwork/sao/x/loan"
loanmodulekeeper "github.com/SaoNetwork/sao/x/loan/keeper"
loanmoduletypes "github.com/SaoNetwork/sao/x/loan/types"
marketmodule "github.com/SaoNetwork/sao/x/market"
marketmodulekeeper "github.com/SaoNetwork/sao/x/market/keeper"
marketmoduletypes "github.com/SaoNetwork/sao/x/market/types"
Expand Down Expand Up @@ -189,6 +193,7 @@ var (
modelmodule.AppModuleBasic{},
didmodule.AppModuleBasic{},
marketmodule.AppModuleBasic{},
loanmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -205,6 +210,7 @@ var (
nodemoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
ordermoduletypes.ModuleName: {authtypes.Staking},
marketmoduletypes.ModuleName: {authtypes.Staking},
loanmoduletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -276,6 +282,8 @@ type App struct {
DidKeeper didmodulekeeper.Keeper

MarketKeeper marketmodulekeeper.Keeper

LoanKeeper loanmodulekeeper.Keeper
// this line is used by starport scaffolding # stargate/app/keeperDeclaration

// mm is the module manager
Expand Down Expand Up @@ -319,6 +327,7 @@ func New(
modelmoduletypes.StoreKey,
didmoduletypes.StoreKey,
marketmoduletypes.StoreKey,
loanmoduletypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -459,6 +468,7 @@ func New(
app.OrderKeeper,
&stakingKeeper,
app.MarketKeeper,
app.LoanKeeper,
appCodec,
keys[nodemoduletypes.StoreKey],
keys[nodemoduletypes.MemStoreKey],
Expand Down Expand Up @@ -572,12 +582,22 @@ func New(
)
marketModule := marketmodule.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper)

app.LoanKeeper = *loanmodulekeeper.NewKeeper(
app.BankKeeper,
appCodec,
keys[loanmoduletypes.StoreKey],
keys[loanmoduletypes.MemStoreKey],
app.GetSubspace(loanmoduletypes.ModuleName),
)
loanModule := loanmodule.NewAppModule(appCodec, app.LoanKeeper, app.AccountKeeper, app.BankKeeper)

app.NodeKeeper = *nodemodulekeeper.NewKeeper(
app.AccountKeeper,
app.BankKeeper,
app.OrderKeeper,
app.StakingKeeper,
app.MarketKeeper,
app.LoanKeeper,
appCodec,
keys[nodemoduletypes.StoreKey],
keys[nodemoduletypes.MemStoreKey],
Expand Down Expand Up @@ -666,6 +686,7 @@ func New(
modelModule,
didModule,
marketModule,
loanModule,
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -701,6 +722,7 @@ func New(
modelmoduletypes.ModuleName,
didmoduletypes.ModuleName,
marketmoduletypes.ModuleName,
loanmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/beginBlockers
)

Expand Down Expand Up @@ -731,6 +753,7 @@ func New(
modelmoduletypes.ModuleName,
didmoduletypes.ModuleName,
marketmoduletypes.ModuleName,
loanmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/endBlockers
)

Expand Down Expand Up @@ -766,6 +789,7 @@ func New(
modelmoduletypes.ModuleName,
didmoduletypes.ModuleName,
marketmoduletypes.ModuleName,
loanmoduletypes.ModuleName,
// this line is used by starport scaffolding # stargate/app/initGenesis
)

Expand Down Expand Up @@ -801,6 +825,7 @@ func New(
modelModule,
didModule,
marketModule,
loanModule,
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()
Expand Down Expand Up @@ -863,6 +888,11 @@ func (app *App) setupUpgradeHandlers() {
v016.CreateUpgradeHandler(app.mm, app.configurator, app.NodeKeeper),
)

app.UpgradeKeeper.SetUpgradeHandler(
v017.UpgradeName,
v017.CreateUpgradeHandler(app.mm, app.configurator, app.NodeKeeper),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Errorf("failed to read upgrade info from disk: %w", err))
Expand All @@ -871,6 +901,19 @@ func (app *App) setupUpgradeHandlers() {
if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

var storeUpgrades *storetypes.StoreUpgrades

switch upgradeInfo.Name {
case v017.UpgradeName:
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{loanmoduletypes.StoreKey},
}
}

if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}

// Name returns the name of the App
Expand Down Expand Up @@ -1035,6 +1078,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(modelmoduletypes.ModuleName)
paramsKeeper.Subspace(didmoduletypes.ModuleName)
paramsKeeper.Subspace(marketmoduletypes.ModuleName)
paramsKeeper.Subspace(loanmoduletypes.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v0_1_7/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v017

const (
UpgradeName = "v0.1.7"
UpgradeInfo = `'upgrade to v0.1.7'`
)
21 changes: 21 additions & 0 deletions app/upgrades/v0_1_7/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v017

import (
nodekeeper "github.com/SaoNetwork/sao/x/node/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 CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
node nodekeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

logger.Debug("running module migrations ...")
return mm.RunMigrations(ctx, configurator, vm)
}
}
4 changes: 4 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ genesis:
amount: "100000000000"
denom: "sao"
annual_percentage_yield : "1"
loan:
params:
InterestRatePerBlock: "0.0000000625"
minLiquidityRatio: "0.3"
staking:
params:
bond_denom: "sao"
Expand Down
Loading
Loading