@indigo-labs/indigo-sdk 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.github/workflows/ci.yml +62 -0
  2. package/.github/workflows/test.yml +44 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.nvmrc +1 -0
  5. package/.prettierrc +6 -0
  6. package/dist/index.d.mts +32 -2
  7. package/dist/index.d.ts +32 -2
  8. package/dist/index.js +81 -6
  9. package/dist/index.mjs +78 -6
  10. package/eslint.config.mjs +36 -0
  11. package/package.json +2 -5
  12. package/src/contracts/cdp.ts +741 -0
  13. package/src/contracts/collector.ts +98 -0
  14. package/src/contracts/gov.ts +1 -0
  15. package/src/contracts/interest-oracle.ts +149 -0
  16. package/src/contracts/lrp.ts +315 -0
  17. package/src/contracts/one-shot.ts +67 -0
  18. package/src/contracts/stability-pool.ts +684 -0
  19. package/src/contracts/staking.ts +348 -0
  20. package/src/contracts/treasury.ts +112 -0
  21. package/src/helpers/asset-helpers.ts +57 -0
  22. package/src/helpers/helper-txs.ts +30 -0
  23. package/src/helpers/helpers.ts +38 -0
  24. package/src/helpers/indigo-helpers.ts +19 -0
  25. package/src/helpers/interest-oracle.ts +57 -0
  26. package/src/helpers/lucid-utils.ts +70 -0
  27. package/src/helpers/price-oracle-helpers.ts +36 -0
  28. package/src/helpers/stability-pool-helpers.ts +207 -0
  29. package/src/helpers/staking-helpers.ts +94 -0
  30. package/src/helpers/time-helpers.ts +4 -0
  31. package/src/helpers/value-helpers.ts +27 -0
  32. package/src/index.ts +34 -0
  33. package/src/scripts/always-fail-validator.ts +7 -0
  34. package/src/scripts/auth-token-policy.ts +23 -0
  35. package/src/scripts/cdp-creator-validator.ts +53 -0
  36. package/src/scripts/cdp-validator.ts +9 -0
  37. package/src/scripts/collector-validator.ts +8 -0
  38. package/src/scripts/execute-validator.ts +52 -0
  39. package/src/scripts/gov-validator.ts +44 -0
  40. package/src/scripts/iasset-policy.ts +22 -0
  41. package/src/scripts/interest-oracle-validator.ts +23 -0
  42. package/src/scripts/lrp-validator.ts +40 -0
  43. package/src/scripts/one-shot-policy.ts +62 -0
  44. package/src/scripts/poll-manager-validator.ts +52 -0
  45. package/src/scripts/poll-shard-validator.ts +47 -0
  46. package/src/scripts/price-oracle-validator.ts +26 -0
  47. package/src/scripts/stability-pool-validator.ts +60 -0
  48. package/src/scripts/staking-validator.ts +8 -0
  49. package/src/scripts/treasury-validator.ts +8 -0
  50. package/src/scripts/version-record-policy.ts +26 -0
  51. package/src/scripts/version-registry.ts +15 -0
  52. package/src/types/generic.ts +106 -0
  53. package/src/types/indigo/cdp-creator.ts +46 -0
  54. package/src/types/indigo/cdp.ts +88 -0
  55. package/src/types/indigo/execute.ts +21 -0
  56. package/src/types/indigo/gov.ts +51 -0
  57. package/src/types/indigo/interest-oracle.ts +55 -0
  58. package/src/types/indigo/lrp.ts +59 -0
  59. package/src/types/indigo/poll-manager.ts +21 -0
  60. package/src/types/indigo/poll-shard.ts +16 -0
  61. package/src/types/indigo/price-oracle.ts +38 -0
  62. package/src/types/indigo/stability-pool.ts +233 -0
  63. package/src/types/indigo/staking.ts +99 -0
  64. package/src/types/indigo/version-record.ts +17 -0
  65. package/src/types/on-chain-decimal.ts +23 -0
  66. package/src/types/one-shot.ts +22 -0
  67. package/src/types/system-params.ts +256 -0
  68. package/tests/data/system-params.json +1012 -0
  69. package/tests/datums.test.ts +286 -0
  70. package/tests/endpoints/initialize.ts +1013 -0
  71. package/tests/hash-checks.test.ts +80 -0
  72. package/tests/indigo-test-helpers.ts +115 -0
  73. package/tests/initialize.test.ts +27 -0
  74. package/tests/interest-calculations.test.ts +120 -0
  75. package/tests/interest-oracle.test.ts +90 -0
  76. package/tests/lrp.test.ts +777 -0
  77. package/tests/queries/governance-queries.ts +31 -0
  78. package/tests/queries/iasset-queries.ts +39 -0
  79. package/tests/queries/interest-oracle-queries.ts +13 -0
  80. package/tests/queries/lrp-queries.ts +39 -0
  81. package/tests/queries/price-oracle-queries.ts +27 -0
  82. package/tests/queries/stability-pool-queries.ts +75 -0
  83. package/tests/queries/staking-queries.ts +43 -0
  84. package/tests/stability-pool.test.ts +364 -0
  85. package/tests/staking.test.ts +105 -0
  86. package/tests/test-helpers.ts +38 -0
  87. package/tsconfig.build.json +4 -0
  88. package/tsconfig.json +17 -0
  89. package/vitest.config.ts +9 -0
@@ -0,0 +1,62 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint-and-build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version-file: '.nvmrc'
21
+
22
+ - name: Setup pnpm
23
+ uses: pnpm/action-setup@v4
24
+ with:
25
+ version: latest
26
+
27
+ - name: Get pnpm store directory
28
+ shell: bash
29
+ run: |
30
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
31
+
32
+ - name: Setup pnpm cache
33
+ uses: actions/cache@v4
34
+ with:
35
+ path: ${{ env.STORE_PATH }}
36
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37
+ restore-keys: |
38
+ ${{ runner.os }}-pnpm-store-
39
+
40
+ - name: Install dependencies
41
+ run: pnpm install --frozen-lockfile
42
+
43
+ - name: Check formatting
44
+ run: pnpm run format:check
45
+
46
+ - name: Check linting
47
+ run: pnpm run lint
48
+
49
+ - name: Build project
50
+ run: pnpm run build
51
+
52
+ - name: Verify build output
53
+ run: |
54
+ if [ ! -d "dist" ]; then
55
+ echo "Build failed: dist directory not found"
56
+ exit 1
57
+ fi
58
+ if [ ! -f "dist/index.js" ] || [ ! -f "dist/index.mjs" ] || [ ! -f "dist/index.d.ts" ]; then
59
+ echo "Build failed: expected output files not found"
60
+ exit 1
61
+ fi
62
+ echo "Build verification passed"
@@ -0,0 +1,44 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - name: Checkout code
15
+ uses: actions/checkout@v4
16
+
17
+ - name: Setup Node.js
18
+ uses: actions/setup-node@v4
19
+ with:
20
+ node-version-file: '.nvmrc'
21
+
22
+ - name: Setup pnpm
23
+ uses: pnpm/action-setup@v4
24
+ with:
25
+ version: latest
26
+
27
+ - name: Get pnpm store directory
28
+ shell: bash
29
+ run: |
30
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
31
+
32
+ - name: Setup pnpm cache
33
+ uses: actions/cache@v4
34
+ with:
35
+ path: ${{ env.STORE_PATH }}
36
+ key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37
+ restore-keys: |
38
+ ${{ runner.os }}-pnpm-store-
39
+
40
+ - name: Install dependencies
41
+ run: pnpm install --frozen-lockfile
42
+
43
+ - name: Run tests
44
+ run: pnpm run test
@@ -0,0 +1 @@
1
+ pnpm exec lint-staged
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v18.19.1
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "tabWidth": 2,
5
+ "semi": true
6
+ }
package/dist/index.d.mts CHANGED
@@ -67,6 +67,7 @@ interface SystemParams {
67
67
  scriptReferences: ScriptReferences;
68
68
  pollShardParams: PollShardParamsSP;
69
69
  pollManagerParams: PollManagerParamsSP;
70
+ lrpParams: LrpParamsSP;
70
71
  indyToken: AssetClassSP;
71
72
  govParams: GovParamsSP;
72
73
  executeParams: ExecuteParamsSP;
@@ -82,6 +83,7 @@ type ValidatorHashes = {
82
83
  stabilityPoolHash: string;
83
84
  pollShardHash: string;
84
85
  pollManagerHash: string;
86
+ lrpHash: string;
85
87
  govHash: string;
86
88
  executeHash: string;
87
89
  collectorHash: string;
@@ -145,6 +147,7 @@ interface ScriptReferences {
145
147
  stabilityPoolValidatorRef: ScriptReference;
146
148
  pollShardValidatorRef: ScriptReference;
147
149
  pollManagerValidatorRef: ScriptReference;
150
+ lrpValidatorRef: ScriptReference;
148
151
  liquidityValidatorRef: ScriptReference;
149
152
  iAssetTokenPolicyRef: ScriptReference;
150
153
  governanceValidatorRef: ScriptReference;
@@ -197,6 +200,12 @@ interface AuthTokenPolicies {
197
200
  cdpAuthTokenRef: ScriptReference;
198
201
  accountTokenRef: ScriptReference;
199
202
  }
203
+ interface LrpParamsSP {
204
+ versionRecordToken: AssetClassSP;
205
+ iassetNft: AssetClassSP;
206
+ iassetPolicyId: CurrencySymbol;
207
+ minRedemptionLovelacesAmt: bigint;
208
+ }
200
209
  interface PollShardParamsSP {
201
210
  stakingValHash: string;
202
211
  stakingToken: AssetClassSP;
@@ -1235,6 +1244,11 @@ declare const LRPDatumSchema: _lucid_evolution_lucid.TObject<{
1235
1244
  maxPrice: _lucid_evolution_lucid.TObject<{
1236
1245
  getOnChainInt: _lucid_evolution_lucid.TUnsafe<bigint>;
1237
1246
  }>;
1247
+ /**
1248
+ * The amount of lovelaces that is available to be spent.
1249
+ * This doesn't correspond to the lovelaces in UTXO's value,
1250
+ * since that can contain fees, too.
1251
+ */
1238
1252
  lovelacesToSpend: _lucid_evolution_lucid.TUnsafe<bigint>;
1239
1253
  }>;
1240
1254
  type LRPDatum = Data.Static<typeof LRPDatumSchema>;
@@ -1273,9 +1287,25 @@ type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
1273
1287
 
1274
1288
  declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, lrpScriptHash: ScriptHash, network: Network, lrpStakeCredential?: Credential$1): Promise<TxBuilder>;
1275
1289
  declare function cancelLrp(lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lucid: LucidEvolution): Promise<TxBuilder>;
1276
- declare function redeemLrp(redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, priceOracleParams: PriceOracleParams, network: Network): Promise<TxBuilder>;
1290
+ declare function redeemLrp(
1291
+ /** The tuple represents the LRP outref and the amount of iAssets to redeem against it. */
1292
+ redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, priceOracleParams: PriceOracleParams, network: Network, currentSlot: number): Promise<TxBuilder>;
1293
+ /**
1294
+ * Create Tx adjusting the LRP and claiming the received iAssets
1295
+ */
1296
+ declare function adjustLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
1297
+ /**
1298
+ * A positive amount increases the lovelaces in the LRP,
1299
+ * and a negative amount takes lovelaces from the LRP.
1300
+ */
1301
+ lovelacesAdjustAmt: bigint, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
1302
+ /**
1303
+ * Create Tx claiming the received iAssets.
1304
+ */
1305
+ declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
1277
1306
 
1278
1307
  declare const mkLrpValidator: (params: LRPParams) => SpendingValidator;
1308
+ declare const mkLrpValidatorFromSP: (params: LrpParamsSP) => SpendingValidator;
1279
1309
 
1280
1310
  /**
1281
1311
  * Uses an always fail validator for the destination address.
@@ -1297,4 +1327,4 @@ type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
1297
1327
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
1298
1328
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
1299
1329
 
1300
- export { AccountAction, AccountActionSchema, AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, Address, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPContract, type CDPCreatorParamsSP, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CdpParams, CollectorContract, type CollectorParams, Credential, CredentialSchema, type CurrencySymbol, type DistributionParams, EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, GovContract, type GovDatum, GovParams, type GovParamsSP, type IAssetContent, IAssetContentSchema, IAssetHelpers, type IAssetOutput, type Input, InterestOracleContract, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, ONE_SECOND, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollShardParams, type PollShardParamsSP, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PubKeyHash, SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolContract, StabilityPoolDatum, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, StabilityPoolRedeemer, StabilityPoolRedeemerSchema, StabilityPoolSnapshot, StakingContract, type StakingParams, type StartTime, type SystemParams, type TokenName, TreasuryContract, type TreasuryParams, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, _cdpValidator, _collectorValidator, _treasuryValidator, addrDetails, addressFromBech32, addressToBech32, balance, calculateFeeFromPercentage, cancelLrp, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, cdpCreatorValidator, createScriptAddress, fromSPInteger, fromSystemParamsAsset, getInlineDatumOrThrow, getRandomElement, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkInterestOracleValidator, mkLrpValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, oneDay, oneHour, oneShotMintTx, oneYear, openLrp, parseAccountDatum, parseCDPDatum, parseGovDatum, parseIAssetDatum, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePriceOracleDatum, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, spAdd, spDiv, spMul, spSub, toSystemParamsAsset };
1330
+ export { AccountAction, AccountActionSchema, AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, Address, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPContract, type CDPCreatorParamsSP, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CdpParams, CollectorContract, type CollectorParams, Credential, CredentialSchema, type CurrencySymbol, type DistributionParams, EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, GovContract, type GovDatum, GovParams, type GovParamsSP, type IAssetContent, IAssetContentSchema, IAssetHelpers, type IAssetOutput, type Input, InterestOracleContract, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpParamsSP, ONE_SECOND, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollShardParams, type PollShardParamsSP, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PubKeyHash, SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolContract, StabilityPoolDatum, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, StabilityPoolRedeemer, StabilityPoolRedeemerSchema, StabilityPoolSnapshot, StakingContract, type StakingParams, type StartTime, type SystemParams, type TokenName, TreasuryContract, type TreasuryParams, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, _cdpValidator, _collectorValidator, _treasuryValidator, addrDetails, addressFromBech32, addressToBech32, adjustLrp, balance, calculateFeeFromPercentage, cancelLrp, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, cdpCreatorValidator, claimLrp, createScriptAddress, fromSPInteger, fromSystemParamsAsset, getInlineDatumOrThrow, getRandomElement, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkInterestOracleValidator, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, oneDay, oneHour, oneShotMintTx, oneYear, openLrp, parseAccountDatum, parseCDPDatum, parseGovDatum, parseIAssetDatum, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePriceOracleDatum, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, spAdd, spDiv, spMul, spSub, toSystemParamsAsset };
package/dist/index.d.ts CHANGED
@@ -67,6 +67,7 @@ interface SystemParams {
67
67
  scriptReferences: ScriptReferences;
68
68
  pollShardParams: PollShardParamsSP;
69
69
  pollManagerParams: PollManagerParamsSP;
70
+ lrpParams: LrpParamsSP;
70
71
  indyToken: AssetClassSP;
71
72
  govParams: GovParamsSP;
72
73
  executeParams: ExecuteParamsSP;
@@ -82,6 +83,7 @@ type ValidatorHashes = {
82
83
  stabilityPoolHash: string;
83
84
  pollShardHash: string;
84
85
  pollManagerHash: string;
86
+ lrpHash: string;
85
87
  govHash: string;
86
88
  executeHash: string;
87
89
  collectorHash: string;
@@ -145,6 +147,7 @@ interface ScriptReferences {
145
147
  stabilityPoolValidatorRef: ScriptReference;
146
148
  pollShardValidatorRef: ScriptReference;
147
149
  pollManagerValidatorRef: ScriptReference;
150
+ lrpValidatorRef: ScriptReference;
148
151
  liquidityValidatorRef: ScriptReference;
149
152
  iAssetTokenPolicyRef: ScriptReference;
150
153
  governanceValidatorRef: ScriptReference;
@@ -197,6 +200,12 @@ interface AuthTokenPolicies {
197
200
  cdpAuthTokenRef: ScriptReference;
198
201
  accountTokenRef: ScriptReference;
199
202
  }
203
+ interface LrpParamsSP {
204
+ versionRecordToken: AssetClassSP;
205
+ iassetNft: AssetClassSP;
206
+ iassetPolicyId: CurrencySymbol;
207
+ minRedemptionLovelacesAmt: bigint;
208
+ }
200
209
  interface PollShardParamsSP {
201
210
  stakingValHash: string;
202
211
  stakingToken: AssetClassSP;
@@ -1235,6 +1244,11 @@ declare const LRPDatumSchema: _lucid_evolution_lucid.TObject<{
1235
1244
  maxPrice: _lucid_evolution_lucid.TObject<{
1236
1245
  getOnChainInt: _lucid_evolution_lucid.TUnsafe<bigint>;
1237
1246
  }>;
1247
+ /**
1248
+ * The amount of lovelaces that is available to be spent.
1249
+ * This doesn't correspond to the lovelaces in UTXO's value,
1250
+ * since that can contain fees, too.
1251
+ */
1238
1252
  lovelacesToSpend: _lucid_evolution_lucid.TUnsafe<bigint>;
1239
1253
  }>;
1240
1254
  type LRPDatum = Data.Static<typeof LRPDatumSchema>;
@@ -1273,9 +1287,25 @@ type OnChainDecimal = Data.Static<typeof OnChainDecimalSchema>;
1273
1287
 
1274
1288
  declare function openLrp(assetTokenName: string, lovelacesAmt: bigint, maxPrice: OnChainDecimal, lucid: LucidEvolution, lrpScriptHash: ScriptHash, network: Network, lrpStakeCredential?: Credential$1): Promise<TxBuilder>;
1275
1289
  declare function cancelLrp(lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lucid: LucidEvolution): Promise<TxBuilder>;
1276
- declare function redeemLrp(redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, priceOracleParams: PriceOracleParams, network: Network): Promise<TxBuilder>;
1290
+ declare function redeemLrp(
1291
+ /** The tuple represents the LRP outref and the amount of iAssets to redeem against it. */
1292
+ redemptionLrpsData: [OutRef, bigint][], lrpRefScriptOutRef: OutRef, priceOracleOutRef: OutRef, iassetOutRef: OutRef, lucid: LucidEvolution, lrpParams: LRPParams, priceOracleParams: PriceOracleParams, network: Network, currentSlot: number): Promise<TxBuilder>;
1293
+ /**
1294
+ * Create Tx adjusting the LRP and claiming the received iAssets
1295
+ */
1296
+ declare function adjustLrp(lucid: LucidEvolution, lrpOutRef: OutRef,
1297
+ /**
1298
+ * A positive amount increases the lovelaces in the LRP,
1299
+ * and a negative amount takes lovelaces from the LRP.
1300
+ */
1301
+ lovelacesAdjustAmt: bigint, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
1302
+ /**
1303
+ * Create Tx claiming the received iAssets.
1304
+ */
1305
+ declare function claimLrp(lucid: LucidEvolution, lrpOutRef: OutRef, lrpRefScriptOutRef: OutRef, lrpParams: LRPParams): Promise<TxBuilder>;
1277
1306
 
1278
1307
  declare const mkLrpValidator: (params: LRPParams) => SpendingValidator;
1308
+ declare const mkLrpValidatorFromSP: (params: LrpParamsSP) => SpendingValidator;
1279
1309
 
1280
1310
  /**
1281
1311
  * Uses an always fail validator for the destination address.
@@ -1297,4 +1327,4 @@ type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
1297
1327
  declare function oneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<[TxBuilder, PolicyId]>;
1298
1328
  declare function runOneShotMintTx(lucid: LucidEvolution, params: OneShotParams): Promise<PolicyId>;
1299
1329
 
1300
- export { AccountAction, AccountActionSchema, AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, Address, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPContract, type CDPCreatorParamsSP, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CdpParams, CollectorContract, type CollectorParams, Credential, CredentialSchema, type CurrencySymbol, type DistributionParams, EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, GovContract, type GovDatum, GovParams, type GovParamsSP, type IAssetContent, IAssetContentSchema, IAssetHelpers, type IAssetOutput, type Input, InterestOracleContract, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, ONE_SECOND, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollShardParams, type PollShardParamsSP, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PubKeyHash, SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolContract, StabilityPoolDatum, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, StabilityPoolRedeemer, StabilityPoolRedeemerSchema, StabilityPoolSnapshot, StakingContract, type StakingParams, type StartTime, type SystemParams, type TokenName, TreasuryContract, type TreasuryParams, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, _cdpValidator, _collectorValidator, _treasuryValidator, addrDetails, addressFromBech32, addressToBech32, balance, calculateFeeFromPercentage, cancelLrp, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, cdpCreatorValidator, createScriptAddress, fromSPInteger, fromSystemParamsAsset, getInlineDatumOrThrow, getRandomElement, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkInterestOracleValidator, mkLrpValidator, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, oneDay, oneHour, oneShotMintTx, oneYear, openLrp, parseAccountDatum, parseCDPDatum, parseGovDatum, parseIAssetDatum, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePriceOracleDatum, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, spAdd, spDiv, spMul, spSub, toSystemParamsAsset };
1330
+ export { AccountAction, AccountActionSchema, AccountContent, AccountContentSchema, ActionReturnDatum, ActionReturnDatumSchema, Address, type AddressCredential, type AddressCredentialOrDatum, type AddressSP, AddressSchema, type Amount, type AssetClass, type AssetClassSP, AssetClassSchema, type AuthTokenPolicies, type CDPContent, CDPContentSchema, CDPContract, type CDPCreatorParamsSP, type CDPDatum, CDPDatumSchema, type CDPFees, CDPFeesSchema, type CdpParams, CollectorContract, type CollectorParams, Credential, CredentialSchema, type CurrencySymbol, type DistributionParams, EpochToScaleToSum, EpochToScaleToSumSchema, ExecuteParams, type ExecuteParamsSP, type FeedInterestOracleRedeemer, FeedInterestOracleRedeemerSchema, GovContract, type GovDatum, GovParams, type GovParamsSP, type IAssetContent, IAssetContentSchema, IAssetHelpers, type IAssetOutput, type Input, InterestOracleContract, type InterestOracleDatum, InterestOracleDatumSchema, type InterestOracleParams, InterestOracleParamsSchema, type LRPDatum, LRPDatumSchema, type LRPParams, LRPParamsSchema, type LRPRedeemer, LRPRedeemerSchema, type LrpParamsSP, ONE_SECOND, type OracleAssetNft, OracleAssetNftSchema, type Output, type OutputReference, OutputReferenceSchema, PollManagerParams, type PollManagerParamsSP, PollShardParams, type PollShardParamsSP, type PriceOracleDatum, PriceOracleDatumSchema, type PriceOracleParams, PriceOracleParamsSchema, type PubKeyHash, SPInteger, SPIntegerSchema, type ScriptCredential, type ScriptOutput, type ScriptRef, type ScriptReference, type ScriptReferences, SnapshotEpochToScaleToSumContent, SnapshotEpochToScaleToSumContentSchema, StabilityPoolContent, StabilityPoolContentSchema, StabilityPoolContract, StabilityPoolDatum, StabilityPoolDatumSchema, StabilityPoolParams, type StabilityPoolParamsSP, StabilityPoolRedeemer, StabilityPoolRedeemerSchema, StabilityPoolSnapshot, StakingContract, type StakingParams, type StartTime, type SystemParams, type TokenName, TreasuryContract, type TreasuryParams, type ValidatorHashes, VerificationKeyHashSchema, type VersionRecordParams, _cdpValidator, _collectorValidator, _treasuryValidator, addrDetails, addressFromBech32, addressToBech32, adjustLrp, balance, calculateFeeFromPercentage, cancelLrp, castExecuteParams, castGovParams, castInterestOracleParams, castLrpParams, castPollManagerParams, castPollShardParams, castPriceOracleParams, castStabilityPoolParams, cdpCreatorValidator, claimLrp, createScriptAddress, fromSPInteger, fromSystemParamsAsset, getInlineDatumOrThrow, getRandomElement, loadSystemParamsFromFile, loadSystemParamsFromUrl, matchSingle, mkCDPCreatorValidator, mkCDPCreatorValidatorFromSP, mkInterestOracleValidator, mkLrpValidator, mkLrpValidatorFromSP, mkPollManagerValidator, mkPollManagerValidatorFromSP, mkPollShardValidator, mkPollShardValidatorFromSP, mkSPInteger, oneDay, oneHour, oneShotMintTx, oneYear, openLrp, parseAccountDatum, parseCDPDatum, parseGovDatum, parseIAssetDatum, parseInterestOracleDatum, parseLrpDatum, parsePriceOracleDatum, parseSnapshotEpochToScaleToSumDatum, parseStabilityPoolDatum, redeemLrp, runCreateScriptRefTx, runOneShotMintTx, scriptRef, serialiseCDPDatum, serialiseFeedInterestOracleRedeemer, serialiseGovDatum, serialiseIAssetDatum, serialiseInterestOracleDatum, serialiseLrpDatum, serialiseLrpRedeemer, serialisePriceOracleDatum, serialiseStabilityPoolDatum, serialiseStabilityPoolRedeemer, spAdd, spDiv, spMul, spSub, toSystemParamsAsset };
package/dist/index.js CHANGED
@@ -88,6 +88,7 @@ __export(index_exports, {
88
88
  addrDetails: () => addrDetails,
89
89
  addressFromBech32: () => addressFromBech32,
90
90
  addressToBech32: () => addressToBech32,
91
+ adjustLrp: () => adjustLrp,
91
92
  balance: () => balance,
92
93
  calculateFeeFromPercentage: () => calculateFeeFromPercentage,
93
94
  cancelLrp: () => cancelLrp,
@@ -100,6 +101,7 @@ __export(index_exports, {
100
101
  castPriceOracleParams: () => castPriceOracleParams,
101
102
  castStabilityPoolParams: () => castStabilityPoolParams,
102
103
  cdpCreatorValidator: () => cdpCreatorValidator,
104
+ claimLrp: () => claimLrp,
103
105
  createScriptAddress: () => createScriptAddress,
104
106
  fromSPInteger: () => fromSPInteger,
105
107
  fromSystemParamsAsset: () => fromSystemParamsAsset,
@@ -112,6 +114,7 @@ __export(index_exports, {
112
114
  mkCDPCreatorValidatorFromSP: () => mkCDPCreatorValidatorFromSP,
113
115
  mkInterestOracleValidator: () => mkInterestOracleValidator,
114
116
  mkLrpValidator: () => mkLrpValidator,
117
+ mkLrpValidatorFromSP: () => mkLrpValidatorFromSP,
115
118
  mkPollManagerValidator: () => mkPollManagerValidator,
116
119
  mkPollManagerValidatorFromSP: () => mkPollManagerValidatorFromSP,
117
120
  mkPollShardValidator: () => mkPollShardValidator,
@@ -2471,6 +2474,9 @@ function mkAssetsOf(assetClass, amount) {
2471
2474
  [assetClassToUnit(assetClass)]: amount
2472
2475
  };
2473
2476
  }
2477
+ function assetClassValueOf(assets, assetClass) {
2478
+ return assets[assetClassToUnit(assetClass)] ?? 0n;
2479
+ }
2474
2480
 
2475
2481
  // tests/queries/interest-oracle-queries.ts
2476
2482
  async function findInterestOracle(lucid, interestNft) {
@@ -2741,6 +2747,11 @@ var LRPDatumSchema = import_lucid32.Data.Object({
2741
2747
  owner: import_lucid32.Data.Bytes(),
2742
2748
  iasset: import_lucid32.Data.Bytes(),
2743
2749
  maxPrice: OnChainDecimalSchema,
2750
+ /**
2751
+ * The amount of lovelaces that is available to be spent.
2752
+ * This doesn't correspond to the lovelaces in UTXO's value,
2753
+ * since that can contain fees, too.
2754
+ */
2744
2755
  lovelacesToSpend: import_lucid32.Data.Integer()
2745
2756
  });
2746
2757
  var LRPDatum = LRPDatumSchema;
@@ -2825,7 +2836,7 @@ async function cancelLrp(lrpOutRef, lrpRefScriptOutRef, lucid) {
2825
2836
  );
2826
2837
  return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSigner(ownAddr);
2827
2838
  }
2828
- async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, priceOracleParams, network) {
2839
+ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, priceOracleParams, network, currentSlot) {
2829
2840
  const lrpScriptRefUtxo = matchSingle(
2830
2841
  await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2831
2842
  (_2) => new Error("Expected a single LRP Ref Script UTXO")
@@ -2844,9 +2855,12 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2844
2855
  getInlineDatumOrThrow(priceOracleUtxo)
2845
2856
  );
2846
2857
  const redemptionLrps = await lucid.utxosByOutRef(lrpsToRedeemOutRefs).then((val) => (0, import_Array2.zip)(val, lrpRedemptionIAssetAmt));
2847
- const [[mainLrpUtxo, mainLrpRedemptionIAssetAmt], _] = (0, import_ts_pattern5.match)(redemptionLrps).with(
2858
+ const [[mainLrpUtxo, _], __] = (0, import_ts_pattern5.match)(redemptionLrps).with(
2848
2859
  [import_ts_pattern5.P._, ...import_ts_pattern5.P.array()],
2849
- ([[firstLrp, firstLrpIAssetAmt], ...rest]) => [[firstLrp, firstLrpIAssetAmt], rest]
2860
+ ([[firstLrp, _2], ...rest]) => [
2861
+ [firstLrp, _2],
2862
+ rest
2863
+ ]
2850
2864
  ).otherwise(() => {
2851
2865
  throw new Error("Expects at least 1 UTXO to redeem.");
2852
2866
  });
@@ -2856,7 +2870,7 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2856
2870
  (idx, acc, [lrpUtxo, redeemIAssetAmt]) => {
2857
2871
  const lovelacesForRedemption = ocdMul(
2858
2872
  {
2859
- getOnChainInt: mainLrpRedemptionIAssetAmt
2873
+ getOnChainInt: redeemIAssetAmt
2860
2874
  },
2861
2875
  priceOracleDatum.price
2862
2876
  ).getOnChainInt;
@@ -2905,12 +2919,57 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2905
2919
  }
2906
2920
  )(redemptionLrps);
2907
2921
  const txValidity = oracleExpirationAwareValidity(
2908
- lucid.currentSlot(),
2922
+ currentSlot,
2909
2923
  Number(priceOracleParams.biasTime),
2910
2924
  Number(priceOracleDatum.expiration),
2911
2925
  network
2912
2926
  );
2913
- return lucid.newTx().validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
2927
+ return lucid.newTx().validFrom(txValidity.validFrom).validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
2928
+ }
2929
+ async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, lrpRefScriptOutRef, lrpParams) {
2930
+ const ownAddr = await lucid.wallet().address();
2931
+ const lrpScriptRefUtxo = matchSingle(
2932
+ await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2933
+ (_) => new Error("Expected a single LRP Ref Script UTXO")
2934
+ );
2935
+ const lrpUtxo = matchSingle(
2936
+ await lucid.utxosByOutRef([lrpOutRef]),
2937
+ (_) => new Error("Expected a single LRP UTXO.")
2938
+ );
2939
+ const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
2940
+ const rewardAssetClass = {
2941
+ currencySymbol: lrpParams.iassetPolicyId,
2942
+ tokenName: lrpDatum.iasset
2943
+ };
2944
+ const rewardAssetsAmt = assetClassValueOf(lrpUtxo.assets, rewardAssetClass);
2945
+ if (lovelacesAdjustAmt === 0n && lrpDatum.lovelacesToSpend === 0n) {
2946
+ throw new Error(
2947
+ "When there's no more lovelaces to spend, use close instead of claim."
2948
+ );
2949
+ }
2950
+ if (lovelacesAdjustAmt < 0 && lrpDatum.lovelacesToSpend <= lovelacesAdjustAmt) {
2951
+ throw new Error(
2952
+ "Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead."
2953
+ );
2954
+ }
2955
+ return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).pay.ToContract(
2956
+ lrpUtxo.address,
2957
+ {
2958
+ kind: "inline",
2959
+ value: serialiseLrpDatum({
2960
+ ...lrpDatum,
2961
+ lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt
2962
+ })
2963
+ },
2964
+ (0, import_lucid34.addAssets)(
2965
+ lrpUtxo.assets,
2966
+ mkAssetsOf(rewardAssetClass, -rewardAssetsAmt),
2967
+ mkLovelacesOf(lovelacesAdjustAmt)
2968
+ )
2969
+ ).addSigner(ownAddr);
2970
+ }
2971
+ async function claimLrp(lucid, lrpOutRef, lrpRefScriptOutRef, lrpParams) {
2972
+ return adjustLrp(lucid, lrpOutRef, 0n, lrpRefScriptOutRef, lrpParams);
2914
2973
  }
2915
2974
 
2916
2975
  // src/scripts/lrp-validator.ts
@@ -2928,6 +2987,19 @@ var mkLrpValidator = (params) => {
2928
2987
  ])
2929
2988
  };
2930
2989
  };
2990
+ var mkLrpValidatorFromSP = (params) => {
2991
+ return {
2992
+ type: lrpValidatorData.type,
2993
+ script: (0, import_lucid35.applyParamsToScript)(lrpValidatorData.cborHex, [
2994
+ castLrpParams({
2995
+ versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
2996
+ iassetNft: fromSystemParamsAsset(params.iassetNft),
2997
+ minRedemptionLovelacesAmt: BigInt(params.minRedemptionLovelacesAmt),
2998
+ iassetPolicyId: params.iassetPolicyId.unCurrencySymbol
2999
+ })
3000
+ ])
3001
+ };
3002
+ };
2931
3003
 
2932
3004
  // src/helpers/helper-txs.ts
2933
3005
  var import_lucid36 = require("@lucid-evolution/lucid");
@@ -3006,6 +3078,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
3006
3078
  addrDetails,
3007
3079
  addressFromBech32,
3008
3080
  addressToBech32,
3081
+ adjustLrp,
3009
3082
  balance,
3010
3083
  calculateFeeFromPercentage,
3011
3084
  cancelLrp,
@@ -3018,6 +3091,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
3018
3091
  castPriceOracleParams,
3019
3092
  castStabilityPoolParams,
3020
3093
  cdpCreatorValidator,
3094
+ claimLrp,
3021
3095
  createScriptAddress,
3022
3096
  fromSPInteger,
3023
3097
  fromSystemParamsAsset,
@@ -3030,6 +3104,7 @@ async function runCreateScriptRefTx(lucid, scriptRefValidator, network) {
3030
3104
  mkCDPCreatorValidatorFromSP,
3031
3105
  mkInterestOracleValidator,
3032
3106
  mkLrpValidator,
3107
+ mkLrpValidatorFromSP,
3033
3108
  mkPollManagerValidator,
3034
3109
  mkPollManagerValidatorFromSP,
3035
3110
  mkPollShardValidator,
package/dist/index.mjs CHANGED
@@ -2375,6 +2375,9 @@ function mkAssetsOf(assetClass, amount) {
2375
2375
  [assetClassToUnit(assetClass)]: amount
2376
2376
  };
2377
2377
  }
2378
+ function assetClassValueOf(assets, assetClass) {
2379
+ return assets[assetClassToUnit(assetClass)] ?? 0n;
2380
+ }
2378
2381
 
2379
2382
  // tests/queries/interest-oracle-queries.ts
2380
2383
  async function findInterestOracle(lucid, interestNft) {
@@ -2651,6 +2654,11 @@ var LRPDatumSchema = Data20.Object({
2651
2654
  owner: Data20.Bytes(),
2652
2655
  iasset: Data20.Bytes(),
2653
2656
  maxPrice: OnChainDecimalSchema,
2657
+ /**
2658
+ * The amount of lovelaces that is available to be spent.
2659
+ * This doesn't correspond to the lovelaces in UTXO's value,
2660
+ * since that can contain fees, too.
2661
+ */
2654
2662
  lovelacesToSpend: Data20.Integer()
2655
2663
  });
2656
2664
  var LRPDatum = LRPDatumSchema;
@@ -2740,7 +2748,7 @@ async function cancelLrp(lrpOutRef, lrpRefScriptOutRef, lucid) {
2740
2748
  );
2741
2749
  return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).addSigner(ownAddr);
2742
2750
  }
2743
- async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, priceOracleParams, network) {
2751
+ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutRef, iassetOutRef, lucid, lrpParams, priceOracleParams, network, currentSlot) {
2744
2752
  const lrpScriptRefUtxo = matchSingle(
2745
2753
  await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2746
2754
  (_2) => new Error("Expected a single LRP Ref Script UTXO")
@@ -2759,9 +2767,12 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2759
2767
  getInlineDatumOrThrow(priceOracleUtxo)
2760
2768
  );
2761
2769
  const redemptionLrps = await lucid.utxosByOutRef(lrpsToRedeemOutRefs).then((val) => zip(val, lrpRedemptionIAssetAmt));
2762
- const [[mainLrpUtxo, mainLrpRedemptionIAssetAmt], _] = match5(redemptionLrps).with(
2770
+ const [[mainLrpUtxo, _], __] = match5(redemptionLrps).with(
2763
2771
  [P5._, ...P5.array()],
2764
- ([[firstLrp, firstLrpIAssetAmt], ...rest]) => [[firstLrp, firstLrpIAssetAmt], rest]
2772
+ ([[firstLrp, _2], ...rest]) => [
2773
+ [firstLrp, _2],
2774
+ rest
2775
+ ]
2765
2776
  ).otherwise(() => {
2766
2777
  throw new Error("Expects at least 1 UTXO to redeem.");
2767
2778
  });
@@ -2771,7 +2782,7 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2771
2782
  (idx, acc, [lrpUtxo, redeemIAssetAmt]) => {
2772
2783
  const lovelacesForRedemption = ocdMul(
2773
2784
  {
2774
- getOnChainInt: mainLrpRedemptionIAssetAmt
2785
+ getOnChainInt: redeemIAssetAmt
2775
2786
  },
2776
2787
  priceOracleDatum.price
2777
2788
  ).getOnChainInt;
@@ -2820,12 +2831,57 @@ async function redeemLrp(redemptionLrpsData, lrpRefScriptOutRef, priceOracleOutR
2820
2831
  }
2821
2832
  )(redemptionLrps);
2822
2833
  const txValidity = oracleExpirationAwareValidity(
2823
- lucid.currentSlot(),
2834
+ currentSlot,
2824
2835
  Number(priceOracleParams.biasTime),
2825
2836
  Number(priceOracleDatum.expiration),
2826
2837
  network
2827
2838
  );
2828
- return lucid.newTx().validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
2839
+ return lucid.newTx().validFrom(txValidity.validFrom).validTo(txValidity.validTo).readFrom([lrpScriptRefUtxo]).readFrom([iassetUtxo, priceOracleUtxo]).compose(tx);
2840
+ }
2841
+ async function adjustLrp(lucid, lrpOutRef, lovelacesAdjustAmt, lrpRefScriptOutRef, lrpParams) {
2842
+ const ownAddr = await lucid.wallet().address();
2843
+ const lrpScriptRefUtxo = matchSingle(
2844
+ await lucid.utxosByOutRef([lrpRefScriptOutRef]),
2845
+ (_) => new Error("Expected a single LRP Ref Script UTXO")
2846
+ );
2847
+ const lrpUtxo = matchSingle(
2848
+ await lucid.utxosByOutRef([lrpOutRef]),
2849
+ (_) => new Error("Expected a single LRP UTXO.")
2850
+ );
2851
+ const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
2852
+ const rewardAssetClass = {
2853
+ currencySymbol: lrpParams.iassetPolicyId,
2854
+ tokenName: lrpDatum.iasset
2855
+ };
2856
+ const rewardAssetsAmt = assetClassValueOf(lrpUtxo.assets, rewardAssetClass);
2857
+ if (lovelacesAdjustAmt === 0n && lrpDatum.lovelacesToSpend === 0n) {
2858
+ throw new Error(
2859
+ "When there's no more lovelaces to spend, use close instead of claim."
2860
+ );
2861
+ }
2862
+ if (lovelacesAdjustAmt < 0 && lrpDatum.lovelacesToSpend <= lovelacesAdjustAmt) {
2863
+ throw new Error(
2864
+ "Can't adjust negatively by more than available. Also, for adjusting by exactly the amount deposited, a close action should be used instead."
2865
+ );
2866
+ }
2867
+ return lucid.newTx().readFrom([lrpScriptRefUtxo]).collectFrom([lrpUtxo], serialiseLrpRedeemer("Cancel")).pay.ToContract(
2868
+ lrpUtxo.address,
2869
+ {
2870
+ kind: "inline",
2871
+ value: serialiseLrpDatum({
2872
+ ...lrpDatum,
2873
+ lovelacesToSpend: lrpDatum.lovelacesToSpend + lovelacesAdjustAmt
2874
+ })
2875
+ },
2876
+ addAssets3(
2877
+ lrpUtxo.assets,
2878
+ mkAssetsOf(rewardAssetClass, -rewardAssetsAmt),
2879
+ mkLovelacesOf(lovelacesAdjustAmt)
2880
+ )
2881
+ ).addSigner(ownAddr);
2882
+ }
2883
+ async function claimLrp(lucid, lrpOutRef, lrpRefScriptOutRef, lrpParams) {
2884
+ return adjustLrp(lucid, lrpOutRef, 0n, lrpRefScriptOutRef, lrpParams);
2829
2885
  }
2830
2886
 
2831
2887
  // src/scripts/lrp-validator.ts
@@ -2845,6 +2901,19 @@ var mkLrpValidator = (params) => {
2845
2901
  ])
2846
2902
  };
2847
2903
  };
2904
+ var mkLrpValidatorFromSP = (params) => {
2905
+ return {
2906
+ type: lrpValidatorData.type,
2907
+ script: applyParamsToScript11(lrpValidatorData.cborHex, [
2908
+ castLrpParams({
2909
+ versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
2910
+ iassetNft: fromSystemParamsAsset(params.iassetNft),
2911
+ minRedemptionLovelacesAmt: BigInt(params.minRedemptionLovelacesAmt),
2912
+ iassetPolicyId: params.iassetPolicyId.unCurrencySymbol
2913
+ })
2914
+ ])
2915
+ };
2916
+ };
2848
2917
 
2849
2918
  // src/helpers/helper-txs.ts
2850
2919
  import {
@@ -2924,6 +2993,7 @@ export {
2924
2993
  addrDetails,
2925
2994
  addressFromBech32,
2926
2995
  addressToBech32,
2996
+ adjustLrp,
2927
2997
  balance,
2928
2998
  calculateFeeFromPercentage,
2929
2999
  cancelLrp,
@@ -2936,6 +3006,7 @@ export {
2936
3006
  castPriceOracleParams,
2937
3007
  castStabilityPoolParams,
2938
3008
  cdpCreatorValidator,
3009
+ claimLrp,
2939
3010
  createScriptAddress,
2940
3011
  fromSPInteger,
2941
3012
  fromSystemParamsAsset,
@@ -2948,6 +3019,7 @@ export {
2948
3019
  mkCDPCreatorValidatorFromSP,
2949
3020
  mkInterestOracleValidator,
2950
3021
  mkLrpValidator,
3022
+ mkLrpValidatorFromSP,
2951
3023
  mkPollManagerValidator,
2952
3024
  mkPollManagerValidatorFromSP,
2953
3025
  mkPollShardValidator,
@@ -0,0 +1,36 @@
1
+ import eslint from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+
4
+ export default tseslint.config(
5
+ {
6
+ ignores: ['**/dist/*', '**/node_modules/*'],
7
+ },
8
+ {
9
+ files: ['**/*.ts'],
10
+ extends: [
11
+ eslint.configs.recommended,
12
+ tseslint.configs.recommendedTypeChecked,
13
+ {
14
+ languageOptions: {
15
+ parserOptions: {
16
+ projectService: true,
17
+ tsconfigRootDir: import.meta.dirname,
18
+ },
19
+ },
20
+ },
21
+ ],
22
+ rules: {
23
+ 'no-unreachable': 'warn',
24
+ 'no-use-before-define': 'error',
25
+ '@typescript-eslint/no-unused-vars': [
26
+ 'error',
27
+ {
28
+ args: 'all',
29
+ argsIgnorePattern: '^_',
30
+ varsIgnorePattern: '^_',
31
+ caughtErrorsIgnorePattern: '^_',
32
+ },
33
+ ],
34
+ },
35
+ },
36
+ );