@pendle/sdk-boros 1.0.10 → 1.0.11-strategies

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 (34) hide show
  1. package/dist/backend/secrettune/BorosCoreSDK.d.ts +376 -3
  2. package/dist/backend/secrettune/BorosCoreSDK.js +170 -1
  3. package/dist/backend/secrettune/BorosCoreSDK.js.map +1 -1
  4. package/dist/backend/secrettune/BorosSendTxsBotSDK.d.ts +18 -11
  5. package/dist/backend/secrettune/BorosSendTxsBotSDK.js +3 -11
  6. package/dist/backend/secrettune/BorosSendTxsBotSDK.js.map +1 -1
  7. package/dist/entities/Calculator/exchangeFees.d.ts +47 -0
  8. package/dist/entities/Calculator/exchangeFees.js +93 -0
  9. package/dist/entities/Calculator/exchangeFees.js.map +1 -0
  10. package/dist/entities/Calculator/index.d.ts +6 -0
  11. package/dist/entities/Calculator/index.js +23 -0
  12. package/dist/entities/Calculator/index.js.map +1 -0
  13. package/dist/entities/Calculator/marginCalculator.d.ts +10 -0
  14. package/dist/entities/Calculator/marginCalculator.js +67 -0
  15. package/dist/entities/Calculator/marginCalculator.js.map +1 -0
  16. package/dist/entities/Calculator/strategyApr.d.ts +30 -0
  17. package/dist/entities/Calculator/strategyApr.js +94 -0
  18. package/dist/entities/Calculator/strategyApr.js.map +1 -0
  19. package/dist/entities/Calculator/strategyExecution.d.ts +28 -0
  20. package/dist/entities/Calculator/strategyExecution.js +130 -0
  21. package/dist/entities/Calculator/strategyExecution.js.map +1 -0
  22. package/dist/entities/Calculator/strategyFinder.d.ts +11 -0
  23. package/dist/entities/Calculator/strategyFinder.js +162 -0
  24. package/dist/entities/Calculator/strategyFinder.js.map +1 -0
  25. package/dist/entities/Calculator/types.d.ts +84 -0
  26. package/dist/entities/Calculator/types.js +3 -0
  27. package/dist/entities/Calculator/types.js.map +1 -0
  28. package/dist/entities/index.d.ts +1 -0
  29. package/dist/entities/index.js +1 -0
  30. package/dist/entities/index.js.map +1 -1
  31. package/package.json +1 -1
  32. package/dist/backend/secrettune/PendleCoreSDK.d.ts +0 -2220
  33. package/dist/backend/secrettune/PendleCoreSDK.js +0 -939
  34. package/dist/backend/secrettune/PendleCoreSDK.js.map +0 -1
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMarginRequiredFor1YU = getMarginRequiredFor1YU;
4
+ exports.getMarginRequiredFor1YUFixedX18 = getMarginRequiredFor1YUFixedX18;
5
+ exports.getStrategyBorosMargin = getStrategyBorosMargin;
6
+ exports.getStrategyMarginRequirements = getStrategyMarginRequirements;
7
+ const boros_offchain_math_1 = require("@pendle/boros-offchain-math");
8
+ const SECONDS_PER_YEAR = 3600 * 24 * 365;
9
+ const DEFAULT_MIN_MARGIN_INDEX_RATE = boros_offchain_math_1.FixedX18.fromNumber(0.1);
10
+ function getMarginRequiredFor1YU(market, leverage) {
11
+ const effectiveLeverage = leverage ?? market.metadata?.maxLeverage ?? 1;
12
+ const marginFactor = market.config.kIM
13
+ ? boros_offchain_math_1.FixedX18.fromRawValue(BigInt(market.config.kIM))
14
+ : boros_offchain_math_1.FixedX18.fromNumber(0.5);
15
+ const tThresh_s = market.config.tThresh ?? 604800;
16
+ const tThresh_y = tThresh_s / SECONDS_PER_YEAR;
17
+ const timeToMaturity_s = market.data?.timeToMaturity ??
18
+ (market.imData.maturity - Math.floor(Date.now() / 1000));
19
+ const timeToMaturity_y = Math.max(0, timeToMaturity_s / SECONDS_PER_YEAR);
20
+ const time_y = Math.max(timeToMaturity_y, tThresh_y);
21
+ const time = boros_offchain_math_1.FixedX18.fromNumber(time_y);
22
+ const impliedApr = market.data?.ammImpliedApr ?? market.data?.midApr ?? 0;
23
+ const absImpliedApr = boros_offchain_math_1.FixedX18.fromNumber(Math.abs(impliedApr));
24
+ const rate = absImpliedApr.gt(DEFAULT_MIN_MARGIN_INDEX_RATE)
25
+ ? absImpliedApr
26
+ : DEFAULT_MIN_MARGIN_INDEX_RATE;
27
+ const contractSuf = rate.mulDown(time).mulDown(marginFactor);
28
+ const offchainSuf = rate.mulDown(time).divDown(boros_offchain_math_1.FixedX18.fromNumber(effectiveLeverage));
29
+ const imSuf = contractSuf.gt(offchainSuf) ? contractSuf : offchainSuf;
30
+ return imSuf.toNumber();
31
+ }
32
+ function getMarginRequiredFor1YUFixedX18(market, leverage) {
33
+ const effectiveLeverage = leverage ?? market.metadata?.maxLeverage ?? 1;
34
+ const marginFactor = market.config.kIM
35
+ ? boros_offchain_math_1.FixedX18.fromRawValue(BigInt(market.config.kIM))
36
+ : boros_offchain_math_1.FixedX18.fromNumber(0.5);
37
+ const tThresh_s = market.config.tThresh ?? 604800;
38
+ const tThresh_y = tThresh_s / SECONDS_PER_YEAR;
39
+ const timeToMaturity_s = market.data?.timeToMaturity ??
40
+ (market.imData.maturity - Math.floor(Date.now() / 1000));
41
+ const timeToMaturity_y = Math.max(0, timeToMaturity_s / SECONDS_PER_YEAR);
42
+ const time_y = Math.max(timeToMaturity_y, tThresh_y);
43
+ const time = boros_offchain_math_1.FixedX18.fromNumber(time_y);
44
+ const impliedApr = market.data?.ammImpliedApr ?? market.data?.midApr ?? 0;
45
+ const absImpliedApr = boros_offchain_math_1.FixedX18.fromNumber(Math.abs(impliedApr));
46
+ const rate = absImpliedApr.gt(DEFAULT_MIN_MARGIN_INDEX_RATE)
47
+ ? absImpliedApr
48
+ : DEFAULT_MIN_MARGIN_INDEX_RATE;
49
+ const contractSuf = rate.mulDown(time).mulDown(marginFactor);
50
+ const offchainSuf = rate.mulDown(time).divDown(boros_offchain_math_1.FixedX18.fromNumber(effectiveLeverage));
51
+ return contractSuf.gt(offchainSuf) ? contractSuf : offchainSuf;
52
+ }
53
+ function getStrategyBorosMargin(longMarket, shortMarket, leverage) {
54
+ const marginRequired1 = getMarginRequiredFor1YU(longMarket, leverage);
55
+ const marginRequired2 = getMarginRequiredFor1YU(shortMarket, leverage);
56
+ return marginRequired1 + marginRequired2;
57
+ }
58
+ function getStrategyMarginRequirements(longMarket, shortMarket, leverage) {
59
+ const marginRequired1 = getMarginRequiredFor1YU(longMarket, leverage);
60
+ const marginRequired2 = getMarginRequiredFor1YU(shortMarket, leverage);
61
+ return {
62
+ marginRequired1,
63
+ marginRequired2,
64
+ totalBorosMargin: marginRequired1 + marginRequired2,
65
+ };
66
+ }
67
+ //# sourceMappingURL=marginCalculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marginCalculator.js","sourceRoot":"","sources":["../../../src/entities/Calculator/marginCalculator.ts"],"names":[],"mappings":";;AA0BA,0DAyCC;AAKD,0EA+BC;AAUD,wDAQC;AAKD,sEAgBC;AA9ID,qEAAuD;AAGvD,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC;AAMzC,MAAM,6BAA6B,GAAG,8BAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAiB/D,SAAgB,uBAAuB,CACrC,MAAsB,EACtB,QAAiB;IAEjB,MAAM,iBAAiB,GAAG,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,WAAW,IAAI,CAAC,CAAC;IAGxE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG;QACpC,CAAC,CAAC,8BAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC,CAAC,8BAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAG7B,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC;IAClD,MAAM,SAAS,GAAG,SAAS,GAAG,gBAAgB,CAAC;IAG/C,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,EAAE,cAAc;QAClD,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;IA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WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC;AACjE,CAAC;AAUD,SAAgB,sBAAsB,CACpC,UAA0B,EAC1B,WAA2B,EAC3B,QAAiB;IAEjB,MAAM,eAAe,GAAG,uBAAuB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvE,OAAO,eAAe,GAAG,eAAe,CAAC;AAC3C,CAAC;AAKD,SAAgB,6BAA6B,CAC3C,UAA0B,EAC1B,WAA2B,EAC3B,QAAiB;IAMjB,MAAM,eAAe,GAAG,uBAAuB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACvE,OAAO;QACL,eAAe;QACf,eAAe;QACf,gBAAgB,EAAE,eAAe,GAAG,eAAe;KACpD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { FixedX18 } from '@pendle/boros-offchain-math';
2
+ import type { Strategy, StrategyCalculatorInput, StrategyCalculatorResult, StrategyFixedAprParams } from './types';
3
+ export declare function calculateStrategyFixedApr(params: StrategyFixedAprParams): number;
4
+ export declare function calculateStrategyFixedAprFixedX18(params: {
5
+ perpLeverage: number;
6
+ daysToMaturity: number;
7
+ borosMargin: FixedX18;
8
+ impliedApr1: FixedX18;
9
+ impliedApr2: FixedX18;
10
+ exchangeFee1: FixedX18;
11
+ exchangeFee2: FixedX18;
12
+ borosTradeFee: FixedX18;
13
+ borosSettlementFee: FixedX18;
14
+ }): FixedX18;
15
+ export declare function calculateStrategy(input: StrategyCalculatorInput): StrategyCalculatorResult;
16
+ export declare function calculateStrategyAprFromStrategy(params: {
17
+ strategy: Strategy;
18
+ perpLeverage: number;
19
+ borosMargin: number;
20
+ exchangeFee1?: number;
21
+ exchangeFee2?: number;
22
+ borosTradeFee?: number;
23
+ borosSettlementFee?: number;
24
+ }): number;
25
+ export declare function calculateAprTimesMaxLeverage(strategy: Strategy, borosMargin: number, fees?: {
26
+ exchangeFee1?: number;
27
+ exchangeFee2?: number;
28
+ borosTradeFee?: number;
29
+ borosSettlementFee?: number;
30
+ }): number;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateStrategyFixedApr = calculateStrategyFixedApr;
4
+ exports.calculateStrategyFixedAprFixedX18 = calculateStrategyFixedAprFixedX18;
5
+ exports.calculateStrategy = calculateStrategy;
6
+ exports.calculateStrategyAprFromStrategy = calculateStrategyAprFromStrategy;
7
+ exports.calculateAprTimesMaxLeverage = calculateAprTimesMaxLeverage;
8
+ const boros_offchain_math_1 = require("@pendle/boros-offchain-math");
9
+ function calculateStrategyFixedApr(params) {
10
+ const { perpLeverage, daysToMaturity, borosMargin, impliedApr1, impliedApr2, exchangeFee1, exchangeFee2, borosTradeFee, borosSettlementFee, } = params;
11
+ if (daysToMaturity <= 0) {
12
+ return 0;
13
+ }
14
+ const impliedAprDiff = Math.abs(impliedApr1 - impliedApr2);
15
+ const annualizationFactor = 365 / daysToMaturity;
16
+ const totalExchangeFees = 2 * (exchangeFee1 + exchangeFee2);
17
+ const totalBorosFees = 2 * (borosSettlementFee + borosTradeFee);
18
+ const totalFees = totalExchangeFees + totalBorosFees;
19
+ const leverageFactor = 1 / (2 / perpLeverage + borosMargin);
20
+ const fixedApr = leverageFactor * (impliedAprDiff - annualizationFactor * totalFees);
21
+ return fixedApr;
22
+ }
23
+ function calculateStrategyFixedAprFixedX18(params) {
24
+ const { perpLeverage, daysToMaturity, borosMargin, impliedApr1, impliedApr2, exchangeFee1, exchangeFee2, borosTradeFee, borosSettlementFee, } = params;
25
+ if (daysToMaturity <= 0) {
26
+ return boros_offchain_math_1.FixedX18.ZERO;
27
+ }
28
+ const impliedAprDiff = impliedApr1.sub(impliedApr2).abs();
29
+ const annualizationFactor = boros_offchain_math_1.FixedX18.fromNumber(365 / daysToMaturity);
30
+ const two = boros_offchain_math_1.FixedX18.fromNumber(2);
31
+ const totalExchangeFees = exchangeFee1.add(exchangeFee2).mulDown(two);
32
+ const totalBorosFees = borosSettlementFee.add(borosTradeFee).mulDown(two);
33
+ const totalFees = totalExchangeFees.add(totalBorosFees);
34
+ const annualizedFees = annualizationFactor.mulDown(totalFees);
35
+ const netReturn = impliedAprDiff.sub(annualizedFees);
36
+ const twoOverPerpLev = boros_offchain_math_1.FixedX18.fromNumber(2 / perpLeverage);
37
+ const denominator = twoOverPerpLev.add(borosMargin);
38
+ const leverageFactor = boros_offchain_math_1.FixedX18.ONE.divDown(denominator);
39
+ const fixedApr = leverageFactor.mulDown(netReturn);
40
+ return fixedApr;
41
+ }
42
+ function calculateStrategy(input) {
43
+ const { totalCapital, daysToMaturity, perpLeverage, borosMargin, impliedApr1, impliedApr2, exchangeFee1, exchangeFee2, borosTradeFee, borosSettlementFee, } = input;
44
+ const params = {
45
+ perpLeverage,
46
+ daysToMaturity,
47
+ borosMargin: borosMargin / 100,
48
+ impliedApr1: impliedApr1 / 100,
49
+ impliedApr2: impliedApr2 / 100,
50
+ exchangeFee1: exchangeFee1 / 100,
51
+ exchangeFee2: exchangeFee2 / 100,
52
+ borosTradeFee: borosTradeFee / 100,
53
+ borosSettlementFee: borosSettlementFee / 100,
54
+ };
55
+ const fixedApr = calculateStrategyFixedApr(params);
56
+ const roi = fixedApr * (daysToMaturity / 365);
57
+ const estimatedEarnings = totalCapital * roi;
58
+ const estimatedEarningsPerYear = totalCapital * fixedApr;
59
+ return {
60
+ fixedApr,
61
+ fixedAprPercentage: fixedApr * 100,
62
+ estimatedEarnings,
63
+ estimatedEarningsPerYear,
64
+ };
65
+ }
66
+ function calculateStrategyAprFromStrategy(params) {
67
+ const { strategy, perpLeverage, borosMargin, exchangeFee1 = 0.0005, exchangeFee2 = 0.0005, borosTradeFee = 0.0005, borosSettlementFee = 0.002, } = params;
68
+ return calculateStrategyFixedApr({
69
+ perpLeverage,
70
+ daysToMaturity: strategy.daysToMaturity,
71
+ borosMargin,
72
+ impliedApr1: strategy.longMarket.impliedApr,
73
+ impliedApr2: strategy.shortMarket.impliedApr,
74
+ exchangeFee1,
75
+ exchangeFee2,
76
+ borosTradeFee,
77
+ borosSettlementFee,
78
+ });
79
+ }
80
+ function calculateAprTimesMaxLeverage(strategy, borosMargin, fees) {
81
+ const { exchangeFee1 = 0.0005, exchangeFee2 = 0.0005, borosTradeFee = 0.0005, borosSettlementFee = 0.002, } = fees ?? {};
82
+ return calculateStrategyFixedApr({
83
+ perpLeverage: strategy.maxPerpLeverage,
84
+ daysToMaturity: strategy.daysToMaturity,
85
+ borosMargin,
86
+ impliedApr1: strategy.longMarket.impliedApr,
87
+ impliedApr2: strategy.shortMarket.impliedApr,
88
+ exchangeFee1,
89
+ exchangeFee2,
90
+ borosTradeFee,
91
+ borosSettlementFee,
92
+ });
93
+ }
94
+ //# sourceMappingURL=strategyApr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategyApr.js","sourceRoot":"","sources":["../../../src/entities/Calculator/strategyApr.ts"],"names":[],"mappings":";;AAYA,8DA6BC;AAKD,8EAoDC;AAWD,8CAwCC;AAKD,4EA8BC;AAWD,oEA4BC;AA/ND,qEAAuD;AAYvD,SAAgB,yBAAyB,CAAC,MAA8B;IACtE,MAAM,EACJ,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,kBAAkB,GACnB,GAAG,MAAM,CAAC;IAEX,IAAI,cAAc,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC,CAAC;IAC3D,MAAM,mBAAmB,GAAG,GAAG,GAAG,cAAc,CAAC;IACjD,MAAM,iBA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AAiB;QACjB,wBAAwB;KACzB,CAAC;AACJ,CAAC;AAKD,SAAgB,gCAAgC,CAAC,MAQhD;IACC,MAAM,EACJ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,YAAY,GAAG,MAAM,EACrB,YAAY,GAAG,MAAM,EACrB,aAAa,GAAG,MAAM,EACtB,kBAAkB,GAAG,KAAK,GAC3B,GAAG,MAAM,CAAC;IAEX,OAAO,yBAAyB,CAAC;QAC/B,YAAY;QACZ,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,WAAW;QACX,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;QAC3C,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU;QAC5C,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC;AAWD,SAAgB,4BAA4B,CAC1C,QAAkB,EAClB,WAAmB,EACnB,IAKC;IAED,MAAM,EACJ,YAAY,GAAG,MAAM,EACrB,YAAY,GAAG,MAAM,EACrB,aAAa,GAAG,MAAM,EACtB,kBAAkB,GAAG,KAAK,GAC3B,GAAG,IAAI,IAAI,EAAE,CAAC;IAEf,OAAO,yBAAyB,CAAC;QAC/B,YAAY,EAAE,QAAQ,CAAC,eAAe;QACtC,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,WAAW;QACX,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU;QAC3C,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,UAAU;QAC5C,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Strategy, StrategyExecutionPlan } from './types';
2
+ export type GenerateExecutionPlanParams = {
3
+ strategy: Strategy;
4
+ totalCapital: number;
5
+ perpLeverage: number;
6
+ borosMargin: number;
7
+ };
8
+ export declare function generateExecutionPlan(params: GenerateExecutionPlanParams): StrategyExecutionPlan;
9
+ export declare function getExecutionStepsSummary(plan: StrategyExecutionPlan): string[];
10
+ export declare function formatExecutionStepsForUI(plan: StrategyExecutionPlan): Array<{
11
+ action: 'Long' | 'Short';
12
+ size: string;
13
+ description: string;
14
+ platform: 'perp' | 'boros';
15
+ exchange: string;
16
+ clickable: boolean;
17
+ }>;
18
+ export declare function calculateCapitalAllocation(params: {
19
+ totalCapital: number;
20
+ perpLeverage: number;
21
+ liquidationThreshold: number;
22
+ }): {
23
+ capitalPerPerpLeg: number;
24
+ capitalPerBorosLeg: number;
25
+ totalPerpCapital: number;
26
+ totalBorosCapital: number;
27
+ notionalExposurePerLeg: number;
28
+ };
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateExecutionPlan = generateExecutionPlan;
4
+ exports.getExecutionStepsSummary = getExecutionStepsSummary;
5
+ exports.formatExecutionStepsForUI = formatExecutionStepsForUI;
6
+ exports.calculateCapitalAllocation = calculateCapitalAllocation;
7
+ function generateExecutionPlan(params) {
8
+ const { strategy, totalCapital, perpLeverage, borosMargin } = params;
9
+ const positionSizePerLeg = totalCapital / (2 / perpLeverage + borosMargin);
10
+ const yuSize = positionSizePerLeg;
11
+ const steps = [
12
+ {
13
+ stepNumber: 1,
14
+ action: 'long',
15
+ platform: 'perp',
16
+ exchange: strategy.longMarket.exchange,
17
+ description: `Long ${strategy.asset} on ${strategy.longMarket.exchange} perpetual`,
18
+ details: {
19
+ asset: strategy.asset,
20
+ size: `${positionSizePerLeg} ${strategy.asset}`,
21
+ marketType: 'perpetual',
22
+ },
23
+ },
24
+ {
25
+ stepNumber: 2,
26
+ action: 'short',
27
+ platform: 'perp',
28
+ exchange: strategy.shortMarket.exchange,
29
+ description: `Short ${strategy.asset} on ${strategy.shortMarket.exchange} perpetual`,
30
+ details: {
31
+ asset: strategy.asset,
32
+ size: `${positionSizePerLeg} ${strategy.asset}`,
33
+ marketType: 'perpetual',
34
+ },
35
+ },
36
+ {
37
+ stepNumber: 3,
38
+ action: 'long',
39
+ platform: 'boros',
40
+ exchange: strategy.longMarket.exchange,
41
+ description: `Long ${strategy.asset} YU on Boros ${strategy.longMarket.exchange} market`,
42
+ marketId: strategy.longMarket.marketId,
43
+ ammId: strategy.longMarket.ammId,
44
+ details: {
45
+ asset: strategy.asset,
46
+ size: `${yuSize} YU ${strategy.asset}`,
47
+ marketType: `Boros ${strategy.longMarket.exchange} market`,
48
+ },
49
+ },
50
+ {
51
+ stepNumber: 4,
52
+ action: 'short',
53
+ platform: 'boros',
54
+ exchange: strategy.shortMarket.exchange,
55
+ description: `Short ${strategy.asset} YU on Boros ${strategy.shortMarket.exchange} market`,
56
+ marketId: strategy.shortMarket.marketId,
57
+ ammId: strategy.shortMarket.ammId,
58
+ details: {
59
+ asset: strategy.asset,
60
+ size: `${yuSize} YU ${strategy.asset}`,
61
+ marketType: `Boros ${strategy.shortMarket.exchange} market`,
62
+ },
63
+ },
64
+ ];
65
+ return {
66
+ strategy,
67
+ steps,
68
+ totalCapitalRequired: totalCapital,
69
+ perpLeverage,
70
+ borosMargin,
71
+ };
72
+ }
73
+ function getExecutionStepsSummary(plan) {
74
+ return plan.steps.map((step) => {
75
+ const actionText = step.action === 'long' ? 'Long' : 'Short';
76
+ return `${actionText} ${step.details.size} on ${step.details.marketType}`;
77
+ });
78
+ }
79
+ function formatExecutionStepsForUI(plan) {
80
+ const { strategy, totalCapitalRequired, perpLeverage, borosMargin } = plan;
81
+ const positionSize = totalCapitalRequired / (2 / perpLeverage + borosMargin);
82
+ return [
83
+ {
84
+ action: 'Long',
85
+ size: `${positionSize} ${strategy.asset}`,
86
+ description: `on ${strategy.longMarket.exchange} ${strategy.asset} perpetual`,
87
+ platform: 'perp',
88
+ exchange: strategy.longMarket.exchange,
89
+ clickable: true,
90
+ },
91
+ {
92
+ action: 'Short',
93
+ size: `${positionSize} ${strategy.asset}`,
94
+ description: `on ${strategy.shortMarket.exchange} ${strategy.asset} perpetual`,
95
+ platform: 'perp',
96
+ exchange: strategy.shortMarket.exchange,
97
+ clickable: true,
98
+ },
99
+ {
100
+ action: 'Long',
101
+ size: `${positionSize} YU ${strategy.asset}`,
102
+ description: `on Boros ${strategy.longMarket.exchange} ${strategy.asset} market`,
103
+ platform: 'boros',
104
+ exchange: strategy.longMarket.exchange,
105
+ clickable: true,
106
+ },
107
+ {
108
+ action: 'Short',
109
+ size: `${positionSize} YU ${strategy.asset}`,
110
+ description: `on Boros ${strategy.shortMarket.exchange} ${strategy.asset} market`,
111
+ platform: 'boros',
112
+ exchange: strategy.shortMarket.exchange,
113
+ clickable: true,
114
+ },
115
+ ];
116
+ }
117
+ function calculateCapitalAllocation(params) {
118
+ const { totalCapital, perpLeverage, liquidationThreshold } = params;
119
+ const capitalPerPerpLeg = totalCapital / 2;
120
+ const notionalExposurePerLeg = capitalPerPerpLeg * perpLeverage;
121
+ const capitalPerBorosLeg = 0;
122
+ return {
123
+ capitalPerPerpLeg,
124
+ capitalPerBorosLeg,
125
+ totalPerpCapital: totalCapital,
126
+ totalBorosCapital: 0,
127
+ notionalExposurePerLeg,
128
+ };
129
+ }
130
+ //# sourceMappingURL=strategyExecution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategyExecution.js","sourceRoot":"","sources":["../../../src/entities/Calculator/strategyExecution.ts"],"names":[],"mappings":";;AAoBA,sDA6EC;AAKD,4DAKC;AAKD,8DAgDC;AAKD,gEA6BC;AA9KD,SAAgB,qBAAqB,CAAC,MAAmC;IACvE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAKrE,MAAM,kBAAkB,GAAG,YAAY,GAAG,CAAC,CAAC,GAAG,YAAY,GAAG,WAAW,CAAC,CAAC;IAG3E,MAAM,MAAM,GAAG,kBAAkB,CAAC;IAElC,MAAM,KAAK,GAA4B;QAErC;YACE,UAAU,EAAE,CAAC;YACb,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,MAAM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G,YAAY,GAAG,CAAC,CAAC;IAC3C,MAAM,sBAAsB,GAAG,iBAAiB,GAAG,YAAY,CAAC;IAGhE,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAE7B,OAAO;QACL,iBAAiB;QACjB,kBAAkB;QAClB,gBAAgB,EAAE,YAAY;QAC9B,iBAAiB,EAAE,CAAC;QACpB,sBAAsB;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { GetStrategiesParams, GetStrategiesResult } from './types';
2
+ export declare function findStrategies(params?: GetStrategiesParams): Promise<GetStrategiesResult>;
3
+ export declare function findStrategiesByAsset(params: GetStrategiesParams & {
4
+ asset: string;
5
+ }): Promise<GetStrategiesResult>;
6
+ export declare function findStrategiesByMaturity(params: GetStrategiesParams & {
7
+ maturity: number;
8
+ }): Promise<GetStrategiesResult>;
9
+ export declare function findStrategiesByExchanges(params: GetStrategiesParams & {
10
+ exchanges: [string, string];
11
+ }): Promise<GetStrategiesResult>;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findStrategies = findStrategies;
4
+ exports.findStrategiesByAsset = findStrategiesByAsset;
5
+ exports.findStrategiesByMaturity = findStrategiesByMaturity;
6
+ exports.findStrategiesByExchanges = findStrategiesByExchanges;
7
+ const module_1 = require("../../backend/secrettune/module");
8
+ const SECONDS_PER_DAY = 86400;
9
+ async function fetchMarkets() {
10
+ const sdk = (0, module_1.getCoreSdk)();
11
+ const { data } = await sdk.markets.marketsControllerGetMarkets({});
12
+ return data.results;
13
+ }
14
+ function toStrategyMarket(market) {
15
+ if (!market.metadata) {
16
+ return null;
17
+ }
18
+ const impliedApr = market.data?.ammImpliedApr ?? market.data?.midApr ?? 0;
19
+ return {
20
+ marketId: market.marketId,
21
+ address: market.address,
22
+ exchange: market.metadata.platformName,
23
+ impliedApr,
24
+ maxLeverage: market.metadata.maxLeverage,
25
+ ammId: market.metadata.ammId,
26
+ ammAddress: market.metadata.ammAddress,
27
+ marketName: market.metadata.marketName,
28
+ rawMarket: market,
29
+ };
30
+ }
31
+ function createMarketGroupKey(market) {
32
+ if (!market.metadata?.assetSymbol) {
33
+ return null;
34
+ }
35
+ return `${market.metadata.assetSymbol}-${market.tokenId}-${market.imData.maturity}`;
36
+ }
37
+ function createStrategyId(asset, collateralTokenId, maturity, longExchange, shortExchange) {
38
+ return `${asset}-${collateralTokenId}-${maturity}-${longExchange}-${shortExchange}`;
39
+ }
40
+ async function findStrategies(params) {
41
+ const { markets: providedMarkets, minImpliedAprSpread = 0, excludeDevTest = true } = params ?? {};
42
+ const markets = providedMarkets ?? (await fetchMarkets());
43
+ const validMarkets = markets.filter((market) => {
44
+ if (!market.metadata?.assetSymbol)
45
+ return false;
46
+ if (!market.metadata?.platformName)
47
+ return false;
48
+ if (market.state === 'Paused' || market.state === 'Halted')
49
+ return false;
50
+ if (excludeDevTest && market.metadata.isDevTest)
51
+ return false;
52
+ return true;
53
+ });
54
+ const marketGroups = new Map();
55
+ for (const market of validMarkets) {
56
+ const key = createMarketGroupKey(market);
57
+ if (!key)
58
+ continue;
59
+ const group = marketGroups.get(key) ?? [];
60
+ group.push(market);
61
+ marketGroups.set(key, group);
62
+ }
63
+ const strategies = [];
64
+ for (const [, groupMarkets] of marketGroups) {
65
+ if (groupMarkets.length < 2)
66
+ continue;
67
+ const byExchange = new Map();
68
+ for (const market of groupMarkets) {
69
+ const exchange = market.metadata.platformName;
70
+ const exchangeMarkets = byExchange.get(exchange) ?? [];
71
+ exchangeMarkets.push(market);
72
+ byExchange.set(exchange, exchangeMarkets);
73
+ }
74
+ const exchanges = Array.from(byExchange.keys());
75
+ if (exchanges.length < 2)
76
+ continue;
77
+ for (let i = 0; i < exchanges.length; i++) {
78
+ for (let j = i + 1; j < exchanges.length; j++) {
79
+ const exchange1Markets = byExchange.get(exchanges[i]);
80
+ const exchange2Markets = byExchange.get(exchanges[j]);
81
+ for (const market1 of exchange1Markets) {
82
+ for (const market2 of exchange2Markets) {
83
+ const strategyMarket1 = toStrategyMarket(market1);
84
+ const strategyMarket2 = toStrategyMarket(market2);
85
+ if (!strategyMarket1 || !strategyMarket2)
86
+ continue;
87
+ const impliedAprSpread = Math.abs(strategyMarket1.impliedApr - strategyMarket2.impliedApr);
88
+ if (impliedAprSpread < minImpliedAprSpread)
89
+ continue;
90
+ let longMarket;
91
+ let shortMarket;
92
+ if (strategyMarket1.impliedApr >= strategyMarket2.impliedApr) {
93
+ longMarket = strategyMarket1;
94
+ shortMarket = strategyMarket2;
95
+ }
96
+ else {
97
+ longMarket = strategyMarket2;
98
+ shortMarket = strategyMarket1;
99
+ }
100
+ const asset = market1.metadata.assetSymbol;
101
+ const collateralTokenId = market1.tokenId;
102
+ const maturity = market1.imData.maturity;
103
+ const timeToMaturity = market1.data?.timeToMaturity ?? (maturity - Math.floor(Date.now() / 1000));
104
+ const daysToMaturity = Math.max(0, Math.ceil(timeToMaturity / SECONDS_PER_DAY));
105
+ const strategy = {
106
+ id: createStrategyId(asset, collateralTokenId, maturity, longMarket.exchange, shortMarket.exchange),
107
+ asset,
108
+ collateralTokenId,
109
+ maturity,
110
+ timeToMaturity,
111
+ daysToMaturity,
112
+ longMarket,
113
+ shortMarket,
114
+ impliedAprSpread,
115
+ maxPerpLeverage: Math.min(longMarket.maxLeverage, shortMarket.maxLeverage),
116
+ };
117
+ strategies.push(strategy);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ strategies.sort((a, b) => b.impliedAprSpread - a.impliedAprSpread);
124
+ return {
125
+ strategies,
126
+ totalCount: strategies.length,
127
+ };
128
+ }
129
+ async function findStrategiesByAsset(params) {
130
+ const { asset, ...rest } = params;
131
+ const result = await findStrategies(rest);
132
+ const filtered = result.strategies.filter((s) => s.asset.toUpperCase() === asset.toUpperCase());
133
+ return {
134
+ strategies: filtered,
135
+ totalCount: filtered.length,
136
+ };
137
+ }
138
+ async function findStrategiesByMaturity(params) {
139
+ const { maturity, ...rest } = params;
140
+ const result = await findStrategies(rest);
141
+ const filtered = result.strategies.filter((s) => s.maturity === maturity);
142
+ return {
143
+ strategies: filtered,
144
+ totalCount: filtered.length,
145
+ };
146
+ }
147
+ async function findStrategiesByExchanges(params) {
148
+ const { exchanges, ...rest } = params;
149
+ const [exchange1, exchange2] = exchanges.map((e) => e.toLowerCase());
150
+ const result = await findStrategies(rest);
151
+ const filtered = result.strategies.filter((s) => {
152
+ const longExchange = s.longMarket.exchange.toLowerCase();
153
+ const shortExchange = s.shortMarket.exchange.toLowerCase();
154
+ return ((longExchange === exchange1 && shortExchange === exchange2) ||
155
+ (longExchange === exchange2 && shortExchange === exchange1));
156
+ });
157
+ return {
158
+ strategies: filtered,
159
+ totalCount: filtered.length,
160
+ };
161
+ }
162
+ //# sourceMappingURL=strategyFinder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategyFinder.js","sourceRoot":"","sources":["../../../src/entities/Calculator/strategyFinder.ts"],"names":[],"mappings":";;AA2EA,wCAkHC;AAKD,sDAYC;AAKD,4DAYC;AAKD,8DAoBC;AAvPD,4DAA6D;AAG7D,MAAM,eAAe,GAAG,KAAK,CAAC;AAK9B,KAAK,UAAU,YAAY;IACzB,MAAM,GAAG,GAAG,IAAA,mBAAU,GAAE,CAAC;IACzB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,2BAA2B,CAAC,EAAE,CAAC,CAAC;IACnE,OAAO,IAAI,CAAC,OAAO,CAAC;AACtB,CAAC;AAKD,SAAS,gBAAgB,CAAC,MAAsB;IAC9C,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;IAE1E,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,OAAO,EAAE,MAAM,CA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,EAAE,CAAC;QAC3D,OAAO,CACL,CAAC,YAAY,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,CAAC;YAC3D,CAAC,YAAY,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,CAAC,CAC5D,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,UAAU,EAAE,QAAQ;QACpB,UAAU,EAAE,QAAQ,CAAC,MAAM;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { MarketResponse } from '../../backend/secrettune/BorosCoreSDK';
2
+ export type StrategyMarket = {
3
+ marketId: number;
4
+ address: string;
5
+ exchange: string;
6
+ impliedApr: number;
7
+ maxLeverage: number;
8
+ ammId?: number;
9
+ ammAddress?: string;
10
+ marketName?: string;
11
+ rawMarket: MarketResponse;
12
+ };
13
+ export type Strategy = {
14
+ id: string;
15
+ asset: string;
16
+ collateralTokenId: number;
17
+ maturity: number;
18
+ timeToMaturity: number;
19
+ daysToMaturity: number;
20
+ longMarket: StrategyMarket;
21
+ shortMarket: StrategyMarket;
22
+ impliedAprSpread: number;
23
+ maxPerpLeverage: number;
24
+ };
25
+ export type StrategyExecutionStep = {
26
+ stepNumber: number;
27
+ action: 'long' | 'short';
28
+ platform: 'boros' | 'perp';
29
+ exchange: string;
30
+ description: string;
31
+ marketId?: number;
32
+ ammId?: number;
33
+ details: {
34
+ asset: string;
35
+ size: string;
36
+ marketType: string;
37
+ };
38
+ };
39
+ export type StrategyExecutionPlan = {
40
+ strategy: Strategy;
41
+ steps: StrategyExecutionStep[];
42
+ totalCapitalRequired: number;
43
+ perpLeverage: number;
44
+ borosMargin: number;
45
+ };
46
+ export type StrategyFixedAprParams = {
47
+ perpLeverage: number;
48
+ daysToMaturity: number;
49
+ borosMargin: number;
50
+ impliedApr1: number;
51
+ impliedApr2: number;
52
+ exchangeFee1: number;
53
+ exchangeFee2: number;
54
+ borosTradeFee: number;
55
+ borosSettlementFee: number;
56
+ };
57
+ export type StrategyCalculatorInput = {
58
+ totalCapital: number;
59
+ liquidationThreshold: number;
60
+ daysToMaturity: number;
61
+ perpLeverage: number;
62
+ borosMargin: number;
63
+ impliedApr1: number;
64
+ impliedApr2: number;
65
+ exchangeFee1: number;
66
+ exchangeFee2: number;
67
+ borosTradeFee: number;
68
+ borosSettlementFee: number;
69
+ };
70
+ export type StrategyCalculatorResult = {
71
+ fixedApr: number;
72
+ fixedAprPercentage: number;
73
+ estimatedEarnings: number;
74
+ estimatedEarningsPerYear: number;
75
+ };
76
+ export type GetStrategiesParams = {
77
+ markets?: MarketResponse[];
78
+ minImpliedAprSpread?: number;
79
+ excludeDevTest?: boolean;
80
+ };
81
+ export type GetStrategiesResult = {
82
+ strategies: Strategy[];
83
+ totalCount: number;
84
+ };
@@ -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":["../../../src/entities/Calculator/types.ts"],"names":[],"mappings":""}