diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0fccc2b1e..7f93d365f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @bobthebuidlr @linkielink @Patricie29 @StefChatz \ No newline at end of file +* @linkielink @Patricie29 @StefChatz \ No newline at end of file diff --git a/src/api/accounts/getAccount.ts b/src/api/accounts/getAccount.ts index fb8f31646..d09ad526a 100644 --- a/src/api/accounts/getAccount.ts +++ b/src/api/accounts/getAccount.ts @@ -18,9 +18,13 @@ export default async function getAccount( const accountPosition: Positions = await creditManagerQueryClient.positions({ accountId }) let perpsVaultPosition = null + if (isPerpsEnabled && address) { const perpsQueryClient = await getPerpsQueryClient(chainConfig) - perpsVaultPosition = await perpsQueryClient.vaultPosition({ accountId, userAddress: address }) + perpsVaultPosition = await perpsQueryClient.vaultPosition({ + accountId, + userAddress: chainConfig.contracts.creditManager, + }) } const accountKind = await creditManagerQueryClient.accountKind({ accountId: accountId }) diff --git a/src/api/cosmwasm-client.ts b/src/api/cosmwasm-client.ts index e9175646d..5601e01e5 100644 --- a/src/api/cosmwasm-client.ts +++ b/src/api/cosmwasm-client.ts @@ -57,7 +57,7 @@ const getParamsQueryClient = async (chainConfig: ChainConfig) => { const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_paramsQueryClient.get(key)) { + if (!_paramsQueryClient.get(key) && contract) { const client = await getClient(rpc) _paramsQueryClient.set(key, new MarsParamsQueryClient(client, contract)) } @@ -75,7 +75,7 @@ const getOracleQueryClientOsmosis = async (chainConfig: ChainConfig) => { const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_oracleQueryClient.get(key)) { + if (!_oracleQueryClient.get(key) && contract) { const client = await getClient(rpc) _oracleQueryClient.set(key, new MarsOracleOsmosisQueryClient(client, contract)) } @@ -93,7 +93,7 @@ const getOracleQueryClientNeutron = async (chainConfig: ChainConfig) => { const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_oracleQueryClient.get(key)) { + if (!_oracleQueryClient.get(key) && contract) { const client = await getClient(rpc) _oracleQueryClient.set(key, new MarsOracleWasmQueryClient(client, contract)) } @@ -120,7 +120,7 @@ const getIncentivesQueryClient = async (chainConfig: ChainConfig) => { const contract = chainConfig.contracts.incentives const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_incentivesQueryClient.get(key)) { + if (!_incentivesQueryClient.get(key) && contract) { const client = await getClient(rpc) _incentivesQueryClient.set(key, new MarsIncentivesQueryClient(client, contract)) } @@ -137,7 +137,7 @@ const getPerpsQueryClient = async (chainConfig: ChainConfig) => { const contract = chainConfig.contracts.perps const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_perpsClient.get(key)) { + if (!_perpsClient.get(key) && contract) { const client = await getClient(rpc) _perpsClient.set(key, new MarsPerpsQueryClient(client, contract)) } @@ -155,7 +155,7 @@ const getRedBankQueryClient = async (chainConfig: ChainConfig) => { const rpc = getUrl(chainConfig.endpoints.rpc) const key = rpc + contract - if (!_redBankQueryClient.get(key)) { + if (!_redBankQueryClient.get(key) && contract) { const client = await getClient(rpc) _redBankQueryClient.set(key, new MarsRedBankQueryClient(client, contract)) } diff --git a/src/api/perps/getOpeningFee.ts b/src/api/perps/getOpeningFee.ts deleted file mode 100644 index f89d41c65..000000000 --- a/src/api/perps/getOpeningFee.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { getPerpsQueryClient } from 'api/cosmwasm-client' -import { BNCoin } from 'types/classes/BNCoin' - -export default async function getOpeningFee( - chainConfig: ChainConfig, - denom: string, - amount: string, -) { - const perpsClient = await getPerpsQueryClient(chainConfig) - - return perpsClient - .openingFee({ denom, size: amount as any }) - .then((resp) => BNCoin.fromCoin(resp.fee)) -} diff --git a/src/chains/neutron/neutron-1.ts b/src/chains/neutron/neutron-1.ts index b800753b1..1f464ec0e 100644 --- a/src/chains/neutron/neutron-1.ts +++ b/src/chains/neutron/neutron-1.ts @@ -68,20 +68,14 @@ const Neutron1: ChainConfig = { sell: 'ibc/B559A80D62249C8AA07A380E2A2BEA6E5CA9A6F079C912C3A9E9B494105E4F81', }, contracts: { - redBank: 'neutron1n97wnm7q6d2hrcna3rqlnyqw2we6k0l8uqvmyqq6gsml92epdu7quugyph', - incentives: 'neutron1aszpdh35zsaz0yj80mz7f5dtl9zq5jfl8hgm094y0j0vsychfekqxhzd39', - oracle: 'neutron1dwp6m7pdrz6rnhdyrx5ha0acsduydqcpzkylvfgspsz60pj2agxqaqrr7g', - params: 'neutron1x4rgd7ry23v2n49y7xdzje0743c5tgrnqrqsvwyya2h6m48tz4jqqex06x', creditManager: 'neutron1qdzn3l4kn7gsjna2tfpg3g3mwd6kunx4p50lfya59k02846xas6qslgs3r', - accountNft: 'neutron184kvu96rqtetmunkkmhu5hru8yaqg7qfhd8ldu5avjnamdqu69squrh3f5', - perps: 'neutron14v9g7regs90qvful7djcajsvrfep5pg9qau7qm6wya6c2lzcpnms692dlt', pyth: 'neutron1m2emc93m9gpwgsrsf2vylv9xvgqh654630v7dfrhrkmr5slly53spg85wv', }, endpoints: { routes: 'https://app.astroport.fi/api/routes', - rpc: process.env.NEXT_PUBLIC_NEUTRON_RPC ?? 'https://rpc-kralum.neutron-1.neutron.org', - fallbackRpc: 'https://rpc.novel.remedy.tm.p2p.org', - rest: process.env.NEXT_PUBLIC_NEUTRON_REST ?? 'https://rest-kralum.neutron-1.neutron.org', + rpc: process.env.NEXT_PUBLIC_NEUTRON_RPC ?? 'https://rpc-lb.neutron.org', + fallbackRpc: 'https://neutron-rpc.cosmos-apis.com', + rest: process.env.NEXT_PUBLIC_NEUTRON_REST ?? 'https://rest-lb.neutron.org', swap: 'https://neutron.astroport.fi/swap', explorer: 'https://mintscan.io/neutron', dexAssets: 'https://neutron-cache-api.onrender.com/neutron-1/tokens', diff --git a/src/chains/neutron/pion-1.ts b/src/chains/neutron/pion-1.ts index 1b1ea4ec1..309fb7316 100644 --- a/src/chains/neutron/pion-1.ts +++ b/src/chains/neutron/pion-1.ts @@ -13,13 +13,7 @@ const Pion1: ChainConfig = { sell: 'factory/neutron1ke0vqqzyymlp5esr8gjwuzh94ysnpvj8er5hm7/UUSDC', }, contracts: { - redBank: 'neutron1f8ag222s4rnytkweym7lfncrxhtee3za5uk54r5n2rjxvsl9slzq36f66d', - incentives: 'neutron12hvgykldx0vxly59ta0ufjz776wxkl9k3r8ugln7xn6zus34a44s2vqw26', - oracle: 'neutron1pev35y62g6vte0s9t67gsf6m8d60x36t7wr0p0ghjl9r3h5mwl0q4h2zwc', - params: 'neutron1q66e3jv2j9r0duzwzt37fwl7h5njhr2kqs0fxmaa58sfqke80a2ss5hrz7', - creditManager: 'neutron13vyqc4efsnc357ze97ppv9h954zjasuj9d0w8es3mk9ea8sg6mvsr3xkjg', - accountNft: 'neutron1hx27cs7jjuvwq4hqgxn4av8agnspy2nwvrrq8e9f80jkeyrwrh8s8x645z', - perps: 'neutron1yu66sjvgg8shfjxkdlxcqh8yg6tmymsgve8lv62q6k4wrs5mt0pq6ard0n', + creditManager: 'neutron1zkxezh5e6jvg0h3kj50hz5d0yrgagkp0c3gcdr6stulw7fye9xlqygj2gz', pyth: 'neutron15ldst8t80982akgr8w8ekcytejzkmfpgdkeq4xgtge48qs7435jqp87u3t', }, endpoints: { diff --git a/src/chains/osmosis/osmosis-1.ts b/src/chains/osmosis/osmosis-1.ts index a7ab7673a..c46b303d4 100644 --- a/src/chains/osmosis/osmosis-1.ts +++ b/src/chains/osmosis/osmosis-1.ts @@ -89,14 +89,8 @@ const Osmosis1: ChainConfig = { }, bech32Config: Bech32Address.defaultBech32Config('osmo'), contracts: { - redBank: 'osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg', - accountNft: 'osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09', - oracle: 'osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g', creditManager: 'osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf', - incentives: 'osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm', - params: 'osmo1nlmdxt9ctql2jr47qd4fpgzg84cjswxyw6q99u4y4u4q6c2f5ksq7ysent', pyth: 'osmo13ge29x4e2s63a8ytz2px8gurtyznmue4a69n5275692v3qn3ks8q7cwck7', - perps: '', }, defaultCurrency: { coinDenom: 'OSMO', diff --git a/src/components/Modals/KeeperFeeModal.tsx b/src/components/Modals/KeeperFeeModal.tsx index e72f4b847..38bb5af7a 100644 --- a/src/components/Modals/KeeperFeeModal.tsx +++ b/src/components/Modals/KeeperFeeModal.tsx @@ -1,54 +1,82 @@ import classNames from 'classnames' -import { useCallback, useEffect, useState } from 'react' - +import { useCallback, useEffect, useMemo, useState } from 'react' import Modal from 'components/Modals/Modal' import AssetAmountInput from 'components/common/AssetAmountInput' import Button from 'components/common/Button' import { Callout, CalloutType } from 'components/common/Callout' import Text from 'components/common/Text' -import { getDefaultChainSettings } from 'constants/defaultSettings' import { LocalStorageKeys } from 'constants/localStorageKeys' -import { BN_ZERO_ONE } from 'constants/math' import useAsset from 'hooks/assets/useAsset' import useChainConfig from 'hooks/chain/useChainConfig' import useLocalStorage from 'hooks/localStorage/useLocalStorage' import useStore from 'store' -import { magnify } from 'utils/formatters' import { BN } from 'utils/helpers' +import { PRICE_ORACLE_DECIMALS } from 'constants/query' export default function KeeperFeeModal() { const chainConfig = useChainConfig() + const creditManagerConfig = useStore((s) => s.creditManagerConfig) + const USD = useAsset('usd') + const modal = useStore((s) => s.keeperFeeModal) + + const defaultKeeperFee = JSON.stringify( + creditManagerConfig?.keeper_fee_config?.min_fee ?? { + denom: '', + amount: '0', + }, + ) + const [keeperFee, setKeeperFee] = useLocalStorage( LocalStorageKeys.PERPS_KEEPER_FEE, - getDefaultChainSettings(chainConfig).perpsKeeperFee, + defaultKeeperFee, ) - const [amount, setAmount] = useState(BN(keeperFee.amount)) - const USD = useAsset('usd') + + const parsedKeeperFee = useMemo(() => { + try { + return typeof keeperFee === 'string' ? JSON.parse(keeperFee) : keeperFee + } catch { + return { denom: '', amount: '0' } + } + }, [keeperFee]) + + const [amount, setAmount] = useState(() => { + return BN(parsedKeeperFee?.amount ?? '0').shiftedBy(2 - PRICE_ORACLE_DECIMALS) + }) const onClose = useCallback(() => { useStore.setState({ keeperFeeModal: false }) }, []) + const minKeeperFee = BN(creditManagerConfig?.keeper_fee_config?.min_fee?.amount ?? '0') + const isLessThanMin = amount.isLessThan(minKeeperFee?.shiftedBy(2 - PRICE_ORACLE_DECIMALS)) + useEffect(() => { - setAmount(BN(keeperFee.amount)) - }, [keeperFee]) + if (parsedKeeperFee?.amount) { + setAmount(BN(parsedKeeperFee.amount).shiftedBy(2 - PRICE_ORACLE_DECIMALS)) + } + }, [parsedKeeperFee]) const handleActionClick = () => { - setKeeperFee({ denom: keeperFee.denom, amount: amount.toString() }) + if (!USD || !parsedKeeperFee.denom) return + + setKeeperFee( + JSON.stringify({ + denom: parsedKeeperFee.denom, + amount: amount.shiftedBy(PRICE_ORACLE_DECIMALS - 2).toString(), + }), + ) onClose() } const onUpdateAmount = useCallback( - (amount: BigNumber) => { + (newAmount: BigNumber) => { if (!USD) return - setAmount(magnify(amount.toString(), USD)) + setAmount(newAmount) }, [USD], ) - const modal = useStore((s) => s.keeperFeeModal) - - if (!modal || !USD) return + if (!modal || !USD || !chainConfig.perps) return null return ( - {amount.isLessThan(BN_ZERO_ONE) && ( + {isLessThanMin && ( - You can not set the Keeper Fee to less than $0.10 as it is the minimum amount for the - Keeper Fee. + You can not set the Keeper Fee to less than $ + {minKeeperFee?.shiftedBy(-PRICE_ORACLE_DECIMALS).toString()} as it is the minimum amount + for the Keeper Fee. )} @@ -84,7 +113,7 @@ export default function KeeperFeeModal() {