@haven-fi/solauto-sdk 1.0.172 → 1.0.173
Sign up to get free protection for your applications and to get access to all the features.
@@ -191,7 +191,7 @@ class TransactionsManager {
|
|
191
191
|
}
|
192
192
|
}
|
193
193
|
this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
|
194
|
-
this.statusCallback?.(this.statuses);
|
194
|
+
this.statusCallback?.([...this.statuses]);
|
195
195
|
}
|
196
196
|
// TODO remove me
|
197
197
|
async debugAccounts(itemSet, tx) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,eAAe,EAEf,GAAG,EACH,SAAS,IAAI,YAAY,EAC1B,MAAM,0BAA0B,CAAC;AAKlC,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAwD5E;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAKpB;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACtC,OAAO,GAAE,MAAU,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ"}
|
@@ -28,7 +28,9 @@ function currentUnixSeconds() {
|
|
28
28
|
return Math.round(new Date().getTime() / 1000);
|
29
29
|
}
|
30
30
|
async function getSolanaAccountCreated(umi, pk) {
|
31
|
-
const account = await umi.rpc.getAccount((0, umi_1.publicKey)(pk), {
|
31
|
+
const account = await umi.rpc.getAccount((0, umi_1.publicKey)(pk), {
|
32
|
+
commitment: "confirmed",
|
33
|
+
});
|
32
34
|
return rpcAccountCreated(account);
|
33
35
|
}
|
34
36
|
function rpcAccountCreated(account) {
|
@@ -53,25 +55,28 @@ async function fetchTokenPrices(mints) {
|
|
53
55
|
}
|
54
56
|
const priceFeedIds = mints.map((mint) => pythConstants_1.PYTH_PRICE_FEED_IDS[mint.toString()]);
|
55
57
|
const getReq = async () => await fetch(`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`);
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
const json = await resp.json();
|
64
|
-
const prices = json.parsed.map((x) => {
|
65
|
-
if (x.price.expo > 0) {
|
66
|
-
return Number((0, numberUtils_1.toBaseUnit)(Number(x.price.price), x.price.expo));
|
67
|
-
}
|
68
|
-
else if (x.price.expo < 0) {
|
69
|
-
return (0, numberUtils_1.fromBaseUnit)(BigInt(x.price.price), Math.abs(x.price.expo));
|
58
|
+
const prices = await retryWithExponentialBackoff(async () => {
|
59
|
+
let resp = await getReq();
|
60
|
+
let status = resp.status;
|
61
|
+
while (status !== 200) {
|
62
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
63
|
+
resp = await getReq();
|
64
|
+
status = resp.status;
|
70
65
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
const json = await resp.json();
|
67
|
+
const prices = json.parsed.map((x) => {
|
68
|
+
if (x.price.expo > 0) {
|
69
|
+
return Number((0, numberUtils_1.toBaseUnit)(Number(x.price.price), x.price.expo));
|
70
|
+
}
|
71
|
+
else if (x.price.expo < 0) {
|
72
|
+
return (0, numberUtils_1.fromBaseUnit)(BigInt(x.price.price), Math.abs(x.price.expo));
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
return Number(x.price.price);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return prices;
|
79
|
+
}, 5, 200);
|
75
80
|
for (var i = 0; i < mints.length; i++) {
|
76
81
|
solautoConstants_1.PRICES[mints[i].toString()] = {
|
77
82
|
price: prices[i],
|
package/package.json
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
MaybeRpcAccount,
|
4
|
+
publicKey,
|
5
|
+
Umi,
|
6
|
+
PublicKey as UmiPublicKey,
|
7
|
+
} from "@metaplex-foundation/umi";
|
3
8
|
import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
|
4
9
|
import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
5
10
|
import { PRICES } from "../constants/solautoConstants";
|
@@ -25,7 +30,9 @@ export async function getSolanaAccountCreated(
|
|
25
30
|
umi: Umi,
|
26
31
|
pk: PublicKey
|
27
32
|
): Promise<boolean> {
|
28
|
-
const account = await umi.rpc.getAccount(publicKey(pk), {
|
33
|
+
const account = await umi.rpc.getAccount(publicKey(pk), {
|
34
|
+
commitment: "confirmed",
|
35
|
+
});
|
29
36
|
return rpcAccountCreated(account);
|
30
37
|
}
|
31
38
|
|
@@ -65,24 +72,33 @@ export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
|
65
72
|
await fetch(
|
66
73
|
`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`
|
67
74
|
);
|
68
|
-
let resp = await getReq();
|
69
|
-
let status = resp.status;
|
70
|
-
while (status !== 200) {
|
71
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
72
|
-
resp = await getReq();
|
73
|
-
status = resp.status;
|
74
|
-
}
|
75
75
|
|
76
|
-
const
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
76
|
+
const prices = await retryWithExponentialBackoff(
|
77
|
+
async () => {
|
78
|
+
let resp = await getReq();
|
79
|
+
let status = resp.status;
|
80
|
+
while (status !== 200) {
|
81
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
82
|
+
resp = await getReq();
|
83
|
+
status = resp.status;
|
84
|
+
}
|
85
|
+
|
86
|
+
const json = await resp.json();
|
87
|
+
const prices = json.parsed.map((x: any) => {
|
88
|
+
if (x.price.expo > 0) {
|
89
|
+
return Number(toBaseUnit(Number(x.price.price), x.price.expo));
|
90
|
+
} else if (x.price.expo < 0) {
|
91
|
+
return fromBaseUnit(BigInt(x.price.price), Math.abs(x.price.expo));
|
92
|
+
} else {
|
93
|
+
return Number(x.price.price);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
|
97
|
+
return prices;
|
98
|
+
},
|
99
|
+
5,
|
100
|
+
200
|
101
|
+
);
|
86
102
|
|
87
103
|
for (var i = 0; i < mints.length; i++) {
|
88
104
|
PRICES[mints[i].toString()] = {
|
@@ -94,7 +110,9 @@ export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
|
94
110
|
return prices;
|
95
111
|
}
|
96
112
|
|
97
|
-
export function safeGetPrice(
|
113
|
+
export function safeGetPrice(
|
114
|
+
mint: PublicKey | UmiPublicKey | undefined
|
115
|
+
): number | undefined {
|
98
116
|
if (mint && mint?.toString() in PRICES) {
|
99
117
|
return PRICES[mint!.toString()].price;
|
100
118
|
}
|