@sonarwatch/portfolio-plugins 0.14.142 → 0.14.144
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 +2177 -2169
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/plugins/balancer/helpers/pools.js +21 -21
- package/src/plugins/banx/constants.d.ts +14 -8
- package/src/plugins/banx/constants.js +25 -13
- package/src/plugins/banx/constants.js.map +1 -1
- package/src/plugins/banx/index.js +12 -2
- package/src/plugins/banx/index.js.map +1 -1
- package/src/plugins/banx/loansFetcher.js +108 -123
- package/src/plugins/banx/loansFetcher.js.map +1 -1
- package/src/plugins/banx/marketsJob.js +40 -0
- package/src/plugins/banx/marketsJob.js.map +1 -0
- package/src/plugins/banx/offersFetcher.js +61 -70
- package/src/plugins/banx/offersFetcher.js.map +1 -1
- package/src/plugins/banx/stakingFetcher.js +6 -3
- package/src/plugins/banx/stakingFetcher.js.map +1 -1
- package/src/plugins/banx/structs.d.ts +222 -2
- package/src/plugins/banx/structs.js +216 -2
- package/src/plugins/banx/structs.js.map +1 -1
- package/src/plugins/banx/types.d.ts +50 -258
- package/src/plugins/banx/vaultsFetcher.d.ts +3 -0
- package/src/plugins/banx/vaultsFetcher.js +74 -0
- package/src/plugins/banx/vaultsFetcher.js.map +1 -0
- package/src/plugins/banx/vaultsJob.d.ts +3 -0
- package/src/plugins/banx/{collectionsJob.js → vaultsJob.js} +5 -16
- package/src/plugins/banx/vaultsJob.js.map +1 -0
- package/src/plugins/jupiter/exchange/dcaFetcher.js +69 -20
- package/src/plugins/jupiter/exchange/dcaFetcher.js.map +1 -1
- package/src/plugins/jupiter/exchange/limitFetcher.js +73 -23
- package/src/plugins/jupiter/exchange/limitFetcher.js.map +1 -1
- package/src/plugins/sushiswap/helpers.js +24 -24
- package/src/plugins/switchboard/onDemandPricingJob.js +2 -2
- package/src/plugins/switchboard/onDemandPricingJob.js.map +1 -1
- package/src/plugins/uniswap-v2/helpers.js +22 -22
- package/src/utils/misc/getCachedDecimalsForToken.d.ts +0 -1
- package/src/utils/misc/getCachedDecimalsForToken.js +3 -51
- package/src/utils/misc/getCachedDecimalsForToken.js.map +1 -1
- package/src/utils/misc/getDecimalsForToken.d.ts +4 -0
- package/src/utils/misc/getDecimalsForToken.js +63 -0
- package/src/utils/misc/getDecimalsForToken.js.map +1 -0
- package/src/utils/sei/constants.js +8 -8
- package/src/utils/sei/getQueryBalanceByOwner.js +4 -4
- package/src/plugins/banx/collectionsJob.js.map +0 -1
- package/src/plugins/banx/filters.d.ts +0 -6
- package/src/plugins/banx/filters.js +0 -39
- package/src/plugins/banx/filters.js.map +0 -1
- package/src/plugins/banx/helpers.d.ts +0 -5
- package/src/plugins/banx/helpers.js +0 -64
- package/src/plugins/banx/helpers.js.map +0 -1
- package/src/plugins/banx/idl.d.ts +0 -123
- package/src/plugins/banx/idl.js +0 -2187
- package/src/plugins/banx/idl.js.map +0 -1
- /package/src/plugins/banx/{collectionsJob.d.ts → marketsJob.d.ts} +0 -0
@@ -15,30 +15,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
17
17
|
const constants_1 = require("./constants");
|
18
|
-
/**
|
19
|
-
* @deprecated
|
20
|
-
* this job has been deprecated following protocol changes
|
21
|
-
*/
|
22
18
|
const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
|
23
|
-
const
|
24
|
-
|
25
|
-
timeout: 5000,
|
26
|
-
})
|
27
|
-
.catch((err) => {
|
28
|
-
throw Error(`BANX_API ERR: ${err}`);
|
19
|
+
const resSpl = yield axios_1.default.get(constants_1.banxApiVaultsUrl, {
|
20
|
+
timeout: 3000,
|
29
21
|
});
|
30
|
-
|
31
|
-
throw Error(`BANX_API NO RESPONSE`);
|
32
|
-
}
|
33
|
-
yield cache.setItem(constants_1.collectionsCacheKey, res.data.data, {
|
22
|
+
yield cache.setItem(constants_1.vaultsCacheKey, resSpl.data.data, {
|
34
23
|
prefix: constants_1.cachePrefix,
|
35
24
|
networkId: portfolio_core_1.NetworkId.solana,
|
36
25
|
});
|
37
26
|
});
|
38
27
|
const job = {
|
39
|
-
id: `${constants_1.platformId}-
|
28
|
+
id: `${constants_1.platformId}-vaults`,
|
40
29
|
executor,
|
41
30
|
labels: ['normal'],
|
42
31
|
};
|
43
32
|
exports.default = job;
|
44
|
-
//# sourceMappingURL=
|
33
|
+
//# sourceMappingURL=vaultsJob.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"vaultsJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/banx/vaultsJob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAuD;AACvD,kDAA0B;AAG1B,2CAKqB;AAGrB,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,MAAM,eAAK,CAAC,GAAG,CAAoB,4BAAgB,EAAE;QAClE,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IAEH,MAAM,KAAK,CAAC,OAAO,CAAC,0BAAc,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE;QACpD,MAAM,EAAE,uBAAW;QACnB,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B,CAAC,CAAC;AACL,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,SAAS;IAC1B,QAAQ;IACR,MAAM,EAAE,CAAC,QAAQ,CAAC;CACnB,CAAC;AAEF,kBAAe,GAAG,CAAC"}
|
@@ -8,6 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
13
16
|
const clients_1 = require("../../../utils/clients");
|
@@ -15,36 +18,82 @@ const solana_1 = require("../../../utils/solana");
|
|
15
18
|
const constants_1 = require("./constants");
|
16
19
|
const structs_1 = require("./structs");
|
17
20
|
const filters_1 = require("./filters");
|
18
|
-
const
|
21
|
+
const getCachedDecimalsForToken_1 = require("../../../utils/misc/getCachedDecimalsForToken");
|
22
|
+
const tokenPriceToAssetToken_1 = __importDefault(require("../../../utils/misc/tokenPriceToAssetToken"));
|
19
23
|
const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
20
24
|
const client = (0, clients_1.getClientSolana)({ commitment: 'processed' });
|
21
25
|
const accounts = yield (0, solana_1.getParsedProgramAccounts)(client, structs_1.dcaStruct, constants_1.dcaProgramId, (0, filters_1.DCAFilters)(owner));
|
22
26
|
if (accounts.length === 0)
|
23
27
|
return [];
|
24
|
-
const
|
28
|
+
const mints = accounts
|
29
|
+
.map((account) => [
|
30
|
+
account.inputMint.toString(),
|
31
|
+
account.outputMint.toString(),
|
32
|
+
])
|
33
|
+
.flat();
|
34
|
+
const pricesMap = yield cache.getTokenPricesAsMap(Array.from(mints), portfolio_core_1.NetworkId.solana);
|
35
|
+
const elements = [];
|
25
36
|
for (let i = 0; i < accounts.length; i++) {
|
26
37
|
const account = accounts[i];
|
27
|
-
const
|
38
|
+
const inputMint = account.inputMint.toString();
|
39
|
+
const inputTokenPrice = pricesMap.get(inputMint);
|
40
|
+
const outputMint = account.outputMint.toString();
|
41
|
+
const outputTokenPrice = pricesMap.get(outputMint);
|
42
|
+
// Decimals
|
43
|
+
const inputDecimals = (inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.decimals) ||
|
44
|
+
(yield (0, getCachedDecimalsForToken_1.getCachedDecimalsForToken)(cache, inputMint, portfolio_core_1.NetworkId.solana));
|
45
|
+
if (!inputDecimals)
|
46
|
+
continue;
|
47
|
+
const outputDecimals = (outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.decimals) ||
|
48
|
+
(yield (0, getCachedDecimalsForToken_1.getCachedDecimalsForToken)(cache, outputMint, portfolio_core_1.NetworkId.solana));
|
49
|
+
if (!outputDecimals)
|
50
|
+
continue;
|
51
|
+
const inputAmount = account.inDeposited
|
52
|
+
.minus(account.inUsed)
|
53
|
+
.div(Math.pow(10, inputDecimals))
|
54
|
+
.toNumber();
|
55
|
+
let inputAsset = null;
|
56
|
+
if (inputAmount !== 0)
|
57
|
+
inputAsset = (0, tokenPriceToAssetToken_1.default)(inputMint, inputAmount, portfolio_core_1.NetworkId.solana, inputTokenPrice);
|
58
|
+
const outputAmount = account.outReceived
|
59
|
+
.minus(account.outWithdrawn)
|
60
|
+
.div(Math.pow(10, outputDecimals))
|
61
|
+
.toNumber();
|
62
|
+
let outputAsset = null;
|
63
|
+
if (outputAmount !== 0)
|
64
|
+
outputAsset = (0, tokenPriceToAssetToken_1.default)(outputMint, outputAmount, portfolio_core_1.NetworkId.solana, outputTokenPrice);
|
65
|
+
const initialInputAmount = account.inDeposited
|
66
|
+
.div(Math.pow(10, inputDecimals))
|
67
|
+
.toNumber();
|
68
|
+
const element = {
|
69
|
+
networkId: portfolio_core_1.NetworkId.solana,
|
70
|
+
type: portfolio_core_1.PortfolioElementType.trade,
|
71
|
+
platformId: constants_1.platformId,
|
28
72
|
label: 'DCA',
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
73
|
+
data: {
|
74
|
+
ref: account.pubkey.toString(),
|
75
|
+
assets: {
|
76
|
+
input: inputAsset,
|
77
|
+
output: outputAsset,
|
78
|
+
},
|
79
|
+
inputAddress: inputMint,
|
80
|
+
outputAddress: outputMint,
|
81
|
+
filledPercentage: 1 - inputAmount / initialInputAmount,
|
82
|
+
inputPrice: (inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price) || null,
|
83
|
+
outputPrice: (outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.price) || null,
|
84
|
+
link: 'https://jup.ag/recurring/',
|
85
|
+
contract: constants_1.dcaProgramId.toString(),
|
86
|
+
initialInputAmount,
|
87
|
+
withdrawnOutputAmount: account.outWithdrawn
|
88
|
+
.div(Math.pow(10, outputDecimals))
|
89
|
+
.toNumber(),
|
90
|
+
createdAt: account.createdAt.toNumber() * 1000,
|
41
91
|
},
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
});
|
92
|
+
value: (0, portfolio_core_1.getUsdValueSum)([(inputAsset === null || inputAsset === void 0 ? void 0 : inputAsset.value) || 0, (outputAsset === null || outputAsset === void 0 ? void 0 : outputAsset.value) || 0]),
|
93
|
+
};
|
94
|
+
elements.push(element);
|
46
95
|
}
|
47
|
-
return
|
96
|
+
return elements;
|
48
97
|
});
|
49
98
|
const fetcher = {
|
50
99
|
id: `${constants_1.platformId}-dca`,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dcaFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/dcaFetcher.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"dcaFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/dcaFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAMoC;AAGpC,oDAAyD;AACzD,kDAAiE;AACjE,2CAAuD;AACvD,uCAAsC;AACtC,uCAAuC;AACvC,6FAA0F;AAC1F,wGAAgF;AAEhF,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;IACtE,MAAM,MAAM,GAAG,IAAA,yBAAe,EAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;IA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,EAAE;gBAC9B,MAAM,EAAE;oBACN,KAAK,EAAE,UAAU;oBACjB,MAAM,EAAE,WAAW;iBACpB;gBACD,YAAY,EAAE,SAAS;gBACvB,aAAa,EAAE,UAAU;gBACzB,gBAAgB,EAAE,CAAC,GAAG,WAAW,GAAG,kBAAkB;gBACtD,UAAU,EAAE,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,KAAK,KAAI,IAAI;gBAC1C,WAAW,EAAE,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,KAAK,KAAI,IAAI;gBAC5C,IAAI,EAAE,2BAA2B;gBACjC,QAAQ,EAAE,wBAAY,CAAC,QAAQ,EAAE;gBACjC,kBAAkB;gBAClB,qBAAqB,EAAE,OAAO,CAAC,YAAY;qBACxC,GAAG,CAAC,SAAA,EAAE,EAAI,cAAc,CAAA,CAAC;qBACzB,QAAQ,EAAE;gBACb,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,GAAG,IAAI;aAC/C;YACD,KAAK,EAAE,IAAA,+BAAc,EAAC,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,KAAI,CAAC,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,KAAI,CAAC,CAAC,CAAC;SACzE,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,MAAM;IACvB,SAAS,EAAE,0BAAS,CAAC,MAAM;IAC3B,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
@@ -8,14 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
9
|
});
|
10
10
|
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
13
16
|
const clients_1 = require("../../../utils/clients");
|
14
17
|
const solana_1 = require("../../../utils/solana");
|
15
18
|
const constants_1 = require("./constants");
|
16
19
|
const filters_1 = require("./filters");
|
17
|
-
const ElementRegistry_1 = require("../../../utils/elementbuilder/ElementRegistry");
|
18
20
|
const structs_1 = require("./structs");
|
21
|
+
const getCachedDecimalsForToken_1 = require("../../../utils/misc/getCachedDecimalsForToken");
|
22
|
+
const tokenPriceToAssetToken_1 = __importDefault(require("../../../utils/misc/tokenPriceToAssetToken"));
|
19
23
|
const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
20
24
|
const client = (0, clients_1.getClientSolana)({ commitment: 'processed' });
|
21
25
|
const accountsRes = yield Promise.all([
|
@@ -28,34 +32,80 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
28
32
|
const accounts = accountsRes.flat();
|
29
33
|
if (accounts.length === 0)
|
30
34
|
return [];
|
31
|
-
const
|
35
|
+
const mints = accounts
|
36
|
+
.map((account) => [
|
37
|
+
account.inputMint.toString(),
|
38
|
+
account.outputMint.toString(),
|
39
|
+
])
|
40
|
+
.flat();
|
41
|
+
const pricesMap = yield cache.getTokenPricesAsMap(Array.from(mints), portfolio_core_1.NetworkId.solana);
|
42
|
+
const elements = [];
|
32
43
|
for (let i = 0; i < accounts.length; i++) {
|
33
44
|
const account = accounts[i];
|
45
|
+
const inputMint = account.inputMint.toString();
|
46
|
+
const inputTokenPrice = pricesMap.get(inputMint);
|
47
|
+
const outputMint = account.outputMint.toString();
|
48
|
+
const outputTokenPrice = pricesMap.get(outputMint);
|
49
|
+
// Decimals
|
50
|
+
const inputDecimals = (inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.decimals) ||
|
51
|
+
(yield (0, getCachedDecimalsForToken_1.getCachedDecimalsForToken)(cache, inputMint, portfolio_core_1.NetworkId.solana));
|
52
|
+
if (!inputDecimals)
|
53
|
+
continue;
|
54
|
+
const outputDecimals = (outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.decimals) ||
|
55
|
+
(yield (0, getCachedDecimalsForToken_1.getCachedDecimalsForToken)(cache, outputMint, portfolio_core_1.NetworkId.solana));
|
56
|
+
if (!outputDecimals)
|
57
|
+
continue;
|
58
|
+
const intputAmount = account.makingAmount
|
59
|
+
.div(Math.pow(10, inputDecimals))
|
60
|
+
.toNumber();
|
61
|
+
const inputAsset = intputAmount === 0
|
62
|
+
? null
|
63
|
+
: (0, tokenPriceToAssetToken_1.default)(inputMint, intputAmount, portfolio_core_1.NetworkId.solana, inputTokenPrice);
|
64
|
+
const outputAmount = account.oriTakingAmount
|
65
|
+
.minus(account.takingAmount)
|
66
|
+
.div(Math.pow(10, outputDecimals))
|
67
|
+
.toNumber();
|
68
|
+
const outputAsset = outputAmount === 0
|
69
|
+
? null
|
70
|
+
: (0, tokenPriceToAssetToken_1.default)(outputMint, outputAmount, portfolio_core_1.NetworkId.solana, outputTokenPrice);
|
71
|
+
const initialInputAmount = account.oriMakingAmount
|
72
|
+
.div(Math.pow(10, inputDecimals))
|
73
|
+
.toNumber();
|
74
|
+
const expectedOutputAmount = account.oriTakingAmount
|
75
|
+
.div(Math.pow(10, outputDecimals))
|
76
|
+
.toNumber();
|
34
77
|
const isV1 = i <= v1Length - 1;
|
35
|
-
const
|
36
|
-
|
37
|
-
|
38
|
-
link: 'https://jup.ag/trigger/',
|
78
|
+
const tags = isV1 ? ['deprecated'] : undefined;
|
79
|
+
const element = {
|
80
|
+
networkId: portfolio_core_1.NetworkId.solana,
|
39
81
|
label: 'LimitOrder',
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
82
|
+
platformId: constants_1.platformId,
|
83
|
+
type: portfolio_core_1.PortfolioElementType.trade,
|
84
|
+
tags,
|
85
|
+
data: {
|
86
|
+
assets: {
|
87
|
+
input: inputAsset,
|
88
|
+
output: outputAsset,
|
89
|
+
},
|
90
|
+
inputAddress: inputMint,
|
91
|
+
outputAddress: outputMint,
|
92
|
+
initialInputAmount,
|
93
|
+
expectedOutputAmount,
|
94
|
+
filledPercentage: 1 - intputAmount / initialInputAmount,
|
95
|
+
inputPrice: (inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price) || null,
|
96
|
+
outputPrice: (outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.price) || null,
|
97
|
+
ref: account.pubkey.toString(),
|
98
|
+
link: 'https://jup.ag/trigger/',
|
99
|
+
contract: isV1
|
100
|
+
? constants_1.limitV1ProgramId.toString()
|
101
|
+
: constants_1.limitV2ProgramId.toString(),
|
102
|
+
withdrawnOutputAmount: 0,
|
52
103
|
},
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
});
|
104
|
+
value: (0, portfolio_core_1.getUsdValueSum)([(inputAsset === null || inputAsset === void 0 ? void 0 : inputAsset.value) || 0, (outputAsset === null || outputAsset === void 0 ? void 0 : outputAsset.value) || 0]),
|
105
|
+
};
|
106
|
+
elements.push(element);
|
57
107
|
}
|
58
|
-
return
|
108
|
+
return elements;
|
59
109
|
});
|
60
110
|
const fetcher = {
|
61
111
|
id: `${constants_1.platformId}-limit`,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"limitFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/limitFetcher.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"limitFetcher.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/src/plugins/jupiter/exchange/limitFetcher.ts"],"names":[],"mappings":";;;;;;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gBAC/B,QAAQ,EAAE,IAAI;oBACZ,CAAC,CAAC,4BAAgB,CAAC,QAAQ,EAAE;oBAC7B,CAAC,CAAC,4BAAgB,CAAC,QAAQ,EAAE;gBAC/B,qBAAqB,EAAE,CAAC;aACzB;YACD,KAAK,EAAE,IAAA,+BAAc,EAAC,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,KAAI,CAAC,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,KAAI,CAAC,CAAC,CAAC;SACzE,CAAC;QACF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,QAAQ;IACzB,SAAS,EAAE,0BAAS,CAAC,MAAM;IAC3B,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
@@ -54,30 +54,30 @@ function sushiV3PairToUniV2(pair) {
|
|
54
54
|
}
|
55
55
|
function getV3PairsAddresses(url, length = 300) {
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
57
|
-
const query = (0, graphql_request_1.gql) `
|
58
|
-
{
|
59
|
-
pools(
|
60
|
-
orderBy: totalValueLockedUSD
|
61
|
-
first: ${length}
|
62
|
-
orderDirection: desc
|
63
|
-
where: { volumeUSD_not: "0", liquidity_not: "0" }
|
64
|
-
) {
|
65
|
-
id
|
66
|
-
token0Price
|
67
|
-
token1Price
|
68
|
-
liquidity
|
69
|
-
token0 {
|
70
|
-
id
|
71
|
-
totalSupply
|
72
|
-
decimals
|
73
|
-
}
|
74
|
-
token1 {
|
75
|
-
id
|
76
|
-
totalSupply
|
77
|
-
decimals
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
57
|
+
const query = (0, graphql_request_1.gql) `
|
58
|
+
{
|
59
|
+
pools(
|
60
|
+
orderBy: totalValueLockedUSD
|
61
|
+
first: ${length}
|
62
|
+
orderDirection: desc
|
63
|
+
where: { volumeUSD_not: "0", liquidity_not: "0" }
|
64
|
+
) {
|
65
|
+
id
|
66
|
+
token0Price
|
67
|
+
token1Price
|
68
|
+
liquidity
|
69
|
+
token0 {
|
70
|
+
id
|
71
|
+
totalSupply
|
72
|
+
decimals
|
73
|
+
}
|
74
|
+
token1 {
|
75
|
+
id
|
76
|
+
totalSupply
|
77
|
+
decimals
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
81
|
`;
|
82
82
|
const res = yield (0, graphql_request_1.default)(url, query);
|
83
83
|
const pools = res.pools;
|
@@ -15,7 +15,7 @@ const constants_1 = require("./constants");
|
|
15
15
|
const clients_1 = require("../../utils/clients");
|
16
16
|
const constants_2 = require("../tokens/constants");
|
17
17
|
const getSwitchboardOnDemandPrice_1 = require("./helpers/getSwitchboardOnDemandPrice");
|
18
|
-
const
|
18
|
+
const getDecimalsForToken_1 = require("../../utils/misc/getDecimalsForToken");
|
19
19
|
const solana_1 = require("../../utils/solana");
|
20
20
|
const feedsToFetch = [
|
21
21
|
{
|
@@ -43,7 +43,7 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
const sources = [];
|
44
44
|
for (const tokenInfo of feedsToFetch) {
|
45
45
|
const values = yield (0, getSwitchboardOnDemandPrice_1.getSwitchboardOnDemandPrices)(connection, tokenInfo.feedsAddresses.map((t) => new web3_js_1.PublicKey(t)));
|
46
|
-
const decimals = yield (0,
|
46
|
+
const decimals = yield (0, getDecimalsForToken_1.getDecimalsForToken)(tokenInfo.mintAddress, portfolio_core_1.NetworkId.solana);
|
47
47
|
tokenInfo.feedsAddresses.forEach((feedToFetch, i) => {
|
48
48
|
const price = values.at(i);
|
49
49
|
if (!price || !decimals)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"onDemandPricingJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/switchboard/onDemandPricingJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAIoC;AACpC,6CAA4C;AAG5C,2CAAyC;AACzC,iDAAsD;AACtD,mDAA2D;AAC3D,uFAAqF;AACrF,
|
1
|
+
{"version":3,"file":"onDemandPricingJob.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/switchboard/onDemandPricingJob.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,+DAIoC;AACpC,6CAA4C;AAG5C,2CAAyC;AACzC,iDAAsD;AACtD,mDAA2D;AAC3D,uFAAqF;AACrF,8EAA2E;AAE3E,+CAAmE;AAEnE,MAAM,YAAY,GAAkC;IAClD;QACE,cAAc,EAAE;YACd,8CAA8C;YAC9C,8CAA8C;YAC9C,8CAA8C;SAC/C;QACD,SAAS,EAAE,0BAAS,CAAC,MAAM;QAC3B,WAAW,EAAE,2CAA0B;KACxC;IACD;QACE,cAAc,EAAE,CAAC,8CAA8C,CAAC;QAChE,WAAW,EAAE,uBAAc;QAC3B,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B;IACD;QACE,cAAc,EAAE,CAAC,8CAA8C,CAAC;QAChE,WAAW,EAAE,sBAAa;QAC1B,SAAS,EAAE,0BAAS,CAAC,MAAM;KAC5B;CACF,CAAC;AAEF,MAAM,QAAQ,GAAgB,CAAO,KAAY,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAA,yBAAe,GAAE,CAAC;IACrC,MAAM,OAAO,GAAuB,EAAE,CAAC;IAEvC,KAAK,MAAM,SAAS,IAAI,YAAY,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,IAAA,0DAA4B,EAC/C,UAAU,EACV,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,mBAAS,CAAC,CAAC,CAAC,CAAC,CACtD,CAAC;QAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,yCAAmB,EACxC,SAAS,CAAC,WAAW,EACrB,0BAAS,CAAC,MAAM,CACjB,CAAC;QAEF,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE;YAClD,MAAM,KAAK,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,KAAK,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAEhC,MAAM,MAAM,GAAqB;gBAC/B,OAAO,EAAE,SAAS,CAAC,WAAW;gBAC9B,QAAQ;gBACR,EAAE,EAAE,GAAG,sBAAU,SAAS,WAAW,CAAC,QAAQ,EAAE,EAAE;gBAClD,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,UAAU,EAAE,gCAAoB,CAAC,EAAE;gBACnC,MAAM,EAAE,GAAG;gBACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,KAAK;aACN,CAAC;YACF,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAA,CAAC;AACF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,mBAAmB;IACpC,QAAQ;IACR,MAAM,EAAE,CAAC,UAAU,CAAC;CACrB,CAAC;AACF,kBAAe,GAAG,CAAC"}
|
@@ -40,28 +40,28 @@ function getPairKey(version) {
|
|
40
40
|
exports.getPairKey = getPairKey;
|
41
41
|
function getPairsV2FromTheGraph(url, length = 300) {
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
43
|
-
const query = (0, graphql_request_1.gql) `
|
44
|
-
{
|
45
|
-
pairs(
|
46
|
-
orderBy: reserveUSD
|
47
|
-
first: ${length}
|
48
|
-
orderDirection: desc
|
49
|
-
where: { trackedReserveETH_not: "0" }
|
50
|
-
) {
|
51
|
-
id
|
52
|
-
reserve0
|
53
|
-
reserve1
|
54
|
-
totalSupply
|
55
|
-
token0 {
|
56
|
-
id
|
57
|
-
decimals
|
58
|
-
}
|
59
|
-
token1 {
|
60
|
-
id
|
61
|
-
decimals
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
43
|
+
const query = (0, graphql_request_1.gql) `
|
44
|
+
{
|
45
|
+
pairs(
|
46
|
+
orderBy: reserveUSD
|
47
|
+
first: ${length}
|
48
|
+
orderDirection: desc
|
49
|
+
where: { trackedReserveETH_not: "0" }
|
50
|
+
) {
|
51
|
+
id
|
52
|
+
reserve0
|
53
|
+
reserve1
|
54
|
+
totalSupply
|
55
|
+
token0 {
|
56
|
+
id
|
57
|
+
decimals
|
58
|
+
}
|
59
|
+
token1 {
|
60
|
+
id
|
61
|
+
decimals
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
65
|
`;
|
66
66
|
const res = yield (0, graphql_request_1.default)(url, query);
|
67
67
|
const pairs = res.pairs;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { NetworkIdType } from '@sonarwatch/portfolio-core';
|
2
2
|
import { Cache } from '../../Cache';
|
3
3
|
type Decimal = number | null;
|
4
|
-
export declare function getDecimalsForToken(address: string, networkId: NetworkIdType): Promise<Decimal>;
|
5
4
|
/**
|
6
5
|
* Return the decimals of a token on any network using RPC calls or TokenList.
|
7
6
|
*
|
@@ -9,60 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.getCachedDecimalsForToken =
|
12
|
+
exports.getCachedDecimalsForToken = void 0;
|
13
13
|
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
14
|
-
const web3_js_1 = require("@solana/web3.js");
|
15
|
-
const core_1 = require("@sei-js/core");
|
16
|
-
const clients_1 = require("../clients");
|
17
|
-
const constants_1 = require("../clients/constants");
|
18
|
-
const sei_1 = require("../sei");
|
19
|
-
const getDecimals_1 = require("../aptos/getDecimals");
|
20
|
-
const getDecimals_2 = require("../solana/getDecimals");
|
21
|
-
const getDecimals_3 = require("../sui/getDecimals");
|
22
14
|
const MemoizedCache_1 = require("./MemoizedCache");
|
15
|
+
const getDecimalsForToken_1 = require("./getDecimalsForToken");
|
23
16
|
const ttl = 60 * 60 * 24;
|
24
17
|
const decimalsMemo = new Map();
|
25
|
-
function getDecimalsForToken(address, networkId) {
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
27
|
-
switch (networkId) {
|
28
|
-
case 'aptos': {
|
29
|
-
const client = (0, clients_1.getClientAptos)();
|
30
|
-
return (0, getDecimals_1.getDecimals)(client, address);
|
31
|
-
}
|
32
|
-
case 'solana': {
|
33
|
-
const client = (0, clients_1.getClientSolana)();
|
34
|
-
return (0, getDecimals_2.getDecimals)(client, new web3_js_1.PublicKey(address));
|
35
|
-
}
|
36
|
-
case 'sei': {
|
37
|
-
if (address.startsWith('factory')) {
|
38
|
-
const client = yield (0, clients_1.getClientSei)();
|
39
|
-
const rep = yield client.cosmos.bank.v1beta1.denomMetadata({
|
40
|
-
denom: address,
|
41
|
-
});
|
42
|
-
const denoms = rep.metadata.denomUnits;
|
43
|
-
return denoms[denoms.length - 1].exponent;
|
44
|
-
}
|
45
|
-
if (address.startsWith('ibc')) {
|
46
|
-
// No solution yet for IBC tokens
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
if (address.startsWith('sei')) {
|
50
|
-
const client = yield (0, core_1.getCosmWasmClient)((0, constants_1.getUrlEndpoint)(portfolio_core_1.NetworkId.sei));
|
51
|
-
const tokenInfo = (yield client.queryContractSmart(address, sei_1.tokenInfoQueryMsg));
|
52
|
-
return tokenInfo.decimals || null;
|
53
|
-
}
|
54
|
-
return null;
|
55
|
-
}
|
56
|
-
case 'sui': {
|
57
|
-
const client = (0, clients_1.getClientSui)();
|
58
|
-
return (0, getDecimals_3.getDecimals)(client, address);
|
59
|
-
}
|
60
|
-
default:
|
61
|
-
throw new Error('getDecimalsForToken : Network not supported');
|
62
|
-
}
|
63
|
-
});
|
64
|
-
}
|
65
|
-
exports.getDecimalsForToken = getDecimalsForToken;
|
66
18
|
/**
|
67
19
|
* Return the decimals of a token on any network using RPC calls or TokenList.
|
68
20
|
*
|
@@ -80,7 +32,7 @@ function getCachedDecimalsForToken(cache, address, networkId) {
|
|
80
32
|
decimalMemo = new MemoizedCache_1.MemoizedCache((0, portfolio_core_1.formatTokenAddress)(address, networkId), {
|
81
33
|
prefix: 'decimalsfortoken',
|
82
34
|
networkId,
|
83
|
-
}, undefined, ttl, () => __awaiter(this, void 0, void 0, function* () { return getDecimalsForToken(address, networkId); }));
|
35
|
+
}, undefined, ttl, () => __awaiter(this, void 0, void 0, function* () { return (0, getDecimalsForToken_1.getDecimalsForToken)(address, networkId); }));
|
84
36
|
decimalsMemo.set(key, decimalMemo);
|
85
37
|
}
|
86
38
|
return decimalMemo.getItem(cache);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getCachedDecimalsForToken.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/misc/getCachedDecimalsForToken.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+
|
1
|
+
{"version":3,"file":"getCachedDecimalsForToken.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/misc/getCachedDecimalsForToken.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA+E;AAE/E,mDAAgD;AAChD,+DAA4D;AAG5D,MAAM,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAEzB,MAAM,YAAY,GAAwC,IAAI,GAAG,EAAE,CAAC;AAEpE;;;;;;;;GAQG;AACH,SAAsB,yBAAyB,CAC7C,KAAY,EACZ,OAAe,EACf,SAAwB;;QAExB,MAAM,GAAG,GAAG,GAAG,SAAS,IAAI,IAAA,mCAAkB,EAAC,OAAO,EAAE,SAAS,CAAC,EAAE,CAAC;QAErE,IAAI,WAAW,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAExC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,WAAW,GAAG,IAAI,6BAAa,CAC7B,IAAA,mCAAkB,EAAC,OAAO,EAAE,SAAS,CAAC,EACtC;gBACE,MAAM,EAAE,kBAAkB;gBAC1B,SAAS;aACV,EACD,SAAS,EACT,GAAG,EACH,GAAS,EAAE,gDAAC,OAAA,IAAA,yCAAmB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAA,GAAA,CACpD,CAAC;YACF,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;CAAA;AAxBD,8DAwBC"}
|
@@ -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
|
+
exports.getDecimalsForToken = void 0;
|
13
|
+
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
15
|
+
const core_1 = require("@sei-js/core");
|
16
|
+
const clients_1 = require("../clients");
|
17
|
+
const constants_1 = require("../clients/constants");
|
18
|
+
const sei_1 = require("../sei");
|
19
|
+
const getDecimals_1 = require("../aptos/getDecimals");
|
20
|
+
const getDecimals_2 = require("../solana/getDecimals");
|
21
|
+
const getDecimals_3 = require("../sui/getDecimals");
|
22
|
+
function getDecimalsForToken(address, networkId) {
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
24
|
+
switch (networkId) {
|
25
|
+
case 'aptos': {
|
26
|
+
const client = (0, clients_1.getClientAptos)();
|
27
|
+
return (0, getDecimals_1.getDecimals)(client, address);
|
28
|
+
}
|
29
|
+
case 'solana': {
|
30
|
+
const client = (0, clients_1.getClientSolana)();
|
31
|
+
return (0, getDecimals_2.getDecimals)(client, new web3_js_1.PublicKey(address));
|
32
|
+
}
|
33
|
+
case 'sei': {
|
34
|
+
if (address.startsWith('factory')) {
|
35
|
+
const client = yield (0, clients_1.getClientSei)();
|
36
|
+
const rep = yield client.cosmos.bank.v1beta1.denomMetadata({
|
37
|
+
denom: address,
|
38
|
+
});
|
39
|
+
const denoms = rep.metadata.denomUnits;
|
40
|
+
return denoms[denoms.length - 1].exponent;
|
41
|
+
}
|
42
|
+
if (address.startsWith('ibc')) {
|
43
|
+
// No solution yet for IBC tokens
|
44
|
+
return null;
|
45
|
+
}
|
46
|
+
if (address.startsWith('sei')) {
|
47
|
+
const client = yield (0, core_1.getCosmWasmClient)((0, constants_1.getUrlEndpoint)(portfolio_core_1.NetworkId.sei));
|
48
|
+
const tokenInfo = (yield client.queryContractSmart(address, sei_1.tokenInfoQueryMsg));
|
49
|
+
return tokenInfo.decimals || null;
|
50
|
+
}
|
51
|
+
return null;
|
52
|
+
}
|
53
|
+
case 'sui': {
|
54
|
+
const client = (0, clients_1.getClientSui)();
|
55
|
+
return (0, getDecimals_3.getDecimals)(client, address);
|
56
|
+
}
|
57
|
+
default:
|
58
|
+
throw new Error('getDecimalsForToken : Network not supported');
|
59
|
+
}
|
60
|
+
});
|
61
|
+
}
|
62
|
+
exports.getDecimalsForToken = getDecimalsForToken;
|
63
|
+
//# sourceMappingURL=getDecimalsForToken.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getDecimalsForToken.js","sourceRoot":"","sources":["../../../../../../pack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