@indigo-labs/indigo-sdk 0.1.21 → 0.1.23
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 +3 -8
- package/.github/workflows/test.yml +44 -0
- package/dist/index.d.mts +670 -1291
- package/dist/index.d.ts +670 -1291
- package/dist/index.js +2240 -4669
- package/dist/index.mjs +2221 -4618
- package/eslint.config.mjs +1 -7
- package/package.json +4 -9
- package/src/contracts/cdp.ts +746 -0
- package/src/contracts/collector.ts +98 -0
- package/src/contracts/gov.ts +1 -0
- package/src/contracts/interest-oracle.ts +149 -0
- package/src/contracts/{lrp/transactions.ts → lrp.ts} +14 -14
- package/src/contracts/{one-shot/transactions.ts → one-shot.ts} +3 -3
- package/src/contracts/stability-pool.ts +690 -0
- package/src/contracts/staking.ts +348 -0
- package/src/contracts/treasury.ts +112 -0
- package/src/helpers/asset-helpers.ts +63 -0
- package/src/{utils → helpers}/helper-txs.ts +0 -1
- package/src/{utils/utils.ts → helpers/helpers.ts} +10 -0
- package/src/{contracts/interest-oracle/helpers.ts → helpers/interest-oracle.ts} +9 -37
- package/src/{contracts/stability-pool/helpers.ts → helpers/stability-pool-helpers.ts} +6 -110
- package/src/helpers/staking-helpers.ts +94 -0
- package/src/helpers/time-helpers.ts +4 -0
- package/src/{utils → helpers}/value-helpers.ts +0 -10
- package/src/index.ts +33 -38
- package/src/{validators → scripts}/cdp-creator-validator.ts +50 -4
- package/src/{validators → scripts}/cdp-validator.ts +5 -3
- package/src/{validators → scripts}/collector-validator.ts +3 -2
- package/src/scripts/execute-validator.ts +52 -0
- package/src/{validators/governance-validator.ts → scripts/gov-validator.ts} +40 -3
- package/src/{validators → scripts}/interest-oracle-validator.ts +20 -4
- package/src/scripts/lrp-validator.ts +40 -0
- package/src/{contracts/one-shot/scripts.ts → scripts/one-shot-policy.ts} +1 -1
- package/src/scripts/poll-manager-validator.ts +52 -0
- package/src/{validators → scripts}/poll-shard-validator.ts +43 -3
- package/src/{contracts/price-oracle/scripts.ts → scripts/price-oracle-validator.ts} +4 -1
- package/src/{validators → scripts}/stability-pool-validator.ts +57 -4
- package/src/{validators → scripts}/staking-validator.ts +3 -2
- package/src/{validators → scripts}/treasury-validator.ts +3 -2
- package/src/{validators → scripts}/version-record-policy.ts +23 -4
- package/src/{validators/execute-validator.ts → scripts/version-registry.ts} +11 -3
- package/src/types/generic.ts +60 -78
- package/src/{contracts/cdp-creator/types.ts → types/indigo/cdp-creator.ts} +4 -6
- package/src/types/indigo/cdp.ts +88 -0
- package/src/types/indigo/execute.ts +21 -0
- package/src/types/indigo/gov.ts +51 -0
- package/src/{contracts/interest-oracle/types.ts → types/indigo/interest-oracle.ts} +1 -1
- package/src/{contracts/lrp/types.ts → types/indigo/lrp.ts} +2 -2
- package/src/types/indigo/poll-manager.ts +21 -0
- package/src/types/indigo/poll-shard.ts +16 -0
- package/src/{contracts/price-oracle/types.ts → types/indigo/price-oracle.ts} +4 -16
- package/src/types/indigo/stability-pool.ts +233 -0
- package/src/types/indigo/staking.ts +99 -0
- package/src/{contracts/version-registry/types.ts → types/indigo/version-record.ts} +1 -1
- package/src/types/on-chain-decimal.ts +0 -22
- package/src/types/system-params.ts +11 -22
- package/tests/datums.test.ts +108 -125
- package/tests/endpoints/initialize.ts +338 -240
- package/tests/hash-checks.test.ts +21 -26
- package/tests/indigo-test-helpers.ts +55 -1
- package/tests/initialize.test.ts +5 -10
- package/tests/interest-calculations.test.ts +18 -18
- package/tests/interest-oracle.test.ts +18 -20
- package/tests/lrp.test.ts +65 -191
- package/tests/queries/governance-queries.ts +16 -19
- package/tests/queries/iasset-queries.ts +23 -46
- package/tests/queries/interest-oracle-queries.ts +6 -3
- package/tests/queries/lrp-queries.ts +2 -2
- package/tests/queries/price-oracle-queries.ts +22 -5
- package/tests/queries/stability-pool-queries.ts +8 -10
- package/tests/queries/staking-queries.ts +19 -28
- package/tests/stability-pool.test.ts +71 -186
- package/tests/staking.test.ts +23 -30
- package/tests/test-helpers.ts +2 -11
- package/tsconfig.json +1 -3
- package/vitest.config.ts +1 -1
- package/src/contracts/cdp/helpers.ts +0 -167
- package/src/contracts/cdp/scripts.ts +0 -33
- package/src/contracts/cdp/transactions.ts +0 -1310
- package/src/contracts/cdp/types.ts +0 -161
- package/src/contracts/cdp-creator/scripts.ts +0 -39
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -44
- package/src/contracts/execute/scripts.ts +0 -48
- package/src/contracts/execute/types.ts +0 -57
- package/src/contracts/gov/helpers.ts +0 -157
- package/src/contracts/gov/scripts.ts +0 -34
- package/src/contracts/gov/transactions.ts +0 -1224
- package/src/contracts/gov/types-new.ts +0 -115
- package/src/contracts/gov/types.ts +0 -89
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -149
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/poll/helpers.ts +0 -55
- package/src/contracts/poll/scripts.ts +0 -72
- package/src/contracts/poll/types-poll-manager.ts +0 -38
- package/src/contracts/poll/types-poll-shard.ts +0 -38
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/price-oracle/transactions.ts +0 -112
- package/src/contracts/stability-pool/scripts.ts +0 -46
- package/src/contracts/stability-pool/transactions.ts +0 -660
- package/src/contracts/stability-pool/types-new.ts +0 -208
- package/src/contracts/stability-pool/types.ts +0 -42
- package/src/contracts/staking/helpers.ts +0 -116
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -268
- package/src/contracts/staking/types-new.ts +0 -81
- package/src/contracts/staking/types.ts +0 -41
- package/src/contracts/treasury/scripts.ts +0 -37
- package/src/contracts/treasury/transactions.ts +0 -44
- package/src/contracts/treasury/types.ts +0 -55
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -19
- package/src/contracts/vesting/helpers.ts +0 -267
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/utils/bigint-utils.ts +0 -7
- package/src/utils/time-helpers.ts +0 -4
- package/src/validators/lrp-validator.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1565
- package/tests/gov.test.ts +0 -1874
- package/tests/mock/assets-mock.ts +0 -59
- package/tests/queries/cdp-queries.ts +0 -144
- package/tests/queries/collector-queries.ts +0 -26
- package/tests/queries/execute-queries.ts +0 -46
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/treasury-queries.ts +0 -19
- package/tests/utils/asserts.ts +0 -13
- package/tests/utils/index.ts +0 -50
- /package/src/{utils → helpers}/indigo-helpers.ts +0 -0
- /package/src/{utils → helpers}/lucid-utils.ts +0 -0
- /package/src/{contracts/price-oracle/helpers.ts → helpers/price-oracle-helpers.ts} +0 -0
- /package/src/{contracts/one-shot/types.ts → types/one-shot.ts} +0 -0
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Core as EvoCore } from '@evolution-sdk/evolution';
|
|
2
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
3
|
-
import { OracleAssetNftSchema } from '../price-oracle/types';
|
|
4
|
-
import { AssetClassSchema } from '../../types/generic';
|
|
5
|
-
import { OnChainDecimalSchema } from '../../types/on-chain-decimal';
|
|
6
|
-
import { IAssetPriceInfoSchema } from '../cdp/types';
|
|
7
|
-
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
8
|
-
|
|
9
|
-
export const ProtocolParamsSchema = Data.Object({
|
|
10
|
-
proposalDeposit: Data.Integer(),
|
|
11
|
-
votingPeriod: Data.Integer(),
|
|
12
|
-
effectiveDelay: Data.Integer(),
|
|
13
|
-
expirationPeriod: Data.Integer(),
|
|
14
|
-
collateralFeePercentage: OnChainDecimalSchema,
|
|
15
|
-
proposingPeriod: Data.Integer(),
|
|
16
|
-
/// Total numer of shards used for voting.
|
|
17
|
-
totalShards: Data.Integer(),
|
|
18
|
-
/// The minimum number of votes (yes + no votes) for a proposal to be possible to pass.
|
|
19
|
-
minimumQuorum: Data.Integer(),
|
|
20
|
-
/// Maximum amount of lovelaces that can be spent at once from the treasury.
|
|
21
|
-
maxTreasuryLovelaceSpend: Data.Integer(),
|
|
22
|
-
/// Maximum amount of INDY that can be spent at once from the treasury.
|
|
23
|
-
maxTreasuryIndySpend: Data.Integer(),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export type ProtocolParams = Data.Static<typeof ProtocolParamsSchema>;
|
|
27
|
-
export const ProtocolParams = ProtocolParamsSchema as unknown as ProtocolParams;
|
|
28
|
-
|
|
29
|
-
const ProposeAssetContentSchema = Data.Object({
|
|
30
|
-
asset: Data.Bytes(),
|
|
31
|
-
priceOracleNft: OracleAssetNftSchema,
|
|
32
|
-
interestOracleNft: AssetClassSchema,
|
|
33
|
-
redemptionRatioPercentage: OnChainDecimalSchema,
|
|
34
|
-
maintenanceRatioPercentage: OnChainDecimalSchema,
|
|
35
|
-
liquidationRatioPercentage: OnChainDecimalSchema,
|
|
36
|
-
debtMintingFeePercentage: OnChainDecimalSchema,
|
|
37
|
-
liquidationProcessingFeePercentage: OnChainDecimalSchema,
|
|
38
|
-
stabilityPoolWithdrawalFeePercentage: OnChainDecimalSchema,
|
|
39
|
-
redemptionReimbursementPercentage: OnChainDecimalSchema,
|
|
40
|
-
redemptionProcessingFeePercentage: OnChainDecimalSchema,
|
|
41
|
-
interestCollectorPortionPercentage: OnChainDecimalSchema,
|
|
42
|
-
});
|
|
43
|
-
export type ProposeAssetContent = Data.Static<typeof ProposeAssetContentSchema>;
|
|
44
|
-
|
|
45
|
-
export const ProposalContentSchema = Data.Enum([
|
|
46
|
-
Data.Object({
|
|
47
|
-
ProposeAsset: ProposeAssetContentSchema,
|
|
48
|
-
}),
|
|
49
|
-
Data.Object({
|
|
50
|
-
ModifyAsset: Data.Object({
|
|
51
|
-
asset: Data.Bytes(),
|
|
52
|
-
newAssetPriceInfo: IAssetPriceInfoSchema,
|
|
53
|
-
newInterestOracleNft: AssetClassSchema,
|
|
54
|
-
newRedemptionRatioPercentage: OnChainDecimalSchema,
|
|
55
|
-
newMaintenanceRatioPercentage: OnChainDecimalSchema,
|
|
56
|
-
newLiquidationRatioPercentage: OnChainDecimalSchema,
|
|
57
|
-
newDebtMintingFeePercentage: OnChainDecimalSchema,
|
|
58
|
-
newLiquidationProcessingFeePercentage: OnChainDecimalSchema,
|
|
59
|
-
newStabilityPoolWithdrawalFeePercentage: OnChainDecimalSchema,
|
|
60
|
-
newRedemptionReimbursementPercentage: OnChainDecimalSchema,
|
|
61
|
-
newRedemptionProcessingFeePercentage: OnChainDecimalSchema,
|
|
62
|
-
newInterestCollectorPortionPercentage: OnChainDecimalSchema,
|
|
63
|
-
}),
|
|
64
|
-
}),
|
|
65
|
-
Data.Object({
|
|
66
|
-
ModifyProtocolParams: Data.Object({
|
|
67
|
-
newParams: ProtocolParamsSchema,
|
|
68
|
-
}),
|
|
69
|
-
}),
|
|
70
|
-
Data.Object({
|
|
71
|
-
UpgradeProtocol: Data.Object({
|
|
72
|
-
content:
|
|
73
|
-
// NOTICE: This is replaced by evolution-sdk encoding of `UpgradePathsSchema` defined in this file.
|
|
74
|
-
Data.Any(),
|
|
75
|
-
}),
|
|
76
|
-
}),
|
|
77
|
-
Data.Object({
|
|
78
|
-
TextProposal: Data.Object({
|
|
79
|
-
bytes: Data.Bytes(),
|
|
80
|
-
}),
|
|
81
|
-
}),
|
|
82
|
-
]);
|
|
83
|
-
export type ProposalContent = Data.Static<typeof ProposalContentSchema>;
|
|
84
|
-
export const ProposalContent =
|
|
85
|
-
ProposalContentSchema as unknown as ProposalContent;
|
|
86
|
-
|
|
87
|
-
const UpgradePathSchema = EvoCore.TSchema.Struct({
|
|
88
|
-
upgradeSymbol: EvoCore.TSchema.ByteArray,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const UpgradePathsSchema = EvoCore.TSchema.Struct({
|
|
92
|
-
upgradeId: EvoCore.TSchema.Integer,
|
|
93
|
-
/// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
|
|
94
|
-
upgradePaths: EvoCore.TSchema.Map(
|
|
95
|
-
EvoCore.TSchema.ByteArray,
|
|
96
|
-
UpgradePathSchema,
|
|
97
|
-
),
|
|
98
|
-
});
|
|
99
|
-
export type UpgradePaths = typeof UpgradePathsSchema.Type;
|
|
100
|
-
|
|
101
|
-
export function serialiseUpgradePaths(d: UpgradePaths): Data {
|
|
102
|
-
return Data.from(
|
|
103
|
-
EvoCore.Data.withSchema(
|
|
104
|
-
UpgradePathsSchema,
|
|
105
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
106
|
-
).toCBORHex(d),
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function parseUpgradePaths(d: Data): UpgradePaths {
|
|
111
|
-
return EvoCore.Data.withSchema(
|
|
112
|
-
UpgradePathsSchema,
|
|
113
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
114
|
-
).fromCBORHex(Data.to(d));
|
|
115
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AddressSchema, AssetClassSchema } from '../../types/generic';
|
|
3
|
-
import { option as O, function as F } from 'fp-ts';
|
|
4
|
-
import { ProposalContentSchema, ProtocolParamsSchema } from './types-new';
|
|
5
|
-
|
|
6
|
-
const GovDatumSchema = Data.Object({
|
|
7
|
-
currentProposal: Data.Integer(),
|
|
8
|
-
protocolParams: ProtocolParamsSchema,
|
|
9
|
-
currentVersion: Data.Integer(),
|
|
10
|
-
iassetsCount: Data.Integer(),
|
|
11
|
-
activeProposals: Data.Integer(),
|
|
12
|
-
treasuryIndyWithdrawnAmt: Data.Integer(),
|
|
13
|
-
});
|
|
14
|
-
export type GovDatum = Data.Static<typeof GovDatumSchema>;
|
|
15
|
-
const GovDatum = GovDatumSchema as unknown as GovDatum;
|
|
16
|
-
|
|
17
|
-
const GovParamsSchema = Data.Object({
|
|
18
|
-
govNFT: AssetClassSchema,
|
|
19
|
-
pollToken: AssetClassSchema,
|
|
20
|
-
upgradeToken: AssetClassSchema,
|
|
21
|
-
indyAsset: AssetClassSchema,
|
|
22
|
-
versionRecordToken: AssetClassSchema,
|
|
23
|
-
pollManagerValHash: Data.Bytes(),
|
|
24
|
-
gBiasTime: Data.Integer(),
|
|
25
|
-
daoIdentityToken: AssetClassSchema,
|
|
26
|
-
iAssetAuthToken: AssetClassSchema,
|
|
27
|
-
});
|
|
28
|
-
export type GovParams = Data.Static<typeof GovParamsSchema>;
|
|
29
|
-
export const GovParams = GovParamsSchema as unknown as GovParams;
|
|
30
|
-
|
|
31
|
-
const ValueWithdrawalItemSchema = Data.Tuple(
|
|
32
|
-
[Data.Bytes(), Data.Bytes(), Data.Integer()],
|
|
33
|
-
{ hasConstr: true },
|
|
34
|
-
);
|
|
35
|
-
export type TreasuryWithdrawalItem = Data.Static<
|
|
36
|
-
typeof ValueWithdrawalItemSchema
|
|
37
|
-
>;
|
|
38
|
-
|
|
39
|
-
export const TreasuryWithdrawalSchema = Data.Object({
|
|
40
|
-
destination: AddressSchema,
|
|
41
|
-
value: Data.Array(ValueWithdrawalItemSchema),
|
|
42
|
-
});
|
|
43
|
-
export type TreasuryWithdrawal = Data.Static<typeof TreasuryWithdrawalSchema>;
|
|
44
|
-
|
|
45
|
-
const GovRedeemerSchema = Data.Enum([
|
|
46
|
-
Data.Object({
|
|
47
|
-
CreatePoll: Data.Object({
|
|
48
|
-
currentTime: Data.Integer(),
|
|
49
|
-
proposalOwner: Data.Bytes(),
|
|
50
|
-
content: ProposalContentSchema,
|
|
51
|
-
treasuryWithdrawal: Data.Nullable(TreasuryWithdrawalSchema),
|
|
52
|
-
}),
|
|
53
|
-
}),
|
|
54
|
-
Data.Object({ WitnessEndPoll: Data.Object({ currentTime: Data.Integer() }) }),
|
|
55
|
-
Data.Literal('UpgradeGov'),
|
|
56
|
-
Data.Literal('UpgradeVersion'),
|
|
57
|
-
]);
|
|
58
|
-
|
|
59
|
-
export type GovRedeemer = Data.Static<typeof GovRedeemerSchema>;
|
|
60
|
-
export const GovRedeemer = GovRedeemerSchema as unknown as GovRedeemer;
|
|
61
|
-
|
|
62
|
-
export function parseGovDatum(datum: Datum): O.Option<GovDatum> {
|
|
63
|
-
try {
|
|
64
|
-
return O.some(Data.from<GovDatum>(datum, GovDatum));
|
|
65
|
-
} catch (_) {
|
|
66
|
-
return O.none;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function parseGovDatumOrThrow(datum: Datum): GovDatum {
|
|
71
|
-
return F.pipe(
|
|
72
|
-
parseGovDatum(datum),
|
|
73
|
-
O.match(() => {
|
|
74
|
-
throw new Error('Expected a Gov datum.');
|
|
75
|
-
}, F.identity),
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function serialiseGovDatum(d: GovDatum): Datum {
|
|
80
|
-
return Data.to<GovDatum>(d, GovDatum);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function serialiseGovRedeemer(redeemer: GovRedeemer): Redeemer {
|
|
84
|
-
return Data.to<GovRedeemer>(redeemer, GovRedeemer);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function castGovParams(params: GovParams): Data {
|
|
88
|
-
return Data.castTo(params, GovParams);
|
|
89
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { applyParamsToScript } from '@lucid-evolution/lucid';
|
|
2
|
-
import { SpendingValidator } from '@lucid-evolution/lucid';
|
|
3
|
-
import {
|
|
4
|
-
castInterestOracleParams,
|
|
5
|
-
InterestOracleParams,
|
|
6
|
-
} from '../interest-oracle/types';
|
|
7
|
-
import { _interestOracleValidator } from '../../validators/interest-oracle-validator';
|
|
8
|
-
|
|
9
|
-
export function mkInterestOracleValidator(
|
|
10
|
-
params: InterestOracleParams,
|
|
11
|
-
): SpendingValidator {
|
|
12
|
-
return {
|
|
13
|
-
type: 'PlutusV2',
|
|
14
|
-
script: applyParamsToScript(_interestOracleValidator.cborHex, [
|
|
15
|
-
castInterestOracleParams(params),
|
|
16
|
-
]),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fromText,
|
|
3
|
-
LucidEvolution,
|
|
4
|
-
OutRef,
|
|
5
|
-
toUnit,
|
|
6
|
-
TxBuilder,
|
|
7
|
-
UTxO,
|
|
8
|
-
validatorToAddress,
|
|
9
|
-
} from '@lucid-evolution/lucid';
|
|
10
|
-
import { AssetClass } from '../../types/generic';
|
|
11
|
-
import {
|
|
12
|
-
InterestOracleParams,
|
|
13
|
-
parseInterestOracleDatum,
|
|
14
|
-
serialiseFeedInterestOracleRedeemer,
|
|
15
|
-
serialiseInterestOracleDatum,
|
|
16
|
-
} from './types';
|
|
17
|
-
import { oneShotMintTx } from '../one-shot/transactions';
|
|
18
|
-
import { mkInterestOracleValidator } from './scripts';
|
|
19
|
-
import { findInterestOracle } from '../../../tests/queries/interest-oracle-queries';
|
|
20
|
-
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
21
|
-
import { calculateUnitaryInterestSinceOracleLastUpdated } from '../interest-oracle/helpers';
|
|
22
|
-
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
|
|
23
|
-
|
|
24
|
-
export async function startInterestOracle(
|
|
25
|
-
initialUnitaryInterest: bigint,
|
|
26
|
-
initialInterestRate: bigint,
|
|
27
|
-
initialLastInterestUpdate: bigint,
|
|
28
|
-
oracleParams: InterestOracleParams,
|
|
29
|
-
lucid: LucidEvolution,
|
|
30
|
-
interestTokenName?: string,
|
|
31
|
-
withScriptRef: boolean = false,
|
|
32
|
-
refOutRef?: OutRef,
|
|
33
|
-
): Promise<[TxBuilder, AssetClass]> {
|
|
34
|
-
const network = lucid.config().network!;
|
|
35
|
-
|
|
36
|
-
const tokenName = interestTokenName ?? 'INTEREST_ORACLE';
|
|
37
|
-
if (!refOutRef) {
|
|
38
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
42
|
-
referenceOutRef: {
|
|
43
|
-
txHash: refOutRef.txHash,
|
|
44
|
-
outputIdx: BigInt(refOutRef.outputIndex),
|
|
45
|
-
},
|
|
46
|
-
mintAmounts: [
|
|
47
|
-
{
|
|
48
|
-
tokenName: fromText(tokenName),
|
|
49
|
-
amount: 1n,
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const validator = mkInterestOracleValidator(oracleParams);
|
|
55
|
-
|
|
56
|
-
tx.pay.ToContract(
|
|
57
|
-
validatorToAddress(network, validator),
|
|
58
|
-
{
|
|
59
|
-
kind: 'inline',
|
|
60
|
-
value: serialiseInterestOracleDatum({
|
|
61
|
-
unitaryInterest: initialUnitaryInterest,
|
|
62
|
-
interestRate: {
|
|
63
|
-
getOnChainInt: initialInterestRate,
|
|
64
|
-
},
|
|
65
|
-
lastUpdated: initialLastInterestUpdate,
|
|
66
|
-
}),
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
lovelace: 2_500_000n,
|
|
70
|
-
[toUnit(policyId, fromText(tokenName))]: 1n,
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
if (withScriptRef) {
|
|
75
|
-
tx.pay.ToAddressWithData(
|
|
76
|
-
validatorToAddress(network, validator),
|
|
77
|
-
undefined,
|
|
78
|
-
undefined,
|
|
79
|
-
validator,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return [
|
|
84
|
-
tx,
|
|
85
|
-
{
|
|
86
|
-
currencySymbol: policyId,
|
|
87
|
-
tokenName: fromText(tokenName),
|
|
88
|
-
},
|
|
89
|
-
];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function feedInterestOracle(
|
|
93
|
-
params: InterestOracleParams,
|
|
94
|
-
newInterestRate: bigint,
|
|
95
|
-
lucid: LucidEvolution,
|
|
96
|
-
assetClass?: AssetClass,
|
|
97
|
-
utxo?: UTxO,
|
|
98
|
-
scriptRef?: UTxO,
|
|
99
|
-
): Promise<TxBuilder> {
|
|
100
|
-
if (!assetClass && !utxo)
|
|
101
|
-
throw new Error('Either interest oracle nft or utxo must be provided');
|
|
102
|
-
if (assetClass && !utxo) {
|
|
103
|
-
utxo = await findInterestOracle(lucid, assetClass);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const now = BigInt(Date.now());
|
|
107
|
-
const tx = lucid.newTx();
|
|
108
|
-
const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo!));
|
|
109
|
-
|
|
110
|
-
if (scriptRef) {
|
|
111
|
-
tx.readFrom([scriptRef]);
|
|
112
|
-
} else {
|
|
113
|
-
tx.attach.Script(mkInterestOracleValidator(params));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
tx.collectFrom(
|
|
117
|
-
[utxo!],
|
|
118
|
-
serialiseFeedInterestOracleRedeemer({
|
|
119
|
-
newInterestRate: {
|
|
120
|
-
getOnChainInt: newInterestRate,
|
|
121
|
-
},
|
|
122
|
-
currentTime: now,
|
|
123
|
-
}),
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
tx.pay.ToContract(
|
|
127
|
-
utxo!.address,
|
|
128
|
-
{
|
|
129
|
-
kind: 'inline',
|
|
130
|
-
value: serialiseInterestOracleDatum({
|
|
131
|
-
unitaryInterest:
|
|
132
|
-
datum.unitaryInterest +
|
|
133
|
-
calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
|
|
134
|
-
interestRate: {
|
|
135
|
-
getOnChainInt: newInterestRate,
|
|
136
|
-
},
|
|
137
|
-
lastUpdated: now,
|
|
138
|
-
}),
|
|
139
|
-
},
|
|
140
|
-
utxo!.assets,
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
tx.validFrom(Number(now) - ONE_SECOND);
|
|
144
|
-
tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
|
|
145
|
-
|
|
146
|
-
tx.addSignerKey(params.owner);
|
|
147
|
-
|
|
148
|
-
return tx;
|
|
149
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
-
import { castLrpParams, LRPParams } from './types';
|
|
3
|
-
import { fromSystemParamsAsset, LrpParamsSP } from '../../types/system-params';
|
|
4
|
-
import { _lrpValidator } from '../../validators/lrp-validator';
|
|
5
|
-
|
|
6
|
-
export const mkLrpValidator = (params: LRPParams): SpendingValidator => {
|
|
7
|
-
return {
|
|
8
|
-
type: 'PlutusV2',
|
|
9
|
-
script: applyParamsToScript(_lrpValidator.cborHex, [castLrpParams(params)]),
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const mkLrpValidatorFromSP = (
|
|
14
|
-
params: LrpParamsSP,
|
|
15
|
-
): SpendingValidator => {
|
|
16
|
-
return {
|
|
17
|
-
type: 'PlutusV2',
|
|
18
|
-
script: applyParamsToScript(_lrpValidator.cborHex, [
|
|
19
|
-
castLrpParams({
|
|
20
|
-
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
21
|
-
iassetNft: fromSystemParamsAsset(params.iassetNft),
|
|
22
|
-
minRedemptionLovelacesAmt: BigInt(params.minRedemptionLovelacesAmt),
|
|
23
|
-
iassetPolicyId: params.iassetPolicyId.unCurrencySymbol,
|
|
24
|
-
}),
|
|
25
|
-
]),
|
|
26
|
-
};
|
|
27
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
calculateTotalVestedRewards,
|
|
3
|
-
calculateTotalVestedTeam,
|
|
4
|
-
} from '../vesting/helpers';
|
|
5
|
-
import { PollStatus } from './types-poll';
|
|
6
|
-
import { ocdDiv, OnChainDecimal } from '../../types/on-chain-decimal';
|
|
7
|
-
|
|
8
|
-
function q(
|
|
9
|
-
initialIndyDist: bigint,
|
|
10
|
-
pollStatus: PollStatus,
|
|
11
|
-
currentTime: bigint,
|
|
12
|
-
treasuryIndyWithdrawnAmt: bigint,
|
|
13
|
-
): OnChainDecimal {
|
|
14
|
-
if (pollStatus.yesVotes + pollStatus.noVotes === 0n)
|
|
15
|
-
return { getOnChainInt: 0n };
|
|
16
|
-
else {
|
|
17
|
-
const e =
|
|
18
|
-
treasuryIndyWithdrawnAmt +
|
|
19
|
-
calculateTotalVestedRewards(currentTime) +
|
|
20
|
-
calculateTotalVestedTeam(currentTime) +
|
|
21
|
-
initialIndyDist;
|
|
22
|
-
|
|
23
|
-
const q =
|
|
24
|
-
ocdDiv(
|
|
25
|
-
{ getOnChainInt: pollStatus.yesVotes },
|
|
26
|
-
{ getOnChainInt: BigInt(Math.floor(Math.sqrt(Number(e)))) },
|
|
27
|
-
).getOnChainInt -
|
|
28
|
-
ocdDiv(
|
|
29
|
-
{ getOnChainInt: pollStatus.noVotes },
|
|
30
|
-
{
|
|
31
|
-
getOnChainInt: BigInt(
|
|
32
|
-
Math.floor(
|
|
33
|
-
Math.sqrt(Number(pollStatus.yesVotes + pollStatus.noVotes)),
|
|
34
|
-
),
|
|
35
|
-
),
|
|
36
|
-
},
|
|
37
|
-
).getOnChainInt;
|
|
38
|
-
|
|
39
|
-
return { getOnChainInt: BigInt(q) };
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function pollPassQuorum(
|
|
44
|
-
initialIndyDist: bigint,
|
|
45
|
-
pollStatus: PollStatus,
|
|
46
|
-
currentTime: bigint,
|
|
47
|
-
minQuorum: bigint,
|
|
48
|
-
treasuryIndyWithdrawnAmt: bigint,
|
|
49
|
-
): boolean {
|
|
50
|
-
return (
|
|
51
|
-
pollStatus.yesVotes + pollStatus.noVotes >= minQuorum &&
|
|
52
|
-
q(initialIndyDist, pollStatus, currentTime, treasuryIndyWithdrawnAmt)
|
|
53
|
-
.getOnChainInt > 50_000n
|
|
54
|
-
);
|
|
55
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
-
import {
|
|
3
|
-
castPollManagerParams,
|
|
4
|
-
PollManagerParams,
|
|
5
|
-
} from '../poll/types-poll-manager';
|
|
6
|
-
import {
|
|
7
|
-
PollManagerParamsSP,
|
|
8
|
-
PollShardParamsSP,
|
|
9
|
-
fromSystemParamsAsset,
|
|
10
|
-
} from '../../types/system-params';
|
|
11
|
-
import { castPollShardParams, PollShardParams } from './types-poll-shard';
|
|
12
|
-
import { _pollManagerValidator } from '../../validators/poll-manager-validator';
|
|
13
|
-
import { _pollShardValidator } from '../../validators/poll-shard-validator';
|
|
14
|
-
|
|
15
|
-
export const mkPollManagerValidator = (
|
|
16
|
-
params: PollManagerParams,
|
|
17
|
-
): SpendingValidator => {
|
|
18
|
-
return {
|
|
19
|
-
type: 'PlutusV2',
|
|
20
|
-
script: applyParamsToScript(_pollManagerValidator.cborHex, [
|
|
21
|
-
castPollManagerParams(params),
|
|
22
|
-
]),
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const mkPollManagerValidatorFromSP = (
|
|
27
|
-
params: PollManagerParamsSP,
|
|
28
|
-
): SpendingValidator => {
|
|
29
|
-
return {
|
|
30
|
-
type: 'PlutusV2',
|
|
31
|
-
script: applyParamsToScript(_pollManagerValidator.cborHex, [
|
|
32
|
-
castPollManagerParams({
|
|
33
|
-
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
34
|
-
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
35
|
-
upgradeToken: fromSystemParamsAsset(params.upgradeToken),
|
|
36
|
-
indyAsset: fromSystemParamsAsset(params.indyAsset),
|
|
37
|
-
govExecuteValHash: params.govExecuteValHash,
|
|
38
|
-
pBiasTime: BigInt(params.pBiasTime),
|
|
39
|
-
shardValHash: params.shardsValHash,
|
|
40
|
-
treasuryValHash: params.treasuryValHash,
|
|
41
|
-
initialIndyDistribution: BigInt(params.initialIndyDistribution),
|
|
42
|
-
}),
|
|
43
|
-
]),
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const mkPollShardValidator = (
|
|
48
|
-
params: PollShardParams,
|
|
49
|
-
): SpendingValidator => {
|
|
50
|
-
return {
|
|
51
|
-
type: 'PlutusV2',
|
|
52
|
-
script: applyParamsToScript(_pollShardValidator.cborHex, [
|
|
53
|
-
castPollShardParams(params),
|
|
54
|
-
]),
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const mkPollShardValidatorFromSP = (
|
|
59
|
-
params: PollShardParamsSP,
|
|
60
|
-
): SpendingValidator => {
|
|
61
|
-
return {
|
|
62
|
-
type: 'PlutusV2',
|
|
63
|
-
script: applyParamsToScript(_pollShardValidator.cborHex, [
|
|
64
|
-
castPollShardParams({
|
|
65
|
-
pollToken: fromSystemParamsAsset(params.pollToken),
|
|
66
|
-
stakingToken: fromSystemParamsAsset(params.stakingToken),
|
|
67
|
-
indyAsset: fromSystemParamsAsset(params.indyAsset),
|
|
68
|
-
stakingValHash: params.stakingValHash,
|
|
69
|
-
}),
|
|
70
|
-
]),
|
|
71
|
-
};
|
|
72
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Data, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
-
|
|
4
|
-
const PollManagerParamsSchema = Data.Object({
|
|
5
|
-
govNFT: AssetClassSchema,
|
|
6
|
-
pollToken: AssetClassSchema,
|
|
7
|
-
upgradeToken: AssetClassSchema,
|
|
8
|
-
indyAsset: AssetClassSchema,
|
|
9
|
-
govExecuteValHash: Data.Bytes(),
|
|
10
|
-
pBiasTime: Data.Integer(),
|
|
11
|
-
shardValHash: Data.Bytes(),
|
|
12
|
-
treasuryValHash: Data.Bytes(),
|
|
13
|
-
initialIndyDistribution: Data.Integer(),
|
|
14
|
-
});
|
|
15
|
-
export type PollManagerParams = Data.Static<typeof PollManagerParamsSchema>;
|
|
16
|
-
export const PollManagerParams =
|
|
17
|
-
PollManagerParamsSchema as unknown as PollManagerParams;
|
|
18
|
-
|
|
19
|
-
const PollManagerRedeemerSchema = Data.Enum([
|
|
20
|
-
Data.Object({
|
|
21
|
-
EndPoll: Data.Object({ currentTime: Data.Integer() }),
|
|
22
|
-
}),
|
|
23
|
-
Data.Object({ CreateShards: Data.Object({ currentTime: Data.Integer() }) }),
|
|
24
|
-
Data.Object({
|
|
25
|
-
MergeShardsManager: Data.Object({ currentTime: Data.Integer() }),
|
|
26
|
-
}),
|
|
27
|
-
]);
|
|
28
|
-
export type PollManagerRedeemer = Data.Static<typeof PollManagerRedeemerSchema>;
|
|
29
|
-
export const PollManagerRedeemer =
|
|
30
|
-
PollManagerRedeemerSchema as unknown as PollManagerRedeemer;
|
|
31
|
-
|
|
32
|
-
export function serialisePollManagerRedeemer(r: PollManagerRedeemer): Redeemer {
|
|
33
|
-
return Data.to<PollManagerRedeemer>(r, PollManagerRedeemer);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function castPollManagerParams(params: PollManagerParams): Data {
|
|
37
|
-
return Data.castTo(params, PollManagerParams);
|
|
38
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Data, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema, OutputReferenceSchema } from '../../types/generic';
|
|
3
|
-
|
|
4
|
-
const PollShardParamsSchema = Data.Object({
|
|
5
|
-
pollToken: AssetClassSchema,
|
|
6
|
-
stakingToken: AssetClassSchema,
|
|
7
|
-
indyAsset: AssetClassSchema,
|
|
8
|
-
stakingValHash: Data.Bytes(),
|
|
9
|
-
});
|
|
10
|
-
export type PollShardParams = Data.Static<typeof PollShardParamsSchema>;
|
|
11
|
-
export const PollShardParams =
|
|
12
|
-
PollShardParamsSchema as unknown as PollShardParams;
|
|
13
|
-
|
|
14
|
-
const VoteOptionSchema = Data.Enum([Data.Literal('Yes'), Data.Literal('No')]);
|
|
15
|
-
export type VoteOption = Data.Static<typeof VoteOptionSchema>;
|
|
16
|
-
|
|
17
|
-
const PollShardRedeemerSchema = Data.Enum([
|
|
18
|
-
Data.Object({ Vote: Data.Object({ content: VoteOptionSchema }) }),
|
|
19
|
-
Data.Object({
|
|
20
|
-
MergeShards: Data.Object({
|
|
21
|
-
currentTime: Data.Integer(),
|
|
22
|
-
pollManagerRef: OutputReferenceSchema,
|
|
23
|
-
}),
|
|
24
|
-
}),
|
|
25
|
-
]);
|
|
26
|
-
export type PollShardRedeemer = Data.Static<typeof PollShardRedeemerSchema>;
|
|
27
|
-
export const PollShardRedeemer =
|
|
28
|
-
PollShardRedeemerSchema as unknown as PollShardRedeemer;
|
|
29
|
-
|
|
30
|
-
export function serialisePollShardRedeemer(
|
|
31
|
-
redeemer: PollShardRedeemer,
|
|
32
|
-
): Redeemer {
|
|
33
|
-
return Data.to<PollShardRedeemer>(redeemer, PollShardRedeemer);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function castPollShardParams(params: PollShardParams): Data {
|
|
37
|
-
return Data.castTo(params, PollShardParams);
|
|
38
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Data, Datum } from '@lucid-evolution/lucid';
|
|
2
|
-
import { TreasuryWithdrawalSchema } from '../gov/types';
|
|
3
|
-
import { AddressSchema } from '../../types/generic';
|
|
4
|
-
import { option as O, function as F } from 'fp-ts';
|
|
5
|
-
import { match, P } from 'ts-pattern';
|
|
6
|
-
import { ProposalContentSchema } from '../gov/types-new';
|
|
7
|
-
|
|
8
|
-
const PollStatusSchema = Data.Object({
|
|
9
|
-
yesVotes: Data.Integer(),
|
|
10
|
-
noVotes: Data.Integer(),
|
|
11
|
-
});
|
|
12
|
-
export type PollStatus = Data.Static<typeof PollStatusSchema>;
|
|
13
|
-
|
|
14
|
-
const PollManagerContentSchema = Data.Object({
|
|
15
|
-
pollId: Data.Integer(),
|
|
16
|
-
pollOwner: Data.Bytes(),
|
|
17
|
-
content: ProposalContentSchema,
|
|
18
|
-
treasuryWithdrawal: Data.Nullable(TreasuryWithdrawalSchema),
|
|
19
|
-
status: PollStatusSchema,
|
|
20
|
-
votingEndTime: Data.Integer(),
|
|
21
|
-
createdShardsCount: Data.Integer(),
|
|
22
|
-
talliedShardsCount: Data.Integer(),
|
|
23
|
-
totalShardsCount: Data.Integer(),
|
|
24
|
-
proposingEndTime: Data.Integer(),
|
|
25
|
-
expirationTime: Data.Integer(),
|
|
26
|
-
protocolVersion: Data.Integer(),
|
|
27
|
-
minimumQuorum: Data.Integer(),
|
|
28
|
-
});
|
|
29
|
-
export type PollManagerContent = Data.Static<typeof PollManagerContentSchema>;
|
|
30
|
-
|
|
31
|
-
const PollShardContentSchema = Data.Object({
|
|
32
|
-
pollId: Data.Integer(),
|
|
33
|
-
status: PollStatusSchema,
|
|
34
|
-
votingEndTime: Data.Integer(),
|
|
35
|
-
managerAddress: AddressSchema,
|
|
36
|
-
});
|
|
37
|
-
export type PollShardContent = Data.Static<typeof PollShardContentSchema>;
|
|
38
|
-
|
|
39
|
-
const PollDatumSchema = Data.Enum([
|
|
40
|
-
Data.Object({
|
|
41
|
-
PollManager: Data.Object({ content: PollManagerContentSchema }),
|
|
42
|
-
}),
|
|
43
|
-
Data.Object({ PollShard: Data.Object({ content: PollShardContentSchema }) }),
|
|
44
|
-
]);
|
|
45
|
-
export type PollDatum = Data.Static<typeof PollDatumSchema>;
|
|
46
|
-
export const PollDatum = PollDatumSchema as unknown as PollDatum;
|
|
47
|
-
|
|
48
|
-
export function parsePollManager(datum: Datum): O.Option<PollManagerContent> {
|
|
49
|
-
try {
|
|
50
|
-
return match(Data.from<PollDatum>(datum, PollDatum))
|
|
51
|
-
.with({ PollManager: P.select() }, (res) => O.some(res.content))
|
|
52
|
-
.otherwise(() => O.none);
|
|
53
|
-
} catch (_) {
|
|
54
|
-
return O.none;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function parsePollManagerOrThrow(datum: Datum): PollManagerContent {
|
|
59
|
-
return F.pipe(
|
|
60
|
-
parsePollManager(datum),
|
|
61
|
-
O.match(() => {
|
|
62
|
-
throw new Error('Expected a Poll manager datum.');
|
|
63
|
-
}, F.identity),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function parsePollShard(datum: Datum): O.Option<PollShardContent> {
|
|
68
|
-
try {
|
|
69
|
-
return match(Data.from<PollDatum>(datum, PollDatum))
|
|
70
|
-
.with({ PollShard: P.select() }, (res) => O.some(res.content))
|
|
71
|
-
.otherwise(() => O.none);
|
|
72
|
-
} catch (_) {
|
|
73
|
-
return O.none;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function parsePollShardOrThrow(datum: Datum): PollShardContent {
|
|
78
|
-
return F.pipe(
|
|
79
|
-
parsePollShard(datum),
|
|
80
|
-
O.match(() => {
|
|
81
|
-
throw new Error('Expected a Poll shard datum.');
|
|
82
|
-
}, F.identity),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function serialisePollDatum(datum: PollDatum): Datum {
|
|
87
|
-
return Data.to<PollDatum>(datum, PollDatum);
|
|
88
|
-
}
|