Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mfi-sdk): sdk transaction overhaul & improved ui transaction handeling #970

Merged
merged 122 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
a96dcc8
feat: transaction refactor structure & implementation (wip)
k0beLeenders Nov 5, 2024
c5d2747
feat: improved type interface for processTransaction
k0beLeenders Nov 5, 2024
1696aa7
feat: integrating new transaction model in the sdk
k0beLeenders Nov 6, 2024
220a75f
feat: implemented new transaction structure across mrgnlend and arena
k0beLeenders Nov 6, 2024
e5b1091
fix: add various bugfixes in transaction flow
k0beLeenders Nov 7, 2024
1c7d940
fix: fixed various bugs with prio fees
k0beLeenders Nov 7, 2024
41e21e6
fix: repay w/ collat refactor wip (checkpoint)
k0beLeenders Nov 8, 2024
d5205a7
feat: looper logic adjustments (wip)
k0beLeenders Nov 15, 2024
8403ea0
fix: tradingbox new looper support
k0beLeenders Nov 15, 2024
28de488
feat: flashloan logic refactored
k0beLeenders Nov 15, 2024
eaf8964
feat: priority fee logic rework & dynamic broadcast type
k0beLeenders Nov 18, 2024
1dc800e
feat: changed priofee ui to micro & various other fixes
k0beLeenders Nov 19, 2024
1eff147
feat: transaction strategy & flashloan optimizations
k0beLeenders Nov 19, 2024
028ad4d
feat: finalized transaction stategies & refactored prio fees
k0beLeenders Nov 20, 2024
a050b5a
feat: improved looper tx logic
k0beLeenders Nov 20, 2024
98bded4
fix: cleanup & improved toasts
k0beLeenders Nov 20, 2024
90e6d3c
fix: increased standard prio fee
k0beLeenders Nov 21, 2024
c5013de
chore: removed console log
k0beLeenders Nov 21, 2024
d169492
fix: refactored confirm transactions to not use ws
k0beLeenders Nov 21, 2024
bfc1fdb
feat: dynamic max cu estimation
k0beLeenders Nov 21, 2024
86ed6eb
fix: switched default broadcast to dynamic
k0beLeenders Nov 21, 2024
7b18e6c
fix: already processed bundles return correct signature
k0beLeenders Nov 22, 2024
cfa79a5
fix: force default broadcast type to dynamic
k0beLeenders Nov 22, 2024
214bfd6
feat: staking & unstaking improvements & fix cu ix replace
k0beLeenders Nov 22, 2024
a5b3991
chore: added deprecated tag
k0beLeenders Nov 22, 2024
4c16027
fix: added priority fee fallback & fixed create accounts
k0beLeenders Nov 23, 2024
c198ae7
fix: increased confirmation time
k0beLeenders Nov 23, 2024
3d9d0ff
fix: removed bundle tip ix from position transfer
k0beLeenders Nov 25, 2024
618a5cc
feat: handle to full for bundle tip edge case
k0beLeenders Nov 25, 2024
634b679
fix: arena improvements & better cu limit for flashloans
k0beLeenders Nov 25, 2024
176cff6
feat: mrgn tx strategies env var support
k0beLeenders Nov 25, 2024
8c37e3f
fix: added rpc proxy again
k0beLeenders Nov 25, 2024
45f9b36
feat: add additional staging urls to allowed origins
chambaz Nov 25, 2024
931ea49
feat: improved error handeling
k0beLeenders Nov 26, 2024
9874e43
fix: added cu estimation fallback
k0beLeenders Nov 26, 2024
b573255
Merge pull request #974 from mrgnlabs/feature/better-handeling
k0beLeenders Nov 27, 2024
3635be9
feat: add retry functionality
borcherd Nov 25, 2024
f3416dd
feat: refactor retry action
borcherd Nov 26, 2024
c43f9d2
feat: add signature to succeeded txn
borcherd Nov 26, 2024
33274ff
chore: add signature to bundled txns
borcherd Nov 26, 2024
4a01f3d
feat: update lendBox closebalance action
borcherd Nov 26, 2024
313ba4d
chore: lendbox changes
borcherd Nov 26, 2024
bbcbca8
feat: loop-box changes
borcherd Nov 26, 2024
9fd580d
feat: update actions that link to individual flows
borcherd Nov 26, 2024
d42e86c
feat: repay-colat-box toast updates
borcherd Nov 26, 2024
a5ec9ec
chores
borcherd Nov 26, 2024
6b2b8b9
fix: stake rpc explorerurls
borcherd Nov 26, 2024
ab7e8bb
feat: toast styling updates (wip)
chambaz Nov 26, 2024
9927afa
feat: toast styles / copy updates
chambaz Nov 27, 2024
1522285
chore: add autoclose back in for succesful toasts
chambaz Nov 27, 2024
a3fd934
Merge pull request #969 from mrgnlabs/feature/toast-overhaul
k0beLeenders Nov 27, 2024
bc05e1b
feat: enhanced actionbox warnings (wip)
chambaz Nov 23, 2024
d08103a
fix: apply width style to all action message types
chambaz Nov 23, 2024
146e0e5
chore: move simulation status to sim utils
chambaz Nov 24, 2024
92a45f5
feat: add simulation progress / complete state indicator to fl action…
chambaz Nov 24, 2024
b0af9b9
feat: move simulation progress to new shared component (wip)
chambaz Nov 24, 2024
e046309
feat: fix complete / error timeout in action sim status, remove testi…
chambaz Nov 24, 2024
ac22517
feat: add simulation status component to stakebox, fix simulation tim…
chambaz Nov 24, 2024
4b014e8
chore: remove sim status from stake box
chambaz Nov 25, 2024
b5621ee
chore: remove testing mods from errors
chambaz Nov 25, 2024
4b3164c
fix: simulation warning max width issue
chambaz Nov 25, 2024
a54b0bd
feat: improve simulation status state mgmt / add to all actions
chambaz Nov 26, 2024
90063cd
Merge pull request #968 from mrgnlabs/feature/simulation-improvements
k0beLeenders Nov 27, 2024
622920d
chore: cleanup & small signature fix
k0beLeenders Nov 27, 2024
dbadff9
feat: basic actions completion modal updates
chambaz Nov 27, 2024
7d6e672
feat: and collat repay options to previous txn and update action comp…
chambaz Nov 27, 2024
71dda98
feat: update looper screen
borcherd Nov 27, 2024
9c83ec3
feat: update repay-colat screen
borcherd Nov 27, 2024
b62fe02
feat: minor style changes for collat repay / looping action complete …
chambaz Nov 27, 2024
5272979
fix: simulation loading state improvements
k0beLeenders Nov 27, 2024
a260262
fix: retry state improvements
k0beLeenders Nov 27, 2024
6b3b56d
Merge pull request #979 from mrgnlabs/feature/simulation-improvements
k0beLeenders Nov 27, 2024
b712459
chore: update lending actionComplete screen with correct amount
borcherd Nov 27, 2024
b395ce5
chore: update toast txnSign
borcherd Nov 27, 2024
99805a6
fix: loading state fix on error
k0beLeenders Nov 27, 2024
907c931
fix: clear simulation result if actionbox has closed
k0beLeenders Nov 27, 2024
f4fe075
chore: actionComplete screen updatedBankAmount
borcherd Nov 27, 2024
1f15966
feat: error improvement implementation & minor fixes
borcherd Nov 27, 2024
e0c6ce3
chore: update toast timeouts
borcherd Nov 27, 2024
acd6622
Merge pull request #982 from mrgnlabs/feature/error-toast-updates
k0beLeenders Nov 27, 2024
19ca0d6
chore: fix merge error
borcherd Nov 27, 2024
b3baea5
fix: add null check
borcherd Nov 27, 2024
a2c3cb8
fix: block height poller improvement, loop box integration styling
chambaz Nov 26, 2024
b01f590
fix: use css to hide / show actionbox and settings view instead of co…
chambaz Nov 26, 2024
2b9bdb7
fix: slippage tooltip copy
chambaz Nov 26, 2024
00b813d
feat: add usd value to actionbox / improve numeral formatting
chambaz Nov 27, 2024
1c95004
feat: portfolio upgrades, usd values, improved support for small numbers
chambaz Nov 27, 2024
eb6117f
chore: stake-screen updates
borcherd Nov 27, 2024
4eb316b
feat: enhanced actionbox warnings (wip)
chambaz Nov 23, 2024
6cf317a
chore: error messaging copy updates
chambaz Nov 27, 2024
663ebdb
fix: lend box imports
chambaz Nov 27, 2024
f4e4a87
fix: merge conflict undid fix
k0beLeenders Nov 27, 2024
81f68de
chore: cleared console log
k0beLeenders Nov 27, 2024
c86385d
feat: copy usd valud to all action inputs
chambaz Nov 28, 2024
a85aca9
feat: remove action box headings, adjust dialog padding
chambaz Nov 28, 2024
23803a7
fix: info action message label width
chambaz Nov 28, 2024
e52f2a0
feat: actionbox preview copy changes
chambaz Nov 28, 2024
f2897d6
fix: stake card responsive styling fixes
chambaz Nov 28, 2024
25ec10e
fix: show correct heading in action complete dialog
chambaz Nov 28, 2024
0869e34
fix: issue APP-818
borcherd Nov 28, 2024
b41e2c8
fix: APP-816
borcherd Nov 28, 2024
e3d767c
chore: remove console.logs
borcherd Nov 28, 2024
38fe74f
feat: move positions functions in sdk
k0beLeenders Nov 28, 2024
9dc902d
fix: added arena priorityFees missing fix
k0beLeenders Nov 28, 2024
7535c4f
fix: simulation fixes for flashloan transactions
k0beLeenders Nov 28, 2024
90c1dbe
Fix: APP-833 & APP-823 & APP-824
borcherd Nov 28, 2024
eea821c
Feat: update error and warning toast styling
borcherd Nov 28, 2024
3ba0f02
FIX: APP-828
borcherd Nov 28, 2024
cafd53a
fix: APP-829
borcherd Nov 28, 2024
fc0f2bb
fix: APP-825
borcherd Nov 28, 2024
f3fbe56
fix: APP-831
borcherd Nov 28, 2024
72b02af
feat: fetch account labels improvements
borcherd Nov 28, 2024
21c357c
Merge pull request #984 from mrgnlabs/fix/fetch-account-labels-improv…
borcherd Nov 28, 2024
3a20bf2
chore: add >1000 formatting
borcherd Nov 28, 2024
a6fbbcf
fix: not able to close lst dialog
k0beLeenders Nov 28, 2024
d37f97c
fix: portfolio asset card value formatting improved support for small…
chambaz Nov 28, 2024
7a2c8a8
fix: prevent infinite liquidation prices
chambaz Nov 28, 2024
3520bc7
fix: using wrong token for usd value in collat repay input
chambaz Nov 28, 2024
f2e8db4
fix: action message line breaking
chambaz Nov 28, 2024
956256c
fix: various a11y warnings
chambaz Nov 28, 2024
8737acb
fix: small number formatting in token select dropdown / repay collat …
chambaz Nov 28, 2024
87ba364
fix: rpc proxy in swap / bridge components
chambaz Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ export const Header = () => {
state.referralCode,
]
);
const { priorityType, broadcastType, maxCap, maxCapType, setTransactionSettings } = useUiStore((state) => ({
priorityType: state.priorityType,
broadcastType: state.broadcastType,
maxCap: state.maxCap,
maxCapType: state.maxCapType,
setTransactionSettings: state.setTransactionSettings,
}));
const { priorityType, broadcastType, priorityFees, maxCap, maxCapType, setTransactionSettings } = useUiStore(
(state) => ({
priorityType: state.priorityType,
broadcastType: state.broadcastType,
priorityFees: state.priorityFees,
maxCap: state.maxCap,
maxCapType: state.maxCapType,
setTransactionSettings: state.setTransactionSettings,
})
);
const { wallet } = useWallet();
const { asPath } = useRouter();
const isMobile = useIsMobile();
Expand Down Expand Up @@ -177,6 +180,10 @@ export const Header = () => {
wallet,
})
}
processOpts={{
...priorityFees,
broadcastType,
}}
headerComponent={
<div className="absolute left-1/2 -translate-x-1/2 flex flex-col items-center gap-2">
<CopyToClipboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const CreatePoolLoading = ({ poolCreatedData, setIsOpen, setIsCompleted }
group,
admin: wallet.publicKey,
seed,
priorityFee: 0, // todo
processOpts: { priorityFeeMicro: 0 }, // todo
});

if (!sig) throw new Error();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Image from "next/image";
import { IconMinus, IconX, IconPlus, IconLoader2 } from "@tabler/icons-react";
import { Transaction, VersionedTransaction } from "@solana/web3.js";

import { MultiStepToastHandle, cn, extractErrorString, capture, fetchPriorityFee } from "@mrgnlabs/mrgn-utils";
import { MultiStepToastHandle, cn, extractErrorString, capture, ClosePositionActionTxns } from "@mrgnlabs/mrgn-utils";
import { ActiveBankInfo, ActionType } from "@mrgnlabs/marginfi-v2-ui-state";

import { useConnection } from "~/hooks/use-connection";
Expand Down Expand Up @@ -41,11 +41,8 @@ export const PositionActionButtons = ({
const { connection } = useConnection();
const { wallet, connected } = useWallet();
const [platformFeeBps] = useUiStore((state) => [state.platformFeeBps]);
const [actionTransaction, setActionTransaction] = React.useState<{
closeTxn: VersionedTransaction | Transaction;
feedCrankTxs: VersionedTransaction[];
quote?: QuoteResponse;
} | null>(null);
const [actionTransaction, setActionTransaction] = React.useState<ClosePositionActionTxns | null>(null);

const [isLoading, setIsLoading] = React.useState(false);
const [multiStepToast, setMultiStepToast] = React.useState<MultiStepToastHandle | null>(null);
const [isClosing, setIsClosing] = React.useState(false);
Expand All @@ -56,16 +53,13 @@ export const PositionActionButtons = ({
state.setIsRefreshingStore,
state.nativeSolBalance,
]);
const [slippageBps, priorityType, broadcastType, maxCap, maxCapType, setIsActionComplete, setPreviousTxn] =
useUiStore((state) => [
state.slippageBps,
state.priorityType,
state.broadcastType,
state.maxCap,
state.maxCapType,
state.setIsActionComplete,
state.setPreviousTxn,
]);
const [slippageBps, priorityFees, broadcastType, setIsActionComplete, setPreviousTxn] = useUiStore((state) => [
state.slippageBps,
state.priorityFees,
state.broadcastType,
state.setIsActionComplete,
state.setPreviousTxn,
]);

const depositBanks = React.useMemo(() => {
const tokenBank = activeGroup.pool.token.isActive ? activeGroup.pool.token : null;
Expand Down Expand Up @@ -107,21 +101,18 @@ export const PositionActionButtons = ({
throw new Error("Invalid client");
}

const priorityFeeUi = await fetchPriorityFee(maxCapType, maxCap, broadcastType, priorityType, connection);

const txns = await calculateClosePositions({
marginfiAccount: activeGroup.selectedAccount,
depositBanks: depositBanks,
borrowBank: borrowBank,
slippageBps,
connection: connection,
priorityFee: priorityFeeUi,
platformFeeBps,
});

if ("description" in txns) {
throw new Error(txns?.description ?? "Something went wrong.");
} else if ("closeTxn" in txns) {
} else if ("actionTxn" in txns) {
setActionTransaction(txns);
}
} catch (error: any) {
Expand All @@ -134,38 +125,19 @@ export const PositionActionButtons = ({
setMultiStepToast(multiStepToast);
}
setIsClosing(false);
}, [
activeGroup,
borrowBank,
depositBanks,
maxCapType,
maxCap,
broadcastType,
priorityType,
connection,
slippageBps,
platformFeeBps,
]);
}, [activeGroup, borrowBank, depositBanks, connection, slippageBps, platformFeeBps]);

const processTransaction = React.useCallback(async () => {
try {
setIsLoading(true);
let txnSig: string | string[] = "";

if (!actionTransaction || !multiStepToast) throw new Error("Action not ready");
if (actionTransaction.closeTxn instanceof Transaction) {
txnSig = await activeGroup.client.processTransaction(actionTransaction.closeTxn);
multiStepToast.setSuccessAndNext();
} else {
txnSig = await activeGroup.client.processTransactions(
[...actionTransaction.feedCrankTxs, actionTransaction.closeTxn],
undefined,
undefined,
broadcastType,
true
);
multiStepToast.setSuccessAndNext();
}
if (!actionTransaction?.actionTxn || !multiStepToast) throw new Error("Action not ready");
txnSig = await activeGroup.client.processTransactions(
[...actionTransaction.additionalTxns, actionTransaction.actionTxn],
{ broadcastType: broadcastType, ...priorityFees }
);
multiStepToast.setSuccessAndNext();

if (txnSig) {
setActionTransaction(null);
Expand Down Expand Up @@ -215,14 +187,18 @@ export const PositionActionButtons = ({
}, [
actionTransaction,
multiStepToast,
activeGroup,
refreshGroup,
setIsRefreshingStore,
wallet,
connection,
activeGroup.client,
activeGroup.pool.token,
activeGroup.pool.quoteTokens,
activeGroup?.groupPk,
broadcastType,
priorityFees,
setIsActionComplete,
setPreviousTxn,
broadcastType,
setIsRefreshingStore,
refreshGroup,
connection,
wallet,
]);

const onClose = React.useCallback(() => {
Expand Down Expand Up @@ -425,40 +401,43 @@ export const PositionActionButtons = ({
</>
)}

{actionTransaction?.quote?.priceImpactPct && (
{actionTransaction?.actionQuote?.priceImpactPct && (
<>
<dt>Price impact</dt>
<dd
className={cn(
Number(actionTransaction.quote.priceImpactPct) > 0.05
Number(actionTransaction.actionQuote.priceImpactPct) > 0.05
? "text-mrgn-error"
: Number(actionTransaction.quote.priceImpactPct) > 0.01
: Number(actionTransaction.actionQuote.priceImpactPct) > 0.01
? "text-alert-foreground"
: "text-mrgn-success",
"text-right"
)}
>
{percentFormatter.format(Number(actionTransaction.quote.priceImpactPct))}
{percentFormatter.format(Number(actionTransaction.actionQuote.priceImpactPct))}
</dd>
</>
)}

{actionTransaction?.quote?.slippageBps && (
{actionTransaction?.actionQuote?.slippageBps && (
<>
<dt>Slippage</dt>
<dd
className={cn(actionTransaction.quote.slippageBps > 500 && "text-alert-foreground", "text-right")}
className={cn(
actionTransaction.actionQuote.slippageBps > 500 && "text-alert-foreground",
"text-right"
)}
>
{percentFormatter.format(Number(actionTransaction.quote.slippageBps) / 10000)}
{percentFormatter.format(Number(actionTransaction.actionQuote.slippageBps) / 10000)}
</dd>
</>
)}

<dt>Platform fee</dt>
{actionTransaction?.quote?.platformFee?.feeBps && (
{actionTransaction?.actionQuote?.platformFee?.feeBps && (
<>
<dd className="text-right">
{percentFormatter.format(actionTransaction.quote.platformFee.feeBps / 10000)}
{percentFormatter.format(actionTransaction.actionQuote.platformFee.feeBps / 10000)}
</dd>
</>
)}
Expand Down
Loading