@triadxyz/triad-protocol 4.2.4 → 4.2.6
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/market.d.ts +7 -0
- package/dist/market.js +22 -0
- package/dist/predictor.d.ts +6 -1
- package/dist/predictor.js +22 -2
- package/dist/trade.js +12 -9
- package/dist/types/customer.d.ts +2 -0
- package/dist/types/idl_triad_protocol.json +1 -14
- package/dist/types/triad_protocol.d.ts +0 -13
- package/dist/utils/helpers.js +3 -1
- package/dist/utils/pda.d.ts +1 -1
- package/dist/utils/pda.js +5 -5
- package/package.json +1 -1
package/dist/market.d.ts
CHANGED
|
@@ -160,4 +160,11 @@ export default class Market {
|
|
|
160
160
|
* @param market.poolId - The ID of the pool
|
|
161
161
|
*/
|
|
162
162
|
createAndResolveMarket(toResolve: UpdateMarketWinningDirectionArgs['markets'][0], market: CreateMarketArgs['markets'][0], customer: PublicKey): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @param marketId
|
|
166
|
+
* @param usdcMint
|
|
167
|
+
* @returns
|
|
168
|
+
*/
|
|
169
|
+
migrateUSDC(marketIds: number[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
163
170
|
}
|
package/dist/market.js
CHANGED
|
@@ -567,5 +567,27 @@ class Market {
|
|
|
567
567
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
568
568
|
});
|
|
569
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
*
|
|
572
|
+
* @param marketId
|
|
573
|
+
* @param usdcMint
|
|
574
|
+
* @returns
|
|
575
|
+
*/
|
|
576
|
+
migrateUSDC(marketIds) {
|
|
577
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
578
|
+
const ixs = [];
|
|
579
|
+
for (const marketId of marketIds) {
|
|
580
|
+
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
581
|
+
ixs.push(yield this.program.methods
|
|
582
|
+
.migrateUsdc()
|
|
583
|
+
.accounts({
|
|
584
|
+
signer: this.program.provider.publicKey,
|
|
585
|
+
market: marketPDA
|
|
586
|
+
})
|
|
587
|
+
.instruction());
|
|
588
|
+
}
|
|
589
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
590
|
+
});
|
|
591
|
+
}
|
|
570
592
|
}
|
|
571
593
|
exports.default = Market;
|
package/dist/predictor.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export default class Predictor {
|
|
|
13
13
|
* @param customerId - Customer ID
|
|
14
14
|
*/
|
|
15
15
|
getPredictor(authority: PublicKey, customerId: number): Promise<PredictorType>;
|
|
16
|
+
createPredictor(users: {
|
|
17
|
+
authority: PublicKey;
|
|
18
|
+
refer: string;
|
|
19
|
+
customerId: number;
|
|
20
|
+
}[]): Promise<void>;
|
|
16
21
|
/**
|
|
17
22
|
* Get User Orders
|
|
18
23
|
* @param wallet - User wallet PublicKey
|
|
@@ -49,7 +54,7 @@ export default class Predictor {
|
|
|
49
54
|
* Withdraw
|
|
50
55
|
* @param args.authority - Authority of the withdraw
|
|
51
56
|
* @param args.amount - Amount to deposit
|
|
52
|
-
* @param args.customerId - Customer ID
|
|
57
|
+
* @param args.customerId - Customer ID
|
|
53
58
|
*/
|
|
54
59
|
withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
55
60
|
/**
|
package/dist/predictor.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
16
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
16
17
|
const constants_1 = require("./utils/constants");
|
|
17
18
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
@@ -47,6 +48,24 @@ class Predictor {
|
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
50
|
}
|
|
51
|
+
createPredictor(users) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
let ixs = [];
|
|
54
|
+
for (const user of users) {
|
|
55
|
+
ixs.push(yield this.program.methods
|
|
56
|
+
.createPredictor({
|
|
57
|
+
customerId: user.customerId,
|
|
58
|
+
refer: new web3_js_1.PublicKey(user.refer)
|
|
59
|
+
})
|
|
60
|
+
.accounts({
|
|
61
|
+
signer: user.authority,
|
|
62
|
+
payer: this.rpcOptions.payer
|
|
63
|
+
})
|
|
64
|
+
.instruction());
|
|
65
|
+
}
|
|
66
|
+
yield (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
50
69
|
/**
|
|
51
70
|
* Get User Orders
|
|
52
71
|
* @param wallet - User wallet PublicKey
|
|
@@ -107,7 +126,8 @@ class Predictor {
|
|
|
107
126
|
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, wallet, customerId);
|
|
108
127
|
return orders
|
|
109
128
|
.map((order) => (0, helpers_1.formatBookOrder)(order, marketId))
|
|
110
|
-
.filter((order) => order.authority === predictorPDA.toBase58()
|
|
129
|
+
.filter((order) => (order.authority === predictorPDA.toBase58() ||
|
|
130
|
+
order.authority === wallet.toBase58()) &&
|
|
111
131
|
order.linkedBookOrderId === constants_1.BOOK_ORDER_NULL.toString());
|
|
112
132
|
});
|
|
113
133
|
}
|
|
@@ -151,7 +171,7 @@ class Predictor {
|
|
|
151
171
|
* Withdraw
|
|
152
172
|
* @param args.authority - Authority of the withdraw
|
|
153
173
|
* @param args.amount - Amount to deposit
|
|
154
|
-
* @param args.customerId - Customer ID
|
|
174
|
+
* @param args.customerId - Customer ID
|
|
155
175
|
*/
|
|
156
176
|
withdraw({ authority, amount, customerId }) {
|
|
157
177
|
return __awaiter(this, void 0, void 0, function* () {
|
package/dist/trade.js
CHANGED
|
@@ -85,7 +85,7 @@ class Trade {
|
|
|
85
85
|
predictor: predictorPDA,
|
|
86
86
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
87
87
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
88
|
-
predictorOrder: (0, pda_1.
|
|
88
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
89
89
|
})
|
|
90
90
|
.instruction());
|
|
91
91
|
}
|
|
@@ -115,7 +115,7 @@ class Trade {
|
|
|
115
115
|
signer: this.program.provider.publicKey,
|
|
116
116
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
117
117
|
predictor: predictorPDA,
|
|
118
|
-
predictorOrder: (0, pda_1.
|
|
118
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection)),
|
|
119
119
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
|
|
120
120
|
})
|
|
121
121
|
.instruction());
|
|
@@ -174,7 +174,7 @@ class Trade {
|
|
|
174
174
|
predictor: predictorPDA,
|
|
175
175
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
176
176
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
177
|
-
predictorOrder: (0, pda_1.
|
|
177
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
178
178
|
})
|
|
179
179
|
.instruction());
|
|
180
180
|
}
|
|
@@ -220,6 +220,7 @@ class Trade {
|
|
|
220
220
|
if (usdcAmount.lte(new bn_js_1.default(0)))
|
|
221
221
|
continue;
|
|
222
222
|
const oppositeOrderDirection = (0, helpers_1.getOppositeOrderDirectionEncoded)(orderDirection);
|
|
223
|
+
const oppositePredictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customer.id);
|
|
223
224
|
ixs.push(yield this.program.methods
|
|
224
225
|
.marketBidOrder({
|
|
225
226
|
amount: new bn_js_1.default(usdcAmount),
|
|
@@ -232,13 +233,13 @@ class Trade {
|
|
|
232
233
|
signer: this.program.provider.publicKey,
|
|
233
234
|
payer: this.rpcOptions.payer,
|
|
234
235
|
predictor: predictorPDA,
|
|
235
|
-
oppositePredictor:
|
|
236
|
+
oppositePredictor: oppositePredictorPDA,
|
|
236
237
|
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
237
238
|
market: marketPDA,
|
|
238
239
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
239
240
|
customer: customer.address,
|
|
240
|
-
predictorOrder: (0, pda_1.
|
|
241
|
-
oppositePredictorOrder: (0, pda_1.
|
|
241
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
242
|
+
oppositePredictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, oppositePredictorPDA, marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
|
|
242
243
|
})
|
|
243
244
|
.instruction());
|
|
244
245
|
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
@@ -285,6 +286,7 @@ class Trade {
|
|
|
285
286
|
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500, customer.marketFeeBps);
|
|
286
287
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
287
288
|
amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
|
|
289
|
+
const oppositePredictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customer.id);
|
|
288
290
|
ixs.push(yield this.program.methods
|
|
289
291
|
.marketAskOrder({
|
|
290
292
|
shares: new bn_js_1.default(sharesToSell),
|
|
@@ -294,12 +296,13 @@ class Trade {
|
|
|
294
296
|
.accounts({
|
|
295
297
|
signer: this.program.provider.publicKey,
|
|
296
298
|
predictor: predictorPDA,
|
|
299
|
+
oppositePredictor: oppositePredictorPDA,
|
|
297
300
|
market: marketPDA,
|
|
298
301
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
299
302
|
customer: customer.address,
|
|
300
303
|
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
301
|
-
predictorOrder: (0, pda_1.
|
|
302
|
-
oppositePredictorOrder: (0, pda_1.
|
|
304
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
305
|
+
oppositePredictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, oppositePredictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection))
|
|
303
306
|
})
|
|
304
307
|
.instruction());
|
|
305
308
|
}
|
|
@@ -328,7 +331,7 @@ class Trade {
|
|
|
328
331
|
predictor: predictorPDA,
|
|
329
332
|
customer: (0, pda_1.getCustomerPDA)(this.program.programId, order.customerId),
|
|
330
333
|
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
331
|
-
predictorOrder: (0, pda_1.
|
|
334
|
+
predictorOrder: (0, pda_1.getPredictorOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
332
335
|
})
|
|
333
336
|
.instruction());
|
|
334
337
|
}
|
package/dist/types/customer.d.ts
CHANGED
|
@@ -1389,20 +1389,7 @@
|
|
|
1389
1389
|
},
|
|
1390
1390
|
{
|
|
1391
1391
|
"name": "market",
|
|
1392
|
-
"writable": true
|
|
1393
|
-
"pda": {
|
|
1394
|
-
"seeds": [
|
|
1395
|
-
{
|
|
1396
|
-
"kind": "const",
|
|
1397
|
-
"value": [109, 97, 114, 107, 101, 116]
|
|
1398
|
-
},
|
|
1399
|
-
{
|
|
1400
|
-
"kind": "account",
|
|
1401
|
-
"path": "market.market_id",
|
|
1402
|
-
"account": "MarketV2"
|
|
1403
|
-
}
|
|
1404
|
-
]
|
|
1405
|
-
}
|
|
1392
|
+
"writable": true
|
|
1406
1393
|
},
|
|
1407
1394
|
{
|
|
1408
1395
|
"name": "mint",
|
|
@@ -1829,19 +1829,6 @@ export type TriadProtocol = {
|
|
|
1829
1829
|
{
|
|
1830
1830
|
name: 'market';
|
|
1831
1831
|
writable: true;
|
|
1832
|
-
pda: {
|
|
1833
|
-
seeds: [
|
|
1834
|
-
{
|
|
1835
|
-
kind: 'const';
|
|
1836
|
-
value: [109, 97, 114, 107, 101, 116];
|
|
1837
|
-
},
|
|
1838
|
-
{
|
|
1839
|
-
kind: 'account';
|
|
1840
|
-
path: 'market.market_id';
|
|
1841
|
-
account: 'marketV2';
|
|
1842
|
-
}
|
|
1843
|
-
];
|
|
1844
|
-
};
|
|
1845
1832
|
},
|
|
1846
1833
|
{
|
|
1847
1834
|
name: 'mint';
|
package/dist/utils/helpers.js
CHANGED
|
@@ -153,7 +153,9 @@ const formatCustomer = (account, publicKey) => {
|
|
|
153
153
|
marketFeeBps: account.marketFeeBps,
|
|
154
154
|
payoutFeeBps: account.payoutFeeBps,
|
|
155
155
|
isVerified: account.isVerified,
|
|
156
|
-
address: publicKey.toString()
|
|
156
|
+
address: publicKey.toString(),
|
|
157
|
+
feeAvailable: account.feeAvailable.toNumber() / Math.pow(10, 6),
|
|
158
|
+
feeClaimed: account.feeClaimed.toNumber() / Math.pow(10, 6)
|
|
157
159
|
};
|
|
158
160
|
};
|
|
159
161
|
exports.formatCustomer = formatCustomer;
|
package/dist/utils/pda.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ export declare const getNftPDA: (programId: PublicKey, number: number) => Public
|
|
|
11
11
|
export declare const getPoseidonPDA: (programId: PublicKey, number: number) => PublicKey;
|
|
12
12
|
export declare const getClaimVaultPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
13
13
|
export declare const getClaimedUserPDA: (programId: PublicKey, claimVault: PublicKey, user: PublicKey) => PublicKey;
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const getPredictorOrderPDA: (programId: PublicKey, predictor: PublicKey, marketId: number, orderDirection: OrderDirection) => PublicKey;
|
|
15
15
|
export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customerId: number) => PublicKey;
|
|
16
16
|
export declare const getCentralPDA: (programId: PublicKey) => PublicKey;
|
package/dist/utils/pda.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCentralPDA = exports.getPredictorPDA = exports.
|
|
6
|
+
exports.getCentralPDA = exports.getPredictorPDA = exports.getPredictorOrderPDA = exports.getClaimedUserPDA = exports.getClaimVaultPDA = exports.getPoseidonPDA = exports.getNftPDA = exports.getCollectionPDA = exports.getStakePDA = exports.getPoolPDA = exports.getCustomerPDA = exports.getOrderBookPDA = exports.getMarketPDA = exports.getTokenATA = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -52,18 +52,18 @@ const getClaimedUserPDA = (programId, claimVault, user) => {
|
|
|
52
52
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('claimed_user'), claimVault.toBuffer(), user.toBuffer()], programId)[0];
|
|
53
53
|
};
|
|
54
54
|
exports.getClaimedUserPDA = getClaimedUserPDA;
|
|
55
|
-
const
|
|
55
|
+
const getPredictorOrderPDA = (programId, predictor, marketId, orderDirection) => {
|
|
56
56
|
let enumOrderDirection = 0;
|
|
57
57
|
if (orderDirection === types_1.OrderDirection.FLOP)
|
|
58
58
|
enumOrderDirection = 1;
|
|
59
59
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
60
|
-
Buffer.from('
|
|
61
|
-
|
|
60
|
+
Buffer.from('predictor_order'),
|
|
61
|
+
predictor.toBuffer(),
|
|
62
62
|
new bn_js_1.default(marketId).toArrayLike(Buffer, 'le', 8),
|
|
63
63
|
new bn_js_1.default(enumOrderDirection).toArrayLike(Buffer, 'le', 1)
|
|
64
64
|
], programId)[0];
|
|
65
65
|
};
|
|
66
|
-
exports.
|
|
66
|
+
exports.getPredictorOrderPDA = getPredictorOrderPDA;
|
|
67
67
|
const getPredictorPDA = (programId, authority, customerId) => {
|
|
68
68
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
69
69
|
Buffer.from('predictor'),
|