Skip to content
Draft
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
24 changes: 24 additions & 0 deletions contracts/abi/createx.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "salt",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "initCode",
"type": "bytes"
}
],
"name": "deployCreate3",
"outputs": [
{
"internalType": "address",
"name": "newContract",
"type": "address"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
Expand Down
75 changes: 75 additions & 0 deletions contracts/contracts/interfaces/cctp/ICCTP.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

interface ICCTPTokenMessenger {
function depositForBurn(
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken,
bytes32 destinationCaller,
uint256 maxFee,
uint32 minFinalityThreshold
) external;

function depositForBurnWithHook(
uint256 amount,
uint32 destinationDomain,
bytes32 mintRecipient,
address burnToken,
bytes32 destinationCaller,
uint256 maxFee,
uint32 minFinalityThreshold,
bytes memory hookData
) external;

function getMinFeeAmount(uint256 amount) external view returns (uint256);
}

interface ICCTPMessageTransmitter {
function sendMessage(
uint32 destinationDomain,
bytes32 recipient,
bytes32 destinationCaller,
uint32 minFinalityThreshold,
bytes memory messageBody
) external;

function receiveMessage(bytes calldata message, bytes calldata attestation)
external
returns (bool);
}

interface IMessageHandlerV2 {
/**
* @notice Handles an incoming finalized message from an IReceiverV2
* @dev Finalized messages have finality threshold values greater than or equal to 2000
* @param sourceDomain The source domain of the message
* @param sender The sender of the message
* @param finalityThresholdExecuted the finality threshold at which the message was attested to
* @param messageBody The raw bytes of the message body
* @return success True, if successful; false, if not.
*/
function handleReceiveFinalizedMessage(
uint32 sourceDomain,
bytes32 sender,
uint32 finalityThresholdExecuted,
bytes calldata messageBody
) external returns (bool);

/**
* @notice Handles an incoming unfinalized message from an IReceiverV2
* @dev Unfinalized messages have finality threshold values less than 2000
* @param sourceDomain The source domain of the message
* @param sender The sender of the message
* @param finalityThresholdExecuted The finality threshold at which the message was attested to
* @param messageBody The raw bytes of the message body
* @return success True, if successful; false, if not.
*/
function handleReceiveUnfinalizedMessage(
uint32 sourceDomain,
bytes32 sender,
uint32 finalityThresholdExecuted,
bytes calldata messageBody
) external returns (bool);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

/**
* @title OUSD Yearn V3 Master Strategy Mock - the Mainnet part
* @author Origin Protocol Inc
*/

contract CrossChainMasterStrategyMock {
address public _remoteAddress;

constructor() {}

function remoteAddress() public view returns (address) {
return _remoteAddress;
}

function setRemoteAddress(address __remoteAddress) public {
_remoteAddress = __remoteAddress;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

/**
* @title OUSD Yearn V3 Remote Strategy Mock - the Mainnet part
Copy link
Member

Choose a reason for hiding this comment

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

"- the Mainnet part" should probably be "- the L2 chain part"

* @author Origin Protocol Inc
*/

contract CrossChainRemoteStrategyMock {
Copy link
Member

Choose a reason for hiding this comment

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

Remove is a better name than Slave :)

address public _masterAddress;

constructor() {}

function masterAddress() public view returns (address) {
return _masterAddress;
}

function setMasterAddress(address __masterAddress) public {
_masterAddress = __masterAddress;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import { InitializeGovernedUpgradeabilityProxy } from "./InitializeGovernedUpgradeabilityProxy.sol";

/**
* @title BaseGovernedUpgradeabilityProxy2
* @dev This is the same as InitializeGovernedUpgradeabilityProxy except that the
* governor is defined in the constructor.
* @author Origin Protocol Inc
*/
contract InitializeGovernedUpgradeabilityProxy2 is
InitializeGovernedUpgradeabilityProxy
{
/**
* This is used when the msg.sender can not be the governor. E.g. when the proxy is
* deployed via CreateX
*/
constructor(address governor) InitializeGovernedUpgradeabilityProxy() {
_setGovernor(governor);
}
}
1 change: 1 addition & 0 deletions contracts/contracts/proxies/Proxies.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import { InitializeGovernedUpgradeabilityProxy } from "./InitializeGovernedUpgradeabilityProxy.sol";
import { InitializeGovernedUpgradeabilityProxy2 } from "./InitializeGovernedUpgradeabilityProxy2.sol";

/**
* @notice OUSDProxy delegates calls to an OUSD implementation
Expand Down
23 changes: 23 additions & 0 deletions contracts/contracts/proxies/create2/CrossChainStrategyProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import { InitializeGovernedUpgradeabilityProxy2 } from "../InitializeGovernedUpgradeabilityProxy2.sol";

// ********************************************************
// ********************************************************
// IMPORTANT: DO NOT CHANGE ANYTHING IN THIS FILE.
// Any changes to this file (even whitespaces) will
// affect the create2 address of the proxy
// ********************************************************
// ********************************************************

/**
* @notice CrossChainStrategyProxy delegates calls to a
* CrossChainMasterStrategy or CrossChainRemoteStrategy
* implementation contract.
*/
contract CrossChainStrategyProxy is InitializeGovernedUpgradeabilityProxy2 {
constructor(address governor)
InitializeGovernedUpgradeabilityProxy2(governor)
{}
}
11 changes: 10 additions & 1 deletion contracts/contracts/strategies/Generalized4626Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ contract Generalized4626Strategy is InitializableAbstractStrategy {
*/
function deposit(address _asset, uint256 _amount)
external
virtual
override
onlyVault
nonReentrant
Expand Down Expand Up @@ -99,6 +100,14 @@ contract Generalized4626Strategy is InitializableAbstractStrategy {
address _asset,
uint256 _amount
) external virtual override onlyVault nonReentrant {
_withdraw(_recipient, _asset, _amount);
}

function _withdraw(
address _recipient,
address _asset,
uint256 _amount
) internal virtual {
require(_amount > 0, "Must withdraw something");
require(_recipient != address(0), "Must specify recipient");
require(_asset == address(assetToken), "Unexpected asset address");
Expand Down Expand Up @@ -147,7 +156,7 @@ contract Generalized4626Strategy is InitializableAbstractStrategy {
* @return balance Total value of the asset in the platform
*/
function checkBalance(address _asset)
external
public
view
virtual
override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

/**
* @title AbstractCCTP4626Strategy - Abstract contract for CCTP morpho strategy
* @author Origin Protocol Inc
*/

import { AbstractCCTPIntegrator } from "./AbstractCCTPIntegrator.sol";

abstract contract AbstractCCTP4626Strategy is AbstractCCTPIntegrator {
uint32 public constant DEPOSIT_MESSAGE = 1;
uint32 public constant WITHDRAW_MESSAGE = 2;
uint32 public constant BALANCE_CHECK_MESSAGE = 3;

constructor(CCTPIntegrationConfig memory _config)
AbstractCCTPIntegrator(_config)
{}

function _encodeDepositMessage(uint64 nonce, uint256 depositAmount)
internal
virtual
returns (bytes memory)
{
return
abi.encodePacked(
ORIGIN_MESSAGE_VERSION,
DEPOSIT_MESSAGE,
abi.encode(nonce, depositAmount)
);
}

function _decodeDepositMessage(bytes memory message)
internal
virtual
returns (uint64, uint256)
{
_verifyMessageVersionAndType(
message,
ORIGIN_MESSAGE_VERSION,
DEPOSIT_MESSAGE
);

(uint64 nonce, uint256 depositAmount) = abi.decode(
_getMessagePayload(message),
(uint64, uint256)
);
return (nonce, depositAmount);
}

function _encodeWithdrawMessage(uint64 nonce, uint256 withdrawAmount)
internal
virtual
returns (bytes memory)
{
return
abi.encodePacked(
ORIGIN_MESSAGE_VERSION,
WITHDRAW_MESSAGE,
abi.encode(nonce, withdrawAmount)
);
}

function _decodeWithdrawMessage(bytes memory message)
internal
virtual
returns (uint64, uint256)
{
_verifyMessageVersionAndType(
message,
ORIGIN_MESSAGE_VERSION,
WITHDRAW_MESSAGE
);

(uint64 nonce, uint256 withdrawAmount) = abi.decode(
_getMessagePayload(message),
(uint64, uint256)
);
return (nonce, withdrawAmount);
}

function _encodeBalanceCheckMessage(uint64 nonce, uint256 balance)
internal
virtual
returns (bytes memory)
{
return
abi.encodePacked(
ORIGIN_MESSAGE_VERSION,
BALANCE_CHECK_MESSAGE,
abi.encode(nonce, balance)
);
}

function _decodeBalanceCheckMessage(bytes memory message)
internal
virtual
returns (uint64, uint256)
{
_verifyMessageVersionAndType(
message,
ORIGIN_MESSAGE_VERSION,
BALANCE_CHECK_MESSAGE
);

(uint64 nonce, uint256 balance) = abi.decode(
_getMessagePayload(message),
(uint64, uint256)
);
return (nonce, balance);
}
}
Loading
Loading