Skip to content

Commit

Permalink
Fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinNagpal committed Feb 21, 2025
1 parent f0592bc commit 42b615b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 46 deletions.
24 changes: 11 additions & 13 deletions scenario/RewardsScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isRewardSupported, matchesDeployment } from './utils';
import { Contract, ContractReceipt } from 'ethers';
import { CometRewards, ERC20__factory } from '../build/types';
import {World} from '../plugins/scenario';
import { getConfigForScenario } from './utils/scenarioHelper';

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

const { rescaleFactor } = await context.getRewardConfig();
const rewardToken = await context.getRewardToken();
Expand Down Expand Up @@ -260,12 +263,7 @@ async function testScalingReward(properties: CometProperties, context: CometCont
[albert.address]
);
await newRewards.connect(albert.signer).setRewardConfigWithMultiplier(comet.address, rewardTokenAddress, multiplier);
await context.sourceTokens(
world.base.network === 'scroll' ? 100000 : exp(1_000, rewardDecimals), // conditional check for scroll network: maximum amount which can be sourced from transaction logs on scroll
rewardTokenAddress, // CometAsset
newRewards.address, // Recipient's address
world.base.network === 'scroll' ? 2751700 : undefined // conditional check for scroll network: Block number to start searching for transfer event on scroll
);
await context.sourceTokens(exp(1_000, rewardDecimals), rewardTokenAddress, newRewards.address);

await baseAsset.approve(albert, comet.address);
await albert.safeSupplyAsset({ asset: baseAssetAddress, amount: 100n * baseScale });
Expand Down Expand Up @@ -305,4 +303,4 @@ async function testScalingReward(properties: CometProperties, context: CometCont
expect(newRewardsOwedAfter).to.be.equal(0n);

return txn; // return txn to measure gas
}
}
8 changes: 4 additions & 4 deletions scenario/constraints/MigrationConstraint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StaticConstraint, Solution, World, debug } from '../../plugins/scenario';
import { CometContext, MigrationData } from '../context/CometContext';
import { Migration, loadMigrations, Actions } from '../../plugins/deployment_manager/Migration';
import { modifiedPaths, subsets } from '../utils';
import { modifiedPaths } from '../utils';
import { DeploymentManager } from '../../plugins/deployment_manager';
import { impersonateAddress } from '../../plugins/scenario/utils';
import { exp } from '../../test/helpers';
Expand All @@ -22,7 +22,7 @@ export class MigrationConstraint<T extends CometContext> implements StaticConstr
async solve(world: World) {
const label = `[${world.base.name}] {MigrationConstraint}`;
const solutions: Solution<T>[] = [];
const migrationPaths = [...subsets(await getMigrations(world))];
const migrationPaths = [await getMigrations(world)];

for (const migrationList of migrationPaths) {
if (migrationList.length == 0 && migrationPaths.length > 1) {
Expand All @@ -48,7 +48,7 @@ export class MigrationConstraint<T extends CometContext> implements StaticConstr
for (const migrationData of migrations) {
const migration = migrationData.migration;
const artifact = await migration.actions.prepare(ctx.world.deploymentManager, govDeploymentManager);
debug(`${label} Prepared migration ${migration.name}.\n for network ${govDeploymentManager.network} Artifact\n-------\n\n${JSON.stringify(artifact, null, 2)}\n-------\n`);
debug(`${label} Prepared migration ${migration.name}.\n Artifact\n-------\n\n${JSON.stringify(artifact, null, 2)}\n-------\n`);
if (await isEnacted(migration.actions, ctx.world.deploymentManager, govDeploymentManager)) {
migrationData.skipVerify = true;
debug(`${label} Migration ${migration.name} has already been enacted`);
Expand All @@ -61,7 +61,7 @@ export class MigrationConstraint<T extends CometContext> implements StaticConstr
if (lastProposalAfter > lastProposalBefore) {
migrationData.lastProposal = lastProposalAfter.toNumber();
}
debug(`${label} Enacted migration ${migration.name} on network ${govDeploymentManager.network}`);
debug(`${label} Enacted migration ${migration.name}`);
}
}

Expand Down
36 changes: 23 additions & 13 deletions scenario/constraints/ProposalConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { IGovernorBravo, ProposalState, OpenProposal } from '../context/Gov';
import { CometContext } from '../context/CometContext';
import { fetchLogs } from '../utils';
import { DeploymentManager } from '../../plugins/deployment_manager';
import { isBridgedDeployment, executeOpenProposal, executeOpenProposalAndRelay } from '../utils';
import { isBridgedDeployment, executeOpenProposal, voteForOpenProposal, executeOpenProposalAndRelay } from '../utils';
import { getOpenBridgedProposals, executeBridgedProposal } from '../utils/bridgeProposal';

async function getOpenProposals(deploymentManager: DeploymentManager, governor: IGovernorBravo): Promise<OpenProposal[]> {
export async function getOpenProposals(deploymentManager: DeploymentManager, governor: IGovernorBravo): Promise<OpenProposal[]> {
const timelockBuf = 30000; // XXX this should be timelock.delay + timelock.GRACE_PERIOD
const votingDelay = (await governor.votingDelay()).toNumber();
const votingPeriod = (await governor.votingPeriod()).toNumber();
Expand All @@ -18,15 +18,26 @@ async function getOpenProposals(deploymentManager: DeploymentManager, governor:
if (logs) {
for (let log of logs) {
if (log.args === undefined) continue;
const [id, , , , , , startBlock, endBlock] = log.args;
const [id, proposer, targets, values, signatures, calldatas, startBlock, endBlock] = log.args;
const state = await governor.state(id);
if ([
ProposalState.Pending,
ProposalState.Active,
ProposalState.Succeeded,
ProposalState.Queued,
].includes(state)) {
proposals.push({ id, startBlock, endBlock });
proposals.push(
{
id,
proposer,
targets,
values,
signatures,
calldatas,
startBlock,
endBlock
}
);
}
}
}
Expand All @@ -53,6 +64,11 @@ export class ProposalConstraint<T extends CometContext> implements StaticConstra
const governanceDeploymentManager = ctx.world.auxiliaryDeploymentManager || deploymentManager;
const governor = await governanceDeploymentManager.contract('governor') as IGovernorBravo;
const proposals = await getOpenProposals(governanceDeploymentManager, governor);

for (const proposal of proposals) {
await voteForOpenProposal(governanceDeploymentManager, proposal);
}

for (const proposal of proposals) {
const preExecutionBlockNumber = await ctx.world.deploymentManager.hre.ethers.provider.getBlockNumber();
let migrationData;
Expand All @@ -62,15 +78,9 @@ export class ProposalConstraint<T extends CometContext> implements StaticConstra
);
}

// temporary hack to skip proposal 353
if (proposal.id.eq(353)) {
console.log('Skipping proposal 353');
continue;
}

// temporary hack to skip proposal 353
if (proposal.id.eq(353)) {
console.log('Skipping proposal 353');
// temporary hack to skip proposal 393
if (proposal.id.eq(393)) {
console.log('Skipping proposal 393');
continue;
}

Expand Down
30 changes: 14 additions & 16 deletions scenario/constraints/UtilizationConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ import { expect } from 'chai';
import { Requirements } from './Requirements';

/**
# Utilization Constraint
# Utilization Constraint
This constraint is used to constrain the utilization rate, by adjust the total
supply and/or borrows of Comet.
This constraint is used to constrain the utilization rate, by adjust the total
supply and/or borrows of Comet.
## Configuration
## Configuration
**requirements**: `{ utilization: number }`
**requirements**: `{ utilization: number }`
If passed in, the constraint will ensure that the utilization of the protocol
is exactly the given value. If this constraint cannot be fulfilled, we will
throw an error, rather than return "no solutions."
If passed in, the constraint will ensure that the utilization of the protocol
is exactly the given value. If this constraint cannot be fulfilled, we will
throw an error, rather than return "no solutions."
* Example: `{ utilization: 0.5 }` to target 50% utilization (borrows / supply).
* Note: if utilization is passed as 0, this will target either borrows=0 or supply=0
**/
* Example: `{ utilization: 0.5 }` to target 50% utilization (borrows / supply).
* Note: if utilization is passed as 0, this will target either borrows=0 or supply=0
**/

interface UtilizationConfig {
utilization?: number;
Expand Down Expand Up @@ -58,6 +58,8 @@ export class UtilizationConstraint<T extends CometContext, R extends Requirement
// utilization is target number
return async (context: T): Promise<T> => {
let comet = await context.getComet();
const baseScale = (await comet.baseScale()).toBigInt();
const basePrice = (await comet.getPrice(await comet.baseTokenPriceFeed())).toBigInt();

let baseToken = context.getAssetByAddress(await comet.baseToken());
let utilizationFactor = factor(utilization!);
Expand All @@ -66,7 +68,7 @@ export class UtilizationConstraint<T extends CometContext, R extends Requirement

// always have at least enough supply to cover current borrows
let toBorrowBase = 0n;
let toSupplyBase = totalBorrowBase <= totalSupplyBase ? 10n : totalBorrowBase - totalSupplyBase;
let toSupplyBase = totalBorrowBase <= totalSupplyBase ? 10n * baseScale : totalBorrowBase - totalSupplyBase;

let expectedSupplyBase = totalSupplyBase + toSupplyBase;
let expectedBorrowBase = utilizationFactor * expectedSupplyBase / factorScale;
Expand Down Expand Up @@ -111,11 +113,7 @@ export class UtilizationConstraint<T extends CometContext, R extends Requirement
const { asset: collateralAsset, borrowCollateralFactor, priceFeed, scale } = await comet.getAssetInfo(i);

const collateralToken = context.getAssetByAddress(collateralAsset);

const basePrice = (await comet.getPrice(await comet.baseTokenPriceFeed())).toBigInt();
const collateralPrice = (await comet.getPrice(priceFeed)).toBigInt();

const baseScale = (await comet.baseScale()).toBigInt();
const collateralScale = scale.toBigInt();

const collateralWeiPerUnitBase = (collateralScale * basePrice) / collateralPrice;
Expand Down

0 comments on commit 42b615b

Please sign in to comment.