@huma-finance/widgets 0.0.62-beta.631 → 0.0.62-beta.633
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/API.md +0 -194
- package/dist/cjs/index.cjs +258 -1866
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -136
- package/dist/index.js +261 -1864
- package/dist/index.js.map +1 -1
- package/package.json +8 -18
- package/src/components/CreditLine/paymentV2/1-ChooseAmount.tsx +0 -1
- package/src/components/InputAmountModal.tsx +2 -13
- package/src/components/Lend/supplyV2/6-Success.tsx +3 -3
- package/src/components/WidgetWrapper.tsx +4 -6
- package/src/index.tsx +0 -139
- package/src/store/widgets.reducers.ts +0 -5
- package/src/store/widgets.store.ts +0 -1
- package/src/components/CreditLine/solanaBorrow/1-ChooseAmount.tsx +0 -67
- package/src/components/CreditLine/solanaBorrow/2-Transfer.tsx +0 -159
- package/src/components/CreditLine/solanaBorrow/3-Done.tsx +0 -38
- package/src/components/CreditLine/solanaBorrow/index.tsx +0 -90
- package/src/components/CreditLine/solanaPayment/1-ChooseAmount.tsx +0 -75
- package/src/components/CreditLine/solanaPayment/2-Transfer.tsx +0 -92
- package/src/components/CreditLine/solanaPayment/3-Done.tsx +0 -59
- package/src/components/CreditLine/solanaPayment/index.tsx +0 -83
- package/src/components/Lend/solanaAddRedemption/1-ChooseTranche.tsx +0 -114
- package/src/components/Lend/solanaAddRedemption/2-ChooseAmount.tsx +0 -183
- package/src/components/Lend/solanaAddRedemption/3-Transfer.tsx +0 -102
- package/src/components/Lend/solanaAddRedemption/4-Done.tsx +0 -29
- package/src/components/Lend/solanaAddRedemption/index.tsx +0 -155
- package/src/components/Lend/solanaCancelRedemption/1-ChooseTranche.tsx +0 -114
- package/src/components/Lend/solanaCancelRedemption/2-Transfer.tsx +0 -99
- package/src/components/Lend/solanaCancelRedemption/3-Done.tsx +0 -55
- package/src/components/Lend/solanaCancelRedemption/index.tsx +0 -162
- package/src/components/Lend/solanaSupply/1-Evaluation.tsx +0 -106
- package/src/components/Lend/solanaSupply/2-ChooseTranche.tsx +0 -116
- package/src/components/Lend/solanaSupply/3-ChooseAmount.tsx +0 -131
- package/src/components/Lend/solanaSupply/4-Transfer.tsx +0 -137
- package/src/components/Lend/solanaSupply/5-Success.tsx +0 -52
- package/src/components/Lend/solanaSupply/index.tsx +0 -155
- package/src/components/SolanaTxDoneModal.tsx +0 -119
- package/src/components/SolanaTxSendModal.tsx +0 -61
- package/src/components/SolanaViewOnExplorer.tsx +0 -29
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.633+de08f40",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,6 +21,8 @@
|
|
|
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",
|
|
24
26
|
"@ethersproject/address": "^5.7.0",
|
|
25
27
|
"@ethersproject/bignumber": "^5.6.0",
|
|
26
28
|
"@ethersproject/bytes": "^5.7.0",
|
|
@@ -29,9 +31,9 @@
|
|
|
29
31
|
"@ethersproject/experimental": "^5.7.0",
|
|
30
32
|
"@ethersproject/providers": "^5.6.0",
|
|
31
33
|
"@ethersproject/units": "^5.6.0",
|
|
32
|
-
"@huma-finance/sdk": "^0.0.62-beta.
|
|
33
|
-
"@huma-finance/shared": "^0.0.
|
|
34
|
-
"@huma-finance/web-shared": "^0.0.
|
|
34
|
+
"@huma-finance/sdk": "^0.0.62-beta.633+de08f40",
|
|
35
|
+
"@huma-finance/shared": "^0.0.61",
|
|
36
|
+
"@huma-finance/web-shared": "^0.0.61",
|
|
35
37
|
"@mui/icons-material": "^5.3.0",
|
|
36
38
|
"@mui/material": "^5.0.6",
|
|
37
39
|
"@mui/styles": "^5.0.2",
|
|
@@ -76,7 +78,7 @@
|
|
|
76
78
|
"react-router-dom": "^5.3.0",
|
|
77
79
|
"react-scripts": "5.0.1",
|
|
78
80
|
"tslib": "^2.5.0",
|
|
79
|
-
"typescript": "^
|
|
81
|
+
"typescript": "^4.8.4",
|
|
80
82
|
"utf8": "^3.0.0",
|
|
81
83
|
"web-vitals": "^2.1.4",
|
|
82
84
|
"yup": "^0.32.11"
|
|
@@ -186,18 +188,6 @@
|
|
|
186
188
|
"wagmi": "^0.12.10"
|
|
187
189
|
},
|
|
188
190
|
"peerDependencies": {
|
|
189
|
-
"@coral-xyz/anchor": "^0.30.1",
|
|
190
|
-
"@emotion/react": "^11.5.0",
|
|
191
|
-
"@emotion/styled": "^11.3.0",
|
|
192
|
-
"@mui/icons-material": "^5.3.0",
|
|
193
|
-
"@mui/material": "^5.0.6",
|
|
194
|
-
"@mui/styles": "^5.0.2",
|
|
195
|
-
"@mui/system": "^5.0.6",
|
|
196
|
-
"@mui/x-date-pickers": "^5.0.7",
|
|
197
|
-
"@solana/spl-token": "^0.4.8",
|
|
198
|
-
"@solana/wallet-adapter-base": "^0.9.23",
|
|
199
|
-
"@solana/wallet-adapter-react": "^0.15.35",
|
|
200
|
-
"@solana/web3.js": "^1.95.3",
|
|
201
191
|
"ethers": "^5.6.1",
|
|
202
192
|
"react": ">=16.8.0",
|
|
203
193
|
"react-dom": ">=16.8.0",
|
|
@@ -207,5 +197,5 @@
|
|
|
207
197
|
"optionalDependencies": {
|
|
208
198
|
"encoding": "^0.1.13"
|
|
209
199
|
},
|
|
210
|
-
"gitHead": "
|
|
200
|
+
"gitHead": "de08f401ed13fbb79a89ccb48e066ad217d6d1bc"
|
|
211
201
|
}
|
|
@@ -20,7 +20,6 @@ type Props = {
|
|
|
20
20
|
tokenSymbol: string
|
|
21
21
|
suffix?: string
|
|
22
22
|
currentAmount: number | string
|
|
23
|
-
minimumAmount?: number
|
|
24
23
|
maxAmount: number | string
|
|
25
24
|
maxAmountText?: string
|
|
26
25
|
maxAmountTitle?: string
|
|
@@ -36,7 +35,6 @@ export function InputAmountModal({
|
|
|
36
35
|
tokenSymbol,
|
|
37
36
|
suffix: defaultSuffix,
|
|
38
37
|
currentAmount,
|
|
39
|
-
minimumAmount,
|
|
40
38
|
maxAmount,
|
|
41
39
|
maxAmountText = 'MAX',
|
|
42
40
|
maxAmountTitle,
|
|
@@ -93,7 +91,6 @@ export function InputAmountModal({
|
|
|
93
91
|
font-size: 13px;
|
|
94
92
|
line-height: 22px;
|
|
95
93
|
letter-spacing: 0.46px;
|
|
96
|
-
white-space: nowrap;
|
|
97
94
|
`,
|
|
98
95
|
info: css`
|
|
99
96
|
color: ${theme.palette.text.secondary};
|
|
@@ -128,9 +125,6 @@ export function InputAmountModal({
|
|
|
128
125
|
if (!isEmpty(maxAmount) && Number(currentAmount) > Number(maxAmount)) {
|
|
129
126
|
return true
|
|
130
127
|
}
|
|
131
|
-
if (!isEmpty(minimumAmount) && Number(currentAmount) < minimumAmount!) {
|
|
132
|
-
return true
|
|
133
|
-
}
|
|
134
128
|
return false
|
|
135
129
|
}
|
|
136
130
|
|
|
@@ -163,6 +157,7 @@ export function InputAmountModal({
|
|
|
163
157
|
/>
|
|
164
158
|
</Box>
|
|
165
159
|
</Box>
|
|
160
|
+
|
|
166
161
|
{infos && (
|
|
167
162
|
<Box>
|
|
168
163
|
{infos.map((info) => (
|
|
@@ -172,13 +167,7 @@ export function InputAmountModal({
|
|
|
172
167
|
))}
|
|
173
168
|
</Box>
|
|
174
169
|
)}
|
|
175
|
-
|
|
176
|
-
<Box>
|
|
177
|
-
<Typography css={styles.info} key='minDeposit'>
|
|
178
|
-
Minimum deposit: {minimumAmount} {tokenSymbol}
|
|
179
|
-
</Typography>
|
|
180
|
-
</Box>
|
|
181
|
-
)}
|
|
170
|
+
|
|
182
171
|
<BottomButton
|
|
183
172
|
variant='contained'
|
|
184
173
|
onClick={handleAction}
|
|
@@ -90,13 +90,13 @@ export function Success({
|
|
|
90
90
|
]
|
|
91
91
|
|
|
92
92
|
const getSubContent = () => {
|
|
93
|
-
const
|
|
93
|
+
const redemptionTime = dayjs()
|
|
94
94
|
.add(lpConfig.withdrawalLockoutPeriodInDays, 'day')
|
|
95
95
|
.date(1)
|
|
96
|
-
const withdrawTime =
|
|
96
|
+
const withdrawTime = redemptionTime.add(1, 'month')
|
|
97
97
|
return [
|
|
98
98
|
`You can begin submitting redemption requests on ${timeUtil.timestampToLL(
|
|
99
|
-
|
|
99
|
+
redemptionTime.unix(),
|
|
100
100
|
)}, which can be redeemed starting ${timeUtil.timestampToLL(
|
|
101
101
|
withdrawTime.unix(),
|
|
102
102
|
)}.`,
|
|
@@ -31,7 +31,7 @@ export function WidgetWrapper({
|
|
|
31
31
|
}: WCProps<Props>): React.ReactElement | null {
|
|
32
32
|
const theme = useTheme()
|
|
33
33
|
const dispatch = useAppDispatch()
|
|
34
|
-
const { step
|
|
34
|
+
const { step } = useAppSelector(selectWidgetState)
|
|
35
35
|
const [{ state, failReason, txReceipt }] = useAtom(sendTxAtom)
|
|
36
36
|
const reset = useResetAtom(txAtom)
|
|
37
37
|
|
|
@@ -42,14 +42,12 @@ export function WidgetWrapper({
|
|
|
42
42
|
}, [dispatch, failReason, state])
|
|
43
43
|
|
|
44
44
|
useEffect(() => {
|
|
45
|
-
if (step === WIDGET_STEP.Done &&
|
|
46
|
-
if (handleSuccess
|
|
45
|
+
if (step === WIDGET_STEP.Done && txReceipt) {
|
|
46
|
+
if (handleSuccess) {
|
|
47
47
|
handleSuccess(txReceipt.blockNumber)
|
|
48
|
-
} else if (handleSuccess && solanaSignature) {
|
|
49
|
-
handleSuccess(0) // solana tx doesn't have block number
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
}, [handleSuccess,
|
|
50
|
+
}, [handleSuccess, step, txReceipt])
|
|
53
51
|
|
|
54
52
|
const handleCloseModal = useCallback(() => {
|
|
55
53
|
reset()
|
package/src/index.tsx
CHANGED
|
@@ -73,26 +73,6 @@ import { SuperfluidFactoring } from './components/SuperfluidFactoring'
|
|
|
73
73
|
import { store } from './store'
|
|
74
74
|
import { themeHuma } from './theme'
|
|
75
75
|
import { WCProps } from './utilTypes'
|
|
76
|
-
import {
|
|
77
|
-
SolanaLendSupply,
|
|
78
|
-
SolanaLendSupplyProps,
|
|
79
|
-
} from './components/Lend/solanaSupply'
|
|
80
|
-
import {
|
|
81
|
-
SolanaLendAddRedemption,
|
|
82
|
-
SolanaLendAddRedemptionProps,
|
|
83
|
-
} from './components/Lend/solanaAddRedemption'
|
|
84
|
-
import {
|
|
85
|
-
SolanaLendCancelRedemption,
|
|
86
|
-
SolanaLendCancelRedemptionProps,
|
|
87
|
-
} from './components/Lend/solanaCancelRedemption'
|
|
88
|
-
import {
|
|
89
|
-
SolanaBorrow,
|
|
90
|
-
SolanaBorrowProps,
|
|
91
|
-
} from './components/CreditLine/solanaBorrow'
|
|
92
|
-
import {
|
|
93
|
-
SolanaPayment,
|
|
94
|
-
SolanaPaymentProps,
|
|
95
|
-
} from './components/CreditLine/solanaPayment'
|
|
96
76
|
import { NotifiContextWrapper } from './components/Notifi/NotifiContextWrapper'
|
|
97
77
|
|
|
98
78
|
/**
|
|
@@ -554,123 +534,4 @@ export function ReceivableBackedCreditLinePaymentWidgetV2(
|
|
|
554
534
|
)
|
|
555
535
|
}
|
|
556
536
|
|
|
557
|
-
/**
|
|
558
|
-
* Object representing the props passed to Solana widgets
|
|
559
|
-
* @typedef {Object} SolanaWidgetProps
|
|
560
|
-
*/
|
|
561
|
-
type SolanaWidgetProps = {
|
|
562
|
-
handleClose?: () => void
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function SolanaWidget(props: WCProps<SolanaWidgetProps>) {
|
|
566
|
-
const { children } = props
|
|
567
|
-
|
|
568
|
-
return (
|
|
569
|
-
<ThemeProvider theme={themeHuma}>
|
|
570
|
-
<ReduxProvider store={store}>{children}</ReduxProvider>
|
|
571
|
-
</ThemeProvider>
|
|
572
|
-
)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* Lend pool supply widget props for Solana pools
|
|
577
|
-
* @typedef {Object} SolanaLendSupplyWidgetProps
|
|
578
|
-
*/
|
|
579
|
-
type SolanaLendSupplyWidgetProps = SolanaLendSupplyProps & SolanaWidgetProps
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Lend pool supply widget for Solana pools
|
|
583
|
-
*
|
|
584
|
-
* @param {SolanaLendSupplyWidgetProps} props - Widget props
|
|
585
|
-
*/
|
|
586
|
-
export function SolanaLendSupplyWidget(props: SolanaLendSupplyWidgetProps) {
|
|
587
|
-
return (
|
|
588
|
-
<SolanaWidget {...props}>
|
|
589
|
-
<SolanaLendSupply {...props} />
|
|
590
|
-
</SolanaWidget>
|
|
591
|
-
)
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
/**
|
|
595
|
-
* Lend pool supply widget props for Solana pools
|
|
596
|
-
* @typedef {Object} SolanaLendAddRedemptionWidgetProps
|
|
597
|
-
*/
|
|
598
|
-
type SolanaLendAddRedemptionWidgetProps = SolanaLendAddRedemptionProps &
|
|
599
|
-
SolanaWidgetProps
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Lend pool supply widget for Solana pools
|
|
603
|
-
*
|
|
604
|
-
* @param {SolanaLendAddRedemptionWidgetProps} props - Widget props
|
|
605
|
-
*/
|
|
606
|
-
export function SolanaLendAddRedemptionWidget(
|
|
607
|
-
props: SolanaLendAddRedemptionWidgetProps,
|
|
608
|
-
) {
|
|
609
|
-
return (
|
|
610
|
-
<SolanaWidget {...props}>
|
|
611
|
-
<SolanaLendAddRedemption {...props} />
|
|
612
|
-
</SolanaWidget>
|
|
613
|
-
)
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
/**
|
|
617
|
-
* Lend pool supply widget props for Solana pools
|
|
618
|
-
* @typedef {Object} SolanaLendCancelRedemptionWidgetProps
|
|
619
|
-
*/
|
|
620
|
-
type SolanaLendCancelRedemptionWidgetProps = SolanaLendCancelRedemptionProps &
|
|
621
|
-
SolanaWidgetProps
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Lend pool supply widget for Solana pools
|
|
625
|
-
*
|
|
626
|
-
* @param {SolanaLendCancelRedemptionWidgetProps} props - Widget props
|
|
627
|
-
*/
|
|
628
|
-
export function SolanaLendCancelRedemptionWidget(
|
|
629
|
-
props: SolanaLendCancelRedemptionWidgetProps,
|
|
630
|
-
) {
|
|
631
|
-
return (
|
|
632
|
-
<SolanaWidget {...props}>
|
|
633
|
-
<SolanaLendCancelRedemption {...props} />
|
|
634
|
-
</SolanaWidget>
|
|
635
|
-
)
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
/**
|
|
639
|
-
* Lend pool supply widget props for Solana pools
|
|
640
|
-
* @typedef {Object} SolanaBorrowWidgetProps
|
|
641
|
-
*/
|
|
642
|
-
type SolanaBorrowWidgetProps = SolanaBorrowProps & SolanaWidgetProps
|
|
643
|
-
|
|
644
|
-
/**
|
|
645
|
-
* Lend pool supply widget for Solana pools
|
|
646
|
-
*
|
|
647
|
-
* @param {SolanaBorrowWidgetProps} props - Widget props
|
|
648
|
-
*/
|
|
649
|
-
export function SolanaBorrowWidget(props: SolanaBorrowWidgetProps) {
|
|
650
|
-
return (
|
|
651
|
-
<SolanaWidget {...props}>
|
|
652
|
-
<SolanaBorrow {...props} />
|
|
653
|
-
</SolanaWidget>
|
|
654
|
-
)
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/**
|
|
658
|
-
* Lend pool supply widget props for Solana pools
|
|
659
|
-
* @typedef {Object} SolanaPaymentWidgetProps
|
|
660
|
-
*/
|
|
661
|
-
type SolanaPaymentWidgetProps = SolanaPaymentProps & SolanaWidgetProps
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Lend pool supply widget for Solana pools
|
|
665
|
-
*
|
|
666
|
-
* @param {SolanaPaymentWidgetProps} props - Widget props
|
|
667
|
-
*/
|
|
668
|
-
export function SolanaPaymentWidget(props: SolanaPaymentWidgetProps) {
|
|
669
|
-
return (
|
|
670
|
-
<SolanaWidget {...props}>
|
|
671
|
-
<SolanaPayment {...props} />
|
|
672
|
-
</SolanaWidget>
|
|
673
|
-
)
|
|
674
|
-
}
|
|
675
|
-
|
|
676
537
|
export * from './components/Notifi/NotifiContextWrapper'
|
|
@@ -32,7 +32,6 @@ export const widgetSlice = createSlice({
|
|
|
32
32
|
state.withdrawShares = undefined
|
|
33
33
|
state.redeemAmount = undefined
|
|
34
34
|
state.redeemShares = undefined
|
|
35
|
-
state.solanaSignature = undefined
|
|
36
35
|
},
|
|
37
36
|
setStep: (state, { payload }: PayloadAction<WIDGET_STEP>) => {
|
|
38
37
|
state.step = payload
|
|
@@ -103,9 +102,6 @@ export const widgetSlice = createSlice({
|
|
|
103
102
|
setMultisend: (state, { payload }: PayloadAction<MultisendPayload>) => {
|
|
104
103
|
state.multisend = payload
|
|
105
104
|
},
|
|
106
|
-
setSolanaSignature: (state, { payload }: PayloadAction<string>) => {
|
|
107
|
-
state.solanaSignature = payload
|
|
108
|
-
},
|
|
109
105
|
setError: (
|
|
110
106
|
state,
|
|
111
107
|
{
|
|
@@ -134,7 +130,6 @@ export const {
|
|
|
134
130
|
setWithdrawShares,
|
|
135
131
|
setRedeemAmount,
|
|
136
132
|
setRedeemShares,
|
|
137
|
-
setSolanaSignature,
|
|
138
133
|
} = widgetSlice.actions
|
|
139
134
|
|
|
140
135
|
export default widgetSlice.reducer
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatNumber,
|
|
3
|
-
SolanaPoolInfo,
|
|
4
|
-
SolanaTokenUtils,
|
|
5
|
-
} from '@huma-finance/shared'
|
|
6
|
-
import { CreditConfigAccount } from '@huma-finance/web-shared'
|
|
7
|
-
import React, { useCallback, useMemo, useState } from 'react'
|
|
8
|
-
|
|
9
|
-
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
10
|
-
import { setBorrowInfo } from '../../../store/widgets.reducers'
|
|
11
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
12
|
-
import { InputAmountModal } from '../../InputAmountModal'
|
|
13
|
-
|
|
14
|
-
type Props = {
|
|
15
|
-
poolInfo: SolanaPoolInfo
|
|
16
|
-
creditConfigAccount: CreditConfigAccount
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function ChooseAmount({
|
|
20
|
-
poolInfo,
|
|
21
|
-
creditConfigAccount,
|
|
22
|
-
}: Props): React.ReactElement {
|
|
23
|
-
const dispatch = useAppDispatch()
|
|
24
|
-
const { symbol, decimals } = poolInfo.underlyingMint
|
|
25
|
-
const [currentAmount, setCurrentAmount] = useState<number>(0)
|
|
26
|
-
const creditAvailable = useMemo(
|
|
27
|
-
() =>
|
|
28
|
-
SolanaTokenUtils.formatUnits(
|
|
29
|
-
creditConfigAccount.creditAvailable,
|
|
30
|
-
decimals,
|
|
31
|
-
),
|
|
32
|
-
[creditConfigAccount.creditAvailable, decimals],
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
const handleChangeAmount = (newAmount: number) => {
|
|
36
|
-
setCurrentAmount(newAmount)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const handleAction = useCallback(() => {
|
|
40
|
-
const borrowAmountBN = SolanaTokenUtils.parseUnits(
|
|
41
|
-
String(currentAmount),
|
|
42
|
-
decimals,
|
|
43
|
-
)
|
|
44
|
-
dispatch(
|
|
45
|
-
setBorrowInfo({
|
|
46
|
-
borrowAmount: currentAmount,
|
|
47
|
-
borrowAmountBN: JSON.parse(borrowAmountBN.toString()),
|
|
48
|
-
chargedFees: 0,
|
|
49
|
-
nextStep: WIDGET_STEP.Transfer,
|
|
50
|
-
}),
|
|
51
|
-
)
|
|
52
|
-
}, [currentAmount, decimals, dispatch])
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<InputAmountModal
|
|
56
|
-
title='Borrow'
|
|
57
|
-
subTitle='Choose Amount'
|
|
58
|
-
tokenSymbol={symbol}
|
|
59
|
-
currentAmount={currentAmount}
|
|
60
|
-
handleChangeAmount={handleChangeAmount}
|
|
61
|
-
maxAmount={creditAvailable}
|
|
62
|
-
infos={[`${String(formatNumber(creditAvailable))} ${symbol} Available`]}
|
|
63
|
-
handleAction={handleAction}
|
|
64
|
-
actionText='BORROW'
|
|
65
|
-
/>
|
|
66
|
-
)
|
|
67
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCreditAccounts,
|
|
3
|
-
getSentinelAddress,
|
|
4
|
-
getTokenAccounts,
|
|
5
|
-
SolanaPoolInfo,
|
|
6
|
-
SolanaTokenUtils,
|
|
7
|
-
} from '@huma-finance/shared'
|
|
8
|
-
import React, { useCallback, useEffect, useState } from 'react'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
12
|
-
createApproveCheckedInstruction,
|
|
13
|
-
createAssociatedTokenAccountInstruction,
|
|
14
|
-
getAccount,
|
|
15
|
-
TOKEN_2022_PROGRAM_ID,
|
|
16
|
-
TokenAccountNotFoundError,
|
|
17
|
-
TokenInvalidAccountOwnerError,
|
|
18
|
-
} from '@solana/spl-token'
|
|
19
|
-
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
20
|
-
import { PublicKey, Transaction } from '@solana/web3.js'
|
|
21
|
-
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
22
|
-
import { BN } from '@coral-xyz/anchor'
|
|
23
|
-
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
24
|
-
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
25
|
-
import { setStep } from '../../../store/widgets.reducers'
|
|
26
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
27
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
28
|
-
|
|
29
|
-
type Props = {
|
|
30
|
-
poolInfo: SolanaPoolInfo
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function Transfer({ poolInfo }: Props): React.ReactElement | null {
|
|
34
|
-
const dispatch = useAppDispatch()
|
|
35
|
-
const { wallet, publicKey } = useWallet()
|
|
36
|
-
const sentinel = getSentinelAddress(poolInfo.chainId)
|
|
37
|
-
const { connection } = useConnection()
|
|
38
|
-
const [transaction, setTransaction] = useState<Transaction>()
|
|
39
|
-
const program = useHumaProgram(poolInfo.chainId)
|
|
40
|
-
const { borrowAmountBN: borrowAmountBNJson } =
|
|
41
|
-
useAppSelector(selectWidgetState)
|
|
42
|
-
|
|
43
|
-
const handleSuccess = useCallback(() => {
|
|
44
|
-
dispatch(setStep(WIDGET_STEP.Done))
|
|
45
|
-
}, [dispatch])
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
async function getTx() {
|
|
49
|
-
if (!wallet || !publicKey || !connection) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const { underlyingTokenATA } = getTokenAccounts(poolInfo, publicKey)
|
|
54
|
-
const tx = new Transaction()
|
|
55
|
-
|
|
56
|
-
// Create user token account if it doesn't exist
|
|
57
|
-
let tokenAccount
|
|
58
|
-
try {
|
|
59
|
-
tokenAccount = await getAccount(
|
|
60
|
-
connection,
|
|
61
|
-
underlyingTokenATA,
|
|
62
|
-
undefined,
|
|
63
|
-
TOKEN_2022_PROGRAM_ID,
|
|
64
|
-
)
|
|
65
|
-
} catch (error: unknown) {
|
|
66
|
-
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
67
|
-
// becoming a system account. Assuming program derived addressing is safe, this is the only case for the
|
|
68
|
-
// TokenInvalidAccountOwnerError in this code path.
|
|
69
|
-
if (
|
|
70
|
-
error instanceof TokenAccountNotFoundError ||
|
|
71
|
-
error instanceof TokenInvalidAccountOwnerError
|
|
72
|
-
) {
|
|
73
|
-
// As this isn't atomic, it's possible others can create associated accounts meanwhile.
|
|
74
|
-
tx.add(
|
|
75
|
-
createAssociatedTokenAccountInstruction(
|
|
76
|
-
publicKey,
|
|
77
|
-
underlyingTokenATA,
|
|
78
|
-
publicKey,
|
|
79
|
-
new PublicKey(poolInfo.underlyingMint.address),
|
|
80
|
-
TOKEN_2022_PROGRAM_ID,
|
|
81
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
82
|
-
),
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Approve allowance to the sentinel if the account is new or delegated amount is not enough
|
|
88
|
-
const borrowAmountBN = new BN(borrowAmountBNJson?.toString() ?? '0')
|
|
89
|
-
if (
|
|
90
|
-
!tokenAccount ||
|
|
91
|
-
borrowAmountBN.gt(new BN(tokenAccount.delegatedAmount.toString())) ||
|
|
92
|
-
tokenAccount.delegate?.toString() !== sentinel
|
|
93
|
-
) {
|
|
94
|
-
tx.add(
|
|
95
|
-
createApproveCheckedInstruction(
|
|
96
|
-
underlyingTokenATA,
|
|
97
|
-
new PublicKey(poolInfo.underlyingMint.address),
|
|
98
|
-
new PublicKey(sentinel), // delegate
|
|
99
|
-
publicKey, // owner of the wallet
|
|
100
|
-
BigInt(
|
|
101
|
-
SolanaTokenUtils.parseUnits(
|
|
102
|
-
'100000000000', // 100 billion
|
|
103
|
-
poolInfo.underlyingMint.decimals,
|
|
104
|
-
).toString(),
|
|
105
|
-
), // amount
|
|
106
|
-
poolInfo.underlyingMint.decimals,
|
|
107
|
-
undefined, // multiSigners
|
|
108
|
-
TOKEN_2022_PROGRAM_ID,
|
|
109
|
-
),
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const { creditConfigAccount, creditStateAccount } = getCreditAccounts(
|
|
114
|
-
poolInfo,
|
|
115
|
-
publicKey,
|
|
116
|
-
)
|
|
117
|
-
// borrowAmountBNJson is stored as a raw number string in this flow
|
|
118
|
-
const programTx = await program.methods
|
|
119
|
-
.drawdown(borrowAmountBN)
|
|
120
|
-
.accountsPartial({
|
|
121
|
-
borrower: publicKey,
|
|
122
|
-
humaConfig: poolInfo.humaConfig,
|
|
123
|
-
poolConfig: poolInfo.poolConfig,
|
|
124
|
-
poolState: poolInfo.poolState,
|
|
125
|
-
creditConfig: creditConfigAccount,
|
|
126
|
-
creditState: creditStateAccount,
|
|
127
|
-
poolAuthority: poolInfo.poolAuthority,
|
|
128
|
-
underlyingMint: poolInfo.underlyingMint.address,
|
|
129
|
-
poolUnderlyingToken: poolInfo.poolUnderlyingTokenAccount,
|
|
130
|
-
borrowerUnderlyingToken: underlyingTokenATA,
|
|
131
|
-
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
132
|
-
})
|
|
133
|
-
.transaction()
|
|
134
|
-
tx.add(programTx)
|
|
135
|
-
|
|
136
|
-
setTransaction(tx)
|
|
137
|
-
}
|
|
138
|
-
getTx()
|
|
139
|
-
}, [
|
|
140
|
-
borrowAmountBNJson,
|
|
141
|
-
connection,
|
|
142
|
-
dispatch,
|
|
143
|
-
poolInfo,
|
|
144
|
-
poolInfo.underlyingMint.address,
|
|
145
|
-
poolInfo.underlyingMint.decimals,
|
|
146
|
-
program.methods,
|
|
147
|
-
publicKey,
|
|
148
|
-
sentinel,
|
|
149
|
-
wallet,
|
|
150
|
-
])
|
|
151
|
-
|
|
152
|
-
return (
|
|
153
|
-
<SolanaTxSendModal
|
|
154
|
-
tx={transaction}
|
|
155
|
-
chainId={poolInfo.chainId}
|
|
156
|
-
handleSuccess={handleSuccess}
|
|
157
|
-
/>
|
|
158
|
-
)
|
|
159
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { formatNumber, SolanaPoolInfo, timeUtil } from '@huma-finance/shared'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import { SolanaPoolState } from '@huma-finance/web-shared'
|
|
5
|
-
import { useAppSelector } from '../../../hooks/useRedux'
|
|
6
|
-
import { selectWidgetState } from '../../../store/widgets.selectors'
|
|
7
|
-
import { SolanaTxDoneModal } from '../../SolanaTxDoneModal'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
poolInfo: SolanaPoolInfo
|
|
11
|
-
poolState: SolanaPoolState
|
|
12
|
-
handleAction: () => void
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Done({
|
|
16
|
-
poolInfo,
|
|
17
|
-
poolState,
|
|
18
|
-
handleAction,
|
|
19
|
-
}: Props): React.ReactElement {
|
|
20
|
-
const { borrowAmount, solanaSignature } = useAppSelector(selectWidgetState)
|
|
21
|
-
const { symbol } = poolInfo.underlyingMint
|
|
22
|
-
const dueDate = timeUtil.timestampToLL(poolState.epochEndTime)
|
|
23
|
-
|
|
24
|
-
const content = [
|
|
25
|
-
`${formatNumber(borrowAmount)} ${symbol} is now in your wallet.`,
|
|
26
|
-
`Note: your first automatic payment will occur after ${dueDate}.`,
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<SolanaTxDoneModal
|
|
31
|
-
handleAction={handleAction}
|
|
32
|
-
content={content}
|
|
33
|
-
chainId={poolInfo.chainId}
|
|
34
|
-
solanaSignature={solanaSignature}
|
|
35
|
-
buttonText='DONE'
|
|
36
|
-
/>
|
|
37
|
-
)
|
|
38
|
-
}
|