@indigo-labs/indigo-sdk 0.1.3 → 0.1.5
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 +5 -2
- 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,98 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Address,
|
|
3
|
-
applyParamsToScript,
|
|
4
|
-
Constr,
|
|
5
|
-
Data,
|
|
6
|
-
fromText,
|
|
7
|
-
LucidEvolution,
|
|
8
|
-
OutRef,
|
|
9
|
-
SpendingValidator,
|
|
10
|
-
TxBuilder,
|
|
11
|
-
UTxO,
|
|
12
|
-
validatorToAddress,
|
|
13
|
-
validatorToScriptHash,
|
|
14
|
-
} from '@lucid-evolution/lucid';
|
|
15
|
-
import { _collectorValidator } from '../scripts/collector-validator';
|
|
16
|
-
import {
|
|
17
|
-
CollectorParams,
|
|
18
|
-
ScriptReferences,
|
|
19
|
-
SystemParams,
|
|
20
|
-
} from '../types/system-params';
|
|
21
|
-
import { scriptRef } from '../helpers/lucid-utils';
|
|
22
|
-
import { getRandomElement } from '../helpers/helpers';
|
|
23
|
-
|
|
24
|
-
export class CollectorContract {
|
|
25
|
-
static async feeTx(
|
|
26
|
-
fee: bigint,
|
|
27
|
-
lucid: LucidEvolution,
|
|
28
|
-
params: SystemParams,
|
|
29
|
-
tx: TxBuilder,
|
|
30
|
-
collectorRef?: OutRef,
|
|
31
|
-
): Promise<void> {
|
|
32
|
-
const collectorUtxo: UTxO = collectorRef
|
|
33
|
-
? getRandomElement(await lucid.utxosByOutRef([collectorRef]))
|
|
34
|
-
: getRandomElement(
|
|
35
|
-
await lucid.utxosAt(
|
|
36
|
-
CollectorContract.address(params.collectorParams, lucid),
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const collectorScriptRefUtxo = await CollectorContract.scriptRef(
|
|
41
|
-
params.scriptReferences,
|
|
42
|
-
lucid,
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
tx.collectFrom([collectorUtxo], Data.to(new Constr(0, [])))
|
|
46
|
-
.pay.ToContract(
|
|
47
|
-
collectorUtxo.address,
|
|
48
|
-
{ kind: 'inline', value: Data.to(new Constr(0, [])) },
|
|
49
|
-
{
|
|
50
|
-
...collectorUtxo.assets,
|
|
51
|
-
lovelace: collectorUtxo.assets.lovelace + fee,
|
|
52
|
-
},
|
|
53
|
-
)
|
|
54
|
-
.readFrom([collectorScriptRefUtxo]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Collector Validator
|
|
58
|
-
static validator(params: CollectorParams): SpendingValidator {
|
|
59
|
-
return {
|
|
60
|
-
type: 'PlutusV2',
|
|
61
|
-
script: applyParamsToScript(_collectorValidator.cborHex, [
|
|
62
|
-
new Constr(0, [
|
|
63
|
-
new Constr(0, [
|
|
64
|
-
params.stakingManagerNFT[0].unCurrencySymbol,
|
|
65
|
-
fromText(params.stakingManagerNFT[1].unTokenName),
|
|
66
|
-
]),
|
|
67
|
-
new Constr(0, [
|
|
68
|
-
params.stakingToken[0].unCurrencySymbol,
|
|
69
|
-
fromText(params.stakingToken[1].unTokenName),
|
|
70
|
-
]),
|
|
71
|
-
new Constr(0, [
|
|
72
|
-
params.versionRecordToken[0].unCurrencySymbol,
|
|
73
|
-
fromText(params.versionRecordToken[1].unTokenName),
|
|
74
|
-
]),
|
|
75
|
-
]),
|
|
76
|
-
]),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
static validatorHash(params: CollectorParams): string {
|
|
81
|
-
return validatorToScriptHash(CollectorContract.validator(params));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
static address(params: CollectorParams, lucid: LucidEvolution): Address {
|
|
85
|
-
const network = lucid.config().network;
|
|
86
|
-
if (!network) {
|
|
87
|
-
throw new Error('Network configuration is undefined');
|
|
88
|
-
}
|
|
89
|
-
return validatorToAddress(network, CollectorContract.validator(params));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static async scriptRef(
|
|
93
|
-
params: ScriptReferences,
|
|
94
|
-
lucid: LucidEvolution,
|
|
95
|
-
): Promise<UTxO> {
|
|
96
|
-
return scriptRef(params.collectorValidatorRef, lucid);
|
|
97
|
-
}
|
|
98
|
-
}
|
package/src/contracts/gov.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export class GovContract {}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fromText,
|
|
3
|
-
LucidEvolution,
|
|
4
|
-
OutRef,
|
|
5
|
-
toUnit,
|
|
6
|
-
TxBuilder,
|
|
7
|
-
UTxO,
|
|
8
|
-
validatorToAddress,
|
|
9
|
-
} from '@lucid-evolution/lucid';
|
|
10
|
-
import { AssetClass } from '../types/generic';
|
|
11
|
-
import {
|
|
12
|
-
InterestOracleParams,
|
|
13
|
-
parseInterestOracleDatum,
|
|
14
|
-
serialiseFeedInterestOracleRedeemer,
|
|
15
|
-
serialiseInterestOracleDatum,
|
|
16
|
-
} from '../types/indigo/interest-oracle';
|
|
17
|
-
import { oneShotMintTx } from './one-shot';
|
|
18
|
-
import { mkInterestOracleValidator } from '../scripts/interest-oracle-validator';
|
|
19
|
-
import { findInterestOracle } from '../../tests/queries/interest-oracle-queries';
|
|
20
|
-
import { ONE_SECOND } from '../helpers/time-helpers';
|
|
21
|
-
import { calculateUnitaryInterestSinceOracleLastUpdated } from '../helpers/interest-oracle';
|
|
22
|
-
|
|
23
|
-
export class InterestOracleContract {
|
|
24
|
-
static async startInterestOracle(
|
|
25
|
-
initialUnitaryInterest: bigint,
|
|
26
|
-
initialInterestRate: bigint,
|
|
27
|
-
initialLastInterestUpdate: bigint,
|
|
28
|
-
oracleParams: InterestOracleParams,
|
|
29
|
-
lucid: LucidEvolution,
|
|
30
|
-
withScriptRef: boolean = false,
|
|
31
|
-
refOutRef?: OutRef,
|
|
32
|
-
interestTokenName?: string,
|
|
33
|
-
): Promise<[TxBuilder, AssetClass]> {
|
|
34
|
-
const tokenName = interestTokenName ?? 'INTEREST_ORACLE';
|
|
35
|
-
if (!refOutRef) {
|
|
36
|
-
refOutRef = (await lucid.wallet().getUtxos())[0];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const [tx, policyId] = await oneShotMintTx(lucid, {
|
|
40
|
-
referenceOutRef: {
|
|
41
|
-
txHash: refOutRef.txHash,
|
|
42
|
-
outputIdx: BigInt(refOutRef.outputIndex),
|
|
43
|
-
},
|
|
44
|
-
mintAmounts: [
|
|
45
|
-
{
|
|
46
|
-
tokenName: fromText(tokenName),
|
|
47
|
-
amount: 1n,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const validator = mkInterestOracleValidator(oracleParams);
|
|
53
|
-
|
|
54
|
-
tx.pay.ToContract(
|
|
55
|
-
validatorToAddress(lucid.config().network, validator),
|
|
56
|
-
{
|
|
57
|
-
kind: 'inline',
|
|
58
|
-
value: serialiseInterestOracleDatum({
|
|
59
|
-
unitaryInterest: initialUnitaryInterest,
|
|
60
|
-
interestRate: {
|
|
61
|
-
getOnChainInt: initialInterestRate,
|
|
62
|
-
},
|
|
63
|
-
lastUpdated: initialLastInterestUpdate,
|
|
64
|
-
}),
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
lovelace: 2_500_000n,
|
|
68
|
-
[toUnit(policyId, fromText(tokenName))]: 1n,
|
|
69
|
-
},
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
if (withScriptRef) {
|
|
73
|
-
tx.pay.ToAddressWithData(
|
|
74
|
-
validatorToAddress(lucid.config().network, validator),
|
|
75
|
-
undefined,
|
|
76
|
-
undefined,
|
|
77
|
-
validator,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return [
|
|
82
|
-
tx,
|
|
83
|
-
{
|
|
84
|
-
currencySymbol: policyId,
|
|
85
|
-
tokenName: fromText(tokenName),
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static async feedInterestOracle(
|
|
91
|
-
params: InterestOracleParams,
|
|
92
|
-
newInterestRate: bigint,
|
|
93
|
-
lucid: LucidEvolution,
|
|
94
|
-
assetClass?: AssetClass,
|
|
95
|
-
utxo?: UTxO,
|
|
96
|
-
scriptRef?: UTxO,
|
|
97
|
-
): Promise<TxBuilder> {
|
|
98
|
-
if (!assetClass && !utxo)
|
|
99
|
-
throw new Error('Either interest oracle nft or utxo must be provided');
|
|
100
|
-
if (assetClass && !utxo) {
|
|
101
|
-
const [ioUtxo, _datum] = await findInterestOracle(lucid, assetClass);
|
|
102
|
-
utxo = ioUtxo;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const now = BigInt(Date.now());
|
|
106
|
-
const tx = lucid.newTx();
|
|
107
|
-
const datum = parseInterestOracleDatum(utxo.datum);
|
|
108
|
-
|
|
109
|
-
if (scriptRef) {
|
|
110
|
-
tx.readFrom([scriptRef]);
|
|
111
|
-
} else {
|
|
112
|
-
tx.attach.Script(mkInterestOracleValidator(params));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
tx.collectFrom(
|
|
116
|
-
[utxo],
|
|
117
|
-
serialiseFeedInterestOracleRedeemer({
|
|
118
|
-
newInterestRate: {
|
|
119
|
-
getOnChainInt: newInterestRate,
|
|
120
|
-
},
|
|
121
|
-
currentTime: now,
|
|
122
|
-
}),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
tx.pay.ToContract(
|
|
126
|
-
utxo.address,
|
|
127
|
-
{
|
|
128
|
-
kind: 'inline',
|
|
129
|
-
value: serialiseInterestOracleDatum({
|
|
130
|
-
unitaryInterest:
|
|
131
|
-
datum.unitaryInterest +
|
|
132
|
-
calculateUnitaryInterestSinceOracleLastUpdated(now, datum),
|
|
133
|
-
interestRate: {
|
|
134
|
-
getOnChainInt: newInterestRate,
|
|
135
|
-
},
|
|
136
|
-
lastUpdated: now,
|
|
137
|
-
}),
|
|
138
|
-
},
|
|
139
|
-
utxo.assets,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
tx.validFrom(Number(now) - ONE_SECOND);
|
|
143
|
-
tx.validTo(Number(now + params.biasTime) - ONE_SECOND);
|
|
144
|
-
|
|
145
|
-
tx.addSignerKey(params.owner);
|
|
146
|
-
|
|
147
|
-
return tx;
|
|
148
|
-
}
|
|
149
|
-
}
|
package/src/contracts/lrp.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LucidEvolution,
|
|
3
|
-
Network,
|
|
4
|
-
ScriptHash,
|
|
5
|
-
TxBuilder,
|
|
6
|
-
Credential,
|
|
7
|
-
OutRef,
|
|
8
|
-
UTxO,
|
|
9
|
-
addAssets,
|
|
10
|
-
} from '@lucid-evolution/lucid';
|
|
11
|
-
import {
|
|
12
|
-
addrDetails,
|
|
13
|
-
createScriptAddress,
|
|
14
|
-
getInlineDatumOrThrow,
|
|
15
|
-
} from '../helpers/lucid-utils';
|
|
16
|
-
import { match, P } from 'ts-pattern';
|
|
17
|
-
import { unzip, zip } from 'fp-ts/lib/Array';
|
|
18
|
-
import { reduceWithIndex } from 'fp-ts/lib/Array';
|
|
19
|
-
import {
|
|
20
|
-
LRPDatum,
|
|
21
|
-
LRPParams,
|
|
22
|
-
parseLrpDatum,
|
|
23
|
-
serialiseLrpDatum,
|
|
24
|
-
serialiseLrpRedeemer,
|
|
25
|
-
} from '../types/indigo/lrp';
|
|
26
|
-
import {
|
|
27
|
-
parsePriceOracleDatum,
|
|
28
|
-
PriceOracleParams,
|
|
29
|
-
} from '../types/indigo/price-oracle';
|
|
30
|
-
import { ocdMul, OnChainDecimal } from '../types/on-chain-decimal';
|
|
31
|
-
import { parseIAssetDatum } from '../types/indigo/cdp';
|
|
32
|
-
import { mkAssetsOf, mkLovelacesOf } from '../helpers/value-helpers';
|
|
33
|
-
import { oracleExpirationAwareValidity } from '../helpers/price-oracle-helpers';
|
|
34
|
-
import { calculateFeeFromPercentage } from '../helpers/indigo-helpers';
|
|
35
|
-
import { matchSingle } from '../helpers/helpers';
|
|
36
|
-
|
|
37
|
-
const MIN_UTXO_COLLATERAL_AMT = 2_000_000n;
|
|
38
|
-
|
|
39
|
-
export async function openLrp(
|
|
40
|
-
assetTokenName: string,
|
|
41
|
-
lovelacesAmt: bigint,
|
|
42
|
-
maxPrice: OnChainDecimal,
|
|
43
|
-
lucid: LucidEvolution,
|
|
44
|
-
lrpScriptHash: ScriptHash,
|
|
45
|
-
network: Network,
|
|
46
|
-
lrpStakeCredential?: Credential,
|
|
47
|
-
): Promise<TxBuilder> {
|
|
48
|
-
const [ownPkh, _] = await addrDetails(lucid);
|
|
49
|
-
|
|
50
|
-
const newDatum: LRPDatum = {
|
|
51
|
-
owner: ownPkh.hash,
|
|
52
|
-
iasset: assetTokenName,
|
|
53
|
-
maxPrice: maxPrice,
|
|
54
|
-
lovelacesToSpend: lovelacesAmt,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return lucid.newTx().pay.ToContract(
|
|
58
|
-
createScriptAddress(network, lrpScriptHash, lrpStakeCredential),
|
|
59
|
-
{
|
|
60
|
-
kind: 'inline',
|
|
61
|
-
value: serialiseLrpDatum(newDatum),
|
|
62
|
-
},
|
|
63
|
-
{ lovelace: lovelacesAmt + MIN_UTXO_COLLATERAL_AMT },
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export async function cancelLrp(
|
|
68
|
-
lrpOutRef: OutRef,
|
|
69
|
-
lrpRefScriptOutRef: OutRef,
|
|
70
|
-
lucid: LucidEvolution,
|
|
71
|
-
): Promise<TxBuilder> {
|
|
72
|
-
const ownAddr = await lucid.wallet().address();
|
|
73
|
-
// TODO: use Promise.all
|
|
74
|
-
const lrpScriptRefUtxo = matchSingle(
|
|
75
|
-
await lucid.utxosByOutRef([lrpRefScriptOutRef]),
|
|
76
|
-
(_) => new Error('Expected a single LRP Ref Script UTXO'),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const lrpUtxo = matchSingle(
|
|
80
|
-
await lucid.utxosByOutRef([lrpOutRef]),
|
|
81
|
-
(_) => new Error('Expected a single LRP UTXO.'),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return lucid
|
|
85
|
-
.newTx()
|
|
86
|
-
.readFrom([lrpScriptRefUtxo])
|
|
87
|
-
.collectFrom([lrpUtxo], serialiseLrpRedeemer('Cancel'))
|
|
88
|
-
.addSigner(ownAddr);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function redeemLrp(
|
|
92
|
-
redemptionLrpsData: [OutRef, bigint][],
|
|
93
|
-
lrpRefScriptOutRef: OutRef,
|
|
94
|
-
priceOracleOutRef: OutRef,
|
|
95
|
-
iassetOutRef: OutRef,
|
|
96
|
-
lucid: LucidEvolution,
|
|
97
|
-
lrpParams: LRPParams,
|
|
98
|
-
priceOracleParams: PriceOracleParams,
|
|
99
|
-
network: Network,
|
|
100
|
-
): Promise<TxBuilder> {
|
|
101
|
-
const lrpScriptRefUtxo = matchSingle(
|
|
102
|
-
await lucid.utxosByOutRef([lrpRefScriptOutRef]),
|
|
103
|
-
(_) => new Error('Expected a single LRP Ref Script UTXO'),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const priceOracleUtxo = matchSingle(
|
|
107
|
-
await lucid.utxosByOutRef([priceOracleOutRef]),
|
|
108
|
-
(_) => new Error('Expected a single price oracle UTXO'),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const iassetUtxo = matchSingle(
|
|
112
|
-
await lucid.utxosByOutRef([iassetOutRef]),
|
|
113
|
-
(_) => new Error('Expected a single IAsset UTXO'),
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const iassetDatum = parseIAssetDatum(getInlineDatumOrThrow(iassetUtxo));
|
|
117
|
-
|
|
118
|
-
const [lrpsToRedeemOutRefs, lrpRedemptionIAssetAmt] =
|
|
119
|
-
unzip(redemptionLrpsData);
|
|
120
|
-
|
|
121
|
-
const priceOracleDatum = parsePriceOracleDatum(
|
|
122
|
-
getInlineDatumOrThrow(priceOracleUtxo),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const redemptionLrps = await lucid
|
|
126
|
-
.utxosByOutRef(lrpsToRedeemOutRefs)
|
|
127
|
-
.then((val) => zip(val, lrpRedemptionIAssetAmt));
|
|
128
|
-
|
|
129
|
-
const [[mainLrpUtxo, mainLrpRedemptionIAssetAmt], _] = match(redemptionLrps)
|
|
130
|
-
.with(
|
|
131
|
-
[P._, ...P.array()],
|
|
132
|
-
([[firstLrp, firstLrpIAssetAmt], ...rest]): [
|
|
133
|
-
[UTxO, bigint],
|
|
134
|
-
[UTxO, bigint][],
|
|
135
|
-
] => [[firstLrp, firstLrpIAssetAmt], rest],
|
|
136
|
-
)
|
|
137
|
-
.otherwise(() => {
|
|
138
|
-
throw new Error('Expects at least 1 UTXO to redeem.');
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
const mainLrpDatum = parseLrpDatum(getInlineDatumOrThrow(mainLrpUtxo));
|
|
142
|
-
|
|
143
|
-
const tx = reduceWithIndex<[UTxO, bigint], TxBuilder>(
|
|
144
|
-
lucid.newTx(),
|
|
145
|
-
(idx, acc, [lrpUtxo, redeemIAssetAmt]) => {
|
|
146
|
-
const lovelacesForRedemption = ocdMul(
|
|
147
|
-
{
|
|
148
|
-
getOnChainInt: mainLrpRedemptionIAssetAmt,
|
|
149
|
-
},
|
|
150
|
-
priceOracleDatum.price,
|
|
151
|
-
).getOnChainInt;
|
|
152
|
-
const reimburstmentLovelaces = calculateFeeFromPercentage(
|
|
153
|
-
iassetDatum.redemptionReimbursementPercentage,
|
|
154
|
-
lovelacesForRedemption,
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
const lrpDatum = parseLrpDatum(getInlineDatumOrThrow(lrpUtxo));
|
|
158
|
-
|
|
159
|
-
return acc
|
|
160
|
-
.collectFrom(
|
|
161
|
-
[lrpUtxo],
|
|
162
|
-
serialiseLrpRedeemer(
|
|
163
|
-
idx === 0
|
|
164
|
-
? { Redeem: { continuingOutputIdx: 0n } }
|
|
165
|
-
: {
|
|
166
|
-
RedeemAuxiliary: {
|
|
167
|
-
continuingOutputIdx: BigInt(idx),
|
|
168
|
-
mainRedeemOutRef: {
|
|
169
|
-
txHash: { hash: mainLrpUtxo.txHash },
|
|
170
|
-
outputIndex: BigInt(mainLrpUtxo.outputIndex),
|
|
171
|
-
},
|
|
172
|
-
asset: mainLrpDatum.iasset,
|
|
173
|
-
assetPrice: priceOracleDatum.price,
|
|
174
|
-
redemptionReimbursementPercentage:
|
|
175
|
-
iassetDatum.redemptionReimbursementPercentage,
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
),
|
|
179
|
-
)
|
|
180
|
-
.pay.ToContract(
|
|
181
|
-
lrpUtxo.address,
|
|
182
|
-
{
|
|
183
|
-
kind: 'inline',
|
|
184
|
-
value: serialiseLrpDatum({
|
|
185
|
-
...lrpDatum,
|
|
186
|
-
lovelacesToSpend:
|
|
187
|
-
lrpDatum.lovelacesToSpend - lovelacesForRedemption,
|
|
188
|
-
}),
|
|
189
|
-
},
|
|
190
|
-
addAssets(
|
|
191
|
-
lrpUtxo.assets,
|
|
192
|
-
mkLovelacesOf(-(lovelacesForRedemption - reimburstmentLovelaces)),
|
|
193
|
-
mkAssetsOf(
|
|
194
|
-
{
|
|
195
|
-
currencySymbol: lrpParams.iassetPolicyId,
|
|
196
|
-
tokenName: mainLrpDatum.iasset,
|
|
197
|
-
},
|
|
198
|
-
redeemIAssetAmt,
|
|
199
|
-
),
|
|
200
|
-
),
|
|
201
|
-
);
|
|
202
|
-
},
|
|
203
|
-
)(redemptionLrps);
|
|
204
|
-
|
|
205
|
-
const txValidity = oracleExpirationAwareValidity(
|
|
206
|
-
lucid.currentSlot(),
|
|
207
|
-
Number(priceOracleParams.biasTime),
|
|
208
|
-
Number(priceOracleDatum.expiration),
|
|
209
|
-
network,
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
return (
|
|
213
|
-
lucid
|
|
214
|
-
.newTx()
|
|
215
|
-
// .validFrom(txValidity.validFrom)
|
|
216
|
-
.validTo(txValidity.validTo)
|
|
217
|
-
// Ref script
|
|
218
|
-
.readFrom([lrpScriptRefUtxo])
|
|
219
|
-
// Ref inputs
|
|
220
|
-
.readFrom([iassetUtxo, priceOracleUtxo])
|
|
221
|
-
.compose(tx)
|
|
222
|
-
);
|
|
223
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Assets,
|
|
4
|
-
Constr,
|
|
5
|
-
Data,
|
|
6
|
-
LucidEvolution,
|
|
7
|
-
mintingPolicyToId,
|
|
8
|
-
PolicyId,
|
|
9
|
-
toUnit,
|
|
10
|
-
TxBuilder,
|
|
11
|
-
} from '@lucid-evolution/lucid';
|
|
12
|
-
import { OneShotParams } from '../types/one-shot';
|
|
13
|
-
import { matchSingle } from '../helpers/helpers';
|
|
14
|
-
import { mkOneShotPolicy } from '../scripts/one-shot-policy';
|
|
15
|
-
import { reduce } from 'fp-ts/lib/Array';
|
|
16
|
-
|
|
17
|
-
export async function oneShotMintTx(
|
|
18
|
-
lucid: LucidEvolution,
|
|
19
|
-
params: OneShotParams,
|
|
20
|
-
): Promise<[TxBuilder, PolicyId]> {
|
|
21
|
-
const oneShotPolicy = mkOneShotPolicy(params);
|
|
22
|
-
const policyId = mintingPolicyToId(oneShotPolicy);
|
|
23
|
-
|
|
24
|
-
const refUtxo = matchSingle(
|
|
25
|
-
await lucid.utxosByOutRef([
|
|
26
|
-
{
|
|
27
|
-
txHash: params.referenceOutRef.txHash,
|
|
28
|
-
outputIndex: Number(params.referenceOutRef.outputIdx),
|
|
29
|
-
},
|
|
30
|
-
]),
|
|
31
|
-
(_) => {
|
|
32
|
-
throw new Error('Cannot find the reference UTXO for one-shot.');
|
|
33
|
-
},
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return [
|
|
37
|
-
lucid
|
|
38
|
-
.newTx()
|
|
39
|
-
.collectFrom([refUtxo])
|
|
40
|
-
.mintAssets(
|
|
41
|
-
reduce<{ tokenName: string; amount: bigint }, Assets>(
|
|
42
|
-
{},
|
|
43
|
-
(acc, entry) =>
|
|
44
|
-
addAssets(acc, {
|
|
45
|
-
[toUnit(policyId, entry.tokenName)]: entry.amount,
|
|
46
|
-
}),
|
|
47
|
-
)(params.mintAmounts),
|
|
48
|
-
Data.to(new Constr(0, [])),
|
|
49
|
-
)
|
|
50
|
-
.attach.MintingPolicy(oneShotPolicy),
|
|
51
|
-
policyId,
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function runOneShotMintTx(
|
|
56
|
-
lucid: LucidEvolution,
|
|
57
|
-
params: OneShotParams,
|
|
58
|
-
): Promise<PolicyId> {
|
|
59
|
-
const [tx, policyId] = await oneShotMintTx(lucid, params);
|
|
60
|
-
const txHash = await tx
|
|
61
|
-
.complete()
|
|
62
|
-
.then((tx) => tx.sign.withWallet().complete())
|
|
63
|
-
.then((tx) => tx.submit());
|
|
64
|
-
|
|
65
|
-
await lucid.awaitTx(txHash);
|
|
66
|
-
return policyId;
|
|
67
|
-
}
|