@triadxyz/triad-protocol 0.0.1-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.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,31 @@
1
+ export declare const TRIAD_PROTOCOL_PROGRAM_ID = "TRDwq3BN4mP3m9KsuNUWSN6QDff93VKGSwE95Jbr9Ss";
2
+ export declare const ATA_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
3
+ export declare const STAKE_SEASON = "Triad Share 1";
4
+ export declare const TTRIAD_DECIMALS = 6;
5
+ export declare const TTRIAD_FEE = 2;
6
+ export declare const RARITY_RANK_SEASON_1: {
7
+ mythic: {
8
+ min: number;
9
+ max: number;
10
+ };
11
+ legendary: {
12
+ min: number;
13
+ max: number;
14
+ };
15
+ epic: {
16
+ min: number;
17
+ max: number;
18
+ };
19
+ rare: {
20
+ min: number;
21
+ max: number;
22
+ };
23
+ uncommon: {
24
+ min: number;
25
+ max: number;
26
+ };
27
+ common: {
28
+ min: number;
29
+ max: number;
30
+ };
31
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RARITY_RANK_SEASON_1 = exports.TTRIAD_FEE = exports.TTRIAD_DECIMALS = exports.STAKE_SEASON = exports.ATA_PROGRAM_ID = exports.TRIAD_PROTOCOL_PROGRAM_ID = void 0;
4
+ exports.TRIAD_PROTOCOL_PROGRAM_ID = 'TRDwq3BN4mP3m9KsuNUWSN6QDff93VKGSwE95Jbr9Ss';
5
+ exports.ATA_PROGRAM_ID = 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
6
+ exports.STAKE_SEASON = 'Triad Share 1';
7
+ exports.TTRIAD_DECIMALS = 6;
8
+ exports.TTRIAD_FEE = 2;
9
+ exports.RARITY_RANK_SEASON_1 = {
10
+ mythic: { min: 1, max: 18 },
11
+ legendary: { min: 19, max: 91 },
12
+ epic: { min: 92, max: 275 },
13
+ rare: { min: 276, max: 643 },
14
+ uncommon: { min: 644, max: 1103 },
15
+ common: { min: 1104, max: 1839 }
16
+ };
@@ -0,0 +1,2 @@
1
+ import { Keypair } from '@solana/web3.js';
2
+ export declare const convertSecretKeyToKeypair: (key: string) => Keypair;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertSecretKeyToKeypair = void 0;
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const bs58_1 = __importDefault(require("bs58"));
9
+ const convertSecretKeyToKeypair = (key) => web3_js_1.Keypair.fromSecretKey(bs58_1.default.decode(key));
10
+ exports.convertSecretKeyToKeypair = convertSecretKeyToKeypair;
@@ -0,0 +1,11 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ import BN from 'bn.js';
3
+ export declare const getTickerAddressSync: (programId: PublicKey, tickerName: string) => PublicKey;
4
+ export declare const encodeString: (value: string) => number[];
5
+ export declare const decodeString: (bytes: number[]) => string;
6
+ export declare const getVaultAddressSync: (programId: PublicKey, tickerAddress: PublicKey) => PublicKey;
7
+ export declare const getTokenVaultAddressSync: (programId: PublicKey, vault: PublicKey) => PublicKey;
8
+ export declare function getUserPositionAddressSync(programId: PublicKey, authority: PublicKey, ticker: PublicKey): PublicKey;
9
+ export declare const getStakeVaultAddressSync: (programId: PublicKey, vaultName: string) => PublicKey;
10
+ export declare const getATASync: (address: PublicKey, Mint: PublicKey) => PublicKey;
11
+ export declare const formatNumber: (number: bigint | BN, decimals?: number) => number;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.formatNumber = exports.getATASync = exports.getStakeVaultAddressSync = exports.getUserPositionAddressSync = exports.getTokenVaultAddressSync = exports.getVaultAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
27
+ const web3_js_1 = require("@solana/web3.js");
28
+ const anchor = __importStar(require("@coral-xyz/anchor"));
29
+ const spl_token_1 = require("@solana/spl-token");
30
+ const constants_1 = require("./constants");
31
+ const getTickerAddressSync = (programId, tickerName) => {
32
+ const [TickerPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ticker'), Buffer.from(tickerName)], programId);
33
+ return TickerPDA;
34
+ };
35
+ exports.getTickerAddressSync = getTickerAddressSync;
36
+ const encodeString = (value) => {
37
+ const buffer = Buffer.alloc(32);
38
+ buffer.fill(value);
39
+ buffer.fill(' ', value.length);
40
+ return Array(...buffer);
41
+ };
42
+ exports.encodeString = encodeString;
43
+ const decodeString = (bytes) => {
44
+ const buffer = Buffer.from(bytes);
45
+ return buffer.toString('utf8').trim();
46
+ };
47
+ exports.decodeString = decodeString;
48
+ const getVaultAddressSync = (programId, tickerAddress) => {
49
+ const [VaultPDA] = web3_js_1.PublicKey.findProgramAddressSync([
50
+ Buffer.from(anchor.utils.bytes.utf8.encode('vault')),
51
+ tickerAddress.toBuffer()
52
+ ], programId);
53
+ return VaultPDA;
54
+ };
55
+ exports.getVaultAddressSync = getVaultAddressSync;
56
+ const getTokenVaultAddressSync = (programId, vault) => {
57
+ const [VaultTokenPDA] = web3_js_1.PublicKey.findProgramAddressSync([
58
+ Buffer.from(anchor.utils.bytes.utf8.encode('vault_token_account')),
59
+ vault.toBuffer()
60
+ ], programId);
61
+ return VaultTokenPDA;
62
+ };
63
+ exports.getTokenVaultAddressSync = getTokenVaultAddressSync;
64
+ function getUserPositionAddressSync(programId, authority, ticker) {
65
+ const [UserPositionPDA] = web3_js_1.PublicKey.findProgramAddressSync([
66
+ Buffer.from(anchor.utils.bytes.utf8.encode('user_position')),
67
+ authority.toBuffer(),
68
+ ticker.toBuffer()
69
+ ], programId);
70
+ return UserPositionPDA;
71
+ }
72
+ exports.getUserPositionAddressSync = getUserPositionAddressSync;
73
+ const getStakeVaultAddressSync = (programId, vaultName) => {
74
+ const [StakeVaultPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('stake_vault'), Buffer.from(vaultName)], programId);
75
+ return StakeVaultPDA;
76
+ };
77
+ exports.getStakeVaultAddressSync = getStakeVaultAddressSync;
78
+ const getATASync = (address, Mint) => {
79
+ const [ATA] = web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(), spl_token_1.TOKEN_2022_PROGRAM_ID.toBytes(), Mint.toBytes()], new web3_js_1.PublicKey(constants_1.ATA_PROGRAM_ID));
80
+ return ATA;
81
+ };
82
+ exports.getATASync = getATASync;
83
+ const formatNumber = (number, decimals = 6) => {
84
+ return Number(number.toString()) / Math.pow(10, decimals);
85
+ };
86
+ exports.formatNumber = formatNumber;
@@ -0,0 +1 @@
1
+ export declare function getPriorityFeeEstimate(priorityLevel: any, transaction: any, RPC_URL: string): Promise<any>;
@@ -0,0 +1,36 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getPriorityFeeEstimate = void 0;
13
+ const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
14
+ function getPriorityFeeEstimate(priorityLevel, transaction, RPC_URL) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const response = yield fetch(RPC_URL, {
17
+ method: "POST",
18
+ headers: { "Content-Type": "application/json" },
19
+ body: JSON.stringify({
20
+ jsonrpc: "2.0",
21
+ id: "1",
22
+ method: "getPriorityFeeEstimate",
23
+ params: [
24
+ {
25
+ transaction: bytes_1.bs58.encode(transaction.serialize()),
26
+ options: { priorityLevel: priorityLevel },
27
+ },
28
+ ],
29
+ }),
30
+ });
31
+ const data = yield response.json();
32
+ console.log("Fee in function for", priorityLevel, " :", data.result.priorityFeeEstimate);
33
+ return data.result;
34
+ });
35
+ }
36
+ exports.getPriorityFeeEstimate = getPriorityFeeEstimate;