@lightconexyz/lightcone-sdk 0.6.1 → 0.7.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/README.md +6 -2
- package/dist/auth/client.d.ts.map +1 -1
- package/dist/auth/client.js +2 -0
- package/dist/auth/client.js.map +1 -1
- package/dist/auth/index.d.ts +15 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +10 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/client.d.ts +17 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +36 -13
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +7 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +60 -6
- package/dist/context.js.map +1 -1
- package/dist/domain/admin/client.d.ts +11 -1
- package/dist/domain/admin/client.d.ts.map +1 -1
- package/dist/domain/admin/client.js +39 -4
- package/dist/domain/admin/client.js.map +1 -1
- package/dist/domain/admin/wire.d.ts +37 -12
- package/dist/domain/admin/wire.d.ts.map +1 -1
- package/dist/domain/admin/wire.js.map +1 -1
- package/dist/domain/market/client.js +1 -1
- package/dist/domain/market/client.js.map +1 -1
- package/dist/domain/market/convert.js +1 -1
- package/dist/domain/market/convert.js.map +1 -1
- package/dist/domain/market/index.d.ts +8 -1
- package/dist/domain/market/index.d.ts.map +1 -1
- package/dist/domain/market/index.js +12 -0
- package/dist/domain/market/index.js.map +1 -1
- package/dist/domain/market/outcome.d.ts +1 -0
- package/dist/domain/market/outcome.d.ts.map +1 -1
- package/dist/domain/market/outcome.js +1 -0
- package/dist/domain/market/outcome.js.map +1 -1
- package/dist/domain/market/tokens.d.ts +2 -0
- package/dist/domain/market/tokens.d.ts.map +1 -1
- package/dist/domain/market/tokens.js +6 -1
- package/dist/domain/market/tokens.js.map +1 -1
- package/dist/domain/market/wire.d.ts +23 -2
- package/dist/domain/market/wire.d.ts.map +1 -1
- package/dist/domain/market/wire.js +5 -0
- package/dist/domain/market/wire.js.map +1 -1
- package/dist/domain/metrics/client.d.ts +3 -3
- package/dist/domain/metrics/client.d.ts.map +1 -1
- package/dist/domain/metrics/client.js +4 -4
- package/dist/domain/metrics/client.js.map +1 -1
- package/dist/domain/metrics/wire.d.ts +5 -1
- package/dist/domain/metrics/wire.d.ts.map +1 -1
- package/dist/domain/metrics/wire.js.map +1 -1
- package/dist/domain/notification/client.d.ts +2 -2
- package/dist/domain/notification/client.d.ts.map +1 -1
- package/dist/domain/notification/client.js +3 -3
- package/dist/domain/notification/client.js.map +1 -1
- package/dist/domain/notification/index.d.ts +3 -1
- package/dist/domain/notification/index.d.ts.map +1 -1
- package/dist/domain/notification/index.js.map +1 -1
- package/dist/domain/order/client.d.ts +12 -10
- package/dist/domain/order/client.d.ts.map +1 -1
- package/dist/domain/order/client.js +20 -13
- package/dist/domain/order/client.js.map +1 -1
- package/dist/domain/order/convert.d.ts +1 -1
- package/dist/domain/order/convert.d.ts.map +1 -1
- package/dist/domain/order/convert.js +2 -2
- package/dist/domain/order/convert.js.map +1 -1
- package/dist/domain/order/index.d.ts +2 -1
- package/dist/domain/order/index.d.ts.map +1 -1
- package/dist/domain/order/index.js +11 -3
- package/dist/domain/order/index.js.map +1 -1
- package/dist/domain/orderbook/client.d.ts +6 -2
- package/dist/domain/orderbook/client.d.ts.map +1 -1
- package/dist/domain/orderbook/client.js +17 -0
- package/dist/domain/orderbook/client.js.map +1 -1
- package/dist/domain/position/builders.d.ts +11 -8
- package/dist/domain/position/builders.d.ts.map +1 -1
- package/dist/domain/position/builders.js +31 -25
- package/dist/domain/position/builders.js.map +1 -1
- package/dist/domain/position/client.d.ts +21 -15
- package/dist/domain/position/client.d.ts.map +1 -1
- package/dist/domain/position/client.js +43 -22
- package/dist/domain/position/client.js.map +1 -1
- package/dist/domain/referral/client.d.ts +2 -2
- package/dist/domain/referral/client.d.ts.map +1 -1
- package/dist/domain/referral/client.js +3 -3
- package/dist/domain/referral/client.js.map +1 -1
- package/dist/domain/trade/client.d.ts +1 -0
- package/dist/domain/trade/client.d.ts.map +1 -1
- package/dist/domain/trade/client.js +14 -0
- package/dist/domain/trade/client.js.map +1 -1
- package/dist/domain/trade/wire.d.ts +6 -0
- package/dist/domain/trade/wire.d.ts.map +1 -1
- package/dist/domain/trade/wire.js.map +1 -1
- package/dist/env.d.ts +6 -1
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +19 -9
- package/dist/env.js.map +1 -1
- package/dist/http/client.d.ts +7 -7
- package/dist/http/client.d.ts.map +1 -1
- package/dist/http/client.js +15 -12
- package/dist/http/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prelude.d.ts +8 -7
- package/dist/prelude.d.ts.map +1 -1
- package/dist/prelude.js +7 -6
- package/dist/prelude.js.map +1 -1
- package/dist/privy/index.d.ts +1 -1
- package/dist/privy/index.js.map +1 -1
- package/dist/program/accounts.d.ts +12 -7
- package/dist/program/accounts.d.ts.map +1 -1
- package/dist/program/accounts.js +38 -16
- package/dist/program/accounts.js.map +1 -1
- package/dist/program/builder.d.ts +0 -4
- package/dist/program/builder.d.ts.map +1 -1
- package/dist/program/builder.js +0 -8
- package/dist/program/builder.js.map +1 -1
- package/dist/program/constants.d.ts +20 -7
- package/dist/program/constants.d.ts.map +1 -1
- package/dist/program/constants.js +21 -8
- package/dist/program/constants.js.map +1 -1
- package/dist/program/error.d.ts +25 -1
- package/dist/program/error.d.ts.map +1 -1
- package/dist/program/error.js +72 -0
- package/dist/program/error.js.map +1 -1
- package/dist/program/index.d.ts +7 -7
- package/dist/program/index.d.ts.map +1 -1
- package/dist/program/index.js +36 -9
- package/dist/program/index.js.map +1 -1
- package/dist/program/instructions.d.ts +184 -71
- package/dist/program/instructions.d.ts.map +1 -1
- package/dist/program/instructions.js +573 -140
- package/dist/program/instructions.js.map +1 -1
- package/dist/program/orders.js +2 -2
- package/dist/program/orders.js.map +1 -1
- package/dist/program/pda.d.ts +21 -3
- package/dist/program/pda.d.ts.map +1 -1
- package/dist/program/pda.js +43 -6
- package/dist/program/pda.js.map +1 -1
- package/dist/program/types.d.ts +139 -21
- package/dist/program/types.d.ts.map +1 -1
- package/dist/program/types.js.map +1 -1
- package/dist/program/utils.d.ts +31 -2
- package/dist/program/utils.d.ts.map +1 -1
- package/dist/program/utils.js +132 -5
- package/dist/program/utils.js.map +1 -1
- package/dist/rpc.d.ts +6 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +9 -7
- package/dist/rpc.js.map +1 -1
- package/dist/rpcFailover.d.ts +22 -0
- package/dist/rpcFailover.d.ts.map +1 -0
- package/dist/rpcFailover.js +71 -0
- package/dist/rpcFailover.js.map +1 -0
- package/dist/shared/fmt/constants.d.ts +5 -0
- package/dist/shared/fmt/constants.d.ts.map +1 -0
- package/dist/shared/fmt/constants.js +25 -0
- package/dist/shared/fmt/constants.js.map +1 -0
- package/dist/shared/fmt/decimal.d.ts +7 -0
- package/dist/shared/fmt/decimal.d.ts.map +1 -1
- package/dist/shared/fmt/decimal.js +28 -20
- package/dist/shared/fmt/decimal.js.map +1 -1
- package/dist/shared/fmt/num.d.ts +7 -0
- package/dist/shared/fmt/num.d.ts.map +1 -1
- package/dist/shared/fmt/num.js +27 -15
- package/dist/shared/fmt/num.js.map +1 -1
- package/dist/ws/client.node.js +1 -1
- package/dist/ws/client.node.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,13 +16,24 @@ exports.buildActivateMarketIx = buildActivateMarketIx;
|
|
|
16
16
|
exports.buildMatchOrdersMultiIx = buildMatchOrdersMultiIx;
|
|
17
17
|
exports.buildSetAuthorityIx = buildSetAuthorityIx;
|
|
18
18
|
exports.buildCreateOrderbookIx = buildCreateOrderbookIx;
|
|
19
|
+
exports.buildSetManagerIx = buildSetManagerIx;
|
|
20
|
+
exports.buildSetMarketFeesIx = buildSetMarketFeesIx;
|
|
21
|
+
exports.buildSetFeeReceiverIx = buildSetFeeReceiverIx;
|
|
22
|
+
exports.buildCreateConditionalMetadataIx = buildCreateConditionalMetadataIx;
|
|
23
|
+
exports.buildUpdateConditionalMetadataIx = buildUpdateConditionalMetadataIx;
|
|
19
24
|
exports.buildWhitelistDepositTokenIx = buildWhitelistDepositTokenIx;
|
|
20
25
|
exports.buildDepositToGlobalIx = buildDepositToGlobalIx;
|
|
26
|
+
exports.buildDepositToGlobalIxWithAlt = buildDepositToGlobalIxWithAlt;
|
|
21
27
|
exports.buildGlobalToMarketDepositIx = buildGlobalToMarketDepositIx;
|
|
22
28
|
exports.buildInitPositionTokensIx = buildInitPositionTokensIx;
|
|
23
29
|
exports.buildExtendPositionTokensIx = buildExtendPositionTokensIx;
|
|
24
30
|
exports.buildDepositAndSwapIx = buildDepositAndSwapIx;
|
|
25
31
|
exports.buildWithdrawFromGlobalIx = buildWithdrawFromGlobalIx;
|
|
32
|
+
exports.buildClosePositionAltIx = buildClosePositionAltIx;
|
|
33
|
+
exports.buildCloseOrderStatusIx = buildCloseOrderStatusIx;
|
|
34
|
+
exports.buildClosePositionTokenAccountsIx = buildClosePositionTokenAccountsIx;
|
|
35
|
+
exports.buildCloseOrderbookAltIx = buildCloseOrderbookAltIx;
|
|
36
|
+
exports.buildCloseOrderbookIx = buildCloseOrderbookIx;
|
|
26
37
|
exports.buildInitializeTx = buildInitializeTx;
|
|
27
38
|
exports.buildCreateMarketTx = buildCreateMarketTx;
|
|
28
39
|
exports.buildAddDepositMintTx = buildAddDepositMintTx;
|
|
@@ -38,14 +49,25 @@ exports.buildWithdrawFromPositionTx = buildWithdrawFromPositionTx;
|
|
|
38
49
|
exports.buildActivateMarketTx = buildActivateMarketTx;
|
|
39
50
|
exports.buildMatchOrdersMultiTx = buildMatchOrdersMultiTx;
|
|
40
51
|
exports.buildSetAuthorityTx = buildSetAuthorityTx;
|
|
52
|
+
exports.buildSetManagerTx = buildSetManagerTx;
|
|
53
|
+
exports.buildSetMarketFeesTx = buildSetMarketFeesTx;
|
|
54
|
+
exports.buildSetFeeReceiverTx = buildSetFeeReceiverTx;
|
|
55
|
+
exports.buildCreateConditionalMetadataTx = buildCreateConditionalMetadataTx;
|
|
56
|
+
exports.buildUpdateConditionalMetadataTx = buildUpdateConditionalMetadataTx;
|
|
41
57
|
exports.buildCreateOrderbookTx = buildCreateOrderbookTx;
|
|
42
58
|
exports.buildWhitelistDepositTokenTx = buildWhitelistDepositTokenTx;
|
|
43
59
|
exports.buildDepositToGlobalTx = buildDepositToGlobalTx;
|
|
60
|
+
exports.buildDepositToGlobalTxWithAlt = buildDepositToGlobalTxWithAlt;
|
|
44
61
|
exports.buildGlobalToMarketDepositTx = buildGlobalToMarketDepositTx;
|
|
45
62
|
exports.buildInitPositionTokensTx = buildInitPositionTokensTx;
|
|
46
63
|
exports.buildExtendPositionTokensTx = buildExtendPositionTokensTx;
|
|
47
64
|
exports.buildDepositAndSwapTx = buildDepositAndSwapTx;
|
|
48
65
|
exports.buildWithdrawFromGlobalTx = buildWithdrawFromGlobalTx;
|
|
66
|
+
exports.buildClosePositionAltTx = buildClosePositionAltTx;
|
|
67
|
+
exports.buildCloseOrderStatusTx = buildCloseOrderStatusTx;
|
|
68
|
+
exports.buildClosePositionTokenAccountsTx = buildClosePositionTokenAccountsTx;
|
|
69
|
+
exports.buildCloseOrderbookAltTx = buildCloseOrderbookAltTx;
|
|
70
|
+
exports.buildCloseOrderbookTx = buildCloseOrderbookTx;
|
|
49
71
|
const web3_js_1 = require("@solana/web3.js");
|
|
50
72
|
const constants_1 = require("./constants");
|
|
51
73
|
const env_1 = require("../env");
|
|
@@ -60,12 +82,67 @@ const error_1 = require("./error");
|
|
|
60
82
|
function signerMut(pubkey) {
|
|
61
83
|
return { pubkey, isSigner: true, isWritable: true };
|
|
62
84
|
}
|
|
85
|
+
function signer(pubkey) {
|
|
86
|
+
return { pubkey, isSigner: true, isWritable: false };
|
|
87
|
+
}
|
|
63
88
|
function writable(pubkey) {
|
|
64
89
|
return { pubkey, isSigner: false, isWritable: true };
|
|
65
90
|
}
|
|
66
91
|
function readonly(pubkey) {
|
|
67
92
|
return { pubkey, isSigner: false, isWritable: false };
|
|
68
93
|
}
|
|
94
|
+
function zeroPubkey() {
|
|
95
|
+
return new web3_js_1.PublicKey(Buffer.alloc(32));
|
|
96
|
+
}
|
|
97
|
+
function canonicalOrderbookMints(params) {
|
|
98
|
+
if (params.baseIndex > 1) {
|
|
99
|
+
throw error_1.ProgramSdkError.invalidOutcomeIndex(params.baseIndex, 1);
|
|
100
|
+
}
|
|
101
|
+
if (params.mintA.equals(params.mintB)) {
|
|
102
|
+
throw error_1.ProgramSdkError.invalidMintOrder();
|
|
103
|
+
}
|
|
104
|
+
const left = {
|
|
105
|
+
mint: params.mintA,
|
|
106
|
+
depositMint: params.mintADepositMint,
|
|
107
|
+
outcomeIndex: params.mintAOutcomeIndex,
|
|
108
|
+
isBase: params.baseIndex === 0,
|
|
109
|
+
};
|
|
110
|
+
const right = {
|
|
111
|
+
mint: params.mintB,
|
|
112
|
+
depositMint: params.mintBDepositMint,
|
|
113
|
+
outcomeIndex: params.mintBOutcomeIndex,
|
|
114
|
+
isBase: params.baseIndex === 1,
|
|
115
|
+
};
|
|
116
|
+
const [mintA, mintB] = Buffer.compare(left.mint.toBuffer(), right.mint.toBuffer()) < 0
|
|
117
|
+
? [left, right]
|
|
118
|
+
: [right, left];
|
|
119
|
+
return {
|
|
120
|
+
mintA,
|
|
121
|
+
mintB,
|
|
122
|
+
baseIndex: mintA.isBase ? 0 : 1,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function validatePayoutNumerators(payoutNumerators) {
|
|
126
|
+
const count = payoutNumerators.length;
|
|
127
|
+
if (count < constants_1.MIN_OUTCOMES || count > constants_1.MAX_OUTCOMES) {
|
|
128
|
+
throw error_1.ProgramSdkError.invalidOutcomeCount(count);
|
|
129
|
+
}
|
|
130
|
+
let denominator = 0n;
|
|
131
|
+
for (const numerator of payoutNumerators) {
|
|
132
|
+
if (!Number.isInteger(numerator) ||
|
|
133
|
+
numerator < 0 ||
|
|
134
|
+
numerator > 0xffffffff) {
|
|
135
|
+
throw error_1.ProgramSdkError.payoutVectorExceedsU32();
|
|
136
|
+
}
|
|
137
|
+
denominator += BigInt(numerator);
|
|
138
|
+
if (denominator > 0xffffffffn) {
|
|
139
|
+
throw error_1.ProgramSdkError.overflow("Payout denominator overflow");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (denominator === 0n) {
|
|
143
|
+
throw error_1.ProgramSdkError.invalidPayoutNumerators();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
69
146
|
// ============================================================================
|
|
70
147
|
// INSTRUCTION BUILDERS
|
|
71
148
|
// ============================================================================
|
|
@@ -99,28 +176,35 @@ function buildInitializeIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
99
176
|
* Creates a new market in Pending status
|
|
100
177
|
*
|
|
101
178
|
* Accounts:
|
|
102
|
-
* 0.
|
|
179
|
+
* 0. manager (signer, mut) - Must be exchange manager
|
|
103
180
|
* 1. exchange (mut) - Exchange PDA
|
|
104
181
|
* 2. market (mut) - Market PDA
|
|
105
182
|
* 3. system_program (readonly)
|
|
183
|
+
* 4. condition_tombstone (mut) - Condition uniqueness PDA
|
|
106
184
|
*
|
|
107
|
-
* Data: [discriminator, num_outcomes (u8), oracle (32), question_id (32)]
|
|
185
|
+
* Data: [discriminator, num_outcomes (u8), oracle (32), question_id (32), maker_fee_bps (i16), taker_fee_bps (i16)]
|
|
108
186
|
*/
|
|
109
187
|
function buildCreateMarketIx(params, marketId, programId = env_1.PROGRAM_ID) {
|
|
110
188
|
(0, utils_1.validateOutcomes)(params.numOutcomes);
|
|
189
|
+
(0, utils_1.validateFeePair)(params.makerFeeBps, params.takerFeeBps);
|
|
111
190
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
112
191
|
const [market] = (0, pda_1.getMarketPda)(marketId, programId);
|
|
192
|
+
const conditionId = (0, utils_1.deriveConditionId)(params.oracle, params.questionId, params.numOutcomes);
|
|
193
|
+
const [conditionTombstone] = (0, pda_1.getConditionTombstonePda)(conditionId, programId);
|
|
113
194
|
const keys = [
|
|
114
|
-
signerMut(params.
|
|
195
|
+
signerMut(params.manager),
|
|
115
196
|
writable(exchange),
|
|
116
197
|
writable(market),
|
|
117
198
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
199
|
+
writable(conditionTombstone),
|
|
118
200
|
];
|
|
119
201
|
const data = Buffer.concat([
|
|
120
202
|
Buffer.from([constants_1.INSTRUCTION.CREATE_MARKET]),
|
|
121
203
|
(0, utils_1.toU8)(params.numOutcomes),
|
|
122
204
|
params.oracle.toBuffer(),
|
|
123
205
|
params.questionId,
|
|
206
|
+
(0, utils_1.toI16Le)(params.makerFeeBps),
|
|
207
|
+
(0, utils_1.toI16Le)(params.takerFeeBps),
|
|
124
208
|
]);
|
|
125
209
|
return new web3_js_1.TransactionInstruction({
|
|
126
210
|
keys,
|
|
@@ -128,61 +212,45 @@ function buildCreateMarketIx(params, marketId, programId = env_1.PROGRAM_ID) {
|
|
|
128
212
|
data,
|
|
129
213
|
});
|
|
130
214
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Serialize outcome metadata for addDepositMint instruction
|
|
133
|
-
*/
|
|
134
|
-
function serializeOutcomeMetadata(metadata) {
|
|
135
|
-
const buffers = [];
|
|
136
|
-
for (const m of metadata) {
|
|
137
|
-
buffers.push((0, utils_1.serializeString)(m.name));
|
|
138
|
-
buffers.push((0, utils_1.serializeString)(m.symbol));
|
|
139
|
-
buffers.push((0, utils_1.serializeString)(m.uri));
|
|
140
|
-
}
|
|
141
|
-
return Buffer.concat(buffers);
|
|
142
|
-
}
|
|
143
215
|
/**
|
|
144
216
|
* Build AddDepositMint instruction
|
|
145
217
|
*
|
|
146
218
|
* Accounts:
|
|
147
|
-
* 0.
|
|
219
|
+
* 0. manager (signer)
|
|
148
220
|
* 1. exchange
|
|
149
221
|
* 2. market
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* 6. token_2022_program
|
|
222
|
+
* 3. deposit_mint
|
|
223
|
+
* 4. vault
|
|
224
|
+
* 5. mint_authority
|
|
225
|
+
* 6. token_program (SPL Token)
|
|
155
226
|
* 7. system_program
|
|
156
|
-
* 8
|
|
227
|
+
* 8. global_deposit_token
|
|
228
|
+
* 9+ conditional_mints[0..num_outcomes]
|
|
157
229
|
*
|
|
158
|
-
* Data: [discriminator
|
|
230
|
+
* Data: [discriminator]
|
|
159
231
|
*/
|
|
160
232
|
function buildAddDepositMintIx(params, market, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
161
|
-
|
|
162
|
-
throw error_1.ProgramSdkError.invalidOutcomeCount(params.outcomeMetadata.length);
|
|
163
|
-
}
|
|
233
|
+
(0, utils_1.validateOutcomes)(numOutcomes);
|
|
164
234
|
const [vault] = (0, pda_1.getVaultPda)(params.depositMint, market, programId);
|
|
165
235
|
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(market, programId);
|
|
166
236
|
const conditionalMints = (0, pda_1.getAllConditionalMintPdas)(market, params.depositMint, numOutcomes, programId);
|
|
167
237
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
238
|
+
const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.depositMint, programId);
|
|
168
239
|
const keys = [
|
|
169
|
-
signerMut(params.
|
|
240
|
+
signerMut(params.manager),
|
|
170
241
|
readonly(exchange),
|
|
171
|
-
|
|
242
|
+
readonly(market),
|
|
172
243
|
readonly(params.depositMint),
|
|
173
244
|
writable(vault),
|
|
174
245
|
readonly(mintAuthority),
|
|
175
246
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
176
|
-
readonly(constants_1.TOKEN_2022_PROGRAM_ID),
|
|
177
247
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
248
|
+
readonly(globalDepositToken),
|
|
178
249
|
];
|
|
179
250
|
for (const [mint] of conditionalMints) {
|
|
180
251
|
keys.push(writable(mint));
|
|
181
252
|
}
|
|
182
|
-
const data = Buffer.
|
|
183
|
-
Buffer.from([constants_1.INSTRUCTION.ADD_DEPOSIT_MINT]),
|
|
184
|
-
serializeOutcomeMetadata(params.outcomeMetadata),
|
|
185
|
-
]);
|
|
253
|
+
const data = Buffer.from([constants_1.INSTRUCTION.ADD_DEPOSIT_MINT]);
|
|
186
254
|
return new web3_js_1.TransactionInstruction({
|
|
187
255
|
keys,
|
|
188
256
|
programId,
|
|
@@ -200,12 +268,10 @@ function buildAddDepositMintIx(params, market, numOutcomes, programId = env_1.PR
|
|
|
200
268
|
* 4. vault
|
|
201
269
|
* 5. user_deposit_ata
|
|
202
270
|
* 6. position
|
|
203
|
-
* 7.
|
|
204
|
-
* 8.
|
|
205
|
-
* 9.
|
|
206
|
-
* 10.
|
|
207
|
-
* 11. associated_token_program
|
|
208
|
-
* 12. system_program
|
|
271
|
+
* 7. mint_authority
|
|
272
|
+
* 8. token_program
|
|
273
|
+
* 9. associated_token_program
|
|
274
|
+
* 10. system_program
|
|
209
275
|
* Remaining: [conditional_mint[i], position_conditional_ata[i]]
|
|
210
276
|
*
|
|
211
277
|
* Data: [discriminator, amount (u64)]
|
|
@@ -216,7 +282,6 @@ function buildDepositIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
216
282
|
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
|
|
217
283
|
const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
|
|
218
284
|
const userDepositAta = (0, utils_1.getDepositTokenAta)(params.depositMint, params.user);
|
|
219
|
-
const positionCollateralAta = (0, utils_1.getDepositTokenAta)(params.depositMint, position);
|
|
220
285
|
const conditionalMints = (0, pda_1.getAllConditionalMintPdas)(params.market, params.depositMint, numOutcomes, programId);
|
|
221
286
|
const keys = [
|
|
222
287
|
signerMut(params.user),
|
|
@@ -226,10 +291,8 @@ function buildDepositIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
226
291
|
writable(vault),
|
|
227
292
|
writable(userDepositAta),
|
|
228
293
|
writable(position),
|
|
229
|
-
writable(positionCollateralAta),
|
|
230
294
|
readonly(mintAuthority),
|
|
231
295
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
232
|
-
readonly(constants_1.TOKEN_2022_PROGRAM_ID),
|
|
233
296
|
readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
|
|
234
297
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
235
298
|
];
|
|
@@ -261,7 +324,6 @@ function buildDepositIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
261
324
|
* 6. user_deposit_ata
|
|
262
325
|
* 7. mint_authority
|
|
263
326
|
* 8. token_program
|
|
264
|
-
* 9. token_2022_program
|
|
265
327
|
* Remaining: [conditional_mint[i], position_conditional_ata[i]]
|
|
266
328
|
*
|
|
267
329
|
* Data: [discriminator, amount (u64)]
|
|
@@ -283,7 +345,6 @@ function buildMergeIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
283
345
|
writable(userDepositAta),
|
|
284
346
|
readonly(mintAuthority),
|
|
285
347
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
286
|
-
readonly(constants_1.TOKEN_2022_PROGRAM_ID),
|
|
287
348
|
];
|
|
288
349
|
for (const [mint] of conditionalMints) {
|
|
289
350
|
keys.push(writable(mint));
|
|
@@ -304,21 +365,22 @@ function buildMergeIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
304
365
|
* Build CancelOrder instruction
|
|
305
366
|
*
|
|
306
367
|
* Accounts:
|
|
307
|
-
* 0.
|
|
308
|
-
* 1.
|
|
309
|
-
* 2.
|
|
310
|
-
* 3.
|
|
368
|
+
* 0. operator (signer, mut)
|
|
369
|
+
* 1. exchange (readonly)
|
|
370
|
+
* 2. market (readonly)
|
|
371
|
+
* 3. order_status (mut)
|
|
311
372
|
*
|
|
312
|
-
* Data: [discriminator, order_hash (32), signed_order (
|
|
373
|
+
* Data: [discriminator, order_hash (32), signed_order (233)]
|
|
313
374
|
*/
|
|
314
|
-
function buildCancelOrderIx(
|
|
375
|
+
function buildCancelOrderIx(operator, market, order, programId = env_1.PROGRAM_ID) {
|
|
315
376
|
const orderHash = (0, orders_1.hashOrder)(order);
|
|
377
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
316
378
|
const [orderStatus] = (0, pda_1.getOrderStatusPda)(orderHash, programId);
|
|
317
379
|
const keys = [
|
|
318
|
-
signerMut(
|
|
380
|
+
signerMut(operator),
|
|
381
|
+
readonly(exchange),
|
|
319
382
|
readonly(market),
|
|
320
383
|
writable(orderStatus),
|
|
321
|
-
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
322
384
|
];
|
|
323
385
|
const data = Buffer.concat([
|
|
324
386
|
Buffer.from([constants_1.INSTRUCTION.CANCEL_ORDER]),
|
|
@@ -338,15 +400,18 @@ function buildCancelOrderIx(maker, market, order, programId = env_1.PROGRAM_ID)
|
|
|
338
400
|
* 0. user (signer, mut)
|
|
339
401
|
* 1. user_nonce (mut)
|
|
340
402
|
* 2. system_program (readonly)
|
|
403
|
+
* 3. exchange (readonly)
|
|
341
404
|
*
|
|
342
405
|
* Data: [discriminator]
|
|
343
406
|
*/
|
|
344
407
|
function buildIncrementNonceIx(user, programId = env_1.PROGRAM_ID) {
|
|
345
408
|
const [userNonce] = (0, pda_1.getUserNoncePda)(user, programId);
|
|
409
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
346
410
|
const keys = [
|
|
347
411
|
signerMut(user),
|
|
348
412
|
writable(userNonce),
|
|
349
413
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
414
|
+
readonly(exchange),
|
|
350
415
|
];
|
|
351
416
|
const data = Buffer.from([constants_1.INSTRUCTION.INCREMENT_NONCE]);
|
|
352
417
|
return new web3_js_1.TransactionInstruction({
|
|
@@ -363,19 +428,20 @@ function buildIncrementNonceIx(user, programId = env_1.PROGRAM_ID) {
|
|
|
363
428
|
* 1. exchange (readonly)
|
|
364
429
|
* 2. market (mut)
|
|
365
430
|
*
|
|
366
|
-
* Data: [discriminator,
|
|
431
|
+
* Data: [discriminator, payout_numerator_0 (u32), ...]
|
|
367
432
|
*/
|
|
368
433
|
function buildSettleMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
434
|
+
validatePayoutNumerators(params.payoutNumerators);
|
|
369
435
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
370
436
|
const [market] = (0, pda_1.getMarketPda)(params.marketId, programId);
|
|
371
437
|
const keys = [
|
|
372
|
-
|
|
438
|
+
signer(params.oracle),
|
|
373
439
|
readonly(exchange),
|
|
374
440
|
writable(market),
|
|
375
441
|
];
|
|
376
442
|
const data = Buffer.concat([
|
|
377
443
|
Buffer.from([constants_1.INSTRUCTION.SETTLE_MARKET]),
|
|
378
|
-
(
|
|
444
|
+
...params.payoutNumerators.map(utils_1.toU32Le),
|
|
379
445
|
]);
|
|
380
446
|
return new web3_js_1.TransactionInstruction({
|
|
381
447
|
keys,
|
|
@@ -397,33 +463,38 @@ function buildSettleMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
397
463
|
* 7. user_deposit_ata
|
|
398
464
|
* 8. mint_authority
|
|
399
465
|
* 9. token_program
|
|
400
|
-
* 10.
|
|
466
|
+
* 10. exchange
|
|
401
467
|
*
|
|
402
|
-
* Data: [discriminator, amount (u64)]
|
|
468
|
+
* Data: [discriminator, amount (u64), outcome_index (u8)]
|
|
403
469
|
*/
|
|
404
|
-
function buildRedeemWinningsIx(params,
|
|
470
|
+
function buildRedeemWinningsIx(params, outcomeIndex, programId = env_1.PROGRAM_ID) {
|
|
471
|
+
if (!Number.isInteger(outcomeIndex) || outcomeIndex < 0 || outcomeIndex > 0xff) {
|
|
472
|
+
throw error_1.ProgramSdkError.invalidOutcomeIndex(outcomeIndex, 0xff);
|
|
473
|
+
}
|
|
474
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
405
475
|
const [vault] = (0, pda_1.getVaultPda)(params.depositMint, params.market, programId);
|
|
406
476
|
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
|
|
407
477
|
const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
|
|
408
|
-
const [
|
|
409
|
-
const
|
|
478
|
+
const [conditionalMint] = (0, pda_1.getConditionalMintPda)(params.market, params.depositMint, outcomeIndex, programId);
|
|
479
|
+
const positionConditionalAta = (0, utils_1.getConditionalTokenAta)(conditionalMint, position);
|
|
410
480
|
const userDepositAta = (0, utils_1.getDepositTokenAta)(params.depositMint, params.user);
|
|
411
481
|
const keys = [
|
|
412
482
|
signerMut(params.user),
|
|
413
483
|
readonly(params.market),
|
|
414
484
|
readonly(params.depositMint),
|
|
415
485
|
writable(vault),
|
|
416
|
-
writable(
|
|
417
|
-
|
|
418
|
-
writable(
|
|
486
|
+
writable(conditionalMint),
|
|
487
|
+
readonly(position),
|
|
488
|
+
writable(positionConditionalAta),
|
|
419
489
|
writable(userDepositAta),
|
|
420
490
|
readonly(mintAuthority),
|
|
421
491
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
422
|
-
readonly(
|
|
492
|
+
readonly(exchange),
|
|
423
493
|
];
|
|
424
494
|
const data = Buffer.concat([
|
|
425
495
|
Buffer.from([constants_1.INSTRUCTION.REDEEM_WINNINGS]),
|
|
426
496
|
(0, utils_1.toU64Le)(params.amount),
|
|
497
|
+
(0, utils_1.toU8)(outcomeIndex),
|
|
427
498
|
]);
|
|
428
499
|
return new web3_js_1.TransactionInstruction({
|
|
429
500
|
keys,
|
|
@@ -486,18 +557,15 @@ function buildSetOperatorIx(authority, newOperator, programId = env_1.PROGRAM_ID
|
|
|
486
557
|
* 4. position_ata (mut)
|
|
487
558
|
* 5. user_ata (mut)
|
|
488
559
|
* 6. token_program (readonly)
|
|
560
|
+
* 7. exchange (readonly)
|
|
489
561
|
*
|
|
490
562
|
* Data: [discriminator, amount (u64), outcome_index (u8)]
|
|
491
563
|
*/
|
|
492
|
-
function buildWithdrawFromPositionIx(params,
|
|
564
|
+
function buildWithdrawFromPositionIx(params, programId = env_1.PROGRAM_ID) {
|
|
565
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
493
566
|
const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
|
|
494
|
-
const positionAta =
|
|
495
|
-
|
|
496
|
-
: (0, utils_1.getDepositTokenAta)(params.mint, position);
|
|
497
|
-
const userAta = isToken2022
|
|
498
|
-
? (0, utils_1.getConditionalTokenAta)(params.mint, params.user)
|
|
499
|
-
: (0, utils_1.getDepositTokenAta)(params.mint, params.user);
|
|
500
|
-
const tokenProgram = isToken2022 ? constants_1.TOKEN_2022_PROGRAM_ID : constants_1.TOKEN_PROGRAM_ID;
|
|
567
|
+
const positionAta = (0, utils_1.getConditionalTokenAta)(params.mint, position);
|
|
568
|
+
const userAta = (0, utils_1.getConditionalTokenAta)(params.mint, params.user);
|
|
501
569
|
const keys = [
|
|
502
570
|
signerMut(params.user),
|
|
503
571
|
readonly(params.market),
|
|
@@ -505,7 +573,8 @@ function buildWithdrawFromPositionIx(params, isToken2022, programId = env_1.PROG
|
|
|
505
573
|
readonly(params.mint),
|
|
506
574
|
writable(positionAta),
|
|
507
575
|
writable(userAta),
|
|
508
|
-
readonly(
|
|
576
|
+
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
577
|
+
readonly(exchange),
|
|
509
578
|
];
|
|
510
579
|
const data = Buffer.concat([
|
|
511
580
|
Buffer.from([constants_1.INSTRUCTION.WITHDRAW_FROM_POSITION]),
|
|
@@ -522,7 +591,7 @@ function buildWithdrawFromPositionIx(params, isToken2022, programId = env_1.PROG
|
|
|
522
591
|
* Build ActivateMarket instruction
|
|
523
592
|
*
|
|
524
593
|
* Accounts:
|
|
525
|
-
* 0.
|
|
594
|
+
* 0. manager (signer)
|
|
526
595
|
* 1. exchange (readonly)
|
|
527
596
|
* 2. market (mut)
|
|
528
597
|
*
|
|
@@ -532,7 +601,7 @@ function buildActivateMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
532
601
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
533
602
|
const [market] = (0, pda_1.getMarketPda)(params.marketId, programId);
|
|
534
603
|
const keys = [
|
|
535
|
-
signerMut(params.
|
|
604
|
+
signerMut(params.manager),
|
|
536
605
|
readonly(exchange),
|
|
537
606
|
writable(market),
|
|
538
607
|
];
|
|
@@ -550,6 +619,7 @@ function buildActivateMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
550
619
|
* 0. operator (signer)
|
|
551
620
|
* 1. exchange (readonly)
|
|
552
621
|
* 2. market (readonly)
|
|
622
|
+
* 3. orderbook (readonly)
|
|
553
623
|
* [taker_order_status if bit7=0] (mut)
|
|
554
624
|
* taker_nonce (readonly)
|
|
555
625
|
* taker_position (mut)
|
|
@@ -557,8 +627,9 @@ function buildActivateMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
557
627
|
* quote_mint (readonly)
|
|
558
628
|
* taker_base_ata (mut)
|
|
559
629
|
* taker_quote_ata (mut)
|
|
560
|
-
*
|
|
630
|
+
* token_program (readonly)
|
|
561
631
|
* system_program (readonly)
|
|
632
|
+
* fee_receiver_quote_ata (mut)
|
|
562
633
|
* Per maker:
|
|
563
634
|
* [maker_order_status if bit_i=0] (mut)
|
|
564
635
|
* maker_nonce (readonly)
|
|
@@ -568,15 +639,15 @@ function buildActivateMarketIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
568
639
|
*
|
|
569
640
|
* Data:
|
|
570
641
|
* [0] discriminator
|
|
571
|
-
* [1..
|
|
572
|
-
* [
|
|
573
|
-
* [
|
|
574
|
-
* [
|
|
575
|
-
* Per maker (
|
|
576
|
-
* [+0..+
|
|
577
|
-
* [+
|
|
578
|
-
* [+
|
|
579
|
-
* [+
|
|
642
|
+
* [1..38] taker Order (37 bytes)
|
|
643
|
+
* [38..102] taker_signature (64 bytes)
|
|
644
|
+
* [102] num_makers
|
|
645
|
+
* [103] full_fill_bitmask
|
|
646
|
+
* Per maker (117 bytes):
|
|
647
|
+
* [+0..+37] maker Order (37)
|
|
648
|
+
* [+37..+101] maker_signature (64)
|
|
649
|
+
* [+101..+109] maker_fill_amount (8)
|
|
650
|
+
* [+109..+117] taker_fill_amount (8)
|
|
580
651
|
*/
|
|
581
652
|
function buildMatchOrdersMultiIx(params, programId = env_1.PROGRAM_ID) {
|
|
582
653
|
if (params.makerOrders.length === 0) {
|
|
@@ -592,15 +663,18 @@ function buildMatchOrdersMultiIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
592
663
|
throw error_1.ProgramSdkError.invalidDataLength("takerFillAmounts", params.makerOrders.length, params.takerFillAmounts.length);
|
|
593
664
|
}
|
|
594
665
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
666
|
+
const [orderbook] = (0, pda_1.getOrderbookPda)(params.baseMint, params.quoteMint, programId);
|
|
595
667
|
const takerOrderHash = (0, orders_1.hashOrder)(params.takerOrder);
|
|
596
668
|
const [takerNonce] = (0, pda_1.getUserNoncePda)(params.takerOrder.maker, programId);
|
|
597
669
|
const [takerPosition] = (0, pda_1.getPositionPda)(params.takerOrder.maker, params.market, programId);
|
|
598
670
|
const takerBaseAta = (0, utils_1.getConditionalTokenAta)(params.baseMint, takerPosition);
|
|
599
671
|
const takerQuoteAta = (0, utils_1.getConditionalTokenAta)(params.quoteMint, takerPosition);
|
|
672
|
+
const feeReceiverQuoteAta = (0, utils_1.getConditionalTokenAta)(params.quoteMint, params.feeReceiver);
|
|
600
673
|
const keys = [
|
|
601
674
|
signerMut(params.operator),
|
|
602
675
|
readonly(exchange),
|
|
603
676
|
readonly(params.market),
|
|
677
|
+
readonly(orderbook),
|
|
604
678
|
];
|
|
605
679
|
// Taker order status if not fully filled (bit 7 = 0)
|
|
606
680
|
const takerFullFill = (params.fullFillBitmask & 0x80) !== 0;
|
|
@@ -614,8 +688,9 @@ function buildMatchOrdersMultiIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
614
688
|
keys.push(readonly(params.quoteMint));
|
|
615
689
|
keys.push(writable(takerBaseAta));
|
|
616
690
|
keys.push(writable(takerQuoteAta));
|
|
617
|
-
keys.push(readonly(constants_1.
|
|
691
|
+
keys.push(readonly(constants_1.TOKEN_PROGRAM_ID));
|
|
618
692
|
keys.push(readonly(constants_1.SYSTEM_PROGRAM_ID));
|
|
693
|
+
keys.push(writable(feeReceiverQuoteAta));
|
|
619
694
|
// Add maker accounts
|
|
620
695
|
for (let i = 0; i < params.makerOrders.length; i++) {
|
|
621
696
|
const makerOrder = params.makerOrders[i];
|
|
@@ -688,37 +763,79 @@ function buildSetAuthorityIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
688
763
|
* Build CreateOrderbook instruction
|
|
689
764
|
*
|
|
690
765
|
* Accounts:
|
|
691
|
-
* 0.
|
|
766
|
+
* 0. manager (signer, mut)
|
|
692
767
|
* 1. market (readonly)
|
|
693
|
-
* 2. mint_a (readonly)
|
|
694
|
-
* 3. mint_b (readonly)
|
|
768
|
+
* 2. mint_a (readonly, canonical order)
|
|
769
|
+
* 3. mint_b (readonly, canonical order)
|
|
695
770
|
* 4. orderbook (mut)
|
|
696
771
|
* 5. lookup_table (mut)
|
|
697
772
|
* 6. exchange (readonly)
|
|
698
773
|
* 7. alt_program (readonly)
|
|
699
774
|
* 8. system_program (readonly)
|
|
775
|
+
* 9. mint_a_deposit_mint (readonly, canonical order)
|
|
776
|
+
* 10. mint_b_deposit_mint (readonly, canonical order)
|
|
777
|
+
* 11. token_program
|
|
778
|
+
* 12. associated_token_program
|
|
779
|
+
* 13. fee_receiver
|
|
780
|
+
* 14. fee_receiver_quote_ata
|
|
700
781
|
*
|
|
701
|
-
* Data: [discriminator, recent_slot (u64), base_index (u8)]
|
|
782
|
+
* Data: [discriminator, recent_slot (u64), base_index (u8), mint_a_outcome_index (u8), mint_b_outcome_index (u8)]
|
|
702
783
|
*/
|
|
703
784
|
function buildCreateOrderbookIx(params, programId = env_1.PROGRAM_ID) {
|
|
785
|
+
const canonical = canonicalOrderbookMints(params);
|
|
704
786
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
705
|
-
const [orderbook] = (0, pda_1.getOrderbookPda)(
|
|
787
|
+
const [orderbook] = (0, pda_1.getOrderbookPda)(canonical.mintA.mint, canonical.mintB.mint, programId);
|
|
706
788
|
const [alt] = (0, pda_1.getAltPda)(orderbook, params.recentSlot);
|
|
789
|
+
const quoteMint = canonical.baseIndex === 0 ? canonical.mintB.mint : canonical.mintA.mint;
|
|
790
|
+
const feeReceiverQuoteAta = (0, utils_1.getConditionalTokenAta)(quoteMint, params.feeReceiver);
|
|
707
791
|
const keys = [
|
|
708
|
-
signerMut(params.
|
|
792
|
+
signerMut(params.manager),
|
|
709
793
|
readonly(params.market),
|
|
710
|
-
readonly(
|
|
711
|
-
readonly(
|
|
794
|
+
readonly(canonical.mintA.mint),
|
|
795
|
+
readonly(canonical.mintB.mint),
|
|
712
796
|
writable(orderbook),
|
|
713
797
|
writable(alt),
|
|
714
798
|
readonly(exchange),
|
|
715
799
|
readonly(constants_1.ALT_PROGRAM_ID),
|
|
716
800
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
801
|
+
readonly(canonical.mintA.depositMint),
|
|
802
|
+
readonly(canonical.mintB.depositMint),
|
|
803
|
+
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
804
|
+
readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
|
|
805
|
+
readonly(params.feeReceiver),
|
|
806
|
+
writable(feeReceiverQuoteAta),
|
|
717
807
|
];
|
|
718
808
|
const data = Buffer.concat([
|
|
719
809
|
Buffer.from([constants_1.INSTRUCTION.CREATE_ORDERBOOK]),
|
|
720
810
|
(0, utils_1.toU64Le)(params.recentSlot),
|
|
721
|
-
|
|
811
|
+
(0, utils_1.toU8)(canonical.baseIndex),
|
|
812
|
+
(0, utils_1.toU8)(canonical.mintA.outcomeIndex),
|
|
813
|
+
(0, utils_1.toU8)(canonical.mintB.outcomeIndex),
|
|
814
|
+
]);
|
|
815
|
+
return new web3_js_1.TransactionInstruction({
|
|
816
|
+
keys,
|
|
817
|
+
programId,
|
|
818
|
+
data,
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Build SetManager instruction
|
|
823
|
+
*
|
|
824
|
+
* Accounts:
|
|
825
|
+
* 0. authority (signer)
|
|
826
|
+
* 1. exchange (mut)
|
|
827
|
+
*
|
|
828
|
+
* Data: [discriminator, new_manager (32)]
|
|
829
|
+
*/
|
|
830
|
+
function buildSetManagerIx(params, programId = env_1.PROGRAM_ID) {
|
|
831
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
832
|
+
const keys = [
|
|
833
|
+
signerMut(params.authority),
|
|
834
|
+
writable(exchange),
|
|
835
|
+
];
|
|
836
|
+
const data = Buffer.concat([
|
|
837
|
+
Buffer.from([constants_1.INSTRUCTION.SET_MANAGER]),
|
|
838
|
+
params.newManager.toBuffer(),
|
|
722
839
|
]);
|
|
723
840
|
return new web3_js_1.TransactionInstruction({
|
|
724
841
|
keys,
|
|
@@ -726,6 +843,96 @@ function buildCreateOrderbookIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
726
843
|
data,
|
|
727
844
|
});
|
|
728
845
|
}
|
|
846
|
+
/**
|
|
847
|
+
* Build SetMarketFees instruction.
|
|
848
|
+
*/
|
|
849
|
+
function buildSetMarketFeesIx(params, programId = env_1.PROGRAM_ID) {
|
|
850
|
+
if (params.updates.length === 0) {
|
|
851
|
+
throw error_1.ProgramSdkError.missingField("updates");
|
|
852
|
+
}
|
|
853
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
854
|
+
const keys = [
|
|
855
|
+
signerMut(params.manager),
|
|
856
|
+
readonly(exchange),
|
|
857
|
+
];
|
|
858
|
+
const buffers = [Buffer.from([constants_1.INSTRUCTION.SET_MARKET_FEES])];
|
|
859
|
+
for (const update of params.updates) {
|
|
860
|
+
(0, utils_1.validateFeePair)(update.makerFeeBps, update.takerFeeBps);
|
|
861
|
+
keys.push(writable(update.market));
|
|
862
|
+
buffers.push((0, utils_1.toI16Le)(update.makerFeeBps));
|
|
863
|
+
buffers.push((0, utils_1.toI16Le)(update.takerFeeBps));
|
|
864
|
+
}
|
|
865
|
+
return new web3_js_1.TransactionInstruction({
|
|
866
|
+
keys,
|
|
867
|
+
programId,
|
|
868
|
+
data: Buffer.concat(buffers),
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* Build SetFeeReceiver instruction.
|
|
873
|
+
*/
|
|
874
|
+
function buildSetFeeReceiverIx(params, programId = env_1.PROGRAM_ID) {
|
|
875
|
+
if (params.newFeeReceiver.equals(zeroPubkey())) {
|
|
876
|
+
throw error_1.ProgramSdkError.invalidFeeReceiver();
|
|
877
|
+
}
|
|
878
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
879
|
+
const keys = [
|
|
880
|
+
signerMut(params.authority),
|
|
881
|
+
writable(exchange),
|
|
882
|
+
];
|
|
883
|
+
return new web3_js_1.TransactionInstruction({
|
|
884
|
+
keys,
|
|
885
|
+
programId,
|
|
886
|
+
data: Buffer.concat([
|
|
887
|
+
Buffer.from([constants_1.INSTRUCTION.SET_FEE_RECEIVER]),
|
|
888
|
+
params.newFeeReceiver.toBuffer(),
|
|
889
|
+
]),
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
function buildCreateConditionalMetadataIx(params, programId = env_1.PROGRAM_ID) {
|
|
893
|
+
return buildConditionalMetadataIx(params, true, programId);
|
|
894
|
+
}
|
|
895
|
+
function buildUpdateConditionalMetadataIx(params, programId = env_1.PROGRAM_ID) {
|
|
896
|
+
return buildConditionalMetadataIx(params, false, programId);
|
|
897
|
+
}
|
|
898
|
+
function buildConditionalMetadataIx(params, isCreate, programId) {
|
|
899
|
+
if (!Number.isInteger(params.outcomeIndex) ||
|
|
900
|
+
params.outcomeIndex < 0 ||
|
|
901
|
+
params.outcomeIndex >= constants_1.MAX_OUTCOMES) {
|
|
902
|
+
throw error_1.ProgramSdkError.invalidOutcomeIndex(params.outcomeIndex, constants_1.MAX_OUTCOMES - 1);
|
|
903
|
+
}
|
|
904
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
905
|
+
const [conditionalMint] = (0, pda_1.getConditionalMintPda)(params.market, params.depositMint, params.outcomeIndex, programId);
|
|
906
|
+
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
|
|
907
|
+
const [metadata] = (0, pda_1.getMplMetadataPda)(conditionalMint);
|
|
908
|
+
const keys = [
|
|
909
|
+
isCreate ? signerMut(params.manager) : signer(params.manager),
|
|
910
|
+
readonly(exchange),
|
|
911
|
+
readonly(params.market),
|
|
912
|
+
readonly(params.depositMint),
|
|
913
|
+
readonly(conditionalMint),
|
|
914
|
+
writable(metadata),
|
|
915
|
+
readonly(mintAuthority),
|
|
916
|
+
readonly(constants_1.MPL_TOKEN_METADATA_PROGRAM_ID),
|
|
917
|
+
];
|
|
918
|
+
if (isCreate) {
|
|
919
|
+
keys.push(readonly(constants_1.SYSTEM_PROGRAM_ID));
|
|
920
|
+
keys.push(readonly(constants_1.RENT_SYSVAR_ID));
|
|
921
|
+
}
|
|
922
|
+
return new web3_js_1.TransactionInstruction({
|
|
923
|
+
keys,
|
|
924
|
+
programId,
|
|
925
|
+
data: Buffer.concat([
|
|
926
|
+
Buffer.from([
|
|
927
|
+
isCreate
|
|
928
|
+
? constants_1.INSTRUCTION.CREATE_CONDITIONAL_METADATA
|
|
929
|
+
: constants_1.INSTRUCTION.UPDATE_CONDITIONAL_METADATA,
|
|
930
|
+
params.outcomeIndex,
|
|
931
|
+
]),
|
|
932
|
+
(0, utils_1.serializeConditionalMetadata)(params.name, params.symbol, params.uri),
|
|
933
|
+
]),
|
|
934
|
+
});
|
|
935
|
+
}
|
|
729
936
|
/**
|
|
730
937
|
* Build WhitelistDepositToken instruction
|
|
731
938
|
*
|
|
@@ -765,12 +972,27 @@ function buildWhitelistDepositTokenIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
765
972
|
* 4. user_token_account (mut)
|
|
766
973
|
* 5. token_program (readonly)
|
|
767
974
|
* 6. system_program (readonly)
|
|
975
|
+
* 7. exchange (readonly)
|
|
976
|
+
* Optional ALT accounts:
|
|
977
|
+
* 8. user_nonce (readonly)
|
|
978
|
+
* 9. lookup_table (mut)
|
|
979
|
+
* 10. alt_program (readonly)
|
|
768
980
|
*
|
|
769
|
-
* Data: [discriminator, amount (u64)]
|
|
981
|
+
* Data: [discriminator, amount (u64), recent_slot (u64 if creating ALT)]
|
|
770
982
|
*/
|
|
771
983
|
function buildDepositToGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
984
|
+
return buildDepositToGlobalIxInner(params, undefined, programId);
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Build DepositToGlobal instruction with user deposit ALT create/extend accounts.
|
|
988
|
+
*/
|
|
989
|
+
function buildDepositToGlobalIxWithAlt(params, altContext, programId = env_1.PROGRAM_ID) {
|
|
990
|
+
return buildDepositToGlobalIxInner(params, altContext, programId);
|
|
991
|
+
}
|
|
992
|
+
function buildDepositToGlobalIxInner(params, altContext, programId) {
|
|
772
993
|
const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.mint, programId);
|
|
773
994
|
const [userGlobalDeposit] = (0, pda_1.getUserGlobalDepositPda)(params.user, params.mint, programId);
|
|
995
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
774
996
|
const userTokenAccount = (0, utils_1.getDepositTokenAta)(params.mint, params.user);
|
|
775
997
|
const keys = [
|
|
776
998
|
signerMut(params.user),
|
|
@@ -780,15 +1002,28 @@ function buildDepositToGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
780
1002
|
writable(userTokenAccount),
|
|
781
1003
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
782
1004
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
1005
|
+
readonly(exchange),
|
|
783
1006
|
];
|
|
784
|
-
const
|
|
1007
|
+
const dataBuffers = [
|
|
785
1008
|
Buffer.from([constants_1.INSTRUCTION.DEPOSIT_TO_GLOBAL]),
|
|
786
1009
|
(0, utils_1.toU64Le)(params.amount),
|
|
787
|
-
]
|
|
1010
|
+
];
|
|
1011
|
+
if (altContext !== undefined) {
|
|
1012
|
+
const [userNonce] = (0, pda_1.getUserNoncePda)(params.user, programId);
|
|
1013
|
+
const lookupTable = altContext.kind === "create"
|
|
1014
|
+
? (0, pda_1.getAltPda)(userNonce, altContext.recentSlot)[0]
|
|
1015
|
+
: altContext.lookupTable;
|
|
1016
|
+
if (altContext.kind === "create") {
|
|
1017
|
+
dataBuffers.push((0, utils_1.toU64Le)(altContext.recentSlot));
|
|
1018
|
+
}
|
|
1019
|
+
keys.push(readonly(userNonce));
|
|
1020
|
+
keys.push(writable(lookupTable));
|
|
1021
|
+
keys.push(readonly(constants_1.ALT_PROGRAM_ID));
|
|
1022
|
+
}
|
|
788
1023
|
return new web3_js_1.TransactionInstruction({
|
|
789
1024
|
keys,
|
|
790
1025
|
programId,
|
|
791
|
-
data,
|
|
1026
|
+
data: Buffer.concat(dataBuffers),
|
|
792
1027
|
});
|
|
793
1028
|
}
|
|
794
1029
|
/**
|
|
@@ -803,12 +1038,10 @@ function buildDepositToGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
803
1038
|
* 5. global_deposit_token (readonly)
|
|
804
1039
|
* 6. user_global_deposit (mut)
|
|
805
1040
|
* 7. position (mut)
|
|
806
|
-
* 8.
|
|
807
|
-
* 9.
|
|
808
|
-
* 10.
|
|
809
|
-
* 11.
|
|
810
|
-
* 12. ata_program (readonly)
|
|
811
|
-
* 13. system_program (readonly)
|
|
1041
|
+
* 8. mint_authority (readonly)
|
|
1042
|
+
* 9. token_program (readonly)
|
|
1043
|
+
* 10. ata_program (readonly)
|
|
1044
|
+
* 11. system_program (readonly)
|
|
812
1045
|
* + per outcome: conditional_mint[i] (mut), position_conditional_ata[i] (mut)
|
|
813
1046
|
*
|
|
814
1047
|
* Data: [discriminator, amount (u64)]
|
|
@@ -819,7 +1052,6 @@ function buildGlobalToMarketDepositIx(params, numOutcomes, programId = env_1.PRO
|
|
|
819
1052
|
const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.depositMint, programId);
|
|
820
1053
|
const [userGlobalDeposit] = (0, pda_1.getUserGlobalDepositPda)(params.user, params.depositMint, programId);
|
|
821
1054
|
const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
|
|
822
|
-
const positionCollateralAta = (0, utils_1.getDepositTokenAta)(params.depositMint, position);
|
|
823
1055
|
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
|
|
824
1056
|
const keys = [
|
|
825
1057
|
signerMut(params.user),
|
|
@@ -830,10 +1062,8 @@ function buildGlobalToMarketDepositIx(params, numOutcomes, programId = env_1.PRO
|
|
|
830
1062
|
readonly(globalDepositToken),
|
|
831
1063
|
writable(userGlobalDeposit),
|
|
832
1064
|
writable(position),
|
|
833
|
-
writable(positionCollateralAta),
|
|
834
1065
|
readonly(mintAuthority),
|
|
835
1066
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
836
|
-
readonly(constants_1.TOKEN_2022_PROGRAM_ID),
|
|
837
1067
|
readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
|
|
838
1068
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
839
1069
|
];
|
|
@@ -856,19 +1086,18 @@ function buildGlobalToMarketDepositIx(params, numOutcomes, programId = env_1.PRO
|
|
|
856
1086
|
* Build InitPositionTokens instruction
|
|
857
1087
|
*
|
|
858
1088
|
* Accounts:
|
|
859
|
-
* 0.
|
|
860
|
-
* 1.
|
|
861
|
-
* 2.
|
|
862
|
-
* 3.
|
|
863
|
-
* 4.
|
|
864
|
-
* 5.
|
|
865
|
-
* 6.
|
|
866
|
-
* 7.
|
|
867
|
-
* 8.
|
|
868
|
-
* 9.
|
|
869
|
-
* 10.
|
|
870
|
-
*
|
|
871
|
-
* + per outcome: conditional_mint[i] (readonly), position_conditional_ata[i] (mut)
|
|
1089
|
+
* 0. payer (signer, mut)
|
|
1090
|
+
* 1. user (readonly)
|
|
1091
|
+
* 2. exchange (readonly)
|
|
1092
|
+
* 3. market (readonly)
|
|
1093
|
+
* 4. position (mut)
|
|
1094
|
+
* 5. lookup_table (mut)
|
|
1095
|
+
* 6. mint_authority (readonly)
|
|
1096
|
+
* 7. token_program (readonly)
|
|
1097
|
+
* 8. ata_program (readonly)
|
|
1098
|
+
* 9. alt_program (readonly)
|
|
1099
|
+
* 10. system_program (readonly)
|
|
1100
|
+
* + per deposit_mint: deposit_mint, vault, gdt, conditional_mint/position_ata pairs
|
|
872
1101
|
*
|
|
873
1102
|
* Data: [discriminator, recent_slot (u64)]
|
|
874
1103
|
*/
|
|
@@ -885,7 +1114,7 @@ function buildInitPositionTokensIx(params, numOutcomes, programId = env_1.PROGRA
|
|
|
885
1114
|
writable(position),
|
|
886
1115
|
writable(lookupTable),
|
|
887
1116
|
readonly(mintAuthority),
|
|
888
|
-
readonly(constants_1.
|
|
1117
|
+
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
889
1118
|
readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
|
|
890
1119
|
readonly(constants_1.ALT_PROGRAM_ID),
|
|
891
1120
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
@@ -916,16 +1145,17 @@ function buildInitPositionTokensIx(params, numOutcomes, programId = env_1.PROGRA
|
|
|
916
1145
|
/**
|
|
917
1146
|
* Build ExtendPositionTokens instruction
|
|
918
1147
|
*
|
|
919
|
-
* Extends an existing position's lookup table
|
|
1148
|
+
* Operator-only. Extends an existing position's lookup table after a market
|
|
1149
|
+
* adds new deposit mints.
|
|
920
1150
|
*
|
|
921
1151
|
* Accounts:
|
|
922
|
-
* 0.
|
|
1152
|
+
* 0. operator (signer, mut)
|
|
923
1153
|
* 1. user (readonly)
|
|
924
1154
|
* 2. exchange (readonly)
|
|
925
1155
|
* 3. market (readonly)
|
|
926
1156
|
* 4. position (readonly)
|
|
927
1157
|
* 5. lookup_table (mut)
|
|
928
|
-
* 6.
|
|
1158
|
+
* 6. token_program (readonly)
|
|
929
1159
|
* 7. ata_program (readonly)
|
|
930
1160
|
* 8. alt_program (readonly)
|
|
931
1161
|
* 9. system_program (readonly)
|
|
@@ -942,13 +1172,13 @@ function buildExtendPositionTokensIx(params, numOutcomes, programId = env_1.PROG
|
|
|
942
1172
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
943
1173
|
const [position] = (0, pda_1.getPositionPda)(params.user, params.market, programId);
|
|
944
1174
|
const keys = [
|
|
945
|
-
signerMut(params.
|
|
1175
|
+
signerMut(params.operator),
|
|
946
1176
|
readonly(params.user),
|
|
947
1177
|
readonly(exchange),
|
|
948
1178
|
readonly(params.market),
|
|
949
1179
|
readonly(position),
|
|
950
1180
|
writable(params.lookupTable),
|
|
951
|
-
readonly(constants_1.
|
|
1181
|
+
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
952
1182
|
readonly(constants_1.ASSOCIATED_TOKEN_PROGRAM_ID),
|
|
953
1183
|
readonly(constants_1.ALT_PROGRAM_ID),
|
|
954
1184
|
readonly(constants_1.SYSTEM_PROGRAM_ID),
|
|
@@ -988,9 +1218,11 @@ function buildDepositAndSwapIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
988
1218
|
throw error_1.ProgramSdkError.tooManyMakers(params.makers.length);
|
|
989
1219
|
}
|
|
990
1220
|
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1221
|
+
const [orderbook] = (0, pda_1.getOrderbookPda)(params.baseMint, params.quoteMint, programId);
|
|
991
1222
|
const [mintAuthority] = (0, pda_1.getMintAuthorityPda)(params.market, programId);
|
|
992
1223
|
const [takerNonce] = (0, pda_1.getUserNoncePda)(params.takerOrder.maker, programId);
|
|
993
1224
|
const [takerPosition] = (0, pda_1.getPositionPda)(params.takerOrder.maker, params.market, programId);
|
|
1225
|
+
const feeReceiverQuoteAta = (0, utils_1.getConditionalTokenAta)(params.quoteMint, params.feeReceiver);
|
|
994
1226
|
const [receiveMint, giveMint] = params.takerOrder.side === types_1.OrderSide.BID
|
|
995
1227
|
? [params.baseMint, params.quoteMint]
|
|
996
1228
|
: [params.quoteMint, params.baseMint];
|
|
@@ -1015,8 +1247,10 @@ function buildDepositAndSwapIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1015
1247
|
signerMut(params.operator),
|
|
1016
1248
|
readonly(exchange),
|
|
1017
1249
|
readonly(params.market),
|
|
1250
|
+
readonly(orderbook),
|
|
1018
1251
|
readonly(mintAuthority),
|
|
1019
1252
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
1253
|
+
writable(feeReceiverQuoteAta),
|
|
1020
1254
|
];
|
|
1021
1255
|
if (!params.takerIsFullFill) {
|
|
1022
1256
|
const takerOrderHash = (0, orders_1.hashOrder)(params.takerOrder);
|
|
@@ -1029,7 +1263,6 @@ function buildDepositAndSwapIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1029
1263
|
keys.push(readonly(params.quoteMint));
|
|
1030
1264
|
keys.push(writable((0, utils_1.getConditionalTokenAta)(receiveMint, takerPosition)));
|
|
1031
1265
|
keys.push(writable((0, utils_1.getConditionalTokenAta)(giveMint, takerPosition)));
|
|
1032
|
-
keys.push(readonly(constants_1.TOKEN_2022_PROGRAM_ID));
|
|
1033
1266
|
keys.push(readonly(constants_1.SYSTEM_PROGRAM_ID));
|
|
1034
1267
|
if (params.takerIsDeposit) {
|
|
1035
1268
|
const [vault] = (0, pda_1.getVaultPda)(params.takerDepositMint, params.market, programId);
|
|
@@ -1100,12 +1333,14 @@ function buildDepositAndSwapIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1100
1333
|
* 3. user_global_deposit (mut) - PDA ["global_deposit", user, mint]
|
|
1101
1334
|
* 4. user_token_account (mut) - user's ATA for mint
|
|
1102
1335
|
* 5. token_program (readonly)
|
|
1336
|
+
* 6. exchange (readonly)
|
|
1103
1337
|
*
|
|
1104
1338
|
* Data: [discriminator, amount (u64)]
|
|
1105
1339
|
*/
|
|
1106
1340
|
function buildWithdrawFromGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
1107
1341
|
const [globalDepositToken] = (0, pda_1.getGlobalDepositTokenPda)(params.mint, programId);
|
|
1108
1342
|
const [userGlobalDeposit] = (0, pda_1.getUserGlobalDepositPda)(params.user, params.mint, programId);
|
|
1343
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1109
1344
|
const userTokenAccount = (0, utils_1.getDepositTokenAta)(params.mint, params.user);
|
|
1110
1345
|
const keys = [
|
|
1111
1346
|
signerMut(params.user),
|
|
@@ -1114,6 +1349,7 @@ function buildWithdrawFromGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1114
1349
|
writable(userGlobalDeposit),
|
|
1115
1350
|
writable(userTokenAccount),
|
|
1116
1351
|
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
1352
|
+
readonly(exchange),
|
|
1117
1353
|
];
|
|
1118
1354
|
const data = Buffer.concat([
|
|
1119
1355
|
Buffer.from([constants_1.INSTRUCTION.WITHDRAW_FROM_GLOBAL]),
|
|
@@ -1125,6 +1361,159 @@ function buildWithdrawFromGlobalIx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1125
1361
|
data,
|
|
1126
1362
|
});
|
|
1127
1363
|
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Build ClosePositionAlt instruction
|
|
1366
|
+
*
|
|
1367
|
+
* Accounts:
|
|
1368
|
+
* 0. operator (signer, mut)
|
|
1369
|
+
* 1. exchange (readonly)
|
|
1370
|
+
* 2. position (readonly)
|
|
1371
|
+
* 3. market (readonly)
|
|
1372
|
+
* 4. lookup_table (mut)
|
|
1373
|
+
* 5. alt_program (readonly)
|
|
1374
|
+
*
|
|
1375
|
+
* Data: [discriminator]
|
|
1376
|
+
*/
|
|
1377
|
+
function buildClosePositionAltIx(params, programId = env_1.PROGRAM_ID) {
|
|
1378
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1379
|
+
const keys = [
|
|
1380
|
+
signerMut(params.operator),
|
|
1381
|
+
readonly(exchange),
|
|
1382
|
+
readonly(params.position),
|
|
1383
|
+
readonly(params.market),
|
|
1384
|
+
writable(params.lookupTable),
|
|
1385
|
+
readonly(constants_1.ALT_PROGRAM_ID),
|
|
1386
|
+
];
|
|
1387
|
+
return new web3_js_1.TransactionInstruction({
|
|
1388
|
+
keys,
|
|
1389
|
+
programId,
|
|
1390
|
+
data: Buffer.from([constants_1.INSTRUCTION.CLOSE_POSITION_ALT]),
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Build CloseOrderStatus instruction
|
|
1395
|
+
*
|
|
1396
|
+
* Accounts:
|
|
1397
|
+
* 0. operator (signer, mut)
|
|
1398
|
+
* 1. exchange (readonly)
|
|
1399
|
+
* 2. order_status (mut)
|
|
1400
|
+
*
|
|
1401
|
+
* Data: [discriminator, order_hash (32)]
|
|
1402
|
+
*/
|
|
1403
|
+
function buildCloseOrderStatusIx(params, programId = env_1.PROGRAM_ID) {
|
|
1404
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1405
|
+
const [orderStatus] = (0, pda_1.getOrderStatusPda)(params.orderHash, programId);
|
|
1406
|
+
const keys = [
|
|
1407
|
+
signerMut(params.operator),
|
|
1408
|
+
readonly(exchange),
|
|
1409
|
+
writable(orderStatus),
|
|
1410
|
+
];
|
|
1411
|
+
const data = Buffer.concat([
|
|
1412
|
+
Buffer.from([constants_1.INSTRUCTION.CLOSE_ORDER_STATUS]),
|
|
1413
|
+
params.orderHash,
|
|
1414
|
+
]);
|
|
1415
|
+
return new web3_js_1.TransactionInstruction({
|
|
1416
|
+
keys,
|
|
1417
|
+
programId,
|
|
1418
|
+
data,
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Build ClosePositionTokenAccounts instruction
|
|
1423
|
+
*
|
|
1424
|
+
* Accounts:
|
|
1425
|
+
* 0. operator (signer, mut)
|
|
1426
|
+
* 1. exchange (readonly)
|
|
1427
|
+
* 2. market (readonly)
|
|
1428
|
+
* 3. position (readonly)
|
|
1429
|
+
* 4. token_program (readonly)
|
|
1430
|
+
* + per deposit mint: deposit_mint, conditional_mint/position_ata pairs
|
|
1431
|
+
*
|
|
1432
|
+
* Data: [discriminator]
|
|
1433
|
+
*/
|
|
1434
|
+
function buildClosePositionTokenAccountsIx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1435
|
+
(0, utils_1.validateOutcomes)(numOutcomes);
|
|
1436
|
+
if (params.depositMints.length === 0) {
|
|
1437
|
+
throw error_1.ProgramSdkError.missingField("deposit_mints");
|
|
1438
|
+
}
|
|
1439
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1440
|
+
const keys = [
|
|
1441
|
+
signerMut(params.operator),
|
|
1442
|
+
readonly(exchange),
|
|
1443
|
+
readonly(params.market),
|
|
1444
|
+
readonly(params.position),
|
|
1445
|
+
readonly(constants_1.TOKEN_PROGRAM_ID),
|
|
1446
|
+
];
|
|
1447
|
+
for (const depositMint of params.depositMints) {
|
|
1448
|
+
keys.push(readonly(depositMint));
|
|
1449
|
+
for (let i = 0; i < numOutcomes; i += 1) {
|
|
1450
|
+
const [conditionalMint] = (0, pda_1.getConditionalMintPda)(params.market, depositMint, i, programId);
|
|
1451
|
+
keys.push(readonly(conditionalMint));
|
|
1452
|
+
keys.push(writable((0, utils_1.getConditionalTokenAta)(conditionalMint, params.position)));
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return new web3_js_1.TransactionInstruction({
|
|
1456
|
+
keys,
|
|
1457
|
+
programId,
|
|
1458
|
+
data: Buffer.from([constants_1.INSTRUCTION.CLOSE_POSITION_TOKEN_ACCOUNTS]),
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
/**
|
|
1462
|
+
* Build CloseOrderbookAlt instruction
|
|
1463
|
+
*
|
|
1464
|
+
* Accounts:
|
|
1465
|
+
* 0. operator (signer, mut)
|
|
1466
|
+
* 1. exchange (readonly)
|
|
1467
|
+
* 2. orderbook (readonly)
|
|
1468
|
+
* 3. market (readonly)
|
|
1469
|
+
* 4. lookup_table (mut)
|
|
1470
|
+
* 5. alt_program (readonly)
|
|
1471
|
+
*
|
|
1472
|
+
* Data: [discriminator]
|
|
1473
|
+
*/
|
|
1474
|
+
function buildCloseOrderbookAltIx(params, programId = env_1.PROGRAM_ID) {
|
|
1475
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1476
|
+
const keys = [
|
|
1477
|
+
signerMut(params.operator),
|
|
1478
|
+
readonly(exchange),
|
|
1479
|
+
readonly(params.orderbook),
|
|
1480
|
+
readonly(params.market),
|
|
1481
|
+
writable(params.lookupTable),
|
|
1482
|
+
readonly(constants_1.ALT_PROGRAM_ID),
|
|
1483
|
+
];
|
|
1484
|
+
return new web3_js_1.TransactionInstruction({
|
|
1485
|
+
keys,
|
|
1486
|
+
programId,
|
|
1487
|
+
data: Buffer.from([constants_1.INSTRUCTION.CLOSE_ORDERBOOK_ALT]),
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Build CloseOrderbook instruction
|
|
1492
|
+
*
|
|
1493
|
+
* Accounts:
|
|
1494
|
+
* 0. operator (signer, mut)
|
|
1495
|
+
* 1. exchange (readonly)
|
|
1496
|
+
* 2. orderbook (mut)
|
|
1497
|
+
* 3. market (readonly)
|
|
1498
|
+
* 4. lookup_table (readonly)
|
|
1499
|
+
*
|
|
1500
|
+
* Data: [discriminator]
|
|
1501
|
+
*/
|
|
1502
|
+
function buildCloseOrderbookIx(params, programId = env_1.PROGRAM_ID) {
|
|
1503
|
+
const [exchange] = (0, pda_1.getExchangePda)(programId);
|
|
1504
|
+
const keys = [
|
|
1505
|
+
signerMut(params.operator),
|
|
1506
|
+
readonly(exchange),
|
|
1507
|
+
writable(params.orderbook),
|
|
1508
|
+
readonly(params.market),
|
|
1509
|
+
readonly(params.lookupTable),
|
|
1510
|
+
];
|
|
1511
|
+
return new web3_js_1.TransactionInstruction({
|
|
1512
|
+
keys,
|
|
1513
|
+
programId,
|
|
1514
|
+
data: Buffer.from([constants_1.INSTRUCTION.CLOSE_ORDERBOOK]),
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1128
1517
|
// ============================================================================
|
|
1129
1518
|
// TRANSACTION BUILDERS (_tx convenience wrappers)
|
|
1130
1519
|
// Each wraps the corresponding _ix builder into a Transaction with feePayer set.
|
|
@@ -1135,11 +1524,11 @@ function buildInitializeTx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1135
1524
|
}
|
|
1136
1525
|
function buildCreateMarketTx(params, marketId, programId = env_1.PROGRAM_ID) {
|
|
1137
1526
|
const ix = buildCreateMarketIx(params, marketId, programId);
|
|
1138
|
-
return new web3_js_1.Transaction({ feePayer: params.
|
|
1527
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1139
1528
|
}
|
|
1140
1529
|
function buildAddDepositMintTx(params, market, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1141
1530
|
const ix = buildAddDepositMintIx(params, market, numOutcomes, programId);
|
|
1142
|
-
return new web3_js_1.Transaction({ feePayer: params.
|
|
1531
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1143
1532
|
}
|
|
1144
1533
|
function buildDepositTx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1145
1534
|
const ix = buildDepositIx(params, numOutcomes, programId);
|
|
@@ -1149,9 +1538,9 @@ function buildMergeTx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
|
1149
1538
|
const ix = buildMergeIx(params, numOutcomes, programId);
|
|
1150
1539
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1151
1540
|
}
|
|
1152
|
-
function buildCancelOrderTx(
|
|
1153
|
-
const ix = buildCancelOrderIx(
|
|
1154
|
-
return new web3_js_1.Transaction({ feePayer:
|
|
1541
|
+
function buildCancelOrderTx(operator, market, order, programId = env_1.PROGRAM_ID) {
|
|
1542
|
+
const ix = buildCancelOrderIx(operator, market, order, programId);
|
|
1543
|
+
return new web3_js_1.Transaction({ feePayer: operator }).add(ix);
|
|
1155
1544
|
}
|
|
1156
1545
|
function buildIncrementNonceTx(user, programId = env_1.PROGRAM_ID) {
|
|
1157
1546
|
const ix = buildIncrementNonceIx(user, programId);
|
|
@@ -1161,8 +1550,8 @@ function buildSettleMarketTx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1161
1550
|
const ix = buildSettleMarketIx(params, programId);
|
|
1162
1551
|
return new web3_js_1.Transaction({ feePayer: params.oracle }).add(ix);
|
|
1163
1552
|
}
|
|
1164
|
-
function buildRedeemWinningsTx(params,
|
|
1165
|
-
const ix = buildRedeemWinningsIx(params,
|
|
1553
|
+
function buildRedeemWinningsTx(params, outcomeIndex, programId = env_1.PROGRAM_ID) {
|
|
1554
|
+
const ix = buildRedeemWinningsIx(params, outcomeIndex, programId);
|
|
1166
1555
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1167
1556
|
}
|
|
1168
1557
|
function buildSetPausedTx(authority, paused, programId = env_1.PROGRAM_ID) {
|
|
@@ -1173,13 +1562,13 @@ function buildSetOperatorTx(authority, newOperator, programId = env_1.PROGRAM_ID
|
|
|
1173
1562
|
const ix = buildSetOperatorIx(authority, newOperator, programId);
|
|
1174
1563
|
return new web3_js_1.Transaction({ feePayer: authority }).add(ix);
|
|
1175
1564
|
}
|
|
1176
|
-
function buildWithdrawFromPositionTx(params,
|
|
1177
|
-
const ix = buildWithdrawFromPositionIx(params,
|
|
1565
|
+
function buildWithdrawFromPositionTx(params, programId = env_1.PROGRAM_ID) {
|
|
1566
|
+
const ix = buildWithdrawFromPositionIx(params, programId);
|
|
1178
1567
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1179
1568
|
}
|
|
1180
1569
|
function buildActivateMarketTx(params, programId = env_1.PROGRAM_ID) {
|
|
1181
1570
|
const ix = buildActivateMarketIx(params, programId);
|
|
1182
|
-
return new web3_js_1.Transaction({ feePayer: params.
|
|
1571
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1183
1572
|
}
|
|
1184
1573
|
function buildMatchOrdersMultiTx(params, programId = env_1.PROGRAM_ID) {
|
|
1185
1574
|
const ix = buildMatchOrdersMultiIx(params, programId);
|
|
@@ -1189,9 +1578,29 @@ function buildSetAuthorityTx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1189
1578
|
const ix = buildSetAuthorityIx(params, programId);
|
|
1190
1579
|
return new web3_js_1.Transaction({ feePayer: params.currentAuthority }).add(ix);
|
|
1191
1580
|
}
|
|
1581
|
+
function buildSetManagerTx(params, programId = env_1.PROGRAM_ID) {
|
|
1582
|
+
const ix = buildSetManagerIx(params, programId);
|
|
1583
|
+
return new web3_js_1.Transaction({ feePayer: params.authority }).add(ix);
|
|
1584
|
+
}
|
|
1585
|
+
function buildSetMarketFeesTx(params, programId = env_1.PROGRAM_ID) {
|
|
1586
|
+
const ix = buildSetMarketFeesIx(params, programId);
|
|
1587
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1588
|
+
}
|
|
1589
|
+
function buildSetFeeReceiverTx(params, programId = env_1.PROGRAM_ID) {
|
|
1590
|
+
const ix = buildSetFeeReceiverIx(params, programId);
|
|
1591
|
+
return new web3_js_1.Transaction({ feePayer: params.authority }).add(ix);
|
|
1592
|
+
}
|
|
1593
|
+
function buildCreateConditionalMetadataTx(params, programId = env_1.PROGRAM_ID) {
|
|
1594
|
+
const ix = buildCreateConditionalMetadataIx(params, programId);
|
|
1595
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1596
|
+
}
|
|
1597
|
+
function buildUpdateConditionalMetadataTx(params, programId = env_1.PROGRAM_ID) {
|
|
1598
|
+
const ix = buildUpdateConditionalMetadataIx(params, programId);
|
|
1599
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1600
|
+
}
|
|
1192
1601
|
function buildCreateOrderbookTx(params, programId = env_1.PROGRAM_ID) {
|
|
1193
1602
|
const ix = buildCreateOrderbookIx(params, programId);
|
|
1194
|
-
return new web3_js_1.Transaction({ feePayer: params.
|
|
1603
|
+
return new web3_js_1.Transaction({ feePayer: params.manager }).add(ix);
|
|
1195
1604
|
}
|
|
1196
1605
|
function buildWhitelistDepositTokenTx(params, programId = env_1.PROGRAM_ID) {
|
|
1197
1606
|
const ix = buildWhitelistDepositTokenIx(params, programId);
|
|
@@ -1201,6 +1610,10 @@ function buildDepositToGlobalTx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1201
1610
|
const ix = buildDepositToGlobalIx(params, programId);
|
|
1202
1611
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1203
1612
|
}
|
|
1613
|
+
function buildDepositToGlobalTxWithAlt(params, altContext, programId = env_1.PROGRAM_ID) {
|
|
1614
|
+
const ix = buildDepositToGlobalIxWithAlt(params, altContext, programId);
|
|
1615
|
+
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1616
|
+
}
|
|
1204
1617
|
function buildGlobalToMarketDepositTx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1205
1618
|
const ix = buildGlobalToMarketDepositIx(params, numOutcomes, programId);
|
|
1206
1619
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
@@ -1211,7 +1624,7 @@ function buildInitPositionTokensTx(params, numOutcomes, programId = env_1.PROGRA
|
|
|
1211
1624
|
}
|
|
1212
1625
|
function buildExtendPositionTokensTx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1213
1626
|
const ix = buildExtendPositionTokensIx(params, numOutcomes, programId);
|
|
1214
|
-
return new web3_js_1.Transaction({ feePayer: params.
|
|
1627
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1215
1628
|
}
|
|
1216
1629
|
function buildDepositAndSwapTx(params, programId = env_1.PROGRAM_ID) {
|
|
1217
1630
|
const ix = buildDepositAndSwapIx(params, programId);
|
|
@@ -1221,4 +1634,24 @@ function buildWithdrawFromGlobalTx(params, programId = env_1.PROGRAM_ID) {
|
|
|
1221
1634
|
const ix = buildWithdrawFromGlobalIx(params, programId);
|
|
1222
1635
|
return new web3_js_1.Transaction({ feePayer: params.user }).add(ix);
|
|
1223
1636
|
}
|
|
1637
|
+
function buildClosePositionAltTx(params, programId = env_1.PROGRAM_ID) {
|
|
1638
|
+
const ix = buildClosePositionAltIx(params, programId);
|
|
1639
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1640
|
+
}
|
|
1641
|
+
function buildCloseOrderStatusTx(params, programId = env_1.PROGRAM_ID) {
|
|
1642
|
+
const ix = buildCloseOrderStatusIx(params, programId);
|
|
1643
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1644
|
+
}
|
|
1645
|
+
function buildClosePositionTokenAccountsTx(params, numOutcomes, programId = env_1.PROGRAM_ID) {
|
|
1646
|
+
const ix = buildClosePositionTokenAccountsIx(params, numOutcomes, programId);
|
|
1647
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1648
|
+
}
|
|
1649
|
+
function buildCloseOrderbookAltTx(params, programId = env_1.PROGRAM_ID) {
|
|
1650
|
+
const ix = buildCloseOrderbookAltIx(params, programId);
|
|
1651
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1652
|
+
}
|
|
1653
|
+
function buildCloseOrderbookTx(params, programId = env_1.PROGRAM_ID) {
|
|
1654
|
+
const ix = buildCloseOrderbookIx(params, programId);
|
|
1655
|
+
return new web3_js_1.Transaction({ feePayer: params.operator }).add(ix);
|
|
1656
|
+
}
|
|
1224
1657
|
//# sourceMappingURL=instructions.js.map
|