@agoric/cosmos 0.35.0-upgrade-14-dev-c8f9e7b.0 → 0.35.0-upgrade-16a-dev-fb592e4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -77
- package/MAINTAINERS.md +3 -0
- package/Makefile +36 -26
- package/ante/ante.go +7 -9
- package/ante/inbound_test.go +3 -2
- package/ante/vm_admission.go +2 -1
- package/app/app.go +212 -140
- package/app/upgrade.go +76 -0
- package/cmd/agd/agvm.go +42 -0
- package/cmd/agd/main.go +130 -11
- package/cmd/libdaemon/main.go +64 -53
- package/cmd/libdaemon/main_test.go +2 -1
- package/daemon/cmd/root.go +171 -74
- package/daemon/cmd/root_test.go +189 -1
- package/daemon/main.go +4 -2
- package/e2e_test/Makefile +29 -0
- package/e2e_test/README.md +100 -0
- package/e2e_test/go.mod +217 -0
- package/e2e_test/go.sum +1323 -0
- package/e2e_test/ibc_conformance_test.go +56 -0
- package/e2e_test/pfm_test.go +613 -0
- package/e2e_test/util.go +271 -0
- package/git-revision.txt +1 -1
- package/go.mod +22 -11
- package/go.sum +17 -13
- package/package.json +9 -5
- package/proto/agoric/swingset/genesis.proto +4 -0
- package/proto/agoric/swingset/swingset.proto +1 -1
- package/proto/agoric/vlocalchain/.clang-format +7 -0
- package/proto/agoric/vlocalchain/vlocalchain.proto +31 -0
- package/proto/agoric/vtransfer/genesis.proto +18 -0
- package/scripts/protocgen.sh +7 -8
- package/types/kv_entry_helpers.go +42 -0
- package/upgradegaia.sh +8 -8
- package/vm/action.go +5 -4
- package/vm/action_test.go +31 -11
- package/vm/client.go +113 -0
- package/vm/client_test.go +182 -0
- package/vm/controller.go +17 -40
- package/vm/core_proposals.go +22 -2
- package/vm/jsonrpcconn/jsonrpcconn.go +160 -0
- package/vm/jsonrpcconn/jsonrpcconn_test.go +126 -0
- package/vm/proto_json.go +38 -0
- package/vm/proto_json_test.go +103 -0
- package/vm/server.go +124 -0
- package/x/swingset/abci.go +10 -10
- package/x/swingset/alias.go +2 -0
- package/x/swingset/client/cli/tx.go +4 -0
- package/x/swingset/genesis.go +84 -24
- package/x/swingset/handler.go +2 -1
- package/x/swingset/keeper/extension_snapshotter.go +2 -2
- package/x/swingset/keeper/keeper.go +13 -25
- package/x/swingset/keeper/msg_server.go +18 -18
- package/x/swingset/keeper/proposal.go +3 -3
- package/x/swingset/keeper/querier.go +12 -11
- package/x/swingset/keeper/swing_store_exports_handler.go +21 -6
- package/x/swingset/keeper/test_utils.go +16 -0
- package/x/swingset/module.go +7 -7
- package/x/swingset/proposal_handler.go +2 -1
- package/x/swingset/testing/queue.go +17 -0
- package/x/swingset/types/default-params.go +1 -1
- package/x/swingset/types/expected_keepers.go +3 -2
- package/x/swingset/types/genesis.pb.go +78 -25
- package/x/swingset/types/msgs.go +44 -24
- package/x/swingset/types/params.go +2 -1
- package/x/swingset/types/proposal.go +5 -4
- package/x/swingset/types/swingset.pb.go +1 -1
- package/x/vbank/genesis.go +0 -2
- package/x/vbank/handler.go +2 -1
- package/x/vbank/keeper/querier.go +4 -3
- package/x/vbank/module.go +0 -5
- package/x/vbank/types/msgs.go +0 -12
- package/x/vbank/vbank.go +9 -9
- package/x/vbank/vbank_test.go +2 -2
- package/x/vibc/alias.go +3 -0
- package/x/vibc/handler.go +16 -9
- package/x/vibc/keeper/keeper.go +102 -65
- package/x/vibc/keeper/triggers.go +101 -0
- package/x/vibc/module.go +5 -8
- package/x/vibc/types/expected_keepers.go +13 -0
- package/x/vibc/types/ibc_module.go +336 -0
- package/x/vibc/types/receiver.go +170 -0
- package/x/vlocalchain/alias.go +19 -0
- package/x/vlocalchain/handler.go +21 -0
- package/x/vlocalchain/keeper/keeper.go +279 -0
- package/x/vlocalchain/keeper/keeper_test.go +97 -0
- package/x/vlocalchain/types/codec.go +34 -0
- package/x/vlocalchain/types/key.go +27 -0
- package/x/vlocalchain/types/msgs.go +16 -0
- package/x/vlocalchain/types/vlocalchain.pb.go +1072 -0
- package/x/vlocalchain/vlocalchain.go +114 -0
- package/x/vlocalchain/vlocalchain_test.go +434 -0
- package/x/vstorage/handler.go +2 -1
- package/x/vstorage/keeper/grpc_query.go +0 -1
- package/x/vstorage/keeper/keeper.go +13 -20
- package/x/vstorage/keeper/querier.go +6 -5
- package/x/vstorage/keeper/querier_test.go +4 -3
- package/x/vstorage/module.go +0 -5
- package/x/vstorage/testing/queue.go +27 -0
- package/x/vtransfer/alias.go +13 -0
- package/x/vtransfer/genesis.go +39 -0
- package/x/vtransfer/genesis_test.go +12 -0
- package/x/vtransfer/handler.go +20 -0
- package/x/vtransfer/ibc_middleware.go +186 -0
- package/x/vtransfer/ibc_middleware_test.go +448 -0
- package/x/vtransfer/keeper/keeper.go +281 -0
- package/x/vtransfer/module.go +124 -0
- package/x/vtransfer/types/expected_keepers.go +38 -0
- package/x/vtransfer/types/genesis.pb.go +327 -0
- package/x/vtransfer/types/key.go +9 -0
- package/x/vtransfer/types/msgs.go +9 -0
- package/ante/fee.go +0 -96
- package/proto/agoric/lien/genesis.proto +0 -25
- package/proto/agoric/lien/lien.proto +0 -25
- package/x/lien/alias.go +0 -17
- package/x/lien/genesis.go +0 -58
- package/x/lien/genesis_test.go +0 -101
- package/x/lien/keeper/account.go +0 -290
- package/x/lien/keeper/keeper.go +0 -255
- package/x/lien/keeper/keeper_test.go +0 -623
- package/x/lien/lien.go +0 -205
- package/x/lien/lien_test.go +0 -533
- package/x/lien/module.go +0 -115
- package/x/lien/spec/01_concepts.md +0 -146
- package/x/lien/spec/02_messages.md +0 -96
- package/x/lien/types/accountkeeper.go +0 -81
- package/x/lien/types/accountstate.go +0 -27
- package/x/lien/types/expected_keepers.go +0 -18
- package/x/lien/types/genesis.pb.go +0 -567
- package/x/lien/types/key.go +0 -25
- package/x/lien/types/lien.pb.go +0 -403
- package/x/vibc/ibc.go +0 -394
- /package/{src/index.cjs → index.cjs} +0 -0
package/x/lien/keeper/account.go
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
package keeper
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"time"
|
|
5
|
-
|
|
6
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
|
|
7
|
-
|
|
8
|
-
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
9
|
-
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
10
|
-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
11
|
-
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
12
|
-
"github.com/gogo/protobuf/proto"
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
// omniAccount is the full expected interface of non-module accounts.
|
|
16
|
-
// In addition to the methods declared in authtypes.AccountI, additional
|
|
17
|
-
// expectations are enforced dynamically through casting and reflection:
|
|
18
|
-
//
|
|
19
|
-
// - non-module accounts are expected to obey the GenesisAccount interface,
|
|
20
|
-
// i.e. to have a Validate() method;
|
|
21
|
-
//
|
|
22
|
-
// - UnpackInterfacesMessage is needed for unpacking accounts embedded
|
|
23
|
-
// in an Any message;
|
|
24
|
-
//
|
|
25
|
-
// - MarshalYAML() is used for String rendering;
|
|
26
|
-
//
|
|
27
|
-
// - protobuf Messages are expected to implement a number of "XXX"-prefixed
|
|
28
|
-
// methods not visible in the Message interface.
|
|
29
|
-
//
|
|
30
|
-
// Declaring the expected methods here allows them to implicitly fall through
|
|
31
|
-
// to an embedded omniAccount.
|
|
32
|
-
//
|
|
33
|
-
// Note that this interface will have to adapt to updated expectations in
|
|
34
|
-
// the cosmos-sdk or protobuf library.
|
|
35
|
-
type omniAccount interface {
|
|
36
|
-
authtypes.GenesisAccount
|
|
37
|
-
codectypes.UnpackInterfacesMessage
|
|
38
|
-
MarshalYAML() (interface{}, error)
|
|
39
|
-
XXX_DiscardUnknown()
|
|
40
|
-
XXX_Marshal([]byte, bool) ([]byte, error)
|
|
41
|
-
XXX_Merge(proto.Message)
|
|
42
|
-
XXX_Size() int
|
|
43
|
-
XXX_Unmarshal([]byte) error
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// omniVestingAccount is an omniAccount plus vesting methods.
|
|
47
|
-
type omniVestingAccount interface {
|
|
48
|
-
omniAccount
|
|
49
|
-
vestexported.VestingAccount
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// omniGrantAccount is an omniAccount plus GrantAccount methods.
|
|
53
|
-
type omniGrantAccount interface {
|
|
54
|
-
omniAccount
|
|
55
|
-
vestexported.GrantAccount
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// omniClawbackAccount is an omniAccount plus Clawback methods.
|
|
59
|
-
type omniClawbackAccount interface {
|
|
60
|
-
omniAccount
|
|
61
|
-
vestexported.ClawbackVestingAccountI
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// unlockedVestingAccount extends an omniAccount to be a vesting account
|
|
65
|
-
// by simulating an original vesting amount of zero. It inherets the marshal
|
|
66
|
-
// behavior of the wrapped account. It uses the lien structure to track
|
|
67
|
-
// delegation.
|
|
68
|
-
type unlockedVestingAccount struct {
|
|
69
|
-
omniAccount
|
|
70
|
-
lien *types.Lien
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var _ omniVestingAccount = unlockedVestingAccount{}
|
|
74
|
-
|
|
75
|
-
// LockedCoins implements the vestexported.VestingAccount interface.
|
|
76
|
-
func (uva unlockedVestingAccount) LockedCoins(ctx sdk.Context) sdk.Coins {
|
|
77
|
-
return sdk.NewCoins()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// TrackDelegation implements the vestexported.VestingAccount interface.
|
|
81
|
-
func (uva unlockedVestingAccount) TrackDelegation(blockTime time.Time, balance, amount sdk.Coins) {
|
|
82
|
-
if !amount.IsAllLTE(balance) {
|
|
83
|
-
panic("insufficient funds")
|
|
84
|
-
}
|
|
85
|
-
uva.lien.Delegated = uva.lien.Delegated.Add(amount...)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// TrackUndelegation implements the vestexported.VestingAccount interface.
|
|
89
|
-
func (uva unlockedVestingAccount) TrackUndelegation(amount sdk.Coins) {
|
|
90
|
-
// max(delegated - amount, 0) == delegated - min(delegated, amount)
|
|
91
|
-
uva.lien.Delegated = uva.lien.Delegated.Sub(uva.lien.Delegated.Min(amount)...)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// GetVestedCoins implements the vestexported.VestingAccount interface.
|
|
95
|
-
func (uva unlockedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins {
|
|
96
|
-
return sdk.NewCoins()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// GetVestingCoins implements the vestexported.VestingAccount interface.
|
|
100
|
-
func (uva unlockedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
|
101
|
-
return sdk.NewCoins()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// GetStartTime implements the vestexported.VestingAccount interface.
|
|
105
|
-
func (uva unlockedVestingAccount) GetStartTime() int64 {
|
|
106
|
-
return 0
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// GetEndTime implements the vestexported.VestingAccount interface.
|
|
110
|
-
func (uva unlockedVestingAccount) GetEndTime() int64 {
|
|
111
|
-
return 0
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// GetOriginalVesting implements the vestexported.VestingAccount interface.
|
|
115
|
-
func (uva unlockedVestingAccount) GetOriginalVesting() sdk.Coins {
|
|
116
|
-
return sdk.NewCoins()
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// GetDelegatedFree implements the vestexported.VestingAccount interface.
|
|
120
|
-
func (uva unlockedVestingAccount) GetDelegatedFree() sdk.Coins {
|
|
121
|
-
return uva.lien.Delegated
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// GetDelegatedVesting implements the vestexported.VestingAccount interface.
|
|
125
|
-
func (uva unlockedVestingAccount) GetDelegatedVesting() sdk.Coins {
|
|
126
|
-
return sdk.NewCoins()
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// XXX_MessageName implements the method used by the gogoproto extension
|
|
130
|
-
// for grpc-gateway compatibility.
|
|
131
|
-
func (uva unlockedVestingAccount) XXX_MessageName() string {
|
|
132
|
-
return proto.MessageName(uva.omniAccount)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// fakeGrantAccount extends an omniVestingAccount to be a GrantAccount.
|
|
136
|
-
type fakeGrantAccount struct {
|
|
137
|
-
omniVestingAccount
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var _ omniGrantAccount = fakeGrantAccount{}
|
|
141
|
-
|
|
142
|
-
// AddGrant implements the vestexported.GrantAccount interface.
|
|
143
|
-
func (fga fakeGrantAccount) AddGrant(ctx sdk.Context, grantAction vestexported.AddGrantAction) error {
|
|
144
|
-
return grantAction.AddToAccount(ctx, fga.omniVestingAccount) // XXX or just fail here
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// fakeClawbackAccount extends an omniGrantAccount to be a clawback account.
|
|
148
|
-
type fakeClawbackAccount struct {
|
|
149
|
-
omniGrantAccount
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
var _ omniClawbackAccount = fakeClawbackAccount{}
|
|
153
|
-
|
|
154
|
-
// GetUnlockedOnly implements the vestexported.ClawbackVestingAccountI interface.
|
|
155
|
-
func (fca fakeClawbackAccount) GetUnlockedOnly(blockTime time.Time) sdk.Coins {
|
|
156
|
-
return fca.omniGrantAccount.GetVestedCoins(blockTime)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// GetVestedOnly implements the vestexported.ClawbackVestingAccountI interface.
|
|
160
|
-
func (fca fakeClawbackAccount) GetVestedOnly(blockTime time.Time) sdk.Coins {
|
|
161
|
-
return fca.omniGrantAccount.GetOriginalVesting()
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Clawback implements the vestexported.ClawbackVestingAccountI interface.
|
|
165
|
-
func (fca fakeClawbackAccount) Clawback(ctx sdk.Context, action vestexported.ClawbackAction) error {
|
|
166
|
-
return action.TakeFromAccount(ctx, fca.omniGrantAccount) // XXX or just fail here
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// PostReward implements the vestexported.ClawbackVestingAccountI interface.
|
|
170
|
-
func (fca fakeClawbackAccount) PostReward(ctx sdk.Context, reward sdk.Coins, action vestexported.RewardAction) error {
|
|
171
|
-
// perform no action here, but lienAccount can divert lien
|
|
172
|
-
return nil
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// ReturnGrants implements the vestexported.ClawbackVestingAccountI interface.
|
|
176
|
-
func (fca fakeClawbackAccount) ReturnGrants(ctx sdk.Context, action vestexported.ReturnGrantAction) error {
|
|
177
|
-
return action.TakeGrants(ctx, fca.omniGrantAccount) // XXX or just fail here
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// LienAccount wraps an omniClawbackAccount to implement lien encumbrance.
|
|
181
|
-
// The LockedCoins() method is the maximum of the coins locked for
|
|
182
|
-
// liens, and the coins locked in the underlying VestingAccount.
|
|
183
|
-
// It inherits the marshaling behavior of the wrapped account.
|
|
184
|
-
// In particular, the Lien account must be passed by pointer because of
|
|
185
|
-
// expectations from the proto library.
|
|
186
|
-
type LienAccount struct {
|
|
187
|
-
omniClawbackAccount
|
|
188
|
-
lienKeeper Keeper
|
|
189
|
-
lien types.Lien
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var _ omniClawbackAccount = &LienAccount{}
|
|
193
|
-
|
|
194
|
-
// LockedCoins implements the method from the VestingAccount interface.
|
|
195
|
-
// It takes the maximum of the coins locked for liens and the coins
|
|
196
|
-
// locked in the wrapped VestingAccount, but limited to the current
|
|
197
|
-
// account balance.
|
|
198
|
-
func (la *LienAccount) LockedCoins(ctx sdk.Context) sdk.Coins {
|
|
199
|
-
wrappedLocked := la.omniClawbackAccount.LockedCoins(ctx)
|
|
200
|
-
lienedLocked := la.LienedLockedCoins(ctx)
|
|
201
|
-
encumbered := wrappedLocked.Max(lienedLocked)
|
|
202
|
-
balance := la.lienKeeper.GetAllBalances(ctx, la.GetAddress())
|
|
203
|
-
return balance.Min(encumbered)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// LienedLockedCoins returns the coins which are locked on the lien/vesting dimension,
|
|
207
|
-
// which is the raw unvested amount, plus the raw liened amount, less the net amount
|
|
208
|
-
// delegated.
|
|
209
|
-
func (la *LienAccount) LienedLockedCoins(ctx sdk.Context) sdk.Coins {
|
|
210
|
-
delegated := la.GetDelegatedFree().Add(la.GetDelegatedVesting()...)
|
|
211
|
-
liened := la.lien.Coins
|
|
212
|
-
acc := la.omniClawbackAccount.(authtypes.AccountI)
|
|
213
|
-
if clawback, ok := acc.(vestexported.ClawbackVestingAccountI); ok {
|
|
214
|
-
liened = liened.Add(clawback.GetOriginalVesting().Sub(clawback.GetVestedOnly(ctx.BlockTime())...)...)
|
|
215
|
-
}
|
|
216
|
-
// Since coins can't go negative, even transiently, use the
|
|
217
|
-
// identity A + B = max(A, B) + min(A, B)
|
|
218
|
-
// max(0, A - B) = max(B, A) - B = A - min(A, B)
|
|
219
|
-
return liened.Sub(liened.Min(delegated)...)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
// XXX_MessageName provides the message name for JSON serialization.
|
|
223
|
-
// See proto.MessageName().
|
|
224
|
-
func (la *LienAccount) XXX_MessageName() string {
|
|
225
|
-
// Use the embedded account's message name for JSON serialization.
|
|
226
|
-
return proto.MessageName(la.omniClawbackAccount)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// NewAccountWrapper returns an AccountWrapper which wraps any account
|
|
230
|
-
// to be a LienAccount associated with the given Keeper, then unwraps
|
|
231
|
-
// any layers that the Wrap added.
|
|
232
|
-
func NewAccountWrapper(lk Keeper) types.AccountWrapper {
|
|
233
|
-
return types.AccountWrapper{
|
|
234
|
-
Wrap: func(ctx sdk.Context, acc authtypes.AccountI) authtypes.AccountI {
|
|
235
|
-
if acc == nil {
|
|
236
|
-
return nil
|
|
237
|
-
}
|
|
238
|
-
omni, ok := acc.(omniAccount)
|
|
239
|
-
if !ok {
|
|
240
|
-
// don't wrap non-omni accounts, e.g. module accounts
|
|
241
|
-
return acc
|
|
242
|
-
}
|
|
243
|
-
addr := acc.GetAddress()
|
|
244
|
-
lien := lk.GetLien(ctx, addr)
|
|
245
|
-
if lien.Coins.IsZero() {
|
|
246
|
-
// don't wrap unless there is a lien
|
|
247
|
-
return acc
|
|
248
|
-
}
|
|
249
|
-
lienAcc := LienAccount{
|
|
250
|
-
lienKeeper: lk,
|
|
251
|
-
lien: lien,
|
|
252
|
-
}
|
|
253
|
-
vestingAcc, ok := omni.(omniVestingAccount)
|
|
254
|
-
if !ok {
|
|
255
|
-
// Make non-vesting accounts appear to be vesting
|
|
256
|
-
// (need to give a pointer to the Lien - this is why the LienAccount
|
|
257
|
-
// holding it is created first).
|
|
258
|
-
vestingAcc = unlockedVestingAccount{omniAccount: omni, lien: &lienAcc.lien}
|
|
259
|
-
}
|
|
260
|
-
grantAcc, ok := vestingAcc.(omniGrantAccount)
|
|
261
|
-
if !ok {
|
|
262
|
-
// Make other vesting accounts appear to be GrantAccounts.
|
|
263
|
-
grantAcc = fakeGrantAccount{omniVestingAccount: vestingAcc}
|
|
264
|
-
}
|
|
265
|
-
clawbackAcc, ok := grantAcc.(omniClawbackAccount)
|
|
266
|
-
if !ok {
|
|
267
|
-
// Make GrantAccounts appear to be ClawbackAccounts.
|
|
268
|
-
clawbackAcc = fakeClawbackAccount{omniGrantAccount: grantAcc}
|
|
269
|
-
}
|
|
270
|
-
lienAcc.omniClawbackAccount = clawbackAcc
|
|
271
|
-
return &lienAcc
|
|
272
|
-
},
|
|
273
|
-
Unwrap: func(ctx sdk.Context, acc authtypes.AccountI) authtypes.AccountI {
|
|
274
|
-
if la, ok := acc.(*LienAccount); ok {
|
|
275
|
-
lk.SetLien(ctx, la.GetAddress(), la.lien)
|
|
276
|
-
acc = la.omniClawbackAccount
|
|
277
|
-
}
|
|
278
|
-
if fca, ok := acc.(fakeClawbackAccount); ok {
|
|
279
|
-
acc = fca.omniGrantAccount
|
|
280
|
-
}
|
|
281
|
-
if fga, ok := acc.(fakeGrantAccount); ok {
|
|
282
|
-
acc = fga.omniVestingAccount
|
|
283
|
-
}
|
|
284
|
-
if uva, ok := acc.(unlockedVestingAccount); ok {
|
|
285
|
-
acc = uva.omniAccount
|
|
286
|
-
}
|
|
287
|
-
return acc
|
|
288
|
-
},
|
|
289
|
-
}
|
|
290
|
-
}
|
package/x/lien/keeper/keeper.go
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
package keeper
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"math"
|
|
6
|
-
|
|
7
|
-
"github.com/Agoric/agoric-sdk/golang/cosmos/x/lien/types"
|
|
8
|
-
|
|
9
|
-
"github.com/cosmos/cosmos-sdk/codec"
|
|
10
|
-
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
|
11
|
-
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
12
|
-
vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
|
|
13
|
-
stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
14
|
-
|
|
15
|
-
vm "github.com/Agoric/agoric-sdk/golang/cosmos/vm"
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
type Keeper interface {
|
|
19
|
-
GetAccountWrapper() types.AccountWrapper
|
|
20
|
-
GetLien(ctx sdk.Context, addr sdk.AccAddress) types.Lien
|
|
21
|
-
SetLien(ctx sdk.Context, addr sdk.AccAddress, lien types.Lien)
|
|
22
|
-
IterateLiens(ctx sdk.Context, cb func(addr sdk.AccAddress, lien types.Lien) bool)
|
|
23
|
-
ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdk.Int) (sdk.Int, error)
|
|
24
|
-
GetAccountState(ctx sdk.Context, addr sdk.AccAddress) types.AccountState
|
|
25
|
-
BondDenom(ctx sdk.Context) string
|
|
26
|
-
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
|
|
27
|
-
GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) []stakingTypes.Delegation
|
|
28
|
-
GetValidator(ctx sdk.Context, valAddr sdk.ValAddress) (stakingTypes.Validator, bool)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// keeperImpl implements the lien keeper.
|
|
32
|
-
// The accountKeeper field must be the same one that the bankKeeper and
|
|
33
|
-
// stakingKeeper use.
|
|
34
|
-
type keeperImpl struct {
|
|
35
|
-
key storetypes.StoreKey
|
|
36
|
-
cdc codec.Codec
|
|
37
|
-
|
|
38
|
-
accountKeeper *types.WrappedAccountKeeper
|
|
39
|
-
bankKeeper types.BankKeeper
|
|
40
|
-
stakingKeeper types.StakingKeeper
|
|
41
|
-
|
|
42
|
-
pushAction vm.ActionPusher
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// NewKeeper returns a new Keeper.
|
|
46
|
-
// The ak must be the same accout keeper that the bk and sk use.
|
|
47
|
-
func NewKeeper(cdc codec.Codec, key storetypes.StoreKey, ak *types.WrappedAccountKeeper, bk types.BankKeeper, sk types.StakingKeeper,
|
|
48
|
-
pushAction vm.ActionPusher) Keeper {
|
|
49
|
-
return keeperImpl{
|
|
50
|
-
key: key,
|
|
51
|
-
cdc: cdc,
|
|
52
|
-
accountKeeper: ak,
|
|
53
|
-
bankKeeper: bk,
|
|
54
|
-
stakingKeeper: sk,
|
|
55
|
-
pushAction: pushAction,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// GetAccountWrapper returns an AccountWrapper that wrap/unwrap accounts
|
|
60
|
-
// with lienAccount specifying this keeper.
|
|
61
|
-
func (lk keeperImpl) GetAccountWrapper() types.AccountWrapper {
|
|
62
|
-
return NewAccountWrapper(lk)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// GetLien returns the lien stored for an account.
|
|
66
|
-
// Defaults to a lien of zero.
|
|
67
|
-
func (lk keeperImpl) GetLien(ctx sdk.Context, addr sdk.AccAddress) types.Lien {
|
|
68
|
-
store := ctx.KVStore(lk.key)
|
|
69
|
-
bz := store.Get(types.LienByAddressKey(addr))
|
|
70
|
-
if bz == nil {
|
|
71
|
-
return types.Lien{}
|
|
72
|
-
}
|
|
73
|
-
var lien types.Lien
|
|
74
|
-
lk.cdc.MustUnmarshal(bz, &lien)
|
|
75
|
-
return lien
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// SetLien sets the lien stored for an account.
|
|
79
|
-
// Deletes the entry if the new lien is zero.
|
|
80
|
-
func (lk keeperImpl) SetLien(ctx sdk.Context, addr sdk.AccAddress, lien types.Lien) {
|
|
81
|
-
store := ctx.KVStore(lk.key)
|
|
82
|
-
key := types.LienByAddressKey(addr)
|
|
83
|
-
if lien.Coins.IsZero() {
|
|
84
|
-
store.Delete(key)
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
bz := lk.cdc.MustMarshal(&lien)
|
|
88
|
-
store.Set(key, bz)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// IterateLiens calls cb() on all nonzero liens in the store.
|
|
92
|
-
// Stops early if cb() returns true.
|
|
93
|
-
func (lk keeperImpl) IterateLiens(ctx sdk.Context, cb func(addr sdk.AccAddress, lien types.Lien) bool) {
|
|
94
|
-
store := ctx.KVStore(lk.key)
|
|
95
|
-
iterator := store.Iterator(nil, nil)
|
|
96
|
-
defer iterator.Close()
|
|
97
|
-
for ; iterator.Valid(); iterator.Next() {
|
|
98
|
-
addr := types.LienByAddressDecodeKey(iterator.Key())
|
|
99
|
-
var lien types.Lien
|
|
100
|
-
lk.cdc.MustUnmarshal(iterator.Value(), &lien)
|
|
101
|
-
if cb(addr, lien) {
|
|
102
|
-
break
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// ChangeLien changes the liened amount of a single denomination in the given account.
|
|
108
|
-
// Either the old or new amount of the denomination can be zero.
|
|
109
|
-
// Liens can always be decreased, but to increase a lien, the new total amount must
|
|
110
|
-
// be vested and either bonded (for the staking token) or in the bank (for other tokens).
|
|
111
|
-
// The total lien can have several different denominations. Each is adjusted
|
|
112
|
-
// independently.
|
|
113
|
-
//
|
|
114
|
-
// The delta is given as a raw Int instead of a Coin since it may be negative.
|
|
115
|
-
func (lk keeperImpl) ChangeLien(ctx sdk.Context, addr sdk.AccAddress, denom string, delta sdk.Int) (sdk.Int, error) {
|
|
116
|
-
oldLien := lk.GetLien(ctx, addr)
|
|
117
|
-
oldCoins := oldLien.Coins
|
|
118
|
-
oldAmt := oldCoins.AmountOf(denom)
|
|
119
|
-
if delta.IsZero() {
|
|
120
|
-
// no-op, no need to do anything
|
|
121
|
-
return oldAmt, nil
|
|
122
|
-
}
|
|
123
|
-
newAmt := oldAmt.Add(delta)
|
|
124
|
-
if newAmt.IsNegative() {
|
|
125
|
-
return oldAmt, fmt.Errorf("lien delta of %s is larger than existing balance %s", delta, oldAmt)
|
|
126
|
-
}
|
|
127
|
-
newCoin := sdk.NewCoin(denom, newAmt)
|
|
128
|
-
newCoins := oldCoins.Sub(sdk.NewCoins(sdk.NewCoin(denom, oldAmt))...).Add(newCoin)
|
|
129
|
-
newLien := types.Lien{
|
|
130
|
-
Coins: newCoins,
|
|
131
|
-
Delegated: oldLien.Delegated,
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if delta.IsPositive() {
|
|
135
|
-
// See if it's okay to increase the lien.
|
|
136
|
-
// Lien can be increased if the new amount is vested,
|
|
137
|
-
// not already liened, and if it's the bond denom,
|
|
138
|
-
// must be staked.
|
|
139
|
-
state := lk.GetAccountState(ctx, addr)
|
|
140
|
-
if denom == lk.BondDenom(ctx) {
|
|
141
|
-
bonded := state.Bonded.AmountOf(denom)
|
|
142
|
-
unvested := state.Unvested.AmountOf(denom)
|
|
143
|
-
if !newAmt.Add(unvested).LTE(bonded) {
|
|
144
|
-
return oldAmt, fmt.Errorf("want to lien %s but only %s vested and bonded", newCoin, bonded.Sub(unvested))
|
|
145
|
-
}
|
|
146
|
-
newDelegated := bonded.Add(state.Unbonding.AmountOf(denom))
|
|
147
|
-
newLien.Delegated = sdk.NewCoins(sdk.NewCoin(denom, newDelegated))
|
|
148
|
-
} else {
|
|
149
|
-
inBank := lk.bankKeeper.GetBalance(ctx, addr, denom)
|
|
150
|
-
if !newAmt.LTE(inBank.Amount) {
|
|
151
|
-
return oldAmt, fmt.Errorf("want to lien %s but only %s available", newCoin, inBank)
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
lk.SetLien(ctx, addr, newLien)
|
|
156
|
-
return newAmt, nil
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// GetAccountState retrieves the AccountState for addr.
|
|
160
|
-
func (lk keeperImpl) GetAccountState(ctx sdk.Context, addr sdk.AccAddress) types.AccountState {
|
|
161
|
-
bonded := lk.getBonded(ctx, addr)
|
|
162
|
-
unbonding := lk.getUnbonding(ctx, addr)
|
|
163
|
-
locked, unvested := lk.getLockedUnvested(ctx, addr)
|
|
164
|
-
liened := lk.GetLien(ctx, addr).Coins
|
|
165
|
-
total := lk.bankKeeper.GetAllBalances(ctx, addr).Add(bonded...).Add(unbonding...)
|
|
166
|
-
return types.AccountState{
|
|
167
|
-
Total: total,
|
|
168
|
-
Bonded: bonded,
|
|
169
|
-
Unbonding: unbonding,
|
|
170
|
-
Locked: locked,
|
|
171
|
-
Liened: liened,
|
|
172
|
-
Unvested: unvested,
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// getBonded returns the bonded tokens delegated by addr.
|
|
177
|
-
func (lk keeperImpl) getBonded(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
178
|
-
bonded := sdk.NewCoins()
|
|
179
|
-
delegations := lk.stakingKeeper.GetDelegatorDelegations(ctx, addr, math.MaxUint16)
|
|
180
|
-
for _, d := range delegations {
|
|
181
|
-
validatorAddr, err := sdk.ValAddressFromBech32(d.ValidatorAddress)
|
|
182
|
-
if err != nil {
|
|
183
|
-
panic(err)
|
|
184
|
-
}
|
|
185
|
-
validator, found := lk.stakingKeeper.GetValidator(ctx, validatorAddr)
|
|
186
|
-
if !found {
|
|
187
|
-
panic("validator not found")
|
|
188
|
-
}
|
|
189
|
-
shares := d.GetShares()
|
|
190
|
-
tokens := validator.TokensFromShares(shares)
|
|
191
|
-
bonded = bonded.Add(sdk.NewCoin(lk.stakingKeeper.BondDenom(ctx), tokens.RoundInt())) // XXX rounding?
|
|
192
|
-
}
|
|
193
|
-
return bonded
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// getUnbonding returns the unbonding tokens delegated by addr.
|
|
197
|
-
func (lk keeperImpl) getUnbonding(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
198
|
-
unbonding := sdk.NewCoins()
|
|
199
|
-
unbondings := lk.stakingKeeper.GetUnbondingDelegations(ctx, addr, math.MaxUint16)
|
|
200
|
-
for _, u := range unbondings {
|
|
201
|
-
amt := sdk.NewInt(0)
|
|
202
|
-
for _, e := range u.Entries {
|
|
203
|
-
amt = amt.Add(e.Balance)
|
|
204
|
-
}
|
|
205
|
-
unbonding = unbonding.Add(sdk.NewCoin(lk.stakingKeeper.BondDenom(ctx), amt))
|
|
206
|
-
}
|
|
207
|
-
return unbonding
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// getLocked returns the number of locked tokens in account addr.
|
|
211
|
-
// This reflects the VestingCoins in the underlying VestingAccount,
|
|
212
|
-
// if any, not the LienAccount wrapping it.
|
|
213
|
-
func (lk keeperImpl) getLockedUnvested(ctx sdk.Context, addr sdk.AccAddress) (sdk.Coins, sdk.Coins) {
|
|
214
|
-
account := lk.accountKeeper.GetAccount(ctx, addr)
|
|
215
|
-
if account == nil {
|
|
216
|
-
// account doesn't exist
|
|
217
|
-
return sdk.NewCoins(), sdk.NewCoins()
|
|
218
|
-
}
|
|
219
|
-
if lienAccount, ok := account.(LienAccount); ok {
|
|
220
|
-
// unwrap the lien wrapper
|
|
221
|
-
account = lienAccount.omniClawbackAccount
|
|
222
|
-
}
|
|
223
|
-
if clawbackAccount, ok := account.(vestexported.ClawbackVestingAccountI); ok {
|
|
224
|
-
original := clawbackAccount.GetOriginalVesting()
|
|
225
|
-
unlocked := clawbackAccount.GetUnlockedOnly(ctx.BlockTime())
|
|
226
|
-
vested := clawbackAccount.GetVestedOnly(ctx.BlockTime())
|
|
227
|
-
return original.Sub(unlocked...), original.Sub(vested...)
|
|
228
|
-
}
|
|
229
|
-
if vestingAccount, ok := account.(vestexported.VestingAccount); ok {
|
|
230
|
-
return vestingAccount.GetVestingCoins(ctx.BlockTime()), sdk.NewCoins()
|
|
231
|
-
}
|
|
232
|
-
return sdk.NewCoins(), sdk.NewCoins()
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// The following methods simply proxy the eponymous staking keeper queries.
|
|
236
|
-
|
|
237
|
-
// BondDenom returns the denom used for staking.
|
|
238
|
-
func (lk keeperImpl) BondDenom(ctx sdk.Context) string {
|
|
239
|
-
return lk.stakingKeeper.BondDenom(ctx)
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
func (lk keeperImpl) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
|
|
243
|
-
return lk.bankKeeper.GetAllBalances(ctx, addr)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// GetDelegatorDelegations returns the delegator's delegations.
|
|
247
|
-
// Returns up to the specified number of delegations.
|
|
248
|
-
func (lk keeperImpl) GetDelegatorDelegations(ctx sdk.Context, delegator sdk.AccAddress, maxRetrieve uint16) []stakingTypes.Delegation {
|
|
249
|
-
return lk.stakingKeeper.GetDelegatorDelegations(ctx, delegator, maxRetrieve)
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// GetValidator returns the named validator, if found.
|
|
253
|
-
func (lk keeperImpl) GetValidator(ctx sdk.Context, valAddr sdk.ValAddress) (stakingTypes.Validator, bool) {
|
|
254
|
-
return lk.stakingKeeper.GetValidator(ctx, valAddr)
|
|
255
|
-
}
|