@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.cjs CHANGED
@@ -24,6 +24,8 @@ __export(src_exports, {
24
24
  MeshEscrowContract: () => MeshEscrowContract,
25
25
  MeshGiftCardBlueprint: () => MeshGiftCardBlueprint,
26
26
  MeshGiftCardContract: () => MeshGiftCardContract,
27
+ MeshHelloWorldBlueprint: () => MeshHelloWorldBlueprint,
28
+ MeshHelloWorldContract: () => MeshHelloWorldContract,
27
29
  MeshMarketplaceBlueprint: () => MeshMarketplaceBlueprint,
28
30
  MeshMarketplaceContract: () => MeshMarketplaceContract,
29
31
  MeshPaymentSplitterBlueprint: () => MeshPaymentSplitterBlueprint,
@@ -39,7 +41,7 @@ __export(src_exports, {
39
41
  });
40
42
  module.exports = __toCommonJS(src_exports);
41
43
 
42
- // src/marketplace/offchain.ts
44
+ // src/escrow/offchain.ts
43
45
  var import_common = require("@meshsdk/common");
44
46
  var import_core = require("@meshsdk/core");
45
47
  var import_core_csl2 = require("@meshsdk/core-csl");
@@ -56,7 +58,7 @@ var MeshTxInitiator = class {
56
58
  mesh,
57
59
  fetcher,
58
60
  wallet,
59
- networkId,
61
+ networkId = 0,
60
62
  stakeCredential
61
63
  }) {
62
64
  this.mesh = mesh;
@@ -66,13 +68,11 @@ var MeshTxInitiator = class {
66
68
  if (wallet) {
67
69
  this.wallet = wallet;
68
70
  }
69
- if (networkId) {
70
- this.networkId = networkId;
71
- if (networkId === 1) {
72
- this.mesh.setNetwork("mainnet");
73
- } else {
74
- this.mesh.setNetwork("preprod");
75
- }
71
+ this.networkId = networkId;
72
+ if (networkId === 1) {
73
+ this.mesh.setNetwork("mainnet");
74
+ } else {
75
+ this.mesh.setNetwork("preprod");
76
76
  }
77
77
  if (stakeCredential) {
78
78
  this.stakeCredential = this.stakeCredential;
@@ -192,11 +192,11 @@ var MeshTxInitiator = class {
192
192
  };
193
193
  };
194
194
 
195
- // src/marketplace/aiken-workspace/plutus.json
195
+ // src/escrow/aiken-workspace/plutus.json
196
196
  var plutus_default = {
197
197
  preamble: {
198
- title: "meshjs/marketplace",
199
- description: "Aiken contracts for project 'meshjs/marketplace'",
198
+ title: "meshjs/escrow",
199
+ description: "Aiken contracts for project 'meshjs/escrow'",
200
200
  version: "0.0.0",
201
201
  plutusVersion: "v2",
202
202
  compiler: {
@@ -207,35 +207,21 @@ var plutus_default = {
207
207
  },
208
208
  validators: [
209
209
  {
210
- title: "marketplace.marketplace",
210
+ title: "escrow.escrow",
211
211
  datum: {
212
- title: "datum",
212
+ title: "_datum",
213
213
  schema: {
214
- $ref: "#/definitions/marketplace~1types~1MarketplaceDatum"
214
+ $ref: "#/definitions/escrow~1types~1EscrowDatum"
215
215
  }
216
216
  },
217
217
  redeemer: {
218
218
  title: "redeemer",
219
219
  schema: {
220
- $ref: "#/definitions/marketplace~1types~1MarketplaceRedeemer"
220
+ $ref: "#/definitions/escrow~1types~1EscrowRedeemer"
221
221
  }
222
222
  },
223
- parameters: [
224
- {
225
- title: "owner",
226
- schema: {
227
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
228
- }
229
- },
230
- {
231
- title: "fee_percentage_basis_point",
232
- schema: {
233
- $ref: "#/definitions/Int"
234
- }
235
- }
236
- ],
237
- compiledCode: "59082f01000032323232323232223223232322322533300b3232533300d3007300e375400226464a64666020601660226ea80204c94ccc044c030c048dd500089919191919191919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc044c084dd5180a18109baa00200513302300233004004001133004004001302400230220013758601660366ea8c02cc06cdd50079805980d9baa300e301b37540102a6660320022004294052819801998011bac3004301a3754601460346ea803805cc018cdc199b82375a601a60346ea805005520a09c0133002330013758600660326ea8c024c064dd50069804980c9baa0133005337006eb4c030c064dd50099998021bab300c30193754601860326ea801922010048810022323300100100322533301d00114bd6f7b63009991299980e19baf300e301e375400400a2646660020020046eacc048c07cdd50019112999811001080089919980200218130019991191980080080291299981380089981419bb037520086e9800d2f5bded8c0264646464a66605066e400200084cc0b0cdd81ba9008374c00e00a2a66605066e3c0200084c94ccc0a4c090c0a8dd500089981699bb03752012605c60566ea80040104010c94ccc0a54ccc0b00045288a5014c0103d87a80001301a3302d374c00297ae032333001001008002222533302e0021001132333004004303200333223233001001005225333033001133034337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0d0cdc800400109981c19bb037520106ea001c01454ccc0d0cdc7804001099299981a9818181b1baa001133039337606ea4024c0e8c0dcdd5000802080219299981a98180008a60103d87a80001302633039375000297ae03370000e00226607066ec0dd48011ba800133006006003375a606a0066eb8c0cc008c0dc008c0d4004dd718168009bad302e001303000213302c337606ea4008dd3000998030030019bab3029003375c604e004605600460520026eb8c084004dd5981100098120010800980f800998010011810000911919800800991980080080191299980e8008a5eb804c8ccc888c8cc00400400c894ccc08c004400c4c8cc094dd3998129ba90063302530220013302530230014bd7019801801981380118128009bae301c0013756603a002660060066042004603e00244a66603800229444c94ccc068c8cdc49bad3007001333008006375c601a0026eb8c040004dd6180f8010998018018008a50301f0012301a301b301b0012223253330173011301837540022900009bad301c3019375400264a66602e602260306ea8004530103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301d337220100042a66603a66e3c0200084c038cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301c337220100042a66603866e3c0200084c034cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c07400494ccc04cc03800452f5bded8c0264646600200297adef6c6022533301900113301a337609801014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c068004c058c04cdd50008b19198008009bac300330133754600660266ea801c894ccc054004530103d87a80001323253330143375e600c602c6ea800801c4c014cc0600092f5c02660080080026032004602e002264a666022601860246ea80044cc88c8cc00400400c894ccc060004528099299980b19b8f375c603600400829444cc00c00c004c06c004dd6180b180b980b980b980b980b980b980b980b98099baa30033013375400e6eb8c058c04cdd50008b192999808980618091baa001130023301530163013375400297ae014c0103d87a8000300230123754600460246ea8030dd2a4000460280026024601e6ea8004528180098071baa00223011301200114984d958c94ccc028c01400454ccc034c030dd50010a4c2c2a66601460080022a66601a60186ea80085261616300a375400264a666010600660126ea80104c8c8c8c8c8c8c8c94ccc04cc0580084c9265333010300b3011375400e264646464a66602e6034004264649319299980b180880089919299980d980f00109924c64a666032602800226464a66603c604200426493180a0008b180f800980d9baa002153330193013001132323232323253330223025002149858dd6981180098118011bad30210013021002375a603e00260366ea800858c064dd50008b180e000980c1baa00315333016301000115333019301837540062930b0b180b1baa002300d003163018001301800230160013012375400e2c2c6eb8c050004c050008dd7180900098090011bad30100013010002300e001300a37540082c464a666012600800226464a66601c60220042930b1bae300f001300b37540042a666012600600226464a66601c60220042930b1bae300f001300b37540042c60126ea8004dc3a40046e1d2000375a002ae6955ceaab9e5573eae815d0aba21",
238
- hash: "96dbc09c69d812e157d42967587c459b60f5dd21b1902312045586c4"
223
+ compiledCode: "590c2f01000032323232323232232323232323232232322533300d3232533300f300c3010375400226464646464646464a66602e602a60306ea80044c8c8c8c8c8c8c8c8c8c94ccc084c07c0244c8c8c8c8c8c8c94ccc0acc0b800c4c94ccc0b0c0bc00c4c94ccc0a8c080c0acdd5000899192999816181118169baa001132533302d302b302e3754006264646464a666068606e004264646464a66606a66ebc024cdd2a40046607200e660726e98014cc0e404ccc0e4dd300925eb8040045281980b9bab302730363754018660326eacc09cc0d8dd51813981b1baa00d301a011302c0073302c0022323302e3756606c0044646eb4c0e0008dd7181b0009bae3034001302c003163756606a002606a0046066002605e6ea800c58c0c4c0b8dd50008b180798169baa003302f302c37540022c601a60566ea8c070c0acdd50010b18168010b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb80dd598141814801181380098119baa01813232325333024302100c132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd500089980500c1bae3031302e37540022c60106060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc058090dd7181e8010a51133003003001303d00115333035005100414a0294058c044014dd7181c181a9baa00116300f006330143301001e00230173756606c606e006660266601e03a008602c6eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa00116300c302a3754603660546ea80045858c0b0008dd6181598160011bac302a00133028374e6600802601a660506e9ccc0140440352f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1980e0151bae304300213300300300114a060860022a66607600a200829405280b180b8059bae303e303b37540022c602a01a660346602c048010603a014660326602a046016603800a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c601860546ea8c06cc0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb808c94ccc094c08cc098dd50008980819814981518139baa0014bd700a6103d87a800030153026375400244646600200200644a66605200229404c94ccc09ccdc79bae302c00200414a2266006006002605800244646600200200644a666050002297adef6c601332253330273375e603060526ea80080144cc030004dd5980d18149baa0021001302a00133002002302b001223300400223375e6028604a6ea8c058c094dd50008011119801801119baf30133024375400200444646600200200644a66604a002297ae013232533302430050021330280023300400400113300400400130290023027001223233001001323300100100322533302500114bd7009919991119198008008019129998158008801899198169ba73302d375200c6605a60540026605a605600297ae033003003302f002302d001375c60480026eacc094004cc00c00cc0a4008c09c004894ccc09000452889929998111919b89375a600e002664464a66604c6046604e6ea8004520001375a605660506ea8004c94ccc098c08cc09cdd50008a60103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a8000132323232533302c337220100042a66605866e3c0200084c05ccc0c0dd4000a5eb80530103d87a8000133006006003375a605a0066eb8c0ac008c0bc008c0b4004c8cc004004024894ccc0a80045300103d87a8000132323232533302b337220100042a66605666e3c0200084c058cc0bcdd3000a5eb80530103d87a8000133006006003375660580066eb8c0a8008c0b8008c0b0004dd7180a0009bae30160013758604e0042660060060022940c09c0048c088c08cc08c00488c8ccc00400400c0088894ccc08c00840044c8ccc010010c09c00ccccc020008dd718110009bab3023001222325333025533302800114a229405300103d87a80001301033029374c00297ae032333001001003002222533302a0021001132333004004302e0033322323300100100522533302f001133030337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0c0cdc800400109981a19bb037520106ea001c01454ccc0c0cdc78040010992999818981798191baa001133035337606ea4024c0d8c0ccdd5000802080219299981898178008a60103d87a80001301c33035375000297ae03370000e00226606866ec0dd48011ba800133006006003375a60620066eb8c0bc008c0cc008c0c4004dd718148009bad302a001302c00230250022323300100100222533302000114bd6f7b6300999119191999804001801000911319190011919198008008019129998138008a4c264a6660500022a66604a60086eb4c09cc0a8008526161323232325333029337206eb8c0a8010dd718150018a9998149804000899803803998168018010b0b1bad302a003302d003302b002302a002302a001233302230200014a0944dd598110019bae3020002302200133002002302300122223233001001005225333022001133023337606ea4014dd300225eb7bdb1804c8c8c8c94ccc08ccdc800480109981399bb037520126e9802001454ccc08ccdc78048010992999812181118129baa001133028337606ea4028c0a4c098dd5000802080219980380480400089981399bb037520046e98004cc01801800cdd598120019bae3022002302600230240013019375401e601060326ea8c028c064dd5180e180c9baa0011632323300100100722533301c00114c0103d87a800013232533301b3375e6018603a6ea80080144c018cc07c0092f5c02660080080026040004603c002603660306ea8020dd2a40006eb0c064c068c068c068c068c068c068008dd6180c000980c180c0011bac301600130123754600260246ea80108c054004528180098081baa00223013301400114984d958c94ccc030c0280044c8c8c8c94ccc04cc0580084c8c9263300b0022323300d3756602a0044646eb4c05c008dd7180a8009bae3013001300b003163756602800260280046024002601c6ea800c54ccc030c02400454ccc03cc038dd50018a4c2c2a66601860040022a66601e601c6ea800c5261616300c37540046e1d20043001007232533300930070011323232325333010301300213232498cc0200088c8cc028dd598090011191bad3014002375c60240026eb8c040004c02000c58dd598088009808801180780098059baa0021533300930060011323232323232323253330143017002132323232498cc0380108c8cc040dd5980c0011191bad301a002375c60300026eb8c058004c038014cc0300188c8cc038dd5980b0011191bad3018002375c602c0026eb8c050004c03001c58dd5980a800980a801180980098098011bab30110013011002300f001300b37540042c60126ea800488c8cc00400400c894ccc0340045261323300300330110023003300f00125333006300430073754002264646464a66601a602000426464931929998061805000899192999808980a00109924c64a66601e601a00226464a666028602e0042649318068008b180a80098089baa0021533300f300c00113232323232325333018301b002149858dd6980c800980c8011bad30170013017002375a602a00260226ea800858c03cdd50008b180900098071baa0031533300c30090011533300f300e37540062930b0b18061baa002300600316300e001300e002300c001300837540022c464a66600c600800226464a666016601c0042930b1bae300c001300837540042a66600c600600226464a666016601c0042930b1bae300c001300837540042c600c6ea8004dc3a40046e1d20005734aae7555cf2ab9f5740ae855d101",
224
+ hash: "8fa9284f5889972d7260c10e940a2e1acb2114bdcea845da3d52de7d"
239
225
  }
240
226
  ],
241
227
  definitions: {
@@ -245,6 +231,24 @@ var plutus_default = {
245
231
  Int: {
246
232
  dataType: "integer"
247
233
  },
234
+ List$Pair$ByteArray_Int: {
235
+ dataType: "map",
236
+ keys: {
237
+ $ref: "#/definitions/ByteArray"
238
+ },
239
+ values: {
240
+ $ref: "#/definitions/Int"
241
+ }
242
+ },
243
+ List$Pair$ByteArray_List$Pair$ByteArray_Int: {
244
+ dataType: "map",
245
+ keys: {
246
+ $ref: "#/definitions/ByteArray"
247
+ },
248
+ values: {
249
+ $ref: "#/definitions/List$Pair$ByteArray_Int"
250
+ }
251
+ },
248
252
  "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
249
253
  title: "Optional",
250
254
  anyOf: [
@@ -350,106 +354,151 @@ var plutus_default = {
350
354
  }
351
355
  ]
352
356
  },
353
- "marketplace/types/MarketplaceDatum": {
354
- title: "MarketplaceDatum",
357
+ "escrow/types/EscrowDatum": {
358
+ title: "EscrowDatum",
355
359
  anyOf: [
356
360
  {
357
- title: "MarketplaceDatum",
361
+ title: "Initiation",
358
362
  dataType: "constructor",
359
363
  index: 0,
360
364
  fields: [
361
365
  {
362
- title: "seller",
366
+ title: "initiator",
363
367
  $ref: "#/definitions/aiken~1transaction~1credential~1Address"
364
368
  },
365
369
  {
366
- title: "price",
367
- $ref: "#/definitions/Int"
370
+ title: "initiator_assets",
371
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
372
+ }
373
+ ]
374
+ },
375
+ {
376
+ title: "ActiveEscrow",
377
+ dataType: "constructor",
378
+ index: 1,
379
+ fields: [
380
+ {
381
+ title: "initiator",
382
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
368
383
  },
369
384
  {
370
- title: "policy",
371
- $ref: "#/definitions/ByteArray"
385
+ title: "initiator_assets",
386
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
372
387
  },
373
388
  {
374
- title: "tokenName",
375
- $ref: "#/definitions/ByteArray"
389
+ title: "recipient",
390
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
391
+ },
392
+ {
393
+ title: "recipient_assets",
394
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
376
395
  }
377
396
  ]
378
397
  }
379
398
  ]
380
399
  },
381
- "marketplace/types/MarketplaceRedeemer": {
382
- title: "MarketplaceRedeemer",
400
+ "escrow/types/EscrowRedeemer": {
401
+ title: "EscrowRedeemer",
383
402
  anyOf: [
384
403
  {
385
- title: "Buy",
404
+ title: "RecipientDeposit",
386
405
  dataType: "constructor",
387
406
  index: 0,
388
- fields: []
407
+ fields: [
408
+ {
409
+ title: "recipient",
410
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
411
+ },
412
+ {
413
+ title: "recipient_assets",
414
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
415
+ }
416
+ ]
389
417
  },
390
418
  {
391
- title: "Close",
419
+ title: "CancelTrade",
392
420
  dataType: "constructor",
393
421
  index: 1,
394
422
  fields: []
423
+ },
424
+ {
425
+ title: "CompleteTrade",
426
+ dataType: "constructor",
427
+ index: 2,
428
+ fields: []
395
429
  }
396
430
  ]
397
431
  }
398
432
  }
399
433
  };
400
434
 
401
- // src/marketplace/offchain.ts
402
- var MeshMarketplaceBlueprint = plutus_default;
403
- var marketplaceDatum = (sellerAddress, lovelaceFee, assetHex) => {
404
- const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(sellerAddress);
405
- const { policyId, assetName } = (0, import_common.parseAssetUnit)(assetHex);
435
+ // src/escrow/offchain.ts
436
+ var MeshEscrowBlueprint = plutus_default;
437
+ var initiateEscrowDatum = (walletAddress, amount) => {
438
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(walletAddress);
406
439
  return (0, import_common.conStr0)([
407
440
  (0, import_common.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
408
- (0, import_common.integer)(lovelaceFee),
409
- (0, import_common.currencySymbol)(policyId),
410
- (0, import_common.tokenName)(assetName)
441
+ (0, import_common.value)(amount)
411
442
  ]);
412
443
  };
413
- var MeshMarketplaceContract = class extends MeshTxInitiator {
414
- ownerAddress;
415
- feePercentageBasisPoint;
416
- scriptCbor;
417
- constructor(inputs, ownerAddress, feePercentageBasisPoint) {
444
+ var activeEscrowDatum = (initiationDatum, walletAddress, amount) => {
445
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(walletAddress);
446
+ const [initiator, initiatorAmount] = initiationDatum.fields;
447
+ return (0, import_common.conStr1)([
448
+ initiator,
449
+ initiatorAmount,
450
+ (0, import_common.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
451
+ (0, import_common.value)(amount)
452
+ ]);
453
+ };
454
+ var recipientDepositRedeemer = (recipient, depositAmount) => initiateEscrowDatum(recipient, depositAmount);
455
+ var MeshEscrowContract = class extends MeshTxInitiator {
456
+ scriptCbor = (0, import_core_csl2.applyParamsToScript)(plutus_default.validators[0].compiledCode, []);
457
+ constructor(inputs) {
418
458
  super(inputs);
419
- this.ownerAddress = ownerAddress;
420
- this.feePercentageBasisPoint = feePercentageBasisPoint;
421
- const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(ownerAddress);
422
- this.scriptCbor = (0, import_core_csl2.applyParamsToScript)(
423
- plutus_default.validators[0].compiledCode,
424
- [
425
- (0, import_common.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
426
- (0, import_common.integer)(feePercentageBasisPoint)
427
- ],
428
- "JSON"
429
- );
430
459
  }
431
- listAsset = async (asset, price) => {
460
+ initiateEscrow = async (escrowAmount) => {
432
461
  const { utxos, walletAddress } = await this.getWalletInfoForTx();
433
- const assetMap = /* @__PURE__ */ new Map();
434
- assetMap.set(asset, "1");
435
462
  const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
436
463
  { code: this.scriptCbor, version: "V2" },
437
464
  void 0,
438
465
  this.networkId
439
466
  );
440
- const tokenForSale = [{ unit: asset, quantity: "1" }];
441
- const outputDatum = marketplaceDatum(walletAddress, price, asset);
442
- await this.mesh.txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
467
+ await this.mesh.txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(
468
+ initiateEscrowDatum(walletAddress, escrowAmount),
469
+ "JSON"
470
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
443
471
  return this.mesh.txHex;
444
472
  };
445
- delistAsset = async (marketplaceUtxo) => {
473
+ cancelEscrow = async (escrowUtxo) => {
446
474
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
475
+ const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
476
+ { code: this.scriptCbor, version: "V2" },
477
+ void 0,
478
+ this.networkId
479
+ );
480
+ const inputDatum = (0, import_core.deserializeDatum)(
481
+ escrowUtxo.output.plutusData
482
+ );
483
+ if (inputDatum.constructor === 1) {
484
+ const [
485
+ initiatorAddressObj,
486
+ initiatorAmount,
487
+ recipientAddressObj,
488
+ recipientAmount
489
+ ] = inputDatum.fields;
490
+ const initiatorAddress = (0, import_core.serializeAddressObj)(initiatorAddressObj);
491
+ const recipientAddress = (0, import_core.serializeAddressObj)(recipientAddressObj);
492
+ const initiatorToReceive = import_common.MeshValue.fromValue(initiatorAmount).toAssets();
493
+ const recipientToReceive = import_common.MeshValue.fromValue(recipientAmount).toAssets();
494
+ this.mesh.txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive);
495
+ }
447
496
  await this.mesh.spendingPlutusScriptV2().txIn(
448
- marketplaceUtxo.input.txHash,
449
- marketplaceUtxo.input.outputIndex,
450
- marketplaceUtxo.output.amount,
451
- marketplaceUtxo.output.address
452
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr1)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).requiredSignerHash((0, import_core.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
497
+ escrowUtxo.input.txHash,
498
+ escrowUtxo.input.outputIndex,
499
+ escrowUtxo.output.amount,
500
+ scriptAddr
501
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr1)([])).txInScript(this.scriptCbor).requiredSignerHash((0, import_core.deserializeAddress)(walletAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
453
502
  collateral.input.txHash,
454
503
  collateral.input.outputIndex,
455
504
  collateral.output.amount,
@@ -457,71 +506,69 @@ var MeshMarketplaceContract = class extends MeshTxInitiator {
457
506
  ).selectUtxosFrom(utxos).complete();
458
507
  return this.mesh.txHex;
459
508
  };
460
- purchaseAsset = async (marketplaceUtxo) => {
509
+ recipientDeposit = async (escrowUtxo, depositAmount) => {
461
510
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
511
+ const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
512
+ { code: this.scriptCbor, version: "V2" },
513
+ void 0,
514
+ this.networkId
515
+ );
462
516
  const inputDatum = (0, import_core.deserializeDatum)(
463
- marketplaceUtxo.output.plutusData
517
+ escrowUtxo.output.plutusData
464
518
  );
465
- const inputLovelace = marketplaceUtxo.output.amount.find(
466
- (a) => a.unit === "lovelace"
467
- ).quantity;
468
- const tx = this.mesh.spendingPlutusScriptV2().txIn(
469
- marketplaceUtxo.input.txHash,
470
- marketplaceUtxo.input.outputIndex,
471
- marketplaceUtxo.output.amount,
472
- marketplaceUtxo.output.address
473
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
519
+ const outputDatum = activeEscrowDatum(
520
+ inputDatum,
521
+ walletAddress,
522
+ depositAmount
523
+ );
524
+ const inputAssets = import_common.MeshValue.fromValue(inputDatum.fields[1]).toAssets();
525
+ const escrowAmount = (0, import_core.mergeAssets)([...depositAmount, ...inputAssets]);
526
+ await this.mesh.spendingPlutusScriptV2().txIn(
527
+ escrowUtxo.input.txHash,
528
+ escrowUtxo.input.outputIndex,
529
+ escrowUtxo.output.amount,
530
+ scriptAddr
531
+ ).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(
532
+ recipientDepositRedeemer(walletAddress, depositAmount),
533
+ "JSON",
534
+ {
535
+ mem: 7e6,
536
+ steps: 3e9
537
+ }
538
+ ).txInScript(this.scriptCbor).txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).txInCollateral(
474
539
  collateral.input.txHash,
475
540
  collateral.input.outputIndex,
476
541
  collateral.output.amount,
477
542
  collateral.output.address
478
- ).selectUtxosFrom(utxos);
479
- let ownerToReceiveLovelace = inputDatum.fields[1].int * this.feePercentageBasisPoint / 1e4;
480
- if (this.feePercentageBasisPoint > 0 && ownerToReceiveLovelace < 1e6) {
481
- ownerToReceiveLovelace = 1e6;
482
- }
483
- if (ownerToReceiveLovelace > 0) {
484
- const ownerAddress = this.ownerAddress;
485
- const ownerToReceive = [
486
- {
487
- unit: "lovelace",
488
- quantity: Math.ceil(ownerToReceiveLovelace).toString()
489
- }
490
- ];
491
- tx.txOut(ownerAddress, ownerToReceive);
492
- }
493
- const sellerToReceiveLovelace = inputDatum.fields[1].int + Number(inputLovelace);
494
- if (sellerToReceiveLovelace > 0) {
495
- const sellerAddress = (0, import_core.serializeAddressObj)(inputDatum.fields[0]);
496
- const sellerToReceive = [
497
- {
498
- unit: "lovelace",
499
- quantity: sellerToReceiveLovelace.toString()
500
- }
501
- ];
502
- tx.txOut(sellerAddress, sellerToReceive);
503
- }
504
- await tx.complete();
543
+ ).selectUtxosFrom(utxos).complete();
505
544
  return this.mesh.txHex;
506
545
  };
507
- relistAsset = async (marketplaceUtxo, newPrice) => {
546
+ completeEscrow = async (escrowUtxo) => {
508
547
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
509
- const inputAsset = marketplaceUtxo.output.amount.find(
510
- (a) => a.unit !== "lovelace"
511
- ).unit;
512
- const tokenForSale = [{ unit: inputAsset, quantity: "1" }];
513
- const outputDatum = marketplaceDatum(walletAddress, newPrice, inputAsset);
514
548
  const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
515
549
  { code: this.scriptCbor, version: "V2" },
516
550
  void 0,
517
551
  this.networkId
518
552
  );
553
+ const inputDatum = (0, import_core.deserializeDatum)(
554
+ escrowUtxo.output.plutusData
555
+ );
556
+ const [
557
+ initiatorAddressObj,
558
+ initiatorAmount,
559
+ recipientAddressObj,
560
+ recipientAmount
561
+ ] = inputDatum.fields;
562
+ const initiatorAddress = (0, import_core.serializeAddressObj)(initiatorAddressObj);
563
+ const recipientAddress = (0, import_core.serializeAddressObj)(recipientAddressObj);
564
+ const initiatorToReceive = import_common.MeshValue.fromValue(recipientAmount).toAssets();
565
+ const recipientToReceive = import_common.MeshValue.fromValue(initiatorAmount).toAssets();
519
566
  await this.mesh.spendingPlutusScriptV2().txIn(
520
- marketplaceUtxo.input.txHash,
521
- marketplaceUtxo.input.outputIndex,
522
- marketplaceUtxo.output.amount,
523
- marketplaceUtxo.output.address
524
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr1)([])).txInScript(this.scriptCbor).txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).requiredSignerHash((0, import_core.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
567
+ escrowUtxo.input.txHash,
568
+ escrowUtxo.input.outputIndex,
569
+ escrowUtxo.output.amount,
570
+ scriptAddr
571
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr2)([])).txInScript(this.scriptCbor).txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive).requiredSignerHash((0, import_core.deserializeAddress)(recipientAddress).pubKeyHash).requiredSignerHash((0, import_core.deserializeAddress)(initiatorAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
525
572
  collateral.input.txHash,
526
573
  collateral.input.outputIndex,
527
574
  collateral.output.amount,
@@ -534,16 +581,16 @@ var MeshMarketplaceContract = class extends MeshTxInitiator {
534
581
  };
535
582
  };
536
583
 
537
- // src/vesting/offchain.ts
584
+ // src/giftcard/offchain.ts
538
585
  var import_common3 = require("@meshsdk/common");
539
586
  var import_core2 = require("@meshsdk/core");
540
587
  var import_core_csl3 = require("@meshsdk/core-csl");
541
588
 
542
- // src/vesting/aiken-workspace/plutus.json
589
+ // src/giftcard/aiken-workspace/plutus.json
543
590
  var plutus_default2 = {
544
591
  preamble: {
545
- title: "meshjs/vesting",
546
- description: "Aiken contracts for project 'meshjs/vesting'",
592
+ title: "meshjs/giftcard",
593
+ description: "Aiken contracts for project 'meshjs/giftcard'",
547
594
  version: "0.0.0",
548
595
  plutusVersion: "v2",
549
596
  compiler: {
@@ -554,21 +601,60 @@ var plutus_default2 = {
554
601
  },
555
602
  validators: [
556
603
  {
557
- title: "vesting.vesting",
604
+ title: "oneshot.gift_card",
605
+ redeemer: {
606
+ title: "rdmr",
607
+ schema: {
608
+ $ref: "#/definitions/oneshot~1Action"
609
+ }
610
+ },
611
+ parameters: [
612
+ {
613
+ title: "token_name",
614
+ schema: {
615
+ $ref: "#/definitions/ByteArray"
616
+ }
617
+ },
618
+ {
619
+ title: "utxo_ref",
620
+ schema: {
621
+ $ref: "#/definitions/aiken~1transaction~1OutputReference"
622
+ }
623
+ }
624
+ ],
625
+ compiledCode: "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
626
+ hash: "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
627
+ },
628
+ {
629
+ title: "oneshot.redeem",
558
630
  datum: {
559
- title: "datum",
631
+ title: "_d",
560
632
  schema: {
561
- $ref: "#/definitions/vesting~1types~1VestingDatum"
633
+ $ref: "#/definitions/Data"
562
634
  }
563
635
  },
564
636
  redeemer: {
565
- title: "_redeemer",
637
+ title: "_r",
566
638
  schema: {
567
639
  $ref: "#/definitions/Data"
568
640
  }
569
641
  },
570
- compiledCode: "5901c40100003232323232323223222533300532533233007300130083754600460126ea800c4c8c8c94ccc028cc004dd6180118061baa3003300c375400c6eb8c014c030dd50048a511533300a330013758600460186ea8c00cc030dd50031bae300f30103010300c3754012266446464646464a666022601660246ea80084c94ccc0480104cdc40038008011bad301630133754004002264a666022601660246ea80084c94ccc0480100084cdc48038009bad3016301337540040022940c050008cdc424000601e6ea8c04cc050004cc044c048004cc044ccc034cdc424000601c6ea8c048c04c00530103d87a80004c0103d87980004bd7018071baa3005300e3754004601e602060206020602060206020602060186ea8c00cc030dd50031bad3003300c3754012294088c8cc00400400c894ccc040004528099299980719b8f375c602600400829444cc00c00c004c04c0048c038c03cc03cc03cc03cc03cc03cc03cc03c0048c034004dc3a400429408c02cc0300045261365653330023370e900018019baa0011323232323232533300b300e002149858dd7180600098060011bae300a001300a002375a601000260086ea8004595cd2ab9d5573caae7d5d02ba157441",
571
- hash: "ac96a3fa3cabf670268a88720402c715ed5fd73ffb3276e6092ead00"
642
+ parameters: [
643
+ {
644
+ title: "token_name",
645
+ schema: {
646
+ $ref: "#/definitions/ByteArray"
647
+ }
648
+ },
649
+ {
650
+ title: "policy_id",
651
+ schema: {
652
+ $ref: "#/definitions/ByteArray"
653
+ }
654
+ }
655
+ ],
656
+ compiledCode: "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
657
+ hash: "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
572
658
  }
573
659
  ],
574
660
  definitions: {
@@ -582,105 +668,174 @@ var plutus_default2 = {
582
668
  Int: {
583
669
  dataType: "integer"
584
670
  },
585
- "vesting/types/VestingDatum": {
586
- title: "VestingDatum",
671
+ "aiken/transaction/OutputReference": {
672
+ title: "OutputReference",
673
+ 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",
587
674
  anyOf: [
588
675
  {
589
- title: "VestingDatum",
676
+ title: "OutputReference",
590
677
  dataType: "constructor",
591
678
  index: 0,
592
679
  fields: [
593
680
  {
594
- title: "lock_until",
595
- description: "POSIX time in second, e.g. 1672843961000",
596
- $ref: "#/definitions/Int"
681
+ title: "transaction_id",
682
+ $ref: "#/definitions/aiken~1transaction~1TransactionId"
597
683
  },
598
684
  {
599
- title: "owner",
600
- description: "Owner's credentials",
601
- $ref: "#/definitions/ByteArray"
602
- },
685
+ title: "output_index",
686
+ $ref: "#/definitions/Int"
687
+ }
688
+ ]
689
+ }
690
+ ]
691
+ },
692
+ "aiken/transaction/TransactionId": {
693
+ title: "TransactionId",
694
+ 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.",
695
+ anyOf: [
696
+ {
697
+ title: "TransactionId",
698
+ dataType: "constructor",
699
+ index: 0,
700
+ fields: [
603
701
  {
604
- title: "beneficiary",
605
- description: "Beneficiary's credentials",
702
+ title: "hash",
606
703
  $ref: "#/definitions/ByteArray"
607
704
  }
608
705
  ]
609
706
  }
610
707
  ]
708
+ },
709
+ "oneshot/Action": {
710
+ title: "Action",
711
+ anyOf: [
712
+ {
713
+ title: "Mint",
714
+ dataType: "constructor",
715
+ index: 0,
716
+ fields: []
717
+ },
718
+ {
719
+ title: "Burn",
720
+ dataType: "constructor",
721
+ index: 1,
722
+ fields: []
723
+ }
724
+ ]
611
725
  }
612
726
  }
613
727
  };
614
728
 
615
- // src/vesting/offchain.ts
616
- var MeshVestingBlueprint = plutus_default2;
617
- var MeshVestingContract = class extends MeshTxInitiator {
618
- scriptCbor = (0, import_core_csl3.applyParamsToScript)(plutus_default2.validators[0].compiledCode, []);
619
- constructor(inputs) {
729
+ // src/giftcard/offchain.ts
730
+ var MeshGiftCardBlueprint = plutus_default2;
731
+ var MeshGiftCardContract = class extends MeshTxInitiator {
732
+ tokenNameHex = "";
733
+ paramUtxo = { outputIndex: 0, txHash: "" };
734
+ giftCardCbor = (tokenNameHex, utxoTxHash, utxoTxId) => {
735
+ return (0, import_core_csl3.applyParamsToScript)(
736
+ plutus_default2.validators[0].compiledCode,
737
+ [(0, import_common3.builtinByteString)(tokenNameHex), (0, import_common3.txOutRef)(utxoTxHash, utxoTxId)],
738
+ "JSON"
739
+ );
740
+ };
741
+ redeemCbor = (tokenNameHex, policyId) => (0, import_core_csl3.applyParamsToScript)(plutus_default2.validators[1].compiledCode, [
742
+ tokenNameHex,
743
+ policyId
744
+ ]);
745
+ constructor(inputs, tokenNameHex, paramUtxo) {
620
746
  super(inputs);
747
+ if (tokenNameHex) {
748
+ this.tokenNameHex = tokenNameHex;
749
+ }
750
+ if (paramUtxo) {
751
+ this.paramUtxo = paramUtxo;
752
+ }
621
753
  }
622
- depositFund = async (amount, lockUntilTimeStampMs, beneficiary) => {
623
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
624
- const scriptAddr = (0, import_core2.serializePlutusScript)(
625
- { code: this.scriptCbor, version: "V2" },
754
+ createGiftCard = async (tokenName2, giftValue) => {
755
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
756
+ const tokenNameHex = (0, import_common3.stringToHex)(tokenName2);
757
+ const firstUtxo = utxos[0];
758
+ if (firstUtxo === void 0) throw new Error("No UTXOs available");
759
+ const remainingUtxos = utxos.slice(1);
760
+ const giftCardScript = this.giftCardCbor(
761
+ tokenNameHex,
762
+ firstUtxo.input.txHash,
763
+ firstUtxo.input.outputIndex
764
+ );
765
+ const giftCardPolicy = (0, import_core2.resolveScriptHash)(giftCardScript, "V2");
766
+ const redeemScript = {
767
+ code: this.redeemCbor(tokenNameHex, giftCardPolicy),
768
+ version: "V2"
769
+ };
770
+ const redeemAddr = (0, import_core2.serializePlutusScript)(
771
+ redeemScript,
626
772
  void 0,
627
- 0
773
+ this.networkId
628
774
  ).address;
629
- const { pubKeyHash: ownerPubKeyHash } = (0, import_core2.deserializeAddress)(walletAddress);
630
- const { pubKeyHash: beneficiaryPubKeyHash } = (0, import_core2.deserializeAddress)(beneficiary);
631
- await this.mesh.txOut(scriptAddr, amount).txOutInlineDatumValue(
632
- (0, import_common3.mConStr0)([
633
- lockUntilTimeStampMs,
634
- ownerPubKeyHash,
635
- beneficiaryPubKeyHash
636
- ])
637
- ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
775
+ await this.mesh.txIn(
776
+ firstUtxo.input.txHash,
777
+ firstUtxo.input.outputIndex,
778
+ firstUtxo.output.amount,
779
+ firstUtxo.output.address
780
+ ).mintPlutusScriptV2().mint("1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common3.mConStr0)([])).txOut(redeemAddr, [
781
+ ...giftValue,
782
+ { unit: giftCardPolicy + tokenNameHex, quantity: "1" }
783
+ ]).txOutInlineDatumValue([
784
+ firstUtxo.input.txHash,
785
+ firstUtxo.input.outputIndex,
786
+ tokenNameHex
787
+ ]).changeAddress(walletAddress).txInCollateral(
788
+ collateral.input.txHash,
789
+ collateral.input.outputIndex,
790
+ collateral.output.amount,
791
+ collateral.output.address
792
+ ).selectUtxosFrom(remainingUtxos).complete();
793
+ this.tokenNameHex = tokenNameHex;
794
+ this.paramUtxo = firstUtxo.input;
638
795
  return this.mesh.txHex;
639
796
  };
640
- withdrawFund = async (vestingUtxo) => {
797
+ redeemGiftCard = async (giftCardUtxo) => {
641
798
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
642
- const { input: collateralInput, output: collateralOutput } = collateral;
643
- const scriptAddr = (0, import_core2.serializePlutusScript)(
644
- { code: this.scriptCbor, version: "V2" },
645
- void 0,
646
- 0
647
- ).address;
648
- const { pubKeyHash } = (0, import_core2.deserializeAddress)(walletAddress);
649
- const datum = (0, import_core2.deserializeDatum)(
650
- vestingUtxo.output.plutusData
799
+ const inlineDatum = (0, import_core2.deserializeDatum)(
800
+ giftCardUtxo.output.plutusData
801
+ ).list;
802
+ const paramTxHash = inlineDatum[0].bytes;
803
+ const paramTxId = inlineDatum[1].int;
804
+ const tokenNameHex = inlineDatum[2].bytes;
805
+ const giftCardScript = this.giftCardCbor(
806
+ tokenNameHex,
807
+ paramTxHash,
808
+ paramTxId
651
809
  );
652
- const invalidBefore = (0, import_common3.unixTimeToEnclosingSlot)(
653
- Math.min(datum.fields[0].int, Date.now() - 15e3),
654
- this.networkId === 0 ? import_common3.SLOT_CONFIG_NETWORK.preprod : import_common3.SLOT_CONFIG_NETWORK.mainnet
655
- ) + 1;
810
+ const giftCardPolicy = (0, import_core2.resolveScriptHash)(giftCardScript, "V2");
811
+ const redeemScript = this.redeemCbor(tokenNameHex, giftCardPolicy);
656
812
  await this.mesh.spendingPlutusScriptV2().txIn(
657
- vestingUtxo.input.txHash,
658
- vestingUtxo.input.outputIndex,
659
- vestingUtxo.output.amount,
660
- scriptAddr
661
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(walletAddress, []).txInCollateral(
662
- collateralInput.txHash,
663
- collateralInput.outputIndex,
664
- collateralOutput.amount,
665
- collateralOutput.address
666
- ).invalidBefore(invalidBefore).requiredSignerHash(pubKeyHash).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
813
+ giftCardUtxo.input.txHash,
814
+ giftCardUtxo.input.outputIndex,
815
+ giftCardUtxo.output.amount,
816
+ giftCardUtxo.output.address
817
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(redeemScript).mintPlutusScriptV2().mint("-1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common3.mConStr1)([])).changeAddress(walletAddress).txInCollateral(
818
+ collateral.input.txHash,
819
+ collateral.input.outputIndex,
820
+ collateral.output.amount,
821
+ collateral.output.address
822
+ ).selectUtxosFrom(utxos).complete();
667
823
  return this.mesh.txHex;
668
824
  };
669
825
  getUtxoByTxHash = async (txHash) => {
670
- return await this._getUtxoByTxHash(txHash, this.scriptCbor);
826
+ return await this._getUtxoByTxHash(txHash);
671
827
  };
672
828
  };
673
829
 
674
- // src/escrow/offchain.ts
675
- var import_common5 = require("@meshsdk/common");
830
+ // src/hello-world/offchain.ts
676
831
  var import_core3 = require("@meshsdk/core");
677
832
  var import_core_csl4 = require("@meshsdk/core-csl");
678
833
 
679
- // src/escrow/aiken-workspace/plutus.json
834
+ // src/hello-world/aiken-workspace/plutus.json
680
835
  var plutus_default3 = {
681
836
  preamble: {
682
- title: "meshjs/escrow",
683
- description: "Aiken contracts for project 'meshjs/escrow'",
837
+ title: "meshjs/aiken",
838
+ description: "Aiken on MeshJS",
684
839
  version: "0.0.0",
685
840
  plutusVersion: "v2",
686
841
  compiler: {
@@ -691,47 +846,164 @@ var plutus_default3 = {
691
846
  },
692
847
  validators: [
693
848
  {
694
- title: "escrow.escrow",
849
+ title: "hello_world.hello_world",
695
850
  datum: {
696
- title: "_datum",
851
+ title: "datum",
697
852
  schema: {
698
- $ref: "#/definitions/escrow~1types~1EscrowDatum"
853
+ $ref: "#/definitions/hello_world~1Datum"
699
854
  }
700
855
  },
701
856
  redeemer: {
702
857
  title: "redeemer",
703
858
  schema: {
704
- $ref: "#/definitions/escrow~1types~1EscrowRedeemer"
859
+ $ref: "#/definitions/hello_world~1Redeemer"
705
860
  }
706
861
  },
707
- compiledCode: "590c2f01000032323232323232232323232323232232322533300d3232533300f300c3010375400226464646464646464a66602e602a60306ea80044c8c8c8c8c8c8c8c8c8c94ccc084c07c0244c8c8c8c8c8c8c94ccc0acc0b800c4c94ccc0b0c0bc00c4c94ccc0a8c080c0acdd5000899192999816181118169baa001132533302d302b302e3754006264646464a666068606e004264646464a66606a66ebc024cdd2a40046607200e660726e98014cc0e404ccc0e4dd300925eb8040045281980b9bab302730363754018660326eacc09cc0d8dd51813981b1baa00d301a011302c0073302c0022323302e3756606c0044646eb4c0e0008dd7181b0009bae3034001302c003163756606a002606a0046066002605e6ea800c58c0c4c0b8dd50008b180798169baa003302f302c37540022c601a60566ea8c070c0acdd50010b18168010b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb80dd598141814801181380098119baa01813232325333024302100c132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd500089980500c1bae3031302e37540022c60106060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc058090dd7181e8010a51133003003001303d00115333035005100414a0294058c044014dd7181c181a9baa00116300f006330143301001e00230173756606c606e006660266601e03a008602c6eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa00116300c302a3754603660546ea80045858c0b0008dd6181598160011bac302a00133028374e6600802601a660506e9ccc0140440352f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1980e0151bae304300213300300300114a060860022a66607600a200829405280b180b8059bae303e303b37540022c602a01a660346602c048010603a014660326602a046016603800a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c601860546ea8c06cc0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb808c94ccc094c08cc098dd50008980819814981518139baa0014bd700a6103d87a800030153026375400244646600200200644a66605200229404c94ccc09ccdc79bae302c00200414a2266006006002605800244646600200200644a666050002297adef6c601332253330273375e603060526ea80080144cc030004dd5980d18149baa0021001302a00133002002302b001223300400223375e6028604a6ea8c058c094dd50008011119801801119baf30133024375400200444646600200200644a66604a002297ae013232533302430050021330280023300400400113300400400130290023027001223233001001323300100100322533302500114bd7009919991119198008008019129998158008801899198169ba73302d375200c6605a60540026605a605600297ae033003003302f002302d001375c60480026eacc094004cc00c00cc0a4008c09c004894ccc09000452889929998111919b89375a600e002664464a66604c6046604e6ea8004520001375a605660506ea8004c94ccc098c08cc09cdd50008a60103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a8000132323232533302c337220100042a66605866e3c0200084c05ccc0c0dd4000a5eb80530103d87a8000133006006003375a605a0066eb8c0ac008c0bc008c0b4004c8cc004004024894ccc0a80045300103d87a8000132323232533302b337220100042a66605666e3c0200084c058cc0bcdd3000a5eb80530103d87a8000133006006003375660580066eb8c0a8008c0b8008c0b0004dd7180a0009bae30160013758604e0042660060060022940c09c0048c088c08cc08c00488c8ccc00400400c0088894ccc08c00840044c8ccc010010c09c00ccccc020008dd718110009bab3023001222325333025533302800114a229405300103d87a80001301033029374c00297ae032333001001003002222533302a0021001132333004004302e0033322323300100100522533302f001133030337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0c0cdc800400109981a19bb037520106ea001c01454ccc0c0cdc78040010992999818981798191baa001133035337606ea4024c0d8c0ccdd5000802080219299981898178008a60103d87a80001301c33035375000297ae03370000e00226606866ec0dd48011ba800133006006003375a60620066eb8c0bc008c0cc008c0c4004dd718148009bad302a001302c00230250022323300100100222533302000114bd6f7b6300999119191999804001801000911319190011919198008008019129998138008a4c264a6660500022a66604a60086eb4c09cc0a8008526161323232325333029337206eb8c0a8010dd718150018a9998149804000899803803998168018010b0b1bad302a003302d003302b002302a002302a001233302230200014a0944dd598110019bae3020002302200133002002302300122223233001001005225333022001133023337606ea4014dd300225eb7bdb1804c8c8c8c94ccc08ccdc800480109981399bb037520126e9802001454ccc08ccdc78048010992999812181118129baa001133028337606ea4028c0a4c098dd5000802080219980380480400089981399bb037520046e98004cc01801800cdd598120019bae3022002302600230240013019375401e601060326ea8c028c064dd5180e180c9baa0011632323300100100722533301c00114c0103d87a800013232533301b3375e6018603a6ea80080144c018cc07c0092f5c02660080080026040004603c002603660306ea8020dd2a40006eb0c064c068c068c068c068c068c068008dd6180c000980c180c0011bac301600130123754600260246ea80108c054004528180098081baa00223013301400114984d958c94ccc030c0280044c8c8c8c94ccc04cc0580084c8c9263300b0022323300d3756602a0044646eb4c05c008dd7180a8009bae3013001300b003163756602800260280046024002601c6ea800c54ccc030c02400454ccc03cc038dd50018a4c2c2a66601860040022a66601e601c6ea800c5261616300c37540046e1d20043001007232533300930070011323232325333010301300213232498cc0200088c8cc028dd598090011191bad3014002375c60240026eb8c040004c02000c58dd598088009808801180780098059baa0021533300930060011323232323232323253330143017002132323232498cc0380108c8cc040dd5980c0011191bad301a002375c60300026eb8c058004c038014cc0300188c8cc038dd5980b0011191bad3018002375c602c0026eb8c050004c03001c58dd5980a800980a801180980098098011bab30110013011002300f001300b37540042c60126ea800488c8cc00400400c894ccc0340045261323300300330110023003300f00125333006300430073754002264646464a66601a602000426464931929998061805000899192999808980a00109924c64a66601e601a00226464a666028602e0042649318068008b180a80098089baa0021533300f300c00113232323232325333018301b002149858dd6980c800980c8011bad30170013017002375a602a00260226ea800858c03cdd50008b180900098071baa0031533300c30090011533300f300e37540062930b0b18061baa002300600316300e001300e002300c001300837540022c464a66600c600800226464a666016601c0042930b1bae300c001300837540042a66600c600600226464a666016601c0042930b1bae300c001300837540042c600c6ea8004dc3a40046e1d20005734aae7555cf2ab9f5740ae855d101",
708
- hash: "8fa9284f5889972d7260c10e940a2e1acb2114bdcea845da3d52de7d"
862
+ compiledCode: "58e901000032323232323223223225333006323253330083371e6eb8c008c028dd5002a4410d48656c6c6f2c20576f726c642100100114a06644646600200200644a66601c00229404c94ccc030cdc79bae301000200414a226600600600260200026eb0c02cc030c030c030c030c030c030c030c030c024dd5180098049baa002375c600260126ea80188c02c0045261365653330043370e900018029baa001132325333009300b002149858dd7180480098031baa0011653330023370e900018019baa0011323253330073009002149858dd7180380098021baa001165734aae7555cf2ab9f5742ae881",
863
+ hash: "c1fe430f19ac248a8a7ea47db106002c4327e542c3fdc60ad6481103"
709
864
  }
710
865
  ],
711
866
  definitions: {
712
867
  ByteArray: {
713
868
  dataType: "bytes"
714
869
  },
715
- Int: {
716
- dataType: "integer"
870
+ "hello_world/Datum": {
871
+ title: "Datum",
872
+ anyOf: [
873
+ {
874
+ title: "Datum",
875
+ dataType: "constructor",
876
+ index: 0,
877
+ fields: [
878
+ {
879
+ title: "owner",
880
+ $ref: "#/definitions/ByteArray"
881
+ }
882
+ ]
883
+ }
884
+ ]
717
885
  },
718
- List$Pair$ByteArray_Int: {
719
- dataType: "map",
720
- keys: {
721
- $ref: "#/definitions/ByteArray"
722
- },
723
- values: {
724
- $ref: "#/definitions/Int"
725
- }
886
+ "hello_world/Redeemer": {
887
+ title: "Redeemer",
888
+ anyOf: [
889
+ {
890
+ title: "Redeemer",
891
+ dataType: "constructor",
892
+ index: 0,
893
+ fields: [
894
+ {
895
+ title: "msg",
896
+ $ref: "#/definitions/ByteArray"
897
+ }
898
+ ]
899
+ }
900
+ ]
901
+ }
902
+ }
903
+ };
904
+
905
+ // src/hello-world/offchain.ts
906
+ var MeshHelloWorldBlueprint = plutus_default3;
907
+ var MeshHelloWorldContract = class extends MeshTxInitiator {
908
+ scriptCbor = (0, import_core_csl4.applyParamsToScript)(plutus_default3.validators[0].compiledCode, []);
909
+ constructor(inputs) {
910
+ super(inputs);
911
+ }
912
+ getScript = () => {
913
+ const { address } = (0, import_core3.serializePlutusScript)(
914
+ { code: this.scriptCbor, version: "V2" },
915
+ void 0,
916
+ this.networkId
917
+ );
918
+ return {
919
+ scriptAddr: address
920
+ };
921
+ };
922
+ lockAsset = async (assets) => {
923
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
924
+ const { scriptAddr } = this.getScript();
925
+ const signerHash = (0, import_core3.deserializeAddress)(walletAddress).pubKeyHash;
926
+ await this.mesh.txOut(scriptAddr, assets).txOutDatumHashValue((0, import_core3.mConStr0)([signerHash])).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
927
+ return this.mesh.txHex;
928
+ };
929
+ unlockAsset = async (scriptUtxo, message) => {
930
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
931
+ const signerHash = (0, import_core3.deserializeAddress)(walletAddress).pubKeyHash;
932
+ await this.mesh.spendingPlutusScriptV2().txIn(
933
+ scriptUtxo.input.txHash,
934
+ scriptUtxo.input.outputIndex,
935
+ scriptUtxo.output.amount,
936
+ scriptUtxo.output.address
937
+ ).txInScript(this.scriptCbor).txInRedeemerValue((0, import_core3.mConStr0)([(0, import_core3.stringToHex)(message)])).txInDatumValue((0, import_core3.mConStr0)([signerHash])).requiredSignerHash(signerHash).changeAddress(walletAddress).txInCollateral(
938
+ collateral.input.txHash,
939
+ collateral.input.outputIndex,
940
+ collateral.output.amount,
941
+ collateral.output.address
942
+ ).selectUtxosFrom(utxos).complete();
943
+ return this.mesh.txHex;
944
+ };
945
+ getUtxoByTxHash = async (txHash) => {
946
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
947
+ };
948
+ };
949
+
950
+ // src/marketplace/offchain.ts
951
+ var import_common6 = require("@meshsdk/common");
952
+ var import_core4 = require("@meshsdk/core");
953
+ var import_core_csl5 = require("@meshsdk/core-csl");
954
+
955
+ // src/marketplace/aiken-workspace/plutus.json
956
+ var plutus_default4 = {
957
+ preamble: {
958
+ title: "meshjs/marketplace",
959
+ description: "Aiken contracts for project 'meshjs/marketplace'",
960
+ version: "0.0.0",
961
+ plutusVersion: "v2",
962
+ compiler: {
963
+ name: "Aiken",
964
+ version: "v1.0.29-alpha+unknown"
726
965
  },
727
- List$Pair$ByteArray_List$Pair$ByteArray_Int: {
728
- dataType: "map",
729
- keys: {
730
- $ref: "#/definitions/ByteArray"
966
+ license: "Apache-2.0"
967
+ },
968
+ validators: [
969
+ {
970
+ title: "marketplace.marketplace",
971
+ datum: {
972
+ title: "datum",
973
+ schema: {
974
+ $ref: "#/definitions/marketplace~1types~1MarketplaceDatum"
975
+ }
731
976
  },
732
- values: {
733
- $ref: "#/definitions/List$Pair$ByteArray_Int"
734
- }
977
+ redeemer: {
978
+ title: "redeemer",
979
+ schema: {
980
+ $ref: "#/definitions/marketplace~1types~1MarketplaceRedeemer"
981
+ }
982
+ },
983
+ parameters: [
984
+ {
985
+ title: "owner",
986
+ schema: {
987
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
988
+ }
989
+ },
990
+ {
991
+ title: "fee_percentage_basis_point",
992
+ schema: {
993
+ $ref: "#/definitions/Int"
994
+ }
995
+ }
996
+ ],
997
+ compiledCode: "59082f01000032323232323232223223232322322533300b3232533300d3007300e375400226464a64666020601660226ea80204c94ccc044c030c048dd500089919191919191919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc044c084dd5180a18109baa00200513302300233004004001133004004001302400230220013758601660366ea8c02cc06cdd50079805980d9baa300e301b37540102a6660320022004294052819801998011bac3004301a3754601460346ea803805cc018cdc199b82375a601a60346ea805005520a09c0133002330013758600660326ea8c024c064dd50069804980c9baa0133005337006eb4c030c064dd50099998021bab300c30193754601860326ea801922010048810022323300100100322533301d00114bd6f7b63009991299980e19baf300e301e375400400a2646660020020046eacc048c07cdd50019112999811001080089919980200218130019991191980080080291299981380089981419bb037520086e9800d2f5bded8c0264646464a66605066e400200084cc0b0cdd81ba9008374c00e00a2a66605066e3c0200084c94ccc0a4c090c0a8dd500089981699bb03752012605c60566ea80040104010c94ccc0a54ccc0b00045288a5014c0103d87a80001301a3302d374c00297ae032333001001008002222533302e0021001132333004004303200333223233001001005225333033001133034337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0d0cdc800400109981c19bb037520106ea001c01454ccc0d0cdc7804001099299981a9818181b1baa001133039337606ea4024c0e8c0dcdd5000802080219299981a98180008a60103d87a80001302633039375000297ae03370000e00226607066ec0dd48011ba800133006006003375a606a0066eb8c0cc008c0dc008c0d4004dd718168009bad302e001303000213302c337606ea4008dd3000998030030019bab3029003375c604e004605600460520026eb8c084004dd5981100098120010800980f800998010011810000911919800800991980080080191299980e8008a5eb804c8ccc888c8cc00400400c894ccc08c004400c4c8cc094dd3998129ba90063302530220013302530230014bd7019801801981380118128009bae301c0013756603a002660060066042004603e00244a66603800229444c94ccc068c8cdc49bad3007001333008006375c601a0026eb8c040004dd6180f8010998018018008a50301f0012301a301b301b0012223253330173011301837540022900009bad301c3019375400264a66602e602260306ea8004530103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301d337220100042a66603a66e3c0200084c038cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301c337220100042a66603866e3c0200084c034cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c07400494ccc04cc03800452f5bded8c0264646600200297adef6c6022533301900113301a337609801014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c068004c058c04cdd50008b19198008009bac300330133754600660266ea801c894ccc054004530103d87a80001323253330143375e600c602c6ea800801c4c014cc0600092f5c02660080080026032004602e002264a666022601860246ea80044cc88c8cc00400400c894ccc060004528099299980b19b8f375c603600400829444cc00c00c004c06c004dd6180b180b980b980b980b980b980b980b980b98099baa30033013375400e6eb8c058c04cdd50008b192999808980618091baa001130023301530163013375400297ae014c0103d87a8000300230123754600460246ea8030dd2a4000460280026024601e6ea8004528180098071baa00223011301200114984d958c94ccc028c01400454ccc034c030dd50010a4c2c2a66601460080022a66601a60186ea80085261616300a375400264a666010600660126ea80104c8c8c8c8c8c8c8c94ccc04cc0580084c9265333010300b3011375400e264646464a66602e6034004264649319299980b180880089919299980d980f00109924c64a666032602800226464a66603c604200426493180a0008b180f800980d9baa002153330193013001132323232323253330223025002149858dd6981180098118011bad30210013021002375a603e00260366ea800858c064dd50008b180e000980c1baa00315333016301000115333019301837540062930b0b180b1baa002300d003163018001301800230160013012375400e2c2c6eb8c050004c050008dd7180900098090011bad30100013010002300e001300a37540082c464a666012600800226464a66601c60220042930b1bae300f001300b37540042a666012600600226464a66601c60220042930b1bae300f001300b37540042c60126ea8004dc3a40046e1d2000375a002ae6955ceaab9e5573eae815d0aba21",
998
+ hash: "96dbc09c69d812e157d42967587c459b60f5dd21b1902312045586c4"
999
+ }
1000
+ ],
1001
+ definitions: {
1002
+ ByteArray: {
1003
+ dataType: "bytes"
1004
+ },
1005
+ Int: {
1006
+ dataType: "integer"
735
1007
  },
736
1008
  "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
737
1009
  title: "Optional",
@@ -838,77 +1110,47 @@ var plutus_default3 = {
838
1110
  }
839
1111
  ]
840
1112
  },
841
- "escrow/types/EscrowDatum": {
842
- title: "EscrowDatum",
1113
+ "marketplace/types/MarketplaceDatum": {
1114
+ title: "MarketplaceDatum",
843
1115
  anyOf: [
844
1116
  {
845
- title: "Initiation",
1117
+ title: "MarketplaceDatum",
846
1118
  dataType: "constructor",
847
1119
  index: 0,
848
1120
  fields: [
849
1121
  {
850
- title: "initiator",
851
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
852
- },
853
- {
854
- title: "initiator_assets",
855
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
856
- }
857
- ]
858
- },
859
- {
860
- title: "ActiveEscrow",
861
- dataType: "constructor",
862
- index: 1,
863
- fields: [
864
- {
865
- title: "initiator",
1122
+ title: "seller",
866
1123
  $ref: "#/definitions/aiken~1transaction~1credential~1Address"
867
1124
  },
868
1125
  {
869
- title: "initiator_assets",
870
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
1126
+ title: "price",
1127
+ $ref: "#/definitions/Int"
871
1128
  },
872
1129
  {
873
- title: "recipient",
874
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
1130
+ title: "policy",
1131
+ $ref: "#/definitions/ByteArray"
875
1132
  },
876
1133
  {
877
- title: "recipient_assets",
878
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
1134
+ title: "tokenName",
1135
+ $ref: "#/definitions/ByteArray"
879
1136
  }
880
1137
  ]
881
1138
  }
882
1139
  ]
883
1140
  },
884
- "escrow/types/EscrowRedeemer": {
885
- title: "EscrowRedeemer",
1141
+ "marketplace/types/MarketplaceRedeemer": {
1142
+ title: "MarketplaceRedeemer",
886
1143
  anyOf: [
887
1144
  {
888
- title: "RecipientDeposit",
1145
+ title: "Buy",
889
1146
  dataType: "constructor",
890
1147
  index: 0,
891
- fields: [
892
- {
893
- title: "recipient",
894
- $ref: "#/definitions/aiken~1transaction~1credential~1Address"
895
- },
896
- {
897
- title: "recipient_assets",
898
- $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
899
- }
900
- ]
901
- },
902
- {
903
- title: "CancelTrade",
904
- dataType: "constructor",
905
- index: 1,
906
1148
  fields: []
907
1149
  },
908
1150
  {
909
- title: "CompleteTrade",
1151
+ title: "Close",
910
1152
  dataType: "constructor",
911
- index: 2,
1153
+ index: 1,
912
1154
  fields: []
913
1155
  }
914
1156
  ]
@@ -916,389 +1158,130 @@ var plutus_default3 = {
916
1158
  }
917
1159
  };
918
1160
 
919
- // src/escrow/offchain.ts
920
- var MeshEscrowBlueprint = plutus_default3;
921
- var initiateEscrowDatum = (walletAddress, amount) => {
922
- const { pubKeyHash, stakeCredentialHash } = (0, import_core3.deserializeAddress)(walletAddress);
923
- return (0, import_common5.conStr0)([
924
- (0, import_common5.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
925
- (0, import_common5.value)(amount)
926
- ]);
927
- };
928
- var activeEscrowDatum = (initiationDatum, walletAddress, amount) => {
929
- const { pubKeyHash, stakeCredentialHash } = (0, import_core3.deserializeAddress)(walletAddress);
930
- const [initiator, initiatorAmount] = initiationDatum.fields;
931
- return (0, import_common5.conStr1)([
932
- initiator,
933
- initiatorAmount,
934
- (0, import_common5.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
935
- (0, import_common5.value)(amount)
1161
+ // src/marketplace/offchain.ts
1162
+ var MeshMarketplaceBlueprint = plutus_default4;
1163
+ var marketplaceDatum = (sellerAddress, lovelaceFee, assetHex) => {
1164
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core4.deserializeAddress)(sellerAddress);
1165
+ const { policyId, assetName } = (0, import_common6.parseAssetUnit)(assetHex);
1166
+ return (0, import_common6.conStr0)([
1167
+ (0, import_common6.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
1168
+ (0, import_common6.integer)(lovelaceFee),
1169
+ (0, import_common6.currencySymbol)(policyId),
1170
+ (0, import_common6.tokenName)(assetName)
936
1171
  ]);
937
1172
  };
938
- var recipientDepositRedeemer = (recipient, depositAmount) => initiateEscrowDatum(recipient, depositAmount);
939
- var MeshEscrowContract = class extends MeshTxInitiator {
940
- scriptCbor = (0, import_core_csl4.applyParamsToScript)(plutus_default3.validators[0].compiledCode, []);
941
- constructor(inputs) {
1173
+ var MeshMarketplaceContract = class extends MeshTxInitiator {
1174
+ ownerAddress;
1175
+ feePercentageBasisPoint;
1176
+ scriptCbor;
1177
+ constructor(inputs, ownerAddress, feePercentageBasisPoint) {
942
1178
  super(inputs);
943
- }
944
- initiateEscrow = async (escrowAmount) => {
945
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
946
- const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
947
- { code: this.scriptCbor, version: "V2" },
948
- void 0,
949
- this.networkId
950
- );
951
- await this.mesh.txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(
952
- initiateEscrowDatum(walletAddress, escrowAmount),
1179
+ this.ownerAddress = ownerAddress;
1180
+ this.feePercentageBasisPoint = feePercentageBasisPoint;
1181
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core4.deserializeAddress)(ownerAddress);
1182
+ this.scriptCbor = (0, import_core_csl5.applyParamsToScript)(
1183
+ plutus_default4.validators[0].compiledCode,
1184
+ [
1185
+ (0, import_common6.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
1186
+ (0, import_common6.integer)(feePercentageBasisPoint)
1187
+ ],
953
1188
  "JSON"
954
- ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
955
- return this.mesh.txHex;
956
- };
957
- cancelEscrow = async (escrowUtxo) => {
958
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
959
- const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
960
- { code: this.scriptCbor, version: "V2" },
961
- void 0,
962
- this.networkId
963
1189
  );
964
- const inputDatum = (0, import_core3.deserializeDatum)(
965
- escrowUtxo.output.plutusData
966
- );
967
- if (inputDatum.constructor === 1) {
968
- const [
969
- initiatorAddressObj,
970
- initiatorAmount,
971
- recipientAddressObj,
972
- recipientAmount
973
- ] = inputDatum.fields;
974
- const initiatorAddress = (0, import_core3.serializeAddressObj)(initiatorAddressObj);
975
- const recipientAddress = (0, import_core3.serializeAddressObj)(recipientAddressObj);
976
- const initiatorToReceive = import_common5.MeshValue.fromValue(initiatorAmount).toAssets();
977
- const recipientToReceive = import_common5.MeshValue.fromValue(recipientAmount).toAssets();
978
- this.mesh.txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive);
979
- }
980
- await this.mesh.spendingPlutusScriptV2().txIn(
981
- escrowUtxo.input.txHash,
982
- escrowUtxo.input.outputIndex,
983
- escrowUtxo.output.amount,
984
- scriptAddr
985
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common5.mConStr1)([])).txInScript(this.scriptCbor).requiredSignerHash((0, import_core3.deserializeAddress)(walletAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
986
- collateral.input.txHash,
987
- collateral.input.outputIndex,
988
- collateral.output.amount,
989
- collateral.output.address
990
- ).selectUtxosFrom(utxos).complete();
991
- return this.mesh.txHex;
992
- };
993
- recipientDeposit = async (escrowUtxo, depositAmount) => {
994
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
995
- const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
996
- { code: this.scriptCbor, version: "V2" },
997
- void 0,
998
- this.networkId
999
- );
1000
- const inputDatum = (0, import_core3.deserializeDatum)(
1001
- escrowUtxo.output.plutusData
1002
- );
1003
- const outputDatum = activeEscrowDatum(
1004
- inputDatum,
1005
- walletAddress,
1006
- depositAmount
1007
- );
1008
- const inputAssets = import_common5.MeshValue.fromValue(inputDatum.fields[1]).toAssets();
1009
- const escrowAmount = (0, import_core3.mergeAssets)([...depositAmount, ...inputAssets]);
1010
- await this.mesh.spendingPlutusScriptV2().txIn(
1011
- escrowUtxo.input.txHash,
1012
- escrowUtxo.input.outputIndex,
1013
- escrowUtxo.output.amount,
1014
- scriptAddr
1015
- ).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(
1016
- recipientDepositRedeemer(walletAddress, depositAmount),
1017
- "JSON",
1018
- {
1019
- mem: 7e6,
1020
- steps: 3e9
1021
- }
1022
- ).txInScript(this.scriptCbor).txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).txInCollateral(
1023
- collateral.input.txHash,
1024
- collateral.input.outputIndex,
1025
- collateral.output.amount,
1026
- collateral.output.address
1027
- ).selectUtxosFrom(utxos).complete();
1028
- return this.mesh.txHex;
1029
- };
1030
- completeEscrow = async (escrowUtxo) => {
1031
- const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1032
- const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
1033
- { code: this.scriptCbor, version: "V2" },
1034
- void 0,
1035
- this.networkId
1036
- );
1037
- const inputDatum = (0, import_core3.deserializeDatum)(
1038
- escrowUtxo.output.plutusData
1039
- );
1040
- const [
1041
- initiatorAddressObj,
1042
- initiatorAmount,
1043
- recipientAddressObj,
1044
- recipientAmount
1045
- ] = inputDatum.fields;
1046
- const initiatorAddress = (0, import_core3.serializeAddressObj)(initiatorAddressObj);
1047
- const recipientAddress = (0, import_core3.serializeAddressObj)(recipientAddressObj);
1048
- const initiatorToReceive = import_common5.MeshValue.fromValue(recipientAmount).toAssets();
1049
- const recipientToReceive = import_common5.MeshValue.fromValue(initiatorAmount).toAssets();
1050
- await this.mesh.spendingPlutusScriptV2().txIn(
1051
- escrowUtxo.input.txHash,
1052
- escrowUtxo.input.outputIndex,
1053
- escrowUtxo.output.amount,
1054
- scriptAddr
1055
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common5.mConStr2)([])).txInScript(this.scriptCbor).txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive).requiredSignerHash((0, import_core3.deserializeAddress)(recipientAddress).pubKeyHash).requiredSignerHash((0, import_core3.deserializeAddress)(initiatorAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
1056
- collateral.input.txHash,
1057
- collateral.input.outputIndex,
1058
- collateral.output.amount,
1059
- collateral.output.address
1060
- ).selectUtxosFrom(utxos).complete();
1061
- return this.mesh.txHex;
1062
- };
1063
- getUtxoByTxHash = async (txHash) => {
1064
- return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1065
- };
1066
- };
1067
-
1068
- // src/giftcard/offchain.ts
1069
- var import_common7 = require("@meshsdk/common");
1070
- var import_core4 = require("@meshsdk/core");
1071
- var import_core_csl5 = require("@meshsdk/core-csl");
1072
-
1073
- // src/giftcard/aiken-workspace/plutus.json
1074
- var plutus_default4 = {
1075
- preamble: {
1076
- title: "meshjs/giftcard",
1077
- description: "Aiken contracts for project 'meshjs/giftcard'",
1078
- version: "0.0.0",
1079
- plutusVersion: "v2",
1080
- compiler: {
1081
- name: "Aiken",
1082
- version: "v1.0.29-alpha+unknown"
1083
- },
1084
- license: "Apache-2.0"
1085
- },
1086
- validators: [
1087
- {
1088
- title: "oneshot.gift_card",
1089
- redeemer: {
1090
- title: "rdmr",
1091
- schema: {
1092
- $ref: "#/definitions/oneshot~1Action"
1093
- }
1094
- },
1095
- parameters: [
1096
- {
1097
- title: "token_name",
1098
- schema: {
1099
- $ref: "#/definitions/ByteArray"
1100
- }
1101
- },
1102
- {
1103
- title: "utxo_ref",
1104
- schema: {
1105
- $ref: "#/definitions/aiken~1transaction~1OutputReference"
1106
- }
1107
- }
1108
- ],
1109
- compiledCode: "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
1110
- hash: "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
1111
- },
1112
- {
1113
- title: "oneshot.redeem",
1114
- datum: {
1115
- title: "_d",
1116
- schema: {
1117
- $ref: "#/definitions/Data"
1118
- }
1119
- },
1120
- redeemer: {
1121
- title: "_r",
1122
- schema: {
1123
- $ref: "#/definitions/Data"
1124
- }
1125
- },
1126
- parameters: [
1127
- {
1128
- title: "token_name",
1129
- schema: {
1130
- $ref: "#/definitions/ByteArray"
1131
- }
1132
- },
1133
- {
1134
- title: "policy_id",
1135
- schema: {
1136
- $ref: "#/definitions/ByteArray"
1137
- }
1138
- }
1139
- ],
1140
- compiledCode: "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
1141
- hash: "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
1142
- }
1143
- ],
1144
- definitions: {
1145
- ByteArray: {
1146
- dataType: "bytes"
1147
- },
1148
- Data: {
1149
- title: "Data",
1150
- description: "Any Plutus data."
1151
- },
1152
- Int: {
1153
- dataType: "integer"
1154
- },
1155
- "aiken/transaction/OutputReference": {
1156
- title: "OutputReference",
1157
- 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",
1158
- anyOf: [
1159
- {
1160
- title: "OutputReference",
1161
- dataType: "constructor",
1162
- index: 0,
1163
- fields: [
1164
- {
1165
- title: "transaction_id",
1166
- $ref: "#/definitions/aiken~1transaction~1TransactionId"
1167
- },
1168
- {
1169
- title: "output_index",
1170
- $ref: "#/definitions/Int"
1171
- }
1172
- ]
1173
- }
1174
- ]
1175
- },
1176
- "aiken/transaction/TransactionId": {
1177
- title: "TransactionId",
1178
- 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.",
1179
- anyOf: [
1180
- {
1181
- title: "TransactionId",
1182
- dataType: "constructor",
1183
- index: 0,
1184
- fields: [
1185
- {
1186
- title: "hash",
1187
- $ref: "#/definitions/ByteArray"
1188
- }
1189
- ]
1190
- }
1191
- ]
1192
- },
1193
- "oneshot/Action": {
1194
- title: "Action",
1195
- anyOf: [
1196
- {
1197
- title: "Mint",
1198
- dataType: "constructor",
1199
- index: 0,
1200
- fields: []
1201
- },
1202
- {
1203
- title: "Burn",
1204
- dataType: "constructor",
1205
- index: 1,
1206
- fields: []
1207
- }
1208
- ]
1209
- }
1210
1190
  }
1211
- };
1212
-
1213
- // src/giftcard/offchain.ts
1214
- var MeshGiftCardBlueprint = plutus_default4;
1215
- var MeshGiftCardContract = class extends MeshTxInitiator {
1216
- tokenNameHex = "";
1217
- paramUtxo = { outputIndex: 0, txHash: "" };
1218
- giftCardCbor = (tokenNameHex, utxoTxHash, utxoTxId) => {
1219
- return (0, import_core_csl5.applyParamsToScript)(
1220
- plutus_default4.validators[0].compiledCode,
1221
- [(0, import_common7.builtinByteString)(tokenNameHex), (0, import_common7.txOutRef)(utxoTxHash, utxoTxId)],
1222
- "JSON"
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 } = (0, import_core4.serializePlutusScript)(
1196
+ { code: this.scriptCbor, version: "V2" },
1197
+ void 0,
1198
+ this.networkId
1223
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;
1224
1204
  };
1225
- redeemCbor = (tokenNameHex, policyId) => (0, import_core_csl5.applyParamsToScript)(plutus_default4.validators[1].compiledCode, [
1226
- tokenNameHex,
1227
- policyId
1228
- ]);
1229
- constructor(inputs, tokenNameHex, paramUtxo) {
1230
- super(inputs);
1231
- if (tokenNameHex) {
1232
- this.tokenNameHex = tokenNameHex;
1233
- }
1234
- if (paramUtxo) {
1235
- this.paramUtxo = paramUtxo;
1236
- }
1237
- }
1238
- createGiftCard = async (tokenName2, giftValue) => {
1205
+ delistAsset = async (marketplaceUtxo) => {
1239
1206
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1240
- const tokenNameHex = (0, import_common7.stringToHex)(tokenName2);
1241
- const firstUtxo = utxos[0];
1242
- if (firstUtxo === void 0) throw new Error("No UTXOs available");
1243
- const remainingUtxos = utxos.slice(1);
1244
- const giftCardScript = this.giftCardCbor(
1245
- tokenNameHex,
1246
- firstUtxo.input.txHash,
1247
- firstUtxo.input.outputIndex
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((0, import_common6.mConStr1)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).requiredSignerHash((0, import_core4.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
1213
+ collateral.input.txHash,
1214
+ collateral.input.outputIndex,
1215
+ collateral.output.amount,
1216
+ collateral.output.address
1217
+ ).selectUtxosFrom(utxos).complete();
1218
+ return this.mesh.txHex;
1219
+ };
1220
+ purchaseAsset = async (marketplaceUtxo) => {
1221
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1222
+ const inputDatum = (0, import_core4.deserializeDatum)(
1223
+ marketplaceUtxo.output.plutusData
1248
1224
  );
1249
- const giftCardPolicy = (0, import_core4.resolveScriptHash)(giftCardScript, "V2");
1250
- const redeemScript = {
1251
- code: this.redeemCbor(tokenNameHex, giftCardPolicy),
1252
- version: "V2"
1253
- };
1254
- const redeemAddr = (0, import_core4.serializePlutusScript)(
1255
- redeemScript,
1256
- void 0,
1257
- this.networkId
1258
- ).address;
1259
- await this.mesh.txIn(
1260
- firstUtxo.input.txHash,
1261
- firstUtxo.input.outputIndex,
1262
- firstUtxo.output.amount,
1263
- firstUtxo.output.address
1264
- ).mintPlutusScriptV2().mint("1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common7.mConStr0)([])).txOut(redeemAddr, [
1265
- ...giftValue,
1266
- { unit: giftCardPolicy + tokenNameHex, quantity: "1" }
1267
- ]).txOutInlineDatumValue([
1268
- firstUtxo.input.txHash,
1269
- firstUtxo.input.outputIndex,
1270
- tokenNameHex
1271
- ]).changeAddress(walletAddress).txInCollateral(
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((0, import_common6.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
1272
1234
  collateral.input.txHash,
1273
1235
  collateral.input.outputIndex,
1274
1236
  collateral.output.amount,
1275
1237
  collateral.output.address
1276
- ).selectUtxosFrom(remainingUtxos).complete();
1277
- this.tokenNameHex = tokenNameHex;
1278
- this.paramUtxo = firstUtxo.input;
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 = (0, import_core4.serializeAddressObj)(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();
1279
1265
  return this.mesh.txHex;
1280
1266
  };
1281
- redeemGiftCard = async (giftCardUtxo) => {
1267
+ relistAsset = async (marketplaceUtxo, newPrice) => {
1282
1268
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1283
- const inlineDatum = (0, import_core4.deserializeDatum)(
1284
- giftCardUtxo.output.plutusData
1285
- ).list;
1286
- const paramTxHash = inlineDatum[0].bytes;
1287
- const paramTxId = inlineDatum[1].int;
1288
- const tokenNameHex = inlineDatum[2].bytes;
1289
- const giftCardScript = this.giftCardCbor(
1290
- tokenNameHex,
1291
- paramTxHash,
1292
- paramTxId
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 } = (0, import_core4.serializePlutusScript)(
1275
+ { code: this.scriptCbor, version: "V2" },
1276
+ void 0,
1277
+ this.networkId
1293
1278
  );
1294
- const giftCardPolicy = (0, import_core4.resolveScriptHash)(giftCardScript, "V2");
1295
- const redeemScript = this.redeemCbor(tokenNameHex, giftCardPolicy);
1296
1279
  await this.mesh.spendingPlutusScriptV2().txIn(
1297
- giftCardUtxo.input.txHash,
1298
- giftCardUtxo.input.outputIndex,
1299
- giftCardUtxo.output.amount,
1300
- giftCardUtxo.output.address
1301
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(redeemScript).mintPlutusScriptV2().mint("-1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common7.mConStr1)([])).changeAddress(walletAddress).txInCollateral(
1280
+ marketplaceUtxo.input.txHash,
1281
+ marketplaceUtxo.input.outputIndex,
1282
+ marketplaceUtxo.output.amount,
1283
+ marketplaceUtxo.output.address
1284
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common6.mConStr1)([])).txInScript(this.scriptCbor).txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).requiredSignerHash((0, import_core4.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
1302
1285
  collateral.input.txHash,
1303
1286
  collateral.input.outputIndex,
1304
1287
  collateral.output.amount,
@@ -1307,12 +1290,12 @@ var MeshGiftCardContract = class extends MeshTxInitiator {
1307
1290
  return this.mesh.txHex;
1308
1291
  };
1309
1292
  getUtxoByTxHash = async (txHash) => {
1310
- return await this._getUtxoByTxHash(txHash);
1293
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1311
1294
  };
1312
1295
  };
1313
1296
 
1314
1297
  // src/payment-splitter/offchain.ts
1315
- var import_common9 = require("@meshsdk/common");
1298
+ var import_common8 = require("@meshsdk/common");
1316
1299
  var import_core5 = require("@meshsdk/core");
1317
1300
  var import_core_csl6 = require("@meshsdk/core-csl");
1318
1301
 
@@ -1404,9 +1387,9 @@ var plutus_default5 = {
1404
1387
  // src/payment-splitter/offchain.ts
1405
1388
  var MeshPaymentSplitterBlueprint = plutus_default5;
1406
1389
  var MeshPaymentSplitterContract = class extends MeshTxInitiator {
1407
- wrapPayees = (payees) => (0, import_common9.list)(
1390
+ wrapPayees = (payees) => (0, import_common8.list)(
1408
1391
  payees.map(
1409
- (payee) => (0, import_common9.builtinByteString)((0, import_core5.deserializeAddress)(payee).pubKeyHash)
1392
+ (payee) => (0, import_common8.builtinByteString)((0, import_core5.deserializeAddress)(payee).pubKeyHash)
1410
1393
  )
1411
1394
  );
1412
1395
  scriptCbor = () => (0, import_core_csl6.applyParamsToScript)(
@@ -1512,7 +1495,7 @@ var MeshPaymentSplitterContract = class extends MeshTxInitiator {
1512
1495
  };
1513
1496
 
1514
1497
  // src/swap/offchain.ts
1515
- var import_common11 = require("@meshsdk/common");
1498
+ var import_common10 = require("@meshsdk/common");
1516
1499
  var import_core6 = require("@meshsdk/core");
1517
1500
  var import_core_csl7 = require("@meshsdk/core-csl");
1518
1501
 
@@ -1738,10 +1721,10 @@ var MeshSwapContract = class extends MeshTxInitiator {
1738
1721
  initiateSwap = async (toProvide, toReceive) => {
1739
1722
  const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1740
1723
  const { pubKeyHash, stakeCredentialHash } = (0, import_core6.deserializeAddress)(walletAddress);
1741
- const swapDatum = (0, import_common11.conStr0)([
1742
- (0, import_common11.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
1743
- (0, import_common11.value)(toProvide),
1744
- (0, import_common11.value)(toReceive)
1724
+ const swapDatum = (0, import_common10.conStr0)([
1725
+ (0, import_common10.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
1726
+ (0, import_common10.value)(toProvide),
1727
+ (0, import_common10.value)(toReceive)
1745
1728
  ]);
1746
1729
  await this.mesh.txOut(this.scriptAddress, toProvide).txOutInlineDatumValue(swapDatum, "JSON").changeAddress(walletAddress).txInCollateral(
1747
1730
  collateral.input.txHash,
@@ -1763,9 +1746,9 @@ var MeshSwapContract = class extends MeshTxInitiator {
1763
1746
  swapUtxo.input.outputIndex,
1764
1747
  swapUtxo.output.amount,
1765
1748
  swapUtxo.output.address
1766
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common11.mConStr1)([])).txInScript(this.scriptCbor).txOut(
1749
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common10.mConStr1)([])).txInScript(this.scriptCbor).txOut(
1767
1750
  initiatorAddress,
1768
- import_common11.MeshValue.fromValue(initiatorToReceive).toAssets()
1751
+ import_common10.MeshValue.fromValue(initiatorToReceive).toAssets()
1769
1752
  ).changeAddress(walletAddress).txInCollateral(
1770
1753
  collateral.input.txHash,
1771
1754
  collateral.input.outputIndex,
@@ -1785,7 +1768,7 @@ var MeshSwapContract = class extends MeshTxInitiator {
1785
1768
  swapUtxo.input.outputIndex,
1786
1769
  swapUtxo.output.amount,
1787
1770
  swapUtxo.output.address
1788
- ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common11.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
1771
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common10.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
1789
1772
  collateral.input.txHash,
1790
1773
  collateral.input.outputIndex,
1791
1774
  collateral.output.amount,
@@ -1797,12 +1780,151 @@ var MeshSwapContract = class extends MeshTxInitiator {
1797
1780
  return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1798
1781
  };
1799
1782
  };
1783
+
1784
+ // src/vesting/offchain.ts
1785
+ var import_common12 = require("@meshsdk/common");
1786
+ var import_core7 = require("@meshsdk/core");
1787
+ var import_core_csl8 = require("@meshsdk/core-csl");
1788
+
1789
+ // src/vesting/aiken-workspace/plutus.json
1790
+ var plutus_default7 = {
1791
+ preamble: {
1792
+ title: "meshjs/vesting",
1793
+ description: "Aiken contracts for project 'meshjs/vesting'",
1794
+ version: "0.0.0",
1795
+ plutusVersion: "v2",
1796
+ compiler: {
1797
+ name: "Aiken",
1798
+ version: "v1.0.29-alpha+unknown"
1799
+ },
1800
+ license: "Apache-2.0"
1801
+ },
1802
+ validators: [
1803
+ {
1804
+ title: "vesting.vesting",
1805
+ datum: {
1806
+ title: "datum",
1807
+ schema: {
1808
+ $ref: "#/definitions/vesting~1types~1VestingDatum"
1809
+ }
1810
+ },
1811
+ redeemer: {
1812
+ title: "_redeemer",
1813
+ schema: {
1814
+ $ref: "#/definitions/Data"
1815
+ }
1816
+ },
1817
+ compiledCode: "5901c40100003232323232323223222533300532533233007300130083754600460126ea800c4c8c8c94ccc028cc004dd6180118061baa3003300c375400c6eb8c014c030dd50048a511533300a330013758600460186ea8c00cc030dd50031bae300f30103010300c3754012266446464646464a666022601660246ea80084c94ccc0480104cdc40038008011bad301630133754004002264a666022601660246ea80084c94ccc0480100084cdc48038009bad3016301337540040022940c050008cdc424000601e6ea8c04cc050004cc044c048004cc044ccc034cdc424000601c6ea8c048c04c00530103d87a80004c0103d87980004bd7018071baa3005300e3754004601e602060206020602060206020602060186ea8c00cc030dd50031bad3003300c3754012294088c8cc00400400c894ccc040004528099299980719b8f375c602600400829444cc00c00c004c04c0048c038c03cc03cc03cc03cc03cc03cc03cc03c0048c034004dc3a400429408c02cc0300045261365653330023370e900018019baa0011323232323232533300b300e002149858dd7180600098060011bae300a001300a002375a601000260086ea8004595cd2ab9d5573caae7d5d02ba157441",
1818
+ hash: "ac96a3fa3cabf670268a88720402c715ed5fd73ffb3276e6092ead00"
1819
+ }
1820
+ ],
1821
+ definitions: {
1822
+ ByteArray: {
1823
+ dataType: "bytes"
1824
+ },
1825
+ Data: {
1826
+ title: "Data",
1827
+ description: "Any Plutus data."
1828
+ },
1829
+ Int: {
1830
+ dataType: "integer"
1831
+ },
1832
+ "vesting/types/VestingDatum": {
1833
+ title: "VestingDatum",
1834
+ anyOf: [
1835
+ {
1836
+ title: "VestingDatum",
1837
+ dataType: "constructor",
1838
+ index: 0,
1839
+ fields: [
1840
+ {
1841
+ title: "lock_until",
1842
+ description: "POSIX time in second, e.g. 1672843961000",
1843
+ $ref: "#/definitions/Int"
1844
+ },
1845
+ {
1846
+ title: "owner",
1847
+ description: "Owner's credentials",
1848
+ $ref: "#/definitions/ByteArray"
1849
+ },
1850
+ {
1851
+ title: "beneficiary",
1852
+ description: "Beneficiary's credentials",
1853
+ $ref: "#/definitions/ByteArray"
1854
+ }
1855
+ ]
1856
+ }
1857
+ ]
1858
+ }
1859
+ }
1860
+ };
1861
+
1862
+ // src/vesting/offchain.ts
1863
+ var MeshVestingBlueprint = plutus_default7;
1864
+ var MeshVestingContract = class extends MeshTxInitiator {
1865
+ scriptCbor = (0, import_core_csl8.applyParamsToScript)(plutus_default7.validators[0].compiledCode, []);
1866
+ constructor(inputs) {
1867
+ super(inputs);
1868
+ }
1869
+ depositFund = async (amount, lockUntilTimeStampMs, beneficiary) => {
1870
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
1871
+ const scriptAddr = (0, import_core7.serializePlutusScript)(
1872
+ { code: this.scriptCbor, version: "V2" },
1873
+ void 0,
1874
+ 0
1875
+ ).address;
1876
+ const { pubKeyHash: ownerPubKeyHash } = (0, import_core7.deserializeAddress)(walletAddress);
1877
+ const { pubKeyHash: beneficiaryPubKeyHash } = (0, import_core7.deserializeAddress)(beneficiary);
1878
+ await this.mesh.txOut(scriptAddr, amount).txOutInlineDatumValue(
1879
+ (0, import_common12.mConStr0)([
1880
+ lockUntilTimeStampMs,
1881
+ ownerPubKeyHash,
1882
+ beneficiaryPubKeyHash
1883
+ ])
1884
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
1885
+ return this.mesh.txHex;
1886
+ };
1887
+ withdrawFund = async (vestingUtxo) => {
1888
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1889
+ const { input: collateralInput, output: collateralOutput } = collateral;
1890
+ const scriptAddr = (0, import_core7.serializePlutusScript)(
1891
+ { code: this.scriptCbor, version: "V2" },
1892
+ void 0,
1893
+ 0
1894
+ ).address;
1895
+ const { pubKeyHash } = (0, import_core7.deserializeAddress)(walletAddress);
1896
+ const datum = (0, import_core7.deserializeDatum)(
1897
+ vestingUtxo.output.plutusData
1898
+ );
1899
+ const invalidBefore = (0, import_common12.unixTimeToEnclosingSlot)(
1900
+ Math.min(datum.fields[0].int, Date.now() - 15e3),
1901
+ this.networkId === 0 ? import_common12.SLOT_CONFIG_NETWORK.preprod : import_common12.SLOT_CONFIG_NETWORK.mainnet
1902
+ ) + 1;
1903
+ await this.mesh.spendingPlutusScriptV2().txIn(
1904
+ vestingUtxo.input.txHash,
1905
+ vestingUtxo.input.outputIndex,
1906
+ vestingUtxo.output.amount,
1907
+ scriptAddr
1908
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(walletAddress, []).txInCollateral(
1909
+ collateralInput.txHash,
1910
+ collateralInput.outputIndex,
1911
+ collateralOutput.amount,
1912
+ collateralOutput.address
1913
+ ).invalidBefore(invalidBefore).requiredSignerHash(pubKeyHash).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
1914
+ return this.mesh.txHex;
1915
+ };
1916
+ getUtxoByTxHash = async (txHash) => {
1917
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1918
+ };
1919
+ };
1800
1920
  // Annotate the CommonJS export names for ESM import in node:
1801
1921
  0 && (module.exports = {
1802
1922
  MeshEscrowBlueprint,
1803
1923
  MeshEscrowContract,
1804
1924
  MeshGiftCardBlueprint,
1805
1925
  MeshGiftCardContract,
1926
+ MeshHelloWorldBlueprint,
1927
+ MeshHelloWorldContract,
1806
1928
  MeshMarketplaceBlueprint,
1807
1929
  MeshMarketplaceContract,
1808
1930
  MeshPaymentSplitterBlueprint,