Skip to content

Commit

Permalink
Always allow SNX on Mainnet and Optimism
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Dec 22, 2024
1 parent a3731ec commit ea1b1f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions liquidity/lib/useCollateralTypes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@snx-v3/contracts": "workspace:*",
"@snx-v3/tsHelpers": "workspace:*",
"@snx-v3/useBlockchain": "workspace:*",
"@snx-v3/useSNX": "workspace:*",
"@snx-v3/useSystemToken": "workspace:*",
"@synthetixio/wei": "^2.74.4",
"@tanstack/react-query": "^5.8.3",
Expand Down
31 changes: 18 additions & 13 deletions liquidity/lib/useCollateralTypes/useCollateralTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { importCollateralTokens } from '@snx-v3/contracts';
import { contractsHash } from '@snx-v3/tsHelpers';
import { Network, useNetwork } from '@snx-v3/useBlockchain';
import { Network, useNetwork, MAINNET, OPTIMISM } from '@snx-v3/useBlockchain';
import { useSystemToken } from '@snx-v3/useSystemToken';
import { useSNX } from '@snx-v3/useSNX';
import { wei, Wei } from '@synthetixio/wei';
import { useQuery } from '@tanstack/react-query';
import { ethers } from 'ethers';
Expand Down Expand Up @@ -54,17 +55,19 @@ export function useCollateralTypes(includeDelegationOff = false, customNetwork?:
const { network: currentNetwork } = useNetwork();
const network = customNetwork ?? currentNetwork;
const { data: systemToken } = useSystemToken(customNetwork);
const { data: MainnetSNX } = useSNX(MAINNET);
const { data: OptimismSNX } = useSNX(OPTIMISM);

return useQuery({
enabled: Boolean(network?.id && network?.preset && systemToken),
enabled: Boolean(network?.id && network?.preset && systemToken && MainnetSNX && OptimismSNX),
queryKey: [
`${network?.id}-${network?.preset}`,
'CollateralTypes',
{ includeDelegationOff },
{ contractsHash: contractsHash([systemToken]) },
{ contractsHash: contractsHash([systemToken, MainnetSNX, OptimismSNX]) },
],
queryFn: async () => {
if (!(network?.id && network?.preset && systemToken))
if (!(network?.id && network?.preset && systemToken && MainnetSNX && OptimismSNX))
throw Error('useCollateralTypes should not be enabled when contracts missing');

const collateralTypes = (await loadCollateralTypes(network.id, network.preset))
Expand Down Expand Up @@ -92,16 +95,18 @@ export function useCollateralTypes(includeDelegationOff = false, customNetwork?:
})
.filter((collateralType) => collateralType.tokenAddress !== systemToken.address);

if (includeDelegationOff) {
return collateralTypes.filter(({ depositingEnabled }) => depositingEnabled);
}

// Return collateral types that have minDelegationD18 < MaxUint256
// When minDelegationD18 === MaxUint256, delegation is effectively disabled
return collateralTypes
.filter(({ depositingEnabled }) => depositingEnabled)
.filter((collateralType) =>
collateralType.minDelegationD18.lt(ethers.constants.MaxUint256)
.filter(
(collateralType) =>
collateralType.depositingEnabled ||
(network.id === MAINNET.id && collateralType.address === MainnetSNX.address) ||
(network.id === OPTIMISM.id && collateralType.address === OptimismSNX.address)
)
.filter(
(collateralType) =>
// Return collateral types that have minDelegationD18 < MaxUint256
// When minDelegationD18 === MaxUint256, delegation is effectively disabled
includeDelegationOff || collateralType.minDelegationD18.lt(ethers.constants.MaxUint256)
);
},
// one hour in ms
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5521,6 +5521,7 @@ __metadata:
"@snx-v3/contracts": "workspace:*"
"@snx-v3/tsHelpers": "workspace:*"
"@snx-v3/useBlockchain": "workspace:*"
"@snx-v3/useSNX": "workspace:*"
"@snx-v3/useSystemToken": "workspace:*"
"@synthetixio/wei": "npm:^2.74.4"
"@tanstack/react-query": "npm:^5.8.3"
Expand Down Expand Up @@ -6074,7 +6075,7 @@ __metadata:
languageName: unknown
linkType: soft

"@snx-v3/useSNX@workspace:liquidity/lib/contracts/useSNX":
"@snx-v3/useSNX@workspace:*, @snx-v3/useSNX@workspace:liquidity/lib/contracts/useSNX":
version: 0.0.0-use.local
resolution: "@snx-v3/useSNX@workspace:liquidity/lib/contracts/useSNX"
dependencies:
Expand Down

0 comments on commit ea1b1f1

Please sign in to comment.