@triadxyz/triad-protocol 0.6.8-beta.devnet → 0.7.0-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/index.d.ts +2 -2
- package/dist/index.js +4 -5
- package/dist/local-test.js +53 -20
- package/dist/stake.d.ts +2 -2
- package/dist/stake.js +21 -16
- package/dist/trade.d.ts +3 -26
- package/dist/trade.js +41 -34
- package/dist/types/idl_triad_protocol.json +184 -174
- package/dist/types/index.d.ts +10 -0
- package/dist/types/stake.d.ts +2 -19
- package/dist/types/stake.js +1 -9
- package/dist/types/trade.d.ts +13 -12
- package/dist/types/triad_protocol.d.ts +180 -230
- package/dist/utils/formatNumber.d.ts +3 -0
- package/dist/utils/formatNumber.js +6 -0
- package/dist/utils/{getRarity.d.ts → getRarityRank.d.ts} +2 -1
- package/dist/utils/{getRarity.js → getRarityRank.js} +1 -2
- package/dist/utils/helpers.d.ts +5 -26
- package/dist/utils/helpers.js +1 -72
- package/dist/utils/pda/index.d.ts +4 -0
- package/dist/utils/pda/index.js +17 -0
- package/dist/utils/pda/stake.d.ts +4 -0
- package/dist/utils/pda/stake.js +16 -0
- package/dist/utils/pda/trade.d.ts +4 -0
- package/dist/utils/pda/trade.js +20 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,12 +14,12 @@ export default class TriadProtocolClient {
|
|
|
14
14
|
* Get User by wallet
|
|
15
15
|
* @param wallet - User wallet
|
|
16
16
|
*/
|
|
17
|
-
getUser(wallet: PublicKey): Promise<import("./types
|
|
17
|
+
getUser(wallet: PublicKey): Promise<import("./types").User>;
|
|
18
18
|
/**
|
|
19
19
|
* Get User by wallet
|
|
20
20
|
* @param wallet - User wallet
|
|
21
21
|
*/
|
|
22
|
-
getUsers(): Promise<import("./types
|
|
22
|
+
getUsers(): Promise<import("./types").User[]>;
|
|
23
23
|
/**
|
|
24
24
|
* Check if user exists
|
|
25
25
|
* @param username - User name
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
17
17
|
const idl_triad_protocol_json_1 = __importDefault(require("./types/idl_triad_protocol.json"));
|
|
18
18
|
const trade_1 = __importDefault(require("./trade"));
|
|
19
19
|
const helpers_1 = require("./utils/helpers");
|
|
20
|
+
const pda_1 = require("./utils/pda");
|
|
20
21
|
const stake_1 = __importDefault(require("./stake"));
|
|
21
22
|
class TriadProtocolClient {
|
|
22
23
|
constructor(connection, wallet) {
|
|
@@ -31,9 +32,8 @@ class TriadProtocolClient {
|
|
|
31
32
|
*/
|
|
32
33
|
getUser(wallet) {
|
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
return (0, helpers_1.formatUser)(response);
|
|
35
|
+
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
36
|
+
return (0, helpers_1.formatUser)(yield this.program.account.user.fetch(userPDA));
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -55,7 +55,7 @@ class TriadProtocolClient {
|
|
|
55
55
|
hasUser(wallet) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
57
|
try {
|
|
58
|
-
yield this.program.account.user.fetch((0,
|
|
58
|
+
yield this.program.account.user.fetch((0, pda_1.getUserPDA)(this.program.programId, wallet));
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
catch (_a) {
|
|
@@ -104,7 +104,6 @@ class TriadProtocolClient {
|
|
|
104
104
|
})
|
|
105
105
|
.accounts({
|
|
106
106
|
signer: wallet,
|
|
107
|
-
payer: wallet,
|
|
108
107
|
referral
|
|
109
108
|
});
|
|
110
109
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
package/dist/local-test.js
CHANGED
|
@@ -24,19 +24,19 @@ const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
|
|
|
24
24
|
const wallet = new anchor_1.Wallet(keypair);
|
|
25
25
|
const triadProtocol = new index_1.default(connection, wallet);
|
|
26
26
|
const markets = [
|
|
27
|
-
{ name: '
|
|
28
|
-
{ name: '
|
|
29
|
-
{ name: '
|
|
30
|
-
{ name: '
|
|
31
|
-
{ name: '
|
|
32
|
-
{ name: '
|
|
33
|
-
{ name: '
|
|
34
|
-
{ name: '
|
|
27
|
+
{ name: 'Jupiter', marketId: 0 },
|
|
28
|
+
{ name: 'Drift', marketId: 1 },
|
|
29
|
+
{ name: 'Pyth', marketId: 2 },
|
|
30
|
+
{ name: 'Undead', marketId: 3 },
|
|
31
|
+
{ name: 'MadLads', marketId: 4 },
|
|
32
|
+
{ name: 'DeGods', marketId: 5 },
|
|
33
|
+
{ name: 'IslandDAO', marketId: 6 },
|
|
34
|
+
{ name: 'Colosseum', marketId: 7 }
|
|
35
35
|
];
|
|
36
36
|
const ordersHypeAndFloopBot = [
|
|
37
37
|
{
|
|
38
38
|
marketId: 0,
|
|
39
|
-
amount:
|
|
39
|
+
amount: 100,
|
|
40
40
|
direction: {
|
|
41
41
|
hype: {}
|
|
42
42
|
},
|
|
@@ -47,7 +47,7 @@ const ordersHypeAndFloopBot = [
|
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
marketId: 0,
|
|
50
|
-
amount:
|
|
50
|
+
amount: 300,
|
|
51
51
|
direction: {
|
|
52
52
|
flop: {}
|
|
53
53
|
},
|
|
@@ -58,29 +58,29 @@ const ordersHypeAndFloopBot = [
|
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
marketId: 0,
|
|
61
|
-
amount:
|
|
61
|
+
amount: 429,
|
|
62
62
|
direction: {
|
|
63
63
|
hype: {}
|
|
64
64
|
},
|
|
65
65
|
orderType: {
|
|
66
|
-
|
|
66
|
+
limit: {}
|
|
67
67
|
},
|
|
68
68
|
limitPrice: 0.8
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
marketId: 0,
|
|
72
|
-
amount:
|
|
72
|
+
amount: 249,
|
|
73
73
|
direction: {
|
|
74
74
|
flop: {}
|
|
75
75
|
},
|
|
76
76
|
orderType: {
|
|
77
|
-
|
|
77
|
+
limit: {}
|
|
78
78
|
},
|
|
79
79
|
limitPrice: 0.2
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
marketId: 0,
|
|
83
|
-
amount:
|
|
83
|
+
amount: 369,
|
|
84
84
|
direction: {
|
|
85
85
|
hype: {}
|
|
86
86
|
},
|
|
@@ -90,7 +90,7 @@ const ordersHypeAndFloopBot = [
|
|
|
90
90
|
},
|
|
91
91
|
{
|
|
92
92
|
marketId: 0,
|
|
93
|
-
amount:
|
|
93
|
+
amount: 369,
|
|
94
94
|
direction: {
|
|
95
95
|
flop: {}
|
|
96
96
|
},
|
|
@@ -100,7 +100,7 @@ const ordersHypeAndFloopBot = [
|
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
marketId: 0,
|
|
103
|
-
amount:
|
|
103
|
+
amount: 369,
|
|
104
104
|
direction: {
|
|
105
105
|
flop: {}
|
|
106
106
|
},
|
|
@@ -110,7 +110,27 @@ const ordersHypeAndFloopBot = [
|
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
marketId: 0,
|
|
113
|
-
amount:
|
|
113
|
+
amount: 369,
|
|
114
|
+
direction: {
|
|
115
|
+
hype: {}
|
|
116
|
+
},
|
|
117
|
+
orderType: {
|
|
118
|
+
market: {}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
marketId: 0,
|
|
123
|
+
amount: 369,
|
|
124
|
+
direction: {
|
|
125
|
+
hype: {}
|
|
126
|
+
},
|
|
127
|
+
orderType: {
|
|
128
|
+
market: {}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
marketId: 0,
|
|
133
|
+
amount: 369,
|
|
114
134
|
direction: {
|
|
115
135
|
hype: {}
|
|
116
136
|
},
|
|
@@ -163,7 +183,7 @@ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
163
183
|
});
|
|
164
184
|
const getOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
185
|
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === wallet.publicKey.toBase58());
|
|
166
|
-
console.log(response
|
|
186
|
+
console.log(response);
|
|
167
187
|
return response.account.orders.map((order) => order.orderId.toNumber());
|
|
168
188
|
});
|
|
169
189
|
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -174,11 +194,12 @@ const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
174
194
|
orderType: order.orderType,
|
|
175
195
|
comment: `hype/flop bot ${order.amount} - ${order.direction}`,
|
|
176
196
|
limitPrice: order.limitPrice
|
|
197
|
+
}, {
|
|
198
|
+
skipPreflight: true
|
|
177
199
|
});
|
|
178
200
|
console.log(response);
|
|
179
201
|
}
|
|
180
202
|
});
|
|
181
|
-
openOrder();
|
|
182
203
|
const closeOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
204
|
for (const order of yield getOrders()) {
|
|
184
205
|
try {
|
|
@@ -191,3 +212,15 @@ const closeOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
191
212
|
catch (_a) { }
|
|
192
213
|
}
|
|
193
214
|
});
|
|
215
|
+
const runBot = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
|
+
while (true) {
|
|
217
|
+
const hasOpenOrders = (yield getOrders()).find((order) => order !== 0);
|
|
218
|
+
if (hasOpenOrders) {
|
|
219
|
+
yield closeOrder();
|
|
220
|
+
}
|
|
221
|
+
yield openOrder();
|
|
222
|
+
yield new Promise((resolve) => setTimeout(resolve, 40000));
|
|
223
|
+
yield closeOrder();
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
openOrder();
|
package/dist/stake.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
4
|
import { TriadProtocol } from './types/triad_protocol';
|
|
5
5
|
import { RpcOptions } from './types';
|
|
6
|
-
import { UpdateStakeVaultArgs, StakeNftArgs, RequestWithdrawArgs, WithdrawArgs, StakeResponse, ClaimStakeRewardsArgs, StakeTokenArgs, UpdateBoostArgs } from './types/stake';
|
|
6
|
+
import { UpdateStakeVaultArgs, StakeNftArgs, RequestWithdrawArgs, WithdrawArgs, Stake as StakeResponse, ClaimStakeRewardsArgs, StakeTokenArgs, UpdateBoostArgs } from './types/stake';
|
|
7
7
|
export default class Stake {
|
|
8
8
|
program: Program<TriadProtocol>;
|
|
9
9
|
provider: AnchorProvider;
|
|
@@ -12,7 +12,7 @@ export default class Stake {
|
|
|
12
12
|
/**
|
|
13
13
|
* Get all Stake Vaults
|
|
14
14
|
*/
|
|
15
|
-
getStakeVaults(): Promise<import("./types/stake").
|
|
15
|
+
getStakeVaults(): Promise<import("./types/stake").StakeVault[]>;
|
|
16
16
|
/**
|
|
17
17
|
* Get Stake Rewards
|
|
18
18
|
*/
|
package/dist/stake.js
CHANGED
|
@@ -8,13 +8,18 @@ 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
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
13
16
|
const web3_js_1 = require("@solana/web3.js");
|
|
14
17
|
const helpers_1 = require("./utils/helpers");
|
|
18
|
+
const stake_1 = require("./utils/pda/stake");
|
|
19
|
+
const pda_1 = require("./utils/pda");
|
|
15
20
|
const constants_1 = require("./utils/constants");
|
|
16
21
|
const base64_js_1 = require("base64-js");
|
|
17
|
-
const
|
|
22
|
+
const getRarityRank_1 = __importDefault(require("./utils/getRarityRank"));
|
|
18
23
|
class Stake {
|
|
19
24
|
constructor(program, provider) {
|
|
20
25
|
this.stakeVaultName = constants_1.STAKE_VAULT_NAME;
|
|
@@ -35,8 +40,8 @@ class Stake {
|
|
|
35
40
|
*/
|
|
36
41
|
getStakeRewards({ wallet, nftName, collections, rank }) {
|
|
37
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const stakeVaultPDA = (0,
|
|
39
|
-
const stakePDA = (0,
|
|
43
|
+
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
44
|
+
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, nftName);
|
|
40
45
|
const method = yield this.program.methods
|
|
41
46
|
.claimStakeRewards({
|
|
42
47
|
collections,
|
|
@@ -90,14 +95,14 @@ class Stake {
|
|
|
90
95
|
const response = yield this.getUserStakes(wallet);
|
|
91
96
|
const data = [];
|
|
92
97
|
for (const stake of response) {
|
|
93
|
-
const
|
|
98
|
+
const rank = (0, getRarityRank_1.default)(ranks, stake.mint, stake.name);
|
|
94
99
|
let available = 0;
|
|
95
100
|
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
96
101
|
try {
|
|
97
102
|
available = yield this.getStakeRewards({
|
|
98
103
|
wallet,
|
|
99
104
|
nftName: stake.name,
|
|
100
|
-
rank
|
|
105
|
+
rank,
|
|
101
106
|
collections
|
|
102
107
|
});
|
|
103
108
|
}
|
|
@@ -154,7 +159,7 @@ class Stake {
|
|
|
154
159
|
*/
|
|
155
160
|
stakeToken({ name, wallet, amount }, options) {
|
|
156
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
-
const userPDA = (0,
|
|
162
|
+
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
158
163
|
const method = this.program.methods
|
|
159
164
|
.stakeToken({
|
|
160
165
|
name,
|
|
@@ -213,9 +218,9 @@ class Stake {
|
|
|
213
218
|
*/
|
|
214
219
|
requestWithdraw({ wallet, name, mint }, options) {
|
|
215
220
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
const stakeVaultPDA = (0,
|
|
217
|
-
const stakePDA = (0,
|
|
218
|
-
const userPDA = (0,
|
|
221
|
+
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
222
|
+
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, name);
|
|
223
|
+
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
219
224
|
const method = this.program.methods.requestWithdrawStake().accounts({
|
|
220
225
|
signer: wallet,
|
|
221
226
|
mint: mint,
|
|
@@ -242,9 +247,9 @@ class Stake {
|
|
|
242
247
|
*/
|
|
243
248
|
withdrawStake({ wallet, name, mint }, options) {
|
|
244
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
-
const stakeVaultPDA = (0,
|
|
246
|
-
const userPDA = (0,
|
|
247
|
-
const stakePDA = (0,
|
|
250
|
+
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
251
|
+
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, wallet);
|
|
252
|
+
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, name);
|
|
248
253
|
const method = this.program.methods.withdrawStake().accounts({
|
|
249
254
|
signer: wallet,
|
|
250
255
|
stake: stakePDA,
|
|
@@ -272,8 +277,8 @@ class Stake {
|
|
|
272
277
|
*/
|
|
273
278
|
claimStakeRewards({ wallet, nftName, collections, rank }, options) {
|
|
274
279
|
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
-
const stakeVaultPDA = (0,
|
|
276
|
-
const stakePDA = (0,
|
|
280
|
+
const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
|
|
281
|
+
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, nftName);
|
|
277
282
|
const method = this.program.methods
|
|
278
283
|
.claimStakeRewards({
|
|
279
284
|
collections,
|
|
@@ -306,12 +311,12 @@ class Stake {
|
|
|
306
311
|
return __awaiter(this, void 0, void 0, function* () {
|
|
307
312
|
const ixs = [];
|
|
308
313
|
for (const nft of nfts) {
|
|
309
|
-
const
|
|
314
|
+
const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, new web3_js_1.PublicKey(nft.wallet), nft.name);
|
|
310
315
|
ixs.push(yield this.program.methods
|
|
311
316
|
.updateStakeBoost()
|
|
312
317
|
.accounts({
|
|
313
318
|
signer: wallet,
|
|
314
|
-
stake:
|
|
319
|
+
stake: stakePDA
|
|
315
320
|
})
|
|
316
321
|
.instruction());
|
|
317
322
|
}
|
package/dist/trade.d.ts
CHANGED
|
@@ -29,53 +29,31 @@ export default class Trade {
|
|
|
29
29
|
authority: PublicKey;
|
|
30
30
|
totalDeposits: BN;
|
|
31
31
|
totalWithdraws: BN;
|
|
32
|
-
|
|
33
|
-
hasOpenOrder: boolean;
|
|
32
|
+
openedOrders: BN;
|
|
34
33
|
orders: {
|
|
35
34
|
ts: BN;
|
|
36
35
|
orderId: BN;
|
|
36
|
+
questionId: BN;
|
|
37
37
|
marketId: BN;
|
|
38
38
|
status: ({
|
|
39
39
|
open?: never;
|
|
40
|
-
filled?: never;
|
|
41
|
-
canceled?: never;
|
|
42
40
|
closed?: never;
|
|
43
41
|
} & {
|
|
44
42
|
init: Record<string, never>;
|
|
45
43
|
}) | ({
|
|
46
44
|
init?: never;
|
|
47
|
-
filled?: never;
|
|
48
|
-
canceled?: never;
|
|
49
45
|
closed?: never;
|
|
50
46
|
} & {
|
|
51
47
|
open: Record<string, never>;
|
|
52
48
|
}) | ({
|
|
53
49
|
init?: never;
|
|
54
50
|
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
51
|
} & {
|
|
72
52
|
closed: Record<string, never>;
|
|
73
53
|
});
|
|
74
54
|
price: BN;
|
|
75
55
|
totalAmount: BN;
|
|
76
56
|
totalShares: BN;
|
|
77
|
-
filledAmount: BN;
|
|
78
|
-
filledShares: BN;
|
|
79
57
|
orderType: ({
|
|
80
58
|
limit?: never;
|
|
81
59
|
} & {
|
|
@@ -94,10 +72,9 @@ export default class Trade {
|
|
|
94
72
|
} & {
|
|
95
73
|
flop: Record<string, never>;
|
|
96
74
|
});
|
|
97
|
-
|
|
75
|
+
pnl: BN;
|
|
98
76
|
padding: number[];
|
|
99
77
|
}[];
|
|
100
|
-
position: BN;
|
|
101
78
|
padding: number[];
|
|
102
79
|
}>;
|
|
103
80
|
openOrder(marketId: number, args: {
|
package/dist/trade.js
CHANGED
|
@@ -16,6 +16,8 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
16
16
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
17
17
|
const constants_1 = require("./utils/constants");
|
|
18
18
|
const helpers_1 = require("./utils/helpers");
|
|
19
|
+
const trade_1 = require("./utils/pda/trade");
|
|
20
|
+
const pda_1 = require("./utils/pda");
|
|
19
21
|
class Trade {
|
|
20
22
|
constructor(program, provider) {
|
|
21
23
|
this.mint = constants_1.TRD_MINT_DEVNET;
|
|
@@ -31,23 +33,24 @@ class Trade {
|
|
|
31
33
|
bump: account.bump,
|
|
32
34
|
address: publicKey.toString(),
|
|
33
35
|
authority: account.authority.toString(),
|
|
34
|
-
marketId: account.marketId.
|
|
36
|
+
marketId: account.marketId.toString(),
|
|
35
37
|
name: account.name,
|
|
36
|
-
hypePrice: account.hypePrice.
|
|
37
|
-
flopPrice: account.flopPrice.
|
|
38
|
-
hypeLiquidity: account.hypeLiquidity.
|
|
39
|
-
flopLiquidity: account.flopLiquidity.
|
|
40
|
-
totalHypeShares: account.totalHypeShares.
|
|
41
|
-
totalFlopShares: account.totalFlopShares.
|
|
42
|
-
totalVolume: account.totalVolume.
|
|
38
|
+
hypePrice: account.hypePrice.toString(),
|
|
39
|
+
flopPrice: account.flopPrice.toString(),
|
|
40
|
+
hypeLiquidity: account.hypeLiquidity.toString(),
|
|
41
|
+
flopLiquidity: account.flopLiquidity.toString(),
|
|
42
|
+
totalHypeShares: account.totalHypeShares.toString(),
|
|
43
|
+
totalFlopShares: account.totalFlopShares.toString(),
|
|
44
|
+
totalVolume: account.totalVolume.toString(),
|
|
43
45
|
mint: account.mint.toString(),
|
|
44
|
-
ts: account.ts.
|
|
45
|
-
updateTs: account.updateTs.
|
|
46
|
-
openOrdersCount: account.openOrdersCount.
|
|
47
|
-
nextOrderId: account.nextOrderId.
|
|
46
|
+
ts: account.ts.toString(),
|
|
47
|
+
updateTs: account.updateTs.toString(),
|
|
48
|
+
openOrdersCount: account.openOrdersCount.toString(),
|
|
49
|
+
nextOrderId: account.nextOrderId.toString(),
|
|
48
50
|
feeBps: account.feeBps,
|
|
49
51
|
feeVault: account.feeVault.toBase58(),
|
|
50
52
|
isActive: account.isActive,
|
|
53
|
+
marketPrice: account.marketPrice.toString(),
|
|
51
54
|
isOfficial: account.isOfficial
|
|
52
55
|
})));
|
|
53
56
|
});
|
|
@@ -59,23 +62,24 @@ class Trade {
|
|
|
59
62
|
bump: account.bump,
|
|
60
63
|
address: address.toString(),
|
|
61
64
|
authority: account.authority.toString(),
|
|
62
|
-
marketId: account.marketId.
|
|
65
|
+
marketId: account.marketId.toString(),
|
|
63
66
|
name: account.name,
|
|
64
|
-
hypePrice: account.hypePrice.
|
|
65
|
-
flopPrice: account.flopPrice.
|
|
66
|
-
hypeLiquidity: account.hypeLiquidity.
|
|
67
|
-
flopLiquidity: account.flopLiquidity.
|
|
68
|
-
totalHypeShares: account.totalHypeShares.
|
|
69
|
-
totalFlopShares: account.totalFlopShares.
|
|
70
|
-
totalVolume: account.totalVolume.
|
|
67
|
+
hypePrice: account.hypePrice.toString(),
|
|
68
|
+
flopPrice: account.flopPrice.toString(),
|
|
69
|
+
hypeLiquidity: account.hypeLiquidity.toString(),
|
|
70
|
+
flopLiquidity: account.flopLiquidity.toString(),
|
|
71
|
+
totalHypeShares: account.totalHypeShares.toString(),
|
|
72
|
+
totalFlopShares: account.totalFlopShares.toString(),
|
|
73
|
+
totalVolume: account.totalVolume.toString(),
|
|
71
74
|
mint: account.mint.toString(),
|
|
72
|
-
ts: account.ts.
|
|
73
|
-
updateTs: account.updateTs.
|
|
74
|
-
openOrdersCount: account.openOrdersCount.
|
|
75
|
-
nextOrderId: account.nextOrderId.
|
|
75
|
+
ts: account.ts.toString(),
|
|
76
|
+
updateTs: account.updateTs.toString(),
|
|
77
|
+
openOrdersCount: account.openOrdersCount.toString(),
|
|
78
|
+
nextOrderId: account.nextOrderId.toString(),
|
|
76
79
|
feeBps: account.feeBps,
|
|
77
80
|
feeVault: account.feeVault.toBase58(),
|
|
78
81
|
isActive: account.isActive,
|
|
82
|
+
marketPrice: account.marketPrice.toString(),
|
|
79
83
|
isOfficial: account.isOfficial
|
|
80
84
|
};
|
|
81
85
|
});
|
|
@@ -109,25 +113,27 @@ class Trade {
|
|
|
109
113
|
}
|
|
110
114
|
getUserTrade() {
|
|
111
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
-
const userTradePDA = (0,
|
|
116
|
+
const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
113
117
|
return this.program.account.userTrade.fetch(userTradePDA);
|
|
114
118
|
});
|
|
115
119
|
}
|
|
116
120
|
openOrder(marketId, args, options) {
|
|
117
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
const marketPDA = (0,
|
|
119
|
-
const feeVualtPDA = (0,
|
|
120
|
-
const userTradePDA = (0,
|
|
122
|
+
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
123
|
+
const feeVualtPDA = (0, trade_1.getFeeVaultPDA)(this.program.programId, marketId);
|
|
124
|
+
const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
125
|
+
const userPDA = (0, pda_1.getUserPDA)(this.program.programId, this.provider.publicKey);
|
|
126
|
+
const userFromATA = (0, pda_1.getTokenATA)(this.provider.publicKey, this.mint);
|
|
121
127
|
const ixs = [];
|
|
122
128
|
try {
|
|
123
|
-
const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(this.program.programId, this.provider.publicKey);
|
|
124
129
|
yield this.program.account.userTrade.fetch(userTradePDA);
|
|
125
130
|
}
|
|
126
131
|
catch (_a) {
|
|
127
132
|
ixs.push(yield this.program.methods
|
|
128
133
|
.createUserTrade()
|
|
129
134
|
.accounts({
|
|
130
|
-
signer: this.provider.publicKey
|
|
135
|
+
signer: this.provider.publicKey,
|
|
136
|
+
user: userPDA
|
|
131
137
|
})
|
|
132
138
|
.instruction());
|
|
133
139
|
}
|
|
@@ -135,14 +141,15 @@ class Trade {
|
|
|
135
141
|
.openOrder({
|
|
136
142
|
amount: new bn_js_1.default(args.amount * Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
137
143
|
direction: args.direction,
|
|
138
|
-
orderType: args.orderType,
|
|
139
|
-
limitPrice: new bn_js_1.default(args.limitPrice * Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
140
144
|
comment: (0, helpers_1.encodeString)(args.comment, 64)
|
|
141
145
|
})
|
|
142
146
|
.accounts({
|
|
143
147
|
signer: this.provider.publicKey,
|
|
144
148
|
market: marketPDA,
|
|
145
|
-
|
|
149
|
+
feeVault: feeVualtPDA,
|
|
150
|
+
userTrade: userTradePDA,
|
|
151
|
+
mint: this.mint,
|
|
152
|
+
userFromAta: userFromATA
|
|
146
153
|
})
|
|
147
154
|
.instruction());
|
|
148
155
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
@@ -163,7 +170,7 @@ class Trade {
|
|
|
163
170
|
}
|
|
164
171
|
closeOrder({ marketId, orderId }, options) {
|
|
165
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
const marketPDA = (0,
|
|
173
|
+
const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
|
|
167
174
|
const method = this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
|
|
168
175
|
signer: this.provider.publicKey,
|
|
169
176
|
market: marketPDA,
|