Skip to content

Commit

Permalink
feat: token expiry info support introduced (#151)
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Jasuwienas <[email protected]>
  • Loading branch information
arianejasuwienas committed Jan 10, 2025
1 parent ee7bfe4 commit db6299d
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 93 deletions.
36 changes: 36 additions & 0 deletions contracts/HtsSystemContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {IERC20Events, IERC20} from "./IERC20.sol";
import {IERC721, IERC721Events} from "./IERC721.sol";
import {IHRC719} from "./IHRC719.sol";
import {IHederaTokenService} from "./IHederaTokenService.sol";
import {IERC165} from "../lib/forge-std/src/interfaces/IERC165.sol";

address constant HTS_ADDRESS = address(0x167);

Expand Down Expand Up @@ -91,6 +92,41 @@ contract HtsSystemContract is IHederaTokenService, IERC20Events, IERC721Events {
responseCode = 22; // HederaResponseCodes.SUCCESS
}

function transferTokens(
address token,
address[] memory accountId,
int64[] memory amount
) htsCall public returns (int64 responseCode) {
require(token != address(0), "transferTokens: invalid token");
require(accountId.length > 0, "transferTokens: missing recipients");
require(amount.length == accountId.length, "transferTokens: inconsistent input");
for (uint256 i = 0; i < accountId.length; i++) {
require(accountId[i] != address(0) && accountId[i] != msg.sender, "transferTokens: Invalid accountId");
transferToken(token, msg.sender, accountId[i], amount[i]);
}
responseCode = 22; // HederaResponseCodes.SUCCESS
}

function transferToken(
address token,
address sender,
address recipient,
int64 amount
) htsCall public returns (int64 responseCode) {
require(token != address(0), "transferToken: invalid token");
address from = sender;
address to = recipient;
if (amount < 0) {
from = recipient;
to = sender;
amount *= -1;
}
require(IERC20(token).allowance(from, msg.sender));
HtsSystemContract(token)._update(from, to, uint256(uint64(amount)));

return 22; // HederaResponseCodes.SUCCESS
}

function dissociateTokens(address account, address[] memory tokens) htsCall public returns (int64 responseCode) {
require(tokens.length > 0, "dissociateTokens: missing tokens");
require(account == msg.sender, "dissociateTokens: Must be signed by the provided Account's key or called from the accounts contract key");
Expand Down
22 changes: 11 additions & 11 deletions contracts/IHederaTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ interface IHederaTokenService {
/// @param token The ID of the token as a solidity address
/// @param accountId account to do a transfer to/from
/// @param amount The amount from the accountId at the same index
// function transferTokens(
// address token,
// address[] memory accountId,
// int64[] memory amount
// ) external returns (int64 responseCode);
function transferTokens(
address token,
address[] memory accountId,
int64[] memory amount
) external returns (int64 responseCode);

/// Initiates a Non-Fungable Token Transfer
/// @param token The ID of the token as a solidity address
Expand All @@ -487,12 +487,12 @@ interface IHederaTokenService {
/// @param sender The sender for the transaction
/// @param recipient The receiver of the transaction
/// @param amount Non-negative value to send. a negative value will result in a failure.
// function transferToken(
// address token,
// address sender,
// address recipient,
// int64 amount
// ) external returns (int64 responseCode);
function transferToken(
address token,
address sender,
address recipient,
int64 amount
) external returns (int64 responseCode);

/// Transfers tokens where the calling account/contract is implicitly the first entry in the token transfer list,
/// where the amount is the value needed to zero balance the transfers. Regular signing rules apply for sending
Expand Down
209 changes: 127 additions & 82 deletions out/HtsSystemContract.sol/HtsSystemContract.json

Large diffs are not rendered by default.

0 comments on commit db6299d

Please sign in to comment.