Skip to content

Commit 1307814

Browse files
committed
updated: min_charge
1 parent 8995899 commit 1307814

File tree

13 files changed

+178
-93
lines changed

13 files changed

+178
-93
lines changed

packages/mesh-contract/src/crowdfund/aiken-workspace-v3/aiken-crowdfund/lib/utils.ak

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use aiken/collection/list
22
use aiken/collection/pairs
33
use cardano/address.{Address}
4-
use cardano/assets.{Value}
4+
use cardano/assets.{Lovelace, from_lovelace}
55
use cardano/transaction.{Input, Output, Redeemer, ScriptPurpose, Spend}
66

77
pub fn redeemer_with_input(
@@ -24,16 +24,16 @@ pub fn check_fundraise_target(
2424
}
2525
}
2626

27-
pub fn output_at_with_value(
27+
pub fn outputs_at_with_lovelace(
2828
outputs: List<Output>,
2929
address: Address,
30-
value: Value,
30+
lovelace: Lovelace,
3131
) -> List<Output> {
3232
list.filter(
3333
outputs,
3434
fn(output) {
35-
let are_values_equal = output.value == value
36-
are_values_equal && output.address == address
35+
let is_lovelace_match = output.value == from_lovelace(lovelace)
36+
is_lovelace_match && output.address == address
3737
},
3838
)
3939
}

packages/mesh-contract/src/crowdfund/aiken-workspace-v3/aiken-crowdfund/specs/3_crowdfund.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Parameter
44

55
- `auth_token`: The policy id of `AuthToken`
6+
- `proposer_key_hash`: ByteArray
67

78
## Datum
89

@@ -30,7 +31,8 @@
3031

3132
2. CompleteCrowdfund
3233

33-
- Any value in the current utxos - (`current_fundraised_amount` + `min_charge`) goes to `fee_address`
34+
- `min_charge` goes to `fee_address`
35+
- utxo value >= `min_charge` + `current_fundraised_amount`
3436
- `current_fundraised_amount` >= `fundraise_target`
3537
- `completion_script` withdrawal script is executed
3638
- `auth_token` from current input is burnt
@@ -48,3 +50,4 @@
4850
- `deadline` is passed
4951
- share token with token name `completion_script` burning in current tx == `current_fundraised_amount`
5052
- `auth_token` from current input is burnt
53+
- signed by `proposer_key_hash`

packages/mesh-contract/src/crowdfund/aiken-workspace-v3/aiken-crowdfund/specs/user_action_doc.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- Validation: 2.1, 3.1
88

9-
2. Withdraw fund. Burning ``share_token``
9+
2. Withdraw fund. Burning `share_token`
1010

1111
- Validation: 2.2, 3.3
1212

@@ -20,10 +20,10 @@
2020

2121
- Validation: 2.2, 3.3
2222

23-
3. Complete Crowdfund. Sending `auth_token` and `fundraised_amount` to `1_spend` from `gov-aiken`
23+
3. Complete Crowdfund. Sending `auth_token` and `fundraised_amount` to `1_spend` from `gov-aiken`. Proposer is required to add `min_charge` to `auth_token` utxo
2424

2525
- Validation: 3.2, 2.1 `Withdraw`, 2.1 `Mint` from `gov_crowdfund`
2626

2727
4. Remove Crowdfund. Burning the `auth_token`
2828

29-
- Validation: 1.2, 2.2, 3.4
29+
- Validation: 1.2, 2.2, 3.4

packages/mesh-contract/src/crowdfund/aiken-workspace-v3/aiken-crowdfund/validators/crowdfund/spend.ak

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
use aiken/collection/list.{delete}
21
use aiken/collection/pairs.{has_key}
32
use cardano/address.{Credential, Script}
4-
use cardano/assets.{
5-
PolicyId, from_lovelace, lovelace_of, merge, policies, restricted_to,
6-
}
3+
use cardano/assets.{PolicyId, lovelace_of}
74
use cardano/transaction.{OutputReference, Transaction, find_input}
85
use cocktail.{
9-
inputs_at_with_policy, only_minted_token, output_inline_datum,
6+
inputs_at_with_policy, key_signed, only_minted_token, output_inline_datum,
107
outputs_at_with_policy, policy_only_minted_token, valid_after, valid_before,
118
value_length,
129
}
1310
use types.{
1411
CompleteCrowdfund, ContributeFund, ContributorWithdrawal, CrowdfundDatum,
1512
CrowdfundRedeemer, RemoveEmptyInstance,
1613
}
17-
use utils.{check_fundraise_target, output_at_with_value}
14+
use utils.{check_fundraise_target, outputs_at_with_lovelace}
1815

19-
validator crowdfund(auth_token: PolicyId) {
16+
validator crowdfund(auth_token: PolicyId, proposer_key_hash: ByteArray) {
2017
spend(
2118
datum_opt: Option<CrowdfundDatum>,
2219
redeemer: CrowdfundRedeemer,
2320
input: OutputReference,
2421
self: Transaction,
2522
) {
26-
let Transaction { inputs, validity_range, mint, outputs, withdrawals, .. } =
27-
self
23+
let Transaction {
24+
inputs,
25+
validity_range,
26+
mint,
27+
outputs,
28+
withdrawals,
29+
extra_signatories,
30+
..
31+
} = self
2832

2933
expect Some(own_input) = find_input(inputs, input)
3034
expect Some(auth_input_datum) = datum_opt
@@ -87,31 +91,18 @@ validator crowdfund(auth_token: PolicyId) {
8791
}
8892

8993
CompleteCrowdfund -> {
90-
let fee_value =
91-
from_lovelace(
92-
lovelace_of(auth_input.output.value) - current_fundraised_amount - min_charge,
93-
)
94+
let input_lovelace_check =
95+
lovelace_of(auth_input.output.value) >= min_charge + current_fundraised_amount
9496

95-
let other_policy =
96-
policies(auth_input.output.value)
97-
|> delete(auth_token)
98-
|> delete("")
99-
let other_value = restricted_to(auth_input.output.value, other_policy)
100-
101-
expect [_] =
102-
output_at_with_value(
103-
outputs,
104-
fee_address,
105-
merge(other_value, fee_value),
106-
)
97+
expect [_] = outputs_at_with_lovelace(outputs, fee_address, min_charge)
10798

10899
let fundraise_check = current_fundraised_amount >= fundraise_target
109100
let completion_script_withdrawal_credential: Credential =
110101
Script(completion_script)
111102
let withdrawal_script_check =
112103
withdrawals
113104
|> has_key(completion_script_withdrawal_credential)
114-
fundraise_check? && withdrawal_script_check? && policy_only_minted_token(
105+
fundraise_check? && withdrawal_script_check? && input_lovelace_check? && policy_only_minted_token(
115106
mint,
116107
auth_token,
117108
completion_script,
@@ -171,7 +162,9 @@ validator crowdfund(auth_token: PolicyId) {
171162
} else {
172163
only_minted_token(mint, auth_token, completion_script, -1)?
173164
}
174-
validity_check? && token_burnt_check?
165+
let proposer_key_signed_check =
166+
key_signed(extra_signatories, proposer_key_hash)
167+
validity_check? && token_burnt_check? && proposer_key_signed_check?
175168
}
176169
}
177170
}

0 commit comments

Comments
 (0)