Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use custom gateway #176

Merged
merged 6 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"dependencies": {
"@0x/subproviders": "^6.5.4",
"@aave/aave-ui-kit": "^0.1.14",
"@aave/math-utils": "0.25.8",
"@aave/contract-helpers": "0.25.8",
"@aave/math-utils": "0.26.1",
"@aave/contract-helpers": "0.26.1",
"@aave/protocol-js": "4.3.0",
"@apollo/client": "^3.4.16",
"@apollo/react-common": "^3.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/libs/governance-provider/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dayjs from 'dayjs';

import { ProposalItem } from './types';

const IPFS_ENDPOINT = 'https://cloudflare-ipfs.com/ipfs';
export const IPFS_ENDPOINT = 'https://gateway.pinata.cloud/ipfs';

/**
* Thegraph data is only up to date to the last emitted events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import fm from 'front-matter';
import { IpfsMeta, IpfsPropsal } from '../types';
import { getProposalMetadata } from '@aave/contract-helpers';
import { IPFS_ENDPOINT } from '../helper';

const useGetMetadataDescription = (idHash: string, skip: boolean) => {
const [loading, setLoading] = useState(false);
Expand All @@ -10,7 +11,7 @@ const useGetMetadataDescription = (idHash: string, skip: boolean) => {
const getMeta = async (idHash: string) => {
setLoading(true);
try {
const rawBody = await getProposalMetadata(idHash);
const rawBody = await getProposalMetadata(idHash, IPFS_ENDPOINT);
// Fix Bug with the @
const parsedDesc = !!rawBody.description
? rawBody.description.replace(/@/gi, '')
Expand Down
22 changes: 14 additions & 8 deletions src/libs/governance-provider/hooks/use-get-proposals-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import { useState } from 'react';
import { Proposal, normalize } from '@aave/protocol-js';
import { normalize } from '@aave/protocol-js';
import { providers } from 'ethers';

import { ProposalItem } from '../types';
import { getProposalExpiry } from '../helper';
import { getProposalExpiry, IPFS_ENDPOINT } from '../helper';

import { useStateLoading, LOADING_STATE } from '../../hooks/use-state-loading';
import { usePolling } from '../../hooks/use-polling';
import { IpfsMeta } from '../types';

import fm from 'front-matter';
import { getProvider } from '../../../helpers/config/markets-and-network-config';
import { AaveGovernanceService, ChainId } from '@aave/contract-helpers';
import {
AaveGovernanceService,
ChainId,
getProposalMetadata,
Proposal,
} from '@aave/contract-helpers';

const MemorizeStartTimestamp: { [id: string]: number } = {};
const MemorizeProposalTimestamp: { [id: string]: number } = {};
Expand All @@ -33,15 +38,16 @@ const generateProposal = async (
);
MemorizeProposalTimestamp[memorizeId] = Number(proposalTimestamp);
}
const meta = await getProposalMetadata(prop.ipfsHash, IPFS_ENDPOINT);
// Fix Bug with the @
const parsedDesc = !!prop.description
? prop.description.replace(/@/gi, '')
const parsedDesc = !!meta.description
? meta.description.replace(/@/gi, '')
: 'no description, or description loading failed';
const processed = fm<IpfsMeta>(parsedDesc);

const proposal: ProposalItem = {
id: Number(prop.id),
title: prop.title || '',
title: meta.title || '',
state: prop.state || '',
ipfsHash: prop.ipfsHash,
description: {
Expand All @@ -51,7 +57,7 @@ const generateProposal = async (
},
creator: prop.creator,
executor: prop.executor,
shortDescription: prop.shortDescription,
shortDescription: meta.shortDescription,
totalVotingSupply: normalize(prop.totalVotingSupply, 18),
executionTime: prop.executionTime,
startBlock: Number(prop.startBlock),
Expand Down Expand Up @@ -91,7 +97,7 @@ const parserProposals = async (
provider: providers.Provider,
averageNetworkBlockTime: number
) => {
const proposalPromises: Promise<ProposalItem | undefined>[] = data.map((prop: Proposal) =>
const proposalPromises: Promise<ProposalItem | undefined>[] = data.map((prop) =>
generateProposal(prop, provider, averageNetworkBlockTime)
);
const results: (ProposalItem | undefined)[] = await Promise.all(proposalPromises);
Expand Down
2 changes: 2 additions & 0 deletions src/libs/governance-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
GovernancePowerDelegationTokenService,
} from '@aave/contract-helpers';
import { useProtocolDataContext } from '../protocol-data-provider';
import { IPFS_ENDPOINT } from './helper';

export interface ProtocolContextDataType {
governanceConfig: GovernanceConfig;
Expand Down Expand Up @@ -55,6 +56,7 @@ export function GovernanceDataProvider({
const governanceService = new AaveGovernanceService(rpcProvider, {
GOVERNANCE_ADDRESS: governanceConfig.addresses.AAVE_GOVERNANCE_V2,
GOVERNANCE_HELPER_ADDRESS: governanceConfig.addresses.AAVE_GOVERNANCE_V2_HELPER,
ipfsGateway: IPFS_ENDPOINT,
});
const powerDelegation = new GovernancePowerDelegationTokenService(rpcProvider);

Expand Down