@indigo-labs/indigo-sdk 0.2.42 → 0.3.1
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 +4 -2
- package/README.md +88 -15
- package/dist/index.d.mts +3012 -2194
- package/dist/index.d.ts +3012 -2194
- package/dist/index.js +9849 -6198
- package/dist/index.mjs +8733 -4933
- package/package.json +14 -3
- package/src/contracts/cdp/helpers.ts +68 -72
- package/src/contracts/cdp/scripts.ts +50 -13
- package/src/contracts/cdp/transactions.ts +841 -546
- package/src/contracts/cdp/types-new.ts +256 -0
- package/src/contracts/cdp/types.ts +26 -144
- package/src/contracts/cdp-creator/scripts.ts +15 -9
- package/src/contracts/cdp-creator/types-new.ts +50 -0
- package/src/contracts/cdp-creator/types.ts +5 -31
- package/src/contracts/collector/scripts.ts +1 -1
- package/src/contracts/collector/transactions.ts +23 -13
- package/src/contracts/collector/types-new.ts +17 -0
- package/src/contracts/execute/scripts.ts +19 -10
- package/src/contracts/execute/types-new.ts +44 -0
- package/src/contracts/execute/types.ts +5 -38
- package/src/contracts/gov/helpers.ts +187 -51
- package/src/contracts/gov/scripts.ts +17 -10
- package/src/contracts/gov/transactions.ts +599 -271
- package/src/contracts/gov/types-new.ts +253 -100
- package/src/contracts/gov/types.ts +4 -71
- package/src/contracts/iasset/helpers.ts +172 -0
- package/src/contracts/iasset/scripts.ts +38 -0
- package/src/contracts/iasset/types.ts +154 -0
- package/src/contracts/initialize/actions.ts +768 -0
- package/src/contracts/initialize/helpers.ts +611 -36
- package/src/contracts/initialize/types.ts +102 -28
- package/src/contracts/interest-collection/helpers.ts +19 -0
- package/src/contracts/interest-collection/scripts.ts +44 -0
- package/src/contracts/interest-collection/transactions.ts +436 -0
- package/src/contracts/interest-collection/types-new.ts +50 -0
- package/src/contracts/interest-collection/types.ts +26 -0
- package/src/contracts/interest-oracle/helpers.ts +2 -30
- package/src/contracts/interest-oracle/scripts.ts +1 -1
- package/src/contracts/interest-oracle/transactions.ts +21 -16
- package/src/contracts/interest-oracle/types-new.ts +32 -0
- package/src/contracts/interest-oracle/types.ts +1 -40
- package/src/contracts/one-shot/transactions.ts +1 -2
- package/src/contracts/poll/helpers.ts +5 -23
- package/src/contracts/poll/scripts.ts +12 -13
- package/src/contracts/poll/types-poll-manager.ts +1 -19
- package/src/contracts/poll/types-poll-new.ts +170 -0
- package/src/contracts/poll/types-poll-shard.ts +2 -24
- package/src/contracts/price-oracle/helpers.ts +1 -4
- package/src/contracts/price-oracle/scripts.ts +3 -8
- package/src/contracts/price-oracle/transactions.ts +32 -25
- package/src/contracts/price-oracle/types-new.ts +50 -0
- package/src/contracts/price-oracle/types.ts +2 -36
- package/src/contracts/pyth-feed/helpers.ts +58 -0
- package/src/contracts/pyth-feed/scripts.ts +15 -0
- package/src/contracts/pyth-feed/types.ts +181 -0
- package/src/contracts/rob/helpers.ts +405 -0
- package/src/contracts/rob/scripts.ts +35 -0
- package/src/contracts/rob/transactions.ts +410 -0
- package/src/contracts/rob/types-new.ts +128 -0
- package/src/contracts/rob/types.ts +16 -0
- package/src/contracts/rob-leverage/helpers.ts +424 -0
- package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
- package/src/contracts/stability-pool/helpers.ts +714 -230
- package/src/contracts/stability-pool/scripts.ts +20 -15
- package/src/contracts/stability-pool/transactions.ts +628 -496
- package/src/contracts/stability-pool/types-new.ts +247 -100
- package/src/contracts/stability-pool/types.ts +5 -22
- package/src/contracts/stableswap/helpers.ts +22 -0
- package/src/contracts/stableswap/scripts.ts +37 -0
- package/src/contracts/stableswap/transactions.ts +647 -0
- package/src/contracts/stableswap/types-new.ts +131 -0
- package/src/contracts/stableswap/types.ts +17 -0
- package/src/contracts/staking/helpers.ts +49 -34
- package/src/contracts/staking/scripts.ts +1 -1
- package/src/contracts/staking/transactions.ts +85 -130
- package/src/contracts/staking/types-new.ts +60 -28
- package/src/contracts/staking/types.ts +1 -28
- package/src/contracts/treasury/helpers.ts +21 -0
- package/src/contracts/treasury/scripts.ts +16 -26
- package/src/contracts/treasury/transactions.ts +256 -27
- package/src/contracts/treasury/types-new.ts +69 -0
- package/src/contracts/treasury/types.ts +2 -43
- package/src/contracts/version-registry/scripts.ts +2 -2
- package/src/contracts/version-registry/types-new.ts +6 -7
- package/src/index.ts +37 -20
- package/src/scripts/auth-token-policy.ts +3 -2
- package/src/scripts/iasset-policy.ts +3 -2
- package/src/types/evolution-schema-options.ts +3 -3
- package/src/types/generic.ts +17 -89
- package/src/types/multisig.ts +48 -0
- package/src/types/on-chain-decimal.ts +14 -7
- package/src/types/rational.ts +61 -0
- package/src/types/system-params.ts +237 -41
- package/src/utils/array-utils.ts +70 -1
- package/src/utils/bigint-utils.ts +12 -0
- package/src/utils/indigo-helpers.ts +8 -10
- package/src/utils/lucid-utils.ts +47 -40
- package/src/utils/oracle-helpers.ts +62 -0
- package/src/utils/pyth/decode.ts +223 -0
- package/src/utils/pyth/encode.ts +262 -0
- package/src/utils/pyth/index.ts +14 -0
- package/src/utils/pyth/types.ts +87 -0
- package/src/validators/always-succeed-validator.ts +6 -0
- package/src/validators/cdp-creator-validator.ts +2 -2
- package/src/validators/cdp-redeem-validator.ts +7 -0
- package/src/validators/cdp-validator.ts +2 -2
- package/src/validators/collector-validator.ts +2 -2
- package/src/validators/execute-validator.ts +2 -2
- package/src/validators/governance-validator.ts +2 -2
- package/src/validators/iasset-validator.ts +7 -0
- package/src/validators/interest-collection-validator.ts +7 -0
- package/src/validators/interest-oracle-validator.ts +2 -2
- package/src/validators/poll-manager-validator.ts +2 -2
- package/src/validators/poll-shard-validator.ts +2 -2
- package/src/validators/price-oracle-validator.ts +7 -0
- package/src/validators/pyth-feed-validator.ts +7 -0
- package/src/validators/rob-validator.ts +7 -0
- package/src/validators/stability-pool-validator.ts +2 -2
- package/src/validators/stableswap-validator.ts +7 -0
- package/src/validators/staking-validator.ts +2 -2
- package/src/validators/treasury-validator.ts +2 -2
- package/src/validators/version-record-policy.ts +2 -2
- package/src/validators/version-registry-validator.ts +2 -2
- package/tests/always-succeed/script.ts +7 -0
- package/tests/bigint-utils.test.ts +41 -0
- package/tests/cdp/actions.ts +610 -0
- package/tests/cdp/cdp-helpers.ts +55 -0
- package/tests/cdp/cdp-queries.ts +440 -0
- package/tests/cdp/cdp.test.ts +6087 -0
- package/tests/cdp/transactions-mutated.ts +1729 -0
- package/tests/data/system-params.json +177 -34
- package/tests/datums.test.ts +209 -210
- package/tests/endpoints/initialize.ts +68 -0
- package/tests/endpoints/interest-collector.ts +37 -0
- package/tests/endpoints/treasury.ts +70 -0
- package/tests/gov/actions.ts +406 -0
- package/tests/gov/gov.test.ts +4450 -0
- package/tests/{queries → gov}/governance-queries.ts +6 -3
- package/tests/hash-checks.test.ts +38 -11
- package/tests/indigo-test-helpers.ts +100 -0
- package/tests/initialize.test.ts +61 -9
- package/tests/interest-collection/interest-collection.test.ts +892 -0
- package/tests/interest-collection/interest-collector-queries.ts +49 -0
- package/tests/interest-collection/transactions-mutated.ts +260 -0
- package/tests/interest-oracle.test.ts +43 -35
- package/tests/mock/assets-mock.ts +234 -23
- package/tests/mock/protocol-params-mock.ts +21 -0
- package/tests/price-oracle/actions.ts +163 -0
- package/tests/price-oracle/price-oracle-queries.ts +12 -0
- package/tests/price-oracle/price-oracle.test.ts +240 -0
- package/tests/price-oracle/transactions-mutated.ts +62 -0
- package/tests/pyth/endpoints.ts +96 -0
- package/tests/pyth/helpers.ts +37 -0
- package/tests/pyth/pyth-encoding.test.ts +376 -0
- package/tests/pyth/pyth-indigo.test.ts +509 -0
- package/tests/pyth/pyth.test.ts +300 -0
- package/tests/queries/execute-queries.ts +6 -5
- package/tests/queries/iasset-queries.ts +175 -5
- package/tests/queries/interest-oracle-queries.ts +4 -2
- package/tests/queries/poll-queries.ts +8 -9
- package/tests/queries/stability-pool-queries.ts +95 -48
- package/tests/queries/staking-queries.ts +4 -2
- package/tests/queries/treasury-queries.ts +80 -5
- package/tests/rob/actions.ts +58 -0
- package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
- package/tests/rob/rob-queries.ts +95 -0
- package/tests/rob/rob.test.ts +3762 -0
- package/tests/rob/transactions-mutated.ts +853 -0
- package/tests/script-size.test.ts +240 -0
- package/tests/setup.ts +135 -0
- package/tests/stability-pool/actions.ts +220 -0
- package/tests/stability-pool.test.ts +6121 -667
- package/tests/stableswap/stableswap-actions.ts +84 -0
- package/tests/stableswap/stableswap-queries.ts +89 -0
- package/tests/stableswap/stableswap.test.ts +3891 -0
- package/tests/stableswap/transactions-mutated.ts +348 -0
- package/tests/staking.test.ts +82 -99
- package/tests/test-helpers.ts +58 -11
- package/tests/treasury.test.ts +242 -0
- package/tests/utils/asserts.ts +74 -0
- package/tests/utils/benchmark-utils.ts +81 -0
- package/tests/utils/index.ts +122 -4
- package/tsconfig.json +9 -1
- package/vitest.config.ts +3 -1
- package/src/contracts/collector/types.ts +0 -16
- package/src/contracts/initialize/transactions.ts +0 -891
- package/src/contracts/leverage/helpers.ts +0 -424
- package/src/contracts/lrp/helpers.ts +0 -294
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/lrp/transactions.ts +0 -250
- package/src/contracts/lrp/types.ts +0 -131
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/vesting/helpers.ts +0 -218
- package/src/utils/value-helpers.ts +0 -37
- package/src/validators/lrp-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1528
- package/tests/gov.test.ts +0 -2011
- package/tests/lrp.test.ts +0 -673
- package/tests/queries/cdp-queries.ts +0 -220
- package/tests/queries/lrp-queries.ts +0 -76
- package/tests/queries/price-oracle-queries.ts +0 -10
|
@@ -1,43 +1,51 @@
|
|
|
1
|
+
import { fromText, LucidEvolution, toHex, UTxO } from '@lucid-evolution/lucid';
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { createScriptAddress } from '../../src/utils/lucid-utils';
|
|
9
|
-
import { AssetClass } from '../../src/types/generic';
|
|
10
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
11
|
-
import { matchSingle } from '../../src';
|
|
3
|
+
fromSystemParamsAsset,
|
|
4
|
+
matchSingle,
|
|
5
|
+
mkStabilityPoolAddr,
|
|
6
|
+
SystemParams,
|
|
7
|
+
} from '../../src';
|
|
12
8
|
import {
|
|
9
|
+
AccountContent,
|
|
13
10
|
parseAccountDatum,
|
|
11
|
+
parseSnapshotEpochToScaleToSumDatum,
|
|
14
12
|
parseStabilityPoolDatum,
|
|
13
|
+
SnapshotEpochToScaleToSumContent,
|
|
14
|
+
StabilityPoolContent,
|
|
15
15
|
} from '../../src/contracts/stability-pool/types-new';
|
|
16
|
+
import { assetClassToUnit } from '@3rd-eye-labs/cardano-offchain-common';
|
|
17
|
+
import { option as O, array as A, function as F } from 'fp-ts';
|
|
16
18
|
|
|
17
19
|
export async function findStabilityPool(
|
|
18
20
|
lucid: LucidEvolution,
|
|
19
|
-
|
|
20
|
-
stabilityPoolToken: AssetClass,
|
|
21
|
+
sysParams: SystemParams,
|
|
21
22
|
asset: string,
|
|
22
|
-
): Promise<UTxO> {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
): Promise<{ utxo: UTxO; datum: StabilityPoolContent }> {
|
|
24
|
+
// We need to consider both with staking credential and without.
|
|
25
|
+
const spUtxos = await lucid.utxosAtWithUnit(
|
|
26
|
+
{ hash: sysParams.validatorHashes.stabilityPoolHash, type: 'Script' },
|
|
27
|
+
assetClassToUnit(
|
|
28
|
+
fromSystemParamsAsset(sysParams.stabilityPoolParams.stabilityPoolToken),
|
|
29
|
+
),
|
|
26
30
|
);
|
|
27
31
|
|
|
28
32
|
return matchSingle(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
F.pipe(
|
|
34
|
+
spUtxos.map((utxo) =>
|
|
35
|
+
F.pipe(
|
|
36
|
+
O.fromNullable(utxo.datum),
|
|
37
|
+
O.flatMap(parseStabilityPoolDatum),
|
|
38
|
+
O.flatMap((datum) => {
|
|
39
|
+
if (toHex(datum.iasset) == fromText(asset)) {
|
|
40
|
+
return O.some({ utxo, datum: datum });
|
|
41
|
+
} else {
|
|
42
|
+
return O.none;
|
|
43
|
+
}
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
),
|
|
47
|
+
A.compact,
|
|
48
|
+
),
|
|
41
49
|
(res) =>
|
|
42
50
|
new Error(
|
|
43
51
|
'Expected a single Stability Pool UTXO.: ' + JSON.stringify(res),
|
|
@@ -47,31 +55,70 @@ export async function findStabilityPool(
|
|
|
47
55
|
|
|
48
56
|
export async function findStabilityPoolAccount(
|
|
49
57
|
lucid: LucidEvolution,
|
|
50
|
-
|
|
58
|
+
sysParams: SystemParams,
|
|
51
59
|
owner: string,
|
|
52
60
|
asset: string,
|
|
53
|
-
): Promise<UTxO> {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
): Promise<{ utxo: UTxO; datum: AccountContent }> {
|
|
62
|
+
// We need to consider both with staking credential and without.
|
|
63
|
+
const spUtxos = await lucid.utxosAt({
|
|
64
|
+
hash: sysParams.validatorHashes.stabilityPoolHash,
|
|
65
|
+
type: 'Script',
|
|
66
|
+
});
|
|
57
67
|
|
|
58
68
|
return matchSingle(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
F.pipe(
|
|
70
|
+
spUtxos.map((utxo) =>
|
|
71
|
+
F.pipe(
|
|
72
|
+
O.fromNullable(utxo.datum),
|
|
73
|
+
O.flatMap(parseAccountDatum),
|
|
74
|
+
O.flatMap((datum) => {
|
|
75
|
+
if (
|
|
76
|
+
toHex(datum.iasset) == fromText(asset) &&
|
|
77
|
+
toHex(datum.owner) == owner
|
|
78
|
+
) {
|
|
79
|
+
return O.some({ utxo, datum: datum });
|
|
80
|
+
} else {
|
|
81
|
+
return O.none;
|
|
82
|
+
}
|
|
83
|
+
}),
|
|
84
|
+
),
|
|
85
|
+
),
|
|
86
|
+
A.compact,
|
|
87
|
+
),
|
|
74
88
|
(res) =>
|
|
75
89
|
new Error('Expected a single Account UTXO.: ' + JSON.stringify(res)),
|
|
76
90
|
);
|
|
77
91
|
}
|
|
92
|
+
|
|
93
|
+
export async function findE2s2sSnapshots(
|
|
94
|
+
lucid: LucidEvolution,
|
|
95
|
+
sysParams: SystemParams,
|
|
96
|
+
asset: string,
|
|
97
|
+
): Promise<{ utxo: UTxO; datum: SnapshotEpochToScaleToSumContent }[]> {
|
|
98
|
+
// No need to query the ones without stake cred, e2s2s will always have stake cred based on script params.
|
|
99
|
+
const spUtxos = await lucid.utxosAtWithUnit(
|
|
100
|
+
mkStabilityPoolAddr(lucid, sysParams),
|
|
101
|
+
assetClassToUnit(
|
|
102
|
+
fromSystemParamsAsset(
|
|
103
|
+
sysParams.stabilityPoolParams.snapshotEpochToScaleToSumToken,
|
|
104
|
+
),
|
|
105
|
+
),
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
return F.pipe(
|
|
109
|
+
spUtxos.map((utxo) =>
|
|
110
|
+
F.pipe(
|
|
111
|
+
O.fromNullable(utxo.datum),
|
|
112
|
+
O.flatMap(parseSnapshotEpochToScaleToSumDatum),
|
|
113
|
+
O.flatMap((datum) => {
|
|
114
|
+
if (toHex(datum.iasset) == fromText(asset)) {
|
|
115
|
+
return O.some({ utxo, datum: datum });
|
|
116
|
+
} else {
|
|
117
|
+
return O.none;
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
A.compact,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -5,14 +5,16 @@ import {
|
|
|
5
5
|
UTxO,
|
|
6
6
|
} from '@lucid-evolution/lucid';
|
|
7
7
|
import { createScriptAddress } from '../../src/utils/lucid-utils';
|
|
8
|
-
import { AssetClass } from '../../src/types/generic';
|
|
9
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
10
8
|
import { matchSingle } from '../../src';
|
|
11
9
|
import { option as O, array as A, function as F } from 'fp-ts';
|
|
12
10
|
import {
|
|
13
11
|
parseStakingPosition,
|
|
14
12
|
StakingPosition,
|
|
15
13
|
} from '../../src/contracts/staking/types-new';
|
|
14
|
+
import {
|
|
15
|
+
AssetClass,
|
|
16
|
+
assetClassToUnit,
|
|
17
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
16
18
|
|
|
17
19
|
export async function findStakingPosition(
|
|
18
20
|
lucid: LucidEvolution,
|
|
@@ -1,13 +1,60 @@
|
|
|
1
|
-
import { LucidEvolution,
|
|
2
|
-
import {
|
|
1
|
+
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
+
import { getRandomElement, SystemParams } from '../../src';
|
|
3
3
|
import { option as O, function as F } from 'fp-ts';
|
|
4
|
+
import {
|
|
5
|
+
AssetClass,
|
|
6
|
+
assetClassToUnit,
|
|
7
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
4
8
|
|
|
5
9
|
export async function findRandomTreasuryUtxo(
|
|
6
10
|
lucid: LucidEvolution,
|
|
7
|
-
|
|
11
|
+
sysParams: SystemParams,
|
|
8
12
|
): Promise<UTxO> {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
// We need to consider both with staking credential and without.
|
|
14
|
+
const treasuryUtxos = await lucid.utxosAt({
|
|
15
|
+
hash: sysParams.validatorHashes.treasuryHash,
|
|
16
|
+
type: 'Script',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return F.pipe(
|
|
20
|
+
O.fromNullable(getRandomElement(treasuryUtxos)),
|
|
21
|
+
O.match(() => {
|
|
22
|
+
throw new Error('Expected some treasury UTXOs.');
|
|
23
|
+
}, F.identity),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function findRandomTreasuryUtxoWithOnlyAda(
|
|
28
|
+
lucid: LucidEvolution,
|
|
29
|
+
sysParams: SystemParams,
|
|
30
|
+
): Promise<UTxO> {
|
|
31
|
+
// We need to consider both with staking credential and without.
|
|
32
|
+
const treasuryUtxos = await lucid.utxosAt({
|
|
33
|
+
hash: sysParams.validatorHashes.treasuryHash,
|
|
34
|
+
type: 'Script',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
38
|
+
(utxo) => Object.keys(utxo.assets).length == 1,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
return F.pipe(
|
|
42
|
+
O.fromNullable(getRandomElement(adaOnlyTreasuryUtxos)),
|
|
43
|
+
O.match(() => {
|
|
44
|
+
throw new Error('Expected some treasury UTXOs.');
|
|
45
|
+
}, F.identity),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function findRandomTreasuryUtxoWithAsset(
|
|
50
|
+
lucid: LucidEvolution,
|
|
51
|
+
sysParams: SystemParams,
|
|
52
|
+
asset: AssetClass,
|
|
53
|
+
): Promise<UTxO> {
|
|
54
|
+
// We need to consider both with staking credential and without.
|
|
55
|
+
const treasuryUtxos = await lucid.utxosAtWithUnit(
|
|
56
|
+
{ hash: sysParams.validatorHashes.treasuryHash, type: 'Script' },
|
|
57
|
+
assetClassToUnit(asset),
|
|
11
58
|
);
|
|
12
59
|
|
|
13
60
|
return F.pipe(
|
|
@@ -17,3 +64,31 @@ export async function findRandomTreasuryUtxo(
|
|
|
17
64
|
}, F.identity),
|
|
18
65
|
);
|
|
19
66
|
}
|
|
67
|
+
|
|
68
|
+
export async function findAllTreasuryUtxos(
|
|
69
|
+
lucid: LucidEvolution,
|
|
70
|
+
sysParams: SystemParams,
|
|
71
|
+
): Promise<UTxO[]> {
|
|
72
|
+
// We need to consider both with staking credential and without.
|
|
73
|
+
return lucid.utxosAt({
|
|
74
|
+
type: 'Script',
|
|
75
|
+
hash: sysParams.validatorHashes.treasuryHash,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function findAllTreasuryUtxosWithNonAdaAsset(
|
|
80
|
+
lucid: LucidEvolution,
|
|
81
|
+
sysParams: SystemParams,
|
|
82
|
+
): Promise<UTxO[]> {
|
|
83
|
+
// We need to consider both with staking credential and without.
|
|
84
|
+
const treasuryUtxos = await lucid.utxosAt({
|
|
85
|
+
hash: sysParams.validatorHashes.treasuryHash,
|
|
86
|
+
type: 'Script',
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
|
|
90
|
+
(utxo) => Object.keys(utxo.assets).length !== 1,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
return treasuryUtxosWithNonAdaAsset;
|
|
94
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { fromText, TxBuilder } from '@lucid-evolution/lucid';
|
|
2
|
+
import { LucidContext } from '../test-helpers';
|
|
3
|
+
import { fromSystemParamsAsset, redeemRob, SystemParams } from '../../src';
|
|
4
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
5
|
+
import { RobOutput } from '../../src/contracts/rob/types-new';
|
|
6
|
+
import { findCollateralAsset, findIAsset } from '../queries/iasset-queries';
|
|
7
|
+
import { findPriceOracleFromCollateralAsset } from '../cdp/cdp-queries';
|
|
8
|
+
|
|
9
|
+
export async function runRedeemRob(
|
|
10
|
+
context: LucidContext,
|
|
11
|
+
sysParams: SystemParams,
|
|
12
|
+
redemptionRobsData: [RobOutput, bigint][],
|
|
13
|
+
iasset: string,
|
|
14
|
+
collateralAsset: AssetClass,
|
|
15
|
+
currentSlot: number,
|
|
16
|
+
pythMessage?: string,
|
|
17
|
+
): Promise<TxBuilder> {
|
|
18
|
+
if (redemptionRobsData.length === 0) throw new Error('No ROBs to redeem');
|
|
19
|
+
|
|
20
|
+
const collateral = await findCollateralAsset(
|
|
21
|
+
context.lucid,
|
|
22
|
+
sysParams,
|
|
23
|
+
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
24
|
+
iasset,
|
|
25
|
+
collateralAsset,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
29
|
+
context.lucid,
|
|
30
|
+
collateral,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const iassetOut = await findIAsset(
|
|
34
|
+
context.lucid,
|
|
35
|
+
sysParams.validatorHashes.iassetHash,
|
|
36
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
|
|
37
|
+
iasset,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const pythStateOutRef = pythMessage
|
|
41
|
+
? await context.lucid.utxoByUnit(
|
|
42
|
+
sysParams.pythConfig.pythStateAssetClass[0].unCurrencySymbol +
|
|
43
|
+
fromText('Pyth State'),
|
|
44
|
+
)
|
|
45
|
+
: undefined;
|
|
46
|
+
|
|
47
|
+
return redeemRob(
|
|
48
|
+
redemptionRobsData.map(([out, amt]) => [out.utxo, amt]),
|
|
49
|
+
priceOracleUtxo,
|
|
50
|
+
iassetOut.utxo,
|
|
51
|
+
collateral.utxo,
|
|
52
|
+
context.lucid,
|
|
53
|
+
sysParams,
|
|
54
|
+
currentSlot,
|
|
55
|
+
pythMessage,
|
|
56
|
+
pythStateOutRef,
|
|
57
|
+
);
|
|
58
|
+
}
|