@huma-finance/widgets 0.0.47-beta.185 → 0.0.48-beta.186
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 +924 -914
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +925 -915
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/StreamFactoring/borrow/1-Evaluation.tsx +3 -4
- package/src/components/StreamFactoring/borrow/2-ChooseAmount.tsx +6 -14
- package/src/components/StreamFactoring/borrow/3-ConfirmTransfer.tsx +8 -3
- package/src/components/StreamFactoring/borrow/5-Permit.tsx +35 -2
- package/src/components/StreamFactoring/borrow/index.tsx +3 -2
- package/src/components/SuperfluidFactoring/SuperfluidFactoredList.tsx +2 -2
- package/src/components/SuperfluidFactoring/SuperfluidUpcomingList.tsx +1 -3
- package/src/index.tsx +4 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.48-beta.186+0a076b2",
|
|
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.48-beta.186+0a076b2",
|
|
34
|
+
"@huma-finance/shared": "^0.0.48-beta.186+0a076b2",
|
|
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": "0a076b2a0a92ec06e3d311e1541f7b3c0ab52b21"
|
|
196
196
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { getAddress } from '@ethersproject/address'
|
|
2
|
-
import { PoolInfoType } from '@huma-finance/shared'
|
|
3
1
|
import { useWeb3React } from '@web3-react/core'
|
|
2
|
+
import { PoolInfoType } from '@huma-finance/shared'
|
|
4
3
|
import React, { useEffect } from 'react'
|
|
5
4
|
|
|
6
5
|
import useEA from '../../../hooks/useEA'
|
|
7
|
-
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
8
6
|
import { LoadingModal } from '../../LoadingModal'
|
|
7
|
+
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
9
8
|
import { SignIn } from '../../SignIn'
|
|
10
9
|
|
|
11
10
|
type Props = {
|
|
@@ -36,7 +35,7 @@ export function Evaluation({
|
|
|
36
35
|
receivable: {
|
|
37
36
|
address: poolInfo.assetAddress!,
|
|
38
37
|
},
|
|
39
|
-
payerWalletAddress:
|
|
38
|
+
payerWalletAddress: payerAddress,
|
|
40
39
|
superToken,
|
|
41
40
|
},
|
|
42
41
|
},
|
|
@@ -28,14 +28,12 @@ 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!
|
|
33
31
|
|
|
34
32
|
const getBorrowFlowrateAndAmount = useCallback(
|
|
35
33
|
(borrowAmount: number) => {
|
|
36
34
|
const currentFlowRateBN = toBigNumber(currentFlowRate)
|
|
37
35
|
const borrowAmountBN = toBigNumber(
|
|
38
|
-
upScale(borrowAmount,
|
|
36
|
+
upScale(borrowAmount, approval!.token.decimal),
|
|
39
37
|
)
|
|
40
38
|
|
|
41
39
|
const totalAmountInBorrowPeriod = currentFlowRateBN.mul(
|
|
@@ -59,24 +57,18 @@ export function ChooseAmount({
|
|
|
59
57
|
const newBorrowAmountBN = borrowFlowrate
|
|
60
58
|
.mul(totalAmountInBorrowPeriod)
|
|
61
59
|
.div(currentFlowRateBN)
|
|
62
|
-
const newBorrowAmount = downScale(
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const newBorrowAmount = downScale(
|
|
61
|
+
newBorrowAmountBN,
|
|
62
|
+
approval!.token.decimal,
|
|
65
63
|
)
|
|
66
64
|
|
|
67
65
|
return {
|
|
68
66
|
borrowFlowrate: borrowFlowrate.toString(),
|
|
69
67
|
borrowAmount: Number(newBorrowAmount),
|
|
70
|
-
borrowAmountBN:
|
|
68
|
+
borrowAmountBN: newBorrowAmountBN,
|
|
71
69
|
}
|
|
72
70
|
},
|
|
73
|
-
[
|
|
74
|
-
approval,
|
|
75
|
-
borrowPeriodInSeconds,
|
|
76
|
-
currentFlowRate,
|
|
77
|
-
superTokenDecimals,
|
|
78
|
-
underlyingTokenDecimals,
|
|
79
|
-
],
|
|
71
|
+
[approval, borrowPeriodInSeconds, currentFlowRate],
|
|
80
72
|
)
|
|
81
73
|
|
|
82
74
|
const handleChangeAmount = useCallback(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { isEmpty } from '@huma-finance/shared'
|
|
1
|
+
import { CHAINS, isEmpty } from '@huma-finance/shared'
|
|
2
|
+
import { useWeb3React } from '@web3-react/core'
|
|
2
3
|
import React, { useCallback } from 'react'
|
|
3
4
|
|
|
4
5
|
import { useAppDispatch, useAppSelector } from '../../../hooks/useRedux'
|
|
@@ -9,11 +10,15 @@ import { ConfirmTransferModal } from '../../ConfirmTransferModal'
|
|
|
9
10
|
|
|
10
11
|
export function ConfirmTransfer(): React.ReactElement | null {
|
|
11
12
|
const dispatch = useAppDispatch()
|
|
13
|
+
const { chainId } = useWeb3React()
|
|
12
14
|
const { borrowAmount, approval } = useAppSelector(selectWidgetState)
|
|
13
15
|
|
|
14
16
|
const handleAction = useCallback(() => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
const step = CHAINS[chainId!].isTestnet
|
|
18
|
+
? WIDGET_STEP.ApproveAllowance
|
|
19
|
+
: WIDGET_STEP.Permit
|
|
20
|
+
dispatch(setStep(step))
|
|
21
|
+
}, [chainId, dispatch])
|
|
17
22
|
|
|
18
23
|
if (isEmpty(borrowAmount) || isEmpty(approval)) {
|
|
19
24
|
return null
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CHAINS,
|
|
3
|
+
Erc2612,
|
|
2
4
|
PoolInfoType,
|
|
3
5
|
SuperfluidPoolProcessor,
|
|
4
|
-
SuperfluidPoolProcessor_ABI,
|
|
5
6
|
useERC2612Permit,
|
|
6
7
|
useMount,
|
|
8
|
+
ERC2612_ABI,
|
|
9
|
+
SuperfluidPoolProcessor_ABI,
|
|
7
10
|
} from '@huma-finance/shared'
|
|
8
11
|
import { BigNumber, Contract, ethers } from 'ethers'
|
|
9
12
|
import React from 'react'
|
|
@@ -22,6 +25,7 @@ import { LoadingModal } from '../../LoadingModal'
|
|
|
22
25
|
type Props = {
|
|
23
26
|
poolInfo: PoolInfoType
|
|
24
27
|
payerAddress: string
|
|
28
|
+
chainId: number
|
|
25
29
|
borrower: string
|
|
26
30
|
superToken: string
|
|
27
31
|
}
|
|
@@ -29,15 +33,36 @@ type Props = {
|
|
|
29
33
|
export function Permit({
|
|
30
34
|
poolInfo,
|
|
31
35
|
payerAddress,
|
|
36
|
+
chainId,
|
|
32
37
|
borrower,
|
|
33
38
|
superToken,
|
|
34
39
|
}: Props): React.ReactElement | null {
|
|
35
40
|
const dispatch = useDispatch()
|
|
41
|
+
const { address: tokenAddress } = poolInfo.poolUnderlyingToken
|
|
36
42
|
const { borrowAmountBN: borrowAmountBNJson, stream } =
|
|
37
43
|
useAppSelector(selectWidgetState)
|
|
38
|
-
const { getTradableStreamPermitMessage } =
|
|
44
|
+
const { getERC2612PermitMessage, getTradableStreamPermitMessage } =
|
|
45
|
+
useERC2612Permit()
|
|
39
46
|
const borrowAmountBN = BigNumber.from(borrowAmountBNJson)
|
|
40
47
|
|
|
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
|
+
|
|
41
66
|
const getDrawdownCallData = async () => {
|
|
42
67
|
const NFTPermitResult = await getTradableStreamPermitMessage(
|
|
43
68
|
poolInfo.assetAddress!,
|
|
@@ -88,6 +113,14 @@ export function Permit({
|
|
|
88
113
|
try {
|
|
89
114
|
const callData = []
|
|
90
115
|
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
|
+
|
|
91
124
|
const drawdownCalldata = await getDrawdownCallData()
|
|
92
125
|
addresses.push(poolInfo.poolProcessor!)
|
|
93
126
|
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 } = useWeb3React()
|
|
42
|
+
const { account, chainId } = useWeb3React()
|
|
43
43
|
const poolInfo = usePoolInfo(poolName, poolType)
|
|
44
44
|
const { step, errorMessage } = useAppSelector(selectWidgetState)
|
|
45
45
|
|
|
@@ -71,10 +71,11 @@ 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 && chainId && (
|
|
75
75
|
<Permit
|
|
76
76
|
poolInfo={poolInfo}
|
|
77
77
|
payerAddress={payerAddress}
|
|
78
|
+
chainId={chainId}
|
|
78
79
|
borrower={account}
|
|
79
80
|
superToken={superToken}
|
|
80
81
|
/>
|
|
@@ -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?.superTokens?.[0].symbol ?? '',
|
|
54
54
|
}),
|
|
55
|
-
[poolInfo?.extra?.
|
|
55
|
+
[poolInfo?.extra?.superTokens],
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -106,9 +106,7 @@ 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?.
|
|
110
|
-
? [poolInfo.extra.superToken.id]
|
|
111
|
-
: [],
|
|
109
|
+
tokenIds: poolInfo?.extra?.superTokens?.map((item) => item.id) ?? [],
|
|
112
110
|
},
|
|
113
111
|
})
|
|
114
112
|
|
package/src/index.tsx
CHANGED
|
@@ -10,7 +10,6 @@ import { Provider as Eip1193Provider } from '@web3-react/types'
|
|
|
10
10
|
import { Provider as AtomProvider } from 'jotai'
|
|
11
11
|
import { Provider as ReduxProvider } from 'react-redux'
|
|
12
12
|
|
|
13
|
-
import { useEffect, useState } from 'react'
|
|
14
13
|
import { ChainSupportProvider } from './components/ChainSupportProvider'
|
|
15
14
|
import {
|
|
16
15
|
CreditLineApprove,
|
|
@@ -64,17 +63,11 @@ type WidgetProps = {
|
|
|
64
63
|
|
|
65
64
|
function Widget(props: WCProps<WidgetProps>) {
|
|
66
65
|
const { children, provider } = props
|
|
67
|
-
const [chainId, setChainId] = useState<number | undefined>(undefined)
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
setChainId(network?.chainId)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
getChainId()
|
|
77
|
-
}, [provider])
|
|
67
|
+
let chainId
|
|
68
|
+
if (provider instanceof JsonRpcProvider) {
|
|
69
|
+
chainId = provider.network.chainId
|
|
70
|
+
}
|
|
78
71
|
|
|
79
72
|
return (
|
|
80
73
|
<ThemeProvider theme={themeHuma}>
|