@meshsdk/contract 1.6.0-alpha.21 → 1.6.2

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.
Files changed (79) hide show
  1. package/dist/index.cjs +37 -0
  2. package/dist/{index.d.mts → index.d.cts} +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +28 -1803
  5. package/package.json +30 -14
  6. package/.turbo/turbo-build$colon$docs.log +0 -8
  7. package/.turbo/turbo-build$colon$mesh.log +0 -19
  8. package/dist/index.mjs +0 -1834
  9. package/src/common.ts +0 -186
  10. package/src/coupon-bond-guaranteed/aiken-workspace/readme.md +0 -0
  11. package/src/coupon-bond-guaranteed/offchain.ts +0 -3
  12. package/src/coupon-bond-guaranteed/readme.md +0 -3
  13. package/src/escrow/aiken-workspace/aiken.lock +0 -26
  14. package/src/escrow/aiken-workspace/aiken.toml +0 -19
  15. package/src/escrow/aiken-workspace/lib/escrow/types.ak +0 -21
  16. package/src/escrow/aiken-workspace/lib/escrow/validators/escrow.ak +0 -122
  17. package/src/escrow/aiken-workspace/plutus.json +0 -238
  18. package/src/escrow/aiken-workspace/readme.md +0 -55
  19. package/src/escrow/aiken-workspace/validators/escrow.ak +0 -9
  20. package/src/escrow/aiken-workspace/validators/tests/escrow.ak +0 -462
  21. package/src/escrow/index.ts +0 -1
  22. package/src/escrow/offchain.ts +0 -254
  23. package/src/escrow/readme.md +0 -38
  24. package/src/giftcard/aiken-workspace/aiken.lock +0 -26
  25. package/src/giftcard/aiken-workspace/aiken.toml +0 -19
  26. package/src/giftcard/aiken-workspace/plutus.json +0 -138
  27. package/src/giftcard/aiken-workspace/readme.md +0 -55
  28. package/src/giftcard/aiken-workspace/validators/oneshot.ak +0 -173
  29. package/src/giftcard/index.ts +0 -1
  30. package/src/giftcard/offchain.ts +0 -184
  31. package/src/giftcard/readme.md +0 -36
  32. package/src/hello-world/aiken-workspace/README.md +0 -19
  33. package/src/hello-world/aiken-workspace/aiken.lock +0 -15
  34. package/src/hello-world/aiken-workspace/aiken.toml +0 -14
  35. package/src/hello-world/aiken-workspace/contract.md +0 -27
  36. package/src/hello-world/aiken-workspace/plutus.json +0 -69
  37. package/src/hello-world/aiken-workspace/validators/hello_world.ak +0 -24
  38. package/src/hello-world/index.ts +0 -1
  39. package/src/hello-world/offchain.ts +0 -24
  40. package/src/hello-world/readme.md +0 -1
  41. package/src/index.ts +0 -6
  42. package/src/marketplace/aiken-workspace/aiken.lock +0 -26
  43. package/src/marketplace/aiken-workspace/aiken.toml +0 -19
  44. package/src/marketplace/aiken-workspace/lib/marketplace/types.ak +0 -15
  45. package/src/marketplace/aiken-workspace/lib/marketplace/validators/marketplace.ak +0 -52
  46. package/src/marketplace/aiken-workspace/plutus.json +0 -204
  47. package/src/marketplace/aiken-workspace/readme.md +0 -55
  48. package/src/marketplace/aiken-workspace/validators/marketplace.ak +0 -14
  49. package/src/marketplace/aiken-workspace/validators/tests/marketplace.ak +0 -218
  50. package/src/marketplace/index.ts +0 -1
  51. package/src/marketplace/offchain.ts +0 -248
  52. package/src/marketplace/readme.md +0 -45
  53. package/src/payment-splitter/aiken-workspace/aiken.lock +0 -15
  54. package/src/payment-splitter/aiken-workspace/aiken.toml +0 -14
  55. package/src/payment-splitter/aiken-workspace/plutus.json +0 -83
  56. package/src/payment-splitter/aiken-workspace/validators/payment-splitter.ak +0 -329
  57. package/src/payment-splitter/index.ts +0 -1
  58. package/src/payment-splitter/offchain.ts +0 -143
  59. package/src/payment-splitter/readme.md +0 -100
  60. package/src/swap/aiken-workspace/aiken.lock +0 -26
  61. package/src/swap/aiken-workspace/aiken.toml +0 -19
  62. package/src/swap/aiken-workspace/plutus.json +0 -208
  63. package/src/swap/aiken-workspace/readme.md +0 -55
  64. package/src/swap/aiken-workspace/validators/swap.ak +0 -188
  65. package/src/swap/index.ts +0 -1
  66. package/src/swap/offchain.ts +0 -139
  67. package/src/swap/readme.md +0 -35
  68. package/src/vesting/aiken-workspace/README.md +0 -24
  69. package/src/vesting/aiken-workspace/aiken.lock +0 -26
  70. package/src/vesting/aiken-workspace/aiken.toml +0 -19
  71. package/src/vesting/aiken-workspace/lib/vesting/types.ak +0 -8
  72. package/src/vesting/aiken-workspace/lib/vesting/validators/vesting.ak +0 -19
  73. package/src/vesting/aiken-workspace/plutus.json +0 -67
  74. package/src/vesting/aiken-workspace/validators/tests/vesting.ak +0 -108
  75. package/src/vesting/aiken-workspace/validators/vesting.ak +0 -9
  76. package/src/vesting/index.ts +0 -1
  77. package/src/vesting/offchain.ts +0 -117
  78. package/src/vesting/readme.md +0 -36
  79. package/tsconfig.json +0 -5
@@ -1,248 +0,0 @@
1
- import {
2
- ConStr0,
3
- conStr0,
4
- CurrencySymbol,
5
- currencySymbol,
6
- Integer,
7
- integer,
8
- mConStr0,
9
- mConStr1,
10
- parseAssetUnit,
11
- PubKeyAddress,
12
- pubKeyAddress,
13
- TokenName,
14
- tokenName,
15
- } from "@meshsdk/common";
16
- import {
17
- deserializeAddress,
18
- deserializeDatum,
19
- Quantity,
20
- serializeAddressObj,
21
- serializePlutusScript,
22
- Unit,
23
- UTxO,
24
- } from "@meshsdk/core";
25
- import { applyParamsToScript } from "@meshsdk/core-csl";
26
- import { keepRelevant, largestFirst } from "@meshsdk/transaction";
27
-
28
- import { MeshTxInitiator, MeshTxInitiatorInput } from "../common";
29
- import blueprint from "./aiken-workspace/plutus.json";
30
-
31
- export const MeshMarketplaceBlueprint = blueprint;
32
-
33
- export type MarketplaceDatum = ConStr0<
34
- [PubKeyAddress, Integer, CurrencySymbol, TokenName]
35
- >;
36
- export const marketplaceDatum = (
37
- sellerAddress: string,
38
- lovelaceFee: number,
39
- assetHex: string,
40
- ): MarketplaceDatum => {
41
- const { pubKeyHash, stakeCredentialHash } = deserializeAddress(sellerAddress);
42
- const { policyId, assetName } = parseAssetUnit(assetHex);
43
- return conStr0([
44
- pubKeyAddress(pubKeyHash, stakeCredentialHash),
45
- integer(lovelaceFee),
46
- currencySymbol(policyId),
47
- tokenName(assetName),
48
- ]);
49
- };
50
-
51
- export class MeshMarketplaceContract extends MeshTxInitiator {
52
- ownerAddress: string;
53
- feePercentageBasisPoint: number;
54
- scriptCbor: string;
55
-
56
- constructor(
57
- inputs: MeshTxInitiatorInput,
58
- ownerAddress: string,
59
- feePercentageBasisPoint: number,
60
- ) {
61
- super(inputs);
62
- this.ownerAddress = ownerAddress;
63
- this.feePercentageBasisPoint = feePercentageBasisPoint;
64
- const { pubKeyHash, stakeCredentialHash } =
65
- deserializeAddress(ownerAddress);
66
- this.scriptCbor = applyParamsToScript(
67
- blueprint.validators[0]!.compiledCode,
68
- [
69
- pubKeyAddress(pubKeyHash, stakeCredentialHash),
70
- integer(feePercentageBasisPoint),
71
- ],
72
- "JSON",
73
- );
74
- }
75
-
76
- listAsset = async (asset: string, price: number) => {
77
- const { utxos, walletAddress } = await this.getWalletInfoForTx();
78
-
79
- const assetMap = new Map<Unit, Quantity>();
80
- assetMap.set(asset, "1");
81
- const selectedUtxos = keepRelevant(assetMap, utxos);
82
-
83
- const { address: scriptAddr } = serializePlutusScript(
84
- { code: this.scriptCbor, version: "V2" },
85
- undefined,
86
- this.networkId,
87
- );
88
-
89
- const tokenForSale = [{ unit: asset, quantity: "1" }];
90
- const outputDatum = marketplaceDatum(walletAddress, price, asset);
91
-
92
- await this.mesh
93
- .txOut(scriptAddr, tokenForSale)
94
- .txOutInlineDatumValue(outputDatum, "JSON")
95
- .changeAddress(walletAddress)
96
- .selectUtxosFrom(selectedUtxos)
97
- .complete();
98
-
99
- return this.mesh.txHex;
100
- };
101
-
102
- delistAsset = async (marketplaceUtxo: UTxO) => {
103
- const { utxos, walletAddress, collateral } =
104
- await this.getWalletInfoForTx();
105
-
106
- await this.mesh
107
- .spendingPlutusScriptV2()
108
- .txIn(
109
- marketplaceUtxo.input.txHash,
110
- marketplaceUtxo.input.outputIndex,
111
- marketplaceUtxo.output.amount,
112
- marketplaceUtxo.output.address,
113
- )
114
- .spendingReferenceTxInInlineDatumPresent()
115
- .spendingReferenceTxInRedeemerValue(mConStr1([]))
116
- .txInScript(this.scriptCbor)
117
- .changeAddress(walletAddress)
118
- .requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash)
119
- .txInCollateral(
120
- collateral.input.txHash,
121
- collateral.input.outputIndex,
122
- collateral.output.amount,
123
- collateral.output.address,
124
- )
125
- .selectUtxosFrom(utxos)
126
- .complete();
127
-
128
- return this.mesh.txHex;
129
- };
130
-
131
- purchaseAsset = async (marketplaceUtxo: UTxO) => {
132
- const { utxos, walletAddress, collateral } =
133
- await this.getWalletInfoForTx();
134
-
135
- const inputDatum = deserializeDatum<MarketplaceDatum>(
136
- marketplaceUtxo.output.plutusData!,
137
- );
138
-
139
- const listingPrice = inputDatum.fields[1].int.toString();
140
- const selectedUtxos = largestFirst(listingPrice, utxos, true);
141
-
142
- const inputLovelace = marketplaceUtxo.output.amount.find(
143
- (a) => a.unit === "lovelace",
144
- )!.quantity;
145
-
146
- const tx = this.mesh
147
- .spendingPlutusScriptV2()
148
- .txIn(
149
- marketplaceUtxo.input.txHash,
150
- marketplaceUtxo.input.outputIndex,
151
- marketplaceUtxo.output.amount,
152
- marketplaceUtxo.output.address,
153
- )
154
- .spendingReferenceTxInInlineDatumPresent()
155
- .spendingReferenceTxInRedeemerValue(mConStr0([]))
156
- .txInScript(this.scriptCbor)
157
- .changeAddress(walletAddress)
158
- .txInCollateral(
159
- collateral.input.txHash,
160
- collateral.input.outputIndex,
161
- collateral.output.amount,
162
- collateral.output.address,
163
- )
164
- .selectUtxosFrom(selectedUtxos);
165
-
166
- let ownerToReceiveLovelace =
167
- ((inputDatum.fields[1].int as number) * this.feePercentageBasisPoint) /
168
- 10000;
169
- if (this.feePercentageBasisPoint > 0 && ownerToReceiveLovelace < 1000000) {
170
- ownerToReceiveLovelace = 1000000;
171
- }
172
-
173
- if (ownerToReceiveLovelace > 0) {
174
- const ownerAddress = this.ownerAddress;
175
- const ownerToReceive = [
176
- {
177
- unit: "lovelace",
178
- quantity: Math.ceil(ownerToReceiveLovelace).toString(),
179
- },
180
- ];
181
- tx.txOut(ownerAddress, ownerToReceive);
182
- }
183
-
184
- const sellerToReceiveLovelace =
185
- (inputDatum.fields[1].int as number) + Number(inputLovelace);
186
-
187
- if (sellerToReceiveLovelace > 0) {
188
- const sellerAddress = serializeAddressObj(inputDatum.fields[0]);
189
- const sellerToReceive = [
190
- {
191
- unit: "lovelace",
192
- quantity: sellerToReceiveLovelace.toString(),
193
- },
194
- ];
195
- tx.txOut(sellerAddress, sellerToReceive);
196
- }
197
- await tx.complete();
198
-
199
- return this.mesh.txHex;
200
- };
201
-
202
- relistAsset = async (marketplaceUtxo: UTxO, newPrice: number) => {
203
- const { utxos, walletAddress, collateral } =
204
- await this.getWalletInfoForTx();
205
- const inputAsset = marketplaceUtxo.output.amount.find(
206
- (a) => a.unit !== "lovelace",
207
- )!.unit;
208
-
209
- const tokenForSale = [{ unit: inputAsset, quantity: "1" }];
210
- const outputDatum = marketplaceDatum(walletAddress, newPrice, inputAsset);
211
-
212
- const { address: scriptAddr } = serializePlutusScript(
213
- { code: this.scriptCbor, version: "V2" },
214
- undefined,
215
- this.networkId,
216
- );
217
-
218
- await this.mesh
219
- .spendingPlutusScriptV2()
220
- .txIn(
221
- marketplaceUtxo.input.txHash,
222
- marketplaceUtxo.input.outputIndex,
223
- marketplaceUtxo.output.amount,
224
- marketplaceUtxo.output.address,
225
- )
226
- .spendingReferenceTxInInlineDatumPresent()
227
- .spendingReferenceTxInRedeemerValue(mConStr1([]))
228
- .txInScript(this.scriptCbor)
229
- .txOut(scriptAddr, tokenForSale)
230
- .txOutInlineDatumValue(outputDatum, "JSON")
231
- .changeAddress(walletAddress)
232
- .requiredSignerHash(deserializeAddress(walletAddress).pubKeyHash)
233
- .txInCollateral(
234
- collateral.input.txHash,
235
- collateral.input.outputIndex,
236
- collateral.output.amount,
237
- collateral.output.address,
238
- )
239
- .selectUtxosFrom(utxos)
240
- .complete();
241
-
242
- return this.mesh.txHex;
243
- };
244
-
245
- getUtxoByTxHash = async (txHash: string): Promise<UTxO | undefined> => {
246
- return await this._getUtxoByTxHash(this.scriptCbor, txHash);
247
- };
248
- }
@@ -1,45 +0,0 @@
1
- # Marketplace Contract
2
-
3
- This marketplace allows anyone to buy and sell native assets such as NFTs.
4
-
5
- [Demo](https://meshjs.dev/smart-contracts/marketplace)
6
-
7
- The marketplace smart contract allows users to buy and sell NFTs. A seller list an NFT for sales by specifying a certain price, and anyone can buy it by paying the demanded price.
8
-
9
- There are 4 actions (or endpoints) available to interact with this smart contract:
10
-
11
- - list asset
12
- - buy asset
13
- - updating listing
14
- - cancel listing
15
-
16
- ## Initialize the Marketplace
17
-
18
- Utilizing the Marketplace contract requires a blockchain provider and a connected browser wallet. Here is an example how we can initialize the Marketplace.
19
-
20
- ```
21
- import { MeshMarketplaceContract } from '@meshsdk/contracts';
22
- import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
23
-
24
- const blockchainProvider = new BlockfrostProvider(APIKEY);
25
-
26
- const meshTxBuilder = new MeshTxBuilder({
27
- fetcher: blockchainProvider,
28
- submitter: blockchainProvider,
29
- });
30
-
31
- const contract = new MeshMarketplaceContract(
32
- {
33
- mesh: meshTxBuilder,
34
- fetcher: blockchainProvider,
35
- wallet: wallet,
36
- networkId: 0,
37
- },
38
- 'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv06fwlvuacpyv59g3a3w2fhk7daa8aepvacnpamyhyyxrgnscrfpsa',
39
- 200
40
- );
41
- ```
42
-
43
- To initialize the Marketplace, we import the MeshMarketplaceContract. The first JSON object is the inputs for the MeshTxInitiatorInput, this requires a MeshTxBuilder, a Provider, a Wallet, and define the network ID.
44
-
45
- Second and third parameters are the ownerAddress and feePercentageBasisPoint. The ownerAddress is the address of the marketplace owner which will receive the marketplace fee. The feePercentageBasisPoint is the percentage of the sale price that the marketplace owner will take. The fee numerator is in the order of hundreds, for example 200 implies a fee of 2%.
@@ -1,15 +0,0 @@
1
- # This file was generated by Aiken
2
- # You typically do not need to edit this file
3
-
4
- [[requirements]]
5
- name = "aiken-lang/stdlib"
6
- version = "1.9.0"
7
- source = "github"
8
-
9
- [[packages]]
10
- name = "aiken-lang/stdlib"
11
- version = "1.9.0"
12
- requirements = []
13
- source = "github"
14
-
15
- [etags]
@@ -1,14 +0,0 @@
1
- name = "fabianbormann/payment-splitter"
2
- version = "0.1.0"
3
- license = "Apache-2.0"
4
- description = "Aiken contracts for project 'fabianbormann/payment-splitter'"
5
-
6
- [repository]
7
- user = "fabianbormann"
8
- project = "payment-splitter"
9
- platform = "github"
10
-
11
- [[dependencies]]
12
- name = "aiken-lang/stdlib"
13
- version = "1.9.0"
14
- source = "github"
@@ -1,83 +0,0 @@
1
- {
2
- "preamble": {
3
- "title": "fabianbormann/payment-splitter",
4
- "description": "Aiken contracts for project 'fabianbormann/payment-splitter'",
5
- "version": "0.1.0",
6
- "plutusVersion": "v2",
7
- "compiler": {
8
- "name": "Aiken",
9
- "version": "v1.0.29-alpha+unknown"
10
- },
11
- "license": "Apache-2.0"
12
- },
13
- "validators": [
14
- {
15
- "title": "payment_splitter.payout",
16
- "datum": {
17
- "title": "_datum",
18
- "schema": {
19
- "$ref": "#/definitions/payment_splitter~1Datum"
20
- }
21
- },
22
- "redeemer": {
23
- "title": "_redeemer",
24
- "schema": {
25
- "$ref": "#/definitions/payment_splitter~1Redeemer"
26
- }
27
- },
28
- "parameters": [
29
- {
30
- "title": "scriptHashes",
31
- "schema": {
32
- "$ref": "#/definitions/List$ByteArray"
33
- }
34
- }
35
- ],
36
- "compiledCode": "5903a5010000323232323232322322322322533300832323232323232323232323253330143375e6e9cccc8c0040048894ccc06800440084ccc00c00cc8c8cc004004010894ccc07400452f5c026464a66603866ebc00801440044cc080008cc010010004c084008c07c004c070004c074004cc8c004004894ccc06400452f5c026466036002660060066600e603a004466603066ebc00400928251301b001323300100100722533301900114bd7009980d1806180c1baa300c3018375460360026600400460380020169801018000100114a0646600200200444a66603000229444c94ccc058cdc39bad301b00233005533301900414c0103d87a80001300e3301a301b0044bd70240002660060060022940c06c004c8cc004004028894ccc05c00452f5c02660306ea0c8c8c8c8c8c94ccc068cdc424000002266e04008cdc08009802005880119980119804806919baf3010301c3754602060386ea8c014c070dd5000803240004466e00004c014dd59803180e9baa3006301d375400466600266010014466ebcc03cc06cdd51807980d9baa0010054800088cdc000098021bab3005301c3754004444646600200200844a66603e0022008266006604200266004004604400246600c64a66603066e1d200230193754002298103d87a8000132330010013756603c60366ea8008894ccc074004530103d87a8000132323232533301e33722911000021533301e3371e9101000021301633022375000297ae014c0103d87a8000133006006003375a603e0066eb8c074008c084008c07c004c8cc004004008894ccc0700045300103d87a8000132323232533301d33722911000021533301d3371e9101000021301533021374c00297ae014c0103d87a80001330060060033756603c0066eb8c070008c080008c07800520002301b301c001301900133002002301a0012253330133370e9001180a1baa00210011375a6030602a6ea800888c8cc00400400c894ccc05c00452f5c026464a66602c600a00426603400466008008002266008008002603600460320026eacc050c054008dd61809800980998098011bac3011001300d37546002601a6ea80108c040004c8cc004004020894ccc03800452f5c026601e60066601e602000297ae0330020023011001374a90000a4c26caca66600c66e1d20003007375400226464a666016601c0042930b1bae300c001300837540022ca66600866e1d20003005375400226464a66601260180042930b1bae300a001300637540022c6eb00055cd2ab9d5573caae7d5d02ba157441",
37
- "hash": "0776032753d2900f7c1e933af4108c53851e10ca95fa10e34af90277"
38
- }
39
- ],
40
- "definitions": {
41
- "ByteArray": {
42
- "dataType": "bytes"
43
- },
44
- "List$ByteArray": {
45
- "dataType": "list",
46
- "items": {
47
- "$ref": "#/definitions/ByteArray"
48
- }
49
- },
50
- "payment_splitter/Datum": {
51
- "title": "Datum",
52
- "anyOf": [
53
- {
54
- "title": "Datum",
55
- "dataType": "constructor",
56
- "index": 0,
57
- "fields": [
58
- {
59
- "title": "owner",
60
- "$ref": "#/definitions/ByteArray"
61
- }
62
- ]
63
- }
64
- ]
65
- },
66
- "payment_splitter/Redeemer": {
67
- "title": "Redeemer",
68
- "anyOf": [
69
- {
70
- "title": "Redeemer",
71
- "dataType": "constructor",
72
- "index": 0,
73
- "fields": [
74
- {
75
- "title": "message",
76
- "$ref": "#/definitions/ByteArray"
77
- }
78
- ]
79
- }
80
- ]
81
- }
82
- }
83
- }