@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/arch.md +15 -8
- package/dist/__tests__/reads.test.js +0 -1
- package/dist/abi/factory.d.ts +14 -0
- package/dist/abi/factory.js +18 -0
- package/dist/abi/forwarder.d.ts +287 -0
- package/dist/abi/forwarder.js +373 -0
- package/dist/abi/fundedAccount.d.ts +38 -99
- package/dist/abi/fundedAccount.js +47 -124
- package/dist/abi/mainVault.d.ts +0 -10
- package/dist/abi/mainVault.js +0 -13
- package/dist/account.d.ts +1 -3
- package/dist/account.js +23 -36
- package/dist/constants.d.ts +3 -3
- package/dist/constants.js +6 -5
- package/dist/indexer.js +1 -1
- package/dist/types.d.ts +1 -6
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/reads.test.ts +0 -1
- package/src/abi/factory.ts +18 -0
- package/src/abi/forwarder.ts +373 -0
- package/src/abi/fundedAccount.ts +47 -124
- package/src/abi/mainVault.ts +0 -13
- package/src/account.ts +26 -40
- package/src/constants.ts +6 -5
- package/src/indexer.ts +1 -1
- package/src/types.ts +1 -6
- package/src/utils.ts +1 -1
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[
|
|
74
|
-
const totalCp = results[
|
|
75
|
-
const
|
|
76
|
-
const rawCheckpoints = results[
|
|
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[
|
|
94
|
+
profitableDaysCount: results[15].result!,
|
|
99
95
|
totalCheckpoints: totalCp,
|
|
100
|
-
lastCheckpointDay: results[
|
|
101
|
-
closingInitiatedAt: Number(results[
|
|
102
|
-
returnInitiatedAt: Number(results[
|
|
103
|
-
pendingWithdrawal: { profit
|
|
104
|
-
trailingFloor: results[
|
|
105
|
-
dailyFloor: results[
|
|
106
|
-
subscriptionFee: results[
|
|
107
|
-
isSubscriptionActive: results[
|
|
108
|
-
canWithdrawProfit: results[
|
|
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
|
|
178
|
-
const
|
|
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
|
|
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: "
|
|
17
|
-
FACTORY: "
|
|
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; //
|
|
37
|
+
export const ACCOUNT_VALUE_DECIMALS = 8; // spotBalance, spotSend
|
|
38
|
+
export const DECIMALS_MULTIPLIER = 100n; // 6dec→8dec (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
|
|
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
|
|
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;
|