@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,260 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Address,
|
|
4
|
-
Assets,
|
|
5
|
-
Data,
|
|
6
|
-
LucidEvolution,
|
|
7
|
-
OutputDatum,
|
|
8
|
-
OutRef,
|
|
9
|
-
toHex,
|
|
10
|
-
TxBuilder,
|
|
11
|
-
UTxO,
|
|
12
|
-
} from '@lucid-evolution/lucid';
|
|
13
|
-
import {
|
|
14
|
-
fromSystemParamsScriptRef,
|
|
15
|
-
SystemParams,
|
|
16
|
-
matchSingle,
|
|
17
|
-
parseInterestCollectionDatum,
|
|
18
|
-
serialiseInterestCollectionDatum,
|
|
19
|
-
serialiseInterestCollectionRedeemer,
|
|
20
|
-
createScriptAddress,
|
|
21
|
-
fromSystemParamsAsset,
|
|
22
|
-
} from '../../src';
|
|
23
|
-
import {
|
|
24
|
-
assetClassValueOf,
|
|
25
|
-
getInlineDatumOrThrow,
|
|
26
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
27
|
-
import { Multisig } from '../../src/types/multisig';
|
|
28
|
-
|
|
29
|
-
type CollectSuccess = {
|
|
30
|
-
kind: 'CollectSuccess';
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type CollectWithoutCDP = {
|
|
34
|
-
kind: 'CollectWithoutCDP';
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type CollectFromMultipleInterestCollectors = {
|
|
38
|
-
kind: 'CollectFromMultipleInterestCollectors';
|
|
39
|
-
utxo: UTxO;
|
|
40
|
-
};
|
|
41
|
-
type CollectFromInterestAdmin = {
|
|
42
|
-
kind: 'CollectFromInterestAdmin';
|
|
43
|
-
};
|
|
44
|
-
type CollectCustomValue = {
|
|
45
|
-
kind: 'CollectCustomValue';
|
|
46
|
-
value: Assets;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export type CollectInterestVariation =
|
|
50
|
-
| CollectSuccess
|
|
51
|
-
| CollectWithoutCDP
|
|
52
|
-
| CollectFromInterestAdmin
|
|
53
|
-
| CollectFromMultipleInterestCollectors
|
|
54
|
-
| CollectCustomValue;
|
|
55
|
-
|
|
56
|
-
export async function testCollectInterest(
|
|
57
|
-
value: Assets,
|
|
58
|
-
lucid: LucidEvolution,
|
|
59
|
-
params: SystemParams,
|
|
60
|
-
tx: TxBuilder,
|
|
61
|
-
interestCollectorOutRef: OutRef,
|
|
62
|
-
variation: CollectInterestVariation,
|
|
63
|
-
): Promise<TxBuilder> {
|
|
64
|
-
const interestCollectorUtxo: UTxO = matchSingle(
|
|
65
|
-
await lucid.utxosByOutRef([interestCollectorOutRef]),
|
|
66
|
-
(_) => new Error('Expected a single interest collector UTXO'),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
// Confirm that the interest collector UTXO is NOT of InterestCollectorDatum type
|
|
70
|
-
if (
|
|
71
|
-
variation.kind !== 'CollectFromInterestAdmin' &&
|
|
72
|
-
assetClassValueOf(
|
|
73
|
-
interestCollectorUtxo.assets,
|
|
74
|
-
fromSystemParamsAsset(params.interestCollectionParams.multisigUtxoNft),
|
|
75
|
-
)
|
|
76
|
-
) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
'Interest collector UTXO is of InterestCollectorDatum type',
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Find the script reference UTXO for the interest collection validator
|
|
83
|
-
const interestCollectionRefScriptUtxo = matchSingle(
|
|
84
|
-
await lucid.utxosByOutRef([
|
|
85
|
-
fromSystemParamsScriptRef(
|
|
86
|
-
params.scriptReferences.interestCollectionValidatorRef,
|
|
87
|
-
),
|
|
88
|
-
]),
|
|
89
|
-
(_) => new Error('Expected a single interest collection Ref Script UTXO'),
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
// Collect the interest from the interest collector UTXO and then pay back with more assets.
|
|
93
|
-
tx.readFrom([interestCollectionRefScriptUtxo])
|
|
94
|
-
.collectFrom(
|
|
95
|
-
[interestCollectorUtxo],
|
|
96
|
-
serialiseInterestCollectionRedeemer('CollectInterest'),
|
|
97
|
-
)
|
|
98
|
-
.pay.ToContract(
|
|
99
|
-
createScriptAddress(
|
|
100
|
-
lucid.config().network!,
|
|
101
|
-
params.validatorHashes.interestCollectionHash,
|
|
102
|
-
),
|
|
103
|
-
{ kind: 'inline', value: Data.void() },
|
|
104
|
-
variation.kind === 'CollectCustomValue'
|
|
105
|
-
? variation.value
|
|
106
|
-
: addAssets(interestCollectorUtxo.assets, value),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (variation.kind === 'CollectFromMultipleInterestCollectors') {
|
|
110
|
-
tx.collectFrom(
|
|
111
|
-
[variation.utxo],
|
|
112
|
-
serialiseInterestCollectionRedeemer('CollectInterest'),
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return tx;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
type DistributeInterestNoAdmin = {
|
|
120
|
-
kind: 'DistributeInterestNoAdmin';
|
|
121
|
-
};
|
|
122
|
-
type DistributeInterestWithDatum = {
|
|
123
|
-
kind: 'DistributeInterestWithDatum';
|
|
124
|
-
datum: OutputDatum;
|
|
125
|
-
};
|
|
126
|
-
export type DistributeInterestVariation =
|
|
127
|
-
| DistributeInterestNoAdmin
|
|
128
|
-
| DistributeInterestWithDatum;
|
|
129
|
-
|
|
130
|
-
export async function testDistributeInterest(
|
|
131
|
-
interestCollectorOutRef: OutRef,
|
|
132
|
-
interestAdminOutRef: OutRef,
|
|
133
|
-
outputAddress: Address,
|
|
134
|
-
outputDatum: OutputDatum | undefined,
|
|
135
|
-
params: SystemParams,
|
|
136
|
-
lucid: LucidEvolution,
|
|
137
|
-
variation: DistributeInterestVariation,
|
|
138
|
-
): Promise<TxBuilder> {
|
|
139
|
-
const interestCollectorUtxo: UTxO = matchSingle(
|
|
140
|
-
await lucid.utxosByOutRef([interestCollectorOutRef]),
|
|
141
|
-
(_) => new Error('Expected a single interest collector UTXO'),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const interestAdminUtxo: UTxO = matchSingle(
|
|
145
|
-
(await lucid.utxosByOutRef([interestAdminOutRef])).filter((utxo) =>
|
|
146
|
-
assetClassValueOf(
|
|
147
|
-
utxo.assets,
|
|
148
|
-
fromSystemParamsAsset(params.interestCollectionParams.multisigUtxoNft),
|
|
149
|
-
),
|
|
150
|
-
),
|
|
151
|
-
(_) => new Error('Expected a single interest admin UTXO'),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
const interestAdminDatum = parseInterestCollectionDatum(
|
|
155
|
-
getInlineDatumOrThrow(interestAdminUtxo),
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
// Find the script reference UTXO for the interest collection validator
|
|
159
|
-
const interestCollectionRefScriptUtxo = matchSingle(
|
|
160
|
-
await lucid.utxosByOutRef([
|
|
161
|
-
fromSystemParamsScriptRef(
|
|
162
|
-
params.scriptReferences.interestCollectionValidatorRef,
|
|
163
|
-
),
|
|
164
|
-
]),
|
|
165
|
-
(_) => new Error('Expected a single interest collection Ref Script UTXO'),
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
const tx = lucid
|
|
169
|
-
.newTx()
|
|
170
|
-
.readFrom([interestCollectionRefScriptUtxo, interestAdminUtxo])
|
|
171
|
-
.collectFrom(
|
|
172
|
-
[interestCollectorUtxo],
|
|
173
|
-
serialiseInterestCollectionRedeemer('Distribute'),
|
|
174
|
-
)
|
|
175
|
-
.pay.ToContract(outputAddress, outputDatum, interestCollectorUtxo.assets);
|
|
176
|
-
|
|
177
|
-
if (variation.kind !== 'DistributeInterestNoAdmin') {
|
|
178
|
-
// TODO: Handle tx contruction for Multisig
|
|
179
|
-
if ('Signature' in interestAdminDatum.admin_permissions) {
|
|
180
|
-
tx.addSignerKey(
|
|
181
|
-
toHex(interestAdminDatum.admin_permissions.Signature.keyHash),
|
|
182
|
-
);
|
|
183
|
-
} else {
|
|
184
|
-
// TODO: Handle other admin permissions types
|
|
185
|
-
throw new Error('Unsupported admin permissions type');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return tx;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export async function updatePermissions(
|
|
193
|
-
interestAdminOutRef: OutRef,
|
|
194
|
-
newAdminPermissions: Multisig,
|
|
195
|
-
params: SystemParams,
|
|
196
|
-
lucid: LucidEvolution,
|
|
197
|
-
): Promise<TxBuilder> {
|
|
198
|
-
const interestAdminUtxo: UTxO = matchSingle(
|
|
199
|
-
(await lucid.utxosByOutRef([interestAdminOutRef])).filter((utxo) =>
|
|
200
|
-
assetClassValueOf(
|
|
201
|
-
utxo.assets,
|
|
202
|
-
fromSystemParamsAsset(params.interestCollectionParams.multisigUtxoNft),
|
|
203
|
-
),
|
|
204
|
-
),
|
|
205
|
-
(_) => new Error('Expected a single interest admin UTXO'),
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const interestAdminDatum = parseInterestCollectionDatum(
|
|
209
|
-
getInlineDatumOrThrow(interestAdminUtxo),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
// Find the script reference UTXO for the interest collection validator
|
|
213
|
-
const interestCollectionRefScriptUtxo = matchSingle(
|
|
214
|
-
await lucid.utxosByOutRef([
|
|
215
|
-
fromSystemParamsScriptRef(
|
|
216
|
-
params.scriptReferences.interestCollectionValidatorRef,
|
|
217
|
-
),
|
|
218
|
-
]),
|
|
219
|
-
(_) => new Error('Expected a single interest collection Ref Script UTXO'),
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
const tx = lucid
|
|
223
|
-
.newTx()
|
|
224
|
-
.readFrom([interestCollectionRefScriptUtxo])
|
|
225
|
-
.collectFrom(
|
|
226
|
-
[interestAdminUtxo],
|
|
227
|
-
serialiseInterestCollectionRedeemer('UpdatePermissions'),
|
|
228
|
-
)
|
|
229
|
-
.pay.ToContract(
|
|
230
|
-
createScriptAddress(
|
|
231
|
-
lucid.config().network!,
|
|
232
|
-
params.validatorHashes.interestCollectionHash,
|
|
233
|
-
),
|
|
234
|
-
{
|
|
235
|
-
kind: 'inline',
|
|
236
|
-
value: serialiseInterestCollectionDatum({
|
|
237
|
-
admin_permissions: newAdminPermissions,
|
|
238
|
-
}),
|
|
239
|
-
},
|
|
240
|
-
interestAdminUtxo.assets,
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
if ('Signature' in interestAdminDatum.admin_permissions) {
|
|
244
|
-
tx.addSignerKey(
|
|
245
|
-
toHex(interestAdminDatum.admin_permissions.Signature.keyHash),
|
|
246
|
-
);
|
|
247
|
-
} else {
|
|
248
|
-
// TODO: Handle other admin permissions types
|
|
249
|
-
throw new Error('Unsupported admin permissions type');
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if ('Signature' in newAdminPermissions) {
|
|
253
|
-
tx.addSignerKey(toHex(newAdminPermissions.Signature.keyHash));
|
|
254
|
-
} else {
|
|
255
|
-
// TODO: Handle other admin permissions types
|
|
256
|
-
throw new Error('Unsupported admin permissions type');
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return tx;
|
|
260
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { beforeEach, test } from 'vitest';
|
|
2
|
-
import { LucidContext, runAndAwaitTxBuilder } from './test-helpers';
|
|
3
|
-
import { EmulatorAccount, Lucid } from '@lucid-evolution/lucid';
|
|
4
|
-
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
|
-
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
-
import { addrDetails } from '../src/utils/lucid-utils';
|
|
7
|
-
import {
|
|
8
|
-
feedInterestOracle,
|
|
9
|
-
InterestOracleParams,
|
|
10
|
-
startInterestOracle,
|
|
11
|
-
} from '../src';
|
|
12
|
-
import { findInterestOracle } from './queries/interest-oracle-queries';
|
|
13
|
-
import { benchmarkAndAwaitTx } from './utils/benchmark-utils';
|
|
14
|
-
import { MAINNET_PROTOCOL_PARAMETERS } from './indigo-test-helpers';
|
|
15
|
-
|
|
16
|
-
type InterestOracleTestContext = LucidContext<{
|
|
17
|
-
admin: EmulatorAccount;
|
|
18
|
-
user: EmulatorAccount;
|
|
19
|
-
}>;
|
|
20
|
-
|
|
21
|
-
beforeEach<InterestOracleTestContext>(
|
|
22
|
-
async (context: InterestOracleTestContext) => {
|
|
23
|
-
context.users = {
|
|
24
|
-
admin: generateEmulatorAccount({}),
|
|
25
|
-
user: generateEmulatorAccount({
|
|
26
|
-
lovelace: BigInt(100_000_000_000_000),
|
|
27
|
-
}),
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
context.emulator = new Emulator(
|
|
31
|
-
[context.users.user],
|
|
32
|
-
MAINNET_PROTOCOL_PARAMETERS,
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
36
|
-
},
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
test<InterestOracleTestContext>('Interest Oracle - Start', async ({
|
|
40
|
-
lucid,
|
|
41
|
-
users,
|
|
42
|
-
emulator,
|
|
43
|
-
}: InterestOracleTestContext) => {
|
|
44
|
-
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
45
|
-
|
|
46
|
-
const [pkh, _] = await addrDetails(lucid);
|
|
47
|
-
|
|
48
|
-
const [tx, _ac] = await startInterestOracle(
|
|
49
|
-
0n,
|
|
50
|
-
0n,
|
|
51
|
-
0n,
|
|
52
|
-
{
|
|
53
|
-
biasTime: 120_000n,
|
|
54
|
-
owner: pkh.hash,
|
|
55
|
-
},
|
|
56
|
-
lucid,
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
await benchmarkAndAwaitTx('Interest Oracle - Start', tx, lucid, emulator);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test<InterestOracleTestContext>('Interest Oracle - Update', async ({
|
|
63
|
-
lucid,
|
|
64
|
-
users,
|
|
65
|
-
emulator,
|
|
66
|
-
}: InterestOracleTestContext) => {
|
|
67
|
-
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
68
|
-
|
|
69
|
-
const [pkh, _] = await addrDetails(lucid);
|
|
70
|
-
const interestParams: InterestOracleParams = {
|
|
71
|
-
biasTime: 120_000n,
|
|
72
|
-
owner: pkh.hash,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const [tx, assetClass] = await startInterestOracle(
|
|
76
|
-
0n,
|
|
77
|
-
0n,
|
|
78
|
-
0n,
|
|
79
|
-
interestParams,
|
|
80
|
-
lucid,
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
await runAndAwaitTxBuilder(lucid, tx);
|
|
84
|
-
|
|
85
|
-
const utxo = await findInterestOracle(lucid, assetClass);
|
|
86
|
-
|
|
87
|
-
await benchmarkAndAwaitTx(
|
|
88
|
-
'Interest Oracle - Update',
|
|
89
|
-
await feedInterestOracle(interestParams, 500_000n, lucid, undefined, utxo),
|
|
90
|
-
lucid,
|
|
91
|
-
emulator,
|
|
92
|
-
);
|
|
93
|
-
});
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssetClass,
|
|
3
|
-
adaAssetClass,
|
|
4
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
5
|
-
import { array as A, function as F, ord as Ord, string as Str } from 'fp-ts';
|
|
6
|
-
import {
|
|
7
|
-
DerivedPythPriceSP,
|
|
8
|
-
getAssetClassComparisonStr,
|
|
9
|
-
InitialAssetParam,
|
|
10
|
-
InitialCollateralAssetParam,
|
|
11
|
-
InitialStablepoolParam,
|
|
12
|
-
PythFeedParamsSP,
|
|
13
|
-
} from '../../src';
|
|
14
|
-
import { toHex } from '@lucid-evolution/lucid';
|
|
15
|
-
import { Rational, rationalFromInt } from '../../src/types/rational';
|
|
16
|
-
|
|
17
|
-
export const DEFAULT_INTEREST = 1_000_000n;
|
|
18
|
-
export const DEFAULT_PRICE = rationalFromInt(1n);
|
|
19
|
-
|
|
20
|
-
type IndigoOracleNftConfig = {
|
|
21
|
-
tag: '_indigo_oracle_nft';
|
|
22
|
-
tokenName: string;
|
|
23
|
-
startPrice: Rational;
|
|
24
|
-
params: {
|
|
25
|
-
biasTime: bigint;
|
|
26
|
-
expirationPeriod: bigint;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
type PythOracleConfig = {
|
|
31
|
-
tag: '_pyth_oracle_nft';
|
|
32
|
-
pythFeedParams: PythFeedParamsSP;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export type InitialCollateralAsset = {
|
|
36
|
-
collateralAsset: AssetClass;
|
|
37
|
-
extraDecimals: bigint;
|
|
38
|
-
priceOracle: IndigoOracleNftConfig | PythOracleConfig;
|
|
39
|
-
interestOracle: {
|
|
40
|
-
tokenName: string;
|
|
41
|
-
initialInterestRate: bigint;
|
|
42
|
-
params: {
|
|
43
|
-
biasTime: bigint;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
redemptionRatio: Rational;
|
|
47
|
-
maintenanceRatio: Rational;
|
|
48
|
-
liquidationRatio: Rational;
|
|
49
|
-
minCollateralAmt: bigint;
|
|
50
|
-
firstCollateralAsset: boolean;
|
|
51
|
-
nextCollateralAsset: AssetClass | undefined;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export type InitialAsset = {
|
|
55
|
-
name: string;
|
|
56
|
-
collateralAssets: InitialCollateralAsset[];
|
|
57
|
-
debtMintingFeeRatio: Rational;
|
|
58
|
-
liquidationProcessingFeeRatio: Rational;
|
|
59
|
-
stabilityPoolWithdrawalFeeRatio: Rational;
|
|
60
|
-
redemptionReimbursementRatio: Rational;
|
|
61
|
-
redemptionProcessingFeeRatio: Rational;
|
|
62
|
-
firstAsset: boolean;
|
|
63
|
-
nextAsset: string | undefined;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export function mkAssetsChain(
|
|
67
|
-
assets: InitialAssetParam[],
|
|
68
|
-
): InitialAssetParam[] {
|
|
69
|
-
const sortedAssets = F.pipe(
|
|
70
|
-
assets,
|
|
71
|
-
A.sort(Ord.contramap<string, InitialAssetParam>((a) => a.name)(Str.Ord)),
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
return sortedAssets.map((asset, idx) => {
|
|
75
|
-
const isFirst = idx === 0;
|
|
76
|
-
const hasNext = idx < sortedAssets.length - 1;
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
...asset,
|
|
80
|
-
firstAsset: isFirst,
|
|
81
|
-
nextAsset: hasNext ? sortedAssets[idx + 1].name : undefined,
|
|
82
|
-
} satisfies InitialAssetParam;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function mkCollateralAssetsChain(
|
|
87
|
-
assets: InitialCollateralAssetParam[],
|
|
88
|
-
): InitialCollateralAssetParam[] {
|
|
89
|
-
const sortedAssets = F.pipe(
|
|
90
|
-
assets,
|
|
91
|
-
A.sort(
|
|
92
|
-
Ord.contramap<string, InitialCollateralAssetParam>((a) =>
|
|
93
|
-
getAssetClassComparisonStr(a.collateralAsset),
|
|
94
|
-
)(Str.Ord),
|
|
95
|
-
),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return sortedAssets.map((asset, idx) => {
|
|
99
|
-
const isFirst = idx === 0;
|
|
100
|
-
const hasNext = idx < sortedAssets.length - 1;
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
...asset,
|
|
104
|
-
firstCollateralAsset: isFirst,
|
|
105
|
-
nextCollateralAsset: hasNext
|
|
106
|
-
? sortedAssets[idx + 1].collateralAsset
|
|
107
|
-
: undefined,
|
|
108
|
-
} satisfies InitialCollateralAssetParam;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export const mkBaseCollateralAsset = (
|
|
113
|
-
a: AssetClass,
|
|
114
|
-
interest: bigint = DEFAULT_INTEREST,
|
|
115
|
-
initialPrice: Rational = DEFAULT_PRICE,
|
|
116
|
-
extraDecimals: bigint = 0n,
|
|
117
|
-
pythStateNft?: AssetClass,
|
|
118
|
-
pythDerivedPrice?: DerivedPythPriceSP,
|
|
119
|
-
): InitialCollateralAssetParam => ({
|
|
120
|
-
collateralAsset: a,
|
|
121
|
-
extraDecimals: extraDecimals,
|
|
122
|
-
priceOracle:
|
|
123
|
-
pythStateNft && pythDerivedPrice
|
|
124
|
-
? {
|
|
125
|
-
tag: '_pyth_oracle_nft',
|
|
126
|
-
pythFeedParams: {
|
|
127
|
-
config: pythDerivedPrice,
|
|
128
|
-
pythStatePolicyId: {
|
|
129
|
-
unCurrencySymbol: toHex(pythStateNft.currencySymbol),
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
}
|
|
133
|
-
: {
|
|
134
|
-
tag: '_indigo_oracle_nft',
|
|
135
|
-
tokenName: 'IASSET_ADA_ORACLE',
|
|
136
|
-
startPrice: initialPrice,
|
|
137
|
-
params: {
|
|
138
|
-
biasTime: 120_000n,
|
|
139
|
-
expirationPeriod: 1_800_000n,
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
interestOracle: {
|
|
143
|
-
tokenName: 'IASSET_ADA_INTEREST_ORACLE',
|
|
144
|
-
initialInterestRate: interest,
|
|
145
|
-
params: {
|
|
146
|
-
biasTime: 120_000n,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
redemptionRatio: rationalFromInt(2n),
|
|
150
|
-
maintenanceRatio: { numerator: 15n, denominator: 10n },
|
|
151
|
-
liquidationRatio: { numerator: 12n, denominator: 10n },
|
|
152
|
-
minCollateralAmt: 10_000_000n,
|
|
153
|
-
firstCollateralAsset: true,
|
|
154
|
-
nextCollateralAsset: undefined,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
export const iusdInitialAssetCfg = (
|
|
158
|
-
interest: bigint = DEFAULT_INTEREST,
|
|
159
|
-
stablepools: InitialStablepoolParam[] = [],
|
|
160
|
-
): InitialAssetParam => ({
|
|
161
|
-
name: 'iUSD',
|
|
162
|
-
collateralAssets: [mkBaseCollateralAsset(adaAssetClass, interest)],
|
|
163
|
-
debtMintingFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
164
|
-
liquidationProcessingFeeRatio: { numerator: 2n, denominator: 100n },
|
|
165
|
-
stabilityPoolWithdrawalFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
166
|
-
redemptionReimbursementRatio: { numerator: 1n, denominator: 100n },
|
|
167
|
-
redemptionProcessingFeeRatio: { numerator: 1n, denominator: 100n },
|
|
168
|
-
firstAsset: true,
|
|
169
|
-
nextAsset: undefined,
|
|
170
|
-
stablepools,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Creates iUSD with a Pyth price oracle
|
|
174
|
-
export const iusdInitialAssetCfgWithPyth = (
|
|
175
|
-
pythStatePolicyId: AssetClass,
|
|
176
|
-
mkCollaterals: (
|
|
177
|
-
pythStatePolicyId: AssetClass,
|
|
178
|
-
) => InitialCollateralAssetParam[],
|
|
179
|
-
): InitialAssetParam => ({
|
|
180
|
-
name: 'iUSD',
|
|
181
|
-
collateralAssets: mkCollaterals(pythStatePolicyId),
|
|
182
|
-
stablepools: [],
|
|
183
|
-
debtMintingFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
184
|
-
liquidationProcessingFeeRatio: { numerator: 2n, denominator: 100n },
|
|
185
|
-
stabilityPoolWithdrawalFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
186
|
-
redemptionReimbursementRatio: { numerator: 1n, denominator: 100n },
|
|
187
|
-
redemptionProcessingFeeRatio: { numerator: 1n, denominator: 100n },
|
|
188
|
-
firstAsset: true,
|
|
189
|
-
nextAsset: undefined,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Creates iETH with a Pyth price oracle
|
|
193
|
-
export const iethInitialAssetCfgWithPyth = (
|
|
194
|
-
pythStatePolicyId: AssetClass,
|
|
195
|
-
mkCollaterals: (
|
|
196
|
-
pythStatePolicyId: AssetClass,
|
|
197
|
-
) => InitialCollateralAssetParam[],
|
|
198
|
-
): InitialAssetParam => ({
|
|
199
|
-
name: 'iETH',
|
|
200
|
-
collateralAssets: mkCollaterals(pythStatePolicyId),
|
|
201
|
-
stablepools: [],
|
|
202
|
-
debtMintingFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
203
|
-
liquidationProcessingFeeRatio: { numerator: 2n, denominator: 100n },
|
|
204
|
-
stabilityPoolWithdrawalFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
205
|
-
redemptionReimbursementRatio: { numerator: 1n, denominator: 100n },
|
|
206
|
-
redemptionProcessingFeeRatio: { numerator: 1n, denominator: 100n },
|
|
207
|
-
firstAsset: true,
|
|
208
|
-
nextAsset: undefined,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Creates iBTC with a Pyth price oracle
|
|
212
|
-
export const ibtcInitialAssetCfgWithPyth = (
|
|
213
|
-
pythStatePolicyId: AssetClass,
|
|
214
|
-
mkCollaterals: (
|
|
215
|
-
pythStatePolicyId: AssetClass,
|
|
216
|
-
) => InitialCollateralAssetParam[],
|
|
217
|
-
): InitialAssetParam => ({
|
|
218
|
-
name: 'iBTC',
|
|
219
|
-
collateralAssets: mkCollaterals(pythStatePolicyId),
|
|
220
|
-
stablepools: [],
|
|
221
|
-
debtMintingFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
222
|
-
liquidationProcessingFeeRatio: { numerator: 2n, denominator: 100n },
|
|
223
|
-
stabilityPoolWithdrawalFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
224
|
-
redemptionReimbursementRatio: { numerator: 1n, denominator: 100n },
|
|
225
|
-
redemptionProcessingFeeRatio: { numerator: 1n, denominator: 100n },
|
|
226
|
-
firstAsset: true,
|
|
227
|
-
nextAsset: undefined,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
export const ieurInitialAssetCfg = (
|
|
231
|
-
interest: bigint = DEFAULT_INTEREST,
|
|
232
|
-
): InitialAssetParam => ({
|
|
233
|
-
name: 'iEUR',
|
|
234
|
-
collateralAssets: [mkBaseCollateralAsset(adaAssetClass, interest)],
|
|
235
|
-
stablepools: [],
|
|
236
|
-
debtMintingFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
237
|
-
liquidationProcessingFeeRatio: { numerator: 2n, denominator: 100n },
|
|
238
|
-
stabilityPoolWithdrawalFeeRatio: { numerator: 5n, denominator: 1_000n },
|
|
239
|
-
redemptionReimbursementRatio: { numerator: 1n, denominator: 100n },
|
|
240
|
-
redemptionProcessingFeeRatio: { numerator: 1n, denominator: 100n },
|
|
241
|
-
firstAsset: true,
|
|
242
|
-
nextAsset: undefined,
|
|
243
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { fromHex } from '@lucid-evolution/lucid';
|
|
2
|
-
import { ProtocolParams } from '../../src/contracts/gov/types-new';
|
|
3
|
-
|
|
4
|
-
export const protocolParamsMock: ProtocolParams = {
|
|
5
|
-
effectiveDelay: 1_000n,
|
|
6
|
-
expirationPeriod: 360_000n,
|
|
7
|
-
proposalDeposit: 1_000n,
|
|
8
|
-
proposingPeriod: 100_000n,
|
|
9
|
-
votingPeriod: 1000_000n,
|
|
10
|
-
totalShards: 4n,
|
|
11
|
-
minimumQuorum: 100_000n,
|
|
12
|
-
maxTreasuryLovelaceSpend: 10_000_000n,
|
|
13
|
-
maxTreasuryIndySpend: 10_000_000n,
|
|
14
|
-
cdpRedemptionRequiredSignature: null,
|
|
15
|
-
electorate: 35_000_000_000_000n,
|
|
16
|
-
foundationMultisig: {
|
|
17
|
-
Signature: {
|
|
18
|
-
keyHash: fromHex(''),
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
};
|