@indigo-labs/indigo-sdk 0.5.5 → 0.5.6

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 (204) hide show
  1. package/package.json +11 -1
  2. package/.claude/settings.local.json +0 -7
  3. package/.github/workflows/ci.yml +0 -66
  4. package/.husky/pre-commit +0 -1
  5. package/.nvmrc +0 -1
  6. package/.prettierignore +0 -1
  7. package/.prettierrc +0 -6
  8. package/eslint.config.mjs +0 -42
  9. package/scripts/bench.sh +0 -62
  10. package/scripts/run-repeat.sh +0 -22
  11. package/src/contracts/cdp/helpers.ts +0 -173
  12. package/src/contracts/cdp/scripts.ts +0 -70
  13. package/src/contracts/cdp/transactions.ts +0 -1584
  14. package/src/contracts/cdp/types-new.ts +0 -277
  15. package/src/contracts/cdp/types.ts +0 -43
  16. package/src/contracts/cdp-creator/queries.ts +0 -30
  17. package/src/contracts/cdp-creator/scripts.ts +0 -45
  18. package/src/contracts/cdp-creator/types-new.ts +0 -50
  19. package/src/contracts/cdp-creator/types.ts +0 -24
  20. package/src/contracts/collector/scripts.ts +0 -32
  21. package/src/contracts/collector/transactions.ts +0 -50
  22. package/src/contracts/collector/types-new.ts +0 -17
  23. package/src/contracts/execute/scripts.ts +0 -57
  24. package/src/contracts/execute/types-new.ts +0 -44
  25. package/src/contracts/execute/types.ts +0 -24
  26. package/src/contracts/gov/helpers.ts +0 -351
  27. package/src/contracts/gov/scripts.ts +0 -41
  28. package/src/contracts/gov/transactions.ts +0 -1607
  29. package/src/contracts/gov/types-new.ts +0 -268
  30. package/src/contracts/gov/types.ts +0 -22
  31. package/src/contracts/iasset/helpers.ts +0 -170
  32. package/src/contracts/iasset/queries.ts +0 -102
  33. package/src/contracts/iasset/scripts.ts +0 -38
  34. package/src/contracts/iasset/types.ts +0 -154
  35. package/src/contracts/initialize/actions.ts +0 -789
  36. package/src/contracts/initialize/helpers.ts +0 -616
  37. package/src/contracts/initialize/types.ts +0 -116
  38. package/src/contracts/interest-collection/helpers.ts +0 -19
  39. package/src/contracts/interest-collection/queries.ts +0 -66
  40. package/src/contracts/interest-collection/scripts.ts +0 -44
  41. package/src/contracts/interest-collection/transactions.ts +0 -433
  42. package/src/contracts/interest-collection/types-new.ts +0 -50
  43. package/src/contracts/interest-collection/types.ts +0 -26
  44. package/src/contracts/interest-oracle/helpers.ts +0 -61
  45. package/src/contracts/interest-oracle/scripts.ts +0 -18
  46. package/src/contracts/interest-oracle/transactions.ts +0 -151
  47. package/src/contracts/interest-oracle/types-new.ts +0 -32
  48. package/src/contracts/interest-oracle/types.ts +0 -16
  49. package/src/contracts/one-shot/scripts.ts +0 -12
  50. package/src/contracts/one-shot/transactions.ts +0 -66
  51. package/src/contracts/one-shot/types.ts +0 -22
  52. package/src/contracts/poll/helpers.ts +0 -37
  53. package/src/contracts/poll/scripts.ts +0 -71
  54. package/src/contracts/poll/types-poll-manager.ts +0 -20
  55. package/src/contracts/poll/types-poll-new.ts +0 -196
  56. package/src/contracts/poll/types-poll-shard.ts +0 -16
  57. package/src/contracts/price-oracle/helpers.ts +0 -30
  58. package/src/contracts/price-oracle/scripts.ts +0 -18
  59. package/src/contracts/price-oracle/transactions.ts +0 -115
  60. package/src/contracts/price-oracle/types-new.ts +0 -50
  61. package/src/contracts/price-oracle/types.ts +0 -16
  62. package/src/contracts/pyth-feed/helpers.ts +0 -82
  63. package/src/contracts/pyth-feed/scripts.ts +0 -15
  64. package/src/contracts/pyth-feed/types.ts +0 -181
  65. package/src/contracts/rob/helpers.ts +0 -666
  66. package/src/contracts/rob/scripts.ts +0 -35
  67. package/src/contracts/rob/transactions.ts +0 -423
  68. package/src/contracts/rob/types-new.ts +0 -128
  69. package/src/contracts/rob/types.ts +0 -16
  70. package/src/contracts/rob-leverage/helpers.ts +0 -422
  71. package/src/contracts/rob-leverage/transactions.ts +0 -368
  72. package/src/contracts/stability-pool/helpers.ts +0 -798
  73. package/src/contracts/stability-pool/queries.ts +0 -132
  74. package/src/contracts/stability-pool/scripts.ts +0 -51
  75. package/src/contracts/stability-pool/transactions.ts +0 -921
  76. package/src/contracts/stability-pool/types-new.ts +0 -385
  77. package/src/contracts/stability-pool/types.ts +0 -25
  78. package/src/contracts/stableswap/helpers.ts +0 -507
  79. package/src/contracts/stableswap/scripts.ts +0 -37
  80. package/src/contracts/stableswap/transactions.ts +0 -475
  81. package/src/contracts/stableswap/types-new.ts +0 -131
  82. package/src/contracts/stableswap/types.ts +0 -17
  83. package/src/contracts/staking/helpers.ts +0 -136
  84. package/src/contracts/staking/scripts.ts +0 -41
  85. package/src/contracts/staking/transactions.ts +0 -349
  86. package/src/contracts/staking/types-new.ts +0 -137
  87. package/src/contracts/staking/types.ts +0 -17
  88. package/src/contracts/treasury/helpers.ts +0 -21
  89. package/src/contracts/treasury/queries.ts +0 -100
  90. package/src/contracts/treasury/scripts.ts +0 -27
  91. package/src/contracts/treasury/transactions.ts +0 -334
  92. package/src/contracts/treasury/types-new.ts +0 -69
  93. package/src/contracts/treasury/types.ts +0 -14
  94. package/src/contracts/version-registry/scripts.ts +0 -29
  95. package/src/contracts/version-registry/types-new.ts +0 -18
  96. package/src/contracts/version-registry/types.ts +0 -17
  97. package/src/index.ts +0 -99
  98. package/src/scripts/always-fail-validator.ts +0 -7
  99. package/src/scripts/auth-token-policy.ts +0 -24
  100. package/src/scripts/iasset-policy.ts +0 -23
  101. package/src/types/evolution-schema-options.ts +0 -16
  102. package/src/types/generic.ts +0 -52
  103. package/src/types/multisig.ts +0 -48
  104. package/src/types/on-chain-decimal.ts +0 -57
  105. package/src/types/rational.ts +0 -76
  106. package/src/types/system-params.ts +0 -463
  107. package/src/utils/array-utils.ts +0 -108
  108. package/src/utils/bigint-utils.ts +0 -35
  109. package/src/utils/helper-txs.ts +0 -31
  110. package/src/utils/indigo-helpers.ts +0 -17
  111. package/src/utils/lucid-utils.ts +0 -125
  112. package/src/utils/oracle-helpers.ts +0 -62
  113. package/src/utils/pyth/decode.ts +0 -223
  114. package/src/utils/pyth/encode.ts +0 -262
  115. package/src/utils/pyth/index.ts +0 -14
  116. package/src/utils/pyth/types.ts +0 -87
  117. package/src/utils/time-helpers.ts +0 -4
  118. package/src/utils/utils.ts +0 -25
  119. package/src/validators/always-succeed-validator.ts +0 -6
  120. package/src/validators/cdp-creator-validator.ts +0 -7
  121. package/src/validators/cdp-redeem-validator.ts +0 -7
  122. package/src/validators/cdp-validator.ts +0 -7
  123. package/src/validators/collector-validator.ts +0 -7
  124. package/src/validators/execute-validator.ts +0 -7
  125. package/src/validators/governance-validator.ts +0 -7
  126. package/src/validators/iasset-validator.ts +0 -7
  127. package/src/validators/interest-collection-validator.ts +0 -7
  128. package/src/validators/interest-oracle-validator.ts +0 -7
  129. package/src/validators/one-shot-policy.ts +0 -7
  130. package/src/validators/poll-manager-validator.ts +0 -7
  131. package/src/validators/poll-shard-validator.ts +0 -7
  132. package/src/validators/price-oracle-validator.ts +0 -7
  133. package/src/validators/pyth-feed-validator.ts +0 -7
  134. package/src/validators/rob-validator.ts +0 -7
  135. package/src/validators/stability-pool-validator.ts +0 -7
  136. package/src/validators/stableswap-validator.ts +0 -7
  137. package/src/validators/staking-validator.ts +0 -7
  138. package/src/validators/treasury-validator.ts +0 -7
  139. package/src/validators/version-record-policy.ts +0 -7
  140. package/src/validators/version-registry-validator.ts +0 -7
  141. package/tests/always-succeed/script.ts +0 -7
  142. package/tests/array-utils.test.ts +0 -92
  143. package/tests/bigint-utils.test.ts +0 -41
  144. package/tests/cdp/actions.ts +0 -680
  145. package/tests/cdp/cdp-helpers.ts +0 -55
  146. package/tests/cdp/cdp-queries.ts +0 -423
  147. package/tests/cdp/cdp.test.ts +0 -6730
  148. package/tests/cdp/transactions-mutated.ts +0 -1733
  149. package/tests/data/system-params.json +0 -1155
  150. package/tests/datums.test.ts +0 -302
  151. package/tests/endpoints/initialize.ts +0 -78
  152. package/tests/endpoints/interest-collector.ts +0 -37
  153. package/tests/endpoints/treasury.ts +0 -70
  154. package/tests/gov/actions.ts +0 -381
  155. package/tests/gov/gov.test.ts +0 -5147
  156. package/tests/gov/governance-queries.ts +0 -37
  157. package/tests/hash-checks.test.ts +0 -112
  158. package/tests/indigo-test-helpers.ts +0 -99
  159. package/tests/initialize.test.ts +0 -79
  160. package/tests/interest-calculations.test.ts +0 -120
  161. package/tests/interest-collection/interest-collection.test.ts +0 -843
  162. package/tests/interest-collection/transactions-mutated.ts +0 -260
  163. package/tests/interest-oracle.test.ts +0 -93
  164. package/tests/mock/assets-mock.ts +0 -243
  165. package/tests/mock/protocol-params-mock.ts +0 -21
  166. package/tests/price-oracle/actions.ts +0 -161
  167. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  168. package/tests/price-oracle/price-oracle.test.ts +0 -228
  169. package/tests/price-oracle/transactions-mutated.ts +0 -59
  170. package/tests/pyth/endpoints.ts +0 -96
  171. package/tests/pyth/helpers.ts +0 -37
  172. package/tests/pyth/pyth-encoding.test.ts +0 -376
  173. package/tests/pyth/pyth-feeds.test.ts +0 -943
  174. package/tests/pyth/pyth-indigo.test.ts +0 -505
  175. package/tests/pyth/pyth.test.ts +0 -299
  176. package/tests/queries/collector-queries.ts +0 -27
  177. package/tests/queries/execute-queries.ts +0 -47
  178. package/tests/queries/iasset-queries.ts +0 -149
  179. package/tests/queries/interest-oracle-queries.ts +0 -12
  180. package/tests/queries/poll-queries.ts +0 -97
  181. package/tests/queries/staking-queries.ts +0 -54
  182. package/tests/rob/actions.ts +0 -56
  183. package/tests/rob/rob-leverage.test.ts +0 -2555
  184. package/tests/rob/rob-queries.ts +0 -95
  185. package/tests/rob/rob.test.ts +0 -3677
  186. package/tests/rob/transactions-mutated.ts +0 -844
  187. package/tests/script-size.test.ts +0 -240
  188. package/tests/setup.ts +0 -135
  189. package/tests/stability-pool/actions.ts +0 -229
  190. package/tests/stability-pool.test.ts +0 -6491
  191. package/tests/stableswap/stableswap-actions.ts +0 -83
  192. package/tests/stableswap/stableswap-queries.ts +0 -98
  193. package/tests/stableswap/stableswap.test.ts +0 -4471
  194. package/tests/stableswap/transactions-mutated.ts +0 -348
  195. package/tests/staking.test.ts +0 -172
  196. package/tests/test-helpers.ts +0 -94
  197. package/tests/treasury/actions.ts +0 -67
  198. package/tests/treasury/treasury.test.ts +0 -320
  199. package/tests/utils/asserts.ts +0 -87
  200. package/tests/utils/benchmark-utils.ts +0 -130
  201. package/tests/utils/index.ts +0 -168
  202. package/tsconfig.build.json +0 -4
  203. package/tsconfig.json +0 -27
  204. package/vitest.config.ts +0 -11
@@ -1,100 +0,0 @@
1
- import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
- import { option as O, function as F } from 'fp-ts';
3
- import {
4
- AssetClass,
5
- assetClassToUnit,
6
- assetClassValueOf,
7
- getRandomElement,
8
- } from '@3rd-eye-labs/cardano-offchain-common';
9
- import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
10
-
11
- export async function findAllTreasuryUtxos(
12
- lucid: LucidEvolution,
13
- sysParams: SystemParams,
14
- ): Promise<UTxO[]> {
15
- // We need to consider both with staking credential and without.
16
- return lucid.utxosAt({
17
- type: 'Script',
18
- hash: sysParams.validatorHashes.treasuryHash,
19
- });
20
- }
21
-
22
- export async function findRandomTreasuryUtxo(
23
- lucid: LucidEvolution,
24
- sysParams: SystemParams,
25
- ): Promise<UTxO> {
26
- // We need to consider both with staking credential and without.
27
- const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
28
-
29
- return F.pipe(
30
- O.fromNullable(getRandomElement(treasuryUtxos)),
31
- O.match(() => {
32
- throw new Error('Expected some treasury UTXOs.');
33
- }, F.identity),
34
- );
35
- }
36
-
37
- export async function findRandomTreasuryUtxoWithOnlyAda(
38
- lucid: LucidEvolution,
39
- sysParams: SystemParams,
40
- ): Promise<UTxO> {
41
- // We need to consider both with staking credential and without.
42
- const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
43
-
44
- const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
45
- (utxo) => Object.keys(utxo.assets).length == 1,
46
- );
47
-
48
- return F.pipe(
49
- O.fromNullable(getRandomElement(adaOnlyTreasuryUtxos)),
50
- O.match(() => {
51
- throw new Error('Expected some treasury UTXOs.');
52
- }, F.identity),
53
- );
54
- }
55
-
56
- export async function findRandomTreasuryUtxoWithAsset(
57
- lucid: LucidEvolution,
58
- sysParams: SystemParams,
59
- asset: AssetClass,
60
- max_number_of_assets: bigint = 2n,
61
- ): Promise<UTxO> {
62
- // We need to consider both with staking credential and without.
63
- const treasuryUtxos = await lucid.utxosAtWithUnit(
64
- { hash: sysParams.validatorHashes.treasuryHash, type: 'Script' },
65
- assetClassToUnit(asset),
66
- );
67
-
68
- const validTreasuryUtxos = treasuryUtxos.filter(
69
- (utxo) => Object.keys(utxo.assets).length <= max_number_of_assets,
70
- );
71
-
72
- return F.pipe(
73
- O.fromNullable(getRandomElement(validTreasuryUtxos)),
74
- O.match(() => {
75
- throw new Error('Expected some treasury UTXOs.');
76
- }, F.identity),
77
- );
78
- }
79
-
80
- export async function findAllTreasuryUtxosWithNonAdaAsset(
81
- lucid: LucidEvolution,
82
- sysParams: SystemParams,
83
- includeDaoToken: boolean = true,
84
- ): Promise<UTxO[]> {
85
- // We need to consider both with staking credential and without.
86
- const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
87
-
88
- const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
89
- (utxo) =>
90
- Object.keys(utxo.assets).length !== 1 &&
91
- (includeDaoToken
92
- ? true
93
- : assetClassValueOf(
94
- utxo.assets,
95
- fromSystemParamsAsset(sysParams.govParams.daoIdentityToken),
96
- ) === 0n),
97
- );
98
-
99
- return treasuryUtxosWithNonAdaAsset;
100
- }
@@ -1,27 +0,0 @@
1
- import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
2
- import {
3
- fromSysParamsStakeCredential,
4
- fromSystemParamsAssetLucid,
5
- TreasuryParamsSP,
6
- } from '../../types/system-params';
7
- import { _treasuryValidator } from '../../validators/treasury-validator';
8
- import { castTreasuryParams } from './types';
9
-
10
- export const mkTreasuryValidatorFromSP = (
11
- params: TreasuryParamsSP,
12
- ): SpendingValidator => {
13
- return {
14
- type: 'PlutusV3',
15
- script: applyParamsToScript(_treasuryValidator.cborHex, [
16
- castTreasuryParams({
17
- upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
18
- versionRecordToken: fromSystemParamsAssetLucid(
19
- params.versionRecordToken,
20
- ),
21
- treasuryUtxosStakeCredential: params.treasuryUtxosStakeCredential
22
- ? fromSysParamsStakeCredential(params.treasuryUtxosStakeCredential)
23
- : null,
24
- }),
25
- ]),
26
- };
27
- };
@@ -1,334 +0,0 @@
1
- import {
2
- addAssets,
3
- Assets,
4
- Data,
5
- fromHex,
6
- LucidEvolution,
7
- OutRef,
8
- TxBuilder,
9
- UTxO,
10
- } from '@lucid-evolution/lucid';
11
- import {
12
- fromSystemParamsScriptRef,
13
- SystemParams,
14
- } from '../../types/system-params';
15
- import { matchSingle } from '../../utils/utils';
16
- import {
17
- adaAssetClass,
18
- AssetClass,
19
- estimateUtxoMinLovelace,
20
- mkAssetsOf,
21
- mkLovelacesOf,
22
- negateAssets,
23
- } from '@3rd-eye-labs/cardano-offchain-common';
24
- import { serialiseTreasuryDatum, serialiseTreasuryRedeemer } from './types-new';
25
- import { array as A, function as F } from 'fp-ts';
26
- import { parseExecuteDatumOrThrow } from '../execute/types-new';
27
- import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
28
- import { createValueFromWithdrawal } from '../gov/helpers';
29
- import { mkTreasuryAddr } from './helpers';
30
-
31
- export async function treasuryFeeTx(
32
- assetToPay: AssetClass,
33
- amountToPay: bigint,
34
- extraLovelaces: bigint,
35
- lucid: LucidEvolution,
36
- sysParams: SystemParams,
37
- tx: TxBuilder,
38
- actionOref: OutRef,
39
- /**
40
- * `undefined` in case using direct treasury payment.
41
- */
42
- treasuryOref: OutRef | undefined,
43
- ): Promise<UTxO | null> {
44
- const [asset, amt, extraLov] = ((): [AssetClass, bigint, bigint] => {
45
- if (amountToPay <= 0 && extraLovelaces > 0) {
46
- return [adaAssetClass, extraLovelaces, 0n];
47
- }
48
-
49
- return [assetToPay, amountToPay, extraLovelaces];
50
- })();
51
-
52
- // If no fee is to be collected, do not include treasury collection.
53
- if (amt <= 0n) return null;
54
-
55
- let treasuryRefScriptUtxo = null;
56
-
57
- if (treasuryOref !== undefined) {
58
- const treasuryUtxo = matchSingle(
59
- await lucid.utxosByOutRef([treasuryOref]),
60
- (_) => new Error('Expected a single treasury UTXO'),
61
- );
62
-
63
- treasuryRefScriptUtxo = matchSingle(
64
- await lucid.utxosByOutRef([
65
- fromSystemParamsScriptRef(
66
- sysParams.scriptReferences.treasuryValidatorRef,
67
- ),
68
- ]),
69
- (_) => new Error('Expected a single treasury Ref Script UTXO'),
70
- );
71
-
72
- tx.readFrom([treasuryRefScriptUtxo])
73
- .collectFrom(
74
- [treasuryUtxo],
75
- serialiseTreasuryRedeemer({
76
- Collect: {
77
- assetToCollect: asset,
78
- amountToCollect: amt,
79
- extraLovelaces: extraLov,
80
- actionInputOref: {
81
- txHash: fromHex(actionOref.txHash),
82
- outputIndex: BigInt(actionOref.outputIndex),
83
- },
84
- },
85
- }),
86
- )
87
- .pay.ToContract(
88
- mkTreasuryAddr(lucid, sysParams),
89
- {
90
- kind: 'inline',
91
- value: serialiseTreasuryDatum({
92
- treasuryInputOref: {
93
- txHash: fromHex(treasuryOref.txHash),
94
- outputIndex: BigInt(treasuryOref.outputIndex),
95
- },
96
- actionInputOref: {
97
- txHash: fromHex(actionOref.txHash),
98
- outputIndex: BigInt(actionOref.outputIndex),
99
- },
100
- }),
101
- },
102
- addAssets(
103
- treasuryUtxo.assets,
104
- mkAssetsOf(asset, amt),
105
- mkLovelacesOf(extraLov),
106
- ),
107
- );
108
- } else {
109
- tx.pay.ToContract(
110
- mkTreasuryAddr(lucid, sysParams),
111
- {
112
- kind: 'inline',
113
- value: serialiseTreasuryDatum({
114
- treasuryInputOref: null,
115
- actionInputOref: {
116
- txHash: fromHex(actionOref.txHash),
117
- outputIndex: BigInt(actionOref.outputIndex),
118
- },
119
- }),
120
- },
121
- addAssets(mkAssetsOf(asset, amt), mkLovelacesOf(extraLov)),
122
- );
123
- }
124
-
125
- return treasuryRefScriptUtxo;
126
- }
127
-
128
- export async function treasuryCollect(
129
- assetToPay: AssetClass,
130
- amountToPay: bigint,
131
- extraLovelaces: bigint,
132
- lucid: LucidEvolution,
133
- sysParams: SystemParams,
134
- actionOref: OutRef,
135
- treasuryOref: OutRef,
136
- ): Promise<TxBuilder> {
137
- const treasuryUtxo = matchSingle(
138
- await lucid.utxosByOutRef([treasuryOref]),
139
- (_) => new Error('Expected a single treasury UTXO'),
140
- );
141
-
142
- const treasuryRefScriptUtxo = matchSingle(
143
- await lucid.utxosByOutRef([
144
- fromSystemParamsScriptRef(
145
- sysParams.scriptReferences.treasuryValidatorRef,
146
- ),
147
- ]),
148
- (_) => new Error('Expected a single treasury Ref Script UTXO'),
149
- );
150
-
151
- return lucid
152
- .newTx()
153
- .readFrom([treasuryRefScriptUtxo])
154
- .collectFrom(
155
- [treasuryUtxo],
156
- serialiseTreasuryRedeemer({
157
- Collect: {
158
- assetToCollect: assetToPay,
159
- amountToCollect: amountToPay,
160
- extraLovelaces: extraLovelaces,
161
- actionInputOref: {
162
- txHash: fromHex(actionOref.txHash),
163
- outputIndex: BigInt(actionOref.outputIndex),
164
- },
165
- },
166
- }),
167
- )
168
- .pay.ToContract(
169
- mkTreasuryAddr(lucid, sysParams),
170
- {
171
- kind: 'inline',
172
- value: serialiseTreasuryDatum({
173
- treasuryInputOref: {
174
- txHash: fromHex(treasuryOref.txHash),
175
- outputIndex: BigInt(treasuryOref.outputIndex),
176
- },
177
- actionInputOref: {
178
- txHash: fromHex(actionOref.txHash),
179
- outputIndex: BigInt(actionOref.outputIndex),
180
- },
181
- }),
182
- },
183
- addAssets(
184
- treasuryUtxo.assets,
185
- mkAssetsOf(assetToPay, amountToPay),
186
- mkLovelacesOf(extraLovelaces),
187
- ),
188
- );
189
- }
190
-
191
- export async function treasuryMerge(
192
- treasuryOutRefs: OutRef[],
193
- lucid: LucidEvolution,
194
- sysParams: SystemParams,
195
- ): Promise<TxBuilder> {
196
- const treasuryScriptRefUtxo = matchSingle(
197
- await lucid.utxosByOutRef([
198
- fromSystemParamsScriptRef(
199
- sysParams.scriptReferences.treasuryValidatorRef,
200
- ),
201
- ]),
202
- (_) => new Error('Expected a single treasury Ref Script UTXO'),
203
- );
204
-
205
- const treasuryUtxos = await lucid.utxosByOutRef(treasuryOutRefs);
206
-
207
- const totalAssets = F.pipe(
208
- treasuryUtxos,
209
- A.reduce<UTxO, Assets>({}, (acc, utxo) => addAssets(acc, utxo.assets)),
210
- );
211
-
212
- return lucid
213
- .newTx()
214
- .readFrom([treasuryScriptRefUtxo])
215
- .collectFrom(treasuryUtxos, serialiseTreasuryRedeemer('Merge'))
216
- .pay.ToContract(
217
- mkTreasuryAddr(lucid, sysParams),
218
- { kind: 'inline', value: Data.void() },
219
- totalAssets,
220
- );
221
- }
222
-
223
- export async function treasurySplit(
224
- treasuryOutRef: OutRef,
225
- lucid: LucidEvolution,
226
- sysParams: SystemParams,
227
- ): Promise<TxBuilder> {
228
- const treasuryScriptRefUtxo = matchSingle(
229
- await lucid.utxosByOutRef([
230
- fromSystemParamsScriptRef(
231
- sysParams.scriptReferences.treasuryValidatorRef,
232
- ),
233
- ]),
234
- (_) => new Error('Expected a single treasury Ref Script UTXO'),
235
- );
236
-
237
- const treasuryUtxo = matchSingle(
238
- await lucid.utxosByOutRef([treasuryOutRef]),
239
- (_) => new Error('Expected a single treasury UTXO'),
240
- );
241
-
242
- const [adaAsset, ...nonAdaAssets] = Object.keys(treasuryUtxo.assets);
243
-
244
- const tx = lucid
245
- .newTx()
246
- .collectFrom([treasuryUtxo], serialiseTreasuryRedeemer('Split'))
247
- .readFrom([treasuryScriptRefUtxo]);
248
-
249
- let paidLovelaces = 0n;
250
-
251
- for (const asset of A.reverse(nonAdaAssets.sort())) {
252
- const utxoMinLovelace = estimateUtxoMinLovelace(
253
- lucid.config().protocolParameters!,
254
- mkTreasuryAddr(lucid, sysParams),
255
- { [asset]: treasuryUtxo.assets[asset] },
256
- { InlineDatum: { datum: Data.void() } },
257
- );
258
-
259
- paidLovelaces += utxoMinLovelace;
260
-
261
- tx.pay.ToContract(
262
- mkTreasuryAddr(lucid, sysParams),
263
- { kind: 'inline', value: Data.void() },
264
- addAssets(
265
- { [asset]: treasuryUtxo.assets[asset] },
266
- mkLovelacesOf(utxoMinLovelace),
267
- ),
268
- );
269
- }
270
-
271
- tx.pay.ToContract(
272
- mkTreasuryAddr(lucid, sysParams),
273
- { kind: 'inline', value: Data.void() },
274
- { [adaAsset]: treasuryUtxo.assets[adaAsset] - paidLovelaces },
275
- );
276
-
277
- return tx;
278
- }
279
-
280
- export async function treasuryPrepareWithdrawal(
281
- treasuryOutRefs: OutRef[],
282
- upgradeOutRef: OutRef,
283
- lucid: LucidEvolution,
284
- sysParams: SystemParams,
285
- ): Promise<TxBuilder> {
286
- const treasuryScriptRefUtxo = matchSingle(
287
- await lucid.utxosByOutRef([
288
- fromSystemParamsScriptRef(
289
- sysParams.scriptReferences.treasuryValidatorRef,
290
- ),
291
- ]),
292
- (_) => new Error('Expected a single treasury Ref Script UTXO'),
293
- );
294
-
295
- const treasuryUtxos = await lucid.utxosByOutRef(treasuryOutRefs);
296
-
297
- const upgradeUtxo = matchSingle(
298
- await lucid.utxosByOutRef([upgradeOutRef]),
299
- (_) => new Error('Expected a single upgrade UTXO'),
300
- );
301
-
302
- const treasuryAddress = mkTreasuryAddr(lucid, sysParams);
303
-
304
- const totalAssets = F.pipe(
305
- treasuryUtxos,
306
- A.reduce<UTxO, Assets>({}, (acc, utxo) => addAssets(acc, utxo.assets)),
307
- );
308
- const executeDatum = parseExecuteDatumOrThrow(
309
- getInlineDatumOrThrow(upgradeUtxo),
310
- );
311
- if (!executeDatum.treasuryWithdrawal)
312
- throw new Error('Expected a treasury withdrawal in the execute datum');
313
- const withdrawalVal = createValueFromWithdrawal(
314
- executeDatum.treasuryWithdrawal,
315
- );
316
- const change = addAssets(totalAssets, negateAssets(withdrawalVal));
317
-
318
- const tx = lucid
319
- .newTx()
320
- .collectFrom(treasuryUtxos, serialiseTreasuryRedeemer('PrepareWithdraw'))
321
- .readFrom([treasuryScriptRefUtxo, upgradeUtxo])
322
- .pay.ToContract(
323
- treasuryAddress,
324
- { kind: 'inline', value: Data.void() },
325
- withdrawalVal,
326
- )
327
- .pay.ToContract(
328
- treasuryAddress,
329
- { kind: 'inline', value: Data.void() },
330
- change,
331
- );
332
-
333
- return tx;
334
- }
@@ -1,69 +0,0 @@
1
- import { TSchema, Data } from '@evolution-sdk/evolution';
2
- import {
3
- AssetClassSchema,
4
- OutputReferenceSchema,
5
- } from '@3rd-eye-labs/cardano-offchain-common';
6
- import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
7
-
8
- const WithdrawalOutputDatumSchema = TSchema.Tuple([
9
- TSchema.ByteArray,
10
- OutputReferenceSchema,
11
- ]);
12
-
13
- export type WithdrawalOutputDatum = typeof WithdrawalOutputDatumSchema.Type;
14
-
15
- const TreasuryDatumSchema = TSchema.Struct(
16
- {
17
- treasuryInputOref: TSchema.NullOr(OutputReferenceSchema),
18
- actionInputOref: OutputReferenceSchema,
19
- },
20
- { flatFields: true },
21
- );
22
-
23
- export type TreasuryDatum = typeof TreasuryDatumSchema.Type;
24
-
25
- const TreasuryRedeemerSchema = TSchema.Union(
26
- TSchema.Literal('Withdraw', { flatInUnion: true }),
27
- TSchema.Literal('PrepareWithdraw', { flatInUnion: true }),
28
- TSchema.Literal('Split', { flatInUnion: true }),
29
- TSchema.Literal('Merge', { flatInUnion: true }),
30
- TSchema.Struct(
31
- {
32
- Collect: TSchema.Struct(
33
- {
34
- assetToCollect: AssetClassSchema,
35
- amountToCollect: TSchema.Integer,
36
- extraLovelaces: TSchema.Integer,
37
- actionInputOref: OutputReferenceSchema,
38
- },
39
- { flatFields: true },
40
- ),
41
- },
42
- { flatInUnion: true },
43
- ),
44
- TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
45
- );
46
-
47
- export type TreasuryRedeemer = typeof TreasuryRedeemerSchema.Type;
48
-
49
- export function serialiseTreasuryRedeemer(r: TreasuryRedeemer): string {
50
- return Data.withSchema(
51
- TreasuryRedeemerSchema,
52
- DEFAULT_SCHEMA_OPTIONS,
53
- ).toCBORHex(r);
54
- }
55
-
56
- export function serialiseWithdrawalOutputDatum(
57
- d: WithdrawalOutputDatum,
58
- ): string {
59
- return Data.withSchema(
60
- WithdrawalOutputDatumSchema,
61
- DEFAULT_SCHEMA_OPTIONS,
62
- ).toCBORHex(d);
63
- }
64
-
65
- export function serialiseTreasuryDatum(d: TreasuryDatum): string {
66
- return Data.withSchema(TreasuryDatumSchema, DEFAULT_SCHEMA_OPTIONS).toCBORHex(
67
- d,
68
- );
69
- }
@@ -1,14 +0,0 @@
1
- import { Data } from '@lucid-evolution/lucid';
2
- import { AssetClassSchema, StakeCredentialSchema } from '../../types/generic';
3
-
4
- export const TreasuryParamsSchema = Data.Object({
5
- upgradeToken: AssetClassSchema,
6
- versionRecordToken: AssetClassSchema,
7
- treasuryUtxosStakeCredential: Data.Nullable(StakeCredentialSchema),
8
- });
9
- export type TreasuryParams = Data.Static<typeof TreasuryParamsSchema>;
10
- export const TreasuryParams = TreasuryParamsSchema as unknown as TreasuryParams;
11
-
12
- export function castTreasuryParams(params: TreasuryParams): Data {
13
- return Data.castTo(params, TreasuryParams);
14
- }
@@ -1,29 +0,0 @@
1
- import {
2
- applyParamsToScript,
3
- MintingPolicy,
4
- SpendingValidator,
5
- } from '@lucid-evolution/lucid';
6
- import {
7
- castVersionRecordTokenParams,
8
- VersionRecordTokenParams,
9
- } from './types';
10
- import { _versionRecordTokenPolicy } from '../../validators/version-record-policy';
11
- import { _versionRegistryValidator } from '../../validators/version-registry-validator';
12
-
13
- export function mkVersionRecordTokenPolicy(
14
- params: VersionRecordTokenParams,
15
- ): MintingPolicy {
16
- return {
17
- type: 'PlutusV3',
18
- script: applyParamsToScript(_versionRecordTokenPolicy.cborHex, [
19
- castVersionRecordTokenParams(params),
20
- ]),
21
- };
22
- }
23
-
24
- export const mkVersionRegistryValidator = (): SpendingValidator => {
25
- return {
26
- type: 'PlutusV3',
27
- script: _versionRegistryValidator.cborHex,
28
- };
29
- };
@@ -1,18 +0,0 @@
1
- import { TSchema, Data } from '@evolution-sdk/evolution';
2
- import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
3
-
4
- const VersionRecordDatumSchema = TSchema.Struct({
5
- upgradeId: TSchema.Integer,
6
- /// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
7
- upgradePaths: TSchema.Array(
8
- TSchema.Tuple([TSchema.ByteArray, TSchema.ByteArray]),
9
- ),
10
- });
11
- export type VersionRecordDatum = typeof VersionRecordDatumSchema.Type;
12
-
13
- export function serialiseVersionRecordDatum(d: VersionRecordDatum): string {
14
- return Data.withSchema(
15
- VersionRecordDatumSchema,
16
- DEFAULT_SCHEMA_OPTIONS,
17
- ).toCBORHex(d);
18
- }
@@ -1,17 +0,0 @@
1
- import { Data } from '@lucid-evolution/lucid';
2
- import { AssetClassSchema } from '../../types/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
- }