@strkfarm/sdk 1.0.24 → 1.0.26
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.browser.global.js +40 -34
- package/dist/index.browser.mjs +40 -34
- package/dist/index.d.ts +21 -0
- package/dist/index.js +40 -34
- package/dist/index.mjs +40 -34
- package/package.json +1 -1
- package/src/strategies/vesu-rebalance.ts +48 -34
|
@@ -38661,6 +38661,45 @@ var strkfarm_risk_engine = (() => {
|
|
|
38661
38661
|
}).filter((p) => p !== null);
|
|
38662
38662
|
return pools;
|
|
38663
38663
|
}
|
|
38664
|
+
async getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI) {
|
|
38665
|
+
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num_exports.getDecimalString(p.pool_id.address.toString()));
|
|
38666
|
+
const _pool = pools.find((d) => {
|
|
38667
|
+
logger.verbose(`pool check: ${d.id == num_exports.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num_exports.getDecimalString(p.pool_id.address.toString())}`);
|
|
38668
|
+
return d.id == num_exports.getDecimalString(p.pool_id.address.toString());
|
|
38669
|
+
});
|
|
38670
|
+
logger.verbose(`pool: ${JSON.stringify(_pool)}`);
|
|
38671
|
+
logger.verbose(typeof _pool);
|
|
38672
|
+
logger.verbose(`name: ${_pool?.name}`);
|
|
38673
|
+
if (!_pool) {
|
|
38674
|
+
throw new Error(`Pool ${p.pool_id.address.toString()} not found`);
|
|
38675
|
+
}
|
|
38676
|
+
const assetInfo = _pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
38677
|
+
let vTokenContract = new Contract(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
38678
|
+
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
38679
|
+
const assets = await vTokenContract.convert_to_assets(uint256_exports.bnToUint256(bal.toString()));
|
|
38680
|
+
const item = {
|
|
38681
|
+
pool_id: p.pool_id,
|
|
38682
|
+
pool_name: _pool?.name,
|
|
38683
|
+
max_weight: p.max_weight,
|
|
38684
|
+
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
38685
|
+
v_token: p.v_token,
|
|
38686
|
+
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
38687
|
+
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
38688
|
+
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
38689
|
+
baseApy: 0,
|
|
38690
|
+
defiSpringApy: 0,
|
|
38691
|
+
netApy: 0
|
|
38692
|
+
} : {
|
|
38693
|
+
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
38694
|
+
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
38695
|
+
netApy: 0
|
|
38696
|
+
},
|
|
38697
|
+
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
38698
|
+
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
38699
|
+
};
|
|
38700
|
+
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
38701
|
+
return item;
|
|
38702
|
+
}
|
|
38664
38703
|
/**
|
|
38665
38704
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
38666
38705
|
* 1. Contract's allowed pools
|
|
@@ -38699,40 +38738,7 @@ var strkfarm_risk_engine = (() => {
|
|
|
38699
38738
|
isErrorPoolsAPI = true;
|
|
38700
38739
|
}
|
|
38701
38740
|
const totalAssets = (await this.getTVL()).amount;
|
|
38702
|
-
const info = allowedPools.map(
|
|
38703
|
-
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num_exports.getDecimalString(p.pool_id.address.toString()));
|
|
38704
|
-
const pool = pools.find((d) => {
|
|
38705
|
-
logger.verbose(`pool check: ${d.id == num_exports.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num_exports.getDecimalString(p.pool_id.address.toString())}`);
|
|
38706
|
-
return d.id == num_exports.getDecimalString(p.pool_id.address.toString());
|
|
38707
|
-
});
|
|
38708
|
-
logger.verbose(`pool: ${JSON.stringify(pool)}`);
|
|
38709
|
-
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
38710
|
-
let vTokenContract = new Contract(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
38711
|
-
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
38712
|
-
const assets = await vTokenContract.convert_to_assets(uint256_exports.bnToUint256(bal.toString()));
|
|
38713
|
-
const item = {
|
|
38714
|
-
pool_id: p.pool_id,
|
|
38715
|
-
pool_name: pool.name,
|
|
38716
|
-
max_weight: p.max_weight,
|
|
38717
|
-
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
38718
|
-
v_token: p.v_token,
|
|
38719
|
-
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
38720
|
-
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
38721
|
-
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
38722
|
-
baseApy: 0,
|
|
38723
|
-
defiSpringApy: 0,
|
|
38724
|
-
netApy: 0
|
|
38725
|
-
} : {
|
|
38726
|
-
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
38727
|
-
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
38728
|
-
netApy: 0
|
|
38729
|
-
},
|
|
38730
|
-
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
38731
|
-
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
38732
|
-
};
|
|
38733
|
-
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
38734
|
-
return item;
|
|
38735
|
-
});
|
|
38741
|
+
const info = allowedPools.map((p) => this.getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI));
|
|
38736
38742
|
const data = await Promise.all(info);
|
|
38737
38743
|
return {
|
|
38738
38744
|
data,
|
package/dist/index.browser.mjs
CHANGED
|
@@ -3673,6 +3673,45 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3673
3673
|
}).filter((p) => p !== null);
|
|
3674
3674
|
return pools;
|
|
3675
3675
|
}
|
|
3676
|
+
async getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI) {
|
|
3677
|
+
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num2.getDecimalString(p.pool_id.address.toString()));
|
|
3678
|
+
const _pool = pools.find((d) => {
|
|
3679
|
+
logger.verbose(`pool check: ${d.id == num2.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num2.getDecimalString(p.pool_id.address.toString())}`);
|
|
3680
|
+
return d.id == num2.getDecimalString(p.pool_id.address.toString());
|
|
3681
|
+
});
|
|
3682
|
+
logger.verbose(`pool: ${JSON.stringify(_pool)}`);
|
|
3683
|
+
logger.verbose(typeof _pool);
|
|
3684
|
+
logger.verbose(`name: ${_pool?.name}`);
|
|
3685
|
+
if (!_pool) {
|
|
3686
|
+
throw new Error(`Pool ${p.pool_id.address.toString()} not found`);
|
|
3687
|
+
}
|
|
3688
|
+
const assetInfo = _pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3689
|
+
let vTokenContract = new Contract4(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3690
|
+
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3691
|
+
const assets = await vTokenContract.convert_to_assets(uint2563.bnToUint256(bal.toString()));
|
|
3692
|
+
const item = {
|
|
3693
|
+
pool_id: p.pool_id,
|
|
3694
|
+
pool_name: _pool?.name,
|
|
3695
|
+
max_weight: p.max_weight,
|
|
3696
|
+
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3697
|
+
v_token: p.v_token,
|
|
3698
|
+
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3699
|
+
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3700
|
+
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3701
|
+
baseApy: 0,
|
|
3702
|
+
defiSpringApy: 0,
|
|
3703
|
+
netApy: 0
|
|
3704
|
+
} : {
|
|
3705
|
+
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3706
|
+
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3707
|
+
netApy: 0
|
|
3708
|
+
},
|
|
3709
|
+
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3710
|
+
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3711
|
+
};
|
|
3712
|
+
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3713
|
+
return item;
|
|
3714
|
+
}
|
|
3676
3715
|
/**
|
|
3677
3716
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
3678
3717
|
* 1. Contract's allowed pools
|
|
@@ -3711,40 +3750,7 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3711
3750
|
isErrorPoolsAPI = true;
|
|
3712
3751
|
}
|
|
3713
3752
|
const totalAssets = (await this.getTVL()).amount;
|
|
3714
|
-
const info = allowedPools.map(
|
|
3715
|
-
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num2.getDecimalString(p.pool_id.address.toString()));
|
|
3716
|
-
const pool = pools.find((d) => {
|
|
3717
|
-
logger.verbose(`pool check: ${d.id == num2.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num2.getDecimalString(p.pool_id.address.toString())}`);
|
|
3718
|
-
return d.id == num2.getDecimalString(p.pool_id.address.toString());
|
|
3719
|
-
});
|
|
3720
|
-
logger.verbose(`pool: ${JSON.stringify(pool)}`);
|
|
3721
|
-
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3722
|
-
let vTokenContract = new Contract4(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3723
|
-
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3724
|
-
const assets = await vTokenContract.convert_to_assets(uint2563.bnToUint256(bal.toString()));
|
|
3725
|
-
const item = {
|
|
3726
|
-
pool_id: p.pool_id,
|
|
3727
|
-
pool_name: pool.name,
|
|
3728
|
-
max_weight: p.max_weight,
|
|
3729
|
-
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3730
|
-
v_token: p.v_token,
|
|
3731
|
-
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3732
|
-
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3733
|
-
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3734
|
-
baseApy: 0,
|
|
3735
|
-
defiSpringApy: 0,
|
|
3736
|
-
netApy: 0
|
|
3737
|
-
} : {
|
|
3738
|
-
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3739
|
-
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3740
|
-
netApy: 0
|
|
3741
|
-
},
|
|
3742
|
-
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3743
|
-
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3744
|
-
};
|
|
3745
|
-
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3746
|
-
return item;
|
|
3747
|
-
});
|
|
3753
|
+
const info = allowedPools.map((p) => this.getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI));
|
|
3748
3754
|
const data = await Promise.all(info);
|
|
3749
3755
|
return {
|
|
3750
3756
|
data,
|
package/dist/index.d.ts
CHANGED
|
@@ -395,6 +395,11 @@ declare class BaseStrategy<TVLInfo, ActionInfo> {
|
|
|
395
395
|
withdrawCall(amountInfo: ActionInfo, receiver: ContractAddr, owner: ContractAddr): Call[];
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
+
interface PoolProps {
|
|
399
|
+
pool_id: ContractAddr;
|
|
400
|
+
max_weight: number;
|
|
401
|
+
v_token: ContractAddr;
|
|
402
|
+
}
|
|
398
403
|
interface Change {
|
|
399
404
|
pool_id: ContractAddr;
|
|
400
405
|
changeAmt: Web3Number;
|
|
@@ -488,6 +493,22 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
|
|
|
488
493
|
usdValue: number;
|
|
489
494
|
}>;
|
|
490
495
|
static getAllPossibleVerifiedPools(asset: ContractAddr): Promise<any>;
|
|
496
|
+
getPoolInfo(p: PoolProps, pools: any[], vesuPositions: any[], totalAssets: Web3Number, isErrorPositionsAPI: boolean, isErrorPoolsAPI: boolean): Promise<{
|
|
497
|
+
pool_id: ContractAddr;
|
|
498
|
+
pool_name: any;
|
|
499
|
+
max_weight: number;
|
|
500
|
+
current_weight: number;
|
|
501
|
+
v_token: ContractAddr;
|
|
502
|
+
amount: Web3Number;
|
|
503
|
+
usdValue: Web3Number;
|
|
504
|
+
APY: {
|
|
505
|
+
baseApy: number;
|
|
506
|
+
defiSpringApy: number;
|
|
507
|
+
netApy: number;
|
|
508
|
+
};
|
|
509
|
+
currentUtilization: number;
|
|
510
|
+
maxUtilization: number;
|
|
511
|
+
}>;
|
|
491
512
|
/**
|
|
492
513
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
493
514
|
* 1. Contract's allowed pools
|
package/dist/index.js
CHANGED
|
@@ -3761,6 +3761,45 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3761
3761
|
}).filter((p) => p !== null);
|
|
3762
3762
|
return pools;
|
|
3763
3763
|
}
|
|
3764
|
+
async getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI) {
|
|
3765
|
+
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === import_starknet7.num.getDecimalString(p.pool_id.address.toString()));
|
|
3766
|
+
const _pool = pools.find((d) => {
|
|
3767
|
+
logger.verbose(`pool check: ${d.id == import_starknet7.num.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${import_starknet7.num.getDecimalString(p.pool_id.address.toString())}`);
|
|
3768
|
+
return d.id == import_starknet7.num.getDecimalString(p.pool_id.address.toString());
|
|
3769
|
+
});
|
|
3770
|
+
logger.verbose(`pool: ${JSON.stringify(_pool)}`);
|
|
3771
|
+
logger.verbose(typeof _pool);
|
|
3772
|
+
logger.verbose(`name: ${_pool?.name}`);
|
|
3773
|
+
if (!_pool) {
|
|
3774
|
+
throw new Error(`Pool ${p.pool_id.address.toString()} not found`);
|
|
3775
|
+
}
|
|
3776
|
+
const assetInfo = _pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3777
|
+
let vTokenContract = new import_starknet7.Contract(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3778
|
+
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3779
|
+
const assets = await vTokenContract.convert_to_assets(import_starknet7.uint256.bnToUint256(bal.toString()));
|
|
3780
|
+
const item = {
|
|
3781
|
+
pool_id: p.pool_id,
|
|
3782
|
+
pool_name: _pool?.name,
|
|
3783
|
+
max_weight: p.max_weight,
|
|
3784
|
+
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3785
|
+
v_token: p.v_token,
|
|
3786
|
+
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3787
|
+
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3788
|
+
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3789
|
+
baseApy: 0,
|
|
3790
|
+
defiSpringApy: 0,
|
|
3791
|
+
netApy: 0
|
|
3792
|
+
} : {
|
|
3793
|
+
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3794
|
+
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3795
|
+
netApy: 0
|
|
3796
|
+
},
|
|
3797
|
+
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3798
|
+
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3799
|
+
};
|
|
3800
|
+
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3801
|
+
return item;
|
|
3802
|
+
}
|
|
3764
3803
|
/**
|
|
3765
3804
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
3766
3805
|
* 1. Contract's allowed pools
|
|
@@ -3799,40 +3838,7 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3799
3838
|
isErrorPoolsAPI = true;
|
|
3800
3839
|
}
|
|
3801
3840
|
const totalAssets = (await this.getTVL()).amount;
|
|
3802
|
-
const info = allowedPools.map(
|
|
3803
|
-
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === import_starknet7.num.getDecimalString(p.pool_id.address.toString()));
|
|
3804
|
-
const pool = pools.find((d) => {
|
|
3805
|
-
logger.verbose(`pool check: ${d.id == import_starknet7.num.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${import_starknet7.num.getDecimalString(p.pool_id.address.toString())}`);
|
|
3806
|
-
return d.id == import_starknet7.num.getDecimalString(p.pool_id.address.toString());
|
|
3807
|
-
});
|
|
3808
|
-
logger.verbose(`pool: ${JSON.stringify(pool)}`);
|
|
3809
|
-
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3810
|
-
let vTokenContract = new import_starknet7.Contract(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3811
|
-
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3812
|
-
const assets = await vTokenContract.convert_to_assets(import_starknet7.uint256.bnToUint256(bal.toString()));
|
|
3813
|
-
const item = {
|
|
3814
|
-
pool_id: p.pool_id,
|
|
3815
|
-
pool_name: pool.name,
|
|
3816
|
-
max_weight: p.max_weight,
|
|
3817
|
-
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3818
|
-
v_token: p.v_token,
|
|
3819
|
-
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3820
|
-
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3821
|
-
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3822
|
-
baseApy: 0,
|
|
3823
|
-
defiSpringApy: 0,
|
|
3824
|
-
netApy: 0
|
|
3825
|
-
} : {
|
|
3826
|
-
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3827
|
-
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3828
|
-
netApy: 0
|
|
3829
|
-
},
|
|
3830
|
-
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3831
|
-
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3832
|
-
};
|
|
3833
|
-
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3834
|
-
return item;
|
|
3835
|
-
});
|
|
3841
|
+
const info = allowedPools.map((p) => this.getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI));
|
|
3836
3842
|
const data = await Promise.all(info);
|
|
3837
3843
|
return {
|
|
3838
3844
|
data,
|
package/dist/index.mjs
CHANGED
|
@@ -3693,6 +3693,45 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3693
3693
|
}).filter((p) => p !== null);
|
|
3694
3694
|
return pools;
|
|
3695
3695
|
}
|
|
3696
|
+
async getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI) {
|
|
3697
|
+
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num2.getDecimalString(p.pool_id.address.toString()));
|
|
3698
|
+
const _pool = pools.find((d) => {
|
|
3699
|
+
logger.verbose(`pool check: ${d.id == num2.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num2.getDecimalString(p.pool_id.address.toString())}`);
|
|
3700
|
+
return d.id == num2.getDecimalString(p.pool_id.address.toString());
|
|
3701
|
+
});
|
|
3702
|
+
logger.verbose(`pool: ${JSON.stringify(_pool)}`);
|
|
3703
|
+
logger.verbose(typeof _pool);
|
|
3704
|
+
logger.verbose(`name: ${_pool?.name}`);
|
|
3705
|
+
if (!_pool) {
|
|
3706
|
+
throw new Error(`Pool ${p.pool_id.address.toString()} not found`);
|
|
3707
|
+
}
|
|
3708
|
+
const assetInfo = _pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3709
|
+
let vTokenContract = new Contract4(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3710
|
+
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3711
|
+
const assets = await vTokenContract.convert_to_assets(uint2563.bnToUint256(bal.toString()));
|
|
3712
|
+
const item = {
|
|
3713
|
+
pool_id: p.pool_id,
|
|
3714
|
+
pool_name: _pool?.name,
|
|
3715
|
+
max_weight: p.max_weight,
|
|
3716
|
+
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3717
|
+
v_token: p.v_token,
|
|
3718
|
+
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3719
|
+
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3720
|
+
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3721
|
+
baseApy: 0,
|
|
3722
|
+
defiSpringApy: 0,
|
|
3723
|
+
netApy: 0
|
|
3724
|
+
} : {
|
|
3725
|
+
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3726
|
+
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3727
|
+
netApy: 0
|
|
3728
|
+
},
|
|
3729
|
+
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3730
|
+
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3731
|
+
};
|
|
3732
|
+
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3733
|
+
return item;
|
|
3734
|
+
}
|
|
3696
3735
|
/**
|
|
3697
3736
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
3698
3737
|
* 1. Contract's allowed pools
|
|
@@ -3731,40 +3770,7 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
|
|
|
3731
3770
|
isErrorPoolsAPI = true;
|
|
3732
3771
|
}
|
|
3733
3772
|
const totalAssets = (await this.getTVL()).amount;
|
|
3734
|
-
const info = allowedPools.map(
|
|
3735
|
-
const vesuPosition = vesuPositions.find((d) => d.pool.id.toString() === num2.getDecimalString(p.pool_id.address.toString()));
|
|
3736
|
-
const pool = pools.find((d) => {
|
|
3737
|
-
logger.verbose(`pool check: ${d.id == num2.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num2.getDecimalString(p.pool_id.address.toString())}`);
|
|
3738
|
-
return d.id == num2.getDecimalString(p.pool_id.address.toString());
|
|
3739
|
-
});
|
|
3740
|
-
logger.verbose(`pool: ${JSON.stringify(pool)}`);
|
|
3741
|
-
const assetInfo = pool?.assets.find((d) => this.asset().address.eqString(d.address));
|
|
3742
|
-
let vTokenContract = new Contract4(vesu_rebalance_abi_default, p.v_token.address, this.config.provider);
|
|
3743
|
-
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
3744
|
-
const assets = await vTokenContract.convert_to_assets(uint2563.bnToUint256(bal.toString()));
|
|
3745
|
-
const item = {
|
|
3746
|
-
pool_id: p.pool_id,
|
|
3747
|
-
pool_name: pool.name,
|
|
3748
|
-
max_weight: p.max_weight,
|
|
3749
|
-
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
3750
|
-
v_token: p.v_token,
|
|
3751
|
-
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
3752
|
-
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
3753
|
-
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
3754
|
-
baseApy: 0,
|
|
3755
|
-
defiSpringApy: 0,
|
|
3756
|
-
netApy: 0
|
|
3757
|
-
} : {
|
|
3758
|
-
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
3759
|
-
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
3760
|
-
netApy: 0
|
|
3761
|
-
},
|
|
3762
|
-
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
3763
|
-
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6))
|
|
3764
|
-
};
|
|
3765
|
-
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
3766
|
-
return item;
|
|
3767
|
-
});
|
|
3773
|
+
const info = allowedPools.map((p) => this.getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI));
|
|
3768
3774
|
const data = await Promise.all(info);
|
|
3769
3775
|
return {
|
|
3770
3776
|
data,
|
package/package.json
CHANGED
|
@@ -172,6 +172,53 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
|
|
|
172
172
|
return pools;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
async getPoolInfo(
|
|
176
|
+
p: PoolProps,
|
|
177
|
+
pools: any[],
|
|
178
|
+
vesuPositions: any[],
|
|
179
|
+
totalAssets: Web3Number,
|
|
180
|
+
isErrorPositionsAPI: boolean,
|
|
181
|
+
isErrorPoolsAPI: boolean,
|
|
182
|
+
) {
|
|
183
|
+
const vesuPosition = vesuPositions.find((d: any) => d.pool.id.toString() === num.getDecimalString(p.pool_id.address.toString()));
|
|
184
|
+
const _pool = pools.find((d: any) => {
|
|
185
|
+
logger.verbose(`pool check: ${d.id == num.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num.getDecimalString(p.pool_id.address.toString())}`);
|
|
186
|
+
return d.id == num.getDecimalString(p.pool_id.address.toString());
|
|
187
|
+
});
|
|
188
|
+
logger.verbose(`pool: ${JSON.stringify(_pool)}`);
|
|
189
|
+
logger.verbose(typeof _pool);
|
|
190
|
+
logger.verbose(`name: ${_pool?.name}`);
|
|
191
|
+
if (!_pool) {
|
|
192
|
+
throw new Error(`Pool ${p.pool_id.address.toString()} not found`);
|
|
193
|
+
}
|
|
194
|
+
const assetInfo = _pool?.assets.find((d: any) => this.asset().address.eqString(d.address));
|
|
195
|
+
let vTokenContract = new Contract(VesuRebalanceAbi, p.v_token.address, this.config.provider);
|
|
196
|
+
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
197
|
+
const assets = await vTokenContract.convert_to_assets(uint256.bnToUint256(bal.toString()));
|
|
198
|
+
const item = {
|
|
199
|
+
pool_id: p.pool_id,
|
|
200
|
+
pool_name: _pool?.name,
|
|
201
|
+
max_weight: p.max_weight,
|
|
202
|
+
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
203
|
+
v_token: p.v_token,
|
|
204
|
+
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
205
|
+
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
206
|
+
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
207
|
+
baseApy: 0,
|
|
208
|
+
defiSpringApy: 0,
|
|
209
|
+
netApy: 0,
|
|
210
|
+
} : {
|
|
211
|
+
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
212
|
+
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
213
|
+
netApy: 0,
|
|
214
|
+
},
|
|
215
|
+
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
216
|
+
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6)),
|
|
217
|
+
}
|
|
218
|
+
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
219
|
+
return item;
|
|
220
|
+
}
|
|
221
|
+
|
|
175
222
|
/**
|
|
176
223
|
* Retrieves the list of allowed pools and their detailed information from multiple sources:
|
|
177
224
|
* 1. Contract's allowed pools
|
|
@@ -262,40 +309,7 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
|
|
|
262
309
|
|
|
263
310
|
const totalAssets = (await this.getTVL()).amount;
|
|
264
311
|
|
|
265
|
-
const info = allowedPools.map(
|
|
266
|
-
const vesuPosition = vesuPositions.find((d: any) => d.pool.id.toString() === num.getDecimalString(p.pool_id.address.toString()));
|
|
267
|
-
const pool = pools.find((d: any) => {
|
|
268
|
-
logger.verbose(`pool check: ${d.id == num.getDecimalString(p.pool_id.address.toString())}, id: ${d.id}, pool_id: ${num.getDecimalString(p.pool_id.address.toString())}`);
|
|
269
|
-
return d.id == num.getDecimalString(p.pool_id.address.toString());
|
|
270
|
-
});
|
|
271
|
-
logger.verbose(`pool: ${JSON.stringify(pool)}`);
|
|
272
|
-
const assetInfo = pool?.assets.find((d: any) => this.asset().address.eqString(d.address));
|
|
273
|
-
let vTokenContract = new Contract(VesuRebalanceAbi, p.v_token.address, this.config.provider);
|
|
274
|
-
const bal = await vTokenContract.balanceOf(this.address.address);
|
|
275
|
-
const assets = await vTokenContract.convert_to_assets(uint256.bnToUint256(bal.toString()));
|
|
276
|
-
const item = {
|
|
277
|
-
pool_id: p.pool_id,
|
|
278
|
-
pool_name: pool.name,
|
|
279
|
-
max_weight: p.max_weight,
|
|
280
|
-
current_weight: isErrorPositionsAPI || !vesuPosition ? 0 : Number(Web3Number.fromWei(vesuPosition.collateral.value, this.decimals()).dividedBy(totalAssets.toString()).toFixed(6)),
|
|
281
|
-
v_token: p.v_token,
|
|
282
|
-
amount: Web3Number.fromWei(assets.toString(), this.decimals()),
|
|
283
|
-
usdValue: isErrorPositionsAPI || !vesuPosition ? Web3Number.fromWei("0", this.decimals()) : Web3Number.fromWei(vesuPosition.collateral.usdPrice.value, vesuPosition.collateral.usdPrice.decimals),
|
|
284
|
-
APY: isErrorPoolsAPI || !assetInfo ? {
|
|
285
|
-
baseApy: 0,
|
|
286
|
-
defiSpringApy: 0,
|
|
287
|
-
netApy: 0,
|
|
288
|
-
} : {
|
|
289
|
-
baseApy: Number(Web3Number.fromWei(assetInfo.stats.supplyApy.value, assetInfo.stats.supplyApy.decimals).toFixed(6)),
|
|
290
|
-
defiSpringApy: Number(Web3Number.fromWei(assetInfo.stats.defiSpringSupplyApr.value, assetInfo.stats.defiSpringSupplyApr.decimals).toFixed(6)),
|
|
291
|
-
netApy: 0,
|
|
292
|
-
},
|
|
293
|
-
currentUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.stats.currentUtilization.value, assetInfo.stats.currentUtilization.decimals).toFixed(6)),
|
|
294
|
-
maxUtilization: isErrorPoolsAPI || !assetInfo ? 0 : Number(Web3Number.fromWei(assetInfo.config.maxUtilization.value, assetInfo.config.maxUtilization.decimals).toFixed(6)),
|
|
295
|
-
}
|
|
296
|
-
item.APY.netApy = item.APY.baseApy + item.APY.defiSpringApy;
|
|
297
|
-
return item;
|
|
298
|
-
});
|
|
312
|
+
const info = allowedPools.map(p => this.getPoolInfo(p, pools, vesuPositions, totalAssets, isErrorPositionsAPI, isErrorPoolsAPI));
|
|
299
313
|
const data = await Promise.all(info);
|
|
300
314
|
return {
|
|
301
315
|
data,
|