@triadxyz/triad-protocol 1.6.7-beta → 1.6.8-beta-dev

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.
@@ -3,6 +3,7 @@ export declare const STAKE_VAULT_NAME = "Triad Share 1";
3
3
  export declare const TRD_DECIMALS = 6;
4
4
  export declare const VERIFIER: PublicKey;
5
5
  export declare const TRD_MINT: PublicKey;
6
+ export declare const USDC_MINT_DEVNET: PublicKey;
6
7
  export declare const TRIAD_ADMIN: PublicKey;
7
8
  export declare const SOL_MINT: PublicKey;
8
9
  export declare const TICKET_CORE_COLLECTION: PublicKey;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.POSEIDON_COLLECTION_SYMBOL = exports.WHEEL_MINT = exports.VALENT_SPIN_NAME = exports.TICKET_CORE_COLLECTION = exports.SOL_MINT = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.VERIFIER = exports.TRD_DECIMALS = exports.STAKE_VAULT_NAME = void 0;
3
+ exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.POSEIDON_COLLECTION_SYMBOL = exports.WHEEL_MINT = exports.VALENT_SPIN_NAME = exports.TICKET_CORE_COLLECTION = exports.SOL_MINT = exports.TRIAD_ADMIN = exports.USDC_MINT_DEVNET = exports.TRD_MINT = exports.VERIFIER = exports.TRD_DECIMALS = exports.STAKE_VAULT_NAME = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.STAKE_VAULT_NAME = 'Triad Share 1';
6
6
  exports.TRD_DECIMALS = 6;
7
7
  exports.VERIFIER = new web3_js_1.PublicKey('42n6BHufivUKrb5Bi6tXbMZvM8NHovrDLX1Rt5w2a919');
8
8
  exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV');
9
+ exports.USDC_MINT_DEVNET = new web3_js_1.PublicKey('4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU');
9
10
  exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
10
11
  exports.SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111112');
11
12
  exports.TICKET_CORE_COLLECTION = new web3_js_1.PublicKey('BaqopH1VXYUCT6VsojbTibVcd3k5jpGGT6296HFb6fVa');
@@ -1,11 +1,40 @@
1
1
  import { Stake, StakeVault } from './../types/stake';
2
- import { Market, Order, UserTrade } from '../types/trade';
2
+ import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, UserTrade } from '../types/trade';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  export declare const encodeString: (value: string, alloc?: number) => number[];
5
5
  export declare const decodeString: (bytes: number[]) => string;
6
6
  export declare const formatStakeVault: (stakeVault: any) => StakeVault;
7
7
  export declare const formatStake: (stake: any) => Stake;
8
8
  export declare const formatMarket: (account: any, address: PublicKey) => Market;
9
- export declare const formatOrder: (order: any) => Order;
10
- export declare const formatUserTrade: (account: any, publicKey: PublicKey) => UserTrade;
9
+ export declare const formatOrder: (order: any, account: PublicKey, authority: PublicKey) => Order;
10
+ export declare const formatUserTrade: (account: any, user: PublicKey) => UserTrade;
11
11
  export declare const calculateStakeRewards: (stake: Stake, multiplier: number) => number;
12
+ export declare const getTokenProgram: (mint: PublicKey) => PublicKey;
13
+ export declare const getOrderDirection: (direction: {
14
+ hype: {};
15
+ } | {
16
+ flop: {};
17
+ }) => OrderDirection;
18
+ export declare const getOrderType: (type: {
19
+ limit: {};
20
+ } | {
21
+ market: {};
22
+ }) => OrderType;
23
+ export declare const getOrderSide: (side: {
24
+ bid: {};
25
+ } | {
26
+ ask: {};
27
+ }) => OrderSide;
28
+ export declare const getOrderStatus: (status: {
29
+ init: {};
30
+ } | {
31
+ open: {};
32
+ } | {
33
+ closed: {};
34
+ } | {
35
+ claimed: {};
36
+ } | {
37
+ liquidated: {};
38
+ } | {
39
+ waiting: {};
40
+ }) => OrderStatus;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
4
4
  const trade_1 = require("../types/trade");
5
5
  const constants_1 = require("./constants");
6
+ const spl_token_1 = require("@solana/spl-token");
7
+ const spl_token_2 = require("@solana/spl-token");
6
8
  const encodeString = (value, alloc = 32) => {
7
9
  const buffer = Buffer.alloc(alloc, 32);
8
10
  buffer.write(value);
@@ -72,40 +74,45 @@ const formatMarket = (account, address) => {
72
74
  marketStart: account.marketStart.toString(),
73
75
  marketEnd: account.marketEnd.toString(),
74
76
  question: Buffer.from(account.question).toString().replace(/\0+$/, ''),
75
- nftHoldersFeeAvailable: account.nftHoldersFeeAvailable.toString(),
76
- nftHoldersFeeClaimed: account.nftHoldersFeeClaimed.toString(),
77
+ creatorFeeAvailable: account.creatorFeeAvailable.toString(),
78
+ creatorFeeClaimed: account.creatorFeeClaimed.toString(),
77
79
  marketFeeAvailable: account.marketFeeAvailable.toString(),
78
80
  marketFeeClaimed: account.marketFeeClaimed.toString(),
81
+ customerId: account.customerId ? account.customerId.toString() : null,
79
82
  winningDirection: trade_1.WinningDirection[Object.keys(account.winningDirection)[0].toUpperCase()],
80
- marketLiquidityAtStart: account.marketLiquidityAtStart.toString() > 0
81
- ? account.marketLiquidityAtStart.toString()
82
- : '500000000'
83
+ marketLiquidityAtStart: account.marketLiquidityAtStart.toString()
83
84
  };
84
85
  };
85
86
  exports.formatMarket = formatMarket;
86
- const formatOrder = (order) => {
87
+ const formatOrder = (order, account, authority) => {
87
88
  return {
88
89
  ts: order.ts.toString(),
89
90
  orderId: order.orderId.toString(),
90
- questionId: order.questionId.toString(),
91
+ filledShares: order.filledShares.toString(),
91
92
  marketId: order.marketId.toString(),
92
- status: order.status,
93
+ status: (0, exports.getOrderStatus)(order.status),
93
94
  price: order.price.toString(),
94
- totalAmount: order.totalAmount.toString(),
95
- totalShares: order.totalShares.toString(),
96
- orderType: order.orderType,
97
- direction: order.direction,
98
- userNonce: order.userNonce.toString()
95
+ amount: order.amount.toString(),
96
+ shares: order.shares.toString(),
97
+ orderType: (0, exports.getOrderType)(order.orderType),
98
+ direction: (0, exports.getOrderDirection)(order.orderDirection),
99
+ userNonce: order.userNonce.toString(),
100
+ orderSide: (0, exports.getOrderSide)(order.orderSide),
101
+ authority: authority.toString(),
102
+ account: account.toString(),
103
+ poseidon: order.poseidon ? order.poseidon.toString() : null,
104
+ linkedOrderId: order.linkedOrderId ? order.linkedOrderId.toString() : null
99
105
  };
100
106
  };
101
107
  exports.formatOrder = formatOrder;
102
- const formatUserTrade = (account, publicKey) => {
108
+ const formatUserTrade = (account, user) => {
103
109
  return {
104
- user: publicKey.toString(),
110
+ user: user.toString(),
111
+ authority: account.authority.toString(),
105
112
  totalDeposits: account.totalDeposits.toString(),
106
113
  totalWithdraws: account.totalWithdraws.toString(),
107
114
  openedOrders: account.openedOrders.toString(),
108
- orders: account.orders.map((order) => (0, exports.formatOrder)(order)),
115
+ orders: account.orders.map((order) => (0, exports.formatOrder)(order, user, account.authority)),
109
116
  nonce: account.nonce.toString(),
110
117
  isSubUser: account.isSubUser
111
118
  };
@@ -118,7 +125,7 @@ const calculateStakeRewards = (stake, multiplier) => {
118
125
  return 0;
119
126
  const collectionsMultiplier = multiplier * 150;
120
127
  const maxRank = 1633;
121
- const rank = 963;
128
+ const rank = 480;
122
129
  const rankWeight = (maxRank - rank + 1) / maxRank;
123
130
  const userStakedAmount = stake.mint === constants_1.TRD_MINT.toBase58()
124
131
  ? stake.amount
@@ -133,3 +140,51 @@ const calculateStakeRewards = (stake, multiplier) => {
133
140
  return (rewards + stake.available) / Math.pow(10, constants_1.TRD_DECIMALS);
134
141
  };
135
142
  exports.calculateStakeRewards = calculateStakeRewards;
143
+ const getTokenProgram = (mint) => {
144
+ if (mint.toBase58() === constants_1.TRD_MINT.toBase58()) {
145
+ return spl_token_2.TOKEN_2022_PROGRAM_ID;
146
+ }
147
+ return spl_token_1.TOKEN_PROGRAM_ID;
148
+ };
149
+ exports.getTokenProgram = getTokenProgram;
150
+ const getOrderDirection = (direction) => {
151
+ if (Object.keys(direction)[0] === 'hype') {
152
+ return trade_1.OrderDirection.HYPE;
153
+ }
154
+ return trade_1.OrderDirection.FLOP;
155
+ };
156
+ exports.getOrderDirection = getOrderDirection;
157
+ const getOrderType = (type) => {
158
+ if (Object.keys(type)[0] === 'limit') {
159
+ return trade_1.OrderType.LIMIT;
160
+ }
161
+ return trade_1.OrderType.MARKET;
162
+ };
163
+ exports.getOrderType = getOrderType;
164
+ const getOrderSide = (side) => {
165
+ if (Object.keys(side)[0] === 'bid') {
166
+ return trade_1.OrderSide.BID;
167
+ }
168
+ return trade_1.OrderSide.ASK;
169
+ };
170
+ exports.getOrderSide = getOrderSide;
171
+ const getOrderStatus = (status) => {
172
+ let currentStatus = Object.keys(status)[0];
173
+ switch (currentStatus) {
174
+ case 'init':
175
+ return trade_1.OrderStatus.INIT;
176
+ case 'open':
177
+ return trade_1.OrderStatus.OPEN;
178
+ case 'closed':
179
+ return trade_1.OrderStatus.CLOSED;
180
+ case 'claimed':
181
+ return trade_1.OrderStatus.CLAIMED;
182
+ case 'liquidated':
183
+ return trade_1.OrderStatus.LIQUIDATED;
184
+ case 'waiting':
185
+ return trade_1.OrderStatus.WAITING;
186
+ default:
187
+ throw new Error('Invalid order status');
188
+ }
189
+ };
190
+ exports.getOrderStatus = getOrderStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.6.7-beta",
3
+ "version": "1.6.8-beta-dev",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1 +0,0 @@
1
- export {};