@triadxyz/triad-protocol 3.5.3-beta → 4.0.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.
@@ -1,15 +0,0 @@
1
- import { AddressLookupTableAccount, Connection, TransactionInstruction } from '@solana/web3.js';
2
- export declare const swap: ({ connection, wallet, inToken, outToken, amount, payer }: {
3
- connection: Connection;
4
- wallet: string;
5
- inToken: string;
6
- outToken: string;
7
- amount: number;
8
- payer: string;
9
- }) => Promise<{
10
- swapIxs: TransactionInstruction[];
11
- addressLookupTableAccounts: AddressLookupTableAccount[];
12
- setupInstructions: any[];
13
- outAmount: any;
14
- }>;
15
- export declare const getPrice: (token: string) => Promise<any>;
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getPrice = exports.swap = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const web3_js_1 = require("@solana/web3.js");
18
- const spl_token_1 = require("@solana/spl-token");
19
- const pda_1 = require("./pda");
20
- const constants_1 = require("./constants");
21
- const swap = ({ connection, wallet, inToken, outToken, amount, payer }) => __awaiter(void 0, void 0, void 0, function* () {
22
- const token = TOKENS[inToken];
23
- if (!token) {
24
- throw new Error('Token not found');
25
- }
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`);
28
- const { data: quoteData } = quoteResponse;
29
- const swapResponse = yield axios_1.default.post('https://lite-api.jup.ag/swap/v1/swap-instructions', {
30
- quoteResponse: quoteData,
31
- userPublicKey: wallet,
32
- payer,
33
- feeAccount: inToken === constants_1.TRD_MINT.toString() ? getFeeAccount() : undefined
34
- });
35
- const { setupInstructions, swapInstruction, addressLookupTableAddresses } = swapResponse.data;
36
- return {
37
- swapIxs: [deserializeInstruction(swapInstruction)],
38
- addressLookupTableAccounts: yield getAddressLookupTableAccounts(connection, addressLookupTableAddresses),
39
- setupInstructions: setupInstructions.length > 0
40
- ? [...setupInstructions.map(deserializeInstruction)]
41
- : [],
42
- outAmount: quoteData.otherAmountThreshold
43
- };
44
- });
45
- exports.swap = swap;
46
- const getPrice = (token) => __awaiter(void 0, void 0, void 0, function* () {
47
- var _a, _b;
48
- const response = yield axios_1.default.get(`https://lite-api.jup.ag/price/v3?ids=${token}`);
49
- return (_b = (_a = response.data[token]) === null || _a === void 0 ? void 0 : _a.usdPrice) !== null && _b !== void 0 ? _b : 0;
50
- });
51
- exports.getPrice = getPrice;
52
- const deserializeInstruction = (instruction) => {
53
- return new web3_js_1.TransactionInstruction({
54
- programId: new web3_js_1.PublicKey(instruction.programId),
55
- keys: instruction.accounts.map((key) => ({
56
- pubkey: new web3_js_1.PublicKey(key.pubkey),
57
- isSigner: key.isSigner,
58
- isWritable: key.isWritable
59
- })),
60
- data: Buffer.from(instruction.data, 'base64')
61
- });
62
- };
63
- const getAddressLookupTableAccounts = (connection, keys) => __awaiter(void 0, void 0, void 0, function* () {
64
- const addressLookupTableAccountInfos = yield connection.getMultipleAccountsInfo(keys.map((key) => new web3_js_1.PublicKey(key)));
65
- return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
66
- const addressLookupTableAddress = keys[index];
67
- if (accountInfo) {
68
- const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
69
- key: new web3_js_1.PublicKey(addressLookupTableAddress),
70
- state: web3_js_1.AddressLookupTableAccount.deserialize(accountInfo.data)
71
- });
72
- acc.push(addressLookupTableAccount);
73
- }
74
- return acc;
75
- }, new Array());
76
- });
77
- const TOKENS = {
78
- So11111111111111111111111111111111111111112: {
79
- mint: 'So11111111111111111111111111111111111111112',
80
- decimals: 9
81
- },
82
- EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: {
83
- mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
84
- decimals: 6
85
- },
86
- t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV: {
87
- mint: 't3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV',
88
- decimals: 6
89
- }
90
- };
91
- const getFeeAccount = () => {
92
- return (0, pda_1.getTokenATA)(new web3_js_1.PublicKey('Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4'), constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID);
93
- };