@indigo-labs/indigo-sdk 0.2.42 → 0.3.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/.github/workflows/ci.yml +4 -2
- package/README.md +88 -15
- package/dist/index.d.mts +3012 -2194
- package/dist/index.d.ts +3012 -2194
- package/dist/index.js +9849 -6198
- package/dist/index.mjs +8733 -4933
- package/package.json +14 -3
- package/src/contracts/cdp/helpers.ts +68 -72
- package/src/contracts/cdp/scripts.ts +50 -13
- package/src/contracts/cdp/transactions.ts +841 -546
- package/src/contracts/cdp/types-new.ts +256 -0
- package/src/contracts/cdp/types.ts +26 -144
- package/src/contracts/cdp-creator/scripts.ts +15 -9
- package/src/contracts/cdp-creator/types-new.ts +50 -0
- package/src/contracts/cdp-creator/types.ts +5 -31
- package/src/contracts/collector/scripts.ts +1 -1
- package/src/contracts/collector/transactions.ts +23 -13
- package/src/contracts/collector/types-new.ts +17 -0
- package/src/contracts/execute/scripts.ts +19 -10
- package/src/contracts/execute/types-new.ts +44 -0
- package/src/contracts/execute/types.ts +5 -38
- package/src/contracts/gov/helpers.ts +187 -51
- package/src/contracts/gov/scripts.ts +17 -10
- package/src/contracts/gov/transactions.ts +599 -271
- package/src/contracts/gov/types-new.ts +253 -100
- package/src/contracts/gov/types.ts +4 -71
- package/src/contracts/iasset/helpers.ts +172 -0
- package/src/contracts/iasset/scripts.ts +38 -0
- package/src/contracts/iasset/types.ts +154 -0
- package/src/contracts/initialize/actions.ts +768 -0
- package/src/contracts/initialize/helpers.ts +611 -36
- package/src/contracts/initialize/types.ts +102 -28
- package/src/contracts/interest-collection/helpers.ts +19 -0
- package/src/contracts/interest-collection/scripts.ts +44 -0
- package/src/contracts/interest-collection/transactions.ts +436 -0
- package/src/contracts/interest-collection/types-new.ts +50 -0
- package/src/contracts/interest-collection/types.ts +26 -0
- package/src/contracts/interest-oracle/helpers.ts +2 -30
- package/src/contracts/interest-oracle/scripts.ts +1 -1
- package/src/contracts/interest-oracle/transactions.ts +21 -16
- package/src/contracts/interest-oracle/types-new.ts +32 -0
- package/src/contracts/interest-oracle/types.ts +1 -40
- package/src/contracts/one-shot/transactions.ts +1 -2
- package/src/contracts/poll/helpers.ts +5 -23
- package/src/contracts/poll/scripts.ts +12 -13
- package/src/contracts/poll/types-poll-manager.ts +1 -19
- package/src/contracts/poll/types-poll-new.ts +170 -0
- package/src/contracts/poll/types-poll-shard.ts +2 -24
- package/src/contracts/price-oracle/helpers.ts +1 -4
- package/src/contracts/price-oracle/scripts.ts +3 -8
- package/src/contracts/price-oracle/transactions.ts +32 -25
- package/src/contracts/price-oracle/types-new.ts +50 -0
- package/src/contracts/price-oracle/types.ts +2 -36
- package/src/contracts/pyth-feed/helpers.ts +58 -0
- package/src/contracts/pyth-feed/scripts.ts +15 -0
- package/src/contracts/pyth-feed/types.ts +181 -0
- package/src/contracts/rob/helpers.ts +405 -0
- package/src/contracts/rob/scripts.ts +35 -0
- package/src/contracts/rob/transactions.ts +410 -0
- package/src/contracts/rob/types-new.ts +128 -0
- package/src/contracts/rob/types.ts +16 -0
- package/src/contracts/rob-leverage/helpers.ts +424 -0
- package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
- package/src/contracts/stability-pool/helpers.ts +714 -230
- package/src/contracts/stability-pool/scripts.ts +20 -15
- package/src/contracts/stability-pool/transactions.ts +628 -496
- package/src/contracts/stability-pool/types-new.ts +247 -100
- package/src/contracts/stability-pool/types.ts +5 -22
- package/src/contracts/stableswap/helpers.ts +22 -0
- package/src/contracts/stableswap/scripts.ts +37 -0
- package/src/contracts/stableswap/transactions.ts +647 -0
- package/src/contracts/stableswap/types-new.ts +131 -0
- package/src/contracts/stableswap/types.ts +17 -0
- package/src/contracts/staking/helpers.ts +49 -34
- package/src/contracts/staking/scripts.ts +1 -1
- package/src/contracts/staking/transactions.ts +85 -130
- package/src/contracts/staking/types-new.ts +60 -28
- package/src/contracts/staking/types.ts +1 -28
- package/src/contracts/treasury/helpers.ts +21 -0
- package/src/contracts/treasury/scripts.ts +16 -26
- package/src/contracts/treasury/transactions.ts +256 -27
- package/src/contracts/treasury/types-new.ts +69 -0
- package/src/contracts/treasury/types.ts +2 -43
- package/src/contracts/version-registry/scripts.ts +2 -2
- package/src/contracts/version-registry/types-new.ts +6 -7
- package/src/index.ts +37 -20
- package/src/scripts/auth-token-policy.ts +3 -2
- package/src/scripts/iasset-policy.ts +3 -2
- package/src/types/evolution-schema-options.ts +3 -3
- package/src/types/generic.ts +17 -89
- package/src/types/multisig.ts +48 -0
- package/src/types/on-chain-decimal.ts +14 -7
- package/src/types/rational.ts +61 -0
- package/src/types/system-params.ts +237 -41
- package/src/utils/array-utils.ts +70 -1
- package/src/utils/bigint-utils.ts +12 -0
- package/src/utils/indigo-helpers.ts +8 -10
- package/src/utils/lucid-utils.ts +47 -40
- package/src/utils/oracle-helpers.ts +62 -0
- package/src/utils/pyth/decode.ts +223 -0
- package/src/utils/pyth/encode.ts +262 -0
- package/src/utils/pyth/index.ts +14 -0
- package/src/utils/pyth/types.ts +87 -0
- package/src/validators/always-succeed-validator.ts +6 -0
- package/src/validators/cdp-creator-validator.ts +2 -2
- package/src/validators/cdp-redeem-validator.ts +7 -0
- package/src/validators/cdp-validator.ts +2 -2
- package/src/validators/collector-validator.ts +2 -2
- package/src/validators/execute-validator.ts +2 -2
- package/src/validators/governance-validator.ts +2 -2
- package/src/validators/iasset-validator.ts +7 -0
- package/src/validators/interest-collection-validator.ts +7 -0
- package/src/validators/interest-oracle-validator.ts +2 -2
- package/src/validators/poll-manager-validator.ts +2 -2
- package/src/validators/poll-shard-validator.ts +2 -2
- package/src/validators/price-oracle-validator.ts +7 -0
- package/src/validators/pyth-feed-validator.ts +7 -0
- package/src/validators/rob-validator.ts +7 -0
- package/src/validators/stability-pool-validator.ts +2 -2
- package/src/validators/stableswap-validator.ts +7 -0
- package/src/validators/staking-validator.ts +2 -2
- package/src/validators/treasury-validator.ts +2 -2
- package/src/validators/version-record-policy.ts +2 -2
- package/src/validators/version-registry-validator.ts +2 -2
- package/tests/always-succeed/script.ts +7 -0
- package/tests/bigint-utils.test.ts +41 -0
- package/tests/cdp/actions.ts +610 -0
- package/tests/cdp/cdp-helpers.ts +55 -0
- package/tests/cdp/cdp-queries.ts +440 -0
- package/tests/cdp/cdp.test.ts +6087 -0
- package/tests/cdp/transactions-mutated.ts +1729 -0
- package/tests/data/system-params.json +177 -34
- package/tests/datums.test.ts +209 -210
- package/tests/endpoints/initialize.ts +68 -0
- package/tests/endpoints/interest-collector.ts +37 -0
- package/tests/endpoints/treasury.ts +70 -0
- package/tests/gov/actions.ts +406 -0
- package/tests/gov/gov.test.ts +4450 -0
- package/tests/{queries → gov}/governance-queries.ts +6 -3
- package/tests/hash-checks.test.ts +38 -11
- package/tests/indigo-test-helpers.ts +100 -0
- package/tests/initialize.test.ts +61 -9
- package/tests/interest-collection/interest-collection.test.ts +892 -0
- package/tests/interest-collection/interest-collector-queries.ts +49 -0
- package/tests/interest-collection/transactions-mutated.ts +260 -0
- package/tests/interest-oracle.test.ts +43 -35
- package/tests/mock/assets-mock.ts +234 -23
- package/tests/mock/protocol-params-mock.ts +21 -0
- package/tests/price-oracle/actions.ts +163 -0
- package/tests/price-oracle/price-oracle-queries.ts +12 -0
- package/tests/price-oracle/price-oracle.test.ts +240 -0
- package/tests/price-oracle/transactions-mutated.ts +62 -0
- package/tests/pyth/endpoints.ts +96 -0
- package/tests/pyth/helpers.ts +37 -0
- package/tests/pyth/pyth-encoding.test.ts +376 -0
- package/tests/pyth/pyth-indigo.test.ts +509 -0
- package/tests/pyth/pyth.test.ts +300 -0
- package/tests/queries/execute-queries.ts +6 -5
- package/tests/queries/iasset-queries.ts +175 -5
- package/tests/queries/interest-oracle-queries.ts +4 -2
- package/tests/queries/poll-queries.ts +8 -9
- package/tests/queries/stability-pool-queries.ts +95 -48
- package/tests/queries/staking-queries.ts +4 -2
- package/tests/queries/treasury-queries.ts +80 -5
- package/tests/rob/actions.ts +58 -0
- package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
- package/tests/rob/rob-queries.ts +95 -0
- package/tests/rob/rob.test.ts +3762 -0
- package/tests/rob/transactions-mutated.ts +853 -0
- package/tests/script-size.test.ts +240 -0
- package/tests/setup.ts +135 -0
- package/tests/stability-pool/actions.ts +220 -0
- package/tests/stability-pool.test.ts +6121 -667
- package/tests/stableswap/stableswap-actions.ts +84 -0
- package/tests/stableswap/stableswap-queries.ts +89 -0
- package/tests/stableswap/stableswap.test.ts +3891 -0
- package/tests/stableswap/transactions-mutated.ts +348 -0
- package/tests/staking.test.ts +82 -99
- package/tests/test-helpers.ts +58 -11
- package/tests/treasury.test.ts +242 -0
- package/tests/utils/asserts.ts +74 -0
- package/tests/utils/benchmark-utils.ts +81 -0
- package/tests/utils/index.ts +122 -4
- package/tsconfig.json +9 -1
- package/vitest.config.ts +3 -1
- package/src/contracts/collector/types.ts +0 -16
- package/src/contracts/initialize/transactions.ts +0 -891
- package/src/contracts/leverage/helpers.ts +0 -424
- package/src/contracts/lrp/helpers.ts +0 -294
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/lrp/transactions.ts +0 -250
- package/src/contracts/lrp/types.ts +0 -131
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/vesting/helpers.ts +0 -218
- package/src/utils/value-helpers.ts +0 -37
- package/src/validators/lrp-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1528
- package/tests/gov.test.ts +0 -2011
- package/tests/lrp.test.ts +0 -673
- package/tests/queries/cdp-queries.ts +0 -220
- package/tests/queries/lrp-queries.ts +0 -76
- package/tests/queries/price-oracle-queries.ts +0 -10
|
@@ -0,0 +1,240 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
2
|
+
import {
|
|
3
|
+
LucidEvolution,
|
|
4
|
+
TxBuilder,
|
|
5
|
+
unixTimeToSlot,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
import {
|
|
8
|
+
addrDetails,
|
|
9
|
+
requestSpAccountAdjustment,
|
|
10
|
+
bigintMax,
|
|
11
|
+
requestSpAccountClosure,
|
|
12
|
+
createE2s2sSnapshots,
|
|
13
|
+
requestSpAccountCreation,
|
|
14
|
+
fromSystemParamsAsset,
|
|
15
|
+
openCdp,
|
|
16
|
+
processSpRequest,
|
|
17
|
+
SystemParams,
|
|
18
|
+
} from '../../src';
|
|
19
|
+
import {
|
|
20
|
+
findAllNecessaryOrefs,
|
|
21
|
+
findPriceOracleFromCollateralAsset,
|
|
22
|
+
} from '../cdp/cdp-queries';
|
|
23
|
+
import {
|
|
24
|
+
findE2s2sSnapshots,
|
|
25
|
+
findStabilityPool,
|
|
26
|
+
findStabilityPoolAccount,
|
|
27
|
+
} from '../queries/stability-pool-queries';
|
|
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
|
+
context.emulator.slot,
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return requestSpAccountCreation(
|
|
98
|
+
asset,
|
|
99
|
+
spDepositAmount,
|
|
100
|
+
sysParams,
|
|
101
|
+
context.lucid,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function waitForAccountCooldown(
|
|
106
|
+
context: LucidContext,
|
|
107
|
+
sysParams: SystemParams,
|
|
108
|
+
asset: string,
|
|
109
|
+
// Request owner
|
|
110
|
+
pkh: string,
|
|
111
|
+
) {
|
|
112
|
+
const accountUtxo = await findStabilityPoolAccount(
|
|
113
|
+
context.lucid,
|
|
114
|
+
sysParams,
|
|
115
|
+
pkh,
|
|
116
|
+
asset,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (accountUtxo.datum.lastRequestProcessingTime !== 0n) {
|
|
120
|
+
const targetSlot = unixTimeToSlot(
|
|
121
|
+
context.lucid.config().network!,
|
|
122
|
+
Number(accountUtxo.datum.lastRequestProcessingTime) +
|
|
123
|
+
sysParams.stabilityPoolParams.accountProcessingCooldownMs,
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
if (targetSlot > context.emulator.slot) {
|
|
127
|
+
expect(targetSlot).toBeGreaterThan(context.emulator.slot);
|
|
128
|
+
|
|
129
|
+
context.emulator.awaitSlot(targetSlot - context.emulator.slot + 2);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function runProcessSpRequest(
|
|
135
|
+
context: LucidContext,
|
|
136
|
+
sysParams: SystemParams,
|
|
137
|
+
asset: string,
|
|
138
|
+
// Request owner
|
|
139
|
+
pkh: string,
|
|
140
|
+
): Promise<TxBuilder> {
|
|
141
|
+
const sp = await findStabilityPool(context.lucid, sysParams, asset);
|
|
142
|
+
|
|
143
|
+
const ia = await findIAsset(
|
|
144
|
+
context.lucid,
|
|
145
|
+
sysParams.validatorHashes.iassetHash,
|
|
146
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
|
|
147
|
+
asset,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
const accountUtxo = await findStabilityPoolAccount(
|
|
151
|
+
context.lucid,
|
|
152
|
+
sysParams,
|
|
153
|
+
pkh,
|
|
154
|
+
asset,
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
await waitForAccountCooldown(context, sysParams, asset, pkh);
|
|
158
|
+
|
|
159
|
+
return processSpRequest(
|
|
160
|
+
sp.utxo,
|
|
161
|
+
accountUtxo.utxo,
|
|
162
|
+
ia.utxo,
|
|
163
|
+
(await findE2s2sSnapshots(context.lucid, sysParams, asset)).map(
|
|
164
|
+
(res) => res.utxo,
|
|
165
|
+
),
|
|
166
|
+
sysParams,
|
|
167
|
+
context.lucid,
|
|
168
|
+
context.emulator.slot,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export async function runCreateAdjustRequest(
|
|
173
|
+
lucid: LucidEvolution,
|
|
174
|
+
sysParams: SystemParams,
|
|
175
|
+
asset: string,
|
|
176
|
+
adjustment: bigint,
|
|
177
|
+
): Promise<TxBuilder> {
|
|
178
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
179
|
+
|
|
180
|
+
const accountUtxo = await findStabilityPoolAccount(
|
|
181
|
+
lucid,
|
|
182
|
+
sysParams,
|
|
183
|
+
pkh.hash,
|
|
184
|
+
asset,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
return requestSpAccountAdjustment(
|
|
188
|
+
adjustment,
|
|
189
|
+
accountUtxo.utxo,
|
|
190
|
+
sysParams,
|
|
191
|
+
lucid,
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export async function runCreateCloseRequest(
|
|
196
|
+
lucid: LucidEvolution,
|
|
197
|
+
sysParams: SystemParams,
|
|
198
|
+
asset: string,
|
|
199
|
+
): Promise<TxBuilder> {
|
|
200
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
201
|
+
|
|
202
|
+
const accountUtxo = await findStabilityPoolAccount(
|
|
203
|
+
lucid,
|
|
204
|
+
sysParams,
|
|
205
|
+
pkh.hash,
|
|
206
|
+
asset,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return requestSpAccountClosure(accountUtxo.utxo, sysParams, lucid);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export async function runCreateE2s2sSnapshots(
|
|
213
|
+
context: LucidContext,
|
|
214
|
+
sysParams: SystemParams,
|
|
215
|
+
asset: string,
|
|
216
|
+
): Promise<TxBuilder> {
|
|
217
|
+
const spUtxo = await findStabilityPool(context.lucid, sysParams, asset);
|
|
218
|
+
|
|
219
|
+
return createE2s2sSnapshots(spUtxo.utxo, sysParams, context.lucid);
|
|
220
|
+
}
|