diff --git a/src/api/pool.js b/src/api/pool.js index 03bf4d3..30cdb69 100644 --- a/src/api/pool.js +++ b/src/api/pool.js @@ -1,8 +1,8 @@ import { get } from 'svelte/store' -import { CURRENCY_DECIMALS, BPS_DIVIDER } from '@lib/config' +import { CURRENCY_DECIMALS, BPS_DIVIDER, DEFAULT_POOL_TRANSACTIONS_COUNT } from '@lib/config' import { getContract } from '@lib/contracts' import { formatUnits, parseUnits } from '@lib/formatters' -import { address, poolBalances, bufferBalances, poolStakes, poolStatsDaily, poolStatsWeekly, poolWithdrawalFees, poolDepositTaxes, poolWithdrawalTaxes, globalUPLs } from '@lib/stores' +import { address, poolBalances, bufferBalances, poolStakes, poolStatsDaily, poolStatsWeekly, poolWithdrawalFees, poolDepositTaxes, poolWithdrawalTaxes, globalUPLs, poolTransactions, lastPoolTransactionsCount } from '@lib/stores' import { getAssetAddress, getAssetAddresses, getLabelForAsset, getChainData } from '@lib/utils' import { showToast, showError } from '@lib/ui' @@ -131,3 +131,42 @@ export async function withdraw(_asset, _amount) { showError(e); } } + +export async function getPoolTransactions(params) { + const dataEndpoint = getChainData('dataEndpoint'); + if (!dataEndpoint) return false; + + if (!params) params = {}; + + let { + first, + skip + } = params; + + if (!first) first = DEFAULT_POOL_TRANSACTIONS_COUNT; + if (!skip) skip = 0; + + try { + const response = await fetch(`${dataEndpoint}/pool/transactions?chain=arbitrum&limit=${first}&skip=${skip}`); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + + const data = await response.json() || []; + const transactions = Array.isArray(data) ? data : data.transactions || []; + lastPoolTransactionsCount.set(transactions.length); + + if (skip) { + let currentTransactions = get(poolTransactions); + poolTransactions.set(currentTransactions.concat(transactions)); + } else { + poolTransactions.set(transactions); + } + + return true; + } catch(e) { + console.error('/pool/transactions GET error', params, e); + lastPoolTransactionsCount.set(0); + if (!skip) poolTransactions.set([]); + } + + return false; +} diff --git a/src/components/pool/Pool.svelte b/src/components/pool/Pool.svelte index 7bc1f66..2bcd2b0 100644 --- a/src/components/pool/Pool.svelte +++ b/src/components/pool/Pool.svelte @@ -1,6 +1,7 @@ @@ -15,5 +16,6 @@
+ -
\ No newline at end of file + diff --git a/src/components/pool/PoolTransactions.svelte b/src/components/pool/PoolTransactions.svelte new file mode 100644 index 0000000..71659c3 --- /dev/null +++ b/src/components/pool/PoolTransactions.svelte @@ -0,0 +1,315 @@ + + + + +
+
+
Pool Transactions
+
Latest deposits, withdrawals, pay ins, and payouts across all pools.
+
+ +
+
+
+
+
Type
+
Asset
+
Amount
+
Pool Balance
+
Buffer
+
Market / User
+
Time
+
Tx
+
+ +
+ {#if isLoading} +
{@html LOADING_ICON}
+ {:else if $poolTransactions.length == 0} +
No pool transactions found.
+ {:else} + {#each $poolTransactions as transaction} +
+
+ {getTypeLabel(transaction.type)} +
+
{getAssetLabel(transaction.asset)}
+
{formatAmount(transaction.amount)}
+
{formatAmount(transaction.poolBalance)}
+
{formatAmount(transaction.bufferBalance)}
+
+ + {#if transaction.market} + {formatMarketName(transaction.market)} +
+ {/if} + {#if transaction.user} + {shortAddress(transaction.user)} + {:else} + - + {/if} +
+
+
{formatDate(transaction.timestamp) || '-'}
+
+ {#if getTransactionHash(transaction)} + View + {:else} + - + {/if} +
+
+ {/each} + + {#if loadingMore} +
{@html LOADING_ICON}
+ {/if} + {/if} +
+
+
+
+
diff --git a/src/lib/config.js b/src/lib/config.js index dbb9e15..44c550d 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -27,6 +27,8 @@ export const DEFAULT_HISTORY_SORT_KEY = ['timestamp', true]; export const DEFAULT_HISTORY_COUNT = 50; +export const DEFAULT_POOL_TRANSACTIONS_COUNT = 50; + export const EXCLUDED_MARKETS = []; // ['HSI', 'KOSPI', 'USD-CNY', 'USD-JPY', 'USD-KRW', 'WTI-USD', 'XBR-USD', 'SPX500', 'DJI', 'NASDAQ', 'FTSE', 'DAX', 'NIKKEI', 'ASX200']; // dead and non chainlink markets, in private beta only export const CURRENCY_DECIMALS = { @@ -127,4 +129,4 @@ export const CHAINDATA = { ETH: ADDRESS_ZERO } } -} \ No newline at end of file +} diff --git a/src/lib/stores.js b/src/lib/stores.js index d5761f7..7863705 100644 --- a/src/lib/stores.js +++ b/src/lib/stores.js @@ -68,6 +68,8 @@ export const poolWithdrawalFees = writable({}); export const claimableRewardsCAP = writable({}); export const totalSupplyCAP = writable(0); export const CAPStake = writable(0); +export const poolTransactions = writable([]); +export const lastPoolTransactionsCount = writable(0); // Pool performance stats (including fees) function getPoolPerformance(stats, latestIndex, oldestIndex) {