@sonarwatch/portfolio-plugins 0.14.85 → 0.14.86

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.
@@ -0,0 +1,6 @@
1
+ import { Platform } from '@sonarwatch/portfolio-core';
2
+ import { Fetcher } from '../../Fetcher';
3
+ import { Job } from '../../Job';
4
+ export declare const platforms: Platform[];
5
+ export declare const jobs: Job[];
6
+ export declare const fetchers: Fetcher[];
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fetchers = exports.jobs = exports.platforms = void 0;
7
+ const constants_1 = require("./constants");
8
+ const positionsFetcher_1 = __importDefault(require("./positionsFetcher"));
9
+ const marketsJob_1 = __importDefault(require("./marketsJob"));
10
+ exports.platforms = [constants_1.platform];
11
+ exports.jobs = [marketsJob_1.default];
12
+ exports.fetchers = [positionsFetcher_1.default];
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ratex/index.ts"],"names":[],"mappings":";;;;;;AAGA,2CAAuC;AACvC,0EAAkD;AAClD,8DAAsC;AAEzB,QAAA,SAAS,GAAe,CAAC,oBAAQ,CAAC,CAAC;AACnC,QAAA,IAAI,GAAU,CAAC,oBAAU,CAAC,CAAC;AAC3B,QAAA,QAAQ,GAAc,CAAC,0BAAgB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Job } from '../../Job';
2
+ declare const job: Job;
3
+ export default job;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const web3_js_1 = require("@solana/web3.js");
16
+ const bn_js_1 = __importDefault(require("bn.js"));
17
+ const portfolio_core_1 = require("@sonarwatch/portfolio-core");
18
+ const constants_1 = require("./constants");
19
+ const clients_1 = require("../../utils/clients");
20
+ const idl_json_1 = __importDefault(require("./idl.json"));
21
+ const solana_1 = require("../../utils/solana");
22
+ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const connection = (0, clients_1.getClientSolana)();
24
+ const addressLookupTable = (yield connection.getAddressLookupTable(constants_1.programIdLookupTable)).value;
25
+ if (!addressLookupTable)
26
+ return;
27
+ const programs = [];
28
+ for (const programId of addressLookupTable.state.addresses) {
29
+ const [statePda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('ratex_state')], programId);
30
+ const idlItem = {
31
+ programId: programId.toString(),
32
+ idl: idl_json_1.default,
33
+ idlType: 'anchor',
34
+ };
35
+ const states = yield (0, solana_1.getAutoParsedMultipleAccountsInfo)(connection, idlItem, [statePda]);
36
+ if (!states[0])
37
+ continue;
38
+ const marketIndexStart = states[0]['marketIndexStart'];
39
+ const [marginMarketPda] = web3_js_1.PublicKey.findProgramAddressSync([
40
+ Buffer.from('margin_market'),
41
+ new bn_js_1.default(marketIndexStart).toArrayLike(Buffer, 'le', 4),
42
+ ], programId);
43
+ const marginMarkets = yield (0, solana_1.getAutoParsedMultipleAccountsInfo)(connection, idlItem, [marginMarketPda]);
44
+ if (!marginMarkets[0])
45
+ continue;
46
+ programs.push({
47
+ programId: programId.toString(),
48
+ mint: marginMarkets[0].mint,
49
+ });
50
+ }
51
+ yield cache.setItem(constants_1.programsCacheKey, programs, {
52
+ prefix: constants_1.platformId,
53
+ networkId: portfolio_core_1.NetworkId.solana,
54
+ });
55
+ });
56
+ const job = {
57
+ id: `${constants_1.platformId}-markets`,
58
+ executor,
59
+ label: 'normal',
60
+ };
61
+ exports.default = job;
62
+ //# sourceMappingURL=marketsJob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marketsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ratex/marketsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAA4C;AAE5C,kDAAuB;AACvB,+DAAuD;AAGvD,2CAIqB;AACrB,iDAAsD;AACtD,0DAA6B;AAC7B,+CAAuE;AAGvE,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IAErC,MAAM,kBAAkB,GAAG,CACzB,MAAM,UAAU,CAAC,qBAAqB,CAAC,gCAAoB,CAAC,CAC7D,CAAC,KAAK,CAAC;IAER,IAAI,CAAC,kBAAkB;QAAE,OAAO;IAEhC,MAAM,QAAQ,GAAG,EAAE,CAAC;IAEpB,KAAK,MAAM,SAAS,IAAI,kBAAkB,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QAC3D,MAAM,CAAC,QAAQ,CAAC,GAAG,mBAAS,CAAC,sBAAsB,CACjD,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,EAC5B,SAAS,CACV,CAAC;QAEF,MAAM,OAAO,GAAG;YACd,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;YAC/B,GAAG,EAAH,kBAAG;YACH,OAAO,EAAE,QAAQ;SACP,CAAC;QAEb,MAAM,MAAM,GAAG,MAAM,IAAA,0CAAiC,EACpD,UAAU,EACV,OAAO,EACP,CAAC,QAAQ,CAAC,CACX,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAAE,SAAS;QAEzB,MAAM,gBAAgB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAW,CAAC;QAEjE,MAAM,CAAC,eAAe,CAAC,GAAG,mBAAS,CAAC,sBAAsB,CACxD;YACE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;YAC5B,IAAI,eAAE,CAAC,gBAAgB,CAAC,CAAC,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;SACtD,EACD,SAAS,CACV,CAAC;QAEF,MAAM,aAAa,GAAG,MAAM,IAAA,0CAAiC,EAC3D,UAAU,EACV,OAAO,EACP,CAAC,eAAe,CAAC,CAClB,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;YAAE,SAAS;QAEhC,QAAQ,CAAC,IAAI,CAAC;YACZ,SAAS,EAAE,SAAS,CAAC,QAAQ,EAAE;YAC/B,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,CAAC,OAAO,CAAC,4BAAgB,EAAE,QAAQ,EAAE;QAC9C,MAAM,EAAE,sBAAU;QAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,UAAU;IAC3B,QAAQ;IACR,KAAK,EAAE,QAAQ;CAChB,CAAC;AACF,kBAAe,GAAG,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Fetcher } from '../../Fetcher';
2
+ declare const fetcher: Fetcher;
3
+ export default fetcher;
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const portfolio_core_1 = require("@sonarwatch/portfolio-core");
16
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
+ const constants_1 = require("./constants");
18
+ const ElementRegistry_1 = require("../../utils/elementbuilder/ElementRegistry");
19
+ const MemoizedCache_1 = require("../../utils/misc/MemoizedCache");
20
+ const tokenAmountFromLiquidity_1 = require("../../utils/clmm/tokenAmountFromLiquidity");
21
+ const helpers_1 = require("./helpers");
22
+ const programsMemo = new MemoizedCache_1.MemoizedCache(constants_1.programsCacheKey, {
23
+ prefix: constants_1.platformId,
24
+ networkId: portfolio_core_1.NetworkId.solana,
25
+ });
26
+ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const programs = yield programsMemo.getItem(cache);
28
+ if (!programs)
29
+ return [];
30
+ const userStatsByProgram = yield (0, helpers_1.getUserStatsByProgram)(programs, owner);
31
+ const [usersByProgram, lpDatasByProgram] = yield Promise.all([
32
+ (0, helpers_1.getUsersByProgram)(programs, userStatsByProgram, owner),
33
+ (0, helpers_1.getLpDatasByProgram)(programs, userStatsByProgram, owner),
34
+ ]);
35
+ const pools = yield (0, helpers_1.getPools)(programs, lpDatasByProgram, cache);
36
+ const elementRegistry = new ElementRegistry_1.ElementRegistry(portfolio_core_1.NetworkId.solana, constants_1.platformId);
37
+ programs.forEach((program) => {
38
+ const users = usersByProgram.get(program.programId);
39
+ if (users) {
40
+ users.forEach((user) => {
41
+ if (!user)
42
+ return;
43
+ user.marginPositions.forEach((marginPosition) => {
44
+ if (marginPosition.balance !== 0) {
45
+ const element = elementRegistry.addElementMultiple({
46
+ label: 'Margin',
47
+ });
48
+ element.addAsset({
49
+ address: program.mint,
50
+ amount: marginPosition.balance,
51
+ });
52
+ }
53
+ });
54
+ });
55
+ }
56
+ const lpDatas = lpDatasByProgram.get(program.programId);
57
+ if (lpDatas) {
58
+ lpDatas.forEach((lpData) => {
59
+ if (!lpData)
60
+ return;
61
+ const ammpool = pools.get(lpData.ammPosition.ammpool);
62
+ if (!ammpool)
63
+ return;
64
+ const { tokenAmountB } = (0, tokenAmountFromLiquidity_1.getTokenAmountsFromLiquidity)(new bignumber_js_1.default(lpData.ammPosition.liquidity), ammpool.pool.tickCurrentIndex, lpData.ammPosition.tickLowerIndex, lpData.ammPosition.tickUpperIndex, true);
65
+ const amount = new bignumber_js_1.default(lpData.reserveQuoteAmount)
66
+ .plus(tokenAmountB)
67
+ .multipliedBy(Math.pow(10, ammpool.lpMarginDecimals))
68
+ .div(ammpool.rate);
69
+ const element = elementRegistry.addElementMultiple({
70
+ label: 'LiquidityPool',
71
+ });
72
+ element.addAsset({
73
+ address: program.mint,
74
+ amount,
75
+ });
76
+ });
77
+ }
78
+ });
79
+ return elementRegistry.getElements(cache);
80
+ });
81
+ const fetcher = {
82
+ id: `${constants_1.platformId}-positions`,
83
+ networkId: portfolio_core_1.NetworkId.solana,
84
+ executor,
85
+ };
86
+ exports.default = fetcher;
87
+ //# sourceMappingURL=positionsFetcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positionsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ratex/positionsFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuD;AACvD,gEAAqC;AAErC,2CAA2D;AAE3D,gFAA6E;AAC7E,kEAA+D;AAE/D,wFAAyF;AACzF,uCAKmB;AAEnB,MAAM,YAAY,GAAG,IAAI,6BAAa,CAAY,4BAAgB,EAAE;IA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C;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,YAAY;IAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;IAC3B,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -0,0 +1,54 @@
1
+ export type State = {
2
+ marketIndexStart: number;
3
+ };
4
+ export type MarginMarket = {
5
+ pubkey: string;
6
+ mint: string;
7
+ };
8
+ export type Program = {
9
+ programId: string;
10
+ mint: string;
11
+ };
12
+ export type UserStats = {
13
+ numberOfSubAccountsCreated: number;
14
+ };
15
+ export type User = {
16
+ marginPositions: MarginPosition[];
17
+ };
18
+ export type MarginPosition = {
19
+ balance: number;
20
+ marketIndex: number;
21
+ decimals: number;
22
+ };
23
+ export type LP = {
24
+ ammPosition: AmmPosition;
25
+ reserveQuoteAmount: number;
26
+ };
27
+ export type AmmPosition = {
28
+ ammpool: string;
29
+ liquidity: number;
30
+ tickLowerIndex: number;
31
+ tickUpperIndex: number;
32
+ lowerRate: number;
33
+ upperRate: number;
34
+ feeGrowthCheckpointA: number;
35
+ feeOwedA: number;
36
+ feeGrowthCheckpointB: number;
37
+ feeOwedB: number;
38
+ };
39
+ export type YieldMarket = {
40
+ pubkey: string;
41
+ oracle: string;
42
+ pool: Ammpool;
43
+ lpMarginIndex: number;
44
+ lpMarginDecimals: number;
45
+ };
46
+ export type Ammpool = {
47
+ sqrtPrice: number;
48
+ liquidity: number;
49
+ tickCurrentIndex: number;
50
+ };
51
+ export type Oracle = {
52
+ rate: number;
53
+ };
54
+ export type YieldMarketWithOracle = YieldMarket & Oracle;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ratex/types.ts"],"names":[],"mappings":""}