hedge-web3 0.1.10 → 0.1.14

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.
Files changed (58) hide show
  1. package/lib/index.js +409 -154
  2. package/lib/index.js.map +1 -1
  3. package/lib/types/src/Constants.d.ts +8 -7
  4. package/lib/types/src/Constants.d.ts.map +1 -1
  5. package/lib/types/src/index.d.ts +3 -0
  6. package/lib/types/src/index.d.ts.map +1 -1
  7. package/lib/types/src/instructions/claimLiquidationPoolPosition.d.ts +5 -0
  8. package/lib/types/src/instructions/claimLiquidationPoolPosition.d.ts.map +1 -0
  9. package/lib/types/src/instructions/closeLiquidationPoolPosition.d.ts +5 -0
  10. package/lib/types/src/instructions/closeLiquidationPoolPosition.d.ts.map +1 -0
  11. package/lib/types/src/instructions/createVault.d.ts +2 -2
  12. package/lib/types/src/instructions/createVault.d.ts.map +1 -1
  13. package/lib/types/src/instructions/depositLiquidationPool.d.ts +5 -0
  14. package/lib/types/src/instructions/depositLiquidationPool.d.ts.map +1 -0
  15. package/lib/types/src/instructions/depositVault.d.ts +1 -1
  16. package/lib/types/src/instructions/depositVault.d.ts.map +1 -1
  17. package/lib/types/src/instructions/liquidateVault.d.ts +2 -2
  18. package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -1
  19. package/lib/types/src/instructions/loanVault.d.ts +1 -1
  20. package/lib/types/src/instructions/loanVault.d.ts.map +1 -1
  21. package/lib/types/src/instructions/redeemVault.d.ts +2 -2
  22. package/lib/types/src/instructions/redeemVault.d.ts.map +1 -1
  23. package/lib/types/src/instructions/refreshOraclePrice.d.ts +8 -2
  24. package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +1 -1
  25. package/lib/types/src/instructions/repayVault.d.ts +1 -1
  26. package/lib/types/src/instructions/repayVault.d.ts.map +1 -1
  27. package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -1
  28. package/lib/types/src/instructions/withdrawVault.d.ts +1 -1
  29. package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -1
  30. package/lib/types/src/state/LiquidationPoolEra.d.ts +1 -1
  31. package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -1
  32. package/lib/types/src/state/LiquidationPosition.d.ts +8 -9
  33. package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -1
  34. package/lib/types/src/state/VaultAccount.d.ts +0 -2
  35. package/lib/types/src/state/VaultAccount.d.ts.map +1 -1
  36. package/lib/types/tsconfig.base.tsbuildinfo +1 -1
  37. package/package.json +6 -2
  38. package/rollup.config.js +3 -1
  39. package/src/Constants.ts +23 -19
  40. package/src/idl/idl.ts +13 -13
  41. package/src/index.ts +3 -0
  42. package/src/instructions/claimLiquidationPoolPosition.ts +68 -0
  43. package/src/instructions/closeLiquidationPoolPosition.ts +88 -0
  44. package/src/instructions/createStakingPool.ts +4 -4
  45. package/src/instructions/createVault.ts +79 -15
  46. package/src/instructions/depositLiquidationPool.ts +70 -0
  47. package/src/instructions/depositStakingPool.ts +2 -2
  48. package/src/instructions/depositVault.ts +71 -12
  49. package/src/instructions/liquidateVault.ts +90 -35
  50. package/src/instructions/loanVault.ts +20 -8
  51. package/src/instructions/redeemVault.ts +42 -16
  52. package/src/instructions/refreshOraclePrice.ts +35 -6
  53. package/src/instructions/repayVault.ts +21 -6
  54. package/src/instructions/withdrawStakingPool.ts +7 -5
  55. package/src/instructions/withdrawVault.ts +29 -6
  56. package/src/state/LiquidationPoolEra.ts +2 -8
  57. package/src/state/LiquidationPosition.ts +38 -39
  58. package/src/state/VaultAccount.ts +0 -4
package/lib/index.js CHANGED
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var anchor = require('@project-serum/anchor');
6
6
  var splToken = require('@solana/spl-token');
7
7
  var web3_js = require('@solana/web3.js');
8
+ var serum = require('@project-serum/serum');
9
+ var uuid = require('uuid');
8
10
  var Decimal = require('decimal.js');
9
11
 
10
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -79,12 +81,12 @@ const vaultIdl = {
79
81
  isSigner: false
80
82
  },
81
83
  {
82
- name: 'splTokenProgramInfo',
84
+ name: 'tokenProgram',
83
85
  isMut: false,
84
86
  isSigner: false
85
87
  },
86
88
  {
87
- name: 'splAssociatedTokenProgramInfo',
89
+ name: 'associatedTokenProgram',
88
90
  isMut: false,
89
91
  isSigner: false
90
92
  },
@@ -149,12 +151,12 @@ const vaultIdl = {
149
151
  isSigner: false
150
152
  },
151
153
  {
152
- name: 'splTokenProgramInfo',
154
+ name: 'tokenProgram',
153
155
  isMut: false,
154
156
  isSigner: false
155
157
  },
156
158
  {
157
- name: 'splAssociatedTokenProgramInfo',
159
+ name: 'associatedTokenProgram',
158
160
  isMut: false,
159
161
  isSigner: false
160
162
  },
@@ -212,7 +214,7 @@ const vaultIdl = {
212
214
  isSigner: false
213
215
  },
214
216
  {
215
- name: 'splTokenProgramInfo',
217
+ name: 'tokenProgram',
216
218
  isMut: false,
217
219
  isSigner: false
218
220
  },
@@ -297,7 +299,7 @@ const vaultIdl = {
297
299
  isSigner: false
298
300
  },
299
301
  {
300
- name: 'splTokenProgramInfo',
302
+ name: 'tokenProgram',
301
303
  isMut: false,
302
304
  isSigner: false
303
305
  },
@@ -484,7 +486,7 @@ const vaultIdl = {
484
486
  isSigner: false
485
487
  },
486
488
  {
487
- name: 'splTokenProgramInfo',
489
+ name: 'tokenProgram',
488
490
  isMut: false,
489
491
  isSigner: false
490
492
  },
@@ -539,7 +541,7 @@ const vaultIdl = {
539
541
  isSigner: false
540
542
  },
541
543
  {
542
- name: 'splTokenProgramInfo',
544
+ name: 'tokenProgram',
543
545
  isMut: false,
544
546
  isSigner: false
545
547
  },
@@ -605,7 +607,7 @@ const vaultIdl = {
605
607
  isSigner: false
606
608
  },
607
609
  {
608
- name: 'splTokenProgramInfo',
610
+ name: 'tokenProgram',
609
611
  isMut: false,
610
612
  isSigner: false
611
613
  },
@@ -664,7 +666,7 @@ const vaultIdl = {
664
666
  isSigner: false
665
667
  },
666
668
  {
667
- name: 'splTokenProgramInfo',
669
+ name: 'tokenProgram',
668
670
  isMut: false,
669
671
  isSigner: false
670
672
  },
@@ -744,7 +746,7 @@ const vaultIdl = {
744
746
  isSigner: true
745
747
  },
746
748
  {
747
- name: 'splTokenProgramInfo',
749
+ name: 'tokenProgram',
748
750
  isMut: false,
749
751
  isSigner: false
750
752
  },
@@ -810,12 +812,12 @@ const vaultIdl = {
810
812
  isSigner: false
811
813
  },
812
814
  {
813
- name: 'splTokenProgramInfo',
815
+ name: 'tokenProgram',
814
816
  isMut: false,
815
817
  isSigner: false
816
818
  },
817
819
  {
818
- name: 'splAssociatedTokenProgramInfo',
820
+ name: 'associatedTokenProgram',
819
821
  isMut: false,
820
822
  isSigner: false
821
823
  },
@@ -1493,39 +1495,43 @@ function parseAnchorErrors(error) {
1493
1495
  throw error;
1494
1496
  }
1495
1497
 
1496
- const HEDGE_PROGRAM_ID = 'hhhJmQPMmb2sNoTQK1ip7ZRGpRdGfskEEgjacf9XFWv';
1498
+ const HEDGE_PROGRAM_ID = 'kkkBajjjT3rKjB3uGzSN83aLoQmaRwfXxbbBj8VLbtH';
1497
1499
  const HEDGE_PROGRAM_PUBLICKEY = new web3_js.PublicKey(HEDGE_PROGRAM_ID);
1498
1500
  const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
1499
1501
  const CHAINLINK_SOL_USD_PUBLICKEY = new web3_js.PublicKey(CHAINLINK_SOL_USD_ID);
1500
1502
  const enc = new TextEncoder();
1501
1503
  async function getLiquidationPoolStatePublicKey() {
1502
- const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1503
- return [poolPublicKey, bump];
1504
+ const [poolPublicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1505
+ return poolPublicKey;
1504
1506
  }
1505
1507
  async function getLiquidationPoolUsdhAccountPublicKey() {
1506
- const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY);
1507
- return [poolPublicKey, bump];
1508
+ const [poolPublicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY);
1509
+ return poolPublicKey;
1508
1510
  }
1509
1511
  async function getUsdhMintPublicKey() {
1510
- const [findMintPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1511
- return [findMintPublicKey, bump];
1512
+ const [findMintPublicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1513
+ return findMintPublicKey;
1512
1514
  }
1513
1515
  async function getVaultSystemStatePublicKey() {
1514
- const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1515
- return [publicKey, bump];
1516
+ const [publicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1517
+ return publicKey;
1516
1518
  }
1517
1519
  async function getHedgeMintPublicKey() {
1518
- const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1519
- return [publicKey, bump];
1520
+ const [publicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1521
+ return publicKey;
1520
1522
  }
1521
1523
  async function getPoolPublicKeyForMint(mintPublicKey) {
1522
1524
  const strToEncode = (mintPublicKey.toString().substring(0, 12));
1523
1525
  const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY);
1524
1526
  return [publicKey, bump, strToEncode];
1525
1527
  }
1526
- async function getSolCollateralPriceAccountPublicKey() {
1527
- const [collateralPriceAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Price')], HEDGE_PROGRAM_PUBLICKEY);
1528
- return collateralPriceAccount;
1528
+ async function getCollateralStateAccountPublicKey(collateralType) {
1529
+ const [collateralStateAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY);
1530
+ return collateralStateAccount;
1531
+ }
1532
+ async function findVaultAddress(vaultSalt) {
1533
+ const [vaultAddress] = await web3_js.PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY);
1534
+ return vaultAddress;
1529
1535
  }
1530
1536
  async function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
1531
1537
  return (await web3_js.PublicKey.findProgramAddress([
@@ -1542,8 +1548,8 @@ async function createStakingPool(program, provider, payer, mintPublicKey, hedgeT
1542
1548
  return poolPublickey;
1543
1549
  }
1544
1550
  async function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
1545
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1546
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1551
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1552
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1547
1553
  const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey);
1548
1554
  const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey);
1549
1555
  const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
@@ -1557,8 +1563,8 @@ async function createStakingPoolInstruction(program, payerPublicKey, mintPublicK
1557
1563
  poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
1558
1564
  poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
1559
1565
  rent: web3_js.SYSVAR_RENT_PUBKEY,
1560
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1561
- splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1566
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1567
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1562
1568
  systemProgram: web3_js.SystemProgram.programId
1563
1569
  },
1564
1570
  signers: []
@@ -1585,8 +1591,8 @@ async function depositStakingPoolInstruction(program, payerPublicKey, poolPositi
1585
1591
  poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
1586
1592
  payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
1587
1593
  rent: web3_js.SYSVAR_RENT_PUBKEY,
1588
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1589
- splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1594
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1595
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1590
1596
  systemProgram: web3_js.SystemProgram.programId
1591
1597
  },
1592
1598
  signers: []
@@ -1600,15 +1606,16 @@ async function withdrawStakingPool(program, provider, payer, poolPositionPublicK
1600
1606
  return poolPosition.publicKey;
1601
1607
  }
1602
1608
  async function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
1603
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1604
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1605
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1609
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1610
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1611
+ const hedgeMintPublickey = await getHedgeMintPublicKey();
1606
1612
  const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
1607
1613
  const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
1608
1614
  const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
1609
1615
  const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
1610
1616
  const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey);
1611
1617
  const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey);
1618
+ const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey);
1612
1619
  return program.instruction.withdrawStakingPool(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
1613
1620
  {
1614
1621
  accounts: {
@@ -1621,88 +1628,274 @@ async function withdrawStakingPoolInstruction(program, payerPublicKey, poolPosit
1621
1628
  payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
1622
1629
  payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
1623
1630
  payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
1631
+ communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
1624
1632
  hedgeMint: hedgeMintPublickey,
1625
1633
  stakedTokenMint: stakedTokenMintPublicKey,
1626
1634
  usdhMint: usdhMintPublickey,
1627
1635
  rent: web3_js.SYSVAR_RENT_PUBKEY,
1628
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1629
- splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1636
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1637
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1630
1638
  systemProgram: web3_js.SystemProgram.programId
1631
1639
  },
1632
1640
  signers: []
1633
1641
  });
1634
1642
  }
1635
1643
 
1636
- async function createVault(program, provider, payer, depositAmount, collateralRatio) {
1637
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1644
+ async function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime) {
1645
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1638
1646
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1647
+ const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1648
+ const poolPosition = web3_js.Keypair.generate();
1649
+ const transaction = new web3_js.Transaction().add(await depositLiquidationPoolInstruction(program, payer.publicKey, payerUsdhAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
1650
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors);
1651
+ return poolPosition.publicKey;
1652
+ }
1653
+ async function depositLiquidationPoolInstruction(program, payerPublicKey, payerUsdhAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
1654
+ const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey();
1655
+ const liquidationPoolState = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
1656
+ const poolUSDHAccount = await getLiquidationPoolUsdhAccountPublicKey();
1657
+ const usdhMint = await getUsdhMintPublicKey();
1658
+ return program.instruction.depositLiquidationPool(new anchor.BN(depositAmount), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
1659
+ {
1660
+ accounts: {
1661
+ poolState: liquidationPoolStatePublicKey,
1662
+ poolEra: liquidationPoolState.currentEra,
1663
+ poolPosition: poolPositionPublicKey,
1664
+ poolUsdhAccount: poolUSDHAccount,
1665
+ usdhMint: usdhMint,
1666
+ payer: payerPublicKey,
1667
+ ownerUsdhAccount: payerUsdhAccount,
1668
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1669
+ systemProgram: web3_js.SystemProgram.programId,
1670
+ rent: web3_js.SYSVAR_RENT_PUBKEY
1671
+ },
1672
+ signers: []
1673
+ });
1674
+ }
1675
+
1676
+ async function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime) {
1677
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1678
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1679
+ const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1680
+ const poolState = await getLiquidationPoolStatePublicKey();
1681
+ const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition);
1682
+ const poolEra = liquidationPositionAccount.era;
1683
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1684
+ const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey();
1685
+ const hedgeMint = await getHedgeMintPublicKey();
1686
+ const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payer.publicKey, hedgeMint);
1687
+ const communityAssociatedHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMint);
1688
+ const transaction = new web3_js.Transaction().add(await closeLiquidationPoolPositionInstruction(program, vaultSystemStatePublicKey, poolState, poolEra, poolPosition, poolUsdhAccount, payer.publicKey, payerUsdhAccount.address, hedgeMint, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime));
1689
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
1690
+ return poolPosition;
1691
+ }
1692
+ async function closeLiquidationPoolPositionInstruction(program, vaultSystemState, poolState, poolEra, poolPosition, poolUsdhAccount, payerPublicKey, payerUsdhAccount, hedgeMint, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
1693
+ return program.instruction.closeLiquidationPoolPosition(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
1694
+ {
1695
+ accounts: {
1696
+ vaultSystemState: vaultSystemState,
1697
+ poolState: poolState,
1698
+ poolEra: poolEra,
1699
+ poolPosition: poolPosition,
1700
+ poolUsdhAccount: poolUsdhAccount,
1701
+ payer: payerPublicKey,
1702
+ ownerUsdhAccount: payerUsdhAccount,
1703
+ hedgeMint: hedgeMint,
1704
+ payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
1705
+ communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
1706
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1707
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1708
+ systemProgram: web3_js.SystemProgram.programId,
1709
+ rent: web3_js.SYSVAR_RENT_PUBKEY
1710
+ },
1711
+ signers: []
1712
+ });
1713
+ }
1714
+
1715
+ async function claimLiquidationPoolPosition(program, provider, poolPosition, payer, collateralType, overrideStartTime) {
1716
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(collateralType);
1717
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1718
+ const collateralMint = collateralStateAccountInfo.collateralMint;
1719
+ const poolStatePublicKey = await getLiquidationPoolStatePublicKey();
1720
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMint);
1721
+ const payerAssociatedTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralMint);
1722
+ const transaction = new web3_js.Transaction().add(await claimLiquidationPoolPositionInstruction(program, poolStatePublicKey, poolAssociatedTokenAccount, collateralStateAccountPublicKey, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount));
1723
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
1724
+ return payerAssociatedTokenAccount;
1725
+ }
1726
+ async function claimLiquidationPoolPositionInstruction(program, poolState, poolAssociatedTokenAccount, collateralStateAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
1727
+ return program.instruction.claimLiquidationPoolPosition({
1728
+ accounts: {
1729
+ poolState: poolState,
1730
+ poolAssociatedTokenAccount: poolAssociatedTokenAccount,
1731
+ collateralStateAccount: collateralStateAccount,
1732
+ collateralMint: collateralMint,
1733
+ poolPosition: poolPosition,
1734
+ payer: payer,
1735
+ payerAssociatedTokenAccount: payerAssociatedTokenAccount,
1736
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1737
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1738
+ systemProgram: web3_js.SystemProgram.programId,
1739
+ rent: web3_js.SYSVAR_RENT_PUBKEY
1740
+ },
1741
+ signers: []
1742
+ });
1743
+ }
1744
+
1745
+ async function createVault(program, provider, payer, collateralType, depositAmount, collateralRatio) {
1746
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1747
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1748
+ const salt = uuid.v4().substring(0, 8);
1749
+ const newVaultPublicKey = await findVaultAddress(salt);
1750
+ const history = web3_js.Keypair.generate();
1639
1751
  // Prep the user to get USDH back out at some point
1640
1752
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1641
- const newVault = web3_js.Keypair.generate();
1642
- const history = web3_js.Keypair.generate();
1643
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1644
- const transaction = new web3_js.Transaction().add(createVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, newVault.publicKey, history.publicKey, depositAmount, collateralRatio));
1645
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, newVault, history], provider === null || provider === void 0 ? void 0 : provider.opts);
1646
- return newVault.publicKey;
1753
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(collateralType);
1754
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1755
+ const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralStateAccountInfo.collateralMint);
1756
+ const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(newVaultPublicKey, collateralStateAccountInfo.collateralMint);
1757
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1758
+ const wrappedSolAccount = web3_js.Keypair.generate();
1759
+ const transaction = new web3_js.Transaction();
1760
+ const signers = [payer, history];
1761
+ if (collateralType === 'SOL') {
1762
+ transaction.add(web3_js.SystemProgram.createAccount({
1763
+ fromPubkey: payer.publicKey,
1764
+ lamports: depositAmount + 2.04e6,
1765
+ newAccountPubkey: wrappedSolAccount.publicKey,
1766
+ programId: splToken.TOKEN_PROGRAM_ID,
1767
+ space: 165
1768
+ }), serum.TokenInstructions.initializeAccount({
1769
+ account: wrappedSolAccount.publicKey,
1770
+ mint: serum.TokenInstructions.WRAPPED_SOL_MINT,
1771
+ owner: payer.publicKey
1772
+ }));
1773
+ signers.push(wrappedSolAccount);
1774
+ }
1775
+ transaction.add(await createVaultInstruction(program, salt, vaultSystemStatePublicKey, payer.publicKey, collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedCollateralAccountPublicKey, collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint, history.publicKey, depositAmount, collateralRatio));
1776
+ if (collateralType === 'SOL') {
1777
+ transaction.add(serum.TokenInstructions.closeAccount({
1778
+ source: wrappedSolAccount.publicKey,
1779
+ destination: payer.publicKey,
1780
+ owner: payer.publicKey
1781
+ }));
1782
+ }
1783
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, signers, provider === null || provider === void 0 ? void 0 : provider.opts).catch(parseAnchorErrors);
1784
+ return newVaultPublicKey;
1647
1785
  }
1648
- function createVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount, collateralRatio) {
1649
- const ix = program.instruction.createVault(new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
1786
+ async function createVaultInstruction(program, salt, vaultSystemStatePublicKey, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedCollateralPublicKey, collateralStateAccount, collateralMint, historyPublicKey, depositAmount, collateralRatio) {
1787
+ const ix = program.instruction.createVault(salt, new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
1650
1788
  accounts: {
1651
1789
  vaultSystemState: vaultSystemStatePublicKey,
1790
+ collateralStateAccount: collateralStateAccount,
1652
1791
  vault: vaultPublicKey,
1792
+ vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
1653
1793
  history: historyPublicKey,
1654
1794
  payer: payerPublicKey,
1655
- systemProgram: web3_js.SystemProgram.programId
1795
+ payerTokenAccount: payerTokenAccountPublicKey,
1796
+ collateralMint: collateralMint,
1797
+ systemProgram: web3_js.SystemProgram.programId,
1798
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1799
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1800
+ rent: web3_js.SYSVAR_RENT_PUBKEY
1656
1801
  },
1657
1802
  signers: []
1658
1803
  });
1659
1804
  return ix;
1660
1805
  }
1661
1806
 
1662
- async function depositVault(program, provider, payer, vaultPublicKey, depositAmount) {
1663
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1807
+ async function depositVault(program, provider, payer, vaultPublicKey,
1808
+ // collateralType: string,
1809
+ depositAmount) {
1810
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1664
1811
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1665
1812
  // Prep the user to get USDH back out at some point
1666
1813
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1814
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
1815
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
1816
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1817
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint);
1818
+ const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralStateAccountInfo.collateralMint);
1819
+ const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccountInfo.collateralMint);
1667
1820
  const history = web3_js.Keypair.generate();
1668
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1669
- const transaction = new web3_js.Transaction().add(depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, depositAmount));
1670
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1821
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1822
+ const wrappedSolAccount = web3_js.Keypair.generate();
1823
+ const transaction = new web3_js.Transaction();
1824
+ const signers = [payer, history];
1825
+ if (vaultAccount.collateralType === 'SOL') {
1826
+ transaction.add(web3_js.SystemProgram.createAccount({
1827
+ fromPubkey: payer.publicKey,
1828
+ lamports: depositAmount + 2.04e6,
1829
+ newAccountPubkey: wrappedSolAccount.publicKey,
1830
+ programId: splToken.TOKEN_PROGRAM_ID,
1831
+ space: 165
1832
+ }), serum.TokenInstructions.initializeAccount({
1833
+ account: wrappedSolAccount.publicKey,
1834
+ mint: serum.TokenInstructions.WRAPPED_SOL_MINT,
1835
+ owner: payer.publicKey
1836
+ }));
1837
+ signers.push(wrappedSolAccount);
1838
+ }
1839
+ transaction.add(await depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, collateralStateAccountInfo.collateralMint, depositAmount));
1840
+ if (vaultAccount.collateralType === 'SOL') {
1841
+ transaction.add(serum.TokenInstructions.closeAccount({
1842
+ source: wrappedSolAccount.publicKey,
1843
+ destination: payer.publicKey,
1844
+ owner: payer.publicKey
1845
+ }));
1846
+ }
1847
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, signers, provider.opts);
1671
1848
  return vaultPublicKey;
1672
1849
  }
1673
- function depositVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount) {
1850
+ async function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, collateralMint, depositAmount) {
1674
1851
  return program.instruction.depositVault(new anchor.BN(depositAmount), {
1675
1852
  accounts: {
1676
1853
  vaultSystemState: vaultSystemStatePublicKey,
1677
- vaultAccount: vaultPublicKey,
1854
+ collateralStateAccount: collateralStateAccountPublicKey,
1855
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
1856
+ collateralTokenMint: collateralMint,
1857
+ vault: vaultPublicKey,
1858
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
1678
1859
  history: historyPublicKey,
1679
- vaultOwner: payerPublicKey,
1680
- systemProgram: web3_js.SystemProgram.programId
1860
+ vaultOwner: vaultOwner,
1861
+ vaultOwnerTokenAccount: vaultOwnerTokenAccount,
1862
+ systemProgram: web3_js.SystemProgram.programId,
1863
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
1681
1864
  },
1682
1865
  signers: []
1683
1866
  });
1684
1867
  }
1685
1868
 
1686
1869
  async function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount) {
1687
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1870
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1688
1871
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1689
1872
  // Prep the user to get USDH back out at some point
1690
1873
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1691
1874
  const history = web3_js.Keypair.generate();
1692
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1693
- const transaction = new web3_js.Transaction().add(await withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, withdrawAmount));
1875
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1876
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
1877
+ const collateralStateAccount = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
1878
+ const vaultAssociatedCollateralAccount = await findAssociatedTokenAddress(vaultPublicKey, serum.TokenInstructions.WRAPPED_SOL_MINT);
1879
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccount);
1880
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccount, collateralStateAccountInfo.collateralMint);
1881
+ const token = new splToken.Token(provider.connection, collateralStateAccountInfo.collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
1882
+ const destinationTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
1883
+ const transaction = new web3_js.Transaction().add(await withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount, collateralStateAccount, collateralAssociatedTokenAccount, history.publicKey, withdrawAmount));
1694
1884
  await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1695
1885
  return vaultPublicKey;
1696
1886
  }
1697
- async function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublickey, historyPublicKey, withdrawAmount) {
1698
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1887
+ async function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, historyPublicKey, withdrawAmount) {
1699
1888
  return program.instruction.withdrawVault(new anchor.BN(withdrawAmount), {
1700
1889
  accounts: {
1701
1890
  vaultSystemState: vaultSystemStatePublicKey,
1702
- vaultAccount: vaultPublickey,
1891
+ collateralStateAccount: collateralStateAccount,
1892
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
1893
+ vault: vaultPublickey,
1894
+ vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
1703
1895
  history: historyPublicKey,
1704
1896
  vaultOwner: payerPublicKey,
1705
- priceForCollateral: solPriceAccount,
1897
+ destinationTokenAccount: destinationTokenAccount,
1898
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1706
1899
  systemProgram: web3_js.SystemProgram.programId
1707
1900
  },
1708
1901
  signers: []
@@ -1710,34 +1903,40 @@ async function withdrawVaultInstruction(program, vaultSystemStatePublicKey, paye
1710
1903
  }
1711
1904
 
1712
1905
  async function loanVault(program, provider, payer, vaultPublicKey, loanAmount) {
1713
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1906
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1714
1907
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1715
1908
  // Prep the user to get USDH back out at some point
1716
1909
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1910
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
1911
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
1912
+ const collateralStateAccount = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1913
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccount.collateralMint);
1914
+ const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccount.collateralMint);
1717
1915
  const history = web3_js.Keypair.generate();
1718
- const transaction = new web3_js.Transaction().add(await loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, loanAmount));
1916
+ const transaction = new web3_js.Transaction().add(await loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, loanAmount));
1719
1917
  await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1720
1918
  return vaultPublicKey;
1721
1919
  }
1722
- async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, loanAmount) {
1723
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1724
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1725
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1920
+ async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, loanAmount) {
1921
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1922
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1923
+ const hedgeMintPublickey = await getHedgeMintPublicKey();
1726
1924
  const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1727
1925
  const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1728
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1729
1926
  return program.instruction.loanVault(new anchor.BN(loanAmount), {
1730
1927
  accounts: {
1731
1928
  vaultSystemState: vaultSystemStatePublicKey,
1929
+ collateralStateAccount: collateralStateAccount,
1930
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
1732
1931
  vaultAccount: vaultPublickey,
1932
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
1733
1933
  history: historyPublicKey,
1734
1934
  feePool: hedgeStakingPoolPublicKey,
1735
1935
  feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1736
1936
  usdhMint: usdhMintPublickey,
1737
1937
  vaultOwner: payerPublicKey,
1738
1938
  ownerUsdhAccount: ownerUsdhAccount,
1739
- priceForCollateral: solPriceAccount,
1740
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1939
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1741
1940
  systemProgram: web3_js.SystemProgram.programId
1742
1941
  },
1743
1942
  signers: []
@@ -1745,132 +1944,194 @@ async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, v
1745
1944
  }
1746
1945
 
1747
1946
  async function repayVault(program, provider, payer, vaultPublicKey, repayAmount) {
1748
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1947
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1749
1948
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1750
1949
  // Prep the user to get USDH back out at some point
1751
1950
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1951
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
1952
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
1953
+ const collateralStateAccount = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1954
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccount.collateralMint);
1955
+ const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccount.collateralMint);
1752
1956
  const history = web3_js.Keypair.generate();
1753
- const transaction = new web3_js.Transaction().add(await repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount));
1957
+ const transaction = new web3_js.Transaction().add(await repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, repayAmount));
1754
1958
  await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1755
1959
  return vaultPublicKey;
1756
1960
  }
1757
- async function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount) {
1758
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1759
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1760
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1961
+ async function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, repayAmount) {
1962
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
1963
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1964
+ const hedgeMintPublickey = await getHedgeMintPublicKey();
1761
1965
  const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1762
1966
  const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1763
1967
  return program.instruction.repayVault(new anchor.BN(repayAmount), {
1764
1968
  accounts: {
1765
1969
  vaultSystemState: vaultSystemStatePublicKey,
1970
+ collateralStateAccount: collateralStateAccount,
1971
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
1766
1972
  vaultAccount: vaultPublickey,
1973
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
1767
1974
  history: historyPublicKey,
1768
1975
  feePool: hedgeStakingPoolPublicKey,
1769
1976
  feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1770
1977
  usdhMint: usdhMintPublickey,
1771
1978
  vaultOwner: payerPublicKey,
1772
1979
  ownerUsdhAccount: ownerUsdhAccount,
1773
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1980
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1774
1981
  systemProgram: web3_js.SystemProgram.programId
1775
1982
  },
1776
1983
  signers: []
1777
1984
  });
1778
1985
  }
1779
1986
 
1780
- async function redeemVault(program, provider, payer, vaultPublicKey, repayAmount, transactionOverrideTime) {
1781
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1987
+ async function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
1988
+ const usdhMintPublickey = await getUsdhMintPublicKey();
1782
1989
  const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1783
1990
  // Prep the user to get USDH back out at some point
1784
1991
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1992
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
1993
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
1994
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
1995
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint);
1996
+ const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccountInfo.collateralMint);
1997
+ const token = new splToken.Token(provider.connection, collateralStateAccountInfo.collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
1998
+ const payerTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
1785
1999
  const history = web3_js.Keypair.generate();
1786
- const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount, transactionOverrideTime));
2000
+ const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, redeemAmount, transactionOverrideTime));
1787
2001
  await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1788
2002
  return vaultPublicKey;
1789
2003
  }
1790
- async function redeemVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount, transactionOverrideTime) {
1791
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1792
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1793
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
2004
+ async function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
2005
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
2006
+ const usdhMintPublickey = await getUsdhMintPublicKey();
2007
+ const hedgeMintPublickey = await getHedgeMintPublicKey();
1794
2008
  const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1795
2009
  const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1796
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1797
- return program.instruction.redeemVault(new anchor.BN(repayAmount), new anchor.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
2010
+ return program.instruction.redeemVault(new anchor.BN(redeemAmount), new anchor.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
1798
2011
  {
1799
2012
  accounts: {
1800
2013
  vaultSystemState: vaultSystemStatePublicKey,
1801
- vaultAccount: vaultPublickey,
2014
+ collateralStateAccount: collateralStateAccount,
2015
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
2016
+ vault: vaultPublickey,
2017
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
1802
2018
  history: historyPublicKey,
1803
2019
  feePool: hedgeStakingPoolPublicKey,
1804
2020
  feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1805
2021
  usdhMint: usdhMintPublickey,
1806
2022
  payer: payerPublicKey,
1807
- payerUsdhAccount: ownerUsdhAccount,
1808
- priceForCollateral: solPriceAccount,
1809
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
2023
+ payerUsdhAccount: payerUsdhAccount,
2024
+ destinationTokenAccount: destinationTokenAccount,
2025
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
1810
2026
  systemProgram: web3_js.SystemProgram.programId
1811
2027
  },
1812
2028
  signers: []
1813
2029
  });
1814
2030
  }
1815
2031
 
1816
- async function liquidateVault(program, provider, payer, vaultPublicKey) {
2032
+ async function liquidateVault(program, provider, payer, vaultPublicKey, preload) {
2033
+ const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
2034
+ const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
2035
+ const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
2036
+ const collateralMint = collateralStateAccountInfo.collateralMint;
2037
+ const token = new splToken.Token(provider.connection, collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
2038
+ const hedgeMintPublickey = await getHedgeMintPublicKey();
2039
+ const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
2040
+ const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey();
2041
+ const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
2042
+ const payerAssociatedTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
2043
+ const feePoolAssociatedTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, collateralMint);
2044
+ const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralMint);
2045
+ const poolAssociatedTokenAccount = await findAssociatedTokenAddress(liquidationPoolStatePublicKey, collateralMint);
2046
+ const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralMint);
1817
2047
  const history = web3_js.Keypair.generate();
1818
2048
  const newEra = web3_js.Keypair.generate();
1819
- const transaction = new web3_js.Transaction().add(await liquidateVaultInstruction(program, payer.publicKey, vaultPublicKey, history.publicKey, newEra.publicKey));
2049
+ const transaction = new web3_js.Transaction();
2050
+ transaction.add(await liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount, collateralMint, collateralAssociatedTokenAccount, vaultAccount.collateralType, preload));
1820
2051
  await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra], provider.opts);
1821
2052
  return vaultPublicKey;
1822
2053
  }
1823
- async function liquidateVaultInstruction(program, payerPublicKey, vaultPublickey, historyPublicKey, newEraPublicKey) {
1824
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1825
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1826
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1827
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1828
- const [liquidationPoolStatePublicKey] = await getLiquidationPoolStatePublicKey();
1829
- const [liquidationPoolUsdhAccountPublickey] = await getLiquidationPoolUsdhAccountPublicKey();
1830
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1831
- const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
1832
- return program.instruction.liquidateVault({
2054
+ async function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, collateralMint, collateralAssociatedTokenAccount, collateralType, preload) {
2055
+ const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
2056
+ const usdhMintPublickey = await getUsdhMintPublicKey();
2057
+ const liquidationPoolUsdhAccountPublickey = await getLiquidationPoolUsdhAccountPublicKey();
2058
+ const collateralStateAccount = await getCollateralStateAccountPublicKey(collateralType);
2059
+ const payload = {
1833
2060
  accounts: {
1834
2061
  vaultSystemState: vaultSystemStatePublicKey,
1835
- poolEra: poolStateInfo.currentEra,
2062
+ collateralStateAccount: collateralStateAccount,
2063
+ collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
2064
+ collateralMint: collateralMint,
2065
+ poolEra: poolEra,
1836
2066
  vaultAccount: vaultPublickey,
1837
- poolState: liquidationPoolStatePublicKey,
2067
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
2068
+ poolState: poolState,
2069
+ poolAssociatedTokenAccount: poolAssociatedTokenAccount,
1838
2070
  usdhMint: usdhMintPublickey,
1839
- priceForCollateral: solPriceAccount,
1840
2071
  history: historyPublicKey,
1841
2072
  payer: payerPublicKey,
1842
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1843
- systemProgram: web3_js.SystemProgram.programId,
1844
- feePool: hedgeStakingPoolPublicKey,
2073
+ payerAssociatedTokenAccount: payerAssociatedTokenAccount,
2074
+ feePool: feePool,
2075
+ feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
1845
2076
  liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
1846
- newEra: newEraPublicKey
2077
+ newEra: newEraPublicKey,
2078
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2079
+ systemProgram: web3_js.SystemProgram.programId,
2080
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2081
+ rent: web3_js.SYSVAR_RENT_PUBKEY
1847
2082
  },
1848
2083
  signers: []
1849
- });
2084
+ };
2085
+ if (preload) {
2086
+ return program.instruction.liquidateVaultPrepAccounts(payload);
2087
+ }
2088
+ return program.instruction.liquidateVault(payload);
1850
2089
  }
1851
2090
 
1852
- async function refreshOraclePrice(program, provider, payer, overridePrice, overrideTime) {
1853
- const transaction = new web3_js.Transaction().add(await refreshOraclePriceInstruction(program, overridePrice, overrideTime));
2091
+ async function refreshOraclePrice(program, provider, payer, collateralType, network, overridePrice, overrideTime) {
2092
+ const transaction = new web3_js.Transaction().add(await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime));
1854
2093
  return await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts);
1855
2094
  }
1856
- async function refreshOraclePriceInstruction(program, overridePrice, overrideTime) {
2095
+ async function refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime) {
1857
2096
  const enc = new TextEncoder();
1858
- const [oracleInfoAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY);
1859
- const [collateralPriceAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Price')], HEDGE_PROGRAM_PUBLICKEY);
2097
+ const [oracleInfoAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY);
2098
+ const [collateralStateAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY);
1860
2099
  return program.instruction.refreshOraclePrice(new anchor.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
1861
2100
  new anchor.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
1862
2101
  {
1863
2102
  accounts: {
1864
2103
  oracleInfoAccount: oracleInfoAccount,
1865
- collateralPriceAccount: collateralPriceAccount,
1866
- oracleChainlink: web3_js.SystemProgram.programId,
1867
- oraclePyth: web3_js.SystemProgram.programId,
1868
- oracleSwitchboard: web3_js.SystemProgram.programId,
2104
+ collateralStateAccount: collateralStateAccount,
2105
+ oracleChainlink: chainlinkAccunts[network],
2106
+ oraclePyth: pythAccounts[network],
2107
+ oracleSwitchboard: switchboardAccounts[network],
1869
2108
  systemProgram: web3_js.SystemProgram.programId
1870
2109
  },
1871
2110
  signers: []
1872
2111
  });
1873
2112
  }
2113
+ var Cluster;
2114
+ (function (Cluster) {
2115
+ Cluster["Testing"] = "Testing";
2116
+ Cluster["Devnet"] = "Devnet";
2117
+ Cluster["MainnetBeta"] = "MainnetBeta";
2118
+ })(Cluster || (Cluster = {}));
2119
+ const pythAccounts = {
2120
+ Testing: web3_js.SystemProgram.programId,
2121
+ Devnet: new web3_js.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
2122
+ MainnetBeta: new web3_js.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
2123
+ };
2124
+ const chainlinkAccunts = {
2125
+ Testing: web3_js.SystemProgram.programId,
2126
+ Devnet: new web3_js.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
2127
+ MainnetBeta: web3_js.SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
2128
+ };
2129
+ const switchboardAccounts = {
2130
+ Testing: web3_js.SystemProgram.programId,
2131
+ // Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
2132
+ Devnet: new web3_js.PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
2133
+ MainnetBeta: web3_js.SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
2134
+ };
1874
2135
 
1875
2136
  /**
1876
2137
  * Convert a U128 to a Decimal
@@ -1899,7 +2160,6 @@ class VaultAccount {
1899
2160
  this.debt = vault.debt.toNumber();
1900
2161
  this.deposited = vault.deposited.toNumber();
1901
2162
  this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio);
1902
- this.liquidationPrice = vault.liquidationPrice.toNumber();
1903
2163
  this.vaultStatus = Object.keys(vault.vaultStatus)[0];
1904
2164
  }
1905
2165
  /**
@@ -2025,7 +2285,7 @@ class LiquidationPoolEra {
2025
2285
  this.liquidyPoolEra = liquidyPoolEra;
2026
2286
  this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber();
2027
2287
  this.product = DecimalFromU128(liquidyPoolEra.productBytes);
2028
- this.sum = DecimalFromU128(liquidyPoolEra.sumBytes);
2288
+ this.sum = liquidyPoolEra.sumBytes.map((sumBytes) => { return DecimalFromU128(sumBytes); });
2029
2289
  this.hedgeRewardsAccumulator = DecimalFromU128(liquidyPoolEra.hedgeRewardsAccumulatorBytes);
2030
2290
  this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber();
2031
2291
  }
@@ -2041,47 +2301,35 @@ class LiquidationPoolState {
2041
2301
  }
2042
2302
 
2043
2303
  class LiquidationPosition {
2044
- constructor(poolPositionInfo, key, era, liquidationPoolState) {
2304
+ constructor(poolPositionInfo, key) {
2045
2305
  this.publicKey = key;
2046
2306
  this.eraPublicKey = poolPositionInfo.era;
2047
- this.era = era;
2048
- this.liquidationPoolState = liquidationPoolState;
2049
2307
  this.ownerAccount = poolPositionInfo.ownerAccount;
2050
2308
  this.deposit = poolPositionInfo.deposit.toNumber();
2051
2309
  this.closedUsdh = poolPositionInfo.closedUsdh.toNumber();
2052
- this.closedSol = poolPositionInfo.closedSol.toNumber();
2053
2310
  this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
2054
2311
  this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
2055
- this.productSnapshot = DecimalFromU128(poolPositionInfo.productSnapshotBytes);
2056
- this.sumSnapshot = DecimalFromU128(poolPositionInfo.sumSnapshotBytes);
2312
+ this.productSnapshotEntry = DecimalFromU128(poolPositionInfo.productSnapshotEntry);
2313
+ this.productSnapshotClosed = DecimalFromU128(poolPositionInfo.productSnapshotClosed);
2314
+ this.sumSnapshotsEntry = poolPositionInfo.sumSnapshotsEntry.map((sum) => { return DecimalFromU128(sum); });
2315
+ this.sumSnapshotsClosed = poolPositionInfo.sumSnapshotsClosed.map((sum) => { return DecimalFromU128(sum); });
2057
2316
  this.hedgeRewardsSnapshot = DecimalFromU128(poolPositionInfo.hedgeRewardsSnapshotAccum);
2058
2317
  this.open = poolPositionInfo.state.open !== undefined;
2059
2318
  }
2060
- getUsdhAvailable() {
2061
- return (this.era.product.div(this.productSnapshot)).mul(new Decimal__default["default"](this.deposit));
2062
- }
2063
- getSolAvailable() {
2064
- return this.era.sum.minus(this.sumSnapshot).div(this.productSnapshot).mul(new Decimal__default["default"](this.deposit)).floor();
2319
+ getUsdhAvailable(era) {
2320
+ return (era.product.div(this.productSnapshotEntry)).mul(new Decimal__default["default"](this.deposit));
2065
2321
  }
2066
- getHedgeAvailable() {
2067
- const LiquidationPoolTotalSupply = 2000000.0 * web3_js.LAMPORTS_PER_SOL;
2068
- const hedgeRewardsSinceLastUpdate = hedgeRewardsDecay(LiquidationPoolTotalSupply, this.liquidationPoolState.hedgeInitRewardsTimestamp * 1000, this.era.hedgeRewardsTimestamp * 1000, Date.now(), 365 * 1000);
2069
- if (this.era.totalDeposits === 0) {
2070
- return new Decimal__default["default"](0);
2071
- }
2072
- const rewardsPerToken = this.era.product.mul(new Decimal__default["default"](hedgeRewardsSinceLastUpdate / this.era.totalDeposits));
2073
- const newAccumulator = rewardsPerToken.add(new Decimal__default["default"](this.era.hedgeRewardsAccumulator));
2074
- const hedgeAvailable = (newAccumulator.minus(this.hedgeRewardsSnapshot)).mul(new Decimal__default["default"](this.deposit)).div(new Decimal__default["default"](this.productSnapshot));
2075
- return hedgeAvailable;
2322
+ getSolAvailable(era) {
2323
+ return era.sum[0].minus(this.sumSnapshotsEntry[0]).div(this.productSnapshotEntry).mul(new Decimal__default["default"](this.deposit)).floor();
2076
2324
  }
2077
2325
  }
2078
- function hedgeRewardsDecay(supply, birthTime, timeIn, timeOut, halfLifeInDays) {
2079
- const timeInOffsetStart = timeIn - birthTime;
2080
- const timeOutOffsetStart = timeOut - birthTime;
2081
- const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24);
2082
- const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart));
2083
- return awardedTokens;
2084
- }
2326
+ // function hedgeRewardsDecay (supply: number, birthTime: number, timeIn: number, timeOut: number, halfLifeInDays: number): number {
2327
+ // const timeInOffsetStart = timeIn - birthTime
2328
+ // const timeOutOffsetStart = timeOut - birthTime
2329
+ // const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24)
2330
+ // const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart))
2331
+ // return awardedTokens
2332
+ // }
2085
2333
 
2086
2334
  exports.CHAINLINK_SOL_USD_ID = CHAINLINK_SOL_USD_ID;
2087
2335
  exports.CHAINLINK_SOL_USD_PUBLICKEY = CHAINLINK_SOL_USD_PUBLICKEY;
@@ -2095,20 +2343,27 @@ exports.StakingPool = StakingPool;
2095
2343
  exports.StakingPoolPosition = StakingPoolPosition;
2096
2344
  exports.VaultAccount = VaultAccount;
2097
2345
  exports.VaultHistoryEvent = VaultHistoryEvent;
2346
+ exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
2347
+ exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
2348
+ exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
2349
+ exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
2098
2350
  exports.createStakingPool = createStakingPool;
2099
2351
  exports.createStakingPoolInstruction = createStakingPoolInstruction;
2100
2352
  exports.createVault = createVault;
2101
2353
  exports.createVaultInstruction = createVaultInstruction;
2354
+ exports.depositLiquidationPool = depositLiquidationPool;
2355
+ exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
2102
2356
  exports.depositStakingPool = depositStakingPool;
2103
2357
  exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
2104
2358
  exports.depositVault = depositVault;
2105
2359
  exports.depositVaultInstruction = depositVaultInstruction;
2106
2360
  exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
2361
+ exports.findVaultAddress = findVaultAddress;
2362
+ exports.getCollateralStateAccountPublicKey = getCollateralStateAccountPublicKey;
2107
2363
  exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
2108
2364
  exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
2109
2365
  exports.getLiquidationPoolUsdhAccountPublicKey = getLiquidationPoolUsdhAccountPublicKey;
2110
2366
  exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
2111
- exports.getSolCollateralPriceAccountPublicKey = getSolCollateralPriceAccountPublicKey;
2112
2367
  exports.getUsdhMintPublicKey = getUsdhMintPublicKey;
2113
2368
  exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
2114
2369
  exports.liquidateVault = liquidateVault;