diff --git a/nft/compile.sh b/nft/compile.sh index 1d41921..640cd6c 100755 --- a/nft/compile.sh +++ b/nft/compile.sh @@ -5,11 +5,11 @@ rm build/nft-collection-editable-code.fif rm build/nft-marketplace-code.fif rm build/nft-sale-code.fif -func -o build/nft-item-code.fif -SPA ../stdlib.fc params.fc op-codes.fc nft-item.fc -func -o build/nft-item-editable-code.fif -SPA ../stdlib.fc params.fc op-codes.fc nft-item-editable-DRAFT.fc -func -o build/nft-collection-code.fif -SPA ../stdlib.fc params.fc op-codes.fc nft-collection.fc -func -o build/nft-collection-editable-code.fif -SPA ../stdlib.fc params.fc op-codes.fc nft-collection-editable.fc -func -o build/nft-marketplace-code.fif -SPA ../stdlib.fc op-codes.fc nft-marketplace.fc -func -o build/nft-sale-code.fif -SPA ../stdlib.fc op-codes.fc nft-sale.fc +func -o build/nft-item-code.fif -SPA ../stdlib.fc nft-item.fc +func -o build/nft-item-editable-code.fif -SPA ../stdlib.fc nft-item-editable-DRAFT.fc +func -o build/nft-collection-code.fif -SPA ../stdlib.fc nft-collection.fc +func -o build/nft-collection-editable-code.fif -SPA ../stdlib.fc nft-collection-editable.fc +func -o build/nft-marketplace-code.fif -SPA ../stdlib.fc nft-marketplace.fc +func -o build/nft-sale-code.fif -SPA ../stdlib.fc nft-sale.fc fift -s build/print-hex.fif diff --git a/nft/nft-collection-editable.fc b/nft/nft-collection-editable.fc index be76dfd..d7a48ec 100644 --- a/nft/nft-collection-editable.fc +++ b/nft/nft-collection-editable.fc @@ -1,3 +1,8 @@ +#pragma version >=0.2.0; + +#include "op-codes.fc"; +#include "params.fc"; + ;; NFT collection smart contract ;; storage scheme @@ -44,7 +49,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { () deploy_nft_item(int item_index, cell nft_item_code, int amount, cell nft_content) impure { cell state_init = calculate_nft_item_state_init(item_index, nft_item_code); - slice nft_address = calculate_nft_item_address(workchain(), state_init); + slice nft_address = calculate_nft_item_address(workchain, state_init); var msg = begin_cell() .store_uint(0x18, 6) .store_slice(nft_address) @@ -61,7 +66,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { .store_slice(to_address) .store_coins(0) .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) - .store_uint(op::report_royalty_params(), 32) + .store_uint(op::report_royalty_params, 32) .store_uint(query_id, 64) .store_slice(data); send_raw_message(msg.end_cell(), 64); ;; carry all the remaining value of the inbound message @@ -84,7 +89,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { var (owner_address, next_item_index, content, nft_item_code, royalty_params) = load_data(); - if (op == op::get_royalty_params()) { + if (op == op::get_royalty_params) { send_royalty_params(sender_address, query_id, royalty_params.begin_parse()); return (); } @@ -103,7 +108,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { } return (); } - if (op == 2) { ;; batch deploy of new nfts + elseif (op == 2) { ;; batch deploy of new nfts int counter = 0; cell deploy_list = in_msg_body~load_ref(); do { @@ -124,12 +129,12 @@ slice calculate_nft_item_address(int wc, cell state_init) { save_data(owner_address, next_item_index, content, nft_item_code, royalty_params); return (); } - if (op == 3) { ;; change owner + elseif (op == 3) { ;; change owner slice new_owner = in_msg_body~load_msg_addr(); save_data(new_owner, next_item_index, content, nft_item_code, royalty_params); return (); } - if (op == 4) { ;; change content + elseif (op == 4) { ;; change content save_data(owner_address, next_item_index, in_msg_body~load_ref(), nft_item_code, in_msg_body~load_ref()); return (); } @@ -147,7 +152,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { slice get_nft_address_by_index(int index) method_id { var (_, _, _, nft_item_code, _) = load_data(); cell state_init = calculate_nft_item_state_init(index, nft_item_code); - return calculate_nft_item_address(workchain(), state_init); + return calculate_nft_item_address(workchain, state_init); } (int, int, slice) royalty_params() method_id { diff --git a/nft/nft-collection.fc b/nft/nft-collection.fc index 5aaf3a3..04f94bf 100644 --- a/nft/nft-collection.fc +++ b/nft/nft-collection.fc @@ -1,3 +1,8 @@ +#pragma version >=0.2.0; + +#include "op-codes.fc"; +#include "params.fc"; + ;; NFT collection smart contract ;; storage scheme @@ -44,7 +49,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { () deploy_nft_item(int item_index, cell nft_item_code, int amount, cell nft_content) impure { cell state_init = calculate_nft_item_state_init(item_index, nft_item_code); - slice nft_address = calculate_nft_item_address(workchain(), state_init); + slice nft_address = calculate_nft_item_address(workchain, state_init); var msg = begin_cell() .store_uint(0x18, 6) .store_slice(nft_address) @@ -61,7 +66,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { .store_slice(to_address) .store_coins(0) .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) - .store_uint(op::report_royalty_params(), 32) + .store_uint(op::report_royalty_params, 32) .store_uint(query_id, 64) .store_slice(data); send_raw_message(msg.end_cell(), 64); ;; carry all the remaining value of the inbound message @@ -84,7 +89,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { var (owner_address, next_item_index, content, nft_item_code, royalty_params) = load_data(); - if (op == op::get_royalty_params()) { + if (op == op::get_royalty_params) { send_royalty_params(sender_address, query_id, royalty_params.begin_parse()); return (); } @@ -103,7 +108,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { } return (); } - if (op == 2) { ;; batch deploy of new nfts + elseif (op == 2) { ;; batch deploy of new nfts int counter = 0; cell deploy_list = in_msg_body~load_ref(); do { @@ -124,7 +129,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { save_data(owner_address, next_item_index, content, nft_item_code, royalty_params); return (); } - if (op == 3) { ;; change owner + elseif (op == 3) { ;; change owner slice new_owner = in_msg_body~load_msg_addr(); save_data(new_owner, next_item_index, content, nft_item_code, royalty_params); return (); @@ -143,7 +148,7 @@ slice calculate_nft_item_address(int wc, cell state_init) { slice get_nft_address_by_index(int index) method_id { var (_, _, _, nft_item_code, _) = load_data(); cell state_init = calculate_nft_item_state_init(index, nft_item_code); - return calculate_nft_item_address(workchain(), state_init); + return calculate_nft_item_address(workchain, state_init); } (int, int, slice) royalty_params() method_id { diff --git a/nft/nft-item-editable-DRAFT.fc b/nft/nft-item-editable-DRAFT.fc index bc3871b..9692eaa 100644 --- a/nft/nft-item-editable-DRAFT.fc +++ b/nft/nft-item-editable-DRAFT.fc @@ -1,3 +1,8 @@ +#pragma version >=0.2.0; + +#include "op-codes.fc"; +#include "params.fc"; + ;; ;; TON NFT Item Smart Contract ;; @@ -85,11 +90,11 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON throw_unless(402, rest_amount >= 0); ;; base nft spends fixed amount of gas, will not check for response if (forward_amount) { - send_msg(new_owner_address, forward_amount, op::ownership_assigned(), query_id, begin_cell().store_slice(owner_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors + send_msg(new_owner_address, forward_amount, op::ownership_assigned, query_id, begin_cell().store_slice(owner_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors } if (need_response) { force_chain(response_destination); - send_msg(response_destination, rest_amount, op::excesses(), query_id, null(), 1); ;; paying fees, revert on errors + send_msg(response_destination, rest_amount, op::excesses, query_id, null(), 1); ;; paying fees, revert on errors } store_data(index, collection_address, new_owner_address, content, editor_address); @@ -116,11 +121,11 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON throw_unless(402, rest_amount >= 0); ;; base nft spends fixed amount of gas, will not check for response if (forward_amount) { - send_msg(new_editor_address, forward_amount, op::editorship_assigned(), query_id, begin_cell().store_slice(editor_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors + send_msg(new_editor_address, forward_amount, op::editorship_assigned, query_id, begin_cell().store_slice(editor_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors } if (need_response) { force_chain(response_destination); - send_msg(response_destination, rest_amount, op::excesses(), query_id, null(), 1); ;; paying fees, revert on errors + send_msg(response_destination, rest_amount, op::excesses, query_id, null(), 1); ;; paying fees, revert on errors } store_data(index, collection_address, owner_address, content, new_editor_address); @@ -155,19 +160,19 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON int op = in_msg_body~load_uint(32); int query_id = in_msg_body~load_uint(64); - if (op == op::transfer()) { + if (op == op::transfer) { transfer_ownership(my_balance, index, collection_address, owner_address, content, editor_address, sender_address, query_id, in_msg_body, fwd_fee); return (); } - if (op == op::get_static_data()) { - send_msg(sender_address, 0, op::report_static_data(), query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message + elseif (op == op::get_static_data) { + send_msg(sender_address, 0, op::report_static_data, query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message return (); } - if (op == op::transfer_editorship()) { + elseif (op == op::transfer_editorship) { transfer_editorship(my_balance, index, collection_address, owner_address, content, editor_address, sender_address, query_id, in_msg_body, fwd_fee); return (); } - if (op == op::edit_content()) { + elseif (op == op::edit_content) { throw_unless(410, equal_slices(sender_address, editor_address)); store_data(index, collection_address, owner_address, in_msg_body~load_ref(), editor_address); return (); diff --git a/nft/nft-item.fc b/nft/nft-item.fc index 2900754..6249079 100644 --- a/nft/nft-item.fc +++ b/nft/nft-item.fc @@ -1,3 +1,9 @@ +#pragma version >=0.2.0; + + +#include "op-codes.fc"; +#include "params.fc"; + ;; ;; TON NFT Item Smart Contract ;; @@ -14,7 +20,7 @@ -} -int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON +const int min_tons_for_storage = 50000000; ;; 0.05 TON ;; ;; Storage @@ -71,7 +77,7 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON in_msg_body~load_int(1); ;; this nft don't use custom_payload int forward_amount = in_msg_body~load_coins(); - int rest_amount = my_balance - min_tons_for_storage(); + int rest_amount = my_balance - min_tons_for_storage; if (forward_amount) { rest_amount -= (forward_amount + fwd_fees); } @@ -83,11 +89,11 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON throw_unless(402, rest_amount >= 0); ;; base nft spends fixed amount of gas, will not check for response if (forward_amount) { - send_msg(new_owner_address, forward_amount, op::ownership_assigned(), query_id, begin_cell().store_slice(owner_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors + send_msg(new_owner_address, forward_amount, op::ownership_assigned, query_id, begin_cell().store_slice(owner_address).store_slice(in_msg_body), 1); ;; paying fees, revert on errors } if (need_response) { force_chain(response_destination); - send_msg(response_destination, rest_amount, op::excesses(), query_id, null(), 1); ;; paying fees, revert on errors + send_msg(response_destination, rest_amount, op::excesses, query_id, null(), 1); ;; paying fees, revert on errors } store_data(index, collection_address, new_owner_address, content); @@ -123,12 +129,12 @@ int min_tons_for_storage() asm "50000000 PUSHINT"; ;; 0.05 TON int op = in_msg_body~load_uint(32); int query_id = in_msg_body~load_uint(64); - if (op == op::transfer()) { + if (op == op::transfer) { transfer_ownership(my_balance, index, collection_address, owner_address, content, sender_address, query_id, in_msg_body, fwd_fee); return (); } - if (op == op::get_static_data()) { - send_msg(sender_address, 0, op::report_static_data(), query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message + elseif (op == op::get_static_data) { + send_msg(sender_address, 0, op::report_static_data, query_id, begin_cell().store_uint(index, 256).store_slice(collection_address), 64); ;; carry all the remaining value of the inbound message return (); } throw(0xffff); diff --git a/nft/nft-sale.fc b/nft/nft-sale.fc index 8ae807a..b0f7791 100644 --- a/nft/nft-sale.fc +++ b/nft/nft-sale.fc @@ -1,6 +1,10 @@ +#pragma version >=0.2.0; + +#include "op-codes.fc"; + ;; NFT sale smart contract -int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON +const int min_gas_amount = 1000000000; ;; 1 TON (slice, slice, slice, int, cell) load_data() inline { var ds = get_data().begin_parse(); @@ -34,7 +38,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON } () buy(int my_balance, slice marketplace_address, slice nft_address, slice nft_owner_address, int full_price, cell fees_cell, int msg_value, slice sender_address, int query_id) impure { - throw_unless(450, msg_value >= full_price + min_gas_amount()); + throw_unless(450, msg_value >= full_price + min_gas_amount); var (marketplace_fee, royalty_address, royalty_amount) = load_fees(fees_cell); @@ -69,7 +73,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON .store_slice(nft_address) .store_coins(0) .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) - .store_uint(op::transfer(), 32) + .store_uint(op::transfer, 32) .store_uint(query_id, 64) .store_slice(sender_address) ;; new_owner_address .store_slice(sender_address) ;; response_address @@ -103,7 +107,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON throw_unless(500, equal_slices(sender_address, nft_address)); int op = in_msg_body~load_uint(32); - throw_unless(501, op == op::ownership_assigned()); + throw_unless(501, op == op::ownership_assigned); int query_id = in_msg_body~load_uint(64); slice prev_owner_address = in_msg_body~load_msg_addr(); @@ -125,7 +129,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON return (); } - if (op == 2) { ;; buy + elseif (op == 2) { ;; buy buy(my_balance, marketplace_address, nft_address, nft_owner_address, full_price, fees_cell, msg_value, sender_address, query_id); @@ -134,7 +138,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON } if (op == 3) { ;; cancel sale - throw_unless(457, msg_value >= min_gas_amount()); + throw_unless(457, msg_value >= min_gas_amount); throw_unless(458, equal_slices(sender_address, nft_owner_address) | equal_slices(sender_address, marketplace_address)); var msg = begin_cell() @@ -142,7 +146,7 @@ int min_gas_amount() asm "1000000000 PUSHINT"; ;; 1 TON .store_slice(nft_address) .store_coins(0) .store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1) - .store_uint(op::transfer(), 32) + .store_uint(op::transfer, 32) .store_uint(query_id, 64) .store_slice(nft_owner_address) ;; new_owner_address .store_slice(nft_owner_address) ;; response_address; diff --git a/nft/op-codes.fc b/nft/op-codes.fc index 84f31ed..a1c78c4 100644 --- a/nft/op-codes.fc +++ b/nft/op-codes.fc @@ -1,12 +1,12 @@ -int op::transfer() asm "0x5fcc3d14 PUSHINT"; -int op::ownership_assigned() asm "0x05138d91 PUSHINT"; -int op::excesses() asm "0xd53276db PUSHINT"; -int op::get_static_data() asm "0x2fcb26a2 PUSHINT"; -int op::report_static_data() asm "0x8b771735 PUSHINT"; -int op::get_royalty_params() asm "0x693d3950 PUSHINT"; -int op::report_royalty_params() asm "0xa8cb00ad PUSHINT"; +const int op::transfer = 0x5fcc3d14; +const int op::ownership_assigned = 0x05138d91; +const int op::excesses = 0xd53276db; +const int op::get_static_data = 0x2fcb26a2; +const int op::report_static_data = 0x8b771735; +const int op::get_royalty_params = 0x693d3950; +const int op::report_royalty_params = 0xa8cb00ad; ;; NFTEditable -int op::edit_content() asm "0x1a0b9d51 PUSHINT"; -int op::transfer_editorship() asm "0x1c04412a PUSHINT"; -int op::editorship_assigned() asm "0x511a4463 PUSHINT"; +const int op::edit_content = 0x1a0b9d51; +const int op::transfer_editorship = 0x1c04412a; +const int op::editorship_assigned = 0x511a4463; diff --git a/nft/params.fc b/nft/params.fc index e28eac4..6c6ce5f 100644 --- a/nft/params.fc +++ b/nft/params.fc @@ -1,6 +1,6 @@ -int workchain() asm "0 PUSHINT"; +const int workchain = 0; () force_chain(slice addr) impure { (int wc, _) = parse_std_addr(addr); - throw_unless(333, wc == workchain()); + throw_unless(333, wc == workchain); } \ No newline at end of file