Skip to content

Commit

Permalink
Make getAssetIndex public, fix bumpSupplyCaps (compound-finance#533)
Browse files Browse the repository at this point in the history
This makes a contract change to configurator, to make `getAssetIndex` public.
It was useful to be able to call this directly when trying to debug these  issues and I think it ought to be public.

Somehow the upgrade path in bumpSupplyCaps was completely broken and had never been used (at least since adding the per-market configuration).
This fixes the call to updateSupplyCap and bypasses governance for this constraint helper to speed it up.

Also remove some whales, since we are voting with all of them and its unnecessary.
  • Loading branch information
jflatow authored Aug 12, 2022
1 parent db74e0f commit a60dba1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion contracts/Configurator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ contract Configurator is ConfiguratorStorage {
/**
* @dev Determine index of asset that matches given address
*/
function getAssetIndex(address cometProxy, address asset) internal view returns (uint) {
function getAssetIndex(address cometProxy, address asset) public view returns (uint) {
AssetConfig[] memory assetConfigs = configuratorParams[cometProxy].assetConfigs;
uint numAssets = assetConfigs.length;
for (uint i = 0; i < numAssets; ) {
Expand Down
31 changes: 9 additions & 22 deletions scenario/context/CometContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,12 @@ export class CometContext {

async bumpSupplyCaps(supplyAmountPerAsset: Record<string, bigint>) {
const comet = await this.getComet();
const configurator = await this.getConfigurator();
const proxyAdmin = await this.getCometAdmin();

// Update supply cap in asset configs if new collateral supply will exceed the supply cap
let shouldUpgrade = false;
const newSupplyCaps: Record<string, bigint> = {};
for (const asset in supplyAmountPerAsset) {
let assetInfo: AssetInfoStructOutput;
try {
assetInfo = await comet.getAssetInfoByAddress(asset);
} catch (e) {
continue; // skip if asset is not a collateral asset
}

const assetInfo = await comet.getAssetInfoByAddress(asset);
const currentTotalSupply = (await comet.totalsCollateral(asset)).totalSupplyAsset.toBigInt();
const newTotalSupply = currentTotalSupply + supplyAmountPerAsset[asset];
if (newTotalSupply > assetInfo.supplyCap.toBigInt()) {
Expand All @@ -138,18 +130,13 @@ export class CometContext {

// Set new supply caps in Configurator and do a deployAndUpgradeTo
if (shouldUpgrade) {
const [targets, values, signatures, calldata] = [[], [], [], []];
for (const asset in newSupplyCaps) {
targets.push(configurator.address);
values.push(0);
signatures.push('updateAssetSupplyCap(address,uint128)');
calldata.push(utils.defaultAbiCoder.encode(['address', 'uint128'], [asset, newSupplyCaps[asset]]))
const gov = await this.world.impersonateAddress(await comet.governor(), 10n**18n);
const cometAdmin = (await this.getCometAdmin()).connect(gov);
const configurator = (await this.getConfigurator()).connect(gov);
for (const [asset, cap] of Object.entries(newSupplyCaps)) {
await configurator.updateAssetSupplyCap(comet.address, asset, cap);
}
targets.push(proxyAdmin.address);
values.push(0);
signatures.push('deployAndUpgradeTo(address,address)');
calldata.push(utils.defaultAbiCoder.encode(['address', 'address'], [configurator.address, comet.address]));
await this.fastGovernanceExecute(targets, values, signatures, calldata);
await cometAdmin.deployAndUpgradeTo(configurator.address, comet.address);
}
}

Expand Down Expand Up @@ -272,9 +259,9 @@ export class CometContext {
const queueEvent = queueTxn.events?.find(event => event.event === 'ProposalQueued');
await this.setNextBlockTimestamp(queueEvent?.args?.eta.toNumber() + 1);

// Execute proposal
// Execute proposal (w/ gas limit so we see if exec reverts, not a gas estimation error)
await this.setNextBaseFeeToZero();
await governor.execute(proposalId, { gasPrice: 0 });
await governor.execute(proposalId, { gasPrice: 0, gasLimit: 12000000 });
}

// Instantly executes some actions through the governance proposal process
Expand Down
3 changes: 0 additions & 3 deletions src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ export const COMP_WHALES = [
'0x61258f12c459984f32b83c86a6cc10aa339396de',
'0x9aa835bc7b8ce13b9b0c9764a52fbf71ac62ccf1',
'0x683a4f9915d6216f73d6df50151725036bd26c02',
'0xa1b61405791170833070c0ea61ed28728a840241',
'0x88fb3d509fc49b515bfeb04e23f53ba339563981',
'0x8169522c2c57883e8ef80c498aab7820da539806'
];

export async function calldata(req: Promise<PopulatedTransaction>): Promise<string> {
Expand Down

0 comments on commit a60dba1

Please sign in to comment.