@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,59 +0,0 @@
|
|
|
1
|
-
export type InitialAsset = {
|
|
2
|
-
name: string;
|
|
3
|
-
priceOracle: {
|
|
4
|
-
tokenName: string;
|
|
5
|
-
startPrice: bigint;
|
|
6
|
-
params: {
|
|
7
|
-
biasTime: bigint;
|
|
8
|
-
expirationTime: bigint;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
initerestOracle: {
|
|
12
|
-
tokenName: string;
|
|
13
|
-
initialInterestRate: bigint;
|
|
14
|
-
params: {
|
|
15
|
-
biasTime: bigint;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
redemptionRatioPercentage: bigint;
|
|
19
|
-
maintenanceRatioPercentage: bigint;
|
|
20
|
-
liquidationRatioPercentage: bigint;
|
|
21
|
-
debtMintingFeePercentage: bigint;
|
|
22
|
-
liquidationProcessingFeePercentage: bigint;
|
|
23
|
-
stabilityPoolWithdrawalFeePercentage: bigint;
|
|
24
|
-
redemptionReimbursementPercentage: bigint;
|
|
25
|
-
redemptionProcessingFeePercentage: bigint;
|
|
26
|
-
interestCollectorPortionPercentage: bigint;
|
|
27
|
-
firstAsset: boolean;
|
|
28
|
-
nextAsset?: string;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const iusdInitialAssetCfg: InitialAsset = {
|
|
32
|
-
name: 'iUSD',
|
|
33
|
-
priceOracle: {
|
|
34
|
-
tokenName: 'iUSD_ORACLE',
|
|
35
|
-
startPrice: 1_000_000n,
|
|
36
|
-
params: {
|
|
37
|
-
biasTime: 120_000n,
|
|
38
|
-
expirationTime: 1_800_000n,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
initerestOracle: {
|
|
42
|
-
tokenName: 'iUSD_ORACLE',
|
|
43
|
-
initialInterestRate: 1_000_000n,
|
|
44
|
-
params: {
|
|
45
|
-
biasTime: 120_000n,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
redemptionRatioPercentage: 200_000_000n,
|
|
49
|
-
maintenanceRatioPercentage: 150_000_000n,
|
|
50
|
-
liquidationRatioPercentage: 120_000_000n,
|
|
51
|
-
debtMintingFeePercentage: 500_000n,
|
|
52
|
-
liquidationProcessingFeePercentage: 2_000_000n,
|
|
53
|
-
stabilityPoolWithdrawalFeePercentage: 500_000n,
|
|
54
|
-
redemptionReimbursementPercentage: 1_000_000n,
|
|
55
|
-
redemptionProcessingFeePercentage: 1_000_000n,
|
|
56
|
-
interestCollectorPortionPercentage: 40_000_000n,
|
|
57
|
-
firstAsset: true,
|
|
58
|
-
nextAsset: undefined,
|
|
59
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Credential,
|
|
3
|
-
fromText,
|
|
4
|
-
LucidEvolution,
|
|
5
|
-
ScriptHash,
|
|
6
|
-
UTxO,
|
|
7
|
-
} from '@lucid-evolution/lucid';
|
|
8
|
-
import {
|
|
9
|
-
AssetClass,
|
|
10
|
-
CDPContent,
|
|
11
|
-
createScriptAddress,
|
|
12
|
-
fromSystemParamsAsset,
|
|
13
|
-
getRandomElement,
|
|
14
|
-
matchSingle,
|
|
15
|
-
parseCdpDatum,
|
|
16
|
-
SystemParams,
|
|
17
|
-
} from '../../src';
|
|
18
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
19
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
20
|
-
|
|
21
|
-
export async function findAllActiveCdps(
|
|
22
|
-
lucid: LucidEvolution,
|
|
23
|
-
sysParams: SystemParams,
|
|
24
|
-
assetAscii: string,
|
|
25
|
-
stakeCred?: Credential,
|
|
26
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }[]> {
|
|
27
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
28
|
-
createScriptAddress(
|
|
29
|
-
lucid.config().network!,
|
|
30
|
-
sysParams.validatorHashes.cdpHash,
|
|
31
|
-
stakeCred,
|
|
32
|
-
),
|
|
33
|
-
assetClassToUnit(fromSystemParamsAsset(sysParams.cdpParams.cdpAuthToken)),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return F.pipe(
|
|
37
|
-
cdpUtxos.map((utxo) =>
|
|
38
|
-
F.pipe(
|
|
39
|
-
O.fromNullable(utxo.datum),
|
|
40
|
-
O.flatMap(parseCdpDatum),
|
|
41
|
-
O.flatMap((datum) => {
|
|
42
|
-
if (datum.iasset === fromText(assetAscii) && datum.cdpOwner) {
|
|
43
|
-
return O.some({ utxo, datum: datum });
|
|
44
|
-
} else {
|
|
45
|
-
return O.none;
|
|
46
|
-
}
|
|
47
|
-
}),
|
|
48
|
-
),
|
|
49
|
-
),
|
|
50
|
-
A.compact,
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function findCdp(
|
|
55
|
-
lucid: LucidEvolution,
|
|
56
|
-
cdpScriptHash: ScriptHash,
|
|
57
|
-
cdpNft: AssetClass,
|
|
58
|
-
ownerPkh: string,
|
|
59
|
-
stakeCred?: Credential,
|
|
60
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }> {
|
|
61
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
62
|
-
createScriptAddress(lucid.config().network!, cdpScriptHash, stakeCred),
|
|
63
|
-
assetClassToUnit(cdpNft),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return matchSingle(
|
|
67
|
-
F.pipe(
|
|
68
|
-
cdpUtxos.map((utxo) =>
|
|
69
|
-
F.pipe(
|
|
70
|
-
O.fromNullable(utxo.datum),
|
|
71
|
-
O.flatMap(parseCdpDatum),
|
|
72
|
-
O.flatMap((datum) => {
|
|
73
|
-
if (datum.cdpOwner === ownerPkh) {
|
|
74
|
-
return O.some({ utxo, datum: datum });
|
|
75
|
-
} else {
|
|
76
|
-
return O.none;
|
|
77
|
-
}
|
|
78
|
-
}),
|
|
79
|
-
),
|
|
80
|
-
),
|
|
81
|
-
A.compact,
|
|
82
|
-
),
|
|
83
|
-
(res) => new Error('Expected a single CDP UTXO.: ' + JSON.stringify(res)),
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export async function findFrozenCDPs(
|
|
88
|
-
lucid: LucidEvolution,
|
|
89
|
-
cdpScriptHash: ScriptHash,
|
|
90
|
-
cdpNft: AssetClass,
|
|
91
|
-
assetAscii: string,
|
|
92
|
-
): Promise<{ utxo: UTxO; datum: CDPContent }[]> {
|
|
93
|
-
const cdpUtxos = await lucid.utxosAtWithUnit(
|
|
94
|
-
createScriptAddress(lucid.config().network!, cdpScriptHash),
|
|
95
|
-
assetClassToUnit(cdpNft),
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return F.pipe(
|
|
99
|
-
cdpUtxos.map((utxo) =>
|
|
100
|
-
F.pipe(
|
|
101
|
-
O.fromNullable(utxo.datum),
|
|
102
|
-
O.flatMap(parseCdpDatum),
|
|
103
|
-
O.flatMap((datum) => {
|
|
104
|
-
if (datum.cdpOwner == null && datum.iasset === fromText(assetAscii)) {
|
|
105
|
-
return O.some({ utxo, datum: datum });
|
|
106
|
-
} else {
|
|
107
|
-
return O.none;
|
|
108
|
-
}
|
|
109
|
-
}),
|
|
110
|
-
),
|
|
111
|
-
),
|
|
112
|
-
A.compact,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export async function findAllCdpCreators(
|
|
117
|
-
lucid: LucidEvolution,
|
|
118
|
-
cdpCreatorScriptHash: string,
|
|
119
|
-
cdpCreatorNft: AssetClass,
|
|
120
|
-
): Promise<UTxO[]> {
|
|
121
|
-
return lucid.utxosAtWithUnit(
|
|
122
|
-
createScriptAddress(lucid.config().network!, cdpCreatorScriptHash),
|
|
123
|
-
assetClassToUnit(cdpCreatorNft),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function findRandomCdpCreator(
|
|
128
|
-
lucid: LucidEvolution,
|
|
129
|
-
cdpCreatorScriptHash: string,
|
|
130
|
-
cdpCreatorNft: AssetClass,
|
|
131
|
-
): Promise<UTxO> {
|
|
132
|
-
const cdpCreatorUtxos = await findAllCdpCreators(
|
|
133
|
-
lucid,
|
|
134
|
-
cdpCreatorScriptHash,
|
|
135
|
-
cdpCreatorNft,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
return F.pipe(
|
|
139
|
-
O.fromNullable(getRandomElement(cdpCreatorUtxos)),
|
|
140
|
-
O.match(() => {
|
|
141
|
-
throw new Error('Expected some cdp creator UTXOs.');
|
|
142
|
-
}, F.identity),
|
|
143
|
-
);
|
|
144
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { createScriptAddress, getRandomElement } from '../../src';
|
|
3
|
-
import { option as O, function as F } from 'fp-ts';
|
|
4
|
-
|
|
5
|
-
export async function findAllCollectors(
|
|
6
|
-
lucid: LucidEvolution,
|
|
7
|
-
collectorScriptHash: string,
|
|
8
|
-
): Promise<UTxO[]> {
|
|
9
|
-
return lucid.utxosAt(
|
|
10
|
-
createScriptAddress(lucid.config().network!, collectorScriptHash),
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function findRandomCollector(
|
|
15
|
-
lucid: LucidEvolution,
|
|
16
|
-
collectorScriptHash: string,
|
|
17
|
-
): Promise<UTxO> {
|
|
18
|
-
const allCollectors = await findAllCollectors(lucid, collectorScriptHash);
|
|
19
|
-
|
|
20
|
-
return F.pipe(
|
|
21
|
-
O.fromNullable(getRandomElement(allCollectors)),
|
|
22
|
-
O.match(() => {
|
|
23
|
-
throw new Error('Expected some poll shard UTXOs.');
|
|
24
|
-
}, F.identity),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import {
|
|
3
|
-
AssetClass,
|
|
4
|
-
createScriptAddress,
|
|
5
|
-
ExecuteDatum,
|
|
6
|
-
matchSingle,
|
|
7
|
-
parseExecuteDatum,
|
|
8
|
-
} from '../../src';
|
|
9
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
10
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
11
|
-
|
|
12
|
-
export async function findExecute(
|
|
13
|
-
lucid: LucidEvolution,
|
|
14
|
-
executeHash: ScriptHash,
|
|
15
|
-
executeNft: AssetClass,
|
|
16
|
-
upgradeId: bigint,
|
|
17
|
-
): Promise<{
|
|
18
|
-
utxo: UTxO;
|
|
19
|
-
datum: ExecuteDatum;
|
|
20
|
-
}> {
|
|
21
|
-
const executeUtxos = await lucid.utxosAtWithUnit(
|
|
22
|
-
createScriptAddress(lucid.config().network!, executeHash),
|
|
23
|
-
assetClassToUnit(executeNft),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return matchSingle(
|
|
27
|
-
F.pipe(
|
|
28
|
-
executeUtxos.map((utxo) =>
|
|
29
|
-
F.pipe(
|
|
30
|
-
O.fromNullable(utxo.datum),
|
|
31
|
-
O.flatMap(parseExecuteDatum),
|
|
32
|
-
O.flatMap((datum) => {
|
|
33
|
-
if (datum.id === upgradeId) {
|
|
34
|
-
return O.some({ utxo, datum: datum });
|
|
35
|
-
} else {
|
|
36
|
-
return O.none;
|
|
37
|
-
}
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
),
|
|
41
|
-
A.compact,
|
|
42
|
-
),
|
|
43
|
-
(res) =>
|
|
44
|
-
new Error('Expected a single Execute UTXO.: ' + JSON.stringify(res)),
|
|
45
|
-
);
|
|
46
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import {
|
|
3
|
-
parsePollManager,
|
|
4
|
-
parsePollShard,
|
|
5
|
-
PollManagerContent,
|
|
6
|
-
PollShardContent,
|
|
7
|
-
} from '../../src/contracts/poll/types-poll';
|
|
8
|
-
import {
|
|
9
|
-
AssetClass,
|
|
10
|
-
matchSingle,
|
|
11
|
-
createScriptAddress,
|
|
12
|
-
getRandomElement,
|
|
13
|
-
} from '../../src';
|
|
14
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
15
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
16
|
-
|
|
17
|
-
export async function findPollManager(
|
|
18
|
-
lucid: LucidEvolution,
|
|
19
|
-
pollManagerScriptHash: ScriptHash,
|
|
20
|
-
pollManagerNft: AssetClass,
|
|
21
|
-
pollId: bigint,
|
|
22
|
-
): Promise<{ utxo: UTxO; datum: PollManagerContent }> {
|
|
23
|
-
const pollManagerUtxos = await lucid.utxosAtWithUnit(
|
|
24
|
-
createScriptAddress(lucid.config().network!, pollManagerScriptHash),
|
|
25
|
-
assetClassToUnit(pollManagerNft),
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return matchSingle(
|
|
29
|
-
F.pipe(
|
|
30
|
-
pollManagerUtxos.map((utxo) =>
|
|
31
|
-
F.pipe(
|
|
32
|
-
O.fromNullable(utxo.datum),
|
|
33
|
-
O.flatMap(parsePollManager),
|
|
34
|
-
O.flatMap((datum) => {
|
|
35
|
-
if (datum.pollId === pollId) {
|
|
36
|
-
return O.some({ utxo, datum: datum });
|
|
37
|
-
} else {
|
|
38
|
-
return O.none;
|
|
39
|
-
}
|
|
40
|
-
}),
|
|
41
|
-
),
|
|
42
|
-
),
|
|
43
|
-
A.compact,
|
|
44
|
-
),
|
|
45
|
-
(res) => new Error('Expected a single Gov UTXO.: ' + JSON.stringify(res)),
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export async function findAllPollShards(
|
|
50
|
-
lucid: LucidEvolution,
|
|
51
|
-
pollShardScriptHash: string,
|
|
52
|
-
pollShardNft: AssetClass,
|
|
53
|
-
pollId: bigint,
|
|
54
|
-
): Promise<{ utxo: UTxO; datum: PollShardContent }[]> {
|
|
55
|
-
const pollShardUtxos = await lucid.utxosAtWithUnit(
|
|
56
|
-
createScriptAddress(lucid.config().network!, pollShardScriptHash),
|
|
57
|
-
assetClassToUnit(pollShardNft),
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return F.pipe(
|
|
61
|
-
pollShardUtxos.map((utxo) =>
|
|
62
|
-
F.pipe(
|
|
63
|
-
O.fromNullable(utxo.datum),
|
|
64
|
-
O.flatMap(parsePollShard),
|
|
65
|
-
O.flatMap((datum) => {
|
|
66
|
-
if (datum.pollId === pollId) {
|
|
67
|
-
return O.some({ utxo, datum: datum });
|
|
68
|
-
} else {
|
|
69
|
-
return O.none;
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
),
|
|
73
|
-
),
|
|
74
|
-
A.compact,
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function findRandomPollShard(
|
|
79
|
-
lucid: LucidEvolution,
|
|
80
|
-
pollShardScriptHash: string,
|
|
81
|
-
pollShardNft: AssetClass,
|
|
82
|
-
pollId: bigint,
|
|
83
|
-
): Promise<{ utxo: UTxO; datum: PollShardContent }> {
|
|
84
|
-
const pollShardOuts = await findAllPollShards(
|
|
85
|
-
lucid,
|
|
86
|
-
pollShardScriptHash,
|
|
87
|
-
pollShardNft,
|
|
88
|
-
pollId,
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
return F.pipe(
|
|
92
|
-
O.fromNullable(getRandomElement(pollShardOuts)),
|
|
93
|
-
O.match(() => {
|
|
94
|
-
throw new Error('Expected some poll shard UTXOs.');
|
|
95
|
-
}, F.identity),
|
|
96
|
-
);
|
|
97
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { createScriptAddress, getRandomElement } from '../../src';
|
|
3
|
-
import { option as O, function as F } from 'fp-ts';
|
|
4
|
-
|
|
5
|
-
export async function findRandomTreasuryUtxo(
|
|
6
|
-
lucid: LucidEvolution,
|
|
7
|
-
treasuryScriptHash: ScriptHash,
|
|
8
|
-
): Promise<UTxO> {
|
|
9
|
-
const treasuryUtxos = await lucid.utxosAt(
|
|
10
|
-
createScriptAddress(lucid.config().network!, treasuryScriptHash),
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
return F.pipe(
|
|
14
|
-
O.fromNullable(getRandomElement(treasuryUtxos)),
|
|
15
|
-
O.match(() => {
|
|
16
|
-
throw new Error('Expected some treasury UTXOs.');
|
|
17
|
-
}, F.identity),
|
|
18
|
-
);
|
|
19
|
-
}
|
package/tests/utils/asserts.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { assert, expect } from 'vitest';
|
|
2
|
-
|
|
3
|
-
export function assertValueInRange<T extends number | bigint>(
|
|
4
|
-
val: T,
|
|
5
|
-
bounds: { min: T; max: T },
|
|
6
|
-
): void {
|
|
7
|
-
assert(bounds.max > bounds.min, 'Bounds are incorrectly configured.');
|
|
8
|
-
|
|
9
|
-
expect(
|
|
10
|
-
bounds.min <= val && val <= bounds.max,
|
|
11
|
-
`${val} not in range [${bounds.min}, ${bounds.max}]`,
|
|
12
|
-
).toBeTruthy();
|
|
13
|
-
}
|
package/tests/utils/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Assets,
|
|
4
|
-
LucidEvolution,
|
|
5
|
-
UTxO,
|
|
6
|
-
} from '@lucid-evolution/lucid';
|
|
7
|
-
import { array as A } from 'fp-ts';
|
|
8
|
-
import { negateAssets } from '../../src/utils/value-helpers';
|
|
9
|
-
|
|
10
|
-
export async function getValueChangeAtAddressAfterAction<T>(
|
|
11
|
-
lucid: LucidEvolution,
|
|
12
|
-
address: string,
|
|
13
|
-
action: () => Promise<T>,
|
|
14
|
-
): Promise<[T, Assets]> {
|
|
15
|
-
const valBefore = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
|
|
16
|
-
addAssets(acc, utxo.assets),
|
|
17
|
-
)(await lucid.utxosAt(address));
|
|
18
|
-
|
|
19
|
-
const res = await action();
|
|
20
|
-
|
|
21
|
-
const valAfter = A.reduce<UTxO, Assets>({}, (acc, utxo) =>
|
|
22
|
-
addAssets(acc, utxo.assets),
|
|
23
|
-
)(await lucid.utxosAt(address));
|
|
24
|
-
|
|
25
|
-
return [res, addAssets(valAfter, negateAssets(valBefore))];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function getNewUtxosAtAddressAfterAction<T>(
|
|
29
|
-
lucid: LucidEvolution,
|
|
30
|
-
address: string,
|
|
31
|
-
action: () => Promise<T>,
|
|
32
|
-
): Promise<[T, UTxO[]]> {
|
|
33
|
-
const utxosBefore = await lucid.utxosAt(address);
|
|
34
|
-
|
|
35
|
-
const res = await action();
|
|
36
|
-
|
|
37
|
-
const utxosAfter = await lucid.utxosAt(address);
|
|
38
|
-
|
|
39
|
-
return [
|
|
40
|
-
res,
|
|
41
|
-
utxosAfter.filter(
|
|
42
|
-
(utxo) =>
|
|
43
|
-
utxosBefore.filter(
|
|
44
|
-
(oldUtxo) =>
|
|
45
|
-
utxo.txHash === oldUtxo.txHash &&
|
|
46
|
-
utxo.outputIndex === oldUtxo.outputIndex,
|
|
47
|
-
).length === 0,
|
|
48
|
-
),
|
|
49
|
-
];
|
|
50
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|