Skip to content

Commit

Permalink
feat: add ability to decommission the validator by burning the
Browse files Browse the repository at this point in the history
init token
  • Loading branch information
MicroProofs committed Dec 20, 2023
1 parent ef6c761 commit d182732
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions validators/stakinator3000.ak
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,36 @@ validator(init_input: OutputReference) {
Or(conds) ->
validate_stake_conditions(conds, False, tx_condition_runner)
}
// find output with same address and nft state token
expect Some(Output { datum: InlineDatum(out_datum), .. }) =
list.find(
outputs,
fn(output) {
output.address == in_address && quantity_of(
output.value,
own_policy,
"",
) == 1
},
)

// Ensure output stake registration shows right time.
expect State { stake_registration, .. }: State = out_datum

// Confusing enough we get milliseconds from the node instead of slot time. So time is in milliseconds
let time_range = ( upper - lower ) / 2 / 1000
// I'm converting to seconds for simplicity
stake_registration == lower + time_range && time_range >= 180

or {
// This allows you to decommission the validator
mint
|> from_minted_value
|> quantity_of(own_policy, "")
|> fn(a) { a == -1 },
// find output with same address and nft state token
{
expect Some(Output { datum: InlineDatum(out_datum), .. }) =
list.find(
outputs,
fn(output) {
output.address == in_address && quantity_of(
output.value,
own_policy,
"",
) == 1
},
)

// Ensure output stake registration shows right time.
expect State { stake_registration, .. }: State = out_datum

// Confusing enough we get milliseconds from the node instead of slot time. So time is in milliseconds
let time_range = ( upper - lower ) / 2000
// I'm converting to seconds for simplicity
stake_registration == lower + time_range && time_range >= 180
},
}
}

fn conditional_multi(rdr: Data, ctx: ScriptContext) -> Bool {
Expand Down

0 comments on commit d182732

Please sign in to comment.