-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: maxSupply extension for jetton
- Loading branch information
1 parent
7398bbe
commit 2e82fd8
Showing
7 changed files
with
190 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 30 additions & 66 deletions
96
contracts/mocks/tokens/jetton/extensions/MaxSupplyImp.tact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,52 @@ | ||
import "../../../traits/tokens/jetton/master.tact"; | ||
import "../../../traits/tokens/jetton/wallet.tact"; | ||
import "../../../traits/tokens/jetton/extensions/MaxSupply.tact"; | ||
message Mint { | ||
amount: Int; | ||
receiver: Address; | ||
} | ||
|
||
contract MaxSupplyJettonImp with Jetton, JettonMaxSupply { | ||
totalSupply: Int as coins; | ||
maxSupply:Int as coins; | ||
import "@stdlib/deploy"; | ||
import "../../../../traits/tokens/jetton/JettonMaster.tact"; | ||
import "../../../../traits/tokens/jetton/JettonWallet.tact"; | ||
import "../../../../traits/tokens/jetton/extensions/MaxSupply.tact"; | ||
|
||
contract MaxSupplyImp with JettonMaster, MaxSupply, Deployable { | ||
total_supply: Int as coins; | ||
max_supply: Int as coins; | ||
owner: Address; | ||
content: Cell; | ||
jetton_content: Cell; | ||
mintable: Bool; | ||
|
||
init(owner: Address, content: Cell, maxSupply:Int){ | ||
self.maxSupply = maxSupply; | ||
self.totalSupply = 0; | ||
init(owner: Address, content: Cell){ | ||
self.total_supply = 0; | ||
self.max_supply = ton("1000"); | ||
self.owner = owner; | ||
self.mintable = true; | ||
self.content = content; | ||
self.jetton_content = content; | ||
} | ||
|
||
receive(msg: Mint){ | ||
let ctx: Context = context(); | ||
require(ctx.sender == self.owner, "Not Owner"); | ||
override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit { | ||
return initOf JettonWalletImp(owner_address, myAddress()); | ||
} | ||
|
||
override inline fun _mint_validate(ctx: Context, msg: JettonMint) { | ||
require(ctx.sender == self.owner, "JettonMaster: Sender is not a Jetton owner"); | ||
require(self.mintable, "JettonMaster: Jetton is not mintable"); | ||
self.requireMaxSupply(msg.amount); | ||
require(self.mintable, "Can't Mint Anymore"); | ||
let toWinit: StateInit = self.getJettonWalletInit(msg.receiver); // Create message | ||
self.mint(msg.receiver, msg.amount, self.owner, toWinit); // (to, amount, response_destination) | ||
} | ||
|
||
receive("Owner: MintClose"){ | ||
receive("Mint:Close"){ | ||
let ctx: Context = context(); | ||
require(ctx.sender == self.owner, "Not Owner"); | ||
require(ctx.sender == self.owner, "JettonMaster: Sender is not a Jetton owner"); | ||
self.mintable = false; | ||
} | ||
|
||
receive(msg: TokenBurnNotification){ | ||
let toWinit: StateInit = self.getJettonWalletInit(msg.owner); // Create message | ||
self.tokenBurnNotification(msg, toWinit); | ||
} | ||
|
||
fun getJettonWalletInit(address: Address): StateInit { | ||
return initOf JettonSampleWalletImp(myAddress(), address); | ||
} | ||
|
||
get fun get_jetton_data(): JettonData { | ||
let winit: StateInit = self.getJettonWalletInit(myAddress()); | ||
return self.get_jetton_data_handler(winit); | ||
} | ||
|
||
get fun get_wallet_address(owner: Address): Address { | ||
let winit: StateInit = self.getJettonWalletInit(owner); | ||
return self.get_wallet_address_handler(winit); | ||
} | ||
} | ||
|
||
contract JettonSampleWalletImp with JettonDefaultWallet { | ||
balance: Int; | ||
contract JettonWalletImp with JettonWallet, Deployable { | ||
balance: Int as coins = 0; | ||
owner: Address; | ||
master: Address; | ||
init(_master: Address, _owner: Address){ | ||
self.balance = 0; | ||
self.master = _master; | ||
self.owner = _owner; | ||
} | ||
jetton_master: Address; | ||
|
||
receive(msg: TokenTransfer){ | ||
let init: StateInit = initOf JettonSampleWalletImp(self.master, msg.destination); | ||
self.tokenTransfer(msg, init); | ||
} | ||
|
||
receive(msg: TokenBurn){ | ||
self.tokenBurn(msg); | ||
} | ||
|
||
receive(msg: TokenTransferInternal){ | ||
// 0x178d4519 | ||
let sinit: StateInit = initOf JettonSampleWalletImp(self.master, msg.from); | ||
self.tokenTransferInternal(msg, sinit); | ||
init(owner: Address, jetton_master: Address) { | ||
self.owner = owner; | ||
self.jetton_master = jetton_master; | ||
} | ||
|
||
get fun get_wallet_data(): JettonWalletData { | ||
let sinit: Cell = initOf JettonSampleWalletImp(self.master, self.owner).code; | ||
return self.get_wallet_data_handler(sinit); | ||
override inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit { | ||
return initOf JettonWalletImp(owner_address, self.jetton_master); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
trait JettonMaxSupply { | ||
maxSupply: Int; | ||
totalSupply: Int; | ||
trait MaxSupply { | ||
max_supply: Int; | ||
total_supply: Int; | ||
|
||
fun requireMaxSupply(mintAmount: Int) { | ||
if(self.maxSupply < (self.totalSupply + mintAmount)){ | ||
if(self.max_supply < (self.total_supply + mintAmount)){ | ||
throw(7878); | ||
} | ||
} | ||
|
||
fun checkMaxSupply(mintAmount: Int): Bool { | ||
return self.maxSupply >= (self.totalSupply + mintAmount); | ||
return self.max_supply >= (self.total_supply + mintAmount); | ||
} | ||
|
||
get fun isMaxSupplyReached(): Bool { | ||
return self.maxSupply == self.totalSupply; | ||
return self.max_supply == self.total_supply; | ||
} | ||
|
||
get fun maxSupply(): Int { | ||
return self.max_supply; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.