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

ERC1155 Compatibility #1238

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jalextowle
Copy link
Contributor

@jalextowle jalextowle commented Feb 1, 2025

Description

This PR makes Hyperdrive fully ERC1155 compatible. To do this, we added safeTransferFrom, safeBatchTransferFrom, and balanceOfBatch. To ensure that our contracts remain code size limit, we also had to remove transferFrom and batchTransferFrom.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 13083371547

Details

  • 69 of 80 (86.25%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 89.268%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contracts/src/matching/HyperdriveMatchingEngine.sol 0 1 0.0%
contracts/src/internal/HyperdriveMultiToken.sol 47 51 92.16%
contracts/src/external/HyperdriveTarget0.sol 3 9 33.33%
Files with Coverage Reduction New Missed Lines %
contracts/src/zaps/UniV3Zap.sol 1 90.0%
Totals Coverage Status
Change from base Build 12941312920: -0.2%
Covered Lines: 3036
Relevant Lines: 3401

💛 - Coveralls

Copy link

github-actions bot commented Feb 1, 2025

Hyperdrive Gas Benchmark

Benchmark suite Current: 47022f9 Previous: 3497650 Deviation Status
addLiquidity: min 33889 gas 33899 gas -0.0295%
addLiquidity: avg 203068 gas 203380 gas -0.1534%
addLiquidity: max 191270 gas 191291 gas -0.0110%
burn: min 31483 gas 31493 gas -0.0318%
burn: avg 137220 gas 136107 gas 0.8177% 🚨
burn: max 111172 gas 111180 gas -0.0072%
checkpoint: min 40267 gas 40289 gas -0.0546%
checkpoint: avg 148329 gas 148356 gas -0.0182%
checkpoint: max 149197 gas 149219 gas -0.0147%
closeLong: min 31471 gas 31481 gas -0.0318%
closeLong: avg 146441 gas 146214 gas 0.1553% 🚨
closeLong: max 126667 gas 126689 gas -0.0174%
closeShort: min 31437 gas 31336 gas 0.3223% 🚨
closeShort: avg 137741 gas 137443 gas 0.2168% 🚨
closeShort: max 132681 gas 132580 gas 0.0762% 🚨
initialize: min 31303 gas 31313 gas -0.0319%
initialize: avg 355131 gas 355025 gas 0.0299% 🚨
initialize: max 355591 gas 355601 gas -0.0028%
openLong: min 33452 gas 33330 gas 0.3660% 🚨
openLong: avg 179181 gas 179602 gas -0.2344%
openLong: max 191484 gas 191434 gas 0.0261% 🚨
openShort: min 33886 gas 33896 gas -0.0295%
openShort: avg 180785 gas 180333 gas 0.2506% 🚨
openShort: max 170058 gas 170068 gas -0.0059%
redeemWithdrawalShares: min 31271 gas 31259 gas 0.0384% 🚨
redeemWithdrawalShares: avg 77487 gas 77780 gas -0.3767%
redeemWithdrawalShares: max 67470 gas 67460 gas 0.0148% 🚨
removeLiquidity: min 31255 gas 31265 gas -0.0320%
removeLiquidity: avg 213380 gas 214089 gas -0.3312%
removeLiquidity: max 220553 gas 218337 gas 1.0149% 🚨

This comment was automatically generated by workflow using github-action-benchmark.

address _to,
uint256[] calldata _ids,
uint256[] calldata _amounts,
bytes memory _data
Copy link

Choose a reason for hiding this comment

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

Why the 2 lines above can be calldata but this line is using memory?
I saw OZ is doing all 3 lines calldata here: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/828dbc357cd7975c0a31d919f6d4dcf7ef2dc427/contracts/token/ERC1155/IERC1155.sol#L121

revert IHyperdrive.BatchInputLengthMismatch();
}

// Call internal transfer for each asset.
for (uint256 i = 0; i < ids.length; i++) {
_transferFrom(ids[i], from, to, values[i], msg.sender);
for (uint256 i = 0; i < _ids.length; i++) {
Copy link

@Sean329 Sean329 Feb 2, 2025

Choose a reason for hiding this comment

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

nit: it should be a gas saver to read the _ids.length once and save it to a local uint length(on the stack, minimal gas) than repeatedly reading the _ids.length thru the loop (3 gas each time)?

bytes calldata
) external view returns (bytes4) {
// If the sender is the right Hyperdrive contract, we accept the transfer.
if (msg.sender == hyperdrive) {
Copy link

Choose a reason for hiding this comment

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

I think at this time, the hyperdrive is still the dummy address 0x1 instead of the real address?

) external view returns (bytes4) {
// If the sender is the right Hyperdrive contract, we accept the batch
// transfer.
if (msg.sender == hyperdrive) {
Copy link

Choose a reason for hiding this comment

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

Also here, 0x1 or the real address?


// Load the balances.
uint256[] memory batchBalances = new uint256[](_accounts.length);
for (uint256 i = 0; i < _accounts.length; ++i) {
Copy link

Choose a reason for hiding this comment

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

Copy link

@Sean329 Sean329 left a comment

Choose a reason for hiding this comment

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

Approved once the comments are resolved, especially the question of hyperdrive address being dummy or real.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants