@deserialize/swap-sdk 1.0.0 → 1.0.2
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/swapSDK.d.ts +12 -10
- package/dist/swapSDK.js +19 -45
- package/dist/swapSDK.js.map +1 -1
- package/package.json +1 -1
- package/src/swapSDK.ts +33 -59
package/dist/swapSDK.d.ts
CHANGED
@@ -19,6 +19,16 @@ export interface SwapRequestParams {
|
|
19
19
|
*/
|
20
20
|
options?: RouteOptions;
|
21
21
|
}
|
22
|
+
export interface SwapTransactionResponse {
|
23
|
+
/** Fully constructed VersionedTransaction ready for signing */
|
24
|
+
transaction: VersionedTransaction;
|
25
|
+
/** Raw transaction data in base64 encoding */
|
26
|
+
serializedTransactions: string;
|
27
|
+
/** Associated lookup accounts */
|
28
|
+
lookupAccounts: PublicKey[];
|
29
|
+
/** Required transaction signers */
|
30
|
+
signers: Keypair[];
|
31
|
+
}
|
22
32
|
export interface RouteOptions {
|
23
33
|
reduceToTwoHops: boolean;
|
24
34
|
}
|
@@ -212,10 +222,10 @@ export declare class SwapSDK {
|
|
212
222
|
* @param params Swap parameters including the quote
|
213
223
|
* @returns Transaction and output details
|
214
224
|
*/
|
215
|
-
|
225
|
+
getSwapTransaction(params: {
|
216
226
|
publicKey: PublicKey;
|
217
227
|
quote: QuoteResponse;
|
218
|
-
}): Promise<
|
228
|
+
}): Promise<SwapTransactionResponse>;
|
219
229
|
/**
|
220
230
|
* Calls the swap endpoint and returns a fully constructed Transaction.
|
221
231
|
* This method is a wrapper that gets a quote first, then executes the swap.
|
@@ -224,14 +234,6 @@ export declare class SwapSDK {
|
|
224
234
|
* @returns A promise that resolves to a SwapTxResult.
|
225
235
|
*/
|
226
236
|
swapTx(params: SwapRequestParams): Promise<SwapTxResult>;
|
227
|
-
/**
|
228
|
-
* Calls the swap endpoint and returns the raw instructions and related data.
|
229
|
-
* This method is a wrapper that gets a quote first, then executes the swap to get instructions.
|
230
|
-
*
|
231
|
-
* @param params Swap parameters.
|
232
|
-
* @returns A promise that resolves to a SwapIxResult.
|
233
|
-
*/
|
234
|
-
swapIx(params: SwapRequestParams): Promise<SwapIxResult>;
|
235
237
|
/**
|
236
238
|
* Calls the /tokenList endpoint and returns an array of tokens.
|
237
239
|
*
|
package/dist/swapSDK.js
CHANGED
@@ -145,7 +145,7 @@ class SwapSDK {
|
|
145
145
|
* @param params Swap parameters including the quote
|
146
146
|
* @returns Transaction and output details
|
147
147
|
*/
|
148
|
-
async
|
148
|
+
async getSwapTransaction(params) {
|
149
149
|
const body = {
|
150
150
|
publicKey: params.publicKey.toBase58(),
|
151
151
|
quote: params.quote,
|
@@ -160,85 +160,59 @@ class SwapSDK {
|
|
160
160
|
if (!response.ok) {
|
161
161
|
throw new Error(`API Error: ${response.statusText}`);
|
162
162
|
}
|
163
|
-
|
164
|
-
}
|
165
|
-
/**
|
166
|
-
* Calls the swap endpoint and returns a fully constructed Transaction.
|
167
|
-
* This method is a wrapper that gets a quote first, then executes the swap.
|
168
|
-
*
|
169
|
-
* @param params Swap parameters.
|
170
|
-
* @returns A promise that resolves to a SwapTxResult.
|
171
|
-
*/
|
172
|
-
async swapTx(params) {
|
173
|
-
// First get a quote
|
174
|
-
const quote = await this.getSwapQuote(params);
|
175
|
-
// Then execute the swap with the quote
|
176
|
-
const data = await this.executeSwap({
|
177
|
-
publicKey: params.publicKey,
|
178
|
-
quote,
|
179
|
-
});
|
163
|
+
const data = await response.json();
|
180
164
|
// Convert the base64-encoded transaction into a VersionedTransaction.
|
181
165
|
const txBuffer = Buffer.from(data.transaction, "base64");
|
182
166
|
const transaction = web3_js_1.VersionedTransaction.deserialize(txBuffer);
|
183
167
|
// Convert lookup accounts from strings to PublicKey objects.
|
184
168
|
const lookupAccounts = (data.lookUpAccounts || []).map((addr) => new web3_js_1.PublicKey(addr));
|
185
|
-
// Convert the route plan tokens into PublicKey objects.
|
186
|
-
const routePlan = (quote.routePlan || []).map((rp) => ({
|
187
|
-
tokenA: new web3_js_1.PublicKey(rp.tokenA),
|
188
|
-
tokenB: new web3_js_1.PublicKey(rp.tokenB),
|
189
|
-
dexId: rp.dexId,
|
190
|
-
}));
|
191
169
|
// Convert each base58-encoded signer secret into a Keypair.
|
192
170
|
const signers = data.signers.map((s) => web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(s)));
|
193
171
|
transaction.sign(signers);
|
194
172
|
return {
|
195
173
|
transaction,
|
196
174
|
serializedTransactions: data.transaction,
|
197
|
-
amountOut: Number(data.amountOut),
|
198
|
-
amountOutUi: Number(quote.amountOut),
|
199
|
-
pairPrice: Number(quote.tokenPrice),
|
200
|
-
routePlan,
|
201
175
|
lookupAccounts,
|
202
176
|
signers,
|
203
|
-
feeRate: parseFloat(quote.feeRate),
|
204
177
|
};
|
205
178
|
}
|
206
179
|
/**
|
207
|
-
* Calls the swap endpoint and returns
|
208
|
-
* This method is a wrapper that gets a quote first, then executes the swap
|
180
|
+
* Calls the swap endpoint and returns a fully constructed Transaction.
|
181
|
+
* This method is a wrapper that gets a quote first, then executes the swap.
|
209
182
|
*
|
210
183
|
* @param params Swap parameters.
|
211
|
-
* @returns A promise that resolves to a
|
184
|
+
* @returns A promise that resolves to a SwapTxResult.
|
212
185
|
*/
|
213
|
-
async
|
186
|
+
async swapTx(params) {
|
214
187
|
// First get a quote
|
215
188
|
const quote = await this.getSwapQuote(params);
|
216
189
|
// Then execute the swap with the quote
|
217
|
-
const data = await this.
|
190
|
+
const data = await this.getSwapTransaction({
|
218
191
|
publicKey: params.publicKey,
|
219
192
|
quote,
|
220
193
|
});
|
194
|
+
const transaction = data.transaction;
|
221
195
|
// Convert lookup accounts from strings to PublicKey objects.
|
222
|
-
const lookupAccounts =
|
196
|
+
const lookupAccounts = data.lookupAccounts;
|
223
197
|
// Convert the route plan tokens into PublicKey objects.
|
224
198
|
const routePlan = (quote.routePlan || []).map((rp) => ({
|
225
199
|
tokenA: new web3_js_1.PublicKey(rp.tokenA),
|
226
200
|
tokenB: new web3_js_1.PublicKey(rp.tokenB),
|
227
201
|
dexId: rp.dexId,
|
228
202
|
}));
|
229
|
-
// Convert each
|
230
|
-
const
|
231
|
-
|
232
|
-
cleanupInstructions: (group.cleanupInstructions || []).map((inst) => this.convertAPIInstruction(inst)),
|
233
|
-
signers: group.signers || [],
|
234
|
-
}));
|
203
|
+
// Convert each base58-encoded signer secret into a Keypair.
|
204
|
+
const signers = data.signers;
|
205
|
+
transaction.sign(signers);
|
235
206
|
return {
|
236
|
-
|
237
|
-
|
207
|
+
transaction,
|
208
|
+
serializedTransactions: data.serializedTransactions,
|
209
|
+
amountOut: Number(quote.amountOut),
|
238
210
|
amountOutUi: Number(quote.amountOut),
|
211
|
+
pairPrice: Number(quote.tokenPrice),
|
239
212
|
routePlan,
|
240
213
|
lookupAccounts,
|
241
|
-
signers
|
214
|
+
signers,
|
215
|
+
feeRate: parseFloat(quote.feeRate),
|
242
216
|
};
|
243
217
|
}
|
244
218
|
/**
|
@@ -252,7 +226,7 @@ class SwapSDK {
|
|
252
226
|
throw new Error(`API Error: ${response.statusText}`);
|
253
227
|
}
|
254
228
|
const data = await response.json();
|
255
|
-
return data.map((token) => ({
|
229
|
+
return data.data.map((token) => ({
|
256
230
|
name: token.metadata.name,
|
257
231
|
symbol: token.metadata.symbol,
|
258
232
|
address: token.address,
|
package/dist/swapSDK.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"swapSDK.js","sourceRoot":"","sources":["../src/swapSDK.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,2DASyB;AACzB,gDAA0B;AAC1B,qCAAiD;
|
1
|
+
{"version":3,"file":"swapSDK.js","sourceRoot":"","sources":["../src/swapSDK.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,2DASyB;AACzB,gDAA0B;AAC1B,qCAAiD;AAmJjD;;;;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gBAC5C,MAAM,EAAE,IAAI,mBAAS,CAAC,GAAG,CAAC,MAAM,CAAC;gBACjC,QAAQ,EAAE,GAAG,CAAC,QAAQ;gBACtB,UAAU,EAAE,GAAG,CAAC,UAAU;aAC3B,CAAC,CAAC;YACH,SAAS,EAAE,IAAI,mBAAS,CAAC,OAAO,CAAC,SAAS,CAAC;YAC3C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;SAChC,CAAC,CAAC;IACL,CAAC;CACF;AA9PD,0BA8PC;AAEY,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,WAAW;IACtB,GAAG,EAAE,KAAK;CACF,CAAC;AAIE,QAAA,QAAQ,GAAG,6BAA6B,CAAC"}
|
package/package.json
CHANGED
package/src/swapSDK.ts
CHANGED
@@ -33,6 +33,17 @@ export interface SwapRequestParams {
|
|
33
33
|
options?: RouteOptions;
|
34
34
|
}
|
35
35
|
|
36
|
+
export interface SwapTransactionResponse {
|
37
|
+
/** Fully constructed VersionedTransaction ready for signing */
|
38
|
+
transaction: VersionedTransaction;
|
39
|
+
/** Raw transaction data in base64 encoding */
|
40
|
+
serializedTransactions: string;
|
41
|
+
/** Associated lookup accounts */
|
42
|
+
lookupAccounts: PublicKey[];
|
43
|
+
/** Required transaction signers */
|
44
|
+
signers: Keypair[];
|
45
|
+
}
|
46
|
+
|
36
47
|
export interface RouteOptions {
|
37
48
|
reduceToTwoHops: boolean;
|
38
49
|
}
|
@@ -258,10 +269,10 @@ export class SwapSDK {
|
|
258
269
|
* @param params Swap parameters including the quote
|
259
270
|
* @returns Transaction and output details
|
260
271
|
*/
|
261
|
-
async
|
272
|
+
async getSwapTransaction(params: {
|
262
273
|
publicKey: PublicKey;
|
263
274
|
quote: QuoteResponse;
|
264
|
-
}): Promise<
|
275
|
+
}): Promise<SwapTransactionResponse> {
|
265
276
|
const body = {
|
266
277
|
publicKey: params.publicKey.toBase58(),
|
267
278
|
quote: params.quote,
|
@@ -279,25 +290,7 @@ export class SwapSDK {
|
|
279
290
|
throw new Error(`API Error: ${response.statusText}`);
|
280
291
|
}
|
281
292
|
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
/**
|
286
|
-
* Calls the swap endpoint and returns a fully constructed Transaction.
|
287
|
-
* This method is a wrapper that gets a quote first, then executes the swap.
|
288
|
-
*
|
289
|
-
* @param params Swap parameters.
|
290
|
-
* @returns A promise that resolves to a SwapTxResult.
|
291
|
-
*/
|
292
|
-
async swapTx(params: SwapRequestParams): Promise<SwapTxResult> {
|
293
|
-
// First get a quote
|
294
|
-
const quote = await this.getSwapQuote(params);
|
295
|
-
|
296
|
-
// Then execute the swap with the quote
|
297
|
-
const data = await this.executeSwap({
|
298
|
-
publicKey: params.publicKey,
|
299
|
-
quote,
|
300
|
-
});
|
293
|
+
const data = await response.json();
|
301
294
|
|
302
295
|
// Convert the base64-encoded transaction into a VersionedTransaction.
|
303
296
|
const txBuffer = Buffer.from(data.transaction, "base64");
|
@@ -308,13 +301,6 @@ export class SwapSDK {
|
|
308
301
|
(addr: string) => new PublicKey(addr)
|
309
302
|
);
|
310
303
|
|
311
|
-
// Convert the route plan tokens into PublicKey objects.
|
312
|
-
const routePlan = (quote.routePlan || []).map((rp: any) => ({
|
313
|
-
tokenA: new PublicKey(rp.tokenA),
|
314
|
-
tokenB: new PublicKey(rp.tokenB),
|
315
|
-
dexId: rp.dexId as DexIdTypes,
|
316
|
-
}));
|
317
|
-
|
318
304
|
// Convert each base58-encoded signer secret into a Keypair.
|
319
305
|
const signers = data.signers.map((s: string) =>
|
320
306
|
Keypair.fromSecretKey(base58.decode(s))
|
@@ -325,65 +311,53 @@ export class SwapSDK {
|
|
325
311
|
return {
|
326
312
|
transaction,
|
327
313
|
serializedTransactions: data.transaction,
|
328
|
-
amountOut: Number(data.amountOut),
|
329
|
-
amountOutUi: Number(quote.amountOut),
|
330
|
-
pairPrice: Number(quote.tokenPrice),
|
331
|
-
routePlan,
|
332
314
|
lookupAccounts,
|
333
315
|
signers,
|
334
|
-
feeRate: parseFloat(quote.feeRate),
|
335
316
|
};
|
336
317
|
}
|
337
318
|
|
338
319
|
/**
|
339
|
-
* Calls the swap endpoint and returns
|
340
|
-
* This method is a wrapper that gets a quote first, then executes the swap
|
320
|
+
* Calls the swap endpoint and returns a fully constructed Transaction.
|
321
|
+
* This method is a wrapper that gets a quote first, then executes the swap.
|
341
322
|
*
|
342
323
|
* @param params Swap parameters.
|
343
|
-
* @returns A promise that resolves to a
|
324
|
+
* @returns A promise that resolves to a SwapTxResult.
|
344
325
|
*/
|
345
|
-
async
|
326
|
+
async swapTx(params: SwapRequestParams): Promise<SwapTxResult> {
|
346
327
|
// First get a quote
|
347
328
|
const quote = await this.getSwapQuote(params);
|
348
329
|
|
349
330
|
// Then execute the swap with the quote
|
350
|
-
const data = await this.
|
331
|
+
const data = await this.getSwapTransaction({
|
351
332
|
publicKey: params.publicKey,
|
352
333
|
quote,
|
353
334
|
});
|
354
335
|
|
355
|
-
|
356
|
-
const lookupAccounts: PublicKey[] = (data.lookUpAccounts || []).map(
|
357
|
-
(addr: string) => new PublicKey(addr)
|
358
|
-
);
|
336
|
+
const transaction = data.transaction;
|
359
337
|
|
338
|
+
// Convert lookup accounts from strings to PublicKey objects.
|
339
|
+
const lookupAccounts: PublicKey[] = data.lookupAccounts;
|
360
340
|
// Convert the route plan tokens into PublicKey objects.
|
361
341
|
const routePlan = (quote.routePlan || []).map((rp: any) => ({
|
362
342
|
tokenA: new PublicKey(rp.tokenA),
|
363
343
|
tokenB: new PublicKey(rp.tokenB),
|
364
|
-
dexId: rp.dexId,
|
344
|
+
dexId: rp.dexId as DexIdTypes,
|
365
345
|
}));
|
366
346
|
|
367
|
-
// Convert each
|
368
|
-
const
|
369
|
-
|
370
|
-
instructions: (group.instructions || []).map((inst: any) =>
|
371
|
-
this.convertAPIInstruction(inst)
|
372
|
-
),
|
373
|
-
cleanupInstructions: (group.cleanupInstructions || []).map(
|
374
|
-
(inst: any) => this.convertAPIInstruction(inst)
|
375
|
-
),
|
376
|
-
signers: group.signers || [],
|
377
|
-
})
|
378
|
-
);
|
347
|
+
// Convert each base58-encoded signer secret into a Keypair.
|
348
|
+
const signers = data.signers;
|
349
|
+
transaction.sign(signers);
|
379
350
|
|
380
351
|
return {
|
381
|
-
|
382
|
-
|
352
|
+
transaction,
|
353
|
+
serializedTransactions: data.serializedTransactions,
|
354
|
+
amountOut: Number(quote.amountOut),
|
383
355
|
amountOutUi: Number(quote.amountOut),
|
356
|
+
pairPrice: Number(quote.tokenPrice),
|
384
357
|
routePlan,
|
385
358
|
lookupAccounts,
|
386
|
-
signers
|
359
|
+
signers,
|
360
|
+
feeRate: parseFloat(quote.feeRate),
|
387
361
|
};
|
388
362
|
}
|
389
363
|
|
@@ -398,7 +372,7 @@ export class SwapSDK {
|
|
398
372
|
throw new Error(`API Error: ${response.statusText}`);
|
399
373
|
}
|
400
374
|
const data = await response.json();
|
401
|
-
return data.map((token: any) => ({
|
375
|
+
return data.data.map((token: any) => ({
|
402
376
|
name: token.metadata.name,
|
403
377
|
symbol: token.metadata.symbol,
|
404
378
|
address: token.address,
|