feat: 添加 YT Asset 合约测试前端
- React + TypeScript + Vite 项目结构 - WalletConnect 钱包连接功能 - WUSD 铸造页面(含边界测试) - Vault 交易页面(买入/卖出 YT,含边界测试) - Factory 管理页面(创建 Vault、更新价格,含权限测试) - 中英文国际化支持 - 显示 Owner/Manager 角色信息 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
649
frontend/src/App.css
Normal file
649
frontend/src/App.css
Normal file
@@ -0,0 +1,649 @@
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background-color: #f5f5f5;
|
||||
color: #333;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.app {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* Header */
|
||||
.header {
|
||||
background: #fff;
|
||||
padding: 16px 24px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.header-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.network-badge {
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.connect-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.address {
|
||||
font-family: monospace;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
background: #f5f5f5;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Navigation */
|
||||
.nav {
|
||||
background: #fff;
|
||||
padding: 0 24px;
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 12px 24px;
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #666;
|
||||
border-bottom: 2px solid transparent;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.nav-btn:hover {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.nav-btn.active {
|
||||
color: #1976d2;
|
||||
border-bottom-color: #1976d2;
|
||||
}
|
||||
|
||||
/* Main */
|
||||
.main {
|
||||
flex: 1;
|
||||
padding: 24px;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Panel */
|
||||
.panel {
|
||||
background: #fff;
|
||||
border-radius: 8px;
|
||||
padding: 24px;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.panel h2 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 20px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.panel h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 16px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* Info Row */
|
||||
.info-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.info-row:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.info-row span {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-row strong {
|
||||
color: #1a1a1a;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.info-row code {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
background: #f5f5f5;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* Form */
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
outline: none;
|
||||
border-color: #1976d2;
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: #1976d2;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background: #1565c0;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
border: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
/* Tabs */
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
margin: 20px 0;
|
||||
background: #f5f5f5;
|
||||
padding: 4px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
padding: 10px 16px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: #fff;
|
||||
color: #1976d2;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Vault Info */
|
||||
.vault-info {
|
||||
background: #f9f9f9;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
text-align: center;
|
||||
padding: 12px;
|
||||
background: #fff;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.info-item span {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.info-item strong {
|
||||
font-size: 14px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
/* Balance Info */
|
||||
.balance-info {
|
||||
background: #e3f2fd;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Trade Section */
|
||||
.trade-section {
|
||||
padding-top: 16px;
|
||||
}
|
||||
|
||||
.preview {
|
||||
background: #f5f5f5;
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
/* Section */
|
||||
.section {
|
||||
margin-top: 24px;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
/* Vault List */
|
||||
.vault-list {
|
||||
background: #f9f9f9;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.vault-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.vault-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.vault-item code {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
.footer {
|
||||
background: #fff;
|
||||
padding: 16px 24px;
|
||||
text-align: center;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.footer p {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* Text States */
|
||||
.text-muted {
|
||||
color: #999;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.success-text {
|
||||
color: #2e7d32;
|
||||
font-size: 14px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.error-text {
|
||||
color: #c62828;
|
||||
font-size: 14px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 640px) {
|
||||
.header {
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.header-info {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.info-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Language Switch */
|
||||
.btn-lang {
|
||||
background: #f5f5f5;
|
||||
color: #333;
|
||||
border: 1px solid #ddd;
|
||||
padding: 6px 12px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.btn-lang:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
|
||||
/* Test Panel Styles */
|
||||
.test-status {
|
||||
background: #f9f9f9;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.test-section {
|
||||
margin-top: 24px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid #e0e0e0;
|
||||
}
|
||||
|
||||
.test-section h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.test-hint {
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
margin-bottom: 16px;
|
||||
padding: 10px 12px;
|
||||
background: #fff8e1;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid #ffc107;
|
||||
}
|
||||
|
||||
.test-hint code {
|
||||
font-family: monospace;
|
||||
font-size: 11px;
|
||||
background: #f5f5f5;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.test-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.test-card {
|
||||
background: #fff;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.test-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.test-name {
|
||||
font-weight: 600;
|
||||
font-size: 14px;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.test-error {
|
||||
font-size: 11px;
|
||||
color: #f57c00;
|
||||
background: #fff3e0;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.test-desc {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.test-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.test-result {
|
||||
font-size: 11px;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
max-width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.test-result.pending {
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
}
|
||||
|
||||
.test-result.success {
|
||||
background: #e8f5e9;
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.test-result.error {
|
||||
background: #ffebee;
|
||||
color: #c62828;
|
||||
}
|
||||
|
||||
/* Button variants */
|
||||
.btn-sm {
|
||||
padding: 6px 14px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background: #ff9800;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-warning:hover:not(:disabled) {
|
||||
background: #f57c00;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: #f44336;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: #d32f2f;
|
||||
}
|
||||
|
||||
/* Form row for side-by-side inputs */
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Quick actions */
|
||||
.quick-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
/* Text color helpers */
|
||||
.text-success {
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.text-warning {
|
||||
color: #f57c00;
|
||||
}
|
||||
|
||||
/* Factory info (reuse for consistency) */
|
||||
.factory-info {
|
||||
background: #f9f9f9;
|
||||
padding: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Section header for collapsible sections */
|
||||
.section-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.section-header h3 {
|
||||
margin: 0;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* Redeem status */
|
||||
.redeem-status {
|
||||
background: #f5f5f5;
|
||||
padding: 12px 16px;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Test result box */
|
||||
.test-result-box {
|
||||
padding: 10px 14px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.test-result-box.pending {
|
||||
background: #e3f2fd;
|
||||
color: #1565c0;
|
||||
}
|
||||
|
||||
.test-result-box.success {
|
||||
background: #e8f5e9;
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.test-result-box.error {
|
||||
background: #ffebee;
|
||||
color: #c62828;
|
||||
}
|
||||
|
||||
/* Role info */
|
||||
.role-info {
|
||||
background: #e8f5e9;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 16px;
|
||||
border: 1px solid #c8e6c9;
|
||||
}
|
||||
|
||||
.role-info .info-row {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.role-info code {
|
||||
font-size: 11px;
|
||||
max-width: 280px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.role-info code.highlight {
|
||||
background: #4caf50;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
}
|
||||
74
frontend/src/App.tsx
Normal file
74
frontend/src/App.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { WagmiProvider } from 'wagmi'
|
||||
import { QueryClientProvider } from '@tanstack/react-query'
|
||||
import { config, queryClient } from './config/wagmi'
|
||||
import { ConnectButton } from './components/ConnectButton'
|
||||
import { LanguageSwitch } from './components/LanguageSwitch'
|
||||
import { WUSDPanel } from './components/WUSDPanel'
|
||||
import { VaultPanel } from './components/VaultPanel'
|
||||
import { FactoryPanel } from './components/FactoryPanel'
|
||||
import './App.css'
|
||||
|
||||
type Tab = 'wusd' | 'vault' | 'factory'
|
||||
|
||||
function AppContent() {
|
||||
const { t } = useTranslation()
|
||||
const [activeTab, setActiveTab] = useState<Tab>('vault')
|
||||
|
||||
return (
|
||||
<div className="app">
|
||||
<header className="header">
|
||||
<h1>{t('header.title')}</h1>
|
||||
<div className="header-info">
|
||||
<LanguageSwitch />
|
||||
<span className="network-badge">{t('common.network')}</span>
|
||||
<ConnectButton />
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<nav className="nav">
|
||||
<button
|
||||
className={`nav-btn ${activeTab === 'wusd' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('wusd')}
|
||||
>
|
||||
{t('nav.wusd')}
|
||||
</button>
|
||||
<button
|
||||
className={`nav-btn ${activeTab === 'vault' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('vault')}
|
||||
>
|
||||
{t('nav.vaultTrading')}
|
||||
</button>
|
||||
<button
|
||||
className={`nav-btn ${activeTab === 'factory' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('factory')}
|
||||
>
|
||||
{t('nav.factory')}
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<main className="main">
|
||||
{activeTab === 'wusd' && <WUSDPanel />}
|
||||
{activeTab === 'vault' && <VaultPanel />}
|
||||
{activeTab === 'factory' && <FactoryPanel />}
|
||||
</main>
|
||||
|
||||
<footer className="footer">
|
||||
<p>{t('footer.description')}</p>
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<WagmiProvider config={config}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AppContent />
|
||||
</QueryClientProvider>
|
||||
</WagmiProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 4.0 KiB |
31
frontend/src/components/ConnectButton.tsx
Normal file
31
frontend/src/components/ConnectButton.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useWeb3Modal } from '@web3modal/wagmi/react'
|
||||
import { useAccount, useDisconnect } from 'wagmi'
|
||||
|
||||
export function ConnectButton() {
|
||||
const { t } = useTranslation()
|
||||
const { open } = useWeb3Modal()
|
||||
const { address, isConnected } = useAccount()
|
||||
const { disconnect } = useDisconnect()
|
||||
|
||||
const formatAddress = (addr: string) => {
|
||||
return `${addr.slice(0, 6)}...${addr.slice(-4)}`
|
||||
}
|
||||
|
||||
if (isConnected && address) {
|
||||
return (
|
||||
<div className="connect-info">
|
||||
<span className="address">{formatAddress(address)}</span>
|
||||
<button onClick={() => disconnect()} className="btn btn-secondary">
|
||||
{t('common.disconnect')}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<button onClick={() => open()} className="btn btn-primary">
|
||||
{t('common.connectWallet')}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
352
frontend/src/components/FactoryPanel.tsx
Normal file
352
frontend/src/components/FactoryPanel.tsx
Normal file
@@ -0,0 +1,352 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useAccount, useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi'
|
||||
import { parseUnits, formatUnits } from 'viem'
|
||||
import { CONTRACTS, FACTORY_ABI, VAULT_ABI } from '../config/contracts'
|
||||
|
||||
export function FactoryPanel() {
|
||||
const { t } = useTranslation()
|
||||
const { address, isConnected } = useAccount()
|
||||
const [createForm, setCreateForm] = useState({
|
||||
name: '',
|
||||
symbol: '',
|
||||
manager: '',
|
||||
hardCap: '',
|
||||
redemptionTime: '',
|
||||
initialWusdPrice: '1',
|
||||
initialYtPrice: '1',
|
||||
})
|
||||
const [priceForm, setPriceForm] = useState({
|
||||
vault: '',
|
||||
wusdPrice: '',
|
||||
ytPrice: '',
|
||||
})
|
||||
const [showPermissionTest, setShowPermissionTest] = useState(false)
|
||||
|
||||
const { data: allVaults, refetch: refetchVaults } = useReadContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'getAllVaults',
|
||||
})
|
||||
|
||||
const { data: vaultCount } = useReadContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'getVaultCount',
|
||||
})
|
||||
|
||||
const { data: owner } = useReadContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'owner',
|
||||
})
|
||||
|
||||
const { data: defaultHardCap } = useReadContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'defaultHardCap',
|
||||
})
|
||||
|
||||
const { writeContract, data: hash, isPending, reset } = useWriteContract()
|
||||
|
||||
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({
|
||||
hash,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
refetchVaults()
|
||||
reset()
|
||||
}
|
||||
}, [isSuccess])
|
||||
|
||||
const handleCreateVault = () => {
|
||||
const redemptionTimestamp = Math.floor(new Date(createForm.redemptionTime).getTime() / 1000)
|
||||
|
||||
writeContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'createVault',
|
||||
args: [
|
||||
createForm.name,
|
||||
createForm.symbol,
|
||||
createForm.manager as `0x${string}`,
|
||||
parseUnits(createForm.hardCap, 18),
|
||||
CONTRACTS.WUSD,
|
||||
BigInt(redemptionTimestamp),
|
||||
parseUnits(createForm.initialWusdPrice, 18),
|
||||
parseUnits(createForm.initialYtPrice, 18),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
const handleUpdatePrices = () => {
|
||||
writeContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'updateVaultPrices',
|
||||
args: [
|
||||
priceForm.vault as `0x${string}`,
|
||||
parseUnits(priceForm.wusdPrice, 18),
|
||||
parseUnits(priceForm.ytPrice, 18),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
// 权限测试函数
|
||||
const runPermissionTest = (testType: string) => {
|
||||
const testVault = allVaults && allVaults.length > 0 ? allVaults[0] : CONTRACTS.VAULTS.YT_A
|
||||
try {
|
||||
switch (testType) {
|
||||
case 'update_price_not_owner':
|
||||
writeContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'updateVaultPrices',
|
||||
args: [testVault as `0x${string}`, parseUnits('1', 18), parseUnits('1', 18)],
|
||||
})
|
||||
break
|
||||
case 'set_manager_not_owner':
|
||||
writeContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'setVaultManager',
|
||||
args: [testVault as `0x${string}`, address as `0x${string}`],
|
||||
})
|
||||
break
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Test error:', err)
|
||||
}
|
||||
}
|
||||
|
||||
const isOwner = address && owner && address.toLowerCase() === owner.toLowerCase()
|
||||
|
||||
if (!isConnected) {
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>{t('factory.title')}</h2>
|
||||
<p className="text-muted">{t('common.connectFirst')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>{t('factory.title')}</h2>
|
||||
|
||||
<div className="factory-info">
|
||||
<div className="info-row">
|
||||
<span>{t('factory.factoryContract')}:</span>
|
||||
<code>{CONTRACTS.FACTORY}</code>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('factory.owner')}:</span>
|
||||
<code>{owner || '-'}</code>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('factory.defaultHardCap')}:</span>
|
||||
<strong>{defaultHardCap ? formatUnits(defaultHardCap, 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('factory.totalVaults')}:</span>
|
||||
<strong>{vaultCount?.toString() || '0'}</strong>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('factory.yourRole')}:</span>
|
||||
<strong>{isOwner ? t('factory.roleOwner') : t('factory.roleUser')}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="section">
|
||||
<h3>{t('factory.allVaults')}</h3>
|
||||
<div className="vault-list">
|
||||
{allVaults && allVaults.length > 0 ? (
|
||||
allVaults.map((vault, index) => (
|
||||
<div key={index} className="vault-item">
|
||||
<span>Vault {index + 1}:</span>
|
||||
<code>{vault}</code>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<p className="text-muted">{t('factory.noVaults')}</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isOwner && (
|
||||
<>
|
||||
<div className="section">
|
||||
<h3>{t('factory.createVault')}</h3>
|
||||
<div className="form-grid">
|
||||
<div className="form-group">
|
||||
<label>{t('factory.name')}</label>
|
||||
<input
|
||||
type="text"
|
||||
value={createForm.name}
|
||||
onChange={(e) => setCreateForm({ ...createForm, name: e.target.value })}
|
||||
placeholder="e.g. YT-D"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.symbol')}</label>
|
||||
<input
|
||||
type="text"
|
||||
value={createForm.symbol}
|
||||
onChange={(e) => setCreateForm({ ...createForm, symbol: e.target.value })}
|
||||
placeholder="e.g. YTD"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.managerAddress')}</label>
|
||||
<input
|
||||
type="text"
|
||||
value={createForm.manager}
|
||||
onChange={(e) => setCreateForm({ ...createForm, manager: e.target.value })}
|
||||
placeholder="0x..."
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('vault.hardCap')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={createForm.hardCap}
|
||||
onChange={(e) => setCreateForm({ ...createForm, hardCap: e.target.value })}
|
||||
placeholder="e.g. 1000000"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.redemptionTime')}</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={createForm.redemptionTime}
|
||||
onChange={(e) => setCreateForm({ ...createForm, redemptionTime: e.target.value })}
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.initialWusdPrice')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={createForm.initialWusdPrice}
|
||||
onChange={(e) => setCreateForm({ ...createForm, initialWusdPrice: e.target.value })}
|
||||
placeholder="1"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.initialYtPrice')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={createForm.initialYtPrice}
|
||||
onChange={(e) => setCreateForm({ ...createForm, initialYtPrice: e.target.value })}
|
||||
placeholder="1"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleCreateVault}
|
||||
disabled={isPending || isConfirming}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{isPending || isConfirming ? t('common.processing') : t('factory.create')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="section">
|
||||
<h3>{t('factory.updatePrices')}</h3>
|
||||
<div className="form-grid">
|
||||
<div className="form-group">
|
||||
<label>{t('factory.vaultAddress')}</label>
|
||||
<select
|
||||
value={priceForm.vault}
|
||||
onChange={(e) => setPriceForm({ ...priceForm, vault: e.target.value })}
|
||||
className="input"
|
||||
>
|
||||
<option value="">{t('factory.selectVault')}</option>
|
||||
{allVaults?.map((vault, index) => (
|
||||
<option key={index} value={vault}>
|
||||
Vault {index + 1}: {vault.slice(0, 10)}...
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.newWusdPrice')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={priceForm.wusdPrice}
|
||||
onChange={(e) => setPriceForm({ ...priceForm, wusdPrice: e.target.value })}
|
||||
placeholder="e.g. 1.05"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label>{t('factory.newYtPrice')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={priceForm.ytPrice}
|
||||
onChange={(e) => setPriceForm({ ...priceForm, ytPrice: e.target.value })}
|
||||
placeholder="e.g. 1.02"
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleUpdatePrices}
|
||||
disabled={isPending || isConfirming || !priceForm.vault}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{isPending || isConfirming ? t('common.processing') : t('factory.update')}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 权限测试区域 */}
|
||||
<div className="section">
|
||||
<div className="section-header" onClick={() => setShowPermissionTest(!showPermissionTest)} style={{ cursor: 'pointer' }}>
|
||||
<h3>{t('test.permissionTests')} {showPermissionTest ? '[-]' : '[+]'}</h3>
|
||||
</div>
|
||||
|
||||
{showPermissionTest && (
|
||||
<>
|
||||
<div className="test-hint">
|
||||
{t('test.permissionHint')}
|
||||
{isOwner && <span style={{ color: '#2e7d32', marginLeft: '8px' }}>(You are Owner)</span>}
|
||||
</div>
|
||||
|
||||
<div className="test-grid">
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.updatePriceNotOwner')}</span>
|
||||
<span className="test-error">OwnableUnauthorizedAccount</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.updatePriceNotOwnerDesc')}</p>
|
||||
<button onClick={() => runPermissionTest('update_price_not_owner')} disabled={isPending || isConfirming} className="btn btn-danger btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.setManagerNotOwner')}</span>
|
||||
<span className="test-error">Forbidden</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.setManagerNotOwnerDesc')}</p>
|
||||
<button onClick={() => runPermissionTest('set_manager_not_owner')} disabled={isPending || isConfirming} className="btn btn-danger btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
16
frontend/src/components/LanguageSwitch.tsx
Normal file
16
frontend/src/components/LanguageSwitch.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
export function LanguageSwitch() {
|
||||
const { i18n } = useTranslation()
|
||||
|
||||
const toggleLanguage = () => {
|
||||
const newLang = i18n.language === 'zh' ? 'en' : 'zh'
|
||||
i18n.changeLanguage(newLang)
|
||||
}
|
||||
|
||||
return (
|
||||
<button onClick={toggleLanguage} className="btn btn-lang">
|
||||
{i18n.language === 'zh' ? 'EN' : '中文'}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
504
frontend/src/components/VaultPanel.tsx
Normal file
504
frontend/src/components/VaultPanel.tsx
Normal file
@@ -0,0 +1,504 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useAccount, useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi'
|
||||
import { parseUnits, formatUnits, maxUint256 } from 'viem'
|
||||
import { CONTRACTS, VAULT_ABI, WUSD_ABI, FACTORY_ABI } from '../config/contracts'
|
||||
|
||||
const VAULTS = [
|
||||
{ name: 'YT-A', address: CONTRACTS.VAULTS.YT_A },
|
||||
{ name: 'YT-B', address: CONTRACTS.VAULTS.YT_B },
|
||||
{ name: 'YT-C', address: CONTRACTS.VAULTS.YT_C },
|
||||
]
|
||||
|
||||
export function VaultPanel() {
|
||||
const { t } = useTranslation()
|
||||
const { address, isConnected } = useAccount()
|
||||
const [selectedVault, setSelectedVault] = useState(VAULTS[0])
|
||||
const [buyAmount, setBuyAmount] = useState('')
|
||||
const [sellAmount, setSellAmount] = useState('')
|
||||
const [activeTab, setActiveTab] = useState<'buy' | 'sell'>('buy')
|
||||
const [showBoundaryTest, setShowBoundaryTest] = useState(false)
|
||||
const [testResult, setTestResult] = useState<{ type: 'success' | 'error' | 'pending', msg: string } | null>(null)
|
||||
|
||||
const { data: vaultInfo, refetch: refetchVaultInfo } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'getVaultInfo',
|
||||
})
|
||||
|
||||
const { data: ytBalance, refetch: refetchYtBalance } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'balanceOf',
|
||||
args: address ? [address] : undefined,
|
||||
})
|
||||
|
||||
const { data: wusdBalance, refetch: refetchWusdBalance } = useReadContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'balanceOf',
|
||||
args: address ? [address] : undefined,
|
||||
})
|
||||
|
||||
const { data: wusdAllowance, refetch: refetchAllowance } = useReadContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'allowance',
|
||||
args: address ? [address, selectedVault.address as `0x${string}`] : undefined,
|
||||
})
|
||||
|
||||
const { data: previewBuyAmount } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'previewBuy',
|
||||
args: buyAmount ? [parseUnits(buyAmount, 18)] : undefined,
|
||||
})
|
||||
|
||||
const { data: previewSellAmount } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'previewSell',
|
||||
args: sellAmount ? [parseUnits(sellAmount, 18)] : undefined,
|
||||
})
|
||||
|
||||
const { data: vaultName } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'name',
|
||||
})
|
||||
|
||||
const { data: vaultSymbol } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'symbol',
|
||||
})
|
||||
|
||||
const { data: canRedeem } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'canRedeemNow',
|
||||
})
|
||||
|
||||
const { data: timeUntilRedeem } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'getTimeUntilNextRedemption',
|
||||
})
|
||||
|
||||
// 读取 Manager 和 Owner 信息
|
||||
const { data: vaultManager } = useReadContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'manager',
|
||||
})
|
||||
|
||||
const { data: factoryOwner } = useReadContract({
|
||||
address: CONTRACTS.FACTORY,
|
||||
abi: FACTORY_ABI,
|
||||
functionName: 'owner',
|
||||
})
|
||||
|
||||
const { writeContract, data: hash, isPending, reset } = useWriteContract()
|
||||
|
||||
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({
|
||||
hash,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
refetchVaultInfo()
|
||||
refetchYtBalance()
|
||||
refetchWusdBalance()
|
||||
refetchAllowance()
|
||||
setBuyAmount('')
|
||||
setSellAmount('')
|
||||
reset()
|
||||
}
|
||||
}, [isSuccess])
|
||||
|
||||
const handleApprove = async () => {
|
||||
if (!buyAmount) return
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'approve',
|
||||
args: [selectedVault.address as `0x${string}`, parseUnits(buyAmount, 18)],
|
||||
})
|
||||
}
|
||||
|
||||
const handleBuy = async () => {
|
||||
if (!buyAmount) return
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'depositYT',
|
||||
args: [parseUnits(buyAmount, 18)],
|
||||
})
|
||||
}
|
||||
|
||||
const handleSell = async () => {
|
||||
if (!sellAmount) return
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'withdrawYT',
|
||||
args: [parseUnits(sellAmount, 18)],
|
||||
})
|
||||
}
|
||||
|
||||
// 边界测试函数
|
||||
const runBoundaryTest = (testType: string) => {
|
||||
setTestResult({ type: 'pending', msg: t('test.running') })
|
||||
try {
|
||||
switch (testType) {
|
||||
case 'buy_zero':
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'depositYT',
|
||||
args: [BigInt(0)],
|
||||
})
|
||||
break
|
||||
case 'sell_zero':
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'withdrawYT',
|
||||
args: [BigInt(0)],
|
||||
})
|
||||
break
|
||||
case 'buy_exceed_balance':
|
||||
const exceedBuy = wusdBalance ? wusdBalance + parseUnits('999999', 18) : parseUnits('999999999', 18)
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'depositYT',
|
||||
args: [exceedBuy],
|
||||
})
|
||||
break
|
||||
case 'sell_exceed_balance':
|
||||
const exceedSell = ytBalance ? ytBalance + parseUnits('999999', 18) : parseUnits('999999999', 18)
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'withdrawYT',
|
||||
args: [exceedSell],
|
||||
})
|
||||
break
|
||||
case 'buy_exceed_hardcap':
|
||||
const hardCap = vaultInfo ? vaultInfo[4] : parseUnits('999999999', 18)
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'depositYT',
|
||||
args: [hardCap + parseUnits('1', 18)],
|
||||
})
|
||||
break
|
||||
case 'sell_in_lock':
|
||||
writeContract({
|
||||
address: selectedVault.address as `0x${string}`,
|
||||
abi: VAULT_ABI,
|
||||
functionName: 'withdrawYT',
|
||||
args: [parseUnits('1', 18)],
|
||||
})
|
||||
break
|
||||
case 'max_approve':
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'approve',
|
||||
args: [selectedVault.address as `0x${string}`, maxUint256],
|
||||
})
|
||||
break
|
||||
}
|
||||
} catch (err: any) {
|
||||
setTestResult({ type: 'error', msg: err.message || 'Error' })
|
||||
}
|
||||
}
|
||||
|
||||
const needsApproval = buyAmount && wusdAllowance !== undefined
|
||||
? parseUnits(buyAmount, 18) > wusdAllowance
|
||||
: false
|
||||
|
||||
if (!isConnected) {
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>{t('vault.title')}</h2>
|
||||
<p className="text-muted">{t('common.connectFirst')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>{t('vault.title')}</h2>
|
||||
|
||||
<div className="form-group">
|
||||
<label>{t('vault.selectVault')}</label>
|
||||
<select
|
||||
value={selectedVault.address}
|
||||
onChange={(e) => {
|
||||
const vault = VAULTS.find(v => v.address === e.target.value)
|
||||
if (vault) setSelectedVault(vault)
|
||||
}}
|
||||
className="input"
|
||||
>
|
||||
{VAULTS.map((vault) => (
|
||||
<option key={vault.address} value={vault.address}>
|
||||
{vault.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="vault-info">
|
||||
<h3>{vaultName || selectedVault.name} ({vaultSymbol || '-'})</h3>
|
||||
<div className="info-grid">
|
||||
<div className="info-item">
|
||||
<span>{t('vault.totalAssets')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[0], 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-item">
|
||||
<span>{t('vault.idleAssets')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[1], 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-item">
|
||||
<span>{t('vault.totalSupply')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[3], 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-item">
|
||||
<span>{t('vault.hardCap')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[4], 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-item">
|
||||
<span>{t('vault.wusdPrice')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[5], 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-item">
|
||||
<span>{t('vault.ytPrice')}</span>
|
||||
<strong>{vaultInfo ? formatUnits(vaultInfo[6], 18) : '0'}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 角色信息 */}
|
||||
<div className="role-info">
|
||||
<div className="info-row">
|
||||
<span>Factory Owner:</span>
|
||||
<code className={address && factoryOwner && address.toLowerCase() === factoryOwner.toLowerCase() ? 'highlight' : ''}>
|
||||
{factoryOwner || '-'}
|
||||
</code>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>Vault Manager:</span>
|
||||
<code className={address && vaultManager && address.toLowerCase() === vaultManager.toLowerCase() ? 'highlight' : ''}>
|
||||
{vaultManager || '-'}
|
||||
</code>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('test.role')}:</span>
|
||||
<strong className={
|
||||
address && factoryOwner && address.toLowerCase() === factoryOwner.toLowerCase() ? 'text-success' :
|
||||
address && vaultManager && address.toLowerCase() === vaultManager.toLowerCase() ? 'text-warning' : ''
|
||||
}>
|
||||
{address && factoryOwner && address.toLowerCase() === factoryOwner.toLowerCase() ? 'Owner' :
|
||||
address && vaultManager && address.toLowerCase() === vaultManager.toLowerCase() ? 'Manager' : 'User'}
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="balance-info">
|
||||
<div className="info-row">
|
||||
<span>{t('vault.yourWusdBalance')}:</span>
|
||||
<strong>{wusdBalance ? formatUnits(wusdBalance, 18) : '0'}</strong>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('vault.yourYtBalance')}:</span>
|
||||
<strong>{ytBalance ? formatUnits(ytBalance, 18) : '0'}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="tabs">
|
||||
<button
|
||||
className={`tab ${activeTab === 'buy' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('buy')}
|
||||
>
|
||||
{t('vault.buyYt')}
|
||||
</button>
|
||||
<button
|
||||
className={`tab ${activeTab === 'sell' ? 'active' : ''}`}
|
||||
onClick={() => setActiveTab('sell')}
|
||||
>
|
||||
{t('vault.sellYt')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{activeTab === 'buy' && (
|
||||
<div className="trade-section">
|
||||
<div className="form-group">
|
||||
<label>{t('vault.wusdAmount')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={buyAmount}
|
||||
onChange={(e) => setBuyAmount(e.target.value)}
|
||||
placeholder={t('vault.enterWusdAmount')}
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
{previewBuyAmount && buyAmount && (
|
||||
<div className="preview">
|
||||
{t('vault.youWillReceive')}: <strong>{formatUnits(previewBuyAmount, 18)} YT</strong>
|
||||
</div>
|
||||
)}
|
||||
{needsApproval ? (
|
||||
<button
|
||||
onClick={handleApprove}
|
||||
disabled={isPending || isConfirming}
|
||||
className="btn btn-secondary"
|
||||
>
|
||||
{isPending || isConfirming ? t('common.processing') : t('vault.approveWusd')}
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleBuy}
|
||||
disabled={isPending || isConfirming || !buyAmount}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{isPending || isConfirming ? t('common.processing') : t('vault.buy')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{activeTab === 'sell' && (
|
||||
<div className="trade-section">
|
||||
<div className="form-group">
|
||||
<label>{t('vault.ytAmount')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={sellAmount}
|
||||
onChange={(e) => setSellAmount(e.target.value)}
|
||||
placeholder={t('vault.enterYtAmount')}
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
{previewSellAmount && sellAmount && (
|
||||
<div className="preview">
|
||||
{t('vault.youWillReceive')}: <strong>{formatUnits(previewSellAmount, 18)} WUSD</strong>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
onClick={handleSell}
|
||||
disabled={isPending || isConfirming || !sellAmount}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{isPending || isConfirming ? t('common.processing') : t('vault.sell')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 边界测试区域 */}
|
||||
<div className="section">
|
||||
<div className="section-header" onClick={() => setShowBoundaryTest(!showBoundaryTest)} style={{ cursor: 'pointer' }}>
|
||||
<h3>{t('test.boundaryTests')} {showBoundaryTest ? '[-]' : '[+]'}</h3>
|
||||
</div>
|
||||
|
||||
{showBoundaryTest && (
|
||||
<>
|
||||
<div className="test-hint">{t('test.boundaryHint')}</div>
|
||||
|
||||
{/* 赎回状态 */}
|
||||
<div className="redeem-status">
|
||||
<span>{t('test.canRedeem')}: </span>
|
||||
<strong className={canRedeem ? 'text-success' : 'text-warning'}>
|
||||
{canRedeem ? t('test.yes') : t('test.no')}
|
||||
</strong>
|
||||
<span style={{ marginLeft: '16px' }}>{t('test.timeToRedeem')}: </span>
|
||||
<strong>{timeUntilRedeem ? `${Number(timeUntilRedeem)}s` : '0s'}</strong>
|
||||
</div>
|
||||
|
||||
<div className="test-grid">
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.buyZero')}</span>
|
||||
<span className="test-error">InvalidAmount</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.buyZeroDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('buy_zero')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.sellZero')}</span>
|
||||
<span className="test-error">InvalidAmount</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.sellZeroDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('sell_zero')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.buyExceedBalance')}</span>
|
||||
<span className="test-error">InsufficientWUSD</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.buyExceedBalanceDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('buy_exceed_balance')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.sellExceedBalance')}</span>
|
||||
<span className="test-error">InsufficientYT</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.sellExceedBalanceDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('sell_exceed_balance')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.buyExceedHardcap')}</span>
|
||||
<span className="test-error">HardCapExceeded</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.buyExceedHardcapDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('buy_exceed_hardcap')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.sellInLock')}</span>
|
||||
<span className="test-error">StillInLockPeriod</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.sellInLockDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('sell_in_lock')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="quick-actions" style={{ marginTop: '16px' }}>
|
||||
<button onClick={() => runBoundaryTest('max_approve')} disabled={isPending || isConfirming} className="btn btn-secondary">
|
||||
{t('test.maxApprove')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{testResult && (
|
||||
<div className={`test-result-box ${testResult.type}`} style={{ marginTop: '12px' }}>
|
||||
{testResult.msg}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
185
frontend/src/components/WUSDPanel.tsx
Normal file
185
frontend/src/components/WUSDPanel.tsx
Normal file
@@ -0,0 +1,185 @@
|
||||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useAccount, useReadContract, useWriteContract, useWaitForTransactionReceipt } from 'wagmi'
|
||||
import { parseUnits, formatUnits } from 'viem'
|
||||
import { CONTRACTS, WUSD_ABI } from '../config/contracts'
|
||||
|
||||
export function WUSDPanel() {
|
||||
const { t } = useTranslation()
|
||||
const { address, isConnected } = useAccount()
|
||||
const [mintAmount, setMintAmount] = useState('')
|
||||
const [showBoundaryTest, setShowBoundaryTest] = useState(false)
|
||||
|
||||
const { data: balance, refetch: refetchBalance } = useReadContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'balanceOf',
|
||||
args: address ? [address] : undefined,
|
||||
})
|
||||
|
||||
const { data: symbol } = useReadContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'symbol',
|
||||
})
|
||||
|
||||
const { data: decimals } = useReadContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'decimals',
|
||||
})
|
||||
|
||||
const { writeContract, data: hash, isPending } = useWriteContract()
|
||||
|
||||
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({
|
||||
hash,
|
||||
})
|
||||
|
||||
const handleMint = async () => {
|
||||
if (!address || !mintAmount || !decimals) return
|
||||
|
||||
try {
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'mint',
|
||||
args: [address, parseUnits(mintAmount, decimals)],
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Mint error:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 边界测试函数
|
||||
const runBoundaryTest = (testType: string) => {
|
||||
if (!address || !decimals) return
|
||||
try {
|
||||
switch (testType) {
|
||||
case 'mint_zero':
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'mint',
|
||||
args: [address, BigInt(0)],
|
||||
})
|
||||
break
|
||||
case 'burn_exceed':
|
||||
const exceedAmount = balance ? balance + parseUnits('999999', decimals) : parseUnits('999999999', decimals)
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'burn',
|
||||
args: [address, exceedAmount],
|
||||
})
|
||||
break
|
||||
case 'mint_10000':
|
||||
writeContract({
|
||||
address: CONTRACTS.WUSD,
|
||||
abi: WUSD_ABI,
|
||||
functionName: 'mint',
|
||||
args: [address, parseUnits('10000', decimals)],
|
||||
})
|
||||
break
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Test error:', err)
|
||||
}
|
||||
}
|
||||
|
||||
if (isSuccess) {
|
||||
refetchBalance()
|
||||
}
|
||||
|
||||
if (!isConnected) {
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>WUSD</h2>
|
||||
<p className="text-muted">{t('common.connectFirst')}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="panel">
|
||||
<h2>{t('wusd.title')}</h2>
|
||||
<div className="info-row">
|
||||
<span>{t('common.contract')}:</span>
|
||||
<code>{CONTRACTS.WUSD}</code>
|
||||
</div>
|
||||
<div className="info-row">
|
||||
<span>{t('common.balance')}:</span>
|
||||
<strong>
|
||||
{balance !== undefined && decimals !== undefined
|
||||
? formatUnits(balance, decimals)
|
||||
: '0'} {symbol || 'WUSD'}
|
||||
</strong>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label>{t('wusd.mintAmount')}</label>
|
||||
<input
|
||||
type="number"
|
||||
value={mintAmount}
|
||||
onChange={(e) => setMintAmount(e.target.value)}
|
||||
placeholder={t('wusd.enterAmount')}
|
||||
className="input"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handleMint}
|
||||
disabled={isPending || isConfirming || !mintAmount}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
{isPending ? t('wusd.confirming') : isConfirming ? t('wusd.minting') : t('wusd.mint')}
|
||||
</button>
|
||||
|
||||
{isSuccess && (
|
||||
<p className="success-text">{t('wusd.mintSuccess')}</p>
|
||||
)}
|
||||
|
||||
{/* 边界测试区域 */}
|
||||
<div className="section">
|
||||
<div className="section-header" onClick={() => setShowBoundaryTest(!showBoundaryTest)} style={{ cursor: 'pointer' }}>
|
||||
<h3>{t('test.boundaryTests')} {showBoundaryTest ? '[-]' : '[+]'}</h3>
|
||||
</div>
|
||||
|
||||
{showBoundaryTest && (
|
||||
<>
|
||||
<div className="test-hint">{t('test.boundaryHint')}</div>
|
||||
|
||||
<div className="test-grid">
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.mintZero')}</span>
|
||||
<span className="test-error">InvalidAmount</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.mintZeroDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('mint_zero')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="test-card">
|
||||
<div className="test-header">
|
||||
<span className="test-name">{t('test.burnExceed')}</span>
|
||||
<span className="test-error">ERC20InsufficientBalance</span>
|
||||
</div>
|
||||
<p className="test-desc">{t('test.burnExceedDesc')}</p>
|
||||
<button onClick={() => runBoundaryTest('burn_exceed')} disabled={isPending || isConfirming} className="btn btn-warning btn-sm">
|
||||
{t('test.run')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="quick-actions" style={{ marginTop: '16px' }}>
|
||||
<button onClick={() => runBoundaryTest('mint_10000')} disabled={isPending || isConfirming} className="btn btn-primary">
|
||||
{t('test.mint10000')}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
510
frontend/src/config/contracts.ts
Normal file
510
frontend/src/config/contracts.ts
Normal file
@@ -0,0 +1,510 @@
|
||||
export const CONTRACTS = {
|
||||
FACTORY: '0x6DaB73519DbaFf23F36FEd24110e2ef5Cfc8aAC9' as const,
|
||||
WUSD: '0x939cf46F7A4d05da2a37213E7379a8b04528F590' as const,
|
||||
VAULTS: {
|
||||
YT_A: '0x0cA35994F033685E7a57ef9bc5d00dd3cf927330' as const,
|
||||
YT_B: '0x333805C9EE75f59Aa2Cc79DfDe2499F920c7b408' as const,
|
||||
YT_C: '0x6DF0ED6f0345F601A206974973dE9fC970598587' as const,
|
||||
}
|
||||
}
|
||||
|
||||
export const FACTORY_ABI = [
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
name: 'allVaults',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'string', name: '_name', type: 'string' },
|
||||
{ internalType: 'string', name: '_symbol', type: 'string' },
|
||||
{ internalType: 'address', name: '_manager', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_hardCap', type: 'uint256' },
|
||||
{ internalType: 'address', name: '_wusd', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_redemptionTime', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_initialWusdPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_initialYtPrice', type: 'uint256' }
|
||||
],
|
||||
name: 'createVault',
|
||||
outputs: [{ internalType: 'address', name: 'vault', type: 'address' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'defaultHardCap',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getAllVaults',
|
||||
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getVaultCount',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: '_vault', type: 'address' }],
|
||||
name: 'getVaultInfo',
|
||||
outputs: [
|
||||
{ internalType: 'bool', name: 'exists', type: 'bool' },
|
||||
{ internalType: 'uint256', name: 'totalAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'idleAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'managedAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'totalSupply', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'hardCap', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'wusdPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'ytPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: 'nextRedemptionTime', type: 'uint256' }
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
name: 'isVault',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'owner',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_defaultHardCap', type: 'uint256' }],
|
||||
name: 'setDefaultHardCap',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_vault', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_hardCap', type: 'uint256' }
|
||||
],
|
||||
name: 'setHardCap',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_vault', type: 'address' },
|
||||
{ internalType: 'address', name: '_manager', type: 'address' }
|
||||
],
|
||||
name: 'setVaultManager',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_vault', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }
|
||||
],
|
||||
name: 'setVaultNextRedemptionTime',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_vault', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_wusdPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_ytPrice', type: 'uint256' }
|
||||
],
|
||||
name: 'updateVaultPrices',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'vaultImplementation',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
}
|
||||
] as const
|
||||
|
||||
export const VAULT_ABI = [
|
||||
{
|
||||
inputs: [],
|
||||
name: 'PRICE_PRECISION',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'owner', type: 'address' },
|
||||
{ internalType: 'address', name: 'spender', type: 'address' }
|
||||
],
|
||||
name: 'allowance',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'approve',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
||||
name: 'balanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'canRedeemNow',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'decimals',
|
||||
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_wusdAmount', type: 'uint256' }],
|
||||
name: 'depositYT',
|
||||
outputs: [{ internalType: 'uint256', name: 'ytAmount', type: 'uint256' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'factory',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getTimeUntilNextRedemption',
|
||||
outputs: [{ internalType: 'uint256', name: 'remainingTime', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'getVaultInfo',
|
||||
outputs: [
|
||||
{ internalType: 'uint256', name: '_totalAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_idleAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_managedAssets', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_totalSupply', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_hardCap', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_wusdPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_ytPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }
|
||||
],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'hardCap',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'idleAssets',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'managedAssets',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'manager',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'name',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'nextRedemptionTime',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_wusdAmount', type: 'uint256' }],
|
||||
name: 'previewBuy',
|
||||
outputs: [{ internalType: 'uint256', name: 'ytAmount', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_ytAmount', type: 'uint256' }],
|
||||
name: 'previewSell',
|
||||
outputs: [{ internalType: 'uint256', name: 'wusdAmount', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'symbol',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalAssets',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalSupply',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'to', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'from', type: 'address' },
|
||||
{ internalType: 'address', name: 'to', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'transferFrom',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_ytAmount', type: 'uint256' }],
|
||||
name: 'withdrawYT',
|
||||
outputs: [{ internalType: 'uint256', name: 'wusdAmount', type: 'uint256' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'wusdAddress',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'wusdPrice',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'ytPrice',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_amount', type: 'uint256' }],
|
||||
name: 'depositManagedAssets',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_to', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'withdrawForManagement',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'uint256', name: '_wusdPrice', type: 'uint256' },
|
||||
{ internalType: 'uint256', name: '_ytPrice', type: 'uint256' }
|
||||
],
|
||||
name: 'updatePrices',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_hardCap', type: 'uint256' }],
|
||||
name: 'setHardCap',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: '_manager', type: 'address' }],
|
||||
name: 'setManager',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'uint256', name: '_nextRedemptionTime', type: 'uint256' }],
|
||||
name: 'setNextRedemptionTime',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const
|
||||
|
||||
export const WUSD_ABI = [
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'owner', type: 'address' },
|
||||
{ internalType: 'address', name: 'spender', type: 'address' }
|
||||
],
|
||||
name: 'allowance',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'spender', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'approve',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
|
||||
name: 'balanceOf',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_from', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'burn',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'decimals',
|
||||
outputs: [{ internalType: 'uint8', name: '', type: 'uint8' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: '_to', type: 'address' },
|
||||
{ internalType: 'uint256', name: '_amount', type: 'uint256' }
|
||||
],
|
||||
name: 'mint',
|
||||
outputs: [],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'name',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'owner',
|
||||
outputs: [{ internalType: 'address', name: '', type: 'address' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'symbol',
|
||||
outputs: [{ internalType: 'string', name: '', type: 'string' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [],
|
||||
name: 'totalSupply',
|
||||
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
||||
stateMutability: 'view',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'to', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
},
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'from', type: 'address' },
|
||||
{ internalType: 'address', name: 'to', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'value', type: 'uint256' }
|
||||
],
|
||||
name: 'transferFrom',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function'
|
||||
}
|
||||
] as const
|
||||
31
frontend/src/config/wagmi.ts
Normal file
31
frontend/src/config/wagmi.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { createWeb3Modal } from '@web3modal/wagmi/react'
|
||||
import { defaultWagmiConfig } from '@web3modal/wagmi/react/config'
|
||||
import { arbitrumSepolia } from 'wagmi/chains'
|
||||
import { QueryClient } from '@tanstack/react-query'
|
||||
|
||||
export const queryClient = new QueryClient()
|
||||
|
||||
// WalletConnect Project ID - 从 https://cloud.walletconnect.com/ 获取
|
||||
const projectId = '3a8170812b534d0ff9d794f19a901d64'
|
||||
|
||||
const metadata = {
|
||||
name: 'YT Asset Test',
|
||||
description: 'YT Asset Contract Testing Interface',
|
||||
url: 'https://maxfight.vip',
|
||||
icons: ['https://avatars.githubusercontent.com/u/37784886']
|
||||
}
|
||||
|
||||
const chains = [arbitrumSepolia] as const
|
||||
|
||||
export const config = defaultWagmiConfig({
|
||||
chains,
|
||||
projectId,
|
||||
metadata,
|
||||
})
|
||||
|
||||
createWeb3Modal({
|
||||
wagmiConfig: config,
|
||||
projectId,
|
||||
enableAnalytics: false,
|
||||
themeMode: 'light',
|
||||
})
|
||||
29
frontend/src/i18n/index.ts
Normal file
29
frontend/src/i18n/index.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import i18n from 'i18next'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
import LanguageDetector from 'i18next-browser-languagedetector'
|
||||
|
||||
import en from './locales/en.json'
|
||||
import zh from './locales/zh.json'
|
||||
|
||||
const resources = {
|
||||
en: { translation: en },
|
||||
zh: { translation: zh }
|
||||
}
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources,
|
||||
fallbackLng: 'en',
|
||||
debug: false,
|
||||
interpolation: {
|
||||
escapeValue: false
|
||||
},
|
||||
detection: {
|
||||
order: ['localStorage', 'navigator'],
|
||||
caches: ['localStorage']
|
||||
}
|
||||
})
|
||||
|
||||
export default i18n
|
||||
135
frontend/src/i18n/locales/en.json
Normal file
135
frontend/src/i18n/locales/en.json
Normal file
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"common": {
|
||||
"connectWallet": "Connect Wallet",
|
||||
"disconnect": "Disconnect",
|
||||
"processing": "Processing...",
|
||||
"confirm": "Confirm",
|
||||
"cancel": "Cancel",
|
||||
"loading": "Loading...",
|
||||
"success": "Success!",
|
||||
"error": "Error",
|
||||
"balance": "Balance",
|
||||
"amount": "Amount",
|
||||
"contract": "Contract",
|
||||
"address": "Address",
|
||||
"network": "Arbitrum Sepolia",
|
||||
"connectFirst": "Please connect wallet first"
|
||||
},
|
||||
"nav": {
|
||||
"wusd": "WUSD",
|
||||
"vaultTrading": "Vault Trading",
|
||||
"factory": "Factory"
|
||||
},
|
||||
"header": {
|
||||
"title": "YT Asset Test"
|
||||
},
|
||||
"footer": {
|
||||
"description": "YT Asset Contract Testing Interface"
|
||||
},
|
||||
"wusd": {
|
||||
"title": "WUSD Token",
|
||||
"mintAmount": "Mint Amount",
|
||||
"enterAmount": "Enter amount to mint",
|
||||
"mint": "Mint WUSD",
|
||||
"minting": "Minting...",
|
||||
"confirming": "Confirming...",
|
||||
"mintSuccess": "Mint successful!"
|
||||
},
|
||||
"vault": {
|
||||
"title": "Vault Trading",
|
||||
"selectVault": "Select Vault",
|
||||
"vaultInfo": "Vault Info",
|
||||
"totalAssets": "Total Assets",
|
||||
"idleAssets": "Idle Assets",
|
||||
"totalSupply": "Total Supply",
|
||||
"hardCap": "Hard Cap",
|
||||
"wusdPrice": "WUSD Price",
|
||||
"ytPrice": "YT Price",
|
||||
"yourWusdBalance": "Your WUSD Balance",
|
||||
"yourYtBalance": "Your YT Balance",
|
||||
"buyYt": "Buy YT",
|
||||
"sellYt": "Sell YT",
|
||||
"wusdAmount": "WUSD Amount",
|
||||
"ytAmount": "YT Amount",
|
||||
"enterWusdAmount": "Enter WUSD amount",
|
||||
"enterYtAmount": "Enter YT amount",
|
||||
"youWillReceive": "You will receive",
|
||||
"approveWusd": "Approve WUSD",
|
||||
"buy": "Buy YT",
|
||||
"sell": "Sell YT"
|
||||
},
|
||||
"factory": {
|
||||
"title": "Factory Management",
|
||||
"factoryContract": "Factory Contract",
|
||||
"owner": "Owner",
|
||||
"defaultHardCap": "Default Hard Cap",
|
||||
"totalVaults": "Total Vaults",
|
||||
"yourRole": "Your Role",
|
||||
"roleOwner": "Owner",
|
||||
"roleUser": "User",
|
||||
"allVaults": "All Vaults",
|
||||
"noVaults": "No vaults created yet",
|
||||
"createVault": "Create New Vault",
|
||||
"name": "Name",
|
||||
"symbol": "Symbol",
|
||||
"managerAddress": "Manager Address",
|
||||
"redemptionTime": "Redemption Time",
|
||||
"initialWusdPrice": "Initial WUSD Price",
|
||||
"initialYtPrice": "Initial YT Price",
|
||||
"create": "Create Vault",
|
||||
"updatePrices": "Update Vault Prices",
|
||||
"vaultAddress": "Vault Address",
|
||||
"selectVault": "Select Vault",
|
||||
"newWusdPrice": "New WUSD Price",
|
||||
"newYtPrice": "New YT Price",
|
||||
"update": "Update Prices"
|
||||
},
|
||||
"language": {
|
||||
"en": "English",
|
||||
"zh": "Chinese"
|
||||
},
|
||||
"test": {
|
||||
"title": "Boundary Test",
|
||||
"currentStatus": "Current Status",
|
||||
"canRedeem": "Can Redeem",
|
||||
"timeToRedeem": "Time to Redeem",
|
||||
"hardCap": "Hard Cap",
|
||||
"role": "Your Role",
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"customAmount": "Custom Amount",
|
||||
"transferAddress": "Transfer Address",
|
||||
"boundaryTests": "Boundary Tests",
|
||||
"boundaryHint": "These tests are designed to trigger contract errors. Expected errors are shown for each test.",
|
||||
"permissionTests": "Permission Tests",
|
||||
"permissionHint": "Test permission restrictions. Should fail if you're not Owner/Manager.",
|
||||
"managerTests": "Manager Functions",
|
||||
"managerHint": "Manager-only functions. Current Manager: ",
|
||||
"normalTests": "Normal Functions",
|
||||
"quickActions": "Quick Actions",
|
||||
"run": "Run",
|
||||
"running": "Running...",
|
||||
"mint10000": "Mint 10000 WUSD",
|
||||
"maxApprove": "Max Approve WUSD",
|
||||
"buyZero": "Buy Amount 0",
|
||||
"buyZeroDesc": "Test depositYT(0)",
|
||||
"sellZero": "Sell Amount 0",
|
||||
"sellZeroDesc": "Test withdrawYT(0)",
|
||||
"buyExceedBalance": "Buy Exceed Balance",
|
||||
"buyExceedBalanceDesc": "Buy more than WUSD balance",
|
||||
"sellExceedBalance": "Sell Exceed Balance",
|
||||
"sellExceedBalanceDesc": "Sell more than YT balance",
|
||||
"buyExceedHardcap": "Buy Exceed Hardcap",
|
||||
"buyExceedHardcapDesc": "Buy amount exceeds vault hardcap",
|
||||
"sellInLock": "Sell In Lock Period",
|
||||
"sellInLockDesc": "Try to sell during lock period",
|
||||
"mintZero": "Mint Amount 0",
|
||||
"mintZeroDesc": "Test mint(0)",
|
||||
"burnExceed": "Burn Exceed Balance",
|
||||
"burnExceedDesc": "Burn more than balance",
|
||||
"updatePriceNotOwner": "Update Price (Not Owner)",
|
||||
"updatePriceNotOwnerDesc": "Non-owner calls updateVaultPrices",
|
||||
"setManagerNotOwner": "Set Manager (Not Owner)",
|
||||
"setManagerNotOwnerDesc": "Non-owner calls setVaultManager"
|
||||
}
|
||||
}
|
||||
135
frontend/src/i18n/locales/zh.json
Normal file
135
frontend/src/i18n/locales/zh.json
Normal file
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"common": {
|
||||
"connectWallet": "连接钱包",
|
||||
"disconnect": "断开连接",
|
||||
"processing": "处理中...",
|
||||
"confirm": "确认",
|
||||
"cancel": "取消",
|
||||
"loading": "加载中...",
|
||||
"success": "成功!",
|
||||
"error": "错误",
|
||||
"balance": "余额",
|
||||
"amount": "数量",
|
||||
"contract": "合约",
|
||||
"address": "地址",
|
||||
"network": "Arbitrum Sepolia",
|
||||
"connectFirst": "请先连接钱包"
|
||||
},
|
||||
"nav": {
|
||||
"wusd": "WUSD",
|
||||
"vaultTrading": "金库交易",
|
||||
"factory": "工厂管理"
|
||||
},
|
||||
"header": {
|
||||
"title": "YT 资产测试"
|
||||
},
|
||||
"footer": {
|
||||
"description": "YT 资产合约测试界面"
|
||||
},
|
||||
"wusd": {
|
||||
"title": "WUSD 代币",
|
||||
"mintAmount": "铸造数量",
|
||||
"enterAmount": "输入铸造数量",
|
||||
"mint": "铸造 WUSD",
|
||||
"minting": "铸造中...",
|
||||
"confirming": "确认中...",
|
||||
"mintSuccess": "铸造成功!"
|
||||
},
|
||||
"vault": {
|
||||
"title": "金库交易",
|
||||
"selectVault": "选择金库",
|
||||
"vaultInfo": "金库信息",
|
||||
"totalAssets": "总资产",
|
||||
"idleAssets": "闲置资产",
|
||||
"totalSupply": "总供应量",
|
||||
"hardCap": "硬顶",
|
||||
"wusdPrice": "WUSD 价格",
|
||||
"ytPrice": "YT 价格",
|
||||
"yourWusdBalance": "你的 WUSD 余额",
|
||||
"yourYtBalance": "你的 YT 余额",
|
||||
"buyYt": "买入 YT",
|
||||
"sellYt": "卖出 YT",
|
||||
"wusdAmount": "WUSD 数量",
|
||||
"ytAmount": "YT 数量",
|
||||
"enterWusdAmount": "输入 WUSD 数量",
|
||||
"enterYtAmount": "输入 YT 数量",
|
||||
"youWillReceive": "你将收到",
|
||||
"approveWusd": "授权 WUSD",
|
||||
"buy": "买入 YT",
|
||||
"sell": "卖出 YT"
|
||||
},
|
||||
"factory": {
|
||||
"title": "工厂管理",
|
||||
"factoryContract": "工厂合约",
|
||||
"owner": "所有者",
|
||||
"defaultHardCap": "默认硬顶",
|
||||
"totalVaults": "金库总数",
|
||||
"yourRole": "你的角色",
|
||||
"roleOwner": "所有者",
|
||||
"roleUser": "用户",
|
||||
"allVaults": "所有金库",
|
||||
"noVaults": "暂无金库",
|
||||
"createVault": "创建新金库",
|
||||
"name": "名称",
|
||||
"symbol": "符号",
|
||||
"managerAddress": "管理员地址",
|
||||
"redemptionTime": "赎回时间",
|
||||
"initialWusdPrice": "初始 WUSD 价格",
|
||||
"initialYtPrice": "初始 YT 价格",
|
||||
"create": "创建金库",
|
||||
"updatePrices": "更新金库价格",
|
||||
"vaultAddress": "金库地址",
|
||||
"selectVault": "选择金库",
|
||||
"newWusdPrice": "新 WUSD 价格",
|
||||
"newYtPrice": "新 YT 价格",
|
||||
"update": "更新价格"
|
||||
},
|
||||
"language": {
|
||||
"en": "英文",
|
||||
"zh": "中文"
|
||||
},
|
||||
"test": {
|
||||
"title": "边界测试",
|
||||
"currentStatus": "当前状态",
|
||||
"canRedeem": "可赎回",
|
||||
"timeToRedeem": "赎回倒计时",
|
||||
"hardCap": "硬顶",
|
||||
"role": "你的角色",
|
||||
"yes": "是",
|
||||
"no": "否",
|
||||
"customAmount": "自定义金额",
|
||||
"transferAddress": "转账地址",
|
||||
"boundaryTests": "边界测试",
|
||||
"boundaryHint": "这些测试旨在触发合约错误。每个测试都显示了预期的错误。",
|
||||
"permissionTests": "权限测试",
|
||||
"permissionHint": "测试权限限制。如果你不是 Owner/Manager 应该会失败。",
|
||||
"managerTests": "Manager 功能",
|
||||
"managerHint": "仅限 Manager 的功能。当前 Manager: ",
|
||||
"normalTests": "正常功能",
|
||||
"quickActions": "快速操作",
|
||||
"run": "执行",
|
||||
"running": "执行中...",
|
||||
"mint10000": "铸造 10000 WUSD",
|
||||
"maxApprove": "最大授权 WUSD",
|
||||
"buyZero": "买入金额为0",
|
||||
"buyZeroDesc": "测试 depositYT(0)",
|
||||
"sellZero": "卖出金额为0",
|
||||
"sellZeroDesc": "测试 withdrawYT(0)",
|
||||
"buyExceedBalance": "买入超过余额",
|
||||
"buyExceedBalanceDesc": "买入金额超过 WUSD 余额",
|
||||
"sellExceedBalance": "卖出超过余额",
|
||||
"sellExceedBalanceDesc": "卖出金额超过 YT 余额",
|
||||
"buyExceedHardcap": "买入超过硬顶",
|
||||
"buyExceedHardcapDesc": "买入金额超过 Vault 硬顶",
|
||||
"sellInLock": "锁定期卖出",
|
||||
"sellInLockDesc": "在锁定期内尝试卖出",
|
||||
"mintZero": "铸造金额为0",
|
||||
"mintZeroDesc": "测试 mint(0)",
|
||||
"burnExceed": "销毁超过余额",
|
||||
"burnExceedDesc": "销毁金额超过余额",
|
||||
"updatePriceNotOwner": "更新价格(非Owner)",
|
||||
"updatePriceNotOwnerDesc": "非 Owner 调用 updateVaultPrices",
|
||||
"setManagerNotOwner": "设置Manager(非Owner)",
|
||||
"setManagerNotOwnerDesc": "非 Owner 调用 setVaultManager"
|
||||
}
|
||||
}
|
||||
22
frontend/src/index.css
Normal file
22
frontend/src/index.css
Normal file
@@ -0,0 +1,22 @@
|
||||
:root {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
line-height: 1.6;
|
||||
font-weight: 400;
|
||||
color-scheme: light;
|
||||
color: #333;
|
||||
background-color: #f5f5f5;
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
#root {
|
||||
min-height: 100vh;
|
||||
}
|
||||
11
frontend/src/main.tsx
Normal file
11
frontend/src/main.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './i18n'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
||||
Reference in New Issue
Block a user