Skip to content

Commit fed4ae9

Browse files
feat: Simple fees support for Token Create with custom fees (#22275)
Signed-off-by: Josh Marinacci <[email protected]> Signed-off-by: Josh Marinacci <[email protected]>
1 parent daf07a0 commit fed4ae9

File tree

6 files changed

+47
-34
lines changed

6 files changed

+47
-34
lines changed

hapi/hedera-protobuf-java-api/src/main/proto/fees/fee_schedule.proto

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ enum Extra {
9797
CRYPTO_TRANSFER_BASE_FUNGIBLE_CUSTOM_FEES=19;
9898
CRYPTO_TRANSFER_BASE_NFT_CUSTOM_FEES=20;
9999
HOOK_EXECUTION=21;
100-
TOKEN_CREATE_FUNGIBLE=22;
101-
TOKEN_CREATE_NFT=23;
102-
TOKEN_MINT_FUNGIBLE=24;
103-
TOKEN_MINT_NFT=25;
104-
CONSENSUS_CREATE_TOPIC_WITH_CUSTOM_FEE=26;
105-
CONSENSUS_SUBMIT_MESSAGE_WITH_CUSTOM_FEE=27;
100+
TOKEN_CREATE_WITH_CUSTOM_FEE=22;
101+
TOKEN_MINT_NFT=23;
102+
CONSENSUS_CREATE_TOPIC_WITH_CUSTOM_FEE=24;
103+
CONSENSUS_SUBMIT_MESSAGE_WITH_CUSTOM_FEE=25;
106104
}
107105

108106
/**

hedera-node/hedera-file-service-impl/src/main/resources/genesis/simpleFeesSchedules.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
{ "name": "CUSTOM_FEE", "fee": 0 },
2929
{ "name": "GAS", "fee": 1 },
3030
{ "name": "ALLOWANCES", "fee": 500000000 },
31-
{ "name": "TOKEN_CREATE_FUNGIBLE", "fee": 9999000000 },
32-
{ "name": "TOKEN_CREATE_NFT", "fee": 19999000000 },
33-
{ "name": "TOKEN_MINT_FUNGIBLE", "fee": 0 },
31+
{ "name": "TOKEN_CREATE_WITH_CUSTOM_FEE", "fee": 10000000000 },
3432
{ "name": "TOKEN_MINT_NFT", "fee": 199000000 },
3533
{ "name": "AIRDROPS", "fee": 8800 },
3634
{ "name": "HOOK_UPDATES", "fee": 10000000000 },
@@ -185,18 +183,16 @@
185183
"schedule": [
186184
{
187185
"name": "TokenCreate",
188-
"baseFee": 0,
186+
"baseFee": 9999000000,
189187
"extras": [
190188
{"name": "KEYS", "includedCount": 1},
191-
{"name": "TOKEN_CREATE_FUNGIBLE", "includedCount": 0 },
192-
{"name": "TOKEN_CREATE_NFT", "includedCount": 0 }
189+
{"name": "TOKEN_CREATE_WITH_CUSTOM_FEE", "includedCount": 0 }
193190
]
194191
},
195192
{
196193
"name": "TokenMint",
197194
"baseFee": 9000000,
198195
"extras": [
199-
{"name": "TOKEN_MINT_FUNGIBLE", "includedCount": 0 },
200196
{"name": "TOKEN_MINT_NFT", "includedCount": 0 }
201197
]
202198
},

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/calculator/TokenCreateFeeCalculator.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.hiero.hapi.fees.FeeScheduleUtils.lookupServiceFee;
66

77
import com.hedera.hapi.node.base.HederaFunctionality;
8-
import com.hedera.hapi.node.base.TokenType;
98
import com.hedera.hapi.node.transaction.TransactionBody;
109
import com.hedera.node.app.spi.fees.FeeContext;
1110
import com.hedera.node.app.spi.fees.ServiceFeeCalculator;
@@ -55,11 +54,8 @@ public void accumulateServiceFee(
5554
}
5655
addExtraFee(feeResult, serviceDef, Extra.KEYS, feeSchedule, keys);
5756

58-
if (op.tokenType() == TokenType.FUNGIBLE_COMMON) {
59-
addExtraFee(feeResult, serviceDef, Extra.TOKEN_CREATE_FUNGIBLE, feeSchedule, 1);
60-
}
61-
if (op.tokenType() == TokenType.NON_FUNGIBLE_UNIQUE) {
62-
addExtraFee(feeResult, serviceDef, Extra.TOKEN_CREATE_NFT, feeSchedule, 1);
57+
if (!op.customFees().isEmpty()) {
58+
addExtraFee(feeResult, serviceDef, Extra.TOKEN_CREATE_WITH_CUSTOM_FEE, feeSchedule, 1);
6359
}
6460
}
6561

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/calculator/TokenMintFeeCalculator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ public void accumulateServiceFee(
2727
feeResult.addServiceFee(1, serviceDef.baseFee());
2828
var op = txnBody.tokenMintOrThrow();
2929
if (op.amount() > 0) {
30-
addExtraFee(feeResult, serviceDef, Extra.TOKEN_MINT_FUNGIBLE, feeSchedule, op.amount());
3130
addExtraFee(feeResult, serviceDef, Extra.TOKEN_MINT_NFT, feeSchedule, 0);
3231
} else {
33-
addExtraFee(feeResult, serviceDef, Extra.TOKEN_MINT_FUNGIBLE, feeSchedule, 0);
3432
addExtraFee(
3533
feeResult,
3634
serviceDef,

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/TokenServiceFeeCalculatorTests.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void createCommonToken() {
106106
.build();
107107
final var result = feeCalculator.calculateTxFee(body, calculatorState);
108108
assertNotNull(result);
109-
assertEquals(TOKEN_CREATE_BASE_FEE + COMMON_TOKEN_FEE, result.total());
109+
assertEquals(TOKEN_CREATE_BASE_FEE, result.total());
110110
}
111111

112112
@Test
@@ -118,7 +118,7 @@ void createUniqueToken() {
118118
final var result = feeCalculator.calculateTxFee(txBody2, calculatorState);
119119

120120
assertNotNull(result);
121-
assertEquals(TOKEN_CREATE_BASE_FEE + UNIQUE_TOKEN_FEE, result.total());
121+
assertEquals(TOKEN_CREATE_BASE_FEE, result.total());
122122
}
123123

124124
@Test
@@ -133,7 +133,7 @@ void mintCommonToken() {
133133
.build();
134134
final var result = feeCalculator.calculateTxFee(body, calculatorState);
135135
assertNotNull(result);
136-
assertEquals(TOKEN_MINT_BASE_FEE + COMMON_TOKEN_FEE * 10, result.total());
136+
assertEquals(TOKEN_MINT_BASE_FEE, result.total());
137137
}
138138

139139
@Test
@@ -242,25 +242,16 @@ private FeeSchedule createTestFeeSchedule() {
242242
makeExtraDef(Extra.BYTES, 1),
243243
makeExtraDef(Extra.KEYS, 2),
244244
makeExtraDef(Extra.SIGNATURES, 3),
245-
makeExtraDef(Extra.TOKEN_CREATE_FUNGIBLE, COMMON_TOKEN_FEE),
246-
makeExtraDef(Extra.TOKEN_CREATE_NFT, UNIQUE_TOKEN_FEE),
247-
makeExtraDef(Extra.TOKEN_MINT_FUNGIBLE, COMMON_TOKEN_FEE),
248245
makeExtraDef(Extra.TOKEN_MINT_NFT, UNIQUE_TOKEN_FEE),
249246
makeExtraDef(Extra.CUSTOM_FEE, 500))
250247
.network(NetworkFee.DEFAULT.copyBuilder().multiplier(2).build())
251248
.services(makeService(
252249
"Token",
253-
makeServiceFee(
254-
TOKEN_CREATE,
255-
TOKEN_CREATE_BASE_FEE,
256-
makeExtraIncluded(Extra.KEYS, 1),
257-
makeExtraIncluded(Extra.TOKEN_CREATE_FUNGIBLE, 0),
258-
makeExtraIncluded(Extra.TOKEN_CREATE_NFT, 0)),
250+
makeServiceFee(TOKEN_CREATE, TOKEN_CREATE_BASE_FEE, makeExtraIncluded(Extra.KEYS, 1)),
259251
makeServiceFee(
260252
TOKEN_MINT,
261253
TOKEN_MINT_BASE_FEE,
262254
makeExtraIncluded(Extra.KEYS, 1),
263-
makeExtraIncluded(Extra.TOKEN_MINT_FUNGIBLE, 0),
264255
makeExtraIncluded(Extra.TOKEN_MINT_NFT, 0)),
265256
makeServiceFee(TOKEN_BURN, TOKEN_BURN_BASE_FEE),
266257
makeServiceFee(TOKEN_DELETE, TOKEN_DELETE_BASE_FEE),

hedera-node/test-clients/src/main/java/com/hedera/services/bdd/suites/fees/TokenServiceSimpleFeesSuite.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenPause;
1414
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnfreeze;
1515
import static com.hedera.services.bdd.spec.transactions.TxnVerbs.tokenUnpause;
16+
import static com.hedera.services.bdd.spec.transactions.token.CustomFeeSpecs.fixedHbarFee;
1617
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.compareSimpleToOld;
1718
import static com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed;
1819
import static com.hedera.services.bdd.suites.HapiSuite.ONE_BILLION_HBARS;
@@ -45,6 +46,7 @@ public class TokenServiceSimpleFeesSuite {
4546
private static final String PAYER = "payer";
4647
private static final String ADMIN = "admin";
4748
private static final String OTHER = "other";
49+
private static final String HBAR_COLLECTOR = "hbarCollector";
4850

4951
@LeakyHapiTest(overrides = {"fees.simpleFeesEnabled"})
5052
@DisplayName("compare create fungible token")
@@ -101,6 +103,36 @@ final Stream<DynamicTest> compareCreateNonFungibleToken() {
101103
// fungible = 19999000000,
102104
// node+network = 1000000
103105
// total = 20000000000 = 2.0
106+
1,
107+
1,
108+
1,
109+
1);
110+
}
111+
112+
@LeakyHapiTest(overrides = {"fees.simpleFeesEnabled"})
113+
@DisplayName("compare create fungible token with custom fees")
114+
final Stream<DynamicTest> compareCreateFungibleTokenWithCustomFees() {
115+
return compareSimpleToOld(
116+
() -> Arrays.asList(
117+
newKeyNamed(SUPPLY_KEY),
118+
cryptoCreate(ADMIN).balance(ONE_BILLION_HBARS),
119+
cryptoCreate(PAYER).balance(ONE_BILLION_HBARS),
120+
cryptoCreate(HBAR_COLLECTOR).balance(0L),
121+
tokenCreate("commonCustomFees")
122+
.blankMemo()
123+
.payingWith(PAYER)
124+
.fee(ONE_HUNDRED_HBARS)
125+
.treasury(ADMIN)
126+
.tokenType(NON_FUNGIBLE_UNIQUE)
127+
.initialSupply(0L)
128+
.supplyKey(SUPPLY_KEY)
129+
.autoRenewAccount(ADMIN)
130+
.autoRenewPeriod(THREE_MONTHS_IN_SECONDS)
131+
.withCustom(fixedHbarFee(1L, HBAR_COLLECTOR))
132+
.logged()
133+
.hasKnownStatus(SUCCESS)
134+
.via("create-token-txn")),
135+
"create-token-txn",
104136
2,
105137
1,
106138
2,
@@ -240,6 +272,8 @@ final Stream<DynamicTest> compareMintMultipleUniqueToken() {
240272
.hasKnownStatus(SUCCESS)
241273
.via("non-fungible-multiple-mint-txn")),
242274
"non-fungible-multiple-mint-txn",
275+
// TODO: we need a better way to represent the cost of minting NFTs.
276+
// with this current system the cost of node+network will be double counted
243277
// base = 9000000,
244278
// tokens = 199000000*3,
245279
// node+network = 1000000

0 commit comments

Comments
 (0)