-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71e4f3f
commit 21cbf9b
Showing
11 changed files
with
529 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.