@triadxyz/poseidons-protocol 0.0.1
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/LICENSE +201 -0
- package/README.md +11 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +162 -0
- package/dist/types/idl_poseidons_protocol.json +718 -0
- package/dist/types/index.d.ts +24 -0
- package/dist/types/index.js +2 -0
- package/dist/types/poseidons_protocol.d.ts +893 -0
- package/dist/types/poseidons_protocol.js +2 -0
- package/dist/utils/constants.d.ts +3 -0
- package/dist/utils/constants.js +6 -0
- package/dist/utils/getPriorityFee.d.ts +2 -0
- package/dist/utils/getPriorityFee.js +25 -0
- package/dist/utils/helpers.d.ts +6 -0
- package/dist/utils/helpers.js +25 -0
- package/dist/utils/pda.d.ts +4 -0
- package/dist/utils/pda.js +18 -0
- package/dist/utils/sendVersionedTransaction.d.ts +6 -0
- package/dist/utils/sendVersionedTransaction.js +47 -0
- package/package.json +44 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CORE_POSEIDON_COLLECTION = exports.POSEIDON_VAULT_PROGRAM_ID = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
exports.POSEIDON_VAULT_PROGRAM_ID = new web3_js_1.PublicKey('E65MHJjJT2ihTLgMfHdWtsNYMA6iJsCjraf7UrxU2sDP');
|
|
6
|
+
exports.CORE_POSEIDON_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er632dvn878qkpdcnvq5ZUspSm');
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const getPriorityFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
let fee = 1000;
|
|
18
|
+
try {
|
|
19
|
+
const response = yield axios_1.default.get('https://solanacompass.com/api/fees');
|
|
20
|
+
fee = response.data[1].priorityTx;
|
|
21
|
+
}
|
|
22
|
+
catch (_a) { }
|
|
23
|
+
return fee;
|
|
24
|
+
});
|
|
25
|
+
exports.default = getPriorityFee;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IdlAccounts } from '@coral-xyz/anchor';
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { PoseidonsProtocol } from '../types/poseidons_protocol';
|
|
4
|
+
import { PoseidonVault, Poseidon } from '../types';
|
|
5
|
+
export declare const formatPoseidonVault: (account: IdlAccounts<PoseidonsProtocol>['poseidonVault'], address: PublicKey) => PoseidonVault;
|
|
6
|
+
export declare const formatPoseidon: (account: IdlAccounts<PoseidonsProtocol>['poseidon'], address: PublicKey) => Poseidon;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatPoseidon = exports.formatPoseidonVault = void 0;
|
|
4
|
+
const formatPoseidonVault = (account, address) => {
|
|
5
|
+
return {
|
|
6
|
+
address: address.toString(),
|
|
7
|
+
authority: account.authority.toString(),
|
|
8
|
+
amount: account.amount.toNumber() / Math.pow(10, 6),
|
|
9
|
+
amountPaid: account.amountPaid.toNumber() / Math.pow(10, 6),
|
|
10
|
+
name: account.name
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.formatPoseidonVault = formatPoseidonVault;
|
|
14
|
+
const formatPoseidon = (account, address) => {
|
|
15
|
+
return {
|
|
16
|
+
address: address.toString(),
|
|
17
|
+
nftMint: account.nftMint.toString(),
|
|
18
|
+
rewardsClaimed: account.rewardsClaimed.toNumber() / Math.pow(10, 6),
|
|
19
|
+
rewardsAvailable: account.rewardsAvailable.toNumber() / Math.pow(10, 6),
|
|
20
|
+
power: account.power.toNumber(),
|
|
21
|
+
trdBurned: account.trdBurned.toNumber() / Math.pow(10, 6),
|
|
22
|
+
number: account.number
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.formatPoseidon = formatPoseidon;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey, program?: PublicKey) => PublicKey;
|
|
3
|
+
export declare const getPoseidonVaultPDA: () => PublicKey;
|
|
4
|
+
export declare const getPoseidonPDA: (mint: PublicKey) => PublicKey;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPoseidonPDA = exports.getPoseidonVaultPDA = exports.getTokenATA = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const getTokenATA = (address, Mint, program = spl_token_1.TOKEN_2022_PROGRAM_ID) => {
|
|
8
|
+
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(), program.toBytes(), Mint.toBytes()], new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
|
9
|
+
};
|
|
10
|
+
exports.getTokenATA = getTokenATA;
|
|
11
|
+
const getPoseidonVaultPDA = () => {
|
|
12
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('poseidon_vault')], constants_1.POSEIDON_VAULT_PROGRAM_ID)[0];
|
|
13
|
+
};
|
|
14
|
+
exports.getPoseidonVaultPDA = getPoseidonVaultPDA;
|
|
15
|
+
const getPoseidonPDA = (mint) => {
|
|
16
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('poseidon'), mint.toBytes()], constants_1.POSEIDON_VAULT_PROGRAM_ID)[0];
|
|
17
|
+
};
|
|
18
|
+
exports.getPoseidonPDA = getPoseidonPDA;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { TransactionInstruction, VersionedTransaction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
2
|
+
import { Program } from '@coral-xyz/anchor';
|
|
3
|
+
import { RpcOptions } from '../types';
|
|
4
|
+
import { PoseidonsProtocol } from '../types/poseidons_protocol';
|
|
5
|
+
declare const sendVersionedTransaction: (program: Program<PoseidonsProtocol>, ixs: TransactionInstruction[], options?: RpcOptions, addressLookupTableAccounts?: AddressLookupTableAccount[]) => Promise<VersionedTransaction | string>;
|
|
6
|
+
export default sendVersionedTransaction;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
+
const getPriorityFee_1 = __importDefault(require("./getPriorityFee"));
|
|
17
|
+
const sendVersionedTransaction = (program, ixs, options, addressLookupTableAccounts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
20
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
21
|
+
microLamports: options.microLamports
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
if (!(options === null || options === void 0 ? void 0 : options.microLamports)) {
|
|
25
|
+
const priorityFee = yield (0, getPriorityFee_1.default)();
|
|
26
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
27
|
+
microLamports: priorityFee
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
const { blockhash } = yield program.provider.connection.getLatestBlockhash();
|
|
31
|
+
if (program.provider.publicKey.toBase58() !== ((_a = options === null || options === void 0 ? void 0 : options.payer) === null || _a === void 0 ? void 0 : _a.toBase58())) {
|
|
32
|
+
return new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
33
|
+
instructions: ixs,
|
|
34
|
+
recentBlockhash: blockhash,
|
|
35
|
+
payerKey: options === null || options === void 0 ? void 0 : options.payer
|
|
36
|
+
}).compileToV0Message(addressLookupTableAccounts));
|
|
37
|
+
}
|
|
38
|
+
return program.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
39
|
+
instructions: ixs,
|
|
40
|
+
recentBlockhash: blockhash,
|
|
41
|
+
payerKey: program.provider.publicKey
|
|
42
|
+
}).compileToV0Message(addressLookupTableAccounts)), [], {
|
|
43
|
+
skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
|
|
44
|
+
commitment: options === null || options === void 0 ? void 0 : options.commitment
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
exports.default = sendVersionedTransaction;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@triadxyz/poseidons-protocol",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"clean": "rimraf dist",
|
|
9
|
+
"build": "yarn run clean && tsc",
|
|
10
|
+
"prepublishOnly": "yarn build"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"./dist/**/*"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [],
|
|
22
|
+
"author": "Triad Markets",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@coral-xyz/anchor": "0.30.1",
|
|
26
|
+
"@solana/spl-token": "0.4.8",
|
|
27
|
+
"@solana/web3.js": "1.95.3",
|
|
28
|
+
"axios": "1.9.0",
|
|
29
|
+
"bn.js": "5.2.2",
|
|
30
|
+
"bs58": "6.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "6.7.3",
|
|
34
|
+
"@typescript-eslint/parser": "6.7.3",
|
|
35
|
+
"@types/bn.js": "^5.1.0",
|
|
36
|
+
"eslint": "8.50.0",
|
|
37
|
+
"eslint-config-prettier": "9.0.0",
|
|
38
|
+
"eslint-plugin-prettier": "5.0.0",
|
|
39
|
+
"prettier": "3.2.4",
|
|
40
|
+
"rimraf": "^5.0.5",
|
|
41
|
+
"typedoc": "0.25.1",
|
|
42
|
+
"typescript": "5.2.2"
|
|
43
|
+
}
|
|
44
|
+
}
|