From e9a747d90e1f67f9c843f122f87d71c7cb98cf4e Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 5 Oct 2023 16:30:36 -0400 Subject: [PATCH 01/12] create base usdbc test file at parity with mainnet test file. --- common/configuration.ts | 8 + .../deploy_stargate_usdc_collateral.ts | 8 + .../stargate/StargateUSDbCTestSuite.test.ts | 278 ++++++++++++++++++ .../stargate/constants.ts | 47 ++- 4 files changed, 330 insertions(+), 11 deletions(-) create mode 100644 test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts diff --git a/common/configuration.ts b/common/configuration.ts index c9b10de79..2941ea62c 100644 --- a/common/configuration.ts +++ b/common/configuration.ts @@ -62,6 +62,7 @@ export interface ITokens { cbETH?: string STG?: string sUSDC?: string + sUSDbC?: string sUSDT?: string sETH?: string MORPHO?: string @@ -112,6 +113,7 @@ interface INetworkConfig { COMET_REWARDS?: string AAVE_V3_INCENTIVES_CONTROLLER?: string AAVE_V3_POOL?: string + STARGATE_STAKING_CONTRACT?: string } export const networkConfig: { [key: string]: INetworkConfig } = { @@ -218,6 +220,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = { COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '1': { name: 'mainnet', @@ -313,6 +316,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = { COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '3': { name: 'tenderly', @@ -408,6 +412,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = { COMET_REWARDS: '0x1B0e765F6224C21223AeA2af16c1C46E38885a40', AAVE_V3_POOL: '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', AAVE_V3_INCENTIVES_CONTROLLER: '0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb', + STARGATE_STAKING_CONTRACT: '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' }, '5': { name: 'goerli', @@ -510,6 +515,8 @@ export const networkConfig: { [key: string]: INetworkConfig } = { aBasUSDbC: '0x0a1d576f3eFeF75b330424287a95A366e8281D54', aWETHv3: '0xD4a0e0b9149BCee3C920d2E00b5dE09138fd8bb7', acbETHv3: '0xcf3D55c10DB69f28fD1A75Bd73f3D8A2d9c595ad', + sUSDbC: '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca', + STG: '0xE3B53AF74a4BF62Ae5511055290838050bf764Df' }, chainlinkFeeds: { DAI: '0x591e79239a7d679378ec8c847e5038150364c78f', // 0.3%, 24hr @@ -527,6 +534,7 @@ export const networkConfig: { [key: string]: INetworkConfig } = { COMET_REWARDS: '0x123964802e6ABabBE1Bc9547D72Ef1B69B00A6b1', AAVE_V3_POOL: '0xA238Dd80C259a72e81d7e4664a9801593F98d1c5', AAVE_V3_INCENTIVES_CONTROLLER: '0xf9cc4F0D883F1a1eb2c253bdb46c254Ca51E1F44', + STARGATE_STAKING_CONTRACT: '0x06Eb48763f117c7Be887296CDcdfad2E4092739C' }, } diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index 6ba2fee7b..0f792b71d 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -52,6 +52,14 @@ async function main() { const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargatePoolWrapper') + let name = 'Wrapped Stargate USDC' + let symbol = 'wSTG-USDC' + + if (chainId == '8453') { + name = 'Wrapped Stargate USDbC' + symbol = 'wSTG-USDbC' + } + const erc20 = await WrapperFactory.deploy( 'Wrapped Stargate USDC', 'wSTG-USDC', diff --git a/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts new file mode 100644 index 000000000..d17a42f34 --- /dev/null +++ b/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts @@ -0,0 +1,278 @@ +import collateralTests from '../collateralTests' +import { CollateralFixtureContext, CollateralOpts, MintCollateralFunc } from '../pluginTestTypes' +import { ethers } from 'hardhat' +import { ContractFactory, BigNumberish, BigNumber } from 'ethers' +import { resetFork } from './helpers' +import { + ERC20Mock, + MockV3Aggregator, + MockV3Aggregator__factory, + TestICollateral, + StargatePoolMock, + IStargateLPStaking, + StargateRewardableWrapper, + StargateRewardableWrapper__factory, +} from '@typechain/index' +import { pushOracleForward } from '../../../utils/oracles' +import { bn, fp } from '#/common/numbers' +import { expect } from 'chai' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' +import { + STARGATE, + USDC_USD_PRICE_FEED, + MAX_TRADE_VOL, + DEFAULT_THRESHOLD, + DELAY_UNTIL_DEFAULT, + SUSDC, + ORACLE_TIMEOUT, + ORACLE_ERROR, +} from './constants' +import { noop } from 'lodash' + +/* + Define interfaces +*/ + +interface StargateCollateralFixtureContext extends CollateralFixtureContext { + pool: StargatePoolMock + wpool: StargateRewardableWrapper + stargate: ERC20Mock + stakingContract: IStargateLPStaking +} + +export enum CollateralType { + STABLE, + VOLATILE, +} + +export interface StargateCollateralOpts extends CollateralOpts { + type?: CollateralType +} + +/* + Define deployment functions +*/ + +export const defaultStargateCollateralOpts: StargateCollateralOpts = { + erc20: SUSDC, + targetName: ethers.utils.formatBytes32String('USD'), + rewardERC20: STARGATE, + priceTimeout: ORACLE_TIMEOUT, + chainlinkFeed: USDC_USD_PRICE_FEED, + oracleTimeout: ORACLE_TIMEOUT, + oracleError: ORACLE_ERROR, + maxTradeVolume: MAX_TRADE_VOL, + defaultThreshold: DEFAULT_THRESHOLD, + delayUntilDefault: DELAY_UNTIL_DEFAULT, + type: CollateralType.STABLE, + revenueHiding: fp('0'), +} + +export const deployCollateral = async ( + opts: StargateCollateralOpts = {} +): Promise => { + opts = { ...defaultStargateCollateralOpts, ...opts } + + const StargatePoolCollateralFactory: ContractFactory = await ethers.getContractFactory( + opts.type === CollateralType.STABLE ? 'StargatePoolFiatCollateral' : 'StargatePoolETHCollateral' + ) + + const collateral = await StargatePoolCollateralFactory.deploy( + { + erc20: opts.erc20, + targetName: opts.targetName, + priceTimeout: opts.priceTimeout, + chainlinkFeed: opts.chainlinkFeed, + oracleError: opts.oracleError, + oracleTimeout: opts.oracleTimeout, + maxTradeVolume: opts.maxTradeVolume, + defaultThreshold: opts.defaultThreshold, + delayUntilDefault: opts.delayUntilDefault, + }, + opts.revenueHiding, + { gasLimit: 2000000000 } + ) + await collateral.deployed() + + // Push forward chainlink feed + await pushOracleForward(opts.chainlinkFeed!) + + // sometimes we are trying to test a negative test case and we want this to fail silently + // fortunately this syntax fails silently because our tools are terrible + await expect(collateral.refresh()) + + return collateral +} + +type Fixture = () => Promise + +const makeCollateralFixtureContext = ( + alice: SignerWithAddress, + opts: StargateCollateralOpts = {} +): Fixture => { + const collateralOpts = { ...defaultStargateCollateralOpts, ...opts } + + const makeCollateralFixtureContext = async () => { + return deployCollateralStargateMockContext(collateralOpts) + } + + return makeCollateralFixtureContext +} + +const deployCollateralStargateMockContext = async ( + opts: StargateCollateralOpts = {} +): Promise => { + const collateralOpts = { ...defaultStargateCollateralOpts, ...opts } + + const MockV3AggregatorFactory = ( + await ethers.getContractFactory('MockV3Aggregator') + ) + let chainlinkFeed: MockV3Aggregator + if (collateralOpts.type === CollateralType.STABLE) + chainlinkFeed = await MockV3AggregatorFactory.deploy(8, bn('1e8')) + else { + chainlinkFeed = await MockV3AggregatorFactory.deploy(8, bn('1995e8')) + } + collateralOpts.chainlinkFeed = chainlinkFeed.address + + const StargateRewardableWrapperFactory = ( + await ethers.getContractFactory('StargateRewardableWrapper') + ) + const stargate = await ( + await ethers.getContractFactory('ERC20Mock') + ).deploy('Stargate Mocked token', 'S*MT') + const stakingContract = await ( + await ethers.getContractFactory('StargateLPStakingMock') + ).deploy(stargate.address) + const mockPool = await ( + await ethers.getContractFactory('StargatePoolMock') + ).deploy('Mock Pool', 'MSP', collateralOpts.type === CollateralType.STABLE ? 6 : 8) + await stakingContract.add(bn('5000'), mockPool.address) + await mockPool.mint(stakingContract.address, bn(1e6)) + await mockPool.setExchangeRate(fp(1)) + const wrapper = await StargateRewardableWrapperFactory.deploy( + 'wMocked Pool', + 'wMSP', + stargate.address, + stakingContract.address, + mockPool.address + ) + collateralOpts.erc20 = wrapper.address + collateralOpts.rewardERC20 = stargate.address + + const collateral = await deployCollateral(collateralOpts) + + const rewardToken = await ethers.getContractAt('ERC20Mock', STARGATE) + + return { + collateral, + chainlinkFeed, + tok: wrapper, + rewardToken, + pool: mockPool, + wpool: wrapper, + stargate, + stakingContract, + } +} + +/* + Define helper functions +*/ + +const mintCollateralTo: MintCollateralFunc = async ( + ctx: StargateCollateralFixtureContext, + amount: BigNumberish, + user: SignerWithAddress, + recipient: string +) => { + const currentExchangeRate = await ctx.collateral.refPerTok() + + // ctx.stakingContract + + await ctx.pool.connect(user).approve(ctx.wpool.address, ethers.constants.MaxUint256) + await ctx.pool.mint(user.address, amount) + await ctx.wpool.connect(user).deposit(amount, user.address) + await ctx.wpool.connect(user).transfer(recipient, amount) + await ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) +} + +const reduceRefPerTok = async ( + ctx: StargateCollateralFixtureContext, + pctDecrease: BigNumberish +) => { + const currentExchangeRate = await ctx.pool.exchangeRate() + await ctx.pool.setExchangeRate( + currentExchangeRate.sub(currentExchangeRate.mul(pctDecrease).div(100)) + ) +} + +const increaseRefPerTok = async ( + ctx: StargateCollateralFixtureContext, + pctIncrease: BigNumberish +) => { + const currentExchangeRate = await ctx.pool.exchangeRate() + await ctx.pool.setExchangeRate( + currentExchangeRate.add(currentExchangeRate.mul(pctIncrease).div(100)) + ) +} + +const getExpectedPrice = async (ctx: StargateCollateralFixtureContext): Promise => { + const initRefPerTok = await ctx.collateral.refPerTok() + + const decimals = await ctx.chainlinkFeed.decimals() + + const initData = await ctx.chainlinkFeed.latestRoundData() + return initData.answer + .mul(bn(10).pow(18 - decimals)) + .mul(initRefPerTok) + .div(fp('1')) +} + +const reduceTargetPerRef = async ( + ctx: StargateCollateralFixtureContext, + pctDecrease: BigNumberish +) => { + const lastRound = await ctx.chainlinkFeed.latestRoundData() + const nextAnswer = lastRound.answer.sub(lastRound.answer.mul(pctDecrease).div(100)) + await ctx.chainlinkFeed.updateAnswer(nextAnswer) +} + +const increaseTargetPerRef = async ( + ctx: StargateCollateralFixtureContext, + pctIncrease: BigNumberish +) => { + const lastRound = await ctx.chainlinkFeed.latestRoundData() + const nextAnswer = lastRound.answer.add(lastRound.answer.mul(pctIncrease).div(100)) + await ctx.chainlinkFeed.updateAnswer(nextAnswer) +} + +/* + Run the test suite +*/ + +export const stableOpts = { + deployCollateral, + collateralSpecificConstructorTests: noop, + collateralSpecificStatusTests: noop, + beforeEachRewardsTest: noop, + makeCollateralFixtureContext, + mintCollateralTo, + reduceRefPerTok, + increaseRefPerTok, + resetFork, + collateralName: 'Stargate USDbC Pool', + reduceTargetPerRef, + increaseTargetPerRef, + itClaimsRewards: it.skip, // reward growth not supported in mock + itChecksTargetPerRefDefault: it, + itChecksRefPerTokDefault: it, + itHasRevenueHiding: it, + itIsPricedByPeg: true, + chainlinkDefaultAnswer: 1e8, + itChecksPriceChanges: it, + getExpectedPrice, + targetNetwork: 'base' +} + +collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 0407dcdc9..209506b20 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -1,20 +1,45 @@ import { bn, fp } from '#/common/numbers' import { networkConfig } from '#/common/configuration' +import hre from 'hardhat' +import { useEnv } from '#/utils/env' -export const STARGATE = networkConfig['1'].tokens['STG']! -export const STAKING_CONTRACT = '0xB0D502E938ed5f4df2E681fE6E419ff29631d62b' -export const SUSDC = networkConfig['1'].tokens['sUSDC']! -export const SUSDT = networkConfig['1'].tokens['sUSDT']! -export const SETH = networkConfig['1'].tokens['sETH']! -export const USDC = networkConfig['1'].tokens['USDC']! -export const USDT = networkConfig['1'].tokens['USDT']! -export const USDC_HOLDER = '0x0a59649758aa4d66e25f08dd01271e891fe52199' -export const USDC_USD_PRICE_FEED = networkConfig['1'].chainlinkFeeds['USDC']! -export const ETH_USD_PRICE_FEED = networkConfig['1'].chainlinkFeeds['ETH']! +const forkNetwork = useEnv('FORK_NETWORK') ?? 'mainnet' +let chainId; + +switch(forkNetwork) { + case 'mainnet': + chainId = '1' + break + case 'base': + chainId = '8453' + break + default: + chainId = '1' + break +} + +const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' +const sUSDC_NAME = chainId == '8453' ? 'sUSDbC' : 'sUSDC' + +export const STARGATE = networkConfig[chainId].tokens['STG']! +export const STAKING_CONTRACT = networkConfig[chainId].STARGATE_STAKING_CONTRACT! +export const SUSDC = networkConfig[chainId].tokens[sUSDC_NAME]! +export const SUSDT = networkConfig[chainId].tokens['sUSDT']! +export const SETH = networkConfig[chainId].tokens['sETH']! +export const USDC = networkConfig[chainId].tokens[USDC_NAME]! +export const USDT = networkConfig[chainId].tokens['USDT']! +export const USDC_HOLDER = chainId == '8453' ? '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' : '0x0a59649758aa4d66e25f08dd01271e891fe52199' +export const USDC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDC']! // currently same key for USDC and USDbC +export const ETH_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['ETH']! export const SUSDC_POOL_ID = bn('1') export const WSUSDC_NAME = 'Wrapped S*USDC' export const WSUSDC_SYMBOL = 'wS*USDC' +export const USDbC = networkConfig[chainId].tokens['USDbC']! +export const SUSDbC = networkConfig[chainId].tokens['sUSDbC']! +export const USDbC_HOLDER = '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' +// export const USDbC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDbC']! + export const ORACLE_TIMEOUT = bn(86400) // 24 hours in seconds export const ORACLE_ERROR = fp('0.005') export const DEFAULT_THRESHOLD = bn(5).mul(bn(10).pow(16)) // 0.05 @@ -22,4 +47,4 @@ export const DELAY_UNTIL_DEFAULT = bn(86400) export const MAX_TRADE_VOL = bn(1000000) export const USDC_DECIMALS = bn(6) -export const FORK_BLOCK = 18170484 +export const FORK_BLOCK = chainId == '8453' ? 4873094 : 17289300 From f28a5370ded013f6b9551154ad1f05f023be46d8 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 5 Oct 2023 16:44:09 -0400 Subject: [PATCH 02/12] consider LPStakingTime as a possible staking contract. --- .../plugins/assets/stargate/StargateRewardableWrapper.sol | 7 ++++++- .../assets/stargate/interfaces/IStargateLPStaking.sol | 3 ++- .../assets/stargate/mocks/StargateLPStakingMock.sol | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol b/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol index 9252a9985..838695d18 100644 --- a/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol +++ b/contracts/plugins/assets/stargate/StargateRewardableWrapper.sol @@ -23,7 +23,12 @@ contract StargateRewardableWrapper is RewardableERC20Wrapper { address(pool_) != address(0), "Invalid address" ); - require(address(stargate_) == address(stakingContract_.stargate()), "Wrong stargate"); + try stakingContract_.stargate() returns (address stargateAddress) { + require(stargateAddress == address(stargate_), "Wrong stargate"); + } catch { + // using LPStakingTime contract instead + require(stakingContract_.eToken() == address(stargate_), "Wrong stargate"); + } uint256 poolLength = stakingContract_.poolLength(); uint256 pid = type(uint256).max; diff --git a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol index 1dada23b0..81a861a4a 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol @@ -6,7 +6,8 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStargateLPStaking { function poolLength() external view returns (uint256); - function stargate() external view returns (IERC20); + function stargate() external view returns (address); + function eToken() external view returns (address); // Info of each pool. struct PoolInfo { diff --git a/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol b/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol index 3ab789869..2123564b6 100644 --- a/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol +++ b/contracts/plugins/assets/stargate/mocks/StargateLPStakingMock.sol @@ -10,13 +10,15 @@ contract StargateLPStakingMock is IStargateLPStaking { mapping(uint256 => mapping(address => uint256)) poolToUserBalance; ERC20Mock public immutable stargateMock; - IERC20 public immutable stargate; + address public immutable stargate; + address public immutable eToken; uint256 public totalAllocPoint = 0; constructor(ERC20Mock stargateMock_) { stargateMock = stargateMock_; - stargate = stargateMock_; + stargate = address(stargateMock_); + eToken = address(stargateMock_); } function poolLength() external view override returns (uint256) { From 2d24e3c756d7251ffa6e2f5ce8d6d2ce69bc59c3 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 5 Oct 2023 16:47:02 -0400 Subject: [PATCH 03/12] update pipeline tests to include stargate. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ca7fc0ee6..3bdee1f96 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -84,7 +84,7 @@ jobs: restore-keys: | hardhat-network-fork-${{ runner.os }}- hardhat-network-fork- - - run: npx hardhat test ./test/plugins/individual-collateral/cbeth/*.test.ts + - run: npx hardhat test ./test/plugins/individual-collateral/{stargate,cbeth}/*.test.ts env: NODE_OPTIONS: '--max-old-space-size=8192' TS_NODE_SKIP_IGNORE: true From 69036c642b729df3eccd87d442d7184b9586af36 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Thu, 5 Oct 2023 16:53:33 -0400 Subject: [PATCH 04/12] touched up deploy scripts. --- .../deploy_stargate_usdc_collateral.ts | 29 +++++++++++-------- .../deploy_stargate_usdt_collateral.ts | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index 0f792b71d..8d2d939e8 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -23,6 +23,7 @@ import { STAKING_CONTRACT, SUSDC, } from '../../../../test/plugins/individual-collateral/stargate/constants' +import { useEnv } from '#/utils/env' async function main() { // ==== Read Configuration ==== @@ -50,27 +51,31 @@ async function main() { /******** Deploy Stargate USDC Wrapper **************************/ - const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargatePoolWrapper') - + const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargateRewardableWrapper') + let chainIdKey = useEnv('FORK_NETWORK', 'mainnet') == 'mainnet' ? '1' : '8453' + let USDC_NAME = 'USDC' let name = 'Wrapped Stargate USDC' let symbol = 'wSTG-USDC' + let sUSDC = networkConfig[chainIdKey].tokens.sUSDC - if (chainId == '8453') { + if (chainIdKey == '8453') { + USDC_NAME = 'USDbC' name = 'Wrapped Stargate USDbC' symbol = 'wSTG-USDbC' + sUSDC = networkConfig[chainIdKey].tokens.sUSDbC } const erc20 = await WrapperFactory.deploy( - 'Wrapped Stargate USDC', - 'wSTG-USDC', - networkConfig[chainId].tokens.STG, - STAKING_CONTRACT, - SUSDC + name, + symbol, + networkConfig[chainIdKey].tokens.STG, + networkConfig[chainIdKey].STARGATE_STAKING_CONTRACT, + sUSDC ) await erc20.deployed() console.log( - `Deployed Wrapper for Stargate USDC on ${hre.network.name} (${chainId}): ${erc20.address} ` + `Deployed Wrapper for Stargate ${USDC_NAME} on ${hre.network.name} (${chainIdKey}): ${erc20.address} ` ) const StargateCollateralFactory: StargatePoolFiatCollateral__factory = @@ -81,11 +86,11 @@ async function main() { ).deploy( { priceTimeout: priceTimeout.toString(), - chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, + chainlinkFeed: networkConfig[chainIdKey].chainlinkFeeds.USDC!, oracleError: fp('0.0025').toString(), // 0.25%, erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, - oracleTimeout: oracleTimeout(chainId, '86400').toString(), // 24h hr, + oracleTimeout: oracleTimeout(chainIdKey, '86400').toString(), // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), defaultThreshold: fp('0.0125').toString(), // 1.25% delayUntilDefault: bn('86400').toString(), // 24h @@ -96,7 +101,7 @@ async function main() { await (await collateral.refresh()).wait() expect(await collateral.status()).to.equal(CollateralStatus.SOUND) - console.log(`Deployed Stargate USDC to ${hre.network.name} (${chainId}): ${collateral.address}`) + console.log(`Deployed Stargate ${USDC_NAME} to ${hre.network.name} (${chainIdKey}): ${collateral.address}`) assetCollDeployments.collateral.sUSDC = collateral.address assetCollDeployments.erc20s.sUSDC = erc20.address diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts index 2d317a40c..8a43556a5 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdt_collateral.ts @@ -50,7 +50,7 @@ async function main() { /******** Deploy Stargate USDT Wrapper **************************/ - const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargatePoolWrapper') + const WrapperFactory: ContractFactory = await hre.ethers.getContractFactory('StargateRewardableWrapper') const erc20 = await WrapperFactory.deploy( 'Wrapped Stargate USDT', From f628d958443b3d63d275dfe4876cd05a846eb6c0 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Fri, 6 Oct 2023 12:31:03 -0400 Subject: [PATCH 05/12] get reward tests working on usdbc. --- .../interfaces/IStargateLPStaking.sol | 1 + .../stargate/interfaces/IStargatePool.sol | 2 - .../individual-collateral/collateralTests.ts | 12 ++-- .../stargate/StargateUSDbCTestSuite.test.ts | 68 +++++++++++++++---- .../stargate/constants.ts | 29 ++++---- 5 files changed, 81 insertions(+), 31 deletions(-) diff --git a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol index 81a861a4a..dc9e62ff5 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargateLPStaking.sol @@ -7,6 +7,7 @@ interface IStargateLPStaking { function poolLength() external view returns (uint256); function stargate() external view returns (address); + function eToken() external view returns (address); // Info of each pool. diff --git a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol index 3ddfc9079..cc9e29078 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol @@ -4,8 +4,6 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStargatePool is IERC20Metadata { - function router() external view returns (address); - function poolId() external view returns (uint256); function totalLiquidity() external view returns (uint256); diff --git a/test/plugins/individual-collateral/collateralTests.ts b/test/plugins/individual-collateral/collateralTests.ts index 6899a1950..9c0a20f98 100644 --- a/test/plugins/individual-collateral/collateralTests.ts +++ b/test/plugins/individual-collateral/collateralTests.ts @@ -159,13 +159,17 @@ export default function fn( itClaimsRewards('claims rewards (via collateral.claimRewards())', async () => { const amount = bn('20').mul(bn(10).pow(await ctx.tok.decimals())) - await mintCollateralTo(ctx, amount, alice, collateral.address) + await mintCollateralTo(ctx, amount, alice, ctx.collateral.address) await advanceBlocks(1000) await setNextBlockTimestamp((await getLatestBlockTimestamp()) + 12000) - const balBefore = await (ctx.rewardToken as IERC20Metadata).balanceOf(collateral.address) - await expect(collateral.claimRewards()).to.emit(ctx.tok, 'RewardsClaimed') - const balAfter = await (ctx.rewardToken as IERC20Metadata).balanceOf(collateral.address) + const balBefore = await (ctx.rewardToken as IERC20Metadata).balanceOf( + ctx.collateral.address + ) + await expect(ctx.collateral.claimRewards()).to.emit(ctx.tok, 'RewardsClaimed') + const balAfter = await (ctx.rewardToken as IERC20Metadata).balanceOf( + ctx.collateral.address + ) expect(balAfter).gt(balBefore) }) diff --git a/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts index d17a42f34..7b69960bb 100644 --- a/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts +++ b/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts @@ -12,6 +12,7 @@ import { IStargateLPStaking, StargateRewardableWrapper, StargateRewardableWrapper__factory, + IStargatePool, } from '@typechain/index' import { pushOracleForward } from '../../../utils/oracles' import { bn, fp } from '#/common/numbers' @@ -26,15 +27,18 @@ import { SUSDC, ORACLE_TIMEOUT, ORACLE_ERROR, + STAKING_CONTRACT, + STARGATE_ROUTER, } from './constants' import { noop } from 'lodash' +import { whileImpersonating } from '#/test/utils/impersonation' /* Define interfaces */ interface StargateCollateralFixtureContext extends CollateralFixtureContext { - pool: StargatePoolMock + pool: StargatePoolMock | IStargatePool wpool: StargateRewardableWrapper stargate: ERC20Mock stakingContract: IStargateLPStaking @@ -138,6 +142,7 @@ const deployCollateralStargateMockContext = async ( const StargateRewardableWrapperFactory = ( await ethers.getContractFactory('StargateRewardableWrapper') ) + const stargate = await ( await ethers.getContractFactory('ERC20Mock') ).deploy('Stargate Mocked token', 'S*MT') @@ -150,12 +155,14 @@ const deployCollateralStargateMockContext = async ( await stakingContract.add(bn('5000'), mockPool.address) await mockPool.mint(stakingContract.address, bn(1e6)) await mockPool.setExchangeRate(fp(1)) + const pool = mockPool + const wrapper = await StargateRewardableWrapperFactory.deploy( - 'wMocked Pool', - 'wMSP', + 'Wrapped Stargate USDC TEST', + 'wsgUSDC-TEST', stargate.address, stakingContract.address, - mockPool.address + pool.address ) collateralOpts.erc20 = wrapper.address collateralOpts.rewardERC20 = stargate.address @@ -169,7 +176,7 @@ const deployCollateralStargateMockContext = async ( chainlinkFeed, tok: wrapper, rewardToken, - pool: mockPool, + pool, wpool: wrapper, stargate, stakingContract, @@ -188,13 +195,15 @@ const mintCollateralTo: MintCollateralFunc = a ) => { const currentExchangeRate = await ctx.collateral.refPerTok() - // ctx.stakingContract - + await whileImpersonating(STARGATE_ROUTER, async (router) => { + await ctx.pool.connect(router).mint(user.address, amount) + }) await ctx.pool.connect(user).approve(ctx.wpool.address, ethers.constants.MaxUint256) - await ctx.pool.mint(user.address, amount) await ctx.wpool.connect(user).deposit(amount, user.address) await ctx.wpool.connect(user).transfer(recipient, amount) - await ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + if (ctx.pool.address != SUSDC) { + ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + } } const reduceRefPerTok = async ( @@ -247,6 +256,41 @@ const increaseTargetPerRef = async ( await ctx.chainlinkFeed.updateAnswer(nextAnswer) } +const beforeEachRewardsTest = async (ctx: StargateCollateralFixtureContext) => { + // switch to propoer network rewards setup + + const stargate = await ethers.getContractAt('ERC20Mock', STARGATE) + const stakingContract = ( + await ethers.getContractAt('IStargateLPStaking', STAKING_CONTRACT) + ) + const pool: StargatePoolMock | IStargatePool = await ethers.getContractAt('IStargatePool', SUSDC) + + const StargateRewardableWrapperFactory = ( + await ethers.getContractFactory('StargateRewardableWrapper') + ) + + const wrapper = await StargateRewardableWrapperFactory.deploy( + 'Wrapped Stargate USDC TEST', + 'wsgUSDC-TEST', + stargate.address, + stakingContract.address, + pool.address + ) + const opts = { + erc20: wrapper.address, + rewardERC20: stargate.address, + } + + const collateral = await deployCollateral(opts) + + ctx.collateral = collateral + ctx.pool = pool + ctx.stakingContract = stakingContract + ctx.stargate = stargate + ctx.tok = wrapper + ctx.wpool = wrapper +} + /* Run the test suite */ @@ -255,7 +299,7 @@ export const stableOpts = { deployCollateral, collateralSpecificConstructorTests: noop, collateralSpecificStatusTests: noop, - beforeEachRewardsTest: noop, + beforeEachRewardsTest, makeCollateralFixtureContext, mintCollateralTo, reduceRefPerTok, @@ -264,7 +308,7 @@ export const stableOpts = { collateralName: 'Stargate USDbC Pool', reduceTargetPerRef, increaseTargetPerRef, - itClaimsRewards: it.skip, // reward growth not supported in mock + itClaimsRewards: it, // reward growth not supported in mock itChecksTargetPerRefDefault: it, itChecksRefPerTokDefault: it, itHasRevenueHiding: it, @@ -272,7 +316,7 @@ export const stableOpts = { chainlinkDefaultAnswer: 1e8, itChecksPriceChanges: it, getExpectedPrice, - targetNetwork: 'base' + targetNetwork: 'base', } collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 209506b20..5664b5b14 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -1,21 +1,20 @@ import { bn, fp } from '#/common/numbers' import { networkConfig } from '#/common/configuration' -import hre from 'hardhat' import { useEnv } from '#/utils/env' const forkNetwork = useEnv('FORK_NETWORK') ?? 'mainnet' -let chainId; +let chainId -switch(forkNetwork) { - case 'mainnet': - chainId = '1' - break - case 'base': - chainId = '8453' - break - default: - chainId = '1' - break +switch (forkNetwork) { + case 'mainnet': + chainId = '1' + break + case 'base': + chainId = '8453' + break + default: + chainId = '1' + break } const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' @@ -28,12 +27,16 @@ export const SUSDT = networkConfig[chainId].tokens['sUSDT']! export const SETH = networkConfig[chainId].tokens['sETH']! export const USDC = networkConfig[chainId].tokens[USDC_NAME]! export const USDT = networkConfig[chainId].tokens['USDT']! -export const USDC_HOLDER = chainId == '8453' ? '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' : '0x0a59649758aa4d66e25f08dd01271e891fe52199' +export const USDC_HOLDER = + chainId == '8453' + ? '0x4c80e24119cfb836cdf0a6b53dc23f04f7e652ca' + : '0x0a59649758aa4d66e25f08dd01271e891fe52199' export const USDC_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['USDC']! // currently same key for USDC and USDbC export const ETH_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['ETH']! export const SUSDC_POOL_ID = bn('1') export const WSUSDC_NAME = 'Wrapped S*USDC' export const WSUSDC_SYMBOL = 'wS*USDC' +export const STARGATE_ROUTER = '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' export const USDbC = networkConfig[chainId].tokens['USDbC']! export const SUSDbC = networkConfig[chainId].tokens['sUSDbC']! From 40da1d1fb659d7ac0dbbf2ef00e2af6475e080ae Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Fri, 6 Oct 2023 13:56:58 -0400 Subject: [PATCH 06/12] simplify stargate tests to 1 file. --- .../stargate/interfaces/IStargatePool.sol | 2 + .../stargate/StargateUSDCTestSuite.test.ts | 70 +++- .../stargate/StargateUSDbCTestSuite.test.ts | 322 ------------------ .../stargate/constants.ts | 2 +- 4 files changed, 61 insertions(+), 335 deletions(-) delete mode 100644 test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts diff --git a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol index cc9e29078..22325d519 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol @@ -4,6 +4,8 @@ pragma solidity 0.8.19; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStargatePool is IERC20Metadata { + function router() external view returns (address); + function poolId() external view returns (uint256); function totalLiquidity() external view returns (uint256); diff --git a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts index 9db7362b1..0008ee71e 100644 --- a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts +++ b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts @@ -12,6 +12,7 @@ import { IStargateLPStaking, StargateRewardableWrapper, StargateRewardableWrapper__factory, + IStargatePool, } from '@typechain/index' import { pushOracleForward } from '../../../utils/oracles' import { bn, fp } from '#/common/numbers' @@ -26,15 +27,19 @@ import { SUSDC, ORACLE_TIMEOUT, ORACLE_ERROR, + STAKING_CONTRACT, + STARGATE_ROUTER, } from './constants' import { noop } from 'lodash' +import { whileImpersonating } from '#/test/utils/impersonation' +import { useEnv } from '#/utils/env' /* Define interfaces */ interface StargateCollateralFixtureContext extends CollateralFixtureContext { - pool: StargatePoolMock + pool: StargatePoolMock | IStargatePool wpool: StargateRewardableWrapper stargate: ERC20Mock stakingContract: IStargateLPStaking @@ -138,6 +143,7 @@ const deployCollateralStargateMockContext = async ( const StargateRewardableWrapperFactory = ( await ethers.getContractFactory('StargateRewardableWrapper') ) + const stargate = await ( await ethers.getContractFactory('ERC20Mock') ).deploy('Stargate Mocked token', 'S*MT') @@ -150,12 +156,14 @@ const deployCollateralStargateMockContext = async ( await stakingContract.add(bn('5000'), mockPool.address) await mockPool.mint(stakingContract.address, bn(1e6)) await mockPool.setExchangeRate(fp(1)) + const pool = mockPool + const wrapper = await StargateRewardableWrapperFactory.deploy( - 'wMocked Pool', - 'wMSP', + 'Wrapped Stargate USDC TEST', + 'wsgUSDC-TEST', stargate.address, stakingContract.address, - mockPool.address + pool.address ) collateralOpts.erc20 = wrapper.address collateralOpts.rewardERC20 = stargate.address @@ -169,7 +177,7 @@ const deployCollateralStargateMockContext = async ( chainlinkFeed, tok: wrapper, rewardToken, - pool: mockPool, + pool, wpool: wrapper, stargate, stakingContract, @@ -188,13 +196,15 @@ const mintCollateralTo: MintCollateralFunc = a ) => { const currentExchangeRate = await ctx.collateral.refPerTok() - // ctx.stakingContract - + await whileImpersonating(STARGATE_ROUTER, async (router) => { + await ctx.pool.connect(router).mint(user.address, amount) + }) await ctx.pool.connect(user).approve(ctx.wpool.address, ethers.constants.MaxUint256) - await ctx.pool.mint(user.address, amount) await ctx.wpool.connect(user).deposit(amount, user.address) await ctx.wpool.connect(user).transfer(recipient, amount) - await ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + if (ctx.pool.address != SUSDC) { + ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) + } } const reduceRefPerTok = async ( @@ -247,6 +257,41 @@ const increaseTargetPerRef = async ( await ctx.chainlinkFeed.updateAnswer(nextAnswer) } +const beforeEachRewardsTest = async (ctx: StargateCollateralFixtureContext) => { + // switch to propoer network rewards setup + + const stargate = await ethers.getContractAt('ERC20Mock', STARGATE) + const stakingContract = ( + await ethers.getContractAt('IStargateLPStaking', STAKING_CONTRACT) + ) + const pool: StargatePoolMock | IStargatePool = await ethers.getContractAt('IStargatePool', SUSDC) + + const StargateRewardableWrapperFactory = ( + await ethers.getContractFactory('StargateRewardableWrapper') + ) + + const wrapper = await StargateRewardableWrapperFactory.deploy( + 'Wrapped Stargate USDC TEST', + 'wsgUSDC-TEST', + stargate.address, + stakingContract.address, + pool.address + ) + const opts = { + erc20: wrapper.address, + rewardERC20: stargate.address, + } + + const collateral = await deployCollateral(opts) + + ctx.collateral = collateral + ctx.pool = pool + ctx.stakingContract = stakingContract + ctx.stargate = stargate + ctx.tok = wrapper + ctx.wpool = wrapper +} + /* Run the test suite */ @@ -255,16 +300,16 @@ export const stableOpts = { deployCollateral, collateralSpecificConstructorTests: noop, collateralSpecificStatusTests: noop, - beforeEachRewardsTest: noop, + beforeEachRewardsTest, makeCollateralFixtureContext, mintCollateralTo, reduceRefPerTok, increaseRefPerTok, resetFork, - collateralName: 'Stargate USDC Pool', + collateralName: 'Stargate USDbC Pool', reduceTargetPerRef, increaseTargetPerRef, - itClaimsRewards: it.skip, // reward growth not supported in mock + itClaimsRewards: it, // reward growth not supported in mock itChecksTargetPerRefDefault: it, itChecksRefPerTokDefault: it, itHasRevenueHiding: it, @@ -272,6 +317,7 @@ export const stableOpts = { chainlinkDefaultAnswer: 1e8, itChecksPriceChanges: it, getExpectedPrice, + targetNetwork: useEnv('FORK_NETWORK') ?? 'mainnet', } collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts deleted file mode 100644 index 7b69960bb..000000000 --- a/test/plugins/individual-collateral/stargate/StargateUSDbCTestSuite.test.ts +++ /dev/null @@ -1,322 +0,0 @@ -import collateralTests from '../collateralTests' -import { CollateralFixtureContext, CollateralOpts, MintCollateralFunc } from '../pluginTestTypes' -import { ethers } from 'hardhat' -import { ContractFactory, BigNumberish, BigNumber } from 'ethers' -import { resetFork } from './helpers' -import { - ERC20Mock, - MockV3Aggregator, - MockV3Aggregator__factory, - TestICollateral, - StargatePoolMock, - IStargateLPStaking, - StargateRewardableWrapper, - StargateRewardableWrapper__factory, - IStargatePool, -} from '@typechain/index' -import { pushOracleForward } from '../../../utils/oracles' -import { bn, fp } from '#/common/numbers' -import { expect } from 'chai' -import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' -import { - STARGATE, - USDC_USD_PRICE_FEED, - MAX_TRADE_VOL, - DEFAULT_THRESHOLD, - DELAY_UNTIL_DEFAULT, - SUSDC, - ORACLE_TIMEOUT, - ORACLE_ERROR, - STAKING_CONTRACT, - STARGATE_ROUTER, -} from './constants' -import { noop } from 'lodash' -import { whileImpersonating } from '#/test/utils/impersonation' - -/* - Define interfaces -*/ - -interface StargateCollateralFixtureContext extends CollateralFixtureContext { - pool: StargatePoolMock | IStargatePool - wpool: StargateRewardableWrapper - stargate: ERC20Mock - stakingContract: IStargateLPStaking -} - -export enum CollateralType { - STABLE, - VOLATILE, -} - -export interface StargateCollateralOpts extends CollateralOpts { - type?: CollateralType -} - -/* - Define deployment functions -*/ - -export const defaultStargateCollateralOpts: StargateCollateralOpts = { - erc20: SUSDC, - targetName: ethers.utils.formatBytes32String('USD'), - rewardERC20: STARGATE, - priceTimeout: ORACLE_TIMEOUT, - chainlinkFeed: USDC_USD_PRICE_FEED, - oracleTimeout: ORACLE_TIMEOUT, - oracleError: ORACLE_ERROR, - maxTradeVolume: MAX_TRADE_VOL, - defaultThreshold: DEFAULT_THRESHOLD, - delayUntilDefault: DELAY_UNTIL_DEFAULT, - type: CollateralType.STABLE, - revenueHiding: fp('0'), -} - -export const deployCollateral = async ( - opts: StargateCollateralOpts = {} -): Promise => { - opts = { ...defaultStargateCollateralOpts, ...opts } - - const StargatePoolCollateralFactory: ContractFactory = await ethers.getContractFactory( - opts.type === CollateralType.STABLE ? 'StargatePoolFiatCollateral' : 'StargatePoolETHCollateral' - ) - - const collateral = await StargatePoolCollateralFactory.deploy( - { - erc20: opts.erc20, - targetName: opts.targetName, - priceTimeout: opts.priceTimeout, - chainlinkFeed: opts.chainlinkFeed, - oracleError: opts.oracleError, - oracleTimeout: opts.oracleTimeout, - maxTradeVolume: opts.maxTradeVolume, - defaultThreshold: opts.defaultThreshold, - delayUntilDefault: opts.delayUntilDefault, - }, - opts.revenueHiding, - { gasLimit: 2000000000 } - ) - await collateral.deployed() - - // Push forward chainlink feed - await pushOracleForward(opts.chainlinkFeed!) - - // sometimes we are trying to test a negative test case and we want this to fail silently - // fortunately this syntax fails silently because our tools are terrible - await expect(collateral.refresh()) - - return collateral -} - -type Fixture = () => Promise - -const makeCollateralFixtureContext = ( - alice: SignerWithAddress, - opts: StargateCollateralOpts = {} -): Fixture => { - const collateralOpts = { ...defaultStargateCollateralOpts, ...opts } - - const makeCollateralFixtureContext = async () => { - return deployCollateralStargateMockContext(collateralOpts) - } - - return makeCollateralFixtureContext -} - -const deployCollateralStargateMockContext = async ( - opts: StargateCollateralOpts = {} -): Promise => { - const collateralOpts = { ...defaultStargateCollateralOpts, ...opts } - - const MockV3AggregatorFactory = ( - await ethers.getContractFactory('MockV3Aggregator') - ) - let chainlinkFeed: MockV3Aggregator - if (collateralOpts.type === CollateralType.STABLE) - chainlinkFeed = await MockV3AggregatorFactory.deploy(8, bn('1e8')) - else { - chainlinkFeed = await MockV3AggregatorFactory.deploy(8, bn('1995e8')) - } - collateralOpts.chainlinkFeed = chainlinkFeed.address - - const StargateRewardableWrapperFactory = ( - await ethers.getContractFactory('StargateRewardableWrapper') - ) - - const stargate = await ( - await ethers.getContractFactory('ERC20Mock') - ).deploy('Stargate Mocked token', 'S*MT') - const stakingContract = await ( - await ethers.getContractFactory('StargateLPStakingMock') - ).deploy(stargate.address) - const mockPool = await ( - await ethers.getContractFactory('StargatePoolMock') - ).deploy('Mock Pool', 'MSP', collateralOpts.type === CollateralType.STABLE ? 6 : 8) - await stakingContract.add(bn('5000'), mockPool.address) - await mockPool.mint(stakingContract.address, bn(1e6)) - await mockPool.setExchangeRate(fp(1)) - const pool = mockPool - - const wrapper = await StargateRewardableWrapperFactory.deploy( - 'Wrapped Stargate USDC TEST', - 'wsgUSDC-TEST', - stargate.address, - stakingContract.address, - pool.address - ) - collateralOpts.erc20 = wrapper.address - collateralOpts.rewardERC20 = stargate.address - - const collateral = await deployCollateral(collateralOpts) - - const rewardToken = await ethers.getContractAt('ERC20Mock', STARGATE) - - return { - collateral, - chainlinkFeed, - tok: wrapper, - rewardToken, - pool, - wpool: wrapper, - stargate, - stakingContract, - } -} - -/* - Define helper functions -*/ - -const mintCollateralTo: MintCollateralFunc = async ( - ctx: StargateCollateralFixtureContext, - amount: BigNumberish, - user: SignerWithAddress, - recipient: string -) => { - const currentExchangeRate = await ctx.collateral.refPerTok() - - await whileImpersonating(STARGATE_ROUTER, async (router) => { - await ctx.pool.connect(router).mint(user.address, amount) - }) - await ctx.pool.connect(user).approve(ctx.wpool.address, ethers.constants.MaxUint256) - await ctx.wpool.connect(user).deposit(amount, user.address) - await ctx.wpool.connect(user).transfer(recipient, amount) - if (ctx.pool.address != SUSDC) { - ctx.pool.setExchangeRate(currentExchangeRate.add(fp('0.000001'))) - } -} - -const reduceRefPerTok = async ( - ctx: StargateCollateralFixtureContext, - pctDecrease: BigNumberish -) => { - const currentExchangeRate = await ctx.pool.exchangeRate() - await ctx.pool.setExchangeRate( - currentExchangeRate.sub(currentExchangeRate.mul(pctDecrease).div(100)) - ) -} - -const increaseRefPerTok = async ( - ctx: StargateCollateralFixtureContext, - pctIncrease: BigNumberish -) => { - const currentExchangeRate = await ctx.pool.exchangeRate() - await ctx.pool.setExchangeRate( - currentExchangeRate.add(currentExchangeRate.mul(pctIncrease).div(100)) - ) -} - -const getExpectedPrice = async (ctx: StargateCollateralFixtureContext): Promise => { - const initRefPerTok = await ctx.collateral.refPerTok() - - const decimals = await ctx.chainlinkFeed.decimals() - - const initData = await ctx.chainlinkFeed.latestRoundData() - return initData.answer - .mul(bn(10).pow(18 - decimals)) - .mul(initRefPerTok) - .div(fp('1')) -} - -const reduceTargetPerRef = async ( - ctx: StargateCollateralFixtureContext, - pctDecrease: BigNumberish -) => { - const lastRound = await ctx.chainlinkFeed.latestRoundData() - const nextAnswer = lastRound.answer.sub(lastRound.answer.mul(pctDecrease).div(100)) - await ctx.chainlinkFeed.updateAnswer(nextAnswer) -} - -const increaseTargetPerRef = async ( - ctx: StargateCollateralFixtureContext, - pctIncrease: BigNumberish -) => { - const lastRound = await ctx.chainlinkFeed.latestRoundData() - const nextAnswer = lastRound.answer.add(lastRound.answer.mul(pctIncrease).div(100)) - await ctx.chainlinkFeed.updateAnswer(nextAnswer) -} - -const beforeEachRewardsTest = async (ctx: StargateCollateralFixtureContext) => { - // switch to propoer network rewards setup - - const stargate = await ethers.getContractAt('ERC20Mock', STARGATE) - const stakingContract = ( - await ethers.getContractAt('IStargateLPStaking', STAKING_CONTRACT) - ) - const pool: StargatePoolMock | IStargatePool = await ethers.getContractAt('IStargatePool', SUSDC) - - const StargateRewardableWrapperFactory = ( - await ethers.getContractFactory('StargateRewardableWrapper') - ) - - const wrapper = await StargateRewardableWrapperFactory.deploy( - 'Wrapped Stargate USDC TEST', - 'wsgUSDC-TEST', - stargate.address, - stakingContract.address, - pool.address - ) - const opts = { - erc20: wrapper.address, - rewardERC20: stargate.address, - } - - const collateral = await deployCollateral(opts) - - ctx.collateral = collateral - ctx.pool = pool - ctx.stakingContract = stakingContract - ctx.stargate = stargate - ctx.tok = wrapper - ctx.wpool = wrapper -} - -/* - Run the test suite -*/ - -export const stableOpts = { - deployCollateral, - collateralSpecificConstructorTests: noop, - collateralSpecificStatusTests: noop, - beforeEachRewardsTest, - makeCollateralFixtureContext, - mintCollateralTo, - reduceRefPerTok, - increaseRefPerTok, - resetFork, - collateralName: 'Stargate USDbC Pool', - reduceTargetPerRef, - increaseTargetPerRef, - itClaimsRewards: it, // reward growth not supported in mock - itChecksTargetPerRefDefault: it, - itChecksRefPerTokDefault: it, - itHasRevenueHiding: it, - itIsPricedByPeg: true, - chainlinkDefaultAnswer: 1e8, - itChecksPriceChanges: it, - getExpectedPrice, - targetNetwork: 'base', -} - -collateralTests(stableOpts) diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 5664b5b14..501b11903 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -36,7 +36,7 @@ export const ETH_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['ETH']! export const SUSDC_POOL_ID = bn('1') export const WSUSDC_NAME = 'Wrapped S*USDC' export const WSUSDC_SYMBOL = 'wS*USDC' -export const STARGATE_ROUTER = '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' +export const STARGATE_ROUTER = chainId == '8453' ? '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' : '0x8731d54E9D02c286767d56ac03e8037C07e01e98' export const USDbC = networkConfig[chainId].tokens['USDbC']! export const SUSDbC = networkConfig[chainId].tokens['sUSDbC']! From 2b0f3686fedd875c1f38e0929fbb28e6aa6290c4 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Fri, 6 Oct 2023 13:58:04 -0400 Subject: [PATCH 07/12] linting. --- .../plugins/assets/stargate/interfaces/IStargatePool.sol | 2 +- test/plugins/individual-collateral/stargate/constants.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol index 22325d519..3ddfc9079 100644 --- a/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol +++ b/contracts/plugins/assets/stargate/interfaces/IStargatePool.sol @@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; interface IStargatePool is IERC20Metadata { function router() external view returns (address); - + function poolId() external view returns (uint256); function totalLiquidity() external view returns (uint256); diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 501b11903..18c4fe56c 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -36,7 +36,10 @@ export const ETH_USD_PRICE_FEED = networkConfig[chainId].chainlinkFeeds['ETH']! export const SUSDC_POOL_ID = bn('1') export const WSUSDC_NAME = 'Wrapped S*USDC' export const WSUSDC_SYMBOL = 'wS*USDC' -export const STARGATE_ROUTER = chainId == '8453' ? '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' : '0x8731d54E9D02c286767d56ac03e8037C07e01e98' +export const STARGATE_ROUTER = + chainId == '8453' + ? '0x45f1A95A4D3f3836523F5c83673c797f4d4d263B' + : '0x8731d54E9D02c286767d56ac03e8037C07e01e98' export const USDbC = networkConfig[chainId].tokens['USDbC']! export const SUSDbC = networkConfig[chainId].tokens['sUSDbC']! From de51a25d2ff54e09a1f1204cf292e32972e0bfa0 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Fri, 6 Oct 2023 16:54:17 -0400 Subject: [PATCH 08/12] deploy and verify stargate on base. --- common/configuration.ts | 2 + .../8453-tmp-assets-collateral.json | 8 +- .../deploy_stargate_usdc_collateral.ts | 15 ++- .../verify_stargate_usdbc.ts | 114 ++++++++++++++++++ 4 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 scripts/verification/collateral-plugins/verify_stargate_usdbc.ts diff --git a/common/configuration.ts b/common/configuration.ts index 2941ea62c..6e5f01aef 100644 --- a/common/configuration.ts +++ b/common/configuration.ts @@ -67,6 +67,8 @@ export interface ITokens { sETH?: string MORPHO?: string astETH?: string + sgUSDC?: string + sgUSDbC?: string // Morpho Aave maUSDC?: string diff --git a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json index ec42edd11..36582064e 100644 --- a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json +++ b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json @@ -8,7 +8,8 @@ "USDbC": "0x6490D66B17A1E9a460Ab54131165C8F921aCcDeB", "cbETH": "0x5fE248625aC2AB0e17A115fef288f17AF1952402", "cUSDbCv3": "0xa372EC846131FBf9AE8b589efa3D041D9a94dF41", - "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b" + "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b", + "sgUSDC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -17,6 +18,7 @@ "USDbC": "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA", "cbETH": "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22", "cUSDbCv3": "0xbC0033679AEf41Fb9FeB553Fdf55a8Bb2fC5B29e", - "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b" + "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b", + "sgUSDC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" } -} +} \ No newline at end of file diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index 8d2d939e8..2ca2633f8 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -55,14 +55,17 @@ async function main() { let chainIdKey = useEnv('FORK_NETWORK', 'mainnet') == 'mainnet' ? '1' : '8453' let USDC_NAME = 'USDC' let name = 'Wrapped Stargate USDC' - let symbol = 'wSTG-USDC' + let symbol = 'wsgUSDC' let sUSDC = networkConfig[chainIdKey].tokens.sUSDC + let oracleError = fp('0.0025') if (chainIdKey == '8453') { USDC_NAME = 'USDbC' name = 'Wrapped Stargate USDbC' - symbol = 'wSTG-USDbC' + symbol = 'wsgUSDbC' sUSDC = networkConfig[chainIdKey].tokens.sUSDbC + + oracleError = fp('0.003') } const erc20 = await WrapperFactory.deploy( @@ -87,12 +90,12 @@ async function main() { { priceTimeout: priceTimeout.toString(), chainlinkFeed: networkConfig[chainIdKey].chainlinkFeeds.USDC!, - oracleError: fp('0.0025').toString(), // 0.25%, + oracleError: oracleError.toString(), erc20: erc20.address, maxTradeVolume: fp('1e6').toString(), // $1m, oracleTimeout: oracleTimeout(chainIdKey, '86400').toString(), // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), - defaultThreshold: fp('0.0125').toString(), // 1.25% + defaultThreshold: fp('0.01').add(oracleError).toString(), // 1.3% delayUntilDefault: bn('86400').toString(), // 24h }, revenueHiding.toString() @@ -103,8 +106,8 @@ async function main() { console.log(`Deployed Stargate ${USDC_NAME} to ${hre.network.name} (${chainIdKey}): ${collateral.address}`) - assetCollDeployments.collateral.sUSDC = collateral.address - assetCollDeployments.erc20s.sUSDC = erc20.address + assetCollDeployments.collateral.sgUSDC = collateral.address + assetCollDeployments.erc20s.sgUSDC = erc20.address deployedCollateral.push(collateral.address.toString()) fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) diff --git a/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts b/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts new file mode 100644 index 000000000..315df7960 --- /dev/null +++ b/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts @@ -0,0 +1,114 @@ +import hre from 'hardhat' +import { getChainId } from '../../../common/blockchain-utils' +import { baseL2Chains, developmentChains, networkConfig } from '../../../common/configuration' +import { fp, bn } from '../../../common/numbers' +import { + getDeploymentFile, + getAssetCollDeploymentFilename, + IAssetCollDeployments, +} from '../../deployment/common' +import { priceTimeout, oracleTimeout, verifyContract, combinedError, revenueHiding } from '../../deployment/utils' + +let deployments: IAssetCollDeployments + +async function main() { + // ********** Read config ********** + const chainId = await getChainId(hre) + if (!networkConfig[chainId]) { + throw new Error(`Missing network configuration for ${hre.network.name}`) + } + + if (developmentChains.includes(hre.network.name)) { + throw new Error(`Cannot verify contracts for development chain ${hre.network.name}`) + } + + const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) + deployments = getDeploymentFile(assetCollDeploymentFilename) + + /******** Verify Stargate USDC - sgUSDC **************************/ + + if (!baseL2Chains.includes(hre.network.name)) { + const name = 'Wrapped Stargate USDC' + const symbol = 'wsgUSDC' + const sUSDC = networkConfig[chainId].tokens.sUSDC + + await verifyContract( + chainId, + deployments.erc20s.sgUSDC, + [ + name, + symbol, + networkConfig[chainId].tokens.STG, + networkConfig[chainId].STARGATE_STAKING_CONTRACT, + sUSDC + ], + 'contracts/plugins/assets/stargate/StargateRewardableWrapper.sol:StargateRewardableWrapper' + ) + + const oracleError = fp('0.0025') // 0.25% + + await verifyContract( + chainId, + deployments.collateral.sgUSDC, + [ + { + priceTimeout: priceTimeout.toString(), + chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, + oracleError: oracleError, // 0.25% + erc20: deployments.erc20s.sgUSDC!, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.01').add(oracleError).toString(), // ~2.5% + delayUntilDefault: bn('86400').toString(), // 24h + }, + revenueHiding.toString() + ], + 'contracts/plugins/assets/stargate/StargatePoolFiatCollateral.sol:StargatePoolFiatCollateral' + ) + } else if (chainId == '8453' || chainId == '84531') { + const name = 'Wrapped Stargate USDbC' + const symbol = 'wsgUSDbC' + const sUSDC = networkConfig[chainId].tokens.sUSDbC + + await verifyContract( + chainId, + deployments.erc20s.sgUSDC, + [ + name, + symbol, + networkConfig[chainId].tokens.STG, + networkConfig[chainId].STARGATE_STAKING_CONTRACT, + sUSDC + ], + 'contracts/plugins/assets/stargate/StargateRewardableWrapper.sol:StargateRewardableWrapper' + ) + + const oracleError = fp('0.003') // 0.3% + + await verifyContract( + chainId, + deployments.collateral.sgUSDC, + [ + { + priceTimeout: priceTimeout.toString(), + chainlinkFeed: networkConfig['8453'].chainlinkFeeds.USDC!, + oracleError: oracleError.toString(), + erc20: deployments.erc20s.sgUSDC!, + maxTradeVolume: fp('1e6').toString(), // $1m, + oracleTimeout: oracleTimeout('8453', '86400').toString(), // 24h hr, + targetName: hre.ethers.utils.formatBytes32String('USD'), + defaultThreshold: fp('0.01').add(oracleError).toString(), // ~2.5% + delayUntilDefault: bn('86400').toString(), // 24h + }, + revenueHiding.toString() + ], + 'contracts/plugins/assets/stargate/StargatePoolFiatCollateral.sol:StargatePoolFiatCollateral' + ) + } +} + +main().catch((error) => { + console.error(error) + process.exitCode = 1 +}) From e8a46a4a80bd504ecd9303bc5dce04d681f03c3f Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Mon, 9 Oct 2023 10:25:12 -0400 Subject: [PATCH 09/12] touchups based on comments. --- .../base-3.0.0/8453-tmp-assets-collateral.json | 4 ++-- .../collaterals/deploy_stargate_usdc_collateral.ts | 11 ++++++++--- .../collateral-plugins/verify_stargate_usdbc.ts | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json index 36582064e..fc80d66c1 100644 --- a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json +++ b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json @@ -9,7 +9,7 @@ "cbETH": "0x5fE248625aC2AB0e17A115fef288f17AF1952402", "cUSDbCv3": "0xa372EC846131FBf9AE8b589efa3D041D9a94dF41", "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b", - "sgUSDC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" + "sgUSDbC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -19,6 +19,6 @@ "cbETH": "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22", "cUSDbCv3": "0xbC0033679AEf41Fb9FeB553Fdf55a8Bb2fC5B29e", "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b", - "sgUSDC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" + "sgUSDbC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" } } \ No newline at end of file diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index 2ca2633f8..cdcb95af5 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -95,7 +95,7 @@ async function main() { maxTradeVolume: fp('1e6').toString(), // $1m, oracleTimeout: oracleTimeout(chainIdKey, '86400').toString(), // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), - defaultThreshold: fp('0.01').add(oracleError).toString(), // 1.3% + defaultThreshold: fp('0.01').add(oracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h }, revenueHiding.toString() @@ -106,8 +106,13 @@ async function main() { console.log(`Deployed Stargate ${USDC_NAME} to ${hre.network.name} (${chainIdKey}): ${collateral.address}`) - assetCollDeployments.collateral.sgUSDC = collateral.address - assetCollDeployments.erc20s.sgUSDC = erc20.address + if (chainIdKey == '8453') { + assetCollDeployments.collateral.sgUSDbC = collateral.address + assetCollDeployments.erc20s.sgUSDbC = erc20.address + } else { + assetCollDeployments.collateral.sgUSDC = collateral.address + assetCollDeployments.erc20s.sgUSDC = erc20.address + } deployedCollateral.push(collateral.address.toString()) fs.writeFileSync(assetCollDeploymentFilename, JSON.stringify(assetCollDeployments, null, 2)) diff --git a/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts b/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts index 315df7960..ab5cd17e9 100644 --- a/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts +++ b/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts @@ -59,7 +59,7 @@ async function main() { maxTradeVolume: fp('1e6').toString(), // $1m, oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min targetName: hre.ethers.utils.formatBytes32String('USD'), - defaultThreshold: fp('0.01').add(oracleError).toString(), // ~2.5% + defaultThreshold: fp('0.01').add(oracleError).toString(), delayUntilDefault: bn('86400').toString(), // 24h }, revenueHiding.toString() From b55b5c524ccf6c1a8481fdb344df49621b9ebf84 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Tue, 10 Oct 2023 12:30:33 -0400 Subject: [PATCH 10/12] change verify file name. --- .../{verify_stargate_usdbc.ts => verify_stargate_usdc.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/verification/collateral-plugins/{verify_stargate_usdbc.ts => verify_stargate_usdc.ts} (100%) diff --git a/scripts/verification/collateral-plugins/verify_stargate_usdbc.ts b/scripts/verification/collateral-plugins/verify_stargate_usdc.ts similarity index 100% rename from scripts/verification/collateral-plugins/verify_stargate_usdbc.ts rename to scripts/verification/collateral-plugins/verify_stargate_usdc.ts From 5d6d55af9cbed86af14c05141d9dae4837396c39 Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Wed, 11 Oct 2023 22:55:12 -0400 Subject: [PATCH 11/12] update keynames. --- common/configuration.ts | 4 ++-- .../base-3.0.0/8453-tmp-assets-collateral.json | 4 ++-- .../collaterals/deploy_stargate_usdc_collateral.ts | 8 ++++---- .../collateral-plugins/verify_stargate_usdc.ts | 14 +++++++------- .../stargate/StargateUSDCTestSuite.test.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common/configuration.ts b/common/configuration.ts index 40034e6f4..e6e1f846e 100644 --- a/common/configuration.ts +++ b/common/configuration.ts @@ -67,8 +67,8 @@ export interface ITokens { sETH?: string MORPHO?: string astETH?: string - sgUSDC?: string - sgUSDbC?: string + wsgUSDC?: string + wsgUSDbC?: string // Morpho Aave maUSDC?: string diff --git a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json index fc80d66c1..60168a94a 100644 --- a/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json +++ b/scripts/addresses/base-3.0.0/8453-tmp-assets-collateral.json @@ -9,7 +9,7 @@ "cbETH": "0x5fE248625aC2AB0e17A115fef288f17AF1952402", "cUSDbCv3": "0xa372EC846131FBf9AE8b589efa3D041D9a94dF41", "aBasUSDbC": "0x1DdB7dfdC5D26FE1f2aD02d9972f12481346Ae9b", - "sgUSDbC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" + "wsgUSDbC": "0x15395aCCbF8c6b28671fe41624D599624709a2D6" }, "erc20s": { "COMP": "0x9e1028F5F1D5eDE59748FFceE5532509976840E0", @@ -19,6 +19,6 @@ "cbETH": "0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22", "cUSDbCv3": "0xbC0033679AEf41Fb9FeB553Fdf55a8Bb2fC5B29e", "aBasUSDbC": "0x308447562442Cc43978f8274fA722C9C14BafF8b", - "sgUSDbC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" + "wsgUSDbC": "0x073F98792ef4c00bB5f11B1F64f13cB25Cde0d8D" } } \ No newline at end of file diff --git a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts index cdcb95af5..5db4436ea 100644 --- a/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts +++ b/scripts/deployment/phase2-assets/collaterals/deploy_stargate_usdc_collateral.ts @@ -107,11 +107,11 @@ async function main() { console.log(`Deployed Stargate ${USDC_NAME} to ${hre.network.name} (${chainIdKey}): ${collateral.address}`) if (chainIdKey == '8453') { - assetCollDeployments.collateral.sgUSDbC = collateral.address - assetCollDeployments.erc20s.sgUSDbC = erc20.address + assetCollDeployments.collateral.wsgUSDbC = collateral.address + assetCollDeployments.erc20s.wsgUSDbC = erc20.address } else { - assetCollDeployments.collateral.sgUSDC = collateral.address - assetCollDeployments.erc20s.sgUSDC = erc20.address + assetCollDeployments.collateral.wsgUSDC = collateral.address + assetCollDeployments.erc20s.wsgUSDC = erc20.address } deployedCollateral.push(collateral.address.toString()) diff --git a/scripts/verification/collateral-plugins/verify_stargate_usdc.ts b/scripts/verification/collateral-plugins/verify_stargate_usdc.ts index ab5cd17e9..3973a5ee5 100644 --- a/scripts/verification/collateral-plugins/verify_stargate_usdc.ts +++ b/scripts/verification/collateral-plugins/verify_stargate_usdc.ts @@ -25,7 +25,7 @@ async function main() { const assetCollDeploymentFilename = getAssetCollDeploymentFilename(chainId) deployments = getDeploymentFile(assetCollDeploymentFilename) - /******** Verify Stargate USDC - sgUSDC **************************/ + /******** Verify Stargate USDC - wsgUSDC **************************/ if (!baseL2Chains.includes(hre.network.name)) { const name = 'Wrapped Stargate USDC' @@ -34,7 +34,7 @@ async function main() { await verifyContract( chainId, - deployments.erc20s.sgUSDC, + deployments.erc20s.wsgUSDC, [ name, symbol, @@ -49,13 +49,13 @@ async function main() { await verifyContract( chainId, - deployments.collateral.sgUSDC, + deployments.collateral.wsgUSDC, [ { priceTimeout: priceTimeout.toString(), chainlinkFeed: networkConfig[chainId].chainlinkFeeds.USDC!, oracleError: oracleError, // 0.25% - erc20: deployments.erc20s.sgUSDC!, + erc20: deployments.erc20s.wsgUSDC!, maxTradeVolume: fp('1e6').toString(), // $1m, oracleTimeout: oracleTimeout(chainId, '1200').toString(), // 20 min targetName: hre.ethers.utils.formatBytes32String('USD'), @@ -73,7 +73,7 @@ async function main() { await verifyContract( chainId, - deployments.erc20s.sgUSDC, + deployments.erc20s.wsgUSDbC, [ name, symbol, @@ -88,13 +88,13 @@ async function main() { await verifyContract( chainId, - deployments.collateral.sgUSDC, + deployments.collateral.wsgUSDbC, [ { priceTimeout: priceTimeout.toString(), chainlinkFeed: networkConfig['8453'].chainlinkFeeds.USDC!, oracleError: oracleError.toString(), - erc20: deployments.erc20s.sgUSDC!, + erc20: deployments.erc20s.wsgUSDbC!, maxTradeVolume: fp('1e6').toString(), // $1m, oracleTimeout: oracleTimeout('8453', '86400').toString(), // 24h hr, targetName: hre.ethers.utils.formatBytes32String('USD'), diff --git a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts index 0008ee71e..28f24dc13 100644 --- a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts +++ b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts @@ -160,7 +160,7 @@ const deployCollateralStargateMockContext = async ( const wrapper = await StargateRewardableWrapperFactory.deploy( 'Wrapped Stargate USDC TEST', - 'wsgUSDC-TEST', + 'wsgUSDbC-TEST', stargate.address, stakingContract.address, pool.address @@ -272,7 +272,7 @@ const beforeEachRewardsTest = async (ctx: StargateCollateralFixtureContext) => { const wrapper = await StargateRewardableWrapperFactory.deploy( 'Wrapped Stargate USDC TEST', - 'wsgUSDC-TEST', + 'wsgUSDbC-TEST', stargate.address, stakingContract.address, pool.address From d3d4e8e8259df106aa92d32f1bce0288f000901d Mon Sep 17 00:00:00 2001 From: Patrick McKelvy Date: Wed, 11 Oct 2023 22:59:38 -0400 Subject: [PATCH 12/12] update test name. --- .../stargate/StargateUSDCTestSuite.test.ts | 3 ++- test/plugins/individual-collateral/stargate/constants.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts index 28f24dc13..f09e2d21c 100644 --- a/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts +++ b/test/plugins/individual-collateral/stargate/StargateUSDCTestSuite.test.ts @@ -29,6 +29,7 @@ import { ORACLE_ERROR, STAKING_CONTRACT, STARGATE_ROUTER, + USDC_NAME, } from './constants' import { noop } from 'lodash' import { whileImpersonating } from '#/test/utils/impersonation' @@ -306,7 +307,7 @@ export const stableOpts = { reduceRefPerTok, increaseRefPerTok, resetFork, - collateralName: 'Stargate USDbC Pool', + collateralName: `Stargate ${USDC_NAME} Pool`, reduceTargetPerRef, increaseTargetPerRef, itClaimsRewards: it, // reward growth not supported in mock diff --git a/test/plugins/individual-collateral/stargate/constants.ts b/test/plugins/individual-collateral/stargate/constants.ts index 18c4fe56c..fa88507d3 100644 --- a/test/plugins/individual-collateral/stargate/constants.ts +++ b/test/plugins/individual-collateral/stargate/constants.ts @@ -17,7 +17,7 @@ switch (forkNetwork) { break } -const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' +export const USDC_NAME = chainId == '8453' ? 'USDbC' : 'USDC' const sUSDC_NAME = chainId == '8453' ? 'sUSDbC' : 'sUSDC' export const STARGATE = networkConfig[chainId].tokens['STG']!