@triadxyz/triad-protocol 1.5.4-beta → 1.5.6-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.js +2 -1
- package/dist/trade.d.ts +46 -39
- package/dist/trade.js +127 -32
- package/dist/types/idl_triad_protocol.json +86 -409
- package/dist/types/trade.d.ts +22 -4
- package/dist/types/triad_protocol.d.ts +86 -494
- package/dist/utils/helpers.d.ts +3 -2
- package/dist/utils/helpers.js +26 -31
- package/dist/utils/pda/trade.d.ts +1 -0
- package/dist/utils/pda/trade.js +9 -1
- package/dist/utils/swap.js +1 -12
- package/package.json +1 -1
- package/dist/local-test.d.ts +0 -1
- package/dist/local-test.js +0 -619
package/dist/utils/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateStakeRewards = exports.
|
|
3
|
+
exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
|
|
4
4
|
const trade_1 = require("../types/trade");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const encodeString = (value, alloc = 32) => {
|
|
@@ -93,39 +93,34 @@ const formatMarket = (account, address) => {
|
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
exports.formatMarket = formatMarket;
|
|
96
|
-
const
|
|
96
|
+
const formatOrder = (order) => {
|
|
97
97
|
return {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
marketId:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
nftHoldersFeeClaimed: '0',
|
|
122
|
-
marketFeeAvailable: '0',
|
|
123
|
-
marketFeeClaimed: '0',
|
|
124
|
-
winningDirection: trade_1.WinningDirection[Object.keys(account.previousResolvedQuestion.winningDirection)[0].toUpperCase()],
|
|
125
|
-
marketLiquidityAtStart: '0'
|
|
98
|
+
ts: order.ts.toString(),
|
|
99
|
+
orderId: order.orderId.toString(),
|
|
100
|
+
questionId: order.questionId.toString(),
|
|
101
|
+
marketId: order.marketId.toString(),
|
|
102
|
+
status: order.status,
|
|
103
|
+
price: order.price.toString(),
|
|
104
|
+
totalAmount: order.totalAmount.toString(),
|
|
105
|
+
totalShares: order.totalShares.toString(),
|
|
106
|
+
orderType: order.orderType,
|
|
107
|
+
direction: order.direction,
|
|
108
|
+
userNonce: order.userNonce.toString()
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
exports.formatOrder = formatOrder;
|
|
112
|
+
const formatUserTrade = (account, publicKey) => {
|
|
113
|
+
return {
|
|
114
|
+
user: publicKey.toString(),
|
|
115
|
+
totalDeposits: account.totalDeposits.toString(),
|
|
116
|
+
totalWithdraws: account.totalWithdraws.toString(),
|
|
117
|
+
openedOrders: account.openedOrders.toString(),
|
|
118
|
+
orders: account.orders.map((order) => (0, exports.formatOrder)(order)),
|
|
119
|
+
nonce: account.nonce.toString(),
|
|
120
|
+
isSubUser: account.isSubUser
|
|
126
121
|
};
|
|
127
122
|
};
|
|
128
|
-
exports.
|
|
123
|
+
exports.formatUserTrade = formatUserTrade;
|
|
129
124
|
const calculateStakeRewards = (stake, multiplier) => {
|
|
130
125
|
if (stake.withdrawTs !== 0)
|
|
131
126
|
return 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const getMarketPDA: (programId: PublicKey, marketId: number) => PublicKey;
|
|
3
3
|
export declare const getUserTradePDA: (programId: PublicKey, wallet: PublicKey) => PublicKey;
|
|
4
|
+
export declare const getSubUserTradePDA: (programId: PublicKey, wallet: PublicKey, nonce: number) => PublicKey;
|
package/dist/utils/pda/trade.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getUserTradePDA = exports.getMarketPDA = void 0;
|
|
6
|
+
exports.getSubUserTradePDA = exports.getUserTradePDA = exports.getMarketPDA = void 0;
|
|
7
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
8
8
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
9
|
const getMarketPDA = (programId, marketId) => {
|
|
@@ -14,3 +14,11 @@ const getUserTradePDA = (programId, wallet) => {
|
|
|
14
14
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_trade'), wallet.toBuffer()], programId)[0];
|
|
15
15
|
};
|
|
16
16
|
exports.getUserTradePDA = getUserTradePDA;
|
|
17
|
+
const getSubUserTradePDA = (programId, wallet, nonce) => {
|
|
18
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
19
|
+
Buffer.from('sub_user_trade'),
|
|
20
|
+
wallet.toBuffer(),
|
|
21
|
+
new bn_js_1.default(nonce).toArrayLike(Buffer, 'le', 8)
|
|
22
|
+
], programId)[0];
|
|
23
|
+
};
|
|
24
|
+
exports.getSubUserTradePDA = getSubUserTradePDA;
|
package/dist/utils/swap.js
CHANGED
|
@@ -22,7 +22,7 @@ const swap = ({ connection, wallet, inToken, amount }) => __awaiter(void 0, void
|
|
|
22
22
|
throw new Error('Token not found');
|
|
23
23
|
}
|
|
24
24
|
const formattedAmountIn = amount * Math.pow(10, token.decimals);
|
|
25
|
-
const quoteResponse = yield axios_1.default.get(`https://quote-api.jup.ag/v6/quote?inputMint=${inToken}&outputMint=${constants_1.TRD_MINT.toBase58()}&amount=${formattedAmountIn}&slippageBps=
|
|
25
|
+
const quoteResponse = yield axios_1.default.get(`https://quote-api.jup.ag/v6/quote?inputMint=${inToken}&outputMint=${constants_1.TRD_MINT.toBase58()}&amount=${formattedAmountIn}&slippageBps=60`);
|
|
26
26
|
const { data: quoteData } = quoteResponse;
|
|
27
27
|
const swapResponse = yield axios_1.default.post('https://quote-api.jup.ag/v6/swap-instructions', {
|
|
28
28
|
userPublicKey: wallet,
|
|
@@ -35,9 +35,6 @@ const swap = ({ connection, wallet, inToken, amount }) => __awaiter(void 0, void
|
|
|
35
35
|
deserializeInstruction(swapInstruction),
|
|
36
36
|
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
37
37
|
units: 500000
|
|
38
|
-
}),
|
|
39
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
40
|
-
microLamports: yield getPriorityFee()
|
|
41
38
|
})
|
|
42
39
|
],
|
|
43
40
|
addressLookupTableAccounts: yield (0, exports.getAddressLookupTableAccounts)(connection, addressLookupTableAddresses),
|
|
@@ -73,15 +70,7 @@ const getAddressLookupTableAccounts = (connection, keys) => __awaiter(void 0, vo
|
|
|
73
70
|
}, new Array());
|
|
74
71
|
});
|
|
75
72
|
exports.getAddressLookupTableAccounts = getAddressLookupTableAccounts;
|
|
76
|
-
const getPriorityFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
-
const response = yield axios_1.default.get('https://solanacompass.com/api/fees');
|
|
78
|
-
return response.data[15].priorityTx || 1000;
|
|
79
|
-
});
|
|
80
73
|
const TOKENS = {
|
|
81
|
-
oreoU2P8bN6jkk3jbaiVxYnG1dCXcYxwhwyK9jSybcp: {
|
|
82
|
-
mint: 'oreoU2P8bN6jkk3jbaiVxYnG1dCXcYxwhwyK9jSybcp',
|
|
83
|
-
decimals: 11
|
|
84
|
-
},
|
|
85
74
|
So11111111111111111111111111111111111111112: {
|
|
86
75
|
mint: 'So11111111111111111111111111111111111111112',
|
|
87
76
|
decimals: 9
|
package/package.json
CHANGED
package/dist/local-test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|