Skip to content

Commit a6a7661

Browse files
committed
updated version; previous incorerct
1 parent f4c5986 commit a6a7661

File tree

7 files changed

+404
-395
lines changed

7 files changed

+404
-395
lines changed

entropy/0xSlither/client/src/UI.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,9 @@ export class UI {
156156
this.walletStatus.textContent = `Connected: ${this.shortenAddress(address)}`;
157157
this.walletStatus.className = 'success';
158158
this.stakeSection.classList.remove('hidden');
159-
// Don't enable stake button yet - wait for match ID from server
160-
this.stakeButton.disabled = true;
161-
this.stakeButton.textContent = 'Waiting for match...';
162-
}
163-
164-
enableStakeButton(): void {
159+
// VAULT MODE: Enable deposit immediately (no match ID wait)
165160
this.stakeButton.disabled = false;
166-
this.stakeButton.textContent = 'Stake 1 SSS';
161+
this.stakeButton.textContent = 'Deposit 1 SSS to Vault';
167162
}
168163

169164
updateWalletAddress(address: string): void {
@@ -180,20 +175,34 @@ export class UI {
180175
this.playButton.classList.add('hidden');
181176
}
182177

183-
setStaked(): void {
184-
this.stakeButton.textContent = '✓ Staked';
178+
setDeposited(): void {
179+
this.stakeButton.textContent = '✓ Deposited to Vault';
185180
this.stakeButton.disabled = true;
186181
this.playButton.classList.remove('hidden');
187182
this.playButton.disabled = false;
188183
}
189184

190-
resetStakeState(): void {
191-
this.stakeButton.textContent = 'Stake 1 SSS';
185+
resetDepositState(): void {
186+
this.stakeButton.textContent = 'Deposit 1 SSS to Vault';
192187
this.stakeButton.disabled = false;
193188
this.playButton.classList.add('hidden');
194189
this.playButton.disabled = true;
195190
}
196191

192+
/**
193+
* @deprecated Use setDeposited() for vault mode
194+
*/
195+
setStaked(): void {
196+
this.setDeposited();
197+
}
198+
199+
/**
200+
* @deprecated Use resetDepositState() for vault mode
201+
*/
202+
resetStakeState(): void {
203+
this.resetDepositState();
204+
}
205+
197206
setWalletNotAvailable(): void {
198207
this.connectWalletButton.disabled = true;
199208
this.walletStatus.textContent = 'No wallet detected. Cannot play.';
@@ -204,18 +213,33 @@ export class UI {
204213
this.tokenBalance.textContent = balance;
205214
}
206215

216+
getDepositAmount(): string {
217+
return '1'; // Fixed deposit amount for vault
218+
}
219+
220+
/**
221+
* @deprecated Use getDepositAmount() for vault mode
222+
*/
207223
getStakeAmount(): string {
208-
return '1'; // Fixed stake amount
224+
return this.getDepositAmount();
209225
}
210226

211-
onStake(callback: () => void): void {
227+
onDeposit(callback: () => void): void {
212228
this.stakeButton.addEventListener('click', () => {
213229
callback();
214230
});
215231
}
216232

217-
updateCurrentScore(totalScore: string): void {
218-
this.currentScore.textContent = `${totalScore} SSS`;
233+
/**
234+
* @deprecated Use onDeposit() for vault mode
235+
*/
236+
onStake(callback: () => void): void {
237+
this.onDeposit(callback);
238+
}
239+
240+
updateCurrentScore(pelletTokens: string): void {
241+
// VAULT MODE: Display pellet tokens only (kill rewards go directly to wallet)
242+
this.currentScore.textContent = `${pelletTokens} SSS (Pellets)`;
219243
}
220244

221245
updateDeathScreenWithBestScore(finalScore: number, bestScore: number): void {

entropy/0xSlither/client/src/WalletService.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NETWORK_CONFIG, getAddChainParameters, getSwitchChainParameters } from
33

44
// Contract ABIs (minimal, only what we need)
55
const STAKE_ARENA_ABI = [
6+
'function depositToVault() external payable',
67
'function enterMatch(bytes32 matchId) external payable',
78
'function tapOut(bytes32 matchId, uint256 score) external',
89
'function getLeaderboard() external view returns (tuple(address player, uint256 score)[])',
@@ -236,6 +237,37 @@ export class WalletService {
236237
}
237238
}
238239

240+
/**
241+
* Deposit SSS to the server vault for continuous gameplay
242+
* This replaces the per-match enterMatch flow
243+
*/
244+
async depositToVault(amount: string): Promise<boolean> {
245+
if (!this.stakeArena) {
246+
console.error('StakeArena not initialized');
247+
throw new Error('StakeArena not initialized');
248+
}
249+
250+
console.log(`Depositing ${amount} SSS to vault...`);
251+
252+
const amountWei = ethers.parseEther(amount);
253+
console.log('Amount in wei:', amountWei);
254+
255+
// Send SSS directly to vault (no match ID needed)
256+
const tx = await this.stakeArena.depositToVault({ value: amountWei });
257+
console.log('Transaction:', tx);
258+
const receipt = await tx.wait(2); // Wait for 2 confirmations for better finality
259+
console.log('Transaction confirmed:', receipt.hash);
260+
261+
// Add a small delay to ensure all RPC nodes have indexed the transaction
262+
await new Promise(resolve => setTimeout(resolve, 1000));
263+
264+
console.log('✅ Successfully deposited to vault');
265+
return true;
266+
}
267+
268+
/**
269+
* @deprecated Use depositToVault() for continuous matches
270+
*/
239271
async enterMatch(matchId: string, amount: string): Promise<boolean> {
240272
if (!this.stakeArena) {
241273
console.error('StakeArena not initialized');
@@ -262,6 +294,10 @@ export class WalletService {
262294
return true;
263295
}
264296

297+
/**
298+
* @deprecated In vault mode, tap-out is handled by server via direct transfers
299+
* No on-chain tapOut call needed
300+
*/
265301
async tapOut(matchId: string, score: number): Promise<boolean> {
266302
if (!this.stakeArena) {
267303
throw new Error('StakeArena not initialized');
@@ -277,6 +313,9 @@ export class WalletService {
277313
return true;
278314
}
279315

316+
/**
317+
* @deprecated Not used in vault mode (no per-match active tracking on-chain)
318+
*/
280319
async isActive(matchId: string, playerAddress: string): Promise<boolean> {
281320
if (!this.stakeArena) {
282321
throw new Error('StakeArena not initialized');
@@ -320,6 +359,10 @@ export class WalletService {
320359
}
321360
}
322361

362+
/**
363+
* @deprecated Not used in vault mode (stakes tracked server-side, not on-chain per match)
364+
* In vault mode, stakes go directly to server wallet on deposit
365+
*/
323366
async getCurrentStake(matchId: string, playerAddress?: string): Promise<string> {
324367
if (!this.stakeArena) return '0';
325368

0 commit comments

Comments
 (0)