@crypticdot/defituna-api 1.1.55 → 1.1.56
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/index.js +58 -63
- package/dist/index.mjs +58 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -588,35 +588,35 @@ var TunaApiClient = class {
|
|
|
588
588
|
/* Endpoints */
|
|
589
589
|
async getMints() {
|
|
590
590
|
const url = this.buildURL("mints");
|
|
591
|
-
return await this.httpRequest(url
|
|
591
|
+
return await this.httpRequest(url, Mint.array());
|
|
592
592
|
}
|
|
593
593
|
async getMint(mintAddress) {
|
|
594
594
|
const url = this.buildURL(`mints/${mintAddress}`);
|
|
595
|
-
return await this.httpRequest(url
|
|
595
|
+
return await this.httpRequest(url, Mint);
|
|
596
596
|
}
|
|
597
597
|
async getMarkets() {
|
|
598
598
|
const url = this.buildURL("markets");
|
|
599
|
-
return await this.httpRequest(url
|
|
599
|
+
return await this.httpRequest(url, Market.array());
|
|
600
600
|
}
|
|
601
601
|
async getMarket(marketAddress) {
|
|
602
602
|
const url = this.buildURL(`markets/${marketAddress}`);
|
|
603
|
-
return await this.httpRequest(url
|
|
603
|
+
return await this.httpRequest(url, Market);
|
|
604
604
|
}
|
|
605
605
|
async getOraclePrices() {
|
|
606
606
|
const url = this.buildURL("oracle-prices");
|
|
607
|
-
return await this.httpRequest(url
|
|
607
|
+
return await this.httpRequest(url, TokenOraclePrice.array());
|
|
608
608
|
}
|
|
609
609
|
async getOraclePrice(mintAddress) {
|
|
610
610
|
const url = this.buildURL(`oracle-prices/${mintAddress}`);
|
|
611
|
-
return await this.httpRequest(url
|
|
611
|
+
return await this.httpRequest(url, TokenOraclePrice);
|
|
612
612
|
}
|
|
613
613
|
async getVaults() {
|
|
614
614
|
const url = this.buildURL("vaults");
|
|
615
|
-
return await this.httpRequest(url
|
|
615
|
+
return await this.httpRequest(url, Vault.array());
|
|
616
616
|
}
|
|
617
617
|
async getVault(vaultAddress) {
|
|
618
618
|
const url = this.buildURL(`vaults/${vaultAddress}`);
|
|
619
|
-
return await this.httpRequest(url
|
|
619
|
+
return await this.httpRequest(url, Vault);
|
|
620
620
|
}
|
|
621
621
|
/**
|
|
622
622
|
* Returns vault historical data for selected time interval.
|
|
@@ -624,137 +624,132 @@ var TunaApiClient = class {
|
|
|
624
624
|
* Example usage: getVaultHistory('H3ifgix98vzi3yCPbmZDLTheeTRf2jykXx8FpY5L7Sfd', '2025-03-10', '2025-04-10')
|
|
625
625
|
*/
|
|
626
626
|
async getVaultHistory(vaultAddress, from, to) {
|
|
627
|
-
const url = this.buildURL(`vaults/${vaultAddress}/history`)
|
|
628
|
-
|
|
629
|
-
|
|
627
|
+
const url = this.appendUrlSearchParams(this.buildURL(`vaults/${vaultAddress}/history`), {
|
|
628
|
+
from: from.toISOString().slice(0, 10),
|
|
629
|
+
to: to.toISOString().slice(0, 10)
|
|
630
|
+
});
|
|
631
|
+
return await this.httpRequest(url, VaultHistoricalStats.array());
|
|
630
632
|
}
|
|
631
633
|
async getPools(providerFilter) {
|
|
632
|
-
const url = this.buildURL("pools")
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
return await this.httpRequest(url.toString(), Pool.array());
|
|
634
|
+
const url = this.appendUrlSearchParams(this.buildURL("pools"), {
|
|
635
|
+
provider: providerFilter && providerFilter !== "all" /* ALL */ ? providerFilter : void 0
|
|
636
|
+
});
|
|
637
|
+
return await this.httpRequest(url, Pool.array());
|
|
637
638
|
}
|
|
638
639
|
async getPool(address) {
|
|
639
640
|
const url = this.buildURL(`pools/${address}`);
|
|
640
|
-
return await this.httpRequest(url
|
|
641
|
+
return await this.httpRequest(url, Pool);
|
|
641
642
|
}
|
|
642
643
|
async getPoolTicks(poolAddress) {
|
|
643
644
|
const url = this.buildURL(`pools/${poolAddress}/ticks`);
|
|
644
|
-
return await this.httpRequest(url
|
|
645
|
+
return await this.httpRequest(url, PoolTicks);
|
|
645
646
|
}
|
|
646
647
|
async getPoolSwaps(poolAddress) {
|
|
647
648
|
const url = this.buildURL(`pools/${poolAddress}/swaps`);
|
|
648
|
-
return await this.httpRequest(url
|
|
649
|
+
return await this.httpRequest(url, PoolSwap.array());
|
|
649
650
|
}
|
|
650
651
|
async getPoolOrderBook(poolAddress, priceStep, inverted) {
|
|
651
|
-
const url = this.buildURL(`pools/${poolAddress}/order-book`)
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
return await this.httpRequest(url.toString(), OrderBook);
|
|
652
|
+
const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/order-book`), {
|
|
653
|
+
price_step: priceStep,
|
|
654
|
+
inverted: inverted || void 0
|
|
655
|
+
});
|
|
656
|
+
return await this.httpRequest(url, OrderBook);
|
|
657
657
|
}
|
|
658
658
|
async getPoolPriceCandles(poolAddress, options) {
|
|
659
659
|
const { from, to, interval, candles } = options;
|
|
660
|
-
const url = this.buildURL(`pools/${poolAddress}/candles`)
|
|
661
|
-
this.appendUrlSearchParams(url, {
|
|
660
|
+
const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/candles`), {
|
|
662
661
|
from: from.toISOString(),
|
|
663
662
|
to: to.toISOString(),
|
|
664
|
-
candles
|
|
663
|
+
candles,
|
|
665
664
|
interval
|
|
666
665
|
});
|
|
667
|
-
return await this.httpRequest(url
|
|
666
|
+
return await this.httpRequest(url, PoolPriceCandle.array());
|
|
668
667
|
}
|
|
669
668
|
async getStakingTreasury() {
|
|
670
669
|
const url = this.buildURL(`staking/treasury`);
|
|
671
|
-
return await this.httpRequest(url
|
|
670
|
+
return await this.httpRequest(url, StakingTreasury);
|
|
672
671
|
}
|
|
673
672
|
async getStakingLeaderboard(page, pageSize, search) {
|
|
674
|
-
const url = this.buildURL(`staking/leaderboard`)
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
...search ? { search } : {}
|
|
673
|
+
const url = this.appendUrlSearchParams(this.buildURL(`staking/leaderboard`), {
|
|
674
|
+
page,
|
|
675
|
+
page_size: pageSize,
|
|
676
|
+
search: search || void 0
|
|
679
677
|
});
|
|
680
|
-
return await this.httpRequest(url
|
|
678
|
+
return await this.httpRequest(url, StakingLeaderboardPage, { parseRoot: true });
|
|
681
679
|
}
|
|
682
680
|
async getUserLendingPositions(userAddress) {
|
|
683
681
|
const url = this.buildURL(`users/${userAddress}/lending-positions`);
|
|
684
|
-
return await this.httpRequest(url
|
|
682
|
+
return await this.httpRequest(url, LendingPosition.array());
|
|
685
683
|
}
|
|
686
684
|
async getUserLendingPositionByAddress(userAddress, lendingPositionAddress) {
|
|
687
685
|
const url = this.buildURL(`users/${userAddress}/lending-positions/${lendingPositionAddress}`);
|
|
688
|
-
return await this.httpRequest(url
|
|
686
|
+
return await this.httpRequest(url, LendingPosition);
|
|
689
687
|
}
|
|
690
688
|
async getUserTunaPositions(userAddress) {
|
|
691
689
|
const url = this.buildURL(`users/${userAddress}/tuna-positions`);
|
|
692
|
-
return await this.httpRequest(url
|
|
690
|
+
return await this.httpRequest(url, TunaPosition.array());
|
|
693
691
|
}
|
|
694
692
|
async getUserTunaPositionByAddress(userAddress, tunaPositionAddress) {
|
|
695
693
|
const url = this.buildURL(`users/${userAddress}/tuna-positions/${tunaPositionAddress}`);
|
|
696
|
-
return await this.httpRequest(url
|
|
694
|
+
return await this.httpRequest(url, TunaPosition);
|
|
697
695
|
}
|
|
698
696
|
async getUserLimitOrders(userAddress, poolFilter) {
|
|
699
|
-
const url = this.buildURL(`users/${userAddress}/limit-orders`)
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return await this.httpRequest(url.toString(), LimitOrder.array());
|
|
697
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), {
|
|
698
|
+
pool: poolFilter || void 0
|
|
699
|
+
});
|
|
700
|
+
return await this.httpRequest(url, LimitOrder.array());
|
|
704
701
|
}
|
|
705
702
|
async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
|
|
706
703
|
const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
|
|
707
|
-
return await this.httpRequest(url
|
|
704
|
+
return await this.httpRequest(url, LimitOrder);
|
|
708
705
|
}
|
|
709
706
|
async getUserStakingPosition(userAddress) {
|
|
710
707
|
const url = this.buildURL(`users/${userAddress}/staking-position`);
|
|
711
|
-
return await this.httpRequest(url
|
|
708
|
+
return await this.httpRequest(url, StakingPosition);
|
|
712
709
|
}
|
|
713
710
|
async getUserStakingPositionHistory(userAddress) {
|
|
714
711
|
const url = this.buildURL(`users/${userAddress}/staking-position/history`);
|
|
715
|
-
return await this.httpRequest(url
|
|
712
|
+
return await this.httpRequest(url, StakingPositionHistoryAction.array());
|
|
716
713
|
}
|
|
717
714
|
async getFeesStats(from, to, interval) {
|
|
718
|
-
const url = this.buildURL(`stats/fees`)
|
|
719
|
-
this.appendUrlSearchParams(url, {
|
|
715
|
+
const url = this.appendUrlSearchParams(this.buildURL(`stats/fees`), {
|
|
720
716
|
from: from.toISOString(),
|
|
721
717
|
to: to.toISOString(),
|
|
722
718
|
interval
|
|
723
719
|
});
|
|
724
|
-
return await this.httpRequest(url
|
|
720
|
+
return await this.httpRequest(url, FeesStatsGroup.array());
|
|
725
721
|
}
|
|
726
722
|
async getStakingRevenueStats(from, to) {
|
|
727
|
-
const url = this.buildURL(`stats/staking/revenue`)
|
|
728
|
-
this.appendUrlSearchParams(url, {
|
|
723
|
+
const url = this.appendUrlSearchParams(this.buildURL(`stats/staking/revenue`), {
|
|
729
724
|
from: from.toISOString().split("T")[0],
|
|
730
725
|
to: to.toISOString().split("T")[0]
|
|
731
726
|
});
|
|
732
|
-
return await this.httpRequest(url
|
|
727
|
+
return await this.httpRequest(url, StakingRevenueStatsGroup.array());
|
|
733
728
|
}
|
|
734
729
|
async getUpdatesStream() {
|
|
735
730
|
const url = this.buildURL(`streams/sse`);
|
|
736
|
-
return new EventSource(url
|
|
731
|
+
return new EventSource(url);
|
|
737
732
|
}
|
|
738
733
|
async updateStreamSubscription(streamId, subscription) {
|
|
739
734
|
const url = this.buildURL(`streams/${streamId}/subscription`);
|
|
740
735
|
const body = JSON.stringify((0, import_snakecase_keys.default)(subscription, { deep: true }));
|
|
741
|
-
return await this.httpRequest(url
|
|
736
|
+
return await this.httpRequest(url, UpdateStreamSubscriptionResult, { method: "PUT", body });
|
|
742
737
|
}
|
|
743
738
|
/* Utility functions */
|
|
744
739
|
buildURL(endpoint) {
|
|
745
|
-
return
|
|
746
|
-
`./v1/${endpoint}`,
|
|
747
|
-
// We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
|
|
748
|
-
// path relative to the parent.
|
|
749
|
-
`${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`
|
|
750
|
-
);
|
|
740
|
+
return `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}v1/${endpoint}`;
|
|
751
741
|
}
|
|
752
742
|
appendUrlSearchParams(url, params) {
|
|
743
|
+
const urlSearchParams = new URLSearchParams();
|
|
753
744
|
Object.entries(params).forEach(([key, value]) => {
|
|
754
745
|
if (value !== void 0) {
|
|
755
|
-
|
|
746
|
+
urlSearchParams.append(key, String(value));
|
|
756
747
|
}
|
|
757
748
|
});
|
|
749
|
+
if (urlSearchParams.size > 0) {
|
|
750
|
+
return `${url}?${urlSearchParams.toString()}`;
|
|
751
|
+
}
|
|
752
|
+
return url;
|
|
758
753
|
}
|
|
759
754
|
};
|
|
760
755
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -553,35 +553,35 @@ var TunaApiClient = class {
|
|
|
553
553
|
/* Endpoints */
|
|
554
554
|
async getMints() {
|
|
555
555
|
const url = this.buildURL("mints");
|
|
556
|
-
return await this.httpRequest(url
|
|
556
|
+
return await this.httpRequest(url, Mint.array());
|
|
557
557
|
}
|
|
558
558
|
async getMint(mintAddress) {
|
|
559
559
|
const url = this.buildURL(`mints/${mintAddress}`);
|
|
560
|
-
return await this.httpRequest(url
|
|
560
|
+
return await this.httpRequest(url, Mint);
|
|
561
561
|
}
|
|
562
562
|
async getMarkets() {
|
|
563
563
|
const url = this.buildURL("markets");
|
|
564
|
-
return await this.httpRequest(url
|
|
564
|
+
return await this.httpRequest(url, Market.array());
|
|
565
565
|
}
|
|
566
566
|
async getMarket(marketAddress) {
|
|
567
567
|
const url = this.buildURL(`markets/${marketAddress}`);
|
|
568
|
-
return await this.httpRequest(url
|
|
568
|
+
return await this.httpRequest(url, Market);
|
|
569
569
|
}
|
|
570
570
|
async getOraclePrices() {
|
|
571
571
|
const url = this.buildURL("oracle-prices");
|
|
572
|
-
return await this.httpRequest(url
|
|
572
|
+
return await this.httpRequest(url, TokenOraclePrice.array());
|
|
573
573
|
}
|
|
574
574
|
async getOraclePrice(mintAddress) {
|
|
575
575
|
const url = this.buildURL(`oracle-prices/${mintAddress}`);
|
|
576
|
-
return await this.httpRequest(url
|
|
576
|
+
return await this.httpRequest(url, TokenOraclePrice);
|
|
577
577
|
}
|
|
578
578
|
async getVaults() {
|
|
579
579
|
const url = this.buildURL("vaults");
|
|
580
|
-
return await this.httpRequest(url
|
|
580
|
+
return await this.httpRequest(url, Vault.array());
|
|
581
581
|
}
|
|
582
582
|
async getVault(vaultAddress) {
|
|
583
583
|
const url = this.buildURL(`vaults/${vaultAddress}`);
|
|
584
|
-
return await this.httpRequest(url
|
|
584
|
+
return await this.httpRequest(url, Vault);
|
|
585
585
|
}
|
|
586
586
|
/**
|
|
587
587
|
* Returns vault historical data for selected time interval.
|
|
@@ -589,137 +589,132 @@ var TunaApiClient = class {
|
|
|
589
589
|
* Example usage: getVaultHistory('H3ifgix98vzi3yCPbmZDLTheeTRf2jykXx8FpY5L7Sfd', '2025-03-10', '2025-04-10')
|
|
590
590
|
*/
|
|
591
591
|
async getVaultHistory(vaultAddress, from, to) {
|
|
592
|
-
const url = this.buildURL(`vaults/${vaultAddress}/history`)
|
|
593
|
-
|
|
594
|
-
|
|
592
|
+
const url = this.appendUrlSearchParams(this.buildURL(`vaults/${vaultAddress}/history`), {
|
|
593
|
+
from: from.toISOString().slice(0, 10),
|
|
594
|
+
to: to.toISOString().slice(0, 10)
|
|
595
|
+
});
|
|
596
|
+
return await this.httpRequest(url, VaultHistoricalStats.array());
|
|
595
597
|
}
|
|
596
598
|
async getPools(providerFilter) {
|
|
597
|
-
const url = this.buildURL("pools")
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
return await this.httpRequest(url.toString(), Pool.array());
|
|
599
|
+
const url = this.appendUrlSearchParams(this.buildURL("pools"), {
|
|
600
|
+
provider: providerFilter && providerFilter !== "all" /* ALL */ ? providerFilter : void 0
|
|
601
|
+
});
|
|
602
|
+
return await this.httpRequest(url, Pool.array());
|
|
602
603
|
}
|
|
603
604
|
async getPool(address) {
|
|
604
605
|
const url = this.buildURL(`pools/${address}`);
|
|
605
|
-
return await this.httpRequest(url
|
|
606
|
+
return await this.httpRequest(url, Pool);
|
|
606
607
|
}
|
|
607
608
|
async getPoolTicks(poolAddress) {
|
|
608
609
|
const url = this.buildURL(`pools/${poolAddress}/ticks`);
|
|
609
|
-
return await this.httpRequest(url
|
|
610
|
+
return await this.httpRequest(url, PoolTicks);
|
|
610
611
|
}
|
|
611
612
|
async getPoolSwaps(poolAddress) {
|
|
612
613
|
const url = this.buildURL(`pools/${poolAddress}/swaps`);
|
|
613
|
-
return await this.httpRequest(url
|
|
614
|
+
return await this.httpRequest(url, PoolSwap.array());
|
|
614
615
|
}
|
|
615
616
|
async getPoolOrderBook(poolAddress, priceStep, inverted) {
|
|
616
|
-
const url = this.buildURL(`pools/${poolAddress}/order-book`)
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
return await this.httpRequest(url.toString(), OrderBook);
|
|
617
|
+
const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/order-book`), {
|
|
618
|
+
price_step: priceStep,
|
|
619
|
+
inverted: inverted || void 0
|
|
620
|
+
});
|
|
621
|
+
return await this.httpRequest(url, OrderBook);
|
|
622
622
|
}
|
|
623
623
|
async getPoolPriceCandles(poolAddress, options) {
|
|
624
624
|
const { from, to, interval, candles } = options;
|
|
625
|
-
const url = this.buildURL(`pools/${poolAddress}/candles`)
|
|
626
|
-
this.appendUrlSearchParams(url, {
|
|
625
|
+
const url = this.appendUrlSearchParams(this.buildURL(`pools/${poolAddress}/candles`), {
|
|
627
626
|
from: from.toISOString(),
|
|
628
627
|
to: to.toISOString(),
|
|
629
|
-
candles
|
|
628
|
+
candles,
|
|
630
629
|
interval
|
|
631
630
|
});
|
|
632
|
-
return await this.httpRequest(url
|
|
631
|
+
return await this.httpRequest(url, PoolPriceCandle.array());
|
|
633
632
|
}
|
|
634
633
|
async getStakingTreasury() {
|
|
635
634
|
const url = this.buildURL(`staking/treasury`);
|
|
636
|
-
return await this.httpRequest(url
|
|
635
|
+
return await this.httpRequest(url, StakingTreasury);
|
|
637
636
|
}
|
|
638
637
|
async getStakingLeaderboard(page, pageSize, search) {
|
|
639
|
-
const url = this.buildURL(`staking/leaderboard`)
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
...search ? { search } : {}
|
|
638
|
+
const url = this.appendUrlSearchParams(this.buildURL(`staking/leaderboard`), {
|
|
639
|
+
page,
|
|
640
|
+
page_size: pageSize,
|
|
641
|
+
search: search || void 0
|
|
644
642
|
});
|
|
645
|
-
return await this.httpRequest(url
|
|
643
|
+
return await this.httpRequest(url, StakingLeaderboardPage, { parseRoot: true });
|
|
646
644
|
}
|
|
647
645
|
async getUserLendingPositions(userAddress) {
|
|
648
646
|
const url = this.buildURL(`users/${userAddress}/lending-positions`);
|
|
649
|
-
return await this.httpRequest(url
|
|
647
|
+
return await this.httpRequest(url, LendingPosition.array());
|
|
650
648
|
}
|
|
651
649
|
async getUserLendingPositionByAddress(userAddress, lendingPositionAddress) {
|
|
652
650
|
const url = this.buildURL(`users/${userAddress}/lending-positions/${lendingPositionAddress}`);
|
|
653
|
-
return await this.httpRequest(url
|
|
651
|
+
return await this.httpRequest(url, LendingPosition);
|
|
654
652
|
}
|
|
655
653
|
async getUserTunaPositions(userAddress) {
|
|
656
654
|
const url = this.buildURL(`users/${userAddress}/tuna-positions`);
|
|
657
|
-
return await this.httpRequest(url
|
|
655
|
+
return await this.httpRequest(url, TunaPosition.array());
|
|
658
656
|
}
|
|
659
657
|
async getUserTunaPositionByAddress(userAddress, tunaPositionAddress) {
|
|
660
658
|
const url = this.buildURL(`users/${userAddress}/tuna-positions/${tunaPositionAddress}`);
|
|
661
|
-
return await this.httpRequest(url
|
|
659
|
+
return await this.httpRequest(url, TunaPosition);
|
|
662
660
|
}
|
|
663
661
|
async getUserLimitOrders(userAddress, poolFilter) {
|
|
664
|
-
const url = this.buildURL(`users/${userAddress}/limit-orders`)
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
return await this.httpRequest(url.toString(), LimitOrder.array());
|
|
662
|
+
const url = this.appendUrlSearchParams(this.buildURL(`users/${userAddress}/limit-orders`), {
|
|
663
|
+
pool: poolFilter || void 0
|
|
664
|
+
});
|
|
665
|
+
return await this.httpRequest(url, LimitOrder.array());
|
|
669
666
|
}
|
|
670
667
|
async getUserLimitOrderByAddress(userAddress, limitOrderAddress) {
|
|
671
668
|
const url = this.buildURL(`users/${userAddress}/limit-orders/${limitOrderAddress}`);
|
|
672
|
-
return await this.httpRequest(url
|
|
669
|
+
return await this.httpRequest(url, LimitOrder);
|
|
673
670
|
}
|
|
674
671
|
async getUserStakingPosition(userAddress) {
|
|
675
672
|
const url = this.buildURL(`users/${userAddress}/staking-position`);
|
|
676
|
-
return await this.httpRequest(url
|
|
673
|
+
return await this.httpRequest(url, StakingPosition);
|
|
677
674
|
}
|
|
678
675
|
async getUserStakingPositionHistory(userAddress) {
|
|
679
676
|
const url = this.buildURL(`users/${userAddress}/staking-position/history`);
|
|
680
|
-
return await this.httpRequest(url
|
|
677
|
+
return await this.httpRequest(url, StakingPositionHistoryAction.array());
|
|
681
678
|
}
|
|
682
679
|
async getFeesStats(from, to, interval) {
|
|
683
|
-
const url = this.buildURL(`stats/fees`)
|
|
684
|
-
this.appendUrlSearchParams(url, {
|
|
680
|
+
const url = this.appendUrlSearchParams(this.buildURL(`stats/fees`), {
|
|
685
681
|
from: from.toISOString(),
|
|
686
682
|
to: to.toISOString(),
|
|
687
683
|
interval
|
|
688
684
|
});
|
|
689
|
-
return await this.httpRequest(url
|
|
685
|
+
return await this.httpRequest(url, FeesStatsGroup.array());
|
|
690
686
|
}
|
|
691
687
|
async getStakingRevenueStats(from, to) {
|
|
692
|
-
const url = this.buildURL(`stats/staking/revenue`)
|
|
693
|
-
this.appendUrlSearchParams(url, {
|
|
688
|
+
const url = this.appendUrlSearchParams(this.buildURL(`stats/staking/revenue`), {
|
|
694
689
|
from: from.toISOString().split("T")[0],
|
|
695
690
|
to: to.toISOString().split("T")[0]
|
|
696
691
|
});
|
|
697
|
-
return await this.httpRequest(url
|
|
692
|
+
return await this.httpRequest(url, StakingRevenueStatsGroup.array());
|
|
698
693
|
}
|
|
699
694
|
async getUpdatesStream() {
|
|
700
695
|
const url = this.buildURL(`streams/sse`);
|
|
701
|
-
return new EventSource(url
|
|
696
|
+
return new EventSource(url);
|
|
702
697
|
}
|
|
703
698
|
async updateStreamSubscription(streamId, subscription) {
|
|
704
699
|
const url = this.buildURL(`streams/${streamId}/subscription`);
|
|
705
700
|
const body = JSON.stringify(snakecaseKeys(subscription, { deep: true }));
|
|
706
|
-
return await this.httpRequest(url
|
|
701
|
+
return await this.httpRequest(url, UpdateStreamSubscriptionResult, { method: "PUT", body });
|
|
707
702
|
}
|
|
708
703
|
/* Utility functions */
|
|
709
704
|
buildURL(endpoint) {
|
|
710
|
-
return
|
|
711
|
-
`./v1/${endpoint}`,
|
|
712
|
-
// We ensure the `baseURL` ends with a `/` so that URL doesn't resolve the
|
|
713
|
-
// path relative to the parent.
|
|
714
|
-
`${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}`
|
|
715
|
-
);
|
|
705
|
+
return `${this.baseURL}${this.baseURL.endsWith("/") ? "" : "/"}v1/${endpoint}`;
|
|
716
706
|
}
|
|
717
707
|
appendUrlSearchParams(url, params) {
|
|
708
|
+
const urlSearchParams = new URLSearchParams();
|
|
718
709
|
Object.entries(params).forEach(([key, value]) => {
|
|
719
710
|
if (value !== void 0) {
|
|
720
|
-
|
|
711
|
+
urlSearchParams.append(key, String(value));
|
|
721
712
|
}
|
|
722
713
|
});
|
|
714
|
+
if (urlSearchParams.size > 0) {
|
|
715
|
+
return `${url}?${urlSearchParams.toString()}`;
|
|
716
|
+
}
|
|
717
|
+
return url;
|
|
723
718
|
}
|
|
724
719
|
};
|
|
725
720
|
export {
|