@triadxyz/triad-protocol 4.2.0 → 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/index.d.ts +4 -167
- package/dist/index.js +15 -576
- 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/idl_triad_protocol.json +511 -900
- 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 +619 -1388
- 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
package/dist/predictor.js
CHANGED
|
@@ -18,7 +18,6 @@ const constants_1 = require("./utils/constants");
|
|
|
18
18
|
const pda_1 = require("./utils/pda");
|
|
19
19
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
20
20
|
const helpers_1 = require("./utils/helpers");
|
|
21
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
22
21
|
class Predictor {
|
|
23
22
|
constructor(program, rpcOptions) {
|
|
24
23
|
this.program = program;
|
|
@@ -34,8 +33,7 @@ class Predictor {
|
|
|
34
33
|
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
35
34
|
try {
|
|
36
35
|
const predictor = yield this.program.account.predictor.fetch(predictorPDA);
|
|
37
|
-
|
|
38
|
-
return (0, helpers_1.formatPredictor)(predictor, predictorPDA, new bn_js_1.default(balance.value.amount));
|
|
36
|
+
return (0, helpers_1.formatPredictor)(predictor, predictorPDA);
|
|
39
37
|
}
|
|
40
38
|
catch (e) {
|
|
41
39
|
return {
|
|
@@ -43,7 +41,9 @@ class Predictor {
|
|
|
43
41
|
authority: authority.toBase58(),
|
|
44
42
|
balance: 0,
|
|
45
43
|
customerId,
|
|
46
|
-
refer: '11111111111111111111111111111111'
|
|
44
|
+
refer: '11111111111111111111111111111111',
|
|
45
|
+
rewardsAvailable: 0,
|
|
46
|
+
rewardsClaimed: 0
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
});
|
|
@@ -78,7 +78,6 @@ class Predictor {
|
|
|
78
78
|
.deposit(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
79
79
|
.accounts({
|
|
80
80
|
signer: authority,
|
|
81
|
-
payer: this.rpcOptions.payer,
|
|
82
81
|
predictor: predictorPDA
|
|
83
82
|
})
|
|
84
83
|
.instruction());
|
|
@@ -93,16 +92,37 @@ class Predictor {
|
|
|
93
92
|
*/
|
|
94
93
|
withdraw({ authority, amount, customerId = 7 }) {
|
|
95
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const ixs = [];
|
|
97
95
|
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
98
|
-
ixs
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
const ixs = [
|
|
97
|
+
yield this.program.methods
|
|
98
|
+
.withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
|
|
99
|
+
.accounts({
|
|
100
|
+
signer: authority,
|
|
101
|
+
predictor: predictorPDA
|
|
102
|
+
})
|
|
103
|
+
.instruction()
|
|
104
|
+
];
|
|
105
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Collect Rewards
|
|
110
|
+
* Claims accumulated TRIAD token rewards for the predictor.
|
|
111
|
+
* @param args.authority - Authority of the predictor
|
|
112
|
+
* @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
|
|
113
|
+
*/
|
|
114
|
+
collectRewards({ authority, customerId = 7 }) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
|
|
117
|
+
const ixs = [
|
|
118
|
+
yield this.program.methods
|
|
119
|
+
.collectRewards()
|
|
120
|
+
.accounts({
|
|
121
|
+
signer: authority,
|
|
122
|
+
predictor: predictorPDA
|
|
123
|
+
})
|
|
124
|
+
.instruction()
|
|
125
|
+
];
|
|
106
126
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
107
127
|
});
|
|
108
128
|
}
|
package/dist/stake.d.ts
CHANGED
|
@@ -35,21 +35,6 @@ export default class Stake {
|
|
|
35
35
|
* @param wallet - User wallet
|
|
36
36
|
*/
|
|
37
37
|
getUnstakeByWallet(wallet: PublicKey): Promise<import(".").Unstake[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Stake Token
|
|
40
|
-
* @param amount - Amount to stake
|
|
41
|
-
*/
|
|
42
|
-
stakeToken(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
43
|
-
/**
|
|
44
|
-
* Update Stake Vault
|
|
45
|
-
* @param amount - Reward amount to deposit
|
|
46
|
-
*/
|
|
47
|
-
addStakeVaultRewards(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
48
|
-
/**
|
|
49
|
-
* Request Unstake
|
|
50
|
-
* @param amount - Amount to unstake
|
|
51
|
-
*/
|
|
52
|
-
requestUnstake(amount: number): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
53
38
|
/**
|
|
54
39
|
* Unstake Token
|
|
55
40
|
* @param unstakePDA - Unstake Public Key
|
package/dist/stake.js
CHANGED
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
15
|
const helpers_1 = require("./utils/helpers");
|
|
17
16
|
const pda_1 = require("./utils/pda");
|
|
18
17
|
const constants_1 = require("./utils/constants");
|
|
@@ -69,65 +68,6 @@ class Stake {
|
|
|
69
68
|
return stake.map((stake) => (0, helpers_1.formatUnstake)(stake.account, stake.publicKey));
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Stake Token
|
|
74
|
-
* @param amount - Amount to stake
|
|
75
|
-
*/
|
|
76
|
-
stakeToken(amount) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
const ixs = [
|
|
79
|
-
yield this.program.methods
|
|
80
|
-
.stakeToken({
|
|
81
|
-
amount: new anchor_1.BN(amount * Math.pow(10, 6))
|
|
82
|
-
})
|
|
83
|
-
.accounts({
|
|
84
|
-
signer: this.program.provider.publicKey,
|
|
85
|
-
mint: constants_1.TRD_MINT
|
|
86
|
-
})
|
|
87
|
-
.instruction()
|
|
88
|
-
];
|
|
89
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Update Stake Vault
|
|
94
|
-
* @param amount - Reward amount to deposit
|
|
95
|
-
*/
|
|
96
|
-
addStakeVaultRewards(amount) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const ixs = [
|
|
99
|
-
yield this.program.methods
|
|
100
|
-
.addStakeVaultRewards(new anchor_1.BN(amount * Math.pow(10, 6)))
|
|
101
|
-
.accounts({
|
|
102
|
-
signer: this.program.provider.publicKey,
|
|
103
|
-
mint: constants_1.TRD_MINT
|
|
104
|
-
})
|
|
105
|
-
.instruction()
|
|
106
|
-
];
|
|
107
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Request Unstake
|
|
112
|
-
* @param amount - Amount to unstake
|
|
113
|
-
*/
|
|
114
|
-
requestUnstake(amount) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
const ixs = [
|
|
117
|
-
yield this.program.methods
|
|
118
|
-
.requestUnstake({
|
|
119
|
-
amount: new anchor_1.BN(amount * Math.pow(10, 6)),
|
|
120
|
-
ts: new anchor_1.BN(Date.now())
|
|
121
|
-
})
|
|
122
|
-
.accounts({
|
|
123
|
-
signer: this.program.provider.publicKey,
|
|
124
|
-
mint: constants_1.TRD_MINT
|
|
125
|
-
})
|
|
126
|
-
.instruction()
|
|
127
|
-
];
|
|
128
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
71
|
/**
|
|
132
72
|
* Unstake Token
|
|
133
73
|
* @param unstakePDA - Unstake Public Key
|
package/dist/trade.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export default class Trade {
|
|
|
33
33
|
* @param args.orders.price - The price of the Order
|
|
34
34
|
* @param args.orders.orderDirection - The direction of the Order
|
|
35
35
|
*/
|
|
36
|
-
placeBidOrder({ orders }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
36
|
+
placeBidOrder({ orders, customerId }: PlaceBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
37
37
|
/**
|
|
38
38
|
* Place Ask Order
|
|
39
39
|
* @param args.orders - Array of orders to execute
|
|
@@ -42,14 +42,14 @@ export default class Trade {
|
|
|
42
42
|
* @param args.orders.marketId - The Id from the market
|
|
43
43
|
* @param args.orders.orderDirection - The direction of the Order
|
|
44
44
|
*/
|
|
45
|
-
placeAskOrder({ orders }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
45
|
+
placeAskOrder({ orders, customerId }: PlaceAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
46
46
|
/**
|
|
47
47
|
* Cancel Bid Order
|
|
48
48
|
* @param args.orders.bookOrderId - The ID of the Book Order
|
|
49
49
|
* @param args.orders.marketId - The ID of the Market
|
|
50
50
|
* @param args.orders.orderDirection - The direction of the Order
|
|
51
51
|
*/
|
|
52
|
-
cancelBidOrder({ orders }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
52
|
+
cancelBidOrder({ orders, customerId }: CancelBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
53
53
|
/**
|
|
54
54
|
* Cancel Ask Order
|
|
55
55
|
* @param args.orders.marketId - The ID of the Market
|
|
@@ -57,14 +57,14 @@ export default class Trade {
|
|
|
57
57
|
* @param args.orders.bookOrderId - The ID of the Book Order
|
|
58
58
|
* @param args.orders.orderDirection - The direction of the Order
|
|
59
59
|
*/
|
|
60
|
-
cancelAskOrder({ orders }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
60
|
+
cancelAskOrder({ orders, customerId }: CancelAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
61
61
|
/**
|
|
62
62
|
* Market Bid Order
|
|
63
63
|
* @param args.marketId - The ID of the Market
|
|
64
64
|
* @param args.amount - The amount of the Order
|
|
65
65
|
* @param args.orderDirection - The direction of the Order
|
|
66
66
|
*/
|
|
67
|
-
marketBidOrder({ marketId, amount,
|
|
67
|
+
marketBidOrder({ marketId, amount, orderDirection, customer }: MarketBidOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
68
68
|
/**
|
|
69
69
|
* Market Ask Order
|
|
70
70
|
* @param args.marketId - The ID of the Market
|
|
@@ -72,7 +72,7 @@ export default class Trade {
|
|
|
72
72
|
* @param args.bookOrderBidId - The ID of the Bid Order
|
|
73
73
|
* @param args.orderDirection - The direction of the Order
|
|
74
74
|
*/
|
|
75
|
-
marketAskOrder({ marketId, shares, orderDirection,
|
|
75
|
+
marketAskOrder({ marketId, shares, orderDirection, customer }: MarketAskOrderArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
76
76
|
/**
|
|
77
77
|
* Payout Order
|
|
78
78
|
* @param args.marketId - The ID of the Market
|
|
@@ -83,5 +83,6 @@ export default class Trade {
|
|
|
83
83
|
marketId: number;
|
|
84
84
|
orderDirection: OrderDirectionEncoded;
|
|
85
85
|
authority: PublicKey;
|
|
86
|
+
customerId: number;
|
|
86
87
|
}[]): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
87
88
|
}
|
package/dist/trade.js
CHANGED
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
17
16
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
18
17
|
const helpers_1 = require("./utils/helpers");
|
|
19
18
|
const types_1 = require("./types");
|
|
@@ -40,20 +39,18 @@ class Trade {
|
|
|
40
39
|
hype: { bid: [], ask: [] },
|
|
41
40
|
flop: { bid: [], ask: [] }
|
|
42
41
|
};
|
|
43
|
-
const
|
|
44
|
-
const orderBook = yield this.program.account.orderBook.fetch(orderBookPDA);
|
|
45
|
-
data.rewardsAvailable = orderBook.rewardsAvailable.toString();
|
|
46
|
-
data.rewardsClaimed = orderBook.rewardsClaimed.toString();
|
|
47
|
-
data.spreadToReward = orderBook.spreadToReward.toString();
|
|
42
|
+
const orderBook = yield this.program.account.orderBook.fetch((0, pda_1.getOrderBookPDA)(this.program.programId, marketId), 'processed');
|
|
48
43
|
const processOrders = (orders, side) => {
|
|
44
|
+
const { bid, ask } = data[side];
|
|
49
45
|
for (const order of orders) {
|
|
50
|
-
if (order.price.
|
|
46
|
+
if (order.price.isZero())
|
|
51
47
|
continue;
|
|
48
|
+
const formatted = (0, helpers_1.formatBookOrder)(order, marketId);
|
|
52
49
|
if ((0, helpers_1.getOrderSideFromNumber)(order.orderSide) === types_1.OrderSide.BID) {
|
|
53
|
-
|
|
50
|
+
bid.push(formatted);
|
|
54
51
|
}
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
else {
|
|
53
|
+
ask.push(formatted);
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
};
|
|
@@ -70,12 +67,10 @@ class Trade {
|
|
|
70
67
|
* @param args.orders.price - The price of the Order
|
|
71
68
|
* @param args.orders.orderDirection - The direction of the Order
|
|
72
69
|
*/
|
|
73
|
-
placeBidOrder({ orders }) {
|
|
70
|
+
placeBidOrder({ orders, customerId = 7 }) {
|
|
74
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
72
|
const ixs = [];
|
|
76
|
-
|
|
77
|
-
throw new Error('Max 6 orders per transaction');
|
|
78
|
-
}
|
|
73
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
|
|
79
74
|
for (const order of orders) {
|
|
80
75
|
ixs.push(yield this.program.methods
|
|
81
76
|
.placeBidOrder({
|
|
@@ -87,9 +82,10 @@ class Trade {
|
|
|
87
82
|
.accounts({
|
|
88
83
|
signer: this.program.provider.publicKey,
|
|
89
84
|
payer: this.rpcOptions.payer,
|
|
85
|
+
predictor: predictorPDA,
|
|
90
86
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
91
87
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
92
|
-
|
|
88
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
93
89
|
})
|
|
94
90
|
.instruction());
|
|
95
91
|
}
|
|
@@ -104,12 +100,10 @@ class Trade {
|
|
|
104
100
|
* @param args.orders.marketId - The Id from the market
|
|
105
101
|
* @param args.orders.orderDirection - The direction of the Order
|
|
106
102
|
*/
|
|
107
|
-
placeAskOrder({ orders }) {
|
|
103
|
+
placeAskOrder({ orders, customerId = 7 }) {
|
|
108
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
105
|
const ixs = [];
|
|
110
|
-
|
|
111
|
-
throw new Error('Max 6 orders per transaction');
|
|
112
|
-
}
|
|
106
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
|
|
113
107
|
for (const order of orders) {
|
|
114
108
|
ixs.push(yield this.program.methods
|
|
115
109
|
.placeAskOrder({
|
|
@@ -120,7 +114,8 @@ class Trade {
|
|
|
120
114
|
.accounts({
|
|
121
115
|
signer: this.program.provider.publicKey,
|
|
122
116
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
123
|
-
|
|
117
|
+
predictor: predictorPDA,
|
|
118
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection)),
|
|
124
119
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
|
|
125
120
|
})
|
|
126
121
|
.instruction());
|
|
@@ -134,12 +129,9 @@ class Trade {
|
|
|
134
129
|
* @param args.orders.marketId - The ID of the Market
|
|
135
130
|
* @param args.orders.orderDirection - The direction of the Order
|
|
136
131
|
*/
|
|
137
|
-
cancelBidOrder({ orders }) {
|
|
132
|
+
cancelBidOrder({ orders, customerId = 7 }) {
|
|
138
133
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
134
|
const ixs = [];
|
|
140
|
-
if (orders.length > 6) {
|
|
141
|
-
throw new Error('You can only cancel up to 6 orders at a time');
|
|
142
|
-
}
|
|
143
135
|
for (const order of orders) {
|
|
144
136
|
ixs.push(yield this.program.methods
|
|
145
137
|
.cancelBidOrder({
|
|
@@ -149,7 +141,7 @@ class Trade {
|
|
|
149
141
|
})
|
|
150
142
|
.accounts({
|
|
151
143
|
signer: new web3_js_1.PublicKey(order.authority),
|
|
152
|
-
|
|
144
|
+
predictor: (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customerId),
|
|
153
145
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
154
146
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId)
|
|
155
147
|
})
|
|
@@ -165,12 +157,10 @@ class Trade {
|
|
|
165
157
|
* @param args.orders.bookOrderId - The ID of the Book Order
|
|
166
158
|
* @param args.orders.orderDirection - The direction of the Order
|
|
167
159
|
*/
|
|
168
|
-
cancelAskOrder({ orders }) {
|
|
160
|
+
cancelAskOrder({ orders, customerId = 7 }) {
|
|
169
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
170
162
|
const ixs = [];
|
|
171
|
-
|
|
172
|
-
throw new Error('Max 5 orders per transaction');
|
|
173
|
-
}
|
|
163
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customerId);
|
|
174
164
|
for (const order of orders) {
|
|
175
165
|
ixs.push(yield this.program.methods
|
|
176
166
|
.cancelAskOrder({
|
|
@@ -181,9 +171,10 @@ class Trade {
|
|
|
181
171
|
.accounts({
|
|
182
172
|
signer: order.authority,
|
|
183
173
|
payer: this.rpcOptions.payer,
|
|
174
|
+
predictor: predictorPDA,
|
|
184
175
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
185
176
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, order.marketId),
|
|
186
|
-
|
|
177
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
187
178
|
})
|
|
188
179
|
.instruction());
|
|
189
180
|
}
|
|
@@ -196,12 +187,11 @@ class Trade {
|
|
|
196
187
|
* @param args.amount - The amount of the Order
|
|
197
188
|
* @param args.orderDirection - The direction of the Order
|
|
198
189
|
*/
|
|
199
|
-
marketBidOrder({ marketId, amount,
|
|
190
|
+
marketBidOrder({ marketId, amount, orderDirection, customer }) {
|
|
200
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
201
192
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
202
193
|
const ixs = [];
|
|
203
|
-
const
|
|
204
|
-
const customer = yield (0, helpers_1.getCustomerById)(this.program, customerId);
|
|
194
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customer.id);
|
|
205
195
|
const orderBook = yield this.getOrderBook(marketId);
|
|
206
196
|
let remainingUSDC = new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS));
|
|
207
197
|
const orders = Object.keys(orderDirection)[0] === 'hype'
|
|
@@ -211,7 +201,7 @@ class Trade {
|
|
|
211
201
|
for (const order of sortedOrders) {
|
|
212
202
|
if (remainingUSDC.lte(new bn_js_1.default(0)))
|
|
213
203
|
break;
|
|
214
|
-
if (order.authority ===
|
|
204
|
+
if (order.authority === predictorPDA.toBase58()) {
|
|
215
205
|
continue;
|
|
216
206
|
}
|
|
217
207
|
const orderPrice = new bn_js_1.default(order.price);
|
|
@@ -241,12 +231,14 @@ class Trade {
|
|
|
241
231
|
.accounts({
|
|
242
232
|
signer: this.program.provider.publicKey,
|
|
243
233
|
payer: this.rpcOptions.payer,
|
|
234
|
+
predictor: predictorPDA,
|
|
235
|
+
oppositePredictor: (0, pda_1.getPredictorPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), customer.id),
|
|
236
|
+
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
244
237
|
market: marketPDA,
|
|
245
238
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
customer: (0, pda_1.getCustomerPDA)(this.program.programId, customerId)
|
|
239
|
+
customer: customer.address,
|
|
240
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
241
|
+
oppositePredictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(oppositeOrderDirection))
|
|
250
242
|
})
|
|
251
243
|
.instruction());
|
|
252
244
|
remainingUSDC = remainingUSDC.sub(usdcAmount);
|
|
@@ -254,7 +246,7 @@ class Trade {
|
|
|
254
246
|
if (ixs.length === 0) {
|
|
255
247
|
throw new Error('No matching orders found to fill the requested amount');
|
|
256
248
|
}
|
|
257
|
-
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions
|
|
249
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
258
250
|
});
|
|
259
251
|
}
|
|
260
252
|
/**
|
|
@@ -264,12 +256,12 @@ class Trade {
|
|
|
264
256
|
* @param args.bookOrderBidId - The ID of the Bid Order
|
|
265
257
|
* @param args.orderDirection - The direction of the Order
|
|
266
258
|
*/
|
|
267
|
-
marketAskOrder({ marketId, shares, orderDirection,
|
|
259
|
+
marketAskOrder({ marketId, shares, orderDirection, customer }) {
|
|
268
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
269
261
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
270
262
|
const ixs = [];
|
|
271
263
|
const addressLookupTableAccounts = [];
|
|
272
|
-
const
|
|
264
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, customer.id);
|
|
273
265
|
const orderBook = yield this.getOrderBook(marketId);
|
|
274
266
|
const bidOrders = Object.keys(orderDirection)[0] === 'hype'
|
|
275
267
|
? orderBook.hype.bid
|
|
@@ -280,7 +272,7 @@ class Trade {
|
|
|
280
272
|
for (const order of sortedOrders) {
|
|
281
273
|
if (remainingShares.lte(new bn_js_1.default(0)))
|
|
282
274
|
break;
|
|
283
|
-
if (order.authority ===
|
|
275
|
+
if (order.authority === predictorPDA.toBase58() ||
|
|
284
276
|
order.linkedBookOrderId !== constants_1.BOOK_ORDER_NULL.toString()) {
|
|
285
277
|
continue;
|
|
286
278
|
}
|
|
@@ -301,14 +293,13 @@ class Trade {
|
|
|
301
293
|
})
|
|
302
294
|
.accounts({
|
|
303
295
|
signer: this.program.provider.publicKey,
|
|
304
|
-
|
|
296
|
+
predictor: predictorPDA,
|
|
305
297
|
market: marketPDA,
|
|
306
|
-
buyerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
307
298
|
orderBook: (0, pda_1.getOrderBookPDA)(this.program.programId, marketId),
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
299
|
+
customer: customer.address,
|
|
300
|
+
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
301
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, marketId, (0, helpers_1.getOrderDirection)(orderDirection)),
|
|
302
|
+
oppositePredictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), marketId, (0, helpers_1.getOrderDirection)(orderDirection))
|
|
312
303
|
})
|
|
313
304
|
.instruction());
|
|
314
305
|
}
|
|
@@ -327,18 +318,17 @@ class Trade {
|
|
|
327
318
|
payoutOrder(orders) {
|
|
328
319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
329
320
|
const ixs = [];
|
|
330
|
-
if (orders.length > 4) {
|
|
331
|
-
throw new Error('Max 4 orders per transaction');
|
|
332
|
-
}
|
|
333
321
|
for (const order of orders) {
|
|
322
|
+
const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, this.program.provider.publicKey, order.customerId);
|
|
334
323
|
ixs.push(yield this.program.methods
|
|
335
324
|
.payoutOrder()
|
|
336
325
|
.accounts({
|
|
337
326
|
signer: order.authority,
|
|
338
|
-
payer: this.rpcOptions.payer,
|
|
339
327
|
market: (0, pda_1.getMarketPDA)(this.program.programId, order.marketId),
|
|
340
|
-
|
|
341
|
-
|
|
328
|
+
predictor: predictorPDA,
|
|
329
|
+
customer: (0, pda_1.getCustomerPDA)(this.program.programId, order.customerId),
|
|
330
|
+
central: (0, pda_1.getCentralPDA)(this.program.programId),
|
|
331
|
+
predictorOrder: (0, pda_1.getOrderPDA)(this.program.programId, predictorPDA, order.marketId, (0, helpers_1.getOrderDirection)(order.orderDirection))
|
|
342
332
|
})
|
|
343
333
|
.instruction());
|
|
344
334
|
}
|