@indigo-labs/indigo-sdk 0.2.42 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +4 -2
- package/README.md +88 -15
- package/dist/index.d.mts +3012 -2194
- package/dist/index.d.ts +3012 -2194
- package/dist/index.js +9849 -6198
- package/dist/index.mjs +8733 -4933
- package/package.json +14 -3
- package/src/contracts/cdp/helpers.ts +68 -72
- package/src/contracts/cdp/scripts.ts +50 -13
- package/src/contracts/cdp/transactions.ts +841 -546
- package/src/contracts/cdp/types-new.ts +256 -0
- package/src/contracts/cdp/types.ts +26 -144
- package/src/contracts/cdp-creator/scripts.ts +15 -9
- package/src/contracts/cdp-creator/types-new.ts +50 -0
- package/src/contracts/cdp-creator/types.ts +5 -31
- package/src/contracts/collector/scripts.ts +1 -1
- package/src/contracts/collector/transactions.ts +23 -13
- package/src/contracts/collector/types-new.ts +17 -0
- package/src/contracts/execute/scripts.ts +19 -10
- package/src/contracts/execute/types-new.ts +44 -0
- package/src/contracts/execute/types.ts +5 -38
- package/src/contracts/gov/helpers.ts +187 -51
- package/src/contracts/gov/scripts.ts +17 -10
- package/src/contracts/gov/transactions.ts +599 -271
- package/src/contracts/gov/types-new.ts +253 -100
- package/src/contracts/gov/types.ts +4 -71
- package/src/contracts/iasset/helpers.ts +172 -0
- package/src/contracts/iasset/scripts.ts +38 -0
- package/src/contracts/iasset/types.ts +154 -0
- package/src/contracts/initialize/actions.ts +768 -0
- package/src/contracts/initialize/helpers.ts +611 -36
- package/src/contracts/initialize/types.ts +102 -28
- package/src/contracts/interest-collection/helpers.ts +19 -0
- package/src/contracts/interest-collection/scripts.ts +44 -0
- package/src/contracts/interest-collection/transactions.ts +436 -0
- package/src/contracts/interest-collection/types-new.ts +50 -0
- package/src/contracts/interest-collection/types.ts +26 -0
- package/src/contracts/interest-oracle/helpers.ts +2 -30
- package/src/contracts/interest-oracle/scripts.ts +1 -1
- package/src/contracts/interest-oracle/transactions.ts +21 -16
- package/src/contracts/interest-oracle/types-new.ts +32 -0
- package/src/contracts/interest-oracle/types.ts +1 -40
- package/src/contracts/one-shot/transactions.ts +1 -2
- package/src/contracts/poll/helpers.ts +5 -23
- package/src/contracts/poll/scripts.ts +12 -13
- package/src/contracts/poll/types-poll-manager.ts +1 -19
- package/src/contracts/poll/types-poll-new.ts +170 -0
- package/src/contracts/poll/types-poll-shard.ts +2 -24
- package/src/contracts/price-oracle/helpers.ts +1 -4
- package/src/contracts/price-oracle/scripts.ts +3 -8
- package/src/contracts/price-oracle/transactions.ts +32 -25
- package/src/contracts/price-oracle/types-new.ts +50 -0
- package/src/contracts/price-oracle/types.ts +2 -36
- package/src/contracts/pyth-feed/helpers.ts +58 -0
- package/src/contracts/pyth-feed/scripts.ts +15 -0
- package/src/contracts/pyth-feed/types.ts +181 -0
- package/src/contracts/rob/helpers.ts +405 -0
- package/src/contracts/rob/scripts.ts +35 -0
- package/src/contracts/rob/transactions.ts +410 -0
- package/src/contracts/rob/types-new.ts +128 -0
- package/src/contracts/rob/types.ts +16 -0
- package/src/contracts/rob-leverage/helpers.ts +424 -0
- package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
- package/src/contracts/stability-pool/helpers.ts +714 -230
- package/src/contracts/stability-pool/scripts.ts +20 -15
- package/src/contracts/stability-pool/transactions.ts +628 -496
- package/src/contracts/stability-pool/types-new.ts +247 -100
- package/src/contracts/stability-pool/types.ts +5 -22
- package/src/contracts/stableswap/helpers.ts +22 -0
- package/src/contracts/stableswap/scripts.ts +37 -0
- package/src/contracts/stableswap/transactions.ts +647 -0
- package/src/contracts/stableswap/types-new.ts +131 -0
- package/src/contracts/stableswap/types.ts +17 -0
- package/src/contracts/staking/helpers.ts +49 -34
- package/src/contracts/staking/scripts.ts +1 -1
- package/src/contracts/staking/transactions.ts +85 -130
- package/src/contracts/staking/types-new.ts +60 -28
- package/src/contracts/staking/types.ts +1 -28
- package/src/contracts/treasury/helpers.ts +21 -0
- package/src/contracts/treasury/scripts.ts +16 -26
- package/src/contracts/treasury/transactions.ts +256 -27
- package/src/contracts/treasury/types-new.ts +69 -0
- package/src/contracts/treasury/types.ts +2 -43
- package/src/contracts/version-registry/scripts.ts +2 -2
- package/src/contracts/version-registry/types-new.ts +6 -7
- package/src/index.ts +37 -20
- package/src/scripts/auth-token-policy.ts +3 -2
- package/src/scripts/iasset-policy.ts +3 -2
- package/src/types/evolution-schema-options.ts +3 -3
- package/src/types/generic.ts +17 -89
- package/src/types/multisig.ts +48 -0
- package/src/types/on-chain-decimal.ts +14 -7
- package/src/types/rational.ts +61 -0
- package/src/types/system-params.ts +237 -41
- package/src/utils/array-utils.ts +70 -1
- package/src/utils/bigint-utils.ts +12 -0
- package/src/utils/indigo-helpers.ts +8 -10
- package/src/utils/lucid-utils.ts +47 -40
- package/src/utils/oracle-helpers.ts +62 -0
- package/src/utils/pyth/decode.ts +223 -0
- package/src/utils/pyth/encode.ts +262 -0
- package/src/utils/pyth/index.ts +14 -0
- package/src/utils/pyth/types.ts +87 -0
- package/src/validators/always-succeed-validator.ts +6 -0
- package/src/validators/cdp-creator-validator.ts +2 -2
- package/src/validators/cdp-redeem-validator.ts +7 -0
- package/src/validators/cdp-validator.ts +2 -2
- package/src/validators/collector-validator.ts +2 -2
- package/src/validators/execute-validator.ts +2 -2
- package/src/validators/governance-validator.ts +2 -2
- package/src/validators/iasset-validator.ts +7 -0
- package/src/validators/interest-collection-validator.ts +7 -0
- package/src/validators/interest-oracle-validator.ts +2 -2
- package/src/validators/poll-manager-validator.ts +2 -2
- package/src/validators/poll-shard-validator.ts +2 -2
- package/src/validators/price-oracle-validator.ts +7 -0
- package/src/validators/pyth-feed-validator.ts +7 -0
- package/src/validators/rob-validator.ts +7 -0
- package/src/validators/stability-pool-validator.ts +2 -2
- package/src/validators/stableswap-validator.ts +7 -0
- package/src/validators/staking-validator.ts +2 -2
- package/src/validators/treasury-validator.ts +2 -2
- package/src/validators/version-record-policy.ts +2 -2
- package/src/validators/version-registry-validator.ts +2 -2
- package/tests/always-succeed/script.ts +7 -0
- package/tests/bigint-utils.test.ts +41 -0
- package/tests/cdp/actions.ts +610 -0
- package/tests/cdp/cdp-helpers.ts +55 -0
- package/tests/cdp/cdp-queries.ts +440 -0
- package/tests/cdp/cdp.test.ts +6087 -0
- package/tests/cdp/transactions-mutated.ts +1729 -0
- package/tests/data/system-params.json +177 -34
- package/tests/datums.test.ts +209 -210
- package/tests/endpoints/initialize.ts +68 -0
- package/tests/endpoints/interest-collector.ts +37 -0
- package/tests/endpoints/treasury.ts +70 -0
- package/tests/gov/actions.ts +406 -0
- package/tests/gov/gov.test.ts +4450 -0
- package/tests/{queries → gov}/governance-queries.ts +6 -3
- package/tests/hash-checks.test.ts +38 -11
- package/tests/indigo-test-helpers.ts +100 -0
- package/tests/initialize.test.ts +61 -9
- package/tests/interest-collection/interest-collection.test.ts +892 -0
- package/tests/interest-collection/interest-collector-queries.ts +49 -0
- package/tests/interest-collection/transactions-mutated.ts +260 -0
- package/tests/interest-oracle.test.ts +43 -35
- package/tests/mock/assets-mock.ts +234 -23
- package/tests/mock/protocol-params-mock.ts +21 -0
- package/tests/price-oracle/actions.ts +163 -0
- package/tests/price-oracle/price-oracle-queries.ts +12 -0
- package/tests/price-oracle/price-oracle.test.ts +240 -0
- package/tests/price-oracle/transactions-mutated.ts +62 -0
- package/tests/pyth/endpoints.ts +96 -0
- package/tests/pyth/helpers.ts +37 -0
- package/tests/pyth/pyth-encoding.test.ts +376 -0
- package/tests/pyth/pyth-indigo.test.ts +509 -0
- package/tests/pyth/pyth.test.ts +300 -0
- package/tests/queries/execute-queries.ts +6 -5
- package/tests/queries/iasset-queries.ts +175 -5
- package/tests/queries/interest-oracle-queries.ts +4 -2
- package/tests/queries/poll-queries.ts +8 -9
- package/tests/queries/stability-pool-queries.ts +95 -48
- package/tests/queries/staking-queries.ts +4 -2
- package/tests/queries/treasury-queries.ts +80 -5
- package/tests/rob/actions.ts +58 -0
- package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
- package/tests/rob/rob-queries.ts +95 -0
- package/tests/rob/rob.test.ts +3762 -0
- package/tests/rob/transactions-mutated.ts +853 -0
- package/tests/script-size.test.ts +240 -0
- package/tests/setup.ts +135 -0
- package/tests/stability-pool/actions.ts +220 -0
- package/tests/stability-pool.test.ts +6121 -667
- package/tests/stableswap/stableswap-actions.ts +84 -0
- package/tests/stableswap/stableswap-queries.ts +89 -0
- package/tests/stableswap/stableswap.test.ts +3891 -0
- package/tests/stableswap/transactions-mutated.ts +348 -0
- package/tests/staking.test.ts +82 -99
- package/tests/test-helpers.ts +58 -11
- package/tests/treasury.test.ts +242 -0
- package/tests/utils/asserts.ts +74 -0
- package/tests/utils/benchmark-utils.ts +81 -0
- package/tests/utils/index.ts +122 -4
- package/tsconfig.json +9 -1
- package/vitest.config.ts +3 -1
- package/src/contracts/collector/types.ts +0 -16
- package/src/contracts/initialize/transactions.ts +0 -891
- package/src/contracts/leverage/helpers.ts +0 -424
- package/src/contracts/lrp/helpers.ts +0 -294
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/lrp/transactions.ts +0 -250
- package/src/contracts/lrp/types.ts +0 -131
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/vesting/helpers.ts +0 -218
- package/src/utils/value-helpers.ts +0 -37
- package/src/validators/lrp-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1528
- package/tests/gov.test.ts +0 -2011
- package/tests/lrp.test.ts +0 -673
- package/tests/queries/cdp-queries.ts +0 -220
- package/tests/queries/lrp-queries.ts +0 -76
- package/tests/queries/price-oracle-queries.ts +0 -10
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fromHex,
|
|
3
|
+
fromText,
|
|
4
|
+
OutRef,
|
|
5
|
+
paymentCredentialOf,
|
|
6
|
+
unixTimeToSlot,
|
|
7
|
+
} from '@lucid-evolution/lucid';
|
|
8
|
+
import {
|
|
9
|
+
addrDetails,
|
|
10
|
+
createProposal,
|
|
11
|
+
createShardsChunks,
|
|
12
|
+
endProposal,
|
|
13
|
+
executeProposal,
|
|
14
|
+
fromSystemParamsAsset,
|
|
15
|
+
InterestOracleParams,
|
|
16
|
+
mergeShards,
|
|
17
|
+
openStakingPosition,
|
|
18
|
+
PriceOracleParams,
|
|
19
|
+
startInterestOracle,
|
|
20
|
+
SystemParams,
|
|
21
|
+
vote,
|
|
22
|
+
} from '../../src';
|
|
23
|
+
import { VoteOption } from '../../src/contracts/poll/types-poll-new';
|
|
24
|
+
import {
|
|
25
|
+
findAllPollShards,
|
|
26
|
+
findPollManager,
|
|
27
|
+
findRandomPollShard,
|
|
28
|
+
} from '../queries/poll-queries';
|
|
29
|
+
import { findStakingPosition } from '../queries/staking-queries';
|
|
30
|
+
import {
|
|
31
|
+
LucidContext,
|
|
32
|
+
runAndAwaitTx,
|
|
33
|
+
runAndAwaitTxBuilder,
|
|
34
|
+
selectWalletByAddress,
|
|
35
|
+
} from '../test-helpers';
|
|
36
|
+
import { findGov } from './governance-queries';
|
|
37
|
+
import { array as A } from 'fp-ts';
|
|
38
|
+
import { expect } from 'vitest';
|
|
39
|
+
import { findExecute } from '../queries/execute-queries';
|
|
40
|
+
import { CollateralAssetInfo } from '../endpoints/initialize';
|
|
41
|
+
import { startPriceOracleTx } from '../../src/contracts/price-oracle/transactions';
|
|
42
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
43
|
+
import {
|
|
44
|
+
findAllCollateralAssetsOfIAsset,
|
|
45
|
+
findIAsset,
|
|
46
|
+
} from '../queries/iasset-queries';
|
|
47
|
+
import { Rational, rationalFromInt } from '../../src/types/rational';
|
|
48
|
+
|
|
49
|
+
export async function runVote(
|
|
50
|
+
pollId: bigint,
|
|
51
|
+
option: VoteOption,
|
|
52
|
+
sysParams: SystemParams,
|
|
53
|
+
context: LucidContext,
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
const [pkh, _] = await addrDetails(context.lucid);
|
|
56
|
+
|
|
57
|
+
const stakingPosOref = await findStakingPosition(
|
|
58
|
+
context.lucid,
|
|
59
|
+
sysParams.validatorHashes.stakingHash,
|
|
60
|
+
fromSystemParamsAsset(sysParams.stakingParams.stakingToken),
|
|
61
|
+
pkh.hash,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const pollShard = await findRandomPollShard(
|
|
65
|
+
context.lucid,
|
|
66
|
+
sysParams.validatorHashes.pollShardHash,
|
|
67
|
+
fromSystemParamsAsset(sysParams.pollShardParams.pollToken),
|
|
68
|
+
pollId,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
await runAndAwaitTx(
|
|
72
|
+
context.lucid,
|
|
73
|
+
vote(
|
|
74
|
+
option,
|
|
75
|
+
pollShard.utxo,
|
|
76
|
+
stakingPosOref.utxo,
|
|
77
|
+
sysParams,
|
|
78
|
+
context.lucid,
|
|
79
|
+
context.emulator.slot,
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function runCreateAllShards(
|
|
85
|
+
pollId: bigint,
|
|
86
|
+
sysParams: SystemParams,
|
|
87
|
+
context: LucidContext,
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
const govUtxo = await findGov(
|
|
90
|
+
context.lucid,
|
|
91
|
+
sysParams.validatorHashes.govHash,
|
|
92
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
for (
|
|
96
|
+
let i = 0;
|
|
97
|
+
i < Math.ceil(Number(govUtxo.datum.protocolParams.totalShards) / 2);
|
|
98
|
+
i++
|
|
99
|
+
) {
|
|
100
|
+
const pollUtxo = await findPollManager(
|
|
101
|
+
context.lucid,
|
|
102
|
+
sysParams.validatorHashes.pollManagerHash,
|
|
103
|
+
fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
|
|
104
|
+
pollId,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
await runAndAwaitTx(
|
|
108
|
+
context.lucid,
|
|
109
|
+
createShardsChunks(
|
|
110
|
+
2n,
|
|
111
|
+
pollUtxo.utxo,
|
|
112
|
+
sysParams,
|
|
113
|
+
context.emulator.slot,
|
|
114
|
+
context.lucid,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function runMergeAllShards(
|
|
121
|
+
pollId: bigint,
|
|
122
|
+
sysParams: SystemParams,
|
|
123
|
+
context: LucidContext,
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
const govUtxo = await findGov(
|
|
126
|
+
context.lucid,
|
|
127
|
+
sysParams.validatorHashes.govHash,
|
|
128
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
for (
|
|
132
|
+
let i = 0;
|
|
133
|
+
i < Math.ceil(Number(govUtxo.datum.protocolParams.totalShards) / 2);
|
|
134
|
+
i++
|
|
135
|
+
) {
|
|
136
|
+
const pollUtxo = await findPollManager(
|
|
137
|
+
context.lucid,
|
|
138
|
+
sysParams.validatorHashes.pollManagerHash,
|
|
139
|
+
fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
|
|
140
|
+
pollId,
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const allPollShards = await findAllPollShards(
|
|
144
|
+
context.lucid,
|
|
145
|
+
sysParams.validatorHashes.pollShardHash,
|
|
146
|
+
fromSystemParamsAsset(sysParams.pollShardParams.pollToken),
|
|
147
|
+
pollUtxo.datum.pollId,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
await runAndAwaitTx(
|
|
151
|
+
context.lucid,
|
|
152
|
+
mergeShards(
|
|
153
|
+
pollUtxo.utxo,
|
|
154
|
+
A.takeLeft(2)(allPollShards).map((u) => u.utxo),
|
|
155
|
+
sysParams,
|
|
156
|
+
context.lucid,
|
|
157
|
+
context.emulator.slot,
|
|
158
|
+
),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function runEndProposal(
|
|
164
|
+
pollId: bigint,
|
|
165
|
+
sysParams: SystemParams,
|
|
166
|
+
context: LucidContext,
|
|
167
|
+
): Promise<void> {
|
|
168
|
+
const pollUtxo = await findPollManager(
|
|
169
|
+
context.lucid,
|
|
170
|
+
sysParams.validatorHashes.pollManagerHash,
|
|
171
|
+
fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
|
|
172
|
+
pollId,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const govUtxo = await findGov(
|
|
176
|
+
context.lucid,
|
|
177
|
+
sysParams.validatorHashes.govHash,
|
|
178
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
await runAndAwaitTx(
|
|
182
|
+
context.lucid,
|
|
183
|
+
endProposal(
|
|
184
|
+
pollUtxo.utxo,
|
|
185
|
+
govUtxo.utxo,
|
|
186
|
+
sysParams,
|
|
187
|
+
context.lucid,
|
|
188
|
+
context.emulator.slot,
|
|
189
|
+
),
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export async function waitForVotingEnd(
|
|
194
|
+
pollId: bigint,
|
|
195
|
+
sysParams: SystemParams,
|
|
196
|
+
context: LucidContext,
|
|
197
|
+
): Promise<void> {
|
|
198
|
+
const pollUtxo = await findPollManager(
|
|
199
|
+
context.lucid,
|
|
200
|
+
sysParams.validatorHashes.pollManagerHash,
|
|
201
|
+
fromSystemParamsAsset(sysParams.pollManagerParams.pollToken),
|
|
202
|
+
pollId,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const targetSlot = unixTimeToSlot(
|
|
206
|
+
context.lucid.config().network!,
|
|
207
|
+
Number(pollUtxo.datum.votingEndTime),
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
if (targetSlot > context.emulator.slot) {
|
|
211
|
+
expect(targetSlot).toBeGreaterThan(context.emulator.slot);
|
|
212
|
+
|
|
213
|
+
context.emulator.awaitSlot(targetSlot - context.emulator.slot + 1);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function runExecuteProposal(
|
|
218
|
+
pollId: bigint,
|
|
219
|
+
treasuryWithdrawalOref: OutRef | null,
|
|
220
|
+
allIAssetOrefs: OutRef[] | null,
|
|
221
|
+
iAssetOref: OutRef | null,
|
|
222
|
+
allCollateralAssetsOrefsOfIAsset: OutRef[] | null,
|
|
223
|
+
collateralAssetOref: OutRef | null,
|
|
224
|
+
stableswapPoolOrCdpCreatorOref: OutRef | null,
|
|
225
|
+
sysParams: SystemParams,
|
|
226
|
+
context: LucidContext,
|
|
227
|
+
): Promise<void> {
|
|
228
|
+
const executeUtxo = await findExecute(
|
|
229
|
+
context.lucid,
|
|
230
|
+
sysParams.validatorHashes.executeHash,
|
|
231
|
+
fromSystemParamsAsset(sysParams.executeParams.upgradeToken),
|
|
232
|
+
pollId,
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
await runAndAwaitTx(
|
|
236
|
+
context.lucid,
|
|
237
|
+
executeProposal(
|
|
238
|
+
executeUtxo.utxo,
|
|
239
|
+
(
|
|
240
|
+
await findGov(
|
|
241
|
+
context.lucid,
|
|
242
|
+
sysParams.validatorHashes.govHash,
|
|
243
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
244
|
+
)
|
|
245
|
+
).utxo,
|
|
246
|
+
treasuryWithdrawalOref,
|
|
247
|
+
allIAssetOrefs,
|
|
248
|
+
iAssetOref,
|
|
249
|
+
allCollateralAssetsOrefsOfIAsset,
|
|
250
|
+
collateralAssetOref,
|
|
251
|
+
stableswapPoolOrCdpCreatorOref,
|
|
252
|
+
sysParams,
|
|
253
|
+
context.lucid,
|
|
254
|
+
context.emulator.slot,
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export async function processSuccessfulProposal(
|
|
260
|
+
pollId: bigint,
|
|
261
|
+
treasuryWithdrawalOref: OutRef | null,
|
|
262
|
+
allIAssetOrefs: OutRef[] | null,
|
|
263
|
+
iAssetOref: OutRef | null,
|
|
264
|
+
allCollateralAssetsOrefsOfIAsset: OutRef[] | null,
|
|
265
|
+
collateralAssetOref: OutRef | null,
|
|
266
|
+
stableswapPoolOrCdpCreatorOref: OutRef | null,
|
|
267
|
+
sysParams: SystemParams,
|
|
268
|
+
context: LucidContext,
|
|
269
|
+
createStakingPos: boolean = true,
|
|
270
|
+
): Promise<void> {
|
|
271
|
+
await runCreateAllShards(pollId, sysParams, context);
|
|
272
|
+
|
|
273
|
+
if (createStakingPos) {
|
|
274
|
+
await runAndAwaitTx(
|
|
275
|
+
context.lucid,
|
|
276
|
+
openStakingPosition(100_000_000_000n, sysParams, context.lucid),
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
await runVote(pollId, 'Yes', sysParams, context);
|
|
281
|
+
|
|
282
|
+
await waitForVotingEnd(pollId, sysParams, context);
|
|
283
|
+
|
|
284
|
+
await runMergeAllShards(pollId, sysParams, context);
|
|
285
|
+
|
|
286
|
+
await runEndProposal(pollId, sysParams, context);
|
|
287
|
+
|
|
288
|
+
await runExecuteProposal(
|
|
289
|
+
pollId,
|
|
290
|
+
treasuryWithdrawalOref,
|
|
291
|
+
allIAssetOrefs,
|
|
292
|
+
iAssetOref,
|
|
293
|
+
allCollateralAssetsOrefsOfIAsset,
|
|
294
|
+
collateralAssetOref,
|
|
295
|
+
stableswapPoolOrCdpCreatorOref,
|
|
296
|
+
sysParams,
|
|
297
|
+
context,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export async function whitelistCollateralAsset(
|
|
302
|
+
context: LucidContext,
|
|
303
|
+
sysParams: SystemParams,
|
|
304
|
+
iassetAscii: string,
|
|
305
|
+
newCollateralAsset: AssetClass,
|
|
306
|
+
initialPrice: Rational,
|
|
307
|
+
initialInterest: bigint,
|
|
308
|
+
createStakingPos: boolean,
|
|
309
|
+
): Promise<CollateralAssetInfo> {
|
|
310
|
+
const prevAddr = await context.lucid.wallet().address();
|
|
311
|
+
|
|
312
|
+
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
313
|
+
|
|
314
|
+
const interestOracleParams: InterestOracleParams = {
|
|
315
|
+
biasTime: 120_000n,
|
|
316
|
+
owner: paymentCredentialOf(context.users.admin.address).hash,
|
|
317
|
+
};
|
|
318
|
+
const [startInterestTx, interestOracleNft] = await startInterestOracle(
|
|
319
|
+
0n,
|
|
320
|
+
initialInterest,
|
|
321
|
+
0n,
|
|
322
|
+
interestOracleParams,
|
|
323
|
+
context.lucid,
|
|
324
|
+
);
|
|
325
|
+
await runAndAwaitTxBuilder(context.lucid, startInterestTx);
|
|
326
|
+
|
|
327
|
+
const oracleParams: PriceOracleParams = {
|
|
328
|
+
biasTime: 120_000n,
|
|
329
|
+
expirationPeriod: 1_800_000n,
|
|
330
|
+
owner: paymentCredentialOf(context.users.admin.address).hash,
|
|
331
|
+
};
|
|
332
|
+
const [priceOracleTx, priceOranceNft] = await startPriceOracleTx(
|
|
333
|
+
context.lucid,
|
|
334
|
+
'COLLATERAL_ORACLE',
|
|
335
|
+
initialPrice,
|
|
336
|
+
oracleParams,
|
|
337
|
+
context.emulator.slot,
|
|
338
|
+
);
|
|
339
|
+
await runAndAwaitTxBuilder(context.lucid, priceOracleTx);
|
|
340
|
+
|
|
341
|
+
const [tx, pollId] = await createProposal(
|
|
342
|
+
{
|
|
343
|
+
AddCollateralAsset: {
|
|
344
|
+
correspondingIAsset: fromHex(fromText(iassetAscii)),
|
|
345
|
+
collateralAsset: newCollateralAsset,
|
|
346
|
+
assetExtraDecimals: 0n,
|
|
347
|
+
assetPriceInfo: { OracleNft: priceOranceNft },
|
|
348
|
+
interestOracleNft: interestOracleNft,
|
|
349
|
+
redemptionRatio: rationalFromInt(2n),
|
|
350
|
+
maintenanceRatio: { numerator: 15n, denominator: 10n },
|
|
351
|
+
liquidationRatio: { numerator: 12n, denominator: 10n },
|
|
352
|
+
minCollateralAmt: 1_000_000n,
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
null,
|
|
356
|
+
sysParams,
|
|
357
|
+
context.lucid,
|
|
358
|
+
context.emulator.slot,
|
|
359
|
+
(
|
|
360
|
+
await findGov(
|
|
361
|
+
context.lucid,
|
|
362
|
+
sysParams.validatorHashes.govHash,
|
|
363
|
+
fromSystemParamsAsset(sysParams.govParams.govNFT),
|
|
364
|
+
)
|
|
365
|
+
).utxo,
|
|
366
|
+
[],
|
|
367
|
+
);
|
|
368
|
+
|
|
369
|
+
await runAndAwaitTxBuilder(context.lucid, tx);
|
|
370
|
+
|
|
371
|
+
const iassetOutput = await findIAsset(
|
|
372
|
+
context.lucid,
|
|
373
|
+
sysParams.validatorHashes.iassetHash,
|
|
374
|
+
fromSystemParamsAsset(sysParams.executeParams.iAssetToken),
|
|
375
|
+
iassetAscii,
|
|
376
|
+
);
|
|
377
|
+
|
|
378
|
+
await processSuccessfulProposal(
|
|
379
|
+
pollId,
|
|
380
|
+
null,
|
|
381
|
+
null,
|
|
382
|
+
iassetOutput.utxo,
|
|
383
|
+
(
|
|
384
|
+
await findAllCollateralAssetsOfIAsset(
|
|
385
|
+
context.lucid,
|
|
386
|
+
sysParams.validatorHashes.iassetHash,
|
|
387
|
+
fromSystemParamsAsset(sysParams.executeParams.collateralAssetToken),
|
|
388
|
+
fromHex(fromText(iassetAscii)),
|
|
389
|
+
)
|
|
390
|
+
).map((o) => o.utxo),
|
|
391
|
+
null,
|
|
392
|
+
null,
|
|
393
|
+
sysParams,
|
|
394
|
+
context,
|
|
395
|
+
createStakingPos,
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
selectWalletByAddress(context, prevAddr);
|
|
399
|
+
|
|
400
|
+
return {
|
|
401
|
+
collateralAsset: newCollateralAsset,
|
|
402
|
+
interestOracleNft: interestOracleNft,
|
|
403
|
+
oracleParams: oracleParams,
|
|
404
|
+
interestOracleParams,
|
|
405
|
+
};
|
|
406
|
+
}
|