@indigo-labs/indigo-sdk 0.1.27 → 0.2.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 +8 -3
- package/dist/index.d.mts +1300 -671
- package/dist/index.d.ts +1300 -671
- package/dist/index.js +4663 -2214
- package/dist/index.mjs +4594 -2184
- package/eslint.config.mjs +7 -1
- package/package.json +9 -4
- package/src/contracts/cdp/helpers.ts +167 -0
- package/src/contracts/cdp/scripts.ts +33 -0
- package/src/contracts/cdp/transactions.ts +1310 -0
- package/src/contracts/cdp/types.ts +161 -0
- package/src/contracts/cdp-creator/scripts.ts +39 -0
- package/src/{types/indigo/cdp-creator.ts → contracts/cdp-creator/types.ts} +6 -4
- package/src/contracts/collector/scripts.ts +32 -0
- package/src/contracts/collector/transactions.ts +44 -0
- package/src/contracts/execute/scripts.ts +48 -0
- package/src/contracts/execute/types.ts +57 -0
- package/src/contracts/gov/helpers.ts +157 -0
- package/src/contracts/gov/scripts.ts +34 -0
- package/src/contracts/gov/transactions.ts +1224 -0
- package/src/contracts/gov/types-new.ts +115 -0
- package/src/contracts/gov/types.ts +89 -0
- package/src/{helpers/interest-oracle.ts → contracts/interest-oracle/helpers.ts} +37 -9
- package/src/contracts/interest-oracle/scripts.ts +18 -0
- package/src/contracts/interest-oracle/transactions.ts +149 -0
- package/src/{types/indigo/interest-oracle.ts → contracts/interest-oracle/types.ts} +1 -1
- package/src/contracts/lrp/scripts.ts +27 -0
- package/src/contracts/{lrp.ts → lrp/transactions.ts} +14 -14
- package/src/{types/indigo/lrp.ts → contracts/lrp/types.ts} +2 -2
- package/src/{scripts/one-shot-policy.ts → contracts/one-shot/scripts.ts} +1 -1
- package/src/contracts/{one-shot.ts → one-shot/transactions.ts} +3 -3
- package/src/contracts/poll/helpers.ts +55 -0
- package/src/contracts/poll/scripts.ts +72 -0
- package/src/contracts/poll/types-poll-manager.ts +38 -0
- package/src/contracts/poll/types-poll-shard.ts +38 -0
- package/src/contracts/poll/types-poll.ts +88 -0
- package/src/{scripts/price-oracle-validator.ts → contracts/price-oracle/scripts.ts} +1 -4
- package/src/contracts/price-oracle/transactions.ts +112 -0
- package/src/{types/indigo/price-oracle.ts → contracts/price-oracle/types.ts} +16 -4
- package/src/{helpers/stability-pool-helpers.ts → contracts/stability-pool/helpers.ts} +110 -6
- package/src/contracts/stability-pool/scripts.ts +46 -0
- package/src/contracts/stability-pool/transactions.ts +676 -0
- package/src/contracts/stability-pool/types-new.ts +208 -0
- package/src/contracts/stability-pool/types.ts +42 -0
- package/src/contracts/staking/helpers.ts +116 -0
- package/src/contracts/staking/scripts.ts +41 -0
- package/src/contracts/staking/transactions.ts +268 -0
- package/src/contracts/staking/types-new.ts +81 -0
- package/src/contracts/staking/types.ts +41 -0
- package/src/contracts/treasury/scripts.ts +37 -0
- package/src/contracts/treasury/transactions.ts +44 -0
- package/src/contracts/treasury/types.ts +55 -0
- package/src/contracts/version-registry/scripts.ts +29 -0
- package/src/contracts/version-registry/types-new.ts +19 -0
- package/src/{types/indigo/version-record.ts → contracts/version-registry/types.ts} +1 -1
- package/src/contracts/vesting/helpers.ts +267 -0
- package/src/index.ts +39 -33
- package/src/types/evolution-schema-options.ts +16 -0
- package/src/types/generic.ts +78 -60
- package/src/types/on-chain-decimal.ts +22 -0
- package/src/types/system-params.ts +22 -11
- package/src/utils/bigint-utils.ts +7 -0
- package/src/{helpers → utils}/helper-txs.ts +1 -0
- package/src/utils/time-helpers.ts +4 -0
- package/src/{helpers/helpers.ts → utils/utils.ts} +0 -10
- package/src/{helpers → utils}/value-helpers.ts +10 -0
- package/src/{scripts → validators}/cdp-creator-validator.ts +4 -50
- package/src/{scripts → validators}/cdp-validator.ts +3 -5
- package/src/{scripts → validators}/collector-validator.ts +2 -3
- package/src/{scripts/version-registry.ts → validators/execute-validator.ts} +3 -11
- package/src/{scripts/gov-validator.ts → validators/governance-validator.ts} +3 -40
- package/src/{scripts → validators}/interest-oracle-validator.ts +4 -20
- package/src/validators/lrp-validator.ts +7 -0
- package/src/validators/poll-manager-validator.ts +7 -0
- package/src/{scripts → validators}/poll-shard-validator.ts +3 -43
- package/src/{scripts → validators}/stability-pool-validator.ts +4 -57
- package/src/{scripts → validators}/staking-validator.ts +2 -3
- package/src/{scripts → validators}/treasury-validator.ts +2 -3
- package/src/{scripts → validators}/version-record-policy.ts +4 -23
- package/src/validators/version-registry-validator.ts +7 -0
- package/tests/cdp.test.ts +1565 -0
- package/tests/datums.test.ts +125 -108
- package/tests/endpoints/initialize.ts +240 -338
- package/tests/gov.test.ts +1874 -0
- package/tests/hash-checks.test.ts +26 -21
- package/tests/indigo-test-helpers.ts +1 -55
- package/tests/initialize.test.ts +10 -5
- package/tests/interest-calculations.test.ts +18 -18
- package/tests/interest-oracle.test.ts +20 -18
- package/tests/lrp.test.ts +191 -65
- package/tests/mock/assets-mock.ts +59 -0
- package/tests/queries/cdp-queries.ts +144 -0
- package/tests/queries/collector-queries.ts +26 -0
- package/tests/queries/execute-queries.ts +46 -0
- package/tests/queries/governance-queries.ts +19 -16
- package/tests/queries/iasset-queries.ts +46 -23
- package/tests/queries/interest-oracle-queries.ts +3 -6
- package/tests/queries/lrp-queries.ts +2 -2
- package/tests/queries/poll-queries.ts +97 -0
- package/tests/queries/price-oracle-queries.ts +5 -22
- package/tests/queries/stability-pool-queries.ts +10 -8
- package/tests/queries/staking-queries.ts +28 -19
- package/tests/queries/treasury-queries.ts +19 -0
- package/tests/stability-pool.test.ts +186 -71
- package/tests/staking.test.ts +30 -23
- package/tests/test-helpers.ts +11 -2
- package/tests/utils/asserts.ts +13 -0
- package/tests/utils/index.ts +50 -0
- package/tsconfig.json +3 -1
- package/vitest.config.ts +1 -1
- package/.github/workflows/test.yml +0 -44
- package/src/contracts/cdp.ts +0 -745
- package/src/contracts/collector.ts +0 -98
- package/src/contracts/gov.ts +0 -1
- package/src/contracts/interest-oracle.ts +0 -149
- package/src/contracts/stability-pool.ts +0 -690
- package/src/contracts/staking.ts +0 -348
- package/src/contracts/treasury.ts +0 -112
- package/src/helpers/asset-helpers.ts +0 -62
- package/src/helpers/staking-helpers.ts +0 -94
- package/src/helpers/time-helpers.ts +0 -4
- package/src/scripts/execute-validator.ts +0 -52
- package/src/scripts/lrp-validator.ts +0 -40
- package/src/scripts/poll-manager-validator.ts +0 -52
- package/src/types/indigo/cdp.ts +0 -88
- package/src/types/indigo/execute.ts +0 -21
- package/src/types/indigo/gov.ts +0 -51
- package/src/types/indigo/poll-manager.ts +0 -21
- package/src/types/indigo/poll-shard.ts +0 -16
- package/src/types/indigo/stability-pool.ts +0 -233
- package/src/types/indigo/staking.ts +0 -99
- /package/src/{types/one-shot.ts → contracts/one-shot/types.ts} +0 -0
- /package/src/{helpers/price-oracle-helpers.ts → contracts/price-oracle/helpers.ts} +0 -0
- /package/src/{helpers → utils}/indigo-helpers.ts +0 -0
- /package/src/{helpers → utils}/lucid-utils.ts +0 -0
package/eslint.config.mjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import eslint from '@eslint/js';
|
|
2
2
|
import tseslint from 'typescript-eslint';
|
|
3
|
+
import vitestEslint from '@vitest/eslint-plugin';
|
|
4
|
+
import { defineConfig } from 'eslint/config';
|
|
3
5
|
|
|
4
|
-
export default
|
|
6
|
+
export default defineConfig(
|
|
5
7
|
{
|
|
6
8
|
ignores: ['**/dist/*', '**/node_modules/*'],
|
|
7
9
|
},
|
|
8
10
|
{
|
|
9
11
|
files: ['**/*.ts'],
|
|
10
12
|
extends: [
|
|
13
|
+
// The vitest eslint recommended is important at least because it's easy to forget `expect`'s matcher calls.
|
|
14
|
+
vitestEslint.configs.recommended,
|
|
11
15
|
eslint.configs.recommended,
|
|
12
16
|
tseslint.configs.recommendedTypeChecked,
|
|
13
17
|
{
|
|
@@ -20,8 +24,10 @@ export default tseslint.config(
|
|
|
20
24
|
},
|
|
21
25
|
],
|
|
22
26
|
rules: {
|
|
27
|
+
'vitest/expect-expect': 'off',
|
|
23
28
|
'no-unreachable': 'warn',
|
|
24
29
|
'no-use-before-define': 'error',
|
|
30
|
+
'no-unused-expressions': 'warn',
|
|
25
31
|
'@typescript-eslint/no-unused-vars': [
|
|
26
32
|
'error',
|
|
27
33
|
{
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
|
|
10
|
-
"
|
|
10
|
+
"type-check": "tsc --noEmit",
|
|
11
|
+
"lint": "pnpm eslint .",
|
|
11
12
|
"lint:fix": "npx eslint --fix .",
|
|
12
13
|
"repack": "pnpm run build && pnpm pack",
|
|
13
14
|
"format": "npx prettier --write src/ tests/",
|
|
@@ -39,8 +40,11 @@
|
|
|
39
40
|
"author": "3rd Eye Labs",
|
|
40
41
|
"license": "MIT",
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@
|
|
43
|
+
"@3rd-eye-labs/cardano-offchain-common": "^1.1.6",
|
|
44
|
+
"@evolution-sdk/evolution": "^0.2.5",
|
|
45
|
+
"@harmoniclabs/crypto": "^0.3.0",
|
|
43
46
|
"@lucid-evolution/lucid": "^0.4.29",
|
|
47
|
+
"decimal.js": "^10.6.0",
|
|
44
48
|
"dotenv": "^16.5.0",
|
|
45
49
|
"fp-ts": "^2.16.10",
|
|
46
50
|
"ts-pattern": "^5.8.0"
|
|
@@ -51,6 +55,7 @@
|
|
|
51
55
|
"@babel/preset-typescript": "^7.21.4",
|
|
52
56
|
"@eslint/js": "^9.32.0",
|
|
53
57
|
"@types/node": "^24.3.0",
|
|
58
|
+
"@vitest/eslint-plugin": "^1.5.0",
|
|
54
59
|
"eslint": "^9.32.0",
|
|
55
60
|
"husky": "^9.1.7",
|
|
56
61
|
"lint-staged": "^16.1.5",
|
|
@@ -58,6 +63,6 @@
|
|
|
58
63
|
"tsup": "^8.3.6",
|
|
59
64
|
"typescript": "^5.9.2",
|
|
60
65
|
"typescript-eslint": "^8.39.0",
|
|
61
|
-
"vitest": "
|
|
66
|
+
"vitest": "^4.0.14"
|
|
62
67
|
}
|
|
63
68
|
}
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
import { Network, slotToUnixTime, UTxO } from '@lucid-evolution/lucid';
|
|
13
|
+
import { CDPContent } from './types';
|
|
14
|
+
import { calculateAccruedInterest } from '../interest-oracle/helpers';
|
|
15
|
+
import { match, P } from 'ts-pattern';
|
|
16
|
+
import { InterestOracleDatum } from '../interest-oracle/types';
|
|
17
|
+
import { lovelacesAmt } from '../../utils/value-helpers';
|
|
18
|
+
import { calculateFeeFromPercentage } from '../../utils/indigo-helpers';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This is mostly for debugging purposes.
|
|
22
|
+
*/
|
|
23
|
+
export function cdpCollateralRatioPercentage(
|
|
24
|
+
currentSlot: number,
|
|
25
|
+
iassetPrice: OnChainDecimal,
|
|
26
|
+
cdpUtxo: UTxO,
|
|
27
|
+
cdpContent: CDPContent,
|
|
28
|
+
interestOracleDatum: InterestOracleDatum,
|
|
29
|
+
network: Network,
|
|
30
|
+
): number {
|
|
31
|
+
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
32
|
+
|
|
33
|
+
return match(cdpContent.cdpFees)
|
|
34
|
+
.with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
|
|
35
|
+
const interestAdaAmt = ocdMul(
|
|
36
|
+
{
|
|
37
|
+
getOnChainInt: calculateAccruedInterest(
|
|
38
|
+
currentTime,
|
|
39
|
+
interest.unitaryInterestSnapshot,
|
|
40
|
+
cdpContent.mintedAmt,
|
|
41
|
+
interest.lastSettled,
|
|
42
|
+
interestOracleDatum,
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
iassetPrice,
|
|
46
|
+
).getOnChainInt;
|
|
47
|
+
|
|
48
|
+
const collateral = lovelacesAmt(cdpUtxo.assets) - interestAdaAmt;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
Number(
|
|
52
|
+
ocdDiv(
|
|
53
|
+
{ getOnChainInt: collateral * 100n },
|
|
54
|
+
ocdMul({ getOnChainInt: cdpContent.mintedAmt }, iassetPrice),
|
|
55
|
+
).getOnChainInt,
|
|
56
|
+
) / Number(OCD_DECIMAL_UNIT)
|
|
57
|
+
);
|
|
58
|
+
})
|
|
59
|
+
.with({ FrozenCDPAccumulatedFees: P.any }, () => 0)
|
|
60
|
+
.exhaustive();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The amount of iassets to redeem to reach the RMR.
|
|
65
|
+
*/
|
|
66
|
+
export function calculateIAssetRedemptionAmt(
|
|
67
|
+
collateralAmt: bigint,
|
|
68
|
+
mintedAmt: bigint,
|
|
69
|
+
price: OnChainDecimal,
|
|
70
|
+
rmr: OnChainDecimal,
|
|
71
|
+
): bigint {
|
|
72
|
+
const hundred: OnChainDecimal = {
|
|
73
|
+
getOnChainInt: 100n * OCD_DECIMAL_UNIT,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const res = ocdAdd(
|
|
77
|
+
ocdNegate(
|
|
78
|
+
ocdDiv({ getOnChainInt: collateralAmt * OCD_DECIMAL_UNIT }, price),
|
|
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
|
+
}),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Calculates the allowable redemption amount so the min collateral constraint still holds.
|
|
98
|
+
* It caps the redemption amount to still satisfy the min collateral.
|
|
99
|
+
*
|
|
100
|
+
* Returns uncapped max iassets /\ capped max iassets
|
|
101
|
+
*
|
|
102
|
+
* The derived calculation comes from the following equation where:
|
|
103
|
+
* c - collateral
|
|
104
|
+
* m - min collateral
|
|
105
|
+
* r - reimburstment ratio
|
|
106
|
+
* x - redemption amount
|
|
107
|
+
*
|
|
108
|
+
* `c - x + r * x = m`
|
|
109
|
+
* `-x + r * x = m - c`
|
|
110
|
+
* `x * (r - 1) = m - c`
|
|
111
|
+
* `x = (m - c) / r - 1`
|
|
112
|
+
*/
|
|
113
|
+
export function calculateMinCollateralCappedIAssetRedemptionAmt(
|
|
114
|
+
collateralAmt: bigint,
|
|
115
|
+
mintedAmt: bigint,
|
|
116
|
+
price: OnChainDecimal,
|
|
117
|
+
rmr: OnChainDecimal,
|
|
118
|
+
reimburstmentPercentage: OnChainDecimal,
|
|
119
|
+
minCollateral: bigint,
|
|
120
|
+
): {
|
|
121
|
+
uncappedIAssetRedemptionAmt: bigint;
|
|
122
|
+
cappedIAssetRedemptionAmt: bigint;
|
|
123
|
+
} {
|
|
124
|
+
const uncappedMaxIAssetRedemptionAmt = calculateIAssetRedemptionAmt(
|
|
125
|
+
collateralAmt,
|
|
126
|
+
mintedAmt,
|
|
127
|
+
price,
|
|
128
|
+
rmr,
|
|
129
|
+
);
|
|
130
|
+
const uncappedMaxRedemptionLovelacesAmt = ocdMul(price, {
|
|
131
|
+
getOnChainInt: uncappedMaxIAssetRedemptionAmt,
|
|
132
|
+
}).getOnChainInt;
|
|
133
|
+
|
|
134
|
+
const maxReimburstment = calculateFeeFromPercentage(
|
|
135
|
+
reimburstmentPercentage,
|
|
136
|
+
uncappedMaxRedemptionLovelacesAmt,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const doesMaxBreakMinCollateral =
|
|
140
|
+
collateralAmt - uncappedMaxRedemptionLovelacesAmt + maxReimburstment <
|
|
141
|
+
minCollateral;
|
|
142
|
+
|
|
143
|
+
if (!doesMaxBreakMinCollateral) {
|
|
144
|
+
return {
|
|
145
|
+
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
146
|
+
cappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
147
|
+
};
|
|
148
|
+
// already below min collateral
|
|
149
|
+
} else if (collateralAmt <= minCollateral) {
|
|
150
|
+
return {
|
|
151
|
+
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
152
|
+
cappedIAssetRedemptionAmt: 0n,
|
|
153
|
+
};
|
|
154
|
+
} else {
|
|
155
|
+
const resLovelaces = Decimal(
|
|
156
|
+
(minCollateral - collateralAmt) * 100_000_000n,
|
|
157
|
+
).div(reimburstmentPercentage.getOnChainInt - 100_000_000n);
|
|
158
|
+
const resIAsset = resLovelaces.div(
|
|
159
|
+
Decimal(price.getOnChainInt).div(OCD_DECIMAL_UNIT),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
164
|
+
cappedIAssetRedemptionAmt: BigInt(resIAsset.floor().toNumber()),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
+
import { CdpParamsSP, fromSystemParamsAsset } from '../../types/system-params';
|
|
3
|
+
import { castCdpParams } from './types';
|
|
4
|
+
import { _cdpValidator } from '../../validators/cdp-validator';
|
|
5
|
+
|
|
6
|
+
export const mkCdpValidatorFromSP = (
|
|
7
|
+
params: CdpParamsSP,
|
|
8
|
+
): SpendingValidator => {
|
|
9
|
+
return {
|
|
10
|
+
type: 'PlutusV2',
|
|
11
|
+
script: applyParamsToScript(_cdpValidator.cborHex, [
|
|
12
|
+
castCdpParams({
|
|
13
|
+
cdp_auth_token: fromSystemParamsAsset(params.cdpAuthToken),
|
|
14
|
+
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
15
|
+
iasset_auth_token: fromSystemParamsAsset(params.iAssetAuthToken),
|
|
16
|
+
stability_pool_auth_token: fromSystemParamsAsset(
|
|
17
|
+
params.stabilityPoolAuthToken,
|
|
18
|
+
),
|
|
19
|
+
version_record_token: fromSystemParamsAsset(params.versionRecordToken),
|
|
20
|
+
upgrade_token: fromSystemParamsAsset(params.upgradeToken),
|
|
21
|
+
collector_val_hash: params.collectorValHash,
|
|
22
|
+
sp_val_hash: params.spValHash,
|
|
23
|
+
gov_nft: fromSystemParamsAsset(params.govNFT),
|
|
24
|
+
min_collateral_in_lovelace: BigInt(params.minCollateralInLovelace),
|
|
25
|
+
partial_redemption_extra_fee_lovelace: BigInt(
|
|
26
|
+
params.partialRedemptionExtraFeeLovelace,
|
|
27
|
+
),
|
|
28
|
+
bias_time: BigInt(params.biasTime),
|
|
29
|
+
treasury_val_hash: params.treasuryValHash,
|
|
30
|
+
}),
|
|
31
|
+
]),
|
|
32
|
+
};
|
|
33
|
+
};
|