Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aiken.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ requirements = []
source = "github"

[etags]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1757410953, nanos_since_epoch = 792061707 }, "9843473958e51725a9274b487d2d4aac0395ec1a2e30f090724fa737226bc127"]
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1758102049, nanos_since_epoch = 210673971 }, "9843473958e51725a9274b487d2d4aac0395ec1a2e30f090724fa737226bc127"]
26 changes: 18 additions & 8 deletions lib/tests/examples/ex_settings.ak
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ pub fn mk_valid_settings_datum(scoopers: List<ByteArray>) -> SettingsDatum {
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
pool_creation_fee: 0,
extensions: ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (0, 0),
next: Void,
},
extensions: [
Pair(
0,
as_data(
ProtocolFeeBasisPointsExtension { protocol_fee_basis_points: (0, 0) },
),
),
],
}
}

Expand Down Expand Up @@ -207,10 +211,16 @@ test example_mainnet_boot_settings_datum() {
simple_fee: 168_000,
strategy_fee: 168_000,
pool_creation_fee: 0,
extensions: ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (30, 30),
next: Void,
},
extensions: [
Pair(
0,
as_data(
ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (0, 0),
},
),
),
],
},
)
}
18 changes: 15 additions & 3 deletions lib/types/settings.ak
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use aiken/builtin
use aiken/collection/dict
use aiken/collection/pairs
use aiken/crypto.{VerificationKey}
use cardano/address.{Address, Credential}
use cardano/assets.{AssetName, PolicyId}
Expand Down Expand Up @@ -67,14 +68,12 @@ pub type SettingsDatum {
/// - publish data for convenient and canonical access by off-chain actors
/// - expose data to the script conditions in the multisig scripts of the two administrator roles
/// - expose additional settings for more advanced pool and order types to operate off of
extensions: ProtocolFeeBasisPointsExtension,
extensions: Pairs<Int, Data>,
}

pub type ProtocolFeeBasisPointsExtension {
/// The default protocol fee basis points to charge on each trade for bid (A -> B) and ask (B -> A) orders, for pools that don't override it
protocol_fee_basis_points: (Int, Int),
/// Pointing to next extension in the future
next: Data,
}

/// The settings redeemer can be spent for two different purposes
Expand All @@ -88,6 +87,19 @@ pub type SettingsRedeemer {
/// The name of the token that authenticates the settings UTXO
pub const settings_nft_name: AssetName = "settings"

pub fn find_protocol_fee_extension(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the first thing we do is fail when this isn't set (via expect Some(...)), we could probably just name this must_find_protocol_fee_extension and simplify the code.

but it's not a major deal.

settings: SettingsDatum,
) -> Option<ProtocolFeeBasisPointsExtension> {
let maybe_extension = pairs.get_first(settings.extensions, 0)
when maybe_extension is {
Some(extension_data) -> {
expect extension: ProtocolFeeBasisPointsExtension = extension_data
Some(extension)
}
None -> None
}
}

/// Scan over the list of reference inputs to find the settings datum, and ensure it's the correct one
/// Note that this makes the assumption that the settings datum is the first reference input, for performance
/// This means that when storing reference scripts on-chain, there needs to be a small amount of "farming" to select
Expand Down
10 changes: 8 additions & 2 deletions validators/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use types/pool.{
MintLP, PoolMintRedeemer, PoolRedeemer, PoolScoop, StablePoolDatum,
UpdatePoolFees, WithdrawFees,
} as types_pool
use types/settings.{SettingsDatum, find_settings_datum}
use types/settings.{
ProtocolFeeBasisPointsExtension, SettingsDatum, find_protocol_fee_extension,
find_settings_datum,
}

/// An implementation of a curve-like "Stableswap" invariant that enables more efficient trades for stablecoin pairs.
///
Expand Down Expand Up @@ -518,6 +521,9 @@ validator pool(
// and potentially even on access UIs for the Sundae protocol
expect metadata_output.datum == InlineDatum(Void)

expect Some(protocol_fee_extension) =
find_protocol_fee_extension(settings_datum)

// And check that the datum is initialized correctly; This is part of why we have a minting policy handling this,
// as it allows us to authenticate the providence of the datum.
// A datum is valid so long as
Expand All @@ -541,7 +547,7 @@ validator pool(
shared.fees_in_legal_range(
pool_output_datum.protocol_fee_basis_points.2nd,
),
settings_datum.extensions.protocol_fee_basis_points == pool_output_datum.protocol_fee_basis_points,
protocol_fee_extension.protocol_fee_basis_points == pool_output_datum.protocol_fee_basis_points,
pool_output_datum.linear_amplification > 0,
liquidity_invariant(
reserve_a * calc_precision,
Expand Down
7 changes: 2 additions & 5 deletions validators/tests/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use types/pool.{
UpdatePoolFees, WithdrawFees,
}
use types/settings.{
ProtocolFeeBasisPointsExtension, SettingsDatum, settings_nft_name,
SettingsDatum, settings_nft_name,
}

type ScoopTestOptions {
Expand Down Expand Up @@ -383,10 +383,7 @@ test scooper_not_in_settings() fail {
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
pool_creation_fee: 0,
extensions: ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (0, 0),
next: Void,
},
extensions: [],
},
),
),
Expand Down
7 changes: 2 additions & 5 deletions validators/tests/pool.manage.ak
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sundae/multisig.{MultisigScript}
use tests/constants
use tests/examples/ex_settings.{mk_valid_settings_input}
use types/pool.{ManageRedeemer, StablePoolDatum}
use types/settings.{ProtocolFeeBasisPointsExtension, SettingsDatum}
use types/settings.{SettingsDatum}

const settings_policy_id: PolicyId =
#"00000000000000000000000000000000000000000000000000000000"
Expand Down Expand Up @@ -388,10 +388,7 @@ fn scenario_settings_input_baseline(
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
pool_creation_fee: 0,
extensions: ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (0, 0),
next: Void,
},
extensions: [],
}
},
)
Expand Down
10 changes: 2 additions & 8 deletions validators/tests/settings.ak
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ use tx_util/builder.{
add_asset_to_tx_output, add_tx_input, add_tx_output, build_txn_context,
mint_assets, new_tx_input, new_tx_output, with_asset_of_tx_input,
}
use types/settings.{
ProtocolFeeBasisPointsExtension, SettingsAdminUpdate, SettingsDatum,
settings_nft_name,
}
use types/settings.{SettingsAdminUpdate, SettingsDatum, settings_nft_name}

fn test_mint_settings(settings_nfts_count: Int) {
let settings_nft =
Expand Down Expand Up @@ -95,10 +92,7 @@ fn mk_valid_settings_datum(scoopers: List<ByteArray>) -> SettingsDatum {
simple_fee: 2_500_000,
strategy_fee: 5_000_000,
pool_creation_fee: 0,
extensions: ProtocolFeeBasisPointsExtension {
protocol_fee_basis_points: (0, 0),
next: Void,
},
extensions: [],
}
}

Expand Down