@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
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import {
|
|
2
|
+
credentialToRewardAddress,
|
|
3
|
+
Data,
|
|
4
|
+
Emulator,
|
|
5
|
+
EmulatorAccount,
|
|
6
|
+
fromHex,
|
|
7
|
+
generateEmulatorAccount,
|
|
8
|
+
Lucid,
|
|
9
|
+
scriptHashToCredential,
|
|
10
|
+
slotToUnixTime,
|
|
11
|
+
toHex,
|
|
12
|
+
validatorToScriptHash,
|
|
13
|
+
} from '@lucid-evolution/lucid';
|
|
14
|
+
import { beforeEach, describe, expect, test } from 'vitest';
|
|
15
|
+
import { LucidContext, runAndAwaitTxBuilder } from '../test-helpers';
|
|
16
|
+
import {
|
|
17
|
+
initPyth,
|
|
18
|
+
TEST_TRUSTED_SIGNER_PRIV_KEY,
|
|
19
|
+
TEST_TRUSTED_SIGNER_PUB_KEY,
|
|
20
|
+
} from './endpoints';
|
|
21
|
+
import {
|
|
22
|
+
PythFeedParams,
|
|
23
|
+
PythStateDatum,
|
|
24
|
+
serialisePythFeedRedeemer,
|
|
25
|
+
serialisePythStateDatum,
|
|
26
|
+
serialisePythUpdatesRedeemer,
|
|
27
|
+
toDataDerivedPythPrice,
|
|
28
|
+
} from '../../src/contracts/pyth-feed/types';
|
|
29
|
+
import { assetClassToUnit } from '@3rd-eye-labs/cardano-offchain-common';
|
|
30
|
+
import { mkPythFeedValidator } from '../../src/contracts/pyth-feed/scripts';
|
|
31
|
+
import { alwaysSucceedValidator } from '../always-succeed/script';
|
|
32
|
+
import {
|
|
33
|
+
encodePriceUpdate,
|
|
34
|
+
encodePythMessage,
|
|
35
|
+
type PriceUpdate,
|
|
36
|
+
type PythMessageParts,
|
|
37
|
+
} from '../../src/utils/pyth';
|
|
38
|
+
import { MAINNET_PROTOCOL_PARAMETERS } from '../indigo-test-helpers';
|
|
39
|
+
import { createPythMessage } from './helpers';
|
|
40
|
+
import { ParsedFeedPayload } from '@pythnetwork/pyth-lazer-sdk';
|
|
41
|
+
import { derivePythPrice } from '../../src/contracts/pyth-feed/helpers';
|
|
42
|
+
import * as Core from '@evolution-sdk/evolution';
|
|
43
|
+
|
|
44
|
+
type MyContext = LucidContext<{
|
|
45
|
+
admin: EmulatorAccount;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
describe('Pyth > Initialization', () => {
|
|
49
|
+
beforeEach<MyContext>(async (context: MyContext) => {
|
|
50
|
+
context.users = {
|
|
51
|
+
admin: generateEmulatorAccount({
|
|
52
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
53
|
+
}),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
context.emulator = new Emulator(
|
|
57
|
+
[context.users.admin],
|
|
58
|
+
MAINNET_PROTOCOL_PARAMETERS,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
62
|
+
context.lucid.selectWallet.fromSeed(context.users.admin.seedPhrase);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('initPyth initializes the Pyth State NFT', async (context: MyContext) => {
|
|
66
|
+
const pythStateAsset = await initPyth(context.lucid);
|
|
67
|
+
|
|
68
|
+
expect(pythStateAsset).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('Properly serializes a Pyth State datum', (_context: MyContext) => {
|
|
72
|
+
const pythStateDatum: PythStateDatum = {
|
|
73
|
+
governance: {
|
|
74
|
+
wormhole: fromHex(''),
|
|
75
|
+
emitterChain: 0n,
|
|
76
|
+
emitterAddress: fromHex(''),
|
|
77
|
+
seenSequence: 0n,
|
|
78
|
+
},
|
|
79
|
+
trustedSigners: new Map([
|
|
80
|
+
[
|
|
81
|
+
fromHex(
|
|
82
|
+
'4a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71f',
|
|
83
|
+
),
|
|
84
|
+
{
|
|
85
|
+
lower_bound: {
|
|
86
|
+
bound_type: {
|
|
87
|
+
_tag: 'NegativeInfinity',
|
|
88
|
+
},
|
|
89
|
+
is_inclusive: true,
|
|
90
|
+
},
|
|
91
|
+
upper_bound: {
|
|
92
|
+
bound_type: {
|
|
93
|
+
_tag: 'Finite',
|
|
94
|
+
finite: 1n,
|
|
95
|
+
},
|
|
96
|
+
is_inclusive: true,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
]),
|
|
101
|
+
deprecatedWithdrawScripts: new Map(),
|
|
102
|
+
withdraw_script: fromHex(
|
|
103
|
+
'7688145a4fa7aa18c16ef0daafeec18091ab99ea4268cfe2d863c79fda131938',
|
|
104
|
+
),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const serialisedPythStateDatum = serialisePythStateDatum(pythStateDatum);
|
|
108
|
+
expect(serialisedPythStateDatum).toBe(
|
|
109
|
+
'd8799fd8799f40004000ffa158204a50d7c3d16b2be5c16ba996109a455a34cce08a81b3e15b86ef407e2f72e71fd8799fd8799fd87980d87a80ffd8799fd87a9f01ffd87a80ffffa058207688145a4fa7aa18c16ef0daafeec18091ab99ea4268cfe2d863c79fda131938ff',
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('Pyth Feed validator can confirm a Pyth Message', async (context: MyContext) => {
|
|
114
|
+
const pythStateAsset = await initPyth(context.lucid);
|
|
115
|
+
|
|
116
|
+
const noble = await import('@noble/ed25519');
|
|
117
|
+
const priceFeedId = 1;
|
|
118
|
+
const price = 1000n;
|
|
119
|
+
const exponent = -8;
|
|
120
|
+
|
|
121
|
+
const params: PythFeedParams = {
|
|
122
|
+
pythStatePolicyId: pythStateAsset.currencySymbol,
|
|
123
|
+
config: {
|
|
124
|
+
Value: { configuration: { priceFeedId: BigInt(priceFeedId) } },
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const pfvValidator = mkPythFeedValidator(params);
|
|
129
|
+
const pfvValHash = validatorToScriptHash(pfvValidator);
|
|
130
|
+
|
|
131
|
+
// Register the stake key for pyth feed validator.
|
|
132
|
+
await runAndAwaitTxBuilder(
|
|
133
|
+
context.lucid,
|
|
134
|
+
context.lucid.newTx().register.Stake(
|
|
135
|
+
credentialToRewardAddress(context.lucid.config().network!, {
|
|
136
|
+
hash: pfvValHash,
|
|
137
|
+
type: 'Script',
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const currentTime = BigInt(
|
|
143
|
+
slotToUnixTime(context.lucid.config().network!, context.emulator.slot),
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// This is to test the transaction validity when using a timestamp different than the
|
|
147
|
+
// slot boundary (which is the usual and general case).
|
|
148
|
+
const timestamp = currentTime - 10n;
|
|
149
|
+
|
|
150
|
+
const update: PriceUpdate = {
|
|
151
|
+
timestampUs: (timestamp * 1_000n).toString(),
|
|
152
|
+
channelId: 0,
|
|
153
|
+
priceFeeds: [
|
|
154
|
+
{
|
|
155
|
+
priceFeedId,
|
|
156
|
+
price: price.toString(),
|
|
157
|
+
exponent,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
const payload = encodePriceUpdate(update);
|
|
162
|
+
const signature = await noble.signAsync(
|
|
163
|
+
payload,
|
|
164
|
+
fromHex(TEST_TRUSTED_SIGNER_PRIV_KEY),
|
|
165
|
+
);
|
|
166
|
+
const parts: PythMessageParts = {
|
|
167
|
+
signature,
|
|
168
|
+
publicKey: fromHex(TEST_TRUSTED_SIGNER_PUB_KEY),
|
|
169
|
+
payload,
|
|
170
|
+
};
|
|
171
|
+
const message = encodePythMessage(parts);
|
|
172
|
+
|
|
173
|
+
const pythStateUtxo = await context.lucid.utxoByUnit(
|
|
174
|
+
assetClassToUnit(pythStateAsset),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
await runAndAwaitTxBuilder(
|
|
178
|
+
context.lucid,
|
|
179
|
+
context.lucid
|
|
180
|
+
.newTx()
|
|
181
|
+
.readFrom([pythStateUtxo])
|
|
182
|
+
.attach.Script(pfvValidator)
|
|
183
|
+
.validFrom(Number(timestamp))
|
|
184
|
+
.validTo(Number(timestamp) + 60 * 1000)
|
|
185
|
+
.withdraw(
|
|
186
|
+
credentialToRewardAddress(
|
|
187
|
+
context.lucid.config().network!,
|
|
188
|
+
scriptHashToCredential(pfvValHash),
|
|
189
|
+
),
|
|
190
|
+
0n,
|
|
191
|
+
serialisePythFeedRedeemer({
|
|
192
|
+
price: {
|
|
193
|
+
numerator: 1_000n,
|
|
194
|
+
denominator: 100_000_000n,
|
|
195
|
+
},
|
|
196
|
+
auxiliaryData: Core.Data.fromCBORHex(Data.void()),
|
|
197
|
+
}),
|
|
198
|
+
)
|
|
199
|
+
.withdraw(
|
|
200
|
+
credentialToRewardAddress(
|
|
201
|
+
context.lucid.config().network!,
|
|
202
|
+
scriptHashToCredential(
|
|
203
|
+
validatorToScriptHash(alwaysSucceedValidator),
|
|
204
|
+
),
|
|
205
|
+
),
|
|
206
|
+
0n,
|
|
207
|
+
serialisePythUpdatesRedeemer([message]),
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
describe('Pyth > Helper functions', () => {
|
|
214
|
+
test('derivePythPrice works', async () => {
|
|
215
|
+
const feed1: ParsedFeedPayload = {
|
|
216
|
+
priceFeedId: 1,
|
|
217
|
+
price: '1000',
|
|
218
|
+
exponent: -8,
|
|
219
|
+
};
|
|
220
|
+
const feed2: ParsedFeedPayload = {
|
|
221
|
+
priceFeedId: 2,
|
|
222
|
+
price: '99',
|
|
223
|
+
exponent: 0,
|
|
224
|
+
};
|
|
225
|
+
const feed3: ParsedFeedPayload = {
|
|
226
|
+
priceFeedId: 3,
|
|
227
|
+
price: '45',
|
|
228
|
+
exponent: 0,
|
|
229
|
+
};
|
|
230
|
+
const message = await createPythMessage(
|
|
231
|
+
[feed1, feed2, feed3],
|
|
232
|
+
BigInt(Date.now()),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
// Single direct value
|
|
236
|
+
// 1000 * 10^-8 = 0.00001
|
|
237
|
+
{
|
|
238
|
+
const price = derivePythPrice(
|
|
239
|
+
{
|
|
240
|
+
Value: {
|
|
241
|
+
configuration: { priceFeedId: 1n },
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
toHex(message),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
expect(price.numerator).toBe(1_000n);
|
|
248
|
+
expect(price.denominator).toBe(100_000_000n);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Single inverse value: 1 / (1000 * 10^-8) = 1 / 0.00001 = 100000
|
|
252
|
+
{
|
|
253
|
+
const price = derivePythPrice(
|
|
254
|
+
{
|
|
255
|
+
Inverse: {
|
|
256
|
+
value: toDataDerivedPythPrice({
|
|
257
|
+
Value: {
|
|
258
|
+
configuration: {
|
|
259
|
+
priceFeedId: 1n,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
toHex(message),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(price.numerator).toBe(100_000_000n);
|
|
269
|
+
expect(price.denominator).toBe(1_000n);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Single divide value: 99 / 45 = 2.2
|
|
273
|
+
{
|
|
274
|
+
const price = derivePythPrice(
|
|
275
|
+
{
|
|
276
|
+
Divide: {
|
|
277
|
+
x: toDataDerivedPythPrice({
|
|
278
|
+
Value: {
|
|
279
|
+
configuration: {
|
|
280
|
+
priceFeedId: 2n,
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
}),
|
|
284
|
+
y: toDataDerivedPythPrice({
|
|
285
|
+
Value: {
|
|
286
|
+
configuration: {
|
|
287
|
+
priceFeedId: 3n,
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
}),
|
|
291
|
+
},
|
|
292
|
+
},
|
|
293
|
+
toHex(message),
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
expect(price.numerator).toBe(99n);
|
|
297
|
+
expect(price.denominator).toBe(45n);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
});
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
+
import { createScriptAddress, matchSingle } from '../../src';
|
|
3
|
+
import { option as O, array as A, function as F } from 'fp-ts';
|
|
2
4
|
import {
|
|
3
5
|
AssetClass,
|
|
4
|
-
|
|
6
|
+
assetClassToUnit,
|
|
7
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
8
|
+
import {
|
|
5
9
|
ExecuteDatum,
|
|
6
|
-
matchSingle,
|
|
7
10
|
parseExecuteDatum,
|
|
8
|
-
} from '../../src';
|
|
9
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
10
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
11
|
+
} from '../../src/contracts/execute/types-new';
|
|
11
12
|
|
|
12
13
|
export async function findExecute(
|
|
13
14
|
lucid: LucidEvolution,
|
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
fromText,
|
|
3
|
+
LucidEvolution,
|
|
4
|
+
ScriptHash,
|
|
5
|
+
toHex,
|
|
6
|
+
toText,
|
|
7
|
+
} from '@lucid-evolution/lucid';
|
|
2
8
|
import { createScriptAddress } from '../../src/utils/lucid-utils';
|
|
3
|
-
import {
|
|
4
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
5
|
-
import { IAssetOutput, matchSingle, parseIAssetDatum } from '../../src';
|
|
9
|
+
import { fromSystemParamsAsset, matchSingle, SystemParams } from '../../src';
|
|
6
10
|
import { option as O, array as A, function as F } from 'fp-ts';
|
|
11
|
+
import {
|
|
12
|
+
AssetClass,
|
|
13
|
+
assetClassToUnit,
|
|
14
|
+
isSameAssetClass,
|
|
15
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
16
|
+
import {
|
|
17
|
+
CollateralAssetOutput,
|
|
18
|
+
IAssetOutput,
|
|
19
|
+
parseCollateralAssetDatum,
|
|
20
|
+
parseIAssetDatum,
|
|
21
|
+
} from '../../src/contracts/iasset/types';
|
|
22
|
+
import { LucidContext } from '../test-helpers';
|
|
7
23
|
|
|
24
|
+
// TODO: replace with the new variant defined below
|
|
8
25
|
export async function findIAsset(
|
|
9
26
|
lucid: LucidEvolution,
|
|
10
27
|
iassetScriptHash: ScriptHash,
|
|
@@ -24,7 +41,45 @@ export async function findIAsset(
|
|
|
24
41
|
O.fromNullable(utxo.datum),
|
|
25
42
|
O.flatMap(parseIAssetDatum),
|
|
26
43
|
O.flatMap((datum) => {
|
|
27
|
-
if (datum.assetName === fromText(iassetName)) {
|
|
44
|
+
if (toHex(datum.assetName) === fromText(iassetName)) {
|
|
45
|
+
return O.some({ utxo, datum: datum });
|
|
46
|
+
} else {
|
|
47
|
+
return O.none;
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
A.compact,
|
|
53
|
+
),
|
|
54
|
+
(res) =>
|
|
55
|
+
new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function findIAssetNew(
|
|
60
|
+
context: LucidContext,
|
|
61
|
+
sysParams: SystemParams,
|
|
62
|
+
// Ascii encoded
|
|
63
|
+
iassetName: string,
|
|
64
|
+
): Promise<IAssetOutput> {
|
|
65
|
+
const iassetUtxos = await context.lucid.utxosAtWithUnit(
|
|
66
|
+
createScriptAddress(
|
|
67
|
+
context.lucid.config().network!,
|
|
68
|
+
sysParams.validatorHashes.iassetHash,
|
|
69
|
+
),
|
|
70
|
+
assetClassToUnit(
|
|
71
|
+
fromSystemParamsAsset(sysParams.cdpParams.iAssetAuthToken),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
return matchSingle(
|
|
76
|
+
F.pipe(
|
|
77
|
+
iassetUtxos.map((utxo) =>
|
|
78
|
+
F.pipe(
|
|
79
|
+
O.fromNullable(utxo.datum),
|
|
80
|
+
O.flatMap(parseIAssetDatum),
|
|
81
|
+
O.flatMap((datum) => {
|
|
82
|
+
if (toHex(datum.assetName) === fromText(iassetName)) {
|
|
28
83
|
return O.some({ utxo, datum: datum });
|
|
29
84
|
} else {
|
|
30
85
|
return O.none;
|
|
@@ -60,3 +115,118 @@ export async function findAllIAssets(
|
|
|
60
115
|
A.compact,
|
|
61
116
|
);
|
|
62
117
|
}
|
|
118
|
+
|
|
119
|
+
// TODO: replace by the new variant defined below
|
|
120
|
+
export async function findCollateralAsset(
|
|
121
|
+
lucid: LucidEvolution,
|
|
122
|
+
sysParams: SystemParams,
|
|
123
|
+
collateralAssetNft: AssetClass,
|
|
124
|
+
// Ascii encoded
|
|
125
|
+
iassetName: string,
|
|
126
|
+
collateralAsset: AssetClass,
|
|
127
|
+
): Promise<CollateralAssetOutput> {
|
|
128
|
+
const collateralAssetUtxos = await lucid.utxosAtWithUnit(
|
|
129
|
+
createScriptAddress(
|
|
130
|
+
lucid.config().network!,
|
|
131
|
+
sysParams.validatorHashes.iassetHash,
|
|
132
|
+
),
|
|
133
|
+
assetClassToUnit(collateralAssetNft),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
return matchSingle(
|
|
137
|
+
F.pipe(
|
|
138
|
+
collateralAssetUtxos.map((utxo) =>
|
|
139
|
+
F.pipe(
|
|
140
|
+
O.fromNullable(utxo.datum),
|
|
141
|
+
O.flatMap(parseCollateralAssetDatum),
|
|
142
|
+
O.flatMap((datum) => {
|
|
143
|
+
if (
|
|
144
|
+
isSameAssetClass(datum.collateralAsset, collateralAsset) &&
|
|
145
|
+
fromText(iassetName) === toHex(datum.iasset)
|
|
146
|
+
) {
|
|
147
|
+
return O.some({ utxo, datum: datum });
|
|
148
|
+
} else {
|
|
149
|
+
return O.none;
|
|
150
|
+
}
|
|
151
|
+
}),
|
|
152
|
+
),
|
|
153
|
+
),
|
|
154
|
+
A.compact,
|
|
155
|
+
),
|
|
156
|
+
(res) =>
|
|
157
|
+
new Error(
|
|
158
|
+
'Expected a single Collateral Asset UTXO.: ' + JSON.stringify(res),
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function findCollateralAssetNew(
|
|
164
|
+
context: LucidContext,
|
|
165
|
+
sysParams: SystemParams,
|
|
166
|
+
// Ascii encoded
|
|
167
|
+
iassetName: string,
|
|
168
|
+
collateralAsset: AssetClass,
|
|
169
|
+
): Promise<CollateralAssetOutput> {
|
|
170
|
+
const collateralAssetUtxos = await context.lucid.utxosAtWithUnit(
|
|
171
|
+
createScriptAddress(
|
|
172
|
+
context.lucid.config().network!,
|
|
173
|
+
sysParams.validatorHashes.iassetHash,
|
|
174
|
+
),
|
|
175
|
+
assetClassToUnit(
|
|
176
|
+
fromSystemParamsAsset(sysParams.cdpParams.collateralAssetAuthToken),
|
|
177
|
+
),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
return matchSingle(
|
|
181
|
+
F.pipe(
|
|
182
|
+
collateralAssetUtxos.map((utxo) =>
|
|
183
|
+
F.pipe(
|
|
184
|
+
O.fromNullable(utxo.datum),
|
|
185
|
+
O.flatMap(parseCollateralAssetDatum),
|
|
186
|
+
O.flatMap((datum) => {
|
|
187
|
+
if (
|
|
188
|
+
isSameAssetClass(datum.collateralAsset, collateralAsset) &&
|
|
189
|
+
fromText(iassetName) === toHex(datum.iasset)
|
|
190
|
+
) {
|
|
191
|
+
return O.some({ utxo, datum: datum });
|
|
192
|
+
} else {
|
|
193
|
+
return O.none;
|
|
194
|
+
}
|
|
195
|
+
}),
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
A.compact,
|
|
199
|
+
),
|
|
200
|
+
(res) =>
|
|
201
|
+
new Error(
|
|
202
|
+
'Expected a single Collateral Asset UTXO.: ' + JSON.stringify(res),
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function findAllCollateralAssetsOfIAsset(
|
|
208
|
+
lucid: LucidEvolution,
|
|
209
|
+
iassetScriptHash: ScriptHash,
|
|
210
|
+
collateralAssetNft: AssetClass,
|
|
211
|
+
iasset: Uint8Array<ArrayBufferLike>,
|
|
212
|
+
): Promise<CollateralAssetOutput[]> {
|
|
213
|
+
const collateralUtxos = await lucid.utxosAtWithUnit(
|
|
214
|
+
createScriptAddress(lucid.config().network!, iassetScriptHash),
|
|
215
|
+
assetClassToUnit(collateralAssetNft),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
return F.pipe(
|
|
219
|
+
collateralUtxos.map((utxo) =>
|
|
220
|
+
F.pipe(
|
|
221
|
+
O.fromNullable(utxo.datum),
|
|
222
|
+
O.flatMap(parseCollateralAssetDatum),
|
|
223
|
+
O.filter(
|
|
224
|
+
(collateralAsset) =>
|
|
225
|
+
toText(toHex(collateralAsset.iasset)) === toText(toHex(iasset)),
|
|
226
|
+
),
|
|
227
|
+
O.map((datum) => ({ utxo, datum: datum })),
|
|
228
|
+
),
|
|
229
|
+
),
|
|
230
|
+
A.compact,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AssetClass,
|
|
3
|
+
assetClassToUnit,
|
|
4
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
1
5
|
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClass } from '../../src/types/generic';
|
|
3
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
4
6
|
|
|
5
7
|
export async function findInterestOracle(
|
|
6
8
|
lucid: LucidEvolution,
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
+
|
|
3
|
+
import { matchSingle, createScriptAddress, getRandomElement } from '../../src';
|
|
4
|
+
import { option as O, array as A, function as F } from 'fp-ts';
|
|
5
|
+
import {
|
|
6
|
+
AssetClass,
|
|
7
|
+
assetClassToUnit,
|
|
8
|
+
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
2
9
|
import {
|
|
3
10
|
parsePollManager,
|
|
4
11
|
parsePollShard,
|
|
5
12
|
PollManagerContent,
|
|
6
13
|
PollShardContent,
|
|
7
|
-
} from '../../src/contracts/poll/types-poll';
|
|
8
|
-
import {
|
|
9
|
-
AssetClass,
|
|
10
|
-
matchSingle,
|
|
11
|
-
createScriptAddress,
|
|
12
|
-
getRandomElement,
|
|
13
|
-
} from '../../src';
|
|
14
|
-
import { assetClassToUnit } from '../../src/utils/value-helpers';
|
|
15
|
-
import { option as O, array as A, function as F } from 'fp-ts';
|
|
14
|
+
} from '../../src/contracts/poll/types-poll-new';
|
|
16
15
|
|
|
17
16
|
export async function findPollManager(
|
|
18
17
|
lucid: LucidEvolution,
|