@meshsdk/contract 1.6.13 → 1.7.1

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