@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,196 +0,0 @@
|
|
|
1
|
-
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
|
-
import {
|
|
3
|
-
ProposalContentSchema,
|
|
4
|
-
TreasuryWithdrawalSchema,
|
|
5
|
-
} from '../gov/types-new';
|
|
6
|
-
import {
|
|
7
|
-
AddressSchema,
|
|
8
|
-
OutputReferenceSchema,
|
|
9
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
10
|
-
import { option as O, function as F } from 'fp-ts';
|
|
11
|
-
import { match, P } from 'ts-pattern';
|
|
12
|
-
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
13
|
-
|
|
14
|
-
const PollStatusSchema = TSchema.Struct({
|
|
15
|
-
yesVotes: TSchema.Integer,
|
|
16
|
-
noVotes: TSchema.Integer,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export type PollStatus = typeof PollStatusSchema.Type;
|
|
20
|
-
|
|
21
|
-
const PollManagerContentSchema = TSchema.Struct({
|
|
22
|
-
pollId: TSchema.Integer,
|
|
23
|
-
pollOwner: TSchema.ByteArray,
|
|
24
|
-
content: ProposalContentSchema,
|
|
25
|
-
treasuryWithdrawal: TSchema.NullOr(TreasuryWithdrawalSchema),
|
|
26
|
-
status: PollStatusSchema,
|
|
27
|
-
votingEndTime: TSchema.Integer,
|
|
28
|
-
createdShardsCount: TSchema.Integer,
|
|
29
|
-
talliedShardsCount: TSchema.Integer,
|
|
30
|
-
totalShardsCount: TSchema.Integer,
|
|
31
|
-
proposingEndTime: TSchema.Integer,
|
|
32
|
-
expirationTime: TSchema.Integer,
|
|
33
|
-
protocolVersion: TSchema.Integer,
|
|
34
|
-
minimumQuorum: TSchema.Integer,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export type PollManagerContent = typeof PollManagerContentSchema.Type;
|
|
38
|
-
|
|
39
|
-
const PollShardContentSchema = TSchema.Struct({
|
|
40
|
-
pollId: TSchema.Integer,
|
|
41
|
-
status: PollStatusSchema,
|
|
42
|
-
votingEndTime: TSchema.Integer,
|
|
43
|
-
managerAddress: AddressSchema,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export type PollShardContent = typeof PollShardContentSchema.Type;
|
|
47
|
-
|
|
48
|
-
const PollDatumSchema = TSchema.Union(
|
|
49
|
-
TSchema.Struct(
|
|
50
|
-
{
|
|
51
|
-
PollManager: PollManagerContentSchema,
|
|
52
|
-
},
|
|
53
|
-
{ flatInUnion: true },
|
|
54
|
-
),
|
|
55
|
-
TSchema.Struct({ PollShard: PollShardContentSchema }, { flatInUnion: true }),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
export type PollDatum = typeof PollDatumSchema.Type;
|
|
59
|
-
|
|
60
|
-
const VoteOptionSchema = TSchema.Union(
|
|
61
|
-
TSchema.Literal('Yes', { flatInUnion: true }),
|
|
62
|
-
TSchema.Literal('No', { flatInUnion: true }),
|
|
63
|
-
);
|
|
64
|
-
export type VoteOption = typeof VoteOptionSchema.Type;
|
|
65
|
-
|
|
66
|
-
const PollShardRedeemerSchema = TSchema.Union(
|
|
67
|
-
TSchema.Struct({ Vote: VoteOptionSchema }, { flatInUnion: true }),
|
|
68
|
-
TSchema.Struct(
|
|
69
|
-
{
|
|
70
|
-
MergeShards: TSchema.Struct(
|
|
71
|
-
{
|
|
72
|
-
currentTime: TSchema.Integer,
|
|
73
|
-
pollManagerRef: OutputReferenceSchema,
|
|
74
|
-
},
|
|
75
|
-
{ flatFields: true },
|
|
76
|
-
),
|
|
77
|
-
},
|
|
78
|
-
{ flatInUnion: true },
|
|
79
|
-
),
|
|
80
|
-
);
|
|
81
|
-
export type PollShardRedeemer = typeof PollShardRedeemerSchema.Type;
|
|
82
|
-
|
|
83
|
-
const PollManagerRedeemerSchema = TSchema.Union(
|
|
84
|
-
TSchema.Struct(
|
|
85
|
-
{
|
|
86
|
-
EndPoll: TSchema.Struct(
|
|
87
|
-
{ currentTime: TSchema.Integer },
|
|
88
|
-
{ flatFields: true },
|
|
89
|
-
),
|
|
90
|
-
},
|
|
91
|
-
{ flatInUnion: true },
|
|
92
|
-
),
|
|
93
|
-
TSchema.Struct(
|
|
94
|
-
{
|
|
95
|
-
CreateShards: TSchema.Struct(
|
|
96
|
-
{ currentTime: TSchema.Integer },
|
|
97
|
-
{ flatFields: true },
|
|
98
|
-
),
|
|
99
|
-
},
|
|
100
|
-
{ flatInUnion: true },
|
|
101
|
-
),
|
|
102
|
-
TSchema.Struct(
|
|
103
|
-
{
|
|
104
|
-
MergeShardsManager: TSchema.Struct(
|
|
105
|
-
{ currentTime: TSchema.Integer },
|
|
106
|
-
{ flatFields: true },
|
|
107
|
-
),
|
|
108
|
-
},
|
|
109
|
-
{ flatInUnion: true },
|
|
110
|
-
),
|
|
111
|
-
);
|
|
112
|
-
export type PollManagerRedeemer = typeof PollManagerRedeemerSchema.Type;
|
|
113
|
-
|
|
114
|
-
export function serialisePollManagerRedeemer(r: PollManagerRedeemer): string {
|
|
115
|
-
return Data.withSchema(PollManagerRedeemerSchema).toCBORHex(r);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function serialisePollShardRedeemer(r: PollShardRedeemer): string {
|
|
119
|
-
return Data.withSchema(PollShardRedeemerSchema).toCBORHex(r);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function parsePollShardRedeemer(
|
|
123
|
-
datum: string,
|
|
124
|
-
): O.Option<PollShardRedeemer> {
|
|
125
|
-
try {
|
|
126
|
-
return O.some(
|
|
127
|
-
Data.withSchema(
|
|
128
|
-
PollShardRedeemerSchema,
|
|
129
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
130
|
-
).fromCBORHex(datum),
|
|
131
|
-
);
|
|
132
|
-
} catch (_) {
|
|
133
|
-
return O.none;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function parsePollShardRedeemerOrThrow(
|
|
138
|
-
datum: string,
|
|
139
|
-
): PollShardRedeemer {
|
|
140
|
-
return F.pipe(
|
|
141
|
-
parsePollShardRedeemer(datum),
|
|
142
|
-
O.match(() => {
|
|
143
|
-
throw new Error('Expected a poll shard redeemer.');
|
|
144
|
-
}, F.identity),
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function parsePollManager(datum: string): O.Option<PollManagerContent> {
|
|
149
|
-
try {
|
|
150
|
-
return match(
|
|
151
|
-
Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
152
|
-
datum,
|
|
153
|
-
),
|
|
154
|
-
)
|
|
155
|
-
.with({ PollManager: P.select() }, (res) => O.some(res))
|
|
156
|
-
.otherwise(() => O.none);
|
|
157
|
-
} catch (_) {
|
|
158
|
-
return O.none;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function parsePollManagerOrThrow(datum: string): PollManagerContent {
|
|
163
|
-
return F.pipe(
|
|
164
|
-
parsePollManager(datum),
|
|
165
|
-
O.match(() => {
|
|
166
|
-
throw new Error('Expected a poll manager datum.');
|
|
167
|
-
}, F.identity),
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function parsePollShard(datum: string): O.Option<PollShardContent> {
|
|
172
|
-
try {
|
|
173
|
-
return match(
|
|
174
|
-
Data.withSchema(PollDatumSchema, DEFAULT_SCHEMA_OPTIONS).fromCBORHex(
|
|
175
|
-
datum,
|
|
176
|
-
),
|
|
177
|
-
)
|
|
178
|
-
.with({ PollShard: P.select() }, (res) => O.some(res))
|
|
179
|
-
.otherwise(() => O.none);
|
|
180
|
-
} catch (_) {
|
|
181
|
-
return O.none;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function parsePollShardOrThrow(datum: string): PollShardContent {
|
|
186
|
-
return F.pipe(
|
|
187
|
-
parsePollShard(datum),
|
|
188
|
-
O.match(() => {
|
|
189
|
-
throw new Error('Expected a poll shard datum.');
|
|
190
|
-
}, F.identity),
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function serialisePollDatum(d: PollDatum): string {
|
|
195
|
-
return Data.withSchema(PollDatumSchema).toCBORHex(d);
|
|
196
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
-
|
|
4
|
-
const PollShardParamsSchema = Data.Object({
|
|
5
|
-
pollToken: AssetClassSchema,
|
|
6
|
-
stakingToken: AssetClassSchema,
|
|
7
|
-
indyAsset: AssetClassSchema,
|
|
8
|
-
stakingValHash: Data.Bytes(),
|
|
9
|
-
});
|
|
10
|
-
export type PollShardParams = Data.Static<typeof PollShardParamsSchema>;
|
|
11
|
-
export const PollShardParams =
|
|
12
|
-
PollShardParamsSchema as unknown as PollShardParams;
|
|
13
|
-
|
|
14
|
-
export function castPollShardParams(params: PollShardParams): Data {
|
|
15
|
-
return Data.castTo(params, PollShardParams);
|
|
16
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution } from '@lucid-evolution/lucid';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Calculates the validity range based on the oracle expiration,
|
|
5
|
-
* and caps the upper bound when necessary.
|
|
6
|
-
*/
|
|
7
|
-
export function oracleExpirationAwareValidity(
|
|
8
|
-
lucid: LucidEvolution,
|
|
9
|
-
biasTime: number,
|
|
10
|
-
oracleExpiration: number,
|
|
11
|
-
): {
|
|
12
|
-
validFrom: number;
|
|
13
|
-
validTo: number;
|
|
14
|
-
} {
|
|
15
|
-
const validateFrom = lucid.slotToUnixTime(lucid.currentSlot() - 1);
|
|
16
|
-
const defaultValidateTo = validateFrom + biasTime;
|
|
17
|
-
/// Take the oracle expiration time - 1 slot which is the last acceptable non-expired valid_to time
|
|
18
|
-
/// for the current oracle.
|
|
19
|
-
const cappedValidateTo = lucid.slotToUnixTime(
|
|
20
|
-
lucid.unixTimeToSlot(oracleExpiration) - 1,
|
|
21
|
-
);
|
|
22
|
-
const isOracleActuallyExpired = cappedValidateTo <= validateFrom;
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
validFrom: validateFrom,
|
|
26
|
-
validTo: isOracleActuallyExpired
|
|
27
|
-
? defaultValidateTo
|
|
28
|
-
: Math.min(defaultValidateTo, cappedValidateTo),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
applyParamsToScript,
|
|
3
|
-
ScriptType,
|
|
4
|
-
SpendingValidator,
|
|
5
|
-
} from '@lucid-evolution/lucid';
|
|
6
|
-
import { castPriceOracleParams, PriceOracleParams } from './types';
|
|
7
|
-
import { _priceOracleValidator } from '../../validators/price-oracle-validator';
|
|
8
|
-
|
|
9
|
-
export function mkPriceOracleValidator(
|
|
10
|
-
params: PriceOracleParams,
|
|
11
|
-
): SpendingValidator {
|
|
12
|
-
return {
|
|
13
|
-
type: 'PlutusV3' as ScriptType,
|
|
14
|
-
script: applyParamsToScript(_priceOracleValidator.cborHex, [
|
|
15
|
-
castPriceOracleParams(params),
|
|
16
|
-
]),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Data,
|
|
4
|
-
fromHex,
|
|
5
|
-
fromText,
|
|
6
|
-
LucidEvolution,
|
|
7
|
-
OutRef,
|
|
8
|
-
TxBuilder,
|
|
9
|
-
validatorToAddress,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import { PriceOracleParams } from './types';
|
|
12
|
-
import { mkPriceOracleValidator } from './scripts';
|
|
13
|
-
import { oneShotMintTx } from '../one-shot/transactions';
|
|
14
|
-
import { AssetClass, mkAssetsOf } from '@3rd-eye-labs/cardano-offchain-common';
|
|
15
|
-
import { matchSingle } from '../../utils/utils';
|
|
16
|
-
import { ONE_SECOND } from '../../utils/time-helpers';
|
|
17
|
-
import {
|
|
18
|
-
PriceOracleDatum,
|
|
19
|
-
serialisePriceOracleDatum,
|
|
20
|
-
serialisePriceOracleRedeemer,
|
|
21
|
-
} from './types-new';
|
|
22
|
-
import * as Core from '@evolution-sdk/evolution';
|
|
23
|
-
import { Rational } from '../../types/rational';
|
|
24
|
-
|
|
25
|
-
export async function startPriceOracleTx(
|
|
26
|
-
lucid: LucidEvolution,
|
|
27
|
-
assetName: string,
|
|
28
|
-
startPrice: Rational,
|
|
29
|
-
oracleParams: PriceOracleParams,
|
|
30
|
-
refOutRef?: OutRef,
|
|
31
|
-
auxiliaryData?: Core.Data.Data,
|
|
32
|
-
): Promise<[TxBuilder, AssetClass]> {
|
|
33
|
-
const now = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
34
|
-
|
|
35
|
-
if (!refOutRef) {
|
|
36
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const [tx, oracleNftPolicyId] = await oneShotMintTx(lucid, {
|
|
40
|
-
referenceOutRef: {
|
|
41
|
-
txHash: refOutRef.txHash,
|
|
42
|
-
outputIdx: BigInt(refOutRef.outputIndex),
|
|
43
|
-
},
|
|
44
|
-
mintAmounts: [
|
|
45
|
-
{
|
|
46
|
-
tokenName: fromText(assetName),
|
|
47
|
-
amount: 1n,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const priceOracleNft: AssetClass = {
|
|
53
|
-
currencySymbol: fromHex(oracleNftPolicyId),
|
|
54
|
-
tokenName: fromHex(fromText(assetName)),
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
58
|
-
|
|
59
|
-
const oracleDatum: PriceOracleDatum = {
|
|
60
|
-
price: startPrice,
|
|
61
|
-
expirationTime: BigInt(now) + oracleParams.expirationPeriod,
|
|
62
|
-
auxiliaryData: auxiliaryData ?? Core.Data.fromCBORHex(Data.void()),
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
tx.pay.ToContract(
|
|
66
|
-
validatorToAddress(lucid.config().network!, oracleValidator),
|
|
67
|
-
{ kind: 'inline', value: serialisePriceOracleDatum(oracleDatum) },
|
|
68
|
-
addAssets(mkAssetsOf(priceOracleNft, 1n)),
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return [tx, priceOracleNft];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function feedPriceOracleTx(
|
|
75
|
-
lucid: LucidEvolution,
|
|
76
|
-
oracleOref: OutRef,
|
|
77
|
-
newPrice: Rational,
|
|
78
|
-
oracleParams: PriceOracleParams,
|
|
79
|
-
auxiliaryData?: Core.Data.Data,
|
|
80
|
-
): Promise<TxBuilder> {
|
|
81
|
-
const currentTime = BigInt(lucid.slotToUnixTime(lucid.currentSlot()));
|
|
82
|
-
|
|
83
|
-
const priceOracleUtxo = matchSingle(
|
|
84
|
-
await lucid.utxosByOutRef([oracleOref]),
|
|
85
|
-
(_) => new Error('Expected a single price oracle UTXO'),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const oracleValidator = mkPriceOracleValidator(oracleParams);
|
|
89
|
-
|
|
90
|
-
return lucid
|
|
91
|
-
.newTx()
|
|
92
|
-
.validFrom(Number(currentTime - oracleParams.biasTime) + ONE_SECOND)
|
|
93
|
-
.validTo(Number(currentTime + oracleParams.biasTime) - ONE_SECOND)
|
|
94
|
-
.attach.SpendingValidator(oracleValidator)
|
|
95
|
-
.collectFrom(
|
|
96
|
-
[priceOracleUtxo],
|
|
97
|
-
serialisePriceOracleRedeemer({
|
|
98
|
-
currentTime: currentTime,
|
|
99
|
-
newPrice: newPrice,
|
|
100
|
-
}),
|
|
101
|
-
)
|
|
102
|
-
.pay.ToContract(
|
|
103
|
-
priceOracleUtxo.address,
|
|
104
|
-
{
|
|
105
|
-
kind: 'inline',
|
|
106
|
-
value: serialisePriceOracleDatum({
|
|
107
|
-
price: newPrice,
|
|
108
|
-
expirationTime: currentTime + oracleParams.expirationPeriod,
|
|
109
|
-
auxiliaryData: auxiliaryData ?? Core.Data.fromCBORHex(Data.void()),
|
|
110
|
-
}),
|
|
111
|
-
},
|
|
112
|
-
priceOracleUtxo.assets,
|
|
113
|
-
)
|
|
114
|
-
.addSignerKey(oracleParams.owner);
|
|
115
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
|
-
import { Schema } from 'effect';
|
|
3
|
-
import { RationalSchema } from '../../types/rational';
|
|
4
|
-
|
|
5
|
-
const OpaqueData = Schema.typeSchema(Data.DataSchema);
|
|
6
|
-
|
|
7
|
-
export const OracleIdxSchema = TSchema.Union(
|
|
8
|
-
TSchema.Struct(
|
|
9
|
-
{
|
|
10
|
-
OracleRefInputIdx: TSchema.Integer,
|
|
11
|
-
},
|
|
12
|
-
{ flatInUnion: true },
|
|
13
|
-
),
|
|
14
|
-
TSchema.Struct(
|
|
15
|
-
{
|
|
16
|
-
OracleOutputIdx: TSchema.Integer,
|
|
17
|
-
},
|
|
18
|
-
{ flatInUnion: true },
|
|
19
|
-
),
|
|
20
|
-
TSchema.Literal('OracleVoid', { flatInUnion: true }),
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
export type OracleIdx = typeof OracleIdxSchema.Type;
|
|
24
|
-
|
|
25
|
-
const PriceOracleDatumSchema = TSchema.Struct({
|
|
26
|
-
price: RationalSchema,
|
|
27
|
-
expirationTime: TSchema.Integer,
|
|
28
|
-
auxiliaryData: OpaqueData,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
export type PriceOracleDatum = typeof PriceOracleDatumSchema.Type;
|
|
32
|
-
|
|
33
|
-
const PriceOracleRedeemerSchema = TSchema.Struct({
|
|
34
|
-
currentTime: TSchema.Integer,
|
|
35
|
-
newPrice: RationalSchema,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
export type PriceOracleRedeemer = typeof PriceOracleRedeemerSchema.Type;
|
|
39
|
-
|
|
40
|
-
export function serialisePriceOracleRedeemer(r: PriceOracleRedeemer): string {
|
|
41
|
-
return Data.withSchema(PriceOracleRedeemerSchema).toCBORHex(r);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function serialisePriceOracleDatum(d: PriceOracleDatum): string {
|
|
45
|
-
return Data.withSchema(PriceOracleDatumSchema).toCBORHex(d);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function parsePriceOracleDatum(datum: string): PriceOracleDatum {
|
|
49
|
-
return Data.withSchema(PriceOracleDatumSchema).fromCBORHex(datum);
|
|
50
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
|
|
3
|
-
export const PriceOracleParamsSchema = Data.Object({
|
|
4
|
-
owner: Data.Bytes(),
|
|
5
|
-
/** Milliseconds */
|
|
6
|
-
biasTime: Data.Integer(),
|
|
7
|
-
/** Milliseconds */
|
|
8
|
-
expirationPeriod: Data.Integer(),
|
|
9
|
-
});
|
|
10
|
-
export type PriceOracleParams = Data.Static<typeof PriceOracleParamsSchema>;
|
|
11
|
-
const PriceOracleParams =
|
|
12
|
-
PriceOracleParamsSchema as unknown as PriceOracleParams;
|
|
13
|
-
|
|
14
|
-
export function castPriceOracleParams(params: PriceOracleParams): Data {
|
|
15
|
-
return Data.castTo(params, PriceOracleParams);
|
|
16
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { match, P } from 'ts-pattern';
|
|
2
|
-
import { Rational } from '../../types/rational';
|
|
3
|
-
import { decodePriceUpdate, decodePythMessage } from '../../utils/pyth';
|
|
4
|
-
import {
|
|
5
|
-
DerivedPythPrice,
|
|
6
|
-
fromDataDerivedPythPrice,
|
|
7
|
-
PythConfiguration,
|
|
8
|
-
} from './types';
|
|
9
|
-
import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
|
|
10
|
-
import { fromHex } from '@lucid-evolution/lucid';
|
|
11
|
-
import { array as A, function as F } from 'fp-ts';
|
|
12
|
-
import { BigIntOrd } from '../../utils/bigint-utils';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Collect all unique price feed IDs in the derived price sorted ascending.
|
|
16
|
-
*/
|
|
17
|
-
export function collectPriceFeedIds(
|
|
18
|
-
derivedPythPrice: DerivedPythPrice,
|
|
19
|
-
): bigint[] {
|
|
20
|
-
const ids = match(derivedPythPrice)
|
|
21
|
-
.with({ Value: P.select() }, (value) => [
|
|
22
|
-
BigInt(value.configuration.priceFeedId),
|
|
23
|
-
])
|
|
24
|
-
.with({ Inverse: P.select() }, (inverse) =>
|
|
25
|
-
collectPriceFeedIds(fromDataDerivedPythPrice(inverse.value)),
|
|
26
|
-
)
|
|
27
|
-
.with({ Divide: P.select() }, (divide) => [
|
|
28
|
-
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.x)),
|
|
29
|
-
...collectPriceFeedIds(fromDataDerivedPythPrice(divide.y)),
|
|
30
|
-
])
|
|
31
|
-
.exhaustive();
|
|
32
|
-
|
|
33
|
-
return F.pipe(ids, A.uniq(BigIntOrd), A.sort(BigIntOrd));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Rational form { num, den } so we can do exact division (e.g. 1/0.00001 = 100000). */
|
|
37
|
-
export function derivePythPrice(
|
|
38
|
-
derivedPythPrice: DerivedPythPrice,
|
|
39
|
-
messageHex: string,
|
|
40
|
-
): Rational {
|
|
41
|
-
const decodedMessage = decodePythMessage(fromHex(messageHex));
|
|
42
|
-
const pricePayload = decodePriceUpdate(decodedMessage.payload);
|
|
43
|
-
return match(derivedPythPrice)
|
|
44
|
-
.with(
|
|
45
|
-
{ Value: P.select() },
|
|
46
|
-
(value: { configuration: PythConfiguration }) => {
|
|
47
|
-
const payload = pricePayload.priceFeeds.find(
|
|
48
|
-
(p: ParsedFeedPayload) =>
|
|
49
|
-
p.priceFeedId === Number(value.configuration.priceFeedId),
|
|
50
|
-
);
|
|
51
|
-
if (!payload)
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Pyth payload not found for feed ID: ${value.configuration.priceFeedId}`,
|
|
54
|
-
);
|
|
55
|
-
const priceStr = payload.price;
|
|
56
|
-
if (priceStr === undefined)
|
|
57
|
-
throw new Error(`Pyth feed ${payload.priceFeedId} has no price`);
|
|
58
|
-
const price = BigInt(priceStr);
|
|
59
|
-
const exp = payload.exponent ?? 0;
|
|
60
|
-
if (exp >= 0) {
|
|
61
|
-
return { numerator: price * 10n ** BigInt(exp), denominator: 1n };
|
|
62
|
-
}
|
|
63
|
-
return { numerator: price, denominator: 10n ** BigInt(-exp) };
|
|
64
|
-
},
|
|
65
|
-
)
|
|
66
|
-
.with({ Inverse: P.select() }, (inverse) => {
|
|
67
|
-
const inner = derivePythPrice(
|
|
68
|
-
fromDataDerivedPythPrice(inverse.value),
|
|
69
|
-
messageHex,
|
|
70
|
-
);
|
|
71
|
-
return { numerator: inner.denominator, denominator: inner.numerator };
|
|
72
|
-
})
|
|
73
|
-
.with({ Divide: P.select() }, (divide) => {
|
|
74
|
-
const x = derivePythPrice(fromDataDerivedPythPrice(divide.x), messageHex);
|
|
75
|
-
const y = derivePythPrice(fromDataDerivedPythPrice(divide.y), messageHex);
|
|
76
|
-
return {
|
|
77
|
-
numerator: x.numerator * y.denominator,
|
|
78
|
-
denominator: x.denominator * y.numerator,
|
|
79
|
-
};
|
|
80
|
-
})
|
|
81
|
-
.exhaustive();
|
|
82
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SpendingValidator } from '@lucid-evolution/lucid';
|
|
2
|
-
import { _pythFeedValidator } from '../../validators/pyth-feed-validator';
|
|
3
|
-
import { applyParamsToScript } from '@evolution-sdk/evolution/uplc';
|
|
4
|
-
import { PythFeedParams, serialisePythFeedParams } from './types';
|
|
5
|
-
|
|
6
|
-
export const mkPythFeedValidator = (
|
|
7
|
-
params: PythFeedParams,
|
|
8
|
-
): SpendingValidator => {
|
|
9
|
-
return {
|
|
10
|
-
type: 'PlutusV3',
|
|
11
|
-
script: applyParamsToScript(_pythFeedValidator.cborHex, [
|
|
12
|
-
serialisePythFeedParams(params),
|
|
13
|
-
]),
|
|
14
|
-
};
|
|
15
|
-
};
|