Skip to content

Commit

Permalink
chore: improve the default NativeOFTAdapter.quoteOFT() method
Browse files Browse the repository at this point in the history
This method is meant to be overriden.  This function should not fail,
and keeping the default OFTCore.quoteOFT(...) implementation was leading
to failed calls as Native tokens aren't ERC-20.

Signed-off-by: Ryan Goulding <[email protected]>
  • Loading branch information
ryandgoulding committed Feb 3, 2025
1 parent 12eaa61 commit e13d57f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 24 deletions.
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);
}
}
2 changes: 2 additions & 0 deletions packages/oft-evm/contracts/OFTCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,6 @@ abstract contract OFTCore is IOFT, OApp, OAppPreCrimeSimulator, OAppOptionsType3
uint256 _amountLD,
uint32 _srcEid
) internal virtual returns (uint256 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);
}
}

0 comments on commit e13d57f

Please sign in to comment.