github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/examples/precompile_example/ZeroTokenOperations.sol (about) 1 // SPDX-License-Identifier: Apache-2.0 2 pragma solidity >=0.5.0 <0.9.0; 3 pragma experimental ABIEncoderV2; 4 5 import "./ExpiryHelper.sol"; 6 import "./PrngSystemContract.sol"; 7 import "./KeyHelper.sol"; 8 import "./HederaTokenService.sol"; 9 import "./FeeHelper.sol"; 10 11 // To alter the behavior of the SolidityPrecompileExample, re-compile this solidity file 12 // (you will also need the other files in this directory) 13 // and copy the outputted json file to ./PrecompileExample.json 14 15 contract ZeroTokenOperations is 16 PrngSystemContract, 17 HederaTokenService, 18 ExpiryHelper, 19 KeyHelper, 20 FeeHelper 21 { 22 address payable owner; 23 address payable aliceAccount; 24 address fungibleToken; 25 26 constructor(address payable _owner, address payable _aliceAccount) { 27 owner = _owner; 28 aliceAccount = _aliceAccount; 29 } 30 31 // In order for some functions (such as createFungibleToken) to work, the contract must possess the funds for 32 // the function call. We are using ContractExecuteTransaction.setPayableAmount() to transfer some Hbar 33 // to the contract's account at each step (which means this function must be payable), and then transferring 34 // the excess Hbar back to the owner at the end of each step. 35 function step0() external payable returns (int responseCode, address) { 36 require(msg.sender == owner); 37 38 IHederaTokenService.TokenKey[] 39 memory keys = new IHederaTokenService.TokenKey[](4); 40 keys[0] = getSingleKey( 41 KeyType.ADMIN, 42 KeyType.PAUSE, 43 KeyValueType.INHERIT_ACCOUNT_KEY, 44 bytes("") 45 ); 46 47 keys[1] = getSingleKey( 48 KeyType.FREEZE, 49 KeyValueType.INHERIT_ACCOUNT_KEY, 50 bytes("") 51 ); 52 keys[2] = getSingleKey( 53 KeyType.WIPE, 54 KeyValueType.INHERIT_ACCOUNT_KEY, 55 bytes("") 56 ); 57 keys[3] = getSingleKey( 58 KeyType.SUPPLY, 59 KeyValueType.INHERIT_ACCOUNT_KEY, 60 bytes("") 61 ); 62 63 (responseCode, fungibleToken) = createFungibleToken( 64 IHederaTokenService.HederaToken( 65 "Example Fungible token", // name 66 "E", // symbol 67 address(this), // treasury 68 "memo", 69 true, // supply type, false -> INFINITE, true -> FINITE 70 1000, // max supply 71 false, // freeze default (setting to false means that this token will not be initially frozen on creation) 72 keys, // the keys for the new token 73 // auto-renew fee paid by aliceAccount every 7,000,000 seconds (approx. 81 days). 74 // This is the minimum auto renew period. 75 createAutoRenewExpiry(address(this), 7000000) 76 ), 77 100, // initial supply 78 0 // decimals 79 ); 80 81 // send any excess Hbar back to the owner 82 owner.transfer(address(this).balance); 83 return (responseCode, fungibleToken); 84 } 85 86 function step1() external returns (int responseCode) { 87 require(msg.sender == owner); 88 89 responseCode = associateToken(aliceAccount, fungibleToken); 90 } 91 92 function step2() external returns (int responseCode) { 93 require(msg.sender == owner); 94 95 responseCode = transferToken( 96 fungibleToken, 97 address(this), // sender 98 aliceAccount, // receiver 99 0 // amount to transfer 100 ); 101 } 102 103 function step3() external returns (int responseCode) { 104 require(msg.sender == owner); 105 106 int64 newTotalSupply; 107 int64[] memory mintedSerials; // applicable to NFT tokens only 108 (responseCode, newTotalSupply, mintedSerials) = mintToken( 109 fungibleToken, 110 0, // amount (applicable to fungible tokens only) 111 new bytes[](0) // metadatas (applicable to NFT tokens only) 112 ); 113 114 // require(newTotalSupply == 100); 115 } 116 117 function step4() external returns (int responseCode) { 118 require(msg.sender == owner); 119 120 int64 totalSupplyLeftAfterBurn; 121 (responseCode, totalSupplyLeftAfterBurn) = burnToken( 122 fungibleToken, 123 0, // amount to burn (applicable to fungible tokens only) 124 new int64[](0) // serial numbers to burn (applicable to NFT tokens only) 125 ); 126 127 // require(totalSupplyLeftAfterBurn == 100); 128 } 129 130 function step5() external returns (int responseCode) { 131 require(msg.sender == owner); 132 133 responseCode = wipeTokenAccount( 134 fungibleToken, 135 aliceAccount, // owner of tokens to wipe from 136 0 // amount to transfer 137 ); 138 } 139 }