diff --git a/package.json b/package.json index fdc6b5a62..19b79b5cb 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ "lint:module": "lerna exec --scope @meshsdk/core \"yarn eslint --fix\"", "lint": "yarn lint:module && yarn lint:demo && yarn lint:docs" }, + "dependencies": { + "@meshsdk/common": "1.0.0-alpha.7" + }, "devDependencies": { "@types/jest": "28.1.6", "@types/node": "18.6.1", diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 071034b38..70f4d88fd 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -37,6 +37,7 @@ "@meshsdk/core": "1.5.16" }, "dependencies": { + "@harmoniclabs/plu-ts": "0.2.2", "@meshsdk/mesh-csl": "^0.0.4" } } \ No newline at end of file diff --git a/packages/contracts/src/common.ts b/packages/contracts/src/common.ts index 8b9545d8b..1416ccc1a 100644 --- a/packages/contracts/src/common.ts +++ b/packages/contracts/src/common.ts @@ -1,10 +1,10 @@ import { MeshTxBuilder, IFetcher, - UTxO, BrowserWallet, MeshWallet, } from '@meshsdk/core'; +import { UTxO } from '@meshsdk/common'; import { v2ScriptToBech32 } from '@meshsdk/mesh-csl'; export type MeshTxInitiatorInput = { diff --git a/packages/contracts/src/escrow/offchain.ts b/packages/contracts/src/escrow/offchain.ts index 584adfa81..ba89d34b1 100644 --- a/packages/contracts/src/escrow/offchain.ts +++ b/packages/contracts/src/escrow/offchain.ts @@ -18,7 +18,7 @@ import { mConStr2, } from '@meshsdk/mesh-csl'; import blueprint from './aiken-workspace/plutus.json'; -import { Asset, UTxO, mergeAssets } from '@meshsdk/core'; +import { Asset, UTxO, mergeAssets } from '@meshsdk/common'; export type InitiationDatum = ConStr0<[PubKeyAddress, Value]>; export const initiateEscrowDatum = ( @@ -71,7 +71,7 @@ export class MeshEscrowContract extends MeshTxInitiator { await this.mesh .txOut(scriptAddr, escrowAmount) .txOutInlineDatumValue( - initiateEscrowDatum(walletAddress, escrowAmount), + initiateEscrowDatum(walletAddress, escrowAmount) as any, 'JSON' ) .changeAddress(walletAddress) @@ -169,7 +169,7 @@ export class MeshEscrowContract extends MeshTxInitiator { ) .spendingReferenceTxInInlineDatumPresent() .txInRedeemerValue( - recipientDepositRedeemer(walletAddress, depositAmount), + recipientDepositRedeemer(walletAddress, depositAmount) as any, { mem: 7_000_000, steps: 3_000_000_000, @@ -178,7 +178,7 @@ export class MeshEscrowContract extends MeshTxInitiator { ) .txInScript(this.scriptCbor) .txOut(scriptAddr, escrowAmount) - .txOutInlineDatumValue(outputDatum, 'JSON') + .txOutInlineDatumValue(outputDatum as any, 'JSON') .changeAddress(walletAddress) .txInCollateral( collateral.input.txHash, diff --git a/packages/contracts/src/giftcard/offchain.ts b/packages/contracts/src/giftcard/offchain.ts index d5a7b7dcc..0f4dafa6d 100644 --- a/packages/contracts/src/giftcard/offchain.ts +++ b/packages/contracts/src/giftcard/offchain.ts @@ -14,7 +14,7 @@ import { mConStr1, } from '@meshsdk/mesh-csl'; import blueprint from './aiken-workspace/plutus.json'; -import { Asset, UTxO } from '@meshsdk/core'; +import { Asset, UTxO } from '@meshsdk/common'; export class MeshGiftCardContract extends MeshTxInitiator { tokenNameHex: string = ''; diff --git a/packages/contracts/src/marketplace/basic.service.ts b/packages/contracts/src/marketplace/basic.service.ts new file mode 100644 index 000000000..25c1d0834 --- /dev/null +++ b/packages/contracts/src/marketplace/basic.service.ts @@ -0,0 +1,266 @@ +import { + IFetcher, + IInitiator, + ISigner, + ISubmitter, + parseAssetUnit, + resolveDataHash, + resolveEpochNo, + resolvePaymentKeyHash, + resolvePlutusScriptAddress, + Transaction, +} from '@meshsdk/core'; +import type { Network, PlutusScript, UTxO } from '@meshsdk/common'; +import { buildPlutusScript, OwnerAddress } from './contract'; + +export class BasicMarketplace { + private _fetcher: IFetcher; + private _initiator: IInitiator; + private _network: Network; + private _owner: string; + private _percentage: number; + private _script: PlutusScript; + private _signer: ISigner; + private _submitter: ISubmitter; + + constructor(options = {} as CreateMarketplaceOptions) { + this._fetcher = options.fetcher; + this._initiator = options.initiator; + this._network = options.network; + this._owner = options.owner; + this._percentage = options.percentage; + this._script = buildPlutusScript(options.owner, options.percentage); + this._signer = options.signer; + this._submitter = options.submitter; + } + + async delistAsset(address: string, asset: string, price: number) { + const { policyId, assetName } = parseAssetUnit(asset); + const tx = await this.buildTx(); + + const datum = { + alternative: 0, + fields: [resolvePaymentKeyHash(address), price, policyId, assetName], + }; + + const redeemer = { + data: { + alternative: 1, + fields: [], + }, + }; + + const assetUTxO = await this.findUTxO( + resolvePlutusScriptAddress( + this._script, + this._network === 'mainnet' ? 1 : 0 + ), + asset, + resolveDataHash(datum) + ); + + tx.redeemValue({ + value: assetUTxO, + script: this._script, + datum, + redeemer, + }) + .sendValue(address, assetUTxO) + .setRequiredSigners([address]); + + const unsignedTx = await tx.build(); + const signedTx = await this._signer.signTx(unsignedTx, true); + return this._submitter.submitTx(signedTx); + } + + async listAsset(address: string, asset: string, price: number) { + const { policyId, assetName } = parseAssetUnit(asset); + const tx = await this.buildTx(); + + const datum = { + alternative: 0, + fields: [resolvePaymentKeyHash(address), price, policyId, assetName], + }; + + tx.sendAssets( + { + address: resolvePlutusScriptAddress( + this._script, + this._network === 'mainnet' ? 1 : 0 + ), + datum: { value: datum }, + }, + [ + { + unit: asset, + quantity: '1', + }, + ] + ); + + const unsignedTx = await tx.build(); + const signedTx = await this._signer.signTx(unsignedTx, false); + return this._submitter.submitTx(signedTx); + } + + async purchaseAsset(address: string, asset: string, price: number) { + const { policyId, assetName } = parseAssetUnit(asset); + const tx = await this.buildTx(); + + const datum = { + alternative: 0, + fields: [resolvePaymentKeyHash(address), price, policyId, assetName], + }; + + const redeemer = { + data: { + alternative: 0, + fields: [], + }, + }; + + const assetUTxO = await this.findUTxO( + resolvePlutusScriptAddress( + this._script, + this._network === 'mainnet' ? 1 : 0 + ), + asset, + resolveDataHash(datum) + ); + + const buyerAddress = await this._initiator.getUsedAddress(); + + const { marketFees } = this.splitAmount(price); + + tx.redeemValue({ + value: assetUTxO, + script: this._script, + datum, + redeemer, + }) + .sendValue(buyerAddress.to_bech32(), assetUTxO) + .sendLovelace(address, price.toString()) + .sendLovelace(this._owner, marketFees.toString()); + + const unsignedTx = await tx.build(); + const signedTx = await this._signer.signTx(unsignedTx, true); + return this._submitter.submitTx(signedTx); + } + + async relistAsset( + address: string, + asset: string, + oldPrice: number, + newPrice: number + ) { + const { policyId, assetName } = parseAssetUnit(asset); + const tx = await this.buildTx(); + + const datum = { + alternative: 0, + fields: [resolvePaymentKeyHash(address), oldPrice, policyId, assetName], + }; + + const redeemer = { + data: { + alternative: 1, + fields: [], + }, + }; + + const assetUTxO = await this.findUTxO( + resolvePlutusScriptAddress( + this._script, + this._network === 'mainnet' ? 1 : 0 + ), + asset, + resolveDataHash(datum) + ); + + tx.redeemValue({ + value: assetUTxO, + script: this._script, + datum, + redeemer, + }) + .sendAssets( + { + address: resolvePlutusScriptAddress( + this._script, + this._network === 'mainnet' ? 1 : 0 + ), + datum: { + value: { + alternative: 0, + fields: [ + resolvePaymentKeyHash(address), + newPrice, + policyId, + assetName, + ], + }, + }, + }, + [ + { + unit: asset, + quantity: '1', + }, + ] + ) + .setRequiredSigners([address]); + + const unsignedTx = await tx.build(); + const signedTx = await this._signer.signTx(unsignedTx, true); + return this._submitter.submitTx(signedTx); + } + + private async buildTx() { + const epoch = resolveEpochNo(this._network); + const parameters = await this._fetcher.fetchProtocolParameters(epoch); + + return new Transaction({ + initiator: this._initiator, + parameters, + }); + } + + private async findUTxO(address: string, assetId: string, dataHash: string) { + const utxos = await this._fetcher.fetchAddressUTxOs(address, assetId); + + if (utxos.length === 0) { + throw new Error(`No listing found for asset with Id: ${assetId}`); + } + + const utxo: UTxO | undefined = utxos.find( + (utxo) => utxo.output.dataHash === dataHash + ); + + if (utxo === undefined) { + throw new Error(`No listing found for asset with Hash: ${dataHash}`); + } + + return utxo; + } + + private splitAmount(price: number) { + const minFees = 1_000_000; + const marketFees = Math.max( + (this._percentage / 1_000_000) * price, + minFees + ); + const netPrice = price - marketFees; + + return { marketFees, netPrice }; + } +} + +type CreateMarketplaceOptions = { + percentage: number; + initiator: IInitiator; + submitter: ISubmitter; + owner: OwnerAddress; + fetcher: IFetcher; + network: Network; + signer: ISigner; +}; diff --git a/packages/contracts/src/marketplace/contract.ts b/packages/contracts/src/marketplace/contract.ts new file mode 100644 index 000000000..3c90e5c07 --- /dev/null +++ b/packages/contracts/src/marketplace/contract.ts @@ -0,0 +1,225 @@ +import { + Address, + bool, + compile, + int, + makeValidator, + PCurrencySymbol, + perror, + pfn, + phoist, + pInt, + pisEmpty, + plam, + plet, + pmatch, + PPubKeyHash, + PScriptContext, + pstruct, + PTokenName, + ptraceIfFalse, + PTxInInfo, + punConstrData, + Script, +} from '@harmoniclabs/plu-ts'; +import { PlutusScript } from '@meshsdk/common'; + +const NFTSale = pstruct({ + NFTSale: { + seller: PPubKeyHash.type, + price: int, + policy: PCurrencySymbol.type, + tokenName: PTokenName.type, + }, +}); + +const SaleAction = pstruct({ + Buy: {}, + Close: {}, +}); + +const feeDenominator = phoist(pInt(1_000_000)); + +const contract = pfn( + [ + PPubKeyHash.type, // owner + int, // feeNumerator + NFTSale.type, + SaleAction.type, + PScriptContext.type, + ], + bool +)((owner, feeNumerator, datum, action, ctx) => + ctx.extract('txInfo').in(({ txInfo }) => + datum.extract('seller', 'price', 'policy', 'tokenName').in((sale) => + plet( + plam( + PTxInInfo.type, + bool + )((_in) => + _in.extract('resolved').in(({ resolved }) => + resolved.extract('address').in( + ({ address }) => punConstrData.$(address as any).fst.eq(0) // MUST be the first constructor (PPubKeyHash) + ) + ) + ) + ).in((_) => + txInfo.extract('signatories', 'outputs', 'inputs').in((tx) => { + const nftSentToSigner = tx.outputs.some((_out) => + _out.extract('value', 'address').in((out) => { + const outToBuyer = plet(tx.signatories.head).in((buyer) => + out.address.extract('credential').in(({ credential }) => + pmatch(credential) + .onPPubKeyCredential((_) => + _.extract('pkh').in(({ pkh }) => pkh.eq(buyer)) + ) + ._((_) => perror(bool)) + ) + ); + + const valueIncludesNFT = out.value.some((entry) => + entry.fst + .eq(sale.policy) + .and( + plet(entry.snd).in((assets) => + assets.some((assetEntry) => + assetEntry.fst + .eq(sale.tokenName) + .and(assetEntry.snd.eq(1)) + ) + ) + ) + ); + + return ptraceIfFalse + .$('multiple signatories') + .$(pisEmpty.$(tx.signatories.tail)) + .and(ptraceIfFalse.$('outToBuyer').$(outToBuyer)) + .and(ptraceIfFalse.$('valueIncludesNFT').$(valueIncludesNFT)); + }) + ); + + const paidToSeller = tx.outputs.some((_out) => + _out.extract('value', 'address').in((out) => { + const outValueGtEqPrice = out.value.some((entry) => + entry.fst.eq('').and( + entry.snd.head.snd // assets // first asset (only on in ADA entry) // quantity + .gtEq(sale.price) + ) + ); + + const outToSeller = out.address + .extract('credential') + .in(({ credential }) => + pmatch(credential) + .onPPubKeyCredential((_) => + _.extract('pkh').in(({ pkh }) => pkh.eq(sale.seller)) + ) + ._((_) => perror(bool)) + ); + + return ptraceIfFalse + .$('outValueGtEqPrice') + .$(outValueGtEqPrice) + .and(ptraceIfFalse.$('outToSeller').$(outToSeller)); + }) + ); + + // const noInputScript = plam(list(PTxInInfo.type), bool) + // (inputs => + // inputs.every(isInputFromPubKeyHash) + // ) + + // prvent double spending attck + // const onlyScriptInputIsOwn = precursiveList(bool, PTxInInfo.type) + // .$(_self => pdelay(pBool(false))) // caseNil + // .$( + // pfn([ + // fn([list(PTxInInfo.type)], bool), + // PTxInInfo.type, + // list(PTxInInfo.type) + // ], bool) + // ((self, head, tail) => + // pif(bool).$(isInputFromPubKeyHash.$(head)) + // .then(self.$(tail) as any) + // .else( + // /* + // we could add a check for the input to be from this actual script + + // however since we are validating for the inputs to contain a single script input + // it implies that it has to be this one (since the validator is runnig) + // */ + // noInputScript.$(tail) + // ) + // ) + // ) + // .$(tx.inputs); + + const paidFee = tx.outputs.some((_out) => + _out.extract('address', 'value').in((out) => { + const goingToMarketplaceOwner = out.address + .extract('credential') + .in(({ credential: ownerCreds }) => + pmatch(ownerCreds) + .onPPubKeyCredential((_) => + _.extract('pkh').in(({ pkh }) => pkh.eq(owner)) + ) + ._((_) => perror(bool)) + ); + + const _paidFee = out.value.some((entry) => + entry.fst + .eq('') + .and( + entry.snd.head.snd.gtEq( + sale.price.mult(feeNumerator).div(feeDenominator) + ) + ) + ); + + return goingToMarketplaceOwner.and(_paidFee); + }) + ); + + return pmatch(action) + .onBuy((_) => + ptraceIfFalse + .$('nftSentToSigner') + .$(nftSentToSigner) + .and(ptraceIfFalse.$('paidToSeller').$(paidToSeller)) + // .and(ptraceIfFalse.$("onlyScriptInputIsOwn").$(onlyScriptInputIsOwn)) + .and(ptraceIfFalse.$('paidFee').$(paidFee)) + ) + .onClose((_) => tx.signatories.some(sale.seller.eqTerm)); + }) + ) + ) + ) +); + +/** + * > **NOTE** The fee numerator is in the order of millions + * > for example `3000` implies a fee of `3000/1_000_000` (or `0.003`) + * > which in a scale from `0` to `1` implies a fee of `0.3%` + */ +const compileMarketplace = (owner: OwnerAddress, percentage: number) => { + const appliedContract = contract + .$(PPubKeyHash.from(Address.fromString(owner).paymentCreds.hash.toBuffer())) + .$(pInt(percentage)); + + const untypedValidator = makeValidator(appliedContract); + return compile(untypedValidator); +}; + +export const buildPlutusScript = ( + owner: OwnerAddress, + percentage: number +): PlutusScript => ({ + version: 'V2' as const, + code: new Script( + 'PlutusScriptV2' as any, + compileMarketplace(owner, percentage) + ).cbor.toString(), +}); + +export type OwnerAddress = string; diff --git a/packages/contracts/src/marketplace/offchain.ts b/packages/contracts/src/marketplace/offchain.ts index 999c1e4b2..72e41afe7 100644 --- a/packages/contracts/src/marketplace/offchain.ts +++ b/packages/contracts/src/marketplace/offchain.ts @@ -19,14 +19,8 @@ import { mConStr0, } from '@meshsdk/mesh-csl'; import blueprint from './aiken-workspace/plutus.json'; -import { - Quantity, - UTxO, - Unit, - keepRelevant, - largestFirst, - parseAssetUnit, -} from '@meshsdk/core'; +import { keepRelevant, largestFirst, parseAssetUnit } from '@meshsdk/core'; +import { Quantity, UTxO, Unit } from '@meshsdk/common'; export type MarketplaceDatum = ConStr0< [PubKeyAddress, Integer, CurrencySymbol, TokenName] @@ -88,7 +82,7 @@ export class MeshMarketplaceContract extends MeshTxInitiator { await this.mesh .txOut(scriptAddr, tokenForSale) - .txOutInlineDatumValue(outputDatum, 'JSON') + .txOutInlineDatumValue(outputDatum as any, 'JSON') .changeAddress(walletAddress) .selectUtxosFrom(selectedUtxos) .complete(); @@ -225,7 +219,7 @@ export class MeshMarketplaceContract extends MeshTxInitiator { .spendingReferenceTxInRedeemerValue(mConStr1([])) .txInScript(this.scriptCbor) .txOut(scriptAddr, tokenForSale) - .txOutInlineDatumValue(outputDatum, 'JSON') + .txOutInlineDatumValue(outputDatum as any, 'JSON') .changeAddress(walletAddress) .requiredSignerHash(serializeBech32Address(walletAddress).pubKeyHash) .txInCollateral( diff --git a/packages/contracts/src/payment-splitter/offchain.ts b/packages/contracts/src/payment-splitter/offchain.ts index eb3cf98ae..9df79500e 100644 --- a/packages/contracts/src/payment-splitter/offchain.ts +++ b/packages/contracts/src/payment-splitter/offchain.ts @@ -11,6 +11,7 @@ import { list, } from '@meshsdk/mesh-csl'; import blueprint from './aiken-workspace/plutus.json'; +import { PlutusScript } from '@meshsdk/common'; export class MeshPaymentSplitterContract extends MeshTxInitiator { wrapPayees = (payees: string[]) => @@ -49,7 +50,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator { const { walletAddress } = await this.getWalletInfoForTx(); - const script = { + const script: PlutusScript = { code: this.scriptCbor(), version: 'V2', }; @@ -83,7 +84,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator { const { walletAddress, collateral } = await this.getWalletInfoForTx(); - const script = { + const script: PlutusScript = { code: this.scriptCbor(), version: 'V2', }; @@ -112,7 +113,7 @@ export class MeshPaymentSplitterContract extends MeshTxInitiator { value: utxo, script: script, datum: datum, - redeemer: redeemer, + redeemer: redeemer as any, // TODO: fix this cast any }); } } diff --git a/packages/contracts/src/vesting/offchain.ts b/packages/contracts/src/vesting/offchain.ts index 8f8378af1..ced218af2 100644 --- a/packages/contracts/src/vesting/offchain.ts +++ b/packages/contracts/src/vesting/offchain.ts @@ -12,7 +12,7 @@ import { parseDatumCbor, } from '@meshsdk/mesh-csl'; import blueprint from './aiken-workspace/plutus.json'; -import { Asset, UTxO } from '@meshsdk/core'; +import { Asset, UTxO } from '@meshsdk/common'; export type VestingDatum = ConStr0< [Integer, BuiltinByteString, BuiltinByteString] diff --git a/packages/core/_package.json b/packages/core/_package.json new file mode 100644 index 000000000..c100b408f --- /dev/null +++ b/packages/core/_package.json @@ -0,0 +1,31 @@ +{ + "name": "@meshsdk/core", + "description": "Rapidly build Web3 apps on the Cardano Blockchain.", + "homepage": "https://meshjs.dev", + "author": "MeshJS", + "version": "2.0.0", + "license": "Apache-2.0", + "type": "module", + "repository": { + "type": "git", + "url": "git+https://github.com/MeshJS/mesh.git" + }, + "bugs": { + "url": "https://github.com/MeshJS/mesh/issues" + }, + "keywords": [ + "blockchain", + "cardano", + "plutus" + ], + "scripts": {}, + "exports": { + ".": { + "import": "./dist/core.js", + "require": "./dist/core.cjs", + "types": "./dist/index.d.ts" + } + }, + "devDependencies": {}, + "dependencies": {} +} diff --git a/packages/core/readme.md b/packages/core/readme.md new file mode 100644 index 000000000..1a62c9af2 --- /dev/null +++ b/packages/core/readme.md @@ -0,0 +1,3 @@ +# meshjs + +This is the main package of meshjs, it contains a collection of TypeScript libraries for Interaction with the Cardano blockchain. diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/packages/demo/backend/support.ts b/packages/demo/backend/support.ts index 8bd7449ce..be7a3db65 100644 --- a/packages/demo/backend/support.ts +++ b/packages/demo/backend/support.ts @@ -1,5 +1,5 @@ import { post } from './'; -import type { UTxO } from '@meshsdk/core'; +import { UTxO } from '@meshsdk/common'; export async function createTransactionDonate( recipientAddress: string, diff --git a/packages/demo/components/common/fetchSelectAssets.tsx b/packages/demo/components/common/fetchSelectAssets.tsx index e47726724..0974a8e0b 100644 --- a/packages/demo/components/common/fetchSelectAssets.tsx +++ b/packages/demo/components/common/fetchSelectAssets.tsx @@ -1,4 +1,4 @@ -import type { AssetExtended } from '@meshsdk/core'; +import type { AssetExtended } from '@meshsdk/common'; import { useEffect, useState } from 'react'; import { useWallet } from '@meshsdk/react'; import Button from '../ui/button'; diff --git a/packages/demo/components/common/mintMeshToken.ts b/packages/demo/components/common/mintMeshToken.ts index b4f30114e..4f1a8210a 100644 --- a/packages/demo/components/common/mintMeshToken.ts +++ b/packages/demo/components/common/mintMeshToken.ts @@ -4,10 +4,14 @@ import { AppWallet, BlockfrostProvider, } from '@meshsdk/core'; -import type { AssetMetadata, Mint } from '@meshsdk/core'; +import type { AssetMetadata, Mint } from '@meshsdk/common'; import { demoMnemonic } from '../../configs/demo'; -export default async function mintMeshToken({setLoading, setResponse, wallet}) { +export default async function mintMeshToken({ + setLoading, + setResponse, + wallet, +}) { setLoading(true); try { const blockchainProvider = new BlockfrostProvider( @@ -54,4 +58,4 @@ export default async function mintMeshToken({setLoading, setResponse, wallet}) { setResponse(txHash); } catch (error) {} setLoading(false); -} \ No newline at end of file +} diff --git a/packages/demo/components/pages/apis/appwallet/signTx.tsx b/packages/demo/components/pages/apis/appwallet/signTx.tsx index 4e0fc9171..f1a0eabae 100644 --- a/packages/demo/components/pages/apis/appwallet/signTx.tsx +++ b/packages/demo/components/pages/apis/appwallet/signTx.tsx @@ -5,7 +5,7 @@ import SectionTwoCol from '../../../common/sectionTwoCol'; import RunDemoButton from '../../../common/runDemoButton'; import RunDemoResult from '../../../common/runDemoResult'; import { Transaction, ForgeScript } from '@meshsdk/core'; -import type { Mint, AssetMetadata } from '@meshsdk/core'; +import type { Mint, AssetMetadata } from '@meshsdk/common'; import useAppWallet from '../../../../contexts/appWallet'; import { demoAddresses } from '../../../../configs/demo'; import Input from '../../../ui/input'; diff --git a/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx b/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx index 46332757c..9162ff0b1 100644 --- a/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx +++ b/packages/demo/components/pages/apis/resolvers/resolveDataHash.tsx @@ -5,7 +5,7 @@ import SectionTwoCol from '../../../common/sectionTwoCol'; import RunDemoButton from '../../../common/runDemoButton'; import RunDemoResult from '../../../common/runDemoResult'; import { resolveDataHash } from '@meshsdk/core'; -import type { Data } from '@meshsdk/core'; +import type { Data } from '@meshsdk/common'; import Input from '../../../ui/input'; import Link from 'next/link'; diff --git a/packages/demo/components/pages/apis/resolvers/resolveNativeScriptHash.tsx b/packages/demo/components/pages/apis/resolvers/resolveNativeScriptHash.tsx index 897517a20..a010a5216 100644 --- a/packages/demo/components/pages/apis/resolvers/resolveNativeScriptHash.tsx +++ b/packages/demo/components/pages/apis/resolvers/resolveNativeScriptHash.tsx @@ -10,7 +10,7 @@ import { resolveSlotNo, } from '@meshsdk/core'; import Input from '../../../ui/input'; -import type { NativeScript } from '@meshsdk/core'; +import type { NativeScript } from '@meshsdk/common'; import { demoAddresses } from '../../../../configs/demo'; export default function ResolveNativeScriptHash() { diff --git a/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx index a499cf9f7..286f927df 100644 --- a/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx +++ b/packages/demo/components/pages/apis/resolvers/resolvePlutusScriptAddress.tsx @@ -6,7 +6,7 @@ import RunDemoButton from '../../../common/runDemoButton'; import RunDemoResult from '../../../common/runDemoResult'; import { resolvePlutusScriptAddress } from '@meshsdk/core'; import Input from '../../../ui/input'; -import type { PlutusScript } from '@meshsdk/core'; +import type { PlutusScript } from '@meshsdk/common'; export default function ResolvePlutusScriptAddress() { const [userinput, setUserinput] = useState(0); @@ -25,7 +25,6 @@ export default function ResolvePlutusScriptAddress() { } function Left(userinput, userinput2) { - let code = `import { resolvePlutusScriptAddress } from '@meshsdk/core';\n`; code += `import type { PlutusScript } from '@meshsdk/core';\n\n`; diff --git a/packages/demo/components/pages/apis/transaction/basic/getSize.tsx b/packages/demo/components/pages/apis/transaction/basic/getSize.tsx index 2d13b645c..1c8493ad2 100644 --- a/packages/demo/components/pages/apis/transaction/basic/getSize.tsx +++ b/packages/demo/components/pages/apis/transaction/basic/getSize.tsx @@ -12,10 +12,9 @@ import { AppWallet, Transaction, ForgeScript, - AssetMetadata, BlockfrostProvider, } from '@meshsdk/core'; -import type { Mint } from '@meshsdk/core'; +import type { AssetMetadata, Mint } from '@meshsdk/common'; import Textarea from '../../../../ui/textarea'; import Link from 'next/link'; @@ -192,7 +191,9 @@ function Right({ userInput, updateField }) { setResponseError(null); try { - const blockchainProvider = new BlockfrostProvider(process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!); + const blockchainProvider = new BlockfrostProvider( + process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD! + ); const wallet = new AppWallet({ networkId: 0, @@ -239,7 +240,7 @@ function Right({ userInput, updateField }) { // const unsignedTx = await tx.build(); // const signedTx = await wallet.signTx(unsignedTx); // const txHash = await wallet.submitTx(signedTx); - + // const size = tx.size; // console.log(11, size); // const fee = tx.fee; diff --git a/packages/demo/components/pages/apis/transaction/basic/sendAssets.tsx b/packages/demo/components/pages/apis/transaction/basic/sendAssets.tsx index b4df486d0..3a84b3b2b 100644 --- a/packages/demo/components/pages/apis/transaction/basic/sendAssets.tsx +++ b/packages/demo/components/pages/apis/transaction/basic/sendAssets.tsx @@ -12,7 +12,7 @@ import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid'; import { demoAddresses } from '../../../../../configs/demo'; import FetchSelectAssets from '../../../../common/fetchSelectAssets'; import { Transaction } from '@meshsdk/core'; -import type { Asset } from '@meshsdk/core'; +import type { Asset } from '@meshsdk/common'; export default function SendAssets() { const { wallet, connected } = useWallet(); diff --git a/packages/demo/components/pages/apis/transaction/minting/burning.tsx b/packages/demo/components/pages/apis/transaction/minting/burning.tsx index 730748609..ca455ffe0 100644 --- a/packages/demo/components/pages/apis/transaction/minting/burning.tsx +++ b/packages/demo/components/pages/apis/transaction/minting/burning.tsx @@ -8,7 +8,7 @@ import { useWallet } from '@meshsdk/react'; import ConnectCipWallet from '../../../../common/connectCipWallet'; import Input from '../../../../ui/input'; import { Transaction, ForgeScript } from '@meshsdk/core'; -import type { Asset, AssetExtended } from '@meshsdk/core'; +import type { Asset, AssetExtended } from '@meshsdk/common'; export default function Burning() { const { wallet, connected } = useWallet(); diff --git a/packages/demo/components/pages/apis/transaction/minting/minting.tsx b/packages/demo/components/pages/apis/transaction/minting/minting.tsx index 4dd638575..88029c706 100644 --- a/packages/demo/components/pages/apis/transaction/minting/minting.tsx +++ b/packages/demo/components/pages/apis/transaction/minting/minting.tsx @@ -10,8 +10,8 @@ import Input from '../../../../ui/input'; import Button from '../../../../ui/button'; import { PlusCircleIcon, TrashIcon } from '@heroicons/react/24/solid'; import { demoAddresses } from '../../../../../configs/demo'; -import { Transaction, ForgeScript, AssetMetadata } from '@meshsdk/core'; -import type { Mint } from '@meshsdk/core'; +import { Transaction, ForgeScript } from '@meshsdk/core'; +import type { AssetMetadata, Mint } from '@meshsdk/common'; import Textarea from '../../../../ui/textarea'; import Link from 'next/link'; import { resolveNativeScriptHash } from '@meshsdk/core'; diff --git a/packages/demo/components/pages/apis/transaction/minting/mintingNativeScript.tsx b/packages/demo/components/pages/apis/transaction/minting/mintingNativeScript.tsx index 47b570769..528e24d79 100644 --- a/packages/demo/components/pages/apis/transaction/minting/mintingNativeScript.tsx +++ b/packages/demo/components/pages/apis/transaction/minting/mintingNativeScript.tsx @@ -13,12 +13,11 @@ import { demoAddresses } from '../../../../../configs/demo'; import { Transaction, ForgeScript, - AssetMetadata, - NativeScript, - Mint, resolvePaymentKeyHash, resolveNativeScriptHash, } from '@meshsdk/core'; + +import { AssetMetadata, NativeScript, Mint } from '@meshsdk/common'; import Textarea from '../../../../ui/textarea'; import Link from 'next/link'; diff --git a/packages/demo/components/pages/apis/transaction/minting/mintingRoyaltyToken.tsx b/packages/demo/components/pages/apis/transaction/minting/mintingRoyaltyToken.tsx index 4464d9870..094933577 100644 --- a/packages/demo/components/pages/apis/transaction/minting/mintingRoyaltyToken.tsx +++ b/packages/demo/components/pages/apis/transaction/minting/mintingRoyaltyToken.tsx @@ -8,7 +8,8 @@ import { useWallet } from '@meshsdk/react'; import ConnectCipWallet from '../../../../common/connectCipWallet'; import Input from '../../../../ui/input'; import { demoAddresses } from '../../../../../configs/demo'; -import { Transaction, ForgeScript, Mint } from '@meshsdk/core'; +import { Transaction, ForgeScript } from '@meshsdk/core'; +import { Mint, AssetMetadata } from '@meshsdk/common'; export default function MintingRoyaltyToken() { const [rate, setRate] = useState('0.2'); @@ -97,7 +98,7 @@ function Right({ rate, setRate, addr, setAddr }) { const tx = new Transaction({ initiator: wallet }); - const _assetMetadata = { rate: rate, addr: addr }; + const _assetMetadata: AssetMetadata = { rate: rate, address: addr }; const asset: Mint = { assetName: '', assetQuantity: '1', diff --git a/packages/demo/components/pages/apis/transaction/smart-contract/datum.tsx b/packages/demo/components/pages/apis/transaction/smart-contract/datum.tsx index 0aa60f6e7..1f76de254 100644 --- a/packages/demo/components/pages/apis/transaction/smart-contract/datum.tsx +++ b/packages/demo/components/pages/apis/transaction/smart-contract/datum.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import Codeblock from '../../../../ui/codeblock'; import SectionTwoCol from '../../../../common/sectionTwoCol'; import { resolveDataHash } from '@meshsdk/core'; -import type { Data } from '@meshsdk/core'; +import type { Data } from '@meshsdk/common'; export default function DesignDatum() { return ( @@ -108,9 +108,9 @@ function Left({}) { return ( <>

- Mesh allows you to freely design the datum structure to suit - the plutus smart contract requirements. You can import the{' '} - Data type to help you design the datum. + Mesh allows you to freely design the datum structure to suit the plutus + smart contract requirements. You can import the Data type + to help you design the datum.

An array

- Or an array, where each item can be either a string, number, a list, or a map. + Or an array, where each item can be either a string, number, a list, or + a map.

A Map

diff --git a/packages/demo/components/pages/apis/transaction/smart-contract/lockAssets.tsx b/packages/demo/components/pages/apis/transaction/smart-contract/lockAssets.tsx index 9e89f6019..899a17145 100644 --- a/packages/demo/components/pages/apis/transaction/smart-contract/lockAssets.tsx +++ b/packages/demo/components/pages/apis/transaction/smart-contract/lockAssets.tsx @@ -7,7 +7,8 @@ import SectionTwoCol from '../../../../common/sectionTwoCol'; import { useWallet } from '@meshsdk/react'; import ConnectCipWallet from '../../../../common/connectCipWallet'; import Input from '../../../../ui/input'; -import { Transaction, Asset } from '@meshsdk/core'; +import { Transaction } from '@meshsdk/core'; +import { Asset } from '@meshsdk/common'; import FetchSelectAssets from '../../../../common/fetchSelectAssets'; import Link from 'next/link'; import useDemo from '../../../../../contexts/demo'; @@ -122,20 +123,22 @@ function Left({ userInput, inputDatum }) { return ( <>

- Assets may be reserved in a smart contract by "locking" them at the script's address. - The assets can only be subsequently unlocked when certain conditions - are met, for example, in the case of making a purchase in a marketplace contract. + Assets may be reserved in a smart contract by "locking" them at the + script's address. The assets can only be subsequently unlocked when + certain conditions are met, for example, in the case of making a + purchase in a marketplace contract.

In this demo, we will lock selected assets from your wallet in an - always succeed smart contract. Even though it is called "always succeed" - because there is no actual "validating" logic, unlocking the assets still - requires the correct datum to be supplied. Also note that in practice, multiple assets (both native - assets and lovelace) can be sent to the contract in a single transaction. + always succeed smart contract. Even though it is called + "always succeed" because there is no actual "validating" logic, + unlocking the assets still requires the correct datum to be supplied. + Also note that in practice, multiple assets (both native assets and + lovelace) can be sent to the contract in a single transaction.

- We need to supply the script address. Luckily Mesh has a handy function to "resolve" (work out) - the script address automatically using: {' '} + We need to supply the script address. Luckily Mesh has a handy function + to "resolve" (work out) the script address automatically using:{' '} Resolve Script Address {' '} @@ -146,9 +149,10 @@ function Left({ userInput, inputDatum }) {

To lock assets in this contract, here's the full code:

- If the transaction is successful, you would usually want to keep a record of the - asset's unit and the datum used in the - transaction, as this information is required to unlock the assets. + If the transaction is successful, you would usually want to keep a + record of the asset's unit and the datum used + in the transaction, as this information is required to unlock the + assets.

); diff --git a/packages/demo/components/pages/apis/transaction/smart-contract/plutus-minting.tsx b/packages/demo/components/pages/apis/transaction/smart-contract/plutus-minting.tsx index 534dd029c..9b3e75bc5 100644 --- a/packages/demo/components/pages/apis/transaction/smart-contract/plutus-minting.tsx +++ b/packages/demo/components/pages/apis/transaction/smart-contract/plutus-minting.tsx @@ -13,13 +13,8 @@ import { demoAddresses, demoPlutusMintingScript, } from '../../../../../configs/demo'; -import { - Transaction, - Mint, - Action, - PlutusScript, - AssetMetadata, -} from '@meshsdk/core'; +import { Transaction } from '@meshsdk/core'; +import { Mint, Action, PlutusScript, AssetMetadata } from '@meshsdk/common'; import Textarea from '../../../../ui/textarea'; import Link from 'next/link'; @@ -177,7 +172,8 @@ function Left({ userInput }) {

In this demo, we will use a Plutus script to mint tokens. This script is designed to always succeed, meaning that anyone can sign and mint tokens - with it, as there is no extra validation logic carried out by this script. + with it, as there is no extra validation logic carried out by this + script.

diff --git a/packages/demo/components/pages/contracts/coupon-bond-guaranteed/depositFund.tsx b/packages/demo/components/pages/contracts/coupon-bond-guaranteed/depositFund.tsx index b50e0f6de..aec7d9847 100644 --- a/packages/demo/components/pages/contracts/coupon-bond-guaranteed/depositFund.tsx +++ b/packages/demo/components/pages/contracts/coupon-bond-guaranteed/depositFund.tsx @@ -5,8 +5,9 @@ import Button from '../../../ui/button'; import { CardanoWallet, useWallet } from '@meshsdk/react'; import { useState } from 'react'; import RunDemoResult from '../../../common/runDemoResult'; -import { Asset, BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core'; +import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core'; import { MeshVestingContract } from '@meshsdk/contracts'; +import { Asset } from '@meshsdk/common'; export default function VestingDepositFund() { return ( diff --git a/packages/demo/components/pages/contracts/escrow/initiateEscrow.tsx b/packages/demo/components/pages/contracts/escrow/initiateEscrow.tsx index 5dc9ddf7b..a94661652 100644 --- a/packages/demo/components/pages/contracts/escrow/initiateEscrow.tsx +++ b/packages/demo/components/pages/contracts/escrow/initiateEscrow.tsx @@ -7,7 +7,7 @@ import { useState } from 'react'; import RunDemoResult from '../../../common/runDemoResult'; import useLocalStorage from '../../../../hooks/useLocalStorage'; import { getContract } from './common'; -import { Asset } from '@meshsdk/core'; +import { Asset } from '@meshsdk/common'; export default function EscrowInitiate() { return ( @@ -30,8 +30,8 @@ function Left() { the escrow contract.

- initiateEscrow() initiate an escrow. The - function accepts the following parameters: + initiateEscrow() initiate an escrow. The function accepts + the following parameters: