1
- use aiken/ transaction.{NoDatum , Output }
2
- use aiken/ transaction/ credential.{Address , VerificationKeyCredential }
1
+ use aiken/ transaction.{Output }
3
2
use aiken/ transaction/ value.{Value , ada_policy_id, ada_asset_name}
4
3
use calculation/ shared.{PoolState } as calc_shared
5
4
use shared.{SingletonValue }
6
- use sundae/ multisig
7
- use types/ order.{Destination , OrderDatum }
5
+ use types/ order.{Destination }
8
6
9
7
/// A donation describes an amount of assets to deposit into the pool, receiving nothing in return (except for the extra change on the UTXO).
10
8
/// Because every LP token holder has an entitlement to a percentage of the assets in the pool, the donation is distributed to all LP token holders
@@ -29,19 +27,19 @@ pub fn do_donation(
29
27
/// If there is no change leftover, this output is ignored and used for the next order
30
28
output: Output ,
31
29
) -> (PoolState , Bool ) {
30
+ let ((asset_a_policy_id, asset_a_asset_name, asset_a_qty), (asset_b_policy_id, asset_b_asset_name, asset_b_qty)) = assets
32
31
// Make sure we're actually donating the pool assets; this is to prevent setting
33
32
// poolIdent to None, and then filling the pool UTXO with garbage tokens and eventually locking it
34
- expect assets.1st.1st == pool_state.quantity_a.1st
35
- expect assets.1st.2nd == pool_state.quantity_a.2nd
36
- expect assets.2nd.1st == pool_state.quantity_b.1st
37
- expect assets.2nd.2nd == pool_state.quantity_b.2nd
33
+ expect asset_a_policy_id == pool_state.quantity_a.1st
34
+ expect asset_a_asset_name == pool_state.quantity_a.2nd
35
+ expect asset_b_policy_id == pool_state.quantity_b.1st
36
+ expect asset_b_asset_name == pool_state.quantity_b.2nd
38
37
// Compute however much of the UTXO value is *left over* after deducting the donation amount from it; If nonzero, this will need to be returned to the user
39
38
let remainder =
40
- shared.to_value (assets.1st)
41
- |> value.merge (shared.to_value (assets.2nd))
42
- |> value.add (ada_policy_id, ada_asset_name, actual_protocol_fee)
43
- |> value.negate
44
- |> value.merge (input_value)
39
+ input_value
40
+ |> value.add (ada_policy_id, ada_asset_name, - actual_protocol_fee)
41
+ |> value.add (asset_a_policy_id, asset_a_asset_name, - asset_a_qty)
42
+ |> value.add (asset_b_policy_id, asset_b_asset_name, - asset_b_qty)
45
43
46
44
let has_remainder = remainder != value.zero ()
47
45
// If we have a remainder, then we need to check the details of the output; this awkward structure
@@ -76,57 +74,3 @@ pub fn do_donation(
76
74
has_remainder,
77
75
)
78
76
}
79
-
80
- test donation () {
81
- let addr =
82
- Address (
83
- VerificationKeyCredential (
84
- #"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513" ,
85
- ),
86
- None ,
87
- )
88
- let ada = (#"" , #"" )
89
- let rberry =
90
- (#"01010101010101010101010101010101010101010101010101010101" , "RBERRY" )
91
- let lp = (#"99999999999999999999999999999999999999999999999999999999" , "LP" )
92
- let pool_state =
93
- PoolState {
94
- quantity_a: (#"" , #"" , 1_000_000_000 ),
95
- quantity_b: (rberry.1st, rberry.2nd, 1_000_000_000 ),
96
- quantity_lp: (lp.1st, lp.2nd, 1_000_000_000 ),
97
- }
98
- let input_value =
99
- value.from_lovelace (3_500_000 )
100
- |> value.add (rberry.1st, rberry.2nd, 1_000_000 )
101
- let assets = (
102
- (ada.1st, ada.2nd, 1_000_000 ),
103
- (rberry.1st, rberry.2nd, 1_000_000 ),
104
- )
105
- let order =
106
- OrderDatum {
107
- pool_ident: None ,
108
- owner: multisig.Signature (
109
- #"6af53ff4f054348ad825c692dd9db8f1760a8e0eacf9af9f99306513" ,
110
- ),
111
- max_protocol_fee: 2_500_000 ,
112
- destination: Destination { address: addr, datum: NoDatum },
113
- details: order.Donation {
114
- assets: assets,
115
- },
116
- extension: Void ,
117
- }
118
- // There's no remainder so do_donation totally ignores this Output record
119
- let output =
120
- Output {
121
- address: addr,
122
- value: value.from_lovelace (999_999_999_999_999_999 ),
123
- datum: NoDatum ,
124
- reference_script: None ,
125
- }
126
- let (final_pool_state, has_remainder) =
127
- do_donation (pool_state, input_value, assets, order.destination, 2_500_000 , output)
128
- expect !has_remainder
129
- expect final_pool_state.quantity_a.3rd == 1_001_000_000
130
- expect final_pool_state.quantity_b.3rd == 1_001_000_000
131
- True
132
- }
0 commit comments