Skip to content

Commit 5beeeec

Browse files
committed
remove redundant compound flag
1 parent 3f90eb0 commit 5beeeec

3 files changed

Lines changed: 131 additions & 167 deletions

File tree

ex/native/rdb/src/consensus/bic/lockup_vault.rs

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub struct Vault {
5656
pub rate_bps: u64,
5757
pub created_epoch: u64,
5858
pub mature_epoch: u64,
59-
pub compound: bool,
6059
pub payout_address: Option<Vec<u8>>,
6160
pub validator: Option<Vec<u8>>,
6261
pub validator_pending: Option<Vec<u8>>,
@@ -66,11 +65,10 @@ pub struct Vault {
6665
}
6766

6867
impl Vault {
69-
//yield accrues into the vault unless a payout address is set. create/set_compound/
70-
//set_payout_address enforce that compound and a payout address never coexist; the
71-
//compound check remains as defense for any pre-invariant state.
68+
//the payout address alone decides yield routing: unset, yield accrues (compounds)
69+
//into the vault; set, it distributes there
7270
pub fn accrues_to_vault(&self) -> bool {
73-
self.compound || self.payout_address.is_none()
71+
self.payout_address.is_none()
7472
}
7573

7674
//validator changes (set or clear) queue for VALIDATOR_CHANGE_QUEUE_EPOCHS;
@@ -107,7 +105,6 @@ impl Vault {
107105
(Term::Binary(b"rate_bps".to_vec()), Term::VarInt(self.rate_bps as i128)),
108106
(Term::Binary(b"created_epoch".to_vec()), Term::VarInt(self.created_epoch as i128)),
109107
(Term::Binary(b"mature_epoch".to_vec()), Term::VarInt(self.mature_epoch as i128)),
110-
(Term::Binary(b"compound".to_vec()), Term::Bool(self.compound)),
111108
(Term::Binary(b"payout_address".to_vec()), opt_bin(&self.payout_address)),
112109
(Term::Binary(b"validator".to_vec()), opt_bin(&self.validator)),
113110
(Term::Binary(b"validator_pending".to_vec()), opt_bin(&self.validator_pending)),
@@ -153,10 +150,6 @@ impl Vault {
153150
rate_bps: uint(b"rate_bps"),
154151
created_epoch: uint(b"created_epoch"),
155152
mature_epoch: uint(b"mature_epoch"),
156-
compound: match get(b"compound") {
157-
Term::Bool(b) => *b,
158-
_ => panic_any("invalid_vault_data"),
159-
},
160153
payout_address: match get(b"payout_address") {
161154
Term::Nil() => None,
162155
Term::Binary(b) => Some(b.clone()),
@@ -212,9 +205,9 @@ pub fn vaults_by_owner(env: &mut ApplyEnv, owner: &[u8]) -> Vec<(Vec<u8>, Vault)
212205
//promotion has already run (promote_pending_validators is first in epoch::next2),
213206
//so this reads vault.validator directly. unlocking vaults still earn (they keep
214207
//backing their validator until withdrawn). yield is due on amount+accrued —
215-
//everything locked in the vault earns, regardless of compound history. payouts
216-
//route per accrues_to_vault: to the payout address if one is set, else accruing
217-
//into the vault. reduction_pct scales payouts (100 = full). pays at most budget,
208+
//everything locked in the vault earns. payouts route per accrues_to_vault: to the
209+
//payout address if one is set, else compounding into the vault.
210+
//reduction_pct scales payouts (100 = full). pays at most budget,
218211
//pro rata if the dues exceed it. returns the total paid, which draws down the
219212
//budget; the caller handles the network tax and accrued-pool accounting.
220213
pub fn pay_epoch_yield(env: &mut ApplyEnv, validators: &HashSet<Vec<u8>>, reduction_pct: u64, budget: i128) -> i128 {
@@ -400,15 +393,15 @@ impl ArgMap {
400393
}
401394
}
402395

403-
const CREATE_KEYS: &[&[u8]] = &[b"amount", b"tier", b"compound", b"validator", b"payout_address", b"owner", b"unlock_epoch", b"months"];
396+
const CREATE_KEYS: &[&[u8]] = &[b"amount", b"tier", b"validator", b"payout_address", b"owner", b"unlock_epoch", b"months"];
404397

405398
//args: a single vecpak map (tag 7) with keys:
406399
// amount (int, required)
407400
// tier (bin, required) — "og" | "3m" | "6m" | "12m"
408-
// compound (bool, required)
409401
// validator (bin pk, optional) — enters the 2-epoch validator queue, same
410402
// as a later set_validator (not live until it posts)
411-
// payout_address (bin pk, optional)
403+
// payout_address (bin pk, optional) — where yield distributes; when unset, yield
404+
// accrues (compounds) into the vault
412405
// owner (bin pk, optional) — who the vault is keyed under and controlled
413406
// by; defaults to the caller. lets a treasury fund a vault held by
414407
// a beneficiary. the caller is always the one debited.
@@ -421,10 +414,6 @@ pub fn call_create(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
421414

422415
let amount = map.require_int(b"amount", "invalid_amount");
423416
let tier = map.require_bin(b"tier", "invalid_vault_type");
424-
let compound = map.require_bool(b"compound", "invalid_compound");
425-
if compound && map.get(b"payout_address").is_some() {
426-
panic_any("payout_not_allowed_with_compound")
427-
}
428417
let (rate_bps, tier_duration) = tier_params(&tier, env.caller_env.entry_epoch);
429418
let duration_epochs = match map.opt_int(b"months", "invalid_months") {
430419
Some(_) if tier.as_slice() != b"og" => panic_any("months_not_allowed"),
@@ -491,7 +480,6 @@ pub fn call_create(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
491480
rate_bps,
492481
created_epoch: entry_epoch,
493482
mature_epoch,
494-
compound,
495483
payout_address,
496484
validator: None,
497485
validator_pending: validator,
@@ -540,25 +528,6 @@ pub fn call_withdraw(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
540528
kv_delete(env, &key);
541529
}
542530

543-
pub fn call_set_compound(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
544-
if args.len() != 2 {
545-
panic_any("invalid_args")
546-
}
547-
let (key, mut vault) = load_caller_vault(env, &args[0]);
548-
if vault.unlock_start_epoch.is_some() {
549-
panic_any("vault_is_unlocking")
550-
}
551-
vault.compound = match args[1].as_slice() {
552-
b"true" => true,
553-
b"false" => false,
554-
_ => panic_any("invalid_compound"),
555-
};
556-
if vault.compound {
557-
vault.payout_address = None;
558-
}
559-
store_vault(env, &key, &vault);
560-
}
561-
562531
pub fn call_set_payout_address(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
563532
if args.len() != 2 {
564533
panic_any("invalid_args")
@@ -567,9 +536,6 @@ pub fn call_set_payout_address(env: &mut ApplyEnv, args: Vec<Vec<u8>>) {
567536
if vault.unlock_start_epoch.is_some() {
568537
panic_any("vault_is_unlocking")
569538
}
570-
if vault.compound {
571-
panic_any("payout_not_allowed_with_compound")
572-
}
573539
validate_pk(&args[1], "invalid_payout_pk");
574540
init_balance_if_missing(env, &args[1]);
575541
vault.payout_address = Some(args[1].to_vec());

ex/native/rdb/src/consensus/consensus_apply.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ pub fn call_bic(
930930
(b"LockupVault", b"create") => return consensus::bic::lockup_vault::call_create(env, args),
931931
(b"LockupVault", b"unlock") => return consensus::bic::lockup_vault::call_unlock(env, args),
932932
(b"LockupVault", b"withdraw") => return consensus::bic::lockup_vault::call_withdraw(env, args),
933-
(b"LockupVault", b"set_compound") => return consensus::bic::lockup_vault::call_set_compound(env, args),
934933
(b"LockupVault", b"set_payout_address") => return consensus::bic::lockup_vault::call_set_payout_address(env, args),
935934
(b"LockupVault", b"clear_payout_address") => return consensus::bic::lockup_vault::call_clear_payout_address(env, args),
936935
(b"LockupVault", b"set_validator") => return consensus::bic::lockup_vault::call_set_validator(env, args),

0 commit comments

Comments
 (0)