@triadxyz/triad-protocol 0.1.2-alpha.2 → 0.1.2-alpha.4
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/utils/priorityFee.d.ts +1 -0
- package/dist/utils/priorityFee.js +36 -0
- package/dist/vault.js +14 -6
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPriorityFeeEstimate(priorityLevel: any, transaction: any, RPC_URL: any): 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;
|
package/dist/vault.js
CHANGED
|
@@ -13,6 +13,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
13
13
|
const web3_js_1 = require("@solana/web3.js");
|
|
14
14
|
const helpers_1 = require("./utils/helpers");
|
|
15
15
|
const spl_token_1 = require("@solana/spl-token");
|
|
16
|
+
const priorityFee_1 = require("./utils/priorityFee");
|
|
16
17
|
class Vault {
|
|
17
18
|
constructor(program, provider) {
|
|
18
19
|
this.provider = provider;
|
|
@@ -62,11 +63,7 @@ class Vault {
|
|
|
62
63
|
hasUserPosition = true;
|
|
63
64
|
}
|
|
64
65
|
catch (_a) { }
|
|
65
|
-
const instructions = [
|
|
66
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
67
|
-
microLamports: 60000
|
|
68
|
-
})
|
|
69
|
-
];
|
|
66
|
+
const instructions = [];
|
|
70
67
|
if (!hasUserPosition) {
|
|
71
68
|
instructions.push(yield this.program.methods
|
|
72
69
|
.createUserPosition()
|
|
@@ -91,6 +88,17 @@ class Vault {
|
|
|
91
88
|
})
|
|
92
89
|
.instruction());
|
|
93
90
|
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
91
|
+
const priorityLevel = 'HIGH';
|
|
92
|
+
let feeEstimate = { priorityFeeEstimate: 0 };
|
|
93
|
+
feeEstimate = yield (0, priorityFee_1.getPriorityFeeEstimate)(priorityLevel, new web3_js_1.TransactionMessage({
|
|
94
|
+
payerKey: this.provider.wallet.publicKey,
|
|
95
|
+
recentBlockhash: blockhash,
|
|
96
|
+
instructions
|
|
97
|
+
}).compileToV0Message(), this.provider.connection);
|
|
98
|
+
const computePriceIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
99
|
+
microLamports: feeEstimate.priorityFeeEstimate
|
|
100
|
+
});
|
|
101
|
+
instructions.unshift(computePriceIx);
|
|
94
102
|
const message = new web3_js_1.TransactionMessage({
|
|
95
103
|
payerKey: this.provider.wallet.publicKey,
|
|
96
104
|
recentBlockhash: blockhash,
|
|
@@ -129,7 +137,7 @@ class Vault {
|
|
|
129
137
|
}
|
|
130
138
|
const instructions = [
|
|
131
139
|
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
132
|
-
microLamports:
|
|
140
|
+
microLamports: 160000
|
|
133
141
|
})
|
|
134
142
|
];
|
|
135
143
|
if (!hasUser) {
|