@indigo-labs/indigo-sdk 0.1.7 → 0.1.9

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 +19 -9
  7. package/dist/index.d.ts +19 -9
  8. package/dist/index.js +341 -315
  9. package/dist/index.mjs +92 -64
  10. package/eslint.config.mjs +36 -0
  11. package/package.json +2 -6
  12. package/src/contracts/cdp.ts +748 -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 +308 -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 +769 -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 +387 -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,55 @@
1
+ import { Data, Datum } from '@lucid-evolution/lucid';
2
+ import { OnChainDecimalSchema } from '../on-chain-decimal';
3
+
4
+ export const InterestOracleDatumSchema = Data.Object({
5
+ unitaryInterest: Data.Integer(),
6
+ interestRate: OnChainDecimalSchema,
7
+ lastUpdated: Data.Integer(),
8
+ });
9
+ export type InterestOracleDatum = Data.Static<typeof InterestOracleDatumSchema>;
10
+ const InterestOracleDatum =
11
+ InterestOracleDatumSchema as unknown as InterestOracleDatum;
12
+
13
+ export function parseInterestOracleDatum(datum: Datum): InterestOracleDatum {
14
+ return Data.from<InterestOracleDatum>(datum, InterestOracleDatum);
15
+ }
16
+
17
+ export function serialiseInterestOracleDatum(
18
+ datum: InterestOracleDatum,
19
+ ): Datum {
20
+ return Data.to<InterestOracleDatum>(datum, InterestOracleDatum);
21
+ }
22
+
23
+ export const FeedInterestOracleRedeemerSchema = Data.Object({
24
+ newInterestRate: OnChainDecimalSchema,
25
+ currentTime: Data.Integer(),
26
+ });
27
+ export type FeedInterestOracleRedeemer = Data.Static<
28
+ typeof FeedInterestOracleRedeemerSchema
29
+ >;
30
+ const FeedInterestOracleRedeemer =
31
+ FeedInterestOracleRedeemerSchema as unknown as FeedInterestOracleRedeemer;
32
+
33
+ export function serialiseFeedInterestOracleRedeemer(
34
+ redeemer: FeedInterestOracleRedeemer,
35
+ ): Datum {
36
+ return Data.to<FeedInterestOracleRedeemer>(
37
+ redeemer,
38
+ FeedInterestOracleRedeemer,
39
+ );
40
+ }
41
+
42
+ export const InterestOracleParamsSchema = Data.Object({
43
+ /** Milliseconds */
44
+ biasTime: Data.Integer(),
45
+ owner: Data.Bytes(),
46
+ });
47
+ export type InterestOracleParams = Data.Static<
48
+ typeof InterestOracleParamsSchema
49
+ >;
50
+ const InterestOracleParams =
51
+ InterestOracleParamsSchema as unknown as InterestOracleParams;
52
+
53
+ export function castInterestOracleParams(params: InterestOracleParams): Data {
54
+ return Data.castTo(params, InterestOracleParams);
55
+ }
@@ -0,0 +1,59 @@
1
+ import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema, OutputReferenceSchema } from '../generic';
3
+ import { OnChainDecimalSchema } from '../on-chain-decimal';
4
+
5
+ export const LRPParamsSchema = Data.Object({
6
+ versionRecordToken: AssetClassSchema,
7
+ iassetNft: AssetClassSchema,
8
+ iassetPolicyId: Data.Bytes(),
9
+ minRedemptionLovelacesAmt: Data.Integer(),
10
+ });
11
+ export type LRPParams = Data.Static<typeof LRPParamsSchema>;
12
+ const LRPParams = LRPParamsSchema as unknown as LRPParams;
13
+
14
+ export const LRPDatumSchema = Data.Object({
15
+ owner: Data.Bytes(),
16
+ iasset: Data.Bytes(),
17
+ maxPrice: OnChainDecimalSchema,
18
+ /**
19
+ * The amount of lovelaces that is available to be spent.
20
+ * This doesn't correspond to the lovelaces in UTXO's value,
21
+ * since that can contain fees, too.
22
+ */
23
+ lovelacesToSpend: Data.Integer(),
24
+ });
25
+ export type LRPDatum = Data.Static<typeof LRPDatumSchema>;
26
+ const LRPDatum = LRPDatumSchema as unknown as LRPDatum;
27
+
28
+ export const LRPRedeemerSchema = Data.Enum([
29
+ Data.Object({ Redeem: Data.Object({ continuingOutputIdx: Data.Integer() }) }),
30
+ Data.Object({
31
+ RedeemAuxiliary: Data.Object({
32
+ continuingOutputIdx: Data.Integer(),
33
+ mainRedeemOutRef: OutputReferenceSchema,
34
+ asset: Data.Bytes(),
35
+ assetPrice: OnChainDecimalSchema,
36
+ redemptionReimbursementPercentage: OnChainDecimalSchema,
37
+ }),
38
+ }),
39
+ Data.Literal('Cancel'),
40
+ Data.Literal('UpgradeVersion'),
41
+ ]);
42
+ export type LRPRedeemer = Data.Static<typeof LRPRedeemerSchema>;
43
+ const LRPRedeemer = LRPRedeemerSchema as unknown as LRPRedeemer;
44
+
45
+ export function parseLrpDatum(datum: Datum): LRPDatum {
46
+ return Data.from<LRPDatum>(datum, LRPDatum);
47
+ }
48
+
49
+ export function serialiseLrpDatum(datum: LRPDatum): Datum {
50
+ return Data.to<LRPDatum>(datum, LRPDatum);
51
+ }
52
+
53
+ export function serialiseLrpRedeemer(redeemer: LRPRedeemer): Redeemer {
54
+ return Data.to<LRPRedeemer>(redeemer, LRPRedeemer);
55
+ }
56
+
57
+ export function castLrpParams(params: LRPParams): Data {
58
+ return Data.castTo(params, LRPParams);
59
+ }
@@ -0,0 +1,21 @@
1
+ import { Data } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../generic';
3
+
4
+ const PollManagerParamsSchema = Data.Object({
5
+ govNFT: AssetClassSchema,
6
+ pollToken: AssetClassSchema,
7
+ upgradeToken: AssetClassSchema,
8
+ indyAsset: AssetClassSchema,
9
+ govExecuteValHash: Data.Bytes(),
10
+ pBiasTime: Data.Integer(),
11
+ shardValHash: Data.Bytes(),
12
+ treasuryValHash: Data.Bytes(),
13
+ initialIndyDistribution: Data.Integer(),
14
+ });
15
+ export type PollManagerParams = Data.Static<typeof PollManagerParamsSchema>;
16
+ export const PollManagerParams =
17
+ PollManagerParamsSchema as unknown as PollManagerParams;
18
+
19
+ export function castPollManagerParams(params: PollManagerParams): Data {
20
+ return Data.castTo(params, PollManagerParams);
21
+ }
@@ -0,0 +1,16 @@
1
+ import { Data } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../generic';
3
+
4
+ const PollShardParamsSchema = Data.Object({
5
+ pollToken: AssetClassSchema,
6
+ stakingToken: AssetClassSchema,
7
+ indyAsset: AssetClassSchema,
8
+ stakingValHash: Data.Bytes(),
9
+ });
10
+ export type PollShardParams = Data.Static<typeof PollShardParamsSchema>;
11
+ export const PollShardParams =
12
+ PollShardParamsSchema as unknown as PollShardParams;
13
+
14
+ export function castPollShardParams(params: PollShardParams): Data {
15
+ return Data.castTo(params, PollShardParams);
16
+ }
@@ -0,0 +1,38 @@
1
+ import { Data, Datum } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../generic';
3
+ import { OnChainDecimalSchema } from '../on-chain-decimal';
4
+
5
+ export const OracleAssetNftSchema = Data.Object({
6
+ oracleNft: Data.Object({ asset: AssetClassSchema }),
7
+ });
8
+ export type OracleAssetNft = Data.Static<typeof OracleAssetNftSchema>;
9
+
10
+ export const PriceOracleParamsSchema = Data.Object({
11
+ owner: Data.Bytes(),
12
+ /** Milliseconds */
13
+ biasTime: Data.Integer(),
14
+ /** Milliseconds */
15
+ expiration: Data.Integer(),
16
+ });
17
+ export type PriceOracleParams = Data.Static<typeof PriceOracleParamsSchema>;
18
+ const PriceOracleParams =
19
+ PriceOracleParamsSchema as unknown as PriceOracleParams;
20
+
21
+ export const PriceOracleDatumSchema = Data.Object({
22
+ price: OnChainDecimalSchema,
23
+ expiration: Data.Integer(),
24
+ });
25
+ export type PriceOracleDatum = Data.Static<typeof PriceOracleDatumSchema>;
26
+ const PriceOracleDatum = PriceOracleDatumSchema as unknown as PriceOracleDatum;
27
+
28
+ export function parsePriceOracleDatum(datum: Datum): PriceOracleDatum {
29
+ return Data.from<PriceOracleDatum>(datum, PriceOracleDatum);
30
+ }
31
+
32
+ export function serialisePriceOracleDatum(datum: PriceOracleDatum): Datum {
33
+ return Data.to<PriceOracleDatum>(datum, PriceOracleDatum);
34
+ }
35
+
36
+ export function castPriceOracleParams(params: PriceOracleParams): Data {
37
+ return Data.castTo(params, PriceOracleParams);
38
+ }
@@ -0,0 +1,233 @@
1
+ import { Data, Datum } from '@lucid-evolution/lucid';
2
+ import { match, P } from 'ts-pattern';
3
+ import {
4
+ AddressSchema,
5
+ AssetClassSchema,
6
+ OutputReferenceSchema,
7
+ } from '../generic';
8
+
9
+ export const SPIntegerSchema = Data.Object({
10
+ value: Data.Integer(),
11
+ });
12
+
13
+ export type SPInteger = Data.Static<typeof SPIntegerSchema>;
14
+ export const SPInteger = SPIntegerSchema as unknown as SPInteger;
15
+
16
+ const StabilityPoolSnapshotSchema = Data.Object({
17
+ productVal: SPIntegerSchema,
18
+ depositVal: SPIntegerSchema,
19
+ sumVal: SPIntegerSchema,
20
+ epoch: Data.Integer(),
21
+ scale: Data.Integer(),
22
+ });
23
+
24
+ export type StabilityPoolSnapshot = Data.Static<
25
+ typeof StabilityPoolSnapshotSchema
26
+ >;
27
+ export const StabilityPoolSnapshot =
28
+ StabilityPoolSnapshotSchema as unknown as StabilityPoolSnapshot;
29
+
30
+ export const EpochToScaleToSumSchema = Data.Map(
31
+ Data.Object({ epoch: Data.Integer(), scale: Data.Integer() }),
32
+ SPIntegerSchema,
33
+ { minItems: 0 },
34
+ );
35
+
36
+ export type EpochToScaleToSum = Data.Static<typeof EpochToScaleToSumSchema>;
37
+ export const EpochToScaleToSum =
38
+ EpochToScaleToSumSchema as unknown as EpochToScaleToSum;
39
+
40
+ export const StabilityPoolContentSchema = Data.Object({
41
+ asset: Data.Bytes(),
42
+ snapshot: StabilityPoolSnapshotSchema,
43
+ epochToScaleToSum: EpochToScaleToSumSchema,
44
+ });
45
+
46
+ export type StabilityPoolContent = Data.Static<
47
+ typeof StabilityPoolContentSchema
48
+ >;
49
+ export const StabilityPoolContent =
50
+ StabilityPoolContentSchema as unknown as StabilityPoolContent;
51
+
52
+ export const AccountActionSchema = Data.Enum([
53
+ Data.Literal('Create'),
54
+ Data.Object({
55
+ Adjust: Data.Object({
56
+ amount: Data.Integer(),
57
+ outputAddress: AddressSchema,
58
+ }),
59
+ }),
60
+ Data.Object({ Close: Data.Object({ outputAddress: AddressSchema }) }),
61
+ ]);
62
+
63
+ export type AccountAction = Data.Static<typeof AccountActionSchema>;
64
+ export const AccountAction = AccountActionSchema as unknown as AccountAction;
65
+
66
+ export const AccountContentSchema = Data.Object({
67
+ owner: Data.Bytes(),
68
+ asset: Data.Bytes(),
69
+ snapshot: StabilityPoolSnapshotSchema,
70
+ request: Data.Nullable(AccountActionSchema),
71
+ });
72
+
73
+ export type AccountContent = Data.Static<typeof AccountContentSchema>;
74
+ export const AccountContent = AccountContentSchema as unknown as AccountContent;
75
+
76
+ export const SnapshotEpochToScaleToSumContentSchema = Data.Object({
77
+ asset: Data.Bytes(),
78
+ snapshot: EpochToScaleToSumSchema,
79
+ });
80
+
81
+ export type SnapshotEpochToScaleToSumContent = Data.Static<
82
+ typeof SnapshotEpochToScaleToSumContentSchema
83
+ >;
84
+ export const SnapshotEpochToScaleToSumContent =
85
+ SnapshotEpochToScaleToSumContentSchema as unknown as SnapshotEpochToScaleToSumContent;
86
+
87
+ export const StabilityPoolDatumSchema = Data.Enum([
88
+ Data.Object({
89
+ StabilityPool: Data.Object({ content: StabilityPoolContentSchema }),
90
+ }),
91
+ Data.Object({ Account: Data.Object({ content: AccountContentSchema }) }),
92
+ Data.Object({
93
+ SnapshotEpochToScaleToSum: Data.Object({
94
+ content: SnapshotEpochToScaleToSumContentSchema,
95
+ }),
96
+ }),
97
+ ]);
98
+
99
+ export type StabilityPoolDatum = Data.Static<typeof StabilityPoolDatumSchema>;
100
+ export const StabilityPoolDatum =
101
+ StabilityPoolDatumSchema as unknown as StabilityPoolDatum;
102
+
103
+ export const ActionReturnDatumSchema = Data.Enum([
104
+ Data.Object({
105
+ IndigoStabilityPoolAccountAdjustment: Data.Object({
106
+ spent_account: OutputReferenceSchema,
107
+ }),
108
+ }),
109
+ Data.Object({
110
+ IndigoStabilityPoolAccountClosure: Data.Object({
111
+ closed_account: OutputReferenceSchema,
112
+ }),
113
+ }),
114
+ ]);
115
+
116
+ export type ActionReturnDatum = Data.Static<typeof ActionReturnDatumSchema>;
117
+ export const ActionReturnDatum =
118
+ ActionReturnDatumSchema as unknown as ActionReturnDatum;
119
+
120
+ export const StabilityPoolRedeemerSchema = Data.Enum([
121
+ Data.Object({ RequestAction: Data.Object({ action: AccountActionSchema }) }),
122
+ Data.Object({
123
+ ProcessRequest: Data.Object({ requestRef: OutputReferenceSchema }),
124
+ }),
125
+ Data.Object({ AnnulRequest: Data.Object({}) }),
126
+ Data.Object({ LiquidateCDP: Data.Object({}) }),
127
+ Data.Object({ RecordEpochToScaleToSum: Data.Object({}) }),
128
+ Data.Object({ UpgradeVersion: Data.Object({}) }),
129
+ ]);
130
+
131
+ export type StabilityPoolRedeemer = Data.Static<
132
+ typeof StabilityPoolRedeemerSchema
133
+ >;
134
+ export const StabilityPoolRedeemer =
135
+ StabilityPoolRedeemerSchema as unknown as StabilityPoolRedeemer;
136
+
137
+ export function parseStabilityPoolDatum(datum: Datum): StabilityPoolContent {
138
+ return match(Data.from<StabilityPoolDatum>(datum, StabilityPoolDatum))
139
+ .with({ StabilityPool: { content: P.select() } }, (res) => res)
140
+ .otherwise(() => {
141
+ throw new Error('Expected a Stability Pool datum.');
142
+ });
143
+ }
144
+
145
+ export function parseAccountDatum(datum: Datum): AccountContent {
146
+ return match(Data.from<StabilityPoolDatum>(datum, StabilityPoolDatum))
147
+ .with({ Account: { content: P.select() } }, (res) => res)
148
+ .otherwise(() => {
149
+ throw new Error('Expected a StakingPosition datum.');
150
+ });
151
+ }
152
+
153
+ export function parseSnapshotEpochToScaleToSumDatum(
154
+ datum: Datum,
155
+ ): SnapshotEpochToScaleToSumContent {
156
+ return match(Data.from<StabilityPoolDatum>(datum, StabilityPoolDatum))
157
+ .with({ SnapshotEpochToScaleToSum: { content: P.select() } }, (res) => res)
158
+ .otherwise(() => {
159
+ throw new Error('Expected a SnapshotEpochToScaleToSum datum.');
160
+ });
161
+ }
162
+
163
+ export function serialiseStabilityPoolDatum(d: StabilityPoolDatum): Datum {
164
+ let cbor = Data.to<StabilityPoolDatum>(d, StabilityPoolDatum);
165
+ if ('StabilityPool' in d) {
166
+ if (cbor.includes('bf')) {
167
+ if (d.StabilityPool.content.epochToScaleToSum.size > 0) {
168
+ cbor = cbor.replace(
169
+ 'bf',
170
+ 'a' + d.StabilityPool.content.epochToScaleToSum.size,
171
+ );
172
+ cbor = cbor.replace('ffffff', 'ffff');
173
+ }
174
+ }
175
+ }
176
+ return cbor;
177
+ }
178
+
179
+ export function serialiseStabilityPoolRedeemer(
180
+ params: StabilityPoolRedeemer,
181
+ ): string {
182
+ return Data.to<StabilityPoolRedeemer>(params, StabilityPoolRedeemer);
183
+ }
184
+
185
+ /** SP Parameters */
186
+ const StabilityPoolParamsSchema = Data.Object({
187
+ assetSymbol: Data.Bytes(),
188
+ stabilityPoolToken: AssetClassSchema,
189
+ snapshotEpochToScaleToSumToken: AssetClassSchema,
190
+ accountToken: AssetClassSchema,
191
+ cdpToken: AssetClassSchema,
192
+ iAssetAuthToken: AssetClassSchema,
193
+ versionRecordToken: AssetClassSchema,
194
+ collectorValHash: Data.Bytes(),
195
+ govNFT: AssetClassSchema,
196
+ accountCreateFeeLovelaces: Data.Integer(),
197
+ accountAdjustmentFeeLovelaces: Data.Integer(),
198
+ requestCollateralLovelaces: Data.Integer(),
199
+ });
200
+ export type StabilityPoolParams = Data.Static<typeof StabilityPoolParamsSchema>;
201
+ export const StabilityPoolParams =
202
+ StabilityPoolParamsSchema as unknown as StabilityPoolParams;
203
+
204
+ export function castStabilityPoolParams(params: StabilityPoolParams): Data {
205
+ return Data.castTo(params, StabilityPoolParams);
206
+ }
207
+
208
+ /** SP Integer */
209
+ const spPrecision: bigint = 1000000000000000000n;
210
+
211
+ export function mkSPInteger(value: bigint): SPInteger {
212
+ return { value: value * spPrecision };
213
+ }
214
+
215
+ export function fromSPInteger(value: SPInteger): bigint {
216
+ return value.value / spPrecision;
217
+ }
218
+
219
+ export function spAdd(a: SPInteger, b: SPInteger): SPInteger {
220
+ return { value: a.value + b.value };
221
+ }
222
+
223
+ export function spSub(a: SPInteger, b: SPInteger): SPInteger {
224
+ return { value: a.value - b.value };
225
+ }
226
+
227
+ export function spMul(a: SPInteger, b: SPInteger): SPInteger {
228
+ return { value: (a.value * b.value) / spPrecision };
229
+ }
230
+
231
+ export function spDiv(a: SPInteger, b: SPInteger): SPInteger {
232
+ return { value: (a.value * spPrecision) / b.value };
233
+ }
@@ -0,0 +1,99 @@
1
+ import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../generic';
3
+ import { match, P } from 'ts-pattern';
4
+
5
+ const StakingParamsSchema = Data.Object({
6
+ stakingManagerNft: AssetClassSchema,
7
+ stakingToken: AssetClassSchema,
8
+ indyToken: AssetClassSchema,
9
+ pollToken: AssetClassSchema,
10
+ versionRecordToken: AssetClassSchema,
11
+ collectorValHash: Data.Bytes(),
12
+ });
13
+ type StakingParams = Data.Static<typeof StakingParamsSchema>;
14
+ const StakingParams = StakingParamsSchema as unknown as StakingParams;
15
+
16
+ const StakingRedeemerSchema = Data.Enum([
17
+ Data.Object({
18
+ CreateStakingPosition: Data.Object({
19
+ creatorPkh: Data.Bytes(),
20
+ }),
21
+ }),
22
+ Data.Literal('UpdateTotalStake'),
23
+ Data.Literal('Distribute'),
24
+ Data.Object({
25
+ AdjustStakedAmount: Data.Object({
26
+ adjustAmount: Data.Integer(),
27
+ }),
28
+ }),
29
+ Data.Literal('Unstake'),
30
+ Data.Literal('Lock'),
31
+ Data.Literal('UpgradeVersion'),
32
+ ]);
33
+ export type StakingRedeemer = Data.Static<typeof StakingRedeemerSchema>;
34
+ const StakingRedeemer = StakingRedeemerSchema as unknown as StakingRedeemer;
35
+
36
+ const RewardSnapshotSchema = Data.Object({ snapshotAda: Data.Integer() });
37
+
38
+ const StakingManagerContentSchema = Data.Object({
39
+ totalStake: Data.Integer(),
40
+ managerSnapshot: RewardSnapshotSchema,
41
+ });
42
+ export type StakingManagerContent = Data.Static<
43
+ typeof StakingManagerContentSchema
44
+ >;
45
+
46
+ const StakingPositionContentSchema = Data.Object({
47
+ owner: Data.Bytes(),
48
+ lockedAmount: Data.Map(
49
+ Data.Integer(),
50
+ Data.Tuple([Data.Integer(), Data.Integer()], {
51
+ hasConstr: true,
52
+ }),
53
+ ),
54
+ positionSnapshot: RewardSnapshotSchema,
55
+ });
56
+ export type StakingPositionContent = Data.Static<
57
+ typeof StakingPositionContentSchema
58
+ >;
59
+
60
+ const StakingDatumSchema = Data.Enum([
61
+ Data.Object({
62
+ StakingManager: Data.Object({ content: StakingManagerContentSchema }),
63
+ }),
64
+ Data.Object({
65
+ StakingPosition: Data.Object({ content: StakingPositionContentSchema }),
66
+ }),
67
+ ]);
68
+ export type StakingDatum = Data.Static<typeof StakingDatumSchema>;
69
+ const StakingDatum = StakingDatumSchema as unknown as StakingDatum;
70
+
71
+ export function parseStakingPositionDatum(
72
+ datum: Datum,
73
+ ): StakingPositionContent {
74
+ return match(Data.from<StakingDatum>(datum, StakingDatum))
75
+ .with({ StakingPosition: { content: P.select() } }, (res) => res)
76
+ .otherwise(() => {
77
+ throw new Error('Expected a StakingPosition datum.');
78
+ });
79
+ }
80
+
81
+ export function parseStakingManagerDatum(datum: Datum): StakingManagerContent {
82
+ return match(Data.from<StakingDatum>(datum, StakingDatum))
83
+ .with({ StakingManager: { content: P.select() } }, (res) => res)
84
+ .otherwise(() => {
85
+ throw new Error('Expected a StakingPosition datum.');
86
+ });
87
+ }
88
+
89
+ export function serialiseStakingRedeemer(redeemer: StakingRedeemer): Redeemer {
90
+ return Data.to<StakingRedeemer>(redeemer, StakingRedeemer);
91
+ }
92
+
93
+ export function serialiseStakingDatum(d: StakingDatum): Datum {
94
+ return Data.to<StakingDatum>(d, StakingDatum);
95
+ }
96
+
97
+ export function castStakingParams(params: StakingParams): Data {
98
+ return Data.castTo(params, StakingParams);
99
+ }
@@ -0,0 +1,17 @@
1
+ import { Data } from '@lucid-evolution/lucid';
2
+ import { AssetClassSchema } from '../generic';
3
+
4
+ const VersionRecordTokenParamsSchema = Data.Object({
5
+ upgradeToken: AssetClassSchema,
6
+ });
7
+ export type VersionRecordTokenParams = Data.Static<
8
+ typeof VersionRecordTokenParamsSchema
9
+ >;
10
+ export const VersionRecordTokenParams =
11
+ VersionRecordTokenParamsSchema as unknown as VersionRecordTokenParams;
12
+
13
+ export function castVersionRecordTokenParams(
14
+ params: VersionRecordTokenParams,
15
+ ): Data {
16
+ return Data.castTo(params, VersionRecordTokenParams);
17
+ }
@@ -0,0 +1,23 @@
1
+ import { Data } from '@lucid-evolution/lucid';
2
+
3
+ export const OCD_DECIMAL_UNIT: bigint = 1_000_000n;
4
+
5
+ export const OnChainDecimalSchema = Data.Object({
6
+ getOnChainInt: Data.Integer(),
7
+ });
8
+ export type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
9
+
10
+ export function ocdMul(a: OnChainDecimal, b: OnChainDecimal): OnChainDecimal {
11
+ return {
12
+ getOnChainInt: (a.getOnChainInt * b.getOnChainInt) / OCD_DECIMAL_UNIT,
13
+ };
14
+ }
15
+
16
+ export function ocdDiv(a: OnChainDecimal, b: OnChainDecimal): OnChainDecimal {
17
+ return {
18
+ getOnChainInt: (a.getOnChainInt * OCD_DECIMAL_UNIT) / b.getOnChainInt,
19
+ };
20
+ }
21
+
22
+ export const OCD_ONE: OnChainDecimal = { getOnChainInt: 1_000_000n };
23
+ export const OCD_ZERO: OnChainDecimal = { getOnChainInt: 0n };
@@ -0,0 +1,22 @@
1
+ import { Data } from '@lucid-evolution/lucid';
2
+
3
+ export const OneShotParamsSchema = Data.Object({
4
+ referenceOutRef: Data.Object({
5
+ txHash: Data.Bytes(),
6
+ outputIdx: Data.Integer(),
7
+ }),
8
+ mintAmounts: Data.Array(
9
+ Data.Object({
10
+ /// Use hex encoded string
11
+ tokenName: Data.Bytes(),
12
+ amount: Data.Integer(),
13
+ }),
14
+ ),
15
+ });
16
+
17
+ export type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
18
+ const OneShotParams = OneShotParamsSchema as unknown as OneShotParams;
19
+
20
+ export function castOneShotParams(params: OneShotParams): Data {
21
+ return Data.castTo(params, OneShotParams);
22
+ }