@huma-finance/widgets 0.0.47-beta.181 → 0.0.47-beta.185
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 +45 -83
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +46 -84
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +4 -3
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +14 -6
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +3 -8
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +2 -35
- package/src/components/StreamFactoring/borrow/index.tsx +2 -3
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +3 -1
- package/src/index.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.47-beta.
|
|
3
|
+
"version": "0.0.47-beta.185+855b3b5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@ethersproject/experimental": "^5.7.0",
|
|
31
31
|
"@ethersproject/providers": "^5.6.0",
|
|
32
32
|
"@ethersproject/units": "^5.6.0",
|
|
33
|
-
"@huma-finance/sdk": "^0.0.
|
|
34
|
-
"@huma-finance/shared": "^0.0.
|
|
33
|
+
"@huma-finance/sdk": "^0.0.47-beta.185+855b3b5",
|
|
34
|
+
"@huma-finance/shared": "^0.0.47-beta.185+855b3b5",
|
|
35
35
|
"@mui/icons-material": "^5.3.0",
|
|
36
36
|
"@mui/material": "^5.0.6",
|
|
37
37
|
"@mui/styles": "^5.0.2",
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
"optionalDependencies": {
|
|
193
193
|
"encoding": "^0.1.13"
|
|
194
194
|
},
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "855b3b572bb1d1f8f58e9b407c83092995766db2"
|
|
196
196
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getAddress } from '@ethersproject/address'
|
|
2
2
|
import { PoolInfoType } from '@huma-finance/shared'
|
|
3
|
+
import { useWeb3React } from '@web3-react/core'
|
|
3
4
|
import React, { useEffect } from 'react'
|
|
4
5
|
|
|
5
6
|
import useEA from '../../../hooks/useEA'
|
|
6
|
-
import { LoadingModal } from '../../LoadingModal'
|
|
7
7
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
|
+
import { LoadingModal } from '../../LoadingModal'
|
|
8
9
|
import { SignIn } from '../../SignIn'
|
|
9
10
|
|
|
10
11
|
type Props = {
|
|
@@ -35,7 +36,7 @@ export function Evaluation({
|
|
|
35
36
|
receivable: {
|
|
36
37
|
address: poolInfo.assetAddress!,
|
|
37
38
|
},
|
|
38
|
-
payerWalletAddress: payerAddress,
|
|
39
|
+
payerWalletAddress: getAddress(payerAddress),
|
|
39
40
|
superToken,
|
|
40
41
|
},
|
|
41
42
|
},
|
|
@@ -28,12 +28,14 @@ export function ChooseAmount({
|
|
|
28
28
|
const [chargedFees, setChargedFees] = useState(0)
|
|
29
29
|
const [currentAmount, setCurrentAmount] = useState(0)
|
|
30
30
|
const borrowPeriodInSeconds = approval!.terms.intervalInDays * 24 * 60 * 60
|
|
31
|
+
const superTokenDecimals = poolInfo.extra?.superToken?.decimals!
|
|
32
|
+
const underlyingTokenDecimals = poolInfo.poolUnderlyingToken.decimals!
|
|
31
33
|
|
|
32
34
|
const getBorrowFlowrateAndAmount = useCallback(
|
|
33
35
|
(borrowAmount: number) => {
|
|
34
36
|
const currentFlowRateBN = toBigNumber(currentFlowRate)
|
|
35
37
|
const borrowAmountBN = toBigNumber(
|
|
36
|
-
upScale(borrowAmount,
|
|
38
|
+
upScale(borrowAmount, superTokenDecimals),
|
|
37
39
|
)
|
|
38
40
|
|
|
39
41
|
const totalAmountInBorrowPeriod = currentFlowRateBN.mul(
|
|
@@ -57,18 +59,24 @@ export function ChooseAmount({
|
|
|
57
59
|
const newBorrowAmountBN = borrowFlowrate
|
|
58
60
|
.mul(totalAmountInBorrowPeriod)
|
|
59
61
|
.div(currentFlowRateBN)
|
|
60
|
-
const newBorrowAmount = downScale(
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const newBorrowAmount = downScale(newBorrowAmountBN, superTokenDecimals)
|
|
63
|
+
const newBorrowAmountUnderlyingTokenBN = toBigNumber(
|
|
64
|
+
upScale(newBorrowAmount, underlyingTokenDecimals),
|
|
63
65
|
)
|
|
64
66
|
|
|
65
67
|
return {
|
|
66
68
|
borrowFlowrate: borrowFlowrate.toString(),
|
|
67
69
|
borrowAmount: Number(newBorrowAmount),
|
|
68
|
-
borrowAmountBN:
|
|
70
|
+
borrowAmountBN: newBorrowAmountUnderlyingTokenBN,
|
|
69
71
|
}
|
|
70
72
|
},
|
|
71
|
-
[
|
|
73
|
+
[
|
|
74
|
+
approval,
|
|
75
|
+
borrowPeriodInSeconds,
|
|
76
|
+
currentFlowRate,
|
|
77
|
+
superTokenDecimals,
|
|
78
|
+
underlyingTokenDecimals,
|
|
79
|
+
],
|
|
72
80
|
)
|
|
73
81
|
|
|
74
82
|
const handleChangeAmount = useCallback(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useWeb3React } from '@web3-react/core'
|
|
1
|
+
import { isEmpty } from '@huma-finance/shared'
|
|
3
2
|
import React, { useCallback } from 'react'
|
|
4
3
|
|
|
5
4
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -10,15 +9,11 @@ import { ConfirmTransferModal } from '../../ConfirmTransferModal'
|
|
|
10
9
|
|
|
11
10
|
export function ConfirmTransfer(): React.ReactElement | null {
|
|
12
11
|
const dispatch = useAppDispatch()
|
|
13
|
-
const { chainId } = useWeb3React()
|
|
14
12
|
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
15
13
|
|
|
16
14
|
const handleAction = useCallback(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: WIDGET_STEP.Permit
|
|
20
|
-
dispatch(setStep(step))
|
|
21
|
-
}, [chainId, dispatch])
|
|
15
|
+
dispatch(setStep(WIDGET_STEP.ApproveAllowance))
|
|
16
|
+
}, [dispatch])
|
|
22
17
|
|
|
23
18
|
if (isEmpty(borrowAmount) || isEmpty(approval)) {
|
|
24
19
|
return null
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CHAINS,
|
|
3
|
-
Erc2612,
|
|
4
2
|
PoolInfoType,
|
|
5
3
|
SuperfluidPoolProcessor,
|
|
4
|
+
SuperfluidPoolProcessor_ABI,
|
|
6
5
|
useERC2612Permit,
|
|
7
6
|
useMount,
|
|
8
|
-
ERC2612_ABI,
|
|
9
|
-
SuperfluidPoolProcessor_ABI,
|
|
10
7
|
} from '@huma-finance/shared'
|
|
11
8
|
import { BigNumber, Contract, ethers } from 'ethers'
|
|
12
9
|
import React from 'react'
|
|
@@ -25,7 +22,6 @@ import { LoadingModal } from '../../LoadingModal'
|
|
|
25
22
|
type Props = {
|
|
26
23
|
poolInfo: PoolInfoType
|
|
27
24
|
payerAddress: string
|
|
28
|
-
chainId: number
|
|
29
25
|
borrower: string
|
|
30
26
|
superToken: string
|
|
31
27
|
}
|
|
@@ -33,36 +29,15 @@ type Props = {
|
|
|
33
29
|
export function Permit({
|
|
34
30
|
poolInfo,
|
|
35
31
|
payerAddress,
|
|
36
|
-
chainId,
|
|
37
32
|
borrower,
|
|
38
33
|
superToken,
|
|
39
34
|
}: Props): React.ReactElement | null {
|
|
40
35
|
const dispatch = useDispatch()
|
|
41
|
-
const { address: tokenAddress } = poolInfo.poolUnderlyingToken
|
|
42
36
|
const { borrowAmountBN: borrowAmountBNJson, stream } =
|
|
43
37
|
useAppSelector(selectWidgetState)
|
|
44
|
-
const {
|
|
45
|
-
useERC2612Permit()
|
|
38
|
+
const { getTradableStreamPermitMessage } = useERC2612Permit()
|
|
46
39
|
const borrowAmountBN = BigNumber.from(borrowAmountBNJson)
|
|
47
40
|
|
|
48
|
-
const getApproveAllowanceCallData = async () => {
|
|
49
|
-
const erc2612PermitResult = await getERC2612PermitMessage(
|
|
50
|
-
tokenAddress,
|
|
51
|
-
poolInfo.poolProcessor!,
|
|
52
|
-
borrowAmountBN.toString()!,
|
|
53
|
-
)
|
|
54
|
-
const tokenContract = new Contract(tokenAddress, ERC2612_ABI) as Erc2612
|
|
55
|
-
return tokenContract.interface.encodeFunctionData('permit', [
|
|
56
|
-
poolInfo.poolProcessor!,
|
|
57
|
-
borrowAmountBN.toString()!,
|
|
58
|
-
erc2612PermitResult.nonce,
|
|
59
|
-
erc2612PermitResult.deadline,
|
|
60
|
-
erc2612PermitResult.v,
|
|
61
|
-
erc2612PermitResult.r,
|
|
62
|
-
erc2612PermitResult.s,
|
|
63
|
-
])
|
|
64
|
-
}
|
|
65
|
-
|
|
66
41
|
const getDrawdownCallData = async () => {
|
|
67
42
|
const NFTPermitResult = await getTradableStreamPermitMessage(
|
|
68
43
|
poolInfo.assetAddress!,
|
|
@@ -113,14 +88,6 @@ export function Permit({
|
|
|
113
88
|
try {
|
|
114
89
|
const callData = []
|
|
115
90
|
const addresses: string[] = []
|
|
116
|
-
|
|
117
|
-
// The token in Goerli hasn't integrated ERC-2612
|
|
118
|
-
if (!CHAINS[chainId].isTestnet) {
|
|
119
|
-
const approveAllowanceCallData = await getApproveAllowanceCallData()
|
|
120
|
-
addresses.push(tokenAddress)
|
|
121
|
-
callData.push(approveAllowanceCallData)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
91
|
const drawdownCalldata = await getDrawdownCallData()
|
|
125
92
|
addresses.push(poolInfo.poolProcessor!)
|
|
126
93
|
callData.push(drawdownCalldata)
|
|
@@ -39,7 +39,7 @@ export function StreamFactoringBorrow({
|
|
|
39
39
|
handleSuccess,
|
|
40
40
|
}: StreamFactoringBorrowProps): React.ReactElement | null {
|
|
41
41
|
const dispatch = useDispatch()
|
|
42
|
-
const { account
|
|
42
|
+
const { account } = useWeb3React()
|
|
43
43
|
const poolInfo = usePoolInfo(poolName, poolType)
|
|
44
44
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
45
45
|
|
|
@@ -71,11 +71,10 @@ export function StreamFactoringBorrow({
|
|
|
71
71
|
{step === WIDGET_STEP.ApproveAllowance && (
|
|
72
72
|
<ApproveAllowance poolInfo={poolInfo} />
|
|
73
73
|
)}
|
|
74
|
-
{step === WIDGET_STEP.Permit && account &&
|
|
74
|
+
{step === WIDGET_STEP.Permit && account && (
|
|
75
75
|
<Permit
|
|
76
76
|
poolInfo={poolInfo}
|
|
77
77
|
payerAddress={payerAddress}
|
|
78
|
-
chainId={chainId}
|
|
79
78
|
borrower={account}
|
|
80
79
|
superToken={superToken}
|
|
81
80
|
/>
|
|
@@ -50,9 +50,9 @@ export function SuperfluidFactoredList({
|
|
|
50
50
|
const setItem = useCallback(
|
|
51
51
|
() =>
|
|
52
52
|
Promise.resolve({
|
|
53
|
-
name: poolInfo?.extra?.
|
|
53
|
+
name: poolInfo?.extra?.superToken?.symbol ?? '',
|
|
54
54
|
}),
|
|
55
|
-
[poolInfo?.extra?.
|
|
55
|
+
[poolInfo?.extra?.superToken],
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -106,7 +106,9 @@ export function SuperfluidUpcomingList({
|
|
|
106
106
|
const { data } = useQuery<{ streams: Stream[] }>(GET_RECEIVED_STREAMS, {
|
|
107
107
|
variables: {
|
|
108
108
|
receiver: account ? account.toLowerCase() : undefined,
|
|
109
|
-
tokenIds: poolInfo?.extra?.
|
|
109
|
+
tokenIds: poolInfo?.extra?.superToken
|
|
110
|
+
? [poolInfo.extra.superToken.id]
|
|
111
|
+
: [],
|
|
110
112
|
},
|
|
111
113
|
})
|
|
112
114
|
|
package/src/index.tsx
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
import { ThemeProvider } from '@mui/material'
|
|
9
9
|
import { Provider as Eip1193Provider } from '@web3-react/types'
|
|
10
10
|
import { Provider as AtomProvider } from 'jotai'
|
|
11
|
-
import { useEffect, useState } from 'react'
|
|
12
11
|
import { Provider as ReduxProvider } from 'react-redux'
|
|
13
12
|
|
|
13
|
+
import { useEffect, useState } from 'react'
|
|
14
14
|
import { ChainSupportProvider } from './components/ChainSupportProvider'
|
|
15
15
|
import {
|
|
16
16
|
CreditLineApprove,
|