@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
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LucidEvolution,
|
|
3
|
-
TxBuilder,
|
|
4
|
-
OutRef,
|
|
5
|
-
UTxO,
|
|
6
|
-
addAssets,
|
|
7
|
-
Data,
|
|
8
|
-
fromHex,
|
|
9
|
-
getInputIndices,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import {
|
|
12
|
-
addrDetails,
|
|
13
|
-
createScriptAddress,
|
|
14
|
-
getInlineDatumOrThrow,
|
|
15
|
-
} from '../../utils/lucid-utils';
|
|
16
|
-
import { serialiseCdpDatum } from '../cdp/types-new';
|
|
17
|
-
import { matchSingle } from '../../utils/utils';
|
|
18
|
-
import {
|
|
19
|
-
fromSystemParamsAsset,
|
|
20
|
-
fromSystemParamsScriptRef,
|
|
21
|
-
SystemParams,
|
|
22
|
-
} from '../../types/system-params';
|
|
23
|
-
import { parseInterestOracleDatum } from '../interest-oracle/types-new';
|
|
24
|
-
import {
|
|
25
|
-
serialiseCDPCreatorDatum,
|
|
26
|
-
serialiseCDPCreatorRedeemer,
|
|
27
|
-
} from '../cdp-creator/types-new';
|
|
28
|
-
import { calculateUnitaryInterestSinceOracleLastUpdated } from '../interest-oracle/helpers';
|
|
29
|
-
import {
|
|
30
|
-
approximateLeverageRedemptions,
|
|
31
|
-
summarizeActualLeverageRedemptions,
|
|
32
|
-
calculateLeverageFromCollateralRatio,
|
|
33
|
-
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
34
|
-
} from './helpers';
|
|
35
|
-
|
|
36
|
-
import {
|
|
37
|
-
parseCollateralAssetDatumOrThrow,
|
|
38
|
-
parseIAssetDatumOrThrow,
|
|
39
|
-
} from '../iasset/types';
|
|
40
|
-
import { mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
|
|
41
|
-
import { RobDatum } from '../rob/types-new';
|
|
42
|
-
import { rationalToFloat } from '../../types/rational';
|
|
43
|
-
import {
|
|
44
|
-
buildRedemptionsTx,
|
|
45
|
-
randomRobsSubsetSatisfyingTargetCollateral,
|
|
46
|
-
} from '../rob/helpers';
|
|
47
|
-
import { treasuryFeeTx } from '../treasury/transactions';
|
|
48
|
-
import Decimal from 'decimal.js';
|
|
49
|
-
import { fromDecimal } from '../../utils/bigint-utils';
|
|
50
|
-
import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
|
|
51
|
-
import { retrieveAdjustedPrice } from '../../utils/oracle-helpers';
|
|
52
|
-
import { attachOracle } from '../iasset/helpers';
|
|
53
|
-
import { OracleIdx } from '../price-oracle/types-new';
|
|
54
|
-
|
|
55
|
-
export async function leverageCdpWithRob(
|
|
56
|
-
leverage: number,
|
|
57
|
-
baseCollateral: bigint,
|
|
58
|
-
priceOracleOutRef: OutRef | undefined,
|
|
59
|
-
iassetOutRef: OutRef,
|
|
60
|
-
collateralAssetOutRef: OutRef,
|
|
61
|
-
cdpCreatorOref: OutRef,
|
|
62
|
-
interestOracleOref: OutRef,
|
|
63
|
-
treasuryOref: OutRef,
|
|
64
|
-
sysParams: SystemParams,
|
|
65
|
-
lucid: LucidEvolution,
|
|
66
|
-
allRobs: [UTxO, RobDatum][],
|
|
67
|
-
pythMessage: string | undefined = undefined,
|
|
68
|
-
pythStateOref: OutRef | undefined = undefined,
|
|
69
|
-
): Promise<TxBuilder> {
|
|
70
|
-
const network = lucid.config().network!;
|
|
71
|
-
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
72
|
-
|
|
73
|
-
const [pkh, skh] = await addrDetails(lucid);
|
|
74
|
-
|
|
75
|
-
const robScriptRefUtxo = matchSingle(
|
|
76
|
-
await lucid.utxosByOutRef([
|
|
77
|
-
fromSystemParamsScriptRef(sysParams.scriptReferences.robValidatorRef),
|
|
78
|
-
]),
|
|
79
|
-
(_) => new Error('Expected a single ROB Ref Script UTXO'),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const cdpCreatorRefScriptUtxo = matchSingle(
|
|
83
|
-
await lucid.utxosByOutRef([
|
|
84
|
-
fromSystemParamsScriptRef(
|
|
85
|
-
sysParams.scriptReferences.cdpCreatorValidatorRef,
|
|
86
|
-
),
|
|
87
|
-
]),
|
|
88
|
-
(_) => new Error('Expected a single cdp creator Ref Script UTXO'),
|
|
89
|
-
);
|
|
90
|
-
const cdpAuthTokenPolicyRefScriptUtxo = matchSingle(
|
|
91
|
-
await lucid.utxosByOutRef([
|
|
92
|
-
fromSystemParamsScriptRef(
|
|
93
|
-
sysParams.scriptReferences.authTokenPolicies.cdpAuthTokenRef,
|
|
94
|
-
),
|
|
95
|
-
]),
|
|
96
|
-
(_) => new Error('Expected a single cdp auth token policy Ref Script UTXO'),
|
|
97
|
-
);
|
|
98
|
-
const iAssetTokenPolicyRefScriptUtxo = matchSingle(
|
|
99
|
-
await lucid.utxosByOutRef([
|
|
100
|
-
fromSystemParamsScriptRef(
|
|
101
|
-
sysParams.scriptReferences.iAssetTokenPolicyRef,
|
|
102
|
-
),
|
|
103
|
-
]),
|
|
104
|
-
(_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
const cdpCreatorUtxo = matchSingle(
|
|
108
|
-
await lucid.utxosByOutRef([cdpCreatorOref]),
|
|
109
|
-
(_) => new Error('Expected a single CDP creator UTXO'),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const interestOracleUtxo = matchSingle(
|
|
113
|
-
await lucid.utxosByOutRef([interestOracleOref]),
|
|
114
|
-
(_) => new Error('Expected a single interest oracle UTXO'),
|
|
115
|
-
);
|
|
116
|
-
const interestOracleDatum = parseInterestOracleDatum(
|
|
117
|
-
getInlineDatumOrThrow(interestOracleUtxo),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const iassetUtxo = matchSingle(
|
|
121
|
-
await lucid.utxosByOutRef([iassetOutRef]),
|
|
122
|
-
(_) => new Error('Expected a single IAsset UTXO'),
|
|
123
|
-
);
|
|
124
|
-
const iassetDatum = parseIAssetDatumOrThrow(
|
|
125
|
-
getInlineDatumOrThrow(iassetUtxo),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const collateralAssetUtxo = matchSingle(
|
|
129
|
-
await lucid.utxosByOutRef([collateralAssetOutRef]),
|
|
130
|
-
(_) => new Error('Expected a single collateral asset UTXO'),
|
|
131
|
-
);
|
|
132
|
-
const collateralAssetDatum = parseCollateralAssetDatumOrThrow(
|
|
133
|
-
getInlineDatumOrThrow(collateralAssetUtxo),
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
const [price, _] = await retrieveAdjustedPrice(
|
|
137
|
-
iassetDatum.assetName,
|
|
138
|
-
collateralAssetDatum.collateralAsset,
|
|
139
|
-
collateralAssetDatum.priceInfo,
|
|
140
|
-
collateralAssetDatum.extraDecimals,
|
|
141
|
-
priceOracleOutRef,
|
|
142
|
-
pythMessage,
|
|
143
|
-
sysParams.pythConfig,
|
|
144
|
-
lucid,
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
148
|
-
collateralAssetDatum.iasset,
|
|
149
|
-
collateralAssetDatum.collateralAsset,
|
|
150
|
-
collateralAssetDatum.maintenanceRatio,
|
|
151
|
-
baseCollateral,
|
|
152
|
-
price,
|
|
153
|
-
iassetDatum.debtMintingFeeRatio,
|
|
154
|
-
iassetDatum.redemptionReimbursementRatio,
|
|
155
|
-
allRobs,
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
if (!maxLeverage) {
|
|
159
|
-
throw new Error("Can't calculate max leverage with those parameters.");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const leverageSummary = approximateLeverageRedemptions(
|
|
163
|
-
baseCollateral,
|
|
164
|
-
leverage,
|
|
165
|
-
iassetDatum.redemptionProcessingFeeRatio,
|
|
166
|
-
iassetDatum.debtMintingFeeRatio,
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
if (maxLeverage < leverageSummary.leverage) {
|
|
170
|
-
throw new Error("Can't use more leverage than max.");
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (
|
|
174
|
-
rationalToFloat(leverageSummary.collateralRatio) <
|
|
175
|
-
rationalToFloat(collateralAssetDatum.maintenanceRatio)
|
|
176
|
-
) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
"Can't have collateral ratio smaller than maintenance ratio",
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const redemptionDetails = summarizeActualLeverageRedemptions(
|
|
183
|
-
leverageSummary.redeemedCollateral,
|
|
184
|
-
iassetDatum.redemptionReimbursementRatio,
|
|
185
|
-
price,
|
|
186
|
-
randomRobsSubsetSatisfyingTargetCollateral(
|
|
187
|
-
iassetDatum.assetName,
|
|
188
|
-
collateralAssetDatum.collateralAsset,
|
|
189
|
-
leverageSummary.redeemedCollateral,
|
|
190
|
-
price,
|
|
191
|
-
allRobs,
|
|
192
|
-
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
193
|
-
),
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
// payout / (1 - debtMintingFee) = total minted amount
|
|
197
|
-
const mintedAmt = fromDecimal(
|
|
198
|
-
Decimal(redemptionDetails.totalIAssetPayout)
|
|
199
|
-
.div(
|
|
200
|
-
Decimal(1).minus(
|
|
201
|
-
Decimal(iassetDatum.debtMintingFeeRatio.numerator).div(
|
|
202
|
-
iassetDatum.debtMintingFeeRatio.denominator,
|
|
203
|
-
),
|
|
204
|
-
),
|
|
205
|
-
)
|
|
206
|
-
.floor(),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
const debtMintingFee = calculateFeeFromRatio(
|
|
210
|
-
iassetDatum.debtMintingFeeRatio,
|
|
211
|
-
mintedAmt,
|
|
212
|
-
);
|
|
213
|
-
|
|
214
|
-
const collateralAmt =
|
|
215
|
-
redemptionDetails.totalRedeemedCollateral + baseCollateral;
|
|
216
|
-
|
|
217
|
-
const cdpNftVal = mkAssetsOf(
|
|
218
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
219
|
-
1n,
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const iassetClass = {
|
|
223
|
-
currencySymbol: fromHex(
|
|
224
|
-
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
|
|
225
|
-
),
|
|
226
|
-
tokenName: iassetDatum.assetName,
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const iassetTokensVal = mkAssetsOf(iassetClass, mintedAmt);
|
|
230
|
-
|
|
231
|
-
const refScripts = [
|
|
232
|
-
cdpCreatorRefScriptUtxo,
|
|
233
|
-
cdpAuthTokenPolicyRefScriptUtxo,
|
|
234
|
-
iAssetTokenPolicyRefScriptUtxo,
|
|
235
|
-
robScriptRefUtxo,
|
|
236
|
-
];
|
|
237
|
-
|
|
238
|
-
const tx = lucid
|
|
239
|
-
.newTx()
|
|
240
|
-
// Ref scripts
|
|
241
|
-
.readFrom(refScripts)
|
|
242
|
-
.mintAssets(cdpNftVal, Data.void())
|
|
243
|
-
.mintAssets(iassetTokensVal, Data.void())
|
|
244
|
-
.pay.ToContract(
|
|
245
|
-
createScriptAddress(network, sysParams.validatorHashes.cdpHash, skh),
|
|
246
|
-
{
|
|
247
|
-
kind: 'inline',
|
|
248
|
-
value: serialiseCdpDatum({
|
|
249
|
-
cdpOwner: fromHex(pkh.hash),
|
|
250
|
-
iasset: iassetDatum.assetName,
|
|
251
|
-
collateralAsset: collateralAssetDatum.collateralAsset,
|
|
252
|
-
mintedAmt: mintedAmt,
|
|
253
|
-
cdpFees: {
|
|
254
|
-
ActiveCDPInterestTracking: {
|
|
255
|
-
lastSettled: currentTime,
|
|
256
|
-
unitaryInterestSnapshot:
|
|
257
|
-
calculateUnitaryInterestSinceOracleLastUpdated(
|
|
258
|
-
currentTime,
|
|
259
|
-
interestOracleDatum,
|
|
260
|
-
) + interestOracleDatum.unitaryInterest,
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
}),
|
|
264
|
-
},
|
|
265
|
-
addAssets(
|
|
266
|
-
cdpNftVal,
|
|
267
|
-
mkAssetsOf(collateralAssetDatum.collateralAsset, collateralAmt),
|
|
268
|
-
),
|
|
269
|
-
)
|
|
270
|
-
.pay.ToContract(
|
|
271
|
-
cdpCreatorUtxo.address,
|
|
272
|
-
{
|
|
273
|
-
kind: 'inline',
|
|
274
|
-
value: serialiseCDPCreatorDatum({
|
|
275
|
-
creatorInputOref: {
|
|
276
|
-
outputIndex: BigInt(cdpCreatorUtxo.outputIndex),
|
|
277
|
-
txHash: fromHex(cdpCreatorUtxo.txHash),
|
|
278
|
-
},
|
|
279
|
-
}),
|
|
280
|
-
},
|
|
281
|
-
cdpCreatorUtxo.assets,
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
const treasuryRefScriptUtxo =
|
|
285
|
-
debtMintingFee > 0n
|
|
286
|
-
? await treasuryFeeTx(
|
|
287
|
-
iassetClass,
|
|
288
|
-
debtMintingFee,
|
|
289
|
-
0n,
|
|
290
|
-
lucid,
|
|
291
|
-
sysParams,
|
|
292
|
-
tx,
|
|
293
|
-
cdpCreatorUtxo,
|
|
294
|
-
treasuryOref,
|
|
295
|
-
)
|
|
296
|
-
: undefined;
|
|
297
|
-
|
|
298
|
-
const { interval, referenceInputs: refInputs } = await attachOracle(
|
|
299
|
-
iassetDatum.assetName,
|
|
300
|
-
collateralAssetDatum.collateralAsset,
|
|
301
|
-
collateralAssetDatum.priceInfo,
|
|
302
|
-
priceOracleOutRef,
|
|
303
|
-
pythStateOref,
|
|
304
|
-
pythMessage,
|
|
305
|
-
sysParams.pythConfig,
|
|
306
|
-
sysParams.cdpCreatorParams.biasTime,
|
|
307
|
-
lucid,
|
|
308
|
-
tx,
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
const referenceInputs = [
|
|
312
|
-
interestOracleUtxo,
|
|
313
|
-
iassetUtxo,
|
|
314
|
-
collateralAssetUtxo,
|
|
315
|
-
...refInputs,
|
|
316
|
-
];
|
|
317
|
-
|
|
318
|
-
const refInputsIndices = getInputIndices(referenceInputs, [
|
|
319
|
-
...referenceInputs,
|
|
320
|
-
...refScripts,
|
|
321
|
-
...(treasuryRefScriptUtxo != null ? [treasuryRefScriptUtxo] : []),
|
|
322
|
-
]);
|
|
323
|
-
|
|
324
|
-
const oracleIdx: OracleIdx =
|
|
325
|
-
priceOracleOutRef !== undefined
|
|
326
|
-
? { OracleRefInputIdx: refInputsIndices[3] }
|
|
327
|
-
: 'OracleVoid';
|
|
328
|
-
|
|
329
|
-
tx.validFrom(interval.validFrom)
|
|
330
|
-
.validTo(interval.validTo)
|
|
331
|
-
.readFrom(referenceInputs)
|
|
332
|
-
.collectFrom([cdpCreatorUtxo], {
|
|
333
|
-
kind: 'self',
|
|
334
|
-
makeRedeemer: (inputIdx) => {
|
|
335
|
-
return serialiseCDPCreatorRedeemer({
|
|
336
|
-
CreateCDP: {
|
|
337
|
-
cdpOwner: fromHex(pkh.hash),
|
|
338
|
-
minted: mintedAmt,
|
|
339
|
-
collateralAmt: collateralAmt,
|
|
340
|
-
currentTime: currentTime,
|
|
341
|
-
creatorInputIdx: inputIdx,
|
|
342
|
-
creatorOutputIdx: 1n,
|
|
343
|
-
cdpOutputIdx: 0n,
|
|
344
|
-
iassetRefInputIdx: refInputsIndices[1],
|
|
345
|
-
collateralAssetRefInputIdx: refInputsIndices[2],
|
|
346
|
-
interestOracleRefInputIdx: refInputsIndices[0],
|
|
347
|
-
priceOracleIdx: oracleIdx,
|
|
348
|
-
},
|
|
349
|
-
});
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
buildRedemptionsTx(
|
|
354
|
-
redemptionDetails.redemptions.map((r) => [r.utxo, r.iassetsPayoutAmt]),
|
|
355
|
-
iassetDatum.assetName,
|
|
356
|
-
collateralAssetDatum.collateralAsset,
|
|
357
|
-
price,
|
|
358
|
-
iassetDatum.redemptionReimbursementRatio,
|
|
359
|
-
sysParams,
|
|
360
|
-
tx,
|
|
361
|
-
2n + (debtMintingFee > 0n ? 1n : 0n),
|
|
362
|
-
refInputsIndices[2],
|
|
363
|
-
refInputsIndices[1],
|
|
364
|
-
oracleIdx,
|
|
365
|
-
);
|
|
366
|
-
|
|
367
|
-
return tx;
|
|
368
|
-
}
|