@indigo-labs/indigo-sdk 0.1.19 → 0.1.20
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 +1004 -681
- package/dist/index.d.ts +1004 -681
- package/dist/index.js +4652 -2255
- package/dist/index.mjs +4592 -2210
- 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} +23 -23
- package/src/{types/indigo/lrp.ts → contracts/lrp/types.ts} +3 -3
- 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 +660 -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 +37 -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 +180 -78
- 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 -748
- 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 -692
- package/src/contracts/staking.ts +0 -348
- package/src/contracts/treasury.ts +0 -112
- package/src/helpers/asset-helpers.ts +0 -57
- 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,81 @@
|
|
|
1
|
+
import { Core as EvoCore } from '@evolution-sdk/evolution';
|
|
2
|
+
import { option as O, function as F } from 'fp-ts';
|
|
3
|
+
import { match, P } from 'ts-pattern';
|
|
4
|
+
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
5
|
+
|
|
6
|
+
const StakingPosLockedAmtSchema = EvoCore.TSchema.Map(
|
|
7
|
+
EvoCore.TSchema.Integer,
|
|
8
|
+
EvoCore.TSchema.Struct({
|
|
9
|
+
voteAmt: EvoCore.TSchema.Integer,
|
|
10
|
+
votingEnd: EvoCore.TSchema.Integer,
|
|
11
|
+
}),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export type StakingPosLockedAmt = typeof StakingPosLockedAmtSchema.Type;
|
|
15
|
+
|
|
16
|
+
const RewardSnapshotSchema = EvoCore.TSchema.Struct({
|
|
17
|
+
snapshotAda: EvoCore.TSchema.Integer,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const StakingPositionSchema = EvoCore.TSchema.Struct({
|
|
21
|
+
owner: EvoCore.TSchema.ByteArray,
|
|
22
|
+
lockedAmount: StakingPosLockedAmtSchema,
|
|
23
|
+
positionSnapshot: RewardSnapshotSchema,
|
|
24
|
+
});
|
|
25
|
+
export type StakingPosition = typeof StakingPositionSchema.Type;
|
|
26
|
+
|
|
27
|
+
const StakingManagerSchema = EvoCore.TSchema.Struct({
|
|
28
|
+
totalStake: EvoCore.TSchema.Integer,
|
|
29
|
+
managerSnapshot: RewardSnapshotSchema,
|
|
30
|
+
});
|
|
31
|
+
export type StakingManager = typeof StakingManagerSchema.Type;
|
|
32
|
+
|
|
33
|
+
const StakingDatumSchema = EvoCore.TSchema.Union(
|
|
34
|
+
StakingManagerSchema,
|
|
35
|
+
StakingPositionSchema,
|
|
36
|
+
);
|
|
37
|
+
type StakingDatum = typeof StakingDatumSchema.Type;
|
|
38
|
+
|
|
39
|
+
export function parseStakingPosition(datum: string): O.Option<StakingPosition> {
|
|
40
|
+
try {
|
|
41
|
+
return match(
|
|
42
|
+
EvoCore.Data.withSchema(
|
|
43
|
+
StakingDatumSchema,
|
|
44
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
45
|
+
).fromCBORHex(datum),
|
|
46
|
+
)
|
|
47
|
+
.with({ owner: P.any }, (res) => O.some(res))
|
|
48
|
+
.otherwise(() => O.none);
|
|
49
|
+
} catch (_) {
|
|
50
|
+
return O.none;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function parseStakingPositionOrThrow(datum: string): StakingPosition {
|
|
55
|
+
return F.pipe(
|
|
56
|
+
parseStakingPosition(datum),
|
|
57
|
+
O.match(() => {
|
|
58
|
+
throw new Error('Expected a StakingPosition datum.');
|
|
59
|
+
}, F.identity),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function parseStakingManagerDatum(datum: string): StakingManager {
|
|
64
|
+
return match(
|
|
65
|
+
EvoCore.Data.withSchema(
|
|
66
|
+
StakingDatumSchema,
|
|
67
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
68
|
+
).fromCBORHex(datum),
|
|
69
|
+
)
|
|
70
|
+
.with({ totalStake: P.any }, (res) => res)
|
|
71
|
+
.otherwise(() => {
|
|
72
|
+
throw new Error('Expected a StakingPosition datum.');
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function serialiseStakingDatum(d: StakingDatum): string {
|
|
77
|
+
return EvoCore.Data.withSchema(
|
|
78
|
+
StakingDatumSchema,
|
|
79
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
80
|
+
).toCBORHex(d);
|
|
81
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Data, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
+
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
+
|
|
4
|
+
const StakingParamsSchema = Data.Object({
|
|
5
|
+
stakingManagerNft: AssetClassSchema,
|
|
6
|
+
stakingToken: AssetClassSchema,
|
|
7
|
+
indyToken: AssetClassSchema,
|
|
8
|
+
pollToken: AssetClassSchema,
|
|
9
|
+
versionRecordToken: AssetClassSchema,
|
|
10
|
+
collectorValHash: Data.Bytes(),
|
|
11
|
+
});
|
|
12
|
+
type StakingParams = Data.Static<typeof StakingParamsSchema>;
|
|
13
|
+
const StakingParams = StakingParamsSchema as unknown as StakingParams;
|
|
14
|
+
|
|
15
|
+
const StakingRedeemerSchema = Data.Enum([
|
|
16
|
+
Data.Object({
|
|
17
|
+
CreateStakingPosition: Data.Object({
|
|
18
|
+
creatorPkh: Data.Bytes(),
|
|
19
|
+
}),
|
|
20
|
+
}),
|
|
21
|
+
Data.Literal('UpdateTotalStake'),
|
|
22
|
+
Data.Literal('Distribute'),
|
|
23
|
+
Data.Object({
|
|
24
|
+
AdjustStakedAmount: Data.Object({
|
|
25
|
+
adjustAmount: Data.Integer(),
|
|
26
|
+
}),
|
|
27
|
+
}),
|
|
28
|
+
Data.Literal('Unstake'),
|
|
29
|
+
Data.Literal('Lock'),
|
|
30
|
+
Data.Literal('UpgradeVersion'),
|
|
31
|
+
]);
|
|
32
|
+
export type StakingRedeemer = Data.Static<typeof StakingRedeemerSchema>;
|
|
33
|
+
const StakingRedeemer = StakingRedeemerSchema as unknown as StakingRedeemer;
|
|
34
|
+
|
|
35
|
+
export function serialiseStakingRedeemer(redeemer: StakingRedeemer): Redeemer {
|
|
36
|
+
return Data.to<StakingRedeemer>(redeemer, StakingRedeemer);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function castStakingParams(params: StakingParams): Data {
|
|
40
|
+
return Data.castTo(params, StakingParams);
|
|
41
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyParamsToScript,
|
|
3
|
+
Constr,
|
|
4
|
+
fromText,
|
|
5
|
+
SpendingValidator,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
import { TreasuryParamsSP } from '../../types/system-params';
|
|
8
|
+
import { _treasuryValidator } from '../../validators/treasury-validator';
|
|
9
|
+
|
|
10
|
+
export const mkTreasuryValidatorFromSP = (
|
|
11
|
+
params: TreasuryParamsSP,
|
|
12
|
+
): SpendingValidator => {
|
|
13
|
+
return {
|
|
14
|
+
type: 'PlutusV2',
|
|
15
|
+
script: applyParamsToScript(_treasuryValidator.cborHex, [
|
|
16
|
+
new Constr(0, [
|
|
17
|
+
new Constr(0, [
|
|
18
|
+
params.upgradeToken[0].unCurrencySymbol,
|
|
19
|
+
fromText(params.upgradeToken[1].unTokenName),
|
|
20
|
+
]),
|
|
21
|
+
new Constr(0, [
|
|
22
|
+
params.versionRecordToken[0].unCurrencySymbol,
|
|
23
|
+
fromText(params.versionRecordToken[1].unTokenName),
|
|
24
|
+
]),
|
|
25
|
+
params.treasuryUtxosStakeCredential
|
|
26
|
+
? new Constr(0, [
|
|
27
|
+
new Constr(0, [
|
|
28
|
+
new Constr(1, [
|
|
29
|
+
params.treasuryUtxosStakeCredential.contents.contents,
|
|
30
|
+
]),
|
|
31
|
+
]),
|
|
32
|
+
])
|
|
33
|
+
: new Constr(1, []),
|
|
34
|
+
]),
|
|
35
|
+
]),
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addAssets,
|
|
3
|
+
Data,
|
|
4
|
+
LucidEvolution,
|
|
5
|
+
OutRef,
|
|
6
|
+
TxBuilder,
|
|
7
|
+
} from '@lucid-evolution/lucid';
|
|
8
|
+
import {
|
|
9
|
+
fromSystemParamsScriptRef,
|
|
10
|
+
SystemParams,
|
|
11
|
+
} from '../../types/system-params';
|
|
12
|
+
import { matchSingle } from '../../utils/utils';
|
|
13
|
+
import { mkLovelacesOf } from '../../utils/value-helpers';
|
|
14
|
+
import { serialiseTreasuryRedeemer } from './types';
|
|
15
|
+
|
|
16
|
+
export async function treasuryFeeTx(
|
|
17
|
+
fee: bigint,
|
|
18
|
+
lucid: LucidEvolution,
|
|
19
|
+
sysParams: SystemParams,
|
|
20
|
+
tx: TxBuilder,
|
|
21
|
+
treasuryOref: OutRef,
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
const treasuryUtxo = matchSingle(
|
|
24
|
+
await lucid.utxosByOutRef([treasuryOref]),
|
|
25
|
+
(_) => new Error('Expected a single treasury UTXO'),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const treasuryRefScriptUtxo = matchSingle(
|
|
29
|
+
await lucid.utxosByOutRef([
|
|
30
|
+
fromSystemParamsScriptRef(
|
|
31
|
+
sysParams.scriptReferences.treasuryValidatorRef,
|
|
32
|
+
),
|
|
33
|
+
]),
|
|
34
|
+
(_) => new Error('Expected a single treasury Ref Script UTXO'),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
tx.readFrom([treasuryRefScriptUtxo])
|
|
38
|
+
.collectFrom([treasuryUtxo], serialiseTreasuryRedeemer('CollectAda'))
|
|
39
|
+
.pay.ToContract(
|
|
40
|
+
treasuryUtxo.address,
|
|
41
|
+
{ kind: 'inline', value: Data.void() },
|
|
42
|
+
addAssets(treasuryUtxo.assets, mkLovelacesOf(fee)),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Data, Datum, Redeemer } from '@lucid-evolution/lucid';
|
|
2
|
+
import {
|
|
3
|
+
AssetClassSchema,
|
|
4
|
+
OutputReferenceSchema,
|
|
5
|
+
StakeCredentialSchema,
|
|
6
|
+
} from '../../types/generic';
|
|
7
|
+
|
|
8
|
+
export const TreasuryParamsSchema = Data.Object({
|
|
9
|
+
upgradeToken: AssetClassSchema,
|
|
10
|
+
versionRecordToken: AssetClassSchema,
|
|
11
|
+
treasuryUtxosStakeCredential: Data.Nullable(StakeCredentialSchema),
|
|
12
|
+
});
|
|
13
|
+
export type TreasuryParams = Data.Static<typeof TreasuryParamsSchema>;
|
|
14
|
+
export const TreasuryParams = TreasuryParamsSchema as unknown as TreasuryParams;
|
|
15
|
+
|
|
16
|
+
const TreasuryRedeemerSchema = Data.Enum([
|
|
17
|
+
Data.Literal('Withdraw'),
|
|
18
|
+
Data.Literal('PrepareWithdraw'),
|
|
19
|
+
Data.Literal('Split'),
|
|
20
|
+
Data.Literal('Merge'),
|
|
21
|
+
Data.Literal('CollectAda'),
|
|
22
|
+
Data.Literal('UpgradeVersion'),
|
|
23
|
+
]);
|
|
24
|
+
export type TreasuryRedeemer = Data.Static<typeof TreasuryRedeemerSchema>;
|
|
25
|
+
const TreasuryRedeemer = TreasuryRedeemerSchema as unknown as TreasuryRedeemer;
|
|
26
|
+
|
|
27
|
+
const WithdrawalOutputDatumSchema = Data.Tuple([
|
|
28
|
+
Data.Bytes(),
|
|
29
|
+
OutputReferenceSchema,
|
|
30
|
+
]);
|
|
31
|
+
export type WithdrawalOutputDatum = Data.Static<
|
|
32
|
+
typeof WithdrawalOutputDatumSchema
|
|
33
|
+
>;
|
|
34
|
+
const WithdrawalOutputDatum =
|
|
35
|
+
WithdrawalOutputDatumSchema as unknown as WithdrawalOutputDatum;
|
|
36
|
+
|
|
37
|
+
export function serialiseWithdrawalOutputDatum(
|
|
38
|
+
d: WithdrawalOutputDatum,
|
|
39
|
+
): Datum {
|
|
40
|
+
return Data.to<WithdrawalOutputDatum>(d, WithdrawalOutputDatum);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function serialiseTreasuryRedeemer(
|
|
44
|
+
redeemer: TreasuryRedeemer,
|
|
45
|
+
): Redeemer {
|
|
46
|
+
return Data.to<TreasuryRedeemer>(redeemer, TreasuryRedeemer);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function serialiseTreasuryDatum(): Datum {
|
|
50
|
+
return Data.void();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function castTreasuryParams(params: TreasuryParams): Data {
|
|
54
|
+
return Data.castTo(params, TreasuryParams);
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyParamsToScript,
|
|
3
|
+
MintingPolicy,
|
|
4
|
+
SpendingValidator,
|
|
5
|
+
} from '@lucid-evolution/lucid';
|
|
6
|
+
import {
|
|
7
|
+
castVersionRecordTokenParams,
|
|
8
|
+
VersionRecordTokenParams,
|
|
9
|
+
} from './types';
|
|
10
|
+
import { _versionRecordTokenPolicy } from '../../validators/version-record-policy';
|
|
11
|
+
import { _versionRegistryValidator } from '../../validators/version-registry-validator';
|
|
12
|
+
|
|
13
|
+
export function mkVersionRecordTokenPolicy(
|
|
14
|
+
params: VersionRecordTokenParams,
|
|
15
|
+
): MintingPolicy {
|
|
16
|
+
return {
|
|
17
|
+
type: 'PlutusV2',
|
|
18
|
+
script: applyParamsToScript(_versionRecordTokenPolicy.cborHex, [
|
|
19
|
+
castVersionRecordTokenParams(params),
|
|
20
|
+
]),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const mkVersionRegistryValidator = (): SpendingValidator => {
|
|
25
|
+
return {
|
|
26
|
+
type: 'PlutusV2',
|
|
27
|
+
script: _versionRegistryValidator.cborHex,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Core as EvoCore } from '@evolution-sdk/evolution';
|
|
2
|
+
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
3
|
+
|
|
4
|
+
const VersionRecordDatumSchema = EvoCore.TSchema.Struct({
|
|
5
|
+
upgradeId: EvoCore.TSchema.Integer,
|
|
6
|
+
/// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
|
|
7
|
+
upgradePaths: EvoCore.TSchema.Map(
|
|
8
|
+
EvoCore.TSchema.ByteArray,
|
|
9
|
+
EvoCore.TSchema.ByteArray,
|
|
10
|
+
),
|
|
11
|
+
});
|
|
12
|
+
export type VersionRecordDatum = typeof VersionRecordDatumSchema.Type;
|
|
13
|
+
|
|
14
|
+
export function serialiseVersionRecordDatum(d: VersionRecordDatum): string {
|
|
15
|
+
return EvoCore.Data.withSchema(
|
|
16
|
+
VersionRecordDatumSchema,
|
|
17
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
18
|
+
).toCBORHex(d);
|
|
19
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { match, P } from 'ts-pattern';
|
|
2
|
+
import { ONE_DAY } from '../../utils/time-helpers';
|
|
3
|
+
import { OCD_DECIMAL_UNIT } from '../../types/on-chain-decimal';
|
|
4
|
+
import { array as A } from 'fp-ts';
|
|
5
|
+
import { bigintMax, bigintMin } from '../../utils/bigint-utils';
|
|
6
|
+
|
|
7
|
+
type Schedule = {
|
|
8
|
+
vestedAtTime: bigint;
|
|
9
|
+
unlockAmt: bigint;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type VestingSchedule = {
|
|
13
|
+
maxUnlockable: bigint;
|
|
14
|
+
schedule: Schedule[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const teamVestingSchedule: Schedule[] = [
|
|
18
|
+
{
|
|
19
|
+
vestedAtTime: 1669067100000n,
|
|
20
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
vestedAtTime: 1672523100000n,
|
|
24
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
vestedAtTime: 1675201500000n,
|
|
28
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
vestedAtTime: 1677620700000n,
|
|
32
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
vestedAtTime: 1680299100000n,
|
|
36
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
vestedAtTime: 1682891100000n,
|
|
40
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
vestedAtTime: 1685569500000n,
|
|
44
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
vestedAtTime: 1688161500000n,
|
|
48
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
vestedAtTime: 1690839900000n,
|
|
52
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
vestedAtTime: 1693518300000n,
|
|
56
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
vestedAtTime: 1696110300000n,
|
|
60
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
vestedAtTime: 1698788700000n,
|
|
64
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
vestedAtTime: 1701380700000n,
|
|
68
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
vestedAtTime: 1704059100000n,
|
|
72
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
vestedAtTime: 1706737500000n,
|
|
76
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
vestedAtTime: 1709243100000n,
|
|
80
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
vestedAtTime: 1711921500000n,
|
|
84
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
vestedAtTime: 1714513500000n,
|
|
88
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
vestedAtTime: 1717191900000n,
|
|
92
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
vestedAtTime: 1719783900000n,
|
|
96
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
vestedAtTime: 1722462300000n,
|
|
100
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
vestedAtTime: 1725140700000n,
|
|
104
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
vestedAtTime: 1727732700000n,
|
|
108
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
vestedAtTime: 1730411100000n,
|
|
112
|
+
unlockAmt: 328_125n * OCD_DECIMAL_UNIT,
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
const spDistributionSchedule: VestingSchedule = {
|
|
117
|
+
maxUnlockable: 14_000_000n * OCD_DECIMAL_UNIT,
|
|
118
|
+
schedule: [
|
|
119
|
+
{
|
|
120
|
+
vestedAtTime: 1669931100000n,
|
|
121
|
+
unlockAmt: 28_768n * OCD_DECIMAL_UNIT,
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
vestedAtTime: 1701467100000n,
|
|
125
|
+
unlockAmt: 33_562n * OCD_DECIMAL_UNIT,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
vestedAtTime: 1727387100000n,
|
|
129
|
+
unlockAmt: 33_561n * OCD_DECIMAL_UNIT,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
vestedAtTime: 1733003100000n,
|
|
133
|
+
unlockAmt: 38_356n * OCD_DECIMAL_UNIT,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
vestedAtTime: 1764539100000n,
|
|
137
|
+
unlockAmt: 43_150n * OCD_DECIMAL_UNIT,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
vestedAtTime: 1796075100000n,
|
|
141
|
+
unlockAmt: 47_945n * OCD_DECIMAL_UNIT,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const liqDistributionSchedule: VestingSchedule = {
|
|
147
|
+
maxUnlockable: 5_250_000n * OCD_DECIMAL_UNIT,
|
|
148
|
+
schedule: [
|
|
149
|
+
{
|
|
150
|
+
vestedAtTime: 1671659100000n,
|
|
151
|
+
unlockAmt: 4_795n * OCD_DECIMAL_UNIT,
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
vestedAtTime: 1703195100000n,
|
|
155
|
+
unlockAmt: 9_590n * OCD_DECIMAL_UNIT,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
vestedAtTime: 1728683100000n,
|
|
159
|
+
unlockAmt: 9_589n * OCD_DECIMAL_UNIT,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
vestedAtTime: 1734731100000n,
|
|
163
|
+
unlockAmt: 14_383n * OCD_DECIMAL_UNIT,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
vestedAtTime: 1766267100000n,
|
|
167
|
+
unlockAmt: 19_178n * OCD_DECIMAL_UNIT,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
vestedAtTime: 1797803100000n,
|
|
171
|
+
unlockAmt: 23_972n * OCD_DECIMAL_UNIT,
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const govDistributionSchedule: VestingSchedule = {
|
|
177
|
+
maxUnlockable: 1_750_000n * OCD_DECIMAL_UNIT,
|
|
178
|
+
schedule: [
|
|
179
|
+
{
|
|
180
|
+
vestedAtTime: 1670363100000n,
|
|
181
|
+
unlockAmt: 2_398n * OCD_DECIMAL_UNIT,
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
vestedAtTime: 1701899100000n,
|
|
185
|
+
unlockAmt: 3_596n * OCD_DECIMAL_UNIT,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
vestedAtTime: 1733435100000n,
|
|
189
|
+
unlockAmt: 4_795n * OCD_DECIMAL_UNIT,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
vestedAtTime: 1752443100000n,
|
|
193
|
+
unlockAmt: 4_794n * OCD_DECIMAL_UNIT,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
vestedAtTime: 1764971100000n,
|
|
197
|
+
unlockAmt: 5_993n * OCD_DECIMAL_UNIT,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
vestedAtTime: 1796507100000n,
|
|
201
|
+
unlockAmt: 7_191n * OCD_DECIMAL_UNIT,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export function calculateTotalVestedTeam(currentTime: bigint): bigint {
|
|
207
|
+
return A.reduce<Schedule, bigint>(0n, (acc, schedule) => {
|
|
208
|
+
if (currentTime >= schedule.vestedAtTime) {
|
|
209
|
+
return acc + schedule.unlockAmt;
|
|
210
|
+
} else {
|
|
211
|
+
return acc;
|
|
212
|
+
}
|
|
213
|
+
})(teamVestingSchedule);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function calculateVestedPerEpoch(
|
|
217
|
+
schedule: VestingSchedule,
|
|
218
|
+
currentTime: bigint,
|
|
219
|
+
): bigint {
|
|
220
|
+
const vestingFreq = 5n * ONE_DAY;
|
|
221
|
+
|
|
222
|
+
function go(sched: Schedule[]): bigint {
|
|
223
|
+
return (
|
|
224
|
+
match(sched)
|
|
225
|
+
.returnType<bigint>()
|
|
226
|
+
.with([], () => 0n)
|
|
227
|
+
// If the current time is earlier than the first vesting period,
|
|
228
|
+
// the vested INDY is zero.
|
|
229
|
+
// Otherwise, the vested INDY increases by the given amount every epoch
|
|
230
|
+
// after the given date.
|
|
231
|
+
// The + 1 indicates that the first vest happens from the given date
|
|
232
|
+
// (as opposed to having to wait for an epoch to complete)
|
|
233
|
+
.with([P.select()], (sched) =>
|
|
234
|
+
bigintMax(
|
|
235
|
+
0n,
|
|
236
|
+
((currentTime - sched.vestedAtTime) / vestingFreq + 1n) *
|
|
237
|
+
sched.unlockAmt,
|
|
238
|
+
),
|
|
239
|
+
)
|
|
240
|
+
// If the current time is past the first period in the schedule,
|
|
241
|
+
// at least all INDY from the first period is vested, and can proceed
|
|
242
|
+
// to compute the vested amount for remaining periods.
|
|
243
|
+
.with([P._, P._, ...P.array()], ([sched1, sched2, ...rest]) =>
|
|
244
|
+
currentTime >= sched2.vestedAtTime
|
|
245
|
+
? ((sched2.vestedAtTime - sched1.vestedAtTime) / vestingFreq) *
|
|
246
|
+
sched1.unlockAmt +
|
|
247
|
+
go([sched2, ...rest])
|
|
248
|
+
: bigintMax(
|
|
249
|
+
0n,
|
|
250
|
+
((currentTime - sched1.vestedAtTime) / vestingFreq + 1n) *
|
|
251
|
+
sched1.unlockAmt,
|
|
252
|
+
),
|
|
253
|
+
)
|
|
254
|
+
.run()
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return bigintMin(schedule.maxUnlockable, go(schedule.schedule));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export function calculateTotalVestedRewards(currentTime: bigint): bigint {
|
|
262
|
+
return (
|
|
263
|
+
calculateVestedPerEpoch(spDistributionSchedule, currentTime) +
|
|
264
|
+
calculateVestedPerEpoch(govDistributionSchedule, currentTime) +
|
|
265
|
+
calculateVestedPerEpoch(liqDistributionSchedule, currentTime)
|
|
266
|
+
);
|
|
267
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
export * from './contracts/cdp';
|
|
2
|
-
export * from './contracts/
|
|
3
|
-
export * from './contracts/
|
|
4
|
-
export * from './contracts/
|
|
5
|
-
export * from './contracts/
|
|
6
|
-
export * from './contracts/
|
|
7
|
-
export * from './contracts/
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
11
|
-
export * from './
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
14
|
-
export * from './
|
|
15
|
-
export * from './
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export * from './
|
|
19
|
-
export * from './
|
|
20
|
-
export * from './
|
|
21
|
-
export * from './
|
|
22
|
-
export * from './
|
|
23
|
-
export * from './
|
|
24
|
-
export * from './
|
|
25
|
-
export * from './
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './
|
|
28
|
-
export * from './
|
|
1
|
+
export * from './contracts/cdp/transactions';
|
|
2
|
+
export * from './contracts/cdp/helpers';
|
|
3
|
+
export * from './contracts/cdp/types';
|
|
4
|
+
export * from './contracts/cdp/scripts';
|
|
5
|
+
export * from './contracts/cdp-creator/types';
|
|
6
|
+
export * from './contracts/cdp-creator/scripts';
|
|
7
|
+
export * from './contracts/poll/scripts';
|
|
8
|
+
export * from './contracts/collector/transactions';
|
|
9
|
+
export * from './contracts/gov/transactions';
|
|
10
|
+
export * from './contracts/gov/types';
|
|
11
|
+
export * from './contracts/stability-pool/transactions';
|
|
12
|
+
export * from './contracts/staking/transactions';
|
|
13
|
+
export * from './contracts/interest-oracle/transactions';
|
|
14
|
+
export * from './contracts/interest-oracle/types';
|
|
15
|
+
export * from './contracts/interest-oracle/scripts';
|
|
16
|
+
export * from './contracts/version-registry/types';
|
|
17
|
+
export * from './contracts/version-registry/scripts';
|
|
18
|
+
export * from './contracts/treasury/transactions';
|
|
19
|
+
export * from './utils/utils';
|
|
20
|
+
export * from './utils/lucid-utils';
|
|
21
|
+
export * from './contracts/stability-pool/helpers';
|
|
22
|
+
export * from './utils/time-helpers';
|
|
23
|
+
export * from './contracts/cdp/scripts';
|
|
24
|
+
export * from './contracts/collector/scripts';
|
|
25
|
+
export * from './contracts/treasury/scripts';
|
|
26
|
+
export * from './contracts/execute/types';
|
|
27
|
+
export * from './contracts/execute/scripts';
|
|
28
|
+
export * from './contracts/price-oracle/types';
|
|
29
|
+
export * from './contracts/stability-pool/types';
|
|
30
|
+
export * from './contracts/lrp/types';
|
|
31
|
+
export * from './contracts/poll/types-poll-shard';
|
|
32
|
+
export * from './contracts/poll/types-poll-manager';
|
|
29
33
|
export * from './types/generic';
|
|
30
34
|
export * from './types/system-params';
|
|
31
|
-
export * from './contracts/lrp';
|
|
32
|
-
export * from './
|
|
33
|
-
export * from './
|
|
34
|
-
export * from './contracts/one-shot';
|
|
35
|
-
export * from './
|
|
35
|
+
export * from './contracts/lrp/transactions';
|
|
36
|
+
export * from './contracts/lrp/scripts';
|
|
37
|
+
export * from './utils/helper-txs';
|
|
38
|
+
export * from './contracts/one-shot/transactions';
|
|
39
|
+
export * from './utils/utils';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodecOptions } from '@evolution-sdk/evolution/core/CBOR';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is related to our on-chain codebase for aiken v1.0.26-alpha
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_SCHEMA_OPTIONS = {
|
|
7
|
+
mode: 'custom',
|
|
8
|
+
useIndefiniteArrays: true,
|
|
9
|
+
// This is important to match aiken's Map encoding.
|
|
10
|
+
useIndefiniteMaps: false,
|
|
11
|
+
useDefiniteForEmpty: true,
|
|
12
|
+
sortMapKeys: false,
|
|
13
|
+
useMinimalEncoding: true,
|
|
14
|
+
mapsAsObjects: false,
|
|
15
|
+
encodeMapAsPairs: false,
|
|
16
|
+
} as const satisfies CodecOptions;
|