Skip to content

Commit

Permalink
Remove poolScriptHash from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 9, 2023
1 parent 44acecd commit 72af6e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 1 addition & 3 deletions lib/types/settings.ak
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use aiken/bytearray
use aiken/cbor
use aiken/hash.{Blake2b_224, Hash}
use aiken/transaction/credential.{Address, Script, VerificationKey, VerificationKeyCredential}
use aiken/transaction/credential.{Address, VerificationKey, VerificationKeyCredential}
use sundae/multisig.{MultisigScript}
use shared.{Rational}
use aiken/transaction.{
Expand All @@ -12,7 +11,6 @@ use aiken/transaction/value.{AssetName, PolicyId}
use aiken/dict

pub type SettingsDatum {
pool_script_hash: Hash<Blake2b_224, Script>,
settings_admin: MultisigScript, // Who can update the updatable settings?
metadata_admin: Address, // Who or what governs the evolution of CIP-68 token metadata
treasury_admin: MultisigScript, // Who can withdraw to the treasury and control delegation
Expand Down
27 changes: 13 additions & 14 deletions validators/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ validator(settings_policy_id: PolicyId) {
// Find the input being spent
let pool_input = spent_output(ctx)

expect ScriptCredential(pool_script_hash) = pool_input.address.payment_credential

// Find the pool output
expect Some(pool_output) = list.head(outputs)
expect pool_output.address == pool_input.address
Expand All @@ -136,7 +138,7 @@ validator(settings_policy_id: PolicyId) {
PoolScoop{ signatory_index, scooper_index, amortized_base_fee, input_order } -> {

// Deconstruct the settings datum with the fields we need for a scoop
let SettingsDatum { pool_script_hash, authorized_scoopers, base_fee, simple_fee, strategy_fee, .. } =
let SettingsDatum { authorized_scoopers, base_fee, simple_fee, strategy_fee, .. } =
settings_datum

// Construct the initial pool state from the datum and the locked values
Expand Down Expand Up @@ -272,6 +274,8 @@ validator(settings_policy_id: PolicyId) {
fn mint(r: PoolMintRedeemer, ctx: ScriptContext) {
when r is {
CreatePool(assets, pool_output_ix, metadata_output_ix) -> {
expect Mint(own_policy_id) = ctx.purpose

// The assets on the pool must be sorted
let (asset_a, asset_b) = assets
let coin_pair_ordering_is_canonical =
Expand Down Expand Up @@ -320,9 +324,9 @@ validator(settings_policy_id: PolicyId) {
expect Some(initial_lq) = math.sqrt(coin_a_amt_sans_rider * coin_b_amt)

// TODO: can we use own_script_hash here?
let new_pool_ref = (settings_datum.pool_script_hash, new_pool_ref_token)
let new_pool_nft = (settings_datum.pool_script_hash, new_pool_nft_token)
let new_pool_lq = (settings_datum.pool_script_hash, new_pool_lp_token)
let new_pool_ref = (own_policy_id, new_pool_ref_token)
let new_pool_nft = (own_policy_id, new_pool_nft_token)
let new_pool_lq = (own_policy_id, new_pool_lp_token)

let expected_mint =
shared.to_value((new_pool_ref.1st, new_pool_ref.2nd, 1))
Expand All @@ -337,7 +341,7 @@ validator(settings_policy_id: PolicyId) {
value.flatten(pool_output.value),
) <= 3 && value.quantity_of(
pool_output.value,
settings_datum.pool_script_hash,
own_policy_id,
new_pool_nft_token,
) == 1

Expand All @@ -346,7 +350,7 @@ validator(settings_policy_id: PolicyId) {
list.at(ctx.transaction.outputs, metadata_output_ix)
expect metadata_output.address == settings_datum.metadata_admin
// TODO: can we use own_script_hash here?
expect value.quantity_of(metadata_output.value, settings_datum.pool_script_hash, new_pool_ref_token) == 1
expect value.quantity_of(metadata_output.value, own_policy_id, new_pool_ref_token) == 1

expect InlineDatum(d) = pool_output.datum
expect pool_output_datum: PoolDatum = d
Expand Down Expand Up @@ -402,7 +406,6 @@ fn wallet_address(hash: ByteArray) -> Address {
}

fn mk_settings_input(
psh: ByteArray,
scoopers: List<ByteArray>,
ix: Int,
) -> Input {
Expand All @@ -412,7 +415,6 @@ fn mk_settings_input(
let settings_address = script_address(hash_of_settings_script)
let settings_datum =
SettingsDatum {
pool_script_hash: psh,
settings_admin: multisig.AnyOf([]),
metadata_admin: Address(
VerificationKeyCredential(
Expand Down Expand Up @@ -575,15 +577,12 @@ test output_missing_nft() fail {

test scooper_not_in_settings() fail {
let somebody = #"11111111111111111111111111111111111111111111111111111111"
let hash_of_pool_script =
#"00000000000000000000000000000000000000000000000000000000"
let options =
ScoopTestOptions {
..default_scoop_test_options(),
edit_settings_datum: Some(
InlineDatum(
SettingsDatum {
pool_script_hash: hash_of_pool_script,
settings_admin: multisig.AnyOf([]),
metadata_admin: Address(
VerificationKeyCredential(
Expand Down Expand Up @@ -699,7 +698,7 @@ fn scoop(options: ScoopTestOptions) {
}
let settings_input = {
let Input { output_reference, output } =
mk_settings_input(hash_of_pool_script, [scooper], 1)
mk_settings_input([scooper], 1)
let updated_output =
Output {
..output,
Expand Down Expand Up @@ -867,7 +866,7 @@ fn scoop_swap_deposit(options: ScoopTestOptions) {
},
}
let settings_input = {
let Input {output_reference, output} = mk_settings_input(hash_of_pool_script, [scooper], 1)
let Input {output_reference, output} = mk_settings_input([scooper], 1)
let updated_output = Output {
..output,
datum: option.or_else(options.edit_settings_datum, output.datum)
Expand Down Expand Up @@ -936,7 +935,7 @@ test mint_test() {
let rberry_token_name = #"524245525259"
let user_address =
wallet_address(#"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513")
let settings_input = mk_settings_input(hash_of_pool_script, [], 1)
let settings_input = mk_settings_input([], 1)
let funds_input = Input {
output_reference: OutputReference {
transaction_id: mk_tx_hash(0),
Expand Down
6 changes: 2 additions & 4 deletions validators/settings.ak
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ validator(protocol_boot_utxo: OutputReference) {

// Settings admin can change any datum fields except for these
let datum_updated_legally =
output_datum.pool_script_hash == d.pool_script_hash
&& output_datum.authorized_staking_keys == d.authorized_staking_keys
output_datum.authorized_staking_keys == d.authorized_staking_keys
&& output_datum.treasury_address == d.treasury_address
&& output_datum.treasury_allowance == d.treasury_allowance
// TODO: move base_fee, simple_fee, and strategy_fee to the treasury admin instead
Expand All @@ -65,8 +64,7 @@ validator(protocol_boot_utxo: OutputReference) {
// instead, we could construct an "allowed datum" from the fields that *are* allowed to change, with a spread from the old datum
// and compare that
let datum_updated_legally =
output_datum.pool_script_hash == d.pool_script_hash
&& output_datum.authorized_staking_keys == d.authorized_staking_keys
output_datum.authorized_staking_keys == d.authorized_staking_keys
&& output_datum.settings_admin == d.settings_admin
&& output_datum.metadata_admin == d.metadata_admin
&& output_datum.treasury_admin == d.treasury_admin
Expand Down

0 comments on commit 72af6e7

Please sign in to comment.