@strkfarm/sdk 2.0.0-dev.27 → 2.0.0-dev.28
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/cli.js +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +79130 -49357
- package/dist/index.browser.mjs +18039 -11434
- package/dist/index.d.ts +2869 -898
- package/dist/index.js +19036 -12210
- package/dist/index.mjs +18942 -12161
- package/package.json +1 -1
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +76 -41
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +167 -2
- package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +4 -4
- package/src/modules/ekubo-pricer.ts +79 -0
- package/src/modules/ekubo-quoter.ts +46 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-from-api.ts +156 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +40 -4
- package/src/modules/pricerBase.ts +2 -1
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +2 -1
- package/src/strategies/base-strategy.ts +78 -10
- package/src/strategies/ekubo-cl-vault.tsx +906 -347
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +6 -1
- package/src/strategies/registry.ts +239 -0
- package/src/strategies/sensei.ts +335 -7
- package/src/strategies/svk-strategy.ts +97 -27
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
- package/src/strategies/universal-adapters/index.ts +9 -8
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
- package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
- package/src/strategies/universal-strategy.tsx +1426 -1178
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +2 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1788
- package/src/strategies/vesu-rebalance.tsx +255 -152
- package/src/utils/health-factor-math.ts +4 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
|
@@ -1,251 +1,263 @@
|
|
|
1
|
-
import { Call, hash, num, shortString } from "starknet";
|
|
2
|
-
import { SIMPLE_SANITIZER, toBigInt } from "./adapter-utils";
|
|
3
|
-
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
4
|
-
import { IConfig, IProtocol, TokenInfo } from "@/interfaces";
|
|
5
|
-
import { PricerBase } from "@/modules/pricerBase";
|
|
6
|
-
import { LeafData, logger, StandardMerkleTree } from "@/utils";
|
|
7
|
-
import { CacheClass } from "@/utils/cacheClass";
|
|
8
|
-
|
|
9
|
-
export interface ManageCall {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export interface
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
1
|
+
import { Call, hash, num, shortString } from "starknet";
|
|
2
|
+
import { SIMPLE_SANITIZER, toBigInt } from "./adapter-utils";
|
|
3
|
+
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
4
|
+
import { IConfig, IProtocol, TokenInfo } from "@/interfaces";
|
|
5
|
+
import { PricerBase } from "@/modules/pricerBase";
|
|
6
|
+
import { LeafData, logger, StandardMerkleTree } from "@/utils";
|
|
7
|
+
import { CacheClass } from "@/utils/cacheClass";
|
|
8
|
+
|
|
9
|
+
export interface ManageCall {
|
|
10
|
+
proofReadableId: string,
|
|
11
|
+
sanitizer: ContractAddr,
|
|
12
|
+
call: {
|
|
13
|
+
contractAddress: ContractAddr,
|
|
14
|
+
selector: string,
|
|
15
|
+
calldata: bigint[]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SwapPriceInfo {
|
|
20
|
+
source: 'avnu' | 'ekubo';
|
|
21
|
+
fromTokenSymbol: string;
|
|
22
|
+
toTokenSymbol: string;
|
|
23
|
+
fromAmount: number;
|
|
24
|
+
toAmount: number;
|
|
25
|
+
effectivePrice: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export interface DepositParams {
|
|
30
|
+
amount: Web3Number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface WithdrawParams {
|
|
34
|
+
amount: Web3Number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// export type GenerateCallFn<T> = (params: T) => ManageCall;
|
|
38
|
+
// export type AdapterLeafType<T> = {leaf: LeafData, callConstructor: GenerateCallFn<T>}
|
|
39
|
+
export type GenerateCallFn<T> = (params: T) => Promise<ManageCall[]>;
|
|
40
|
+
export type AdapterLeafType<T> = {leaves: LeafData[], callConstructor: GenerateCallFn<T>}
|
|
41
|
+
export type LeafAdapterFn<T> = () => AdapterLeafType<T>;
|
|
42
|
+
|
|
43
|
+
export enum APYType {
|
|
44
|
+
BASE = "base",
|
|
45
|
+
REWARD = "reward",
|
|
46
|
+
LST = "lst"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface SupportedPosition {
|
|
50
|
+
asset: TokenInfo,
|
|
51
|
+
isDebt: boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface BaseAdapterConfig {
|
|
55
|
+
baseToken: TokenInfo,
|
|
56
|
+
supportedPositions: SupportedPosition[],
|
|
57
|
+
networkConfig: IConfig,
|
|
58
|
+
pricer: PricerBase,
|
|
59
|
+
vaultAllocator: ContractAddr
|
|
60
|
+
vaultAddress: ContractAddr
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type PositionAPY = { apy: number, type: APYType };
|
|
64
|
+
export type PositionInfo = {
|
|
65
|
+
tokenInfo: TokenInfo,
|
|
66
|
+
amount: Web3Number,
|
|
67
|
+
usdValue: number,
|
|
68
|
+
remarks: string,
|
|
69
|
+
apy: PositionAPY,
|
|
70
|
+
protocol: IProtocol
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export type PositionAmount = {
|
|
74
|
+
amount: Web3Number,
|
|
75
|
+
remarks: string,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export abstract class BaseAdapter<DepositParams, WithdrawParams> extends CacheClass {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly config: BaseAdapterConfig;
|
|
81
|
+
readonly protocol: IProtocol;
|
|
82
|
+
|
|
83
|
+
constructor(config: BaseAdapterConfig, name: string, protocol: IProtocol) {
|
|
84
|
+
super();
|
|
85
|
+
this.config = config;
|
|
86
|
+
this.name = name;
|
|
87
|
+
this.protocol = protocol;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Loop through all supported positions and return amount, usd value, remarks and apy for each
|
|
92
|
+
*/
|
|
93
|
+
async getPositions(): Promise<PositionInfo[]> {
|
|
94
|
+
const results: PositionInfo[] = [];
|
|
95
|
+
for (const supported of this.config.supportedPositions) {
|
|
96
|
+
const amount = await this.getPosition(supported);
|
|
97
|
+
if (!amount) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const usdValue = await this.getUSDValue(supported.asset, amount.amount);
|
|
101
|
+
const apy = await this.getAPY(supported);
|
|
102
|
+
results.push({ tokenInfo: supported.asset, amount: amount.amount, usdValue, apy, protocol: this.protocol, remarks: amount.remarks });
|
|
103
|
+
}
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Implemented by child adapters to compute APY for a given supported position
|
|
109
|
+
*/
|
|
110
|
+
protected abstract getAPY(supportedPosition: SupportedPosition): Promise<PositionAPY>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Implemented by child adapters to fetch amount for a given supported position
|
|
114
|
+
*/
|
|
115
|
+
protected abstract getPosition(supportedPosition: SupportedPosition): Promise<PositionAmount | null>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Implemented by child adapters to calculate maximum deposit positions
|
|
119
|
+
* @param amount Optional amount in baseToken to deposit
|
|
120
|
+
*/
|
|
121
|
+
abstract maxDeposit(amount?: Web3Number): Promise<PositionInfo>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Implemented by child adapters to calculate maximum withdraw positions
|
|
125
|
+
*/
|
|
126
|
+
abstract maxWithdraw(): Promise<PositionInfo>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Uses pricer to convert an amount of an asset to USD value
|
|
130
|
+
*/
|
|
131
|
+
protected async getUSDValue(asset: TokenInfo, amount: Web3Number): Promise<number> {
|
|
132
|
+
const priceInfo = await this.config.pricer.getPrice(asset.priceProxySymbol || asset.symbol);
|
|
133
|
+
return amount.toNumber() * priceInfo.price;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
protected constructSimpleLeafData(params: {
|
|
138
|
+
id: string,
|
|
139
|
+
target: ContractAddr,
|
|
140
|
+
method: string,
|
|
141
|
+
packedArguments: bigint[],
|
|
142
|
+
}, sanitizer: ContractAddr = SIMPLE_SANITIZER): LeafData {
|
|
143
|
+
const { id, target, method, packedArguments } = params;
|
|
144
|
+
return {
|
|
145
|
+
id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
|
|
146
|
+
readableId: id,
|
|
147
|
+
data: [
|
|
148
|
+
sanitizer.toBigInt(), // sanitizer address
|
|
149
|
+
target.toBigInt(), // contract
|
|
150
|
+
toBigInt(hash.getSelectorFromName(method)), // method name
|
|
151
|
+
BigInt(packedArguments.length),
|
|
152
|
+
...packedArguments
|
|
153
|
+
]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Implementor must provide target/method/packedArguments/sanitizer for deposit leaf construction
|
|
159
|
+
*/
|
|
160
|
+
protected abstract _getDepositLeaf(): {
|
|
161
|
+
target: ContractAddr,
|
|
162
|
+
method: string,
|
|
163
|
+
packedArguments: bigint[],
|
|
164
|
+
sanitizer: ContractAddr,
|
|
165
|
+
id: string
|
|
166
|
+
}[];
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Implementor must provide target/method/packedArguments/sanitizer for withdraw leaf construction
|
|
170
|
+
*/
|
|
171
|
+
protected abstract _getWithdrawLeaf(): {
|
|
172
|
+
target: ContractAddr,
|
|
173
|
+
method: string,
|
|
174
|
+
packedArguments: bigint[],
|
|
175
|
+
sanitizer: ContractAddr,
|
|
176
|
+
id: string
|
|
177
|
+
}[];
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Returns deposit leaf adapter using configured proof id
|
|
181
|
+
*/
|
|
182
|
+
getDepositLeaf(): AdapterLeafType<DepositParams> {
|
|
183
|
+
const leafConfigs = this._getDepositLeaf();
|
|
184
|
+
const leaves = leafConfigs.map(config => {
|
|
185
|
+
const { target, method, packedArguments, sanitizer, id } = config;
|
|
186
|
+
const leaf = this.constructSimpleLeafData({
|
|
187
|
+
id: id,
|
|
188
|
+
target,
|
|
189
|
+
method,
|
|
190
|
+
packedArguments
|
|
191
|
+
}, sanitizer);
|
|
192
|
+
return leaf;
|
|
193
|
+
});
|
|
194
|
+
return { leaves, callConstructor: this.getDepositCall.bind(this) as unknown as GenerateCallFn<DepositParams> };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Returns withdraw leaf adapter using configured proof id
|
|
199
|
+
*/
|
|
200
|
+
getWithdrawLeaf(): AdapterLeafType<WithdrawParams> {
|
|
201
|
+
const leafConfigs = this._getWithdrawLeaf();
|
|
202
|
+
const leaves = leafConfigs.map(config => {
|
|
203
|
+
const { target, method, packedArguments, sanitizer, id } = config;
|
|
204
|
+
const leaf = this.constructSimpleLeafData({
|
|
205
|
+
id: id,
|
|
206
|
+
target,
|
|
207
|
+
method,
|
|
208
|
+
packedArguments
|
|
209
|
+
}, sanitizer ?? SIMPLE_SANITIZER);
|
|
210
|
+
return leaf;
|
|
211
|
+
});
|
|
212
|
+
return { leaves, callConstructor: this.getWithdrawCall.bind(this) as unknown as GenerateCallFn<WithdrawParams> };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Implementor must provide deposit call
|
|
217
|
+
* @param params
|
|
218
|
+
*/
|
|
219
|
+
abstract getDepositCall(params: DepositParams): Promise<ManageCall[]>;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Implementor must provide withdraw call
|
|
223
|
+
* @param params
|
|
224
|
+
*/
|
|
225
|
+
abstract getWithdrawCall(params: WithdrawParams): Promise<ManageCall[]>;
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
getProofs<T>(isDeposit: boolean, tree: StandardMerkleTree): { proofs: string[][], callConstructor: GenerateCallFn<DepositParams> | GenerateCallFn<WithdrawParams> } {
|
|
229
|
+
let proofGroups: string[][] = [];
|
|
230
|
+
|
|
231
|
+
const ids = isDeposit ? this.getDepositLeaf().leaves.map(l => l.readableId) : this.getWithdrawLeaf().leaves.map(l => l.readableId);
|
|
232
|
+
// console.log(`${this.name}::getProofs ids: ${ids}`);
|
|
233
|
+
for (const [i, v] of tree.entries()) {
|
|
234
|
+
// console.log(`${this.name}::getProofs v: ${v.readableId}`);
|
|
235
|
+
if (ids.includes(v.readableId)) {
|
|
236
|
+
// console.log(`${this.name}::getProofs found id: ${v.readableId}`);
|
|
237
|
+
proofGroups.push(tree.getProof(i));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (proofGroups.length != ids.length) {
|
|
241
|
+
throw new Error(`Not all proofs found for IDs: ${ids.join(', ')}`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// find leaf adapter
|
|
245
|
+
return {
|
|
246
|
+
proofs: proofGroups,
|
|
247
|
+
callConstructor: isDeposit ?
|
|
248
|
+
this.getDepositCall.bind(this) :
|
|
249
|
+
this.getWithdrawCall.bind(this)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async getNetAPY(): Promise<number> {
|
|
254
|
+
const positions = (await this.getPositions()).filter(position => position !== null);
|
|
255
|
+
logger.verbose(`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`);
|
|
256
|
+
const netAmount = positions.reduce((acc, curr) => acc + curr.usdValue, 0);
|
|
257
|
+
const netAPY = positions.reduce((acc, curr) => acc + curr.apy.apy * curr.usdValue, 0) / netAmount;
|
|
258
|
+
logger.verbose(`${this.name}::getNetAPY: netAPY: ${netAPY}`);
|
|
259
|
+
return netAPY;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
abstract getHealthFactor(): Promise<number>;
|
|
263
|
+
}
|