diff --git a/examples/precompile-example/ZeroTokenOperations.json b/examples/precompile-example/ZeroTokenOperations.json new file mode 100644 index 000000000..891f5287e --- /dev/null +++ b/examples/precompile-example/ZeroTokenOperations.json @@ -0,0 +1,421 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "ZeroTokenOperations", + "sourceName": "contracts/ZeroTokenOperations.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "address payable", + "name": "_owner", + "type": "address" + }, + { + "internalType": "address payable", + "name": "_aliceAccount", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "getTokenExpiryInfo", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + }, + { + "components": [ + { + "internalType": "uint32", + "name": "second", + "type": "uint32" + }, + { + "internalType": "address", + "name": "autoRenewAccount", + "type": "address" + }, + { + "internalType": "uint32", + "name": "autoRenewPeriod", + "type": "uint32" + } + ], + "internalType": "struct IHederaTokenService.Expiry", + "name": "expiryInfo", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "keyType", + "type": "uint256" + } + ], + "name": "getTokenKey", + "outputs": [ + { + "internalType": "int64", + "name": "responseCode", + "type": "int64" + }, + { + "components": [ + { + "internalType": "bool", + "name": "inheritAccountKey", + "type": "bool" + }, + { + "internalType": "address", + "name": "contractId", + "type": "address" + }, + { + "internalType": "bytes", + "name": "ed25519", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "ECDSA_secp256k1", + "type": "bytes" + }, + { + "internalType": "address", + "name": "delegatableContractId", + "type": "address" + } + ], + "internalType": "struct IHederaTokenService.KeyValue", + "name": "key", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "grantTokenKyc", + "outputs": [ + { + "internalType": "int64", + "name": "responseCode", + "type": "int64" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "isKyc", + "outputs": [ + { + "internalType": "int64", + "name": "responseCode", + "type": "int64" + }, + { + "internalType": "bool", + "name": "kycGranted", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "pauseToken", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "revokeTokenKyc", + "outputs": [ + { + "internalType": "int64", + "name": "responseCode", + "type": "int64" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "step0", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "step1", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "step2", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "step3", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "step4", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "step5", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "unpauseToken", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint32", + "name": "second", + "type": "uint32" + }, + { + "internalType": "address", + "name": "autoRenewAccount", + "type": "address" + }, + { + "internalType": "uint32", + "name": "autoRenewPeriod", + "type": "uint32" + } + ], + "internalType": "struct IHederaTokenService.Expiry", + "name": "expiryInfo", + "type": "tuple" + } + ], + "name": "updateTokenExpiryInfo", + "outputs": [ + { + "internalType": "int256", + "name": "responseCode", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "keyType", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "inheritAccountKey", + "type": "bool" + }, + { + "internalType": "address", + "name": "contractId", + "type": "address" + }, + { + "internalType": "bytes", + "name": "ed25519", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "ECDSA_secp256k1", + "type": "bytes" + }, + { + "internalType": "address", + "name": "delegatableContractId", + "type": "address" + } + ], + "internalType": "struct IHederaTokenService.KeyValue", + "name": "key", + "type": "tuple" + } + ], + "internalType": "struct IHederaTokenService.TokenKey[]", + "name": "keys", + "type": "tuple[]" + } + ], + "name": "updateTokenKeys", + "outputs": [ + { + "internalType": "int64", + "name": "responseCode", + "type": "int64" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "bytecode": "0x60806040523480156200001157600080fd5b5060405162001d7c38038062001d7c833981016040819052620000349162000083565b600080546001600160a01b039384166001600160a01b03199182161790915560018054929093169116179055620000ba565b80516001600160a01b03811681146200007e57600080fd5b919050565b6000806040838503121562000096578182fd5b620000a18362000066565b9150620000b16020840162000066565b90509250929050565b611cb280620000ca6000396000f3fe6080604052600436106100e85760003560e01c80638f4ed3331161008a578063d614cdb811610059578063d614cdb814610248578063df4ec24914610276578063f2c31ff41461028b578063fb5d7376146102c557600080fd5b80638f4ed333146101de5780638f8d7f99146101f3578063af99c63314610213578063d40a71fb1461023357600080fd5b80634fb4bcec116100c65780634fb4bcec14610156578063593d6e821461016b5780636fc3cbaf1461018b5780637c41ad2c146101be57600080fd5b80633b3bff0f146100ed5780633c4dd32e1461012057806344ac2d481461014e575b600080fd5b3480156100f957600080fd5b5061010d610108366004611246565b6102da565b6040519081526020015b60405180910390f35b34801561012c57600080fd5b5061014061013b3660046114af565b6103b4565b604051610117929190611a01565b61010d61049b565b34801561016257600080fd5b5061010d610661565b34801561017757600080fd5b5061010d610186366004611434565b61069c565b34801561019757600080fd5b506101ab6101a636600461129a565b610779565b60405160079190910b8152602001610117565b3480156101ca57600080fd5b5061010d6101d9366004611246565b6107a5565b3480156101ea57600080fd5b5061010d6107d3565b3480156101ff57600080fd5b506101ab61020e366004611262565b61080b565b34801561021f57600080fd5b506101ab61022e366004611262565b610841565b34801561023f57600080fd5b5061010d610877565b34801561025457600080fd5b50610268610263366004611246565b6108ab565b6040516101179291906119ed565b34801561028257600080fd5b5061010d6109ba565b34801561029757600080fd5b506102ab6102a6366004611262565b610a38565b6040805160079390930b8352901515602083015201610117565b3480156102d157600080fd5b5061010d610b03565b6040516001600160a01b03821660248201526000908190819061016790633b3bff0f60e01b906044015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161034291906118a4565b6000604051808303816000865af19150503d806000811461037f576040519150601f19603f3d011682016040523d82523d6000602084013e610384565b606091505b5091509150816103955760156103a9565b808060200190518101906103a991906114da565b60030b949350505050565b60006103be611104565b604080516001600160a01b0386166024820152604480820186905282518083039091018152606490910182526020810180516001600160e01b0316631e26e99760e11b1790529051600091829161016791610418916118a4565b6000604051808303816000865af19150503d8060008114610455576040519150601f19603f3d011682016040523d82523d6000602084013e61045a565b606091505b5091509150610467611104565b8261047457601581610488565b8180602001905181019061048891906115b3565b60039190910b9890975095505050505050565b600080546001600160a01b031633146104b357600080fd5b604080516001808252818301909252600091816020015b6104d2611147565b8152602001906001900390816104ca57505060408051602081019091526000815290915061050590605d90600190610b53565b8160008151811061052657634e487b7160e01b600052603260045260246000fd5b6020908102919091018101919091526040805161016081018252601661012082019081527522bc30b6b8363290233ab733b4b13632903a37b5b2b760511b6101408301528152815180830183526001808252604560f81b828601528285019190915230828401528251808401845260048152636d656d6f60e01b81860152606080840191909152608083018290526103e860a0840152600060c0840181905260e084018790529154845191820185529181526001600160a01b0390911693810193909352626acfc0918301919091526106089161010082015260646000610b82565b600280546001600160a01b039283166001600160a01b031990911617905560008054604051939550909116914780156108fc0292909190818181858888f1935050505015801561065c573d6000803e3d6000fd5b505090565b600080546001600160a01b0316331461067957600080fd5b600254600154610697916001600160a01b0390811691166000610cb0565b905090565b60008060006101676001600160a01b031663593d6e8260e01b86866040516024016106c89291906118e4565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161070691906118a4565b6000604051808303816000865af19150503d8060008114610743576040519150601f19603f3d011682016040523d82523d6000602084013e610748565b606091505b50915091508161075957601561076d565b8080602001905181019061076d91906114da565b60030b95945050505050565b60008060006101676001600160a01b0316636fc3cbaf60e01b86866040516024016106c89291906118c0565b6040516001600160a01b03821660248201526000908190819061016790631f106b4b60e21b90604401610304565b600080546001600160a01b031633146107eb57600080fd5b600254600154610697916001600160a01b03908116913091166000610d91565b6040516001600160a01b038381166024830152821660448201526000908190819061016790638f8d7f9960e01b906064016106c8565b6040516001600160a01b03838116602483015282166044820152600090819081906101679063af99c63360e01b906064016106c8565b600080546001600160a01b0316331461088f57600080fd5b600154600254610697916001600160a01b039081169116610e79565b604080516060810182526000808252602080830182905282840182905283516001600160a01b038616602480830191909152855180830390910181526044909101855290810180516001600160e01b0316631ac299b760e31b17905292519092839182916101679161091d91906118a4565b6000604051808303816000865af19150503d806000811461095a576040519150601f19603f3d011682016040523d82523d6000602084013e61095f565b606091505b5091509150610987604080516060810182526000808252602082018190529181019190915290565b82610994576015816109a8565b818060200190518101906109a8919061154a565b60039190910b97909650945050505050565b600080546001600160a01b031633146109d257600080fd5b600254604080516000808252602082019092529091606091610a1b916001600160a01b031690849081610a15565b6060815260200190600190039081610a005790505b50610eaf565b9194509250905060646001600160401b0383161461065c57600080fd5b604080516001600160a01b038481166024830152831660448083019190915282518083039091018152606490910182526020810180516001600160e01b0316633cb0c7fd60e21b179052905160009182918291829161016791610a9a916118a4565b6000604051808303816000865af19150503d8060008114610ad7576040519150601f19603f3d011682016040523d82523d6000602084013e610adc565b606091505b509150915081610aef57601560006109a8565b808060200190518101906109a8919061151f565b600080546001600160a01b03163314610b1b57600080fd5b600254600090606090610b38906001600160a01b03168383610fad565b909350915060646001600160401b0383161461065c57600080fd5b610b5b611147565b6040518060400160405280858152602001610b7885856000611083565b9052949350505050565b600080848061010001516000015163ffffffff166000148015610bb257506101008101516040015163ffffffff16155b15610bc8576101008101516276a7006040909101525b6000806101676001600160a01b031634637812a04b60e01b8a8a8a604051602401610bf593929190611a1d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051610c3391906118a4565b60006040518083038185875af1925050503d8060008114610c70576040519150601f19603f3d011682016040523d82523d6000602084013e610c75565b606091505b509150915081610c885760156000610c9c565b80806020019051810190610c9c91906114f4565b60039190910b999098509650505050505050565b604080516001600160a01b0385811660248301528416604482015263ffffffff831660648083019190915282518083039091018152608490910182526020810180516001600160e01b0316639790686d60e01b17905290516000918291829161016791610d1d91906118a4565b6000604051808303816000865af19150503d8060008114610d5a576040519150601f19603f3d011682016040523d82523d6000602084013e610d5f565b606091505b509150915081610d70576015610d84565b80806020019051810190610d8491906114da565b60030b9695505050505050565b604080516001600160a01b038681166024830152858116604483015284166064820152600783900b6084808301919091528251808303909101815260a490910182526020810180516001600160e01b031663eca3691760e01b17905290516000918291829161016791610e0491906118a4565b6000604051808303816000865af19150503d8060008114610e41576040519150601f19603f3d011682016040523d82523d6000602084013e610e46565b606091505b509150915081610e57576015610e6b565b80806020019051810190610e6b91906114da565b60030b979650505050505050565b6040516001600160a01b03838116602483015282166044820152600090819081906101679063248a35ef60e11b906064016106c8565b60008060606000806101676001600160a01b031663278e0b8860e01b898989604051602401610ee093929190611901565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051610f1e91906118a4565b6000604051808303816000865af19150503d8060008114610f5b576040519150601f19603f3d011682016040523d82523d6000602084013e610f60565b606091505b509150915081610f83576040805160008082526020820190925260159190610f97565b80806020019051810190610f9791906116b8565b60039290920b9a90995090975095505050505050565b6000806000806101676001600160a01b031663acb9cff960e01b888888604051602401610fdc93929190611982565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161101a91906118a4565b6000604051808303816000865af19150503d8060008114611057576040519150601f19603f3d011682016040523d82523d6000602084013e61105c565b606091505b50915091508161106f5760156000610488565b808060200190518101906104889190611686565b61108b611104565b600184141561109d57600181526110fd565b60028414156110ba576001600160a01b03821660208201526110fd565b60038414156110cf57604081018390526110fd565b60048414156110e457606081018390526110fd565b60058414156110fd576001600160a01b03821660808201525b9392505050565b6040518060a0016040528060001515815260200160006001600160a01b03168152602001606081526020016060815260200160006001600160a01b031681525090565b604051806040016040528060008152602001611161611104565b905290565b803561117181611c44565b919050565b805161117181611c44565b600082601f830112611191578081fd5b81356111a461119f82611bd7565b611b84565b8181528460208386010111156111b8578283fd5b816020850160208301379081016020019190915292915050565b600082601f8301126111e2578081fd5b81516111f061119f82611bd7565b818152846020838601011115611204578283fd5b611215826020830160208701611bfe565b949350505050565b8051600381900b811461117157600080fd5b80516001600160401b038116811461117157600080fd5b600060208284031215611257578081fd5b81356110fd81611c44565b60008060408385031215611274578081fd5b823561127f81611c44565b9150602083013561128f81611c44565b809150509250929050565b600080604083850312156112ac578182fd5b6112b68335611c44565b823591506001600160401b0380602085013511156112d2578182fd5b6020840135840185601f8201126112e7578283fd5b6112f461119f8235611bb4565b808235825260208201915060208301886020853560051b8601011115611318578586fd5b855b8435811015611425578582351115611330578687fd5b81358501601f196040828d0382011215611348578889fd5b611350611b18565b60208301358152604083013589811115611368578a8bfd5b929092019160a0838e038301121561137e57898afd5b611386611b40565b9150602083013561139681611c5c565b82526113a460408401611166565b60208301526060830135898111156113ba578a8bfd5b6113c98e602083870101611181565b60408401525088608084013511156113df57898afd5b6113f28d60206080860135860101611181565b606083015261140360a08401611166565b608083015260208181019290925286529485019492909201915060010161131a565b50959890975095505050505050565b6000808284036080811215611447578283fd5b833561145281611c44565b92506060601f1982011215611465578182fd5b5061146e611b62565b602084013561147c81611c6a565b8152604084013561148c81611c44565b6020820152606084013561149f81611c6a565b6040820152919491935090915050565b600080604083850312156114c1578182fd5b82356114cc81611c44565b946020939093013593505050565b6000602082840312156114eb578081fd5b6110fd8261121d565b60008060408385031215611506578182fd5b61150f8361121d565b9150602083015161128f81611c44565b60008060408385031215611531578182fd5b61153a8361121d565b9150602083015161128f81611c5c565b600080828403608081121561155d578283fd5b6115668461121d565b92506060601f1982011215611579578182fd5b50611582611b62565b602084015161159081611c6a565b815260408401516115a081611c44565b6020820152606084015161149f81611c6a565b600080604083850312156115c5578182fd5b6115ce8361121d565b915060208301516001600160401b03808211156115e9578283fd5b9084019060a082870312156115fc578283fd5b611604611b40565b825161160f81611c5c565b815261161d60208401611176565b6020820152604083015182811115611633578485fd5b61163f888286016111d2565b604083015250606083015182811115611656578485fd5b611662888286016111d2565b60608301525061167460808401611176565b60808201528093505050509250929050565b60008060408385031215611698578182fd5b6116a18361121d565b91506116af6020840161122f565b90509250929050565b6000806000606084860312156116cc578081fd5b6116d58461121d565b925060206116e481860161122f565b925060408501516001600160401b038111156116fe578283fd5b8501601f8101871361170e578283fd5b805161171c61119f82611bb4565b8082825284820191508484018a868560051b870101111561173b578687fd5b8694505b8385101561176b5780518060070b8114611757578788fd5b83526001949094019391850191850161173f565b5080955050505050509250925092565b600081518084526020808501808196508360051b81019150828601855b858110156117d657828403895281518051855285015160408686018190526117c28187018361183a565b9a87019a9550505090840190600101611798565b5091979650505050505050565b600081518084526117fb816020860160208601611bfe565b601f01601f19169290920160200192915050565b805163ffffffff90811683526020808301516001600160a01b03169084015260409182015116910152565b8051151582526000602082015160018060a01b0380821660208601526040840151915060a0604086015261187160a08601836117e3565b91506060840151858303606087015261188a83826117e3565b925050806080850151166080860152508091505092915050565b600082516118b6818460208701611bfe565b9190910192915050565b6001600160a01b03831681526040602082018190526000906112159083018461177b565b6001600160a01b0383168152608081016110fd602083018461180f565b60006060820160018060a01b038616835260206001600160401b038616818501526060604085015281855180845260808601915060808160051b8701019350828701855b8281101561197357607f198887030184526119618683516117e3565b95509284019290840190600101611945565b50939998505050505050505050565b6001600160a01b03841681526001600160401b0383166020808301919091526060604083018190528351908301819052600091848101916080850190845b818110156119df57845160070b835293830193918301916001016119c0565b509098975050505050505050565b828152608081016110fd602083018461180f565b8260070b8152604060208201526000611215604083018461183a565b6060815260008451610160806060850152611a3c6101c08501836117e3565b91506020870151605f1980868503016080870152611a5a84836117e3565b935060408901519150611a7860a08701836001600160a01b03169052565b60608901519150808685030160c0870152611a9384836117e3565b935060808901519150611aaa60e087018315159052565b60a08901519150610100611ac58188018463ffffffff169052565b60c08a0151151561012088015260e08a015187860383016101408901529250611aee858461177b565b9450808a015192505050611b048286018261180f565b505060208301949094525060400152919050565b604080519081016001600160401b0381118282101715611b3a57611b3a611c2e565b60405290565b60405160a081016001600160401b0381118282101715611b3a57611b3a611c2e565b604051606081016001600160401b0381118282101715611b3a57611b3a611c2e565b604051601f8201601f191681016001600160401b0381118282101715611bac57611bac611c2e565b604052919050565b60006001600160401b03821115611bcd57611bcd611c2e565b5060051b60200190565b60006001600160401b03821115611bf057611bf0611c2e565b50601f01601f191660200190565b60005b83811015611c19578181015183820152602001611c01565b83811115611c28576000848401525b50505050565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114611c5957600080fd5b50565b8015158114611c5957600080fd5b63ffffffff81168114611c5957600080fdfea26469706673582212204ebf4993dc340cedf556b9b06b4ddaa31b7889a60dc7aba2ea3905fb328b3e3664736f6c63430008040033", + "deployedBytecode": "0x6080604052600436106100e85760003560e01c80638f4ed3331161008a578063d614cdb811610059578063d614cdb814610248578063df4ec24914610276578063f2c31ff41461028b578063fb5d7376146102c557600080fd5b80638f4ed333146101de5780638f8d7f99146101f3578063af99c63314610213578063d40a71fb1461023357600080fd5b80634fb4bcec116100c65780634fb4bcec14610156578063593d6e821461016b5780636fc3cbaf1461018b5780637c41ad2c146101be57600080fd5b80633b3bff0f146100ed5780633c4dd32e1461012057806344ac2d481461014e575b600080fd5b3480156100f957600080fd5b5061010d610108366004611246565b6102da565b6040519081526020015b60405180910390f35b34801561012c57600080fd5b5061014061013b3660046114af565b6103b4565b604051610117929190611a01565b61010d61049b565b34801561016257600080fd5b5061010d610661565b34801561017757600080fd5b5061010d610186366004611434565b61069c565b34801561019757600080fd5b506101ab6101a636600461129a565b610779565b60405160079190910b8152602001610117565b3480156101ca57600080fd5b5061010d6101d9366004611246565b6107a5565b3480156101ea57600080fd5b5061010d6107d3565b3480156101ff57600080fd5b506101ab61020e366004611262565b61080b565b34801561021f57600080fd5b506101ab61022e366004611262565b610841565b34801561023f57600080fd5b5061010d610877565b34801561025457600080fd5b50610268610263366004611246565b6108ab565b6040516101179291906119ed565b34801561028257600080fd5b5061010d6109ba565b34801561029757600080fd5b506102ab6102a6366004611262565b610a38565b6040805160079390930b8352901515602083015201610117565b3480156102d157600080fd5b5061010d610b03565b6040516001600160a01b03821660248201526000908190819061016790633b3bff0f60e01b906044015b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161034291906118a4565b6000604051808303816000865af19150503d806000811461037f576040519150601f19603f3d011682016040523d82523d6000602084013e610384565b606091505b5091509150816103955760156103a9565b808060200190518101906103a991906114da565b60030b949350505050565b60006103be611104565b604080516001600160a01b0386166024820152604480820186905282518083039091018152606490910182526020810180516001600160e01b0316631e26e99760e11b1790529051600091829161016791610418916118a4565b6000604051808303816000865af19150503d8060008114610455576040519150601f19603f3d011682016040523d82523d6000602084013e61045a565b606091505b5091509150610467611104565b8261047457601581610488565b8180602001905181019061048891906115b3565b60039190910b9890975095505050505050565b600080546001600160a01b031633146104b357600080fd5b604080516001808252818301909252600091816020015b6104d2611147565b8152602001906001900390816104ca57505060408051602081019091526000815290915061050590605d90600190610b53565b8160008151811061052657634e487b7160e01b600052603260045260246000fd5b6020908102919091018101919091526040805161016081018252601661012082019081527522bc30b6b8363290233ab733b4b13632903a37b5b2b760511b6101408301528152815180830183526001808252604560f81b828601528285019190915230828401528251808401845260048152636d656d6f60e01b81860152606080840191909152608083018290526103e860a0840152600060c0840181905260e084018790529154845191820185529181526001600160a01b0390911693810193909352626acfc0918301919091526106089161010082015260646000610b82565b600280546001600160a01b039283166001600160a01b031990911617905560008054604051939550909116914780156108fc0292909190818181858888f1935050505015801561065c573d6000803e3d6000fd5b505090565b600080546001600160a01b0316331461067957600080fd5b600254600154610697916001600160a01b0390811691166000610cb0565b905090565b60008060006101676001600160a01b031663593d6e8260e01b86866040516024016106c89291906118e4565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161070691906118a4565b6000604051808303816000865af19150503d8060008114610743576040519150601f19603f3d011682016040523d82523d6000602084013e610748565b606091505b50915091508161075957601561076d565b8080602001905181019061076d91906114da565b60030b95945050505050565b60008060006101676001600160a01b0316636fc3cbaf60e01b86866040516024016106c89291906118c0565b6040516001600160a01b03821660248201526000908190819061016790631f106b4b60e21b90604401610304565b600080546001600160a01b031633146107eb57600080fd5b600254600154610697916001600160a01b03908116913091166000610d91565b6040516001600160a01b038381166024830152821660448201526000908190819061016790638f8d7f9960e01b906064016106c8565b6040516001600160a01b03838116602483015282166044820152600090819081906101679063af99c63360e01b906064016106c8565b600080546001600160a01b0316331461088f57600080fd5b600154600254610697916001600160a01b039081169116610e79565b604080516060810182526000808252602080830182905282840182905283516001600160a01b038616602480830191909152855180830390910181526044909101855290810180516001600160e01b0316631ac299b760e31b17905292519092839182916101679161091d91906118a4565b6000604051808303816000865af19150503d806000811461095a576040519150601f19603f3d011682016040523d82523d6000602084013e61095f565b606091505b5091509150610987604080516060810182526000808252602082018190529181019190915290565b82610994576015816109a8565b818060200190518101906109a8919061154a565b60039190910b97909650945050505050565b600080546001600160a01b031633146109d257600080fd5b600254604080516000808252602082019092529091606091610a1b916001600160a01b031690849081610a15565b6060815260200190600190039081610a005790505b50610eaf565b9194509250905060646001600160401b0383161461065c57600080fd5b604080516001600160a01b038481166024830152831660448083019190915282518083039091018152606490910182526020810180516001600160e01b0316633cb0c7fd60e21b179052905160009182918291829161016791610a9a916118a4565b6000604051808303816000865af19150503d8060008114610ad7576040519150601f19603f3d011682016040523d82523d6000602084013e610adc565b606091505b509150915081610aef57601560006109a8565b808060200190518101906109a8919061151f565b600080546001600160a01b03163314610b1b57600080fd5b600254600090606090610b38906001600160a01b03168383610fad565b909350915060646001600160401b0383161461065c57600080fd5b610b5b611147565b6040518060400160405280858152602001610b7885856000611083565b9052949350505050565b600080848061010001516000015163ffffffff166000148015610bb257506101008101516040015163ffffffff16155b15610bc8576101008101516276a7006040909101525b6000806101676001600160a01b031634637812a04b60e01b8a8a8a604051602401610bf593929190611a1d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051610c3391906118a4565b60006040518083038185875af1925050503d8060008114610c70576040519150601f19603f3d011682016040523d82523d6000602084013e610c75565b606091505b509150915081610c885760156000610c9c565b80806020019051810190610c9c91906114f4565b60039190910b999098509650505050505050565b604080516001600160a01b0385811660248301528416604482015263ffffffff831660648083019190915282518083039091018152608490910182526020810180516001600160e01b0316639790686d60e01b17905290516000918291829161016791610d1d91906118a4565b6000604051808303816000865af19150503d8060008114610d5a576040519150601f19603f3d011682016040523d82523d6000602084013e610d5f565b606091505b509150915081610d70576015610d84565b80806020019051810190610d8491906114da565b60030b9695505050505050565b604080516001600160a01b038681166024830152858116604483015284166064820152600783900b6084808301919091528251808303909101815260a490910182526020810180516001600160e01b031663eca3691760e01b17905290516000918291829161016791610e0491906118a4565b6000604051808303816000865af19150503d8060008114610e41576040519150601f19603f3d011682016040523d82523d6000602084013e610e46565b606091505b509150915081610e57576015610e6b565b80806020019051810190610e6b91906114da565b60030b979650505050505050565b6040516001600160a01b03838116602483015282166044820152600090819081906101679063248a35ef60e11b906064016106c8565b60008060606000806101676001600160a01b031663278e0b8860e01b898989604051602401610ee093929190611901565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051610f1e91906118a4565b6000604051808303816000865af19150503d8060008114610f5b576040519150601f19603f3d011682016040523d82523d6000602084013e610f60565b606091505b509150915081610f83576040805160008082526020820190925260159190610f97565b80806020019051810190610f9791906116b8565b60039290920b9a90995090975095505050505050565b6000806000806101676001600160a01b031663acb9cff960e01b888888604051602401610fdc93929190611982565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b031990941693909317909252905161101a91906118a4565b6000604051808303816000865af19150503d8060008114611057576040519150601f19603f3d011682016040523d82523d6000602084013e61105c565b606091505b50915091508161106f5760156000610488565b808060200190518101906104889190611686565b61108b611104565b600184141561109d57600181526110fd565b60028414156110ba576001600160a01b03821660208201526110fd565b60038414156110cf57604081018390526110fd565b60048414156110e457606081018390526110fd565b60058414156110fd576001600160a01b03821660808201525b9392505050565b6040518060a0016040528060001515815260200160006001600160a01b03168152602001606081526020016060815260200160006001600160a01b031681525090565b604051806040016040528060008152602001611161611104565b905290565b803561117181611c44565b919050565b805161117181611c44565b600082601f830112611191578081fd5b81356111a461119f82611bd7565b611b84565b8181528460208386010111156111b8578283fd5b816020850160208301379081016020019190915292915050565b600082601f8301126111e2578081fd5b81516111f061119f82611bd7565b818152846020838601011115611204578283fd5b611215826020830160208701611bfe565b949350505050565b8051600381900b811461117157600080fd5b80516001600160401b038116811461117157600080fd5b600060208284031215611257578081fd5b81356110fd81611c44565b60008060408385031215611274578081fd5b823561127f81611c44565b9150602083013561128f81611c44565b809150509250929050565b600080604083850312156112ac578182fd5b6112b68335611c44565b823591506001600160401b0380602085013511156112d2578182fd5b6020840135840185601f8201126112e7578283fd5b6112f461119f8235611bb4565b808235825260208201915060208301886020853560051b8601011115611318578586fd5b855b8435811015611425578582351115611330578687fd5b81358501601f196040828d0382011215611348578889fd5b611350611b18565b60208301358152604083013589811115611368578a8bfd5b929092019160a0838e038301121561137e57898afd5b611386611b40565b9150602083013561139681611c5c565b82526113a460408401611166565b60208301526060830135898111156113ba578a8bfd5b6113c98e602083870101611181565b60408401525088608084013511156113df57898afd5b6113f28d60206080860135860101611181565b606083015261140360a08401611166565b608083015260208181019290925286529485019492909201915060010161131a565b50959890975095505050505050565b6000808284036080811215611447578283fd5b833561145281611c44565b92506060601f1982011215611465578182fd5b5061146e611b62565b602084013561147c81611c6a565b8152604084013561148c81611c44565b6020820152606084013561149f81611c6a565b6040820152919491935090915050565b600080604083850312156114c1578182fd5b82356114cc81611c44565b946020939093013593505050565b6000602082840312156114eb578081fd5b6110fd8261121d565b60008060408385031215611506578182fd5b61150f8361121d565b9150602083015161128f81611c44565b60008060408385031215611531578182fd5b61153a8361121d565b9150602083015161128f81611c5c565b600080828403608081121561155d578283fd5b6115668461121d565b92506060601f1982011215611579578182fd5b50611582611b62565b602084015161159081611c6a565b815260408401516115a081611c44565b6020820152606084015161149f81611c6a565b600080604083850312156115c5578182fd5b6115ce8361121d565b915060208301516001600160401b03808211156115e9578283fd5b9084019060a082870312156115fc578283fd5b611604611b40565b825161160f81611c5c565b815261161d60208401611176565b6020820152604083015182811115611633578485fd5b61163f888286016111d2565b604083015250606083015182811115611656578485fd5b611662888286016111d2565b60608301525061167460808401611176565b60808201528093505050509250929050565b60008060408385031215611698578182fd5b6116a18361121d565b91506116af6020840161122f565b90509250929050565b6000806000606084860312156116cc578081fd5b6116d58461121d565b925060206116e481860161122f565b925060408501516001600160401b038111156116fe578283fd5b8501601f8101871361170e578283fd5b805161171c61119f82611bb4565b8082825284820191508484018a868560051b870101111561173b578687fd5b8694505b8385101561176b5780518060070b8114611757578788fd5b83526001949094019391850191850161173f565b5080955050505050509250925092565b600081518084526020808501808196508360051b81019150828601855b858110156117d657828403895281518051855285015160408686018190526117c28187018361183a565b9a87019a9550505090840190600101611798565b5091979650505050505050565b600081518084526117fb816020860160208601611bfe565b601f01601f19169290920160200192915050565b805163ffffffff90811683526020808301516001600160a01b03169084015260409182015116910152565b8051151582526000602082015160018060a01b0380821660208601526040840151915060a0604086015261187160a08601836117e3565b91506060840151858303606087015261188a83826117e3565b925050806080850151166080860152508091505092915050565b600082516118b6818460208701611bfe565b9190910192915050565b6001600160a01b03831681526040602082018190526000906112159083018461177b565b6001600160a01b0383168152608081016110fd602083018461180f565b60006060820160018060a01b038616835260206001600160401b038616818501526060604085015281855180845260808601915060808160051b8701019350828701855b8281101561197357607f198887030184526119618683516117e3565b95509284019290840190600101611945565b50939998505050505050505050565b6001600160a01b03841681526001600160401b0383166020808301919091526060604083018190528351908301819052600091848101916080850190845b818110156119df57845160070b835293830193918301916001016119c0565b509098975050505050505050565b828152608081016110fd602083018461180f565b8260070b8152604060208201526000611215604083018461183a565b6060815260008451610160806060850152611a3c6101c08501836117e3565b91506020870151605f1980868503016080870152611a5a84836117e3565b935060408901519150611a7860a08701836001600160a01b03169052565b60608901519150808685030160c0870152611a9384836117e3565b935060808901519150611aaa60e087018315159052565b60a08901519150610100611ac58188018463ffffffff169052565b60c08a0151151561012088015260e08a015187860383016101408901529250611aee858461177b565b9450808a015192505050611b048286018261180f565b505060208301949094525060400152919050565b604080519081016001600160401b0381118282101715611b3a57611b3a611c2e565b60405290565b60405160a081016001600160401b0381118282101715611b3a57611b3a611c2e565b604051606081016001600160401b0381118282101715611b3a57611b3a611c2e565b604051601f8201601f191681016001600160401b0381118282101715611bac57611bac611c2e565b604052919050565b60006001600160401b03821115611bcd57611bcd611c2e565b5060051b60200190565b60006001600160401b03821115611bf057611bf0611c2e565b50601f01601f191660200190565b60005b83811015611c19578181015183820152602001611c01565b83811115611c28576000848401525b50505050565b634e487b7160e01b600052604160045260246000fd5b6001600160a01b0381168114611c5957600080fd5b50565b8015158114611c5957600080fd5b63ffffffff81168114611c5957600080fdfea26469706673582212204ebf4993dc340cedf556b9b06b4ddaa31b7889a60dc7aba2ea3905fb328b3e3664736f6c63430008040033", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/examples/precompile-example/ZeroTokenOperations.sol b/examples/precompile-example/ZeroTokenOperations.sol new file mode 100644 index 000000000..45d50a0d0 --- /dev/null +++ b/examples/precompile-example/ZeroTokenOperations.sol @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: Apache-2.0 +pragma solidity >=0.5.0 <0.9.0; +pragma experimental ABIEncoderV2; + +import "./ExpiryHelper.sol"; + +// To alter the behavior of the SolidityPrecompileExample, re-compile this solidity file +// (you will also need the other files in this directory) +// and copy the outputted json file to ./PrecompileExample.json + +contract ZeroTokenOperations is ExpiryHelper { + address payable owner; + address payable aliceAccount; + address fungibleToken; + address nftToken; + + constructor(address payable _owner, address payable _aliceAccount) { + owner = _owner; + aliceAccount = _aliceAccount; + } + + // In order for some functions (such as createFungibleToken) to work, the contract must possess the funds for + // the function call. We are using ContractExecuteTransaction.setPayableAmount() to transfer some Hbar + // to the contract's account at each step (which means this function must be payable), and then transferring + // the excess Hbar back to the owner at the end of each step. + function step0() external payable returns (int responseCode) { + require(msg.sender == owner); + + IHederaTokenService.TokenKey[] + memory keys = new IHederaTokenService.TokenKey[](1); + // Set the admin key, supply key, pause key, and freeze key to the key of the account that executed function (INHERIT_ACCOUNT_KEY). + keys[0] = createSingleKey( + ADMIN_KEY_TYPE | + SUPPLY_KEY_TYPE | + PAUSE_KEY_TYPE | + FREEZE_KEY_TYPE | + WIPE_KEY_TYPE, + INHERIT_ACCOUNT_KEY, + bytes("") + ); + + (responseCode, fungibleToken) = createFungibleToken( + IHederaTokenService.HederaToken( + "Example Fungible token", // name + "E", // symbol + address(this), // treasury + "memo", + true, // supply type, false -> INFINITE, true -> FINITE + 1000, // max supply + false, // freeze default (setting to false means that this token will not be initially frozen on creation) + keys, // the keys for the new token + // auto-renew fee paid by aliceAccount every 7,000,000 seconds (approx. 81 days). + // This is the minimum auto renew period. + createAutoRenewExpiry(aliceAccount, 7000000) + ), + 100, // initial supply + 0 // decimals + ); + + // send any excess Hbar back to the owner + owner.transfer(address(this).balance); + } + + function step1() external returns (int responseCode) { + require(msg.sender == owner); + + responseCode = associateToken(aliceAccount, fungibleToken); + } + + function step2() external returns (int responseCode) { + require(msg.sender == owner); + + responseCode = transferToken( + fungibleToken, + address(this), // sender + aliceAccount, // receiver + 0 // amount to transfer + ); + } + + function step3() external returns (int responseCode) { + require(msg.sender == owner); + + uint64 newTotalSupply; + int64[] memory mintedSerials; // applicable to NFT tokens only + (responseCode, newTotalSupply, mintedSerials) = mintToken( + fungibleToken, + 0, // amount (applicable to fungible tokens only) + new bytes[](0) // metadatas (applicable to NFT tokens only) + ); + + require(newTotalSupply == 100 + 0); + } + + function step4() external returns (int responseCode) { + require(msg.sender == owner); + + uint64 newTotalSupply; + int64[] memory mintedSerials; // applicable to NFT tokens only + (responseCode, newTotalSupply) = burnToken( + fungibleToken, + 0, // amount (applicable to fungible tokens only) + mintedSerials // metadatas (applicable to NFT tokens only) + ); + + require(newTotalSupply == 100 + 0); + } + + function step5() external returns (int responseCode) { + require(msg.sender == owner); + + responseCode = wipeTokenAccount( + fungibleToken, + aliceAccount, // owner of tokens to wipe from + 0 // amount to transfer + ); + } +} diff --git a/examples/zeroTokenOperations.js b/examples/zeroTokenOperations.js new file mode 100644 index 000000000..3d0366d7f --- /dev/null +++ b/examples/zeroTokenOperations.js @@ -0,0 +1,137 @@ +// This example is for HIP-564 described here: https://hips.hedera.com/hip/hip-564 + +import * as hashgraph from "@hashgraph/sdk"; +import ContractHelper from "./ContractHelper.js"; +import contract from "./precompile-example/ZeroTokenOperations.json" assert { type: "json" }; +import dotenv from "dotenv"; + +dotenv.config(); + +//Steps 1-5 are executed through ContractHelper and calling HIP564Example Contract. +//Step 6 is executed through the SDK + +async function main() { + // Keys should be ED25519 + // TODO: Fix the wallet to work with ECDSA + if (process.env.OPERATOR_ID == null || process.env.OPERATOR_KEY == null) { + throw new Error( + "Environment variables OPERATOR_ID, and OPERATOR_KEY are required." + ); + } + const myAccountId = hashgraph.AccountId.fromString(process.env.OPERATOR_ID); + + const wallet = new hashgraph.Wallet( + process.env.OPERATOR_ID, + process.env.OPERATOR_KEY, + new hashgraph.LocalProvider() + ); + + const alicePrivateKey = hashgraph.PrivateKey.generateED25519(); + const alicePublicKey = alicePrivateKey.publicKey; + + let transaction = await new hashgraph.AccountCreateTransaction() + .setKey(alicePublicKey) + .setInitialBalance(hashgraph.Hbar.fromString("10")) + .freezeWithSigner(wallet); + transaction = await transaction.signWithSigner(wallet); + + let response = await transaction.executeWithSigner(wallet); + const aliceAccountId = (await response.getReceiptWithSigner(wallet)) + .accountId; + + const aliceWallet = new hashgraph.Wallet( + aliceAccountId, + alicePrivateKey, + new hashgraph.LocalProvider() + ); + + // Instantiate ContractHelper + + // The contract bytecode is located on the `object` field + const contractBytecode = /** @type {string} */ (contract.bytecode); + + const contractHelper = await ContractHelper.init( + contractBytecode, + new hashgraph.ContractFunctionParameters() + .addAddress(wallet.getAccountId().toSolidityAddress()) + .addAddress(aliceAccountId.toSolidityAddress()), + wallet + ); + + // Configure steps in ContracHelper + contractHelper + .setPayableAmountForStep(0, new hashgraph.Hbar(20)) + .addSignerForStep(1, alicePrivateKey); + // step 0 creates a fungible token + // step 1 Associate with account + // step 2 transfer the token by passing a zero value + // step 3 mint the token by passing a zero value + // step 4 burn the token by passing a zero value + // step 5 wipe the token by passing a zero value + + await contractHelper.executeSteps( + /* from step */ 0, + /* to step */ 5, + wallet + ); + + // step 6 use SDK and transfer passing a zero value + //Create Fungible Token + console.log(`Attempting to execute step 6`); + + let tokenCreateTransaction = await new hashgraph.TokenCreateTransaction() + .setTokenName("Black Sea LimeChain Token") + .setTokenSymbol("BSL") + .setTreasuryAccountId(myAccountId) + .setInitialSupply(10000) // Total supply = 10000 / 10 ^ 2 + .setDecimals(2) + .setAutoRenewAccountId(myAccountId) + .freezeWithSigner(wallet); + + tokenCreateTransaction = await tokenCreateTransaction.signWithSigner( + wallet + ); + let responseTokenCreate = await tokenCreateTransaction.executeWithSigner( + wallet + ); + const tokenId = (await responseTokenCreate.getReceiptWithSigner(wallet)) + .tokenId; + + //Associate Token with Account + // Accounts on hedera have to opt in to receive any types of token that aren't HBAR + const tokenAssociateTransaction = + await new hashgraph.TokenAssociateTransaction() + .setAccountId(aliceAccountId) + .setTokenIds([tokenId]) + .freezeWithSigner(aliceWallet); + + const signedTxForAssociateToken = + await tokenAssociateTransaction.signWithSigner(aliceWallet); + const txResponseAssociatedToken = + await signedTxForAssociateToken.executeWithSigner(wallet); + const status = ( + await txResponseAssociatedToken.getReceiptWithSigner(wallet) + ).status; + + //Transfer token + const transferToken = await new hashgraph.TransferTransaction() + .addTokenTransfer(tokenId, myAccountId, 0) // deduct 0 tokens + .addTokenTransfer(tokenId, aliceAccountId, 0) // increase balance by 0 + .freezeWithSigner(wallet); + + const signedTransferTokenTX = await transferToken.signWithSigner(wallet); + const txResponseTransferToken = + await signedTransferTokenTX.executeWithSigner(wallet); + + //Verify the transaction reached consensus + const transferReceipRecord = + await txResponseTransferToken.getRecordWithSigner(wallet); + + console.log( + `step 6 completed, and returned valid result. (TransactionId "${transferReceipRecord.transactionId.toString()}")` + ); + + console.log("All steps completed with valid results."); +} + +void main();