Skip to content

Commit

Permalink
Merge pull request #1246 from mars-protocol/develop
Browse files Browse the repository at this point in the history
Neutron RPC and REST update
  • Loading branch information
linkielink authored Dec 2, 2024
2 parents 76615b8 + 3b6df63 commit d2366c3
Show file tree
Hide file tree
Showing 55 changed files with 833 additions and 457 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @bobthebuidlr @linkielink @Patricie29 @StefChatz
* @linkielink @Patricie29 @StefChatz
6 changes: 5 additions & 1 deletion src/api/accounts/getAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
12 changes: 6 additions & 6 deletions src/api/cosmwasm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand All @@ -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))
}
Expand Down
14 changes: 0 additions & 14 deletions src/api/perps/getOpeningFee.ts

This file was deleted.

12 changes: 3 additions & 9 deletions src/chains/neutron/neutron-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 1 addition & 7 deletions src/chains/neutron/pion-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 0 additions & 6 deletions src/chains/osmosis/osmosis-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
69 changes: 49 additions & 20 deletions src/components/Modals/KeeperFeeModal.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Modal
Expand All @@ -71,10 +99,11 @@ export default function KeeperFeeModal() {
asset={USD}
isUSD
/>
{amount.isLessThan(BN_ZERO_ONE) && (
{isLessThanMin && (
<Callout type={CalloutType.WARNING}>
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.
</Callout>
)}
<Text size='sm' className='text-white/60'>
Expand All @@ -84,7 +113,7 @@ export default function KeeperFeeModal() {
</Text>
<Button
onClick={handleActionClick}
disabled={amount.isLessThan(BN_ZERO_ONE)}
disabled={isLessThanMin}
className='w-full !text-base'
color='tertiary'
text='Done'
Expand Down
6 changes: 2 additions & 4 deletions src/components/Modals/PerpsSlTpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { Callout, CalloutType } from 'components/common/Callout'
import Divider from 'components/common/Divider'
import { TrashBin } from 'components/common/Icons'
import Text from 'components/common/Text'
import { getDefaultChainSettings } from 'constants/defaultSettings'
import { LocalStorageKeys } from 'constants/localStorageKeys'
import { BN_ZERO } from 'constants/math'
import useCurrentAccount from 'hooks/accounts/useCurrentAccount'
import useAssets from 'hooks/assets/useAssets'
import useDepositEnabledAssets from 'hooks/assets/useDepositEnabledAssets'
import useChainConfig from 'hooks/chain/useChainConfig'
import useLocalStorage from 'hooks/localStorage/useLocalStorage'
import usePerpsAsset from 'hooks/perps/usePerpsAsset'
import usePerpsConfig from 'hooks/perps/usePerpsConfig'
Expand Down Expand Up @@ -56,11 +54,11 @@ export default function PerpsSlTpModal() {
return takeProfitPrice.minus(currentPrice).dividedBy(currentPrice).multipliedBy(100)
}, [currentPrice, takeProfitPrice])

const chainConfig = useChainConfig()
const creditManagerConfig = useStore((s) => s.creditManagerConfig)

const [keeperFee, _] = useLocalStorage(
LocalStorageKeys.PERPS_KEEPER_FEE,
getDefaultChainSettings(chainConfig).perpsKeeperFee,
creditManagerConfig?.keeper_fee_config?.min_fee,
)

const feeToken = useMemo(
Expand Down
4 changes: 4 additions & 0 deletions src/components/Wallet/WalletConnectProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const mobileProviders: WalletMobileProvider[] = [
new CosmostationMobileProvider({
networks: getSupportedChainsInfos(WalletID.CosmostationMobile),
}),
new CosmiframeExtensionProvider({
allowedParentOrigins: DAODAO_ORIGINS,
networks: getSupportedChainsInfos(WalletID.DaoDao),
}) as any,
]

const extensionProviders: WalletExtensionProvider[] = [
Expand Down
Loading

0 comments on commit d2366c3

Please sign in to comment.