@indigo-labs/indigo-sdk 0.1.21 → 0.1.22
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.
- package/.github/workflows/ci.yml +3 -8
- package/.github/workflows/test.yml +44 -0
- package/dist/index.d.mts +670 -1291
- package/dist/index.d.ts +670 -1291
- package/dist/index.js +2235 -4669
- package/dist/index.mjs +2216 -4618
- package/eslint.config.mjs +1 -7
- package/package.json +4 -9
- package/src/contracts/cdp.ts +746 -0
- package/src/contracts/collector.ts +98 -0
- package/src/contracts/gov.ts +1 -0
- package/src/contracts/interest-oracle.ts +149 -0
- package/src/contracts/{lrp/transactions.ts → lrp.ts} +14 -14
- package/src/contracts/{one-shot/transactions.ts → one-shot.ts} +3 -3
- package/src/contracts/stability-pool.ts +690 -0
- package/src/contracts/staking.ts +348 -0
- package/src/contracts/treasury.ts +112 -0
- package/src/helpers/asset-helpers.ts +57 -0
- package/src/{utils → helpers}/helper-txs.ts +0 -1
- package/src/{utils/utils.ts → helpers/helpers.ts} +10 -0
- package/src/{contracts/interest-oracle/helpers.ts → helpers/interest-oracle.ts} +9 -37
- package/src/{contracts/stability-pool/helpers.ts → helpers/stability-pool-helpers.ts} +6 -110
- package/src/helpers/staking-helpers.ts +94 -0
- package/src/helpers/time-helpers.ts +4 -0
- package/src/{utils → helpers}/value-helpers.ts +0 -10
- package/src/index.ts +33 -38
- package/src/{validators → scripts}/cdp-creator-validator.ts +50 -4
- package/src/{validators → scripts}/cdp-validator.ts +5 -3
- package/src/{validators → scripts}/collector-validator.ts +3 -2
- package/src/scripts/execute-validator.ts +52 -0
- package/src/{validators/governance-validator.ts → scripts/gov-validator.ts} +40 -3
- package/src/{validators → scripts}/interest-oracle-validator.ts +20 -4
- package/src/scripts/lrp-validator.ts +40 -0
- package/src/{contracts/one-shot/scripts.ts → scripts/one-shot-policy.ts} +1 -1
- package/src/scripts/poll-manager-validator.ts +52 -0
- package/src/{validators → scripts}/poll-shard-validator.ts +43 -3
- package/src/{contracts/price-oracle/scripts.ts → scripts/price-oracle-validator.ts} +4 -1
- package/src/{validators → scripts}/stability-pool-validator.ts +57 -4
- package/src/{validators → scripts}/staking-validator.ts +3 -2
- package/src/{validators → scripts}/treasury-validator.ts +3 -2
- package/src/{validators → scripts}/version-record-policy.ts +23 -4
- package/src/{validators/execute-validator.ts → scripts/version-registry.ts} +11 -3
- package/src/types/generic.ts +60 -78
- package/src/{contracts/cdp-creator/types.ts → types/indigo/cdp-creator.ts} +4 -6
- package/src/types/indigo/cdp.ts +88 -0
- package/src/types/indigo/execute.ts +21 -0
- package/src/types/indigo/gov.ts +51 -0
- package/src/{contracts/interest-oracle/types.ts → types/indigo/interest-oracle.ts} +1 -1
- package/src/{contracts/lrp/types.ts → types/indigo/lrp.ts} +2 -2
- package/src/types/indigo/poll-manager.ts +21 -0
- package/src/types/indigo/poll-shard.ts +16 -0
- package/src/{contracts/price-oracle/types.ts → types/indigo/price-oracle.ts} +4 -16
- package/src/types/indigo/stability-pool.ts +233 -0
- package/src/types/indigo/staking.ts +99 -0
- package/src/{contracts/version-registry/types.ts → types/indigo/version-record.ts} +1 -1
- package/src/types/on-chain-decimal.ts +0 -22
- package/src/types/system-params.ts +11 -22
- package/tests/datums.test.ts +108 -125
- package/tests/endpoints/initialize.ts +338 -240
- package/tests/hash-checks.test.ts +21 -26
- package/tests/indigo-test-helpers.ts +55 -1
- package/tests/initialize.test.ts +5 -10
- package/tests/interest-calculations.test.ts +18 -18
- package/tests/interest-oracle.test.ts +18 -20
- package/tests/lrp.test.ts +65 -191
- package/tests/queries/governance-queries.ts +16 -19
- package/tests/queries/iasset-queries.ts +23 -46
- package/tests/queries/interest-oracle-queries.ts +6 -3
- package/tests/queries/lrp-queries.ts +2 -2
- package/tests/queries/price-oracle-queries.ts +22 -5
- package/tests/queries/stability-pool-queries.ts +8 -10
- package/tests/queries/staking-queries.ts +19 -28
- package/tests/stability-pool.test.ts +71 -186
- package/tests/staking.test.ts +23 -30
- package/tests/test-helpers.ts +2 -11
- package/tsconfig.json +1 -3
- package/vitest.config.ts +1 -1
- package/src/contracts/cdp/helpers.ts +0 -167
- package/src/contracts/cdp/scripts.ts +0 -33
- package/src/contracts/cdp/transactions.ts +0 -1310
- package/src/contracts/cdp/types.ts +0 -161
- package/src/contracts/cdp-creator/scripts.ts +0 -39
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -44
- package/src/contracts/execute/scripts.ts +0 -48
- package/src/contracts/execute/types.ts +0 -57
- package/src/contracts/gov/helpers.ts +0 -157
- package/src/contracts/gov/scripts.ts +0 -34
- package/src/contracts/gov/transactions.ts +0 -1224
- package/src/contracts/gov/types-new.ts +0 -115
- package/src/contracts/gov/types.ts +0 -89
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -149
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/poll/helpers.ts +0 -55
- package/src/contracts/poll/scripts.ts +0 -72
- package/src/contracts/poll/types-poll-manager.ts +0 -38
- package/src/contracts/poll/types-poll-shard.ts +0 -38
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/price-oracle/transactions.ts +0 -112
- package/src/contracts/stability-pool/scripts.ts +0 -46
- package/src/contracts/stability-pool/transactions.ts +0 -660
- package/src/contracts/stability-pool/types-new.ts +0 -208
- package/src/contracts/stability-pool/types.ts +0 -42
- package/src/contracts/staking/helpers.ts +0 -116
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -268
- package/src/contracts/staking/types-new.ts +0 -81
- package/src/contracts/staking/types.ts +0 -41
- package/src/contracts/treasury/scripts.ts +0 -37
- package/src/contracts/treasury/transactions.ts +0 -44
- package/src/contracts/treasury/types.ts +0 -55
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -19
- package/src/contracts/vesting/helpers.ts +0 -267
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/utils/bigint-utils.ts +0 -7
- package/src/utils/time-helpers.ts +0 -4
- package/src/validators/lrp-validator.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1565
- package/tests/gov.test.ts +0 -1874
- package/tests/mock/assets-mock.ts +0 -59
- package/tests/queries/cdp-queries.ts +0 -144
- package/tests/queries/collector-queries.ts +0 -26
- package/tests/queries/execute-queries.ts +0 -46
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/treasury-queries.ts +0 -19
- package/tests/utils/asserts.ts +0 -13
- package/tests/utils/index.ts +0 -50
- /package/src/{utils → helpers}/indigo-helpers.ts +0 -0
- /package/src/{utils → helpers}/lucid-utils.ts +0 -0
- /package/src/{contracts/price-oracle/helpers.ts → helpers/price-oracle-helpers.ts} +0 -0
- /package/src/{contracts/one-shot/types.ts → types/one-shot.ts} +0 -0
package/tests/lrp.test.ts
CHANGED
|
@@ -11,23 +11,23 @@ import {
|
|
|
11
11
|
UTxO,
|
|
12
12
|
validatorToScriptHash,
|
|
13
13
|
} from '@lucid-evolution/lucid';
|
|
14
|
-
import { LRPParams, parseLrpDatum } from '../src/
|
|
15
|
-
import { mkLrpValidator } from '../src/
|
|
16
|
-
import { runCreateScriptRefTx } from '../src/
|
|
17
|
-
import { runOneShotMintTx } from '../src/contracts/one-shot
|
|
14
|
+
import { LRPParams, parseLrpDatum } from '../src/types/indigo/lrp';
|
|
15
|
+
import { mkLrpValidator } from '../src/scripts/lrp-validator';
|
|
16
|
+
import { runCreateScriptRefTx } from '../src/helpers/helper-txs';
|
|
17
|
+
import { runOneShotMintTx } from '../src/contracts/one-shot';
|
|
18
18
|
import {
|
|
19
19
|
adjustLrp,
|
|
20
20
|
cancelLrp,
|
|
21
21
|
claimLrp,
|
|
22
22
|
openLrp,
|
|
23
23
|
redeemLrp,
|
|
24
|
-
} from '../src/contracts/lrp
|
|
24
|
+
} from '../src/contracts/lrp';
|
|
25
25
|
import { findLrp } from './queries/lrp-queries';
|
|
26
|
-
import { addrDetails, getInlineDatumOrThrow } from '../src/
|
|
27
|
-
import { runAndAwaitTx
|
|
28
|
-
import { matchSingle } from '../src/
|
|
29
|
-
import { runCreateIAsset } from './indigo-test-helpers';
|
|
30
|
-
import { mkPriceOracleValidator } from '../src/
|
|
26
|
+
import { addrDetails, getInlineDatumOrThrow } from '../src/helpers/lucid-utils';
|
|
27
|
+
import { runAndAwaitTx } from './test-helpers';
|
|
28
|
+
import { matchSingle } from '../src/helpers/helpers';
|
|
29
|
+
import { runCreateIAsset, runStartPriceOracle } from './indigo-test-helpers';
|
|
30
|
+
import { mkPriceOracleValidator } from '../src/scripts/price-oracle-validator';
|
|
31
31
|
import { AssetClass, OracleAssetNft, PriceOracleParams } from '../src';
|
|
32
32
|
import { alwaysFailValidator } from '../src/scripts/always-fail-validator';
|
|
33
33
|
import {
|
|
@@ -37,9 +37,8 @@ import {
|
|
|
37
37
|
} from '../src/types/on-chain-decimal';
|
|
38
38
|
import { findPriceOracle } from './queries/price-oracle-queries';
|
|
39
39
|
import { findIAsset } from './queries/iasset-queries';
|
|
40
|
-
import { assetClassValueOf, lovelacesAmt } from '../src/
|
|
40
|
+
import { assetClassValueOf, lovelacesAmt } from '../src/helpers/value-helpers';
|
|
41
41
|
import { strictEqual } from 'assert';
|
|
42
|
-
import { startPriceOracleTx } from '../src/contracts/price-oracle/transactions';
|
|
43
42
|
|
|
44
43
|
type LRPTestContext = {
|
|
45
44
|
iassetAc: AssetClass;
|
|
@@ -78,19 +77,19 @@ async function initTest(
|
|
|
78
77
|
};
|
|
79
78
|
const oracleValidator = mkPriceOracleValidator(priceOracleParams);
|
|
80
79
|
const oracleValidatorHash = validatorToScriptHash(oracleValidator);
|
|
81
|
-
const
|
|
80
|
+
const oracleNft = await runStartPriceOracle(
|
|
82
81
|
lucid,
|
|
83
|
-
|
|
84
|
-
iassetPrice,
|
|
82
|
+
oracleValidatorHash,
|
|
85
83
|
priceOracleParams,
|
|
84
|
+
network,
|
|
85
|
+
fromText('ORACLE_IBTC'),
|
|
86
|
+
iassetPrice,
|
|
86
87
|
);
|
|
87
88
|
|
|
88
|
-
await runAndAwaitTxBuilder(lucid, tx);
|
|
89
|
-
|
|
90
89
|
const iassetValHash = validatorToScriptHash(alwaysFailValidator);
|
|
91
90
|
const iassetNft = await runCreateIAsset(lucid, network, iassetValHash, {
|
|
92
91
|
assetName: iassetTokenName,
|
|
93
|
-
price: { Oracle:
|
|
92
|
+
price: { Oracle: oracleNft },
|
|
94
93
|
interestOracleNft: { currencySymbol: '', tokenName: '' },
|
|
95
94
|
redemptionRatio: OCD_ONE,
|
|
96
95
|
maintenanceRatio: OCD_ONE,
|
|
@@ -200,7 +199,7 @@ describe('LRP', () => {
|
|
|
200
199
|
lovelacesAmt(adjustedUtxo1.assets) >=
|
|
201
200
|
parseLrpDatum(getInlineDatumOrThrow(adjustedUtxo1)).lovelacesToSpend,
|
|
202
201
|
'Lovelaces to spend has to be smaller than actual lovelaces in UTXO',
|
|
203
|
-
)
|
|
202
|
+
);
|
|
204
203
|
|
|
205
204
|
await runAndAwaitTx(
|
|
206
205
|
lucid,
|
|
@@ -235,7 +234,7 @@ describe('LRP', () => {
|
|
|
235
234
|
lovelacesAmt(adjustedUtxo2.assets) >=
|
|
236
235
|
parseLrpDatum(getInlineDatumOrThrow(adjustedUtxo2)).lovelacesToSpend,
|
|
237
236
|
'Lovelaces to spend has to be smaller than actual lovelaces in UTXO',
|
|
238
|
-
)
|
|
237
|
+
);
|
|
239
238
|
});
|
|
240
239
|
|
|
241
240
|
it('claim', async () => {
|
|
@@ -324,15 +323,18 @@ describe('LRP', () => {
|
|
|
324
323
|
redeemLrp(
|
|
325
324
|
[[lrpUtxo, redemptionIAssetAmt]],
|
|
326
325
|
lrpRefScriptOutRef,
|
|
327
|
-
await findPriceOracle(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
326
|
+
await findPriceOracle(
|
|
327
|
+
lucid,
|
|
328
|
+
network,
|
|
329
|
+
testCtx.oracleValHash,
|
|
330
|
+
testCtx.oracleNft,
|
|
331
|
+
),
|
|
332
|
+
await findIAsset(
|
|
333
|
+
lucid,
|
|
334
|
+
testCtx.iassetValHash,
|
|
335
|
+
testCtx.iassetNft,
|
|
336
|
+
toText(iassetTokenName),
|
|
337
|
+
),
|
|
336
338
|
lucid,
|
|
337
339
|
lrpParams,
|
|
338
340
|
network,
|
|
@@ -447,15 +449,18 @@ describe('LRP', () => {
|
|
|
447
449
|
redeemLrp(
|
|
448
450
|
[[lrpUtxo, redemptionIAssetAmt]],
|
|
449
451
|
lrpRefScriptOutRef,
|
|
450
|
-
await findPriceOracle(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
452
|
+
await findPriceOracle(
|
|
453
|
+
lucid,
|
|
454
|
+
network,
|
|
455
|
+
testCtx.oracleValHash,
|
|
456
|
+
testCtx.oracleNft,
|
|
457
|
+
),
|
|
458
|
+
await findIAsset(
|
|
459
|
+
lucid,
|
|
460
|
+
testCtx.iassetValHash,
|
|
461
|
+
testCtx.iassetNft,
|
|
462
|
+
toText(iassetTokenName),
|
|
463
|
+
),
|
|
459
464
|
lucid,
|
|
460
465
|
lrpParams,
|
|
461
466
|
network,
|
|
@@ -576,130 +581,18 @@ describe('LRP', () => {
|
|
|
576
581
|
redeemLrp(
|
|
577
582
|
[[lrpUtxo, redemptionIAssetAmt]],
|
|
578
583
|
lrpRefScriptOutRef,
|
|
579
|
-
await findPriceOracle(
|
|
580
|
-
(
|
|
581
|
-
await findIAsset(
|
|
582
|
-
lucid,
|
|
583
|
-
testCtx.iassetValHash,
|
|
584
|
-
testCtx.iassetNft,
|
|
585
|
-
toText(iassetTokenName),
|
|
586
|
-
)
|
|
587
|
-
).utxo,
|
|
588
|
-
lucid,
|
|
589
|
-
lrpParams,
|
|
590
|
-
network,
|
|
591
|
-
),
|
|
592
|
-
);
|
|
593
|
-
|
|
594
|
-
const redeemedLrp = await findSingleOwnLrp();
|
|
595
|
-
|
|
596
|
-
strictEqual(
|
|
597
|
-
assetClassValueOf(redeemedLrp.assets, redemptionAsset),
|
|
598
|
-
redemptionIAssetAmt,
|
|
599
|
-
'LRP has wrong number of iassets after redemption',
|
|
600
|
-
);
|
|
601
|
-
|
|
602
|
-
await runAndAwaitTx(
|
|
603
|
-
lucid,
|
|
604
|
-
cancelLrp(redeemedLrp, lrpRefScriptOutRef, lucid),
|
|
605
|
-
);
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
it('redeem, redeem again and cancel', async () => {
|
|
609
|
-
const network: Network = 'Custom';
|
|
610
|
-
const account1 = generateEmulatorAccount({
|
|
611
|
-
lovelace: 80_000_000_000n, // 80,000 ADA
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
const emulator = new Emulator([account1]);
|
|
615
|
-
const lucid = await Lucid(emulator, network);
|
|
616
|
-
|
|
617
|
-
lucid.selectWallet.fromSeed(account1.seedPhrase);
|
|
618
|
-
|
|
619
|
-
const iassetTokenName = fromText('iBTC');
|
|
620
|
-
const testCtx = await initTest(
|
|
621
|
-
lucid,
|
|
622
|
-
network,
|
|
623
|
-
iassetTokenName,
|
|
624
|
-
10_000_000n,
|
|
625
|
-
OCD_ONE,
|
|
626
|
-
);
|
|
627
|
-
|
|
628
|
-
const [ownPkh, _] = await addrDetails(lucid);
|
|
629
|
-
|
|
630
|
-
const lrpParams: LRPParams = {
|
|
631
|
-
versionRecordToken: {
|
|
632
|
-
currencySymbol: fromText('smth'),
|
|
633
|
-
tokenName: fromText('version_record'),
|
|
634
|
-
},
|
|
635
|
-
iassetNft: testCtx.iassetNft,
|
|
636
|
-
iassetPolicyId: testCtx.iassetAc.currencySymbol,
|
|
637
|
-
minRedemptionLovelacesAmt: 1_000_000n,
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
const lrpValidator = mkLrpValidator(lrpParams);
|
|
641
|
-
const lrpValidatorHash = validatorToScriptHash(lrpValidator);
|
|
642
|
-
const lrpRefScriptOutRef = await runCreateScriptRefTx(
|
|
643
|
-
lucid,
|
|
644
|
-
lrpValidator,
|
|
645
|
-
network,
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
const findSingleOwnLrp = async (): Promise<UTxO> => {
|
|
649
|
-
return matchSingle(
|
|
650
|
-
await findLrp(
|
|
584
|
+
await findPriceOracle(
|
|
651
585
|
lucid,
|
|
652
586
|
network,
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
587
|
+
testCtx.oracleValHash,
|
|
588
|
+
testCtx.oracleNft,
|
|
589
|
+
),
|
|
590
|
+
await findIAsset(
|
|
591
|
+
lucid,
|
|
592
|
+
testCtx.iassetValHash,
|
|
593
|
+
testCtx.iassetNft,
|
|
594
|
+
toText(iassetTokenName),
|
|
656
595
|
),
|
|
657
|
-
(res) =>
|
|
658
|
-
new Error('Expected a single LRP UTXO.: ' + JSON.stringify(res)),
|
|
659
|
-
);
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
await runAndAwaitTx(
|
|
663
|
-
lucid,
|
|
664
|
-
openLrp(
|
|
665
|
-
iassetTokenName,
|
|
666
|
-
20_000_000n,
|
|
667
|
-
{ getOnChainInt: 1_000_000n },
|
|
668
|
-
lucid,
|
|
669
|
-
lrpValidatorHash,
|
|
670
|
-
network,
|
|
671
|
-
),
|
|
672
|
-
);
|
|
673
|
-
|
|
674
|
-
const lrpUtxo = await findSingleOwnLrp();
|
|
675
|
-
|
|
676
|
-
const redemptionAsset: AssetClass = {
|
|
677
|
-
currencySymbol: testCtx.iassetAc.currencySymbol,
|
|
678
|
-
tokenName: iassetTokenName,
|
|
679
|
-
};
|
|
680
|
-
|
|
681
|
-
strictEqual(
|
|
682
|
-
assetClassValueOf(lrpUtxo.assets, redemptionAsset),
|
|
683
|
-
0n,
|
|
684
|
-
'LRP should have no iassets before redemption',
|
|
685
|
-
);
|
|
686
|
-
|
|
687
|
-
const redemptionIAssetAmt = 5_000_000n;
|
|
688
|
-
|
|
689
|
-
await runAndAwaitTx(
|
|
690
|
-
lucid,
|
|
691
|
-
redeemLrp(
|
|
692
|
-
[[lrpUtxo, redemptionIAssetAmt]],
|
|
693
|
-
lrpRefScriptOutRef,
|
|
694
|
-
await findPriceOracle(lucid, testCtx.oracleNft),
|
|
695
|
-
(
|
|
696
|
-
await findIAsset(
|
|
697
|
-
lucid,
|
|
698
|
-
testCtx.iassetValHash,
|
|
699
|
-
testCtx.iassetNft,
|
|
700
|
-
toText(iassetTokenName),
|
|
701
|
-
)
|
|
702
|
-
).utxo,
|
|
703
596
|
lucid,
|
|
704
597
|
lrpParams,
|
|
705
598
|
network,
|
|
@@ -708,37 +601,15 @@ describe('LRP', () => {
|
|
|
708
601
|
|
|
709
602
|
const redeemedLrp = await findSingleOwnLrp();
|
|
710
603
|
|
|
711
|
-
await runAndAwaitTx(
|
|
712
|
-
lucid,
|
|
713
|
-
redeemLrp(
|
|
714
|
-
[[redeemedLrp, redemptionIAssetAmt]],
|
|
715
|
-
lrpRefScriptOutRef,
|
|
716
|
-
await findPriceOracle(lucid, testCtx.oracleNft),
|
|
717
|
-
(
|
|
718
|
-
await findIAsset(
|
|
719
|
-
lucid,
|
|
720
|
-
testCtx.iassetValHash,
|
|
721
|
-
testCtx.iassetNft,
|
|
722
|
-
toText(iassetTokenName),
|
|
723
|
-
)
|
|
724
|
-
).utxo,
|
|
725
|
-
lucid,
|
|
726
|
-
lrpParams,
|
|
727
|
-
network,
|
|
728
|
-
),
|
|
729
|
-
);
|
|
730
|
-
|
|
731
604
|
strictEqual(
|
|
732
605
|
assetClassValueOf(redeemedLrp.assets, redemptionAsset),
|
|
733
606
|
redemptionIAssetAmt,
|
|
734
607
|
'LRP has wrong number of iassets after redemption',
|
|
735
608
|
);
|
|
736
609
|
|
|
737
|
-
const closableLrp = await findSingleOwnLrp();
|
|
738
|
-
|
|
739
610
|
await runAndAwaitTx(
|
|
740
611
|
lucid,
|
|
741
|
-
cancelLrp(
|
|
612
|
+
cancelLrp(redeemedLrp, lrpRefScriptOutRef, lucid),
|
|
742
613
|
);
|
|
743
614
|
});
|
|
744
615
|
|
|
@@ -841,15 +712,18 @@ describe('LRP', () => {
|
|
|
841
712
|
[lrpUtxo2, 4_000_000n],
|
|
842
713
|
],
|
|
843
714
|
lrpRefScriptOutRef,
|
|
844
|
-
await findPriceOracle(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
715
|
+
await findPriceOracle(
|
|
716
|
+
lucid,
|
|
717
|
+
network,
|
|
718
|
+
testCtx.oracleValHash,
|
|
719
|
+
testCtx.oracleNft,
|
|
720
|
+
),
|
|
721
|
+
await findIAsset(
|
|
722
|
+
lucid,
|
|
723
|
+
testCtx.iassetValHash,
|
|
724
|
+
testCtx.iassetNft,
|
|
725
|
+
toText(iassetTokenName),
|
|
726
|
+
),
|
|
853
727
|
lucid,
|
|
854
728
|
lrpParams,
|
|
855
729
|
network,
|
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { createScriptAddress } from '../../src/
|
|
2
|
+
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
3
3
|
import { AssetClass } from '../../src/types/generic';
|
|
4
|
-
import { assetClassToUnit } from '../../src/
|
|
5
|
-
import {
|
|
6
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
4
|
+
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
5
|
+
import { matchSingle, parseGovDatum } from '../../src';
|
|
7
6
|
|
|
8
7
|
export async function findGov(
|
|
9
8
|
lucid: LucidEvolution,
|
|
10
9
|
govScriptHash: ScriptHash,
|
|
11
10
|
govNft: AssetClass,
|
|
12
|
-
): Promise<{
|
|
13
|
-
utxo: UTxO;
|
|
14
|
-
datum: GovDatum;
|
|
15
|
-
}> {
|
|
11
|
+
): Promise<UTxO> {
|
|
16
12
|
const govUtxos = await lucid.utxosAtWithUnit(
|
|
17
|
-
createScriptAddress(lucid.config().network
|
|
13
|
+
createScriptAddress(lucid.config().network, govScriptHash),
|
|
18
14
|
assetClassToUnit(govNft),
|
|
19
15
|
);
|
|
20
16
|
|
|
21
17
|
return matchSingle(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
govUtxos.filter((utxo) => {
|
|
19
|
+
if (utxo.datum != null) {
|
|
20
|
+
try {
|
|
21
|
+
parseGovDatum(utxo.datum);
|
|
22
|
+
return true; // TODO: implement Gov Datum
|
|
23
|
+
} catch (_) {
|
|
24
|
+
// when incompatible datum
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
32
29
|
(res) => new Error('Expected a single Gov UTXO.: ' + JSON.stringify(res)),
|
|
33
30
|
);
|
|
34
31
|
}
|
|
@@ -1,62 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
fromText,
|
|
3
|
+
LucidEvolution,
|
|
4
|
+
ScriptHash,
|
|
5
|
+
UTxO,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
3
8
|
import { AssetClass } from '../../src/types/generic';
|
|
4
|
-
import { assetClassToUnit } from '../../src/
|
|
5
|
-
import {
|
|
6
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
9
|
+
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
10
|
+
import { matchSingle, parseIAssetDatum } from '../../src';
|
|
7
11
|
|
|
8
12
|
export async function findIAsset(
|
|
9
13
|
lucid: LucidEvolution,
|
|
10
14
|
iassetScriptHash: ScriptHash,
|
|
11
15
|
iassetNft: AssetClass,
|
|
12
|
-
// Ascii encoded
|
|
13
16
|
iassetName: string,
|
|
14
|
-
): Promise<
|
|
17
|
+
): Promise<UTxO> {
|
|
15
18
|
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
16
|
-
createScriptAddress(lucid.config().network
|
|
19
|
+
createScriptAddress(lucid.config().network, iassetScriptHash),
|
|
17
20
|
assetClassToUnit(iassetNft),
|
|
18
21
|
);
|
|
19
22
|
|
|
20
23
|
return matchSingle(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
),
|
|
34
|
-
),
|
|
35
|
-
A.compact,
|
|
36
|
-
),
|
|
24
|
+
iassetUtxos.filter((utxo) => {
|
|
25
|
+
if (utxo.datum != null) {
|
|
26
|
+
try {
|
|
27
|
+
const iassetDatum = parseIAssetDatum(utxo.datum);
|
|
28
|
+
|
|
29
|
+
return iassetDatum.assetName == fromText(iassetName);
|
|
30
|
+
} catch (_) {
|
|
31
|
+
// when incompatible datum
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
37
36
|
(res) =>
|
|
38
37
|
new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
|
|
39
38
|
);
|
|
40
39
|
}
|
|
41
|
-
|
|
42
|
-
export async function findAllIAssets(
|
|
43
|
-
lucid: LucidEvolution,
|
|
44
|
-
iassetScriptHash: ScriptHash,
|
|
45
|
-
iassetNft: AssetClass,
|
|
46
|
-
): Promise<IAssetOutput[]> {
|
|
47
|
-
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
48
|
-
createScriptAddress(lucid.config().network!, iassetScriptHash),
|
|
49
|
-
assetClassToUnit(iassetNft),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
return F.pipe(
|
|
53
|
-
iassetUtxos.map((utxo) =>
|
|
54
|
-
F.pipe(
|
|
55
|
-
O.fromNullable(utxo.datum),
|
|
56
|
-
O.flatMap(parseIAssetDatum),
|
|
57
|
-
O.map((datum) => ({ utxo, datum: datum })),
|
|
58
|
-
),
|
|
59
|
-
),
|
|
60
|
-
A.compact,
|
|
61
|
-
);
|
|
62
|
-
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
2
|
import { AssetClass } from '../../src/types/generic';
|
|
3
|
-
import { assetClassToUnit } from '../../src/
|
|
3
|
+
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
4
|
+
import { InterestOracleDatum, parseInterestOracleDatum } from '../../src';
|
|
4
5
|
|
|
5
6
|
export async function findInterestOracle(
|
|
6
7
|
lucid: LucidEvolution,
|
|
7
8
|
interestNft: AssetClass,
|
|
8
|
-
): Promise<UTxO> {
|
|
9
|
-
|
|
9
|
+
): Promise<[UTxO, InterestOracleDatum]> {
|
|
10
|
+
const interestUtxo = await lucid.utxoByUnit(assetClassToUnit(interestNft));
|
|
11
|
+
if (!interestUtxo.datum) throw new Error('No interest oracle utxo found');
|
|
12
|
+
return [interestUtxo, parseInterestOracleDatum(interestUtxo.datum)];
|
|
10
13
|
}
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
ScriptHash,
|
|
6
6
|
UTxO,
|
|
7
7
|
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { createScriptAddress } from '../../src/
|
|
9
|
-
import { parseLrpDatum } from '../../src/
|
|
8
|
+
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
9
|
+
import { parseLrpDatum } from '../../src/types/indigo/lrp';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Beware, this shouldn't be used in production since it queries all the UTXOs
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
LucidEvolution,
|
|
3
|
+
Network,
|
|
4
|
+
OutRef,
|
|
5
|
+
ScriptHash,
|
|
6
|
+
toUnit,
|
|
7
|
+
} from '@lucid-evolution/lucid';
|
|
8
|
+
import { createScriptAddress, matchSingle, OracleAssetNft } from '../../src';
|
|
4
9
|
|
|
5
10
|
export async function findPriceOracle(
|
|
6
11
|
lucid: LucidEvolution,
|
|
12
|
+
network: Network,
|
|
13
|
+
oracleScriptHash: ScriptHash,
|
|
7
14
|
oracleNft: OracleAssetNft,
|
|
8
|
-
): Promise<
|
|
9
|
-
return
|
|
15
|
+
): Promise<OutRef> {
|
|
16
|
+
return matchSingle(
|
|
17
|
+
await lucid.utxosAtWithUnit(
|
|
18
|
+
createScriptAddress(network, oracleScriptHash),
|
|
19
|
+
toUnit(
|
|
20
|
+
oracleNft.oracleNft.asset.currencySymbol,
|
|
21
|
+
oracleNft.oracleNft.asset.tokenName,
|
|
22
|
+
),
|
|
23
|
+
),
|
|
24
|
+
(res) =>
|
|
25
|
+
new Error('Expected a single Oracle UTXO.: ' + JSON.stringify(res)),
|
|
26
|
+
);
|
|
10
27
|
}
|
|
@@ -2,17 +2,16 @@ import {
|
|
|
2
2
|
fromText,
|
|
3
3
|
LucidEvolution,
|
|
4
4
|
ScriptHash,
|
|
5
|
-
toHex,
|
|
6
5
|
UTxO,
|
|
7
6
|
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { createScriptAddress } from '../../src/
|
|
7
|
+
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
9
8
|
import { AssetClass } from '../../src/types/generic';
|
|
10
|
-
import { assetClassToUnit } from '../../src/
|
|
11
|
-
import { matchSingle } from '../../src';
|
|
9
|
+
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
12
10
|
import {
|
|
11
|
+
matchSingle,
|
|
13
12
|
parseAccountDatum,
|
|
14
13
|
parseStabilityPoolDatum,
|
|
15
|
-
} from '../../src
|
|
14
|
+
} from '../../src';
|
|
16
15
|
|
|
17
16
|
export async function findStabilityPool(
|
|
18
17
|
lucid: LucidEvolution,
|
|
@@ -21,7 +20,7 @@ export async function findStabilityPool(
|
|
|
21
20
|
asset: string,
|
|
22
21
|
): Promise<UTxO> {
|
|
23
22
|
const stakingUtxos = await lucid.utxosAtWithUnit(
|
|
24
|
-
createScriptAddress(lucid.config().network
|
|
23
|
+
createScriptAddress(lucid.config().network, stabilityPoolHash),
|
|
25
24
|
assetClassToUnit(stabilityPoolToken),
|
|
26
25
|
);
|
|
27
26
|
|
|
@@ -31,7 +30,7 @@ export async function findStabilityPool(
|
|
|
31
30
|
try {
|
|
32
31
|
const stabilityPoolDatum = parseStabilityPoolDatum(utxo.datum);
|
|
33
32
|
|
|
34
|
-
return
|
|
33
|
+
return stabilityPoolDatum.asset == fromText(asset);
|
|
35
34
|
} catch (_) {
|
|
36
35
|
// when incompatible datum
|
|
37
36
|
return false;
|
|
@@ -52,7 +51,7 @@ export async function findStabilityPoolAccount(
|
|
|
52
51
|
asset: string,
|
|
53
52
|
): Promise<UTxO> {
|
|
54
53
|
const accountUtxos = await lucid.utxosAt(
|
|
55
|
-
createScriptAddress(lucid.config().network
|
|
54
|
+
createScriptAddress(lucid.config().network, stabilityPoolHash),
|
|
56
55
|
);
|
|
57
56
|
|
|
58
57
|
return matchSingle(
|
|
@@ -62,8 +61,7 @@ export async function findStabilityPoolAccount(
|
|
|
62
61
|
const accountDatum = parseAccountDatum(utxo.datum);
|
|
63
62
|
|
|
64
63
|
return (
|
|
65
|
-
|
|
66
|
-
toHex(accountDatum.owner) == owner
|
|
64
|
+
accountDatum.asset == fromText(asset) && accountDatum.owner == owner
|
|
67
65
|
);
|
|
68
66
|
} catch (_) {
|
|
69
67
|
// when incompatible datum
|
|
@@ -1,49 +1,40 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LucidEvolution,
|
|
3
|
+
Network,
|
|
4
|
+
OutRef,
|
|
3
5
|
ScriptHash,
|
|
4
|
-
toHex,
|
|
5
|
-
UTxO,
|
|
6
6
|
} from '@lucid-evolution/lucid';
|
|
7
|
-
import { createScriptAddress } from '../../src/
|
|
7
|
+
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
8
8
|
import { AssetClass } from '../../src/types/generic';
|
|
9
|
-
import { assetClassToUnit } from '../../src/
|
|
9
|
+
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
10
10
|
import { matchSingle } from '../../src';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
parseStakingPosition,
|
|
14
|
-
StakingPosition,
|
|
15
|
-
} from '../../src/contracts/staking/types-new';
|
|
11
|
+
import { parseStakingPositionDatum } from '../../src/types/indigo/staking';
|
|
16
12
|
|
|
17
13
|
export async function findStakingPosition(
|
|
18
14
|
lucid: LucidEvolution,
|
|
15
|
+
network: Network,
|
|
19
16
|
stakingScriptHash: ScriptHash,
|
|
20
17
|
stakingPositionNft: AssetClass,
|
|
21
18
|
owner: string,
|
|
22
|
-
): Promise<
|
|
23
|
-
const network = lucid.config().network!;
|
|
24
|
-
|
|
19
|
+
): Promise<OutRef> {
|
|
25
20
|
const stakingUtxos = await lucid.utxosAtWithUnit(
|
|
26
21
|
createScriptAddress(network, stakingScriptHash),
|
|
27
22
|
assetClassToUnit(stakingPositionNft),
|
|
28
23
|
);
|
|
29
24
|
|
|
30
25
|
return matchSingle(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
),
|
|
45
|
-
A.compact,
|
|
46
|
-
),
|
|
26
|
+
stakingUtxos.filter((utxo) => {
|
|
27
|
+
if (utxo.datum != null) {
|
|
28
|
+
try {
|
|
29
|
+
const stakingDatum = parseStakingPositionDatum(utxo.datum);
|
|
30
|
+
|
|
31
|
+
return stakingDatum.owner == owner;
|
|
32
|
+
} catch (_) {
|
|
33
|
+
// when incompatible datum
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
47
38
|
(res) =>
|
|
48
39
|
new Error(
|
|
49
40
|
'Expected a single Staking Position UTXO.: ' + JSON.stringify(res),
|