From 1025d24ab6df1f7949c30a8a0cf1b083909092f2 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 15 Jun 2023 11:08:34 -0700 Subject: [PATCH 01/48] initial gen --- .../arbitrum/usdc-native/configuration.json | 65 +++++++++++++++++ deployments/arbitrum/usdc-native/deploy.ts | 72 +++++++++++++++++++ .../1686852466_configurate_and_ens.ts | 14 ++++ deployments/arbitrum/usdc-native/relations.ts | 38 ++++++++++ 4 files changed, 189 insertions(+) create mode 100644 deployments/arbitrum/usdc-native/configuration.json create mode 100644 deployments/arbitrum/usdc-native/deploy.ts create mode 100644 deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts create mode 100644 deployments/arbitrum/usdc-native/relations.ts diff --git a/deployments/arbitrum/usdc-native/configuration.json b/deployments/arbitrum/usdc-native/configuration.json new file mode 100644 index 000000000..9a4f18b2c --- /dev/null +++ b/deployments/arbitrum/usdc-native/configuration.json @@ -0,0 +1,65 @@ +{ + "name": "Compound USDC(native)", + "symbol": "cUSDCv3-native", + "baseToken": "USDC", + "baseTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", + "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", + "borrowMin": "100e6", + "pauseGuardian": "0x78E6317DD6D43DdbDa00Dce32C2CbaFc99361a9d", + "storeFrontPriceFactor": 0.8, + "targetReserves": "5000000e6", + "rates": { + "supplyKink": 0.8, + "supplySlopeLow": 0.0325, + "supplySlopeHigh": 0.4, + "supplyBase": 0, + "borrowKink": 0.8, + "borrowSlopeLow": 0.035, + "borrowSlopeHigh": 0.25, + "borrowBase": 0.015 + }, + "tracking": { + "indexScale": "1e15", + "baseSupplySpeed": "0.000402083333333e15", + "baseBorrowSpeed": "0e15", + "baseMinForRewards": "10000e6" + }, + "assets": { + "ARB": { + "address": "0x912ce59144191c1204e64559fe8253a0e49e6548", + "priceFeed": "0xb2A824043730FE05F3DA2efaFa1CBbe83fa548D6", + "decimals": "18", + "borrowCF": 0.55, + "liquidateCF": 0.60, + "liquidationFactor": 0.93, + "supplyCap": "4000000e18" + }, + "GMX": { + "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", + "priceFeed": "0xDB98056FecFff59D032aB628337A4887110df3dB", + "decimals": "18", + "borrowCF": 0.40, + "liquidateCF": 0.45, + "liquidationFactor": 0.93, + "supplyCap": "50000e18" + }, + "WETH": { + "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", + "priceFeed": "0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612", + "decimals": "18", + "borrowCF": 0.78, + "liquidateCF": 0.85, + "liquidationFactor": 0.95, + "supplyCap": "5000e18" + }, + "WBTC": { + "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", + "priceFeed": "0xd0C7101eACbB49F3deCcCc166d238410D6D46d57", + "decimals": "8", + "borrowCF": 0.70, + "liquidateCF": 0.77, + "liquidationFactor": 0.95, + "supplyCap": "300e8" + } + } +} diff --git a/deployments/arbitrum/usdc-native/deploy.ts b/deployments/arbitrum/usdc-native/deploy.ts new file mode 100644 index 000000000..f0e8c02c8 --- /dev/null +++ b/deployments/arbitrum/usdc-native/deploy.ts @@ -0,0 +1,72 @@ +import { Deployed, DeploymentManager } from '../../../plugins/deployment_manager'; +import { DeploySpec, deployComet } from '../../../src/deploy'; + +const HOUR = 60 * 60; +const DAY = 24 * HOUR; + +const MAINNET_TIMELOCK = '0x6d903f6003cca6255d85cca4d3b5e5146dc33925'; + +export default async function deploy(deploymentManager: DeploymentManager, deploySpec: DeploySpec): Promise { + const trace = deploymentManager.tracer() + const ethers = deploymentManager.hre.ethers; + + // pull in existing assets + const USDC = await deploymentManager.existing('USDC', '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', 'arbitrum'); + const ARB = await deploymentManager.existing('ARB', '0x912ce59144191c1204e64559fe8253a0e49e6548', 'arbitrum'); + const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); + const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); + const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); + + // Deploy ArbitrumBridgeReceiver + const bridgeReceiver = await deploymentManager.deploy( + 'bridgeReceiver', + 'bridges/arbitrum/ArbitrumBridgeReceiver.sol', + [] + ); + + // Deploy Local Timelock + const localTimelock = await deploymentManager.deploy( + 'timelock', + 'vendor/Timelock.sol', + [ + bridgeReceiver.address, // admin + 1 * DAY, // delay + 14 * DAY, // grace period + 12 * HOUR, // minimum delay + 30 * DAY // maxiumum delay + ] + ); + + // Initialize ArbitrumBridgeReceiver + await deploymentManager.idempotent( + async () => !(await bridgeReceiver.initialized()), + async () => { + trace(`Initializing BridgeReceiver`); + await bridgeReceiver.initialize( + MAINNET_TIMELOCK, // govTimelock + localTimelock.address // localTimelock + ); + trace(`BridgeReceiver initialized`); + } + ); + + // Deploy Comet + const deployed = await deployComet(deploymentManager, deploySpec); + const { comet } = deployed; + + // Deploy Bulker + const bulker = await deploymentManager.deploy( + 'bulker', + 'bulkers/BaseBulker.sol', + [ + await comet.governor(), // admin + WETH.address // weth + ] + ); + + return { + ...deployed, + bridgeReceiver, + bulker + }; +} diff --git a/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts b/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts new file mode 100644 index 000000000..e958de593 --- /dev/null +++ b/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts @@ -0,0 +1,14 @@ +import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; +import { migration } from '../../../../plugins/deployment_manager/Migration'; + +interface Vars {}; + +export default migration('1686852466_configurate_and_ens', { + prepare: async (deploymentManager: DeploymentManager) => { + return {}; + }, + + enact: async (deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, vars: Vars) => { + // No governance changes + } +}); diff --git a/deployments/arbitrum/usdc-native/relations.ts b/deployments/arbitrum/usdc-native/relations.ts new file mode 100644 index 000000000..28efc7b6e --- /dev/null +++ b/deployments/arbitrum/usdc-native/relations.ts @@ -0,0 +1,38 @@ +import baseRelationConfig from '../../relations'; + +export default { + ...baseRelationConfig, + governor: { + artifact: 'contracts/bridges/arbitrum/ArbitrumBridgeReceiver.sol:ArbitrumBridgeReceiver' + }, + ClonableBeaconProxy: { + artifact: 'contracts/ERC20.sol:ERC20' + }, + // USDC native + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, + // ARB + '0x912ce59144191c1204e64559fe8253a0e49e6548': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, + // WETH + '0x82af49447d8a07e3bd95bd0d56f35241523fbab1': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + } +}; From 0b4b0bf8ebc0e0729749ec0cf2680d1c6a91538c Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 15 Jun 2023 11:46:34 -0700 Subject: [PATCH 02/48] remove files --- deployments/arbitrum/usdc-native/deploy.ts | 2 +- .../1686852466_configurate_and_ens.ts | 14 ------- deployments/arbitrum/usdc-native/relations.ts | 38 ------------------- 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts delete mode 100644 deployments/arbitrum/usdc-native/relations.ts diff --git a/deployments/arbitrum/usdc-native/deploy.ts b/deployments/arbitrum/usdc-native/deploy.ts index f0e8c02c8..f32c122dc 100644 --- a/deployments/arbitrum/usdc-native/deploy.ts +++ b/deployments/arbitrum/usdc-native/deploy.ts @@ -11,7 +11,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const ethers = deploymentManager.hre.ethers; // pull in existing assets - const USDC = await deploymentManager.existing('USDC', '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', 'arbitrum'); + const USDC = await deploymentManager.existing('USDC', '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 'arbitrum'); const ARB = await deploymentManager.existing('ARB', '0x912ce59144191c1204e64559fe8253a0e49e6548', 'arbitrum'); const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); diff --git a/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts b/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts deleted file mode 100644 index e958de593..000000000 --- a/deployments/arbitrum/usdc-native/migrations/1686852466_configurate_and_ens.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; -import { migration } from '../../../../plugins/deployment_manager/Migration'; - -interface Vars {}; - -export default migration('1686852466_configurate_and_ens', { - prepare: async (deploymentManager: DeploymentManager) => { - return {}; - }, - - enact: async (deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, vars: Vars) => { - // No governance changes - } -}); diff --git a/deployments/arbitrum/usdc-native/relations.ts b/deployments/arbitrum/usdc-native/relations.ts deleted file mode 100644 index 28efc7b6e..000000000 --- a/deployments/arbitrum/usdc-native/relations.ts +++ /dev/null @@ -1,38 +0,0 @@ -import baseRelationConfig from '../../relations'; - -export default { - ...baseRelationConfig, - governor: { - artifact: 'contracts/bridges/arbitrum/ArbitrumBridgeReceiver.sol:ArbitrumBridgeReceiver' - }, - ClonableBeaconProxy: { - artifact: 'contracts/ERC20.sol:ERC20' - }, - // USDC native - '0xaf88d065e77c8cC2239327C5EDb3A432268e5831': { - artifact: 'contracts/ERC20.sol:ERC20', - delegates: { - field: { - slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' - } - } - }, - // ARB - '0x912ce59144191c1204e64559fe8253a0e49e6548': { - artifact: 'contracts/ERC20.sol:ERC20', - delegates: { - field: { - slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' - } - } - }, - // WETH - '0x82af49447d8a07e3bd95bd0d56f35241523fbab1': { - artifact: 'contracts/ERC20.sol:ERC20', - delegates: { - field: { - slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' - } - } - } -}; From 6c8d767dec076b09b6371e15be938cd0bc84eef8 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 15 Jun 2023 15:48:01 -0700 Subject: [PATCH 03/48] rename directory --- deployments/arbitrum/{usdc-native => usdc-n}/configuration.json | 0 deployments/arbitrum/{usdc-native => usdc-n}/deploy.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename deployments/arbitrum/{usdc-native => usdc-n}/configuration.json (100%) rename deployments/arbitrum/{usdc-native => usdc-n}/deploy.ts (100%) diff --git a/deployments/arbitrum/usdc-native/configuration.json b/deployments/arbitrum/usdc-n/configuration.json similarity index 100% rename from deployments/arbitrum/usdc-native/configuration.json rename to deployments/arbitrum/usdc-n/configuration.json diff --git a/deployments/arbitrum/usdc-native/deploy.ts b/deployments/arbitrum/usdc-n/deploy.ts similarity index 100% rename from deployments/arbitrum/usdc-native/deploy.ts rename to deployments/arbitrum/usdc-n/deploy.ts From 3890dc184114f2d9bbb353c97a5b924f65b3165e Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 10:48:44 -0700 Subject: [PATCH 04/48] add scenario --- deployments/arbitrum/usdc-n/configuration.json | 2 +- deployments/arbitrum/usdc-n/deploy.ts | 2 +- hardhat.config.ts | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/deployments/arbitrum/usdc-n/configuration.json b/deployments/arbitrum/usdc-n/configuration.json index 9a4f18b2c..81980cd3e 100644 --- a/deployments/arbitrum/usdc-n/configuration.json +++ b/deployments/arbitrum/usdc-n/configuration.json @@ -1,6 +1,6 @@ { "name": "Compound USDC(native)", - "symbol": "cUSDCv3-native", + "symbol": "cUSDCNv3", "baseToken": "USDC", "baseTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", diff --git a/deployments/arbitrum/usdc-n/deploy.ts b/deployments/arbitrum/usdc-n/deploy.ts index f32c122dc..f0e8c02c8 100644 --- a/deployments/arbitrum/usdc-n/deploy.ts +++ b/deployments/arbitrum/usdc-n/deploy.ts @@ -11,7 +11,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const ethers = deploymentManager.hre.ethers; // pull in existing assets - const USDC = await deploymentManager.existing('USDC', '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 'arbitrum'); + const USDC = await deploymentManager.existing('USDC', '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', 'arbitrum'); const ARB = await deploymentManager.existing('ARB', '0x912ce59144191c1204e64559fe8253a0e49e6548', 'arbitrum'); const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); diff --git a/hardhat.config.ts b/hardhat.config.ts index e7b9c6bc4..c84ab06d2 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -347,6 +347,12 @@ const config: HardhatUserConfig = { deployment: 'usdc', auxiliaryBase: 'mainnet' }, + { + name: 'arbitrum-usdc-native', + network: 'arbitrum', + deployment: 'usdc-n', + auxiliaryBase: 'mainnet' + }, { name: 'arbitrum-goerli', network: 'arbitrum-goerli', From 280b091037472fa44cf7c00ea78b51e8ac31af27 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 10:53:59 -0700 Subject: [PATCH 05/48] upadte deploy script --- deployments/arbitrum/usdc-n/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc-n/deploy.ts b/deployments/arbitrum/usdc-n/deploy.ts index f0e8c02c8..f32c122dc 100644 --- a/deployments/arbitrum/usdc-n/deploy.ts +++ b/deployments/arbitrum/usdc-n/deploy.ts @@ -11,7 +11,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const ethers = deploymentManager.hre.ethers; // pull in existing assets - const USDC = await deploymentManager.existing('USDC', '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', 'arbitrum'); + const USDC = await deploymentManager.existing('USDC', '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 'arbitrum'); const ARB = await deploymentManager.existing('ARB', '0x912ce59144191c1204e64559fe8253a0e49e6548', 'arbitrum'); const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); From 55ef5c1194f8a3ad088c773deee8e9ca410dc081 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 11:02:54 -0700 Subject: [PATCH 06/48] renamde to usdc.n --- deployments/arbitrum/{usdc-n => usdc.n}/configuration.json | 0 deployments/arbitrum/{usdc-n => usdc.n}/deploy.ts | 0 hardhat.config.ts | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename deployments/arbitrum/{usdc-n => usdc.n}/configuration.json (100%) rename deployments/arbitrum/{usdc-n => usdc.n}/deploy.ts (100%) diff --git a/deployments/arbitrum/usdc-n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json similarity index 100% rename from deployments/arbitrum/usdc-n/configuration.json rename to deployments/arbitrum/usdc.n/configuration.json diff --git a/deployments/arbitrum/usdc-n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts similarity index 100% rename from deployments/arbitrum/usdc-n/deploy.ts rename to deployments/arbitrum/usdc.n/deploy.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index c84ab06d2..535cb6062 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -350,7 +350,7 @@ const config: HardhatUserConfig = { { name: 'arbitrum-usdc-native', network: 'arbitrum', - deployment: 'usdc-n', + deployment: 'usdc.n', auxiliaryBase: 'mainnet' }, { From fdd3e274c742b8383d601bebb207897ca9ce264c Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 11:58:11 -0700 Subject: [PATCH 07/48] added relations for scenario test --- deployments/arbitrum/usdc.n/relations.ts | 38 ++++++++++++++++++++++++ hardhat.config.ts | 4 ++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 deployments/arbitrum/usdc.n/relations.ts diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc.n/relations.ts new file mode 100644 index 000000000..28efc7b6e --- /dev/null +++ b/deployments/arbitrum/usdc.n/relations.ts @@ -0,0 +1,38 @@ +import baseRelationConfig from '../../relations'; + +export default { + ...baseRelationConfig, + governor: { + artifact: 'contracts/bridges/arbitrum/ArbitrumBridgeReceiver.sol:ArbitrumBridgeReceiver' + }, + ClonableBeaconProxy: { + artifact: 'contracts/ERC20.sol:ERC20' + }, + // USDC native + '0xaf88d065e77c8cC2239327C5EDb3A432268e5831': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, + // ARB + '0x912ce59144191c1204e64559fe8253a0e49e6548': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, + // WETH + '0x82af49447d8a07e3bd95bd0d56f35241523fbab1': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + } +}; diff --git a/hardhat.config.ts b/hardhat.config.ts index 535cb6062..42660d616 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -25,6 +25,7 @@ import mainnetRelationConfigMap from './deployments/mainnet/usdc/relations'; import mainnetWethRelationConfigMap from './deployments/mainnet/weth/relations'; import polygonRelationConfigMap from './deployments/polygon/usdc/relations'; import arbitrumRelationConfigMap from './deployments/arbitrum/usdc/relations'; +import arbitrumNativeRelationConfigMap from './deployments/arbitrum/usdc.n/relations'; import arbitrumGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations'; import baseGoerliRelationConfigMap from './deployments/base-goerli/usdc/relations'; import baseGoerliWethRelationConfigMap from './deployments/base-goerli/weth/relations'; @@ -281,7 +282,8 @@ const config: HardhatUserConfig = { usdc: polygonRelationConfigMap }, arbitrum: { - usdc: arbitrumRelationConfigMap + usdc: arbitrumRelationConfigMap, + 'usdc.n': arbitrumNativeRelationConfigMap }, 'arbitrum-goerli': { usdc: arbitrumGoerliRelationConfigMap From 9bb5ec5135a0ee4271c7cec9318354466d7578a6 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 12:47:26 -0700 Subject: [PATCH 08/48] add scenario test to CI --- .github/workflows/run-scenarios.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-scenarios.yaml b/.github/workflows/run-scenarios.yaml index 4e954f580..722146a3b 100644 --- a/.github/workflows/run-scenarios.yaml +++ b/.github/workflows/run-scenarios.yaml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - bases: [ development, mainnet, mainnet-weth, goerli, goerli-weth, fuji, mumbai, polygon, arbitrum, arbitrum-goerli, base-goerli, base-goerli-weth, linea-goerli ] + bases: [ development, mainnet, mainnet-weth, goerli, goerli-weth, fuji, mumbai, polygon, arbitrum-usdc.e, arbitrum-usdc, arbitrum-goerli, base-goerli, base-goerli-weth, linea-goerli] name: Run scenarios env: ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }} From 944f551d841679b16a59b06d45005e4978d0a91c Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 15:32:29 -0700 Subject: [PATCH 09/48] add migration scrtips, but just changed the USDC reference address --- .../1686953660_configurate_and_ens.ts | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts new file mode 100644 index 000000000..25a7e3086 --- /dev/null +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -0,0 +1,312 @@ +import { Contract } from 'ethers'; +import { expect } from 'chai'; +import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; +import { diffState, getCometConfig } from '../../../../plugins/deployment_manager/DiffState'; +import { migration } from '../../../../plugins/deployment_manager/Migration'; +import { calldata, exp, getConfigurationStruct, proposal } from '../../../../src/deploy'; +import { applyL1ToL2Alias, estimateL2Transaction, estimateTokenBridge } from '../../../../scenario/utils/arbitrumUtils'; + +const ENSName = 'compound-community-licenses.eth'; +const ENSResolverAddress = '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'; +const ENSSubdomainLabel = 'v3-additional-grants'; +const ENSSubdomain = `${ENSSubdomainLabel}.${ENSName}`; +const ENSTextRecordKey = 'v3-official-markets'; + +const arbitrumCOMPAddress = '0x354A6dA3fcde098F8389cad84b0182725c6C91dE'; + +const cUSDTAddress = '0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9'; + +export default migration('1686953660_configurate_and_ens', { + prepare: async (_deploymentManager: DeploymentManager) => { + return {}; + }, + + enact: async (deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager) => { + const trace = deploymentManager.tracer(); + const ethers = deploymentManager.hre.ethers; + const { utils } = ethers; + + const { + bridgeReceiver, + timelock: l2Timelock, + comet, + cometAdmin, + configurator, + rewards, + } = await deploymentManager.getContracts(); + + const { + arbitrumInbox, + arbitrumL1GatewayRouter, + timelock, + comptrollerV2, + governor, + USDC, + COMP, + } = await govDeploymentManager.getContracts(); + + const USDCAmountToBridge = exp(10_000, 6); + const COMPAmountToBridge = exp(12_500, 18); + const usdcGatewayAddress = await arbitrumL1GatewayRouter.getGateway(USDC.address); + const compGatewayAddress = await arbitrumL1GatewayRouter.getGateway(COMP.address); + const refundAddress = l2Timelock.address; + + const compGasParams = await estimateTokenBridge( + { + token: COMP.address, + from: timelock.address, + to: rewards.address, + amount: COMPAmountToBridge + }, + govDeploymentManager, + deploymentManager + ); + + const usdcGasParams = await estimateTokenBridge( + { + token: USDC.address, + from: timelock.address, + to: comet.address, + amount: USDCAmountToBridge + }, + govDeploymentManager, + deploymentManager + ); + + const configuration = await getConfigurationStruct(deploymentManager); + + const setConfigurationCalldata = await calldata( + configurator.populateTransaction.setConfiguration(comet.address, configuration) + ); + const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [configurator.address, comet.address] + ); + const setRewardConfigCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [comet.address, arbitrumCOMPAddress] + ); + const l2ProposalData = utils.defaultAbiCoder.encode( + ['address[]', 'uint256[]', 'string[]', 'bytes[]'], + [ + [configurator.address, cometAdmin.address, rewards.address], + [0, 0, 0], + [ + 'setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))', + 'deployAndUpgradeTo(address,address)', + 'setRewardConfig(address,address)' + ], + [setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata] + ] + ); + + const createRetryableTicketGasParams = await estimateL2Transaction( + { + from: applyL1ToL2Alias(timelock.address), + to: bridgeReceiver.address, + data: l2ProposalData + }, + deploymentManager + ); + + const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); + const subdomainHash = ethers.utils.namehash(ENSSubdomain); + const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); + const officialMarkets = JSON.parse(officialMarketsJSON); + const updatedMarkets = { + ...officialMarkets, + 42161: [ + { + baseSymbol: 'USDC', + cometAddress: comet.address, + } + ], + }; + + const mainnetActions = [ + // 1. Set Comet configuration and deployAndUpgradeTo new Comet on Arbitrum. + { + contract: arbitrumInbox, + signature: 'createRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)', + args: [ + bridgeReceiver.address, // address to, + 0, // uint256 l2CallValue, + createRetryableTicketGasParams.maxSubmissionCost, // uint256 maxSubmissionCost, + refundAddress, // address excessFeeRefundAddress, + refundAddress, // address callValueRefundAddress, + createRetryableTicketGasParams.gasLimit, // uint256 gasLimit, + createRetryableTicketGasParams.maxFeePerGas, // uint256 maxFeePerGas, + l2ProposalData, // bytes calldata data + ], + value: createRetryableTicketGasParams.deposit + }, + // 2. Approve the USDC gateway to take Timelock's USDC for bridging + { + contract: USDC, + signature: 'approve(address,uint256)', + args: [usdcGatewayAddress, USDCAmountToBridge] + }, + // 3. Bridge USDC from mainnet to Arbitrum Comet + { + contract: arbitrumL1GatewayRouter, + signature: 'outboundTransferCustomRefund(address,address,address,uint256,uint256,uint256,bytes)', + args: [ + USDC.address, // address _token, + refundAddress, // address _refundTo + comet.address, // address _to, + USDCAmountToBridge, // uint256 _amount, + usdcGasParams.gasLimit, // uint256 _maxGas, + usdcGasParams.maxFeePerGas, // uint256 _gasPriceBid, + utils.defaultAbiCoder.encode( + ['uint256', 'bytes'], + [usdcGasParams.maxSubmissionCost, '0x'] + ) // bytes calldata _data + ], + value: usdcGasParams.deposit + }, + // 4. Approve the COMP gateway to take Timelock's COMP for bridging + { + contract: COMP, + signature: 'approve(address,uint256)', + args: [compGatewayAddress, COMPAmountToBridge] + }, + // 5. Bridge COMP from mainnet to Arbitrum rewards + { + contract: arbitrumL1GatewayRouter, + signature: 'outboundTransferCustomRefund(address,address,address,uint256,uint256,uint256,bytes)', + args: [ + COMP.address, // address _token, + refundAddress, // address _refundTo, + rewards.address, // address _to, + COMPAmountToBridge, // uint256 _amount, + compGasParams.gasLimit, // uint256 _maxGas, + compGasParams.maxFeePerGas, // uint256 _gasPriceBid, + utils.defaultAbiCoder.encode( + ['uint256', 'bytes'], + [compGasParams.maxSubmissionCost, '0x'] + ) // bytes calldata _data + ], + value: compGasParams.deposit + }, + // 6. Update the list of official markets + { + target: ENSResolverAddress, + signature: 'setText(bytes32,string,string)', + calldata: ethers.utils.defaultAbiCoder.encode( + ['bytes32', 'string', 'string'], + [subdomainHash, ENSTextRecordKey, JSON.stringify(updatedMarkets)] + ) + }, + // 7. Displace v2 USDT COMP rewards + { + contract: comptrollerV2, + signature: '_setCompSpeeds(address[],uint256[],uint256[])', + args: [ + [cUSDTAddress], + [0], + [0], + ], + }, + ]; + + const description = "# Initialize cUSDCv3 on Arbitrum\n\nThis proposal takes the governance steps recommended and necessary to initialize a Compound III USDC market on Arbitrum; upon execution, cUSDCv3 will be ready for use. Simulations have confirmed the market's readiness, as much as possible, using the [Comet scenario suite](https://github.com/compound-finance/comet/tree/main/scenario). Although real tests have also been run over the Goerli/Arbitrum Goerli bridge, this proposal requires estimating gas costs in advance of executing the bridge proposal, and therefore includes risks not present in previous proposals.\n\nAlthough the proposal sets the entire configuration in the Configurator, the initial deployment already has most of these same parameters already set. The new parameters are limited to increasing the supply caps of the collateral assets from their initial values of 0. The risk parameters and supply caps are based off of [recommendations from Gauntlet](https://www.comp.xyz/t/deploy-compound-v3-on-arbitrum/4100/15).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/719) and [forum discussion](https://www.comp.xyz/t/deploy-compound-v3-on-arbitrum/4100).\n\n\n## Proposal Actions\n\nThe first proposal action sets the Comet configuration and deploys a new Comet implementation on Arbitrum. This sends the encoded `setConfiguration` and `deployAndUpgradeTo` calls across the bridge to the governance receiver on Arbitrum. It also calls `setRewardConfig` on the Arbitrum rewards contract, to establish Arbitrum's bridged version of COMP as the reward token for the deployment and set the initial supply speed to be ~34.74 COMP/day.\n\nThe second action approves Arbitrum's [L1 Arb-Custom Gateway](https://etherscan.io/address/0xcEe284F754E854890e311e3280b767F80797180d) to take Timelock's USDC, in order to seed the market reserves through the bridge.\n\nThe third action bridges USDC from mainnet to the Compound instance on Arbitrum, via Arbitrum's [L1GatewayRouter contract](https://etherscan.io/address/0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef).\n\nThe fourth action approves Arbitrum's [L1 ERC20 Gateway](https://etherscan.io/address/0xa3A7B6F88361F48403514059F1F16C8E78d60EeC) to take Timelock's COMP, in order to seed the rewards contract through the bridge.\n\nThe fifth action transfers COMP from mainnet to the rewards contract on Arbitrum, via Arbitrum's [L1GatewayRouter contract](https://etherscan.io/address/0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef).\n\nThe sixth action updates the ENS TXT record `v3-official-markets` on `v3-additional-grants.compound-community-licenses.eth`, updating the official markets JSON to include the new Arbitrum cUSDCv3 market.\n\nThe seventh action turns off COMP distributions on Compound v2 USDT borrows (~34.74 COMP/day) as they are being shifted to Arbitrum."; + const txn = await govDeploymentManager.retry(async () => + trace(await governor.propose(...(await proposal(mainnetActions, description)))) + ); + + const event = txn.events.find(event => event.event === 'ProposalCreated'); + const [proposalId] = event.args; + + trace(`Created proposal ${proposalId}.`); + }, + + async enacted(deploymentManager: DeploymentManager): Promise { + return true; + }, + + async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { + const ethers = deploymentManager.hre.ethers; + await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set + + const { + comet, + rewards + } = await deploymentManager.getContracts(); + + const { + comptrollerV2 + } = await govDeploymentManager.getContracts(); + + // 1. + const stateChanges = await diffState(comet, getCometConfig, preMigrationBlockNumber); + expect(stateChanges).to.deep.equal({ + ARB: { + supplyCap: exp(4_000_000, 18) + }, + GMX: { + supplyCap: exp(50_000, 18) + }, + WETH: { + supplyCap: exp(5_000, 18) + }, + WBTC: { + supplyCap: exp(300, 8) + }, + baseTrackingSupplySpeed: exp(34.74 / 86400, 15, 18) + }); + + const config = await rewards.rewardConfig(comet.address); + expect(config.token).to.be.equal(arbitrumCOMPAddress); + expect(config.rescaleFactor).to.be.equal(exp(1, 12)); + expect(config.shouldUpscale).to.be.equal(true); + + // 2. & 3. + expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); + + // 4. & 5. + const arbitrumCOMP = new Contract( + arbitrumCOMPAddress, + ['function balanceOf(address account) external view returns (uint256)'], + deploymentManager.hre.ethers.provider + ); + expect(await arbitrumCOMP.balanceOf(rewards.address)).to.be.equal(exp(12_500, 18)); + + // 6. + const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); + const subdomainHash = ethers.utils.namehash(ENSSubdomain); + const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); + const officialMarkets = JSON.parse(officialMarketsJSON); + expect(officialMarkets).to.deep.equal({ + 1: [ + { + baseSymbol: 'USDC', + cometAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + }, + { + baseSymbol: 'WETH', + cometAddress: '0xA17581A9E3356d9A858b789D68B4d866e593aE94', + }, + ], + + 137: [ + { + baseSymbol: 'USDC', + cometAddress: '0xF25212E676D1F7F89Cd72fFEe66158f541246445', + }, + ], + + 42161: [ + { + baseSymbol: 'USDC', + cometAddress: comet.address, + } + ], + }); + + // 7. + expect(await comptrollerV2.compBorrowSpeeds(cUSDTAddress)).to.be.equal(0); + expect(await comptrollerV2.compSupplySpeeds(cUSDTAddress)).to.be.equal(0); + expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); + expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); + } +}); From b666eda215b739d3ba97a1e6decdfba2f4504318 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 16 Jun 2023 16:18:03 -0700 Subject: [PATCH 10/48] update migration script --- .../1686953660_configurate_and_ens.ts | 61 ++++++------------- 1 file changed, 19 insertions(+), 42 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 25a7e3086..de4bad747 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -111,17 +111,14 @@ export default migration('1686953660_configurate_and_ens', { const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); const subdomainHash = ethers.utils.namehash(ENSSubdomain); - const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); - const officialMarkets = JSON.parse(officialMarketsJSON); - const updatedMarkets = { - ...officialMarkets, - 42161: [ - { - baseSymbol: 'USDC', - cometAddress: comet.address, - } - ], - }; + const arbitrumChainId = (await deploymentManager.hre.ethers.provider.getNetwork()).chainId.toString(); + const newMarketObject = { baseSymbol: 'USDC.n', cometAddress: comet.address }; + const officialMarketsJSON = JSON.parse(await ENSResolver.text(subdomainHash, ENSTextRecordKey)); + if (officialMarketsJSON[arbitrumChainId]) { + officialMarketsJSON[arbitrumChainId].push(newMarketObject); + } else { + officialMarketsJSON[arbitrumChainId] = [newMarketObject]; + } const mainnetActions = [ // 1. Set Comet configuration and deployAndUpgradeTo new Comet on Arbitrum. @@ -140,37 +137,13 @@ export default migration('1686953660_configurate_and_ens', { ], value: createRetryableTicketGasParams.deposit }, - // 2. Approve the USDC gateway to take Timelock's USDC for bridging - { - contract: USDC, - signature: 'approve(address,uint256)', - args: [usdcGatewayAddress, USDCAmountToBridge] - }, - // 3. Bridge USDC from mainnet to Arbitrum Comet - { - contract: arbitrumL1GatewayRouter, - signature: 'outboundTransferCustomRefund(address,address,address,uint256,uint256,uint256,bytes)', - args: [ - USDC.address, // address _token, - refundAddress, // address _refundTo - comet.address, // address _to, - USDCAmountToBridge, // uint256 _amount, - usdcGasParams.gasLimit, // uint256 _maxGas, - usdcGasParams.maxFeePerGas, // uint256 _gasPriceBid, - utils.defaultAbiCoder.encode( - ['uint256', 'bytes'], - [usdcGasParams.maxSubmissionCost, '0x'] - ) // bytes calldata _data - ], - value: usdcGasParams.deposit - }, - // 4. Approve the COMP gateway to take Timelock's COMP for bridging + // 2. Approve the COMP gateway to take Timelock's COMP for bridging { contract: COMP, signature: 'approve(address,uint256)', args: [compGatewayAddress, COMPAmountToBridge] }, - // 5. Bridge COMP from mainnet to Arbitrum rewards + // 3. Bridge COMP from mainnet to Arbitrum rewards { contract: arbitrumL1GatewayRouter, signature: 'outboundTransferCustomRefund(address,address,address,uint256,uint256,uint256,bytes)', @@ -188,16 +161,16 @@ export default migration('1686953660_configurate_and_ens', { ], value: compGasParams.deposit }, - // 6. Update the list of official markets + // 4. Update the list of official markets { target: ENSResolverAddress, signature: 'setText(bytes32,string,string)', calldata: ethers.utils.defaultAbiCoder.encode( ['bytes32', 'string', 'string'], - [subdomainHash, ENSTextRecordKey, JSON.stringify(updatedMarkets)] + [subdomainHash, ENSTextRecordKey, JSON.stringify(officialMarketsJSON)] ) }, - // 7. Displace v2 USDT COMP rewards + // 5. Displace v2 USDT COMP rewards { contract: comptrollerV2, signature: '_setCompSpeeds(address[],uint256[],uint256[])', @@ -209,7 +182,7 @@ export default migration('1686953660_configurate_and_ens', { }, ]; - const description = "# Initialize cUSDCv3 on Arbitrum\n\nThis proposal takes the governance steps recommended and necessary to initialize a Compound III USDC market on Arbitrum; upon execution, cUSDCv3 will be ready for use. Simulations have confirmed the market's readiness, as much as possible, using the [Comet scenario suite](https://github.com/compound-finance/comet/tree/main/scenario). Although real tests have also been run over the Goerli/Arbitrum Goerli bridge, this proposal requires estimating gas costs in advance of executing the bridge proposal, and therefore includes risks not present in previous proposals.\n\nAlthough the proposal sets the entire configuration in the Configurator, the initial deployment already has most of these same parameters already set. The new parameters are limited to increasing the supply caps of the collateral assets from their initial values of 0. The risk parameters and supply caps are based off of [recommendations from Gauntlet](https://www.comp.xyz/t/deploy-compound-v3-on-arbitrum/4100/15).\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/719) and [forum discussion](https://www.comp.xyz/t/deploy-compound-v3-on-arbitrum/4100).\n\n\n## Proposal Actions\n\nThe first proposal action sets the Comet configuration and deploys a new Comet implementation on Arbitrum. This sends the encoded `setConfiguration` and `deployAndUpgradeTo` calls across the bridge to the governance receiver on Arbitrum. It also calls `setRewardConfig` on the Arbitrum rewards contract, to establish Arbitrum's bridged version of COMP as the reward token for the deployment and set the initial supply speed to be ~34.74 COMP/day.\n\nThe second action approves Arbitrum's [L1 Arb-Custom Gateway](https://etherscan.io/address/0xcEe284F754E854890e311e3280b767F80797180d) to take Timelock's USDC, in order to seed the market reserves through the bridge.\n\nThe third action bridges USDC from mainnet to the Compound instance on Arbitrum, via Arbitrum's [L1GatewayRouter contract](https://etherscan.io/address/0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef).\n\nThe fourth action approves Arbitrum's [L1 ERC20 Gateway](https://etherscan.io/address/0xa3A7B6F88361F48403514059F1F16C8E78d60EeC) to take Timelock's COMP, in order to seed the rewards contract through the bridge.\n\nThe fifth action transfers COMP from mainnet to the rewards contract on Arbitrum, via Arbitrum's [L1GatewayRouter contract](https://etherscan.io/address/0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef).\n\nThe sixth action updates the ENS TXT record `v3-official-markets` on `v3-additional-grants.compound-community-licenses.eth`, updating the official markets JSON to include the new Arbitrum cUSDCv3 market.\n\nThe seventh action turns off COMP distributions on Compound v2 USDT borrows (~34.74 COMP/day) as they are being shifted to Arbitrum."; + const description = "# Configurate Arbitrum cUSDCNv3 market, set reward config, USDC native and COMP, and update ENS text record."; const txn = await govDeploymentManager.retry(async () => trace(await governor.propose(...(await proposal(mainnetActions, description)))) ); @@ -280,7 +253,7 @@ export default migration('1686953660_configurate_and_ens', { 1: [ { baseSymbol: 'USDC', - cometAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + cometAddress: '0xc3d688B66703497DAA19211EEdff47f25384cdc3', }, { baseSymbol: 'WETH', @@ -298,6 +271,10 @@ export default migration('1686953660_configurate_and_ens', { 42161: [ { baseSymbol: 'USDC', + cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', + }, + { + baseSymbol: 'USDC.n', cometAddress: comet.address, } ], From 1a158a56fb6ac9ffb1c25e4d3cc9bf8391955e6f Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Tue, 20 Jun 2023 10:18:06 -0700 Subject: [PATCH 11/48] since it's native, we shouldn't need usdc bridge things in migration --- .../migrations/1686953660_configurate_and_ens.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index de4bad747..f7becad66 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -45,9 +45,7 @@ export default migration('1686953660_configurate_and_ens', { COMP, } = await govDeploymentManager.getContracts(); - const USDCAmountToBridge = exp(10_000, 6); const COMPAmountToBridge = exp(12_500, 18); - const usdcGatewayAddress = await arbitrumL1GatewayRouter.getGateway(USDC.address); const compGatewayAddress = await arbitrumL1GatewayRouter.getGateway(COMP.address); const refundAddress = l2Timelock.address; @@ -62,17 +60,6 @@ export default migration('1686953660_configurate_and_ens', { deploymentManager ); - const usdcGasParams = await estimateTokenBridge( - { - token: USDC.address, - from: timelock.address, - to: comet.address, - amount: USDCAmountToBridge - }, - govDeploymentManager, - deploymentManager - ); - const configuration = await getConfigurationStruct(deploymentManager); const setConfigurationCalldata = await calldata( From c8058e6883425dba3344c9cb55e46e52178b45b9 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 12:45:25 -0700 Subject: [PATCH 12/48] try to fix the liquidator scenario errors --- deployments/arbitrum/usdc.n/deploy.ts | 3 +- .../1686953660_configurate_and_ens.ts | 42 ++++++++++--------- scenario/LiquidationBotScenario.ts | 38 +++++++++++++++-- .../liquidateUnderwaterBorrowers.ts | 11 +++-- src/deploy/index.ts | 3 +- 5 files changed, 69 insertions(+), 28 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index f32c122dc..45ef3cae9 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -11,6 +11,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const ethers = deploymentManager.hre.ethers; // pull in existing assets + // USDC native const USDC = await deploymentManager.existing('USDC', '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 'arbitrum'); const ARB = await deploymentManager.existing('ARB', '0x912ce59144191c1204e64559fe8253a0e49e6548', 'arbitrum'); const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); @@ -60,7 +61,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo 'bulkers/BaseBulker.sol', [ await comet.governor(), // admin - WETH.address // weth + USDC.address // usdc native ] ); diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index f7becad66..2416e8edd 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -180,9 +180,9 @@ export default migration('1686953660_configurate_and_ens', { trace(`Created proposal ${proposalId}.`); }, - async enacted(deploymentManager: DeploymentManager): Promise { - return true; - }, + // async enacted(deploymentManager: DeploymentManager): Promise { + // return true; + // }, async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { const ethers = deploymentManager.hre.ethers; @@ -198,22 +198,24 @@ export default migration('1686953660_configurate_and_ens', { } = await govDeploymentManager.getContracts(); // 1. - const stateChanges = await diffState(comet, getCometConfig, preMigrationBlockNumber); - expect(stateChanges).to.deep.equal({ - ARB: { - supplyCap: exp(4_000_000, 18) - }, - GMX: { - supplyCap: exp(50_000, 18) - }, - WETH: { - supplyCap: exp(5_000, 18) - }, - WBTC: { - supplyCap: exp(300, 8) - }, - baseTrackingSupplySpeed: exp(34.74 / 86400, 15, 18) - }); + // TODO: Once contract is deploy and migrate to the right cap amount, will uncomment this to verify + + // const stateChanges = await diffState(comet, getCometConfig, preMigrationBlockNumber); + // expect(stateChanges).to.deep.equal({ + // ARB: { + // supplyCap: exp(4_000_000, 18) + // }, + // GMX: { + // supplyCap: exp(50_000, 18) + // }, + // WETH: { + // supplyCap: exp(5_000, 18) + // }, + // WBTC: { + // supplyCap: exp(300, 8) + // }, + // baseTrackingSupplySpeed: exp(34.74 / 86400, 15, 18) + // }); const config = await rewards.rewardConfig(comet.address); expect(config.token).to.be.equal(arbitrumCOMPAddress); @@ -221,7 +223,7 @@ export default migration('1686953660_configurate_and_ens', { expect(config.shouldUpscale).to.be.equal(true); // 2. & 3. - expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); + // expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); // 4. & 5. const arbitrumCOMP = new Contract( diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 679001409..4547dd824 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -78,7 +78,8 @@ for (let i = 0; i < MAX_ASSETS; i++) { usdc: 2250000 }, arbitrum: { - usdc: 10000000 + usdc: 10000000, + 'usdc.n': 10000000 } }; const assetAmounts = { @@ -122,6 +123,16 @@ for (let i = 0; i < MAX_ASSETS; i++) { ' == 500', // WBTC ' == 50' + ], + 'usdc.n': [ + // ARB + ' == 500000', + // GMX + ' == 4000', + // WETH + ' == 500', + // WBTC + ' == 50' ] } }; @@ -249,7 +260,8 @@ for (let i = 0; i < MAX_ASSETS; i++) { usdc: 3000000 }, arbitrum: { - usdc: 10000000 + usdc: 10000000, + 'usdc.n': 10000000 } }; const assetAmounts = { @@ -293,6 +305,16 @@ for (let i = 0; i < MAX_ASSETS; i++) { ' == 5000', // WBTC ' == 300' + ], + 'usdc.n': [ + // ARB + ' == 1000000', + // GMX + ' == 10000', + // WETH + ' == 5000', + // WBTC + ' == 300' ] } }; @@ -337,6 +359,16 @@ for (let i = 0; i < MAX_ASSETS; i++) { exp(500, 18), // WBTC exp(50, 8), + ], + 'usdc.n': [ + // ARB + exp(300000, 18), + // GMX + exp(3000, 18), + // WETH + exp(500, 18), + // WBTC + exp(50, 8), ] } }; @@ -788,4 +820,4 @@ scenario( ); } -// XXX test that Liquidator liquidates up to the max amount for that asset \ No newline at end of file +// XXX test that Liquidator liquidates up to the max amount for that asset diff --git a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts index 5da732c4e..162d96779 100644 --- a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts +++ b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts @@ -73,7 +73,8 @@ const liquidationThresholds = { 'usdc': 10e6 }, arbitrum: { - 'usdc': 10e6 + 'usdc': 10e6, + 'usdc.n': 10e6 } }; @@ -104,7 +105,11 @@ export const flashLoanPools = { usdc: { tokenAddress: addresses.arbitrum.USDC, // USDC/USDC_E/.01% pool poolFee: 100 - } + }, + 'usdc.n': { + tokenAddress: addresses.arbitrum.USDT, + poolFee: 100 + }, } }; @@ -490,4 +495,4 @@ export async function getAssets(comet: CometInterface): Promise { })), ]; return assets; -} \ No newline at end of file +} diff --git a/src/deploy/index.ts b/src/deploy/index.ts index f63217f5b..8b8e61a4c 100644 --- a/src/deploy/index.ts +++ b/src/deploy/index.ts @@ -96,7 +96,8 @@ export const WHALES = { arbitrum: [ '0xf89d7b9c864f589bbf53a82105107622b35eaa40', // USDC whale '0x7b7b957c284c2c227c980d6e2f804311947b84d0', // WBTC whale - '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae' // COMP whale + '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae', // COMP whale + '0xe68ee8a12c611fd043fb05d65e1548dc1383f2b9' // native USDC whale ], 'arbitrum-goerli': [ '0x4984cbfa5b199e5920995883d345bbe14b005db7', // USDC whale From 7a697bb4be16cfe19e9935c561c9cad5833df108 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 12:45:49 -0700 Subject: [PATCH 13/48] intent --- src/deploy/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/deploy/index.ts b/src/deploy/index.ts index 8b8e61a4c..6d4eef8fb 100644 --- a/src/deploy/index.ts +++ b/src/deploy/index.ts @@ -96,8 +96,8 @@ export const WHALES = { arbitrum: [ '0xf89d7b9c864f589bbf53a82105107622b35eaa40', // USDC whale '0x7b7b957c284c2c227c980d6e2f804311947b84d0', // WBTC whale - '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae', // COMP whale - '0xe68ee8a12c611fd043fb05d65e1548dc1383f2b9' // native USDC whale + '0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae', // COMP whale + '0xe68ee8a12c611fd043fb05d65e1548dc1383f2b9' // native USDC whale ], 'arbitrum-goerli': [ '0x4984cbfa5b199e5920995883d345bbe14b005db7', // USDC whale From 48d4c0ecb5d36986f3fa37dd663b223d431ebddd Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 12:46:18 -0700 Subject: [PATCH 14/48] change those to be 0 initially --- deployments/arbitrum/usdc.n/configuration.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 81980cd3e..124f77d75 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "4000000e18" + "supplyCap": "0e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "50000e18" + "supplyCap": "0e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "5000e18" + "supplyCap": "0e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "300e8" + "supplyCap": "0e18" } } } From 922121d4a9461b1f80969d5733853cd62bcc2be9 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 13:29:50 -0700 Subject: [PATCH 15/48] FINALLY scneario passed :D --- deployments/arbitrum/usdc.n/deploy.ts | 12 ++---------- scenario/LiquidationBotScenario.ts | 16 ++++++++-------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 45ef3cae9..8b197a695 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -55,19 +55,11 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const deployed = await deployComet(deploymentManager, deploySpec); const { comet } = deployed; - // Deploy Bulker - const bulker = await deploymentManager.deploy( - 'bulker', - 'bulkers/BaseBulker.sol', - [ - await comet.governor(), // admin - USDC.address // usdc native - ] - ); + const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); return { ...deployed, - bridgeReceiver, + bridgeReceiver, bulker }; } diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 4547dd824..06419bec2 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -126,13 +126,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - ' == 500000', + ' == 5000', // GMX - ' == 4000', + ' == 400', // WETH - ' == 500', + ' == 100', // WBTC - ' == 50' + ' == 5' ] } }; @@ -362,13 +362,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - exp(300000, 18), + exp(10000, 18), // GMX - exp(3000, 18), + exp(300, 18), // WETH - exp(500, 18), + exp(50, 18), // WBTC - exp(50, 8), + exp(1, 8), ] } }; From 7e894ea0022e21800e44e6c91f319f0258a3b582 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 13:58:06 -0700 Subject: [PATCH 16/48] don't re-deploy bulker --- deployments/arbitrum/usdc.n/deploy.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 8b197a695..4268d6a3a 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -55,11 +55,8 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const deployed = await deployComet(deploymentManager, deploySpec); const { comet } = deployed; - const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); - return { ...deployed, bridgeReceiver, - bulker }; } From 4d681135163301dd2824f3a04b6dd44516df2eef Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 21 Jun 2023 18:43:33 -0700 Subject: [PATCH 17/48] set a number in configuration to make bulker tests pass --- .../arbitrum/usdc.n/configuration.json | 8 ++-- deployments/arbitrum/usdc.n/deploy.ts | 40 +++---------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 124f77d75..81980cd3e 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "4000000e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "50000e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "0e18" + "supplyCap": "5000e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "0e18" + "supplyCap": "300e8" } } } diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 4268d6a3a..302239dba 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -18,45 +18,17 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); - // Deploy ArbitrumBridgeReceiver - const bridgeReceiver = await deploymentManager.deploy( - 'bridgeReceiver', - 'bridges/arbitrum/ArbitrumBridgeReceiver.sol', - [] - ); - - // Deploy Local Timelock - const localTimelock = await deploymentManager.deploy( - 'timelock', - 'vendor/Timelock.sol', - [ - bridgeReceiver.address, // admin - 1 * DAY, // delay - 14 * DAY, // grace period - 12 * HOUR, // minimum delay - 30 * DAY // maxiumum delay - ] - ); - - // Initialize ArbitrumBridgeReceiver - await deploymentManager.idempotent( - async () => !(await bridgeReceiver.initialized()), - async () => { - trace(`Initializing BridgeReceiver`); - await bridgeReceiver.initialize( - MAINNET_TIMELOCK, // govTimelock - localTimelock.address // localTimelock - ); - trace(`BridgeReceiver initialized`); - } - ); + // Import shared contracts from original usdc deployment + const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); + const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); + const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc'); // Deploy Comet const deployed = await deployComet(deploymentManager, deploySpec); - const { comet } = deployed; - + return { ...deployed, bridgeReceiver, + bulker }; } From 24bb4fea6428173d0f58fff4150a0caaecb83f4b Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 22 Jun 2023 12:20:41 -0700 Subject: [PATCH 18/48] set configuration to 0 supply cap for initialization, although it will fail the bulker test --- deployments/arbitrum/usdc.n/configuration.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 81980cd3e..124f77d75 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "4000000e18" + "supplyCap": "0e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "50000e18" + "supplyCap": "0e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "5000e18" + "supplyCap": "0e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "300e8" + "supplyCap": "0e18" } } } From a0b5f90bd751b6d916f706e9f6769151ad1f3e65 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 11:08:39 -0700 Subject: [PATCH 19/48] update liquidity pool to use the one with better liquidity --- deployments/arbitrum/usdc.n/configuration.json | 8 ++++---- scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 124f77d75..81980cd3e 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "4000000e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "50000e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "0e18" + "supplyCap": "5000e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "0e18" + "supplyCap": "300e8" } } } diff --git a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts index 162d96779..f592c3bb4 100644 --- a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts +++ b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts @@ -107,7 +107,7 @@ export const flashLoanPools = { poolFee: 100 }, 'usdc.n': { - tokenAddress: addresses.arbitrum.USDT, + tokenAddress: addresses.arbitrum.USDC_E, poolFee: 100 }, } From a9d0d4aad1d5191025ca8b6a6dd629a730d5d35f Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 11:20:21 -0700 Subject: [PATCH 20/48] after new pool use better liquidity, now able to bump up the volume --- scenario/LiquidationBotScenario.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 06419bec2..4547dd824 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -126,13 +126,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - ' == 5000', + ' == 500000', // GMX - ' == 400', + ' == 4000', // WETH - ' == 100', + ' == 500', // WBTC - ' == 5' + ' == 50' ] } }; @@ -362,13 +362,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - exp(10000, 18), + exp(300000, 18), // GMX - exp(300, 18), + exp(3000, 18), // WETH - exp(50, 18), + exp(500, 18), // WBTC - exp(1, 8), + exp(50, 8), ] } }; From 1d31ac2f0597ffcdc6c88886f32c9466563aba8b Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 11:29:44 -0700 Subject: [PATCH 21/48] remove v2 rewards config step, crank down borrowMin --- deployments/arbitrum/usdc.n/configuration.json | 2 +- .../migrations/1686953660_configurate_and_ens.ts | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 81980cd3e..47b941c03 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -4,7 +4,7 @@ "baseToken": "USDC", "baseTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", - "borrowMin": "100e6", + "borrowMin": "10e6", "pauseGuardian": "0x78E6317DD6D43DdbDa00Dce32C2CbaFc99361a9d", "storeFrontPriceFactor": 0.8, "targetReserves": "5000000e6", diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 2416e8edd..c9799cf89 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -157,16 +157,6 @@ export default migration('1686953660_configurate_and_ens', { [subdomainHash, ENSTextRecordKey, JSON.stringify(officialMarketsJSON)] ) }, - // 5. Displace v2 USDT COMP rewards - { - contract: comptrollerV2, - signature: '_setCompSpeeds(address[],uint256[],uint256[])', - args: [ - [cUSDTAddress], - [0], - [0], - ], - }, ]; const description = "# Configurate Arbitrum cUSDCNv3 market, set reward config, USDC native and COMP, and update ENS text record."; From 81e837c2f677bceeecd829a2a4790081b1e0e2ff Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 12:38:35 -0700 Subject: [PATCH 22/48] update migration description --- .../usdc.n/migrations/1686953660_configurate_and_ens.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index c9799cf89..fa5b99fbb 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -159,7 +159,7 @@ export default migration('1686953660_configurate_and_ens', { }, ]; - const description = "# Configurate Arbitrum cUSDCNv3 market, set reward config, USDC native and COMP, and update ENS text record."; + const description = "# Configurate Arbitrum cUSDCv3 market for USDC native, and set ENS record for official markets"; const txn = await govDeploymentManager.retry(async () => trace(await governor.propose(...(await proposal(mainnetActions, description)))) ); @@ -170,10 +170,6 @@ export default migration('1686953660_configurate_and_ens', { trace(`Created proposal ${proposalId}.`); }, - // async enacted(deploymentManager: DeploymentManager): Promise { - // return true; - // }, - async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { const ethers = deploymentManager.hre.ethers; await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set From d5886ef437594b81e50c4dcb366d4a4a2ef6441b Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 13:03:12 -0700 Subject: [PATCH 23/48] remove trailing newline --- deployments/arbitrum/usdc.n/configuration.json | 2 +- deployments/arbitrum/usdc.n/deploy.ts | 2 +- .../usdc.n/migrations/1686953660_configurate_and_ens.ts | 2 +- deployments/arbitrum/usdc.n/relations.ts | 2 +- scenario/LiquidationBotScenario.ts | 2 +- scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts | 2 +- src/deploy/index.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index 47b941c03..dc35d5341 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -62,4 +62,4 @@ "supplyCap": "300e8" } } -} +} \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 302239dba..22fa60943 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -31,4 +31,4 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo bridgeReceiver, bulker }; -} +} \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index fa5b99fbb..3c96491d7 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -261,4 +261,4 @@ export default migration('1686953660_configurate_and_ens', { expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); } -}); +}); \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc.n/relations.ts index 28efc7b6e..f592f14ec 100644 --- a/deployments/arbitrum/usdc.n/relations.ts +++ b/deployments/arbitrum/usdc.n/relations.ts @@ -35,4 +35,4 @@ export default { } } } -}; +}; \ No newline at end of file diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 4547dd824..b655712f2 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -820,4 +820,4 @@ scenario( ); } -// XXX test that Liquidator liquidates up to the max amount for that asset +// XXX test that Liquidator liquidates up to the max amount for that asset \ No newline at end of file diff --git a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts index f592c3bb4..957a9a44e 100644 --- a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts +++ b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts @@ -495,4 +495,4 @@ export async function getAssets(comet: CometInterface): Promise { })), ]; return assets; -} +} \ No newline at end of file diff --git a/src/deploy/index.ts b/src/deploy/index.ts index 6d4eef8fb..ba9fece1e 100644 --- a/src/deploy/index.ts +++ b/src/deploy/index.ts @@ -139,4 +139,4 @@ export async function proposal(actions: ProposalAction[], description: string): } } return [targets, values, signatures, calldatas, description]; -} +} \ No newline at end of file From e4c1a3481190c35c908848fd09882f475bfe1dae Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 13:41:36 -0700 Subject: [PATCH 24/48] ok need to referencing existing rewards in deploy script to share the rewards' --- deployments/arbitrum/usdc.n/deploy.ts | 4 +- .../1686953660_configurate_and_ens.ts | 56 ++----------------- 2 files changed, 7 insertions(+), 53 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 22fa60943..a671c610b 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -22,6 +22,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc'); + const rewards = await deploymentManager.fromDep('rewards', 'arbitrum', 'usdc'); // Deploy Comet const deployed = await deployComet(deploymentManager, deploySpec); @@ -29,6 +30,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo return { ...deployed, bridgeReceiver, - bulker + bulker, + rewards }; } \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 3c96491d7..1c68489b0 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -45,21 +45,7 @@ export default migration('1686953660_configurate_and_ens', { COMP, } = await govDeploymentManager.getContracts(); - const COMPAmountToBridge = exp(12_500, 18); - const compGatewayAddress = await arbitrumL1GatewayRouter.getGateway(COMP.address); const refundAddress = l2Timelock.address; - - const compGasParams = await estimateTokenBridge( - { - token: COMP.address, - from: timelock.address, - to: rewards.address, - amount: COMPAmountToBridge - }, - govDeploymentManager, - deploymentManager - ); - const configuration = await getConfigurationStruct(deploymentManager); const setConfigurationCalldata = await calldata( @@ -124,31 +110,8 @@ export default migration('1686953660_configurate_and_ens', { ], value: createRetryableTicketGasParams.deposit }, - // 2. Approve the COMP gateway to take Timelock's COMP for bridging - { - contract: COMP, - signature: 'approve(address,uint256)', - args: [compGatewayAddress, COMPAmountToBridge] - }, - // 3. Bridge COMP from mainnet to Arbitrum rewards - { - contract: arbitrumL1GatewayRouter, - signature: 'outboundTransferCustomRefund(address,address,address,uint256,uint256,uint256,bytes)', - args: [ - COMP.address, // address _token, - refundAddress, // address _refundTo, - rewards.address, // address _to, - COMPAmountToBridge, // uint256 _amount, - compGasParams.gasLimit, // uint256 _maxGas, - compGasParams.maxFeePerGas, // uint256 _gasPriceBid, - utils.defaultAbiCoder.encode( - ['uint256', 'bytes'], - [compGasParams.maxSubmissionCost, '0x'] - ) // bytes calldata _data - ], - value: compGasParams.deposit - }, - // 4. Update the list of official markets + + // 2. Update the list of official markets { target: ENSResolverAddress, signature: 'setText(bytes32,string,string)', @@ -208,18 +171,7 @@ export default migration('1686953660_configurate_and_ens', { expect(config.rescaleFactor).to.be.equal(exp(1, 12)); expect(config.shouldUpscale).to.be.equal(true); - // 2. & 3. - // expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); - - // 4. & 5. - const arbitrumCOMP = new Contract( - arbitrumCOMPAddress, - ['function balanceOf(address account) external view returns (uint256)'], - deploymentManager.hre.ethers.provider - ); - expect(await arbitrumCOMP.balanceOf(rewards.address)).to.be.equal(exp(12_500, 18)); - - // 6. + // 2. const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); const subdomainHash = ethers.utils.namehash(ENSSubdomain); const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); @@ -255,7 +207,7 @@ export default migration('1686953660_configurate_and_ens', { ], }); - // 7. + // 3. expect(await comptrollerV2.compBorrowSpeeds(cUSDTAddress)).to.be.equal(0); expect(await comptrollerV2.compSupplySpeeds(cUSDTAddress)).to.be.equal(0); expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); From c1f606ef4b5cdf1ee1e8862d6709b74ee1cf7a02 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 23 Jun 2023 15:57:47 -0700 Subject: [PATCH 25/48] naming changes --- deployments/arbitrum/usdc.n/configuration.json | 6 +++--- .../migrations/1686953660_configurate_and_ens.ts | 11 ++++------- deployments/arbitrum/usdc.n/relations.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc.n/configuration.json index dc35d5341..03176e52e 100644 --- a/deployments/arbitrum/usdc.n/configuration.json +++ b/deployments/arbitrum/usdc.n/configuration.json @@ -1,10 +1,10 @@ { - "name": "Compound USDC(native)", - "symbol": "cUSDCNv3", + "name": "Compound USDC", + "symbol": "cUSDCv3", "baseToken": "USDC", "baseTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", - "borrowMin": "10e6", + "borrowMin": "1e6", "pauseGuardian": "0x78E6317DD6D43DdbDa00Dce32C2CbaFc99361a9d", "storeFrontPriceFactor": 0.8, "targetReserves": "5000000e6", diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 1c68489b0..c33ccbeeb 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -14,8 +14,6 @@ const ENSTextRecordKey = 'v3-official-markets'; const arbitrumCOMPAddress = '0x354A6dA3fcde098F8389cad84b0182725c6C91dE'; -const cUSDTAddress = '0xf650c3d88d12db855b8bf7d11be6c55a4e07dcc9'; - export default migration('1686953660_configurate_and_ens', { prepare: async (_deploymentManager: DeploymentManager) => { return {}; @@ -85,7 +83,7 @@ export default migration('1686953660_configurate_and_ens', { const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); const subdomainHash = ethers.utils.namehash(ENSSubdomain); const arbitrumChainId = (await deploymentManager.hre.ethers.provider.getNetwork()).chainId.toString(); - const newMarketObject = { baseSymbol: 'USDC.n', cometAddress: comet.address }; + const newMarketObject = { baseSymbol: 'USDC', cometAddress: comet.address }; const officialMarketsJSON = JSON.parse(await ENSResolver.text(subdomainHash, ENSTextRecordKey)); if (officialMarketsJSON[arbitrumChainId]) { officialMarketsJSON[arbitrumChainId].push(newMarketObject); @@ -122,7 +120,8 @@ export default migration('1686953660_configurate_and_ens', { }, ]; - const description = "# Configurate Arbitrum cUSDCv3 market for USDC native, and set ENS record for official markets"; + // TODO: Will update this description to be more accurate once the contract is deployed + const description = "# Configurate Arbitrum cUSDCv3 market for Native USDC native, and set ENS record for official markets"; const txn = await govDeploymentManager.retry(async () => trace(await governor.propose(...(await proposal(mainnetActions, description)))) ); @@ -201,15 +200,13 @@ export default migration('1686953660_configurate_and_ens', { cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', }, { - baseSymbol: 'USDC.n', + baseSymbol: 'USDC', cometAddress: comet.address, } ], }); // 3. - expect(await comptrollerV2.compBorrowSpeeds(cUSDTAddress)).to.be.equal(0); - expect(await comptrollerV2.compSupplySpeeds(cUSDTAddress)).to.be.equal(0); expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); } diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc.n/relations.ts index f592f14ec..9234fc84c 100644 --- a/deployments/arbitrum/usdc.n/relations.ts +++ b/deployments/arbitrum/usdc.n/relations.ts @@ -8,7 +8,7 @@ export default { ClonableBeaconProxy: { artifact: 'contracts/ERC20.sol:ERC20' }, - // USDC native + // Native USDC '0xaf88d065e77c8cC2239327C5EDb3A432268e5831': { artifact: 'contracts/ERC20.sol:ERC20', delegates: { From d6e272ef72f704d74ad168481e04d4354f14f029 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Tue, 27 Jun 2023 17:24:41 -0700 Subject: [PATCH 26/48] added cctp contracts address to roots and update relayArbitrummessage --- deployments/arbitrum/usdc/roots.json | 4 +- deployments/mainnet/usdc/roots.json | 3 +- scenario/utils/relayArbitrumMessage.ts | 72 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json index dce14a07b..5339d8ac7 100644 --- a/deployments/arbitrum/usdc/roots.json +++ b/deployments/arbitrum/usdc/roots.json @@ -3,5 +3,7 @@ "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", - "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" + "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d", + "arbitrumCCTPTokenMinter": "0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48", + "arbitrumCCTPMessageTransmitter": "0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca" } \ No newline at end of file diff --git a/deployments/mainnet/usdc/roots.json b/deployments/mainnet/usdc/roots.json index 87b6e5d00..b7a505acd 100644 --- a/deployments/mainnet/usdc/roots.json +++ b/deployments/mainnet/usdc/roots.json @@ -6,5 +6,6 @@ "bulker": "0xa397a8C2086C554B531c02E29f3291c9704B00c7", "fxRoot": "0xfe5e5D361b2ad62c541bAb87C45a0B9B018389a2", "arbitrumInbox": "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", - "arbitrumL1GatewayRouter": "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef" + "arbitrumL1GatewayRouter": "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef", + "mainnetCCTPTokenMessenger": "0xbd3fa81b58ba92a82136038b25adec7066af3155" } \ No newline at end of file diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index b9cb75f34..907fa821e 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -110,4 +110,76 @@ export default async function relayArbitrumMessage( await bridgeReceiver.executeProposal(id, { gasPrice: 0 }); } } + + // CCTP relay + // L1 contracts + const MainnetTokenMessenger = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPTokenMessenger'); + // Arbitrum TokenMinter + const TokenMinter = await governanceDeploymentManager.getContractOrThrow('arbitrumCCTPTokenMinter'); + + const depositForBurnEvents: Log[] = await governanceDeploymentManager.hre.ethers.provider.getLogs({ + fromBlock: startingBlockNumber, + toBlock: 'latest', + address: MainnetTokenMessenger.address, + topics: [utils.id('MessageSent(bytes)')] + }); + + // Decode message body + const burnEvents = depositForBurnEvents.map(({ data }) => { + const decodedData = utils.defaultAbiCoder.decode( + [ + 'uint32 _msgVersion', + 'uint32 _msgSourceDomain', + 'uint32 _msgDestinationDomain', + 'uint64 _msgNonce', + 'bytes32 _msgSender', + 'bytes32 _msgRecipient', + 'bytes32 _msgDestinationCaller', + 'bytes _msgRawBody' + ], + data + ); + + // Another decode to from _msgRawBody to get the amount + const decodedMsgRawBody = utils.defaultAbiCoder.decode( + [ + 'uint32 _version', + 'bytes32 _burnToken', + 'bytes32 _mintRecipient', + 'uint256 _amount', + 'bytes32 _messageSender' + ], + decodedData._msgRawBody + ); + const { _msgSender, _MsgRecipient, _msgSourceDomain } = decodedData; + const { _amount, _burnToken } = decodedMsgRawBody; + return { + sender: _msgSender, + recipient: _MsgRecipient, + amount: _amount, + sourceDomain: _msgSourceDomain, + burnToken: _burnToken + } + }); + + // Impersonate the Arbitrum TokenMinter and mint token to recipient + for (let burnEvent of burnEvents) { + const { sender, recipient, amount, sourceDomain, burnToken } = burnEvent; + const localTokenMessengerSigner = await impersonateAddress( + bridgeDeploymentManager, + '0x19330d10d9cc8751218eaf51e8885d058642e08a' + ); + const transactionRequest = await localTokenMessengerSigner.populateTransaction({ + to: TokenMinter.address, + from: '0x19330d10d9cc8751218eaf51e8885d058642e08a', + data: TokenMinter.interface.encodeFunctionData('mint', [sourceDomain, burnToken, recipient, amount]), + gasPrice: 0 + }); + + await setNextBaseFeeToZero(bridgeDeploymentManager); + + const tx = await ( + await localTokenMessengerSigner.sendTransaction(transactionRequest) + ).wait(); + } } From 74cc7bf9343585ffe6347798aace6fc944e61564 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Tue, 27 Jun 2023 17:41:41 -0700 Subject: [PATCH 27/48] add l2 cctp --- deployments/arbitrum/usdc.n/deploy.ts | 3 ++- scenario/utils/relayArbitrumMessage.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index a671c610b..83195119e 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -17,7 +17,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); - + const arbitrumCCTPTokenMinter = await deploymentManager.existing('arbitrumCCTPTokenMinter', '0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48', 'arbitrum'); // Import shared contracts from original usdc deployment const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); @@ -30,6 +30,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo return { ...deployed, bridgeReceiver, + arbitrumCCTPTokenMinter, bulker, rewards }; diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index 907fa821e..25b41905f 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -114,8 +114,8 @@ export default async function relayArbitrumMessage( // CCTP relay // L1 contracts const MainnetTokenMessenger = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPTokenMessenger'); - // Arbitrum TokenMinter - const TokenMinter = await governanceDeploymentManager.getContractOrThrow('arbitrumCCTPTokenMinter'); + // Arbitrum TokenMinter which is L2 contracts + const TokenMinter = await bridgeDeploymentManager.getContractOrThrow('arbitrumCCTPTokenMinter'); const depositForBurnEvents: Log[] = await governanceDeploymentManager.hre.ethers.provider.getLogs({ fromBlock: startingBlockNumber, From 82b0cb7a50211c83f8cef382111933a0d766abc6 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 28 Jun 2023 10:56:44 -0700 Subject: [PATCH 28/48] depositForBurn() to use CCTP to send native USDC to arbitrum comet --- .../1686953660_configurate_and_ens.ts | 25 ++++++++++++++++--- scenario/utils/relayArbitrumMessage.ts | 12 ++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index c33ccbeeb..849eb2ee6 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -41,11 +41,14 @@ export default migration('1686953660_configurate_and_ens', { governor, USDC, COMP, + mainnetCCTPTokenMessenger, } = await govDeploymentManager.getContracts(); const refundAddress = l2Timelock.address; const configuration = await getConfigurationStruct(deploymentManager); - + const USDCAmountToBridge = exp(10_000, 6); + // CCTP destination domain for Arbitrum + const ArbitrumDestinationDomain = 3; const setConfigurationCalldata = await calldata( configurator.populateTransaction.setConfiguration(comet.address, configuration) ); @@ -108,8 +111,19 @@ export default migration('1686953660_configurate_and_ens', { ], value: createRetryableTicketGasParams.deposit }, - - // 2. Update the list of official markets + // 2. Approve USDC to CCTP + { + contract: USDC, + signature: 'approve(address,uint256)', + args: [mainnetCCTPTokenMessenger.address, USDCAmountToBridge] + }, + // 3. Burn USDC to Arbitrum via CCTP + { + contract: mainnetCCTPTokenMessenger, + signature: 'depositForBurn(uint256,uint32,bytes32,address)', + args: [USDCAmountToBridge, ArbitrumDestinationDomain, utils.hexZeroPad(comet.address, 32), USDC.address], + }, + // 4. Update the list of official markets { target: ENSResolverAddress, signature: 'setText(bytes32,string,string)', @@ -170,7 +184,10 @@ export default migration('1686953660_configurate_and_ens', { expect(config.rescaleFactor).to.be.equal(exp(1, 12)); expect(config.shouldUpscale).to.be.equal(true); - // 2. + // 2 & 3. + expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); + + // 4. const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); const subdomainHash = ethers.utils.namehash(ENSSubdomain); const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index 25b41905f..488a0b3e1 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -124,6 +124,10 @@ export default async function relayArbitrumMessage( topics: [utils.id('MessageSent(bytes)')] }); + console.log('***************MainnetTokenMessenger***************'); + console.log(utils.id('MessageSent(bytes)')); + console.log(depositForBurnEvents); + // Decode message body const burnEvents = depositForBurnEvents.map(({ data }) => { const decodedData = utils.defaultAbiCoder.decode( @@ -152,10 +156,10 @@ export default async function relayArbitrumMessage( decodedData._msgRawBody ); const { _msgSender, _MsgRecipient, _msgSourceDomain } = decodedData; - const { _amount, _burnToken } = decodedMsgRawBody; + const { _amount, _burnToken, _mintRecipient } = decodedMsgRawBody; return { sender: _msgSender, - recipient: _MsgRecipient, + recipient: _mintRecipient, amount: _amount, sourceDomain: _msgSourceDomain, burnToken: _burnToken @@ -172,7 +176,7 @@ export default async function relayArbitrumMessage( const transactionRequest = await localTokenMessengerSigner.populateTransaction({ to: TokenMinter.address, from: '0x19330d10d9cc8751218eaf51e8885d058642e08a', - data: TokenMinter.interface.encodeFunctionData('mint', [sourceDomain, burnToken, recipient, amount]), + data: TokenMinter.interface.encodeFunctionData('mint', [sourceDomain, burnToken, utils.getAddress(recipient), amount]), gasPrice: 0 }); @@ -181,5 +185,7 @@ export default async function relayArbitrumMessage( const tx = await ( await localTokenMessengerSigner.sendTransaction(transactionRequest) ).wait(); + + console.log('tx: ', tx); } } From 748259f0a7ba66cae98e469fd29536f461c6035c Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 28 Jun 2023 17:04:22 -0700 Subject: [PATCH 29/48] finally relayArbitrum works with CCTP --- deployments/mainnet/usdc/roots.json | 3 +- scenario/utils/relayArbitrumMessage.ts | 107 ++++++++++++++++--------- 2 files changed, 70 insertions(+), 40 deletions(-) diff --git a/deployments/mainnet/usdc/roots.json b/deployments/mainnet/usdc/roots.json index b7a505acd..b17b129e0 100644 --- a/deployments/mainnet/usdc/roots.json +++ b/deployments/mainnet/usdc/roots.json @@ -7,5 +7,6 @@ "fxRoot": "0xfe5e5D361b2ad62c541bAb87C45a0B9B018389a2", "arbitrumInbox": "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", "arbitrumL1GatewayRouter": "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef", - "mainnetCCTPTokenMessenger": "0xbd3fa81b58ba92a82136038b25adec7066af3155" + "mainnetCCTPTokenMessenger": "0xbd3fa81b58ba92a82136038b25adec7066af3155", + "mainnetCCTPMessageTransmitter": "0x0a992d191deec32afe36203ad87d7d289a738f81" } \ No newline at end of file diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index 488a0b3e1..499a0253a 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -114,65 +114,96 @@ export default async function relayArbitrumMessage( // CCTP relay // L1 contracts const MainnetTokenMessenger = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPTokenMessenger'); + const MainnetMessageTransmitter = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPMessageTransmitter'); // Arbitrum TokenMinter which is L2 contracts const TokenMinter = await bridgeDeploymentManager.getContractOrThrow('arbitrumCCTPTokenMinter'); const depositForBurnEvents: Log[] = await governanceDeploymentManager.hre.ethers.provider.getLogs({ fromBlock: startingBlockNumber, toBlock: 'latest', - address: MainnetTokenMessenger.address, + address: MainnetMessageTransmitter.address, topics: [utils.id('MessageSent(bytes)')] }); - console.log('***************MainnetTokenMessenger***************'); - console.log(utils.id('MessageSent(bytes)')); - console.log(depositForBurnEvents); - // Decode message body const burnEvents = depositForBurnEvents.map(({ data }) => { - const decodedData = utils.defaultAbiCoder.decode( - [ - 'uint32 _msgVersion', - 'uint32 _msgSourceDomain', - 'uint32 _msgDestinationDomain', - 'uint64 _msgNonce', - 'bytes32 _msgSender', - 'bytes32 _msgRecipient', - 'bytes32 _msgDestinationCaller', - 'bytes _msgRawBody' - ], - data - ); + const dataBytes = utils.arrayify(data); + // Since data is encodePacked, so can't simply decode via AbiCoder.decode + const offset = 64; + const length = { + uint32: 4, + uint64: 8, + bytes32: 32, + uint256: 32, + }; + let start = offset; + let end = start + length.uint32; + // msgVersion, skip won't use + start = end; + end = start + length.uint32; + // msgSourceDomain + const msgSourceDomain = BigNumber.from(dataBytes.slice(start, end)).toNumber(); + + start = end; + end = start + length.uint32; + // msgDestinationDomain, skip won't use + + start = end; + end = start + length.uint64; + // msgNonce, skip won't use + + start = end; + end = start + length.bytes32; + // msgSender, skip won't use + + start = end; + end = start + length.bytes32; + // msgRecipient, skip won't use + + start = end; + end = start + length.bytes32; + // msgDestination, skip won't use + + start = end; + end = start + length.uint32; + // rawMsgBody version, skip won't use + + start = end; + end = start + length.bytes32; + // rawMsgBody burnToken + const burnToken = utils.hexlify(dataBytes.slice(start, end)); + + start = end; + end = start + length.bytes32; + // rawMsgBody mintRecipient + const mintRecipient = utils.getAddress(utils.hexlify(dataBytes.slice(start, end)).slice(-40)); + + start = end; + end = start + length.uint256; + + // rawMsgBody amount + const amount = BigNumber.from(dataBytes.slice(start, end)).toNumber(); + + start = end; + end = start + length.bytes32; + // rawMsgBody messageSender, skip won't use - // Another decode to from _msgRawBody to get the amount - const decodedMsgRawBody = utils.defaultAbiCoder.decode( - [ - 'uint32 _version', - 'bytes32 _burnToken', - 'bytes32 _mintRecipient', - 'uint256 _amount', - 'bytes32 _messageSender' - ], - decodedData._msgRawBody - ); - const { _msgSender, _MsgRecipient, _msgSourceDomain } = decodedData; - const { _amount, _burnToken, _mintRecipient } = decodedMsgRawBody; return { - sender: _msgSender, - recipient: _mintRecipient, - amount: _amount, - sourceDomain: _msgSourceDomain, - burnToken: _burnToken + recipient: mintRecipient, + amount: amount, + sourceDomain: msgSourceDomain, + burnToken: burnToken } }); // Impersonate the Arbitrum TokenMinter and mint token to recipient for (let burnEvent of burnEvents) { - const { sender, recipient, amount, sourceDomain, burnToken } = burnEvent; + const { recipient, amount, sourceDomain, burnToken } = burnEvent; const localTokenMessengerSigner = await impersonateAddress( bridgeDeploymentManager, '0x19330d10d9cc8751218eaf51e8885d058642e08a' ); + const transactionRequest = await localTokenMessengerSigner.populateTransaction({ to: TokenMinter.address, from: '0x19330d10d9cc8751218eaf51e8885d058642e08a', @@ -185,7 +216,5 @@ export default async function relayArbitrumMessage( const tx = await ( await localTokenMessengerSigner.sendTransaction(transactionRequest) ).wait(); - - console.log('tx: ', tx); } } From e008f585e65e56ad2740d4e8ad0c0ece907989a7 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 28 Jun 2023 17:19:16 -0700 Subject: [PATCH 30/48] format --- scenario/utils/relayArbitrumMessage.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index 499a0253a..3bf22981d 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -196,17 +196,20 @@ export default async function relayArbitrumMessage( } }); + // Impersonate the Arbitrum TokenMinter and mint token to recipient + const ImpersonateLocalTokenMessager = '0x19330d10d9cc8751218eaf51e8885d058642e08a'; + // Impersonate the Arbitrum TokenMinter and mint token to recipient for (let burnEvent of burnEvents) { const { recipient, amount, sourceDomain, burnToken } = burnEvent; const localTokenMessengerSigner = await impersonateAddress( bridgeDeploymentManager, - '0x19330d10d9cc8751218eaf51e8885d058642e08a' + ImpersonateLocalTokenMessager ); const transactionRequest = await localTokenMessengerSigner.populateTransaction({ to: TokenMinter.address, - from: '0x19330d10d9cc8751218eaf51e8885d058642e08a', + from: ImpersonateLocalTokenMessager, data: TokenMinter.interface.encodeFunctionData('mint', [sourceDomain, burnToken, utils.getAddress(recipient), amount]), gasPrice: 0 }); From 07da85b129a46f34e09fa1144ab30aba16b3b338 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Fri, 30 Jun 2023 13:39:21 -0700 Subject: [PATCH 31/48] update to turn off bridge market's reward speed --- deployments/arbitrum/usdc.n/deploy.ts | 15 +++-- .../1686953660_configurate_and_ens.ts | 44 +++++++++---- deployments/arbitrum/usdc.n/relations.ts | 62 ++++++++++++++++++- 3 files changed, 105 insertions(+), 16 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 83195119e..7a288af68 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -18,20 +18,27 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); const arbitrumCCTPTokenMinter = await deploymentManager.existing('arbitrumCCTPTokenMinter', '0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48', 'arbitrum'); - // Import shared contracts from original usdc deployment + + // Import shared contracts from cUSDCv3 + const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'arbitrum', 'usdc'); + const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); + const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'arbitrum', 'usdc'); + const configurator = await deploymentManager.fromDep('configurator', 'arbitrum', 'usdc'); + const rewards = await deploymentManager.fromDep('rewards', 'arbitrum', 'usdc'); const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc'); - const rewards = await deploymentManager.fromDep('rewards', 'arbitrum', 'usdc'); + const bridgedComet = await deploymentManager.fromDep('bridgedComet', 'arbitrum', 'usdc', 'comet'); // Deploy Comet const deployed = await deployComet(deploymentManager, deploySpec); - + return { ...deployed, bridgeReceiver, arbitrumCCTPTokenMinter, bulker, - rewards + rewards, + bridgedComet }; } \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 849eb2ee6..89f127692 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -24,6 +24,7 @@ export default migration('1686953660_configurate_and_ens', { const ethers = deploymentManager.hre.ethers; const { utils } = ethers; + const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); const { bridgeReceiver, timelock: l2Timelock, @@ -31,27 +32,29 @@ export default migration('1686953660_configurate_and_ens', { cometAdmin, configurator, rewards, + bridgedComet, } = await deploymentManager.getContracts(); const { arbitrumInbox, arbitrumL1GatewayRouter, timelock, - comptrollerV2, governor, USDC, - COMP, mainnetCCTPTokenMessenger, } = await govDeploymentManager.getContracts(); const refundAddress = l2Timelock.address; const configuration = await getConfigurationStruct(deploymentManager); - const USDCAmountToBridge = exp(10_000, 6); - // CCTP destination domain for Arbitrum - const ArbitrumDestinationDomain = 3; + const setFactoryCalldata = await calldata( + configurator.populateTransaction.setFactory(comet.address, cometFactory.address) + ); const setConfigurationCalldata = await calldata( configurator.populateTransaction.setConfiguration(comet.address, configuration) ); + const USDCAmountToBridge = exp(10_000, 6); + // CCTP destination domain for Arbitrum + const ArbitrumDestinationDomain = 3; const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode( ['address', 'address'], [configurator.address, comet.address] @@ -60,17 +63,31 @@ export default migration('1686953660_configurate_and_ens', { ['address', 'address'], [comet.address, arbitrumCOMPAddress] ); + + const turnOffBridgeCometSupplySpeedCalldata = utils.defaultAbiCoder.encode( + ['address', 'uint64'], + [bridgedComet.address, 0] + ); + + const turnOffBridgedCometBorrowSpeedCalldata = utils.defaultAbiCoder.encode( + ['address', 'uint64'], + [bridgedComet.address, 0] + ); + const l2ProposalData = utils.defaultAbiCoder.encode( ['address[]', 'uint256[]', 'string[]', 'bytes[]'], [ - [configurator.address, cometAdmin.address, rewards.address], - [0, 0, 0], + [configurator.address, configurator.address, cometAdmin.address, rewards.address, configurator.address, configurator.address], + [0, 0, 0, 0, 0, 0], [ + 'setFactory(address,address)', 'setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))', 'deployAndUpgradeTo(address,address)', - 'setRewardConfig(address,address)' + 'setRewardConfig(address,address)', + 'setBaseTrackingSupplySpeed(address,uint64)', + 'setBaseTrackingBorrowSpeed(address,uint64)', ], - [setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata] + [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffBridgeCometSupplySpeedCalldata, turnOffBridgedCometBorrowSpeedCalldata] ] ); @@ -131,7 +148,7 @@ export default migration('1686953660_configurate_and_ens', { ['bytes32', 'string', 'string'], [subdomainHash, ENSTextRecordKey, JSON.stringify(officialMarketsJSON)] ) - }, + } ]; // TODO: Will update this description to be more accurate once the contract is deployed @@ -152,7 +169,8 @@ export default migration('1686953660_configurate_and_ens', { const { comet, - rewards + rewards, + bridgedComet, } = await deploymentManager.getContracts(); const { @@ -226,5 +244,9 @@ export default migration('1686953660_configurate_and_ens', { // 3. expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); + + // 4. + expect(await bridgedComet.baseTrackingSupplySpeed()).to.be.equal(0); + expect(await bridgedComet.baseTrackingBorrowSpeed()).to.be.equal(0); } }); \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc.n/relations.ts index 9234fc84c..2a7febb6c 100644 --- a/deployments/arbitrum/usdc.n/relations.ts +++ b/deployments/arbitrum/usdc.n/relations.ts @@ -17,6 +17,15 @@ export default { } } }, + // Bridged USDC + '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8': { + artifact: 'contracts/ERC20.sol:ERC20', + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' + } + } + }, // ARB '0x912ce59144191c1204e64559fe8253a0e49e6548': { artifact: 'contracts/ERC20.sol:ERC20', @@ -34,5 +43,56 @@ export default { slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc' } } - } + }, + bridgedComet: { + delegates: { + field: { + slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc', + }, + }, + relations: { + baseToken: { + alias: async (nativetoken) => nativetoken.symbol()+'.e', + }, + baseTokenPriceFeed: { + field: async (bridgedComet) => bridgedComet.baseTokenPriceFeed(), + alias: async (_, { baseToken }) => `${await baseToken[0].symbol()+'.e'}:priceFeed`, + }, + assets: { + field: async (bridgedComet) => { + const n = await bridgedComet.numAssets(); + return Promise.all( + Array(n).fill(0).map(async (_, i) => { + const assetInfo = await bridgedComet.getAssetInfo(i); + return assetInfo.asset; + }) + ); + }, + alias: async (token) => token.symbol(), + }, + assetPriceFeeds: { + field: async (bridgedComet) => { + const n = await bridgedComet.numAssets(); + return Promise.all( + Array(n).fill(0).map(async (_, i) => { + const assetInfo = await bridgedComet.getAssetInfo(i); + return assetInfo.priceFeed; + }) + ); + }, + alias: async (_, { assets }, i) => `${await assets[i].symbol()}:priceFeed`, + }, + cometAdmin: { + field: { + slot: '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103', + }, + }, + }, + }, + 'bridgedComet:implementation': { + artifact: 'contracts/Comet.sol:Comet', + delegates: { + field: async (bridgedComet) => bridgedComet.extensionDelegate(), + }, + }, }; \ No newline at end of file From e739bf2ea06b63c0f861b9c41fb9df401548f977 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Mon, 3 Jul 2023 14:49:32 -0700 Subject: [PATCH 32/48] fix scenarios and slightly reduced volume in liquidator scenarios (somehow during testing the pool the bot uses to flashloan have been withdrew and don't have full liquidity to cover tests --- .../migrations/1686953660_configurate_and_ens.ts | 14 ++++++++++---- scenario/LiquidationBotScenario.ts | 16 ++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 89f127692..158b0d001 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -59,6 +59,7 @@ export default migration('1686953660_configurate_and_ens', { ['address', 'address'], [configurator.address, comet.address] ); + const setRewardConfigCalldata = utils.defaultAbiCoder.encode( ['address', 'address'], [comet.address, arbitrumCOMPAddress] @@ -74,11 +75,16 @@ export default migration('1686953660_configurate_and_ens', { [bridgedComet.address, 0] ); + const deployAndUpgradeToBridgedCometCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [configurator.address, bridgedComet.address] + ); + const l2ProposalData = utils.defaultAbiCoder.encode( ['address[]', 'uint256[]', 'string[]', 'bytes[]'], [ - [configurator.address, configurator.address, cometAdmin.address, rewards.address, configurator.address, configurator.address], - [0, 0, 0, 0, 0, 0], + [configurator.address, configurator.address, cometAdmin.address, rewards.address, configurator.address, configurator.address, cometAdmin.address], + [0, 0, 0, 0, 0, 0, 0], [ 'setFactory(address,address)', 'setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))', @@ -86,8 +92,9 @@ export default migration('1686953660_configurate_and_ens', { 'setRewardConfig(address,address)', 'setBaseTrackingSupplySpeed(address,uint64)', 'setBaseTrackingBorrowSpeed(address,uint64)', + 'deployAndUpgradeTo(address,address)', ], - [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffBridgeCometSupplySpeedCalldata, turnOffBridgedCometBorrowSpeedCalldata] + [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffBridgeCometSupplySpeedCalldata, turnOffBridgedCometBorrowSpeedCalldata, deployAndUpgradeToBridgedCometCalldata] ] ); @@ -244,7 +251,6 @@ export default migration('1686953660_configurate_and_ens', { // 3. expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); - // 4. expect(await bridgedComet.baseTrackingSupplySpeed()).to.be.equal(0); expect(await bridgedComet.baseTrackingBorrowSpeed()).to.be.equal(0); diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index b655712f2..0a2028898 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -126,13 +126,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - ' == 500000', + ' == 300000', // GMX - ' == 4000', + ' == 2000', // WETH - ' == 500', + ' == 300', // WBTC - ' == 50' + ' == 30' ] } }; @@ -362,13 +362,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - exp(300000, 18), + exp(200000, 18), // GMX - exp(3000, 18), + exp(2000, 18), // WETH - exp(500, 18), + exp(300, 18), // WBTC - exp(50, 8), + exp(30, 8), ] } }; From b77225cb90c730a1107b3678168f3816fca95835 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 5 Jul 2023 12:36:42 -0400 Subject: [PATCH 33/48] now it has just enough liquidity to pass the test, reverted the liquidation scenario back to usual amount --- scenario/LiquidationBotScenario.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index 0a2028898..a08837f9e 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -362,13 +362,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - exp(200000, 18), + exp(300000, 18), // GMX - exp(2000, 18), + exp(3000, 18), // WETH - exp(300, 18), + exp(500, 18), // WBTC - exp(30, 8), + exp(50, 8), ] } }; From 8c29661582ffe4c3fa294ef77381d96aced707b7 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 12:47:39 -0400 Subject: [PATCH 34/48] address comments: remove network prefixes, move contract import from deploy to migration scripts, move relay specific contracts to relay script --- deployments/arbitrum/usdc.n/deploy.ts | 4 -- .../1686953660_configurate_and_ens.ts | 17 +++---- deployments/arbitrum/usdc.n/relations.ts | 51 ------------------- scenario/utils/relayArbitrumMessage.ts | 31 +++++++---- scenario/utils/relayMessage.ts | 7 ++- 5 files changed, 35 insertions(+), 75 deletions(-) diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 7a288af68..0e29a52fe 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -17,7 +17,6 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const GMX = await deploymentManager.existing('GMX', '0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a', 'arbitrum'); const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); - const arbitrumCCTPTokenMinter = await deploymentManager.existing('arbitrumCCTPTokenMinter', '0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48', 'arbitrum'); // Import shared contracts from cUSDCv3 const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'arbitrum', 'usdc'); @@ -28,7 +27,6 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc'); - const bridgedComet = await deploymentManager.fromDep('bridgedComet', 'arbitrum', 'usdc', 'comet'); // Deploy Comet const deployed = await deployComet(deploymentManager, deploySpec); @@ -36,9 +34,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo return { ...deployed, bridgeReceiver, - arbitrumCCTPTokenMinter, bulker, rewards, - bridgedComet }; } \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index 158b0d001..f727d8be6 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -25,6 +25,7 @@ export default migration('1686953660_configurate_and_ens', { const { utils } = ethers; const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); + const bridgedComet = await deploymentManager.fromDep('comet.e', 'arbitrum', 'usdc', 'comet'); const { bridgeReceiver, timelock: l2Timelock, @@ -32,16 +33,15 @@ export default migration('1686953660_configurate_and_ens', { cometAdmin, configurator, rewards, - bridgedComet, } = await deploymentManager.getContracts(); - + const { arbitrumInbox, arbitrumL1GatewayRouter, timelock, governor, USDC, - mainnetCCTPTokenMessenger, + CCTPTokenMessenger, } = await govDeploymentManager.getContracts(); const refundAddress = l2Timelock.address; @@ -139,11 +139,11 @@ export default migration('1686953660_configurate_and_ens', { { contract: USDC, signature: 'approve(address,uint256)', - args: [mainnetCCTPTokenMessenger.address, USDCAmountToBridge] + args: [CCTPTokenMessenger.address, USDCAmountToBridge] }, // 3. Burn USDC to Arbitrum via CCTP { - contract: mainnetCCTPTokenMessenger, + contract: CCTPTokenMessenger, signature: 'depositForBurn(uint256,uint32,bytes32,address)', args: [USDCAmountToBridge, ArbitrumDestinationDomain, utils.hexZeroPad(comet.address, 32), USDC.address], }, @@ -173,11 +173,10 @@ export default migration('1686953660_configurate_and_ens', { async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { const ethers = deploymentManager.hre.ethers; await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set - + const bridgedComet = await deploymentManager.fromDep('bridgedComet', 'arbitrum', 'usdc', 'comet'); const { comet, rewards, - bridgedComet, } = await deploymentManager.getContracts(); const { @@ -248,10 +247,10 @@ export default migration('1686953660_configurate_and_ens', { ], }); - // 3. + // Ensure proposal has set speed correctly expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); - // 4. + // Ensure proposal has set bridged market to 0 expect(await bridgedComet.baseTrackingSupplySpeed()).to.be.equal(0); expect(await bridgedComet.baseTrackingBorrowSpeed()).to.be.equal(0); } diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc.n/relations.ts index 2a7febb6c..b1ca91f34 100644 --- a/deployments/arbitrum/usdc.n/relations.ts +++ b/deployments/arbitrum/usdc.n/relations.ts @@ -44,55 +44,4 @@ export default { } } }, - bridgedComet: { - delegates: { - field: { - slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc', - }, - }, - relations: { - baseToken: { - alias: async (nativetoken) => nativetoken.symbol()+'.e', - }, - baseTokenPriceFeed: { - field: async (bridgedComet) => bridgedComet.baseTokenPriceFeed(), - alias: async (_, { baseToken }) => `${await baseToken[0].symbol()+'.e'}:priceFeed`, - }, - assets: { - field: async (bridgedComet) => { - const n = await bridgedComet.numAssets(); - return Promise.all( - Array(n).fill(0).map(async (_, i) => { - const assetInfo = await bridgedComet.getAssetInfo(i); - return assetInfo.asset; - }) - ); - }, - alias: async (token) => token.symbol(), - }, - assetPriceFeeds: { - field: async (bridgedComet) => { - const n = await bridgedComet.numAssets(); - return Promise.all( - Array(n).fill(0).map(async (_, i) => { - const assetInfo = await bridgedComet.getAssetInfo(i); - return assetInfo.priceFeed; - }) - ); - }, - alias: async (_, { assets }, i) => `${await assets[i].symbol()}:priceFeed`, - }, - cometAdmin: { - field: { - slot: '0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103', - }, - }, - }, - }, - 'bridgedComet:implementation': { - artifact: 'contracts/Comet.sol:Comet', - delegates: { - field: async (bridgedComet) => bridgedComet.extensionDelegate(), - }, - }, }; \ No newline at end of file diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index 3bf22981d..e2c350e0f 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -4,7 +4,7 @@ import { setNextBaseFeeToZero, setNextBlockTimestamp } from './hreUtils'; import { utils, BigNumber } from 'ethers'; import { Log } from '@ethersproject/abstract-provider'; -export default async function relayArbitrumMessage( +export async function relayArbitrumMessage( governanceDeploymentManager: DeploymentManager, bridgeDeploymentManager: DeploymentManager, startingBlockNumber: number @@ -110,18 +110,27 @@ export default async function relayArbitrumMessage( await bridgeReceiver.executeProposal(id, { gasPrice: 0 }); } } +} +export async function relayCCTPMint( + governanceDeploymentManager: DeploymentManager, + bridgeDeploymentManager: DeploymentManager, + startingBlockNumber: number +){ // CCTP relay // L1 contracts - const MainnetTokenMessenger = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPTokenMessenger'); - const MainnetMessageTransmitter = await governanceDeploymentManager.getContractOrThrow('mainnetCCTPMessageTransmitter'); + const L1MessageTransmitter = await governanceDeploymentManager.getContractOrThrow('CCTPMessageTransmitter'); // Arbitrum TokenMinter which is L2 contracts - const TokenMinter = await bridgeDeploymentManager.getContractOrThrow('arbitrumCCTPTokenMinter'); - + const TokenMinter = + bridgeDeploymentManager.network === 'arbitrum' ? + await bridgeDeploymentManager.existing('TokenMinter', '0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48', 'arbitrum') : + await bridgeDeploymentManager.existing('TokenMinter', '0xE997d7d2F6E065a9A93Fa2175E878Fb9081F1f0A', 'arbitrum-goerli'); + + const depositForBurnEvents: Log[] = await governanceDeploymentManager.hre.ethers.provider.getLogs({ fromBlock: startingBlockNumber, toBlock: 'latest', - address: MainnetMessageTransmitter.address, + address: L1MessageTransmitter.address, topics: [utils.id('MessageSent(bytes)')] }); @@ -197,19 +206,21 @@ export default async function relayArbitrumMessage( }); // Impersonate the Arbitrum TokenMinter and mint token to recipient - const ImpersonateLocalTokenMessager = '0x19330d10d9cc8751218eaf51e8885d058642e08a'; - + const ImpersonateLocalTokenMessenger = + bridgeDeploymentManager.network === 'arbitrum' ? '0x19330d10d9cc8751218eaf51e8885d058642e08a' : + 'arbitrum-goerli' ? '0x12dcfd3fe2e9eac2859fd1ed86d2ab8c5a2f9352' : + '0x0'; // Impersonate the Arbitrum TokenMinter and mint token to recipient for (let burnEvent of burnEvents) { const { recipient, amount, sourceDomain, burnToken } = burnEvent; const localTokenMessengerSigner = await impersonateAddress( bridgeDeploymentManager, - ImpersonateLocalTokenMessager + ImpersonateLocalTokenMessenger ); const transactionRequest = await localTokenMessengerSigner.populateTransaction({ to: TokenMinter.address, - from: ImpersonateLocalTokenMessager, + from: ImpersonateLocalTokenMessenger, data: TokenMinter.interface.encodeFunctionData('mint', [sourceDomain, burnToken, utils.getAddress(recipient), amount]), gasPrice: 0 }); diff --git a/scenario/utils/relayMessage.ts b/scenario/utils/relayMessage.ts index ef7b78a40..9cab8a0e2 100644 --- a/scenario/utils/relayMessage.ts +++ b/scenario/utils/relayMessage.ts @@ -1,6 +1,6 @@ import { DeploymentManager } from '../../plugins/deployment_manager'; import relayPolygonMessage from './relayPolygonMessage'; -import relayArbitrumMessage from './relayArbitrumMessage'; +import { relayArbitrumMessage, relayCCTPMint } from './relayArbitrumMessage'; import relayBaseMessage from './relayBaseMessage'; import relayLineaMessage from './relayLineaMessage'; @@ -33,6 +33,11 @@ export default async function relayMessage( bridgeDeploymentManager, startingBlockNumber ); + await relayCCTPMint( + governanceDeploymentManager, + bridgeDeploymentManager, + startingBlockNumber + ); break; case 'linea-goerli': await relayLineaMessage( From a1afadeba08d5bbff278a29bbbc64d5c4a4260fc Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 13:07:24 -0400 Subject: [PATCH 35/48] remove network prefixes, and rename bridgeComet to usdceComet --- .../1686953660_configurate_and_ens.ts | 24 +++++++++---------- deployments/arbitrum/usdc/roots.json | 4 +--- deployments/mainnet/usdc/roots.json | 4 ++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index f727d8be6..cebc20fe2 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -25,7 +25,7 @@ export default migration('1686953660_configurate_and_ens', { const { utils } = ethers; const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); - const bridgedComet = await deploymentManager.fromDep('comet.e', 'arbitrum', 'usdc', 'comet'); + const usdceComet = await deploymentManager.fromDep('comet.e', 'arbitrum', 'usdc', 'comet'); const { bridgeReceiver, timelock: l2Timelock, @@ -65,19 +65,19 @@ export default migration('1686953660_configurate_and_ens', { [comet.address, arbitrumCOMPAddress] ); - const turnOffBridgeCometSupplySpeedCalldata = utils.defaultAbiCoder.encode( + const turnOffUSDCeCometSupplySpeedCalldata = utils.defaultAbiCoder.encode( ['address', 'uint64'], - [bridgedComet.address, 0] + [usdceComet.address, 0] ); - const turnOffBridgedCometBorrowSpeedCalldata = utils.defaultAbiCoder.encode( + const turnOffUSDCeCometBorrowSpeedCalldata = utils.defaultAbiCoder.encode( ['address', 'uint64'], - [bridgedComet.address, 0] + [usdceComet.address, 0] ); - const deployAndUpgradeToBridgedCometCalldata = utils.defaultAbiCoder.encode( + const deployAndUpgradeToUSDCeCometCalldata = utils.defaultAbiCoder.encode( ['address', 'address'], - [configurator.address, bridgedComet.address] + [configurator.address, usdceComet.address] ); const l2ProposalData = utils.defaultAbiCoder.encode( @@ -94,7 +94,7 @@ export default migration('1686953660_configurate_and_ens', { 'setBaseTrackingBorrowSpeed(address,uint64)', 'deployAndUpgradeTo(address,address)', ], - [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffBridgeCometSupplySpeedCalldata, turnOffBridgedCometBorrowSpeedCalldata, deployAndUpgradeToBridgedCometCalldata] + [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffUSDCeCometSupplySpeedCalldata, turnOffUSDCeCometBorrowSpeedCalldata, deployAndUpgradeToUSDCeCometCalldata] ] ); @@ -173,7 +173,7 @@ export default migration('1686953660_configurate_and_ens', { async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { const ethers = deploymentManager.hre.ethers; await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set - const bridgedComet = await deploymentManager.fromDep('bridgedComet', 'arbitrum', 'usdc', 'comet'); + const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc', 'comet'); const { comet, rewards, @@ -250,8 +250,8 @@ export default migration('1686953660_configurate_and_ens', { // Ensure proposal has set speed correctly expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); - // Ensure proposal has set bridged market to 0 - expect(await bridgedComet.baseTrackingSupplySpeed()).to.be.equal(0); - expect(await bridgedComet.baseTrackingBorrowSpeed()).to.be.equal(0); + // Ensure proposal has set usdce market to 0 + expect(await usdceComet.baseTrackingSupplySpeed()).to.be.equal(0); + expect(await usdceComet.baseTrackingBorrowSpeed()).to.be.equal(0); } }); \ No newline at end of file diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json index 5339d8ac7..dce14a07b 100644 --- a/deployments/arbitrum/usdc/roots.json +++ b/deployments/arbitrum/usdc/roots.json @@ -3,7 +3,5 @@ "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", - "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d", - "arbitrumCCTPTokenMinter": "0xE7Ed1fa7f45D05C508232aa32649D89b73b8bA48", - "arbitrumCCTPMessageTransmitter": "0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca" + "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" } \ No newline at end of file diff --git a/deployments/mainnet/usdc/roots.json b/deployments/mainnet/usdc/roots.json index b17b129e0..ed592341d 100644 --- a/deployments/mainnet/usdc/roots.json +++ b/deployments/mainnet/usdc/roots.json @@ -7,6 +7,6 @@ "fxRoot": "0xfe5e5D361b2ad62c541bAb87C45a0B9B018389a2", "arbitrumInbox": "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f", "arbitrumL1GatewayRouter": "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef", - "mainnetCCTPTokenMessenger": "0xbd3fa81b58ba92a82136038b25adec7066af3155", - "mainnetCCTPMessageTransmitter": "0x0a992d191deec32afe36203ad87d7d289a738f81" + "CCTPTokenMessenger": "0xbd3fa81b58ba92a82136038b25adec7066af3155", + "CCTPMessageTransmitter": "0x0a992d191deec32afe36203ad87d7d289a738f81" } \ No newline at end of file From 9d3cf20a7525db2a7a6e984853dab995dd93976c Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 16:27:38 -0400 Subject: [PATCH 36/48] rename/refactor usdc -> usdc.e, and usdc.n -> usdc. Also rename deplyoment name for to and to --- .../arbitrum/{usdc => usdc.e}/configuration.json | 2 +- deployments/arbitrum/{usdc => usdc.e}/deploy.ts | 0 .../migrations/1679020486_configurate_and_ens.ts | 0 .../arbitrum/{usdc => usdc.e}/relations.ts | 0 deployments/arbitrum/usdc.e/roots.json | 7 +++++++ deployments/arbitrum/usdc.n/deploy.ts | 16 ++++++++-------- .../migrations/1686953660_configurate_and_ens.ts | 12 ++++++++---- deployments/arbitrum/usdc/roots.json | 8 +------- hardhat.config.ts | 10 +++++----- scenario/LiquidationBotScenario.ts | 10 +++++----- .../liquidateUnderwaterBorrowers.ts | 4 ++-- 11 files changed, 37 insertions(+), 32 deletions(-) rename deployments/arbitrum/{usdc => usdc.e}/configuration.json (98%) rename deployments/arbitrum/{usdc => usdc.e}/deploy.ts (100%) rename deployments/arbitrum/{usdc => usdc.e}/migrations/1679020486_configurate_and_ens.ts (100%) rename deployments/arbitrum/{usdc => usdc.e}/relations.ts (100%) create mode 100644 deployments/arbitrum/usdc.e/roots.json diff --git a/deployments/arbitrum/usdc/configuration.json b/deployments/arbitrum/usdc.e/configuration.json similarity index 98% rename from deployments/arbitrum/usdc/configuration.json rename to deployments/arbitrum/usdc.e/configuration.json index e7d68ae12..d95c0af43 100644 --- a/deployments/arbitrum/usdc/configuration.json +++ b/deployments/arbitrum/usdc.e/configuration.json @@ -1,7 +1,7 @@ { "name": "Compound USDC", "symbol": "cUSDCv3", - "baseToken": "USDC", + "baseToken": "USDC.e", "baseTokenAddress": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8", "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", "borrowMin": "100e6", diff --git a/deployments/arbitrum/usdc/deploy.ts b/deployments/arbitrum/usdc.e/deploy.ts similarity index 100% rename from deployments/arbitrum/usdc/deploy.ts rename to deployments/arbitrum/usdc.e/deploy.ts diff --git a/deployments/arbitrum/usdc/migrations/1679020486_configurate_and_ens.ts b/deployments/arbitrum/usdc.e/migrations/1679020486_configurate_and_ens.ts similarity index 100% rename from deployments/arbitrum/usdc/migrations/1679020486_configurate_and_ens.ts rename to deployments/arbitrum/usdc.e/migrations/1679020486_configurate_and_ens.ts diff --git a/deployments/arbitrum/usdc/relations.ts b/deployments/arbitrum/usdc.e/relations.ts similarity index 100% rename from deployments/arbitrum/usdc/relations.ts rename to deployments/arbitrum/usdc.e/relations.ts diff --git a/deployments/arbitrum/usdc.e/roots.json b/deployments/arbitrum/usdc.e/roots.json new file mode 100644 index 000000000..dce14a07b --- /dev/null +++ b/deployments/arbitrum/usdc.e/roots.json @@ -0,0 +1,7 @@ +{ + "comet": "0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA", + "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", + "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", + "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", + "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" +} \ No newline at end of file diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc.n/deploy.ts index 0e29a52fe..19d799173 100644 --- a/deployments/arbitrum/usdc.n/deploy.ts +++ b/deployments/arbitrum/usdc.n/deploy.ts @@ -19,14 +19,14 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); // Import shared contracts from cUSDCv3 - const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'arbitrum', 'usdc'); - const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); - const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'arbitrum', 'usdc'); - const configurator = await deploymentManager.fromDep('configurator', 'arbitrum', 'usdc'); - const rewards = await deploymentManager.fromDep('rewards', 'arbitrum', 'usdc'); - const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc'); - const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc'); - const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc'); + const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'arbitrum', 'usdc.e'); + const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc.e'); + const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'arbitrum', 'usdc.e'); + const configurator = await deploymentManager.fromDep('configurator', 'arbitrum', 'usdc.e'); + const rewards = await deploymentManager.fromDep('rewards', 'arbitrum', 'usdc.e'); + const bulker = await deploymentManager.fromDep('bulker', 'arbitrum', 'usdc.e'); + const localTimelock = await deploymentManager.fromDep('timelock', 'arbitrum', 'usdc.e'); + const bridgeReceiver = await deploymentManager.fromDep('bridgeReceiver', 'arbitrum', 'usdc.e'); // Deploy Comet const deployed = await deployComet(deploymentManager, deploySpec); diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts index cebc20fe2..9b792be8a 100644 --- a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts @@ -24,8 +24,8 @@ export default migration('1686953660_configurate_and_ens', { const ethers = deploymentManager.hre.ethers; const { utils } = ethers; - const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc'); - const usdceComet = await deploymentManager.fromDep('comet.e', 'arbitrum', 'usdc', 'comet'); + const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc.e'); + const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); const { bridgeReceiver, timelock: l2Timelock, @@ -112,6 +112,10 @@ export default migration('1686953660_configurate_and_ens', { const arbitrumChainId = (await deploymentManager.hre.ethers.provider.getNetwork()).chainId.toString(); const newMarketObject = { baseSymbol: 'USDC', cometAddress: comet.address }; const officialMarketsJSON = JSON.parse(await ENSResolver.text(subdomainHash, ENSTextRecordKey)); + + // Rename old USDC market into USDC.e + officialMarketsJSON[arbitrumChainId][0].baseSymbol = 'USDC.e'; + if (officialMarketsJSON[arbitrumChainId]) { officialMarketsJSON[arbitrumChainId].push(newMarketObject); } else { @@ -173,7 +177,7 @@ export default migration('1686953660_configurate_and_ens', { async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { const ethers = deploymentManager.hre.ethers; await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set - const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc', 'comet'); + const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); const { comet, rewards, @@ -237,7 +241,7 @@ export default migration('1686953660_configurate_and_ens', { 42161: [ { - baseSymbol: 'USDC', + baseSymbol: 'USDC.e', cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', }, { diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json index dce14a07b..9e26dfeeb 100644 --- a/deployments/arbitrum/usdc/roots.json +++ b/deployments/arbitrum/usdc/roots.json @@ -1,7 +1 @@ -{ - "comet": "0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA", - "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", - "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", - "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", - "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" -} \ No newline at end of file +{} \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 42660d616..231aed072 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -24,7 +24,7 @@ import mumbaiRelationConfigMap from './deployments/mumbai/usdc/relations'; import mainnetRelationConfigMap from './deployments/mainnet/usdc/relations'; import mainnetWethRelationConfigMap from './deployments/mainnet/weth/relations'; import polygonRelationConfigMap from './deployments/polygon/usdc/relations'; -import arbitrumRelationConfigMap from './deployments/arbitrum/usdc/relations'; +import arbitrumRelationConfigMap from './deployments/arbitrum/usdc.e/relations'; import arbitrumNativeRelationConfigMap from './deployments/arbitrum/usdc.n/relations'; import arbitrumGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations'; import baseGoerliRelationConfigMap from './deployments/base-goerli/usdc/relations'; @@ -282,7 +282,7 @@ const config: HardhatUserConfig = { usdc: polygonRelationConfigMap }, arbitrum: { - usdc: arbitrumRelationConfigMap, + 'usdc.e': arbitrumRelationConfigMap, 'usdc.n': arbitrumNativeRelationConfigMap }, 'arbitrum-goerli': { @@ -344,13 +344,13 @@ const config: HardhatUserConfig = { auxiliaryBase: 'mainnet' }, { - name: 'arbitrum', + name: 'arbitrum-usdc.e', network: 'arbitrum', - deployment: 'usdc', + deployment: 'usdc.e', auxiliaryBase: 'mainnet' }, { - name: 'arbitrum-usdc-native', + name: 'arbitrum-usdc', network: 'arbitrum', deployment: 'usdc.n', auxiliaryBase: 'mainnet' diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index a08837f9e..bed630369 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -78,7 +78,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { usdc: 2250000 }, arbitrum: { - usdc: 10000000, + 'usdc.e': 10000000, 'usdc.n': 10000000 } }; @@ -114,7 +114,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], }, arbitrum: { - usdc: [ + 'usdc.e': [ // ARB ' == 500000', // GMX @@ -260,7 +260,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { usdc: 3000000 }, arbitrum: { - usdc: 10000000, + 'usdc.e': 10000000, 'usdc.n': 10000000 } }; @@ -296,7 +296,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { ] }, arbitrum: { - usdc: [ + 'usdc.e': [ // ARB ' == 1000000', // GMX @@ -350,7 +350,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { ] }, arbitrum: { - usdc: [ + 'usdc.e': [ // ARB exp(300000, 18), // GMX diff --git a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts index 957a9a44e..6097ef080 100644 --- a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts +++ b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts @@ -73,7 +73,7 @@ const liquidationThresholds = { 'usdc': 10e6 }, arbitrum: { - 'usdc': 10e6, + 'usdc.e': 10e6, 'usdc.n': 10e6 } }; @@ -102,7 +102,7 @@ export const flashLoanPools = { } }, arbitrum: { - usdc: { + 'usdc.e': { tokenAddress: addresses.arbitrum.USDC, // USDC/USDC_E/.01% pool poolFee: 100 }, From e3d8597411035373cbffe33ba497c05c3ea474f1 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 16:40:37 -0400 Subject: [PATCH 37/48] luckily by the time of testing now Jul 6th 1:40PM PST, we have enough liquidity in the uniswap USDC.e:USDC pool to cover the unchanged volume liquidation scenarios test --- scenario/LiquidationBotScenario.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index bed630369..d96ffadcc 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -126,13 +126,13 @@ for (let i = 0; i < MAX_ASSETS; i++) { ], 'usdc.n': [ // ARB - ' == 300000', + ' == 500000', // GMX - ' == 2000', + ' == 4000', // WETH - ' == 300', + ' == 500', // WBTC - ' == 30' + ' == 50' ] } }; From 4b95ada23f372cd8986654e3c5de18cc636813e8 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 17:16:03 -0400 Subject: [PATCH 38/48] rename usdc.n to usdc --- .../arbitrum/{usdc.n => usdc}/configuration.json | 0 deployments/arbitrum/{usdc.n => usdc}/deploy.ts | 0 .../migrations/1686953660_configurate_and_ens.ts | 0 deployments/arbitrum/{usdc.n => usdc}/relations.ts | 0 deployments/arbitrum/usdc/roots.json | 1 - hardhat.config.ts | 6 +++--- scenario/LiquidationBotScenario.ts | 10 +++++----- .../liquidation_bot/liquidateUnderwaterBorrowers.ts | 4 ++-- 8 files changed, 10 insertions(+), 11 deletions(-) rename deployments/arbitrum/{usdc.n => usdc}/configuration.json (100%) rename deployments/arbitrum/{usdc.n => usdc}/deploy.ts (100%) rename deployments/arbitrum/{usdc.n => usdc}/migrations/1686953660_configurate_and_ens.ts (100%) rename deployments/arbitrum/{usdc.n => usdc}/relations.ts (100%) delete mode 100644 deployments/arbitrum/usdc/roots.json diff --git a/deployments/arbitrum/usdc.n/configuration.json b/deployments/arbitrum/usdc/configuration.json similarity index 100% rename from deployments/arbitrum/usdc.n/configuration.json rename to deployments/arbitrum/usdc/configuration.json diff --git a/deployments/arbitrum/usdc.n/deploy.ts b/deployments/arbitrum/usdc/deploy.ts similarity index 100% rename from deployments/arbitrum/usdc.n/deploy.ts rename to deployments/arbitrum/usdc/deploy.ts diff --git a/deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts similarity index 100% rename from deployments/arbitrum/usdc.n/migrations/1686953660_configurate_and_ens.ts rename to deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts diff --git a/deployments/arbitrum/usdc.n/relations.ts b/deployments/arbitrum/usdc/relations.ts similarity index 100% rename from deployments/arbitrum/usdc.n/relations.ts rename to deployments/arbitrum/usdc/relations.ts diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json deleted file mode 100644 index 9e26dfeeb..000000000 --- a/deployments/arbitrum/usdc/roots.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 231aed072..5d6bcb75e 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -25,7 +25,7 @@ import mainnetRelationConfigMap from './deployments/mainnet/usdc/relations'; import mainnetWethRelationConfigMap from './deployments/mainnet/weth/relations'; import polygonRelationConfigMap from './deployments/polygon/usdc/relations'; import arbitrumRelationConfigMap from './deployments/arbitrum/usdc.e/relations'; -import arbitrumNativeRelationConfigMap from './deployments/arbitrum/usdc.n/relations'; +import arbitrumNativeRelationConfigMap from './deployments/arbitrum/usdc/relations'; import arbitrumGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations'; import baseGoerliRelationConfigMap from './deployments/base-goerli/usdc/relations'; import baseGoerliWethRelationConfigMap from './deployments/base-goerli/weth/relations'; @@ -283,7 +283,7 @@ const config: HardhatUserConfig = { }, arbitrum: { 'usdc.e': arbitrumRelationConfigMap, - 'usdc.n': arbitrumNativeRelationConfigMap + usdc: arbitrumNativeRelationConfigMap }, 'arbitrum-goerli': { usdc: arbitrumGoerliRelationConfigMap @@ -352,7 +352,7 @@ const config: HardhatUserConfig = { { name: 'arbitrum-usdc', network: 'arbitrum', - deployment: 'usdc.n', + deployment: 'usdc', auxiliaryBase: 'mainnet' }, { diff --git a/scenario/LiquidationBotScenario.ts b/scenario/LiquidationBotScenario.ts index d96ffadcc..2ba8b0214 100644 --- a/scenario/LiquidationBotScenario.ts +++ b/scenario/LiquidationBotScenario.ts @@ -79,7 +79,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { }, arbitrum: { 'usdc.e': 10000000, - 'usdc.n': 10000000 + usdc: 10000000 } }; const assetAmounts = { @@ -124,7 +124,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { // WBTC ' == 50' ], - 'usdc.n': [ + usdc: [ // ARB ' == 500000', // GMX @@ -261,7 +261,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { }, arbitrum: { 'usdc.e': 10000000, - 'usdc.n': 10000000 + usdc: 10000000 } }; const assetAmounts = { @@ -306,7 +306,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { // WBTC ' == 300' ], - 'usdc.n': [ + usdc: [ // ARB ' == 1000000', // GMX @@ -360,7 +360,7 @@ for (let i = 0; i < MAX_ASSETS; i++) { // WBTC exp(50, 8), ], - 'usdc.n': [ + usdc: [ // ARB exp(300000, 18), // GMX diff --git a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts index 6097ef080..d073fb587 100644 --- a/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts +++ b/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts @@ -74,7 +74,7 @@ const liquidationThresholds = { }, arbitrum: { 'usdc.e': 10e6, - 'usdc.n': 10e6 + usdc: 10e6 } }; @@ -106,7 +106,7 @@ export const flashLoanPools = { tokenAddress: addresses.arbitrum.USDC, // USDC/USDC_E/.01% pool poolFee: 100 }, - 'usdc.n': { + usdc: { tokenAddress: addresses.arbitrum.USDC_E, poolFee: 100 }, From a73265b162702dccd2756c509f59461a80a914f7 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 6 Jul 2023 18:04:41 -0400 Subject: [PATCH 39/48] make yarn lint happy --- scenario/utils/relayArbitrumMessage.ts | 12 ++++++------ scenario/utils/relayMessage.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scenario/utils/relayArbitrumMessage.ts b/scenario/utils/relayArbitrumMessage.ts index e2c350e0f..4929b9533 100644 --- a/scenario/utils/relayArbitrumMessage.ts +++ b/scenario/utils/relayArbitrumMessage.ts @@ -202,14 +202,14 @@ export async function relayCCTPMint( amount: amount, sourceDomain: msgSourceDomain, burnToken: burnToken - } + }; }); // Impersonate the Arbitrum TokenMinter and mint token to recipient - const ImpersonateLocalTokenMessenger = - bridgeDeploymentManager.network === 'arbitrum' ? '0x19330d10d9cc8751218eaf51e8885d058642e08a' : - 'arbitrum-goerli' ? '0x12dcfd3fe2e9eac2859fd1ed86d2ab8c5a2f9352' : - '0x0'; + const ImpersonateLocalTokenMessenger = + bridgeDeploymentManager.network === 'arbitrum' ? '0x19330d10d9cc8751218eaf51e8885d058642e08a' : + bridgeDeploymentManager.network === 'arbitrum-goerli' ? '0x12dcfd3fe2e9eac2859fd1ed86d2ab8c5a2f9352' : + '0x0'; // Impersonate the Arbitrum TokenMinter and mint token to recipient for (let burnEvent of burnEvents) { const { recipient, amount, sourceDomain, burnToken } = burnEvent; @@ -227,7 +227,7 @@ export async function relayCCTPMint( await setNextBaseFeeToZero(bridgeDeploymentManager); - const tx = await ( + await ( await localTokenMessengerSigner.sendTransaction(transactionRequest) ).wait(); } diff --git a/scenario/utils/relayMessage.ts b/scenario/utils/relayMessage.ts index 9cab8a0e2..c48f1bbf3 100644 --- a/scenario/utils/relayMessage.ts +++ b/scenario/utils/relayMessage.ts @@ -37,7 +37,7 @@ export default async function relayMessage( governanceDeploymentManager, bridgeDeploymentManager, startingBlockNumber - ); + ); break; case 'linea-goerli': await relayLineaMessage( From b0bab3fcbb6f94361b48a870147d3b315c644302 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 12 Jul 2023 13:51:24 -0700 Subject: [PATCH 40/48] change default supply reward speed on new comet to be 0 --- .../arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts index 9b792be8a..65b9a1b89 100644 --- a/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts +++ b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts @@ -252,7 +252,7 @@ export default migration('1686953660_configurate_and_ens', { }); // Ensure proposal has set speed correctly - expect(await comet.baseTrackingSupplySpeed()).to.be.equal(exp(34.74 / 86400, 15, 18)); + expect(await comet.baseTrackingSupplySpeed()).to.be.equal(0); expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); // Ensure proposal has set usdce market to 0 expect(await usdceComet.baseTrackingSupplySpeed()).to.be.equal(0); From 14f1c5f62d40c28bf79167f84c94863949ea7d95 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 16 Aug 2023 11:37:41 -0700 Subject: [PATCH 41/48] hardat confit resolve conflicts --- hardhat.config.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 368116375..242663a4e 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -24,9 +24,8 @@ import mumbaiRelationConfigMap from './deployments/mumbai/usdc/relations'; import mainnetRelationConfigMap from './deployments/mainnet/usdc/relations'; import mainnetWethRelationConfigMap from './deployments/mainnet/weth/relations'; import polygonRelationConfigMap from './deployments/polygon/usdc/relations'; -import arbitrumRelationConfigMap from './deployments/arbitrum/usdc.e/relations'; -import arbitrumNativeRelationConfigMap from './deployments/arbitrum/usdc/relations'; -import arbitrumGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations'; +import arbitrumBridgedUsdcRelationConfigMap from './deployments/arbitrum/usdc.e/relations'; +import arbitrumNativeUsdcRelationConfigMap from './deployments/arbitrum/usdc/relations'; import arbitrumBridgedUsdcGoerliRelationConfigMap from './deployments/arbitrum-goerli/usdc.e/relations'; import arbitrumGoerliNativeUsdcRelationConfigMap from './deployments/arbitrum-goerli/usdc/relations'; import baseGoerliRelationConfigMap from './deployments/base-goerli/usdc/relations'; @@ -284,8 +283,8 @@ const config: HardhatUserConfig = { usdc: polygonRelationConfigMap }, arbitrum: { - 'usdc.e': arbitrumRelationConfigMap, - usdc: arbitrumNativeRelationConfigMap + 'usdc.e': arbitrumBridgedUsdcRelationConfigMap, + usdc: arbitrumNativeUsdcRelationConfigMap }, 'arbitrum-goerli': { 'usdc.e': arbitrumBridgedUsdcGoerliRelationConfigMap, From cb89aa5030cc573179e1257913c70b69828d9f44 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 16 Aug 2023 11:40:38 -0700 Subject: [PATCH 42/48] removed migration script, and set supply cap to 0 on configuration --- deployments/arbitrum/usdc/configuration.json | 8 +- .../1686953660_configurate_and_ens.ts | 261 ------------------ 2 files changed, 4 insertions(+), 265 deletions(-) delete mode 100644 deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts diff --git a/deployments/arbitrum/usdc/configuration.json b/deployments/arbitrum/usdc/configuration.json index 03176e52e..49f8169c7 100644 --- a/deployments/arbitrum/usdc/configuration.json +++ b/deployments/arbitrum/usdc/configuration.json @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "4000000e18" + "supplyCap": "0e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "50000e18" + "supplyCap": "0e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "5000e18" + "supplyCap": "0e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "300e8" + "supplyCap": "0e8" } } } \ No newline at end of file diff --git a/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts deleted file mode 100644 index 65b9a1b89..000000000 --- a/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts +++ /dev/null @@ -1,261 +0,0 @@ -import { Contract } from 'ethers'; -import { expect } from 'chai'; -import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; -import { diffState, getCometConfig } from '../../../../plugins/deployment_manager/DiffState'; -import { migration } from '../../../../plugins/deployment_manager/Migration'; -import { calldata, exp, getConfigurationStruct, proposal } from '../../../../src/deploy'; -import { applyL1ToL2Alias, estimateL2Transaction, estimateTokenBridge } from '../../../../scenario/utils/arbitrumUtils'; - -const ENSName = 'compound-community-licenses.eth'; -const ENSResolverAddress = '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'; -const ENSSubdomainLabel = 'v3-additional-grants'; -const ENSSubdomain = `${ENSSubdomainLabel}.${ENSName}`; -const ENSTextRecordKey = 'v3-official-markets'; - -const arbitrumCOMPAddress = '0x354A6dA3fcde098F8389cad84b0182725c6C91dE'; - -export default migration('1686953660_configurate_and_ens', { - prepare: async (_deploymentManager: DeploymentManager) => { - return {}; - }, - - enact: async (deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager) => { - const trace = deploymentManager.tracer(); - const ethers = deploymentManager.hre.ethers; - const { utils } = ethers; - - const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc.e'); - const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); - const { - bridgeReceiver, - timelock: l2Timelock, - comet, - cometAdmin, - configurator, - rewards, - } = await deploymentManager.getContracts(); - - const { - arbitrumInbox, - arbitrumL1GatewayRouter, - timelock, - governor, - USDC, - CCTPTokenMessenger, - } = await govDeploymentManager.getContracts(); - - const refundAddress = l2Timelock.address; - const configuration = await getConfigurationStruct(deploymentManager); - const setFactoryCalldata = await calldata( - configurator.populateTransaction.setFactory(comet.address, cometFactory.address) - ); - const setConfigurationCalldata = await calldata( - configurator.populateTransaction.setConfiguration(comet.address, configuration) - ); - const USDCAmountToBridge = exp(10_000, 6); - // CCTP destination domain for Arbitrum - const ArbitrumDestinationDomain = 3; - const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode( - ['address', 'address'], - [configurator.address, comet.address] - ); - - const setRewardConfigCalldata = utils.defaultAbiCoder.encode( - ['address', 'address'], - [comet.address, arbitrumCOMPAddress] - ); - - const turnOffUSDCeCometSupplySpeedCalldata = utils.defaultAbiCoder.encode( - ['address', 'uint64'], - [usdceComet.address, 0] - ); - - const turnOffUSDCeCometBorrowSpeedCalldata = utils.defaultAbiCoder.encode( - ['address', 'uint64'], - [usdceComet.address, 0] - ); - - const deployAndUpgradeToUSDCeCometCalldata = utils.defaultAbiCoder.encode( - ['address', 'address'], - [configurator.address, usdceComet.address] - ); - - const l2ProposalData = utils.defaultAbiCoder.encode( - ['address[]', 'uint256[]', 'string[]', 'bytes[]'], - [ - [configurator.address, configurator.address, cometAdmin.address, rewards.address, configurator.address, configurator.address, cometAdmin.address], - [0, 0, 0, 0, 0, 0, 0], - [ - 'setFactory(address,address)', - 'setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))', - 'deployAndUpgradeTo(address,address)', - 'setRewardConfig(address,address)', - 'setBaseTrackingSupplySpeed(address,uint64)', - 'setBaseTrackingBorrowSpeed(address,uint64)', - 'deployAndUpgradeTo(address,address)', - ], - [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffUSDCeCometSupplySpeedCalldata, turnOffUSDCeCometBorrowSpeedCalldata, deployAndUpgradeToUSDCeCometCalldata] - ] - ); - - const createRetryableTicketGasParams = await estimateL2Transaction( - { - from: applyL1ToL2Alias(timelock.address), - to: bridgeReceiver.address, - data: l2ProposalData - }, - deploymentManager - ); - - const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); - const subdomainHash = ethers.utils.namehash(ENSSubdomain); - const arbitrumChainId = (await deploymentManager.hre.ethers.provider.getNetwork()).chainId.toString(); - const newMarketObject = { baseSymbol: 'USDC', cometAddress: comet.address }; - const officialMarketsJSON = JSON.parse(await ENSResolver.text(subdomainHash, ENSTextRecordKey)); - - // Rename old USDC market into USDC.e - officialMarketsJSON[arbitrumChainId][0].baseSymbol = 'USDC.e'; - - if (officialMarketsJSON[arbitrumChainId]) { - officialMarketsJSON[arbitrumChainId].push(newMarketObject); - } else { - officialMarketsJSON[arbitrumChainId] = [newMarketObject]; - } - - const mainnetActions = [ - // 1. Set Comet configuration and deployAndUpgradeTo new Comet on Arbitrum. - { - contract: arbitrumInbox, - signature: 'createRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)', - args: [ - bridgeReceiver.address, // address to, - 0, // uint256 l2CallValue, - createRetryableTicketGasParams.maxSubmissionCost, // uint256 maxSubmissionCost, - refundAddress, // address excessFeeRefundAddress, - refundAddress, // address callValueRefundAddress, - createRetryableTicketGasParams.gasLimit, // uint256 gasLimit, - createRetryableTicketGasParams.maxFeePerGas, // uint256 maxFeePerGas, - l2ProposalData, // bytes calldata data - ], - value: createRetryableTicketGasParams.deposit - }, - // 2. Approve USDC to CCTP - { - contract: USDC, - signature: 'approve(address,uint256)', - args: [CCTPTokenMessenger.address, USDCAmountToBridge] - }, - // 3. Burn USDC to Arbitrum via CCTP - { - contract: CCTPTokenMessenger, - signature: 'depositForBurn(uint256,uint32,bytes32,address)', - args: [USDCAmountToBridge, ArbitrumDestinationDomain, utils.hexZeroPad(comet.address, 32), USDC.address], - }, - // 4. Update the list of official markets - { - target: ENSResolverAddress, - signature: 'setText(bytes32,string,string)', - calldata: ethers.utils.defaultAbiCoder.encode( - ['bytes32', 'string', 'string'], - [subdomainHash, ENSTextRecordKey, JSON.stringify(officialMarketsJSON)] - ) - } - ]; - - // TODO: Will update this description to be more accurate once the contract is deployed - const description = "# Configurate Arbitrum cUSDCv3 market for Native USDC native, and set ENS record for official markets"; - const txn = await govDeploymentManager.retry(async () => - trace(await governor.propose(...(await proposal(mainnetActions, description)))) - ); - - const event = txn.events.find(event => event.event === 'ProposalCreated'); - const [proposalId] = event.args; - - trace(`Created proposal ${proposalId}.`); - }, - - async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { - const ethers = deploymentManager.hre.ethers; - await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set - const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); - const { - comet, - rewards, - } = await deploymentManager.getContracts(); - - const { - comptrollerV2 - } = await govDeploymentManager.getContracts(); - - // 1. - // TODO: Once contract is deploy and migrate to the right cap amount, will uncomment this to verify - - // const stateChanges = await diffState(comet, getCometConfig, preMigrationBlockNumber); - // expect(stateChanges).to.deep.equal({ - // ARB: { - // supplyCap: exp(4_000_000, 18) - // }, - // GMX: { - // supplyCap: exp(50_000, 18) - // }, - // WETH: { - // supplyCap: exp(5_000, 18) - // }, - // WBTC: { - // supplyCap: exp(300, 8) - // }, - // baseTrackingSupplySpeed: exp(34.74 / 86400, 15, 18) - // }); - - const config = await rewards.rewardConfig(comet.address); - expect(config.token).to.be.equal(arbitrumCOMPAddress); - expect(config.rescaleFactor).to.be.equal(exp(1, 12)); - expect(config.shouldUpscale).to.be.equal(true); - - // 2 & 3. - expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); - - // 4. - const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); - const subdomainHash = ethers.utils.namehash(ENSSubdomain); - const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); - const officialMarkets = JSON.parse(officialMarketsJSON); - expect(officialMarkets).to.deep.equal({ - 1: [ - { - baseSymbol: 'USDC', - cometAddress: '0xc3d688B66703497DAA19211EEdff47f25384cdc3', - }, - { - baseSymbol: 'WETH', - cometAddress: '0xA17581A9E3356d9A858b789D68B4d866e593aE94', - }, - ], - - 137: [ - { - baseSymbol: 'USDC', - cometAddress: '0xF25212E676D1F7F89Cd72fFEe66158f541246445', - }, - ], - - 42161: [ - { - baseSymbol: 'USDC.e', - cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', - }, - { - baseSymbol: 'USDC', - cometAddress: comet.address, - } - ], - }); - - // Ensure proposal has set speed correctly - expect(await comet.baseTrackingSupplySpeed()).to.be.equal(0); - expect(await comet.baseTrackingBorrowSpeed()).to.be.equal(0); - // Ensure proposal has set usdce market to 0 - expect(await usdceComet.baseTrackingSupplySpeed()).to.be.equal(0); - expect(await usdceComet.baseTrackingBorrowSpeed()).to.be.equal(0); - } -}); \ No newline at end of file From 6b846eda0c6b0ac74489b5a1f6d544d6cee9fb4f Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 16 Aug 2023 11:43:07 -0700 Subject: [PATCH 43/48] set reward speed to zero --- deployments/arbitrum/usdc/configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc/configuration.json b/deployments/arbitrum/usdc/configuration.json index 49f8169c7..c5d44d7a0 100644 --- a/deployments/arbitrum/usdc/configuration.json +++ b/deployments/arbitrum/usdc/configuration.json @@ -20,7 +20,7 @@ }, "tracking": { "indexScale": "1e15", - "baseSupplySpeed": "0.000402083333333e15", + "baseSupplySpeed": "0e15", "baseBorrowSpeed": "0e15", "baseMinForRewards": "10000e6" }, From ca12b578d4b2063dcd4032b263f1ef883f335b4a Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Wed, 16 Aug 2023 11:44:29 -0700 Subject: [PATCH 44/48] set borrow min to 1 wer --- deployments/arbitrum/usdc/configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc/configuration.json b/deployments/arbitrum/usdc/configuration.json index c5d44d7a0..0309aa962 100644 --- a/deployments/arbitrum/usdc/configuration.json +++ b/deployments/arbitrum/usdc/configuration.json @@ -4,7 +4,7 @@ "baseToken": "USDC", "baseTokenAddress": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", "baseTokenPriceFeed": "0x50834F3163758fcC1Df9973b6e91f0F0F0434aD3", - "borrowMin": "1e6", + "borrowMin": "1e0", "pauseGuardian": "0x78E6317DD6D43DdbDa00Dce32C2CbaFc99361a9d", "storeFrontPriceFactor": 0.8, "targetReserves": "5000000e6", From 2590b8301cef4f6af6374ec3e9bc04f80caab42d Mon Sep 17 00:00:00 2001 From: Hans Wang <2709448+cwang25@users.noreply.github.com> Date: Wed, 16 Aug 2023 15:00:54 -0700 Subject: [PATCH 45/48] Update deployments/arbitrum/usdc/deploy.ts Co-authored-by: Kevin Cheng --- deployments/arbitrum/usdc/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc/deploy.ts b/deployments/arbitrum/usdc/deploy.ts index 19d799173..fcbbd09a6 100644 --- a/deployments/arbitrum/usdc/deploy.ts +++ b/deployments/arbitrum/usdc/deploy.ts @@ -18,7 +18,7 @@ export default async function deploy(deploymentManager: DeploymentManager, deplo const WETH = await deploymentManager.existing('WETH', '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', 'arbitrum'); const WBTC = await deploymentManager.existing('WBTC', '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', 'arbitrum'); - // Import shared contracts from cUSDCv3 + // Import shared contracts from the USDC.e market const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'arbitrum', 'usdc.e'); const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc.e'); const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'arbitrum', 'usdc.e'); From 427bbf292363f63b246ed9f753bbc1059c0345f3 Mon Sep 17 00:00:00 2001 From: GitHub Actions Bot <> Date: Wed, 16 Aug 2023 22:30:10 +0000 Subject: [PATCH 46/48] Modified deployment roots from GitHub Actions --- deployments/arbitrum/usdc/roots.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 deployments/arbitrum/usdc/roots.json diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json new file mode 100644 index 000000000..e4c4bec6a --- /dev/null +++ b/deployments/arbitrum/usdc/roots.json @@ -0,0 +1,7 @@ +{ + "comet": "0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf", + "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", + "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", + "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", + "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" +} \ No newline at end of file From d006f46ced4a77a1f894059094c643cfd69931b8 Mon Sep 17 00:00:00 2001 From: Hans Wang <2709448+cwang25@users.noreply.github.com> Date: Tue, 29 Aug 2023 11:20:19 -0700 Subject: [PATCH 47/48] Migrate and initialize Arbitrum Native USDC market (#789) * Revert "move migration files to separate PR, and keep this original one to be 'deploy' PR" This reverts commit f1f9808b6a88c60d825930226ce16bac0f7c58ce. * update configurate to meet with the feedback from testnet * fix scenario test error and udpate migration to meet the latest official market list and prepare for the official launch * update speed to 10COMP/day and update migration description * uncommented state change verify, since comet has been deployed * 10/86400 is irrationale number so it is 0.000115740740740 to be the closest value that falls within e15 limit * fix migrations * fix typo * update description * Modified migration from GitHub Actions * Update deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts Co-authored-by: Kevin Cheng * removed comments --------- Co-authored-by: GitHub Actions Bot <> Co-authored-by: Kevin Cheng --- deployments/arbitrum/usdc/configuration.json | 10 +- .../1686953660_configurate_and_ens.ts | 267 ++++++++++++++++++ scenario/utils/bridgeProposal.ts | 3 +- 3 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts diff --git a/deployments/arbitrum/usdc/configuration.json b/deployments/arbitrum/usdc/configuration.json index 0309aa962..7690422f7 100644 --- a/deployments/arbitrum/usdc/configuration.json +++ b/deployments/arbitrum/usdc/configuration.json @@ -20,7 +20,7 @@ }, "tracking": { "indexScale": "1e15", - "baseSupplySpeed": "0e15", + "baseSupplySpeed": "0.000115740740740e15", "baseBorrowSpeed": "0e15", "baseMinForRewards": "10000e6" }, @@ -32,7 +32,7 @@ "borrowCF": 0.55, "liquidateCF": 0.60, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "4000000e18" }, "GMX": { "address": "0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a", @@ -41,7 +41,7 @@ "borrowCF": 0.40, "liquidateCF": 0.45, "liquidationFactor": 0.93, - "supplyCap": "0e18" + "supplyCap": "50000e18" }, "WETH": { "address": "0x82af49447d8a07e3bd95bd0d56f35241523fbab1", @@ -50,7 +50,7 @@ "borrowCF": 0.78, "liquidateCF": 0.85, "liquidationFactor": 0.95, - "supplyCap": "0e18" + "supplyCap": "5000e18" }, "WBTC": { "address": "0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f", @@ -59,7 +59,7 @@ "borrowCF": 0.70, "liquidateCF": 0.77, "liquidationFactor": 0.95, - "supplyCap": "0e8" + "supplyCap": "300e8" } } } \ No newline at end of file diff --git a/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts new file mode 100644 index 000000000..0c9184741 --- /dev/null +++ b/deployments/arbitrum/usdc/migrations/1686953660_configurate_and_ens.ts @@ -0,0 +1,267 @@ +import { Contract } from 'ethers'; +import { expect } from 'chai'; +import { DeploymentManager } from '../../../../plugins/deployment_manager/DeploymentManager'; +import { diffState, getCometConfig } from '../../../../plugins/deployment_manager/DiffState'; +import { migration } from '../../../../plugins/deployment_manager/Migration'; +import { calldata, exp, getConfigurationStruct, proposal } from '../../../../src/deploy'; +import { applyL1ToL2Alias, estimateL2Transaction, estimateTokenBridge } from '../../../../scenario/utils/arbitrumUtils'; + +const ENSName = 'compound-community-licenses.eth'; +const ENSResolverAddress = '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'; +const ENSSubdomainLabel = 'v3-additional-grants'; +const ENSSubdomain = `${ENSSubdomainLabel}.${ENSName}`; +const ENSTextRecordKey = 'v3-official-markets'; + +const arbitrumCOMPAddress = '0x354A6dA3fcde098F8389cad84b0182725c6C91dE'; + +export default migration('1686953660_configurate_and_ens', { + prepare: async (_deploymentManager: DeploymentManager) => { + return {}; + }, + + enact: async (deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager) => { + const trace = deploymentManager.tracer(); + const ethers = deploymentManager.hre.ethers; + const { utils } = ethers; + + const cometFactory = await deploymentManager.fromDep('cometFactory', 'arbitrum', 'usdc.e'); + const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); + const { + bridgeReceiver, + timelock: l2Timelock, + comet, + cometAdmin, + configurator, + rewards, + } = await deploymentManager.getContracts(); + + const { + arbitrumInbox, + arbitrumL1GatewayRouter, + timelock, + governor, + USDC, + CCTPTokenMessenger, + } = await govDeploymentManager.getContracts(); + + const refundAddress = l2Timelock.address; + const configuration = await getConfigurationStruct(deploymentManager); + const setFactoryCalldata = await calldata( + configurator.populateTransaction.setFactory(comet.address, cometFactory.address) + ); + const setConfigurationCalldata = await calldata( + configurator.populateTransaction.setConfiguration(comet.address, configuration) + ); + const USDCAmountToBridge = exp(10_000, 6); + // CCTP destination domain for Arbitrum + const ArbitrumDestinationDomain = 3; + const deployAndUpgradeToCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [configurator.address, comet.address] + ); + + const setRewardConfigCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [comet.address, arbitrumCOMPAddress] + ); + + const turnOffUSDCeCometSupplySpeedCalldata = utils.defaultAbiCoder.encode( + ['address', 'uint64'], + [usdceComet.address, 0] + ); + + const turnOffUSDCeCometBorrowSpeedCalldata = utils.defaultAbiCoder.encode( + ['address', 'uint64'], + [usdceComet.address, 0] + ); + + const deployAndUpgradeToUSDCeCometCalldata = utils.defaultAbiCoder.encode( + ['address', 'address'], + [configurator.address, usdceComet.address] + ); + + const l2ProposalData = utils.defaultAbiCoder.encode( + ['address[]', 'uint256[]', 'string[]', 'bytes[]'], + [ + [configurator.address, configurator.address, cometAdmin.address, rewards.address, configurator.address, configurator.address, cometAdmin.address], + [0, 0, 0, 0, 0, 0, 0], + [ + 'setFactory(address,address)', + 'setConfiguration(address,(address,address,address,address,address,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint64,uint104,uint104,uint104,(address,address,uint8,uint64,uint64,uint64,uint128)[]))', + 'deployAndUpgradeTo(address,address)', + 'setRewardConfig(address,address)', + 'setBaseTrackingSupplySpeed(address,uint64)', + 'setBaseTrackingBorrowSpeed(address,uint64)', + 'deployAndUpgradeTo(address,address)', + ], + [setFactoryCalldata, setConfigurationCalldata, deployAndUpgradeToCalldata, setRewardConfigCalldata, turnOffUSDCeCometSupplySpeedCalldata, turnOffUSDCeCometBorrowSpeedCalldata, deployAndUpgradeToUSDCeCometCalldata] + ] + ); + + const createRetryableTicketGasParams = await estimateL2Transaction( + { + from: applyL1ToL2Alias(timelock.address), + to: bridgeReceiver.address, + data: l2ProposalData + }, + deploymentManager + ); + + const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); + const subdomainHash = ethers.utils.namehash(ENSSubdomain); + const arbitrumChainId = (await deploymentManager.hre.ethers.provider.getNetwork()).chainId.toString(); + const newMarketObject = { baseSymbol: 'USDC', cometAddress: comet.address }; + const officialMarketsJSON = JSON.parse(await ENSResolver.text(subdomainHash, ENSTextRecordKey)); + + // Rename old USDC market into USDC.e + officialMarketsJSON[arbitrumChainId][0].baseSymbol = 'USDC.e'; + + if (officialMarketsJSON[arbitrumChainId]) { + officialMarketsJSON[arbitrumChainId].push(newMarketObject); + } else { + officialMarketsJSON[arbitrumChainId] = [newMarketObject]; + } + + const mainnetActions = [ + // 1. Set Comet configuration and deployAndUpgradeTo new Comet on Arbitrum. + { + contract: arbitrumInbox, + signature: 'createRetryableTicket(address,uint256,uint256,address,address,uint256,uint256,bytes)', + args: [ + bridgeReceiver.address, // address to, + 0, // uint256 l2CallValue, + createRetryableTicketGasParams.maxSubmissionCost, // uint256 maxSubmissionCost, + refundAddress, // address excessFeeRefundAddress, + refundAddress, // address callValueRefundAddress, + createRetryableTicketGasParams.gasLimit, // uint256 gasLimit, + createRetryableTicketGasParams.maxFeePerGas, // uint256 maxFeePerGas, + l2ProposalData, // bytes calldata data + ], + value: createRetryableTicketGasParams.deposit + }, + // 2. Approve USDC to CCTP + { + contract: USDC, + signature: 'approve(address,uint256)', + args: [CCTPTokenMessenger.address, USDCAmountToBridge] + }, + // 3. Burn USDC to Arbitrum via CCTP + { + contract: CCTPTokenMessenger, + signature: 'depositForBurn(uint256,uint32,bytes32,address)', + args: [USDCAmountToBridge, ArbitrumDestinationDomain, utils.hexZeroPad(comet.address, 32), USDC.address], + }, + // 4. Update the list of official markets + { + target: ENSResolverAddress, + signature: 'setText(bytes32,string,string)', + calldata: ethers.utils.defaultAbiCoder.encode( + ['bytes32', 'string', 'string'], + [subdomainHash, ENSTextRecordKey, JSON.stringify(officialMarketsJSON)] + ) + } + ]; + + const description = "# Initialize native USDC market cUSDCv3 on Arbitrum\n\nThis proposal takes the governance steps recommended and necessary to initialize a Compound III USDC (native USDC on Arbitrum) market on Arbitrum; upon execution, cUSDCv3 will be ready for use. Simulations have confirmed the market’s readiness, as much as possible, using the [Comet scenario suite](https://github.com/compound-finance/comet/tree/main/scenario). Although real tests have also been run over the Goerli/Arbitrum Goerli, this will be the first proposal to mint native USDC on Arbitrum mainnet by burning USDC on mainnet via the `depositAndBurn` function on the Cross-Chain Transfer Protocol (CCTP) provided by Circle, and therefore includes risks not present in previous proposals.\n\nThe proposal sets the entire configuration in the Configurator to be the same as the existing bridged USDC.e market. Finally, the parameters include a migration of bridged USDC.e market supply-side COMP incentives to users in the new native USDC market.\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/789) and [forum discussion](https://www.comp.xyz/t/initialize-compound-iii-native-usdc-on-arbitrum/4542).\n\n\n## Proposal Actions\n\nThe first proposal action sets the Comet Factory, Comet configuration and deploys a new Comet implementation on Arbitrum. This sends the encoded `setFactory`, `setConfiguration` and `deployAndUpgradeTo` calls across the bridge to the governance receiver on Arbitrum. It also calls `setRewardConfig` on the Arbitrum rewards contract, to establish Arbitrum’s bridged version of COMP as the reward token for the deployment and set the initial supply speed to be 10 COMP/day and borrow speed to be 0 COMP/day. It calls another `setBaseTrackingSupplySpeed` and `setBaseTrackingBorrowSpeed` to set the supply speed and borrow speed of the existing USDC.e market to be 0 COMP/day. Lastly it calls `deployAndUpgradeTo` to deploy an updated Comet implementation for the existing bridged USDC.e market to have the new supply and borrow rewards speed.\n\nThe second action approves Circle’s Cross-Chain Transfer Protocol (CCTP)[TokenMessenger](https://etherscan.io/address/0xbd3fa81b58ba92a82136038b25adec7066af3155) to take the Timelock's USDC on Mainnet, in order to seed the market reserves through the CCTP.\n\nThe third action deposits and burns 10K USDC from mainnet via `depositForBurn` function on CCTP’s TokenMessenger contract to mint native USDC to Comet on Arbitrum.\n\nThe fourth action updates the ENS TXT record `v3-official-markets` on `v3-additional-grants.compound-community-licenses.eth`, updating the official markets JSON to include the new native USDC market and renames the bridged USDC market’s baseSymbol to USDC.e from USDC."; + const txn = await govDeploymentManager.retry(async () => + trace(await governor.propose(...(await proposal(mainnetActions, description)))) + ); + + const event = txn.events.find(event => event.event === 'ProposalCreated'); + const [proposalId] = event.args; + + trace(`Created proposal ${proposalId}.`); + }, + + async enacted(deploymentManager: DeploymentManager): Promise { + return true; + }, + + async verify(deploymentManager: DeploymentManager, govDeploymentManager: DeploymentManager, preMigrationBlockNumber: number) { + const ethers = deploymentManager.hre.ethers; + await deploymentManager.spider(); // Pull in Arbitrum COMP now that reward config has been set + const usdceComet = await deploymentManager.fromDep('usdceComet', 'arbitrum', 'usdc.e', 'comet'); + const { + comet, + rewards, + } = await deploymentManager.getContracts(); + + const { + comptrollerV2 + } = await govDeploymentManager.getContracts(); + + // 1. Verify state changes + const stateChanges = await diffState(comet, getCometConfig, preMigrationBlockNumber); + expect(stateChanges).to.deep.equal({ + ARB: { + supplyCap: exp(4_000_000, 18) + }, + GMX: { + supplyCap: exp(50_000, 18) + }, + WETH: { + supplyCap: exp(5_000, 18) + }, + WBTC: { + supplyCap: exp(300, 8) + }, + baseTrackingSupplySpeed: exp(10 / 86400, 15, 18), + }); + + const config = await rewards.rewardConfig(comet.address); + expect(config.token).to.be.equal(arbitrumCOMPAddress); + expect(config.rescaleFactor).to.be.equal(exp(1, 12)); + expect(config.shouldUpscale).to.be.equal(true); + // Ensure proposal has set usdce market to 0 + expect(await usdceComet.baseTrackingSupplySpeed()).to.be.equal(0); + expect(await usdceComet.baseTrackingBorrowSpeed()).to.be.equal(0); + + // 2 & 3. + expect(await comet.getReserves()).to.be.equal(exp(10_000, 6)); + + // 4. + const ENSResolver = await govDeploymentManager.existing('ENSResolver', ENSResolverAddress); + const subdomainHash = ethers.utils.namehash(ENSSubdomain); + const officialMarketsJSON = await ENSResolver.text(subdomainHash, ENSTextRecordKey); + const officialMarkets = JSON.parse(officialMarketsJSON); + expect(officialMarkets).to.deep.equal({ + 1: [ + { + baseSymbol: 'USDC', + cometAddress: '0xc3d688B66703497DAA19211EEdff47f25384cdc3', + }, + { + baseSymbol: 'WETH', + cometAddress: '0xA17581A9E3356d9A858b789D68B4d866e593aE94', + }, + ], + 8453: [ + { + baseSymbol: 'USDbC', + cometAddress: '0x9c4ec768c28520B50860ea7a15bd7213a9fF58bf' + }, + { + baseSymbol: 'WETH', + cometAddress: '0x46e6b214b524310239732D51387075E0e70970bf' + } + ], + 137: [ + { + baseSymbol: 'USDC', + cometAddress: '0xF25212E676D1F7F89Cd72fFEe66158f541246445', + }, + ], + + 42161: [ + { + baseSymbol: 'USDC.e', + cometAddress: '0xA5EDBDD9646f8dFF606d7448e414884C7d905dCA', + }, + { + baseSymbol: 'USDC', + cometAddress: comet.address, + } + ], + }); + } +}); \ No newline at end of file diff --git a/scenario/utils/bridgeProposal.ts b/scenario/utils/bridgeProposal.ts index 14d7cf923..10c103040 100644 --- a/scenario/utils/bridgeProposal.ts +++ b/scenario/utils/bridgeProposal.ts @@ -34,8 +34,9 @@ export async function executeBridgedProposal( const receiver = await deploymentManager.getContractOrThrow('bridgeReceiver'); const { id, eta } = proposal; + const blockNow = await deploymentManager.hre.ethers.provider.getBlock('latest'); // fast forward l2 time - await setNextBlockTimestamp(deploymentManager, eta.toNumber() + 1); + await setNextBlockTimestamp(deploymentManager, Math.max(eta.toNumber() + 1, blockNow.timestamp + 1)); // execute queued proposal await setNextBaseFeeToZero(deploymentManager); From cca8968fc47f4e5121edaef8c6d14700eb8ea1e7 Mon Sep 17 00:00:00 2001 From: Hans Wang Date: Thu, 31 Aug 2023 16:26:28 -0700 Subject: [PATCH 48/48] add arb mainnet messagetransmitter --- deployments/arbitrum/usdc/roots.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployments/arbitrum/usdc/roots.json b/deployments/arbitrum/usdc/roots.json index e4c4bec6a..54603b0c6 100644 --- a/deployments/arbitrum/usdc/roots.json +++ b/deployments/arbitrum/usdc/roots.json @@ -3,5 +3,6 @@ "configurator": "0xb21b06D71c75973babdE35b49fFDAc3F82Ad3775", "rewards": "0x88730d254A2f7e6AC8388c3198aFd694bA9f7fae", "bridgeReceiver": "0x42480C37B249e33aABaf4c22B20235656bd38068", - "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d" + "bulker": "0xbdE8F31D2DdDA895264e27DD990faB3DC87b372d", + "CCTPMessageTransmitter": "0xC30362313FBBA5cf9163F0bb16a0e01f01A896ca" } \ No newline at end of file