1
- import { type DottedKeys , entries } from "@morpho-org/morpho-ts" ;
2
-
1
+ import {
2
+ type DeepPartial ,
3
+ type DottedKeys ,
4
+ entries ,
5
+ } from "@morpho-org/morpho-ts" ;
6
+ import isPlainObject from "lodash/isPlainObject" ;
7
+ import mergeWith from "lodash/mergeWith" ;
3
8
import { ChainId } from "./chain.js" ;
4
9
import { UnsupportedChainIdError } from "./errors.js" ;
5
10
import type { Address } from "./types.js" ;
@@ -54,7 +59,7 @@ export interface ChainAddresses {
54
59
wstEth ?: Address ;
55
60
}
56
61
57
- export const addressesRegistry = {
62
+ const _addressesRegistry = {
58
63
[ ChainId . EthMainnet ] : {
59
64
morpho : "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb" ,
60
65
permit2 : "0x000000000022D473030F116dDEE9F6B43aC78BA3" ,
@@ -363,9 +368,9 @@ export const addressesRegistry = {
363
368
} ,
364
369
} as const ;
365
370
366
- export const addresses = addressesRegistry as Record < number , ChainAddresses > ;
371
+ export const addresses = _addressesRegistry as Record < number , ChainAddresses > ;
367
372
368
- export type AddressLabel = DottedKeys < ( typeof addressesRegistry ) [ ChainId ] > ;
373
+ export type AddressLabel = DottedKeys < ( typeof _addressesRegistry ) [ ChainId ] > ;
369
374
370
375
export const getChainAddresses = ( chainId : number ) : ChainAddresses => {
371
376
const chainAddresses = addresses [ chainId ] ;
@@ -383,33 +388,34 @@ export const unwrappedTokensMapping: Record<
383
388
Record < Address , Address >
384
389
> = {
385
390
[ ChainId . EthMainnet ] : {
386
- [ addressesRegistry [ ChainId . EthMainnet ] . wbIB01 ] :
387
- addressesRegistry [ ChainId . EthMainnet ] . bIB01 ,
388
- [ addressesRegistry [ ChainId . EthMainnet ] . wbC3M ] :
389
- addressesRegistry [ ChainId . EthMainnet ] . bC3M ,
390
- [ addressesRegistry [ ChainId . EthMainnet ] . wNative ] : NATIVE_ADDRESS ,
391
- [ addressesRegistry [ ChainId . EthMainnet ] . stEth ] : NATIVE_ADDRESS ,
392
- [ addressesRegistry [ ChainId . EthMainnet ] . wstEth ] :
393
- addressesRegistry [ ChainId . EthMainnet ] . stEth ,
394
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDTWBTCWETH-morpho" ] ] :
395
- addressesRegistry [ ChainId . EthMainnet ] . crvUSDTWBTCWETH ,
396
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDCWBTCWETH-morpho" ] ] :
397
- addressesRegistry [ ChainId . EthMainnet ] . crvUSDCWBTCWETH ,
398
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvCRVUSDTBTCWSTETH-morpho" ] ] :
399
- addressesRegistry [ ChainId . EthMainnet ] . crvCRVUSDTBTCWSTETH ,
400
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxTryLSD-morpho" ] ] :
401
- addressesRegistry [ ChainId . EthMainnet ] . tryLSD ,
402
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDETHCRV-morpho" ] ] :
403
- addressesRegistry [ ChainId . EthMainnet ] . crvUSDETHCRV ,
404
- [ addressesRegistry [ ChainId . EthMainnet ] [ "stkcvx2BTC-f-morpho" ] ] :
405
- addressesRegistry [ ChainId . EthMainnet ] [ "2BTC-f" ] ,
391
+ [ _addressesRegistry [ ChainId . EthMainnet ] . wbIB01 ] :
392
+ _addressesRegistry [ ChainId . EthMainnet ] . bIB01 ,
393
+ [ _addressesRegistry [ ChainId . EthMainnet ] . wbC3M ] :
394
+ _addressesRegistry [ ChainId . EthMainnet ] . bC3M ,
395
+ [ _addressesRegistry [ ChainId . EthMainnet ] . wNative ] : NATIVE_ADDRESS ,
396
+ [ _addressesRegistry [ ChainId . EthMainnet ] . stEth ] : NATIVE_ADDRESS ,
397
+ [ _addressesRegistry [ ChainId . EthMainnet ] . wstEth ] :
398
+ _addressesRegistry [ ChainId . EthMainnet ] . stEth ,
399
+ [ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDTWBTCWETH-morpho" ] ] :
400
+ _addressesRegistry [ ChainId . EthMainnet ] . crvUSDTWBTCWETH ,
401
+ [ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDCWBTCWETH-morpho" ] ] :
402
+ _addressesRegistry [ ChainId . EthMainnet ] . crvUSDCWBTCWETH ,
403
+ [ _addressesRegistry [ ChainId . EthMainnet ] [
404
+ "stkcvxcrvCRVUSDTBTCWSTETH-morpho"
405
+ ] ] : _addressesRegistry [ ChainId . EthMainnet ] . crvCRVUSDTBTCWSTETH ,
406
+ [ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxTryLSD-morpho" ] ] :
407
+ _addressesRegistry [ ChainId . EthMainnet ] . tryLSD ,
408
+ [ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDETHCRV-morpho" ] ] :
409
+ _addressesRegistry [ ChainId . EthMainnet ] . crvUSDETHCRV ,
410
+ [ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvx2BTC-f-morpho" ] ] :
411
+ _addressesRegistry [ ChainId . EthMainnet ] [ "2BTC-f" ] ,
406
412
} ,
407
413
[ ChainId . BaseMainnet ] : {
408
- [ addressesRegistry [ ChainId . BaseMainnet ] . wNative ] : NATIVE_ADDRESS ,
409
- [ addressesRegistry [ ChainId . BaseMainnet ] . verUsdc ] :
410
- addressesRegistry [ ChainId . BaseMainnet ] . usdc ,
411
- [ addressesRegistry [ ChainId . BaseMainnet ] . testUsdc ] :
412
- addressesRegistry [ ChainId . BaseMainnet ] . usdc ,
414
+ [ _addressesRegistry [ ChainId . BaseMainnet ] . wNative ] : NATIVE_ADDRESS ,
415
+ [ _addressesRegistry [ ChainId . BaseMainnet ] . verUsdc ] :
416
+ _addressesRegistry [ ChainId . BaseMainnet ] . usdc ,
417
+ [ _addressesRegistry [ ChainId . BaseMainnet ] . testUsdc ] :
418
+ _addressesRegistry [ ChainId . BaseMainnet ] . usdc ,
413
419
} ,
414
420
[ ChainId . PolygonMainnet ] : { } ,
415
421
[ ChainId . ArbitrumMainnet ] : { } ,
@@ -441,7 +447,7 @@ export const erc20WrapperTokens: Record<number, Set<Address>> = {};
441
447
*/
442
448
export const permissionedWrapperTokens : Record < number , Set < Address > > = {
443
449
[ ChainId . BaseMainnet ] : new Set ( [
444
- addressesRegistry [ ChainId . BaseMainnet ] . testUsdc ,
450
+ _addressesRegistry [ ChainId . BaseMainnet ] . testUsdc ,
445
451
] ) ,
446
452
} ;
447
453
@@ -451,8 +457,8 @@ export const permissionedWrapperTokens: Record<number, Set<Address>> = {
451
457
*/
452
458
export const permissionedBackedTokens : Record < number , Set < Address > > = {
453
459
[ ChainId . EthMainnet ] : new Set ( [
454
- addressesRegistry [ ChainId . EthMainnet ] . wbIB01 ,
455
- addressesRegistry [ ChainId . EthMainnet ] . wbC3M ,
460
+ _addressesRegistry [ ChainId . EthMainnet ] . wbIB01 ,
461
+ _addressesRegistry [ ChainId . EthMainnet ] . wbC3M ,
456
462
] ) ,
457
463
} ;
458
464
@@ -462,7 +468,7 @@ export const permissionedBackedTokens: Record<number, Set<Address>> = {
462
468
*/
463
469
export const permissionedCoinbaseTokens : Record < number , Set < Address > > = {
464
470
[ ChainId . BaseMainnet ] : new Set ( [
465
- addressesRegistry [ ChainId . BaseMainnet ] . verUsdc ,
471
+ _addressesRegistry [ ChainId . BaseMainnet ] . verUsdc ,
466
472
] ) ,
467
473
} ;
468
474
@@ -492,11 +498,29 @@ entries(permissionedWrapperTokens).forEach(([chainId, tokens]) => {
492
498
*/
493
499
export const convexWrapperTokens : Record < number , Set < Address > > = {
494
500
[ ChainId . EthMainnet ] : new Set ( [
495
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDTWBTCWETH-morpho" ] ,
496
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDCWBTCWETH-morpho" ] ,
497
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvCRVUSDTBTCWSTETH-morpho" ] ,
498
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxTryLSD-morpho" ] ,
499
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDETHCRV-morpho" ] ,
500
- addressesRegistry [ ChainId . EthMainnet ] [ "stkcvx2BTC-f-morpho" ] ,
501
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDTWBTCWETH-morpho" ] ,
502
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDCWBTCWETH-morpho" ] ,
503
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvCRVUSDTBTCWSTETH-morpho" ] ,
504
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxTryLSD-morpho" ] ,
505
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvxcrvUSDETHCRV-morpho" ] ,
506
+ _addressesRegistry [ ChainId . EthMainnet ] [ "stkcvx2BTC-f-morpho" ] ,
501
507
] ) ,
502
508
} ;
509
+
510
+ export let addressesRegistry = Object . freeze ( _addressesRegistry ) ;
511
+
512
+ export function registerCustomAddresses (
513
+ customAddresses :
514
+ | Record < keyof typeof _addressesRegistry , DeepPartial < ChainAddresses > >
515
+ | Record < number , ChainAddresses > ,
516
+ ) {
517
+ // biome-ignore lint/suspicious/noExplicitAny: type is not trivial and not important here
518
+ const customizer = ( objValue : any , _srcValue : any , key : string ) => {
519
+ if ( objValue !== undefined && ! isPlainObject ( objValue ) )
520
+ throw new Error ( `Cannot override existing address: ${ key } ` ) ;
521
+ } ;
522
+
523
+ addressesRegistry = Object . freeze (
524
+ mergeWith ( { } , _addressesRegistry , customAddresses , customizer ) ,
525
+ ) ;
526
+ }
0 commit comments