@indigo-labs/indigo-sdk 0.1.6 → 0.1.8
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 +32 -2
- package/dist/index.d.ts +32 -2
- package/dist/index.js +81 -6
- package/dist/index.mjs +78 -6
- package/eslint.config.mjs +36 -0
- package/package.json +2 -5
- package/src/contracts/cdp.ts +741 -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 +315 -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 +777 -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 +364 -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,80 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
loadSystemParamsFromFile,
|
|
4
|
+
StakingContract,
|
|
5
|
+
CollectorContract,
|
|
6
|
+
CDPContract,
|
|
7
|
+
mkCDPCreatorValidatorFromSP,
|
|
8
|
+
mkInterestOracleValidator,
|
|
9
|
+
mkLrpValidatorFromSP,
|
|
10
|
+
} from '../src';
|
|
11
|
+
import { validatorToScriptHash } from '@lucid-evolution/lucid';
|
|
12
|
+
import { mkStabilityPoolValidatorFromSP } from '../src/scripts/stability-pool-validator';
|
|
13
|
+
import { mkGovValidatorFromSP } from '../src/scripts/gov-validator';
|
|
14
|
+
|
|
15
|
+
const systemParams = loadSystemParamsFromFile(
|
|
16
|
+
'./tests/data/system-params.json',
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
describe('Validator Hash checks', () => {
|
|
20
|
+
it('CDP Creator validator hash', () => {
|
|
21
|
+
expect(
|
|
22
|
+
validatorToScriptHash(
|
|
23
|
+
mkCDPCreatorValidatorFromSP(systemParams.cdpCreatorParams),
|
|
24
|
+
),
|
|
25
|
+
).toBe(systemParams.validatorHashes.cdpCreatorHash);
|
|
26
|
+
});
|
|
27
|
+
it('CDP validator hash', () => {
|
|
28
|
+
expect(CDPContract.validatorHash(systemParams.cdpParams)).toBe(
|
|
29
|
+
systemParams.validatorHashes.cdpHash,
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
it('Collector validator hash', () => {
|
|
33
|
+
expect(CollectorContract.validatorHash(systemParams.collectorParams)).toBe(
|
|
34
|
+
systemParams.validatorHashes.collectorHash,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
// TODO: Revisit this test, issues with cbor encoding on Lucid?
|
|
38
|
+
// Applying parameters to the validator using `aiken build` does not result in the same hash as the one generate by Lucid.
|
|
39
|
+
// it('Execute validator hash', () => {
|
|
40
|
+
// expect(
|
|
41
|
+
// validatorToScriptHash(mkExecuteValidatorFromSP(systemParams.executeParams)),
|
|
42
|
+
// ).toBe(
|
|
43
|
+
// systemParams.validatorHashes.executeHash,
|
|
44
|
+
// );
|
|
45
|
+
// });
|
|
46
|
+
it('Gov validator hash', () => {
|
|
47
|
+
expect(
|
|
48
|
+
validatorToScriptHash(mkGovValidatorFromSP(systemParams.govParams)),
|
|
49
|
+
).toBe(systemParams.validatorHashes.govHash);
|
|
50
|
+
});
|
|
51
|
+
it('Staking validator hash', () => {
|
|
52
|
+
expect(StakingContract.validatorHash(systemParams.stakingParams)).toBe(
|
|
53
|
+
systemParams.validatorHashes.stakingHash,
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
it('Stability Pool validator hash', () => {
|
|
57
|
+
expect(
|
|
58
|
+
validatorToScriptHash(
|
|
59
|
+
mkStabilityPoolValidatorFromSP(systemParams.stabilityPoolParams),
|
|
60
|
+
),
|
|
61
|
+
).toBe(systemParams.validatorHashes.stabilityPoolHash);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('Interest Oracle validator hash', () => {
|
|
65
|
+
expect(
|
|
66
|
+
validatorToScriptHash(
|
|
67
|
+
mkInterestOracleValidator({
|
|
68
|
+
biasTime: 1_200_000n,
|
|
69
|
+
owner: 'a962c79bd58fc9fcecd78f8a963e0ce80e907264cd86cd5814d87333',
|
|
70
|
+
}),
|
|
71
|
+
),
|
|
72
|
+
).toBe('b970b3e0e1b591840627e6919898c12ee57e2f0225ab03e056d10d52');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('LRP validator hash', () => {
|
|
76
|
+
expect(
|
|
77
|
+
validatorToScriptHash(mkLrpValidatorFromSP(systemParams.lrpParams)),
|
|
78
|
+
).toBe(systemParams.validatorHashes.lrpHash);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
});
|