@indigo-labs/indigo-sdk 0.5.4 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +17 -0
- package/dist/index.mjs +15 -0
- package/package.json +11 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/ci.yml +0 -66
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -6
- package/eslint.config.mjs +0 -42
- package/scripts/bench.sh +0 -62
- package/scripts/run-repeat.sh +0 -22
- package/src/contracts/cdp/helpers.ts +0 -173
- package/src/contracts/cdp/scripts.ts +0 -70
- package/src/contracts/cdp/transactions.ts +0 -1584
- package/src/contracts/cdp/types-new.ts +0 -277
- package/src/contracts/cdp/types.ts +0 -43
- package/src/contracts/cdp-creator/queries.ts +0 -30
- package/src/contracts/cdp-creator/scripts.ts +0 -45
- package/src/contracts/cdp-creator/types-new.ts +0 -50
- package/src/contracts/cdp-creator/types.ts +0 -24
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -50
- package/src/contracts/collector/types-new.ts +0 -17
- package/src/contracts/execute/scripts.ts +0 -57
- package/src/contracts/execute/types-new.ts +0 -44
- package/src/contracts/execute/types.ts +0 -24
- package/src/contracts/gov/helpers.ts +0 -351
- package/src/contracts/gov/scripts.ts +0 -41
- package/src/contracts/gov/transactions.ts +0 -1607
- package/src/contracts/gov/types-new.ts +0 -268
- package/src/contracts/gov/types.ts +0 -22
- package/src/contracts/iasset/helpers.ts +0 -170
- package/src/contracts/iasset/queries.ts +0 -102
- package/src/contracts/iasset/scripts.ts +0 -38
- package/src/contracts/iasset/types.ts +0 -154
- package/src/contracts/initialize/actions.ts +0 -789
- package/src/contracts/initialize/helpers.ts +0 -616
- package/src/contracts/initialize/types.ts +0 -116
- package/src/contracts/interest-collection/helpers.ts +0 -19
- package/src/contracts/interest-collection/queries.ts +0 -66
- package/src/contracts/interest-collection/scripts.ts +0 -44
- package/src/contracts/interest-collection/transactions.ts +0 -433
- package/src/contracts/interest-collection/types-new.ts +0 -50
- package/src/contracts/interest-collection/types.ts +0 -26
- package/src/contracts/interest-oracle/helpers.ts +0 -61
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -151
- package/src/contracts/interest-oracle/types-new.ts +0 -32
- package/src/contracts/interest-oracle/types.ts +0 -16
- package/src/contracts/one-shot/scripts.ts +0 -12
- package/src/contracts/one-shot/transactions.ts +0 -66
- package/src/contracts/one-shot/types.ts +0 -22
- package/src/contracts/poll/helpers.ts +0 -37
- package/src/contracts/poll/scripts.ts +0 -71
- package/src/contracts/poll/types-poll-manager.ts +0 -20
- package/src/contracts/poll/types-poll-new.ts +0 -196
- package/src/contracts/poll/types-poll-shard.ts +0 -16
- package/src/contracts/price-oracle/helpers.ts +0 -30
- package/src/contracts/price-oracle/scripts.ts +0 -18
- package/src/contracts/price-oracle/transactions.ts +0 -115
- package/src/contracts/price-oracle/types-new.ts +0 -50
- package/src/contracts/price-oracle/types.ts +0 -16
- package/src/contracts/pyth-feed/helpers.ts +0 -82
- package/src/contracts/pyth-feed/scripts.ts +0 -15
- package/src/contracts/pyth-feed/types.ts +0 -181
- package/src/contracts/rob/helpers.ts +0 -666
- package/src/contracts/rob/scripts.ts +0 -35
- package/src/contracts/rob/transactions.ts +0 -423
- package/src/contracts/rob/types-new.ts +0 -128
- package/src/contracts/rob/types.ts +0 -16
- package/src/contracts/rob-leverage/helpers.ts +0 -422
- package/src/contracts/rob-leverage/transactions.ts +0 -368
- package/src/contracts/stability-pool/helpers.ts +0 -798
- package/src/contracts/stability-pool/queries.ts +0 -132
- package/src/contracts/stability-pool/scripts.ts +0 -51
- package/src/contracts/stability-pool/transactions.ts +0 -921
- package/src/contracts/stability-pool/types-new.ts +0 -385
- package/src/contracts/stability-pool/types.ts +0 -25
- package/src/contracts/stableswap/helpers.ts +0 -507
- package/src/contracts/stableswap/scripts.ts +0 -37
- package/src/contracts/stableswap/transactions.ts +0 -475
- package/src/contracts/stableswap/types-new.ts +0 -131
- package/src/contracts/stableswap/types.ts +0 -17
- package/src/contracts/staking/helpers.ts +0 -136
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -349
- package/src/contracts/staking/types-new.ts +0 -137
- package/src/contracts/staking/types.ts +0 -17
- package/src/contracts/treasury/helpers.ts +0 -21
- package/src/contracts/treasury/queries.ts +0 -100
- package/src/contracts/treasury/scripts.ts +0 -27
- package/src/contracts/treasury/transactions.ts +0 -334
- package/src/contracts/treasury/types-new.ts +0 -69
- package/src/contracts/treasury/types.ts +0 -14
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -18
- package/src/contracts/version-registry/types.ts +0 -17
- package/src/index.ts +0 -93
- package/src/scripts/always-fail-validator.ts +0 -7
- package/src/scripts/auth-token-policy.ts +0 -24
- package/src/scripts/iasset-policy.ts +0 -23
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/types/generic.ts +0 -52
- package/src/types/multisig.ts +0 -48
- package/src/types/on-chain-decimal.ts +0 -57
- package/src/types/rational.ts +0 -61
- package/src/types/system-params.ts +0 -463
- package/src/utils/array-utils.ts +0 -108
- package/src/utils/bigint-utils.ts +0 -35
- package/src/utils/helper-txs.ts +0 -31
- package/src/utils/indigo-helpers.ts +0 -17
- package/src/utils/lucid-utils.ts +0 -125
- package/src/utils/oracle-helpers.ts +0 -62
- package/src/utils/pyth/decode.ts +0 -223
- package/src/utils/pyth/encode.ts +0 -262
- package/src/utils/pyth/index.ts +0 -14
- package/src/utils/pyth/types.ts +0 -87
- package/src/utils/time-helpers.ts +0 -4
- package/src/utils/utils.ts +0 -25
- package/src/validators/always-succeed-validator.ts +0 -6
- package/src/validators/cdp-creator-validator.ts +0 -7
- package/src/validators/cdp-redeem-validator.ts +0 -7
- package/src/validators/cdp-validator.ts +0 -7
- package/src/validators/collector-validator.ts +0 -7
- package/src/validators/execute-validator.ts +0 -7
- package/src/validators/governance-validator.ts +0 -7
- package/src/validators/iasset-validator.ts +0 -7
- package/src/validators/interest-collection-validator.ts +0 -7
- package/src/validators/interest-oracle-validator.ts +0 -7
- package/src/validators/one-shot-policy.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/poll-shard-validator.ts +0 -7
- package/src/validators/price-oracle-validator.ts +0 -7
- package/src/validators/pyth-feed-validator.ts +0 -7
- package/src/validators/rob-validator.ts +0 -7
- package/src/validators/stability-pool-validator.ts +0 -7
- package/src/validators/stableswap-validator.ts +0 -7
- package/src/validators/staking-validator.ts +0 -7
- package/src/validators/treasury-validator.ts +0 -7
- package/src/validators/version-record-policy.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/always-succeed/script.ts +0 -7
- package/tests/array-utils.test.ts +0 -92
- package/tests/bigint-utils.test.ts +0 -41
- package/tests/cdp/actions.ts +0 -680
- package/tests/cdp/cdp-helpers.ts +0 -55
- package/tests/cdp/cdp-queries.ts +0 -423
- package/tests/cdp/cdp.test.ts +0 -6730
- package/tests/cdp/transactions-mutated.ts +0 -1733
- package/tests/data/system-params.json +0 -1155
- package/tests/datums.test.ts +0 -302
- package/tests/endpoints/initialize.ts +0 -78
- package/tests/endpoints/interest-collector.ts +0 -37
- package/tests/endpoints/treasury.ts +0 -70
- package/tests/gov/actions.ts +0 -381
- package/tests/gov/gov.test.ts +0 -5147
- package/tests/gov/governance-queries.ts +0 -37
- package/tests/hash-checks.test.ts +0 -112
- package/tests/indigo-test-helpers.ts +0 -99
- package/tests/initialize.test.ts +0 -79
- package/tests/interest-calculations.test.ts +0 -120
- package/tests/interest-collection/interest-collection.test.ts +0 -843
- package/tests/interest-collection/transactions-mutated.ts +0 -260
- package/tests/interest-oracle.test.ts +0 -93
- package/tests/mock/assets-mock.ts +0 -243
- package/tests/mock/protocol-params-mock.ts +0 -21
- package/tests/price-oracle/actions.ts +0 -161
- package/tests/price-oracle/price-oracle-queries.ts +0 -12
- package/tests/price-oracle/price-oracle.test.ts +0 -228
- package/tests/price-oracle/transactions-mutated.ts +0 -59
- package/tests/pyth/endpoints.ts +0 -96
- package/tests/pyth/helpers.ts +0 -37
- package/tests/pyth/pyth-encoding.test.ts +0 -376
- package/tests/pyth/pyth-feeds.test.ts +0 -943
- package/tests/pyth/pyth-indigo.test.ts +0 -505
- package/tests/pyth/pyth.test.ts +0 -299
- package/tests/queries/collector-queries.ts +0 -27
- package/tests/queries/execute-queries.ts +0 -47
- package/tests/queries/iasset-queries.ts +0 -149
- package/tests/queries/interest-oracle-queries.ts +0 -12
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/staking-queries.ts +0 -54
- package/tests/rob/actions.ts +0 -56
- package/tests/rob/rob-leverage.test.ts +0 -2555
- package/tests/rob/rob-queries.ts +0 -95
- package/tests/rob/rob.test.ts +0 -3677
- package/tests/rob/transactions-mutated.ts +0 -844
- package/tests/script-size.test.ts +0 -240
- package/tests/setup.ts +0 -135
- package/tests/stability-pool/actions.ts +0 -229
- package/tests/stability-pool.test.ts +0 -6491
- package/tests/stableswap/stableswap-actions.ts +0 -83
- package/tests/stableswap/stableswap-queries.ts +0 -98
- package/tests/stableswap/stableswap.test.ts +0 -4471
- package/tests/stableswap/transactions-mutated.ts +0 -348
- package/tests/staking.test.ts +0 -172
- package/tests/test-helpers.ts +0 -94
- package/tests/treasury/actions.ts +0 -67
- package/tests/treasury/treasury.test.ts +0 -320
- package/tests/utils/asserts.ts +0 -87
- package/tests/utils/benchmark-utils.ts +0 -130
- package/tests/utils/index.ts +0 -168
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -27
- package/vitest.config.ts +0 -11
package/tests/cdp/cdp-queries.ts
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Credential,
|
|
3
|
-
fromHex,
|
|
4
|
-
fromText,
|
|
5
|
-
LucidEvolution,
|
|
6
|
-
ScriptHash,
|
|
7
|
-
toHex,
|
|
8
|
-
toText,
|
|
9
|
-
UTxO,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import {
|
|
12
|
-
addrDetails,
|
|
13
|
-
adjustPriceToDecimals,
|
|
14
|
-
cdpCollateralRatioPercentage,
|
|
15
|
-
createScriptAddress,
|
|
16
|
-
findStabilityPool,
|
|
17
|
-
fromSystemParamsAsset,
|
|
18
|
-
matchSingle,
|
|
19
|
-
SystemParams,
|
|
20
|
-
} from '../../src';
|
|
21
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
22
|
-
import {
|
|
23
|
-
CDPContent,
|
|
24
|
-
parseCdpDatum,
|
|
25
|
-
parseStableswapPoolDatum,
|
|
26
|
-
StableswapPoolContent,
|
|
27
|
-
} from '../../src/contracts/cdp/types-new';
|
|
28
|
-
import { match, P } from 'ts-pattern';
|
|
29
|
-
import {
|
|
30
|
-
AssetClass,
|
|
31
|
-
assetClassToUnit,
|
|
32
|
-
getInlineDatumOrThrow,
|
|
33
|
-
getRandomElement,
|
|
34
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
35
|
-
import {
|
|
36
|
-
InterestOracleDatum,
|
|
37
|
-
parseInterestOracleDatum,
|
|
38
|
-
} from '../../src/contracts/interest-oracle/types-new';
|
|
39
|
-
import { findCollateralAsset, findIAsset } from '../queries/iasset-queries';
|
|
40
|
-
import { findPriceOracle } from '../price-oracle/price-oracle-queries';
|
|
41
|
-
import { findInterestOracle } from '../queries/interest-oracle-queries';
|
|
42
|
-
import { findRandomCollector } from '../queries/collector-queries';
|
|
43
|
-
import { findGov } from '../gov/governance-queries';
|
|
44
|
-
import { findRandomTreasuryUtxoWithOnlyAda } from '../../src/contracts/treasury/queries';
|
|
45
|
-
import { parsePriceOracleDatum } from '../../src/contracts/price-oracle/types-new';
|
|
46
|
-
import {
|
|
47
|
-
CollateralAssetOutput,
|
|
48
|
-
IAssetOutput,
|
|
49
|
-
} from '../../src/contracts/iasset/types';
|
|
50
|
-
import { findRandomNonAdminInterestCollector } from '../../src/contracts/interest-collection/queries';
|
|
51
|
-
import { Rational } from '../../src/types/rational';
|
|
52
|
-
|
|
53
|
-
export async function findAllActiveCdps(
|
|
54
|
-
lucid: LucidEvolution,
|
|
55
|
-
sysParams: SystemParams,
|
|
56
|
-
assetAscii: string,
|
|
57
|
-
stakeCred?: Credential,
|
|
58
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }[]> {
|
|
59
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
60
|
-
createScriptAddress(
|
|
61
|
-
lucid.config().network!,
|
|
62
|
-
sysParams.validatorHashes.cdpHash,
|
|
63
|
-
stakeCred,
|
|
64
|
-
),
|
|
65
|
-
assetClassToUnit(fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken)),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return F.pipe(
|
|
69
|
-
cdpUtxos.map((utxo) =>
|
|
70
|
-
F.pipe(
|
|
71
|
-
O.fromNullable(utxo.datum),
|
|
72
|
-
O.flatMap(parseCdpDatum),
|
|
73
|
-
O.flatMap((datum) => {
|
|
74
|
-
if (toHex(datum.iasset) === fromText(assetAscii) && datum.cdpOwner) {
|
|
75
|
-
return O.some({ utxo, datum: datum });
|
|
76
|
-
} else {
|
|
77
|
-
return O.none;
|
|
78
|
-
}
|
|
79
|
-
}),
|
|
80
|
-
),
|
|
81
|
-
),
|
|
82
|
-
A.compact,
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function findCdp(
|
|
87
|
-
lucid: LucidEvolution,
|
|
88
|
-
cdpScriptHash: ScriptHash,
|
|
89
|
-
cdpNft: AssetClass,
|
|
90
|
-
ownerPkh: string,
|
|
91
|
-
stakeCred?: Credential,
|
|
92
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }> {
|
|
93
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
94
|
-
createScriptAddress(lucid.config().network!, cdpScriptHash, stakeCred),
|
|
95
|
-
assetClassToUnit(cdpNft),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return matchSingle(
|
|
99
|
-
F.pipe(
|
|
100
|
-
cdpUtxos.map((utxo) =>
|
|
101
|
-
F.pipe(
|
|
102
|
-
O.fromNullable(utxo.datum),
|
|
103
|
-
O.flatMap(parseCdpDatum),
|
|
104
|
-
O.flatMap((datum) => {
|
|
105
|
-
if (datum.cdpOwner && toHex(datum.cdpOwner) === ownerPkh) {
|
|
106
|
-
return O.some({ utxo, datum: datum });
|
|
107
|
-
} else {
|
|
108
|
-
return O.none;
|
|
109
|
-
}
|
|
110
|
-
}),
|
|
111
|
-
),
|
|
112
|
-
),
|
|
113
|
-
A.compact,
|
|
114
|
-
),
|
|
115
|
-
(res) => new Error('Expected a single CDP UTXO.: ' + JSON.stringify(res)),
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// TODO: use the new variant defined below.
|
|
120
|
-
export async function findOwnCdp(
|
|
121
|
-
lucid: LucidEvolution,
|
|
122
|
-
cdpScriptHash: ScriptHash,
|
|
123
|
-
cdpNft: AssetClass,
|
|
124
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }> {
|
|
125
|
-
const [pkh, skh] = await addrDetails(lucid);
|
|
126
|
-
return findCdp(lucid, cdpScriptHash, cdpNft, pkh.hash, skh);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export async function findOwnCdpNew(
|
|
130
|
-
lucid: LucidEvolution,
|
|
131
|
-
sysParams: SystemParams,
|
|
132
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }> {
|
|
133
|
-
const [pkh, skh] = await addrDetails(lucid);
|
|
134
|
-
return findCdp(
|
|
135
|
-
lucid,
|
|
136
|
-
sysParams.validatorHashes.cdpHash,
|
|
137
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
138
|
-
pkh.hash,
|
|
139
|
-
skh,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function findFrozenCDPs(
|
|
144
|
-
lucid: LucidEvolution,
|
|
145
|
-
cdpScriptHash: ScriptHash,
|
|
146
|
-
cdpNft: AssetClass,
|
|
147
|
-
assetAscii: string,
|
|
148
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }[]> {
|
|
149
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
150
|
-
createScriptAddress(lucid.config().network!, cdpScriptHash),
|
|
151
|
-
assetClassToUnit(cdpNft),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
return F.pipe(
|
|
155
|
-
cdpUtxos.map((utxo) =>
|
|
156
|
-
F.pipe(
|
|
157
|
-
O.fromNullable(utxo.datum),
|
|
158
|
-
O.flatMap(parseCdpDatum),
|
|
159
|
-
O.flatMap((datum) => {
|
|
160
|
-
if (
|
|
161
|
-
datum.cdpOwner == null &&
|
|
162
|
-
toHex(datum.iasset) === fromText(assetAscii)
|
|
163
|
-
) {
|
|
164
|
-
return O.some({ utxo, datum: datum });
|
|
165
|
-
} else {
|
|
166
|
-
return O.none;
|
|
167
|
-
}
|
|
168
|
-
}),
|
|
169
|
-
),
|
|
170
|
-
),
|
|
171
|
-
A.compact,
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export async function findStableswapPool(
|
|
176
|
-
lucid: LucidEvolution,
|
|
177
|
-
cdpScriptHash: ScriptHash,
|
|
178
|
-
cdpNft: AssetClass,
|
|
179
|
-
iassetName: string,
|
|
180
|
-
collateralAsset: AssetClass,
|
|
181
|
-
): Promise<{ utxo: UTxO; datum: StableswapPoolContent }> {
|
|
182
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
183
|
-
createScriptAddress(lucid.config().network!, cdpScriptHash),
|
|
184
|
-
assetClassToUnit(cdpNft),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
return matchSingle(
|
|
188
|
-
F.pipe(
|
|
189
|
-
cdpUtxos.map((utxo) =>
|
|
190
|
-
F.pipe(
|
|
191
|
-
O.fromNullable(utxo.datum),
|
|
192
|
-
O.flatMap(parseStableswapPoolDatum),
|
|
193
|
-
O.flatMap((datum) => {
|
|
194
|
-
if (
|
|
195
|
-
toHex(datum.iasset) === iassetName &&
|
|
196
|
-
toHex(datum.collateralAsset.currencySymbol) ===
|
|
197
|
-
toHex(collateralAsset.currencySymbol) &&
|
|
198
|
-
toHex(datum.collateralAsset.tokenName) ===
|
|
199
|
-
toHex(collateralAsset.tokenName)
|
|
200
|
-
) {
|
|
201
|
-
return O.some({ utxo, datum: datum });
|
|
202
|
-
} else {
|
|
203
|
-
return O.none;
|
|
204
|
-
}
|
|
205
|
-
}),
|
|
206
|
-
),
|
|
207
|
-
),
|
|
208
|
-
A.compact,
|
|
209
|
-
),
|
|
210
|
-
(res) =>
|
|
211
|
-
new Error(
|
|
212
|
-
'Expected a single stableswap pool UTXO.: ' + JSON.stringify(res),
|
|
213
|
-
),
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export async function findAllCdpCreators(
|
|
218
|
-
lucid: LucidEvolution,
|
|
219
|
-
cdpCreatorScriptHash: string,
|
|
220
|
-
cdpCreatorNft: AssetClass,
|
|
221
|
-
): Promise<UTxO[]> {
|
|
222
|
-
return lucid.utxosAtWithUnit(
|
|
223
|
-
createScriptAddress(lucid.config().network!, cdpCreatorScriptHash),
|
|
224
|
-
assetClassToUnit(cdpCreatorNft),
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// TODO: replace by the new variant defined below
|
|
229
|
-
export async function findRandomCdpCreator(
|
|
230
|
-
lucid: LucidEvolution,
|
|
231
|
-
cdpCreatorScriptHash: string,
|
|
232
|
-
cdpCreatorNft: AssetClass,
|
|
233
|
-
): Promise<UTxO> {
|
|
234
|
-
const cdpCreatorUtxos = await findAllCdpCreators(
|
|
235
|
-
lucid,
|
|
236
|
-
cdpCreatorScriptHash,
|
|
237
|
-
cdpCreatorNft,
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
return F.pipe(
|
|
241
|
-
O.fromNullable(getRandomElement(cdpCreatorUtxos)),
|
|
242
|
-
O.match(() => {
|
|
243
|
-
throw new Error('Expected some cdp creator UTXOs.');
|
|
244
|
-
}, F.identity),
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function findPriceOracleFromCollateralAsset(
|
|
249
|
-
lucid: LucidEvolution,
|
|
250
|
-
collateralAsset: CollateralAssetOutput,
|
|
251
|
-
): Promise<UTxO | undefined> {
|
|
252
|
-
return match(collateralAsset.datum.priceInfo)
|
|
253
|
-
.with({ OracleNft: P.select() }, (oracleNft) =>
|
|
254
|
-
findPriceOracle(lucid, oracleNft),
|
|
255
|
-
)
|
|
256
|
-
.with({ Delisted: P.any }, () => {
|
|
257
|
-
throw new Error('Cannot find price oracle as iAsset is delisted');
|
|
258
|
-
})
|
|
259
|
-
.otherwise(() => Promise.resolve(undefined));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export async function findAllNecessaryOrefs(
|
|
263
|
-
lucid: LucidEvolution,
|
|
264
|
-
sysParams: SystemParams,
|
|
265
|
-
iasset: string,
|
|
266
|
-
collateralAsset: AssetClass,
|
|
267
|
-
): Promise<{
|
|
268
|
-
stabilityPoolUtxo: UTxO;
|
|
269
|
-
iasset: IAssetOutput;
|
|
270
|
-
collateralAsset: CollateralAssetOutput;
|
|
271
|
-
cdpCreatorUtxo: UTxO;
|
|
272
|
-
interestOracleUtxo: UTxO;
|
|
273
|
-
collectorUtxo: UTxO;
|
|
274
|
-
interestCollectorUtxo: UTxO;
|
|
275
|
-
govUtxo: UTxO;
|
|
276
|
-
treasuryUtxo: UTxO;
|
|
277
|
-
}> {
|
|
278
|
-
const iassetOut = await findIAsset(
|
|
279
|
-
lucid,
|
|
280
|
-
sysParams.validatorHashes.iassetHash,
|
|
281
|
-
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
|
|
282
|
-
iasset,
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
const collateralAssetOut = await findCollateralAsset(
|
|
286
|
-
lucid,
|
|
287
|
-
sysParams,
|
|
288
|
-
fromSystemParamsAsset(sysParams.cdpCreatorParams.collateralAssetAuthTk),
|
|
289
|
-
iasset,
|
|
290
|
-
collateralAsset,
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
const stabilityPool = await findStabilityPool(
|
|
294
|
-
lucid,
|
|
295
|
-
sysParams,
|
|
296
|
-
fromHex(fromText(iasset)),
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
return {
|
|
300
|
-
stabilityPoolUtxo: stabilityPool.utxo,
|
|
301
|
-
iasset: iassetOut,
|
|
302
|
-
collateralAsset: collateralAssetOut,
|
|
303
|
-
cdpCreatorUtxo: await findRandomCdpCreator(
|
|
304
|
-
lucid,
|
|
305
|
-
sysParams.validatorHashes.cdpCreatorHash,
|
|
306
|
-
fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft),
|
|
307
|
-
),
|
|
308
|
-
interestOracleUtxo: await findInterestOracle(
|
|
309
|
-
lucid,
|
|
310
|
-
collateralAssetOut.datum.interestOracleNft,
|
|
311
|
-
),
|
|
312
|
-
collectorUtxo: await findRandomCollector(
|
|
313
|
-
lucid,
|
|
314
|
-
sysParams.validatorHashes.collectorHash,
|
|
315
|
-
),
|
|
316
|
-
interestCollectorUtxo: await findRandomNonAdminInterestCollector(
|
|
317
|
-
lucid,
|
|
318
|
-
sysParams,
|
|
319
|
-
),
|
|
320
|
-
govUtxo: (
|
|
321
|
-
await findGov(
|
|
322
|
-
lucid,
|
|
323
|
-
sysParams.validatorHashes.govHash,
|
|
324
|
-
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
325
|
-
)
|
|
326
|
-
).utxo,
|
|
327
|
-
treasuryUtxo: await findRandomTreasuryUtxoWithOnlyAda(lucid, sysParams),
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export async function findPrice(
|
|
332
|
-
lucid: LucidEvolution,
|
|
333
|
-
sysParams: SystemParams,
|
|
334
|
-
asset: string,
|
|
335
|
-
collateralAsset: AssetClass,
|
|
336
|
-
): Promise<Rational> {
|
|
337
|
-
const orefs = await findAllNecessaryOrefs(
|
|
338
|
-
lucid,
|
|
339
|
-
sysParams,
|
|
340
|
-
asset,
|
|
341
|
-
collateralAsset,
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
const priceIasset = await match(orefs.collateralAsset.datum.priceInfo)
|
|
345
|
-
.with({ OracleNft: P.select() }, async (oracleNft) => {
|
|
346
|
-
const priceOracleUtxo = matchSingle(
|
|
347
|
-
await lucid.utxosByOutRef([await findPriceOracle(lucid, oracleNft)]),
|
|
348
|
-
(_) => new Error('Expected a single price oracle UTXO'),
|
|
349
|
-
);
|
|
350
|
-
return parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo))
|
|
351
|
-
.price;
|
|
352
|
-
})
|
|
353
|
-
.with({ Delisted: P.select() }, (price) => {
|
|
354
|
-
return price.price;
|
|
355
|
-
})
|
|
356
|
-
.with({ DeferredValidation: P.select() }, (_) => {
|
|
357
|
-
throw new Error('Pyth price not implemented');
|
|
358
|
-
})
|
|
359
|
-
.exhaustive();
|
|
360
|
-
|
|
361
|
-
return priceIasset;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export async function findInterestDatum(
|
|
365
|
-
lucid: LucidEvolution,
|
|
366
|
-
sysParams: SystemParams,
|
|
367
|
-
asset: string,
|
|
368
|
-
collateralAsset: AssetClass,
|
|
369
|
-
): Promise<InterestOracleDatum> {
|
|
370
|
-
const orefs = await findAllNecessaryOrefs(
|
|
371
|
-
lucid,
|
|
372
|
-
sysParams,
|
|
373
|
-
asset,
|
|
374
|
-
collateralAsset,
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
const interestOracleUtxo = matchSingle(
|
|
378
|
-
await lucid.utxosByOutRef([orefs.interestOracleUtxo]),
|
|
379
|
-
(_) => new Error('Expected a single interest oracle UTXO'),
|
|
380
|
-
);
|
|
381
|
-
return parseInterestOracleDatum(getInlineDatumOrThrow(interestOracleUtxo));
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export async function findCdpCR(
|
|
385
|
-
lucid: LucidEvolution,
|
|
386
|
-
sysParams: SystemParams,
|
|
387
|
-
cdp: { utxo: UTxO; datum: CDPContent },
|
|
388
|
-
): Promise<number> {
|
|
389
|
-
const iassetAscii = toText(toHex(cdp.datum.iasset));
|
|
390
|
-
|
|
391
|
-
const collateralAsset = await findCollateralAsset(
|
|
392
|
-
lucid,
|
|
393
|
-
sysParams,
|
|
394
|
-
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
395
|
-
iassetAscii,
|
|
396
|
-
cdp.datum.collateralAsset,
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
const price = await findPrice(
|
|
400
|
-
lucid,
|
|
401
|
-
sysParams,
|
|
402
|
-
iassetAscii,
|
|
403
|
-
cdp.datum.collateralAsset,
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
const adjustedPrice = adjustPriceToDecimals(
|
|
407
|
-
collateralAsset.datum.extraDecimals,
|
|
408
|
-
price,
|
|
409
|
-
);
|
|
410
|
-
|
|
411
|
-
return cdpCollateralRatioPercentage(
|
|
412
|
-
BigInt(lucid.slotToUnixTime(lucid.currentSlot())),
|
|
413
|
-
adjustedPrice,
|
|
414
|
-
cdp.utxo.assets,
|
|
415
|
-
cdp.datum,
|
|
416
|
-
await findInterestDatum(
|
|
417
|
-
lucid,
|
|
418
|
-
sysParams,
|
|
419
|
-
iassetAscii,
|
|
420
|
-
cdp.datum.collateralAsset,
|
|
421
|
-
),
|
|
422
|
-
);
|
|
423
|
-
}
|