upgrade mango-client to support optimized settlePnl and reduce retry interval to 15s; implement more optimized settlePnl

This commit is contained in:
dd 2021-12-25 12:23:04 -05:00
parent dca90fe340
commit 9e4ad312f7
3 changed files with 35 additions and 14 deletions

View File

@ -7,6 +7,7 @@ import Tooltip from './Tooltip'
import PerpSideBadge from './PerpSideBadge'
import {
getMarketIndexBySymbol,
MangoAccount,
PerpAccount,
PerpMarket,
QUOTE_INDEX,
@ -25,7 +26,8 @@ import useMangoAccount from '../hooks/useMangoAccount'
export const settlePnl = async (
perpMarket: PerpMarket,
perpAccount: PerpAccount,
t
t,
mangoAccounts: MangoAccount[] | undefined
) => {
const mangoAccount = useMangoStore.getState().selectedMangoAccount.current
const mangoGroup = useMangoStore.getState().selectedMangoGroup.current
@ -43,7 +45,8 @@ export const settlePnl = async (
perpMarket,
mangoGroup.rootBankAccounts[QUOTE_INDEX],
mangoCache.priceCache[marketIndex].price,
wallet
wallet,
mangoAccounts
)
actions.reloadMangoAccount()
notify({
@ -112,7 +115,7 @@ export default function MarketPosition() {
const handleSettlePnl = (perpMarket, perpAccount) => {
setSettling(true)
settlePnl(perpMarket, perpAccount, t).then(() => {
settlePnl(perpMarket, perpAccount, t, undefined).then(() => {
setSettling(false)
})
}

View File

@ -6,12 +6,11 @@ import { ExclamationIcon } from '@heroicons/react/outline'
import Button from '../components/Button'
import { useViewport } from '../hooks/useViewport'
import { breakpoints } from './TradePageGrid'
import { Table, Td, Th, TrBody, TrHead } from './TableElements'
import { ExpandableRow, Table, Td, Th, TrBody, TrHead } from './TableElements'
import { formatUsdValue } from '../utils'
import Loading from './Loading'
import usePerpPositions from '../hooks/usePerpPositions'
import MarketCloseModal from './MarketCloseModal'
import { ExpandableRow } from './TableElements'
import PerpSideBadge from './PerpSideBadge'
import PnlText from './PnlText'
import { settlePnl } from './MarketPosition'
@ -23,6 +22,9 @@ const PositionsTable = () => {
const { reloadMangoAccount } = useMangoStore((s) => s.actions)
const [settling, setSettling] = useState(false)
const mangoClient = useMangoStore((s) => s.connection.client)
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const selectedMarket = useMangoStore((s) => s.selectedMarket.current)
const selectedMarketConfig = useMangoStore((s) => s.selectedMarket.config)
const price = useMangoStore((s) => s.tradeForm.price)
@ -51,8 +53,11 @@ const PositionsTable = () => {
const handleSettleAll = async () => {
setSettling(true)
const mangoAccounts = await mangoClient.getAllMangoAccounts(mangoGroup)
await Promise.all(
unsettledPositions.map((p) => settlePnl(p.perpMarket, p.perpAccount, t))
unsettledPositions.map((p) =>
settlePnl(p.perpMarket, p.perpAccount, t, mangoAccounts)
)
)
await reloadMangoAccount()
setSettling(false)

View File

@ -1006,7 +1006,7 @@
"@blockworks-foundation/mango-client@git+https://github.com/blockworks-foundation/mango-client-v3.git":
version "3.2.16"
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#74969460a23f738ada162c8127c371fe1881c406"
resolved "git+https://github.com/blockworks-foundation/mango-client-v3.git#628b46ab99879fdf2bd6d39d35dfb6133d6badcf"
dependencies:
"@project-serum/anchor" "^0.16.2"
"@project-serum/serum" "0.13.55"
@ -2031,9 +2031,9 @@
integrity sha512-qVCiT93utxN0cawScyQuNx8H82vBvZXSClZfgOu3l3dRRlRO6FjKEZlaPgXG9XUFjIAOsA4kAJY101vobHeJLQ==
"@types/express-serve-static-core@^4.17.9":
version "4.17.26"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.26.tgz#5d9a8eeecb9d5f9d7fc1d85f541512a84638ae88"
integrity sha512-zeu3tpouA043RHxW0gzRxwCHchMgftE8GArRsvYT0ByDMbn19olQHx5jLue0LxWY6iYtXb7rXmuVtSkhy9YZvQ==
version "4.17.27"
resolved "https://registry.yarnpkg.com/@types/express-serve-static-core/-/express-serve-static-core-4.17.27.tgz#7a776191e47295d2a05962ecbb3a4ce97e38b401"
integrity sha512-e/sVallzUTPdyOTiqi8O8pMdBBphscvI6E4JYaKlja4Lm+zh7UFSSdW5VMkRbhDtmrONqOUHOXRguPsDckzxNA==
dependencies:
"@types/node" "*"
"@types/qs" "*"
@ -2099,9 +2099,9 @@
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==
"@types/node@*":
version "17.0.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.2.tgz#a4c07d47ff737e8ee7e586fe636ff0e1ddff070a"
integrity sha512-JepeIUPFDARgIs0zD/SKPgFsJEAF0X5/qO80llx59gOxFTboS9Amv3S+QfB7lqBId5sFXJ99BN0J6zFRvL9dDA==
version "17.0.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.4.tgz#fec0ce0526abb6062fd206d72a642811b887a111"
integrity sha512-6xwbrW4JJiJLgF+zNypN5wr2ykM9/jHcL7rQ8fZe2vuftggjzZeRSM4OwRc6Xk8qWjwJ99qVHo/JgOGmomWRog==
"@types/node@^12.12.54":
version "12.20.38"
@ -10186,7 +10186,20 @@ yargs@^15.4.1:
y18n "^4.0.0"
yargs-parser "^18.1.2"
yargs@^17.0.1, yargs@^17.2.1:
yargs@^17.0.1:
version "17.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.1.tgz#da56b28f32e2fd45aefb402ed9c26f42be4c07b9"
integrity sha512-WUANQeVgjLbNsEmGk20f+nlHgOqzRFpiGWVaBrYGYIGANIIu3lWjoyi0fNlFmJkvfhCZ6BXINe7/W2O2bV4iaA==
dependencies:
cliui "^7.0.2"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.0.0"
yargs@^17.2.1:
version "17.3.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.0.tgz#295c4ffd0eef148ef3e48f7a2e0f58d0e4f26b1c"
integrity sha512-GQl1pWyDoGptFPJx9b9L6kmR33TGusZvXIZUT+BOz9f7X2L94oeAskFYLEg/FkhV06zZPBYLvLZRWeYId29lew==