Skip to content

Commit

Permalink
feat: get treasury address based on chainId
Browse files Browse the repository at this point in the history
  • Loading branch information
gleiser-oliveira committed Dec 4, 2023
1 parent 95150e6 commit 3994917
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/clients/api/queries/useGetTreasuryTotals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import {
useGetIsolatedPools,
useGetVTokenBalancesAll,
} from 'clients/api';
import { getVTreasuryContractAddress, getVTreasuryV8ContractAddress } from 'packages/contracts';
import { useAccountAddress, useChainId } from 'packages/wallet';
import { ChainId } from 'types';
import { convertMantissaToTokens, indexBy } from 'utilities';

// Note: this is a temporary fix. Once we start refactoring this part we should
// probably fetch the treasury address using the Comptroller contract
const TREASURY_ADDRESSES = new Map([
[56, '0xF322942f644A996A617BD29c16bd7d231d9F35E9'],
// When querying comptroller.treasuryAddress() we get an empty address back,
// so for now I've let it as it is
[97, '0x0000000000000000000000000000000000000000'],
]);

export interface Data {
treasurySupplyBalanceCents: BigNumber;
treasuryBorrowBalanceCents: BigNumber;
Expand All @@ -33,7 +26,15 @@ export interface UseGetTreasuryTotalsOutput {
const useGetTreasuryTotals = (): UseGetTreasuryTotalsOutput => {
const { accountAddress } = useAccountAddress();
const { chainId } = useChainId();
const treasuryAddress = TREASURY_ADDRESSES.get(chainId);
const treasuryAddress = useMemo(() => {
switch (chainId) {
case ChainId.BSC_MAINNET:
case ChainId.BSC_TESTNET:
return getVTreasuryContractAddress({ chainId });
default:
return getVTreasuryV8ContractAddress({ chainId });
}
}, [chainId]);

const { data: getPoolsData, isLoading: isGetPoolsDataLoading } = useGetIsolatedPools({
accountAddress,
Expand Down
17 changes: 17 additions & 0 deletions src/packages/contracts/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import venusOracleBscMainnetDeployments from '@venusprotocol/oracle/deployments/
import venusOracleBscTestnetDeployments from '@venusprotocol/oracle/deployments/bsctestnet_addresses.json';
import venusOracleSepoliaDeployments from '@venusprotocol/oracle/deployments/sepolia_addresses.json';
import { abi as LegacyPoolComptrollerAbi } from '@venusprotocol/venus-protocol/artifacts/contracts/Comptroller/Diamond/DiamondConsolidated.sol/DiamondConsolidated.json';
import { abi as VTreasuryAbi } from '@venusprotocol/venus-protocol/artifacts/contracts/Governance/VTreasury.sol/VTreasury.json';
import { abi as VTreasuryV8Abi } from '@venusprotocol/venus-protocol/artifacts/contracts/Governance/VTreasuryV8.sol/VTreasuryV8.json';
import { abi as JumpRateModelAbi } from '@venusprotocol/venus-protocol/artifacts/contracts/InterestRateModels/JumpRateModel.sol/JumpRateModel.json';
import { abi as VenusLensAbi } from '@venusprotocol/venus-protocol/artifacts/contracts/Lens/VenusLens.sol/VenusLens.json';
import { abi as SwapRouterAbi } from '@venusprotocol/venus-protocol/artifacts/contracts/Swap/SwapRouter.sol/SwapRouter.json';
Expand Down Expand Up @@ -209,6 +211,21 @@ export const contracts: ContractConfig[] = [
[ChainId.BSC_MAINNET]: venusProtocolBscMainnetDeployments.addresses.Prime,
},
},
{
name: 'VTreasury',
abi: VTreasuryAbi,
address: {
[ChainId.BSC_TESTNET]: venusProtocolBscTestnetDeployments.addresses.VTreasury,
[ChainId.BSC_MAINNET]: venusProtocolBscMainnetDeployments.addresses.VTreasury,
},
},
{
name: 'VTreasuryV8',
abi: VTreasuryV8Abi,
address: {
[ChainId.SEPOLIA]: venusProtocolSepoliaDeployments.addresses.VTreasuryV8,
},
},
// Generic Contracts
{
name: 'IsolatedPoolComptroller',
Expand Down

0 comments on commit 3994917

Please sign in to comment.