@kehtus/proportion-sdk 0.1.2 → 0.1.3

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.
Files changed (89) hide show
  1. package/LICENSE +21 -0
  2. package/dist/abi/factory.d.ts +1 -0
  3. package/dist/abi/factory.d.ts.map +1 -0
  4. package/dist/abi/factory.js +1 -0
  5. package/dist/abi/factory.js.map +1 -0
  6. package/dist/abi/forwarder.d.ts +1 -0
  7. package/dist/abi/forwarder.d.ts.map +1 -0
  8. package/dist/abi/forwarder.js +1 -0
  9. package/dist/abi/forwarder.js.map +1 -0
  10. package/dist/abi/fundedAccount.d.ts +1 -0
  11. package/dist/abi/fundedAccount.d.ts.map +1 -0
  12. package/dist/abi/fundedAccount.js +1 -0
  13. package/dist/abi/fundedAccount.js.map +1 -0
  14. package/dist/abi/mainVault.d.ts +198 -16
  15. package/dist/abi/mainVault.d.ts.map +1 -0
  16. package/dist/abi/mainVault.js +253 -19
  17. package/dist/abi/mainVault.js.map +1 -0
  18. package/dist/account.d.ts +3 -2
  19. package/dist/account.d.ts.map +1 -0
  20. package/dist/account.js +46 -43
  21. package/dist/account.js.map +1 -0
  22. package/dist/base.d.ts +9 -0
  23. package/dist/base.d.ts.map +1 -0
  24. package/dist/base.js +19 -0
  25. package/dist/base.js.map +1 -0
  26. package/dist/constants.d.ts +5 -4
  27. package/dist/constants.d.ts.map +1 -0
  28. package/dist/constants.js +5 -4
  29. package/dist/constants.js.map +1 -0
  30. package/dist/factory.d.ts +1 -0
  31. package/dist/factory.d.ts.map +1 -0
  32. package/dist/factory.js +56 -10
  33. package/dist/factory.js.map +1 -0
  34. package/dist/index.d.ts +1 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +1 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/indexer.d.ts +8 -3
  39. package/dist/indexer.d.ts.map +1 -0
  40. package/dist/indexer.js +81 -136
  41. package/dist/indexer.js.map +1 -0
  42. package/dist/sdk.d.ts +1 -0
  43. package/dist/sdk.d.ts.map +1 -0
  44. package/dist/sdk.js +1 -0
  45. package/dist/sdk.js.map +1 -0
  46. package/dist/types.d.ts +5 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +1 -0
  49. package/dist/types.js.map +1 -0
  50. package/dist/utils.d.ts +8 -0
  51. package/dist/utils.d.ts.map +1 -0
  52. package/dist/utils.js +10 -0
  53. package/dist/utils.js.map +1 -0
  54. package/dist/vault.d.ts +7 -4
  55. package/dist/vault.d.ts.map +1 -0
  56. package/dist/vault.js +76 -51
  57. package/dist/vault.js.map +1 -0
  58. package/package.json +12 -1
  59. package/arch.md +0 -455
  60. package/dist/__tests__/account.test.d.ts +0 -1
  61. package/dist/__tests__/account.test.js +0 -36
  62. package/dist/__tests__/indexer.test.d.ts +0 -1
  63. package/dist/__tests__/indexer.test.js +0 -230
  64. package/dist/__tests__/lifecycle.test.d.ts +0 -1
  65. package/dist/__tests__/lifecycle.test.js +0 -186
  66. package/dist/__tests__/reads.test.d.ts +0 -1
  67. package/dist/__tests__/reads.test.js +0 -184
  68. package/dist/__tests__/utils.test.d.ts +0 -1
  69. package/dist/__tests__/utils.test.js +0 -185
  70. package/src/__tests__/account.test.ts +0 -40
  71. package/src/__tests__/indexer.test.ts +0 -255
  72. package/src/__tests__/lifecycle.test.ts +0 -231
  73. package/src/__tests__/reads.test.ts +0 -208
  74. package/src/__tests__/utils.test.ts +0 -245
  75. package/src/abi/factory.ts +0 -417
  76. package/src/abi/forwarder.ts +0 -373
  77. package/src/abi/fundedAccount.ts +0 -1296
  78. package/src/abi/mainVault.ts +0 -1852
  79. package/src/account.ts +0 -325
  80. package/src/constants.ts +0 -51
  81. package/src/factory.ts +0 -157
  82. package/src/index.ts +0 -16
  83. package/src/indexer.ts +0 -636
  84. package/src/sdk.ts +0 -93
  85. package/src/types.ts +0 -421
  86. package/src/utils.ts +0 -143
  87. package/src/vault.ts +0 -479
  88. package/tsconfig.json +0 -19
  89. package/vitest.config.ts +0 -8
@@ -1,185 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { activationFee, subscriptionFee, splitProfit, trailingFloor, dailyFloor, isTrailingBreached, isDailyBreached, fromUsdc, toUsdc, from8Dec, to8Dec, toUsdc6, formatUsd, stateToLabel, labelToState, } from "../utils.js";
3
- import { AccountState } from "../types.js";
4
- // ── Helpers ──────────────────────────────────────────
5
- const usdc = (n) => BigInt(n) * 1000000n; // 6-dec USDC
6
- const dec8 = (n) => BigInt(n) * 100000000n; // 8-dec internal
7
- // ── Decimal conversions ──────────────────────────────
8
- describe("decimal conversions", () => {
9
- it("toUsdc converts number to 6-dec bigint", () => {
10
- expect(toUsdc(100)).toBe(100000000n);
11
- expect(toUsdc(0.5)).toBe(500000n);
12
- expect(toUsdc(5000)).toBe(5000000000n);
13
- });
14
- it("fromUsdc converts 6-dec bigint to number", () => {
15
- expect(fromUsdc(100000000n)).toBe(100);
16
- expect(fromUsdc(500000n)).toBe(0.5);
17
- });
18
- it("to8Dec scales 6-dec to 8-dec (*100)", () => {
19
- expect(to8Dec(usdc(1000))).toBe(dec8(1000));
20
- });
21
- it("toUsdc6 scales 8-dec down to 6-dec (/100)", () => {
22
- expect(toUsdc6(dec8(1000))).toBe(usdc(1000));
23
- });
24
- it("from8Dec converts 8-dec bigint to number", () => {
25
- expect(from8Dec(dec8(5000))).toBe(5000);
26
- expect(from8Dec(50000000n)).toBe(0.5);
27
- });
28
- it("roundtrip: toUsdc -> to8Dec -> toUsdc6", () => {
29
- const original = toUsdc(1234);
30
- const up = to8Dec(original);
31
- const down = toUsdc6(up);
32
- expect(down).toBe(original);
33
- });
34
- });
35
- // ── Activation fee ───────────────────────────────────
36
- describe("activationFee", () => {
37
- const FM = 120; // current contract feeMultiplier
38
- it("$5000 account, 500bps, no daily DD → $300", () => {
39
- // 5000 * 500 * 120 / 1_000_000 = 300
40
- expect(activationFee(usdc(5000), 500, false, FM)).toBe(usdc(300));
41
- });
42
- it("$5000 account, 500bps, daily DD → $240", () => {
43
- // 300 * 8000 / 10000 = 240 (20% discount)
44
- expect(activationFee(usdc(5000), 500, true, FM)).toBe(usdc(240));
45
- });
46
- it("$10000 account, 1000bps, no daily DD → $1200", () => {
47
- // 10000 * 1000 * 120 / 1_000_000 = 1200
48
- expect(activationFee(usdc(10000), 1000, false, FM)).toBe(usdc(1200));
49
- });
50
- it("$10000 account, 1000bps, daily DD → $960", () => {
51
- // 1200 * 8000 / 10000 = 960 (20% discount)
52
- expect(activationFee(usdc(10000), 1000, true, FM)).toBe(usdc(960));
53
- });
54
- it("min params: $100 account, 500bps → $6", () => {
55
- // 100 * 500 * 120 / 1_000_000 = 6
56
- const fee = activationFee(usdc(100), 500, false, FM);
57
- expect(fee).toBe(usdc(6));
58
- });
59
- });
60
- // ── Subscription fee ─────────────────────────────────
61
- describe("subscriptionFee", () => {
62
- const SFM = 150; // current contract subscriptionFeeMultiplier
63
- it("$5000 account → $75/month", () => {
64
- // 5000 * 150 / 10000 = 75
65
- expect(subscriptionFee(usdc(5000), SFM)).toBe(usdc(75));
66
- });
67
- it("legacy signature is still accepted for compatibility", () => {
68
- expect(subscriptionFee(usdc(5000), 500, true, SFM)).toBe(usdc(75));
69
- });
70
- it("$10000 account → $150/month", () => {
71
- expect(subscriptionFee(usdc(10000), SFM)).toBe(usdc(150));
72
- });
73
- });
74
- // ── Profit split ─────────────────────────────────────
75
- describe("splitProfit", () => {
76
- it("$1000 profit → 80% owner, 7% protocol, 13% vault", () => {
77
- const { owner, vault, protocol } = splitProfit(usdc(1000));
78
- expect(owner).toBe(usdc(800));
79
- expect(protocol).toBe(usdc(70));
80
- expect(vault).toBe(usdc(130));
81
- });
82
- it("sum of parts equals total", () => {
83
- const profit = usdc(7777);
84
- const { owner, vault, protocol } = splitProfit(profit);
85
- expect(owner + vault + protocol).toBe(profit);
86
- });
87
- it("zero profit", () => {
88
- const { owner, vault, protocol } = splitProfit(0n);
89
- expect(owner).toBe(0n);
90
- expect(vault).toBe(0n);
91
- expect(protocol).toBe(0n);
92
- });
93
- it("small profit — rounding goes to vault (remainder)", () => {
94
- // $1 = 1_000_000
95
- // owner = 1_000_000 * 8000 / 10000 = 800_000
96
- // protocol = 1_000_000 * 700 / 10000 = 70_000
97
- // vault = 1_000_000 - 800_000 - 70_000 = 130_000
98
- const { owner, vault, protocol } = splitProfit(usdc(1));
99
- expect(owner).toBe(800000n);
100
- expect(protocol).toBe(70000n);
101
- expect(vault).toBe(130000n);
102
- });
103
- });
104
- // ── Drawdown floors ──────────────────────────────────
105
- describe("trailingFloor", () => {
106
- it("500bps = 5% drawdown from HWM", () => {
107
- const hwm = dec8(10000); // $10,000 in 8-dec
108
- expect(trailingFloor(hwm, 500)).toBe(dec8(9500));
109
- });
110
- it("1000bps = 10% drawdown", () => {
111
- const hwm = dec8(5000);
112
- expect(trailingFloor(hwm, 1000)).toBe(dec8(4500));
113
- });
114
- });
115
- describe("dailyFloor", () => {
116
- it("500bps → daily = 250bps = 2.5% from day start", () => {
117
- const dsv = dec8(10000);
118
- // dailyBps = 500 / 2 = 250
119
- // floor = 10000 - 10000 * 250 / 10000 = 10000 - 250 = 9750
120
- expect(dailyFloor(dsv, 500)).toBe(dec8(9750));
121
- });
122
- it("1000bps → daily = 500bps = 5%", () => {
123
- const dsv = dec8(10000);
124
- expect(dailyFloor(dsv, 1000)).toBe(dec8(9500));
125
- });
126
- });
127
- describe("breach checks", () => {
128
- const hwm = dec8(10000);
129
- const dsv = dec8(10000);
130
- it("isTrailingBreached — below floor → true", () => {
131
- expect(isTrailingBreached(dec8(9499), hwm, 500)).toBe(true);
132
- });
133
- it("isTrailingBreached — at floor → false", () => {
134
- expect(isTrailingBreached(dec8(9500), hwm, 500)).toBe(false);
135
- });
136
- it("isTrailingBreached — above floor → false", () => {
137
- expect(isTrailingBreached(dec8(9501), hwm, 500)).toBe(false);
138
- });
139
- it("isDailyBreached — below floor → true", () => {
140
- expect(isDailyBreached(dec8(9749), dsv, 500)).toBe(true);
141
- });
142
- it("isDailyBreached — at floor → false", () => {
143
- expect(isDailyBreached(dec8(9750), dsv, 500)).toBe(false);
144
- });
145
- });
146
- // ── Enum mapping ─────────────────────────────────────
147
- describe("state enum mapping", () => {
148
- it("stateToLabel maps all states", () => {
149
- expect(stateToLabel(AccountState.Uninitialized)).toBe("UNINITIALIZED");
150
- expect(stateToLabel(AccountState.Active)).toBe("ACTIVE");
151
- expect(stateToLabel(AccountState.Closing)).toBe("CLOSING");
152
- expect(stateToLabel(AccountState.Closed)).toBe("CLOSED");
153
- expect(stateToLabel(AccountState.WithdrawalPending)).toBe("WITHDRAWAL_PENDING");
154
- expect(stateToLabel(AccountState.Returning)).toBe("RETURNING");
155
- expect(stateToLabel(AccountState.Initialized)).toBe("INITIALIZED");
156
- });
157
- it("labelToState reverses correctly", () => {
158
- expect(labelToState("UNINITIALIZED")).toBe(AccountState.Uninitialized);
159
- expect(labelToState("ACTIVE")).toBe(AccountState.Active);
160
- expect(labelToState("CLOSED")).toBe(AccountState.Closed);
161
- expect(labelToState("CLOSING")).toBe(AccountState.Closing);
162
- });
163
- it("roundtrip: state → label → state", () => {
164
- for (const state of [
165
- AccountState.Initialized,
166
- AccountState.Active,
167
- AccountState.WithdrawalPending,
168
- AccountState.Closing,
169
- AccountState.Returning,
170
- AccountState.Closed,
171
- ]) {
172
- expect(labelToState(stateToLabel(state))).toBe(state);
173
- }
174
- });
175
- });
176
- // ── formatUsd ────────────────────────────────────────
177
- describe("formatUsd", () => {
178
- it("formats 6-dec bigint as USD", () => {
179
- expect(formatUsd(usdc(1000))).toBe("$1,000.00");
180
- expect(formatUsd(usdc(0))).toBe("$0.00");
181
- });
182
- it("formats with custom decimals", () => {
183
- expect(formatUsd(dec8(5000), 8)).toBe("$5,000.00");
184
- });
185
- });
@@ -1,40 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { normalizeCheckpoints } from "../account.js";
3
-
4
- describe("normalizeCheckpoints", () => {
5
- it("keeps linear order before the ring buffer wraps", () => {
6
- const checkpoints = [
7
- { accountValue: 100n, timestamp: 1n, profitable: false },
8
- { accountValue: 110n, timestamp: 2n, profitable: true },
9
- { accountValue: 120n, timestamp: 3n, profitable: true },
10
- { accountValue: 0n, timestamp: 0n, profitable: false },
11
- { accountValue: 0n, timestamp: 0n, profitable: false },
12
- { accountValue: 0n, timestamp: 0n, profitable: false },
13
- { accountValue: 0n, timestamp: 0n, profitable: false },
14
- ] as const;
15
-
16
- expect(normalizeCheckpoints(checkpoints, 3, 3).map((cp) => cp.accountValue)).toEqual([100n, 110n, 120n]);
17
- });
18
-
19
- it("returns chronological order after the ring buffer wraps", () => {
20
- const checkpoints = [
21
- { accountValue: 800n, timestamp: 8n, profitable: true },
22
- { accountValue: 200n, timestamp: 2n, profitable: false },
23
- { accountValue: 300n, timestamp: 3n, profitable: false },
24
- { accountValue: 400n, timestamp: 4n, profitable: false },
25
- { accountValue: 500n, timestamp: 5n, profitable: true },
26
- { accountValue: 600n, timestamp: 6n, profitable: true },
27
- { accountValue: 700n, timestamp: 7n, profitable: true },
28
- ] as const;
29
-
30
- expect(normalizeCheckpoints(checkpoints, 7, 1).map((cp) => cp.accountValue)).toEqual([
31
- 200n,
32
- 300n,
33
- 400n,
34
- 500n,
35
- 600n,
36
- 700n,
37
- 800n,
38
- ]);
39
- });
40
- });
@@ -1,255 +0,0 @@
1
- import { describe, it, expect, beforeAll } from "vitest";
2
- import { IndexerModule } from "../indexer.js";
3
- import "dotenv/config";
4
-
5
- // ── Setup ────────────────────────────────────────────
6
-
7
- const GRAPHQL_URL = process.env.GRAPHQL_URL;
8
- if (!GRAPHQL_URL) throw new Error("GRAPHQL_URL required in .env for indexer tests");
9
-
10
- const indexer = new IndexerModule(GRAPHQL_URL);
11
-
12
- // We'll find an existing account address from the indexer to test detail queries
13
- let existingAccountId: string | null = null;
14
- let existingOwner: string | null = null;
15
- let activeVaultId: string | null = null;
16
- let activeFactoryId: string | null = null;
17
-
18
- beforeAll(async () => {
19
- try {
20
- const protocol = await indexer.getProtocolConfig();
21
- if (protocol) {
22
- activeVaultId = protocol.vaultAddress;
23
- activeFactoryId = protocol.factoryAddress;
24
- }
25
- } catch {
26
- // protocol config may be unavailable on older indexers
27
- }
28
-
29
- try {
30
- const accounts = await indexer.getAccountsByState("ACTIVE");
31
- if (accounts.length > 0) {
32
- existingAccountId = accounts[0].id;
33
- existingOwner = accounts[0].owner;
34
- }
35
- } catch {
36
- // indexer may have no active accounts
37
- }
38
- });
39
-
40
- // ── Protocol ───────────────────────────────────────
41
-
42
- describe("indexer: protocol", () => {
43
- it("getProtocolConfig returns deployment pointer or null", async () => {
44
- const protocol = await indexer.getProtocolConfig();
45
- if (!protocol) {
46
- console.log(" [SKIP] no ProtocolConfig entity in indexer yet");
47
- return;
48
- }
49
- expect(protocol.id).toBeTruthy();
50
- expect(protocol.vaultAddress).toBeTruthy();
51
- expect(protocol.factoryAddress).toBeTruthy();
52
- });
53
- });
54
-
55
- // ── Vault ────────────────────────────────────────────
56
-
57
- describe("indexer: vault", () => {
58
- it("getVault returns vault data or null", async () => {
59
- const vault = await indexer.getVault();
60
- if (!vault) {
61
- console.log(" [SKIP] no Vault entity in indexer yet");
62
- return;
63
- }
64
- expect(vault.id).toBeTruthy();
65
- expect(vault.address).toBeTruthy();
66
- expect(typeof vault.totalAccountsActivated).toBe("number");
67
- expect(typeof vault.paused).toBe("boolean");
68
- expect(typeof vault.totalAccountsActive).toBe("number");
69
- expect(vault).toHaveProperty("cumulativeProtocolFeesRouted");
70
- expect(vault).toHaveProperty("cumulativeRescuedFunds");
71
- });
72
- });
73
-
74
- // ── Accounts ─────────────────────────────────────────
75
-
76
- describe("indexer: accounts", () => {
77
- it("getAccountsByState returns array", async () => {
78
- const accounts = await indexer.getAccountsByState("ACTIVE");
79
- expect(Array.isArray(accounts)).toBe(true);
80
- if (accounts.length > 0) {
81
- expect(accounts[0].state).toBe("ACTIVE");
82
- expect(accounts[0].id).toBeTruthy();
83
- expect(accounts[0].owner).toBeTruthy();
84
- }
85
- });
86
-
87
- it("getAccountsByStates returns array", async () => {
88
- const accounts = await indexer.getAccountsByStates(["ACTIVE", "CLOSING"]);
89
- expect(Array.isArray(accounts)).toBe(true);
90
- for (const acc of accounts) {
91
- expect(["ACTIVE", "CLOSING"]).toContain(acc.state);
92
- }
93
- });
94
-
95
- it("getAccount returns single account or null", async () => {
96
- if (!existingAccountId) {
97
- console.log(" [SKIP] no existing accounts");
98
- return;
99
- }
100
- const acc = await indexer.getAccount(existingAccountId);
101
- expect(acc).not.toBeNull();
102
- expect(acc!.id).toBe(existingAccountId);
103
- expect(acc!.owner).toBeTruthy();
104
- expect(acc!.vaultAddress).toBeTruthy();
105
- expect(acc!.factoryAddress).toBeTruthy();
106
- expect(typeof acc!.drawdownBps).toBe("number");
107
- expect(typeof acc!.dailyDrawdownEnabled).toBe("boolean");
108
- expect(acc).toHaveProperty("closePendingSubFee");
109
- expect(acc).toHaveProperty("closePendingProfit");
110
- });
111
-
112
- it("getAccountsByOwner returns accounts", async () => {
113
- if (!existingOwner) {
114
- console.log(" [SKIP] no existing owner");
115
- return;
116
- }
117
- const accounts = await indexer.getAccountsByOwner(existingOwner);
118
- expect(Array.isArray(accounts)).toBe(true);
119
- expect(accounts.length).toBeGreaterThan(0);
120
- expect(accounts[0].owner.toLowerCase()).toBe(existingOwner.toLowerCase());
121
- });
122
- });
123
-
124
- // ── History ──────────────────────────────────────────
125
-
126
- describe("indexer: history", () => {
127
- it("getCheckpoints returns array", async () => {
128
- if (!existingAccountId) return;
129
- const checkpoints = await indexer.getCheckpoints(existingAccountId);
130
- expect(Array.isArray(checkpoints)).toBe(true);
131
- if (checkpoints.length > 0) {
132
- expect(checkpoints[0].dayNumber).toBeTruthy();
133
- expect(typeof checkpoints[0].profitable).toBe("boolean");
134
- }
135
- });
136
-
137
- it("getWithdrawals returns array", async () => {
138
- if (!existingAccountId) return;
139
- const withdrawals = await indexer.getWithdrawals(existingAccountId);
140
- expect(Array.isArray(withdrawals)).toBe(true);
141
- });
142
-
143
- it("getSubscriptionPayments returns array", async () => {
144
- if (!existingAccountId) return;
145
- const payments = await indexer.getSubscriptionPayments(existingAccountId);
146
- expect(Array.isArray(payments)).toBe(true);
147
- });
148
-
149
- it("getEvents returns array", async () => {
150
- if (!existingAccountId) return;
151
- const events = await indexer.getEvents(existingAccountId);
152
- expect(Array.isArray(events)).toBe(true);
153
- if (events.length > 0) {
154
- expect(events[0].eventType).toBeTruthy();
155
- expect(events[0].txHash).toBeTruthy();
156
- }
157
- });
158
-
159
- it("getEventsByType returns array", async () => {
160
- const events = await indexer.getEventsByType("Initialized", 5);
161
- expect(Array.isArray(events)).toBe(true);
162
- });
163
- });
164
-
165
- // ── LP ───────────────────────────────────────────────
166
-
167
- describe("indexer: LP", () => {
168
- it("getLP returns null for unknown address", async () => {
169
- const lp = await indexer.getLP("0x0000000000000000000000000000000000000001");
170
- expect(lp).toBeNull();
171
- });
172
-
173
- it("getLPDeposits returns array", async () => {
174
- if (!existingOwner) return;
175
- const deposits = await indexer.getLPDeposits(existingOwner);
176
- expect(Array.isArray(deposits)).toBe(true);
177
- });
178
-
179
- it("getLPWithdrawals returns array", async () => {
180
- if (!existingOwner) return;
181
- const withdrawals = await indexer.getLPWithdrawals(existingOwner);
182
- expect(Array.isArray(withdrawals)).toBe(true);
183
- });
184
-
185
- it("getLPDayData returns array", async () => {
186
- const dayData = await indexer.getLPDayData(existingOwner ?? "0x0000000000000000000000000000000000000001");
187
- expect(Array.isArray(dayData)).toBe(true);
188
- });
189
- });
190
-
191
- // ── Builder ──────────────────────────────────────────
192
-
193
- describe("indexer: builder", () => {
194
- it("getBuilder returns null for unknown address", async () => {
195
- const builder = await indexer.getBuilder("0x0000000000000000000000000000000000000001");
196
- expect(builder).toBeNull();
197
- });
198
-
199
- it("getDelegates returns array", async () => {
200
- if (!existingOwner) return;
201
- const delegates = await indexer.getDelegates(existingOwner);
202
- expect(Array.isArray(delegates)).toBe(true);
203
- });
204
- });
205
-
206
- // ── Config ───────────────────────────────────────────
207
-
208
- describe("indexer: config", () => {
209
- it("getMainVaultConfig returns config or null", async () => {
210
- if (!activeVaultId) {
211
- console.log(" [SKIP] no active vault in ProtocolConfig");
212
- return;
213
- }
214
- const config = await indexer.getMainVaultConfig(activeVaultId);
215
- expect(config).not.toBeNull();
216
- expect(config!.vaultAddress.toLowerCase()).toBe(activeVaultId.toLowerCase());
217
- expect(typeof config!.subscriptionFeeMultiplier).toBe("number");
218
- });
219
-
220
- it("getFactoryConfig returns config or null", async () => {
221
- if (!activeFactoryId) {
222
- console.log(" [SKIP] no active factory in ProtocolConfig");
223
- return;
224
- }
225
- const config = await indexer.getFactoryConfig(activeFactoryId);
226
- expect(config).not.toBeNull();
227
- expect(config!.factoryAddress.toLowerCase()).toBe(activeFactoryId.toLowerCase());
228
- });
229
-
230
- it("getConfigChanges returns array", async () => {
231
- const changes = await indexer.getConfigChanges({
232
- contractAddress: activeVaultId ?? undefined,
233
- limit: 5,
234
- });
235
- expect(Array.isArray(changes)).toBe(true);
236
- });
237
-
238
- it("getAllowedPerps returns array", async () => {
239
- const perps = await indexer.getAllowedPerps();
240
- expect(Array.isArray(perps)).toBe(true);
241
- if (perps.length > 0) {
242
- expect(typeof perps[0].perpIndex).toBe("number");
243
- expect(perps[0].allowed).toBe(true);
244
- }
245
- });
246
-
247
- it("getVaultDayData returns array", async () => {
248
- const days = await indexer.getVaultDayData(activeVaultId ?? undefined, { limit: 5 });
249
- expect(Array.isArray(days)).toBe(true);
250
- if (days.length > 0) {
251
- expect(typeof days[0].dayNumber).toBe("number");
252
- expect(days[0].totalAssets).toBeTruthy();
253
- }
254
- });
255
- });