@triadxyz/triad-protocol 4.0.2 → 4.0.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.
- package/dist/predictor.d.ts +12 -5
- package/dist/predictor.js +33 -7
- package/dist/trade.js +2 -2
- package/dist/types/idl_triad_protocol.json +3 -3
- package/dist/types/predictor.d.ts +9 -2
- package/dist/types/triad_protocol.d.ts +3 -3
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/feeCalculator.js +1 -1
- package/dist/utils/helpers.d.ts +3 -1
- package/dist/utils/helpers.js +11 -1
- package/dist/utils/pda.d.ts +1 -1
- package/dist/utils/pda.js +2 -2
- package/package.json +1 -1
package/dist/predictor.d.ts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
3
|
import { Program } from '@coral-xyz/anchor';
|
|
3
4
|
import { TriadProtocol } from './types/triad_protocol';
|
|
4
5
|
import { RpcOptions } from './types';
|
|
5
|
-
import { DepositArgs, WithdrawArgs } from './types/predictor';
|
|
6
|
+
import { DepositArgs, WithdrawArgs, Predictor as PredictorType } from './types/predictor';
|
|
6
7
|
export default class Predictor {
|
|
7
8
|
private program;
|
|
8
9
|
private rpcOptions;
|
|
9
10
|
constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Get predictor
|
|
13
|
+
* @param authority - Authority public key
|
|
14
|
+
* @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
15
|
+
*/
|
|
16
|
+
getPredictor(authority: PublicKey, customerId?: number): Promise<PredictorType>;
|
|
10
17
|
/**
|
|
11
18
|
* Deposit
|
|
12
19
|
* @param args.authority - Authority of the deposit
|
|
13
20
|
* @param args.amount - Amount to deposit
|
|
14
21
|
* @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
|
|
15
|
-
* @param args.
|
|
22
|
+
* @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
16
23
|
*/
|
|
17
|
-
deposit({ authority, amount, refer,
|
|
24
|
+
deposit({ authority, amount, refer, customerId }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
18
25
|
/**
|
|
19
26
|
* Withdraw
|
|
20
27
|
* @param args.authority - Authority of the withdraw
|
|
21
28
|
* @param args.amount - Amount to deposit
|
|
22
|
-
* @param args.
|
|
29
|
+
* @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
23
30
|
*/
|
|
24
|
-
withdraw({ authority, amount,
|
|
31
|
+
withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
25
32
|
}
|
package/dist/predictor.js
CHANGED
|
@@ -17,29 +17,55 @@ const bn_js_1 = __importDefault(require("bn.js"));
|
|
|
17
17
|
const constants_1 = require("./utils/constants");
|
|
18
18
|
const pda_1 = require("./utils/pda");
|
|
19
19
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
20
|
+
const helpers_1 = require("./utils/helpers");
|
|
21
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
20
22
|
class Predictor {
|
|
21
23
|
constructor(program, rpcOptions) {
|
|
22
24
|
this.program = program;
|
|
23
25
|
this.rpcOptions = rpcOptions;
|
|
24
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Get predictor
|
|
29
|
+
* @param authority - Authority public key
|
|
30
|
+
* @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
31
|
+
*/
|
|
32
|
+
getPredictor(authority, customerId = 7) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
35
|
+
try {
|
|
36
|
+
const predictor = yield this.program.account.predictor.fetch(predictorPDA);
|
|
37
|
+
const balance = yield this.program.provider.connection.getTokenAccountBalance((0, pda_1.getTokenATA)(predictorPDA, constants_1.UNIT_MINT, spl_token_1.TOKEN_PROGRAM_ID));
|
|
38
|
+
return (0, helpers_1.formatPredictor)(predictor, predictorPDA, new bn_js_1.default(balance.value.amount));
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
return {
|
|
42
|
+
address: predictorPDA.toBase58(),
|
|
43
|
+
authority: authority.toBase58(),
|
|
44
|
+
balance: 0,
|
|
45
|
+
customerId,
|
|
46
|
+
refer: '11111111111111111111111111111111'
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
25
51
|
/**
|
|
26
52
|
* Deposit
|
|
27
53
|
* @param args.authority - Authority of the deposit
|
|
28
54
|
* @param args.amount - Amount to deposit
|
|
29
55
|
* @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
|
|
30
|
-
* @param args.
|
|
56
|
+
* @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
31
57
|
*/
|
|
32
|
-
deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'),
|
|
58
|
+
deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customerId = 7 }) {
|
|
33
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
60
|
const ixs = [];
|
|
35
|
-
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority,
|
|
61
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
36
62
|
try {
|
|
37
63
|
yield this.program.account.predictor.fetch(predictorPDA);
|
|
38
64
|
}
|
|
39
65
|
catch (e) {
|
|
40
66
|
ixs.push(yield this.program.methods
|
|
41
67
|
.createPredictor({
|
|
42
|
-
|
|
68
|
+
customerId,
|
|
43
69
|
refer
|
|
44
70
|
})
|
|
45
71
|
.accounts({
|
|
@@ -63,12 +89,12 @@ class Predictor {
|
|
|
63
89
|
* Withdraw
|
|
64
90
|
* @param args.authority - Authority of the withdraw
|
|
65
91
|
* @param args.amount - Amount to deposit
|
|
66
|
-
* @param args.
|
|
92
|
+
* @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
67
93
|
*/
|
|
68
|
-
withdraw({ authority, amount,
|
|
94
|
+
withdraw({ authority, amount, customerId = 7 }) {
|
|
69
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
96
|
const ixs = [];
|
|
71
|
-
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority,
|
|
97
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
72
98
|
ixs.push(yield this.program.methods
|
|
73
99
|
.withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
74
100
|
.accounts({
|
package/dist/trade.js
CHANGED
|
@@ -215,7 +215,7 @@ class Trade {
|
|
|
215
215
|
}
|
|
216
216
|
const orderPrice = new bn_js_1.default(order.price);
|
|
217
217
|
const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
|
|
218
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000,
|
|
218
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500);
|
|
219
219
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
220
220
|
const maxSharesForPrice = remainingUSDC
|
|
221
221
|
.mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
@@ -287,7 +287,7 @@ class Trade {
|
|
|
287
287
|
continue;
|
|
288
288
|
remainingShares = remainingShares.sub(sharesToSell);
|
|
289
289
|
const orderPrice = new bn_js_1.default(order.price);
|
|
290
|
-
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000,
|
|
290
|
+
const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500);
|
|
291
291
|
const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
|
|
292
292
|
amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
|
|
293
293
|
ixs.push(yield this.program.methods
|
|
@@ -847,7 +847,7 @@
|
|
|
847
847
|
},
|
|
848
848
|
{
|
|
849
849
|
"kind": "arg",
|
|
850
|
-
"path": "args.
|
|
850
|
+
"path": "args.customer_id"
|
|
851
851
|
}
|
|
852
852
|
]
|
|
853
853
|
}
|
|
@@ -3106,7 +3106,7 @@
|
|
|
3106
3106
|
"type": "pubkey"
|
|
3107
3107
|
},
|
|
3108
3108
|
{
|
|
3109
|
-
"name": "
|
|
3109
|
+
"name": "customer_id",
|
|
3110
3110
|
"type": "u16"
|
|
3111
3111
|
}
|
|
3112
3112
|
]
|
|
@@ -3886,7 +3886,7 @@
|
|
|
3886
3886
|
"type": "pubkey"
|
|
3887
3887
|
},
|
|
3888
3888
|
{
|
|
3889
|
-
"name": "
|
|
3889
|
+
"name": "customer_id",
|
|
3890
3890
|
"type": "u16"
|
|
3891
3891
|
},
|
|
3892
3892
|
{
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
export type Predictor = {
|
|
4
|
+
address: string;
|
|
5
|
+
authority: string;
|
|
6
|
+
refer: string;
|
|
7
|
+
customerId: number;
|
|
8
|
+
balance: number;
|
|
9
|
+
};
|
|
3
10
|
export type DepositArgs = {
|
|
4
11
|
authority: PublicKey;
|
|
5
12
|
amount: number;
|
|
6
13
|
refer?: PublicKey;
|
|
7
|
-
|
|
14
|
+
customerId?: number;
|
|
8
15
|
};
|
|
9
16
|
export type WithdrawArgs = {
|
|
10
17
|
authority: PublicKey;
|
|
11
18
|
amount: number;
|
|
12
|
-
|
|
19
|
+
customerId?: number;
|
|
13
20
|
};
|
|
@@ -1167,7 +1167,7 @@ export type TriadProtocol = {
|
|
|
1167
1167
|
},
|
|
1168
1168
|
{
|
|
1169
1169
|
kind: 'arg';
|
|
1170
|
-
path: 'args.
|
|
1170
|
+
path: 'args.customer_id';
|
|
1171
1171
|
}
|
|
1172
1172
|
];
|
|
1173
1173
|
};
|
|
@@ -3994,7 +3994,7 @@ export type TriadProtocol = {
|
|
|
3994
3994
|
type: 'pubkey';
|
|
3995
3995
|
},
|
|
3996
3996
|
{
|
|
3997
|
-
name: '
|
|
3997
|
+
name: 'customerId';
|
|
3998
3998
|
type: 'u16';
|
|
3999
3999
|
}
|
|
4000
4000
|
];
|
|
@@ -4774,7 +4774,7 @@ export type TriadProtocol = {
|
|
|
4774
4774
|
type: 'pubkey';
|
|
4775
4775
|
},
|
|
4776
4776
|
{
|
|
4777
|
-
name: '
|
|
4777
|
+
name: 'customerId';
|
|
4778
4778
|
type: 'u16';
|
|
4779
4779
|
},
|
|
4780
4780
|
{
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
export declare const USDC_MINT: PublicKey;
|
|
4
4
|
export declare const TRD_MINT: PublicKey;
|
|
5
|
+
export declare const UNIT_MINT: PublicKey;
|
|
5
6
|
export declare const TRIAD_ADMIN: PublicKey;
|
|
6
7
|
export declare const TICKET_CORE_COLLECTION: PublicKey;
|
|
7
8
|
export declare const POSEIDON_CORE_COLLECTION: PublicKey;
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.USDC_MINT = void 0;
|
|
3
|
+
exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.UNIT_MINT = exports.TRD_MINT = exports.USDC_MINT = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
|
|
6
6
|
exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV');
|
|
7
|
+
exports.UNIT_MINT = new web3_js_1.PublicKey('75wzVU6j9U6oZVJjQYLtiN7Z5Ah97it1UyWZN29HgE4m');
|
|
7
8
|
exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
|
|
8
9
|
exports.TICKET_CORE_COLLECTION = new web3_js_1.PublicKey('BaqopH1VXYUCT6VsojbTibVcd3k5jpGGT6296HFb6fVa');
|
|
9
10
|
exports.POSEIDON_CORE_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er632dvn878qkpdcnvq5ZUspSm');
|
|
@@ -7,7 +7,7 @@ exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = ex
|
|
|
7
7
|
*/
|
|
8
8
|
function calculateDynamicFeeBps(price, feeBps) {
|
|
9
9
|
const internalPrice = price * Math.pow(10, 6);
|
|
10
|
-
if (internalPrice
|
|
10
|
+
if (internalPrice < 900000) {
|
|
11
11
|
return feeBps;
|
|
12
12
|
}
|
|
13
13
|
return Math.floor(((990000 - internalPrice) * 1900) / price);
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { IdlAccounts } from '@coral-xyz/anchor';
|
|
2
|
+
import { BN, IdlAccounts } from '@coral-xyz/anchor';
|
|
3
3
|
import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, OrderDirectionEncoded, OrderTypeEncoded, OrderSideEncoded, OrderStatusEncoded, Pool, BookOrder } from '../types';
|
|
4
4
|
import { Stake, StakeVault, Unstake } from '../types/stake';
|
|
5
5
|
import { Customer } from '../types/customer';
|
|
6
6
|
import { TriadProtocol } from '../types/triad_protocol';
|
|
7
|
+
import { Predictor } from '../types/predictor';
|
|
7
8
|
export declare const encodeString: (value: string, alloc?: number) => number[];
|
|
8
9
|
export declare const decodeString: (bytes: number[]) => string;
|
|
9
10
|
export declare const formatStakeVault: (stakeVault: IdlAccounts<TriadProtocol>['stakeVault']) => StakeVault;
|
|
@@ -25,3 +26,4 @@ export declare const getOrderStatus: (status: OrderStatusEncoded) => OrderStatus
|
|
|
25
26
|
export declare const getOrderDirectionEncoded: (orderDirection: OrderDirection) => OrderDirectionEncoded;
|
|
26
27
|
export declare const getOppositeOrderDirection: (orderDirection: OrderDirection) => OrderDirection;
|
|
27
28
|
export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDirectionEncoded) => OrderDirectionEncoded;
|
|
29
|
+
export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
3
|
+
exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
6
|
const types_1 = require("../types");
|
|
@@ -245,3 +245,13 @@ const getOppositeOrderDirectionEncoded = (orderDirection) => {
|
|
|
245
245
|
return { hype: {} };
|
|
246
246
|
};
|
|
247
247
|
exports.getOppositeOrderDirectionEncoded = getOppositeOrderDirectionEncoded;
|
|
248
|
+
const formatPredictor = (account, publicKey, balance) => {
|
|
249
|
+
return {
|
|
250
|
+
address: publicKey.toBase58(),
|
|
251
|
+
authority: publicKey.toString(),
|
|
252
|
+
refer: account.refer.toString(),
|
|
253
|
+
customerId: account.customerId,
|
|
254
|
+
balance: balance.toNumber() / 1e6
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
exports.formatPredictor = formatPredictor;
|
package/dist/utils/pda.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export declare const getPoseidonPDA: (programId: PublicKey, number: number) => P
|
|
|
13
13
|
export declare const getClaimVaultPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
14
14
|
export declare const getClaimedUserPDA: (programId: PublicKey, claimVault: PublicKey, user: PublicKey) => PublicKey;
|
|
15
15
|
export declare const getOrderPDA: (programId: PublicKey, authority: PublicKey, marketId: number, orderDirection: OrderDirection) => PublicKey;
|
|
16
|
-
export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey,
|
|
16
|
+
export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customerId: number) => PublicKey;
|
|
17
17
|
export declare const getCentralPDA: (programId: PublicKey) => PublicKey;
|
package/dist/utils/pda.js
CHANGED
|
@@ -64,11 +64,11 @@ const getOrderPDA = (programId, authority, marketId, orderDirection) => {
|
|
|
64
64
|
], programId)[0];
|
|
65
65
|
};
|
|
66
66
|
exports.getOrderPDA = getOrderPDA;
|
|
67
|
-
const getPredictorPDA = (programId, authority,
|
|
67
|
+
const getPredictorPDA = (programId, authority, customerId) => {
|
|
68
68
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
69
69
|
Buffer.from('predictor'),
|
|
70
70
|
authority.toBuffer(),
|
|
71
|
-
new bn_js_1.default(
|
|
71
|
+
new bn_js_1.default(customerId).toArrayLike(Buffer, 'le', 2)
|
|
72
72
|
], programId)[0];
|
|
73
73
|
};
|
|
74
74
|
exports.getPredictorPDA = getPredictorPDA;
|