Skip to content

Commit

Permalink
refactor: moved repetitive code into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Debugger022 committed Sep 25, 2023
1 parent 1fa8eec commit efe8c4a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ function matchValues(array1: string[], array2: string[]) {
}
}

async function verifyAccessControlPermissions(
accessControlManager: ethers.Contract,
comptrollerTronSigner: ethers.Signer,
values: string[],
) {
const returnValues = [];
for (let i = 0; i < values.length; i++) {
returnValues.push(
await accessControlManager
.connect(comptrollerTronSigner)
.isAllowedToCall(values[i], "_setForcedLiquidation(address,bool)"),
);
}
return returnValues;
}

forking(33504900, () => {
const provider = ethers.provider;
let comptrollerBeacon: ethers.Contract;
Expand Down Expand Up @@ -71,6 +87,8 @@ forking(33504900, () => {
});

describe("Post-VIP behavior", () => {
const timeLockArray: string[] = [NORMAL_TIMELOCK, FAST_TRACK_TIMELOCK, CRITICAL_TIMELOCK];
const boolArray: bool[] = [true, true, true];
let accessControlManager: ethers.Contract;
let comptrollerStableCoinSigner: ethers.Signer;
let comptrollerDefiSigner: ethers.Signer;
Expand Down Expand Up @@ -112,93 +130,38 @@ forking(33504900, () => {
});

it("Pool StableCoin permissions", async () => {
expect(
await accessControlManager
.connect(comptrollerStableCoinSigner)
.isAllowedToCall(CRITICAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerStableCoinSigner)
.isAllowedToCall(FAST_TRACK_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerStableCoinSigner)
.isAllowedToCall(NORMAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
matchValues(
boolArray,
await verifyAccessControlPermissions(accessControlManager, comptrollerStableCoinSigner, timeLockArray),
);
});

it("Pool Defi permissions", async () => {
expect(
await accessControlManager
.connect(comptrollerDefiSigner)
.isAllowedToCall(CRITICAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerDefiSigner)
.isAllowedToCall(FAST_TRACK_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerDefiSigner)
.isAllowedToCall(NORMAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
matchValues(
boolArray,
await verifyAccessControlPermissions(accessControlManager, comptrollerDefiSigner, timeLockArray),
);
});

it("Pool GameFi permissions", async () => {
expect(
await accessControlManager
.connect(comptrollerGameFiSigner)
.isAllowedToCall(CRITICAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerGameFiSigner)
.isAllowedToCall(FAST_TRACK_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerGameFiSigner)
.isAllowedToCall(NORMAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
matchValues(
boolArray,
await verifyAccessControlPermissions(accessControlManager, comptrollerGameFiSigner, timeLockArray),
);
});

it("Pool Liquied Staked Bnb permissions", async () => {
expect(
await accessControlManager
.connect(comptrollerLiquidStakedBnbSigner)
.isAllowedToCall(CRITICAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerLiquidStakedBnbSigner)
.isAllowedToCall(FAST_TRACK_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerLiquidStakedBnbSigner)
.isAllowedToCall(NORMAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
matchValues(
boolArray,
await verifyAccessControlPermissions(accessControlManager, comptrollerLiquidStakedBnbSigner, timeLockArray),
);
});

it("Pool Tron permissions", async () => {
expect(
await accessControlManager
.connect(comptrollerTronSigner)
.isAllowedToCall(CRITICAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerTronSigner)
.isAllowedToCall(FAST_TRACK_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
expect(
await accessControlManager
.connect(comptrollerTronSigner)
.isAllowedToCall(NORMAL_TIMELOCK, "_setForcedLiquidation(address,bool)"),
).equals(true);
matchValues(
boolArray,
await verifyAccessControlPermissions(accessControlManager, comptrollerTronSigner, timeLockArray),
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ const FAST_TRACK_TIMELOCK = "0x3CFf21b7AF8390fE68799D58727d3b4C25a83cb6";
const CRITICAL_TIMELOCK = "0x23B893a7C45a5Eb8c8C062b9F32d0D2e43eD286D";
const NORMAL_TIMELOCK = "0xce10739590001705F7FF231611ba4A48B2820327";

interface GrantAccess {
target: string;
signature: string;
params: Array<string>;
}

const grantAccessControl = (contract: string) => {
const accessProposals: Array<GrantAccess> = [];
[NORMAL_TIMELOCK, FAST_TRACK_TIMELOCK, CRITICAL_TIMELOCK].map(target => {
accessProposals.push({
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [contract, "_setForcedLiquidation(address,bool)", target],
});
});

return accessProposals;
};

export const vipComptrollerBeaconUpgradeTestnet = () => {
const meta = {
version: "v2",
Expand All @@ -33,96 +52,11 @@ export const vipComptrollerBeaconUpgradeTestnet = () => {
signature: "upgradeTo(address)",
params: [NEW_COMPTROLLER_IMPLEMENTATION],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_STABLECOIN, "_setForcedLiquidation(address,bool)", NORMAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_STABLECOIN, "_setForcedLiquidation(address,bool)", FAST_TRACK_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_STABLECOIN, "_setForcedLiquidation(address,bool)", CRITICAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_DEFI, "_setForcedLiquidation(address,bool)", NORMAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_DEFI, "_setForcedLiquidation(address,bool)", FAST_TRACK_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_DEFI, "_setForcedLiquidation(address,bool)", CRITICAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_GAMEFI, "_setForcedLiquidation(address,bool)", NORMAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_GAMEFI, "_setForcedLiquidation(address,bool)", FAST_TRACK_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_GAMEFI, "_setForcedLiquidation(address,bool)", CRITICAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_LIQUID_STAKED_BNB, "_setForcedLiquidation(address,bool)", NORMAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_LIQUID_STAKED_BNB, "_setForcedLiquidation(address,bool)", FAST_TRACK_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_LIQUID_STAKED_BNB, "_setForcedLiquidation(address,bool)", CRITICAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_TRON, "_setForcedLiquidation(address,bool)", NORMAL_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_TRON, "_setForcedLiquidation(address,bool)", FAST_TRACK_TIMELOCK],
},

{
target: ACM,
signature: "giveCallPermission(address,string,address)",
params: [POOL_TRON, "_setForcedLiquidation(address,bool)", CRITICAL_TIMELOCK],
},
...grantAccessControl(POOL_STABLECOIN),
...grantAccessControl(POOL_DEFI),
...grantAccessControl(POOL_GAMEFI),
...grantAccessControl(POOL_LIQUID_STAKED_BNB),
...grantAccessControl(POOL_TRON),
],
meta,
ProposalType.REGULAR,
Expand Down

0 comments on commit efe8c4a

Please sign in to comment.