@meshsdk/contract 1.6.13 → 1.7.0

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