Reapply "feat: implement auto-pump mechanism to prevent pool drainage"
This reverts commit fdfba7efd2.
This commit is contained in:
parent
fdfba7efd2
commit
f240b96847
8 changed files with 1727 additions and 29 deletions
|
|
@ -34,6 +34,7 @@
|
|||
: userHolding
|
||||
);
|
||||
let estimatedResult = $derived(calculateEstimate(numericAmount, type, currentPrice));
|
||||
let estimatedAutoPump = $derived(calculateAutoPumpEffects(numericAmount, type, coin));
|
||||
let hasValidAmount = $derived(numericAmount > 0);
|
||||
let userBalance = $derived($PORTFOLIO_DATA ? $PORTFOLIO_DATA.baseCurrencyBalance : 0);
|
||||
let hasEnoughFunds = $derived(
|
||||
|
|
@ -64,6 +65,25 @@
|
|||
}
|
||||
}
|
||||
|
||||
function calculateAutoPumpEffects(amount: number, tradeType: 'BUY' | 'SELL', coinData: any) {
|
||||
if (!amount) return { fee: 0, burn: 0 };
|
||||
|
||||
const pumpFeeRate = Number(coinData.pumpFeeRate || 0.005);
|
||||
const burnRate = Number(coinData.burnRate || 0.001);
|
||||
|
||||
if (tradeType === 'BUY') {
|
||||
const fee = amount * pumpFeeRate;
|
||||
const estimatedTokens = calculateEstimate(amount, tradeType, currentPrice).result;
|
||||
const burn = estimatedTokens * burnRate;
|
||||
return { fee, burn };
|
||||
} else {
|
||||
const estimatedValue = calculateEstimate(amount, tradeType, currentPrice).result;
|
||||
const fee = estimatedValue * pumpFeeRate;
|
||||
const burn = amount * burnRate;
|
||||
return { fee, burn };
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
open = false;
|
||||
amount = '';
|
||||
|
|
@ -183,6 +203,20 @@
|
|||
: `~$${estimatedResult.result.toFixed(6)}`}
|
||||
</span>
|
||||
</div>
|
||||
{#if estimatedAutoPump.fee > 0 || estimatedAutoPump.burn > 0}
|
||||
<div class="border-muted mt-2 border-t pt-2">
|
||||
<div class="text-muted-foreground text-xs">
|
||||
<div class="mb-1 flex items-center justify-between">
|
||||
<span>🔥 Auto-pump fee (0.5%):</span>
|
||||
<span>+${estimatedAutoPump.fee.toFixed(6)} to pool</span>
|
||||
</div>
|
||||
<div class="flex items-center justify-between">
|
||||
<span>🔥 Token burn (0.1%):</span>
|
||||
<span>-{estimatedAutoPump.burn.toFixed(6)} {coin.symbol}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
<p class="text-muted-foreground mt-1 text-xs">
|
||||
AMM estimation - includes slippage from pool impact
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ export const coin = pgTable("coin", {
|
|||
change24h: decimal("change_24h", { precision: 30, scale: 4 }).default("0.0000"), // Percentage
|
||||
poolCoinAmount: decimal("pool_coin_amount", { precision: 30, scale: 8 }).notNull().default("0.00000000"),
|
||||
poolBaseCurrencyAmount: decimal("pool_base_currency_amount", { precision: 30, scale: 8, }).notNull().default("0.00000000"),
|
||||
pumpFeeRate: decimal("pump_fee_rate", { precision: 10, scale: 8 }).notNull().default("0.00500000"), // 0.5%
|
||||
burnRate: decimal("burn_rate", { precision: 10, scale: 8 }).notNull().default("0.00100000"), // 0.1%
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
isListed: boolean("is_listed").default(true).notNull(),
|
||||
|
|
@ -109,6 +111,8 @@ export const transaction = pgTable("transaction", {
|
|||
quantity: decimal("quantity", { precision: 30, scale: 8 }).notNull(),
|
||||
pricePerCoin: decimal("price_per_coin", { precision: 20, scale: 8 }).notNull(),
|
||||
totalBaseCurrencyAmount: decimal("total_base_currency_amount", { precision: 30, scale: 8 }).notNull(),
|
||||
pumpFeeApplied: decimal("pump_fee_applied", { precision: 30, scale: 8 }).default("0.00000000"),
|
||||
tokensBurned: decimal("tokens_burned", { precision: 30, scale: 8 }).default("0.00000000"),
|
||||
timestamp: timestamp("timestamp", { withTimezone: true }).notNull().defaultNow(),
|
||||
recipientUserId: integer('recipient_user_id').references(() => user.id, { onDelete: 'set null' }),
|
||||
senderUserId: integer('sender_user_id').references(() => user.id, { onDelete: 'set null' }),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ export interface CoinData {
|
|||
change24h: number;
|
||||
createdAt: string;
|
||||
creatorName: string | null;
|
||||
pumpFeeRate?: number;
|
||||
burnRate?: number;
|
||||
}
|
||||
|
||||
export interface MarketFilters {
|
||||
|
|
|
|||
Reference in a new issue