Skip to content

Commit

Permalink
test: token airdrops
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <[email protected]>
  • Loading branch information
victor-yanev committed Nov 12, 2024
1 parent 41e3d39 commit 2f1afc2
Show file tree
Hide file tree
Showing 14 changed files with 816 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@
[
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"components": [
{
"internalType": "address",
"name": "accountID",
"type": "address"
},
{
"internalType": "int64",
"name": "amount",
"type": "int64"
},
{
"internalType": "bool",
"name": "isApproval",
"type": "bool"
}
],
"internalType": "struct IHederaTokenService.AccountAmount[]",
"name": "transfers",
"type": "tuple[]"
},
{
"components": [
{
"internalType": "address",
"name": "senderAccountID",
"type": "address"
},
{
"internalType": "address",
"name": "receiverAccountID",
"type": "address"
},
{
"internalType": "int64",
"name": "serialNumber",
"type": "int64"
},
{
"internalType": "bool",
"name": "isApproval",
"type": "bool"
}
],
"internalType": "struct IHederaTokenService.NftTransfer[]",
"name": "nftTransfers",
"type": "tuple[]"
}
],
"internalType": "struct IHederaTokenService.TokenTransferList[]",
"name": "tokenTransfers",
"type": "tuple[]"
}
],
"name": "airdropTokens",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -173,6 +248,88 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "int64",
"name": "serial",
"type": "int64"
}
],
"internalType": "struct IHederaTokenService.PendingAirdrop[]",
"name": "pendingAirdrops",
"type": "tuple[]"
}
],
"name": "cancelAirdrops",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"internalType": "address",
"name": "receiver",
"type": "address"
},
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "int64",
"name": "serial",
"type": "int64"
}
],
"internalType": "struct IHederaTokenService.PendingAirdrop[]",
"name": "pendingAirdrops",
"type": "tuple[]"
}
],
"name": "claimAirdrops",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -2428,6 +2585,47 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "rejectingAddress",
"type": "address"
},
{
"internalType": "address[]",
"name": "ftAddresses",
"type": "address[]"
},
{
"components": [
{
"internalType": "address",
"name": "nft",
"type": "address"
},
{
"internalType": "int64",
"name": "serial",
"type": "int64"
}
],
"internalType": "struct IHederaTokenService.NftID[]",
"name": "nftIDs",
"type": "tuple[]"
}
],
"name": "rejectTokens",
"outputs": [
{
"internalType": "int64",
"name": "responseCode",
"type": "int64"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.5.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../HederaResponseCodes.sol";
import "./IHederaTokenService.sol";
import {HederaResponseCodes} from "../HederaResponseCodes.sol";
import {IHederaTokenService} from "./IHederaTokenService.sol";
pragma experimental ABIEncoderV2;

abstract contract HederaTokenService {
address constant precompileAddress = address(0x167);
Expand Down Expand Up @@ -704,4 +704,36 @@ abstract contract HederaTokenService {
abi.encodeWithSelector(IHederaTokenService.updateNonFungibleTokenCustomFees.selector, token, fixedFees, royaltyFees));
responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
}

function airdropTokens(IHederaTokenService.TokenTransferList[] memory tokenTransfers)
internal returns (int64 responseCode) {
(bool success, bytes memory result) = precompileAddress.call(
abi.encodeWithSelector(IHederaTokenService.airdropTokens.selector, tokenTransfers)
);
(responseCode) = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
}

function cancelAirdrops(IHederaTokenService.PendingAirdrop[] memory pendingAirdrops)
internal returns (int64 responseCode) {
(bool success, bytes memory result) = precompileAddress.call(
abi.encodeWithSelector(IHederaTokenService.cancelAirdrops.selector, pendingAirdrops)
);
(responseCode) = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
}

function claimAirdrops(IHederaTokenService.PendingAirdrop[] memory pendingAirdrops)
internal returns (int64 responseCode) {
(bool success, bytes memory result) = precompileAddress.call(
abi.encodeWithSelector(IHederaTokenService.claimAirdrops.selector, pendingAirdrops)
);
(responseCode) = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
}

function rejectTokens(address rejectingAddress, address[] memory ftAddresses, IHederaTokenService.NftID[] memory nftIds)
internal returns (int64 responseCode) {
(bool success, bytes memory result) = precompileAddress.call(
abi.encodeWithSelector(IHederaTokenService.rejectTokens.selector, rejectingAddress, ftAddresses, nftIds)
);
(responseCode) = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
}
}
12 changes: 12 additions & 0 deletions contracts/system-contracts/hedera-token-service/IHRC904.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.4.9 <0.9.0;

interface IHRC904 {
function cancelAirdropFT(address receiverAddress) external returns (int64 responseCode);
function cancelAirdropNFT(address receiverAddress, int64 serialNumber) external returns (int64 responseCode);
function claimAirdropFT(address senderAddress) external returns (int64 responseCode);
function claimAirdropNFT(address senderAddress, int64 serialNumber) external returns (int64 responseCode);
function rejectTokenFT() external returns (int64 responseCode);
function rejectTokenNFTs(int64[] memory serialNumbers) external returns (int64 responseCode);
function setUnlimitedAutomaticAssociations(bool enableAutoAssociations) external returns (int64 responseCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ interface IHederaTokenService {
address feeCollector;
}

struct PendingAirdrop {
address sender;
address receiver;

address token;
int64 serial;
}

struct NftID {
address nft;
int64 serial;
}

/**********************
* Direct HTS Calls *
**********************/
Expand Down Expand Up @@ -815,4 +828,12 @@ interface IHederaTokenService {
/// @param royaltyFees Set of royalty fees for `token`
/// @return responseCode The response code for the status of the request. SUCCESS is 22.
function updateNonFungibleTokenCustomFees(address token, IHederaTokenService.FixedFee[] memory fixedFees, IHederaTokenService.RoyaltyFee[] memory royaltyFees) external returns (int64 responseCode);

function airdropTokens(TokenTransferList[] memory tokenTransfers) external returns (int64 responseCode);

function cancelAirdrops(PendingAirdrop[] memory pendingAirdrops) external returns (int64 responseCode);

function claimAirdrops(PendingAirdrop[] memory pendingAirdrops) external returns (int64 responseCode);

function rejectTokens(address rejectingAddress, address[] memory ftAddresses, NftID[] memory nftIDs) external returns (int64 responseCode);
}
Loading

0 comments on commit 2f1afc2

Please sign in to comment.