@indigo-labs/indigo-sdk 0.5.4 → 0.5.6
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/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +17 -0
- package/dist/index.mjs +15 -0
- package/package.json +11 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/ci.yml +0 -66
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -6
- package/eslint.config.mjs +0 -42
- package/scripts/bench.sh +0 -62
- package/scripts/run-repeat.sh +0 -22
- package/src/contracts/cdp/helpers.ts +0 -173
- package/src/contracts/cdp/scripts.ts +0 -70
- package/src/contracts/cdp/transactions.ts +0 -1584
- package/src/contracts/cdp/types-new.ts +0 -277
- package/src/contracts/cdp/types.ts +0 -43
- package/src/contracts/cdp-creator/queries.ts +0 -30
- package/src/contracts/cdp-creator/scripts.ts +0 -45
- package/src/contracts/cdp-creator/types-new.ts +0 -50
- package/src/contracts/cdp-creator/types.ts +0 -24
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -50
- package/src/contracts/collector/types-new.ts +0 -17
- package/src/contracts/execute/scripts.ts +0 -57
- package/src/contracts/execute/types-new.ts +0 -44
- package/src/contracts/execute/types.ts +0 -24
- package/src/contracts/gov/helpers.ts +0 -351
- package/src/contracts/gov/scripts.ts +0 -41
- package/src/contracts/gov/transactions.ts +0 -1607
- package/src/contracts/gov/types-new.ts +0 -268
- package/src/contracts/gov/types.ts +0 -22
- package/src/contracts/iasset/helpers.ts +0 -170
- package/src/contracts/iasset/queries.ts +0 -102
- package/src/contracts/iasset/scripts.ts +0 -38
- package/src/contracts/iasset/types.ts +0 -154
- package/src/contracts/initialize/actions.ts +0 -789
- package/src/contracts/initialize/helpers.ts +0 -616
- package/src/contracts/initialize/types.ts +0 -116
- package/src/contracts/interest-collection/helpers.ts +0 -19
- package/src/contracts/interest-collection/queries.ts +0 -66
- package/src/contracts/interest-collection/scripts.ts +0 -44
- package/src/contracts/interest-collection/transactions.ts +0 -433
- package/src/contracts/interest-collection/types-new.ts +0 -50
- package/src/contracts/interest-collection/types.ts +0 -26
- package/src/contracts/interest-oracle/helpers.ts +0 -61
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -151
- package/src/contracts/interest-oracle/types-new.ts +0 -32
- package/src/contracts/interest-oracle/types.ts +0 -16
- package/src/contracts/one-shot/scripts.ts +0 -12
- package/src/contracts/one-shot/transactions.ts +0 -66
- package/src/contracts/one-shot/types.ts +0 -22
- package/src/contracts/poll/helpers.ts +0 -37
- package/src/contracts/poll/scripts.ts +0 -71
- package/src/contracts/poll/types-poll-manager.ts +0 -20
- package/src/contracts/poll/types-poll-new.ts +0 -196
- package/src/contracts/poll/types-poll-shard.ts +0 -16
- package/src/contracts/price-oracle/helpers.ts +0 -30
- package/src/contracts/price-oracle/scripts.ts +0 -18
- package/src/contracts/price-oracle/transactions.ts +0 -115
- package/src/contracts/price-oracle/types-new.ts +0 -50
- package/src/contracts/price-oracle/types.ts +0 -16
- package/src/contracts/pyth-feed/helpers.ts +0 -82
- package/src/contracts/pyth-feed/scripts.ts +0 -15
- package/src/contracts/pyth-feed/types.ts +0 -181
- package/src/contracts/rob/helpers.ts +0 -666
- package/src/contracts/rob/scripts.ts +0 -35
- package/src/contracts/rob/transactions.ts +0 -423
- package/src/contracts/rob/types-new.ts +0 -128
- package/src/contracts/rob/types.ts +0 -16
- package/src/contracts/rob-leverage/helpers.ts +0 -422
- package/src/contracts/rob-leverage/transactions.ts +0 -368
- package/src/contracts/stability-pool/helpers.ts +0 -798
- package/src/contracts/stability-pool/queries.ts +0 -132
- package/src/contracts/stability-pool/scripts.ts +0 -51
- package/src/contracts/stability-pool/transactions.ts +0 -921
- package/src/contracts/stability-pool/types-new.ts +0 -385
- package/src/contracts/stability-pool/types.ts +0 -25
- package/src/contracts/stableswap/helpers.ts +0 -507
- package/src/contracts/stableswap/scripts.ts +0 -37
- package/src/contracts/stableswap/transactions.ts +0 -475
- package/src/contracts/stableswap/types-new.ts +0 -131
- package/src/contracts/stableswap/types.ts +0 -17
- package/src/contracts/staking/helpers.ts +0 -136
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -349
- package/src/contracts/staking/types-new.ts +0 -137
- package/src/contracts/staking/types.ts +0 -17
- package/src/contracts/treasury/helpers.ts +0 -21
- package/src/contracts/treasury/queries.ts +0 -100
- package/src/contracts/treasury/scripts.ts +0 -27
- package/src/contracts/treasury/transactions.ts +0 -334
- package/src/contracts/treasury/types-new.ts +0 -69
- package/src/contracts/treasury/types.ts +0 -14
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -18
- package/src/contracts/version-registry/types.ts +0 -17
- package/src/index.ts +0 -93
- package/src/scripts/always-fail-validator.ts +0 -7
- package/src/scripts/auth-token-policy.ts +0 -24
- package/src/scripts/iasset-policy.ts +0 -23
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/types/generic.ts +0 -52
- package/src/types/multisig.ts +0 -48
- package/src/types/on-chain-decimal.ts +0 -57
- package/src/types/rational.ts +0 -61
- package/src/types/system-params.ts +0 -463
- package/src/utils/array-utils.ts +0 -108
- package/src/utils/bigint-utils.ts +0 -35
- package/src/utils/helper-txs.ts +0 -31
- package/src/utils/indigo-helpers.ts +0 -17
- package/src/utils/lucid-utils.ts +0 -125
- package/src/utils/oracle-helpers.ts +0 -62
- package/src/utils/pyth/decode.ts +0 -223
- package/src/utils/pyth/encode.ts +0 -262
- package/src/utils/pyth/index.ts +0 -14
- package/src/utils/pyth/types.ts +0 -87
- package/src/utils/time-helpers.ts +0 -4
- package/src/utils/utils.ts +0 -25
- package/src/validators/always-succeed-validator.ts +0 -6
- package/src/validators/cdp-creator-validator.ts +0 -7
- package/src/validators/cdp-redeem-validator.ts +0 -7
- package/src/validators/cdp-validator.ts +0 -7
- package/src/validators/collector-validator.ts +0 -7
- package/src/validators/execute-validator.ts +0 -7
- package/src/validators/governance-validator.ts +0 -7
- package/src/validators/iasset-validator.ts +0 -7
- package/src/validators/interest-collection-validator.ts +0 -7
- package/src/validators/interest-oracle-validator.ts +0 -7
- package/src/validators/one-shot-policy.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/poll-shard-validator.ts +0 -7
- package/src/validators/price-oracle-validator.ts +0 -7
- package/src/validators/pyth-feed-validator.ts +0 -7
- package/src/validators/rob-validator.ts +0 -7
- package/src/validators/stability-pool-validator.ts +0 -7
- package/src/validators/stableswap-validator.ts +0 -7
- package/src/validators/staking-validator.ts +0 -7
- package/src/validators/treasury-validator.ts +0 -7
- package/src/validators/version-record-policy.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/always-succeed/script.ts +0 -7
- package/tests/array-utils.test.ts +0 -92
- package/tests/bigint-utils.test.ts +0 -41
- package/tests/cdp/actions.ts +0 -680
- package/tests/cdp/cdp-helpers.ts +0 -55
- package/tests/cdp/cdp-queries.ts +0 -423
- package/tests/cdp/cdp.test.ts +0 -6730
- package/tests/cdp/transactions-mutated.ts +0 -1733
- package/tests/data/system-params.json +0 -1155
- package/tests/datums.test.ts +0 -302
- package/tests/endpoints/initialize.ts +0 -78
- package/tests/endpoints/interest-collector.ts +0 -37
- package/tests/endpoints/treasury.ts +0 -70
- package/tests/gov/actions.ts +0 -381
- package/tests/gov/gov.test.ts +0 -5147
- package/tests/gov/governance-queries.ts +0 -37
- package/tests/hash-checks.test.ts +0 -112
- package/tests/indigo-test-helpers.ts +0 -99
- package/tests/initialize.test.ts +0 -79
- package/tests/interest-calculations.test.ts +0 -120
- package/tests/interest-collection/interest-collection.test.ts +0 -843
- package/tests/interest-collection/transactions-mutated.ts +0 -260
- package/tests/interest-oracle.test.ts +0 -93
- package/tests/mock/assets-mock.ts +0 -243
- package/tests/mock/protocol-params-mock.ts +0 -21
- package/tests/price-oracle/actions.ts +0 -161
- package/tests/price-oracle/price-oracle-queries.ts +0 -12
- package/tests/price-oracle/price-oracle.test.ts +0 -228
- package/tests/price-oracle/transactions-mutated.ts +0 -59
- package/tests/pyth/endpoints.ts +0 -96
- package/tests/pyth/helpers.ts +0 -37
- package/tests/pyth/pyth-encoding.test.ts +0 -376
- package/tests/pyth/pyth-feeds.test.ts +0 -943
- package/tests/pyth/pyth-indigo.test.ts +0 -505
- package/tests/pyth/pyth.test.ts +0 -299
- package/tests/queries/collector-queries.ts +0 -27
- package/tests/queries/execute-queries.ts +0 -47
- package/tests/queries/iasset-queries.ts +0 -149
- package/tests/queries/interest-oracle-queries.ts +0 -12
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/staking-queries.ts +0 -54
- package/tests/rob/actions.ts +0 -56
- package/tests/rob/rob-leverage.test.ts +0 -2555
- package/tests/rob/rob-queries.ts +0 -95
- package/tests/rob/rob.test.ts +0 -3677
- package/tests/rob/transactions-mutated.ts +0 -844
- package/tests/script-size.test.ts +0 -240
- package/tests/setup.ts +0 -135
- package/tests/stability-pool/actions.ts +0 -229
- package/tests/stability-pool.test.ts +0 -6491
- package/tests/stableswap/stableswap-actions.ts +0 -83
- package/tests/stableswap/stableswap-queries.ts +0 -98
- package/tests/stableswap/stableswap.test.ts +0 -4471
- package/tests/stableswap/transactions-mutated.ts +0 -348
- package/tests/staking.test.ts +0 -172
- package/tests/test-helpers.ts +0 -94
- package/tests/treasury/actions.ts +0 -67
- package/tests/treasury/treasury.test.ts +0 -320
- package/tests/utils/asserts.ts +0 -87
- package/tests/utils/benchmark-utils.ts +0 -130
- package/tests/utils/index.ts +0 -168
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -27
- package/vitest.config.ts +0 -11
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
|
-
import { MultisigSchema } from '../../types/multisig';
|
|
3
|
-
|
|
4
|
-
const InterestCollectionDatumSchema = TSchema.Struct({
|
|
5
|
-
admin_permissions: MultisigSchema,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
export type InterestCollectionDatum = typeof InterestCollectionDatumSchema.Type;
|
|
9
|
-
|
|
10
|
-
const InterestCollectionRedeemerSchema = TSchema.Union(
|
|
11
|
-
TSchema.Literal('CollectInterest', { flatInUnion: true }),
|
|
12
|
-
TSchema.Struct(
|
|
13
|
-
{
|
|
14
|
-
BatchCollectInterest: TSchema.Struct(
|
|
15
|
-
{
|
|
16
|
-
currentTime: TSchema.Integer,
|
|
17
|
-
ownInputIndex: TSchema.Integer,
|
|
18
|
-
collateralAssetRefInputIndex: TSchema.Integer,
|
|
19
|
-
interestOracleRefInputIndex: TSchema.Integer,
|
|
20
|
-
},
|
|
21
|
-
{ flatFields: true },
|
|
22
|
-
),
|
|
23
|
-
},
|
|
24
|
-
{ flatInUnion: true },
|
|
25
|
-
),
|
|
26
|
-
TSchema.Literal('Distribute', { flatInUnion: true }),
|
|
27
|
-
TSchema.Literal('UpdatePermissions', { flatInUnion: true }),
|
|
28
|
-
TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
export type InterestCollectionRedeemer =
|
|
32
|
-
typeof InterestCollectionRedeemerSchema.Type;
|
|
33
|
-
|
|
34
|
-
export function serialiseInterestCollectionRedeemer(
|
|
35
|
-
redeemer: InterestCollectionRedeemer,
|
|
36
|
-
): string {
|
|
37
|
-
return Data.withSchema(InterestCollectionRedeemerSchema).toCBORHex(redeemer);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function parseInterestCollectionDatum(
|
|
41
|
-
datum: string,
|
|
42
|
-
): InterestCollectionDatum {
|
|
43
|
-
return Data.withSchema(InterestCollectionDatumSchema).fromCBORHex(datum);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function serialiseInterestCollectionDatum(
|
|
47
|
-
datum: InterestCollectionDatum,
|
|
48
|
-
): string {
|
|
49
|
-
return Data.withSchema(InterestCollectionDatumSchema).toCBORHex(datum);
|
|
50
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
-
|
|
4
|
-
export const InterestCollectionParamsSchema = Data.Object({
|
|
5
|
-
versionRecordNft: AssetClassSchema,
|
|
6
|
-
multisigUtxoNft: AssetClassSchema,
|
|
7
|
-
cdpAuthTk: AssetClassSchema,
|
|
8
|
-
collateralAssetAuthTk: AssetClassSchema,
|
|
9
|
-
govAuthTk: AssetClassSchema,
|
|
10
|
-
cdpAssetSymbol: Data.Bytes(),
|
|
11
|
-
cdpBiasTime: Data.Integer(),
|
|
12
|
-
interestSettlementCooldown: Data.Integer(),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export type InterestCollectionParams = Data.Static<
|
|
16
|
-
typeof InterestCollectionParamsSchema
|
|
17
|
-
>;
|
|
18
|
-
|
|
19
|
-
const InterestCollectionParams =
|
|
20
|
-
InterestCollectionParamsSchema as unknown as InterestCollectionParams;
|
|
21
|
-
|
|
22
|
-
export function castInterestCollectionParams(
|
|
23
|
-
params: InterestCollectionParams,
|
|
24
|
-
): Data {
|
|
25
|
-
return Data.castTo(params, InterestCollectionParams);
|
|
26
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { ONE_YEAR } from '../../utils/time-helpers';
|
|
2
|
-
import { OCD_DECIMAL_UNIT } from '../../types/on-chain-decimal';
|
|
3
|
-
import { InterestOracleDatum } from './types-new';
|
|
4
|
-
|
|
5
|
-
const unitaryInterestPrecision = 1_000_000_000_000_000_000n;
|
|
6
|
-
|
|
7
|
-
export function calculateUnitaryInterest(
|
|
8
|
-
timePeriod: bigint,
|
|
9
|
-
interestRate: bigint,
|
|
10
|
-
): bigint {
|
|
11
|
-
return (
|
|
12
|
-
(timePeriod * interestRate * unitaryInterestPrecision) /
|
|
13
|
-
ONE_YEAR /
|
|
14
|
-
OCD_DECIMAL_UNIT
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function calculateUnitaryInterestSinceOracleLastUpdated(
|
|
19
|
-
now: bigint,
|
|
20
|
-
oracleDatum: InterestOracleDatum,
|
|
21
|
-
): bigint {
|
|
22
|
-
return calculateUnitaryInterest(
|
|
23
|
-
now - oracleDatum.lastUpdated,
|
|
24
|
-
oracleDatum.interestRate.getOnChainInt,
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function calculateAccruedInterest(
|
|
29
|
-
/**
|
|
30
|
-
* Should be ideally the result of the following: lucid.slotToUnixTime(lucid.currentSlot()).
|
|
31
|
-
* Otherwise, the unix timestamp should suffice, but might not be 100% precise as on-chain.
|
|
32
|
-
*/
|
|
33
|
-
now: bigint,
|
|
34
|
-
unitaryInterestSnapshot: bigint,
|
|
35
|
-
mintedAmount: bigint,
|
|
36
|
-
interestLastSettled: bigint,
|
|
37
|
-
interestOracleDatum: InterestOracleDatum,
|
|
38
|
-
): bigint {
|
|
39
|
-
if (interestOracleDatum.unitaryInterest >= unitaryInterestSnapshot) {
|
|
40
|
-
const interestFromPreviousRates =
|
|
41
|
-
((interestOracleDatum.unitaryInterest - unitaryInterestSnapshot) *
|
|
42
|
-
mintedAmount) /
|
|
43
|
-
unitaryInterestPrecision;
|
|
44
|
-
const lastRateInterest =
|
|
45
|
-
((now - interestOracleDatum.lastUpdated) *
|
|
46
|
-
interestOracleDatum.interestRate.getOnChainInt *
|
|
47
|
-
mintedAmount) /
|
|
48
|
-
ONE_YEAR /
|
|
49
|
-
OCD_DECIMAL_UNIT;
|
|
50
|
-
|
|
51
|
-
return interestFromPreviousRates + lastRateInterest;
|
|
52
|
-
} else {
|
|
53
|
-
return (
|
|
54
|
-
((now - interestLastSettled) *
|
|
55
|
-
interestOracleDatum.interestRate.getOnChainInt *
|
|
56
|
-
mintedAmount) /
|
|
57
|
-
ONE_YEAR /
|
|
58
|
-
OCD_DECIMAL_UNIT
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -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: 'PlutusV3',
|
|
14
|
-
script: applyParamsToScript(_interestOracleValidator.cborHex, [
|
|
15
|
-
castInterestOracleParams(params),
|
|
16
|
-
]),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fromHex,
|
|
3
|
-
fromText,
|
|
4
|
-
LucidEvolution,
|
|
5
|
-
OutRef,
|
|
6
|
-
toUnit,
|
|
7
|
-
TxBuilder,
|
|
8
|
-
UTxO,
|
|
9
|
-
validatorToAddress,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import { InterestOracleParams } from './types';
|
|
12
|
-
import { oneShotMintTx } from '../one-shot/transactions';
|
|
13
|
-
import { mkInterestOracleValidator } from './scripts';
|
|
14
|
-
import { findInterestOracle } from '../../../tests/queries/interest-oracle-queries';
|
|
15
|
-
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
16
|
-
import { calculateUnitaryInterestSinceOracleLastUpdated } from '../interest-oracle/helpers';
|
|
17
|
-
import { getInlineDatumOrThrow } from '../../utils/lucid-utils';
|
|
18
|
-
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
19
|
-
import {
|
|
20
|
-
parseInterestOracleDatum,
|
|
21
|
-
serialiseFeedInterestOracleRedeemer,
|
|
22
|
-
serialiseInterestOracleDatum,
|
|
23
|
-
} from './types-new';
|
|
24
|
-
|
|
25
|
-
export async function startInterestOracle(
|
|
26
|
-
initialUnitaryInterest: bigint,
|
|
27
|
-
initialInterestRate: bigint,
|
|
28
|
-
initialLastInterestUpdate: bigint,
|
|
29
|
-
oracleParams: InterestOracleParams,
|
|
30
|
-
lucid: LucidEvolution,
|
|
31
|
-
interestTokenName?: string,
|
|
32
|
-
withScriptRef: boolean = false,
|
|
33
|
-
refOutRef?: OutRef,
|
|
34
|
-
): Promise<[TxBuilder, AssetClass]> {
|
|
35
|
-
const network = lucid.config().network!;
|
|
36
|
-
|
|
37
|
-
const tokenName = interestTokenName ?? 'INTEREST_ORACLE';
|
|
38
|
-
if (!refOutRef) {
|
|
39
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
43
|
-
referenceOutRef: {
|
|
44
|
-
txHash: refOutRef.txHash,
|
|
45
|
-
outputIdx: BigInt(refOutRef.outputIndex),
|
|
46
|
-
},
|
|
47
|
-
mintAmounts: [
|
|
48
|
-
{
|
|
49
|
-
tokenName: fromText(tokenName),
|
|
50
|
-
amount: 1n,
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const validator = mkInterestOracleValidator(oracleParams);
|
|
56
|
-
|
|
57
|
-
tx.pay.ToContract(
|
|
58
|
-
validatorToAddress(network, validator),
|
|
59
|
-
{
|
|
60
|
-
kind: 'inline',
|
|
61
|
-
value: serialiseInterestOracleDatum({
|
|
62
|
-
unitaryInterest: initialUnitaryInterest,
|
|
63
|
-
interestRate: {
|
|
64
|
-
getOnChainInt: initialInterestRate,
|
|
65
|
-
},
|
|
66
|
-
lastUpdated: initialLastInterestUpdate,
|
|
67
|
-
}),
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
lovelace: 2_500_000n,
|
|
71
|
-
[toUnit(policyId, fromText(tokenName))]: 1n,
|
|
72
|
-
},
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
if (withScriptRef) {
|
|
76
|
-
tx.pay.ToAddressWithData(
|
|
77
|
-
validatorToAddress(network, validator),
|
|
78
|
-
undefined,
|
|
79
|
-
undefined,
|
|
80
|
-
validator,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return [
|
|
85
|
-
tx,
|
|
86
|
-
{
|
|
87
|
-
currencySymbol: fromHex(policyId),
|
|
88
|
-
tokenName: fromHex(fromText(tokenName)),
|
|
89
|
-
},
|
|
90
|
-
];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function feedInterestOracle(
|
|
94
|
-
params: InterestOracleParams,
|
|
95
|
-
newInterestRate: bigint,
|
|
96
|
-
lucid: LucidEvolution,
|
|
97
|
-
assetClass?: AssetClass,
|
|
98
|
-
utxo?: UTxO,
|
|
99
|
-
scriptRef?: UTxO,
|
|
100
|
-
): Promise<TxBuilder> {
|
|
101
|
-
if (!assetClass && !utxo)
|
|
102
|
-
throw new Error('Either interest oracle nft or utxo must be provided');
|
|
103
|
-
if (assetClass && !utxo) {
|
|
104
|
-
utxo = await findInterestOracle(lucid, assetClass);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
108
|
-
|
|
109
|
-
const tx = lucid.newTx();
|
|
110
|
-
const datum = parseInterestOracleDatum(getInlineDatumOrThrow(utxo!));
|
|
111
|
-
|
|
112
|
-
if (scriptRef) {
|
|
113
|
-
tx.readFrom([scriptRef]);
|
|
114
|
-
} else {
|
|
115
|
-
tx.attach.Script(mkInterestOracleValidator(params));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
tx.collectFrom(
|
|
119
|
-
[utxo!],
|
|
120
|
-
serialiseFeedInterestOracleRedeemer({
|
|
121
|
-
newInterestRate: {
|
|
122
|
-
getOnChainInt: newInterestRate,
|
|
123
|
-
},
|
|
124
|
-
currentTime: now,
|
|
125
|
-
}),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
tx.pay.ToContract(
|
|
129
|
-
utxo!.address,
|
|
130
|
-
{
|
|
131
|
-
kind: 'inline',
|
|
132
|
-
value: serialiseInterestOracleDatum({
|
|
133
|
-
unitaryInterest:
|
|
134
|
-
datum.unitaryInterest +
|
|
135
|
-
calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
|
|
136
|
-
interestRate: {
|
|
137
|
-
getOnChainInt: newInterestRate,
|
|
138
|
-
},
|
|
139
|
-
lastUpdated: now,
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
utxo!.assets,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
tx.validFrom(Number(now) - ONE_SECOND);
|
|
146
|
-
tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
|
|
147
|
-
|
|
148
|
-
tx.addSignerKey(params.owner);
|
|
149
|
-
|
|
150
|
-
return tx;
|
|
151
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
|
-
import { OnChainDecimalSchema } from '../../types/on-chain-decimal';
|
|
3
|
-
|
|
4
|
-
export const InterestOracleDatumSchema = TSchema.Struct({
|
|
5
|
-
unitaryInterest: TSchema.Integer,
|
|
6
|
-
interestRate: OnChainDecimalSchema,
|
|
7
|
-
lastUpdated: TSchema.Integer,
|
|
8
|
-
});
|
|
9
|
-
export type InterestOracleDatum = typeof InterestOracleDatumSchema.Type;
|
|
10
|
-
|
|
11
|
-
const InterestOracleRedeemerSchema = TSchema.Struct({
|
|
12
|
-
newInterestRate: OnChainDecimalSchema,
|
|
13
|
-
currentTime: TSchema.Integer,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export type InterestOracleRedeemer = typeof InterestOracleRedeemerSchema.Type;
|
|
17
|
-
|
|
18
|
-
export function serialiseFeedInterestOracleRedeemer(
|
|
19
|
-
redeemer: InterestOracleRedeemer,
|
|
20
|
-
): string {
|
|
21
|
-
return Data.withSchema(InterestOracleRedeemerSchema).toCBORHex(redeemer);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function parseInterestOracleDatum(datum: string): InterestOracleDatum {
|
|
25
|
-
return Data.withSchema(InterestOracleDatumSchema).fromCBORHex(datum);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function serialiseInterestOracleDatum(
|
|
29
|
-
datum: InterestOracleDatum,
|
|
30
|
-
): string {
|
|
31
|
-
return Data.withSchema(InterestOracleDatumSchema).toCBORHex(datum);
|
|
32
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
|
|
3
|
-
export const InterestOracleParamsSchema = Data.Object({
|
|
4
|
-
/** Milliseconds */
|
|
5
|
-
biasTime: Data.Integer(),
|
|
6
|
-
owner: Data.Bytes(),
|
|
7
|
-
});
|
|
8
|
-
export type InterestOracleParams = Data.Static<
|
|
9
|
-
typeof InterestOracleParamsSchema
|
|
10
|
-
>;
|
|
11
|
-
const InterestOracleParams =
|
|
12
|
-
InterestOracleParamsSchema as unknown as InterestOracleParams;
|
|
13
|
-
|
|
14
|
-
export function castInterestOracleParams(params: InterestOracleParams): Data {
|
|
15
|
-
return Data.castTo(params, InterestOracleParams);
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { applyParamsToScript, MintingPolicy } from '@lucid-evolution/lucid';
|
|
2
|
-
import { castOneShotParams, OneShotParams } from './types';
|
|
3
|
-
import { _oneShotPolicy } from '../../validators/one-shot-policy';
|
|
4
|
-
|
|
5
|
-
export function mkOneShotPolicy(params: OneShotParams): MintingPolicy {
|
|
6
|
-
return {
|
|
7
|
-
type: 'PlutusV3',
|
|
8
|
-
script: applyParamsToScript(_oneShotPolicy.cborHex, [
|
|
9
|
-
castOneShotParams(params),
|
|
10
|
-
]),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Assets,
|
|
4
|
-
Data,
|
|
5
|
-
LucidEvolution,
|
|
6
|
-
mintingPolicyToId,
|
|
7
|
-
PolicyId,
|
|
8
|
-
toUnit,
|
|
9
|
-
TxBuilder,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import { OneShotParams } from './types';
|
|
12
|
-
import { matchSingle } from '../../utils/utils';
|
|
13
|
-
import { mkOneShotPolicy } from './scripts';
|
|
14
|
-
import { reduce } from 'fp-ts/lib/Array';
|
|
15
|
-
|
|
16
|
-
export async function oneShotMintTx(
|
|
17
|
-
lucid: LucidEvolution,
|
|
18
|
-
params: OneShotParams,
|
|
19
|
-
): Promise<[TxBuilder, PolicyId]> {
|
|
20
|
-
const oneShotPolicy = mkOneShotPolicy(params);
|
|
21
|
-
const policyId = mintingPolicyToId(oneShotPolicy);
|
|
22
|
-
|
|
23
|
-
const refUtxo = matchSingle(
|
|
24
|
-
await lucid.utxosByOutRef([
|
|
25
|
-
{
|
|
26
|
-
txHash: params.referenceOutRef.txHash,
|
|
27
|
-
outputIndex: Number(params.referenceOutRef.outputIdx),
|
|
28
|
-
},
|
|
29
|
-
]),
|
|
30
|
-
(_) => {
|
|
31
|
-
throw new Error('Cannot find the reference UTXO for one-shot.');
|
|
32
|
-
},
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
return [
|
|
36
|
-
lucid
|
|
37
|
-
.newTx()
|
|
38
|
-
.collectFrom([refUtxo])
|
|
39
|
-
.mintAssets(
|
|
40
|
-
reduce<{ tokenName: string; amount: bigint }, Assets>(
|
|
41
|
-
{},
|
|
42
|
-
(acc, entry) =>
|
|
43
|
-
addAssets(acc, {
|
|
44
|
-
[toUnit(policyId, entry.tokenName)]: entry.amount,
|
|
45
|
-
}),
|
|
46
|
-
)(params.mintAmounts),
|
|
47
|
-
Data.void(),
|
|
48
|
-
)
|
|
49
|
-
.attach.MintingPolicy(oneShotPolicy),
|
|
50
|
-
policyId,
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function runOneShotMintTx(
|
|
55
|
-
lucid: LucidEvolution,
|
|
56
|
-
params: OneShotParams,
|
|
57
|
-
): Promise<PolicyId> {
|
|
58
|
-
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
59
|
-
const txHash = await tx
|
|
60
|
-
.complete()
|
|
61
|
-
.then((tx) => tx.sign.withWallet().complete())
|
|
62
|
-
.then((tx) => tx.submit());
|
|
63
|
-
|
|
64
|
-
await lucid.awaitTx(txHash);
|
|
65
|
-
return policyId;
|
|
66
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
|
|
3
|
-
export const OneShotParamsSchema = Data.Object({
|
|
4
|
-
referenceOutRef: Data.Object({
|
|
5
|
-
txHash: Data.Bytes(),
|
|
6
|
-
outputIdx: Data.Integer(),
|
|
7
|
-
}),
|
|
8
|
-
mintAmounts: Data.Array(
|
|
9
|
-
Data.Object({
|
|
10
|
-
/// Use hex encoded string
|
|
11
|
-
tokenName: Data.Bytes(),
|
|
12
|
-
amount: Data.Integer(),
|
|
13
|
-
}),
|
|
14
|
-
),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export type OneShotParams = Data.Static<typeof OneShotParamsSchema>;
|
|
18
|
-
const OneShotParams = OneShotParamsSchema as unknown as OneShotParams;
|
|
19
|
-
|
|
20
|
-
export function castOneShotParams(params: OneShotParams): Data {
|
|
21
|
-
return Data.castTo(params, OneShotParams);
|
|
22
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ocdDiv, OnChainDecimal } from '../../types/on-chain-decimal';
|
|
2
|
-
import { PollStatus } from './types-poll-new';
|
|
3
|
-
|
|
4
|
-
function q(pollStatus: PollStatus, e: bigint): OnChainDecimal {
|
|
5
|
-
if (pollStatus.yesVotes + pollStatus.noVotes === 0n)
|
|
6
|
-
return { getOnChainInt: 0n };
|
|
7
|
-
else {
|
|
8
|
-
const q =
|
|
9
|
-
ocdDiv(
|
|
10
|
-
{ getOnChainInt: pollStatus.yesVotes },
|
|
11
|
-
{ getOnChainInt: BigInt(Math.floor(Math.sqrt(Number(e)))) },
|
|
12
|
-
).getOnChainInt -
|
|
13
|
-
ocdDiv(
|
|
14
|
-
{ getOnChainInt: pollStatus.noVotes },
|
|
15
|
-
{
|
|
16
|
-
getOnChainInt: BigInt(
|
|
17
|
-
Math.floor(
|
|
18
|
-
Math.sqrt(Number(pollStatus.yesVotes + pollStatus.noVotes)),
|
|
19
|
-
),
|
|
20
|
-
),
|
|
21
|
-
},
|
|
22
|
-
).getOnChainInt;
|
|
23
|
-
|
|
24
|
-
return { getOnChainInt: BigInt(q) };
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function pollPassQuorum(
|
|
29
|
-
pollStatus: PollStatus,
|
|
30
|
-
electorate: bigint,
|
|
31
|
-
minQuorum: bigint,
|
|
32
|
-
): boolean {
|
|
33
|
-
return (
|
|
34
|
-
pollStatus.yesVotes + pollStatus.noVotes >= minQuorum &&
|
|
35
|
-
q(pollStatus, electorate).getOnChainInt > 50_000n
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,71 +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
|
-
fromSystemParamsAssetLucid,
|
|
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: 'PlutusV3',
|
|
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: 'PlutusV3',
|
|
31
|
-
script: applyParamsToScript(_pollManagerValidator.cborHex, [
|
|
32
|
-
castPollManagerParams({
|
|
33
|
-
govNFT: fromSystemParamsAssetLucid(params.govNFT),
|
|
34
|
-
pollToken: fromSystemParamsAssetLucid(params.pollToken),
|
|
35
|
-
upgradeToken: fromSystemParamsAssetLucid(params.upgradeToken),
|
|
36
|
-
indyAsset: fromSystemParamsAssetLucid(params.indyAsset),
|
|
37
|
-
govExecuteValHash: params.govExecuteValHash,
|
|
38
|
-
pBiasTime: BigInt(params.pBiasTime),
|
|
39
|
-
shardValHash: params.shardsValHash,
|
|
40
|
-
treasuryValHash: params.treasuryValHash,
|
|
41
|
-
}),
|
|
42
|
-
]),
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const mkPollShardValidator = (
|
|
47
|
-
params: PollShardParams,
|
|
48
|
-
): SpendingValidator => {
|
|
49
|
-
return {
|
|
50
|
-
type: 'PlutusV3',
|
|
51
|
-
script: applyParamsToScript(_pollShardValidator.cborHex, [
|
|
52
|
-
castPollShardParams(params),
|
|
53
|
-
]),
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const mkPollShardValidatorFromSP = (
|
|
58
|
-
params: PollShardParamsSP,
|
|
59
|
-
): SpendingValidator => {
|
|
60
|
-
return {
|
|
61
|
-
type: 'PlutusV3',
|
|
62
|
-
script: applyParamsToScript(_pollShardValidator.cborHex, [
|
|
63
|
-
castPollShardParams({
|
|
64
|
-
pollToken: fromSystemParamsAssetLucid(params.pollToken),
|
|
65
|
-
stakingToken: fromSystemParamsAssetLucid(params.stakingToken),
|
|
66
|
-
indyAsset: fromSystemParamsAssetLucid(params.indyAsset),
|
|
67
|
-
stakingValHash: params.stakingValHash,
|
|
68
|
-
}),
|
|
69
|
-
]),
|
|
70
|
-
};
|
|
71
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Data } 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
|
-
});
|
|
14
|
-
export type PollManagerParams = Data.Static<typeof PollManagerParamsSchema>;
|
|
15
|
-
export const PollManagerParams =
|
|
16
|
-
PollManagerParamsSchema as unknown as PollManagerParams;
|
|
17
|
-
|
|
18
|
-
export function castPollManagerParams(params: PollManagerParams): Data {
|
|
19
|
-
return Data.castTo(params, PollManagerParams);
|
|
20
|
-
}
|