11import { iPartialLiquidatorAbi } from "@gearbox-protocol/liquidator-v2-contracts/abi" ;
22import type { CreditAccountData } from "@gearbox-protocol/sdk" ;
3- import { ADDRESS_0X0 , AP_ROUTER , formatBN } from "@gearbox-protocol/sdk" ;
3+ import { formatBN , TypedObjectUtils } from "@gearbox-protocol/sdk" ;
44import {
55 calcLiquidatableLTs ,
66 createAnvilClient ,
@@ -9,9 +9,10 @@ import {
99import type { Address , SimulateContractReturnType } from "viem" ;
1010
1111import { exceptionsAbis } from "../../data/index.js" ;
12- import AAVELiquidatorContract from "./AAVELiquidatorContract.js" ;
13- import GHOLiquidatorContract from "./GHOLiquidatorContract.js" ;
14- import type PartialLiquidatorContract from "./PartialLiquidatorContract.js" ;
12+ import {
13+ createPartialLiquidators ,
14+ type IPartialLiquidatorContract ,
15+ } from "./partial/index.js" ;
1516import SingularFullLiquidator from "./SingularFullLiquidator.js" ;
1617import SingularLiquidator from "./SingularLiquidator.js" ;
1718import type {
@@ -20,18 +21,14 @@ import type {
2021 PartialLiquidationPreviewWithFallback ,
2122} from "./types.js" ;
2223
23- // currently there is no reliable way to get this from sdk
24- const LEGACY_PL_BOT : Address = "0x0f06c2bD612Ee7D52d4bC76Ce3BD7E95247AF2a9" ;
25- const NEXO_PL_BOT : Address = "0xc82020f1922AE56CCF25d5F2E2d6155E44583ef9" ;
26-
2724export default class SingularPartialLiquidator extends SingularLiquidator < PartialLiquidationPreviewWithFallback > {
2825 protected readonly name = "partial" ;
2926 protected readonly adverb = "partially" ;
3027
3128 /**
3229 * mapping of credit manager address to deployed partial liquidator
3330 */
34- #liquidatorForCM: Record < Address , PartialLiquidatorContract > = { } ;
31+ #liquidatorForCM: Record < Address , IPartialLiquidatorContract > = { } ;
3532 #fallback?: SingularFullLiquidator ;
3633
3734 public async launch ( asFallback ?: boolean ) : Promise < void > {
@@ -43,84 +40,33 @@ export default class SingularPartialLiquidator extends SingularLiquidator<Partia
4340 await this . #fallback. launch ( true ) ;
4441 }
4542
46- const [ router ] = this . sdk . addressProvider . getLatestVersion ( AP_ROUTER ) ;
47-
48- const aaveLiquidator = new AAVELiquidatorContract (
49- "AAVE Partial Liquidator" ,
50- router ,
51- LEGACY_PL_BOT ,
52- this . config . aavePartialLiquidatorAddress ,
53- ) ;
54- const nexoLiquidator = new AAVELiquidatorContract (
55- "AAVE Nexo Partial Liquidator" ,
56- router ,
57- NEXO_PL_BOT ,
58- this . config . nexoPartialLiquidatorAddress ,
59- ) ;
60- const ghoLiquidator = new GHOLiquidatorContract (
61- router ,
62- LEGACY_PL_BOT ,
63- "GHO" ,
64- ) ;
65- const dolaLiquidator = new GHOLiquidatorContract (
66- router ,
67- LEGACY_PL_BOT ,
68- "DOLA" ,
69- ) ;
70- // safe to use 0x0 because none of underlyings is 0x0, so no cms will be added
71- const GHO =
72- this . creditAccountService . sdk . tokensMeta . findBySymbol ( "GHO" ) ?. addr ??
73- ADDRESS_0X0 ;
74- const DOLA =
75- this . creditAccountService . sdk . tokensMeta . findBySymbol ( "DOLA" ) ?. addr ??
76- ADDRESS_0X0 ;
77-
78- for ( const cm of this . sdk . marketRegister . creditManagers ) {
79- switch ( cm . underlying ) {
80- case GHO : {
81- ghoLiquidator . addCreditManager ( cm ) ;
82- this . #liquidatorForCM[ cm . creditManager . address ] = ghoLiquidator ;
83- break ;
84- }
85- case DOLA : {
86- dolaLiquidator . addCreditManager ( cm ) ;
87- this . #liquidatorForCM[ cm . creditManager . address ] = dolaLiquidator ;
88- break ;
89- }
90- default : {
91- // identifying nexo (aka k3) credit managers
92- if ( cm . name . toLowerCase ( ) . includes ( "k3" ) ) {
93- nexoLiquidator . addCreditManager ( cm ) ;
94- this . #liquidatorForCM[ cm . creditManager . address ] = nexoLiquidator ;
95- } else {
96- aaveLiquidator . addCreditManager ( cm ) ;
97- this . #liquidatorForCM[ cm . creditManager . address ] = aaveLiquidator ;
98- }
99- }
100- }
43+ this . #liquidatorForCM = createPartialLiquidators ( this . sdk ) ;
44+ const contracts = new Set < IPartialLiquidatorContract > ( ) ;
45+ for ( const [ cm , contract ] of TypedObjectUtils . entries (
46+ this . #liquidatorForCM,
47+ ) ) {
48+ this . logger . debug (
49+ `Will use ${ contract . name } for ${ this . sdk . provider . addressLabels . get ( cm ) } ` ,
50+ ) ;
51+ contracts . add ( contract ) ;
10152 }
102-
53+ this . logger . debug (
54+ `Need to deploy ${ contracts . size } partial liquidator contracts: ${ Array . from (
55+ contracts ,
56+ )
57+ . map ( c => c . name )
58+ . join ( ", " ) } `,
59+ ) ;
10360 let expectedEnv : Record < string , string > = { } ;
104- for ( const contract of [
105- aaveLiquidator ,
106- nexoLiquidator ,
107- ghoLiquidator ,
108- dolaLiquidator ,
109- ] ) {
110- if ( ! contract . isSupported ) {
111- this . logger . info (
112- `${ contract . name } is not supported on ${ this . config . network } ` ,
113- ) ;
114- continue ;
115- }
61+ for ( const contract of contracts ) {
11662 await contract . deploy ( ) ;
11763 await contract . configure ( ) ;
11864 expectedEnv = {
11965 ...expectedEnv ,
120- ...Object . fromEntries ( [ contract . envVariable ] ) ,
66+ ...contract . envVariables ,
12167 } ;
12268 }
123- this . logger . info ( expectedEnv , "expected env" ) ;
69+ this . logger . debug ( expectedEnv , "expected env" ) ;
12470 }
12571
12672 public async makeLiquidatable (
0 commit comments