@triadxyz/triad-protocol 0.6.2-beta.devnet → 0.6.4-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 +90 -46
- package/dist/trade.d.ts +77 -0
- package/dist/trade.js +7 -3
- 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,85 @@ 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 response = yield triadProtocol.trade.getMarkets();
|
|
149
|
+
console.log(response);
|
|
150
|
+
});
|
|
151
|
+
const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
+
for (const market of markets) {
|
|
153
|
+
try {
|
|
154
|
+
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
155
|
+
skipPreflight: true
|
|
156
|
+
});
|
|
157
|
+
console.log(`Initialized market ${market.name}:`, response);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.error(`Error initializing market ${market.name}:`, error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const getOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
+
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === wallet.publicKey.toBase58());
|
|
166
|
+
console.log(response.account.orders.map((order) => order.orderId.toNumber()));
|
|
167
|
+
return response.account.orders.map((order) => order.orderId.toNumber());
|
|
168
|
+
});
|
|
134
169
|
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
170
|
for (const order of ordersHypeAndFloopBot) {
|
|
136
171
|
const response = yield triadProtocol.trade.openOrder(0, {
|
|
@@ -139,10 +174,19 @@ const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
139
174
|
orderType: order.orderType,
|
|
140
175
|
comment: `hype/flop bot ${order.amount} - ${order.direction}`,
|
|
141
176
|
limitPrice: order.limitPrice
|
|
142
|
-
}, {
|
|
143
|
-
skipPreflight: true
|
|
144
177
|
});
|
|
145
178
|
console.log(response);
|
|
146
179
|
}
|
|
147
180
|
});
|
|
148
|
-
|
|
181
|
+
const closeOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
+
for (const order of yield getOrders()) {
|
|
183
|
+
try {
|
|
184
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
185
|
+
marketId: 0,
|
|
186
|
+
orderId: order
|
|
187
|
+
});
|
|
188
|
+
console.log(response);
|
|
189
|
+
}
|
|
190
|
+
catch (_a) { }
|
|
191
|
+
}
|
|
192
|
+
});
|
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({
|