@strkfarm/sdk 1.0.7 → 1.0.9
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 +10 -0
- package/dist/cli.mjs +18 -2
- package/dist/index.browser.global.js +2371 -9
- package/dist/index.d.ts +4 -0
- package/dist/index.js +38 -9
- package/dist/index.mjs +45 -9
- package/package.json +2 -1
- package/src/data/tokens.json +7 -0
- package/src/modules/pricer.ts +38 -7
- package/src/strategies/autoCompounderStrk.ts +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ declare class Pricer {
|
|
|
37
37
|
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
38
38
|
*/
|
|
39
39
|
protected PRICE_API: string;
|
|
40
|
+
protected client: any;
|
|
40
41
|
constructor(config: IConfig, tokens: TokenInfo[]);
|
|
41
42
|
isReady(): boolean;
|
|
42
43
|
waitTillReady(): Promise<void>;
|
|
@@ -45,6 +46,9 @@ declare class Pricer {
|
|
|
45
46
|
assertNotStale(timestamp: Date, tokenName: string): void;
|
|
46
47
|
getPrice(tokenName: string): Promise<PriceInfo>;
|
|
47
48
|
protected _loadPrices(onUpdate?: (tokenSymbol: string) => void): void;
|
|
49
|
+
_getPrice(token: TokenInfo): Promise<number>;
|
|
50
|
+
_getPriceCoinbase(token: TokenInfo): Promise<number>;
|
|
51
|
+
_getPriceCoinMarketCap(token: TokenInfo): Promise<number>;
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
declare class Pragma {
|
package/dist/index.js
CHANGED
|
@@ -126,6 +126,13 @@ var tokens_default = [
|
|
|
126
126
|
address: "",
|
|
127
127
|
decimals: 18,
|
|
128
128
|
pricerKey: "DAI-USDT"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "kSTRK token",
|
|
132
|
+
symbol: "kSTRK",
|
|
133
|
+
address: "",
|
|
134
|
+
decimals: 18,
|
|
135
|
+
pricerKey: "DAI-USDT"
|
|
129
136
|
}
|
|
130
137
|
];
|
|
131
138
|
|
|
@@ -168,6 +175,7 @@ var Global = class {
|
|
|
168
175
|
};
|
|
169
176
|
|
|
170
177
|
// src/modules/pricer.ts
|
|
178
|
+
var CoinMarketCap = require("coinmarketcap-api");
|
|
171
179
|
var Pricer = class {
|
|
172
180
|
constructor(config, tokens) {
|
|
173
181
|
this.tokens = [];
|
|
@@ -176,6 +184,8 @@ var Pricer = class {
|
|
|
176
184
|
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
177
185
|
*/
|
|
178
186
|
this.PRICE_API = `https://api.coinbase.com/v2/prices/{{PRICER_KEY}}/buy`;
|
|
187
|
+
// backup oracle
|
|
188
|
+
this.client = new CoinMarketCap(process.env.COINMARKETCAP_KEY);
|
|
179
189
|
this.config = config;
|
|
180
190
|
this.tokens = tokens;
|
|
181
191
|
}
|
|
@@ -239,13 +249,7 @@ var Pricer = class {
|
|
|
239
249
|
onUpdate(token.symbol);
|
|
240
250
|
return;
|
|
241
251
|
}
|
|
242
|
-
|
|
243
|
-
throw new FatalError(`Pricer key not found for ${token.name}`);
|
|
244
|
-
}
|
|
245
|
-
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
246
|
-
const result = await import_axios.default.get(url);
|
|
247
|
-
const data = result.data;
|
|
248
|
-
const price = Number(data.data.amount);
|
|
252
|
+
const price = await this._getPrice(token);
|
|
249
253
|
this.prices[token.symbol] = {
|
|
250
254
|
price,
|
|
251
255
|
timestamp: /* @__PURE__ */ new Date()
|
|
@@ -272,6 +276,30 @@ var Pricer = class {
|
|
|
272
276
|
});
|
|
273
277
|
}
|
|
274
278
|
}
|
|
279
|
+
async _getPrice(token) {
|
|
280
|
+
try {
|
|
281
|
+
return await this._getPriceCoinbase(token);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
return await this._getPriceCoinMarketCap(token);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
}
|
|
288
|
+
throw new FatalError(`Price not found for ${token.name}`);
|
|
289
|
+
}
|
|
290
|
+
async _getPriceCoinbase(token) {
|
|
291
|
+
if (!token.pricerKey) {
|
|
292
|
+
throw new FatalError(`Pricer key not found for ${token.name}`);
|
|
293
|
+
}
|
|
294
|
+
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
295
|
+
const result = await import_axios.default.get(url);
|
|
296
|
+
const data = result.data;
|
|
297
|
+
return Number(data.data.amount);
|
|
298
|
+
}
|
|
299
|
+
async _getPriceCoinMarketCap(token) {
|
|
300
|
+
const result = await this.client.getQuotes({ symbol: token.symbol });
|
|
301
|
+
return result.data[token.symbol].quote.USD.price;
|
|
302
|
+
}
|
|
275
303
|
};
|
|
276
304
|
|
|
277
305
|
// src/modules/pragma.ts
|
|
@@ -682,8 +710,9 @@ var AutoCompounderSTRK = class {
|
|
|
682
710
|
this.init();
|
|
683
711
|
}
|
|
684
712
|
async init() {
|
|
685
|
-
const
|
|
686
|
-
|
|
713
|
+
const provider = this.config.provider;
|
|
714
|
+
const cls = await provider.getClassAt(this.addr.address);
|
|
715
|
+
this.contract = new import_starknet4.Contract(cls.abi, this.addr.address, provider);
|
|
687
716
|
this.initialized = true;
|
|
688
717
|
}
|
|
689
718
|
async waitForInitilisation() {
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/modules/pricer.ts
|
|
2
9
|
import axios from "axios";
|
|
3
10
|
|
|
@@ -72,6 +79,13 @@ var tokens_default = [
|
|
|
72
79
|
address: "",
|
|
73
80
|
decimals: 18,
|
|
74
81
|
pricerKey: "DAI-USDT"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "kSTRK token",
|
|
85
|
+
symbol: "kSTRK",
|
|
86
|
+
address: "",
|
|
87
|
+
decimals: 18,
|
|
88
|
+
pricerKey: "DAI-USDT"
|
|
75
89
|
}
|
|
76
90
|
];
|
|
77
91
|
|
|
@@ -114,6 +128,7 @@ var Global = class {
|
|
|
114
128
|
};
|
|
115
129
|
|
|
116
130
|
// src/modules/pricer.ts
|
|
131
|
+
var CoinMarketCap = __require("coinmarketcap-api");
|
|
117
132
|
var Pricer = class {
|
|
118
133
|
constructor(config, tokens) {
|
|
119
134
|
this.tokens = [];
|
|
@@ -122,6 +137,8 @@ var Pricer = class {
|
|
|
122
137
|
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
123
138
|
*/
|
|
124
139
|
this.PRICE_API = `https://api.coinbase.com/v2/prices/{{PRICER_KEY}}/buy`;
|
|
140
|
+
// backup oracle
|
|
141
|
+
this.client = new CoinMarketCap(process.env.COINMARKETCAP_KEY);
|
|
125
142
|
this.config = config;
|
|
126
143
|
this.tokens = tokens;
|
|
127
144
|
}
|
|
@@ -185,13 +202,7 @@ var Pricer = class {
|
|
|
185
202
|
onUpdate(token.symbol);
|
|
186
203
|
return;
|
|
187
204
|
}
|
|
188
|
-
|
|
189
|
-
throw new FatalError(`Pricer key not found for ${token.name}`);
|
|
190
|
-
}
|
|
191
|
-
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
192
|
-
const result = await axios.get(url);
|
|
193
|
-
const data = result.data;
|
|
194
|
-
const price = Number(data.data.amount);
|
|
205
|
+
const price = await this._getPrice(token);
|
|
195
206
|
this.prices[token.symbol] = {
|
|
196
207
|
price,
|
|
197
208
|
timestamp: /* @__PURE__ */ new Date()
|
|
@@ -218,6 +229,30 @@ var Pricer = class {
|
|
|
218
229
|
});
|
|
219
230
|
}
|
|
220
231
|
}
|
|
232
|
+
async _getPrice(token) {
|
|
233
|
+
try {
|
|
234
|
+
return await this._getPriceCoinbase(token);
|
|
235
|
+
} catch (error) {
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
return await this._getPriceCoinMarketCap(token);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
}
|
|
241
|
+
throw new FatalError(`Price not found for ${token.name}`);
|
|
242
|
+
}
|
|
243
|
+
async _getPriceCoinbase(token) {
|
|
244
|
+
if (!token.pricerKey) {
|
|
245
|
+
throw new FatalError(`Pricer key not found for ${token.name}`);
|
|
246
|
+
}
|
|
247
|
+
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
248
|
+
const result = await axios.get(url);
|
|
249
|
+
const data = result.data;
|
|
250
|
+
return Number(data.data.amount);
|
|
251
|
+
}
|
|
252
|
+
async _getPriceCoinMarketCap(token) {
|
|
253
|
+
const result = await this.client.getQuotes({ symbol: token.symbol });
|
|
254
|
+
return result.data[token.symbol].quote.USD.price;
|
|
255
|
+
}
|
|
221
256
|
};
|
|
222
257
|
|
|
223
258
|
// src/modules/pragma.ts
|
|
@@ -628,8 +663,9 @@ var AutoCompounderSTRK = class {
|
|
|
628
663
|
this.init();
|
|
629
664
|
}
|
|
630
665
|
async init() {
|
|
631
|
-
const
|
|
632
|
-
|
|
666
|
+
const provider = this.config.provider;
|
|
667
|
+
const cls = await provider.getClassAt(this.addr.address);
|
|
668
|
+
this.contract = new Contract2(cls.abi, this.addr.address, provider);
|
|
633
669
|
this.initialized = true;
|
|
634
670
|
}
|
|
635
671
|
async waitForInitilisation() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strkfarm/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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
|
"main": "dist/index.js",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"bignumber.js": "4.0.4",
|
|
49
49
|
"browser-assert": "^1.2.1",
|
|
50
50
|
"chalk": "^4.1.2",
|
|
51
|
+
"coinmarketcap-api": "^3.1.1",
|
|
51
52
|
"commander": "^12.1.0",
|
|
52
53
|
"inquirer": "^10.1.2",
|
|
53
54
|
"node-telegram-bot-api": "^0.66.0",
|
package/src/data/tokens.json
CHANGED
package/src/modules/pricer.ts
CHANGED
|
@@ -2,6 +2,7 @@ import axios from "axios";
|
|
|
2
2
|
import { FatalError, Global, logger } from "@/global";
|
|
3
3
|
import { TokenInfo } from "@/interfaces/common";
|
|
4
4
|
import { IConfig } from "@/interfaces/common";
|
|
5
|
+
const CoinMarketCap = require('coinmarketcap-api')
|
|
5
6
|
|
|
6
7
|
export interface PriceInfo {
|
|
7
8
|
price: number,
|
|
@@ -18,6 +19,10 @@ export class Pricer {
|
|
|
18
19
|
* TOKENA and TOKENB are the two token names to get price of TokenA in terms of TokenB
|
|
19
20
|
*/
|
|
20
21
|
protected PRICE_API = `https://api.coinbase.com/v2/prices/{{PRICER_KEY}}/buy`;
|
|
22
|
+
|
|
23
|
+
// backup oracle
|
|
24
|
+
protected client = new CoinMarketCap(process.env.COINMARKETCAP_KEY!);
|
|
25
|
+
|
|
21
26
|
constructor(config: IConfig, tokens: TokenInfo[]) {
|
|
22
27
|
this.config = config;
|
|
23
28
|
this.tokens = tokens;
|
|
@@ -89,13 +94,8 @@ export class Pricer {
|
|
|
89
94
|
onUpdate(token.symbol);
|
|
90
95
|
return;
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
96
|
-
const result = await axios.get(url);
|
|
97
|
-
const data: any = result.data;
|
|
98
|
-
const price = Number(data.data.amount);
|
|
97
|
+
|
|
98
|
+
const price = await this._getPrice(token);
|
|
99
99
|
this.prices[token.symbol] = {
|
|
100
100
|
price,
|
|
101
101
|
timestamp: new Date()
|
|
@@ -122,4 +122,35 @@ export class Pricer {
|
|
|
122
122
|
})
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
|
|
126
|
+
async _getPrice(token: TokenInfo) {
|
|
127
|
+
try {
|
|
128
|
+
return await this._getPriceCoinbase(token);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
// do nothing, try next
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
return await this._getPriceCoinMarketCap(token);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
// do nothing, try next
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
throw new FatalError(`Price not found for ${token.name}`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async _getPriceCoinbase(token: TokenInfo) {
|
|
143
|
+
if (!token.pricerKey) {
|
|
144
|
+
throw new FatalError(`Pricer key not found for ${token.name}`);
|
|
145
|
+
}
|
|
146
|
+
const url = this.PRICE_API.replace("{{PRICER_KEY}}", token.pricerKey);
|
|
147
|
+
const result = await axios.get(url);
|
|
148
|
+
const data: any = result.data;
|
|
149
|
+
return Number(data.data.amount);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async _getPriceCoinMarketCap(token: TokenInfo): Promise<number> {
|
|
153
|
+
const result = await this.client.getQuotes({symbol: token.symbol});
|
|
154
|
+
return result.data[token.symbol].quote.USD.price as number
|
|
155
|
+
}
|
|
125
156
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
2
2
|
import { IConfig } from "@/interfaces";
|
|
3
|
-
import { Contract, uint256 } from "starknet";
|
|
3
|
+
import { Contract, RpcProvider, uint256 } from "starknet";
|
|
4
4
|
import { Pricer } from "@/modules/pricer";
|
|
5
5
|
|
|
6
6
|
export class AutoCompounderSTRK {
|
|
@@ -29,8 +29,9 @@ export class AutoCompounderSTRK {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
async init() {
|
|
32
|
-
const
|
|
33
|
-
|
|
32
|
+
const provider: RpcProvider = this.config.provider;
|
|
33
|
+
const cls = await provider.getClassAt(this.addr.address);
|
|
34
|
+
this.contract = new Contract(cls.abi, this.addr.address, provider);
|
|
34
35
|
this.initialized = true;
|
|
35
36
|
}
|
|
36
37
|
|