@triadxyz/triad-protocol 0.1.1-alpha.1 → 0.1.1-alpha.4

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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
+ /// <reference types="bn.js" />
1
2
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
2
- import { Connection } from '@solana/web3.js';
3
+ import { Connection, PublicKey } from '@solana/web3.js';
3
4
  import { TriadProtocol } from './types/triad_protocol';
4
5
  import Ticker from './ticker';
5
6
  import Vault from './vault';
@@ -9,4 +10,34 @@ export default class TriadProtocolClient {
9
10
  ticker: Ticker;
10
11
  vault: Vault;
11
12
  constructor(connection: Connection, wallet: Wallet);
13
+ getUserPositions: (userWallet: PublicKey) => Promise<{
14
+ ticker: import("@coral-xyz/anchor").ProgramAccount<{
15
+ initTs: import("bn.js");
16
+ updatedTs: import("bn.js");
17
+ bump: number;
18
+ authority: PublicKey;
19
+ name: string;
20
+ protocolProgramId: PublicKey;
21
+ price: import("bn.js");
22
+ vault: PublicKey;
23
+ }>;
24
+ position: {
25
+ ts: import("bn.js");
26
+ bump: number;
27
+ totalDeposited: import("bn.js");
28
+ totalWithdrawn: import("bn.js");
29
+ lpShare: import("bn.js");
30
+ totalPositions: number;
31
+ ticker: PublicKey;
32
+ authority: PublicKey;
33
+ positions: {
34
+ amount: import("bn.js");
35
+ entryPrice: import("bn.js");
36
+ ts: import("bn.js");
37
+ isLong: boolean;
38
+ isOpen: boolean;
39
+ pnl: import("bn.js");
40
+ }[];
41
+ };
42
+ }[]>;
12
43
  }
package/dist/index.js CHANGED
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -8,8 +17,21 @@ const triad_protocol_1 = require("./types/triad_protocol");
8
17
  const constants_1 = require("./utils/constants");
9
18
  const ticker_1 = __importDefault(require("./ticker"));
10
19
  const vault_1 = __importDefault(require("./vault"));
20
+ const helpers_1 = require("./utils/helpers");
11
21
  class TriadProtocolClient {
12
22
  constructor(connection, wallet) {
23
+ this.getUserPositions = (userWallet) => __awaiter(this, void 0, void 0, function* () {
24
+ const tickers = yield this.ticker.getTickers();
25
+ const positions = yield Promise.all(tickers.map((ticker) => __awaiter(this, void 0, void 0, function* () {
26
+ const UserPositionPDA = (0, helpers_1.getUserPositionAddressSync)(this.program.programId, userWallet, ticker.publicKey);
27
+ const position = yield this.program.account.userPosition.fetch(UserPositionPDA);
28
+ return {
29
+ ticker,
30
+ position
31
+ };
32
+ })));
33
+ return positions;
34
+ });
13
35
  this.provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
14
36
  this.program = new anchor_1.Program(triad_protocol_1.IDL, constants_1.TRIAD_PROTOCOL_PROGRAM_ID, this.provider);
15
37
  this.ticker = new ticker_1.default(this.program, this.provider);
package/dist/ticker.d.ts CHANGED
@@ -31,4 +31,14 @@ export default class Ticker {
31
31
  protocolProgramId: PublicKey;
32
32
  tokenMint: PublicKey;
33
33
  }): Promise<string>;
34
+ /**
35
+ * Update a ticker's price
36
+ * @param name - The ticker's name
37
+ * @param price - The ticker's price
38
+ *
39
+ */
40
+ updateTickerPrice({ name, price }: {
41
+ name: string;
42
+ price: string;
43
+ }): Promise<string>;
34
44
  }
package/dist/ticker.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const helpers_1 = require("./utils/helpers");
13
+ const bn_js_1 = require("bn.js");
13
14
  class Ticker {
14
15
  constructor(program, provider) {
15
16
  this.provider = provider;
@@ -47,5 +48,23 @@ class Ticker {
47
48
  .rpc();
48
49
  });
49
50
  }
51
+ /**
52
+ * Update a ticker's price
53
+ * @param name - The ticker's name
54
+ * @param price - The ticker's price
55
+ *
56
+ */
57
+ updateTickerPrice({ name, price }) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const TickerPDA = (0, helpers_1.getTickerAddressSync)(this.program.programId, name);
60
+ return this.program.methods
61
+ .updateTickerPrice({ price: new bn_js_1.BN(price) })
62
+ .accounts({
63
+ signer: this.provider.wallet.publicKey,
64
+ ticker: TickerPDA
65
+ })
66
+ .rpc();
67
+ });
68
+ }
50
69
  }
51
70
  exports.default = Ticker;
@@ -265,7 +265,7 @@ export type TriadProtocol = {
265
265
  {
266
266
  defined: 'Position';
267
267
  },
268
- 6
268
+ 3
269
269
  ];
270
270
  };
271
271
  }
@@ -411,10 +411,6 @@ export type TriadProtocol = {
411
411
  name: 'amount';
412
412
  type: 'u64';
413
413
  },
414
- {
415
- name: 'ticker';
416
- type: 'publicKey';
417
- },
418
414
  {
419
415
  name: 'entryPrice';
420
416
  type: 'u64';
@@ -268,7 +268,7 @@ exports.IDL = {
268
268
  {
269
269
  defined: 'Position'
270
270
  },
271
- 6
271
+ 3
272
272
  ]
273
273
  }
274
274
  }
@@ -414,10 +414,6 @@ exports.IDL = {
414
414
  name: 'amount',
415
415
  type: 'u64'
416
416
  },
417
- {
418
- name: 'ticker',
419
- type: 'publicKey'
420
- },
421
417
  {
422
418
  name: 'entryPrice',
423
419
  type: 'u64'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.1.1-alpha.1",
3
+ "version": "0.1.1-alpha.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",