aftermath-ts-sdk 1.1.97 → 1.2.0-refactor.1
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/dist/general/historicalData/historicalData.d.ts +1 -1
- package/dist/general/historicalData/historicalData.d.ts.map +1 -1
- package/dist/general/nfts/nftsApi.d.ts +1 -5
- package/dist/general/nfts/nftsApi.d.ts.map +1 -1
- package/dist/general/nfts/nftsApi.js +15 -29
- package/dist/general/nfts/nftsApiCasting.d.ts +0 -1
- package/dist/general/nfts/nftsApiCasting.d.ts.map +1 -1
- package/dist/general/nfts/nftsApiCasting.js +0 -10
- package/dist/general/nfts/nftsTypes.d.ts +0 -1
- package/dist/general/nfts/nftsTypes.d.ts.map +1 -1
- package/dist/general/prices/{coingecko/coinGeckoTypes.d.ts → coinGeckoTypes.d.ts} +1 -1
- package/dist/general/prices/coinGeckoTypes.d.ts.map +1 -0
- package/dist/general/providers/aftermath.d.ts.map +1 -1
- package/dist/general/providers/aftermath.js +1 -2
- package/dist/general/providers/aftermathApi.d.ts +1 -34
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +2 -90
- package/dist/general/types/castingTypes.d.ts +0 -7
- package/dist/general/types/castingTypes.d.ts.map +1 -1
- package/dist/general/types/configTypes.d.ts +0 -6
- package/dist/general/types/configTypes.d.ts.map +1 -1
- package/dist/general/types/generalTypes.d.ts +0 -3
- package/dist/general/types/generalTypes.d.ts.map +1 -1
- package/dist/general/types/index.d.ts +1 -0
- package/dist/general/types/index.d.ts.map +1 -1
- package/dist/general/types/index.js +1 -0
- package/dist/general/utils/helpers.d.ts +1 -16
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +2 -32
- package/dist/general/utils/index.d.ts +0 -1
- package/dist/general/utils/index.d.ts.map +1 -1
- package/dist/general/utils/index.js +0 -1
- package/dist/packages/coin/api/coinApi.d.ts +1 -12
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +0 -123
- package/dist/packages/dca/api/dcaApi.d.ts +1 -28
- package/dist/packages/dca/api/dcaApi.d.ts.map +1 -1
- package/dist/packages/dca/api/dcaApi.js +0 -172
- package/dist/packages/farms/api/farmsApi.d.ts +1 -24
- package/dist/packages/farms/api/farmsApi.d.ts.map +1 -1
- package/dist/packages/farms/api/farmsApi.js +0 -69
- package/dist/packages/farms/api/farmsApiCasting.d.ts +2 -3
- package/dist/packages/farms/api/farmsApiCasting.d.ts.map +1 -1
- package/dist/packages/farms/api/farmsApiCasting.js +0 -45
- package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +0 -9
- package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.d.ts +0 -5
- package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
- package/dist/packages/faucet/api/faucetApi.js +2 -29
- package/dist/packages/faucet/faucet.d.ts +3 -2
- package/dist/packages/faucet/faucet.d.ts.map +1 -1
- package/dist/packages/faucet/faucet.js +2 -2
- package/dist/packages/leveragedStaking/api/leveragedStakingApi.d.ts.map +1 -1
- package/dist/packages/leveragedStaking/api/leveragedStakingApi.js +383 -298
- package/dist/packages/nftAmm/nftAmmMarket.d.ts +9 -5
- package/dist/packages/nftAmm/nftAmmMarket.d.ts.map +1 -1
- package/dist/packages/nftAmm/nftAmmMarket.js +34 -6
- package/dist/packages/oracle/api/oracleApi.d.ts +1 -10
- package/dist/packages/oracle/api/oracleApi.d.ts.map +1 -1
- package/dist/packages/oracle/api/oracleApi.js +0 -38
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts +2 -58
- package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
- package/dist/packages/perpetuals/api/perpetualsApi.js +0 -735
- package/dist/packages/pools/api/poolsApi.d.ts +2 -217
- package/dist/packages/pools/api/poolsApi.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApi.js +0 -752
- package/dist/packages/pools/api/poolsApiCasting.d.ts +3 -15
- package/dist/packages/pools/api/poolsApiCasting.d.ts.map +1 -1
- package/dist/packages/pools/api/poolsApiCasting.js +0 -86
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts +1 -15
- package/dist/packages/pools/api/poolsApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/pools/pools.d.ts +4 -1
- package/dist/packages/pools/pools.d.ts.map +1 -1
- package/dist/packages/pools/pools.js +5 -0
- package/dist/packages/router/api/routerApi.d.ts +2 -116
- package/dist/packages/router/api/routerApi.d.ts.map +1 -1
- package/dist/packages/router/api/routerApi.js +3 -345
- package/dist/packages/router/api/routerApiCasting.d.ts +2 -5
- package/dist/packages/router/api/routerApiCasting.d.ts.map +1 -1
- package/dist/packages/router/api/routerApiCasting.js +0 -104
- package/dist/packages/router/api/routerApiCastingTypes.d.ts +1 -13
- package/dist/packages/router/api/routerApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/router/routerTypes.d.ts +3 -35
- package/dist/packages/router/routerTypes.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.d.ts +2 -50
- package/dist/packages/staking/api/stakingApi.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApi.js +0 -226
- package/dist/packages/staking/api/stakingApiCasting.d.ts +2 -4
- package/dist/packages/staking/api/stakingApiCasting.d.ts.map +1 -1
- package/dist/packages/staking/api/stakingApiCasting.js +0 -21
- package/dist/packages/staking/api/stakingApiCastingTypes.d.ts +1 -8
- package/dist/packages/staking/api/stakingApiCastingTypes.d.ts.map +1 -1
- package/dist/packages/staking/stakingTypes.d.ts +2 -0
- package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
- package/dist/packages/sui/api/suiApi.d.ts +1 -2
- package/dist/packages/sui/api/suiApi.d.ts.map +1 -1
- package/dist/packages/sui/api/suiApi.js +0 -3
- package/package.json +1 -1
- package/dist/general/dynamicGas/dynamicGasApi.d.ts +0 -15
- package/dist/general/dynamicGas/dynamicGasApi.d.ts.map +0 -1
- package/dist/general/dynamicGas/dynamicGasApi.js +0 -87
- package/dist/general/historicalData/historicalDataApi.d.ts +0 -9
- package/dist/general/historicalData/historicalDataApi.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataApi.js +0 -13
- package/dist/general/historicalData/historicalDataApiInterface.d.ts +0 -12
- package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +0 -1
- package/dist/general/historicalData/historicalDataApiInterface.js +0 -2
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts +0 -13
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts.map +0 -1
- package/dist/general/historicalData/placeholderHistoricalDataApi.js +0 -26
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +0 -22
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +0 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +0 -179
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts +0 -23
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts.map +0 -1
- package/dist/general/prices/coingecko/coinGeckoPricesApi.js +0 -113
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts.map +0 -1
- package/dist/general/prices/placeholder/placeholderPricesApi.d.ts +0 -20
- package/dist/general/prices/placeholder/placeholderPricesApi.d.ts.map +0 -1
- package/dist/general/prices/placeholder/placeholderPricesApi.js +0 -85
- package/dist/general/prices/pricesApiInterface.d.ts +0 -13
- package/dist/general/prices/pricesApiInterface.d.ts.map +0 -1
- package/dist/general/prices/pricesApiInterface.js +0 -2
- package/dist/general/prices/pyth/pythPricesApi.d.ts +0 -2
- package/dist/general/prices/pyth/pythPricesApi.d.ts.map +0 -1
- package/dist/general/prices/pyth/pythPricesApi.js +0 -52
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts +0 -13
- package/dist/general/prices/pyth/pythPricesApiHelpers.d.ts.map +0 -1
- package/dist/general/prices/pyth/pythPricesApiHelpers.js +0 -77
- package/dist/general/prices/router/routerPricesApi.d.ts +0 -18
- package/dist/general/prices/router/routerPricesApi.d.ts.map +0 -1
- package/dist/general/prices/router/routerPricesApi.js +0 -126
- package/dist/general/utils/indexerCaller.d.ts +0 -14
- package/dist/general/utils/indexerCaller.d.ts.map +0 -1
- package/dist/general/utils/indexerCaller.js +0 -129
- /package/dist/general/prices/{coingecko/coinGeckoTypes.js → coinGeckoTypes.js} +0 -0
|
@@ -8,9 +8,6 @@ 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
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.PoolsApi = void 0;
|
|
16
13
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
@@ -19,10 +16,6 @@ const casting_1 = require("../../../general/utils/casting");
|
|
|
19
16
|
const pools_1 = require("../pools");
|
|
20
17
|
const utils_2 = require("../../../general/utils");
|
|
21
18
|
const coin_1 = require("../../coin");
|
|
22
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
23
|
-
const poolsApiCasting_1 = require("./poolsApiCasting");
|
|
24
|
-
const duration_1 = __importDefault(require("dayjs/plugin/duration"));
|
|
25
|
-
const fixedUtils_1 = require("../../../general/utils/fixedUtils");
|
|
26
19
|
const eventsApiHelpers_1 = require("../../../general/apiHelpers/eventsApiHelpers");
|
|
27
20
|
const bcs_1 = require("@mysten/sui/bcs");
|
|
28
21
|
/**
|
|
@@ -49,36 +42,6 @@ class PoolsApi {
|
|
|
49
42
|
// =========================================================================
|
|
50
43
|
// Objects
|
|
51
44
|
// =========================================================================
|
|
52
|
-
// TODO: make caches shared across pool object fetching funcs
|
|
53
|
-
/**
|
|
54
|
-
* Fetches a pool object by its object ID.
|
|
55
|
-
* @async
|
|
56
|
-
* @param {ObjectId} inputs.objectId - The object ID of the pool to fetch.
|
|
57
|
-
* @returns {Promise<PoolObject>} A promise that resolves to the fetched pool object.
|
|
58
|
-
*/
|
|
59
|
-
this.fetchPool = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
return (yield this.fetchPools({ objectIds: [inputs.objectId] }))[0];
|
|
61
|
-
});
|
|
62
|
-
this.fetchPools = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const poolIds = inputs.objectIds.map((objectId) => utils_2.Helpers.addLeadingZeroesToType(objectId));
|
|
64
|
-
const response = yield this.Provider.indexerCaller.fetchIndexer("pools", {
|
|
65
|
-
pool_ids: poolIds,
|
|
66
|
-
});
|
|
67
|
-
const pools = poolsApiCasting_1.PoolsApiCasting.poolObjectsFromIndexerResponse(response);
|
|
68
|
-
return poolIds.map((objectId) => pools.find((pool) => pool.objectId ===
|
|
69
|
-
utils_2.Helpers.addLeadingZeroesToType(objectId)
|
|
70
|
-
// TODO: handle this error case better
|
|
71
|
-
));
|
|
72
|
-
});
|
|
73
|
-
/**
|
|
74
|
-
* Fetches all pool objects.
|
|
75
|
-
* @async
|
|
76
|
-
* @returns {Promise<PoolObject[]>} A promise that resolves to an array of all fetched pool objects.
|
|
77
|
-
*/
|
|
78
|
-
this.fetchAllPools = () => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
const response = yield this.Provider.indexerCaller.fetchIndexer("pools", {});
|
|
80
|
-
return poolsApiCasting_1.PoolsApiCasting.poolObjectsFromIndexerResponse(response);
|
|
81
|
-
});
|
|
82
45
|
this.fetchOwnedDaoFeePoolOwnerCaps = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
83
46
|
const { walletAddress } = inputs;
|
|
84
47
|
if (!this.objectTypes.daoFeePoolOwnerCap)
|
|
@@ -439,35 +402,6 @@ class PoolsApi {
|
|
|
439
402
|
// =========================================================================
|
|
440
403
|
// Transaction Builders
|
|
441
404
|
// =========================================================================
|
|
442
|
-
/**
|
|
443
|
-
* Fetches a transaction block for creating a new pool.
|
|
444
|
-
* @async
|
|
445
|
-
* @param {SuiAddress} inputs.walletAddress - The wallet address of the user creating the pool.
|
|
446
|
-
* @param {CoinType} inputs.lpCoinType - The coin type of the LP token.
|
|
447
|
-
* @param {PoolCreationLpCoinMetadata} inputs.lpCoinMetadata - The metadata of the LP token.
|
|
448
|
-
* @param {{ coinType: CoinType; weight: Percentage; decimals?: CoinDecimal; tradeFeeIn: Percentage; initialDeposit: Balance; }[]} inputs.coinsInfo - An array of objects containing information about the coins in the pool.
|
|
449
|
-
* @param {PoolName} inputs.poolName - The name of the pool.
|
|
450
|
-
* @param {0 | 1} inputs.poolFlatness - The flatness of the pool.
|
|
451
|
-
* @param {ObjectId} inputs.createPoolCapId - The object ID of the create pool cap.
|
|
452
|
-
* @param {boolean} inputs.respectDecimals - Whether to respect decimals.
|
|
453
|
-
* @param {CoinDecimal} [inputs.forceLpDecimals] - The decimal places to force for the LP token.
|
|
454
|
-
* @param {boolean} [inputs.isSponsoredTx] - Whether the transaction is sponsored.
|
|
455
|
-
* @returns {Promise<Transaction>} A promise that resolves to the fetched transaction block.
|
|
456
|
-
*/
|
|
457
|
-
this.fetchCreatePoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
458
|
-
var _a;
|
|
459
|
-
// NOTE: these are temp defaults down below since some selections are currently disabled in contracts
|
|
460
|
-
return this.fetchBuildCreatePoolTx(Object.assign(Object.assign({}, inputs), { lpCoinIconUrl: (_a = inputs.lpCoinMetadata.iconUrl) !== null && _a !== void 0 ? _a : "", poolFlatness: inputs.poolFlatness === 1 ? casting_1.Casting.Fixed.fixedOneB : BigInt(0), coinsInfo: inputs.coinsInfo.map((info, index) => {
|
|
461
|
-
let weight = casting_1.Casting.numberToFixedBigInt(info.weight);
|
|
462
|
-
if (index === 0) {
|
|
463
|
-
const otherWeightsSum = utils_2.Helpers.sumBigInt(inputs.coinsInfo
|
|
464
|
-
.slice(1)
|
|
465
|
-
.map((info) => casting_1.Casting.numberToFixedBigInt(info.weight)));
|
|
466
|
-
weight = casting_1.Casting.Fixed.fixedOneB - otherWeightsSum;
|
|
467
|
-
}
|
|
468
|
-
return Object.assign(Object.assign({}, info), { weight, tradeFeeIn: casting_1.Casting.numberToFixedBigInt(info.tradeFeeIn), depositFee: BigInt(0), withdrawFee: BigInt(0), tradeFeeOut: BigInt(0) });
|
|
469
|
-
}) }));
|
|
470
|
-
});
|
|
471
405
|
/**
|
|
472
406
|
* Fetches a transaction block for trading in a pool.
|
|
473
407
|
* @async
|
|
@@ -716,604 +650,9 @@ class PoolsApi {
|
|
|
716
650
|
tx.transferObjects([upgradeCap], inputs.walletAddress);
|
|
717
651
|
return tx;
|
|
718
652
|
};
|
|
719
|
-
/**
|
|
720
|
-
* Fetches and builds a transaction for creating a new liquidity pool.
|
|
721
|
-
* @param inputs An object containing the necessary inputs for creating the pool.
|
|
722
|
-
* @returns A Promise that resolves to a Transaction object representing the built transaction.
|
|
723
|
-
*/
|
|
724
|
-
this.fetchBuildCreatePoolTx = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
725
|
-
const { coinsInfo, isSponsoredTx, burnLpCoin, lpCoinType, daoFeeInfo } = inputs;
|
|
726
|
-
const tx = new transactions_1.Transaction();
|
|
727
|
-
tx.setSender(inputs.walletAddress);
|
|
728
|
-
// TODO: make this fetching work
|
|
729
|
-
// const createPoolCapId =
|
|
730
|
-
// inputs.createPoolCapId !== undefined
|
|
731
|
-
// ? inputs.createPoolCapId
|
|
732
|
-
// : (
|
|
733
|
-
// await this.Provider.Objects().fetchObjectsOfTypeOwnedByAddress(
|
|
734
|
-
// inputs.walletAddress,
|
|
735
|
-
// `${this.addresses.pools.packages.cmmm}::${PoolsApi.constants.moduleNames.pool}::CreatePoolCap<${inputs.lpCoinType}>`
|
|
736
|
-
// )
|
|
737
|
-
// )[0].data?.objectId;
|
|
738
|
-
// if (createPoolCapId === undefined)
|
|
739
|
-
// throw new Error(
|
|
740
|
-
// "no CreatePoolCap for LP Coin Type found owned by address"
|
|
741
|
-
// );
|
|
742
|
-
coinsInfo.sort((a, b) => {
|
|
743
|
-
const coinA = a.coinType.toUpperCase();
|
|
744
|
-
const coinB = b.coinType.toUpperCase();
|
|
745
|
-
return coinA < coinB ? -1 : coinA > coinB ? 1 : 0;
|
|
746
|
-
});
|
|
747
|
-
const coinTypes = coinsInfo.map((coin) => coin.coinType);
|
|
748
|
-
const lpCoinDescription = yield this.createLpCoinMetadataDescription(Object.assign(Object.assign({}, inputs), { coinTypes }));
|
|
749
|
-
const coinArgs = yield this.Provider.Coin().fetchCoinsWithAmountTx(Object.assign(Object.assign({ tx }, inputs), { coinTypes, coinAmounts: coinsInfo.map((info) => info.initialDeposit), isSponsoredTx }));
|
|
750
|
-
const createPoolTxArgs = Object.assign(Object.assign({ tx }, inputs), {
|
|
751
|
-
// createPoolCapId,
|
|
752
|
-
coinsInfo: coinsInfo.map((info, index) => {
|
|
753
|
-
return Object.assign(Object.assign({}, info), { coinId: coinArgs[index] });
|
|
754
|
-
}), lpCoinDescription });
|
|
755
|
-
if (daoFeeInfo) {
|
|
756
|
-
if (!this.objectTypes.daoFeePool)
|
|
757
|
-
throw new Error("dao fee pool addresses have not been set in provider");
|
|
758
|
-
const [poolId, lpCoinId] = this.createPoolTx(createPoolTxArgs);
|
|
759
|
-
const [daoFeePoolId, daoFeePoolOwnerCapId] = this.daoFeePoolNewTx({
|
|
760
|
-
tx,
|
|
761
|
-
poolId,
|
|
762
|
-
lpCoinType,
|
|
763
|
-
feeRecipient: daoFeeInfo.feeRecipient,
|
|
764
|
-
feeBps: casting_1.Casting.percentageToBps(daoFeeInfo.feePercentage),
|
|
765
|
-
});
|
|
766
|
-
this.Provider.Objects().publicShareObjectTx({
|
|
767
|
-
tx,
|
|
768
|
-
object: daoFeePoolId,
|
|
769
|
-
objectType: `${this.objectTypes.daoFeePool}<${lpCoinType}>`,
|
|
770
|
-
});
|
|
771
|
-
if (burnLpCoin) {
|
|
772
|
-
this.Provider.Objects().burnObjectTx({
|
|
773
|
-
tx,
|
|
774
|
-
object: lpCoinId,
|
|
775
|
-
});
|
|
776
|
-
tx.transferObjects([daoFeePoolOwnerCapId], inputs.walletAddress);
|
|
777
|
-
}
|
|
778
|
-
else {
|
|
779
|
-
tx.transferObjects([lpCoinId, daoFeePoolOwnerCapId], inputs.walletAddress);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
else {
|
|
783
|
-
if (burnLpCoin) {
|
|
784
|
-
const [poolId, lpCoinId] = this.createPoolTx(createPoolTxArgs);
|
|
785
|
-
this.Provider.Objects().publicShareObjectTx({
|
|
786
|
-
tx,
|
|
787
|
-
object: poolId,
|
|
788
|
-
objectType: `${this.objectTypes.pool}<${lpCoinType}>`,
|
|
789
|
-
});
|
|
790
|
-
this.Provider.Objects().burnObjectTx({
|
|
791
|
-
tx,
|
|
792
|
-
object: lpCoinId,
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
else {
|
|
796
|
-
this.createPoolTx(Object.assign(Object.assign({}, createPoolTxArgs), { withTransfer: true }));
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return tx;
|
|
800
|
-
});
|
|
801
653
|
this.buildDaoFeePoolUpdateFeeBpsTx = utils_2.Helpers.transactions.createBuildTxFunc(this.daoFeePoolUpdateFeeBpsTx);
|
|
802
654
|
this.buildDaoFeePoolUpdateFeeRecipientTx = utils_2.Helpers.transactions.createBuildTxFunc(this.daoFeePoolUpdateFeeRecipientTx);
|
|
803
655
|
// =========================================================================
|
|
804
|
-
// Inspections
|
|
805
|
-
// =========================================================================
|
|
806
|
-
/**
|
|
807
|
-
* Fetches the pool object ID for a given LP coin type.
|
|
808
|
-
* @param inputs - An object containing the LP coin type.
|
|
809
|
-
* @returns A Promise that resolves to the pool object ID.
|
|
810
|
-
*/
|
|
811
|
-
this.fetchPoolObjectIdForLpCoinType = this.Provider.withCache({
|
|
812
|
-
key: "fetchPoolObjectIdForLpCoinType",
|
|
813
|
-
expirationSeconds: -1,
|
|
814
|
-
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
815
|
-
if (!pools_1.Pools.isPossibleLpCoinType(inputs))
|
|
816
|
-
return "";
|
|
817
|
-
const tx = new transactions_1.Transaction();
|
|
818
|
-
this.poolObjectIdForLpCoinTypeTx(Object.assign({ tx }, inputs));
|
|
819
|
-
const bytes = yield this.Provider.Inspections().fetchFirstBytesFromTxOutput({
|
|
820
|
-
tx,
|
|
821
|
-
});
|
|
822
|
-
return casting_1.Casting.addressFromBytes(bytes);
|
|
823
|
-
}),
|
|
824
|
-
});
|
|
825
|
-
// TODO: add cache and generalize logic
|
|
826
|
-
// public fetchPoolObjectIdForLpCoinTypes = this.Provider.withCache({
|
|
827
|
-
// key: "fetchPoolObjectIdForLpCoinTypes",
|
|
828
|
-
// expirationSeconds: -1,
|
|
829
|
-
// callback: async (inputs: {
|
|
830
|
-
// lpCoinType: CoinType;
|
|
831
|
-
// }): Promise<ObjectId | undefined> => {
|
|
832
|
-
// if (!Pools.isPossibleLpCoinType(inputs)) return "";
|
|
833
|
-
// const tx = new Transaction();
|
|
834
|
-
// this.poolObjectIdForLpCoinTypeTx({ tx, ...inputs });
|
|
835
|
-
// const bytes =
|
|
836
|
-
// await this.Provider.Inspections().fetchFirstBytesFromTxOutput({
|
|
837
|
-
// tx,
|
|
838
|
-
// });
|
|
839
|
-
// return Casting.addressFromBytes(bytes);
|
|
840
|
-
// },
|
|
841
|
-
// });
|
|
842
|
-
this.fetchIsLpCoinType = this.Provider.withCache({
|
|
843
|
-
key: "fetchIsLpCoinType",
|
|
844
|
-
expirationSeconds: -1,
|
|
845
|
-
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
846
|
-
const { lpCoinType } = inputs;
|
|
847
|
-
const poolId = yield this.fetchPoolObjectIdForLpCoinType({
|
|
848
|
-
lpCoinType,
|
|
849
|
-
});
|
|
850
|
-
if (!poolId)
|
|
851
|
-
return false;
|
|
852
|
-
return true;
|
|
853
|
-
}),
|
|
854
|
-
});
|
|
855
|
-
/**
|
|
856
|
-
* Fetches the list of unique supported coins across all pools.
|
|
857
|
-
* @returns {Promise<CoinType[]>} A promise that resolves to an array of unique supported coins.
|
|
858
|
-
*/
|
|
859
|
-
this.fetchSupportedCoins = () => __awaiter(this, void 0, void 0, function* () {
|
|
860
|
-
const pools = yield this.Provider.Pools().fetchAllPools();
|
|
861
|
-
const allCoins = pools
|
|
862
|
-
.map((pool) => Object.keys(pool.coins))
|
|
863
|
-
.reduce((prev, cur) => [...prev, ...cur], []);
|
|
864
|
-
const uniqueCoins = utils_2.Helpers.uniqueArray(allCoins);
|
|
865
|
-
return uniqueCoins;
|
|
866
|
-
});
|
|
867
|
-
/**
|
|
868
|
-
* Fetches the owned LP coin positions for a given wallet address.
|
|
869
|
-
* @param inputs An object containing the wallet address.
|
|
870
|
-
* @returns A Promise that resolves to an array of PoolLpInfo objects.
|
|
871
|
-
*/
|
|
872
|
-
this.fetchOwnedLpCoinPositions = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
873
|
-
const { walletAddress } = inputs;
|
|
874
|
-
const [coinsToBalance, pools] = yield Promise.all([
|
|
875
|
-
this.Provider.Wallet().fetchAllCoinBalances({
|
|
876
|
-
walletAddress,
|
|
877
|
-
}),
|
|
878
|
-
this.fetchAllPools(),
|
|
879
|
-
]);
|
|
880
|
-
let lpInfo = [];
|
|
881
|
-
for (const pool of pools) {
|
|
882
|
-
const lpCoinType = utils_2.Helpers.addLeadingZeroesToType(pool.lpCoinType);
|
|
883
|
-
if (!(lpCoinType in coinsToBalance))
|
|
884
|
-
continue;
|
|
885
|
-
lpInfo.push({
|
|
886
|
-
lpCoinType,
|
|
887
|
-
poolId: pool.objectId,
|
|
888
|
-
balance: coinsToBalance[lpCoinType],
|
|
889
|
-
});
|
|
890
|
-
}
|
|
891
|
-
return lpInfo;
|
|
892
|
-
});
|
|
893
|
-
// =========================================================================
|
|
894
|
-
// Stats
|
|
895
|
-
// =========================================================================
|
|
896
|
-
/**
|
|
897
|
-
* Fetches statistics for a given pool.
|
|
898
|
-
* @param inputs An object containing the pool, trade events within a certain time frame, coins to price, and coins to decimals.
|
|
899
|
-
* @returns A Promise that resolves to a PoolStats object containing the volume, TVL, supply per LP token, LP token price, fees, and APY.
|
|
900
|
-
*/
|
|
901
|
-
this.fetchPoolStats = this.Provider.withCache({
|
|
902
|
-
key: "fetchPoolStats",
|
|
903
|
-
expirationSeconds: 60 * 5,
|
|
904
|
-
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
905
|
-
const { poolId } = inputs;
|
|
906
|
-
const pool = yield this.fetchPool({ objectId: poolId });
|
|
907
|
-
const poolCoins = pool.coins;
|
|
908
|
-
const poolCoinTypes = Object.keys(pool.coins);
|
|
909
|
-
// TODO: move common milliseconds to constants or use dayjs
|
|
910
|
-
const durationMs24hrs = 86400000;
|
|
911
|
-
const [coinsToPrice, coinsToDecimals, volumes] = yield Promise.all([
|
|
912
|
-
this.Provider.Prices().fetchCoinsToPrice({
|
|
913
|
-
coins: poolCoinTypes,
|
|
914
|
-
}),
|
|
915
|
-
this.Provider.Coin().fetchCoinsToDecimals({
|
|
916
|
-
coins: poolCoinTypes,
|
|
917
|
-
}),
|
|
918
|
-
this.fetchPoolVolume({
|
|
919
|
-
poolId: pool.objectId,
|
|
920
|
-
durationMs: durationMs24hrs,
|
|
921
|
-
}),
|
|
922
|
-
]);
|
|
923
|
-
const volume = utils_2.Helpers.calcIndexerVolumeUsd({
|
|
924
|
-
volumes,
|
|
925
|
-
coinsToDecimals,
|
|
926
|
-
coinsToPrice,
|
|
927
|
-
});
|
|
928
|
-
const tvl = this.calcPoolTvl({
|
|
929
|
-
poolCoins: pool.coins,
|
|
930
|
-
coinsToPrice,
|
|
931
|
-
coinsToDecimals,
|
|
932
|
-
});
|
|
933
|
-
const supplyPerLps = this.calcPoolSupplyPerLps(poolCoins, pool.lpCoinSupply);
|
|
934
|
-
const lpPrice = this.calcPoolLpPrice({
|
|
935
|
-
lpCoinDecimals: pool.lpCoinDecimals,
|
|
936
|
-
lpCoinSupply: pool.lpCoinSupply,
|
|
937
|
-
tvl,
|
|
938
|
-
});
|
|
939
|
-
// this is okay since all trade fees are currently the same for every coin
|
|
940
|
-
const firstCoin = Object.values(pool.coins)[0];
|
|
941
|
-
const fees = volume *
|
|
942
|
-
fixedUtils_1.FixedUtils.directCast(firstCoin.tradeFeeIn + firstCoin.tradeFeeOut);
|
|
943
|
-
const apr = this.calcApr({
|
|
944
|
-
fees24Hours: fees,
|
|
945
|
-
tvl,
|
|
946
|
-
});
|
|
947
|
-
return {
|
|
948
|
-
volume,
|
|
949
|
-
tvl,
|
|
950
|
-
supplyPerLps,
|
|
951
|
-
lpPrice,
|
|
952
|
-
fees,
|
|
953
|
-
apr,
|
|
954
|
-
};
|
|
955
|
-
}),
|
|
956
|
-
});
|
|
957
|
-
/**
|
|
958
|
-
* Fetches the pool volume for a given pool and duration.
|
|
959
|
-
* @param inputs - The inputs for fetching the pool volume.
|
|
960
|
-
* @returns A Promise that resolves to an array of pool volumes.
|
|
961
|
-
*/
|
|
962
|
-
this.fetchPoolVolume = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
963
|
-
const { poolId, durationMs } = inputs;
|
|
964
|
-
const response = yield this.Provider.indexerCaller.fetchIndexer(`pools/${poolId}/swap-volume/${durationMs}`);
|
|
965
|
-
return response.map((data) => (Object.assign(Object.assign({}, data), { coinTypeIn: utils_2.Helpers.addLeadingZeroesToType(data.coinTypeIn), coinTypeOut: utils_2.Helpers.addLeadingZeroesToType(data.coinTypeOut) })));
|
|
966
|
-
});
|
|
967
|
-
/**
|
|
968
|
-
* Fetches the total volume of swaps within a specified duration.
|
|
969
|
-
* @param inputs - The inputs for fetching the total volume.
|
|
970
|
-
* @returns A Promise that resolves to an array of total volumes.
|
|
971
|
-
*/
|
|
972
|
-
this.fetchTotalVolume = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
973
|
-
const { durationMs } = inputs;
|
|
974
|
-
return this.Provider.indexerCaller.fetchIndexer(`pools/total-swap-volume/${durationMs}`);
|
|
975
|
-
});
|
|
976
|
-
/**
|
|
977
|
-
* Calculates the total value locked (TVL) for a given pool, based on its current balances and prices.
|
|
978
|
-
* @param inputs - An object containing the pool's coins, their prices, and their decimal places.
|
|
979
|
-
* @returns The total value locked (TVL) for the pool.
|
|
980
|
-
*/
|
|
981
|
-
this.calcPoolTvl = (inputs) => {
|
|
982
|
-
const { poolCoins, coinsToPrice, coinsToDecimals } = inputs;
|
|
983
|
-
let tvl = 0;
|
|
984
|
-
for (const [poolCoinType, poolCoin] of Object.entries(poolCoins)) {
|
|
985
|
-
const amountWithDecimals = coin_1.Coin.balanceWithDecimals(poolCoin.balance, coinsToDecimals[poolCoinType]);
|
|
986
|
-
const price = coinsToPrice[poolCoinType];
|
|
987
|
-
tvl += amountWithDecimals * (price < 0 ? 0 : price);
|
|
988
|
-
}
|
|
989
|
-
return tvl;
|
|
990
|
-
};
|
|
991
|
-
this.fetchCalcPoolVolume24hrs = this.Provider.withCache({
|
|
992
|
-
key: "fetchPool",
|
|
993
|
-
expirationSeconds: 300,
|
|
994
|
-
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
995
|
-
const { poolId } = inputs;
|
|
996
|
-
const durationMs = 86400000; // 24hrs
|
|
997
|
-
const volumes = yield this.fetchPoolVolume({
|
|
998
|
-
durationMs,
|
|
999
|
-
poolId,
|
|
1000
|
-
});
|
|
1001
|
-
const coins = utils_2.Helpers.uniqueArray([
|
|
1002
|
-
...volumes.map((vol) => vol.coinTypeIn),
|
|
1003
|
-
...volumes.map((vol) => vol.coinTypeOut),
|
|
1004
|
-
]);
|
|
1005
|
-
const [coinsToPrice, coinsToDecimals] = yield Promise.all([
|
|
1006
|
-
this.Provider.Prices().fetchCoinsToPrice({ coins }),
|
|
1007
|
-
this.Provider.Coin().fetchCoinsToDecimals({ coins }),
|
|
1008
|
-
]);
|
|
1009
|
-
return utils_2.Helpers.calcIndexerVolumeUsd({
|
|
1010
|
-
volumes,
|
|
1011
|
-
coinsToPrice,
|
|
1012
|
-
coinsToDecimals,
|
|
1013
|
-
});
|
|
1014
|
-
}),
|
|
1015
|
-
});
|
|
1016
|
-
/**
|
|
1017
|
-
* Calculates the pool supply per LP token.
|
|
1018
|
-
* @param poolCoins - The pool coins object.
|
|
1019
|
-
* @param lpSupply - The total supply of LP tokens.
|
|
1020
|
-
* @returns An array of supply per LP token for each pool coin.
|
|
1021
|
-
*/
|
|
1022
|
-
this.calcPoolSupplyPerLps = (poolCoins, lpSupply) => {
|
|
1023
|
-
const supplyPerLps = Object.values(poolCoins).map((poolCoin) => Number(poolCoin.balance) / Number(lpSupply));
|
|
1024
|
-
return supplyPerLps;
|
|
1025
|
-
};
|
|
1026
|
-
/**
|
|
1027
|
-
* Calculates the price of a liquidity pool token.
|
|
1028
|
-
* @param inputs - An object containing the liquidity pool token supply, total value locked, and the number of decimal places for the token.
|
|
1029
|
-
* @returns The price of the liquidity pool token.
|
|
1030
|
-
*/
|
|
1031
|
-
this.calcPoolLpPrice = (inputs) => {
|
|
1032
|
-
const { lpCoinSupply, tvl, lpCoinDecimals } = inputs;
|
|
1033
|
-
const lpPrice = Number(Number(tvl) / coin_1.Coin.balanceWithDecimals(lpCoinSupply, lpCoinDecimals));
|
|
1034
|
-
return lpPrice;
|
|
1035
|
-
};
|
|
1036
|
-
/**
|
|
1037
|
-
* Calculates the APR (Annual Percentage Rate) based on the fees collected in the last 24 hours and the TVL (Total Value Locked) of a pool.
|
|
1038
|
-
* @param inputs - An object containing the fees collected in the last 24 hours and the TVL of a pool.
|
|
1039
|
-
* @returns The APR (Annual Percentage Rate) of the pool.
|
|
1040
|
-
*/
|
|
1041
|
-
this.calcApr = (inputs) => {
|
|
1042
|
-
const { fees24Hours, tvl } = inputs;
|
|
1043
|
-
// TODO: use daysjs instead
|
|
1044
|
-
const daysInYear = 365;
|
|
1045
|
-
return (fees24Hours * daysInYear) / tvl;
|
|
1046
|
-
};
|
|
1047
|
-
// =========================================================================
|
|
1048
|
-
// Prices
|
|
1049
|
-
// =========================================================================
|
|
1050
|
-
// TODO: make this faster this is slow as shit when LP balances are involved...
|
|
1051
|
-
// (so much fetching!)
|
|
1052
|
-
// TODO: rename this function and/or move it ?
|
|
1053
|
-
/**
|
|
1054
|
-
* Fetches the prices of the given LP coins.
|
|
1055
|
-
* @param lpCoins The LP coins to fetch prices for.
|
|
1056
|
-
* @returns An object containing the prices of the LP coins.
|
|
1057
|
-
*/
|
|
1058
|
-
this.fetchLpCoinsToPrice = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1059
|
-
const { lpCoins } = inputs;
|
|
1060
|
-
const unsafeLpCoinPoolObjectIds = yield Promise.all(lpCoins.map((lpCoinType) => __awaiter(this, void 0, void 0, function* () {
|
|
1061
|
-
return this.fetchPoolObjectIdForLpCoinType({
|
|
1062
|
-
lpCoinType,
|
|
1063
|
-
});
|
|
1064
|
-
})));
|
|
1065
|
-
const safeIndexes = [];
|
|
1066
|
-
const lpCoinPoolObjectIds = unsafeLpCoinPoolObjectIds.filter((id, index) => {
|
|
1067
|
-
const isValid = id !== undefined;
|
|
1068
|
-
if (isValid)
|
|
1069
|
-
safeIndexes.push(index);
|
|
1070
|
-
return isValid;
|
|
1071
|
-
});
|
|
1072
|
-
const poolStats = yield Promise.all(lpCoinPoolObjectIds.map((poolId) => this.fetchPoolStats({ poolId })));
|
|
1073
|
-
let lpCoinsToPrice = {};
|
|
1074
|
-
for (const [index, safeIndex] of safeIndexes.entries()) {
|
|
1075
|
-
const lpCoin = lpCoins[safeIndex];
|
|
1076
|
-
const coinPrice = poolStats[index].lpPrice;
|
|
1077
|
-
lpCoinsToPrice = Object.assign(Object.assign({}, lpCoinsToPrice), { [lpCoin]: coinPrice });
|
|
1078
|
-
}
|
|
1079
|
-
for (const [index, lpCoin] of lpCoins.entries()) {
|
|
1080
|
-
if (safeIndexes.includes(index))
|
|
1081
|
-
continue;
|
|
1082
|
-
lpCoinsToPrice = Object.assign(Object.assign({}, lpCoinsToPrice), { [lpCoin]: -1 });
|
|
1083
|
-
}
|
|
1084
|
-
return lpCoinsToPrice;
|
|
1085
|
-
});
|
|
1086
|
-
// =========================================================================
|
|
1087
|
-
// Graph Data
|
|
1088
|
-
// =========================================================================
|
|
1089
|
-
/**
|
|
1090
|
-
* Calculates the pool fee data from the given volume data and pool trade fee.
|
|
1091
|
-
* @param inputs - The inputs required to calculate the pool fee data.
|
|
1092
|
-
* @param inputs.volumeData - The volume data to calculate the pool fee data from.
|
|
1093
|
-
* @param inputs.poolTradeFee - The pool trade fee to use for the calculation.
|
|
1094
|
-
* @returns The pool fee data calculated from the given volume data and pool trade fee.
|
|
1095
|
-
*/
|
|
1096
|
-
this.calcPoolFeeDataFromVolume = (inputs) => {
|
|
1097
|
-
const feeData = inputs.volumeData.map((data) => ({
|
|
1098
|
-
time: data.time,
|
|
1099
|
-
value: data.value * fixedUtils_1.FixedUtils.directCast(inputs.poolTradeFee),
|
|
1100
|
-
}));
|
|
1101
|
-
return feeData;
|
|
1102
|
-
};
|
|
1103
|
-
/**
|
|
1104
|
-
* Calculates the pool volume data based on the provided inputs.
|
|
1105
|
-
* @param inputs An object containing the necessary inputs for the calculation.
|
|
1106
|
-
* @param inputs.tradeEvents An array of pool trade events.
|
|
1107
|
-
* @param inputs.timeUnit The time unit to use for the calculation.
|
|
1108
|
-
* @param inputs.time The time duration to use for the calculation.
|
|
1109
|
-
* @returns An array of pool data points.
|
|
1110
|
-
*/
|
|
1111
|
-
this.fetchCalcPoolVolumeData = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1112
|
-
const { poolId, timeframe } = inputs;
|
|
1113
|
-
const pool = yield this.fetchPool({ objectId: poolId });
|
|
1114
|
-
const coins = Object.keys(pool.coins);
|
|
1115
|
-
const [coinsToPrice, coinsToDecimals] = yield Promise.all([
|
|
1116
|
-
this.Provider.Prices().fetchCoinsToPrice({
|
|
1117
|
-
coins,
|
|
1118
|
-
}),
|
|
1119
|
-
this.Provider.Coin().fetchCoinsToDecimals({ coins }),
|
|
1120
|
-
]);
|
|
1121
|
-
const { time, timeUnit } = PoolsApi.poolVolumeDataTimeframes[timeframe];
|
|
1122
|
-
const tradeEvents = yield this.fetchTradeEventsWithinTime({
|
|
1123
|
-
time,
|
|
1124
|
-
timeUnit,
|
|
1125
|
-
poolId,
|
|
1126
|
-
});
|
|
1127
|
-
const buckets = time;
|
|
1128
|
-
const now = Date.now();
|
|
1129
|
-
const maxTimeAgo = (0, dayjs_1.default)(now).subtract(time, timeUnit);
|
|
1130
|
-
const timeGap = (0, dayjs_1.default)(now).diff(maxTimeAgo);
|
|
1131
|
-
const bucketTimestampSize = timeGap / buckets;
|
|
1132
|
-
const emptyDataPoints = Array(buckets)
|
|
1133
|
-
.fill({
|
|
1134
|
-
time: 0,
|
|
1135
|
-
value: 0,
|
|
1136
|
-
})
|
|
1137
|
-
.map((dataPoint, index) => {
|
|
1138
|
-
return Object.assign(Object.assign({}, dataPoint), { time: maxTimeAgo.valueOf() + index * bucketTimestampSize });
|
|
1139
|
-
});
|
|
1140
|
-
const dataPoints = tradeEvents.reduce((acc, trade) => {
|
|
1141
|
-
if (trade.timestamp === undefined)
|
|
1142
|
-
return acc;
|
|
1143
|
-
const tradeDate = dayjs_1.default.unix(trade.timestamp / 1000);
|
|
1144
|
-
const bucketIndex = acc.length -
|
|
1145
|
-
Math.floor((0, dayjs_1.default)(now).diff(tradeDate) / bucketTimestampSize) -
|
|
1146
|
-
1;
|
|
1147
|
-
const amountUsd = trade.typesIn.reduce((acc, cur, index) => {
|
|
1148
|
-
const price = coinsToPrice[cur];
|
|
1149
|
-
const amountInUsd = price < 0
|
|
1150
|
-
? 0
|
|
1151
|
-
: coin_1.Coin.balanceWithDecimalsUsd(trade.amountsIn[index], coinsToDecimals[cur], price);
|
|
1152
|
-
return acc + (amountInUsd < 0 ? 0 : amountInUsd);
|
|
1153
|
-
}, 0);
|
|
1154
|
-
acc[bucketIndex].value += amountUsd;
|
|
1155
|
-
return acc;
|
|
1156
|
-
}, emptyDataPoints);
|
|
1157
|
-
return dataPoints;
|
|
1158
|
-
});
|
|
1159
|
-
// =========================================================================
|
|
1160
|
-
// LP Coin Metadata
|
|
1161
|
-
// =========================================================================
|
|
1162
|
-
/**
|
|
1163
|
-
* Creates a description for the Aftermath LP coin for a given pool.
|
|
1164
|
-
* @param inputs - An object containing the pool name and an array of coin types.
|
|
1165
|
-
* @returns A string describing the Aftermath LP coin for the given pool.
|
|
1166
|
-
*/
|
|
1167
|
-
this.createLpCoinMetadataDescription = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1168
|
-
// TODO: do all of this a little bit cleaner
|
|
1169
|
-
// TODO: should metadata be passed into pool creation func ?
|
|
1170
|
-
const coinSymbols = (yield Promise.all(inputs.coinTypes.map((coin) => this.Provider.Coin().fetchCoinMetadata({ coin })))).map((metadata) => metadata.symbol);
|
|
1171
|
-
return `Aftermath LP coin for ${inputs.poolName} Pool (${coinSymbols.reduce((acc, symbol, index) => acc + symbol + (index >= coinSymbols.length - 1 ? "" : ", "), "")})`;
|
|
1172
|
-
});
|
|
1173
|
-
// =========================================================================
|
|
1174
|
-
// CoinGecko Integration
|
|
1175
|
-
// =========================================================================
|
|
1176
|
-
this.fetchCoinGeckoTickerData = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
1177
|
-
const { pools, coinsToDecimals } = inputs;
|
|
1178
|
-
return (yield Promise.all(pools.map((pool) => __awaiter(this, void 0, void 0, function* () {
|
|
1179
|
-
const durationMs24hrs = 86400000;
|
|
1180
|
-
const volumes = yield this.fetchPoolVolume({
|
|
1181
|
-
poolId: pool.pool.objectId,
|
|
1182
|
-
durationMs: durationMs24hrs,
|
|
1183
|
-
});
|
|
1184
|
-
return Object.keys(pool.pool.coins)
|
|
1185
|
-
.slice(0, -1)
|
|
1186
|
-
.map((baseCoinType, index) => {
|
|
1187
|
-
return Object.keys(pool.pool.coins)
|
|
1188
|
-
.slice(index + 1)
|
|
1189
|
-
.map((targetCoinType) => {
|
|
1190
|
-
if (!pool.stats)
|
|
1191
|
-
throw new Error("pool is missing stats");
|
|
1192
|
-
if (baseCoinType === targetCoinType)
|
|
1193
|
-
return undefined;
|
|
1194
|
-
const volumeData = (() => {
|
|
1195
|
-
var _a, _b;
|
|
1196
|
-
const volumeDataIn = (_a = volumes.find((volume) => volume.coinTypeIn ===
|
|
1197
|
-
baseCoinType)) !== null && _a !== void 0 ? _a : {
|
|
1198
|
-
totalAmountIn: 0,
|
|
1199
|
-
totalAmountOut: 0,
|
|
1200
|
-
};
|
|
1201
|
-
const volumeDataOut = (_b = volumes.find((volume) => volume.coinTypeOut ===
|
|
1202
|
-
baseCoinType)) !== null && _b !== void 0 ? _b : {
|
|
1203
|
-
totalAmountIn: 0,
|
|
1204
|
-
totalAmountOut: 0,
|
|
1205
|
-
};
|
|
1206
|
-
return {
|
|
1207
|
-
baseVolume: volumeDataIn.totalAmountIn +
|
|
1208
|
-
volumeDataOut.totalAmountOut,
|
|
1209
|
-
targetVolume: volumeDataIn.totalAmountOut +
|
|
1210
|
-
volumeDataOut.totalAmountIn,
|
|
1211
|
-
};
|
|
1212
|
-
})();
|
|
1213
|
-
const baseDecimals = coinsToDecimals[baseCoinType];
|
|
1214
|
-
const targetDecimals = coinsToDecimals[targetCoinType];
|
|
1215
|
-
if (baseDecimals === undefined ||
|
|
1216
|
-
targetDecimals === undefined)
|
|
1217
|
-
throw new Error("coin decimals not found");
|
|
1218
|
-
const baseVolume = coin_1.Coin.balanceWithDecimals(BigInt(volumeData.baseVolume), baseDecimals);
|
|
1219
|
-
const targetVolume = coin_1.Coin.balanceWithDecimals(BigInt(volumeData.targetVolume), targetDecimals);
|
|
1220
|
-
const unscaledPrice = pool.getSpotPrice({
|
|
1221
|
-
coinInType: baseCoinType,
|
|
1222
|
-
coinOutType: targetCoinType,
|
|
1223
|
-
});
|
|
1224
|
-
const denominator = coin_1.Coin.balanceWithDecimals(unscaledPrice, baseDecimals - targetDecimals);
|
|
1225
|
-
const price = denominator
|
|
1226
|
-
? 1 / denominator
|
|
1227
|
-
: 0;
|
|
1228
|
-
const data = {
|
|
1229
|
-
pool_id: pool.pool.objectId,
|
|
1230
|
-
base_currency: baseCoinType,
|
|
1231
|
-
target_currency: targetCoinType,
|
|
1232
|
-
ticker_id: `${baseCoinType}_${targetCoinType}`,
|
|
1233
|
-
liquidity_in_usd: pool.stats.tvl,
|
|
1234
|
-
base_volume: baseVolume,
|
|
1235
|
-
target_volume: targetVolume,
|
|
1236
|
-
last_price: price,
|
|
1237
|
-
};
|
|
1238
|
-
return data;
|
|
1239
|
-
})
|
|
1240
|
-
.reduce((prev, curr) => [
|
|
1241
|
-
...prev,
|
|
1242
|
-
...(curr ? [curr] : []),
|
|
1243
|
-
], []);
|
|
1244
|
-
})
|
|
1245
|
-
.reduce((prev, curr) => [...prev, ...curr], []);
|
|
1246
|
-
})))).reduce((prev, curr) => [...prev, ...curr], []);
|
|
1247
|
-
});
|
|
1248
|
-
// public fetchCoinGeckoHistoricalTradeData = async (inputs: {
|
|
1249
|
-
// limit: number;
|
|
1250
|
-
// baseCoinType: CoinType;
|
|
1251
|
-
// targetCoinType: CoinType;
|
|
1252
|
-
// coinsToDecimals: CoinsToDecimals;
|
|
1253
|
-
// }): Promise<CoinGeckoHistoricalTradeData[]> => {
|
|
1254
|
-
// const { coinsToDecimals } = inputs;
|
|
1255
|
-
// const trades = await this.fetchCoinGeckoHistoricalTrades(inputs);
|
|
1256
|
-
// return trades.map((trade) => {
|
|
1257
|
-
// const amountInWithDecimals = Coin.balanceWithDecimals(
|
|
1258
|
-
// BigInt(trade.amountIn),
|
|
1259
|
-
// coinsToDecimals[trade.coinTypeIn]
|
|
1260
|
-
// );
|
|
1261
|
-
// const amountOutWithDecimals = Coin.balanceWithDecimals(
|
|
1262
|
-
// BigInt(trade.amountOut),
|
|
1263
|
-
// coinsToDecimals[trade.coinTypeOut]
|
|
1264
|
-
// );
|
|
1265
|
-
// const [baseAmount, targetAmount, type]: [
|
|
1266
|
-
// number,
|
|
1267
|
-
// number,
|
|
1268
|
-
// "buy" | "sell"
|
|
1269
|
-
// ] =
|
|
1270
|
-
// trade.coinTypeIn === inputs.baseCoinType
|
|
1271
|
-
// ? [amountInWithDecimals, amountOutWithDecimals, "sell"]
|
|
1272
|
-
// : [amountOutWithDecimals, amountInWithDecimals, "buy"];
|
|
1273
|
-
// const price = baseAmount / targetAmount;
|
|
1274
|
-
// return {
|
|
1275
|
-
// price,
|
|
1276
|
-
// type,
|
|
1277
|
-
// trade_id: trade._id.$oid,
|
|
1278
|
-
// base_volume: baseAmount,
|
|
1279
|
-
// target_volume: targetAmount,
|
|
1280
|
-
// trade_timestamp: trade.timestampMs,
|
|
1281
|
-
// };
|
|
1282
|
-
// });
|
|
1283
|
-
// };
|
|
1284
|
-
// =========================================================================
|
|
1285
|
-
// Private Methods
|
|
1286
|
-
// =========================================================================
|
|
1287
|
-
// =========================================================================
|
|
1288
|
-
// Helpers
|
|
1289
|
-
// =========================================================================
|
|
1290
|
-
// private async fetchCoinGeckoHistoricalTrades(inputs: {
|
|
1291
|
-
// limit: number;
|
|
1292
|
-
// baseCoinType: CoinType;
|
|
1293
|
-
// targetCoinType: CoinType;
|
|
1294
|
-
// }): Promise<
|
|
1295
|
-
// {
|
|
1296
|
-
// _id: {
|
|
1297
|
-
// $oid: UniqueId;
|
|
1298
|
-
// };
|
|
1299
|
-
// amountIn: number;
|
|
1300
|
-
// amountOut: number;
|
|
1301
|
-
// timestampMs: Timestamp;
|
|
1302
|
-
// coinTypeIn: CoinType;
|
|
1303
|
-
// coinTypeOut: CoinType;
|
|
1304
|
-
// }[]
|
|
1305
|
-
// > {
|
|
1306
|
-
// const { limit, baseCoinType, targetCoinType } = inputs;
|
|
1307
|
-
// return this.Provider.indexerCaller.fetchIndexer(
|
|
1308
|
-
// `pools/coingecko/historical-trades/${Helpers.addLeadingZeroesToType(
|
|
1309
|
-
// baseCoinType
|
|
1310
|
-
// )}/${Helpers.addLeadingZeroesToType(targetCoinType)}`,
|
|
1311
|
-
// {
|
|
1312
|
-
// limit,
|
|
1313
|
-
// }
|
|
1314
|
-
// );
|
|
1315
|
-
// }
|
|
1316
|
-
// =========================================================================
|
|
1317
656
|
// Event Types
|
|
1318
657
|
// =========================================================================
|
|
1319
658
|
this.tradeEventType = () => eventsApiHelpers_1.EventsApiHelpers.createEventType(this.addresses.pools.packages.events, PoolsApi.constants.moduleNames.events, PoolsApi.constants.eventNames.swap);
|
|
@@ -1482,79 +821,6 @@ class PoolsApi {
|
|
|
1482
821
|
}
|
|
1483
822
|
: {}));
|
|
1484
823
|
}
|
|
1485
|
-
// =========================================================================
|
|
1486
|
-
// Events
|
|
1487
|
-
// =========================================================================
|
|
1488
|
-
/**
|
|
1489
|
-
* Fetches trade events for a pool.
|
|
1490
|
-
* @async
|
|
1491
|
-
* @param {ApiIndexerEventsBody & { poolId: ObjectId }} inputs - An object containing the pool ID, cursor, and limit.
|
|
1492
|
-
* @returns {Promise<PoolTradeEvent[]>} A promise that resolves to an array of fetched trade events.
|
|
1493
|
-
*/
|
|
1494
|
-
fetchTradeEvents(inputs) {
|
|
1495
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1496
|
-
const { poolId, cursor, limit } = inputs;
|
|
1497
|
-
return this.Provider.indexerCaller.fetchIndexerEvents(`pools/${poolId}/events/swap`, {
|
|
1498
|
-
cursor,
|
|
1499
|
-
limit,
|
|
1500
|
-
}, casting_1.Casting.pools.poolTradeEventFromIndexerOnChain);
|
|
1501
|
-
});
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* Fetches withdraw events for a pool.
|
|
1505
|
-
* @async
|
|
1506
|
-
* @param {ApiIndexerEventsBody & { poolId: ObjectId }} inputs - An object containing the pool ID, cursor, and limit.
|
|
1507
|
-
* @returns {Promise<PoolWithdrawEvent[]>} A promise that resolves to an array of fetched withdraw events.
|
|
1508
|
-
*/
|
|
1509
|
-
fetchWithdrawEvents(inputs) {
|
|
1510
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1511
|
-
const { poolId, cursor, limit } = inputs;
|
|
1512
|
-
return this.Provider.indexerCaller.fetchIndexerEvents(`pools/${poolId}/events/withdraw`, {
|
|
1513
|
-
cursor,
|
|
1514
|
-
limit,
|
|
1515
|
-
}, casting_1.Casting.pools.poolWithdrawEventFromIndexerOnChain);
|
|
1516
|
-
});
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Fetches deposit events for a pool.
|
|
1520
|
-
* @async
|
|
1521
|
-
* @param {ApiIndexerEventsBody & { poolId: ObjectId }} inputs - An object containing the pool ID, cursor, and limit.
|
|
1522
|
-
* @returns {Promise<PoolDepositEvent[]>} A promise that resolves to an array of fetched deposit events.
|
|
1523
|
-
*/
|
|
1524
|
-
fetchDepositEvents(inputs) {
|
|
1525
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1526
|
-
const { poolId, cursor, limit } = inputs;
|
|
1527
|
-
return this.Provider.indexerCaller.fetchIndexerEvents(`pools/${poolId}/events/deposit`, {
|
|
1528
|
-
cursor,
|
|
1529
|
-
limit,
|
|
1530
|
-
}, casting_1.Casting.pools.poolDepositEventFromIndexerOnChain);
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
/**
|
|
1534
|
-
* Fetches trade events for a pool within a specified time frame.
|
|
1535
|
-
* @async
|
|
1536
|
-
* @param {ObjectId} inputs.poolId - The object ID of the pool to fetch trade events for.
|
|
1537
|
-
* @param {DurationUnitType} inputs.timeUnit - The time unit of the time frame.
|
|
1538
|
-
* @param {number} inputs.time - The duration of the time frame.
|
|
1539
|
-
* @returns {Promise<PoolTradeEvent[]>} A promise that resolves to an array of fetched trade events.
|
|
1540
|
-
*/
|
|
1541
|
-
fetchTradeEventsWithinTime(inputs) {
|
|
1542
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1543
|
-
try {
|
|
1544
|
-
const { poolId, timeUnit, time } = inputs;
|
|
1545
|
-
dayjs_1.default.extend(duration_1.default);
|
|
1546
|
-
const durationMs = dayjs_1.default.duration(time, timeUnit).asMilliseconds();
|
|
1547
|
-
const tradeEventsOnChain = yield this.Provider.indexerCaller.fetchIndexer(`pools/${poolId}/swap-events-within-time/${durationMs}`, undefined, {
|
|
1548
|
-
skip: 0,
|
|
1549
|
-
limit: 10000, // max from mongo ?
|
|
1550
|
-
});
|
|
1551
|
-
return tradeEventsOnChain.map(casting_1.Casting.pools.poolTradeEventFromIndexerOnChain);
|
|
1552
|
-
}
|
|
1553
|
-
catch (e) {
|
|
1554
|
-
return [];
|
|
1555
|
-
}
|
|
1556
|
-
});
|
|
1557
|
-
}
|
|
1558
824
|
}
|
|
1559
825
|
exports.PoolsApi = PoolsApi;
|
|
1560
826
|
// =========================================================================
|
|
@@ -1589,21 +855,3 @@ PoolsApi.constants = {
|
|
|
1589
855
|
},
|
|
1590
856
|
defaultLpCoinIconImageUrl: "https://aftermath.finance/coins/lp/af_lp.svg",
|
|
1591
857
|
};
|
|
1592
|
-
PoolsApi.poolVolumeDataTimeframes = {
|
|
1593
|
-
"1D": {
|
|
1594
|
-
time: 24,
|
|
1595
|
-
timeUnit: "hour",
|
|
1596
|
-
},
|
|
1597
|
-
// "1W": {
|
|
1598
|
-
// time: 7,
|
|
1599
|
-
// timeUnit: "day",
|
|
1600
|
-
// },
|
|
1601
|
-
// "1M": {
|
|
1602
|
-
// time: 30,
|
|
1603
|
-
// timeUnit: "day",
|
|
1604
|
-
// },
|
|
1605
|
-
// "3M": {
|
|
1606
|
-
// time: 90,
|
|
1607
|
-
// timeUnit: "day",
|
|
1608
|
-
// },
|
|
1609
|
-
};
|