Skip to content

Commit 3091440

Browse files
committed
change extensions to Pairs<Int, Data>
1 parent c639373 commit 3091440

File tree

7 files changed

+48
-32
lines changed

7 files changed

+48
-32
lines changed

aiken.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ requirements = []
4646
source = "github"
4747

4848
[etags]
49-
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1757410953, nanos_since_epoch = 792061707 }, "9843473958e51725a9274b487d2d4aac0395ec1a2e30f090724fa737226bc127"]
49+
"aiken-lang/fuzz@main" = [{ secs_since_epoch = 1758102049, nanos_since_epoch = 210673971 }, "9843473958e51725a9274b487d2d4aac0395ec1a2e30f090724fa737226bc127"]

lib/tests/examples/ex_settings.ak

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ pub fn mk_valid_settings_datum(scoopers: List<ByteArray>) -> SettingsDatum {
3131
simple_fee: 2_500_000,
3232
strategy_fee: 5_000_000,
3333
pool_creation_fee: 0,
34-
extensions: ProtocolFeeBasisPointsExtension {
35-
protocol_fee_basis_points: (0, 0),
36-
next: Void,
37-
},
34+
extensions: [
35+
Pair(
36+
0,
37+
as_data(
38+
ProtocolFeeBasisPointsExtension { protocol_fee_basis_points: (0, 0) },
39+
),
40+
),
41+
],
3842
}
3943
}
4044

@@ -207,10 +211,16 @@ test example_mainnet_boot_settings_datum() {
207211
simple_fee: 168_000,
208212
strategy_fee: 168_000,
209213
pool_creation_fee: 0,
210-
extensions: ProtocolFeeBasisPointsExtension {
211-
protocol_fee_basis_points: (30, 30),
212-
next: Void,
213-
},
214+
extensions: [
215+
Pair(
216+
0,
217+
as_data(
218+
ProtocolFeeBasisPointsExtension {
219+
protocol_fee_basis_points: (0, 0),
220+
},
221+
),
222+
),
223+
],
214224
},
215225
)
216226
}

lib/types/settings.ak

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use aiken/builtin
22
use aiken/collection/dict
3+
use aiken/collection/pairs
34
use aiken/crypto.{VerificationKey}
45
use cardano/address.{Address, Credential}
56
use cardano/assets.{AssetName, PolicyId}
@@ -67,14 +68,12 @@ pub type SettingsDatum {
6768
/// - publish data for convenient and canonical access by off-chain actors
6869
/// - expose data to the script conditions in the multisig scripts of the two administrator roles
6970
/// - expose additional settings for more advanced pool and order types to operate off of
70-
extensions: ProtocolFeeBasisPointsExtension,
71+
extensions: Pairs<Int, Data>,
7172
}
7273

7374
pub type ProtocolFeeBasisPointsExtension {
7475
/// 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
7576
protocol_fee_basis_points: (Int, Int),
76-
/// Pointing to next extension in the future
77-
next: Data,
7877
}
7978

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

90+
pub fn find_protocol_fee_extension(
91+
settings: SettingsDatum,
92+
) -> Option<ProtocolFeeBasisPointsExtension> {
93+
let maybe_extension = pairs.get_first(settings.extensions, 0)
94+
when maybe_extension is {
95+
Some(extension_data) -> {
96+
expect extension: ProtocolFeeBasisPointsExtension = extension_data
97+
Some(extension)
98+
}
99+
None -> None
100+
}
101+
}
102+
91103
/// Scan over the list of reference inputs to find the settings datum, and ensure it's the correct one
92104
/// Note that this makes the assumption that the settings datum is the first reference input, for performance
93105
/// This means that when storing reference scripts on-chain, there needs to be a small amount of "farming" to select

validators/pool.ak

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ use types/pool.{
2424
MintLP, PoolMintRedeemer, PoolRedeemer, PoolScoop, StablePoolDatum,
2525
UpdatePoolFees, WithdrawFees,
2626
} as types_pool
27-
use types/settings.{SettingsDatum, find_settings_datum}
27+
use types/settings.{
28+
ProtocolFeeBasisPointsExtension, SettingsDatum, find_protocol_fee_extension,
29+
find_settings_datum,
30+
}
2831

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

524+
expect Some(protocol_fee_extension) =
525+
find_protocol_fee_extension(settings_datum)
526+
521527
// And check that the datum is initialized correctly; This is part of why we have a minting policy handling this,
522528
// as it allows us to authenticate the providence of the datum.
523529
// A datum is valid so long as
@@ -541,7 +547,7 @@ validator pool(
541547
shared.fees_in_legal_range(
542548
pool_output_datum.protocol_fee_basis_points.2nd,
543549
),
544-
settings_datum.extensions.protocol_fee_basis_points == pool_output_datum.protocol_fee_basis_points,
550+
protocol_fee_extension.protocol_fee_basis_points == pool_output_datum.protocol_fee_basis_points,
545551
pool_output_datum.linear_amplification > 0,
546552
liquidity_invariant(
547553
reserve_a * calc_precision,

validators/tests/pool.ak

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use types/pool.{
3737
UpdatePoolFees, WithdrawFees,
3838
}
3939
use types/settings.{
40-
ProtocolFeeBasisPointsExtension, SettingsDatum, settings_nft_name,
40+
SettingsDatum, settings_nft_name,
4141
}
4242

4343
type ScoopTestOptions {
@@ -383,10 +383,7 @@ test scooper_not_in_settings() fail {
383383
simple_fee: 2_500_000,
384384
strategy_fee: 5_000_000,
385385
pool_creation_fee: 0,
386-
extensions: ProtocolFeeBasisPointsExtension {
387-
protocol_fee_basis_points: (0, 0),
388-
next: Void,
389-
},
386+
extensions: [],
390387
},
391388
),
392389
),

validators/tests/pool.manage.ak

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use sundae/multisig.{MultisigScript}
1717
use tests/constants
1818
use tests/examples/ex_settings.{mk_valid_settings_input}
1919
use types/pool.{ManageRedeemer, StablePoolDatum}
20-
use types/settings.{ProtocolFeeBasisPointsExtension, SettingsDatum}
20+
use types/settings.{SettingsDatum}
2121

2222
const settings_policy_id: PolicyId =
2323
#"00000000000000000000000000000000000000000000000000000000"
@@ -388,10 +388,7 @@ fn scenario_settings_input_baseline(
388388
simple_fee: 2_500_000,
389389
strategy_fee: 5_000_000,
390390
pool_creation_fee: 0,
391-
extensions: ProtocolFeeBasisPointsExtension {
392-
protocol_fee_basis_points: (0, 0),
393-
next: Void,
394-
},
391+
extensions: [],
395392
}
396393
},
397394
)

validators/tests/settings.ak

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use tx_util/builder.{
1212
add_asset_to_tx_output, add_tx_input, add_tx_output, build_txn_context,
1313
mint_assets, new_tx_input, new_tx_output, with_asset_of_tx_input,
1414
}
15-
use types/settings.{
16-
ProtocolFeeBasisPointsExtension, SettingsAdminUpdate, SettingsDatum,
17-
settings_nft_name,
18-
}
15+
use types/settings.{SettingsAdminUpdate, SettingsDatum, settings_nft_name}
1916

2017
fn test_mint_settings(settings_nfts_count: Int) {
2118
let settings_nft =
@@ -95,10 +92,7 @@ fn mk_valid_settings_datum(scoopers: List<ByteArray>) -> SettingsDatum {
9592
simple_fee: 2_500_000,
9693
strategy_fee: 5_000_000,
9794
pool_creation_fee: 0,
98-
extensions: ProtocolFeeBasisPointsExtension {
99-
protocol_fee_basis_points: (0, 0),
100-
next: Void,
101-
},
95+
extensions: [],
10296
}
10397
}
10498

0 commit comments

Comments
 (0)