@triadxyz/triad-protocol 0.7.0-beta.devnet → 0.7.1-beta.devnet

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.
@@ -168,6 +168,7 @@ const getMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
168
168
  const markets = yield triadProtocol.trade.getMarkets();
169
169
  console.log(markets);
170
170
  });
171
+ getMarkets();
171
172
  const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
172
173
  for (const market of markets) {
173
174
  try {
@@ -223,4 +224,3 @@ const runBot = () => __awaiter(void 0, void 0, void 0, function* () {
223
224
  yield closeOrder();
224
225
  }
225
226
  });
226
- openOrder();
package/dist/trade.js CHANGED
@@ -29,59 +29,15 @@ class Trade {
29
29
  */
30
30
  getMarkets() {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- return this.program.account.market.all().then((markets) => markets.map(({ account, publicKey }) => ({
33
- bump: account.bump,
34
- address: publicKey.toString(),
35
- authority: account.authority.toString(),
36
- marketId: account.marketId.toString(),
37
- name: account.name,
38
- hypePrice: account.hypePrice.toString(),
39
- flopPrice: account.flopPrice.toString(),
40
- hypeLiquidity: account.hypeLiquidity.toString(),
41
- flopLiquidity: account.flopLiquidity.toString(),
42
- totalHypeShares: account.totalHypeShares.toString(),
43
- totalFlopShares: account.totalFlopShares.toString(),
44
- totalVolume: account.totalVolume.toString(),
45
- mint: account.mint.toString(),
46
- ts: account.ts.toString(),
47
- updateTs: account.updateTs.toString(),
48
- openOrdersCount: account.openOrdersCount.toString(),
49
- nextOrderId: account.nextOrderId.toString(),
50
- feeBps: account.feeBps,
51
- feeVault: account.feeVault.toBase58(),
52
- isActive: account.isActive,
53
- marketPrice: account.marketPrice.toString(),
54
- isOfficial: account.isOfficial
55
- })));
32
+ return this.program.account.market
33
+ .all()
34
+ .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarket)(account, publicKey)));
56
35
  });
57
36
  }
58
37
  getMarketByAddress(address) {
59
38
  return __awaiter(this, void 0, void 0, function* () {
60
39
  const account = yield this.program.account.market.fetch(address);
61
- return {
62
- bump: account.bump,
63
- address: address.toString(),
64
- authority: account.authority.toString(),
65
- marketId: account.marketId.toString(),
66
- name: account.name,
67
- hypePrice: account.hypePrice.toString(),
68
- flopPrice: account.flopPrice.toString(),
69
- hypeLiquidity: account.hypeLiquidity.toString(),
70
- flopLiquidity: account.flopLiquidity.toString(),
71
- totalHypeShares: account.totalHypeShares.toString(),
72
- totalFlopShares: account.totalFlopShares.toString(),
73
- totalVolume: account.totalVolume.toString(),
74
- mint: account.mint.toString(),
75
- ts: account.ts.toString(),
76
- updateTs: account.updateTs.toString(),
77
- openOrdersCount: account.openOrdersCount.toString(),
78
- nextOrderId: account.nextOrderId.toString(),
79
- feeBps: account.feeBps,
80
- feeVault: account.feeVault.toBase58(),
81
- isActive: account.isActive,
82
- marketPrice: account.marketPrice.toString(),
83
- isOfficial: account.isOfficial
84
- };
40
+ return (0, helpers_1.accountToMarket)(account, address);
85
41
  });
86
42
  }
87
43
  /**
@@ -21,7 +21,28 @@ export type Market = {
21
21
  isActive: boolean;
22
22
  marketPrice: string;
23
23
  isOfficial: boolean;
24
+ resolvedQuestions: ResolvedQuestion[];
25
+ currentQuestionId: string;
26
+ currentQuestionStart: string;
27
+ currentQuestionEnd: string;
28
+ currentQuestion: string;
24
29
  };
30
+ export type ResolvedQuestion = {
31
+ question: string;
32
+ startTime: string;
33
+ endTime: string;
34
+ hypeLiquidity: string;
35
+ flopLiquidity: string;
36
+ winningDirection: WinningDirection;
37
+ marketPrice: string;
38
+ finalHypePrice: string;
39
+ finalFlopPrice: string;
40
+ };
41
+ export declare enum WinningDirection {
42
+ Hype = "Hype",
43
+ Flop = "Flop",
44
+ None = "None"
45
+ }
25
46
  export type OrderDirection = {
26
47
  hype: {};
27
48
  } | {
@@ -1,2 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WinningDirection = void 0;
4
+ var WinningDirection;
5
+ (function (WinningDirection) {
6
+ WinningDirection["Hype"] = "Hype";
7
+ WinningDirection["Flop"] = "Flop";
8
+ WinningDirection["None"] = "None";
9
+ })(WinningDirection || (exports.WinningDirection = WinningDirection = {}));
@@ -1,7 +1,10 @@
1
1
  import { Stake, StakeVault } from './../types/stake';
2
2
  import { User } from './../types';
3
+ import { Market } from '../types/trade';
4
+ import { PublicKey } from '@solana/web3.js';
3
5
  export declare const encodeString: (value: string, alloc?: number) => number[];
4
6
  export declare const decodeString: (bytes: number[]) => string;
5
7
  export declare const formatStakeVault: (stakeVault: any) => StakeVault;
6
8
  export declare const formatStake: (stake: any) => Stake;
7
9
  export declare const formatUser: (user: any) => User;
10
+ export declare const accountToMarket: (account: any, address: PublicKey) => Market;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.accountToMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
4
+ const trade_1 = require("../types/trade");
4
5
  const encodeString = (value, alloc = 32) => {
5
6
  const buffer = Buffer.alloc(alloc);
6
7
  buffer.fill(value);
@@ -62,3 +63,50 @@ const formatUser = (user) => {
62
63
  };
63
64
  };
64
65
  exports.formatUser = formatUser;
66
+ const accountToMarket = (account, address) => {
67
+ return {
68
+ bump: account.bump,
69
+ address: address.toString(),
70
+ authority: account.authority.toString(),
71
+ marketId: account.marketId.toString(),
72
+ name: account.name,
73
+ hypePrice: account.hypePrice.toString(),
74
+ flopPrice: account.flopPrice.toString(),
75
+ hypeLiquidity: account.hypeLiquidity.toString(),
76
+ flopLiquidity: account.flopLiquidity.toString(),
77
+ totalHypeShares: account.totalHypeShares.toString(),
78
+ totalFlopShares: account.totalFlopShares.toString(),
79
+ totalVolume: account.totalVolume.toString(),
80
+ mint: account.mint.toString(),
81
+ ts: account.ts.toString(),
82
+ updateTs: account.updateTs.toString(),
83
+ openOrdersCount: account.openOrdersCount.toString(),
84
+ nextOrderId: account.nextOrderId.toString(),
85
+ feeBps: account.feeBps,
86
+ feeVault: account.feeVault.toBase58(),
87
+ isActive: account.isActive,
88
+ marketPrice: account.marketPrice.toString(),
89
+ isOfficial: account.isOfficial,
90
+ resolvedQuestions: account.resolvedQuestions.map(accountToResolvedQuestion),
91
+ currentQuestionId: account.currentQuestionId.toString(),
92
+ currentQuestionStart: account.currentQuestionStart.toString(),
93
+ currentQuestionEnd: account.currentQuestionEnd.toString(),
94
+ currentQuestion: Buffer.from(account.currentQuestion)
95
+ .toString()
96
+ .replace(/\0+$/, '')
97
+ };
98
+ };
99
+ exports.accountToMarket = accountToMarket;
100
+ const accountToResolvedQuestion = (question) => {
101
+ return {
102
+ question: Buffer.from(question.question).toString().replace(/\0+$/, ''),
103
+ startTime: question.startTime.toString(),
104
+ endTime: question.endTime.toString(),
105
+ hypeLiquidity: question.hypeLiquidity.toString(),
106
+ flopLiquidity: question.flopLiquidity.toString(),
107
+ winningDirection: trade_1.WinningDirection[question.winningDirection],
108
+ marketPrice: question.marketPrice.toString(),
109
+ finalHypePrice: question.finalHypePrice.toString(),
110
+ finalFlopPrice: question.finalFlopPrice.toString()
111
+ };
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.7.0-beta.devnet",
3
+ "version": "0.7.1-beta.devnet",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",