@strkfarm/sdk 1.0.6
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 +636 -0
- package/dist/cli.mjs +613 -0
- package/dist/index.browser.global.js +33487 -0
- package/dist/index.d.ts +360 -0
- package/dist/index.js +1003 -0
- package/dist/index.mjs +948 -0
- package/package.json +58 -0
- package/src/cli.ts +160 -0
- package/src/data/pragma.abi.json +96 -0
- package/src/data/tokens.json +72 -0
- package/src/dataTypes/address.ts +38 -0
- package/src/dataTypes/bignumber.ts +53 -0
- package/src/dataTypes/index.ts +2 -0
- package/src/global.ts +73 -0
- package/src/index.browser.ts +6 -0
- package/src/index.ts +9 -0
- package/src/interfaces/common.ts +33 -0
- package/src/interfaces/index.ts +3 -0
- package/src/interfaces/initializable.ts +21 -0
- package/src/interfaces/lending.ts +75 -0
- package/src/modules/index.ts +3 -0
- package/src/modules/pragma.ts +22 -0
- package/src/modules/pricer.ts +125 -0
- package/src/modules/zkLend.ts +162 -0
- package/src/node/index.ts +1 -0
- package/src/node/pricer-redis.ts +71 -0
- package/src/notifs/index.ts +1 -0
- package/src/notifs/telegram.ts +48 -0
- package/src/strategies/autoCompounderStrk.ts +71 -0
- package/src/strategies/index.ts +1 -0
- package/src/utils/encrypt.ts +68 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/store.ts +173 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { RpcProvider, BlockIdentifier, Contract, Account } from 'starknet';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import * as util from 'util';
|
|
4
|
+
import TelegramBot from 'node-telegram-bot-api';
|
|
5
|
+
|
|
6
|
+
interface TokenInfo {
|
|
7
|
+
name: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
address: string;
|
|
10
|
+
decimals: number;
|
|
11
|
+
pricerKey?: string;
|
|
12
|
+
}
|
|
13
|
+
declare enum Network {
|
|
14
|
+
mainnet = "mainnet",
|
|
15
|
+
sepolia = "sepolia",
|
|
16
|
+
devnet = "devnet"
|
|
17
|
+
}
|
|
18
|
+
interface IConfig {
|
|
19
|
+
provider: RpcProvider;
|
|
20
|
+
network: Network;
|
|
21
|
+
stage: 'production' | 'staging';
|
|
22
|
+
heartbeatUrl?: string;
|
|
23
|
+
}
|
|
24
|
+
declare function getMainnetConfig(rpcUrl?: string, blockIdentifier?: BlockIdentifier): IConfig;
|
|
25
|
+
|
|
26
|
+
interface PriceInfo {
|
|
27
|
+
price: number;
|
|
28
|
+
timestamp: Date;
|
|
29
|
+
}
|
|
30
|
+
declare class Pricer {
|
|
31
|
+
readonly config: IConfig;
|
|
32
|
+
readonly tokens: TokenInfo[];
|
|
33
|
+
protected prices: {
|
|
34
|
+
[key: string]: PriceInfo;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
38
|
+
*/
|
|
39
|
+
protected PRICE_API: string;
|
|
40
|
+
constructor(config: IConfig, tokens: TokenInfo[]);
|
|
41
|
+
isReady(): boolean;
|
|
42
|
+
waitTillReady(): Promise<void>;
|
|
43
|
+
start(): void;
|
|
44
|
+
isStale(timestamp: Date, tokenName: string): boolean;
|
|
45
|
+
assertNotStale(timestamp: Date, tokenName: string): void;
|
|
46
|
+
getPrice(tokenName: string): Promise<PriceInfo>;
|
|
47
|
+
protected _loadPrices(onUpdate?: (tokenSymbol: string) => void): void;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare class Pragma {
|
|
51
|
+
contractAddr: string;
|
|
52
|
+
readonly contract: Contract;
|
|
53
|
+
constructor(provider: RpcProvider);
|
|
54
|
+
getPrice(tokenAddr: string): Promise<number>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A simple wrapper around a contract address that is universally comparable
|
|
59
|
+
* - Helps avoid padding issues
|
|
60
|
+
*/
|
|
61
|
+
declare class ContractAddr {
|
|
62
|
+
readonly address: string;
|
|
63
|
+
constructor(address: string);
|
|
64
|
+
static from(address: string): ContractAddr;
|
|
65
|
+
eq(other: ContractAddr): boolean;
|
|
66
|
+
eqString(other: string): boolean;
|
|
67
|
+
static standardise(address: string | bigint): string;
|
|
68
|
+
static eqString(a: string, b: string): boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
declare class Web3Number extends BigNumber {
|
|
72
|
+
decimals: number;
|
|
73
|
+
constructor(value: string | number, decimals: number);
|
|
74
|
+
static fromWei(weiNumber: string | number, decimals: number): Web3Number;
|
|
75
|
+
toWei(): string;
|
|
76
|
+
multipliedBy(value: string | number): Web3Number;
|
|
77
|
+
dividedBy(value: string | number): Web3Number;
|
|
78
|
+
plus(value: string | number): Web3Number;
|
|
79
|
+
minus(n: number | string, base?: number): Web3Number;
|
|
80
|
+
toString(base?: number | undefined): string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface ILendingMetadata {
|
|
84
|
+
name: string;
|
|
85
|
+
logo: string;
|
|
86
|
+
}
|
|
87
|
+
declare enum MarginType {
|
|
88
|
+
SHARED = "shared",
|
|
89
|
+
NONE = "none"
|
|
90
|
+
}
|
|
91
|
+
interface ILendingPosition {
|
|
92
|
+
tokenName: string;
|
|
93
|
+
tokenSymbol: string;
|
|
94
|
+
marginType: MarginType;
|
|
95
|
+
debtAmount: Web3Number;
|
|
96
|
+
debtUSD: Web3Number;
|
|
97
|
+
supplyAmount: Web3Number;
|
|
98
|
+
supplyUSD: Web3Number;
|
|
99
|
+
}
|
|
100
|
+
interface LendingToken extends TokenInfo {
|
|
101
|
+
borrowFactor: Web3Number;
|
|
102
|
+
collareralFactor: Web3Number;
|
|
103
|
+
}
|
|
104
|
+
declare abstract class ILending {
|
|
105
|
+
readonly config: IConfig;
|
|
106
|
+
readonly metadata: ILendingMetadata;
|
|
107
|
+
readonly tokens: LendingToken[];
|
|
108
|
+
protected initialised: boolean;
|
|
109
|
+
constructor(config: IConfig, metadata: ILendingMetadata);
|
|
110
|
+
/** Async function to init the class */
|
|
111
|
+
abstract init(): Promise<void>;
|
|
112
|
+
/** Wait for initialisation */
|
|
113
|
+
waitForInitilisation(): Promise<void>;
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @param lending_tokens Array of tokens to consider for compute collateral value
|
|
117
|
+
* @param debt_tokens Array of tokens to consider to compute debt values
|
|
118
|
+
* @param user
|
|
119
|
+
*/
|
|
120
|
+
abstract get_health_factor_tokenwise(lending_tokens: TokenInfo[], debt_tokens: TokenInfo[], user: ContractAddr): Promise<number>;
|
|
121
|
+
abstract get_health_factor(user: ContractAddr): Promise<number>;
|
|
122
|
+
abstract getPositionsSummary(user: ContractAddr): Promise<{
|
|
123
|
+
collateralUSD: number;
|
|
124
|
+
debtUSD: number;
|
|
125
|
+
}>;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
declare abstract class Initializable {
|
|
129
|
+
protected initialized: boolean;
|
|
130
|
+
constructor();
|
|
131
|
+
abstract init(): Promise<void>;
|
|
132
|
+
waitForInitilisation(): Promise<void>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class ZkLend extends ILending implements ILending {
|
|
136
|
+
readonly pricer: Pricer;
|
|
137
|
+
static readonly POOLS_URL = "https://app.zklend.com/api/pools";
|
|
138
|
+
private POSITION_URL;
|
|
139
|
+
constructor(config: IConfig, pricer: Pricer);
|
|
140
|
+
init(): Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* @description Get the health factor of the user for given lending and debt tokens
|
|
143
|
+
* @param lending_tokens
|
|
144
|
+
* @param debt_tokens
|
|
145
|
+
* @param user
|
|
146
|
+
* @returns hf (e.g. returns 1.5 for 150% health factor)
|
|
147
|
+
*/
|
|
148
|
+
get_health_factor_tokenwise(lending_tokens: TokenInfo[], debt_tokens: TokenInfo[], user: ContractAddr): Promise<number>;
|
|
149
|
+
/**
|
|
150
|
+
* @description Get the health factor of the user
|
|
151
|
+
* - Considers all tokens for collateral and debt
|
|
152
|
+
*/
|
|
153
|
+
get_health_factor(user: ContractAddr): Promise<number>;
|
|
154
|
+
getPositionsSummary(user: ContractAddr): Promise<{
|
|
155
|
+
collateralUSD: number;
|
|
156
|
+
debtUSD: number;
|
|
157
|
+
}>;
|
|
158
|
+
/**
|
|
159
|
+
* @description Get the token-wise collateral and debt positions of the user
|
|
160
|
+
* @param user Contract address of the user
|
|
161
|
+
* @returns Promise<ILendingPosition[]>
|
|
162
|
+
*/
|
|
163
|
+
getPositions(user: ContractAddr): Promise<ILendingPosition[]>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
declare const logger: {
|
|
167
|
+
verbose(message: string): void;
|
|
168
|
+
assert(condition?: boolean, ...data: any[]): void;
|
|
169
|
+
assert(value: any, message?: string, ...optionalParams: any[]): void;
|
|
170
|
+
clear(): void;
|
|
171
|
+
clear(): void;
|
|
172
|
+
count(label?: string): void;
|
|
173
|
+
count(label?: string): void;
|
|
174
|
+
countReset(label?: string): void;
|
|
175
|
+
countReset(label?: string): void;
|
|
176
|
+
debug(...data: any[]): void;
|
|
177
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
178
|
+
dir(item?: any, options?: any): void;
|
|
179
|
+
dir(obj: any, options?: util.InspectOptions): void;
|
|
180
|
+
dirxml(...data: any[]): void;
|
|
181
|
+
dirxml(...data: any[]): void;
|
|
182
|
+
error(...data: any[]): void;
|
|
183
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
184
|
+
group(...data: any[]): void;
|
|
185
|
+
group(...label: any[]): void;
|
|
186
|
+
groupCollapsed(...data: any[]): void;
|
|
187
|
+
groupCollapsed(...label: any[]): void;
|
|
188
|
+
groupEnd(): void;
|
|
189
|
+
groupEnd(): void;
|
|
190
|
+
info(...data: any[]): void;
|
|
191
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
192
|
+
log(...data: any[]): void;
|
|
193
|
+
log(message?: any, ...optionalParams: any[]): void;
|
|
194
|
+
table(tabularData?: any, properties?: string[]): void;
|
|
195
|
+
table(tabularData: any, properties?: readonly string[]): void;
|
|
196
|
+
time(label?: string): void;
|
|
197
|
+
time(label?: string): void;
|
|
198
|
+
timeEnd(label?: string): void;
|
|
199
|
+
timeEnd(label?: string): void;
|
|
200
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
201
|
+
timeLog(label?: string, ...data: any[]): void;
|
|
202
|
+
timeStamp(label?: string): void;
|
|
203
|
+
timeStamp(label?: string): void;
|
|
204
|
+
trace(...data: any[]): void;
|
|
205
|
+
trace(message?: any, ...optionalParams: any[]): void;
|
|
206
|
+
warn(...data: any[]): void;
|
|
207
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
208
|
+
Console: console.ConsoleConstructor;
|
|
209
|
+
profile(label?: string): void;
|
|
210
|
+
profileEnd(label?: string): void;
|
|
211
|
+
};
|
|
212
|
+
declare class FatalError extends Error {
|
|
213
|
+
constructor(message: string, err?: Error);
|
|
214
|
+
}
|
|
215
|
+
/** Contains globally useful functions.
|
|
216
|
+
* - fatalError: Things to do when a fatal error occurs
|
|
217
|
+
*/
|
|
218
|
+
declare class Global {
|
|
219
|
+
static fatalError(message: string, err?: Error): void;
|
|
220
|
+
static httpError(url: string, err: Error, message?: string): void;
|
|
221
|
+
static getTokens(): Promise<TokenInfo[]>;
|
|
222
|
+
static assert(condition: any, message: string): void;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
declare class AutoCompounderSTRK {
|
|
226
|
+
readonly config: IConfig;
|
|
227
|
+
readonly addr: ContractAddr;
|
|
228
|
+
readonly pricer: Pricer;
|
|
229
|
+
private initialized;
|
|
230
|
+
contract: Contract | null;
|
|
231
|
+
readonly metadata: {
|
|
232
|
+
decimals: number;
|
|
233
|
+
underlying: {
|
|
234
|
+
address: ContractAddr;
|
|
235
|
+
name: string;
|
|
236
|
+
symbol: string;
|
|
237
|
+
};
|
|
238
|
+
name: string;
|
|
239
|
+
};
|
|
240
|
+
constructor(config: IConfig, pricer: Pricer);
|
|
241
|
+
init(): Promise<void>;
|
|
242
|
+
waitForInitilisation(): Promise<void>;
|
|
243
|
+
/** Returns shares of user */
|
|
244
|
+
balanceOf(user: ContractAddr): Promise<Web3Number>;
|
|
245
|
+
/** Returns underlying assets of user */
|
|
246
|
+
balanceOfUnderlying(user: ContractAddr): Promise<Web3Number>;
|
|
247
|
+
/** Returns usd value of assets */
|
|
248
|
+
usdBalanceOfUnderlying(user: ContractAddr): Promise<{
|
|
249
|
+
usd: Web3Number;
|
|
250
|
+
assets: Web3Number;
|
|
251
|
+
}>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class TelegramNotif {
|
|
255
|
+
private subscribers;
|
|
256
|
+
readonly bot: TelegramBot;
|
|
257
|
+
constructor(token: string, shouldPoll: boolean);
|
|
258
|
+
activateChatBot(): void;
|
|
259
|
+
sendMessage(msg: string): void;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @description Config to manage storage of files on disk
|
|
264
|
+
* @param SECRET_FILE_FOLDER - Folder to store secret files (default: ~/.starknet-store)
|
|
265
|
+
* @param NETWORK - Network to use
|
|
266
|
+
*/
|
|
267
|
+
interface StoreConfig {
|
|
268
|
+
SECRET_FILE_FOLDER?: string;
|
|
269
|
+
NETWORK: Network;
|
|
270
|
+
ACCOUNTS_FILE_NAME?: string;
|
|
271
|
+
PASSWORD: string;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* @description Info of a particular account
|
|
275
|
+
*/
|
|
276
|
+
interface AccountInfo {
|
|
277
|
+
address: string;
|
|
278
|
+
pk: string;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @description map of accounts of a network
|
|
282
|
+
*/
|
|
283
|
+
interface NetworkAccounts {
|
|
284
|
+
[accountKey: string]: AccountInfo;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @description map of all accounts of all networks
|
|
288
|
+
*/
|
|
289
|
+
interface AllAccountsStore {
|
|
290
|
+
[networkKey: string]: NetworkAccounts;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* @description StoreConfig with optional fields marked required
|
|
294
|
+
*/
|
|
295
|
+
type RequiredStoreConfig = Required<StoreConfig>;
|
|
296
|
+
/**
|
|
297
|
+
* @description Get the default store config
|
|
298
|
+
* @param network
|
|
299
|
+
* @returns StoreConfig
|
|
300
|
+
*/
|
|
301
|
+
declare function getDefaultStoreConfig(network: Network): RequiredStoreConfig;
|
|
302
|
+
/**
|
|
303
|
+
* @description Store class to manage accounts
|
|
304
|
+
*/
|
|
305
|
+
declare class Store {
|
|
306
|
+
readonly config: IConfig;
|
|
307
|
+
readonly storeConfig: RequiredStoreConfig;
|
|
308
|
+
private encryptor;
|
|
309
|
+
constructor(config: IConfig, storeConfig: StoreConfig);
|
|
310
|
+
static logPassword(password: string): void;
|
|
311
|
+
getAccount(accountKey: string): Account;
|
|
312
|
+
addAccount(accountKey: string, address: string, pk: string): void;
|
|
313
|
+
private getAccountFilePath;
|
|
314
|
+
private getAllAccounts;
|
|
315
|
+
/**
|
|
316
|
+
* @description Load all accounts of the network
|
|
317
|
+
* @returns NetworkAccounts
|
|
318
|
+
*/
|
|
319
|
+
loadAccounts(): NetworkAccounts;
|
|
320
|
+
/**
|
|
321
|
+
* @description List all accountKeys of the network
|
|
322
|
+
* @returns string[]
|
|
323
|
+
*/
|
|
324
|
+
listAccounts(): string[];
|
|
325
|
+
static ensureFolder(folder: string): void;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
declare class PasswordJsonCryptoUtil {
|
|
329
|
+
private readonly algorithm;
|
|
330
|
+
private readonly keyLength;
|
|
331
|
+
private readonly saltLength;
|
|
332
|
+
private readonly ivLength;
|
|
333
|
+
private readonly tagLength;
|
|
334
|
+
private readonly pbkdf2Iterations;
|
|
335
|
+
private deriveKey;
|
|
336
|
+
encrypt(data: any, password: string): string;
|
|
337
|
+
decrypt(encryptedData: string, password: string): any;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
type RequiredFields<T> = {
|
|
341
|
+
[K in keyof T]-?: T[K];
|
|
342
|
+
};
|
|
343
|
+
type RequiredKeys<T> = {
|
|
344
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
|
|
345
|
+
}[keyof T];
|
|
346
|
+
|
|
347
|
+
declare class PricerRedis extends Pricer {
|
|
348
|
+
private redisClient;
|
|
349
|
+
constructor(config: IConfig, tokens: TokenInfo[]);
|
|
350
|
+
/** Reads prices from Pricer._loadPrices and uses a callback to set prices in redis */
|
|
351
|
+
startWithRedis(redisUrl: string): Promise<void>;
|
|
352
|
+
close(): Promise<void>;
|
|
353
|
+
initRedis(redisUrl: string): Promise<void>;
|
|
354
|
+
/** sets current local price in redis */
|
|
355
|
+
private _setRedisPrices;
|
|
356
|
+
/** Returns price from redis */
|
|
357
|
+
getPrice(tokenSymbol: string): Promise<PriceInfo>;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export { type AccountInfo, type AllAccountsStore, AutoCompounderSTRK, ContractAddr, FatalError, Global, type IConfig, ILending, type ILendingMetadata, type ILendingPosition, Initializable, type LendingToken, MarginType, Network, PasswordJsonCryptoUtil, Pragma, type PriceInfo, Pricer, PricerRedis, type RequiredFields, type RequiredKeys, type RequiredStoreConfig, Store, type StoreConfig, TelegramNotif, type TokenInfo, Web3Number, ZkLend, getDefaultStoreConfig, getMainnetConfig, logger };
|