@meshsdk/contract 1.6.2 → 1.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,37 +1,1810 @@
1
- "use strict";var O=Object.defineProperty;var e0=Object.getOwnPropertyDescriptor;var t0=Object.getOwnPropertyNames;var a0=Object.prototype.hasOwnProperty;var c0=(o,e)=>{for(var t in e)O(o,t,{get:e[t],enumerable:!0})},i0=(o,e,t,c)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of t0(e))!a0.call(o,a)&&a!==t&&O(o,a,{get:()=>e[a],enumerable:!(c=e0(e,a))||c.enumerable});return o};var n0=o=>i0(O({},"__esModule",{value:!0}),o);var x0={};c0(x0,{MeshEscrowBlueprint:()=>u0,MeshEscrowContract:()=>_,MeshGiftCardBlueprint:()=>f0,MeshGiftCardContract:()=>U,MeshMarketplaceBlueprint:()=>r0,MeshMarketplaceContract:()=>H,MeshPaymentSplitterBlueprint:()=>m0,MeshPaymentSplitterContract:()=>W,MeshSwapBlueprint:()=>y0,MeshSwapContract:()=>j,MeshVestingBlueprint:()=>o0,MeshVestingContract:()=>R,activeEscrowDatum:()=>G,initiateEscrowDatum:()=>M,marketplaceDatum:()=>D,recipientDepositRedeemer:()=>Q});module.exports=n0(x0);var f=require("@meshsdk/common"),x=require("@meshsdk/core"),E=require("@meshsdk/core-csl");var L=require("@meshsdk/core-csl"),m=class{mesh;fetcher;wallet;stakeCredential;networkId=0;constructor({mesh:e,fetcher:t,wallet:c,networkId:a,stakeCredential:i}){this.mesh=e,t&&(this.fetcher=t),c&&(this.wallet=c),a&&(this.networkId=a),i&&(this.stakeCredential=this.stakeCredential)}signSubmitReset=async()=>{let e=this.mesh.completeSigning(),t=await this.mesh.submitTx(e);return this.mesh.reset(),t};queryUtxos=async e=>this.fetcher?await this.fetcher.fetchAddressUTxOs(e):[];getWalletDappAddress=async()=>{if(this.wallet){let e=await this.wallet.getUsedAddresses();if(e.length>0)return e[0];let t=await this.wallet.getUnusedAddresses();if(t.length>0)return t[0]}return""};getWalletCollateral=async()=>{if(this.wallet)return(await this.wallet.getCollateral())[0]};getWalletUtxosWithMinLovelace=async(e,t=[])=>{let c=t;return this.wallet&&(!t||t.length===0)&&(c=await this.wallet.getUtxos()),c.filter(a=>{let i=a.output.amount.find(n=>n.unit==="lovelace")?.quantity;return Number(i)>e})};getWalletUtxosWithToken=async(e,t=[])=>{let c=t;return this.wallet&&t.length===0&&(c=await this.wallet.getUtxos()),c.filter(a=>{let i=a.output.amount.find(n=>n.unit===e)?.quantity;return Number(i)>=1})};getAddressUtxosWithMinLovelace=async(e,t,c=[])=>{let a=c;return this.fetcher&&(!c||c.length===0)&&(a=await this.fetcher.fetchAddressUTxOs(e)),a.filter(i=>{let n=i.output.amount.find(s=>s.unit==="lovelace")?.quantity;return Number(n)>t})};getAddressUtxosWithToken=async(e,t,c=[])=>{let a=c;return this.fetcher&&c.length===0&&(a=await this.fetcher.fetchAddressUTxOs(e)),a.filter(i=>{let n=i.output.amount.find(s=>s.unit===t)?.quantity;return Number(n)>=1})};getWalletInfoForTx=async()=>{let e=await this.wallet?.getUtxos(),t=await this.getWalletCollateral(),c=await this.getWalletDappAddress();if(!e||e?.length===0)throw new Error("No utxos found");if(!t)throw new Error("No collateral found");if(!c)throw new Error("No wallet address found");return{utxos:e,collateral:t,walletAddress:c}};_getUtxoByTxHash=async(e,t)=>{if(this.fetcher){let c=await this.fetcher?.fetchUTxOs(e),a=c[0];if(t){let i=(0,L.v2ScriptToBech32)(t,void 0,this.networkId);a=c.filter(n=>n.output.address===i)[0]||c[0]}return a}}};var P={preamble:{title:"meshjs/marketplace",description:"Aiken contracts for project 'meshjs/marketplace'",version:"0.0.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.29-alpha+unknown"},license:"Apache-2.0"},validators:[{title:"marketplace.marketplace",datum:{title:"datum",schema:{$ref:"#/definitions/marketplace~1types~1MarketplaceDatum"}},redeemer:{title:"redeemer",schema:{$ref:"#/definitions/marketplace~1types~1MarketplaceRedeemer"}},parameters:[{title:"owner",schema:{$ref:"#/definitions/aiken~1transaction~1credential~1Address"}},{title:"fee_percentage_basis_point",schema:{$ref:"#/definitions/Int"}}],compiledCode:"59082f01000032323232323232223223232322322533300b3232323232323232325333014300e30153754002264a66602a6020602c6ea80344c94ccc058c044c05cdd50008991919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc048c084dd5180898109baa00200513302300233004004001133004004001302400230220013758601860366ea8c030c06cdd50079806180d9baa300b301b37540062a6660320022004294052819803998049bac3008301a3754601660346ea803805cc018cdc199b82375a601460346ea805005520a09c0133006330083758600e60326ea8c028c064dd50069805180c9baa0133005337006eb4c024c064dd50099998059bab300930193754601260326ea8005220100488100301b301837540022c64660020026eb0c024c060dd51804980c1baa00c22533301a00114c0103d87a80001323253330193375e601860366ea80080144c038cc0740092f5c0266008008002603c0046038002264a66602c6022602e6ea80044cc88c8cc00400400c894ccc074004528099299980d99b8f375c604000400829444cc00c00c004c080004dd6180d980e180e180e180e180e180e180e180e180c1baa3009301837540186eb8c06cc060dd50008b19299980b1808980b9baa0011300b3301a301b3018375400297ae014c0103d87a80003008301737546010602e6ea8044c064c058dd50008a503005301537540124a666026601c002297adef6c6013232330010014bd6f7b63011299980c80089980d19bb04c01014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c06800488c8cc004004c8cc00400400c894ccc06400452f5c0264666444646600200200644a66603e0022006264660426e9ccc084dd480319810980f00099810980f800a5eb80cc00c00cc08c008c084004dd7180c0009bab301900133003003301d002301b00122533301800114a2264a66602c6466e24dd698038009998058031bae300a001375c60120026eb0c06c0084cc00c00c004528180d8009180b180b980b80091191980080080191299980b0008a5eb7bdb1804cc894ccc054cdd79804180b9baa0020051323330010010023756601060306ea800c8894ccc06c00840044c8ccc010010c07c00ccc88c8cc004004014894ccc0800044cc084cdd81ba9004374c00697adef6c6013232323253330213372001000426604a66ec0dd48041ba6007005153330213371e010004264a666044603a60466ea80044cc098cdd81ba9009302730243754002008200864a666044a66604a00229445280a6103d87a80001301733026374c00297ae03233300100100800222253330270021001132333004004302b0033322323300100100522533302c00113302d337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0b4cdc800400109981899bb037520106ea001c01454ccc0b4cdc78040010992999817181498179baa001133032337606ea4024c0ccc0c0dd5000802080219299981718148008a60103d87a80001302333032375000297ae03370000e00226606266ec0dd48011ba800133006006003375a605c0066eb8c0b0008c0c0008c0b8004dd718130009bad30270013029002133025337606ea4008dd3000998030030019bab3022003375c6040004604800460440026eb8c068004dd5980d800980e8010800980c00099801001180c8009180a180a80091809800911192999808180518089baa0011480004dd6980a98091baa001325333010300a301137540022980103d87a8000132330010013756602c60266ea8008894ccc054004530103d87a80001323232325333016337220100042a66602c66e3c0200084c02ccc068dd4000a5eb80530103d87a8000133006006003375a602e0066eb8c054008c064008c05c004c8cc004004010894ccc0500045300103d87a80001323232325333015337220100042a66602a66e3c0200084c028cc064dd3000a5eb80530103d87a80001330060060033756602c0066eb8c050008c060008c058004dd2a400029309b2b19299980518028008a99980698061baa00214985854ccc028c01000454ccc034c030dd50010a4c2c2c60146ea8004c94ccc020c00cc024dd5002099191919191919192999809980b00109924ca666020601660226ea801c4c8c8c8c94ccc05cc0680084c8c926325333016301100113232533301b301e002132498c94ccc064c0500044c8c94ccc078c0840084c926301400116301f001301b37540042a66603260260022646464646464a666044604a0042930b1bad30230013023002375a604200260420046eb4c07c004c06cdd50010b180c9baa00116301c001301837540062a66602c60200022a66603260306ea800c526161630163754004601a0062c60300026030004602c00260246ea801c5858dd7180a000980a0011bae30120013012002375a60200026020004601c00260146ea8010588c94ccc024c0100044c8c94ccc038c04400852616375c601e00260166ea800854ccc024c00c0044c8c94ccc038c04400852616375c601e00260166ea800858c024dd50009b8748008dc3a40006eb40055cd2ab9d5573caae7d5d02ba157441",hash:"cd144c1e18d8e44dfeacb018a2795d17d7c30574a427eb2aa2dbc87c"}],definitions:{ByteArray:{dataType:"bytes"},Int:{dataType:"integer"},"Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Optional",anyOf:[{title:"Some",description:"An optional value.",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]},{title:"None",description:"Nothing.",dataType:"constructor",index:1,fields:[]}]},"aiken/transaction/credential/Address":{title:"Address",description:`A Cardano \`Address\` typically holding one or two credential references.
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are
4
- completely excluded from Plutus contexts. Thus, from an on-chain
5
- perspective only exists addresses of type 00, 01, ..., 07 as detailed
6
- in [CIP-0019 :: Shelley Addresses](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019/#shelley-addresses).`,anyOf:[{title:"Address",dataType:"constructor",index:0,fields:[{title:"payment_credential",$ref:"#/definitions/aiken~1transaction~1credential~1Credential"},{title:"stake_credential",$ref:"#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]}]},"aiken/transaction/credential/Credential":{title:"Credential",description:`A general structure for representing an on-chain \`Credential\`.
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ MeshEscrowBlueprint: () => MeshEscrowBlueprint,
24
+ MeshEscrowContract: () => MeshEscrowContract,
25
+ MeshGiftCardBlueprint: () => MeshGiftCardBlueprint,
26
+ MeshGiftCardContract: () => MeshGiftCardContract,
27
+ MeshMarketplaceBlueprint: () => MeshMarketplaceBlueprint,
28
+ MeshMarketplaceContract: () => MeshMarketplaceContract,
29
+ MeshPaymentSplitterBlueprint: () => MeshPaymentSplitterBlueprint,
30
+ MeshPaymentSplitterContract: () => MeshPaymentSplitterContract,
31
+ MeshSwapBlueprint: () => MeshSwapBlueprint,
32
+ MeshSwapContract: () => MeshSwapContract,
33
+ MeshVestingBlueprint: () => MeshVestingBlueprint,
34
+ MeshVestingContract: () => MeshVestingContract,
35
+ activeEscrowDatum: () => activeEscrowDatum,
36
+ initiateEscrowDatum: () => initiateEscrowDatum,
37
+ marketplaceDatum: () => marketplaceDatum,
38
+ recipientDepositRedeemer: () => recipientDepositRedeemer
39
+ });
40
+ module.exports = __toCommonJS(src_exports);
7
41
 
8
- Credentials are always one of two kinds: a direct public/private key
9
- pair, or a script (native or Plutus).`,anyOf:[{title:"VerificationKeyCredential",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/ByteArray"}]},{title:"ScriptCredential",dataType:"constructor",index:1,fields:[{$ref:"#/definitions/ByteArray"}]}]},"aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Referenced",description:`Represent a type of object that can be represented either inline (by hash)
10
- or via a reference (i.e. a pointer to an on-chain location).
42
+ // src/marketplace/offchain.ts
43
+ var import_common = require("@meshsdk/common");
44
+ var import_core = require("@meshsdk/core");
45
+ var import_core_csl2 = require("@meshsdk/core-csl");
11
46
 
12
- This is mainly use for capturing pointers to a stake credential
13
- registration certificate in the case of so-called pointer addresses.`,anyOf:[{title:"Inline",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Credential"}]},{title:"Pointer",dataType:"constructor",index:1,fields:[{title:"slot_number",$ref:"#/definitions/Int"},{title:"transaction_index",$ref:"#/definitions/Int"},{title:"certificate_index",$ref:"#/definitions/Int"}]}]},"marketplace/types/MarketplaceDatum":{title:"MarketplaceDatum",anyOf:[{title:"MarketplaceDatum",dataType:"constructor",index:0,fields:[{title:"seller",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"price",$ref:"#/definitions/Int"},{title:"policy",$ref:"#/definitions/ByteArray"},{title:"tokenName",$ref:"#/definitions/ByteArray"}]}]},"marketplace/types/MarketplaceRedeemer":{title:"MarketplaceRedeemer",anyOf:[{title:"Buy",dataType:"constructor",index:0,fields:[]},{title:"Close",dataType:"constructor",index:1,fields:[]}]}}};var r0=P,D=(o,e,t)=>{let{pubKeyHash:c,stakeCredentialHash:a}=(0,x.deserializeAddress)(o),{policyId:i,assetName:n}=(0,f.parseAssetUnit)(t);return(0,f.conStr0)([(0,f.pubKeyAddress)(c,a),(0,f.integer)(e),(0,f.currencySymbol)(i),(0,f.tokenName)(n)])},H=class extends m{ownerAddress;feePercentageBasisPoint;scriptCbor;constructor(e,t,c){super(e),this.ownerAddress=t,this.feePercentageBasisPoint=c;let{pubKeyHash:a,stakeCredentialHash:i}=(0,x.deserializeAddress)(t);this.scriptCbor=(0,E.applyParamsToScript)(P.validators[0].compiledCode,[(0,f.pubKeyAddress)(a,i),(0,f.integer)(c)],"JSON")}listAsset=async(e,t)=>{let{utxos:c,walletAddress:a}=await this.getWalletInfoForTx();new Map().set(e,"1");let{address:n}=(0,x.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId),s=[{unit:e,quantity:"1"}],d=D(a,t,e);return await this.mesh.txOut(n,s).txOutInlineDatumValue(d,"JSON").changeAddress(a).selectUtxosFrom(c).complete(),this.mesh.txHex};delistAsset=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx();return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,f.mConStr1)([])).txInScript(this.scriptCbor).changeAddress(c).requiredSignerHash((0,x.deserializeAddress)(c).pubKeyHash).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t).complete(),this.mesh.txHex};purchaseAsset=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),i=(0,x.deserializeDatum)(e.output.plutusData),n=i.fields[1].int.toString(),s=e.output.amount.find(b=>b.unit==="lovelace").quantity,d=this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,f.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t),l=i.fields[1].int*this.feePercentageBasisPoint/1e4;if(this.feePercentageBasisPoint>0&&l<1e6&&(l=1e6),l>0){let b=this.ownerAddress,g=[{unit:"lovelace",quantity:Math.ceil(l).toString()}];d.txOut(b,g)}let r=i.fields[1].int+Number(s);if(r>0){let b=(0,x.serializeAddressObj)(i.fields[0]),g=[{unit:"lovelace",quantity:r.toString()}];d.txOut(b,g)}return await d.complete(),this.mesh.txHex};relistAsset=async(e,t)=>{let{utxos:c,walletAddress:a,collateral:i}=await this.getWalletInfoForTx(),n=e.output.amount.find(r=>r.unit!=="lovelace").unit,s=[{unit:n,quantity:"1"}],d=D(a,t,n),{address:l}=(0,x.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId);return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,f.mConStr1)([])).txInScript(this.scriptCbor).txOut(l,s).txOutInlineDatumValue(d,"JSON").changeAddress(a).requiredSignerHash((0,x.deserializeAddress)(a).pubKeyHash).txInCollateral(i.input.txHash,i.input.outputIndex,i.output.amount,i.output.address).selectUtxosFrom(c).complete(),this.mesh.txHex};getUtxoByTxHash=async e=>await this._getUtxoByTxHash(e,this.scriptCbor)};var k=require("@meshsdk/common"),T=require("@meshsdk/core"),z=require("@meshsdk/core-csl");var B={preamble:{title:"meshjs/vesting",description:"Aiken contracts for project 'meshjs/vesting'",version:"0.0.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.29-alpha+unknown"},license:"Apache-2.0"},validators:[{title:"vesting.vesting",datum:{title:"datum",schema:{$ref:"#/definitions/vesting~1types~1VestingDatum"}},redeemer:{title:"_redeemer",schema:{$ref:"#/definitions/ByteArray"}},compiledCode:"5901c801000032323232323232232232253330063232323253323300b3001300c3754600a601a6ea801854ccc02ccc010dd6180198069baa3002300d375400c6eb8c014c034dd50050a511533300b3300437586006601a6ea8c008c034dd50031bae301030113011300d3754014266446464646464a666024601060266ea80084c94ccc04c0104cdc40038008011bad301730143754004002264a666024601060266ea80084c94ccc04c0100084cdc48038009bad3017301437540040022940c054008cdc42400060206ea8c050c054004cc048c04c004cc048ccc038cdc424000601e6ea8c04cc05000530103d87a80004c0103d87980004bd7018079baa3004300f375400460206022602260226022602260226022601a6ea8c008c034dd50031bad3002300d37540142940dc3a400429408c03c0048c038c03cc03cc03cc03cc03cc03cc03cc03c00488c8cc00400400c894ccc038004528099299980619b8f375c602200400829444cc00c00c004c0440048c030c03400452613656375c002a66600466e1d2000300337540022646464646464a666016601c0042930b1bae300c001300c002375c601400260140046eb4c020004c010dd50008b2b9a5573aaae7955cfaba05742ae89",hash:"5978a5118ecb36ad827390a21769bfa680ffc499d364bad913b4dffa"}],definitions:{ByteArray:{dataType:"bytes"},Int:{dataType:"integer"},"vesting/types/VestingDatum":{title:"VestingDatum",anyOf:[{title:"VestingDatum",dataType:"constructor",index:0,fields:[{title:"lock_until",description:"POSIX time in second, e.g. 1672843961000",$ref:"#/definitions/Int"},{title:"owner",description:"Owner's credentials",$ref:"#/definitions/ByteArray"},{title:"beneficiary",description:"Beneficiary's credentials",$ref:"#/definitions/ByteArray"}]}]}}};var o0=B,R=class extends m{scriptCbor=(0,z.applyParamsToScript)(B.validators[0].compiledCode,[]);constructor(e){super(e)}depositFund=async(e,t,c)=>{let{utxos:a,walletAddress:i}=await this.getWalletInfoForTx(),n=(0,T.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,0).address,{pubKeyHash:s}=(0,T.deserializeAddress)(i),{pubKeyHash:d}=(0,T.deserializeAddress)(c);return await this.mesh.txOut(n,e).txOutInlineDatumValue((0,k.mConStr0)([t,s,d])).changeAddress(i).selectUtxosFrom(a).complete(),this.mesh.txHex};withdrawFund=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),{input:i,output:n}=a,s=(0,T.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,0).address,{pubKeyHash:d}=(0,T.deserializeAddress)(c),l=(0,T.deserializeDatum)(e.output.plutusData),r=(0,k.unixTimeToEnclosingSlot)(Math.min(l.fields[0].int,Date.now()-15e3),this.networkId===0?k.SLOT_CONFIG_NETWORK.preprod:k.SLOT_CONFIG_NETWORK.mainnet)+1;return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,s).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(c,[]).txInCollateral(i.txHash,i.outputIndex,n.amount,n.address).invalidBefore(r).requiredSignerHash(d).changeAddress(c).selectUtxosFrom(t).complete(),this.mesh.txHex};getUtxoByTxHash=async e=>await this._getUtxoByTxHash(e,this.scriptCbor)};var p=require("@meshsdk/common"),u=require("@meshsdk/core"),J=require("@meshsdk/core-csl");var V={preamble:{title:"meshjs/escrow",description:"Aiken contracts for project 'meshjs/escrow'",version:"0.0.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.29-alpha+unknown"},license:"Apache-2.0"},validators:[{title:"escrow.escrow",datum:{title:"datum",schema:{$ref:"#/definitions/escrow~1types~1EscrowDatum"}},redeemer:{title:"redeemer",schema:{$ref:"#/definitions/escrow~1types~1EscrowRedeemer"}},compiledCode:"590c2f01000032323232323232232323232323232232322533300d323232323232323232323232323232533301c3019301d37540022646464646464a666044604060466ea80044c8c94ccc090c0880044c8c8c8c8c8c8c94ccc0b8c0c400c4c94ccc0bcc0c800c4c94ccc0b4c08cc0b8dd5000899192999817981298181baa0011325333030302e30313754006264646464a66606e6074004264646464a66607066ebc024cdd2a40046607800e660786e98014cc0f004ccc0f0dd300925eb804004528198111bab302830393754018660426eacc0a0c0e4dd51814181c9baa00d3020011302f0073302f00223233031375660720044646eb4c0ec008dd7181c8009bae3037001302f00316375660700026070004606c00260646ea800c58c0d0c0c4dd50008b180d98181baa0033032302f37540022c6032605c6ea8c074c0b8dd50010b18180010b18178011bac302e302f0023758605a002660566e9ccc058028014cc0acdd39980a804002a5eb80dd598159816001181500098131baa01b153330243021001132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd50008998098061bae3031302e37540022c60266060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc07c060dd7181e8010a51133003003001303d00115333035005100414a0294058c070014dd7181c181a9baa00116301a0063301c33017012002301a3756606c606e006660366602c02200860326eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa001163015302a3754603260546ea80045858c0b0008dd6181598160011bac302a00133028374e6602600e004660506e9ccc0480140092f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1981280f1bae304300213300300300114a060860022a66607600a200829405280b18110059bae303e303b37540022c604001a660446603a0300106040014660426603802e016603e00a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c602a60546ea8c064c0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc04c01c008cc0a0dd39980900280125eb80c090dd500d180918121baa301330243754604e60486ea800458c8c8cc004004018894ccc09c004530103d87a80001323253330263375e602c60506ea80080144c048cc0a80092f5c026600800800260560046052002604c60466ea8018dd618129813181318131813181318130011bac30240013024302400237586044002603c6ea8c030c078dd50080a50300c301d375401e44646600200200644a666042002297adef6c601332253330203375e602060446ea80080144cc028004dd5980898111baa0021001302300133002002302400122323300100100322533302000114a0264a66603c66e3cdd718118010020a511330030030013023001232533301a3018301b37540022600c6603c603e60386ea80052f5c02980103d87a80003009301b37540024646600200200444a66603a002297adef6c6013322323233330110030020012226323200232323300100100322533302400114984c94ccc09400454ccc088c010dd6981218138010a4c2c264646464a66604c66e40dd718138021bae30270031533302630080011330070073302a0030021616375a604e00660540066050004604e004604e002466603e603a002941289bab301f003375c603a004603e0026600400460400024464666002002006004444a66603c00420022646660080086044006666601e0046eb8c074004dd5980f00091119299981029998118008a5114a02980103d87a80001300c33024374c00297ae0323330010010030022225333025002100113233300400430290033322323300100100522533302a00113302b337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0accdc800400109981799bb037520106ea001c01454ccc0accdc78040010992999816181518169baa001133030337606ea4024c0c4c0b8dd5000802080219299981618150008a60103d87a80001301833030375000297ae03370000e00226605e66ec0dd48011ba800133006006003375a60580066eb8c0a8008c0b8008c0b0004dd718120009bad302500130270023020002223233001001323300100100322533301d00114bd7009919991119198008008019129998118008801899198129ba733025375200c6604a60440026604a604600297ae03300300330270023025001375c60380026eacc074004cc00c00cc084008c07c004894ccc070004528899299980d1919b89375a6010002664464a66603c6036603e6ea8004520001375a604660406ea8004c94ccc078c06cc07cdd50008a6103d87a8000132330010013756604860426ea8008894ccc08c004530103d87a80001323232325333024337220100042a66604866e3c0200084c040cc0a0dd4000a5eb80530103d87a8000133006006003375a604a0066eb8c08c008c09c008c094004c8cc004004024894ccc0880045300103d87a80001323232325333023337220100042a66604666e3c0200084c03ccc09cdd3000a5eb80530103d87a8000133006006003375660480066eb8c088008c098008c090004dd718058009bae300c0013758603e0042660060060022940c07c004dd2a40004603260346034002446600c004466ebcc014c05cdd50008011119802801119baf300430163754600a602c6ea80040088c0580048c054c05800488c8cc00400400c894ccc05400452f5c026464a666028600a004266030004660080080022660080080026032004602e0024444646600200200a44a66602c00226602e66ec0dd48029ba60044bd6f7b630099191919299980b99b9000900213301b337606ea4024dd30040028a99980b99b8f009002132533301830163019375400226603866ec0dd4805180e980d1baa001004100433300700900800113301b337606ea4008dd3000998030030019bab3018003375c602c0046034004603000229309b2b19299980618050008991919192999809980b0010991924c660160044646601a6eacc0540088c8dd6980b8011bae3015001375c602600260160062c6eacc050004c050008c048004c038dd50018a99980618048008a99980798071baa00314985854ccc030c00800454ccc03cc038dd50018a4c2c2c60186ea8008dc3a4008600200e464a666012600e002264646464a6660206026004264649319804001119198051bab3012002232375a60280046eb8c048004dd7180800098040018b1bab30110013011002300f001300b37540042a666012600c00226464646464646464a666028602e0042646464649319807002119198081bab3018002232375a60340046eb8c060004dd7180b000980700299806003119198071bab3016002232375a60300046eb8c058004dd7180a00098060038b1bab3015001301500230130013013002375660220026022004601e00260166ea800858c024dd50009119198008008019129998068008a4c2646600600660220046006601e0024a66600c6008600e6ea80044c8c8c8c94ccc034c0400084c8c92632533300c300a0011323253330113014002132498c94ccc03cc0340044c8c94ccc050c05c0084c926300d001163015001301137540042a66601e60180022646464646464a66603060360042930b1bad30190013019002375a602e002602e0046eb4c054004c044dd50010b18079baa001163012001300e37540062a66601860120022a66601e601c6ea800c5261616300c3754004600c0062c601c002601c004601800260106ea8004588c94ccc018c0100044c8c94ccc02cc03800852616375c601800260106ea800854ccc018c00c0044c8c94ccc02cc03800852616375c601800260106ea800858c018dd50009b8748008dc3a4000ae6955ceaab9e5573eae815d0aba201",hash:"bb0ead2a88fda451e0e5e01ff096309c06c1a6eb2206209d20243aaa"}],definitions:{ByteArray:{dataType:"bytes"},Int:{dataType:"integer"},List$Pair$ByteArray_Int:{dataType:"map",keys:{$ref:"#/definitions/ByteArray"},values:{$ref:"#/definitions/Int"}},List$Pair$ByteArray_List$Pair$ByteArray_Int:{dataType:"map",keys:{$ref:"#/definitions/ByteArray"},values:{$ref:"#/definitions/List$Pair$ByteArray_Int"}},"Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Optional",anyOf:[{title:"Some",description:"An optional value.",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]},{title:"None",description:"Nothing.",dataType:"constructor",index:1,fields:[]}]},"aiken/transaction/credential/Address":{title:"Address",description:`A Cardano \`Address\` typically holding one or two credential references.
47
+ // src/common.ts
48
+ var import_core_csl = require("@meshsdk/core-csl");
49
+ var MeshTxInitiator = class {
50
+ mesh;
51
+ fetcher;
52
+ wallet;
53
+ stakeCredential;
54
+ networkId = 0;
55
+ constructor({
56
+ mesh,
57
+ fetcher,
58
+ wallet,
59
+ networkId,
60
+ stakeCredential
61
+ }) {
62
+ this.mesh = mesh;
63
+ if (fetcher) {
64
+ this.fetcher = fetcher;
65
+ }
66
+ if (wallet) {
67
+ this.wallet = wallet;
68
+ }
69
+ if (networkId) {
70
+ this.networkId = networkId;
71
+ }
72
+ if (stakeCredential) {
73
+ this.stakeCredential = this.stakeCredential;
74
+ }
75
+ }
76
+ signSubmitReset = async () => {
77
+ const signedTx = this.mesh.completeSigning();
78
+ const txHash = await this.mesh.submitTx(signedTx);
79
+ this.mesh.reset();
80
+ return txHash;
81
+ };
82
+ queryUtxos = async (walletAddress) => {
83
+ if (this.fetcher) {
84
+ const utxos = await this.fetcher.fetchAddressUTxOs(walletAddress);
85
+ return utxos;
86
+ }
87
+ return [];
88
+ };
89
+ getWalletDappAddress = async () => {
90
+ if (this.wallet) {
91
+ const usedAddresses = await this.wallet.getUsedAddresses();
92
+ if (usedAddresses.length > 0) {
93
+ return usedAddresses[0];
94
+ }
95
+ const unusedAddresses = await this.wallet.getUnusedAddresses();
96
+ if (unusedAddresses.length > 0) {
97
+ return unusedAddresses[0];
98
+ }
99
+ }
100
+ return "";
101
+ };
102
+ getWalletCollateral = async () => {
103
+ if (this.wallet) {
104
+ const utxos = await this.wallet.getCollateral();
105
+ return utxos[0];
106
+ }
107
+ return void 0;
108
+ };
109
+ getWalletUtxosWithMinLovelace = async (lovelace, providedUtxos = []) => {
110
+ let utxos = providedUtxos;
111
+ if (this.wallet && (!providedUtxos || providedUtxos.length === 0)) {
112
+ utxos = await this.wallet.getUtxos();
113
+ }
114
+ return utxos.filter((u) => {
115
+ const lovelaceAmount = u.output.amount.find(
116
+ (a) => a.unit === "lovelace"
117
+ )?.quantity;
118
+ return Number(lovelaceAmount) > lovelace;
119
+ });
120
+ };
121
+ getWalletUtxosWithToken = async (assetHex, userUtxos = []) => {
122
+ let utxos = userUtxos;
123
+ if (this.wallet && userUtxos.length === 0) {
124
+ utxos = await this.wallet.getUtxos();
125
+ }
126
+ return utxos.filter((u) => {
127
+ const assetAmount = u.output.amount.find(
128
+ (a) => a.unit === assetHex
129
+ )?.quantity;
130
+ return Number(assetAmount) >= 1;
131
+ });
132
+ };
133
+ getAddressUtxosWithMinLovelace = async (walletAddress, lovelace, providedUtxos = []) => {
134
+ let utxos = providedUtxos;
135
+ if (this.fetcher && (!providedUtxos || providedUtxos.length === 0)) {
136
+ utxos = await this.fetcher.fetchAddressUTxOs(walletAddress);
137
+ }
138
+ return utxos.filter((u) => {
139
+ const lovelaceAmount = u.output.amount.find(
140
+ (a) => a.unit === "lovelace"
141
+ )?.quantity;
142
+ return Number(lovelaceAmount) > lovelace;
143
+ });
144
+ };
145
+ getAddressUtxosWithToken = async (walletAddress, assetHex, userUtxos = []) => {
146
+ let utxos = userUtxos;
147
+ if (this.fetcher && userUtxos.length === 0) {
148
+ utxos = await this.fetcher.fetchAddressUTxOs(walletAddress);
149
+ }
150
+ return utxos.filter((u) => {
151
+ const assetAmount = u.output.amount.find(
152
+ (a) => a.unit === assetHex
153
+ )?.quantity;
154
+ return Number(assetAmount) >= 1;
155
+ });
156
+ };
157
+ getWalletInfoForTx = async () => {
158
+ const utxos = await this.wallet?.getUtxos();
159
+ const collateral = await this.getWalletCollateral();
160
+ const walletAddress = await this.getWalletDappAddress();
161
+ if (!utxos || utxos?.length === 0) {
162
+ throw new Error("No utxos found");
163
+ }
164
+ if (!collateral) {
165
+ throw new Error("No collateral found");
166
+ }
167
+ if (!walletAddress) {
168
+ throw new Error("No wallet address found");
169
+ }
170
+ return { utxos, collateral, walletAddress };
171
+ };
172
+ _getUtxoByTxHash = async (txHash, scriptCbor) => {
173
+ if (this.fetcher) {
174
+ const utxos = await this.fetcher?.fetchUTxOs(txHash);
175
+ let scriptUtxo = utxos[0];
176
+ if (scriptCbor) {
177
+ const scriptAddr = (0, import_core_csl.v2ScriptToBech32)(
178
+ scriptCbor,
179
+ void 0,
180
+ this.networkId
181
+ );
182
+ scriptUtxo = utxos.filter((utxo) => utxo.output.address === scriptAddr)[0] || utxos[0];
183
+ }
184
+ return scriptUtxo;
185
+ }
186
+ return void 0;
187
+ };
188
+ };
14
189
 
15
- Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are
16
- completely excluded from Plutus contexts. Thus, from an on-chain
17
- perspective only exists addresses of type 00, 01, ..., 07 as detailed
18
- in [CIP-0019 :: Shelley Addresses](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019/#shelley-addresses).`,anyOf:[{title:"Address",dataType:"constructor",index:0,fields:[{title:"payment_credential",$ref:"#/definitions/aiken~1transaction~1credential~1Credential"},{title:"stake_credential",$ref:"#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]}]},"aiken/transaction/credential/Credential":{title:"Credential",description:`A general structure for representing an on-chain \`Credential\`.
190
+ // src/marketplace/aiken-workspace/plutus.json
191
+ var plutus_default = {
192
+ preamble: {
193
+ title: "meshjs/marketplace",
194
+ description: "Aiken contracts for project 'meshjs/marketplace'",
195
+ version: "0.0.0",
196
+ plutusVersion: "v2",
197
+ compiler: {
198
+ name: "Aiken",
199
+ version: "v1.0.29-alpha+unknown"
200
+ },
201
+ license: "Apache-2.0"
202
+ },
203
+ validators: [
204
+ {
205
+ title: "marketplace.marketplace",
206
+ datum: {
207
+ title: "datum",
208
+ schema: {
209
+ $ref: "#/definitions/marketplace~1types~1MarketplaceDatum"
210
+ }
211
+ },
212
+ redeemer: {
213
+ title: "redeemer",
214
+ schema: {
215
+ $ref: "#/definitions/marketplace~1types~1MarketplaceRedeemer"
216
+ }
217
+ },
218
+ parameters: [
219
+ {
220
+ title: "owner",
221
+ schema: {
222
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
223
+ }
224
+ },
225
+ {
226
+ title: "fee_percentage_basis_point",
227
+ schema: {
228
+ $ref: "#/definitions/Int"
229
+ }
230
+ }
231
+ ],
232
+ compiledCode: "59082f01000032323232323232223223232322322533300b3232533300d3007300e375400226464a64666020601660226ea80204c94ccc044c030c048dd500089919191919191919299980c99299980e8008a501533301d302000114a22940cc88c8cc00400400c894ccc08000452f5c026464a66603e66ebcc044c084dd5180a18109baa00200513302300233004004001133004004001302400230220013758601660366ea8c02cc06cdd50079805980d9baa300e301b37540102a6660320022004294052819801998011bac3004301a3754601460346ea803805cc018cdc199b82375a601a60346ea805005520a09c0133002330013758600660326ea8c024c064dd50069804980c9baa0133005337006eb4c030c064dd50099998021bab300c30193754601860326ea801922010048810022323300100100322533301d00114bd6f7b63009991299980e19baf300e301e375400400a2646660020020046eacc048c07cdd50019112999811001080089919980200218130019991191980080080291299981380089981419bb037520086e9800d2f5bded8c0264646464a66605066e400200084cc0b0cdd81ba9008374c00e00a2a66605066e3c0200084c94ccc0a4c090c0a8dd500089981699bb03752012605c60566ea80040104010c94ccc0a54ccc0b00045288a5014c0103d87a80001301a3302d374c00297ae032333001001008002222533302e0021001132333004004303200333223233001001005225333033001133034337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0d0cdc800400109981c19bb037520106ea001c01454ccc0d0cdc7804001099299981a9818181b1baa001133039337606ea4024c0e8c0dcdd5000802080219299981a98180008a60103d87a80001302633039375000297ae03370000e00226607066ec0dd48011ba800133006006003375a606a0066eb8c0cc008c0dc008c0d4004dd718168009bad302e001303000213302c337606ea4008dd3000998030030019bab3029003375c604e004605600460520026eb8c084004dd5981100098120010800980f800998010011810000911919800800991980080080191299980e8008a5eb804c8ccc888c8cc00400400c894ccc08c004400c4c8cc094dd3998129ba90063302530220013302530230014bd7019801801981380118128009bae301c0013756603a002660060066042004603e00244a66603800229444c94ccc068c8cdc49bad3007001333008006375c601a0026eb8c040004dd6180f8010998018018008a50301f0012301a301b301b0012223253330173011301837540022900009bad301c3019375400264a66602e602260306ea8004530103d87a8000132330010013756603a60346ea8008894ccc070004530103d87a8000132323232533301d337220100042a66603a66e3c0200084c038cc084dd4000a5eb80530103d87a8000133006006003375a603c0066eb8c070008c080008c078004c8cc004004010894ccc06c0045300103d87a8000132323232533301c337220100042a66603866e3c0200084c034cc080dd3000a5eb80530103d87a80001330060060033756603a0066eb8c06c008c07c008c07400494ccc04cc03800452f5bded8c0264646600200297adef6c6022533301900113301a337609801014000374c00697adef6c60132323232533301a3372091010000213301e337609801014000374c00e00a2a66603466e3d2210000213301e337609801014000374c00e00626603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc0040052f5bded8c044a66603000226603266ec13001014000375000697adef6c6013232323253330193372091010000213301d337609801014000375000e00a2a66603266e3d2210000213301d337609801014000375000e00626603a66ec0dd48011ba800133006006003375a60340066eb8c060008c070008c068004c058c04cdd50008b19198008009bac300330133754600660266ea801c894ccc054004530103d87a80001323253330143375e600c602c6ea800801c4c014cc0600092f5c02660080080026032004602e002264a666022601860246ea80044cc88c8cc00400400c894ccc060004528099299980b19b8f375c603600400829444cc00c00c004c06c004dd6180b180b980b980b980b980b980b980b980b98099baa30033013375400e6eb8c058c04cdd50008b192999808980618091baa001130023301530163013375400297ae014c0103d87a8000300230123754600460246ea8030dd2a4000460280026024601e6ea8004528180098071baa00223011301200114984d958c94ccc028c01400454ccc034c030dd50010a4c2c2a66601460080022a66601a60186ea80085261616300a375400264a666010600660126ea80104c8c8c8c8c8c8c8c94ccc04cc0580084c9265333010300b3011375400e264646464a66602e6034004264649319299980b180880089919299980d980f00109924c64a666032602800226464a66603c604200426493180a0008b180f800980d9baa002153330193013001132323232323253330223025002149858dd6981180098118011bad30210013021002375a603e00260366ea800858c064dd50008b180e000980c1baa00315333016301000115333019301837540062930b0b180b1baa002300d003163018001301800230160013012375400e2c2c6eb8c050004c050008dd7180900098090011bad30100013010002300e001300a37540082c464a666012600800226464a66601c60220042930b1bae300f001300b37540042a666012600600226464a66601c60220042930b1bae300f001300b37540042c60126ea8004dc3a40046e1d2000375a002ae6955ceaab9e5573eae815d0aba21",
233
+ hash: "96dbc09c69d812e157d42967587c459b60f5dd21b1902312045586c4"
234
+ }
235
+ ],
236
+ definitions: {
237
+ ByteArray: {
238
+ dataType: "bytes"
239
+ },
240
+ Int: {
241
+ dataType: "integer"
242
+ },
243
+ "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
244
+ title: "Optional",
245
+ anyOf: [
246
+ {
247
+ title: "Some",
248
+ description: "An optional value.",
249
+ dataType: "constructor",
250
+ index: 0,
251
+ fields: [
252
+ {
253
+ $ref: "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
254
+ }
255
+ ]
256
+ },
257
+ {
258
+ title: "None",
259
+ description: "Nothing.",
260
+ dataType: "constructor",
261
+ index: 1,
262
+ fields: []
263
+ }
264
+ ]
265
+ },
266
+ "aiken/transaction/credential/Address": {
267
+ title: "Address",
268
+ 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).",
269
+ anyOf: [
270
+ {
271
+ title: "Address",
272
+ dataType: "constructor",
273
+ index: 0,
274
+ fields: [
275
+ {
276
+ title: "payment_credential",
277
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
278
+ },
279
+ {
280
+ title: "stake_credential",
281
+ $ref: "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
282
+ }
283
+ ]
284
+ }
285
+ ]
286
+ },
287
+ "aiken/transaction/credential/Credential": {
288
+ title: "Credential",
289
+ 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).",
290
+ anyOf: [
291
+ {
292
+ title: "VerificationKeyCredential",
293
+ dataType: "constructor",
294
+ index: 0,
295
+ fields: [
296
+ {
297
+ $ref: "#/definitions/ByteArray"
298
+ }
299
+ ]
300
+ },
301
+ {
302
+ title: "ScriptCredential",
303
+ dataType: "constructor",
304
+ index: 1,
305
+ fields: [
306
+ {
307
+ $ref: "#/definitions/ByteArray"
308
+ }
309
+ ]
310
+ }
311
+ ]
312
+ },
313
+ "aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
314
+ title: "Referenced",
315
+ 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.",
316
+ anyOf: [
317
+ {
318
+ title: "Inline",
319
+ dataType: "constructor",
320
+ index: 0,
321
+ fields: [
322
+ {
323
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
324
+ }
325
+ ]
326
+ },
327
+ {
328
+ title: "Pointer",
329
+ dataType: "constructor",
330
+ index: 1,
331
+ fields: [
332
+ {
333
+ title: "slot_number",
334
+ $ref: "#/definitions/Int"
335
+ },
336
+ {
337
+ title: "transaction_index",
338
+ $ref: "#/definitions/Int"
339
+ },
340
+ {
341
+ title: "certificate_index",
342
+ $ref: "#/definitions/Int"
343
+ }
344
+ ]
345
+ }
346
+ ]
347
+ },
348
+ "marketplace/types/MarketplaceDatum": {
349
+ title: "MarketplaceDatum",
350
+ anyOf: [
351
+ {
352
+ title: "MarketplaceDatum",
353
+ dataType: "constructor",
354
+ index: 0,
355
+ fields: [
356
+ {
357
+ title: "seller",
358
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
359
+ },
360
+ {
361
+ title: "price",
362
+ $ref: "#/definitions/Int"
363
+ },
364
+ {
365
+ title: "policy",
366
+ $ref: "#/definitions/ByteArray"
367
+ },
368
+ {
369
+ title: "tokenName",
370
+ $ref: "#/definitions/ByteArray"
371
+ }
372
+ ]
373
+ }
374
+ ]
375
+ },
376
+ "marketplace/types/MarketplaceRedeemer": {
377
+ title: "MarketplaceRedeemer",
378
+ anyOf: [
379
+ {
380
+ title: "Buy",
381
+ dataType: "constructor",
382
+ index: 0,
383
+ fields: []
384
+ },
385
+ {
386
+ title: "Close",
387
+ dataType: "constructor",
388
+ index: 1,
389
+ fields: []
390
+ }
391
+ ]
392
+ }
393
+ }
394
+ };
19
395
 
20
- Credentials are always one of two kinds: a direct public/private key
21
- pair, or a script (native or Plutus).`,anyOf:[{title:"VerificationKeyCredential",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/ByteArray"}]},{title:"ScriptCredential",dataType:"constructor",index:1,fields:[{$ref:"#/definitions/ByteArray"}]}]},"aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Referenced",description:`Represent a type of object that can be represented either inline (by hash)
22
- or via a reference (i.e. a pointer to an on-chain location).
396
+ // src/marketplace/offchain.ts
397
+ var MeshMarketplaceBlueprint = plutus_default;
398
+ var marketplaceDatum = (sellerAddress, lovelaceFee, assetHex) => {
399
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(sellerAddress);
400
+ const { policyId, assetName } = (0, import_common.parseAssetUnit)(assetHex);
401
+ return (0, import_common.conStr0)([
402
+ (0, import_common.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
403
+ (0, import_common.integer)(lovelaceFee),
404
+ (0, import_common.currencySymbol)(policyId),
405
+ (0, import_common.tokenName)(assetName)
406
+ ]);
407
+ };
408
+ var MeshMarketplaceContract = class extends MeshTxInitiator {
409
+ ownerAddress;
410
+ feePercentageBasisPoint;
411
+ scriptCbor;
412
+ constructor(inputs, ownerAddress, feePercentageBasisPoint) {
413
+ super(inputs);
414
+ this.ownerAddress = ownerAddress;
415
+ this.feePercentageBasisPoint = feePercentageBasisPoint;
416
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core.deserializeAddress)(ownerAddress);
417
+ this.scriptCbor = (0, import_core_csl2.applyParamsToScript)(
418
+ plutus_default.validators[0].compiledCode,
419
+ [
420
+ (0, import_common.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
421
+ (0, import_common.integer)(feePercentageBasisPoint)
422
+ ],
423
+ "JSON"
424
+ );
425
+ }
426
+ listAsset = async (asset, price) => {
427
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
428
+ const assetMap = /* @__PURE__ */ new Map();
429
+ assetMap.set(asset, "1");
430
+ const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
431
+ { code: this.scriptCbor, version: "V2" },
432
+ void 0,
433
+ this.networkId
434
+ );
435
+ const tokenForSale = [{ unit: asset, quantity: "1" }];
436
+ const outputDatum = marketplaceDatum(walletAddress, price, asset);
437
+ await this.mesh.txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
438
+ return this.mesh.txHex;
439
+ };
440
+ delistAsset = async (marketplaceUtxo) => {
441
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
442
+ await this.mesh.spendingPlutusScriptV2().txIn(
443
+ marketplaceUtxo.input.txHash,
444
+ marketplaceUtxo.input.outputIndex,
445
+ marketplaceUtxo.output.amount,
446
+ marketplaceUtxo.output.address
447
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr1)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).requiredSignerHash((0, import_core.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
448
+ collateral.input.txHash,
449
+ collateral.input.outputIndex,
450
+ collateral.output.amount,
451
+ collateral.output.address
452
+ ).selectUtxosFrom(utxos).complete();
453
+ return this.mesh.txHex;
454
+ };
455
+ purchaseAsset = async (marketplaceUtxo) => {
456
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
457
+ const inputDatum = (0, import_core.deserializeDatum)(
458
+ marketplaceUtxo.output.plutusData
459
+ );
460
+ const inputLovelace = marketplaceUtxo.output.amount.find(
461
+ (a) => a.unit === "lovelace"
462
+ ).quantity;
463
+ const tx = this.mesh.spendingPlutusScriptV2().txIn(
464
+ marketplaceUtxo.input.txHash,
465
+ marketplaceUtxo.input.outputIndex,
466
+ marketplaceUtxo.output.amount,
467
+ marketplaceUtxo.output.address
468
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
469
+ collateral.input.txHash,
470
+ collateral.input.outputIndex,
471
+ collateral.output.amount,
472
+ collateral.output.address
473
+ ).selectUtxosFrom(utxos);
474
+ let ownerToReceiveLovelace = inputDatum.fields[1].int * this.feePercentageBasisPoint / 1e4;
475
+ if (this.feePercentageBasisPoint > 0 && ownerToReceiveLovelace < 1e6) {
476
+ ownerToReceiveLovelace = 1e6;
477
+ }
478
+ if (ownerToReceiveLovelace > 0) {
479
+ const ownerAddress = this.ownerAddress;
480
+ const ownerToReceive = [
481
+ {
482
+ unit: "lovelace",
483
+ quantity: Math.ceil(ownerToReceiveLovelace).toString()
484
+ }
485
+ ];
486
+ tx.txOut(ownerAddress, ownerToReceive);
487
+ }
488
+ const sellerToReceiveLovelace = inputDatum.fields[1].int + Number(inputLovelace);
489
+ if (sellerToReceiveLovelace > 0) {
490
+ const sellerAddress = (0, import_core.serializeAddressObj)(inputDatum.fields[0]);
491
+ const sellerToReceive = [
492
+ {
493
+ unit: "lovelace",
494
+ quantity: sellerToReceiveLovelace.toString()
495
+ }
496
+ ];
497
+ tx.txOut(sellerAddress, sellerToReceive);
498
+ }
499
+ await tx.complete();
500
+ return this.mesh.txHex;
501
+ };
502
+ relistAsset = async (marketplaceUtxo, newPrice) => {
503
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
504
+ const inputAsset = marketplaceUtxo.output.amount.find(
505
+ (a) => a.unit !== "lovelace"
506
+ ).unit;
507
+ const tokenForSale = [{ unit: inputAsset, quantity: "1" }];
508
+ const outputDatum = marketplaceDatum(walletAddress, newPrice, inputAsset);
509
+ const { address: scriptAddr } = (0, import_core.serializePlutusScript)(
510
+ { code: this.scriptCbor, version: "V2" },
511
+ void 0,
512
+ this.networkId
513
+ );
514
+ await this.mesh.spendingPlutusScriptV2().txIn(
515
+ marketplaceUtxo.input.txHash,
516
+ marketplaceUtxo.input.outputIndex,
517
+ marketplaceUtxo.output.amount,
518
+ marketplaceUtxo.output.address
519
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common.mConStr1)([])).txInScript(this.scriptCbor).txOut(scriptAddr, tokenForSale).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).requiredSignerHash((0, import_core.deserializeAddress)(walletAddress).pubKeyHash).txInCollateral(
520
+ collateral.input.txHash,
521
+ collateral.input.outputIndex,
522
+ collateral.output.amount,
523
+ collateral.output.address
524
+ ).selectUtxosFrom(utxos).complete();
525
+ return this.mesh.txHex;
526
+ };
527
+ getUtxoByTxHash = async (txHash) => {
528
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
529
+ };
530
+ };
23
531
 
24
- This is mainly use for capturing pointers to a stake credential
25
- registration certificate in the case of so-called pointer addresses.`,anyOf:[{title:"Inline",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Credential"}]},{title:"Pointer",dataType:"constructor",index:1,fields:[{title:"slot_number",$ref:"#/definitions/Int"},{title:"transaction_index",$ref:"#/definitions/Int"},{title:"certificate_index",$ref:"#/definitions/Int"}]}]},"escrow/types/EscrowDatum":{title:"EscrowDatum",anyOf:[{title:"Initiation",dataType:"constructor",index:0,fields:[{title:"initiator",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"initiator_assets",$ref:"#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"}]},{title:"ActiveEscrow",dataType:"constructor",index:1,fields:[{title:"initiator",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"initiator_assets",$ref:"#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"},{title:"recipient",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"recipient_assets",$ref:"#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"}]}]},"escrow/types/EscrowRedeemer":{title:"EscrowRedeemer",anyOf:[{title:"RecipientDeposit",dataType:"constructor",index:0,fields:[{title:"recipient",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"recipient_assets",$ref:"#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"}]},{title:"CancelTrade",dataType:"constructor",index:1,fields:[]},{title:"CompleteTrade",dataType:"constructor",index:2,fields:[]}]}}};var u0=V,M=(o,e)=>{let{pubKeyHash:t,stakeCredentialHash:c}=(0,u.deserializeAddress)(o);return(0,p.conStr0)([(0,p.pubKeyAddress)(t,c),(0,p.value)(e)])},G=(o,e,t)=>{let{pubKeyHash:c,stakeCredentialHash:a}=(0,u.deserializeAddress)(e),[i,n]=o.fields;return(0,p.conStr1)([i,n,(0,p.pubKeyAddress)(c,a),(0,p.value)(t)])},Q=(o,e)=>M(o,e),_=class extends m{scriptCbor=(0,J.applyParamsToScript)(V.validators[0].compiledCode,[]);constructor(e){super(e)}initiateEscrow=async e=>{let{utxos:t,walletAddress:c}=await this.getWalletInfoForTx(),{address:a}=(0,u.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId);return await this.mesh.txOut(a,e).txOutInlineDatumValue(M(c,e),"JSON").changeAddress(c).selectUtxosFrom(t).complete(),this.mesh.txHex};cancelEscrow=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),{address:i}=(0,u.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId),n=(0,u.deserializeDatum)(e.output.plutusData);if(n.constructor===1){let[s,d,l,r]=n.fields,b=(0,u.serializeAddressObj)(s),g=(0,u.serializeAddressObj)(l),w=p.MeshValue.fromValue(d).toAssets(),S=p.MeshValue.fromValue(r).toAssets();this.mesh.txOut(b,w).txOut(g,S)}return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,i).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,p.mConStr1)([])).txInScript(this.scriptCbor).requiredSignerHash((0,u.deserializeAddress)(c).pubKeyHash).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t).complete(),this.mesh.txHex};recipientDeposit=async(e,t)=>{let{utxos:c,walletAddress:a,collateral:i}=await this.getWalletInfoForTx(),{address:n}=(0,u.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId),s=(0,u.deserializeDatum)(e.output.plutusData),d=G(s,a,t),l=p.MeshValue.fromValue(s.fields[1]).toAssets(),r=(0,u.mergeAssets)([...t,...l]);return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,n).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(Q(a,t),"JSON",{mem:7e6,steps:3e9}).txInScript(this.scriptCbor).txOut(n,r).txOutInlineDatumValue(d,"JSON").changeAddress(a).txInCollateral(i.input.txHash,i.input.outputIndex,i.output.amount,i.output.address).selectUtxosFrom(c).complete(),this.mesh.txHex};completeEscrow=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),{address:i}=(0,u.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,this.networkId),n=(0,u.deserializeDatum)(e.output.plutusData),[s,d,l,r]=n.fields,b=(0,u.serializeAddressObj)(s),g=(0,u.serializeAddressObj)(l),w=p.MeshValue.fromValue(r).toAssets(),S=p.MeshValue.fromValue(d).toAssets();return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,i).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,p.mConStr2)([])).txInScript(this.scriptCbor).txOut(b,w).txOut(g,S).requiredSignerHash((0,u.deserializeAddress)(g).pubKeyHash).requiredSignerHash((0,u.deserializeAddress)(b).pubKeyHash).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t).complete(),this.mesh.txHex};getUtxoByTxHash=async e=>await this._getUtxoByTxHash(e,this.scriptCbor)};var I=require("@meshsdk/common"),C=require("@meshsdk/core"),N=require("@meshsdk/core-csl");var v={preamble:{title:"meshjs/giftcard",description:"Aiken contracts for project 'meshjs/giftcard'",version:"0.0.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.29-alpha+unknown"},license:"Apache-2.0"},validators:[{title:"oneshot.gift_card",redeemer:{title:"rdmr",schema:{$ref:"#/definitions/oneshot~1Action"}},parameters:[{title:"token_name",schema:{$ref:"#/definitions/ByteArray"}},{title:"utxo_ref",schema:{$ref:"#/definitions/aiken~1transaction~1OutputReference"}}],compiledCode:"5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",hash:"0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"},{title:"oneshot.redeem",datum:{title:"_d",schema:{$ref:"#/definitions/Data"}},redeemer:{title:"_r",schema:{$ref:"#/definitions/Data"}},parameters:[{title:"token_name",schema:{$ref:"#/definitions/ByteArray"}},{title:"policy_id",schema:{$ref:"#/definitions/ByteArray"}}],compiledCode:"5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",hash:"39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"}],definitions:{ByteArray:{dataType:"bytes"},Data:{title:"Data",description:"Any Plutus data."},Int:{dataType:"integer"},"aiken/transaction/OutputReference":{title:"OutputReference",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",anyOf:[{title:"OutputReference",dataType:"constructor",index:0,fields:[{title:"transaction_id",$ref:"#/definitions/aiken~1transaction~1TransactionId"},{title:"output_index",$ref:"#/definitions/Int"}]}]},"aiken/transaction/TransactionId":{title:"TransactionId",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.",anyOf:[{title:"TransactionId",dataType:"constructor",index:0,fields:[{title:"hash",$ref:"#/definitions/ByteArray"}]}]},"oneshot/Action":{title:"Action",anyOf:[{title:"Mint",dataType:"constructor",index:0,fields:[]},{title:"Burn",dataType:"constructor",index:1,fields:[]}]}}};var f0=v,U=class extends m{tokenNameHex="";paramUtxo={outputIndex:0,txHash:""};giftCardCbor=(e,t,c)=>(0,N.applyParamsToScript)(v.validators[0].compiledCode,[(0,I.builtinByteString)(e),(0,I.txOutRef)(t,c)],"JSON");redeemCbor=(e,t)=>(0,N.applyParamsToScript)(v.validators[1].compiledCode,[e,t]);constructor(e,t,c){super(e),t&&(this.tokenNameHex=t),c&&(this.paramUtxo=c)}createGiftCard=async(e,t)=>{let{utxos:c,walletAddress:a,collateral:i}=await this.getWalletInfoForTx(),n=(0,I.stringToHex)(e),s=c[0];if(s===void 0)throw new Error("No UTXOs available");let d=c.slice(1),l=this.giftCardCbor(n,s.input.txHash,s.input.outputIndex),r=(0,C.resolveScriptHash)(l,"V2"),b={code:this.redeemCbor(n,r),version:"V2"},g=(0,C.serializePlutusScript)(b,void 0,this.networkId).address;return await this.mesh.txIn(s.input.txHash,s.input.outputIndex,s.output.amount,s.output.address).mintPlutusScriptV2().mint("1",r,n).mintingScript(l).mintRedeemerValue((0,I.mConStr0)([])).txOut(g,[...t,{unit:r+n,quantity:"1"}]).txOutInlineDatumValue([s.input.txHash,s.input.outputIndex,n]).changeAddress(a).txInCollateral(i.input.txHash,i.input.outputIndex,i.output.amount,i.output.address).selectUtxosFrom(d).complete(),this.tokenNameHex=n,this.paramUtxo=s.input,this.mesh.txHex};redeemGiftCard=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),i=(0,C.deserializeDatum)(e.output.plutusData).list,n=i[0].bytes,s=i[1].int,d=i[2].bytes,l=this.giftCardCbor(d,n,s),r=(0,C.resolveScriptHash)(l,"V2"),b=this.redeemCbor(d,r);return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(b).mintPlutusScriptV2().mint("-1",r,d).mintingScript(l).mintRedeemerValue((0,I.mConStr1)([])).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t).complete(),this.mesh.txHex};getUtxoByTxHash=async e=>await this._getUtxoByTxHash(e);getScripts=()=>{let e=this.giftCardCbor(this.tokenNameHex,this.paramUtxo.txHash,this.paramUtxo.outputIndex),t=(0,C.resolveScriptHash)(e,"V2"),c=this.redeemCbor(this.tokenNameHex,t);return{giftCardScript:e,redeemScript:c}}};var $=require("@meshsdk/common"),h=require("@meshsdk/core"),X=require("@meshsdk/core-csl");var F={preamble:{title:"fabianbormann/payment-splitter",description:"Aiken contracts for project 'fabianbormann/payment-splitter'",version:"0.1.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.29-alpha+unknown"},license:"Apache-2.0"},validators:[{title:"payment_splitter.payout",datum:{title:"_datum",schema:{$ref:"#/definitions/payment_splitter~1Datum"}},redeemer:{title:"_redeemer",schema:{$ref:"#/definitions/payment_splitter~1Redeemer"}},parameters:[{title:"scriptHashes",schema:{$ref:"#/definitions/List$ByteArray"}}],compiledCode:"5903a5010000323232323232322322322322533300832323232323232323232323253330143375e6e9cccc8c0040048894ccc06800440084ccc00c00cc8c8cc004004010894ccc07400452f5c026464a66603866ebc00801440044cc080008cc010010004c084008c07c004c070004c074004cc8c004004894ccc06400452f5c026466036002660060066600e603a004466603066ebc00400928251301b001323300100100722533301900114bd7009980d1806180c1baa300c3018375460360026600400460380020169801018000100114a0646600200200444a66603000229444c94ccc058cdc39bad301b00233005533301900414c0103d87a80001300e3301a301b0044bd70240002660060060022940c06c004c8cc004004028894ccc05c00452f5c02660306ea0c8c8c8c8c8c94ccc068cdc424000002266e04008cdc08009802005880119980119804806919baf3010301c3754602060386ea8c014c070dd5000803240004466e00004c014dd59803180e9baa3006301d375400466600266010014466ebcc03cc06cdd51807980d9baa0010054800088cdc000098021bab3005301c3754004444646600200200844a66603e0022008266006604200266004004604400246600c64a66603066e1d200230193754002298103d87a8000132330010013756603c60366ea8008894ccc074004530103d87a8000132323232533301e33722911000021533301e3371e9101000021301633022375000297ae014c0103d87a8000133006006003375a603e0066eb8c074008c084008c07c004c8cc004004008894ccc0700045300103d87a8000132323232533301d33722911000021533301d3371e9101000021301533021374c00297ae014c0103d87a80001330060060033756603c0066eb8c070008c080008c07800520002301b301c001301900133002002301a0012253330133370e9001180a1baa00210011375a6030602a6ea800888c8cc00400400c894ccc05c00452f5c026464a66602c600a00426603400466008008002266008008002603600460320026eacc050c054008dd61809800980998098011bac3011001300d37546002601a6ea80108c040004c8cc004004020894ccc03800452f5c026601e60066601e602000297ae0330020023011001374a90000a4c26caca66600c66e1d20003007375400226464a666016601c0042930b1bae300c001300837540022ca66600866e1d20003005375400226464a66601260180042930b1bae300a001300637540022c6eb00055cd2ab9d5573caae7d5d02ba157441",hash:"0776032753d2900f7c1e933af4108c53851e10ca95fa10e34af90277"}],definitions:{ByteArray:{dataType:"bytes"},List$ByteArray:{dataType:"list",items:{$ref:"#/definitions/ByteArray"}},"payment_splitter/Datum":{title:"Datum",anyOf:[{title:"Datum",dataType:"constructor",index:0,fields:[{title:"owner",$ref:"#/definitions/ByteArray"}]}]},"payment_splitter/Redeemer":{title:"Redeemer",anyOf:[{title:"Redeemer",dataType:"constructor",index:0,fields:[{title:"message",$ref:"#/definitions/ByteArray"}]}]}}};var m0=F,W=class extends m{wrapPayees=e=>(0,$.list)(e.map(t=>(0,$.builtinByteString)((0,h.deserializeAddress)(t).pubKeyHash)));scriptCbor=()=>(0,X.applyParamsToScript)(F.validators[0].compiledCode,[this.wrapPayees(this.payees)],"JSON");payees=[];constructor(e,t){super(e),e.wallet?(e.wallet instanceof h.MeshWallet&&(this.payees=[e.wallet.getUsedAddresses()[0],...t]),e.wallet instanceof h.BrowserWallet&&e.wallet.getUsedAddresses().then(c=>{this.payees=[c[0],...t]})):(this.payees=t,console.warn("Wallet not provided. Therefore the payment address will not be added to the payees list which makes it impossible to trigger the payout."))}sendLovelaceToSplitter=async e=>{if(this.wallet===null||this.wallet===void 0)throw new Error("Wallet not provided");let{walletAddress:t}=await this.getWalletInfoForTx(),c={code:this.scriptCbor(),version:"V2"},{address:a}=(0,h.serializePlutusScript)(c,void 0,0),{pubKeyHash:i}=(0,h.deserializeAddress)(t),n={alternative:0,fields:[i]};return await new h.Transaction({initiator:this.wallet}).sendLovelace({address:a,datum:{value:n}},e.toString()).build()};triggerPayout=async()=>{if(this.wallet===null||this.wallet===void 0)throw new Error("Wallet not provided");let{walletAddress:e,collateral:t}=await this.getWalletInfoForTx(),c={code:this.scriptCbor(),version:"V2"},{address:a}=(0,h.serializePlutusScript)(c,void 0,0),i=await this.fetcher?.fetchAddressUTxOs(a)||[],{pubKeyHash:n}=(0,h.deserializeAddress)(e),s={alternative:0,fields:[n]},l={data:{alternative:0,fields:["Hello, World!"]}},r=new h.Transaction({initiator:this.wallet}),b=0;for(let w of i){let S=w.output?.amount;if(S){let q=S.find(Z=>Z.unit==="lovelace");q&&(b+=Math.floor(Number(q.quantity)/this.payees.length)),r=r.redeemValue({value:w,script:c,datum:s,redeemer:l})}}r=r.setCollateral([t]);for(let w of this.payees)r=r.sendLovelace(w,b.toString());return r=r.setRequiredSigners([e]),await r.build()}};var y=require("@meshsdk/common"),A=require("@meshsdk/core"),Y=require("@meshsdk/core-csl");var K={preamble:{title:"meshjs/swap",description:"Aiken contracts for project 'meshjs/swap'",version:"0.0.0",plutusVersion:"v2",compiler:{name:"Aiken",version:"v1.0.24-alpha+982eff4"},license:"Apache-2.0"},validators:[{title:"swap.swap",datum:{title:"datum",schema:{$ref:"#/definitions/swap~1SwapDatum"}},redeemer:{title:"redeemer",schema:{$ref:"#/definitions/swap~1SwapRedeemer"}},compiledCode:"59077601000032323232323232323222232325333008323232533300b3370e9001000899191919299980799b87480080084c94ccc040cdc3a4000601e0022646464646464646464646464a666038a6660380102002294040085281980299980200425eb7bdb180894ccc074cdd79807980d980a980d8010058998020009bab3015301b3015301b002100137566026603203066008664466600a00497adef6c6022533301e3375e6020603800400626600a0026eacc058c0700084004dd61802980c1806180c00a9806180c00b9bab30053018017223233300100100300222253330210021001132333004004302500333223233001001005225333026001133027337606ea4010dd3001a5eb7bdb1804c8c8c8c94ccc09ccdd799807804001260103d879800013302b337606ea4020dd30038028a99981399b8f0080021323253330293370e900000089981699bb03752014605c604e00400a200a604e00264a666050a66605600229445280a60103d87a800013374a9000198161ba60014bd70191998008008040011112999816801080089919980200218188019991191980080080291299981900089981999bb037520086ea000d2f5bded8c0264646464a66606666ebccc06c020009300103d8798000133037337606ea4020dd40038028a99981999b8f0080021323253330353370e900000089981c99bb037520146074606600400a200a606600264a66606866e1c005200014c103d87a800013374a90001981c1ba80014bd7019b80007001133037337606ea4008dd4000998030030019bad3034003375c6064004606c00460680026eb8c0b0004dd69816800981780109981599bb037520046e98004cc01801800cdd598140019bae3026002302a0023028001375c60400026eacc084004c08c008894ccc068cdc80010008a6103d87980001533301a3371e0040022980103d87a800014c103d87b8000222323300100100422533301f001100413300330210013300200230220012232323300100100222533301e00114a226464a66603a66e24dd698040011991191919299981119b8748008004520001375a604e6040004604000264a66604266e1d200200114c0103d87a8000132323300100100222533302700114c103d87a800013232323253330283371e014004266e9520003302c375000297ae0133006006003375a60520066eb8c09c008c0ac008c0a4004dd59813180f801180f80099198008008051129998120008a6103d87a800013232323253330253371e010004266e95200033029374c00297ae01330060060033756604c0066eb8c090008c0a0008c098004dd718078011bae301500213300400400114a060440046eb0c080004c8cc004004008894ccc07400452f5c0264666444646600200200644a66604600220062646604a6e9ccc094dd4803198129ba9375c60440026604a6ea0dd69811800a5eb80cc00c00cc09c008c094004dd7180e0009bab301d001330030033021002301f0012301b301c301c001533301700114a0264a6660300022944528180d00099191980080080111299980c8008a5eb804c8c94ccc060cdd79805180b1808180b00100309980e00119802002000899802002000980e801180d8009bac300530113005301100e30043010300a30100013016001300e0011632323300100100222533301500114c0103d87a80001323253330143375e600c6024004010266e952000330180024bd70099802002000980c801180b8009bac3001300d3001300d00a13232323300100100322533301600114a026464a66602a66e3c008014528899802002000980d0011bae3018001323253330123370e9000180880089bae30173010001163003300f0013002300e00d37586028602a602a602a602a602a602a602a602a601a6002601a014460280026018012602200260120042940c024004c004c01c0108c038c03c004526136563253330083370e90000008a99980598030020a4c2c2a66601066e1d20020011533300b300600414985858c01800cc8c8c94ccc024cdc3a40000022646464646464a666024602a0042646464931980500191919198068009191bad3018002375c602c0026eacc054008dd718098009980480211919198060009191bad3017002375c602a0026eacc050008dd7180900099299980819b87480000044c8c8c8c94ccc05cc0680084c8c9263253330163370e900000089919299980d980f00109924c64a66603266e1d200000113232533301e3021002132498c05400458c07c004c05c00854ccc064cdc3a40040022646464646464a666044604a0042930b1bad30230013023002375a604200260420046eb4c07c004c05c00858c05c00458c070004c05000c54ccc058cdc3a40040022a66603260280062930b0b180a00118070018b180c000980c001180b00098070030b18070028b1bab30130013013002375660220026022004601e002600e00c2c600e00a44646600200200644a66601c00229309919801801980900118019808000919299980419b87480000044c8c94ccc034c04000852616375c601c002600c0042a66601066e1d200200113232533300d3010002149858dd7180700098030010b1803000918029baa001230033754002ae6955ceaab9e5573eae815d0aba21",hash:"3f1869e426f5350c595ffd8ca4a6fba8186947ae0cd6c136fe23054a"}],definitions:{ByteArray:{dataType:"bytes"},Int:{dataType:"integer"},"Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Optional",anyOf:[{title:"Some",description:"An optional value.",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]},{title:"None",description:"Nothing.",dataType:"constructor",index:1,fields:[]}]},"aiken/dict/Dict$ByteArray_Int":{title:"Dict",description:"An opaque `Dict`. The type is opaque because the module maintains some\n invariant, namely: there's only one occurrence of a given key in the dictionary.\n\n Note that the `key` parameter is a phantom-type, and only present as a\n means of documentation. Keys can be any type, yet will need to comparable\n to use functions like `insert`.\n\n See for example:\n\n ```aiken\n pub type Value =\n Dict<PolicyId, Dict<AssetName, Int>>\n ```",dataType:"map",keys:{$ref:"#/definitions/ByteArray"},values:{$ref:"#/definitions/Int"}},"aiken/transaction/credential/Address":{title:"Address",description:`A Cardano \`Address\` typically holding one or two credential references.
532
+ // src/vesting/offchain.ts
533
+ var import_common3 = require("@meshsdk/common");
534
+ var import_core2 = require("@meshsdk/core");
535
+ var import_core_csl3 = require("@meshsdk/core-csl");
26
536
 
27
- Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are
28
- completely excluded from Plutus contexts. Thus, from an on-chain
29
- perspective only exists addresses of type 00, 01, ..., 07 as detailed
30
- in [CIP-0019 :: Shelley Addresses](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0019/#shelley-addresses).`,anyOf:[{title:"Address",dataType:"constructor",index:0,fields:[{title:"payment_credential",$ref:"#/definitions/aiken~1transaction~1credential~1Credential"},{title:"stake_credential",$ref:"#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"}]}]},"aiken/transaction/credential/Credential":{title:"Credential",description:`A general structure for representing an on-chain \`Credential\`.
537
+ // src/vesting/aiken-workspace/plutus.json
538
+ var plutus_default2 = {
539
+ preamble: {
540
+ title: "meshjs/vesting",
541
+ description: "Aiken contracts for project 'meshjs/vesting'",
542
+ version: "0.0.0",
543
+ plutusVersion: "v2",
544
+ compiler: {
545
+ name: "Aiken",
546
+ version: "v1.0.29-alpha+unknown"
547
+ },
548
+ license: "Apache-2.0"
549
+ },
550
+ validators: [
551
+ {
552
+ title: "vesting.vesting",
553
+ datum: {
554
+ title: "datum",
555
+ schema: {
556
+ $ref: "#/definitions/vesting~1types~1VestingDatum"
557
+ }
558
+ },
559
+ redeemer: {
560
+ title: "_redeemer",
561
+ schema: {
562
+ $ref: "#/definitions/Data"
563
+ }
564
+ },
565
+ compiledCode: "5901c40100003232323232323223222533300532533233007300130083754600460126ea800c4c8c8c94ccc028cc004dd6180118061baa3003300c375400c6eb8c014c030dd50048a511533300a330013758600460186ea8c00cc030dd50031bae300f30103010300c3754012266446464646464a666022601660246ea80084c94ccc0480104cdc40038008011bad301630133754004002264a666022601660246ea80084c94ccc0480100084cdc48038009bad3016301337540040022940c050008cdc424000601e6ea8c04cc050004cc044c048004cc044ccc034cdc424000601c6ea8c048c04c00530103d87a80004c0103d87980004bd7018071baa3005300e3754004601e602060206020602060206020602060186ea8c00cc030dd50031bad3003300c3754012294088c8cc00400400c894ccc040004528099299980719b8f375c602600400829444cc00c00c004c04c0048c038c03cc03cc03cc03cc03cc03cc03cc03c0048c034004dc3a400429408c02cc0300045261365653330023370e900018019baa0011323232323232533300b300e002149858dd7180600098060011bae300a001300a002375a601000260086ea8004595cd2ab9d5573caae7d5d02ba157441",
566
+ hash: "ac96a3fa3cabf670268a88720402c715ed5fd73ffb3276e6092ead00"
567
+ }
568
+ ],
569
+ definitions: {
570
+ ByteArray: {
571
+ dataType: "bytes"
572
+ },
573
+ Data: {
574
+ title: "Data",
575
+ description: "Any Plutus data."
576
+ },
577
+ Int: {
578
+ dataType: "integer"
579
+ },
580
+ "vesting/types/VestingDatum": {
581
+ title: "VestingDatum",
582
+ anyOf: [
583
+ {
584
+ title: "VestingDatum",
585
+ dataType: "constructor",
586
+ index: 0,
587
+ fields: [
588
+ {
589
+ title: "lock_until",
590
+ description: "POSIX time in second, e.g. 1672843961000",
591
+ $ref: "#/definitions/Int"
592
+ },
593
+ {
594
+ title: "owner",
595
+ description: "Owner's credentials",
596
+ $ref: "#/definitions/ByteArray"
597
+ },
598
+ {
599
+ title: "beneficiary",
600
+ description: "Beneficiary's credentials",
601
+ $ref: "#/definitions/ByteArray"
602
+ }
603
+ ]
604
+ }
605
+ ]
606
+ }
607
+ }
608
+ };
31
609
 
32
- Credentials are always one of two kinds: a direct public/private key
33
- pair, or a script (native or Plutus).`,anyOf:[{title:"VerificationKeyCredential",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/ByteArray"}]},{title:"ScriptCredential",dataType:"constructor",index:1,fields:[{$ref:"#/definitions/ByteArray"}]}]},"aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential":{title:"Referenced",description:`Represent a type of object that can be represented either inline (by hash)
34
- or via a reference (i.e. a pointer to an on-chain location).
610
+ // src/vesting/offchain.ts
611
+ var MeshVestingBlueprint = plutus_default2;
612
+ var MeshVestingContract = class extends MeshTxInitiator {
613
+ scriptCbor = (0, import_core_csl3.applyParamsToScript)(plutus_default2.validators[0].compiledCode, []);
614
+ constructor(inputs) {
615
+ super(inputs);
616
+ }
617
+ depositFund = async (amount, lockUntilTimeStampMs, beneficiary) => {
618
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
619
+ const scriptAddr = (0, import_core2.serializePlutusScript)(
620
+ { code: this.scriptCbor, version: "V2" },
621
+ void 0,
622
+ 0
623
+ ).address;
624
+ const { pubKeyHash: ownerPubKeyHash } = (0, import_core2.deserializeAddress)(walletAddress);
625
+ const { pubKeyHash: beneficiaryPubKeyHash } = (0, import_core2.deserializeAddress)(beneficiary);
626
+ await this.mesh.txOut(scriptAddr, amount).txOutInlineDatumValue(
627
+ (0, import_common3.mConStr0)([
628
+ lockUntilTimeStampMs,
629
+ ownerPubKeyHash,
630
+ beneficiaryPubKeyHash
631
+ ])
632
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
633
+ return this.mesh.txHex;
634
+ };
635
+ withdrawFund = async (vestingUtxo) => {
636
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
637
+ const { input: collateralInput, output: collateralOutput } = collateral;
638
+ const scriptAddr = (0, import_core2.serializePlutusScript)(
639
+ { code: this.scriptCbor, version: "V2" },
640
+ void 0,
641
+ 0
642
+ ).address;
643
+ const { pubKeyHash } = (0, import_core2.deserializeAddress)(walletAddress);
644
+ const datum = (0, import_core2.deserializeDatum)(
645
+ vestingUtxo.output.plutusData
646
+ );
647
+ const invalidBefore = (0, import_common3.unixTimeToEnclosingSlot)(
648
+ Math.min(datum.fields[0].int, Date.now() - 15e3),
649
+ this.networkId === 0 ? import_common3.SLOT_CONFIG_NETWORK.preprod : import_common3.SLOT_CONFIG_NETWORK.mainnet
650
+ ) + 1;
651
+ await this.mesh.spendingPlutusScriptV2().txIn(
652
+ vestingUtxo.input.txHash,
653
+ vestingUtxo.input.outputIndex,
654
+ vestingUtxo.output.amount,
655
+ scriptAddr
656
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(this.scriptCbor).txOut(walletAddress, []).txInCollateral(
657
+ collateralInput.txHash,
658
+ collateralInput.outputIndex,
659
+ collateralOutput.amount,
660
+ collateralOutput.address
661
+ ).invalidBefore(invalidBefore).requiredSignerHash(pubKeyHash).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
662
+ return this.mesh.txHex;
663
+ };
664
+ getUtxoByTxHash = async (txHash) => {
665
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
666
+ };
667
+ };
35
668
 
36
- This is mainly use for capturing pointers to a stake credential
37
- registration certificate in the case of so-called pointer addresses.`,anyOf:[{title:"Inline",dataType:"constructor",index:0,fields:[{$ref:"#/definitions/aiken~1transaction~1credential~1Credential"}]},{title:"Pointer",dataType:"constructor",index:1,fields:[{title:"slot_number",$ref:"#/definitions/Int"},{title:"transaction_index",$ref:"#/definitions/Int"},{title:"certificate_index",$ref:"#/definitions/Int"}]}]},"aiken/transaction/value/Value":{title:"Value",description:"A multi-asset output `Value`. Contains tokens indexed by [PolicyId](#PolicyId) and [AssetName](#AssetName).\n\n This type maintain some invariants by construction; in particular, a `Value` will never contain a\n zero quantity of a particular token.",dataType:"map",keys:{$ref:"#/definitions/ByteArray"},values:{$ref:"#/definitions/aiken~1dict~1Dict$ByteArray_Int"}},"swap/SwapDatum":{title:"SwapDatum",anyOf:[{title:"SwapDatum",dataType:"constructor",index:0,fields:[{title:"initiator",$ref:"#/definitions/aiken~1transaction~1credential~1Address"},{title:"to_provide",$ref:"#/definitions/aiken~1transaction~1value~1Value"},{title:"to_receive",$ref:"#/definitions/aiken~1transaction~1value~1Value"}]}]},"swap/SwapRedeemer":{title:"SwapRedeemer",anyOf:[{title:"Cancel",dataType:"constructor",index:0,fields:[]},{title:"Swap",dataType:"constructor",index:1,fields:[]}]}}};var y0=K,j=class extends m{scriptCbor=(0,Y.applyParamsToScript)(K.validators[0].compiledCode,[]);scriptAddress;constructor(e){super(e),this.scriptAddress=(0,A.serializePlutusScript)({code:this.scriptCbor,version:"V2"},void 0,0).address}initiateSwap=async(e,t)=>{let{utxos:c,walletAddress:a,collateral:i}=await this.getWalletInfoForTx(),{pubKeyHash:n,stakeCredentialHash:s}=(0,A.deserializeAddress)(a),d=(0,y.conStr0)([(0,y.pubKeyAddress)(n,s),(0,y.value)(e),(0,y.value)(t)]);return await this.mesh.txOut(this.scriptAddress,e).txOutInlineDatumValue(d,"JSON").changeAddress(a).txInCollateral(i.input.txHash,i.input.outputIndex,i.output.amount,i.output.address).selectUtxosFrom(c).complete(),this.mesh.txHex};acceptSwap=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),i=(0,A.deserializeDatum)(e.output.plutusData),n=(0,A.serializeAddressObj)(i.fields[0]),s=i.fields[2];return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,y.mConStr1)([])).txInScript(this.scriptCbor).txOut(n,y.MeshValue.fromValue(s).toAssets()).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).selectUtxosFrom(t).complete(),this.mesh.txHex};cancelSwap=async e=>{let{utxos:t,walletAddress:c,collateral:a}=await this.getWalletInfoForTx(),i=(0,A.deserializeDatum)(e.output.plutusData),n=(0,A.serializeAddressObj)(i.fields[0]);return await this.mesh.spendingPlutusScriptV2().txIn(e.input.txHash,e.input.outputIndex,e.output.amount,e.output.address).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0,y.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(c).txInCollateral(a.input.txHash,a.input.outputIndex,a.output.amount,a.output.address).requiredSignerHash((0,A.deserializeAddress)(n).pubKeyHash).selectUtxosFrom(t).complete(),this.mesh.txHex};getUtxoByTxHash=async e=>await this._getUtxoByTxHash(e,this.scriptCbor)};0&&(module.exports={MeshEscrowBlueprint,MeshEscrowContract,MeshGiftCardBlueprint,MeshGiftCardContract,MeshMarketplaceBlueprint,MeshMarketplaceContract,MeshPaymentSplitterBlueprint,MeshPaymentSplitterContract,MeshSwapBlueprint,MeshSwapContract,MeshVestingBlueprint,MeshVestingContract,activeEscrowDatum,initiateEscrowDatum,marketplaceDatum,recipientDepositRedeemer});
669
+ // src/escrow/offchain.ts
670
+ var import_common5 = require("@meshsdk/common");
671
+ var import_core3 = require("@meshsdk/core");
672
+ var import_core_csl4 = require("@meshsdk/core-csl");
673
+
674
+ // src/escrow/aiken-workspace/plutus.json
675
+ var plutus_default3 = {
676
+ preamble: {
677
+ title: "meshjs/escrow",
678
+ description: "Aiken contracts for project 'meshjs/escrow'",
679
+ version: "0.0.0",
680
+ plutusVersion: "v2",
681
+ compiler: {
682
+ name: "Aiken",
683
+ version: "v1.0.29-alpha+unknown"
684
+ },
685
+ license: "Apache-2.0"
686
+ },
687
+ validators: [
688
+ {
689
+ title: "escrow.escrow",
690
+ datum: {
691
+ title: "_datum",
692
+ schema: {
693
+ $ref: "#/definitions/escrow~1types~1EscrowDatum"
694
+ }
695
+ },
696
+ redeemer: {
697
+ title: "redeemer",
698
+ schema: {
699
+ $ref: "#/definitions/escrow~1types~1EscrowRedeemer"
700
+ }
701
+ },
702
+ compiledCode: "590c2f01000032323232323232232323232323232232322533300d3232533300f300c3010375400226464646464646464a66602e602a60306ea80044c8c8c8c8c8c8c8c8c8c94ccc084c07c0244c8c8c8c8c8c8c94ccc0acc0b800c4c94ccc0b0c0bc00c4c94ccc0a8c080c0acdd5000899192999816181118169baa001132533302d302b302e3754006264646464a666068606e004264646464a66606a66ebc024cdd2a40046607200e660726e98014cc0e404ccc0e4dd300925eb8040045281980b9bab302730363754018660326eacc09cc0d8dd51813981b1baa00d301a011302c0073302c0022323302e3756606c0044646eb4c0e0008dd7181b0009bae3034001302c003163756606a002606a0046066002605e6ea800c58c0c4c0b8dd50008b180798169baa003302f302c37540022c601a60566ea8c070c0acdd50010b18168010b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb80dd598141814801181380098119baa01813232325333024302100c132323232533302b302e0031533302b0021325333029301f302a375400226464a666056605260586ea80084c94ccc0b0c0a8c0b4dd500089980500c1bae3031302e37540022c60106060605a6ea80084c8c8c8c8c8c8c8c94ccc0ccc0c4c0d0dd500089919299981a9819981b1baa0011533303532330010013303a375200666074607660706ea80092f5c044a66607400229404c94ccc0e0cc058090dd7181e8010a51133003003001303d00115333035005100414a0294058c044014dd7181c181a9baa00116300f006330143301001e00230173756606c606e006660266601e03a008602c6eacc0d400cc0d0004c0d0004c0cc008c0c4004c0b4dd50011811800981718159baa00116300c302a3754603660546ea80045858c0b0008dd6181598160011bac302a00133028374e6600802601a660506e9ccc0140440352f5c0264646464a666056605c0062a666056004264a666052603e60546ea80044c94ccc0a8c09cc0acdd500089919191919191919299981a981c001099191919191919299981c981b981d1baa00113232533303b3039303c37540022a6660766466002002660806ea400ccc100c104c0f8dd500125eb80894ccc100004528899299981f1980e0151bae304300213300300300114a060860022a66607600a200829405280b180b8059bae303e303b37540022c602a01a660346602c048010603a014660326602a046016603800a6605e008464660626eacc0e40088c8dd6981d8011bae3039001375c606e002605e00a6605a00c4646605e6eacc0dc0088c8dd6981c8011bae3037001375c606a002605a00e2c6eacc0d8004c0d8008c0d0004c0d0008dd598190009819001181800098161baa00116302e302b37540022c601860546ea8c06cc0a8dd50008b0b18160011bac302b302c00237586054002660506e9ccc01004c034cc0a0dd399802808806a5eb808c94ccc094c08cc098dd50008980819814981518139baa0014bd700a6103d87a800030153026375400244646600200200644a66605200229404c94ccc09ccdc79bae302c00200414a2266006006002605800244646600200200644a666050002297adef6c601332253330273375e603060526ea80080144cc030004dd5980d18149baa0021001302a00133002002302b001223300400223375e6028604a6ea8c058c094dd50008011119801801119baf30133024375400200444646600200200644a66604a002297ae013232533302430050021330280023300400400113300400400130290023027001223233001001323300100100322533302500114bd7009919991119198008008019129998158008801899198169ba73302d375200c6605a60540026605a605600297ae033003003302f002302d001375c60480026eacc094004cc00c00cc0a4008c09c004894ccc09000452889929998111919b89375a600e002664464a66604c6046604e6ea8004520001375a605660506ea8004c94ccc098c08cc09cdd50008a60103d87a8000132330010013756605860526ea8008894ccc0ac004530103d87a8000132323232533302c337220100042a66605866e3c0200084c05ccc0c0dd4000a5eb80530103d87a8000133006006003375a605a0066eb8c0ac008c0bc008c0b4004c8cc004004024894ccc0a80045300103d87a8000132323232533302b337220100042a66605666e3c0200084c058cc0bcdd3000a5eb80530103d87a8000133006006003375660580066eb8c0a8008c0b8008c0b0004dd7180a0009bae30160013758604e0042660060060022940c09c0048c088c08cc08c00488c8ccc00400400c0088894ccc08c00840044c8ccc010010c09c00ccccc020008dd718110009bab3023001222325333025533302800114a229405300103d87a80001301033029374c00297ae032333001001003002222533302a0021001132333004004302e0033322323300100100522533302f001133030337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0c0cdc800400109981a19bb037520106ea001c01454ccc0c0cdc78040010992999818981798191baa001133035337606ea4024c0d8c0ccdd5000802080219299981898178008a60103d87a80001301c33035375000297ae03370000e00226606866ec0dd48011ba800133006006003375a60620066eb8c0bc008c0cc008c0c4004dd718148009bad302a001302c00230250022323300100100222533302000114bd6f7b6300999119191999804001801000911319190011919198008008019129998138008a4c264a6660500022a66604a60086eb4c09cc0a8008526161323232325333029337206eb8c0a8010dd718150018a9998149804000899803803998168018010b0b1bad302a003302d003302b002302a002302a001233302230200014a0944dd598110019bae3020002302200133002002302300122223233001001005225333022001133023337606ea4014dd300225eb7bdb1804c8c8c8c94ccc08ccdc800480109981399bb037520126e9802001454ccc08ccdc78048010992999812181118129baa001133028337606ea4028c0a4c098dd5000802080219980380480400089981399bb037520046e98004cc01801800cdd598120019bae3022002302600230240013019375401e601060326ea8c028c064dd5180e180c9baa0011632323300100100722533301c00114c0103d87a800013232533301b3375e6018603a6ea80080144c018cc07c0092f5c02660080080026040004603c002603660306ea8020dd2a40006eb0c064c068c068c068c068c068c068008dd6180c000980c180c0011bac301600130123754600260246ea80108c054004528180098081baa00223013301400114984d958c94ccc030c0280044c8c8c8c94ccc04cc0580084c8c9263300b0022323300d3756602a0044646eb4c05c008dd7180a8009bae3013001300b003163756602800260280046024002601c6ea800c54ccc030c02400454ccc03cc038dd50018a4c2c2a66601860040022a66601e601c6ea800c5261616300c37540046e1d20043001007232533300930070011323232325333010301300213232498cc0200088c8cc028dd598090011191bad3014002375c60240026eb8c040004c02000c58dd598088009808801180780098059baa0021533300930060011323232323232323253330143017002132323232498cc0380108c8cc040dd5980c0011191bad301a002375c60300026eb8c058004c038014cc0300188c8cc038dd5980b0011191bad3018002375c602c0026eb8c050004c03001c58dd5980a800980a801180980098098011bab30110013011002300f001300b37540042c60126ea800488c8cc00400400c894ccc0340045261323300300330110023003300f00125333006300430073754002264646464a66601a602000426464931929998061805000899192999808980a00109924c64a66601e601a00226464a666028602e0042649318068008b180a80098089baa0021533300f300c00113232323232325333018301b002149858dd6980c800980c8011bad30170013017002375a602a00260226ea800858c03cdd50008b180900098071baa0031533300c30090011533300f300e37540062930b0b18061baa002300600316300e001300e002300c001300837540022c464a66600c600800226464a666016601c0042930b1bae300c001300837540042a66600c600600226464a666016601c0042930b1bae300c001300837540042c600c6ea8004dc3a40046e1d20005734aae7555cf2ab9f5740ae855d101",
703
+ hash: "8fa9284f5889972d7260c10e940a2e1acb2114bdcea845da3d52de7d"
704
+ }
705
+ ],
706
+ definitions: {
707
+ ByteArray: {
708
+ dataType: "bytes"
709
+ },
710
+ Int: {
711
+ dataType: "integer"
712
+ },
713
+ List$Pair$ByteArray_Int: {
714
+ dataType: "map",
715
+ keys: {
716
+ $ref: "#/definitions/ByteArray"
717
+ },
718
+ values: {
719
+ $ref: "#/definitions/Int"
720
+ }
721
+ },
722
+ List$Pair$ByteArray_List$Pair$ByteArray_Int: {
723
+ dataType: "map",
724
+ keys: {
725
+ $ref: "#/definitions/ByteArray"
726
+ },
727
+ values: {
728
+ $ref: "#/definitions/List$Pair$ByteArray_Int"
729
+ }
730
+ },
731
+ "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
732
+ title: "Optional",
733
+ anyOf: [
734
+ {
735
+ title: "Some",
736
+ description: "An optional value.",
737
+ dataType: "constructor",
738
+ index: 0,
739
+ fields: [
740
+ {
741
+ $ref: "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
742
+ }
743
+ ]
744
+ },
745
+ {
746
+ title: "None",
747
+ description: "Nothing.",
748
+ dataType: "constructor",
749
+ index: 1,
750
+ fields: []
751
+ }
752
+ ]
753
+ },
754
+ "aiken/transaction/credential/Address": {
755
+ title: "Address",
756
+ description: "A Cardano `Address` typically holding one or two credential references.\n\n Note that legacy bootstrap addresses (a.k.a. 'Byron addresses') are\n completely excluded from Plutus contexts. Thus, from an on-chain\n perspective only exists addresses of type 00, 01, ..., 07 as detailed\n in [CIP-0019 :: Shelley Addresses](https://cips.cardano.org/cip/CIP-19).",
757
+ anyOf: [
758
+ {
759
+ title: "Address",
760
+ dataType: "constructor",
761
+ index: 0,
762
+ fields: [
763
+ {
764
+ title: "payment_credential",
765
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
766
+ },
767
+ {
768
+ title: "stake_credential",
769
+ $ref: "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
770
+ }
771
+ ]
772
+ }
773
+ ]
774
+ },
775
+ "aiken/transaction/credential/Credential": {
776
+ title: "Credential",
777
+ description: "A general structure for representing an on-chain `Credential`.\n\n Credentials are always one of two kinds: a direct public/private key\n pair, or a script (native or Plutus).",
778
+ anyOf: [
779
+ {
780
+ title: "VerificationKeyCredential",
781
+ dataType: "constructor",
782
+ index: 0,
783
+ fields: [
784
+ {
785
+ $ref: "#/definitions/ByteArray"
786
+ }
787
+ ]
788
+ },
789
+ {
790
+ title: "ScriptCredential",
791
+ dataType: "constructor",
792
+ index: 1,
793
+ fields: [
794
+ {
795
+ $ref: "#/definitions/ByteArray"
796
+ }
797
+ ]
798
+ }
799
+ ]
800
+ },
801
+ "aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
802
+ title: "Referenced",
803
+ description: "Represent a type of object that can be represented either inline (by hash)\n or via a reference (i.e. a pointer to an on-chain location).\n\n This is mainly use for capturing pointers to a stake credential\n registration certificate in the case of so-called pointer addresses.",
804
+ anyOf: [
805
+ {
806
+ title: "Inline",
807
+ dataType: "constructor",
808
+ index: 0,
809
+ fields: [
810
+ {
811
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
812
+ }
813
+ ]
814
+ },
815
+ {
816
+ title: "Pointer",
817
+ dataType: "constructor",
818
+ index: 1,
819
+ fields: [
820
+ {
821
+ title: "slot_number",
822
+ $ref: "#/definitions/Int"
823
+ },
824
+ {
825
+ title: "transaction_index",
826
+ $ref: "#/definitions/Int"
827
+ },
828
+ {
829
+ title: "certificate_index",
830
+ $ref: "#/definitions/Int"
831
+ }
832
+ ]
833
+ }
834
+ ]
835
+ },
836
+ "escrow/types/EscrowDatum": {
837
+ title: "EscrowDatum",
838
+ anyOf: [
839
+ {
840
+ title: "Initiation",
841
+ dataType: "constructor",
842
+ index: 0,
843
+ fields: [
844
+ {
845
+ title: "initiator",
846
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
847
+ },
848
+ {
849
+ title: "initiator_assets",
850
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
851
+ }
852
+ ]
853
+ },
854
+ {
855
+ title: "ActiveEscrow",
856
+ dataType: "constructor",
857
+ index: 1,
858
+ fields: [
859
+ {
860
+ title: "initiator",
861
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
862
+ },
863
+ {
864
+ title: "initiator_assets",
865
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
866
+ },
867
+ {
868
+ title: "recipient",
869
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
870
+ },
871
+ {
872
+ title: "recipient_assets",
873
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
874
+ }
875
+ ]
876
+ }
877
+ ]
878
+ },
879
+ "escrow/types/EscrowRedeemer": {
880
+ title: "EscrowRedeemer",
881
+ anyOf: [
882
+ {
883
+ title: "RecipientDeposit",
884
+ dataType: "constructor",
885
+ index: 0,
886
+ fields: [
887
+ {
888
+ title: "recipient",
889
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
890
+ },
891
+ {
892
+ title: "recipient_assets",
893
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
894
+ }
895
+ ]
896
+ },
897
+ {
898
+ title: "CancelTrade",
899
+ dataType: "constructor",
900
+ index: 1,
901
+ fields: []
902
+ },
903
+ {
904
+ title: "CompleteTrade",
905
+ dataType: "constructor",
906
+ index: 2,
907
+ fields: []
908
+ }
909
+ ]
910
+ }
911
+ }
912
+ };
913
+
914
+ // src/escrow/offchain.ts
915
+ var MeshEscrowBlueprint = plutus_default3;
916
+ var initiateEscrowDatum = (walletAddress, amount) => {
917
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core3.deserializeAddress)(walletAddress);
918
+ return (0, import_common5.conStr0)([
919
+ (0, import_common5.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
920
+ (0, import_common5.value)(amount)
921
+ ]);
922
+ };
923
+ var activeEscrowDatum = (initiationDatum, walletAddress, amount) => {
924
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core3.deserializeAddress)(walletAddress);
925
+ const [initiator, initiatorAmount] = initiationDatum.fields;
926
+ return (0, import_common5.conStr1)([
927
+ initiator,
928
+ initiatorAmount,
929
+ (0, import_common5.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
930
+ (0, import_common5.value)(amount)
931
+ ]);
932
+ };
933
+ var recipientDepositRedeemer = (recipient, depositAmount) => initiateEscrowDatum(recipient, depositAmount);
934
+ var MeshEscrowContract = class extends MeshTxInitiator {
935
+ scriptCbor = (0, import_core_csl4.applyParamsToScript)(plutus_default3.validators[0].compiledCode, []);
936
+ constructor(inputs) {
937
+ super(inputs);
938
+ }
939
+ initiateEscrow = async (escrowAmount) => {
940
+ const { utxos, walletAddress } = await this.getWalletInfoForTx();
941
+ const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
942
+ { code: this.scriptCbor, version: "V2" },
943
+ void 0,
944
+ this.networkId
945
+ );
946
+ await this.mesh.txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(
947
+ initiateEscrowDatum(walletAddress, escrowAmount),
948
+ "JSON"
949
+ ).changeAddress(walletAddress).selectUtxosFrom(utxos).complete();
950
+ return this.mesh.txHex;
951
+ };
952
+ cancelEscrow = async (escrowUtxo) => {
953
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
954
+ const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
955
+ { code: this.scriptCbor, version: "V2" },
956
+ void 0,
957
+ this.networkId
958
+ );
959
+ const inputDatum = (0, import_core3.deserializeDatum)(
960
+ escrowUtxo.output.plutusData
961
+ );
962
+ if (inputDatum.constructor === 1) {
963
+ const [
964
+ initiatorAddressObj,
965
+ initiatorAmount,
966
+ recipientAddressObj,
967
+ recipientAmount
968
+ ] = inputDatum.fields;
969
+ const initiatorAddress = (0, import_core3.serializeAddressObj)(initiatorAddressObj);
970
+ const recipientAddress = (0, import_core3.serializeAddressObj)(recipientAddressObj);
971
+ const initiatorToReceive = import_common5.MeshValue.fromValue(initiatorAmount).toAssets();
972
+ const recipientToReceive = import_common5.MeshValue.fromValue(recipientAmount).toAssets();
973
+ this.mesh.txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive);
974
+ }
975
+ await this.mesh.spendingPlutusScriptV2().txIn(
976
+ escrowUtxo.input.txHash,
977
+ escrowUtxo.input.outputIndex,
978
+ escrowUtxo.output.amount,
979
+ scriptAddr
980
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common5.mConStr1)([])).txInScript(this.scriptCbor).requiredSignerHash((0, import_core3.deserializeAddress)(walletAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
981
+ collateral.input.txHash,
982
+ collateral.input.outputIndex,
983
+ collateral.output.amount,
984
+ collateral.output.address
985
+ ).selectUtxosFrom(utxos).complete();
986
+ return this.mesh.txHex;
987
+ };
988
+ recipientDeposit = async (escrowUtxo, depositAmount) => {
989
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
990
+ const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
991
+ { code: this.scriptCbor, version: "V2" },
992
+ void 0,
993
+ this.networkId
994
+ );
995
+ const inputDatum = (0, import_core3.deserializeDatum)(
996
+ escrowUtxo.output.plutusData
997
+ );
998
+ const outputDatum = activeEscrowDatum(
999
+ inputDatum,
1000
+ walletAddress,
1001
+ depositAmount
1002
+ );
1003
+ const inputAssets = import_common5.MeshValue.fromValue(inputDatum.fields[1]).toAssets();
1004
+ const escrowAmount = (0, import_core3.mergeAssets)([...depositAmount, ...inputAssets]);
1005
+ await this.mesh.spendingPlutusScriptV2().txIn(
1006
+ escrowUtxo.input.txHash,
1007
+ escrowUtxo.input.outputIndex,
1008
+ escrowUtxo.output.amount,
1009
+ scriptAddr
1010
+ ).spendingReferenceTxInInlineDatumPresent().txInRedeemerValue(
1011
+ recipientDepositRedeemer(walletAddress, depositAmount),
1012
+ "JSON",
1013
+ {
1014
+ mem: 7e6,
1015
+ steps: 3e9
1016
+ }
1017
+ ).txInScript(this.scriptCbor).txOut(scriptAddr, escrowAmount).txOutInlineDatumValue(outputDatum, "JSON").changeAddress(walletAddress).txInCollateral(
1018
+ collateral.input.txHash,
1019
+ collateral.input.outputIndex,
1020
+ collateral.output.amount,
1021
+ collateral.output.address
1022
+ ).selectUtxosFrom(utxos).complete();
1023
+ return this.mesh.txHex;
1024
+ };
1025
+ completeEscrow = async (escrowUtxo) => {
1026
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1027
+ const { address: scriptAddr } = (0, import_core3.serializePlutusScript)(
1028
+ { code: this.scriptCbor, version: "V2" },
1029
+ void 0,
1030
+ this.networkId
1031
+ );
1032
+ const inputDatum = (0, import_core3.deserializeDatum)(
1033
+ escrowUtxo.output.plutusData
1034
+ );
1035
+ const [
1036
+ initiatorAddressObj,
1037
+ initiatorAmount,
1038
+ recipientAddressObj,
1039
+ recipientAmount
1040
+ ] = inputDatum.fields;
1041
+ const initiatorAddress = (0, import_core3.serializeAddressObj)(initiatorAddressObj);
1042
+ const recipientAddress = (0, import_core3.serializeAddressObj)(recipientAddressObj);
1043
+ const initiatorToReceive = import_common5.MeshValue.fromValue(recipientAmount).toAssets();
1044
+ const recipientToReceive = import_common5.MeshValue.fromValue(initiatorAmount).toAssets();
1045
+ await this.mesh.spendingPlutusScriptV2().txIn(
1046
+ escrowUtxo.input.txHash,
1047
+ escrowUtxo.input.outputIndex,
1048
+ escrowUtxo.output.amount,
1049
+ scriptAddr
1050
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common5.mConStr2)([])).txInScript(this.scriptCbor).txOut(initiatorAddress, initiatorToReceive).txOut(recipientAddress, recipientToReceive).requiredSignerHash((0, import_core3.deserializeAddress)(recipientAddress).pubKeyHash).requiredSignerHash((0, import_core3.deserializeAddress)(initiatorAddress).pubKeyHash).changeAddress(walletAddress).txInCollateral(
1051
+ collateral.input.txHash,
1052
+ collateral.input.outputIndex,
1053
+ collateral.output.amount,
1054
+ collateral.output.address
1055
+ ).selectUtxosFrom(utxos).complete();
1056
+ return this.mesh.txHex;
1057
+ };
1058
+ getUtxoByTxHash = async (txHash) => {
1059
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1060
+ };
1061
+ };
1062
+
1063
+ // src/giftcard/offchain.ts
1064
+ var import_common7 = require("@meshsdk/common");
1065
+ var import_core4 = require("@meshsdk/core");
1066
+ var import_core_csl5 = require("@meshsdk/core-csl");
1067
+
1068
+ // src/giftcard/aiken-workspace/plutus.json
1069
+ var plutus_default4 = {
1070
+ preamble: {
1071
+ title: "meshjs/giftcard",
1072
+ description: "Aiken contracts for project 'meshjs/giftcard'",
1073
+ version: "0.0.0",
1074
+ plutusVersion: "v2",
1075
+ compiler: {
1076
+ name: "Aiken",
1077
+ version: "v1.0.29-alpha+unknown"
1078
+ },
1079
+ license: "Apache-2.0"
1080
+ },
1081
+ validators: [
1082
+ {
1083
+ title: "oneshot.gift_card",
1084
+ redeemer: {
1085
+ title: "rdmr",
1086
+ schema: {
1087
+ $ref: "#/definitions/oneshot~1Action"
1088
+ }
1089
+ },
1090
+ parameters: [
1091
+ {
1092
+ title: "token_name",
1093
+ schema: {
1094
+ $ref: "#/definitions/ByteArray"
1095
+ }
1096
+ },
1097
+ {
1098
+ title: "utxo_ref",
1099
+ schema: {
1100
+ $ref: "#/definitions/aiken~1transaction~1OutputReference"
1101
+ }
1102
+ }
1103
+ ],
1104
+ compiledCode: "5901f5010000323232323232322322232323225333009323232533300c3007300d3754002264646464a666026602c00426464a666024601a60266ea803854ccc048c034c04cdd5191980080080311299980b8008a60103d87a80001323253330163375e603660306ea800804c4cdd2a40006603400497ae0133004004001301b002301900115333012300c00113371e00402029405854ccc048cdc3800a4002266e3c0080405281bad3013002375c60220022c602800264a66601e601260206ea800452f5bded8c026eacc050c044dd500099191980080099198008009bab3016301730173017301700522533301500114bd6f7b630099191919299980b19b91488100002153330163371e9101000021003100513301a337606ea4008dd3000998030030019bab3017003375c602a0046032004602e00244a666028002298103d87a800013232323253330153372200e0042a66602a66e3c01c0084cdd2a4000660326e980052f5c02980103d87a80001330060060033756602c0066eb8c050008c060008c058004dd7180998081baa00337586024002601c6ea800858c040c044008c03c004c02cdd50008a4c26cac64a66601060060022a66601660146ea8010526161533300830020011533300b300a37540082930b0b18041baa003370e90011b8748000dd7000ab9a5573aaae7955cfaba05742ae89",
1105
+ hash: "0c0d17d9095fe6b07a2727403e2c6f2dff8042ed7c300cb67a2577a2"
1106
+ },
1107
+ {
1108
+ title: "oneshot.redeem",
1109
+ datum: {
1110
+ title: "_d",
1111
+ schema: {
1112
+ $ref: "#/definitions/Data"
1113
+ }
1114
+ },
1115
+ redeemer: {
1116
+ title: "_r",
1117
+ schema: {
1118
+ $ref: "#/definitions/Data"
1119
+ }
1120
+ },
1121
+ parameters: [
1122
+ {
1123
+ title: "token_name",
1124
+ schema: {
1125
+ $ref: "#/definitions/ByteArray"
1126
+ }
1127
+ },
1128
+ {
1129
+ title: "policy_id",
1130
+ schema: {
1131
+ $ref: "#/definitions/ByteArray"
1132
+ }
1133
+ }
1134
+ ],
1135
+ compiledCode: "5901320100003232323232323223223222253330083232533300d3010002132533300b3370e6eb4c034009200113371e0020122940dd718058008b180700099299980499b8748008c028dd50008a5eb7bdb1804dd5980718059baa001323300100132330010013756601e602060206020602060186ea8c03cc030dd50019129998070008a5eb7bdb1804c8c8c8c94ccc03ccdc8a45000021533300f3371e91010000210031005133013337606ea4008dd3000998030030019bab3010003375c601c0046024004602000244a66601a002298103d87a8000132323232533300e337220140042a66601c66e3c0280084cdd2a4000660246e980052f5c02980103d87a80001330060060033756601e0066eb8c034008c044008c03c00452613656375c0026eb80055cd2ab9d5573caae7d5d02ba157441",
1136
+ hash: "39faa048196bb6b30f50815475e9d16b22e7a0ef6de5935b408ca617"
1137
+ }
1138
+ ],
1139
+ definitions: {
1140
+ ByteArray: {
1141
+ dataType: "bytes"
1142
+ },
1143
+ Data: {
1144
+ title: "Data",
1145
+ description: "Any Plutus data."
1146
+ },
1147
+ Int: {
1148
+ dataType: "integer"
1149
+ },
1150
+ "aiken/transaction/OutputReference": {
1151
+ title: "OutputReference",
1152
+ 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",
1153
+ anyOf: [
1154
+ {
1155
+ title: "OutputReference",
1156
+ dataType: "constructor",
1157
+ index: 0,
1158
+ fields: [
1159
+ {
1160
+ title: "transaction_id",
1161
+ $ref: "#/definitions/aiken~1transaction~1TransactionId"
1162
+ },
1163
+ {
1164
+ title: "output_index",
1165
+ $ref: "#/definitions/Int"
1166
+ }
1167
+ ]
1168
+ }
1169
+ ]
1170
+ },
1171
+ "aiken/transaction/TransactionId": {
1172
+ title: "TransactionId",
1173
+ 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.",
1174
+ anyOf: [
1175
+ {
1176
+ title: "TransactionId",
1177
+ dataType: "constructor",
1178
+ index: 0,
1179
+ fields: [
1180
+ {
1181
+ title: "hash",
1182
+ $ref: "#/definitions/ByteArray"
1183
+ }
1184
+ ]
1185
+ }
1186
+ ]
1187
+ },
1188
+ "oneshot/Action": {
1189
+ title: "Action",
1190
+ anyOf: [
1191
+ {
1192
+ title: "Mint",
1193
+ dataType: "constructor",
1194
+ index: 0,
1195
+ fields: []
1196
+ },
1197
+ {
1198
+ title: "Burn",
1199
+ dataType: "constructor",
1200
+ index: 1,
1201
+ fields: []
1202
+ }
1203
+ ]
1204
+ }
1205
+ }
1206
+ };
1207
+
1208
+ // src/giftcard/offchain.ts
1209
+ var MeshGiftCardBlueprint = plutus_default4;
1210
+ var MeshGiftCardContract = class extends MeshTxInitiator {
1211
+ tokenNameHex = "";
1212
+ paramUtxo = { outputIndex: 0, txHash: "" };
1213
+ giftCardCbor = (tokenNameHex, utxoTxHash, utxoTxId) => {
1214
+ return (0, import_core_csl5.applyParamsToScript)(
1215
+ plutus_default4.validators[0].compiledCode,
1216
+ [(0, import_common7.builtinByteString)(tokenNameHex), (0, import_common7.txOutRef)(utxoTxHash, utxoTxId)],
1217
+ "JSON"
1218
+ );
1219
+ };
1220
+ redeemCbor = (tokenNameHex, policyId) => (0, import_core_csl5.applyParamsToScript)(plutus_default4.validators[1].compiledCode, [
1221
+ tokenNameHex,
1222
+ policyId
1223
+ ]);
1224
+ constructor(inputs, tokenNameHex, paramUtxo) {
1225
+ super(inputs);
1226
+ if (tokenNameHex) {
1227
+ this.tokenNameHex = tokenNameHex;
1228
+ }
1229
+ if (paramUtxo) {
1230
+ this.paramUtxo = paramUtxo;
1231
+ }
1232
+ }
1233
+ createGiftCard = async (tokenName2, giftValue) => {
1234
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1235
+ const tokenNameHex = (0, import_common7.stringToHex)(tokenName2);
1236
+ const firstUtxo = utxos[0];
1237
+ if (firstUtxo === void 0) throw new Error("No UTXOs available");
1238
+ const remainingUtxos = utxos.slice(1);
1239
+ const giftCardScript = this.giftCardCbor(
1240
+ tokenNameHex,
1241
+ firstUtxo.input.txHash,
1242
+ firstUtxo.input.outputIndex
1243
+ );
1244
+ const giftCardPolicy = (0, import_core4.resolveScriptHash)(giftCardScript, "V2");
1245
+ const redeemScript = {
1246
+ code: this.redeemCbor(tokenNameHex, giftCardPolicy),
1247
+ version: "V2"
1248
+ };
1249
+ const redeemAddr = (0, import_core4.serializePlutusScript)(
1250
+ redeemScript,
1251
+ void 0,
1252
+ this.networkId
1253
+ ).address;
1254
+ await this.mesh.txIn(
1255
+ firstUtxo.input.txHash,
1256
+ firstUtxo.input.outputIndex,
1257
+ firstUtxo.output.amount,
1258
+ firstUtxo.output.address
1259
+ ).mintPlutusScriptV2().mint("1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common7.mConStr0)([])).txOut(redeemAddr, [
1260
+ ...giftValue,
1261
+ { unit: giftCardPolicy + tokenNameHex, quantity: "1" }
1262
+ ]).txOutInlineDatumValue([
1263
+ firstUtxo.input.txHash,
1264
+ firstUtxo.input.outputIndex,
1265
+ tokenNameHex
1266
+ ]).changeAddress(walletAddress).txInCollateral(
1267
+ collateral.input.txHash,
1268
+ collateral.input.outputIndex,
1269
+ collateral.output.amount,
1270
+ collateral.output.address
1271
+ ).selectUtxosFrom(remainingUtxos).complete();
1272
+ this.tokenNameHex = tokenNameHex;
1273
+ this.paramUtxo = firstUtxo.input;
1274
+ return this.mesh.txHex;
1275
+ };
1276
+ redeemGiftCard = async (giftCardUtxo) => {
1277
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1278
+ const inlineDatum = (0, import_core4.deserializeDatum)(
1279
+ giftCardUtxo.output.plutusData
1280
+ ).list;
1281
+ const paramTxHash = inlineDatum[0].bytes;
1282
+ const paramTxId = inlineDatum[1].int;
1283
+ const tokenNameHex = inlineDatum[2].bytes;
1284
+ const giftCardScript = this.giftCardCbor(
1285
+ tokenNameHex,
1286
+ paramTxHash,
1287
+ paramTxId
1288
+ );
1289
+ const giftCardPolicy = (0, import_core4.resolveScriptHash)(giftCardScript, "V2");
1290
+ const redeemScript = this.redeemCbor(tokenNameHex, giftCardPolicy);
1291
+ await this.mesh.spendingPlutusScriptV2().txIn(
1292
+ giftCardUtxo.input.txHash,
1293
+ giftCardUtxo.input.outputIndex,
1294
+ giftCardUtxo.output.amount,
1295
+ giftCardUtxo.output.address
1296
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue("").txInScript(redeemScript).mintPlutusScriptV2().mint("-1", giftCardPolicy, tokenNameHex).mintingScript(giftCardScript).mintRedeemerValue((0, import_common7.mConStr1)([])).changeAddress(walletAddress).txInCollateral(
1297
+ collateral.input.txHash,
1298
+ collateral.input.outputIndex,
1299
+ collateral.output.amount,
1300
+ collateral.output.address
1301
+ ).selectUtxosFrom(utxos).complete();
1302
+ return this.mesh.txHex;
1303
+ };
1304
+ getUtxoByTxHash = async (txHash) => {
1305
+ return await this._getUtxoByTxHash(txHash);
1306
+ };
1307
+ };
1308
+
1309
+ // src/payment-splitter/offchain.ts
1310
+ var import_common9 = require("@meshsdk/common");
1311
+ var import_core5 = require("@meshsdk/core");
1312
+ var import_core_csl6 = require("@meshsdk/core-csl");
1313
+
1314
+ // src/payment-splitter/aiken-workspace/plutus.json
1315
+ var plutus_default5 = {
1316
+ preamble: {
1317
+ title: "fabianbormann/payment-splitter",
1318
+ description: "Aiken contracts for project 'fabianbormann/payment-splitter'",
1319
+ version: "0.1.0",
1320
+ plutusVersion: "v2",
1321
+ compiler: {
1322
+ name: "Aiken",
1323
+ version: "v1.0.29-alpha+unknown"
1324
+ },
1325
+ license: "Apache-2.0"
1326
+ },
1327
+ validators: [
1328
+ {
1329
+ title: "payment_splitter.payout",
1330
+ datum: {
1331
+ title: "_datum",
1332
+ schema: {
1333
+ $ref: "#/definitions/payment_splitter~1Datum"
1334
+ }
1335
+ },
1336
+ redeemer: {
1337
+ title: "_redeemer",
1338
+ schema: {
1339
+ $ref: "#/definitions/payment_splitter~1Redeemer"
1340
+ }
1341
+ },
1342
+ parameters: [
1343
+ {
1344
+ title: "scriptHashes",
1345
+ schema: {
1346
+ $ref: "#/definitions/List$ByteArray"
1347
+ }
1348
+ }
1349
+ ],
1350
+ compiledCode: "5903a5010000323232323232322322322322533300832323232323232323232323253330143375e6e9cccc8c0040048894ccc06800440084ccc00c00cc8c8cc004004010894ccc07400452f5c026464a66603866ebc00801440044cc080008cc010010004c084008c07c004c070004c074004cc8c004004894ccc06400452f5c026466036002660060066600e603a004466603066ebc00400928251301b001323300100100722533301900114bd7009980d1806180c1baa300c3018375460360026600400460380020169801018000100114a0646600200200444a66603000229444c94ccc058cdc39bad301b00233005533301900414c0103d87a80001300e3301a301b0044bd70240002660060060022940c06c004c8cc004004028894ccc05c00452f5c02660306ea0c8c8c8c8c8c94ccc068cdc424000002266e04008cdc08009802005880119980119804806919baf3010301c3754602060386ea8c014c070dd5000803240004466e00004c014dd59803180e9baa3006301d375400466600266010014466ebcc03cc06cdd51807980d9baa0010054800088cdc000098021bab3005301c3754004444646600200200844a66603e0022008266006604200266004004604400246600c64a66603066e1d200230193754002298103d87a8000132330010013756603c60366ea8008894ccc074004530103d87a8000132323232533301e33722911000021533301e3371e9101000021301633022375000297ae014c0103d87a8000133006006003375a603e0066eb8c074008c084008c07c004c8cc004004008894ccc0700045300103d87a8000132323232533301d33722911000021533301d3371e9101000021301533021374c00297ae014c0103d87a80001330060060033756603c0066eb8c070008c080008c07800520002301b301c001301900133002002301a0012253330133370e9001180a1baa00210011375a6030602a6ea800888c8cc00400400c894ccc05c00452f5c026464a66602c600a00426603400466008008002266008008002603600460320026eacc050c054008dd61809800980998098011bac3011001300d37546002601a6ea80108c040004c8cc004004020894ccc03800452f5c026601e60066601e602000297ae0330020023011001374a90000a4c26caca66600c66e1d20003007375400226464a666016601c0042930b1bae300c001300837540022ca66600866e1d20003005375400226464a66601260180042930b1bae300a001300637540022c6eb00055cd2ab9d5573caae7d5d02ba157441",
1351
+ hash: "0776032753d2900f7c1e933af4108c53851e10ca95fa10e34af90277"
1352
+ }
1353
+ ],
1354
+ definitions: {
1355
+ ByteArray: {
1356
+ dataType: "bytes"
1357
+ },
1358
+ List$ByteArray: {
1359
+ dataType: "list",
1360
+ items: {
1361
+ $ref: "#/definitions/ByteArray"
1362
+ }
1363
+ },
1364
+ "payment_splitter/Datum": {
1365
+ title: "Datum",
1366
+ anyOf: [
1367
+ {
1368
+ title: "Datum",
1369
+ dataType: "constructor",
1370
+ index: 0,
1371
+ fields: [
1372
+ {
1373
+ title: "owner",
1374
+ $ref: "#/definitions/ByteArray"
1375
+ }
1376
+ ]
1377
+ }
1378
+ ]
1379
+ },
1380
+ "payment_splitter/Redeemer": {
1381
+ title: "Redeemer",
1382
+ anyOf: [
1383
+ {
1384
+ title: "Redeemer",
1385
+ dataType: "constructor",
1386
+ index: 0,
1387
+ fields: [
1388
+ {
1389
+ title: "message",
1390
+ $ref: "#/definitions/ByteArray"
1391
+ }
1392
+ ]
1393
+ }
1394
+ ]
1395
+ }
1396
+ }
1397
+ };
1398
+
1399
+ // src/payment-splitter/offchain.ts
1400
+ var MeshPaymentSplitterBlueprint = plutus_default5;
1401
+ var MeshPaymentSplitterContract = class extends MeshTxInitiator {
1402
+ wrapPayees = (payees) => (0, import_common9.list)(
1403
+ payees.map(
1404
+ (payee) => (0, import_common9.builtinByteString)((0, import_core5.deserializeAddress)(payee).pubKeyHash)
1405
+ )
1406
+ );
1407
+ scriptCbor = () => (0, import_core_csl6.applyParamsToScript)(
1408
+ plutus_default5.validators[0].compiledCode,
1409
+ [this.wrapPayees(this.payees)],
1410
+ "JSON"
1411
+ );
1412
+ payees = [];
1413
+ constructor(inputs, payees) {
1414
+ super(inputs);
1415
+ if (inputs.wallet) {
1416
+ if (inputs.wallet instanceof import_core5.MeshWallet) {
1417
+ this.payees = [inputs.wallet.getUsedAddresses()[0], ...payees];
1418
+ }
1419
+ if (inputs.wallet instanceof import_core5.BrowserWallet) {
1420
+ inputs.wallet.getUsedAddresses().then((addresses) => {
1421
+ this.payees = [addresses[0], ...payees];
1422
+ });
1423
+ }
1424
+ } else {
1425
+ this.payees = payees;
1426
+ console.warn(
1427
+ "Wallet not provided. Therefore the payment address will not be added to the payees list which makes it impossible to trigger the payout."
1428
+ );
1429
+ }
1430
+ }
1431
+ sendLovelaceToSplitter = async (lovelaceAmount) => {
1432
+ if (this.wallet === null || this.wallet === void 0) {
1433
+ throw new Error("Wallet not provided");
1434
+ }
1435
+ const { walletAddress } = await this.getWalletInfoForTx();
1436
+ const script = {
1437
+ code: this.scriptCbor(),
1438
+ version: "V2"
1439
+ };
1440
+ const { address: scriptAddress } = (0, import_core5.serializePlutusScript)(
1441
+ script,
1442
+ void 0,
1443
+ 0
1444
+ );
1445
+ const { pubKeyHash } = (0, import_core5.deserializeAddress)(walletAddress);
1446
+ const datum = {
1447
+ alternative: 0,
1448
+ fields: [pubKeyHash]
1449
+ };
1450
+ const tx = new import_core5.Transaction({ initiator: this.wallet }).sendLovelace(
1451
+ {
1452
+ address: scriptAddress,
1453
+ datum: { value: datum }
1454
+ },
1455
+ lovelaceAmount.toString()
1456
+ );
1457
+ const unsignedTx = await tx.build();
1458
+ return unsignedTx;
1459
+ };
1460
+ triggerPayout = async () => {
1461
+ if (this.wallet === null || this.wallet === void 0) {
1462
+ throw new Error("Wallet not provided");
1463
+ }
1464
+ const { walletAddress, collateral } = await this.getWalletInfoForTx();
1465
+ const script = {
1466
+ code: this.scriptCbor(),
1467
+ version: "V2"
1468
+ };
1469
+ const { address: scriptAddress } = (0, import_core5.serializePlutusScript)(
1470
+ script,
1471
+ void 0,
1472
+ 0
1473
+ );
1474
+ const utxos = await this.fetcher?.fetchAddressUTxOs(scriptAddress) || [];
1475
+ const { pubKeyHash } = (0, import_core5.deserializeAddress)(walletAddress);
1476
+ const datum = {
1477
+ alternative: 0,
1478
+ fields: [pubKeyHash]
1479
+ };
1480
+ const redeemerData = "Hello, World!";
1481
+ const redeemer = { data: { alternative: 0, fields: [redeemerData] } };
1482
+ let tx = new import_core5.Transaction({ initiator: this.wallet });
1483
+ let split = 0;
1484
+ for (const utxo of utxos) {
1485
+ const amount = utxo.output?.amount;
1486
+ if (amount) {
1487
+ let lovelace = amount.find((asset) => asset.unit === "lovelace");
1488
+ if (lovelace) {
1489
+ split += Math.floor(Number(lovelace.quantity) / this.payees.length);
1490
+ }
1491
+ tx = tx.redeemValue({
1492
+ value: utxo,
1493
+ script,
1494
+ datum,
1495
+ redeemer
1496
+ });
1497
+ }
1498
+ }
1499
+ tx = tx.setCollateral([collateral]);
1500
+ for (const payee of this.payees) {
1501
+ tx = tx.sendLovelace(payee, split.toString());
1502
+ }
1503
+ tx = tx.setRequiredSigners([walletAddress]);
1504
+ const unsignedTx = await tx.build();
1505
+ return unsignedTx;
1506
+ };
1507
+ };
1508
+
1509
+ // src/swap/offchain.ts
1510
+ var import_common11 = require("@meshsdk/common");
1511
+ var import_core6 = require("@meshsdk/core");
1512
+ var import_core_csl7 = require("@meshsdk/core-csl");
1513
+
1514
+ // src/swap/aiken-workspace/plutus.json
1515
+ var plutus_default6 = {
1516
+ preamble: {
1517
+ title: "meshjs/swap",
1518
+ description: "Aiken contracts for project 'meshjs/swap'",
1519
+ version: "0.0.0",
1520
+ plutusVersion: "v2",
1521
+ compiler: {
1522
+ name: "Aiken",
1523
+ version: "v1.0.29-alpha+unknown"
1524
+ },
1525
+ license: "Apache-2.0"
1526
+ },
1527
+ validators: [
1528
+ {
1529
+ title: "swap.swap",
1530
+ datum: {
1531
+ title: "datum",
1532
+ schema: {
1533
+ $ref: "#/definitions/swap~1SwapDatum"
1534
+ }
1535
+ },
1536
+ redeemer: {
1537
+ title: "redeemer",
1538
+ schema: {
1539
+ $ref: "#/definitions/swap~1SwapRedeemer"
1540
+ }
1541
+ },
1542
+ compiledCode: "590827010000323232323232322323232232253330083232533300a3007300b375400226464a6466601a6014601c6ea80204c94ccc038c030c03cdd5000899191919191919191919299980c299980d8048a501533301b301e00914a2294054ccc06000440085280a50330043330030084bd6f7b63011299980c99baf300e301b3754602260366ea800802c4cc010004dd59808980d9baa3011301b37540042002600c6eacc03cc064dd500b19801999119980200125eb7bdb180894ccc068cdd79807980e1baa0020031330050013756602460386ea80084004dd61802180c1baa300b3018375401e601660306ea8054c014dd59802180c1baa0152232333001001003002222533301d00210011323330040043021003333300b002375c60380026eacc074004888c94ccc07d4ccc0880045288a5014c103d87a80001301333023374c00297ae0323330010010030022225333024002100113233300400430280033322323300100100522533302900113302a337606ea4010dd4001a5eb7bdb1804c8c8c8c94ccc0a8cdc800400109981719bb037520106ea001c01454ccc0a8cdc78040010992999815981498161baa00113302f337606ea4024c0c0c0b4dd5000802080219299981598148008a60103d87a80001301f3302f375000297ae03370000e00226605c66ec0dd48011ba800133006006003375a60560066eb8c0a4008c0b4008c0ac004dd718118009bad30240013026002301f002222323300100100422533301c0011004133003301e00133002002301f001223233001001323300100100322533301b00114bd7009919991119198008008019129998108008801899198119ba733023375200c66046604000266046604200297ae03300300330250023023001375c60340026eacc06c004cc00c00cc07c008c074004894ccc068004528899299980c1919b89375a600e002664464a6660386032603a6ea8004520001375a6042603c6ea8004c94ccc070c064c074dd50008a6103d87a80001323300100137566044603e6ea8008894ccc084004530103d87a80001323232325333022337220100042a66604466e3c0200084c058cc098dd4000a5eb80530103d87a8000133006006003375a60460066eb8c084008c094008c08c004c8cc004004024894ccc0800045300103d87a80001323232325333021337220100042a66604266e3c0200084c054cc094dd3000a5eb80530103d87a8000133006006003375660440066eb8c080008c090008c088004dd718070009bae30110013758603a0042660060060022940c0740048c060c064c0640048c8cc004004008894ccc05c00452f5bded8c02664464646666010006004002444c646400464646600200200644a66603c002293099299980f8008a99980e18021bad301e30210021498584c8c8c8c94ccc080cdc81bae3021004375c60420062a666040601000226600e00e660480060042c2c6eb4c08400cc09000cc088008c084008c0840048ccc064c05c00528251375660320066eb8c05c008c064004cc008008c0680048888c8cc004004014894ccc0640044cc068cdd81ba9005374c00897adef6c60132323232533301a3372001200426603c66ec0dd48049ba60080051533301a3371e012004264a666036603260386ea80044cc07ccdd81ba900a3020301d3754002008200866600e01201000226603c66ec0dd48011ba600133006006003375660360066eb8c064008c074008c06c004c8cc004004dd6180298091baa30053012375401244a666028002297ae01323253330133375e6010602a6ea8c02cc054dd500100289980b80119802002000899802002000980c001180b000980198081baa300630103754602660206ea800458c8cc004004dd6180198081baa30033010375400e44a666024002298103d87a80001323253330113375e600c60266ea800801c4c014cc0540092f5c0266008008002602c0046028002264a66601c6018601e6ea80044cc88c8cc00400400c894ccc054004528099299980999b8f375c603000400829444cc00c00c004c060004dd61809980a180a180a180a180a180a180a180a18081baa30033010375400e6eb8c04cc040dd50008b192999807180618079baa001130023301230133010375400297ae014c0103d87a80003002300f37546004601e6ea8030dd2a400046022002601e60186ea8004528180098059baa0022300e300f00114984d958c94ccc01cc01400454ccc028c024dd50010a4c2c2a66600e60080022a66601460126ea80085261616300737540026464a66600c6008600e6ea80144c8c8c8c8c8c94ccc03cc0480084c8c8c926330090032323300b375660240044646eb4c050008dd718090009bae3010001330080042323300a375660220044646eb4c04c008dd718088009bae300f001533300c300a300d375400a264646464a666026602c0042646493192999809180800089919299980b980d00109924c64a66602a602600226464a666034603a0042649318098008b180d800980b9baa0021533301530120011323232323232533301e3021002149858dd6980f800980f8011bad301d001301d002375a6036002602e6ea800858c054dd50008b180c000980a1baa00315333012300f00115333015301437540062930b0b18091baa002300c00316301400130140023012001300e375400a2c2c6eacc040004c040008dd598070009807001180600098041baa0051622323300100100322533300c00114984c8cc00c00cc040008c00cc0380048c94ccc018c0100044c8c94ccc02cc03800852616375c601800260106ea800854ccc018c00c0044c8c94ccc02cc03800852616375c601800260106ea800858c018dd50009b8748008dc3a4000ae6955ceaab9e5573eae815d0aba201",
1543
+ hash: "5db0485a71b88eb31dec330bcf994509ea24b709498f90f9b1863902"
1544
+ }
1545
+ ],
1546
+ definitions: {
1547
+ ByteArray: {
1548
+ dataType: "bytes"
1549
+ },
1550
+ Int: {
1551
+ dataType: "integer"
1552
+ },
1553
+ List$Pair$ByteArray_Int: {
1554
+ dataType: "map",
1555
+ keys: {
1556
+ $ref: "#/definitions/ByteArray"
1557
+ },
1558
+ values: {
1559
+ $ref: "#/definitions/Int"
1560
+ }
1561
+ },
1562
+ List$Pair$ByteArray_List$Pair$ByteArray_Int: {
1563
+ dataType: "map",
1564
+ keys: {
1565
+ $ref: "#/definitions/ByteArray"
1566
+ },
1567
+ values: {
1568
+ $ref: "#/definitions/List$Pair$ByteArray_Int"
1569
+ }
1570
+ },
1571
+ "Option$aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
1572
+ title: "Optional",
1573
+ anyOf: [
1574
+ {
1575
+ title: "Some",
1576
+ description: "An optional value.",
1577
+ dataType: "constructor",
1578
+ index: 0,
1579
+ fields: [
1580
+ {
1581
+ $ref: "#/definitions/aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
1582
+ }
1583
+ ]
1584
+ },
1585
+ {
1586
+ title: "None",
1587
+ description: "Nothing.",
1588
+ dataType: "constructor",
1589
+ index: 1,
1590
+ fields: []
1591
+ }
1592
+ ]
1593
+ },
1594
+ "aiken/transaction/credential/Address": {
1595
+ title: "Address",
1596
+ 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).",
1597
+ anyOf: [
1598
+ {
1599
+ title: "Address",
1600
+ dataType: "constructor",
1601
+ index: 0,
1602
+ fields: [
1603
+ {
1604
+ title: "payment_credential",
1605
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
1606
+ },
1607
+ {
1608
+ title: "stake_credential",
1609
+ $ref: "#/definitions/Option$aiken~1transaction~1credential~1Referenced$aiken~1transaction~1credential~1Credential"
1610
+ }
1611
+ ]
1612
+ }
1613
+ ]
1614
+ },
1615
+ "aiken/transaction/credential/Credential": {
1616
+ title: "Credential",
1617
+ 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).",
1618
+ anyOf: [
1619
+ {
1620
+ title: "VerificationKeyCredential",
1621
+ dataType: "constructor",
1622
+ index: 0,
1623
+ fields: [
1624
+ {
1625
+ $ref: "#/definitions/ByteArray"
1626
+ }
1627
+ ]
1628
+ },
1629
+ {
1630
+ title: "ScriptCredential",
1631
+ dataType: "constructor",
1632
+ index: 1,
1633
+ fields: [
1634
+ {
1635
+ $ref: "#/definitions/ByteArray"
1636
+ }
1637
+ ]
1638
+ }
1639
+ ]
1640
+ },
1641
+ "aiken/transaction/credential/Referenced$aiken/transaction/credential/Credential": {
1642
+ title: "Referenced",
1643
+ 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.",
1644
+ anyOf: [
1645
+ {
1646
+ title: "Inline",
1647
+ dataType: "constructor",
1648
+ index: 0,
1649
+ fields: [
1650
+ {
1651
+ $ref: "#/definitions/aiken~1transaction~1credential~1Credential"
1652
+ }
1653
+ ]
1654
+ },
1655
+ {
1656
+ title: "Pointer",
1657
+ dataType: "constructor",
1658
+ index: 1,
1659
+ fields: [
1660
+ {
1661
+ title: "slot_number",
1662
+ $ref: "#/definitions/Int"
1663
+ },
1664
+ {
1665
+ title: "transaction_index",
1666
+ $ref: "#/definitions/Int"
1667
+ },
1668
+ {
1669
+ title: "certificate_index",
1670
+ $ref: "#/definitions/Int"
1671
+ }
1672
+ ]
1673
+ }
1674
+ ]
1675
+ },
1676
+ "swap/SwapDatum": {
1677
+ title: "SwapDatum",
1678
+ anyOf: [
1679
+ {
1680
+ title: "SwapDatum",
1681
+ dataType: "constructor",
1682
+ index: 0,
1683
+ fields: [
1684
+ {
1685
+ title: "initiator",
1686
+ $ref: "#/definitions/aiken~1transaction~1credential~1Address"
1687
+ },
1688
+ {
1689
+ title: "to_provide",
1690
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
1691
+ },
1692
+ {
1693
+ title: "to_receive",
1694
+ $ref: "#/definitions/List$Pair$ByteArray_List$Pair$ByteArray_Int"
1695
+ }
1696
+ ]
1697
+ }
1698
+ ]
1699
+ },
1700
+ "swap/SwapRedeemer": {
1701
+ title: "SwapRedeemer",
1702
+ anyOf: [
1703
+ {
1704
+ title: "Cancel",
1705
+ dataType: "constructor",
1706
+ index: 0,
1707
+ fields: []
1708
+ },
1709
+ {
1710
+ title: "Swap",
1711
+ dataType: "constructor",
1712
+ index: 1,
1713
+ fields: []
1714
+ }
1715
+ ]
1716
+ }
1717
+ }
1718
+ };
1719
+
1720
+ // src/swap/offchain.ts
1721
+ var MeshSwapBlueprint = plutus_default6;
1722
+ var MeshSwapContract = class extends MeshTxInitiator {
1723
+ scriptCbor = (0, import_core_csl7.applyParamsToScript)(plutus_default6.validators[0].compiledCode, []);
1724
+ scriptAddress;
1725
+ constructor(inputs) {
1726
+ super(inputs);
1727
+ this.scriptAddress = (0, import_core6.serializePlutusScript)(
1728
+ { code: this.scriptCbor, version: "V2" },
1729
+ void 0,
1730
+ 0
1731
+ ).address;
1732
+ }
1733
+ initiateSwap = async (toProvide, toReceive) => {
1734
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1735
+ const { pubKeyHash, stakeCredentialHash } = (0, import_core6.deserializeAddress)(walletAddress);
1736
+ const swapDatum = (0, import_common11.conStr0)([
1737
+ (0, import_common11.pubKeyAddress)(pubKeyHash, stakeCredentialHash),
1738
+ (0, import_common11.value)(toProvide),
1739
+ (0, import_common11.value)(toReceive)
1740
+ ]);
1741
+ await this.mesh.txOut(this.scriptAddress, toProvide).txOutInlineDatumValue(swapDatum, "JSON").changeAddress(walletAddress).txInCollateral(
1742
+ collateral.input.txHash,
1743
+ collateral.input.outputIndex,
1744
+ collateral.output.amount,
1745
+ collateral.output.address
1746
+ ).selectUtxosFrom(utxos).complete();
1747
+ return this.mesh.txHex;
1748
+ };
1749
+ acceptSwap = async (swapUtxo) => {
1750
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1751
+ const inlineDatum = (0, import_core6.deserializeDatum)(
1752
+ swapUtxo.output.plutusData
1753
+ );
1754
+ const initiatorAddress = (0, import_core6.serializeAddressObj)(inlineDatum.fields[0]);
1755
+ const initiatorToReceive = inlineDatum.fields[2];
1756
+ await this.mesh.spendingPlutusScriptV2().txIn(
1757
+ swapUtxo.input.txHash,
1758
+ swapUtxo.input.outputIndex,
1759
+ swapUtxo.output.amount,
1760
+ swapUtxo.output.address
1761
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common11.mConStr1)([])).txInScript(this.scriptCbor).txOut(initiatorAddress, import_common11.MeshValue.fromValue(initiatorToReceive).toAssets()).changeAddress(walletAddress).txInCollateral(
1762
+ collateral.input.txHash,
1763
+ collateral.input.outputIndex,
1764
+ collateral.output.amount,
1765
+ collateral.output.address
1766
+ ).selectUtxosFrom(utxos).complete();
1767
+ return this.mesh.txHex;
1768
+ };
1769
+ cancelSwap = async (swapUtxo) => {
1770
+ const { utxos, walletAddress, collateral } = await this.getWalletInfoForTx();
1771
+ const inlineDatum = (0, import_core6.deserializeDatum)(
1772
+ swapUtxo.output.plutusData
1773
+ );
1774
+ const initiatorAddress = (0, import_core6.serializeAddressObj)(inlineDatum.fields[0]);
1775
+ await this.mesh.spendingPlutusScriptV2().txIn(
1776
+ swapUtxo.input.txHash,
1777
+ swapUtxo.input.outputIndex,
1778
+ swapUtxo.output.amount,
1779
+ swapUtxo.output.address
1780
+ ).spendingReferenceTxInInlineDatumPresent().spendingReferenceTxInRedeemerValue((0, import_common11.mConStr0)([])).txInScript(this.scriptCbor).changeAddress(walletAddress).txInCollateral(
1781
+ collateral.input.txHash,
1782
+ collateral.input.outputIndex,
1783
+ collateral.output.amount,
1784
+ collateral.output.address
1785
+ ).requiredSignerHash((0, import_core6.deserializeAddress)(initiatorAddress).pubKeyHash).selectUtxosFrom(utxos).complete();
1786
+ return this.mesh.txHex;
1787
+ };
1788
+ getUtxoByTxHash = async (txHash) => {
1789
+ return await this._getUtxoByTxHash(txHash, this.scriptCbor);
1790
+ };
1791
+ };
1792
+ // Annotate the CommonJS export names for ESM import in node:
1793
+ 0 && (module.exports = {
1794
+ MeshEscrowBlueprint,
1795
+ MeshEscrowContract,
1796
+ MeshGiftCardBlueprint,
1797
+ MeshGiftCardContract,
1798
+ MeshMarketplaceBlueprint,
1799
+ MeshMarketplaceContract,
1800
+ MeshPaymentSplitterBlueprint,
1801
+ MeshPaymentSplitterContract,
1802
+ MeshSwapBlueprint,
1803
+ MeshSwapContract,
1804
+ MeshVestingBlueprint,
1805
+ MeshVestingContract,
1806
+ activeEscrowDatum,
1807
+ initiateEscrowDatum,
1808
+ marketplaceDatum,
1809
+ recipientDepositRedeemer
1810
+ });