@triadxyz/triad-protocol 0.6.2-beta.devnet → 0.6.5-beta.devnet
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/local-test.js +95 -46
- package/dist/trade.d.ts +77 -0
- package/dist/trade.js +7 -3
- package/dist/types/idl_triad_protocol.json +9 -9
- package/dist/types/triad_protocol.d.ts +9 -9
- package/package.json +1 -1
package/dist/local-test.js
CHANGED
|
@@ -17,7 +17,7 @@ const index_1 = __importDefault(require("./index"));
|
|
|
17
17
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
-
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/
|
|
20
|
+
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
21
21
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc-devnet.txt');
|
|
22
22
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
23
23
|
const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
|
|
@@ -33,48 +33,6 @@ const markets = [
|
|
|
33
33
|
{ name: 'ISLANDDAO/TRD', marketId: 6 },
|
|
34
34
|
{ name: 'COLOSSEUM/TRD', marketId: 7 }
|
|
35
35
|
];
|
|
36
|
-
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
-
const response = yield triadProtocol.stake.updateStakeVault({
|
|
38
|
-
wallet: wallet.publicKey
|
|
39
|
-
});
|
|
40
|
-
console.log(response);
|
|
41
|
-
});
|
|
42
|
-
const updateBoost = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
const response = (yield axios_1.default.get('https://api.triadfi.co/boost'))
|
|
44
|
-
.data;
|
|
45
|
-
const stakes = yield triadProtocol.stake.getStakes();
|
|
46
|
-
const update = [];
|
|
47
|
-
for (const stake of stakes) {
|
|
48
|
-
if (update.length >= 10) {
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
if (response.includes(stake.mint) && !stake.boost) {
|
|
52
|
-
update.push({ name: stake.name, wallet: stake.authority });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const updateBoostResponse = yield triadProtocol.stake.updateBoost({
|
|
56
|
-
wallet: wallet.publicKey,
|
|
57
|
-
nfts: update
|
|
58
|
-
});
|
|
59
|
-
console.log(updateBoostResponse);
|
|
60
|
-
});
|
|
61
|
-
const getMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
const response = yield triadProtocol.trade.getMarkets();
|
|
63
|
-
console.log(response);
|
|
64
|
-
});
|
|
65
|
-
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
for (const market of markets) {
|
|
67
|
-
try {
|
|
68
|
-
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
69
|
-
skipPreflight: true
|
|
70
|
-
});
|
|
71
|
-
console.log(`Initialized market ${market.name}:`, response);
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error(`Error initializing market ${market.name}:`, error);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
36
|
const ordersHypeAndFloopBot = [
|
|
79
37
|
{
|
|
80
38
|
marketId: 0,
|
|
@@ -129,8 +87,90 @@ const ordersHypeAndFloopBot = [
|
|
|
129
87
|
orderType: {
|
|
130
88
|
market: {}
|
|
131
89
|
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
marketId: 0,
|
|
93
|
+
amount: 123,
|
|
94
|
+
direction: {
|
|
95
|
+
flop: {}
|
|
96
|
+
},
|
|
97
|
+
orderType: {
|
|
98
|
+
market: {}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
marketId: 0,
|
|
103
|
+
amount: 12003,
|
|
104
|
+
direction: {
|
|
105
|
+
flop: {}
|
|
106
|
+
},
|
|
107
|
+
orderType: {
|
|
108
|
+
market: {}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
marketId: 0,
|
|
113
|
+
amount: 12003,
|
|
114
|
+
direction: {
|
|
115
|
+
hype: {}
|
|
116
|
+
},
|
|
117
|
+
orderType: {
|
|
118
|
+
market: {}
|
|
119
|
+
}
|
|
132
120
|
}
|
|
133
121
|
];
|
|
122
|
+
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
const response = yield triadProtocol.stake.updateStakeVault({
|
|
124
|
+
wallet: wallet.publicKey
|
|
125
|
+
});
|
|
126
|
+
console.log(response);
|
|
127
|
+
});
|
|
128
|
+
const updateBoost = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
const response = (yield axios_1.default.get('https://api.triadfi.co/boost'))
|
|
130
|
+
.data;
|
|
131
|
+
const stakes = yield triadProtocol.stake.getStakes();
|
|
132
|
+
const update = [];
|
|
133
|
+
for (const stake of stakes) {
|
|
134
|
+
if (update.length >= 10) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
if (response.includes(stake.mint) && !stake.boost) {
|
|
138
|
+
update.push({ name: stake.name, wallet: stake.authority });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const updateBoostResponse = yield triadProtocol.stake.updateBoost({
|
|
142
|
+
wallet: wallet.publicKey,
|
|
143
|
+
nfts: update
|
|
144
|
+
});
|
|
145
|
+
console.log(updateBoostResponse);
|
|
146
|
+
});
|
|
147
|
+
const getMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
|
+
// const acc = await connection.getAccountInfo(
|
|
149
|
+
// new PublicKey('2J7uYG9ND5pf4px8ABZBh2QtB5wrhkgRcSZvVDA3NZxk')
|
|
150
|
+
// )
|
|
151
|
+
// console.log(JSON.stringify(acc.data, null, 2))
|
|
152
|
+
const markets = yield triadProtocol.trade.getMarkets();
|
|
153
|
+
console.log(markets);
|
|
154
|
+
});
|
|
155
|
+
getMarkets();
|
|
156
|
+
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
for (const market of markets) {
|
|
158
|
+
try {
|
|
159
|
+
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
160
|
+
skipPreflight: true
|
|
161
|
+
});
|
|
162
|
+
console.log(`Initialized market ${market.name}:`, response);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(`Error initializing market ${market.name}:`, error);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
const getOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
170
|
+
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === wallet.publicKey.toBase58());
|
|
171
|
+
console.log(response.account.orders.map((order) => order.orderId.toNumber()));
|
|
172
|
+
return response.account.orders.map((order) => order.orderId.toNumber());
|
|
173
|
+
});
|
|
134
174
|
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
175
|
for (const order of ordersHypeAndFloopBot) {
|
|
136
176
|
const response = yield triadProtocol.trade.openOrder(0, {
|
|
@@ -139,10 +179,19 @@ const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
139
179
|
orderType: order.orderType,
|
|
140
180
|
comment: `hype/flop bot ${order.amount} - ${order.direction}`,
|
|
141
181
|
limitPrice: order.limitPrice
|
|
142
|
-
}, {
|
|
143
|
-
skipPreflight: true
|
|
144
182
|
});
|
|
145
183
|
console.log(response);
|
|
146
184
|
}
|
|
147
185
|
});
|
|
148
|
-
|
|
186
|
+
const closeOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
187
|
+
for (const order of yield getOrders()) {
|
|
188
|
+
try {
|
|
189
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
190
|
+
marketId: 0,
|
|
191
|
+
orderId: order
|
|
192
|
+
});
|
|
193
|
+
console.log(response);
|
|
194
|
+
}
|
|
195
|
+
catch (_a) { }
|
|
196
|
+
}
|
|
197
|
+
});
|
package/dist/trade.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { TriadProtocol } from './types/triad_protocol';
|
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { Market, OrderDirection, OrderType } from './types/trade';
|
|
5
5
|
import { RpcOptions } from './types';
|
|
6
|
+
import BN from 'bn.js';
|
|
6
7
|
export default class Trade {
|
|
7
8
|
program: Program<TriadProtocol>;
|
|
8
9
|
provider: AnchorProvider;
|
|
@@ -23,6 +24,82 @@ export default class Trade {
|
|
|
23
24
|
marketId: number;
|
|
24
25
|
name: string;
|
|
25
26
|
}, options?: RpcOptions): Promise<string>;
|
|
27
|
+
getUserTrade(): Promise<{
|
|
28
|
+
bump: number;
|
|
29
|
+
authority: PublicKey;
|
|
30
|
+
totalDeposits: BN;
|
|
31
|
+
totalWithdraws: BN;
|
|
32
|
+
openOrders: number;
|
|
33
|
+
hasOpenOrder: boolean;
|
|
34
|
+
orders: {
|
|
35
|
+
ts: BN;
|
|
36
|
+
orderId: BN;
|
|
37
|
+
marketId: BN;
|
|
38
|
+
status: ({
|
|
39
|
+
open?: never;
|
|
40
|
+
filled?: never;
|
|
41
|
+
canceled?: never;
|
|
42
|
+
closed?: never;
|
|
43
|
+
} & {
|
|
44
|
+
init: Record<string, never>;
|
|
45
|
+
}) | ({
|
|
46
|
+
init?: never;
|
|
47
|
+
filled?: never;
|
|
48
|
+
canceled?: never;
|
|
49
|
+
closed?: never;
|
|
50
|
+
} & {
|
|
51
|
+
open: Record<string, never>;
|
|
52
|
+
}) | ({
|
|
53
|
+
init?: never;
|
|
54
|
+
open?: never;
|
|
55
|
+
canceled?: never;
|
|
56
|
+
closed?: never;
|
|
57
|
+
} & {
|
|
58
|
+
filled: Record<string, never>;
|
|
59
|
+
}) | ({
|
|
60
|
+
init?: never;
|
|
61
|
+
open?: never;
|
|
62
|
+
filled?: never;
|
|
63
|
+
closed?: never;
|
|
64
|
+
} & {
|
|
65
|
+
canceled: Record<string, never>;
|
|
66
|
+
}) | ({
|
|
67
|
+
init?: never;
|
|
68
|
+
open?: never;
|
|
69
|
+
filled?: never;
|
|
70
|
+
canceled?: never;
|
|
71
|
+
} & {
|
|
72
|
+
closed: Record<string, never>;
|
|
73
|
+
});
|
|
74
|
+
price: BN;
|
|
75
|
+
totalAmount: BN;
|
|
76
|
+
totalShares: BN;
|
|
77
|
+
filledAmount: BN;
|
|
78
|
+
filledShares: BN;
|
|
79
|
+
orderType: ({
|
|
80
|
+
limit?: never;
|
|
81
|
+
} & {
|
|
82
|
+
market: Record<string, never>;
|
|
83
|
+
}) | ({
|
|
84
|
+
market?: never;
|
|
85
|
+
} & {
|
|
86
|
+
limit: Record<string, never>;
|
|
87
|
+
});
|
|
88
|
+
direction: ({
|
|
89
|
+
flop?: never;
|
|
90
|
+
} & {
|
|
91
|
+
hype: Record<string, never>;
|
|
92
|
+
}) | ({
|
|
93
|
+
hype?: never;
|
|
94
|
+
} & {
|
|
95
|
+
flop: Record<string, never>;
|
|
96
|
+
});
|
|
97
|
+
settledPnl: BN;
|
|
98
|
+
padding: number[];
|
|
99
|
+
}[];
|
|
100
|
+
position: BN;
|
|
101
|
+
padding: number[];
|
|
102
|
+
}>;
|
|
26
103
|
openOrder(marketId: number, args: {
|
|
27
104
|
amount: number;
|
|
28
105
|
direction: OrderDirection;
|
package/dist/trade.js
CHANGED
|
@@ -109,6 +109,12 @@ class Trade {
|
|
|
109
109
|
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
+
getUserTrade() {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(this.program.programId, this.provider.publicKey);
|
|
115
|
+
return this.program.account.userTrade.fetch(userTradePDA);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
112
118
|
openOrder(marketId, args, options) {
|
|
113
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
120
|
const marketPDA = (0, helpers_1.getMarketAddressSync)(this.program.programId, marketId);
|
|
@@ -130,9 +136,7 @@ class Trade {
|
|
|
130
136
|
amount: new bn_js_1.default(args.amount * Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
131
137
|
direction: args.direction,
|
|
132
138
|
orderType: args.orderType,
|
|
133
|
-
limitPrice: args.limitPrice
|
|
134
|
-
? new bn_js_1.default(args.limitPrice * Math.pow(10, constants_1.TRD_DECIMALS))
|
|
135
|
-
: undefined,
|
|
139
|
+
limitPrice: new bn_js_1.default(args.limitPrice * Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
136
140
|
comment: (0, helpers_1.encodeString)(args.comment, 64)
|
|
137
141
|
})
|
|
138
142
|
.accounts({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"address": "
|
|
2
|
+
"address": "4tKAoWz98eYiNh19UwBYzdqsNmTCrdwV4vMqdUwJi35E",
|
|
3
3
|
"metadata": {
|
|
4
4
|
"name": "triad_protocol",
|
|
5
5
|
"version": "0.1.4",
|
|
@@ -353,7 +353,7 @@
|
|
|
353
353
|
"seeds": [
|
|
354
354
|
{
|
|
355
355
|
"kind": "account",
|
|
356
|
-
"path": "
|
|
356
|
+
"path": "market"
|
|
357
357
|
},
|
|
358
358
|
{
|
|
359
359
|
"kind": "account",
|
|
@@ -1376,11 +1376,11 @@
|
|
|
1376
1376
|
},
|
|
1377
1377
|
{
|
|
1378
1378
|
"name": "deposited",
|
|
1379
|
-
"type": "
|
|
1379
|
+
"type": "u64"
|
|
1380
1380
|
},
|
|
1381
1381
|
{
|
|
1382
1382
|
"name": "withdrawn",
|
|
1383
|
-
"type": "
|
|
1383
|
+
"type": "u64"
|
|
1384
1384
|
},
|
|
1385
1385
|
{
|
|
1386
1386
|
"name": "net_balance",
|
|
@@ -1392,7 +1392,7 @@
|
|
|
1392
1392
|
},
|
|
1393
1393
|
{
|
|
1394
1394
|
"name": "project_claimed",
|
|
1395
|
-
"type": "
|
|
1395
|
+
"type": "u64"
|
|
1396
1396
|
},
|
|
1397
1397
|
{
|
|
1398
1398
|
"name": "nft_holders_available",
|
|
@@ -1400,7 +1400,7 @@
|
|
|
1400
1400
|
},
|
|
1401
1401
|
{
|
|
1402
1402
|
"name": "nft_holders_claimed",
|
|
1403
|
-
"type": "
|
|
1403
|
+
"type": "u64"
|
|
1404
1404
|
},
|
|
1405
1405
|
{
|
|
1406
1406
|
"name": "market_available",
|
|
@@ -1408,7 +1408,7 @@
|
|
|
1408
1408
|
},
|
|
1409
1409
|
{
|
|
1410
1410
|
"name": "market_claimed",
|
|
1411
|
-
"type": "
|
|
1411
|
+
"type": "u64"
|
|
1412
1412
|
},
|
|
1413
1413
|
{
|
|
1414
1414
|
"name": "padding",
|
|
@@ -1496,7 +1496,7 @@
|
|
|
1496
1496
|
{
|
|
1497
1497
|
"name": "total_volume",
|
|
1498
1498
|
"docs": ["Total trading volume (in TRD)"],
|
|
1499
|
-
"type": "
|
|
1499
|
+
"type": "u64"
|
|
1500
1500
|
},
|
|
1501
1501
|
{
|
|
1502
1502
|
"name": "vault_token_account",
|
|
@@ -1551,7 +1551,7 @@
|
|
|
1551
1551
|
{
|
|
1552
1552
|
"name": "padding",
|
|
1553
1553
|
"type": {
|
|
1554
|
-
"array": ["u8",
|
|
1554
|
+
"array": ["u8", 242]
|
|
1555
1555
|
}
|
|
1556
1556
|
}
|
|
1557
1557
|
]
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* IDL can be found at `target/idl/triad_protocol.json`.
|
|
6
6
|
*/
|
|
7
7
|
export type TriadProtocol = {
|
|
8
|
-
address: '
|
|
8
|
+
address: '4tKAoWz98eYiNh19UwBYzdqsNmTCrdwV4vMqdUwJi35E';
|
|
9
9
|
metadata: {
|
|
10
10
|
name: 'triadProtocol';
|
|
11
11
|
version: '0.1.4';
|
|
@@ -475,7 +475,7 @@ export type TriadProtocol = {
|
|
|
475
475
|
seeds: [
|
|
476
476
|
{
|
|
477
477
|
kind: 'account';
|
|
478
|
-
path: '
|
|
478
|
+
path: 'market';
|
|
479
479
|
},
|
|
480
480
|
{
|
|
481
481
|
kind: 'account';
|
|
@@ -1875,11 +1875,11 @@ export type TriadProtocol = {
|
|
|
1875
1875
|
},
|
|
1876
1876
|
{
|
|
1877
1877
|
name: 'deposited';
|
|
1878
|
-
type: '
|
|
1878
|
+
type: 'u64';
|
|
1879
1879
|
},
|
|
1880
1880
|
{
|
|
1881
1881
|
name: 'withdrawn';
|
|
1882
|
-
type: '
|
|
1882
|
+
type: 'u64';
|
|
1883
1883
|
},
|
|
1884
1884
|
{
|
|
1885
1885
|
name: 'netBalance';
|
|
@@ -1891,7 +1891,7 @@ export type TriadProtocol = {
|
|
|
1891
1891
|
},
|
|
1892
1892
|
{
|
|
1893
1893
|
name: 'projectClaimed';
|
|
1894
|
-
type: '
|
|
1894
|
+
type: 'u64';
|
|
1895
1895
|
},
|
|
1896
1896
|
{
|
|
1897
1897
|
name: 'nftHoldersAvailable';
|
|
@@ -1899,7 +1899,7 @@ export type TriadProtocol = {
|
|
|
1899
1899
|
},
|
|
1900
1900
|
{
|
|
1901
1901
|
name: 'nftHoldersClaimed';
|
|
1902
|
-
type: '
|
|
1902
|
+
type: 'u64';
|
|
1903
1903
|
},
|
|
1904
1904
|
{
|
|
1905
1905
|
name: 'marketAvailable';
|
|
@@ -1907,7 +1907,7 @@ export type TriadProtocol = {
|
|
|
1907
1907
|
},
|
|
1908
1908
|
{
|
|
1909
1909
|
name: 'marketClaimed';
|
|
1910
|
-
type: '
|
|
1910
|
+
type: 'u64';
|
|
1911
1911
|
},
|
|
1912
1912
|
{
|
|
1913
1913
|
name: 'padding';
|
|
@@ -1995,7 +1995,7 @@ export type TriadProtocol = {
|
|
|
1995
1995
|
{
|
|
1996
1996
|
name: 'totalVolume';
|
|
1997
1997
|
docs: ['Total trading volume (in TRD)'];
|
|
1998
|
-
type: '
|
|
1998
|
+
type: 'u64';
|
|
1999
1999
|
},
|
|
2000
2000
|
{
|
|
2001
2001
|
name: 'vaultTokenAccount';
|
|
@@ -2050,7 +2050,7 @@ export type TriadProtocol = {
|
|
|
2050
2050
|
{
|
|
2051
2051
|
name: 'padding';
|
|
2052
2052
|
type: {
|
|
2053
|
-
array: ['u8',
|
|
2053
|
+
array: ['u8', 242];
|
|
2054
2054
|
};
|
|
2055
2055
|
}
|
|
2056
2056
|
];
|