Skip to content

Commit

Permalink
feat: maxSupply extension for jetton
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Jul 10, 2024
1 parent 7398bbe commit 2e82fd8
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 128 deletions.
34 changes: 26 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ Additionally, we are exploring potential changes in Tact to support importing di

```plaintext
├── access
│ ├── ownableTransferable2Step
│ └── accessControl
│ ├── OwnableTransferable2Step
│ └── AccessControl
├── utils
│ └── counter
│ └── Counter
├── payments
│ └── paymentSplitter
│ └── PaymentSplitter
└── tokens
└── jetton
├── Jetton
└── extensions
├── maxSupply(in progress)
└── approveable(in progress)
├── MaxSupply
└── Approveable(in progress)
```

## Scripts
Expand All @@ -117,17 +117,35 @@ Additionally, we are exploring potential changes in Tact to support importing di

```plaintext
├── contracts
│ │
│ ├── traits
│ │ │
│ │ └── (trait categories)
│ │ └── (trait files)
│ │ │
│ │ └── (trait sub-categories)
│ │ │
│ │ └── (trait files)
│ └── mocks
│ │ │
│ │ └── (mock categories)
│ │ └── (mock files)
│ │ │
│ │ └── (mock sub-categories)
│ │ │
│ │ └── (mock files)
├── tests
│ │
│ ├── (test categories)
│ │ │
│ │ └── (test files)
│ │
│ └── main.spec.ts
├── wrappers
│ │
│ └──(wrapper file)
├── package.json
└── README.md
```

Expand Down
96 changes: 30 additions & 66 deletions contracts/mocks/tokens/jetton/extensions/MaxSupplyImp.tact
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);
}
}
9 changes: 0 additions & 9 deletions contracts/traits/tokens/jetton/JettonMaster.tact
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ trait JettonMaster {

receive(msg: JettonMint){
let ctx: Context = context();
dump(0);
self._mint_validate(ctx, msg);
dump(1);
self._mint(ctx, msg);
dump(2);
}

receive(msg: JettonBurnNotification){
Expand All @@ -39,11 +36,8 @@ trait JettonMaster {
abstract inline fun calculate_jetton_wallet_init(owner_address: Address): StateInit;

virtual inline fun _mint_validate(ctx: Context, msg: JettonMint) {
dump(3);
require(ctx.sender == self.owner, "JettonMaster: Sender is not a Jetton owner");
dump(4);
require(self.mintable, "JettonMaster: Jetton is not mintable");
dump(5);
}

virtual inline fun _burn_notification_validate(ctx: Context, msg: JettonBurnNotification) {
Expand All @@ -52,10 +46,8 @@ trait JettonMaster {
}

virtual inline fun _mint(ctx: Context, msg: JettonMint) {
dump(6);
let initCode: StateInit = self.calculate_jetton_wallet_init(msg.receiver);
self.total_supply = (self.total_supply + msg.amount);
dump(7);
send(SendParameters{
to: contractAddress(initCode),
value: 0,
Expand All @@ -73,7 +65,6 @@ trait JettonMaster {
data: initCode.data
}
);
dump(8);
}

inline fun _burn_notification(ctx: Context, msg: JettonBurnNotification) {
Expand Down
16 changes: 10 additions & 6 deletions contracts/traits/tokens/jetton/extensions/MaxSupply.tact
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;
}
}
5 changes: 2 additions & 3 deletions tests/main.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { shouldBehaveLikeAccessControl } from './access/AccessControl.behavior';
import { shouldBehaveLikeOwnableTransferable2Step } from './access/OwnableTransferable2Step';
import { shouldBehaveLikePaymentSplitter } from './payments/paymentSplitter.behavior';
import { shouldBehaveLikeBasicJetton } from './tokens/jetton/Jetton.behavior';
import { shouldBehaveLikeApproveableJetton } from './tokens/jetton/extensions/approveable.behavior';
import { shouldBehaveLikeMaxSupplyJetton } from './tokens/jetton/extensions/maxsupply.behavior';
import { shouldBehaveLikeMaxSupply } from './tokens/jetton/extensions/maxsupply.behavior';
import { shouldBehaveLikeCounter } from './utils/Counter.behavior';

describe('OpenGem-contract UnitTests', function () {
Expand All @@ -29,7 +28,7 @@ describe('OpenGem-contract UnitTests', function () {
});
describe('extensions', function () {
describe('maxSupply', function () {
// shouldBehaveLikeMaxSupplyJetton();
shouldBehaveLikeMaxSupply();
});
describe('approveable', function () {
// shouldBehaveLikeApproveableJetton();
Expand Down
Loading

0 comments on commit 2e82fd8

Please sign in to comment.