@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,509 @@
|
|
|
1
|
+
import { beforeEach, describe, test, expect } from 'vitest';
|
|
2
|
+
import { IndigoTestContext, runAndAwaitTx } from '../test-helpers';
|
|
3
|
+
import {
|
|
4
|
+
EXAMPLE_TOKEN_1,
|
|
5
|
+
EXAMPLE_TOKEN_2,
|
|
6
|
+
EXAMPLE_TOKEN_3,
|
|
7
|
+
MAINNET_PROTOCOL_PARAMETERS,
|
|
8
|
+
} from '../indigo-test-helpers';
|
|
9
|
+
import {
|
|
10
|
+
addAssets,
|
|
11
|
+
Emulator,
|
|
12
|
+
fromHex,
|
|
13
|
+
fromText,
|
|
14
|
+
generateEmulatorAccount,
|
|
15
|
+
generateEmulatorAccountFromPrivateKey,
|
|
16
|
+
Lucid,
|
|
17
|
+
slotToUnixTime,
|
|
18
|
+
toHex,
|
|
19
|
+
} from '@lucid-evolution/lucid';
|
|
20
|
+
import {
|
|
21
|
+
adaAssetClass,
|
|
22
|
+
AssetClass,
|
|
23
|
+
mkAssetsOf,
|
|
24
|
+
mkLovelacesOf,
|
|
25
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
26
|
+
import {
|
|
27
|
+
DEFAULT_INTEREST,
|
|
28
|
+
DEFAULT_PRICE,
|
|
29
|
+
ibtcInitialAssetCfgWithPyth,
|
|
30
|
+
iethInitialAssetCfgWithPyth,
|
|
31
|
+
iusdInitialAssetCfgWithPyth,
|
|
32
|
+
mkBaseCollateralAsset,
|
|
33
|
+
} from '../mock/assets-mock';
|
|
34
|
+
import { runFreezeCdp, runOpenCdp, runWithdrawCdp } from '../cdp/actions';
|
|
35
|
+
import { benchmarkAndAwaitTx } from '../utils/benchmark-utils';
|
|
36
|
+
import { addrDetails, MIN_ROB_COLLATERAL_AMT, openRob } from '../../src';
|
|
37
|
+
import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
|
|
38
|
+
import { createPythMessage } from './helpers';
|
|
39
|
+
import { findSingleRob } from '../rob/rob-queries';
|
|
40
|
+
import { expectValue } from '../utils/asserts';
|
|
41
|
+
import { runRedeemRob } from '../rob/actions';
|
|
42
|
+
import { rationalFromInt } from '../../src/types/rational';
|
|
43
|
+
import { init } from '../endpoints/initialize';
|
|
44
|
+
|
|
45
|
+
const collateralAssetA: AssetClass = {
|
|
46
|
+
currencySymbol: fromHex(
|
|
47
|
+
// random generated
|
|
48
|
+
'cc072059ae741791b7b9c23d9baea6a0b0d764dec617ce7e027a8dea',
|
|
49
|
+
),
|
|
50
|
+
tokenName: fromHex(fromText('A')),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe('Pyth > Indigo', () => {
|
|
54
|
+
beforeEach<IndigoTestContext>(async (context: IndigoTestContext) => {
|
|
55
|
+
context.users = {
|
|
56
|
+
admin: generateEmulatorAccount(
|
|
57
|
+
addAssets(
|
|
58
|
+
mkLovelacesOf(100_000_000_000_000n),
|
|
59
|
+
mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000_000_000n),
|
|
60
|
+
mkAssetsOf(collateralAssetA, 100_000_000n),
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
user: generateEmulatorAccount(
|
|
64
|
+
addAssets(
|
|
65
|
+
mkLovelacesOf(100_000_000_000_000n),
|
|
66
|
+
mkAssetsOf(EXAMPLE_TOKEN_1, 1_000_000_000_000_000n),
|
|
67
|
+
mkAssetsOf(EXAMPLE_TOKEN_2, 1_000_000_000_000_000n),
|
|
68
|
+
mkAssetsOf(EXAMPLE_TOKEN_3, 1_000_000_000_000_000n),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
user2: generateEmulatorAccount({
|
|
72
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
73
|
+
}),
|
|
74
|
+
withdrawalAccount: generateEmulatorAccountFromPrivateKey({}),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
context.emulator = new Emulator(
|
|
78
|
+
[
|
|
79
|
+
context.users.admin,
|
|
80
|
+
context.users.user,
|
|
81
|
+
context.users.user2,
|
|
82
|
+
context.users.withdrawalAccount,
|
|
83
|
+
],
|
|
84
|
+
MAINNET_PROTOCOL_PARAMETERS,
|
|
85
|
+
);
|
|
86
|
+
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
87
|
+
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
88
|
+
|
|
89
|
+
const [systemParams, assetConfigs] = await init(
|
|
90
|
+
context.lucid,
|
|
91
|
+
[],
|
|
92
|
+
context.emulator.slot,
|
|
93
|
+
(pythStateNft: AssetClass) => [
|
|
94
|
+
iusdInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
|
|
95
|
+
mkBaseCollateralAsset(
|
|
96
|
+
adaAssetClass,
|
|
97
|
+
DEFAULT_INTEREST,
|
|
98
|
+
DEFAULT_PRICE,
|
|
99
|
+
0n,
|
|
100
|
+
pythStatePolicyId,
|
|
101
|
+
{
|
|
102
|
+
tag: 'value',
|
|
103
|
+
val: { priceFeedId: 1 },
|
|
104
|
+
},
|
|
105
|
+
),
|
|
106
|
+
]),
|
|
107
|
+
iethInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
|
|
108
|
+
mkBaseCollateralAsset(
|
|
109
|
+
collateralAssetA,
|
|
110
|
+
DEFAULT_INTEREST,
|
|
111
|
+
DEFAULT_PRICE,
|
|
112
|
+
0n,
|
|
113
|
+
pythStatePolicyId,
|
|
114
|
+
{
|
|
115
|
+
tag: 'value',
|
|
116
|
+
val: { priceFeedId: 2 },
|
|
117
|
+
},
|
|
118
|
+
),
|
|
119
|
+
]),
|
|
120
|
+
ibtcInitialAssetCfgWithPyth(pythStateNft, (pythStatePolicyId) => [
|
|
121
|
+
mkBaseCollateralAsset(
|
|
122
|
+
adaAssetClass,
|
|
123
|
+
DEFAULT_INTEREST,
|
|
124
|
+
DEFAULT_PRICE,
|
|
125
|
+
0n,
|
|
126
|
+
pythStatePolicyId,
|
|
127
|
+
{
|
|
128
|
+
tag: 'divide',
|
|
129
|
+
val: [
|
|
130
|
+
{ tag: 'value', val: { priceFeedId: 1 } },
|
|
131
|
+
{ tag: 'value', val: { priceFeedId: 2 } },
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
),
|
|
135
|
+
]),
|
|
136
|
+
],
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
context.systemParams = systemParams;
|
|
140
|
+
context.assetConfigs = assetConfigs;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('Open CDP - Direct Price Value (ada collateral)', async (context: IndigoTestContext) => {
|
|
144
|
+
const currentTime = BigInt(
|
|
145
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
149
|
+
priceFeedId: 1,
|
|
150
|
+
price: '1000000',
|
|
151
|
+
exponent: -6,
|
|
152
|
+
};
|
|
153
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
154
|
+
|
|
155
|
+
await benchmarkAndAwaitTx(
|
|
156
|
+
'Pyth - CDP - Direct Price Value (ADA collateral)',
|
|
157
|
+
await runOpenCdp(
|
|
158
|
+
context,
|
|
159
|
+
context.systemParams,
|
|
160
|
+
'iUSD',
|
|
161
|
+
adaAssetClass,
|
|
162
|
+
10_000_000n,
|
|
163
|
+
500_000n,
|
|
164
|
+
toHex(message),
|
|
165
|
+
),
|
|
166
|
+
context.lucid,
|
|
167
|
+
context.emulator,
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('Open CDP - Direct Price Value (non-ADA collateral)', async (context: IndigoTestContext) => {
|
|
172
|
+
const currentTime = BigInt(
|
|
173
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const iEthFeed: ParsedFeedPayload = {
|
|
177
|
+
priceFeedId: 2,
|
|
178
|
+
price: '1000000',
|
|
179
|
+
exponent: -6,
|
|
180
|
+
feedUpdateTimestamp: Number(currentTime) * 1000,
|
|
181
|
+
};
|
|
182
|
+
const message = await createPythMessage([iEthFeed], currentTime * 1_000n);
|
|
183
|
+
|
|
184
|
+
await benchmarkAndAwaitTx(
|
|
185
|
+
'Pyth - CDP - Direct Price Value (non-ADA collateral)',
|
|
186
|
+
await runOpenCdp(
|
|
187
|
+
context,
|
|
188
|
+
context.systemParams,
|
|
189
|
+
'iETH',
|
|
190
|
+
collateralAssetA,
|
|
191
|
+
10_000_000n,
|
|
192
|
+
500_000n,
|
|
193
|
+
toHex(message),
|
|
194
|
+
),
|
|
195
|
+
context.lucid,
|
|
196
|
+
context.emulator,
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test('Open CDP - Divide Price Value', async (context: IndigoTestContext) => {
|
|
201
|
+
const currentTime = BigInt(
|
|
202
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const feed1: ParsedFeedPayload = {
|
|
206
|
+
priceFeedId: 1,
|
|
207
|
+
price: '1000000',
|
|
208
|
+
exponent: -6,
|
|
209
|
+
};
|
|
210
|
+
const feed2: ParsedFeedPayload = {
|
|
211
|
+
priceFeedId: 2,
|
|
212
|
+
price: '10',
|
|
213
|
+
exponent: -1,
|
|
214
|
+
};
|
|
215
|
+
const message = await createPythMessage(
|
|
216
|
+
[feed1, feed2],
|
|
217
|
+
currentTime * 1_000n,
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
await benchmarkAndAwaitTx(
|
|
221
|
+
'Pyth - CDP - Divide Price Value',
|
|
222
|
+
await runOpenCdp(
|
|
223
|
+
context,
|
|
224
|
+
context.systemParams,
|
|
225
|
+
'iBTC',
|
|
226
|
+
adaAssetClass,
|
|
227
|
+
10_000_000n,
|
|
228
|
+
500_000n,
|
|
229
|
+
toHex(message),
|
|
230
|
+
),
|
|
231
|
+
context.lucid,
|
|
232
|
+
context.emulator,
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test('Open CDP - Fails if missing feed price', async (context: IndigoTestContext) => {
|
|
237
|
+
const currentTime = BigInt(
|
|
238
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
// This feed doesn't include a price for feedId 2, which is used by the iBTC asset
|
|
242
|
+
const feed1: ParsedFeedPayload = {
|
|
243
|
+
priceFeedId: 1,
|
|
244
|
+
price: '1000000',
|
|
245
|
+
exponent: -6,
|
|
246
|
+
};
|
|
247
|
+
const message = await createPythMessage([feed1], currentTime * 1_000n);
|
|
248
|
+
|
|
249
|
+
await expect(
|
|
250
|
+
runOpenCdp(
|
|
251
|
+
context,
|
|
252
|
+
context.systemParams,
|
|
253
|
+
'iBTC',
|
|
254
|
+
adaAssetClass,
|
|
255
|
+
10_000_000n,
|
|
256
|
+
500_000n,
|
|
257
|
+
toHex(message),
|
|
258
|
+
),
|
|
259
|
+
).rejects.toThrowError('Pyth payload not found for feed ID: 2');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test('Withdraw CDP - Direct Price Value', async (context: IndigoTestContext) => {
|
|
263
|
+
const currentTime = BigInt(
|
|
264
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
268
|
+
priceFeedId: 1,
|
|
269
|
+
price: '1000000',
|
|
270
|
+
exponent: -6,
|
|
271
|
+
feedUpdateTimestamp: Number(currentTime) * 1000,
|
|
272
|
+
};
|
|
273
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
274
|
+
|
|
275
|
+
await runAndAwaitTx(
|
|
276
|
+
context.lucid,
|
|
277
|
+
runOpenCdp(
|
|
278
|
+
context,
|
|
279
|
+
context.systemParams,
|
|
280
|
+
'iUSD',
|
|
281
|
+
adaAssetClass,
|
|
282
|
+
11_000_000n,
|
|
283
|
+
500_000n,
|
|
284
|
+
toHex(message),
|
|
285
|
+
),
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
await benchmarkAndAwaitTx(
|
|
289
|
+
'Pyth - CDP - Withdraw CDP - Direct Price Value',
|
|
290
|
+
await runWithdrawCdp(
|
|
291
|
+
context,
|
|
292
|
+
context.systemParams,
|
|
293
|
+
'iUSD',
|
|
294
|
+
adaAssetClass,
|
|
295
|
+
1_000_000n,
|
|
296
|
+
toHex(message),
|
|
297
|
+
),
|
|
298
|
+
context.lucid,
|
|
299
|
+
context.emulator,
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('Freeze CDP - Direct Price Value', async (context: IndigoTestContext) => {
|
|
304
|
+
const currentTime = BigInt(
|
|
305
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
306
|
+
);
|
|
307
|
+
{
|
|
308
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
309
|
+
priceFeedId: 1,
|
|
310
|
+
price: '1000000',
|
|
311
|
+
exponent: -6,
|
|
312
|
+
};
|
|
313
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
314
|
+
|
|
315
|
+
await runAndAwaitTx(
|
|
316
|
+
context.lucid,
|
|
317
|
+
runOpenCdp(
|
|
318
|
+
context,
|
|
319
|
+
context.systemParams,
|
|
320
|
+
'iUSD',
|
|
321
|
+
adaAssetClass,
|
|
322
|
+
11_000_000n,
|
|
323
|
+
500_000n,
|
|
324
|
+
toHex(message),
|
|
325
|
+
),
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
{
|
|
329
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
330
|
+
priceFeedId: 1,
|
|
331
|
+
price: '100000000',
|
|
332
|
+
exponent: -6,
|
|
333
|
+
};
|
|
334
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
335
|
+
const [pkh, skh] = await addrDetails(context.lucid);
|
|
336
|
+
|
|
337
|
+
await benchmarkAndAwaitTx(
|
|
338
|
+
'Pyth - CDP - Freeze CDP - Direct Price Value',
|
|
339
|
+
await runFreezeCdp(
|
|
340
|
+
context,
|
|
341
|
+
context.systemParams,
|
|
342
|
+
'iUSD',
|
|
343
|
+
adaAssetClass,
|
|
344
|
+
pkh.hash,
|
|
345
|
+
skh,
|
|
346
|
+
toHex(message),
|
|
347
|
+
),
|
|
348
|
+
context.lucid,
|
|
349
|
+
context.emulator,
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test<IndigoTestContext>('ROB redemption on buy order', async (context: IndigoTestContext) => {
|
|
355
|
+
const [ownPkh, _] = await addrDetails(context.lucid);
|
|
356
|
+
|
|
357
|
+
const currentTime = BigInt(
|
|
358
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
359
|
+
);
|
|
360
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
361
|
+
priceFeedId: 1,
|
|
362
|
+
price: '1000000',
|
|
363
|
+
exponent: -6,
|
|
364
|
+
feedUpdateTimestamp: Number(currentTime) * 1000,
|
|
365
|
+
};
|
|
366
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
367
|
+
|
|
368
|
+
await runAndAwaitTx(
|
|
369
|
+
context.lucid,
|
|
370
|
+
runOpenCdp(
|
|
371
|
+
context,
|
|
372
|
+
context.systemParams,
|
|
373
|
+
'iUSD',
|
|
374
|
+
adaAssetClass,
|
|
375
|
+
100_000_000n,
|
|
376
|
+
30_000_000n,
|
|
377
|
+
toHex(message),
|
|
378
|
+
),
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
const initialDeposit = 20_000_000n;
|
|
382
|
+
|
|
383
|
+
await runAndAwaitTx(
|
|
384
|
+
context.lucid,
|
|
385
|
+
openRob(
|
|
386
|
+
'iUSD',
|
|
387
|
+
initialDeposit,
|
|
388
|
+
{
|
|
389
|
+
BuyIAssetOrder: {
|
|
390
|
+
collateralAsset: adaAssetClass,
|
|
391
|
+
maxPrice: rationalFromInt(1n),
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
context.lucid,
|
|
395
|
+
context.systemParams,
|
|
396
|
+
),
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
const robUtxo = await findSingleRob(
|
|
400
|
+
context,
|
|
401
|
+
context.systemParams,
|
|
402
|
+
'iUSD',
|
|
403
|
+
ownPkh,
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
const redemptionIAssetAmt = 7_500_000n;
|
|
407
|
+
|
|
408
|
+
await benchmarkAndAwaitTx(
|
|
409
|
+
'Pyth - ROB - Redemption on buy order',
|
|
410
|
+
await runRedeemRob(
|
|
411
|
+
context,
|
|
412
|
+
context.systemParams,
|
|
413
|
+
[[robUtxo, redemptionIAssetAmt]],
|
|
414
|
+
'iUSD',
|
|
415
|
+
adaAssetClass,
|
|
416
|
+
context.emulator.slot,
|
|
417
|
+
toHex(message),
|
|
418
|
+
),
|
|
419
|
+
context.lucid,
|
|
420
|
+
context.emulator,
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test<IndigoTestContext>('ROB redemption on sell order', async (context: IndigoTestContext) => {
|
|
425
|
+
const [ownPkh, _] = await addrDetails(context.lucid);
|
|
426
|
+
|
|
427
|
+
const currentTime = BigInt(
|
|
428
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
429
|
+
);
|
|
430
|
+
const iUsdFeed: ParsedFeedPayload = {
|
|
431
|
+
priceFeedId: 1,
|
|
432
|
+
price: '1250000',
|
|
433
|
+
exponent: -6,
|
|
434
|
+
feedUpdateTimestamp: Number(currentTime) * 1000,
|
|
435
|
+
};
|
|
436
|
+
const message = await createPythMessage([iUsdFeed], currentTime * 1_000n);
|
|
437
|
+
|
|
438
|
+
await runAndAwaitTx(
|
|
439
|
+
context.lucid,
|
|
440
|
+
runOpenCdp(
|
|
441
|
+
context,
|
|
442
|
+
context.systemParams,
|
|
443
|
+
'iUSD',
|
|
444
|
+
adaAssetClass,
|
|
445
|
+
100_000_000n,
|
|
446
|
+
30_000_000n,
|
|
447
|
+
toHex(message),
|
|
448
|
+
),
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
const initialDeposit = 20_000_000n;
|
|
452
|
+
|
|
453
|
+
await runAndAwaitTx(
|
|
454
|
+
context.lucid,
|
|
455
|
+
openRob(
|
|
456
|
+
'iUSD',
|
|
457
|
+
initialDeposit,
|
|
458
|
+
{
|
|
459
|
+
SellIAssetOrder: {
|
|
460
|
+
allowedCollateralAssets: [[adaAssetClass, rationalFromInt(1n)]],
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
context.lucid,
|
|
464
|
+
context.systemParams,
|
|
465
|
+
),
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
const robUtxo = await findSingleRob(
|
|
469
|
+
context,
|
|
470
|
+
context.systemParams,
|
|
471
|
+
'iUSD',
|
|
472
|
+
ownPkh,
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
const iassetAc: AssetClass = {
|
|
476
|
+
currencySymbol: fromHex(
|
|
477
|
+
context.systemParams.robParams.iassetPolicyId.unCurrencySymbol,
|
|
478
|
+
),
|
|
479
|
+
tokenName: fromHex(fromText('iUSD')),
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
expectValue(
|
|
483
|
+
robUtxo.utxo.assets,
|
|
484
|
+
'Wrong ROB value before redemption',
|
|
485
|
+
).toEqual(
|
|
486
|
+
addAssets(
|
|
487
|
+
mkLovelacesOf(MIN_ROB_COLLATERAL_AMT),
|
|
488
|
+
mkAssetsOf(iassetAc, initialDeposit),
|
|
489
|
+
),
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
const payoutCollateralAmt = 7_500_000n;
|
|
493
|
+
|
|
494
|
+
await benchmarkAndAwaitTx(
|
|
495
|
+
'Pyth - ROB - Redemption on sell order',
|
|
496
|
+
await runRedeemRob(
|
|
497
|
+
context,
|
|
498
|
+
context.systemParams,
|
|
499
|
+
[[robUtxo, payoutCollateralAmt]],
|
|
500
|
+
'iUSD',
|
|
501
|
+
adaAssetClass,
|
|
502
|
+
context.emulator.slot,
|
|
503
|
+
toHex(message),
|
|
504
|
+
),
|
|
505
|
+
context.lucid,
|
|
506
|
+
context.emulator,
|
|
507
|
+
);
|
|
508
|
+
});
|
|
509
|
+
});
|