@kehtus/proportion-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/account.ts CHANGED
@@ -52,8 +52,6 @@ export class AccountModule {
52
52
  { ...contract, functionName: "subscriptionCancelled" },
53
53
  { ...contract, functionName: "pendingSubscriptionFee" },
54
54
  { ...contract, functionName: "apiWallet" },
55
- { ...contract, functionName: "riskEngineWallet" },
56
- { ...contract, functionName: "builderRiskEngineWallet" },
57
55
  { ...contract, functionName: "checkpointIndex" },
58
56
  { ...contract, functionName: "profitableDaysCount" },
59
57
  { ...contract, functionName: "totalCheckpoints" },
@@ -70,10 +68,10 @@ export class AccountModule {
70
68
  ],
71
69
  });
72
70
 
73
- const checkpointIndex = results[16].result!;
74
- const totalCp = results[18].result!;
75
- const [profit, requestedAt] = results[22].result!;
76
- const rawCheckpoints = results[28].result!;
71
+ const checkpointIndex = results[14].result!;
72
+ const totalCp = results[16].result!;
73
+ const profit = results[20].result! as bigint;
74
+ const rawCheckpoints = results[26].result!;
77
75
  const checkpoints = normalizeCheckpoints(rawCheckpoints, totalCp, checkpointIndex);
78
76
 
79
77
  return {
@@ -92,20 +90,18 @@ export class AccountModule {
92
90
  subscriptionCancelled: results[11].result!,
93
91
  pendingSubscriptionFee: results[12].result!,
94
92
  apiWallet: results[13].result!,
95
- riskEngineWallet: results[14].result!,
96
- builderRiskEngineWallet: results[15].result!,
97
93
  checkpointIndex,
98
- profitableDaysCount: results[17].result!,
94
+ profitableDaysCount: results[15].result!,
99
95
  totalCheckpoints: totalCp,
100
- lastCheckpointDay: results[19].result!,
101
- closingInitiatedAt: Number(results[20].result!),
102
- returnInitiatedAt: Number(results[21].result!),
103
- pendingWithdrawal: { profit, requestedAt: Number(requestedAt) },
104
- trailingFloor: results[23].result!,
105
- dailyFloor: results[24].result!,
106
- subscriptionFee: results[25].result!,
107
- isSubscriptionActive: results[26].result!,
108
- canWithdrawProfit: results[27].result!,
96
+ lastCheckpointDay: results[17].result!,
97
+ closingInitiatedAt: Number(results[18].result!),
98
+ returnInitiatedAt: Number(results[19].result!),
99
+ pendingWithdrawal: { profit },
100
+ trailingFloor: results[21].result!,
101
+ dailyFloor: results[22].result!,
102
+ subscriptionFee: results[23].result!,
103
+ isSubscriptionActive: results[24].result!,
104
+ canWithdrawProfit: results[25].result!,
109
105
  checkpoints,
110
106
  };
111
107
  }
@@ -174,13 +170,13 @@ export class AccountModule {
174
170
  return normalizeCheckpoints(all, Number(total), Number(checkpointIndex));
175
171
  }
176
172
 
177
- async getPendingWithdrawal(account: Address): Promise<{ profit: bigint; requestedAt: number }> {
178
- const result = await this.publicClient.readContract({
173
+ async getPendingWithdrawal(account: Address): Promise<{ profit: bigint }> {
174
+ const profit = await this.publicClient.readContract({
179
175
  address: account,
180
176
  abi: fundedAccountAbi,
181
177
  functionName: "pendingWithdrawal",
182
- });
183
- return { profit: result[0], requestedAt: Number(result[1]) };
178
+ }) as bigint;
179
+ return { profit };
184
180
  }
185
181
 
186
182
  async getAccountConfig(account: Address): Promise<{
@@ -243,14 +239,6 @@ export class AccountModule {
243
239
  });
244
240
  }
245
241
 
246
- async cancelStuckWithdrawal(account: Address): Promise<Hash> {
247
- return this.write({
248
- address: account,
249
- abi: fundedAccountAbi,
250
- functionName: "cancelStuckWithdrawal",
251
- });
252
- }
253
-
254
242
  // ── PERMISSIONLESS WRITES ───────────────────────────
255
243
 
256
244
  async checkpoint(account: Address): Promise<Hash> {
@@ -294,6 +282,14 @@ export class AccountModule {
294
282
  });
295
283
  }
296
284
 
285
+ async bridgeToEvm(account: Address): Promise<Hash> {
286
+ return this.write({
287
+ address: account,
288
+ abi: fundedAccountAbi,
289
+ functionName: "bridgeToEvm",
290
+ });
291
+ }
292
+
297
293
  async finalizeReturn(account: Address): Promise<Hash> {
298
294
  return this.write({
299
295
  address: account,
@@ -326,14 +322,4 @@ export class AccountModule {
326
322
  });
327
323
  }
328
324
 
329
- // ── RISK ENGINE WRITES ──────────────────────────────
330
-
331
- async setRiskEngineWallet(account: Address, wallet: Address): Promise<Hash> {
332
- return this.write({
333
- address: account,
334
- abi: fundedAccountAbi,
335
- functionName: "setRiskEngineWallet",
336
- args: [wallet],
337
- });
338
- }
339
325
  }
package/src/constants.ts CHANGED
@@ -13,8 +13,9 @@ export const hyperEvm = {
13
13
  } as const satisfies Chain;
14
14
 
15
15
  export const ADDRESSES = {
16
- MAIN_VAULT: "0x4478888dA8d22E275344C1A24BDEbcf2bfE2dc45",
17
- FACTORY: "0xb7cE604a000CCFCe7c7DAfFBaefD26c33C86CE7A",
16
+ MAIN_VAULT: "0xA89F85eC9350e64295B199ee8011454d891e19B1",
17
+ FACTORY: "0xE056F0D2A476CCd9A24230C7DB7c9d6AF44a0161",
18
+ FORWARDER: "0x4fDc2489dE19BECC9FAeA59672F377bf740E4ecF",
18
19
  USDC: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
19
20
  } as const;
20
21
 
@@ -33,12 +34,12 @@ export const HYPE_FOR_GAS = 1_000_000_000_000_000n; // 0.001 ether
33
34
 
34
35
  // Decimals
35
36
  export const USDC_DECIMALS = 6;
36
- export const ACCOUNT_VALUE_DECIMALS = 8;
37
- export const DECIMALS_MULTIPLIER = 100n; // 68 dec
37
+ export const ACCOUNT_VALUE_DECIMALS = 8; // spotBalance, spotSend
38
+ export const DECIMALS_MULTIPLIER = 100n; // 6dec8dec (used for spotSend conversion)
39
+ // Note: accountValue, HWM, dayStartValue, floors are all 6dec (accountMarginSummary returns 6dec)
38
40
 
39
41
  // Time (seconds)
40
42
  export const SUBSCRIPTION_PERIOD = 30 * 86400;
41
- export const WITHDRAWAL_TIMEOUT = 7 * 86400;
42
43
  export const BRIDGE_DELAY = 30;
43
44
  export const CLOSING_TIMEOUT = 3 * 86400;
44
45
  export const CHECKPOINT_INTERVAL = 86400;
package/src/indexer.ts CHANGED
@@ -43,7 +43,7 @@ export class IndexerModule {
43
43
 
44
44
  private static readonly PAGE_SIZE = 1000;
45
45
  private static readonly VAULT_FIELDS = `id address totalDeposits totalWithdrawals totalActivationFees cumulativeActivationFeesToVault totalAllocated totalShares cumulativeProfitShares cumulativeCancelledProfit cumulativeSubscriptionFees cumulativeProtocolFeesRouted cumulativeHypercoreFees cumulativeAccountGains cumulativeAccountLosses cumulativeRescuedFunds totalAccountsActivated totalAccountsActive totalAccountsClosed paused subscriptionFeeMultiplier protocolFeeBps protocolFeeReceiver updatedAt`;
46
- private static readonly ACCOUNT_FIELDS = `id owner builder { id address vaultAddress } vaultAddress factoryAddress state accountSize drawdownBps dailyDrawdownEnabled activationFee highWaterMark profitableDaysCount lastCheckpointDay totalCheckpoints subscriptionPaidUntil subscriptionCancelled pendingSubscriptionFee subscriptionFeeMultiplier dayStartValue apiWallet riskEngineWallet builderRiskEngineWallet createdAt activatedAt closingInitiatedAt returnInitiatedAt closedAt returnedAmount breachType breachValue breachFloor closePendingSubFee closePendingProfit lastWithdrawalId updatedAt`;
46
+ private static readonly ACCOUNT_FIELDS = `id owner builder { id address vaultAddress } vaultAddress factoryAddress state accountSize drawdownBps dailyDrawdownEnabled activationFee highWaterMark profitableDaysCount lastCheckpointDay totalCheckpoints subscriptionPaidUntil subscriptionCancelled pendingSubscriptionFee subscriptionFeeMultiplier dayStartValue apiWallet createdAt activatedAt closingInitiatedAt returnInitiatedAt closedAt returnedAmount breachType breachValue breachFloor closePendingSubFee closePendingProfit lastWithdrawalId updatedAt`;
47
47
  private static readonly MAIN_VAULT_CONFIG_FIELDS = `id vaultAddress factoryAddress owner pendingOwner relayer paused protocolFeeReceiver feeMultiplier subscriptionFeeMultiplier dailyDdDiscountBps minBuilderShares builderLeverage protocolFeeBps minAccountSize maxAccountSize minDrawdownBps maxDrawdownBps maxUtilizationBps maxSingleAccountBps hypeForSpot maxCap createdAt updatedAt`;
48
48
  private static readonly FACTORY_CONFIG_FIELDS = `id factoryAddress vaultAddress owner pendingOwner createdAt updatedAt`;
49
49
  private static readonly CONFIG_CHANGE_FIELDS = `id contractAddress contractType field oldValue newValue blockNumber timestamp txHash`;
package/src/types.ts CHANGED
@@ -58,7 +58,6 @@ export type IndexerAccountStateLabel =
58
58
  export type BreachType =
59
59
  | "TRAILING_DRAWDOWN"
60
60
  | "DAILY_DRAWDOWN"
61
- | "LEVERAGE"
62
61
  | "POSITION_LEVERAGE"
63
62
  | "UNAUTHORIZED_ASSET"
64
63
  | "SUBSCRIPTION_EXPIRED";
@@ -123,15 +122,13 @@ export interface AccountDetails {
123
122
  subscriptionCancelled: boolean;
124
123
  pendingSubscriptionFee: bigint;
125
124
  apiWallet: Address;
126
- riskEngineWallet: Address;
127
- builderRiskEngineWallet: Address;
128
125
  checkpointIndex: number;
129
126
  totalCheckpoints: number;
130
127
  profitableDaysCount: number;
131
128
  lastCheckpointDay: bigint;
132
129
  closingInitiatedAt: number;
133
130
  returnInitiatedAt: number;
134
- pendingWithdrawal: { profit: bigint; requestedAt: number };
131
+ pendingWithdrawal: { profit: bigint };
135
132
  trailingFloor: bigint;
136
133
  dailyFloor: bigint;
137
134
  subscriptionFee: bigint;
@@ -214,8 +211,6 @@ export interface GqlAccount {
214
211
  subscriptionFeeMultiplier: number;
215
212
  dayStartValue: string;
216
213
  apiWallet: string | null;
217
- riskEngineWallet: string | null;
218
- builderRiskEngineWallet: string | null;
219
214
  createdAt: string;
220
215
  activatedAt: string | null;
221
216
  closingInitiatedAt: string | null;
package/src/utils.ts CHANGED
@@ -35,7 +35,7 @@ export function formatUsd(amount: bigint, dec: number = USDC_DECIMALS): string {
35
35
  return "$" + num.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
36
36
  }
37
37
 
38
- // ── Drawdown ────────────────────────────────────────
38
+ // ── Drawdown (all values in 6dec — matching on-chain HWM/dayStartValue) ──
39
39
 
40
40
  export function trailingFloor(hwm: bigint, drawdownBps: number): bigint {
41
41
  return hwm - (hwm * BigInt(drawdownBps)) / BPS;