@indigo-labs/indigo-sdk 0.2.41 → 0.3.0
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/dist/index.d.mts +3008 -2194
- package/dist/index.d.ts +3008 -2194
- package/dist/index.js +9827 -6194
- package/dist/index.mjs +8591 -4809
- 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 +831 -545
- 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 +625 -495
- package/src/contracts/stability-pool/types-new.ts +237 -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 +611 -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 +210 -0
- package/tests/stability-pool.test.ts +5469 -666
- 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
|
@@ -1,79 +1,105 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, test } from 'vitest';
|
|
2
|
+
|
|
3
|
+
// Just a placeholder otherwise vitest wouldn't like it.
|
|
4
|
+
describe('ROB leverage', () => {
|
|
5
|
+
test.todo('Always pass', () => {});
|
|
6
|
+
});
|
|
7
|
+
// eslint-disable-next-line vitest/no-commented-out-tests
|
|
8
|
+
/*import { beforeEach, expect, test, vi } from 'vitest';
|
|
2
9
|
import {
|
|
3
10
|
addrDetails,
|
|
4
11
|
cdpCollateralRatioPercentage,
|
|
5
12
|
fromSystemParamsAsset,
|
|
6
13
|
getInlineDatumOrThrow,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
openLrp,
|
|
10
|
-
parseInterestOracleDatum,
|
|
11
|
-
parsePriceOracleDatum,
|
|
14
|
+
openRob,
|
|
15
|
+
RobParamsSP,
|
|
12
16
|
SystemParams,
|
|
13
|
-
} from '
|
|
17
|
+
} from '../../src';
|
|
14
18
|
import {
|
|
15
19
|
addAssets,
|
|
16
20
|
Emulator,
|
|
17
21
|
EmulatorAccount,
|
|
22
|
+
fromHex,
|
|
18
23
|
fromText,
|
|
19
24
|
generateEmulatorAccount,
|
|
20
25
|
Lucid,
|
|
21
26
|
toText,
|
|
22
27
|
UTxO,
|
|
23
28
|
} from '@lucid-evolution/lucid';
|
|
24
|
-
import {
|
|
25
|
-
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
29
|
+
import { LucidContext, runAndAwaitTx } from '../test-helpers';
|
|
26
30
|
import { describe } from 'vitest';
|
|
31
|
+
|
|
32
|
+
import { init } from '../endpoints/initialize';
|
|
27
33
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} from '
|
|
32
|
-
import {
|
|
33
|
-
import { iusdInitialAssetCfg } from './mock/assets-mock';
|
|
34
|
-
import { findAllLrps } from './queries/lrp-queries';
|
|
35
|
-
import { ocdFloor, OnChainDecimal } from '../src/types/on-chain-decimal';
|
|
36
|
-
import { assertValueInRange } from './utils/asserts';
|
|
34
|
+
iusdInitialAssetCfg,
|
|
35
|
+
mkBaseCollateralAsset,
|
|
36
|
+
} from '../mock/assets-mock';
|
|
37
|
+
import { ocdFloor, OnChainDecimal } from '../../src/types/on-chain-decimal';
|
|
38
|
+
import { assertValueInRange } from '../utils/asserts';
|
|
37
39
|
|
|
38
40
|
import {
|
|
39
41
|
calculateLeverageFromCollateralRatio,
|
|
40
42
|
MAX_REDEMPTIONS_WITH_CDP_OPEN,
|
|
41
|
-
} from '
|
|
42
|
-
import { leverageCdpWithLrp } from '
|
|
43
|
+
} from '../../src/contracts/leverage/helpers';
|
|
44
|
+
import { leverageCdpWithLrp } from '../../src/contracts/leverage/transactions';
|
|
43
45
|
import {
|
|
44
46
|
calculateTotalAdaForRedemption,
|
|
45
47
|
lrpRedeemableLovelacesInclReimb,
|
|
46
48
|
MIN_LRP_COLLATERAL_AMT,
|
|
47
49
|
randomLrpsSubsetSatisfyingTargetLovelaces,
|
|
48
|
-
} from '
|
|
50
|
+
} from '../../src/contracts/lrp/helpers';
|
|
51
|
+
import { RobDatum, RobDatum } from '../../src/contracts/lrp/types-new';
|
|
52
|
+
import {
|
|
53
|
+
adaAssetClass,
|
|
54
|
+
AssetClass,
|
|
55
|
+
assetClassValueOf,
|
|
56
|
+
lovelacesAmt,
|
|
57
|
+
mkLovelacesOf,
|
|
58
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
59
|
+
import {
|
|
60
|
+
findAllNecessaryOrefs,
|
|
61
|
+
findCdp,
|
|
62
|
+
findPriceOracleFromCollateralAsset,
|
|
63
|
+
} from '../cdp/cdp-queries';
|
|
64
|
+
import { parsePriceOracleDatum } from '../../src/contracts/price-oracle/types-new';
|
|
65
|
+
import { parseInterestOracleDatum } from '../../src/contracts/interest-oracle/types-new';
|
|
66
|
+
import { benchmarkAndAwaitTx } from '../utils/benchmark-utils';
|
|
67
|
+
import { findAllRobs } from './lrp-queries';
|
|
49
68
|
|
|
50
69
|
type MyContext = LucidContext<{
|
|
51
70
|
admin: EmulatorAccount;
|
|
52
71
|
user: EmulatorAccount;
|
|
53
72
|
}>;
|
|
54
73
|
|
|
55
|
-
async function
|
|
74
|
+
async function openBuyRobs(
|
|
56
75
|
context: MyContext,
|
|
57
76
|
sysParams: SystemParams,
|
|
58
77
|
iasset: string,
|
|
78
|
+
collateralAsset: AssetClass,
|
|
59
79
|
amountsToSpend: bigint[],
|
|
60
80
|
maxPrice: OnChainDecimal,
|
|
61
81
|
): Promise<void> {
|
|
62
82
|
for (const amt of amountsToSpend) {
|
|
63
83
|
await runAndAwaitTx(
|
|
64
84
|
context.lucid,
|
|
65
|
-
|
|
85
|
+
openRob(
|
|
86
|
+
iasset,
|
|
87
|
+
amt,
|
|
88
|
+
{ BuyIAssetOrder: { collateralAsset: collateralAsset, maxPrice } },
|
|
89
|
+
context.lucid,
|
|
90
|
+
sysParams,
|
|
91
|
+
),
|
|
66
92
|
);
|
|
67
93
|
}
|
|
68
94
|
}
|
|
69
95
|
|
|
70
|
-
function
|
|
71
|
-
lrp: { utxo: UTxO; datum:
|
|
72
|
-
|
|
96
|
+
function hadRobRedemption(
|
|
97
|
+
lrp: { utxo: UTxO; datum: RobDatum },
|
|
98
|
+
robParams: RobParamsSP,
|
|
73
99
|
): boolean {
|
|
74
100
|
return (
|
|
75
101
|
assetClassValueOf(lrp.utxo.assets, {
|
|
76
|
-
currencySymbol:
|
|
102
|
+
currencySymbol: fromHex(robParams.iassetPolicyId.unCurrencySymbol),
|
|
77
103
|
tokenName: lrp.datum.iasset,
|
|
78
104
|
}) > 0
|
|
79
105
|
);
|
|
@@ -87,38 +113,39 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
87
113
|
txHash: '',
|
|
88
114
|
});
|
|
89
115
|
|
|
90
|
-
const mockLrpParams:
|
|
116
|
+
const mockLrpParams: RobParamsSP = {
|
|
91
117
|
iassetNft: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
92
118
|
iassetPolicyId: { unCurrencySymbol: '' },
|
|
93
119
|
minRedemptionLovelacesAmt: 10n,
|
|
94
120
|
versionRecordToken: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
121
|
+
iassetValHash: '',
|
|
95
122
|
};
|
|
96
123
|
|
|
97
124
|
test('1', () => {
|
|
98
|
-
const lrps: [UTxO,
|
|
125
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
99
126
|
[
|
|
100
127
|
mockUtxo(100n),
|
|
101
128
|
{
|
|
102
|
-
iasset: 'iUSD',
|
|
129
|
+
iasset: fromHex(fromText('iUSD')),
|
|
103
130
|
lovelacesToSpend: 100n,
|
|
104
131
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
105
|
-
owner: '',
|
|
132
|
+
owner: fromHex(''),
|
|
106
133
|
},
|
|
107
134
|
],
|
|
108
135
|
[
|
|
109
136
|
mockUtxo(100n),
|
|
110
137
|
{
|
|
111
|
-
iasset: 'iUSD',
|
|
138
|
+
iasset: fromHex(fromText('iUSD')),
|
|
112
139
|
lovelacesToSpend: 100n,
|
|
113
140
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
114
|
-
owner: '',
|
|
141
|
+
owner: fromHex(''),
|
|
115
142
|
},
|
|
116
143
|
],
|
|
117
144
|
];
|
|
118
145
|
|
|
119
146
|
expect(
|
|
120
147
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
121
|
-
'iUSD',
|
|
148
|
+
fromHex(fromText('iUSD')),
|
|
122
149
|
120n,
|
|
123
150
|
{ getOnChainInt: 1_000_000n },
|
|
124
151
|
lrps,
|
|
@@ -129,21 +156,21 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
129
156
|
});
|
|
130
157
|
|
|
131
158
|
test('2', () => {
|
|
132
|
-
const lrps: [UTxO,
|
|
159
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
133
160
|
[
|
|
134
161
|
mockUtxo(100n),
|
|
135
162
|
{
|
|
136
|
-
iasset: 'iUSD',
|
|
163
|
+
iasset: fromHex(fromText('iUSD')),
|
|
137
164
|
lovelacesToSpend: 100n,
|
|
138
165
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
139
|
-
owner: '',
|
|
166
|
+
owner: fromHex(''),
|
|
140
167
|
},
|
|
141
168
|
],
|
|
142
169
|
];
|
|
143
170
|
|
|
144
171
|
expect(
|
|
145
172
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
146
|
-
'iUSD',
|
|
173
|
+
fromHex(fromText('iUSD')),
|
|
147
174
|
100n,
|
|
148
175
|
{ getOnChainInt: 1_000_000n },
|
|
149
176
|
lrps,
|
|
@@ -154,39 +181,39 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
154
181
|
});
|
|
155
182
|
|
|
156
183
|
test('filtering by iasset 1', () => {
|
|
157
|
-
const lrps: [UTxO,
|
|
184
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
158
185
|
[
|
|
159
186
|
mockUtxo(100n),
|
|
160
187
|
{
|
|
161
|
-
iasset: 'iUSD',
|
|
188
|
+
iasset: fromHex(fromText('iUSD')),
|
|
162
189
|
lovelacesToSpend: 100n,
|
|
163
190
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
164
|
-
owner: '',
|
|
191
|
+
owner: fromHex(''),
|
|
165
192
|
},
|
|
166
193
|
],
|
|
167
194
|
[
|
|
168
195
|
mockUtxo(100n),
|
|
169
196
|
{
|
|
170
|
-
iasset: 'iBTC',
|
|
197
|
+
iasset: fromHex(fromText('iBTC')),
|
|
171
198
|
lovelacesToSpend: 100n,
|
|
172
199
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
173
|
-
owner: '',
|
|
200
|
+
owner: fromHex(''),
|
|
174
201
|
},
|
|
175
202
|
],
|
|
176
203
|
[
|
|
177
204
|
mockUtxo(100n),
|
|
178
205
|
{
|
|
179
|
-
iasset: 'iUSD',
|
|
206
|
+
iasset: fromHex(fromText('iUSD')),
|
|
180
207
|
lovelacesToSpend: 100n,
|
|
181
208
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
182
|
-
owner: '',
|
|
209
|
+
owner: fromHex(''),
|
|
183
210
|
},
|
|
184
211
|
],
|
|
185
212
|
];
|
|
186
213
|
|
|
187
214
|
expect(
|
|
188
215
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
189
|
-
'iUSD',
|
|
216
|
+
fromHex(fromText('iUSD')),
|
|
190
217
|
110n,
|
|
191
218
|
{ getOnChainInt: 1_000_000n },
|
|
192
219
|
lrps,
|
|
@@ -197,30 +224,30 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
197
224
|
});
|
|
198
225
|
|
|
199
226
|
test('filtering by iasset 2', () => {
|
|
200
|
-
const lrps: [UTxO,
|
|
227
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
201
228
|
[
|
|
202
229
|
mockUtxo(100n),
|
|
203
230
|
{
|
|
204
|
-
iasset: 'iUSD',
|
|
231
|
+
iasset: fromHex(fromText('iUSD')),
|
|
205
232
|
lovelacesToSpend: 100n,
|
|
206
233
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
207
|
-
owner: '',
|
|
234
|
+
owner: fromHex(''),
|
|
208
235
|
},
|
|
209
236
|
],
|
|
210
237
|
[
|
|
211
238
|
mockUtxo(100n),
|
|
212
239
|
{
|
|
213
|
-
iasset: 'iBTC',
|
|
240
|
+
iasset: fromHex(fromText('iBTC')),
|
|
214
241
|
lovelacesToSpend: 100n,
|
|
215
242
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
216
|
-
owner: '',
|
|
243
|
+
owner: fromHex(''),
|
|
217
244
|
},
|
|
218
245
|
],
|
|
219
246
|
];
|
|
220
247
|
|
|
221
248
|
expect(() =>
|
|
222
249
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
223
|
-
'iUSD',
|
|
250
|
+
fromHex(fromText('iUSD')),
|
|
224
251
|
110n,
|
|
225
252
|
{ getOnChainInt: 1_000_000n },
|
|
226
253
|
lrps,
|
|
@@ -231,30 +258,30 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
231
258
|
});
|
|
232
259
|
|
|
233
260
|
test('filtering by price 1', () => {
|
|
234
|
-
const lrps: [UTxO,
|
|
261
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
235
262
|
[
|
|
236
263
|
mockUtxo(100n),
|
|
237
264
|
{
|
|
238
|
-
iasset: 'iUSD',
|
|
265
|
+
iasset: fromHex(fromText('iUSD')),
|
|
239
266
|
lovelacesToSpend: 100n,
|
|
240
267
|
maxPrice: { getOnChainInt: 1_500_000n },
|
|
241
|
-
owner: '',
|
|
268
|
+
owner: fromHex(''),
|
|
242
269
|
},
|
|
243
270
|
],
|
|
244
271
|
[
|
|
245
272
|
mockUtxo(100n),
|
|
246
273
|
{
|
|
247
|
-
iasset: 'iUSD',
|
|
274
|
+
iasset: fromHex(fromText('iUSD')),
|
|
248
275
|
lovelacesToSpend: 100n,
|
|
249
276
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
250
|
-
owner: '',
|
|
277
|
+
owner: fromHex(''),
|
|
251
278
|
},
|
|
252
279
|
],
|
|
253
280
|
];
|
|
254
281
|
|
|
255
282
|
expect(() =>
|
|
256
283
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
257
|
-
'iUSD',
|
|
284
|
+
fromHex(fromText('iUSD')),
|
|
258
285
|
120n,
|
|
259
286
|
{ getOnChainInt: 1_100_000n },
|
|
260
287
|
lrps,
|
|
@@ -265,39 +292,39 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
265
292
|
});
|
|
266
293
|
|
|
267
294
|
test('filtering by price 2', () => {
|
|
268
|
-
const lrps: [UTxO,
|
|
295
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
269
296
|
[
|
|
270
297
|
mockUtxo(100n),
|
|
271
298
|
{
|
|
272
|
-
iasset: 'iUSD',
|
|
299
|
+
iasset: fromHex(fromText('iUSD')),
|
|
273
300
|
lovelacesToSpend: 50n,
|
|
274
301
|
maxPrice: { getOnChainInt: 1_500_000n },
|
|
275
|
-
owner: '',
|
|
302
|
+
owner: fromHex(''),
|
|
276
303
|
},
|
|
277
304
|
],
|
|
278
305
|
[
|
|
279
306
|
mockUtxo(100n),
|
|
280
307
|
{
|
|
281
|
-
iasset: 'iUSD',
|
|
308
|
+
iasset: fromHex(fromText('iUSD')),
|
|
282
309
|
lovelacesToSpend: 100n,
|
|
283
310
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
284
|
-
owner: '',
|
|
311
|
+
owner: fromHex(''),
|
|
285
312
|
},
|
|
286
313
|
],
|
|
287
314
|
[
|
|
288
315
|
mockUtxo(100n),
|
|
289
316
|
{
|
|
290
|
-
iasset: 'iUSD',
|
|
317
|
+
iasset: fromHex(fromText('iUSD')),
|
|
291
318
|
lovelacesToSpend: 100n,
|
|
292
319
|
maxPrice: { getOnChainInt: 1_300_000n },
|
|
293
|
-
owner: '',
|
|
320
|
+
owner: fromHex(''),
|
|
294
321
|
},
|
|
295
322
|
],
|
|
296
323
|
];
|
|
297
324
|
|
|
298
325
|
expect(
|
|
299
326
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
300
|
-
'iUSD',
|
|
327
|
+
fromHex(fromText('iUSD')),
|
|
301
328
|
120n,
|
|
302
329
|
{ getOnChainInt: 1_100_000n },
|
|
303
330
|
lrps,
|
|
@@ -308,23 +335,23 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
308
335
|
});
|
|
309
336
|
|
|
310
337
|
test('min redemption check 1', () => {
|
|
311
|
-
const lrps: [UTxO,
|
|
338
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
312
339
|
[
|
|
313
340
|
mockUtxo(100n),
|
|
314
341
|
{
|
|
315
|
-
iasset: 'iUSD',
|
|
342
|
+
iasset: fromHex(fromText('iUSD')),
|
|
316
343
|
lovelacesToSpend: 100n,
|
|
317
344
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
318
|
-
owner: '',
|
|
345
|
+
owner: fromHex(''),
|
|
319
346
|
},
|
|
320
347
|
],
|
|
321
348
|
[
|
|
322
349
|
mockUtxo(100n),
|
|
323
350
|
{
|
|
324
|
-
iasset: 'iUSD',
|
|
351
|
+
iasset: fromHex(fromText('iUSD')),
|
|
325
352
|
lovelacesToSpend: 100n,
|
|
326
353
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
327
|
-
owner: '',
|
|
354
|
+
owner: fromHex(''),
|
|
328
355
|
},
|
|
329
356
|
],
|
|
330
357
|
];
|
|
@@ -333,7 +360,7 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
333
360
|
|
|
334
361
|
expect(
|
|
335
362
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
336
|
-
'iUSD',
|
|
363
|
+
fromHex(fromText('iUSD')),
|
|
337
364
|
105n,
|
|
338
365
|
{ getOnChainInt: 1_000_000n },
|
|
339
366
|
lrps,
|
|
@@ -345,32 +372,32 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
345
372
|
});
|
|
346
373
|
|
|
347
374
|
test('min redemption check 2', () => {
|
|
348
|
-
const lrps: [UTxO,
|
|
375
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
349
376
|
[
|
|
350
377
|
mockUtxo(100n),
|
|
351
378
|
{
|
|
352
|
-
iasset: 'iUSD',
|
|
379
|
+
iasset: fromHex(fromText('iUSD')),
|
|
353
380
|
lovelacesToSpend: 100n,
|
|
354
381
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
355
|
-
owner: '',
|
|
382
|
+
owner: fromHex(''),
|
|
356
383
|
},
|
|
357
384
|
],
|
|
358
385
|
[
|
|
359
386
|
mockUtxo(5n),
|
|
360
387
|
{
|
|
361
|
-
iasset: 'iUSD',
|
|
388
|
+
iasset: fromHex(fromText('iUSD')),
|
|
362
389
|
lovelacesToSpend: 5n,
|
|
363
390
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
364
|
-
owner: '',
|
|
391
|
+
owner: fromHex(''),
|
|
365
392
|
},
|
|
366
393
|
],
|
|
367
394
|
[
|
|
368
395
|
mockUtxo(100n),
|
|
369
396
|
{
|
|
370
|
-
iasset: 'iUSD',
|
|
397
|
+
iasset: fromHex(fromText('iUSD')),
|
|
371
398
|
lovelacesToSpend: 100n,
|
|
372
399
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
373
|
-
owner: '',
|
|
400
|
+
owner: fromHex(''),
|
|
374
401
|
},
|
|
375
402
|
],
|
|
376
403
|
];
|
|
@@ -379,7 +406,7 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
379
406
|
|
|
380
407
|
expect(
|
|
381
408
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
382
|
-
'iUSD',
|
|
409
|
+
fromHex(fromText('iUSD')),
|
|
383
410
|
120n,
|
|
384
411
|
{ getOnChainInt: 1_000_000n },
|
|
385
412
|
lrps,
|
|
@@ -391,32 +418,32 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
391
418
|
});
|
|
392
419
|
|
|
393
420
|
test('min redemption check 3', () => {
|
|
394
|
-
const lrps: [UTxO,
|
|
421
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
395
422
|
[
|
|
396
423
|
mockUtxo(100n),
|
|
397
424
|
{
|
|
398
|
-
iasset: 'iUSD',
|
|
425
|
+
iasset: fromHex(fromText('iUSD')),
|
|
399
426
|
lovelacesToSpend: 100n,
|
|
400
427
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
401
|
-
owner: '',
|
|
428
|
+
owner: fromHex(''),
|
|
402
429
|
},
|
|
403
430
|
],
|
|
404
431
|
[
|
|
405
432
|
mockUtxo(15n),
|
|
406
433
|
{
|
|
407
|
-
iasset: 'iUSD',
|
|
434
|
+
iasset: fromHex(fromText('iUSD')),
|
|
408
435
|
lovelacesToSpend: 15n,
|
|
409
436
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
410
|
-
owner: '',
|
|
437
|
+
owner: fromHex(''),
|
|
411
438
|
},
|
|
412
439
|
],
|
|
413
440
|
[
|
|
414
441
|
mockUtxo(100n),
|
|
415
442
|
{
|
|
416
|
-
iasset: 'iUSD',
|
|
443
|
+
iasset: fromHex(fromText('iUSD')),
|
|
417
444
|
lovelacesToSpend: 100n,
|
|
418
445
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
419
|
-
owner: '',
|
|
446
|
+
owner: fromHex(''),
|
|
420
447
|
},
|
|
421
448
|
],
|
|
422
449
|
];
|
|
@@ -425,7 +452,7 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
425
452
|
|
|
426
453
|
expect(
|
|
427
454
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
428
|
-
'iUSD',
|
|
455
|
+
fromHex(fromText('iUSD')),
|
|
429
456
|
120n,
|
|
430
457
|
{ getOnChainInt: 1_000_000n },
|
|
431
458
|
lrps,
|
|
@@ -437,50 +464,50 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
437
464
|
});
|
|
438
465
|
|
|
439
466
|
test('max redemptions check 1', () => {
|
|
440
|
-
const lrps: [UTxO,
|
|
467
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
441
468
|
[
|
|
442
469
|
mockUtxo(100n),
|
|
443
470
|
{
|
|
444
|
-
iasset: 'iUSD',
|
|
471
|
+
iasset: fromHex(fromText('iUSD')),
|
|
445
472
|
lovelacesToSpend: 100n,
|
|
446
473
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
447
|
-
owner: '',
|
|
474
|
+
owner: fromHex(''),
|
|
448
475
|
},
|
|
449
476
|
],
|
|
450
477
|
[
|
|
451
478
|
mockUtxo(90n),
|
|
452
479
|
{
|
|
453
|
-
iasset: 'iUSD',
|
|
480
|
+
iasset: fromHex(fromText('iUSD')),
|
|
454
481
|
lovelacesToSpend: 90n,
|
|
455
482
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
456
|
-
owner: '',
|
|
483
|
+
owner: fromHex(''),
|
|
457
484
|
},
|
|
458
485
|
],
|
|
459
486
|
[
|
|
460
487
|
mockUtxo(80n),
|
|
461
488
|
{
|
|
462
|
-
iasset: 'iUSD',
|
|
489
|
+
iasset: fromHex(fromText('iUSD')),
|
|
463
490
|
lovelacesToSpend: 80n,
|
|
464
491
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
465
|
-
owner: '',
|
|
492
|
+
owner: fromHex(''),
|
|
466
493
|
},
|
|
467
494
|
],
|
|
468
495
|
[
|
|
469
496
|
mockUtxo(70n),
|
|
470
497
|
{
|
|
471
|
-
iasset: 'iUSD',
|
|
498
|
+
iasset: fromHex(fromText('iUSD')),
|
|
472
499
|
lovelacesToSpend: 70n,
|
|
473
500
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
474
|
-
owner: '',
|
|
501
|
+
owner: fromHex(''),
|
|
475
502
|
},
|
|
476
503
|
],
|
|
477
504
|
[
|
|
478
505
|
mockUtxo(100n),
|
|
479
506
|
{
|
|
480
|
-
iasset: 'iUSD',
|
|
507
|
+
iasset: fromHex(fromText('iUSD')),
|
|
481
508
|
lovelacesToSpend: 100n,
|
|
482
509
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
483
|
-
owner: '',
|
|
510
|
+
owner: fromHex(''),
|
|
484
511
|
},
|
|
485
512
|
],
|
|
486
513
|
];
|
|
@@ -491,7 +518,7 @@ describe('randomLrpsSubsetSatisfyingTargetLovelaces', () => {
|
|
|
491
518
|
|
|
492
519
|
expect(
|
|
493
520
|
randomLrpsSubsetSatisfyingTargetLovelaces(
|
|
494
|
-
'iUSD',
|
|
521
|
+
fromHex(fromText('iUSD')),
|
|
495
522
|
360n,
|
|
496
523
|
{ getOnChainInt: 1_000_000n },
|
|
497
524
|
lrps,
|
|
@@ -511,11 +538,12 @@ describe('lrpRedeemableLovelacesInclReimb', () => {
|
|
|
511
538
|
txHash: '',
|
|
512
539
|
});
|
|
513
540
|
|
|
514
|
-
const mockLrpParams:
|
|
541
|
+
const mockLrpParams: RobParamsSP = {
|
|
515
542
|
iassetNft: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
516
543
|
iassetPolicyId: { unCurrencySymbol: '' },
|
|
517
544
|
minRedemptionLovelacesAmt: 10n,
|
|
518
545
|
versionRecordToken: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
546
|
+
iassetValHash: '',
|
|
519
547
|
};
|
|
520
548
|
|
|
521
549
|
test('1', () => {
|
|
@@ -524,10 +552,10 @@ describe('lrpRedeemableLovelacesInclReimb', () => {
|
|
|
524
552
|
[
|
|
525
553
|
mockUtxo(110n),
|
|
526
554
|
{
|
|
527
|
-
iasset: 'iUSD',
|
|
555
|
+
iasset: fromHex(fromText('iUSD')),
|
|
528
556
|
lovelacesToSpend: 100n,
|
|
529
557
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
530
|
-
owner: '',
|
|
558
|
+
owner: fromHex(''),
|
|
531
559
|
},
|
|
532
560
|
],
|
|
533
561
|
mockLrpParams,
|
|
@@ -541,10 +569,10 @@ describe('lrpRedeemableLovelacesInclReimb', () => {
|
|
|
541
569
|
[
|
|
542
570
|
mockUtxo(20_000_000n),
|
|
543
571
|
{
|
|
544
|
-
iasset: 'iUSD',
|
|
572
|
+
iasset: fromHex(fromText('iUSD')),
|
|
545
573
|
lovelacesToSpend: 100_000_000n,
|
|
546
574
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
547
|
-
owner: '',
|
|
575
|
+
owner: fromHex(''),
|
|
548
576
|
},
|
|
549
577
|
],
|
|
550
578
|
mockLrpParams,
|
|
@@ -558,10 +586,10 @@ describe('lrpRedeemableLovelacesInclReimb', () => {
|
|
|
558
586
|
[
|
|
559
587
|
mockUtxo(20n),
|
|
560
588
|
{
|
|
561
|
-
iasset: 'iUSD',
|
|
589
|
+
iasset: fromHex(fromText('iUSD')),
|
|
562
590
|
lovelacesToSpend: 5n,
|
|
563
591
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
564
|
-
owner: '',
|
|
592
|
+
owner: fromHex(''),
|
|
565
593
|
},
|
|
566
594
|
],
|
|
567
595
|
mockLrpParams,
|
|
@@ -578,38 +606,39 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
578
606
|
txHash: '',
|
|
579
607
|
});
|
|
580
608
|
|
|
581
|
-
const mockLrpParams:
|
|
609
|
+
const mockLrpParams: RobParamsSP = {
|
|
582
610
|
iassetNft: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
583
611
|
iassetPolicyId: { unCurrencySymbol: '' },
|
|
584
612
|
minRedemptionLovelacesAmt: 10n,
|
|
585
613
|
versionRecordToken: [{ unCurrencySymbol: '' }, { unTokenName: '' }],
|
|
614
|
+
iassetValHash: '',
|
|
586
615
|
};
|
|
587
616
|
|
|
588
617
|
test('1', () => {
|
|
589
|
-
const lrps: [UTxO,
|
|
618
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
590
619
|
[
|
|
591
620
|
mockUtxo(100n),
|
|
592
621
|
{
|
|
593
|
-
iasset: 'iUSD',
|
|
622
|
+
iasset: fromHex(fromText('iUSD')),
|
|
594
623
|
lovelacesToSpend: 100n,
|
|
595
624
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
596
|
-
owner: '',
|
|
625
|
+
owner: fromHex(''),
|
|
597
626
|
},
|
|
598
627
|
],
|
|
599
628
|
[
|
|
600
629
|
mockUtxo(100n),
|
|
601
630
|
{
|
|
602
|
-
iasset: 'iUSD',
|
|
631
|
+
iasset: fromHex(fromText('iUSD')),
|
|
603
632
|
lovelacesToSpend: 100n,
|
|
604
633
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
605
|
-
owner: '',
|
|
634
|
+
owner: fromHex(''),
|
|
606
635
|
},
|
|
607
636
|
],
|
|
608
637
|
];
|
|
609
638
|
|
|
610
639
|
expect(
|
|
611
640
|
calculateTotalAdaForRedemption(
|
|
612
|
-
'iUSD',
|
|
641
|
+
fromHex(fromText('iUSD')),
|
|
613
642
|
{ getOnChainInt: 1_000_000n },
|
|
614
643
|
mockLrpParams,
|
|
615
644
|
lrps,
|
|
@@ -620,30 +649,30 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
620
649
|
});
|
|
621
650
|
|
|
622
651
|
test('2', () => {
|
|
623
|
-
const lrps: [UTxO,
|
|
652
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
624
653
|
[
|
|
625
654
|
mockUtxo(1000n),
|
|
626
655
|
{
|
|
627
|
-
iasset: 'iUSD',
|
|
656
|
+
iasset: fromHex(fromText('iUSD')),
|
|
628
657
|
lovelacesToSpend: 1000n,
|
|
629
658
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
630
|
-
owner: '',
|
|
659
|
+
owner: fromHex(''),
|
|
631
660
|
},
|
|
632
661
|
],
|
|
633
662
|
[
|
|
634
663
|
mockUtxo(1000n),
|
|
635
664
|
{
|
|
636
|
-
iasset: 'iUSD',
|
|
665
|
+
iasset: fromHex(fromText('iUSD')),
|
|
637
666
|
lovelacesToSpend: 1000n,
|
|
638
667
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
639
|
-
owner: '',
|
|
668
|
+
owner: fromHex(''),
|
|
640
669
|
},
|
|
641
670
|
],
|
|
642
671
|
];
|
|
643
672
|
|
|
644
673
|
expect(
|
|
645
674
|
calculateTotalAdaForRedemption(
|
|
646
|
-
'iUSD',
|
|
675
|
+
fromHex(fromText('iUSD')),
|
|
647
676
|
{ getOnChainInt: 1_000_000n },
|
|
648
677
|
mockLrpParams,
|
|
649
678
|
lrps,
|
|
@@ -653,39 +682,39 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
653
682
|
});
|
|
654
683
|
|
|
655
684
|
test('filtering by assets 1', () => {
|
|
656
|
-
const lrps: [UTxO,
|
|
685
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
657
686
|
[
|
|
658
687
|
mockUtxo(1000n),
|
|
659
688
|
{
|
|
660
|
-
iasset: 'iUSD',
|
|
689
|
+
iasset: fromHex(fromText('iUSD')),
|
|
661
690
|
lovelacesToSpend: 1000n,
|
|
662
691
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
663
|
-
owner: '',
|
|
692
|
+
owner: fromHex(''),
|
|
664
693
|
},
|
|
665
694
|
],
|
|
666
695
|
[
|
|
667
696
|
mockUtxo(1000n),
|
|
668
697
|
{
|
|
669
|
-
iasset: 'iBTC',
|
|
698
|
+
iasset: fromHex(fromText('iBTC')),
|
|
670
699
|
lovelacesToSpend: 1000n,
|
|
671
700
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
672
|
-
owner: '',
|
|
701
|
+
owner: fromHex(''),
|
|
673
702
|
},
|
|
674
703
|
],
|
|
675
704
|
[
|
|
676
705
|
mockUtxo(1000n),
|
|
677
706
|
{
|
|
678
|
-
iasset: 'iETH',
|
|
707
|
+
iasset: fromHex(fromText('iETH')),
|
|
679
708
|
lovelacesToSpend: 1000n,
|
|
680
709
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
681
|
-
owner: '',
|
|
710
|
+
owner: fromHex(''),
|
|
682
711
|
},
|
|
683
712
|
],
|
|
684
713
|
];
|
|
685
714
|
|
|
686
715
|
expect(
|
|
687
716
|
calculateTotalAdaForRedemption(
|
|
688
|
-
'iUSD',
|
|
717
|
+
fromHex(fromText('iUSD')),
|
|
689
718
|
{ getOnChainInt: 1_000_000n },
|
|
690
719
|
mockLrpParams,
|
|
691
720
|
lrps,
|
|
@@ -695,39 +724,39 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
695
724
|
});
|
|
696
725
|
|
|
697
726
|
test('filtering by price 1', () => {
|
|
698
|
-
const lrps: [UTxO,
|
|
727
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
699
728
|
[
|
|
700
729
|
mockUtxo(1000n),
|
|
701
730
|
{
|
|
702
|
-
iasset: 'iUSD',
|
|
731
|
+
iasset: fromHex(fromText('iUSD')),
|
|
703
732
|
lovelacesToSpend: 1000n,
|
|
704
733
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
705
|
-
owner: '',
|
|
734
|
+
owner: fromHex(''),
|
|
706
735
|
},
|
|
707
736
|
],
|
|
708
737
|
[
|
|
709
738
|
mockUtxo(1000n),
|
|
710
739
|
{
|
|
711
|
-
iasset: 'iUSD',
|
|
740
|
+
iasset: fromHex(fromText('iUSD')),
|
|
712
741
|
lovelacesToSpend: 1000n,
|
|
713
742
|
maxPrice: { getOnChainInt: 1_500_000n },
|
|
714
|
-
owner: '',
|
|
743
|
+
owner: fromHex(''),
|
|
715
744
|
},
|
|
716
745
|
],
|
|
717
746
|
[
|
|
718
747
|
mockUtxo(1000n),
|
|
719
748
|
{
|
|
720
|
-
iasset: 'iUSD',
|
|
749
|
+
iasset: fromHex(fromText('iUSD')),
|
|
721
750
|
lovelacesToSpend: 1000n,
|
|
722
751
|
maxPrice: { getOnChainInt: 800_000n },
|
|
723
|
-
owner: '',
|
|
752
|
+
owner: fromHex(''),
|
|
724
753
|
},
|
|
725
754
|
],
|
|
726
755
|
];
|
|
727
756
|
|
|
728
757
|
expect(
|
|
729
758
|
calculateTotalAdaForRedemption(
|
|
730
|
-
'iUSD',
|
|
759
|
+
fromHex(fromText('iUSD')),
|
|
731
760
|
{ getOnChainInt: 1_100_000n },
|
|
732
761
|
mockLrpParams,
|
|
733
762
|
lrps,
|
|
@@ -737,50 +766,50 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
737
766
|
});
|
|
738
767
|
|
|
739
768
|
test('capping by max redemptions 1', () => {
|
|
740
|
-
const lrps: [UTxO,
|
|
769
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
741
770
|
[
|
|
742
771
|
mockUtxo(1000n),
|
|
743
772
|
{
|
|
744
|
-
iasset: 'iUSD',
|
|
773
|
+
iasset: fromHex(fromText('iUSD')),
|
|
745
774
|
lovelacesToSpend: 1000n,
|
|
746
775
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
747
|
-
owner: '',
|
|
776
|
+
owner: fromHex(''),
|
|
748
777
|
},
|
|
749
778
|
],
|
|
750
779
|
[
|
|
751
780
|
mockUtxo(1400n),
|
|
752
781
|
{
|
|
753
|
-
iasset: 'iUSD',
|
|
782
|
+
iasset: fromHex(fromText('iUSD')),
|
|
754
783
|
lovelacesToSpend: 1400n,
|
|
755
784
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
756
|
-
owner: '',
|
|
785
|
+
owner: fromHex(''),
|
|
757
786
|
},
|
|
758
787
|
],
|
|
759
788
|
[
|
|
760
789
|
mockUtxo(1600n),
|
|
761
790
|
{
|
|
762
|
-
iasset: 'iUSD',
|
|
791
|
+
iasset: fromHex(fromText('iUSD')),
|
|
763
792
|
lovelacesToSpend: 1600n,
|
|
764
793
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
765
|
-
owner: '',
|
|
794
|
+
owner: fromHex(''),
|
|
766
795
|
},
|
|
767
796
|
],
|
|
768
797
|
[
|
|
769
798
|
mockUtxo(1800n),
|
|
770
799
|
{
|
|
771
|
-
iasset: 'iUSD',
|
|
800
|
+
iasset: fromHex(fromText('iUSD')),
|
|
772
801
|
lovelacesToSpend: 1800n,
|
|
773
802
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
774
|
-
owner: '',
|
|
803
|
+
owner: fromHex(''),
|
|
775
804
|
},
|
|
776
805
|
],
|
|
777
806
|
[
|
|
778
807
|
mockUtxo(2000n),
|
|
779
808
|
{
|
|
780
|
-
iasset: 'iUSD',
|
|
809
|
+
iasset: fromHex(fromText('iUSD')),
|
|
781
810
|
lovelacesToSpend: 2000n,
|
|
782
811
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
783
|
-
owner: '',
|
|
812
|
+
owner: fromHex(''),
|
|
784
813
|
},
|
|
785
814
|
],
|
|
786
815
|
];
|
|
@@ -789,7 +818,7 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
789
818
|
|
|
790
819
|
expect(
|
|
791
820
|
calculateTotalAdaForRedemption(
|
|
792
|
-
'iUSD',
|
|
821
|
+
fromHex(fromText('iUSD')),
|
|
793
822
|
{ getOnChainInt: 1_000_000n },
|
|
794
823
|
mockLrpParams,
|
|
795
824
|
lrps,
|
|
@@ -800,50 +829,50 @@ describe('calculateTotalAdaForRedemption', () => {
|
|
|
800
829
|
});
|
|
801
830
|
|
|
802
831
|
test('incorrectly initialised LRPs 1', () => {
|
|
803
|
-
const lrps: [UTxO,
|
|
832
|
+
const lrps: [UTxO, RobDatum][] = [
|
|
804
833
|
// This one should be capped to the UTXO value
|
|
805
834
|
[
|
|
806
835
|
mockUtxo(20_000_000n),
|
|
807
836
|
{
|
|
808
|
-
iasset: 'iUSD',
|
|
837
|
+
iasset: fromHex(fromText('iUSD')),
|
|
809
838
|
lovelacesToSpend: 100_000_000n,
|
|
810
839
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
811
|
-
owner: '',
|
|
840
|
+
owner: fromHex(''),
|
|
812
841
|
},
|
|
813
842
|
],
|
|
814
843
|
[
|
|
815
844
|
mockUtxo(1000n),
|
|
816
845
|
{
|
|
817
|
-
iasset: 'iUSD',
|
|
846
|
+
iasset: fromHex(fromText('iUSD')),
|
|
818
847
|
lovelacesToSpend: 1000n,
|
|
819
848
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
820
|
-
owner: '',
|
|
849
|
+
owner: fromHex(''),
|
|
821
850
|
},
|
|
822
851
|
],
|
|
823
852
|
[
|
|
824
853
|
mockUtxo(1000n),
|
|
825
854
|
{
|
|
826
|
-
iasset: 'iUSD',
|
|
855
|
+
iasset: fromHex(fromText('iUSD')),
|
|
827
856
|
lovelacesToSpend: 1000n,
|
|
828
857
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
829
|
-
owner: '',
|
|
858
|
+
owner: fromHex(''),
|
|
830
859
|
},
|
|
831
860
|
],
|
|
832
861
|
// This one shold get dropped since less than min
|
|
833
862
|
[
|
|
834
863
|
mockUtxo(1000n),
|
|
835
864
|
{
|
|
836
|
-
iasset: 'iUSD',
|
|
865
|
+
iasset: fromHex(fromText('iUSD')),
|
|
837
866
|
lovelacesToSpend: 5n,
|
|
838
867
|
maxPrice: { getOnChainInt: 1_000_000n },
|
|
839
|
-
owner: '',
|
|
868
|
+
owner: fromHex(''),
|
|
840
869
|
},
|
|
841
870
|
],
|
|
842
871
|
];
|
|
843
872
|
|
|
844
873
|
expect(
|
|
845
874
|
calculateTotalAdaForRedemption(
|
|
846
|
-
'iUSD',
|
|
875
|
+
fromHex(fromText('iUSD')),
|
|
847
876
|
{ getOnChainInt: 1_000_000n },
|
|
848
877
|
mockLrpParams,
|
|
849
878
|
lrps,
|
|
@@ -869,53 +898,73 @@ describe('LRP leverage', () => {
|
|
|
869
898
|
test<MyContext>('Open 2x leveraged CDP; 1 LRP; price ~1.1; f_r=.01; f_m=.005', async (context: MyContext) => {
|
|
870
899
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
871
900
|
|
|
872
|
-
const [sysParams,
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
...iusdInitialAssetCfg
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
901
|
+
const [sysParams, [iusdAssetInfo]] = await init(
|
|
902
|
+
context.lucid,
|
|
903
|
+
[
|
|
904
|
+
{
|
|
905
|
+
...iusdInitialAssetCfg(),
|
|
906
|
+
collateralAssets: [
|
|
907
|
+
{
|
|
908
|
+
...mkBaseCollateralAsset(adaAssetClass, 0n, 1_104_093n),
|
|
909
|
+
maintenanceRatioPercentage: 150_000_000n,
|
|
910
|
+
},
|
|
911
|
+
],
|
|
912
|
+
debtMintingFeePercentage: 500_000n,
|
|
913
|
+
redemptionReimbursementPercentage: 1_000_000n,
|
|
882
914
|
},
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
},
|
|
887
|
-
]);
|
|
888
|
-
|
|
889
|
-
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
915
|
+
],
|
|
916
|
+
context.emulator.slot,
|
|
917
|
+
);
|
|
890
918
|
|
|
891
|
-
await
|
|
892
|
-
|
|
893
|
-
|
|
919
|
+
await openBuyRobs(
|
|
920
|
+
context,
|
|
921
|
+
sysParams,
|
|
922
|
+
iusdAssetInfo.iassetTokenNameAscii,
|
|
923
|
+
adaAssetClass,
|
|
924
|
+
[100_000_000n],
|
|
925
|
+
{
|
|
926
|
+
getOnChainInt: 1_500_000n,
|
|
927
|
+
},
|
|
928
|
+
);
|
|
894
929
|
|
|
895
|
-
const
|
|
930
|
+
const allRobs = await findAllRobs(
|
|
931
|
+
context.lucid,
|
|
932
|
+
sysParams,
|
|
933
|
+
iusdAssetInfo.iassetTokenNameAscii,
|
|
934
|
+
);
|
|
896
935
|
|
|
897
936
|
const orefs = await findAllNecessaryOrefs(
|
|
898
937
|
context.lucid,
|
|
899
938
|
sysParams,
|
|
900
|
-
|
|
939
|
+
iusdAssetInfo.iassetTokenNameAscii,
|
|
940
|
+
adaAssetClass,
|
|
901
941
|
);
|
|
902
942
|
|
|
903
|
-
const
|
|
904
|
-
await runAndAwaitTx(
|
|
943
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
905
944
|
context.lucid,
|
|
906
|
-
|
|
945
|
+
orefs.collateralAsset,
|
|
946
|
+
);
|
|
947
|
+
|
|
948
|
+
const baseCollateral = 20_000_000n;
|
|
949
|
+
|
|
950
|
+
await benchmarkAndAwaitTx(
|
|
951
|
+
'Leverage - CDP open with 1 LRP',
|
|
952
|
+
await leverageCdpWithLrp(
|
|
907
953
|
2,
|
|
908
954
|
baseCollateral,
|
|
909
|
-
|
|
955
|
+
priceOracleUtxo,
|
|
910
956
|
orefs.iasset.utxo,
|
|
957
|
+
orefs.collateralAsset.utxo,
|
|
911
958
|
orefs.cdpCreatorUtxo,
|
|
912
959
|
orefs.interestOracleUtxo,
|
|
913
960
|
orefs.collectorUtxo,
|
|
914
961
|
sysParams,
|
|
915
962
|
context.lucid,
|
|
916
|
-
|
|
963
|
+
allRobs.map((lrps) => [lrps.utxo, lrps.datum]),
|
|
917
964
|
context.emulator.slot,
|
|
918
965
|
),
|
|
966
|
+
context.lucid,
|
|
967
|
+
context.emulator,
|
|
919
968
|
);
|
|
920
969
|
|
|
921
970
|
const [pkh, skh] = await addrDetails(context.lucid);
|
|
@@ -941,8 +990,7 @@ describe('LRP leverage', () => {
|
|
|
941
990
|
assertValueInRange(
|
|
942
991
|
cdpCollateralRatioPercentage(
|
|
943
992
|
context.emulator.slot,
|
|
944
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
945
|
-
.price,
|
|
993
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
946
994
|
res.utxo,
|
|
947
995
|
res.datum,
|
|
948
996
|
parseInterestOracleDatum(
|
|
@@ -960,26 +1008,30 @@ describe('LRP leverage', () => {
|
|
|
960
1008
|
test<MyContext>('Open 2x leveraged CDP; 4 LRPs; price ~0.9; f_r=.01; f_m=.005', async (context: MyContext) => {
|
|
961
1009
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
962
1010
|
|
|
963
|
-
const [sysParams, __] = await init(
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
...iusdInitialAssetCfg
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1011
|
+
const [sysParams, __] = await init(
|
|
1012
|
+
context.lucid,
|
|
1013
|
+
[
|
|
1014
|
+
{
|
|
1015
|
+
...iusdInitialAssetCfg,
|
|
1016
|
+
priceOracle: {
|
|
1017
|
+
...iusdInitialAssetCfg.priceOracle,
|
|
1018
|
+
startPrice: 904_093n,
|
|
1019
|
+
},
|
|
1020
|
+
interestOracle: {
|
|
1021
|
+
...iusdInitialAssetCfg.interestOracle,
|
|
1022
|
+
initialInterestRate: 0n,
|
|
1023
|
+
},
|
|
1024
|
+
maintenanceRatioPercentage: 150_000_000n,
|
|
1025
|
+
debtMintingFeePercentage: 500_000n,
|
|
1026
|
+
redemptionReimbursementPercentage: 1_000_000n,
|
|
973
1027
|
},
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
},
|
|
978
|
-
]);
|
|
1028
|
+
],
|
|
1029
|
+
context.emulator.slot,
|
|
1030
|
+
);
|
|
979
1031
|
|
|
980
1032
|
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
981
1033
|
|
|
982
|
-
await
|
|
1034
|
+
await openBuyRobs(
|
|
983
1035
|
context,
|
|
984
1036
|
sysParams,
|
|
985
1037
|
iasset,
|
|
@@ -997,13 +1049,18 @@ describe('LRP leverage', () => {
|
|
|
997
1049
|
toText(iasset),
|
|
998
1050
|
);
|
|
999
1051
|
|
|
1052
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
1053
|
+
context.lucid,
|
|
1054
|
+
orefs.iasset,
|
|
1055
|
+
);
|
|
1056
|
+
|
|
1000
1057
|
const baseCollateral = 100_000_000n;
|
|
1001
1058
|
await runAndAwaitTx(
|
|
1002
1059
|
context.lucid,
|
|
1003
1060
|
leverageCdpWithLrp(
|
|
1004
1061
|
2,
|
|
1005
1062
|
baseCollateral,
|
|
1006
|
-
|
|
1063
|
+
priceOracleUtxo,
|
|
1007
1064
|
orefs.iasset.utxo,
|
|
1008
1065
|
orefs.cdpCreatorUtxo,
|
|
1009
1066
|
orefs.interestOracleUtxo,
|
|
@@ -1038,8 +1095,7 @@ describe('LRP leverage', () => {
|
|
|
1038
1095
|
assertValueInRange(
|
|
1039
1096
|
cdpCollateralRatioPercentage(
|
|
1040
1097
|
context.emulator.slot,
|
|
1041
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1042
|
-
.price,
|
|
1098
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1043
1099
|
res.utxo,
|
|
1044
1100
|
res.datum,
|
|
1045
1101
|
parseInterestOracleDatum(
|
|
@@ -1056,7 +1112,7 @@ describe('LRP leverage', () => {
|
|
|
1056
1112
|
{
|
|
1057
1113
|
const lrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1058
1114
|
expect(
|
|
1059
|
-
lrps.every((lrp) =>
|
|
1115
|
+
lrps.every((lrp) => hadRobRedemption(lrp, sysParams.lrpParams)),
|
|
1060
1116
|
).toBeTruthy();
|
|
1061
1117
|
}
|
|
1062
1118
|
});
|
|
@@ -1064,26 +1120,30 @@ describe('LRP leverage', () => {
|
|
|
1064
1120
|
test<MyContext>('Open 2.3x leveraged CDP; 4 LRPs; price ~1.03; f_r=.01; f_m=.013', async (context: MyContext) => {
|
|
1065
1121
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
1066
1122
|
|
|
1067
|
-
const [sysParams, __] = await init(
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
...iusdInitialAssetCfg
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1123
|
+
const [sysParams, __] = await init(
|
|
1124
|
+
context.lucid,
|
|
1125
|
+
[
|
|
1126
|
+
{
|
|
1127
|
+
...iusdInitialAssetCfg,
|
|
1128
|
+
priceOracle: {
|
|
1129
|
+
...iusdInitialAssetCfg.priceOracle,
|
|
1130
|
+
startPrice: 1_037_093n,
|
|
1131
|
+
},
|
|
1132
|
+
interestOracle: {
|
|
1133
|
+
...iusdInitialAssetCfg.interestOracle,
|
|
1134
|
+
initialInterestRate: 0n,
|
|
1135
|
+
},
|
|
1136
|
+
maintenanceRatioPercentage: 150_000_000n,
|
|
1137
|
+
debtMintingFeePercentage: 1_300_000n,
|
|
1138
|
+
redemptionReimbursementPercentage: 1_000_000n,
|
|
1077
1139
|
},
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
},
|
|
1082
|
-
]);
|
|
1140
|
+
],
|
|
1141
|
+
context.emulator.slot,
|
|
1142
|
+
);
|
|
1083
1143
|
|
|
1084
1144
|
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
1085
1145
|
|
|
1086
|
-
await
|
|
1146
|
+
await openBuyRobs(
|
|
1087
1147
|
context,
|
|
1088
1148
|
sysParams,
|
|
1089
1149
|
iasset,
|
|
@@ -1101,13 +1161,18 @@ describe('LRP leverage', () => {
|
|
|
1101
1161
|
toText(iasset),
|
|
1102
1162
|
);
|
|
1103
1163
|
|
|
1164
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
1165
|
+
context.lucid,
|
|
1166
|
+
orefs.iasset,
|
|
1167
|
+
);
|
|
1168
|
+
|
|
1104
1169
|
const baseCollateral = 100_000_000n;
|
|
1105
1170
|
await runAndAwaitTx(
|
|
1106
1171
|
context.lucid,
|
|
1107
1172
|
leverageCdpWithLrp(
|
|
1108
1173
|
2.3,
|
|
1109
1174
|
baseCollateral,
|
|
1110
|
-
|
|
1175
|
+
priceOracleUtxo,
|
|
1111
1176
|
orefs.iasset.utxo,
|
|
1112
1177
|
orefs.cdpCreatorUtxo,
|
|
1113
1178
|
orefs.interestOracleUtxo,
|
|
@@ -1142,8 +1207,7 @@ describe('LRP leverage', () => {
|
|
|
1142
1207
|
assertValueInRange(
|
|
1143
1208
|
cdpCollateralRatioPercentage(
|
|
1144
1209
|
context.emulator.slot,
|
|
1145
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1146
|
-
.price,
|
|
1210
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1147
1211
|
res.utxo,
|
|
1148
1212
|
res.datum,
|
|
1149
1213
|
parseInterestOracleDatum(
|
|
@@ -1160,7 +1224,7 @@ describe('LRP leverage', () => {
|
|
|
1160
1224
|
{
|
|
1161
1225
|
const lrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1162
1226
|
expect(
|
|
1163
|
-
lrps.every((lrp) =>
|
|
1227
|
+
lrps.every((lrp) => hadRobRedemption(lrp, sysParams.lrpParams)),
|
|
1164
1228
|
).toBeTruthy();
|
|
1165
1229
|
}
|
|
1166
1230
|
});
|
|
@@ -1168,26 +1232,30 @@ describe('LRP leverage', () => {
|
|
|
1168
1232
|
test<MyContext>('Open 1.2x leveraged CDP 3 LRPs price ~1.46; f_r=.02; f_m=.007', async (context: MyContext) => {
|
|
1169
1233
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
1170
1234
|
|
|
1171
|
-
const [sysParams, __] = await init(
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
...iusdInitialAssetCfg
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1235
|
+
const [sysParams, __] = await init(
|
|
1236
|
+
context.lucid,
|
|
1237
|
+
[
|
|
1238
|
+
{
|
|
1239
|
+
...iusdInitialAssetCfg,
|
|
1240
|
+
priceOracle: {
|
|
1241
|
+
...iusdInitialAssetCfg.priceOracle,
|
|
1242
|
+
startPrice: 1_461_093n,
|
|
1243
|
+
},
|
|
1244
|
+
interestOracle: {
|
|
1245
|
+
...iusdInitialAssetCfg.interestOracle,
|
|
1246
|
+
initialInterestRate: 0n,
|
|
1247
|
+
},
|
|
1248
|
+
maintenanceRatioPercentage: 150_000_000n,
|
|
1249
|
+
debtMintingFeePercentage: 700_000n,
|
|
1250
|
+
redemptionReimbursementPercentage: 2_000_000n,
|
|
1181
1251
|
},
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
},
|
|
1186
|
-
]);
|
|
1252
|
+
],
|
|
1253
|
+
context.emulator.slot,
|
|
1254
|
+
);
|
|
1187
1255
|
|
|
1188
1256
|
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
1189
1257
|
|
|
1190
|
-
await
|
|
1258
|
+
await openBuyRobs(
|
|
1191
1259
|
context,
|
|
1192
1260
|
sysParams,
|
|
1193
1261
|
iasset,
|
|
@@ -1205,13 +1273,18 @@ describe('LRP leverage', () => {
|
|
|
1205
1273
|
toText(iasset),
|
|
1206
1274
|
);
|
|
1207
1275
|
|
|
1276
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
1277
|
+
context.lucid,
|
|
1278
|
+
orefs.iasset,
|
|
1279
|
+
);
|
|
1280
|
+
|
|
1208
1281
|
const baseCollateral = 1_000_000_000n;
|
|
1209
1282
|
await runAndAwaitTx(
|
|
1210
1283
|
context.lucid,
|
|
1211
1284
|
leverageCdpWithLrp(
|
|
1212
1285
|
1.2,
|
|
1213
1286
|
baseCollateral,
|
|
1214
|
-
|
|
1287
|
+
priceOracleUtxo,
|
|
1215
1288
|
orefs.iasset.utxo,
|
|
1216
1289
|
orefs.cdpCreatorUtxo,
|
|
1217
1290
|
orefs.interestOracleUtxo,
|
|
@@ -1246,8 +1319,7 @@ describe('LRP leverage', () => {
|
|
|
1246
1319
|
assertValueInRange(
|
|
1247
1320
|
cdpCollateralRatioPercentage(
|
|
1248
1321
|
context.emulator.slot,
|
|
1249
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1250
|
-
.price,
|
|
1322
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1251
1323
|
res.utxo,
|
|
1252
1324
|
res.datum,
|
|
1253
1325
|
parseInterestOracleDatum(
|
|
@@ -1264,7 +1336,7 @@ describe('LRP leverage', () => {
|
|
|
1264
1336
|
{
|
|
1265
1337
|
const lrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1266
1338
|
expect(
|
|
1267
|
-
lrps.every((lrp) =>
|
|
1339
|
+
lrps.every((lrp) => hadRobRedemption(lrp, sysParams.lrpParams)),
|
|
1268
1340
|
).toBeTruthy();
|
|
1269
1341
|
}
|
|
1270
1342
|
});
|
|
@@ -1272,26 +1344,30 @@ describe('LRP leverage', () => {
|
|
|
1272
1344
|
test<MyContext>('Open max leverage leveraged CDP; 4 CDPs; price 1; f_r=.01; f_m=.005', async (context: MyContext) => {
|
|
1273
1345
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
1274
1346
|
|
|
1275
|
-
const [sysParams, __] = await init(
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
...iusdInitialAssetCfg
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1347
|
+
const [sysParams, __] = await init(
|
|
1348
|
+
context.lucid,
|
|
1349
|
+
[
|
|
1350
|
+
{
|
|
1351
|
+
...iusdInitialAssetCfg,
|
|
1352
|
+
priceOracle: {
|
|
1353
|
+
...iusdInitialAssetCfg.priceOracle,
|
|
1354
|
+
startPrice: 1_000_000n,
|
|
1355
|
+
},
|
|
1356
|
+
interestOracle: {
|
|
1357
|
+
...iusdInitialAssetCfg.interestOracle,
|
|
1358
|
+
initialInterestRate: 0n,
|
|
1359
|
+
},
|
|
1360
|
+
maintenanceRatioPercentage: 150_000_000n,
|
|
1361
|
+
debtMintingFeePercentage: 500_000n,
|
|
1362
|
+
redemptionReimbursementPercentage: 1_000_000n,
|
|
1285
1363
|
},
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
},
|
|
1290
|
-
]);
|
|
1364
|
+
],
|
|
1365
|
+
context.emulator.slot,
|
|
1366
|
+
);
|
|
1291
1367
|
|
|
1292
1368
|
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
1293
1369
|
|
|
1294
|
-
await
|
|
1370
|
+
await openBuyRobs(
|
|
1295
1371
|
context,
|
|
1296
1372
|
sysParams,
|
|
1297
1373
|
iasset,
|
|
@@ -1309,24 +1385,29 @@ describe('LRP leverage', () => {
|
|
|
1309
1385
|
toText(iasset),
|
|
1310
1386
|
);
|
|
1311
1387
|
|
|
1388
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
1389
|
+
context.lucid,
|
|
1390
|
+
orefs.iasset,
|
|
1391
|
+
);
|
|
1392
|
+
|
|
1312
1393
|
const baseCollateral = 1_000_000_000n;
|
|
1313
1394
|
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
1314
|
-
iasset,
|
|
1395
|
+
fromHex(iasset),
|
|
1315
1396
|
orefs.iasset.datum.maintenanceRatio,
|
|
1316
1397
|
baseCollateral,
|
|
1317
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1398
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1318
1399
|
orefs.iasset.datum.debtMintingFeePercentage,
|
|
1319
1400
|
orefs.iasset.datum.redemptionReimbursementPercentage,
|
|
1320
1401
|
sysParams.lrpParams,
|
|
1321
1402
|
allLrps.map((lrps) => [lrps.utxo, lrps.datum]),
|
|
1322
1403
|
)!;
|
|
1323
1404
|
|
|
1324
|
-
await
|
|
1325
|
-
|
|
1326
|
-
leverageCdpWithLrp(
|
|
1405
|
+
await benchmarkAndAwaitTx(
|
|
1406
|
+
'Leverage - CDP open with 4 LRP',
|
|
1407
|
+
await leverageCdpWithLrp(
|
|
1327
1408
|
maxLeverage,
|
|
1328
1409
|
baseCollateral,
|
|
1329
|
-
|
|
1410
|
+
priceOracleUtxo,
|
|
1330
1411
|
orefs.iasset.utxo,
|
|
1331
1412
|
orefs.cdpCreatorUtxo,
|
|
1332
1413
|
orefs.interestOracleUtxo,
|
|
@@ -1336,6 +1417,8 @@ describe('LRP leverage', () => {
|
|
|
1336
1417
|
allLrps.map((lrps) => [lrps.utxo, lrps.datum]),
|
|
1337
1418
|
context.emulator.slot,
|
|
1338
1419
|
),
|
|
1420
|
+
context.lucid,
|
|
1421
|
+
context.emulator,
|
|
1339
1422
|
);
|
|
1340
1423
|
|
|
1341
1424
|
const [pkh, skh] = await addrDetails(context.lucid);
|
|
@@ -1361,8 +1444,7 @@ describe('LRP leverage', () => {
|
|
|
1361
1444
|
assertValueInRange(
|
|
1362
1445
|
cdpCollateralRatioPercentage(
|
|
1363
1446
|
context.emulator.slot,
|
|
1364
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1365
|
-
.price,
|
|
1447
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1366
1448
|
res.utxo,
|
|
1367
1449
|
res.datum,
|
|
1368
1450
|
parseInterestOracleDatum(
|
|
@@ -1379,7 +1461,7 @@ describe('LRP leverage', () => {
|
|
|
1379
1461
|
{
|
|
1380
1462
|
const lrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1381
1463
|
expect(
|
|
1382
|
-
lrps.every((lrp) =>
|
|
1464
|
+
lrps.every((lrp) => hadRobRedemption(lrp, sysParams.lrpParams)),
|
|
1383
1465
|
).toBeTruthy();
|
|
1384
1466
|
}
|
|
1385
1467
|
});
|
|
@@ -1387,28 +1469,38 @@ describe('LRP leverage', () => {
|
|
|
1387
1469
|
test<MyContext>('Open max leverage leveraged CDP; 2 CDPs; price 2.5; f_r=.014; f_m=.006', async (context: MyContext) => {
|
|
1388
1470
|
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
1389
1471
|
|
|
1390
|
-
const [sysParams, __] = await init(
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
...iusdInitialAssetCfg
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1472
|
+
const [sysParams, __] = await init(
|
|
1473
|
+
context.lucid,
|
|
1474
|
+
[
|
|
1475
|
+
{
|
|
1476
|
+
...iusdInitialAssetCfg,
|
|
1477
|
+
priceOracle: {
|
|
1478
|
+
...iusdInitialAssetCfg.priceOracle,
|
|
1479
|
+
startPrice: 2_500_000n,
|
|
1480
|
+
},
|
|
1481
|
+
interestOracle: {
|
|
1482
|
+
...iusdInitialAssetCfg.interestOracle,
|
|
1483
|
+
initialInterestRate: 0n,
|
|
1484
|
+
},
|
|
1485
|
+
maintenanceRatioPercentage: 130_000_000n,
|
|
1486
|
+
debtMintingFeePercentage: 600_000n,
|
|
1487
|
+
redemptionReimbursementPercentage: 1_400_000n,
|
|
1400
1488
|
},
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
},
|
|
1405
|
-
]);
|
|
1489
|
+
],
|
|
1490
|
+
context.emulator.slot,
|
|
1491
|
+
);
|
|
1406
1492
|
|
|
1407
1493
|
const iasset = fromText(iusdInitialAssetCfg.name);
|
|
1408
1494
|
|
|
1409
|
-
await
|
|
1410
|
-
|
|
1411
|
-
|
|
1495
|
+
await openBuyRobs(
|
|
1496
|
+
context,
|
|
1497
|
+
sysParams,
|
|
1498
|
+
iasset,
|
|
1499
|
+
[325_000_000n, 325_000_000n],
|
|
1500
|
+
{
|
|
1501
|
+
getOnChainInt: 3_000_000n,
|
|
1502
|
+
},
|
|
1503
|
+
);
|
|
1412
1504
|
|
|
1413
1505
|
const allLrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1414
1506
|
|
|
@@ -1418,12 +1510,17 @@ describe('LRP leverage', () => {
|
|
|
1418
1510
|
toText(iasset),
|
|
1419
1511
|
);
|
|
1420
1512
|
|
|
1513
|
+
const priceOracleUtxo = await findPriceOracleFromCollateralAsset(
|
|
1514
|
+
context.lucid,
|
|
1515
|
+
orefs.iasset,
|
|
1516
|
+
);
|
|
1517
|
+
|
|
1421
1518
|
const baseCollateral = 200_000_000n;
|
|
1422
1519
|
const maxLeverage = calculateLeverageFromCollateralRatio(
|
|
1423
|
-
iasset,
|
|
1520
|
+
fromHex(iasset),
|
|
1424
1521
|
orefs.iasset.datum.maintenanceRatio,
|
|
1425
1522
|
baseCollateral,
|
|
1426
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1523
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1427
1524
|
orefs.iasset.datum.debtMintingFeePercentage,
|
|
1428
1525
|
orefs.iasset.datum.redemptionReimbursementPercentage,
|
|
1429
1526
|
sysParams.lrpParams,
|
|
@@ -1435,7 +1532,7 @@ describe('LRP leverage', () => {
|
|
|
1435
1532
|
leverageCdpWithLrp(
|
|
1436
1533
|
maxLeverage,
|
|
1437
1534
|
baseCollateral,
|
|
1438
|
-
|
|
1535
|
+
priceOracleUtxo,
|
|
1439
1536
|
orefs.iasset.utxo,
|
|
1440
1537
|
orefs.cdpCreatorUtxo,
|
|
1441
1538
|
orefs.interestOracleUtxo,
|
|
@@ -1470,8 +1567,7 @@ describe('LRP leverage', () => {
|
|
|
1470
1567
|
assertValueInRange(
|
|
1471
1568
|
cdpCollateralRatioPercentage(
|
|
1472
1569
|
context.emulator.slot,
|
|
1473
|
-
parsePriceOracleDatum(getInlineDatumOrThrow(
|
|
1474
|
-
.price,
|
|
1570
|
+
parsePriceOracleDatum(getInlineDatumOrThrow(priceOracleUtxo)).price,
|
|
1475
1571
|
res.utxo,
|
|
1476
1572
|
res.datum,
|
|
1477
1573
|
parseInterestOracleDatum(
|
|
@@ -1488,8 +1584,9 @@ describe('LRP leverage', () => {
|
|
|
1488
1584
|
{
|
|
1489
1585
|
const lrps = await findAllLrps(context.lucid, sysParams, iasset);
|
|
1490
1586
|
expect(
|
|
1491
|
-
lrps.every((lrp) =>
|
|
1587
|
+
lrps.every((lrp) => hadRobRedemption(lrp, sysParams.lrpParams)),
|
|
1492
1588
|
).toBeTruthy();
|
|
1493
1589
|
}
|
|
1494
1590
|
});
|
|
1495
1591
|
});
|
|
1592
|
+
*/
|