@@ -2,6 +2,7 @@ import type { Address } from "viem";
22
33import type { IGearboxSDKPlugin , MarketSuite } from "../../sdk/index.js" ;
44import { AddressMap , BasePlugin } from "../../sdk/index.js" ;
5+ import { MarketConfiguratorContract } from "../../sdk/market/MarketConfiguratorContract.js" ;
56import type { DegenDistributorsStateHuman } from "./types.js" ;
67
78export interface DegenDistributorsPluginState {
@@ -36,15 +37,32 @@ export class DegenDistributorsPlugin
3637 `loading degen distributors for ${ this . sdk . networkType } ` ,
3738 ) ;
3839
39- const distributors = await Promise . allSettled (
40- configurators . map ( cfg => cfg . getPeripheryContract ( "DEGEN_DISTRIBUTOR" ) ) ,
41- ) ;
40+ const distributors =
41+ await MarketConfiguratorContract . getPeripheryContractBatch (
42+ Object . values ( configurators ) ,
43+ this . sdk . client ,
44+ "DEGEN_DISTRIBUTOR" ,
45+ ) ;
4246
4347 const distributorByConfigurator = configurators . reduce <
44- Record < Address , PromiseSettledResult < Address > >
48+ Record <
49+ Address ,
50+ | {
51+ error ?: undefined ;
52+ result : readonly `0x${string } `[ ] ;
53+ status : "success" ;
54+ }
55+ | {
56+ error : Error ;
57+ result ?: undefined ;
58+ status : "failure" ;
59+ }
60+ >
4561 > ( ( acc , cfg , index ) => {
4662 const cfgLC = cfg . address . toLowerCase ( ) as Address ;
47- acc [ cfgLC ] = distributors [ index ] ;
63+ const distributor = distributors [ index ] ;
64+
65+ acc [ cfgLC ] = distributor ;
4866 return acc ;
4967 } , { } ) ;
5068
@@ -55,11 +73,13 @@ export class DegenDistributorsPlugin
5573 const cfgLC = cfg . toLowerCase ( ) as Address ;
5674 const r = distributorByConfigurator ?. [ cfgLC ] ;
5775
58- if ( r . status === "fulfilled" ) {
59- this . #distributors?. upsert ( pool , r . value ) ;
76+ if ( r . status === "success" && r . result . length > 0 ) {
77+ this . #distributors?. upsert ( pool , r . result [ 0 ] ) ;
6078 } else {
6179 this . sdk . logger ?. error (
62- `failed to load degen distributor for market configurator ${ this . labelAddress ( cfg ) } and pool ${ this . labelAddress ( pool ) } : ${ r . reason } ` ,
80+ `failed to load degen distributor for market configurator ${ this . labelAddress (
81+ cfg ,
82+ ) } and pool ${ this . labelAddress ( pool ) } : ${ r . error } `,
6383 ) ;
6484 }
6585 } ) ;
0 commit comments