Skip to content

Commit

Permalink
feat: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglescode committed May 7, 2024
1 parent 71e4f3f commit 21cbf9b
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 219 deletions.
66 changes: 36 additions & 30 deletions packages/contracts/src/escrow/readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
# Escrow

The escrow contract is a simple contract that allows two parties to agree on a transaction and then have the funds locked until the transaction is complete. The contract is designed to be used in a trustless manner, so that neither party can cheat the other.

Actors:
- initiator
- initiator is the party that starts the escrow
- initiator deposit assets into the escrow
- recipient
- recipient deposit assets into the escrow
- both parties
- either party can cancel the trade and all assets are returned to the original owner
- both parties must agree to the trade before the assets are released

Story:
When two parties agree on a transaction, they can deposit assets into the escrow and the recipient can withdraw the assets if the transaction is complete. if the transaction is not complete or canceled, the assets are returned to the original owner.

Endpoints:
- initiator deposit assets
- recipient deposit assets
- cancel trade
- complete trade
list, pay, report, dispute, claim?


Processes:
- initiate -> cancel
- initiaite -> recipient deposit -> initiator cancel
- initiaite -> recipient deposit -> recipient cancel
- initiaite -> recipient deposit -> complete trade
# Escrow contract

Escrow contract facilitates the secure exchange of assets between two parties by acting as a trusted intermediary that holds the assets until the conditions of the agreement are met.

The escrow smart contract allows two parties to exchange assets securely. The contract holds the assets until both parties agree and sign off on the transaction.

There are 4 actions available to interact with this smart contract:

- initiate escrow and deposit assets
- deposit assets
- complete escrow
- cancel escrow

To initialize the escrow, we need to initialize a provider, MeshTxBuilder and MeshEscrowContract.

```
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import { useWallet } from '@meshsdk/react';
const { connected, wallet } = useWallet();
const blockchainProvider = new BlockfrostProvider(APIKEY);
const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});
const contract = new MeshEscrowContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});
```
34 changes: 34 additions & 0 deletions packages/contracts/src/giftcard/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Giftcard contract

Giftcard contract allows users to create a transactions to lock assets into the smart contract, which can be redeemed by any user.

Creating a giftcard will mint a token and send the assets to the contract. While redeeming will burn the token and send the assets to the redeemer.

There are 2 actions (or endpoints) available to interact with this smart contract:

- create giftcard
- redeem giftcard

To initialize the escrow, we need to initialize a provider, MeshTxBuilder and MeshGiftCardContract.

```
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshGiftCardContract } from '@meshsdk/contracts';
import { useWallet } from '@meshsdk/react';
const { connected, wallet } = useWallet();
const blockchainProvider = new BlockfrostProvider(APIKEY);
const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});
const contract = new MeshGiftCardContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});
```
45 changes: 42 additions & 3 deletions packages/contracts/src/marketplace/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,43 @@
# Marketplace
# Marketplace Contract

Endpoints:
buy, update, cancel, purchase
This marketplace allows anyone to buy and sell native assets such as NFTs.

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.

There are 4 actions (or endpoints) available to interact with this smart contract:

- list asset
- buy asset
- updating listing
- cancel listing

## Initialize the Marketplace

Utilizing the Marketplace contract requires a blockchain provider and a connected browser wallet. Here is an example how we can initialize the Marketplace.

```
import { MeshMarketplaceContract } from '@meshsdk/contracts';
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
const blockchainProvider = new BlockfrostProvider(APIKEY);
const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});
const contract = new MeshMarketplaceContract(
{
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
},
'addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv06fwlvuacpyv59g3a3w2fhk7daa8aepvacnpamyhyyxrgnscrfpsa',
200
);
```

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.

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%.
Empty file.
62 changes: 62 additions & 0 deletions packages/contracts/src/payment-splitter/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 💸 Aiken Payment Splitter

A simple payment splitter validator written in Aiken and its off-chain counterpart. The Aiken code is located in the onchain directory, while the off-chain code is in the offchain directory.

## ⛓ On-chain

The validator checks two simple rules:

1. The list of (unique) payment credentials must match the provided list of "known payees." This list can be provided as a parameter to the validator.
2. The sum of the outputs (by payment credentials) must be equally split. (Excluding change outputs)

### 🔌 Prerequirements

- [Aiken](https://aiken-lang.org/installation-instructions#from-aikup-linux--macos-only)

### 🪄 Test and build

```bash
cd onchain
aiken test
aiken build
```

## 📄 Off-chain

### 🔌 Prerequirements

- Node >= 16
- Yarn

### 💳 Prepare a list of wallets

```bash
cd offchain
yarn install
node use-payment-splitter.js prepare 5
```

### 💎 Top up the wallets

Copy the address from the output of the previous command and send some test Ada on the preprod network to this address.
If you don't have test Ada at all, you can get some from the [Cardano Testnets Faucet](https://docs.cardano.org/cardano-testnets/tools/faucet/).

### 🤳🏼 Send 10 tAda to the payment splitter

Anyone can lock funds in the payment splitter by sending an amount to the contract address.

```bash
node use-payment-splitter.js lock 10000000
```

Example transaction: https://preprod.cexplorer.io/tx/0008dd3ead94b0ca922ad45162762d73b5200efc5565a24532f1517fdf060dee

### 🤑 Trigger a payout

This command will generate a transaction that calculates the total available Lovelace value within the contract UTXOs and distributes the funds among the payees.

```bash
node use-payment-splitter.js unlock
```

Example transaction: https://preprod.cexplorer.io/tx/53be51e0f1268d41caae2944a760387fd762e76058aceddee73ca507d9e9a9c7
51 changes: 31 additions & 20 deletions packages/contracts/src/vesting/readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# Vesting
# Vesting Contract

Vesting contract is a smart contract that locks up funds for a period of time and allows the owner to withdraw the funds after the lockup period.

Actors:
- owner
- owner is the organization that is depositing funds into the vesting contract
- owner deposit funds to be locked up for a period of time
- ? owner can withdraw funds if it is not redeemed after a certain time after the lockup period
- ? owner can cancel the lockup period if someone leaves the organization
- beneficiary
- beneficiary is the recipient of the locked up funds
- beneficiary can withdraw funds after the lockup period

Story:
when a new employee join an organization, they are promised an amount of money to be paid after a period of time. The organization can deposit the funds into a vesting contract and the employee can withdraw the funds after the lockup period. this is to ensure that the employee stays with the organization for a period of time.

Endpoints:
- owner deposit funds
- withdraw funds

Reference:
- https://aiken-lang.org/example--vesting
When a new employee joins an organization, they typically receive a promise of compensation to be disbursed after a specified duration of employment. This arrangement often involves the organization depositing the funds into a vesting contract, with the employee gaining access to the funds upon the completion of a predetermined lockup period. Through the utilization of vesting contracts, organizations establish a mechanism to encourage employee retention by linking financial rewards to tenure.

There are 2 actions (or endpoints) available to interact with this smart contract:

- deposit asset
- withdraw asset

To initialize the escrow, we need to initialize a provider, MeshTxBuilder and MeshVestingContract.

```
import { BlockfrostProvider, MeshTxBuilder } from '@meshsdk/core';
import { MeshVestingContract } from '@meshsdk/contracts';
import { useWallet } from '@meshsdk/react';
const { connected, wallet } = useWallet();
const blockchainProvider = new BlockfrostProvider(APIKEY);
const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
submitter: blockchainProvider,
});
const contract = new MeshVestingContract({
mesh: meshTxBuilder,
fetcher: blockchainProvider,
wallet: wallet,
networkId: 0,
});
```
11 changes: 3 additions & 8 deletions packages/demo/components/pages/apis/appwallet/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ export default function Hero() {
<div className="grid grid-cols-1 px-4 lg:grid-cols-3 lg:gap-4 pb-16">
<div className="col-span-2">
<p>
Whether you are building a minting script, or an application that
requires multi-signature, <code>AppWallet</code> is all you need to
get started.
</p>

<p className="font-medium">
In this section, you will learn how to initialize a wallet and use
it to sign transactions.
<code>AppWallet</code> is useful for building other user wallets and
fully customed applications's backend.
</p>
<p className="font-medium"></p>
</div>
</div>
</>
Expand Down
14 changes: 9 additions & 5 deletions packages/demo/components/pages/apis/meshwallet/hero.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { WalletIcon } from '@heroicons/react/24/solid';
import Codeblock from '../../../ui/codeblock';

export default function Hero() {
return (
Expand All @@ -14,13 +13,18 @@ export default function Hero() {
</div>
</h2>
<p className="mb-8 font-light text-gray-500 sm:text-xl dark:text-gray-400">
Mesh Wallet is a class that provides a set of APIs to interact with
the blockchain. This wallet is compatible with Mesh transaction
builders.
Mesh Wallet provides a set of APIs to interact with the blockchain.
This wallet is compatible with Mesh transaction builders.
</p>
</header>
<div className="grid grid-cols-1 px-4 lg:grid-cols-3 lg:gap-4 pb-16">
<div className="col-span-2"></div>
<div className="col-span-2">
<p>
Whether you are building a minting script, or an application that
requires multi-signature, <code>MeshWallet</code> is all you need to
get started.
</p>
</div>
</div>
</>
);
Expand Down
28 changes: 18 additions & 10 deletions packages/demo/pages/debug/mesh/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { MeshWallet, BlockfrostProvider, Transaction } from '@meshsdk/core';
import {
MeshWallet,
BlockfrostProvider,
YaciProvider,
Transaction,
} from '@meshsdk/core';
import { ForgeScript } from '@meshsdk/core';
import type { Mint, AssetMetadata } from '@meshsdk/core';
import { MeshTxBuilder } from '@meshsdk/core';
import { MeshEscrowContract } from '@meshsdk/contracts';
import { useWallet } from '@meshsdk/react';

export default function Mesh() {
function getBlockchainProvider() {
// const blockchainProvider = new BlockfrostProvider(
// process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
// );
const blockchainProvider = new YaciProvider('http://localhost:8080/api/v1');
return blockchainProvider;
}

async function getMeshWallet() {
const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);
const blockchainProvider = getBlockchainProvider();
const wallet = new MeshWallet({
networkId: 0,
fetcher: blockchainProvider,
Expand Down Expand Up @@ -176,9 +186,7 @@ export default function Mesh() {
async function testSmartContract() {
const wallet = await getMeshWallet();

const blockchainProvider = new BlockfrostProvider(
process.env.NEXT_PUBLIC_BLOCKFROST_API_KEY_PREPROD!
);
const blockchainProvider = getBlockchainProvider();

const meshTxBuilder = new MeshTxBuilder({
fetcher: blockchainProvider,
Expand Down Expand Up @@ -208,7 +216,8 @@ export default function Mesh() {

// cancelEscrow
const utxo = await contract.getUtxoByTxHash(
'046c3b1f6fda82466b0c231971d50baf150b18a14773c62bb1832c3d8f2969b3'
// note, must change this to the txhash of the previous tx
'f40f880e1571b332c426ba2769e98a62aa13446e66fe876eaf94724a0b53643a'
);
const tx = await contract.cancelEscrow(utxo);
const signedTx = await wallet.signTx(tx, true);
Expand All @@ -219,7 +228,6 @@ export default function Mesh() {
return (
<>
<div className="flex flex-col gap-4 m-4">
<button onClick={() => getMeshWallet()}>getWallet</button>
<button onClick={() => getBalance()}>getBalance</button>
<button onClick={() => getChangeAddress()}>getChangeAddress</button>
<button onClick={() => getNetworkId()}>getNetworkId</button>
Expand Down

0 comments on commit 21cbf9b

Please sign in to comment.