@strkfarm/sdk 1.0.37 → 1.0.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "description": "STRKFarm TS SDK (Meant for our internal use, but feel free to use it)",
5
5
  "typings": "dist/index.d.ts",
6
6
  "types": "dist/index.d.ts",
@@ -51,7 +51,8 @@
51
51
  "typescript": "^5.5.3"
52
52
  },
53
53
  "peerDependencies": {
54
- "react": "19.1.0"
54
+ "react": "19.1.0",
55
+ "starknet": "^6.11.0"
55
56
  },
56
57
  "dependencies": {
57
58
  "@avnu/avnu-sdk": "^3.0.2",
@@ -67,7 +68,6 @@
67
68
  "proxy-from-env": "^1.1.0",
68
69
  "redis": "^4.7.0",
69
70
  "stacktrace-js": "^2.0.2",
70
- "starknet": "^6.11.0",
71
71
  "winston": "^3.13.0"
72
72
  }
73
73
  }
@@ -1,65 +1,67 @@
1
- import { logger } from "@/global";
1
+ import { logger } from "@/utils/logger";
2
2
  import BigNumber from "bignumber.js";
3
3
 
4
4
  export class _Web3Number<T extends _Web3Number<T>> extends BigNumber {
5
- decimals: number;
5
+ decimals: number;
6
6
 
7
- constructor(value: string | number, decimals: number) {
8
- super(value);
9
- this.decimals = decimals;
10
- }
7
+ constructor(value: string | number, decimals: number) {
8
+ super(value);
9
+ this.decimals = decimals;
10
+ }
11
11
 
12
- toWei() {
13
- return this.mul(10 ** this.decimals).toFixed(0);
14
- }
12
+ toWei() {
13
+ return this.mul(10 ** this.decimals).toFixed(0);
14
+ }
15
15
 
16
- multipliedBy(value: string | number | T): T {
17
- const _value = this.getStandardString(value);
18
- return this.construct(this.mul(_value).toString(), this.decimals);
19
- }
16
+ multipliedBy(value: string | number | T): T {
17
+ const _value = this.getStandardString(value);
18
+ return this.construct(this.mul(_value).toString(), this.decimals);
19
+ }
20
20
 
21
- dividedBy(value: string | number | T): T {
22
- const _value = this.getStandardString(value);
23
- return this.construct(this.div(_value).toString(), this.decimals);
24
- }
21
+ dividedBy(value: string | number | T): T {
22
+ const _value = this.getStandardString(value);
23
+ return this.construct(this.div(_value).toString(), this.decimals);
24
+ }
25
25
 
26
- plus(value: string | number | T): T {
27
- const _value = this.getStandardString(value);
28
- return this.construct(this.add(_value).toString(), this.decimals);
29
- }
26
+ plus(value: string | number | T): T {
27
+ const _value = this.getStandardString(value);
28
+ return this.construct(this.add(_value).toString(), this.decimals);
29
+ }
30
30
 
31
- minus(n: number | string | T, base?: number): T {
32
- const _value = this.getStandardString(n);
33
- return this.construct(super.minus(_value, base).toString(), this.decimals);
34
- }
31
+ minus(n: number | string | T, base?: number): T {
32
+ const _value = this.getStandardString(n);
33
+ return this.construct(super.minus(_value, base).toString(), this.decimals);
34
+ }
35
35
 
36
- protected construct(value: string | number, decimals: number): T {
37
- return new (this.constructor as { new (value: string | number, decimals: number): T })(value, decimals);
38
- }
36
+ protected construct(value: string | number, decimals: number): T {
37
+ return new (this.constructor as {
38
+ new (value: string | number, decimals: number): T;
39
+ })(value, decimals);
40
+ }
39
41
 
40
- toString(decimals: number | undefined = this.maxToFixedDecimals()): string {
41
- return super.toFixed(decimals);
42
- }
42
+ toString(): string {
43
+ return super.toString();
44
+ }
43
45
 
44
- toJSON() {
45
- return this.toString();
46
- }
46
+ toJSON() {
47
+ return this.toString();
48
+ }
47
49
 
48
- valueOf() {
49
- return this.toString();
50
- }
50
+ valueOf() {
51
+ return this.toString();
52
+ }
51
53
 
52
- private maxToFixedDecimals() {
53
- return Math.min(this.decimals, 18);
54
- }
54
+ private maxToFixedDecimals() {
55
+ return Math.min(this.decimals, 18);
56
+ }
55
57
 
56
- private getStandardString(value: string | number | T): string {
57
- if (typeof value == 'string') {
58
- return value
59
- }
60
- return value.toFixed(this.maxToFixedDecimals())
58
+ private getStandardString(value: string | number | T): string {
59
+ if (typeof value == "string") {
60
+ return value;
61
61
  }
62
+ return value.toFixed(this.maxToFixedDecimals());
63
+ }
62
64
  }
63
65
 
64
- BigNumber.config({ DECIMAL_PLACES: 18, ROUNDING_MODE: BigNumber.ROUND_DOWN })
65
- _Web3Number.config({ DECIMAL_PLACES: 18, ROUNDING_MODE: BigNumber.ROUND_DOWN })
66
+ BigNumber.config({ DECIMAL_PLACES: 18, ROUNDING_MODE: BigNumber.ROUND_DOWN });
67
+ _Web3Number.config({ DECIMAL_PLACES: 18, ROUNDING_MODE: BigNumber.ROUND_DOWN });
package/src/global.ts CHANGED
@@ -1,39 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import { TokenInfo } from './interfaces';
3
3
  import { ContractAddr } from './dataTypes';
4
-
5
- const colors = {
6
- error: 'red',
7
- warn: 'yellow',
8
- info: 'blue',
9
- verbose: 'white',
10
- debug: 'white',
11
- }
12
-
13
- // Add custom colors to Winston
14
- // winston.addColors(colors);
15
-
16
- // export const logger = createLogger({
17
- // level: 'verbose', // Set the minimum logging level
18
- // format: format.combine(
19
- // format.colorize({ all: true }), // Apply custom colors
20
- // format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), // Add timestamp to log messages
21
- // format.printf(({ timestamp, level, message }) => {
22
- // return `${timestamp} ${level}: ${message}`;
23
- // })
24
- // ),
25
- // transports: [
26
- // // new transports.Console() // Output logs to the console
27
- // ]
28
- // });
29
-
30
-
31
- export const logger = {
32
- ...console,
33
- verbose(message: string) {
34
- console.log(`[VERBOSE] ${message}`);
35
- }
36
- };
4
+ import { logger } from '@/utils/logger';
37
5
 
38
6
 
39
7
  export class FatalError extends Error {
@@ -1,60 +1,65 @@
1
- import { ContractAddr, Web3Number } from "@/dataTypes"
2
- import { BlockIdentifier, RpcProvider } from "starknet"
3
- import React from 'react';
1
+ import { ContractAddr, Web3Number } from "@/dataTypes";
2
+ import { BlockIdentifier, RpcProvider } from "starknet";
3
+ import React from "react";
4
4
 
5
5
  export enum RiskType {
6
- MARKET_RISK = 'Market Risk',
7
- // if non-correalted pairs, this is 3 (STRK/USDC)
8
- // if highly correalted pairs, this is 1 (e.g. xSTRK/STRK)
9
- // if correalted pairs, this is 2 (e.g. BTC/SOL)
10
- // If there is added leverage on top, can go till 5
11
- IMPERMANENT_LOSS = 'Impermanent Loss Risk',
12
- LIQUIDATION_RISK = 'Liquidation Risk',
13
- LOW_LIQUIDITY_RISK = 'Low Liquidity Risk',
14
- SMART_CONTRACT_RISK = 'Smart Contract Risk',
15
- ORACLE_RISK = 'Oracle Risk',
16
- TECHNICAL_RISK = 'Technical Risk',
17
- COUNTERPARTY_RISK = 'Counterparty Risk', // e.g. bad debt
6
+ MARKET_RISK = "Market Risk",
7
+ // if non-correalted pairs, this is 3 (STRK/USDC)
8
+ // if highly correalted pairs, this is 1 (e.g. xSTRK/STRK)
9
+ // if correalted pairs, this is 2 (e.g. BTC/SOL)
10
+ // If there is added leverage on top, can go till 5
11
+ IMPERMANENT_LOSS = "Impermanent Loss Risk",
12
+ LIQUIDATION_RISK = "Liquidation Risk",
13
+ LOW_LIQUIDITY_RISK = "Low Liquidity Risk",
14
+ SMART_CONTRACT_RISK = "Smart Contract Risk",
15
+ ORACLE_RISK = "Oracle Risk",
16
+ TECHNICAL_RISK = "Technical Risk",
17
+ COUNTERPARTY_RISK = "Counterparty Risk" // e.g. bad debt
18
18
  }
19
19
 
20
20
  export interface RiskFactor {
21
- type: RiskType,
22
- value: number, // 0 to 5
23
- weight: number // 0 to 100
21
+ type: RiskType;
22
+ value: number; // 0 to 5
23
+ weight: number; // 0 to 100
24
24
  }
25
25
 
26
26
  export interface TokenInfo {
27
- name: string,
28
- symbol: string,
29
- address: ContractAddr,
30
- decimals: number,
31
- logo: string,
32
- coingeckId?: string,
33
- displayDecimals: number
27
+ name: string;
28
+ symbol: string;
29
+ address: ContractAddr;
30
+ decimals: number;
31
+ logo: string;
32
+ coingeckId?: string;
33
+ displayDecimals: number;
34
34
  }
35
35
 
36
36
  export enum Network {
37
- mainnet = "mainnet",
38
- sepolia = "sepolia",
39
- devnet = "devnet"
37
+ mainnet = "mainnet",
38
+ sepolia = "sepolia",
39
+ devnet = "devnet"
40
40
  }
41
41
 
42
42
  export interface IConfig {
43
- provider: RpcProvider,
44
- network: Network,
45
- stage: 'production' | 'staging',
46
- heartbeatUrl?: string
43
+ provider: RpcProvider;
44
+ network: Network;
45
+ stage: "production" | "staging";
46
+ heartbeatUrl?: string;
47
47
  }
48
48
 
49
49
  export interface IProtocol {
50
- name: string,
51
- logo: string,
50
+ name: string;
51
+ logo: string;
52
52
  }
53
53
 
54
54
  export enum FlowChartColors {
55
- Green = 'purple',
56
- Blue = '#35484f',
57
- Purple = '#6e53dc',
55
+ Green = "purple",
56
+ Blue = "#35484f",
57
+ Purple = "#6e53dc"
58
+ }
59
+
60
+ export interface FAQ {
61
+ question: string | React.ReactNode;
62
+ answer: string | React.ReactNode;
58
63
  }
59
64
 
60
65
  /**
@@ -62,78 +67,87 @@ export enum FlowChartColors {
62
67
  * @property risk.riskFactor.factor - The value of the risk factor from 0 to 10, 0 being the lowest and 10 being the highest.
63
68
  */
64
69
  export interface IStrategyMetadata<T> {
65
- name: string,
66
- description: string | React.ReactNode,
67
- address: ContractAddr,
68
- type: 'ERC4626' | 'ERC721' | 'Other',
69
- depositTokens: TokenInfo[],
70
- protocols: IProtocol[],
71
- auditUrl?: string,
72
- maxTVL: Web3Number,
73
- risk: {
74
- riskFactor: RiskFactor[],
75
- netRisk: number,
76
- notARisks: string[]
77
- },
78
- apyMethodology?: string,
79
- additionalInfo: T
70
+ name: string;
71
+ description: string | React.ReactNode;
72
+ address: ContractAddr;
73
+ launchBlock: number;
74
+ type: "ERC4626" | "ERC721" | "Other";
75
+ depositTokens: TokenInfo[];
76
+ protocols: IProtocol[];
77
+ auditUrl?: string;
78
+ maxTVL: Web3Number;
79
+ risk: {
80
+ riskFactor: RiskFactor[];
81
+ netRisk: number;
82
+ notARisks: string[];
83
+ };
84
+ apyMethodology?: string;
85
+ additionalInfo: T;
86
+ faqs: FAQ[];
80
87
  }
81
88
 
82
89
  export interface IInvestmentFlow {
83
- id?: string, // used to link flows
84
- title: string,
85
- subItems: {key: string, value: string}[],
86
- linkedFlows: IInvestmentFlow[],
87
- style?: any
90
+ id?: string; // used to link flows
91
+ title: string;
92
+ subItems: { key: string; value: string }[];
93
+ linkedFlows: IInvestmentFlow[];
94
+ style?: any;
88
95
  }
89
96
 
90
- export function getMainnetConfig(rpcUrl = "https://starknet-mainnet.public.blastapi.io", blockIdentifier: BlockIdentifier = 'pending'): IConfig {
91
- return {
92
- provider: new RpcProvider({
93
- nodeUrl: rpcUrl,
94
- blockIdentifier: blockIdentifier
95
- }),
96
- stage: "production",
97
- network: Network.mainnet
98
- }
97
+ export function getMainnetConfig(
98
+ rpcUrl = "https://starknet-mainnet.public.blastapi.io",
99
+ blockIdentifier: BlockIdentifier = "pending"
100
+ ): IConfig {
101
+ return {
102
+ provider: new RpcProvider({
103
+ nodeUrl: rpcUrl,
104
+ blockIdentifier: blockIdentifier
105
+ }),
106
+ stage: "production",
107
+ network: Network.mainnet
108
+ };
99
109
  }
100
110
 
101
111
  export const getRiskExplaination = (riskType: RiskType) => {
102
- switch (riskType) {
103
- case RiskType.MARKET_RISK:
104
- return "The risk of the market moving against the position."
105
- case RiskType.IMPERMANENT_LOSS:
106
- return "The temporary loss of value experienced by liquidity providers in AMMs when asset prices diverge compared to simply holding them."
107
- case RiskType.LIQUIDATION_RISK:
108
- return "The risk of losing funds due to the position being liquidated."
109
- case RiskType.LOW_LIQUIDITY_RISK:
110
- return "The risk of low liquidity in the pool, which can lead to high slippages or reduced in-abilities to quickly exit the position."
111
- case RiskType.ORACLE_RISK:
112
- return "The risk of the oracle being manipulated or incorrect."
113
- case RiskType.SMART_CONTRACT_RISK:
114
- return "The risk of the smart contract being vulnerable to attacks."
115
- case RiskType.TECHNICAL_RISK:
116
- return "The risk of technical issues e.g. backend failure."
117
- case RiskType.COUNTERPARTY_RISK:
118
- return "The risk of the counterparty defaulting e.g. bad debt on lending platforms."
119
- }
120
- }
112
+ switch (riskType) {
113
+ case RiskType.MARKET_RISK:
114
+ return "The risk of the market moving against the position.";
115
+ case RiskType.IMPERMANENT_LOSS:
116
+ return "The temporary loss of value experienced by liquidity providers in AMMs when asset prices diverge compared to simply holding them.";
117
+ case RiskType.LIQUIDATION_RISK:
118
+ return "The risk of losing funds due to the position being liquidated.";
119
+ case RiskType.LOW_LIQUIDITY_RISK:
120
+ return "The risk of low liquidity in the pool, which can lead to high slippages or reduced in-abilities to quickly exit the position.";
121
+ case RiskType.ORACLE_RISK:
122
+ return "The risk of the oracle being manipulated or incorrect.";
123
+ case RiskType.SMART_CONTRACT_RISK:
124
+ return "The risk of the smart contract being vulnerable to attacks.";
125
+ case RiskType.TECHNICAL_RISK:
126
+ return "The risk of technical issues e.g. backend failure.";
127
+ case RiskType.COUNTERPARTY_RISK:
128
+ return "The risk of the counterparty defaulting e.g. bad debt on lending platforms.";
129
+ }
130
+ };
121
131
 
122
132
  export const getRiskColor = (risk: RiskFactor) => {
123
- const value = risk.value;
124
- if (value === 0) return 'green';
125
- if (value < 2.5) return 'yellow';
126
- return 'red';
127
- }
133
+ const value = risk.value;
134
+ if (value === 0) return "green";
135
+ if (value < 2.5) return "yellow";
136
+ return "red";
137
+ };
128
138
 
129
139
  export const getNoRiskTags = (risks: RiskFactor[]) => {
130
- const noRisks1 = risks.filter(risk => risk.value === 0).map(risk => risk.type);
140
+ const noRisks1 = risks
141
+ .filter((risk) => risk.value === 0)
142
+ .map((risk) => risk.type);
143
+
144
+ // const risks not present
145
+ const noRisks2 = Object.values(RiskType).filter(
146
+ (risk) => !risks.map((risk) => risk.type).includes(risk)
147
+ );
131
148
 
132
- // const risks not present
133
- const noRisks2 = Object.values(RiskType).filter(risk => !risks.map(risk => risk.type).includes(risk));
149
+ const mergedUnique = [...new Set([...noRisks1, ...noRisks2])];
134
150
 
135
- const mergedUnique = [...new Set([...noRisks1, ...noRisks2])];
136
-
137
- // add `No` to the start of each risk
138
- return mergedUnique.map(risk => `No ${risk}`);
139
- }
151
+ // add `No` to the start of each risk
152
+ return mergedUnique.map((risk) => `No ${risk}`);
153
+ };
@@ -1,10 +1,9 @@
1
1
  import { IConfig } from "@/interfaces/common";
2
2
  import { TokenInfo } from "./common";
3
3
  import { ContractAddr } from "@/dataTypes/address";
4
- import { loggers } from "winston";
5
- import { logger } from "@/global";
6
4
  import { log } from "console";
7
5
  import { Web3Number } from "@/dataTypes";
6
+ import { logger } from "@/utils/logger";
8
7
 
9
8
  export interface ILendingMetadata {
10
9
  name: string;
@@ -3,7 +3,7 @@ import { uint256 } from "starknet";
3
3
  import { Call, Uint256 } from "starknet";
4
4
  import { fetchBuildExecuteTransaction, fetchQuotes, Quote } from "@avnu/avnu-sdk";
5
5
  import { assert } from "../utils";
6
- import { logger } from "@/global";
6
+ import { logger } from "@/utils/logger";
7
7
 
8
8
  export interface Route {
9
9
  token_from: string,
@@ -20,4 +20,10 @@ export class ERC20 {
20
20
  const balance = await contract.call('balanceOf', [address.toString()]);
21
21
  return Web3Number.fromWei(balance.toString(), tokenDecimals);
22
22
  }
23
+
24
+ async allowance(token: string | ContractAddr, owner: string | ContractAddr, spender: string | ContractAddr, tokenDecimals: number) {
25
+ const contract = this.contract(token);
26
+ const allowance = await contract.call('allowance', [owner.toString(), spender.toString()]);
27
+ return Web3Number.fromWei(allowance.toString(), tokenDecimals);
28
+ }
23
29
  }
@@ -1,5 +1,5 @@
1
1
  import { ContractAddr, Web3Number } from "@/dataTypes";
2
- import { logger } from "@/global";
2
+ import { logger } from "@/utils/logger";
3
3
  import { IConfig } from "@/interfaces";
4
4
  import { assert } from "@/utils";
5
5
  import { Contract, num } from "starknet";
@@ -1,6 +1,6 @@
1
1
  import { Contract, RpcProvider } from "starknet";
2
2
  import PragmaAbi from '@/data/pragma.abi.json';
3
- import { logger } from "@/global";
3
+ import { logger } from "@/utils/logger";
4
4
 
5
5
  export class Pragma {
6
6
  contractAddr = '0x023fb3afbff2c0e3399f896dcf7400acf1a161941cfb386e34a123f228c62832';
@@ -1,8 +1,8 @@
1
- import { logger } from "@/global";
2
- import { PriceInfo } from "./pricer";
1
+ import { PriceInfo } from "./pricer";
3
2
  import axios from "axios";
4
3
  import { IConfig, TokenInfo } from "@/interfaces";
5
4
  import { PricerBase } from "./pricerBase";
5
+ import { logger } from "@/utils/logger";
6
6
 
7
7
  export class PricerFromApi extends PricerBase {
8
8
  constructor(config: IConfig, tokens: TokenInfo[]) {
@@ -15,7 +15,7 @@ export class PricerFromApi extends PricerBase {
15
15
  } catch (e: any) {
16
16
  logger.warn('getPriceFromMyAPI error', JSON.stringify(e.message || e));
17
17
  }
18
- logger.log('getPrice coinbase', tokenSymbol);
18
+ logger.info('getPrice coinbase', tokenSymbol);
19
19
  let retry = 0;
20
20
  const MAX_RETRIES = 5;
21
21
  for (retry = 1; retry < MAX_RETRIES + 1; retry++) {
@@ -1,9 +1,10 @@
1
1
  import axios from "axios";
2
- import { FatalError, Global, logger } from "@/global";
2
+ import { FatalError, Global } from "@/global";
3
3
  import { TokenInfo } from "@/interfaces/common";
4
4
  import { IConfig } from "@/interfaces/common";
5
5
  import { Web3Number } from "@/dataTypes";
6
6
  import { PricerBase } from "./pricerBase";
7
+ import { logger } from "@/utils/logger";
7
8
 
8
9
  export interface PriceInfo {
9
10
  price: number,
@@ -1,12 +1,13 @@
1
1
  import axios from "axios";
2
2
  import BigNumber from "bignumber.js";
3
3
  import { Web3Number } from "@/dataTypes/bignumber.browser";
4
- import { FatalError, Global, logger } from "@/global";
4
+ import { FatalError, Global } from "@/global";
5
5
  import { TokenInfo } from "@/interfaces";
6
6
  import { ILending, ILendingPosition, LendingToken, MarginType } from "@/interfaces/lending";
7
7
  import { ContractAddr } from "@/dataTypes/address";
8
8
  import { IConfig } from "@/interfaces";
9
9
  import { Pricer } from "./pricer";
10
+ import { logger } from "@/utils/logger";
10
11
 
11
12
  export class ZkLend extends ILending implements ILending {
12
13
  readonly pricer: Pricer;
@@ -1,8 +1,9 @@
1
- import { FatalError, Global, logger } from '@/global';
1
+ import { FatalError, Global } from '@/global';
2
2
  import { IConfig, TokenInfo } from '@/interfaces';
3
3
  import { PriceInfo, Pricer } from '@/modules/pricer';
4
4
  import { createClient } from 'redis';
5
5
  import type { RedisClientType } from 'redis'
6
+ import { logger } from "@/utils/logger";
6
7
 
7
8
  export class PricerRedis extends Pricer {
8
9
  private redisClient: RedisClientType | null = null;
@@ -1,5 +1,5 @@
1
- import { logger } from "@/global";
2
1
  import TelegramBot from "node-telegram-bot-api";
2
+ import { logger } from "@/utils/logger";
3
3
 
4
4
  export class TelegramNotif {
5
5
  private subscribers: string[] = [