-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: crypto transfer support (#195)
Signed-off-by: Mariusz Jasuwienas <mariusz.jasuwienas@arianelabs.com>
- Loading branch information
1 parent
fd99e8a
commit cfc904c
Showing
14 changed files
with
8,597 additions
and
8 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
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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# If you want to deploy on testnet go to https://portal.hedera.com/ to setup your private key | ||
TESTNET_OPERATOR_PRIVATE_KEY=0x0000000000000000000000000000000000000000000000000000000000000000 |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
types | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# HTS crypto transfer hbars example | ||
|
||
Simple scripts to show and investigate how the crypto transfer actually works for the hbar operations on the testnet. | ||
|
||
Requires testnet account with non-empty balance. Each test run will result in decreasing the balance. | ||
|
||
## Configuration | ||
|
||
Create `.env` file based on `.env.example` | ||
|
||
``` | ||
# Alias accounts keys | ||
TESTNET_OPERATOR_PRIVATE_KEY= | ||
``` | ||
|
||
## Setup & Install | ||
|
||
In the project directory: | ||
|
||
1. Run `npm install` | ||
2. Run `npx hardhat test` |
75 changes: 75 additions & 0 deletions
75
examples/hardhat-hts-crypto-transfer-hbar/contracts/IHederaTokenService.sol
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
// pragma experimental ABIEncoderV2; | ||
|
||
interface IHederaTokenService { | ||
|
||
// /// Transfers cryptocurrency among two or more accounts by making the desired adjustments to their | ||
// /// balances. Each transfer list can specify up to 10 adjustments. Each negative amount is withdrawn | ||
// /// from the corresponding account (a sender), and each positive one is added to the corresponding | ||
// /// account (a receiver). The amounts list must sum to zero. Each amount is a number of tinybars | ||
// /// (there are 100,000,000 tinybars in one hbar). If any sender account fails to have sufficient | ||
// /// hbars, then the entire transaction fails, and none of those transfers occur, though the | ||
// /// transaction fee is still charged. This transaction must be signed by the keys for all the sending | ||
// /// accounts, and for any receiving accounts that have receiverSigRequired == true. The signatures | ||
// /// are in the same order as the accounts, skipping those accounts that don't need a signature. | ||
// /// @custom:version 0.3.0 previous version did not include isApproval | ||
struct AccountAmount { | ||
// The Account ID, as a solidity address, that sends/receives cryptocurrency or tokens | ||
address accountID; | ||
|
||
// The amount of the lowest denomination of the given token that | ||
// the account sends(negative) or receives(positive) | ||
int64 amount; | ||
|
||
// If true then the transfer is expected to be an approved allowance and the | ||
// accountID is expected to be the owner. The default is false (omitted). | ||
bool isApproval; | ||
} | ||
|
||
// /// A sender account, a receiver account, and the serial number of an NFT of a Token with | ||
// /// NON_FUNGIBLE_UNIQUE type. When minting NFTs the sender will be the default AccountID instance | ||
// /// (0.0.0 aka 0x0) and when burning NFTs, the receiver will be the default AccountID instance. | ||
// /// @custom:version 0.3.0 previous version did not include isApproval | ||
struct NftTransfer { | ||
// The solidity address of the sender | ||
address senderAccountID; | ||
|
||
// The solidity address of the receiver | ||
address receiverAccountID; | ||
|
||
// The serial number of the NFT | ||
int64 serialNumber; | ||
|
||
// If true then the transfer is expected to be an approved allowance and the | ||
// accountID is expected to be the owner. The default is false (omitted). | ||
bool isApproval; | ||
} | ||
|
||
struct TokenTransferList { | ||
// The ID of the token as a solidity address | ||
address token; | ||
|
||
// Applicable to tokens of type FUNGIBLE_COMMON. Multiple list of AccountAmounts, each of which | ||
// has an account and amount. | ||
AccountAmount[] transfers; | ||
|
||
// Applicable to tokens of type NON_FUNGIBLE_UNIQUE. Multiple list of NftTransfers, each of | ||
// which has a sender and receiver account, including the serial number of the NFT | ||
NftTransfer[] nftTransfers; | ||
} | ||
|
||
struct TransferList { | ||
// Multiple list of AccountAmounts, each of which has an account and amount. | ||
// Used to transfer hbars between the accounts in the list. | ||
AccountAmount[] transfers; | ||
} | ||
|
||
/// Performs transfers among combinations of tokens and hbars | ||
/// @param transferList the list of hbar transfers to do | ||
/// @param tokenTransfers the list of token transfers to do | ||
/// @custom:version 0.3.0 the signature of the previous version was cryptoTransfer(TokenTransferList[] memory tokenTransfers) | ||
function cryptoTransfer(TransferList memory transferList, TokenTransferList[] memory tokenTransfers) | ||
external | ||
returns (int64 responseCode); | ||
} |
50 changes: 50 additions & 0 deletions
50
examples/hardhat-hts-crypto-transfer-hbar/hardhat.config.js
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/*- | ||
* Hedera Hardhat Forking Plugin | ||
* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
require('dotenv').config(); | ||
require('@nomicfoundation/hardhat-toolbox'); | ||
require('@nomicfoundation/hardhat-chai-matchers'); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
mocha: { | ||
timeout: 3600000, | ||
}, | ||
solidity: { | ||
version: '0.8.9', | ||
settings: { | ||
optimizer: { | ||
enabled: true, | ||
runs: 500, | ||
}, | ||
}, | ||
}, | ||
defaultNetwork: 'testnet', | ||
networks: { | ||
hardhat: { | ||
allowUnlimitedContractSize: true, | ||
}, | ||
testnet: { | ||
url: 'https://testnet.hashio.io/api', | ||
accounts: process.env.TESTNET_OPERATOR_PRIVATE_KEY | ||
? [process.env.TESTNET_OPERATOR_PRIVATE_KEY] | ||
: [], | ||
chainId: 296, | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.