@triadxyz/triad-protocol 1.8.1-beta → 1.8.3-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.js +8 -2
- package/dist/types/idl_triad_protocol.json +161 -0
- package/dist/types/triad_protocol.d.ts +248 -0
- package/package.json +1 -1
package/dist/trade.js
CHANGED
|
@@ -522,11 +522,16 @@ class Trade {
|
|
|
522
522
|
const { userTradePDA: buyerTrade, ixs: userTradeIxs } = yield this.getUserTradeIxs();
|
|
523
523
|
const orderBook = yield this.getOrderBook(marketId);
|
|
524
524
|
let remainingUSDC = amount * Math.pow(10, this.decimals);
|
|
525
|
-
const orders = direction[0]
|
|
525
|
+
const orders = Object.keys(direction)[0] === 'hype'
|
|
526
|
+
? orderBook.hype.ask
|
|
527
|
+
: orderBook.flop.ask;
|
|
526
528
|
const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
|
|
527
529
|
for (const order of sortedOrders) {
|
|
528
530
|
if (remainingUSDC <= 0)
|
|
529
531
|
break;
|
|
532
|
+
if (order.authority === this.provider.publicKey.toBase58()) {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
530
535
|
const orderPrice = Number(order.price);
|
|
531
536
|
const maxSharesForPrice = remainingUSDC / orderPrice;
|
|
532
537
|
const availableShares = Number(order.totalShares);
|
|
@@ -548,7 +553,8 @@ class Trade {
|
|
|
548
553
|
buyerTrade,
|
|
549
554
|
sellerTrade: sellerTradePDA,
|
|
550
555
|
mint,
|
|
551
|
-
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
556
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint),
|
|
557
|
+
sellerAuthority: new web3_js_1.PublicKey(order.authority)
|
|
552
558
|
})
|
|
553
559
|
.instruction());
|
|
554
560
|
remainingUSDC -= usdcAmount;
|
|
@@ -736,6 +736,115 @@
|
|
|
736
736
|
],
|
|
737
737
|
"args": []
|
|
738
738
|
},
|
|
739
|
+
{
|
|
740
|
+
"name": "market_ask_order",
|
|
741
|
+
"discriminator": [189, 66, 162, 254, 3, 85, 152, 54],
|
|
742
|
+
"accounts": [
|
|
743
|
+
{
|
|
744
|
+
"name": "signer",
|
|
745
|
+
"writable": true,
|
|
746
|
+
"signer": true
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
"name": "squads",
|
|
750
|
+
"writable": true,
|
|
751
|
+
"address": "6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
"name": "seller_trade",
|
|
755
|
+
"writable": true
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
"name": "buyer_trade",
|
|
759
|
+
"writable": true
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
"name": "market",
|
|
763
|
+
"writable": true
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
"name": "mint",
|
|
767
|
+
"writable": true
|
|
768
|
+
},
|
|
769
|
+
{
|
|
770
|
+
"name": "user_from_ata",
|
|
771
|
+
"writable": true,
|
|
772
|
+
"pda": {
|
|
773
|
+
"seeds": [
|
|
774
|
+
{
|
|
775
|
+
"kind": "account",
|
|
776
|
+
"path": "signer"
|
|
777
|
+
},
|
|
778
|
+
{
|
|
779
|
+
"kind": "account",
|
|
780
|
+
"path": "token_program"
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
"kind": "account",
|
|
784
|
+
"path": "mint"
|
|
785
|
+
}
|
|
786
|
+
],
|
|
787
|
+
"program": {
|
|
788
|
+
"kind": "const",
|
|
789
|
+
"value": [
|
|
790
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
791
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
792
|
+
219, 233, 248, 89
|
|
793
|
+
]
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
},
|
|
797
|
+
{
|
|
798
|
+
"name": "market_ata",
|
|
799
|
+
"writable": true,
|
|
800
|
+
"pda": {
|
|
801
|
+
"seeds": [
|
|
802
|
+
{
|
|
803
|
+
"kind": "account",
|
|
804
|
+
"path": "market"
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
"kind": "account",
|
|
808
|
+
"path": "token_program"
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
"kind": "account",
|
|
812
|
+
"path": "mint"
|
|
813
|
+
}
|
|
814
|
+
],
|
|
815
|
+
"program": {
|
|
816
|
+
"kind": "const",
|
|
817
|
+
"value": [
|
|
818
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
819
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
820
|
+
219, 233, 248, 89
|
|
821
|
+
]
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"name": "token_program"
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
"name": "associated_token_program",
|
|
830
|
+
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
"name": "system_program",
|
|
834
|
+
"address": "11111111111111111111111111111111"
|
|
835
|
+
}
|
|
836
|
+
],
|
|
837
|
+
"args": [
|
|
838
|
+
{
|
|
839
|
+
"name": "args",
|
|
840
|
+
"type": {
|
|
841
|
+
"defined": {
|
|
842
|
+
"name": "MarketAskOrderArgs"
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
]
|
|
847
|
+
},
|
|
739
848
|
{
|
|
740
849
|
"name": "market_bid_order",
|
|
741
850
|
"discriminator": [145, 89, 7, 166, 85, 59, 48, 149],
|
|
@@ -822,6 +931,38 @@
|
|
|
822
931
|
}
|
|
823
932
|
}
|
|
824
933
|
},
|
|
934
|
+
{
|
|
935
|
+
"name": "seller_authority",
|
|
936
|
+
"writable": true
|
|
937
|
+
},
|
|
938
|
+
{
|
|
939
|
+
"name": "seller_to_ata",
|
|
940
|
+
"writable": true,
|
|
941
|
+
"pda": {
|
|
942
|
+
"seeds": [
|
|
943
|
+
{
|
|
944
|
+
"kind": "account",
|
|
945
|
+
"path": "seller_authority"
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
"kind": "account",
|
|
949
|
+
"path": "token_program"
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
"kind": "account",
|
|
953
|
+
"path": "mint"
|
|
954
|
+
}
|
|
955
|
+
],
|
|
956
|
+
"program": {
|
|
957
|
+
"kind": "const",
|
|
958
|
+
"value": [
|
|
959
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
960
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
961
|
+
219, 233, 248, 89
|
|
962
|
+
]
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
},
|
|
825
966
|
{
|
|
826
967
|
"name": "token_program"
|
|
827
968
|
},
|
|
@@ -2178,6 +2319,26 @@
|
|
|
2178
2319
|
]
|
|
2179
2320
|
}
|
|
2180
2321
|
},
|
|
2322
|
+
{
|
|
2323
|
+
"name": "MarketAskOrderArgs",
|
|
2324
|
+
"type": {
|
|
2325
|
+
"kind": "struct",
|
|
2326
|
+
"fields": [
|
|
2327
|
+
{
|
|
2328
|
+
"name": "shares",
|
|
2329
|
+
"type": "u64"
|
|
2330
|
+
},
|
|
2331
|
+
{
|
|
2332
|
+
"name": "order_direction",
|
|
2333
|
+
"type": {
|
|
2334
|
+
"defined": {
|
|
2335
|
+
"name": "OrderDirection"
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
]
|
|
2340
|
+
}
|
|
2341
|
+
},
|
|
2181
2342
|
{
|
|
2182
2343
|
"name": "MarketBidOrderArgs",
|
|
2183
2344
|
"type": {
|
|
@@ -1003,6 +1003,173 @@ export type TriadProtocol = {
|
|
|
1003
1003
|
];
|
|
1004
1004
|
args: [];
|
|
1005
1005
|
},
|
|
1006
|
+
{
|
|
1007
|
+
name: 'marketAskOrder';
|
|
1008
|
+
discriminator: [189, 66, 162, 254, 3, 85, 152, 54];
|
|
1009
|
+
accounts: [
|
|
1010
|
+
{
|
|
1011
|
+
name: 'signer';
|
|
1012
|
+
writable: true;
|
|
1013
|
+
signer: true;
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
name: 'squads';
|
|
1017
|
+
writable: true;
|
|
1018
|
+
address: '6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq';
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
name: 'sellerTrade';
|
|
1022
|
+
writable: true;
|
|
1023
|
+
},
|
|
1024
|
+
{
|
|
1025
|
+
name: 'buyerTrade';
|
|
1026
|
+
writable: true;
|
|
1027
|
+
},
|
|
1028
|
+
{
|
|
1029
|
+
name: 'market';
|
|
1030
|
+
writable: true;
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
name: 'mint';
|
|
1034
|
+
writable: true;
|
|
1035
|
+
},
|
|
1036
|
+
{
|
|
1037
|
+
name: 'userFromAta';
|
|
1038
|
+
writable: true;
|
|
1039
|
+
pda: {
|
|
1040
|
+
seeds: [
|
|
1041
|
+
{
|
|
1042
|
+
kind: 'account';
|
|
1043
|
+
path: 'signer';
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
kind: 'account';
|
|
1047
|
+
path: 'tokenProgram';
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
kind: 'account';
|
|
1051
|
+
path: 'mint';
|
|
1052
|
+
}
|
|
1053
|
+
];
|
|
1054
|
+
program: {
|
|
1055
|
+
kind: 'const';
|
|
1056
|
+
value: [
|
|
1057
|
+
140,
|
|
1058
|
+
151,
|
|
1059
|
+
37,
|
|
1060
|
+
143,
|
|
1061
|
+
78,
|
|
1062
|
+
36,
|
|
1063
|
+
137,
|
|
1064
|
+
241,
|
|
1065
|
+
187,
|
|
1066
|
+
61,
|
|
1067
|
+
16,
|
|
1068
|
+
41,
|
|
1069
|
+
20,
|
|
1070
|
+
142,
|
|
1071
|
+
13,
|
|
1072
|
+
131,
|
|
1073
|
+
11,
|
|
1074
|
+
90,
|
|
1075
|
+
19,
|
|
1076
|
+
153,
|
|
1077
|
+
218,
|
|
1078
|
+
255,
|
|
1079
|
+
16,
|
|
1080
|
+
132,
|
|
1081
|
+
4,
|
|
1082
|
+
142,
|
|
1083
|
+
123,
|
|
1084
|
+
216,
|
|
1085
|
+
219,
|
|
1086
|
+
233,
|
|
1087
|
+
248,
|
|
1088
|
+
89
|
|
1089
|
+
];
|
|
1090
|
+
};
|
|
1091
|
+
};
|
|
1092
|
+
},
|
|
1093
|
+
{
|
|
1094
|
+
name: 'marketAta';
|
|
1095
|
+
writable: true;
|
|
1096
|
+
pda: {
|
|
1097
|
+
seeds: [
|
|
1098
|
+
{
|
|
1099
|
+
kind: 'account';
|
|
1100
|
+
path: 'market';
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
kind: 'account';
|
|
1104
|
+
path: 'tokenProgram';
|
|
1105
|
+
},
|
|
1106
|
+
{
|
|
1107
|
+
kind: 'account';
|
|
1108
|
+
path: 'mint';
|
|
1109
|
+
}
|
|
1110
|
+
];
|
|
1111
|
+
program: {
|
|
1112
|
+
kind: 'const';
|
|
1113
|
+
value: [
|
|
1114
|
+
140,
|
|
1115
|
+
151,
|
|
1116
|
+
37,
|
|
1117
|
+
143,
|
|
1118
|
+
78,
|
|
1119
|
+
36,
|
|
1120
|
+
137,
|
|
1121
|
+
241,
|
|
1122
|
+
187,
|
|
1123
|
+
61,
|
|
1124
|
+
16,
|
|
1125
|
+
41,
|
|
1126
|
+
20,
|
|
1127
|
+
142,
|
|
1128
|
+
13,
|
|
1129
|
+
131,
|
|
1130
|
+
11,
|
|
1131
|
+
90,
|
|
1132
|
+
19,
|
|
1133
|
+
153,
|
|
1134
|
+
218,
|
|
1135
|
+
255,
|
|
1136
|
+
16,
|
|
1137
|
+
132,
|
|
1138
|
+
4,
|
|
1139
|
+
142,
|
|
1140
|
+
123,
|
|
1141
|
+
216,
|
|
1142
|
+
219,
|
|
1143
|
+
233,
|
|
1144
|
+
248,
|
|
1145
|
+
89
|
|
1146
|
+
];
|
|
1147
|
+
};
|
|
1148
|
+
};
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
name: 'tokenProgram';
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
name: 'associatedTokenProgram';
|
|
1155
|
+
address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
1156
|
+
},
|
|
1157
|
+
{
|
|
1158
|
+
name: 'systemProgram';
|
|
1159
|
+
address: '11111111111111111111111111111111';
|
|
1160
|
+
}
|
|
1161
|
+
];
|
|
1162
|
+
args: [
|
|
1163
|
+
{
|
|
1164
|
+
name: 'args';
|
|
1165
|
+
type: {
|
|
1166
|
+
defined: {
|
|
1167
|
+
name: 'marketAskOrderArgs';
|
|
1168
|
+
};
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
];
|
|
1172
|
+
},
|
|
1006
1173
|
{
|
|
1007
1174
|
name: 'marketBidOrder';
|
|
1008
1175
|
discriminator: [145, 89, 7, 166, 85, 59, 48, 149];
|
|
@@ -1147,6 +1314,67 @@ export type TriadProtocol = {
|
|
|
1147
1314
|
};
|
|
1148
1315
|
};
|
|
1149
1316
|
},
|
|
1317
|
+
{
|
|
1318
|
+
name: 'sellerAuthority';
|
|
1319
|
+
writable: true;
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
name: 'sellerToAta';
|
|
1323
|
+
writable: true;
|
|
1324
|
+
pda: {
|
|
1325
|
+
seeds: [
|
|
1326
|
+
{
|
|
1327
|
+
kind: 'account';
|
|
1328
|
+
path: 'sellerAuthority';
|
|
1329
|
+
},
|
|
1330
|
+
{
|
|
1331
|
+
kind: 'account';
|
|
1332
|
+
path: 'tokenProgram';
|
|
1333
|
+
},
|
|
1334
|
+
{
|
|
1335
|
+
kind: 'account';
|
|
1336
|
+
path: 'mint';
|
|
1337
|
+
}
|
|
1338
|
+
];
|
|
1339
|
+
program: {
|
|
1340
|
+
kind: 'const';
|
|
1341
|
+
value: [
|
|
1342
|
+
140,
|
|
1343
|
+
151,
|
|
1344
|
+
37,
|
|
1345
|
+
143,
|
|
1346
|
+
78,
|
|
1347
|
+
36,
|
|
1348
|
+
137,
|
|
1349
|
+
241,
|
|
1350
|
+
187,
|
|
1351
|
+
61,
|
|
1352
|
+
16,
|
|
1353
|
+
41,
|
|
1354
|
+
20,
|
|
1355
|
+
142,
|
|
1356
|
+
13,
|
|
1357
|
+
131,
|
|
1358
|
+
11,
|
|
1359
|
+
90,
|
|
1360
|
+
19,
|
|
1361
|
+
153,
|
|
1362
|
+
218,
|
|
1363
|
+
255,
|
|
1364
|
+
16,
|
|
1365
|
+
132,
|
|
1366
|
+
4,
|
|
1367
|
+
142,
|
|
1368
|
+
123,
|
|
1369
|
+
216,
|
|
1370
|
+
219,
|
|
1371
|
+
233,
|
|
1372
|
+
248,
|
|
1373
|
+
89
|
|
1374
|
+
];
|
|
1375
|
+
};
|
|
1376
|
+
};
|
|
1377
|
+
},
|
|
1150
1378
|
{
|
|
1151
1379
|
name: 'tokenProgram';
|
|
1152
1380
|
},
|
|
@@ -2851,6 +3079,26 @@ export type TriadProtocol = {
|
|
|
2851
3079
|
];
|
|
2852
3080
|
};
|
|
2853
3081
|
},
|
|
3082
|
+
{
|
|
3083
|
+
name: 'marketAskOrderArgs';
|
|
3084
|
+
type: {
|
|
3085
|
+
kind: 'struct';
|
|
3086
|
+
fields: [
|
|
3087
|
+
{
|
|
3088
|
+
name: 'shares';
|
|
3089
|
+
type: 'u64';
|
|
3090
|
+
},
|
|
3091
|
+
{
|
|
3092
|
+
name: 'orderDirection';
|
|
3093
|
+
type: {
|
|
3094
|
+
defined: {
|
|
3095
|
+
name: 'orderDirection';
|
|
3096
|
+
};
|
|
3097
|
+
};
|
|
3098
|
+
}
|
|
3099
|
+
];
|
|
3100
|
+
};
|
|
3101
|
+
},
|
|
2854
3102
|
{
|
|
2855
3103
|
name: 'marketBidOrderArgs';
|
|
2856
3104
|
type: {
|