hedge-web3 0.1.0 → 0.1.1

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.
@@ -0,0 +1,34 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: actions/setup-node@v2
16
+ with:
17
+ node-version: 16
18
+ - run: npm ci
19
+ - run: npm run build
20
+
21
+ publish-npm:
22
+ needs: build
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - uses: actions/setup-node@v2
27
+ with:
28
+ node-version: 16
29
+ registry-url: https://registry.npmjs.org/
30
+ - run: npm ci
31
+ - run: npm run build
32
+ - run: npm publish
33
+ env:
34
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "hedge-web3",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Hedge Javascript API",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "npm run clean; rollup -c",
8
8
  "clean": "rimraf ./lib",
9
9
  "dev": "rollup -c",
10
- "deploy-docs": "npm run docs; gh-pages -d doc",
11
10
  "docs": "set -ex; typedoc --treatWarningsAsErrors",
12
11
  "test": "echo \"Error: no test specified\" && exit 1"
13
12
  },
@@ -1,13 +1,29 @@
1
1
  import { LAMPORTS_PER_SOL, PublicKey } from '@solana/web3.js'
2
2
  import { HedgeDecimal } from '../HedgeDecimal'
3
3
 
4
+ /**
5
+ * A class that represents an on-chian vault.
6
+ */
4
7
  export class VaultAccount {
8
+ /** The public key of this vault. */
5
9
  publicKey: PublicKey
10
+
11
+ /** The public key of the vault owner. */
6
12
  vaultOwner: PublicKey
13
+
14
+ /** The outstanding debt of the vault (in USDH Lamports). */
7
15
  debt: number
16
+
17
+ /** The deposited collateral of the vault (in SOL Lamports). */
8
18
  deposited: number
19
+
20
+ /** The minimum collateral ratio this vault must maintain to not be subject to liquidation. */
9
21
  minCollateralRatio: HedgeDecimal
22
+
23
+ /** The SOL/USD price at which this vault is subject to liquidation */
10
24
  liquidationPrice: number
25
+
26
+ /** Current State of the vautl ("Open", "Closed", "Liquidated") */
11
27
  vaultStatus: string
12
28
 
13
29
  constructor (vault: any
@@ -22,18 +38,39 @@ export class VaultAccount {
22
38
  this.vaultStatus = Object.keys(vault.vaultStatus)[0]
23
39
  }
24
40
 
41
+ /**
42
+ * Check if some `PublicKey` is the owner
43
+ *
44
+ * @param publicKey the publicKey to check against the vault owner
45
+ * @returns true if publicKey matches the owner publicKey
46
+ */
25
47
  public isOwnedBy (publicKey: PublicKey): boolean {
26
48
  return publicKey.toString() === this.vaultOwner.toString()
27
49
  }
28
50
 
51
+ /**
52
+ * Get the collateral value in SOL
53
+ *
54
+ * @returns collateral value in SOL
55
+ */
29
56
  public inSol (): number {
30
57
  return this.deposited / LAMPORTS_PER_SOL
31
58
  }
32
59
 
60
+ /**
61
+ * Get the debt value in USDH
62
+ *
63
+ * @returns debt value in USDH
64
+ */
33
65
  public inUsd (): number {
34
66
  return this.debt / LAMPORTS_PER_SOL
35
67
  }
36
68
 
69
+ /**
70
+ * Pretty print the vault publickey for easy display
71
+ *
72
+ * @returns example: `1b6ca...azy71s`
73
+ */
37
74
  public toDisplayString (): string {
38
75
  return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey.toString().substring(this.publicKey.toString().length - 6)}`
39
76
  }