@meshsdk/contract 1.6.0-alpha.21 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +37 -0
- package/dist/{index.d.mts → index.d.cts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -1803
- package/package.json +30 -14
- package/.turbo/turbo-build$colon$docs.log +0 -8
- package/.turbo/turbo-build$colon$mesh.log +0 -19
- package/dist/index.mjs +0 -1834
- package/src/common.ts +0 -186
- package/src/coupon-bond-guaranteed/aiken-workspace/readme.md +0 -0
- package/src/coupon-bond-guaranteed/offchain.ts +0 -3
- package/src/coupon-bond-guaranteed/readme.md +0 -3
- package/src/escrow/aiken-workspace/aiken.lock +0 -26
- package/src/escrow/aiken-workspace/aiken.toml +0 -19
- package/src/escrow/aiken-workspace/lib/escrow/types.ak +0 -21
- package/src/escrow/aiken-workspace/lib/escrow/validators/escrow.ak +0 -122
- package/src/escrow/aiken-workspace/plutus.json +0 -238
- package/src/escrow/aiken-workspace/readme.md +0 -55
- package/src/escrow/aiken-workspace/validators/escrow.ak +0 -9
- package/src/escrow/aiken-workspace/validators/tests/escrow.ak +0 -462
- package/src/escrow/index.ts +0 -1
- package/src/escrow/offchain.ts +0 -254
- package/src/escrow/readme.md +0 -38
- package/src/giftcard/aiken-workspace/aiken.lock +0 -26
- package/src/giftcard/aiken-workspace/aiken.toml +0 -19
- package/src/giftcard/aiken-workspace/plutus.json +0 -138
- package/src/giftcard/aiken-workspace/readme.md +0 -55
- package/src/giftcard/aiken-workspace/validators/oneshot.ak +0 -173
- package/src/giftcard/index.ts +0 -1
- package/src/giftcard/offchain.ts +0 -184
- package/src/giftcard/readme.md +0 -36
- package/src/hello-world/aiken-workspace/README.md +0 -19
- package/src/hello-world/aiken-workspace/aiken.lock +0 -15
- package/src/hello-world/aiken-workspace/aiken.toml +0 -14
- package/src/hello-world/aiken-workspace/contract.md +0 -27
- package/src/hello-world/aiken-workspace/plutus.json +0 -69
- package/src/hello-world/aiken-workspace/validators/hello_world.ak +0 -24
- package/src/hello-world/index.ts +0 -1
- package/src/hello-world/offchain.ts +0 -24
- package/src/hello-world/readme.md +0 -1
- package/src/index.ts +0 -6
- package/src/marketplace/aiken-workspace/aiken.lock +0 -26
- package/src/marketplace/aiken-workspace/aiken.toml +0 -19
- package/src/marketplace/aiken-workspace/lib/marketplace/types.ak +0 -15
- package/src/marketplace/aiken-workspace/lib/marketplace/validators/marketplace.ak +0 -52
- package/src/marketplace/aiken-workspace/plutus.json +0 -204
- package/src/marketplace/aiken-workspace/readme.md +0 -55
- package/src/marketplace/aiken-workspace/validators/marketplace.ak +0 -14
- package/src/marketplace/aiken-workspace/validators/tests/marketplace.ak +0 -218
- package/src/marketplace/index.ts +0 -1
- package/src/marketplace/offchain.ts +0 -248
- package/src/marketplace/readme.md +0 -45
- package/src/payment-splitter/aiken-workspace/aiken.lock +0 -15
- package/src/payment-splitter/aiken-workspace/aiken.toml +0 -14
- package/src/payment-splitter/aiken-workspace/plutus.json +0 -83
- package/src/payment-splitter/aiken-workspace/validators/payment-splitter.ak +0 -329
- package/src/payment-splitter/index.ts +0 -1
- package/src/payment-splitter/offchain.ts +0 -143
- package/src/payment-splitter/readme.md +0 -100
- package/src/swap/aiken-workspace/aiken.lock +0 -26
- package/src/swap/aiken-workspace/aiken.toml +0 -19
- package/src/swap/aiken-workspace/plutus.json +0 -208
- package/src/swap/aiken-workspace/readme.md +0 -55
- package/src/swap/aiken-workspace/validators/swap.ak +0 -188
- package/src/swap/index.ts +0 -1
- package/src/swap/offchain.ts +0 -139
- package/src/swap/readme.md +0 -35
- package/src/vesting/aiken-workspace/README.md +0 -24
- package/src/vesting/aiken-workspace/aiken.lock +0 -26
- package/src/vesting/aiken-workspace/aiken.toml +0 -19
- package/src/vesting/aiken-workspace/lib/vesting/types.ak +0 -8
- package/src/vesting/aiken-workspace/lib/vesting/validators/vesting.ak +0 -19
- package/src/vesting/aiken-workspace/plutus.json +0 -67
- package/src/vesting/aiken-workspace/validators/tests/vesting.ak +0 -108
- package/src/vesting/aiken-workspace/validators/vesting.ak +0 -9
- package/src/vesting/index.ts +0 -1
- package/src/vesting/offchain.ts +0 -117
- package/src/vesting/readme.md +0 -36
- package/tsconfig.json +0 -5
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
use aiken/hash.{Blake2b_224, Hash}
|
|
2
|
-
use aiken/list
|
|
3
|
-
use aiken/option
|
|
4
|
-
use aiken/transaction.{
|
|
5
|
-
Input, NoDatum, Output, OutputReference, ScriptContext, Spend, Transaction,
|
|
6
|
-
TransactionId,
|
|
7
|
-
}
|
|
8
|
-
use aiken/transaction/credential.{
|
|
9
|
-
Address, VerificationKey, VerificationKeyCredential,
|
|
10
|
-
}
|
|
11
|
-
use aiken/transaction/value.{from_lovelace, lovelace_of}
|
|
12
|
-
|
|
13
|
-
type Datum {
|
|
14
|
-
owner: Hash<Blake2b_224, VerificationKey>,
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type Redeemer {
|
|
18
|
-
message: ByteArray,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
validator(scriptHashes: List<ByteArray>) {
|
|
22
|
-
fn payout(_datum: Datum, _redeemer: Redeemer, context: ScriptContext) -> Bool {
|
|
23
|
-
let payees = list.map(scriptHashes, fn(x) { VerificationKeyCredential(x) })
|
|
24
|
-
|
|
25
|
-
let Transaction { outputs, inputs, fee, .. } = context.transaction
|
|
26
|
-
|
|
27
|
-
let outputCredentials =
|
|
28
|
-
list.map(outputs, fn(output) { output.address.payment_credential })
|
|
29
|
-
|
|
30
|
-
// Only the payees are allowed to trigger the payout and the list needs to include all payees
|
|
31
|
-
let hasNoAdditionalPayees =
|
|
32
|
-
list.difference(list.unique(outputCredentials), payees) == []
|
|
33
|
-
|
|
34
|
-
// All payees must receive the same amount but the payee that triggered the payout
|
|
35
|
-
// must receive the sum of its own inputs minus the fee back to itself on top of that
|
|
36
|
-
let outputValues =
|
|
37
|
-
list.map(
|
|
38
|
-
payees,
|
|
39
|
-
fn(payee) {
|
|
40
|
-
let payeeOutputs =
|
|
41
|
-
list.filter(
|
|
42
|
-
outputs,
|
|
43
|
-
fn(output) { output.address.payment_credential == payee },
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
let payeeOutputSum =
|
|
47
|
-
list.foldr(
|
|
48
|
-
payeeOutputs,
|
|
49
|
-
0,
|
|
50
|
-
fn(output, acc) { acc + lovelace_of(output.value) },
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
let payeeInput =
|
|
54
|
-
list.filter(
|
|
55
|
-
inputs,
|
|
56
|
-
fn(input) { input.output.address.payment_credential == payee },
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
let payeeInputSum =
|
|
60
|
-
list.foldr(
|
|
61
|
-
payeeInput,
|
|
62
|
-
0,
|
|
63
|
-
fn(input, acc) { acc + lovelace_of(input.output.value) },
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
if payeeInputSum > 0 {
|
|
67
|
-
// The payee must receive the sum of its own inputs minus the fee back to itself
|
|
68
|
-
let change = payeeInputSum - lovelace_of(fee)
|
|
69
|
-
payeeOutputSum - change
|
|
70
|
-
} else {
|
|
71
|
-
payeeOutputSum
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
)
|
|
75
|
-
let isSplitEqually =
|
|
76
|
-
list.all(
|
|
77
|
-
outputValues,
|
|
78
|
-
fn(value) {
|
|
79
|
-
let firstOutputValue = option.or_else(list.head(outputValues), 0)
|
|
80
|
-
value == firstOutputValue
|
|
81
|
-
},
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
hasNoAdditionalPayees && isSplitEqually
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
test should_split_equally() {
|
|
89
|
-
let datum =
|
|
90
|
-
Datum { owner: #"52bd00e69e371daa373c021c3f4321356902016c320e41526e239406" }
|
|
91
|
-
let placeholder_utxo =
|
|
92
|
-
OutputReference { transaction_id: TransactionId(""), output_index: 0 }
|
|
93
|
-
let context =
|
|
94
|
-
ScriptContext {
|
|
95
|
-
purpose: Spend(placeholder_utxo),
|
|
96
|
-
transaction: transaction.placeholder()
|
|
97
|
-
|> fn(transaction) {
|
|
98
|
-
Transaction {
|
|
99
|
-
..transaction,
|
|
100
|
-
fee: from_lovelace(846025),
|
|
101
|
-
inputs: [
|
|
102
|
-
Input {
|
|
103
|
-
output_reference: OutputReference {
|
|
104
|
-
transaction_id: TransactionId(""),
|
|
105
|
-
output_index: 0,
|
|
106
|
-
},
|
|
107
|
-
output: Output {
|
|
108
|
-
address: Address {
|
|
109
|
-
payment_credential: VerificationKeyCredential(
|
|
110
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
111
|
-
),
|
|
112
|
-
stake_credential: None,
|
|
113
|
-
},
|
|
114
|
-
value: from_lovelace(41961442),
|
|
115
|
-
datum: NoDatum,
|
|
116
|
-
reference_script: None,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
Input {
|
|
120
|
-
output_reference: OutputReference {
|
|
121
|
-
transaction_id: TransactionId(""),
|
|
122
|
-
output_index: 0,
|
|
123
|
-
},
|
|
124
|
-
output: Output {
|
|
125
|
-
address: Address {
|
|
126
|
-
payment_credential: VerificationKeyCredential(
|
|
127
|
-
#"29ab97f98df7b26c5bfea0c68a727194eca3a14fe41bbe640bce1b8c",
|
|
128
|
-
),
|
|
129
|
-
stake_credential: None,
|
|
130
|
-
},
|
|
131
|
-
value: from_lovelace(15000000),
|
|
132
|
-
datum: NoDatum,
|
|
133
|
-
reference_script: None,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
outputs: [
|
|
138
|
-
Output {
|
|
139
|
-
address: Address {
|
|
140
|
-
payment_credential: VerificationKeyCredential(
|
|
141
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
142
|
-
),
|
|
143
|
-
stake_credential: None,
|
|
144
|
-
},
|
|
145
|
-
value: from_lovelace(3000000),
|
|
146
|
-
datum: NoDatum,
|
|
147
|
-
reference_script: None,
|
|
148
|
-
},
|
|
149
|
-
Output {
|
|
150
|
-
address: Address {
|
|
151
|
-
payment_credential: VerificationKeyCredential(
|
|
152
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
153
|
-
),
|
|
154
|
-
stake_credential: None,
|
|
155
|
-
},
|
|
156
|
-
value: from_lovelace(41115417),
|
|
157
|
-
datum: NoDatum,
|
|
158
|
-
reference_script: None,
|
|
159
|
-
},
|
|
160
|
-
Output {
|
|
161
|
-
address: Address {
|
|
162
|
-
payment_credential: VerificationKeyCredential(
|
|
163
|
-
#"3cea9e9f66482d00cdacd2087d27173d534b76ce7e3cc86e8a07f434",
|
|
164
|
-
),
|
|
165
|
-
stake_credential: None,
|
|
166
|
-
},
|
|
167
|
-
value: from_lovelace(3000000),
|
|
168
|
-
datum: NoDatum,
|
|
169
|
-
reference_script: None,
|
|
170
|
-
},
|
|
171
|
-
Output {
|
|
172
|
-
address: Address {
|
|
173
|
-
payment_credential: VerificationKeyCredential(
|
|
174
|
-
#"01f3855a5b36569e6ce1bdd8286f2b8b4e764b0e1a90a3e3d8357490",
|
|
175
|
-
),
|
|
176
|
-
stake_credential: None,
|
|
177
|
-
},
|
|
178
|
-
value: from_lovelace(3000000),
|
|
179
|
-
datum: NoDatum,
|
|
180
|
-
reference_script: None,
|
|
181
|
-
},
|
|
182
|
-
Output {
|
|
183
|
-
address: Address {
|
|
184
|
-
payment_credential: VerificationKeyCredential(
|
|
185
|
-
#"ce63d3ad78867ac366cabe17e3f15f76d05e0f99827986f92413c4d8",
|
|
186
|
-
),
|
|
187
|
-
stake_credential: None,
|
|
188
|
-
},
|
|
189
|
-
value: from_lovelace(3000000),
|
|
190
|
-
datum: NoDatum,
|
|
191
|
-
reference_script: None,
|
|
192
|
-
},
|
|
193
|
-
Output {
|
|
194
|
-
address: Address {
|
|
195
|
-
payment_credential: VerificationKeyCredential(
|
|
196
|
-
#"06cae4f91a7e73521cfb42a0dcfe0d90feff52ffa096467995bfb503",
|
|
197
|
-
),
|
|
198
|
-
stake_credential: None,
|
|
199
|
-
},
|
|
200
|
-
value: from_lovelace(3000000),
|
|
201
|
-
datum: NoDatum,
|
|
202
|
-
reference_script: None,
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
extra_signatories: [
|
|
206
|
-
#"52bd00e69e371daa373c021c3f4321356902016c320e41526e239406",
|
|
207
|
-
],
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
let redeemer = Redeemer { message: "Payday" }
|
|
213
|
-
|
|
214
|
-
let scriptHashes =
|
|
215
|
-
[
|
|
216
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
217
|
-
#"3cea9e9f66482d00cdacd2087d27173d534b76ce7e3cc86e8a07f434",
|
|
218
|
-
#"01f3855a5b36569e6ce1bdd8286f2b8b4e764b0e1a90a3e3d8357490",
|
|
219
|
-
#"ce63d3ad78867ac366cabe17e3f15f76d05e0f99827986f92413c4d8",
|
|
220
|
-
#"06cae4f91a7e73521cfb42a0dcfe0d90feff52ffa096467995bfb503",
|
|
221
|
-
]
|
|
222
|
-
|
|
223
|
-
payout(scriptHashes, datum, redeemer, context)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
test payment_splitter_should_fail() fail {
|
|
227
|
-
let datum =
|
|
228
|
-
Datum { owner: #"52bd00e69e371daa373c021c3f4321356902016c320e41526e239406" }
|
|
229
|
-
let placeholder_utxo =
|
|
230
|
-
OutputReference { transaction_id: TransactionId(""), output_index: 0 }
|
|
231
|
-
let context =
|
|
232
|
-
ScriptContext {
|
|
233
|
-
purpose: Spend(placeholder_utxo),
|
|
234
|
-
transaction: transaction.placeholder()
|
|
235
|
-
|> fn(transaction) {
|
|
236
|
-
Transaction {
|
|
237
|
-
..transaction,
|
|
238
|
-
fee: from_lovelace(846025),
|
|
239
|
-
inputs: [
|
|
240
|
-
Input {
|
|
241
|
-
output_reference: OutputReference {
|
|
242
|
-
transaction_id: TransactionId(""),
|
|
243
|
-
output_index: 0,
|
|
244
|
-
},
|
|
245
|
-
output: Output {
|
|
246
|
-
address: Address {
|
|
247
|
-
payment_credential: VerificationKeyCredential(
|
|
248
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
249
|
-
),
|
|
250
|
-
stake_credential: None,
|
|
251
|
-
},
|
|
252
|
-
value: from_lovelace(41961442),
|
|
253
|
-
datum: NoDatum,
|
|
254
|
-
reference_script: None,
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
|
-
Input {
|
|
258
|
-
output_reference: OutputReference {
|
|
259
|
-
transaction_id: TransactionId(""),
|
|
260
|
-
output_index: 0,
|
|
261
|
-
},
|
|
262
|
-
output: Output {
|
|
263
|
-
address: Address {
|
|
264
|
-
payment_credential: VerificationKeyCredential(
|
|
265
|
-
#"29ab97f98df7b26c5bfea0c68a727194eca3a14fe41bbe640bce1b8c",
|
|
266
|
-
),
|
|
267
|
-
stake_credential: None,
|
|
268
|
-
},
|
|
269
|
-
value: from_lovelace(16000000),
|
|
270
|
-
datum: NoDatum,
|
|
271
|
-
reference_script: None,
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
],
|
|
275
|
-
outputs: [
|
|
276
|
-
Output {
|
|
277
|
-
address: Address {
|
|
278
|
-
payment_credential: VerificationKeyCredential(
|
|
279
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
280
|
-
),
|
|
281
|
-
stake_credential: None,
|
|
282
|
-
},
|
|
283
|
-
value: from_lovelace(8000000),
|
|
284
|
-
datum: NoDatum,
|
|
285
|
-
reference_script: None,
|
|
286
|
-
},
|
|
287
|
-
Output {
|
|
288
|
-
address: Address {
|
|
289
|
-
payment_credential: VerificationKeyCredential(
|
|
290
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
291
|
-
),
|
|
292
|
-
stake_credential: None,
|
|
293
|
-
},
|
|
294
|
-
value: from_lovelace(41115417),
|
|
295
|
-
datum: NoDatum,
|
|
296
|
-
reference_script: None,
|
|
297
|
-
},
|
|
298
|
-
Output {
|
|
299
|
-
address: Address {
|
|
300
|
-
payment_credential: VerificationKeyCredential(
|
|
301
|
-
#"3cea9e9f66482d00cdacd2087d27173d534b76ce7e3cc86e8a07f434",
|
|
302
|
-
),
|
|
303
|
-
stake_credential: None,
|
|
304
|
-
},
|
|
305
|
-
value: from_lovelace(8000000),
|
|
306
|
-
datum: NoDatum,
|
|
307
|
-
reference_script: None,
|
|
308
|
-
},
|
|
309
|
-
],
|
|
310
|
-
extra_signatories: [
|
|
311
|
-
#"52bd00e69e371daa373c021c3f4321356902016c320e41526e239406",
|
|
312
|
-
],
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
let redeemer = Redeemer { message: "Payday" }
|
|
318
|
-
|
|
319
|
-
let scriptHashes =
|
|
320
|
-
[
|
|
321
|
-
#"92e2ae51fb03dcc55c471506fe35bdedad9c266b0d09c2b8bc7cb445",
|
|
322
|
-
#"3cea9e9f66482d00cdacd2087d27173d534b76ce7e3cc86e8a07f434",
|
|
323
|
-
#"01f3855a5b36569e6ce1bdd8286f2b8b4e764b0e1a90a3e3d8357490",
|
|
324
|
-
#"ce63d3ad78867ac366cabe17e3f15f76d05e0f99827986f92413c4d8",
|
|
325
|
-
#"06cae4f91a7e73521cfb42a0dcfe0d90feff52ffa096467995bfb503",
|
|
326
|
-
]
|
|
327
|
-
|
|
328
|
-
payout(scriptHashes, datum, redeemer, context)
|
|
329
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './offchain';
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { builtinByteString, list, PlutusScript } from "@meshsdk/common";
|
|
2
|
-
import {
|
|
3
|
-
BrowserWallet,
|
|
4
|
-
deserializeAddress,
|
|
5
|
-
MeshWallet,
|
|
6
|
-
serializePlutusScript,
|
|
7
|
-
Transaction,
|
|
8
|
-
} from "@meshsdk/core";
|
|
9
|
-
import { applyParamsToScript } from "@meshsdk/core-csl";
|
|
10
|
-
|
|
11
|
-
import { MeshTxInitiator, MeshTxInitiatorInput } from "../common";
|
|
12
|
-
import blueprint from "./aiken-workspace/plutus.json";
|
|
13
|
-
|
|
14
|
-
export const MeshPaymentSplitterBlueprint = blueprint;
|
|
15
|
-
|
|
16
|
-
export class MeshPaymentSplitterContract extends MeshTxInitiator {
|
|
17
|
-
wrapPayees = (payees: string[]) =>
|
|
18
|
-
list(
|
|
19
|
-
payees.map((payee) =>
|
|
20
|
-
builtinByteString(deserializeAddress(payee).pubKeyHash),
|
|
21
|
-
),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
scriptCbor = () =>
|
|
25
|
-
applyParamsToScript(
|
|
26
|
-
blueprint.validators[0]!.compiledCode,
|
|
27
|
-
[this.wrapPayees(this.payees)],
|
|
28
|
-
"JSON",
|
|
29
|
-
);
|
|
30
|
-
payees: string[] = [];
|
|
31
|
-
|
|
32
|
-
constructor(inputs: MeshTxInitiatorInput, payees: string[]) {
|
|
33
|
-
super(inputs);
|
|
34
|
-
|
|
35
|
-
if (inputs.wallet) {
|
|
36
|
-
// We add the initiator to the payees list, as only the payees can trigger the payout in the next steps
|
|
37
|
-
if (inputs.wallet instanceof MeshWallet) {
|
|
38
|
-
this.payees = [inputs.wallet.getUsedAddresses()[0]!, ...payees];
|
|
39
|
-
}
|
|
40
|
-
if (inputs.wallet instanceof BrowserWallet) {
|
|
41
|
-
inputs.wallet.getUsedAddresses().then((addresses) => {
|
|
42
|
-
this.payees = [addresses[0]!, ...payees];
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
this.payees = payees;
|
|
47
|
-
console.warn(
|
|
48
|
-
"Wallet not provided. Therefore the payment address will not be added to the payees list which makes it impossible to trigger the payout.",
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
sendLovelaceToSplitter = async (lovelaceAmount: number): Promise<string> => {
|
|
54
|
-
if (this.wallet === null || this.wallet === undefined) {
|
|
55
|
-
throw new Error("Wallet not provided");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const { walletAddress } = await this.getWalletInfoForTx();
|
|
59
|
-
|
|
60
|
-
const script: PlutusScript = {
|
|
61
|
-
code: this.scriptCbor(),
|
|
62
|
-
version: "V2",
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const { address: scriptAddress } = serializePlutusScript(
|
|
66
|
-
script,
|
|
67
|
-
undefined,
|
|
68
|
-
0,
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
const { pubKeyHash } = deserializeAddress(walletAddress);
|
|
72
|
-
const datum = {
|
|
73
|
-
alternative: 0,
|
|
74
|
-
fields: [pubKeyHash],
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const tx = new Transaction({ initiator: this.wallet }).sendLovelace(
|
|
78
|
-
{
|
|
79
|
-
address: scriptAddress,
|
|
80
|
-
datum: { value: datum },
|
|
81
|
-
},
|
|
82
|
-
lovelaceAmount.toString(),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const unsignedTx = await tx.build();
|
|
86
|
-
return unsignedTx;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
triggerPayout = async () => {
|
|
90
|
-
if (this.wallet === null || this.wallet === undefined) {
|
|
91
|
-
throw new Error("Wallet not provided");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const { walletAddress, collateral } = await this.getWalletInfoForTx();
|
|
95
|
-
|
|
96
|
-
const script: PlutusScript = {
|
|
97
|
-
code: this.scriptCbor(),
|
|
98
|
-
version: "V2",
|
|
99
|
-
};
|
|
100
|
-
const { address: scriptAddress } = serializePlutusScript(
|
|
101
|
-
script,
|
|
102
|
-
undefined,
|
|
103
|
-
0,
|
|
104
|
-
);
|
|
105
|
-
const utxos = (await this.fetcher?.fetchAddressUTxOs(scriptAddress)) || [];
|
|
106
|
-
const { pubKeyHash } = deserializeAddress(walletAddress);
|
|
107
|
-
const datum = {
|
|
108
|
-
alternative: 0,
|
|
109
|
-
fields: [pubKeyHash],
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
const redeemerData = "Hello, World!";
|
|
113
|
-
const redeemer = { data: { alternative: 0, fields: [redeemerData] } };
|
|
114
|
-
|
|
115
|
-
let tx = new Transaction({ initiator: this.wallet });
|
|
116
|
-
let split = 0;
|
|
117
|
-
for (const utxo of utxos) {
|
|
118
|
-
const amount = utxo.output?.amount;
|
|
119
|
-
if (amount) {
|
|
120
|
-
let lovelace = amount.find((asset) => asset.unit === "lovelace");
|
|
121
|
-
if (lovelace) {
|
|
122
|
-
split += Math.floor(Number(lovelace.quantity) / this.payees.length);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
tx = tx.redeemValue({
|
|
126
|
-
value: utxo,
|
|
127
|
-
script: script,
|
|
128
|
-
datum: datum,
|
|
129
|
-
redeemer: redeemer,
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
tx = tx.setCollateral([collateral]);
|
|
135
|
-
for (const payee of this.payees) {
|
|
136
|
-
tx = tx.sendLovelace(payee, split.toString());
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
tx = tx.setRequiredSigners([walletAddress]);
|
|
140
|
-
const unsignedTx = await tx.build();
|
|
141
|
-
return unsignedTx;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# 💸 Aiken Payment Splitter
|
|
2
|
-
|
|
3
|
-
A simple payment splitter validator written in Aiken and its off-chain counterpart. The Aiken code is located in the onchain directory, while the off-chain code is in the offchain directory.
|
|
4
|
-
|
|
5
|
-
[Demo](https://meshjs.dev/smart-contracts/payment-splitter)
|
|
6
|
-
|
|
7
|
-
There are 2 actions (or endpoints) available to interact with this smart contract:
|
|
8
|
-
|
|
9
|
-
- Send Lovelace to Payment Splitter
|
|
10
|
-
- Trigger Payout
|
|
11
|
-
|
|
12
|
-
To initialize the payment splitter, we need to initialize a provider, MeshTxBuilder and MeshPaymentSplitterContract.
|
|
13
|
-
|
|
14
|
-
```typescript
|
|
15
|
-
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
|
|
16
|
-
import { MeshPaymentSplitterContract } from '@meshsdk/contracts';
|
|
17
|
-
import { useWallet } from '@meshsdk/react';
|
|
18
|
-
|
|
19
|
-
const { connected, wallet } = useWallet();
|
|
20
|
-
|
|
21
|
-
const blockchainProvider = new BlockfrostProvider(APIKEY);
|
|
22
|
-
|
|
23
|
-
const meshTxBuilder = new MeshTxBuilder({
|
|
24
|
-
fetcher: blockchainProvider,
|
|
25
|
-
submitter: blockchainProvider,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const contract = new MeshPaymentSplitterContract(
|
|
29
|
-
{
|
|
30
|
-
mesh: meshTxBuilder,
|
|
31
|
-
fetcher: blockchainProvider,
|
|
32
|
-
wallet: wallet,
|
|
33
|
-
networkId: 0,
|
|
34
|
-
},
|
|
35
|
-
[
|
|
36
|
-
'addr_test1vpg334d6skwu6xxq0r4lqrnsjd5293n8s3d80em60kf6guc7afx8k',
|
|
37
|
-
'addr_test1vp4l2kk0encl7t7972ngepgm0044fu8695prkgh5vjj5l6sxu0l3p',
|
|
38
|
-
'addr_test1vqqnfs2vt42nq4htq460wd6gjxaj05jg9vzg76ur6ws4sngs55pwr',
|
|
39
|
-
'addr_test1vqv2qhqddxmf87pzky2nkd9wm4y5599mhp62mu4atuss5dgdja5pw',
|
|
40
|
-
]);
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## ⛓ On-chain
|
|
44
|
-
|
|
45
|
-
The validator checks two simple rules:
|
|
46
|
-
|
|
47
|
-
1. The list of (unique) payment credentials must match the provided list of "known payees." This list can be provided as a parameter to the validator.
|
|
48
|
-
2. The sum of the outputs (by payment credentials) must be equally split. (Excluding change outputs)
|
|
49
|
-
|
|
50
|
-
### 🔌 Prerequirements
|
|
51
|
-
|
|
52
|
-
- [Aiken](https://aiken-lang.org/installation-instructions#from-aikup-linux--macos-only)
|
|
53
|
-
|
|
54
|
-
### 🪄 Test and build
|
|
55
|
-
|
|
56
|
-
```bash
|
|
57
|
-
cd onchain
|
|
58
|
-
aiken test
|
|
59
|
-
aiken build
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## 📄 Off-chain
|
|
63
|
-
|
|
64
|
-
### 🔌 Prerequirements
|
|
65
|
-
|
|
66
|
-
- Node >= 16
|
|
67
|
-
- Yarn
|
|
68
|
-
|
|
69
|
-
### 💳 Prepare a list of wallets
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
cd offchain
|
|
73
|
-
yarn install
|
|
74
|
-
node use-payment-splitter.js prepare 5
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### 💎 Top up the wallets
|
|
78
|
-
|
|
79
|
-
Copy the address from the output of the previous command and send some test Ada on the preprod network to this address.
|
|
80
|
-
If you don't have test Ada at all, you can get some from the [Cardano Testnets Faucet](https://docs.cardano.org/cardano-testnets/tools/faucet/).
|
|
81
|
-
|
|
82
|
-
### 🤳🏼 Send 10 tAda to the payment splitter
|
|
83
|
-
|
|
84
|
-
Anyone can lock funds in the payment splitter by sending an amount to the contract address.
|
|
85
|
-
|
|
86
|
-
```bash
|
|
87
|
-
node use-payment-splitter.js lock 10000000
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Example transaction: https://preprod.cexplorer.io/tx/0008dd3ead94b0ca922ad45162762d73b5200efc5565a24532f1517fdf060dee
|
|
91
|
-
|
|
92
|
-
### 🤑 Trigger a payout
|
|
93
|
-
|
|
94
|
-
This command will generate a transaction that calculates the total available Lovelace value within the contract UTXOs and distributes the funds among the payees.
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
node use-payment-splitter.js unlock
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Example transaction: https://preprod.cexplorer.io/tx/53be51e0f1268d41caae2944a760387fd762e76058aceddee73ca507d9e9a9c7
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# This file was generated by Aiken
|
|
2
|
-
# You typically do not need to edit this file
|
|
3
|
-
|
|
4
|
-
[[requirements]]
|
|
5
|
-
name = "aiken-lang/stdlib"
|
|
6
|
-
version = "1.9.0"
|
|
7
|
-
source = "github"
|
|
8
|
-
|
|
9
|
-
[[requirements]]
|
|
10
|
-
name = "sidan-lab/aiken-utils"
|
|
11
|
-
version = "0.1.6-beta"
|
|
12
|
-
source = "github"
|
|
13
|
-
|
|
14
|
-
[[packages]]
|
|
15
|
-
name = "aiken-lang/stdlib"
|
|
16
|
-
version = "1.9.0"
|
|
17
|
-
requirements = []
|
|
18
|
-
source = "github"
|
|
19
|
-
|
|
20
|
-
[[packages]]
|
|
21
|
-
name = "sidan-lab/aiken-utils"
|
|
22
|
-
version = "0.1.6-beta"
|
|
23
|
-
requirements = []
|
|
24
|
-
source = "github"
|
|
25
|
-
|
|
26
|
-
[etags]
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name = "meshjs/swap"
|
|
2
|
-
version = "0.0.0"
|
|
3
|
-
license = "Apache-2.0"
|
|
4
|
-
description = "Aiken contracts for project 'meshjs/swap'"
|
|
5
|
-
|
|
6
|
-
[repository]
|
|
7
|
-
user = "meshjs"
|
|
8
|
-
project = "swap"
|
|
9
|
-
platform = "github"
|
|
10
|
-
|
|
11
|
-
[[dependencies]]
|
|
12
|
-
name = "aiken-lang/stdlib"
|
|
13
|
-
version = "1.9.0"
|
|
14
|
-
source = "github"
|
|
15
|
-
|
|
16
|
-
[[dependencies]]
|
|
17
|
-
name = "sidan-lab/aiken-utils"
|
|
18
|
-
version = "0.1.6-beta"
|
|
19
|
-
source = "github"
|