Skip to content

Commit

Permalink
Automatically fetch all sidechain facto gauges data in getGauges
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe-git committed Mar 19, 2022
1 parent 0f30335 commit e842e8e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
21 changes: 4 additions & 17 deletions pages/api/getFactoGauges/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Web3 from 'web3';
import groupBy from 'lodash.groupby';
import { fn } from 'utils/api';
import gaugeRegistry from 'constants/abis/gauge-registry.json';
import sideChainGauge from 'constants/abis/sidechain-gauge.json';
Expand All @@ -9,19 +8,11 @@ import multicallAbi from 'constants/abis/multicall.json';
import gaugeControllerAbi from 'constants/abis/gauge_controller.json';
import factorypool3Abi from 'constants/abis/factory_swap.json';

import erc20Abi from 'constants/abis/erc20.json';
import { multiCall } from 'utils/Calls';
import { flattenArray, sum, arrayToHashmap } from 'utils/Array';
import getTokensPrices from 'utils/data/tokens-prices';
import getAssetsPrices from 'utils/data/assets-prices';
import getFactoryV2GaugeRewards from 'utils/data/getFactoryV2GaugeRewards';
import { arrayToHashmap } from 'utils/Array';
import { getMultiCall } from 'utils/getters';

import getMainRegistryPools from 'pages/api/getMainRegistryPools';
import getGauges from 'pages/api/getGauges';
import { IS_DEV } from 'constants/AppConstants';
import configs from 'constants/configs';
import allCoins from 'constants/coins';


export default fn(async ({ blockchainId }) => {
Expand All @@ -39,13 +30,6 @@ export default fn(async ({ blockchainId }) => {


const {
nativeCurrencySymbol,
nativeCurrencyCoingeckoId,
nativeAssetErc20WrapperId,
platformCoingeckoId,
rpcUrl,
factoryImplementationAddressMap: implementationAddressMap,
getFactoryCryptoRegistryAddress,
multicallAddress,
} = config;

Expand Down Expand Up @@ -145,9 +129,11 @@ export default fn(async ({ blockchainId }) => {

let hasCrv = false
let gauge_relative_weight;
let get_gauge_weight;
try {
await gaugeController.methods.gauge_types(gaugeList[gaugeN]).call()
gauge_relative_weight = await gaugeController.methods.gauge_relative_weight(gaugeList[gaugeN]).call()
get_gauge_weight = await gaugeController.methods.get_gauge_weight(gaugeList[gaugeN]).call()
hasCrv = true
} catch (e) { }

Expand All @@ -172,6 +158,7 @@ export default fn(async ({ blockchainId }) => {
working_supply,
totalSupply,
gauge_relative_weight,
get_gauge_weight,
inflation_rate: Number(inflation_rate) || pendingEmissions[gaugeList[gaugeN]],
},
swap_data: {
Expand Down
68 changes: 59 additions & 9 deletions pages/api/getGauges.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from 'axios';
import Web3 from 'web3';
import WEB3_CONSTANTS from 'constants/Web3';
import { fn } from '../../utils/api';
import getFactoGauges from 'pages/api/getFactoGauges';
import { fn } from 'utils/api';
import { arrayToHashmap, flattenArray } from 'utils/Array';
import aggregatorInterfaceABI from '../../constants/abis/aggregator.json';
import multicallAbi from '../../constants/abis/multicall.json';
import gaugeControllerAbi from '../../constants/abis/gauge_controller.json';
Expand All @@ -10,6 +11,15 @@ import swapAbi from '../../constants/abis/tripool_swap.json';

import { getFactoryRegistry, getMultiCall } from '../../utils/getters';

const CHAINS_WITH_FACTORY_GAUGES = [
'fantom',
'polygon',
'arbitrum',
'avalanche',
'optimism',
'xdai',
];

const web3 = new Web3(WEB3_CONSTANTS.RPC_URL);

export default fn(async () => {
Expand Down Expand Up @@ -783,11 +793,6 @@ export default fn(async () => {
},
}

// at this stage we would take the data
// from the getFactoGauges and add it to the above object
// below would fetch the gauge controller data and complete the object
// we need to iterate through getFactoGauges and include the ones where hasCRV is true

// get pool addresses
let calls = [];

Expand Down Expand Up @@ -879,8 +884,53 @@ export default fn(async () => {
}
})



// Add all sidechain factory gauges
const factoGauges = await Promise.all(CHAINS_WITH_FACTORY_GAUGES.map((blockchainId) => (
getFactoGauges.straightCall({ blockchainId })
)));

gauges = {
...gauges,
...arrayToHashmap(flattenArray(factoGauges.map(({ gauges: blochainFactoGauges }, i) => {
const blockchainId = CHAINS_WITH_FACTORY_GAUGES[i];

return (
blochainFactoGauges.filter(({ hasCrv }) => hasCrv).map(({
gauge,
gauge_data: {
gauge_relative_weight,
get_gauge_weight,
inflation_rate,
totalSupply,
working_supply,
},
swap,
swap_token,
type,
symbol,
}) => [
`${blockchainId}-f-${symbol.replace('-f-gauge', '')}`, {
swap,
swap_token,
name: `${blockchainId}-f-${symbol.replace('-f-gauge', '')}`,
gauge,
type,
side_chain: true,
factory: true,
gauge_data: {
inflation_rate,
working_supply,
},
gauge_controller: {
gauge_relative_weight,
get_gauge_weight,
inflation_rate,
},
},
])
);
})))
};


return { gauges };
Expand Down

0 comments on commit e842e8e

Please sign in to comment.