@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,154 @@
|
|
|
1
|
+
message TransferJettonDistributor {
|
|
2
|
+
tokenJettonAddress: Address;
|
|
3
|
+
tokenJettonAmount: Int as coins;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
message JettonBurnDistributor {
|
|
7
|
+
tokenJettonAddress: Address;
|
|
8
|
+
tokenJettonAmount: Int as coins;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
message(0x595f07bc) JettonBurn {
|
|
12
|
+
queryId: Int as uint64;
|
|
13
|
+
amount: Int as coins;
|
|
14
|
+
responseDestination: Address?;
|
|
15
|
+
customPayload: Cell? = null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
message NativeSwapDistributor {
|
|
19
|
+
poolAddress: Address;
|
|
20
|
+
amount: Int as coins;
|
|
21
|
+
limit: Int as coins;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
message(0xea06185d) NativeSwap {
|
|
25
|
+
// Unique identifier used to trace transactions across multiple contracts
|
|
26
|
+
// Defaults to 0, which means we don't mark messages to trace their chains
|
|
27
|
+
queryId: Int as uint64 = 0;
|
|
28
|
+
|
|
29
|
+
// Toncoin amount for the swap
|
|
30
|
+
amount: Int as coins;
|
|
31
|
+
|
|
32
|
+
// Inlined fields of SwapStep Struct
|
|
33
|
+
poolAddress: Address;
|
|
34
|
+
kind: Int as uint1 = 0;
|
|
35
|
+
limit: Int as coins = 0;
|
|
36
|
+
nextStep: SwapStep? = null;
|
|
37
|
+
|
|
38
|
+
// Set of parameters relevant for the whole swap
|
|
39
|
+
swapParams: SwapParams;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
message JettonSwapDistributor{
|
|
43
|
+
poolAddress: Address;
|
|
44
|
+
vaultAddress: Address;
|
|
45
|
+
tokenJettonAddress: Address;
|
|
46
|
+
tokenJettonAmount: Int as coins;
|
|
47
|
+
limit: Int as coins;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
message(0xe3a0d482) JettonSwapPayload {
|
|
51
|
+
// Inlined fields of SwapStep Struct
|
|
52
|
+
poolAddress: Address;
|
|
53
|
+
kind: Int as uint1 = 0;
|
|
54
|
+
limit: Int as coins = 0;
|
|
55
|
+
nextStep: SwapStep? = null;
|
|
56
|
+
|
|
57
|
+
// Set of parameters relevant for the whole swap
|
|
58
|
+
swapParams: SwapParams;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
struct SwapStep {
|
|
62
|
+
poolAddress: Address;
|
|
63
|
+
kind: Int as uint1 = 0;
|
|
64
|
+
limit: Int as coins = 0;
|
|
65
|
+
nextStep: Cell?;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
struct SwapParams {
|
|
69
|
+
deadline: Int as uint32 = 0;
|
|
70
|
+
recipientAddress: Address? = null;
|
|
71
|
+
referralAddress: Address? = null;
|
|
72
|
+
fulfillPayload: Cell? = null;
|
|
73
|
+
rejectPayload: Cell? = null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
message JettonProvideLiquidityDistributor {
|
|
77
|
+
poolAddress: Address;
|
|
78
|
+
tokenAJettonAddress: Address;
|
|
79
|
+
tokenBJettonAddress: Address;
|
|
80
|
+
tokenAJettonAmount: Int as coins;
|
|
81
|
+
tokenBJettonAmount: Int as coins;
|
|
82
|
+
minimalLpAmount: Int as coins;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// https://docs.dedust.io/reference/tlb-schemes#message-deposit_liquidity-1
|
|
86
|
+
message(0x40e108d6) JettonDepositLiquidity {
|
|
87
|
+
// Pool type: 0 for volatile, 1 for stable
|
|
88
|
+
// Volatile pool is based on the "Constant Product" formula
|
|
89
|
+
// Stable-swap pool is optimized for assets of near-equal value,
|
|
90
|
+
// e.g. USDT/USDC, TON/stTON, etc.
|
|
91
|
+
poolType: Int as uint1;
|
|
92
|
+
|
|
93
|
+
// Provided assets
|
|
94
|
+
asset0: Asset;
|
|
95
|
+
asset1: Asset;
|
|
96
|
+
|
|
97
|
+
// Minimal amount of LP tokens to be received
|
|
98
|
+
// If there's less liquidity provided, the provisioning will be rejected
|
|
99
|
+
// Defaults to 0, makes this value ignored
|
|
100
|
+
minimalLpAmount: Int as coins = 0;
|
|
101
|
+
|
|
102
|
+
// Target amount of the first asset
|
|
103
|
+
targetBalances0: Int as coins;
|
|
104
|
+
|
|
105
|
+
// Target amount of the second asset
|
|
106
|
+
targetBalances1: Int as coins;
|
|
107
|
+
|
|
108
|
+
// Custom payload attached to the transaction if the provisioning is successful
|
|
109
|
+
// Defaults to `null`, which means no payload
|
|
110
|
+
fulfillPayload: Cell? = null;
|
|
111
|
+
|
|
112
|
+
// Custom payload attached to the transaction if the provisioning is rejected
|
|
113
|
+
// Defaults to `null`, which means no payload
|
|
114
|
+
rejectPayload: Cell? = null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
message NativeProvideLiquidityDistributor {
|
|
118
|
+
jettonWalletAddress: Address;
|
|
119
|
+
jettonMasterAddress: Address;
|
|
120
|
+
jettonAmount: Int as coins;
|
|
121
|
+
nativeAmount: Int as coins;
|
|
122
|
+
minimalLpAmount: Int as coins;
|
|
123
|
+
vaultAddress: Address;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/// https://docs.dedust.io/reference/tlb-schemes#message-deposit_liquidity
|
|
127
|
+
message(0xd55e4686) NativeDepositLiquidity {
|
|
128
|
+
// Unique identifier used to trace transactions across multiple contracts
|
|
129
|
+
// Defaults to 0, which means we don't mark messages to trace their chains
|
|
130
|
+
queryId: Int as uint64 = 0;
|
|
131
|
+
|
|
132
|
+
// Toncoin amount for the deposit
|
|
133
|
+
amount: Int as coins;
|
|
134
|
+
|
|
135
|
+
// Inlined fields of JettonDepositLiquidity Message without the opcode prefix
|
|
136
|
+
poolType: Int as uint1;
|
|
137
|
+
asset0: Asset;
|
|
138
|
+
asset1: Asset;
|
|
139
|
+
minimalLpAmount: Int as coins = 0;
|
|
140
|
+
targetBalances0: Int as coins;
|
|
141
|
+
targetBalances1: Int as coins;
|
|
142
|
+
fulfillPayload: Cell? = null;
|
|
143
|
+
rejectPayload: Cell? = null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// https://docs.dedust.io/reference/tlb-schemes#asset
|
|
147
|
+
struct Asset {
|
|
148
|
+
// Specify 0 for native (TON) and omit all following fields
|
|
149
|
+
// Specify 1 for Jetton and then you must set non-null values for the following fields
|
|
150
|
+
type: Int as uint4;
|
|
151
|
+
|
|
152
|
+
workchain: Int as uint8 = 0; // Both this zeroes will be removed during .build() function. Only type will remain.
|
|
153
|
+
address: Int as uint256 = 0;
|
|
154
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
message WithdrawMessage {
|
|
2
|
+
amount: Int as coins;
|
|
3
|
+
receiver: Address;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
message SetFees {
|
|
7
|
+
newNapFee: Int as coins;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
message(0xe3a0d482) JettonSwapPayload {
|
|
11
|
+
// Inlined fields of SwapStep Struct
|
|
12
|
+
poolAddress: Address;
|
|
13
|
+
kind: Int as uint1 = 0;
|
|
14
|
+
limit: Int as coins = 0;
|
|
15
|
+
nextStep: SwapStep? = null;
|
|
16
|
+
|
|
17
|
+
// Set of parameters relevant for the whole swap
|
|
18
|
+
swapParams: SwapParams;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
struct SwapStep {
|
|
22
|
+
poolAddress: Address;
|
|
23
|
+
kind: Int as uint1 = 0;
|
|
24
|
+
limit: Int as coins = 0;
|
|
25
|
+
nextStep: Cell?;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
struct SwapParams {
|
|
29
|
+
deadline: Int as uint32 = 0;
|
|
30
|
+
recipientAddress: Address? = null;
|
|
31
|
+
referralAddress: Address? = null;
|
|
32
|
+
fulfillPayload: Cell? = null;
|
|
33
|
+
rejectPayload: Cell? = null;
|
|
34
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file provides traits for TEP-0074, TEP-0064 jetton standard
|
|
3
|
+
|
|
4
|
+
[TEP0074](https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md)
|
|
5
|
+
[Official FunC implementation](https://github.com/ton-blockchain/token-contract/blob/main/ft/jetton-wallet.fc)
|
|
6
|
+
[Ton Minter Contract](https://github.com/ton-blockchain/minter-contract)
|
|
7
|
+
[Tact Template](https://github.com/howardpen9/jetton-implementation-in-tact/blob/main/sources/contract.tact)
|
|
8
|
+
*/
|
|
9
|
+
import "./JettonWallet";
|
|
10
|
+
|
|
11
|
+
struct JettonData {
|
|
12
|
+
total_supply: Int as coins; // the total number of issues jettons
|
|
13
|
+
mintable: Bool; // flag which indicates whether number of jettons can increase admin_address
|
|
14
|
+
admin_address: Address; // address of smart-contrac which control Jetton
|
|
15
|
+
jetton_content: Cell; // data in accordance to Token Data Standard #64
|
|
16
|
+
jetton_wallet_code: Cell; // code of wallet for that jetton
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
message JettonMint {
|
|
20
|
+
origin: Address; // address of origin mint request (may be wallet v4)
|
|
21
|
+
receiver: Address; // address of receiver
|
|
22
|
+
amount: Int; // amount of jettons to mint
|
|
23
|
+
custom_payload: Cell?; // optional custom data
|
|
24
|
+
forward_ton_amount: Int as coins;
|
|
25
|
+
forward_payload: Slice as remaining;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
trait JettonMaster {
|
|
29
|
+
total_supply: Int; // the total number of issued jettons
|
|
30
|
+
mintable: Bool; // flag which indicates whether minting is allowed
|
|
31
|
+
owner: Address; // owner of this jetton
|
|
32
|
+
jetton_content: Cell; // data in accordance to Token Data Standard #64
|
|
33
|
+
|
|
34
|
+
//********************************************//
|
|
35
|
+
// Messages //
|
|
36
|
+
//********************************************//
|
|
37
|
+
|
|
38
|
+
// @dev JettonBurnNotification is sent from Jetton wallet after burning jettons
|
|
39
|
+
receive(msg: JettonBurnNotification) {
|
|
40
|
+
let ctx: Context = context();
|
|
41
|
+
self._burn_notification_validate(ctx, msg);
|
|
42
|
+
self._burn_notification(ctx, msg);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// @dev JettonMint is sent from user to mint jettons
|
|
46
|
+
receive(msg: JettonMint) {
|
|
47
|
+
let ctx: Context = context();
|
|
48
|
+
self._mint_validate(ctx, msg);
|
|
49
|
+
self._mint(ctx, msg);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//********************************************//
|
|
53
|
+
// Internal functions //
|
|
54
|
+
//********************************************//
|
|
55
|
+
|
|
56
|
+
// @dev calculate_jetton_wallet_init retrieve init code of a jetton wallet
|
|
57
|
+
// @note one MUST override this function in inherited contract
|
|
58
|
+
abstract inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit;
|
|
59
|
+
|
|
60
|
+
// @dev _mint_validate conduct some custom validating before mint
|
|
61
|
+
virtual inline fun _mint_validate(ctx: Context, msg: JettonMint) {
|
|
62
|
+
require(ctx.sender == self.owner, "JettonMaster: Sender is not a Jetton owner");
|
|
63
|
+
require(self.mintable, "JettonMaster: Jetton is not mintable");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// @dev _mint mint jettons
|
|
67
|
+
virtual inline fun _mint(ctx: Context, msg: JettonMint) {
|
|
68
|
+
let initCode: StateInit = self.calculate_jetton_wallet_init(msg.receiver);
|
|
69
|
+
self.total_supply = self.total_supply + msg.amount;
|
|
70
|
+
send(SendParameters{
|
|
71
|
+
to: contractAddress(initCode),
|
|
72
|
+
value: 0,
|
|
73
|
+
bounce: true,
|
|
74
|
+
mode: SendRemainingValue,
|
|
75
|
+
body: JettonInternalTransfer{
|
|
76
|
+
query_id: 0,
|
|
77
|
+
amount: msg.amount,
|
|
78
|
+
response_address: msg.origin,
|
|
79
|
+
from: myAddress(),
|
|
80
|
+
forward_ton_amount: msg.forward_ton_amount,
|
|
81
|
+
forward_payload: msg.forward_payload
|
|
82
|
+
}.toCell(),
|
|
83
|
+
code: initCode.code,
|
|
84
|
+
data: initCode.data
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// @dev _burn_notification_validate perform some custom validation after receiving JettonBurnNotification sent from Jetton wallet
|
|
89
|
+
virtual inline fun _burn_notification_validate(ctx: Context, msg: JettonBurnNotification) {
|
|
90
|
+
let initCode: StateInit = self.calculate_jetton_wallet_init(msg.sender);
|
|
91
|
+
require(ctx.sender == contractAddress(initCode), "Sender is not a Jetton wallet");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// @dev _burn_notification dwindles total_supply and send notification to wallet after receiving JettonBurnNotification
|
|
95
|
+
inline fun _burn_notification(ctx: Context, msg: JettonBurnNotification) {
|
|
96
|
+
self.total_supply = self.total_supply - msg.amount;
|
|
97
|
+
if(msg.response_destination != newAddress(0, 0)){
|
|
98
|
+
send(SendParameters{
|
|
99
|
+
to: msg.response_destination,
|
|
100
|
+
value: 0,
|
|
101
|
+
bounce: false,
|
|
102
|
+
mode: SendRemainingValue + SendIgnoreErrors
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//*********************************//
|
|
108
|
+
// Getters //
|
|
109
|
+
//*********************************//
|
|
110
|
+
|
|
111
|
+
// @dev get_jetton_data retrieve information of this jetton
|
|
112
|
+
get fun get_jetton_data(): JettonData {
|
|
113
|
+
return JettonData{
|
|
114
|
+
total_supply: self.total_supply,
|
|
115
|
+
mintable: self.mintable,
|
|
116
|
+
admin_address: self.owner,
|
|
117
|
+
jetton_content: self.jetton_content,
|
|
118
|
+
jetton_wallet_code: self.calculate_jetton_wallet_init(myAddress()).code
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// @dev get_wallet_address call calculate_jetton_wallet_init and return address of wallet
|
|
123
|
+
get fun get_wallet_address(owner_address: Address): Address {
|
|
124
|
+
let initCode: StateInit = self.calculate_jetton_wallet_init(owner_address);
|
|
125
|
+
return contractAddress(initCode);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
This file provides traits for TEP-0074 jetton standard
|
|
3
|
+
|
|
4
|
+
[TEP0074](https://github.com/ton-blockchain/TEPs/blob/master/text/0074-jettons-standard.md)
|
|
5
|
+
[Official FunC implementation](https://github.com/ton-blockchain/token-contract/blob/main/ft/jetton-wallet.fc)
|
|
6
|
+
[Ton Minter Contract](https://github.com/ton-blockchain/minter-contract)
|
|
7
|
+
[Tact Template](https://github.com/howardpen9/jetton-implementation-in-tact/blob/main/sources/contract.tact)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
message(0x0f8a7ea5) JettonTransfer {
|
|
11
|
+
query_id: Int as uint64; // arbitrary request number
|
|
12
|
+
amount: Int as coins; // amount of jettons to transfer
|
|
13
|
+
destination: Address; // address of the new owner of the jettons
|
|
14
|
+
response_destination: Address; // address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.
|
|
15
|
+
custom_payload: Cell?; // optional custom payload
|
|
16
|
+
forward_ton_amount: Int as coins; // the amount of nanotons to be sent to the destination address.
|
|
17
|
+
forward_payload: Slice as remaining; // optional custom data that should be sent to the destination address.
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
message(0x7362d09c) JettonTransferNotification {
|
|
21
|
+
query_id: Int as uint64; // arbitrary request number
|
|
22
|
+
amount: Int as coins; // amount of jettons to transfer
|
|
23
|
+
sender: Address; // address of the sender of the jettons
|
|
24
|
+
forward_payload: Slice as remaining; // optional custom payload
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
message(0x595f07bc) JettonBurn {
|
|
28
|
+
query_id: Int as uint64; // arbitrary request number
|
|
29
|
+
amount: Int as coins; // amount of jettons to burn
|
|
30
|
+
response_destination: Address; // address where to send a response with confirmation of a successful burn and the rest of the incoming message coins.
|
|
31
|
+
custom_payload: Cell?; // optional custom payload
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
message(0xd53276db) JettonExcesses {
|
|
35
|
+
query_id: Int as uint64; // arbitrary request number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
message(0x178d4519) JettonInternalTransfer {
|
|
39
|
+
query_id: Int as uint64; // arbitrary request number
|
|
40
|
+
amount: Int as coins; // amount of jettons to transfer
|
|
41
|
+
from: Address; // address of the sender of the jettons
|
|
42
|
+
response_address: Address; // address where to send a response with confirmation of a successful transfer and the rest of the incoming message coins.
|
|
43
|
+
forward_ton_amount: Int as coins; // the amount of nanotons to be sent to the destination address.
|
|
44
|
+
forward_payload: Slice as remaining; // optional custom data that should be sent to the destination address.
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
message(0x7bdd97de) JettonBurnNotification {
|
|
48
|
+
query_id: Int as uint64; // arbitrary request number
|
|
49
|
+
amount: Int as coins; // amount of jettons to burn
|
|
50
|
+
sender: Address; // address of the sender of the jettons
|
|
51
|
+
response_destination: Address; // address where to send a response with confirmation of a successful burn and the rest of the incoming message coins.
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
struct WalletData {
|
|
55
|
+
balance: Int as coins; // amount of jettons on wallet
|
|
56
|
+
owner: Address; // address of wallet owner;
|
|
57
|
+
jetton: Address; // address of Jetton master-address
|
|
58
|
+
jetton_wallet_code: Cell; // with code of this wallet
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
trait JettonWallet {
|
|
63
|
+
balance: Int;
|
|
64
|
+
owner: Address;
|
|
65
|
+
jetton_master: Address;
|
|
66
|
+
virtual const gasConsumption: Int = ton("0.01");
|
|
67
|
+
virtual const minTonsForStorage: Int = ton("0.01");
|
|
68
|
+
|
|
69
|
+
//********************************************//
|
|
70
|
+
// Messages //
|
|
71
|
+
//********************************************//
|
|
72
|
+
|
|
73
|
+
// @dev JettonTransfer is send from the owner of the jetton wallet to the jetton wallet itself to transfer jettons to another user
|
|
74
|
+
receive(msg: JettonTransfer) {
|
|
75
|
+
let ctx: Context = context();
|
|
76
|
+
self.balance = self.balance - msg.amount;
|
|
77
|
+
require(self.balance >= 0, "JettonWallet: Not enough jettons to transfer");
|
|
78
|
+
self._transfer_validate(ctx, msg);
|
|
79
|
+
self._transfer_estimate_remain_value(ctx, msg);
|
|
80
|
+
self._transfer_jetton(ctx, msg);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// @dev JettonBurn is send from the owner of the jetton wallet to the jetton wallet itself to burn jettons
|
|
84
|
+
receive(msg: JettonBurn) {
|
|
85
|
+
let ctx: Context = context();
|
|
86
|
+
self.balance = self.balance - msg.amount;
|
|
87
|
+
require(self.balance >= 0, "JettonWallet: Not enough balance to burn tokens");
|
|
88
|
+
self._burn_validate(ctx, msg);
|
|
89
|
+
self._burn_tokens(ctx, msg);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// @dev JettonInternalTransfer is send from the jetton master or jetton wallet to the jetton wallet itself to transfer jettons to this jetton wallet
|
|
93
|
+
receive(msg: JettonInternalTransfer) {
|
|
94
|
+
let ctx: Context = context();
|
|
95
|
+
self.balance = self.balance + msg.amount;
|
|
96
|
+
require(self.balance >= 0, "JettonWallet: Not allow negative balance after internal transfer");
|
|
97
|
+
self._internal_transfer_validate(ctx, msg);
|
|
98
|
+
let remain: Int = self._internal_transfer_estimate_remain_value(ctx, msg);
|
|
99
|
+
if (msg.forward_ton_amount > 0){
|
|
100
|
+
self._internal_transfer_notification(ctx, msg);
|
|
101
|
+
}
|
|
102
|
+
self._internal_transfer_excesses(ctx, msg, remain);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
bounced(src: bounced<JettonInternalTransfer>) {
|
|
106
|
+
self.balance = self.balance + src.amount;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
bounced(src: bounced<JettonBurnNotification>) {
|
|
110
|
+
self.balance = self.balance + src.amount;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
//********************************************//
|
|
115
|
+
// Internal functions //
|
|
116
|
+
//********************************************//
|
|
117
|
+
|
|
118
|
+
// @dev calculate_jetton_wallet_init will get init code of a jetton wallet by provided it's owner address
|
|
119
|
+
// @note one MUST override this function and return state init of the inherited jetton wallet implementation
|
|
120
|
+
abstract inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit;
|
|
121
|
+
|
|
122
|
+
// @dev _internal_tranfer_validate will validate internal transfer message, usually it will check that sender is a jetton master or jetton wallet
|
|
123
|
+
// @note this function will triggered on receiving JettonTransfer message
|
|
124
|
+
virtual inline fun _internal_transfer_validate(ctx: Context, msg: JettonInternalTransfer) {
|
|
125
|
+
if(ctx.sender != self.jetton_master){
|
|
126
|
+
let init: StateInit = self.calculate_jetton_wallet_init(msg.from);
|
|
127
|
+
require(ctx.sender == contractAddress(init), "JettonWallet: Only Jetton master or Jetton wallet can call this function");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// @dev _internal_transfer_estimate_remain_value will estimate remain value after deducting storage fee, forward fee and gas consumption
|
|
132
|
+
virtual inline fun _internal_transfer_estimate_remain_value(ctx: Context, msg: JettonInternalTransfer): Int {
|
|
133
|
+
let tonBalanceBeforeMsg: Int = myBalance() - ctx.value;
|
|
134
|
+
let storage_fee: Int = self.minTonsForStorage - min(tonBalanceBeforeMsg, self.minTonsForStorage);
|
|
135
|
+
let remain: Int = ctx.value - (storage_fee + self.gasConsumption);
|
|
136
|
+
if (msg.forward_ton_amount > 0) {
|
|
137
|
+
remain = remain - (ctx.readForwardFee() + msg.forward_ton_amount);
|
|
138
|
+
}
|
|
139
|
+
return remain;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// @dev _internal_transfer_notification will send notification to the owner of the jetton wallet
|
|
143
|
+
virtual inline fun _internal_transfer_notification(ctx: Context, msg: JettonInternalTransfer) {
|
|
144
|
+
if (msg.forward_ton_amount > 0) {
|
|
145
|
+
send(SendParameters{
|
|
146
|
+
to: self.owner,
|
|
147
|
+
value: msg.forward_ton_amount,
|
|
148
|
+
mode: SendPayGasSeparately,
|
|
149
|
+
bounce: false,
|
|
150
|
+
body: JettonTransferNotification{
|
|
151
|
+
query_id: msg.query_id,
|
|
152
|
+
amount: msg.amount,
|
|
153
|
+
sender: msg.from,
|
|
154
|
+
forward_payload: msg.forward_payload
|
|
155
|
+
}.toCell()
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// @dev _internal_transfer_excesses will send excesses message back after transfer action completed
|
|
161
|
+
virtual inline fun _internal_transfer_excesses(ctx: Context, msg: JettonInternalTransfer, remain: Int){
|
|
162
|
+
if((msg.response_address != newAddress(0, 0)) && remain > 0){
|
|
163
|
+
send(SendParameters{
|
|
164
|
+
to: msg.response_address,
|
|
165
|
+
value: remain,
|
|
166
|
+
bounce: false,
|
|
167
|
+
mode: SendIgnoreErrors,
|
|
168
|
+
body: JettonExcesses{
|
|
169
|
+
query_id: msg.query_id
|
|
170
|
+
}.toCell()
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// @dev _burn_validate will conduct custom checking when receiving JettonBurn message
|
|
176
|
+
virtual inline fun _burn_validate(ctx: Context, msg: JettonBurn) {
|
|
177
|
+
require(ctx.sender == self.owner, "JettonWallet: Only owner can burn tokens");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// @dev _burn_tokens will burn tokens and send JettonBurnNotification back to the jetton master
|
|
181
|
+
// @note this message is bounceable, if burn action failed, the message will be bounced back, you should increase the balance of the wallet
|
|
182
|
+
virtual inline fun _burn_tokens(ctx: Context, msg: JettonBurn) {
|
|
183
|
+
send(SendParameters{
|
|
184
|
+
to: self.jetton_master,
|
|
185
|
+
value: 0,
|
|
186
|
+
mode: SendRemainingValue,
|
|
187
|
+
bounce: true,
|
|
188
|
+
body: JettonBurnNotification{
|
|
189
|
+
query_id: msg.query_id,
|
|
190
|
+
amount: msg.amount,
|
|
191
|
+
sender: self.owner,
|
|
192
|
+
response_destination: msg.response_destination
|
|
193
|
+
}.toCell()
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// @dev _transfer_validate will conduct custom checking when receiving JettonTransfer message
|
|
198
|
+
virtual inline fun _transfer_validate(ctx: Context, msg: JettonTransfer) {
|
|
199
|
+
require(ctx.sender == self.owner, "Only owner can call this function");
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// @dev _transfer_estimate_remain_value will estimate remain value after deducting storage fee, forward fee and gas consumption
|
|
204
|
+
virtual inline fun _transfer_estimate_remain_value(ctx: Context, msg: JettonTransfer) {
|
|
205
|
+
let fwd_count: Int = 1;
|
|
206
|
+
if (msg.forward_ton_amount > 0) {
|
|
207
|
+
fwd_count = 2;
|
|
208
|
+
}
|
|
209
|
+
require(ctx.value > fwd_count * ctx.readForwardFee() + 2 * self.gasConsumption + self.minTonsForStorage, "Not enough funds to transfer");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// @dev _transfer_jetton will transfer jettons to the jetton wallet of the destination address (owner of jetton wallet)
|
|
213
|
+
// @note this message is bounceable, if transfer action failed, the message will be bounced back, you should increase the balance of the wallet
|
|
214
|
+
virtual inline fun _transfer_jetton(ctx: Context, msg: JettonTransfer) {
|
|
215
|
+
let init: StateInit = self.calculate_jetton_wallet_init(msg.destination);
|
|
216
|
+
let receiver: Address = contractAddress(init);
|
|
217
|
+
send(SendParameters{
|
|
218
|
+
to: receiver,
|
|
219
|
+
value: 0,
|
|
220
|
+
bounce: true,
|
|
221
|
+
mode: SendRemainingValue,
|
|
222
|
+
body: JettonInternalTransfer{
|
|
223
|
+
query_id: msg.query_id,
|
|
224
|
+
amount: msg.amount,
|
|
225
|
+
response_address: msg.response_destination,
|
|
226
|
+
from: self.owner,
|
|
227
|
+
forward_ton_amount: msg.forward_ton_amount,
|
|
228
|
+
forward_payload: msg.forward_payload
|
|
229
|
+
}.toCell(),
|
|
230
|
+
code: init.code,
|
|
231
|
+
data: init.data
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
//*********************************//
|
|
236
|
+
// Getters //
|
|
237
|
+
//*********************************//
|
|
238
|
+
|
|
239
|
+
// @dev get_wallet_data will return wallet data, which follows TEP 0074 standard
|
|
240
|
+
get fun get_wallet_data(): WalletData{
|
|
241
|
+
return WalletData {
|
|
242
|
+
balance: self.balance,
|
|
243
|
+
owner: self.owner,
|
|
244
|
+
jetton: self.jetton_master,
|
|
245
|
+
jetton_wallet_code: self.calculate_jetton_wallet_init(self.owner).code
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*
|
|
2
|
+
NFT Auciton Market Error Code :
|
|
3
|
+
3724: Bid doesn't meet the minimum increase requirement
|
|
4
|
+
11017: Contract is already initialized
|
|
5
|
+
19941: Only owner can build nft auction contract
|
|
6
|
+
20805: Only owner can init auction end time.
|
|
7
|
+
20844: BuyNowPrice must be greater than reservePrice
|
|
8
|
+
24136: Auction was not set before.
|
|
9
|
+
37031: NFT Seller cannot bid
|
|
10
|
+
42237: Contract is not initialized
|
|
11
|
+
42345: Only owner can revise auction contract
|
|
12
|
+
45065: Auction not yet ended
|
|
13
|
+
46984: Auction ended
|
|
14
|
+
50905: Auction bid period ended
|
|
15
|
+
54143: This NFT didn't transfer to NFT Auction Market Contract yet.
|
|
16
|
+
55234: BuyNowPrice must be greater than reservePrice.
|
|
17
|
+
58706: Auction was already set for this NFT.
|
|
18
|
+
59374: Cannot update reserve price and buy now price at the same time.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
NFT Auction Error Code :
|
|
23
|
+
3724: Bid doesn't meet the minimum increase requirement
|
|
24
|
+
11017: Contract is already initialized
|
|
25
|
+
19941: Only owner can build nft auction contract
|
|
26
|
+
20805: Only owner can init auction end time.
|
|
27
|
+
20844: BuyNowPrice must be greater than reservePrice
|
|
28
|
+
24136: Auction was not set before.
|
|
29
|
+
37031: NFT Seller cannot bid
|
|
30
|
+
42237: Contract is not initialized
|
|
31
|
+
42345: Only owner can revise auction contract
|
|
32
|
+
45065: Auction not yet ended
|
|
33
|
+
46984: Auction ended
|
|
34
|
+
50905: Auction bid period ended
|
|
35
|
+
54143: This NFT didn't transfer to NFT Auction Market Contract yet.
|
|
36
|
+
55234: BuyNowPrice must be greater than reservePrice.
|
|
37
|
+
58706: Auction was already set for this NFT.
|
|
38
|
+
59374: Cannot update reserve price and buy now price at the same time.
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
Error code Old Version :
|
|
43
|
+
1000: Auction not yet ended.
|
|
44
|
+
1001: Only owner can do this.
|
|
45
|
+
1002: Auction was not set before.
|
|
46
|
+
1003: This NFT didn't transfer to NFT Auction Market Contract yet.
|
|
47
|
+
1004: Contract is already initialized.
|
|
48
|
+
1005: Auction ended.
|
|
49
|
+
1006: NFT Seller cannot bid.
|
|
50
|
+
1007: Bid doesn't meet the minimum increase requirement.
|
|
51
|
+
1008: Auction was already set for this NFT.
|
|
52
|
+
1009: Auction did not set up before.
|
|
53
|
+
1010: BuyNowPrice must be greater than reservePrice.
|
|
54
|
+
1011: Cannot update reserve price and buy now price at the same time.
|
|
55
|
+
*/
|