@sonarwatch/portfolio-plugins 0.12.179 → 0.12.181

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. package/CHANGELOG.md +1514 -1506
  2. package/README.md +3 -3
  3. package/package.json +1 -1
  4. package/src/index.js +5 -0
  5. package/src/index.js.map +1 -1
  6. package/src/plugins/balancer/helpers/pools.js +21 -21
  7. package/src/plugins/bucket/bucketsJob.js +71 -0
  8. package/src/plugins/bucket/bucketsJob.js.map +1 -0
  9. package/src/plugins/bucket/collateralFetcher.js +46 -60
  10. package/src/plugins/bucket/collateralFetcher.js.map +1 -1
  11. package/src/plugins/bucket/constants.d.ts +8 -5
  12. package/src/plugins/bucket/constants.js +11 -20
  13. package/src/plugins/bucket/constants.js.map +1 -1
  14. package/src/plugins/bucket/index.js +5 -2
  15. package/src/plugins/bucket/index.js.map +1 -1
  16. package/src/plugins/bucket/sbuckJob.js +56 -0
  17. package/src/plugins/bucket/sbuckJob.js.map +1 -0
  18. package/src/plugins/bucket/stakingFetcher.d.ts +3 -0
  19. package/src/plugins/bucket/stakingFetcher.js +47 -0
  20. package/src/plugins/bucket/stakingFetcher.js.map +1 -0
  21. package/src/plugins/bucket/types.d.ts +113 -0
  22. package/src/plugins/loopscale/constants.d.ts +3 -1
  23. package/src/plugins/loopscale/constants.js +4 -4
  24. package/src/plugins/loopscale/constants.js.map +1 -1
  25. package/src/plugins/loopscale/filters.d.ts +7 -0
  26. package/src/plugins/loopscale/filters.js +62 -0
  27. package/src/plugins/loopscale/filters.js.map +1 -0
  28. package/src/plugins/loopscale/helpers.d.ts +33 -0
  29. package/src/plugins/loopscale/helpers.js +162 -0
  30. package/src/plugins/loopscale/helpers.js.map +1 -0
  31. package/src/plugins/loopscale/index.js +1 -2
  32. package/src/plugins/loopscale/index.js.map +1 -1
  33. package/src/plugins/loopscale/positionsFetcher.js +89 -40
  34. package/src/plugins/loopscale/positionsFetcher.js.map +1 -1
  35. package/src/plugins/loopscale/structs.d.ts +95 -14
  36. package/src/plugins/loopscale/structs.js +87 -13
  37. package/src/plugins/loopscale/structs.js.map +1 -1
  38. package/src/plugins/moonwalk/constants.d.ts +1 -0
  39. package/src/plugins/moonwalk/constants.js +2 -1
  40. package/src/plugins/moonwalk/constants.js.map +1 -1
  41. package/src/plugins/moonwalk/gamesFetcher.js +24 -61
  42. package/src/plugins/moonwalk/gamesFetcher.js.map +1 -1
  43. package/src/plugins/moonwalk/index.js +1 -2
  44. package/src/plugins/moonwalk/index.js.map +1 -1
  45. package/src/plugins/moonwalk/types.d.ts +12 -0
  46. package/src/plugins/moonwalk/types.js +3 -0
  47. package/src/plugins/moonwalk/types.js.map +1 -0
  48. package/src/plugins/save/obligationsFetcher.js +3 -3
  49. package/src/plugins/save/obligationsFetcher.js.map +1 -1
  50. package/src/plugins/stabble/constants.js +1 -1
  51. package/src/plugins/sushiswap/helpers.js +24 -24
  52. package/src/plugins/uniswap-v2/helpers.js +22 -22
  53. package/src/plugins/zeta/airdropFetcher.js +14 -14
  54. package/src/utils/sei/constants.js +8 -8
  55. package/src/utils/sei/getQueryBalanceByOwner.js +4 -4
  56. package/src/plugins/loopscale/marketsJob.js +0 -26
  57. package/src/plugins/loopscale/marketsJob.js.map +0 -1
  58. package/src/plugins/moonwalk/gamesJob.js +0 -37
  59. package/src/plugins/moonwalk/gamesJob.js.map +0 -1
  60. /package/src/plugins/{loopscale/marketsJob.d.ts → bucket/bucketsJob.d.ts} +0 -0
  61. /package/src/plugins/{moonwalk/gamesJob.d.ts → bucket/sbuckJob.d.ts} +0 -0
@@ -21,3 +21,116 @@ export type CollateralFields = {
21
21
  };
22
22
  };
23
23
  };
24
+ export type Flask = {
25
+ id: ID;
26
+ reserves: string;
27
+ sbuck_supply: {
28
+ fields: {
29
+ value: string;
30
+ };
31
+ type: string;
32
+ };
33
+ version: string;
34
+ };
35
+ export type StakeProof = {
36
+ id: ID;
37
+ name: string;
38
+ value: {
39
+ fields: {
40
+ fountain_id: string;
41
+ id: ID;
42
+ lock_until: string;
43
+ stake_amount: string;
44
+ stake_weight: string;
45
+ start_uint: string;
46
+ };
47
+ type: string;
48
+ }[];
49
+ };
50
+ export type BucketProtocol = {
51
+ buck_treasury_cap: {
52
+ fields: {
53
+ ID: ID;
54
+ total_supply: {
55
+ fields: {
56
+ value: string;
57
+ };
58
+ type: string;
59
+ };
60
+ };
61
+ type: string;
62
+ };
63
+ id: ID;
64
+ min_bottle_size: string;
65
+ version: string;
66
+ };
67
+ export type BucketObject = {
68
+ id: ID;
69
+ base_fee_rate: string;
70
+ bottle_table: {
71
+ fields: {
72
+ debt_per_unit_stake: string;
73
+ id: ID;
74
+ last_debt_error: string;
75
+ last_reward_error: string;
76
+ reward_per_unit_stake: string;
77
+ table: {
78
+ fields: {
79
+ id: ID;
80
+ head: string;
81
+ size: string;
82
+ tail: string;
83
+ };
84
+ type: string;
85
+ };
86
+ total_collateral_snapshot: string;
87
+ total_stake: string;
88
+ total_stake_snapshot: string;
89
+ };
90
+ type: string;
91
+ };
92
+ collateral_decimal: number;
93
+ collateral_vault: string;
94
+ latest_redemption_time: string;
95
+ max_mint_amount: string;
96
+ min_collateral_ratio: string;
97
+ minted_buck_amount: string;
98
+ recovery_mode_threshold: string;
99
+ surplus_bottle_table: {
100
+ fields: {
101
+ id: ID;
102
+ size: string;
103
+ };
104
+ type: string;
105
+ };
106
+ total_flash_loan_amount: string;
107
+ };
108
+ export type Bucket = {
109
+ token: string;
110
+ baseFeeRate: number;
111
+ bottleTableSize: string;
112
+ bottleTableId: string;
113
+ collateralDecimal: number;
114
+ collateralVault: string;
115
+ latestRedemptionTime: number;
116
+ minCollateralRatio: string;
117
+ mintedBuckAmount: string;
118
+ minBottleSize: string | undefined;
119
+ maxMintAmount: string;
120
+ recoveryModeThreshold: string;
121
+ };
122
+ export type PipeObject = {
123
+ output_volume: string;
124
+ };
125
+ export type FountainStakeProof = {
126
+ id: ID;
127
+ name: string;
128
+ value: {
129
+ fields: {
130
+ fountain_id: string;
131
+ id: ID;
132
+ strap_address: string;
133
+ };
134
+ type: string;
135
+ }[];
136
+ };
@@ -1,5 +1,7 @@
1
1
  import { Platform } from '@sonarwatch/portfolio-core';
2
+ import { PublicKey } from '@solana/web3.js';
2
3
  export declare const platformId = "loopscale";
3
4
  export declare const platform: Platform;
4
5
  export declare const marketsCachePrefix = "loopscale-markets";
5
- export declare const programId = "abfcSQac2vK2Pa6UAJb37DzarVxF15bDTdphJzAqYYp";
6
+ export declare const creditbookProgramId: PublicKey;
7
+ export declare const lockboxProgramId: PublicKey;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.programId = exports.marketsCachePrefix = exports.platform = exports.platformId = void 0;
3
+ exports.lockboxProgramId = exports.creditbookProgramId = exports.marketsCachePrefix = exports.platform = exports.platformId = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
4
5
  exports.platformId = 'loopscale';
5
6
  exports.platform = {
6
7
  id: exports.platformId,
@@ -11,7 +12,6 @@ exports.platform = {
11
12
  // defiLlamaId: 'foo-finance', // from https://defillama.com/docs/api
12
13
  };
13
14
  exports.marketsCachePrefix = `${exports.platformId}-markets`;
14
- exports.programId = 'abfcSQac2vK2Pa6UAJb37DzarVxF15bDTdphJzAqYYp';
15
- // borrow tx : https://solana.fm/tx/3Fb3JYbPwJvWsgcE8ihdyuDuBeXiPe8ELJVed5VG9U9cjyEqDZuTWoboacaSawVPRGaCR4b5DSP2Grs8EHYq7tgu?cluster=mainnet-alpha
16
- // deposit lend tx : https://solana.fm/tx/2dRBwkQX3QArnMdEocYhRs3Drni2LR1cWDonsLKX3ks4dvjRXLSDzSx5T4ar5fTU1CjZDJT8kSJq5ADHyn7kRySM?cluster=mainnet-alpha
15
+ exports.creditbookProgramId = new web3_js_1.PublicKey('abfcSQac2vK2Pa6UAJb37DzarVxF15bDTdphJzAqYYp');
16
+ exports.lockboxProgramId = new web3_js_1.PublicKey('1oCkVqJ2uk4SuHyCuZKi8q3J6gjoe9Pux3XvHnHFVy4');
17
17
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG,WAAW,CAAC;AACzB,QAAA,QAAQ,GAAa;IAChC,EAAE,EAAE,kBAAU;IACd,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,kDAAkD;IACzD,OAAO,EAAE,4BAA4B;IACrC,OAAO,EAAE,6BAA6B;IACtC,qEAAqE;CACtE,CAAC;AACW,QAAA,kBAAkB,GAAG,GAAG,kBAAU,UAAU,CAAC;AAE7C,QAAA,SAAS,GAAG,6CAA6C,CAAC;AAEvE,kJAAkJ;AAClJ,wJAAwJ"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/constants.ts"],"names":[],"mappings":";;;AACA,6CAA4C;AAE/B,QAAA,UAAU,GAAG,WAAW,CAAC;AACzB,QAAA,QAAQ,GAAa;IAChC,EAAE,EAAE,kBAAU;IACd,IAAI,EAAE,WAAW;IACjB,KAAK,EAAE,kDAAkD;IACzD,OAAO,EAAE,4BAA4B;IACrC,OAAO,EAAE,6BAA6B;IACtC,qEAAqE;CACtE,CAAC;AACW,QAAA,kBAAkB,GAAG,GAAG,kBAAU,UAAU,CAAC;AAE7C,QAAA,mBAAmB,GAAG,IAAI,mBAAS,CAC9C,6CAA6C,CAC9C,CAAC;AACW,QAAA,gBAAgB,GAAG,IAAI,mBAAS,CAC3C,6CAA6C,CAC9C,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { GetProgramAccountsFilter } from '@solana/web3.js';
2
+ export declare const roleFilters: (owner: string) => GetProgramAccountsFilter[];
3
+ export declare const escrowFilters: (organization_identifier: string) => GetProgramAccountsFilter[];
4
+ export declare const orderFilters: (organization_identifier: string) => GetProgramAccountsFilter[];
5
+ export declare const loanVaultLentFilters: (borrower: string) => GetProgramAccountsFilter[];
6
+ export declare const loanVaultBorrowedFilters: (borrower: string) => GetProgramAccountsFilter[];
7
+ export declare const lockboxFilters: (nft: string) => GetProgramAccountsFilter[];
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lockboxFilters = exports.loanVaultBorrowedFilters = exports.loanVaultLentFilters = exports.orderFilters = exports.escrowFilters = exports.roleFilters = void 0;
4
+ const roleFilters = (owner) => [
5
+ {
6
+ memcmp: {
7
+ offset: 8,
8
+ bytes: owner,
9
+ },
10
+ },
11
+ ];
12
+ exports.roleFilters = roleFilters;
13
+ const escrowFilters = (organization_identifier) => [
14
+ {
15
+ memcmp: {
16
+ offset: 8,
17
+ bytes: organization_identifier,
18
+ },
19
+ },
20
+ { dataSize: 208 },
21
+ ];
22
+ exports.escrowFilters = escrowFilters;
23
+ const orderFilters = (organization_identifier) => [
24
+ {
25
+ memcmp: {
26
+ offset: 73,
27
+ bytes: organization_identifier,
28
+ },
29
+ },
30
+ { dataSize: 355 },
31
+ ];
32
+ exports.orderFilters = orderFilters;
33
+ const loanVaultLentFilters = (borrower) => [
34
+ {
35
+ memcmp: {
36
+ offset: 8 + 32,
37
+ bytes: borrower,
38
+ },
39
+ },
40
+ { dataSize: 338 },
41
+ ];
42
+ exports.loanVaultLentFilters = loanVaultLentFilters;
43
+ const loanVaultBorrowedFilters = (borrower) => [
44
+ {
45
+ memcmp: {
46
+ offset: 8 + 32 + 32,
47
+ bytes: borrower,
48
+ },
49
+ },
50
+ { dataSize: 338 },
51
+ ];
52
+ exports.loanVaultBorrowedFilters = loanVaultBorrowedFilters;
53
+ const lockboxFilters = (nft) => [
54
+ {
55
+ memcmp: {
56
+ offset: 52,
57
+ bytes: nft,
58
+ },
59
+ },
60
+ ];
61
+ exports.lockboxFilters = lockboxFilters;
62
+ //# sourceMappingURL=filters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/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KACF;CACF,CAAC;AAPW,QAAA,cAAc,kBAOzB"}
@@ -0,0 +1,33 @@
1
+ import { Connection, PublicKey } from '@solana/web3.js';
2
+ import { ParsedAccount } from '../../utils/solana';
3
+ import { EscrowAccount, Ledger, LoanVault, Order } from './structs';
4
+ export declare const getAdminOrgs: (connection: Connection, owner: string) => Promise<PublicKey[]>;
5
+ export declare const getEscrows: (connection: Connection, adminOrgs: PublicKey[]) => Promise<ParsedAccount<EscrowAccount>[]>;
6
+ export declare const getLoanVaults: (connection: Connection, escrowAccounts: ParsedAccount<EscrowAccount>[]) => Promise<{
7
+ loansLent: ParsedAccount<LoanVault>[][];
8
+ loansBorrowed: ParsedAccount<LoanVault>[][];
9
+ }>;
10
+ export declare const getOrdersForLoans: (connection: Connection, loans: ParsedAccount<LoanVault>[]) => Promise<{
11
+ order: ParsedAccount<Order> | null;
12
+ ledgers: Ledger[];
13
+ orderAddress: PublicKey;
14
+ }[]>;
15
+ export declare const getLenderOrderValues: (orders: {
16
+ order: ParsedAccount<Order> | null;
17
+ ledgers: Ledger[];
18
+ orderAddress: PublicKey;
19
+ }[]) => Balances;
20
+ export declare const getBorrowerOrderValues: (orders: {
21
+ order: ParsedAccount<Order> | null;
22
+ ledgers: Ledger[];
23
+ orderAddress: PublicKey;
24
+ }[]) => Balances;
25
+ export declare const getBorrowerCollateralValues: (connection: Connection, orders: {
26
+ order: ParsedAccount<Order> | null;
27
+ ledgers: Ledger[];
28
+ orderAddress: PublicKey;
29
+ }[]) => Promise<Balances>;
30
+ export declare const getTokensBalance: (owner: string) => Promise<Balances>;
31
+ export type Balances = {
32
+ [key: string]: number;
33
+ };
@@ -0,0 +1,162 @@
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
+ exports.getTokensBalance = exports.getBorrowerCollateralValues = exports.getBorrowerOrderValues = exports.getLenderOrderValues = exports.getOrdersForLoans = exports.getLoanVaults = exports.getEscrows = exports.getAdminOrgs = void 0;
16
+ const web3_js_1 = require("@solana/web3.js");
17
+ const solana_1 = require("../../utils/solana");
18
+ const constants_1 = require("./constants");
19
+ const structs_1 = require("./structs");
20
+ const filters_1 = require("./filters");
21
+ const getSolanaDasEndpoint_1 = __importDefault(require("../../utils/clients/getSolanaDasEndpoint"));
22
+ const getAssetsByOwnerDas_1 = require("../../utils/solana/das/getAssetsByOwnerDas");
23
+ const isHeliusFungibleAsset_1 = require("../../utils/solana/das/isHeliusFungibleAsset");
24
+ const getAdminOrgs = (connection, owner) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const roles = yield (0, solana_1.getParsedProgramAccounts)(connection, structs_1.roleAccountStruct, constants_1.creditbookProgramId, (0, filters_1.roleFilters)(owner));
26
+ return roles
27
+ .filter((r) => r.type === 4 || r.type === 5)
28
+ .map((r) => r.organization);
29
+ });
30
+ exports.getAdminOrgs = getAdminOrgs;
31
+ const getEscrows = (connection, adminOrgs) => __awaiter(void 0, void 0, void 0, function* () {
32
+ return (yield Promise.all(adminOrgs.map((organizationIdentifier) => (0, solana_1.getParsedProgramAccounts)(connection, structs_1.escrowAccountStruct, constants_1.creditbookProgramId, (0, filters_1.escrowFilters)(organizationIdentifier.toString()))))).flat();
33
+ });
34
+ exports.getEscrows = getEscrows;
35
+ const getLoanVaults = (connection, escrowAccounts) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const [loansBorrowed, loansLent] = yield Promise.all([
37
+ yield Promise.all(escrowAccounts.map((escrowAccount) => (0, solana_1.getParsedProgramAccounts)(connection, structs_1.loanVaultStruct, constants_1.creditbookProgramId, (0, filters_1.loanVaultBorrowedFilters)(escrowAccount.pubkey.toString())))),
38
+ yield Promise.all(escrowAccounts.map((escrowAccount) => (0, solana_1.getParsedProgramAccounts)(connection, structs_1.loanVaultStruct, constants_1.creditbookProgramId, (0, filters_1.loanVaultLentFilters)(escrowAccount.pubkey.toString())))),
39
+ ]);
40
+ return {
41
+ loansLent,
42
+ loansBorrowed,
43
+ };
44
+ });
45
+ exports.getLoanVaults = getLoanVaults;
46
+ const getOrdersForLoans = (connection, loans) => __awaiter(void 0, void 0, void 0, function* () {
47
+ const orderAddresses = loans.map((l) => l.order);
48
+ const orders = yield (0, solana_1.getParsedMultipleAccountsInfo)(connection, structs_1.orderStruct, orderAddresses);
49
+ const orderLedgerAddresses = orderAddresses.map((o) => web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('order_ledgers'), o.toBytes()], constants_1.creditbookProgramId)[0]);
50
+ const orderLedgers = yield (0, solana_1.getParsedMultipleAccountsInfo)(connection, structs_1.orderLedgerStruct, orderLedgerAddresses);
51
+ const orderData = [];
52
+ for (let i = 0; i < orderAddresses.length; i++) {
53
+ const order = orders[i];
54
+ const orderLedger = orderLedgers[i];
55
+ if (!orderLedger)
56
+ continue;
57
+ const { ledgers } = orderLedger;
58
+ const orderAddress = orderAddresses[i];
59
+ orderData.push({ order, ledgers, orderAddress });
60
+ }
61
+ return orderData;
62
+ });
63
+ exports.getOrdersForLoans = getOrdersForLoans;
64
+ const getLenderOrderValues = (orders) => {
65
+ const loanValues = {};
66
+ for (let i = 0; i < orders.length; i++) {
67
+ const order = orders[i];
68
+ if (!order.order || !order.order.principal_mint)
69
+ continue;
70
+ const principal = order.order.principal_mint.toString();
71
+ const totalOwed = getOrderDueAmount(order.ledgers);
72
+ if (!Object.keys(loanValues).includes(principal)) {
73
+ loanValues[principal] = totalOwed;
74
+ }
75
+ else {
76
+ loanValues[principal] += totalOwed;
77
+ }
78
+ }
79
+ return loanValues;
80
+ };
81
+ exports.getLenderOrderValues = getLenderOrderValues;
82
+ const getBorrowerOrderValues = (orders) => {
83
+ const loanValues = {};
84
+ for (let i = 0; i < orders.length; i++) {
85
+ const order = orders[i];
86
+ if (!order.order || !order.order.principal_mint)
87
+ continue;
88
+ const principal = order.order.principal_mint.toString();
89
+ const totalDue = getOrderDueAmount(order.ledgers);
90
+ if (!Object.keys(loanValues).includes(principal)) {
91
+ loanValues[principal] = totalDue;
92
+ }
93
+ else {
94
+ loanValues[principal] += totalDue;
95
+ }
96
+ }
97
+ return loanValues;
98
+ };
99
+ exports.getBorrowerOrderValues = getBorrowerOrderValues;
100
+ function getOrderDueAmount(ledgers) {
101
+ return ledgers.reduce((prev, curr) => prev +
102
+ (curr.principal_due.toNumber() - curr.principal_repaid.toNumber()) +
103
+ (curr.interest_due.toNumber() - curr.interest_repaid.toNumber()), 0);
104
+ }
105
+ const getBorrowerCollateralValues = (connection, orders) => __awaiter(void 0, void 0, void 0, function* () {
106
+ const lbNfts = orders.map((o) => { var _a; return (_a = o.order) === null || _a === void 0 ? void 0 : _a.collateral_mint; });
107
+ const lockboxes = yield fetchLockboxesFromNFTs(connection, lbNfts.filter((p) => p !== null));
108
+ const balances = yield Promise.all(lockboxes.map((lockbox) => (0, exports.getTokensBalance)(lockbox.toString())));
109
+ return mergeBalances(balances);
110
+ });
111
+ exports.getBorrowerCollateralValues = getBorrowerCollateralValues;
112
+ const fetchLockboxesFromNFTs = (connection, nfts) => __awaiter(void 0, void 0, void 0, function* () {
113
+ const lbs = [];
114
+ for (let i = 0; i < nfts.length; i++) {
115
+ const lb = yield (0, solana_1.getParsedProgramAccounts)(connection, structs_1.lockboxStruct, constants_1.lockboxProgramId, (0, filters_1.lockboxFilters)(nfts[i].toString()));
116
+ if (lb.length > 0)
117
+ lbs.push(lb[0].pubkey);
118
+ }
119
+ return lbs;
120
+ });
121
+ const getTokensBalance = (owner) => __awaiter(void 0, void 0, void 0, function* () {
122
+ const dasEndpoint = (0, getSolanaDasEndpoint_1.default)();
123
+ const items = yield (0, getAssetsByOwnerDas_1.getAssetsByOwnerDas)(dasEndpoint, owner, {
124
+ showNativeBalance: false,
125
+ showGrandTotal: false,
126
+ showInscription: false,
127
+ });
128
+ const escrowValues = {};
129
+ items.filter(isHeliusFungibleAsset_1.isHeliusFungibleAsset).forEach((asset) => {
130
+ var _a;
131
+ if (!((_a = asset.token_info) === null || _a === void 0 ? void 0 : _a.balance))
132
+ return;
133
+ if (!Object.keys(escrowValues).includes(asset.id)) {
134
+ escrowValues[asset.id] = asset.token_info.balance;
135
+ }
136
+ else {
137
+ escrowValues[asset.id] += asset.token_info.balance;
138
+ }
139
+ });
140
+ return escrowValues;
141
+ });
142
+ exports.getTokensBalance = getTokensBalance;
143
+ const mergeBalances = (balances) => {
144
+ if (!balances.length)
145
+ return {};
146
+ if (balances.length === 1)
147
+ return balances[0];
148
+ const mainBalance = balances[0];
149
+ for (let i = 1; i < balances.length; i++) {
150
+ Object.keys(balances[i]).forEach((mint) => {
151
+ const amount = balances[i][mint];
152
+ if (!Object.keys(mainBalance).includes(mint)) {
153
+ mainBalance[mint] = amount;
154
+ }
155
+ else {
156
+ mainBalance[mint] += amount;
157
+ }
158
+ });
159
+ }
160
+ return mainBalance;
161
+ };
162
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAwD;AACxD,+CAI4B;AAC5B,2CAAoE;AACpE,uCAYmB;AACnB,uCAMmB;AACnB,oGAA4E;AAC5E,oFAAiF;AACjF,wFAAqF;AAE9E,MAAM,YAAY,GAAG,CAC1B,UAAsB,EACtB,KAAa,EACS,EAAE;IACxB,MAA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AC9B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC"}
@@ -5,9 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchers = exports.jobs = exports.platforms = void 0;
7
7
  const constants_1 = require("./constants");
8
- const marketsJob_1 = __importDefault(require("./marketsJob"));
9
8
  const positionsFetcher_1 = __importDefault(require("./positionsFetcher"));
10
9
  exports.platforms = [constants_1.platform];
11
- exports.jobs = [marketsJob_1.default];
10
+ exports.jobs = [];
12
11
  exports.fetchers = [positionsFetcher_1.default];
13
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/index.ts"],"names":[],"mappings":";;;;;;AAGA,2CAAuC;AACvC,8DAAsC;AACtC,0EAAkD;AAErC,QAAA,SAAS,GAAe,CAAC,oBAAQ,CAAC,CAAC;AACnC,QAAA,IAAI,GAAU,CAAC,oBAAU,CAAC,CAAC;AAC3B,QAAA,QAAQ,GAAc,CAAC,0BAAgB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/index.ts"],"names":[],"mappings":";;;;;;AAGA,2CAAuC;AACvC,0EAAkD;AAErC,QAAA,SAAS,GAAe,CAAC,oBAAQ,CAAC,CAAC;AACnC,QAAA,IAAI,GAAU,EAAE,CAAC;AACjB,QAAA,QAAQ,GAAc,CAAC,0BAAgB,CAAC,CAAC"}
@@ -13,54 +13,103 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const portfolio_core_1 = require("@sonarwatch/portfolio-core");
16
- const web3_js_1 = require("@solana/web3.js");
17
16
  const constants_1 = require("./constants");
18
17
  const clients_1 = require("../../utils/clients");
19
- const solana_1 = require("../../utils/solana");
20
- const structs_1 = require("./structs");
21
- const tokenPriceToAssetToken_1 = __importDefault(require("../../utils/misc/tokenPriceToAssetToken"));
18
+ const helpers_1 = require("./helpers");
19
+ const ElementRegistry_1 = require("../../utils/elementbuilder/ElementRegistry");
20
+ const depositsFetcher_1 = __importDefault(require("../marginfi/depositsFetcher"));
22
21
  const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
23
22
  const connection = (0, clients_1.getClientSolana)();
24
- const accounts = yield (0, solana_1.getParsedProgramAccounts)(connection, structs_1.liquidityStruct, new web3_js_1.PublicKey('pid'), [
25
- {
26
- dataSize: structs_1.liquidityStruct.byteSize,
27
- },
28
- {
29
- memcmp: {
30
- bytes: owner,
31
- offset: 40,
32
- },
33
- },
34
- ]);
35
- if (accounts.length === 0)
23
+ const adminOrgs = yield (0, helpers_1.getAdminOrgs)(connection, owner);
24
+ if (!adminOrgs.length)
36
25
  return [];
37
- const solTokenPrice = yield cache.getTokenPrice(portfolio_core_1.solanaNativeAddress, portfolio_core_1.NetworkId.solana);
38
- const assets = [];
39
- accounts.forEach((acc) => {
40
- if (acc.amountDeposited.isZero())
41
- return;
42
- const amount = acc.amountDeposited
43
- .div(Math.pow(10, portfolio_core_1.solanaNativeDecimals))
44
- .toNumber();
45
- const asset = (0, tokenPriceToAssetToken_1.default)(portfolio_core_1.solanaNativeAddress, amount, portfolio_core_1.NetworkId.solana, solTokenPrice);
46
- assets.push(asset);
47
- });
48
- if (assets.length === 0)
26
+ const escrowAccounts = yield (0, helpers_1.getEscrows)(connection, adminOrgs);
27
+ if (!escrowAccounts.length)
49
28
  return [];
50
- const element = {
51
- networkId: portfolio_core_1.NetworkId.solana,
52
- label: 'Deposit',
53
- platformId: constants_1.platformId,
54
- type: portfolio_core_1.PortfolioElementType.multiple,
55
- value: (0, portfolio_core_1.getUsdValueSum)(assets.map((a) => a.value)),
56
- data: {
57
- assets,
58
- },
59
- };
60
- return [element];
29
+ const { loansLent, loansBorrowed } = yield (0, helpers_1.getLoanVaults)(connection, escrowAccounts);
30
+ const lenderLoanValues = [];
31
+ const borrowerLoanValues = [];
32
+ const borrowerCollateralValues = [];
33
+ for (const escrowAccount of escrowAccounts) {
34
+ const e = escrowAccounts.indexOf(escrowAccount);
35
+ const data = yield (0, helpers_1.getOrdersForLoans)(connection, [
36
+ ...loansLent[e],
37
+ ...loansBorrowed[e],
38
+ ]);
39
+ const lenderOrders = [];
40
+ for (let i = 0; i < loansLent[e].length; i++) {
41
+ const loan = loansLent[e][i];
42
+ const order = data.find((o) => o.orderAddress.toString() === loan.order.toString());
43
+ if (order !== undefined &&
44
+ order.order &&
45
+ (order.order.status === 1 || order.order.status === 2))
46
+ lenderOrders.push(order);
47
+ }
48
+ const borrowerOrders = [];
49
+ for (let i = 0; i < loansBorrowed[e].length; i++) {
50
+ const loan = loansBorrowed[e][i];
51
+ const order = data.find((o) => o.orderAddress.toString() === loan.order.toString());
52
+ if (order !== undefined &&
53
+ order.order &&
54
+ (order.order.status === 1 || order.order.status === 2))
55
+ borrowerOrders.push(order);
56
+ }
57
+ lenderLoanValues.push((0, helpers_1.getLenderOrderValues)(lenderOrders));
58
+ borrowerLoanValues.push((0, helpers_1.getBorrowerOrderValues)(borrowerOrders));
59
+ borrowerCollateralValues.push(yield (0, helpers_1.getBorrowerCollateralValues)(connection, borrowerOrders));
60
+ }
61
+ const [escrowValues, escrowMarginfiElements] = yield Promise.all([
62
+ Promise.all(escrowAccounts.map((escrowAccount) => (0, helpers_1.getTokensBalance)(escrowAccount.pubkey.toString()))),
63
+ Promise.all(escrowAccounts.map((escrowAccount) => depositsFetcher_1.default.executor(escrowAccount.pubkey.toString(), cache))),
64
+ ]);
65
+ const elementRegistry = new ElementRegistry_1.ElementRegistry(portfolio_core_1.NetworkId.solana, constants_1.platformId);
66
+ escrowAccounts.forEach((escrowAccount, i) => {
67
+ const element = elementRegistry.addElementBorrowlend({
68
+ label: 'Lending',
69
+ name: Object.keys(borrowerLoanValues[i]).length > 0 ? 'Borrow' : 'Lend',
70
+ });
71
+ escrowMarginfiElements[i].forEach((marginfiElement) => {
72
+ if (marginfiElement.type === portfolio_core_1.PortfolioElementType.borrowlend) {
73
+ marginfiElement.data.suppliedAssets.forEach((asset) => {
74
+ if (asset.data.address && asset.data.amount) {
75
+ element.addSuppliedAsset({
76
+ address: asset.data.address,
77
+ amount: asset.data.amount,
78
+ alreadyShifted: true,
79
+ });
80
+ }
81
+ });
82
+ }
83
+ });
84
+ Object.keys(escrowValues[i]).forEach((address) => {
85
+ element.addSuppliedAsset({
86
+ address,
87
+ amount: escrowValues[i][address],
88
+ });
89
+ });
90
+ Object.keys(lenderLoanValues[i]).forEach((address) => {
91
+ element.addSuppliedAsset({
92
+ address,
93
+ amount: lenderLoanValues[i][address],
94
+ });
95
+ });
96
+ Object.keys(borrowerLoanValues[i]).forEach((address) => {
97
+ element.addBorrowedAsset({
98
+ address,
99
+ amount: borrowerLoanValues[i][address],
100
+ });
101
+ });
102
+ Object.keys(borrowerCollateralValues[i]).forEach((address) => {
103
+ element.addSuppliedAsset({
104
+ address,
105
+ amount: borrowerCollateralValues[i][address],
106
+ });
107
+ });
108
+ });
109
+ return elementRegistry.getElements(cache);
61
110
  });
62
111
  const fetcher = {
63
- id: `${constants_1.platformId}-solana`,
112
+ id: `${constants_1.platformId}-positions`,
64
113
  networkId: portfolio_core_1.NetworkId.solana,
65
114
  executor,
66
115
  };
@@ -1 +1 @@
1
- {"version":3,"file":"positionsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/positionsFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAQoC;AACpC,6CAA4C;AAE5C,2CAAyC;AAEzC,iDAAsD;AACtD,+CAA8D;AAC9D,uCAA4C;AAC5C,qGAA6E;AAE7E,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;IACtE,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;I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AI,EAAE;YACJ,MAAM;SACP;KACF,CAAC;IACF,OAAO,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,SAAS;IAC1B,SAAS,EAAE,0BAAS,CAAC,MAAM;IAC3B,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"positionsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/loopscale/positionsFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA6E;AAE7E,2CAAyC;AAEzC,iDAAsD;AACtD,uCASmB;AACnB,gFAA6E;AAC7E,kFAA0D;AAE1D,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;IACtE,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IAErC,MAAM,SAAS,GAAG,MAAM,IAAA,sBAAY,EAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAExD,IAAI,CAAC,SAAS,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEjC,MAAM,cAAc,GAAG,MAAM,IAAA,oBAAU,EAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAE/D,IAAI,CAAC,cAAc,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEtC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,uBAAa,EACtD,UAAU,EACV,cAAc,CACf,CAAC;IAEF,MAAM,gBAAgB,GAA8B,EAAE,CAAC;IACvD,MAAM,kBAAkB,GAA8B,EAAE,CAAC;IACzD,MAAM,wBAAwB,GAA8B,EAAE,CAAC;IAC/D,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAiB,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