@strkfarm/sdk 1.0.56 → 1.0.58
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 +265 -84
- package/dist/index.browser.mjs +260 -67
- package/dist/index.d.ts +56 -9
- package/dist/index.js +261 -71
- package/dist/index.mjs +261 -71
- package/package.json +1 -1
- package/src/node/deployer.ts +1 -1
- package/src/notifs/telegram.ts +0 -2
- package/src/strategies/base-strategy.ts +3 -23
- package/src/strategies/sensei.ts +13 -6
- package/src/strategies/universal-adapters/baseAdapter.ts +2 -1
- package/src/strategies/universal-adapters/vesu-adapter.ts +80 -10
- package/src/strategies/universal-strategy.ts +190 -31
- package/src/utils/cacheClass.ts +29 -0
- package/src/utils/oz-merkle.ts +0 -9
package/dist/index.js
CHANGED
|
@@ -2066,7 +2066,6 @@ var import_bytes = require("@ericnordelo/strk-merkle-tree/dist/bytes");
|
|
|
2066
2066
|
var import_core = require("@ericnordelo/strk-merkle-tree/dist/core");
|
|
2067
2067
|
var import_hashes = require("@ericnordelo/strk-merkle-tree/dist/hashes");
|
|
2068
2068
|
var import_merkletree = require("@ericnordelo/strk-merkle-tree/dist/merkletree");
|
|
2069
|
-
var import_errors = require("@ericnordelo/strk-merkle-tree/src/utils/errors");
|
|
2070
2069
|
var import_starknet4 = require("starknet");
|
|
2071
2070
|
|
|
2072
2071
|
// ../node_modules/@noble/hashes/esm/_assert.js
|
|
@@ -4124,13 +4123,6 @@ var StandardMerkleTree = class _StandardMerkleTree extends import_merkletree.Mer
|
|
|
4124
4123
|
});
|
|
4125
4124
|
return new _StandardMerkleTree(tree, indexedValues, leafEncoding);
|
|
4126
4125
|
}
|
|
4127
|
-
static load(data) {
|
|
4128
|
-
(0, import_errors.validateArgument)(data.format === "standard-v1", `Unknown format '${data.format}'`);
|
|
4129
|
-
(0, import_errors.validateArgument)(data.leafEncoding !== void 0, "Expected leaf encoding");
|
|
4130
|
-
const tree = new _StandardMerkleTree(data.tree, data.values, data.leafEncoding);
|
|
4131
|
-
tree.validate();
|
|
4132
|
-
return tree;
|
|
4133
|
-
}
|
|
4134
4126
|
static verify(root, leafEncoding, leaf, proof) {
|
|
4135
4127
|
return (0, import_bytes.toHex)(root) === (0, import_core.processProof)((0, import_hashes.standardLeafHash)(leafEncoding, leaf), proof);
|
|
4136
4128
|
}
|
|
@@ -5888,23 +5880,10 @@ var vesu_rebalance_abi_default = [
|
|
|
5888
5880
|
}
|
|
5889
5881
|
];
|
|
5890
5882
|
|
|
5891
|
-
// src/
|
|
5892
|
-
var
|
|
5893
|
-
constructor(
|
|
5883
|
+
// src/utils/cacheClass.ts
|
|
5884
|
+
var CacheClass = class {
|
|
5885
|
+
constructor() {
|
|
5894
5886
|
this.cache = /* @__PURE__ */ new Map();
|
|
5895
|
-
this.config = config;
|
|
5896
|
-
}
|
|
5897
|
-
async getUserTVL(user) {
|
|
5898
|
-
throw new Error("Not implemented");
|
|
5899
|
-
}
|
|
5900
|
-
async getTVL() {
|
|
5901
|
-
throw new Error("Not implemented");
|
|
5902
|
-
}
|
|
5903
|
-
async depositCall(amountInfo, receiver) {
|
|
5904
|
-
throw new Error("Not implemented");
|
|
5905
|
-
}
|
|
5906
|
-
async withdrawCall(amountInfo, receiver, owner) {
|
|
5907
|
-
throw new Error("Not implemented");
|
|
5908
5887
|
}
|
|
5909
5888
|
setCache(key, data, ttl = 6e4) {
|
|
5910
5889
|
const timestamp = Date.now();
|
|
@@ -5925,6 +5904,27 @@ var BaseStrategy = class {
|
|
|
5925
5904
|
}
|
|
5926
5905
|
};
|
|
5927
5906
|
|
|
5907
|
+
// src/strategies/base-strategy.ts
|
|
5908
|
+
var BaseStrategy = class extends CacheClass {
|
|
5909
|
+
constructor(config) {
|
|
5910
|
+
super();
|
|
5911
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
5912
|
+
this.config = config;
|
|
5913
|
+
}
|
|
5914
|
+
async getUserTVL(user) {
|
|
5915
|
+
throw new Error("Not implemented");
|
|
5916
|
+
}
|
|
5917
|
+
async getTVL() {
|
|
5918
|
+
throw new Error("Not implemented");
|
|
5919
|
+
}
|
|
5920
|
+
async depositCall(amountInfo, receiver) {
|
|
5921
|
+
throw new Error("Not implemented");
|
|
5922
|
+
}
|
|
5923
|
+
async withdrawCall(amountInfo, receiver, owner) {
|
|
5924
|
+
throw new Error("Not implemented");
|
|
5925
|
+
}
|
|
5926
|
+
};
|
|
5927
|
+
|
|
5928
5928
|
// src/node/headless.browser.ts
|
|
5929
5929
|
var import_axios5 = __toESM(require("axios"));
|
|
5930
5930
|
async function getAPIUsingHeadlessBrowser(url) {
|
|
@@ -20394,9 +20394,8 @@ var SenseiVault = class extends BaseStrategy {
|
|
|
20394
20394
|
}
|
|
20395
20395
|
async getPositionInfo() {
|
|
20396
20396
|
const CACHE_KEY = "positionInfo";
|
|
20397
|
-
|
|
20398
|
-
|
|
20399
|
-
}
|
|
20397
|
+
const existingCacheData = this.getCache(CACHE_KEY);
|
|
20398
|
+
if (existingCacheData) return existingCacheData;
|
|
20400
20399
|
const resp = await fetch(
|
|
20401
20400
|
`${getTrovesEndpoint()}/vesu/positions?walletAddress=${this.address.address}`
|
|
20402
20401
|
);
|
|
@@ -20440,9 +20439,8 @@ var SenseiVault = class extends BaseStrategy {
|
|
|
20440
20439
|
}
|
|
20441
20440
|
async getSecondaryTokenPriceRelativeToMain(retry = 0) {
|
|
20442
20441
|
const CACHE_KEY = "xSTRKPrice";
|
|
20443
|
-
|
|
20444
|
-
|
|
20445
|
-
}
|
|
20442
|
+
const existingCacheData = this.getCache(CACHE_KEY);
|
|
20443
|
+
if (existingCacheData) return existingCacheData;
|
|
20446
20444
|
const params = {
|
|
20447
20445
|
sellTokenAddress: this.metadata.additionalInfo.secondaryToken.address.address,
|
|
20448
20446
|
buyTokenAddress: this.metadata.additionalInfo.mainToken.address.address,
|
|
@@ -20596,7 +20594,7 @@ function toBigInt(value) {
|
|
|
20596
20594
|
}
|
|
20597
20595
|
|
|
20598
20596
|
// src/strategies/universal-adapters/baseAdapter.ts
|
|
20599
|
-
var BaseAdapter = class {
|
|
20597
|
+
var BaseAdapter = class extends CacheClass {
|
|
20600
20598
|
constructSimpleLeafData(params) {
|
|
20601
20599
|
const { id, target, method, packedArguments } = params;
|
|
20602
20600
|
return {
|
|
@@ -22971,7 +22969,6 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
|
|
|
22971
22969
|
constructor(config) {
|
|
22972
22970
|
super();
|
|
22973
22971
|
this.VESU_SINGLETON = ContractAddr.from("0x000d8d6dfec4d33bfb6895de9f3852143a17c6f92fd2a21da3d6924d34870160");
|
|
22974
|
-
this.cache = {};
|
|
22975
22972
|
this.getModifyPosition = () => {
|
|
22976
22973
|
const positionData = [0n];
|
|
22977
22974
|
const packedArguments = [
|
|
@@ -23000,17 +22997,19 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
|
|
|
23000
22997
|
denomination: this.formatAmountDenominationEnum(params.collateralAmount.denomination),
|
|
23001
22998
|
value: {
|
|
23002
22999
|
abs: import_starknet14.uint256.bnToUint256(params.collateralAmount.value.abs.toWei()),
|
|
23003
|
-
is_negative: params.collateralAmount.value.is_negative
|
|
23000
|
+
is_negative: params.collateralAmount.value.abs.isZero() ? false : params.collateralAmount.value.is_negative
|
|
23004
23001
|
}
|
|
23005
23002
|
};
|
|
23003
|
+
logger.verbose(`VesuAdapter::ConstructingModify::Collateral::${JSON.stringify(_collateral)}`);
|
|
23006
23004
|
const _debt = {
|
|
23007
23005
|
amount_type: this.formatAmountTypeEnum(params.debtAmount.amount_type),
|
|
23008
23006
|
denomination: this.formatAmountDenominationEnum(params.debtAmount.denomination),
|
|
23009
23007
|
value: {
|
|
23010
23008
|
abs: import_starknet14.uint256.bnToUint256(params.debtAmount.value.abs.toWei()),
|
|
23011
|
-
is_negative: params.debtAmount.value.is_negative
|
|
23009
|
+
is_negative: params.debtAmount.value.abs.isZero() ? false : params.debtAmount.value.is_negative
|
|
23012
23010
|
}
|
|
23013
23011
|
};
|
|
23012
|
+
logger.verbose(`VesuAdapter::ConstructingModify::Debt::${JSON.stringify(_debt)}`);
|
|
23014
23013
|
const singletonContract = new import_starknet14.Contract(vesu_singleton_abi_default, this.VESU_SINGLETON.toString(), new import_starknet14.RpcProvider({ nodeUrl: "" }));
|
|
23015
23014
|
const call = singletonContract.populate("modify_position", {
|
|
23016
23015
|
params: {
|
|
@@ -23079,20 +23078,22 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
|
|
|
23079
23078
|
}
|
|
23080
23079
|
async getLTVConfig(config) {
|
|
23081
23080
|
const CACHE_KEY = "ltv_config";
|
|
23082
|
-
|
|
23083
|
-
|
|
23081
|
+
const cacheData = this.getCache(CACHE_KEY);
|
|
23082
|
+
if (cacheData) {
|
|
23083
|
+
return cacheData;
|
|
23084
23084
|
}
|
|
23085
23085
|
const output2 = await this.getVesuSingletonContract(config).call("ltv_config", [this.config.poolId.address, this.config.collateral.address.address, this.config.debt.address.address]);
|
|
23086
|
-
this.
|
|
23087
|
-
return this.
|
|
23086
|
+
this.setCache(CACHE_KEY, Number(output2.max_ltv) / 1e18, 3e5);
|
|
23087
|
+
return this.getCache(CACHE_KEY);
|
|
23088
23088
|
}
|
|
23089
23089
|
async getPositions(config) {
|
|
23090
23090
|
if (!this.pricer) {
|
|
23091
23091
|
throw new Error("Pricer is not initialized");
|
|
23092
23092
|
}
|
|
23093
23093
|
const CACHE_KEY = "positions";
|
|
23094
|
-
|
|
23095
|
-
|
|
23094
|
+
const cacheData = this.getCache(CACHE_KEY);
|
|
23095
|
+
if (cacheData) {
|
|
23096
|
+
return cacheData;
|
|
23096
23097
|
}
|
|
23097
23098
|
const output2 = await this.getVesuSingletonContract(config).call("position_unsafe", [
|
|
23098
23099
|
this.config.poolId.address,
|
|
@@ -23115,9 +23116,65 @@ var VesuAdapter = class _VesuAdapter extends BaseAdapter {
|
|
|
23115
23116
|
usdValue: debtAmount.multipliedBy(token2Price.price).toNumber(),
|
|
23116
23117
|
remarks: "Debt"
|
|
23117
23118
|
}];
|
|
23118
|
-
this.
|
|
23119
|
+
this.setCache(CACHE_KEY, value, 6e4);
|
|
23120
|
+
return value;
|
|
23121
|
+
}
|
|
23122
|
+
async getCollateralization(config) {
|
|
23123
|
+
if (!this.pricer) {
|
|
23124
|
+
throw new Error("Pricer is not initialized");
|
|
23125
|
+
}
|
|
23126
|
+
const CACHE_KEY = "collateralization";
|
|
23127
|
+
const cacheData = this.getCache(CACHE_KEY);
|
|
23128
|
+
if (cacheData) {
|
|
23129
|
+
return cacheData;
|
|
23130
|
+
}
|
|
23131
|
+
const output2 = await this.getVesuSingletonContract(config).call("check_collateralization_unsafe", [
|
|
23132
|
+
this.config.poolId.address,
|
|
23133
|
+
this.config.collateral.address.address,
|
|
23134
|
+
this.config.debt.address.address,
|
|
23135
|
+
this.config.vaultAllocator.address
|
|
23136
|
+
]);
|
|
23137
|
+
const collateralAmount = Web3Number.fromWei(output2["1"].toString(), 18);
|
|
23138
|
+
const debtAmount = Web3Number.fromWei(output2["2"].toString(), 18);
|
|
23139
|
+
const value = [{
|
|
23140
|
+
token: this.config.collateral,
|
|
23141
|
+
usdValue: collateralAmount.toNumber(),
|
|
23142
|
+
remarks: "Collateral"
|
|
23143
|
+
}, {
|
|
23144
|
+
token: this.config.debt,
|
|
23145
|
+
usdValue: debtAmount.toNumber(),
|
|
23146
|
+
remarks: "Debt"
|
|
23147
|
+
}];
|
|
23148
|
+
this.setCache(CACHE_KEY, value, 6e4);
|
|
23119
23149
|
return value;
|
|
23120
23150
|
}
|
|
23151
|
+
async getAssetPrices() {
|
|
23152
|
+
const collateralizationProm = this.getCollateralization(this.networkConfig);
|
|
23153
|
+
const positionsProm = this.getPositions(this.networkConfig);
|
|
23154
|
+
const ltvProm = this.getLTVConfig(this.networkConfig);
|
|
23155
|
+
const output2 = await Promise.all([collateralizationProm, positionsProm, ltvProm]);
|
|
23156
|
+
const [collateralization, positions, ltv] = output2;
|
|
23157
|
+
const collateralTokenAmount = positions[0].amount;
|
|
23158
|
+
const collateralUSDAmount = collateralization[0].usdValue;
|
|
23159
|
+
const collateralPrice = collateralUSDAmount / collateralTokenAmount.toNumber();
|
|
23160
|
+
const debtTokenAmount = positions[1].amount;
|
|
23161
|
+
const debtUSDAmount = collateralization[1].usdValue;
|
|
23162
|
+
const debtPrice = debtUSDAmount / debtTokenAmount.toNumber();
|
|
23163
|
+
return {
|
|
23164
|
+
collateralTokenAmount,
|
|
23165
|
+
collateralUSDAmount,
|
|
23166
|
+
collateralPrice,
|
|
23167
|
+
debtTokenAmount,
|
|
23168
|
+
debtUSDAmount,
|
|
23169
|
+
debtPrice,
|
|
23170
|
+
ltv
|
|
23171
|
+
};
|
|
23172
|
+
}
|
|
23173
|
+
async getHealthFactor() {
|
|
23174
|
+
const ltv = await this.getLTVConfig(this.networkConfig);
|
|
23175
|
+
const collateralisation = await this.getCollateralization(this.networkConfig);
|
|
23176
|
+
return collateralisation[0].usdValue * ltv / collateralisation[1].usdValue;
|
|
23177
|
+
}
|
|
23121
23178
|
static async getVesuPools(retry = 0) {
|
|
23122
23179
|
const CACHE_KEY = "VESU_POOLS";
|
|
23123
23180
|
const cacheValue = Global.getGlobalCache(CACHE_KEY);
|
|
@@ -25489,19 +25546,32 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25489
25546
|
const debtAsset1 = pool1.assets.find((a) => a.symbol === vesuAdapter1.config.debt.symbol)?.stats;
|
|
25490
25547
|
const collateralAsset2 = pool2.assets.find((a) => a.symbol === vesuAdapter2.config.collateral.symbol)?.stats;
|
|
25491
25548
|
const debtAsset2 = pool2.assets.find((a) => a.symbol === vesuAdapter2.config.debt.symbol)?.stats;
|
|
25492
|
-
const collateral1APY = Number(collateralAsset1.supplyApy.value) / 1e18
|
|
25549
|
+
const collateral1APY = Number(collateralAsset1.supplyApy.value) / 1e18;
|
|
25493
25550
|
const debt1APY = Number(debtAsset1.borrowApr.value) / 1e18;
|
|
25494
|
-
const collateral2APY = Number(collateralAsset2.supplyApy.value) / 1e18
|
|
25551
|
+
const collateral2APY = Number(collateralAsset2.supplyApy.value) / 1e18;
|
|
25495
25552
|
const debt2APY = Number(debtAsset2.borrowApr.value) / 1e18;
|
|
25496
|
-
const apys = [collateral1APY, debt1APY, collateral2APY, debt2APY];
|
|
25497
25553
|
const positions = await this.getVaultPositions();
|
|
25498
|
-
|
|
25499
|
-
const
|
|
25500
|
-
|
|
25501
|
-
|
|
25502
|
-
const
|
|
25503
|
-
const
|
|
25504
|
-
|
|
25554
|
+
const weights = positions.map((p, index) => p.usdValue * (index % 2 == 0 ? 1 : -1));
|
|
25555
|
+
const baseAPYs = [collateral1APY, debt1APY, collateral2APY, debt2APY];
|
|
25556
|
+
assert(positions.length == baseAPYs.length, "Positions and APYs length mismatch");
|
|
25557
|
+
const rewardAPYs = [Number(collateralAsset1.defiSpringSupplyApr.value) / 1e18, 0, Number(collateralAsset2.defiSpringSupplyApr.value) / 1e18, 0];
|
|
25558
|
+
const baseAPY = this.computeAPY(baseAPYs, weights);
|
|
25559
|
+
const rewardAPY = this.computeAPY(rewardAPYs, weights);
|
|
25560
|
+
const apys = [...baseAPYs, ...rewardAPYs];
|
|
25561
|
+
const netAPY = baseAPY + rewardAPY;
|
|
25562
|
+
return { net: netAPY, splits: [{
|
|
25563
|
+
apy: baseAPY,
|
|
25564
|
+
id: "base"
|
|
25565
|
+
}, {
|
|
25566
|
+
apy: rewardAPY,
|
|
25567
|
+
id: "defispring"
|
|
25568
|
+
}] };
|
|
25569
|
+
}
|
|
25570
|
+
computeAPY(apys, weights) {
|
|
25571
|
+
assert(apys.length === weights.length, "APYs and weights length mismatch");
|
|
25572
|
+
const weightedSum = apys.reduce((acc, apy, i) => acc + apy * weights[i], 0);
|
|
25573
|
+
const totalWeight = weights.reduce((acc, weight) => acc + weight, 0);
|
|
25574
|
+
return weightedSum / totalWeight;
|
|
25505
25575
|
}
|
|
25506
25576
|
/**
|
|
25507
25577
|
* Calculates the total TVL of the strategy.
|
|
@@ -25524,22 +25594,50 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25524
25594
|
};
|
|
25525
25595
|
}
|
|
25526
25596
|
async getAUM() {
|
|
25597
|
+
const currentAUM = await this.contract.call("aum", []);
|
|
25598
|
+
const lastReportTime = await this.contract.call("last_report_timestamp", []);
|
|
25599
|
+
const token1Price = await this.pricer.getPrice(this.metadata.depositTokens[0].symbol);
|
|
25527
25600
|
const [vesuAdapter1, vesuAdapter2] = this.getVesuAdapters();
|
|
25528
25601
|
const leg1AUM = await vesuAdapter1.getPositions(this.config);
|
|
25529
25602
|
const leg2AUM = await vesuAdapter2.getPositions(this.config);
|
|
25530
|
-
const
|
|
25531
|
-
|
|
25532
|
-
|
|
25603
|
+
const balance = await new ERC20(this.config).balanceOf(this.asset().address, this.metadata.additionalInfo.vaultAllocator, this.asset().decimals);
|
|
25604
|
+
logger.verbose(`${this.getTag()} unused balance: ${balance}`);
|
|
25605
|
+
const aumToken = leg1AUM[0].amount.plus(leg2AUM[0].usdValue / token1Price.price).minus(leg1AUM[1].usdValue / token1Price.price).minus(leg2AUM[1].amount).plus(balance);
|
|
25606
|
+
logger.verbose(`${this.getTag()} Actual AUM: ${aumToken}`);
|
|
25607
|
+
const netAPY = await this.netAPY();
|
|
25608
|
+
const defispringAPY = netAPY.splits.find((s) => s.id === "defispring")?.apy || 0;
|
|
25609
|
+
if (!defispringAPY) throw new Error("DefiSpring APY not found");
|
|
25610
|
+
const timeDiff = Math.round(Date.now() / 1e3) - Number(lastReportTime);
|
|
25611
|
+
const growthRate = timeDiff * defispringAPY / (365 * 24 * 60 * 60);
|
|
25612
|
+
const prevAum = Web3Number.fromWei(currentAUM.toString(), this.asset().decimals);
|
|
25613
|
+
const rewardAssets = prevAum.multipliedBy(growthRate);
|
|
25614
|
+
logger.verbose(`${this.getTag()} DefiSpring AUM time difference: ${timeDiff}`);
|
|
25615
|
+
logger.verbose(`${this.getTag()} Current AUM: ${currentAUM}`);
|
|
25616
|
+
logger.verbose(`${this.getTag()} Net APY: ${JSON.stringify(netAPY)}`);
|
|
25617
|
+
logger.verbose(`${this.getTag()} rewards AUM: ${rewardAssets}`);
|
|
25618
|
+
const newAUM = aumToken.plus(rewardAssets);
|
|
25619
|
+
logger.verbose(`${this.getTag()} New AUM: ${newAUM}`);
|
|
25620
|
+
const net = {
|
|
25533
25621
|
tokenInfo: this.asset(),
|
|
25534
|
-
amount:
|
|
25535
|
-
usdValue:
|
|
25622
|
+
amount: newAUM,
|
|
25623
|
+
usdValue: newAUM.multipliedBy(token1Price.price).toNumber()
|
|
25536
25624
|
};
|
|
25625
|
+
const splits = [{
|
|
25626
|
+
id: "finalised",
|
|
25627
|
+
aum: aumToken
|
|
25628
|
+
}, {
|
|
25629
|
+
id: "defispring",
|
|
25630
|
+
aum: rewardAssets
|
|
25631
|
+
}];
|
|
25632
|
+
return { net, splits, prevAum };
|
|
25537
25633
|
}
|
|
25538
25634
|
getVesuAdapters() {
|
|
25539
25635
|
const vesuAdapter1 = this.getAdapter("vesu_leg1_adapter" /* VESU_LEG1 */);
|
|
25540
25636
|
const vesuAdapter2 = this.getAdapter("vesu_leg2_adapter" /* VESU_LEG2 */);
|
|
25541
25637
|
vesuAdapter1.pricer = this.pricer;
|
|
25542
25638
|
vesuAdapter2.pricer = this.pricer;
|
|
25639
|
+
vesuAdapter1.networkConfig = this.config;
|
|
25640
|
+
vesuAdapter2.networkConfig = this.config;
|
|
25543
25641
|
return [vesuAdapter1, vesuAdapter2];
|
|
25544
25642
|
}
|
|
25545
25643
|
async getVaultPositions() {
|
|
@@ -25581,12 +25679,14 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25581
25679
|
}));
|
|
25582
25680
|
const output2 = [{
|
|
25583
25681
|
proofs: manage5Info.proofs,
|
|
25584
|
-
manageCall: manageCall5
|
|
25682
|
+
manageCall: manageCall5,
|
|
25683
|
+
step: STEP2_ID
|
|
25585
25684
|
}];
|
|
25586
25685
|
if (approveAmount.gt(0)) {
|
|
25587
25686
|
output2.unshift({
|
|
25588
25687
|
proofs: manage4Info.proofs,
|
|
25589
|
-
manageCall: manageCall4
|
|
25688
|
+
manageCall: manageCall4,
|
|
25689
|
+
step: STEP1_ID
|
|
25590
25690
|
});
|
|
25591
25691
|
}
|
|
25592
25692
|
return output2;
|
|
@@ -25594,9 +25694,96 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25594
25694
|
getTag() {
|
|
25595
25695
|
return `${_UniversalStrategy.name}:${this.metadata.name}`;
|
|
25596
25696
|
}
|
|
25697
|
+
async getVesuHealthFactors() {
|
|
25698
|
+
return await Promise.all(this.getVesuAdapters().map((v) => v.getHealthFactor()));
|
|
25699
|
+
}
|
|
25700
|
+
async computeRebalanceConditionAndReturnCalls() {
|
|
25701
|
+
const vesuAdapters = this.getVesuAdapters();
|
|
25702
|
+
const healthFactors = await this.getVesuHealthFactors();
|
|
25703
|
+
const leg1HealthFactor = healthFactors[0];
|
|
25704
|
+
const leg2HealthFactor = healthFactors[1];
|
|
25705
|
+
logger.verbose(`${this.getTag()}: HealthFactorLeg1: ${leg1HealthFactor}`);
|
|
25706
|
+
logger.verbose(`${this.getTag()}: HealthFactorLeg2: ${leg2HealthFactor}`);
|
|
25707
|
+
const minHf = this.metadata.additionalInfo.minHealthFactor;
|
|
25708
|
+
const isRebalanceNeeded1 = leg1HealthFactor < minHf;
|
|
25709
|
+
const isRebalanceNeeded2 = leg2HealthFactor < minHf;
|
|
25710
|
+
if (!isRebalanceNeeded1 && !isRebalanceNeeded2) {
|
|
25711
|
+
return [];
|
|
25712
|
+
}
|
|
25713
|
+
if (isRebalanceNeeded1) {
|
|
25714
|
+
const amount = await this.getLegRebalanceAmount(vesuAdapters[0], leg1HealthFactor, false);
|
|
25715
|
+
const leg2HF = await this.getNewHealthFactor(vesuAdapters[1], amount, true);
|
|
25716
|
+
assert(leg2HF > minHf, `Rebalance Leg1 failed: Leg2 HF after rebalance would be too low: ${leg2HF}`);
|
|
25717
|
+
return [await this.getRebalanceCall({
|
|
25718
|
+
isLeg1toLeg2: false,
|
|
25719
|
+
amount
|
|
25720
|
+
})];
|
|
25721
|
+
} else {
|
|
25722
|
+
const amount = await this.getLegRebalanceAmount(vesuAdapters[1], leg2HealthFactor, true);
|
|
25723
|
+
const leg1HF = await this.getNewHealthFactor(vesuAdapters[0], amount, false);
|
|
25724
|
+
assert(leg1HF > minHf, `Rebalance Leg2 failed: Leg1 HF after rebalance would be too low: ${leg1HF}`);
|
|
25725
|
+
return [await this.getRebalanceCall({
|
|
25726
|
+
isLeg1toLeg2: true,
|
|
25727
|
+
amount
|
|
25728
|
+
})];
|
|
25729
|
+
}
|
|
25730
|
+
}
|
|
25731
|
+
async getNewHealthFactor(vesuAdapter, newAmount, isWithdraw) {
|
|
25732
|
+
const {
|
|
25733
|
+
collateralTokenAmount,
|
|
25734
|
+
collateralUSDAmount,
|
|
25735
|
+
collateralPrice,
|
|
25736
|
+
debtTokenAmount,
|
|
25737
|
+
debtUSDAmount,
|
|
25738
|
+
debtPrice,
|
|
25739
|
+
ltv
|
|
25740
|
+
} = await vesuAdapter.getAssetPrices();
|
|
25741
|
+
if (isWithdraw) {
|
|
25742
|
+
const newHF = (collateralTokenAmount.toNumber() - newAmount.toNumber()) * collateralPrice * ltv / debtUSDAmount;
|
|
25743
|
+
logger.verbose(`getNewHealthFactor:: HF: ${newHF}, amoutn: ${newAmount.toNumber()}, isDeposit`);
|
|
25744
|
+
return newHF;
|
|
25745
|
+
} else {
|
|
25746
|
+
const newHF = collateralUSDAmount * ltv / ((debtTokenAmount.toNumber() + newAmount.toNumber()) * debtPrice);
|
|
25747
|
+
logger.verbose(`getNewHealthFactor:: HF: ${newHF}, amoutn: ${newAmount.toNumber()}, isRepay`);
|
|
25748
|
+
return newHF;
|
|
25749
|
+
}
|
|
25750
|
+
}
|
|
25751
|
+
/**
|
|
25752
|
+
*
|
|
25753
|
+
* @param vesuAdapter
|
|
25754
|
+
* @param currentHf
|
|
25755
|
+
* @param isDeposit if true, attempt by adding collateral, else by repaying
|
|
25756
|
+
* @returns
|
|
25757
|
+
*/
|
|
25758
|
+
async getLegRebalanceAmount(vesuAdapter, currentHf, isDeposit) {
|
|
25759
|
+
const {
|
|
25760
|
+
collateralTokenAmount,
|
|
25761
|
+
collateralUSDAmount,
|
|
25762
|
+
collateralPrice,
|
|
25763
|
+
debtTokenAmount,
|
|
25764
|
+
debtUSDAmount,
|
|
25765
|
+
debtPrice,
|
|
25766
|
+
ltv
|
|
25767
|
+
} = await vesuAdapter.getAssetPrices();
|
|
25768
|
+
if (debtTokenAmount.isZero()) {
|
|
25769
|
+
return Web3Number.fromWei(0, 0);
|
|
25770
|
+
}
|
|
25771
|
+
assert(collateralPrice > 0 && debtPrice > 0, "getRebalanceAmount: Invalid price");
|
|
25772
|
+
const targetHF = this.metadata.additionalInfo.targetHealthFactor;
|
|
25773
|
+
if (currentHf > targetHF - 0.01)
|
|
25774
|
+
throw new Error("getLegRebalanceAmount: Current health factor is healthy");
|
|
25775
|
+
if (isDeposit) {
|
|
25776
|
+
const newAmount = targetHF * debtUSDAmount / (collateralPrice * ltv) - collateralTokenAmount.toNumber();
|
|
25777
|
+
logger.verbose(`${this.getTag()}:: getLegRebalanceAmount: addCollateral, currentHf: ${currentHf}, targetHF: ${targetHF}, collAmount: ${collateralTokenAmount.toString()}, collUSD: ${collateralUSDAmount}, collPrice: ${collateralPrice}, debtAmount: ${debtTokenAmount.toString()}, debtUSD: ${debtUSDAmount}, debtPrice: ${debtPrice}, ltv: ${ltv}, newAmount: ${newAmount}`);
|
|
25778
|
+
return new Web3Number(newAmount.toFixed(8), collateralTokenAmount.decimals);
|
|
25779
|
+
} else {
|
|
25780
|
+
const newAmount = debtTokenAmount.toNumber() - collateralUSDAmount * ltv / (targetHF * debtPrice);
|
|
25781
|
+
logger.verbose(`${this.getTag()}:: getLegRebalanceAmount: repayDebt, currentHf: ${currentHf}, targetHF: ${targetHF}, collAmount: ${collateralTokenAmount.toString()}, collUSD: ${collateralUSDAmount}, collPrice: ${collateralPrice}, debtAmount: ${debtTokenAmount.toString()}, debtUSD: ${debtUSDAmount}, debtPrice: ${debtPrice}, ltv: ${ltv}, newAmount: ${newAmount}`);
|
|
25782
|
+
return new Web3Number(newAmount.toFixed(8), debtTokenAmount.decimals);
|
|
25783
|
+
}
|
|
25784
|
+
}
|
|
25597
25785
|
async getVesuMultiplyCall(params) {
|
|
25598
|
-
const vesuAdapter1 = this.
|
|
25599
|
-
const vesuAdapter2 = this.getAdapter("vesu_leg2_adapter" /* VESU_LEG2 */);
|
|
25786
|
+
const [vesuAdapter1, vesuAdapter2] = this.getVesuAdapters();
|
|
25600
25787
|
const leg1LTV = await vesuAdapter1.getLTVConfig(this.config);
|
|
25601
25788
|
const leg2LTV = await vesuAdapter2.getLTVConfig(this.config);
|
|
25602
25789
|
logger.verbose(`${this.getTag()}: LTVLeg1: ${leg1LTV}`);
|
|
@@ -25605,7 +25792,7 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25605
25792
|
const token2Price = await this.pricer.getPrice(vesuAdapter2.config.collateral.symbol);
|
|
25606
25793
|
logger.verbose(`${this.getTag()}: Price${vesuAdapter1.config.collateral.symbol}: ${token1Price.price}`);
|
|
25607
25794
|
logger.verbose(`${this.getTag()}: Price${vesuAdapter2.config.collateral.symbol}: ${token2Price.price}`);
|
|
25608
|
-
const TARGET_HF =
|
|
25795
|
+
const TARGET_HF = this.metadata.additionalInfo.targetHealthFactor;
|
|
25609
25796
|
const k1 = token1Price.price * leg1LTV / token2Price.price / TARGET_HF;
|
|
25610
25797
|
const k2 = token1Price.price * TARGET_HF / token2Price.price / leg2LTV;
|
|
25611
25798
|
const borrow2Amount = new Web3Number(
|
|
@@ -25663,14 +25850,14 @@ var UniversalStrategy = class _UniversalStrategy extends BaseStrategy {
|
|
|
25663
25850
|
});
|
|
25664
25851
|
if (params.isLeg1toLeg2) {
|
|
25665
25852
|
const manageCall = this.getManageCall([
|
|
25666
|
-
|
|
25667
|
-
|
|
25853
|
+
...callSet1.map((i) => i.step),
|
|
25854
|
+
...callSet2.map((i) => i.step)
|
|
25668
25855
|
], [...callSet1.map((i) => i.manageCall), ...callSet2.map((i) => i.manageCall)]);
|
|
25669
25856
|
return manageCall;
|
|
25670
25857
|
} else {
|
|
25671
25858
|
const manageCall = this.getManageCall([
|
|
25672
|
-
|
|
25673
|
-
|
|
25859
|
+
...callSet2.map((i) => i.step),
|
|
25860
|
+
...callSet1.map((i) => i.step)
|
|
25674
25861
|
], [...callSet2.map((i) => i.manageCall), ...callSet1.map((i) => i.manageCall)]);
|
|
25675
25862
|
return manageCall;
|
|
25676
25863
|
}
|
|
@@ -25737,15 +25924,21 @@ var usdcVaultSettings = {
|
|
|
25737
25924
|
manager: ContractAddr.from("0xf41a2b1f498a7f9629db0b8519259e66e964260a23d20003f3e42bb1997a07"),
|
|
25738
25925
|
vaultAllocator: ContractAddr.from("0x228cca1005d3f2b55cbaba27cb291dacf1b9a92d1d6b1638195fbd3d0c1e3ba"),
|
|
25739
25926
|
redeemRequestNFT: ContractAddr.from("0x906d03590010868cbf7590ad47043959d7af8e782089a605d9b22567b64fda"),
|
|
25927
|
+
aumOracle: ContractAddr.from("0x6faf45ed185dec13ef723c9ead4266cab98d06f2cb237e331b1fa5c2aa79afe"),
|
|
25740
25928
|
leafAdapters: [],
|
|
25741
|
-
adapters: []
|
|
25929
|
+
adapters: [],
|
|
25930
|
+
targetHealthFactor: 1.3,
|
|
25931
|
+
minHealthFactor: 1.25
|
|
25742
25932
|
};
|
|
25743
25933
|
var wbtcVaultSettings = {
|
|
25744
25934
|
manager: ContractAddr.from("0xef8a664ffcfe46a6af550766d27c28937bf1b77fb4ab54d8553e92bca5ba34"),
|
|
25745
25935
|
vaultAllocator: ContractAddr.from("0x1e01c25f0d9494570226ad28a7fa856c0640505e809c366a9fab4903320e735"),
|
|
25746
25936
|
redeemRequestNFT: ContractAddr.from("0x4fec59a12f8424281c1e65a80b5de51b4e754625c60cddfcd00d46941ec37b2"),
|
|
25937
|
+
aumOracle: ContractAddr.from("0x2edf4edbed3f839e7f07dcd913e92299898ff4cf0ba532f8c572c66c5b331b2"),
|
|
25747
25938
|
leafAdapters: [],
|
|
25748
|
-
adapters: []
|
|
25939
|
+
adapters: [],
|
|
25940
|
+
targetHealthFactor: 1.3,
|
|
25941
|
+
minHealthFactor: 1.25
|
|
25749
25942
|
};
|
|
25750
25943
|
var UniversalStrategies = [
|
|
25751
25944
|
{
|
|
@@ -25795,13 +25988,10 @@ var TelegramNotif = class {
|
|
|
25795
25988
|
this.subscribers = [
|
|
25796
25989
|
// '6820228303',
|
|
25797
25990
|
"1505578076",
|
|
25798
|
-
// '5434736198', // maaza
|
|
25799
25991
|
"1356705582",
|
|
25800
25992
|
// langs
|
|
25801
25993
|
"1388729514",
|
|
25802
25994
|
// hwashere
|
|
25803
|
-
"6020162572",
|
|
25804
|
-
//minato
|
|
25805
25995
|
"985902592"
|
|
25806
25996
|
];
|
|
25807
25997
|
this.bot = new import_node_telegram_bot_api.default(token, { polling: shouldPoll });
|
|
@@ -26078,7 +26268,7 @@ function getAccount(accountKey, config, password = process.env.ACCOUNT_SECURE_PA
|
|
|
26078
26268
|
...storeConfig,
|
|
26079
26269
|
PASSWORD: password
|
|
26080
26270
|
});
|
|
26081
|
-
return store.getAccount(accountKey);
|
|
26271
|
+
return store.getAccount(accountKey, "0x3");
|
|
26082
26272
|
}
|
|
26083
26273
|
async function myDeclare(contract_name, package_name = "strkfarm", config, acc) {
|
|
26084
26274
|
const provider2 = config.provider;
|