@triadxyz/triad-protocol 4.1.9 → 4.2.1
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/customer.d.ts +8 -1
- package/dist/customer.js +23 -0
- package/dist/index.d.ts +4 -138
- package/dist/index.js +15 -441
- package/dist/market.d.ts +163 -0
- package/dist/market.js +571 -0
- package/dist/poseidon.d.ts +2 -4
- package/dist/poseidon.js +10 -16
- package/dist/predictor.d.ts +8 -1
- package/dist/predictor.js +34 -14
- package/dist/stake.d.ts +0 -15
- package/dist/stake.js +0 -60
- package/dist/trade.d.ts +7 -6
- package/dist/trade.js +44 -54
- package/dist/types/customer.d.ts +5 -0
- package/dist/types/idl_triad_protocol.json +515 -901
- package/dist/types/index.d.ts +1 -4
- package/dist/types/predictor.d.ts +6 -0
- package/dist/types/trade.d.ts +7 -2
- package/dist/types/triad_protocol.d.ts +623 -1389
- package/dist/utils/feeCalculator.d.ts +0 -8
- package/dist/utils/feeCalculator.js +3 -32
- package/dist/utils/helpers.d.ts +2 -2
- package/dist/utils/helpers.js +6 -7
- package/dist/utils/sendVersionedTransaction.js +3 -11
- package/package.json +1 -1
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
* Returns fee in basis points (bps)
|
|
4
4
|
*/
|
|
5
5
|
export declare function calculateDynamicFeeBps(price: number, feeBps: number, customerMarketFeeBps: number): number;
|
|
6
|
-
/**
|
|
7
|
-
* Calculate tiered fixed fee based on entry amount (USDC)
|
|
8
|
-
*/
|
|
9
|
-
export declare function calculateFixedFee(amount: number): number;
|
|
10
6
|
/**
|
|
11
7
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
12
8
|
*/
|
|
@@ -24,8 +20,6 @@ export declare function simulateBuyOrder(amount: number, price: number, feeBps:
|
|
|
24
20
|
sharesReceived: number;
|
|
25
21
|
feeAmount: number;
|
|
26
22
|
feePercentage: number;
|
|
27
|
-
fixedFee: number;
|
|
28
|
-
volumeFee: number;
|
|
29
23
|
realEntryPrice: number;
|
|
30
24
|
};
|
|
31
25
|
/**
|
|
@@ -37,7 +31,5 @@ export declare function simulateSellOrder(shares: number, price: number, feeBps:
|
|
|
37
31
|
sharesReceived: number;
|
|
38
32
|
feeAmount: number;
|
|
39
33
|
feePercentage: number;
|
|
40
|
-
fixedFee: number;
|
|
41
|
-
volumeFee: number;
|
|
42
34
|
realEntryPrice: number;
|
|
43
35
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.
|
|
3
|
+
exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = exports.applyBuyFee = exports.calculateDynamicFeeBps = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Calculate dynamic fee based on price
|
|
6
6
|
* Returns fee in basis points (bps)
|
|
@@ -13,28 +13,6 @@ function calculateDynamicFeeBps(price, feeBps, customerMarketFeeBps) {
|
|
|
13
13
|
return Math.max(Math.floor(((990000 - internalPrice) * 1900) / internalPrice), 90);
|
|
14
14
|
}
|
|
15
15
|
exports.calculateDynamicFeeBps = calculateDynamicFeeBps;
|
|
16
|
-
/**
|
|
17
|
-
* Calculate tiered fixed fee based on entry amount (USDC)
|
|
18
|
-
*/
|
|
19
|
-
function calculateFixedFee(amount) {
|
|
20
|
-
const internalAmount = Math.floor(amount * 1000000);
|
|
21
|
-
if (internalAmount >= 100000000) {
|
|
22
|
-
return 2.5;
|
|
23
|
-
}
|
|
24
|
-
else if (internalAmount >= 50000000) {
|
|
25
|
-
return 1.5;
|
|
26
|
-
}
|
|
27
|
-
else if (internalAmount >= 20000000) {
|
|
28
|
-
return 0.75;
|
|
29
|
-
}
|
|
30
|
-
else if (internalAmount >= 5000000) {
|
|
31
|
-
return 0.3;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return 0.15;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.calculateFixedFee = calculateFixedFee;
|
|
38
16
|
/**
|
|
39
17
|
* Apply dynamic fee to price for buy orders (adds fee)
|
|
40
18
|
*/
|
|
@@ -61,10 +39,8 @@ exports.applySellFee = applySellFee;
|
|
|
61
39
|
* Simulate a buy order with given amount and price
|
|
62
40
|
*/
|
|
63
41
|
function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
|
|
64
|
-
const fixedFee = calculateFixedFee(amount);
|
|
65
|
-
const amountAfterFixedFee = amount - fixedFee;
|
|
66
42
|
const effectivePrice = applyBuyFee(price, feeBps, customerMarketFeeBps);
|
|
67
|
-
const sharesReceived =
|
|
43
|
+
const sharesReceived = amount / effectivePrice;
|
|
68
44
|
const valueAtOriginalPrice = sharesReceived * price;
|
|
69
45
|
const feeAmount = amount - valueAtOriginalPrice;
|
|
70
46
|
return {
|
|
@@ -73,8 +49,6 @@ function simulateBuyOrder(amount, price, feeBps, customerMarketFeeBps) {
|
|
|
73
49
|
sharesReceived,
|
|
74
50
|
feeAmount,
|
|
75
51
|
feePercentage: (feeAmount / amount) * 100,
|
|
76
|
-
fixedFee,
|
|
77
|
-
volumeFee: feeAmount - fixedFee,
|
|
78
52
|
realEntryPrice: amount / sharesReceived
|
|
79
53
|
};
|
|
80
54
|
}
|
|
@@ -86,8 +60,7 @@ function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
|
|
|
86
60
|
const effectivePrice = applySellFee(price, feeBps, customerMarketFeeBps);
|
|
87
61
|
const amountToReceiveBeforeFixed = shares * effectivePrice;
|
|
88
62
|
const valueAtOriginalPrice = shares * price;
|
|
89
|
-
const
|
|
90
|
-
const amountReceived = amountToReceiveBeforeFixed - fixedFee;
|
|
63
|
+
const amountReceived = amountToReceiveBeforeFixed;
|
|
91
64
|
const feeAmount = valueAtOriginalPrice - amountReceived;
|
|
92
65
|
return {
|
|
93
66
|
entryPrice: price,
|
|
@@ -95,8 +68,6 @@ function simulateSellOrder(shares, price, feeBps, customerMarketFeeBps) {
|
|
|
95
68
|
sharesReceived: shares,
|
|
96
69
|
feeAmount,
|
|
97
70
|
feePercentage: (feeAmount / valueAtOriginalPrice) * 100,
|
|
98
|
-
fixedFee,
|
|
99
|
-
volumeFee: feeAmount - fixedFee,
|
|
100
71
|
realEntryPrice: amountReceived / shares
|
|
101
72
|
};
|
|
102
73
|
}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import {
|
|
2
|
+
import { IdlAccounts, Program } 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';
|
|
@@ -26,7 +26,7 @@ export declare const getOrderStatus: (status: OrderStatusEncoded) => OrderStatus
|
|
|
26
26
|
export declare const getOrderDirectionEncoded: (orderDirection: OrderDirection) => OrderDirectionEncoded;
|
|
27
27
|
export declare const getOppositeOrderDirection: (orderDirection: OrderDirection) => OrderDirection;
|
|
28
28
|
export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDirectionEncoded) => OrderDirectionEncoded;
|
|
29
|
-
export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey
|
|
29
|
+
export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey) => Predictor;
|
|
30
30
|
export declare const getPriceFeedAccountForProgram: (priceFeedId: string) => PublicKey;
|
|
31
31
|
export declare const getFeedIdFromHex: (input?: string) => PublicKey | null;
|
|
32
32
|
export declare const getCustomerById: (program: Program<TriadProtocol>, customerId: number) => Promise<Customer>;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -103,10 +103,7 @@ const formatMarket = (account, address) => {
|
|
|
103
103
|
marketStart: account.marketStart.toString(),
|
|
104
104
|
marketEnd: account.marketEnd.toString(),
|
|
105
105
|
question: Buffer.from(account.question).toString().replace(/\0+$/, ''),
|
|
106
|
-
|
|
107
|
-
payoutFeeClaimed: account.payoutFeeClaimed.toString(),
|
|
108
|
-
marketFeeAvailable: account.marketFeeAvailable.toString(),
|
|
109
|
-
marketFeeClaimed: account.marketFeeClaimed.toString(),
|
|
106
|
+
feeGenerated: account.feeGenerated.toString(),
|
|
110
107
|
winningDirection: types_1.WinningDirection[Object.keys(account.winningDirection)[0].toUpperCase()],
|
|
111
108
|
marketLiquidityAtStart: account.marketLiquidityAtStart.toNumber() > 0
|
|
112
109
|
? account.marketLiquidityAtStart.toString()
|
|
@@ -262,13 +259,15 @@ const getOppositeOrderDirectionEncoded = (orderDirection) => {
|
|
|
262
259
|
return { hype: {} };
|
|
263
260
|
};
|
|
264
261
|
exports.getOppositeOrderDirectionEncoded = getOppositeOrderDirectionEncoded;
|
|
265
|
-
const formatPredictor = (account, publicKey
|
|
262
|
+
const formatPredictor = (account, publicKey) => {
|
|
266
263
|
return {
|
|
267
264
|
address: publicKey.toBase58(),
|
|
268
|
-
authority:
|
|
265
|
+
authority: account.authority.toString(),
|
|
269
266
|
refer: account.refer.toString(),
|
|
270
267
|
customerId: account.customerId,
|
|
271
|
-
balance: balance.toNumber() / 1e6
|
|
268
|
+
balance: account.balance.toNumber() / 1e6,
|
|
269
|
+
rewardsAvailable: account.rewardsAvailable.toNumber() / 1e6,
|
|
270
|
+
rewardsClaimed: account.rewardsClaimed.toNumber() / 1e6
|
|
272
271
|
};
|
|
273
272
|
};
|
|
274
273
|
exports.formatPredictor = formatPredictor;
|
|
@@ -8,12 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
-
const getPriorityFee_1 = __importDefault(require("./getPriorityFee"));
|
|
17
13
|
const sendVersionedTransaction = (program, ixs, options, addressLookupTableAccounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
14
|
var _a;
|
|
19
15
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
@@ -21,13 +17,9 @@ const sendVersionedTransaction = (program, ixs, options, addressLookupTableAccou
|
|
|
21
17
|
microLamports: options.microLamports
|
|
22
18
|
}));
|
|
23
19
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
microLamports: priorityFee
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
const { blockhash } = yield program.provider.connection.getLatestBlockhash();
|
|
20
|
+
const { blockhash } = yield program.provider.connection.getLatestBlockhash({
|
|
21
|
+
commitment: 'confirmed'
|
|
22
|
+
});
|
|
31
23
|
if (program.provider.publicKey.toBase58() !== ((_a = options === null || options === void 0 ? void 0 : options.payer) === null || _a === void 0 ? void 0 : _a.toBase58())) {
|
|
32
24
|
return new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
33
25
|
instructions: ixs,
|