@@ -32,6 +32,9 @@ import factorypool3BaseCryptoAbi from '#root/constants/abis/factory_crypto_swap.
32
32
import { uintToBN } from '#root/utils/Web3/index.js' ;
33
33
import { lc } from '#root/utils/String.js' ;
34
34
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
+
35
38
const isCryptoPool = ( { registryId } ) => registryId . includes ( 'crypto' ) ;
36
39
37
40
// 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 }) => {
118
121
superSettings : {
119
122
fallbackValue : 1e18 ,
120
123
} ,
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
+ } ] : [ ] ) ] : [ {
122
149
address : pool . address ,
123
150
abi : poolAbi ,
124
151
methodName : 'get_virtual_price' ,
@@ -149,8 +176,9 @@ export default fn(async ({ blockchainId }) => {
149
176
/**
150
177
* Calculate base daily and weekly apys
151
178
*/
179
+ let adminFee ;
152
180
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 ;
154
182
const { xcpProfit : [ { data : unsafeXcpProfitDayOld } ] , xcpProfitA : [ { data : unsafeXcpProfitADayOld } ] } = dayOldPoolData ;
155
183
const { xcpProfit : [ { data : unsafeXcpProfitWeekOld } ] , xcpProfitA : [ { data : unsafeXcpProfitAWeekOld } ] } = weekOldPoolData ;
156
184
@@ -161,9 +189,14 @@ export default fn(async ({ blockchainId }) => {
161
189
const xcpProfitWeekOld = safeXcpProfit ( unsafeXcpProfitWeekOld ) ;
162
190
const xcpProfitAWeekOld = safeXcpProfit ( unsafeXcpProfitAWeekOld ) ;
163
191
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
167
200
const rateDaily = ( currentProfit - dayOldProfit ) / dayOldProfit ;
168
201
const rateWeekly = ( currentProfit - weekOldProfit ) / weekOldProfit ;
169
202
0 commit comments