@indigo-labs/indigo-sdk 0.1.7 → 0.1.8

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/.github/workflows/ci.yml +62 -0
  2. package/.github/workflows/test.yml +44 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierrc +6 -0
  6. package/dist/index.d.mts +11 -1
  7. package/dist/index.d.ts +11 -1
  8. package/dist/index.js +15 -0
  9. package/dist/index.mjs +14 -0
  10. package/eslint.config.mjs +36 -0
  11. package/package.json +2 -5
  12. package/src/contracts/cdp.ts +741 -0
  13. package/src/contracts/collector.ts +98 -0
  14. package/src/contracts/gov.ts +1 -0
  15. package/src/contracts/interest-oracle.ts +149 -0
  16. package/src/contracts/lrp.ts +315 -0
  17. package/src/contracts/one-shot.ts +67 -0
  18. package/src/contracts/stability-pool.ts +684 -0
  19. package/src/contracts/staking.ts +348 -0
  20. package/src/contracts/treasury.ts +112 -0
  21. package/src/helpers/asset-helpers.ts +57 -0
  22. package/src/helpers/helper-txs.ts +30 -0
  23. package/src/helpers/helpers.ts +38 -0
  24. package/src/helpers/indigo-helpers.ts +19 -0
  25. package/src/helpers/interest-oracle.ts +57 -0
  26. package/src/helpers/lucid-utils.ts +70 -0
  27. package/src/helpers/price-oracle-helpers.ts +36 -0
  28. package/src/helpers/stability-pool-helpers.ts +207 -0
  29. package/src/helpers/staking-helpers.ts +94 -0
  30. package/src/helpers/time-helpers.ts +4 -0
  31. package/src/helpers/value-helpers.ts +27 -0
  32. package/src/index.ts +34 -0
  33. package/src/scripts/always-fail-validator.ts +7 -0
  34. package/src/scripts/auth-token-policy.ts +23 -0
  35. package/src/scripts/cdp-creator-validator.ts +53 -0
  36. package/src/scripts/cdp-validator.ts +9 -0
  37. package/src/scripts/collector-validator.ts +8 -0
  38. package/src/scripts/execute-validator.ts +52 -0
  39. package/src/scripts/gov-validator.ts +44 -0
  40. package/src/scripts/iasset-policy.ts +22 -0
  41. package/src/scripts/interest-oracle-validator.ts +23 -0
  42. package/src/scripts/lrp-validator.ts +40 -0
  43. package/src/scripts/one-shot-policy.ts +62 -0
  44. package/src/scripts/poll-manager-validator.ts +52 -0
  45. package/src/scripts/poll-shard-validator.ts +47 -0
  46. package/src/scripts/price-oracle-validator.ts +26 -0
  47. package/src/scripts/stability-pool-validator.ts +60 -0
  48. package/src/scripts/staking-validator.ts +8 -0
  49. package/src/scripts/treasury-validator.ts +8 -0
  50. package/src/scripts/version-record-policy.ts +26 -0
  51. package/src/scripts/version-registry.ts +15 -0
  52. package/src/types/generic.ts +106 -0
  53. package/src/types/indigo/cdp-creator.ts +46 -0
  54. package/src/types/indigo/cdp.ts +88 -0
  55. package/src/types/indigo/execute.ts +21 -0
  56. package/src/types/indigo/gov.ts +51 -0
  57. package/src/types/indigo/interest-oracle.ts +55 -0
  58. package/src/types/indigo/lrp.ts +59 -0
  59. package/src/types/indigo/poll-manager.ts +21 -0
  60. package/src/types/indigo/poll-shard.ts +16 -0
  61. package/src/types/indigo/price-oracle.ts +38 -0
  62. package/src/types/indigo/stability-pool.ts +233 -0
  63. package/src/types/indigo/staking.ts +99 -0
  64. package/src/types/indigo/version-record.ts +17 -0
  65. package/src/types/on-chain-decimal.ts +23 -0
  66. package/src/types/one-shot.ts +22 -0
  67. package/src/types/system-params.ts +256 -0
  68. package/tests/data/system-params.json +1012 -0
  69. package/tests/datums.test.ts +286 -0
  70. package/tests/endpoints/initialize.ts +1013 -0
  71. package/tests/hash-checks.test.ts +80 -0
  72. package/tests/indigo-test-helpers.ts +115 -0
  73. package/tests/initialize.test.ts +27 -0
  74. package/tests/interest-calculations.test.ts +120 -0
  75. package/tests/interest-oracle.test.ts +90 -0
  76. package/tests/lrp.test.ts +777 -0
  77. package/tests/queries/governance-queries.ts +31 -0
  78. package/tests/queries/iasset-queries.ts +39 -0
  79. package/tests/queries/interest-oracle-queries.ts +13 -0
  80. package/tests/queries/lrp-queries.ts +39 -0
  81. package/tests/queries/price-oracle-queries.ts +27 -0
  82. package/tests/queries/stability-pool-queries.ts +75 -0
  83. package/tests/queries/staking-queries.ts +43 -0
  84. package/tests/stability-pool.test.ts +364 -0
  85. package/tests/staking.test.ts +105 -0
  86. package/tests/test-helpers.ts +38 -0
  87. package/tsconfig.build.json +4 -0
  88. package/tsconfig.json +17 -0
  89. package/vitest.config.ts +9 -0
@@ -0,0 +1,31 @@
1
+ import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
2
+ import { createScriptAddress } from '../../src/helpers/lucid-utils';
3
+ import { AssetClass } from '../../src/types/generic';
4
+ import { assetClassToUnit } from '../../src/helpers/value-helpers';
5
+ import { matchSingle, parseGovDatum } from '../../src';
6
+
7
+ export async function findGov(
8
+ lucid: LucidEvolution,
9
+ govScriptHash: ScriptHash,
10
+ govNft: AssetClass,
11
+ ): Promise<UTxO> {
12
+ const govUtxos = await lucid.utxosAtWithUnit(
13
+ createScriptAddress(lucid.config().network, govScriptHash),
14
+ assetClassToUnit(govNft),
15
+ );
16
+
17
+ return matchSingle(
18
+ govUtxos.filter((utxo) => {
19
+ if (utxo.datum != null) {
20
+ try {
21
+ parseGovDatum(utxo.datum);
22
+ return true; // TODO: implement Gov Datum
23
+ } catch (_) {
24
+ // when incompatible datum
25
+ return false;
26
+ }
27
+ }
28
+ }),
29
+ (res) => new Error('Expected a single Gov UTXO.: ' + JSON.stringify(res)),
30
+ );
31
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ fromText,
3
+ LucidEvolution,
4
+ ScriptHash,
5
+ UTxO,
6
+ } from '@lucid-evolution/lucid';
7
+ import { createScriptAddress } from '../../src/helpers/lucid-utils';
8
+ import { AssetClass } from '../../src/types/generic';
9
+ import { assetClassToUnit } from '../../src/helpers/value-helpers';
10
+ import { matchSingle, parseIAssetDatum } from '../../src';
11
+
12
+ export async function findIAsset(
13
+ lucid: LucidEvolution,
14
+ iassetScriptHash: ScriptHash,
15
+ iassetNft: AssetClass,
16
+ iassetName: string,
17
+ ): Promise<UTxO> {
18
+ const iassetUtxos = await lucid.utxosAtWithUnit(
19
+ createScriptAddress(lucid.config().network, iassetScriptHash),
20
+ assetClassToUnit(iassetNft),
21
+ );
22
+
23
+ return matchSingle(
24
+ iassetUtxos.filter((utxo) => {
25
+ if (utxo.datum != null) {
26
+ try {
27
+ const iassetDatum = parseIAssetDatum(utxo.datum);
28
+
29
+ return iassetDatum.assetName == fromText(iassetName);
30
+ } catch (_) {
31
+ // when incompatible datum
32
+ return false;
33
+ }
34
+ }
35
+ }),
36
+ (res) =>
37
+ new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
38
+ );
39
+ }
@@ -0,0 +1,13 @@
1
+ import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
+ import { AssetClass } from '../../src/types/generic';
3
+ import { assetClassToUnit } from '../../src/helpers/value-helpers';
4
+ import { InterestOracleDatum, parseInterestOracleDatum } from '../../src';
5
+
6
+ export async function findInterestOracle(
7
+ lucid: LucidEvolution,
8
+ interestNft: AssetClass,
9
+ ): Promise<[UTxO, InterestOracleDatum]> {
10
+ const interestUtxo = await lucid.utxoByUnit(assetClassToUnit(interestNft));
11
+ if (!interestUtxo.datum) throw new Error('No interest oracle utxo found');
12
+ return [interestUtxo, parseInterestOracleDatum(interestUtxo.datum)];
13
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ Credential,
3
+ LucidEvolution,
4
+ Network,
5
+ ScriptHash,
6
+ UTxO,
7
+ } from '@lucid-evolution/lucid';
8
+ import { createScriptAddress } from '../../src/helpers/lucid-utils';
9
+ import { parseLrpDatum } from '../../src/types/indigo/lrp';
10
+
11
+ /**
12
+ * Beware, this shouldn't be used in production since it queries all the UTXOs
13
+ * at an address and does the filtering in this function.
14
+ */
15
+ export async function findLrp(
16
+ lucid: LucidEvolution,
17
+ network: Network,
18
+ lrpScriptHash: ScriptHash,
19
+ owner: string,
20
+ assetTokenName: string,
21
+ stakeCredential?: Credential,
22
+ ): Promise<UTxO[]> {
23
+ const lrpUtxos = await lucid.utxosAt(
24
+ createScriptAddress(network, lrpScriptHash, stakeCredential),
25
+ );
26
+
27
+ return lrpUtxos.filter((utxo) => {
28
+ if (utxo.datum != null) {
29
+ try {
30
+ const lrpDatum = parseLrpDatum(utxo.datum);
31
+
32
+ return lrpDatum.owner == owner && lrpDatum.iasset == assetTokenName;
33
+ } catch (_) {
34
+ // when incompatible datum
35
+ return false;
36
+ }
37
+ }
38
+ });
39
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ LucidEvolution,
3
+ Network,
4
+ OutRef,
5
+ ScriptHash,
6
+ toUnit,
7
+ } from '@lucid-evolution/lucid';
8
+ import { createScriptAddress, matchSingle, OracleAssetNft } from '../../src';
9
+
10
+ export async function findPriceOracle(
11
+ lucid: LucidEvolution,
12
+ network: Network,
13
+ oracleScriptHash: ScriptHash,
14
+ oracleNft: OracleAssetNft,
15
+ ): Promise<OutRef> {
16
+ return matchSingle(
17
+ await lucid.utxosAtWithUnit(
18
+ createScriptAddress(network, oracleScriptHash),
19
+ toUnit(
20
+ oracleNft.oracleNft.asset.currencySymbol,
21
+ oracleNft.oracleNft.asset.tokenName,
22
+ ),
23
+ ),
24
+ (res) =>
25
+ new Error('Expected a single Oracle UTXO.: ' + JSON.stringify(res)),
26
+ );
27
+ }
@@ -0,0 +1,75 @@
1
+ import {
2
+ fromText,
3
+ LucidEvolution,
4
+ ScriptHash,
5
+ UTxO,
6
+ } from '@lucid-evolution/lucid';
7
+ import { createScriptAddress } from '../../src/helpers/lucid-utils';
8
+ import { AssetClass } from '../../src/types/generic';
9
+ import { assetClassToUnit } from '../../src/helpers/value-helpers';
10
+ import {
11
+ matchSingle,
12
+ parseAccountDatum,
13
+ parseStabilityPoolDatum,
14
+ } from '../../src';
15
+
16
+ export async function findStabilityPool(
17
+ lucid: LucidEvolution,
18
+ stabilityPoolHash: ScriptHash,
19
+ stabilityPoolToken: AssetClass,
20
+ asset: string,
21
+ ): Promise<UTxO> {
22
+ const stakingUtxos = await lucid.utxosAtWithUnit(
23
+ createScriptAddress(lucid.config().network, stabilityPoolHash),
24
+ assetClassToUnit(stabilityPoolToken),
25
+ );
26
+
27
+ return matchSingle(
28
+ stakingUtxos.filter((utxo) => {
29
+ if (utxo.datum != null) {
30
+ try {
31
+ const stabilityPoolDatum = parseStabilityPoolDatum(utxo.datum);
32
+
33
+ return stabilityPoolDatum.asset == fromText(asset);
34
+ } catch (_) {
35
+ // when incompatible datum
36
+ return false;
37
+ }
38
+ }
39
+ }),
40
+ (res) =>
41
+ new Error(
42
+ 'Expected a single Stability Pool UTXO.: ' + JSON.stringify(res),
43
+ ),
44
+ );
45
+ }
46
+
47
+ export async function findStabilityPoolAccount(
48
+ lucid: LucidEvolution,
49
+ stabilityPoolHash: ScriptHash,
50
+ owner: string,
51
+ asset: string,
52
+ ): Promise<UTxO> {
53
+ const accountUtxos = await lucid.utxosAt(
54
+ createScriptAddress(lucid.config().network, stabilityPoolHash),
55
+ );
56
+
57
+ return matchSingle(
58
+ accountUtxos.filter((utxo) => {
59
+ if (utxo.datum != null) {
60
+ try {
61
+ const accountDatum = parseAccountDatum(utxo.datum);
62
+
63
+ return (
64
+ accountDatum.asset == fromText(asset) && accountDatum.owner == owner
65
+ );
66
+ } catch (_) {
67
+ // when incompatible datum
68
+ return false;
69
+ }
70
+ }
71
+ }),
72
+ (res) =>
73
+ new Error('Expected a single Account UTXO.: ' + JSON.stringify(res)),
74
+ );
75
+ }
@@ -0,0 +1,43 @@
1
+ import {
2
+ LucidEvolution,
3
+ Network,
4
+ OutRef,
5
+ ScriptHash,
6
+ } from '@lucid-evolution/lucid';
7
+ import { createScriptAddress } from '../../src/helpers/lucid-utils';
8
+ import { AssetClass } from '../../src/types/generic';
9
+ import { assetClassToUnit } from '../../src/helpers/value-helpers';
10
+ import { matchSingle } from '../../src';
11
+ import { parseStakingPositionDatum } from '../../src/types/indigo/staking';
12
+
13
+ export async function findStakingPosition(
14
+ lucid: LucidEvolution,
15
+ network: Network,
16
+ stakingScriptHash: ScriptHash,
17
+ stakingPositionNft: AssetClass,
18
+ owner: string,
19
+ ): Promise<OutRef> {
20
+ const stakingUtxos = await lucid.utxosAtWithUnit(
21
+ createScriptAddress(network, stakingScriptHash),
22
+ assetClassToUnit(stakingPositionNft),
23
+ );
24
+
25
+ return matchSingle(
26
+ stakingUtxos.filter((utxo) => {
27
+ if (utxo.datum != null) {
28
+ try {
29
+ const stakingDatum = parseStakingPositionDatum(utxo.datum);
30
+
31
+ return stakingDatum.owner == owner;
32
+ } catch (_) {
33
+ // when incompatible datum
34
+ return false;
35
+ }
36
+ }
37
+ }),
38
+ (res) =>
39
+ new Error(
40
+ 'Expected a single Staking Position UTXO.: ' + JSON.stringify(res),
41
+ ),
42
+ );
43
+ }
@@ -0,0 +1,364 @@
1
+ import { beforeEach, test, afterEach } from 'vitest';
2
+ import { LucidContext, runAndAwaitTx } from './test-helpers';
3
+ import { fromText, Lucid } from '@lucid-evolution/lucid';
4
+ import { Emulator } from '@lucid-evolution/lucid';
5
+ import { generateEmulatorAccount } from '@lucid-evolution/lucid';
6
+ import { init } from './endpoints/initialize';
7
+ import { addrDetails, CDPContract, StabilityPoolContract } from '../src';
8
+ import {
9
+ findStabilityPool,
10
+ findStabilityPoolAccount,
11
+ } from './queries/stability-pool-queries';
12
+ import { findIAsset } from './queries/iasset-queries';
13
+ import { findGov } from './queries/governance-queries';
14
+
15
+ let originalDateNow: () => number;
16
+
17
+ beforeEach<LucidContext>(async (context: LucidContext) => {
18
+ context.users = {
19
+ admin: generateEmulatorAccount({
20
+ lovelace: BigInt(100_000_000_000_000),
21
+ }),
22
+ user: generateEmulatorAccount({
23
+ lovelace: BigInt(100_000_000_000_000),
24
+ }),
25
+ };
26
+
27
+ context.emulator = new Emulator([context.users.admin, context.users.user]);
28
+
29
+ context.lucid = await Lucid(context.emulator, 'Custom');
30
+
31
+ originalDateNow = Date.now;
32
+ Date.now = () => context.emulator.now();
33
+ });
34
+
35
+ afterEach(() => {
36
+ Date.now = originalDateNow;
37
+ });
38
+
39
+ test<LucidContext>('Stability Pool - Create Account', async ({
40
+ lucid,
41
+ users,
42
+ }: LucidContext) => {
43
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
44
+ const systemParams = await init(lucid);
45
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
46
+ const [pkh, _] = await addrDetails(lucid);
47
+
48
+ await runAndAwaitTx(
49
+ lucid,
50
+ CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
51
+ );
52
+
53
+ await runAndAwaitTx(
54
+ lucid,
55
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
56
+ );
57
+
58
+ const stabilityPoolUtxo = await findStabilityPool(
59
+ lucid,
60
+ systemParams.validatorHashes.stabilityPoolHash,
61
+ {
62
+ currencySymbol:
63
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
64
+ tokenName: fromText(
65
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
66
+ ),
67
+ },
68
+ 'iUSD',
69
+ );
70
+
71
+ const accountUtxo = await findStabilityPoolAccount(
72
+ lucid,
73
+ systemParams.validatorHashes.stabilityPoolHash,
74
+ pkh.hash,
75
+ 'iUSD',
76
+ );
77
+
78
+ const assetUtxo = await findIAsset(
79
+ lucid,
80
+ systemParams.validatorHashes.cdpHash,
81
+ {
82
+ currencySymbol:
83
+ systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
84
+ tokenName: fromText(
85
+ systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
86
+ ),
87
+ },
88
+ 'iUSD',
89
+ );
90
+
91
+ const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
92
+ currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
93
+ tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
94
+ });
95
+
96
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
97
+
98
+ await runAndAwaitTx(
99
+ lucid,
100
+ StabilityPoolContract.processRequest(
101
+ 'iUSD',
102
+ stabilityPoolUtxo,
103
+ accountUtxo,
104
+ govUtxo,
105
+ assetUtxo,
106
+ undefined,
107
+ systemParams,
108
+ lucid,
109
+ ),
110
+ );
111
+ });
112
+
113
+ test<LucidContext>('Stability Pool - Adjust Account', async ({
114
+ lucid,
115
+ users,
116
+ }: LucidContext) => {
117
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
118
+ const systemParams = await init(lucid);
119
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
120
+ const [pkh, _] = await addrDetails(lucid);
121
+
122
+ await runAndAwaitTx(
123
+ lucid,
124
+ CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
125
+ );
126
+
127
+ await runAndAwaitTx(
128
+ lucid,
129
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
130
+ );
131
+
132
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
133
+
134
+ let stabilityPoolUtxo = await findStabilityPool(
135
+ lucid,
136
+ systemParams.validatorHashes.stabilityPoolHash,
137
+ {
138
+ currencySymbol:
139
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
140
+ tokenName: fromText(
141
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
142
+ ),
143
+ },
144
+ 'iUSD',
145
+ );
146
+
147
+ let accountUtxo = await findStabilityPoolAccount(
148
+ lucid,
149
+ systemParams.validatorHashes.stabilityPoolHash,
150
+ pkh.hash,
151
+ 'iUSD',
152
+ );
153
+
154
+ const assetUtxo = await findIAsset(
155
+ lucid,
156
+ systemParams.validatorHashes.cdpHash,
157
+ {
158
+ currencySymbol:
159
+ systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
160
+ tokenName: fromText(
161
+ systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
162
+ ),
163
+ },
164
+ 'iUSD',
165
+ );
166
+
167
+ const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
168
+ currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
169
+ tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
170
+ });
171
+
172
+ await runAndAwaitTx(
173
+ lucid,
174
+ StabilityPoolContract.processRequest(
175
+ 'iUSD',
176
+ stabilityPoolUtxo,
177
+ accountUtxo,
178
+ govUtxo,
179
+ assetUtxo,
180
+ undefined,
181
+ systemParams,
182
+ lucid,
183
+ ),
184
+ );
185
+
186
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
187
+
188
+ stabilityPoolUtxo = await findStabilityPool(
189
+ lucid,
190
+ systemParams.validatorHashes.stabilityPoolHash,
191
+ {
192
+ currencySymbol:
193
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
194
+ tokenName: fromText(
195
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
196
+ ),
197
+ },
198
+ 'iUSD',
199
+ );
200
+
201
+ accountUtxo = await findStabilityPoolAccount(
202
+ lucid,
203
+ systemParams.validatorHashes.stabilityPoolHash,
204
+ pkh.hash,
205
+ 'iUSD',
206
+ );
207
+
208
+ await runAndAwaitTx(
209
+ lucid,
210
+ StabilityPoolContract.adjustAccount(
211
+ 'iUSD',
212
+ 10n,
213
+ accountUtxo,
214
+ systemParams,
215
+ lucid,
216
+ ),
217
+ );
218
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
219
+
220
+ accountUtxo = await findStabilityPoolAccount(
221
+ lucid,
222
+ systemParams.validatorHashes.stabilityPoolHash,
223
+ pkh.hash,
224
+ 'iUSD',
225
+ );
226
+
227
+ await runAndAwaitTx(
228
+ lucid,
229
+ StabilityPoolContract.processRequest(
230
+ 'iUSD',
231
+ stabilityPoolUtxo,
232
+ accountUtxo,
233
+ govUtxo,
234
+ assetUtxo,
235
+ undefined,
236
+ systemParams,
237
+ lucid,
238
+ ),
239
+ );
240
+ });
241
+
242
+ test<LucidContext>('Stability Pool - Close Account', async ({
243
+ lucid,
244
+ users,
245
+ emulator,
246
+ }: LucidContext) => {
247
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
248
+ const systemParams = await init(lucid, emulator.now());
249
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
250
+ const [pkh, _] = await addrDetails(lucid);
251
+
252
+ await runAndAwaitTx(
253
+ lucid,
254
+ CDPContract.openPosition('iUSD', 1_000_000_000n, 20n, systemParams, lucid),
255
+ );
256
+
257
+ await runAndAwaitTx(
258
+ lucid,
259
+ StabilityPoolContract.createAccount('iUSD', 10n, systemParams, lucid),
260
+ );
261
+
262
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
263
+
264
+ let stabilityPoolUtxo = await findStabilityPool(
265
+ lucid,
266
+ systemParams.validatorHashes.stabilityPoolHash,
267
+ {
268
+ currencySymbol:
269
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
270
+ tokenName: fromText(
271
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
272
+ ),
273
+ },
274
+ 'iUSD',
275
+ );
276
+
277
+ let accountUtxo = await findStabilityPoolAccount(
278
+ lucid,
279
+ systemParams.validatorHashes.stabilityPoolHash,
280
+ pkh.hash,
281
+ 'iUSD',
282
+ );
283
+
284
+ const assetUtxo = await findIAsset(
285
+ lucid,
286
+ systemParams.validatorHashes.cdpHash,
287
+ {
288
+ currencySymbol:
289
+ systemParams.cdpParams.iAssetAuthToken[0].unCurrencySymbol,
290
+ tokenName: fromText(
291
+ systemParams.cdpParams.iAssetAuthToken[1].unTokenName,
292
+ ),
293
+ },
294
+ 'iUSD',
295
+ );
296
+
297
+ const govUtxo = await findGov(lucid, systemParams.validatorHashes.govHash, {
298
+ currencySymbol: systemParams.govParams.govNFT[0].unCurrencySymbol,
299
+ tokenName: fromText(systemParams.govParams.govNFT[1].unTokenName),
300
+ });
301
+
302
+ await runAndAwaitTx(
303
+ lucid,
304
+ StabilityPoolContract.processRequest(
305
+ 'iUSD',
306
+ stabilityPoolUtxo,
307
+ accountUtxo,
308
+ govUtxo,
309
+ assetUtxo,
310
+ undefined,
311
+ systemParams,
312
+ lucid,
313
+ ),
314
+ );
315
+
316
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
317
+
318
+ stabilityPoolUtxo = await findStabilityPool(
319
+ lucid,
320
+ systemParams.validatorHashes.stabilityPoolHash,
321
+ {
322
+ currencySymbol:
323
+ systemParams.stabilityPoolParams.stabilityPoolToken[0].unCurrencySymbol,
324
+ tokenName: fromText(
325
+ systemParams.stabilityPoolParams.stabilityPoolToken[1].unTokenName,
326
+ ),
327
+ },
328
+ 'iUSD',
329
+ );
330
+
331
+ accountUtxo = await findStabilityPoolAccount(
332
+ lucid,
333
+ systemParams.validatorHashes.stabilityPoolHash,
334
+ pkh.hash,
335
+ 'iUSD',
336
+ );
337
+
338
+ await runAndAwaitTx(
339
+ lucid,
340
+ StabilityPoolContract.closeAccount(accountUtxo, systemParams, lucid),
341
+ );
342
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
343
+
344
+ accountUtxo = await findStabilityPoolAccount(
345
+ lucid,
346
+ systemParams.validatorHashes.stabilityPoolHash,
347
+ pkh.hash,
348
+ 'iUSD',
349
+ );
350
+
351
+ await runAndAwaitTx(
352
+ lucid,
353
+ StabilityPoolContract.processRequest(
354
+ 'iUSD',
355
+ stabilityPoolUtxo,
356
+ accountUtxo,
357
+ govUtxo,
358
+ assetUtxo,
359
+ undefined,
360
+ systemParams,
361
+ lucid,
362
+ ),
363
+ );
364
+ });