add settle borrow instruction to deposit transaction

This commit is contained in:
Tyler Shipe 2021-04-22 16:20:57 -04:00
parent 7d26ec8fac
commit 861eb34a76
4 changed files with 25 additions and 6 deletions

View File

@ -9,6 +9,7 @@ import useMarket from '../hooks/useMarket'
import { ElementTitle } from './styles'
import { InformationCircleIcon } from '@heroicons/react/outline'
import Tooltip from './Tooltip'
import { sleep } from '../utils'
const BalancesTable = () => {
const balances = useBalances()
@ -33,6 +34,7 @@ const BalancesTable = () => {
markets,
wallet
)
await sleep(250)
actions.fetchMarginAccounts()
} catch (e) {
console.warn('Error settling all:', e)

View File

@ -62,12 +62,12 @@ const DepositSrmModal = ({ isOpen, onClose }) => {
? mangoSrmAccountsForOwner[0].publicKey
: undefined
)
.then((_mangoSrmAcct: PublicKey) => {
.then(async (_mangoSrmAcct: PublicKey) => {
setSubmitting(false)
actions.fetchMangoSrmAccounts()
actions.fetchWalletBalances()
actions.fetchMangoGroup()
onClose()
await actions.fetchWalletBalances()
await actions.fetchMangoSrmAccounts()
await actions.fetchMangoGroup()
})
.catch((err) => {
setSubmitting(false)

View File

@ -55,10 +55,10 @@ const WithdrawModal = ({ isOpen, onClose }) => {
walletSrmAccount.publicKey,
Number(inputAmount)
)
.then((_transSig: string) => {
.then(async (_transSig: string) => {
setSubmitting(false)
onClose()
actions.fetchWalletBalances()
await actions.fetchWalletBalances()
actions.fetchMangoSrmAccounts()
actions.fetchMangoGroup()
})

View File

@ -140,6 +140,23 @@ export async function deposit(
const transaction = new Transaction()
transaction.add(instruction)
// settle borrow
const settleKeys = [
{ isSigner: false, isWritable: true, pubkey: mangoGroup.publicKey },
{ isSigner: false, isWritable: true, pubkey: marginAccount.publicKey },
{ isSigner: true, isWritable: false, pubkey: wallet.publicKey },
{ isSigner: false, isWritable: false, pubkey: SYSVAR_CLOCK_PUBKEY },
]
const setttleBorrowsData = encodeMangoInstruction({
SettleBorrow: { tokenIndex: new BN(tokenIndex), quantity: nativeQuantity },
})
const settleBorrowsInstruction = new TransactionInstruction({
keys: settleKeys,
data: setttleBorrowsData,
programId,
})
transaction.add(settleBorrowsInstruction)
const signers = []
const functionName = 'Deposit'