@triadxyz/triad-protocol 2.8.1-beta → 2.8.3-beta
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.js +9 -4
- package/dist/utils/swap.d.ts +2 -1
- package/dist/utils/swap.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -368,7 +368,8 @@ class TriadProtocolClient {
|
|
|
368
368
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
369
369
|
inToken: token,
|
|
370
370
|
outToken: constants_1.TRD_MINT.toString(),
|
|
371
|
-
amount
|
|
371
|
+
amount,
|
|
372
|
+
swapMode: 'ExactIn'
|
|
372
373
|
});
|
|
373
374
|
amountInTRD = outAmount;
|
|
374
375
|
if (swapIxs.length === 0) {
|
|
@@ -504,7 +505,8 @@ class TriadProtocolClient {
|
|
|
504
505
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
505
506
|
inToken: constants_1.USDC_MINT.toBase58(),
|
|
506
507
|
outToken: constants_1.TRD_MINT.toString(),
|
|
507
|
-
amount: order.shares / Math.pow(10, this.decimals)
|
|
508
|
+
amount: order.shares / Math.pow(10, this.decimals),
|
|
509
|
+
swapMode: 'ExactIn'
|
|
508
510
|
});
|
|
509
511
|
if (swapIxs.length === 0) {
|
|
510
512
|
return;
|
|
@@ -900,13 +902,15 @@ class TriadProtocolClient {
|
|
|
900
902
|
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
901
903
|
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
902
904
|
}
|
|
905
|
+
console.log('totalUSDCNeeded', totalUSDCNeeded.toNumber());
|
|
903
906
|
if (isTrdPayout && totalUSDCNeeded.gt(new bn_js_1.default(0))) {
|
|
904
907
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
905
908
|
connection: this.program.provider.connection,
|
|
906
909
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
907
910
|
inToken: constants_1.TRD_MINT.toString(),
|
|
908
911
|
outToken: constants_1.USDC_MINT.toString(),
|
|
909
|
-
amount: totalUSDCNeeded.toNumber() / Math.pow(10, this.decimals)
|
|
912
|
+
amount: totalUSDCNeeded.toNumber() / Math.pow(10, this.decimals),
|
|
913
|
+
swapMode: 'ExactOut'
|
|
910
914
|
});
|
|
911
915
|
if (swapIxs.length === 0) {
|
|
912
916
|
return;
|
|
@@ -1048,7 +1052,8 @@ class TriadProtocolClient {
|
|
|
1048
1052
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
1049
1053
|
inToken: constants_1.USDC_MINT.toBase58(),
|
|
1050
1054
|
outToken: constants_1.TRD_MINT.toString(),
|
|
1051
|
-
amount: amountOfUSDC.toNumber()
|
|
1055
|
+
amount: amountOfUSDC.toNumber(),
|
|
1056
|
+
swapMode: 'ExactIn'
|
|
1052
1057
|
});
|
|
1053
1058
|
if (swapIxs.length > 0) {
|
|
1054
1059
|
ixs.push(...setupInstructions);
|
package/dist/utils/swap.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AddressLookupTableAccount, Connection, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
export declare const swap: ({ connection, wallet, inToken, outToken, amount }: {
|
|
2
|
+
export declare const swap: ({ connection, wallet, inToken, outToken, amount, swapMode }: {
|
|
3
3
|
connection: Connection;
|
|
4
4
|
wallet: string;
|
|
5
5
|
inToken: string;
|
|
6
6
|
outToken: string;
|
|
7
7
|
amount: number;
|
|
8
|
+
swapMode: 'ExactIn' | 'ExactOut';
|
|
8
9
|
}) => Promise<{
|
|
9
10
|
swapIxs: TransactionInstruction[];
|
|
10
11
|
addressLookupTableAccounts: AddressLookupTableAccount[];
|
package/dist/utils/swap.js
CHANGED
|
@@ -18,13 +18,13 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
18
18
|
const web3_js_1 = require("@solana/web3.js");
|
|
19
19
|
const constants_1 = require("./constants");
|
|
20
20
|
const spl_token_1 = require("@solana/spl-token");
|
|
21
|
-
const swap = ({ connection, wallet, inToken, outToken, amount }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const swap = ({ connection, wallet, inToken, outToken, amount, swapMode = 'ExactIn' }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
22
|
const token = TOKENS[inToken];
|
|
23
23
|
if (!token) {
|
|
24
24
|
throw new Error('Token not found');
|
|
25
25
|
}
|
|
26
26
|
const formattedAmountIn = amount * Math.pow(10, token.decimals);
|
|
27
|
-
const quoteResponse = yield axios_1.default.get(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${inToken}&outputMint=${outToken}&amount=${formattedAmountIn}&slippageBps=20&onlyDirectRoutes=true&platformFeeBps=60`);
|
|
27
|
+
const quoteResponse = yield axios_1.default.get(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${inToken}&outputMint=${outToken}&amount=${formattedAmountIn}&swapMode=${swapMode}&slippageBps=20&onlyDirectRoutes=true&platformFeeBps=60`);
|
|
28
28
|
const { data: quoteData } = quoteResponse;
|
|
29
29
|
const swapResponse = yield axios_1.default.post('https://lite-api.jup.ag/swap/v1/swap-instructions', {
|
|
30
30
|
quoteResponse: quoteData,
|