@cowprotocol/sdk-trading-solana 0.3.0 → 0.4.0
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.mts +36 -7
- package/dist/index.d.ts +36 -7
- package/dist/index.js +56 -24
- package/dist/index.mjs +53 -21
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -104,18 +104,47 @@ type SolanaSignAndSend = (instruction: TransactionInstruction) => Promise<{
|
|
|
104
104
|
signature: string;
|
|
105
105
|
}>;
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* Version-embedded seed shared by every settlement-program PDA (`SETTLEMENT_SEED` in
|
|
109
|
-
* cow-settlement-interface). Must be regenerated if `SOLANA_SETTLEMENT_PROGRAM_VERSION` changes.
|
|
110
|
-
*/
|
|
111
|
-
declare const SETTLEMENT_SEED: Uint8Array<ArrayBufferLike>;
|
|
112
107
|
/** Trailing seed identifying order PDAs (`ORDER_SEED` in cow-settlement-interface). */
|
|
113
108
|
declare const ORDER_SEED: Uint8Array<ArrayBufferLike>;
|
|
114
109
|
/**
|
|
115
110
|
* Derives the canonical order PDA and bump for an order's `uid`, matching `find_order_pda` in
|
|
116
111
|
* cow-settlement-interface.
|
|
112
|
+
*
|
|
113
|
+
* `env` selects the seed version and must describe the same deployment as `programId` — obtain the latter
|
|
114
|
+
* from `getSolanaSettlementProgramId(env)` rather than pairing them by hand.
|
|
115
|
+
*/
|
|
116
|
+
declare function findOrderPda(programId: PublicKey, uid: Uint8Array, env?: CowEnv): [PublicKey, number];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Version-embedded seed shared by every settlement-program PDA of `env` (`SETTLEMENT_SEED` in
|
|
120
|
+
* cow-settlement-interface). Keyed by env because the version is a property of a deployment: each env's seed
|
|
121
|
+
* has to be derived from the version of the program id that env resolves to.
|
|
122
|
+
*
|
|
123
|
+
* Returns a copy: the cached seeds are mutable `Uint8Array`s, and a caller writing into one would silently
|
|
124
|
+
* corrupt every later derivation for that env.
|
|
125
|
+
*/
|
|
126
|
+
declare function getSettlementSeed(env?: CowEnv): Uint8Array;
|
|
127
|
+
|
|
128
|
+
/** Settlement program id deployed for `env`. */
|
|
129
|
+
declare function getSolanaSettlementProgramId(env?: CowEnv): PublicKey;
|
|
130
|
+
/**
|
|
131
|
+
* Derives the canonical settlement state PDA and bump, matching `find_state_pda` in
|
|
132
|
+
* cow-settlement-interface. The env's settlement seed is its only seed, so the address moves with every
|
|
133
|
+
* major/minor bump of the settlement program.
|
|
134
|
+
*
|
|
135
|
+
* `env` selects the seed version and must describe the same deployment as `programId`. Prefer
|
|
136
|
+
* `getSolanaDelegateAuthority`, which derives both from one env and so cannot mismatch.
|
|
137
|
+
*/
|
|
138
|
+
declare function findSettlementStatePda(programId: PublicKey, env?: CowEnv): [PublicKey, number];
|
|
139
|
+
/**
|
|
140
|
+
* The SPL delegate a sell-token account has to approve before the settlement program can move its
|
|
141
|
+
* funds — the Solana analogue of the EVM vault relayer spender.
|
|
142
|
+
*
|
|
143
|
+
* This is the settlement state PDA, not the program id: the program signs its token CPIs as that PDA,
|
|
144
|
+
* so approving anything else yields a delegate that cannot move the funds. Because the PDA seed carries
|
|
145
|
+
* the program's major/minor version, every delegation has to be renewed after a version bump.
|
|
117
146
|
*/
|
|
118
|
-
declare function
|
|
147
|
+
declare function getSolanaDelegateAuthority(env?: CowEnv): PublicKey;
|
|
119
148
|
|
|
120
149
|
interface CreateOrderInstructionParams {
|
|
121
150
|
programId: PublicKey;
|
|
@@ -169,4 +198,4 @@ declare class SolanaTradingSdk {
|
|
|
169
198
|
getQuote(params: SolanaQuoteParameters): Promise<QuoteAndPost>;
|
|
170
199
|
}
|
|
171
200
|
|
|
172
|
-
export { type CreateOrderInstructionParams, ENCODED_ORDER_INTENT_SIZE, JupiterAPI, type JupiterOrderRequest, type JupiterOrderResponse, ORDER_SEED,
|
|
201
|
+
export { type CreateOrderInstructionParams, ENCODED_ORDER_INTENT_SIZE, JupiterAPI, type JupiterOrderRequest, type JupiterOrderResponse, ORDER_SEED, type SolanaOrderIntent, type SolanaQuote, type SolanaQuoteParameters, type SolanaSignAndSend, SolanaTradingSdk, type SolanaTradingSdkOptions, buildCreateOrderInstruction, encodeOrderIntent, findOrderPda, findSettlementStatePda, getSettlementSeed, getSolanaDelegateAuthority, getSolanaQuote, getSolanaSettlementProgramId, hashOrderIntent, postSolanaSwapOrderFromQuote, toHex };
|
package/dist/index.d.ts
CHANGED
|
@@ -104,18 +104,47 @@ type SolanaSignAndSend = (instruction: TransactionInstruction) => Promise<{
|
|
|
104
104
|
signature: string;
|
|
105
105
|
}>;
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* Version-embedded seed shared by every settlement-program PDA (`SETTLEMENT_SEED` in
|
|
109
|
-
* cow-settlement-interface). Must be regenerated if `SOLANA_SETTLEMENT_PROGRAM_VERSION` changes.
|
|
110
|
-
*/
|
|
111
|
-
declare const SETTLEMENT_SEED: Uint8Array<ArrayBufferLike>;
|
|
112
107
|
/** Trailing seed identifying order PDAs (`ORDER_SEED` in cow-settlement-interface). */
|
|
113
108
|
declare const ORDER_SEED: Uint8Array<ArrayBufferLike>;
|
|
114
109
|
/**
|
|
115
110
|
* Derives the canonical order PDA and bump for an order's `uid`, matching `find_order_pda` in
|
|
116
111
|
* cow-settlement-interface.
|
|
112
|
+
*
|
|
113
|
+
* `env` selects the seed version and must describe the same deployment as `programId` — obtain the latter
|
|
114
|
+
* from `getSolanaSettlementProgramId(env)` rather than pairing them by hand.
|
|
115
|
+
*/
|
|
116
|
+
declare function findOrderPda(programId: PublicKey, uid: Uint8Array, env?: CowEnv): [PublicKey, number];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Version-embedded seed shared by every settlement-program PDA of `env` (`SETTLEMENT_SEED` in
|
|
120
|
+
* cow-settlement-interface). Keyed by env because the version is a property of a deployment: each env's seed
|
|
121
|
+
* has to be derived from the version of the program id that env resolves to.
|
|
122
|
+
*
|
|
123
|
+
* Returns a copy: the cached seeds are mutable `Uint8Array`s, and a caller writing into one would silently
|
|
124
|
+
* corrupt every later derivation for that env.
|
|
125
|
+
*/
|
|
126
|
+
declare function getSettlementSeed(env?: CowEnv): Uint8Array;
|
|
127
|
+
|
|
128
|
+
/** Settlement program id deployed for `env`. */
|
|
129
|
+
declare function getSolanaSettlementProgramId(env?: CowEnv): PublicKey;
|
|
130
|
+
/**
|
|
131
|
+
* Derives the canonical settlement state PDA and bump, matching `find_state_pda` in
|
|
132
|
+
* cow-settlement-interface. The env's settlement seed is its only seed, so the address moves with every
|
|
133
|
+
* major/minor bump of the settlement program.
|
|
134
|
+
*
|
|
135
|
+
* `env` selects the seed version and must describe the same deployment as `programId`. Prefer
|
|
136
|
+
* `getSolanaDelegateAuthority`, which derives both from one env and so cannot mismatch.
|
|
137
|
+
*/
|
|
138
|
+
declare function findSettlementStatePda(programId: PublicKey, env?: CowEnv): [PublicKey, number];
|
|
139
|
+
/**
|
|
140
|
+
* The SPL delegate a sell-token account has to approve before the settlement program can move its
|
|
141
|
+
* funds — the Solana analogue of the EVM vault relayer spender.
|
|
142
|
+
*
|
|
143
|
+
* This is the settlement state PDA, not the program id: the program signs its token CPIs as that PDA,
|
|
144
|
+
* so approving anything else yields a delegate that cannot move the funds. Because the PDA seed carries
|
|
145
|
+
* the program's major/minor version, every delegation has to be renewed after a version bump.
|
|
117
146
|
*/
|
|
118
|
-
declare function
|
|
147
|
+
declare function getSolanaDelegateAuthority(env?: CowEnv): PublicKey;
|
|
119
148
|
|
|
120
149
|
interface CreateOrderInstructionParams {
|
|
121
150
|
programId: PublicKey;
|
|
@@ -169,4 +198,4 @@ declare class SolanaTradingSdk {
|
|
|
169
198
|
getQuote(params: SolanaQuoteParameters): Promise<QuoteAndPost>;
|
|
170
199
|
}
|
|
171
200
|
|
|
172
|
-
export { type CreateOrderInstructionParams, ENCODED_ORDER_INTENT_SIZE, JupiterAPI, type JupiterOrderRequest, type JupiterOrderResponse, ORDER_SEED,
|
|
201
|
+
export { type CreateOrderInstructionParams, ENCODED_ORDER_INTENT_SIZE, JupiterAPI, type JupiterOrderRequest, type JupiterOrderResponse, ORDER_SEED, type SolanaOrderIntent, type SolanaQuote, type SolanaQuoteParameters, type SolanaSignAndSend, SolanaTradingSdk, type SolanaTradingSdkOptions, buildCreateOrderInstruction, encodeOrderIntent, findOrderPda, findSettlementStatePda, getSettlementSeed, getSolanaDelegateAuthority, getSolanaQuote, getSolanaSettlementProgramId, hashOrderIntent, postSolanaSwapOrderFromQuote, toHex };
|
package/dist/index.js
CHANGED
|
@@ -23,12 +23,15 @@ __export(src_exports, {
|
|
|
23
23
|
ENCODED_ORDER_INTENT_SIZE: () => ENCODED_ORDER_INTENT_SIZE,
|
|
24
24
|
JupiterAPI: () => JupiterAPI,
|
|
25
25
|
ORDER_SEED: () => ORDER_SEED,
|
|
26
|
-
SETTLEMENT_SEED: () => SETTLEMENT_SEED,
|
|
27
26
|
SolanaTradingSdk: () => SolanaTradingSdk,
|
|
28
27
|
buildCreateOrderInstruction: () => buildCreateOrderInstruction,
|
|
29
28
|
encodeOrderIntent: () => encodeOrderIntent,
|
|
30
29
|
findOrderPda: () => findOrderPda,
|
|
30
|
+
findSettlementStatePda: () => findSettlementStatePda,
|
|
31
|
+
getSettlementSeed: () => getSettlementSeed,
|
|
32
|
+
getSolanaDelegateAuthority: () => getSolanaDelegateAuthority,
|
|
31
33
|
getSolanaQuote: () => getSolanaQuote,
|
|
34
|
+
getSolanaSettlementProgramId: () => getSolanaSettlementProgramId,
|
|
32
35
|
hashOrderIntent: () => hashOrderIntent,
|
|
33
36
|
postSolanaSwapOrderFromQuote: () => postSolanaSwapOrderFromQuote,
|
|
34
37
|
toHex: () => toHex
|
|
@@ -91,32 +94,61 @@ function toHex(bytes) {
|
|
|
91
94
|
|
|
92
95
|
// src/orderPda.ts
|
|
93
96
|
var import_web3 = require("@solana/web3.js");
|
|
97
|
+
|
|
98
|
+
// src/settlementSeed.ts
|
|
94
99
|
var import_sdk_config = require("@cowprotocol/sdk-config");
|
|
95
100
|
var SETTLEMENT_SEED_PREFIX = "settlement v";
|
|
96
101
|
var SETTLEMENT_SEED_VERSION_LEN = 7;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
function buildSettlementSeed(version) {
|
|
103
|
+
if (version.length > SETTLEMENT_SEED_VERSION_LEN) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Settlement program version "${version}" exceeds the ${SETTLEMENT_SEED_VERSION_LEN}-byte seed field`
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return new TextEncoder().encode(SETTLEMENT_SEED_PREFIX + version.padEnd(SETTLEMENT_SEED_VERSION_LEN, " "));
|
|
109
|
+
}
|
|
110
|
+
var SETTLEMENT_SEEDS = {
|
|
111
|
+
prod: buildSettlementSeed(import_sdk_config.SOLANA_SETTLEMENT_PROGRAM_VERSION),
|
|
112
|
+
staging: buildSettlementSeed(import_sdk_config.SOLANA_SETTLEMENT_PROGRAM_VERSION_STAGING)
|
|
113
|
+
};
|
|
114
|
+
function getSettlementSeed(env = "prod") {
|
|
115
|
+
return SETTLEMENT_SEEDS[env].slice();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/orderPda.ts
|
|
100
119
|
var ORDER_SEED = new TextEncoder().encode("order");
|
|
101
|
-
function findOrderPda(programId, uid) {
|
|
102
|
-
return import_web3.PublicKey.findProgramAddressSync([
|
|
120
|
+
function findOrderPda(programId, uid, env) {
|
|
121
|
+
return import_web3.PublicKey.findProgramAddressSync([getSettlementSeed(env), uid, ORDER_SEED], programId);
|
|
103
122
|
}
|
|
104
123
|
|
|
105
|
-
// src/
|
|
124
|
+
// src/statePda.ts
|
|
106
125
|
var import_web32 = require("@solana/web3.js");
|
|
126
|
+
var import_sdk_config2 = require("@cowprotocol/sdk-config");
|
|
127
|
+
function getSolanaSettlementProgramId(env) {
|
|
128
|
+
return new import_web32.PublicKey(env === "staging" ? import_sdk_config2.SOLANA_SETTLEMENT_PROGRAM_ID_STAGING : import_sdk_config2.SOLANA_SETTLEMENT_PROGRAM_ID);
|
|
129
|
+
}
|
|
130
|
+
function findSettlementStatePda(programId, env) {
|
|
131
|
+
return import_web32.PublicKey.findProgramAddressSync([getSettlementSeed(env)], programId);
|
|
132
|
+
}
|
|
133
|
+
function getSolanaDelegateAuthority(env) {
|
|
134
|
+
return findSettlementStatePda(getSolanaSettlementProgramId(env), env)[0];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/createOrderInstruction.ts
|
|
138
|
+
var import_web33 = require("@solana/web3.js");
|
|
107
139
|
var CREATE_ORDER_DISCRIMINATOR = 2;
|
|
108
140
|
function buildCreateOrderInstruction(params) {
|
|
109
141
|
const intentBytes = encodeOrderIntent(params.intent);
|
|
110
142
|
const data = Buffer.alloc(1 + intentBytes.length);
|
|
111
143
|
data[0] = CREATE_ORDER_DISCRIMINATOR;
|
|
112
144
|
data.set(intentBytes, 1);
|
|
113
|
-
return new
|
|
145
|
+
return new import_web33.TransactionInstruction({
|
|
114
146
|
programId: params.programId,
|
|
115
147
|
keys: [
|
|
116
148
|
{ pubkey: params.owner, isSigner: true, isWritable: false },
|
|
117
149
|
{ pubkey: params.createdBy, isSigner: true, isWritable: true },
|
|
118
150
|
{ pubkey: params.orderPda, isSigner: false, isWritable: true },
|
|
119
|
-
{ pubkey:
|
|
151
|
+
{ pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false }
|
|
120
152
|
],
|
|
121
153
|
data
|
|
122
154
|
});
|
|
@@ -170,9 +202,8 @@ function isJupiterOrderResponse(body, request) {
|
|
|
170
202
|
}
|
|
171
203
|
|
|
172
204
|
// src/getSolanaQuote.ts
|
|
173
|
-
var
|
|
205
|
+
var import_web34 = require("@solana/web3.js");
|
|
174
206
|
var import_spl_token = require("@solana/spl-token");
|
|
175
|
-
var import_sdk_config2 = require("@cowprotocol/sdk-config");
|
|
176
207
|
var import_sdk_order_book2 = require("@cowprotocol/sdk-order-book");
|
|
177
208
|
var DEFAULT_VALID_FOR_SECONDS = 30 * 60;
|
|
178
209
|
var ZERO_APP_DATA = new Uint8Array(32);
|
|
@@ -193,12 +224,12 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
193
224
|
if (!Number.isFinite(validForSeconds) || validForSeconds <= 0) {
|
|
194
225
|
throw new Error("validForSeconds must be a finite number greater than zero");
|
|
195
226
|
}
|
|
196
|
-
const owner = new
|
|
197
|
-
const receiver = new
|
|
198
|
-
const sellMint = new
|
|
199
|
-
const buyMint = new
|
|
200
|
-
const sellTokenProgram = sellTokenProgramId ? new
|
|
201
|
-
const buyTokenProgram = buyTokenProgramId ? new
|
|
227
|
+
const owner = new import_web34.PublicKey(ownerAddress);
|
|
228
|
+
const receiver = new import_web34.PublicKey(receiverAddress);
|
|
229
|
+
const sellMint = new import_web34.PublicKey(params.sellTokenAddress);
|
|
230
|
+
const buyMint = new import_web34.PublicKey(params.buyTokenAddress);
|
|
231
|
+
const sellTokenProgram = sellTokenProgramId ? new import_web34.PublicKey(sellTokenProgramId) : void 0;
|
|
232
|
+
const buyTokenProgram = buyTokenProgramId ? new import_web34.PublicKey(buyTokenProgramId) : void 0;
|
|
202
233
|
const sellTokenAddress = sellMint.toBase58();
|
|
203
234
|
const buyTokenAddress = buyMint.toBase58();
|
|
204
235
|
const jupiterOrder = await jupiterApi.getOrder({
|
|
@@ -248,10 +279,8 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
248
279
|
};
|
|
249
280
|
const intentBytes = encodeOrderIntent(intent);
|
|
250
281
|
const uid = await hashOrderIntent(intentBytes);
|
|
251
|
-
const programId =
|
|
252
|
-
|
|
253
|
-
);
|
|
254
|
-
const [orderPda] = findOrderPda(programId, uid);
|
|
282
|
+
const programId = getSolanaSettlementProgramId(options.env);
|
|
283
|
+
const [orderPda] = findOrderPda(programId, uid, options.env);
|
|
255
284
|
const solanaQuote = {
|
|
256
285
|
intent,
|
|
257
286
|
intentBytes,
|
|
@@ -294,7 +323,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
294
323
|
// src/postSwapOrderFromQuote.ts
|
|
295
324
|
var import_spl_token2 = require("@solana/spl-token");
|
|
296
325
|
var import_sdk_order_book3 = require("@cowprotocol/sdk-order-book");
|
|
297
|
-
var
|
|
326
|
+
var import_web35 = require("@solana/web3.js");
|
|
298
327
|
async function postSolanaSwapOrderFromQuote({ quoteResults, solanaQuote }, signAndSend, advancedSettings, signingStepManager) {
|
|
299
328
|
const intent = { ...solanaQuote.intent };
|
|
300
329
|
let uid = solanaQuote.uid;
|
|
@@ -304,7 +333,7 @@ async function postSolanaSwapOrderFromQuote({ quoteResults, solanaQuote }, signA
|
|
|
304
333
|
if (receiver) {
|
|
305
334
|
intent.buyTokenAccount = (0, import_spl_token2.getAssociatedTokenAddressSync)(
|
|
306
335
|
intent.buyMint,
|
|
307
|
-
new
|
|
336
|
+
new import_web35.PublicKey(receiver),
|
|
308
337
|
false,
|
|
309
338
|
solanaQuote.buyTokenProgramId
|
|
310
339
|
);
|
|
@@ -355,12 +384,15 @@ var SolanaTradingSdk = class {
|
|
|
355
384
|
ENCODED_ORDER_INTENT_SIZE,
|
|
356
385
|
JupiterAPI,
|
|
357
386
|
ORDER_SEED,
|
|
358
|
-
SETTLEMENT_SEED,
|
|
359
387
|
SolanaTradingSdk,
|
|
360
388
|
buildCreateOrderInstruction,
|
|
361
389
|
encodeOrderIntent,
|
|
362
390
|
findOrderPda,
|
|
391
|
+
findSettlementStatePda,
|
|
392
|
+
getSettlementSeed,
|
|
393
|
+
getSolanaDelegateAuthority,
|
|
363
394
|
getSolanaQuote,
|
|
395
|
+
getSolanaSettlementProgramId,
|
|
364
396
|
hashOrderIntent,
|
|
365
397
|
postSolanaSwapOrderFromQuote,
|
|
366
398
|
toHex
|
package/dist/index.mjs
CHANGED
|
@@ -54,15 +54,47 @@ function toHex(bytes) {
|
|
|
54
54
|
|
|
55
55
|
// src/orderPda.ts
|
|
56
56
|
import { PublicKey } from "@solana/web3.js";
|
|
57
|
-
|
|
57
|
+
|
|
58
|
+
// src/settlementSeed.ts
|
|
59
|
+
import {
|
|
60
|
+
SOLANA_SETTLEMENT_PROGRAM_VERSION,
|
|
61
|
+
SOLANA_SETTLEMENT_PROGRAM_VERSION_STAGING
|
|
62
|
+
} from "@cowprotocol/sdk-config";
|
|
58
63
|
var SETTLEMENT_SEED_PREFIX = "settlement v";
|
|
59
64
|
var SETTLEMENT_SEED_VERSION_LEN = 7;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
function buildSettlementSeed(version) {
|
|
66
|
+
if (version.length > SETTLEMENT_SEED_VERSION_LEN) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
`Settlement program version "${version}" exceeds the ${SETTLEMENT_SEED_VERSION_LEN}-byte seed field`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return new TextEncoder().encode(SETTLEMENT_SEED_PREFIX + version.padEnd(SETTLEMENT_SEED_VERSION_LEN, " "));
|
|
72
|
+
}
|
|
73
|
+
var SETTLEMENT_SEEDS = {
|
|
74
|
+
prod: buildSettlementSeed(SOLANA_SETTLEMENT_PROGRAM_VERSION),
|
|
75
|
+
staging: buildSettlementSeed(SOLANA_SETTLEMENT_PROGRAM_VERSION_STAGING)
|
|
76
|
+
};
|
|
77
|
+
function getSettlementSeed(env = "prod") {
|
|
78
|
+
return SETTLEMENT_SEEDS[env].slice();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/orderPda.ts
|
|
63
82
|
var ORDER_SEED = new TextEncoder().encode("order");
|
|
64
|
-
function findOrderPda(programId, uid) {
|
|
65
|
-
return PublicKey.findProgramAddressSync([
|
|
83
|
+
function findOrderPda(programId, uid, env) {
|
|
84
|
+
return PublicKey.findProgramAddressSync([getSettlementSeed(env), uid, ORDER_SEED], programId);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/statePda.ts
|
|
88
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
89
|
+
import { SOLANA_SETTLEMENT_PROGRAM_ID, SOLANA_SETTLEMENT_PROGRAM_ID_STAGING } from "@cowprotocol/sdk-config";
|
|
90
|
+
function getSolanaSettlementProgramId(env) {
|
|
91
|
+
return new PublicKey2(env === "staging" ? SOLANA_SETTLEMENT_PROGRAM_ID_STAGING : SOLANA_SETTLEMENT_PROGRAM_ID);
|
|
92
|
+
}
|
|
93
|
+
function findSettlementStatePda(programId, env) {
|
|
94
|
+
return PublicKey2.findProgramAddressSync([getSettlementSeed(env)], programId);
|
|
95
|
+
}
|
|
96
|
+
function getSolanaDelegateAuthority(env) {
|
|
97
|
+
return findSettlementStatePda(getSolanaSettlementProgramId(env), env)[0];
|
|
66
98
|
}
|
|
67
99
|
|
|
68
100
|
// src/createOrderInstruction.ts
|
|
@@ -133,9 +165,8 @@ function isJupiterOrderResponse(body, request) {
|
|
|
133
165
|
}
|
|
134
166
|
|
|
135
167
|
// src/getSolanaQuote.ts
|
|
136
|
-
import { PublicKey as
|
|
168
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
137
169
|
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
|
138
|
-
import { SOLANA_SETTLEMENT_PROGRAM_ID, SOLANA_SETTLEMENT_PROGRAM_ID_STAGING } from "@cowprotocol/sdk-config";
|
|
139
170
|
import { getQuoteAmountsAndCosts, OrderKind as OrderKind2 } from "@cowprotocol/sdk-order-book";
|
|
140
171
|
var DEFAULT_VALID_FOR_SECONDS = 30 * 60;
|
|
141
172
|
var ZERO_APP_DATA = new Uint8Array(32);
|
|
@@ -156,12 +187,12 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
156
187
|
if (!Number.isFinite(validForSeconds) || validForSeconds <= 0) {
|
|
157
188
|
throw new Error("validForSeconds must be a finite number greater than zero");
|
|
158
189
|
}
|
|
159
|
-
const owner = new
|
|
160
|
-
const receiver = new
|
|
161
|
-
const sellMint = new
|
|
162
|
-
const buyMint = new
|
|
163
|
-
const sellTokenProgram = sellTokenProgramId ? new
|
|
164
|
-
const buyTokenProgram = buyTokenProgramId ? new
|
|
190
|
+
const owner = new PublicKey4(ownerAddress);
|
|
191
|
+
const receiver = new PublicKey4(receiverAddress);
|
|
192
|
+
const sellMint = new PublicKey4(params.sellTokenAddress);
|
|
193
|
+
const buyMint = new PublicKey4(params.buyTokenAddress);
|
|
194
|
+
const sellTokenProgram = sellTokenProgramId ? new PublicKey4(sellTokenProgramId) : void 0;
|
|
195
|
+
const buyTokenProgram = buyTokenProgramId ? new PublicKey4(buyTokenProgramId) : void 0;
|
|
165
196
|
const sellTokenAddress = sellMint.toBase58();
|
|
166
197
|
const buyTokenAddress = buyMint.toBase58();
|
|
167
198
|
const jupiterOrder = await jupiterApi.getOrder({
|
|
@@ -211,10 +242,8 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
211
242
|
};
|
|
212
243
|
const intentBytes = encodeOrderIntent(intent);
|
|
213
244
|
const uid = await hashOrderIntent(intentBytes);
|
|
214
|
-
const programId =
|
|
215
|
-
|
|
216
|
-
);
|
|
217
|
-
const [orderPda] = findOrderPda(programId, uid);
|
|
245
|
+
const programId = getSolanaSettlementProgramId(options.env);
|
|
246
|
+
const [orderPda] = findOrderPda(programId, uid, options.env);
|
|
218
247
|
const solanaQuote = {
|
|
219
248
|
intent,
|
|
220
249
|
intentBytes,
|
|
@@ -257,7 +286,7 @@ async function getSolanaQuote(params, options = {}) {
|
|
|
257
286
|
// src/postSwapOrderFromQuote.ts
|
|
258
287
|
import { getAssociatedTokenAddressSync as getAssociatedTokenAddressSync2 } from "@solana/spl-token";
|
|
259
288
|
import { SigningScheme } from "@cowprotocol/sdk-order-book";
|
|
260
|
-
import { PublicKey as
|
|
289
|
+
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
261
290
|
async function postSolanaSwapOrderFromQuote({ quoteResults, solanaQuote }, signAndSend, advancedSettings, signingStepManager) {
|
|
262
291
|
const intent = { ...solanaQuote.intent };
|
|
263
292
|
let uid = solanaQuote.uid;
|
|
@@ -267,7 +296,7 @@ async function postSolanaSwapOrderFromQuote({ quoteResults, solanaQuote }, signA
|
|
|
267
296
|
if (receiver) {
|
|
268
297
|
intent.buyTokenAccount = getAssociatedTokenAddressSync2(
|
|
269
298
|
intent.buyMint,
|
|
270
|
-
new
|
|
299
|
+
new PublicKey5(receiver),
|
|
271
300
|
false,
|
|
272
301
|
solanaQuote.buyTokenProgramId
|
|
273
302
|
);
|
|
@@ -317,12 +346,15 @@ export {
|
|
|
317
346
|
ENCODED_ORDER_INTENT_SIZE,
|
|
318
347
|
JupiterAPI,
|
|
319
348
|
ORDER_SEED,
|
|
320
|
-
SETTLEMENT_SEED,
|
|
321
349
|
SolanaTradingSdk,
|
|
322
350
|
buildCreateOrderInstruction,
|
|
323
351
|
encodeOrderIntent,
|
|
324
352
|
findOrderPda,
|
|
353
|
+
findSettlementStatePda,
|
|
354
|
+
getSettlementSeed,
|
|
355
|
+
getSolanaDelegateAuthority,
|
|
325
356
|
getSolanaQuote,
|
|
357
|
+
getSolanaSettlementProgramId,
|
|
326
358
|
hashOrderIntent,
|
|
327
359
|
postSolanaSwapOrderFromQuote,
|
|
328
360
|
toHex
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-trading-solana",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "CowProtocol Solana trading: Jupiter-sourced quotes and on-chain CreateOrder posting against the Solana settlement program",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@solana/spl-token": "0.4.14",
|
|
41
41
|
"@solana/web3.js": "1.98.4",
|
|
42
|
-
"@cowprotocol/sdk-config": "2.
|
|
43
|
-
"@cowprotocol/sdk-order-book": "4.0.
|
|
44
|
-
"@cowprotocol/sdk-trading": "2.4.
|
|
42
|
+
"@cowprotocol/sdk-config": "2.6.0",
|
|
43
|
+
"@cowprotocol/sdk-order-book": "4.0.4",
|
|
44
|
+
"@cowprotocol/sdk-trading": "2.4.1"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|