@huma-finance/widgets 0.0.69-beta.840 → 0.0.69-beta.845

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.69-beta.840+6cc345b",
3
+ "version": "0.0.69-beta.845+96de165",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -29,9 +29,9 @@
29
29
  "@ethersproject/experimental": "^5.7.0",
30
30
  "@ethersproject/providers": "^5.6.0",
31
31
  "@ethersproject/units": "^5.6.0",
32
- "@huma-finance/sdk": "^0.0.69-beta.840+6cc345b",
33
- "@huma-finance/shared": "^0.0.69-beta.840+6cc345b",
34
- "@huma-finance/web-shared": "^0.0.69-beta.840+6cc345b",
32
+ "@huma-finance/sdk": "^0.0.69-beta.845+96de165",
33
+ "@huma-finance/shared": "^0.0.69-beta.845+96de165",
34
+ "@huma-finance/web-shared": "^0.0.69-beta.845+96de165",
35
35
  "@mui/x-date-pickers": "^5.0.7",
36
36
  "@notifi-network/notifi-frontend-client": "^1.1.2",
37
37
  "@notifi-network/notifi-react": "^1.1.2",
@@ -201,5 +201,5 @@
201
201
  "optionalDependencies": {
202
202
  "encoding": "^0.1.13"
203
203
  },
204
- "gitHead": "6cc345ba537842807a0c5744bbc0e0d20314d24e"
204
+ "gitHead": "96de165c93226572df1a2e5f3189efecf7540b78"
205
205
  }
@@ -0,0 +1,79 @@
1
+ import { UnderlyingTokenInfo } from '@huma-finance/shared'
2
+ import { Box, Divider, css, useTheme } from '@mui/material'
3
+ import React from 'react'
4
+ import { useDispatch } from 'react-redux'
5
+ import { setStep } from '../../../store/widgets.reducers'
6
+ import { WIDGET_STEP } from '../../../store/widgets.store'
7
+ import { BottomButton } from '../../BottomButton'
8
+ import { WrapperModal } from '../../WrapperModal'
9
+
10
+ type Props = {
11
+ poolUnderlyingToken: UnderlyingTokenInfo
12
+ withdrawableAmountFormatted: string | number
13
+ sharePrice: number
14
+ }
15
+
16
+ export function ConfirmTransfer({
17
+ poolUnderlyingToken,
18
+ withdrawableAmountFormatted,
19
+ sharePrice,
20
+ }: Props): React.ReactElement {
21
+ const theme = useTheme()
22
+ const dispatch = useDispatch()
23
+ const { symbol } = poolUnderlyingToken
24
+
25
+ const goToWithdraw = () => {
26
+ dispatch(setStep(WIDGET_STEP.Transfer))
27
+ }
28
+
29
+ const styles = {
30
+ itemWrapper: css`
31
+ margin-top: ${theme.spacing(9)};
32
+ color: ${theme.palette.text.primary};
33
+ font-weight: 400;
34
+ font-size: 16px;
35
+ line-height: 175%;
36
+ letter-spacing: 0.15px;
37
+ `,
38
+ item: css`
39
+ display: flex;
40
+ justify-content: space-between;
41
+ align-items: center;
42
+ margin-bottom: ${theme.spacing(3)};
43
+ `,
44
+ itemValue: css`
45
+ font-size: 20px;
46
+ font-weight: 700;
47
+ `,
48
+ divider: css`
49
+ border-color: ${theme.palette.divider};
50
+ margin-bottom: ${theme.spacing(3)};
51
+ `,
52
+ }
53
+
54
+ return (
55
+ <WrapperModal
56
+ title={`Withdraw ${symbol}`}
57
+ subTitle='Withdraw all the available amount'
58
+ >
59
+ <Box css={styles.itemWrapper}>
60
+ <Box css={styles.item}>
61
+ <Box>Price Per Share</Box>
62
+ <Box css={styles.itemValue}>
63
+ {sharePrice.toFixed(1)} {symbol}
64
+ </Box>
65
+ </Box>
66
+ <Divider css={styles.divider} orientation='horizontal' />
67
+ <Box css={styles.item}>
68
+ <Box fontWeight={700}>Available to withdraw</Box>
69
+ <Box css={styles.itemValue}>
70
+ {withdrawableAmountFormatted} {symbol}
71
+ </Box>
72
+ </Box>
73
+ </Box>
74
+ <BottomButton variant='contained' onClick={goToWithdraw}>
75
+ WITHDRAW
76
+ </BottomButton>
77
+ </WrapperModal>
78
+ )
79
+ }
@@ -0,0 +1,105 @@
1
+ import {
2
+ getTokenAccounts,
3
+ SolanaPoolInfo,
4
+ TrancheType,
5
+ } from '@huma-finance/shared'
6
+ import { useHumaProgram } from '@huma-finance/web-shared'
7
+ import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
8
+ import { useWallet } from '@solana/wallet-adapter-react'
9
+ import { Transaction } from '@solana/web3.js'
10
+ import React, { useCallback, useEffect, useState } from 'react'
11
+ import { useAppDispatch } from '../../../hooks/useRedux'
12
+ import { setStep } from '../../../store/widgets.reducers'
13
+ import { WIDGET_STEP } from '../../../store/widgets.store'
14
+ import { SolanaTxSendModal } from '../../SolanaTxSendModal'
15
+
16
+ type Props = {
17
+ poolInfo: SolanaPoolInfo
18
+ selectedTranche: TrancheType
19
+ poolIsClosed: boolean
20
+ }
21
+
22
+ export function Transfer({
23
+ poolInfo,
24
+ selectedTranche,
25
+ poolIsClosed,
26
+ }: Props): React.ReactElement | null {
27
+ const { publicKey } = useWallet()
28
+ const dispatch = useAppDispatch()
29
+ const program = useHumaProgram(poolInfo.chainId)
30
+ const [transaction, setTransaction] = useState<Transaction>()
31
+
32
+ useEffect(() => {
33
+ async function getTx() {
34
+ if (!publicKey || transaction) {
35
+ return
36
+ }
37
+
38
+ const tx = new Transaction()
39
+ const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
40
+ getTokenAccounts(poolInfo, publicKey)
41
+ const trancheMint =
42
+ selectedTranche === 'senior'
43
+ ? poolInfo.seniorTrancheMint
44
+ : poolInfo.juniorTrancheMint
45
+ const lenderTrancheToken =
46
+ selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA
47
+
48
+ if (!poolIsClosed) {
49
+ const disburseTx = await program.methods
50
+ .disburse()
51
+ .accountsPartial({
52
+ lender: publicKey,
53
+ humaConfig: poolInfo.humaConfig,
54
+ poolConfig: poolInfo.poolConfig,
55
+ underlyingMint: poolInfo.underlyingMint.address,
56
+ trancheMint,
57
+ poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
58
+ lenderUnderlyingToken: underlyingTokenATA,
59
+ tokenProgram: TOKEN_PROGRAM_ID,
60
+ })
61
+ .transaction()
62
+ tx.add(disburseTx)
63
+ } else {
64
+ const withdrawAfterPoolClosureTx = await program.methods
65
+ .withdrawAfterPoolClosure()
66
+ .accountsPartial({
67
+ lender: publicKey,
68
+ humaConfig: poolInfo.humaConfig,
69
+ poolConfig: poolInfo.poolConfig,
70
+ underlyingMint: poolInfo.underlyingMint.address,
71
+ trancheMint,
72
+ poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
73
+ lenderUnderlyingToken: underlyingTokenATA,
74
+ lenderTrancheToken,
75
+ underlyingTokenProgram: TOKEN_PROGRAM_ID,
76
+ trancheTokenProgram: TOKEN_2022_PROGRAM_ID,
77
+ })
78
+ .transaction()
79
+ tx.add(withdrawAfterPoolClosureTx)
80
+ }
81
+
82
+ setTransaction(tx)
83
+ }
84
+ getTx()
85
+ }, [
86
+ poolInfo,
87
+ poolIsClosed,
88
+ program.methods,
89
+ publicKey,
90
+ selectedTranche,
91
+ transaction,
92
+ ])
93
+
94
+ const handleSuccess = useCallback(() => {
95
+ dispatch(setStep(WIDGET_STEP.Done))
96
+ }, [dispatch])
97
+
98
+ return (
99
+ <SolanaTxSendModal
100
+ tx={transaction}
101
+ chainId={poolInfo.chainId}
102
+ handleSuccess={handleSuccess}
103
+ />
104
+ )
105
+ }
@@ -0,0 +1,32 @@
1
+ import { BN } from '@coral-xyz/anchor'
2
+ import {
3
+ formatMoneyFixed,
4
+ SolanaTokenUtils,
5
+ UnderlyingTokenInfo,
6
+ } from '@huma-finance/shared'
7
+ import React from 'react'
8
+ import { TxDoneModal } from '../../TxDoneModal'
9
+
10
+ type Props = {
11
+ poolUnderlyingToken: UnderlyingTokenInfo
12
+ withdrawAmount: BN
13
+ handleAction: () => void
14
+ }
15
+
16
+ export function Done({
17
+ poolUnderlyingToken,
18
+ withdrawAmount,
19
+ handleAction,
20
+ }: Props): React.ReactElement {
21
+ const { symbol } = poolUnderlyingToken
22
+ const withdrawAmountFormatted = formatMoneyFixed(
23
+ SolanaTokenUtils.formatUnits(withdrawAmount, poolUnderlyingToken.decimals),
24
+ 2,
25
+ )
26
+
27
+ const content = [
28
+ `You successfully withdrew ${withdrawAmountFormatted} ${symbol}.`,
29
+ ]
30
+
31
+ return <TxDoneModal handleAction={handleAction} content={content} />
32
+ }
@@ -0,0 +1,138 @@
1
+ import {
2
+ formatNumberFixed,
3
+ SolanaPoolInfo,
4
+ SolanaTokenUtils,
5
+ TrancheType,
6
+ } from '@huma-finance/shared'
7
+ import { LenderStateAccount, SolanaPoolState } from '@huma-finance/web-shared'
8
+ import React, { useCallback, useEffect, useState } from 'react'
9
+ import { useDispatch } from 'react-redux'
10
+
11
+ import { BN } from '@coral-xyz/anchor'
12
+ import { Mint } from '@solana/spl-token'
13
+ import { useAppSelector } from '../../../hooks/useRedux'
14
+ import { setStep } from '../../../store/widgets.reducers'
15
+ import { selectWidgetState } from '../../../store/widgets.selectors'
16
+ import { WIDGET_STEP } from '../../../store/widgets.store'
17
+ import { ErrorModal } from '../../ErrorModal'
18
+ import { WidgetWrapper } from '../../WidgetWrapper'
19
+ import { ConfirmTransfer } from './1-ConfirmTransfer'
20
+ import { Transfer } from './2-Transfer'
21
+ import { Done } from './3-Done'
22
+
23
+ /**
24
+ * Solana lend pool withdraw props
25
+ * @typedef {Object} SolanaLendWithdrawProps
26
+ * @property {SolanaPoolInfo} poolInfo The metadata of the pool.
27
+ * @property {SolanaPoolState} poolState The current state config of the pool.
28
+ * @property {LenderStateAccount} lenderStateAccount The lender state account of the user.
29
+ * @property {Mint} trancheMintAccount The mint account of the tranche.
30
+ * @property {TrancheType} trancheType The type of the tranche.
31
+ * @property {function():void} handleClose Function to notify to close the widget modal when user clicks the 'x' close button.
32
+ * @property {function((number|undefined)):void|undefined} handleSuccess Optional function to notify that the lending pool withdraw action is successful.
33
+ */
34
+ export type SolanaLendWithdrawProps = {
35
+ poolInfo: SolanaPoolInfo
36
+ poolState: SolanaPoolState
37
+ lenderStateAccount: LenderStateAccount
38
+ trancheMintAccount: Mint
39
+ trancheType: TrancheType
40
+ handleClose: () => void
41
+ handleSuccess?: (blockNumber?: number) => void
42
+ }
43
+
44
+ export function SolanaLendWithdraw({
45
+ poolInfo,
46
+ poolState,
47
+ lenderStateAccount,
48
+ trancheMintAccount,
49
+ trancheType,
50
+ handleClose,
51
+ handleSuccess,
52
+ }: SolanaLendWithdrawProps): React.ReactElement | null {
53
+ const dispatch = useDispatch()
54
+ const { step, errorMessage } = useAppSelector(selectWidgetState)
55
+ const { symbol, decimals } = poolInfo.underlyingMint
56
+ const title = `Withdraw ${symbol}`
57
+ const poolIsClosed = poolState.status === 'closed'
58
+ const [sharePrice, setSharePrice] = useState(0)
59
+ const { totalAmountProcessed, totalAmountWithdrawn } =
60
+ lenderStateAccount.redemptionRecord
61
+ const withdrawableAmount = totalAmountProcessed.sub(totalAmountWithdrawn)
62
+ const withdrawableAmountFormatted = formatNumberFixed(
63
+ SolanaTokenUtils.formatUnits(withdrawableAmount, decimals),
64
+ 2,
65
+ )
66
+
67
+ useEffect(() => {
68
+ if (!step) {
69
+ dispatch(setStep(WIDGET_STEP.ConfirmTransfer))
70
+ }
71
+ }, [dispatch, step])
72
+
73
+ useEffect(() => {
74
+ const trancheAssets =
75
+ trancheType === 'senior'
76
+ ? poolState.seniorTrancheAssets
77
+ : poolState.juniorTrancheAssets
78
+
79
+ const trancheAssetsVal = new BN(trancheAssets ?? 1)
80
+ const trancheSupplyVal = new BN(trancheMintAccount.supply.toString() ?? 1)
81
+ const sharePrice =
82
+ trancheAssetsVal.muln(100000).div(trancheSupplyVal).toNumber() / 100000
83
+ setSharePrice(sharePrice)
84
+ }, [
85
+ poolState.juniorTrancheAssets,
86
+ poolState.seniorTrancheAssets,
87
+ trancheMintAccount.supply,
88
+ trancheType,
89
+ ])
90
+
91
+ const handleWithdrawSuccess = useCallback(
92
+ (blockNumber: number) => {
93
+ if (handleSuccess) {
94
+ handleSuccess(blockNumber)
95
+ }
96
+ },
97
+ [handleSuccess],
98
+ )
99
+
100
+ return (
101
+ <WidgetWrapper
102
+ isOpen
103
+ loadingTitle={title}
104
+ handleClose={handleClose}
105
+ handleSuccess={handleWithdrawSuccess}
106
+ >
107
+ {step === WIDGET_STEP.ConfirmTransfer && (
108
+ <ConfirmTransfer
109
+ poolUnderlyingToken={poolInfo.underlyingMint}
110
+ withdrawableAmountFormatted={withdrawableAmountFormatted ?? '--'}
111
+ sharePrice={sharePrice}
112
+ />
113
+ )}
114
+ {step === WIDGET_STEP.Transfer && (
115
+ <Transfer
116
+ poolInfo={poolInfo}
117
+ selectedTranche={trancheType}
118
+ poolIsClosed={poolIsClosed}
119
+ />
120
+ )}
121
+ {step === WIDGET_STEP.Done && (
122
+ <Done
123
+ poolUnderlyingToken={poolInfo.underlyingMint}
124
+ withdrawAmount={withdrawableAmount}
125
+ handleAction={handleClose}
126
+ />
127
+ )}
128
+ {step === WIDGET_STEP.Error && (
129
+ <ErrorModal
130
+ title={title}
131
+ errorReason='Sorry there was an error'
132
+ errorMessage={errorMessage}
133
+ handleOk={handleClose}
134
+ />
135
+ )}
136
+ </WidgetWrapper>
137
+ )
138
+ }
package/src/index.tsx CHANGED
@@ -30,6 +30,14 @@ import {
30
30
  CreditLinePaymentPropsV2,
31
31
  CreditLinePaymentV2,
32
32
  } from './components/CreditLine/paymentV2'
33
+ import {
34
+ SolanaBorrow,
35
+ SolanaBorrowProps,
36
+ } from './components/CreditLine/solanaBorrow'
37
+ import {
38
+ SolanaPayment,
39
+ SolanaPaymentProps,
40
+ } from './components/CreditLine/solanaPayment'
33
41
  import {
34
42
  SupplyFirstLossCover,
35
43
  SupplyFirstLossCoverProps,
@@ -50,6 +58,30 @@ import {
50
58
  CancelRedemptionPropsV2,
51
59
  CancelRedemptionV2,
52
60
  } from './components/Lend/cancelRedemptionV2 '
61
+ import {
62
+ SolanaLendAddRedemption,
63
+ SolanaLendAddRedemptionProps,
64
+ } from './components/Lend/solanaAddRedemption'
65
+ import {
66
+ SolanaLendCancelRedemption,
67
+ SolanaLendCancelRedemptionProps,
68
+ } from './components/Lend/solanaCancelRedemption'
69
+ import {
70
+ SolanaEnableAutoRedemption,
71
+ SolanaEnableAutoRedemptionProps,
72
+ } from './components/Lend/solanaEnableAutoRedemption'
73
+ import {
74
+ SolanaLendSupply,
75
+ SolanaLendSupplyProps,
76
+ } from './components/Lend/solanaSupply'
77
+ import {
78
+ SolanaLendWithdraw,
79
+ SolanaLendWithdrawProps,
80
+ } from './components/Lend/solanaWithdraw'
81
+ import {
82
+ StellarLendSupply,
83
+ StellarLendSupplyProps,
84
+ } from './components/Lend/stellarSupply'
53
85
  import { LendSupply, LendSupplyProps } from './components/Lend/supply'
54
86
  import { LendSupplyPropsV2, LendSupplyV2 } from './components/Lend/supplyV2'
55
87
  import { LendWithdraw, LendWithdrawProps } from './components/Lend/withdraw'
@@ -57,6 +89,7 @@ import {
57
89
  LendWithdrawPropsV2,
58
90
  LendWithdrawV2,
59
91
  } from './components/Lend/withdrawV2'
92
+ import { NotifiContextWrapper } from './components/Notifi/NotifiContextWrapper'
60
93
  import {
61
94
  ReceivableBackedCreditLineBorrowPropsV2,
62
95
  ReceivableBackedCreditLineBorrowV2,
@@ -69,35 +102,6 @@ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
69
102
  import { store } from './store'
70
103
  import { themeHuma } from './theme'
71
104
  import { WCProps } from './utilTypes'
72
- import {
73
- SolanaLendSupply,
74
- SolanaLendSupplyProps,
75
- } from './components/Lend/solanaSupply'
76
- import {
77
- SolanaLendAddRedemption,
78
- SolanaLendAddRedemptionProps,
79
- } from './components/Lend/solanaAddRedemption'
80
- import {
81
- SolanaLendCancelRedemption,
82
- SolanaLendCancelRedemptionProps,
83
- } from './components/Lend/solanaCancelRedemption'
84
- import {
85
- SolanaBorrow,
86
- SolanaBorrowProps,
87
- } from './components/CreditLine/solanaBorrow'
88
- import {
89
- SolanaPayment,
90
- SolanaPaymentProps,
91
- } from './components/CreditLine/solanaPayment'
92
- import { NotifiContextWrapper } from './components/Notifi/NotifiContextWrapper'
93
- import {
94
- StellarLendSupply,
95
- StellarLendSupplyProps,
96
- } from './components/Lend/stellarSupply'
97
- import {
98
- SolanaEnableAutoRedemption,
99
- SolanaEnableAutoRedemptionProps,
100
- } from './components/Lend/solanaEnableAutoRedemption'
101
105
 
102
106
  /**
103
107
  * Mapping of your JSON-RPC connections indexed by chainId
@@ -675,6 +679,20 @@ export function SolanaPaymentWidget(props: SolanaPaymentWidgetProps) {
675
679
  )
676
680
  }
677
681
 
682
+ /**
683
+ * Solana lend withdraw widget
684
+ *
685
+ * @param {SolanaLendWithdrawProps} props - The solana lend pool withdraw widget props.
686
+ * @returns Solana lend pool withdraw widget component
687
+ */
688
+ export function SolanaLendWithdrawWidget(props: SolanaLendWithdrawProps) {
689
+ return (
690
+ <GenericWidget {...props}>
691
+ <SolanaLendWithdraw {...props} />
692
+ </GenericWidget>
693
+ )
694
+ }
695
+
678
696
  /**
679
697
  * Lend pool supply widget props for Stellar pools
680
698
  * @typedef {Object} StellarLendSupplyWidgetProps