@indigo-labs/indigo-sdk 0.1.3 → 0.1.4
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/package.json +4 -1
- package/.github/workflows/ci.yml +0 -62
- package/.github/workflows/test.yml +0 -44
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/.prettierrc +0 -6
- package/eslint.config.mjs +0 -35
- package/src/contracts/cdp.ts +0 -741
- package/src/contracts/collector.ts +0 -98
- package/src/contracts/gov.ts +0 -1
- package/src/contracts/interest-oracle.ts +0 -149
- package/src/contracts/lrp.ts +0 -223
- package/src/contracts/one-shot.ts +0 -67
- package/src/contracts/stability-pool.ts +0 -684
- package/src/contracts/staking.ts +0 -348
- package/src/contracts/treasury.ts +0 -112
- package/src/helpers/asset-helpers.ts +0 -57
- package/src/helpers/helper-txs.ts +0 -30
- package/src/helpers/helpers.ts +0 -38
- package/src/helpers/indigo-helpers.ts +0 -19
- package/src/helpers/interest-oracle.ts +0 -57
- package/src/helpers/lucid-utils.ts +0 -70
- package/src/helpers/price-oracle-helpers.ts +0 -36
- package/src/helpers/stability-pool-helpers.ts +0 -207
- package/src/helpers/staking-helpers.ts +0 -94
- package/src/helpers/time-helpers.ts +0 -4
- package/src/helpers/value-helpers.ts +0 -16
- package/src/index.ts +0 -34
- package/src/scripts/always-fail-validator.ts +0 -7
- package/src/scripts/auth-token-policy.ts +0 -23
- package/src/scripts/cdp-creator-validator.ts +0 -53
- package/src/scripts/cdp-validator.ts +0 -9
- package/src/scripts/collector-validator.ts +0 -8
- package/src/scripts/execute-validator.ts +0 -52
- package/src/scripts/gov-validator.ts +0 -44
- package/src/scripts/iasset-policy.ts +0 -22
- package/src/scripts/interest-oracle-validator.ts +0 -23
- package/src/scripts/lrp-validator.ts +0 -23
- package/src/scripts/one-shot-policy.ts +0 -62
- package/src/scripts/poll-manager-validator.ts +0 -52
- package/src/scripts/poll-shard-validator.ts +0 -47
- package/src/scripts/price-oracle-validator.ts +0 -26
- package/src/scripts/stability-pool-validator.ts +0 -60
- package/src/scripts/staking-validator.ts +0 -8
- package/src/scripts/treasury-validator.ts +0 -8
- package/src/scripts/version-record-policy.ts +0 -26
- package/src/scripts/version-registry.ts +0 -15
- package/src/types/generic.ts +0 -106
- package/src/types/indigo/cdp-creator.ts +0 -46
- package/src/types/indigo/cdp.ts +0 -88
- package/src/types/indigo/execute.ts +0 -21
- package/src/types/indigo/gov.ts +0 -51
- package/src/types/indigo/interest-oracle.ts +0 -55
- package/src/types/indigo/lrp.ts +0 -54
- package/src/types/indigo/poll-manager.ts +0 -21
- package/src/types/indigo/poll-shard.ts +0 -16
- package/src/types/indigo/price-oracle.ts +0 -38
- package/src/types/indigo/stability-pool.ts +0 -233
- package/src/types/indigo/staking.ts +0 -99
- package/src/types/indigo/version-record.ts +0 -17
- package/src/types/on-chain-decimal.ts +0 -23
- package/src/types/one-shot.ts +0 -22
- package/src/types/system-params.ts +0 -246
- package/tests/data/system-params.json +0 -989
- package/tests/datums.test.ts +0 -286
- package/tests/endpoints/initialize.ts +0 -1013
- package/tests/hash-checks.test.ts +0 -73
- package/tests/indigo-test-helpers.ts +0 -115
- package/tests/initialize.test.ts +0 -27
- package/tests/interest-calculations.test.ts +0 -120
- package/tests/interest-oracle.test.ts +0 -90
- package/tests/lrp.test.ts +0 -149
- package/tests/queries/governance-queries.ts +0 -31
- package/tests/queries/iasset-queries.ts +0 -39
- package/tests/queries/interest-oracle-queries.ts +0 -13
- package/tests/queries/lrp-queries.ts +0 -39
- package/tests/queries/price-oracle-queries.ts +0 -27
- package/tests/queries/stability-pool-queries.ts +0 -75
- package/tests/queries/staking-queries.ts +0 -43
- package/tests/stability-pool.test.ts +0 -364
- package/tests/staking.test.ts +0 -105
- package/tests/test-helpers.ts +0 -38
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -16
- package/vitest.config.ts +0 -9
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
loadSystemParamsFromFile,
|
|
4
|
-
StakingContract,
|
|
5
|
-
CollectorContract,
|
|
6
|
-
CDPContract,
|
|
7
|
-
mkCDPCreatorValidatorFromSP,
|
|
8
|
-
mkInterestOracleValidator,
|
|
9
|
-
} from '../src';
|
|
10
|
-
import { validatorToScriptHash } from '@lucid-evolution/lucid';
|
|
11
|
-
import { mkStabilityPoolValidatorFromSP } from '../src/scripts/stability-pool-validator';
|
|
12
|
-
import { mkGovValidatorFromSP } from '../src/scripts/gov-validator';
|
|
13
|
-
|
|
14
|
-
const systemParams = loadSystemParamsFromFile(
|
|
15
|
-
'./tests/data/system-params.json',
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
describe('Validator Hash checks', () => {
|
|
19
|
-
it('CDP Creator validator hash', () => {
|
|
20
|
-
expect(
|
|
21
|
-
validatorToScriptHash(
|
|
22
|
-
mkCDPCreatorValidatorFromSP(systemParams.cdpCreatorParams),
|
|
23
|
-
),
|
|
24
|
-
).toBe(systemParams.validatorHashes.cdpCreatorHash);
|
|
25
|
-
});
|
|
26
|
-
it('CDP validator hash', () => {
|
|
27
|
-
expect(CDPContract.validatorHash(systemParams.cdpParams)).toBe(
|
|
28
|
-
systemParams.validatorHashes.cdpHash,
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
it('Collector validator hash', () => {
|
|
32
|
-
expect(CollectorContract.validatorHash(systemParams.collectorParams)).toBe(
|
|
33
|
-
systemParams.validatorHashes.collectorHash,
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
// TODO: Revisit this test, issues with cbor encoding on Lucid?
|
|
37
|
-
// Applying parameters to the validator using `aiken build` does not result in the same hash as the one generate by Lucid.
|
|
38
|
-
// it('Execute validator hash', () => {
|
|
39
|
-
// expect(
|
|
40
|
-
// validatorToScriptHash(mkExecuteValidatorFromSP(systemParams.executeParams)),
|
|
41
|
-
// ).toBe(
|
|
42
|
-
// systemParams.validatorHashes.executeHash,
|
|
43
|
-
// );
|
|
44
|
-
// });
|
|
45
|
-
it('Gov validator hash', () => {
|
|
46
|
-
expect(
|
|
47
|
-
validatorToScriptHash(mkGovValidatorFromSP(systemParams.govParams)),
|
|
48
|
-
).toBe(systemParams.validatorHashes.govHash);
|
|
49
|
-
});
|
|
50
|
-
it('Staking validator hash', () => {
|
|
51
|
-
expect(StakingContract.validatorHash(systemParams.stakingParams)).toBe(
|
|
52
|
-
systemParams.validatorHashes.stakingHash,
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
it('Stability Pool validator hash', () => {
|
|
56
|
-
expect(
|
|
57
|
-
validatorToScriptHash(
|
|
58
|
-
mkStabilityPoolValidatorFromSP(systemParams.stabilityPoolParams),
|
|
59
|
-
),
|
|
60
|
-
).toBe(systemParams.validatorHashes.stabilityPoolHash);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('Interest Oracle validator hash', () => {
|
|
64
|
-
expect(
|
|
65
|
-
validatorToScriptHash(
|
|
66
|
-
mkInterestOracleValidator({
|
|
67
|
-
biasTime: 1_200_000n,
|
|
68
|
-
owner: 'a962c79bd58fc9fcecd78f8a963e0ce80e907264cd86cd5814d87333',
|
|
69
|
-
}),
|
|
70
|
-
),
|
|
71
|
-
).toBe('b970b3e0e1b591840627e6919898c12ee57e2f0225ab03e056d10d52');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Assets,
|
|
3
|
-
fromText,
|
|
4
|
-
LucidEvolution,
|
|
5
|
-
Network,
|
|
6
|
-
ScriptHash,
|
|
7
|
-
toUnit,
|
|
8
|
-
} from '@lucid-evolution/lucid';
|
|
9
|
-
import { createScriptAddress } from '../src/helpers/lucid-utils';
|
|
10
|
-
import {
|
|
11
|
-
AssetClass,
|
|
12
|
-
IAssetContent,
|
|
13
|
-
OracleAssetNft,
|
|
14
|
-
PriceOracleParams,
|
|
15
|
-
runOneShotMintTx,
|
|
16
|
-
serialiseIAssetDatum,
|
|
17
|
-
serialisePriceOracleDatum,
|
|
18
|
-
} from '../src';
|
|
19
|
-
import { OnChainDecimal } from '../src/types/on-chain-decimal';
|
|
20
|
-
|
|
21
|
-
export async function runStartPriceOracle(
|
|
22
|
-
lucid: LucidEvolution,
|
|
23
|
-
oracleScriptHash: ScriptHash,
|
|
24
|
-
oracleParams: PriceOracleParams,
|
|
25
|
-
network: Network,
|
|
26
|
-
// Hex encoded
|
|
27
|
-
oracleNftTokenName: string,
|
|
28
|
-
price: OnChainDecimal,
|
|
29
|
-
): Promise<OracleAssetNft> {
|
|
30
|
-
const utxos = await lucid.wallet().getUtxos();
|
|
31
|
-
|
|
32
|
-
const nftPolicyId = await runOneShotMintTx(lucid, {
|
|
33
|
-
referenceOutRef: {
|
|
34
|
-
txHash: utxos[0].txHash,
|
|
35
|
-
outputIdx: BigInt(utxos[0].outputIndex),
|
|
36
|
-
},
|
|
37
|
-
mintAmounts: [{ tokenName: oracleNftTokenName, amount: 1n }],
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const nftValue: Assets = { [toUnit(nftPolicyId, oracleNftTokenName)]: 1n };
|
|
41
|
-
|
|
42
|
-
const txHash = await lucid
|
|
43
|
-
.newTx()
|
|
44
|
-
.pay.ToContract(
|
|
45
|
-
createScriptAddress(network, oracleScriptHash),
|
|
46
|
-
{
|
|
47
|
-
kind: 'inline',
|
|
48
|
-
value: serialisePriceOracleDatum({
|
|
49
|
-
price: price,
|
|
50
|
-
expiration: BigInt(Date.now()) + oracleParams.expiration,
|
|
51
|
-
}),
|
|
52
|
-
},
|
|
53
|
-
nftValue,
|
|
54
|
-
)
|
|
55
|
-
.complete()
|
|
56
|
-
.then((tx) => tx.sign.withWallet().complete())
|
|
57
|
-
.then((tx) => tx.submit());
|
|
58
|
-
|
|
59
|
-
await lucid.awaitTx(txHash);
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
oracleNft: {
|
|
63
|
-
asset: {
|
|
64
|
-
currencySymbol: nftPolicyId,
|
|
65
|
-
tokenName: oracleNftTokenName,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* TODO: the NFT has to be minted using the auth policy based on execute NFT.
|
|
73
|
-
* This is just a mocked setup for test purposes.
|
|
74
|
-
*
|
|
75
|
-
* @returns NFT of the iAsset.
|
|
76
|
-
*/
|
|
77
|
-
export async function runCreateIAsset(
|
|
78
|
-
lucid: LucidEvolution,
|
|
79
|
-
network: Network,
|
|
80
|
-
cdpScriptHash: ScriptHash,
|
|
81
|
-
iasset: IAssetContent,
|
|
82
|
-
): Promise<AssetClass> {
|
|
83
|
-
const nftTokenName = fromText('IASSET_NFT');
|
|
84
|
-
const utxos = await lucid.wallet().getUtxos();
|
|
85
|
-
const nftPolicyId = await runOneShotMintTx(lucid, {
|
|
86
|
-
referenceOutRef: {
|
|
87
|
-
txHash: utxos[0].txHash,
|
|
88
|
-
outputIdx: BigInt(utxos[0].outputIndex),
|
|
89
|
-
},
|
|
90
|
-
mintAmounts: [{ tokenName: nftTokenName, amount: 1n }],
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
const nftValue: Assets = { [toUnit(nftPolicyId, nftTokenName)]: 1n };
|
|
94
|
-
|
|
95
|
-
const txHash = await lucid
|
|
96
|
-
.newTx()
|
|
97
|
-
.pay.ToContract(
|
|
98
|
-
createScriptAddress(network, cdpScriptHash),
|
|
99
|
-
{
|
|
100
|
-
kind: 'inline',
|
|
101
|
-
value: serialiseIAssetDatum(iasset),
|
|
102
|
-
},
|
|
103
|
-
nftValue,
|
|
104
|
-
)
|
|
105
|
-
.complete()
|
|
106
|
-
.then((tx) => tx.sign.withWallet().complete())
|
|
107
|
-
.then((tx) => tx.submit());
|
|
108
|
-
|
|
109
|
-
await lucid.awaitTx(txHash);
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
currencySymbol: nftPolicyId,
|
|
113
|
-
tokenName: nftTokenName,
|
|
114
|
-
};
|
|
115
|
-
}
|
package/tests/initialize.test.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { beforeEach, test } from 'vitest';
|
|
2
|
-
import { LucidContext } from './test-helpers';
|
|
3
|
-
import { Lucid } from '@lucid-evolution/lucid';
|
|
4
|
-
import { Emulator } from '@lucid-evolution/lucid';
|
|
5
|
-
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
6
|
-
import { init } from './endpoints/initialize';
|
|
7
|
-
|
|
8
|
-
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
9
|
-
context.users = {
|
|
10
|
-
admin: generateEmulatorAccount({
|
|
11
|
-
lovelace: BigInt(100_000_000_000_000),
|
|
12
|
-
}),
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
context.emulator = new Emulator([context.users.admin]);
|
|
16
|
-
|
|
17
|
-
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test<LucidContext>('Initialize Protocol - can initialize', async ({
|
|
21
|
-
lucid,
|
|
22
|
-
users,
|
|
23
|
-
}: LucidContext) => {
|
|
24
|
-
lucid.selectWallet.fromSeed(users.admin.seedPhrase);
|
|
25
|
-
|
|
26
|
-
await init(lucid);
|
|
27
|
-
});
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { oneDay } from '../src/helpers/time-helpers';
|
|
3
|
-
import {
|
|
4
|
-
calculateAccruedInterest,
|
|
5
|
-
calculateUnitaryInterestSinceOracleLastUpdated,
|
|
6
|
-
} from '../src/helpers/interest-oracle';
|
|
7
|
-
|
|
8
|
-
describe('Interest Calculations', () => {
|
|
9
|
-
describe('Calculate Unitary Interest', () => {
|
|
10
|
-
it('Should calculate the unitary interest correctly, 0', () => {
|
|
11
|
-
expect(
|
|
12
|
-
calculateUnitaryInterestSinceOracleLastUpdated(oneDay * 6n, {
|
|
13
|
-
unitaryInterest: 684_931_506_849_315n,
|
|
14
|
-
interestRate: { getOnChainInt: 100_000n },
|
|
15
|
-
lastUpdated: oneDay * 5n,
|
|
16
|
-
}),
|
|
17
|
-
).toBe(273_972_602_739_726n);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('Should calculate the unitary interest correctly, 1', () => {
|
|
21
|
-
expect(
|
|
22
|
-
calculateUnitaryInterestSinceOracleLastUpdated(oneDay * 6n, {
|
|
23
|
-
unitaryInterest: 0n,
|
|
24
|
-
interestRate: { getOnChainInt: 50_000n },
|
|
25
|
-
lastUpdated: 0n,
|
|
26
|
-
}),
|
|
27
|
-
).toBe(821_917_808_219_178n);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('Should calculate the unitary interest correctly, 2', () => {
|
|
31
|
-
expect(
|
|
32
|
-
calculateUnitaryInterestSinceOracleLastUpdated(1n, {
|
|
33
|
-
unitaryInterest: 0n,
|
|
34
|
-
interestRate: { getOnChainInt: 1n },
|
|
35
|
-
lastUpdated: 0n,
|
|
36
|
-
}),
|
|
37
|
-
).toBe(31n);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('Calculate Accumulated Interest', () => {
|
|
42
|
-
it('Should calculate the accumulated interest correctly, 0', () => {
|
|
43
|
-
expect(
|
|
44
|
-
calculateAccruedInterest(oneDay, 0n, 1_000_000n, 0n, {
|
|
45
|
-
unitaryInterest: 0n,
|
|
46
|
-
interestRate: { getOnChainInt: 50_000n },
|
|
47
|
-
lastUpdated: 0n,
|
|
48
|
-
}),
|
|
49
|
-
).toBe(136n);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('Should calculate the accumulated interest correctly, 1', () => {
|
|
53
|
-
expect(
|
|
54
|
-
calculateAccruedInterest(oneDay * 6n, 0n, 1_000_000n, 0n, {
|
|
55
|
-
unitaryInterest: 684_931_506_849_315n,
|
|
56
|
-
interestRate: { getOnChainInt: 100_000n },
|
|
57
|
-
lastUpdated: oneDay * 5n,
|
|
58
|
-
}),
|
|
59
|
-
).toBe(684n + 273n);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('Should calculate the accumulated interest correctly, 2', () => {
|
|
63
|
-
expect(
|
|
64
|
-
calculateAccruedInterest(oneDay * 17n, 0n, 1_000_000n, 0n, {
|
|
65
|
-
unitaryInterest: 1_506_849_315_068_493n,
|
|
66
|
-
interestRate: { getOnChainInt: 100_000n },
|
|
67
|
-
lastUpdated: oneDay * 15n,
|
|
68
|
-
}),
|
|
69
|
-
).toBe(1506n + 547n);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('Should calculate the accumulated interest correctly, 3', () => {
|
|
73
|
-
expect(
|
|
74
|
-
calculateAccruedInterest(
|
|
75
|
-
oneDay * 17n,
|
|
76
|
-
410_958_904_109_589n,
|
|
77
|
-
1_000_000n,
|
|
78
|
-
oneDay * 3n,
|
|
79
|
-
{
|
|
80
|
-
unitaryInterest: 1_506_849_315_068_493n,
|
|
81
|
-
interestRate: { getOnChainInt: 100_000n },
|
|
82
|
-
lastUpdated: oneDay * 15n,
|
|
83
|
-
},
|
|
84
|
-
),
|
|
85
|
-
).toBe(1095n + 547n);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('Should calculate the accumulated interest correctly, 4', () => {
|
|
89
|
-
expect(
|
|
90
|
-
calculateAccruedInterest(
|
|
91
|
-
oneDay * 17n,
|
|
92
|
-
767_123_287_671_232n,
|
|
93
|
-
1_000_000n,
|
|
94
|
-
oneDay * 6n,
|
|
95
|
-
{
|
|
96
|
-
unitaryInterest: 1_506_849_315_068_493n,
|
|
97
|
-
interestRate: { getOnChainInt: 100_000n },
|
|
98
|
-
lastUpdated: oneDay * 15n,
|
|
99
|
-
},
|
|
100
|
-
),
|
|
101
|
-
).toBe(739n + 547n);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('Should calculate the accumulated interest correctly, 5', () => {
|
|
105
|
-
expect(
|
|
106
|
-
calculateAccruedInterest(
|
|
107
|
-
oneDay * 10n,
|
|
108
|
-
821_917_808_219_178n,
|
|
109
|
-
1_000_000n,
|
|
110
|
-
oneDay * 6n,
|
|
111
|
-
{
|
|
112
|
-
unitaryInterest: 0n,
|
|
113
|
-
interestRate: { getOnChainInt: 50_000n },
|
|
114
|
-
lastUpdated: 0n,
|
|
115
|
-
},
|
|
116
|
-
),
|
|
117
|
-
).toBe(547n);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, test } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
LucidContext,
|
|
4
|
-
runAndAwaitTx,
|
|
5
|
-
runAndAwaitTxBuilder,
|
|
6
|
-
} from './test-helpers';
|
|
7
|
-
import { Lucid } from '@lucid-evolution/lucid';
|
|
8
|
-
import { Emulator } from '@lucid-evolution/lucid';
|
|
9
|
-
import { generateEmulatorAccount } from '@lucid-evolution/lucid';
|
|
10
|
-
import { addrDetails } from '../src/helpers/lucid-utils';
|
|
11
|
-
import { InterestOracleContract, InterestOracleParams } from '../src';
|
|
12
|
-
import { findInterestOracle } from './queries/interest-oracle-queries';
|
|
13
|
-
|
|
14
|
-
let originalDateNow: () => number;
|
|
15
|
-
|
|
16
|
-
beforeEach<LucidContext>(async (context: LucidContext) => {
|
|
17
|
-
context.users = {
|
|
18
|
-
user: generateEmulatorAccount({
|
|
19
|
-
lovelace: BigInt(100_000_000_000_000),
|
|
20
|
-
}),
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
context.emulator = new Emulator([context.users.user]);
|
|
24
|
-
|
|
25
|
-
context.lucid = await Lucid(context.emulator, 'Custom');
|
|
26
|
-
|
|
27
|
-
originalDateNow = Date.now;
|
|
28
|
-
Date.now = () => context.emulator.now();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
Date.now = originalDateNow;
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test<LucidContext>('Interest Oracle - Start', async ({
|
|
36
|
-
lucid,
|
|
37
|
-
users,
|
|
38
|
-
}: LucidContext) => {
|
|
39
|
-
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
40
|
-
|
|
41
|
-
const [pkh, _] = await addrDetails(lucid);
|
|
42
|
-
|
|
43
|
-
const [tx, _ac] = await InterestOracleContract.startInterestOracle(
|
|
44
|
-
0n,
|
|
45
|
-
0n,
|
|
46
|
-
0n,
|
|
47
|
-
{
|
|
48
|
-
biasTime: 120_000n,
|
|
49
|
-
owner: pkh.hash,
|
|
50
|
-
},
|
|
51
|
-
lucid,
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
await runAndAwaitTxBuilder(lucid, tx);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test<LucidContext>('Interest Oracle - Update', async ({
|
|
58
|
-
lucid,
|
|
59
|
-
users,
|
|
60
|
-
}: LucidContext) => {
|
|
61
|
-
lucid.selectWallet.fromSeed(users.user.seedPhrase);
|
|
62
|
-
|
|
63
|
-
const [pkh, _] = await addrDetails(lucid);
|
|
64
|
-
const interestParams: InterestOracleParams = {
|
|
65
|
-
biasTime: 120_000n,
|
|
66
|
-
owner: pkh.hash,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const [tx, assetClass] = await InterestOracleContract.startInterestOracle(
|
|
70
|
-
0n,
|
|
71
|
-
0n,
|
|
72
|
-
0n,
|
|
73
|
-
interestParams,
|
|
74
|
-
lucid,
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
await runAndAwaitTxBuilder(lucid, tx);
|
|
78
|
-
|
|
79
|
-
const [utxo, _datum] = await findInterestOracle(lucid, assetClass);
|
|
80
|
-
await runAndAwaitTx(
|
|
81
|
-
lucid,
|
|
82
|
-
InterestOracleContract.feedInterestOracle(
|
|
83
|
-
interestParams,
|
|
84
|
-
500_000n,
|
|
85
|
-
lucid,
|
|
86
|
-
undefined,
|
|
87
|
-
utxo,
|
|
88
|
-
),
|
|
89
|
-
);
|
|
90
|
-
});
|
package/tests/lrp.test.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
Emulator,
|
|
4
|
-
fromText,
|
|
5
|
-
generateEmulatorAccount,
|
|
6
|
-
Lucid,
|
|
7
|
-
Network,
|
|
8
|
-
validatorToScriptHash,
|
|
9
|
-
} from '@lucid-evolution/lucid';
|
|
10
|
-
import { LRPParams } from '../src/types/indigo/lrp';
|
|
11
|
-
import { mkLrpValidator } from '../src/scripts/lrp-validator';
|
|
12
|
-
import { runCreateScriptRefTx } from '../src/helpers/helper-txs';
|
|
13
|
-
import { runOneShotMintTx } from '../src/contracts/one-shot';
|
|
14
|
-
import { cancelLrp, openLrp } from '../src/contracts/lrp';
|
|
15
|
-
import { findLrp } from './queries/lrp-queries';
|
|
16
|
-
import { addrDetails } from '../src/helpers/lucid-utils';
|
|
17
|
-
import { runAndAwaitTx } from './test-helpers';
|
|
18
|
-
import { matchSingle } from '../src/helpers/helpers';
|
|
19
|
-
import { runCreateIAsset, runStartPriceOracle } from './indigo-test-helpers';
|
|
20
|
-
import { mkPriceOracleValidator } from '../src/scripts/price-oracle-validator';
|
|
21
|
-
import { AssetClass, PriceOracleParams } from '../src';
|
|
22
|
-
import { alwaysFailValidator } from '../src/scripts/always-fail-validator';
|
|
23
|
-
import { OCD_ONE, OCD_ZERO } from '../src/types/on-chain-decimal';
|
|
24
|
-
|
|
25
|
-
describe('LRP', () => {
|
|
26
|
-
it('case 1', async () => {
|
|
27
|
-
const network: Network = 'Custom';
|
|
28
|
-
const account1 = generateEmulatorAccount({
|
|
29
|
-
lovelace: 80_000_000_000n, // 80,000 ADA
|
|
30
|
-
});
|
|
31
|
-
const emulator = new Emulator([account1]);
|
|
32
|
-
|
|
33
|
-
const lucid = await Lucid(emulator, network);
|
|
34
|
-
lucid.selectWallet.fromSeed(account1.seedPhrase);
|
|
35
|
-
|
|
36
|
-
const iassetTokenName = fromText('TEST_IBTC');
|
|
37
|
-
const utxos = await lucid.wallet().getUtxos();
|
|
38
|
-
const iassetPolicyId = await runOneShotMintTx(lucid, {
|
|
39
|
-
referenceOutRef: {
|
|
40
|
-
txHash: utxos[0].txHash,
|
|
41
|
-
outputIdx: BigInt(utxos[0].outputIndex),
|
|
42
|
-
},
|
|
43
|
-
mintAmounts: [{ tokenName: iassetTokenName, amount: 10_000_000n }],
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const [ownPkh, _] = await addrDetails(lucid);
|
|
47
|
-
|
|
48
|
-
const priceOracleParams: PriceOracleParams = {
|
|
49
|
-
owner: ownPkh.hash,
|
|
50
|
-
// 1 minute
|
|
51
|
-
biasTime: 1n * 60n * 1000n,
|
|
52
|
-
// 10 minutes
|
|
53
|
-
expiration: 10n * 60n * 1000n,
|
|
54
|
-
};
|
|
55
|
-
const oracleValidator = mkPriceOracleValidator(priceOracleParams);
|
|
56
|
-
const oracleValidatorHash = validatorToScriptHash(oracleValidator);
|
|
57
|
-
const oracleNft = await runStartPriceOracle(
|
|
58
|
-
lucid,
|
|
59
|
-
oracleValidatorHash,
|
|
60
|
-
priceOracleParams,
|
|
61
|
-
network,
|
|
62
|
-
fromText('ORACLE_IBTC'),
|
|
63
|
-
OCD_ONE,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const iassetValHash = validatorToScriptHash(alwaysFailValidator);
|
|
67
|
-
const dummyAc: AssetClass = { currencySymbol: '', tokenName: '' };
|
|
68
|
-
const iassetNft = await runCreateIAsset(lucid, network, iassetValHash, {
|
|
69
|
-
assetName: iassetTokenName,
|
|
70
|
-
price: { Oracle: oracleNft },
|
|
71
|
-
interestOracleNft: dummyAc,
|
|
72
|
-
redemptionRatio: OCD_ONE,
|
|
73
|
-
maintenanceRatio: OCD_ONE,
|
|
74
|
-
liquidationRatio: OCD_ONE,
|
|
75
|
-
debtMintingFeePercentage: OCD_ZERO,
|
|
76
|
-
liquidationProcessingFeePercentage: OCD_ZERO,
|
|
77
|
-
stabilityPoolWithdrawalFeePercentage: OCD_ZERO,
|
|
78
|
-
redemptionReimbursementPercentage: OCD_ONE,
|
|
79
|
-
redemptionProcessingFeePercentage: OCD_ZERO,
|
|
80
|
-
interestCollectorPortionPercentage: OCD_ZERO,
|
|
81
|
-
firstIAsset: true,
|
|
82
|
-
nextIAsset: null,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const lrpParams: LRPParams = {
|
|
86
|
-
versionRecordToken: {
|
|
87
|
-
currencySymbol: fromText('smth'),
|
|
88
|
-
tokenName: fromText('version_record'),
|
|
89
|
-
},
|
|
90
|
-
iassetNft: iassetNft,
|
|
91
|
-
iassetPolicyId: iassetPolicyId,
|
|
92
|
-
minRedemptionLovelacesAmt: 1_000_000n,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const lrpValidator = mkLrpValidator(lrpParams);
|
|
96
|
-
const lrpValidatorHash = validatorToScriptHash(lrpValidator);
|
|
97
|
-
|
|
98
|
-
const lrpRefScriptOutRef = await runCreateScriptRefTx(
|
|
99
|
-
lucid,
|
|
100
|
-
lrpValidator,
|
|
101
|
-
network,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
await runAndAwaitTx(
|
|
105
|
-
lucid,
|
|
106
|
-
openLrp(
|
|
107
|
-
iassetTokenName,
|
|
108
|
-
20_000_000n,
|
|
109
|
-
{ getOnChainInt: 1_000_000n },
|
|
110
|
-
lucid,
|
|
111
|
-
lrpValidatorHash,
|
|
112
|
-
network,
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const lrpOutRef = matchSingle(
|
|
117
|
-
await findLrp(
|
|
118
|
-
lucid,
|
|
119
|
-
network,
|
|
120
|
-
lrpValidatorHash,
|
|
121
|
-
ownPkh.hash,
|
|
122
|
-
iassetTokenName,
|
|
123
|
-
),
|
|
124
|
-
(res) => new Error('Expected a single LRP UTXO.: ' + JSON.stringify(res)),
|
|
125
|
-
);
|
|
126
|
-
|
|
127
|
-
await runAndAwaitTx(lucid, cancelLrp(lrpOutRef, lrpRefScriptOutRef, lucid));
|
|
128
|
-
|
|
129
|
-
// await runAndAwaitTx(
|
|
130
|
-
// lucid,
|
|
131
|
-
// redeemLrp(
|
|
132
|
-
// [[lrpOutRef, 5_000_000n]],
|
|
133
|
-
// lrpRefScriptOutRef,
|
|
134
|
-
// await findPriceOracle(lucid, network, oracleValidatorHash, oracleNft),
|
|
135
|
-
// await findIAsset(
|
|
136
|
-
// lucid,
|
|
137
|
-
// network,
|
|
138
|
-
// iassetValHash,
|
|
139
|
-
// iassetNft,
|
|
140
|
-
// iassetTokenName,
|
|
141
|
-
// ),
|
|
142
|
-
// lucid,
|
|
143
|
-
// lrpParams,
|
|
144
|
-
// priceOracleParams,
|
|
145
|
-
// network,
|
|
146
|
-
// ),
|
|
147
|
-
// );
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, ScriptHash, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
3
|
-
import { AssetClass } from '../../src/types/generic';
|
|
4
|
-
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
5
|
-
import { matchSingle, parseGovDatum } from '../../src';
|
|
6
|
-
|
|
7
|
-
export async function findGov(
|
|
8
|
-
lucid: LucidEvolution,
|
|
9
|
-
govScriptHash: ScriptHash,
|
|
10
|
-
govNft: AssetClass,
|
|
11
|
-
): Promise<UTxO> {
|
|
12
|
-
const govUtxos = await lucid.utxosAtWithUnit(
|
|
13
|
-
createScriptAddress(lucid.config().network, govScriptHash),
|
|
14
|
-
assetClassToUnit(govNft),
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
return matchSingle(
|
|
18
|
-
govUtxos.filter((utxo) => {
|
|
19
|
-
if (utxo.datum != null) {
|
|
20
|
-
try {
|
|
21
|
-
parseGovDatum(utxo.datum);
|
|
22
|
-
return true; // TODO: implement Gov Datum
|
|
23
|
-
} catch (_) {
|
|
24
|
-
// when incompatible datum
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}),
|
|
29
|
-
(res) => new Error('Expected a single Gov UTXO.: ' + JSON.stringify(res)),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fromText,
|
|
3
|
-
LucidEvolution,
|
|
4
|
-
ScriptHash,
|
|
5
|
-
UTxO,
|
|
6
|
-
} from '@lucid-evolution/lucid';
|
|
7
|
-
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
8
|
-
import { AssetClass } from '../../src/types/generic';
|
|
9
|
-
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
10
|
-
import { matchSingle, parseIAssetDatum } from '../../src';
|
|
11
|
-
|
|
12
|
-
export async function findIAsset(
|
|
13
|
-
lucid: LucidEvolution,
|
|
14
|
-
iassetScriptHash: ScriptHash,
|
|
15
|
-
iassetNft: AssetClass,
|
|
16
|
-
iassetName: string,
|
|
17
|
-
): Promise<UTxO> {
|
|
18
|
-
const iassetUtxos = await lucid.utxosAtWithUnit(
|
|
19
|
-
createScriptAddress(lucid.config().network, iassetScriptHash),
|
|
20
|
-
assetClassToUnit(iassetNft),
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
return matchSingle(
|
|
24
|
-
iassetUtxos.filter((utxo) => {
|
|
25
|
-
if (utxo.datum != null) {
|
|
26
|
-
try {
|
|
27
|
-
const iassetDatum = parseIAssetDatum(utxo.datum);
|
|
28
|
-
|
|
29
|
-
return iassetDatum.assetName == fromText(iassetName);
|
|
30
|
-
} catch (_) {
|
|
31
|
-
// when incompatible datum
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}),
|
|
36
|
-
(res) =>
|
|
37
|
-
new Error('Expected a single IAsset UTXO.: ' + JSON.stringify(res)),
|
|
38
|
-
);
|
|
39
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LucidEvolution, UTxO } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClass } from '../../src/types/generic';
|
|
3
|
-
import { assetClassToUnit } from '../../src/helpers/value-helpers';
|
|
4
|
-
import { InterestOracleDatum, parseInterestOracleDatum } from '../../src';
|
|
5
|
-
|
|
6
|
-
export async function findInterestOracle(
|
|
7
|
-
lucid: LucidEvolution,
|
|
8
|
-
interestNft: AssetClass,
|
|
9
|
-
): Promise<[UTxO, InterestOracleDatum]> {
|
|
10
|
-
const interestUtxo = await lucid.utxoByUnit(assetClassToUnit(interestNft));
|
|
11
|
-
if (!interestUtxo.datum) throw new Error('No interest oracle utxo found');
|
|
12
|
-
return [interestUtxo, parseInterestOracleDatum(interestUtxo.datum)];
|
|
13
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Credential,
|
|
3
|
-
LucidEvolution,
|
|
4
|
-
Network,
|
|
5
|
-
OutRef,
|
|
6
|
-
ScriptHash,
|
|
7
|
-
} from '@lucid-evolution/lucid';
|
|
8
|
-
import { createScriptAddress } from '../../src/helpers/lucid-utils';
|
|
9
|
-
import { parseLrpDatum } from '../../src/types/indigo/lrp';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Beware, this shouldn't be used in production since it queries all the UTXOs
|
|
13
|
-
* at an address and does the filtering in this function.
|
|
14
|
-
*/
|
|
15
|
-
export async function findLrp(
|
|
16
|
-
lucid: LucidEvolution,
|
|
17
|
-
network: Network,
|
|
18
|
-
lrpScriptHash: ScriptHash,
|
|
19
|
-
owner: string,
|
|
20
|
-
assetTokenName: string,
|
|
21
|
-
stakeCredential?: Credential,
|
|
22
|
-
): Promise<OutRef[]> {
|
|
23
|
-
const lrpUtxos = await lucid.utxosAt(
|
|
24
|
-
createScriptAddress(network, lrpScriptHash, stakeCredential),
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return lrpUtxos.filter((utxo) => {
|
|
28
|
-
if (utxo.datum != null) {
|
|
29
|
-
try {
|
|
30
|
-
const lrpDatum = parseLrpDatum(utxo.datum);
|
|
31
|
-
|
|
32
|
-
return lrpDatum.owner == owner && lrpDatum.iasset == assetTokenName;
|
|
33
|
-
} catch (_) {
|
|
34
|
-
// when incompatible datum
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|