@triadxyz/triad-protocol 1.8.8-beta → 1.8.9-beta
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/trade.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import BN from 'bn.js';
|
|
|
7
7
|
export default class Trade {
|
|
8
8
|
private program;
|
|
9
9
|
private provider;
|
|
10
|
-
mint: PublicKey;
|
|
11
10
|
decimals: number;
|
|
12
11
|
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
13
12
|
/**
|
|
@@ -288,7 +287,7 @@ export default class Trade {
|
|
|
288
287
|
* @param options - RPC options
|
|
289
288
|
*
|
|
290
289
|
*/
|
|
291
|
-
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId }: PlaceOrderArgs, options?: RpcOptions): Promise<string>;
|
|
290
|
+
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }: PlaceOrderArgs, options?: RpcOptions): Promise<string>;
|
|
292
291
|
/**
|
|
293
292
|
* Cancel Order
|
|
294
293
|
* @param args.marketId - The ID of the Market
|
package/dist/trade.js
CHANGED
|
@@ -21,11 +21,11 @@ const trade_2 = require("./utils/pda/trade");
|
|
|
21
21
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
22
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
23
23
|
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
24
|
+
const pda_1 = require("./utils/pda");
|
|
24
25
|
class Trade {
|
|
25
26
|
constructor(program, provider) {
|
|
26
27
|
this.program = program;
|
|
27
28
|
this.provider = provider;
|
|
28
|
-
this.mint = constants_1.TRD_MINT;
|
|
29
29
|
this.decimals = constants_1.TRD_DECIMALS; // We're using only TRD or USDC so we can use the same decimals 6
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -196,7 +196,7 @@ class Trade {
|
|
|
196
196
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
|
|
197
197
|
signer: this.provider.publicKey,
|
|
198
198
|
market: marketPDA,
|
|
199
|
-
mint:
|
|
199
|
+
mint: constants_1.TRD_MINT,
|
|
200
200
|
userTrade: userTradePDA
|
|
201
201
|
}), options);
|
|
202
202
|
});
|
|
@@ -424,12 +424,11 @@ class Trade {
|
|
|
424
424
|
* @param options - RPC options
|
|
425
425
|
*
|
|
426
426
|
*/
|
|
427
|
-
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId }, options) {
|
|
427
|
+
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }, options) {
|
|
428
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
429
|
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
430
430
|
const ixs = [];
|
|
431
431
|
const { userTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
|
|
432
|
-
console.log(userTradePDA);
|
|
433
432
|
if (userTradeIxs.length > 0) {
|
|
434
433
|
ixs.push(...userTradeIxs);
|
|
435
434
|
}
|
|
@@ -450,6 +449,11 @@ class Trade {
|
|
|
450
449
|
.instruction());
|
|
451
450
|
}
|
|
452
451
|
if (Object.keys(orderSide)[0] === 'ask' && bidOrderId) {
|
|
452
|
+
let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
453
|
+
if (bidNonce !== 0) {
|
|
454
|
+
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, bidNonce);
|
|
455
|
+
bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
456
|
+
}
|
|
453
457
|
ixs.push(yield this.program.methods
|
|
454
458
|
.placeAskOrder({
|
|
455
459
|
shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
|
|
@@ -460,7 +464,8 @@ class Trade {
|
|
|
460
464
|
.accounts({
|
|
461
465
|
signer: this.provider.publicKey,
|
|
462
466
|
market: marketPDA,
|
|
463
|
-
userTrade: userTradePDA
|
|
467
|
+
userTrade: userTradePDA,
|
|
468
|
+
bidUserTrade: bidUserTradePDA
|
|
464
469
|
})
|
|
465
470
|
.instruction());
|
|
466
471
|
}
|
|
@@ -501,7 +506,7 @@ class Trade {
|
|
|
501
506
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelAskOrder(new bn_js_1.default(orderId)).accounts({
|
|
502
507
|
signer: this.provider.publicKey,
|
|
503
508
|
market: marketPDA,
|
|
504
|
-
|
|
509
|
+
askUserTrade: userTradePDA,
|
|
505
510
|
bidUserTrade: bidUserTradePDA
|
|
506
511
|
}), options);
|
|
507
512
|
});
|
|
@@ -532,6 +537,7 @@ class Trade {
|
|
|
532
537
|
if (order.authority === this.provider.publicKey.toBase58()) {
|
|
533
538
|
continue;
|
|
534
539
|
}
|
|
540
|
+
console.log(order);
|
|
535
541
|
const orderPrice = Number(order.price);
|
|
536
542
|
const maxSharesForPrice = remainingUSDC / orderPrice;
|
|
537
543
|
const availableShares = Number(order.totalShares);
|
|
@@ -542,6 +548,7 @@ class Trade {
|
|
|
542
548
|
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), Number(order.userNonce));
|
|
543
549
|
sellerTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
544
550
|
}
|
|
551
|
+
const tokenProgram = (0, helpers_1.getTokenProgram)(mint);
|
|
545
552
|
ixs.push(yield this.program.methods
|
|
546
553
|
.marketBidOrder({
|
|
547
554
|
amount: new bn_js_1.default(usdcAmount),
|
|
@@ -554,8 +561,10 @@ class Trade {
|
|
|
554
561
|
buyerTrade,
|
|
555
562
|
sellerTrade: sellerTradePDA,
|
|
556
563
|
mint,
|
|
557
|
-
tokenProgram
|
|
558
|
-
sellerAuthority: new web3_js_1.PublicKey(order.authority)
|
|
564
|
+
tokenProgram,
|
|
565
|
+
sellerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
566
|
+
marketToAta: (0, pda_1.getTokenATA)(marketPDA, mint, tokenProgram),
|
|
567
|
+
userFromAta: (0, pda_1.getTokenATA)(this.provider.publicKey, mint, tokenProgram)
|
|
559
568
|
})
|
|
560
569
|
.instruction());
|
|
561
570
|
remainingUSDC -= usdcAmount;
|
|
@@ -74,15 +74,15 @@
|
|
|
74
74
|
"signer": true
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
"name": "
|
|
77
|
+
"name": "ask_user_trade",
|
|
78
78
|
"writable": true
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
"name": "
|
|
81
|
+
"name": "bid_user_trade",
|
|
82
82
|
"writable": true
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
"name": "
|
|
85
|
+
"name": "market",
|
|
86
86
|
"writable": true
|
|
87
87
|
},
|
|
88
88
|
{
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -80,15 +80,15 @@ export type TriadProtocol = {
|
|
|
80
80
|
signer: true;
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
name: '
|
|
83
|
+
name: 'askUserTrade';
|
|
84
84
|
writable: true;
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
name: '
|
|
87
|
+
name: 'bidUserTrade';
|
|
88
88
|
writable: true;
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
name: '
|
|
91
|
+
name: 'market';
|
|
92
92
|
writable: true;
|
|
93
93
|
},
|
|
94
94
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const getUserPositionPDA: (programId: PublicKey, wallet: PublicKey, ticker: PublicKey) => PublicKey;
|
|
3
|
-
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey) => PublicKey;
|
|
3
|
+
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey, program?: PublicKey) => PublicKey;
|
|
4
4
|
export declare const getWheelPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
5
5
|
export declare const getCollectionPDA: (programId: PublicKey, collectionSymbol: string) => PublicKey;
|
|
6
6
|
export declare const getNftPDA: (programId: PublicKey, number: number) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -11,8 +11,8 @@ const getUserPositionPDA = (programId, wallet, ticker) => {
|
|
|
11
11
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_position'), wallet.toBuffer(), ticker.toBuffer()], programId)[0];
|
|
12
12
|
};
|
|
13
13
|
exports.getUserPositionPDA = getUserPositionPDA;
|
|
14
|
-
const getTokenATA = (address, Mint) => {
|
|
15
|
-
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(),
|
|
14
|
+
const getTokenATA = (address, Mint, program = spl_token_1.TOKEN_2022_PROGRAM_ID) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(), program.toBytes(), Mint.toBytes()], new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
|
16
16
|
};
|
|
17
17
|
exports.getTokenATA = getTokenATA;
|
|
18
18
|
const getWheelPDA = (programId, name) => {
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triadxyz/triad-protocol",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9-beta",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"clean": "rimraf dist",
|
|
9
9
|
"build": "yarn run clean && tsc",
|
|
10
|
-
"prepublishOnly": "yarn build"
|
|
11
|
-
"test": "rimraf dist && tsc && node ./dist/local-test/index.js"
|
|
10
|
+
"prepublishOnly": "yarn build"
|
|
12
11
|
},
|
|
13
12
|
"publishConfig": {
|
|
14
13
|
"access": "public"
|