@huma-finance/widgets 0.0.73-beta.957 → 0.0.73-beta.961
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/index.js
CHANGED
|
@@ -174943,59 +174943,79 @@ function Transfer$9({
|
|
|
174943
174943
|
poolIsClosed: ur
|
|
174944
174944
|
}) {
|
|
174945
174945
|
useLogOnFirstMount("Transaction");
|
|
174946
|
-
const { publicKey: cr } = useWallet(), fr = useAppDispatch(), lr = useHumaProgram(ar.chainId), [
|
|
174946
|
+
const { publicKey: cr } = useWallet(), fr = useAppDispatch(), { connection: lr } = useConnection(), dr = useHumaProgram(ar.chainId), [pr, yr] = useState();
|
|
174947
174947
|
useEffect(() => {
|
|
174948
|
-
async function
|
|
174949
|
-
if (!cr ||
|
|
174948
|
+
async function gr() {
|
|
174949
|
+
if (!cr || pr || !lr)
|
|
174950
174950
|
return;
|
|
174951
|
-
const
|
|
174951
|
+
const hr = new Transaction$3(), { underlyingTokenATA: Sr, seniorTrancheATA: Ir, juniorTrancheATA: Tr } = getTokenAccounts(ar, cr), xr = or === "senior" ? ar.seniorTrancheMint : ar.juniorTrancheMint, Br = or === "senior" ? Ir : Tr;
|
|
174952
|
+
try {
|
|
174953
|
+
await getAccount(
|
|
174954
|
+
lr,
|
|
174955
|
+
Sr,
|
|
174956
|
+
void 0,
|
|
174957
|
+
TOKEN_PROGRAM_ID
|
|
174958
|
+
);
|
|
174959
|
+
} catch (Pr) {
|
|
174960
|
+
(Pr instanceof TokenAccountNotFoundError || Pr instanceof TokenInvalidAccountOwnerError) && hr.add(
|
|
174961
|
+
createAssociatedTokenAccountInstruction(
|
|
174962
|
+
cr,
|
|
174963
|
+
Sr,
|
|
174964
|
+
cr,
|
|
174965
|
+
new PublicKey$2(ar.underlyingMint.address),
|
|
174966
|
+
TOKEN_PROGRAM_ID,
|
|
174967
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
174968
|
+
)
|
|
174969
|
+
);
|
|
174970
|
+
}
|
|
174952
174971
|
if (ur) {
|
|
174953
|
-
const
|
|
174972
|
+
const Pr = await dr.methods.withdrawAfterPoolClosure().accountsPartial({
|
|
174954
174973
|
lender: cr,
|
|
174955
174974
|
humaConfig: ar.humaConfig,
|
|
174956
174975
|
poolConfig: ar.poolConfig,
|
|
174957
174976
|
underlyingMint: ar.underlyingMint.address,
|
|
174958
|
-
trancheMint:
|
|
174977
|
+
trancheMint: xr,
|
|
174959
174978
|
poolUnderlyingToken: ar.poolUnderlyingTokenAccount,
|
|
174960
|
-
lenderUnderlyingToken:
|
|
174961
|
-
lenderTrancheToken:
|
|
174979
|
+
lenderUnderlyingToken: Sr,
|
|
174980
|
+
lenderTrancheToken: Br,
|
|
174962
174981
|
underlyingTokenProgram: TOKEN_PROGRAM_ID,
|
|
174963
174982
|
trancheTokenProgram: TOKEN_2022_PROGRAM_ID
|
|
174964
174983
|
}).transaction();
|
|
174965
|
-
|
|
174984
|
+
hr.add(Pr);
|
|
174966
174985
|
} else {
|
|
174967
|
-
const
|
|
174986
|
+
const Pr = await dr.methods.disburse().accountsPartial({
|
|
174968
174987
|
lender: cr,
|
|
174969
174988
|
humaConfig: ar.humaConfig,
|
|
174970
174989
|
poolConfig: ar.poolConfig,
|
|
174971
174990
|
underlyingMint: ar.underlyingMint.address,
|
|
174972
|
-
trancheMint:
|
|
174991
|
+
trancheMint: xr,
|
|
174973
174992
|
poolUnderlyingToken: ar.poolUnderlyingTokenAccount,
|
|
174974
|
-
lenderUnderlyingToken:
|
|
174993
|
+
lenderUnderlyingToken: Sr,
|
|
174975
174994
|
tokenProgram: TOKEN_PROGRAM_ID
|
|
174976
174995
|
}).transaction();
|
|
174977
|
-
|
|
174996
|
+
hr.add(Pr);
|
|
174978
174997
|
}
|
|
174979
|
-
|
|
174998
|
+
yr(hr);
|
|
174980
174999
|
}
|
|
174981
|
-
|
|
175000
|
+
gr();
|
|
174982
175001
|
}, [
|
|
175002
|
+
lr,
|
|
174983
175003
|
ar,
|
|
174984
175004
|
ur,
|
|
174985
|
-
|
|
175005
|
+
dr.methods,
|
|
174986
175006
|
cr,
|
|
174987
175007
|
or,
|
|
174988
|
-
|
|
175008
|
+
pr
|
|
174989
175009
|
]);
|
|
174990
|
-
const
|
|
175010
|
+
const Ar = useCallback(() => {
|
|
174991
175011
|
fr(setStep(WIDGET_STEP.Done));
|
|
174992
175012
|
}, [fr]);
|
|
174993
175013
|
return /* @__PURE__ */ jsx(
|
|
174994
175014
|
SolanaTxSendModal,
|
|
174995
175015
|
{
|
|
174996
|
-
tx:
|
|
175016
|
+
tx: pr,
|
|
174997
175017
|
chainId: ar.chainId,
|
|
174998
|
-
handleSuccess:
|
|
175018
|
+
handleSuccess: Ar
|
|
174999
175019
|
}
|
|
175000
175020
|
);
|
|
175001
175021
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.73-beta.
|
|
3
|
+
"version": "0.0.73-beta.961+34c4cad",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@ethersproject/contracts": "^5.7.0",
|
|
23
23
|
"@ethersproject/experimental": "^5.7.0",
|
|
24
24
|
"@ethersproject/units": "^5.6.0",
|
|
25
|
-
"@huma-finance/sdk": "^0.0.73-beta.
|
|
26
|
-
"@huma-finance/shared": "^0.0.73-beta.
|
|
27
|
-
"@huma-finance/web-shared": "^0.0.73-beta.
|
|
25
|
+
"@huma-finance/sdk": "^0.0.73-beta.961+34c4cad",
|
|
26
|
+
"@huma-finance/shared": "^0.0.73-beta.961+34c4cad",
|
|
27
|
+
"@huma-finance/web-shared": "^0.0.73-beta.961+34c4cad",
|
|
28
28
|
"@mui/x-date-pickers": "^5.0.7",
|
|
29
29
|
"@notifi-network/notifi-frontend-client": "^1.1.2",
|
|
30
30
|
"@notifi-network/notifi-react": "^1.1.2",
|
|
@@ -190,5 +190,5 @@
|
|
|
190
190
|
"optionalDependencies": {
|
|
191
191
|
"encoding": "^0.1.13"
|
|
192
192
|
},
|
|
193
|
-
"gitHead": "
|
|
193
|
+
"gitHead": "34c4cad8e5f86bb81f80fb99eb320248271a320c"
|
|
194
194
|
}
|
|
@@ -4,15 +4,23 @@ import {
|
|
|
4
4
|
TrancheType,
|
|
5
5
|
} from '@huma-finance/shared'
|
|
6
6
|
import { useHumaProgram } from '@huma-finance/web-shared'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import {
|
|
8
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
9
|
+
createAssociatedTokenAccountInstruction,
|
|
10
|
+
getAccount,
|
|
11
|
+
TOKEN_2022_PROGRAM_ID,
|
|
12
|
+
TOKEN_PROGRAM_ID,
|
|
13
|
+
TokenAccountNotFoundError,
|
|
14
|
+
TokenInvalidAccountOwnerError,
|
|
15
|
+
} from '@solana/spl-token'
|
|
16
|
+
import { useConnection, useWallet } from '@solana/wallet-adapter-react'
|
|
17
|
+
import { PublicKey, Transaction } from '@solana/web3.js'
|
|
10
18
|
import React, { useCallback, useEffect, useState } from 'react'
|
|
19
|
+
import useLogOnFirstMount from '../../../hooks/useLogOnFirstMount'
|
|
11
20
|
import { useAppDispatch } from '../../../hooks/useRedux'
|
|
12
21
|
import { setStep } from '../../../store/widgets.reducers'
|
|
13
22
|
import { WIDGET_STEP } from '../../../store/widgets.store'
|
|
14
23
|
import { SolanaTxSendModal } from '../../SolanaTxSendModal'
|
|
15
|
-
import useLogOnFirstMount from '../../../hooks/useLogOnFirstMount'
|
|
16
24
|
|
|
17
25
|
type Props = {
|
|
18
26
|
poolInfo: SolanaPoolInfo
|
|
@@ -28,12 +36,13 @@ export function Transfer({
|
|
|
28
36
|
useLogOnFirstMount('Transaction')
|
|
29
37
|
const { publicKey } = useWallet()
|
|
30
38
|
const dispatch = useAppDispatch()
|
|
39
|
+
const { connection } = useConnection()
|
|
31
40
|
const program = useHumaProgram(poolInfo.chainId)
|
|
32
41
|
const [transaction, setTransaction] = useState<Transaction>()
|
|
33
42
|
|
|
34
43
|
useEffect(() => {
|
|
35
44
|
async function getTx() {
|
|
36
|
-
if (!publicKey || transaction) {
|
|
45
|
+
if (!publicKey || transaction || !connection) {
|
|
37
46
|
return
|
|
38
47
|
}
|
|
39
48
|
|
|
@@ -47,6 +56,37 @@ export function Transfer({
|
|
|
47
56
|
const lenderTrancheToken =
|
|
48
57
|
selectedTranche === 'senior' ? seniorTrancheATA : juniorTrancheATA
|
|
49
58
|
|
|
59
|
+
// Create user token account if it doesn't exist
|
|
60
|
+
try {
|
|
61
|
+
await getAccount(
|
|
62
|
+
connection,
|
|
63
|
+
underlyingTokenATA,
|
|
64
|
+
undefined,
|
|
65
|
+
TOKEN_PROGRAM_ID,
|
|
66
|
+
)
|
|
67
|
+
} catch (error: unknown) {
|
|
68
|
+
// TokenAccountNotFoundError can be possible if the associated address has already received some lamports,
|
|
69
|
+
// becoming a system account. Assuming program derived addressing is safe, this is the only case for the
|
|
70
|
+
// TokenInvalidAccountOwnerError in this code path.
|
|
71
|
+
// Source: https://solana.stackexchange.com/questions/802/checking-to-see-if-a-token-account-exists-using-anchor-ts
|
|
72
|
+
if (
|
|
73
|
+
error instanceof TokenAccountNotFoundError ||
|
|
74
|
+
error instanceof TokenInvalidAccountOwnerError
|
|
75
|
+
) {
|
|
76
|
+
// As this isn't atomic, it's possible others can create associated accounts meanwhile.
|
|
77
|
+
tx.add(
|
|
78
|
+
createAssociatedTokenAccountInstruction(
|
|
79
|
+
publicKey,
|
|
80
|
+
underlyingTokenATA,
|
|
81
|
+
publicKey,
|
|
82
|
+
new PublicKey(poolInfo.underlyingMint.address),
|
|
83
|
+
TOKEN_PROGRAM_ID,
|
|
84
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
50
90
|
if (!poolIsClosed) {
|
|
51
91
|
const disburseTx = await program.methods
|
|
52
92
|
.disburse()
|
|
@@ -85,6 +125,7 @@ export function Transfer({
|
|
|
85
125
|
}
|
|
86
126
|
getTx()
|
|
87
127
|
}, [
|
|
128
|
+
connection,
|
|
88
129
|
poolInfo,
|
|
89
130
|
poolIsClosed,
|
|
90
131
|
program.methods,
|