@triadxyz/triad-protocol 2.8.3-beta → 2.8.4-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 +6 -12
- package/dist/utils/swap.d.ts +2 -2
- package/dist/utils/swap.js +9 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -368,8 +368,7 @@ class TriadProtocolClient {
|
|
|
368
368
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
369
369
|
inToken: token,
|
|
370
370
|
outToken: constants_1.TRD_MINT.toString(),
|
|
371
|
-
amount
|
|
372
|
-
swapMode: 'ExactIn'
|
|
371
|
+
amount
|
|
373
372
|
});
|
|
374
373
|
amountInTRD = outAmount;
|
|
375
374
|
if (swapIxs.length === 0) {
|
|
@@ -505,8 +504,7 @@ class TriadProtocolClient {
|
|
|
505
504
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
506
505
|
inToken: constants_1.USDC_MINT.toBase58(),
|
|
507
506
|
outToken: constants_1.TRD_MINT.toString(),
|
|
508
|
-
amount: order.shares / Math.pow(10, this.decimals)
|
|
509
|
-
swapMode: 'ExactIn'
|
|
507
|
+
amount: order.shares / Math.pow(10, this.decimals)
|
|
510
508
|
});
|
|
511
509
|
if (swapIxs.length === 0) {
|
|
512
510
|
return;
|
|
@@ -891,26 +889,23 @@ class TriadProtocolClient {
|
|
|
891
889
|
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
892
890
|
.div(adjustedPrice);
|
|
893
891
|
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
894
|
-
console.log('sharesToBuy', sharesToBuy.toNumber());
|
|
895
892
|
if (sharesToBuy.lte(new bn_js_1.default(0)))
|
|
896
893
|
continue;
|
|
897
894
|
const usdcAmount = sharesToBuy
|
|
898
895
|
.mul(adjustedPrice)
|
|
899
896
|
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
900
|
-
console.log('usdcAmount', usdcAmount.toNumber());
|
|
901
|
-
console.log('--------------------------------');
|
|
902
897
|
totalUSDCNeeded = totalUSDCNeeded.add(usdcAmount);
|
|
903
898
|
tempRemainingUSDC = tempRemainingUSDC.sub(usdcAmount);
|
|
904
899
|
}
|
|
905
|
-
console.log('totalUSDCNeeded', totalUSDCNeeded.toNumber());
|
|
906
900
|
if (isTrdPayout && totalUSDCNeeded.gt(new bn_js_1.default(0))) {
|
|
901
|
+
const price = yield (0, swap_1.getPrice)(constants_1.TRD_MINT.toString());
|
|
902
|
+
const amountInTRD = totalUSDCNeeded.toNumber() / Math.pow(10, this.decimals) / price;
|
|
907
903
|
const { swapIxs, addressLookupTableAccounts: swapAddressLookupTableAccounts, outAmount, setupInstructions } = yield (0, swap_1.swap)({
|
|
908
904
|
connection: this.program.provider.connection,
|
|
909
905
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
910
906
|
inToken: constants_1.TRD_MINT.toString(),
|
|
911
907
|
outToken: constants_1.USDC_MINT.toString(),
|
|
912
|
-
amount:
|
|
913
|
-
swapMode: 'ExactOut'
|
|
908
|
+
amount: amountInTRD
|
|
914
909
|
});
|
|
915
910
|
if (swapIxs.length === 0) {
|
|
916
911
|
return;
|
|
@@ -1052,8 +1047,7 @@ class TriadProtocolClient {
|
|
|
1052
1047
|
wallet: this.program.provider.publicKey.toBase58(),
|
|
1053
1048
|
inToken: constants_1.USDC_MINT.toBase58(),
|
|
1054
1049
|
outToken: constants_1.TRD_MINT.toString(),
|
|
1055
|
-
amount: amountOfUSDC.toNumber()
|
|
1056
|
-
swapMode: 'ExactIn'
|
|
1050
|
+
amount: amountOfUSDC.toNumber()
|
|
1057
1051
|
});
|
|
1058
1052
|
if (swapIxs.length > 0) {
|
|
1059
1053
|
ixs.push(...setupInstructions);
|
package/dist/utils/swap.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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 }: {
|
|
3
3
|
connection: Connection;
|
|
4
4
|
wallet: string;
|
|
5
5
|
inToken: string;
|
|
6
6
|
outToken: string;
|
|
7
7
|
amount: number;
|
|
8
|
-
swapMode: 'ExactIn' | 'ExactOut';
|
|
9
8
|
}) => Promise<{
|
|
10
9
|
swapIxs: TransactionInstruction[];
|
|
11
10
|
addressLookupTableAccounts: AddressLookupTableAccount[];
|
|
12
11
|
setupInstructions: TransactionInstruction[];
|
|
13
12
|
outAmount: any;
|
|
14
13
|
}>;
|
|
14
|
+
export declare const getPrice: (token: string) => Promise<any>;
|
package/dist/utils/swap.js
CHANGED
|
@@ -12,19 +12,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.swap = void 0;
|
|
15
|
+
exports.getPrice = exports.swap = void 0;
|
|
16
16
|
const index_1 = require("./pda/index");
|
|
17
17
|
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
|
|
21
|
+
const swap = ({ connection, wallet, inToken, outToken, amount }) => __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}&
|
|
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`);
|
|
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,
|
|
@@ -42,6 +42,12 @@ const swap = ({ connection, wallet, inToken, outToken, amount, swapMode = 'Exact
|
|
|
42
42
|
};
|
|
43
43
|
});
|
|
44
44
|
exports.swap = swap;
|
|
45
|
+
const getPrice = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
var _a, _b;
|
|
47
|
+
const response = yield axios_1.default.get(`https://lite-api.jup.ag/price/v3?ids=${token}`);
|
|
48
|
+
return (_b = (_a = response.data[token]) === null || _a === void 0 ? void 0 : _a.usdPrice) !== null && _b !== void 0 ? _b : 0;
|
|
49
|
+
});
|
|
50
|
+
exports.getPrice = getPrice;
|
|
45
51
|
const deserializeInstruction = (instruction) => {
|
|
46
52
|
return new web3_js_1.TransactionInstruction({
|
|
47
53
|
programId: new web3_js_1.PublicKey(instruction.programId),
|