@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Indigo SDK for interacting with Indigo endpoints via lucid-evolution",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -40,13 +40,18 @@
|
|
|
40
40
|
"author": "3rd Eye Labs",
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@3rd-eye-labs/cardano-offchain-common": "
|
|
44
|
-
"@evolution-sdk/evolution": "^0.
|
|
43
|
+
"@3rd-eye-labs/cardano-offchain-common": "1.2.0",
|
|
44
|
+
"@evolution-sdk/evolution": "^0.3.22",
|
|
45
45
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
46
46
|
"@lucid-evolution/lucid": "^0.4.29",
|
|
47
|
+
"@noble/ed25519": "^3.0.0",
|
|
48
|
+
"@pythnetwork/pyth-lazer-sdk": "^6.0.0",
|
|
47
49
|
"decimal.js": "^10.6.0",
|
|
48
50
|
"dotenv": "^16.5.0",
|
|
51
|
+
"effect": "^3.19.18",
|
|
49
52
|
"fp-ts": "^2.16.10",
|
|
53
|
+
"json-with-bigint": "3.5.3",
|
|
54
|
+
"libsodium-wrappers-sumo": "^0.8.2",
|
|
50
55
|
"ts-pattern": "^5.8.0"
|
|
51
56
|
},
|
|
52
57
|
"devDependencies": {
|
|
@@ -64,5 +69,11 @@
|
|
|
64
69
|
"typescript": "^5.9.2",
|
|
65
70
|
"typescript-eslint": "^8.39.0",
|
|
66
71
|
"vitest": "^4.0.14"
|
|
72
|
+
},
|
|
73
|
+
"pnpm": {
|
|
74
|
+
"overrides": {
|
|
75
|
+
"libsodium-wrappers-sumo": "0.8.2",
|
|
76
|
+
"libsodium-sumo": "0.8.2"
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import {
|
|
3
|
-
OCD_DECIMAL_UNIT,
|
|
4
|
-
ocdAdd,
|
|
5
|
-
ocdCeil,
|
|
6
|
-
ocdDiv,
|
|
7
|
-
ocdMul,
|
|
8
|
-
ocdNegate,
|
|
9
|
-
ocdSub,
|
|
10
|
-
OnChainDecimal,
|
|
11
|
-
} from '../../types/on-chain-decimal';
|
|
12
1
|
import { Network, slotToUnixTime, UTxO } from '@lucid-evolution/lucid';
|
|
13
|
-
import { CDPContent } from './types';
|
|
14
2
|
import { calculateAccruedInterest } from '../interest-oracle/helpers';
|
|
15
3
|
import { match, P } from 'ts-pattern';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
4
|
+
import { calculateFeeFromRatio } from '../../utils/indigo-helpers';
|
|
5
|
+
import { assetClassValueOf } from '@3rd-eye-labs/cardano-offchain-common';
|
|
6
|
+
import { InterestOracleDatum } from '../interest-oracle/types-new';
|
|
7
|
+
import { CDPContent } from './types-new';
|
|
8
|
+
import {
|
|
9
|
+
Rational,
|
|
10
|
+
rationalAdd,
|
|
11
|
+
rationalCeil,
|
|
12
|
+
rationalDiv,
|
|
13
|
+
rationalFloor,
|
|
14
|
+
rationalFromInt,
|
|
15
|
+
rationalMul,
|
|
16
|
+
rationalNegate,
|
|
17
|
+
rationalSub,
|
|
18
|
+
} from '../../types/rational';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* This is mostly for debugging purposes.
|
|
22
22
|
*/
|
|
23
23
|
export function cdpCollateralRatioPercentage(
|
|
24
24
|
currentSlot: number,
|
|
25
|
-
iassetPrice:
|
|
25
|
+
iassetPrice: Rational,
|
|
26
26
|
cdpUtxo: UTxO,
|
|
27
27
|
cdpContent: CDPContent,
|
|
28
28
|
interestOracleDatum: InterestOracleDatum,
|
|
@@ -32,29 +32,28 @@ export function cdpCollateralRatioPercentage(
|
|
|
32
32
|
|
|
33
33
|
return match(cdpContent.cdpFees)
|
|
34
34
|
.with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
interestOracleDatum,
|
|
43
|
-
),
|
|
44
|
-
},
|
|
45
|
-
iassetPrice,
|
|
46
|
-
).getOnChainInt;
|
|
35
|
+
const interestAmt = calculateAccruedInterest(
|
|
36
|
+
currentTime,
|
|
37
|
+
interest.unitaryInterestSnapshot,
|
|
38
|
+
cdpContent.mintedAmt,
|
|
39
|
+
interest.lastSettled,
|
|
40
|
+
interestOracleDatum,
|
|
41
|
+
);
|
|
47
42
|
|
|
48
|
-
const collateral =
|
|
43
|
+
const collateral = assetClassValueOf(
|
|
44
|
+
cdpUtxo.assets,
|
|
45
|
+
cdpContent.collateralAsset,
|
|
46
|
+
);
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
) / Number(OCD_DECIMAL_UNIT)
|
|
48
|
+
const ratio = rationalDiv(
|
|
49
|
+
rationalFromInt(collateral),
|
|
50
|
+
rationalMul(
|
|
51
|
+
rationalFromInt(cdpContent.mintedAmt + interestAmt),
|
|
52
|
+
iassetPrice,
|
|
53
|
+
),
|
|
57
54
|
);
|
|
55
|
+
|
|
56
|
+
return Number((ratio.numerator * 100n) / ratio.denominator);
|
|
58
57
|
})
|
|
59
58
|
.with({ FrozenCDPAccumulatedFees: P.any }, () => 0)
|
|
60
59
|
.exhaustive();
|
|
@@ -66,29 +65,16 @@ export function cdpCollateralRatioPercentage(
|
|
|
66
65
|
export function calculateIAssetRedemptionAmt(
|
|
67
66
|
collateralAmt: bigint,
|
|
68
67
|
mintedAmt: bigint,
|
|
69
|
-
price:
|
|
70
|
-
rmr:
|
|
68
|
+
price: Rational,
|
|
69
|
+
rmr: Rational,
|
|
71
70
|
): bigint {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
),
|
|
80
|
-
ocdDiv(
|
|
81
|
-
ocdMul(rmr, { getOnChainInt: mintedAmt * OCD_DECIMAL_UNIT }),
|
|
82
|
-
hundred,
|
|
83
|
-
),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
return ocdCeil(
|
|
87
|
-
ocdDiv(
|
|
88
|
-
res,
|
|
89
|
-
ocdSub(ocdDiv(rmr, hundred), {
|
|
90
|
-
getOnChainInt: OCD_DECIMAL_UNIT,
|
|
91
|
-
}),
|
|
71
|
+
return rationalCeil(
|
|
72
|
+
rationalDiv(
|
|
73
|
+
rationalAdd(
|
|
74
|
+
rationalNegate(rationalDiv(rationalFromInt(collateralAmt), price)),
|
|
75
|
+
rationalMul(rmr, rationalFromInt(mintedAmt)),
|
|
76
|
+
),
|
|
77
|
+
rationalSub(rmr, rationalFromInt(1n)),
|
|
92
78
|
),
|
|
93
79
|
);
|
|
94
80
|
}
|
|
@@ -113,9 +99,9 @@ export function calculateIAssetRedemptionAmt(
|
|
|
113
99
|
export function calculateMinCollateralCappedIAssetRedemptionAmt(
|
|
114
100
|
collateralAmt: bigint,
|
|
115
101
|
mintedAmt: bigint,
|
|
116
|
-
price:
|
|
117
|
-
rmr:
|
|
118
|
-
|
|
102
|
+
price: Rational,
|
|
103
|
+
rmr: Rational,
|
|
104
|
+
reimbursementRatio: Rational,
|
|
119
105
|
minCollateral: bigint,
|
|
120
106
|
): {
|
|
121
107
|
uncappedIAssetRedemptionAmt: bigint;
|
|
@@ -127,12 +113,12 @@ export function calculateMinCollateralCappedIAssetRedemptionAmt(
|
|
|
127
113
|
price,
|
|
128
114
|
rmr,
|
|
129
115
|
);
|
|
130
|
-
const uncappedMaxRedemptionLovelacesAmt =
|
|
131
|
-
|
|
132
|
-
|
|
116
|
+
const uncappedMaxRedemptionLovelacesAmt = rationalFloor(
|
|
117
|
+
rationalMul(price, rationalFromInt(uncappedMaxIAssetRedemptionAmt)),
|
|
118
|
+
);
|
|
133
119
|
|
|
134
|
-
const maxReimburstment =
|
|
135
|
-
|
|
120
|
+
const maxReimburstment = calculateFeeFromRatio(
|
|
121
|
+
reimbursementRatio,
|
|
136
122
|
uncappedMaxRedemptionLovelacesAmt,
|
|
137
123
|
);
|
|
138
124
|
|
|
@@ -152,16 +138,26 @@ export function calculateMinCollateralCappedIAssetRedemptionAmt(
|
|
|
152
138
|
cappedIAssetRedemptionAmt: 0n,
|
|
153
139
|
};
|
|
154
140
|
} else {
|
|
155
|
-
const resLovelaces =
|
|
156
|
-
(minCollateral - collateralAmt)
|
|
157
|
-
|
|
158
|
-
const resIAsset = resLovelaces.div(
|
|
159
|
-
Decimal(price.getOnChainInt).div(OCD_DECIMAL_UNIT),
|
|
141
|
+
const resLovelaces = rationalDiv(
|
|
142
|
+
rationalFromInt(minCollateral - collateralAmt),
|
|
143
|
+
rationalSub(reimbursementRatio, rationalFromInt(1n)),
|
|
160
144
|
);
|
|
145
|
+
const resIAsset = rationalDiv(resLovelaces, price);
|
|
161
146
|
|
|
162
147
|
return {
|
|
163
148
|
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
164
|
-
cappedIAssetRedemptionAmt:
|
|
149
|
+
cappedIAssetRedemptionAmt: rationalFloor(resIAsset),
|
|
165
150
|
};
|
|
166
151
|
}
|
|
167
152
|
}
|
|
153
|
+
|
|
154
|
+
export function adjustPriceToDecimals(
|
|
155
|
+
extraDecimals: bigint,
|
|
156
|
+
price: Rational,
|
|
157
|
+
): Rational {
|
|
158
|
+
return extraDecimals === 0n
|
|
159
|
+
? price
|
|
160
|
+
: extraDecimals > 0n
|
|
161
|
+
? rationalMul(price, rationalFromInt(10n ** extraDecimals))
|
|
162
|
+
: rationalDiv(price, rationalFromInt(10n ** -extraDecimals));
|
|
163
|
+
}
|
|
@@ -1,32 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
applyParamsToScript,
|
|
3
|
+
SpendingValidator,
|
|
4
|
+
WithdrawalValidator,
|
|
5
|
+
} from '@lucid-evolution/lucid';
|
|
6
|
+
import {
|
|
7
|
+
CdpParamsSP,
|
|
8
|
+
CdpRedeemParamsSP,
|
|
9
|
+
fromSystemParamsAssetLucid,
|
|
10
|
+
} from '../../types/system-params';
|
|
11
|
+
import { castCdpParams, castCdpRedeemParams } from './types';
|
|
4
12
|
import { _cdpValidator } from '../../validators/cdp-validator';
|
|
13
|
+
import { _cdpRedeemValidator } from '../../validators/cdp-redeem-validator';
|
|
5
14
|
|
|
6
15
|
export const mkCdpValidatorFromSP = (
|
|
7
16
|
params: CdpParamsSP,
|
|
8
17
|
): SpendingValidator => {
|
|
9
18
|
return {
|
|
10
|
-
type: '
|
|
19
|
+
type: 'PlutusV3',
|
|
11
20
|
script: applyParamsToScript(_cdpValidator.cborHex, [
|
|
12
21
|
castCdpParams({
|
|
13
|
-
cdp_auth_token:
|
|
22
|
+
cdp_auth_token: fromSystemParamsAssetLucid(params.cdpAuthToken),
|
|
14
23
|
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
15
|
-
iasset_auth_token:
|
|
16
|
-
|
|
24
|
+
iasset_auth_token: fromSystemParamsAssetLucid(params.iAssetAuthToken),
|
|
25
|
+
collateral_asset_auth_token: fromSystemParamsAssetLucid(
|
|
26
|
+
params.collateralAssetAuthToken,
|
|
27
|
+
),
|
|
28
|
+
stability_pool_auth_token: fromSystemParamsAssetLucid(
|
|
17
29
|
params.stabilityPoolAuthToken,
|
|
18
30
|
),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
upgrade_token: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
32
|
+
version_record_token: fromSystemParamsAssetLucid(
|
|
33
|
+
params.versionRecordToken,
|
|
34
|
+
),
|
|
35
|
+
interest_collector_val_hash: params.interestCollectorValHash,
|
|
22
36
|
sp_val_hash: params.spValHash,
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
iasset_val_hash: params.iassetValHash,
|
|
38
|
+
treasury_val_hash: params.treasuryValHash,
|
|
39
|
+
cdp_redeem_val_hash: params.cdpRedeemValHash,
|
|
40
|
+
bias_time: BigInt(params.biasTime),
|
|
41
|
+
}),
|
|
42
|
+
]),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const mkCdpRedeemValidatorFromSP = (
|
|
47
|
+
params: CdpRedeemParamsSP,
|
|
48
|
+
): WithdrawalValidator => {
|
|
49
|
+
return {
|
|
50
|
+
type: 'PlutusV3',
|
|
51
|
+
script: applyParamsToScript(_cdpRedeemValidator.cborHex, [
|
|
52
|
+
castCdpRedeemParams({
|
|
53
|
+
cdp_auth_token: fromSystemParamsAssetLucid(params.cdpAuthToken),
|
|
54
|
+
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
55
|
+
iasset_auth_token: fromSystemParamsAssetLucid(params.iAssetAuthToken),
|
|
56
|
+
collateral_asset_auth_token: fromSystemParamsAssetLucid(
|
|
57
|
+
params.collateralAssetAuthToken,
|
|
58
|
+
),
|
|
59
|
+
interest_collector_val_hash: params.interestCollectorValHash,
|
|
60
|
+
iasset_val_hash: params.iassetValHash,
|
|
61
|
+
treasury_val_hash: params.treasuryValHash,
|
|
62
|
+
gov_nft: fromSystemParamsAssetLucid(params.govNFT),
|
|
25
63
|
partial_redemption_extra_fee_lovelace: BigInt(
|
|
26
64
|
params.partialRedemptionExtraFeeLovelace,
|
|
27
65
|
),
|
|
28
66
|
bias_time: BigInt(params.biasTime),
|
|
29
|
-
treasury_val_hash: params.treasuryValHash,
|
|
30
67
|
}),
|
|
31
68
|
]),
|
|
32
69
|
};
|