@aspan/sdk 0.5.1 → 0.5.2
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/index.d.mts +22 -7
- package/dist/index.d.ts +22 -7
- package/dist/index.js +63 -7
- package/dist/index.mjs +63 -7
- package/package.json +1 -1
- package/src/abi/sApUSD.ts +14 -0
- package/src/bot/services/risk-keeper.ts +17 -3
- package/src/client.ts +60 -0
- package/src/index.ts +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -461,6 +461,21 @@ declare class AspanReadClient {
|
|
|
461
461
|
xBNBBalance: bigint;
|
|
462
462
|
}>;
|
|
463
463
|
getUserStabilityPoolPosition(user: Address): Promise<UserStabilityPoolPosition>;
|
|
464
|
+
/**
|
|
465
|
+
* Get realtime exchange rate using live xBNB price (not cached xBNBToApUSDRate).
|
|
466
|
+
* Use this for accurate PnL display — the on-chain exchangeRate() only updates
|
|
467
|
+
* on deposit/withdraw and doesn't reflect xBNB price changes between operations.
|
|
468
|
+
*
|
|
469
|
+
* @returns Exchange rate in 18 decimals (e.g. 1.15e18 means 1 sApUSD = 1.15 apUSD equivalent)
|
|
470
|
+
*/
|
|
471
|
+
getRealtimeExchangeRate(): Promise<{
|
|
472
|
+
exchangeRate: bigint;
|
|
473
|
+
accountedApUSD: bigint;
|
|
474
|
+
accountedXBNB: bigint;
|
|
475
|
+
xBNBPriceUSD: bigint;
|
|
476
|
+
totalValue: bigint;
|
|
477
|
+
totalSupply: bigint;
|
|
478
|
+
}>;
|
|
464
479
|
getExchangeRate(): Promise<bigint>;
|
|
465
480
|
getTotalStaked(): Promise<bigint>;
|
|
466
481
|
previewDeposit(assets: bigint): Promise<bigint>;
|
|
@@ -2829,13 +2844,13 @@ declare const BSC_ADDRESSES: {
|
|
|
2829
2844
|
readonly WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
|
2830
2845
|
};
|
|
2831
2846
|
declare const PHAROS_ADDRESSES: {
|
|
2832
|
-
readonly diamond: "
|
|
2833
|
-
readonly apUSD: "
|
|
2834
|
-
readonly xBNB: "
|
|
2835
|
-
readonly sApUSD: "
|
|
2836
|
-
readonly mockLST: "
|
|
2837
|
-
readonly mockPriceFeed: "
|
|
2838
|
-
readonly mockExchangeRate: "
|
|
2847
|
+
readonly diamond: "0x3d5ceb29BA3b4B837eddCAf53442371828933e5D";
|
|
2848
|
+
readonly apUSD: "0x054f8DB2F700883949d657Da9418c6F6B734BA18";
|
|
2849
|
+
readonly xBNB: "0x1da6F06F7195464732FB9ECa98DE8BC1c520C3a1";
|
|
2850
|
+
readonly sApUSD: "0xf94f0b76942f83Bb4BC010a942c297D18842313b";
|
|
2851
|
+
readonly mockLST: "0xDD890267E72320522E8C61aD357B650ebe4C47c5";
|
|
2852
|
+
readonly mockPriceFeed: "0x4180062949036fCe833027f0ABf7052e7485ddfC";
|
|
2853
|
+
readonly mockExchangeRate: "0xb9aDC2552cF3Fb223236CfEa1c78D277fA8fb8B6";
|
|
2839
2854
|
};
|
|
2840
2855
|
/**
|
|
2841
2856
|
* Format a bigint amount to human-readable string with decimals
|
package/dist/index.d.ts
CHANGED
|
@@ -461,6 +461,21 @@ declare class AspanReadClient {
|
|
|
461
461
|
xBNBBalance: bigint;
|
|
462
462
|
}>;
|
|
463
463
|
getUserStabilityPoolPosition(user: Address): Promise<UserStabilityPoolPosition>;
|
|
464
|
+
/**
|
|
465
|
+
* Get realtime exchange rate using live xBNB price (not cached xBNBToApUSDRate).
|
|
466
|
+
* Use this for accurate PnL display — the on-chain exchangeRate() only updates
|
|
467
|
+
* on deposit/withdraw and doesn't reflect xBNB price changes between operations.
|
|
468
|
+
*
|
|
469
|
+
* @returns Exchange rate in 18 decimals (e.g. 1.15e18 means 1 sApUSD = 1.15 apUSD equivalent)
|
|
470
|
+
*/
|
|
471
|
+
getRealtimeExchangeRate(): Promise<{
|
|
472
|
+
exchangeRate: bigint;
|
|
473
|
+
accountedApUSD: bigint;
|
|
474
|
+
accountedXBNB: bigint;
|
|
475
|
+
xBNBPriceUSD: bigint;
|
|
476
|
+
totalValue: bigint;
|
|
477
|
+
totalSupply: bigint;
|
|
478
|
+
}>;
|
|
464
479
|
getExchangeRate(): Promise<bigint>;
|
|
465
480
|
getTotalStaked(): Promise<bigint>;
|
|
466
481
|
previewDeposit(assets: bigint): Promise<bigint>;
|
|
@@ -2829,13 +2844,13 @@ declare const BSC_ADDRESSES: {
|
|
|
2829
2844
|
readonly WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c";
|
|
2830
2845
|
};
|
|
2831
2846
|
declare const PHAROS_ADDRESSES: {
|
|
2832
|
-
readonly diamond: "
|
|
2833
|
-
readonly apUSD: "
|
|
2834
|
-
readonly xBNB: "
|
|
2835
|
-
readonly sApUSD: "
|
|
2836
|
-
readonly mockLST: "
|
|
2837
|
-
readonly mockPriceFeed: "
|
|
2838
|
-
readonly mockExchangeRate: "
|
|
2847
|
+
readonly diamond: "0x3d5ceb29BA3b4B837eddCAf53442371828933e5D";
|
|
2848
|
+
readonly apUSD: "0x054f8DB2F700883949d657Da9418c6F6B734BA18";
|
|
2849
|
+
readonly xBNB: "0x1da6F06F7195464732FB9ECa98DE8BC1c520C3a1";
|
|
2850
|
+
readonly sApUSD: "0xf94f0b76942f83Bb4BC010a942c297D18842313b";
|
|
2851
|
+
readonly mockLST: "0xDD890267E72320522E8C61aD357B650ebe4C47c5";
|
|
2852
|
+
readonly mockPriceFeed: "0x4180062949036fCe833027f0ABf7052e7485ddfC";
|
|
2853
|
+
readonly mockExchangeRate: "0xb9aDC2552cF3Fb223236CfEa1c78D277fA8fb8B6";
|
|
2839
2854
|
};
|
|
2840
2855
|
/**
|
|
2841
2856
|
* Format a bigint amount to human-readable string with decimals
|
package/dist/index.js
CHANGED
|
@@ -773,6 +773,20 @@ var SApUSDABI = [
|
|
|
773
773
|
],
|
|
774
774
|
stateMutability: "view"
|
|
775
775
|
},
|
|
776
|
+
{
|
|
777
|
+
type: "function",
|
|
778
|
+
name: "accountedApUSD",
|
|
779
|
+
inputs: [],
|
|
780
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
781
|
+
stateMutability: "view"
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
type: "function",
|
|
785
|
+
name: "accountedXBNB",
|
|
786
|
+
inputs: [],
|
|
787
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
788
|
+
stateMutability: "view"
|
|
789
|
+
},
|
|
776
790
|
{
|
|
777
791
|
type: "function",
|
|
778
792
|
name: "xBNBToApUSDRate",
|
|
@@ -1269,6 +1283,48 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1269
1283
|
]);
|
|
1270
1284
|
return { shares, balance };
|
|
1271
1285
|
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Get realtime exchange rate using live xBNB price (not cached xBNBToApUSDRate).
|
|
1288
|
+
* Use this for accurate PnL display — the on-chain exchangeRate() only updates
|
|
1289
|
+
* on deposit/withdraw and doesn't reflect xBNB price changes between operations.
|
|
1290
|
+
*
|
|
1291
|
+
* @returns Exchange rate in 18 decimals (e.g. 1.15e18 means 1 sApUSD = 1.15 apUSD equivalent)
|
|
1292
|
+
*/
|
|
1293
|
+
async getRealtimeExchangeRate() {
|
|
1294
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
1295
|
+
const PRECISION2 = 10n ** 18n;
|
|
1296
|
+
const VIRTUAL_ASSETS = 10n ** 6n;
|
|
1297
|
+
const VIRTUAL_SHARES = 10n ** 6n;
|
|
1298
|
+
const [accountedApUSD, accountedXBNB, totalSupply, xBNBPriceUSD] = await Promise.all([
|
|
1299
|
+
this.publicClient.readContract({
|
|
1300
|
+
address: sApUSDAddress,
|
|
1301
|
+
abi: SApUSDABI,
|
|
1302
|
+
functionName: "accountedApUSD"
|
|
1303
|
+
}),
|
|
1304
|
+
this.publicClient.readContract({
|
|
1305
|
+
address: sApUSDAddress,
|
|
1306
|
+
abi: SApUSDABI,
|
|
1307
|
+
functionName: "accountedXBNB"
|
|
1308
|
+
}),
|
|
1309
|
+
this.publicClient.readContract({
|
|
1310
|
+
address: sApUSDAddress,
|
|
1311
|
+
abi: SApUSDABI,
|
|
1312
|
+
functionName: "totalSupply"
|
|
1313
|
+
}),
|
|
1314
|
+
this.getXBNBPriceUSD()
|
|
1315
|
+
]);
|
|
1316
|
+
const totalValue = accountedXBNB === 0n || xBNBPriceUSD === 0n ? accountedApUSD : accountedApUSD + accountedXBNB * xBNBPriceUSD / PRECISION2;
|
|
1317
|
+
const supply = totalSupply + VIRTUAL_SHARES;
|
|
1318
|
+
const exchangeRate = supply === 0n ? PRECISION2 : (totalValue + VIRTUAL_ASSETS) * PRECISION2 / supply;
|
|
1319
|
+
return {
|
|
1320
|
+
exchangeRate,
|
|
1321
|
+
accountedApUSD,
|
|
1322
|
+
accountedXBNB,
|
|
1323
|
+
xBNBPriceUSD,
|
|
1324
|
+
totalValue,
|
|
1325
|
+
totalSupply
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1272
1328
|
async getExchangeRate() {
|
|
1273
1329
|
try {
|
|
1274
1330
|
return await this.publicClient.readContract({
|
|
@@ -3015,13 +3071,13 @@ var BSC_ADDRESSES = {
|
|
|
3015
3071
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
|
|
3016
3072
|
};
|
|
3017
3073
|
var PHAROS_ADDRESSES = {
|
|
3018
|
-
diamond: "
|
|
3019
|
-
apUSD: "
|
|
3020
|
-
xBNB: "
|
|
3021
|
-
sApUSD: "
|
|
3022
|
-
mockLST: "
|
|
3023
|
-
mockPriceFeed: "
|
|
3024
|
-
mockExchangeRate: "
|
|
3074
|
+
diamond: "0x3d5ceb29BA3b4B837eddCAf53442371828933e5D",
|
|
3075
|
+
apUSD: "0x054f8DB2F700883949d657Da9418c6F6B734BA18",
|
|
3076
|
+
xBNB: "0x1da6F06F7195464732FB9ECa98DE8BC1c520C3a1",
|
|
3077
|
+
sApUSD: "0xf94f0b76942f83Bb4BC010a942c297D18842313b",
|
|
3078
|
+
mockLST: "0xDD890267E72320522E8C61aD357B650ebe4C47c5",
|
|
3079
|
+
mockPriceFeed: "0x4180062949036fCe833027f0ABf7052e7485ddfC",
|
|
3080
|
+
mockExchangeRate: "0xb9aDC2552cF3Fb223236CfEa1c78D277fA8fb8B6"
|
|
3025
3081
|
};
|
|
3026
3082
|
function formatAmount(amount, decimals = 4) {
|
|
3027
3083
|
const divisor = 10n ** BigInt(18 - decimals);
|
package/dist/index.mjs
CHANGED
|
@@ -715,6 +715,20 @@ var SApUSDABI = [
|
|
|
715
715
|
],
|
|
716
716
|
stateMutability: "view"
|
|
717
717
|
},
|
|
718
|
+
{
|
|
719
|
+
type: "function",
|
|
720
|
+
name: "accountedApUSD",
|
|
721
|
+
inputs: [],
|
|
722
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
723
|
+
stateMutability: "view"
|
|
724
|
+
},
|
|
725
|
+
{
|
|
726
|
+
type: "function",
|
|
727
|
+
name: "accountedXBNB",
|
|
728
|
+
inputs: [],
|
|
729
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
730
|
+
stateMutability: "view"
|
|
731
|
+
},
|
|
718
732
|
{
|
|
719
733
|
type: "function",
|
|
720
734
|
name: "xBNBToApUSDRate",
|
|
@@ -1211,6 +1225,48 @@ var AspanReadClient = class _AspanReadClient {
|
|
|
1211
1225
|
]);
|
|
1212
1226
|
return { shares, balance };
|
|
1213
1227
|
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Get realtime exchange rate using live xBNB price (not cached xBNBToApUSDRate).
|
|
1230
|
+
* Use this for accurate PnL display — the on-chain exchangeRate() only updates
|
|
1231
|
+
* on deposit/withdraw and doesn't reflect xBNB price changes between operations.
|
|
1232
|
+
*
|
|
1233
|
+
* @returns Exchange rate in 18 decimals (e.g. 1.15e18 means 1 sApUSD = 1.15 apUSD equivalent)
|
|
1234
|
+
*/
|
|
1235
|
+
async getRealtimeExchangeRate() {
|
|
1236
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
1237
|
+
const PRECISION2 = 10n ** 18n;
|
|
1238
|
+
const VIRTUAL_ASSETS = 10n ** 6n;
|
|
1239
|
+
const VIRTUAL_SHARES = 10n ** 6n;
|
|
1240
|
+
const [accountedApUSD, accountedXBNB, totalSupply, xBNBPriceUSD] = await Promise.all([
|
|
1241
|
+
this.publicClient.readContract({
|
|
1242
|
+
address: sApUSDAddress,
|
|
1243
|
+
abi: SApUSDABI,
|
|
1244
|
+
functionName: "accountedApUSD"
|
|
1245
|
+
}),
|
|
1246
|
+
this.publicClient.readContract({
|
|
1247
|
+
address: sApUSDAddress,
|
|
1248
|
+
abi: SApUSDABI,
|
|
1249
|
+
functionName: "accountedXBNB"
|
|
1250
|
+
}),
|
|
1251
|
+
this.publicClient.readContract({
|
|
1252
|
+
address: sApUSDAddress,
|
|
1253
|
+
abi: SApUSDABI,
|
|
1254
|
+
functionName: "totalSupply"
|
|
1255
|
+
}),
|
|
1256
|
+
this.getXBNBPriceUSD()
|
|
1257
|
+
]);
|
|
1258
|
+
const totalValue = accountedXBNB === 0n || xBNBPriceUSD === 0n ? accountedApUSD : accountedApUSD + accountedXBNB * xBNBPriceUSD / PRECISION2;
|
|
1259
|
+
const supply = totalSupply + VIRTUAL_SHARES;
|
|
1260
|
+
const exchangeRate = supply === 0n ? PRECISION2 : (totalValue + VIRTUAL_ASSETS) * PRECISION2 / supply;
|
|
1261
|
+
return {
|
|
1262
|
+
exchangeRate,
|
|
1263
|
+
accountedApUSD,
|
|
1264
|
+
accountedXBNB,
|
|
1265
|
+
xBNBPriceUSD,
|
|
1266
|
+
totalValue,
|
|
1267
|
+
totalSupply
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1214
1270
|
async getExchangeRate() {
|
|
1215
1271
|
try {
|
|
1216
1272
|
return await this.publicClient.readContract({
|
|
@@ -2962,13 +3018,13 @@ var BSC_ADDRESSES = {
|
|
|
2962
3018
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
|
|
2963
3019
|
};
|
|
2964
3020
|
var PHAROS_ADDRESSES = {
|
|
2965
|
-
diamond: "
|
|
2966
|
-
apUSD: "
|
|
2967
|
-
xBNB: "
|
|
2968
|
-
sApUSD: "
|
|
2969
|
-
mockLST: "
|
|
2970
|
-
mockPriceFeed: "
|
|
2971
|
-
mockExchangeRate: "
|
|
3021
|
+
diamond: "0x3d5ceb29BA3b4B837eddCAf53442371828933e5D",
|
|
3022
|
+
apUSD: "0x054f8DB2F700883949d657Da9418c6F6B734BA18",
|
|
3023
|
+
xBNB: "0x1da6F06F7195464732FB9ECa98DE8BC1c520C3a1",
|
|
3024
|
+
sApUSD: "0xf94f0b76942f83Bb4BC010a942c297D18842313b",
|
|
3025
|
+
mockLST: "0xDD890267E72320522E8C61aD357B650ebe4C47c5",
|
|
3026
|
+
mockPriceFeed: "0x4180062949036fCe833027f0ABf7052e7485ddfC",
|
|
3027
|
+
mockExchangeRate: "0xb9aDC2552cF3Fb223236CfEa1c78D277fA8fb8B6"
|
|
2972
3028
|
};
|
|
2973
3029
|
function formatAmount(amount, decimals = 4) {
|
|
2974
3030
|
const divisor = 10n ** BigInt(18 - decimals);
|
package/package.json
CHANGED
package/src/abi/sApUSD.ts
CHANGED
|
@@ -64,6 +64,20 @@ export const SApUSDABI = [
|
|
|
64
64
|
],
|
|
65
65
|
stateMutability: "view"
|
|
66
66
|
},
|
|
67
|
+
{
|
|
68
|
+
type: "function",
|
|
69
|
+
name: "accountedApUSD",
|
|
70
|
+
inputs: [],
|
|
71
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
72
|
+
stateMutability: "view"
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: "function",
|
|
76
|
+
name: "accountedXBNB",
|
|
77
|
+
inputs: [],
|
|
78
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
79
|
+
stateMutability: "view"
|
|
80
|
+
},
|
|
67
81
|
{
|
|
68
82
|
type: "function",
|
|
69
83
|
name: "xBNBToApUSDRate",
|
|
@@ -318,11 +318,25 @@ export class RiskKeeperService {
|
|
|
318
318
|
|
|
319
319
|
this.state.isProcessing = true;
|
|
320
320
|
|
|
321
|
-
//
|
|
322
|
-
|
|
321
|
+
// Contract allows full clean when vault xBNB <= 10 xBNB (dust exemption)
|
|
322
|
+
// Otherwise capped at 10% per call (MAX_CLEAN_PERCENT_BPS = 1000)
|
|
323
|
+
const DUST_THRESHOLD = 10n * 10n ** 18n; // 10 xBNB — must match contract DUST_CLEAN_THRESHOLD
|
|
324
|
+
const FULL_CLEAN_THRESHOLD = 1n * 10n ** 18n; // 1 xBNB — below this, clean everything
|
|
325
|
+
let cleanAmount: bigint;
|
|
326
|
+
|
|
327
|
+
if (vaultState.xBNBAmount <= FULL_CLEAN_THRESHOLD) {
|
|
328
|
+
// Less than 1 xBNB remaining — clean all to avoid infinite tiny trades
|
|
329
|
+
cleanAmount = vaultState.xBNBAmount;
|
|
330
|
+
console.log(`[RiskKeeper] Below 1 xBNB (${Number(vaultState.xBNBAmount) / 1e18}), cleaning all in one shot`);
|
|
331
|
+
} else if (vaultState.xBNBAmount <= DUST_THRESHOLD) {
|
|
332
|
+
cleanAmount = vaultState.xBNBAmount;
|
|
333
|
+
console.log(`[RiskKeeper] Dust amount (${Number(vaultState.xBNBAmount) / 1e18} xBNB <= 10), cleaning all in one shot`);
|
|
334
|
+
} else {
|
|
335
|
+
cleanAmount = (vaultState.xBNBAmount * BigInt(this.TWAP_PERCENTAGE)) / 100n;
|
|
336
|
+
}
|
|
323
337
|
|
|
324
338
|
if (cleanAmount === 0n) {
|
|
325
|
-
console.log("[RiskKeeper] Clean amount
|
|
339
|
+
console.log("[RiskKeeper] Clean amount rounds to 0, skipping");
|
|
326
340
|
return;
|
|
327
341
|
}
|
|
328
342
|
|
package/src/client.ts
CHANGED
|
@@ -551,6 +551,66 @@ export class AspanReadClient {
|
|
|
551
551
|
return { shares, balance };
|
|
552
552
|
}
|
|
553
553
|
|
|
554
|
+
/**
|
|
555
|
+
* Get realtime exchange rate using live xBNB price (not cached xBNBToApUSDRate).
|
|
556
|
+
* Use this for accurate PnL display — the on-chain exchangeRate() only updates
|
|
557
|
+
* on deposit/withdraw and doesn't reflect xBNB price changes between operations.
|
|
558
|
+
*
|
|
559
|
+
* @returns Exchange rate in 18 decimals (e.g. 1.15e18 means 1 sApUSD = 1.15 apUSD equivalent)
|
|
560
|
+
*/
|
|
561
|
+
async getRealtimeExchangeRate(): Promise<{
|
|
562
|
+
exchangeRate: bigint;
|
|
563
|
+
accountedApUSD: bigint;
|
|
564
|
+
accountedXBNB: bigint;
|
|
565
|
+
xBNBPriceUSD: bigint;
|
|
566
|
+
totalValue: bigint;
|
|
567
|
+
totalSupply: bigint;
|
|
568
|
+
}> {
|
|
569
|
+
const sApUSDAddress = await this.getSApUSD();
|
|
570
|
+
const PRECISION = 10n ** 18n;
|
|
571
|
+
const VIRTUAL_ASSETS = 10n ** 6n;
|
|
572
|
+
const VIRTUAL_SHARES = 10n ** 6n;
|
|
573
|
+
|
|
574
|
+
const [accountedApUSD, accountedXBNB, totalSupply, xBNBPriceUSD] = await Promise.all([
|
|
575
|
+
this.publicClient.readContract({
|
|
576
|
+
address: sApUSDAddress,
|
|
577
|
+
abi: SApUSDABI,
|
|
578
|
+
functionName: "accountedApUSD",
|
|
579
|
+
}) as Promise<bigint>,
|
|
580
|
+
this.publicClient.readContract({
|
|
581
|
+
address: sApUSDAddress,
|
|
582
|
+
abi: SApUSDABI,
|
|
583
|
+
functionName: "accountedXBNB",
|
|
584
|
+
}) as Promise<bigint>,
|
|
585
|
+
this.publicClient.readContract({
|
|
586
|
+
address: sApUSDAddress,
|
|
587
|
+
abi: SApUSDABI,
|
|
588
|
+
functionName: "totalSupply",
|
|
589
|
+
}) as Promise<bigint>,
|
|
590
|
+
this.getXBNBPriceUSD(),
|
|
591
|
+
]);
|
|
592
|
+
|
|
593
|
+
// _totalValue = accountedApUSD + (accountedXBNB * xBNBPrice) / 1e18
|
|
594
|
+
const totalValue = accountedXBNB === 0n || xBNBPriceUSD === 0n
|
|
595
|
+
? accountedApUSD
|
|
596
|
+
: accountedApUSD + (accountedXBNB * xBNBPriceUSD) / PRECISION;
|
|
597
|
+
|
|
598
|
+
// exchangeRate = (totalValue + VIRTUAL_ASSETS) * 1e18 / (totalSupply + VIRTUAL_SHARES)
|
|
599
|
+
const supply = totalSupply + VIRTUAL_SHARES;
|
|
600
|
+
const exchangeRate = supply === 0n
|
|
601
|
+
? PRECISION
|
|
602
|
+
: ((totalValue + VIRTUAL_ASSETS) * PRECISION) / supply;
|
|
603
|
+
|
|
604
|
+
return {
|
|
605
|
+
exchangeRate,
|
|
606
|
+
accountedApUSD,
|
|
607
|
+
accountedXBNB,
|
|
608
|
+
xBNBPriceUSD,
|
|
609
|
+
totalValue,
|
|
610
|
+
totalSupply,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
|
|
554
614
|
async getExchangeRate(): Promise<bigint> {
|
|
555
615
|
try {
|
|
556
616
|
return await this.publicClient.readContract({
|
package/src/index.ts
CHANGED
|
@@ -134,13 +134,13 @@ export const BSC_ADDRESSES = {
|
|
|
134
134
|
} as const;
|
|
135
135
|
|
|
136
136
|
export const PHAROS_ADDRESSES = {
|
|
137
|
-
diamond: "
|
|
138
|
-
apUSD: "
|
|
139
|
-
xBNB: "
|
|
140
|
-
sApUSD: "
|
|
141
|
-
mockLST: "
|
|
142
|
-
mockPriceFeed: "
|
|
143
|
-
mockExchangeRate: "
|
|
137
|
+
diamond: "0x3d5ceb29BA3b4B837eddCAf53442371828933e5D" as const,
|
|
138
|
+
apUSD: "0x054f8DB2F700883949d657Da9418c6F6B734BA18" as const,
|
|
139
|
+
xBNB: "0x1da6F06F7195464732FB9ECa98DE8BC1c520C3a1" as const,
|
|
140
|
+
sApUSD: "0xf94f0b76942f83Bb4BC010a942c297D18842313b" as const,
|
|
141
|
+
mockLST: "0xDD890267E72320522E8C61aD357B650ebe4C47c5" as const,
|
|
142
|
+
mockPriceFeed: "0x4180062949036fCe833027f0ABf7052e7485ddfC" as const,
|
|
143
|
+
mockExchangeRate: "0xb9aDC2552cF3Fb223236CfEa1c78D277fA8fb8B6" as const,
|
|
144
144
|
} as const;
|
|
145
145
|
|
|
146
146
|
// ============ Utility Functions ============
|