mirror of
https://github.com/pezkuwichain/pwap.git
synced 2026-06-13 04:21:03 +00:00
feat: add CoinGecko price logic with DOT-based fallback
- HEZ price: CoinGecko direct > DOT/3 > DEX pool - PEZ price: CoinGecko direct > DOT/10 > DEX pool - Added AuthorizeCall signed extension for blockchain connection - Updated @pezkuwi packages to 16.5.22 and 14.0.13
This commit is contained in:
Generated
+518
-498
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,5 @@
|
|||||||
"STYLE GUIDE": "contributor/STYLE_GUIDE.md",
|
"STYLE GUIDE": "contributor/STYLE_GUIDE.md",
|
||||||
"Weight Generation": "contributor/weight-generation.md"
|
"Weight Generation": "contributor/weight-generation.md"
|
||||||
},
|
},
|
||||||
"README": "README.md",
|
"README": "README.md"
|
||||||
"REBRAND PROGRESS": "REBRAND_PROGRESS.md"
|
|
||||||
}
|
}
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# HARİÇ TUTULACAK KLASÖRLER
|
|
||||||
EXCLUDE_DIRS = {'crate_placeholders', '.git', 'target', 'node_modules', '__pycache__'}
|
|
||||||
|
|
||||||
# Düzeltilecek Kalıplar ve Yerine Geçecek Değerler
|
|
||||||
# Tekrar eden önekleri temizler.
|
|
||||||
REPLACEMENT_MAP = {
|
|
||||||
"pezpez": "pez",
|
|
||||||
"Pezpez": "Pez",
|
|
||||||
"PEZPEZ": "PEZ",
|
|
||||||
"PeZPeZ": "PeZ",
|
|
||||||
"pezPez": "pez",
|
|
||||||
"PEZpez": "PEZ",
|
|
||||||
}
|
|
||||||
|
|
||||||
def is_path_excluded(path):
|
|
||||||
"""Verilen yolun yasaklı bir klasörün içinde olup olmadığını kontrol eder."""
|
|
||||||
parts = path.split(os.sep)
|
|
||||||
return any(excluded in parts for excluded in EXCLUDE_DIRS)
|
|
||||||
|
|
||||||
def fix_double_prefix(text):
|
|
||||||
"""Metin içindeki çift PEZ öneklerini tek PEZ önekiyle değiştirir."""
|
|
||||||
for old_prefix, new_prefix in REPLACEMENT_MAP.items():
|
|
||||||
text = text.replace(old_prefix, new_prefix)
|
|
||||||
return text
|
|
||||||
|
|
||||||
def process_content_updates(root_dir):
|
|
||||||
"""Belirtilen dizin altındaki tüm hedef dosyaların içeriğini günceller."""
|
|
||||||
# Sadece .rs ve .toml gibi kod dosyalarını hedefleyelim.
|
|
||||||
TARGET_EXTENSIONS = ('.rs', '.toml', '.md', '.txt', '.yml', '.yaml', '.json', '.py')
|
|
||||||
|
|
||||||
print("--- Adım 1: Dosya İçeriklerinde Çift Önek Düzeltme ---")
|
|
||||||
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=True):
|
|
||||||
dirnames[:] = [d for d in dirnames if d not in EXCLUDE_DIRS]
|
|
||||||
if is_path_excluded(dirpath):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for filename in filenames:
|
|
||||||
if filename.endswith(TARGET_EXTENSIONS) or filename == 'Cargo.lock':
|
|
||||||
filepath = os.path.join(dirpath, filename)
|
|
||||||
|
|
||||||
if os.path.basename(filepath) == os.path.basename(sys.argv[0]):
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
|
||||||
content = f.read()
|
|
||||||
|
|
||||||
original_content = content
|
|
||||||
content = fix_double_prefix(content)
|
|
||||||
|
|
||||||
if content != original_content:
|
|
||||||
with open(filepath, 'w', encoding='utf-8') as f:
|
|
||||||
f.write(content)
|
|
||||||
print(f" [İÇERİK DÜZELTİLDİ] Dosya içeriği: {filepath}")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f" [HATA] İçerik düzeltilirken: {filepath} -> {e}")
|
|
||||||
|
|
||||||
def rename_pezpez_paths(root_dir):
|
|
||||||
"""Dosya ve klasör adlarında geçen 'pezpez' önekini 'pez' olarak düzeltir (bottom-up)."""
|
|
||||||
|
|
||||||
# 2. Klasör İsimlerini Düzelt (topdown=False, en alttan yukarı güvenli işlem)
|
|
||||||
print("\n--- Adım 2: Klasör İsimlerinin Düzeltilmesi (pezpez -> pez) ---")
|
|
||||||
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=False):
|
|
||||||
|
|
||||||
if any(excluded in dirpath.split(os.sep) for excluded in EXCLUDE_DIRS):
|
|
||||||
continue
|
|
||||||
|
|
||||||
dirname = os.path.basename(dirpath)
|
|
||||||
original_dirname = dirname
|
|
||||||
new_dirname = fix_double_prefix(dirname)
|
|
||||||
|
|
||||||
if new_dirname != original_dirname:
|
|
||||||
old_path = dirpath
|
|
||||||
new_path = os.path.join(os.path.dirname(dirpath), new_dirname)
|
|
||||||
|
|
||||||
if os.path.exists(old_path) and not os.path.exists(new_path):
|
|
||||||
try:
|
|
||||||
os.rename(old_path, new_path)
|
|
||||||
print(f" [RENAME-DIR] {original_dirname} -> {new_dirname}")
|
|
||||||
except OSError as e:
|
|
||||||
print(f" [HATA] Klasör adlandırılamadı {original_dirname}: {e}")
|
|
||||||
|
|
||||||
# 3. Dosya İsimlerini Düzelt (topdown=True, kökten aşağı)
|
|
||||||
print("\n--- Adım 3: Dosya İsimlerinin Düzeltilmesi (pezpez -> pez) ---")
|
|
||||||
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=True):
|
|
||||||
|
|
||||||
dirnames[:] = [d for d in dirnames if d not in EXCLUDE_DIRS]
|
|
||||||
if is_path_excluded(dirpath):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for filename in filenames:
|
|
||||||
original_filename = filename
|
|
||||||
new_filename = fix_double_prefix(filename)
|
|
||||||
|
|
||||||
if new_filename != original_filename:
|
|
||||||
old_path = os.path.join(dirpath, original_filename)
|
|
||||||
new_path = os.path.join(dirpath, new_filename)
|
|
||||||
|
|
||||||
if os.path.exists(old_path) and not os.path.exists(new_path):
|
|
||||||
try:
|
|
||||||
os.rename(old_path, new_path)
|
|
||||||
print(f" [RENAME-FILE] {original_filename} -> {new_filename}")
|
|
||||||
except OSError as e:
|
|
||||||
print(f" [HATA] Dosya adlandırılamadı {original_filename}: {e}")
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
root_dir = os.getcwd()
|
|
||||||
print("==================================================")
|
|
||||||
print(f"🔧 PEZPEZ DÜZELTME (İçerik ve Ad) İşlemi Başlatılıyor...")
|
|
||||||
print(f"⚠️ Çalışma Dizini: {root_dir}")
|
|
||||||
print("==================================================")
|
|
||||||
|
|
||||||
# Önce içerikleri düzelt (dosya yolları değişmeden)
|
|
||||||
process_content_updates(root_dir)
|
|
||||||
|
|
||||||
# Ardından dosya ve klasör adlarını düzelt
|
|
||||||
rename_pezpez_paths(root_dir)
|
|
||||||
|
|
||||||
print("\n✅ PEZPEZ Düzeltme işlemi tamamlandı.")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# HARİÇ TUTULACAK KLASÖRLER
|
|
||||||
EXCLUDE_DIRS = {'crate_placeholders', '.git', 'target', 'node_modules', '__pycache__'}
|
|
||||||
|
|
||||||
# Yeniden adlandırma haritası (Basit: sadece 'pallet'in önüne 'pez' ekle)
|
|
||||||
RENAME_MAP = {
|
|
||||||
# Tireli (kebab-case) isimlendirmeler için
|
|
||||||
"pallet-": "pezpallet-",
|
|
||||||
# Alt çizgili (snake_case) isimlendirmeler için
|
|
||||||
"pallet_": "pezpallet_",
|
|
||||||
}
|
|
||||||
|
|
||||||
# Not: Bu betik, 'Pallet-' veya 'PALLET-' gibi büyük harf varyasyonlarını dosya sisteminde
|
|
||||||
# (çoğunlukla küçük harf veya tireli kullanılan) adreslemeyebilir, ancak en yaygın olanları hedefler.
|
|
||||||
|
|
||||||
def is_path_excluded(path):
|
|
||||||
"""Verilen yolun yasaklı bir klasörün içinde olup olmadığını kontrol eder."""
|
|
||||||
parts = path.split(os.sep)
|
|
||||||
return any(excluded in parts for excluded in EXCLUDE_DIRS)
|
|
||||||
|
|
||||||
def rename_paths(root_dir):
|
|
||||||
"""
|
|
||||||
Dosya ve klasör adlarında geçen 'pallet' önekini 'pezpallet' olarak değiştirir.
|
|
||||||
Bottom-up (en alttan yukarı) yaklaşımıyla klasör adlarını güvenli bir şekilde değiştirir.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Adım 1: Dosya İsimlerini Düzelt (topdown=True, kökten aşağı)
|
|
||||||
print("--- Adım 1: Dosya İsimlerinin Güncellenmesi (pallet -> pezpallet) ---")
|
|
||||||
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=True):
|
|
||||||
|
|
||||||
# Yasaklı klasörleri atla
|
|
||||||
dirnames[:] = [d for d in dirnames if d not in EXCLUDE_DIRS]
|
|
||||||
if any(excluded in dirpath.split(os.sep) for excluded in EXCLUDE_DIRS):
|
|
||||||
continue
|
|
||||||
|
|
||||||
for filename in filenames:
|
|
||||||
original_filename = filename
|
|
||||||
new_filename = filename
|
|
||||||
|
|
||||||
for old_prefix, new_prefix in RENAME_MAP.items():
|
|
||||||
if old_prefix in new_filename:
|
|
||||||
# Basit string değiştirme, pez yaratma riskini taşıyoruz.
|
|
||||||
new_filename = new_filename.replace(old_prefix, new_prefix)
|
|
||||||
|
|
||||||
if new_filename != original_filename:
|
|
||||||
old_path = os.path.join(dirpath, original_filename)
|
|
||||||
new_path = os.path.join(dirpath, new_filename)
|
|
||||||
|
|
||||||
if os.path.exists(old_path) and not os.path.exists(new_path):
|
|
||||||
try:
|
|
||||||
os.rename(old_path, new_path)
|
|
||||||
print(f" [RENAME-FILE] {original_filename} -> {new_filename}")
|
|
||||||
except OSError as e:
|
|
||||||
print(f" [HATA] Dosya adlandırılamadı {original_filename}: {e}")
|
|
||||||
|
|
||||||
# Adım 2: Klasör İsimlerini Düzelt (topdown=False, en alttan yukarı güvenli işlem)
|
|
||||||
print("\n--- Adım 2: Klasör İsimlerinin Güncellenmesi (pallet -> pezpallet) ---")
|
|
||||||
for dirpath, dirnames, filenames in os.walk(root_dir, topdown=False):
|
|
||||||
|
|
||||||
if any(excluded in dirpath.split(os.sep) for excluded in EXCLUDE_DIRS):
|
|
||||||
continue
|
|
||||||
|
|
||||||
dirname = os.path.basename(dirpath)
|
|
||||||
original_dirname = dirname
|
|
||||||
new_dirname = dirname
|
|
||||||
|
|
||||||
for old_prefix, new_prefix in RENAME_MAP.items():
|
|
||||||
if old_prefix in new_dirname:
|
|
||||||
new_dirname = new_dirname.replace(old_prefix, new_prefix)
|
|
||||||
|
|
||||||
if new_dirname != original_dirname:
|
|
||||||
old_path = dirpath
|
|
||||||
new_path = os.path.join(os.path.dirname(dirpath), new_dirname)
|
|
||||||
|
|
||||||
if os.path.exists(old_path) and not os.path.exists(new_path):
|
|
||||||
try:
|
|
||||||
os.rename(old_path, new_path)
|
|
||||||
print(f" [RENAME-DIR] {original_dirname} -> {new_dirname}")
|
|
||||||
except OSError as e:
|
|
||||||
print(f" [HATA] Klasör adlandırılamadı {original_dirname}: {e}")
|
|
||||||
|
|
||||||
def main():
|
|
||||||
root_dir = os.getcwd()
|
|
||||||
print("==================================================")
|
|
||||||
print(f"🗂️ Dosya Adı Düzeltme İşlemi Başlatılıyor (pallet -> pezpallet)...")
|
|
||||||
print(f"⚠️ Çalışma Dizini: {root_dir}")
|
|
||||||
print("==================================================")
|
|
||||||
|
|
||||||
rename_paths(root_dir)
|
|
||||||
|
|
||||||
print("\n✅ Dosya Adları Düzeltme işlemi tamamlandı.")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -94,69 +94,125 @@ export const AccountBalance: React.FC = () => {
|
|||||||
return colors[assetId] || { bg: 'from-cyan-500/20 to-blue-500/20', text: 'text-cyan-400', border: 'border-cyan-500/30' };
|
return colors[assetId] || { bg: 'from-cyan-500/20 to-blue-500/20', text: 'text-cyan-400', border: 'border-cyan-500/30' };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fetch token prices from pools using pool account ID
|
// Fetch token prices from CoinGecko with fallback logic
|
||||||
|
// Priority: CoinGecko direct > DOT-based calculation > DEX pool
|
||||||
const fetchTokenPrices = async () => {
|
const fetchTokenPrices = async () => {
|
||||||
|
try {
|
||||||
|
if (import.meta.env.DEV) console.log('💰 Fetching token prices from CoinGecko...');
|
||||||
|
|
||||||
|
// CoinGecko API - fetch DOT, HEZ, PEZ prices
|
||||||
|
// Note: HEZ and PEZ may not be listed yet, so we use DOT as fallback
|
||||||
|
const coingeckoIds = 'polkadot,pezkuwichain,pez-token'; // DOT is always available
|
||||||
|
const response = await fetch(
|
||||||
|
`https://api.coingecko.com/api/v3/simple/price?ids=${coingeckoIds}&vs_currencies=usd&include_24hr_change=true`
|
||||||
|
);
|
||||||
|
|
||||||
|
let hezPrice = 0;
|
||||||
|
let pezPrice = 0;
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
if (import.meta.env.DEV) console.log('📊 CoinGecko response:', data);
|
||||||
|
|
||||||
|
const dotPrice = data['polkadot']?.usd || 0;
|
||||||
|
const directHezPrice = data['pezkuwichain']?.usd || 0;
|
||||||
|
const directPezPrice = data['pez-token']?.usd || 0;
|
||||||
|
|
||||||
|
// Use direct CoinGecko price if available, otherwise calculate from DOT
|
||||||
|
if (directHezPrice > 0) {
|
||||||
|
hezPrice = directHezPrice;
|
||||||
|
if (import.meta.env.DEV) console.log('✅ HEZ price from CoinGecko:', hezPrice, 'USD');
|
||||||
|
} else if (dotPrice > 0) {
|
||||||
|
// HEZ = DOT / 3
|
||||||
|
hezPrice = dotPrice / 3;
|
||||||
|
if (import.meta.env.DEV) console.log('✅ HEZ price (DOT/3):', hezPrice, 'USD');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (directPezPrice > 0) {
|
||||||
|
pezPrice = directPezPrice;
|
||||||
|
if (import.meta.env.DEV) console.log('✅ PEZ price from CoinGecko:', pezPrice, 'USD');
|
||||||
|
} else if (dotPrice > 0) {
|
||||||
|
// PEZ = DOT / 10
|
||||||
|
pezPrice = dotPrice / 10;
|
||||||
|
if (import.meta.env.DEV) console.log('✅ PEZ price (DOT/10):', pezPrice, 'USD');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If CoinGecko failed or returned 0, try DEX pool as fallback
|
||||||
|
if ((hezPrice === 0 || pezPrice === 0) && api && isApiReady) {
|
||||||
|
if (import.meta.env.DEV) console.log('⚠️ CoinGecko incomplete, trying DEX pool fallback...');
|
||||||
|
await fetchDexPoolPrices(hezPrice, pezPrice);
|
||||||
|
} else {
|
||||||
|
setHezUsdPrice(hezPrice);
|
||||||
|
setPezUsdPrice(pezPrice);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (import.meta.env.DEV) console.error('❌ CoinGecko fetch failed, trying DEX pool:', error);
|
||||||
|
// Fallback to DEX pool prices
|
||||||
|
if (api && isApiReady) {
|
||||||
|
await fetchDexPoolPrices(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fallback: Fetch prices from DEX pools
|
||||||
|
const fetchDexPoolPrices = async (existingHezPrice: number, existingPezPrice: number) => {
|
||||||
if (!api || !isApiReady) return;
|
if (!api || !isApiReady) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (import.meta.env.DEV) console.log('💰 Fetching token prices from pools...');
|
|
||||||
|
|
||||||
// Import utilities for pool account derivation
|
|
||||||
const { stringToU8a } = await import('@pezkuwi/util');
|
const { stringToU8a } = await import('@pezkuwi/util');
|
||||||
const { blake2AsU8a } = await import('@pezkuwi/util-crypto');
|
const { blake2AsU8a } = await import('@pezkuwi/util-crypto');
|
||||||
const PALLET_ID = stringToU8a('py/ascon');
|
const PALLET_ID = stringToU8a('py/ascon');
|
||||||
|
|
||||||
// Fetch wHEZ/wUSDT pool reserves (Asset 0 / Asset 1000)
|
let hezPrice = existingHezPrice;
|
||||||
const whezPoolId = api.createType('(u32, u32)', [0, ASSET_IDS.WUSDT]);
|
let pezPrice = existingPezPrice;
|
||||||
const whezPalletIdType = api.createType('[u8; 8]', PALLET_ID);
|
|
||||||
const whezFullTuple = api.createType('([u8; 8], (u32, u32))', [whezPalletIdType, whezPoolId]);
|
|
||||||
const whezAccountHash = blake2AsU8a(whezFullTuple.toU8a(), 256);
|
|
||||||
const whezPoolAccountId = api.createType('AccountId32', whezAccountHash);
|
|
||||||
|
|
||||||
const whezReserve0Query = await api.query.assets.account(0, whezPoolAccountId);
|
// Only fetch HEZ from DEX if not already set
|
||||||
const whezReserve1Query = await api.query.assets.account(ASSET_IDS.WUSDT, whezPoolAccountId);
|
if (hezPrice === 0) {
|
||||||
|
const whezPoolId = api.createType('(u32, u32)', [0, ASSET_IDS.WUSDT]);
|
||||||
|
const whezPalletIdType = api.createType('[u8; 8]', PALLET_ID);
|
||||||
|
const whezFullTuple = api.createType('([u8; 8], (u32, u32))', [whezPalletIdType, whezPoolId]);
|
||||||
|
const whezAccountHash = blake2AsU8a(whezFullTuple.toU8a(), 256);
|
||||||
|
const whezPoolAccountId = api.createType('AccountId32', whezAccountHash);
|
||||||
|
|
||||||
if (whezReserve0Query.isSome && whezReserve1Query.isSome) {
|
const whezReserve0Query = await api.query.assets.account(0, whezPoolAccountId);
|
||||||
const reserve0Data = whezReserve0Query.unwrap();
|
const whezReserve1Query = await api.query.assets.account(ASSET_IDS.WUSDT, whezPoolAccountId);
|
||||||
const reserve1Data = whezReserve1Query.unwrap();
|
|
||||||
|
|
||||||
const reserve0 = BigInt(reserve0Data.balance.toString()); // wHEZ (12 decimals)
|
if (whezReserve0Query.isSome && whezReserve1Query.isSome) {
|
||||||
const reserve1 = BigInt(reserve1Data.balance.toString()); // wUSDT (6 decimals)
|
const reserve0Data = whezReserve0Query.unwrap();
|
||||||
|
const reserve1Data = whezReserve1Query.unwrap();
|
||||||
// Calculate price: 1 HEZ = ? USD
|
const reserve0 = BigInt(reserve0Data.balance.toString());
|
||||||
const hezPrice = Number(reserve1 * BigInt(10 ** 12)) / Number(reserve0 * BigInt(10 ** 6));
|
const reserve1 = BigInt(reserve1Data.balance.toString());
|
||||||
if (import.meta.env.DEV) console.log('✅ HEZ price:', hezPrice, 'USD');
|
hezPrice = Number(reserve1 * BigInt(10 ** 12)) / Number(reserve0 * BigInt(10 ** 6));
|
||||||
setHezUsdPrice(hezPrice);
|
if (import.meta.env.DEV) console.log('✅ HEZ price from DEX:', hezPrice, 'USD');
|
||||||
} else {
|
}
|
||||||
if (import.meta.env.DEV) console.warn('⚠️ wHEZ/wUSDT pool has no reserves');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch PEZ/wUSDT pool reserves (Asset 1 / Asset 1000)
|
// Only fetch PEZ from DEX if not already set
|
||||||
const pezPoolId = api.createType('(u32, u32)', [1, ASSET_IDS.WUSDT]);
|
if (pezPrice === 0) {
|
||||||
const pezPalletIdType = api.createType('[u8; 8]', PALLET_ID);
|
const pezPoolId = api.createType('(u32, u32)', [1, ASSET_IDS.WUSDT]);
|
||||||
const pezFullTuple = api.createType('([u8; 8], (u32, u32))', [pezPalletIdType, pezPoolId]);
|
const pezPalletIdType = api.createType('[u8; 8]', PALLET_ID);
|
||||||
const pezAccountHash = blake2AsU8a(pezFullTuple.toU8a(), 256);
|
const pezFullTuple = api.createType('([u8; 8], (u32, u32))', [pezPalletIdType, pezPoolId]);
|
||||||
const pezPoolAccountId = api.createType('AccountId32', pezAccountHash);
|
const pezAccountHash = blake2AsU8a(pezFullTuple.toU8a(), 256);
|
||||||
|
const pezPoolAccountId = api.createType('AccountId32', pezAccountHash);
|
||||||
|
|
||||||
const pezReserve0Query = await api.query.assets.account(1, pezPoolAccountId);
|
const pezReserve0Query = await api.query.assets.account(1, pezPoolAccountId);
|
||||||
const pezReserve1Query = await api.query.assets.account(ASSET_IDS.WUSDT, pezPoolAccountId);
|
const pezReserve1Query = await api.query.assets.account(ASSET_IDS.WUSDT, pezPoolAccountId);
|
||||||
|
|
||||||
if (pezReserve0Query.isSome && pezReserve1Query.isSome) {
|
if (pezReserve0Query.isSome && pezReserve1Query.isSome) {
|
||||||
const reserve0Data = pezReserve0Query.unwrap();
|
const reserve0Data = pezReserve0Query.unwrap();
|
||||||
const reserve1Data = pezReserve1Query.unwrap();
|
const reserve1Data = pezReserve1Query.unwrap();
|
||||||
|
const reserve0 = BigInt(reserve0Data.balance.toString());
|
||||||
const reserve0 = BigInt(reserve0Data.balance.toString()); // PEZ (12 decimals)
|
const reserve1 = BigInt(reserve1Data.balance.toString());
|
||||||
const reserve1 = BigInt(reserve1Data.balance.toString()); // wUSDT (6 decimals)
|
pezPrice = Number(reserve1 * BigInt(10 ** 12)) / Number(reserve0 * BigInt(10 ** 6));
|
||||||
|
if (import.meta.env.DEV) console.log('✅ PEZ price from DEX:', pezPrice, 'USD');
|
||||||
// Calculate price: 1 PEZ = ? USD
|
}
|
||||||
const pezPrice = Number(reserve1 * BigInt(10 ** 12)) / Number(reserve0 * BigInt(10 ** 6));
|
|
||||||
if (import.meta.env.DEV) console.log('✅ PEZ price:', pezPrice, 'USD');
|
|
||||||
setPezUsdPrice(pezPrice);
|
|
||||||
} else {
|
|
||||||
if (import.meta.env.DEV) console.warn('⚠️ PEZ/wUSDT pool has no reserves');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setHezUsdPrice(hezPrice);
|
||||||
|
setPezUsdPrice(pezPrice);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (import.meta.env.DEV) console.error('❌ Failed to fetch token prices:', error);
|
if (import.meta.env.DEV) console.error('❌ DEX pool price fetch failed:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,16 @@ export const PezkuwiProvider: React.FC<PezkuwiProviderProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const provider = new WsProvider(currentEndpoint);
|
const provider = new WsProvider(currentEndpoint);
|
||||||
const apiInstance = await ApiPromise.create({ provider });
|
// PezkuwiChain custom signed extensions
|
||||||
|
const apiInstance = await ApiPromise.create({
|
||||||
|
provider,
|
||||||
|
signedExtensions: {
|
||||||
|
AuthorizeCall: {
|
||||||
|
extrinsic: {},
|
||||||
|
payload: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
await apiInstance.isReady;
|
await apiInstance.isReady;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user