@indigo-labs/indigo-sdk 0.5.5 → 0.5.6

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 (204) hide show
  1. package/package.json +11 -1
  2. package/.claude/settings.local.json +0 -7
  3. package/.github/workflows/ci.yml +0 -66
  4. package/.husky/pre-commit +0 -1
  5. package/.nvmrc +0 -1
  6. package/.prettierignore +0 -1
  7. package/.prettierrc +0 -6
  8. package/eslint.config.mjs +0 -42
  9. package/scripts/bench.sh +0 -62
  10. package/scripts/run-repeat.sh +0 -22
  11. package/src/contracts/cdp/helpers.ts +0 -173
  12. package/src/contracts/cdp/scripts.ts +0 -70
  13. package/src/contracts/cdp/transactions.ts +0 -1584
  14. package/src/contracts/cdp/types-new.ts +0 -277
  15. package/src/contracts/cdp/types.ts +0 -43
  16. package/src/contracts/cdp-creator/queries.ts +0 -30
  17. package/src/contracts/cdp-creator/scripts.ts +0 -45
  18. package/src/contracts/cdp-creator/types-new.ts +0 -50
  19. package/src/contracts/cdp-creator/types.ts +0 -24
  20. package/src/contracts/collector/scripts.ts +0 -32
  21. package/src/contracts/collector/transactions.ts +0 -50
  22. package/src/contracts/collector/types-new.ts +0 -17
  23. package/src/contracts/execute/scripts.ts +0 -57
  24. package/src/contracts/execute/types-new.ts +0 -44
  25. package/src/contracts/execute/types.ts +0 -24
  26. package/src/contracts/gov/helpers.ts +0 -351
  27. package/src/contracts/gov/scripts.ts +0 -41
  28. package/src/contracts/gov/transactions.ts +0 -1607
  29. package/src/contracts/gov/types-new.ts +0 -268
  30. package/src/contracts/gov/types.ts +0 -22
  31. package/src/contracts/iasset/helpers.ts +0 -170
  32. package/src/contracts/iasset/queries.ts +0 -102
  33. package/src/contracts/iasset/scripts.ts +0 -38
  34. package/src/contracts/iasset/types.ts +0 -154
  35. package/src/contracts/initialize/actions.ts +0 -789
  36. package/src/contracts/initialize/helpers.ts +0 -616
  37. package/src/contracts/initialize/types.ts +0 -116
  38. package/src/contracts/interest-collection/helpers.ts +0 -19
  39. package/src/contracts/interest-collection/queries.ts +0 -66
  40. package/src/contracts/interest-collection/scripts.ts +0 -44
  41. package/src/contracts/interest-collection/transactions.ts +0 -433
  42. package/src/contracts/interest-collection/types-new.ts +0 -50
  43. package/src/contracts/interest-collection/types.ts +0 -26
  44. package/src/contracts/interest-oracle/helpers.ts +0 -61
  45. package/src/contracts/interest-oracle/scripts.ts +0 -18
  46. package/src/contracts/interest-oracle/transactions.ts +0 -151
  47. package/src/contracts/interest-oracle/types-new.ts +0 -32
  48. package/src/contracts/interest-oracle/types.ts +0 -16
  49. package/src/contracts/one-shot/scripts.ts +0 -12
  50. package/src/contracts/one-shot/transactions.ts +0 -66
  51. package/src/contracts/one-shot/types.ts +0 -22
  52. package/src/contracts/poll/helpers.ts +0 -37
  53. package/src/contracts/poll/scripts.ts +0 -71
  54. package/src/contracts/poll/types-poll-manager.ts +0 -20
  55. package/src/contracts/poll/types-poll-new.ts +0 -196
  56. package/src/contracts/poll/types-poll-shard.ts +0 -16
  57. package/src/contracts/price-oracle/helpers.ts +0 -30
  58. package/src/contracts/price-oracle/scripts.ts +0 -18
  59. package/src/contracts/price-oracle/transactions.ts +0 -115
  60. package/src/contracts/price-oracle/types-new.ts +0 -50
  61. package/src/contracts/price-oracle/types.ts +0 -16
  62. package/src/contracts/pyth-feed/helpers.ts +0 -82
  63. package/src/contracts/pyth-feed/scripts.ts +0 -15
  64. package/src/contracts/pyth-feed/types.ts +0 -181
  65. package/src/contracts/rob/helpers.ts +0 -666
  66. package/src/contracts/rob/scripts.ts +0 -35
  67. package/src/contracts/rob/transactions.ts +0 -423
  68. package/src/contracts/rob/types-new.ts +0 -128
  69. package/src/contracts/rob/types.ts +0 -16
  70. package/src/contracts/rob-leverage/helpers.ts +0 -422
  71. package/src/contracts/rob-leverage/transactions.ts +0 -368
  72. package/src/contracts/stability-pool/helpers.ts +0 -798
  73. package/src/contracts/stability-pool/queries.ts +0 -132
  74. package/src/contracts/stability-pool/scripts.ts +0 -51
  75. package/src/contracts/stability-pool/transactions.ts +0 -921
  76. package/src/contracts/stability-pool/types-new.ts +0 -385
  77. package/src/contracts/stability-pool/types.ts +0 -25
  78. package/src/contracts/stableswap/helpers.ts +0 -507
  79. package/src/contracts/stableswap/scripts.ts +0 -37
  80. package/src/contracts/stableswap/transactions.ts +0 -475
  81. package/src/contracts/stableswap/types-new.ts +0 -131
  82. package/src/contracts/stableswap/types.ts +0 -17
  83. package/src/contracts/staking/helpers.ts +0 -136
  84. package/src/contracts/staking/scripts.ts +0 -41
  85. package/src/contracts/staking/transactions.ts +0 -349
  86. package/src/contracts/staking/types-new.ts +0 -137
  87. package/src/contracts/staking/types.ts +0 -17
  88. package/src/contracts/treasury/helpers.ts +0 -21
  89. package/src/contracts/treasury/queries.ts +0 -100
  90. package/src/contracts/treasury/scripts.ts +0 -27
  91. package/src/contracts/treasury/transactions.ts +0 -334
  92. package/src/contracts/treasury/types-new.ts +0 -69
  93. package/src/contracts/treasury/types.ts +0 -14
  94. package/src/contracts/version-registry/scripts.ts +0 -29
  95. package/src/contracts/version-registry/types-new.ts +0 -18
  96. package/src/contracts/version-registry/types.ts +0 -17
  97. package/src/index.ts +0 -99
  98. package/src/scripts/always-fail-validator.ts +0 -7
  99. package/src/scripts/auth-token-policy.ts +0 -24
  100. package/src/scripts/iasset-policy.ts +0 -23
  101. package/src/types/evolution-schema-options.ts +0 -16
  102. package/src/types/generic.ts +0 -52
  103. package/src/types/multisig.ts +0 -48
  104. package/src/types/on-chain-decimal.ts +0 -57
  105. package/src/types/rational.ts +0 -76
  106. package/src/types/system-params.ts +0 -463
  107. package/src/utils/array-utils.ts +0 -108
  108. package/src/utils/bigint-utils.ts +0 -35
  109. package/src/utils/helper-txs.ts +0 -31
  110. package/src/utils/indigo-helpers.ts +0 -17
  111. package/src/utils/lucid-utils.ts +0 -125
  112. package/src/utils/oracle-helpers.ts +0 -62
  113. package/src/utils/pyth/decode.ts +0 -223
  114. package/src/utils/pyth/encode.ts +0 -262
  115. package/src/utils/pyth/index.ts +0 -14
  116. package/src/utils/pyth/types.ts +0 -87
  117. package/src/utils/time-helpers.ts +0 -4
  118. package/src/utils/utils.ts +0 -25
  119. package/src/validators/always-succeed-validator.ts +0 -6
  120. package/src/validators/cdp-creator-validator.ts +0 -7
  121. package/src/validators/cdp-redeem-validator.ts +0 -7
  122. package/src/validators/cdp-validator.ts +0 -7
  123. package/src/validators/collector-validator.ts +0 -7
  124. package/src/validators/execute-validator.ts +0 -7
  125. package/src/validators/governance-validator.ts +0 -7
  126. package/src/validators/iasset-validator.ts +0 -7
  127. package/src/validators/interest-collection-validator.ts +0 -7
  128. package/src/validators/interest-oracle-validator.ts +0 -7
  129. package/src/validators/one-shot-policy.ts +0 -7
  130. package/src/validators/poll-manager-validator.ts +0 -7
  131. package/src/validators/poll-shard-validator.ts +0 -7
  132. package/src/validators/price-oracle-validator.ts +0 -7
  133. package/src/validators/pyth-feed-validator.ts +0 -7
  134. package/src/validators/rob-validator.ts +0 -7
  135. package/src/validators/stability-pool-validator.ts +0 -7
  136. package/src/validators/stableswap-validator.ts +0 -7
  137. package/src/validators/staking-validator.ts +0 -7
  138. package/src/validators/treasury-validator.ts +0 -7
  139. package/src/validators/version-record-policy.ts +0 -7
  140. package/src/validators/version-registry-validator.ts +0 -7
  141. package/tests/always-succeed/script.ts +0 -7
  142. package/tests/array-utils.test.ts +0 -92
  143. package/tests/bigint-utils.test.ts +0 -41
  144. package/tests/cdp/actions.ts +0 -680
  145. package/tests/cdp/cdp-helpers.ts +0 -55
  146. package/tests/cdp/cdp-queries.ts +0 -423
  147. package/tests/cdp/cdp.test.ts +0 -6730
  148. package/tests/cdp/transactions-mutated.ts +0 -1733
  149. package/tests/data/system-params.json +0 -1155
  150. package/tests/datums.test.ts +0 -302
  151. package/tests/endpoints/initialize.ts +0 -78
  152. package/tests/endpoints/interest-collector.ts +0 -37
  153. package/tests/endpoints/treasury.ts +0 -70
  154. package/tests/gov/actions.ts +0 -381
  155. package/tests/gov/gov.test.ts +0 -5147
  156. package/tests/gov/governance-queries.ts +0 -37
  157. package/tests/hash-checks.test.ts +0 -112
  158. package/tests/indigo-test-helpers.ts +0 -99
  159. package/tests/initialize.test.ts +0 -79
  160. package/tests/interest-calculations.test.ts +0 -120
  161. package/tests/interest-collection/interest-collection.test.ts +0 -843
  162. package/tests/interest-collection/transactions-mutated.ts +0 -260
  163. package/tests/interest-oracle.test.ts +0 -93
  164. package/tests/mock/assets-mock.ts +0 -243
  165. package/tests/mock/protocol-params-mock.ts +0 -21
  166. package/tests/price-oracle/actions.ts +0 -161
  167. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  168. package/tests/price-oracle/price-oracle.test.ts +0 -228
  169. package/tests/price-oracle/transactions-mutated.ts +0 -59
  170. package/tests/pyth/endpoints.ts +0 -96
  171. package/tests/pyth/helpers.ts +0 -37
  172. package/tests/pyth/pyth-encoding.test.ts +0 -376
  173. package/tests/pyth/pyth-feeds.test.ts +0 -943
  174. package/tests/pyth/pyth-indigo.test.ts +0 -505
  175. package/tests/pyth/pyth.test.ts +0 -299
  176. package/tests/queries/collector-queries.ts +0 -27
  177. package/tests/queries/execute-queries.ts +0 -47
  178. package/tests/queries/iasset-queries.ts +0 -149
  179. package/tests/queries/interest-oracle-queries.ts +0 -12
  180. package/tests/queries/poll-queries.ts +0 -97
  181. package/tests/queries/staking-queries.ts +0 -54
  182. package/tests/rob/actions.ts +0 -56
  183. package/tests/rob/rob-leverage.test.ts +0 -2555
  184. package/tests/rob/rob-queries.ts +0 -95
  185. package/tests/rob/rob.test.ts +0 -3677
  186. package/tests/rob/transactions-mutated.ts +0 -844
  187. package/tests/script-size.test.ts +0 -240
  188. package/tests/setup.ts +0 -135
  189. package/tests/stability-pool/actions.ts +0 -229
  190. package/tests/stability-pool.test.ts +0 -6491
  191. package/tests/stableswap/stableswap-actions.ts +0 -83
  192. package/tests/stableswap/stableswap-queries.ts +0 -98
  193. package/tests/stableswap/stableswap.test.ts +0 -4471
  194. package/tests/stableswap/transactions-mutated.ts +0 -348
  195. package/tests/staking.test.ts +0 -172
  196. package/tests/test-helpers.ts +0 -94
  197. package/tests/treasury/actions.ts +0 -67
  198. package/tests/treasury/treasury.test.ts +0 -320
  199. package/tests/utils/asserts.ts +0 -87
  200. package/tests/utils/benchmark-utils.ts +0 -130
  201. package/tests/utils/index.ts +0 -168
  202. package/tsconfig.build.json +0 -4
  203. package/tsconfig.json +0 -27
  204. package/vitest.config.ts +0 -11
@@ -1,240 +0,0 @@
1
- import { beforeEach, describe, test } from 'vitest';
2
- import {
3
- loadSystemParamsFromFile,
4
- mkCDPCreatorValidatorFromSP,
5
- mkCdpValidatorFromSP,
6
- mkCollectorValidatorFromSP,
7
- mkExecuteValidatorFromSP,
8
- mkRobValidatorFromSP,
9
- mkPollManagerValidatorFromSP,
10
- mkPollShardValidatorFromSP,
11
- mkVersionRegistryValidator,
12
- } from '../src';
13
- import { LucidContext } from './test-helpers';
14
- import {
15
- Emulator,
16
- EmulatorAccount,
17
- Lucid,
18
- LucidEvolution,
19
- SpendingValidator,
20
- TxBuilder,
21
- credentialToAddress,
22
- fromHex,
23
- generateEmulatorAccount,
24
- } from '@lucid-evolution/lucid';
25
- import { benchmarkAndAwaitTx } from './utils/benchmark-utils';
26
- import { mkGovValidatorFromSP } from '../src/contracts/gov/scripts';
27
- import { mkStabilityPoolValidatorFromSP } from '../src/contracts/stability-pool/scripts';
28
- import { mkStakingValidatorFromSP } from '../src/contracts/staking/scripts';
29
- import { mkTreasuryValidatorFromSP } from '../src/contracts/treasury/scripts';
30
- import { mkStableswapValidatorFromSP } from '../src/contracts/stableswap/scripts';
31
- import { mkPythFeedValidator } from '../src/contracts/pyth-feed/scripts';
32
- import { MAINNET_PROTOCOL_PARAMETERS } from './indigo-test-helpers';
33
-
34
- const systemParams = loadSystemParamsFromFile(
35
- './tests/data/system-params.json',
36
- );
37
-
38
- type TestContext = LucidContext<{
39
- admin: EmulatorAccount;
40
- }>;
41
-
42
- describe('Script Size', () => {
43
- function initScriptRef(
44
- lucid: LucidEvolution,
45
- validator: SpendingValidator,
46
- ): TxBuilder {
47
- return lucid.newTx().pay.ToContract(
48
- credentialToAddress(lucid.config().network!, {
49
- hash: 'ea84d625650d066e1645e3e81d9c70a73f9ed837bd96dc49850ae744', // always fail validator hash
50
- type: 'Script',
51
- }),
52
- undefined,
53
- undefined,
54
- validator,
55
- );
56
- }
57
-
58
- beforeEach<TestContext>(async (context: TestContext) => {
59
- context.users = {
60
- admin: generateEmulatorAccount({
61
- lovelace: BigInt(100_000_000),
62
- }),
63
- };
64
-
65
- context.emulator = new Emulator(
66
- [context.users.admin],
67
- MAINNET_PROTOCOL_PARAMETERS,
68
- );
69
- context.lucid = await Lucid(context.emulator, 'Custom');
70
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
71
- });
72
-
73
- test('CDP Creator', async (context: TestContext) => {
74
- await benchmarkAndAwaitTx(
75
- 'Script Size - CDP Creator',
76
- initScriptRef(
77
- context.lucid,
78
- mkCDPCreatorValidatorFromSP(systemParams.cdpCreatorParams),
79
- ),
80
- context.lucid,
81
- context.emulator,
82
- );
83
- });
84
-
85
- test('CDP', async (context: TestContext) => {
86
- await benchmarkAndAwaitTx(
87
- 'Script Size - CDP',
88
- initScriptRef(
89
- context.lucid,
90
- mkCdpValidatorFromSP(systemParams.cdpParams),
91
- ),
92
- context.lucid,
93
- context.emulator,
94
- );
95
- });
96
-
97
- test('Collector', async (context: TestContext) => {
98
- await benchmarkAndAwaitTx(
99
- 'Script Size - Collector',
100
- initScriptRef(
101
- context.lucid,
102
- mkCollectorValidatorFromSP(systemParams.collectorParams),
103
- ),
104
- context.lucid,
105
- context.emulator,
106
- );
107
- });
108
-
109
- test('Execute', async (context: TestContext) => {
110
- await benchmarkAndAwaitTx(
111
- 'Script Size - Execute',
112
- initScriptRef(
113
- context.lucid,
114
- mkExecuteValidatorFromSP(systemParams.executeParams),
115
- ),
116
- context.lucid,
117
- context.emulator,
118
- );
119
- });
120
-
121
- test('Gov', async (context: TestContext) => {
122
- await benchmarkAndAwaitTx(
123
- 'Script Size - Gov',
124
- initScriptRef(
125
- context.lucid,
126
- mkGovValidatorFromSP(systemParams.govParams),
127
- ),
128
- context.lucid,
129
- context.emulator,
130
- );
131
- });
132
-
133
- test('ROB', async (context: TestContext) => {
134
- await benchmarkAndAwaitTx(
135
- 'Script Size - ROB',
136
- initScriptRef(
137
- context.lucid,
138
- mkRobValidatorFromSP(systemParams.robParams),
139
- ),
140
- context.lucid,
141
- context.emulator,
142
- );
143
- });
144
-
145
- test('Poll Manager', async (context: TestContext) => {
146
- await benchmarkAndAwaitTx(
147
- 'Script Size - Poll Manager',
148
- initScriptRef(
149
- context.lucid,
150
- mkPollManagerValidatorFromSP(systemParams.pollManagerParams),
151
- ),
152
- context.lucid,
153
- context.emulator,
154
- );
155
- });
156
-
157
- test('Poll Shard', async (context: TestContext) => {
158
- await benchmarkAndAwaitTx(
159
- 'Script Size - Poll Shard',
160
- initScriptRef(
161
- context.lucid,
162
- mkPollShardValidatorFromSP(systemParams.pollShardParams),
163
- ),
164
- context.lucid,
165
- context.emulator,
166
- );
167
- });
168
-
169
- test('Pyth Feed', async (context: TestContext) => {
170
- await benchmarkAndAwaitTx(
171
- 'Script Size - Pyth Feed',
172
- initScriptRef(
173
- context.lucid,
174
- mkPythFeedValidator({
175
- config: { Value: { configuration: { priceFeedId: 0n } } },
176
- pythStatePolicyId: fromHex(''),
177
- }),
178
- ),
179
- context.lucid,
180
- context.emulator,
181
- );
182
- });
183
-
184
- test('Stability Pool', async (context: TestContext) => {
185
- await benchmarkAndAwaitTx(
186
- 'Script Size - Stability Pool',
187
- initScriptRef(
188
- context.lucid,
189
- mkStabilityPoolValidatorFromSP(systemParams.stabilityPoolParams),
190
- ),
191
- context.lucid,
192
- context.emulator,
193
- );
194
- });
195
-
196
- test('Stableswap', async (context: TestContext) => {
197
- await benchmarkAndAwaitTx(
198
- 'Script Size - Stableswap',
199
- initScriptRef(
200
- context.lucid,
201
- mkStableswapValidatorFromSP(systemParams.stableswapParams),
202
- ),
203
- context.lucid,
204
- context.emulator,
205
- );
206
- });
207
-
208
- test('Staking', async (context: TestContext) => {
209
- await benchmarkAndAwaitTx(
210
- 'Script Size - Staking',
211
- initScriptRef(
212
- context.lucid,
213
- mkStakingValidatorFromSP(systemParams.stakingParams),
214
- ),
215
- context.lucid,
216
- context.emulator,
217
- );
218
- });
219
-
220
- test('Treasury', async (context: TestContext) => {
221
- await benchmarkAndAwaitTx(
222
- 'Script Size - Treasury',
223
- initScriptRef(
224
- context.lucid,
225
- mkTreasuryValidatorFromSP(systemParams.treasuryParams),
226
- ),
227
- context.lucid,
228
- context.emulator,
229
- );
230
- });
231
-
232
- test('Version Registry', async (context: TestContext) => {
233
- await benchmarkAndAwaitTx(
234
- 'Script Size - Version Registry',
235
- initScriptRef(context.lucid, mkVersionRegistryValidator()),
236
- context.lucid,
237
- context.emulator,
238
- );
239
- });
240
- });
package/tests/setup.ts DELETED
@@ -1,135 +0,0 @@
1
- import { BenchmarkResult } from './utils/benchmark-utils';
2
- import { writeFileSync, readFileSync, existsSync, unlinkSync } from 'fs';
3
- import { join } from 'path';
4
-
5
- // File path to persist benchmark results across workers
6
- const BENCHMARK_RESULTS_FILE = join(
7
- process.cwd(),
8
- '.vitest-benchmark-results.json',
9
- );
10
-
11
- // Parse command-line arguments for --benchmark-file flag
12
- function getBenchmarkOutputFile(): string | null {
13
- const args = process.argv;
14
- const flagIndex = args.indexOf('--benchmark-file');
15
- if (flagIndex !== -1 && flagIndex + 1 < args.length) {
16
- return args[flagIndex + 1];
17
- }
18
- return null;
19
- }
20
-
21
- // Helper function to read results from file
22
- function readResultsFromFile(): Record<string, BenchmarkResult> {
23
- if (existsSync(BENCHMARK_RESULTS_FILE)) {
24
- try {
25
- const content = readFileSync(BENCHMARK_RESULTS_FILE, 'utf-8');
26
- return JSON.parse(content) as Record<string, BenchmarkResult>;
27
- } catch (error) {
28
- console.warn('Failed to read benchmark results file:', error);
29
- return {};
30
- }
31
- }
32
- return {};
33
- }
34
-
35
- // Helper function to write results to file
36
- function writeResultsToFile(results: Record<string, BenchmarkResult>): void {
37
- try {
38
- writeFileSync(
39
- BENCHMARK_RESULTS_FILE,
40
- JSON.stringify(results, null, 2),
41
- 'utf-8',
42
- );
43
- } catch (error) {
44
- console.warn('Failed to write benchmark results file:', error);
45
- }
46
- }
47
-
48
- // In-memory store for the current worker/test file
49
- // Using a Proxy to automatically sync to file when properties are set
50
- const _BENCHMARK_RESULTS: Record<string, BenchmarkResult> = {};
51
-
52
- // Create a Proxy that automatically syncs to file on property assignment
53
- export const BENCHMARK_RESULTS = new Proxy(_BENCHMARK_RESULTS, {
54
- set(target, property, value: BenchmarkResult) {
55
- if (Object.prototype.hasOwnProperty.call(target, property)) {
56
- throw new Error(
57
- `Benchmark with name "${property as string}" already exists.`,
58
- );
59
- }
60
-
61
- // Set the value in the local object
62
- target[property as string] = value;
63
-
64
- // Merge with existing results from file and write back
65
- const existingResults = readResultsFromFile();
66
- const mergedResults = { ...existingResults, ...target };
67
- writeResultsToFile(mergedResults);
68
-
69
- return true;
70
- },
71
- get(target, property) {
72
- // When reading, first merge with file results to get latest from other workers
73
- const fileResults = readResultsFromFile();
74
- Object.assign(target, fileResults);
75
- return target[property as string];
76
- },
77
- });
78
-
79
- // Vitest global setup (must be default export)
80
- export default function setup() {
81
- // Clear any existing results file at the start
82
- if (existsSync(BENCHMARK_RESULTS_FILE)) {
83
- unlinkSync(BENCHMARK_RESULTS_FILE);
84
- }
85
-
86
- // Return teardown function
87
- return function teardown() {
88
- // Read all results from file (accumulated across all workers)
89
- const results = readResultsFromFile();
90
-
91
- if (Object.keys(results).length === 0) {
92
- return;
93
- }
94
-
95
- // Sort entries by benchmark name alphabetically
96
- const sortedEntries = Object.entries(results).sort(([a], [b]) =>
97
- a.localeCompare(b),
98
- );
99
-
100
- const decimalPlaces = 3;
101
-
102
- console.log('\n=== Benchmark Results ===');
103
- console.table(
104
- sortedEntries.map(([name, result]: [string, BenchmarkResult]) => ({
105
- 'Benchmark Name': name,
106
- 'Memory Percentage': result.memPercentage.toFixed(decimalPlaces) + '%',
107
- 'Steps Percentage': result.stepsPercentage.toFixed(decimalPlaces) + '%',
108
- 'Size Percentage': result.sizePercentage.toFixed(decimalPlaces) + '%',
109
- })),
110
- );
111
-
112
- // Write results to output file if --benchmark-file flag is present
113
- const outputFile = getBenchmarkOutputFile();
114
- if (outputFile) {
115
- try {
116
- writeFileSync(
117
- outputFile,
118
- JSON.stringify(Object.fromEntries(sortedEntries), null, 2),
119
- 'utf-8',
120
- );
121
- console.log(`\nBenchmark results written to: ${outputFile}`);
122
- } catch (error) {
123
- console.warn(
124
- `Failed to write benchmark results to ${outputFile}:`,
125
- error,
126
- );
127
- }
128
- }
129
-
130
- // Clean up the results file
131
- if (existsSync(BENCHMARK_RESULTS_FILE)) {
132
- unlinkSync(BENCHMARK_RESULTS_FILE);
133
- }
134
- };
135
- }
@@ -1,229 +0,0 @@
1
- import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
2
- import {
3
- fromHex,
4
- fromText,
5
- LucidEvolution,
6
- TxBuilder,
7
- } from '@lucid-evolution/lucid';
8
- import {
9
- addrDetails,
10
- requestSpAccountAdjustment,
11
- bigintMax,
12
- requestSpAccountClosure,
13
- createE2s2sSnapshots,
14
- requestSpAccountCreation,
15
- fromSystemParamsAsset,
16
- openCdp,
17
- processSpRequest,
18
- SystemParams,
19
- findStabilityPool,
20
- findStabilityPoolAccount,
21
- findE2s2sSnapshots,
22
- } from '../../src';
23
- import {
24
- findAllNecessaryOrefs,
25
- findPriceOracleFromCollateralAsset,
26
- } from '../cdp/cdp-queries';
27
-
28
- import { LucidContext, runAndAwaitTx } from '../test-helpers';
29
- import { expect } from 'vitest';
30
- import { findIAsset } from '../queries/iasset-queries';
31
- import {
32
- rationalCeil,
33
- rationalDiv,
34
- rationalFromInt,
35
- rationalMul,
36
- rationalSub,
37
- } from '../../src/types/rational';
38
-
39
- export async function runOpenCdpAndCreateSPAccount(
40
- context: LucidContext,
41
- sysParams: SystemParams,
42
- asset: string,
43
- /**
44
- * The collateral asset to back the borrowed iAssets that will be used for stability pool deposit.
45
- */
46
- collateralAsset: AssetClass,
47
- spDepositAmount: bigint,
48
- ): Promise<TxBuilder> {
49
- const orefs = await findAllNecessaryOrefs(
50
- context.lucid,
51
- sysParams,
52
- asset,
53
- collateralAsset,
54
- );
55
-
56
- const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
57
- context.lucid,
58
- orefs.collateralAsset,
59
- );
60
-
61
- const collateral = bigintMax(
62
- orefs.collateralAsset.datum.minCollateralAmt,
63
- // collateralisation should be maintenance ratio * 2
64
- rationalCeil(
65
- rationalMul(
66
- rationalFromInt(2n * spDepositAmount),
67
- orefs.collateralAsset.datum.maintenanceRatio,
68
- ),
69
- ),
70
- );
71
-
72
- // Mint enough to match the intended SP deposit after paying debt minting fees.
73
- const mintAmount = rationalCeil(
74
- rationalDiv(
75
- rationalFromInt(spDepositAmount),
76
- rationalSub(rationalFromInt(1n), orefs.iasset.datum.debtMintingFeeRatio),
77
- ),
78
- );
79
-
80
- await runAndAwaitTx(
81
- context.lucid,
82
- openCdp(
83
- collateral,
84
- BigInt(mintAmount),
85
- sysParams,
86
- orefs.cdpCreatorUtxo,
87
- orefs.iasset.utxo,
88
- orefs.collateralAsset.utxo,
89
- priceOracleUtxo,
90
- orefs.interestOracleUtxo,
91
- orefs.treasuryUtxo,
92
- context.lucid,
93
- ),
94
- );
95
-
96
- return requestSpAccountCreation(
97
- asset,
98
- spDepositAmount,
99
- sysParams,
100
- context.lucid,
101
- );
102
- }
103
-
104
- async function waitForAccountCooldown(
105
- context: LucidContext,
106
- sysParams: SystemParams,
107
- asset: string,
108
- // Request owner
109
- pkh: string,
110
- ) {
111
- const accountUtxo = await findStabilityPoolAccount(
112
- context.lucid,
113
- sysParams,
114
- pkh,
115
- fromHex(fromText(asset)),
116
- );
117
-
118
- if (accountUtxo.datum.lastRequestProcessingTime !== 0n) {
119
- const targetSlot = context.lucid.unixTimeToSlot(
120
- Number(accountUtxo.datum.lastRequestProcessingTime) +
121
- sysParams.stabilityPoolParams.accountProcessingCooldownMs,
122
- );
123
-
124
- if (targetSlot > context.lucid.currentSlot()) {
125
- expect(targetSlot).toBeGreaterThan(context.lucid.currentSlot());
126
-
127
- context.emulator.awaitSlot(targetSlot - context.lucid.currentSlot() + 2);
128
- }
129
- }
130
- }
131
-
132
- export async function runProcessSpRequest(
133
- context: LucidContext,
134
- sysParams: SystemParams,
135
- asset: string,
136
- // Request owner
137
- pkh: string,
138
- ): Promise<TxBuilder> {
139
- const sp = await findStabilityPool(
140
- context.lucid,
141
- sysParams,
142
- fromHex(fromText(asset)),
143
- );
144
-
145
- const ia = await findIAsset(
146
- context.lucid,
147
- sysParams.validatorHashes.iassetHash,
148
- fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
149
- asset,
150
- );
151
-
152
- const accountUtxo = await findStabilityPoolAccount(
153
- context.lucid,
154
- sysParams,
155
- pkh,
156
- fromHex(fromText(asset)),
157
- );
158
-
159
- await waitForAccountCooldown(context, sysParams, asset, pkh);
160
-
161
- return processSpRequest(
162
- sp.utxo,
163
- accountUtxo.utxo,
164
- ia.utxo,
165
- (
166
- await findE2s2sSnapshots(
167
- context.lucid,
168
- sysParams,
169
- fromHex(fromText(asset)),
170
- )
171
- ).map((res) => res.utxo),
172
- sysParams,
173
- context.lucid,
174
- );
175
- }
176
-
177
- export async function runCreateAdjustRequest(
178
- lucid: LucidEvolution,
179
- sysParams: SystemParams,
180
- asset: string,
181
- adjustment: bigint,
182
- ): Promise<TxBuilder> {
183
- const [pkh, _] = await addrDetails(lucid);
184
-
185
- const accountUtxo = await findStabilityPoolAccount(
186
- lucid,
187
- sysParams,
188
- pkh.hash,
189
- fromHex(fromText(asset)),
190
- );
191
-
192
- return requestSpAccountAdjustment(
193
- adjustment,
194
- accountUtxo.utxo,
195
- sysParams,
196
- lucid,
197
- );
198
- }
199
-
200
- export async function runCreateCloseRequest(
201
- lucid: LucidEvolution,
202
- sysParams: SystemParams,
203
- asset: string,
204
- ): Promise<TxBuilder> {
205
- const [pkh, _] = await addrDetails(lucid);
206
-
207
- const accountUtxo = await findStabilityPoolAccount(
208
- lucid,
209
- sysParams,
210
- pkh.hash,
211
- fromHex(fromText(asset)),
212
- );
213
-
214
- return requestSpAccountClosure(accountUtxo.utxo, sysParams, lucid);
215
- }
216
-
217
- export async function runCreateE2s2sSnapshots(
218
- context: LucidContext,
219
- sysParams: SystemParams,
220
- asset: string,
221
- ): Promise<TxBuilder> {
222
- const spUtxo = await findStabilityPool(
223
- context.lucid,
224
- sysParams,
225
- fromHex(fromText(asset)),
226
- );
227
-
228
- return createE2s2sSnapshots(spUtxo.utxo, sysParams, context.lucid);
229
- }