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/lib/index.js CHANGED
@@ -28,6 +28,7 @@ __exportStar(require("./instructions/refreshOraclePrice"), exports);
28
28
  __exportStar(require("./instructions/initHedgeFoundation"), exports);
29
29
  __exportStar(require("./instructions/initHedgeFoundationTokens"), exports);
30
30
  __exportStar(require("./instructions/setHalted"), exports);
31
+ __exportStar(require("./instructions/setVaultTypeStatus"), exports);
31
32
  __exportStar(require("./HedgeDecimal"), exports);
32
33
  __exportStar(require("./Constants"), exports);
33
34
  __exportStar(require("./state/VaultAccount"), exports);
@@ -37,3 +38,4 @@ __exportStar(require("./state/StakingPoolPosition"), exports);
37
38
  __exportStar(require("./state/LiquidationPoolEra"), exports);
38
39
  __exportStar(require("./state/LiquidationPoolState"), exports);
39
40
  __exportStar(require("./state/LiquidationPosition"), exports);
41
+ __exportStar(require("./utils/getLinkedListAccounts"), exports);
@@ -17,26 +17,26 @@ const Errors_1 = require("../utils/Errors");
17
17
  const Constants_1 = require("../Constants");
18
18
  function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
21
- const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
20
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
21
+ const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
22
22
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
23
23
  const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
24
24
  const poolEra = liquidationPositionAccount.era;
25
25
  const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
26
26
  const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
27
27
  const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
28
- const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUsdhAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
28
+ const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
29
29
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
30
30
  return poolPosition;
31
31
  });
32
32
  }
33
33
  exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
34
- function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUsdhAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
34
+ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
36
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
37
- const usdhMint = yield (0, Constants_1.getUsdhMintPublicKey)();
37
+ const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
38
38
  const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
39
- const poolUsdhAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
39
+ const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
40
40
  const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
41
41
  return program.instruction.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
42
42
  {
@@ -45,11 +45,11 @@ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition,
45
45
  poolState: poolState,
46
46
  poolEra: poolEra,
47
47
  poolPosition: poolPosition,
48
- poolUsdhAccount: poolUsdhAccount,
48
+ poolUshAccount: poolUshAccount,
49
49
  payer: payerPublicKey,
50
- ownerUsdhAccount: payerUsdhAccount,
50
+ ownerUshAccount: payerUshAccount,
51
51
  hedgeMint: hedgeMint,
52
- usdhMint: usdhMint,
52
+ ushMint: ushMint,
53
53
  payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
54
54
  communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
55
55
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -28,19 +28,19 @@ function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, he
28
28
  return __awaiter(this, void 0, void 0, function* () {
29
29
  console.log("createStakingPoolInstruction program ID", program.programId.toString());
30
30
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
31
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
32
- const [poolPublickey, poolBump, poolSeedPhrase] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
31
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
32
+ const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
33
33
  const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
34
- const poolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, usdhMintPublickey);
35
- return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), {
34
+ const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
35
+ return program.instruction.createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), {
36
36
  accounts: {
37
37
  signer: payerPublicKey,
38
38
  vaultSystemState: vaultSystemStatePublicKey,
39
39
  pool: poolPublickey,
40
40
  stakedTokenMintInfo: mintPublicKey,
41
- usdhMint: usdhMintPublickey,
41
+ ushMint: ushMintPublickey,
42
42
  poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
43
- poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
43
+ poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
44
44
  rent: web3_js_1.SYSVAR_RENT_PUBKEY,
45
45
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
46
46
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -19,12 +19,12 @@ const uuid_1 = require("uuid");
19
19
  const Errors_1 = require("../utils/Errors");
20
20
  function createVault(program, provider, payer, collateralType, depositAmount, overrideTime) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
22
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
23
23
  const salt = (0, uuid_1.v4)().substring(0, 8);
24
24
  const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
25
25
  const history = web3_js_1.Keypair.generate();
26
- // Prep the user to get USDH back out at some point
27
- yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
26
+ // Prep the user to get USH back out at some point
27
+ yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
28
28
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
29
29
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
30
30
  const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
@@ -35,7 +35,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
35
35
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
36
36
  serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
37
37
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
38
- const feePoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
38
+ const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
39
39
  if (isWrappedSol) {
40
40
  transaction.add(web3_js_1.SystemProgram.createAccount({
41
41
  fromPubkey: payer.publicKey,
@@ -50,7 +50,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
50
50
  }));
51
51
  signers.push(wrappedSolAccount);
52
52
  }
53
- transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUsdhTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, usdhMintPublickey, depositAmount, overrideTime));
53
+ transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
54
54
  if (isWrappedSol) {
55
55
  transaction.add(serum_1.TokenInstructions.closeAccount({
56
56
  source: wrappedSolAccount.publicKey,
@@ -66,7 +66,7 @@ exports.createVault = createVault;
66
66
  function buildCreateVaultTransaction(program, collateralType, depositAmount, overrideTime) {
67
67
  return __awaiter(this, void 0, void 0, function* () {
68
68
  console.log("HEDGE SDK: buildCreateVaultTransaction");
69
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
69
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
70
70
  const payerPublicKey = program.provider.wallet.publicKey;
71
71
  const salt = (0, uuid_1.v4)().substring(0, 8);
72
72
  const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
@@ -89,7 +89,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
89
89
  const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
90
90
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
91
91
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
92
- const feePoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
92
+ const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
93
93
  console.log('about to start building transaction');
94
94
  // If wrapped SOL collateral, we convert the SOL to wSOL to use in the instruction
95
95
  if (isWrappedSol) {
@@ -107,7 +107,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
107
107
  signers.push(wrappedSolAccount);
108
108
  }
109
109
  console.log("hedgeStakingPoolPublicKey", hedgeStakingPoolPublicKey.toString());
110
- transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUsdhTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, usdhMintPublickey, depositAmount, overrideTime));
110
+ transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
111
111
  if (isWrappedSol) {
112
112
  transaction.add(serum_1.TokenInstructions.closeAccount({
113
113
  source: wrappedSolAccount.publicKey,
@@ -122,7 +122,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
122
122
  });
123
123
  }
124
124
  exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
125
- function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUsdhTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, usdhMintPublickey, depositAmount, overrideTime) {
125
+ function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
126
126
  return __awaiter(this, void 0, void 0, function* () {
127
127
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
128
128
  const ix = program.instruction.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
@@ -133,12 +133,12 @@ function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccount
133
133
  vault: vaultPublicKey,
134
134
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
135
135
  feePool: feePool,
136
- feePoolAssociatedUsdhTokenAccount: feePoolAssociatedUsdhTokenAccount,
136
+ feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
137
137
  history: historyPublicKey,
138
138
  payer: payerPublicKey,
139
139
  payerTokenAccount: payerTokenAccountPublicKey,
140
140
  collateralMint: collateralMint,
141
- usdhMint: usdhMintPublickey,
141
+ ushMint: ushMintPublickey,
142
142
  systemProgram: web3_js_1.SystemProgram.programId,
143
143
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
144
144
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
@@ -17,21 +17,21 @@ const Errors_1 = require("../utils/Errors");
17
17
  const Constants_1 = require("../Constants");
18
18
  function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime) {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
21
- const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
20
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
21
+ const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
22
22
  const poolPosition = web3_js_1.Keypair.generate();
23
- const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUsdhAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
23
+ const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
24
24
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(Errors_1.parseAnchorErrors);
25
25
  return poolPosition.publicKey;
26
26
  });
27
27
  }
28
28
  exports.depositLiquidationPool = depositLiquidationPool;
29
- function depositLiquidationPoolInstruction(program, payerPublicKey, payerUsdhAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
29
+ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
32
32
  const liquidationPoolState = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
33
- const poolUSDHAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
34
- const usdhMint = yield (0, Constants_1.getUsdhMintPublicKey)();
33
+ const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
34
+ const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
35
35
  const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
36
36
  return program.instruction.depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
37
37
  {
@@ -40,10 +40,10 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUsdhAcc
40
40
  poolState: liquidationPoolStatePublicKey,
41
41
  poolEra: liquidationPoolState.currentEra,
42
42
  poolPosition: poolPositionPublicKey,
43
- poolUsdhAccount: poolUSDHAccount,
44
- usdhMint: usdhMint,
43
+ poolUshAccount: poolUSHAccount,
44
+ ushMint: ushMint,
45
45
  payer: payerPublicKey,
46
- ownerUsdhAccount: payerUsdhAccount,
46
+ ownerUshAccount: payerUshAccount,
47
47
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
48
48
  systemProgram: web3_js_1.SystemProgram.programId,
49
49
  rent: web3_js_1.SYSVAR_RENT_PUBKEY
@@ -14,12 +14,13 @@ const anchor_1 = require("@project-serum/anchor");
14
14
  const serum_1 = require("@project-serum/serum");
15
15
  const spl_token_1 = require("@solana/spl-token");
16
16
  const web3_js_1 = require("@solana/web3.js");
17
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
17
18
  const Constants_1 = require("../Constants");
18
19
  function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
21
- // Prep the user to get USDH back out at some point
22
- yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
21
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
22
+ // Prep the user to get USH back out at some point
23
+ yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
23
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
24
25
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
25
26
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
@@ -30,29 +31,32 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
30
31
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
31
32
  const wrappedSolAccount = web3_js_1.Keypair.generate();
32
33
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
33
- const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
34
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
34
35
  const transaction = new web3_js_1.Transaction();
35
36
  const signers = [payer, history];
37
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, depositAmount, 0, false, false);
36
38
  if (vaultAccount.collateralType === 'SOL') {
37
39
  transaction.add(web3_js_1.SystemProgram.createAccount({
38
40
  fromPubkey: payer.publicKey,
39
41
  lamports: depositAmount + 2.04e6,
40
42
  newAccountPubkey: wrappedSolAccount.publicKey,
41
43
  programId: spl_token_1.TOKEN_PROGRAM_ID,
42
- space: 165
44
+ space: 165,
43
45
  }), serum_1.TokenInstructions.initializeAccount({
44
46
  account: wrappedSolAccount.publicKey,
45
47
  mint: serum_1.TokenInstructions.WRAPPED_SOL_MINT,
46
- owner: payer.publicKey
48
+ owner: payer.publicKey,
47
49
  }));
48
50
  signers.push(wrappedSolAccount);
49
51
  }
50
- transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUsdhTokenAccount, vaultTypeAccountInfo.collateralMint, usdhMintPublickey, depositAmount, overrideTime));
52
+ transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL'
53
+ ? wrappedSolAccount.publicKey
54
+ : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
51
55
  if (vaultAccount.collateralType === 'SOL') {
52
56
  transaction.add(serum_1.TokenInstructions.closeAccount({
53
57
  source: wrappedSolAccount.publicKey,
54
58
  destination: payer.publicKey,
55
- owner: payer.publicKey
59
+ owner: payer.publicKey,
56
60
  }));
57
61
  }
58
62
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers, provider.opts);
@@ -60,7 +64,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
60
64
  });
61
65
  }
62
66
  exports.depositVault = depositVault;
63
- function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUsdhTokenAccount, collateralMint, usdhMintPublickey, depositAmount, overrideTime) {
67
+ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
64
68
  return __awaiter(this, void 0, void 0, function* () {
65
69
  return program.instruction.depositVault(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
66
70
  {
@@ -72,15 +76,18 @@ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner,
72
76
  vault: vaultPublicKey,
73
77
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
74
78
  feePool: hedgeStakingPoolPublicKey,
75
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
79
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
76
80
  history: historyPublicKey,
77
81
  vaultOwner: vaultOwner,
78
82
  vaultOwnerTokenAccount: vaultOwnerTokenAccount,
79
- usdhMint: usdhMintPublickey,
83
+ ushMint: ushMintPublickey,
84
+ oldSmallerVaultInfo: oldSmallerPublicKey,
85
+ newSmallerVaultInfo: newSmallerPublicKey,
86
+ newLargerVaultInfo: newLargerPublicKey,
80
87
  systemProgram: web3_js_1.SystemProgram.programId,
81
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
88
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
82
89
  },
83
- signers: []
90
+ signers: [],
84
91
  });
85
92
  });
86
93
  }
@@ -27,8 +27,8 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
28
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
29
29
  const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
30
- const poolUsdhTokenAccount = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
31
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
30
+ const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
31
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
32
32
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
33
33
  const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
34
34
  const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
@@ -37,9 +37,9 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
37
37
  vaultSystemState: vaultSystemStatePublicKey,
38
38
  poolState: poolStatePublickey,
39
39
  poolEra: poolEraPublicKey,
40
- poolUsdhAccount: poolUsdhTokenAccount,
40
+ poolUshAccount: poolUshTokenAccount,
41
41
  founder: payerPublicKey,
42
- usdhMint: usdhMintPublickey,
42
+ ushMint: ushMintPublickey,
43
43
  hedgeMint: hedgeMintPublickey,
44
44
  founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
45
45
  communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
@@ -13,6 +13,7 @@ exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -21,7 +22,7 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
21
22
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
22
23
  const collateralMint = vaultTypeAccountInfo.collateralMint;
23
24
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
24
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
25
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
25
26
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
26
27
  const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
27
28
  const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
@@ -30,21 +31,22 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
30
31
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
31
32
  const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
32
33
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
33
- const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, hedgeStakingPoolPublicKey, true);
34
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
35
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, false, true);
34
36
  const history = web3_js_1.Keypair.generate();
35
37
  const newEra = web3_js_1.Keypair.generate();
36
38
  const transaction = new web3_js_1.Transaction();
37
- transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUsdhTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, vaultAccount.collateralType, overrideTime));
39
+ transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultAccount.collateralType, overrideTime));
38
40
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra], provider.opts);
39
41
  return vaultPublicKey;
40
42
  });
41
43
  }
42
44
  exports.liquidateVault = liquidateVault;
43
- function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUsdhTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, collateralType, overrideTime) {
45
+ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, collateralType, overrideTime) {
44
46
  return __awaiter(this, void 0, void 0, function* () {
45
47
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
46
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
47
- const liquidationPoolUsdhAccountPublickey = yield (0, Constants_1.getLiquidationPoolUsdhAccountPublicKey)();
48
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
49
+ const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
48
50
  const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
49
51
  const payload = {
50
52
  accounts: {
@@ -57,21 +59,24 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
57
59
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
58
60
  poolState: poolState,
59
61
  poolAssociatedTokenAccount: poolAssociatedTokenAccount,
60
- usdhMint: usdhMintPublickey,
62
+ ushMint: ushMintPublickey,
61
63
  history: historyPublicKey,
62
64
  payer: payerPublicKey,
63
65
  payerAssociatedTokenAccount: payerAssociatedTokenAccount,
64
66
  feePool: feePool,
65
67
  feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
66
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
67
- liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
68
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
69
+ liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
68
70
  newEra: newEraPublicKey,
71
+ oldSmallerVaultInfo: oldSmallerPublicKey,
72
+ newSmallerVaultInfo: newSmallerPublicKey,
73
+ newLargerVaultInfo: newLargerPublicKey,
69
74
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
70
75
  systemProgram: web3_js_1.SystemProgram.programId,
71
76
  associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
72
- rent: web3_js_1.SYSVAR_RENT_PUBKEY
77
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
73
78
  },
74
- signers: []
79
+ signers: [],
75
80
  };
76
81
  return program.instruction.liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
77
82
  payload);
@@ -13,30 +13,32 @@ exports.loanVaultInstruction = exports.loanVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
20
- const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
20
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
21
+ const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
21
22
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
22
23
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
23
24
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
24
25
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
25
26
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
27
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
26
28
  const history = web3_js_1.Keypair.generate();
27
- const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, loanAmount, overrideTime));
29
+ const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
28
30
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
29
31
  return vaultPublicKey;
30
32
  });
31
33
  }
32
34
  exports.loanVault = loanVault;
33
- function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, loanAmount, overrideTime) {
35
+ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime) {
34
36
  return __awaiter(this, void 0, void 0, function* () {
35
37
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
36
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
38
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
37
39
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
38
40
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
39
- const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
41
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
40
42
  return program.instruction.loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
41
43
  {
42
44
  accounts: {
@@ -47,14 +49,17 @@ function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPu
47
49
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
48
50
  history: historyPublicKey,
49
51
  feePool: hedgeStakingPoolPublicKey,
50
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
51
- usdhMint: usdhMintPublickey,
52
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
53
+ ushMint: ushMintPublickey,
52
54
  vaultOwner: payerPublicKey,
53
- ownerUsdhAccount: ownerUsdhAccount,
55
+ ownerUshAccount: ownerUshAccount,
56
+ oldSmallerVaultInfo: oldSmallerPublicKey,
57
+ newSmallerVaultInfo: newSmallerPublicKey,
58
+ newLargerVaultInfo: newLargerPublicKey,
54
59
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
55
- systemProgram: web3_js_1.SystemProgram.programId
60
+ systemProgram: web3_js_1.SystemProgram.programId,
56
61
  },
57
- signers: []
62
+ signers: [],
58
63
  });
59
64
  });
60
65
  }
@@ -14,32 +14,34 @@ const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  // import { TokenInstructions } from '@project-serum/serum'
16
16
  const web3_js_1 = require("@solana/web3.js");
17
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
17
18
  const Constants_1 = require("../Constants");
18
19
  function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
21
- // Prep the user to get USDH back out at some point
22
- const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
21
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
22
+ // Prep the user to get USH back out at some point
23
+ const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
23
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
24
25
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
25
26
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
26
27
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
27
28
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
28
29
  const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
30
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
29
31
  const history = web3_js_1.Keypair.generate();
30
- const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, redeemAmount, transactionOverrideTime));
32
+ const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
31
33
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
32
34
  return vaultPublicKey;
33
35
  });
34
36
  }
35
37
  exports.redeemVault = redeemVault;
36
- function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
38
+ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime) {
37
39
  return __awaiter(this, void 0, void 0, function* () {
38
40
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
39
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
41
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
40
42
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
41
43
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
42
- const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
44
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
43
45
  return program.instruction.redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
44
46
  {
45
47
  accounts: {
@@ -50,11 +52,14 @@ function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, desti
50
52
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
51
53
  history: historyPublicKey,
52
54
  feePool: hedgeStakingPoolPublicKey,
53
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
54
- usdhMint: usdhMintPublickey,
55
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
56
+ ushMint: ushMintPublickey,
55
57
  payer: payerPublicKey,
56
- payerUsdhAccount: payerUsdhAccount,
58
+ payerUshAccount: payerUshAccount,
57
59
  destinationTokenAccount: destinationTokenAccount,
60
+ oldSmallerVaultInfo: oldSmallerPublicKey,
61
+ newSmallerVaultInfo: newSmallerPublicKey,
62
+ newLargerVaultInfo: newLargerPublicKey,
58
63
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
59
64
  systemProgram: web3_js_1.SystemProgram.programId
60
65
  },
@@ -13,31 +13,33 @@ exports.repayVaultInstruction = exports.repayVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
20
- // Prep the user to get USDH back out at some point
21
- const payerUsdhAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, usdhMintPublickey, payer.publicKey);
20
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
21
+ // Prep the user to get USH back out at some point
22
+ const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
22
23
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
23
24
  const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
24
25
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
25
26
  const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
26
27
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
28
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
27
29
  const history = web3_js_1.Keypair.generate();
28
- const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime));
30
+ const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
29
31
  yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
30
32
  return vaultPublicKey;
31
33
  });
32
34
  }
33
35
  exports.repayVault = repayVault;
34
- function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime) {
36
+ function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
38
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
37
- const usdhMintPublickey = yield (0, Constants_1.getUsdhMintPublicKey)();
39
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
38
40
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
39
41
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
40
- const hedgeStakingPoolAssociatedUsdhTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, usdhMintPublickey);
42
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
41
43
  return program.instruction.repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
42
44
  {
43
45
  accounts: {
@@ -48,14 +50,17 @@ function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultP
48
50
  vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
49
51
  history: historyPublicKey,
50
52
  feePool: hedgeStakingPoolPublicKey,
51
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
52
- usdhMint: usdhMintPublickey,
53
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
54
+ ushMint: ushMintPublickey,
53
55
  vaultOwner: payerPublicKey,
54
- ownerUsdhAccount: ownerUsdhAccount,
56
+ oldSmallerVaultInfo: oldSmallerPublicKey,
57
+ newSmallerVaultInfo: newSmallerPublicKey,
58
+ newLargerVaultInfo: newLargerPublicKey,
59
+ ownerUshAccount: ownerUshAccount,
55
60
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
56
- systemProgram: web3_js_1.SystemProgram.programId
61
+ systemProgram: web3_js_1.SystemProgram.programId,
57
62
  },
58
- signers: []
63
+ signers: [],
59
64
  });
60
65
  });
61
66
  }