@@ -32,6 +32,9 @@ import factorypool3BaseCryptoAbi from '#root/constants/abis/factory_crypto_swap.
3232import { uintToBN } from '#root/utils/Web3/index.js' ;
3333import { lc } from '#root/utils/String.js' ;
3434
35+ const ADMIN_FEE_1_ABI = [ { "name" : "admin_fee" , "outputs" : [ { "type" : "uint256" , "name" : "" } ] , "inputs" : [ ] , "stateMutability" : "view" , "type" : "function" } ] ;
36+ const ADMIN_FEE_2_ABI = [ { "stateMutability" : "view" , "type" : "function" , "name" : "ADMIN_FEE" , "inputs" : [ ] , "outputs" : [ { "name" : "" , "type" : "uint256" } ] } ] ;
37+
3538const isCryptoPool = ( { registryId } ) => registryId . includes ( 'crypto' ) ;
3639
3740// xcp_profit and xcp_profit_a can return '0' when queried for a crypto pool with no activity, whether
@@ -118,7 +121,31 @@ export default fn(async ({ blockchainId }) => {
118121 superSettings : {
119122 fallbackValue : 1e18 ,
120123 } ,
121- } ] : [ {
124+ } , ...( blockNumber === undefined ? [ {
125+ address : pool . address ,
126+ abi : ADMIN_FEE_1_ABI ,
127+ methodName : 'admin_fee' ,
128+ metaData : { type : 'adminFee_try_1' , pool } ,
129+ networkSettings : {
130+ ...networkSettings ,
131+ blockNumber,
132+ } ,
133+ superSettings : {
134+ fallbackValue : null , // Know when this method hits a dead-end instead of defaulting to valid value
135+ } ,
136+ } , {
137+ address : pool . address ,
138+ abi : ADMIN_FEE_2_ABI ,
139+ methodName : 'ADMIN_FEE' ,
140+ metaData : { type : 'adminFee_try_2' , pool } ,
141+ networkSettings : {
142+ ...networkSettings ,
143+ blockNumber,
144+ } ,
145+ superSettings : {
146+ fallbackValue : null , // Know when this method hits a dead-end instead of defaulting to valid value
147+ } ,
148+ } ] : [ ] ) ] : [ {
122149 address : pool . address ,
123150 abi : poolAbi ,
124151 methodName : 'get_virtual_price' ,
@@ -149,8 +176,9 @@ export default fn(async ({ blockchainId }) => {
149176 /**
150177 * Calculate base daily and weekly apys
151178 */
179+ let adminFee ;
152180 if ( isCryptoPool ( pool ) ) {
153- const { xcpProfit : [ { data : unsafeXcpProfit } ] , xcpProfitA : [ { data : unsafeXcpProfitA } ] } = currentPoolData ;
181+ const { xcpProfit : [ { data : unsafeXcpProfit } ] , xcpProfitA : [ { data : unsafeXcpProfitA } ] , adminFee_try_1 : [ { data : adminFeeRaw1 } ] , adminFee_try_2 : [ { data : adminFeeRaw2 } ] } = currentPoolData ;
154182 const { xcpProfit : [ { data : unsafeXcpProfitDayOld } ] , xcpProfitA : [ { data : unsafeXcpProfitADayOld } ] } = dayOldPoolData ;
155183 const { xcpProfit : [ { data : unsafeXcpProfitWeekOld } ] , xcpProfitA : [ { data : unsafeXcpProfitAWeekOld } ] } = weekOldPoolData ;
156184
@@ -161,9 +189,14 @@ export default fn(async ({ blockchainId }) => {
161189 const xcpProfitWeekOld = safeXcpProfit ( unsafeXcpProfitWeekOld ) ;
162190 const xcpProfitAWeekOld = safeXcpProfit ( unsafeXcpProfitAWeekOld ) ;
163191
164- const currentProfit = ( ( xcpProfit / 2 ) + ( xcpProfitA / 2 ) + 1e18 ) / 2 ;
165- const dayOldProfit = ( ( xcpProfitDayOld / 2 ) + ( xcpProfitADayOld / 2 ) + 1e18 ) / 2 ;
166- const weekOldProfit = ( ( xcpProfitWeekOld / 2 ) + ( xcpProfitAWeekOld / 2 ) + 1e18 ) / 2 ;
192+ if ( adminFeeRaw1 === null && adminFeeRaw2 === null ) {
193+ throw new Error ( `adminFee could not be retrieved for pool ${ pool } because methods used seem invalid` )
194+ }
195+ adminFee = uintToBN ( adminFeeRaw1 ?? adminFeeRaw2 , 10 ) . toNumber ( ) ;
196+
197+ const currentProfit = ( xcpProfit * ( 1 - adminFee ) / 1e18 + xcpProfitA * adminFee / 1e18 + 1 ) / 2 ; // Better calc taking admin fee into account
198+ const dayOldProfit = ( xcpProfitDayOld * ( 1 - adminFee ) / 1e18 + xcpProfitADayOld * adminFee / 1e18 + 1 ) / 2 ; // Better calc taking admin fee into account
199+ const weekOldProfit = ( xcpProfitWeekOld * ( 1 - adminFee ) / 1e18 + xcpProfitAWeekOld * adminFee / 1e18 + 1 ) / 2 ; // Better calc taking admin fee into account
167200 const rateDaily = ( currentProfit - dayOldProfit ) / dayOldProfit ;
168201 const rateWeekly = ( currentProfit - weekOldProfit ) / weekOldProfit ;
169202
0 commit comments