@triadxyz/triad-protocol 4.3.2 → 4.3.4

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.
@@ -2,7 +2,7 @@ import { PublicKey } from '@solana/web3.js';
2
2
  import { Program } from '@coral-xyz/anchor';
3
3
  import { TriadProtocol } from './types/triad_protocol';
4
4
  import { RpcOptions } from './types';
5
- import { DepositArgs, DepositExtArgs, WithdrawArgs, CollectRewardsArgs, Predictor as PredictorType } from './types/predictor';
5
+ import { DepositArgs, WithdrawArgs, CollectRewardsArgs, Predictor as PredictorType } from './types/predictor';
6
6
  export default class Predictor {
7
7
  private program;
8
8
  private rpcOptions;
@@ -48,8 +48,9 @@ export default class Predictor {
48
48
  * @param args.amount - Amount to deposit
49
49
  * @param args.refer - Referral public key
50
50
  * @param args.customerId - Customer ID
51
+ * @param args.depositId - Deposit ID
51
52
  */
52
- deposit({ authority, amount, refer, customerId }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
53
+ deposit({ authority, amount, refer, customerId, depositId }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
53
54
  /**
54
55
  * Withdraw
55
56
  * @param args.authority - Authority of the withdraw
@@ -58,16 +59,6 @@ export default class Predictor {
58
59
  * @param args.customerId - Customer ID
59
60
  */
60
61
  withdraw({ authority, recipient, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
61
- /**
62
- * Deposit Ext
63
- * Idempotent deposit with an optional external deposit record.
64
- * @param args.authority - Authority of the deposit
65
- * @param args.amount - Amount to deposit
66
- * @param args.refer - Referral public key (used only when creating the predictor)
67
- * @param args.customerId - Customer ID
68
- * @param args.depositId - Optional 12-byte deposit ID used as idempotency key
69
- */
70
- depositExt({ authority, amount, refer, customerId, depositId }: DepositExtArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
71
62
  /**
72
63
  * Collect Rewards
73
64
  * Claims accumulated TRIAD token rewards for the predictor.
package/dist/predictor.js CHANGED
@@ -129,8 +129,9 @@ class Predictor {
129
129
  * @param args.amount - Amount to deposit
130
130
  * @param args.refer - Referral public key
131
131
  * @param args.customerId - Customer ID
132
+ * @param args.depositId - Deposit ID
132
133
  */
133
- deposit({ authority, amount, refer, customerId }) {
134
+ deposit({ authority, amount, refer, customerId, depositId }) {
134
135
  return __awaiter(this, void 0, void 0, function* () {
135
136
  const ixs = [];
136
137
  const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
@@ -150,10 +151,19 @@ class Predictor {
150
151
  .instruction());
151
152
  }
152
153
  ixs.push(yield this.program.methods
153
- .deposit(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
154
+ .deposit({
155
+ amount: new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)),
156
+ depositId: depositId
157
+ ? Array.from(Buffer.from(depositId, 'hex'))
158
+ : null
159
+ })
154
160
  .accounts({
155
161
  signer: authority,
156
- predictor: predictorPDA
162
+ predictor: predictorPDA,
163
+ customer: (0, pda_1.getCustomerPDA)(this.program.programId, customerId),
164
+ predictorDeposit: depositId
165
+ ? (0, pda_1.getPredictorDepositPDA)(this.program.programId, depositId)
166
+ : null
157
167
  })
158
168
  .instruction());
159
169
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
@@ -183,48 +193,6 @@ class Predictor {
183
193
  return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
184
194
  });
185
195
  }
186
- /**
187
- * Deposit Ext
188
- * Idempotent deposit with an optional external deposit record.
189
- * @param args.authority - Authority of the deposit
190
- * @param args.amount - Amount to deposit
191
- * @param args.refer - Referral public key (used only when creating the predictor)
192
- * @param args.customerId - Customer ID
193
- * @param args.depositId - Optional 12-byte deposit ID used as idempotency key
194
- */
195
- depositExt({ authority, amount, refer, customerId, depositId }) {
196
- return __awaiter(this, void 0, void 0, function* () {
197
- const ixs = [];
198
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
199
- try {
200
- yield this.program.account.predictor.fetch(predictorPDA);
201
- }
202
- catch (e) {
203
- ixs.push(yield this.program.methods
204
- .createPredictor({
205
- customerId,
206
- refer
207
- })
208
- .accounts({
209
- signer: this.program.provider.publicKey,
210
- payer: this.rpcOptions.payer
211
- })
212
- .instruction());
213
- }
214
- ixs.push(yield this.program.methods
215
- .depositExt({
216
- amount: new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)),
217
- depositId: Array.from(Buffer.from(depositId, 'hex'))
218
- })
219
- .accounts({
220
- signer: authority,
221
- predictor: predictorPDA,
222
- predictorDeposit: (0, pda_1.getPredictorDepositPDA)(this.program.programId, depositId)
223
- })
224
- .instruction());
225
- return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
226
- });
227
- }
228
196
  /**
229
197
  * Collect Rewards
230
198
  * Claims accumulated TRIAD token rewards for the predictor.
@@ -11,6 +11,7 @@ export type Customer = {
11
11
  payoutFeeBps: number;
12
12
  feeAvailable: number;
13
13
  feeClaimed: number;
14
+ netCash: number;
14
15
  };
15
16
  export type CreateCustomerArgs = {
16
17
  id: number;
@@ -892,157 +892,17 @@
892
892
  },
893
893
  {
894
894
  "name": "customer",
895
- "writable": true,
896
- "pda": {
897
- "seeds": [
898
- {
899
- "kind": "const",
900
- "value": [99, 117, 115, 116, 111, 109, 101, 114]
901
- },
902
- {
903
- "kind": "account",
904
- "path": "predictor.customer_id",
905
- "account": "Predictor"
906
- }
907
- ]
908
- }
909
- },
910
- {
911
- "name": "predictor",
912
895
  "writable": true
913
896
  },
914
- {
915
- "name": "mint",
916
- "writable": true,
917
- "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
918
- },
919
- {
920
- "name": "user_ata",
921
- "writable": true,
922
- "pda": {
923
- "seeds": [
924
- {
925
- "kind": "account",
926
- "path": "signer"
927
- },
928
- {
929
- "kind": "account",
930
- "path": "token_program"
931
- },
932
- {
933
- "kind": "account",
934
- "path": "mint"
935
- }
936
- ],
937
- "program": {
938
- "kind": "const",
939
- "value": [
940
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
941
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
942
- 219, 233, 248, 89
943
- ]
944
- }
945
- }
946
- },
947
- {
948
- "name": "central_ata",
949
- "writable": true,
950
- "pda": {
951
- "seeds": [
952
- {
953
- "kind": "account",
954
- "path": "central"
955
- },
956
- {
957
- "kind": "account",
958
- "path": "token_program"
959
- },
960
- {
961
- "kind": "account",
962
- "path": "mint"
963
- }
964
- ],
965
- "program": {
966
- "kind": "const",
967
- "value": [
968
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
969
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
970
- 219, 233, 248, 89
971
- ]
972
- }
973
- }
974
- },
975
- {
976
- "name": "token_program",
977
- "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
978
- },
979
- {
980
- "name": "associated_token_program",
981
- "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
982
- },
983
- {
984
- "name": "system_program",
985
- "address": "11111111111111111111111111111111"
986
- }
987
- ],
988
- "args": [
989
- {
990
- "name": "amount",
991
- "type": "u64"
992
- }
993
- ]
994
- },
995
- {
996
- "name": "deposit_ext",
997
- "discriminator": [80, 29, 27, 89, 96, 75, 249, 174],
998
- "accounts": [
999
- {
1000
- "name": "signer",
1001
- "writable": true,
1002
- "signer": true
1003
- },
1004
- {
1005
- "name": "central",
1006
- "writable": true,
1007
- "pda": {
1008
- "seeds": [
1009
- {
1010
- "kind": "const",
1011
- "value": [99, 101, 110, 116, 114, 97, 108]
1012
- },
1013
- {
1014
- "kind": "const",
1015
- "value": [
1016
- 116, 114, 105, 97, 100, 109, 97, 114, 107, 101, 116, 115
1017
- ]
1018
- }
1019
- ]
1020
- }
1021
- },
1022
- {
1023
- "name": "customer",
1024
- "writable": true,
1025
- "pda": {
1026
- "seeds": [
1027
- {
1028
- "kind": "const",
1029
- "value": [99, 117, 115, 116, 111, 109, 101, 114]
1030
- },
1031
- {
1032
- "kind": "account",
1033
- "path": "predictor.customer_id",
1034
- "account": "Predictor"
1035
- }
1036
- ]
1037
- }
1038
- },
1039
897
  {
1040
898
  "name": "predictor",
1041
899
  "writable": true
1042
900
  },
1043
901
  {
1044
902
  "name": "predictor_deposit",
1045
- "writable": true
903
+ "writable": true,
904
+ "signer": true,
905
+ "optional": true
1046
906
  },
1047
907
  {
1048
908
  "name": "mint",
@@ -1123,7 +983,7 @@
1123
983
  "name": "args",
1124
984
  "type": {
1125
985
  "defined": {
1126
- "name": "DepositExtArgs"
986
+ "name": "DepositArgs"
1127
987
  }
1128
988
  }
1129
989
  }
@@ -2928,6 +2788,26 @@
2928
2788
  ]
2929
2789
  }
2930
2790
  },
2791
+ {
2792
+ "name": "DepositArgs",
2793
+ "type": {
2794
+ "kind": "struct",
2795
+ "fields": [
2796
+ {
2797
+ "name": "amount",
2798
+ "type": "u64"
2799
+ },
2800
+ {
2801
+ "name": "deposit_id",
2802
+ "type": {
2803
+ "option": {
2804
+ "array": ["u8", 12]
2805
+ }
2806
+ }
2807
+ }
2808
+ ]
2809
+ }
2810
+ },
2931
2811
  {
2932
2812
  "name": "DepositEvent",
2933
2813
  "type": {
@@ -2968,24 +2848,6 @@
2968
2848
  ]
2969
2849
  }
2970
2850
  },
2971
- {
2972
- "name": "DepositExtArgs",
2973
- "type": {
2974
- "kind": "struct",
2975
- "fields": [
2976
- {
2977
- "name": "amount",
2978
- "type": "u64"
2979
- },
2980
- {
2981
- "name": "deposit_id",
2982
- "type": {
2983
- "array": ["u8", 12]
2984
- }
2985
- }
2986
- ]
2987
- }
2988
- },
2989
2851
  {
2990
2852
  "name": "Key",
2991
2853
  "type": {
@@ -13,6 +13,7 @@ export type DepositArgs = {
13
13
  amount: number;
14
14
  refer: PublicKey;
15
15
  customerId: number;
16
+ depositId?: string;
16
17
  };
17
18
  export type WithdrawArgs = {
18
19
  authority: PublicKey;
@@ -1107,217 +1107,6 @@ export type TriadProtocol = {
1107
1107
  {
1108
1108
  name: 'customer';
1109
1109
  writable: true;
1110
- pda: {
1111
- seeds: [
1112
- {
1113
- kind: 'const';
1114
- value: [99, 117, 115, 116, 111, 109, 101, 114];
1115
- },
1116
- {
1117
- kind: 'account';
1118
- path: 'predictor.customer_id';
1119
- account: 'predictor';
1120
- }
1121
- ];
1122
- };
1123
- },
1124
- {
1125
- name: 'predictor';
1126
- writable: true;
1127
- },
1128
- {
1129
- name: 'mint';
1130
- writable: true;
1131
- address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
1132
- },
1133
- {
1134
- name: 'userAta';
1135
- writable: true;
1136
- pda: {
1137
- seeds: [
1138
- {
1139
- kind: 'account';
1140
- path: 'signer';
1141
- },
1142
- {
1143
- kind: 'account';
1144
- path: 'tokenProgram';
1145
- },
1146
- {
1147
- kind: 'account';
1148
- path: 'mint';
1149
- }
1150
- ];
1151
- program: {
1152
- kind: 'const';
1153
- value: [
1154
- 140,
1155
- 151,
1156
- 37,
1157
- 143,
1158
- 78,
1159
- 36,
1160
- 137,
1161
- 241,
1162
- 187,
1163
- 61,
1164
- 16,
1165
- 41,
1166
- 20,
1167
- 142,
1168
- 13,
1169
- 131,
1170
- 11,
1171
- 90,
1172
- 19,
1173
- 153,
1174
- 218,
1175
- 255,
1176
- 16,
1177
- 132,
1178
- 4,
1179
- 142,
1180
- 123,
1181
- 216,
1182
- 219,
1183
- 233,
1184
- 248,
1185
- 89
1186
- ];
1187
- };
1188
- };
1189
- },
1190
- {
1191
- name: 'centralAta';
1192
- writable: true;
1193
- pda: {
1194
- seeds: [
1195
- {
1196
- kind: 'account';
1197
- path: 'central';
1198
- },
1199
- {
1200
- kind: 'account';
1201
- path: 'tokenProgram';
1202
- },
1203
- {
1204
- kind: 'account';
1205
- path: 'mint';
1206
- }
1207
- ];
1208
- program: {
1209
- kind: 'const';
1210
- value: [
1211
- 140,
1212
- 151,
1213
- 37,
1214
- 143,
1215
- 78,
1216
- 36,
1217
- 137,
1218
- 241,
1219
- 187,
1220
- 61,
1221
- 16,
1222
- 41,
1223
- 20,
1224
- 142,
1225
- 13,
1226
- 131,
1227
- 11,
1228
- 90,
1229
- 19,
1230
- 153,
1231
- 218,
1232
- 255,
1233
- 16,
1234
- 132,
1235
- 4,
1236
- 142,
1237
- 123,
1238
- 216,
1239
- 219,
1240
- 233,
1241
- 248,
1242
- 89
1243
- ];
1244
- };
1245
- };
1246
- },
1247
- {
1248
- name: 'tokenProgram';
1249
- address: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
1250
- },
1251
- {
1252
- name: 'associatedTokenProgram';
1253
- address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
1254
- },
1255
- {
1256
- name: 'systemProgram';
1257
- address: '11111111111111111111111111111111';
1258
- }
1259
- ];
1260
- args: [
1261
- {
1262
- name: 'amount';
1263
- type: 'u64';
1264
- }
1265
- ];
1266
- },
1267
- {
1268
- name: 'depositExt';
1269
- discriminator: [80, 29, 27, 89, 96, 75, 249, 174];
1270
- accounts: [
1271
- {
1272
- name: 'signer';
1273
- writable: true;
1274
- signer: true;
1275
- },
1276
- {
1277
- name: 'central';
1278
- writable: true;
1279
- pda: {
1280
- seeds: [
1281
- {
1282
- kind: 'const';
1283
- value: [99, 101, 110, 116, 114, 97, 108];
1284
- },
1285
- {
1286
- kind: 'const';
1287
- value: [
1288
- 116,
1289
- 114,
1290
- 105,
1291
- 97,
1292
- 100,
1293
- 109,
1294
- 97,
1295
- 114,
1296
- 107,
1297
- 101,
1298
- 116,
1299
- 115
1300
- ];
1301
- }
1302
- ];
1303
- };
1304
- },
1305
- {
1306
- name: 'customer';
1307
- writable: true;
1308
- pda: {
1309
- seeds: [
1310
- {
1311
- kind: 'const';
1312
- value: [99, 117, 115, 116, 111, 109, 101, 114];
1313
- },
1314
- {
1315
- kind: 'account';
1316
- path: 'predictor.customer_id';
1317
- account: 'predictor';
1318
- }
1319
- ];
1320
- };
1321
1110
  },
1322
1111
  {
1323
1112
  name: 'predictor';
@@ -1326,6 +1115,8 @@ export type TriadProtocol = {
1326
1115
  {
1327
1116
  name: 'predictorDeposit';
1328
1117
  writable: true;
1118
+ signer: true;
1119
+ optional: true;
1329
1120
  },
1330
1121
  {
1331
1122
  name: 'mint';
@@ -1464,7 +1255,7 @@ export type TriadProtocol = {
1464
1255
  name: 'args';
1465
1256
  type: {
1466
1257
  defined: {
1467
- name: 'depositExtArgs';
1258
+ name: 'depositArgs';
1468
1259
  };
1469
1260
  };
1470
1261
  }
@@ -3494,6 +3285,26 @@ export type TriadProtocol = {
3494
3285
  ];
3495
3286
  };
3496
3287
  },
3288
+ {
3289
+ name: 'depositArgs';
3290
+ type: {
3291
+ kind: 'struct';
3292
+ fields: [
3293
+ {
3294
+ name: 'amount';
3295
+ type: 'u64';
3296
+ },
3297
+ {
3298
+ name: 'depositId';
3299
+ type: {
3300
+ option: {
3301
+ array: ['u8', 12];
3302
+ };
3303
+ };
3304
+ }
3305
+ ];
3306
+ };
3307
+ },
3497
3308
  {
3498
3309
  name: 'depositEvent';
3499
3310
  type: {
@@ -3534,24 +3345,6 @@ export type TriadProtocol = {
3534
3345
  ];
3535
3346
  };
3536
3347
  },
3537
- {
3538
- name: 'depositExtArgs';
3539
- type: {
3540
- kind: 'struct';
3541
- fields: [
3542
- {
3543
- name: 'amount';
3544
- type: 'u64';
3545
- },
3546
- {
3547
- name: 'depositId';
3548
- type: {
3549
- array: ['u8', 12];
3550
- };
3551
- }
3552
- ];
3553
- };
3554
- },
3555
3348
  {
3556
3349
  name: 'key';
3557
3350
  type: {
@@ -155,7 +155,8 @@ const formatCustomer = (account, publicKey) => {
155
155
  isVerified: account.isVerified,
156
156
  address: publicKey.toString(),
157
157
  feeAvailable: account.feeAvailable.toNumber() / Math.pow(10, 6),
158
- feeClaimed: account.feeClaimed.toNumber() / Math.pow(10, 6)
158
+ feeClaimed: account.feeClaimed.toNumber() / Math.pow(10, 6),
159
+ netCash: account.netCash.toNumber() / Math.pow(10, 6)
159
160
  };
160
161
  };
161
162
  exports.formatCustomer = formatCustomer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.3.2",
3
+ "version": "4.3.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",