Skip to content

Commit

Permalink
docs: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
YianW committed Jun 23, 2022
1 parent 4e2cec0 commit 44a8c05
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 2,918 deletions.
14 changes: 14 additions & 0 deletions src/__configuration__/navigationMenu/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const pageDefinitions: SimpleNavItem[] = [
<MarkdownPage title={'Token Contract'} markdown={Docs.GetStarted.SmartContracts.TokenContract} />
),
},
{
title: 'Token Contract V2',
url: '/token-contract-v2',
component: (
<MarkdownPage title={'Token Contract'} markdown={Docs.GetStarted.SmartContracts.TokenContractV2} />
),
},
{
title: 'Lock Contract',
url: '/lock-contract',
Expand All @@ -67,6 +74,13 @@ export const pageDefinitions: SimpleNavItem[] = [
<MarkdownPage title={'Non-Fungible Token Contract'} markdown={Docs.GetStarted.SmartContracts.NftContract} />
),
},
{
title: 'NFT Contract V2',
url: '/nft-contract-v2',
component: (
<MarkdownPage title={'Non-Fungible Token Contract V2'} markdown={Docs.GetStarted.SmartContracts.NftContractV2} />
),
},
{
title: 'Payment Contract',
url: '/payment-contract',
Expand Down
4 changes: 3 additions & 1 deletion src/docs/get-started/smart-contracts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import TokenContract from './token-contract.mdx';
import TokenContractV2 from './token-contract-v2.mdx'
import LockContract from './lock-contract.mdx';
import NftContract from './nft-contract.mdx';
import NftContractV2 from './nft-contract-v2.mdx'
import PaymentContract from './payment-channel-contract.mdx';
import VswapContract from './v-swap-contract.mdx';
import VstableswapContract from './v-stable-swap.mdx';
Expand All @@ -9,4 +11,4 @@ import VoptionContract from './v-option.mdx';
import VescrowContract from './v-escrow.mdx';


export { TokenContract, LockContract, NftContract, PaymentContract, VswapContract, VstableswapContract, VatomicswapContract, VoptionContract, VescrowContract};
export { TokenContract, TokenContractV2, LockContract, NftContract, NftContractV2, PaymentContract, VswapContract, VstableswapContract, VatomicswapContract, VoptionContract, VescrowContract};
166 changes: 7 additions & 159 deletions src/docs/get-started/smart-contracts/lock-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,173 +2,21 @@

# Lock Contract


## Introduction

Lock contracts allow users to lock a specific token in the contract for some period of time. This allows users to guarantee they have a certain amount of funds upon lock expiration. This may be helpful in implementing some kinds of staking interactions with users of a VSYS token for instance.

The lock contract is a very simple contract that is able to store a selected token. It allows anyone to execute this contract and lock their funds into it for some period of time. It is not necessary to open multiple lock contracts for different people to lock their coins of tokens.

## Using the VSYS Python API Wrapper (pyvsystems)

To generate and broadcast transactions, we can use pyvsystems to test contract functionalities on the Vsys chain.

### Install pyvsystems

Pyvsystems can be installed by first cloning the GitHub repository in terminal.

```sh
git clone https://github.com/virtualeconomy/pyvsystems.git
```

Then using pip, we can install the repository as a package.

```sh
pip3 install pyvsystems/.
```

Now you can import pyvsystems in your own workplace.

## Register a lock contract

Before we start, please make sure you have already set up a mainnet node or a devnet node. For the devnet node set-up instruction, you can refer to “How to build your own V Systems Devnet“.

### 1. To create and execute a lock contract of your own, you first need to initialize API connection.

<b>Data required:</b>

1. Your node address.
2. Your api key(optional).
3. Your seed.

```python:
import pyvsystems as pv
from pyvsystems import Account
from pyvsystems.contract_helper import *

custom_wrapper = pv.create_api_wrapper("your_node_address", api_key="your_node_api_key(optional)")
# chain = pv.Chain(chain_name='mainnet', chain_id='M', address_version=5, api_wrapper=custom_wrapper) # for mainnet
chain = pv.Chain(chain_name='testnet', chain_id='T', address_version=5, api_wrapper=custom_wrapper) #for testnet or devnet
sender = Account(chain=chain, seed="<your_sender_seed>")
```

### 2. Next, we need to register the contract with contract_helper in pyvsystems.

<b>Data required:</b>

1. Your token id. (you can create your own token in devnet for testing. For more information, please refer to “Token Contract”)

```python:
lock_contract_helper = LockContractHelper()

lock_contract_object = lock_contract_helper.contract_object

register_lock_contract_data_stack = lock_contract_helper.register_data_stack_generator("your_token_id")

print("register contract information: ",sender.register_contract(lock_contract_object, register_lock_contract_data_stack))
```
You can see your contract information in the terminal. Take note of your contract id.
## Using Lock Contract functions
After registering the lock contract, you can execute the functions of the contract.
| Executable functions | Function ID | Inputs | Input types | Description |
|:--------------------:|:-----------:|:-------------:|:-----------:|:------------------------------------------:|
| lock() | 0 | (“timestamp”) | long | Lock the funds until a specified timestamp |
### Lock Function:
<b>Data required:</b>
1. Lock contract’s id
2. Lock timestamp
```python:

lock_contract_helper = LockContractHelper()
## Implementation

lock_contract_id = "your_lock_contract_id"

lock_function_id = lock_contract_helper.lock_function_index

lock_data_stack = lock_contract_helper.lock_data_stack_generator(your_timestamp)

sender.execute_contract(lock_contract_id, lock_function_id, lock_data_stack)

```

### Querying the Contract database

In order for the contract to do anything, it has to store some information within the database. This information can be queried by using the correct database key within the full node. The contract helper objects contain the corresponding database keys for each stored variable.

### Get Lock Contract Maker

<b>Data required:</b>

1. Lock contract’s id

```python:
lock_contract_helper = LockContractHelper()

lock_contract_id = "<your_lock_contract_id>"

maker_db_key = lock_contract_helper.maker_db_key_generator()

print(chain.contract_db_query(lock_contract_id, maker_db_key))
```

### Get Token id of the Supported Token

This helps you retrieve the token ID of the supported token in the lock contract.

<b>Data required:</b>

1. Lock contract’s id

```python:
lock_contract_helper = LockContractHelper()

lock_contract_id = "<your_lock_contract_id>"

token_id_db_key = lock_contract_helper.token_id_db_key_generator()

print(chain.contract_db_query(lock_contract_id, token_id_db_key))
```

### Get Address' Contract Balance

This helps you retrieve the Address' contract balance in the lock contract.

<b>Data required:</b>

1. Lock contract’s id

```python:
lock_contract_helper = LockContractHelper()

lock_contract_id = "<your_lock_contract_id>"

contract_balance_db_key = lock_contract_helper.contract_balance_db_key_generator(sender.address)#sender is defined in initialize part

print(chain.contract_db_query(lock_contract_id, contract_balance_db_key))
```

### Get Address' Lock Time

This helps you retrieve the lock time of the Address from the Lock Contract ID in the lock contract.

<b>Data required:</b>
The lock contract is a very simple contract that is able to store a selected token. It allows anyone to execute this contract and lock their funds into it for some period of time. It is not necessary to open multiple lock contracts for different people to lock their coins of tokens.

1. Lock contract’s id

```python:
lock_contract_helper = LockContractHelper()
## Tutorial

lock_contract_id = "<your_lock_contract_id>"
For the tutorials, you can check the documentations for the token contracts of SDKs.

contract_lock_time_db_key = lock_contract_helper.contract_lock_time_db_key_generator(sender.address)
- [Python SDK](https://github.com/virtualeconomy/py-vsys/tree/main/doc/smart_contract)

print(chain.contract_db_query(lock_contract_id, contract_lock_time_db_key))
```
- [Javascript SDK](https://github.com/virtualeconomy/js-vsys/tree/main/doc/smart_contract)
33 changes: 33 additions & 0 deletions src/docs/get-started/smart-contracts/nft-contract-v2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- KEYWORDS: Non-Fungible Token Smart Contract V2-->

# NFT Contract V2


## Introduction

The Non-fungible Token Contract V2 provides an advanced feature to create a single, unsplittable token. In the real world, there are lots of transactions involving different anonymous people, these transactions may result in losses for certain parties due to malicious activity. Thankfully, these unsafe transactions could be avoided by using black list or white list. In other words, we can put those suspicious people into the black list to block them from participating in transactions or place only credible, trusted people into the white list to only allow specific people to join transactions.


## Implementation

The Non-fungible contract V2 controls a single token that can be sent, deposited or withdrawn same to the previous version. It also supports the `updateListUser` and `updateListCtrt` function while the caller can put the target user address/contract account into the specified white/black list to restrict participants(i.e., user address/contract account) joining the Non-fungible Contract V2's transactions. On the other hand, the `updateListUser` and `updateListCtrt` function can also be used to remove the target user address/contract account from the white/black list when necessary.


## Use Cases

The use cases of white/black list in Non-fungible Contract V2 is similar to Token Contract V2.

Although the white/black list can also be used to restrict the participants joining in transactions, they should be used in different conditions. Like if you hold a private gallery to sell some art works, you may put your members into white list. It allows some specified members make transactions in your gallery, moreover the public cannot make transactions in your gallery even if they hold the tokens.

On the other hand, the gallery owner should create a Non-fungible contract V2 with black list feature if the owner's gallery is open to the public. Since it is complicated and costly to update customers to the white list one by one, the black list can be a more efficient and feasible way in this situation. And therefore, the gallery owner can only block someone with a history of bad behaviour from making transactions but others can still make their transactions.

Therefore, Non-fungible Contract V2 improves the user experience that black/white list gives flexibility for the contract to apply in the real world for different purposes.


## Tutorial

For the tutorials, you can check the documentations for the token contracts of SDKs.

- [Python SDK](https://github.com/virtualeconomy/py-vsys/tree/main/doc/smart_contract)

- [Javascript SDK](https://github.com/virtualeconomy/js-vsys/tree/main/doc/smart_contract)
38 changes: 6 additions & 32 deletions src/docs/get-started/smart-contracts/nft-contract.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,21 @@

# NFT Contract


## Introduction

The Non-fungible Token Contract acts as a method to create a single token that cannot be split into any parts. This gives a neat way of proving the ownership of some unique asset. A simple example is a token representing an item within a game, this token can then be sent from wallet to wallet, representing an in game trade.


## Implementation

The Non-fungible contract controls a single token that can be sent, deposited or withdrawn. When registering a Non-fungible contract, it takes in no inputs. The token id of the issued token should be used to represent some form of unique asset, and the ownership of this token can easily be confirmed on the VSYS blockchain. It should be noted that the Non-fungible Token Contract can issue multiple tokens, each with its unique token id.


## Register a Non-fungible Token Contract

### Initialize API Connection

```python:
import pyvsystems as pv
from pyvsystems import Account
from pyvsystems.contract import token_id_from_contract_id
from pyvsystems.contract_helper import *

custom_wrapper = pv.create_api_wrapper("your_node_address", api_key="your_node_api_key(optional)")
# chain = pv.Chain(chain_name='mainnet', chain_id='M', address_version=5, api_wrapper=custom_wrapper)

chain = pv.Chain(chain_name='testnet', chain_id='T', address_version=5, api_wrapper=custom_wrapper)

sender = Account(chain=chain, seed="your_sender_seed")
```

### Non-fungible Token Contract ByteString:

```python:
VJodouhmnHVDwtkBZ2NdgahT7NAgNE9EpWoZApzobhpua2nDL9D3sbHSoRRk8bEFeme2BHrXPdcq5VNJcPdGMUD54Smwatyx74cPJyet6bCWmLciHE2jGw9u5TmatjdpFSjGKegh76GvJstK3VaLagvsJJMaaKM9MNXYtgJyDr1Zw7U9PXV7N9TQnSsqz6EHMgDvd8aTDqEG7bxxAotkAgeh4KHqnk6Ga117q5AJctJcbUtD99iUgPmJrC8vzX85TEXgHRY1psW7D6daeExfVVrEPHFHrU6XfhegKv9vRbJBGL861U4Qg6HWbWxbuitgtKoBazSp7VofDtrZebq2NSpZoXCAZC8DRiaysanAqyCJZf7jJ8NfXtWej8L9vg8PVs65MrEmK8toadcyCA2UGzg6pQKrMKQEUahruBiS7zuo62eWwJBxUD1fQ1RGPk9BbMDk9FQQxXu3thSJPnKktq3aJhD9GNFpvyEAaWigp5nfjgH5doVTQk1PgoxeXRAWQNPztjNvZWv6iD85CoZqfCWdJbAXPrWvYW5FsRLW1xJ4ELRUfReMAjCGYuFWdA3CZyefpiDEWqVTe5SA6J6XeUppRyXKpKQTc6upesoAGZZ2NtFDryq22izC6D5p1i98YpC6Dk1qcKevaANKHH8TfFoQT717nrQEY2aLoWrA1ip2t5etdZjNVFmghxXEeCAGy3NcLDFHmAfcBZhHKeJHp8H8HbiMRtWe3wmwKX6mPx16ahnd3dMGCsxAZfjQcy4J1HpuCm7rHMULkixUFYRYqx85c7UpLcijLRybE1MLRjEZ5SEYtazNuiZBwq1KUcNipzrxta9Rpvt2j4WyMadxPf5r9YeAaJJp42PiC6SGfyjHjRQN4K3pohdQRbbG4HQ95NaWCy7CAwbpXRCh9NDMMQ2cmTfB3KFW2M
```

### Code:
```python:
on_fungible_contract_helper = NonFungibleContractHelper()

non_fungible_contract_object = non_fungible_contract_helper.contract_object
## Tutorial

register_non_fungible_data_stack = non_fungible_contract_helper.register_data_stack_generator()
For the tutorials, you can check the documentations for the token contracts of SDKs.

sender.register_contract(non_fungible_contract_object, register_non_fungible_data_stack)
- [Python SDK](https://github.com/virtualeconomy/py-vsys/tree/main/doc/smart_contract)

```
- [Javascript SDK](https://github.com/virtualeconomy/js-vsys/tree/main/doc/smart_contract)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

2 comments on commit 44a8c05

@FK-VSYS

This comment was marked as spam.

@fukvsys
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1
2
3
4
5
6

Please sign in to comment.