-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: withdrawReward on StakingAccountHolder (#9307)
refs: #9071 I'm not confident this closes #9071; see that issue for questions about scope. ## Description Adds `WithdrawReward` on `invitationMakers` of `StakingAccountHolder`, following the pattern set by `Delegate`. ### Security Considerations I'm a bit uneasy about lack of guards for the helper facet (`helper: UnguardedHelperI`). It seems to impose a non-local review burden: we have to be sure every call to the helper facet passes only args that have already been guarded. I tripped on it, once: I passed the wrong type of thing to a helper method and didn't get a helpful guard violation message. ### Scaling Considerations While proportionally, the amount of work done doesn't outgrow the message size (presuming an IBC transaction is O(1)), in absolute terms, it seems unlikely that the fee for a `WithdrawReward` `MsgSpendAction` compensates for the cost of the IBC transaction. ### Documentation Considerations It's not entirely clear to me what the status of `StakingAccountHolder` is. Is it an example? If so, maybe this is `docs` rather than `feat`? ### Testing Considerations Based on internal discussions, the tests here are unit tests that mock the rest of the system. ### Upgrade Considerations This presumably gets deployed with the rest of orchestration in an upcoming chain-halting upgrade.
- Loading branch information
Showing
5 changed files
with
429 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// @ts-check | ||
import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; | ||
|
||
import { | ||
MsgWithdrawDelegatorReward, | ||
MsgWithdrawDelegatorRewardResponse, | ||
} from '@agoric/cosmic-proto/cosmos/distribution/v1beta1/tx.js'; | ||
import { MsgDelegateResponse } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; | ||
import { Any } from '@agoric/cosmic-proto/google/protobuf/any.js'; | ||
import { decodeBase64, encodeBase64 } from '@endo/base64'; | ||
import { tryDecodeResponse } from '../src/exos/stakingAccountKit.js'; | ||
|
||
const test = anyTest; | ||
|
||
const scenario1 = { | ||
acct1: { | ||
address: 'agoric1spy36ltduehs5dmszfrp792f0k2emcntrql3nx', | ||
}, | ||
validator: { address: 'agoric1valoper234', addressEncoding: 'bech32' }, | ||
delegations: { | ||
agoric1valoper234: { denom: 'uatom', amount: '200' }, | ||
}, | ||
}; | ||
|
||
test('MsgWithdrawDelegatorReward: protobuf encoding reminder', t => { | ||
const actual = MsgWithdrawDelegatorReward.toProtoMsg({ | ||
delegatorAddress: 'abc', | ||
validatorAddress: 'def', | ||
}); | ||
|
||
const abc = [0x03, 0x61, 0x62, 0x63]; // wire type 3, a, b, c | ||
const def = [0x03, 0x64, 0x65, 0x66]; | ||
t.deepEqual(actual, { | ||
typeUrl: '/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward', | ||
value: Uint8Array.from([0x0a, ...abc, 0x12, ...def]), | ||
}); | ||
}); | ||
|
||
test('DelegateResponse decoding', t => { | ||
// executeEncodedTx() returns "acknowledge string" | ||
const ackStr = | ||
'Ei0KKy9jb3Ntb3Muc3Rha2luZy52MWJldGExLk1zZ0RlbGVnYXRlUmVzcG9uc2U='; | ||
// That's base64 protobuf of an Any | ||
const any = Any.decode(decodeBase64(ackStr)); | ||
|
||
t.like(any, { $typeUrl: '/google.protobuf.Any', typeUrl: '' }); | ||
t.true(any.value instanceof Uint8Array); | ||
|
||
/** @import {MsgDelegateResponseProtoMsg} from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; */ | ||
/** @type {MsgDelegateResponseProtoMsg} */ | ||
// @ts-expect-error we can tell this is the type from tye typeUrl | ||
const protoMsg = Any.decode(any.value); | ||
t.like(protoMsg, { | ||
$typeUrl: '/google.protobuf.Any', | ||
typeUrl: '/cosmos.staking.v1beta1.MsgDelegateResponse', | ||
}); | ||
t.true(protoMsg.value instanceof Uint8Array); | ||
|
||
const msgD = MsgDelegateResponse.fromProtoMsg(protoMsg); | ||
t.deepEqual(msgD, {}); | ||
}); | ||
|
||
test('tryDecodeResponse from withdraw', t => { | ||
const ackStr = | ||
'ElIKPy9jb3Ntb3MuZGlzdHJpYnV0aW9uLnYxYmV0YTEuTXNnV2l0aGR' + | ||
'yYXdEZWxlZ2F0b3JSZXdhcmRSZXNwb25zZRIPCg0KBnVzdGFrZRIDMjAw'; | ||
const msg = tryDecodeResponse( | ||
ackStr, | ||
MsgWithdrawDelegatorRewardResponse.fromProtoMsg, | ||
); | ||
t.deepEqual(msg, { amount: [{ amount: '200', denom: 'ustake' }] }); | ||
}); | ||
|
||
test('MsgWithdrawDelegatorRewardResponse encoding', t => { | ||
const { delegations } = scenario1; | ||
/** @type {MsgWithdrawDelegatorRewardResponse} */ | ||
const response = { amount: Object.values(delegations) }; | ||
const protoMsg = MsgWithdrawDelegatorRewardResponse.toProtoMsg(response); | ||
|
||
const typeUrl = | ||
'/cosmos.distribution.v1beta1.MsgWithdrawDelegatorRewardResponse'; | ||
t.like(protoMsg, { typeUrl }); | ||
t.true(protoMsg.value instanceof Uint8Array); | ||
|
||
const any1 = Any.fromPartial(protoMsg); | ||
const any2 = Any.fromPartial({ value: Any.encode(any1).finish() }); | ||
t.like(any2, { $typeUrl: '/google.protobuf.Any', typeUrl: '' }); | ||
t.true(any2.value instanceof Uint8Array); | ||
|
||
const ackStr = encodeBase64(Any.encode(any2).finish()); | ||
t.is(typeof ackStr, 'string'); | ||
t.is( | ||
ackStr, | ||
'ElEKPy9jb3Ntb3MuZGlzdHJpYnV0aW9uLnYxYmV0YTEuTXNnV2l0aGRy' + | ||
'YXdEZWxlZ2F0b3JSZXdhcmRSZXNwb25zZRIOCgwKBXVhdG9tEgMyMDA=', | ||
); | ||
}); |
Oops, something went wrong.