-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: stateless lien module that upcalls to kernel
- Loading branch information
Showing
10 changed files
with
458 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package lien | ||
|
||
import ( | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/keeper" | ||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types" | ||
) | ||
|
||
var ( | ||
NewKeeper = keeper.NewKeeper | ||
NewWrappedAccountKeeper = types.NewWrappedAccountKeeper | ||
) | ||
|
||
type ( | ||
Keeper = keeper.Keeper | ||
) |
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,135 @@ | ||
package keeper | ||
|
||
import ( | ||
"strings" | ||
"time" | ||
|
||
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" | ||
) | ||
|
||
func maxCoins(a, b sdk.Coins) sdk.Coins { | ||
max := make([]sdk.Coin, 0) | ||
for indexA, indexB := 0, 0; indexA < len(a) && indexB < len(b); { | ||
coinA, coinB := a[indexA], b[indexB] | ||
switch strings.Compare(coinA.Denom, coinB.Denom) { | ||
case -1: // A < B | ||
max = append(max, coinA) | ||
indexA++ | ||
case 0: // A == B | ||
maxCoin := coinA | ||
if coinB.IsGTE(maxCoin) { | ||
maxCoin = coinB | ||
} | ||
if !maxCoin.IsZero() { | ||
max = append(max, maxCoin) | ||
} | ||
indexA++ | ||
indexB++ | ||
case 1: // A > B | ||
max = append(max, coinB) | ||
indexB++ | ||
} | ||
} | ||
return sdk.NewCoins(max...) | ||
} | ||
|
||
var _ vestexported.VestingAccount = &LienAccount{} | ||
|
||
type LienAccount struct { | ||
vestexported.VestingAccount | ||
lienKeeper Keeper | ||
} | ||
|
||
// LockedCoins implements the method from the VestingAccount interface. | ||
// It takes the maximum of the coins locked for liens and the cons | ||
// locked in the wrapped VestingAccount. | ||
func (la *LienAccount) LockedCoins(ctx sdk.Context) sdk.Coins { | ||
wrappedLocked := la.VestingAccount.LockedCoins(ctx) | ||
lienedLocked := la.LienedLockedCoins(ctx) | ||
return maxCoins(wrappedLocked, lienedLocked) | ||
} | ||
|
||
func (la *LienAccount) LienedLockedCoins(ctx sdk.Context) sdk.Coins { | ||
return la.lienKeeper.GetLien(ctx, la.GetAddress()) | ||
} | ||
|
||
func NewAccountWrapper(lk Keeper) types.AccountWrapper { | ||
return types.AccountWrapper{ | ||
Wrap: func(acc authtypes.AccountI) authtypes.AccountI { | ||
if acc == nil { | ||
return nil | ||
} | ||
return &LienAccount{ | ||
VestingAccount: makeVesting(acc), | ||
lienKeeper: lk, | ||
} | ||
}, | ||
Unwrap: func(acc authtypes.AccountI) authtypes.AccountI { | ||
if la, ok := acc.(*LienAccount); ok { | ||
acc = la.VestingAccount | ||
} | ||
if uva, ok := acc.(*unlockedVestingAccount); ok { | ||
acc = uva.AccountI | ||
} | ||
return acc | ||
}, | ||
} | ||
} | ||
|
||
func makeVesting(acc authtypes.AccountI) vestexported.VestingAccount { | ||
if v, ok := acc.(vestexported.VestingAccount); ok { | ||
return v | ||
} | ||
return &unlockedVestingAccount{AccountI: acc} | ||
} | ||
|
||
// unlockedVestingAccount extends an ordinary account to be a vesting account | ||
// by simulating an original vesting amount of zero. It will be still stored | ||
// as the wrapped account. | ||
type unlockedVestingAccount struct { | ||
authtypes.AccountI | ||
} | ||
|
||
var _ vestexported.VestingAccount = (*unlockedVestingAccount)(nil) | ||
|
||
func (uva *unlockedVestingAccount) LockedCoins(ctx sdk.Context) sdk.Coins { | ||
return sdk.NewCoins() | ||
} | ||
|
||
func (uva *unlockedVestingAccount) TrackDelegation(blockTime time.Time, balance, amount sdk.Coins) { | ||
} | ||
|
||
func (uva *unlockedVestingAccount) TrackUndelegation(amount sdk.Coins) { | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins { | ||
return sdk.NewCoins() | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins { | ||
return sdk.NewCoins() | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetStartTime() int64 { | ||
return 0 | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetEndTime() int64 { | ||
return 0 | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetOriginalVesting() sdk.Coins { | ||
return sdk.NewCoins() | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetDelegatedFree() sdk.Coins { | ||
return sdk.NewCoins() | ||
} | ||
|
||
func (uva *unlockedVestingAccount) GetDelegatedVesting() sdk.Coins { | ||
return sdk.NewCoins() | ||
} |
Oops, something went wrong.