@indigo-labs/indigo-sdk 0.1.21 → 0.1.23

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 (135) hide show
  1. package/.github/workflows/ci.yml +3 -8
  2. package/.github/workflows/test.yml +44 -0
  3. package/dist/index.d.mts +670 -1291
  4. package/dist/index.d.ts +670 -1291
  5. package/dist/index.js +2240 -4669
  6. package/dist/index.mjs +2221 -4618
  7. package/eslint.config.mjs +1 -7
  8. package/package.json +4 -9
  9. package/src/contracts/cdp.ts +746 -0
  10. package/src/contracts/collector.ts +98 -0
  11. package/src/contracts/gov.ts +1 -0
  12. package/src/contracts/interest-oracle.ts +149 -0
  13. package/src/contracts/{lrp/transactions.ts → lrp.ts} +14 -14
  14. package/src/contracts/{one-shot/transactions.ts → one-shot.ts} +3 -3
  15. package/src/contracts/stability-pool.ts +690 -0
  16. package/src/contracts/staking.ts +348 -0
  17. package/src/contracts/treasury.ts +112 -0
  18. package/src/helpers/asset-helpers.ts +63 -0
  19. package/src/{utils → helpers}/helper-txs.ts +0 -1
  20. package/src/{utils/utils.ts → helpers/helpers.ts} +10 -0
  21. package/src/{contracts/interest-oracle/helpers.ts → helpers/interest-oracle.ts} +9 -37
  22. package/src/{contracts/stability-pool/helpers.ts → helpers/stability-pool-helpers.ts} +6 -110
  23. package/src/helpers/staking-helpers.ts +94 -0
  24. package/src/helpers/time-helpers.ts +4 -0
  25. package/src/{utils → helpers}/value-helpers.ts +0 -10
  26. package/src/index.ts +33 -38
  27. package/src/{validators → scripts}/cdp-creator-validator.ts +50 -4
  28. package/src/{validators → scripts}/cdp-validator.ts +5 -3
  29. package/src/{validators → scripts}/collector-validator.ts +3 -2
  30. package/src/scripts/execute-validator.ts +52 -0
  31. package/src/{validators/governance-validator.ts → scripts/gov-validator.ts} +40 -3
  32. package/src/{validators → scripts}/interest-oracle-validator.ts +20 -4
  33. package/src/scripts/lrp-validator.ts +40 -0
  34. package/src/{contracts/one-shot/scripts.ts → scripts/one-shot-policy.ts} +1 -1
  35. package/src/scripts/poll-manager-validator.ts +52 -0
  36. package/src/{validators → scripts}/poll-shard-validator.ts +43 -3
  37. package/src/{contracts/price-oracle/scripts.ts → scripts/price-oracle-validator.ts} +4 -1
  38. package/src/{validators → scripts}/stability-pool-validator.ts +57 -4
  39. package/src/{validators → scripts}/staking-validator.ts +3 -2
  40. package/src/{validators → scripts}/treasury-validator.ts +3 -2
  41. package/src/{validators → scripts}/version-record-policy.ts +23 -4
  42. package/src/{validators/execute-validator.ts → scripts/version-registry.ts} +11 -3
  43. package/src/types/generic.ts +60 -78
  44. package/src/{contracts/cdp-creator/types.ts → types/indigo/cdp-creator.ts} +4 -6
  45. package/src/types/indigo/cdp.ts +88 -0
  46. package/src/types/indigo/execute.ts +21 -0
  47. package/src/types/indigo/gov.ts +51 -0
  48. package/src/{contracts/interest-oracle/types.ts → types/indigo/interest-oracle.ts} +1 -1
  49. package/src/{contracts/lrp/types.ts → types/indigo/lrp.ts} +2 -2
  50. package/src/types/indigo/poll-manager.ts +21 -0
  51. package/src/types/indigo/poll-shard.ts +16 -0
  52. package/src/{contracts/price-oracle/types.ts → types/indigo/price-oracle.ts} +4 -16
  53. package/src/types/indigo/stability-pool.ts +233 -0
  54. package/src/types/indigo/staking.ts +99 -0
  55. package/src/{contracts/version-registry/types.ts → types/indigo/version-record.ts} +1 -1
  56. package/src/types/on-chain-decimal.ts +0 -22
  57. package/src/types/system-params.ts +11 -22
  58. package/tests/datums.test.ts +108 -125
  59. package/tests/endpoints/initialize.ts +338 -240
  60. package/tests/hash-checks.test.ts +21 -26
  61. package/tests/indigo-test-helpers.ts +55 -1
  62. package/tests/initialize.test.ts +5 -10
  63. package/tests/interest-calculations.test.ts +18 -18
  64. package/tests/interest-oracle.test.ts +18 -20
  65. package/tests/lrp.test.ts +65 -191
  66. package/tests/queries/governance-queries.ts +16 -19
  67. package/tests/queries/iasset-queries.ts +23 -46
  68. package/tests/queries/interest-oracle-queries.ts +6 -3
  69. package/tests/queries/lrp-queries.ts +2 -2
  70. package/tests/queries/price-oracle-queries.ts +22 -5
  71. package/tests/queries/stability-pool-queries.ts +8 -10
  72. package/tests/queries/staking-queries.ts +19 -28
  73. package/tests/stability-pool.test.ts +71 -186
  74. package/tests/staking.test.ts +23 -30
  75. package/tests/test-helpers.ts +2 -11
  76. package/tsconfig.json +1 -3
  77. package/vitest.config.ts +1 -1
  78. package/src/contracts/cdp/helpers.ts +0 -167
  79. package/src/contracts/cdp/scripts.ts +0 -33
  80. package/src/contracts/cdp/transactions.ts +0 -1310
  81. package/src/contracts/cdp/types.ts +0 -161
  82. package/src/contracts/cdp-creator/scripts.ts +0 -39
  83. package/src/contracts/collector/scripts.ts +0 -32
  84. package/src/contracts/collector/transactions.ts +0 -44
  85. package/src/contracts/execute/scripts.ts +0 -48
  86. package/src/contracts/execute/types.ts +0 -57
  87. package/src/contracts/gov/helpers.ts +0 -157
  88. package/src/contracts/gov/scripts.ts +0 -34
  89. package/src/contracts/gov/transactions.ts +0 -1224
  90. package/src/contracts/gov/types-new.ts +0 -115
  91. package/src/contracts/gov/types.ts +0 -89
  92. package/src/contracts/interest-oracle/scripts.ts +0 -18
  93. package/src/contracts/interest-oracle/transactions.ts +0 -149
  94. package/src/contracts/lrp/scripts.ts +0 -27
  95. package/src/contracts/poll/helpers.ts +0 -55
  96. package/src/contracts/poll/scripts.ts +0 -72
  97. package/src/contracts/poll/types-poll-manager.ts +0 -38
  98. package/src/contracts/poll/types-poll-shard.ts +0 -38
  99. package/src/contracts/poll/types-poll.ts +0 -88
  100. package/src/contracts/price-oracle/transactions.ts +0 -112
  101. package/src/contracts/stability-pool/scripts.ts +0 -46
  102. package/src/contracts/stability-pool/transactions.ts +0 -660
  103. package/src/contracts/stability-pool/types-new.ts +0 -208
  104. package/src/contracts/stability-pool/types.ts +0 -42
  105. package/src/contracts/staking/helpers.ts +0 -116
  106. package/src/contracts/staking/scripts.ts +0 -41
  107. package/src/contracts/staking/transactions.ts +0 -268
  108. package/src/contracts/staking/types-new.ts +0 -81
  109. package/src/contracts/staking/types.ts +0 -41
  110. package/src/contracts/treasury/scripts.ts +0 -37
  111. package/src/contracts/treasury/transactions.ts +0 -44
  112. package/src/contracts/treasury/types.ts +0 -55
  113. package/src/contracts/version-registry/scripts.ts +0 -29
  114. package/src/contracts/version-registry/types-new.ts +0 -19
  115. package/src/contracts/vesting/helpers.ts +0 -267
  116. package/src/types/evolution-schema-options.ts +0 -16
  117. package/src/utils/bigint-utils.ts +0 -7
  118. package/src/utils/time-helpers.ts +0 -4
  119. package/src/validators/lrp-validator.ts +0 -7
  120. package/src/validators/poll-manager-validator.ts +0 -7
  121. package/src/validators/version-registry-validator.ts +0 -7
  122. package/tests/cdp.test.ts +0 -1565
  123. package/tests/gov.test.ts +0 -1874
  124. package/tests/mock/assets-mock.ts +0 -59
  125. package/tests/queries/cdp-queries.ts +0 -144
  126. package/tests/queries/collector-queries.ts +0 -26
  127. package/tests/queries/execute-queries.ts +0 -46
  128. package/tests/queries/poll-queries.ts +0 -97
  129. package/tests/queries/treasury-queries.ts +0 -19
  130. package/tests/utils/asserts.ts +0 -13
  131. package/tests/utils/index.ts +0 -50
  132. /package/src/{utils → helpers}/indigo-helpers.ts +0 -0
  133. /package/src/{utils → helpers}/lucid-utils.ts +0 -0
  134. /package/src/{contracts/price-oracle/helpers.ts → helpers/price-oracle-helpers.ts} +0 -0
  135. /package/src/{contracts/one-shot/types.ts → types/one-shot.ts} +0 -0
@@ -1,112 +0,0 @@
1
- import {
2
- addAssets,
3
- fromText,
4
- LucidEvolution,
5
- OutRef,
6
- slotToUnixTime,
7
- TxBuilder,
8
- validatorToAddress,
9
- } from '@lucid-evolution/lucid';
10
- import { AssetClass } from '../../types/generic';
11
- import {
12
- OracleAssetNft,
13
- PriceOracleDatum,
14
- PriceOracleParams,
15
- serialisePriceOracleDatum,
16
- serialisePriceOracleRedeemer,
17
- } from './types';
18
- import { mkPriceOracleValidator } from './scripts';
19
- import { oneShotMintTx } from '../one-shot/transactions';
20
- import { mkAssetsOf, mkLovelacesOf } from '../../utils/value-helpers';
21
- import { OnChainDecimal } from '../../types/on-chain-decimal';
22
- import { matchSingle } from '../../utils/utils';
23
- import { ONE_SECOND } from '../../utils/time-helpers';
24
-
25
- export async function startPriceOracleTx(
26
- lucid: LucidEvolution,
27
- assetName: string,
28
- startPrice: OnChainDecimal,
29
- oracleParams: PriceOracleParams,
30
- now: number = Date.now(),
31
- refOutRef?: OutRef,
32
- ): Promise<[TxBuilder, OracleAssetNft]> {
33
- if (!refOutRef) {
34
- refOutRef = (await lucid.wallet().getUtxos())[0];
35
- }
36
-
37
- const [tx, oracleNftPolicyId] = await oneShotMintTx(lucid, {
38
- referenceOutRef: {
39
- txHash: refOutRef.txHash,
40
- outputIdx: BigInt(refOutRef.outputIndex),
41
- },
42
- mintAmounts: [
43
- {
44
- tokenName: fromText(assetName),
45
- amount: 1n,
46
- },
47
- ],
48
- });
49
-
50
- const priceOracleNft: AssetClass = {
51
- currencySymbol: oracleNftPolicyId,
52
- tokenName: fromText(assetName),
53
- };
54
-
55
- const oracleValidator = mkPriceOracleValidator(oracleParams);
56
-
57
- const oracleDatum: PriceOracleDatum = {
58
- price: startPrice,
59
- expiration: BigInt(now) + oracleParams.expiration,
60
- };
61
-
62
- tx.pay.ToContract(
63
- validatorToAddress(lucid.config().network!, oracleValidator),
64
- { kind: 'inline', value: serialisePriceOracleDatum(oracleDatum) },
65
- addAssets(mkLovelacesOf(5_000_000n), mkAssetsOf(priceOracleNft, 1n)),
66
- );
67
-
68
- return [tx, { oracleNft: priceOracleNft }];
69
- }
70
-
71
- export async function feedPriceOracleTx(
72
- lucid: LucidEvolution,
73
- oracleOref: OutRef,
74
- newPrice: OnChainDecimal,
75
- oracleParams: PriceOracleParams,
76
- currentSlot: number,
77
- ): Promise<TxBuilder> {
78
- const network = lucid.config().network!;
79
- const currentTime = BigInt(slotToUnixTime(network, currentSlot));
80
-
81
- const priceOracleUtxo = matchSingle(
82
- await lucid.utxosByOutRef([oracleOref]),
83
- (_) => new Error('Expected a single price oracle UTXO'),
84
- );
85
-
86
- const oracleValidator = mkPriceOracleValidator(oracleParams);
87
-
88
- return lucid
89
- .newTx()
90
- .validFrom(Number(currentTime - oracleParams.biasTime) + ONE_SECOND)
91
- .validTo(Number(currentTime + oracleParams.biasTime) - ONE_SECOND)
92
- .attach.SpendingValidator(oracleValidator)
93
- .collectFrom(
94
- [priceOracleUtxo],
95
- serialisePriceOracleRedeemer({
96
- currentTime: currentTime,
97
- newPrice: newPrice,
98
- }),
99
- )
100
- .pay.ToContract(
101
- priceOracleUtxo.address,
102
- {
103
- kind: 'inline',
104
- value: serialisePriceOracleDatum({
105
- price: newPrice,
106
- expiration: currentTime + oracleParams.expiration,
107
- }),
108
- },
109
- priceOracleUtxo.assets,
110
- )
111
- .addSignerKey(oracleParams.owner);
112
- }
@@ -1,46 +0,0 @@
1
- import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
2
- import { castStabilityPoolParams, StabilityPoolParams } from './types';
3
- import {
4
- fromSystemParamsAsset,
5
- StabilityPoolParamsSP,
6
- } from '../../types/system-params';
7
- import { _stabilityPoolValidator } from '../../validators/stability-pool-validator';
8
-
9
- export const mkStabilityPoolValidator = (
10
- params: StabilityPoolParams,
11
- ): SpendingValidator => {
12
- return {
13
- type: 'PlutusV2',
14
- script: applyParamsToScript(_stabilityPoolValidator.cborHex, [
15
- castStabilityPoolParams(params),
16
- ]),
17
- };
18
- };
19
-
20
- export const mkStabilityPoolValidatorFromSP = (
21
- params: StabilityPoolParamsSP,
22
- ): SpendingValidator => {
23
- return {
24
- type: 'PlutusV2',
25
- script: applyParamsToScript(_stabilityPoolValidator.cborHex, [
26
- castStabilityPoolParams({
27
- assetSymbol: params.assetSymbol.unCurrencySymbol,
28
- stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
29
- snapshotEpochToScaleToSumToken: fromSystemParamsAsset(
30
- params.snapshotEpochToScaleToSumToken,
31
- ),
32
- accountToken: fromSystemParamsAsset(params.accountToken),
33
- cdpToken: fromSystemParamsAsset(params.cdpToken),
34
- iAssetAuthToken: fromSystemParamsAsset(params.iAssetAuthToken),
35
- versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
36
- collectorValHash: params.collectorValHash,
37
- govNFT: fromSystemParamsAsset(params.govNFT),
38
- accountCreateFeeLovelaces: BigInt(params.accountCreateFeeLovelaces),
39
- accountAdjustmentFeeLovelaces: BigInt(
40
- params.accountAdjustmentFeeLovelaces,
41
- ),
42
- requestCollateralLovelaces: BigInt(params.requestCollateralLovelaces),
43
- }),
44
- ]),
45
- };
46
- };