@indigo-labs/indigo-sdk 0.5.5 → 0.5.6
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/package.json +11 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/ci.yml +0 -66
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -6
- package/eslint.config.mjs +0 -42
- package/scripts/bench.sh +0 -62
- package/scripts/run-repeat.sh +0 -22
- package/src/contracts/cdp/helpers.ts +0 -173
- package/src/contracts/cdp/scripts.ts +0 -70
- package/src/contracts/cdp/transactions.ts +0 -1584
- package/src/contracts/cdp/types-new.ts +0 -277
- package/src/contracts/cdp/types.ts +0 -43
- package/src/contracts/cdp-creator/queries.ts +0 -30
- package/src/contracts/cdp-creator/scripts.ts +0 -45
- package/src/contracts/cdp-creator/types-new.ts +0 -50
- package/src/contracts/cdp-creator/types.ts +0 -24
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -50
- package/src/contracts/collector/types-new.ts +0 -17
- package/src/contracts/execute/scripts.ts +0 -57
- package/src/contracts/execute/types-new.ts +0 -44
- package/src/contracts/execute/types.ts +0 -24
- package/src/contracts/gov/helpers.ts +0 -351
- package/src/contracts/gov/scripts.ts +0 -41
- package/src/contracts/gov/transactions.ts +0 -1607
- package/src/contracts/gov/types-new.ts +0 -268
- package/src/contracts/gov/types.ts +0 -22
- package/src/contracts/iasset/helpers.ts +0 -170
- package/src/contracts/iasset/queries.ts +0 -102
- package/src/contracts/iasset/scripts.ts +0 -38
- package/src/contracts/iasset/types.ts +0 -154
- package/src/contracts/initialize/actions.ts +0 -789
- package/src/contracts/initialize/helpers.ts +0 -616
- package/src/contracts/initialize/types.ts +0 -116
- package/src/contracts/interest-collection/helpers.ts +0 -19
- package/src/contracts/interest-collection/queries.ts +0 -66
- package/src/contracts/interest-collection/scripts.ts +0 -44
- package/src/contracts/interest-collection/transactions.ts +0 -433
- package/src/contracts/interest-collection/types-new.ts +0 -50
- package/src/contracts/interest-collection/types.ts +0 -26
- package/src/contracts/interest-oracle/helpers.ts +0 -61
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -151
- package/src/contracts/interest-oracle/types-new.ts +0 -32
- package/src/contracts/interest-oracle/types.ts +0 -16
- package/src/contracts/one-shot/scripts.ts +0 -12
- package/src/contracts/one-shot/transactions.ts +0 -66
- package/src/contracts/one-shot/types.ts +0 -22
- package/src/contracts/poll/helpers.ts +0 -37
- package/src/contracts/poll/scripts.ts +0 -71
- package/src/contracts/poll/types-poll-manager.ts +0 -20
- package/src/contracts/poll/types-poll-new.ts +0 -196
- package/src/contracts/poll/types-poll-shard.ts +0 -16
- package/src/contracts/price-oracle/helpers.ts +0 -30
- package/src/contracts/price-oracle/scripts.ts +0 -18
- package/src/contracts/price-oracle/transactions.ts +0 -115
- package/src/contracts/price-oracle/types-new.ts +0 -50
- package/src/contracts/price-oracle/types.ts +0 -16
- package/src/contracts/pyth-feed/helpers.ts +0 -82
- package/src/contracts/pyth-feed/scripts.ts +0 -15
- package/src/contracts/pyth-feed/types.ts +0 -181
- package/src/contracts/rob/helpers.ts +0 -666
- package/src/contracts/rob/scripts.ts +0 -35
- package/src/contracts/rob/transactions.ts +0 -423
- package/src/contracts/rob/types-new.ts +0 -128
- package/src/contracts/rob/types.ts +0 -16
- package/src/contracts/rob-leverage/helpers.ts +0 -422
- package/src/contracts/rob-leverage/transactions.ts +0 -368
- package/src/contracts/stability-pool/helpers.ts +0 -798
- package/src/contracts/stability-pool/queries.ts +0 -132
- package/src/contracts/stability-pool/scripts.ts +0 -51
- package/src/contracts/stability-pool/transactions.ts +0 -921
- package/src/contracts/stability-pool/types-new.ts +0 -385
- package/src/contracts/stability-pool/types.ts +0 -25
- package/src/contracts/stableswap/helpers.ts +0 -507
- package/src/contracts/stableswap/scripts.ts +0 -37
- package/src/contracts/stableswap/transactions.ts +0 -475
- package/src/contracts/stableswap/types-new.ts +0 -131
- package/src/contracts/stableswap/types.ts +0 -17
- package/src/contracts/staking/helpers.ts +0 -136
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -349
- package/src/contracts/staking/types-new.ts +0 -137
- package/src/contracts/staking/types.ts +0 -17
- package/src/contracts/treasury/helpers.ts +0 -21
- package/src/contracts/treasury/queries.ts +0 -100
- package/src/contracts/treasury/scripts.ts +0 -27
- package/src/contracts/treasury/transactions.ts +0 -334
- package/src/contracts/treasury/types-new.ts +0 -69
- package/src/contracts/treasury/types.ts +0 -14
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -18
- package/src/contracts/version-registry/types.ts +0 -17
- package/src/index.ts +0 -99
- package/src/scripts/always-fail-validator.ts +0 -7
- package/src/scripts/auth-token-policy.ts +0 -24
- package/src/scripts/iasset-policy.ts +0 -23
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/types/generic.ts +0 -52
- package/src/types/multisig.ts +0 -48
- package/src/types/on-chain-decimal.ts +0 -57
- package/src/types/rational.ts +0 -76
- package/src/types/system-params.ts +0 -463
- package/src/utils/array-utils.ts +0 -108
- package/src/utils/bigint-utils.ts +0 -35
- package/src/utils/helper-txs.ts +0 -31
- package/src/utils/indigo-helpers.ts +0 -17
- package/src/utils/lucid-utils.ts +0 -125
- package/src/utils/oracle-helpers.ts +0 -62
- package/src/utils/pyth/decode.ts +0 -223
- package/src/utils/pyth/encode.ts +0 -262
- package/src/utils/pyth/index.ts +0 -14
- package/src/utils/pyth/types.ts +0 -87
- package/src/utils/time-helpers.ts +0 -4
- package/src/utils/utils.ts +0 -25
- package/src/validators/always-succeed-validator.ts +0 -6
- package/src/validators/cdp-creator-validator.ts +0 -7
- package/src/validators/cdp-redeem-validator.ts +0 -7
- package/src/validators/cdp-validator.ts +0 -7
- package/src/validators/collector-validator.ts +0 -7
- package/src/validators/execute-validator.ts +0 -7
- package/src/validators/governance-validator.ts +0 -7
- package/src/validators/iasset-validator.ts +0 -7
- package/src/validators/interest-collection-validator.ts +0 -7
- package/src/validators/interest-oracle-validator.ts +0 -7
- package/src/validators/one-shot-policy.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/poll-shard-validator.ts +0 -7
- package/src/validators/price-oracle-validator.ts +0 -7
- package/src/validators/pyth-feed-validator.ts +0 -7
- package/src/validators/rob-validator.ts +0 -7
- package/src/validators/stability-pool-validator.ts +0 -7
- package/src/validators/stableswap-validator.ts +0 -7
- package/src/validators/staking-validator.ts +0 -7
- package/src/validators/treasury-validator.ts +0 -7
- package/src/validators/version-record-policy.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/always-succeed/script.ts +0 -7
- package/tests/array-utils.test.ts +0 -92
- package/tests/bigint-utils.test.ts +0 -41
- package/tests/cdp/actions.ts +0 -680
- package/tests/cdp/cdp-helpers.ts +0 -55
- package/tests/cdp/cdp-queries.ts +0 -423
- package/tests/cdp/cdp.test.ts +0 -6730
- package/tests/cdp/transactions-mutated.ts +0 -1733
- package/tests/data/system-params.json +0 -1155
- package/tests/datums.test.ts +0 -302
- package/tests/endpoints/initialize.ts +0 -78
- package/tests/endpoints/interest-collector.ts +0 -37
- package/tests/endpoints/treasury.ts +0 -70
- package/tests/gov/actions.ts +0 -381
- package/tests/gov/gov.test.ts +0 -5147
- package/tests/gov/governance-queries.ts +0 -37
- package/tests/hash-checks.test.ts +0 -112
- package/tests/indigo-test-helpers.ts +0 -99
- package/tests/initialize.test.ts +0 -79
- package/tests/interest-calculations.test.ts +0 -120
- package/tests/interest-collection/interest-collection.test.ts +0 -843
- package/tests/interest-collection/transactions-mutated.ts +0 -260
- package/tests/interest-oracle.test.ts +0 -93
- package/tests/mock/assets-mock.ts +0 -243
- package/tests/mock/protocol-params-mock.ts +0 -21
- package/tests/price-oracle/actions.ts +0 -161
- package/tests/price-oracle/price-oracle-queries.ts +0 -12
- package/tests/price-oracle/price-oracle.test.ts +0 -228
- package/tests/price-oracle/transactions-mutated.ts +0 -59
- package/tests/pyth/endpoints.ts +0 -96
- package/tests/pyth/helpers.ts +0 -37
- package/tests/pyth/pyth-encoding.test.ts +0 -376
- package/tests/pyth/pyth-feeds.test.ts +0 -943
- package/tests/pyth/pyth-indigo.test.ts +0 -505
- package/tests/pyth/pyth.test.ts +0 -299
- package/tests/queries/collector-queries.ts +0 -27
- package/tests/queries/execute-queries.ts +0 -47
- package/tests/queries/iasset-queries.ts +0 -149
- package/tests/queries/interest-oracle-queries.ts +0 -12
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/staking-queries.ts +0 -54
- package/tests/rob/actions.ts +0 -56
- package/tests/rob/rob-leverage.test.ts +0 -2555
- package/tests/rob/rob-queries.ts +0 -95
- package/tests/rob/rob.test.ts +0 -3677
- package/tests/rob/transactions-mutated.ts +0 -844
- package/tests/script-size.test.ts +0 -240
- package/tests/setup.ts +0 -135
- package/tests/stability-pool/actions.ts +0 -229
- package/tests/stability-pool.test.ts +0 -6491
- package/tests/stableswap/stableswap-actions.ts +0 -83
- package/tests/stableswap/stableswap-queries.ts +0 -98
- package/tests/stableswap/stableswap.test.ts +0 -4471
- package/tests/stableswap/transactions-mutated.ts +0 -348
- package/tests/staking.test.ts +0 -172
- package/tests/test-helpers.ts +0 -94
- package/tests/treasury/actions.ts +0 -67
- package/tests/treasury/treasury.test.ts +0 -320
- package/tests/utils/asserts.ts +0 -87
- package/tests/utils/benchmark-utils.ts +0 -130
- package/tests/utils/index.ts +0 -168
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -27
- package/vitest.config.ts +0 -11
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
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
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
8
18
|
"lint-staged": {
|
|
9
19
|
"*.{js,ts,jsx,tsx}": [
|
|
10
20
|
"prettier --write",
|
package/.github/workflows/ci.yml
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- main
|
|
7
|
-
pull_request:
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
lint-and-build:
|
|
11
|
-
runs-on: self-hosted
|
|
12
|
-
|
|
13
|
-
steps:
|
|
14
|
-
- name: Checkout code
|
|
15
|
-
uses: actions/checkout@v4
|
|
16
|
-
|
|
17
|
-
- name: Setup Node.js
|
|
18
|
-
uses: actions/setup-node@v6
|
|
19
|
-
with:
|
|
20
|
-
node-version-file: '.nvmrc'
|
|
21
|
-
|
|
22
|
-
- name: Setup pnpm
|
|
23
|
-
uses: pnpm/action-setup@v6
|
|
24
|
-
|
|
25
|
-
- name: Get pnpm store directory
|
|
26
|
-
shell: bash
|
|
27
|
-
run: |
|
|
28
|
-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
29
|
-
|
|
30
|
-
- name: Setup pnpm cache
|
|
31
|
-
uses: actions/cache@v4
|
|
32
|
-
with:
|
|
33
|
-
path: ${{ env.STORE_PATH }}
|
|
34
|
-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
35
|
-
restore-keys: |
|
|
36
|
-
${{ runner.os }}-pnpm-store-
|
|
37
|
-
|
|
38
|
-
- name: Install dependencies
|
|
39
|
-
run: pnpm install
|
|
40
|
-
|
|
41
|
-
- name: Check formatting
|
|
42
|
-
run: pnpm run format:check
|
|
43
|
-
|
|
44
|
-
- name: Check linting
|
|
45
|
-
run: pnpm run lint
|
|
46
|
-
|
|
47
|
-
- name: Type check
|
|
48
|
-
run: pnpm run type-check
|
|
49
|
-
|
|
50
|
-
- name: Run tests
|
|
51
|
-
run: pnpm test
|
|
52
|
-
|
|
53
|
-
- name: Build project
|
|
54
|
-
run: pnpm run build
|
|
55
|
-
|
|
56
|
-
- name: Verify build output
|
|
57
|
-
run: |
|
|
58
|
-
if [ ! -d "dist" ]; then
|
|
59
|
-
echo "Build failed: dist directory not found"
|
|
60
|
-
exit 1
|
|
61
|
-
fi
|
|
62
|
-
if [ ! -f "dist/index.js" ] || [ ! -f "dist/index.mjs" ] || [ ! -f "dist/index.d.ts" ]; then
|
|
63
|
-
echo "Build failed: expected output files not found"
|
|
64
|
-
exit 1
|
|
65
|
-
fi
|
|
66
|
-
echo "Build verification passed"
|
package/.husky/pre-commit
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pnpm exec lint-staged
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
v24.4.1
|
package/.prettierignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pnpm-lock.yaml
|
package/.prettierrc
DELETED
package/eslint.config.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import vitestEslint from '@vitest/eslint-plugin';
|
|
4
|
-
import { defineConfig } from 'eslint/config';
|
|
5
|
-
|
|
6
|
-
export default defineConfig(
|
|
7
|
-
{
|
|
8
|
-
ignores: ['**/dist/*', '**/node_modules/*'],
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
files: ['**/*.ts'],
|
|
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,
|
|
15
|
-
eslint.configs.recommended,
|
|
16
|
-
tseslint.configs.recommendedTypeChecked,
|
|
17
|
-
{
|
|
18
|
-
languageOptions: {
|
|
19
|
-
parserOptions: {
|
|
20
|
-
projectService: true,
|
|
21
|
-
tsconfigRootDir: import.meta.dirname,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
rules: {
|
|
27
|
-
'vitest/expect-expect': 'off',
|
|
28
|
-
'no-unreachable': 'warn',
|
|
29
|
-
'no-use-before-define': 'error',
|
|
30
|
-
'no-unused-expressions': 'warn',
|
|
31
|
-
'@typescript-eslint/no-unused-vars': [
|
|
32
|
-
'error',
|
|
33
|
-
{
|
|
34
|
-
args: 'all',
|
|
35
|
-
argsIgnorePattern: '^_',
|
|
36
|
-
varsIgnorePattern: '^_',
|
|
37
|
-
caughtErrorsIgnorePattern: '^_',
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
);
|
package/scripts/bench.sh
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Runs the testsuite X times and collects the mem spent for each run,
|
|
4
|
-
# at the end, it summarises the results (max, median, avg).
|
|
5
|
-
# It's best to run just a single test using `.only` so it's quick.
|
|
6
|
-
#
|
|
7
|
-
# Usage: ./bench.sh <test-file> <benchmark-name> <runs>
|
|
8
|
-
# Example: ./bench.sh interest-collection.test.ts "Interest Collection - Batch Collect 13 CDPs" 20
|
|
9
|
-
|
|
10
|
-
if [ "$#" -ne 3 ]; then
|
|
11
|
-
echo "Usage: $0 <test-file> <benchmark-name> <runs>"
|
|
12
|
-
echo "Example: $0 interest-collection.test.ts \"Interest Collection - Batch Collect 13 CDPs\" 20"
|
|
13
|
-
exit 1
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
test_file="$1"
|
|
17
|
-
benchmark_name="$2"
|
|
18
|
-
runs="$3"
|
|
19
|
-
|
|
20
|
-
if ! [[ "$runs" =~ ^[0-9]+$ ]] || [ "$runs" -lt 1 ]; then
|
|
21
|
-
echo "Error: <runs> must be a positive integer"
|
|
22
|
-
exit 1
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
total=0
|
|
26
|
-
values=()
|
|
27
|
-
|
|
28
|
-
for i in $(seq 1 $runs); do
|
|
29
|
-
echo -n "Run $i/$runs... "
|
|
30
|
-
output=$(pnpm test "$test_file" 2>&1)
|
|
31
|
-
mem=$(echo "$output" | grep "$benchmark_name" | grep -oP "'\d+\.\d+%'" | head -1 | tr -d "'%")
|
|
32
|
-
|
|
33
|
-
if [ -z "$mem" ]; then
|
|
34
|
-
echo "ERROR: benchmark '$benchmark_name' not found in output — aborting"
|
|
35
|
-
exit 1
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
echo "Memory: ${mem}%"
|
|
39
|
-
values+=("$mem")
|
|
40
|
-
total=$(echo "$total + $mem" | bc)
|
|
41
|
-
done
|
|
42
|
-
|
|
43
|
-
sorted=($(printf '%s\n' "${values[@]}" | sort -n))
|
|
44
|
-
|
|
45
|
-
avg=$(echo "scale=3; $total / $runs" | bc)
|
|
46
|
-
min=${sorted[0]}
|
|
47
|
-
max=${sorted[$runs-1]}
|
|
48
|
-
|
|
49
|
-
mid=$(($runs / 2))
|
|
50
|
-
if (( $runs % 2 == 0 )); then
|
|
51
|
-
median=$(echo "scale=3; (${sorted[$mid-1]} + ${sorted[$mid]}) / 2" | bc)
|
|
52
|
-
else
|
|
53
|
-
median=${sorted[$mid]}
|
|
54
|
-
fi
|
|
55
|
-
|
|
56
|
-
echo ""
|
|
57
|
-
echo "=== Benchmark: $benchmark_name ==="
|
|
58
|
-
echo "=== Test file: $test_file | Runs: $runs ==="
|
|
59
|
-
echo "Average : ${avg}%"
|
|
60
|
-
echo "Minimum : ${min}%"
|
|
61
|
-
echo "Maximum : ${max}%"
|
|
62
|
-
echo "Median : ${median}%"
|
package/scripts/run-repeat.sh
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# Usage: ./scripts/run-repeat.sh <n> <command...>
|
|
3
|
-
# Example: ./scripts/run-repeat.sh 100 pnpm test stableswap.test.ts
|
|
4
|
-
|
|
5
|
-
N=${1:?Usage: $0 <n> <command...>}
|
|
6
|
-
shift
|
|
7
|
-
CMD=("$@")
|
|
8
|
-
|
|
9
|
-
failures=0
|
|
10
|
-
|
|
11
|
-
for ((i = 1; i <= N; i++)); do
|
|
12
|
-
printf "Run %d/%d ... " "$i" "$N"
|
|
13
|
-
if "${CMD[@]}" > /tmp/run-repeat-out.txt 2>&1; then
|
|
14
|
-
echo "ok"
|
|
15
|
-
else
|
|
16
|
-
echo "FAILED"
|
|
17
|
-
((failures++))
|
|
18
|
-
fi
|
|
19
|
-
done
|
|
20
|
-
|
|
21
|
-
echo ""
|
|
22
|
-
echo "Done: $((N - failures))/$N passed, $failures failed."
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { Assets } from '@lucid-evolution/lucid';
|
|
2
|
-
import { calculateAccruedInterest } from '../interest-oracle/helpers';
|
|
3
|
-
import { match, P } from 'ts-pattern';
|
|
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
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Amount of iasset equal in value to the given number of collateral amount.
|
|
22
|
-
*/
|
|
23
|
-
export function iassetValueOfCollateral(
|
|
24
|
-
collateralAmt: bigint,
|
|
25
|
-
oraclePrice: Rational,
|
|
26
|
-
): bigint {
|
|
27
|
-
return rationalFloor(
|
|
28
|
-
rationalDiv(rationalFromInt(collateralAmt), oraclePrice),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function cdpCollateralRatioPercentage(
|
|
33
|
-
/**
|
|
34
|
-
* Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
|
|
35
|
-
* Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
|
|
36
|
-
*/
|
|
37
|
-
now: bigint,
|
|
38
|
-
iassetPrice: Rational,
|
|
39
|
-
cdpUtxoAssets: Assets,
|
|
40
|
-
cdpContent: CDPContent,
|
|
41
|
-
interestOracleDatum: InterestOracleDatum,
|
|
42
|
-
): number {
|
|
43
|
-
return match(cdpContent.cdpFees)
|
|
44
|
-
.with({ ActiveCDPInterestTracking: P.select() }, (interest) => {
|
|
45
|
-
const interestAmt = calculateAccruedInterest(
|
|
46
|
-
now,
|
|
47
|
-
interest.unitaryInterestSnapshot,
|
|
48
|
-
cdpContent.mintedAmt,
|
|
49
|
-
interest.lastSettled,
|
|
50
|
-
interestOracleDatum,
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const collateral = assetClassValueOf(
|
|
54
|
-
cdpUtxoAssets,
|
|
55
|
-
cdpContent.collateralAsset,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const ratio = rationalDiv(
|
|
59
|
-
rationalFromInt(collateral),
|
|
60
|
-
rationalMul(
|
|
61
|
-
rationalFromInt(cdpContent.mintedAmt + interestAmt),
|
|
62
|
-
iassetPrice,
|
|
63
|
-
),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return (Number(ratio.numerator) * 100) / Number(ratio.denominator);
|
|
67
|
-
})
|
|
68
|
-
.with({ FrozenCDPAccumulatedFees: P.any }, () => 0)
|
|
69
|
-
.exhaustive();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The amount of iassets to redeem to reach the RMR.
|
|
74
|
-
*/
|
|
75
|
-
export function calculateIAssetRedemptionAmt(
|
|
76
|
-
collateralAmt: bigint,
|
|
77
|
-
mintedAmt: bigint,
|
|
78
|
-
price: Rational,
|
|
79
|
-
rmr: Rational,
|
|
80
|
-
): bigint {
|
|
81
|
-
return rationalCeil(
|
|
82
|
-
rationalDiv(
|
|
83
|
-
rationalAdd(
|
|
84
|
-
rationalNegate(rationalDiv(rationalFromInt(collateralAmt), price)),
|
|
85
|
-
rationalMul(rmr, rationalFromInt(mintedAmt)),
|
|
86
|
-
),
|
|
87
|
-
rationalSub(rmr, rationalFromInt(1n)),
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Calculates the allowable redemption amount so the min collateral constraint still holds.
|
|
94
|
-
* It caps the redemption amount to still satisfy the min collateral.
|
|
95
|
-
*
|
|
96
|
-
* Returns uncapped max iassets /\ capped max iassets
|
|
97
|
-
*
|
|
98
|
-
* The derived calculation comes from the following equation where:
|
|
99
|
-
* c - collateral
|
|
100
|
-
* m - min collateral
|
|
101
|
-
* r - reimburstment ratio
|
|
102
|
-
* x - redemption amount
|
|
103
|
-
*
|
|
104
|
-
* `c - x + r * x = m`
|
|
105
|
-
* `-x + r * x = m - c`
|
|
106
|
-
* `x * (r - 1) = m - c`
|
|
107
|
-
* `x = (m - c) / r - 1`
|
|
108
|
-
*/
|
|
109
|
-
export function calculateMinCollateralCappedIAssetRedemptionAmt(
|
|
110
|
-
collateralAmt: bigint,
|
|
111
|
-
mintedAmt: bigint,
|
|
112
|
-
price: Rational,
|
|
113
|
-
rmr: Rational,
|
|
114
|
-
reimbursementRatio: Rational,
|
|
115
|
-
minCollateral: bigint,
|
|
116
|
-
): {
|
|
117
|
-
uncappedIAssetRedemptionAmt: bigint;
|
|
118
|
-
cappedIAssetRedemptionAmt: bigint;
|
|
119
|
-
} {
|
|
120
|
-
const uncappedMaxIAssetRedemptionAmt = calculateIAssetRedemptionAmt(
|
|
121
|
-
collateralAmt,
|
|
122
|
-
mintedAmt,
|
|
123
|
-
price,
|
|
124
|
-
rmr,
|
|
125
|
-
);
|
|
126
|
-
const uncappedMaxRedemptionLovelacesAmt = rationalFloor(
|
|
127
|
-
rationalMul(price, rationalFromInt(uncappedMaxIAssetRedemptionAmt)),
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const maxReimburstment = calculateFeeFromRatio(
|
|
131
|
-
reimbursementRatio,
|
|
132
|
-
uncappedMaxRedemptionLovelacesAmt,
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const doesMaxBreakMinCollateral =
|
|
136
|
-
collateralAmt - uncappedMaxRedemptionLovelacesAmt + maxReimburstment <
|
|
137
|
-
minCollateral;
|
|
138
|
-
|
|
139
|
-
if (!doesMaxBreakMinCollateral) {
|
|
140
|
-
return {
|
|
141
|
-
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
142
|
-
cappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
143
|
-
};
|
|
144
|
-
// already below min collateral
|
|
145
|
-
} else if (collateralAmt <= minCollateral) {
|
|
146
|
-
return {
|
|
147
|
-
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
148
|
-
cappedIAssetRedemptionAmt: 0n,
|
|
149
|
-
};
|
|
150
|
-
} else {
|
|
151
|
-
const resLovelaces = rationalDiv(
|
|
152
|
-
rationalFromInt(minCollateral - collateralAmt),
|
|
153
|
-
rationalSub(reimbursementRatio, rationalFromInt(1n)),
|
|
154
|
-
);
|
|
155
|
-
const resIAsset = rationalDiv(resLovelaces, price);
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
uncappedIAssetRedemptionAmt: uncappedMaxIAssetRedemptionAmt,
|
|
159
|
-
cappedIAssetRedemptionAmt: rationalFloor(resIAsset),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function adjustPriceToDecimals(
|
|
165
|
-
extraDecimals: bigint,
|
|
166
|
-
price: Rational,
|
|
167
|
-
): Rational {
|
|
168
|
-
return extraDecimals === 0n
|
|
169
|
-
? price
|
|
170
|
-
: extraDecimals > 0n
|
|
171
|
-
? rationalMul(price, rationalFromInt(10n ** extraDecimals))
|
|
172
|
-
: rationalDiv(price, rationalFromInt(10n ** -extraDecimals));
|
|
173
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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';
|
|
12
|
-
import { _cdpValidator } from '../../validators/cdp-validator';
|
|
13
|
-
import { _cdpRedeemValidator } from '../../validators/cdp-redeem-validator';
|
|
14
|
-
|
|
15
|
-
export const mkCdpValidatorFromSP = (
|
|
16
|
-
params: CdpParamsSP,
|
|
17
|
-
): SpendingValidator => {
|
|
18
|
-
return {
|
|
19
|
-
type: 'PlutusV3',
|
|
20
|
-
script: applyParamsToScript(_cdpValidator.cborHex, [
|
|
21
|
-
castCdpParams({
|
|
22
|
-
cdp_auth_token: fromSystemParamsAssetLucid(params.cdpAuthToken),
|
|
23
|
-
cdp_asset_symbol: params.cdpAssetSymbol.unCurrencySymbol,
|
|
24
|
-
iasset_auth_token: fromSystemParamsAssetLucid(params.iAssetAuthToken),
|
|
25
|
-
collateral_asset_auth_token: fromSystemParamsAssetLucid(
|
|
26
|
-
params.collateralAssetAuthToken,
|
|
27
|
-
),
|
|
28
|
-
stability_pool_auth_token: fromSystemParamsAssetLucid(
|
|
29
|
-
params.stabilityPoolAuthToken,
|
|
30
|
-
),
|
|
31
|
-
upgrade_token: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
32
|
-
version_record_token: fromSystemParamsAssetLucid(
|
|
33
|
-
params.versionRecordToken,
|
|
34
|
-
),
|
|
35
|
-
interest_collector_val_hash: params.interestCollectorValHash,
|
|
36
|
-
sp_val_hash: params.spValHash,
|
|
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),
|
|
63
|
-
partial_redemption_extra_fee_lovelace: BigInt(
|
|
64
|
-
params.partialRedemptionExtraFeeLovelace,
|
|
65
|
-
),
|
|
66
|
-
bias_time: BigInt(params.biasTime),
|
|
67
|
-
}),
|
|
68
|
-
]),
|
|
69
|
-
};
|
|
70
|
-
};
|