@simplenft/api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -0
- package/blueprint.config.ts +13 -0
- package/contracts/buyer_profile.tact +73 -0
- package/contracts/imports/stdlib.fc +625 -0
- package/contracts/jetton_eq.tact +79 -0
- package/contracts/message.tact +189 -0
- package/contracts/nft_item.tact +98 -0
- package/contracts/nft_item_free.tact +98 -0
- package/contracts/packages/math/float.fc +95 -0
- package/contracts/packages/misc/distributor_messages.tact +154 -0
- package/contracts/packages/nap/errcodes.tact +5 -0
- package/contracts/packages/nap/messages.tact +34 -0
- package/contracts/packages/token/jetton/JettonMaster.tact +127 -0
- package/contracts/packages/token/jetton/JettonWallet.tact +248 -0
- package/contracts/packages/token/nft/AuctionErrorCode.tact +55 -0
- package/contracts/packages/token/nft/NFTAuction.tact +226 -0
- package/contracts/packages/token/nft/NFTAuctionMarket.tact +302 -0
- package/contracts/packages/token/nft/NFTCollection.tact +69 -0
- package/contracts/packages/token/nft/NFTItem.tact +190 -0
- package/contracts/packages/token/nft/extensions/NFTEditable.tact +3 -0
- package/contracts/packages/token/nft/extensions/NFTRoyalty.tact +63 -0
- package/contracts/packages/traits/taxable.tact +31 -0
- package/contracts/packages/utils/Estimatable.tact +11 -0
- package/contracts/packages/utils/Lockable.tact +23 -0
- package/contracts/sbt_item.tact +70 -0
- package/contracts/simple_nft_collection.tact +177 -0
- package/contracts/simple_nft_collection_v2.tact +304 -0
- package/contracts/simple_nft_master.tact +102 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.js +58 -0
- package/dist/backend-service.d.ts +13 -0
- package/dist/backend-service.js +29 -0
- package/dist/backend-types.d.ts +60 -0
- package/dist/backend-types.js +2 -0
- package/dist/content.d.ts +3 -0
- package/dist/content.js +30 -0
- package/dist/contracts/tact_NftItem.d.ts +619 -0
- package/dist/contracts/tact_NftItem.js +2312 -0
- package/dist/contracts/tact_SimpleNftCollectionV2.d.ts +658 -0
- package/dist/contracts/tact_SimpleNftCollectionV2.js +2427 -0
- package/dist/contracts/tact_SimpleNftMaster.d.ts +624 -0
- package/dist/contracts/tact_SimpleNftMaster.js +2350 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +254 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.js +2 -0
- package/package.json +56 -0
- package/src/api.ts +62 -0
- package/src/backend-service.ts +40 -0
- package/src/backend-types.ts +72 -0
- package/src/content.ts +36 -0
- package/src/contracts/tact_NftItem.ts +2718 -0
- package/src/contracts/tact_SimpleNftCollectionV2.ts +2843 -0
- package/src/contracts/tact_SimpleNftMaster.ts +2759 -0
- package/src/index.ts +361 -0
- package/src/types.ts +62 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import "@stdlib/deploy";
|
|
2
|
+
import "./packages/token/jetton/JettonMaster";
|
|
3
|
+
import "./packages/token/jetton/JettonWallet";
|
|
4
|
+
|
|
5
|
+
contract EqJettonWallet with JettonWallet {
|
|
6
|
+
balance: Int as coins = 0;
|
|
7
|
+
owner: Address;
|
|
8
|
+
jetton_master: Address;
|
|
9
|
+
|
|
10
|
+
init(owner: Address, jetton_master: Address) {
|
|
11
|
+
self.owner = owner;
|
|
12
|
+
self.jetton_master = jetton_master;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit {
|
|
16
|
+
return initOf EqJettonWallet(owner_address, self.jetton_master);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
contract EqJettonMaster with JettonMaster, Deployable {
|
|
21
|
+
total_supply: Int as coins = 0;
|
|
22
|
+
mintable: Bool = true;
|
|
23
|
+
owner: Address;
|
|
24
|
+
jetton_content: Cell;
|
|
25
|
+
|
|
26
|
+
// Fixed calculated value
|
|
27
|
+
init(owner: Address, jetton_content: Cell, total_supply: Int){
|
|
28
|
+
let ctx: Context = context();
|
|
29
|
+
self.owner = owner;
|
|
30
|
+
self.total_supply = total_supply;
|
|
31
|
+
self.jetton_content = jetton_content;
|
|
32
|
+
let msg: JettonMint = JettonMint{
|
|
33
|
+
origin: ctx.sender,
|
|
34
|
+
receiver: ctx.sender,
|
|
35
|
+
amount: total_supply,
|
|
36
|
+
custom_payload: emptyCell(),
|
|
37
|
+
forward_ton_amount: 0,
|
|
38
|
+
forward_payload: emptySlice()
|
|
39
|
+
};
|
|
40
|
+
self._mint(ctx, msg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* receive("Mint:1") {
|
|
44
|
+
let ctx: Context = context();
|
|
45
|
+
let msg: JettonMint = JettonMint{
|
|
46
|
+
origin: ctx.sender,
|
|
47
|
+
receiver: ctx.sender,
|
|
48
|
+
amount: ton("1"),
|
|
49
|
+
custom_payload: emptyCell(),
|
|
50
|
+
forward_ton_amount: 0,
|
|
51
|
+
forward_payload: emptySlice()
|
|
52
|
+
};
|
|
53
|
+
self._mint_validate(ctx, msg);
|
|
54
|
+
self._mint(ctx, msg);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
receive("Mint:Grand") {
|
|
58
|
+
let ctx: Context = context();
|
|
59
|
+
let msg: JettonMint = JettonMint{
|
|
60
|
+
origin: ctx.sender,
|
|
61
|
+
receiver: ctx.sender,
|
|
62
|
+
amount: ton("1000"),
|
|
63
|
+
custom_payload: emptyCell(),
|
|
64
|
+
forward_ton_amount: 0,
|
|
65
|
+
forward_payload: emptySlice()
|
|
66
|
+
};
|
|
67
|
+
self._mint(ctx, msg);
|
|
68
|
+
} */
|
|
69
|
+
|
|
70
|
+
override inline fun _mint_validate(ctx: Context, msg: JettonMint) {
|
|
71
|
+
require(self.mintable, "JettonMaster: Jetton is not mintable");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit {
|
|
75
|
+
return initOf EqJettonWallet(owner_address, myAddress());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
message LogEventMintRecord {
|
|
2
|
+
minter: Address;
|
|
3
|
+
item_id: Int;
|
|
4
|
+
generate_number: Int;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
message(0x693d3950) GetRoyaltyParams {
|
|
9
|
+
query_id: Int as uint64;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
message GetProfile {
|
|
13
|
+
query_id: Int as uint64;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
message(0xa8cb00ad) ReportRoyaltyParams {
|
|
17
|
+
query_id: Int as uint64;
|
|
18
|
+
numerator: Int as uint16;
|
|
19
|
+
denominator: Int as uint16;
|
|
20
|
+
destination: Address;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
struct CollectionData {
|
|
24
|
+
next_item_index: Int;
|
|
25
|
+
collection_content: Cell;
|
|
26
|
+
owner_address: Address;
|
|
27
|
+
}
|
|
28
|
+
struct RoyaltyParams {
|
|
29
|
+
numerator: Int;
|
|
30
|
+
denominator: Int;
|
|
31
|
+
destination: Address;
|
|
32
|
+
}
|
|
33
|
+
message CollectionSetupParams {
|
|
34
|
+
owner_address: Address;
|
|
35
|
+
master_address: Address;
|
|
36
|
+
collection_content: Cell;
|
|
37
|
+
nft_individual_content_url: Cell;
|
|
38
|
+
royalty_params: RoyaltyParams;
|
|
39
|
+
mint_limit: Int;
|
|
40
|
+
nft_price: Int;
|
|
41
|
+
mint_time_limit: Int;
|
|
42
|
+
is_sbt: Int;
|
|
43
|
+
enable_profile: Bool;
|
|
44
|
+
enable_whitelist: Bool;
|
|
45
|
+
user_item_limit: Int;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
message UpdateWhiteList {
|
|
49
|
+
user: Address;
|
|
50
|
+
whitelist: Bool;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
message AddToWhiteList {
|
|
54
|
+
add: Bool;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
message CollectionMintParams {
|
|
58
|
+
queryId: Int;
|
|
59
|
+
owner_address: Address;
|
|
60
|
+
collection_content: Cell;
|
|
61
|
+
nft_individual_content_url: Cell;
|
|
62
|
+
royalty_params: RoyaltyParams;
|
|
63
|
+
mint_limit: Int;
|
|
64
|
+
mint_time_limit: Int;
|
|
65
|
+
is_sbt: Int;
|
|
66
|
+
nft_price: Int;
|
|
67
|
+
enable_profile: Bool;
|
|
68
|
+
enable_whitelist: Bool;
|
|
69
|
+
user_item_limit: Int;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
message ProfileData {
|
|
73
|
+
query_id: Int as uint64;
|
|
74
|
+
user: Address;
|
|
75
|
+
is_whitelisted: Bool;
|
|
76
|
+
is_blacklisted: Bool;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
message(0x5fcc3d14) Transfer {
|
|
80
|
+
query_id: Int as uint64;
|
|
81
|
+
new_owner: Address;
|
|
82
|
+
response_destination: Address?;
|
|
83
|
+
custom_payload: Cell?;
|
|
84
|
+
forward_amount: Int as coins;
|
|
85
|
+
forward_payload: Slice as remaining;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
message(0x05138d91) OwnershipAssigned {
|
|
89
|
+
query_id: Int as uint64;
|
|
90
|
+
prev_owner: Address;
|
|
91
|
+
forward_payload: Slice as remaining;
|
|
92
|
+
}
|
|
93
|
+
message(0xd53276db) Excesses {
|
|
94
|
+
query_id: Int as uint64;
|
|
95
|
+
}
|
|
96
|
+
message(0x2fcb26a2) GetStaticData {
|
|
97
|
+
query_id: Int as uint64;
|
|
98
|
+
}
|
|
99
|
+
message(0x8b771735) ReportStaticData {
|
|
100
|
+
query_id: Int as uint64;
|
|
101
|
+
index_id: Int;
|
|
102
|
+
collection: Address;
|
|
103
|
+
}
|
|
104
|
+
struct GetNftData {
|
|
105
|
+
is_initialized: Bool;
|
|
106
|
+
index: Int;
|
|
107
|
+
collection_address: Address;
|
|
108
|
+
owner_address: Address;
|
|
109
|
+
individual_content: Cell;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
struct CollectionMasterData {
|
|
113
|
+
master: Address;
|
|
114
|
+
mint_limit: Int;
|
|
115
|
+
price: Int;
|
|
116
|
+
mint_time_limit: Int;
|
|
117
|
+
is_sbt: Int;
|
|
118
|
+
index_in_collection: Int;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
struct CollectionMasterDataV2 {
|
|
122
|
+
master: Address;
|
|
123
|
+
mint_limit: Int;
|
|
124
|
+
price: Int;
|
|
125
|
+
mint_time_limit: Int;
|
|
126
|
+
is_sbt: Int;
|
|
127
|
+
index_in_collection: Int;
|
|
128
|
+
enable_whitelist: Bool;
|
|
129
|
+
user_item_limit: Int;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
|
|
134
|
+
master: self.master_address,
|
|
135
|
+
mint_limit: self.mint_limit,
|
|
136
|
+
mint_time_limit: self.mint_time_limit,
|
|
137
|
+
is_sbt: self.is_sbt,
|
|
138
|
+
price: self.price,
|
|
139
|
+
index_in_collection: self.collection_index
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
message MintTo{
|
|
143
|
+
owner: Address;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
message MassUpdateWhiteList {
|
|
147
|
+
addresses: Cell;
|
|
148
|
+
add: Bool;
|
|
149
|
+
spendPerAddress: Int as uint64;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
message SetupCollectionData{
|
|
153
|
+
collection_owner: Address?;
|
|
154
|
+
collection_item_price: Int;
|
|
155
|
+
user_item_limit: Int;
|
|
156
|
+
enable_whitelist: Bool;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
message CompleteTodo{
|
|
160
|
+
seqno: Int as uint256;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
message InternalComplete{
|
|
164
|
+
excess: Address;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
message InternalAdd{
|
|
169
|
+
amount: Int as coins;
|
|
170
|
+
origin: Address;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
message TransferOwner {
|
|
174
|
+
new_owner: Address;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
message Withdraw {
|
|
178
|
+
to: Address;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
struct MasterData {
|
|
182
|
+
master: Address;
|
|
183
|
+
next_collection_index: Int;
|
|
184
|
+
collection_creation_price: Int;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const masterMinStorage: Int = ton("0.05");
|
|
188
|
+
const minTonsForStorage: Int = ton("0.005");
|
|
189
|
+
const gasConsumption: Int = ton("0.012");
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import "@stdlib/deploy";
|
|
2
|
+
import "./message.tact";
|
|
3
|
+
|
|
4
|
+
contract NftItem {
|
|
5
|
+
collection_address: Address;
|
|
6
|
+
item_index: Int as uint32;
|
|
7
|
+
is_initialized: Bool;
|
|
8
|
+
|
|
9
|
+
owner: Address?;
|
|
10
|
+
individual_content: Cell?;
|
|
11
|
+
|
|
12
|
+
init(collection_address: Address, item_index: Int){
|
|
13
|
+
require(sender() == collection_address, "not from collection");
|
|
14
|
+
self.collection_address = collection_address;
|
|
15
|
+
self.item_index = item_index;
|
|
16
|
+
self.is_initialized = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
receive(msg: Transfer){
|
|
20
|
+
let ctx: Context = context(); // Reference: https://docs.tact-lang.org/language/ref/common#context
|
|
21
|
+
let msgValue: Int = self.msgValue(ctx.value);
|
|
22
|
+
|
|
23
|
+
if (self.is_initialized == false) { // Initial Transfer, aka the "Minting" of the NFT
|
|
24
|
+
require(ctx.sender == self.collection_address, "initialized tx need from collection");
|
|
25
|
+
self.is_initialized = true;
|
|
26
|
+
self.owner = msg.new_owner;
|
|
27
|
+
self.individual_content = msg.custom_payload;
|
|
28
|
+
send(SendParameters{
|
|
29
|
+
to: msg.response_destination!!,
|
|
30
|
+
value: msgValue,
|
|
31
|
+
mode: SendPayGasSeparately,
|
|
32
|
+
body: Excesses { query_id: msg.query_id }.toCell()
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
require(ctx.sender == self.owner!!, "not owner");
|
|
36
|
+
// require(self.is_sbt == 0, "Sbt cannot be transferred");
|
|
37
|
+
self.owner = msg.new_owner; // change current owner to the new_owner
|
|
38
|
+
if (msg.forward_amount > 0) {
|
|
39
|
+
send(SendParameters{
|
|
40
|
+
to: msg.new_owner,
|
|
41
|
+
value: msg.forward_amount,
|
|
42
|
+
mode: SendPayGasSeparately,
|
|
43
|
+
body: OwnershipAssigned{
|
|
44
|
+
query_id: msg.query_id,
|
|
45
|
+
prev_owner: ctx.sender,
|
|
46
|
+
forward_payload: msg.forward_payload
|
|
47
|
+
}.toCell()
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
msgValue = msgValue - ctx.readForwardFee();
|
|
52
|
+
if (msg.response_destination != null) {
|
|
53
|
+
send(SendParameters{
|
|
54
|
+
to: msg.response_destination!!,
|
|
55
|
+
value: msgValue - msg.forward_amount,
|
|
56
|
+
mode: SendPayGasSeparately,
|
|
57
|
+
body: Excesses { query_id: msg.query_id }.toCell()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
receive(msg: GetStaticData){
|
|
64
|
+
let ctx: Context = context();
|
|
65
|
+
send(SendParameters {
|
|
66
|
+
to: ctx.sender,
|
|
67
|
+
value: 0,
|
|
68
|
+
mode: 64, // (return msg amount except gas fees)
|
|
69
|
+
bounce: true,
|
|
70
|
+
body: ReportStaticData{
|
|
71
|
+
query_id: msg.query_id,
|
|
72
|
+
index_id: self.item_index,
|
|
73
|
+
collection: self.collection_address
|
|
74
|
+
}.toCell()
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fun msgValue(value: Int): Int {
|
|
79
|
+
let tonBalanceBeforeMsg: Int = myBalance() - value;
|
|
80
|
+
let storageFee: Int = minTonsForStorage - min(tonBalanceBeforeMsg, minTonsForStorage);
|
|
81
|
+
return value - (storageFee + gasConsumption);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --------- Get Function --------- //
|
|
85
|
+
get fun get_nft_data(): GetNftData {
|
|
86
|
+
let b: StringBuilder = beginString();
|
|
87
|
+
let collectionData: String = (self.individual_content!!).asSlice().asString();
|
|
88
|
+
b.append(collectionData);
|
|
89
|
+
|
|
90
|
+
return GetNftData {
|
|
91
|
+
is_initialized: self.is_initialized,
|
|
92
|
+
index: self.item_index,
|
|
93
|
+
collection_address: self.collection_address,
|
|
94
|
+
owner_address: self.owner!!,
|
|
95
|
+
individual_content: b.toCell()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import "@stdlib/deploy";
|
|
2
|
+
import "./message.tact";
|
|
3
|
+
|
|
4
|
+
contract NftItem {
|
|
5
|
+
collection_address: Address;
|
|
6
|
+
item_index: Int;
|
|
7
|
+
is_initialized: Bool;
|
|
8
|
+
|
|
9
|
+
owner: Address?;
|
|
10
|
+
individual_content: Cell?;
|
|
11
|
+
|
|
12
|
+
init(collection_address: Address, item_index: Int){
|
|
13
|
+
require(sender() == collection_address, "not from collection");
|
|
14
|
+
self.collection_address = collection_address;
|
|
15
|
+
self.item_index = item_index;
|
|
16
|
+
self.is_initialized = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
receive(msg: Transfer){
|
|
20
|
+
let ctx: Context = context(); // Reference: https://docs.tact-lang.org/language/ref/common#context
|
|
21
|
+
let msgValue: Int = self.msgValue(ctx.value);
|
|
22
|
+
|
|
23
|
+
if (self.is_initialized == false) { // Initial Transfer, aka the "Minting" of the NFT
|
|
24
|
+
require(ctx.sender == self.collection_address, "initialized tx need from collection");
|
|
25
|
+
self.is_initialized = true;
|
|
26
|
+
self.owner = msg.new_owner;
|
|
27
|
+
self.individual_content = msg.custom_payload;
|
|
28
|
+
send(SendParameters{
|
|
29
|
+
to: msg.new_owner, // Above paid contract
|
|
30
|
+
value: msgValue,
|
|
31
|
+
mode: SendPayGasSeparately,
|
|
32
|
+
body: Excesses { query_id: msg.query_id }.toCell()
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
require(ctx.sender == self.owner!!, "not owner");
|
|
36
|
+
// require(self.is_sbt == 0, "Sbt cannot be transferred");
|
|
37
|
+
self.owner = msg.new_owner; // change current owner to the new_owner
|
|
38
|
+
if (msg.forward_amount > 0) {
|
|
39
|
+
send(SendParameters{
|
|
40
|
+
to: msg.new_owner,
|
|
41
|
+
value: msg.forward_amount,
|
|
42
|
+
mode: SendIgnoreErrors + SendRemainingValue,
|
|
43
|
+
body: OwnershipAssigned{
|
|
44
|
+
query_id: msg.query_id,
|
|
45
|
+
prev_owner: ctx.sender,
|
|
46
|
+
forward_payload: msg.forward_payload
|
|
47
|
+
}.toCell()
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
msgValue = msgValue - ctx.readForwardFee();
|
|
52
|
+
if (msg.response_destination != null) {
|
|
53
|
+
send(SendParameters{
|
|
54
|
+
to: msg.response_destination!!,
|
|
55
|
+
value: msgValue - msg.forward_amount,
|
|
56
|
+
mode: SendIgnoreErrors + SendRemainingValue,
|
|
57
|
+
body: Excesses { query_id: msg.query_id }.toCell()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
receive(msg: GetStaticData){
|
|
64
|
+
let ctx: Context = context();
|
|
65
|
+
send(SendParameters {
|
|
66
|
+
to: ctx.sender,
|
|
67
|
+
value: 0,
|
|
68
|
+
mode: 64, // (return msg amount except gas fees)
|
|
69
|
+
bounce: true,
|
|
70
|
+
body: ReportStaticData{
|
|
71
|
+
query_id: msg.query_id,
|
|
72
|
+
index_id: self.item_index,
|
|
73
|
+
collection: self.collection_address
|
|
74
|
+
}.toCell()
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fun msgValue(value: Int): Int {
|
|
79
|
+
let tonBalanceBeforeMsg: Int = myBalance() - value;
|
|
80
|
+
let storageFee: Int = minTonsForStorage - min(tonBalanceBeforeMsg, minTonsForStorage);
|
|
81
|
+
return value - (storageFee + gasConsumption);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// --------- Get Function --------- //
|
|
85
|
+
get fun get_nft_data(): GetNftData {
|
|
86
|
+
let b: StringBuilder = beginString();
|
|
87
|
+
let collectionData: String = (self.individual_content!!).asSlice().asString();
|
|
88
|
+
b.append(collectionData);
|
|
89
|
+
|
|
90
|
+
return GetNftData {
|
|
91
|
+
is_initialized: self.is_initialized,
|
|
92
|
+
index: self.item_index,
|
|
93
|
+
collection_address: self.collection_address,
|
|
94
|
+
owner_address: self.owner!!,
|
|
95
|
+
individual_content: b.toCell()
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
;; Title: Func functions for floating point operation
|
|
2
|
+
;; Description: This file contains the functions for floating point operation
|
|
3
|
+
;; Author: @alan890104
|
|
4
|
+
;; Version: 0.1
|
|
5
|
+
|
|
6
|
+
const ERROR_INTEGER_OVERFLOW = 4;
|
|
7
|
+
|
|
8
|
+
;; requireInt128 function is used to check if the value is in the range of 128 bit integer
|
|
9
|
+
int requireInt128(int) asm "128 FITS";
|
|
10
|
+
|
|
11
|
+
;; requireFloat function is used to check if the value is compatible with fixed point float (128 bit integer + 64 bit decimal)
|
|
12
|
+
int requireFloat(int) asm "192 FITS";
|
|
13
|
+
|
|
14
|
+
;; toFloat function convert a 128 bit integer to fixed point float
|
|
15
|
+
;; the precision is about log10(2^64) = 19.2659
|
|
16
|
+
;; the integer part is 128 bit, the decimal part is 64 bit
|
|
17
|
+
int toFloat(int value) inline_ref {
|
|
18
|
+
value.requireInt128();
|
|
19
|
+
return value << 64;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
;; add function is used to add two fixed point float
|
|
23
|
+
;; this function will not check if the value is compatible with fixed point float
|
|
24
|
+
;; it is an alias function for "+" operator
|
|
25
|
+
int add(int floatA, int floatB) inline_ref {
|
|
26
|
+
return floatA + floatB;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
;; sub function is used to subtract two fixed point float
|
|
30
|
+
;; this function will not check if the value is compatible with fixed point float
|
|
31
|
+
;; it is equivalent to "-" operator
|
|
32
|
+
int sub(int floatA, int floatB) inline_ref {
|
|
33
|
+
return floatA - floatB;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
;; mul function is used to multiply two fixed point float
|
|
37
|
+
;; WARNING: the internal result may exceed 256 bit (196 bit * 196 bit = 392 bit)
|
|
38
|
+
int mul(int floatA, int floatB) inline_ref {
|
|
39
|
+
return (floatA * floatB) >> 64;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
;; div function is used to divide two fixed point float
|
|
43
|
+
;; the internal result is 192 bit + 64 bit = 256 bit, so it will not overflow
|
|
44
|
+
;; this function ignores checking if the value is compatible with fixed point float and division by zero
|
|
45
|
+
int div(int floatA, int floatB) inline_ref {
|
|
46
|
+
return (floatA << 64) / floatB;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
;; safeAdd function is used to add two fixed point float
|
|
50
|
+
;; it will check if the value is compatible with fixed point float, if not, it will throw an error
|
|
51
|
+
int safeAdd(int floatA, int floatB) inline_ref {
|
|
52
|
+
floatA.requireFloat();
|
|
53
|
+
floatB.requireFloat();
|
|
54
|
+
return floatA + floatB;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
;; safeSub function is used to subtract two fixed point float
|
|
59
|
+
;; it will check if the value is compatible with fixed point float, if not, it will throw an error
|
|
60
|
+
int safeSub(int floatA, int floatB) inline_ref {
|
|
61
|
+
floatA.requireFloat();
|
|
62
|
+
floatB.requireFloat();
|
|
63
|
+
return floatA - floatB;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
;; safeMul function is used to multiply two fixed point float
|
|
67
|
+
;; it will check if the value is compatible with fixed point float, if not, it will throw an error
|
|
68
|
+
int safeMul(int floatA, int floatB) inline_ref {
|
|
69
|
+
floatA.requireFloat();
|
|
70
|
+
floatB.requireFloat();
|
|
71
|
+
return (floatA * floatB) >> 64;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
;; safeDiv function is used to divide two fixed point float
|
|
75
|
+
;; it will check if the value is compatible with fixed point float, if not, it will throw an error
|
|
76
|
+
int safeDiv(int floatA, int floatB) inline_ref {
|
|
77
|
+
throw_if(ERROR_INTEGER_OVERFLOW, floatB == 0);
|
|
78
|
+
floatA.requireFloat();
|
|
79
|
+
floatB.requireFloat();
|
|
80
|
+
return (floatA << 64) / floatB;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
;; sqrtFloat function is used to calculate the square root of a fixed point float
|
|
84
|
+
;; used newton's method to approximate the square root, since the precision is 64 bit, we need to shift 32 bit back
|
|
85
|
+
int sqrtFloat(int x) inline_ref {
|
|
86
|
+
int z = (x + 1) / 2;
|
|
87
|
+
int y = x;
|
|
88
|
+
while (z < y) {
|
|
89
|
+
y = z;
|
|
90
|
+
z = (x / z + z) / 2;
|
|
91
|
+
}
|
|
92
|
+
;; y << (self.precision // 2)
|
|
93
|
+
;; The precision of fixed point float is 64 bit, so we need to shift 32 bit back
|
|
94
|
+
return y << 32;
|
|
95
|
+
}
|