@indigo-labs/indigo-sdk 0.3.28 → 0.4.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/.claude/settings.local.json +7 -0
- package/.github/workflows/ci.yml +0 -1
- package/README.md +16 -0
- package/dist/index.d.mts +33 -3
- package/dist/index.d.ts +33 -3
- package/dist/index.js +610 -364
- package/dist/index.mjs +445 -196
- package/package.json +14 -22
- package/scripts/bench.sh +0 -0
- package/src/contracts/cdp-creator/queries.ts +30 -0
- package/src/contracts/iasset/queries.ts +102 -0
- package/src/contracts/initialize/actions.ts +38 -15
- package/{tests/interest-collection/interest-collector-queries.ts → src/contracts/interest-collection/queries.ts} +28 -12
- package/src/contracts/pyth-feed/helpers.ts +24 -0
- package/{tests/treasury/treasury-queries.ts → src/contracts/treasury/queries.ts} +15 -24
- package/src/index.ts +6 -1
- package/tests/cdp/actions.ts +1 -1
- package/tests/cdp/cdp-queries.ts +3 -23
- package/tests/cdp/transactions-mutated.ts +3 -4
- package/tests/gov/gov.test.ts +18 -18
- package/tests/interest-collection/interest-collection.test.ts +17 -62
- package/tests/queries/iasset-queries.ts +1 -84
- package/tests/rob/rob.test.ts +52 -52
- package/tests/stableswap/stableswap.test.ts +1 -1
- package/tests/treasury/actions.ts +1 -1
- package/tests/treasury/treasury.test.ts +1 -1
package/package.json
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigo-labs/indigo-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
|
|
10
|
-
"type-check": "tsc --noEmit",
|
|
11
|
-
"lint": "pnpm eslint .",
|
|
12
|
-
"lint:fix": "npx eslint --fix .",
|
|
13
|
-
"repack": "pnpm run build && pnpm pack",
|
|
14
|
-
"format": "npx prettier --write src/ tests/",
|
|
15
|
-
"format:check": "npx prettier --check src/ tests/",
|
|
16
|
-
"test": "vitest run",
|
|
17
|
-
"prepare": "husky",
|
|
18
|
-
"lint-staged": "lint-staged"
|
|
19
|
-
},
|
|
20
8
|
"lint-staged": {
|
|
21
9
|
"*.{js,ts,jsx,tsx}": [
|
|
22
10
|
"prettier --write",
|
|
@@ -39,12 +27,11 @@
|
|
|
39
27
|
],
|
|
40
28
|
"author": "3rd Eye Labs",
|
|
41
29
|
"license": "MIT",
|
|
42
|
-
"packageManager": "pnpm@10.33.4",
|
|
43
30
|
"dependencies": {
|
|
44
|
-
"@3rd-eye-labs/cardano-offchain-common": "1.
|
|
31
|
+
"@3rd-eye-labs/cardano-offchain-common": "1.4.7",
|
|
45
32
|
"@evolution-sdk/evolution": "^0.3.22",
|
|
46
33
|
"@harmoniclabs/crypto": "^0.3.0",
|
|
47
|
-
"@lucid-evolution/lucid": "
|
|
34
|
+
"@lucid-evolution/lucid": "0.5.5",
|
|
48
35
|
"@noble/ed25519": "^3.0.0",
|
|
49
36
|
"@pythnetwork/pyth-lazer-sdk": "^6.0.0",
|
|
50
37
|
"decimal.js": "^10.6.0",
|
|
@@ -71,10 +58,15 @@
|
|
|
71
58
|
"typescript-eslint": "^8.39.0",
|
|
72
59
|
"vitest": "^4.0.14"
|
|
73
60
|
},
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --tsconfig tsconfig.build.json",
|
|
63
|
+
"type-check": "tsc --noEmit",
|
|
64
|
+
"lint": "pnpm eslint .",
|
|
65
|
+
"lint:fix": "npx eslint --fix .",
|
|
66
|
+
"repack": "pnpm run build && pnpm pack",
|
|
67
|
+
"format": "npx prettier --write src/ tests/",
|
|
68
|
+
"format:check": "npx prettier --check src/ tests/",
|
|
69
|
+
"test": "vitest run",
|
|
70
|
+
"lint-staged": "lint-staged"
|
|
79
71
|
}
|
|
80
|
-
}
|
|
72
|
+
}
|
package/scripts/bench.sh
CHANGED
|
File without changes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assetClassToUnit,
|
|
3
|
+
getRandomElement,
|
|
4
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
5
|
+
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
6
|
+
import { option as O, function as F } from 'fp-ts';
|
|
7
|
+
import { createScriptAddress } from '../../utils/lucid-utils';
|
|
8
|
+
import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
|
|
9
|
+
|
|
10
|
+
export async function findRandomCdpCreator(
|
|
11
|
+
lucid: LucidEvolution,
|
|
12
|
+
sysParams: SystemParams,
|
|
13
|
+
): Promise<UTxO> {
|
|
14
|
+
const cdpCreatorUtxos = await lucid.utxosAtWithUnit(
|
|
15
|
+
createScriptAddress(
|
|
16
|
+
lucid.config().network!,
|
|
17
|
+
sysParams.validatorHashes.cdpCreatorHash,
|
|
18
|
+
),
|
|
19
|
+
assetClassToUnit(
|
|
20
|
+
fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft),
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return F.pipe(
|
|
25
|
+
O.fromNullable(getRandomElement(cdpCreatorUtxos)),
|
|
26
|
+
O.match(() => {
|
|
27
|
+
throw new Error('Expected some cdp creator UTXOs.');
|
|
28
|
+
}, F.identity),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { LucidEvolution, toHex } from '@lucid-evolution/lucid';
|
|
2
|
+
import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
|
|
3
|
+
import {
|
|
4
|
+
AssetClass,
|
|
5
|
+
assetClassToUnit,
|
|
6
|
+
isSameAssetClass,
|
|
7
|
+
matchSingle,
|
|
8
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
9
|
+
import {
|
|
10
|
+
CollateralAssetOutput,
|
|
11
|
+
IAssetOutput,
|
|
12
|
+
parseCollateralAssetDatum,
|
|
13
|
+
parseIAssetDatum,
|
|
14
|
+
} from './types';
|
|
15
|
+
import { createScriptAddress } from '../../utils/lucid-utils';
|
|
16
|
+
import { option as O, array as A, function as F } from 'fp-ts';
|
|
17
|
+
|
|
18
|
+
export async function findIAsset(
|
|
19
|
+
lucid: LucidEvolution,
|
|
20
|
+
sysParams: SystemParams,
|
|
21
|
+
/**
|
|
22
|
+
* For conversion from hex use the `fromHex` function from lucid-evolution.
|
|
23
|
+
*/
|
|
24
|
+
iassetName: Uint8Array<ArrayBufferLike>,
|
|
25
|
+
): Promise<IAssetOutput> {
|
|
26
|
+
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
27
|
+
createScriptAddress(
|
|
28
|
+
lucid.config().network!,
|
|
29
|
+
sysParams.validatorHashes.iassetHash,
|
|
30
|
+
),
|
|
31
|
+
assetClassToUnit(
|
|
32
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
|
|
33
|
+
),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return matchSingle(
|
|
37
|
+
F.pipe(
|
|
38
|
+
iassetUtxos.map((utxo) =>
|
|
39
|
+
F.pipe(
|
|
40
|
+
O.fromNullable(utxo.datum),
|
|
41
|
+
O.flatMap(parseIAssetDatum),
|
|
42
|
+
O.flatMap((datum) => {
|
|
43
|
+
if (toHex(datum.assetName) === toHex(iassetName)) {
|
|
44
|
+
return O.some({ utxo, datum: datum });
|
|
45
|
+
} else {
|
|
46
|
+
return O.none;
|
|
47
|
+
}
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
A.compact,
|
|
52
|
+
),
|
|
53
|
+
(res) =>
|
|
54
|
+
new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function findCollateralAsset(
|
|
59
|
+
lucid: LucidEvolution,
|
|
60
|
+
sysParams: SystemParams,
|
|
61
|
+
/**
|
|
62
|
+
* For conversion from hex use the `fromHex` function from lucid-evolution.
|
|
63
|
+
*/
|
|
64
|
+
iassetName: Uint8Array<ArrayBufferLike>,
|
|
65
|
+
collateralAsset: AssetClass,
|
|
66
|
+
): Promise<CollateralAssetOutput> {
|
|
67
|
+
const collateralAssetUtxos = await lucid.utxosAtWithUnit(
|
|
68
|
+
createScriptAddress(
|
|
69
|
+
lucid.config().network!,
|
|
70
|
+
sysParams.validatorHashes.iassetHash,
|
|
71
|
+
),
|
|
72
|
+
assetClassToUnit(
|
|
73
|
+
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
74
|
+
),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return matchSingle(
|
|
78
|
+
F.pipe(
|
|
79
|
+
collateralAssetUtxos.map((utxo) =>
|
|
80
|
+
F.pipe(
|
|
81
|
+
O.fromNullable(utxo.datum),
|
|
82
|
+
O.flatMap(parseCollateralAssetDatum),
|
|
83
|
+
O.flatMap((datum) => {
|
|
84
|
+
if (
|
|
85
|
+
isSameAssetClass(datum.collateralAsset, collateralAsset) &&
|
|
86
|
+
toHex(iassetName) === toHex(datum.iasset)
|
|
87
|
+
) {
|
|
88
|
+
return O.some({ utxo, datum: datum });
|
|
89
|
+
} else {
|
|
90
|
+
return O.none;
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
A.compact,
|
|
96
|
+
),
|
|
97
|
+
(res) =>
|
|
98
|
+
new Error(
|
|
99
|
+
'Expected a single Collateral Asset UTXO.: ' + JSON.stringify(res),
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -69,7 +69,6 @@ import { mkStabilityPoolValidatorFromSP } from '../stability-pool/scripts';
|
|
|
69
69
|
import { mkTreasuryValidatorFromSP } from '../treasury/scripts';
|
|
70
70
|
import { mkCDPCreatorValidatorFromSP } from '../cdp-creator/scripts';
|
|
71
71
|
import { mkGovValidatorFromSP } from '../gov/scripts';
|
|
72
|
-
import { submitTx } from '../../utils/lucid-utils';
|
|
73
72
|
import {
|
|
74
73
|
deriveAuthToken,
|
|
75
74
|
initScriptRef,
|
|
@@ -121,17 +120,29 @@ export async function initPythConfig(
|
|
|
121
120
|
pythFeedValidator,
|
|
122
121
|
);
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
try {
|
|
124
|
+
// Register the stake key for pyth feed validator.
|
|
125
|
+
await runAndAwaitTxBuilder(
|
|
126
|
+
lucid,
|
|
127
|
+
lucid.newTx().register.Stake(
|
|
128
|
+
credentialToRewardAddress(lucid.config().network!, {
|
|
129
|
+
hash: validatorToScriptHash(pythFeedValidator),
|
|
130
|
+
type: 'Script',
|
|
131
|
+
}),
|
|
132
|
+
),
|
|
133
|
+
);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const message =
|
|
136
|
+
error instanceof Error ? error.message : String(error);
|
|
137
|
+
if (
|
|
138
|
+
!message.includes('StakeKeyRegisteredDELEG') &&
|
|
139
|
+
!message.includes(
|
|
140
|
+
'Trying to re-register some already known credentials.',
|
|
141
|
+
)
|
|
142
|
+
) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
135
146
|
const key = `${asset.name}/${toHex(collateral.collateralAsset.currencySymbol)}.${toHex(collateral.collateralAsset.tokenName)}`;
|
|
136
147
|
|
|
137
148
|
return {
|
|
@@ -368,8 +379,20 @@ export async function init(
|
|
|
368
379
|
scriptHashToCredential(cdpRedeemValHash),
|
|
369
380
|
);
|
|
370
381
|
|
|
371
|
-
|
|
372
|
-
|
|
382
|
+
try {
|
|
383
|
+
await runAndAwaitTxBuilder(
|
|
384
|
+
lucid,
|
|
385
|
+
lucid.newTx().register.Stake(cdpRedeemRewardAddr),
|
|
386
|
+
);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
389
|
+
if (
|
|
390
|
+
!message.includes('StakeKeyRegisteredDELEG') &&
|
|
391
|
+
!message.includes('Trying to re-register some already known credentials.')
|
|
392
|
+
) {
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
373
396
|
const cdpParams: CdpParamsSP = {
|
|
374
397
|
cdpAuthToken: toSystemParamsAsset(cdpToken),
|
|
375
398
|
cdpAssetSymbol: { unCurrencySymbol: assetSymbol },
|
|
@@ -578,7 +601,7 @@ export async function init(
|
|
|
578
601
|
lucid,
|
|
579
602
|
govParams,
|
|
580
603
|
govNftAsset,
|
|
581
|
-
|
|
604
|
+
initialAssets,
|
|
582
605
|
protocolParams,
|
|
583
606
|
);
|
|
584
607
|
|
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { createScriptAddress } from '../../src';
|
|
3
2
|
import { option as O, function as F } from 'fp-ts';
|
|
4
3
|
import {
|
|
5
|
-
AssetClass,
|
|
6
4
|
assetClassToUnit,
|
|
7
5
|
assetClassValueOf,
|
|
8
6
|
getRandomElement,
|
|
9
7
|
matchSingle,
|
|
10
8
|
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
9
|
+
import { createScriptAddress } from '../../utils/lucid-utils';
|
|
10
|
+
import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
|
|
11
11
|
|
|
12
12
|
export async function findAllInterestCollectors(
|
|
13
13
|
lucid: LucidEvolution,
|
|
14
|
-
|
|
14
|
+
sysParams: SystemParams,
|
|
15
15
|
): Promise<UTxO[]> {
|
|
16
16
|
return lucid.utxosAt(
|
|
17
|
-
createScriptAddress(
|
|
17
|
+
createScriptAddress(
|
|
18
|
+
lucid.config().network!,
|
|
19
|
+
sysParams.validatorHashes.interestCollectionHash,
|
|
20
|
+
),
|
|
18
21
|
);
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export async function findAdminInterestCollectors(
|
|
22
25
|
lucid: LucidEvolution,
|
|
23
|
-
|
|
24
|
-
multisigUtxoNft: AssetClass,
|
|
26
|
+
sysParams: SystemParams,
|
|
25
27
|
): Promise<UTxO> {
|
|
26
28
|
return matchSingle(
|
|
27
29
|
await lucid.utxosAtWithUnit(
|
|
28
|
-
createScriptAddress(
|
|
29
|
-
|
|
30
|
+
createScriptAddress(
|
|
31
|
+
lucid.config().network!,
|
|
32
|
+
sysParams.validatorHashes.interestCollectionHash,
|
|
33
|
+
),
|
|
34
|
+
assetClassToUnit(
|
|
35
|
+
fromSystemParamsAsset(
|
|
36
|
+
sysParams.interestCollectionParams.multisigUtxoNft,
|
|
37
|
+
),
|
|
38
|
+
),
|
|
30
39
|
),
|
|
31
40
|
(_) => new Error('Expected a single admin interest collector UTXO'),
|
|
32
41
|
);
|
|
@@ -34,12 +43,19 @@ export async function findAdminInterestCollectors(
|
|
|
34
43
|
|
|
35
44
|
export async function findRandomNonAdminInterestCollector(
|
|
36
45
|
lucid: LucidEvolution,
|
|
37
|
-
|
|
38
|
-
multisigUtxoNft: AssetClass,
|
|
46
|
+
sysParams: SystemParams,
|
|
39
47
|
): Promise<UTxO> {
|
|
40
48
|
const allCollectors = (
|
|
41
|
-
await findAllInterestCollectors(lucid,
|
|
42
|
-
).filter(
|
|
49
|
+
await findAllInterestCollectors(lucid, sysParams)
|
|
50
|
+
).filter(
|
|
51
|
+
(utxo) =>
|
|
52
|
+
!assetClassValueOf(
|
|
53
|
+
utxo.assets,
|
|
54
|
+
fromSystemParamsAsset(
|
|
55
|
+
sysParams.interestCollectionParams.multisigUtxoNft,
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
43
59
|
|
|
44
60
|
return F.pipe(
|
|
45
61
|
O.fromNullable(getRandomElement(allCollectors)),
|
|
@@ -8,6 +8,30 @@ import {
|
|
|
8
8
|
} from './types';
|
|
9
9
|
import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
|
|
10
10
|
import { fromHex } from '@lucid-evolution/lucid';
|
|
11
|
+
import { array as A, function as F } from 'fp-ts';
|
|
12
|
+
import { BigIntOrd } from '../../utils/bigint-utils';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Collect all unique price feed IDs in the derived price sorted ascending.
|
|
16
|
+
*/
|
|
17
|
+
export function collectPriceFeedIds(
|
|
18
|
+
derivedPythPrice: DerivedPythPrice,
|
|
19
|
+
): bigint[] {
|
|
20
|
+
const ids = match(derivedPythPrice)
|
|
21
|
+
.with({ Value: P.select() }, (value) => [
|
|
22
|
+
BigInt(value.configuration.priceFeedId),
|
|
23
|
+
])
|
|
24
|
+
.with({ Inverse: P.select() }, (inverse) =>
|
|
25
|
+
collectPriceFeedIds(fromDataDerivedPythPrice(inverse.value)),
|
|
26
|
+
)
|
|
27
|
+
.with({ Divide: P.select() }, (divide) => [
|
|
28
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.x)),
|
|
29
|
+
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.y)),
|
|
30
|
+
])
|
|
31
|
+
.exhaustive();
|
|
32
|
+
|
|
33
|
+
return F.pipe(ids, A.uniq(BigIntOrd), A.sort(BigIntOrd));
|
|
34
|
+
}
|
|
11
35
|
|
|
12
36
|
/** Rational form { num, den } so we can do exact division (e.g. 1/0.00001 = 100000). */
|
|
13
37
|
export function derivePythPrice(
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { fromSystemParamsAsset, SystemParams } from '../../src';
|
|
3
2
|
import { option as O, function as F } from 'fp-ts';
|
|
4
3
|
import {
|
|
5
4
|
AssetClass,
|
|
@@ -7,16 +6,25 @@ import {
|
|
|
7
6
|
assetClassValueOf,
|
|
8
7
|
getRandomElement,
|
|
9
8
|
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
9
|
+
import { fromSystemParamsAsset, SystemParams } from '../../types/system-params';
|
|
10
10
|
|
|
11
|
-
export async function
|
|
11
|
+
export async function findAllTreasuryUtxos(
|
|
12
12
|
lucid: LucidEvolution,
|
|
13
13
|
sysParams: SystemParams,
|
|
14
|
-
): Promise<UTxO> {
|
|
14
|
+
): Promise<UTxO[]> {
|
|
15
15
|
// We need to consider both with staking credential and without.
|
|
16
|
-
|
|
17
|
-
hash: sysParams.validatorHashes.treasuryHash,
|
|
16
|
+
return lucid.utxosAt({
|
|
18
17
|
type: 'Script',
|
|
18
|
+
hash: sysParams.validatorHashes.treasuryHash,
|
|
19
19
|
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function findRandomTreasuryUtxo(
|
|
23
|
+
lucid: LucidEvolution,
|
|
24
|
+
sysParams: SystemParams,
|
|
25
|
+
): Promise<UTxO> {
|
|
26
|
+
// We need to consider both with staking credential and without.
|
|
27
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
20
28
|
|
|
21
29
|
return F.pipe(
|
|
22
30
|
O.fromNullable(getRandomElement(treasuryUtxos)),
|
|
@@ -31,10 +39,7 @@ export async function findRandomTreasuryUtxoWithOnlyAda(
|
|
|
31
39
|
sysParams: SystemParams,
|
|
32
40
|
): Promise<UTxO> {
|
|
33
41
|
// We need to consider both with staking credential and without.
|
|
34
|
-
const treasuryUtxos = await lucid
|
|
35
|
-
hash: sysParams.validatorHashes.treasuryHash,
|
|
36
|
-
type: 'Script',
|
|
37
|
-
});
|
|
42
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
38
43
|
|
|
39
44
|
const adaOnlyTreasuryUtxos = treasuryUtxos.filter(
|
|
40
45
|
(utxo) => Object.keys(utxo.assets).length == 1,
|
|
@@ -72,27 +77,13 @@ export async function findRandomTreasuryUtxoWithAsset(
|
|
|
72
77
|
);
|
|
73
78
|
}
|
|
74
79
|
|
|
75
|
-
export async function findAllTreasuryUtxos(
|
|
76
|
-
lucid: LucidEvolution,
|
|
77
|
-
sysParams: SystemParams,
|
|
78
|
-
): Promise<UTxO[]> {
|
|
79
|
-
// We need to consider both with staking credential and without.
|
|
80
|
-
return lucid.utxosAt({
|
|
81
|
-
type: 'Script',
|
|
82
|
-
hash: sysParams.validatorHashes.treasuryHash,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
80
|
export async function findAllTreasuryUtxosWithNonAdaAsset(
|
|
87
81
|
lucid: LucidEvolution,
|
|
88
82
|
sysParams: SystemParams,
|
|
89
83
|
includeDaoToken: boolean = true,
|
|
90
84
|
): Promise<UTxO[]> {
|
|
91
85
|
// We need to consider both with staking credential and without.
|
|
92
|
-
const treasuryUtxos = await lucid
|
|
93
|
-
hash: sysParams.validatorHashes.treasuryHash,
|
|
94
|
-
type: 'Script',
|
|
95
|
-
});
|
|
86
|
+
const treasuryUtxos = await findAllTreasuryUtxos(lucid, sysParams);
|
|
96
87
|
|
|
97
88
|
const treasuryUtxosWithNonAdaAsset = treasuryUtxos.filter(
|
|
98
89
|
(utxo) =>
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './contracts/cdp/types-new';
|
|
|
5
5
|
export * from './contracts/cdp/scripts';
|
|
6
6
|
export * from './contracts/cdp-creator/types';
|
|
7
7
|
export * from './contracts/cdp-creator/scripts';
|
|
8
|
+
export * from './contracts/cdp-creator/queries';
|
|
8
9
|
export * from './contracts/poll/scripts';
|
|
9
10
|
export * from './contracts/collector/transactions';
|
|
10
11
|
export * from './contracts/collector/types-new';
|
|
@@ -28,16 +29,18 @@ export * from './contracts/interest-collection/types';
|
|
|
28
29
|
export * from './contracts/interest-collection/types-new';
|
|
29
30
|
export * from './contracts/interest-collection/scripts';
|
|
30
31
|
export * from './contracts/interest-collection/transactions';
|
|
32
|
+
export * from './contracts/interest-collection/queries';
|
|
31
33
|
export * from './contracts/interest-oracle/scripts';
|
|
32
34
|
export * from './contracts/version-registry/types';
|
|
33
35
|
export * from './contracts/version-registry/scripts';
|
|
34
36
|
export * from './contracts/treasury/transactions';
|
|
35
37
|
export * from './contracts/treasury/helpers';
|
|
38
|
+
export * from './contracts/treasury/scripts';
|
|
39
|
+
export * from './contracts/treasury/queries';
|
|
36
40
|
export * from './contracts/stability-pool/helpers';
|
|
37
41
|
export * from './utils/time-helpers';
|
|
38
42
|
export * from './contracts/cdp/scripts';
|
|
39
43
|
export * from './contracts/collector/scripts';
|
|
40
|
-
export * from './contracts/treasury/scripts';
|
|
41
44
|
export * from './contracts/execute/types';
|
|
42
45
|
export * from './contracts/execute/types-new';
|
|
43
46
|
export * from './contracts/execute/scripts';
|
|
@@ -75,9 +78,11 @@ export * from './contracts/initialize/actions';
|
|
|
75
78
|
export * from './utils/pyth';
|
|
76
79
|
export * from './contracts/pyth-feed/types';
|
|
77
80
|
export * from './contracts/pyth-feed/scripts';
|
|
81
|
+
export * from './contracts/pyth-feed/helpers';
|
|
78
82
|
export * from './contracts/iasset/types';
|
|
79
83
|
export * from './contracts/iasset/scripts';
|
|
80
84
|
export * from './contracts/iasset/helpers';
|
|
85
|
+
export * from './contracts/iasset/queries';
|
|
81
86
|
export * from './contracts/stableswap/helpers';
|
|
82
87
|
export * from './contracts/stableswap/transactions';
|
|
83
88
|
export * from './contracts/stableswap/types-new';
|
package/tests/cdp/actions.ts
CHANGED
|
@@ -59,7 +59,7 @@ import { runFeedPriceToOracle } from '../price-oracle/actions';
|
|
|
59
59
|
import { rationalFromInt, rationalMul } from '../../src/types/rational';
|
|
60
60
|
import { array as A } from 'fp-ts';
|
|
61
61
|
import { sendValueTo } from '../utils';
|
|
62
|
-
import { findRandomTreasuryUtxoWithAsset } from '
|
|
62
|
+
import { findRandomTreasuryUtxoWithAsset } from '../../src/contracts/treasury/queries';
|
|
63
63
|
|
|
64
64
|
// Selects users wallet and opens a CDP with the given initial collateral and mint amount
|
|
65
65
|
export async function runOpenCdp(
|
package/tests/cdp/cdp-queries.ts
CHANGED
|
@@ -40,14 +40,13 @@ import { findPriceOracle } from '../price-oracle/price-oracle-queries';
|
|
|
40
40
|
import { findInterestOracle } from '../queries/interest-oracle-queries';
|
|
41
41
|
import { findRandomCollector } from '../queries/collector-queries';
|
|
42
42
|
import { findGov } from '../gov/governance-queries';
|
|
43
|
-
import { findRandomTreasuryUtxoWithOnlyAda } from '
|
|
43
|
+
import { findRandomTreasuryUtxoWithOnlyAda } from '../../src/contracts/treasury/queries';
|
|
44
44
|
import { parsePriceOracleDatum } from '../../src/contracts/price-oracle/types-new';
|
|
45
45
|
import {
|
|
46
46
|
CollateralAssetOutput,
|
|
47
47
|
IAssetOutput,
|
|
48
48
|
} from '../../src/contracts/iasset/types';
|
|
49
|
-
import { findRandomNonAdminInterestCollector } from '
|
|
50
|
-
import { LucidContext } from '../test-helpers';
|
|
49
|
+
import { findRandomNonAdminInterestCollector } from '../../src/contracts/interest-collection/queries';
|
|
51
50
|
import { Rational } from '../../src/types/rational';
|
|
52
51
|
|
|
53
52
|
export async function findAllActiveCdps(
|
|
@@ -245,24 +244,6 @@ export async function findRandomCdpCreator(
|
|
|
245
244
|
);
|
|
246
245
|
}
|
|
247
246
|
|
|
248
|
-
export async function findRandomCdpCreatorNew(
|
|
249
|
-
context: LucidContext,
|
|
250
|
-
sysParams: SystemParams,
|
|
251
|
-
): Promise<UTxO> {
|
|
252
|
-
const cdpCreatorUtxos = await findAllCdpCreators(
|
|
253
|
-
context.lucid,
|
|
254
|
-
sysParams.validatorHashes.cdpCreatorHash,
|
|
255
|
-
fromSystemParamsAsset(sysParams.cdpCreatorParams.cdpCreatorNft),
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
return F.pipe(
|
|
259
|
-
O.fromNullable(getRandomElement(cdpCreatorUtxos)),
|
|
260
|
-
O.match(() => {
|
|
261
|
-
throw new Error('Expected some cdp creator UTXOs.');
|
|
262
|
-
}, F.identity),
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
247
|
export function findPriceOracleFromCollateralAsset(
|
|
267
248
|
lucid: LucidEvolution,
|
|
268
249
|
collateralAsset: CollateralAssetOutput,
|
|
@@ -329,8 +310,7 @@ export async function findAllNecessaryOrefs(
|
|
|
329
310
|
),
|
|
330
311
|
interestCollectorUtxo: await findRandomNonAdminInterestCollector(
|
|
331
312
|
lucid,
|
|
332
|
-
sysParams
|
|
333
|
-
fromSystemParamsAsset(sysParams.interestCollectionParams.multisigUtxoNft),
|
|
313
|
+
sysParams,
|
|
334
314
|
),
|
|
335
315
|
govUtxo: (
|
|
336
316
|
await findGov(
|
|
@@ -75,7 +75,7 @@ import { AssetInfo } from '../endpoints/initialize';
|
|
|
75
75
|
import { LucidContext } from '../test-helpers';
|
|
76
76
|
import { option as O, function as F } from 'fp-ts';
|
|
77
77
|
import { findPriceOracle } from '../price-oracle/price-oracle-queries';
|
|
78
|
-
import { findRandomNonAdminInterestCollector } from '
|
|
78
|
+
import { findRandomNonAdminInterestCollector } from '../../src/contracts/interest-collection/queries';
|
|
79
79
|
import {
|
|
80
80
|
serialiseCDPCreatorDatum,
|
|
81
81
|
serialiseCDPCreatorRedeemer,
|
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
CollectInterestVariation,
|
|
85
85
|
testCollectInterest,
|
|
86
86
|
} from '../interest-collection/transactions-mutated';
|
|
87
|
-
import { findRandomTreasuryUtxoWithOnlyAda } from '
|
|
87
|
+
import { findRandomTreasuryUtxoWithOnlyAda } from '../../src/contracts/treasury/queries';
|
|
88
88
|
import {
|
|
89
89
|
Rational,
|
|
90
90
|
rationalFloor,
|
|
@@ -909,8 +909,7 @@ export async function runTestAdjustCdpDelisted(
|
|
|
909
909
|
|
|
910
910
|
const interestCollectorUtxo = await findRandomNonAdminInterestCollector(
|
|
911
911
|
context.lucid,
|
|
912
|
-
sysParams
|
|
913
|
-
fromSystemParamsAsset(sysParams.interestCollectionParams.multisigUtxoNft),
|
|
912
|
+
sysParams,
|
|
914
913
|
);
|
|
915
914
|
|
|
916
915
|
const validateFrom = slotToUnixTime(network, context.emulator.slot - 1);
|