@drift-labs/sdk 2.31.1-beta.19 → 2.31.1-beta.20
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/VERSION +1 -1
- package/lib/idl/drift.json +1 -1
- package/lib/math/superStake.js +7 -3
- package/package.json +1 -1
- package/src/idl/drift.json +1 -1
- package/src/math/superStake.ts +3 -2
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.31.1-beta.
|
|
1
|
+
2.31.1-beta.20
|
package/lib/idl/drift.json
CHANGED
package/lib/math/superStake.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.calculateSolEarned = exports.findBestSuperStakeIxs = void 0;
|
|
4
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -6,6 +9,7 @@ const marinade_1 = require("../marinade");
|
|
|
6
9
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
7
10
|
const types_1 = require("../types");
|
|
8
11
|
const numericConstants_1 = require("../constants/numericConstants");
|
|
12
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
13
|
async function findBestSuperStakeIxs({ amount, jupiterClient, driftClient, userAccountPublicKey, }) {
|
|
10
14
|
const marinadeProgram = (0, marinade_1.getMarinadeFinanceProgram)(driftClient.provider);
|
|
11
15
|
const marinadePrice = await (0, marinade_1.getMarinadeMSolPrice)(marinadeProgram);
|
|
@@ -56,7 +60,7 @@ async function calculateSolEarned({ user, depositRecords, }) {
|
|
|
56
60
|
const date = new Date(timestamp * 1000); // Convert Unix timestamp to milliseconds
|
|
57
61
|
const swaggerApiDateTime = date.toISOString(); // Format date as swagger API date-time
|
|
58
62
|
const url = `https://api.marinade.finance/msol/price_sol?time=${swaggerApiDateTime}`;
|
|
59
|
-
const response = await
|
|
63
|
+
const response = await (0, node_fetch_1.default)(url);
|
|
60
64
|
if (response.status === 200) {
|
|
61
65
|
const data = await response.json();
|
|
62
66
|
msolRatios.set(timestamp, data);
|
|
@@ -66,7 +70,7 @@ async function calculateSolEarned({ user, depositRecords, }) {
|
|
|
66
70
|
let solEarned = numericConstants_1.ZERO;
|
|
67
71
|
for (const record of depositRecords) {
|
|
68
72
|
if (record.marketIndex === 1) {
|
|
69
|
-
if ((0, types_1.isVariant)(record.
|
|
73
|
+
if ((0, types_1.isVariant)(record.direction, 'deposit')) {
|
|
70
74
|
solEarned = solEarned.sub(record.amount);
|
|
71
75
|
}
|
|
72
76
|
else {
|
|
@@ -77,7 +81,7 @@ async function calculateSolEarned({ user, depositRecords, }) {
|
|
|
77
81
|
const msolRatio = msolRatios.get(record.ts.toNumber());
|
|
78
82
|
const msolRatioBN = new anchor_1.BN(msolRatio * web3_js_1.LAMPORTS_PER_SOL);
|
|
79
83
|
const solAmount = record.amount.mul(msolRatioBN).div(numericConstants_1.LAMPORTS_PRECISION);
|
|
80
|
-
if ((0, types_1.isVariant)(record.
|
|
84
|
+
if ((0, types_1.isVariant)(record.direction, 'deposit')) {
|
|
81
85
|
solEarned = solEarned.sub(solAmount);
|
|
82
86
|
}
|
|
83
87
|
else {
|
package/package.json
CHANGED
package/src/idl/drift.json
CHANGED
package/src/math/superStake.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { BN } from '@coral-xyz/anchor';
|
|
|
11
11
|
import { User } from '../user';
|
|
12
12
|
import { DepositRecord, isVariant } from '../types';
|
|
13
13
|
import { LAMPORTS_PRECISION, ZERO } from '../constants/numericConstants';
|
|
14
|
+
import fetch from 'node-fetch';
|
|
14
15
|
|
|
15
16
|
export async function findBestSuperStakeIxs({
|
|
16
17
|
amount,
|
|
@@ -99,7 +100,7 @@ export async function calculateSolEarned({
|
|
|
99
100
|
let solEarned = ZERO;
|
|
100
101
|
for (const record of depositRecords) {
|
|
101
102
|
if (record.marketIndex === 1) {
|
|
102
|
-
if (isVariant(record.
|
|
103
|
+
if (isVariant(record.direction, 'deposit')) {
|
|
103
104
|
solEarned = solEarned.sub(record.amount);
|
|
104
105
|
} else {
|
|
105
106
|
solEarned = solEarned.add(record.amount);
|
|
@@ -109,7 +110,7 @@ export async function calculateSolEarned({
|
|
|
109
110
|
const msolRatioBN = new BN(msolRatio * LAMPORTS_PER_SOL);
|
|
110
111
|
|
|
111
112
|
const solAmount = record.amount.mul(msolRatioBN).div(LAMPORTS_PRECISION);
|
|
112
|
-
if (isVariant(record.
|
|
113
|
+
if (isVariant(record.direction, 'deposit')) {
|
|
113
114
|
solEarned = solEarned.sub(solAmount);
|
|
114
115
|
} else {
|
|
115
116
|
solEarned = solEarned.add(solAmount);
|