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

chore: improve the default NativeOFTAdapter.quoteOFT() method #1228

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-rice-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/oft-evm": patch
---

Better default NativeOFT.quoteOFT method
2 changes: 1 addition & 1 deletion packages/oft-evm/artifacts/IFee.sol/IFee.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@
},
"version": 1
},
"id": 5
"id": 6
}
2 changes: 1 addition & 1 deletion packages/oft-evm/artifacts/IOFT.sol/IOFT.json
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,5 @@
},
"version": 1
},
"id": 6
"id": 8
}
10 changes: 5 additions & 5 deletions packages/oft-evm/artifacts/OFT.sol/OFT.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/oft-evm/artifacts/OFTAdapter.sol/OFTAdapter.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"abi": [],
"bytecode": {
"object": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212201c55612d88681587eb04d6cb61bdef89ffb56c9a27de0545f1b5aabde9212e0a64736f6c63430008160033",
"sourceMap": "59:2931:7:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;59:2931:7;;;;;;;;;;;;;;;;;",
"sourceMap": "59:2931:9:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;59:2931:9;;;;;;;;;;;;;;;;;",
"linkReferences": {}
},
"deployedBytecode": {
"object": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212201c55612d88681587eb04d6cb61bdef89ffb56c9a27de0545f1b5aabde9212e0a64736f6c63430008160033",
"sourceMap": "59:2931:7:-:0;;;;;;;;",
"sourceMap": "59:2931:9:-:0;;;;;;;;",
"linkReferences": {}
},
"methodIdentifiers": {},
Expand Down Expand Up @@ -48,5 +48,5 @@
},
"version": 1
},
"id": 7
"id": 9
}
10 changes: 5 additions & 5 deletions packages/oft-evm/artifacts/OFTCore.sol/OFTCore.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/oft-evm/artifacts/OFTMsgCodec.sol/OFTMsgCodec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"abi": [],
"bytecode": {
"object": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220c1f832b93889fecf0edf2732171b608de9c35d6963c9337083a2c97ee20ab5a964736f6c63430008160033",
"sourceMap": "59:2846:8:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;59:2846:8;;;;;;;;;;;;;;;;;",
"sourceMap": "59:2846:10:-:0;;;;;;;;;;;;;;;-1:-1:-1;;;59:2846:10;;;;;;;;;;;;;;;;;",
"linkReferences": {}
},
"deployedBytecode": {
"object": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220c1f832b93889fecf0edf2732171b608de9c35d6963c9337083a2c97ee20ab5a964736f6c63430008160033",
"sourceMap": "59:2846:8:-:0;;;;;;;;",
"sourceMap": "59:2846:10:-:0;;;;;;;;",
"linkReferences": {}
},
"methodIdentifiers": {},
Expand Down Expand Up @@ -46,5 +46,5 @@
},
"version": 1
},
"id": 8
"id": 10
}
35 changes: 34 additions & 1 deletion packages/oft-evm/contracts/NativeOFTAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity ^0.8.22;

import { MessagingFee, MessagingReceipt, OFTCore, OFTReceipt, SendParam } from "./OFTCore.sol";
import { MessagingFee, MessagingReceipt, OFTCore, OFTFeeDetail, OFTLimit, OFTReceipt, SendParam } from "./OFTCore.sol";

/**
*
Expand Down Expand Up @@ -126,4 +126,37 @@ abstract contract NativeOFTAdapter is OFTCore {
function _payNative(uint256 _nativeFee) internal pure override returns (uint256 nativeFee) {
return _nativeFee;
}

/**
* @notice Provides the fee breakdown and settings data for an OFT. Unused in the default implementation.
* @param _sendParam The parameters for the send operation.
* @return oftLimit The OFT limit information.
* @return oftFeeDetails The details of OFT fees.
* @return oftReceipt The OFT receipt information.
*/
function quoteOFT(
SendParam calldata _sendParam
)
external
view
virtual
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
oftLimit = OFTLimit(0, type(uint256).max);

// Unused in the default implementation; reserved for future complex fee details.
oftFeeDetails = new OFTFeeDetail[](0);

// @dev This is the same as the send() operation, but without the actual send.
// - amountSentLD is the amount in local decimals that would be sent from the sender.
// - amountReceivedLD is the amount in local decimals that will be credited to the recipient on the remote OFT instance.
// @dev The amountSentLD MIGHT not equal the amount the user actually receives. HOWEVER, the default does.
(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}
}
16 changes: 16 additions & 0 deletions packages/oft-evm/test/OFT.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -795,5 +795,21 @@ contract OFTTest is TestHelperOz5 {
assertEq(0, oftFeeDetails.length);
assertEq(minAmountToCreditLD, oftReceipt.amountSentLD);
assertEq(minAmountToCreditLD, oftReceipt.amountReceivedLD);

// Test native
sendParam = SendParam(
A_EID,
to,
_amountToSendLD,
minAmountToCreditLD,
"",
"",
""
);
(oftLimit, oftFeeDetails, oftReceipt) = dNativeOFTAdapter.quoteOFT(sendParam);
assertEq(0, oftLimit.minAmountLD);
assertEq(type(uint256).max, oftLimit.maxAmountLD);
assertEq(0, oftFeeDetails.length);
assertEq(minAmountToCreditLD, oftReceipt.amountSentLD);
}
}