@@ -11,6 +11,8 @@ import { Address } from "viem";
1111import { computeMarketCap } from "../oracle" ;
1212import { getLockableV3PoolData } from "@app/utils/v3-utils/getV3PoolData" ;
1313import { chainConfigs } from "@app/config" ;
14+ import { AssetData } from "@app/types" ;
15+ import { Network } from "@app/types/config-types" ;
1416
1517export const fetchExistingPool = async ( {
1618 poolAddress,
@@ -87,21 +89,7 @@ export const insertPoolIfNotExists = async ({
8789 totalSupply : assetTotalSupply ,
8890 } ) ;
8991
90- let migrationType ;
91- if (
92- assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v2 . v2Migrator . toLowerCase ( )
93- || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v2 . nimCustomV2Migrator . toLowerCase ( )
94- ) {
95- migrationType = "v2" ;
96- } else if (
97- assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v3 . v3Migrator . toLowerCase ( )
98- || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v3 . nimCustomV3Migrator . toLowerCase ( )
99- ) {
100- migrationType = "v3" ;
101- } else if ( assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v4 . v4Migrator . toLowerCase ( ) ) {
102- migrationType = "v4" ;
103- }
104-
92+ let migrationType = getMigrationType ( assetData , chain . name ) ;
10593
10694 return await db . insert ( pool ) . values ( {
10795 ...poolData ,
@@ -229,20 +217,7 @@ export const insertPoolIfNotExistsV4 = async ({
229217 graduationBalance : 0n ,
230218 } ) ;
231219
232- let migrationType ;
233- if (
234- assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v2 . v2Migrator . toLowerCase ( )
235- || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v2 . nimCustomV2Migrator . toLowerCase ( )
236- ) {
237- migrationType = "v2" ;
238- } else if (
239- assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v3 . v3Migrator . toLowerCase ( )
240- || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v3 . nimCustomV3Migrator . toLowerCase ( )
241- ) {
242- migrationType = "v3" ;
243- } else if ( assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chain . name ] . addresses . v4 . v4Migrator . toLowerCase ( ) ) {
244- migrationType = "v4" ;
245- }
220+ let migrationType = getMigrationType ( assetData , chain . name ) ;
246221
247222 return await db . insert ( pool ) . values ( {
248223 address,
@@ -363,3 +338,21 @@ export const insertLockableV3PoolIfNotExists = async ({
363338 integrator : assetData . integrator ,
364339 } ) ;
365340} ;
341+
342+ function getMigrationType ( assetData : AssetData , chainName : Network ) : string {
343+ if (
344+ assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chainName ] . addresses . v2 . v2Migrator . toLowerCase ( )
345+ || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chainName ] . addresses . v2 . nimCustomV2Migrator . toLowerCase ( )
346+ ) {
347+ return "v2" ;
348+ } else if (
349+ assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chainName ] . addresses . v3 . v3Migrator . toLowerCase ( )
350+ || assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chainName ] . addresses . v3 . nimCustomV3Migrator . toLowerCase ( )
351+ ) {
352+ return "v3" ;
353+ } else if ( assetData . liquidityMigrator . toLowerCase ( ) === chainConfigs [ chainName ] . addresses . v4 . v4Migrator . toLowerCase ( ) ) {
354+ return "v4" ;
355+ } else {
356+ return "unknown" ;
357+ }
358+ }
0 commit comments