@sonarwatch/portfolio-plugins 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.json +2 -2
- package/src/Cache.d.ts +3 -1
- package/src/Cache.js +52 -14
- package/src/Cache.js.map +1 -1
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/platforms.d.ts +2 -0
- package/src/platforms.js +11 -1
- package/src/platforms.js.map +1 -1
- package/src/plugins/cetus/clmmsFetcher.d.ts +3 -0
- package/src/plugins/cetus/clmmsFetcher.js +109 -0
- package/src/plugins/cetus/clmmsFetcher.js.map +1 -0
- package/src/plugins/cetus/constants.d.ts +5 -0
- package/src/plugins/cetus/constants.js +9 -0
- package/src/plugins/cetus/constants.js.map +1 -0
- package/src/plugins/cetus/helpers.d.ts +16 -0
- package/src/plugins/cetus/helpers.js +194 -0
- package/src/plugins/cetus/helpers.js.map +1 -0
- package/src/plugins/cetus/index.d.ts +4 -0
- package/src/plugins/cetus/index.js +11 -0
- package/src/plugins/cetus/index.js.map +1 -0
- package/src/plugins/cetus/poolsJob.d.ts +3 -0
- package/src/plugins/cetus/poolsJob.js +54 -0
- package/src/plugins/cetus/poolsJob.js.map +1 -0
- package/src/plugins/cetus/types.d.ts +90 -0
- package/src/plugins/cetus/types.js +10 -0
- package/src/plugins/cetus/types.js.map +1 -0
- package/src/plugins/orca/clmmPositionsFetcher.js +2 -2
- package/src/plugins/orca/clmmPositionsFetcher.js.map +1 -1
- package/src/plugins/orca/helpers.d.ts +0 -10
- package/src/plugins/orca/helpers.js +1 -193
- package/src/plugins/orca/helpers.js.map +1 -1
- package/src/plugins/tokens/fetchers/evms/evmNativeExecutorGenerator.d.ts +3 -0
- package/src/plugins/tokens/fetchers/evms/evmNativeExecutorGenerator.js +49 -0
- package/src/plugins/tokens/fetchers/evms/evmNativeExecutorGenerator.js.map +1 -0
- package/src/plugins/tokens/fetchers/evms/index.js +7 -5
- package/src/plugins/tokens/fetchers/evms/index.js.map +1 -1
- package/src/plugins/tokens/index.js +4 -0
- package/src/plugins/tokens/index.js.map +1 -1
- package/src/plugins/turbos/clmmsPositionsFetcher.d.ts +3 -0
- package/src/plugins/turbos/clmmsPositionsFetcher.js +128 -0
- package/src/plugins/turbos/clmmsPositionsFetcher.js.map +1 -0
- package/src/plugins/turbos/constants.d.ts +5 -0
- package/src/plugins/turbos/constants.js +9 -0
- package/src/plugins/turbos/constants.js.map +1 -0
- package/src/plugins/turbos/helper.d.ts +8 -0
- package/src/plugins/turbos/helper.js +34 -0
- package/src/plugins/turbos/helper.js.map +1 -0
- package/src/plugins/turbos/index.d.ts +4 -0
- package/src/plugins/turbos/index.js +11 -0
- package/src/plugins/turbos/index.js.map +1 -0
- package/src/plugins/turbos/poolsJob.d.ts +3 -0
- package/src/plugins/turbos/poolsJob.js +53 -0
- package/src/plugins/turbos/poolsJob.js.map +1 -0
- package/src/plugins/turbos/types.d.ts +103 -0
- package/src/plugins/turbos/types.js +3 -0
- package/src/plugins/turbos/types.js.map +1 -0
- package/src/utils/clients/constants.js +2 -0
- package/src/utils/clients/constants.js.map +1 -1
- package/src/utils/clients/getEvmClients.js +1 -0
- package/src/utils/clients/getEvmClients.js.map +1 -1
- package/src/utils/clmm/tokenAmountFromLiquidity.d.ts +10 -0
- package/src/utils/clmm/tokenAmountFromLiquidity.js +199 -0
- package/src/utils/clmm/tokenAmountFromLiquidity.js.map +1 -0
@@ -0,0 +1,128 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
16
|
+
const sui_js_1 = require("@mysten/sui.js");
|
17
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
18
|
+
const constants_1 = require("./constants");
|
19
|
+
const clients_1 = require("../../utils/clients");
|
20
|
+
const tokenAmountFromLiquidity_1 = require("../../utils/clmm/tokenAmountFromLiquidity");
|
21
|
+
const tokenPriceToAssetToken_1 = __importDefault(require("../../utils/misc/tokenPriceToAssetToken"));
|
22
|
+
const helper_1 = require("./helper");
|
23
|
+
const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
24
|
+
const client = (0, clients_1.getClientSui)();
|
25
|
+
const nftsPositionsRes = yield client.getOwnedObjects({
|
26
|
+
owner,
|
27
|
+
options: {
|
28
|
+
showType: true,
|
29
|
+
showContent: true,
|
30
|
+
showDisplay: true,
|
31
|
+
showOwner: true,
|
32
|
+
},
|
33
|
+
filter: { Package: constants_1.packageIdOriginal },
|
34
|
+
});
|
35
|
+
if (!nftsPositionsRes.data)
|
36
|
+
return [];
|
37
|
+
const clmmPoolsIds = [];
|
38
|
+
const clmmPositionsIds = [];
|
39
|
+
const nftPositionByPositionId = new Map();
|
40
|
+
for (let i = 0; i < nftsPositionsRes.data.length; i++) {
|
41
|
+
const nftData = nftsPositionsRes.data[i].data;
|
42
|
+
if (!nftData)
|
43
|
+
continue;
|
44
|
+
if (nftData.type !== constants_1.clmmNftType)
|
45
|
+
continue;
|
46
|
+
const nftPositionFields = (0, sui_js_1.getObjectFields)(nftData);
|
47
|
+
clmmPoolsIds.push(nftPositionFields.pool_id);
|
48
|
+
clmmPositionsIds.push(nftPositionFields.position_id);
|
49
|
+
nftPositionByPositionId.set(nftPositionFields.position_id, nftPositionFields);
|
50
|
+
}
|
51
|
+
const pools = yield cache.getItems(clmmPoolsIds, {
|
52
|
+
prefix: constants_1.clmmPoolsPrefix,
|
53
|
+
networkId: portfolio_core_1.NetworkId.sui,
|
54
|
+
});
|
55
|
+
const poolsById = new Map();
|
56
|
+
pools.forEach((pool) => {
|
57
|
+
if (pool) {
|
58
|
+
poolsById.set(pool.objectId, pool);
|
59
|
+
}
|
60
|
+
});
|
61
|
+
const clmmPositionsRes = yield client.multiGetObjects({
|
62
|
+
ids: clmmPositionsIds,
|
63
|
+
options: {
|
64
|
+
showType: true,
|
65
|
+
showContent: true,
|
66
|
+
showDisplay: true,
|
67
|
+
showOwner: true,
|
68
|
+
},
|
69
|
+
});
|
70
|
+
const assets = [];
|
71
|
+
let totalLiquidityValue = 0;
|
72
|
+
for (let i = 0; i < clmmPositionsRes.length; i++) {
|
73
|
+
const clmmPosition = (0, sui_js_1.getObjectFields)(clmmPositionsRes[i]);
|
74
|
+
const nftPosition = nftPositionByPositionId.get(clmmPosition.id.id);
|
75
|
+
if (!nftPosition)
|
76
|
+
continue;
|
77
|
+
const pool = poolsById.get(nftPosition.pool_id);
|
78
|
+
if (!pool)
|
79
|
+
continue;
|
80
|
+
const { tokenAmountA, tokenAmountB } = (0, tokenAmountFromLiquidity_1.getTokenAmountsFromLiquidity)(new bignumber_js_1.default(clmmPosition.liquidity).toNumber(), (0, helper_1.bitsToNumber)(pool.tick_current_index), (0, helper_1.bitsToNumber)(clmmPosition.tick_lower_index), (0, helper_1.bitsToNumber)(clmmPosition.tick_upper_index), 0);
|
81
|
+
// TODO : améliorer le problème du 0x000002::sui::SUI + manque de 0x
|
82
|
+
const coinA = (0, helper_1.formatForNative)(`0x${nftPosition.coin_type_a.fields.name}`);
|
83
|
+
const coinB = (0, helper_1.formatForNative)(`0x${nftPosition.coin_type_b.fields.name}`);
|
84
|
+
const tokenPriceA = yield cache.getTokenPrice(coinA, portfolio_core_1.NetworkId.sui);
|
85
|
+
if (!tokenPriceA)
|
86
|
+
continue;
|
87
|
+
const assetTokenA = (0, tokenPriceToAssetToken_1.default)(coinA, tokenAmountA / Math.pow(10, tokenPriceA.decimals), portfolio_core_1.NetworkId.sui, tokenPriceA);
|
88
|
+
const tokenPriceB = yield cache.getTokenPrice(coinB, portfolio_core_1.NetworkId.sui);
|
89
|
+
if (!tokenPriceB)
|
90
|
+
continue;
|
91
|
+
const assetTokenB = (0, tokenPriceToAssetToken_1.default)(coinB, tokenAmountB / Math.pow(10, tokenPriceB.decimals), portfolio_core_1.NetworkId.sui, tokenPriceB);
|
92
|
+
if (!assetTokenA ||
|
93
|
+
!assetTokenB ||
|
94
|
+
assetTokenA.value === null ||
|
95
|
+
assetTokenB.value === null)
|
96
|
+
continue;
|
97
|
+
const value = assetTokenA.value + assetTokenB.value;
|
98
|
+
assets.push({
|
99
|
+
assets: [assetTokenA, assetTokenB],
|
100
|
+
assetsValue: value,
|
101
|
+
rewardAssets: [],
|
102
|
+
rewardAssetsValue: 0,
|
103
|
+
value,
|
104
|
+
yields: [],
|
105
|
+
});
|
106
|
+
totalLiquidityValue += value;
|
107
|
+
}
|
108
|
+
return [
|
109
|
+
{
|
110
|
+
type: portfolio_core_1.PortfolioElementType.liquidity,
|
111
|
+
networkId: portfolio_core_1.NetworkId.sui,
|
112
|
+
platformId: constants_1.platformId,
|
113
|
+
label: 'LiquidityPool',
|
114
|
+
tags: ['Concentrated'],
|
115
|
+
value: totalLiquidityValue,
|
116
|
+
data: {
|
117
|
+
liquidities: assets,
|
118
|
+
},
|
119
|
+
},
|
120
|
+
];
|
121
|
+
});
|
122
|
+
const fetcher = {
|
123
|
+
id: `${constants_1.platformId}-clmms-positions`,
|
124
|
+
networkId: portfolio_core_1.NetworkId.sui,
|
125
|
+
executor,
|
126
|
+
};
|
127
|
+
exports.default = fetcher;
|
128
|
+
//# sourceMappingURL=clmmsPositionsFetcher.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"clmmsPositionsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/clmmsPositionsFetcher.ts"],"names":[],"mappings":"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"}
|
@@ -0,0 +1,5 @@
|
|
1
|
+
export declare const platformId = "turbos";
|
2
|
+
export declare const clmmPoolsPrefix: string;
|
3
|
+
export declare const poolTableId = "0x08984ed8705f44b6403705dc248896e56ab7961447820ae29be935ce0d32198b";
|
4
|
+
export declare const packageIdOriginal = "0x91bfbc386a41afcfd9b2533058d7e915a1d3829089cc268ff4333d54d6339ca1";
|
5
|
+
export declare const clmmNftType: string;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.clmmNftType = exports.packageIdOriginal = exports.poolTableId = exports.clmmPoolsPrefix = exports.platformId = void 0;
|
4
|
+
exports.platformId = 'turbos';
|
5
|
+
exports.clmmPoolsPrefix = `${exports.platformId}-clmmPools`;
|
6
|
+
exports.poolTableId = '0x08984ed8705f44b6403705dc248896e56ab7961447820ae29be935ce0d32198b';
|
7
|
+
exports.packageIdOriginal = '0x91bfbc386a41afcfd9b2533058d7e915a1d3829089cc268ff4333d54d6339ca1';
|
8
|
+
exports.clmmNftType = `${exports.packageIdOriginal}::position_nft::TurbosPositionNFT`;
|
9
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,QAAQ,CAAC;AACtB,QAAA,eAAe,GAAG,GAAG,kBAAU,YAAY,CAAC;AAE5C,QAAA,WAAW,GACtB,oEAAoE,CAAC;AAE1D,QAAA,iBAAiB,GAC5B,oEAAoE,CAAC;AAE1D,QAAA,WAAW,GAAG,GAAG,yBAAiB,mCAAmC,CAAC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { SuiObjectResponse } from '@mysten/sui.js';
|
2
|
+
import { Bits, Pool, Types } from './types';
|
3
|
+
export declare function parsePoolType(type: string, length: 2): [string, string];
|
4
|
+
export declare function parsePoolType(type: string, length: 3): Types;
|
5
|
+
export declare function parsePoolType(type: string): string[];
|
6
|
+
export declare function parsePool(pool: SuiObjectResponse): Pool;
|
7
|
+
export declare function formatForNative(coin: string): string;
|
8
|
+
export declare function bitsToNumber(bits: Bits): number;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bitsToNumber = exports.formatForNative = exports.parsePool = exports.parsePoolType = void 0;
|
4
|
+
const sui_js_1 = require("@mysten/sui.js");
|
5
|
+
const helpers_1 = require("../cetus/helpers");
|
6
|
+
function parsePoolType(type, length) {
|
7
|
+
var _a;
|
8
|
+
const types = ((_a = type.replace('>', '').split('<')[1]) === null || _a === void 0 ? void 0 : _a.split(/,\s*/)) || [];
|
9
|
+
if (length !== undefined && length !== types.length) {
|
10
|
+
throw new Error('Invalid pool type');
|
11
|
+
}
|
12
|
+
return types;
|
13
|
+
}
|
14
|
+
exports.parsePoolType = parsePoolType;
|
15
|
+
function parsePool(pool) {
|
16
|
+
const fields = (0, sui_js_1.getObjectFields)(pool);
|
17
|
+
const objectId = (0, sui_js_1.getObjectId)(pool);
|
18
|
+
const type = (0, sui_js_1.getObjectType)(pool);
|
19
|
+
return Object.assign(Object.assign({}, fields), { objectId,
|
20
|
+
type, types: parsePoolType(type, 3) });
|
21
|
+
}
|
22
|
+
exports.parsePool = parsePool;
|
23
|
+
function formatForNative(coin) {
|
24
|
+
return coin ===
|
25
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI'
|
26
|
+
? '0x2::sui::SUI'
|
27
|
+
: coin;
|
28
|
+
}
|
29
|
+
exports.formatForNative = formatForNative;
|
30
|
+
function bitsToNumber(bits) {
|
31
|
+
return (0, helpers_1.asIntN)(BigInt(bits.fields.bits));
|
32
|
+
}
|
33
|
+
exports.bitsToNumber = bitsToNumber;
|
34
|
+
//# sourceMappingURL=helper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/helper.ts"],"names":[],"mappings":";;;AAAA,2CAKwB;AAExB,8CAA0C;AAK1C,SAAgB,aAAa,CAAC,IAAY,EAAE,MAAe;;IACzD,MAAM,KAAK,GAAG,CAAA,MAAA,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,MAAM,CAAC,KAAI,EAAE,CAAC;IAEvE,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE;QACnD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;KACtC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AARD,sCAQC;AACD,SAAgB,SAAS,CAAC,IAAuB;IAC/C,MAAM,MAAM,GAAG,IAAA,wBAAe,EAAC,IAAI,CAAe,CAAC;IACnD,MAAM,QAAQ,GAAG,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAA,sBAAa,EAAC,IAAI,CAAE,CAAC;IAClC,uCACK,MAAM,KACT,QAAQ;QACR,IAAI,EACJ,KAAK,EAAE,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,IAC7B;AACJ,CAAC;AAVD,8BAUC;AAED,SAAgB,eAAe,CAAC,IAAY;IAC1C,OAAO,IAAI;QACT,8EAA8E;QAC9E,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AALD,0CAKC;AAED,SAAgB,YAAY,CAAC,IAAU;IACrC,OAAO,IAAA,gBAAM,EAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC;AAFD,oCAEC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.fetchers = exports.jobs = void 0;
|
7
|
+
const poolsJob_1 = __importDefault(require("./poolsJob"));
|
8
|
+
const clmmsPositionsFetcher_1 = __importDefault(require("./clmmsPositionsFetcher"));
|
9
|
+
exports.jobs = [poolsJob_1.default];
|
10
|
+
exports.fetchers = [clmmsPositionsFetcher_1.default];
|
11
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/index.ts"],"names":[],"mappings":";;;;;;AAEA,0DAAkC;AAClC,oFAA0D;AAE7C,QAAA,IAAI,GAAU,CAAC,kBAAQ,CAAC,CAAC;AACzB,QAAA,QAAQ,GAAc,CAAC,+BAAmB,CAAC,CAAC"}
|
@@ -0,0 +1,53 @@
|
|
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 sui_js_1 = require("@mysten/sui.js");
|
13
|
+
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
14
|
+
const constants_1 = require("./constants");
|
15
|
+
const clients_1 = require("../../utils/clients");
|
16
|
+
const helper_1 = require("./helper");
|
17
|
+
const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
|
18
|
+
const client = (0, clients_1.getClientSui)();
|
19
|
+
const poolFactories = yield client.getDynamicFields({
|
20
|
+
parentId: constants_1.poolTableId,
|
21
|
+
});
|
22
|
+
const poolFactoryIds = poolFactories.data.map(sui_js_1.getObjectId);
|
23
|
+
if (!poolFactoryIds.length)
|
24
|
+
return;
|
25
|
+
const poolFactoryInfos = yield client.multiGetObjects({
|
26
|
+
ids: poolFactoryIds,
|
27
|
+
options: { showContent: true },
|
28
|
+
});
|
29
|
+
const poolIds = poolFactoryInfos.map((info) => {
|
30
|
+
const fields = (0, sui_js_1.getObjectFields)(info);
|
31
|
+
return fields.value.fields.pool_id;
|
32
|
+
});
|
33
|
+
if (!poolIds.length)
|
34
|
+
return;
|
35
|
+
const pools = yield client.multiGetObjects({
|
36
|
+
ids: poolIds,
|
37
|
+
options: { showContent: true },
|
38
|
+
});
|
39
|
+
const promises = pools.map((pool) => {
|
40
|
+
const parsedPool = (0, helper_1.parsePool)(pool);
|
41
|
+
return cache.setItem(parsedPool.objectId, parsedPool, {
|
42
|
+
prefix: constants_1.clmmPoolsPrefix,
|
43
|
+
networkId: portfolio_core_1.NetworkId.sui,
|
44
|
+
});
|
45
|
+
});
|
46
|
+
yield Promise.allSettled(promises);
|
47
|
+
});
|
48
|
+
const job = {
|
49
|
+
id: `${constants_1.platformId}-pools`,
|
50
|
+
executor,
|
51
|
+
};
|
52
|
+
exports.default = job;
|
53
|
+
//# sourceMappingURL=poolsJob.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"poolsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/poolsJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAAgF;AAChF,+DAAuD;AAGvD,2CAAuE;AACvE,iDAAmD;AACnD,qCAAqC;AAErC,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAA,sBAAY,GAAE,CAAC;IAC9B,MAAM,aAAa,GAAqB,MAAM,MAAM,CAAC,gBAAgB,CAAC;QACpE,QAAQ,EAAE,uBAAW;KACtB,CAAC,CAAC;IACH,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,oBAAW,CAAC,CAAC;IAC3D,IAAI,CAAC,cAAc,CAAC,MAAM;QAAE,OAAO;IAEnC,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;QACpD,GAAG,EAAE,cAAc;QACnB,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;KAC/B,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,IAAA,wBAAe,EAAC,IAAI,CAOlC,CAAC;QACF,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC;IACrC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO;IAC5B,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;QACzC,GAAG,EAAE,OAAO;QACZ,OAAO,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE;KAC/B,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QAClC,MAAM,UAAU,GAAG,IAAA,kBAAS,EAAC,IAAI,CAAC,CAAC;QACnC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,EAAE;YACpD,MAAM,EAAE,2BAAe;YACvB,SAAS,EAAE,0BAAS,CAAC,GAAG;SACzB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,QAAQ;IACzB,QAAQ;CACT,CAAC;AACF,kBAAe,GAAG,CAAC"}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
2
|
+
export type PoolFields = {
|
3
|
+
coin_a: string;
|
4
|
+
coin_b: string;
|
5
|
+
deploy_time_ms: string;
|
6
|
+
fee: number;
|
7
|
+
fee_growth_global_a: string;
|
8
|
+
fee_growth_global_b: string;
|
9
|
+
fee_protocol: number;
|
10
|
+
id: {
|
11
|
+
id: string;
|
12
|
+
};
|
13
|
+
liquidity: string;
|
14
|
+
max_liquidity_per_tick: string;
|
15
|
+
protocol_fees_a: string;
|
16
|
+
protocol_fees_b: string;
|
17
|
+
reward_infos: {
|
18
|
+
type: string;
|
19
|
+
fields: {
|
20
|
+
emissions_per_second: string;
|
21
|
+
growth_global: string;
|
22
|
+
id: {
|
23
|
+
id: string;
|
24
|
+
};
|
25
|
+
manager: string;
|
26
|
+
vault: string;
|
27
|
+
vault_coin_type: string;
|
28
|
+
};
|
29
|
+
}[];
|
30
|
+
reward_last_updated_time_ms: string;
|
31
|
+
sqrt_price: string;
|
32
|
+
tick_current_index: Bits;
|
33
|
+
tick_map: {
|
34
|
+
type: string;
|
35
|
+
fields: {
|
36
|
+
id: {
|
37
|
+
id: string;
|
38
|
+
};
|
39
|
+
size: string;
|
40
|
+
};
|
41
|
+
};
|
42
|
+
tick_spacing: number;
|
43
|
+
unlocked: boolean;
|
44
|
+
};
|
45
|
+
export type Types = [string, string, string];
|
46
|
+
export type Bits = {
|
47
|
+
type: string;
|
48
|
+
fields: {
|
49
|
+
bits: number;
|
50
|
+
};
|
51
|
+
};
|
52
|
+
export type Pool = PoolFields & {
|
53
|
+
objectId: string;
|
54
|
+
type: string;
|
55
|
+
types: Types;
|
56
|
+
};
|
57
|
+
export type NFTFields = {
|
58
|
+
coin_type_a: CoinType;
|
59
|
+
coin_type_b: CoinType;
|
60
|
+
description: string;
|
61
|
+
fee_type: CoinType;
|
62
|
+
id: {
|
63
|
+
id: string;
|
64
|
+
};
|
65
|
+
img_url: string;
|
66
|
+
name: string;
|
67
|
+
pool_id: string;
|
68
|
+
position_id: string;
|
69
|
+
};
|
70
|
+
export type CoinType = {
|
71
|
+
type: string;
|
72
|
+
fields: {
|
73
|
+
name: string;
|
74
|
+
};
|
75
|
+
};
|
76
|
+
export type PositionFields = {
|
77
|
+
fee_growth_inside_a: string;
|
78
|
+
fee_growth_inside_b: string;
|
79
|
+
id: {
|
80
|
+
id: string;
|
81
|
+
};
|
82
|
+
liquidity: string;
|
83
|
+
reward_infos: {
|
84
|
+
type: string;
|
85
|
+
fields: {
|
86
|
+
amount_owed: string;
|
87
|
+
reward_growth_inside: string;
|
88
|
+
};
|
89
|
+
}[];
|
90
|
+
tick_lower_index: Bits;
|
91
|
+
tick_upper_index: Bits;
|
92
|
+
tokens_owed_a: string;
|
93
|
+
tokens_owed_b: string;
|
94
|
+
};
|
95
|
+
export type PositionTick = {
|
96
|
+
tickIndex: number;
|
97
|
+
initialized: boolean;
|
98
|
+
liquidityNet: BigNumber;
|
99
|
+
liquidityGross: BigNumber;
|
100
|
+
feeGrowthOutsideA: BigNumber;
|
101
|
+
feeGrowthOutsideB: BigNumber;
|
102
|
+
rewardGrowthsOutside: [BigNumber, BigNumber, BigNumber];
|
103
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/turbos/types.ts"],"names":[],"mappings":""}
|
@@ -9,6 +9,7 @@ const urlToRpcEndpoint_1 = __importDefault(require("./urlToRpcEndpoint"));
|
|
9
9
|
exports.viemChainsByNetworkId = {
|
10
10
|
ethereum: chains_1.mainnet,
|
11
11
|
avalanche: chains_1.avalanche,
|
12
|
+
polygon: chains_1.polygon,
|
12
13
|
};
|
13
14
|
function getUrlEndpoints() {
|
14
15
|
return {
|
@@ -19,6 +20,7 @@ function getUrlEndpoints() {
|
|
19
20
|
'https://eth-mainnet.g.alchemy.com/v2',
|
20
21
|
avalanche: process.env['PORTFOLIO_AVALANCHE_RPC'] ||
|
21
22
|
'https://api.avax.network/ext/bc/C/rpc',
|
23
|
+
polygon: process.env['PORTFOLIO_POLYGON_RPC'] || 'https://polygon.llamarpc.com',
|
22
24
|
aptos: process.env['PORTFOLIO_APTOS_RPC'] ||
|
23
25
|
'https://fullnode.mainnet.aptoslabs.com',
|
24
26
|
sui: process.env['PORTFOLIO_SUI_RPC'] ||
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/clients/constants.ts"],"names":[],"mappings":";;;;;;AAKA,
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/clients/constants.ts"],"names":[],"mappings":";;;;;;AAKA,wCAAiE;AACjE,0EAAkD;AAErC,QAAA,qBAAqB,GAAoC;IACpE,QAAQ,EAAE,gBAAO;IACjB,SAAS,EAAT,kBAAS;IACT,OAAO,EAAP,gBAAO;CACR,CAAC;AAEF,SAAgB,eAAe;IAC7B,OAAO;QACL,OAAO,EACL,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,+BAA+B;QACzE,MAAM,EACJ,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;YACnC,qCAAqC;QACvC,QAAQ,EACN,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;YACrC,sCAAsC;QACxC,SAAS,EACP,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC;YACtC,uCAAuC;QACzC,OAAO,EACL,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,8BAA8B;QACxE,KAAK,EACH,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;YAClC,wCAAwC;QAC1C,GAAG,EACD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;YAChC,iDAAiD;KACpD,CAAC;AACJ,CAAC;AAtBD,0CAsBC;AAED,SAAgB,cAAc,CAAC,SAAwB;IACrD,OAAO,eAAe,EAAE,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe;IAC7B,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC;IACvC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACjD,GAAG;QACH,IAAA,0BAAgB,EAAC,KAAK,CAAC;KACxB,CAAC,CACmC,CAAC;AAC1C,CAAC;AARD,0CAQC;AAED,SAAgB,cAAc,CAAC,SAAwB;IACrD,OAAO,eAAe,EAAE,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC;AAFD,wCAEC"}
|
@@ -9,6 +9,7 @@ function getEvmClients() {
|
|
9
9
|
return {
|
10
10
|
avalanche: (0, getEvmClient_1.default)(portfolio_core_1.NetworkId.avalanche),
|
11
11
|
ethereum: (0, getEvmClient_1.default)(portfolio_core_1.NetworkId.ethereum),
|
12
|
+
polygon: (0, getEvmClient_1.default)(portfolio_core_1.NetworkId.polygon),
|
12
13
|
};
|
13
14
|
}
|
14
15
|
exports.default = getEvmClients;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getEvmClients.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/clients/getEvmClients.ts"],"names":[],"mappings":";;;;;AACA,+DAAyE;AACzE,kEAA0C;AAE1C,SAAwB,aAAa;
|
1
|
+
{"version":3,"file":"getEvmClients.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/clients/getEvmClients.ts"],"names":[],"mappings":";;;;;AACA,+DAAyE;AACzE,kEAA0C;AAE1C,SAAwB,aAAa;IAInC,OAAO;QACL,SAAS,EAAE,IAAA,sBAAY,EAAC,0BAAS,CAAC,SAAS,CAAC;QAC5C,QAAQ,EAAE,IAAA,sBAAY,EAAC,0BAAS,CAAC,QAAQ,CAAC;QAC1C,OAAO,EAAE,IAAA,sBAAY,EAAC,0BAAS,CAAC,OAAO,CAAC;KACzC,CAAC;AACJ,CAAC;AATD,gCASC"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
2
|
+
import BN from 'bn.js';
|
3
|
+
export declare function signedShiftRight(n0: BN, shiftBy: number, bitWidth: number): BN;
|
4
|
+
export declare function tickIndexToSqrtPricePositive(tick: number): BigNumber;
|
5
|
+
export declare function tickIndexToSqrtPriceNegative(tickIndex: number): BigNumber;
|
6
|
+
export declare function tickIndexToSqrtPriceX64(tickIndex: number): BigNumber;
|
7
|
+
export declare function getTokenAmountsFromLiquidity(liquidity: number, tickCurrentIndex: number, tickLowerIndex: number, tickUpperIndex: number, roundUp: number): {
|
8
|
+
tokenAmountA: number;
|
9
|
+
tokenAmountB: number;
|
10
|
+
};
|
@@ -0,0 +1,199 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.getTokenAmountsFromLiquidity = exports.tickIndexToSqrtPriceX64 = exports.tickIndexToSqrtPriceNegative = exports.tickIndexToSqrtPricePositive = exports.signedShiftRight = void 0;
|
7
|
+
/* eslint-disable no-bitwise */
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
10
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
11
|
+
function signedShiftRight(n0, shiftBy, bitWidth) {
|
12
|
+
const twoN0 = n0.toTwos(bitWidth).shrn(shiftBy);
|
13
|
+
twoN0.imaskn(bitWidth - shiftBy + 1);
|
14
|
+
return twoN0.fromTwos(bitWidth - shiftBy);
|
15
|
+
}
|
16
|
+
exports.signedShiftRight = signedShiftRight;
|
17
|
+
function tickIndexToSqrtPricePositive(tick) {
|
18
|
+
let ratio;
|
19
|
+
if ((tick & 1) !== 0) {
|
20
|
+
ratio = new bn_js_1.default('79232123823359799118286999567');
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
ratio = new bn_js_1.default('79228162514264337593543950336');
|
24
|
+
}
|
25
|
+
if ((tick & 2) !== 0) {
|
26
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79236085330515764027303304731')), 96, 256);
|
27
|
+
}
|
28
|
+
if ((tick & 4) !== 0) {
|
29
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79244008939048815603706035061')), 96, 256);
|
30
|
+
}
|
31
|
+
if ((tick & 8) !== 0) {
|
32
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79259858533276714757314932305')), 96, 256);
|
33
|
+
}
|
34
|
+
if ((tick & 16) !== 0) {
|
35
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79291567232598584799939703904')), 96, 256);
|
36
|
+
}
|
37
|
+
if ((tick & 32) !== 0) {
|
38
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79355022692464371645785046466')), 96, 256);
|
39
|
+
}
|
40
|
+
if ((tick & 64) !== 0) {
|
41
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79482085999252804386437311141')), 96, 256);
|
42
|
+
}
|
43
|
+
if ((tick & 128) !== 0) {
|
44
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('79736823300114093921829183326')), 96, 256);
|
45
|
+
}
|
46
|
+
if ((tick & 256) !== 0) {
|
47
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('80248749790819932309965073892')), 96, 256);
|
48
|
+
}
|
49
|
+
if ((tick & 512) !== 0) {
|
50
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('81282483887344747381513967011')), 96, 256);
|
51
|
+
}
|
52
|
+
if ((tick & 1024) !== 0) {
|
53
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('83390072131320151908154831281')), 96, 256);
|
54
|
+
}
|
55
|
+
if ((tick & 2048) !== 0) {
|
56
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('87770609709833776024991924138')), 96, 256);
|
57
|
+
}
|
58
|
+
if ((tick & 4096) !== 0) {
|
59
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('97234110755111693312479820773')), 96, 256);
|
60
|
+
}
|
61
|
+
if ((tick & 8192) !== 0) {
|
62
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('119332217159966728226237229890')), 96, 256);
|
63
|
+
}
|
64
|
+
if ((tick & 16384) !== 0) {
|
65
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('179736315981702064433883588727')), 96, 256);
|
66
|
+
}
|
67
|
+
if ((tick & 32768) !== 0) {
|
68
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('407748233172238350107850275304')), 96, 256);
|
69
|
+
}
|
70
|
+
if ((tick & 65536) !== 0) {
|
71
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('2098478828474011932436660412517')), 96, 256);
|
72
|
+
}
|
73
|
+
if ((tick & 131072) !== 0) {
|
74
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('55581415166113811149459800483533')), 96, 256);
|
75
|
+
}
|
76
|
+
if ((tick & 262144) !== 0) {
|
77
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('38992368544603139932233054999993551')), 96, 256);
|
78
|
+
}
|
79
|
+
return new bignumber_js_1.default(signedShiftRight(ratio, 32, 256).toString());
|
80
|
+
}
|
81
|
+
exports.tickIndexToSqrtPricePositive = tickIndexToSqrtPricePositive;
|
82
|
+
function tickIndexToSqrtPriceNegative(tickIndex) {
|
83
|
+
const tick = Math.abs(tickIndex);
|
84
|
+
let ratio;
|
85
|
+
if ((tick & 1) !== 0) {
|
86
|
+
ratio = new bn_js_1.default('18445821805675392311');
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
ratio = new bn_js_1.default('18446744073709551616');
|
90
|
+
}
|
91
|
+
if ((tick & 2) !== 0) {
|
92
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18444899583751176498')), 64, 256);
|
93
|
+
}
|
94
|
+
if ((tick & 4) !== 0) {
|
95
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18443055278223354162')), 64, 256);
|
96
|
+
}
|
97
|
+
if ((tick & 8) !== 0) {
|
98
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18439367220385604838')), 64, 256);
|
99
|
+
}
|
100
|
+
if ((tick & 16) !== 0) {
|
101
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18431993317065449817')), 64, 256);
|
102
|
+
}
|
103
|
+
if ((tick & 32) !== 0) {
|
104
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18417254355718160513')), 64, 256);
|
105
|
+
}
|
106
|
+
if ((tick & 64) !== 0) {
|
107
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18387811781193591352')), 64, 256);
|
108
|
+
}
|
109
|
+
if ((tick & 128) !== 0) {
|
110
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18329067761203520168')), 64, 256);
|
111
|
+
}
|
112
|
+
if ((tick & 256) !== 0) {
|
113
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('18212142134806087854')), 64, 256);
|
114
|
+
}
|
115
|
+
if ((tick & 512) !== 0) {
|
116
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('17980523815641551639')), 64, 256);
|
117
|
+
}
|
118
|
+
if ((tick & 1024) !== 0) {
|
119
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('17526086738831147013')), 64, 256);
|
120
|
+
}
|
121
|
+
if ((tick & 2048) !== 0) {
|
122
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('16651378430235024244')), 64, 256);
|
123
|
+
}
|
124
|
+
if ((tick & 4096) !== 0) {
|
125
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('15030750278693429944')), 64, 256);
|
126
|
+
}
|
127
|
+
if ((tick & 8192) !== 0) {
|
128
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('12247334978882834399')), 64, 256);
|
129
|
+
}
|
130
|
+
if ((tick & 16384) !== 0) {
|
131
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('8131365268884726200')), 64, 256);
|
132
|
+
}
|
133
|
+
if ((tick & 32768) !== 0) {
|
134
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('3584323654723342297')), 64, 256);
|
135
|
+
}
|
136
|
+
if ((tick & 65536) !== 0) {
|
137
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('696457651847595233')), 64, 256);
|
138
|
+
}
|
139
|
+
if ((tick & 131072) !== 0) {
|
140
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('26294789957452057')), 64, 256);
|
141
|
+
}
|
142
|
+
if ((tick & 262144) !== 0) {
|
143
|
+
ratio = signedShiftRight(ratio.mul(new bn_js_1.default('37481735321082')), 64, 256);
|
144
|
+
}
|
145
|
+
return new bignumber_js_1.default(ratio.toString());
|
146
|
+
}
|
147
|
+
exports.tickIndexToSqrtPriceNegative = tickIndexToSqrtPriceNegative;
|
148
|
+
function tickIndexToSqrtPriceX64(tickIndex) {
|
149
|
+
if (tickIndex > 0) {
|
150
|
+
return new bignumber_js_1.default(tickIndexToSqrtPricePositive(tickIndex));
|
151
|
+
}
|
152
|
+
return new bignumber_js_1.default(tickIndexToSqrtPriceNegative(tickIndex));
|
153
|
+
}
|
154
|
+
exports.tickIndexToSqrtPriceX64 = tickIndexToSqrtPriceX64;
|
155
|
+
const fromX64Decimal = (num) => num.times(decimal_js_1.default.pow(2, -64));
|
156
|
+
const toX64Decimal = (num) => num.times(decimal_js_1.default.pow(2, 64));
|
157
|
+
function getTokenAmountsFromLiquidity(liquidity, tickCurrentIndex, tickLowerIndex, tickUpperIndex, roundUp) {
|
158
|
+
const currentSqrtPrice = tickIndexToSqrtPriceX64(tickCurrentIndex);
|
159
|
+
const lowerSqrtPrice = tickIndexToSqrtPriceX64(tickLowerIndex);
|
160
|
+
const upperSqrtPrice = tickIndexToSqrtPriceX64(tickUpperIndex);
|
161
|
+
const decLiquidity = new decimal_js_1.default(liquidity.toString());
|
162
|
+
const currentPrice = new decimal_js_1.default(currentSqrtPrice.toString());
|
163
|
+
const lowerPrice = new decimal_js_1.default(lowerSqrtPrice.toString());
|
164
|
+
const upperPrice = new decimal_js_1.default(upperSqrtPrice.toString());
|
165
|
+
let tokenA;
|
166
|
+
let tokenB;
|
167
|
+
if (currentSqrtPrice.lt(lowerSqrtPrice)) {
|
168
|
+
// x = L * (pb - pa) / (pa * pb)
|
169
|
+
tokenA = toX64Decimal(decLiquidity)
|
170
|
+
.times(upperPrice.sub(lowerPrice))
|
171
|
+
.div(lowerPrice.mul(upperPrice));
|
172
|
+
tokenB = new decimal_js_1.default(0);
|
173
|
+
}
|
174
|
+
else if (currentSqrtPrice.lt(upperSqrtPrice)) {
|
175
|
+
// x = L * (pb - p) / (p * pb)
|
176
|
+
// y = L * (p - pa)
|
177
|
+
tokenA = toX64Decimal(decLiquidity)
|
178
|
+
.times(upperPrice.sub(currentPrice))
|
179
|
+
.div(currentPrice.mul(upperPrice));
|
180
|
+
tokenB = fromX64Decimal(decLiquidity.mul(currentPrice.sub(lowerPrice)));
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
// y = L * (pb - pa)
|
184
|
+
tokenA = new decimal_js_1.default(0);
|
185
|
+
tokenB = fromX64Decimal(decLiquidity.mul(upperPrice.sub(lowerPrice)));
|
186
|
+
}
|
187
|
+
if (roundUp) {
|
188
|
+
return {
|
189
|
+
tokenAmountA: tokenA.ceil().toNumber(),
|
190
|
+
tokenAmountB: tokenB.ceil().toNumber(),
|
191
|
+
};
|
192
|
+
}
|
193
|
+
return {
|
194
|
+
tokenAmountA: tokenA.floor().toNumber(),
|
195
|
+
tokenAmountB: tokenB.floor().toNumber(),
|
196
|
+
};
|
197
|
+
}
|
198
|
+
exports.getTokenAmountsFromLiquidity = getTokenAmountsFromLiquidity;
|
199
|
+
//# sourceMappingURL=tokenAmountFromLiquidity.js.map
|