@sonarwatch/portfolio-plugins 0.14.152 → 0.14.154

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +2236 -2228
  2. package/README.md +3 -3
  3. package/package.json +1 -1
  4. package/src/plugins/balancer/helpers/pools.js +21 -21
  5. package/src/plugins/defituna/lendingPoolsJob.js +33 -0
  6. package/src/plugins/defituna/lendingPoolsJob.js.map +1 -1
  7. package/src/plugins/drift/spotMarketsJob.js +0 -1
  8. package/src/plugins/drift/spotMarketsJob.js.map +1 -1
  9. package/src/plugins/ensofi/index.js +2 -1
  10. package/src/plugins/ensofi/index.js.map +1 -1
  11. package/src/plugins/ensofi/solanaLoansJob.d.ts +3 -0
  12. package/src/plugins/ensofi/solanaLoansJob.js +63 -0
  13. package/src/plugins/ensofi/solanaLoansJob.js.map +1 -0
  14. package/src/plugins/ensofi/structs.js +2 -2
  15. package/src/plugins/ensofi/structs.js.map +1 -1
  16. package/src/plugins/kamino/reservesJob.js +35 -0
  17. package/src/plugins/kamino/reservesJob.js.map +1 -1
  18. package/src/plugins/loopscale/constants.d.ts +2 -3
  19. package/src/plugins/loopscale/constants.js +3 -4
  20. package/src/plugins/loopscale/constants.js.map +1 -1
  21. package/src/plugins/loopscale/helpers.d.ts +6 -33
  22. package/src/plugins/loopscale/helpers.js +39 -142
  23. package/src/plugins/loopscale/helpers.js.map +1 -1
  24. package/src/plugins/loopscale/index.js +10 -3
  25. package/src/plugins/loopscale/index.js.map +1 -1
  26. package/src/plugins/loopscale/lendFetcher.js +57 -0
  27. package/src/plugins/loopscale/lendFetcher.js.map +1 -0
  28. package/src/plugins/loopscale/lendVaultsFetcher.d.ts +6 -0
  29. package/src/plugins/loopscale/lendVaultsFetcher.js +68 -0
  30. package/src/plugins/loopscale/lendVaultsFetcher.js.map +1 -0
  31. package/src/plugins/loopscale/loansFetcher.d.ts +3 -0
  32. package/src/plugins/loopscale/loansFetcher.js +79 -0
  33. package/src/plugins/loopscale/loansFetcher.js.map +1 -0
  34. package/src/plugins/loopscale/structs.d.ts +116 -86
  35. package/src/plugins/loopscale/structs.js +101 -79
  36. package/src/plugins/loopscale/structs.js.map +1 -1
  37. package/src/plugins/loopscale/types.d.ts +6 -0
  38. package/src/plugins/loopscale/types.js +3 -0
  39. package/src/plugins/loopscale/types.js.map +1 -0
  40. package/src/plugins/loopscale/vaultsJob.d.ts +3 -0
  41. package/src/plugins/loopscale/vaultsJob.js +121 -0
  42. package/src/plugins/loopscale/vaultsJob.js.map +1 -0
  43. package/src/plugins/lulo/depositsFetcher.js +9 -29
  44. package/src/plugins/lulo/depositsFetcher.js.map +1 -1
  45. package/src/plugins/marginfi/banksJob.js +6 -2
  46. package/src/plugins/marginfi/banksJob.js.map +1 -1
  47. package/src/plugins/marginfi/constants.d.ts +5 -3
  48. package/src/plugins/marginfi/constants.js +8 -7
  49. package/src/plugins/marginfi/constants.js.map +1 -1
  50. package/src/plugins/marginfi/depositsFetcher.js +50 -27
  51. package/src/plugins/marginfi/depositsFetcher.js.map +1 -1
  52. package/src/plugins/marginfi/getMarginFiAccounts.d.ts +6 -0
  53. package/src/plugins/marginfi/getMarginFiAccounts.js +44 -0
  54. package/src/plugins/marginfi/getMarginFiAccounts.js.map +1 -0
  55. package/src/plugins/marginfi/helpers.d.ts +0 -5
  56. package/src/plugins/marginfi/helpers.js +1 -81
  57. package/src/plugins/marginfi/helpers.js.map +1 -1
  58. package/src/plugins/marginfi/structs/MarginfiAccount.d.ts +5 -0
  59. package/src/plugins/marginfi/structs/MarginfiAccount.js.map +1 -1
  60. package/src/plugins/suilend/helpers.js +2 -0
  61. package/src/plugins/suilend/helpers.js.map +1 -1
  62. package/src/plugins/sushiswap/helpers.js +24 -24
  63. package/src/plugins/uniswap-v2/helpers.js +22 -22
  64. package/src/utils/misc/getLendingMarketAprs.d.ts +3 -1
  65. package/src/utils/misc/getLendingMarketAprs.js +24 -1
  66. package/src/utils/misc/getLendingMarketAprs.js.map +1 -1
  67. package/src/utils/sei/constants.js +8 -8
  68. package/src/utils/sei/getQueryBalanceByOwner.js +4 -4
  69. package/src/plugins/loopscale/filters.d.ts +0 -9
  70. package/src/plugins/loopscale/filters.js +0 -62
  71. package/src/plugins/loopscale/filters.js.map +0 -1
  72. package/src/plugins/loopscale/positionsFetcher.js +0 -119
  73. package/src/plugins/loopscale/positionsFetcher.js.map +0 -1
  74. package/src/plugins/marginfi/filters.d.ts +0 -5
  75. package/src/plugins/marginfi/filters.js +0 -45
  76. package/src/plugins/marginfi/filters.js.map +0 -1
  77. /package/src/plugins/loopscale/{positionsFetcher.d.ts → lendFetcher.d.ts} +0 -0
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # @sonarwatch/portfolio-plugins
2
-
3
- This library is @sonarwatch/portfolio-plugins
1
+ # @sonarwatch/portfolio-plugins
2
+
3
+ This library is @sonarwatch/portfolio-plugins
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonarwatch/portfolio-plugins",
3
- "version": "0.14.152",
3
+ "version": "0.14.154",
4
4
  "type": "commonjs",
5
5
  "types": "./src/index.d.ts",
6
6
  "peerDependencies": {
@@ -36,27 +36,27 @@ exports.getBalancerPoolsV2 = void 0;
36
36
  const graphql_request_1 = __importStar(require("graphql-request"));
37
37
  function getBalancerPoolsV2(url) {
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
- const query = (0, graphql_request_1.gql) `
40
- query pools {
41
- pools(
42
- first: 1000
43
- orderBy: totalLiquidity
44
- orderDirection: desc
45
- where: { totalLiquidity_gt: "500" }
46
- ) {
47
- id
48
- address
49
- symbol
50
- totalLiquidity
51
- totalShares
52
- tokens {
53
- balance
54
- decimals
55
- symbol
56
- address
57
- }
58
- }
59
- }
39
+ const query = (0, graphql_request_1.gql) `
40
+ query pools {
41
+ pools(
42
+ first: 1000
43
+ orderBy: totalLiquidity
44
+ orderDirection: desc
45
+ where: { totalLiquidity_gt: "500" }
46
+ ) {
47
+ id
48
+ address
49
+ symbol
50
+ totalLiquidity
51
+ totalShares
52
+ tokens {
53
+ balance
54
+ decimals
55
+ symbol
56
+ address
57
+ }
58
+ }
59
+ }
60
60
  `;
61
61
  const res = yield (0, graphql_request_1.default)(url, query);
62
62
  const pools = res.pools;
@@ -33,6 +33,8 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
33
33
  dataSize: 355,
34
34
  },
35
35
  ]);
36
+ const tokenPriceById = yield cache.getTokenPricesAsMap(pools.map((p) => p.mint.toString()), portfolio_core_1.NetworkId.solana);
37
+ const items = [];
36
38
  yield cache.setItem(constants_1.lendingPoolsCacheKey, pools.map((pool) => {
37
39
  const utilization = pool.depositedFunds.isGreaterThan(0)
38
40
  ? new bignumber_js_1.default(pool.borrowedFunds)
@@ -44,12 +46,43 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
44
46
  .dividedBy(Math.pow(2, 60))
45
47
  .multipliedBy((0, helpers_1.rateFactor)(utilization));
46
48
  const supplyApy = borrowApy.multipliedBy(utilization);
49
+ const tokenPrice = tokenPriceById.get(pool.mint.toString());
50
+ if (tokenPrice) {
51
+ const blRate = {
52
+ borrowedAmount: pool.borrowedFunds
53
+ .dividedBy(Math.pow(10, tokenPrice.decimals))
54
+ .toNumber(),
55
+ depositedAmount: pool.depositedFunds
56
+ .dividedBy(Math.pow(10, tokenPrice.decimals))
57
+ .toNumber(),
58
+ borrowYield: {
59
+ apr: (0, portfolio_core_1.apyToApr)(borrowApy.toNumber()),
60
+ apy: borrowApy.toNumber(),
61
+ },
62
+ depositYield: {
63
+ apr: (0, portfolio_core_1.apyToApr)(supplyApy.toNumber()),
64
+ apy: supplyApy.toNumber(),
65
+ },
66
+ utilizationRatio: utilization,
67
+ platformId: constants_1.platformId,
68
+ tokenAddress: pool.mint.toString(),
69
+ ref: pool.pubkey.toString(),
70
+ };
71
+ items.push({
72
+ key: `${pool.pubkey.toString()}-${pool.mint.toString()}`,
73
+ value: blRate,
74
+ });
75
+ }
47
76
  return Object.assign(Object.assign({}, pool), { supplyApy,
48
77
  borrowApy });
49
78
  }), {
50
79
  prefix: constants_1.platformId,
51
80
  networkId: portfolio_core_1.NetworkId.solana,
52
81
  });
82
+ yield cache.setItems(items, {
83
+ prefix: portfolio_core_1.borrowLendRatesPrefix,
84
+ networkId: portfolio_core_1.NetworkId.solana,
85
+ });
53
86
  });
54
87
  const job = {
55
88
  id: `${constants_1.platformId}-lending-pools`,
@@ -1 +1 @@
1
- {"version":3,"file":"lendingPoolsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/defituna/lendingPoolsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gEAAqC;AACrC,+DAAuD;AAGvD,2CAAgF;AAChF,+CAA8D;AAC9D,iDAAsD;AACtD,uCAAwC;AACxC,uCAAuC;AAEvC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IAErC,MAAM,KAAK,GAAG,MAAM,IAAA,iCAAwB,EAC1C,UAAU,EACV,qBAAW,EACX,2BAAe,EACf;QACE;YACE,MAAM,EAAE;gBACN,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,aAAa;aACrB;SACF;QACD;YACE,QAAQ,EAAE,GAAG;SACd;KACF,CACF,CAAC;IAEF,MAAM,KAAK,CAAC,OAAO,CACjB,gCAAoB,EACpB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACjB,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC,IAAI,sBAAS,CAAC,IAAI,CAAC,aAAa,CAAC;iBAC9B,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC;iBAC9B,QAAQ,EAAE;YACf,CAAC,CAAC,CAAC,CAAC;QACN,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,IAAI,CAAC,YAAY,CAAC;aAC/C,YAAY,CAAC,eAAe,CAAC;aAC7B,SAAS,CAAC,SAAA,CAAC,EAAI,EAAE,CAAA,CAAC;aAClB,YAAY,CAAC,IAAA,oBAAU,EAAC,WAAW,CAAC,CAAC,CAAC;QAEzC,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAEtD,uCACK,IAAI,KACP,SAAS;YACT,SAAS,IACT;IACJ,CAAC,CAAC,EACF;QACE,MAAM,EAAE,sBAAU;QAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CACF,CAAC;AACJ,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,gBAAgB;IACjC,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AAEF,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"lendingPoolsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/defituna/lendingPoolsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gEAAqC;AACrC,+DAKoC;AAGpC,2CAAgF;AAChF,+CAA8D;AAC9D,iDAAsD;AACtD,uCAAwC;AACxC,uCAAuC;AAEvC,MAAM,eAAe,GAAG,QAAQ,CAAC;AAEjC,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IAErC,MAAM,KAAK,GAAG,MAAM,IAAA,iCAAwB,EAC1C,UAAU,EACV,qBAAW,EACX,2BAAe,EACf;QACE;YACE,MAAM,EAAE;gBACN,MAAM,EAAE,CAAC;gBACT,KAAK,EAAE,aAAa;aACrB;SACF;QACD;YACE,QAAQ,EAAE,GAAG;SACd;KACF,CACF,CAAC;IAEF,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,mBAAmB,C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AA,yBAAQ,EAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;oBACnC,GAAG,EAAE,SAAS,CAAC,QAAQ,EAAE;iBAC1B;gBACD,YAAY,EAAE;oBACZ,GAAG,EAAE,IAAA,yBAAQ,EAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;oBACnC,GAAG,EAAE,SAAS,CAAC,QAAQ,EAAE;iBAC1B;gBACD,gBAAgB,EAAE,WAAW;gBAC7B,UAAU,EAAV,sBAAU;gBACV,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAClC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;aAC5B,CAAC;YAEF,KAAK,CAAC,IAAI,CAAC;gBACT,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE;gBACxD,KAAK,EAAE,MAAM;aACd,CAAC,CAAC;QACL,CAAC;QAED,uCACK,IAAI,KACP,SAAS;YACT,SAAS,IACT;IACJ,CAAC,CAAC,EACF;QACE,MAAM,EAAE,sBAAU;QAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CACF,CAAC;IACF,MAAM,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE;QAC1B,MAAM,EAAE,sCAAqB;QAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,gBAAgB;IACjC,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AAEF,kBAAe,GAAG,CAAC"}
@@ -65,7 +65,6 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
65
65
  },
66
66
  depositedAmount,
67
67
  platformId: constants_1.platformId,
68
- poolName: 'Main',
69
68
  };
70
69
  yield cache.setItem(`${spotMarketAccount.vault.toString()}-${tokenAddress}`, rate, {
71
70
  prefix: portfolio_core_1.borrowLendRatesPrefix,
@@ -1 +1 @@
1
- {"version":3,"file":"spotMarketsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/drift/spotMarketsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAKoC;AACpC,gEAAqC;AACrC,2CAKqB;AACrB,+CAA8D;AAC9D,qCAA4C;AAC5C,uCAAyC;AACzC,iDAAsD;AACtD,uCAKmB;AAKnB,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,yBAAe,GAAE,CAAC;IACjC,MAAM,kBAAkB,GAAG,MAAM,IAAA,iCAAwB,EACvD,MAAM,EACN,yBAAgB,EAChB,wBAAY,EACZ,sBAAY,CACb,CAAC;IACF,IAAI,CAAC,kBAAkB;QAAE,OAAO;IAEhC,iBAAiB;IACjB,MAAM,YAAY,GAAuB,EAAE,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnD,MAAM,GAAG,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAClC,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,KAAK,CAAC,OAAO,CAAC,2BAAe,EAAE,YAAY,EAAE;QACjD,MAAM,EAAE,sBAAU;QAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CAAC,CAAC;IAEH,MAAM,WAAW,GAAyB,EAAE,CAAC;IAC7C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/D,MAAM,iBAAiB,GA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f,UAAU,EAAV,sBAAU;YACV,QAAQ,EAAE,MAAM;SACjB,CAAC;QAEF,MAAM,KAAK,CAAC,OAAO,CACjB,GAAG,iBAAiB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,YAAY,EAAE,EACvD,IAAI,EACJ;YACE,MAAM,EAAE,sCAAqB;YAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;SAC5B,CACF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,CAAC,OAAO,CAAuB,0BAAc,EAAE,WAAW,EAAE;QACrE,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,cAAc;IAC/B,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AACF,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"spotMarketsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/drift/spotMarketsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAKoC;AACpC,gEAAqC;AACrC,2CAKqB;AACrB,+CAA8D;AAC9D,qCAA4C;AAC5C,uCAAyC;AACzC,iDAAsD;AACtD,uCAKmB;AAKnB,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,yBAAe,GAAE,CAAC;IACjC,MAAM,kBAAkB,GAAG,MAAM,IAAA,iCAAwB,EACvD,MAAM,EACN,yBAAgB,EAChB,wBAAY,EACZ,sBAAY,CACb,CAAC;IACF,IAAI,CAAC,kBAAkB;QAAE,OAAO;IAEhC,iBAAiB;IACjB,MAAM,YAAY,GAAuB,EAAE,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnD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AEb,MAAM,eAAe,GAAG,iBAAiB,CAAC,cAAc;aACrD,YAAY,CACX,iBAAiB,CAAC,yBAAyB,CAAC,GAAG,CAC7C,oCAA0B,CAC3B,CACF;aACA,GAAG,CAAC,iBAAiB,CAAC;aACtB,QAAQ,EAAE,CAAC;QAEd,IAAI,cAAc,IAAI,EAAE,IAAI,eAAe,IAAI,EAAE;YAAE,SAAS;QAE5D,MAAM,IAAI,GAAmB;YAC3B,YAAY;YACZ,WAAW,EAAE;gBACX,GAAG,EAAE,IAAA,yBAAQ,EAAC,SAAS,CAAC;gBACxB,GAAG,EAAE,SAAS;aACf;YACD,cAAc;YACd,YAAY,EAAE;gBACZ,GAAG,EAAE,IAAA,yBAAQ,EAAC,UAAU,CAAC;gBACzB,GAAG,EAAE,UAAU;aAChB;YACD,eAAe;YACf,UAAU,EAAV,sBAAU;SACX,CAAC;QAEF,MAAM,KAAK,CAAC,OAAO,CACjB,GAAG,iBAAiB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,YAAY,EAAE,EACvD,IAAI,EACJ;YACE,MAAM,EAAE,sCAAqB;YAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;SAC5B,CACF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,CAAC,OAAO,CAAuB,0BAAc,EAAE,WAAW,EAAE;QACrE,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,cAAc;IAC/B,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AACF,kBAAe,GAAG,CAAC"}
@@ -8,7 +8,8 @@ const constants_1 = require("./constants");
8
8
  const suiLoansJob_1 = __importDefault(require("./suiLoansJob"));
9
9
  const suiLoansFetcher_1 = __importDefault(require("./suiLoansFetcher"));
10
10
  const solanaLoansFetcher_1 = __importDefault(require("./solanaLoansFetcher"));
11
+ const solanaLoansJob_1 = __importDefault(require("./solanaLoansJob"));
11
12
  exports.platforms = [constants_1.platform];
12
- exports.jobs = [suiLoansJob_1.default];
13
+ exports.jobs = [suiLoansJob_1.default, solanaLoansJob_1.default];
13
14
  exports.fetchers = [suiLoansFetcher_1.default, solanaLoansFetcher_1.default];
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ensofi/index.ts"],"names":[],"mappings":";;;;;;AAGA,2CAAuC;AACvC,gEAAwC;AACxC,wEAAgD;AAChD,8EAAsD;AAEzC,QAAA,SAAS,GAAe,CAAC,oBAAQ,CAAC,CAAC;AACnC,QAAA,IAAI,GAAU,CAAC,qBAAW,CAAC,CAAC;AAC5B,QAAA,QAAQ,GAAc,CAAC,yBAAe,EAAE,4BAAkB,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ensofi/index.ts"],"names":[],"mappings":";;;;;;AAGA,2CAAuC;AACvC,gEAAwC;AACxC,wEAAgD;AAChD,8EAAsD;AACtD,sEAA8C;AAEjC,QAAA,SAAS,GAAe,CAAC,oBAAQ,CAAC,CAAC;AACnC,QAAA,IAAI,GAAU,CAAC,qBAAW,EAAE,wBAAc,CAAC,CAAC;AAC5C,QAAA,QAAQ,GAAc,CAAC,yBAAe,EAAE,4BAAkB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { Job } from '../../Job';
2
+ declare const job: Job;
3
+ export default job;
@@ -0,0 +1,63 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const portfolio_core_1 = require("@sonarwatch/portfolio-core");
13
+ const clients_1 = require("../../utils/clients");
14
+ const ParsedGpa_1 = require("../../utils/solana/beets/ParsedGpa");
15
+ const constants_1 = require("./constants");
16
+ const structs_1 = require("./structs");
17
+ const solana_1 = require("../../utils/solana");
18
+ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const connection = (0, clients_1.getClientSolana)();
20
+ const lendOffers = yield ParsedGpa_1.ParsedGpa.build(connection, structs_1.lendOfferAccountStruct, constants_1.ensofiProgramId)
21
+ .addFilter('accountDiscriminator', [130, 140, 110, 73, 124, 199, 122, 81])
22
+ .addDataSizeFilter(154)
23
+ .run();
24
+ const items = [];
25
+ for (const lendOffer of lendOffers) {
26
+ if (lendOffer.status !== structs_1.LendOfferStatus.Created)
27
+ continue;
28
+ const apr = -lendOffer.interest / 10000;
29
+ const blRate = {
30
+ borrowedAmount: 0,
31
+ depositedAmount: lendOffer.amount.dividedBy(Math.pow(10, 6)).toNumber(),
32
+ borrowYield: {
33
+ apr,
34
+ apy: (0, portfolio_core_1.aprToApy)(apr),
35
+ },
36
+ depositYield: {
37
+ apr: 0,
38
+ apy: 0,
39
+ },
40
+ platformId: constants_1.platformId,
41
+ poolName: (0, solana_1.u8ArrayToString)(lendOffer.offerId).replace('lend_offer_', ''),
42
+ tokenAddress: lendOffer.lendMintToken.toString(),
43
+ utilizationRatio: 0,
44
+ duration: lendOffer.duration.times(1000).toNumber(),
45
+ ref: lendOffer.pubkey.toString(),
46
+ };
47
+ items.push({
48
+ key: `${lendOffer.pubkey.toString()}-${lendOffer.lendMintToken.toString()}`,
49
+ value: blRate,
50
+ });
51
+ }
52
+ yield cache.setItems(items, {
53
+ prefix: portfolio_core_1.borrowLendRatesPrefix,
54
+ networkId: portfolio_core_1.NetworkId.solana,
55
+ });
56
+ });
57
+ const job = {
58
+ id: `${constants_1.platformId}-solana-loans`,
59
+ executor,
60
+ labels: ['realtime'],
61
+ };
62
+ exports.default = job;
63
+ //# sourceMappingURL=solanaLoansJob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solanaLoansJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ensofi/solanaLoansJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAKoC;AAGpC,iDAAsD;AACtD,kEAA+D;AAC/D,2CAA0D;AAC1D,uCAAoE;AACpE,+CAAqD;AAErD,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IACrC,MAAM,UAAU,GAAG,MAAM,qBAAS,CAAC,KAAK,CACtC,UAAU,EACV,gCAAsB,EACtB,2BAAe,CAChB;SACE,SAAS,CAAC,sBAAsB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;SACzE,iBAAiB,CAAC,GAAG,CAAC;SACtB,GAAG,EAAE,CAAC;IACT,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,SAAS,CAAC,MAAM,KAAK,yBAAe,CAAC,OAAO;YAAE,SAAS;QAC3D,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;QACxC,MAAM,MAAM,GAAmB;YAC7B,cAAc,EAAE,CAAC;YACjB,eAAe,EAAE,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC,QAAQ,EAAE;YAC/D,WAAW,EAAE;gBACX,GAAG;gBACH,GAAG,EAAE,IAAA,yBAAQ,EAAC,GAAG,CAAC;aACnB;YACD,YAAY,EAAE;gBACZ,GAAG,EAAE,CAAC;gBACN,GAAG,EAAE,CAAC;aACP;YACD,UAAU,EAAV,sBAAU;YACV,QAAQ,EAAE,IAAA,wBAAe,EAAC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC;YACvE,YAAY,EAAE,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE;YAChD,gBAAgB,EAAE,CAAC;YACnB,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;YACnD,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE;SACjC,CAAC;QACF,KAAK,CAAC,IAAI,CAAC;YACT,GAAG,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,SAAS,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE;YAC3E,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC;IACD,MAAM,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE;QAC1B,MAAM,EAAE,sCAAqB;QAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AACF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,eAAe;IAChC,QAAQ;IACR,MAAM,EAAE,CAAC,UAAU,CAAC;CACrB,CAAC;AACF,kBAAe,GAAG,CAAC"}
@@ -23,10 +23,10 @@ var LoanOfferStatus;
23
23
  })(LoanOfferStatus || (exports.LoanOfferStatus = LoanOfferStatus = {}));
24
24
  exports.lendOfferAccountStruct = new beet_1.FixableBeetStruct([
25
25
  ['accountDiscriminator', (0, beet_1.uniformFixedSizeArray)(beet_1.u8, 8)],
26
- ['interest', solana_1.f64],
26
+ ['interest', beet_1.u16],
27
27
  ['lenderFeePercent', solana_1.f64],
28
28
  ['duration', solana_1.u64],
29
- ['offerId', (0, beet_1.uniformFixedSizeArray)(beet_1.u8, 30)],
29
+ ['offerId', (0, beet_1.array)(beet_1.u8)],
30
30
  ['lender', beet_solana_1.publicKey],
31
31
  ['lendMintToken', beet_solana_1.publicKey],
32
32
  ['amount', solana_1.u64],
@@ -1 +1 @@
1
- {"version":3,"file":"structs.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/ensofi/structs.ts"],"names":[],"mappings":";;;AAEA,oDAMmC;AACnC,kEAA6D;AAC7D,+CAAmD;AAEnD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,2DAAW,CAAA;IACX,+DAAa,CAAA;IACb,6DAAY,CAAA;IACZ,yDAAU,CAAA;AACZ,CAAC,EALW,eAAe,+BAAf,eAAe,QAK1B;AAED,IAAY,eAQX;AARD,WAAY,eAAe;IACzB,2DAAW,CAAA;IACX,2EAAmB,CAAA;IACnB,uDAAS,CAAA;IACT,qEAAgB,CAAA;IAChB,mEAAe,CAAA;IACf,iEAAc,CAAA;IACd,6DAAY,CAAA;AACd,CAAC,EARW,eAAe,+BAAf,eAAe,QAQ1B;AAeY,QAAA,sBAAsB,GAAG,IAAI,wBAAiB,CACzD;IACE,CAAC,sBAAsB,EAAE,IAAA,4BAAqB,EAAC,SAAE,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC,UAAU,EAAE,YAAG,CAAC;IACjB,CAAC,kBAAkB,EAAE,YAAG,CAAC;IACzB,CAAC,UAAU,EAAE,YAAG,CAAC;IACjB,CAAC,SAAS,EAAE,IAAA,4BAAqB,EAAC,SAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC,QAAQ,EAAE,uBAAS,CAAC;IACrB,CAAC,eAAe,EAAE,uBAAS,CAAC;IAC5B,CAAC,QAAQ,EAAE,YAAG,CAAC;IACf,CAAC,MAAM,EAAE,SAAE,CAAC;IACZ,CAAC,QAAQ,EAAE,SAAE,CAAC;CACf,EACD,CAAC,IAAI,EA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AAC,SAAE,EAAE,EAAE,CAAC,CAAC;IAC9C,CAAC,UAAU,EAAE,YAAG,CAAC;IACjB,CAAC,cAAc,EAAE,YAAG,CAAC;IACrB,CAAC,kBAAkB,EAAE,YAAG,CAAC;IACzB,CAAC,UAAU,EAAE,YAAG,CAAC;IACjB,CAAC,eAAe,EAAE,uBAAS,CAAC;IAC5B,CAAC,QAAQ,EAAE,uBAAS,CAAC;IACrB,CAAC,SAAS,EAAE,IAAA,4BAAqB,EAAC,SAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,CAAC,UAAU,EAAE,uBAAS,CAAC;IACvB,CAAC,qBAAqB,EAAE,uBAAS,CAAC;IAClC,CAAC,kBAAkB,EAAE,YAAG,CAAC;IACzB,CAAC,uBAAuB,EAAE,IAAA,cAAO,EAAC,YAAG,CAAC,CAAC;IACvC,CAAC,QAAQ,EAAE,SAAE,CAAC;IACd,CAAC,oBAAoB,EAAE,YAAG,CAAC;IAC3B,CAAC,WAAW,EAAE,YAAG,CAAC;IAClB,CAAC,eAAe,EAAE,YAAG,CAAC;IACtB,CAAC,kBAAkB,EAAE,YAAG,CAAC;IACzB,CAAC,cAAc,EAAE,IAAA,4BAAqB,EAAC,SAAE,EAAE,EAAE,CAAC,CAAC;IAC/C,CAAC,iBAAiB,EAAE,YAAG,CAAC;IACxB,CAAC,MAAM,EAAE,SAAE,CAAC;CACb,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAwB,CACnC,CAAC"}
@@ -18,14 +18,18 @@ const klend_1 = require("./structs/klend");
18
18
  const apr_1 = require("./helpers/apr");
19
19
  const common_1 = require("./helpers/common");
20
20
  const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
21
+ var _a;
21
22
  const client = (0, clients_1.getClientSolana)();
22
23
  const reservesAccounts = (yield Promise.all([
23
24
  (0, solana_1.getParsedProgramAccounts)(client, klend_1.reserveStruct, constants_1.klendProgramId, (0, filters_1.dataSizeFilter)(8624)),
24
25
  (0, solana_1.getParsedProgramAccounts)(client, klend_1.reserveStruct, constants_1.klendProgramId, (0, filters_1.dataSizeFilter)(8464)),
25
26
  ])).flat();
27
+ const items = [];
26
28
  if (reservesAccounts.length !== 0) {
27
29
  const reserveById = {};
28
30
  for (const reserve of reservesAccounts) {
31
+ if (reserve.lendingMarket.toString() === '11111111111111111111111111111111')
32
+ continue;
29
33
  const borrowApr = (0, apr_1.calculateBorrowAPR)(reserve);
30
34
  const supplyApr = (0, apr_1.calculateSupplyAPR)(reserve);
31
35
  const exchangeRate = (0, common_1.getEchangeRate)(reserve);
@@ -34,7 +38,38 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
34
38
  supplyApr,
35
39
  exchangeRate,
36
40
  cumulativeBorrowRate });
41
+ const borrowedAmountRaw = reserve.liquidity.borrowedAmountSf.dividedBy(Math.pow(2, 60));
42
+ const depositedAmountRaw = reserve.liquidity.availableAmount.plus(borrowedAmountRaw);
43
+ const decimalsFactor = Math.pow(10, reserve.liquidity.mintDecimals.toNumber());
44
+ const rate = {
45
+ tokenAddress: reserve.liquidity.mintPubkey.toString(),
46
+ depositedAmount: depositedAmountRaw
47
+ .dividedBy(decimalsFactor)
48
+ .toNumber(),
49
+ depositYield: {
50
+ apy: (0, portfolio_core_1.aprToApy)(supplyApr),
51
+ apr: supplyApr,
52
+ },
53
+ borrowedAmount: borrowedAmountRaw.dividedBy(decimalsFactor).toNumber(),
54
+ borrowYield: {
55
+ apy: (0, portfolio_core_1.aprToApy)(borrowApr),
56
+ apr: borrowApr,
57
+ },
58
+ utilizationRatio: borrowedAmountRaw
59
+ .dividedBy(depositedAmountRaw)
60
+ .toNumber(),
61
+ platformId: constants_1.platformId,
62
+ poolName: (_a = constants_1.lendingConfigs.get(reserve.lendingMarket.toString())) === null || _a === void 0 ? void 0 : _a.name,
63
+ };
64
+ items.push({
65
+ key: `${reserve.pubkey.toString()}-${reserve.liquidity.mintPubkey.toString()}`,
66
+ value: rate,
67
+ });
37
68
  }
69
+ yield cache.setItems(items, {
70
+ prefix: portfolio_core_1.borrowLendRatesPrefix,
71
+ networkId: portfolio_core_1.NetworkId.solana,
72
+ });
38
73
  yield cache.setItem(constants_1.reservesKey, reserveById, {
39
74
  prefix: constants_1.platformId,
40
75
  networkId: portfolio_core_1.NetworkId.solana,
@@ -1 +1 @@
1
- {"version":3,"file":"reservesJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/kamino/reservesJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAAuD;AAGvD,iDAAsD;AACtD,+CAA8D;AAC9D,wDAA4D;AAC5D,2CAAsE;AACtE,2CAAgD;AAChD,uCAAuE;AAEvE,6CAA2E;AAE3E,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,yBAAe,GAAE,CAAC;IACjC,MAAM,gBAAgB,GAAG,CACvB,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,IAAA,iCAAwB,EACtB,MAAM,EACN,qBAAa,EACb,0BAAc,EACd,IAAA,wBAAc,EAAC,IAAI,CAAC,CACrB;QACD,IAAA,iCAAwB,EACtB,MAAM,EACN,qBAAa,EACb,0BAAc,EACd,IAAA,wBAAc,EAAC,IAAI,CAAC,CACrB;KACF,CAAC,CACH,CAAC,IAAI,EAAE,CAAC;IACT,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,WAAW,GAAoC,EAAE,CAAC;QACxD,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;YACvC,MAAM,SAAS,GAAG,IAAA,wBAAkB,EAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,SAAS,GAAG,IAAA,wBAAkB,EAAC,OAAO,CAAC,CAAC;YAC9C,MAAM,YAAY,GAAG,IAAA,uBAAc,EAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,oBAAoB,GAAG,IAAA,gCAAuB,EAClD,OAAO,CAAC,SAAS,CAAC,uBAAuB,CAC1C,CAAC,QAAQ,EAAE,CAAC;YACb,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,mCACjC,OAAO,KACV,SAAS;gBACT,SAAS;gBACT,YAAY;gBACZ,oBAAoB,GACrB,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC,OAAO,CAAC,uBAAW,EAAE,WAAW,EAAE;YAC5C,MAAM,EAAE,sBAAU;YAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;SAC5B,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,WAAW;IAC5B,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AACF,kBAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"reservesJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/kamino/reservesJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAKoC;AAGpC,iDAAsD;AACtD,+CAA8D;AAC9D,wDAA4D;AAC5D,2CAKqB;AACrB,2CAAgD;AAChD,uCAAuE;AAEvE,6CAA2E;AAE3E,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;;IACnD,MAAM,MAAM,GAAG,IAAA,yBAAe,GAAE,CAAC;IACjC,MAAM,gBAAgB,GAAG,CACvB,MAAM,OAAO,CAAC,GAAG,CAAC;QAChB,IAAA,iCAAwB,EACtB,MAAM,EACN,qBAAa,EACb,0BAAc,EACd,IAAA,wBAAc,EAAC,IAAI,CAAC,CACrB;QACD,IAAA,iCAAwB,EACtB,MAAM,EACN,qBAAa,EACb,0BAAc,EACd,IAAA,wBAAc,EAAC,IAAI,CAAC,CACrB;KACF,CAAC,CACH,CAAC,IAAI,EAAE,CAAC;IACT,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,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cAAc,CAAC,CAAC,QAAQ,EAAE;gBACtE,WAAW,EAAE;oBACX,GAAG,EAAE,IAAA,yBAAQ,EAAC,SAAS,CAAC;oBACxB,GAAG,EAAE,SAAS;iBACf;gBACD,gBAAgB,EAAE,iBAAiB;qBAChC,SAAS,CAAC,kBAAkB,CAAC;qBAC7B,QAAQ,EAAE;gBACb,UAAU,EAAV,sBAAU;gBACV,QAAQ,EAAE,MAAA,0BAAc,CAAC,GAAG,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,0CAAE,IAAI;aACrE,CAAC;YACF,KAAK,CAAC,IAAI,CAAC;gBACT,GAAG,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE;gBAC9E,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;QACL,CAAC;QACD,MAAM,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE;YAC1B,MAAM,EAAE,sCAAqB;YAC7B,SAAS,EAAE,0BAAS,CAAC,MAAM;SAC5B,CAAC,CAAC;QACH,MAAM,KAAK,CAAC,OAAO,CAAC,uBAAW,EAAE,WAAW,EAAE;YAC5C,MAAM,EAAE,sBAAU;YAClB,SAAS,EAAE,0BAAS,CAAC,MAAM;SAC5B,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,WAAW;IAC5B,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AACF,kBAAe,GAAG,CAAC"}
@@ -4,6 +4,5 @@ import { Platform } from '@sonarwatch/portfolio-core';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  export declare const platformId = "loopscale";
6
6
  export declare const platform: Platform;
7
- export declare const marketsCachePrefix = "loopscale-markets";
8
- export declare const creditbookProgramId: PublicKey;
9
- export declare const lockboxProgramId: PublicKey;
7
+ export declare const vaultsCacheKey = "vaults";
8
+ export declare const loopscaleProgramId: PublicKey;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lockboxProgramId = exports.creditbookProgramId = exports.marketsCachePrefix = exports.platform = exports.platformId = void 0;
3
+ exports.loopscaleProgramId = exports.vaultsCacheKey = exports.platform = exports.platformId = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.platformId = 'loopscale';
6
6
  exports.platform = {
@@ -15,7 +15,6 @@ exports.platform = {
15
15
  github: 'https://github.com/bridgesplit',
16
16
  description: 'Loopscale is a new way to lend and borrow onchain with the best rates, any asset, and less risk.',
17
17
  };
18
- exports.marketsCachePrefix = `${exports.platformId}-markets`;
19
- exports.creditbookProgramId = new web3_js_1.PublicKey('abfcSQac2vK2Pa6UAJb37DzarVxF15bDTdphJzAqYYp');
20
- exports.lockboxProgramId = new web3_js_1.PublicKey('1oCkVqJ2uk4SuHyCuZKi8q3J6gjoe9Pux3XvHnHFVy4');
18
+ exports.vaultsCacheKey = `vaults`;
19
+ exports.loopscaleProgramId = new web3_js_1.PublicKey('1oopBoJG58DgkUVKkEzKgyG9dvRmpgeEm1AVjoHkF78');
21
20
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
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,EACH,+EAA+E;IACjF,OAAO,EAAE,4BAA4B;IACrC,OAAO,EAAE,6BAA6B;IACtC,qEAAqE;IACrE,aAAa,EAAE,6BAA6B;IAC5C,OAAO,EAAE,8BAA8B;IACvC,MAAM,EAAE,gCAAgC;IACxC,WAAW,EACT,kGAAkG;CACrG,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"}
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,EACH,+EAA+E;IACjF,OAAO,EAAE,4BAA4B;IACrC,OAAO,EAAE,6BAA6B;IACtC,qEAAqE;IACrE,aAAa,EAAE,6BAA6B;IAC5C,OAAO,EAAE,8BAA8B;IACvC,MAAM,EAAE,gCAAgC;IACxC,WAAW,EACT,kGAAkG;CACrG,CAAC;AACW,QAAA,cAAc,GAAG,QAAQ,CAAC;AAE1B,QAAA,kBAAkB,GAAG,IAAI,mBAAS,CAC7C,6CAA6C,CAC9C,CAAC"}
@@ -1,35 +1,8 @@
1
+ /// <reference types="node" />
1
2
  /// <reference types="@drift-labs/sdk/node_modules/@solana/web3.js" />
2
3
  /// <reference types="jito-ts/node_modules/@solana/web3.js" />
3
- import { Connection, PublicKey } from '@solana/web3.js';
4
- import { ParsedAccount } from '../../utils/solana';
5
- import { EscrowAccount, Ledger, LoanVault, Order } from './structs';
6
- export declare const getAdminOrgs: (connection: Connection, owner: string) => Promise<PublicKey[]>;
7
- export declare const getEscrows: (connection: Connection, adminOrgs: PublicKey[]) => Promise<ParsedAccount<EscrowAccount>[]>;
8
- export declare const getLoanVaults: (connection: Connection, escrowAccounts: ParsedAccount<EscrowAccount>[]) => Promise<{
9
- loansLent: ParsedAccount<LoanVault>[][];
10
- loansBorrowed: ParsedAccount<LoanVault>[][];
11
- }>;
12
- export declare const getOrdersForLoans: (connection: Connection, loans: ParsedAccount<LoanVault>[]) => Promise<{
13
- order: ParsedAccount<Order> | null;
14
- ledgers: Ledger[];
15
- orderAddress: PublicKey;
16
- }[]>;
17
- export declare const getLenderOrderValues: (orders: {
18
- order: ParsedAccount<Order> | null;
19
- ledgers: Ledger[];
20
- orderAddress: PublicKey;
21
- }[]) => Balances;
22
- export declare const getBorrowerOrderValues: (orders: {
23
- order: ParsedAccount<Order> | null;
24
- ledgers: Ledger[];
25
- orderAddress: PublicKey;
26
- }[]) => Balances;
27
- export declare const getBorrowerCollateralValues: (connection: Connection, orders: {
28
- order: ParsedAccount<Order> | null;
29
- ledgers: Ledger[];
30
- orderAddress: PublicKey;
31
- }[]) => Promise<Balances>;
32
- export declare const getTokensBalance: (owner: string) => Promise<Balances>;
33
- export type Balances = {
34
- [key: string]: number;
35
- };
4
+ import { PublicKey } from '@solana/web3.js';
5
+ import { Cache } from '../../Cache';
6
+ export declare const getProgramAddress: (seeds: (Uint8Array | Buffer)[], programId: PublicKey) => PublicKey;
7
+ export declare function bytesToNumberLE(bytes: Uint8Array): number;
8
+ export declare function getMarginFiAccountBalance(account: PublicKey, cache: Cache): Promise<number>;
@@ -12,151 +12,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
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;
15
+ exports.getMarginFiAccountBalance = exports.bytesToNumberLE = exports.getProgramAddress = void 0;
16
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;
17
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
+ const getMarginFiAccounts_1 = require("../marginfi/getMarginFiAccounts");
19
+ const helpers_1 = require("../marginfi/helpers");
20
+ const getProgramAddress = (seeds, programId) => {
21
+ const [key] = web3_js_1.PublicKey.findProgramAddressSync(seeds, programId);
22
+ return key;
80
23
  };
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
- }
24
+ exports.getProgramAddress = getProgramAddress;
25
+ function bytesToNumberLE(bytes) {
26
+ let result = BigInt(0);
27
+ for (let i = bytes.length - 1; i >= 0; i--) {
28
+ // eslint-disable-next-line no-bitwise
29
+ result = (result << BigInt(8)) | BigInt(bytes[i]);
96
30
  }
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);
31
+ return Number(result);
104
32
  }
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
- }
33
+ exports.bytesToNumberLE = bytesToNumberLE;
34
+ function getMarginFiAccountBalance(account, cache) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const marginFiAccounts = yield (0, getMarginFiAccounts_1.getMarginFiAccounts)(account.toString(), cache);
37
+ let accountBalance = 0;
38
+ marginFiAccounts.forEach((acc) => {
39
+ if (!acc)
40
+ return;
41
+ acc.balances.forEach((balance) => {
42
+ if (!balance)
43
+ return;
44
+ const shareBalance = (0, helpers_1.wrappedI80F48toBigNumber)(balance.assetShares);
45
+ const { bank } = balance;
46
+ if (bank !== undefined) {
47
+ const shareValue = (0, helpers_1.wrappedI80F48toBigNumber)({
48
+ value: new bignumber_js_1.default(bank.assetShareValue.value),
49
+ });
50
+ const totalValue = shareBalance.multipliedBy(shareValue);
51
+ accountBalance += totalValue.toNumber();
52
+ }
53
+ });
158
54
  });
159
- }
160
- return mainBalance;
161
- };
55
+ return accountBalance;
56
+ });
57
+ }
58
+ exports.getMarginFiAccountBalance = getMarginFiAccountBalance;
162
59
  //# sourceMappingURL=helpers.js.map