hedge-web3 0.1.25 → 0.1.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/declarations/Constants.d.ts +3 -3
  2. package/declarations/idl/vault.d.ts +889 -752
  3. package/declarations/index.d.ts +2 -0
  4. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
  5. package/declarations/instructions/createVault.d.ts +1 -1
  6. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  7. package/declarations/instructions/depositVault.d.ts +1 -1
  8. package/declarations/instructions/liquidateVault.d.ts +1 -1
  9. package/declarations/instructions/loanVault.d.ts +1 -1
  10. package/declarations/instructions/redeemVault.d.ts +1 -1
  11. package/declarations/instructions/repayVault.d.ts +1 -1
  12. package/declarations/instructions/setVaultTypeStatus.d.ts +4 -0
  13. package/declarations/instructions/withdrawVault.d.ts +1 -1
  14. package/declarations/state/LiquidationPosition.d.ts +2 -2
  15. package/declarations/state/StakingPool.d.ts +1 -1
  16. package/declarations/state/StakingPoolPosition.d.ts +2 -2
  17. package/declarations/state/VaultAccount.d.ts +11 -3
  18. package/declarations/state/VaultHistoryEvent.d.ts +2 -2
  19. package/declarations/utils/getLinkedListAccounts.d.ts +3 -0
  20. package/lib/Constants.js +10 -10
  21. package/lib/idl/vault.js +922 -785
  22. package/lib/index.js +2 -0
  23. package/lib/instructions/closeLiquidationPoolPosition.js +9 -9
  24. package/lib/instructions/createStakingPool.js +6 -6
  25. package/lib/instructions/createVault.js +11 -11
  26. package/lib/instructions/depositLiquidationPool.js +9 -9
  27. package/lib/instructions/depositVault.js +20 -13
  28. package/lib/instructions/initHedgeFoundation.js +4 -4
  29. package/lib/instructions/liquidateVault.js +16 -11
  30. package/lib/instructions/loanVault.js +16 -11
  31. package/lib/instructions/redeemVault.js +15 -10
  32. package/lib/instructions/repayVault.js +17 -12
  33. package/lib/instructions/setVaultTypeStatus.js +38 -0
  34. package/lib/instructions/withdrawStakingPool.js +6 -6
  35. package/lib/instructions/withdrawVault.js +18 -13
  36. package/lib/state/LiquidationPosition.js +2 -2
  37. package/lib/state/StakingPool.js +1 -1
  38. package/lib/state/StakingPoolPosition.js +3 -3
  39. package/lib/state/VaultAccount.js +56 -3
  40. package/lib/state/VaultHistoryEvent.js +2 -2
  41. package/lib/utils/Errors.js +2 -2
  42. package/lib/utils/getLinkedListAccounts.js +131 -0
  43. package/package.json +3 -1
  44. package/src/Constants.ts +73 -31
  45. package/src/idl/vault.ts +1848 -1574
  46. package/src/index.ts +3 -0
  47. package/src/instructions/closeLiquidationPoolPosition.ts +10 -10
  48. package/src/instructions/createStakingPool.ts +6 -7
  49. package/src/instructions/createVault.ts +17 -17
  50. package/src/instructions/depositLiquidationPool.ts +10 -10
  51. package/src/instructions/depositVault.ts +104 -29
  52. package/src/instructions/initHedgeFoundation.ts +5 -5
  53. package/src/instructions/initHedgeFoundationTokens.ts +1 -1
  54. package/src/instructions/liquidateVault.ts +124 -27
  55. package/src/instructions/loanVault.ts +97 -25
  56. package/src/instructions/redeemVault.ts +35 -12
  57. package/src/instructions/repayVault.ts +91 -26
  58. package/src/instructions/setHalted.ts +1 -1
  59. package/src/instructions/setVaultTypeStatus.ts +50 -0
  60. package/src/instructions/withdrawStakingPool.ts +7 -7
  61. package/src/instructions/withdrawVault.ts +106 -28
  62. package/src/state/LiquidationPosition.ts +3 -3
  63. package/src/state/StakingPool.ts +2 -6
  64. package/src/state/StakingPoolPosition.ts +4 -4
  65. package/src/state/VaultAccount.ts +89 -13
  66. package/src/state/VaultHistoryEvent.ts +4 -4
  67. package/src/utils/Errors.ts +2 -2
  68. package/src/utils/getLinkedListAccounts.ts +156 -0
  69. package/declarations/idl/idl.d.ts +0 -2
  70. package/lib/idl/idl.js +0 -1475
  71. package/src/idl/idl.ts +0 -1474
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export * from './instructions/refreshOraclePrice'
17
17
  export * from './instructions/initHedgeFoundation'
18
18
  export * from './instructions/initHedgeFoundationTokens'
19
19
  export * from './instructions/setHalted'
20
+ export * from './instructions/setVaultTypeStatus'
20
21
 
21
22
  export * from './HedgeDecimal'
22
23
  export * from './Constants'
@@ -28,3 +29,5 @@ export * from './state/StakingPoolPosition'
28
29
  export * from './state/LiquidationPoolEra'
29
30
  export * from './state/LiquidationPoolState'
30
31
  export * from './state/LiquidationPosition'
32
+
33
+ export * from './utils/getLinkedListAccounts'
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import { PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
4
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
+ import { getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
6
 
7
7
  export async function closeLiquidationPoolPosition (
8
8
  program: Program,
@@ -11,8 +11,8 @@ export async function closeLiquidationPoolPosition (
11
11
  payer: Signer,
12
12
  overrideStartTime?: number
13
13
  ): Promise<PublicKey> {
14
- const usdhMintPublickey = await getUsdhMintPublicKey()
15
- const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
14
+ const ushMintPublickey = await getUshMintPublicKey()
15
+ const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
16
16
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
17
17
  const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition)
18
18
  const poolEra = liquidationPositionAccount.era
@@ -27,7 +27,7 @@ export async function closeLiquidationPoolPosition (
27
27
  poolEra,
28
28
  poolPosition,
29
29
  payer.publicKey,
30
- payerUsdhAccount.address,
30
+ payerUshAccount.address,
31
31
  payerAssociatedHedgeAccount.address,
32
32
  communityAssociatedHedgeTokenAccount.address,
33
33
  overrideStartTime
@@ -42,16 +42,16 @@ export async function closeLiquidationPoolPositionInstruction (
42
42
  poolEra: PublicKey,
43
43
  poolPosition: PublicKey,
44
44
  payerPublicKey: PublicKey,
45
- payerUsdhAccount: PublicKey,
45
+ payerUshAccount: PublicKey,
46
46
  payerAssociatedHedgeAccount: PublicKey,
47
47
  communityAssociatedHedgeTokenAccount: PublicKey,
48
48
  overrideStartTime?: number
49
49
  ): Promise<TransactionInstruction> {
50
50
 
51
51
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
52
- const usdhMint = await getUsdhMintPublicKey()
52
+ const ushMint = await getUshMintPublicKey()
53
53
  const hedgeMint = await getHedgeMintPublicKey()
54
- const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey()
54
+ const poolUshAccount = await getLiquidationPoolUshAccountPublicKey()
55
55
  const poolState = await getLiquidationPoolStatePublicKey()
56
56
 
57
57
  return program.instruction.closeLiquidationPoolPosition(
@@ -62,11 +62,11 @@ export async function closeLiquidationPoolPositionInstruction (
62
62
  poolState: poolState,
63
63
  poolEra: poolEra,
64
64
  poolPosition: poolPosition,
65
- poolUsdhAccount: poolUsdhAccount,
65
+ poolUshAccount: poolUshAccount,
66
66
  payer: payerPublicKey,
67
- ownerUsdhAccount: payerUsdhAccount,
67
+ ownerUshAccount: payerUshAccount,
68
68
  hedgeMint: hedgeMint,
69
- usdhMint: usdhMint,
69
+ ushMint: ushMint,
70
70
  payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
71
71
  communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
72
72
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import { PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
4
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
+ import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
6
 
7
7
  export async function createStakingPool (
8
8
  program: Program,
@@ -35,15 +35,14 @@ export async function createStakingPoolInstruction (
35
35
  ): Promise<TransactionInstruction> {
36
36
  console.log("createStakingPoolInstruction program ID", program.programId.toString())
37
37
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
38
- const usdhMintPublickey = await getUsdhMintPublicKey()
39
- const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey)
38
+ const ushMintPublickey = await getUshMintPublicKey()
39
+ const [poolPublickey, poolBump] = await getPoolPublicKeyForMint(mintPublicKey)
40
40
 
41
41
  const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey)
42
- const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey)
42
+ const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(poolPublickey, ushMintPublickey)
43
43
 
44
44
  return program.instruction.createStakingPool(
45
45
  poolBump,
46
- poolSeedPhrase,
47
46
  new BN(hedgeTokensToBeMinted),
48
47
  new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)),
49
48
  {
@@ -52,9 +51,9 @@ export async function createStakingPoolInstruction (
52
51
  vaultSystemState: vaultSystemStatePublicKey,
53
52
  pool: poolPublickey,
54
53
  stakedTokenMintInfo: mintPublicKey,
55
- usdhMint: usdhMintPublickey,
54
+ ushMint: ushMintPublickey,
56
55
  poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
57
- poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
56
+ poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
58
57
  rent: SYSVAR_RENT_PUBKEY,
59
58
  tokenProgram: TOKEN_PROGRAM_ID,
60
59
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -19,7 +19,7 @@ import {
19
19
  findAssociatedTokenAddress,
20
20
  findVaultAddress,
21
21
  getVaultTypeAccountPublicKey,
22
- getUsdhMintPublicKey,
22
+ getUshMintPublicKey,
23
23
  getVaultSystemStatePublicKey,
24
24
  getPoolPublicKeyForMint,
25
25
  getHedgeMintPublicKey,
@@ -36,17 +36,17 @@ export async function createVault(
36
36
  depositAmount: number,
37
37
  overrideTime?: number
38
38
  ): Promise<PublicKey> {
39
- const usdhMintPublickey = await getUsdhMintPublicKey();
39
+ const ushMintPublickey = await getUshMintPublicKey();
40
40
 
41
41
  const salt = uuidv4().substring(0, 8);
42
42
  const newVaultPublicKey = await findVaultAddress(salt);
43
43
  const history = Keypair.generate();
44
44
 
45
- // Prep the user to get USDH back out at some point
45
+ // Prep the user to get USH back out at some point
46
46
  await getOrCreateAssociatedTokenAccount(
47
47
  provider.connection,
48
48
  payer,
49
- usdhMintPublickey,
49
+ ushMintPublickey,
50
50
  payer.publicKey
51
51
  );
52
52
 
@@ -78,9 +78,9 @@ export async function createVault(
78
78
  const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
79
79
  await getHedgeMintPublicKey()
80
80
  );
81
- const feePoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
81
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
82
82
  hedgeStakingPoolPublicKey,
83
- usdhMintPublickey
83
+ ushMintPublickey
84
84
  );
85
85
 
86
86
  if (isWrappedSol) {
@@ -109,11 +109,11 @@ export async function createVault(
109
109
  newVaultPublicKey,
110
110
  vaultAssociatedTokenAccount,
111
111
  hedgeStakingPoolPublicKey,
112
- feePoolAssociatedUsdhTokenAccount,
112
+ feePoolAssociatedUshTokenAccount,
113
113
  vaultTypeAccountPublicKey,
114
114
  vaultTypeAccountInfo.collateralMint,
115
115
  history.publicKey,
116
- usdhMintPublickey,
116
+ ushMintPublickey,
117
117
  depositAmount,
118
118
  overrideTime
119
119
  )
@@ -145,7 +145,7 @@ export async function buildCreateVaultTransaction(
145
145
  ): Promise<[Transaction, Signer[], PublicKey]> {
146
146
 
147
147
  console.log("HEDGE SDK: buildCreateVaultTransaction")
148
- const usdhMintPublickey = await getUsdhMintPublicKey();
148
+ const ushMintPublickey = await getUshMintPublicKey();
149
149
  const payerPublicKey = program.provider.wallet.publicKey;
150
150
 
151
151
  const salt = uuidv4().substring(0, 8);
@@ -189,9 +189,9 @@ export async function buildCreateVaultTransaction(
189
189
  const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
190
190
  await getHedgeMintPublicKey()
191
191
  );
192
- const feePoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
192
+ const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
193
193
  hedgeStakingPoolPublicKey,
194
- usdhMintPublickey
194
+ ushMintPublickey
195
195
  );
196
196
 
197
197
  console.log('about to start building transaction')
@@ -224,11 +224,11 @@ export async function buildCreateVaultTransaction(
224
224
  newVaultPublicKey,
225
225
  vaultAssociatedTokenAccount,
226
226
  hedgeStakingPoolPublicKey,
227
- feePoolAssociatedUsdhTokenAccount,
227
+ feePoolAssociatedUshTokenAccount,
228
228
  vaultTypeAccountPublicKey,
229
229
  vaultTypeAccountInfo.collateralMint,
230
230
  history.publicKey,
231
- usdhMintPublickey,
231
+ ushMintPublickey,
232
232
  depositAmount,
233
233
  overrideTime
234
234
  )
@@ -258,11 +258,11 @@ export async function createVaultInstruction(
258
258
  vaultPublicKey: PublicKey,
259
259
  vaultAssociatedTokenAccount: PublicKey,
260
260
  feePool: PublicKey,
261
- feePoolAssociatedUsdhTokenAccount: PublicKey,
261
+ feePoolAssociatedUshTokenAccount: PublicKey,
262
262
  vaultTypeAccount: PublicKey,
263
263
  collateralMint: PublicKey,
264
264
  historyPublicKey: PublicKey,
265
- usdhMintPublickey: PublicKey,
265
+ ushMintPublickey: PublicKey,
266
266
  depositAmount: number,
267
267
  overrideTime?: number
268
268
  ): Promise<TransactionInstruction> {
@@ -279,12 +279,12 @@ export async function createVaultInstruction(
279
279
  vault: vaultPublicKey,
280
280
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
281
281
  feePool: feePool,
282
- feePoolAssociatedUsdhTokenAccount: feePoolAssociatedUsdhTokenAccount,
282
+ feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
283
283
  history: historyPublicKey,
284
284
  payer: payerPublicKey,
285
285
  payerTokenAccount: payerTokenAccountPublicKey,
286
286
  collateralMint: collateralMint,
287
- usdhMint: usdhMintPublickey,
287
+ ushMint: ushMintPublickey,
288
288
  systemProgram: SystemProgram.programId,
289
289
  tokenProgram: TOKEN_PROGRAM_ID,
290
290
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -2,7 +2,7 @@ import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
4
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
+ import { getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
6
 
7
7
  export async function depositLiquidationPool (
8
8
  program: Program,
@@ -11,15 +11,15 @@ export async function depositLiquidationPool (
11
11
  depositAmount: number,
12
12
  overrideStartTime?: number
13
13
  ): Promise<PublicKey> {
14
- const usdhMintPublickey = await getUsdhMintPublicKey()
15
- const payerUsdhAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
14
+ const ushMintPublickey = await getUshMintPublicKey()
15
+ const payerUshAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
16
16
 
17
17
  const poolPosition = Keypair.generate()
18
18
  const transaction = new Transaction().add(
19
19
  await depositLiquidationPoolInstruction(
20
20
  program,
21
21
  payer.publicKey,
22
- payerUsdhAccount.address,
22
+ payerUshAccount.address,
23
23
  poolPosition.publicKey,
24
24
  depositAmount,
25
25
  overrideStartTime
@@ -32,7 +32,7 @@ export async function depositLiquidationPool (
32
32
  export async function depositLiquidationPoolInstruction (
33
33
  program: Program,
34
34
  payerPublicKey: PublicKey,
35
- payerUsdhAccount: PublicKey,
35
+ payerUshAccount: PublicKey,
36
36
  poolPositionPublicKey: PublicKey,
37
37
  depositAmount: number,
38
38
  overrideStartTime?: number
@@ -40,8 +40,8 @@ export async function depositLiquidationPoolInstruction (
40
40
  const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey()
41
41
  const liquidationPoolState = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey)
42
42
 
43
- const poolUSDHAccount = await getLiquidationPoolUsdhAccountPublicKey()
44
- const usdhMint = await getUsdhMintPublicKey()
43
+ const poolUSHAccount = await getLiquidationPoolUshAccountPublicKey()
44
+ const ushMint = await getUshMintPublicKey()
45
45
 
46
46
  const vaultSystemState = await getVaultSystemStatePublicKey()
47
47
 
@@ -54,10 +54,10 @@ export async function depositLiquidationPoolInstruction (
54
54
  poolState: liquidationPoolStatePublicKey,
55
55
  poolEra: liquidationPoolState.currentEra,
56
56
  poolPosition: poolPositionPublicKey,
57
- poolUsdhAccount: poolUSDHAccount,
58
- usdhMint: usdhMint,
57
+ poolUshAccount: poolUSHAccount,
58
+ ushMint: ushMint,
59
59
  payer: payerPublicKey,
60
- ownerUsdhAccount: payerUsdhAccount,
60
+ ownerUshAccount: payerUshAccount,
61
61
  tokenProgram: TOKEN_PROGRAM_ID,
62
62
  systemProgram: SystemProgram.programId,
63
63
  rent: SYSVAR_RENT_PUBKEY
@@ -1,8 +1,27 @@
1
1
  import { BN, Program, Provider } from '@project-serum/anchor'
2
2
  import { TokenInstructions } from '@project-serum/serum'
3
- import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
4
- import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
5
- import { findAssociatedTokenAddress, getVaultTypeAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey, getPoolPublicKeyForMint, getHedgeMintPublicKey } from '../Constants'
3
+ import {
4
+ getOrCreateAssociatedTokenAccount,
5
+ TOKEN_PROGRAM_ID,
6
+ } from '@solana/spl-token'
7
+ import {
8
+ Keypair,
9
+ PublicKey,
10
+ sendAndConfirmTransaction,
11
+ Signer,
12
+ SystemProgram,
13
+ Transaction,
14
+ TransactionInstruction,
15
+ } from '@solana/web3.js'
16
+ import { getLinkedListAccounts } from '../utils/getLinkedListAccounts'
17
+ import {
18
+ findAssociatedTokenAddress,
19
+ getVaultTypeAccountPublicKey,
20
+ getUshMintPublicKey,
21
+ getVaultSystemStatePublicKey,
22
+ getPoolPublicKeyForMint,
23
+ getHedgeMintPublicKey,
24
+ } from '../Constants'
6
25
 
7
26
  export async function depositVault(
8
27
  program: Program,
@@ -12,33 +31,71 @@ export async function depositVault(
12
31
  depositAmount: number,
13
32
  overrideTime?: number
14
33
  ): Promise<PublicKey> {
15
- const usdhMintPublickey = await getUsdhMintPublicKey()
34
+ const ushMintPublickey = await getUshMintPublicKey()
16
35
 
17
- // Prep the user to get USDH back out at some point
18
- await getOrCreateAssociatedTokenAccount(provider.connection, payer, usdhMintPublickey, payer.publicKey)
36
+ // Prep the user to get USH back out at some point
37
+ await getOrCreateAssociatedTokenAccount(
38
+ provider.connection,
39
+ payer,
40
+ ushMintPublickey,
41
+ payer.publicKey
42
+ )
19
43
 
20
44
  const vaultAccount = await program.account.vault.fetch(vaultPublicKey)
21
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(vaultAccount.collateralType)
22
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
23
- const vaultTypeAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true)
45
+ const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
46
+ vaultAccount.collateralType
47
+ )
48
+ const vaultTypeAccountInfo = await program.account.vaultType.fetch(
49
+ vaultTypeAccountPublicKey
50
+ )
51
+ const vaultTypeAssociatedTokenAccount =
52
+ await getOrCreateAssociatedTokenAccount(
53
+ provider.connection,
54
+ payer,
55
+ vaultTypeAccountInfo.collateralMint,
56
+ vaultTypeAccountPublicKey,
57
+ true
58
+ )
24
59
 
25
- const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
26
- const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(vaultPublicKey, vaultTypeAccountInfo.collateralMint)
60
+ const payerTokenAccount = await findAssociatedTokenAddress(
61
+ payer.publicKey,
62
+ vaultTypeAccountInfo.collateralMint
63
+ )
64
+ const vaultAssociatedCollateralAccountPublicKey =
65
+ await findAssociatedTokenAddress(
66
+ vaultPublicKey,
67
+ vaultTypeAccountInfo.collateralMint
68
+ )
27
69
 
28
70
  const history = Keypair.generate()
29
71
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
30
72
 
31
73
  const wrappedSolAccount = Keypair.generate()
32
74
 
33
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
34
- const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(
35
- hedgeStakingPoolPublicKey,
36
- usdhMintPublickey
75
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
76
+ await getHedgeMintPublicKey()
37
77
  )
78
+ const hedgeStakingPoolAssociatedUshTokenAccount =
79
+ await findAssociatedTokenAddress(
80
+ hedgeStakingPoolPublicKey,
81
+ ushMintPublickey
82
+ )
38
83
 
39
84
  const transaction = new Transaction()
40
85
  const signers = [payer, history]
41
86
 
87
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] =
88
+ await getLinkedListAccounts(
89
+ program,
90
+ provider,
91
+ vaultTypeAccountPublicKey,
92
+ vaultPublicKey,
93
+ depositAmount,
94
+ 0,
95
+ false,
96
+ false
97
+ )
98
+
42
99
  if (vaultAccount.collateralType === 'SOL') {
43
100
  transaction.add(
44
101
  SystemProgram.createAccount({
@@ -46,12 +103,12 @@ export async function depositVault(
46
103
  lamports: depositAmount + 2.04e6,
47
104
  newAccountPubkey: wrappedSolAccount.publicKey,
48
105
  programId: TOKEN_PROGRAM_ID,
49
- space: 165
106
+ space: 165,
50
107
  }),
51
108
  TokenInstructions.initializeAccount({
52
109
  account: wrappedSolAccount.publicKey,
53
110
  mint: TokenInstructions.WRAPPED_SOL_MINT,
54
- owner: payer.publicKey
111
+ owner: payer.publicKey,
55
112
  })
56
113
  )
57
114
  signers.push(wrappedSolAccount)
@@ -61,16 +118,21 @@ export async function depositVault(
61
118
  program,
62
119
  vaultSystemStatePublicKey,
63
120
  payer.publicKey,
64
- vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount,
121
+ vaultAccount.collateralType === 'SOL'
122
+ ? wrappedSolAccount.publicKey
123
+ : payerTokenAccount,
65
124
  vaultPublicKey,
66
125
  vaultAssociatedCollateralAccountPublicKey,
67
126
  history.publicKey,
68
127
  vaultTypeAccountPublicKey,
69
128
  vaultTypeAssociatedTokenAccount.address,
70
129
  hedgeStakingPoolPublicKey,
71
- hedgeStakingPoolAssociatedUsdhTokenAccount,
130
+ hedgeStakingPoolAssociatedUshTokenAccount,
72
131
  vaultTypeAccountInfo.collateralMint,
73
- usdhMintPublickey,
132
+ ushMintPublickey,
133
+ oldSmallerPublicKey,
134
+ newSmallerPublicKey,
135
+ newLargerPublicKey,
74
136
  depositAmount,
75
137
  overrideTime
76
138
  )
@@ -80,12 +142,17 @@ export async function depositVault(
80
142
  TokenInstructions.closeAccount({
81
143
  source: wrappedSolAccount.publicKey,
82
144
  destination: payer.publicKey,
83
- owner: payer.publicKey
145
+ owner: payer.publicKey,
84
146
  })
85
147
  )
86
148
  }
87
149
 
88
- await sendAndConfirmTransaction(provider.connection, transaction, signers, provider.opts)
150
+ await sendAndConfirmTransaction(
151
+ provider.connection,
152
+ transaction,
153
+ signers,
154
+ provider.opts
155
+ )
89
156
  return vaultPublicKey
90
157
  }
91
158
 
@@ -100,9 +167,12 @@ export async function depositVaultInstruction(
100
167
  vaultTypeAccountPublicKey: PublicKey,
101
168
  vaultTypeAssociatedTokenAccount: PublicKey,
102
169
  hedgeStakingPoolPublicKey: PublicKey,
103
- hedgeStakingPoolAssociatedUsdhTokenAccount: PublicKey,
170
+ hedgeStakingPoolAssociatedUshTokenAccount: PublicKey,
104
171
  collateralMint: PublicKey,
105
- usdhMintPublickey: PublicKey,
172
+ ushMintPublickey: PublicKey,
173
+ oldSmallerPublicKey: PublicKey,
174
+ newSmallerPublicKey: PublicKey,
175
+ newLargerPublicKey: PublicKey,
106
176
  depositAmount: number,
107
177
  overrideTime?: number
108
178
  ): Promise<TransactionInstruction> {
@@ -118,14 +188,19 @@ export async function depositVaultInstruction(
118
188
  vault: vaultPublicKey,
119
189
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
120
190
  feePool: hedgeStakingPoolPublicKey,
121
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
191
+ feePoolAssociatedUshTokenAccount:
192
+ hedgeStakingPoolAssociatedUshTokenAccount,
122
193
  history: historyPublicKey,
123
194
  vaultOwner: vaultOwner,
124
195
  vaultOwnerTokenAccount: vaultOwnerTokenAccount,
125
- usdhMint: usdhMintPublickey,
196
+ ushMint: ushMintPublickey,
197
+ oldSmallerVaultInfo: oldSmallerPublicKey,
198
+ newSmallerVaultInfo: newSmallerPublicKey,
199
+ newLargerVaultInfo: newLargerPublicKey,
126
200
  systemProgram: SystemProgram.programId,
127
- tokenProgram: TOKEN_PROGRAM_ID
201
+ tokenProgram: TOKEN_PROGRAM_ID,
128
202
  },
129
- signers: []
130
- })
203
+ signers: [],
204
+ }
205
+ )
131
206
  }
@@ -2,7 +2,7 @@ import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
4
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
+ import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
6
 
7
7
  export async function initHedgeFoundation(
8
8
  program: Program,
@@ -30,8 +30,8 @@ export async function initHedgeFoundationInstruction (
30
30
  ): Promise<TransactionInstruction> {
31
31
  const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
32
32
  const poolStatePublickey = await getLiquidationPoolStatePublicKey()
33
- const poolUsdhTokenAccount = await getLiquidationPoolUsdhAccountPublicKey()
34
- const usdhMintPublickey = await getUsdhMintPublicKey()
33
+ const poolUshTokenAccount = await getLiquidationPoolUshAccountPublicKey()
34
+ const ushMintPublickey = await getUshMintPublicKey()
35
35
  const hedgeMintPublickey = await getHedgeMintPublicKey()
36
36
  const founderHedgeTokenAccount = await findAssociatedTokenAddress(
37
37
  payerPublicKey,
@@ -48,9 +48,9 @@ export async function initHedgeFoundationInstruction (
48
48
  vaultSystemState: vaultSystemStatePublicKey,
49
49
  poolState: poolStatePublickey,
50
50
  poolEra: poolEraPublicKey,
51
- poolUsdhAccount: poolUsdhTokenAccount,
51
+ poolUshAccount: poolUshTokenAccount,
52
52
  founder: payerPublicKey,
53
- usdhMint: usdhMintPublickey,
53
+ ushMint: ushMintPublickey,
54
54
  hedgeMint: hedgeMintPublickey,
55
55
  founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
56
56
  communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
@@ -2,7 +2,7 @@ import { Program, Provider } from '@project-serum/anchor'
2
2
  import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
3
  import { Keypair, PublicKey, sendAndConfirmTransaction, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
4
  import { parseAnchorErrors } from '../utils/Errors'
5
- import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUsdhAccountPublicKey, getUsdhMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
5
+ import { findAssociatedTokenAddress, getHedgeMintPublicKey, getLiquidationPoolStatePublicKey, getLiquidationPoolUshAccountPublicKey, getUshMintPublicKey, getVaultSystemStatePublicKey } from '../Constants'
6
6
 
7
7
  export async function initHedgeFoundationTokens(
8
8
  program: Program,