@indigo-labs/indigo-sdk 0.2.42 → 0.3.0
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 +4 -2
- package/dist/index.d.mts +3008 -2194
- package/dist/index.d.ts +3008 -2194
- package/dist/index.js +9827 -6194
- package/dist/index.mjs +8591 -4809
- package/package.json +14 -3
- package/src/contracts/cdp/helpers.ts +68 -72
- package/src/contracts/cdp/scripts.ts +50 -13
- package/src/contracts/cdp/transactions.ts +831 -545
- package/src/contracts/cdp/types-new.ts +256 -0
- package/src/contracts/cdp/types.ts +26 -144
- package/src/contracts/cdp-creator/scripts.ts +15 -9
- package/src/contracts/cdp-creator/types-new.ts +50 -0
- package/src/contracts/cdp-creator/types.ts +5 -31
- package/src/contracts/collector/scripts.ts +1 -1
- package/src/contracts/collector/transactions.ts +23 -13
- package/src/contracts/collector/types-new.ts +17 -0
- package/src/contracts/execute/scripts.ts +19 -10
- package/src/contracts/execute/types-new.ts +44 -0
- package/src/contracts/execute/types.ts +5 -38
- package/src/contracts/gov/helpers.ts +187 -51
- package/src/contracts/gov/scripts.ts +17 -10
- package/src/contracts/gov/transactions.ts +599 -271
- package/src/contracts/gov/types-new.ts +253 -100
- package/src/contracts/gov/types.ts +4 -71
- package/src/contracts/iasset/helpers.ts +172 -0
- package/src/contracts/iasset/scripts.ts +38 -0
- package/src/contracts/iasset/types.ts +154 -0
- package/src/contracts/initialize/actions.ts +768 -0
- package/src/contracts/initialize/helpers.ts +611 -36
- package/src/contracts/initialize/types.ts +102 -28
- package/src/contracts/interest-collection/helpers.ts +19 -0
- package/src/contracts/interest-collection/scripts.ts +44 -0
- package/src/contracts/interest-collection/transactions.ts +436 -0
- package/src/contracts/interest-collection/types-new.ts +50 -0
- package/src/contracts/interest-collection/types.ts +26 -0
- package/src/contracts/interest-oracle/helpers.ts +2 -30
- package/src/contracts/interest-oracle/scripts.ts +1 -1
- package/src/contracts/interest-oracle/transactions.ts +21 -16
- package/src/contracts/interest-oracle/types-new.ts +32 -0
- package/src/contracts/interest-oracle/types.ts +1 -40
- package/src/contracts/one-shot/transactions.ts +1 -2
- package/src/contracts/poll/helpers.ts +5 -23
- package/src/contracts/poll/scripts.ts +12 -13
- package/src/contracts/poll/types-poll-manager.ts +1 -19
- package/src/contracts/poll/types-poll-new.ts +170 -0
- package/src/contracts/poll/types-poll-shard.ts +2 -24
- package/src/contracts/price-oracle/helpers.ts +1 -4
- package/src/contracts/price-oracle/scripts.ts +3 -8
- package/src/contracts/price-oracle/transactions.ts +32 -25
- package/src/contracts/price-oracle/types-new.ts +50 -0
- package/src/contracts/price-oracle/types.ts +2 -36
- package/src/contracts/pyth-feed/helpers.ts +58 -0
- package/src/contracts/pyth-feed/scripts.ts +15 -0
- package/src/contracts/pyth-feed/types.ts +181 -0
- package/src/contracts/rob/helpers.ts +405 -0
- package/src/contracts/rob/scripts.ts +35 -0
- package/src/contracts/rob/transactions.ts +410 -0
- package/src/contracts/rob/types-new.ts +128 -0
- package/src/contracts/rob/types.ts +16 -0
- package/src/contracts/rob-leverage/helpers.ts +424 -0
- package/src/contracts/{leverage → rob-leverage}/transactions.ts +68 -48
- package/src/contracts/stability-pool/helpers.ts +714 -230
- package/src/contracts/stability-pool/scripts.ts +20 -15
- package/src/contracts/stability-pool/transactions.ts +625 -493
- package/src/contracts/stability-pool/types-new.ts +237 -100
- package/src/contracts/stability-pool/types.ts +5 -22
- package/src/contracts/stableswap/helpers.ts +22 -0
- package/src/contracts/stableswap/scripts.ts +37 -0
- package/src/contracts/stableswap/transactions.ts +647 -0
- package/src/contracts/stableswap/types-new.ts +131 -0
- package/src/contracts/stableswap/types.ts +17 -0
- package/src/contracts/staking/helpers.ts +49 -34
- package/src/contracts/staking/scripts.ts +1 -1
- package/src/contracts/staking/transactions.ts +85 -130
- package/src/contracts/staking/types-new.ts +60 -28
- package/src/contracts/staking/types.ts +1 -28
- package/src/contracts/treasury/helpers.ts +21 -0
- package/src/contracts/treasury/scripts.ts +16 -26
- package/src/contracts/treasury/transactions.ts +256 -27
- package/src/contracts/treasury/types-new.ts +69 -0
- package/src/contracts/treasury/types.ts +2 -43
- package/src/contracts/version-registry/scripts.ts +2 -2
- package/src/contracts/version-registry/types-new.ts +6 -7
- package/src/index.ts +37 -20
- package/src/scripts/auth-token-policy.ts +3 -2
- package/src/scripts/iasset-policy.ts +3 -2
- package/src/types/evolution-schema-options.ts +3 -3
- package/src/types/generic.ts +17 -89
- package/src/types/multisig.ts +48 -0
- package/src/types/on-chain-decimal.ts +14 -7
- package/src/types/rational.ts +61 -0
- package/src/types/system-params.ts +237 -41
- package/src/utils/array-utils.ts +70 -1
- package/src/utils/bigint-utils.ts +12 -0
- package/src/utils/indigo-helpers.ts +8 -10
- package/src/utils/lucid-utils.ts +47 -40
- package/src/utils/oracle-helpers.ts +62 -0
- package/src/utils/pyth/decode.ts +223 -0
- package/src/utils/pyth/encode.ts +262 -0
- package/src/utils/pyth/index.ts +14 -0
- package/src/utils/pyth/types.ts +87 -0
- package/src/validators/always-succeed-validator.ts +6 -0
- package/src/validators/cdp-creator-validator.ts +2 -2
- package/src/validators/cdp-redeem-validator.ts +7 -0
- package/src/validators/cdp-validator.ts +2 -2
- package/src/validators/collector-validator.ts +2 -2
- package/src/validators/execute-validator.ts +2 -2
- package/src/validators/governance-validator.ts +2 -2
- package/src/validators/iasset-validator.ts +7 -0
- package/src/validators/interest-collection-validator.ts +7 -0
- package/src/validators/interest-oracle-validator.ts +2 -2
- package/src/validators/poll-manager-validator.ts +2 -2
- package/src/validators/poll-shard-validator.ts +2 -2
- package/src/validators/price-oracle-validator.ts +7 -0
- package/src/validators/pyth-feed-validator.ts +7 -0
- package/src/validators/rob-validator.ts +7 -0
- package/src/validators/stability-pool-validator.ts +2 -2
- package/src/validators/stableswap-validator.ts +7 -0
- package/src/validators/staking-validator.ts +2 -2
- package/src/validators/treasury-validator.ts +2 -2
- package/src/validators/version-record-policy.ts +2 -2
- package/src/validators/version-registry-validator.ts +2 -2
- package/tests/always-succeed/script.ts +7 -0
- package/tests/bigint-utils.test.ts +41 -0
- package/tests/cdp/actions.ts +611 -0
- package/tests/cdp/cdp-helpers.ts +55 -0
- package/tests/cdp/cdp-queries.ts +440 -0
- package/tests/cdp/cdp.test.ts +6087 -0
- package/tests/cdp/transactions-mutated.ts +1729 -0
- package/tests/data/system-params.json +177 -34
- package/tests/datums.test.ts +209 -210
- package/tests/endpoints/initialize.ts +68 -0
- package/tests/endpoints/interest-collector.ts +37 -0
- package/tests/endpoints/treasury.ts +70 -0
- package/tests/gov/actions.ts +406 -0
- package/tests/gov/gov.test.ts +4450 -0
- package/tests/{queries → gov}/governance-queries.ts +6 -3
- package/tests/hash-checks.test.ts +38 -11
- package/tests/indigo-test-helpers.ts +100 -0
- package/tests/initialize.test.ts +61 -9
- package/tests/interest-collection/interest-collection.test.ts +892 -0
- package/tests/interest-collection/interest-collector-queries.ts +49 -0
- package/tests/interest-collection/transactions-mutated.ts +260 -0
- package/tests/interest-oracle.test.ts +43 -35
- package/tests/mock/assets-mock.ts +234 -23
- package/tests/mock/protocol-params-mock.ts +21 -0
- package/tests/price-oracle/actions.ts +163 -0
- package/tests/price-oracle/price-oracle-queries.ts +12 -0
- package/tests/price-oracle/price-oracle.test.ts +240 -0
- package/tests/price-oracle/transactions-mutated.ts +62 -0
- package/tests/pyth/endpoints.ts +96 -0
- package/tests/pyth/helpers.ts +37 -0
- package/tests/pyth/pyth-encoding.test.ts +376 -0
- package/tests/pyth/pyth-indigo.test.ts +509 -0
- package/tests/pyth/pyth.test.ts +300 -0
- package/tests/queries/execute-queries.ts +6 -5
- package/tests/queries/iasset-queries.ts +175 -5
- package/tests/queries/interest-oracle-queries.ts +4 -2
- package/tests/queries/poll-queries.ts +8 -9
- package/tests/queries/stability-pool-queries.ts +95 -48
- package/tests/queries/staking-queries.ts +4 -2
- package/tests/queries/treasury-queries.ts +80 -5
- package/tests/rob/actions.ts +58 -0
- package/tests/{lrp-leverage.test.ts → rob/rob-leverage.test.ts} +393 -296
- package/tests/rob/rob-queries.ts +95 -0
- package/tests/rob/rob.test.ts +3762 -0
- package/tests/rob/transactions-mutated.ts +853 -0
- package/tests/script-size.test.ts +240 -0
- package/tests/setup.ts +135 -0
- package/tests/stability-pool/actions.ts +210 -0
- package/tests/stability-pool.test.ts +5469 -666
- package/tests/stableswap/stableswap-actions.ts +84 -0
- package/tests/stableswap/stableswap-queries.ts +89 -0
- package/tests/stableswap/stableswap.test.ts +3891 -0
- package/tests/stableswap/transactions-mutated.ts +348 -0
- package/tests/staking.test.ts +82 -99
- package/tests/test-helpers.ts +58 -11
- package/tests/treasury.test.ts +242 -0
- package/tests/utils/asserts.ts +74 -0
- package/tests/utils/benchmark-utils.ts +81 -0
- package/tests/utils/index.ts +122 -4
- package/tsconfig.json +9 -1
- package/vitest.config.ts +3 -1
- package/src/contracts/collector/types.ts +0 -16
- package/src/contracts/initialize/transactions.ts +0 -891
- package/src/contracts/leverage/helpers.ts +0 -424
- package/src/contracts/lrp/helpers.ts +0 -294
- package/src/contracts/lrp/scripts.ts +0 -27
- package/src/contracts/lrp/transactions.ts +0 -250
- package/src/contracts/lrp/types.ts +0 -131
- package/src/contracts/poll/types-poll.ts +0 -88
- package/src/contracts/vesting/helpers.ts +0 -218
- package/src/utils/value-helpers.ts +0 -37
- package/src/validators/lrp-validator.ts +0 -7
- package/tests/cdp.test.ts +0 -1528
- package/tests/gov.test.ts +0 -2011
- package/tests/lrp.test.ts +0 -673
- package/tests/queries/cdp-queries.ts +0 -220
- package/tests/queries/lrp-queries.ts +0 -76
- package/tests/queries/price-oracle-queries.ts +0 -10
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
2
|
import { match, P } from 'ts-pattern';
|
|
3
|
-
import {
|
|
3
|
+
import { option as O, function as F } from 'fp-ts';
|
|
4
|
+
|
|
4
5
|
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
6
|
+
import {
|
|
7
|
+
AddressSchema,
|
|
8
|
+
AssetClassSchema,
|
|
9
|
+
OutputReferenceSchema,
|
|
10
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
11
|
+
import {
|
|
12
|
+
divideOnChainCompatible,
|
|
13
|
+
zeroNegatives,
|
|
14
|
+
} from '../../utils/bigint-utils';
|
|
5
15
|
|
|
6
|
-
export const SPIntegerSchema =
|
|
7
|
-
value:
|
|
16
|
+
export const SPIntegerSchema = TSchema.Struct({
|
|
17
|
+
value: TSchema.Integer,
|
|
8
18
|
});
|
|
9
19
|
|
|
10
20
|
export type SPInteger = typeof SPIntegerSchema.Type;
|
|
11
21
|
|
|
12
|
-
const AccountActionSchema =
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
const AccountActionSchema = TSchema.Union(
|
|
23
|
+
TSchema.Literal('Create', { flatInUnion: true }),
|
|
24
|
+
TSchema.Struct(
|
|
15
25
|
{
|
|
16
|
-
Adjust:
|
|
26
|
+
Adjust: TSchema.Struct(
|
|
17
27
|
{
|
|
18
|
-
amount:
|
|
28
|
+
amount: TSchema.Integer,
|
|
19
29
|
outputAddress: AddressSchema,
|
|
20
30
|
},
|
|
21
31
|
{ flatFields: true },
|
|
@@ -23,10 +33,10 @@ const AccountActionSchema = EvoCore.TSchema.Union(
|
|
|
23
33
|
},
|
|
24
34
|
{ flatInUnion: true },
|
|
25
35
|
),
|
|
26
|
-
|
|
36
|
+
TSchema.Struct(
|
|
27
37
|
{
|
|
28
|
-
Close:
|
|
29
|
-
{ outputAddress: AddressSchema },
|
|
38
|
+
Close: TSchema.Struct(
|
|
39
|
+
{ outputAddress: AddressSchema, maxTxFee: TSchema.Integer },
|
|
30
40
|
{ flatFields: true },
|
|
31
41
|
),
|
|
32
42
|
},
|
|
@@ -36,97 +46,184 @@ const AccountActionSchema = EvoCore.TSchema.Union(
|
|
|
36
46
|
|
|
37
47
|
export type AccountAction = typeof AccountActionSchema.Type;
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
const SumSnapshotSchema = TSchema.Struct({
|
|
50
|
+
sumVal: SPIntegerSchema,
|
|
51
|
+
isLastInEpoch: TSchema.Boolean,
|
|
52
|
+
isFirstSnapshot: TSchema.Boolean,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export type SumSnapshot = typeof SumSnapshotSchema.Type;
|
|
56
|
+
|
|
57
|
+
const EpochToScaleKeySchema = TSchema.Struct({
|
|
58
|
+
epoch: TSchema.Integer,
|
|
59
|
+
scale: TSchema.Integer,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type EpochToScaleKey = typeof EpochToScaleKeySchema.Type;
|
|
63
|
+
|
|
64
|
+
const EpochToScaleToSumEntrySchema = TSchema.Tuple([
|
|
65
|
+
EpochToScaleKeySchema,
|
|
66
|
+
SumSnapshotSchema,
|
|
67
|
+
]);
|
|
46
68
|
|
|
47
|
-
export type
|
|
69
|
+
export type EpochToScaleToSumEntry = typeof EpochToScaleToSumEntrySchema.Type;
|
|
48
70
|
|
|
49
|
-
const
|
|
71
|
+
const StateSnapshotSchema = TSchema.Struct({
|
|
50
72
|
productVal: SPIntegerSchema,
|
|
51
73
|
depositVal: SPIntegerSchema,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
74
|
+
epoch: TSchema.Integer,
|
|
75
|
+
scale: TSchema.Integer,
|
|
76
|
+
});
|
|
77
|
+
export type StateSnapshot = typeof StateSnapshotSchema.Type;
|
|
78
|
+
|
|
79
|
+
const AssetSnapshotSchema = TSchema.Struct({
|
|
80
|
+
currentSumVal: SPIntegerSchema,
|
|
81
|
+
epoch2scale2sum: TSchema.Array(EpochToScaleToSumEntrySchema),
|
|
55
82
|
});
|
|
83
|
+
export type AssetSnapshot = typeof AssetSnapshotSchema.Type;
|
|
56
84
|
|
|
57
|
-
|
|
85
|
+
const AssetStateSchema = TSchema.Tuple([AssetClassSchema, AssetSnapshotSchema]);
|
|
86
|
+
export type AssetState = typeof AssetStateSchema.Type;
|
|
58
87
|
|
|
59
|
-
export const StabilityPoolContentSchema =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
88
|
+
export const StabilityPoolContentSchema = TSchema.Struct({
|
|
89
|
+
iasset: TSchema.ByteArray,
|
|
90
|
+
state: StateSnapshotSchema,
|
|
91
|
+
assetStates: TSchema.Array(AssetStateSchema),
|
|
63
92
|
});
|
|
64
93
|
|
|
65
94
|
export type StabilityPoolContent = typeof StabilityPoolContentSchema.Type;
|
|
66
95
|
|
|
67
|
-
export const AccountContentSchema =
|
|
68
|
-
owner:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
96
|
+
export const AccountContentSchema = TSchema.Struct({
|
|
97
|
+
owner: TSchema.ByteArray,
|
|
98
|
+
iasset: TSchema.ByteArray,
|
|
99
|
+
state: StateSnapshotSchema,
|
|
100
|
+
assetSums: TSchema.Array(TSchema.Tuple([AssetClassSchema, SPIntegerSchema])),
|
|
101
|
+
request: TSchema.NullOr(AccountActionSchema),
|
|
102
|
+
lastRequestProcessingTime: TSchema.Integer,
|
|
72
103
|
});
|
|
73
104
|
|
|
74
105
|
export type AccountContent = typeof AccountContentSchema.Type;
|
|
75
106
|
|
|
76
|
-
export const SnapshotEpochToScaleToSumContentSchema =
|
|
77
|
-
snapshot:
|
|
78
|
-
|
|
107
|
+
export const SnapshotEpochToScaleToSumContentSchema = TSchema.Struct({
|
|
108
|
+
snapshot: TSchema.Array(EpochToScaleToSumEntrySchema),
|
|
109
|
+
iasset: TSchema.ByteArray,
|
|
110
|
+
collateralAsset: AssetClassSchema,
|
|
79
111
|
});
|
|
80
112
|
|
|
81
113
|
export type SnapshotEpochToScaleToSumContent =
|
|
82
114
|
typeof SnapshotEpochToScaleToSumContentSchema.Type;
|
|
83
115
|
|
|
84
|
-
export const StabilityPoolDatumSchema =
|
|
85
|
-
|
|
116
|
+
export const StabilityPoolDatumSchema = TSchema.Union(
|
|
117
|
+
TSchema.Struct(
|
|
86
118
|
{ StabilityPool: StabilityPoolContentSchema },
|
|
87
119
|
{ flatInUnion: true },
|
|
88
120
|
),
|
|
89
|
-
|
|
90
|
-
|
|
121
|
+
TSchema.Struct({ Account: AccountContentSchema }, { flatInUnion: true }),
|
|
122
|
+
TSchema.Struct(
|
|
123
|
+
{ SnapshotEpochToScaleToSum: SnapshotEpochToScaleToSumContentSchema },
|
|
91
124
|
{ flatInUnion: true },
|
|
92
125
|
),
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const E2S2SIndexSchema = TSchema.Union(
|
|
129
|
+
TSchema.Struct(
|
|
130
|
+
{ StabilityPoolListIdx: TSchema.Integer },
|
|
95
131
|
{ flatInUnion: true },
|
|
96
132
|
),
|
|
133
|
+
TSchema.Struct(
|
|
134
|
+
{
|
|
135
|
+
RefInputIdx: TSchema.Struct(
|
|
136
|
+
{
|
|
137
|
+
refInputIdx: TSchema.Integer,
|
|
138
|
+
snapshotListIdx: TSchema.Integer,
|
|
139
|
+
},
|
|
140
|
+
{ flatFields: true },
|
|
141
|
+
),
|
|
142
|
+
},
|
|
143
|
+
{ flatInUnion: true },
|
|
144
|
+
),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
export type E2S2SIndex = typeof E2S2SIndexSchema.Type;
|
|
148
|
+
|
|
149
|
+
const E2S2SIndicesPerAssetSchema = TSchema.Array(
|
|
150
|
+
TSchema.Tuple([E2S2SIndexSchema, TSchema.NullOr(E2S2SIndexSchema)]),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
export type E2S2SIndicesPerAsset = typeof E2S2SIndicesPerAssetSchema.Type;
|
|
154
|
+
|
|
155
|
+
const ProcessRequestAccountContentSchema = TSchema.Struct(
|
|
156
|
+
{
|
|
157
|
+
poolInputIdx: TSchema.Integer,
|
|
158
|
+
accountInputIdx: TSchema.Integer,
|
|
159
|
+
e2s2sIdxs: E2S2SIndicesPerAssetSchema,
|
|
160
|
+
currentTime: TSchema.Integer,
|
|
161
|
+
},
|
|
162
|
+
{ flatFields: true },
|
|
97
163
|
);
|
|
98
164
|
|
|
99
|
-
export
|
|
100
|
-
|
|
101
|
-
|
|
165
|
+
export type ProcessRequestAccountContent =
|
|
166
|
+
typeof ProcessRequestAccountContentSchema.Type;
|
|
167
|
+
|
|
168
|
+
export const StabilityPoolRedeemerSchema = TSchema.Union(
|
|
169
|
+
TSchema.Struct({ RequestAction: AccountActionSchema }, { flatInUnion: true }),
|
|
170
|
+
TSchema.Struct(
|
|
171
|
+
{
|
|
172
|
+
ProcessRequestPool: TSchema.Struct(
|
|
173
|
+
{
|
|
174
|
+
poolInputIdx: TSchema.Integer,
|
|
175
|
+
accountInputIdx: TSchema.Integer,
|
|
176
|
+
},
|
|
177
|
+
{ flatFields: true },
|
|
178
|
+
),
|
|
179
|
+
},
|
|
102
180
|
{ flatInUnion: true },
|
|
103
181
|
),
|
|
104
|
-
|
|
182
|
+
TSchema.Struct(
|
|
105
183
|
{
|
|
106
|
-
|
|
107
|
-
txHash: EvoCore.TSchema.Struct({ hash: EvoCore.TSchema.ByteArray }),
|
|
108
|
-
outputIndex: EvoCore.TSchema.Integer,
|
|
109
|
-
}),
|
|
184
|
+
ProcessRequestAccount: ProcessRequestAccountContentSchema,
|
|
110
185
|
},
|
|
111
186
|
{ flatInUnion: true },
|
|
112
187
|
),
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
188
|
+
TSchema.Literal('AnnulRequest', { flatInUnion: true }),
|
|
189
|
+
TSchema.Literal('LiquidateCDP', { flatInUnion: true }),
|
|
190
|
+
TSchema.Literal('RecordEpochToScaleToSum', { flatInUnion: true }),
|
|
191
|
+
TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
|
|
117
192
|
);
|
|
118
193
|
|
|
119
194
|
export type StabilityPoolRedeemer = typeof StabilityPoolRedeemerSchema.Type;
|
|
120
195
|
|
|
196
|
+
const ActionReturnDatumSchema = TSchema.Union(
|
|
197
|
+
TSchema.Struct(
|
|
198
|
+
{
|
|
199
|
+
IndigoStabilityPoolAccountAdjustment: OutputReferenceSchema,
|
|
200
|
+
},
|
|
201
|
+
{ flatInUnion: true },
|
|
202
|
+
),
|
|
203
|
+
TSchema.Struct(
|
|
204
|
+
{
|
|
205
|
+
IndigoStabilityPoolAccountClosure: OutputReferenceSchema,
|
|
206
|
+
},
|
|
207
|
+
{ flatInUnion: true },
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
export type ActionReturnDatum = typeof ActionReturnDatumSchema.Type;
|
|
212
|
+
|
|
213
|
+
export function serialiseActionReturnDatum(d: ActionReturnDatum): string {
|
|
214
|
+
return Data.withSchema(
|
|
215
|
+
ActionReturnDatumSchema,
|
|
216
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
217
|
+
).toCBORHex(d);
|
|
218
|
+
}
|
|
219
|
+
|
|
121
220
|
export function serialiseStabilityPoolRedeemer(
|
|
122
221
|
r: StabilityPoolRedeemer,
|
|
123
222
|
): string {
|
|
124
|
-
|
|
223
|
+
return Data.withSchema(
|
|
125
224
|
StabilityPoolRedeemerSchema,
|
|
126
225
|
DEFAULT_SCHEMA_OPTIONS,
|
|
127
226
|
).toCBORHex(r);
|
|
128
|
-
|
|
129
|
-
return rdmr;
|
|
130
227
|
}
|
|
131
228
|
|
|
132
229
|
export function serialiseStabilityPoolDatum(
|
|
@@ -136,63 +233,99 @@ export function serialiseStabilityPoolDatum(
|
|
|
136
233
|
*/
|
|
137
234
|
useIndefiniteMaps: boolean = false,
|
|
138
235
|
): string {
|
|
139
|
-
|
|
236
|
+
return Data.withSchema(StabilityPoolDatumSchema, {
|
|
140
237
|
...DEFAULT_SCHEMA_OPTIONS,
|
|
141
238
|
useIndefiniteMaps: useIndefiniteMaps,
|
|
142
239
|
}).toCBORHex(d);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function parseStabilityPoolDatum(
|
|
243
|
+
datum: string,
|
|
244
|
+
): O.Option<StabilityPoolContent> {
|
|
245
|
+
try {
|
|
246
|
+
return match(
|
|
247
|
+
Data.withSchema(
|
|
248
|
+
StabilityPoolDatumSchema,
|
|
249
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
250
|
+
).fromCBORHex(datum),
|
|
251
|
+
)
|
|
252
|
+
.with({ StabilityPool: P.select() }, (res) => O.some(res))
|
|
253
|
+
.otherwise(() => O.none);
|
|
254
|
+
} catch (_) {
|
|
255
|
+
return O.none;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
export function parseStabilityPoolDatumOrThrow(
|
|
259
|
+
datum: string,
|
|
260
|
+
): StabilityPoolContent {
|
|
261
|
+
return F.pipe(
|
|
262
|
+
parseStabilityPoolDatum(datum),
|
|
263
|
+
O.match(() => {
|
|
264
|
+
throw new Error('Expected stability pool datum.');
|
|
265
|
+
}, F.identity),
|
|
266
|
+
);
|
|
267
|
+
}
|
|
143
268
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
).fromCBORHex(datum),
|
|
166
|
-
)
|
|
167
|
-
.with({ Account: P.select() }, (res) => res)
|
|
168
|
-
.otherwise(() => {
|
|
169
|
-
throw new Error('Expected a Stability Pool datum.');
|
|
170
|
-
});
|
|
269
|
+
export function parseAccountDatum(datum: string): O.Option<AccountContent> {
|
|
270
|
+
try {
|
|
271
|
+
return match(
|
|
272
|
+
Data.withSchema(
|
|
273
|
+
StabilityPoolDatumSchema,
|
|
274
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
275
|
+
).fromCBORHex(datum),
|
|
276
|
+
)
|
|
277
|
+
.with({ Account: P.select() }, (res) => O.some(res))
|
|
278
|
+
.otherwise(() => O.none);
|
|
279
|
+
} catch (_) {
|
|
280
|
+
return O.none;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
export function parseAccountDatumOrThrow(datum: string): AccountContent {
|
|
284
|
+
return F.pipe(
|
|
285
|
+
parseAccountDatum(datum),
|
|
286
|
+
O.match(() => {
|
|
287
|
+
throw new Error('Expected account datum.');
|
|
288
|
+
}, F.identity),
|
|
289
|
+
);
|
|
171
290
|
}
|
|
291
|
+
|
|
172
292
|
export function parseSnapshotEpochToScaleToSumDatum(
|
|
173
293
|
datum: string,
|
|
294
|
+
): O.Option<SnapshotEpochToScaleToSumContent> {
|
|
295
|
+
try {
|
|
296
|
+
return match(
|
|
297
|
+
Data.withSchema(
|
|
298
|
+
StabilityPoolDatumSchema,
|
|
299
|
+
DEFAULT_SCHEMA_OPTIONS,
|
|
300
|
+
).fromCBORHex(datum),
|
|
301
|
+
)
|
|
302
|
+
.with({ SnapshotEpochToScaleToSum: P.select() }, (res) => O.some(res))
|
|
303
|
+
.otherwise(() => O.none);
|
|
304
|
+
} catch (_) {
|
|
305
|
+
return O.none;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function parseSnapshotEpochToScaleToSumDatumOrThrow(
|
|
310
|
+
datum: string,
|
|
174
311
|
): SnapshotEpochToScaleToSumContent {
|
|
175
|
-
return
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
.with({ SnapshotEpochToScaleToSum: P.select() }, (res) => res)
|
|
182
|
-
.otherwise(() => {
|
|
183
|
-
throw new Error('Expected a Stability Pool datum.');
|
|
184
|
-
});
|
|
312
|
+
return F.pipe(
|
|
313
|
+
parseSnapshotEpochToScaleToSumDatum(datum),
|
|
314
|
+
O.match(() => {
|
|
315
|
+
throw new Error('Expected snapshot e2s2s datum.');
|
|
316
|
+
}, F.identity),
|
|
317
|
+
);
|
|
185
318
|
}
|
|
186
319
|
|
|
187
320
|
/** SP Integer */
|
|
188
|
-
const spPrecision: bigint =
|
|
321
|
+
const spPrecision: bigint = 1_000_000_000_000_000_000n;
|
|
189
322
|
|
|
190
323
|
export function mkSPInteger(value: bigint): SPInteger {
|
|
191
324
|
return { value: value * spPrecision };
|
|
192
325
|
}
|
|
193
326
|
|
|
194
327
|
export function fromSPInteger(value: SPInteger): bigint {
|
|
195
|
-
return value.value
|
|
328
|
+
return divideOnChainCompatible(value.value, spPrecision);
|
|
196
329
|
}
|
|
197
330
|
|
|
198
331
|
export function spAdd(a: SPInteger, b: SPInteger): SPInteger {
|
|
@@ -204,9 +337,13 @@ export function spSub(a: SPInteger, b: SPInteger): SPInteger {
|
|
|
204
337
|
}
|
|
205
338
|
|
|
206
339
|
export function spMul(a: SPInteger, b: SPInteger): SPInteger {
|
|
207
|
-
return { value: (a.value * b.value
|
|
340
|
+
return { value: divideOnChainCompatible(a.value * b.value, spPrecision) };
|
|
208
341
|
}
|
|
209
342
|
|
|
210
343
|
export function spDiv(a: SPInteger, b: SPInteger): SPInteger {
|
|
211
|
-
return { value: (a.value * spPrecision
|
|
344
|
+
return { value: divideOnChainCompatible(a.value * spPrecision, b.value) };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function spZeroNegatives(a: SPInteger): SPInteger {
|
|
348
|
+
return { value: zeroNegatives(a.value) };
|
|
212
349
|
}
|
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema,
|
|
3
|
-
|
|
4
|
-
export const ActionReturnDatumSchema = Data.Enum([
|
|
5
|
-
Data.Object({
|
|
6
|
-
IndigoStabilityPoolAccountAdjustment: Data.Object({
|
|
7
|
-
spent_account: OutputReferenceSchema,
|
|
8
|
-
}),
|
|
9
|
-
}),
|
|
10
|
-
Data.Object({
|
|
11
|
-
IndigoStabilityPoolAccountClosure: Data.Object({
|
|
12
|
-
closed_account: OutputReferenceSchema,
|
|
13
|
-
}),
|
|
14
|
-
}),
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
export type ActionReturnDatum = Data.Static<typeof ActionReturnDatumSchema>;
|
|
18
|
-
export const ActionReturnDatum =
|
|
19
|
-
ActionReturnDatumSchema as unknown as ActionReturnDatum;
|
|
2
|
+
import { AssetClassSchema, StakeCredentialSchema } from '../../types/generic';
|
|
20
3
|
|
|
21
4
|
/** SP Parameters */
|
|
22
5
|
const StabilityPoolParamsSchema = Data.Object({
|
|
@@ -27,11 +10,11 @@ const StabilityPoolParamsSchema = Data.Object({
|
|
|
27
10
|
cdpToken: AssetClassSchema,
|
|
28
11
|
iAssetAuthToken: AssetClassSchema,
|
|
29
12
|
versionRecordToken: AssetClassSchema,
|
|
30
|
-
|
|
31
|
-
govNFT: AssetClassSchema,
|
|
13
|
+
iassetValHash: Data.Bytes(),
|
|
32
14
|
accountCreateFeeLovelaces: Data.Integer(),
|
|
33
|
-
|
|
34
|
-
|
|
15
|
+
accountProcessingCooldownMs: Data.Integer(),
|
|
16
|
+
accountProcessingBiasMs: Data.Integer(),
|
|
17
|
+
stakeCredential: Data.Nullable(StakeCredentialSchema),
|
|
35
18
|
});
|
|
36
19
|
export type StabilityPoolParams = Data.Static<typeof StabilityPoolParamsSchema>;
|
|
37
20
|
export const StabilityPoolParams =
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fromHex, fromText, OutRef } from '@lucid-evolution/lucid';
|
|
2
|
+
import { serialiseStableswapOutputDatum } from './types-new';
|
|
3
|
+
import { Data } from '@evolution-sdk/evolution';
|
|
4
|
+
|
|
5
|
+
export const BASE_MAX_EXECUTION_FEE = 1_000_000n;
|
|
6
|
+
|
|
7
|
+
export function createDestinationDatum(
|
|
8
|
+
datum: Data.Data | null,
|
|
9
|
+
outRef: OutRef,
|
|
10
|
+
): string {
|
|
11
|
+
if (!datum) {
|
|
12
|
+
return serialiseStableswapOutputDatum([
|
|
13
|
+
fromHex(fromText('IndigoStableswap')),
|
|
14
|
+
{
|
|
15
|
+
txHash: fromHex(outRef.txHash),
|
|
16
|
+
outputIndex: BigInt(outRef.outputIndex),
|
|
17
|
+
},
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return Data.toCBORHex(datum);
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { applyParamsToScript, SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
+
import { castStableswapParams, StableswapParams } from './types';
|
|
3
|
+
import {
|
|
4
|
+
fromSystemParamsAssetLucid,
|
|
5
|
+
StableswapParamsSP,
|
|
6
|
+
} from '../../types/system-params';
|
|
7
|
+
import { _stableswapValidator } from '../../validators/stableswap-validator';
|
|
8
|
+
|
|
9
|
+
export const mkStableswapValidator = (
|
|
10
|
+
params: StableswapParams,
|
|
11
|
+
): SpendingValidator => {
|
|
12
|
+
return {
|
|
13
|
+
type: 'PlutusV3',
|
|
14
|
+
script: applyParamsToScript(_stableswapValidator.cborHex, [
|
|
15
|
+
castStableswapParams(params),
|
|
16
|
+
]),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const mkStableswapValidatorFromSP = (
|
|
21
|
+
params: StableswapParamsSP,
|
|
22
|
+
): SpendingValidator => {
|
|
23
|
+
return {
|
|
24
|
+
type: 'PlutusV3',
|
|
25
|
+
script: applyParamsToScript(_stableswapValidator.cborHex, [
|
|
26
|
+
castStableswapParams({
|
|
27
|
+
iassetSymbol: params.iassetSymbol.unCurrencySymbol,
|
|
28
|
+
cdpToken: fromSystemParamsAssetLucid(params.cdpToken),
|
|
29
|
+
versionRecordToken: fromSystemParamsAssetLucid(
|
|
30
|
+
params.versionRecordToken,
|
|
31
|
+
),
|
|
32
|
+
cdpValHash: params.cdpValHash,
|
|
33
|
+
treasuryValHash: params.treasuryValHash,
|
|
34
|
+
}),
|
|
35
|
+
]),
|
|
36
|
+
};
|
|
37
|
+
};
|