Skip to content

Commit

Permalink
Modified identifyOracle
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptickoan committed Apr 13, 2022
1 parent ab62b12 commit 493e8ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
8 changes: 1 addition & 7 deletions src/components/pages/Fuse/FusePoolInfoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,12 @@ const AssetAndOtherInfo = ({ assets, poolOracle, tokensData }: { assets: USDPric
});


const oracleIdentity = useIdentifyOracle(
const { identity: oracleIdentity, oracle: oracleAddress } = useIdentifyOracle(
selectedAsset.oracle,
poolOracle,
selectedAsset.underlyingToken
)

// Link to MPO if asset is ETH
const oracleAddress =
(selectedAsset.underlyingToken === ETH_TOKEN_DATA.address || selectedAsset.oracle === ETH_TOKEN_DATA.address)
? poolOracle
: selectedAsset.oracle;

const isMobile = useIsMobile();

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const OracleConfig = ({
const options = useGetOracleOptions(oracleData, tokenAddress);

// Identify token oracle address
const oracleIdentity = useIdentifyOracle(oracleAddress, poolOracleAddress, tokenAddress);
const {identity: oracleIdentity} = useIdentifyOracle(oracleAddress, poolOracleAddress, tokenAddress);

const [inputTouched, setInputTouched] = useState(false);

Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Fuse/Modals/Edit/OraclesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const OracleRow = ({
underlyings: string[];
isDefault?: boolean;
}) => {
const oracleIdentity = useIdentifyOracle(oracle);
const {identity: oracleIdentity} = useIdentifyOracle(oracle);

const displayedOracle = !!oracleIdentity
? oracleIdentity
Expand Down
23 changes: 13 additions & 10 deletions src/hooks/fuse/useOracleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,18 @@ export const useIdentifyOracle = (
oracleAddr: string,
poolOracle?: string,
tokenAddr?: string
): string => {
):{
identity: string;
oracle: string;
} => {
const { fuse } = useRari();

const { data } = useQuery("Identifying Oracle " + tokenAddr, async () => {
if (tokenAddr && tokenAddr === ETH_TOKEN_DATA.address)
return "MasterPriceOracle";
return {identity: "MasterPriceOracle", oracle: oracleAddr};

// If no oracle address provided, return empty string
if (!oracleAddr) return "";
if (!oracleAddr) return {identity: "", oracle: oracleAddr};

if (oracleAddr === EmptyAddress && !!poolOracle) {
// If condition is true it means price feed comes from default oracle
Expand All @@ -58,22 +61,22 @@ export const useIdentifyOracle = (
true
);

const tokenOracle = await poolDefaultOracleContract.oracles(tokenAddr);
const tokenOracle: string = await poolDefaultOracleContract.oracles(tokenAddr);

// Identify type of oracle used
const identity = await fuse.identifyPriceOracle(tokenOracle);
const identity: string = await fuse.identifyPriceOracle(tokenOracle);

return identity;
return {identity, oracle: tokenOracle};
}

const identity = await fuse.identifyPriceOracle(oracleAddr);
const identity: string = await fuse.identifyPriceOracle(oracleAddr);

if (identity === "MasterPriceOracleV1") return "RariMasterPriceOracle";
if (identity === "MasterPriceOracleV1") return {identity: "RariMasterPriceOracle", oracle: oracleAddr};

return identity;
return {identity, oracle: oracleAddr};
});

return data ?? "";
return data ?? {identity: " ", oracle: oracleAddr};
};

export const useOracleData = (
Expand Down

1 comment on commit 493e8ca

@vercel
Copy link

@vercel vercel bot commented on 493e8ca Apr 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.