Skip to content

Commit 9e972e1

Browse files
initial commit
1 parent 8883ef8 commit 9e972e1

File tree

3 files changed

+13
-41
lines changed

3 files changed

+13
-41
lines changed

src/ForeignController.sol

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { IERC4626 } from "../lib/openzeppelin-contracts/contracts/interfaces/IER
1616

1717
import { IPSM3 } from "spark-psm/src/interfaces/IPSM3.sol";
1818

19+
import { LayerZeroLib } from "./libraries/LayerZeroLib.sol";
20+
1921
import { IALMProxy } from "./interfaces/IALMProxy.sol";
2022
import { ICCTPLike } from "./interfaces/CCTPInterfaces.sol";
2123
import { IRateLimits } from "./interfaces/IRateLimits.sol";
@@ -68,7 +70,7 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
6870
bytes32 public constant LIMIT_AAVE_DEPOSIT = keccak256("LIMIT_AAVE_DEPOSIT");
6971
bytes32 public constant LIMIT_AAVE_WITHDRAW = keccak256("LIMIT_AAVE_WITHDRAW");
7072
bytes32 public constant LIMIT_ASSET_TRANSFER = keccak256("LIMIT_ASSET_TRANSFER");
71-
bytes32 public constant LIMIT_LAYERZERO_TRANSFER = keccak256("LIMIT_LAYERZERO_TRANSFER");
73+
bytes32 public constant LIMIT_LAYERZERO_TRANSFER = LayerZeroLib.LIMIT_LAYERZERO_TRANSFER;
7274
bytes32 public constant LIMIT_PSM_DEPOSIT = keccak256("LIMIT_PSM_DEPOSIT");
7375
bytes32 public constant LIMIT_PSM_WITHDRAW = keccak256("LIMIT_PSM_WITHDRAW");
7476
bytes32 public constant LIMIT_SPARK_VAULT_TAKE = keccak256("LIMIT_SPARK_VAULT_TAKE");
@@ -301,45 +303,15 @@ contract ForeignController is ReentrancyGuard, AccessControlEnumerable {
301303
payable
302304
nonReentrant
303305
onlyRole(RELAYER)
304-
rateLimited(
305-
keccak256(abi.encode(LIMIT_LAYERZERO_TRANSFER, oftAddress, destinationEndpointId)),
306-
amount
307-
)
308306
{
309-
bytes32 recipient = layerZeroRecipients[destinationEndpointId];
310-
311-
require(recipient != bytes32(0), "FC/recipient-not-set");
312-
313-
// NOTE: Full integration testing of this logic is not possible without OFTs with
314-
// approvalRequired == true. Add integration testing for this case before
315-
// using in production.
316-
if (ILayerZero(oftAddress).approvalRequired()) {
317-
_approve(ILayerZero(oftAddress).token(), oftAddress, amount);
318-
}
319-
320-
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200_000, 0);
321-
322-
SendParam memory sendParams = SendParam({
323-
dstEid : destinationEndpointId,
324-
to : recipient,
325-
amountLD : amount,
326-
minAmountLD : 0,
327-
extraOptions : options,
328-
composeMsg : "",
329-
oftCmd : ""
307+
LayerZeroLib.transferTokenLayerZero({
308+
proxy : proxy,
309+
rateLimits : rateLimits,
310+
oftAddress : oftAddress,
311+
amount : amount,
312+
destinationEndpointId : destinationEndpointId,
313+
layerZeroRecipient : layerZeroRecipients[destinationEndpointId]
330314
});
331-
332-
// Query the min amount received on the destination chain and set it.
333-
( ,, OFTReceipt memory receipt ) = ILayerZero(oftAddress).quoteOFT(sendParams);
334-
sendParams.minAmountLD = receipt.amountReceivedLD;
335-
336-
MessagingFee memory fee = ILayerZero(oftAddress).quoteSend(sendParams, false);
337-
338-
proxy.doCallWithValue{value: fee.nativeFee}(
339-
oftAddress,
340-
abi.encodeCall(ILayerZero.send, (sendParams, fee, address(proxy))),
341-
fee.nativeFee
342-
);
343315
}
344316

345317
/**********************************************************************************************/

src/libraries/LayerZeroLib.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ library LayerZeroLib {
3939
amount
4040
);
4141

42-
require(layerZeroRecipient != bytes32(0), "MC/recipient-not-set");
42+
require(layerZeroRecipient != bytes32(0), "recipient-not-set");
4343

4444
// NOTE: Full integration testing of this logic is not possible without OFTs with
4545
// approvalRequired == false. Add integration testing for this case before

test/mainnet-fork/LayerZero.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ contract MainnetControllerTransferLayerZeroFailureTests is MainnetControllerLaye
173173
deal(relayer, fee.nativeFee);
174174

175175
vm.prank(relayer);
176-
vm.expectRevert("MC/recipient-not-set");
176+
vm.expectRevert("recipient-not-set");
177177
mainnetController.transferTokenLayerZero{value: fee.nativeFee}(
178178
USDT_OFT,
179179
10_000_000e6,
@@ -540,7 +540,7 @@ contract ForeignControllerTransferLayerZeroFailureTests is ArbitrumChainLayerZer
540540
deal(relayer, fee.nativeFee);
541541

542542
vm.prank(relayer);
543-
vm.expectRevert("FC/recipient-not-set");
543+
vm.expectRevert("recipient-not-set");
544544
foreignController.transferTokenLayerZero{value: fee.nativeFee}(
545545
USDT_OFT,
546546
10_000_000e6,

0 commit comments

Comments
 (0)