@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
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Data, Datum, Redeemer, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
+
import { AssetClassSchema, OutputReferenceSchema } from '../../types/generic';
|
|
3
|
+
import { OnChainDecimalSchema } from '../../types/on-chain-decimal';
|
|
4
|
+
import { OracleAssetNftSchema } from '../price-oracle/types';
|
|
5
|
+
import { match, P } from 'ts-pattern';
|
|
6
|
+
import { option as O, function as F } from 'fp-ts';
|
|
7
|
+
|
|
8
|
+
const CdpParamsSchema = Data.Object({
|
|
9
|
+
cdp_auth_token: AssetClassSchema,
|
|
10
|
+
cdp_asset_symbol: Data.Bytes(),
|
|
11
|
+
iasset_auth_token: AssetClassSchema,
|
|
12
|
+
stability_pool_auth_token: AssetClassSchema,
|
|
13
|
+
version_record_token: AssetClassSchema,
|
|
14
|
+
upgrade_token: AssetClassSchema,
|
|
15
|
+
collector_val_hash: Data.Bytes(),
|
|
16
|
+
sp_val_hash: Data.Bytes(),
|
|
17
|
+
gov_nft: AssetClassSchema,
|
|
18
|
+
min_collateral_in_lovelace: Data.Integer(),
|
|
19
|
+
partial_redemption_extra_fee_lovelace: Data.Integer(),
|
|
20
|
+
bias_time: Data.Integer(),
|
|
21
|
+
treasury_val_hash: Data.Bytes(),
|
|
22
|
+
});
|
|
23
|
+
export type CdpParams = Data.Static<typeof CdpParamsSchema>;
|
|
24
|
+
const CdpParams = CdpParamsSchema as unknown as CdpParams;
|
|
25
|
+
|
|
26
|
+
export const CDPFeesSchema = Data.Enum([
|
|
27
|
+
Data.Object({
|
|
28
|
+
ActiveCDPInterestTracking: Data.Object({
|
|
29
|
+
lastSettled: Data.Integer(),
|
|
30
|
+
unitaryInterestSnapshot: Data.Integer(),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
Data.Object({
|
|
34
|
+
FrozenCDPAccumulatedFees: Data.Object({
|
|
35
|
+
lovelacesTreasury: Data.Integer(),
|
|
36
|
+
lovelacesIndyStakers: Data.Integer(),
|
|
37
|
+
}),
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export const CDPContentSchema = Data.Object({
|
|
42
|
+
cdpOwner: Data.Nullable(Data.Bytes()),
|
|
43
|
+
iasset: Data.Bytes(),
|
|
44
|
+
mintedAmt: Data.Integer(),
|
|
45
|
+
cdpFees: CDPFeesSchema,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export const IAssetPriceInfoSchema = Data.Enum([
|
|
49
|
+
Data.Object({
|
|
50
|
+
Delisted: Data.Object({ content: OnChainDecimalSchema }),
|
|
51
|
+
}),
|
|
52
|
+
Data.Object({
|
|
53
|
+
Oracle: Data.Object({ content: OracleAssetNftSchema }),
|
|
54
|
+
}),
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
export const IAssetContentSchema = Data.Object({
|
|
58
|
+
/** Use the HEX encoding */
|
|
59
|
+
assetName: Data.Bytes(),
|
|
60
|
+
price: IAssetPriceInfoSchema,
|
|
61
|
+
interestOracleNft: AssetClassSchema,
|
|
62
|
+
redemptionRatio: OnChainDecimalSchema,
|
|
63
|
+
maintenanceRatio: OnChainDecimalSchema,
|
|
64
|
+
liquidationRatio: OnChainDecimalSchema,
|
|
65
|
+
debtMintingFeePercentage: OnChainDecimalSchema,
|
|
66
|
+
liquidationProcessingFeePercentage: OnChainDecimalSchema,
|
|
67
|
+
stabilityPoolWithdrawalFeePercentage: OnChainDecimalSchema,
|
|
68
|
+
redemptionReimbursementPercentage: OnChainDecimalSchema,
|
|
69
|
+
redemptionProcessingFeePercentage: OnChainDecimalSchema,
|
|
70
|
+
interestCollectorPortionPercentage: OnChainDecimalSchema,
|
|
71
|
+
firstIAsset: Data.Boolean(),
|
|
72
|
+
nextIAsset: Data.Nullable(Data.Bytes()),
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export const CDPDatumSchema = Data.Enum([
|
|
76
|
+
Data.Object({ CDP: Data.Object({ content: CDPContentSchema }) }),
|
|
77
|
+
Data.Object({ IAsset: Data.Object({ content: IAssetContentSchema }) }),
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
export type CDPFees = Data.Static<typeof CDPFeesSchema>;
|
|
81
|
+
export type CDPDatum = Data.Static<typeof CDPDatumSchema>;
|
|
82
|
+
const CDPDatum = CDPDatumSchema as unknown as CDPDatum;
|
|
83
|
+
|
|
84
|
+
export type CDPContent = Data.Static<typeof CDPContentSchema>;
|
|
85
|
+
const CDPContent = CDPContentSchema as unknown as CDPContent;
|
|
86
|
+
export type IAssetContent = Data.Static<typeof IAssetContentSchema>;
|
|
87
|
+
const IAssetContent = IAssetContentSchema as unknown as IAssetContent;
|
|
88
|
+
|
|
89
|
+
const CDPRedeemerSchema = Data.Enum([
|
|
90
|
+
Data.Object({
|
|
91
|
+
AdjustCdp: Data.Object({
|
|
92
|
+
currentTime: Data.Integer(),
|
|
93
|
+
mintedAmtChange: Data.Integer(),
|
|
94
|
+
collateralAmtChange: Data.Integer(),
|
|
95
|
+
}),
|
|
96
|
+
}),
|
|
97
|
+
Data.Object({ CloseCdp: Data.Object({ currentTime: Data.Integer() }) }),
|
|
98
|
+
Data.Object({ RedeemCdp: Data.Object({ currentTime: Data.Integer() }) }),
|
|
99
|
+
Data.Object({ FreezeCdp: Data.Object({ currentTime: Data.Integer() }) }),
|
|
100
|
+
Data.Literal('MergeCdps'),
|
|
101
|
+
Data.Object({
|
|
102
|
+
MergeAuxiliary: Data.Object({ mainMergeUtxo: OutputReferenceSchema }),
|
|
103
|
+
}),
|
|
104
|
+
Data.Literal('Liquidate'),
|
|
105
|
+
Data.Literal('UpdateOrInsertAsset'),
|
|
106
|
+
Data.Literal('UpgradeVersion'),
|
|
107
|
+
]);
|
|
108
|
+
export type CDPRedeemer = Data.Static<typeof CDPRedeemerSchema>;
|
|
109
|
+
const CDPRedeemer = CDPRedeemerSchema as unknown as CDPRedeemer;
|
|
110
|
+
|
|
111
|
+
export function serialiseCdpRedeemer(r: CDPRedeemer): Redeemer {
|
|
112
|
+
return Data.to<CDPRedeemer>(r, CDPRedeemer);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function parseCdpDatum(datum: Datum): O.Option<CDPContent> {
|
|
116
|
+
return match(Data.from<CDPDatum>(datum, CDPDatum))
|
|
117
|
+
.with({ CDP: { content: P.select() } }, (res) => O.some(res))
|
|
118
|
+
.otherwise(() => O.none);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function parseCdpDatumOrThrow(datum: Datum): CDPContent {
|
|
122
|
+
return F.pipe(
|
|
123
|
+
parseCdpDatum(datum),
|
|
124
|
+
O.match(() => {
|
|
125
|
+
throw new Error('Expected a CDP datum.');
|
|
126
|
+
}, F.identity),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function serialiseCdpDatum(cdpDatum: CDPContent): Datum {
|
|
131
|
+
return Data.to<CDPDatum>({ CDP: { content: cdpDatum } }, CDPDatum);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function parseIAssetDatum(datum: Datum): O.Option<IAssetContent> {
|
|
135
|
+
try {
|
|
136
|
+
return match(Data.from<CDPDatum>(datum, CDPDatum))
|
|
137
|
+
.with({ IAsset: { content: P.select() } }, (res) => O.some(res))
|
|
138
|
+
.otherwise(() => O.none);
|
|
139
|
+
} catch (_) {
|
|
140
|
+
return O.none;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function parseIAssetDatumOrThrow(datum: Datum): IAssetContent {
|
|
145
|
+
return F.pipe(
|
|
146
|
+
parseIAssetDatum(datum),
|
|
147
|
+
O.match(() => {
|
|
148
|
+
throw new Error('Expected an IAsset datum.');
|
|
149
|
+
}, F.identity),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function serialiseIAssetDatum(iassetDatum: IAssetContent): Datum {
|
|
154
|
+
return Data.to<CDPDatum>({ IAsset: { content: iassetDatum } }, CDPDatum);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function castCdpParams(params: CdpParams): Data {
|
|
158
|
+
return Data.castTo(params, CdpParams);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type IAssetOutput = { datum: IAssetContent; utxo: UTxO };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
+
import { castCDPCreatorParams, CDPCreatorParams } from './types';
|
|
3
|
+
import {
|
|
4
|
+
CDPCreatorParamsSP,
|
|
5
|
+
fromSystemParamsAsset,
|
|
6
|
+
} from '../../types/system-params';
|
|
7
|
+
import { _cdpCreatorValidator } from '../../validators/cdp-creator-validator';
|
|
8
|
+
|
|
9
|
+
export const mkCDPCreatorValidator = (
|
|
10
|
+
params: CDPCreatorParams,
|
|
11
|
+
): SpendingValidator => {
|
|
12
|
+
return {
|
|
13
|
+
type: 'PlutusV2',
|
|
14
|
+
script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
|
|
15
|
+
castCDPCreatorParams(params),
|
|
16
|
+
]),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const mkCDPCreatorValidatorFromSP = (
|
|
21
|
+
params: CDPCreatorParamsSP,
|
|
22
|
+
): SpendingValidator => {
|
|
23
|
+
return {
|
|
24
|
+
type: 'PlutusV2',
|
|
25
|
+
script: applyParamsToScript(_cdpCreatorValidator.cborHex, [
|
|
26
|
+
castCDPCreatorParams({
|
|
27
|
+
cdpCreatorNft: fromSystemParamsAsset(params.cdpCreatorNft),
|
|
28
|
+
cdpAssetCs: params.cdpAssetCs.unCurrencySymbol,
|
|
29
|
+
cdpAuthTk: fromSystemParamsAsset(params.cdpAuthTk),
|
|
30
|
+
iAssetAuthTk: fromSystemParamsAsset(params.iAssetAuthTk),
|
|
31
|
+
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
32
|
+
cdpScriptHash: params.cdpScriptHash,
|
|
33
|
+
collectorValHash: params.collectorValHash,
|
|
34
|
+
minCollateralInLovelace: BigInt(params.minCollateralInLovelace),
|
|
35
|
+
biasTime: BigInt(params.biasTime),
|
|
36
|
+
}),
|
|
37
|
+
]),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Data, Datum } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema } from '
|
|
1
|
+
import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
+
import { AssetClassSchema } from '../../types/generic';
|
|
3
3
|
|
|
4
4
|
const CDPCreatorParamsSchema = Data.Object({
|
|
5
5
|
cdpCreatorNft: AssetClassSchema,
|
|
@@ -37,8 +37,10 @@ export type CDPCreatorRedeemer = Data.Static<typeof CDPCreatorRedeemerSchema>;
|
|
|
37
37
|
export const CDPCreatorRedeemer =
|
|
38
38
|
CDPCreatorRedeemerSchema as unknown as CDPCreatorRedeemer;
|
|
39
39
|
|
|
40
|
-
export function
|
|
41
|
-
|
|
40
|
+
export function serialiseCDPCreatorRedeemer(
|
|
41
|
+
params: CDPCreatorRedeemer,
|
|
42
|
+
): Redeemer {
|
|
43
|
+
return Data.to<CDPCreatorRedeemer>(params, CDPCreatorRedeemer);
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export function serialiseCDPCreatorDatum(): Datum {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyParamsToScript,
|
|
3
|
+
Constr,
|
|
4
|
+
fromText,
|
|
5
|
+
SpendingValidator,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
import { CollectorParamsSP } from '../../types/system-params';
|
|
8
|
+
import { _collectorValidator } from '../../validators/collector-validator';
|
|
9
|
+
|
|
10
|
+
export const mkCollectorValidatorFromSP = (
|
|
11
|
+
params: CollectorParamsSP,
|
|
12
|
+
): SpendingValidator => {
|
|
13
|
+
return {
|
|
14
|
+
type: 'PlutusV2',
|
|
15
|
+
script: applyParamsToScript(_collectorValidator.cborHex, [
|
|
16
|
+
new Constr(0, [
|
|
17
|
+
new Constr(0, [
|
|
18
|
+
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
19
|
+
fromText(params.stakingManagerNFT[1].unTokenName),
|
|
20
|
+
]),
|
|
21
|
+
new Constr(0, [
|
|
22
|
+
params.stakingToken[0].unCurrencySymbol,
|
|
23
|
+
fromText(params.stakingToken[1].unTokenName),
|
|
24
|
+
]),
|
|
25
|
+
new Constr(0, [
|
|
26
|
+
params.versionRecordToken[0].unCurrencySymbol,
|
|
27
|
+
fromText(params.versionRecordToken[1].unTokenName),
|
|
28
|
+
]),
|
|
29
|
+
]),
|
|
30
|
+
]),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Constr,
|
|
3
|
+
Data,
|
|
4
|
+
LucidEvolution,
|
|
5
|
+
OutRef,
|
|
6
|
+
TxBuilder,
|
|
7
|
+
UTxO,
|
|
8
|
+
} from '@lucid-evolution/lucid';
|
|
9
|
+
import {
|
|
10
|
+
fromSystemParamsScriptRef,
|
|
11
|
+
SystemParams,
|
|
12
|
+
} from '../../types/system-params';
|
|
13
|
+
import { matchSingle } from '../../utils/utils';
|
|
14
|
+
|
|
15
|
+
export async function collectorFeeTx(
|
|
16
|
+
fee: bigint,
|
|
17
|
+
lucid: LucidEvolution,
|
|
18
|
+
params: SystemParams,
|
|
19
|
+
tx: TxBuilder,
|
|
20
|
+
collectorOref: OutRef,
|
|
21
|
+
): Promise<void> {
|
|
22
|
+
const collectorUtxo: UTxO = matchSingle(
|
|
23
|
+
await lucid.utxosByOutRef([collectorOref]),
|
|
24
|
+
(_) => new Error('Expected a single collector UTXO'),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const collectorRefScriptUtxo = matchSingle(
|
|
28
|
+
await lucid.utxosByOutRef([
|
|
29
|
+
fromSystemParamsScriptRef(params.scriptReferences.collectorValidatorRef),
|
|
30
|
+
]),
|
|
31
|
+
(_) => new Error('Expected a single collector Ref Script UTXO'),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
tx.collectFrom([collectorUtxo], Data.to(new Constr(0, [])))
|
|
35
|
+
.pay.ToContract(
|
|
36
|
+
collectorUtxo.address,
|
|
37
|
+
{ kind: 'inline', value: Data.to(new Constr(0, [])) },
|
|
38
|
+
{
|
|
39
|
+
...collectorUtxo.assets,
|
|
40
|
+
lovelace: collectorUtxo.assets.lovelace + fee,
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
.readFrom([collectorRefScriptUtxo]);
|
|
44
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyParamsToScript,
|
|
3
|
+
applySingleCborEncoding,
|
|
4
|
+
SpendingValidator,
|
|
5
|
+
} from '@lucid-evolution/lucid';
|
|
6
|
+
import { castExecuteParams, ExecuteParams } from './types';
|
|
7
|
+
import {
|
|
8
|
+
ExecuteParamsSP,
|
|
9
|
+
fromSystemParamsAsset,
|
|
10
|
+
} from '../../types/system-params';
|
|
11
|
+
import { _executeValidator } from '../../validators/execute-validator';
|
|
12
|
+
|
|
13
|
+
export const mkExecuteValidator = (
|
|
14
|
+
params: ExecuteParams,
|
|
15
|
+
): SpendingValidator => {
|
|
16
|
+
return {
|
|
17
|
+
type: 'PlutusV2',
|
|
18
|
+
script: applySingleCborEncoding(
|
|
19
|
+
applyParamsToScript(_executeValidator.cborHex, [
|
|
20
|
+
castExecuteParams(params),
|
|
21
|
+
]),
|
|
22
|
+
),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const mkExecuteValidatorFromSP = (
|
|
27
|
+
params: ExecuteParamsSP,
|
|
28
|
+
): SpendingValidator => {
|
|
29
|
+
return {
|
|
30
|
+
type: 'PlutusV2',
|
|
31
|
+
script: applySingleCborEncoding(
|
|
32
|
+
applyParamsToScript(_executeValidator.cborHex, [
|
|
33
|
+
castExecuteParams({
|
|
34
|
+
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
35
|
+
upgradeToken: fromSystemParamsAsset(params.upgradeToken),
|
|
36
|
+
iAssetToken: fromSystemParamsAsset(params.iAssetToken),
|
|
37
|
+
stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
|
|
38
|
+
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
39
|
+
cdpValHash: params.cdpValHash,
|
|
40
|
+
sPoolValHash: params.sPoolValHash,
|
|
41
|
+
versionRegistryValHash: params.versionRegistryValHash,
|
|
42
|
+
treasuryValHash: params.treasuryValHash,
|
|
43
|
+
indyAsset: fromSystemParamsAsset(params.indyAsset),
|
|
44
|
+
} as ExecuteParams),
|
|
45
|
+
]),
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Data, Datum } from '@lucid-evolution/lucid';
|
|
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
|
+
|
|
7
|
+
const ExecuteParamsSchema = Data.Object({
|
|
8
|
+
govNFT: AssetClassSchema,
|
|
9
|
+
upgradeToken: AssetClassSchema,
|
|
10
|
+
iAssetToken: AssetClassSchema,
|
|
11
|
+
stabilityPoolToken: AssetClassSchema,
|
|
12
|
+
versionRecordToken: AssetClassSchema,
|
|
13
|
+
cdpValHash: Data.Bytes(),
|
|
14
|
+
sPoolValHash: Data.Bytes(),
|
|
15
|
+
versionRegistryValHash: Data.Bytes(),
|
|
16
|
+
treasuryValHash: Data.Bytes(),
|
|
17
|
+
indyAsset: AssetClassSchema,
|
|
18
|
+
});
|
|
19
|
+
export type ExecuteParams = Data.Static<typeof ExecuteParamsSchema>;
|
|
20
|
+
export const ExecuteParams = ExecuteParamsSchema as unknown as ExecuteParams;
|
|
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
|
+
export function castExecuteParams(params: ExecuteParams): Data {
|
|
56
|
+
return Data.castTo(params, ExecuteParams);
|
|
57
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { pipe } from 'fp-ts/lib/function';
|
|
2
|
+
import {
|
|
3
|
+
array as A,
|
|
4
|
+
option as O,
|
|
5
|
+
string as S,
|
|
6
|
+
ord as Ord,
|
|
7
|
+
function as F,
|
|
8
|
+
} from 'fp-ts';
|
|
9
|
+
import { TreasuryWithdrawal, TreasuryWithdrawalItem } from './types';
|
|
10
|
+
import {
|
|
11
|
+
addAssets,
|
|
12
|
+
Assets,
|
|
13
|
+
LucidEvolution,
|
|
14
|
+
OutRef,
|
|
15
|
+
toText,
|
|
16
|
+
} from '@lucid-evolution/lucid';
|
|
17
|
+
import { mkAssetsOf } from '../../utils/value-helpers';
|
|
18
|
+
import {
|
|
19
|
+
IAssetContent,
|
|
20
|
+
IAssetOutput,
|
|
21
|
+
parseIAssetDatumOrThrow,
|
|
22
|
+
} from '../cdp/types';
|
|
23
|
+
import { ProposeAssetContent } from './types-new';
|
|
24
|
+
import { matchSingle } from '../../utils/utils';
|
|
25
|
+
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
|
|
26
|
+
|
|
27
|
+
export function proposalDeposit(
|
|
28
|
+
baseDeposit: bigint,
|
|
29
|
+
activeProposals: bigint,
|
|
30
|
+
): bigint {
|
|
31
|
+
return baseDeposit * 2n ** activeProposals;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createValueFromWithdrawal(w: TreasuryWithdrawal): Assets {
|
|
35
|
+
return A.reduce<TreasuryWithdrawalItem, Assets>({}, (acc, [cs, tk, amt]) =>
|
|
36
|
+
addAssets(acc, mkAssetsOf({ currencySymbol: cs, tokenName: tk }, amt)),
|
|
37
|
+
)(w.value);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Find the IAsset that should be a preceding one for the new IAsset token name.
|
|
42
|
+
* In case there are no iassets, none should be returned.
|
|
43
|
+
*/
|
|
44
|
+
export async function findRelativeIAssetForInsertion(
|
|
45
|
+
/**
|
|
46
|
+
* UFT encoded
|
|
47
|
+
*/
|
|
48
|
+
newIAssetTokenName: string,
|
|
49
|
+
allIAssetOrefs: OutRef[],
|
|
50
|
+
lucid: LucidEvolution,
|
|
51
|
+
): Promise<O.Option<IAssetOutput>> {
|
|
52
|
+
const iassetUtxos = await Promise.all(
|
|
53
|
+
allIAssetOrefs.map(async (oref) => {
|
|
54
|
+
const iassetUtxo = matchSingle(
|
|
55
|
+
await lucid.utxosByOutRef([oref]),
|
|
56
|
+
(_) => new Error('Expected a single IAsset UTXO'),
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const datum = parseIAssetDatumOrThrow(getInlineDatumOrThrow(iassetUtxo));
|
|
60
|
+
|
|
61
|
+
return { datum: datum, utxo: iassetUtxo };
|
|
62
|
+
}),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
// The iasset just before the new token name based on assets ordering
|
|
66
|
+
return pipe(
|
|
67
|
+
// Sort the asset names
|
|
68
|
+
iassetUtxos,
|
|
69
|
+
A.sort(
|
|
70
|
+
Ord.contramap<string, IAssetOutput>((x) => toText(x.datum.assetName))(
|
|
71
|
+
S.Ord,
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
// split head and tail
|
|
75
|
+
A.foldLeft(
|
|
76
|
+
() => O.none,
|
|
77
|
+
(head, rest) => O.some<[IAssetOutput, IAssetOutput[]]>([head, rest]),
|
|
78
|
+
),
|
|
79
|
+
// find the preceding iasset for the new token name
|
|
80
|
+
O.flatMap(([firstIAsset, rest]) =>
|
|
81
|
+
O.some(
|
|
82
|
+
A.reduce<IAssetOutput, IAssetOutput>(firstIAsset, (acc, iasset) =>
|
|
83
|
+
toText(iasset.datum.assetName) < newIAssetTokenName ? iasset : acc,
|
|
84
|
+
)(rest),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function iassetCreationDatumHelper(
|
|
91
|
+
proposeAssetContent: ProposeAssetContent,
|
|
92
|
+
referencedIAsset: O.Option<IAssetContent>,
|
|
93
|
+
): { newIAsset: IAssetContent; newReferencedIAsset: O.Option<IAssetContent> } {
|
|
94
|
+
const newContent: IAssetContent = {
|
|
95
|
+
assetName: proposeAssetContent.asset,
|
|
96
|
+
price: { Oracle: { content: proposeAssetContent.priceOracleNft } },
|
|
97
|
+
interestOracleNft: proposeAssetContent.interestOracleNft,
|
|
98
|
+
redemptionRatio: proposeAssetContent.redemptionRatioPercentage,
|
|
99
|
+
maintenanceRatio: proposeAssetContent.maintenanceRatioPercentage,
|
|
100
|
+
liquidationRatio: proposeAssetContent.liquidationRatioPercentage,
|
|
101
|
+
debtMintingFeePercentage: proposeAssetContent.debtMintingFeePercentage,
|
|
102
|
+
liquidationProcessingFeePercentage:
|
|
103
|
+
proposeAssetContent.liquidationProcessingFeePercentage,
|
|
104
|
+
stabilityPoolWithdrawalFeePercentage:
|
|
105
|
+
proposeAssetContent.stabilityPoolWithdrawalFeePercentage,
|
|
106
|
+
redemptionReimbursementPercentage:
|
|
107
|
+
proposeAssetContent.redemptionReimbursementPercentage,
|
|
108
|
+
redemptionProcessingFeePercentage:
|
|
109
|
+
proposeAssetContent.redemptionProcessingFeePercentage,
|
|
110
|
+
interestCollectorPortionPercentage:
|
|
111
|
+
proposeAssetContent.interestCollectorPortionPercentage,
|
|
112
|
+
firstIAsset: true,
|
|
113
|
+
nextIAsset: null,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return F.pipe(
|
|
117
|
+
referencedIAsset,
|
|
118
|
+
O.match<
|
|
119
|
+
IAssetContent,
|
|
120
|
+
{ newIAsset: IAssetContent; newReferencedIAsset: O.Option<IAssetContent> }
|
|
121
|
+
>(
|
|
122
|
+
() => ({
|
|
123
|
+
newIAsset: newContent,
|
|
124
|
+
newReferencedIAsset: O.none,
|
|
125
|
+
}),
|
|
126
|
+
(referencedIA) => {
|
|
127
|
+
if (
|
|
128
|
+
toText(proposeAssetContent.asset) < toText(referencedIA.assetName)
|
|
129
|
+
) {
|
|
130
|
+
return {
|
|
131
|
+
newIAsset: {
|
|
132
|
+
...newContent,
|
|
133
|
+
firstIAsset: true,
|
|
134
|
+
nextIAsset: referencedIA.assetName,
|
|
135
|
+
},
|
|
136
|
+
newReferencedIAsset: O.some({
|
|
137
|
+
...referencedIA,
|
|
138
|
+
firstIAsset: false,
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
141
|
+
} else {
|
|
142
|
+
return {
|
|
143
|
+
newIAsset: {
|
|
144
|
+
...newContent,
|
|
145
|
+
firstIAsset: false,
|
|
146
|
+
nextIAsset: referencedIA.nextIAsset,
|
|
147
|
+
},
|
|
148
|
+
newReferencedIAsset: O.some({
|
|
149
|
+
...referencedIA,
|
|
150
|
+
nextIAsset: proposeAssetContent.asset,
|
|
151
|
+
}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
),
|
|
156
|
+
);
|
|
157
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
+
import { castGovParams, GovParams } from './types';
|
|
3
|
+
import { GovParamsSP, fromSystemParamsAsset } from '../../types/system-params';
|
|
4
|
+
import { _governanceValidator } from '../../validators/governance-validator';
|
|
5
|
+
|
|
6
|
+
export const mkGovValidator = (params: GovParams): SpendingValidator => {
|
|
7
|
+
return {
|
|
8
|
+
type: 'PlutusV2',
|
|
9
|
+
script: applyParamsToScript(_governanceValidator.cborHex, [
|
|
10
|
+
castGovParams(params),
|
|
11
|
+
]),
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const mkGovValidatorFromSP = (
|
|
16
|
+
params: GovParamsSP,
|
|
17
|
+
): SpendingValidator => {
|
|
18
|
+
return {
|
|
19
|
+
type: 'PlutusV2',
|
|
20
|
+
script: applyParamsToScript(_governanceValidator.cborHex, [
|
|
21
|
+
castGovParams({
|
|
22
|
+
gBiasTime: BigInt(params.gBiasTime),
|
|
23
|
+
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
24
|
+
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
25
|
+
upgradeToken: fromSystemParamsAsset(params.upgradeToken),
|
|
26
|
+
indyAsset: fromSystemParamsAsset(params.indyAsset),
|
|
27
|
+
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
28
|
+
pollManagerValHash: params.pollManagerValHash,
|
|
29
|
+
daoIdentityToken: fromSystemParamsAsset(params.daoIdentityToken),
|
|
30
|
+
iAssetAuthToken: fromSystemParamsAsset(params.iAssetAuthToken),
|
|
31
|
+
}),
|
|
32
|
+
]),
|
|
33
|
+
};
|
|
34
|
+
};
|