Skip to content
Open
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
50 changes: 49 additions & 1 deletion contracts/FraxOFTAdapterUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
pragma solidity ^0.8.22;

import { OFTAdapterUpgradeable } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/OFTAdapterUpgradeable.sol";
import { SendParam, OFTLimit, OFTFeeDetail, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { RateLimiterModule } from "contracts/modules/RateLimiterModule.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract FraxOFTAdapterUpgradeable is OFTAdapterUpgradeable, RateLimiterModule {
using SafeERC20 for IERC20;

contract FraxOFTAdapterUpgradeable is OFTAdapterUpgradeable {
constructor(
address _token,
address _lzEndpoint
Expand All @@ -22,4 +28,46 @@ contract FraxOFTAdapterUpgradeable is OFTAdapterUpgradeable {
__Ownable_init();
_transferOwnership(_delegate);
}

function quoteOFT(
SendParam calldata _sendParam
)
external
view
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
uint256 minAmountLD = 0;
uint256 maxAmountLD = _removeDust(_rateLimitedMaxAmountLD(_sendParam.dstEid));
oftLimit = OFTLimit(minAmountLD, maxAmountLD);

oftFeeDetails = new OFTFeeDetail[](0);

(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}

function _debit(
uint256 _amountLD,
uint256 _minAmountLD,
uint32 _dstEid
) internal override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);
_consumeOutboundRateLimit(_dstEid, amountSentLD);
innerToken.safeTransferFrom(msg.sender, address(this), amountSentLD);
}

function _credit(
address _to,
uint256 _amountLD,
uint32 _srcEid
) internal override returns (uint256 amountReceivedLD) {
_consumeInboundRateLimit(_srcEid, _amountLD);
innerToken.safeTransfer(_to, _amountLD);
return _amountLD;
}
}
28 changes: 27 additions & 1 deletion contracts/FraxOFTMintableAdapterUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
pragma solidity ^0.8.22;

import { OFTAdapterUpgradeable } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/OFTAdapterUpgradeable.sol";
import { SendParam, OFTLimit, OFTFeeDetail, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { SupplyTrackingModule } from "./modules/SupplyTrackingModule.sol";
import { RateLimiterModule } from "./modules/RateLimiterModule.sol";

interface IERC20PermitPermissionedOptiMintable {
function minter_burn_from(address, uint256) external;
function minter_mint(address, uint256) external;
}

contract FraxOFTMintableAdapterUpgradeable is OFTAdapterUpgradeable, SupplyTrackingModule {
contract FraxOFTMintableAdapterUpgradeable is OFTAdapterUpgradeable, SupplyTrackingModule, RateLimiterModule {
constructor(
address _token,
address _lzEndpoint
Expand All @@ -36,6 +38,28 @@ contract FraxOFTMintableAdapterUpgradeable is OFTAdapterUpgradeable, SupplyTrack
_setInitialTotalSupply(_eid, _amount);
}

function quoteOFT(
SendParam calldata _sendParam
)
external
view
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
uint256 minAmountLD = 0;
uint256 maxAmountLD = _removeDust(_rateLimitedMaxAmountLD(_sendParam.dstEid));
oftLimit = OFTLimit(minAmountLD, maxAmountLD);

oftFeeDetails = new OFTFeeDetail[](0);

(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}

/// @dev overrides OFTAdapterUpgradeable.sol to burn the tokens from the sender/track supply
/// @dev added in v1.1.0
function _debit(
Expand All @@ -44,6 +68,7 @@ contract FraxOFTMintableAdapterUpgradeable is OFTAdapterUpgradeable, SupplyTrack
uint32 _dstEid
) internal override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);
_consumeOutboundRateLimit(_dstEid, amountSentLD);

_addToTotalTransferTo(_dstEid, amountSentLD);

Expand All @@ -57,6 +82,7 @@ contract FraxOFTMintableAdapterUpgradeable is OFTAdapterUpgradeable, SupplyTrack
uint256 _amountLD,
uint32 _srcEid
) internal override returns (uint256 amountReceivedLD) {
_consumeInboundRateLimit(_srcEid, _amountLD);

_addToTotalTransferFrom(_srcEid, _amountLD);

Expand Down
29 changes: 27 additions & 2 deletions contracts/FraxOFTMintableAdapterUpgradeableTIP20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ pragma solidity ^0.8.22;

import { OFTAdapterUpgradeable } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/OFTAdapterUpgradeable.sol";
import { SupplyTrackingModule } from "contracts/modules/SupplyTrackingModule.sol";
import { RateLimiterModule } from "contracts/modules/RateLimiterModule.sol";
import { TempoAltTokenBase } from "contracts/base/TempoAltTokenBase.sol";
import { ITIP20 } from "@tempo/interfaces/ITIP20.sol";
import { MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { IOFT, SendParam, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { IOFT, SendParam, OFTLimit, OFTFeeDetail, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract FraxOFTMintableAdapterUpgradeableTIP20 is OFTAdapterUpgradeable, SupplyTrackingModule, TempoAltTokenBase {
contract FraxOFTMintableAdapterUpgradeableTIP20 is OFTAdapterUpgradeable, SupplyTrackingModule, TempoAltTokenBase, RateLimiterModule {
/// @notice Emitted when ERC20 tokens are recovered
event RecoveredERC20(address indexed token, uint256 amount);

Expand Down Expand Up @@ -47,6 +48,28 @@ contract FraxOFTMintableAdapterUpgradeableTIP20 is OFTAdapterUpgradeable, Supply
_setInitialTotalSupply(_eid, _amount);
}

function quoteOFT(
SendParam calldata _sendParam
)
external
view
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
uint256 minAmountLD = 0;
uint256 maxAmountLD = _removeDust(_rateLimitedMaxAmountLD(_sendParam.dstEid));
oftLimit = OFTLimit(minAmountLD, maxAmountLD);

oftFeeDetails = new OFTFeeDetail[](0);

(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}

/// @inheritdoc IOFT
/// @dev Overrides send to prevent msg.value being sent (EndpointV2Alt uses ERC20 for gas)
function send(
Expand Down Expand Up @@ -81,6 +104,7 @@ contract FraxOFTMintableAdapterUpgradeableTIP20 is OFTAdapterUpgradeable, Supply
uint32 _dstEid
) internal override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);
_consumeOutboundRateLimit(_dstEid, amountSentLD);

_addToTotalTransferTo(_dstEid, amountSentLD);

Expand All @@ -96,6 +120,7 @@ contract FraxOFTMintableAdapterUpgradeableTIP20 is OFTAdapterUpgradeable, Supply
uint256 _amountLD,
uint32 _srcEid
) internal override returns (uint256 amountReceivedLD) {
_consumeInboundRateLimit(_srcEid, _amountLD);
_addToTotalTransferFrom(_srcEid, _amountLD);

ITIP20(address(innerToken)).mint(_to, _amountLD);
Expand Down
49 changes: 46 additions & 3 deletions contracts/FraxOFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
pragma solidity ^0.8.22;

import { OFTUpgradeable } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/OFTUpgradeable.sol";
import { SendParam } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { SendParam, OFTLimit, OFTFeeDetail, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";

import {EIP3009Module} from "contracts/modules/EIP3009Module.sol";
import {PermitModule} from "contracts/modules/PermitModule.sol";
import {RateLimiterModule} from "contracts/modules/RateLimiterModule.sol";

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

contract FraxOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule {
contract FraxOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule, RateLimiterModule {
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {
_disableInitializers();
}
Expand Down Expand Up @@ -63,10 +64,52 @@ contract FraxOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule {
return _buildMsgAndOptions(_sendParam, _amountLD);
}

function quoteOFT(
SendParam calldata _sendParam
)
external
view
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
uint256 minAmountLD = 0;
uint256 maxAmountLD = _removeDust(_rateLimitedMaxAmountLD(_sendParam.dstEid));
oftLimit = OFTLimit(minAmountLD, maxAmountLD);

oftFeeDetails = new OFTFeeDetail[](0);

(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}

//==============================================================================
// Overrides
//==============================================================================

function _debit(
uint256 _amountLD,
uint256 _minAmountLD,
uint32 _dstEid
) internal override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);
_consumeOutboundRateLimit(_dstEid, amountSentLD);
_burn(msg.sender, amountSentLD);
}

function _credit(
address _to,
uint256 _amountLD,
uint32 _srcEid
) internal override returns (uint256 amountReceivedLD) {
_consumeInboundRateLimit(_srcEid, _amountLD);
_mint(_to, _amountLD);
return _amountLD;
}

/// @dev supports EIP3009
function _transfer(address from, address to, uint256 amount) internal override(EIP3009Module, ERC20Upgradeable) {
return ERC20Upgradeable._transfer(from, to, amount);
Expand All @@ -76,4 +119,4 @@ contract FraxOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule {
function _approve(address owner, address spender, uint256 amount) internal override(PermitModule, ERC20Upgradeable) {
return ERC20Upgradeable._approve(owner, spender, amount);
}
}
}
49 changes: 46 additions & 3 deletions contracts/WFRAXTokenOFTUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
pragma solidity ^0.8.22;

import { OFTUpgradeable } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/OFTUpgradeable.sol";
import { SendParam } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";
import { SendParam, OFTLimit, OFTFeeDetail, OFTReceipt } from "@fraxfinance/layerzero-v2-upgradeable/oapp/contracts/oft/interfaces/IOFT.sol";

import {EIP3009Module} from "contracts/modules/EIP3009Module.sol";
import {PermitModule} from "contracts/modules/PermitModule.sol";
import {RateLimiterModule} from "contracts/modules/RateLimiterModule.sol";

import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";

contract WFRAXTokenOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule {
contract WFRAXTokenOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule, RateLimiterModule {
constructor(address _lzEndpoint) OFTUpgradeable(_lzEndpoint) {
_disableInitializers();
}
Expand Down Expand Up @@ -57,10 +58,52 @@ contract WFRAXTokenOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule
return _buildMsgAndOptions(_sendParam, _amountLD);
}

function quoteOFT(
SendParam calldata _sendParam
)
external
view
override
returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
{
uint256 minAmountLD = 0;
uint256 maxAmountLD = _removeDust(_rateLimitedMaxAmountLD(_sendParam.dstEid));
oftLimit = OFTLimit(minAmountLD, maxAmountLD);

oftFeeDetails = new OFTFeeDetail[](0);

(uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
}

//==============================================================================
// Overrides
//==============================================================================

function _debit(
uint256 _amountLD,
uint256 _minAmountLD,
uint32 _dstEid
) internal override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
(amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);
_consumeOutboundRateLimit(_dstEid, amountSentLD);
_burn(msg.sender, amountSentLD);
}

function _credit(
address _to,
uint256 _amountLD,
uint32 _srcEid
) internal override returns (uint256 amountReceivedLD) {
_consumeInboundRateLimit(_srcEid, _amountLD);
_mint(_to, _amountLD);
return _amountLD;
}

/// @dev supports EIP3009
function _transfer(address from, address to, uint256 amount) internal override(EIP3009Module, ERC20Upgradeable) {
return ERC20Upgradeable._transfer(from, to, amount);
Expand All @@ -70,4 +113,4 @@ contract WFRAXTokenOFTUpgradeable is OFTUpgradeable, EIP3009Module, PermitModule
function _approve(address owner, address spender, uint256 amount) internal override(PermitModule, ERC20Upgradeable) {
return ERC20Upgradeable._approve(owner, spender, amount);
}
}
}
Loading
Loading