@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/actions.ts
DELETED
|
@@ -1,680 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TxBuilder,
|
|
3
|
-
Credential,
|
|
4
|
-
stakeCredentialOf,
|
|
5
|
-
toHex,
|
|
6
|
-
UTxO,
|
|
7
|
-
toText,
|
|
8
|
-
fromText,
|
|
9
|
-
Assets,
|
|
10
|
-
addAssets,
|
|
11
|
-
fromHex,
|
|
12
|
-
} from '@lucid-evolution/lucid';
|
|
13
|
-
import {
|
|
14
|
-
addrDetails,
|
|
15
|
-
burnCdp,
|
|
16
|
-
closeCdp,
|
|
17
|
-
depositCdp,
|
|
18
|
-
freezeCdp,
|
|
19
|
-
fromSystemParamsAsset,
|
|
20
|
-
liquidateCdp,
|
|
21
|
-
mintCdp,
|
|
22
|
-
mkTreasuryAddr,
|
|
23
|
-
openCdp,
|
|
24
|
-
redeemCdp,
|
|
25
|
-
SystemParams,
|
|
26
|
-
withdrawCdp,
|
|
27
|
-
} from '../../src';
|
|
28
|
-
import {
|
|
29
|
-
findAllActiveCdps,
|
|
30
|
-
findAllNecessaryOrefs,
|
|
31
|
-
findCdp,
|
|
32
|
-
findFrozenCDPs,
|
|
33
|
-
findPrice,
|
|
34
|
-
findPriceOracleFromCollateralAsset,
|
|
35
|
-
} from './cdp-queries';
|
|
36
|
-
import {
|
|
37
|
-
LucidContext,
|
|
38
|
-
repeat,
|
|
39
|
-
runAndAwaitTx,
|
|
40
|
-
runAndAwaitTxBuilder,
|
|
41
|
-
} from '../test-helpers';
|
|
42
|
-
import { AssetInfo } from '../endpoints/initialize';
|
|
43
|
-
import { assert, expect } from 'vitest';
|
|
44
|
-
import { feedPriceOracleTx } from '../../src/contracts/price-oracle/transactions';
|
|
45
|
-
import {
|
|
46
|
-
adaAssetClass,
|
|
47
|
-
AssetClass,
|
|
48
|
-
assetClassToUnit,
|
|
49
|
-
assetClassValueOf,
|
|
50
|
-
getInlineDatumOrThrow,
|
|
51
|
-
matchSingle,
|
|
52
|
-
mkAssetsOf,
|
|
53
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
54
|
-
import { parseCdpDatumOrThrow } from '../../src/contracts/cdp/types-new';
|
|
55
|
-
import { match, P } from 'ts-pattern';
|
|
56
|
-
import { findPriceOracle } from '../price-oracle/price-oracle-queries';
|
|
57
|
-
import { findCollateralAsset } from '../queries/iasset-queries';
|
|
58
|
-
import { runFeedPriceToOracle } from '../price-oracle/actions';
|
|
59
|
-
import { rationalFromInt, rationalMul } from '../../src/types/rational';
|
|
60
|
-
import { array as A } from 'fp-ts';
|
|
61
|
-
import { sendValueTo } from '../utils';
|
|
62
|
-
import { findRandomTreasuryUtxoWithAsset } from '../../src/contracts/treasury/queries';
|
|
63
|
-
|
|
64
|
-
// Selects users wallet and opens a CDP with the given initial collateral and mint amount
|
|
65
|
-
export async function runOpenCdp(
|
|
66
|
-
context: LucidContext,
|
|
67
|
-
sysParams: SystemParams,
|
|
68
|
-
asset: string,
|
|
69
|
-
collateralAsset: AssetClass,
|
|
70
|
-
initialCollateral: bigint,
|
|
71
|
-
initialMint: bigint,
|
|
72
|
-
pythMessage?: string,
|
|
73
|
-
directTreasuryPayment: boolean = false,
|
|
74
|
-
): Promise<TxBuilder> {
|
|
75
|
-
const orefs = await findAllNecessaryOrefs(
|
|
76
|
-
context.lucid,
|
|
77
|
-
sysParams,
|
|
78
|
-
asset,
|
|
79
|
-
collateralAsset,
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
83
|
-
context.lucid,
|
|
84
|
-
orefs.collateralAsset,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const pythStateOref = pythMessage
|
|
88
|
-
? await context.lucid.utxoByUnit(
|
|
89
|
-
assetClassToUnit(
|
|
90
|
-
fromSystemParamsAsset(sysParams.pythConfig.pythStateAssetClass),
|
|
91
|
-
),
|
|
92
|
-
)
|
|
93
|
-
: undefined;
|
|
94
|
-
|
|
95
|
-
return openCdp(
|
|
96
|
-
initialCollateral,
|
|
97
|
-
initialMint,
|
|
98
|
-
sysParams,
|
|
99
|
-
orefs.cdpCreatorUtxo,
|
|
100
|
-
orefs.iasset.utxo,
|
|
101
|
-
orefs.collateralAsset.utxo,
|
|
102
|
-
priceOracleUtxo,
|
|
103
|
-
orefs.interestOracleUtxo,
|
|
104
|
-
directTreasuryPayment ? undefined : orefs.treasuryUtxo,
|
|
105
|
-
context.lucid,
|
|
106
|
-
pythMessage,
|
|
107
|
-
pythStateOref,
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export async function runDepositCdp(
|
|
112
|
-
context: LucidContext,
|
|
113
|
-
sysParams: SystemParams,
|
|
114
|
-
asset: string,
|
|
115
|
-
collateralAsset: AssetClass,
|
|
116
|
-
amount: bigint = 1_000_000n,
|
|
117
|
-
): Promise<TxBuilder> {
|
|
118
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
119
|
-
|
|
120
|
-
const cdp = await findCdp(
|
|
121
|
-
context.lucid,
|
|
122
|
-
sysParams.validatorHashes.cdpHash,
|
|
123
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
124
|
-
pkh.hash,
|
|
125
|
-
skh,
|
|
126
|
-
);
|
|
127
|
-
const orefs = await findAllNecessaryOrefs(
|
|
128
|
-
context.lucid,
|
|
129
|
-
sysParams,
|
|
130
|
-
asset,
|
|
131
|
-
collateralAsset,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
return await depositCdp(
|
|
135
|
-
amount,
|
|
136
|
-
cdp.utxo,
|
|
137
|
-
orefs.iasset.utxo,
|
|
138
|
-
orefs.collateralAsset.utxo,
|
|
139
|
-
orefs.interestOracleUtxo,
|
|
140
|
-
orefs.treasuryUtxo,
|
|
141
|
-
orefs.interestCollectorUtxo,
|
|
142
|
-
sysParams,
|
|
143
|
-
context.lucid,
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export async function runWithdrawCdp(
|
|
148
|
-
context: LucidContext,
|
|
149
|
-
sysParams: SystemParams,
|
|
150
|
-
asset: string,
|
|
151
|
-
collateralAsset: AssetClass,
|
|
152
|
-
amount: bigint = 1_000_000n,
|
|
153
|
-
pythMessage?: string,
|
|
154
|
-
): Promise<TxBuilder> {
|
|
155
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
156
|
-
|
|
157
|
-
const cdp = await findCdp(
|
|
158
|
-
context.lucid,
|
|
159
|
-
sysParams.validatorHashes.cdpHash,
|
|
160
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
161
|
-
pkh.hash,
|
|
162
|
-
skh,
|
|
163
|
-
);
|
|
164
|
-
const orefs = await findAllNecessaryOrefs(
|
|
165
|
-
context.lucid,
|
|
166
|
-
sysParams,
|
|
167
|
-
asset,
|
|
168
|
-
collateralAsset,
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
const priceOracleUtxo = await match(orefs.collateralAsset.datum.priceInfo)
|
|
172
|
-
.with({ OracleNft: P.select() }, (oracleNft) =>
|
|
173
|
-
findPriceOracle(context.lucid, oracleNft),
|
|
174
|
-
)
|
|
175
|
-
.otherwise(() => undefined);
|
|
176
|
-
|
|
177
|
-
const pythStateOref = pythMessage
|
|
178
|
-
? await context.lucid.utxoByUnit(
|
|
179
|
-
sysParams.pythConfig.pythStateAssetClass[0].unCurrencySymbol +
|
|
180
|
-
fromText('Pyth State'),
|
|
181
|
-
)
|
|
182
|
-
: undefined;
|
|
183
|
-
|
|
184
|
-
return await withdrawCdp(
|
|
185
|
-
amount,
|
|
186
|
-
cdp.utxo,
|
|
187
|
-
orefs.iasset.utxo,
|
|
188
|
-
orefs.collateralAsset.utxo,
|
|
189
|
-
priceOracleUtxo,
|
|
190
|
-
orefs.interestOracleUtxo,
|
|
191
|
-
orefs.treasuryUtxo,
|
|
192
|
-
orefs.interestCollectorUtxo,
|
|
193
|
-
sysParams,
|
|
194
|
-
context.lucid,
|
|
195
|
-
pythMessage,
|
|
196
|
-
pythStateOref,
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export async function runMintCdp(
|
|
201
|
-
context: LucidContext,
|
|
202
|
-
sysParams: SystemParams,
|
|
203
|
-
asset: string,
|
|
204
|
-
collateralAsset: AssetClass,
|
|
205
|
-
amount: bigint = 100_000n,
|
|
206
|
-
pythMessage?: string,
|
|
207
|
-
directTreasuryPayment: boolean = false,
|
|
208
|
-
): Promise<TxBuilder> {
|
|
209
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
210
|
-
|
|
211
|
-
const cdp = await findCdp(
|
|
212
|
-
context.lucid,
|
|
213
|
-
sysParams.validatorHashes.cdpHash,
|
|
214
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
215
|
-
pkh.hash,
|
|
216
|
-
skh,
|
|
217
|
-
);
|
|
218
|
-
const orefs = await findAllNecessaryOrefs(
|
|
219
|
-
context.lucid,
|
|
220
|
-
sysParams,
|
|
221
|
-
asset,
|
|
222
|
-
collateralAsset,
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
const priceOracleUtxo = await match(orefs.collateralAsset.datum.priceInfo)
|
|
226
|
-
.with({ OracleNft: P.select() }, (oracleNft) =>
|
|
227
|
-
findPriceOracle(context.lucid, oracleNft),
|
|
228
|
-
)
|
|
229
|
-
.otherwise(() => undefined);
|
|
230
|
-
|
|
231
|
-
const pythStateOref = pythMessage
|
|
232
|
-
? await context.lucid.utxoByUnit(
|
|
233
|
-
sysParams.pythConfig.pythStateAssetClass[0].unCurrencySymbol +
|
|
234
|
-
fromText('Pyth State'),
|
|
235
|
-
)
|
|
236
|
-
: undefined;
|
|
237
|
-
|
|
238
|
-
return await mintCdp(
|
|
239
|
-
amount,
|
|
240
|
-
cdp.utxo,
|
|
241
|
-
orefs.iasset.utxo,
|
|
242
|
-
orefs.collateralAsset.utxo,
|
|
243
|
-
priceOracleUtxo,
|
|
244
|
-
orefs.interestOracleUtxo,
|
|
245
|
-
directTreasuryPayment ? undefined : orefs.treasuryUtxo,
|
|
246
|
-
orefs.interestCollectorUtxo,
|
|
247
|
-
sysParams,
|
|
248
|
-
context.lucid,
|
|
249
|
-
pythMessage,
|
|
250
|
-
pythStateOref,
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export async function runBurnCdp(
|
|
255
|
-
context: LucidContext,
|
|
256
|
-
sysParams: SystemParams,
|
|
257
|
-
asset: string,
|
|
258
|
-
collateralAsset: AssetClass,
|
|
259
|
-
amount: bigint = 100_000n,
|
|
260
|
-
): Promise<TxBuilder> {
|
|
261
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
262
|
-
|
|
263
|
-
const cdp = await findCdp(
|
|
264
|
-
context.lucid,
|
|
265
|
-
sysParams.validatorHashes.cdpHash,
|
|
266
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
267
|
-
pkh.hash,
|
|
268
|
-
skh,
|
|
269
|
-
);
|
|
270
|
-
const orefs = await findAllNecessaryOrefs(
|
|
271
|
-
context.lucid,
|
|
272
|
-
sysParams,
|
|
273
|
-
asset,
|
|
274
|
-
collateralAsset,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
return await burnCdp(
|
|
278
|
-
amount,
|
|
279
|
-
cdp.utxo,
|
|
280
|
-
orefs.iasset.utxo,
|
|
281
|
-
orefs.collateralAsset.utxo,
|
|
282
|
-
orefs.interestOracleUtxo,
|
|
283
|
-
orefs.treasuryUtxo,
|
|
284
|
-
orefs.interestCollectorUtxo,
|
|
285
|
-
sysParams,
|
|
286
|
-
context.lucid,
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export async function runCloseCdp(
|
|
291
|
-
context: LucidContext,
|
|
292
|
-
sysParams: SystemParams,
|
|
293
|
-
asset: string,
|
|
294
|
-
collateralAsset: AssetClass,
|
|
295
|
-
): Promise<TxBuilder> {
|
|
296
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
297
|
-
|
|
298
|
-
const cdp = await findCdp(
|
|
299
|
-
context.lucid,
|
|
300
|
-
sysParams.validatorHashes.cdpHash,
|
|
301
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
302
|
-
pkh.hash,
|
|
303
|
-
skh,
|
|
304
|
-
);
|
|
305
|
-
const orefs = await findAllNecessaryOrefs(
|
|
306
|
-
context.lucid,
|
|
307
|
-
sysParams,
|
|
308
|
-
asset,
|
|
309
|
-
collateralAsset,
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
return await closeCdp(
|
|
313
|
-
cdp.utxo,
|
|
314
|
-
orefs.collateralAsset.utxo,
|
|
315
|
-
orefs.interestOracleUtxo,
|
|
316
|
-
orefs.interestCollectorUtxo,
|
|
317
|
-
sysParams,
|
|
318
|
-
context.lucid,
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export async function runRedeemCdp(
|
|
323
|
-
context: LucidContext,
|
|
324
|
-
sysParams: SystemParams,
|
|
325
|
-
iusdAssetInfo: AssetInfo,
|
|
326
|
-
collateralAsset: AssetClass,
|
|
327
|
-
pkh: string,
|
|
328
|
-
skh: Credential | undefined,
|
|
329
|
-
directTreasuryPayment: boolean = false,
|
|
330
|
-
): Promise<TxBuilder> {
|
|
331
|
-
const cdp = await findCdp(
|
|
332
|
-
context.lucid,
|
|
333
|
-
sysParams.validatorHashes.cdpHash,
|
|
334
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
335
|
-
pkh,
|
|
336
|
-
skh,
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
const orefs = await findAllNecessaryOrefs(
|
|
340
|
-
context.lucid,
|
|
341
|
-
sysParams,
|
|
342
|
-
iusdAssetInfo.iassetTokenNameAscii,
|
|
343
|
-
collateralAsset,
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
const priceOracleUtxo = await match(orefs.collateralAsset.datum.priceInfo)
|
|
347
|
-
.with({ OracleNft: P.select() }, (oracleNft) =>
|
|
348
|
-
findPriceOracle(context.lucid, oracleNft),
|
|
349
|
-
)
|
|
350
|
-
.otherwise(() => undefined);
|
|
351
|
-
|
|
352
|
-
return await redeemCdp(
|
|
353
|
-
cdp.datum.mintedAmt,
|
|
354
|
-
cdp.utxo,
|
|
355
|
-
orefs.iasset.utxo,
|
|
356
|
-
orefs.collateralAsset.utxo,
|
|
357
|
-
priceOracleUtxo,
|
|
358
|
-
orefs.interestOracleUtxo,
|
|
359
|
-
orefs.interestCollectorUtxo,
|
|
360
|
-
directTreasuryPayment ? undefined : orefs.treasuryUtxo,
|
|
361
|
-
orefs.govUtxo,
|
|
362
|
-
sysParams,
|
|
363
|
-
context.lucid,
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
export async function runFreezeCdp(
|
|
368
|
-
context: LucidContext,
|
|
369
|
-
sysParams: SystemParams,
|
|
370
|
-
asset: string,
|
|
371
|
-
collateralAsset: AssetClass,
|
|
372
|
-
pkh: string,
|
|
373
|
-
skh: Credential | undefined,
|
|
374
|
-
pythMessage?: string,
|
|
375
|
-
): Promise<TxBuilder> {
|
|
376
|
-
const cdp = await findCdp(
|
|
377
|
-
context.lucid,
|
|
378
|
-
sysParams.validatorHashes.cdpHash,
|
|
379
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
380
|
-
pkh,
|
|
381
|
-
skh,
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
const orefs = await findAllNecessaryOrefs(
|
|
385
|
-
context.lucid,
|
|
386
|
-
sysParams,
|
|
387
|
-
asset,
|
|
388
|
-
collateralAsset,
|
|
389
|
-
);
|
|
390
|
-
|
|
391
|
-
const priceOracleUtxo = await match(orefs.collateralAsset.datum.priceInfo)
|
|
392
|
-
.with({ OracleNft: P.select() }, (oracleNft) =>
|
|
393
|
-
findPriceOracle(context.lucid, oracleNft),
|
|
394
|
-
)
|
|
395
|
-
.otherwise(() => undefined);
|
|
396
|
-
|
|
397
|
-
const pythStateOref = pythMessage
|
|
398
|
-
? await context.lucid.utxoByUnit(
|
|
399
|
-
sysParams.pythConfig.pythStateAssetClass[0].unCurrencySymbol +
|
|
400
|
-
fromText('Pyth State'),
|
|
401
|
-
)
|
|
402
|
-
: undefined;
|
|
403
|
-
return freezeCdp(
|
|
404
|
-
cdp.utxo,
|
|
405
|
-
orefs.iasset.utxo,
|
|
406
|
-
orefs.collateralAsset.utxo,
|
|
407
|
-
priceOracleUtxo,
|
|
408
|
-
orefs.interestOracleUtxo,
|
|
409
|
-
sysParams,
|
|
410
|
-
context.lucid,
|
|
411
|
-
pythMessage,
|
|
412
|
-
pythStateOref,
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export async function runCreateAndFreezeCdps(
|
|
417
|
-
context: LucidContext,
|
|
418
|
-
sysParams: SystemParams,
|
|
419
|
-
assetInfo: AssetInfo,
|
|
420
|
-
numberOfCdps: number,
|
|
421
|
-
iasset: string,
|
|
422
|
-
collateralAsset: AssetClass,
|
|
423
|
-
): Promise<void> {
|
|
424
|
-
const collateralAssetOutput = await findCollateralAsset(
|
|
425
|
-
context.lucid,
|
|
426
|
-
sysParams,
|
|
427
|
-
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
428
|
-
iasset,
|
|
429
|
-
collateralAsset,
|
|
430
|
-
);
|
|
431
|
-
|
|
432
|
-
let priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
433
|
-
context.lucid,
|
|
434
|
-
collateralAssetOutput,
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
await repeat(numberOfCdps, async () => {
|
|
438
|
-
const orefs = await findAllNecessaryOrefs(
|
|
439
|
-
context.lucid,
|
|
440
|
-
sysParams,
|
|
441
|
-
iasset,
|
|
442
|
-
collateralAsset,
|
|
443
|
-
);
|
|
444
|
-
|
|
445
|
-
await runAndAwaitTx(
|
|
446
|
-
context.lucid,
|
|
447
|
-
openCdp(
|
|
448
|
-
12_000_000n,
|
|
449
|
-
6_000_000n,
|
|
450
|
-
sysParams,
|
|
451
|
-
orefs.cdpCreatorUtxo,
|
|
452
|
-
orefs.iasset.utxo,
|
|
453
|
-
orefs.collateralAsset.utxo,
|
|
454
|
-
priceOracleUtxo,
|
|
455
|
-
orefs.interestOracleUtxo,
|
|
456
|
-
orefs.treasuryUtxo,
|
|
457
|
-
context.lucid,
|
|
458
|
-
),
|
|
459
|
-
);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
await runAndAwaitTx(
|
|
463
|
-
context.lucid,
|
|
464
|
-
feedPriceOracleTx(
|
|
465
|
-
context.lucid,
|
|
466
|
-
priceOracleUtxo!,
|
|
467
|
-
{ numerator: 18n, denominator: 10n }, // 1.8
|
|
468
|
-
assetInfo.collateralAssets[0].oracleParams!,
|
|
469
|
-
),
|
|
470
|
-
);
|
|
471
|
-
|
|
472
|
-
priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
473
|
-
context.lucid,
|
|
474
|
-
collateralAssetOutput,
|
|
475
|
-
);
|
|
476
|
-
|
|
477
|
-
{
|
|
478
|
-
const activeCdps = await findAllActiveCdps(
|
|
479
|
-
context.lucid,
|
|
480
|
-
sysParams,
|
|
481
|
-
iasset,
|
|
482
|
-
stakeCredentialOf(context.users.admin.address),
|
|
483
|
-
);
|
|
484
|
-
|
|
485
|
-
expect(
|
|
486
|
-
activeCdps.length === numberOfCdps,
|
|
487
|
-
`Expected ${numberOfCdps} cdps`,
|
|
488
|
-
).toBeTruthy();
|
|
489
|
-
|
|
490
|
-
for (const cdp of activeCdps) {
|
|
491
|
-
const orefs = await findAllNecessaryOrefs(
|
|
492
|
-
context.lucid,
|
|
493
|
-
sysParams,
|
|
494
|
-
iasset,
|
|
495
|
-
collateralAsset,
|
|
496
|
-
);
|
|
497
|
-
|
|
498
|
-
await runAndAwaitTx(
|
|
499
|
-
context.lucid,
|
|
500
|
-
freezeCdp(
|
|
501
|
-
cdp.utxo,
|
|
502
|
-
orefs.iasset.utxo,
|
|
503
|
-
orefs.collateralAsset.utxo,
|
|
504
|
-
priceOracleUtxo,
|
|
505
|
-
orefs.interestOracleUtxo,
|
|
506
|
-
sysParams,
|
|
507
|
-
context.lucid,
|
|
508
|
-
),
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
export async function runLiquidateCdp(
|
|
515
|
-
context: LucidContext,
|
|
516
|
-
sysParams: SystemParams,
|
|
517
|
-
frozenCdpUtxo: UTxO,
|
|
518
|
-
treasuryUtxo?: UTxO,
|
|
519
|
-
directTreasuryPayment: boolean = false,
|
|
520
|
-
): Promise<TxBuilder> {
|
|
521
|
-
const cdpDatum = parseCdpDatumOrThrow(getInlineDatumOrThrow(frozenCdpUtxo));
|
|
522
|
-
const orefs = await findAllNecessaryOrefs(
|
|
523
|
-
context.lucid,
|
|
524
|
-
sysParams,
|
|
525
|
-
toText(toHex(cdpDatum.iasset)),
|
|
526
|
-
cdpDatum.collateralAsset,
|
|
527
|
-
);
|
|
528
|
-
return liquidateCdp(
|
|
529
|
-
frozenCdpUtxo,
|
|
530
|
-
orefs.stabilityPoolUtxo,
|
|
531
|
-
orefs.interestCollectorUtxo,
|
|
532
|
-
directTreasuryPayment
|
|
533
|
-
? undefined
|
|
534
|
-
: treasuryUtxo
|
|
535
|
-
? treasuryUtxo
|
|
536
|
-
: orefs.treasuryUtxo,
|
|
537
|
-
sysParams,
|
|
538
|
-
context.lucid,
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Expecting price double will make CDP liquidatable.
|
|
544
|
-
*/
|
|
545
|
-
export async function executeLiquidation(
|
|
546
|
-
context: LucidContext,
|
|
547
|
-
sysParams: SystemParams,
|
|
548
|
-
liquidatedDebt: bigint,
|
|
549
|
-
liquidatedCollateral: bigint,
|
|
550
|
-
collateralAsset: AssetClass,
|
|
551
|
-
assetInfo: AssetInfo,
|
|
552
|
-
liquidateWrapper: (liquidateTx: TxBuilder) => Promise<void> = async (tx) => {
|
|
553
|
-
await runAndAwaitTxBuilder(context.lucid, tx);
|
|
554
|
-
},
|
|
555
|
-
directTreasuryPayment: boolean = false,
|
|
556
|
-
) {
|
|
557
|
-
const price = await findPrice(
|
|
558
|
-
context.lucid,
|
|
559
|
-
sysParams,
|
|
560
|
-
assetInfo.iassetTokenNameAscii,
|
|
561
|
-
collateralAsset,
|
|
562
|
-
);
|
|
563
|
-
|
|
564
|
-
const [pkh, skh] = await addrDetails(context.lucid);
|
|
565
|
-
|
|
566
|
-
await runAndAwaitTx(
|
|
567
|
-
context.lucid,
|
|
568
|
-
runOpenCdp(
|
|
569
|
-
context,
|
|
570
|
-
sysParams,
|
|
571
|
-
assetInfo.iassetTokenNameAscii,
|
|
572
|
-
collateralAsset,
|
|
573
|
-
liquidatedCollateral,
|
|
574
|
-
liquidatedDebt,
|
|
575
|
-
),
|
|
576
|
-
);
|
|
577
|
-
|
|
578
|
-
const user4Value = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
|
|
579
|
-
addAssets(acc, utxo.assets),
|
|
580
|
-
)(await context.lucid.utxosAt(context.users['user4'].address));
|
|
581
|
-
|
|
582
|
-
const iassetAc: AssetClass = {
|
|
583
|
-
currencySymbol: fromHex(
|
|
584
|
-
sysParams.cdpParams.cdpAssetSymbol.unCurrencySymbol,
|
|
585
|
-
),
|
|
586
|
-
tokenName: fromHex(fromText(assetInfo.iassetTokenNameAscii)),
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
// Send iAssets to treasury so liquidation is performed from a clean address.
|
|
590
|
-
await sendValueTo(
|
|
591
|
-
mkTreasuryAddr(context.lucid, sysParams),
|
|
592
|
-
mkAssetsOf(iassetAc, assetClassValueOf(user4Value, iassetAc)),
|
|
593
|
-
context.lucid,
|
|
594
|
-
);
|
|
595
|
-
|
|
596
|
-
const user4collateralAssetAmount = assetClassValueOf(
|
|
597
|
-
user4Value,
|
|
598
|
-
collateralAsset,
|
|
599
|
-
);
|
|
600
|
-
|
|
601
|
-
// Send collateral asset to treasury so liquidation is performed from a clean address.
|
|
602
|
-
if (collateralAsset !== adaAssetClass && user4collateralAssetAmount > 0n) {
|
|
603
|
-
await sendValueTo(
|
|
604
|
-
mkTreasuryAddr(context.lucid, sysParams),
|
|
605
|
-
mkAssetsOf(collateralAsset, user4collateralAssetAmount),
|
|
606
|
-
context.lucid,
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
const user4ValueBeforeLiquidation = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
|
|
611
|
-
addAssets(acc, utxo.assets),
|
|
612
|
-
)(await context.lucid.utxosAt(context.users['user4'].address));
|
|
613
|
-
|
|
614
|
-
assert(Object.keys(user4ValueBeforeLiquidation).length === 1);
|
|
615
|
-
|
|
616
|
-
context.emulator.awaitSlot(1000);
|
|
617
|
-
|
|
618
|
-
await runFeedPriceToOracle(
|
|
619
|
-
context,
|
|
620
|
-
sysParams,
|
|
621
|
-
assetInfo,
|
|
622
|
-
collateralAsset,
|
|
623
|
-
rationalMul(price, rationalFromInt(2n)),
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
await runAndAwaitTx(
|
|
627
|
-
context.lucid,
|
|
628
|
-
runFreezeCdp(
|
|
629
|
-
context,
|
|
630
|
-
sysParams,
|
|
631
|
-
assetInfo.iassetTokenNameAscii,
|
|
632
|
-
collateralAsset,
|
|
633
|
-
pkh.hash,
|
|
634
|
-
skh,
|
|
635
|
-
),
|
|
636
|
-
);
|
|
637
|
-
|
|
638
|
-
const frozenCdp = matchSingle(
|
|
639
|
-
await findFrozenCDPs(
|
|
640
|
-
context.lucid,
|
|
641
|
-
sysParams.validatorHashes.cdpHash,
|
|
642
|
-
fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken),
|
|
643
|
-
assetInfo.iassetTokenNameAscii,
|
|
644
|
-
),
|
|
645
|
-
(_) => new Error('Expected only single frozen CDP'),
|
|
646
|
-
);
|
|
647
|
-
|
|
648
|
-
let treasuryUtxo = undefined;
|
|
649
|
-
|
|
650
|
-
if (!directTreasuryPayment) {
|
|
651
|
-
treasuryUtxo = await findRandomTreasuryUtxoWithAsset(
|
|
652
|
-
context.lucid,
|
|
653
|
-
sysParams,
|
|
654
|
-
collateralAsset,
|
|
655
|
-
);
|
|
656
|
-
|
|
657
|
-
// This treasury UTxO should contain ADA and collateral asset.
|
|
658
|
-
if (collateralAsset !== adaAssetClass) {
|
|
659
|
-
assert(Object.keys(treasuryUtxo.assets).length === 2);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
await liquidateWrapper(
|
|
664
|
-
await runLiquidateCdp(
|
|
665
|
-
context,
|
|
666
|
-
sysParams,
|
|
667
|
-
frozenCdp.utxo,
|
|
668
|
-
treasuryUtxo,
|
|
669
|
-
directTreasuryPayment,
|
|
670
|
-
),
|
|
671
|
-
);
|
|
672
|
-
|
|
673
|
-
await runFeedPriceToOracle(
|
|
674
|
-
context,
|
|
675
|
-
sysParams,
|
|
676
|
-
assetInfo,
|
|
677
|
-
collateralAsset,
|
|
678
|
-
price,
|
|
679
|
-
);
|
|
680
|
-
}
|
package/tests/cdp/cdp-helpers.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { match, P } from 'ts-pattern';
|
|
2
|
-
import { CDPContent } from '../../src/contracts/cdp/types-new';
|
|
3
|
-
import { calculateAccruedInterest } from '../../src/contracts/interest-oracle/helpers';
|
|
4
|
-
import { LucidContext } from '../test-helpers';
|
|
5
|
-
import { toHex, toText } from '@lucid-evolution/lucid';
|
|
6
|
-
import { findCollateralAsset } from '../queries/iasset-queries';
|
|
7
|
-
import {
|
|
8
|
-
fromSystemParamsAsset,
|
|
9
|
-
getInlineDatumOrThrow,
|
|
10
|
-
SystemParams,
|
|
11
|
-
} from '../../src';
|
|
12
|
-
import { findInterestOracle } from '../queries/interest-oracle-queries';
|
|
13
|
-
import { parseInterestOracleDatum } from '../../src/contracts/interest-oracle/types-new';
|
|
14
|
-
|
|
15
|
-
export async function calculateCdpInterest(
|
|
16
|
-
cdp: CDPContent,
|
|
17
|
-
context: LucidContext,
|
|
18
|
-
sysParams: SystemParams,
|
|
19
|
-
): Promise<bigint> {
|
|
20
|
-
const currentTime = BigInt(
|
|
21
|
-
context.lucid.slotToUnixTime(context.lucid.currentSlot()),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const collateralAsset = await findCollateralAsset(
|
|
25
|
-
context.lucid,
|
|
26
|
-
sysParams,
|
|
27
|
-
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
28
|
-
toText(toHex(cdp.iasset)),
|
|
29
|
-
cdp.collateralAsset,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
const interestOracleUtxo = await findInterestOracle(
|
|
33
|
-
context.lucid,
|
|
34
|
-
collateralAsset.datum.interestOracleNft,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const interestOracleDatum = parseInterestOracleDatum(
|
|
38
|
-
getInlineDatumOrThrow(interestOracleUtxo),
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return match(cdp.cdpFees)
|
|
42
|
-
.with({ FrozenCDPAccumulatedFees: P.select() }, (fees) => {
|
|
43
|
-
return fees.iassetInterest;
|
|
44
|
-
})
|
|
45
|
-
.with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
|
|
46
|
-
return calculateAccruedInterest(
|
|
47
|
-
currentTime,
|
|
48
|
-
interest.unitaryInterestSnapshot,
|
|
49
|
-
cdp.mintedAmt,
|
|
50
|
-
interest.lastSettled,
|
|
51
|
-
interestOracleDatum,
|
|
52
|
-
);
|
|
53
|
-
})
|
|
54
|
-
.exhaustive();
|
|
55
|
-
}
|