Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: crypto transfer method implemented (#195) #216

Closed
wants to merge 2 commits into from

Conversation

arianejasuwienas
Copy link
Contributor

Description:
Adding crypto transfer method support to the hts. While calling the address 0x167 you the cryptoTransefer method can be invoked.

Related issue(s):

Fixes #195

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@arianejasuwienas arianejasuwienas requested a review from a team as a code owner January 22, 2025 15:27
@@ -43,6 +43,119 @@ contract HtsSystemContract is IHederaTokenService, IERC20Events, IERC721Events {
assembly { accountId := sload(slot) }
}

function cryptoTransfer(TransferList memory transferList, TokenTransferList[] memory tokenTransfers)
payable htsCall external returns (int64 responseCode) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not yet implemented in the services repository:

https://github.com/hashgraph/hedera-smart-contracts/blob/88472c9879fc02bc697b08e60fae11718d74d0b0/test/foundry/mocks/hts-precompile/HtsSystemContractMock.sol#L1359

so it does not necessarily have to be payable.

@arianejasuwienas arianejasuwienas self-assigned this Jan 22, 2025
@arianejasuwienas arianejasuwienas added the feature Enhancing an existing feature driven by business requirements. Typically backwards compatible. label Jan 22, 2025
@@ -43,6 +43,119 @@ contract HtsSystemContract is IHederaTokenService, IERC20Events, IERC721Events {
assembly { accountId := sload(slot) }
}

function cryptoTransfer(TransferList memory transferList, TokenTransferList[] memory tokenTransfers)
payable htsCall external returns (int64 responseCode) {
uint256 hbarsReceived = msg.value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we are in the right track here. The wrapper method for cryptoTransfer https://github.com/hashgraph/hedera-smart-contracts/blob/0a617acfd804131e6f0ad5b7bc46019783f82bad/contracts/system-contracts/hedera-token-service/HederaTokenService.sol#L29-L35 does not pass msg.value so it does not seem this should be payable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is because the HTS is responsible for the hbar transfer then.

    /// Performs transfers among combinations of tokens and hbars

To mimic this behaviour and NOT have this method payable we would have to do some vm cheats here (which perhaps is not a bad idea, I will try to figure out the possibilities).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work in hardhat, but is accomplishable in foundry. I'll proceed with implementing that; I'm currently working on adding the approval mechanism.

Also, since I'm using vm deal cheatcodes to change balances now, I have to rethink / double check the validation and assertions.

@arianejasuwienas arianejasuwienas marked this pull request as draft January 23, 2025 13:45
@arianejasuwienas arianejasuwienas deleted the 195-crypto-transfer-support branch January 30, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Enhancing an existing feature driven by business requirements. Typically backwards compatible.
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

Implement the cryptoTransfer method defined in the IHederaTokenService
2 participants