@indigo-labs/indigo-sdk 0.2.41 → 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 -495
- 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
|
@@ -14,7 +14,7 @@ export function mkVersionRecordTokenPolicy(
|
|
|
14
14
|
params: VersionRecordTokenParams,
|
|
15
15
|
): MintingPolicy {
|
|
16
16
|
return {
|
|
17
|
-
type: '
|
|
17
|
+
type: 'PlutusV3',
|
|
18
18
|
script: applyParamsToScript(_versionRecordTokenPolicy.cborHex, [
|
|
19
19
|
castVersionRecordTokenParams(params),
|
|
20
20
|
]),
|
|
@@ -23,7 +23,7 @@ export function mkVersionRecordTokenPolicy(
|
|
|
23
23
|
|
|
24
24
|
export const mkVersionRegistryValidator = (): SpendingValidator => {
|
|
25
25
|
return {
|
|
26
|
-
type: '
|
|
26
|
+
type: 'PlutusV3',
|
|
27
27
|
script: _versionRegistryValidator.cborHex,
|
|
28
28
|
};
|
|
29
29
|
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
2
|
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
3
3
|
|
|
4
|
-
const VersionRecordDatumSchema =
|
|
5
|
-
upgradeId:
|
|
4
|
+
const VersionRecordDatumSchema = TSchema.Struct({
|
|
5
|
+
upgradeId: TSchema.Integer,
|
|
6
6
|
/// Underlying representation of the following mapping: ValidatorHash -> UpgradePath
|
|
7
|
-
upgradePaths:
|
|
8
|
-
|
|
9
|
-
EvoCore.TSchema.ByteArray,
|
|
7
|
+
upgradePaths: TSchema.Array(
|
|
8
|
+
TSchema.Tuple([TSchema.ByteArray, TSchema.ByteArray]),
|
|
10
9
|
),
|
|
11
10
|
});
|
|
12
11
|
export type VersionRecordDatum = typeof VersionRecordDatumSchema.Type;
|
|
13
12
|
|
|
14
13
|
export function serialiseVersionRecordDatum(d: VersionRecordDatum): string {
|
|
15
|
-
return
|
|
14
|
+
return Data.withSchema(
|
|
16
15
|
VersionRecordDatumSchema,
|
|
17
16
|
DEFAULT_SCHEMA_OPTIONS,
|
|
18
17
|
).toCBORHex(d);
|
package/src/index.ts
CHANGED
|
@@ -1,58 +1,75 @@
|
|
|
1
1
|
export * from './contracts/cdp/transactions';
|
|
2
2
|
export * from './contracts/cdp/helpers';
|
|
3
3
|
export * from './contracts/cdp/types';
|
|
4
|
+
export * from './contracts/cdp/types-new';
|
|
4
5
|
export * from './contracts/cdp/scripts';
|
|
5
6
|
export * from './contracts/cdp-creator/types';
|
|
6
7
|
export * from './contracts/cdp-creator/scripts';
|
|
7
8
|
export * from './contracts/poll/scripts';
|
|
8
9
|
export * from './contracts/collector/transactions';
|
|
9
|
-
export * from './contracts/collector/types';
|
|
10
|
+
export * from './contracts/collector/types-new';
|
|
10
11
|
export * from './contracts/gov/transactions';
|
|
11
12
|
export * from './contracts/gov/types';
|
|
12
13
|
export * from './contracts/gov/types-new';
|
|
13
14
|
export * from './contracts/stability-pool/transactions';
|
|
14
|
-
export * from './contracts/stability-pool/types-new';
|
|
15
|
-
export * from './contracts/staking/helpers';
|
|
16
15
|
export * from './contracts/staking/transactions';
|
|
17
|
-
export * from './contracts/staking/
|
|
16
|
+
export * from './contracts/staking/helpers';
|
|
18
17
|
export * from './contracts/staking/types-new';
|
|
18
|
+
export * from './contracts/staking/types';
|
|
19
19
|
export * from './contracts/interest-oracle/transactions';
|
|
20
20
|
export * from './contracts/interest-oracle/types';
|
|
21
|
-
export * from './contracts/interest-oracle/
|
|
21
|
+
export * from './contracts/interest-oracle/types-new';
|
|
22
22
|
export * from './contracts/interest-oracle/helpers';
|
|
23
|
-
export * from './contracts/
|
|
24
|
-
export * from './contracts/
|
|
25
|
-
export * from './contracts/
|
|
23
|
+
export * from './contracts/interest-collection/helpers';
|
|
24
|
+
export * from './contracts/interest-collection/types';
|
|
25
|
+
export * from './contracts/interest-collection/types-new';
|
|
26
|
+
export * from './contracts/interest-collection/scripts';
|
|
27
|
+
export * from './contracts/interest-collection/transactions';
|
|
28
|
+
export * from './contracts/interest-oracle/scripts';
|
|
26
29
|
export * from './contracts/version-registry/types';
|
|
27
30
|
export * from './contracts/version-registry/scripts';
|
|
28
31
|
export * from './contracts/treasury/transactions';
|
|
29
|
-
export * from './
|
|
32
|
+
export * from './contracts/treasury/helpers';
|
|
30
33
|
export * from './contracts/stability-pool/helpers';
|
|
31
34
|
export * from './utils/time-helpers';
|
|
32
35
|
export * from './contracts/cdp/scripts';
|
|
33
36
|
export * from './contracts/collector/scripts';
|
|
34
37
|
export * from './contracts/treasury/scripts';
|
|
35
|
-
export * from './contracts/treasury/types';
|
|
36
38
|
export * from './contracts/execute/types';
|
|
39
|
+
export * from './contracts/execute/types-new';
|
|
37
40
|
export * from './contracts/execute/scripts';
|
|
38
41
|
export * from './contracts/price-oracle/types';
|
|
39
42
|
export * from './contracts/stability-pool/types';
|
|
43
|
+
export * from './contracts/stability-pool/types-new';
|
|
40
44
|
export * from './contracts/poll/types-poll-shard';
|
|
41
45
|
export * from './contracts/poll/types-poll-manager';
|
|
42
|
-
export * from './contracts/poll/types-poll';
|
|
43
46
|
export * from './types/generic';
|
|
47
|
+
export * from './types/rational';
|
|
44
48
|
export * from './types/system-params';
|
|
45
|
-
export * from './contracts/
|
|
46
|
-
export * from './contracts/
|
|
47
|
-
export * from './contracts/
|
|
48
|
-
export * from './contracts/
|
|
49
|
-
export * from './
|
|
49
|
+
export * from './contracts/rob/helpers';
|
|
50
|
+
export * from './contracts/rob/types';
|
|
51
|
+
export * from './contracts/rob/types-new';
|
|
52
|
+
export * from './contracts/rob/transactions';
|
|
53
|
+
export * from './contracts/rob/scripts';
|
|
50
54
|
export * from './contracts/one-shot/transactions';
|
|
55
|
+
export * from './contracts/rob-leverage/transactions';
|
|
56
|
+
export * from './contracts/rob-leverage/helpers';
|
|
57
|
+
export * from './contracts/price-oracle/transactions';
|
|
58
|
+
export * from './contracts/price-oracle/types';
|
|
59
|
+
export * from './contracts/price-oracle/types-new';
|
|
60
|
+
export * from './contracts/price-oracle/scripts';
|
|
51
61
|
export * from './utils/utils';
|
|
52
62
|
export * from './utils/array-utils';
|
|
53
|
-
export * from './utils/
|
|
54
|
-
export * from './
|
|
55
|
-
export * from './
|
|
63
|
+
export * from './utils/lucid-utils';
|
|
64
|
+
export * from './utils/helper-txs';
|
|
65
|
+
export * from './utils/bigint-utils';
|
|
56
66
|
export * from './contracts/initialize/types';
|
|
57
67
|
export * from './contracts/initialize/helpers';
|
|
58
|
-
export * from './contracts/initialize/
|
|
68
|
+
export * from './contracts/initialize/actions';
|
|
69
|
+
export * from './utils/pyth';
|
|
70
|
+
export * from './contracts/pyth-feed/types';
|
|
71
|
+
export * from './contracts/pyth-feed/scripts';
|
|
72
|
+
export * from './contracts/iasset/types';
|
|
73
|
+
export * from './contracts/stableswap/helpers';
|
|
74
|
+
export * from './contracts/stableswap/transactions';
|
|
75
|
+
export * from './contracts/stableswap/types-new';
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
1
2
|
import {
|
|
2
3
|
applyParamsToScript,
|
|
3
4
|
Constr,
|
|
4
5
|
MintingPolicy,
|
|
5
6
|
ScriptType,
|
|
7
|
+
toHex,
|
|
6
8
|
} from '@lucid-evolution/lucid';
|
|
7
|
-
import { AssetClass } from '../types/generic';
|
|
8
9
|
|
|
9
10
|
const authPolicyData = {
|
|
10
11
|
type: 'PlutusV2' as ScriptType,
|
|
@@ -16,7 +17,7 @@ export function mkAuthTokenPolicy(ac: AssetClass, tn: string): MintingPolicy {
|
|
|
16
17
|
return {
|
|
17
18
|
type: authPolicyData.type,
|
|
18
19
|
script: applyParamsToScript(authPolicyData.cborHex, [
|
|
19
|
-
new Constr(0, [ac.currencySymbol, ac.tokenName]),
|
|
20
|
+
new Constr(0, [toHex(ac.currencySymbol), toHex(ac.tokenName)]),
|
|
20
21
|
tn,
|
|
21
22
|
]),
|
|
22
23
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
1
2
|
import {
|
|
2
3
|
applyParamsToScript,
|
|
3
4
|
Constr,
|
|
4
5
|
MintingPolicy,
|
|
5
6
|
ScriptType,
|
|
7
|
+
toHex,
|
|
6
8
|
} from '@lucid-evolution/lucid';
|
|
7
|
-
import { AssetClass } from '../types/generic';
|
|
8
9
|
|
|
9
10
|
const iassetPolicyData = {
|
|
10
11
|
type: 'PlutusV2' as ScriptType,
|
|
@@ -16,7 +17,7 @@ export function mkIAssetTokenPolicy(ac: AssetClass): MintingPolicy {
|
|
|
16
17
|
return {
|
|
17
18
|
type: iassetPolicyData.type,
|
|
18
19
|
script: applyParamsToScript(iassetPolicyData.cborHex, [
|
|
19
|
-
new Constr(0, [ac.currencySymbol, ac.tokenName]),
|
|
20
|
+
new Constr(0, [toHex(ac.currencySymbol), toHex(ac.tokenName)]),
|
|
20
21
|
]),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CBOR } from '@evolution-sdk/evolution';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**`
|
|
4
4
|
* This is related to our on-chain codebase for aiken v1.0.26-alpha
|
|
5
5
|
*/
|
|
6
6
|
export const DEFAULT_SCHEMA_OPTIONS = {
|
|
@@ -13,4 +13,4 @@ export const DEFAULT_SCHEMA_OPTIONS = {
|
|
|
13
13
|
useMinimalEncoding: true,
|
|
14
14
|
mapsAsObjects: false,
|
|
15
15
|
encodeMapAsPairs: false,
|
|
16
|
-
} as const satisfies CodecOptions;
|
|
16
|
+
} as const satisfies CBOR.CodecOptions;
|
package/src/types/generic.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
Data,
|
|
4
|
-
getAddressDetails,
|
|
5
|
-
Credential,
|
|
6
|
-
Network,
|
|
7
|
-
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { match, P } from 'ts-pattern';
|
|
1
|
+
import { AssetClass } from '@3rd-eye-labs/cardano-offchain-common';
|
|
2
|
+
import { Data, fromHex, toHex, UTxO } from '@lucid-evolution/lucid';
|
|
9
3
|
|
|
10
4
|
export const AssetClassSchema = Data.Object({
|
|
11
5
|
currencySymbol: Data.Bytes(),
|
|
12
6
|
/** Use the HEX encoding */
|
|
13
7
|
tokenName: Data.Bytes(),
|
|
14
8
|
});
|
|
15
|
-
export type
|
|
9
|
+
export type AssetClassD = Data.Static<typeof AssetClassSchema>;
|
|
16
10
|
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
export function toAssetClassFromLucid(asset: AssetClassD): AssetClass {
|
|
12
|
+
return {
|
|
13
|
+
currencySymbol: fromHex(asset.currencySymbol),
|
|
14
|
+
tokenName: fromHex(asset.tokenName),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getAssetClassComparisonStr(asset: AssetClass): string {
|
|
19
|
+
return `${toHex(asset.currencySymbol)}${toHex(asset.tokenName)}`;
|
|
20
|
+
}
|
|
22
21
|
|
|
23
22
|
export const VerificationKeyHashSchema = Data.Bytes();
|
|
24
23
|
|
|
@@ -46,79 +45,8 @@ export const StakeCredentialSchema = Data.Enum([
|
|
|
46
45
|
}),
|
|
47
46
|
]);
|
|
48
47
|
|
|
49
|
-
export
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
export type AddressD = Data.Static<typeof AddressSchema>;
|
|
54
|
-
export const AddressD = AddressSchema as unknown as AddressD;
|
|
55
|
-
|
|
56
|
-
export function addressToBech32(address: AddressD, network: Network): string {
|
|
57
|
-
const matchCred = (cred: CredentialD) =>
|
|
58
|
-
match(cred)
|
|
59
|
-
.returnType<Credential>()
|
|
60
|
-
.with({ PublicKeyCredential: [P.select()] }, (pkh) => {
|
|
61
|
-
return { type: 'Key', hash: pkh };
|
|
62
|
-
})
|
|
63
|
-
.with({ ScriptCredential: [P.select()] }, (scriptCred) => {
|
|
64
|
-
return { type: 'Script', hash: scriptCred };
|
|
65
|
-
})
|
|
66
|
-
.exhaustive();
|
|
67
|
-
|
|
68
|
-
const stakeCred: Credential | undefined = match(address.stakeCredential)
|
|
69
|
-
.returnType<Credential | undefined>()
|
|
70
|
-
.with(P.nullish, () => undefined)
|
|
71
|
-
.with({ Inline: [P.select()] }, (cred) => matchCred(cred))
|
|
72
|
-
.otherwise(() => {
|
|
73
|
-
throw new Error('Unexpected stake credential format.');
|
|
74
|
-
});
|
|
48
|
+
export type StakeCredential = Data.Static<typeof StakeCredentialSchema>;
|
|
49
|
+
export const StakeCredential =
|
|
50
|
+
StakeCredentialSchema as unknown as StakeCredential;
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return credentialToAddress(network, cred, stakeCred);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function addressFromBech32(address: string): AddressD {
|
|
82
|
-
const details = getAddressDetails(address);
|
|
83
|
-
|
|
84
|
-
const matchCred = (cred: Credential): CredentialD => {
|
|
85
|
-
return match(cred)
|
|
86
|
-
.returnType<CredentialD>()
|
|
87
|
-
.with({ type: 'Key', hash: P.select() }, (pkh) => {
|
|
88
|
-
return {
|
|
89
|
-
PublicKeyCredential: [pkh],
|
|
90
|
-
};
|
|
91
|
-
})
|
|
92
|
-
.with({ type: 'Script', hash: P.select() }, (scriptHash) => ({
|
|
93
|
-
ScriptCredential: [scriptHash],
|
|
94
|
-
}))
|
|
95
|
-
.exhaustive();
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
return match(details)
|
|
99
|
-
.returnType<AddressD>()
|
|
100
|
-
.with(
|
|
101
|
-
{ paymentCredential: P.nullish },
|
|
102
|
-
{ type: P.not(P.union('Base', 'Enterprise')) },
|
|
103
|
-
(_) => {
|
|
104
|
-
throw new Error('Invalid address provided');
|
|
105
|
-
},
|
|
106
|
-
)
|
|
107
|
-
.narrow()
|
|
108
|
-
.otherwise((details) => ({
|
|
109
|
-
paymentCredential: matchCred(details.paymentCredential),
|
|
110
|
-
stakeCredential: details.stakeCredential
|
|
111
|
-
? {
|
|
112
|
-
Inline: [matchCred(details.stakeCredential)],
|
|
113
|
-
}
|
|
114
|
-
: null,
|
|
115
|
-
}));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export interface CurrencySymbol {
|
|
119
|
-
unCurrencySymbol: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface TokenName {
|
|
123
|
-
unTokenName: string;
|
|
124
|
-
}
|
|
52
|
+
export type ParsedOutput<T> = { utxo: UTxO; datum: T };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
|
|
4
|
+
const OpaqueData = Schema.typeSchema(Data.DataSchema);
|
|
5
|
+
|
|
6
|
+
export const MultisigSchema = TSchema.Union(
|
|
7
|
+
TSchema.Struct(
|
|
8
|
+
{
|
|
9
|
+
Signature: TSchema.Struct(
|
|
10
|
+
{
|
|
11
|
+
keyHash: TSchema.ByteArray,
|
|
12
|
+
},
|
|
13
|
+
{ flatFields: true },
|
|
14
|
+
),
|
|
15
|
+
},
|
|
16
|
+
{ flatInUnion: true },
|
|
17
|
+
),
|
|
18
|
+
TSchema.Struct(
|
|
19
|
+
{
|
|
20
|
+
AtLeast: TSchema.Struct(
|
|
21
|
+
{
|
|
22
|
+
required: TSchema.Integer,
|
|
23
|
+
authSignatories: TSchema.Array(OpaqueData),
|
|
24
|
+
},
|
|
25
|
+
{ flatFields: true },
|
|
26
|
+
),
|
|
27
|
+
},
|
|
28
|
+
{ flatInUnion: true },
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export type Multisig = typeof MultisigSchema.Type;
|
|
33
|
+
|
|
34
|
+
export function parseMultisig(datum: string): Multisig {
|
|
35
|
+
return Data.withSchema(MultisigSchema).fromCBORHex(datum);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function fromDataMultisig(data: Data.Data): Multisig {
|
|
39
|
+
return Data.withSchema(MultisigSchema).fromCBORHex(Data.toCBORHex(data));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function toDataMultisig(data: Multisig): Data.Data {
|
|
43
|
+
return Data.withSchema(MultisigSchema).toData(data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function serialiseMultisig(datum: Multisig): string {
|
|
47
|
+
return Data.withSchema(MultisigSchema).toCBORHex(datum);
|
|
48
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TSchema } from '@evolution-sdk/evolution';
|
|
2
|
+
import { divideOnChainCompatible } from '../utils/bigint-utils';
|
|
2
3
|
|
|
3
4
|
export const OCD_DECIMAL_UNIT: bigint = 1_000_000n;
|
|
4
5
|
|
|
5
|
-
export const OnChainDecimalSchema =
|
|
6
|
-
getOnChainInt:
|
|
6
|
+
export const OnChainDecimalSchema = TSchema.Struct({
|
|
7
|
+
getOnChainInt: TSchema.Integer,
|
|
7
8
|
});
|
|
8
|
-
|
|
9
|
-
export
|
|
9
|
+
|
|
10
|
+
export type OnChainDecimal = typeof OnChainDecimalSchema.Type;
|
|
10
11
|
|
|
11
12
|
export function ocdCeil(a: OnChainDecimal): bigint {
|
|
12
13
|
const whole = a.getOnChainInt / OCD_DECIMAL_UNIT;
|
|
@@ -24,13 +25,19 @@ export function ocdNegate(a: OnChainDecimal): OnChainDecimal {
|
|
|
24
25
|
|
|
25
26
|
export function ocdMul(a: OnChainDecimal, b: OnChainDecimal): OnChainDecimal {
|
|
26
27
|
return {
|
|
27
|
-
getOnChainInt: (
|
|
28
|
+
getOnChainInt: divideOnChainCompatible(
|
|
29
|
+
a.getOnChainInt * b.getOnChainInt,
|
|
30
|
+
OCD_DECIMAL_UNIT,
|
|
31
|
+
),
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export function ocdDiv(a: OnChainDecimal, b: OnChainDecimal): OnChainDecimal {
|
|
32
36
|
return {
|
|
33
|
-
getOnChainInt: (
|
|
37
|
+
getOnChainInt: divideOnChainCompatible(
|
|
38
|
+
a.getOnChainInt * OCD_DECIMAL_UNIT,
|
|
39
|
+
b.getOnChainInt,
|
|
40
|
+
),
|
|
34
41
|
};
|
|
35
42
|
}
|
|
36
43
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { TSchema } from '@evolution-sdk/evolution';
|
|
2
|
+
import { divideOnChainCompatible } from '../utils/bigint-utils';
|
|
3
|
+
|
|
4
|
+
export const RationalSchema = TSchema.Struct({
|
|
5
|
+
numerator: TSchema.Integer,
|
|
6
|
+
denominator: TSchema.Integer,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export type Rational = typeof RationalSchema.Type;
|
|
10
|
+
|
|
11
|
+
export const rationalZero: Rational = { numerator: 0n, denominator: 1n };
|
|
12
|
+
|
|
13
|
+
export function rationalFromInt(a: bigint): Rational {
|
|
14
|
+
return { numerator: a, denominator: 1n };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function rationalFloor(a: Rational): bigint {
|
|
18
|
+
return divideOnChainCompatible(a.numerator, a.denominator);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function rationalCeil(a: Rational): bigint {
|
|
22
|
+
const intDiv = a.numerator / a.denominator;
|
|
23
|
+
return a.numerator % a.denominator > 0n ? intDiv + 1n : intDiv;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function rationalNegate(a: Rational): Rational {
|
|
27
|
+
return { numerator: -a.numerator, denominator: a.denominator };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function rationalAdd(a: Rational, b: Rational): Rational {
|
|
31
|
+
return {
|
|
32
|
+
numerator: a.numerator * b.denominator + b.numerator * a.denominator,
|
|
33
|
+
denominator: a.denominator * b.denominator,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function rationalSub(a: Rational, b: Rational): Rational {
|
|
38
|
+
return {
|
|
39
|
+
numerator: a.numerator * b.denominator - b.numerator * a.denominator,
|
|
40
|
+
denominator: a.denominator * b.denominator,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function rationalMul(a: Rational, b: Rational): Rational {
|
|
45
|
+
return {
|
|
46
|
+
numerator: a.numerator * b.numerator,
|
|
47
|
+
denominator: a.denominator * b.denominator,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function rationalDiv(a: Rational, b: Rational): Rational {
|
|
52
|
+
if (b.numerator === 0n) throw new Error('Cannot divide by zero.');
|
|
53
|
+
return {
|
|
54
|
+
numerator: a.numerator * b.denominator,
|
|
55
|
+
denominator: a.denominator * b.numerator,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function rationalToFloat(a: Rational): number {
|
|
60
|
+
return Number(a.numerator) / Number(a.denominator);
|
|
61
|
+
}
|