@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,463 +0,0 @@
|
|
|
1
|
-
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
2
|
-
import {
|
|
3
|
-
Credential,
|
|
4
|
-
fromHex,
|
|
5
|
-
fromText,
|
|
6
|
-
OutRef,
|
|
7
|
-
toHex,
|
|
8
|
-
toText,
|
|
9
|
-
} from '@lucid-evolution/lucid';
|
|
10
|
-
import { AssetClassD, StakeCredential } from './generic';
|
|
11
|
-
import {
|
|
12
|
-
DerivedPythPrice,
|
|
13
|
-
PythFeedParams,
|
|
14
|
-
toDataDerivedPythPrice,
|
|
15
|
-
} from '../contracts/pyth-feed/types';
|
|
16
|
-
import { match } from 'ts-pattern';
|
|
17
|
-
import { P } from 'ts-pattern';
|
|
18
|
-
|
|
19
|
-
export interface CurrencySymbolSP {
|
|
20
|
-
unCurrencySymbol: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface TokenNameSP {
|
|
24
|
-
unTokenName: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* AssetClassSP used in System Params
|
|
29
|
-
*/
|
|
30
|
-
export type AssetClassSP = [CurrencySymbolSP, TokenNameSP];
|
|
31
|
-
|
|
32
|
-
export type PythPriceConfigurationSP = {
|
|
33
|
-
priceFeedId: number;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export type DerivedPythPriceSP =
|
|
37
|
-
| {
|
|
38
|
-
tag: 'value';
|
|
39
|
-
val: PythPriceConfigurationSP;
|
|
40
|
-
}
|
|
41
|
-
| {
|
|
42
|
-
tag: 'inverse';
|
|
43
|
-
val: DerivedPythPriceSP;
|
|
44
|
-
}
|
|
45
|
-
| {
|
|
46
|
-
tag: 'divide';
|
|
47
|
-
val: [DerivedPythPriceSP, DerivedPythPriceSP];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export type PythFeedParamsSP = {
|
|
51
|
-
config: DerivedPythPriceSP;
|
|
52
|
-
pythStatePolicyId: CurrencySymbolSP;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export function fromSysParamsDerivedPythPrice(
|
|
56
|
-
cfg: DerivedPythPriceSP,
|
|
57
|
-
): DerivedPythPrice {
|
|
58
|
-
return match(cfg)
|
|
59
|
-
.returnType<DerivedPythPrice>()
|
|
60
|
-
.with({ tag: 'value', val: P.select() }, (val) => {
|
|
61
|
-
return {
|
|
62
|
-
Value: {
|
|
63
|
-
configuration: {
|
|
64
|
-
priceFeedId: BigInt(val.priceFeedId),
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
})
|
|
69
|
-
.with({ tag: 'inverse', val: P.select() }, (val) => {
|
|
70
|
-
return {
|
|
71
|
-
Inverse: {
|
|
72
|
-
value: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val)),
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
})
|
|
76
|
-
.with({ tag: 'divide', val: P.select() }, (val) => {
|
|
77
|
-
return {
|
|
78
|
-
Divide: {
|
|
79
|
-
x: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val[0])),
|
|
80
|
-
y: toDataDerivedPythPrice(fromSysParamsDerivedPythPrice(val[1])),
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
})
|
|
84
|
-
.exhaustive();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function fromSysParamsPythFeedParams(
|
|
88
|
-
params: PythFeedParamsSP,
|
|
89
|
-
): PythFeedParams {
|
|
90
|
-
return {
|
|
91
|
-
config: fromSysParamsDerivedPythPrice(params.config),
|
|
92
|
-
pythStatePolicyId: fromHex(params.pythStatePolicyId.unCurrencySymbol),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type PythFeedConfig = {
|
|
97
|
-
params: PythFeedParamsSP;
|
|
98
|
-
pythFeedValHash: string;
|
|
99
|
-
pythFeedValScriptRef: ScriptReference;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export type PythConfig = {
|
|
103
|
-
pythStateAssetClass: AssetClassSP;
|
|
104
|
-
/**
|
|
105
|
-
* Key is in the format: "iAsset.ascii/Collateral.currency.hex.Collateral.tokenName.hex".
|
|
106
|
-
* Use the `getPythFeedConfig` helper to querying.
|
|
107
|
-
*/
|
|
108
|
-
pythFeeds: {
|
|
109
|
-
[key: string]: PythFeedConfig;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
export function getPythFeedConfig(
|
|
114
|
-
cfg: PythConfig,
|
|
115
|
-
iasset: Uint8Array<ArrayBufferLike>,
|
|
116
|
-
collateralAsset: AssetClass,
|
|
117
|
-
): PythFeedConfig {
|
|
118
|
-
const res =
|
|
119
|
-
cfg.pythFeeds[
|
|
120
|
-
`${toText(toHex(iasset))}/${toHex(collateralAsset.currencySymbol)}.${toHex(collateralAsset.tokenName)}`
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
if (res == null)
|
|
124
|
-
throw new Error('No Pyth config known for such assets combination');
|
|
125
|
-
|
|
126
|
-
return res;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export interface SystemParams {
|
|
130
|
-
versionRecordParams: VersionRecordParams;
|
|
131
|
-
validatorHashes: ValidatorHashes;
|
|
132
|
-
treasuryParams: TreasuryParamsSP;
|
|
133
|
-
startTime: StartTime;
|
|
134
|
-
stakingParams: StakingParamsSP;
|
|
135
|
-
stabilityPoolParams: StabilityPoolParamsSP;
|
|
136
|
-
stableswapParams: StableswapParamsSP;
|
|
137
|
-
scriptReferences: ScriptReferences;
|
|
138
|
-
pollShardParams: PollShardParamsSP;
|
|
139
|
-
pollManagerParams: PollManagerParamsSP;
|
|
140
|
-
robParams: RobParamsSP;
|
|
141
|
-
interestCollectionParams: InterestCollectionParamsSP;
|
|
142
|
-
indyToken: AssetClassSP;
|
|
143
|
-
govParams: GovParamsSP;
|
|
144
|
-
executeParams: ExecuteParamsSP;
|
|
145
|
-
collectorParams: CollectorParamsSP;
|
|
146
|
-
cdpParams: CdpParamsSP;
|
|
147
|
-
cdpCreatorParams: CDPCreatorParamsSP;
|
|
148
|
-
cdpRedeemParams: CdpRedeemParamsSP;
|
|
149
|
-
iassetParams: IAssetParamsSP;
|
|
150
|
-
pythConfig: PythConfig;
|
|
151
|
-
}
|
|
152
|
-
export type ValidatorHashes = {
|
|
153
|
-
versionRegistryHash: string;
|
|
154
|
-
treasuryHash: string;
|
|
155
|
-
stableswapHash: string;
|
|
156
|
-
stakingHash: string;
|
|
157
|
-
stabilityPoolHash: string;
|
|
158
|
-
pollShardHash: string;
|
|
159
|
-
pollManagerHash: string;
|
|
160
|
-
robHash: string;
|
|
161
|
-
interestCollectionHash: string;
|
|
162
|
-
govHash: string;
|
|
163
|
-
executeHash: string;
|
|
164
|
-
collectorHash: string;
|
|
165
|
-
cdpHash: string;
|
|
166
|
-
cdpCreatorHash: string;
|
|
167
|
-
iassetHash: string;
|
|
168
|
-
};
|
|
169
|
-
export interface AddressCredential {
|
|
170
|
-
tag: string;
|
|
171
|
-
contents: PubKeyHash;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export interface ScriptCredential {
|
|
175
|
-
tag: string;
|
|
176
|
-
contents: {
|
|
177
|
-
tag: string;
|
|
178
|
-
contents: string;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
export interface PubKeyHash {
|
|
182
|
-
getPubKeyHash: string;
|
|
183
|
-
}
|
|
184
|
-
export interface VersionRecordParams {
|
|
185
|
-
upgradeToken: AssetClassSP;
|
|
186
|
-
}
|
|
187
|
-
export interface TreasuryParamsSP {
|
|
188
|
-
upgradeToken: AssetClassSP;
|
|
189
|
-
versionRecordToken: AssetClassSP;
|
|
190
|
-
treasuryUtxosStakeCredential: ScriptCredential | undefined;
|
|
191
|
-
}
|
|
192
|
-
export interface StartTime {
|
|
193
|
-
slot: number;
|
|
194
|
-
blockHeader: string;
|
|
195
|
-
}
|
|
196
|
-
export interface StakingParamsSP {
|
|
197
|
-
versionRecordToken: AssetClassSP;
|
|
198
|
-
stakingToken: AssetClassSP;
|
|
199
|
-
stakingManagerNFT: AssetClassSP;
|
|
200
|
-
pollToken: AssetClassSP;
|
|
201
|
-
indyToken: AssetClassSP;
|
|
202
|
-
collectorValHash: string;
|
|
203
|
-
}
|
|
204
|
-
export interface StabilityPoolParamsSP {
|
|
205
|
-
versionRecordToken: AssetClassSP;
|
|
206
|
-
stabilityPoolToken: AssetClassSP;
|
|
207
|
-
snapshotEpochToScaleToSumToken: AssetClassSP;
|
|
208
|
-
iAssetAuthToken: AssetClassSP;
|
|
209
|
-
iassetValHash: string;
|
|
210
|
-
cdpToken: AssetClassSP;
|
|
211
|
-
assetSymbol: CurrencySymbolSP;
|
|
212
|
-
accountToken: AssetClassSP;
|
|
213
|
-
accountCreateFeeLovelaces: number;
|
|
214
|
-
accountProcessingCooldownMs: number;
|
|
215
|
-
accountProcessingBiasMs: number;
|
|
216
|
-
stakeCredential: ScriptCredential | undefined;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export interface StableswapParamsSP {
|
|
220
|
-
iassetSymbol: CurrencySymbolSP;
|
|
221
|
-
cdpToken: AssetClassSP;
|
|
222
|
-
versionRecordToken: AssetClassSP;
|
|
223
|
-
cdpValHash: string;
|
|
224
|
-
treasuryValHash: string;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export interface ScriptReferences {
|
|
228
|
-
versionRegistryValidatorRef: ScriptReference;
|
|
229
|
-
treasuryValidatorRef: ScriptReference;
|
|
230
|
-
stakingValidatorRef: ScriptReference;
|
|
231
|
-
stabilityPoolValidatorRef: ScriptReference;
|
|
232
|
-
stableswapValidatorRef: ScriptReference;
|
|
233
|
-
pollShardValidatorRef: ScriptReference;
|
|
234
|
-
pollManagerValidatorRef: ScriptReference;
|
|
235
|
-
robValidatorRef: ScriptReference;
|
|
236
|
-
interestCollectionValidatorRef: ScriptReference;
|
|
237
|
-
iAssetTokenPolicyRef: ScriptReference;
|
|
238
|
-
governanceValidatorRef: ScriptReference;
|
|
239
|
-
executeValidatorRef: ScriptReference;
|
|
240
|
-
collectorValidatorRef: ScriptReference;
|
|
241
|
-
cdpValidatorRef: ScriptReference;
|
|
242
|
-
cdpCreatorValidatorRef: ScriptReference;
|
|
243
|
-
cdpRedeemValidatorRef: ScriptReference;
|
|
244
|
-
iassetValidatorRef: ScriptReference;
|
|
245
|
-
authTokenPolicies: AuthTokenPolicies;
|
|
246
|
-
}
|
|
247
|
-
export interface Output {
|
|
248
|
-
scriptRef: ScriptRef;
|
|
249
|
-
output: ScriptOutput;
|
|
250
|
-
}
|
|
251
|
-
export interface ScriptRef {
|
|
252
|
-
tag: string;
|
|
253
|
-
contents?: string[] | null;
|
|
254
|
-
}
|
|
255
|
-
export interface ScriptOutput {
|
|
256
|
-
referenceScript: string;
|
|
257
|
-
datum: AddressCredentialOrDatum;
|
|
258
|
-
amount: Amount;
|
|
259
|
-
address: AddressSP;
|
|
260
|
-
}
|
|
261
|
-
export interface AddressCredentialOrDatum {
|
|
262
|
-
tag: string;
|
|
263
|
-
contents: string;
|
|
264
|
-
}
|
|
265
|
-
export interface Amount {
|
|
266
|
-
getValue?:
|
|
267
|
-
| ((CurrencySymbolSP | (number[] | null)[] | null)[] | null)[]
|
|
268
|
-
| null;
|
|
269
|
-
}
|
|
270
|
-
export interface AddressSP {
|
|
271
|
-
addressStakingCredential?: null;
|
|
272
|
-
addressCredential: AddressCredentialOrDatum;
|
|
273
|
-
}
|
|
274
|
-
export interface Input {
|
|
275
|
-
transactionId: string;
|
|
276
|
-
index: number;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export interface ScriptReference {
|
|
280
|
-
output?: Output;
|
|
281
|
-
input: Input;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export interface AuthTokenPolicies {
|
|
285
|
-
upgradeTokenRef: ScriptReference;
|
|
286
|
-
stakingTokenRef: ScriptReference;
|
|
287
|
-
stabilityPoolTokenRef: ScriptReference;
|
|
288
|
-
stabilityPoolAuthTokenRef: ScriptReference;
|
|
289
|
-
snapshotEpochToScaleToSumTokenRef: ScriptReference;
|
|
290
|
-
pollManagerTokenRef: ScriptReference;
|
|
291
|
-
iAssetAuthTokenRef: ScriptReference;
|
|
292
|
-
iAssetTokenRef: ScriptReference;
|
|
293
|
-
collateralAssetTokenRef: ScriptReference;
|
|
294
|
-
cdpAuthTokenRef: ScriptReference;
|
|
295
|
-
accountTokenRef: ScriptReference;
|
|
296
|
-
versionRecordTokenPolicyRef: ScriptReference;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export interface RobParamsSP {
|
|
300
|
-
versionRecordToken: AssetClassSP;
|
|
301
|
-
iassetAuthToken: AssetClassSP;
|
|
302
|
-
collateralAssetAuthToken: AssetClassSP;
|
|
303
|
-
iassetValHash: string;
|
|
304
|
-
iassetPolicyId: CurrencySymbolSP;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface InterestCollectionParamsSP {
|
|
308
|
-
versionRecordNft: AssetClassSP;
|
|
309
|
-
multisigUtxoNft: AssetClassSP;
|
|
310
|
-
cdpAuthTk: AssetClassSP;
|
|
311
|
-
collateralAssetAuthTk: AssetClassSP;
|
|
312
|
-
govAuthTk: AssetClassSP;
|
|
313
|
-
cdpAssetSymbol: CurrencySymbolSP;
|
|
314
|
-
cdpBiasTime: bigint;
|
|
315
|
-
interestSettlementCooldown: bigint;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
export interface PollShardParamsSP {
|
|
319
|
-
stakingValHash: string;
|
|
320
|
-
stakingToken: AssetClassSP;
|
|
321
|
-
pollToken: AssetClassSP;
|
|
322
|
-
indyAsset: AssetClassSP;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
export interface PollManagerParamsSP {
|
|
326
|
-
upgradeToken: AssetClassSP;
|
|
327
|
-
treasuryValHash: string;
|
|
328
|
-
shardsValHash: string;
|
|
329
|
-
pollToken: AssetClassSP;
|
|
330
|
-
pBiasTime: bigint;
|
|
331
|
-
indyAsset: AssetClassSP;
|
|
332
|
-
govNFT: AssetClassSP;
|
|
333
|
-
govExecuteValHash: string;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export interface GovParamsSP {
|
|
337
|
-
versionRecordToken: AssetClassSP;
|
|
338
|
-
upgradeToken: AssetClassSP;
|
|
339
|
-
pollToken: AssetClassSP;
|
|
340
|
-
pollManagerValHash: string;
|
|
341
|
-
iassetValHash: string;
|
|
342
|
-
indyAsset: AssetClassSP;
|
|
343
|
-
iAssetAuthToken: AssetClassSP;
|
|
344
|
-
govNFT: AssetClassSP;
|
|
345
|
-
gBiasTime: bigint;
|
|
346
|
-
daoIdentityToken: AssetClassSP;
|
|
347
|
-
iassetSymbol: CurrencySymbolSP;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export interface ExecuteParamsSP {
|
|
351
|
-
govNFT: AssetClassSP;
|
|
352
|
-
upgradeToken: AssetClassSP;
|
|
353
|
-
iAssetToken: AssetClassSP;
|
|
354
|
-
collateralAssetToken: AssetClassSP;
|
|
355
|
-
stabilityPoolToken: AssetClassSP;
|
|
356
|
-
cdpCreatorToken: AssetClassSP;
|
|
357
|
-
cdpToken: AssetClassSP;
|
|
358
|
-
versionRecordToken: AssetClassSP;
|
|
359
|
-
iassetValHash: string;
|
|
360
|
-
cdpValHash: string;
|
|
361
|
-
sPoolValHash: string;
|
|
362
|
-
versionRegistryValHash: string;
|
|
363
|
-
treasuryValHash: string;
|
|
364
|
-
}
|
|
365
|
-
export interface CollectorParamsSP {
|
|
366
|
-
versionRecordToken: AssetClassSP;
|
|
367
|
-
stakingToken: AssetClassSP;
|
|
368
|
-
stakingManagerNFT: AssetClassSP;
|
|
369
|
-
}
|
|
370
|
-
export interface CdpRedeemParamsSP {
|
|
371
|
-
treasuryValHash: string;
|
|
372
|
-
iassetValHash: string;
|
|
373
|
-
partialRedemptionExtraFeeLovelace: number;
|
|
374
|
-
iAssetAuthToken: AssetClassSP;
|
|
375
|
-
collateralAssetAuthToken: AssetClassSP;
|
|
376
|
-
govNFT: AssetClassSP;
|
|
377
|
-
interestCollectorValHash: string;
|
|
378
|
-
cdpAuthToken: AssetClassSP;
|
|
379
|
-
cdpAssetSymbol: CurrencySymbolSP;
|
|
380
|
-
biasTime: bigint;
|
|
381
|
-
}
|
|
382
|
-
export interface CdpParamsSP {
|
|
383
|
-
upgradeToken: AssetClassSP;
|
|
384
|
-
versionRecordToken: AssetClassSP;
|
|
385
|
-
treasuryValHash: string;
|
|
386
|
-
stabilityPoolAuthToken: AssetClassSP;
|
|
387
|
-
spValHash: string;
|
|
388
|
-
iassetValHash: string;
|
|
389
|
-
iAssetAuthToken: AssetClassSP;
|
|
390
|
-
collateralAssetAuthToken: AssetClassSP;
|
|
391
|
-
interestCollectorValHash: string;
|
|
392
|
-
cdpRedeemValHash: string;
|
|
393
|
-
cdpAuthToken: AssetClassSP;
|
|
394
|
-
cdpAssetSymbol: CurrencySymbolSP;
|
|
395
|
-
biasTime: bigint;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export interface IAssetParamsSP {
|
|
399
|
-
upgradeToken: AssetClassSP;
|
|
400
|
-
versionRecordToken: AssetClassSP;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export interface CDPCreatorParamsSP {
|
|
404
|
-
versionRecordToken: AssetClassSP;
|
|
405
|
-
upgradeToken: AssetClassSP;
|
|
406
|
-
iAssetAuthTk: AssetClassSP;
|
|
407
|
-
collateralAssetAuthTk: AssetClassSP;
|
|
408
|
-
treasuryValHash: string;
|
|
409
|
-
cdpScriptHash: string;
|
|
410
|
-
iassetValHash: string;
|
|
411
|
-
cdpCreatorNft: AssetClassSP;
|
|
412
|
-
cdpAuthTk: AssetClassSP;
|
|
413
|
-
cdpAssetCs: CurrencySymbolSP;
|
|
414
|
-
biasTime: bigint;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export function toSystemParamsAsset(asset: AssetClass): AssetClassSP {
|
|
418
|
-
return [
|
|
419
|
-
{ unCurrencySymbol: toHex(asset.currencySymbol) },
|
|
420
|
-
{ unTokenName: toText(toHex(asset.tokenName)) },
|
|
421
|
-
];
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
export function fromSystemParamsAsset(asset: AssetClassSP): AssetClass {
|
|
425
|
-
return {
|
|
426
|
-
currencySymbol: fromHex(asset[0].unCurrencySymbol),
|
|
427
|
-
tokenName: fromHex(fromText(asset[1].unTokenName)),
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export function fromSystemParamsAssetLucid(asset: AssetClassSP): AssetClassD {
|
|
432
|
-
return {
|
|
433
|
-
currencySymbol: asset[0].unCurrencySymbol,
|
|
434
|
-
tokenName: fromText(asset[1].unTokenName),
|
|
435
|
-
};
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
export function fromSystemParamsScriptRef(ref: ScriptReference): OutRef {
|
|
439
|
-
return { outputIndex: ref.input.index, txHash: ref.input.transactionId };
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
export function fromSysParamsCredential(cred: ScriptCredential): Credential {
|
|
443
|
-
if (cred.contents.tag === 'PublicKeyCredential') {
|
|
444
|
-
return { type: 'Key', hash: cred.contents.contents };
|
|
445
|
-
}
|
|
446
|
-
return { type: 'Script', hash: cred.contents.contents };
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
export function fromSysParamsStakeCredential(
|
|
450
|
-
cred: ScriptCredential,
|
|
451
|
-
): StakeCredential {
|
|
452
|
-
return {
|
|
453
|
-
Inline: [
|
|
454
|
-
cred.contents.tag === 'PublicKeyCredential'
|
|
455
|
-
? {
|
|
456
|
-
PublicKeyCredential: [cred.contents.contents],
|
|
457
|
-
}
|
|
458
|
-
: {
|
|
459
|
-
ScriptCredential: [cred.contents.contents],
|
|
460
|
-
},
|
|
461
|
-
],
|
|
462
|
-
};
|
|
463
|
-
}
|
package/src/utils/array-utils.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
array as A,
|
|
3
|
-
ord as Ord,
|
|
4
|
-
readonlyArray as RA,
|
|
5
|
-
option as O,
|
|
6
|
-
function as F,
|
|
7
|
-
} from 'fp-ts';
|
|
8
|
-
import { Predicate } from 'fp-ts/lib/Predicate';
|
|
9
|
-
|
|
10
|
-
export function shuffle<T>(arr: T[]): T[] {
|
|
11
|
-
const source = [...arr];
|
|
12
|
-
for (let i = source.length - 1; i > 0; i--) {
|
|
13
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
14
|
-
[source[i], source[j]] = [source[j], source[i]];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return source;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The parameter `arr` should be sorted for correct results.
|
|
22
|
-
*/
|
|
23
|
-
export function insertSorted<T>(arr: T[], item: T, ord: Ord.Ord<T>): T[] {
|
|
24
|
-
if (arr.length === 0) {
|
|
25
|
-
return [item];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const arrOrd = ord.compare(arr[0], arr[arr.length - 1]);
|
|
29
|
-
// Array containing the same items
|
|
30
|
-
if (arrOrd === 0) {
|
|
31
|
-
if (ord.compare(arr[0], item) === -1) {
|
|
32
|
-
return [...arr, item];
|
|
33
|
-
} else {
|
|
34
|
-
return [item, ...arr];
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// TODO: could be improved with binary search
|
|
39
|
-
for (let i = 0; i < arr.length; i++) {
|
|
40
|
-
if (ord.compare(arr[i], item) !== arrOrd) {
|
|
41
|
-
return [...A.takeLeft(i)(arr), item, ...A.takeRight(arr.length - i)(arr)];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return [...arr, item];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Replace when existent, otherwise add at the end.
|
|
50
|
-
*/
|
|
51
|
-
export const repsertReadonlyArr =
|
|
52
|
-
<K, V>(predicate: Predicate<K>, val: V, mkKey: () => K) =>
|
|
53
|
-
(arr: ReadonlyArray<readonly [K, V]>): ReadonlyArray<readonly [K, V]> => {
|
|
54
|
-
const idx = F.pipe(
|
|
55
|
-
arr,
|
|
56
|
-
RA.findIndex(([key, _]) => predicate(key)),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const res = F.pipe(
|
|
60
|
-
idx,
|
|
61
|
-
O.chain((i) =>
|
|
62
|
-
F.pipe(
|
|
63
|
-
arr,
|
|
64
|
-
RA.modifyAt(i, ([key, _]) => [key, val]),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
return F.pipe(
|
|
70
|
-
res,
|
|
71
|
-
O.getOrElse<ReadonlyArray<readonly [K, V]>>(() => [
|
|
72
|
-
...arr,
|
|
73
|
-
[mkKey(), val],
|
|
74
|
-
]),
|
|
75
|
-
);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const repsertWithReadonlyArr =
|
|
79
|
-
<K, V>(
|
|
80
|
-
predicate: Predicate<K>,
|
|
81
|
-
replaceVal: (oldVal: V) => V,
|
|
82
|
-
newVal: () => V,
|
|
83
|
-
mkKey: () => K,
|
|
84
|
-
) =>
|
|
85
|
-
(arr: ReadonlyArray<readonly [K, V]>): ReadonlyArray<readonly [K, V]> => {
|
|
86
|
-
const idx = F.pipe(
|
|
87
|
-
arr,
|
|
88
|
-
RA.findIndex(([key, _]) => predicate(key)),
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const res = F.pipe(
|
|
92
|
-
idx,
|
|
93
|
-
O.chain((i) =>
|
|
94
|
-
F.pipe(
|
|
95
|
-
arr,
|
|
96
|
-
RA.modifyAt(i, ([key, oldVal]) => [key, replaceVal(oldVal)]),
|
|
97
|
-
),
|
|
98
|
-
),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return F.pipe(
|
|
102
|
-
res,
|
|
103
|
-
O.getOrElse<ReadonlyArray<readonly [K, V]>>(() => [
|
|
104
|
-
...arr,
|
|
105
|
-
[mkKey(), newVal()],
|
|
106
|
-
]),
|
|
107
|
-
);
|
|
108
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
import { array as A, ord as Ord } from 'fp-ts';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Plutus division behaves differently when working with negative numbers vs positive ones.
|
|
6
|
-
*/
|
|
7
|
-
export function divideOnChainCompatible(a: bigint, b: bigint): bigint {
|
|
8
|
-
const res = a / b;
|
|
9
|
-
return res + (res < 0n ? -1n : 0n);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function bigintMax(a: bigint, b: bigint): bigint {
|
|
13
|
-
return a > b ? a : b;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function bigintMin(a: bigint, b: bigint): bigint {
|
|
17
|
-
return a < b ? a : b;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function sum(arr: bigint[]): bigint {
|
|
21
|
-
return A.reduce<bigint, bigint>(0n, (acc, val) => acc + val)(arr);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function fromDecimal(val: Decimal): bigint {
|
|
25
|
-
return BigInt(val.toString());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function zeroNegatives(a: bigint): bigint {
|
|
29
|
-
return bigintMax(0n, a);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const BigIntOrd: Ord.Ord<bigint> = {
|
|
33
|
-
equals: (x, y) => x === y,
|
|
34
|
-
compare: (first, second) => (first < second ? -1 : first > second ? 1 : 0),
|
|
35
|
-
};
|
package/src/utils/helper-txs.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LucidEvolution,
|
|
3
|
-
Network,
|
|
4
|
-
OutRef,
|
|
5
|
-
SpendingValidator,
|
|
6
|
-
validatorToAddress,
|
|
7
|
-
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { alwaysFailValidator } from '../scripts/always-fail-validator';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* TODO: remove this, it should be part of the testsuite only
|
|
12
|
-
* Uses an always fail validator for the destination address.
|
|
13
|
-
*/
|
|
14
|
-
export async function runCreateScriptRefTx(
|
|
15
|
-
lucid: LucidEvolution,
|
|
16
|
-
scriptRefValidator: SpendingValidator,
|
|
17
|
-
network: Network,
|
|
18
|
-
): Promise<OutRef> {
|
|
19
|
-
const scriptAddr = validatorToAddress(network, alwaysFailValidator);
|
|
20
|
-
|
|
21
|
-
const txHash = await lucid
|
|
22
|
-
.newTx()
|
|
23
|
-
.pay.ToAddressWithData(scriptAddr, undefined, {}, scriptRefValidator)
|
|
24
|
-
.complete()
|
|
25
|
-
.then((tx) => tx.sign.withWallet().complete())
|
|
26
|
-
.then((tx) => tx.submit());
|
|
27
|
-
|
|
28
|
-
await lucid.awaitTx(txHash);
|
|
29
|
-
|
|
30
|
-
return { txHash: txHash, outputIndex: 0 };
|
|
31
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Rational,
|
|
3
|
-
rationalFloor,
|
|
4
|
-
rationalFromInt,
|
|
5
|
-
rationalMul,
|
|
6
|
-
} from '../types/rational';
|
|
7
|
-
|
|
8
|
-
export function calculateFeeFromRatio(
|
|
9
|
-
feeRatio: Rational,
|
|
10
|
-
amount: bigint,
|
|
11
|
-
): bigint {
|
|
12
|
-
if (amount < 0) {
|
|
13
|
-
return 0n;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return rationalFloor(rationalMul(rationalFromInt(amount), feeRatio));
|
|
17
|
-
}
|