@triadxyz/triad-protocol 4.0.1 → 4.0.2

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,39 @@
1
+ /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { Program } from '@coral-xyz/anchor';
4
+ import { TriadProtocol } from './types/triad_protocol';
5
+ import { RpcOptions } from './types';
6
+ import { CreateCustomerArgs, UpdateCustomerFeeArgs } from './types/customer';
7
+ export default class Customer {
8
+ private program;
9
+ private rpcOptions;
10
+ constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
11
+ /**
12
+ * Get Next Customer ID
13
+ */
14
+ nextCustomerId(): Promise<number>;
15
+ /**
16
+ * Get Costumer By Wallet Address
17
+ * @param wallet - The wallet address of the customer
18
+ */
19
+ getCustomerByWallet(wallet: PublicKey): Promise<import("@triadxyz/triad-protocol").Customer>;
20
+ /**
21
+ * Get Customer By ID
22
+ * @param customerId - The ID of the customer
23
+ */
24
+ getCustomerById(customerId: number): Promise<import("@triadxyz/triad-protocol").Customer>;
25
+ /**
26
+ * Create Customer
27
+ * @param args.id - The ID of the customer
28
+ * @param args.name - The name of the customer
29
+ * @param args.authority - The authority of the customer
30
+ * @param args.feeRecipient - The fee recipient of the customer
31
+ */
32
+ createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
33
+ /**
34
+ * Update Customer Fee
35
+ * @param customerId - Customer ID
36
+ * @param feeBps - Fee in basis points
37
+ */
38
+ updateCustomerFee({ customerId, feeBps, feeRecipient }: UpdateCustomerFeeArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
39
+ }
@@ -0,0 +1,98 @@
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 sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
16
+ const triad_protocol_1 = require("@triadxyz/triad-protocol");
17
+ class Customer {
18
+ constructor(program, rpcOptions) {
19
+ this.program = program;
20
+ this.rpcOptions = rpcOptions;
21
+ }
22
+ /**
23
+ * Get Next Customer ID
24
+ */
25
+ nextCustomerId() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const customers = yield this.program.account.customer.all();
28
+ return customers.length + 1;
29
+ });
30
+ }
31
+ /**
32
+ * Get Costumer By Wallet Address
33
+ * @param wallet - The wallet address of the customer
34
+ */
35
+ getCustomerByWallet(wallet) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const [customer] = yield this.program.account.customer.all([
38
+ {
39
+ memcmp: {
40
+ offset: 10 + 1,
41
+ bytes: wallet.toBase58()
42
+ }
43
+ }
44
+ ]);
45
+ return (0, triad_protocol_1.formatCustomer)(customer.account, customer.publicKey);
46
+ });
47
+ }
48
+ /**
49
+ * Get Customer By ID
50
+ * @param customerId - The ID of the customer
51
+ */
52
+ getCustomerById(customerId) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const customerPDA = (0, triad_protocol_1.getCustomerPDA)(this.program.programId, customerId);
55
+ const customer = yield this.program.account.customer.fetch(customerPDA, this.rpcOptions.commitment);
56
+ return (0, triad_protocol_1.formatCustomer)(customer, customerPDA);
57
+ });
58
+ }
59
+ /**
60
+ * Create Customer
61
+ * @param args.id - The ID of the customer
62
+ * @param args.name - The name of the customer
63
+ * @param args.authority - The authority of the customer
64
+ * @param args.feeRecipient - The fee recipient of the customer
65
+ */
66
+ createCustomer({ id, name, authority, feeRecipient }) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const ixs = [
69
+ yield this.program.methods
70
+ .createCustomer({ id, name, authority, feeRecipient })
71
+ .accounts({
72
+ signer: this.program.provider.publicKey
73
+ })
74
+ .instruction()
75
+ ];
76
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
77
+ });
78
+ }
79
+ /**
80
+ * Update Customer Fee
81
+ * @param customerId - Customer ID
82
+ * @param feeBps - Fee in basis points
83
+ */
84
+ updateCustomerFee({ customerId, feeBps, feeRecipient }) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const ixs = [
87
+ yield this.program.methods
88
+ .updateCustomerFee({ id: customerId, feeBps, feeRecipient })
89
+ .accounts({
90
+ signer: this.program.provider.publicKey
91
+ })
92
+ .instruction()
93
+ ];
94
+ return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
95
+ });
96
+ }
97
+ }
98
+ exports.default = Customer;
package/dist/index.d.ts CHANGED
@@ -2,10 +2,17 @@
2
2
  import { Connection, PublicKey } from '@solana/web3.js';
3
3
  import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
4
4
  import { TriadProtocol as TriadProtocolIDL } from './types/triad_protocol';
5
- import { CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, BookOrder, MarketAskOrderArgs, RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, OrderDirectionEncoded, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs } from './types';
5
+ import { RpcOptions, CreateMarketArgs, CreatePoolArgs, UpdateMarketWinningDirectionArgs, UpdateMarketPayoutArgs, UpdateMarketQuestionArgs, UpdateMarketEndArgs } from './types';
6
6
  import Stake from './stake';
7
7
  import Poseidon from './poseidon';
8
+ import Predictor from './predictor';
9
+ import Trade from './trade';
10
+ import Customer from './customer';
8
11
  export * from './types';
12
+ export * from './types/predictor';
13
+ export * from './types/stake';
14
+ export * from './types/trade';
15
+ export * from './types/customer';
9
16
  export * from './utils/helpers';
10
17
  export * from './utils/feeCalculator';
11
18
  export * from './utils/constants';
@@ -18,6 +25,9 @@ export default class TriadProtocol {
18
25
  provider: AnchorProvider;
19
26
  stake: Stake;
20
27
  poseidon: Poseidon;
28
+ predictor: Predictor;
29
+ trade: Trade;
30
+ customer: Customer;
21
31
  constructor(connection: Connection, wallet: Wallet, rpcOptions: RpcOptions);
22
32
  /**
23
33
  * Get User Orders
@@ -39,21 +49,11 @@ export default class TriadProtocol {
39
49
  * Get all User Book Orders
40
50
  * @param wallet - User wallet PublicKey
41
51
  */
42
- getUserBookOrders(wallet: PublicKey): Promise<BookOrder[]>;
52
+ getUserBookOrders(wallet: PublicKey): Promise<import("./types").BookOrder[]>;
43
53
  /**
44
54
  * Get User Book Orders By Market ID
45
55
  */
46
- getUserBookOrdersByMarketId(wallet: PublicKey, marketId: number): Promise<BookOrder[]>;
47
- /**
48
- * Get Costumer By Wallet Address
49
- * @param wallet - The wallet address of the customer
50
- */
51
- getCustomerByWallet(wallet: PublicKey): Promise<import("./types").Customer>;
52
- /**
53
- * Get Customer By ID
54
- * @param customerId - The ID of the customer
55
- */
56
- getCustomerById(customerId: number): Promise<import("./types").Customer>;
56
+ getUserBookOrdersByMarketId(wallet: PublicKey, marketId: number): Promise<import("./types").BookOrder[]>;
57
57
  /**
58
58
  * Get All Pools
59
59
  */
@@ -81,10 +81,6 @@ export default class TriadProtocol {
81
81
  * Get Current Market ID
82
82
  */
83
83
  nextMarketId(): Promise<number>;
84
- /**
85
- * Get Next Customer ID
86
- */
87
- nextCustomerId(): Promise<number>;
88
84
  /**
89
85
  * Get Next Pool ID
90
86
  */
@@ -156,110 +152,4 @@ export default class TriadProtocol {
156
152
  * @param question - Question
157
153
  */
158
154
  updatePoolQuestion(poolId: number, question: string): Promise<string | import("@solana/web3.js").VersionedTransaction>;
159
- /**
160
- * Payout Order
161
- * @param args.marketId - The ID of the Market
162
- * @param args.authority - The authority of the order
163
- * @param args.orderDirection - The direction of the Order to Payout
164
- */
165
- payoutOrder(orders: {
166
- marketId: number;
167
- orderDirection: OrderDirectionEncoded;
168
- authority: PublicKey;
169
- }[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
170
- /**
171
- * Create Customer
172
- * @param args.id - The ID of the customer
173
- * @param args.name - The name of the customer
174
- * @param args.authority - The authority of the customer
175
- * @param args.feeRecipient - The fee recipient of the customer
176
- */
177
- createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
178
- /**
179
- * Place Bid Order
180
- * @param args.orders - Array of orders to execute
181
- * @param args.orders.marketId - The ID of the Market
182
- * @param args.orders.amount - The amount of the Order
183
- * @param args.orders.price - The price of the Order
184
- * @param args.orders.orderDirection - The direction of the Order
185
- */
186
- placeBidOrder({ orders }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
187
- /**
188
- * Place Ask Order
189
- * @param args.orders - Array of orders to execute
190
- * @param args.orders.amount - The amount of the Order
191
- * @param args.orders.price - The price of the Order
192
- * @param args.orders.marketId - The Id from the market
193
- * @param args.orders.orderDirection - The direction of the Order
194
- */
195
- placeAskOrder({ orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
196
- /**
197
- * Cancel Bid Order
198
- * @param args.orders.bookOrderId - The ID of the Book Order
199
- * @param args.orders.marketId - The ID of the Market
200
- * @param args.orders.orderDirection - The direction of the Order
201
- */
202
- cancelBidOrder({ orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
203
- /**
204
- * Cancel Ask Order
205
- * @param args.orders.marketId - The ID of the Market
206
- * @param args.orders.authority - The authority of the order
207
- * @param args.orders.bookOrderId - The ID of the Book Order
208
- * @param args.orders.orderDirection - The direction of the Order
209
- */
210
- cancelAskOrder({ orders }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
211
- /**
212
- * Market Bid Order
213
- * @param args.marketId - The ID of the Market
214
- * @param args.amount - The amount of the Order
215
- * @param args.orderDirection - The direction of the Order
216
- */
217
- marketBidOrder({ marketId, amount, orderDirection }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
218
- /**
219
- * Market Ask Order
220
- * @param args.marketId - The ID of the Market
221
- * @param args.shares - The amount of shares to sell
222
- * @param args.bookOrderBidId - The ID of the Bid Order
223
- * @param args.orderDirection - The direction of the Order
224
- */
225
- marketAskOrder({ marketId, shares, orderDirection }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
226
- /**
227
- * Get Orders By Market ID
228
- * @param marketId - Market ID
229
- */
230
- getOrderBook(marketId: number): Promise<{
231
- marketId: number;
232
- rewardsAvailable: string;
233
- rewardsClaimed: string;
234
- spreadToReward: string;
235
- hype: {
236
- bid: BookOrder[];
237
- ask: BookOrder[];
238
- };
239
- flop: {
240
- bid: BookOrder[];
241
- ask: BookOrder[];
242
- };
243
- }>;
244
- /**
245
- * Update Customer Fee
246
- * @param customerId - Customer ID
247
- * @param feeBps - Fee in basis points
248
- */
249
- updateCustomerFee({ customerId, feeBps, feeRecipient }: {
250
- customerId: number;
251
- feeBps: number;
252
- feeRecipient: PublicKey | null;
253
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
254
- deposit({ authority, amount, refer, customer }: {
255
- authority: PublicKey;
256
- amount: number;
257
- refer?: PublicKey;
258
- customer?: number;
259
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
260
- withdraw({ authority, amount, customer }: {
261
- authority: PublicKey;
262
- amount: number;
263
- customer?: number;
264
- }): Promise<string | import("@solana/web3.js").VersionedTransaction>;
265
155
  }