-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'marmaladedocs' of https://github.com/kadena-community/k…
…adena.js into marmaladedocs
- Loading branch information
Showing
3 changed files
with
64 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
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
57 changes: 57 additions & 0 deletions
57
packages/apps/docs/src/pages/marmalade/architecture/sale-contracts.md
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,57 @@ | ||
--- | ||
title: Sale Contracts | ||
description: Sale Contracts in Marmalade V2 | ||
menu: Sale Contracts | ||
label: Sale Contracts | ||
order: 3 | ||
layout: full | ||
--- | ||
|
||
# Sale Contracts | ||
|
||
With Sale Contracts, Marmalade V2 introduces a new way to manage the sale of a token. WHen offering a token up for sale in the ledger, it is now possible to also provide a reference to a sale contract. This sale contract can then be used to manage the sale of the token which allows for maximum flexibility and creativity in the sale of a token. | ||
|
||
Security is an important aspect of selling a token, especially when it comes to guaranteeing royalty. Therefore the sale contracts are required to be registered within the Policy Manager. This ensures that the sale contract is known to the Policy Manager and that the Policy Manager can enforce the sale contract. Before registering the sale contract will undergo a review process to ensure that it is safe to use. | ||
|
||
Where Sale Contracts are aimed at general purpose sales, Marmalade token creators still have complete flexibility to implement any custom sale logic within a policy and attach it to the token itself. This allows for a wide range of sale options and flexibility. | ||
|
||
## Sale Contract Interface | ||
|
||
The sale contract interface is a light interface which needs to be implemented by any sale contract. It is used by the Policy Manager to enforce the sale contract. The interface is defined as follows: | ||
|
||
```pact | ||
(defun enforce-quote-update:bool (sale-id:string price:decimal) | ||
@doc "Read-only Function that is enforced to update quote price at enforce-buy" | ||
) | ||
``` | ||
|
||
The function `enforce-quote-update` is called in from the `buy` step in the ledger and takes two parameters: | ||
|
||
- sale-id (type: string): This parameter represents the identifier of the sale, which is basicaly the pact-id that is created when the token is offered up for sale in the ledger. | ||
- price (type: decimal): This parameter represents the finale price associated with the sale. | ||
|
||
## Available Sale Contracts | ||
|
||
**Conventional Auction** | ||
|
||
A conventional auction is a sale contract that allows for the sale of a token through a conventional auction. The seller can set a reserve price which will ensure that the token is not sold below a certain price. The auction will run for a set amount of time and the highest bidder will win the auction. If the reserve price is not met, the seller can choose to cancel the auction and the token will be returned to the seller. | ||
The contract is deployed at `marmalade-sale.conventional-auction`. | ||
|
||
More sale contracts will follow but in the meantime, you can also create your own sale contract. The sale contracts can be found in the [Marmalade Github repository](https://github.com/kadena-io/marmalade) under `pact/sale-contracts`. Just create a pull request and we will review your sale contract and take care of deployment and whitelisting it in the Policy Manager. | ||
|
||
## Using a Sale Contract | ||
The sale contract can be used by providing the sale contract's module name as part of the quote specification when calling the `offer` function in the ledger. Here's an example of the quote specification with the sale contract's module name mentioned under the key `sale-type`. | ||
|
||
```pact | ||
"quote" : { | ||
"fungible": coin | ||
,"sale-price": 0.0 | ||
,"seller-fungible-account": { | ||
"account": "k:seller" | ||
,"guard": {"keys": ["seller"], "pred": "keys-all"} | ||
} | ||
,"sale-type": "marmalade-sale.conventional-auction" | ||
} | ||
``` | ||
|
||
**_Note:_** When using a sale contract the `sale-price` during `offer` must always be `0.0`, since the sale contract will be responsible for updating the price during the `buy` step. |