@meshsdk/contract 1.6.12 → 1.7.0

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.js CHANGED
@@ -1,17 +1,17 @@
1
- // src/marketplace/offchain.ts
1
+ // src/escrow/offchain.ts
2
2
  import {
3
3
  conStr0,
4
- currencySymbol,
5
- integer,
6
- mConStr0,
4
+ conStr1,
7
5
  mConStr1,
8
- parseAssetUnit,
6
+ mConStr2,
9
7
  pubKeyAddress,
10
- tokenName
8
+ value,
9
+ MeshValue
11
10
  } from "@meshsdk/common";
12
11
  import {
13
12
  deserializeAddress,
14
13
  deserializeDatum,
14
+ mergeAssets,
15
15
  serializeAddressObj,
16
16
  serializePlutusScript
17
17
  } from "@meshsdk/core";
@@ -29,7 +29,7 @@ var MeshTxInitiator = class {
29
29
  mesh,
30
30
  fetcher,
31
31
  wallet,
32
- networkId,
32
+ networkId = 0,
33
33
  stakeCredential
34
34
  }) {
35
35
  this.mesh = mesh;
@@ -39,13 +39,11 @@ var MeshTxInitiator = class {
39
39
  if (wallet) {
40
40
  this.wallet = wallet;
41
41
  }
42
- if (networkId) {
43
- this.networkId = networkId;
44
- if (networkId === 1) {
45
- this.mesh.setNetwork("mainnet");
46
- } else {
47
- this.mesh.setNetwork("preprod");
48
- }
42
+ this.networkId = networkId;
43
+ if (networkId === 1) {
44
+ this.mesh.setNetwork("mainnet");
45
+ } else {
46
+ this.mesh.setNetwork("preprod");
49
47
  }
50
48
  if (stakeCredential) {
51
49
  this.stakeCredential = this.stakeCredential;
@@ -165,11 +163,11 @@ var MeshTxInitiator = class {
165
163
  };
166
164
  };
167
165
 
168
- // src/marketplace/aiken-workspace/plutus.json
166
+ // src/escrow/aiken-workspace/plutus.json
169
167
  var plutus_default = {
170
168
  preamble: {
171
- title: "meshjs/marketplace",
172
- description: "Aiken contracts for project 'meshjs/marketplace'",
169
+ title: "meshjs/escrow",
170
+ description: "Aiken contracts for project 'meshjs/escrow'",
173
171
  version: "0.0.0",
174
172
  plutusVersion: "v2",
175
173
  compiler: {
@@ -180,35 +178,21 @@ var plutus_default = {
180
178
  },
181
179
  validators: [
182
180
  {
183
- title: "marketplace.marketplace",
181
+ title: "escrow.escrow",
184
182
  datum: {
185
- title: "datum",
183
+ title: "_datum",
186
184
  schema: {
187
- $ref: "#/definitions/marketplace~1types~1MarketplaceDatum"
185
+ $ref: "#/definitions/escrow~1types~1EscrowDatum"
188
186
  }
189
187
  },
190
188
  redeemer: {
191
189
  title: "redeemer",
192
190
  schema: {
193
- $ref: "#/definitions/marketplace~1types~1MarketplaceRedeemer"
191
+ $ref: "#/definitions/escrow~1types~1EscrowRedeemer"
194
192
  }
195
193
  },
196
- parameters: [
197
- {
198
- title: "owner",
199
- schema: {
200
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
201
- }
202
- },
203
- {
204
- title: "fee_percentage_basis_point",
205
- schema: {
206
- $ref: "#/definitions/Int"
207
- }
208
- }
209
- ],
210
- compiledCode: "59082f01000032323232323232223223232322322533300b3232533300d3007300e375400226464a64666020601660226ea80204c94ccc044c030c048dd500089919191919191919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc044c084dd5180a18109baa00200513302300233004004001133004004001302400230220013758601660366ea8c02cc06cdd50079805980d9baa300e301b37540102a6660320022004294052819801998011bac3004301a3754601460346ea803805cc018cdc199b82375a601a60346ea805005520a09c0133002330013758600660326ea8c024c064dd50069804980c9baa0133005337006eb4c030c064dd50099998021bab300c30193754601860326ea801922010048810022323300100100322533301d00114bd6f7b63009991299980e19baf300e301e375400400a2646660020020046eacc048c07cdd50019112999811001080089919980200218130019991191980080080291299981380089981419bb037520086e9800d2f5bded8c0264646464a66605066e400200084cc0b0cdd81ba9008374c00e00a2a66605066e3c0200084c94ccc0a4c090c0a8dd500089981699bb03752012605c60566ea80040104010c94ccc0a54ccc0b00045288a5014c0103d87a80001301a3302d374c00297ae032333001001008002222533302e0021001132333004004303200333223233001001005225333033001133034337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0d0cdc800400109981c19bb037520106ea001c01454ccc0d0cdc7804001099299981a9818181b1baa001133039337606ea4024c0e8c0dcdd5000802080219299981a98180008a60103d87a80001302633039375000297ae03370000e00226607066ec0dd48011ba800133006006003375a606a0066eb8c0cc008c0dc008c0d4004dd718168009bad302e001303000213302c337606ea4008dd3000998030030019bab3029003375c604e004605600460520026eb8c084004dd5981100098120010800980f800998010011810000911919800800991980080080191299980e8008a5eb804c8ccc888c8cc00400400c894ccc08c004400c4c8cc094dd3998129ba90063302530220013302530230014bd7019801801981380118128009bae301c0013756603a002660060066042004603e00244a66603800229444c94ccc068c8cdc49bad3007001333008006375c601a0026eb8c040004dd6180f8010998018018008a50301f0012301a301b301b0012223253330173011301837540022900009bad301c3019375400264a66602e602260306ea8004530103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301d337220100042a66603a66e3c0200084c038cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301c337220100042a66603866e3c0200084c034cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c07400494ccc04cc03800452f5bded8c0264646600200297adef6c6022533301900113301a337609801014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c068004c058c04cdd50008b19198008009bac300330133754600660266ea801c894ccc054004530103d87a80001323253330143375e600c602c6ea800801c4c014cc0600092f5c02660080080026032004602e002264a666022601860246ea80044cc88c8cc00400400c894ccc060004528099299980b19b8f375c603600400829444cc00c00c004c06c004dd6180b180b980b980b980b980b980b980b980b98099baa30033013375400e6eb8c058c04cdd50008b192999808980618091baa001130023301530163013375400297ae014c0103d87a8000300230123754600460246ea8030dd2a4000460280026024601e6ea8004528180098071baa00223011301200114984d958c94ccc028c01400454ccc034c030dd50010a4c2c2a66601460080022a66601a60186ea80085261616300a375400264a666010600660126ea80104c8c8c8c8c8c8c8c94ccc04cc0580084c9265333010300b3011375400e264646464a66602e6034004264649319299980b180880089919299980d980f00109924c64a666032602800226464a66603c604200426493180a0008b180f800980d9baa002153330193013001132323232323253330223025002149858dd6981180098118011bad30210013021002375a603e00260366ea800858c064dd50008b180e000980c1baa00315333016301000115333019301837540062930b0b180b1baa002300d003163018001301800230160013012375400e2c2c6eb8c050004c050008dd7180900098090011bad30100013010002300e001300a37540082c464a666012600800226464a66601c60220042930b1bae300f001300b37540042a666012600600226464a66601c60220042930b1bae300f001300b37540042c60126ea8004dc3a40046e1d2000375a002ae6955ceaab9e5573eae815d0aba21",
211
- hash: "96dbc09c69d812e157d42967587c459b60f5dd21b1902312045586c4"
194
+ compiledCode: "590c2f01000032323232323232232323232323232232322533300d3232533300f300c3010375400226464646464646464a66602e602a60306ea80044c8c8c8c8c8c8c8c8c8c94ccc084c07c0244c8c8c8c8c8c8c94ccc0acc0b800c4c94ccc0b0c0bc00c4c94ccc0a8c080c0acdd5000899192999816181118169baa001132533302d302b302e3754006264646464a666068606e004264646464a66606a66ebc024cdd2a40046607200e660726e98014cc0e404ccc0e4dd300925eb8040045281980b9bab302730363754018660326eacc09cc0d8dd51813981b1baa00d301a011302c0073302c0022323302e3756606c0044646eb4c0e0008dd7181b0009bae3034001302c003163756606a002606a0046066002605e6ea800c58c0c4c0b8dd50008b180798169baa003302f302c37540022c601a60566ea8c070c0acdd50010b18168010b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb80dd598141814801181380098119baa01813232325333024302100c132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd500089980500c1bae3031302e37540022c60106060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc058090dd7181e8010a51133003003001303d00115333035005100414a0294058c044014dd7181c181a9baa00116300f006330143301001e00230173756606c606e006660266601e03a008602c6eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa00116300c302a3754603660546ea80045858c0b0008dd6181598160011bac302a00133028374e6600802601a660506e9ccc0140440352f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1980e0151bae304300213300300300114a060860022a66607600a200829405280b180b8059bae303e303b37540022c602a01a660346602c048010603a014660326602a046016603800a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c601860546ea8c06cc0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb808c94ccc094c08cc098dd50008980819814981518139baa0014bd700a6103d87a800030153026375400244646600200200644a66605200229404c94ccc09ccdc79bae302c00200414a2266006006002605800244646600200200644a666050002297adef6c601332253330273375e603060526ea80080144cc030004dd5980d18149baa0021001302a00133002002302b001223300400223375e6028604a6ea8c058c094dd50008011119801801119baf30133024375400200444646600200200644a66604a002297ae013232533302430050021330280023300400400113300400400130290023027001223233001001323300100100322533302500114bd7009919991119198008008019129998158008801899198169ba73302d375200c6605a60540026605a605600297ae033003003302f002302d001375c60480026eacc094004cc00c00cc0a4008c09c004894ccc09000452889929998111919b89375a600e002664464a66604c6046604e6ea8004520001375a605660506ea8004c94ccc098c08cc09cdd50008a60103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a8000132323232533302c337220100042a66605866e3c0200084c05ccc0c0dd4000a5eb80530103d87a8000133006006003375a605a0066eb8c0ac008c0bc008c0b4004c8cc004004024894ccc0a80045300103d87a8000132323232533302b337220100042a66605666e3c0200084c058cc0bcdd3000a5eb80530103d87a8000133006006003375660580066eb8c0a8008c0b8008c0b0004dd7180a0009bae30160013758604e0042660060060022940c09c0048c088c08cc08c00488c8ccc00400400c0088894ccc08c00840044c8ccc010010c09c00ccccc020008dd718110009bab3023001222325333025533302800114a229405300103d87a80001301033029374c00297ae032333001001003002222533302a0021001132333004004302e0033322323300100100522533302f001133030337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0c0cdc800400109981a19bb037520106ea001c01454ccc0c0cdc78040010992999818981798191baa001133035337606ea4024c0d8c0ccdd5000802080219299981898178008a60103d87a80001301c33035375000297ae03370000e00226606866ec0dd48011ba800133006006003375a60620066eb8c0bc008c0cc008c0c4004dd718148009bad302a001302c00230250022323300100100222533302000114bd6f7b6300999119191999804001801000911319190011919198008008019129998138008a4c264a6660500022a66604a60086eb4c09cc0a8008526161323232325333029337206eb8c0a8010dd718150018a9998149804000899803803998168018010b0b1bad302a003302d003302b002302a002302a001233302230200014a0944dd598110019bae3020002302200133002002302300122223233001001005225333022001133023337606ea4014dd300225eb7bdb1804c8c8c8c94ccc08ccdc800480109981399bb037520126e9802001454ccc08ccdc78048010992999812181118129baa001133028337606ea4028c0a4c098dd5000802080219980380480400089981399bb037520046e98004cc01801800cdd598120019bae3022002302600230240013019375401e601060326ea8c028c064dd5180e180c9baa0011632323300100100722533301c00114c0103d87a800013232533301b3375e6018603a6ea80080144c018cc07c0092f5c02660080080026040004603c002603660306ea8020dd2a40006eb0c064c068c068c068c068c068c068008dd6180c000980c180c0011bac301600130123754600260246ea80108c054004528180098081baa00223013301400114984d958c94ccc030c0280044c8c8c8c94ccc04cc0580084c8c9263300b0022323300d3756602a0044646eb4c05c008dd7180a8009bae3013001300b003163756602800260280046024002601c6ea800c54ccc030c02400454ccc03cc038dd50018a4c2c2a66601860040022a66601e601c6ea800c5261616300c37540046e1d20043001007232533300930070011323232325333010301300213232498cc0200088c8cc028dd598090011191bad3014002375c60240026eb8c040004c02000c58dd598088009808801180780098059baa0021533300930060011323232323232323253330143017002132323232498cc0380108c8cc040dd5980c0011191bad301a002375c60300026eb8c058004c038014cc0300188c8cc038dd5980b0011191bad3018002375c602c0026eb8c050004c03001c58dd5980a800980a801180980098098011bab30110013011002300f001300b37540042c60126ea800488c8cc00400400c894ccc0340045261323300300330110023003300f00125333006300430073754002264646464a66601a602000426464931929998061805000899192999808980a00109924c64a66601e601a00226464a666028602e0042649318068008b180a80098089baa0021533300f300c00113232323232325333018301b002149858dd6980c800980c8011bad30170013017002375a602a00260226ea800858c03cdd50008b180900098071baa0031533300c30090011533300f300e37540062930b0b18061baa002300600316300e001300e002300c001300837540022c464a66600c600800226464a666016601c0042930b1bae300c001300837540042a66600c600600226464a666016601c0042930b1bae300c001300837540042c600c6ea8004dc3a40046e1d20005734aae7555cf2ab9f5740ae855d101",
195
+ hash: "8fa9284f5889972d7260c10e940a2e1acb2114bdcea845da3d52de7d"
212
196
  }
213
197
  ],
214
198
  definitions: {
@@ -218,6 +202,24 @@ var plutus_default = {
218
202
  Int: {
219
203
  dataType: "integer"
220
204
  },
205
+ List$Pair$ByteArray_Int: {
206
+ dataType: "map",
207
+ keys: {
208
+ $ref: "#/definitions/ByteArray"
209
+ },
210
+ values: {
211
+ $ref: "#/definitions/Int"
212
+ }
213
+ },
214
+ List$Pair$ByteArray_List$Pair$ByteArray_Int: {
215
+ dataType: "map",
216
+ keys: {
217
+ $ref: "#/definitions/ByteArray"
218
+ },
219
+ values: {
220
+ $ref: "#/definitions/List$Pair$ByteArray_Int"
221
+ }
222
+ },
221
223
  "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
222
224
  title: "Optional",
223
225
  anyOf: [
@@ -323,106 +325,151 @@ var plutus_default = {
323
325
  }
324
326
  ]
325
327
  },
326
- "marketplace/types/MarketplaceDatum": {
327
- title: "MarketplaceDatum",
328
+ "escrow/types/EscrowDatum": {
329
+ title: "EscrowDatum",
328
330
  anyOf: [
329
331
  {
330
- title: "MarketplaceDatum",
332
+ title: "Initiation",
331
333
  dataType: "constructor",
332
334
  index: 0,
333
335
  fields: [
334
336
  {
335
- title: "seller",
337
+ title: "initiator",
336
338
  $ref: "#/definitions/aiken~1transaction~1credential~1Address"
337
339
  },
338
340
  {
339
- title: "price",
340
- $ref: "#/definitions/Int"
341
+ title: "initiator_assets",
342
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
343
+ }
344
+ ]
345
+ },
346
+ {
347
+ title: "ActiveEscrow",
348
+ dataType: "constructor",
349
+ index: 1,
350
+ fields: [
351
+ {
352
+ title: "initiator",
353
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
341
354
  },
342
355
  {
343
- title: "policy",
344
- $ref: "#/definitions/ByteArray"
356
+ title: "initiator_assets",
357
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
345
358
  },
346
359
  {
347
- title: "tokenName",
348
- $ref: "#/definitions/ByteArray"
360
+ title: "recipient",
361
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
362
+ },
363
+ {
364
+ title: "recipient_assets",
365
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
349
366
  }
350
367
  ]
351
368
  }
352
369
  ]
353
370
  },
354
- "marketplace/types/MarketplaceRedeemer": {
355
- title: "MarketplaceRedeemer",
371
+ "escrow/types/EscrowRedeemer": {
372
+ title: "EscrowRedeemer",
356
373
  anyOf: [
357
374
  {
358
- title: "Buy",
375
+ title: "RecipientDeposit",
359
376
  dataType: "constructor",
360
377
  index: 0,
361
- fields: []
378
+ fields: [
379
+ {
380
+ title: "recipient",
381
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
382
+ },
383
+ {
384
+ title: "recipient_assets",
385
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
386
+ }
387
+ ]
362
388
  },
363
389
  {
364
- title: "Close",
390
+ title: "CancelTrade",
365
391
  dataType: "constructor",
366
392
  index: 1,
367
393
  fields: []
394
+ },
395
+ {
396
+ title: "CompleteTrade",
397
+ dataType: "constructor",
398
+ index: 2,
399
+ fields: []
368
400
  }
369
401
  ]
370
402
  }
371
403
  }
372
404
  };
373
405
 
374
- // src/marketplace/offchain.ts
375
- var MeshMarketplaceBlueprint = plutus_default;
376
- var marketplaceDatum = (sellerAddress, lovelaceFee, assetHex) => {
377
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress(sellerAddress);
378
- const { policyId, assetName } = parseAssetUnit(assetHex);
406
+ // src/escrow/offchain.ts
407
+ var MeshEscrowBlueprint = plutus_default;
408
+ var initiateEscrowDatum = (walletAddress, amount) => {
409
+ const { pubKeyHash, stakeCredentialHash } = deserializeAddress(walletAddress);
379
410
  return conStr0([
380
411
  pubKeyAddress(pubKeyHash, stakeCredentialHash),
381
- integer(lovelaceFee),
382
- currencySymbol(policyId),
383
- tokenName(assetName)
412
+ value(amount)
384
413
  ]);
385
414
  };
386
- var MeshMarketplaceContract = class extends MeshTxInitiator {
387
- ownerAddress;
388
- feePercentageBasisPoint;
389
- scriptCbor;
390
- constructor(inputs, ownerAddress, feePercentageBasisPoint) {
415
+ var activeEscrowDatum = (initiationDatum, walletAddress, amount) => {
416
+ const { pubKeyHash, stakeCredentialHash } = deserializeAddress(walletAddress);
417
+ const [initiator, initiatorAmount] = initiationDatum.fields;
418
+ return conStr1([
419
+ initiator,
420
+ initiatorAmount,
421
+ pubKeyAddress(pubKeyHash, stakeCredentialHash),
422
+ value(amount)
423
+ ]);
424
+ };
425
+ var recipientDepositRedeemer = (recipient, depositAmount) => initiateEscrowDatum(recipient, depositAmount);
426
+ var MeshEscrowContract = class extends MeshTxInitiator {
427
+ scriptCbor = applyParamsToScript(plutus_default.validators[0].compiledCode, []);
428
+ constructor(inputs) {
391
429
  super(inputs);
392
- this.ownerAddress = ownerAddress;
393
- this.feePercentageBasisPoint = feePercentageBasisPoint;
394
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress(ownerAddress);
395
- this.scriptCbor = applyParamsToScript(
396
- plutus_default.validators[0].compiledCode,
397
- [
398
- pubKeyAddress(pubKeyHash, stakeCredentialHash),
399
- integer(feePercentageBasisPoint)
400
- ],
401
- "JSON"
402
- );
403
430
  }
404
- listAsset = async (asset, price) => {
431
+ initiateEscrow = async (escrowAmount) => {
405
432
  const { utxos, walletAddress } = await this.getWalletInfoForTx();
406
- const assetMap = /* @__PURE__ */ new Map();
407
- assetMap.set(asset, "1");
408
433
  const { address: scriptAddr } = serializePlutusScript(
409
434
  { code: this.scriptCbor, version: "V2" },
410
435
  void 0,
411
436
  this.networkId
412
437
  );
413
- const tokenForSale = [{ unit: asset, quantity: "1" }];
414
- const outputDatum = marketplaceDatum(walletAddress, price, asset);
415
- await this.mesh.txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
438
+ await this.mesh.txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(
439
+ initiateEscrowDatum(walletAddress, escrowAmount),
440
+ "JSON"
441
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
416
442
  return this.mesh.txHex;
417
443
  };
418
- delistAsset = async (marketplaceUtxo) => {
444
+ cancelEscrow = async (escrowUtxo) => {
419
445
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
446
+ const { address: scriptAddr } = serializePlutusScript(
447
+ { code: this.scriptCbor, version: "V2" },
448
+ void 0,
449
+ this.networkId
450
+ );
451
+ const inputDatum = deserializeDatum(
452
+ escrowUtxo.output.plutusData
453
+ );
454
+ if (inputDatum.constructor === 1) {
455
+ const [
456
+ initiatorAddressObj,
457
+ initiatorAmount,
458
+ recipientAddressObj,
459
+ recipientAmount
460
+ ] = inputDatum.fields;
461
+ const initiatorAddress = serializeAddressObj(initiatorAddressObj);
462
+ const recipientAddress = serializeAddressObj(recipientAddressObj);
463
+ const initiatorToReceive = MeshValue.fromValue(initiatorAmount).toAssets();
464
+ const recipientToReceive = MeshValue.fromValue(recipientAmount).toAssets();
465
+ this.mesh.txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive);
466
+ }
420
467
  await this.mesh.spendingPlutusScriptV2().txIn(
421
- marketplaceUtxo.input.txHash,
422
- marketplaceUtxo.input.outputIndex,
423
- marketplaceUtxo.output.amount,
424
- marketplaceUtxo.output.address
425
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr1([])).txInScript(this.scriptCbor).changeAddress(walletAddress).requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash).txInCollateral(
468
+ escrowUtxo.input.txHash,
469
+ escrowUtxo.input.outputIndex,
470
+ escrowUtxo.output.amount,
471
+ scriptAddr
472
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr1([])).txInScript(this.scriptCbor).requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
426
473
  collateral.input.txHash,
427
474
  collateral.input.outputIndex,
428
475
  collateral.output.amount,
@@ -430,71 +477,69 @@ var MeshMarketplaceContract = class extends MeshTxInitiator {
430
477
  ).selectUtxosFrom(utxos).complete();
431
478
  return this.mesh.txHex;
432
479
  };
433
- purchaseAsset = async (marketplaceUtxo) => {
480
+ recipientDeposit = async (escrowUtxo, depositAmount) => {
434
481
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
482
+ const { address: scriptAddr } = serializePlutusScript(
483
+ { code: this.scriptCbor, version: "V2" },
484
+ void 0,
485
+ this.networkId
486
+ );
435
487
  const inputDatum = deserializeDatum(
436
- marketplaceUtxo.output.plutusData
488
+ escrowUtxo.output.plutusData
437
489
  );
438
- const inputLovelace = marketplaceUtxo.output.amount.find(
439
- (a) => a.unit === "lovelace"
440
- ).quantity;
441
- const tx = this.mesh.spendingPlutusScriptV2().txIn(
442
- marketplaceUtxo.input.txHash,
443
- marketplaceUtxo.input.outputIndex,
444
- marketplaceUtxo.output.amount,
445
- marketplaceUtxo.output.address
446
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr0([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
490
+ const outputDatum = activeEscrowDatum(
491
+ inputDatum,
492
+ walletAddress,
493
+ depositAmount
494
+ );
495
+ const inputAssets = MeshValue.fromValue(inputDatum.fields[1]).toAssets();
496
+ const escrowAmount = mergeAssets([...depositAmount, ...inputAssets]);
497
+ await this.mesh.spendingPlutusScriptV2().txIn(
498
+ escrowUtxo.input.txHash,
499
+ escrowUtxo.input.outputIndex,
500
+ escrowUtxo.output.amount,
501
+ scriptAddr
502
+ ).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(
503
+ recipientDepositRedeemer(walletAddress, depositAmount),
504
+ "JSON",
505
+ {
506
+ mem: 7e6,
507
+ steps: 3e9
508
+ }
509
+ ).txInScript(this.scriptCbor).txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).txInCollateral(
447
510
  collateral.input.txHash,
448
511
  collateral.input.outputIndex,
449
512
  collateral.output.amount,
450
513
  collateral.output.address
451
- ).selectUtxosFrom(utxos);
452
- let ownerToReceiveLovelace = inputDatum.fields[1].int * this.feePercentageBasisPoint / 1e4;
453
- if (this.feePercentageBasisPoint > 0 && ownerToReceiveLovelace < 1e6) {
454
- ownerToReceiveLovelace = 1e6;
455
- }
456
- if (ownerToReceiveLovelace > 0) {
457
- const ownerAddress = this.ownerAddress;
458
- const ownerToReceive = [
459
- {
460
- unit: "lovelace",
461
- quantity: Math.ceil(ownerToReceiveLovelace).toString()
462
- }
463
- ];
464
- tx.txOut(ownerAddress, ownerToReceive);
465
- }
466
- const sellerToReceiveLovelace = inputDatum.fields[1].int + Number(inputLovelace);
467
- if (sellerToReceiveLovelace > 0) {
468
- const sellerAddress = serializeAddressObj(inputDatum.fields[0]);
469
- const sellerToReceive = [
470
- {
471
- unit: "lovelace",
472
- quantity: sellerToReceiveLovelace.toString()
473
- }
474
- ];
475
- tx.txOut(sellerAddress, sellerToReceive);
476
- }
477
- await tx.complete();
514
+ ).selectUtxosFrom(utxos).complete();
478
515
  return this.mesh.txHex;
479
516
  };
480
- relistAsset = async (marketplaceUtxo, newPrice) => {
517
+ completeEscrow = async (escrowUtxo) => {
481
518
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
482
- const inputAsset = marketplaceUtxo.output.amount.find(
483
- (a) => a.unit !== "lovelace"
484
- ).unit;
485
- const tokenForSale = [{ unit: inputAsset, quantity: "1" }];
486
- const outputDatum = marketplaceDatum(walletAddress, newPrice, inputAsset);
487
519
  const { address: scriptAddr } = serializePlutusScript(
488
520
  { code: this.scriptCbor, version: "V2" },
489
521
  void 0,
490
522
  this.networkId
491
523
  );
524
+ const inputDatum = deserializeDatum(
525
+ escrowUtxo.output.plutusData
526
+ );
527
+ const [
528
+ initiatorAddressObj,
529
+ initiatorAmount,
530
+ recipientAddressObj,
531
+ recipientAmount
532
+ ] = inputDatum.fields;
533
+ const initiatorAddress = serializeAddressObj(initiatorAddressObj);
534
+ const recipientAddress = serializeAddressObj(recipientAddressObj);
535
+ const initiatorToReceive = MeshValue.fromValue(recipientAmount).toAssets();
536
+ const recipientToReceive = MeshValue.fromValue(initiatorAmount).toAssets();
492
537
  await this.mesh.spendingPlutusScriptV2().txIn(
493
- marketplaceUtxo.input.txHash,
494
- marketplaceUtxo.input.outputIndex,
495
- marketplaceUtxo.output.amount,
496
- marketplaceUtxo.output.address
497
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr1([])).txInScript(this.scriptCbor).txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash).txInCollateral(
538
+ escrowUtxo.input.txHash,
539
+ escrowUtxo.input.outputIndex,
540
+ escrowUtxo.output.amount,
541
+ scriptAddr
542
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr2([])).txInScript(this.scriptCbor).txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive).requiredSignerHash(deserializeAddress(recipientAddress).pubKeyHash).requiredSignerHash(deserializeAddress(initiatorAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
498
543
  collateral.input.txHash,
499
544
  collateral.input.outputIndex,
500
545
  collateral.output.amount,
@@ -507,24 +552,26 @@ var MeshMarketplaceContract = class extends MeshTxInitiator {
507
552
  };
508
553
  };
509
554
 
510
- // src/vesting/offchain.ts
555
+ // src/giftcard/offchain.ts
511
556
  import {
512
- mConStr0 as mConStr02,
513
- SLOT_CONFIG_NETWORK,
514
- unixTimeToEnclosingSlot
557
+ builtinByteString,
558
+ mConStr0,
559
+ mConStr1 as mConStr12,
560
+ stringToHex,
561
+ txOutRef
515
562
  } from "@meshsdk/common";
516
563
  import {
517
- deserializeAddress as deserializeAddress2,
518
564
  deserializeDatum as deserializeDatum2,
565
+ resolveScriptHash,
519
566
  serializePlutusScript as serializePlutusScript2
520
567
  } from "@meshsdk/core";
521
568
  import { applyParamsToScript as applyParamsToScript2 } from "@meshsdk/core-csl";
522
569
 
523
- // src/vesting/aiken-workspace/plutus.json
570
+ // src/giftcard/aiken-workspace/plutus.json
524
571
  var plutus_default2 = {
525
572
  preamble: {
526
- title: "meshjs/vesting",
527
- description: "Aiken contracts for project 'meshjs/vesting'",
573
+ title: "meshjs/giftcard",
574
+ description: "Aiken contracts for project 'meshjs/giftcard'",
528
575
  version: "0.0.0",
529
576
  plutusVersion: "v2",
530
577
  compiler: {
@@ -535,21 +582,60 @@ var plutus_default2 = {
535
582
  },
536
583
  validators: [
537
584
  {
538
- title: "vesting.vesting",
585
+ title: "oneshot.gift_card",
586
+ redeemer: {
587
+ title: "rdmr",
588
+ schema: {
589
+ $ref: "#/definitions/oneshot~1Action"
590
+ }
591
+ },
592
+ parameters: [
593
+ {
594
+ title: "token_name",
595
+ schema: {
596
+ $ref: "#/definitions/ByteArray"
597
+ }
598
+ },
599
+ {
600
+ title: "utxo_ref",
601
+ schema: {
602
+ $ref: "#/definitions/aiken~1transaction~1OutputReference"
603
+ }
604
+ }
605
+ ],
606
+ compiledCode: "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
607
+ hash: "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
608
+ },
609
+ {
610
+ title: "oneshot.redeem",
539
611
  datum: {
540
- title: "datum",
612
+ title: "_d",
541
613
  schema: {
542
- $ref: "#/definitions/vesting~1types~1VestingDatum"
614
+ $ref: "#/definitions/Data"
543
615
  }
544
616
  },
545
617
  redeemer: {
546
- title: "_redeemer",
618
+ title: "_r",
547
619
  schema: {
548
620
  $ref: "#/definitions/Data"
549
621
  }
550
622
  },
551
- compiledCode: "5901c40100003232323232323223222533300532533233007300130083754600460126ea800c4c8c8c94ccc028cc004dd6180118061baa3003300c375400c6eb8c014c030dd50048a511533300a330013758600460186ea8c00cc030dd50031bae300f30103010300c3754012266446464646464a666022601660246ea80084c94ccc0480104cdc40038008011bad301630133754004002264a666022601660246ea80084c94ccc0480100084cdc48038009bad3016301337540040022940c050008cdc424000601e6ea8c04cc050004cc044c048004cc044ccc034cdc424000601c6ea8c048c04c00530103d87a80004c0103d87980004bd7018071baa3005300e3754004601e602060206020602060206020602060186ea8c00cc030dd50031bad3003300c3754012294088c8cc00400400c894ccc040004528099299980719b8f375c602600400829444cc00c00c004c04c0048c038c03cc03cc03cc03cc03cc03cc03cc03c0048c034004dc3a400429408c02cc0300045261365653330023370e900018019baa0011323232323232533300b300e002149858dd7180600098060011bae300a001300a002375a601000260086ea8004595cd2ab9d5573caae7d5d02ba157441",
552
- hash: "ac96a3fa3cabf670268a88720402c715ed5fd73ffb3276e6092ead00"
623
+ parameters: [
624
+ {
625
+ title: "token_name",
626
+ schema: {
627
+ $ref: "#/definitions/ByteArray"
628
+ }
629
+ },
630
+ {
631
+ title: "policy_id",
632
+ schema: {
633
+ $ref: "#/definitions/ByteArray"
634
+ }
635
+ }
636
+ ],
637
+ compiledCode: "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
638
+ hash: "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
553
639
  }
554
640
  ],
555
641
  definitions: {
@@ -563,119 +649,179 @@ var plutus_default2 = {
563
649
  Int: {
564
650
  dataType: "integer"
565
651
  },
566
- "vesting/types/VestingDatum": {
567
- title: "VestingDatum",
652
+ "aiken/transaction/OutputReference": {
653
+ title: "OutputReference",
654
+ description: "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",
568
655
  anyOf: [
569
656
  {
570
- title: "VestingDatum",
657
+ title: "OutputReference",
571
658
  dataType: "constructor",
572
659
  index: 0,
573
660
  fields: [
574
661
  {
575
- title: "lock_until",
576
- description: "POSIX time in second, e.g. 1672843961000",
577
- $ref: "#/definitions/Int"
662
+ title: "transaction_id",
663
+ $ref: "#/definitions/aiken~1transaction~1TransactionId"
578
664
  },
579
665
  {
580
- title: "owner",
581
- description: "Owner's credentials",
582
- $ref: "#/definitions/ByteArray"
583
- },
666
+ title: "output_index",
667
+ $ref: "#/definitions/Int"
668
+ }
669
+ ]
670
+ }
671
+ ]
672
+ },
673
+ "aiken/transaction/TransactionId": {
674
+ title: "TransactionId",
675
+ description: "A unique transaction identifier, as the hash of a transaction body. Note that the transaction id\n isn't a direct hash of the `Transaction` as visible on-chain. Rather, they correspond to hash\n digests of transaction body as they are serialized on the network.",
676
+ anyOf: [
677
+ {
678
+ title: "TransactionId",
679
+ dataType: "constructor",
680
+ index: 0,
681
+ fields: [
584
682
  {
585
- title: "beneficiary",
586
- description: "Beneficiary's credentials",
683
+ title: "hash",
587
684
  $ref: "#/definitions/ByteArray"
588
685
  }
589
686
  ]
590
687
  }
591
688
  ]
689
+ },
690
+ "oneshot/Action": {
691
+ title: "Action",
692
+ anyOf: [
693
+ {
694
+ title: "Mint",
695
+ dataType: "constructor",
696
+ index: 0,
697
+ fields: []
698
+ },
699
+ {
700
+ title: "Burn",
701
+ dataType: "constructor",
702
+ index: 1,
703
+ fields: []
704
+ }
705
+ ]
592
706
  }
593
707
  }
594
708
  };
595
709
 
596
- // src/vesting/offchain.ts
597
- var MeshVestingBlueprint = plutus_default2;
598
- var MeshVestingContract = class extends MeshTxInitiator {
599
- scriptCbor = applyParamsToScript2(plutus_default2.validators[0].compiledCode, []);
600
- constructor(inputs) {
710
+ // src/giftcard/offchain.ts
711
+ var MeshGiftCardBlueprint = plutus_default2;
712
+ var MeshGiftCardContract = class extends MeshTxInitiator {
713
+ tokenNameHex = "";
714
+ paramUtxo = { outputIndex: 0, txHash: "" };
715
+ giftCardCbor = (tokenNameHex, utxoTxHash, utxoTxId) => {
716
+ return applyParamsToScript2(
717
+ plutus_default2.validators[0].compiledCode,
718
+ [builtinByteString(tokenNameHex), txOutRef(utxoTxHash, utxoTxId)],
719
+ "JSON"
720
+ );
721
+ };
722
+ redeemCbor = (tokenNameHex, policyId) => applyParamsToScript2(plutus_default2.validators[1].compiledCode, [
723
+ tokenNameHex,
724
+ policyId
725
+ ]);
726
+ constructor(inputs, tokenNameHex, paramUtxo) {
601
727
  super(inputs);
728
+ if (tokenNameHex) {
729
+ this.tokenNameHex = tokenNameHex;
730
+ }
731
+ if (paramUtxo) {
732
+ this.paramUtxo = paramUtxo;
733
+ }
602
734
  }
603
- depositFund = async (amount, lockUntilTimeStampMs, beneficiary) => {
604
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
605
- const scriptAddr = serializePlutusScript2(
606
- { code: this.scriptCbor, version: "V2" },
735
+ createGiftCard = async (tokenName2, giftValue) => {
736
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
737
+ const tokenNameHex = stringToHex(tokenName2);
738
+ const firstUtxo = utxos[0];
739
+ if (firstUtxo === void 0) throw new Error("No UTXOs available");
740
+ const remainingUtxos = utxos.slice(1);
741
+ const giftCardScript = this.giftCardCbor(
742
+ tokenNameHex,
743
+ firstUtxo.input.txHash,
744
+ firstUtxo.input.outputIndex
745
+ );
746
+ const giftCardPolicy = resolveScriptHash(giftCardScript, "V2");
747
+ const redeemScript = {
748
+ code: this.redeemCbor(tokenNameHex, giftCardPolicy),
749
+ version: "V2"
750
+ };
751
+ const redeemAddr = serializePlutusScript2(
752
+ redeemScript,
607
753
  void 0,
608
- 0
754
+ this.networkId
609
755
  ).address;
610
- const { pubKeyHash: ownerPubKeyHash } = deserializeAddress2(walletAddress);
611
- const { pubKeyHash: beneficiaryPubKeyHash } = deserializeAddress2(beneficiary);
612
- await this.mesh.txOut(scriptAddr, amount).txOutInlineDatumValue(
613
- mConStr02([
614
- lockUntilTimeStampMs,
615
- ownerPubKeyHash,
616
- beneficiaryPubKeyHash
617
- ])
618
- ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
756
+ await this.mesh.txIn(
757
+ firstUtxo.input.txHash,
758
+ firstUtxo.input.outputIndex,
759
+ firstUtxo.output.amount,
760
+ firstUtxo.output.address
761
+ ).mintPlutusScriptV2().mint("1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue(mConStr0([])).txOut(redeemAddr, [
762
+ ...giftValue,
763
+ { unit: giftCardPolicy + tokenNameHex, quantity: "1" }
764
+ ]).txOutInlineDatumValue([
765
+ firstUtxo.input.txHash,
766
+ firstUtxo.input.outputIndex,
767
+ tokenNameHex
768
+ ]).changeAddress(walletAddress).txInCollateral(
769
+ collateral.input.txHash,
770
+ collateral.input.outputIndex,
771
+ collateral.output.amount,
772
+ collateral.output.address
773
+ ).selectUtxosFrom(remainingUtxos).complete();
774
+ this.tokenNameHex = tokenNameHex;
775
+ this.paramUtxo = firstUtxo.input;
619
776
  return this.mesh.txHex;
620
777
  };
621
- withdrawFund = async (vestingUtxo) => {
778
+ redeemGiftCard = async (giftCardUtxo) => {
622
779
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
623
- const { input: collateralInput, output: collateralOutput } = collateral;
624
- const scriptAddr = serializePlutusScript2(
625
- { code: this.scriptCbor, version: "V2" },
626
- void 0,
627
- 0
628
- ).address;
629
- const { pubKeyHash } = deserializeAddress2(walletAddress);
630
- const datum = deserializeDatum2(
631
- vestingUtxo.output.plutusData
780
+ const inlineDatum = deserializeDatum2(
781
+ giftCardUtxo.output.plutusData
782
+ ).list;
783
+ const paramTxHash = inlineDatum[0].bytes;
784
+ const paramTxId = inlineDatum[1].int;
785
+ const tokenNameHex = inlineDatum[2].bytes;
786
+ const giftCardScript = this.giftCardCbor(
787
+ tokenNameHex,
788
+ paramTxHash,
789
+ paramTxId
632
790
  );
633
- const invalidBefore = unixTimeToEnclosingSlot(
634
- Math.min(datum.fields[0].int, Date.now() - 15e3),
635
- this.networkId === 0 ? SLOT_CONFIG_NETWORK.preprod : SLOT_CONFIG_NETWORK.mainnet
636
- ) + 1;
791
+ const giftCardPolicy = resolveScriptHash(giftCardScript, "V2");
792
+ const redeemScript = this.redeemCbor(tokenNameHex, giftCardPolicy);
637
793
  await this.mesh.spendingPlutusScriptV2().txIn(
638
- vestingUtxo.input.txHash,
639
- vestingUtxo.input.outputIndex,
640
- vestingUtxo.output.amount,
641
- scriptAddr
642
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(walletAddress, []).txInCollateral(
643
- collateralInput.txHash,
644
- collateralInput.outputIndex,
645
- collateralOutput.amount,
646
- collateralOutput.address
647
- ).invalidBefore(invalidBefore).requiredSignerHash(pubKeyHash).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
648
- return this.mesh.txHex;
649
- };
794
+ giftCardUtxo.input.txHash,
795
+ giftCardUtxo.input.outputIndex,
796
+ giftCardUtxo.output.amount,
797
+ giftCardUtxo.output.address
798
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(redeemScript).mintPlutusScriptV2().mint("-1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue(mConStr12([])).changeAddress(walletAddress).txInCollateral(
799
+ collateral.input.txHash,
800
+ collateral.input.outputIndex,
801
+ collateral.output.amount,
802
+ collateral.output.address
803
+ ).selectUtxosFrom(utxos).complete();
804
+ return this.mesh.txHex;
805
+ };
650
806
  getUtxoByTxHash = async (txHash) => {
651
- return await this._getUtxoByTxHash(txHash, this.scriptCbor);
807
+ return await this._getUtxoByTxHash(txHash);
652
808
  };
653
809
  };
654
810
 
655
- // src/escrow/offchain.ts
656
- import {
657
- conStr0 as conStr02,
658
- conStr1,
659
- mConStr1 as mConStr12,
660
- mConStr2,
661
- pubKeyAddress as pubKeyAddress2,
662
- value,
663
- MeshValue
664
- } from "@meshsdk/common";
811
+ // src/hello-world/offchain.ts
665
812
  import {
666
- deserializeAddress as deserializeAddress3,
667
- deserializeDatum as deserializeDatum3,
668
- mergeAssets,
669
- serializeAddressObj as serializeAddressObj2,
670
- serializePlutusScript as serializePlutusScript3
813
+ deserializeAddress as deserializeAddress2,
814
+ mConStr0 as mConStr02,
815
+ serializePlutusScript as serializePlutusScript3,
816
+ stringToHex as stringToHex2
671
817
  } from "@meshsdk/core";
672
818
  import { applyParamsToScript as applyParamsToScript3 } from "@meshsdk/core-csl";
673
819
 
674
- // src/escrow/aiken-workspace/plutus.json
820
+ // src/hello-world/aiken-workspace/plutus.json
675
821
  var plutus_default3 = {
676
822
  preamble: {
677
- title: "meshjs/escrow",
678
- description: "Aiken contracts for project 'meshjs/escrow'",
823
+ title: "meshjs/aiken",
824
+ description: "Aiken on MeshJS",
679
825
  version: "0.0.0",
680
826
  plutusVersion: "v2",
681
827
  compiler: {
@@ -686,368 +832,95 @@ var plutus_default3 = {
686
832
  },
687
833
  validators: [
688
834
  {
689
- title: "escrow.escrow",
835
+ title: "hello_world.hello_world",
690
836
  datum: {
691
- title: "_datum",
837
+ title: "datum",
692
838
  schema: {
693
- $ref: "#/definitions/escrow~1types~1EscrowDatum"
839
+ $ref: "#/definitions/hello_world~1Datum"
694
840
  }
695
841
  },
696
842
  redeemer: {
697
843
  title: "redeemer",
698
844
  schema: {
699
- $ref: "#/definitions/escrow~1types~1EscrowRedeemer"
845
+ $ref: "#/definitions/hello_world~1Redeemer"
700
846
  }
701
847
  },
702
- compiledCode: "590c2f01000032323232323232232323232323232232322533300d3232533300f300c3010375400226464646464646464a66602e602a60306ea80044c8c8c8c8c8c8c8c8c8c94ccc084c07c0244c8c8c8c8c8c8c94ccc0acc0b800c4c94ccc0b0c0bc00c4c94ccc0a8c080c0acdd5000899192999816181118169baa001132533302d302b302e3754006264646464a666068606e004264646464a66606a66ebc024cdd2a40046607200e660726e98014cc0e404ccc0e4dd300925eb8040045281980b9bab302730363754018660326eacc09cc0d8dd51813981b1baa00d301a011302c0073302c0022323302e3756606c0044646eb4c0e0008dd7181b0009bae3034001302c003163756606a002606a0046066002605e6ea800c58c0c4c0b8dd50008b180798169baa003302f302c37540022c601a60566ea8c070c0acdd50010b18168010b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb80dd598141814801181380098119baa01813232325333024302100c132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd500089980500c1bae3031302e37540022c60106060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc058090dd7181e8010a51133003003001303d00115333035005100414a0294058c044014dd7181c181a9baa00116300f006330143301001e00230173756606c606e006660266601e03a008602c6eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa00116300c302a3754603660546ea80045858c0b0008dd6181598160011bac302a00133028374e6600802601a660506e9ccc0140440352f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1980e0151bae304300213300300300114a060860022a66607600a200829405280b180b8059bae303e303b37540022c602a01a660346602c048010603a014660326602a046016603800a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c601860546ea8c06cc0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb808c94ccc094c08cc098dd50008980819814981518139baa0014bd700a6103d87a800030153026375400244646600200200644a66605200229404c94ccc09ccdc79bae302c00200414a2266006006002605800244646600200200644a666050002297adef6c601332253330273375e603060526ea80080144cc030004dd5980d18149baa0021001302a00133002002302b001223300400223375e6028604a6ea8c058c094dd50008011119801801119baf30133024375400200444646600200200644a66604a002297ae013232533302430050021330280023300400400113300400400130290023027001223233001001323300100100322533302500114bd7009919991119198008008019129998158008801899198169ba73302d375200c6605a60540026605a605600297ae033003003302f002302d001375c60480026eacc094004cc00c00cc0a4008c09c004894ccc09000452889929998111919b89375a600e002664464a66604c6046604e6ea8004520001375a605660506ea8004c94ccc098c08cc09cdd50008a60103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a8000132323232533302c337220100042a66605866e3c0200084c05ccc0c0dd4000a5eb80530103d87a8000133006006003375a605a0066eb8c0ac008c0bc008c0b4004c8cc004004024894ccc0a80045300103d87a8000132323232533302b337220100042a66605666e3c0200084c058cc0bcdd3000a5eb80530103d87a8000133006006003375660580066eb8c0a8008c0b8008c0b0004dd7180a0009bae30160013758604e0042660060060022940c09c0048c088c08cc08c00488c8ccc00400400c0088894ccc08c00840044c8ccc010010c09c00ccccc020008dd718110009bab3023001222325333025533302800114a229405300103d87a80001301033029374c00297ae032333001001003002222533302a0021001132333004004302e0033322323300100100522533302f001133030337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0c0cdc800400109981a19bb037520106ea001c01454ccc0c0cdc78040010992999818981798191baa001133035337606ea4024c0d8c0ccdd5000802080219299981898178008a60103d87a80001301c33035375000297ae03370000e00226606866ec0dd48011ba800133006006003375a60620066eb8c0bc008c0cc008c0c4004dd718148009bad302a001302c00230250022323300100100222533302000114bd6f7b6300999119191999804001801000911319190011919198008008019129998138008a4c264a6660500022a66604a60086eb4c09cc0a8008526161323232325333029337206eb8c0a8010dd718150018a9998149804000899803803998168018010b0b1bad302a003302d003302b002302a002302a001233302230200014a0944dd598110019bae3020002302200133002002302300122223233001001005225333022001133023337606ea4014dd300225eb7bdb1804c8c8c8c94ccc08ccdc800480109981399bb037520126e9802001454ccc08ccdc78048010992999812181118129baa001133028337606ea4028c0a4c098dd5000802080219980380480400089981399bb037520046e98004cc01801800cdd598120019bae3022002302600230240013019375401e601060326ea8c028c064dd5180e180c9baa0011632323300100100722533301c00114c0103d87a800013232533301b3375e6018603a6ea80080144c018cc07c0092f5c02660080080026040004603c002603660306ea8020dd2a40006eb0c064c068c068c068c068c068c068008dd6180c000980c180c0011bac301600130123754600260246ea80108c054004528180098081baa00223013301400114984d958c94ccc030c0280044c8c8c8c94ccc04cc0580084c8c9263300b0022323300d3756602a0044646eb4c05c008dd7180a8009bae3013001300b003163756602800260280046024002601c6ea800c54ccc030c02400454ccc03cc038dd50018a4c2c2a66601860040022a66601e601c6ea800c5261616300c37540046e1d20043001007232533300930070011323232325333010301300213232498cc0200088c8cc028dd598090011191bad3014002375c60240026eb8c040004c02000c58dd598088009808801180780098059baa0021533300930060011323232323232323253330143017002132323232498cc0380108c8cc040dd5980c0011191bad301a002375c60300026eb8c058004c038014cc0300188c8cc038dd5980b0011191bad3018002375c602c0026eb8c050004c03001c58dd5980a800980a801180980098098011bab30110013011002300f001300b37540042c60126ea800488c8cc00400400c894ccc0340045261323300300330110023003300f00125333006300430073754002264646464a66601a602000426464931929998061805000899192999808980a00109924c64a66601e601a00226464a666028602e0042649318068008b180a80098089baa0021533300f300c00113232323232325333018301b002149858dd6980c800980c8011bad30170013017002375a602a00260226ea800858c03cdd50008b180900098071baa0031533300c30090011533300f300e37540062930b0b18061baa002300600316300e001300e002300c001300837540022c464a66600c600800226464a666016601c0042930b1bae300c001300837540042a66600c600600226464a666016601c0042930b1bae300c001300837540042c600c6ea8004dc3a40046e1d20005734aae7555cf2ab9f5740ae855d101",
703
- hash: "8fa9284f5889972d7260c10e940a2e1acb2114bdcea845da3d52de7d"
848
+ compiledCode: "58e901000032323232323223223225333006323253330083371e6eb8c008c028dd5002a4410d48656c6c6f2c20576f726c642100100114a06644646600200200644a66601c00229404c94ccc030cdc79bae301000200414a226600600600260200026eb0c02cc030c030c030c030c030c030c030c030c024dd5180098049baa002375c600260126ea80188c02c0045261365653330043370e900018029baa001132325333009300b002149858dd7180480098031baa0011653330023370e900018019baa0011323253330073009002149858dd7180380098021baa001165734aae7555cf2ab9f5742ae881",
849
+ hash: "c1fe430f19ac248a8a7ea47db106002c4327e542c3fdc60ad6481103"
704
850
  }
705
851
  ],
706
852
  definitions: {
707
853
  ByteArray: {
708
854
  dataType: "bytes"
709
855
  },
710
- Int: {
711
- dataType: "integer"
712
- },
713
- List$Pair$ByteArray_Int: {
714
- dataType: "map",
715
- keys: {
716
- $ref: "#/definitions/ByteArray"
717
- },
718
- values: {
719
- $ref: "#/definitions/Int"
720
- }
721
- },
722
- List$Pair$ByteArray_List$Pair$ByteArray_Int: {
723
- dataType: "map",
724
- keys: {
725
- $ref: "#/definitions/ByteArray"
726
- },
727
- values: {
728
- $ref: "#/definitions/List$Pair$ByteArray_Int"
729
- }
730
- },
731
- "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
732
- title: "Optional",
733
- anyOf: [
734
- {
735
- title: "Some",
736
- description: "An optional value.",
737
- dataType: "constructor",
738
- index: 0,
739
- fields: [
740
- {
741
- $ref: "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
742
- }
743
- ]
744
- },
745
- {
746
- title: "None",
747
- description: "Nothing.",
748
- dataType: "constructor",
749
- index: 1,
750
- fields: []
751
- }
752
- ]
753
- },
754
- "aiken/transaction/credential/Address": {
755
- title: "Address",
756
- description: "A Cardano `Address` typically holding one or two credential references.\n\n Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are\n completely excluded from Plutus contexts. Thus, from an on-chain\n perspective only exists addresses of type 00, 01, ..., 07 as detailed\n in [CIP-0019 :: Shelley Addresses](https://cips.cardano.org/cip/CIP-19).",
757
- anyOf: [
758
- {
759
- title: "Address",
760
- dataType: "constructor",
761
- index: 0,
762
- fields: [
763
- {
764
- title: "payment_credential",
765
- $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
766
- },
767
- {
768
- title: "stake_credential",
769
- $ref: "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
770
- }
771
- ]
772
- }
773
- ]
774
- },
775
- "aiken/transaction/credential/Credential": {
776
- title: "Credential",
777
- description: "A general structure for representing an on-chain `Credential`.\n\n Credentials are always one of two kinds: a direct public/private key\n pair, or a script (native or Plutus).",
856
+ "hello_world/Datum": {
857
+ title: "Datum",
778
858
  anyOf: [
779
859
  {
780
- title: "VerificationKeyCredential",
860
+ title: "Datum",
781
861
  dataType: "constructor",
782
862
  index: 0,
783
863
  fields: [
784
864
  {
865
+ title: "owner",
785
866
  $ref: "#/definitions/ByteArray"
786
867
  }
787
868
  ]
788
- },
789
- {
790
- title: "ScriptCredential",
791
- dataType: "constructor",
792
- index: 1,
793
- fields: [
794
- {
795
- $ref: "#/definitions/ByteArray"
796
- }
797
- ]
798
- }
799
- ]
800
- },
801
- "aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
802
- title: "Referenced",
803
- description: "Represent a type of object that can be represented either inline (by hash)\n or via a reference (i.e. a pointer to an on-chain location).\n\n This is mainly use for capturing pointers to a stake credential\n registration certificate in the case of so-called pointer addresses.",
804
- anyOf: [
805
- {
806
- title: "Inline",
807
- dataType: "constructor",
808
- index: 0,
809
- fields: [
810
- {
811
- $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
812
- }
813
- ]
814
- },
815
- {
816
- title: "Pointer",
817
- dataType: "constructor",
818
- index: 1,
819
- fields: [
820
- {
821
- title: "slot_number",
822
- $ref: "#/definitions/Int"
823
- },
824
- {
825
- title: "transaction_index",
826
- $ref: "#/definitions/Int"
827
- },
828
- {
829
- title: "certificate_index",
830
- $ref: "#/definitions/Int"
831
- }
832
- ]
833
869
  }
834
870
  ]
835
871
  },
836
- "escrow/types/EscrowDatum": {
837
- title: "EscrowDatum",
838
- anyOf: [
839
- {
840
- title: "Initiation",
841
- dataType: "constructor",
842
- index: 0,
843
- fields: [
844
- {
845
- title: "initiator",
846
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
847
- },
848
- {
849
- title: "initiator_assets",
850
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
851
- }
852
- ]
853
- },
854
- {
855
- title: "ActiveEscrow",
856
- dataType: "constructor",
857
- index: 1,
858
- fields: [
859
- {
860
- title: "initiator",
861
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
862
- },
863
- {
864
- title: "initiator_assets",
865
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
866
- },
867
- {
868
- title: "recipient",
869
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
870
- },
871
- {
872
- title: "recipient_assets",
873
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
874
- }
875
- ]
876
- }
877
- ]
878
- },
879
- "escrow/types/EscrowRedeemer": {
880
- title: "EscrowRedeemer",
872
+ "hello_world/Redeemer": {
873
+ title: "Redeemer",
881
874
  anyOf: [
882
875
  {
883
- title: "RecipientDeposit",
876
+ title: "Redeemer",
884
877
  dataType: "constructor",
885
878
  index: 0,
886
879
  fields: [
887
880
  {
888
- title: "recipient",
889
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
890
- },
891
- {
892
- title: "recipient_assets",
893
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
881
+ title: "msg",
882
+ $ref: "#/definitions/ByteArray"
894
883
  }
895
884
  ]
896
- },
897
- {
898
- title: "CancelTrade",
899
- dataType: "constructor",
900
- index: 1,
901
- fields: []
902
- },
903
- {
904
- title: "CompleteTrade",
905
- dataType: "constructor",
906
- index: 2,
907
- fields: []
908
885
  }
909
886
  ]
910
887
  }
911
888
  }
912
889
  };
913
890
 
914
- // src/escrow/offchain.ts
915
- var MeshEscrowBlueprint = plutus_default3;
916
- var initiateEscrowDatum = (walletAddress, amount) => {
917
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress3(walletAddress);
918
- return conStr02([
919
- pubKeyAddress2(pubKeyHash, stakeCredentialHash),
920
- value(amount)
921
- ]);
922
- };
923
- var activeEscrowDatum = (initiationDatum, walletAddress, amount) => {
924
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress3(walletAddress);
925
- const [initiator, initiatorAmount] = initiationDatum.fields;
926
- return conStr1([
927
- initiator,
928
- initiatorAmount,
929
- pubKeyAddress2(pubKeyHash, stakeCredentialHash),
930
- value(amount)
931
- ]);
932
- };
933
- var recipientDepositRedeemer = (recipient, depositAmount) => initiateEscrowDatum(recipient, depositAmount);
934
- var MeshEscrowContract = class extends MeshTxInitiator {
891
+ // src/hello-world/offchain.ts
892
+ var MeshHelloWorldBlueprint = plutus_default3;
893
+ var MeshHelloWorldContract = class extends MeshTxInitiator {
935
894
  scriptCbor = applyParamsToScript3(plutus_default3.validators[0].compiledCode, []);
936
895
  constructor(inputs) {
937
896
  super(inputs);
938
897
  }
939
- initiateEscrow = async (escrowAmount) => {
940
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
941
- const { address: scriptAddr } = serializePlutusScript3(
898
+ getScript = () => {
899
+ const { address } = serializePlutusScript3(
942
900
  { code: this.scriptCbor, version: "V2" },
943
901
  void 0,
944
902
  this.networkId
945
903
  );
946
- await this.mesh.txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(
947
- initiateEscrowDatum(walletAddress, escrowAmount),
948
- "JSON"
949
- ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
950
- return this.mesh.txHex;
951
- };
952
- cancelEscrow = async (escrowUtxo) => {
953
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
954
- const { address: scriptAddr } = serializePlutusScript3(
955
- { code: this.scriptCbor, version: "V2" },
956
- void 0,
957
- this.networkId
958
- );
959
- const inputDatum = deserializeDatum3(
960
- escrowUtxo.output.plutusData
961
- );
962
- if (inputDatum.constructor === 1) {
963
- const [
964
- initiatorAddressObj,
965
- initiatorAmount,
966
- recipientAddressObj,
967
- recipientAmount
968
- ] = inputDatum.fields;
969
- const initiatorAddress = serializeAddressObj2(initiatorAddressObj);
970
- const recipientAddress = serializeAddressObj2(recipientAddressObj);
971
- const initiatorToReceive = MeshValue.fromValue(initiatorAmount).toAssets();
972
- const recipientToReceive = MeshValue.fromValue(recipientAmount).toAssets();
973
- this.mesh.txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive);
974
- }
975
- await this.mesh.spendingPlutusScriptV2().txIn(
976
- escrowUtxo.input.txHash,
977
- escrowUtxo.input.outputIndex,
978
- escrowUtxo.output.amount,
979
- scriptAddr
980
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr12([])).txInScript(this.scriptCbor).requiredSignerHash(deserializeAddress3(walletAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
981
- collateral.input.txHash,
982
- collateral.input.outputIndex,
983
- collateral.output.amount,
984
- collateral.output.address
985
- ).selectUtxosFrom(utxos).complete();
986
- return this.mesh.txHex;
987
- };
988
- recipientDeposit = async (escrowUtxo, depositAmount) => {
989
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
990
- const { address: scriptAddr } = serializePlutusScript3(
991
- { code: this.scriptCbor, version: "V2" },
992
- void 0,
993
- this.networkId
994
- );
995
- const inputDatum = deserializeDatum3(
996
- escrowUtxo.output.plutusData
997
- );
998
- const outputDatum = activeEscrowDatum(
999
- inputDatum,
1000
- walletAddress,
1001
- depositAmount
1002
- );
1003
- const inputAssets = MeshValue.fromValue(inputDatum.fields[1]).toAssets();
1004
- const escrowAmount = mergeAssets([...depositAmount, ...inputAssets]);
1005
- await this.mesh.spendingPlutusScriptV2().txIn(
1006
- escrowUtxo.input.txHash,
1007
- escrowUtxo.input.outputIndex,
1008
- escrowUtxo.output.amount,
1009
- scriptAddr
1010
- ).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(
1011
- recipientDepositRedeemer(walletAddress, depositAmount),
1012
- "JSON",
1013
- {
1014
- mem: 7e6,
1015
- steps: 3e9
1016
- }
1017
- ).txInScript(this.scriptCbor).txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).txInCollateral(
1018
- collateral.input.txHash,
1019
- collateral.input.outputIndex,
1020
- collateral.output.amount,
1021
- collateral.output.address
1022
- ).selectUtxosFrom(utxos).complete();
1023
- return this.mesh.txHex;
904
+ return {
905
+ scriptAddr: address
906
+ };
1024
907
  };
1025
- completeEscrow = async (escrowUtxo) => {
1026
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1027
- const { address: scriptAddr } = serializePlutusScript3(
1028
- { code: this.scriptCbor, version: "V2" },
1029
- void 0,
1030
- this.networkId
1031
- );
1032
- const inputDatum = deserializeDatum3(
1033
- escrowUtxo.output.plutusData
1034
- );
1035
- const [
1036
- initiatorAddressObj,
1037
- initiatorAmount,
1038
- recipientAddressObj,
1039
- recipientAmount
1040
- ] = inputDatum.fields;
1041
- const initiatorAddress = serializeAddressObj2(initiatorAddressObj);
1042
- const recipientAddress = serializeAddressObj2(recipientAddressObj);
1043
- const initiatorToReceive = MeshValue.fromValue(recipientAmount).toAssets();
1044
- const recipientToReceive = MeshValue.fromValue(initiatorAmount).toAssets();
908
+ lockAsset = async (assets) => {
909
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
910
+ const { scriptAddr } = this.getScript();
911
+ const signerHash = deserializeAddress2(walletAddress).pubKeyHash;
912
+ await this.mesh.txOut(scriptAddr, assets).txOutDatumHashValue(mConStr02([signerHash])).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
913
+ return this.mesh.txHex;
914
+ };
915
+ unlockAsset = async (scriptUtxo, message) => {
916
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
917
+ const signerHash = deserializeAddress2(walletAddress).pubKeyHash;
1045
918
  await this.mesh.spendingPlutusScriptV2().txIn(
1046
- escrowUtxo.input.txHash,
1047
- escrowUtxo.input.outputIndex,
1048
- escrowUtxo.output.amount,
1049
- scriptAddr
1050
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr2([])).txInScript(this.scriptCbor).txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive).requiredSignerHash(deserializeAddress3(recipientAddress).pubKeyHash).requiredSignerHash(deserializeAddress3(initiatorAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
919
+ scriptUtxo.input.txHash,
920
+ scriptUtxo.input.outputIndex,
921
+ scriptUtxo.output.amount,
922
+ scriptUtxo.output.address
923
+ ).txInScript(this.scriptCbor).txInRedeemerValue(mConStr02([stringToHex2(message)])).txInDatumValue(mConStr02([signerHash])).requiredSignerHash(signerHash).changeAddress(walletAddress).txInCollateral(
1051
924
  collateral.input.txHash,
1052
925
  collateral.input.outputIndex,
1053
926
  collateral.output.amount,
@@ -1060,26 +933,30 @@ var MeshEscrowContract = class extends MeshTxInitiator {
1060
933
  };
1061
934
  };
1062
935
 
1063
- // src/giftcard/offchain.ts
936
+ // src/marketplace/offchain.ts
1064
937
  import {
1065
- builtinByteString,
938
+ conStr0 as conStr02,
939
+ currencySymbol,
940
+ integer,
1066
941
  mConStr0 as mConStr03,
1067
942
  mConStr1 as mConStr13,
1068
- stringToHex,
1069
- txOutRef
943
+ parseAssetUnit,
944
+ pubKeyAddress as pubKeyAddress2,
945
+ tokenName
1070
946
  } from "@meshsdk/common";
1071
947
  import {
1072
- deserializeDatum as deserializeDatum4,
1073
- resolveScriptHash,
948
+ deserializeAddress as deserializeAddress3,
949
+ deserializeDatum as deserializeDatum3,
950
+ serializeAddressObj as serializeAddressObj2,
1074
951
  serializePlutusScript as serializePlutusScript4
1075
952
  } from "@meshsdk/core";
1076
953
  import { applyParamsToScript as applyParamsToScript4 } from "@meshsdk/core-csl";
1077
954
 
1078
- // src/giftcard/aiken-workspace/plutus.json
955
+ // src/marketplace/aiken-workspace/plutus.json
1079
956
  var plutus_default4 = {
1080
957
  preamble: {
1081
- title: "meshjs/giftcard",
1082
- description: "Aiken contracts for project 'meshjs/giftcard'",
958
+ title: "meshjs/marketplace",
959
+ description: "Aiken contracts for project 'meshjs/marketplace'",
1083
960
  version: "0.0.0",
1084
961
  plutusVersion: "v2",
1085
962
  compiler: {
@@ -1090,122 +967,188 @@ var plutus_default4 = {
1090
967
  },
1091
968
  validators: [
1092
969
  {
1093
- title: "oneshot.gift_card",
1094
- redeemer: {
1095
- title: "rdmr",
1096
- schema: {
1097
- $ref: "#/definitions/oneshot~1Action"
1098
- }
1099
- },
1100
- parameters: [
1101
- {
1102
- title: "token_name",
1103
- schema: {
1104
- $ref: "#/definitions/ByteArray"
1105
- }
1106
- },
1107
- {
1108
- title: "utxo_ref",
1109
- schema: {
1110
- $ref: "#/definitions/aiken~1transaction~1OutputReference"
1111
- }
1112
- }
1113
- ],
1114
- compiledCode: "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
1115
- hash: "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
1116
- },
1117
- {
1118
- title: "oneshot.redeem",
970
+ title: "marketplace.marketplace",
1119
971
  datum: {
1120
- title: "_d",
972
+ title: "datum",
1121
973
  schema: {
1122
- $ref: "#/definitions/Data"
974
+ $ref: "#/definitions/marketplace~1types~1MarketplaceDatum"
1123
975
  }
1124
976
  },
1125
977
  redeemer: {
1126
- title: "_r",
978
+ title: "redeemer",
1127
979
  schema: {
1128
- $ref: "#/definitions/Data"
980
+ $ref: "#/definitions/marketplace~1types~1MarketplaceRedeemer"
1129
981
  }
1130
982
  },
1131
983
  parameters: [
1132
984
  {
1133
- title: "token_name",
985
+ title: "owner",
1134
986
  schema: {
1135
- $ref: "#/definitions/ByteArray"
987
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
1136
988
  }
1137
989
  },
1138
990
  {
1139
- title: "policy_id",
991
+ title: "fee_percentage_basis_point",
1140
992
  schema: {
1141
- $ref: "#/definitions/ByteArray"
993
+ $ref: "#/definitions/Int"
1142
994
  }
1143
995
  }
1144
996
  ],
1145
- compiledCode: "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
1146
- hash: "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
997
+ compiledCode: "59082f01000032323232323232223223232322322533300b3232533300d3007300e375400226464a64666020601660226ea80204c94ccc044c030c048dd500089919191919191919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc044c084dd5180a18109baa00200513302300233004004001133004004001302400230220013758601660366ea8c02cc06cdd50079805980d9baa300e301b37540102a6660320022004294052819801998011bac3004301a3754601460346ea803805cc018cdc199b82375a601a60346ea805005520a09c0133002330013758600660326ea8c024c064dd50069804980c9baa0133005337006eb4c030c064dd50099998021bab300c30193754601860326ea801922010048810022323300100100322533301d00114bd6f7b63009991299980e19baf300e301e375400400a2646660020020046eacc048c07cdd50019112999811001080089919980200218130019991191980080080291299981380089981419bb037520086e9800d2f5bded8c0264646464a66605066e400200084cc0b0cdd81ba9008374c00e00a2a66605066e3c0200084c94ccc0a4c090c0a8dd500089981699bb03752012605c60566ea80040104010c94ccc0a54ccc0b00045288a5014c0103d87a80001301a3302d374c00297ae032333001001008002222533302e0021001132333004004303200333223233001001005225333033001133034337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0d0cdc800400109981c19bb037520106ea001c01454ccc0d0cdc7804001099299981a9818181b1baa001133039337606ea4024c0e8c0dcdd5000802080219299981a98180008a60103d87a80001302633039375000297ae03370000e00226607066ec0dd48011ba800133006006003375a606a0066eb8c0cc008c0dc008c0d4004dd718168009bad302e001303000213302c337606ea4008dd3000998030030019bab3029003375c604e004605600460520026eb8c084004dd5981100098120010800980f800998010011810000911919800800991980080080191299980e8008a5eb804c8ccc888c8cc00400400c894ccc08c004400c4c8cc094dd3998129ba90063302530220013302530230014bd7019801801981380118128009bae301c0013756603a002660060066042004603e00244a66603800229444c94ccc068c8cdc49bad3007001333008006375c601a0026eb8c040004dd6180f8010998018018008a50301f0012301a301b301b0012223253330173011301837540022900009bad301c3019375400264a66602e602260306ea8004530103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301d337220100042a66603a66e3c0200084c038cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301c337220100042a66603866e3c0200084c034cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c07400494ccc04cc03800452f5bded8c0264646600200297adef6c6022533301900113301a337609801014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c068004c058c04cdd50008b19198008009bac300330133754600660266ea801c894ccc054004530103d87a80001323253330143375e600c602c6ea800801c4c014cc0600092f5c02660080080026032004602e002264a666022601860246ea80044cc88c8cc00400400c894ccc060004528099299980b19b8f375c603600400829444cc00c00c004c06c004dd6180b180b980b980b980b980b980b980b980b98099baa30033013375400e6eb8c058c04cdd50008b192999808980618091baa001130023301530163013375400297ae014c0103d87a8000300230123754600460246ea8030dd2a4000460280026024601e6ea8004528180098071baa00223011301200114984d958c94ccc028c01400454ccc034c030dd50010a4c2c2a66601460080022a66601a60186ea80085261616300a375400264a666010600660126ea80104c8c8c8c8c8c8c8c94ccc04cc0580084c9265333010300b3011375400e264646464a66602e6034004264649319299980b180880089919299980d980f00109924c64a666032602800226464a66603c604200426493180a0008b180f800980d9baa002153330193013001132323232323253330223025002149858dd6981180098118011bad30210013021002375a603e00260366ea800858c064dd50008b180e000980c1baa00315333016301000115333019301837540062930b0b180b1baa002300d003163018001301800230160013012375400e2c2c6eb8c050004c050008dd7180900098090011bad30100013010002300e001300a37540082c464a666012600800226464a66601c60220042930b1bae300f001300b37540042a666012600600226464a66601c60220042930b1bae300f001300b37540042c60126ea8004dc3a40046e1d2000375a002ae6955ceaab9e5573eae815d0aba21",
998
+ hash: "96dbc09c69d812e157d42967587c459b60f5dd21b1902312045586c4"
1147
999
  }
1148
1000
  ],
1149
1001
  definitions: {
1150
1002
  ByteArray: {
1151
1003
  dataType: "bytes"
1152
1004
  },
1153
- Data: {
1154
- title: "Data",
1155
- description: "Any Plutus data."
1156
- },
1157
1005
  Int: {
1158
1006
  dataType: "integer"
1159
1007
  },
1160
- "aiken/transaction/OutputReference": {
1161
- title: "OutputReference",
1162
- description: "An `OutputReference` is a unique reference to an output on-chain. The `output_index`\n corresponds to the position in the output list of the transaction (identified by its id)\n that produced that output",
1008
+ "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
1009
+ title: "Optional",
1163
1010
  anyOf: [
1164
1011
  {
1165
- title: "OutputReference",
1012
+ title: "Some",
1013
+ description: "An optional value.",
1166
1014
  dataType: "constructor",
1167
1015
  index: 0,
1168
1016
  fields: [
1169
1017
  {
1170
- title: "transaction_id",
1171
- $ref: "#/definitions/aiken~1transaction~1TransactionId"
1018
+ $ref: "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
1019
+ }
1020
+ ]
1021
+ },
1022
+ {
1023
+ title: "None",
1024
+ description: "Nothing.",
1025
+ dataType: "constructor",
1026
+ index: 1,
1027
+ fields: []
1028
+ }
1029
+ ]
1030
+ },
1031
+ "aiken/transaction/credential/Address": {
1032
+ title: "Address",
1033
+ description: "A Cardano `Address` typically holding one or two credential references.\n\n Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are\n completely excluded from Plutus contexts. Thus, from an on-chain\n perspective only exists addresses of type 00, 01, ..., 07 as detailed\n in [CIP-0019 :: Shelley Addresses](https://cips.cardano.org/cip/CIP-19).",
1034
+ anyOf: [
1035
+ {
1036
+ title: "Address",
1037
+ dataType: "constructor",
1038
+ index: 0,
1039
+ fields: [
1040
+ {
1041
+ title: "payment_credential",
1042
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
1172
1043
  },
1173
1044
  {
1174
- title: "output_index",
1045
+ title: "stake_credential",
1046
+ $ref: "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
1047
+ }
1048
+ ]
1049
+ }
1050
+ ]
1051
+ },
1052
+ "aiken/transaction/credential/Credential": {
1053
+ title: "Credential",
1054
+ description: "A general structure for representing an on-chain `Credential`.\n\n Credentials are always one of two kinds: a direct public/private key\n pair, or a script (native or Plutus).",
1055
+ anyOf: [
1056
+ {
1057
+ title: "VerificationKeyCredential",
1058
+ dataType: "constructor",
1059
+ index: 0,
1060
+ fields: [
1061
+ {
1062
+ $ref: "#/definitions/ByteArray"
1063
+ }
1064
+ ]
1065
+ },
1066
+ {
1067
+ title: "ScriptCredential",
1068
+ dataType: "constructor",
1069
+ index: 1,
1070
+ fields: [
1071
+ {
1072
+ $ref: "#/definitions/ByteArray"
1073
+ }
1074
+ ]
1075
+ }
1076
+ ]
1077
+ },
1078
+ "aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
1079
+ title: "Referenced",
1080
+ description: "Represent a type of object that can be represented either inline (by hash)\n or via a reference (i.e. a pointer to an on-chain location).\n\n This is mainly use for capturing pointers to a stake credential\n registration certificate in the case of so-called pointer addresses.",
1081
+ anyOf: [
1082
+ {
1083
+ title: "Inline",
1084
+ dataType: "constructor",
1085
+ index: 0,
1086
+ fields: [
1087
+ {
1088
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
1089
+ }
1090
+ ]
1091
+ },
1092
+ {
1093
+ title: "Pointer",
1094
+ dataType: "constructor",
1095
+ index: 1,
1096
+ fields: [
1097
+ {
1098
+ title: "slot_number",
1099
+ $ref: "#/definitions/Int"
1100
+ },
1101
+ {
1102
+ title: "transaction_index",
1103
+ $ref: "#/definitions/Int"
1104
+ },
1105
+ {
1106
+ title: "certificate_index",
1175
1107
  $ref: "#/definitions/Int"
1176
1108
  }
1177
1109
  ]
1178
1110
  }
1179
1111
  ]
1180
1112
  },
1181
- "aiken/transaction/TransactionId": {
1182
- title: "TransactionId",
1183
- description: "A unique transaction identifier, as the hash of a transaction body. Note that the transaction id\n isn't a direct hash of the `Transaction` as visible on-chain. Rather, they correspond to hash\n digests of transaction body as they are serialized on the network.",
1113
+ "marketplace/types/MarketplaceDatum": {
1114
+ title: "MarketplaceDatum",
1184
1115
  anyOf: [
1185
1116
  {
1186
- title: "TransactionId",
1117
+ title: "MarketplaceDatum",
1187
1118
  dataType: "constructor",
1188
1119
  index: 0,
1189
1120
  fields: [
1190
1121
  {
1191
- title: "hash",
1122
+ title: "seller",
1123
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
1124
+ },
1125
+ {
1126
+ title: "price",
1127
+ $ref: "#/definitions/Int"
1128
+ },
1129
+ {
1130
+ title: "policy",
1131
+ $ref: "#/definitions/ByteArray"
1132
+ },
1133
+ {
1134
+ title: "tokenName",
1192
1135
  $ref: "#/definitions/ByteArray"
1193
1136
  }
1194
1137
  ]
1195
1138
  }
1196
1139
  ]
1197
1140
  },
1198
- "oneshot/Action": {
1199
- title: "Action",
1141
+ "marketplace/types/MarketplaceRedeemer": {
1142
+ title: "MarketplaceRedeemer",
1200
1143
  anyOf: [
1201
1144
  {
1202
- title: "Mint",
1145
+ title: "Buy",
1203
1146
  dataType: "constructor",
1204
1147
  index: 0,
1205
1148
  fields: []
1206
1149
  },
1207
1150
  {
1208
- title: "Burn",
1151
+ title: "Close",
1209
1152
  dataType: "constructor",
1210
1153
  index: 1,
1211
1154
  fields: []
@@ -1215,95 +1158,130 @@ var plutus_default4 = {
1215
1158
  }
1216
1159
  };
1217
1160
 
1218
- // src/giftcard/offchain.ts
1219
- var MeshGiftCardBlueprint = plutus_default4;
1220
- var MeshGiftCardContract = class extends MeshTxInitiator {
1221
- tokenNameHex = "";
1222
- paramUtxo = { outputIndex: 0, txHash: "" };
1223
- giftCardCbor = (tokenNameHex, utxoTxHash, utxoTxId) => {
1224
- return applyParamsToScript4(
1225
- plutus_default4.validators[0].compiledCode,
1226
- [builtinByteString(tokenNameHex), txOutRef(utxoTxHash, utxoTxId)],
1227
- "JSON"
1228
- );
1229
- };
1230
- redeemCbor = (tokenNameHex, policyId) => applyParamsToScript4(plutus_default4.validators[1].compiledCode, [
1231
- tokenNameHex,
1232
- policyId
1161
+ // src/marketplace/offchain.ts
1162
+ var MeshMarketplaceBlueprint = plutus_default4;
1163
+ var marketplaceDatum = (sellerAddress, lovelaceFee, assetHex) => {
1164
+ const { pubKeyHash, stakeCredentialHash } = deserializeAddress3(sellerAddress);
1165
+ const { policyId, assetName } = parseAssetUnit(assetHex);
1166
+ return conStr02([
1167
+ pubKeyAddress2(pubKeyHash, stakeCredentialHash),
1168
+ integer(lovelaceFee),
1169
+ currencySymbol(policyId),
1170
+ tokenName(assetName)
1233
1171
  ]);
1234
- constructor(inputs, tokenNameHex, paramUtxo) {
1172
+ };
1173
+ var MeshMarketplaceContract = class extends MeshTxInitiator {
1174
+ ownerAddress;
1175
+ feePercentageBasisPoint;
1176
+ scriptCbor;
1177
+ constructor(inputs, ownerAddress, feePercentageBasisPoint) {
1235
1178
  super(inputs);
1236
- if (tokenNameHex) {
1237
- this.tokenNameHex = tokenNameHex;
1238
- }
1239
- if (paramUtxo) {
1240
- this.paramUtxo = paramUtxo;
1241
- }
1242
- }
1243
- createGiftCard = async (tokenName2, giftValue) => {
1244
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1245
- const tokenNameHex = stringToHex(tokenName2);
1246
- const firstUtxo = utxos[0];
1247
- if (firstUtxo === void 0) throw new Error("No UTXOs available");
1248
- const remainingUtxos = utxos.slice(1);
1249
- const giftCardScript = this.giftCardCbor(
1250
- tokenNameHex,
1251
- firstUtxo.input.txHash,
1252
- firstUtxo.input.outputIndex
1179
+ this.ownerAddress = ownerAddress;
1180
+ this.feePercentageBasisPoint = feePercentageBasisPoint;
1181
+ const { pubKeyHash, stakeCredentialHash } = deserializeAddress3(ownerAddress);
1182
+ this.scriptCbor = applyParamsToScript4(
1183
+ plutus_default4.validators[0].compiledCode,
1184
+ [
1185
+ pubKeyAddress2(pubKeyHash, stakeCredentialHash),
1186
+ integer(feePercentageBasisPoint)
1187
+ ],
1188
+ "JSON"
1253
1189
  );
1254
- const giftCardPolicy = resolveScriptHash(giftCardScript, "V2");
1255
- const redeemScript = {
1256
- code: this.redeemCbor(tokenNameHex, giftCardPolicy),
1257
- version: "V2"
1258
- };
1259
- const redeemAddr = serializePlutusScript4(
1260
- redeemScript,
1190
+ }
1191
+ listAsset = async (asset, price) => {
1192
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
1193
+ const assetMap = /* @__PURE__ */ new Map();
1194
+ assetMap.set(asset, "1");
1195
+ const { address: scriptAddr } = serializePlutusScript4(
1196
+ { code: this.scriptCbor, version: "V2" },
1261
1197
  void 0,
1262
1198
  this.networkId
1263
- ).address;
1264
- await this.mesh.txIn(
1265
- firstUtxo.input.txHash,
1266
- firstUtxo.input.outputIndex,
1267
- firstUtxo.output.amount,
1268
- firstUtxo.output.address
1269
- ).mintPlutusScriptV2().mint("1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue(mConStr03([])).txOut(redeemAddr, [
1270
- ...giftValue,
1271
- { unit: giftCardPolicy + tokenNameHex, quantity: "1" }
1272
- ]).txOutInlineDatumValue([
1273
- firstUtxo.input.txHash,
1274
- firstUtxo.input.outputIndex,
1275
- tokenNameHex
1276
- ]).changeAddress(walletAddress).txInCollateral(
1199
+ );
1200
+ const tokenForSale = [{ unit: asset, quantity: "1" }];
1201
+ const outputDatum = marketplaceDatum(walletAddress, price, asset);
1202
+ await this.mesh.txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
1203
+ return this.mesh.txHex;
1204
+ };
1205
+ delistAsset = async (marketplaceUtxo) => {
1206
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1207
+ await this.mesh.spendingPlutusScriptV2().txIn(
1208
+ marketplaceUtxo.input.txHash,
1209
+ marketplaceUtxo.input.outputIndex,
1210
+ marketplaceUtxo.output.amount,
1211
+ marketplaceUtxo.output.address
1212
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr13([])).txInScript(this.scriptCbor).changeAddress(walletAddress).requiredSignerHash(deserializeAddress3(walletAddress).pubKeyHash).txInCollateral(
1277
1213
  collateral.input.txHash,
1278
1214
  collateral.input.outputIndex,
1279
1215
  collateral.output.amount,
1280
1216
  collateral.output.address
1281
- ).selectUtxosFrom(remainingUtxos).complete();
1282
- this.tokenNameHex = tokenNameHex;
1283
- this.paramUtxo = firstUtxo.input;
1217
+ ).selectUtxosFrom(utxos).complete();
1284
1218
  return this.mesh.txHex;
1285
1219
  };
1286
- redeemGiftCard = async (giftCardUtxo) => {
1220
+ purchaseAsset = async (marketplaceUtxo) => {
1287
1221
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1288
- const inlineDatum = deserializeDatum4(
1289
- giftCardUtxo.output.plutusData
1290
- ).list;
1291
- const paramTxHash = inlineDatum[0].bytes;
1292
- const paramTxId = inlineDatum[1].int;
1293
- const tokenNameHex = inlineDatum[2].bytes;
1294
- const giftCardScript = this.giftCardCbor(
1295
- tokenNameHex,
1296
- paramTxHash,
1297
- paramTxId
1222
+ const inputDatum = deserializeDatum3(
1223
+ marketplaceUtxo.output.plutusData
1224
+ );
1225
+ const inputLovelace = marketplaceUtxo.output.amount.find(
1226
+ (a) => a.unit === "lovelace"
1227
+ ).quantity;
1228
+ const tx = this.mesh.spendingPlutusScriptV2().txIn(
1229
+ marketplaceUtxo.input.txHash,
1230
+ marketplaceUtxo.input.outputIndex,
1231
+ marketplaceUtxo.output.amount,
1232
+ marketplaceUtxo.output.address
1233
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr03([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
1234
+ collateral.input.txHash,
1235
+ collateral.input.outputIndex,
1236
+ collateral.output.amount,
1237
+ collateral.output.address
1238
+ ).selectUtxosFrom(utxos);
1239
+ let ownerToReceiveLovelace = inputDatum.fields[1].int * this.feePercentageBasisPoint / 1e4;
1240
+ if (this.feePercentageBasisPoint > 0 && ownerToReceiveLovelace < 1e6) {
1241
+ ownerToReceiveLovelace = 1e6;
1242
+ }
1243
+ if (ownerToReceiveLovelace > 0) {
1244
+ const ownerAddress = this.ownerAddress;
1245
+ const ownerToReceive = [
1246
+ {
1247
+ unit: "lovelace",
1248
+ quantity: Math.ceil(ownerToReceiveLovelace).toString()
1249
+ }
1250
+ ];
1251
+ tx.txOut(ownerAddress, ownerToReceive);
1252
+ }
1253
+ const sellerToReceiveLovelace = inputDatum.fields[1].int + Number(inputLovelace);
1254
+ if (sellerToReceiveLovelace > 0) {
1255
+ const sellerAddress = serializeAddressObj2(inputDatum.fields[0]);
1256
+ const sellerToReceive = [
1257
+ {
1258
+ unit: "lovelace",
1259
+ quantity: sellerToReceiveLovelace.toString()
1260
+ }
1261
+ ];
1262
+ tx.txOut(sellerAddress, sellerToReceive);
1263
+ }
1264
+ await tx.complete();
1265
+ return this.mesh.txHex;
1266
+ };
1267
+ relistAsset = async (marketplaceUtxo, newPrice) => {
1268
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1269
+ const inputAsset = marketplaceUtxo.output.amount.find(
1270
+ (a) => a.unit !== "lovelace"
1271
+ ).unit;
1272
+ const tokenForSale = [{ unit: inputAsset, quantity: "1" }];
1273
+ const outputDatum = marketplaceDatum(walletAddress, newPrice, inputAsset);
1274
+ const { address: scriptAddr } = serializePlutusScript4(
1275
+ { code: this.scriptCbor, version: "V2" },
1276
+ void 0,
1277
+ this.networkId
1298
1278
  );
1299
- const giftCardPolicy = resolveScriptHash(giftCardScript, "V2");
1300
- const redeemScript = this.redeemCbor(tokenNameHex, giftCardPolicy);
1301
1279
  await this.mesh.spendingPlutusScriptV2().txIn(
1302
- giftCardUtxo.input.txHash,
1303
- giftCardUtxo.input.outputIndex,
1304
- giftCardUtxo.output.amount,
1305
- giftCardUtxo.output.address
1306
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(redeemScript).mintPlutusScriptV2().mint("-1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue(mConStr13([])).changeAddress(walletAddress).txInCollateral(
1280
+ marketplaceUtxo.input.txHash,
1281
+ marketplaceUtxo.input.outputIndex,
1282
+ marketplaceUtxo.output.amount,
1283
+ marketplaceUtxo.output.address
1284
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue(mConStr13([])).txInScript(this.scriptCbor).txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).requiredSignerHash(deserializeAddress3(walletAddress).pubKeyHash).txInCollateral(
1307
1285
  collateral.input.txHash,
1308
1286
  collateral.input.outputIndex,
1309
1287
  collateral.output.amount,
@@ -1312,7 +1290,7 @@ var MeshGiftCardContract = class extends MeshTxInitiator {
1312
1290
  return this.mesh.txHex;
1313
1291
  };
1314
1292
  getUtxoByTxHash = async (txHash) => {
1315
- return await this._getUtxoByTxHash(txHash);
1293
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1316
1294
  };
1317
1295
  };
1318
1296
 
@@ -1533,7 +1511,7 @@ import {
1533
1511
  } from "@meshsdk/common";
1534
1512
  import {
1535
1513
  deserializeAddress as deserializeAddress5,
1536
- deserializeDatum as deserializeDatum5,
1514
+ deserializeDatum as deserializeDatum4,
1537
1515
  serializeAddressObj as serializeAddressObj3,
1538
1516
  serializePlutusScript as serializePlutusScript6
1539
1517
  } from "@meshsdk/core";
@@ -1776,7 +1754,7 @@ var MeshSwapContract = class extends MeshTxInitiator {
1776
1754
  };
1777
1755
  acceptSwap = async (swapUtxo) => {
1778
1756
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1779
- const inlineDatum = deserializeDatum5(
1757
+ const inlineDatum = deserializeDatum4(
1780
1758
  swapUtxo.output.plutusData
1781
1759
  );
1782
1760
  const initiatorAddress = serializeAddressObj3(inlineDatum.fields[0]);
@@ -1799,7 +1777,7 @@ var MeshSwapContract = class extends MeshTxInitiator {
1799
1777
  };
1800
1778
  cancelSwap = async (swapUtxo) => {
1801
1779
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1802
- const inlineDatum = deserializeDatum5(
1780
+ const inlineDatum = deserializeDatum4(
1803
1781
  swapUtxo.output.plutusData
1804
1782
  );
1805
1783
  const initiatorAddress = serializeAddressObj3(inlineDatum.fields[0]);
@@ -1820,11 +1798,158 @@ var MeshSwapContract = class extends MeshTxInitiator {
1820
1798
  return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1821
1799
  };
1822
1800
  };
1801
+
1802
+ // src/vesting/offchain.ts
1803
+ import {
1804
+ mConStr0 as mConStr05,
1805
+ SLOT_CONFIG_NETWORK,
1806
+ unixTimeToEnclosingSlot
1807
+ } from "@meshsdk/common";
1808
+ import {
1809
+ deserializeAddress as deserializeAddress6,
1810
+ deserializeDatum as deserializeDatum5,
1811
+ serializePlutusScript as serializePlutusScript7
1812
+ } from "@meshsdk/core";
1813
+ import { applyParamsToScript as applyParamsToScript7 } from "@meshsdk/core-csl";
1814
+
1815
+ // src/vesting/aiken-workspace/plutus.json
1816
+ var plutus_default7 = {
1817
+ preamble: {
1818
+ title: "meshjs/vesting",
1819
+ description: "Aiken contracts for project 'meshjs/vesting'",
1820
+ version: "0.0.0",
1821
+ plutusVersion: "v2",
1822
+ compiler: {
1823
+ name: "Aiken",
1824
+ version: "v1.0.29-alpha+unknown"
1825
+ },
1826
+ license: "Apache-2.0"
1827
+ },
1828
+ validators: [
1829
+ {
1830
+ title: "vesting.vesting",
1831
+ datum: {
1832
+ title: "datum",
1833
+ schema: {
1834
+ $ref: "#/definitions/vesting~1types~1VestingDatum"
1835
+ }
1836
+ },
1837
+ redeemer: {
1838
+ title: "_redeemer",
1839
+ schema: {
1840
+ $ref: "#/definitions/Data"
1841
+ }
1842
+ },
1843
+ compiledCode: "5901c40100003232323232323223222533300532533233007300130083754600460126ea800c4c8c8c94ccc028cc004dd6180118061baa3003300c375400c6eb8c014c030dd50048a511533300a330013758600460186ea8c00cc030dd50031bae300f30103010300c3754012266446464646464a666022601660246ea80084c94ccc0480104cdc40038008011bad301630133754004002264a666022601660246ea80084c94ccc0480100084cdc48038009bad3016301337540040022940c050008cdc424000601e6ea8c04cc050004cc044c048004cc044ccc034cdc424000601c6ea8c048c04c00530103d87a80004c0103d87980004bd7018071baa3005300e3754004601e602060206020602060206020602060186ea8c00cc030dd50031bad3003300c3754012294088c8cc00400400c894ccc040004528099299980719b8f375c602600400829444cc00c00c004c04c0048c038c03cc03cc03cc03cc03cc03cc03cc03c0048c034004dc3a400429408c02cc0300045261365653330023370e900018019baa0011323232323232533300b300e002149858dd7180600098060011bae300a001300a002375a601000260086ea8004595cd2ab9d5573caae7d5d02ba157441",
1844
+ hash: "ac96a3fa3cabf670268a88720402c715ed5fd73ffb3276e6092ead00"
1845
+ }
1846
+ ],
1847
+ definitions: {
1848
+ ByteArray: {
1849
+ dataType: "bytes"
1850
+ },
1851
+ Data: {
1852
+ title: "Data",
1853
+ description: "Any Plutus data."
1854
+ },
1855
+ Int: {
1856
+ dataType: "integer"
1857
+ },
1858
+ "vesting/types/VestingDatum": {
1859
+ title: "VestingDatum",
1860
+ anyOf: [
1861
+ {
1862
+ title: "VestingDatum",
1863
+ dataType: "constructor",
1864
+ index: 0,
1865
+ fields: [
1866
+ {
1867
+ title: "lock_until",
1868
+ description: "POSIX time in second, e.g. 1672843961000",
1869
+ $ref: "#/definitions/Int"
1870
+ },
1871
+ {
1872
+ title: "owner",
1873
+ description: "Owner's credentials",
1874
+ $ref: "#/definitions/ByteArray"
1875
+ },
1876
+ {
1877
+ title: "beneficiary",
1878
+ description: "Beneficiary's credentials",
1879
+ $ref: "#/definitions/ByteArray"
1880
+ }
1881
+ ]
1882
+ }
1883
+ ]
1884
+ }
1885
+ }
1886
+ };
1887
+
1888
+ // src/vesting/offchain.ts
1889
+ var MeshVestingBlueprint = plutus_default7;
1890
+ var MeshVestingContract = class extends MeshTxInitiator {
1891
+ scriptCbor = applyParamsToScript7(plutus_default7.validators[0].compiledCode, []);
1892
+ constructor(inputs) {
1893
+ super(inputs);
1894
+ }
1895
+ depositFund = async (amount, lockUntilTimeStampMs, beneficiary) => {
1896
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
1897
+ const scriptAddr = serializePlutusScript7(
1898
+ { code: this.scriptCbor, version: "V2" },
1899
+ void 0,
1900
+ 0
1901
+ ).address;
1902
+ const { pubKeyHash: ownerPubKeyHash } = deserializeAddress6(walletAddress);
1903
+ const { pubKeyHash: beneficiaryPubKeyHash } = deserializeAddress6(beneficiary);
1904
+ await this.mesh.txOut(scriptAddr, amount).txOutInlineDatumValue(
1905
+ mConStr05([
1906
+ lockUntilTimeStampMs,
1907
+ ownerPubKeyHash,
1908
+ beneficiaryPubKeyHash
1909
+ ])
1910
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
1911
+ return this.mesh.txHex;
1912
+ };
1913
+ withdrawFund = async (vestingUtxo) => {
1914
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1915
+ const { input: collateralInput, output: collateralOutput } = collateral;
1916
+ const scriptAddr = serializePlutusScript7(
1917
+ { code: this.scriptCbor, version: "V2" },
1918
+ void 0,
1919
+ 0
1920
+ ).address;
1921
+ const { pubKeyHash } = deserializeAddress6(walletAddress);
1922
+ const datum = deserializeDatum5(
1923
+ vestingUtxo.output.plutusData
1924
+ );
1925
+ const invalidBefore = unixTimeToEnclosingSlot(
1926
+ Math.min(datum.fields[0].int, Date.now() - 15e3),
1927
+ this.networkId === 0 ? SLOT_CONFIG_NETWORK.preprod : SLOT_CONFIG_NETWORK.mainnet
1928
+ ) + 1;
1929
+ await this.mesh.spendingPlutusScriptV2().txIn(
1930
+ vestingUtxo.input.txHash,
1931
+ vestingUtxo.input.outputIndex,
1932
+ vestingUtxo.output.amount,
1933
+ scriptAddr
1934
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(walletAddress, []).txInCollateral(
1935
+ collateralInput.txHash,
1936
+ collateralInput.outputIndex,
1937
+ collateralOutput.amount,
1938
+ collateralOutput.address
1939
+ ).invalidBefore(invalidBefore).requiredSignerHash(pubKeyHash).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
1940
+ return this.mesh.txHex;
1941
+ };
1942
+ getUtxoByTxHash = async (txHash) => {
1943
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1944
+ };
1945
+ };
1823
1946
  export {
1824
1947
  MeshEscrowBlueprint,
1825
1948
  MeshEscrowContract,
1826
1949
  MeshGiftCardBlueprint,
1827
1950
  MeshGiftCardContract,
1951
+ MeshHelloWorldBlueprint,
1952
+ MeshHelloWorldContract,
1828
1953
  MeshMarketplaceBlueprint,
1829
1954
  MeshMarketplaceContract,
1830
1955
  MeshPaymentSplitterBlueprint,