@triadxyz/triad-protocol 1.6.7-beta-dev → 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,12 +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
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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokenProgram = 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
6
  const spl_token_1 = require("@solana/spl-token");
@@ -74,40 +74,45 @@ const formatMarket = (account, address) => {
74
74
  marketStart: account.marketStart.toString(),
75
75
  marketEnd: account.marketEnd.toString(),
76
76
  question: Buffer.from(account.question).toString().replace(/\0+$/, ''),
77
- nftHoldersFeeAvailable: account.nftHoldersFeeAvailable.toString(),
78
- nftHoldersFeeClaimed: account.nftHoldersFeeClaimed.toString(),
77
+ creatorFeeAvailable: account.creatorFeeAvailable.toString(),
78
+ creatorFeeClaimed: account.creatorFeeClaimed.toString(),
79
79
  marketFeeAvailable: account.marketFeeAvailable.toString(),
80
80
  marketFeeClaimed: account.marketFeeClaimed.toString(),
81
+ customerId: account.customerId ? account.customerId.toString() : null,
81
82
  winningDirection: trade_1.WinningDirection[Object.keys(account.winningDirection)[0].toUpperCase()],
82
- marketLiquidityAtStart: account.marketLiquidityAtStart.toString() > 0
83
- ? account.marketLiquidityAtStart.toString()
84
- : '500000000'
83
+ marketLiquidityAtStart: account.marketLiquidityAtStart.toString()
85
84
  };
86
85
  };
87
86
  exports.formatMarket = formatMarket;
88
- const formatOrder = (order) => {
87
+ const formatOrder = (order, account, authority) => {
89
88
  return {
90
89
  ts: order.ts.toString(),
91
90
  orderId: order.orderId.toString(),
92
- questionId: order.questionId.toString(),
91
+ filledShares: order.filledShares.toString(),
93
92
  marketId: order.marketId.toString(),
94
- status: order.status,
93
+ status: (0, exports.getOrderStatus)(order.status),
95
94
  price: order.price.toString(),
96
- totalAmount: order.totalAmount.toString(),
97
- totalShares: order.totalShares.toString(),
98
- orderType: order.orderType,
99
- direction: order.direction,
100
- 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
101
105
  };
102
106
  };
103
107
  exports.formatOrder = formatOrder;
104
- const formatUserTrade = (account, publicKey) => {
108
+ const formatUserTrade = (account, user) => {
105
109
  return {
106
- user: publicKey.toString(),
110
+ user: user.toString(),
111
+ authority: account.authority.toString(),
107
112
  totalDeposits: account.totalDeposits.toString(),
108
113
  totalWithdraws: account.totalWithdraws.toString(),
109
114
  openedOrders: account.openedOrders.toString(),
110
- orders: account.orders.map((order) => (0, exports.formatOrder)(order)),
115
+ orders: account.orders.map((order) => (0, exports.formatOrder)(order, user, account.authority)),
111
116
  nonce: account.nonce.toString(),
112
117
  isSubUser: account.isSubUser
113
118
  };
@@ -120,7 +125,7 @@ const calculateStakeRewards = (stake, multiplier) => {
120
125
  return 0;
121
126
  const collectionsMultiplier = multiplier * 150;
122
127
  const maxRank = 1633;
123
- const rank = 963;
128
+ const rank = 480;
124
129
  const rankWeight = (maxRank - rank + 1) / maxRank;
125
130
  const userStakedAmount = stake.mint === constants_1.TRD_MINT.toBase58()
126
131
  ? stake.amount
@@ -142,3 +147,44 @@ const getTokenProgram = (mint) => {
142
147
  return spl_token_1.TOKEN_PROGRAM_ID;
143
148
  };
144
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-dev",
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",
package/dist/wheel.d.ts DELETED
@@ -1,62 +0,0 @@
1
- import { AnchorProvider, Program } from '@coral-xyz/anchor';
2
- import { Keypair } from '@solana/web3.js';
3
- import { TriadProtocol } from './types/triad_protocol';
4
- import { RpcOptions } from './types';
5
- export default class Wheel {
6
- private program;
7
- private provider;
8
- constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
9
- /**
10
- * Add Whell Prize
11
- * @param args.rangeMin - Range min to get prize
12
- * @param args.rangeMax - Range max to get prize
13
- * @param args.prize - Prize number it's indentifier
14
- * @param args.availableQuantity - Amount available to get
15
- * @param args.amount - Amount to send
16
- *
17
- * @param options - RPC options
18
- *
19
- */
20
- addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }: {
21
- rangeMin: number;
22
- rangeMax: number;
23
- prize: number;
24
- availableQuantity: number;
25
- amount: number;
26
- }, options?: RpcOptions): Promise<string>;
27
- /**
28
- * Claim Wheel Token
29
- * @param amount - Amount of tokens to claim
30
- * @param verifier - Verifier keypair
31
- *
32
- * @param options - RPC options
33
- *
34
- */
35
- claimWheelToken(amount: number, verifier: Keypair, options?: RpcOptions): Promise<string>;
36
- /**
37
- * Spin Wheel
38
- * @param args.isSol - Whether to pay with SOL or token
39
- * @param args.verifier - Verifier keypair
40
- * @param args.prize - Prize number
41
- *
42
- * @param options - RPC options
43
- *
44
- */
45
- spinWheel(args: {
46
- isSol: boolean;
47
- prizes: number[];
48
- verifier: Keypair;
49
- }, options?: RpcOptions): Promise<string>;
50
- /**
51
- * Get Spin Wheel
52
- *
53
- */
54
- getSpinWheel(amount: number): Promise<number[]>;
55
- /**
56
- * Swap Wheel Token
57
- * @param amount - Amount of tokens to buy
58
- * @param options - RPC options
59
- *
60
- */
61
- swapWheelToken(amount: number, options?: RpcOptions): Promise<string>;
62
- }
package/dist/wheel.js DELETED
@@ -1,149 +0,0 @@
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
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const anchor_1 = require("@coral-xyz/anchor");
16
- const pda_1 = require("./utils/pda");
17
- const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
18
- const constants_1 = require("./utils/constants");
19
- const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
20
- class Wheel {
21
- constructor(program, provider) {
22
- this.program = program;
23
- this.provider = provider;
24
- }
25
- /**
26
- * Add Whell Prize
27
- * @param args.rangeMin - Range min to get prize
28
- * @param args.rangeMax - Range max to get prize
29
- * @param args.prize - Prize number it's indentifier
30
- * @param args.availableQuantity - Amount available to get
31
- * @param args.amount - Amount to send
32
- *
33
- * @param options - RPC options
34
- *
35
- */
36
- addWheelPrize({ rangeMin, rangeMax, prize, availableQuantity, amount }, options) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const method = this.program.methods
39
- .addWheelPrize({
40
- name: constants_1.VALENT_SPIN_NAME,
41
- rangeMin: new anchor_1.BN(rangeMin),
42
- rangeMax: new anchor_1.BN(rangeMax),
43
- prize: new anchor_1.BN(prize),
44
- availableQuantity: new anchor_1.BN(availableQuantity),
45
- amount: new anchor_1.BN(amount)
46
- })
47
- .accounts({
48
- signer: this.provider.wallet.publicKey
49
- });
50
- return (0, sendTransactionWithOptions_1.default)(method, options);
51
- });
52
- }
53
- /**
54
- * Claim Wheel Token
55
- * @param amount - Amount of tokens to claim
56
- * @param verifier - Verifier keypair
57
- *
58
- * @param options - RPC options
59
- *
60
- */
61
- claimWheelToken(amount, verifier, options) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const ix = yield this.program.methods
64
- .claimWheelToken({
65
- name: constants_1.VALENT_SPIN_NAME,
66
- amount: new anchor_1.BN(amount * Math.pow(10, 6))
67
- })
68
- .accounts({
69
- signer: this.provider.wallet.publicKey,
70
- verifier: verifier.publicKey,
71
- mint: constants_1.WHEEL_MINT
72
- })
73
- .instruction();
74
- return (0, sendVersionedTransaction_1.default)(this.provider, [ix], options, undefined, [], verifier);
75
- });
76
- }
77
- /**
78
- * Spin Wheel
79
- * @param args.isSol - Whether to pay with SOL or token
80
- * @param args.verifier - Verifier keypair
81
- * @param args.prize - Prize number
82
- *
83
- * @param options - RPC options
84
- *
85
- */
86
- spinWheel(args, options) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const wheelPDA = (0, pda_1.getWheelPDA)(this.program.programId, constants_1.VALENT_SPIN_NAME);
89
- let ixs = [];
90
- for (const prize of args.prizes) {
91
- ixs.push(yield this.program.methods
92
- .spinWheel({
93
- isSol: args.isSol,
94
- prize: new anchor_1.BN(prize)
95
- })
96
- .accounts({
97
- signer: this.provider.wallet.publicKey,
98
- verifier: constants_1.VERIFIER,
99
- wheel: wheelPDA,
100
- mint: constants_1.WHEEL_MINT
101
- })
102
- .instruction());
103
- }
104
- return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options, undefined, [], args.verifier);
105
- });
106
- }
107
- /**
108
- * Get Spin Wheel
109
- *
110
- */
111
- getSpinWheel(amount) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const [wheel] = yield this.program.account.wheel.all();
114
- const prizes = [];
115
- for (let i = 0; i < amount; i++) {
116
- const randomNumber = Math.floor(Math.random() * 1000000) + 1;
117
- const prize = wheel.account.prizes.find((p) => randomNumber >= p.rangeMin.toNumber() &&
118
- randomNumber <= p.rangeMax.toNumber() &&
119
- p.status.claimed);
120
- if (!prize) {
121
- prizes.push(999);
122
- }
123
- prizes.push(prize.prize.toNumber());
124
- }
125
- return prizes;
126
- });
127
- }
128
- /**
129
- * Swap Wheel Token
130
- * @param amount - Amount of tokens to buy
131
- * @param options - RPC options
132
- *
133
- */
134
- swapWheelToken(amount, options) {
135
- return __awaiter(this, void 0, void 0, function* () {
136
- const method = this.program.methods
137
- .swapWheelToken({
138
- name: constants_1.VALENT_SPIN_NAME,
139
- amount: new anchor_1.BN(amount)
140
- })
141
- .accounts({
142
- signer: this.provider.wallet.publicKey,
143
- mint: constants_1.WHEEL_MINT
144
- });
145
- return (0, sendTransactionWithOptions_1.default)(method, options);
146
- });
147
- }
148
- }
149
- exports.default = Wheel;