hedge-web3 0.1.2 → 0.1.8

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 (66) hide show
  1. package/README.md +44 -0
  2. package/lib/index.js +385 -73
  3. package/lib/index.js.map +1 -1
  4. package/lib/types/src/Constants.d.ts +3 -3
  5. package/lib/types/src/Constants.d.ts.map +1 -1
  6. package/lib/types/src/StakingPools.d.ts +4 -0
  7. package/lib/types/src/StakingPools.d.ts.map +1 -0
  8. package/lib/types/src/Vaults.d.ts +9 -0
  9. package/lib/types/src/Vaults.d.ts.map +1 -0
  10. package/lib/types/src/index.d.ts +12 -2
  11. package/lib/types/src/index.d.ts.map +1 -1
  12. package/lib/types/src/instructions/createStakingPool.d.ts +5 -0
  13. package/lib/types/src/instructions/createStakingPool.d.ts.map +1 -0
  14. package/lib/types/src/instructions/createVault.d.ts +4 -3
  15. package/lib/types/src/instructions/createVault.d.ts.map +1 -1
  16. package/lib/types/src/instructions/depositStakingPool.d.ts +5 -0
  17. package/lib/types/src/instructions/depositStakingPool.d.ts.map +1 -0
  18. package/lib/types/src/instructions/depositVault.d.ts +4 -3
  19. package/lib/types/src/instructions/depositVault.d.ts.map +1 -1
  20. package/lib/types/src/instructions/liquidateVault.d.ts +5 -0
  21. package/lib/types/src/instructions/liquidateVault.d.ts.map +1 -0
  22. package/lib/types/src/instructions/loanVault.d.ts +4 -3
  23. package/lib/types/src/instructions/loanVault.d.ts.map +1 -1
  24. package/lib/types/src/instructions/redeemVault.d.ts +4 -3
  25. package/lib/types/src/instructions/redeemVault.d.ts.map +1 -1
  26. package/lib/types/src/instructions/repayVault.d.ts +4 -3
  27. package/lib/types/src/instructions/repayVault.d.ts.map +1 -1
  28. package/lib/types/src/instructions/withdrawStakingPool.d.ts +5 -0
  29. package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +1 -0
  30. package/lib/types/src/instructions/withdrawVault.d.ts +4 -3
  31. package/lib/types/src/instructions/withdrawVault.d.ts.map +1 -1
  32. package/lib/types/src/state/LiquidationPoolEra.d.ts.map +1 -1
  33. package/lib/types/src/state/LiquidationPosition.d.ts +1 -0
  34. package/lib/types/src/state/LiquidationPosition.d.ts.map +1 -1
  35. package/lib/types/src/state/StakingPool.d.ts +1 -2
  36. package/lib/types/src/state/StakingPool.d.ts.map +1 -1
  37. package/lib/types/src/state/StakingPoolPosition.d.ts +1 -0
  38. package/lib/types/src/state/StakingPoolPosition.d.ts.map +1 -1
  39. package/lib/types/src/state/VaultAccount.d.ts.map +1 -1
  40. package/lib/types/src/utils/Errors.d.ts +2 -0
  41. package/lib/types/src/utils/Errors.d.ts.map +1 -0
  42. package/lib/types/tsconfig.base.tsbuildinfo +1 -1
  43. package/package.json +3 -3
  44. package/src/Constants.ts +3 -3
  45. package/src/StakingPools.ts +3 -0
  46. package/src/Vaults.ts +8 -0
  47. package/src/index.ts +14 -5
  48. package/src/instructions/createStakingPool.ts +64 -0
  49. package/src/instructions/createVault.ts +10 -11
  50. package/src/instructions/depositStakingPool.ts +60 -0
  51. package/src/instructions/depositVault.ts +10 -11
  52. package/src/instructions/liquidateVault.ts +66 -0
  53. package/src/instructions/loanVault.ts +10 -11
  54. package/src/instructions/redeemVault.ts +10 -11
  55. package/src/instructions/repayVault.ts +10 -11
  56. package/src/instructions/withdrawStakingPool.ts +69 -0
  57. package/src/instructions/withdrawVault.ts +10 -11
  58. package/src/state/LiquidationPoolEra.ts +5 -5
  59. package/src/state/LiquidationPosition.ts +26 -18
  60. package/src/state/StakingPool.ts +4 -5
  61. package/src/state/StakingPoolPosition.ts +4 -5
  62. package/src/state/VaultAccount.ts +0 -1
  63. package/src/state/VaultHistoryEvent.ts +1 -1
  64. package/src/types/buffer-layout/index.d.ts +88 -0
  65. package/src/utils/Errors.ts +11 -0
  66. package/typedoc.json +1 -2
package/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Hedge Web3 API
2
+
3
+ Documentation for the Hedge Web3 TypeScript API.
4
+
5
+ ![NPM Version](https://badge.fury.io/js/hedge-web3.svg)
6
+
7
+ ## Documentation
8
+
9
+ Documentation can be found here: [https://web3-docs.hedge.so/](https://web3-docs.hedge.so/)
10
+
11
+
12
+ ## Installation
13
+
14
+ TypeDoc runs on Node.js and is available as a NPM package.
15
+
16
+ ```sh
17
+ npm install hedge-web3 --save-dev
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ To create a vault, import the package.
23
+
24
+ ```js
25
+ const HedgeWeb3 = require('hedge-web3')
26
+ ```
27
+
28
+ To create a vault and deposit 3 SOL:
29
+
30
+ ```js
31
+ const vaultPublickey = await HedgeWeb3.createVault(connection, ownerPublicKey, LAMPORTS_PER_SOL * 3, LAMPORTS_PER_SOL * 1.2)
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ This project is maintained by a community of developers. Contributions are welcome and appreciated.
37
+ You can find Hedge Labs on GitHub; feel free to open an issue or create a pull request:
38
+ https://github.com/Hedge-Finance/hedge-web3
39
+
40
+ ## License
41
+
42
+ Copyright (c) 2021 [Christopher Coudron](https://hedge.so)<br>
43
+ Copyright (c) 2021 [Hedge Labs Ltd.](https://hedge.so)<br>
44
+ Licensed under the Apache License 2.0.
package/lib/index.js CHANGED
@@ -11,39 +11,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
11
11
 
12
12
  var Decimal__default = /*#__PURE__*/_interopDefaultLegacy(Decimal);
13
13
 
14
- const HEDGE_PROGRAM_ID = 'fff6FuPWrBPzFHeWwtBQaPjKvMvW27w8Jf4P7SSoueX';
15
- const HEDGE_PROGRAM_PUBLICKEY = new web3_js.PublicKey(HEDGE_PROGRAM_ID);
16
- const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
17
- const CHAINLINK_SOL_USD_PUBLICKEY = new web3_js.PublicKey(CHAINLINK_SOL_USD_ID);
18
- async function getUsdhMintPublicKey() {
19
- const enc = new TextEncoder();
20
- const [findMintPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
21
- return [findMintPublicKey, bump];
22
- }
23
- async function getVaultSystemStatePublicKey() {
24
- const enc = new TextEncoder();
25
- const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
26
- return [publicKey, bump];
27
- }
28
- async function getHedgeMintPublicKey() {
29
- const enc = new TextEncoder();
30
- const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
31
- return [publicKey, bump];
32
- }
33
- async function getPoolPublicKeyForMint(mintPublicKey) {
34
- const enc = new TextEncoder();
35
- const strToEncode = (mintPublicKey.toString().substring(0, 12));
36
- const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY);
37
- return [publicKey, bump, strToEncode];
38
- }
39
- async function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
40
- return (await web3_js.PublicKey.findProgramAddress([
41
- walletAddress.toBuffer(),
42
- splToken.TOKEN_PROGRAM_ID.toBuffer(),
43
- tokenMintAddress.toBuffer()
44
- ], splToken.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
45
- }
46
-
47
14
  const vaultIdl = {
48
15
  version: '0.1.0',
49
16
  name: 'vault',
@@ -1517,20 +1484,169 @@ const vaultIdl = {
1517
1484
  ]
1518
1485
  };
1519
1486
 
1520
- async function createVault(connection, payer, depositAmount, collateralRatio, confirmOptions) {
1487
+ function parseAnchorErrors(error) {
1488
+ const idlErrors = anchor.parseIdlErrors(vaultIdl);
1489
+ const parsedError = anchor.ProgramError.parse(error, idlErrors);
1490
+ if (parsedError !== null) {
1491
+ throw parsedError;
1492
+ }
1493
+ throw error;
1494
+ }
1495
+
1496
+ const HEDGE_PROGRAM_ID = 'hhhJmQPMmb2sNoTQK1ip7ZRGpRdGfskEEgjacf9XFWv';
1497
+ const HEDGE_PROGRAM_PUBLICKEY = new web3_js.PublicKey(HEDGE_PROGRAM_ID);
1498
+ const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
1499
+ const CHAINLINK_SOL_USD_PUBLICKEY = new web3_js.PublicKey(CHAINLINK_SOL_USD_ID);
1500
+ async function getLiquidationPoolStatePublicKey() {
1501
+ const enc = new TextEncoder();
1502
+ const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1503
+ return [poolPublicKey, bump];
1504
+ }
1505
+ async function getLiquidationPoolUsdhAccountPublicKey() {
1506
+ const enc = new TextEncoder();
1507
+ const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY);
1508
+ return [poolPublicKey, bump];
1509
+ }
1510
+ async function getUsdhMintPublicKey() {
1511
+ const enc = new TextEncoder();
1512
+ const [findMintPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1513
+ return [findMintPublicKey, bump];
1514
+ }
1515
+ async function getVaultSystemStatePublicKey() {
1516
+ const enc = new TextEncoder();
1517
+ const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1518
+ return [publicKey, bump];
1519
+ }
1520
+ async function getHedgeMintPublicKey() {
1521
+ const enc = new TextEncoder();
1522
+ const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1523
+ return [publicKey, bump];
1524
+ }
1525
+ async function getPoolPublicKeyForMint(mintPublicKey) {
1526
+ const enc = new TextEncoder();
1527
+ const strToEncode = (mintPublicKey.toString().substring(0, 12));
1528
+ const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY);
1529
+ return [publicKey, bump, strToEncode];
1530
+ }
1531
+ async function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
1532
+ return (await web3_js.PublicKey.findProgramAddress([
1533
+ walletAddress.toBuffer(),
1534
+ splToken.TOKEN_PROGRAM_ID.toBuffer(),
1535
+ tokenMintAddress.toBuffer()
1536
+ ], splToken.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
1537
+ }
1538
+
1539
+ async function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
1540
+ const transaction = new web3_js.Transaction().add(await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
1541
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
1542
+ const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey);
1543
+ return poolPublickey;
1544
+ }
1545
+ async function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
1546
+ const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1521
1547
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1522
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1548
+ const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey);
1549
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey);
1550
+ const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
1551
+ return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor.BN(hedgeTokensToBeMinted), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), {
1552
+ accounts: {
1553
+ signer: payerPublicKey,
1554
+ vaultSystemState: vaultSystemStatePublicKey,
1555
+ pool: poolPublickey,
1556
+ stakedTokenMintInfo: mintPublicKey,
1557
+ usdhMint: usdhMintPublickey,
1558
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
1559
+ poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
1560
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
1561
+ splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1562
+ splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1563
+ systemProgram: web3_js.SystemProgram.programId
1564
+ },
1565
+ signers: []
1566
+ });
1567
+ }
1568
+
1569
+ async function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
1570
+ const poolPosition = web3_js.Keypair.generate();
1571
+ const transaction = new web3_js.Transaction().add(await depositStakingPoolInstruction(program, payer.publicKey, poolPosition.publicKey, mintPublicKey, depositAmount, overrideStartTime));
1572
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors);
1573
+ return poolPosition.publicKey;
1574
+ }
1575
+ async function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
1576
+ const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
1577
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
1578
+ const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
1579
+ return program.instruction.depositStakingPool(new anchor.BN(depositAmount), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
1580
+ {
1581
+ accounts: {
1582
+ payer: payerPublicKey,
1583
+ pool: poolPublickey,
1584
+ poolPosition: poolPositionPublicKey,
1585
+ stakedTokenMintInfo: stakedTokenMintPublicKey,
1586
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
1587
+ payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
1588
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
1589
+ splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1590
+ splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1591
+ systemProgram: web3_js.SystemProgram.programId
1592
+ },
1593
+ signers: []
1594
+ });
1595
+ }
1596
+
1597
+ async function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
1598
+ const poolPosition = web3_js.Keypair.generate();
1599
+ const transaction = new web3_js.Transaction().add(await withdrawStakingPoolInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
1600
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
1601
+ return poolPosition.publicKey;
1602
+ }
1603
+ async function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
1604
+ const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1605
+ const [usdhMintPublickey] = await getUsdhMintPublicKey();
1606
+ const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1607
+ const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
1608
+ const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
1609
+ const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
1610
+ const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
1611
+ const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey);
1612
+ const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey);
1613
+ return program.instruction.withdrawStakingPool(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
1614
+ {
1615
+ accounts: {
1616
+ payer: payerPublicKey,
1617
+ vaultSystemState: vaultSystemStatePublicKey,
1618
+ pool: poolPublickey,
1619
+ poolPosition: poolPositionPublicKey,
1620
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
1621
+ poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
1622
+ payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
1623
+ payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
1624
+ payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
1625
+ hedgeMint: hedgeMintPublickey,
1626
+ stakedTokenMint: stakedTokenMintPublicKey,
1627
+ usdhMint: usdhMintPublickey,
1628
+ rent: web3_js.SYSVAR_RENT_PUBKEY,
1629
+ splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1630
+ splAssociatedTokenProgramInfo: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
1631
+ systemProgram: web3_js.SystemProgram.programId
1632
+ },
1633
+ signers: []
1634
+ });
1635
+ }
1636
+
1637
+ async function createVault(program, provider, payer, depositAmount, collateralRatio) {
1638
+ const [usdhMintPublickey] = await getUsdhMintPublicKey();
1639
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1523
1640
  // Prep the user to get USDH back out at some point
1524
1641
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1525
1642
  const newVault = web3_js.Keypair.generate();
1526
1643
  const history = web3_js.Keypair.generate();
1527
1644
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1528
- const transaction = new web3_js.Transaction().add(createVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, newVault.publicKey, history.publicKey, depositAmount, collateralRatio));
1529
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, newVault, history], confirmOptions);
1645
+ const transaction = new web3_js.Transaction().add(createVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, newVault.publicKey, history.publicKey, depositAmount, collateralRatio));
1646
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, newVault, history], provider === null || provider === void 0 ? void 0 : provider.opts);
1530
1647
  return newVault.publicKey;
1531
1648
  }
1532
- function createVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount, collateralRatio) {
1533
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1649
+ function createVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount, collateralRatio) {
1534
1650
  const ix = program.instruction.createVault(new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
1535
1651
  accounts: {
1536
1652
  vaultSystemState: vaultSystemStatePublicKey,
@@ -1544,19 +1660,18 @@ function createVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vault
1544
1660
  return ix;
1545
1661
  }
1546
1662
 
1547
- async function depositVault(connection, payer, vaultPublicKey, depositAmount, confirmOptions) {
1663
+ async function depositVault(program, provider, payer, vaultPublicKey, depositAmount) {
1548
1664
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1549
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1665
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1550
1666
  // Prep the user to get USDH back out at some point
1551
1667
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1552
1668
  const history = web3_js.Keypair.generate();
1553
1669
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1554
- const transaction = new web3_js.Transaction().add(depositVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, depositAmount));
1555
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
1670
+ const transaction = new web3_js.Transaction().add(depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, depositAmount));
1671
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1556
1672
  return vaultPublicKey;
1557
1673
  }
1558
- function depositVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount) {
1559
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1674
+ function depositVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount) {
1560
1675
  return program.instruction.depositVault(new anchor.BN(depositAmount), {
1561
1676
  accounts: {
1562
1677
  vaultSystemState: vaultSystemStatePublicKey,
@@ -1569,19 +1684,18 @@ function depositVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaul
1569
1684
  });
1570
1685
  }
1571
1686
 
1572
- async function withdrawVault(connection, payer, vaultPublicKey, withdrawAmount, chainlinkOverridePrice, confirmOptions) {
1687
+ async function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, chainlinkOverridePrice) {
1573
1688
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1574
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1689
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1575
1690
  // Prep the user to get USDH back out at some point
1576
1691
  await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1577
1692
  const history = web3_js.Keypair.generate();
1578
1693
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1579
- const transaction = new web3_js.Transaction().add(withdrawVaultInstruction(vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, withdrawAmount, chainlinkOverridePrice));
1580
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
1694
+ const transaction = new web3_js.Transaction().add(withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, withdrawAmount, chainlinkOverridePrice));
1695
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1581
1696
  return vaultPublicKey;
1582
1697
  }
1583
- function withdrawVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vaultPublickey, historyPublicKey, withdrawAmount, chainlinkOverridePrice) {
1584
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1698
+ function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublickey, historyPublicKey, withdrawAmount, chainlinkOverridePrice) {
1585
1699
  return program.instruction.withdrawVault(new anchor.BN(withdrawAmount), new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : 200 * web3_js.LAMPORTS_PER_SOL), {
1586
1700
  accounts: {
1587
1701
  vaultSystemState: vaultSystemStatePublicKey,
@@ -1595,18 +1709,17 @@ function withdrawVaultInstruction(vaultSystemStatePublicKey, payerPublicKey, vau
1595
1709
  });
1596
1710
  }
1597
1711
 
1598
- async function loanVault(connection, payer, vaultPublicKey, loanAmount, chainlinkOverridePrice, confirmOptions) {
1712
+ async function loanVault(program, provider, payer, vaultPublicKey, loanAmount, chainlinkOverridePrice) {
1599
1713
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1600
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1714
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1601
1715
  // Prep the user to get USDH back out at some point
1602
1716
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1603
1717
  const history = web3_js.Keypair.generate();
1604
- const transaction = new web3_js.Transaction().add(await loanVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, loanAmount, chainlinkOverridePrice));
1605
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
1718
+ const transaction = new web3_js.Transaction().add(await loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, loanAmount, chainlinkOverridePrice));
1719
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1606
1720
  return vaultPublicKey;
1607
1721
  }
1608
- async function loanVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, loanAmount, chainlinkOverridePrice) {
1609
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1722
+ async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, loanAmount, chainlinkOverridePrice) {
1610
1723
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1611
1724
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1612
1725
  const [hedgeMintPublickey] = await getHedgeMintPublicKey();
@@ -1631,18 +1744,17 @@ async function loanVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPubli
1631
1744
  });
1632
1745
  }
1633
1746
 
1634
- async function repayVault(connection, payer, vaultPublicKey, repayAmount, confirmOptions) {
1747
+ async function repayVault(program, provider, payer, vaultPublicKey, repayAmount) {
1635
1748
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1636
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1749
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1637
1750
  // Prep the user to get USDH back out at some point
1638
1751
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1639
1752
  const history = web3_js.Keypair.generate();
1640
- const transaction = new web3_js.Transaction().add(await repayVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount));
1641
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
1753
+ const transaction = new web3_js.Transaction().add(await repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount));
1754
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1642
1755
  return vaultPublicKey;
1643
1756
  }
1644
- async function repayVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount) {
1645
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1757
+ async function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount) {
1646
1758
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1647
1759
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1648
1760
  const [hedgeMintPublickey] = await getHedgeMintPublicKey();
@@ -1665,18 +1777,17 @@ async function repayVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPubl
1665
1777
  });
1666
1778
  }
1667
1779
 
1668
- async function redeemVault(connection, payer, vaultPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime, confirmOptions) {
1780
+ async function redeemVault(program, provider, payer, vaultPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime) {
1669
1781
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1670
- const USDH = new splToken.Token(connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1782
+ const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1671
1783
  // Prep the user to get USDH back out at some point
1672
1784
  const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1673
1785
  const history = web3_js.Keypair.generate();
1674
- const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime));
1675
- await web3_js.sendAndConfirmTransaction(connection, transaction, [payer, history], confirmOptions);
1786
+ const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime));
1787
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1676
1788
  return vaultPublicKey;
1677
1789
  }
1678
- async function redeemVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime) {
1679
- const program = new anchor.Program(vaultIdl, HEDGE_PROGRAM_ID);
1790
+ async function redeemVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount, chainlinkOverridePrice, transactionOverrideTime) {
1680
1791
  const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1681
1792
  const [usdhMintPublickey] = await getUsdhMintPublicKey();
1682
1793
  const [hedgeMintPublickey] = await getHedgeMintPublicKey();
@@ -1702,6 +1813,42 @@ async function redeemVaultInstruction(payerPublicKey, ownerUsdhAccount, vaultPub
1702
1813
  });
1703
1814
  }
1704
1815
 
1816
+ async function liquidateVault(program, provider, payer, vaultPublicKey, chainlinkOverridePrice) {
1817
+ const history = web3_js.Keypair.generate();
1818
+ const newEra = web3_js.Keypair.generate();
1819
+ const transaction = new web3_js.Transaction().add(await liquidateVaultInstruction(program, payer.publicKey, vaultPublicKey, history.publicKey, newEra.publicKey, chainlinkOverridePrice));
1820
+ await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra], provider.opts);
1821
+ return vaultPublicKey;
1822
+ }
1823
+ async function liquidateVaultInstruction(program, payerPublicKey, vaultPublickey, historyPublicKey, newEraPublicKey, chainlinkOverridePrice) {
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 poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
1831
+ return program.instruction.liquidateVault(new anchor.BN(chainlinkOverridePrice !== null && chainlinkOverridePrice !== void 0 ? chainlinkOverridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
1832
+ {
1833
+ accounts: {
1834
+ vaultSystemState: vaultSystemStatePublicKey,
1835
+ poolEra: poolStateInfo.currentEra,
1836
+ vaultAccount: vaultPublickey,
1837
+ poolState: liquidationPoolStatePublicKey,
1838
+ usdhMint: usdhMintPublickey,
1839
+ chainlinkFeedAccount: CHAINLINK_SOL_USD_PUBLICKEY,
1840
+ history: historyPublicKey,
1841
+ payer: payerPublicKey,
1842
+ splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1843
+ systemProgram: web3_js.SystemProgram.programId,
1844
+ feePool: hedgeStakingPoolPublicKey,
1845
+ liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
1846
+ newEra: newEraPublicKey
1847
+ },
1848
+ signers: []
1849
+ });
1850
+ }
1851
+
1705
1852
  /**
1706
1853
  * Convert a U128 to a Decimal
1707
1854
  *
@@ -1730,7 +1877,6 @@ class VaultAccount {
1730
1877
  this.deposited = vault.deposited.toNumber();
1731
1878
  this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio);
1732
1879
  this.liquidationPrice = vault.liquidationPrice.toNumber();
1733
- this.minCollateralRatio = vault.minCollateralRatio.toNumber();
1734
1880
  this.vaultStatus = Object.keys(vault.vaultStatus)[0];
1735
1881
  }
1736
1882
  /**
@@ -1768,23 +1914,189 @@ class VaultAccount {
1768
1914
  }
1769
1915
  }
1770
1916
 
1771
- function foo(input) {
1772
- console.log('Input', input);
1917
+ class VaultHistoryEvent {
1918
+ constructor(account, publicKey) {
1919
+ this.account = account;
1920
+ this.publicKey = publicKey;
1921
+ this.actorAccount = account.actorAccount;
1922
+ this.usdSolPrice = DecimalFromU128(account.usdSolPrice.toString());
1923
+ this.usdhDebtBefore = account.usdhDebtBefore.toNumber();
1924
+ this.usdhDebtAfter = account.usdhDebtAfter.toNumber();
1925
+ this.solBalanceBefore = account.solBalanceBefore.toNumber();
1926
+ this.solBalanceAfter = account.solBalanceAfter.toNumber();
1927
+ this.minCollateralRatioBefore = DecimalFromU128(account.minCollateralRatioBefore);
1928
+ this.minCollateralRatioAfter = DecimalFromU128(account.minCollateralRatioAfter);
1929
+ this.vaultStateBefore = account.vaultStateBefore;
1930
+ this.vaultStateAfter = account.vaultStateAfter;
1931
+ this.timestamp = account.timestamp.toNumber();
1932
+ this.action = account.action;
1933
+ }
1934
+ }
1935
+ exports.VaultStatus = void 0;
1936
+ (function (VaultStatus) {
1937
+ VaultStatus[VaultStatus["Open"] = 0] = "Open";
1938
+ VaultStatus[VaultStatus["Closed"] = 1] = "Closed";
1939
+ VaultStatus[VaultStatus["Liquidated"] = 2] = "Liquidated";
1940
+ VaultStatus[VaultStatus["Distributed"] = 3] = "Distributed";
1941
+ VaultStatus[VaultStatus["Redeemed"] = 4] = "Redeemed";
1942
+ })(exports.VaultStatus || (exports.VaultStatus = {}));
1943
+ exports.VaultHistoryAction = void 0;
1944
+ (function (VaultHistoryAction) {
1945
+ VaultHistoryAction[VaultHistoryAction["Create"] = 0] = "Create";
1946
+ VaultHistoryAction[VaultHistoryAction["Close"] = 1] = "Close";
1947
+ VaultHistoryAction[VaultHistoryAction["Liquidate"] = 2] = "Liquidate";
1948
+ VaultHistoryAction[VaultHistoryAction["PartialLiquidate"] = 3] = "PartialLiquidate";
1949
+ VaultHistoryAction[VaultHistoryAction["Distributed"] = 4] = "Distributed";
1950
+ VaultHistoryAction[VaultHistoryAction["Redeem"] = 5] = "Redeem";
1951
+ VaultHistoryAction[VaultHistoryAction["TransferOwnership"] = 6] = "TransferOwnership";
1952
+ VaultHistoryAction[VaultHistoryAction["Deposit"] = 7] = "Deposit";
1953
+ VaultHistoryAction[VaultHistoryAction["Withdraw"] = 8] = "Withdraw";
1954
+ VaultHistoryAction[VaultHistoryAction["Loan"] = 9] = "Loan";
1955
+ VaultHistoryAction[VaultHistoryAction["RepayCredit"] = 10] = "RepayCredit";
1956
+ })(exports.VaultHistoryAction || (exports.VaultHistoryAction = {}));
1957
+
1958
+ class StakingPool {
1959
+ constructor(poolInfo, publicKey) {
1960
+ this.poolInfo = poolInfo;
1961
+ this.publicKey = publicKey;
1962
+ this.deposits = poolInfo.deposits.toNumber();
1963
+ // this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
1964
+ // this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
1965
+ this.lastTransactionTime = poolInfo.lastTransactionTime.toNumber();
1966
+ this.startTime = poolInfo.startTime.toNumber();
1967
+ this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
1968
+ this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
1969
+ this.hedgeRewardAccumulator = DecimalFromU128(poolInfo.hedgeRewardAccumulator);
1970
+ this.usdhFeeAccumulator = DecimalFromU128(poolInfo.usdhFeeAccumulator);
1971
+ this.solFeeAccumulator = DecimalFromU128(poolInfo.solFeeAccumulator);
1972
+ // this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
1973
+ }
1974
+ }
1975
+
1976
+ class StakingPoolPosition {
1977
+ constructor(poolPositionInfo, key, stakingPool) {
1978
+ this.poolPositionInfo = poolPositionInfo;
1979
+ this.publicKey = key;
1980
+ this.pool = stakingPool;
1981
+ this.owner = poolPositionInfo.owner;
1982
+ this.deposited = poolPositionInfo.deposited.toNumber();
1983
+ this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
1984
+ this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
1985
+ this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
1986
+ this.startHedgeRewardAccumulator = DecimalFromU128(poolPositionInfo.startHedgeRewardAccumulator);
1987
+ this.startUsdhFeeAccumulator = DecimalFromU128(poolPositionInfo.startUsdhFeeAccumulator);
1988
+ this.startSolFeeAccumulator = DecimalFromU128(poolPositionInfo.startSolFeeAccumulator);
1989
+ this.open = poolPositionInfo.state.open !== undefined;
1990
+ }
1991
+ getCurrentUsdhFeeReward() {
1992
+ return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new Decimal__default["default"](this.deposited));
1993
+ }
1994
+ }
1995
+
1996
+ /**
1997
+ * Represents an on-chian pool era. In the event an era is depleted of deposits, a new era is
1998
+ * created to maintain each users contribution to the pool.
1999
+ */
2000
+ class LiquidationPoolEra {
2001
+ constructor(liquidyPoolEra) {
2002
+ this.liquidyPoolEra = liquidyPoolEra;
2003
+ this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber();
2004
+ this.product = DecimalFromU128(liquidyPoolEra.productBytes);
2005
+ this.sum = DecimalFromU128(liquidyPoolEra.sumBytes);
2006
+ this.hedgeRewardsAccumulator = DecimalFromU128(liquidyPoolEra.hedgeRewardsAccumulatorBytes);
2007
+ this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber();
2008
+ }
2009
+ }
2010
+
2011
+ class LiquidationPoolState {
2012
+ constructor(liquidationPoolState) {
2013
+ this.liquidationPoolState = liquidationPoolState;
2014
+ this.lifetimeDeposits = liquidationPoolState.lifetimeDeposits.toNumber();
2015
+ this.hedgeInitRewardsTimestamp = liquidationPoolState.hedgeInitRewardsTimestamp.toNumber();
2016
+ // TODO Add the rest that are missing. Do we need them?
2017
+ }
2018
+ }
2019
+
2020
+ class LiquidationPosition {
2021
+ constructor(poolPositionInfo, key, era, liquidationPoolState) {
2022
+ this.publicKey = key;
2023
+ this.eraPublicKey = poolPositionInfo.era;
2024
+ this.era = era;
2025
+ this.liquidationPoolState = liquidationPoolState;
2026
+ this.ownerAccount = poolPositionInfo.ownerAccount;
2027
+ this.deposit = poolPositionInfo.deposit.toNumber();
2028
+ this.closedUsdh = poolPositionInfo.closedUsdh.toNumber();
2029
+ this.closedSol = poolPositionInfo.closedSol.toNumber();
2030
+ this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
2031
+ this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
2032
+ this.productSnapshot = DecimalFromU128(poolPositionInfo.productSnapshotBytes);
2033
+ this.sumSnapshot = DecimalFromU128(poolPositionInfo.sumSnapshotBytes);
2034
+ this.hedgeRewardsSnapshot = DecimalFromU128(poolPositionInfo.hedgeRewardsSnapshotAccum);
2035
+ this.open = poolPositionInfo.state.open !== undefined;
2036
+ }
2037
+ getUsdhAvailable() {
2038
+ return (this.era.product.div(this.productSnapshot)).mul(new Decimal__default["default"](this.deposit));
2039
+ }
2040
+ getSolAvailable() {
2041
+ return this.era.sum.minus(this.sumSnapshot).div(this.productSnapshot).mul(new Decimal__default["default"](this.deposit)).floor();
2042
+ }
2043
+ getHedgeAvailable() {
2044
+ const LiquidationPoolTotalSupply = 2000000.0 * web3_js.LAMPORTS_PER_SOL;
2045
+ const hedgeRewardsSinceLastUpdate = hedgeRewardsDecay(LiquidationPoolTotalSupply, this.liquidationPoolState.hedgeInitRewardsTimestamp * 1000, this.era.hedgeRewardsTimestamp * 1000, Date.now(), 365 * 1000);
2046
+ if (this.era.totalDeposits === 0) {
2047
+ return new Decimal__default["default"](0);
2048
+ }
2049
+ const rewardsPerToken = this.era.product.mul(new Decimal__default["default"](hedgeRewardsSinceLastUpdate / this.era.totalDeposits));
2050
+ const newAccumulator = rewardsPerToken.add(new Decimal__default["default"](this.era.hedgeRewardsAccumulator));
2051
+ const hedgeAvailable = (newAccumulator.minus(this.hedgeRewardsSnapshot)).mul(new Decimal__default["default"](this.deposit)).div(new Decimal__default["default"](this.productSnapshot));
2052
+ return hedgeAvailable;
2053
+ }
2054
+ }
2055
+ function hedgeRewardsDecay(supply, birthTime, timeIn, timeOut, halfLifeInDays) {
2056
+ const timeInOffsetStart = timeIn - birthTime;
2057
+ const timeOutOffsetStart = timeOut - birthTime;
2058
+ const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24);
2059
+ const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart));
2060
+ return awardedTokens;
1773
2061
  }
1774
2062
 
2063
+ exports.CHAINLINK_SOL_USD_ID = CHAINLINK_SOL_USD_ID;
2064
+ exports.CHAINLINK_SOL_USD_PUBLICKEY = CHAINLINK_SOL_USD_PUBLICKEY;
1775
2065
  exports.DecimalFromU128 = DecimalFromU128;
2066
+ exports.HEDGE_PROGRAM_ID = HEDGE_PROGRAM_ID;
2067
+ exports.HEDGE_PROGRAM_PUBLICKEY = HEDGE_PROGRAM_PUBLICKEY;
2068
+ exports.LiquidationPoolEra = LiquidationPoolEra;
2069
+ exports.LiquidationPoolState = LiquidationPoolState;
2070
+ exports.LiquidationPosition = LiquidationPosition;
2071
+ exports.StakingPool = StakingPool;
2072
+ exports.StakingPoolPosition = StakingPoolPosition;
1776
2073
  exports.VaultAccount = VaultAccount;
2074
+ exports.VaultHistoryEvent = VaultHistoryEvent;
2075
+ exports.createStakingPool = createStakingPool;
2076
+ exports.createStakingPoolInstruction = createStakingPoolInstruction;
1777
2077
  exports.createVault = createVault;
1778
2078
  exports.createVaultInstruction = createVaultInstruction;
2079
+ exports.depositStakingPool = depositStakingPool;
2080
+ exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
1779
2081
  exports.depositVault = depositVault;
1780
2082
  exports.depositVaultInstruction = depositVaultInstruction;
1781
- exports.foo = foo;
2083
+ exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
2084
+ exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
2085
+ exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
2086
+ exports.getLiquidationPoolUsdhAccountPublicKey = getLiquidationPoolUsdhAccountPublicKey;
2087
+ exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
2088
+ exports.getUsdhMintPublicKey = getUsdhMintPublicKey;
2089
+ exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
2090
+ exports.liquidateVault = liquidateVault;
2091
+ exports.liquidateVaultInstruction = liquidateVaultInstruction;
1782
2092
  exports.loanVault = loanVault;
1783
2093
  exports.loanVaultInstruction = loanVaultInstruction;
1784
2094
  exports.redeemVault = redeemVault;
1785
2095
  exports.redeemVaultInstruction = redeemVaultInstruction;
1786
2096
  exports.repayVault = repayVault;
1787
2097
  exports.repayVaultInstruction = repayVaultInstruction;
2098
+ exports.withdrawStakingPool = withdrawStakingPool;
2099
+ exports.withdrawStakingPoolInstruction = withdrawStakingPoolInstruction;
1788
2100
  exports.withdrawVault = withdrawVault;
1789
2101
  exports.withdrawVaultInstruction = withdrawVaultInstruction;
1790
2102
  //# sourceMappingURL=index.js.map