Skip to content

Commit

Permalink
feat: finalized scenarios, added ronin bridge receiver, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
artemwoofsoftware committed Jan 29, 2025
1 parent 0f3cd57 commit f011826
Show file tree
Hide file tree
Showing 15 changed files with 186 additions and 78 deletions.
36 changes: 36 additions & 0 deletions contracts/bridges/ronin/RoninBridgeReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;

import "../SweepableBridgeReceiver.sol";

contract RoninBridgeReceiver is SweepableBridgeReceiver {
struct Any2EVMMessage {
bytes32 messageId;
uint64 sourceChainSelector;
bytes sender;
bytes data;
EVMTokenAmount[] destTokenAmounts;
}
struct EVMTokenAmount {
address token;
uint256 amount;
}

error InvalidRouter();

address public l2Router;

constructor(address l2Router_) {
l2Router = l2Router_;
}

function ccipReceive(Any2EVMMessage calldata message) external {
if (msg.sender != l2Router) revert InvalidRouter();
processMessage(toAddress(message.sender), message.data);
}

function toAddress(bytes memory data) public pure returns (address addr) {
require(data.length >= 20, "Invalid data length");
return abi.decode(data, (address));
}
}
45 changes: 0 additions & 45 deletions deployments/ronin-saigon/usdc/configuration.json

This file was deleted.

45 changes: 45 additions & 0 deletions deployments/ronin-saigon/weth/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "Compound WETH",
"symbol": "cWETHv3",
"baseToken": "WETH",
"baseTokenAddress": "0x3eb007a52b5Ba013e65B787c04bF775b946115B1",
"rewardTokenAddress": "0xfF5C5b4e3Cbc5513b3Ef462f00E4477Ee16a8C56",
"borrowMin": "0.01e18",
"storeFrontPriceFactor": 0.6,
"targetReserves": "5_000_000e18",
"pauseGuardian": "0xf6c14190474A96189aad3e931E20c92E62D965D1",
"rates": {
"borrowBase": 0.015,
"borrowSlopeLow": 0.0333,
"borrowKink": 0.9,
"borrowSlopeHigh": 4.0,
"supplyBase": 0,
"supplySlopeLow": 0.039,
"supplyKink": 0.9,
"supplySlopeHigh": 3.6
},
"tracking": {
"indexScale": "1e15",
"baseSupplySpeed": "46296296296e0",
"baseBorrowSpeed": "46296296296e0",
"baseMinForRewards": "1000e18"
},
"assets": {
"COMP": {
"address": "0xfF5C5b4e3Cbc5513b3Ef462f00E4477Ee16a8C56",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.87,
"liquidationFactor": 0.93,
"supplyCap": "2800e18"
},
"WRON": {
"address": "0xA959726154953bAe111746E265E6d754F48570E6",
"decimals": "18",
"borrowCF": 0.82,
"liquidateCF": 0.87,
"liquidationFactor": 0.93,
"supplyCap": "2800e18"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DeploySpec, deployComet, exp } from '../../../src/deploy';
const HOUR = 60 * 60;
const DAY = 24 * HOUR;

const MAINNET_TIMELOCK = '0x6d903f6003cca6255d85cca4d3b5e5146dc33925';
const SEPOLIA_TIMELOCK = '0x54a06047087927D9B0fb21c1cf0ebd792764dDB8';

export default async function deploy(
deploymentManager: DeploymentManager,
Expand Down Expand Up @@ -57,7 +57,7 @@ async function deployContracts(
// Deploy OptimismBridgeReceiver
const bridgeReceiver = await deploymentManager.deploy(
'bridgeReceiver',
'bridges/optimism/OptimismBridgeReceiver.sol',
'bridges/ronin/RoninBridgeReceiver.sol',
[l2CCIPRouter.address]
);

Expand All @@ -80,28 +80,27 @@ async function deployContracts(
async () => {
trace(`Initializing BridgeReceiver`);
await bridgeReceiver.initialize(
MAINNET_TIMELOCK, // govTimelock
SEPOLIA_TIMELOCK, // govTimelock
localTimelock.address // localTimelock
);
trace(`BridgeReceiver initialized`);
}
);

const USDCPriceFeed = await deploymentManager.deploy(
'USDC:simplePriceFeed',
const WETHPriceFeed = await deploymentManager.deploy(
'WETH:simplePriceFeed',
'test/SimplePriceFeed.sol',
[
exp(0.98882408, 18), // Latest answer on mainnet at block 16170924
exp(1, 18),
8
]
);

// Deploy cbETH / ETH SimplePriceFeed
const WRONPriceFeed = await deploymentManager.deploy(
'WRON:simplePriceFeed',
'test/SimplePriceFeed.sol',
[
exp(0.97, 18),
exp(0.047, 18),
8
]
);
Expand All @@ -110,7 +109,7 @@ async function deployContracts(
'COMP:simplePriceFeed',
'test/SimplePriceFeed.sol',
[
exp(0.97, 18),
exp(0.022, 18),
8
]
);
Expand Down Expand Up @@ -140,7 +139,7 @@ async function deployContracts(

// Deploy all Comet-related contracts
const deployed = await deployComet(deploymentManager, deploySpec, {
baseTokenPriceFeed: USDCPriceFeed.address,
baseTokenPriceFeed: WETHPriceFeed.address,
assetConfigs: [assetConfig0, assetConfig1],
});
// Deploy Comet
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import optimismUsdtRelationConfigMap from './deployments/optimism/usdt/relations
import optimismWethRelationConfigMap from './deployments/optimism/weth/relations';
import mantleRelationConfigMap from './deployments/mantle/usde/relations';
import scrollRelationConfigMap from './deployments/scroll/usdc/relations';
import roninSaigonRelationConfigMap from './deployments/ronin-saigon/usdc/relations';
import roninSaigonRelationConfigMap from './deployments/ronin-saigon/weth/relations';

task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
for (const account of await hre.ethers.getSigners()) console.log(account.address);
Expand Down Expand Up @@ -349,7 +349,7 @@ const config: HardhatUserConfig = {
usdc: scrollRelationConfigMap
},
'ronin-saigon': {
usdc: roninSaigonRelationConfigMap
weth: roninSaigonRelationConfigMap
}
},
},
Expand Down Expand Up @@ -495,7 +495,7 @@ const config: HardhatUserConfig = {
{
name: 'ronin-saigon',
network: 'ronin-saigon',
deployment: 'usdc',
deployment: 'weth',
auxiliaryBase: 'sepolia-usdc'
}
],
Expand Down
4 changes: 0 additions & 4 deletions plugins/import/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export function getEtherscanUrl(network: string): string {
base: 'basescan.org',
optimism: 'optimistic.etherscan.io',
mantle: 'mantlescan.xyz',
<<<<<<< HEAD
'ronin-saigon': 'explorer-kintsugi.roninchain.com/v2/2021',
'scroll-goerli': 'alpha-blockscout.scroll.io',
=======
>>>>>>> 4351754488084e32d366b0fbe91ebbb19b28cfa3
scroll: 'scrollscan.com'
}[network];

Expand Down
9 changes: 7 additions & 2 deletions scenario/BulkerScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ scenario(
scenario(
'Comet#bulker > (WETH base) all non-reward actions in one txn',
{
filter: async (ctx) => await isBulkerSupported(ctx) && matchesDeployment(ctx, [{ deployment: 'weth' }]),
filter: async (ctx) => await isBulkerSupported(ctx) &&
matchesDeployment(ctx, [{ deployment: 'weth' }]) &&
!matchesDeployment(ctx, [{ network: 'ronin-saigon', deployment: 'weth'}]),
supplyCaps: async (ctx) => (
{
$asset0: getConfigForScenario(ctx).bulkerAsset,
Expand Down Expand Up @@ -515,7 +517,10 @@ scenario(
scenario(
'Comet#bulker > (WETH base) all actions in one txn',
{
filter: async (ctx) => await isBulkerSupported(ctx) && await isRewardSupported(ctx) && matchesDeployment(ctx, [{ deployment: 'weth' }]),
filter: async (ctx) => await isBulkerSupported(ctx) &&
await isRewardSupported(ctx) &&
matchesDeployment(ctx, [{ deployment: 'weth' }]) &&
!matchesDeployment(ctx, [{ network: 'ronin-saigon', deployment: 'weth'}]),
supplyCaps: {
$asset0: 10,
},
Expand Down
15 changes: 9 additions & 6 deletions scenario/RewardsScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isRewardSupported, matchesDeployment } from './utils';
import { Contract, ContractReceipt } from 'ethers';
import { CometRewards, ERC20__factory } from '../build/types';
import {World} from '../plugins/scenario';
import { getConfigForScenario } from './utils/scenarioHelper';

function calculateRewardsOwed(
userBalance: bigint,
Expand Down Expand Up @@ -152,20 +153,22 @@ scenario(
'Comet#rewards > can claim borrow rewards for self',
{
filter: async (ctx) => await isRewardSupported(ctx),
tokenBalances: {
albert: { $asset0: ' == 10000' }, // in units of asset, not wei
$comet: { $base: ' >= 1000 ' }
},
tokenBalances: async (ctx) => (
{
albert: { $asset0: ` == ${getConfigForScenario(ctx).rewardsAsset}` }, // in units of asset, not wei
$comet: { $base: ` >= ${getConfigForScenario(ctx).rewardsBase} ` }
}
)
},
async ({ comet, rewards, actors }, context, world) => {
const { albert } = actors;
const { asset: collateralAssetAddress, scale: scaleBN } = await comet.getAssetInfo(0);
const collateralAsset = context.getAssetByAddress(collateralAssetAddress);
const scale = scaleBN.toBigInt();
const toSupply = 10_000n * scale;
const toSupply = BigInt(getConfigForScenario(context).rewardsAsset) * scale;
const baseAssetAddress = await comet.baseToken();
const baseScale = (await comet.baseScale()).toBigInt();
const toBorrow = 1_000n * baseScale;
const toBorrow = BigInt(getConfigForScenario(context).rewardsBase) * baseScale;

const { rescaleFactor } = await context.getRewardConfig();
const rewardToken = await context.getRewardToken();
Expand Down
4 changes: 3 additions & 1 deletion scenario/SupplyScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ scenario(
/transfer amount exceeds spender allowance/,
/Dai\/insufficient-allowance/,
symbol === 'WETH' ? /Transaction reverted without a reason string/ : /.^/,
symbol === 'WRON' ? /Transaction reverted without a reason string/ : /.^/,
symbol === 'wstETH' ? /0xc2139725/ : /.^/,
symbol === 'WMATIC' ? /Transaction reverted without a reason string/ : /.^/,
symbol === 'WPOL' ? /Transaction reverted without a reason string/ : /.^/,
Expand Down Expand Up @@ -582,7 +583,7 @@ scenario(

await collateralAsset.approve(albert, comet.address);
await albert.allow(betty, true);

await expectRevertMatches(
betty.supplyAssetFrom({
src: albert.address,
Expand All @@ -593,6 +594,7 @@ scenario(
[
/transfer amount exceeds balance/,
/Dai\/insufficient-balance/,
symbol === 'WRON' ? /Transaction reverted without a reason string/ : /.^/,
symbol === 'WETH' ? /Transaction reverted without a reason string/ : /.^/,
symbol === 'wstETH' ? /0x00b284f2/ : /.^/,
symbol === 'WMATIC' ? /Transaction reverted without a reason string/ : /.^/,
Expand Down
13 changes: 9 additions & 4 deletions scenario/WithdrawScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,14 @@ scenario(
scenario(
'Comet#withdraw collateral reverts if position is undercollateralized',
{
cometBalances: {
albert: { $base: -1000, $asset0: 1000 }, // in units of asset, not wei
},
cometBalances: async (ctx) => (
{
albert: {
$base: -getConfigForScenario(ctx).withdrawBase1,
$asset0: getConfigForScenario(ctx).withdrawAsset1
}, // in units of asset, not wei
}
)
},
async ({ comet, actors }, context) => {
const { albert } = actors;
Expand All @@ -318,7 +323,7 @@ scenario(
await expectRevertCustom(
albert.withdrawAsset({
asset: collateralAsset.address,
amount: 1000n * scale
amount: BigInt(getConfigForScenario(context).withdrawAsset1) * scale
}),
'NotCollateralized()'
);
Expand Down
Loading

0 comments on commit f011826

Please sign in to comment.