hedge-web3 0.1.26 → 0.1.29
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/declarations/Constants.d.ts +1 -1
- package/declarations/idl/vault.d.ts +1056 -768
- package/declarations/index.d.ts +2 -0
- package/declarations/instructions/depositVault.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -1
- package/declarations/instructions/redeemVault.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -1
- package/declarations/instructions/setVaultTypeStatus.d.ts +4 -0
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/VaultAccount.d.ts +8 -0
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -0
- package/lib/Constants.js +3 -3
- package/lib/idl/vault.js +1054 -766
- package/lib/index.js +2 -0
- package/lib/instructions/createStakingPool.js +2 -2
- package/lib/instructions/depositVault.js +14 -7
- package/lib/instructions/liquidateVault.js +9 -4
- package/lib/instructions/loanVault.js +9 -4
- package/lib/instructions/redeemVault.js +7 -2
- package/lib/instructions/repayVault.js +9 -4
- package/lib/instructions/setVaultTypeStatus.js +38 -0
- package/lib/instructions/withdrawVault.js +12 -7
- package/lib/state/VaultAccount.js +54 -1
- package/lib/utils/Errors.js +2 -2
- package/lib/utils/getLinkedListAccounts.js +131 -0
- package/package.json +3 -1
- package/src/Constants.ts +73 -31
- package/src/idl/vault.ts +2075 -1499
- package/src/index.ts +3 -0
- package/src/instructions/createStakingPool.ts +1 -2
- package/src/instructions/depositVault.ts +97 -22
- package/src/instructions/liquidateVault.ts +118 -21
- package/src/instructions/loanVault.ts +91 -19
- package/src/instructions/redeemVault.ts +23 -0
- package/src/instructions/repayVault.ts +84 -19
- package/src/instructions/setVaultTypeStatus.ts +50 -0
- package/src/instructions/withdrawVault.ts +99 -21
- package/src/state/StakingPool.ts +0 -4
- package/src/state/VaultAccount.ts +86 -10
- package/src/utils/Errors.ts +2 -2
- package/src/utils/getLinkedListAccounts.ts +156 -0
- package/declarations/idl/idl.d.ts +0 -2
- package/lib/idl/idl.js +0 -1475
- package/src/idl/idl.ts +0 -1474
package/src/Constants.ts
CHANGED
@@ -1,64 +1,106 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
3
|
+
TOKEN_PROGRAM_ID,
|
4
|
+
} from '@solana/spl-token'
|
2
5
|
import { PublicKey } from '@solana/web3.js'
|
3
6
|
|
4
|
-
export const HEDGE_PROGRAM_ID = '
|
7
|
+
export const HEDGE_PROGRAM_ID = 'HDG3uyafYaKxSYRW37ZBTdxaUCoyzaqbuirYucAeaPFY'
|
5
8
|
export const HEDGE_PROGRAM_PUBLICKEY = new PublicKey(HEDGE_PROGRAM_ID)
|
6
9
|
|
7
|
-
export const CHAINLINK_SOL_USD_ID =
|
10
|
+
export const CHAINLINK_SOL_USD_ID =
|
11
|
+
'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'
|
8
12
|
export const CHAINLINK_SOL_USD_PUBLICKEY = new PublicKey(CHAINLINK_SOL_USD_ID)
|
9
13
|
|
10
14
|
const enc = new TextEncoder()
|
11
15
|
|
12
|
-
export async function getLiquidationPoolStatePublicKey
|
13
|
-
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
16
|
+
export async function getLiquidationPoolStatePublicKey(): Promise<PublicKey> {
|
17
|
+
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
18
|
+
[enc.encode('LiquidationPoolStateV1')],
|
19
|
+
HEDGE_PROGRAM_PUBLICKEY
|
20
|
+
)
|
14
21
|
return poolPublicKey
|
15
22
|
}
|
16
23
|
|
17
|
-
export async function getLiquidationPoolUshAccountPublicKey
|
18
|
-
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
24
|
+
export async function getLiquidationPoolUshAccountPublicKey(): Promise<PublicKey> {
|
25
|
+
const [poolPublicKey] = await PublicKey.findProgramAddress(
|
26
|
+
[enc.encode('LiquidationPoolUSHAccountV1')],
|
27
|
+
HEDGE_PROGRAM_PUBLICKEY
|
28
|
+
)
|
19
29
|
return poolPublicKey
|
20
30
|
}
|
21
31
|
|
22
|
-
export async function getUshMintPublicKey
|
23
|
-
const [findMintPublicKey] = await PublicKey.findProgramAddress(
|
32
|
+
export async function getUshMintPublicKey(): Promise<PublicKey> {
|
33
|
+
const [findMintPublicKey] = await PublicKey.findProgramAddress(
|
34
|
+
[enc.encode('UshMintV1')],
|
35
|
+
HEDGE_PROGRAM_PUBLICKEY
|
36
|
+
)
|
24
37
|
return findMintPublicKey
|
25
38
|
}
|
26
39
|
|
27
|
-
export async function getVaultSystemStatePublicKey
|
28
|
-
const [publicKey] = await PublicKey.findProgramAddress(
|
40
|
+
export async function getVaultSystemStatePublicKey(): Promise<PublicKey> {
|
41
|
+
const [publicKey] = await PublicKey.findProgramAddress(
|
42
|
+
[enc.encode('VaultSystemStateV1')],
|
43
|
+
HEDGE_PROGRAM_PUBLICKEY
|
44
|
+
)
|
29
45
|
return publicKey
|
30
46
|
}
|
31
47
|
|
32
|
-
export async function getHedgeMintPublicKey
|
33
|
-
const [publicKey] = await PublicKey.findProgramAddress(
|
48
|
+
export async function getHedgeMintPublicKey(): Promise<PublicKey> {
|
49
|
+
const [publicKey] = await PublicKey.findProgramAddress(
|
50
|
+
[enc.encode('HEDGEMintV1')],
|
51
|
+
HEDGE_PROGRAM_PUBLICKEY
|
52
|
+
)
|
34
53
|
return publicKey
|
35
54
|
}
|
36
55
|
|
37
|
-
export async function getPoolPublicKeyForMint
|
38
|
-
|
39
|
-
|
56
|
+
export async function getPoolPublicKeyForMint(
|
57
|
+
mintPublicKey: PublicKey
|
58
|
+
): Promise<[PublicKey, number, string]> {
|
59
|
+
const strToEncode = mintPublicKey.toString().substring(0, 12)
|
60
|
+
const [publicKey, bump] = await PublicKey.findProgramAddress(
|
61
|
+
[enc.encode(strToEncode)],
|
62
|
+
HEDGE_PROGRAM_PUBLICKEY
|
63
|
+
)
|
40
64
|
return [publicKey, bump, strToEncode]
|
41
65
|
}
|
42
|
-
export async function getVaultTypeAccountPublicKey
|
43
|
-
|
66
|
+
export async function getVaultTypeAccountPublicKey(
|
67
|
+
collateralType: string
|
68
|
+
): Promise<PublicKey> {
|
69
|
+
const [vaultTypeAccount] = await PublicKey.findProgramAddress(
|
70
|
+
[enc.encode(collateralType), enc.encode('State')],
|
71
|
+
HEDGE_PROGRAM_PUBLICKEY
|
72
|
+
)
|
44
73
|
return vaultTypeAccount
|
45
74
|
}
|
46
|
-
export async function getVaultTypeOracleAccountPublicKey
|
47
|
-
|
75
|
+
export async function getVaultTypeOracleAccountPublicKey(
|
76
|
+
collateralType: string
|
77
|
+
): Promise<PublicKey> {
|
78
|
+
const [vaultTypeOracleAccount] = await PublicKey.findProgramAddress(
|
79
|
+
[enc.encode(collateralType), enc.encode('Oracle')],
|
80
|
+
HEDGE_PROGRAM_PUBLICKEY
|
81
|
+
)
|
48
82
|
return vaultTypeOracleAccount
|
49
83
|
}
|
50
|
-
export async function findVaultAddress
|
51
|
-
const [vaultAddress] = await PublicKey.findProgramAddress(
|
84
|
+
export async function findVaultAddress(vaultSalt: string): Promise<PublicKey> {
|
85
|
+
const [vaultAddress] = await PublicKey.findProgramAddress(
|
86
|
+
[enc.encode('Vault'), enc.encode(vaultSalt)],
|
87
|
+
HEDGE_PROGRAM_PUBLICKEY
|
88
|
+
)
|
52
89
|
return vaultAddress
|
53
90
|
}
|
54
91
|
|
55
|
-
export async function findAssociatedTokenAddress
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
92
|
+
export async function findAssociatedTokenAddress(
|
93
|
+
walletAddress: PublicKey,
|
94
|
+
tokenMintAddress: PublicKey
|
95
|
+
): Promise<PublicKey> {
|
96
|
+
return (
|
97
|
+
await PublicKey.findProgramAddress(
|
98
|
+
[
|
99
|
+
walletAddress.toBuffer(),
|
100
|
+
TOKEN_PROGRAM_ID.toBuffer(),
|
101
|
+
tokenMintAddress.toBuffer(),
|
102
|
+
],
|
103
|
+
ASSOCIATED_TOKEN_PROGRAM_ID
|
104
|
+
)
|
105
|
+
)[0]
|
64
106
|
}
|