forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfarm.ts
More file actions
79 lines (73 loc) · 2.73 KB
/
Copy pathfarm.ts
File metadata and controls
79 lines (73 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** A user's staked position in a farm, including time-lock metadata. */
export type FarmPosition = {
/** Stable identifier so UI updates survive re-renders. */
id: string;
/** Soroban contract id for this pool. */
contractAddress?: string;
name: string;
img: string;
earned: string;
/** Current staked balance, display string (e.g. "5.398"). */
stake: string;
dailyRate: string;
totalStakedLiquidity: string;
/** Token symbol of the locked asset. */
symbol: string;
/** Amount currently locked, in display units. */
lockedAmount: number;
/** Pool minimum deposit in display units. If set and remaining < this after unlock, contract closes the position entirely. */
minDepositAmount?: number;
/** Unix epoch (ms) when the position was locked. */
lockedAt: number;
/** Minimum lock period (seconds) before the position can be unlocked. */
lockPeriodSeconds: number;
/** Current boost allocation percentage (0-100) if set. */
boostAllocation?: number;
};
/** Epoch (ms) at which a position becomes eligible for unlock. */
export function unlockAvailableAt(position: FarmPosition): number {
return position.lockedAt + position.lockPeriodSeconds * 1000;
}
/**
* Represents each stage of an in-progress deposit (lock) transaction.
*
* idle – no deposit in progress
* simulating – building the Soroban transaction and running simulateTransaction
* signing – Freighter popup is open, waiting for user approval
* submitting – sendTransaction sent, polling waitForConfirmation
* success – transaction confirmed on-chain
* error – any step above failed
*/
export type DepositStep =
| "idle"
| "simulating"
| "signing"
| "submitting"
| "success"
| "error";
/** Human-readable label shown in the modal for each DepositStep. */
export const DEPOSIT_STEP_LABEL: Record<DepositStep, string> = {
idle: "",
simulating: "Estimating fees…",
signing: "Waiting for Freighter signature…",
submitting: "Waiting for on-chain confirmation…",
success: "Deposit confirmed!",
error: "",
};
/** Snapshot saved after a successful deposit for display in the success screen. */
export type DepositRecord = {
poolId: string;
symbol: string;
/** Display amount the user entered (in token units, not stroops). */
displayAmount: number;
txHash: string;
confirmedAt: number;
};
/** Convert a display amount (token units) to Soroban i128 stroops string. */
export function toStroops(displayAmount: number): string {
return String(Math.round(displayAmount * 10_000_000));
}
/** Whether a DepositStep represents an in-flight operation (blocks dismiss). */
export function isDepositPending(step: DepositStep): boolean {
return step === "simulating" || step === "signing" || step === "submitting";
}