@indigo-labs/indigo-sdk 0.2.41 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +4 -2
- package/dist/index.d.mts +3008 -2194
- package/dist/index.d.ts +3008 -2194
- package/dist/index.js +9827 -6194
- package/dist/index.mjs +8591 -4809
- package/package.json +14 -3
- package/src/contracts/cdp/helpers.ts +68 -72
- package/src/contracts/cdp/scripts.ts +50 -13
- package/src/contracts/cdp/transactions.ts +831 -545
- package/src/contracts/cdp/types-new.ts +256 -0
- package/src/contracts/cdp/types.ts +26 -144
- package/src/contracts/cdp-creator/scripts.ts +15 -9
- package/src/contracts/cdp-creator/types-new.ts +50 -0
- package/src/contracts/cdp-creator/types.ts +5 -31
- package/src/contracts/collector/scripts.ts +1 -1
- package/src/contracts/collector/transactions.ts +23 -13
- package/src/contracts/collector/types-new.ts +17 -0
- package/src/contracts/execute/scripts.ts +19 -10
- package/src/contracts/execute/types-new.ts +44 -0
- package/src/contracts/execute/types.ts +5 -38
- package/src/contracts/gov/helpers.ts +187 -51
- package/src/contracts/gov/scripts.ts +17 -10
- package/src/contracts/gov/transactions.ts +599 -271
- package/src/contracts/gov/types-new.ts +253 -100
- package/src/contracts/gov/types.ts +4 -71
- package/src/contracts/iasset/helpers.ts +172 -0
- package/src/contracts/iasset/scripts.ts +38 -0
- package/src/contracts/iasset/types.ts +154 -0
- package/src/contracts/initialize/actions.ts +768 -0
- package/src/contracts/initialize/helpers.ts +611 -36
- package/src/contracts/initialize/types.ts +102 -28
- package/src/contracts/interest-collection/helpers.ts +19 -0
- package/src/contracts/interest-collection/scripts.ts +44 -0
- package/src/contracts/interest-collection/transactions.ts +436 -0
- package/src/contracts/interest-collection/types-new.ts +50 -0
- package/src/contracts/interest-collection/types.ts +26 -0
- package/src/contracts/interest-oracle/helpers.ts +2 -30
- package/src/contracts/interest-oracle/scripts.ts +1 -1
- package/src/contracts/interest-oracle/transactions.ts +21 -16
- package/src/contracts/interest-oracle/types-new.ts +32 -0
- package/src/contracts/interest-oracle/types.ts +1 -40
- package/src/contracts/one-shot/transactions.ts +1 -2
- package/src/contracts/poll/helpers.ts +5 -23
- package/src/contracts/poll/scripts.ts +12 -13
- package/src/contracts/poll/types-poll-manager.ts +1 -19
- package/src/contracts/poll/types-poll-new.ts +170 -0
- package/src/contracts/poll/types-poll-shard.ts +2 -24
- package/src/contracts/price-oracle/helpers.ts +1 -4
- package/src/contracts/price-oracle/scripts.ts +3 -8
- package/src/contracts/price-oracle/transactions.ts +32 -25
- package/src/contracts/price-oracle/types-new.ts +50 -0
- package/src/contracts/price-oracle/types.ts +2 -36
- package/src/contracts/pyth-feed/helpers.ts +58 -0
- package/src/contracts/pyth-feed/scripts.ts +15 -0
- package/src/contracts/pyth-feed/types.ts +181 -0
- package/src/contracts/rob/helpers.ts +405 -0
- package/src/contracts/rob/scripts.ts +35 -0
- package/src/contracts/rob/transactions.ts +410 -0
- package/src/contracts/rob/types-new.ts +128 -0
- package/src/contracts/rob/types.ts +16 -0
- package/src/contracts/rob-leverage/helpers.ts +424 -0
- package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
- package/src/contracts/stability-pool/helpers.ts +714 -230
- package/src/contracts/stability-pool/scripts.ts +20 -15
- package/src/contracts/stability-pool/transactions.ts +625 -495
- package/src/contracts/stability-pool/types-new.ts +237 -100
- package/src/contracts/stability-pool/types.ts +5 -22
- package/src/contracts/stableswap/helpers.ts +22 -0
- package/src/contracts/stableswap/scripts.ts +37 -0
- package/src/contracts/stableswap/transactions.ts +647 -0
- package/src/contracts/stableswap/types-new.ts +131 -0
- package/src/contracts/stableswap/types.ts +17 -0
- package/src/contracts/staking/helpers.ts +49 -34
- package/src/contracts/staking/scripts.ts +1 -1
- package/src/contracts/staking/transactions.ts +85 -130
- package/src/contracts/staking/types-new.ts +60 -28
- package/src/contracts/staking/types.ts +1 -28
- package/src/contracts/treasury/helpers.ts +21 -0
- package/src/contracts/treasury/scripts.ts +16 -26
- package/src/contracts/treasury/transactions.ts +256 -27
- package/src/contracts/treasury/types-new.ts +69 -0
- package/src/contracts/treasury/types.ts +2 -43
- package/src/contracts/version-registry/scripts.ts +2 -2
- package/src/contracts/version-registry/types-new.ts +6 -7
- package/src/index.ts +37 -20
- package/src/scripts/auth-token-policy.ts +3 -2
- package/src/scripts/iasset-policy.ts +3 -2
- package/src/types/evolution-schema-options.ts +3 -3
- package/src/types/generic.ts +17 -89
- package/src/types/multisig.ts +48 -0
- package/src/types/on-chain-decimal.ts +14 -7
- package/src/types/rational.ts +61 -0
- package/src/types/system-params.ts +237 -41
- package/src/utils/array-utils.ts +70 -1
- package/src/utils/bigint-utils.ts +12 -0
- package/src/utils/indigo-helpers.ts +8 -10
- package/src/utils/lucid-utils.ts +47 -40
- package/src/utils/oracle-helpers.ts +62 -0
- package/src/utils/pyth/decode.ts +223 -0
- package/src/utils/pyth/encode.ts +262 -0
- package/src/utils/pyth/index.ts +14 -0
- package/src/utils/pyth/types.ts +87 -0
- package/src/validators/always-succeed-validator.ts +6 -0
- package/src/validators/cdp-creator-validator.ts +2 -2
- package/src/validators/cdp-redeem-validator.ts +7 -0
- package/src/validators/cdp-validator.ts +2 -2
- package/src/validators/collector-validator.ts +2 -2
- package/src/validators/execute-validator.ts +2 -2
- package/src/validators/governance-validator.ts +2 -2
- package/src/validators/iasset-validator.ts +7 -0
- package/src/validators/interest-collection-validator.ts +7 -0
- package/src/validators/interest-oracle-validator.ts +2 -2
- package/src/validators/poll-manager-validator.ts +2 -2
- package/src/validators/poll-shard-validator.ts +2 -2
- package/src/validators/price-oracle-validator.ts +7 -0
- package/src/validators/pyth-feed-validator.ts +7 -0
- package/src/validators/rob-validator.ts +7 -0
- package/src/validators/stability-pool-validator.ts +2 -2
- package/src/validators/stableswap-validator.ts +7 -0
- package/src/validators/staking-validator.ts +2 -2
- package/src/validators/treasury-validator.ts +2 -2
- package/src/validators/version-record-policy.ts +2 -2
- package/src/validators/version-registry-validator.ts +2 -2
- package/tests/always-succeed/script.ts +7 -0
- package/tests/bigint-utils.test.ts +41 -0
- package/tests/cdp/actions.ts +611 -0
- package/tests/cdp/cdp-helpers.ts +55 -0
- package/tests/cdp/cdp-queries.ts +440 -0
- package/tests/cdp/cdp.test.ts +6087 -0
- package/tests/cdp/transactions-mutated.ts +1729 -0
- package/tests/data/system-params.json +177 -34
- package/tests/datums.test.ts +209 -210
- package/tests/endpoints/initialize.ts +68 -0
- package/tests/endpoints/interest-collector.ts +37 -0
- package/tests/endpoints/treasury.ts +70 -0
- package/tests/gov/actions.ts +406 -0
- package/tests/gov/gov.test.ts +4450 -0
- package/tests/{queries → gov}/governance-queries.ts +6 -3
- package/tests/hash-checks.test.ts +38 -11
- package/tests/indigo-test-helpers.ts +100 -0
- package/tests/initialize.test.ts +61 -9
- package/tests/interest-collection/interest-collection.test.ts +892 -0
- package/tests/interest-collection/interest-collector-queries.ts +49 -0
- package/tests/interest-collection/transactions-mutated.ts +260 -0
- package/tests/interest-oracle.test.ts +43 -35
- package/tests/mock/assets-mock.ts +234 -23
- package/tests/mock/protocol-params-mock.ts +21 -0
- package/tests/price-oracle/actions.ts +163 -0
- package/tests/price-oracle/price-oracle-queries.ts +12 -0
- package/tests/price-oracle/price-oracle.test.ts +240 -0
- package/tests/price-oracle/transactions-mutated.ts +62 -0
- package/tests/pyth/endpoints.ts +96 -0
- package/tests/pyth/helpers.ts +37 -0
- package/tests/pyth/pyth-encoding.test.ts +376 -0
- package/tests/pyth/pyth-indigo.test.ts +509 -0
- package/tests/pyth/pyth.test.ts +300 -0
- package/tests/queries/execute-queries.ts +6 -5
- package/tests/queries/iasset-queries.ts +175 -5
- package/tests/queries/interest-oracle-queries.ts +4 -2
- package/tests/queries/poll-queries.ts +8 -9
- package/tests/queries/stability-pool-queries.ts +95 -48
- package/tests/queries/staking-queries.ts +4 -2
- package/tests/queries/treasury-queries.ts +80 -5
- package/tests/rob/actions.ts +58 -0
- package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
- package/tests/rob/rob-queries.ts +95 -0
- package/tests/rob/rob.test.ts +3762 -0
- package/tests/rob/transactions-mutated.ts +853 -0
- package/tests/script-size.test.ts +240 -0
- package/tests/setup.ts +135 -0
- package/tests/stability-pool/actions.ts +210 -0
- package/tests/stability-pool.test.ts +5469 -666
- package/tests/stableswap/stableswap-actions.ts +84 -0
- package/tests/stableswap/stableswap-queries.ts +89 -0
- package/tests/stableswap/stableswap.test.ts +3891 -0
- package/tests/stableswap/transactions-mutated.ts +348 -0
- package/tests/staking.test.ts +82 -99
- package/tests/test-helpers.ts +58 -11
- package/tests/treasury.test.ts +242 -0
- package/tests/utils/asserts.ts +74 -0
- package/tests/utils/benchmark-utils.ts +81 -0
- package/tests/utils/index.ts +122 -4
- package/tsconfig.json +9 -1
- package/vitest.config.ts +3 -1
- package/src/contracts/collector/types.ts +0 -16
- package/src/contracts/initialize/transactions.ts +0 -891
- package/src/contracts/leverage/helpers.ts +0 -424
- package/src/contracts/lrp/helpers.ts +0 -294
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/lrp/transactions.ts +0 -250
- package/src/contracts/lrp/types.ts +0 -131
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/vesting/helpers.ts +0 -218
- package/src/utils/value-helpers.ts +0 -37
- package/src/validators/lrp-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1528
- package/tests/gov.test.ts +0 -2011
- package/tests/lrp.test.ts +0 -673
- package/tests/queries/cdp-queries.ts +0 -220
- package/tests/queries/lrp-queries.ts +0 -76
- package/tests/queries/price-oracle-queries.ts +0 -10
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
import { castExecuteParams, ExecuteParams } from './types';
|
|
7
7
|
import {
|
|
8
8
|
ExecuteParamsSP,
|
|
9
|
-
|
|
9
|
+
fromSystemParamsAssetLucid,
|
|
10
10
|
} from '../../types/system-params';
|
|
11
11
|
import { _executeValidator } from '../../validators/execute-validator';
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export const mkExecuteValidator = (
|
|
|
14
14
|
params: ExecuteParams,
|
|
15
15
|
): SpendingValidator => {
|
|
16
16
|
return {
|
|
17
|
-
type: '
|
|
17
|
+
type: 'PlutusV3',
|
|
18
18
|
script: applySingleCborEncoding(
|
|
19
19
|
applyParamsToScript(_executeValidator.cborHex, [
|
|
20
20
|
castExecuteParams(params),
|
|
@@ -27,21 +27,30 @@ export const mkExecuteValidatorFromSP = (
|
|
|
27
27
|
params: ExecuteParamsSP,
|
|
28
28
|
): SpendingValidator => {
|
|
29
29
|
return {
|
|
30
|
-
type: '
|
|
30
|
+
type: 'PlutusV3',
|
|
31
31
|
script: applySingleCborEncoding(
|
|
32
32
|
applyParamsToScript(_executeValidator.cborHex, [
|
|
33
33
|
castExecuteParams({
|
|
34
|
-
govNFT:
|
|
35
|
-
upgradeToken:
|
|
36
|
-
iAssetToken:
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
govNFT: fromSystemParamsAssetLucid(params.govNFT),
|
|
35
|
+
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
36
|
+
iAssetToken: fromSystemParamsAssetLucid(params.iAssetToken),
|
|
37
|
+
collateralAssetToken: fromSystemParamsAssetLucid(
|
|
38
|
+
params.collateralAssetToken,
|
|
39
|
+
),
|
|
40
|
+
stabilityPoolToken: fromSystemParamsAssetLucid(
|
|
41
|
+
params.stabilityPoolToken,
|
|
42
|
+
),
|
|
43
|
+
cdpCreatorToken: fromSystemParamsAssetLucid(params.cdpCreatorToken),
|
|
44
|
+
cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
|
|
45
|
+
versionRecordToken: fromSystemParamsAssetLucid(
|
|
46
|
+
params.versionRecordToken,
|
|
47
|
+
),
|
|
48
|
+
iassetValHash: params.iassetValHash,
|
|
39
49
|
cdpValHash: params.cdpValHash,
|
|
40
50
|
sPoolValHash: params.sPoolValHash,
|
|
41
51
|
versionRegistryValHash: params.versionRegistryValHash,
|
|
42
52
|
treasuryValHash: params.treasuryValHash,
|
|
43
|
-
|
|
44
|
-
} as ExecuteParams),
|
|
53
|
+
}),
|
|
45
54
|
]),
|
|
46
55
|
),
|
|
47
56
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { option as O, function as F } from 'fp-ts';
|
|
2
|
+
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
3
|
+
import {
|
|
4
|
+
ProposalContentSchema,
|
|
5
|
+
TreasuryWithdrawalSchema,
|
|
6
|
+
} from '../gov/types-new';
|
|
7
|
+
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
8
|
+
|
|
9
|
+
const ExecuteDatumSchema = TSchema.Struct({
|
|
10
|
+
id: TSchema.Integer,
|
|
11
|
+
content: ProposalContentSchema,
|
|
12
|
+
passedTime: TSchema.Integer,
|
|
13
|
+
votingEndTime: TSchema.Integer,
|
|
14
|
+
protocolVersion: TSchema.Integer,
|
|
15
|
+
/// Value proposed to be withdrawn from the treasury as part of the proposal.
|
|
16
|
+
treasuryWithdrawal: TSchema.NullOr(TreasuryWithdrawalSchema),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type ExecuteDatum = typeof ExecuteDatumSchema.Type;
|
|
20
|
+
|
|
21
|
+
export function serialiseExecuteDatum(d: ExecuteDatum): string {
|
|
22
|
+
return Data.withSchema(ExecuteDatumSchema).toCBORHex(d);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseExecuteDatum(datum: string): O.Option<ExecuteDatum> {
|
|
26
|
+
try {
|
|
27
|
+
return O.some(
|
|
28
|
+
Data.withSchema(ExecuteDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
29
|
+
datum,
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return O.none;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function parseExecuteDatumOrThrow(datum: string): ExecuteDatum {
|
|
38
|
+
return F.pipe(
|
|
39
|
+
parseExecuteDatum(datum),
|
|
40
|
+
O.match(() => {
|
|
41
|
+
throw new Error('Expected an Execute datum.');
|
|
42
|
+
}, F.identity),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -1,57 +1,24 @@
|
|
|
1
|
-
import { Data
|
|
1
|
+
import { Data } from '@lucid-evolution/lucid';
|
|
2
2
|
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
-
import { TreasuryWithdrawalSchema } from '../gov/types';
|
|
4
|
-
import { option as O, function as F } from 'fp-ts';
|
|
5
|
-
import { ProposalContentSchema } from '../gov/types-new';
|
|
6
3
|
|
|
7
4
|
const ExecuteParamsSchema = Data.Object({
|
|
8
5
|
govNFT: AssetClassSchema,
|
|
9
6
|
upgradeToken: AssetClassSchema,
|
|
10
7
|
iAssetToken: AssetClassSchema,
|
|
8
|
+
collateralAssetToken: AssetClassSchema,
|
|
11
9
|
stabilityPoolToken: AssetClassSchema,
|
|
10
|
+
cdpCreatorToken: AssetClassSchema,
|
|
11
|
+
cdpToken: AssetClassSchema,
|
|
12
12
|
versionRecordToken: AssetClassSchema,
|
|
13
|
+
iassetValHash: Data.Bytes(),
|
|
13
14
|
cdpValHash: Data.Bytes(),
|
|
14
15
|
sPoolValHash: Data.Bytes(),
|
|
15
16
|
versionRegistryValHash: Data.Bytes(),
|
|
16
17
|
treasuryValHash: Data.Bytes(),
|
|
17
|
-
indyAsset: AssetClassSchema,
|
|
18
18
|
});
|
|
19
19
|
export type ExecuteParams = Data.Static<typeof ExecuteParamsSchema>;
|
|
20
20
|
export const ExecuteParams = ExecuteParamsSchema as unknown as ExecuteParams;
|
|
21
21
|
|
|
22
|
-
const ExecuteDatumSchema = Data.Object({
|
|
23
|
-
id: Data.Integer(),
|
|
24
|
-
content: ProposalContentSchema,
|
|
25
|
-
passedTime: Data.Integer(),
|
|
26
|
-
votingEndTime: Data.Integer(),
|
|
27
|
-
protocolVersion: Data.Integer(),
|
|
28
|
-
/// Value proposed to be withdrawn from the treasury as part of the proposal.
|
|
29
|
-
treasuryWithdrawal: Data.Nullable(TreasuryWithdrawalSchema),
|
|
30
|
-
});
|
|
31
|
-
export type ExecuteDatum = Data.Static<typeof ExecuteDatumSchema>;
|
|
32
|
-
export const ExecuteDatum = ExecuteDatumSchema as unknown as ExecuteDatum;
|
|
33
|
-
|
|
34
|
-
export function serialiseExecuteDatum(d: ExecuteDatum): Datum {
|
|
35
|
-
return Data.to<ExecuteDatum>(d, ExecuteDatum);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function parseExecuteDatum(d: Datum): O.Option<ExecuteDatum> {
|
|
39
|
-
try {
|
|
40
|
-
return O.some(Data.from<ExecuteDatum>(d, ExecuteDatum));
|
|
41
|
-
} catch (_) {
|
|
42
|
-
return O.none;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function parseExecuteDatumOrThrow(d: Datum): ExecuteDatum {
|
|
47
|
-
return F.pipe(
|
|
48
|
-
parseExecuteDatum(d),
|
|
49
|
-
O.match(() => {
|
|
50
|
-
throw new Error('Expected an Execute datum.');
|
|
51
|
-
}, F.identity),
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
22
|
export function castExecuteParams(params: ExecuteParams): Data {
|
|
56
23
|
return Data.castTo(params, ExecuteParams);
|
|
57
24
|
}
|
|
@@ -6,23 +6,33 @@ import {
|
|
|
6
6
|
ord as Ord,
|
|
7
7
|
function as F,
|
|
8
8
|
} from 'fp-ts';
|
|
9
|
-
import { TreasuryWithdrawal, TreasuryWithdrawalItem } from './types';
|
|
10
9
|
import {
|
|
11
10
|
addAssets,
|
|
12
11
|
Assets,
|
|
13
12
|
LucidEvolution,
|
|
14
13
|
OutRef,
|
|
14
|
+
toHex,
|
|
15
15
|
toText,
|
|
16
|
+
UTxO,
|
|
16
17
|
} from '@lucid-evolution/lucid';
|
|
17
|
-
import {
|
|
18
|
+
import { matchSingle } from '../../utils/utils';
|
|
19
|
+
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
|
|
18
20
|
import {
|
|
21
|
+
AddCollateralAsssetContent,
|
|
22
|
+
ProposeAssetContent,
|
|
23
|
+
TreasuryWithdrawal,
|
|
24
|
+
TreasuryWithdrawalItem,
|
|
25
|
+
} from './types-new';
|
|
26
|
+
import { AssetClass, mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
|
|
27
|
+
import {
|
|
28
|
+
CollateralAssetContent,
|
|
29
|
+
CollateralAssetOutput,
|
|
19
30
|
IAssetContent,
|
|
20
31
|
IAssetOutput,
|
|
32
|
+
parseCollateralAssetDatumOrThrow,
|
|
21
33
|
parseIAssetDatumOrThrow,
|
|
22
|
-
} from '../
|
|
23
|
-
import {
|
|
24
|
-
import { matchSingle } from '../../utils/utils';
|
|
25
|
-
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
|
|
34
|
+
} from '../iasset/types';
|
|
35
|
+
import { getAssetClassComparisonStr, ParsedOutput } from '../../types/generic';
|
|
26
36
|
|
|
27
37
|
export function proposalDeposit(
|
|
28
38
|
baseDeposit: bigint,
|
|
@@ -32,100 +42,159 @@ export function proposalDeposit(
|
|
|
32
42
|
}
|
|
33
43
|
|
|
34
44
|
export function createValueFromWithdrawal(w: TreasuryWithdrawal): Assets {
|
|
35
|
-
return A.reduce<TreasuryWithdrawalItem, Assets>({}, (acc,
|
|
36
|
-
addAssets(
|
|
37
|
-
|
|
45
|
+
return A.reduce<TreasuryWithdrawalItem, Assets>({}, (acc, item) =>
|
|
46
|
+
addAssets(
|
|
47
|
+
acc,
|
|
48
|
+
mkAssetsOf(
|
|
49
|
+
{
|
|
50
|
+
currencySymbol: item.currencySymbol,
|
|
51
|
+
tokenName: item.tokenName,
|
|
52
|
+
},
|
|
53
|
+
item.amount,
|
|
54
|
+
),
|
|
55
|
+
),
|
|
56
|
+
)([...w.value]);
|
|
38
57
|
}
|
|
39
58
|
|
|
40
59
|
/**
|
|
41
|
-
*
|
|
42
|
-
* In case there are no iassets, none should be returned.
|
|
60
|
+
* A generic solution for iassets and collateral assets chain.
|
|
43
61
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
async function findRelativeAssetForInsertion<
|
|
63
|
+
T extends Uint8Array<ArrayBufferLike> | AssetClass,
|
|
64
|
+
K,
|
|
65
|
+
>(
|
|
66
|
+
newAsset: T,
|
|
49
67
|
allIAssetOrefs: OutRef[],
|
|
50
68
|
lucid: LucidEvolution,
|
|
51
|
-
|
|
52
|
-
|
|
69
|
+
assetOrd: Ord.Ord<T>,
|
|
70
|
+
getComparisonAsset: (datum: K) => T,
|
|
71
|
+
parseDatum: (utxo: UTxO) => K,
|
|
72
|
+
): Promise<O.Option<ParsedOutput<K>>> {
|
|
73
|
+
const parsedUtxos = await Promise.all(
|
|
53
74
|
allIAssetOrefs.map(async (oref) => {
|
|
54
|
-
const
|
|
75
|
+
const utxo = matchSingle(
|
|
55
76
|
await lucid.utxosByOutRef([oref]),
|
|
56
|
-
(_) => new Error('Expected a single
|
|
77
|
+
(_) => new Error('Expected a single UTXO'),
|
|
57
78
|
);
|
|
58
79
|
|
|
59
|
-
const datum =
|
|
80
|
+
const datum = parseDatum(utxo);
|
|
60
81
|
|
|
61
|
-
return { datum: datum, utxo:
|
|
82
|
+
return { datum: datum, utxo: utxo };
|
|
62
83
|
}),
|
|
63
84
|
);
|
|
64
85
|
|
|
65
86
|
// The iasset just before the new token name based on assets ordering
|
|
66
87
|
return pipe(
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
parsedUtxos,
|
|
89
|
+
// Sort by the asset names
|
|
69
90
|
A.sort(
|
|
70
|
-
Ord.contramap<
|
|
71
|
-
|
|
91
|
+
Ord.contramap<T, ParsedOutput<K>>((a) => getComparisonAsset(a.datum))(
|
|
92
|
+
assetOrd,
|
|
72
93
|
),
|
|
73
94
|
),
|
|
74
95
|
// split head and tail
|
|
75
96
|
A.foldLeft(
|
|
76
97
|
() => O.none,
|
|
77
|
-
(head, rest) =>
|
|
98
|
+
(head, rest) =>
|
|
99
|
+
O.some<[ParsedOutput<K>, ParsedOutput<K>[]]>([head, rest]),
|
|
78
100
|
),
|
|
79
101
|
// find the preceding iasset for the new token name
|
|
80
102
|
O.flatMap(([firstIAsset, rest]) =>
|
|
81
103
|
O.some(
|
|
82
|
-
A.reduce<
|
|
83
|
-
|
|
104
|
+
A.reduce<ParsedOutput<K>, ParsedOutput<K>>(
|
|
105
|
+
firstIAsset,
|
|
106
|
+
(acc, iasset) => {
|
|
107
|
+
const isGreater =
|
|
108
|
+
assetOrd.compare(getComparisonAsset(iasset.datum), newAsset) ===
|
|
109
|
+
-1;
|
|
110
|
+
|
|
111
|
+
// When the new asset is greater, stop searching for the reference.
|
|
112
|
+
return isGreater ? iasset : acc;
|
|
113
|
+
},
|
|
84
114
|
)(rest),
|
|
85
115
|
),
|
|
86
116
|
),
|
|
87
117
|
);
|
|
88
118
|
}
|
|
89
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Find the IAsset that should be a preceding one for the new IAsset token name.
|
|
122
|
+
* In case there are no iassets, none should be returned.
|
|
123
|
+
*/
|
|
124
|
+
export async function findRelativeIAssetForInsertion(
|
|
125
|
+
newIAssetTokenName: Uint8Array<ArrayBufferLike>,
|
|
126
|
+
allIAssetOrefs: OutRef[],
|
|
127
|
+
lucid: LucidEvolution,
|
|
128
|
+
): Promise<O.Option<IAssetOutput>> {
|
|
129
|
+
return findRelativeAssetForInsertion(
|
|
130
|
+
newIAssetTokenName,
|
|
131
|
+
allIAssetOrefs,
|
|
132
|
+
lucid,
|
|
133
|
+
Ord.contramap<string, Uint8Array<ArrayBufferLike>>((x) => toText(toHex(x)))(
|
|
134
|
+
S.Ord,
|
|
135
|
+
),
|
|
136
|
+
(d) => d.assetName,
|
|
137
|
+
(utxo) => parseIAssetDatumOrThrow(getInlineDatumOrThrow(utxo)),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Find collateral asset that should be a preceding one for the new Collateral asset.
|
|
143
|
+
* In case there are no collateral assets, none should be returned.
|
|
144
|
+
*/
|
|
145
|
+
export async function findRelativeCollateralAssetForInsertion(
|
|
146
|
+
newCollateralAsset: AssetClass,
|
|
147
|
+
allCollateralAssetOrefs: OutRef[],
|
|
148
|
+
lucid: LucidEvolution,
|
|
149
|
+
): Promise<O.Option<CollateralAssetOutput>> {
|
|
150
|
+
return findRelativeAssetForInsertion(
|
|
151
|
+
newCollateralAsset,
|
|
152
|
+
allCollateralAssetOrefs,
|
|
153
|
+
lucid,
|
|
154
|
+
Ord.contramap<string, AssetClass>((x) => getAssetClassComparisonStr(x))(
|
|
155
|
+
S.Ord,
|
|
156
|
+
),
|
|
157
|
+
(d) => d.collateralAsset,
|
|
158
|
+
(utxo) => parseCollateralAssetDatumOrThrow(getInlineDatumOrThrow(utxo)),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
type IAssetCreationDatumHelperReturnType = {
|
|
163
|
+
newIAsset: IAssetContent;
|
|
164
|
+
newReferencedIAsset: O.Option<IAssetContent>;
|
|
165
|
+
};
|
|
166
|
+
|
|
90
167
|
export function iassetCreationDatumHelper(
|
|
91
168
|
proposeAssetContent: ProposeAssetContent,
|
|
92
169
|
referencedIAsset: O.Option<IAssetContent>,
|
|
93
|
-
):
|
|
170
|
+
): IAssetCreationDatumHelperReturnType {
|
|
94
171
|
const newContent: IAssetContent = {
|
|
95
172
|
assetName: proposeAssetContent.asset,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
proposeAssetContent.
|
|
104
|
-
|
|
105
|
-
proposeAssetContent.
|
|
106
|
-
redemptionReimbursementPercentage:
|
|
107
|
-
proposeAssetContent.redemptionReimbursementPercentage,
|
|
108
|
-
redemptionProcessingFeePercentage:
|
|
109
|
-
proposeAssetContent.redemptionProcessingFeePercentage,
|
|
110
|
-
interestCollectorPortionPercentage:
|
|
111
|
-
proposeAssetContent.interestCollectorPortionPercentage,
|
|
173
|
+
collateralAssetsCount: 0n,
|
|
174
|
+
debtMintingFeeRatio: proposeAssetContent.debtMintingFeeRatio,
|
|
175
|
+
liquidationProcessingFeeRatio:
|
|
176
|
+
proposeAssetContent.liquidationProcessingFeeRatio,
|
|
177
|
+
stabilityPoolWithdrawalFeeRatio:
|
|
178
|
+
proposeAssetContent.stabilityPoolWithdrawalFeeRatio,
|
|
179
|
+
redemptionReimbursementRatio:
|
|
180
|
+
proposeAssetContent.redemptionReimbursementRatio,
|
|
181
|
+
redemptionProcessingFeeRatio:
|
|
182
|
+
proposeAssetContent.redemptionProcessingFeeRatio,
|
|
112
183
|
firstIAsset: true,
|
|
113
184
|
nextIAsset: null,
|
|
114
185
|
};
|
|
115
186
|
|
|
116
187
|
return F.pipe(
|
|
117
188
|
referencedIAsset,
|
|
118
|
-
O.match<
|
|
119
|
-
IAssetContent,
|
|
120
|
-
{ newIAsset: IAssetContent; newReferencedIAsset: O.Option<IAssetContent> }
|
|
121
|
-
>(
|
|
189
|
+
O.match<IAssetContent, IAssetCreationDatumHelperReturnType>(
|
|
122
190
|
() => ({
|
|
123
191
|
newIAsset: newContent,
|
|
124
192
|
newReferencedIAsset: O.none,
|
|
125
193
|
}),
|
|
126
194
|
(referencedIA) => {
|
|
127
195
|
if (
|
|
128
|
-
toText(proposeAssetContent.asset) <
|
|
196
|
+
toText(toHex(proposeAssetContent.asset)) <
|
|
197
|
+
toText(toHex(referencedIA.assetName))
|
|
129
198
|
) {
|
|
130
199
|
return {
|
|
131
200
|
newIAsset: {
|
|
@@ -155,3 +224,70 @@ export function iassetCreationDatumHelper(
|
|
|
155
224
|
),
|
|
156
225
|
);
|
|
157
226
|
}
|
|
227
|
+
|
|
228
|
+
type CollateralAssetCreationDatumHelperReturnType = {
|
|
229
|
+
newCollateralAsset: CollateralAssetContent;
|
|
230
|
+
newReferencedCollateralAsset: O.Option<CollateralAssetContent>;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export function collateralAssetCreationDatumHelper(
|
|
234
|
+
addAssetContent: AddCollateralAsssetContent,
|
|
235
|
+
referencedCollateralAsset: O.Option<CollateralAssetContent>,
|
|
236
|
+
): CollateralAssetCreationDatumHelperReturnType {
|
|
237
|
+
const newContent: CollateralAssetContent = {
|
|
238
|
+
iasset: addAssetContent.correspondingIAsset,
|
|
239
|
+
collateralAsset: addAssetContent.collateralAsset,
|
|
240
|
+
extraDecimals: addAssetContent.assetExtraDecimals,
|
|
241
|
+
priceInfo: addAssetContent.assetPriceInfo,
|
|
242
|
+
interestOracleNft: addAssetContent.interestOracleNft,
|
|
243
|
+
redemptionRatio: addAssetContent.redemptionRatio,
|
|
244
|
+
maintenanceRatio: addAssetContent.maintenanceRatio,
|
|
245
|
+
liquidationRatio: addAssetContent.liquidationRatio,
|
|
246
|
+
minCollateralAmt: addAssetContent.minCollateralAmt,
|
|
247
|
+
firstCollateralAsset: true,
|
|
248
|
+
nextCollateralAsset: null,
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
return F.pipe(
|
|
252
|
+
referencedCollateralAsset,
|
|
253
|
+
O.match<
|
|
254
|
+
CollateralAssetContent,
|
|
255
|
+
CollateralAssetCreationDatumHelperReturnType
|
|
256
|
+
>(
|
|
257
|
+
() => ({
|
|
258
|
+
newCollateralAsset: newContent,
|
|
259
|
+
newReferencedCollateralAsset: O.none,
|
|
260
|
+
}),
|
|
261
|
+
(referencedCA) => {
|
|
262
|
+
if (
|
|
263
|
+
getAssetClassComparisonStr(addAssetContent.collateralAsset) <
|
|
264
|
+
getAssetClassComparisonStr(referencedCA.collateralAsset)
|
|
265
|
+
) {
|
|
266
|
+
return {
|
|
267
|
+
newCollateralAsset: {
|
|
268
|
+
...newContent,
|
|
269
|
+
firstCollateralAsset: true,
|
|
270
|
+
nextCollateralAsset: referencedCA.collateralAsset,
|
|
271
|
+
},
|
|
272
|
+
newReferencedCollateralAsset: O.some({
|
|
273
|
+
...referencedCA,
|
|
274
|
+
firstCollateralAsset: false,
|
|
275
|
+
}),
|
|
276
|
+
};
|
|
277
|
+
} else {
|
|
278
|
+
return {
|
|
279
|
+
newCollateralAsset: {
|
|
280
|
+
...newContent,
|
|
281
|
+
firstCollateralAsset: false,
|
|
282
|
+
nextCollateralAsset: referencedCA.nextCollateralAsset,
|
|
283
|
+
},
|
|
284
|
+
newReferencedCollateralAsset: O.some({
|
|
285
|
+
...referencedCA,
|
|
286
|
+
nextCollateralAsset: addAssetContent.collateralAsset,
|
|
287
|
+
}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
2
|
import { castGovParams, GovParams } from './types';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
GovParamsSP,
|
|
5
|
+
fromSystemParamsAssetLucid,
|
|
6
|
+
} from '../../types/system-params';
|
|
4
7
|
import { _governanceValidator } from '../../validators/governance-validator';
|
|
5
8
|
|
|
6
9
|
export const mkGovValidator = (params: GovParams): SpendingValidator => {
|
|
7
10
|
return {
|
|
8
|
-
type: '
|
|
11
|
+
type: 'PlutusV3',
|
|
9
12
|
script: applyParamsToScript(_governanceValidator.cborHex, [
|
|
10
13
|
castGovParams(params),
|
|
11
14
|
]),
|
|
@@ -16,18 +19,22 @@ export const mkGovValidatorFromSP = (
|
|
|
16
19
|
params: GovParamsSP,
|
|
17
20
|
): SpendingValidator => {
|
|
18
21
|
return {
|
|
19
|
-
type: '
|
|
22
|
+
type: 'PlutusV3',
|
|
20
23
|
script: applyParamsToScript(_governanceValidator.cborHex, [
|
|
21
24
|
castGovParams({
|
|
22
25
|
gBiasTime: BigInt(params.gBiasTime),
|
|
23
|
-
govNFT:
|
|
24
|
-
pollToken:
|
|
25
|
-
upgradeToken:
|
|
26
|
-
indyAsset:
|
|
27
|
-
versionRecordToken:
|
|
26
|
+
govNFT: fromSystemParamsAssetLucid(params.govNFT),
|
|
27
|
+
pollToken: fromSystemParamsAssetLucid(params.pollToken),
|
|
28
|
+
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
29
|
+
indyAsset: fromSystemParamsAssetLucid(params.indyAsset),
|
|
30
|
+
versionRecordToken: fromSystemParamsAssetLucid(
|
|
31
|
+
params.versionRecordToken,
|
|
32
|
+
),
|
|
33
|
+
iassetSymbol: params.iassetSymbol.unCurrencySymbol,
|
|
34
|
+
iassetValHash: params.iassetValHash,
|
|
28
35
|
pollManagerValHash: params.pollManagerValHash,
|
|
29
|
-
daoIdentityToken:
|
|
30
|
-
iAssetAuthToken:
|
|
36
|
+
daoIdentityToken: fromSystemParamsAssetLucid(params.daoIdentityToken),
|
|
37
|
+
iAssetAuthToken: fromSystemParamsAssetLucid(params.iAssetAuthToken),
|
|
31
38
|
}),
|
|
32
39
|
]),
|
|
33
40
|
};
|