@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,105 @@
1
+ import { beforeEach, test } 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 { StakingContract } from '../src/contracts/staking';
7
+ import { init } from './endpoints/initialize';
8
+ import { addrDetails } from '../src/helpers/lucid-utils';
9
+ import { findStakingPosition } from './queries/staking-queries';
10
+
11
+ beforeEach<LucidContext>(async (context: LucidContext) => {
12
+ context.users = {
13
+ admin: generateEmulatorAccount({
14
+ lovelace: BigInt(100_000_000_000_000),
15
+ }),
16
+ };
17
+
18
+ context.emulator = new Emulator([context.users.admin]);
19
+
20
+ context.lucid = await Lucid(context.emulator, 'Custom');
21
+ });
22
+
23
+ test<LucidContext>('Staking - Create Position', async ({
24
+ lucid,
25
+ users,
26
+ }: LucidContext) => {
27
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
28
+ const systemParams = await init(lucid);
29
+
30
+ await runAndAwaitTx(
31
+ lucid,
32
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
33
+ );
34
+ });
35
+
36
+ test<LucidContext>('Staking - Adjust Position', async ({
37
+ lucid,
38
+ users,
39
+ }: LucidContext) => {
40
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
41
+ const systemParams = await init(lucid);
42
+
43
+ await runAndAwaitTx(
44
+ lucid,
45
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
46
+ );
47
+
48
+ const [pkh, _] = await addrDetails(lucid);
49
+ const myStakingPosition = await findStakingPosition(
50
+ lucid,
51
+ lucid.config().network,
52
+ systemParams.validatorHashes.stakingHash,
53
+ {
54
+ currencySymbol:
55
+ systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
56
+ tokenName: fromText(
57
+ systemParams.stakingParams.stakingToken[1].unTokenName,
58
+ ),
59
+ },
60
+ pkh.hash,
61
+ );
62
+
63
+ await runAndAwaitTx(
64
+ lucid,
65
+ StakingContract.adjustPosition(
66
+ myStakingPosition,
67
+ 1_000_000n,
68
+ systemParams,
69
+ lucid,
70
+ ),
71
+ );
72
+ });
73
+
74
+ test<LucidContext>('Staking - Close Position', async ({
75
+ lucid,
76
+ users,
77
+ }: LucidContext) => {
78
+ lucid.selectWallet.fromSeed(users.admin.seedPhrase);
79
+ const systemParams = await init(lucid);
80
+
81
+ await runAndAwaitTx(
82
+ lucid,
83
+ StakingContract.openPosition(1_000_000n, systemParams, lucid),
84
+ );
85
+
86
+ const [pkh, _] = await addrDetails(lucid);
87
+ const myStakingPosition = await findStakingPosition(
88
+ lucid,
89
+ lucid.config().network,
90
+ systemParams.validatorHashes.stakingHash,
91
+ {
92
+ currencySymbol:
93
+ systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
94
+ tokenName: fromText(
95
+ systemParams.stakingParams.stakingToken[1].unTokenName,
96
+ ),
97
+ },
98
+ pkh.hash,
99
+ );
100
+
101
+ await runAndAwaitTx(
102
+ lucid,
103
+ StakingContract.closePosition(myStakingPosition, systemParams, lucid),
104
+ );
105
+ });
@@ -0,0 +1,38 @@
1
+ import {
2
+ Emulator,
3
+ EmulatorAccount,
4
+ LucidEvolution,
5
+ TxBuilder,
6
+ } from '@lucid-evolution/lucid';
7
+
8
+ export type LucidContext = {
9
+ lucid: LucidEvolution;
10
+ users: { [key: string]: EmulatorAccount };
11
+ emulator: Emulator;
12
+ };
13
+
14
+ export async function runAndAwaitTx(
15
+ lucid: LucidEvolution,
16
+ transaction: Promise<TxBuilder>,
17
+ ): Promise<string> {
18
+ const txHash = await transaction
19
+ .then((tx) => tx.complete())
20
+ .then((tx) => tx.sign.withWallet().complete())
21
+ .then((tx) => tx.submit());
22
+
23
+ await lucid.awaitTx(txHash);
24
+ return txHash;
25
+ }
26
+
27
+ export async function runAndAwaitTxBuilder(
28
+ lucid: LucidEvolution,
29
+ transaction: TxBuilder,
30
+ ): Promise<string> {
31
+ const txHash = await transaction
32
+ .complete()
33
+ .then((tx) => tx.sign.withWallet().complete())
34
+ .then((tx) => tx.submit());
35
+
36
+ await lucid.awaitTx(txHash);
37
+ return txHash;
38
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "exclude": ["spec/**/*.spec.ts", "vitest.config.ts"]
4
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "./dist",
4
+ "sourceMap": true,
5
+ "module": "nodenext",
6
+ "target": "ESNext",
7
+ "moduleResolution": "nodenext",
8
+ "allowUnreachableCode": true
9
+ },
10
+ "ts-node": {
11
+ "compilerOptions": {
12
+ "module": "ES2022"
13
+ }
14
+ },
15
+ "include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"],
16
+ "exclude": ["dist", "node_modules"]
17
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ testTimeout: 120000, // 2 minutes
6
+ reporters: 'verbose',
7
+ include: ['./tests/**/*.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
8
+ },
9
+ });