Skip to content

Commit b8cb32b

Browse files
authored
Merge pull request #415 from Gearbox-protocol/loss-policy-decode
fix: decode loss policy actions
2 parents 334a709 + 74ac4cb commit b8cb32b

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { Hex } from "viem";
2+
import { iLossPolicyV310Abi } from "../../../abi/310/generated.js";
3+
import { AbstractFactory } from "./abstract-factory.js";
4+
5+
const abi = iLossPolicyV310Abi;
6+
7+
export enum AccessMode {
8+
Permissionless = 0,
9+
Permissioned = 1,
10+
Forbidden = 2,
11+
}
12+
13+
export class LossPolicyFactory extends AbstractFactory<typeof abi> {
14+
constructor() {
15+
super(abi);
16+
}
17+
18+
setAccessMode(args: { accessMode: AccessMode }): Hex {
19+
return this.createCallData({
20+
functionName: "setAccessMode",
21+
args: [args.accessMode],
22+
});
23+
}
24+
25+
setChecksEnabled(args: { enabled: boolean }): Hex {
26+
return this.createCallData({
27+
functionName: "setChecksEnabled",
28+
args: [args.enabled],
29+
});
30+
}
31+
}

src/permissionless/bindings/market-configurator.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
import { handleSalt } from "../utils/create2.js";
3636
import { convertPercent } from "../utils/index.js";
3737
import { CreditFactory } from "./factory/credit-factory.js";
38+
import { LossPolicyFactory } from "./factory/loss-policy-factory.js";
3839
import { PoolFactory } from "./factory/pool-factory.js";
3940
import { PriceOracleFactory } from "./factory/price-oracle-factory.js";
4041
import { AddressProviderContract, BaseContract } from "./index.js";
@@ -60,12 +61,14 @@ export class MarketConfiguratorContract extends BaseContract<typeof abi> {
6061
public readonly creditFactory: CreditFactory;
6162
public readonly poolFactory: PoolFactory;
6263
public readonly priceOracleFactory: PriceOracleFactory;
64+
public readonly lossPolicyFactory: LossPolicyFactory;
6365

6466
constructor(address: Address, client: PublicClient) {
6567
super(abi, address, client, "MarketConfigurator");
6668
this.creditFactory = new CreditFactory();
6769
this.poolFactory = new PoolFactory();
6870
this.priceOracleFactory = new PriceOracleFactory();
71+
this.lossPolicyFactory = new LossPolicyFactory();
6972
}
7073

7174
async getAddressProvider(): Promise<AddressProviderContract> {
@@ -540,6 +543,8 @@ export class MarketConfiguratorContract extends BaseContract<typeof abi> {
540543
treasury: Address;
541544
pausableAdmins: Address[];
542545
unpausableAdmins: Address[];
546+
lossLiquidators: Address[];
547+
emergencyLiquidators: Address[];
543548
}> {
544549
const [admin, emergencyAdmin, treasury, acl] = await Promise.all([
545550
this.contract.read.admin(),
@@ -567,6 +572,22 @@ export class MarketConfiguratorContract extends BaseContract<typeof abi> {
567572
functionName: "getRoleHolders",
568573
args: [stringToHex("UNPAUSABLE_ADMIN", { size: 32 })],
569574
},
575+
{
576+
address: acl,
577+
abi: parseAbi([
578+
"function getRoleHolders(bytes32) view returns (address[])",
579+
]),
580+
functionName: "getRoleHolders",
581+
args: [stringToHex("LOSS_LIQUIDATOR", { size: 32 })],
582+
},
583+
{
584+
address: acl,
585+
abi: parseAbi([
586+
"function getRoleHolders(bytes32) view returns (address[])",
587+
]),
588+
functionName: "getRoleHolders",
589+
args: [stringToHex("EMERGENCY_LIQUIDATOR", { size: 32 })],
590+
},
570591
],
571592
});
572593

@@ -576,6 +597,8 @@ export class MarketConfiguratorContract extends BaseContract<typeof abi> {
576597
treasury,
577598
pausableAdmins: [...results[0]],
578599
unpausableAdmins: [...results[1]],
600+
lossLiquidators: [...results[2]],
601+
emergencyLiquidators: [...results[3]],
579602
};
580603
}
581604

@@ -917,6 +940,32 @@ export class MarketConfiguratorContract extends BaseContract<typeof abi> {
917940
},
918941
};
919942
}
943+
case "configureLossPolicy": {
944+
const [pool, calldata] = args as [Address, Hex];
945+
const decoded = this.lossPolicyFactory.decodeConfig(calldata);
946+
if (decoded) {
947+
return {
948+
chainId: 0,
949+
target: this.address,
950+
label: this.name,
951+
functionName,
952+
args: {
953+
pool,
954+
data: json_stringify(decoded),
955+
},
956+
};
957+
}
958+
return {
959+
chainId: 0,
960+
target: this.address,
961+
label: this.name,
962+
functionName,
963+
args: {
964+
pool,
965+
calldata,
966+
},
967+
};
968+
}
920969

921970
case "updateInterestRateModel": {
922971
const [pool, deployParams] = args as [Address, DeployParams];

0 commit comments

Comments
 (0)