Skip to content

Commit

Permalink
Merge pull request #861 from ionicprotocol/development
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
rhlsthrm authored Dec 17, 2024
2 parents 816728b + 480965b commit db8e99b
Show file tree
Hide file tree
Showing 24 changed files with 5,417 additions and 345 deletions.
2 changes: 1 addition & 1 deletion ops/modules/lambda/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ resource "aws_lambda_function" "executable" {
timeout = var.timeout
memory_size = var.memory_size
environment {
variables = merge(var.container_env_vars, { TARGET_target_chain_id = var.target_chain_id })
variables = merge(var.container_env_vars, { TARGET_CHAIN_ID = var.target_chain_id })
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/bots/pyth-updater/src/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const config = {
environment: process.env.NODE_ENV ?? 'development',
logLevel: process.env.LOG_LEVEL ?? 'info',
chainId: parseInt(process.env.TARGET_CHAIN_ID ?? '8453', 10),
rpcUrls: process.env.BASE_MAINNET_RPCS
? process.env.BASE_MAINNET_RPCS.split(',')
rpcUrls: process.env.WEB3_HTTP_PROVIDER_URLS
? process.env.WEB3_HTTP_PROVIDER_URLS.split(',')
: ['https://base-rpc.publicnode.com'], // Updated to handle multiple RPC URLs
adminPrivateKey: process.env.PYTH_UPDATER_ETHEREUM_ADMIN_PRIVATE_KEY ?? '',
adminAccount: process.env.PYTH_UPDATER_ETHEREUM_ADMIN_ACCOUNT ?? '',
Expand Down
32 changes: 27 additions & 5 deletions packages/contracts/contracts/compound/CTokenOracleProtected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,53 @@ import { IHypernativeOracle } from "../external/hypernative/interfaces/IHypernat

contract CTokenOracleProtected is CErc20Storage {
error InteractionNotAllowed();
error CallerIsNotEOA();

modifier onlyOracleApproved() {
address oracleAddress = ap.getAddress("HYPERNATIVE_ORACLE");

if (oracleAddress == address(0)) {
_;
return;
}

IHypernativeOracle oracle = IHypernativeOracle(oracleAddress);
if (oracle.isBlacklistedContext(msg.sender, tx.origin) || !oracle.isTimeExceeded(msg.sender)) {
revert InteractionNotAllowed();
}
oracle.validateForbiddenContextInteraction(tx.origin, msg.sender);
_;
}

modifier onlyOracleApprovedAllowEOA() {
address oracleAddress = ap.getAddress("HYPERNATIVE_ORACLE");

if (oracleAddress == address(0)) {
_;
return;
}

IHypernativeOracle oracle = IHypernativeOracle(oracleAddress);
oracle.validateBlacklistedAccountInteraction(msg.sender);
if (tx.origin == msg.sender) {
_;
return;
}

oracle.validateForbiddenContextInteraction(tx.origin, msg.sender);
_;
}

modifier onlyNotBlacklistedEOA() {
address oracleAddress = ap.getAddress("HYPERNATIVE_ORACLE");

if (oracleAddress == address(0)) {
_;
return;
}

IHypernativeOracle oracle = IHypernativeOracle(oracleAddress);
if (oracle.isBlacklistedAccount(msg.sender) || msg.sender != tx.origin) {
revert InteractionNotAllowed();
if (msg.sender != tx.origin) {
revert CallerIsNotEOA();
}
oracle.validateBlacklistedAccountInteraction(msg.sender);
_;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
pragma solidity ^0.8.22;

interface IHypernativeOracle {
function register(address account) external;
function registerStrict(address account) external;
function isBlacklistedAccount(address account) external view returns (bool);
function isBlacklistedContext(address sender, address origin) external view returns (bool);
function isTimeExceeded(address account) external view returns (bool);
}
function register(address account, bool isStrictMode) external;
function validateForbiddenAccountInteraction(address sender) external view;
function validateForbiddenContextInteraction(address origin, address sender) external view;
function validateBlacklistedAccountInteraction(address sender) external;
}
9 changes: 3 additions & 6 deletions packages/contracts/contracts/security/OracleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ contract OracleRegistry is Ownable2Step {
constructor() Ownable2Step() {}

function oracleRegister(address _account) public {
address oracleAddress = _getAddressBySlot(HYPERNATIVE_ORACLE_STORAGE_SLOT);
address oracleAddress = hypernativeOracle();
bool isStrictMode = hypernativeOracleIsStrictMode();
IHypernativeOracle oracle = IHypernativeOracle(oracleAddress);
if (hypernativeOracleIsStrictMode()) {
oracle.registerStrict(_account);
} else {
oracle.register(_account);
}
oracle.register(_account, isStrictMode);
}

function setOracle(address _oracle) public onlyOwner {
Expand Down
35 changes: 16 additions & 19 deletions packages/contracts/contracts/test/OracleProtectedTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,30 @@ import { InterestRateModel } from "../compound/InterestRateModel.sol";
import { IHypernativeOracle } from "../external/hypernative/interfaces/IHypernativeOracle.sol";
import { AddressesProvider } from "../ionic/AddressesProvider.sol";
contract MockOraclePasses is IHypernativeOracle {
function isBlacklistedContext(address _account, address _origin) external pure returns (bool) {
return false;
}
function isTimeExceeded(address _account) external pure returns (bool) {
return true;
}
function isBlacklistedAccount(address _account) external pure returns (bool) {
return false;
}
function register(address _account) external {}
function registerStrict(address _account) external {}
function register(address account, bool isStrictMode) external pure {}

function validateForbiddenAccountInteraction(address sender) external pure {}

function validateForbiddenContextInteraction(address origin, address sender) external pure {}

function validateBlacklistedAccountInteraction(address sender) external pure {}
}

contract MockOracleFails is IHypernativeOracle {
function isBlacklistedContext(address _account, address _origin) external pure returns (bool) {
return true;
error InteractionNotAllowed();
function register(address account, bool isStrictMode) external pure {}

function validateForbiddenAccountInteraction(address sender) external pure {
revert InteractionNotAllowed();
}

function isTimeExceeded(address _account) external pure returns (bool) {
return true;
function validateForbiddenContextInteraction(address origin, address sender) external pure {
revert InteractionNotAllowed();
}

function isBlacklistedAccount(address _account) external pure returns (bool) {
return false;
function validateBlacklistedAccountInteraction(address sender) external pure {
revert InteractionNotAllowed();
}
function register(address _account) external {}
function registerStrict(address _account) external {}
}

contract OracleProtectedTest is UpgradesBaseTest {
Expand Down
152 changes: 76 additions & 76 deletions packages/contracts/deploy/03-deploy-ctokens-set-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
});
console.log("CErc20RewardsDelegate: ", erc20RewardsDel.address);

const erc20PluginRewardsDel = await deployments.deploy("CErc20PluginRewardsDelegate", {
from: deployer,
args: [],
log: true,
waitConfirmations: 1
});
console.log("CErc20PluginRewardsDelegate: ", erc20PluginRewardsDel.address);
// const erc20PluginRewardsDel = await deployments.deploy("CErc20PluginRewardsDelegate", {
// from: deployer,
// args: [],
// log: true,
// waitConfirmations: 1
// });
// console.log("CErc20PluginRewardsDelegate: ", erc20PluginRewardsDel.address);

const becomeImplementationData = encodeAbiParameters(parseAbiParameters("address"), [zeroAddress]);

Expand Down Expand Up @@ -250,75 +250,75 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
}
}

{
// CErc20PluginRewardsDelegate
const erc20PluginRewardsDelExtensions = await fuseFeeDistributor.read.getCErc20DelegateExtensions([
erc20PluginRewardsDel.address as Address
]);
if (
erc20PluginRewardsDelExtensions.length == 0 ||
erc20PluginRewardsDelExtensions[0] != erc20PluginRewardsDel.address ||
erc20PluginRewardsDelExtensions[1] != cTokenFirstExtension.address
) {
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
await prepareAndLogTransaction({
contractInstance: fuseFeeDistributor,
functionName: "_setCErc20DelegateExtensions",
args: [
erc20PluginRewardsDel.address as Address,
[erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
],
description: "Set CErc20PluginRewardsDelegate Extensions",
inputs: [
{ internalType: "address", name: "cErc20Delegate", type: "address" },
{ internalType: "address[]", name: "extensions", type: "address[]" }
]
});
} else {
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
erc20PluginRewardsDel.address as Address,
[erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
]);
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(`configured the extensions for the CErc20PluginRewardsDelegate ${erc20PluginRewardsDel.address}`);
}
} else {
console.log(`CErc20PluginRewardsDelegate extensions already configured`);
}
const [latestCErc20PluginRewardsDelegate] = await fuseFeeDistributor.read.latestCErc20Delegate([4]);
if (
latestCErc20PluginRewardsDelegate === zeroAddress ||
latestCErc20PluginRewardsDelegate !== erc20PluginRewardsDel.address
) {
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
await prepareAndLogTransaction({
contractInstance: fuseFeeDistributor,
functionName: "_setLatestCErc20Delegate",
args: [4, erc20PluginRewardsDel.address as Address, becomeImplementationData],
description: "Set Latest CErc20PluginRewardsDelegate",
inputs: [
{ internalType: "uint8", name: "delegateType", type: "uint8" },
{ internalType: "address", name: "newImplementation", type: "address" },
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
]
});
} else {
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
4,
erc20PluginRewardsDel.address as Address,
becomeImplementationData
]);
await publicClient.waitForTransactionReceipt({ hash: tx });
console.log(
`Set the latest CErc20PluginRewardsDelegate implementation from ${latestCErc20PluginRewardsDelegate} to ${erc20PluginRewardsDel.address}`
);
}
} else {
console.log(
`No change in the latest CErc20PluginRewardsDelegate implementation ${erc20PluginRewardsDel.address}`
);
}
}
// {
// // CErc20PluginRewardsDelegate
// const erc20PluginRewardsDelExtensions = await fuseFeeDistributor.read.getCErc20DelegateExtensions([
// erc20PluginRewardsDel.address as Address
// ]);
// if (
// erc20PluginRewardsDelExtensions.length == 0 ||
// erc20PluginRewardsDelExtensions[0] != erc20PluginRewardsDel.address ||
// erc20PluginRewardsDelExtensions[1] != cTokenFirstExtension.address
// ) {
// if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
// await prepareAndLogTransaction({
// contractInstance: fuseFeeDistributor,
// functionName: "_setCErc20DelegateExtensions",
// args: [
// erc20PluginRewardsDel.address as Address,
// [erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
// ],
// description: "Set CErc20PluginRewardsDelegate Extensions",
// inputs: [
// { internalType: "address", name: "cErc20Delegate", type: "address" },
// { internalType: "address[]", name: "extensions", type: "address[]" }
// ]
// });
// } else {
// tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
// erc20PluginRewardsDel.address as Address,
// [erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
// ]);
// await publicClient.waitForTransactionReceipt({ hash: tx });
// console.log(`configured the extensions for the CErc20PluginRewardsDelegate ${erc20PluginRewardsDel.address}`);
// }
// } else {
// console.log(`CErc20PluginRewardsDelegate extensions already configured`);
// }
// const [latestCErc20PluginRewardsDelegate] = await fuseFeeDistributor.read.latestCErc20Delegate([4]);
// if (
// latestCErc20PluginRewardsDelegate === zeroAddress ||
// latestCErc20PluginRewardsDelegate !== erc20PluginRewardsDel.address
// ) {
// if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
// await prepareAndLogTransaction({
// contractInstance: fuseFeeDistributor,
// functionName: "_setLatestCErc20Delegate",
// args: [4, erc20PluginRewardsDel.address as Address, becomeImplementationData],
// description: "Set Latest CErc20PluginRewardsDelegate",
// inputs: [
// { internalType: "uint8", name: "delegateType", type: "uint8" },
// { internalType: "address", name: "newImplementation", type: "address" },
// { internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
// ]
// });
// } else {
// tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
// 4,
// erc20PluginRewardsDel.address as Address,
// becomeImplementationData
// ]);
// await publicClient.waitForTransactionReceipt({ hash: tx });
// console.log(
// `Set the latest CErc20PluginRewardsDelegate implementation from ${latestCErc20PluginRewardsDelegate} to ${erc20PluginRewardsDel.address}`
// );
// }
// } else {
// console.log(
// `No change in the latest CErc20PluginRewardsDelegate implementation ${erc20PluginRewardsDel.address}`
// );
// }
// }
};

func.tags = ["prod", "market-setup"];
Expand Down
103 changes: 54 additions & 49 deletions packages/contracts/deployments/base/CErc20Delegate.json

Large diffs are not rendered by default.

109 changes: 57 additions & 52 deletions packages/contracts/deployments/base/CErc20PluginDelegate.json

Large diffs are not rendered by default.

103 changes: 54 additions & 49 deletions packages/contracts/deployments/base/CErc20RewardsDelegate.json

Large diffs are not rendered by default.

103 changes: 54 additions & 49 deletions packages/contracts/deployments/base/CTokenFirstExtension.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions packages/contracts/deployments/base/OracleRegistry.json

Large diffs are not rendered by default.

Loading

0 comments on commit db8e99b

Please sign in to comment.