@triadxyz/triad-protocol 3.0.0-beta → 3.0.1-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/index.d.ts +3 -1
- package/dist/index.js +38 -2
- package/dist/types/index.d.ts +3 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -387,6 +387,7 @@ export default class TriadProtocolClient {
|
|
|
387
387
|
* @param args.direction - The direction of the Order
|
|
388
388
|
* @param args.mint - The mint of the Order
|
|
389
389
|
* @param args.price - The price of the Order
|
|
390
|
+
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
390
391
|
*
|
|
391
392
|
* @param options - RPC options
|
|
392
393
|
*/
|
|
@@ -410,10 +411,11 @@ export default class TriadProtocolClient {
|
|
|
410
411
|
* @param args.orderId - The ID of the Order
|
|
411
412
|
* @param args.userNonce - The nonce of the user
|
|
412
413
|
* @param args.direction - The direction of the Order
|
|
414
|
+
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
413
415
|
*
|
|
414
416
|
* @param options - RPC options
|
|
415
417
|
*/
|
|
416
|
-
cancelBidOrder({ marketId, orderId, userNonce, mint, direction }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
418
|
+
cancelBidOrder({ marketId, orderId, userNonce, mint, direction, isTrdPayout, remainingShares, price }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
417
419
|
/**
|
|
418
420
|
* Cancel Ask Order
|
|
419
421
|
* @param args.marketId - The ID of the Market
|
package/dist/index.js
CHANGED
|
@@ -735,19 +735,38 @@ class TriadProtocolClient {
|
|
|
735
735
|
* @param args.direction - The direction of the Order
|
|
736
736
|
* @param args.mint - The mint of the Order
|
|
737
737
|
* @param args.price - The price of the Order
|
|
738
|
+
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
738
739
|
*
|
|
739
740
|
* @param options - RPC options
|
|
740
741
|
*/
|
|
741
742
|
placeBidOrder({ marketId, amount, direction, mint, price, isTrdPayout }, options) {
|
|
742
743
|
return __awaiter(this, void 0, void 0, function* () {
|
|
743
744
|
const ixs = [];
|
|
745
|
+
const addressLookupTableAccounts = [];
|
|
746
|
+
let amountInUSDC = new bn_js_1.default(amount * Math.pow(10, this.decimals));
|
|
747
|
+
if (isTrdPayout) {
|
|
748
|
+
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
749
|
+
connection: this.program.provider.connection,
|
|
750
|
+
wallet: this.program.provider.publicKey.toBase58(),
|
|
751
|
+
inToken: constants_1.TRD_MINT.toString(),
|
|
752
|
+
outToken: constants_1.USDC_MINT.toString(),
|
|
753
|
+
amount: Math.floor(amount)
|
|
754
|
+
});
|
|
755
|
+
if (swapIxs.length === 0) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
amountInUSDC = new bn_js_1.default(outAmount);
|
|
759
|
+
ixs.push(...setupInstructions);
|
|
760
|
+
ixs.push(...swapIxs);
|
|
761
|
+
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
762
|
+
}
|
|
744
763
|
const { userTradePDA, userTradeIxs } = yield this.getUserTradeNonce(marketId, Object.keys(direction)[0]);
|
|
745
764
|
if (userTradeIxs.length > 0) {
|
|
746
765
|
ixs.push(...userTradeIxs);
|
|
747
766
|
}
|
|
748
767
|
ixs.push(yield this.program.methods
|
|
749
768
|
.placeBidOrder({
|
|
750
|
-
amount:
|
|
769
|
+
amount: amountInUSDC,
|
|
751
770
|
price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
|
|
752
771
|
orderDirection: direction,
|
|
753
772
|
isTrdPayout
|
|
@@ -803,12 +822,14 @@ class TriadProtocolClient {
|
|
|
803
822
|
* @param args.orderId - The ID of the Order
|
|
804
823
|
* @param args.userNonce - The nonce of the user
|
|
805
824
|
* @param args.direction - The direction of the Order
|
|
825
|
+
* @param args.isTrdPayout - Whether to payout in TRD or not
|
|
806
826
|
*
|
|
807
827
|
* @param options - RPC options
|
|
808
828
|
*/
|
|
809
|
-
cancelBidOrder({ marketId, orderId, userNonce, mint, direction }, options) {
|
|
829
|
+
cancelBidOrder({ marketId, orderId, userNonce, mint, direction, isTrdPayout, remainingShares, price }, options) {
|
|
810
830
|
return __awaiter(this, void 0, void 0, function* () {
|
|
811
831
|
const ixs = [];
|
|
832
|
+
const addressLookupTableAccounts = [];
|
|
812
833
|
ixs.push(yield this.program.methods
|
|
813
834
|
.cancelBidOrder({
|
|
814
835
|
orderId: new bn_js_1.default(orderId),
|
|
@@ -823,6 +844,21 @@ class TriadProtocolClient {
|
|
|
823
844
|
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
824
845
|
})
|
|
825
846
|
.instruction());
|
|
847
|
+
if (isTrdPayout) {
|
|
848
|
+
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, setupInstructions } = yield (0, swap_1.swap)({
|
|
849
|
+
connection: this.program.provider.connection,
|
|
850
|
+
wallet: this.program.provider.publicKey.toBase58(),
|
|
851
|
+
inToken: constants_1.USDC_MINT.toString(),
|
|
852
|
+
outToken: constants_1.TRD_MINT.toString(),
|
|
853
|
+
amount: Math.floor((remainingShares * price) / Math.pow(10, this.decimals))
|
|
854
|
+
});
|
|
855
|
+
if (swapIxs.length === 0) {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
ixs.push(...setupInstructions);
|
|
859
|
+
ixs.push(...swapIxs);
|
|
860
|
+
addressLookupTableAccounts.push(...swapAddressLookupTableAccounts);
|
|
861
|
+
}
|
|
826
862
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
827
863
|
});
|
|
828
864
|
}
|
package/dist/types/index.d.ts
CHANGED