@indigo-labs/indigo-sdk 0.5.4 → 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 (208) hide show
  1. package/dist/index.d.mts +11 -1
  2. package/dist/index.d.ts +11 -1
  3. package/dist/index.js +17 -0
  4. package/dist/index.mjs +15 -0
  5. package/package.json +11 -1
  6. package/.claude/settings.local.json +0 -7
  7. package/.github/workflows/ci.yml +0 -66
  8. package/.husky/pre-commit +0 -1
  9. package/.nvmrc +0 -1
  10. package/.prettierignore +0 -1
  11. package/.prettierrc +0 -6
  12. package/eslint.config.mjs +0 -42
  13. package/scripts/bench.sh +0 -62
  14. package/scripts/run-repeat.sh +0 -22
  15. package/src/contracts/cdp/helpers.ts +0 -173
  16. package/src/contracts/cdp/scripts.ts +0 -70
  17. package/src/contracts/cdp/transactions.ts +0 -1584
  18. package/src/contracts/cdp/types-new.ts +0 -277
  19. package/src/contracts/cdp/types.ts +0 -43
  20. package/src/contracts/cdp-creator/queries.ts +0 -30
  21. package/src/contracts/cdp-creator/scripts.ts +0 -45
  22. package/src/contracts/cdp-creator/types-new.ts +0 -50
  23. package/src/contracts/cdp-creator/types.ts +0 -24
  24. package/src/contracts/collector/scripts.ts +0 -32
  25. package/src/contracts/collector/transactions.ts +0 -50
  26. package/src/contracts/collector/types-new.ts +0 -17
  27. package/src/contracts/execute/scripts.ts +0 -57
  28. package/src/contracts/execute/types-new.ts +0 -44
  29. package/src/contracts/execute/types.ts +0 -24
  30. package/src/contracts/gov/helpers.ts +0 -351
  31. package/src/contracts/gov/scripts.ts +0 -41
  32. package/src/contracts/gov/transactions.ts +0 -1607
  33. package/src/contracts/gov/types-new.ts +0 -268
  34. package/src/contracts/gov/types.ts +0 -22
  35. package/src/contracts/iasset/helpers.ts +0 -170
  36. package/src/contracts/iasset/queries.ts +0 -102
  37. package/src/contracts/iasset/scripts.ts +0 -38
  38. package/src/contracts/iasset/types.ts +0 -154
  39. package/src/contracts/initialize/actions.ts +0 -789
  40. package/src/contracts/initialize/helpers.ts +0 -616
  41. package/src/contracts/initialize/types.ts +0 -116
  42. package/src/contracts/interest-collection/helpers.ts +0 -19
  43. package/src/contracts/interest-collection/queries.ts +0 -66
  44. package/src/contracts/interest-collection/scripts.ts +0 -44
  45. package/src/contracts/interest-collection/transactions.ts +0 -433
  46. package/src/contracts/interest-collection/types-new.ts +0 -50
  47. package/src/contracts/interest-collection/types.ts +0 -26
  48. package/src/contracts/interest-oracle/helpers.ts +0 -61
  49. package/src/contracts/interest-oracle/scripts.ts +0 -18
  50. package/src/contracts/interest-oracle/transactions.ts +0 -151
  51. package/src/contracts/interest-oracle/types-new.ts +0 -32
  52. package/src/contracts/interest-oracle/types.ts +0 -16
  53. package/src/contracts/one-shot/scripts.ts +0 -12
  54. package/src/contracts/one-shot/transactions.ts +0 -66
  55. package/src/contracts/one-shot/types.ts +0 -22
  56. package/src/contracts/poll/helpers.ts +0 -37
  57. package/src/contracts/poll/scripts.ts +0 -71
  58. package/src/contracts/poll/types-poll-manager.ts +0 -20
  59. package/src/contracts/poll/types-poll-new.ts +0 -196
  60. package/src/contracts/poll/types-poll-shard.ts +0 -16
  61. package/src/contracts/price-oracle/helpers.ts +0 -30
  62. package/src/contracts/price-oracle/scripts.ts +0 -18
  63. package/src/contracts/price-oracle/transactions.ts +0 -115
  64. package/src/contracts/price-oracle/types-new.ts +0 -50
  65. package/src/contracts/price-oracle/types.ts +0 -16
  66. package/src/contracts/pyth-feed/helpers.ts +0 -82
  67. package/src/contracts/pyth-feed/scripts.ts +0 -15
  68. package/src/contracts/pyth-feed/types.ts +0 -181
  69. package/src/contracts/rob/helpers.ts +0 -666
  70. package/src/contracts/rob/scripts.ts +0 -35
  71. package/src/contracts/rob/transactions.ts +0 -423
  72. package/src/contracts/rob/types-new.ts +0 -128
  73. package/src/contracts/rob/types.ts +0 -16
  74. package/src/contracts/rob-leverage/helpers.ts +0 -422
  75. package/src/contracts/rob-leverage/transactions.ts +0 -368
  76. package/src/contracts/stability-pool/helpers.ts +0 -798
  77. package/src/contracts/stability-pool/queries.ts +0 -132
  78. package/src/contracts/stability-pool/scripts.ts +0 -51
  79. package/src/contracts/stability-pool/transactions.ts +0 -921
  80. package/src/contracts/stability-pool/types-new.ts +0 -385
  81. package/src/contracts/stability-pool/types.ts +0 -25
  82. package/src/contracts/stableswap/helpers.ts +0 -507
  83. package/src/contracts/stableswap/scripts.ts +0 -37
  84. package/src/contracts/stableswap/transactions.ts +0 -475
  85. package/src/contracts/stableswap/types-new.ts +0 -131
  86. package/src/contracts/stableswap/types.ts +0 -17
  87. package/src/contracts/staking/helpers.ts +0 -136
  88. package/src/contracts/staking/scripts.ts +0 -41
  89. package/src/contracts/staking/transactions.ts +0 -349
  90. package/src/contracts/staking/types-new.ts +0 -137
  91. package/src/contracts/staking/types.ts +0 -17
  92. package/src/contracts/treasury/helpers.ts +0 -21
  93. package/src/contracts/treasury/queries.ts +0 -100
  94. package/src/contracts/treasury/scripts.ts +0 -27
  95. package/src/contracts/treasury/transactions.ts +0 -334
  96. package/src/contracts/treasury/types-new.ts +0 -69
  97. package/src/contracts/treasury/types.ts +0 -14
  98. package/src/contracts/version-registry/scripts.ts +0 -29
  99. package/src/contracts/version-registry/types-new.ts +0 -18
  100. package/src/contracts/version-registry/types.ts +0 -17
  101. package/src/index.ts +0 -93
  102. package/src/scripts/always-fail-validator.ts +0 -7
  103. package/src/scripts/auth-token-policy.ts +0 -24
  104. package/src/scripts/iasset-policy.ts +0 -23
  105. package/src/types/evolution-schema-options.ts +0 -16
  106. package/src/types/generic.ts +0 -52
  107. package/src/types/multisig.ts +0 -48
  108. package/src/types/on-chain-decimal.ts +0 -57
  109. package/src/types/rational.ts +0 -61
  110. package/src/types/system-params.ts +0 -463
  111. package/src/utils/array-utils.ts +0 -108
  112. package/src/utils/bigint-utils.ts +0 -35
  113. package/src/utils/helper-txs.ts +0 -31
  114. package/src/utils/indigo-helpers.ts +0 -17
  115. package/src/utils/lucid-utils.ts +0 -125
  116. package/src/utils/oracle-helpers.ts +0 -62
  117. package/src/utils/pyth/decode.ts +0 -223
  118. package/src/utils/pyth/encode.ts +0 -262
  119. package/src/utils/pyth/index.ts +0 -14
  120. package/src/utils/pyth/types.ts +0 -87
  121. package/src/utils/time-helpers.ts +0 -4
  122. package/src/utils/utils.ts +0 -25
  123. package/src/validators/always-succeed-validator.ts +0 -6
  124. package/src/validators/cdp-creator-validator.ts +0 -7
  125. package/src/validators/cdp-redeem-validator.ts +0 -7
  126. package/src/validators/cdp-validator.ts +0 -7
  127. package/src/validators/collector-validator.ts +0 -7
  128. package/src/validators/execute-validator.ts +0 -7
  129. package/src/validators/governance-validator.ts +0 -7
  130. package/src/validators/iasset-validator.ts +0 -7
  131. package/src/validators/interest-collection-validator.ts +0 -7
  132. package/src/validators/interest-oracle-validator.ts +0 -7
  133. package/src/validators/one-shot-policy.ts +0 -7
  134. package/src/validators/poll-manager-validator.ts +0 -7
  135. package/src/validators/poll-shard-validator.ts +0 -7
  136. package/src/validators/price-oracle-validator.ts +0 -7
  137. package/src/validators/pyth-feed-validator.ts +0 -7
  138. package/src/validators/rob-validator.ts +0 -7
  139. package/src/validators/stability-pool-validator.ts +0 -7
  140. package/src/validators/stableswap-validator.ts +0 -7
  141. package/src/validators/staking-validator.ts +0 -7
  142. package/src/validators/treasury-validator.ts +0 -7
  143. package/src/validators/version-record-policy.ts +0 -7
  144. package/src/validators/version-registry-validator.ts +0 -7
  145. package/tests/always-succeed/script.ts +0 -7
  146. package/tests/array-utils.test.ts +0 -92
  147. package/tests/bigint-utils.test.ts +0 -41
  148. package/tests/cdp/actions.ts +0 -680
  149. package/tests/cdp/cdp-helpers.ts +0 -55
  150. package/tests/cdp/cdp-queries.ts +0 -423
  151. package/tests/cdp/cdp.test.ts +0 -6730
  152. package/tests/cdp/transactions-mutated.ts +0 -1733
  153. package/tests/data/system-params.json +0 -1155
  154. package/tests/datums.test.ts +0 -302
  155. package/tests/endpoints/initialize.ts +0 -78
  156. package/tests/endpoints/interest-collector.ts +0 -37
  157. package/tests/endpoints/treasury.ts +0 -70
  158. package/tests/gov/actions.ts +0 -381
  159. package/tests/gov/gov.test.ts +0 -5147
  160. package/tests/gov/governance-queries.ts +0 -37
  161. package/tests/hash-checks.test.ts +0 -112
  162. package/tests/indigo-test-helpers.ts +0 -99
  163. package/tests/initialize.test.ts +0 -79
  164. package/tests/interest-calculations.test.ts +0 -120
  165. package/tests/interest-collection/interest-collection.test.ts +0 -843
  166. package/tests/interest-collection/transactions-mutated.ts +0 -260
  167. package/tests/interest-oracle.test.ts +0 -93
  168. package/tests/mock/assets-mock.ts +0 -243
  169. package/tests/mock/protocol-params-mock.ts +0 -21
  170. package/tests/price-oracle/actions.ts +0 -161
  171. package/tests/price-oracle/price-oracle-queries.ts +0 -12
  172. package/tests/price-oracle/price-oracle.test.ts +0 -228
  173. package/tests/price-oracle/transactions-mutated.ts +0 -59
  174. package/tests/pyth/endpoints.ts +0 -96
  175. package/tests/pyth/helpers.ts +0 -37
  176. package/tests/pyth/pyth-encoding.test.ts +0 -376
  177. package/tests/pyth/pyth-feeds.test.ts +0 -943
  178. package/tests/pyth/pyth-indigo.test.ts +0 -505
  179. package/tests/pyth/pyth.test.ts +0 -299
  180. package/tests/queries/collector-queries.ts +0 -27
  181. package/tests/queries/execute-queries.ts +0 -47
  182. package/tests/queries/iasset-queries.ts +0 -149
  183. package/tests/queries/interest-oracle-queries.ts +0 -12
  184. package/tests/queries/poll-queries.ts +0 -97
  185. package/tests/queries/staking-queries.ts +0 -54
  186. package/tests/rob/actions.ts +0 -56
  187. package/tests/rob/rob-leverage.test.ts +0 -2555
  188. package/tests/rob/rob-queries.ts +0 -95
  189. package/tests/rob/rob.test.ts +0 -3677
  190. package/tests/rob/transactions-mutated.ts +0 -844
  191. package/tests/script-size.test.ts +0 -240
  192. package/tests/setup.ts +0 -135
  193. package/tests/stability-pool/actions.ts +0 -229
  194. package/tests/stability-pool.test.ts +0 -6491
  195. package/tests/stableswap/stableswap-actions.ts +0 -83
  196. package/tests/stableswap/stableswap-queries.ts +0 -98
  197. package/tests/stableswap/stableswap.test.ts +0 -4471
  198. package/tests/stableswap/transactions-mutated.ts +0 -348
  199. package/tests/staking.test.ts +0 -172
  200. package/tests/test-helpers.ts +0 -94
  201. package/tests/treasury/actions.ts +0 -67
  202. package/tests/treasury/treasury.test.ts +0 -320
  203. package/tests/utils/asserts.ts +0 -87
  204. package/tests/utils/benchmark-utils.ts +0 -130
  205. package/tests/utils/index.ts +0 -168
  206. package/tsconfig.build.json +0 -4
  207. package/tsconfig.json +0 -27
  208. package/vitest.config.ts +0 -11
@@ -1,161 +0,0 @@
1
- import {
2
- AssetClass,
3
- getInlineDatumOrThrow,
4
- isSameAssetClass,
5
- } from '@3rd-eye-labs/cardano-offchain-common';
6
- import { AssetInfo, fromSystemParamsAsset, SystemParams } from '../../src';
7
- import {
8
- LucidContext,
9
- runAndAwaitTx,
10
- selectWalletByAddress,
11
- } from '../test-helpers';
12
- import {
13
- findAllNecessaryOrefs,
14
- findPrice,
15
- findPriceOracleFromCollateralAsset,
16
- } from '../cdp/cdp-queries';
17
- import { feedPriceOracleTx } from '../../src/contracts/price-oracle/transactions';
18
- import { findCollateralAsset } from '../queries/iasset-queries';
19
- import { findPriceOracle } from './price-oracle-queries';
20
- import { match, P } from 'ts-pattern';
21
- import { parsePriceOracleDatum } from '../../src/contracts/price-oracle/types-new';
22
- import { expect } from 'vitest';
23
- import { Rational } from '../../src/types/rational';
24
-
25
- /**
26
- * Selects admin wallet and feeds the price oracle with the given price
27
- */
28
- export async function runFeedPriceToOracle(
29
- context: LucidContext,
30
- sysParams: SystemParams,
31
- assetInfo: AssetInfo,
32
- collateralAsset: AssetClass,
33
- price: Rational,
34
- ): Promise<void> {
35
- const prevAddr = await context.lucid.wallet().address();
36
-
37
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
38
-
39
- const collateralOut = await findCollateralAsset(
40
- context.lucid,
41
- sysParams,
42
- fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
43
- assetInfo.iassetTokenNameAscii,
44
- collateralAsset,
45
- );
46
-
47
- const collateralInfo = assetInfo.collateralAssets.find((a) =>
48
- isSameAssetClass(a.collateralAsset, collateralAsset),
49
- );
50
-
51
- if (!collateralInfo) {
52
- throw new Error('No such collateral asset for the given iasset.');
53
- }
54
-
55
- const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
56
- context.lucid,
57
- collateralOut,
58
- );
59
-
60
- await runAndAwaitTx(
61
- context.lucid,
62
- feedPriceOracleTx(
63
- context.lucid,
64
- priceOracleUtxo!,
65
- price,
66
- collateralInfo.oracleParams!,
67
- ),
68
- );
69
-
70
- selectWalletByAddress(context, prevAddr);
71
- }
72
-
73
- /**
74
- * When oracle expired, refreshing updates the expiration leaving the same price.
75
- */
76
- export async function refreshPriceOracle(
77
- context: LucidContext,
78
- sysParams: SystemParams,
79
- assetInfo: AssetInfo,
80
- collateralAsset: AssetClass,
81
- ): Promise<void> {
82
- const prevAddr = await context.lucid.wallet().address();
83
-
84
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
85
-
86
- // Feed price oracle
87
- const orefs = await findAllNecessaryOrefs(
88
- context.lucid,
89
- sysParams,
90
- assetInfo.iassetTokenNameAscii,
91
- collateralAsset,
92
- );
93
-
94
- const collateralInfo = assetInfo.collateralAssets.find((a) =>
95
- isSameAssetClass(a.collateralAsset, collateralAsset),
96
- );
97
-
98
- if (!collateralInfo) {
99
- throw new Error('No such collateral asset for the given iasset.');
100
- }
101
-
102
- const price = await findPrice(
103
- context.lucid,
104
- sysParams,
105
- assetInfo.iassetTokenNameAscii,
106
- collateralAsset,
107
- );
108
-
109
- const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
110
- context.lucid,
111
- orefs.collateralAsset,
112
- );
113
-
114
- await runAndAwaitTx(
115
- context.lucid,
116
- feedPriceOracleTx(
117
- context.lucid,
118
- priceOracleUtxo!,
119
- price,
120
- collateralInfo.oracleParams!,
121
- ),
122
- );
123
-
124
- selectWalletByAddress(context, prevAddr);
125
- }
126
-
127
- export async function waitForOracleExpiration(
128
- context: LucidContext,
129
- sysParams: SystemParams,
130
- iasset: string,
131
- collateralAsset: AssetClass,
132
- ): Promise<void> {
133
- const collateral = await findCollateralAsset(
134
- context.lucid,
135
- sysParams,
136
- fromSystemParamsAsset(sysParams.cdpCreatorParams.collateralAssetAuthTk),
137
- iasset,
138
- collateralAsset,
139
- );
140
-
141
- await match(collateral.datum.priceInfo)
142
- .with({ OracleNft: P.select() }, async (nft) => {
143
- const priceOracle = await findPriceOracle(context.lucid, nft);
144
-
145
- const oracle = parsePriceOracleDatum(getInlineDatumOrThrow(priceOracle));
146
-
147
- const targetSlot = context.lucid.unixTimeToSlot(
148
- Number(oracle.expirationTime),
149
- );
150
-
151
- if (targetSlot > context.lucid.currentSlot()) {
152
- expect(targetSlot).toBeGreaterThan(context.lucid.currentSlot());
153
-
154
- context.emulator.awaitSlot(
155
- targetSlot - context.lucid.currentSlot() + 5,
156
- );
157
- }
158
- })
159
- // otherwise no need to await
160
- .otherwise(() => {});
161
- }
@@ -1,12 +0,0 @@
1
- import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
2
- import {
3
- AssetClass,
4
- assetClassToUnit,
5
- } from '@3rd-eye-labs/cardano-offchain-common';
6
-
7
- export async function findPriceOracle(
8
- lucid: LucidEvolution,
9
- oracleNft: AssetClass,
10
- ): Promise<UTxO> {
11
- return lucid.utxoByUnit(assetClassToUnit(oracleNft));
12
- }
@@ -1,228 +0,0 @@
1
- import {
2
- addAssets,
3
- Emulator,
4
- EmulatorAccount,
5
- generateEmulatorAccount,
6
- Lucid,
7
- paymentCredentialOf,
8
- } from '@lucid-evolution/lucid';
9
- import { beforeEach, describe, test } from 'vitest';
10
- import {
11
- LucidContext,
12
- runAndAwaitTx,
13
- runAndAwaitTxBuilder,
14
- } from '../test-helpers';
15
- import { mkLovelacesOf } from '@3rd-eye-labs/cardano-offchain-common';
16
- import {
17
- feedPriceOracleTx,
18
- PriceOracleParams,
19
- startPriceOracleTx,
20
- } from '../../src';
21
- import { expectScriptFailure } from '../utils/asserts';
22
- import { feedPriceOracleTxStealNft } from './transactions-mutated';
23
- import * as Core from '@evolution-sdk/evolution';
24
- import { rationalFromInt } from '../../src/types/rational';
25
-
26
- type MyContext = LucidContext<{
27
- admin: EmulatorAccount;
28
- }>;
29
-
30
- describe('Rational Price Oracle', () => {
31
- beforeEach<MyContext>(async (context: MyContext) => {
32
- context.users = {
33
- admin: generateEmulatorAccount(
34
- addAssets(mkLovelacesOf(100_000_000_000_000n)),
35
- ),
36
- };
37
-
38
- context.emulator = new Emulator(Object.values(context.users));
39
- context.lucid = await Lucid(context.emulator, 'Custom');
40
- context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
41
- });
42
-
43
- test<MyContext>('Start Rational Price Oracle', async (context: MyContext) => {
44
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
45
- const params: PriceOracleParams = {
46
- owner: pkh,
47
- biasTime: 20_000n,
48
- expirationPeriod: 1_800_000n,
49
- };
50
- const [tx, _] = await startPriceOracleTx(
51
- context.lucid,
52
- 'ORACLE_NFT',
53
- rationalFromInt(1n),
54
- params,
55
- );
56
-
57
- await runAndAwaitTxBuilder(context.lucid, tx);
58
- });
59
-
60
- test<MyContext>('Feed Rational Price Oracle', async (context: MyContext) => {
61
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
62
- const params: PriceOracleParams = {
63
- owner: pkh,
64
- biasTime: 20_000n,
65
- expirationPeriod: 1_800_000n,
66
- };
67
- const [startTx, _] = await startPriceOracleTx(
68
- context.lucid,
69
- 'ORACLE_NFT',
70
- rationalFromInt(1n),
71
- params,
72
- );
73
-
74
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
75
-
76
- const feedTx = await feedPriceOracleTx(
77
- context.lucid,
78
- { txHash: startTxHash, outputIndex: 0 },
79
- rationalFromInt(2n),
80
- params,
81
- );
82
-
83
- await runAndAwaitTxBuilder(context.lucid, feedTx);
84
- });
85
-
86
- test<MyContext>('Feed Rational Price Oracle cannot be negative', async (context: MyContext) => {
87
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
88
- const params: PriceOracleParams = {
89
- owner: pkh,
90
- biasTime: 20_000n,
91
- expirationPeriod: 1_800_000n,
92
- };
93
- const [startTx, _] = await startPriceOracleTx(
94
- context.lucid,
95
- 'ORACLE_NFT',
96
- rationalFromInt(1n),
97
- params,
98
- );
99
-
100
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
101
-
102
- await expectScriptFailure(
103
- 'Price must be positive',
104
- feedPriceOracleTx(
105
- context.lucid,
106
- { txHash: startTxHash, outputIndex: 0 },
107
- rationalFromInt(-2n),
108
- params,
109
- ),
110
- );
111
- });
112
-
113
- test<MyContext>('Feed Rational Price Oracle cannot be steal NFT', async (context: MyContext) => {
114
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
115
- const params: PriceOracleParams = {
116
- owner: pkh,
117
- biasTime: 20_000n,
118
- expirationPeriod: 1_800_000n,
119
- };
120
- const [startTx, _] = await startPriceOracleTx(
121
- context.lucid,
122
- 'ORACLE_NFT',
123
- rationalFromInt(1n),
124
- params,
125
- );
126
-
127
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
128
-
129
- await expectScriptFailure(
130
- 'Wrong continuing output',
131
- feedPriceOracleTxStealNft(
132
- context.lucid,
133
- { txHash: startTxHash, outputIndex: 0 },
134
- rationalFromInt(2n),
135
- params,
136
- ),
137
- );
138
- });
139
-
140
- test<MyContext>('Feed Rational Price Oracle cannot have zero denominator', async (context: MyContext) => {
141
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
142
- const params: PriceOracleParams = {
143
- owner: pkh,
144
- biasTime: 20_000n,
145
- expirationPeriod: 1_800_000n,
146
- };
147
- const [startTx, _] = await startPriceOracleTx(
148
- context.lucid,
149
- 'ORACLE_NFT',
150
- rationalFromInt(1n),
151
- params,
152
- );
153
-
154
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
155
-
156
- await expectScriptFailure(
157
- 'Denominator cannot be zero',
158
- feedPriceOracleTx(
159
- context.lucid,
160
- { txHash: startTxHash, outputIndex: 0 },
161
- { numerator: 2n, denominator: 0n },
162
- params,
163
- ),
164
- );
165
- });
166
-
167
- test<MyContext>('Feed Rational Price Oracle with large number', async (context: MyContext) => {
168
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
169
- const params: PriceOracleParams = {
170
- owner: pkh,
171
- biasTime: 20_000n,
172
- expirationPeriod: 1_800_000n,
173
- };
174
- const [startTx, _] = await startPriceOracleTx(
175
- context.lucid,
176
- 'ORACLE_NFT',
177
- rationalFromInt(1n),
178
- params,
179
- );
180
-
181
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
182
-
183
- await runAndAwaitTx(
184
- context.lucid,
185
- feedPriceOracleTx(
186
- context.lucid,
187
- { txHash: startTxHash, outputIndex: 0 },
188
- {
189
- numerator:
190
- BigInt(Number.MAX_SAFE_INTEGER) * BigInt(Number.MAX_SAFE_INTEGER),
191
- denominator: BigInt(Number.MAX_SAFE_INTEGER),
192
- },
193
- params,
194
- ),
195
- );
196
- });
197
-
198
- test<MyContext>('Feed Rational Price Oracle can change auxiliary data', async (context: MyContext) => {
199
- const pkh = paymentCredentialOf(context.users.admin.address).hash;
200
- const params: PriceOracleParams = {
201
- owner: pkh,
202
- biasTime: 20_000n,
203
- expirationPeriod: 1_800_000n,
204
- };
205
- const [startTx, _] = await startPriceOracleTx(
206
- context.lucid,
207
- 'ORACLE_NFT',
208
- rationalFromInt(1n),
209
- params,
210
- );
211
-
212
- const startTxHash = await runAndAwaitTxBuilder(context.lucid, startTx);
213
-
214
- await runAndAwaitTx(
215
- context.lucid,
216
- feedPriceOracleTx(
217
- context.lucid,
218
- { txHash: startTxHash, outputIndex: 0 },
219
- rationalFromInt(1n),
220
- params,
221
-
222
- Core.Data.fromCBORHex(
223
- 'd8799f1b0180e51d1ae19514d8799f1a00030d40ff1b00000194ce33c598ff',
224
- ),
225
- ),
226
- );
227
- });
228
- });
@@ -1,59 +0,0 @@
1
- import {
2
- Data,
3
- LucidEvolution,
4
- OutRef,
5
- TxBuilder,
6
- } from '@lucid-evolution/lucid';
7
- import {
8
- serialisePriceOracleDatum,
9
- serialisePriceOracleRedeemer,
10
- } from '../../src/contracts/price-oracle/types-new';
11
- import { PriceOracleParams } from '../../src/contracts/price-oracle/types';
12
- import { mkPriceOracleValidator } from '../../src/contracts/price-oracle/scripts';
13
- import { matchSingle } from '../../src/utils/utils';
14
- import { ONE_SECOND } from '../../src/utils/time-helpers';
15
- import * as Core from '@evolution-sdk/evolution';
16
- import { mkLovelacesOf } from '@3rd-eye-labs/cardano-offchain-common';
17
- import { Rational } from '../../src/types/rational';
18
-
19
- export async function feedPriceOracleTxStealNft(
20
- lucid: LucidEvolution,
21
- oracleOref: OutRef,
22
- newPrice: Rational,
23
- oracleParams: PriceOracleParams,
24
- ): Promise<TxBuilder> {
25
- const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
26
-
27
- const priceOracleUtxo = matchSingle(
28
- await lucid.utxosByOutRef([oracleOref]),
29
- (_) => new Error('Expected a single price oracle UTXO'),
30
- );
31
-
32
- const oracleValidator = mkPriceOracleValidator(oracleParams);
33
-
34
- return lucid
35
- .newTx()
36
- .validFrom(Number(currentTime - oracleParams.biasTime) + ONE_SECOND)
37
- .validTo(Number(currentTime + oracleParams.biasTime) - ONE_SECOND)
38
- .attach.SpendingValidator(oracleValidator)
39
- .collectFrom(
40
- [priceOracleUtxo],
41
- serialisePriceOracleRedeemer({
42
- currentTime: currentTime,
43
- newPrice: newPrice,
44
- }),
45
- )
46
- .pay.ToContract(
47
- priceOracleUtxo.address,
48
- {
49
- kind: 'inline',
50
- value: serialisePriceOracleDatum({
51
- price: newPrice,
52
- expirationTime: currentTime + oracleParams.expirationPeriod,
53
- auxiliaryData: Core.Data.fromCBORHex(Data.void()),
54
- }),
55
- },
56
- mkLovelacesOf(5_000_000n),
57
- )
58
- .addSignerKey(oracleParams.owner);
59
- }
@@ -1,96 +0,0 @@
1
- import {
2
- credentialToAddress,
3
- credentialToRewardAddress,
4
- fromHex,
5
- fromText,
6
- LucidEvolution,
7
- validatorToScriptHash,
8
- } from '@lucid-evolution/lucid';
9
- import {
10
- PythStateDatum,
11
- serialisePythStateDatum,
12
- } from '../../src/contracts/pyth-feed/types';
13
- import { alwaysSucceedValidator } from '../always-succeed/script';
14
- import { runAndAwaitTxBuilder } from '../test-helpers';
15
- import { AssetClass, mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
16
- import { mintOneTimeToken } from '../../src';
17
-
18
- export const TEST_TRUSTED_SIGNER_PRIV_KEY =
19
- 'a8e6c4d187e6247719cf45112917094c6973d2cf5a5f2e9f3a6802543e523239';
20
- export const TEST_TRUSTED_SIGNER_PUB_KEY =
21
- '4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f';
22
-
23
- // For the purpose of testing Pyth in an emulated environment, we need to initialize a Pyth State NFT
24
- // This NFT will be sent to an always succeeds validator that will have the "Pyth State" datum
25
- // The important part is that the Pyth State includes an always succeeds withdraw script and a
26
- // trusted signer that we can use to validate the Pyth Messages we generate.
27
- export async function initPyth(lucid: LucidEvolution): Promise<AssetClass> {
28
- const pythStateName = fromText('Pyth State');
29
- const pythStatePolicyId = await mintOneTimeToken(lucid, pythStateName, 1n);
30
- const pythStateAsset = {
31
- currencySymbol: fromHex(pythStatePolicyId),
32
- tokenName: fromHex(pythStateName),
33
- };
34
-
35
- const alwaysSucceedsValidatorHash = validatorToScriptHash(
36
- alwaysSucceedValidator,
37
- );
38
- const pythStateDatum: PythStateDatum = {
39
- // The governance doesn't matter for the purpose of testing, so we can use any values
40
- governance: {
41
- wormhole: fromHex(''),
42
- emitterChain: 0n,
43
- emitterAddress: fromHex(''),
44
- seenSequence: 0n,
45
- },
46
- trustedSigners: new Map([
47
- [
48
- fromHex(TEST_TRUSTED_SIGNER_PUB_KEY),
49
- {
50
- lower_bound: {
51
- bound_type: {
52
- _tag: 'NegativeInfinity',
53
- },
54
- is_inclusive: true,
55
- },
56
- upper_bound: {
57
- bound_type: {
58
- _tag: 'PositiveInfinity',
59
- },
60
- is_inclusive: true,
61
- },
62
- },
63
- ],
64
- ]),
65
- deprecatedWithdrawScripts: new Map(),
66
- // For the purpose of testing, we use the always succeeds validator to validate the Pyth Messages.
67
- // This means the message signature checking will always succeed for the purpose of emulation testing.
68
- withdraw_script: fromHex(alwaysSucceedsValidatorHash),
69
- };
70
-
71
- await runAndAwaitTxBuilder(
72
- lucid,
73
- lucid.newTx().pay.ToContract(
74
- credentialToAddress(lucid.config().network!, {
75
- hash: validatorToScriptHash(alwaysSucceedValidator),
76
- type: 'Script',
77
- }),
78
- { kind: 'inline', value: serialisePythStateDatum(pythStateDatum) },
79
- mkAssetsOf(pythStateAsset, 1n),
80
- alwaysSucceedValidator,
81
- ),
82
- );
83
-
84
- // Register the stake key for always succeeds validator.
85
- await runAndAwaitTxBuilder(
86
- lucid,
87
- lucid.newTx().register.Stake(
88
- credentialToRewardAddress(lucid.config().network!, {
89
- hash: validatorToScriptHash(alwaysSucceedValidator),
90
- type: 'Script',
91
- }),
92
- ),
93
- );
94
-
95
- return pythStateAsset;
96
- }
@@ -1,37 +0,0 @@
1
- import { fromHex } from '@lucid-evolution/lucid';
2
- import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
3
- import {
4
- encodePriceUpdate,
5
- encodePythMessage,
6
- type PythMessageParts,
7
- } from '../../src/utils/pyth';
8
- import {
9
- TEST_TRUSTED_SIGNER_PRIV_KEY,
10
- TEST_TRUSTED_SIGNER_PUB_KEY,
11
- } from './endpoints';
12
-
13
- /**
14
- * Creates a signed Pyth message from a list of price feeds.
15
- * Uses the test trusted signer keys for signing.
16
- */
17
- export async function createPythMessage(
18
- feeds: ParsedFeedPayload[],
19
- timestampUs: bigint,
20
- channelId = 0,
21
- ): Promise<Uint8Array> {
22
- const noble = await import('@noble/ed25519');
23
- const payload = encodePriceUpdate({
24
- timestampUs: timestampUs.toString(),
25
- channelId,
26
- priceFeeds: feeds,
27
- });
28
- const parts: PythMessageParts = {
29
- signature: await noble.signAsync(
30
- payload,
31
- fromHex(TEST_TRUSTED_SIGNER_PRIV_KEY),
32
- ),
33
- publicKey: fromHex(TEST_TRUSTED_SIGNER_PUB_KEY),
34
- payload,
35
- };
36
- return encodePythMessage(parts);
37
- }