@indigo-labs/indigo-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 (93) 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/.prettierrc +1 -1
  5. package/README.md +52 -7
  6. package/dist/index.d.mts +1064 -182
  7. package/dist/index.d.ts +1064 -182
  8. package/dist/index.js +2565 -561
  9. package/dist/index.mjs +2546 -593
  10. package/eslint.config.mjs +35 -0
  11. package/package.json +61 -43
  12. package/src/contracts/cdp.ts +208 -359
  13. package/src/contracts/collector.ts +13 -6
  14. package/src/contracts/gov.ts +1 -58
  15. package/src/contracts/interest-oracle.ts +139 -39
  16. package/src/contracts/lrp.ts +223 -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 +30 -13
  21. package/src/helpers/asset-helpers.ts +51 -22
  22. package/src/helpers/helper-txs.ts +30 -0
  23. package/src/helpers/helpers.ts +29 -8
  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 +62 -16
  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 -3
  31. package/src/helpers/value-helpers.ts +16 -0
  32. package/src/index.ts +15 -4
  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 +46 -2
  36. package/src/scripts/collector-validator.ts +2 -2
  37. package/src/scripts/execute-validator.ts +52 -0
  38. package/src/scripts/gov-validator.ts +44 -0
  39. package/src/scripts/iasset-policy.ts +22 -0
  40. package/src/scripts/interest-oracle-validator.ts +18 -3
  41. package/src/scripts/lrp-validator.ts +23 -0
  42. package/src/scripts/one-shot-policy.ts +62 -0
  43. package/src/scripts/poll-manager-validator.ts +52 -0
  44. package/src/scripts/poll-shard-validator.ts +47 -0
  45. package/src/scripts/price-oracle-validator.ts +26 -0
  46. package/src/scripts/stability-pool-validator.ts +60 -0
  47. package/src/scripts/staking-validator.ts +8 -0
  48. package/src/scripts/version-record-policy.ts +26 -0
  49. package/src/scripts/version-registry.ts +15 -0
  50. package/src/types/generic.ts +99 -6
  51. package/src/types/indigo/cdp-creator.ts +46 -0
  52. package/src/types/indigo/cdp.ts +86 -31
  53. package/src/types/indigo/execute.ts +21 -0
  54. package/src/types/indigo/gov.ts +50 -20
  55. package/src/types/indigo/interest-oracle.ts +55 -5
  56. package/src/types/indigo/lrp.ts +54 -0
  57. package/src/types/indigo/poll-manager.ts +21 -0
  58. package/src/types/indigo/poll-shard.ts +16 -0
  59. package/src/types/indigo/price-oracle.ts +38 -4
  60. package/src/types/indigo/stability-pool.ts +233 -0
  61. package/src/types/indigo/staking.ts +99 -0
  62. package/src/types/indigo/version-record.ts +17 -0
  63. package/src/types/on-chain-decimal.ts +23 -0
  64. package/src/types/one-shot.ts +22 -0
  65. package/src/types/system-params.ts +95 -77
  66. package/tests/data/system-params.json +972 -972
  67. package/tests/datums.test.ts +279 -44
  68. package/tests/endpoints/initialize.ts +1013 -0
  69. package/tests/hash-checks.test.ts +71 -15
  70. package/tests/indigo-test-helpers.ts +115 -0
  71. package/tests/initialize.test.ts +27 -0
  72. package/tests/interest-calculations.test.ts +110 -133
  73. package/tests/interest-oracle.test.ts +90 -0
  74. package/tests/lrp.test.ts +149 -0
  75. package/tests/queries/governance-queries.ts +31 -0
  76. package/tests/queries/iasset-queries.ts +39 -0
  77. package/tests/queries/interest-oracle-queries.ts +13 -0
  78. package/tests/queries/lrp-queries.ts +39 -0
  79. package/tests/queries/price-oracle-queries.ts +27 -0
  80. package/tests/queries/stability-pool-queries.ts +75 -0
  81. package/tests/queries/staking-queries.ts +43 -0
  82. package/tests/stability-pool.test.ts +364 -0
  83. package/tests/staking.test.ts +105 -0
  84. package/tests/test-helpers.ts +38 -0
  85. package/tsconfig.build.json +4 -0
  86. package/tsconfig.json +8 -27
  87. package/vitest.config.ts +9 -0
  88. package/babel.config.cjs +0 -13
  89. package/examples/sample-cdp.ts +0 -43
  90. package/jest.config.js +0 -13
  91. package/src/contracts/cdp-creator.ts +0 -86
  92. package/src/contracts/price-oracle.ts +0 -24
  93. package/src/helpers/cdp-helpers.ts +0 -9
@@ -1,17 +1,73 @@
1
- import { loadSystemParamsFromFile, loadSystemParamsFromUrl } from '../src/helpers';
2
- import { CDPCreatorContract } from '../src/contracts/cdp-creator';
3
- import { CDPContract, SystemParams } from '../src';
4
- import { CollectorContract } from '../src/contracts/collector';
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ loadSystemParamsFromFile,
4
+ StakingContract,
5
+ CollectorContract,
6
+ CDPContract,
7
+ mkCDPCreatorValidatorFromSP,
8
+ mkInterestOracleValidator,
9
+ } from '../src';
10
+ import { validatorToScriptHash } from '@lucid-evolution/lucid';
11
+ import { mkStabilityPoolValidatorFromSP } from '../src/scripts/stability-pool-validator';
12
+ import { mkGovValidatorFromSP } from '../src/scripts/gov-validator';
13
+
14
+ const systemParams = loadSystemParamsFromFile(
15
+ './tests/data/system-params.json',
16
+ );
5
17
 
6
- const systemParams = loadSystemParamsFromFile('./tests/data/system-params.json');
7
18
  describe('Validator Hash checks', () => {
8
- it('CDP Creator validator hash', () => {
9
- expect(CDPCreatorContract.validatorHash(systemParams.cdpCreatorParams)).toBe(systemParams.validatorHashes.cdpCreatorHash);
10
- });
11
- it('CDP validator hash', () => {
12
- expect(CDPContract.validatorHash(systemParams.cdpParams)).toBe(systemParams.validatorHashes.cdpHash);
13
- });
14
- it('Collector validator hash', () => {
15
- expect(CollectorContract.validatorHash(systemParams.collectorParams)).toBe(systemParams.validatorHashes.collectorHash);
16
- });
17
- })
19
+ it('CDP Creator validator hash', () => {
20
+ expect(
21
+ validatorToScriptHash(
22
+ mkCDPCreatorValidatorFromSP(systemParams.cdpCreatorParams),
23
+ ),
24
+ ).toBe(systemParams.validatorHashes.cdpCreatorHash);
25
+ });
26
+ it('CDP validator hash', () => {
27
+ expect(CDPContract.validatorHash(systemParams.cdpParams)).toBe(
28
+ systemParams.validatorHashes.cdpHash,
29
+ );
30
+ });
31
+ it('Collector validator hash', () => {
32
+ expect(CollectorContract.validatorHash(systemParams.collectorParams)).toBe(
33
+ systemParams.validatorHashes.collectorHash,
34
+ );
35
+ });
36
+ // TODO: Revisit this test, issues with cbor encoding on Lucid?
37
+ // Applying parameters to the validator using `aiken build` does not result in the same hash as the one generate by Lucid.
38
+ // it('Execute validator hash', () => {
39
+ // expect(
40
+ // validatorToScriptHash(mkExecuteValidatorFromSP(systemParams.executeParams)),
41
+ // ).toBe(
42
+ // systemParams.validatorHashes.executeHash,
43
+ // );
44
+ // });
45
+ it('Gov validator hash', () => {
46
+ expect(
47
+ validatorToScriptHash(mkGovValidatorFromSP(systemParams.govParams)),
48
+ ).toBe(systemParams.validatorHashes.govHash);
49
+ });
50
+ it('Staking validator hash', () => {
51
+ expect(StakingContract.validatorHash(systemParams.stakingParams)).toBe(
52
+ systemParams.validatorHashes.stakingHash,
53
+ );
54
+ });
55
+ it('Stability Pool validator hash', () => {
56
+ expect(
57
+ validatorToScriptHash(
58
+ mkStabilityPoolValidatorFromSP(systemParams.stabilityPoolParams),
59
+ ),
60
+ ).toBe(systemParams.validatorHashes.stabilityPoolHash);
61
+ });
62
+
63
+ it('Interest Oracle validator hash', () => {
64
+ expect(
65
+ validatorToScriptHash(
66
+ mkInterestOracleValidator({
67
+ biasTime: 1_200_000n,
68
+ owner: 'a962c79bd58fc9fcecd78f8a963e0ce80e907264cd86cd5814d87333',
69
+ }),
70
+ ),
71
+ ).toBe('b970b3e0e1b591840627e6919898c12ee57e2f0225ab03e056d10d52');
72
+ });
73
+ });
@@ -0,0 +1,115 @@
1
+ import {
2
+ Assets,
3
+ fromText,
4
+ LucidEvolution,
5
+ Network,
6
+ ScriptHash,
7
+ toUnit,
8
+ } from '@lucid-evolution/lucid';
9
+ import { createScriptAddress } from '../src/helpers/lucid-utils';
10
+ import {
11
+ AssetClass,
12
+ IAssetContent,
13
+ OracleAssetNft,
14
+ PriceOracleParams,
15
+ runOneShotMintTx,
16
+ serialiseIAssetDatum,
17
+ serialisePriceOracleDatum,
18
+ } from '../src';
19
+ import { OnChainDecimal } from '../src/types/on-chain-decimal';
20
+
21
+ export async function runStartPriceOracle(
22
+ lucid: LucidEvolution,
23
+ oracleScriptHash: ScriptHash,
24
+ oracleParams: PriceOracleParams,
25
+ network: Network,
26
+ // Hex encoded
27
+ oracleNftTokenName: string,
28
+ price: OnChainDecimal,
29
+ ): Promise<OracleAssetNft> {
30
+ const utxos = await lucid.wallet().getUtxos();
31
+
32
+ const nftPolicyId = await runOneShotMintTx(lucid, {
33
+ referenceOutRef: {
34
+ txHash: utxos[0].txHash,
35
+ outputIdx: BigInt(utxos[0].outputIndex),
36
+ },
37
+ mintAmounts: [{ tokenName: oracleNftTokenName, amount: 1n }],
38
+ });
39
+
40
+ const nftValue: Assets = { [toUnit(nftPolicyId, oracleNftTokenName)]: 1n };
41
+
42
+ const txHash = await lucid
43
+ .newTx()
44
+ .pay.ToContract(
45
+ createScriptAddress(network, oracleScriptHash),
46
+ {
47
+ kind: 'inline',
48
+ value: serialisePriceOracleDatum({
49
+ price: price,
50
+ expiration: BigInt(Date.now()) + oracleParams.expiration,
51
+ }),
52
+ },
53
+ nftValue,
54
+ )
55
+ .complete()
56
+ .then((tx) => tx.sign.withWallet().complete())
57
+ .then((tx) => tx.submit());
58
+
59
+ await lucid.awaitTx(txHash);
60
+
61
+ return {
62
+ oracleNft: {
63
+ asset: {
64
+ currencySymbol: nftPolicyId,
65
+ tokenName: oracleNftTokenName,
66
+ },
67
+ },
68
+ };
69
+ }
70
+
71
+ /**
72
+ * TODO: the NFT has to be minted using the auth policy based on execute NFT.
73
+ * This is just a mocked setup for test purposes.
74
+ *
75
+ * @returns NFT of the iAsset.
76
+ */
77
+ export async function runCreateIAsset(
78
+ lucid: LucidEvolution,
79
+ network: Network,
80
+ cdpScriptHash: ScriptHash,
81
+ iasset: IAssetContent,
82
+ ): Promise<AssetClass> {
83
+ const nftTokenName = fromText('IASSET_NFT');
84
+ const utxos = await lucid.wallet().getUtxos();
85
+ const nftPolicyId = await runOneShotMintTx(lucid, {
86
+ referenceOutRef: {
87
+ txHash: utxos[0].txHash,
88
+ outputIdx: BigInt(utxos[0].outputIndex),
89
+ },
90
+ mintAmounts: [{ tokenName: nftTokenName, amount: 1n }],
91
+ });
92
+
93
+ const nftValue: Assets = { [toUnit(nftPolicyId, nftTokenName)]: 1n };
94
+
95
+ const txHash = await lucid
96
+ .newTx()
97
+ .pay.ToContract(
98
+ createScriptAddress(network, cdpScriptHash),
99
+ {
100
+ kind: 'inline',
101
+ value: serialiseIAssetDatum(iasset),
102
+ },
103
+ nftValue,
104
+ )
105
+ .complete()
106
+ .then((tx) => tx.sign.withWallet().complete())
107
+ .then((tx) => tx.submit());
108
+
109
+ await lucid.awaitTx(txHash);
110
+
111
+ return {
112
+ currencySymbol: nftPolicyId,
113
+ tokenName: nftTokenName,
114
+ };
115
+ }
@@ -0,0 +1,27 @@
1
+ import { beforeEach, test } from 'vitest';
2
+ import { LucidContext } from './test-helpers';
3
+ import { 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
+
8
+ beforeEach<LucidContext>(async (context: LucidContext) => {
9
+ context.users = {
10
+ admin: generateEmulatorAccount({
11
+ lovelace: BigInt(100_000_000_000_000),
12
+ }),
13
+ };
14
+
15
+ context.emulator = new Emulator([context.users.admin]);
16
+
17
+ context.lucid = await Lucid(context.emulator, 'Custom');
18
+ });
19
+
20
+ test<LucidContext>('Initialize Protocol - can initialize', async ({
21
+ lucid,
22
+ users,
23
+ }: LucidContext) => {
24
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
25
+
26
+ await init(lucid);
27
+ });
@@ -1,143 +1,120 @@
1
- import { InterestOracleContract } from "../src/contracts/interest-oracle";
2
- import { oneDay } from "../src/helpers/time-helpers";
1
+ import { describe, expect, it } from 'vitest';
2
+ import { oneDay } from '../src/helpers/time-helpers';
3
+ import {
4
+ calculateAccruedInterest,
5
+ calculateUnitaryInterestSinceOracleLastUpdated,
6
+ } from '../src/helpers/interest-oracle';
3
7
 
4
8
  describe('Interest Calculations', () => {
5
- describe('Calculate Unitary Interest', () => {
6
- it('Should calculate the unitary interest correctly, 0', () => {
7
- expect(
8
- InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
9
- oneDay * 6n,
10
- {
11
- unitaryInterest: 684_931_506_849_315n,
12
- interestRate: 100_000n,
13
- lastUpdated: oneDay * 5n
14
- }
15
- )
16
- ).toBe(273_972_602_739_726n);
17
- });
9
+ describe('Calculate Unitary Interest', () => {
10
+ it('Should calculate the unitary interest correctly, 0', () => {
11
+ expect(
12
+ calculateUnitaryInterestSinceOracleLastUpdated(oneDay * 6n, {
13
+ unitaryInterest: 684_931_506_849_315n,
14
+ interestRate: { getOnChainInt: 100_000n },
15
+ lastUpdated: oneDay * 5n,
16
+ }),
17
+ ).toBe(273_972_602_739_726n);
18
+ });
18
19
 
19
- it('Should calculate the unitary interest correctly, 1', () => {
20
- expect(
21
- InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
22
- oneDay * 6n,
23
- {
24
- unitaryInterest: 0n,
25
- interestRate: 50_000n,
26
- lastUpdated: 0n
27
- }
28
- )
29
- ).toBe(821_917_808_219_178n);
30
- });
20
+ it('Should calculate the unitary interest correctly, 1', () => {
21
+ expect(
22
+ calculateUnitaryInterestSinceOracleLastUpdated(oneDay * 6n, {
23
+ unitaryInterest: 0n,
24
+ interestRate: { getOnChainInt: 50_000n },
25
+ lastUpdated: 0n,
26
+ }),
27
+ ).toBe(821_917_808_219_178n);
28
+ });
31
29
 
32
- it('Should calculate the unitary interest correctly, 2', () => {
33
- expect(
34
- InterestOracleContract.calculateUnitaryInterestSinceOracleLastUpdated(
35
- 1n,
36
- {
37
- unitaryInterest: 0n,
38
- interestRate: 1n,
39
- lastUpdated: 0n
40
- }
41
- )
42
- ).toBe(31n);
43
- });
44
- })
30
+ it('Should calculate the unitary interest correctly, 2', () => {
31
+ expect(
32
+ calculateUnitaryInterestSinceOracleLastUpdated(1n, {
33
+ unitaryInterest: 0n,
34
+ interestRate: { getOnChainInt: 1n },
35
+ lastUpdated: 0n,
36
+ }),
37
+ ).toBe(31n);
38
+ });
39
+ });
45
40
 
46
- describe('Calculate Accumulated Interest', () => {
47
- it('Should calculate the accumulated interest correctly, 0', () => {
48
- expect(
49
- InterestOracleContract.calculateAccruedInterest(
50
- oneDay,
51
- 0n,
52
- 1_000_000n,
53
- 0n,
54
- {
55
- unitaryInterest: 0n,
56
- interestRate: 50_000n,
57
- lastUpdated: 0n
58
- }
59
- )
60
- ).toBe(136n)
61
- });
41
+ describe('Calculate Accumulated Interest', () => {
42
+ it('Should calculate the accumulated interest correctly, 0', () => {
43
+ expect(
44
+ calculateAccruedInterest(oneDay, 0n, 1_000_000n, 0n, {
45
+ unitaryInterest: 0n,
46
+ interestRate: { getOnChainInt: 50_000n },
47
+ lastUpdated: 0n,
48
+ }),
49
+ ).toBe(136n);
50
+ });
62
51
 
63
- it('Should calculate the accumulated interest correctly, 1', () => {
64
- expect(
65
- InterestOracleContract.calculateAccruedInterest(
66
- oneDay * 6n,
67
- 0n,
68
- 1_000_000n,
69
- 0n,
70
- {
71
- unitaryInterest: 684_931_506_849_315n,
72
- interestRate: 100_000n,
73
- lastUpdated: oneDay * 5n
74
- }
75
- )
76
- ).toBe(684n + 273n)
77
- });
52
+ it('Should calculate the accumulated interest correctly, 1', () => {
53
+ expect(
54
+ calculateAccruedInterest(oneDay * 6n, 0n, 1_000_000n, 0n, {
55
+ unitaryInterest: 684_931_506_849_315n,
56
+ interestRate: { getOnChainInt: 100_000n },
57
+ lastUpdated: oneDay * 5n,
58
+ }),
59
+ ).toBe(684n + 273n);
60
+ });
78
61
 
79
- it('Should calculate the accumulated interest correctly, 2', () => {
80
- expect(
81
- InterestOracleContract.calculateAccruedInterest(
82
- oneDay * 17n,
83
- 0n,
84
- 1_000_000n,
85
- 0n,
86
- {
87
- unitaryInterest: 1_506_849_315_068_493n,
88
- interestRate: 100_000n,
89
- lastUpdated: oneDay * 15n
90
- }
91
- )
92
- ).toBe(1506n + 547n)
93
- });
62
+ it('Should calculate the accumulated interest correctly, 2', () => {
63
+ expect(
64
+ calculateAccruedInterest(oneDay * 17n, 0n, 1_000_000n, 0n, {
65
+ unitaryInterest: 1_506_849_315_068_493n,
66
+ interestRate: { getOnChainInt: 100_000n },
67
+ lastUpdated: oneDay * 15n,
68
+ }),
69
+ ).toBe(1506n + 547n);
70
+ });
71
+
72
+ it('Should calculate the accumulated interest correctly, 3', () => {
73
+ expect(
74
+ calculateAccruedInterest(
75
+ oneDay * 17n,
76
+ 410_958_904_109_589n,
77
+ 1_000_000n,
78
+ oneDay * 3n,
79
+ {
80
+ unitaryInterest: 1_506_849_315_068_493n,
81
+ interestRate: { getOnChainInt: 100_000n },
82
+ lastUpdated: oneDay * 15n,
83
+ },
84
+ ),
85
+ ).toBe(1095n + 547n);
86
+ });
94
87
 
95
- it('Should calculate the accumulated interest correctly, 3', () => {
96
- expect(
97
- InterestOracleContract.calculateAccruedInterest(
98
- oneDay * 17n,
99
- 410_958_904_109_589n,
100
- 1_000_000n,
101
- oneDay * 3n,
102
- {
103
- unitaryInterest: 1_506_849_315_068_493n,
104
- interestRate: 100_000n,
105
- lastUpdated: oneDay * 15n
106
- }
107
- )
108
- ).toBe(1095n + 547n)
109
- });
88
+ it('Should calculate the accumulated interest correctly, 4', () => {
89
+ expect(
90
+ calculateAccruedInterest(
91
+ oneDay * 17n,
92
+ 767_123_287_671_232n,
93
+ 1_000_000n,
94
+ oneDay * 6n,
95
+ {
96
+ unitaryInterest: 1_506_849_315_068_493n,
97
+ interestRate: { getOnChainInt: 100_000n },
98
+ lastUpdated: oneDay * 15n,
99
+ },
100
+ ),
101
+ ).toBe(739n + 547n);
102
+ });
110
103
 
111
- it('Should calculate the accumulated interest correctly, 4', () => {
112
- expect(
113
- InterestOracleContract.calculateAccruedInterest(
114
- oneDay * 17n,
115
- 767_123_287_671_232n,
116
- 1_000_000n,
117
- oneDay * 6n,
118
- {
119
- unitaryInterest: 1_506_849_315_068_493n,
120
- interestRate: 100_000n,
121
- lastUpdated: oneDay * 15n
122
- }
123
- )
124
- ).toBe(739n + 547n)
125
- });
126
-
127
- it('Should calculate the accumulated interest correctly, 5', () => {
128
- expect(
129
- InterestOracleContract.calculateAccruedInterest(
130
- oneDay * 10n,
131
- 821_917_808_219_178n,
132
- 1_000_000n,
133
- oneDay * 6n,
134
- {
135
- unitaryInterest: 0n,
136
- interestRate: 50_000n,
137
- lastUpdated: 0n
138
- }
139
- )
140
- ).toBe(547n)
141
- });
104
+ it('Should calculate the accumulated interest correctly, 5', () => {
105
+ expect(
106
+ calculateAccruedInterest(
107
+ oneDay * 10n,
108
+ 821_917_808_219_178n,
109
+ 1_000_000n,
110
+ oneDay * 6n,
111
+ {
112
+ unitaryInterest: 0n,
113
+ interestRate: { getOnChainInt: 50_000n },
114
+ lastUpdated: 0n,
115
+ },
116
+ ),
117
+ ).toBe(547n);
142
118
  });
143
- });
119
+ });
120
+ });
@@ -0,0 +1,90 @@
1
+ import { afterEach, beforeEach, test } from 'vitest';
2
+ import {
3
+ LucidContext,
4
+ runAndAwaitTx,
5
+ runAndAwaitTxBuilder,
6
+ } from './test-helpers';
7
+ import { Lucid } from '@lucid-evolution/lucid';
8
+ import { Emulator } from '@lucid-evolution/lucid';
9
+ import { generateEmulatorAccount } from '@lucid-evolution/lucid';
10
+ import { addrDetails } from '../src/helpers/lucid-utils';
11
+ import { InterestOracleContract, InterestOracleParams } from '../src';
12
+ import { findInterestOracle } from './queries/interest-oracle-queries';
13
+
14
+ let originalDateNow: () => number;
15
+
16
+ beforeEach<LucidContext>(async (context: LucidContext) => {
17
+ context.users = {
18
+ user: generateEmulatorAccount({
19
+ lovelace: BigInt(100_000_000_000_000),
20
+ }),
21
+ };
22
+
23
+ context.emulator = new Emulator([context.users.user]);
24
+
25
+ context.lucid = await Lucid(context.emulator, 'Custom');
26
+
27
+ originalDateNow = Date.now;
28
+ Date.now = () => context.emulator.now();
29
+ });
30
+
31
+ afterEach(() => {
32
+ Date.now = originalDateNow;
33
+ });
34
+
35
+ test<LucidContext>('Interest Oracle - Start', async ({
36
+ lucid,
37
+ users,
38
+ }: LucidContext) => {
39
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
40
+
41
+ const [pkh, _] = await addrDetails(lucid);
42
+
43
+ const [tx, _ac] = await InterestOracleContract.startInterestOracle(
44
+ 0n,
45
+ 0n,
46
+ 0n,
47
+ {
48
+ biasTime: 120_000n,
49
+ owner: pkh.hash,
50
+ },
51
+ lucid,
52
+ );
53
+
54
+ await runAndAwaitTxBuilder(lucid, tx);
55
+ });
56
+
57
+ test<LucidContext>('Interest Oracle - Update', async ({
58
+ lucid,
59
+ users,
60
+ }: LucidContext) => {
61
+ lucid.selectWallet.fromSeed(users.user.seedPhrase);
62
+
63
+ const [pkh, _] = await addrDetails(lucid);
64
+ const interestParams: InterestOracleParams = {
65
+ biasTime: 120_000n,
66
+ owner: pkh.hash,
67
+ };
68
+
69
+ const [tx, assetClass] = await InterestOracleContract.startInterestOracle(
70
+ 0n,
71
+ 0n,
72
+ 0n,
73
+ interestParams,
74
+ lucid,
75
+ );
76
+
77
+ await runAndAwaitTxBuilder(lucid, tx);
78
+
79
+ const [utxo, _datum] = await findInterestOracle(lucid, assetClass);
80
+ await runAndAwaitTx(
81
+ lucid,
82
+ InterestOracleContract.feedInterestOracle(
83
+ interestParams,
84
+ 500_000n,
85
+ lucid,
86
+ undefined,
87
+ utxo,
88
+ ),
89
+ );
90
+ });