@indigo-labs/indigo-sdk 0.1.20 → 0.1.22
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 +678 -1001
- package/dist/index.d.ts +678 -1001
- package/dist/index.js +2272 -4670
- package/dist/index.mjs +2234 -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 +57 -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 -37
- 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,112 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
fromText,
|
|
4
|
-
LucidEvolution,
|
|
5
|
-
OutRef,
|
|
6
|
-
slotToUnixTime,
|
|
7
|
-
TxBuilder,
|
|
8
|
-
validatorToAddress,
|
|
9
|
-
} from '@lucid-evolution/lucid';
|
|
10
|
-
import { AssetClass } from '../../types/generic';
|
|
11
|
-
import {
|
|
12
|
-
OracleAssetNft,
|
|
13
|
-
PriceOracleDatum,
|
|
14
|
-
PriceOracleParams,
|
|
15
|
-
serialisePriceOracleDatum,
|
|
16
|
-
serialisePriceOracleRedeemer,
|
|
17
|
-
} from './types';
|
|
18
|
-
import { mkPriceOracleValidator } from './scripts';
|
|
19
|
-
import { oneShotMintTx } from '../one-shot/transactions';
|
|
20
|
-
import { mkAssetsOf, mkLovelacesOf } from '../../utils/value-helpers';
|
|
21
|
-
import { OnChainDecimal } from '../../types/on-chain-decimal';
|
|
22
|
-
import { matchSingle } from '../../utils/utils';
|
|
23
|
-
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
24
|
-
|
|
25
|
-
export async function startPriceOracleTx(
|
|
26
|
-
lucid: LucidEvolution,
|
|
27
|
-
assetName: string,
|
|
28
|
-
startPrice: OnChainDecimal,
|
|
29
|
-
oracleParams: PriceOracleParams,
|
|
30
|
-
now: number = Date.now(),
|
|
31
|
-
refOutRef?: OutRef,
|
|
32
|
-
): Promise<[TxBuilder, OracleAssetNft]> {
|
|
33
|
-
if (!refOutRef) {
|
|
34
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const [tx, oracleNftPolicyId] = await oneShotMintTx(lucid, {
|
|
38
|
-
referenceOutRef: {
|
|
39
|
-
txHash: refOutRef.txHash,
|
|
40
|
-
outputIdx: BigInt(refOutRef.outputIndex),
|
|
41
|
-
},
|
|
42
|
-
mintAmounts: [
|
|
43
|
-
{
|
|
44
|
-
tokenName: fromText(assetName),
|
|
45
|
-
amount: 1n,
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const priceOracleNft: AssetClass = {
|
|
51
|
-
currencySymbol: oracleNftPolicyId,
|
|
52
|
-
tokenName: fromText(assetName),
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
56
|
-
|
|
57
|
-
const oracleDatum: PriceOracleDatum = {
|
|
58
|
-
price: startPrice,
|
|
59
|
-
expiration: BigInt(now) + oracleParams.expiration,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
tx.pay.ToContract(
|
|
63
|
-
validatorToAddress(lucid.config().network!, oracleValidator),
|
|
64
|
-
{ kind: 'inline', value: serialisePriceOracleDatum(oracleDatum) },
|
|
65
|
-
addAssets(mkLovelacesOf(5_000_000n), mkAssetsOf(priceOracleNft, 1n)),
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return [tx, { oracleNft: priceOracleNft }];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function feedPriceOracleTx(
|
|
72
|
-
lucid: LucidEvolution,
|
|
73
|
-
oracleOref: OutRef,
|
|
74
|
-
newPrice: OnChainDecimal,
|
|
75
|
-
oracleParams: PriceOracleParams,
|
|
76
|
-
currentSlot: number,
|
|
77
|
-
): Promise<TxBuilder> {
|
|
78
|
-
const network = lucid.config().network!;
|
|
79
|
-
const currentTime = BigInt(slotToUnixTime(network, currentSlot));
|
|
80
|
-
|
|
81
|
-
const priceOracleUtxo = matchSingle(
|
|
82
|
-
await lucid.utxosByOutRef([oracleOref]),
|
|
83
|
-
(_) => new Error('Expected a single price oracle UTXO'),
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
87
|
-
|
|
88
|
-
return lucid
|
|
89
|
-
.newTx()
|
|
90
|
-
.validFrom(Number(currentTime - oracleParams.biasTime) + ONE_SECOND)
|
|
91
|
-
.validTo(Number(currentTime + oracleParams.biasTime) - ONE_SECOND)
|
|
92
|
-
.attach.SpendingValidator(oracleValidator)
|
|
93
|
-
.collectFrom(
|
|
94
|
-
[priceOracleUtxo],
|
|
95
|
-
serialisePriceOracleRedeemer({
|
|
96
|
-
currentTime: currentTime,
|
|
97
|
-
newPrice: newPrice,
|
|
98
|
-
}),
|
|
99
|
-
)
|
|
100
|
-
.pay.ToContract(
|
|
101
|
-
priceOracleUtxo.address,
|
|
102
|
-
{
|
|
103
|
-
kind: 'inline',
|
|
104
|
-
value: serialisePriceOracleDatum({
|
|
105
|
-
price: newPrice,
|
|
106
|
-
expiration: currentTime + oracleParams.expiration,
|
|
107
|
-
}),
|
|
108
|
-
},
|
|
109
|
-
priceOracleUtxo.assets,
|
|
110
|
-
)
|
|
111
|
-
.addSignerKey(oracleParams.owner);
|
|
112
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
-
import { castStabilityPoolParams, StabilityPoolParams } from './types';
|
|
3
|
-
import {
|
|
4
|
-
fromSystemParamsAsset,
|
|
5
|
-
StabilityPoolParamsSP,
|
|
6
|
-
} from '../../types/system-params';
|
|
7
|
-
import { _stabilityPoolValidator } from '../../validators/stability-pool-validator';
|
|
8
|
-
|
|
9
|
-
export const mkStabilityPoolValidator = (
|
|
10
|
-
params: StabilityPoolParams,
|
|
11
|
-
): SpendingValidator => {
|
|
12
|
-
return {
|
|
13
|
-
type: 'PlutusV2',
|
|
14
|
-
script: applyParamsToScript(_stabilityPoolValidator.cborHex, [
|
|
15
|
-
castStabilityPoolParams(params),
|
|
16
|
-
]),
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const mkStabilityPoolValidatorFromSP = (
|
|
21
|
-
params: StabilityPoolParamsSP,
|
|
22
|
-
): SpendingValidator => {
|
|
23
|
-
return {
|
|
24
|
-
type: 'PlutusV2',
|
|
25
|
-
script: applyParamsToScript(_stabilityPoolValidator.cborHex, [
|
|
26
|
-
castStabilityPoolParams({
|
|
27
|
-
assetSymbol: params.assetSymbol.unCurrencySymbol,
|
|
28
|
-
stabilityPoolToken: fromSystemParamsAsset(params.stabilityPoolToken),
|
|
29
|
-
snapshotEpochToScaleToSumToken: fromSystemParamsAsset(
|
|
30
|
-
params.snapshotEpochToScaleToSumToken,
|
|
31
|
-
),
|
|
32
|
-
accountToken: fromSystemParamsAsset(params.accountToken),
|
|
33
|
-
cdpToken: fromSystemParamsAsset(params.cdpToken),
|
|
34
|
-
iAssetAuthToken: fromSystemParamsAsset(params.iAssetAuthToken),
|
|
35
|
-
versionRecordToken: fromSystemParamsAsset(params.versionRecordToken),
|
|
36
|
-
collectorValHash: params.collectorValHash,
|
|
37
|
-
govNFT: fromSystemParamsAsset(params.govNFT),
|
|
38
|
-
accountCreateFeeLovelaces: BigInt(params.accountCreateFeeLovelaces),
|
|
39
|
-
accountAdjustmentFeeLovelaces: BigInt(
|
|
40
|
-
params.accountAdjustmentFeeLovelaces,
|
|
41
|
-
),
|
|
42
|
-
requestCollateralLovelaces: BigInt(params.requestCollateralLovelaces),
|
|
43
|
-
}),
|
|
44
|
-
]),
|
|
45
|
-
};
|
|
46
|
-
};
|