@huma-finance/widgets 0.0.62-beta.612 → 0.0.62-beta.618
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/dist/cjs/index.cjs +735 -1448
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +433 -1167
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +2 -2
- package/src/components/CreditLine/solanaBorrow/2-ApproveAllowance.tsx +5 -3
- package/src/components/Lend/solanaAddRedemption/2-ChooseAmount.tsx +5 -5
- package/src/components/Lend/solanaAddRedemption/index.tsx +6 -2
- package/src/components/Lend/solanaCancelRedemption/index.tsx +2 -2
- package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +8 -6
- package/src/components/Lend/solanaSupply/4-Transfer.tsx +51 -3
- package/src/components/Lend/solanaSupply/index.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.62-beta.
|
|
3
|
+
"version": "0.0.62-beta.618+0bd4a98",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@apollo/client": "^3.7.2",
|
|
23
23
|
"@coinbase/wallet-sdk": "^3.5.3",
|
|
24
|
-
"@emotion/react": "^11.5.0",
|
|
25
|
-
"@emotion/styled": "^11.3.0",
|
|
26
24
|
"@ethersproject/address": "^5.7.0",
|
|
27
25
|
"@ethersproject/bignumber": "^5.6.0",
|
|
28
26
|
"@ethersproject/constants": "^5.7.0",
|
|
@@ -30,14 +28,9 @@
|
|
|
30
28
|
"@ethersproject/experimental": "^5.7.0",
|
|
31
29
|
"@ethersproject/providers": "^5.6.0",
|
|
32
30
|
"@ethersproject/units": "^5.6.0",
|
|
33
|
-
"@huma-finance/sdk": "^0.0.62-beta.
|
|
34
|
-
"@huma-finance/shared": "^0.0.62-beta.
|
|
35
|
-
"@huma-finance/web-shared": "^0.0.62-beta.
|
|
36
|
-
"@mui/icons-material": "^5.3.0",
|
|
37
|
-
"@mui/material": "^5.0.6",
|
|
38
|
-
"@mui/styles": "^5.0.2",
|
|
39
|
-
"@mui/system": "^5.0.6",
|
|
40
|
-
"@mui/x-date-pickers": "^5.0.7",
|
|
31
|
+
"@huma-finance/sdk": "^0.0.62-beta.618+0bd4a98",
|
|
32
|
+
"@huma-finance/shared": "^0.0.62-beta.618+0bd4a98",
|
|
33
|
+
"@huma-finance/web-shared": "^0.0.62-beta.618+0bd4a98",
|
|
41
34
|
"@notifi-network/notifi-frontend-client": "^0.91.1",
|
|
42
35
|
"@reduxjs/toolkit": "^1.8.6",
|
|
43
36
|
"@types/utf8": "^3.0.1",
|
|
@@ -187,6 +180,13 @@
|
|
|
187
180
|
},
|
|
188
181
|
"peerDependencies": {
|
|
189
182
|
"@coral-xyz/anchor": "^0.30.1",
|
|
183
|
+
"@emotion/react": "^11.5.0",
|
|
184
|
+
"@emotion/styled": "^11.3.0",
|
|
185
|
+
"@mui/icons-material": "^5.3.0",
|
|
186
|
+
"@mui/material": "^5.0.6",
|
|
187
|
+
"@mui/styles": "^5.0.2",
|
|
188
|
+
"@mui/system": "^5.0.6",
|
|
189
|
+
"@mui/x-date-pickers": "^5.0.7",
|
|
190
190
|
"@solana/spl-token": "^0.4.8",
|
|
191
191
|
"@solana/wallet-adapter-base": "^0.9.23",
|
|
192
192
|
"@solana/wallet-adapter-react": "^0.15.35",
|
|
@@ -200,5 +200,5 @@
|
|
|
200
200
|
"optionalDependencies": {
|
|
201
201
|
"encoding": "^0.1.13"
|
|
202
202
|
},
|
|
203
|
-
"gitHead": "
|
|
203
|
+
"gitHead": "0bd4a983d62b8318e2f189a22288510eb16e490c"
|
|
204
204
|
}
|
|
@@ -55,7 +55,7 @@ export function ChooseAmount({
|
|
|
55
55
|
decimals,
|
|
56
56
|
)
|
|
57
57
|
const nextStep =
|
|
58
|
-
borrowAmountBN.gt(new BN(tokenAccount.delegatedAmount)) ||
|
|
58
|
+
borrowAmountBN.gt(new BN(tokenAccount.delegatedAmount.toString())) ||
|
|
59
59
|
tokenAccount.delegate?.toString() !== sentinel
|
|
60
60
|
? WIDGET_STEP.ApproveAllowance
|
|
61
61
|
: WIDGET_STEP.Transfer
|
|
@@ -63,7 +63,7 @@ export function ChooseAmount({
|
|
|
63
63
|
dispatch(
|
|
64
64
|
setBorrowInfo({
|
|
65
65
|
borrowAmount: currentAmount,
|
|
66
|
-
borrowAmountBN,
|
|
66
|
+
borrowAmountBN: JSON.parse(borrowAmountBN.toString()),
|
|
67
67
|
chargedFees: 0,
|
|
68
68
|
nextStep,
|
|
69
69
|
}),
|
|
@@ -51,9 +51,11 @@ export function ApproveAllowance({
|
|
|
51
51
|
new PublicKey(poolInfo.underlyingMint.address),
|
|
52
52
|
new PublicKey(sentinel), // delegate
|
|
53
53
|
publicKey, // owner of the wallet
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
BigInt(
|
|
55
|
+
SolanaTokenUtils.parseUnits(
|
|
56
|
+
'100000000000', // 100 billion
|
|
57
|
+
poolInfo.underlyingMint.decimals,
|
|
58
|
+
).toString(),
|
|
57
59
|
), // amount
|
|
58
60
|
poolInfo.underlyingMint.decimals,
|
|
59
61
|
undefined, // multiSigners
|
|
@@ -58,8 +58,8 @@ export function ChooseAmount({
|
|
|
58
58
|
|
|
59
59
|
return SolanaTokenUtils.formatUnits(
|
|
60
60
|
selectedTranche === 'senior'
|
|
61
|
-
? new BN(seniorTokenAccount?.amount)
|
|
62
|
-
: new BN(juniorTokenAccount?.amount),
|
|
61
|
+
? new BN(seniorTokenAccount?.amount?.toString() ?? 0)
|
|
62
|
+
: new BN(juniorTokenAccount?.amount?.toString() ?? 0),
|
|
63
63
|
mintAccount.decimals,
|
|
64
64
|
)
|
|
65
65
|
}, [
|
|
@@ -76,7 +76,7 @@ export function ChooseAmount({
|
|
|
76
76
|
|
|
77
77
|
const mintSupplyFormatted = Number(
|
|
78
78
|
SolanaTokenUtils.formatUnits(
|
|
79
|
-
new BN(mintAccount.supply),
|
|
79
|
+
new BN(mintAccount.supply.toString()),
|
|
80
80
|
mintAccount.decimals,
|
|
81
81
|
),
|
|
82
82
|
)
|
|
@@ -87,7 +87,7 @@ export function ChooseAmount({
|
|
|
87
87
|
|
|
88
88
|
const seniorTrancheAssetsFormatted = Number(
|
|
89
89
|
SolanaTokenUtils.formatUnits(
|
|
90
|
-
new BN(poolState?.seniorTrancheAssets),
|
|
90
|
+
new BN(poolState?.seniorTrancheAssets ?? 0),
|
|
91
91
|
mintAccount.decimals,
|
|
92
92
|
),
|
|
93
93
|
)
|
|
@@ -98,7 +98,7 @@ export function ChooseAmount({
|
|
|
98
98
|
|
|
99
99
|
const juniorTrancheAssetsFormatted = Number(
|
|
100
100
|
SolanaTokenUtils.formatUnits(
|
|
101
|
-
new BN(poolState?.juniorTrancheAssets),
|
|
101
|
+
new BN(poolState?.juniorTrancheAssets ?? 0),
|
|
102
102
|
mintAccount.decimals,
|
|
103
103
|
),
|
|
104
104
|
)
|
|
@@ -55,8 +55,12 @@ export function SolanaLendAddRedemption({
|
|
|
55
55
|
|
|
56
56
|
useEffect(() => {
|
|
57
57
|
if (!step && !isLoadingLenderAccounts && !isLoadingTokenAccounts) {
|
|
58
|
-
const seniorTrancheShares = new BN(
|
|
59
|
-
|
|
58
|
+
const seniorTrancheShares = new BN(
|
|
59
|
+
seniorTokenAccount?.amount?.toString() ?? 0,
|
|
60
|
+
)
|
|
61
|
+
const juniorTrancheShares = new BN(
|
|
62
|
+
juniorTokenAccount?.amount?.toString() ?? 0,
|
|
63
|
+
)
|
|
60
64
|
|
|
61
65
|
if (juniorTrancheShares.gtn(0) && seniorTrancheShares.lten(0)) {
|
|
62
66
|
setSelectedTranche('junior')
|
|
@@ -46,10 +46,10 @@ export function SolanaLendCancelRedemption({
|
|
|
46
46
|
useEffect(() => {
|
|
47
47
|
if (!step && !isLoadingLenderAccounts) {
|
|
48
48
|
const seniorTrancheSharesRequested = new BN(
|
|
49
|
-
seniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
49
|
+
seniorLenderStateAccount?.redemptionRecord.numSharesRequested ?? 0,
|
|
50
50
|
)
|
|
51
51
|
const juniorTrancheSharesRequested = new BN(
|
|
52
|
-
juniorLenderStateAccount?.redemptionRecord.numSharesRequested,
|
|
52
|
+
juniorLenderStateAccount?.redemptionRecord.numSharesRequested ?? 0,
|
|
53
53
|
)
|
|
54
54
|
|
|
55
55
|
if (
|
|
@@ -18,7 +18,7 @@ type Props = {
|
|
|
18
18
|
poolState: SolanaPoolState
|
|
19
19
|
tokenAccount: Account
|
|
20
20
|
selectedTranche: TrancheType | undefined
|
|
21
|
-
isUniTranche
|
|
21
|
+
isUniTranche?: boolean
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export function ChooseAmount({
|
|
@@ -32,7 +32,7 @@ export function ChooseAmount({
|
|
|
32
32
|
const { symbol, decimals } = poolInfo.underlyingMint
|
|
33
33
|
const [currentAmount, setCurrentAmount] = useState<number | string>(0)
|
|
34
34
|
const balance = useMemo(
|
|
35
|
-
() => new BN(tokenAccount.amount),
|
|
35
|
+
() => new BN(tokenAccount.amount.toString()),
|
|
36
36
|
[tokenAccount.amount],
|
|
37
37
|
)
|
|
38
38
|
|
|
@@ -43,11 +43,13 @@ export function ChooseAmount({
|
|
|
43
43
|
seniorTrancheAssets,
|
|
44
44
|
juniorTrancheAssets,
|
|
45
45
|
} = poolState
|
|
46
|
-
const juniorTrancheAssetsBN = new BN(juniorTrancheAssets)
|
|
47
|
-
const seniorTrancheAssetsBN = new BN(seniorTrancheAssets)
|
|
46
|
+
const juniorTrancheAssetsBN = new BN(juniorTrancheAssets ?? 0)
|
|
47
|
+
const seniorTrancheAssetsBN = new BN(seniorTrancheAssets ?? 0)
|
|
48
48
|
const totalDeployedBN = seniorTrancheAssetsBN.add(juniorTrancheAssetsBN)
|
|
49
|
-
const totalAvailableCapBN = new BN(liquidityCap).sub(totalDeployedBN)
|
|
50
|
-
const maxSeniorAssetsBN = juniorTrancheAssetsBN.muln(
|
|
49
|
+
const totalAvailableCapBN = new BN(liquidityCap ?? 0).sub(totalDeployedBN)
|
|
50
|
+
const maxSeniorAssetsBN = juniorTrancheAssetsBN.muln(
|
|
51
|
+
maxSeniorJuniorRatio ?? 0,
|
|
52
|
+
)
|
|
51
53
|
let seniorAvailableCapBN = maxSeniorAssetsBN.sub(seniorTrancheAssetsBN)
|
|
52
54
|
seniorAvailableCapBN = seniorAvailableCapBN.gt(totalAvailableCapBN)
|
|
53
55
|
? totalAvailableCapBN
|
|
@@ -8,13 +8,14 @@ import React, { useCallback, useEffect, useState } from 'react'
|
|
|
8
8
|
|
|
9
9
|
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token'
|
|
10
10
|
import { useWallet } from '@solana/wallet-adapter-react'
|
|
11
|
-
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
11
|
+
import { useHumaProgram, useLenderAccounts } from '@huma-finance/web-shared'
|
|
12
12
|
import { Transaction } from '@solana/web3.js'
|
|
13
13
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
14
14
|
import { setStep } from '../../../store/widgets.reducers'
|
|
15
15
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
16
16
|
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
17
17
|
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
18
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
18
19
|
|
|
19
20
|
type Props = {
|
|
20
21
|
poolInfo: SolanaPoolInfo
|
|
@@ -34,6 +35,13 @@ export function Transfer({
|
|
|
34
35
|
decimals,
|
|
35
36
|
)
|
|
36
37
|
const [transaction, setTransaction] = useState<Transaction>()
|
|
38
|
+
const {
|
|
39
|
+
juniorLenderApprovedAccountPDA,
|
|
40
|
+
seniorLenderApprovedAccountPDA,
|
|
41
|
+
seniorLenderStateAccount,
|
|
42
|
+
juniorLenderStateAccount,
|
|
43
|
+
loading: isLoadingLenderAccounts,
|
|
44
|
+
} = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
|
|
37
45
|
const program = useHumaProgram(poolInfo.chainId)
|
|
38
46
|
|
|
39
47
|
const handleSuccess = useCallback(() => {
|
|
@@ -42,13 +50,43 @@ export function Transfer({
|
|
|
42
50
|
|
|
43
51
|
useEffect(() => {
|
|
44
52
|
async function getTx() {
|
|
45
|
-
if (!publicKey || transaction) {
|
|
53
|
+
if (!publicKey || transaction || isLoadingLenderAccounts) {
|
|
46
54
|
return
|
|
47
55
|
}
|
|
48
56
|
|
|
57
|
+
const tx = new Transaction()
|
|
58
|
+
|
|
49
59
|
const { underlyingTokenATA, seniorTrancheATA, juniorTrancheATA } =
|
|
50
60
|
getTokenAccounts(poolInfo, publicKey)
|
|
51
|
-
|
|
61
|
+
if (
|
|
62
|
+
(selectedTranche === 'senior' && !seniorLenderStateAccount) ||
|
|
63
|
+
(selectedTranche === 'junior' && !juniorLenderStateAccount)
|
|
64
|
+
) {
|
|
65
|
+
const createLenderAccountsTx = await program.methods
|
|
66
|
+
.createLenderAccounts()
|
|
67
|
+
.accountsPartial({
|
|
68
|
+
lender: publicKey,
|
|
69
|
+
humaConfig: poolInfo.humaConfig,
|
|
70
|
+
poolConfig: poolInfo.poolConfig,
|
|
71
|
+
approvedLender:
|
|
72
|
+
selectedTranche === 'senior'
|
|
73
|
+
? seniorLenderApprovedAccountPDA!
|
|
74
|
+
: juniorLenderApprovedAccountPDA!,
|
|
75
|
+
trancheMint:
|
|
76
|
+
selectedTranche === 'senior'
|
|
77
|
+
? poolInfo.seniorTrancheMint
|
|
78
|
+
: poolInfo.juniorTrancheMint,
|
|
79
|
+
lenderTrancheToken:
|
|
80
|
+
selectedTranche === 'senior'
|
|
81
|
+
? seniorTrancheATA
|
|
82
|
+
: juniorTrancheATA,
|
|
83
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
84
|
+
})
|
|
85
|
+
.transaction()
|
|
86
|
+
tx.add(createLenderAccountsTx)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const depositTx = await program.methods
|
|
52
90
|
.deposit(supplyBigNumber)
|
|
53
91
|
.accountsPartial({
|
|
54
92
|
depositor: publicKey,
|
|
@@ -66,19 +104,29 @@ export function Transfer({
|
|
|
66
104
|
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
67
105
|
})
|
|
68
106
|
.transaction()
|
|
107
|
+
tx.add(depositTx)
|
|
69
108
|
|
|
70
109
|
setTransaction(tx)
|
|
71
110
|
}
|
|
72
111
|
getTx()
|
|
73
112
|
}, [
|
|
113
|
+
isLoadingLenderAccounts,
|
|
114
|
+
juniorLenderApprovedAccountPDA,
|
|
115
|
+
juniorLenderStateAccount,
|
|
74
116
|
poolInfo,
|
|
75
117
|
program.methods,
|
|
76
118
|
publicKey,
|
|
77
119
|
selectedTranche,
|
|
120
|
+
seniorLenderApprovedAccountPDA,
|
|
121
|
+
seniorLenderStateAccount,
|
|
78
122
|
supplyBigNumber,
|
|
79
123
|
transaction,
|
|
80
124
|
])
|
|
81
125
|
|
|
126
|
+
if (isLoadingLenderAccounts) {
|
|
127
|
+
return <LoadingModal title='Supply' />
|
|
128
|
+
}
|
|
129
|
+
|
|
82
130
|
return (
|
|
83
131
|
<SolanaTxSendModal
|
|
84
132
|
tx={transaction}
|
|
@@ -40,6 +40,7 @@ export function SolanaLendSupply({
|
|
|
40
40
|
handleSuccess,
|
|
41
41
|
}: SolanaLendSupplyProps): React.ReactElement | null {
|
|
42
42
|
const dispatch = useDispatch()
|
|
43
|
+
const { isUniTranche } = poolState
|
|
43
44
|
const {
|
|
44
45
|
seniorLenderApproved,
|
|
45
46
|
juniorLenderApproved,
|
|
@@ -47,7 +48,6 @@ export function SolanaLendSupply({
|
|
|
47
48
|
} = useLenderAccounts(poolInfo.chainId, poolInfo.poolName)
|
|
48
49
|
const [tokenAccount, isLoadingTokenAccount] = useTokenAccount(poolInfo)
|
|
49
50
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
50
|
-
const isUniTranche = poolState.maxSeniorJuniorRatio === 0
|
|
51
51
|
const [selectedTranche, setSelectedTranche] = useState<TrancheType>()
|
|
52
52
|
|
|
53
53
|
useEffect(() => {
|