Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for latest ll and tsol #25

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.6 (2023-05-15)

### Improvements
* Updated to newer compiler version 0.62.0
* Added `CollectionBase` and `NftBase` implementations to inherit from

## 1.1.4 (2022-08-17)

### Improvements
Expand Down
151 changes: 8 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,153 +1,18 @@
# everscale-tip
# TIP4 NFT

# Prerequisites

# What is needed for development?
- Install [npm](https://www.npmjs.com/)
- Install [Locklift](https://github.com/broxus/locklift.git)

- Install [TON Solidity Compiler](https://github.com/tonlabs/TON-Solidity-Compiler.git)
- Install [TVM linker](https://github.com/tonlabs/TVM-linker/releases/tag/0.14.2)
- Install [nmp](https://www.npmjs.com/)

# Initialize project

1. Create empty folder and move to it
1. Init npm project. ```npm init -y```
1. Install itgold library for development NFT. ```npm i @itgold/everscale-tip```
2. Init locklift project. ```locklift init```
3. Install library for NFT. ```npm i tip4```
4. Add NFT contracts to `externalContracts` and `precompiled` sections of your `locklift.config.ts`

# How to run tests
# Run tests
```npm run test```

# How to use library

1. Create ```Nft.sol``` file and fill it.

```solidity
pragma ton-solidity = 0.58.1;

pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;


import '@itgold/everscale-tip/contracts/TIP4_1/TIP4_1Nft.sol';

contract Nft is TIP4_1Nft {

constructor(
address owner,
address sendGasTo,
uint128 remainOnNft
) TIP4_1Nft(
owner,
sendGasTo,
remainOnNft
) public {}

}
```

2. Create ```Collection.sol``` file and fill it.

```solidity
pragma ton-solidity = 0.58.1;

pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;


import '@itgold/everscale-tip/contracts/TIP4_1/TIP4_1Collection.sol';
import '@itgold/everscale-tip/contracts/access/OwnableExternal.sol';
import './Nft.sol';

contract Collection is TIP4_1Collection, OwnableExternal {

/**
* Errors
**/
uint8 constant sender_is_not_owner = 100;
uint8 constant value_is_less_than_required = 101;

/// _remainOnNft - the number of crystals that will remain after the entire mint
/// process is completed on the Nft contract
uint128 _remainOnNft = 0.3 ton;

constructor(
TvmCell codeNft,
uint256 ownerPubkey
) OwnableExternal(
ownerPubkey
) TIP4_1Collection (
codeNft
) public {
tvm.accept();
}

function mintNft() external virtual {
require(msg.value > _remainOnNft + 0.1 ton, value_is_less_than_required);
tvm.rawReserve(0, 4);

uint256 id = uint256(_totalSupply);
_totalSupply++;

TvmCell codeNft = _buildNftCode(address(this));
TvmCell stateNft = _buildNftState(codeNft, id);
address nftAddr = new Nft{
stateInit: stateNft,
value: 0,
flag: 128
}(
msg.sender,
msg.sender,
_remainOnNft
);

emit NftCreated(
id,
nftAddr,
msg.sender,
msg.sender,
msg.sender
);

}

function setRemainOnNft(uint128 remainOnNft) external virtual {
require(TIP4_1Collection._isOwner(), sender_is_not_owner);
_remainOnNft = remainOnNft;
}

function _isOwner() internal override onlyOwner returns(bool){
return true;
}

function _buildNftState(
TvmCell code,
uint256 id
) internal virtual override pure returns (TvmCell) {
return tvm.buildStateInit({
contr: Nft,
varInit: {_id: id},
code: code
});
}

}
```

> TIP: You can use another samples from [everscale-tip-samples](https://github.com/itgoldio/everscale-tip-samples/tree/main/demo)

# Build project

1. build ```Nft.sol``` file to use [TON Solidity Compiler](https://github.com/tonlabs/TON-Solidity-Compiler.git)
1. ```solc Nft.sol --include-path node_modules```
1. build ```Collection.sol``` file to use [TON Solidity Compiler](https://github.com/tonlabs/TON-Solidity-Compiler.git)
1. ```solc Collection.sol --include-path node_modules```
1. compile ```Nft.code``` file to use [TVM linker](https://github.com/tonlabs/TVM-linker/releases/tag/0.14.2)
1. ```tvm_linker compile --abi-json Nft.abi.json Nft.code --lib stdlib_sol.tvm -o Nft.tvc```
1. compile ```Collection.code``` file to use [TVM linker](https://github.com/tonlabs/TVM-linker/releases/tag/0.14.2)
1. ```tvm_linker compile --abi-json Collection.abi.json Collection.code --lib stdlib_sol.tvm -o Collection.tvc```

# Deploy NFT

Deploy ```Collection.tvc``` use [ever-sdk](https://github.com/tonlabs/ever-sdk) or [cli](https://github.com/tonlabs/tonos-cli)

89 changes: 89 additions & 0 deletions contracts/CollectionBase.tsol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
pragma ever-solidity >= 0.62.0;

pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;


import './TIP4_2/TIP4_2Collection.tsol';
import './TIP4_3/TIP4_3Collection.tsol';
import './NftBase.tsol';


contract CollectionBase is TIP4_2Collection, TIP4_3Collection {

/**
* Errors
**/
uint8 constant sender_is_not_owner = 101;
uint8 constant value_is_less_than_required = 102;


/// _remainOnNft - the number of crystals that will remain after the entire mint
/// process is completed on the Nft contract
uint128 _remainOnNft = 0.3 ever;

constructor(
TvmCell codeNft,
TvmCell codeIndex,
TvmCell codeIndexBasis,
string json
) TIP4_1Collection (
codeNft
) TIP4_2Collection (
json
) TIP4_3Collection (
codeIndex,
codeIndexBasis
) public {
tvm.accept();
}

function _mintNft(
string json
) internal {
require(msg.value > _remainOnNft + (2 * _indexDeployValue), value_is_less_than_required);
/// reserve original_balance
tvm.rawReserve(0, 4);

uint256 id = _totalSupply;
_totalSupply++;

TvmCell codeNft = _buildNftCode(address(this));
TvmCell stateNft = _buildNftState(codeNft, id);
address nftAddr = new NftBase{
stateInit: stateNft,
value: 0,
flag: 128
}(
msg.sender,
msg.sender,
_remainOnNft,
json,
_indexDeployValue,
_indexDestroyValue,
_codeIndex
);

emit NftCreated(
id,
nftAddr,
msg.sender,
msg.sender,
msg.sender
);

}

function _buildNftState(
TvmCell code,
uint256 id
) internal virtual override(TIP4_2Collection, TIP4_3Collection) pure returns (TvmCell) {
return tvm.buildStateInit({
contr: NftBase,
varInit: {_id: id},
code: code
});
}

}
71 changes: 71 additions & 0 deletions contracts/NftBase.tsol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
pragma ever-solidity >= 0.62.0;

pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;


import './TIP4_1/TIP4_1Nft.tsol';
import './TIP4_2/TIP4_2Nft.tsol';
import './TIP4_3/TIP4_3Nft.tsol';


contract NftBase is TIP4_1Nft, TIP4_2Nft, TIP4_3Nft {

constructor(
address owner,
address sendGasTo,
uint128 remainOnNft,
string json,
uint128 indexDeployValue,
uint128 indexDestroyValue,
TvmCell codeIndex
) TIP4_1Nft(
owner,
sendGasTo,
remainOnNft
) TIP4_2Nft (
json
) TIP4_3Nft (
indexDeployValue,
indexDestroyValue,
codeIndex
) public {
tvm.accept();
}

function _beforeTransfer(
address to,
address sendGasTo,
mapping(address => CallbackParams) callbacks
) internal virtual override(TIP4_1Nft, TIP4_3Nft) {
TIP4_3Nft._beforeTransfer(to, sendGasTo, callbacks);
}

function _afterTransfer(
address to,
address sendGasTo,
mapping(address => CallbackParams) callbacks
) internal virtual override(TIP4_1Nft, TIP4_3Nft) {
TIP4_3Nft._afterTransfer(to, sendGasTo, callbacks);
}

function _beforeChangeOwner(
address oldOwner,
address newOwner,
address sendGasTo,
mapping(address => CallbackParams) callbacks
) internal virtual override(TIP4_1Nft, TIP4_3Nft) {
TIP4_3Nft._beforeChangeOwner(oldOwner, newOwner, sendGasTo, callbacks);
}

function _afterChangeOwner(
address oldOwner,
address newOwner,
address sendGasTo,
mapping(address => CallbackParams) callbacks
) internal virtual override(TIP4_1Nft, TIP4_3Nft) {
TIP4_3Nft._afterChangeOwner(oldOwner, newOwner, sendGasTo, callbacks);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pragma AbiHeader time;
pragma AbiHeader pubkey;


import '../TIP6/TIP6.sol';
import './interfaces/ITIP4_1Collection.sol';
import './TIP4_1Nft.sol';
import '../TIP6/TIP6.tsol';
import './interfaces/ITIP4_1Collection.tsol';
import './TIP4_1Nft.tsol';


/// @title One of the required contracts of an TIP4-1(Non-Fungible Token Standard) compliant technology.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ pragma AbiHeader time;
pragma AbiHeader pubkey;


import './interfaces/ITIP4_1NFT.sol';
import './interfaces/INftChangeOwner.sol';
import './interfaces/INftChangeManager.sol';
import './interfaces/INftTransfer.sol';
import './interfaces/ITIP4_1NFT.tsol';
import './interfaces/INftChangeOwner.tsol';
import './interfaces/INftChangeManager.tsol';
import './interfaces/INftTransfer.tsol';

import '../TIP6/TIP6.sol';
import '../TIP6/TIP6.tsol';


/// @title One of the required contracts of an TIP4-1(Non-Fungible Token Standard) compliant technology.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pragma ever-solidity ^0.62.0;

interface INftChangeOwner {

struct CallbackParams {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pragma ever-solidity ^0.62.0;

interface INftTransfer {

struct CallbackParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pragma AbiHeader time;
pragma AbiHeader pubkey;


import '../TIP4_1/TIP4_1Collection.sol';
import './interfaces/ITIP4_2JSON_Metadata.sol';
import './TIP4_2Nft.sol';
import '../TIP4_1/TIP4_1Collection.tsol';
import './interfaces/ITIP4_2JSON_Metadata.tsol';
import './TIP4_2Nft.tsol';


/// This contract implement TIP4_1Collection and ITIP4_2JSON_Metadata (add JSON Metadata)
Expand Down
Loading