@indigo-labs/indigo-sdk 0.1.7 → 0.1.9
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 +62 -0
- package/.github/workflows/test.yml +44 -0
- package/.husky/pre-commit +1 -0
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/dist/index.d.mts +19 -9
- package/dist/index.d.ts +19 -9
- package/dist/index.js +341 -315
- package/dist/index.mjs +92 -64
- package/eslint.config.mjs +36 -0
- package/package.json +2 -6
- package/src/contracts/cdp.ts +748 -0
- package/src/contracts/collector.ts +98 -0
- package/src/contracts/gov.ts +1 -0
- package/src/contracts/interest-oracle.ts +149 -0
- package/src/contracts/lrp.ts +308 -0
- package/src/contracts/one-shot.ts +67 -0
- package/src/contracts/stability-pool.ts +684 -0
- package/src/contracts/staking.ts +348 -0
- package/src/contracts/treasury.ts +112 -0
- package/src/helpers/asset-helpers.ts +57 -0
- package/src/helpers/helper-txs.ts +30 -0
- package/src/helpers/helpers.ts +38 -0
- package/src/helpers/indigo-helpers.ts +19 -0
- package/src/helpers/interest-oracle.ts +57 -0
- package/src/helpers/lucid-utils.ts +70 -0
- package/src/helpers/price-oracle-helpers.ts +36 -0
- package/src/helpers/stability-pool-helpers.ts +207 -0
- package/src/helpers/staking-helpers.ts +94 -0
- package/src/helpers/time-helpers.ts +4 -0
- package/src/helpers/value-helpers.ts +27 -0
- package/src/index.ts +34 -0
- package/src/scripts/always-fail-validator.ts +7 -0
- package/src/scripts/auth-token-policy.ts +23 -0
- package/src/scripts/cdp-creator-validator.ts +53 -0
- package/src/scripts/cdp-validator.ts +9 -0
- package/src/scripts/collector-validator.ts +8 -0
- package/src/scripts/execute-validator.ts +52 -0
- package/src/scripts/gov-validator.ts +44 -0
- package/src/scripts/iasset-policy.ts +22 -0
- package/src/scripts/interest-oracle-validator.ts +23 -0
- package/src/scripts/lrp-validator.ts +40 -0
- package/src/scripts/one-shot-policy.ts +62 -0
- package/src/scripts/poll-manager-validator.ts +52 -0
- package/src/scripts/poll-shard-validator.ts +47 -0
- package/src/scripts/price-oracle-validator.ts +26 -0
- package/src/scripts/stability-pool-validator.ts +60 -0
- package/src/scripts/staking-validator.ts +8 -0
- package/src/scripts/treasury-validator.ts +8 -0
- package/src/scripts/version-record-policy.ts +26 -0
- package/src/scripts/version-registry.ts +15 -0
- package/src/types/generic.ts +106 -0
- package/src/types/indigo/cdp-creator.ts +46 -0
- package/src/types/indigo/cdp.ts +88 -0
- package/src/types/indigo/execute.ts +21 -0
- package/src/types/indigo/gov.ts +51 -0
- package/src/types/indigo/interest-oracle.ts +55 -0
- package/src/types/indigo/lrp.ts +59 -0
- package/src/types/indigo/poll-manager.ts +21 -0
- package/src/types/indigo/poll-shard.ts +16 -0
- package/src/types/indigo/price-oracle.ts +38 -0
- package/src/types/indigo/stability-pool.ts +233 -0
- package/src/types/indigo/staking.ts +99 -0
- package/src/types/indigo/version-record.ts +17 -0
- package/src/types/on-chain-decimal.ts +23 -0
- package/src/types/one-shot.ts +22 -0
- package/src/types/system-params.ts +256 -0
- package/tests/data/system-params.json +1012 -0
- package/tests/datums.test.ts +286 -0
- package/tests/endpoints/initialize.ts +1013 -0
- package/tests/hash-checks.test.ts +80 -0
- package/tests/indigo-test-helpers.ts +115 -0
- package/tests/initialize.test.ts +27 -0
- package/tests/interest-calculations.test.ts +120 -0
- package/tests/interest-oracle.test.ts +90 -0
- package/tests/lrp.test.ts +769 -0
- package/tests/queries/governance-queries.ts +31 -0
- package/tests/queries/iasset-queries.ts +39 -0
- package/tests/queries/interest-oracle-queries.ts +13 -0
- package/tests/queries/lrp-queries.ts +39 -0
- package/tests/queries/price-oracle-queries.ts +27 -0
- package/tests/queries/stability-pool-queries.ts +75 -0
- package/tests/queries/staking-queries.ts +43 -0
- package/tests/stability-pool.test.ts +387 -0
- package/tests/staking.test.ts +105 -0
- package/tests/test-helpers.ts +38 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { beforeEach, test } from 'vitest';
|
|
2
|
+
import { LucidContext, runAndAwaitTx } from './test-helpers';
|
|
3
|
+
import { fromText, Lucid } from '@lucid-evolution/lucid';
|
|
4
|
+
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
|
+
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
+
import { StakingContract } from '../src/contracts/staking';
|
|
7
|
+
import { init } from './endpoints/initialize';
|
|
8
|
+
import { addrDetails } from '../src/helpers/lucid-utils';
|
|
9
|
+
import { findStakingPosition } from './queries/staking-queries';
|
|
10
|
+
|
|
11
|
+
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
12
|
+
context.users = {
|
|
13
|
+
admin: generateEmulatorAccount({
|
|
14
|
+
lovelace: BigInt(100_000_000_000_000),
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
context.emulator = new Emulator([context.users.admin]);
|
|
19
|
+
|
|
20
|
+
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test<LucidContext>('Staking - Create Position', async ({
|
|
24
|
+
lucid,
|
|
25
|
+
users,
|
|
26
|
+
}: LucidContext) => {
|
|
27
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
28
|
+
const systemParams = await init(lucid);
|
|
29
|
+
|
|
30
|
+
await runAndAwaitTx(
|
|
31
|
+
lucid,
|
|
32
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test<LucidContext>('Staking - Adjust Position', async ({
|
|
37
|
+
lucid,
|
|
38
|
+
users,
|
|
39
|
+
}: LucidContext) => {
|
|
40
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
41
|
+
const systemParams = await init(lucid);
|
|
42
|
+
|
|
43
|
+
await runAndAwaitTx(
|
|
44
|
+
lucid,
|
|
45
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
49
|
+
const myStakingPosition = await findStakingPosition(
|
|
50
|
+
lucid,
|
|
51
|
+
lucid.config().network,
|
|
52
|
+
systemParams.validatorHashes.stakingHash,
|
|
53
|
+
{
|
|
54
|
+
currencySymbol:
|
|
55
|
+
systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
|
|
56
|
+
tokenName: fromText(
|
|
57
|
+
systemParams.stakingParams.stakingToken[1].unTokenName,
|
|
58
|
+
),
|
|
59
|
+
},
|
|
60
|
+
pkh.hash,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await runAndAwaitTx(
|
|
64
|
+
lucid,
|
|
65
|
+
StakingContract.adjustPosition(
|
|
66
|
+
myStakingPosition,
|
|
67
|
+
1_000_000n,
|
|
68
|
+
systemParams,
|
|
69
|
+
lucid,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test<LucidContext>('Staking - Close Position', async ({
|
|
75
|
+
lucid,
|
|
76
|
+
users,
|
|
77
|
+
}: LucidContext) => {
|
|
78
|
+
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
79
|
+
const systemParams = await init(lucid);
|
|
80
|
+
|
|
81
|
+
await runAndAwaitTx(
|
|
82
|
+
lucid,
|
|
83
|
+
StakingContract.openPosition(1_000_000n, systemParams, lucid),
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const [pkh, _] = await addrDetails(lucid);
|
|
87
|
+
const myStakingPosition = await findStakingPosition(
|
|
88
|
+
lucid,
|
|
89
|
+
lucid.config().network,
|
|
90
|
+
systemParams.validatorHashes.stakingHash,
|
|
91
|
+
{
|
|
92
|
+
currencySymbol:
|
|
93
|
+
systemParams.stakingParams.stakingToken[0].unCurrencySymbol,
|
|
94
|
+
tokenName: fromText(
|
|
95
|
+
systemParams.stakingParams.stakingToken[1].unTokenName,
|
|
96
|
+
),
|
|
97
|
+
},
|
|
98
|
+
pkh.hash,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
await runAndAwaitTx(
|
|
102
|
+
lucid,
|
|
103
|
+
StakingContract.closePosition(myStakingPosition, systemParams, lucid),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Emulator,
|
|
3
|
+
EmulatorAccount,
|
|
4
|
+
LucidEvolution,
|
|
5
|
+
TxBuilder,
|
|
6
|
+
} from '@lucid-evolution/lucid';
|
|
7
|
+
|
|
8
|
+
export type LucidContext = {
|
|
9
|
+
lucid: LucidEvolution;
|
|
10
|
+
users: { [key: string]: EmulatorAccount };
|
|
11
|
+
emulator: Emulator;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export async function runAndAwaitTx(
|
|
15
|
+
lucid: LucidEvolution,
|
|
16
|
+
transaction: Promise<TxBuilder>,
|
|
17
|
+
): Promise<string> {
|
|
18
|
+
const txHash = await transaction
|
|
19
|
+
.then((tx) => tx.complete())
|
|
20
|
+
.then((tx) => tx.sign.withWallet().complete())
|
|
21
|
+
.then((tx) => tx.submit());
|
|
22
|
+
|
|
23
|
+
await lucid.awaitTx(txHash);
|
|
24
|
+
return txHash;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function runAndAwaitTxBuilder(
|
|
28
|
+
lucid: LucidEvolution,
|
|
29
|
+
transaction: TxBuilder,
|
|
30
|
+
): Promise<string> {
|
|
31
|
+
const txHash = await transaction
|
|
32
|
+
.complete()
|
|
33
|
+
.then((tx) => tx.sign.withWallet().complete())
|
|
34
|
+
.then((tx) => tx.submit());
|
|
35
|
+
|
|
36
|
+
await lucid.awaitTx(txHash);
|
|
37
|
+
return txHash;
|
|
38
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "./dist",
|
|
4
|
+
"sourceMap": true,
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"target": "ESNext",
|
|
7
|
+
"moduleResolution": "nodenext",
|
|
8
|
+
"allowUnreachableCode": true
|
|
9
|
+
},
|
|
10
|
+
"ts-node": {
|
|
11
|
+
"compilerOptions": {
|
|
12
|
+
"module": "ES2022"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts", "tests/**/*.ts", "vitest.config.ts"],
|
|
16
|
+
"exclude": ["dist", "node_modules"]
|
|
17
|
+
}
|