@indigo-labs/indigo-sdk 0.5.4 → 0.5.6
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/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +17 -0
- package/dist/index.mjs +15 -0
- package/package.json +11 -1
- package/.claude/settings.local.json +0 -7
- package/.github/workflows/ci.yml +0 -66
- package/.husky/pre-commit +0 -1
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/.prettierrc +0 -6
- package/eslint.config.mjs +0 -42
- package/scripts/bench.sh +0 -62
- package/scripts/run-repeat.sh +0 -22
- package/src/contracts/cdp/helpers.ts +0 -173
- package/src/contracts/cdp/scripts.ts +0 -70
- package/src/contracts/cdp/transactions.ts +0 -1584
- package/src/contracts/cdp/types-new.ts +0 -277
- package/src/contracts/cdp/types.ts +0 -43
- package/src/contracts/cdp-creator/queries.ts +0 -30
- package/src/contracts/cdp-creator/scripts.ts +0 -45
- package/src/contracts/cdp-creator/types-new.ts +0 -50
- package/src/contracts/cdp-creator/types.ts +0 -24
- package/src/contracts/collector/scripts.ts +0 -32
- package/src/contracts/collector/transactions.ts +0 -50
- package/src/contracts/collector/types-new.ts +0 -17
- package/src/contracts/execute/scripts.ts +0 -57
- package/src/contracts/execute/types-new.ts +0 -44
- package/src/contracts/execute/types.ts +0 -24
- package/src/contracts/gov/helpers.ts +0 -351
- package/src/contracts/gov/scripts.ts +0 -41
- package/src/contracts/gov/transactions.ts +0 -1607
- package/src/contracts/gov/types-new.ts +0 -268
- package/src/contracts/gov/types.ts +0 -22
- package/src/contracts/iasset/helpers.ts +0 -170
- package/src/contracts/iasset/queries.ts +0 -102
- package/src/contracts/iasset/scripts.ts +0 -38
- package/src/contracts/iasset/types.ts +0 -154
- package/src/contracts/initialize/actions.ts +0 -789
- package/src/contracts/initialize/helpers.ts +0 -616
- package/src/contracts/initialize/types.ts +0 -116
- package/src/contracts/interest-collection/helpers.ts +0 -19
- package/src/contracts/interest-collection/queries.ts +0 -66
- package/src/contracts/interest-collection/scripts.ts +0 -44
- package/src/contracts/interest-collection/transactions.ts +0 -433
- package/src/contracts/interest-collection/types-new.ts +0 -50
- package/src/contracts/interest-collection/types.ts +0 -26
- package/src/contracts/interest-oracle/helpers.ts +0 -61
- package/src/contracts/interest-oracle/scripts.ts +0 -18
- package/src/contracts/interest-oracle/transactions.ts +0 -151
- package/src/contracts/interest-oracle/types-new.ts +0 -32
- package/src/contracts/interest-oracle/types.ts +0 -16
- package/src/contracts/one-shot/scripts.ts +0 -12
- package/src/contracts/one-shot/transactions.ts +0 -66
- package/src/contracts/one-shot/types.ts +0 -22
- package/src/contracts/poll/helpers.ts +0 -37
- package/src/contracts/poll/scripts.ts +0 -71
- package/src/contracts/poll/types-poll-manager.ts +0 -20
- package/src/contracts/poll/types-poll-new.ts +0 -196
- package/src/contracts/poll/types-poll-shard.ts +0 -16
- package/src/contracts/price-oracle/helpers.ts +0 -30
- package/src/contracts/price-oracle/scripts.ts +0 -18
- package/src/contracts/price-oracle/transactions.ts +0 -115
- package/src/contracts/price-oracle/types-new.ts +0 -50
- package/src/contracts/price-oracle/types.ts +0 -16
- package/src/contracts/pyth-feed/helpers.ts +0 -82
- package/src/contracts/pyth-feed/scripts.ts +0 -15
- package/src/contracts/pyth-feed/types.ts +0 -181
- package/src/contracts/rob/helpers.ts +0 -666
- package/src/contracts/rob/scripts.ts +0 -35
- package/src/contracts/rob/transactions.ts +0 -423
- package/src/contracts/rob/types-new.ts +0 -128
- package/src/contracts/rob/types.ts +0 -16
- package/src/contracts/rob-leverage/helpers.ts +0 -422
- package/src/contracts/rob-leverage/transactions.ts +0 -368
- package/src/contracts/stability-pool/helpers.ts +0 -798
- package/src/contracts/stability-pool/queries.ts +0 -132
- package/src/contracts/stability-pool/scripts.ts +0 -51
- package/src/contracts/stability-pool/transactions.ts +0 -921
- package/src/contracts/stability-pool/types-new.ts +0 -385
- package/src/contracts/stability-pool/types.ts +0 -25
- package/src/contracts/stableswap/helpers.ts +0 -507
- package/src/contracts/stableswap/scripts.ts +0 -37
- package/src/contracts/stableswap/transactions.ts +0 -475
- package/src/contracts/stableswap/types-new.ts +0 -131
- package/src/contracts/stableswap/types.ts +0 -17
- package/src/contracts/staking/helpers.ts +0 -136
- package/src/contracts/staking/scripts.ts +0 -41
- package/src/contracts/staking/transactions.ts +0 -349
- package/src/contracts/staking/types-new.ts +0 -137
- package/src/contracts/staking/types.ts +0 -17
- package/src/contracts/treasury/helpers.ts +0 -21
- package/src/contracts/treasury/queries.ts +0 -100
- package/src/contracts/treasury/scripts.ts +0 -27
- package/src/contracts/treasury/transactions.ts +0 -334
- package/src/contracts/treasury/types-new.ts +0 -69
- package/src/contracts/treasury/types.ts +0 -14
- package/src/contracts/version-registry/scripts.ts +0 -29
- package/src/contracts/version-registry/types-new.ts +0 -18
- package/src/contracts/version-registry/types.ts +0 -17
- package/src/index.ts +0 -93
- package/src/scripts/always-fail-validator.ts +0 -7
- package/src/scripts/auth-token-policy.ts +0 -24
- package/src/scripts/iasset-policy.ts +0 -23
- package/src/types/evolution-schema-options.ts +0 -16
- package/src/types/generic.ts +0 -52
- package/src/types/multisig.ts +0 -48
- package/src/types/on-chain-decimal.ts +0 -57
- package/src/types/rational.ts +0 -61
- package/src/types/system-params.ts +0 -463
- package/src/utils/array-utils.ts +0 -108
- package/src/utils/bigint-utils.ts +0 -35
- package/src/utils/helper-txs.ts +0 -31
- package/src/utils/indigo-helpers.ts +0 -17
- package/src/utils/lucid-utils.ts +0 -125
- package/src/utils/oracle-helpers.ts +0 -62
- package/src/utils/pyth/decode.ts +0 -223
- package/src/utils/pyth/encode.ts +0 -262
- package/src/utils/pyth/index.ts +0 -14
- package/src/utils/pyth/types.ts +0 -87
- package/src/utils/time-helpers.ts +0 -4
- package/src/utils/utils.ts +0 -25
- package/src/validators/always-succeed-validator.ts +0 -6
- package/src/validators/cdp-creator-validator.ts +0 -7
- package/src/validators/cdp-redeem-validator.ts +0 -7
- package/src/validators/cdp-validator.ts +0 -7
- package/src/validators/collector-validator.ts +0 -7
- package/src/validators/execute-validator.ts +0 -7
- package/src/validators/governance-validator.ts +0 -7
- package/src/validators/iasset-validator.ts +0 -7
- package/src/validators/interest-collection-validator.ts +0 -7
- package/src/validators/interest-oracle-validator.ts +0 -7
- package/src/validators/one-shot-policy.ts +0 -7
- package/src/validators/poll-manager-validator.ts +0 -7
- package/src/validators/poll-shard-validator.ts +0 -7
- package/src/validators/price-oracle-validator.ts +0 -7
- package/src/validators/pyth-feed-validator.ts +0 -7
- package/src/validators/rob-validator.ts +0 -7
- package/src/validators/stability-pool-validator.ts +0 -7
- package/src/validators/stableswap-validator.ts +0 -7
- package/src/validators/staking-validator.ts +0 -7
- package/src/validators/treasury-validator.ts +0 -7
- package/src/validators/version-record-policy.ts +0 -7
- package/src/validators/version-registry-validator.ts +0 -7
- package/tests/always-succeed/script.ts +0 -7
- package/tests/array-utils.test.ts +0 -92
- package/tests/bigint-utils.test.ts +0 -41
- package/tests/cdp/actions.ts +0 -680
- package/tests/cdp/cdp-helpers.ts +0 -55
- package/tests/cdp/cdp-queries.ts +0 -423
- package/tests/cdp/cdp.test.ts +0 -6730
- package/tests/cdp/transactions-mutated.ts +0 -1733
- package/tests/data/system-params.json +0 -1155
- package/tests/datums.test.ts +0 -302
- package/tests/endpoints/initialize.ts +0 -78
- package/tests/endpoints/interest-collector.ts +0 -37
- package/tests/endpoints/treasury.ts +0 -70
- package/tests/gov/actions.ts +0 -381
- package/tests/gov/gov.test.ts +0 -5147
- package/tests/gov/governance-queries.ts +0 -37
- package/tests/hash-checks.test.ts +0 -112
- package/tests/indigo-test-helpers.ts +0 -99
- package/tests/initialize.test.ts +0 -79
- package/tests/interest-calculations.test.ts +0 -120
- package/tests/interest-collection/interest-collection.test.ts +0 -843
- package/tests/interest-collection/transactions-mutated.ts +0 -260
- package/tests/interest-oracle.test.ts +0 -93
- package/tests/mock/assets-mock.ts +0 -243
- package/tests/mock/protocol-params-mock.ts +0 -21
- package/tests/price-oracle/actions.ts +0 -161
- package/tests/price-oracle/price-oracle-queries.ts +0 -12
- package/tests/price-oracle/price-oracle.test.ts +0 -228
- package/tests/price-oracle/transactions-mutated.ts +0 -59
- package/tests/pyth/endpoints.ts +0 -96
- package/tests/pyth/helpers.ts +0 -37
- package/tests/pyth/pyth-encoding.test.ts +0 -376
- package/tests/pyth/pyth-feeds.test.ts +0 -943
- package/tests/pyth/pyth-indigo.test.ts +0 -505
- package/tests/pyth/pyth.test.ts +0 -299
- package/tests/queries/collector-queries.ts +0 -27
- package/tests/queries/execute-queries.ts +0 -47
- package/tests/queries/iasset-queries.ts +0 -149
- package/tests/queries/interest-oracle-queries.ts +0 -12
- package/tests/queries/poll-queries.ts +0 -97
- package/tests/queries/staking-queries.ts +0 -54
- package/tests/rob/actions.ts +0 -56
- package/tests/rob/rob-leverage.test.ts +0 -2555
- package/tests/rob/rob-queries.ts +0 -95
- package/tests/rob/rob.test.ts +0 -3677
- package/tests/rob/transactions-mutated.ts +0 -844
- package/tests/script-size.test.ts +0 -240
- package/tests/setup.ts +0 -135
- package/tests/stability-pool/actions.ts +0 -229
- package/tests/stability-pool.test.ts +0 -6491
- package/tests/stableswap/stableswap-actions.ts +0 -83
- package/tests/stableswap/stableswap-queries.ts +0 -98
- package/tests/stableswap/stableswap.test.ts +0 -4471
- package/tests/stableswap/transactions-mutated.ts +0 -348
- package/tests/staking.test.ts +0 -172
- package/tests/test-helpers.ts +0 -94
- package/tests/treasury/actions.ts +0 -67
- package/tests/treasury/treasury.test.ts +0 -320
- package/tests/utils/asserts.ts +0 -87
- package/tests/utils/benchmark-utils.ts +0 -130
- package/tests/utils/index.ts +0 -168
- package/tsconfig.build.json +0 -4
- package/tsconfig.json +0 -27
- package/vitest.config.ts +0 -11
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addAssets,
|
|
3
|
-
Address,
|
|
4
|
-
credentialToAddress,
|
|
5
|
-
Data,
|
|
6
|
-
fromHex,
|
|
7
|
-
fromText,
|
|
8
|
-
LucidEvolution,
|
|
9
|
-
OutRef,
|
|
10
|
-
paymentCredentialOf,
|
|
11
|
-
sortUTxOs,
|
|
12
|
-
toHex,
|
|
13
|
-
TxBuilder,
|
|
14
|
-
} from '@lucid-evolution/lucid';
|
|
15
|
-
import {
|
|
16
|
-
fromSystemParamsScriptRef,
|
|
17
|
-
SystemParams,
|
|
18
|
-
} from '../../types/system-params';
|
|
19
|
-
import {
|
|
20
|
-
parseStableswapOrderDatumOrThrow,
|
|
21
|
-
serialiseStableswapOrderDatum,
|
|
22
|
-
serialiseStableswapOrderRedeemer,
|
|
23
|
-
StableswapOrderDatum,
|
|
24
|
-
} from './types-new';
|
|
25
|
-
import {
|
|
26
|
-
AssetClass,
|
|
27
|
-
addressFromBech32,
|
|
28
|
-
addressToBech32,
|
|
29
|
-
getInlineDatumOrThrow,
|
|
30
|
-
matchSingle,
|
|
31
|
-
mkAssetsOf,
|
|
32
|
-
mkLovelacesOf,
|
|
33
|
-
lovelacesAmt,
|
|
34
|
-
isSameOutRef,
|
|
35
|
-
assetClassValueOf,
|
|
36
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
37
|
-
import {
|
|
38
|
-
parseStableswapPoolDatumOrThrow,
|
|
39
|
-
serialiseCdpRedeemer,
|
|
40
|
-
serialiseStableswapPoolDatum,
|
|
41
|
-
StableswapPoolContent,
|
|
42
|
-
} from '../cdp/types-new';
|
|
43
|
-
import { array as A, function as F } from 'fp-ts';
|
|
44
|
-
import { isEmpty } from 'fp-ts/lib/Array';
|
|
45
|
-
import {
|
|
46
|
-
BASE_MAX_EXECUTION_FEE,
|
|
47
|
-
createDestinationDatum,
|
|
48
|
-
estimateMinOrderOutputLovelaces,
|
|
49
|
-
PSMProcessingConfig,
|
|
50
|
-
StableswapInfo,
|
|
51
|
-
StableswapOrderInfo,
|
|
52
|
-
summariseOrder,
|
|
53
|
-
} from './helpers';
|
|
54
|
-
import * as Core from '@evolution-sdk/evolution';
|
|
55
|
-
import { treasuryFeeTx } from '../treasury/transactions';
|
|
56
|
-
import { Rational } from '../../types/rational';
|
|
57
|
-
|
|
58
|
-
export async function createStableswapOrder(
|
|
59
|
-
iasset: string,
|
|
60
|
-
collateralAsset: AssetClass,
|
|
61
|
-
amount: bigint,
|
|
62
|
-
minting: boolean,
|
|
63
|
-
poolDatum: StableswapPoolContent,
|
|
64
|
-
params: SystemParams,
|
|
65
|
-
lucid: LucidEvolution,
|
|
66
|
-
destinationAddress?: Address,
|
|
67
|
-
destinationInlineDatum?: Core.Data.Data,
|
|
68
|
-
maxExecutionFee: bigint = BASE_MAX_EXECUTION_FEE,
|
|
69
|
-
additionalLovelaces: bigint = 0n,
|
|
70
|
-
maxFeeRatio?: Rational,
|
|
71
|
-
): Promise<TxBuilder> {
|
|
72
|
-
const myAddress = await lucid.wallet().address();
|
|
73
|
-
|
|
74
|
-
const pkh = paymentCredentialOf(myAddress);
|
|
75
|
-
|
|
76
|
-
const datum: StableswapOrderDatum = {
|
|
77
|
-
iasset: fromHex(fromText(iasset)),
|
|
78
|
-
collateralAsset: collateralAsset,
|
|
79
|
-
owner: fromHex(pkh.hash),
|
|
80
|
-
destination: addressFromBech32(destinationAddress ?? myAddress),
|
|
81
|
-
destinationInlineDatum: destinationInlineDatum ?? null,
|
|
82
|
-
maxExecutionFee: maxExecutionFee,
|
|
83
|
-
maxFeeRatio:
|
|
84
|
-
maxFeeRatio ??
|
|
85
|
-
(minting ? poolDatum.mintingFeeRatio : poolDatum.redemptionFeeRatio),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const assetsToSwap = minting
|
|
89
|
-
? mkAssetsOf(collateralAsset, amount)
|
|
90
|
-
: mkAssetsOf(
|
|
91
|
-
{
|
|
92
|
-
currencySymbol: fromHex(
|
|
93
|
-
params.stableswapParams.iassetSymbol.unCurrencySymbol,
|
|
94
|
-
),
|
|
95
|
-
tokenName: fromHex(fromText(iasset)),
|
|
96
|
-
},
|
|
97
|
-
amount,
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const orderAssetsPlusFees = addAssets(
|
|
101
|
-
assetsToSwap,
|
|
102
|
-
mkLovelacesOf(maxExecutionFee),
|
|
103
|
-
mkLovelacesOf(additionalLovelaces),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const expectedMinOutputLovelaces = estimateMinOrderOutputLovelaces(
|
|
107
|
-
lucid,
|
|
108
|
-
datum,
|
|
109
|
-
orderAssetsPlusFees,
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
return lucid.newTx().pay.ToContract(
|
|
113
|
-
credentialToAddress(lucid.config().network!, {
|
|
114
|
-
hash: params.validatorHashes.stableswapHash,
|
|
115
|
-
type: 'Script',
|
|
116
|
-
}),
|
|
117
|
-
{
|
|
118
|
-
kind: 'inline',
|
|
119
|
-
value: serialiseStableswapOrderDatum(datum),
|
|
120
|
-
},
|
|
121
|
-
addAssets(orderAssetsPlusFees, mkLovelacesOf(expectedMinOutputLovelaces)),
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function cancelStableswapOrder(
|
|
126
|
-
stableswapOrderOref: OutRef,
|
|
127
|
-
sysParams: SystemParams,
|
|
128
|
-
lucid: LucidEvolution,
|
|
129
|
-
): Promise<TxBuilder> {
|
|
130
|
-
const stableswapScriptRefUtxo = matchSingle(
|
|
131
|
-
await lucid.utxosByOutRef([
|
|
132
|
-
fromSystemParamsScriptRef(
|
|
133
|
-
sysParams.scriptReferences.stableswapValidatorRef,
|
|
134
|
-
),
|
|
135
|
-
]),
|
|
136
|
-
(_) => new Error('Expected a single Stableswap Ref Script UTXO'),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const stableswapOrderUtxo = matchSingle(
|
|
140
|
-
await lucid.utxosByOutRef([stableswapOrderOref]),
|
|
141
|
-
(_) => new Error('Expected a single Stableswap Order UTXO.'),
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const stableswapOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
145
|
-
getInlineDatumOrThrow(stableswapOrderUtxo),
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
return lucid
|
|
149
|
-
.newTx()
|
|
150
|
-
.readFrom([stableswapScriptRefUtxo])
|
|
151
|
-
.collectFrom(
|
|
152
|
-
[stableswapOrderUtxo],
|
|
153
|
-
serialiseStableswapOrderRedeemer('CancelStableswapOrder'),
|
|
154
|
-
)
|
|
155
|
-
.addSignerKey(toHex(stableswapOrderDatum.owner));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function batchProcessStableswapOrders(
|
|
159
|
-
stableswapOrderOrefs: OutRef[],
|
|
160
|
-
stableswapPoolOref: OutRef,
|
|
161
|
-
treasuryOref: OutRef,
|
|
162
|
-
sysParams: SystemParams,
|
|
163
|
-
lucid: LucidEvolution,
|
|
164
|
-
psmProcessingConfig?: PSMProcessingConfig,
|
|
165
|
-
): Promise<TxBuilder> {
|
|
166
|
-
const stableswapScriptRefUtxo = matchSingle(
|
|
167
|
-
await lucid.utxosByOutRef([
|
|
168
|
-
fromSystemParamsScriptRef(
|
|
169
|
-
sysParams.scriptReferences.stableswapValidatorRef,
|
|
170
|
-
),
|
|
171
|
-
]),
|
|
172
|
-
(_) => new Error('Expected a single Stableswap Ref Script UTXO'),
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
const cdpScriptRefUtxo = matchSingle(
|
|
176
|
-
await lucid.utxosByOutRef([
|
|
177
|
-
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef),
|
|
178
|
-
]),
|
|
179
|
-
(_) => new Error('Expected a single CDP Ref Script UTXO'),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
|
-
const iAssetTokenPolicyRefScriptUtxo = matchSingle(
|
|
183
|
-
await lucid.utxosByOutRef([
|
|
184
|
-
fromSystemParamsScriptRef(
|
|
185
|
-
sysParams.scriptReferences.iAssetTokenPolicyRef,
|
|
186
|
-
),
|
|
187
|
-
]),
|
|
188
|
-
(_) => new Error('Expected a single iasset token policy Ref Script UTXO'),
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
if (isEmpty(stableswapOrderOrefs)) {
|
|
192
|
-
throw new Error('At least one order must be provided.');
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const stableswapOrderUtxos = await lucid.utxosByOutRef(stableswapOrderOrefs);
|
|
196
|
-
|
|
197
|
-
const sortedStableswapOrderUtxos = sortUTxOs(
|
|
198
|
-
stableswapOrderUtxos,
|
|
199
|
-
'Canonical',
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
if (sortedStableswapOrderUtxos.length !== stableswapOrderOrefs.length) {
|
|
203
|
-
throw new Error('Expected certain number of orders');
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const mainOrderUtxo = sortedStableswapOrderUtxos[0];
|
|
207
|
-
|
|
208
|
-
const mainOrderDatum = parseStableswapOrderDatumOrThrow(
|
|
209
|
-
getInlineDatumOrThrow(mainOrderUtxo),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
const iassetAc = {
|
|
213
|
-
currencySymbol: fromHex(
|
|
214
|
-
sysParams.stableswapParams.iassetSymbol.unCurrencySymbol,
|
|
215
|
-
),
|
|
216
|
-
tokenName: mainOrderDatum.iasset,
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const collateralAc = mainOrderDatum.collateralAsset;
|
|
220
|
-
|
|
221
|
-
const stableswapPoolUtxo = matchSingle(
|
|
222
|
-
await lucid.utxosByOutRef([stableswapPoolOref]),
|
|
223
|
-
(_) => new Error('Expected a single cdp UTXO'),
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
227
|
-
getInlineDatumOrThrow(stableswapPoolUtxo),
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
const ordersInfo: StableswapOrderInfo[] = sortedStableswapOrderUtxos.map(
|
|
231
|
-
(orderUtxo) => {
|
|
232
|
-
const orderDatum = parseStableswapOrderDatumOrThrow(
|
|
233
|
-
getInlineDatumOrThrow(orderUtxo),
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
const res = summariseOrder(
|
|
237
|
-
lucid,
|
|
238
|
-
{ utxo: orderUtxo, datum: orderDatum },
|
|
239
|
-
{ utxo: stableswapPoolUtxo, datum: stableswapPoolDatum },
|
|
240
|
-
sysParams,
|
|
241
|
-
psmProcessingConfig,
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
if (res._tag === 'ERROR') {
|
|
245
|
-
throw new Error(res.description);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return res.result;
|
|
249
|
-
},
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
const totalSwapInfo = F.pipe(
|
|
253
|
-
ordersInfo,
|
|
254
|
-
A.reduce<StableswapOrderInfo, StableswapInfo>(
|
|
255
|
-
{
|
|
256
|
-
suppliedCollateralAsset: 0n,
|
|
257
|
-
suppliedIasset: 0n,
|
|
258
|
-
owedCollateralAsset: 0n,
|
|
259
|
-
owedIasset: 0n,
|
|
260
|
-
mintingFee: 0n,
|
|
261
|
-
redemptionFee: 0n,
|
|
262
|
-
},
|
|
263
|
-
(acc, orderInfo) => {
|
|
264
|
-
return {
|
|
265
|
-
suppliedCollateralAsset:
|
|
266
|
-
acc.suppliedCollateralAsset +
|
|
267
|
-
orderInfo.swapInfo.suppliedCollateralAsset,
|
|
268
|
-
suppliedIasset:
|
|
269
|
-
acc.suppliedIasset + orderInfo.swapInfo.suppliedIasset,
|
|
270
|
-
owedCollateralAsset:
|
|
271
|
-
acc.owedCollateralAsset + orderInfo.swapInfo.owedCollateralAsset,
|
|
272
|
-
owedIasset: acc.owedIasset + orderInfo.swapInfo.owedIasset,
|
|
273
|
-
mintingFee: acc.mintingFee + orderInfo.swapInfo.mintingFee,
|
|
274
|
-
redemptionFee: acc.redemptionFee + orderInfo.swapInfo.redemptionFee,
|
|
275
|
-
} satisfies StableswapInfo;
|
|
276
|
-
},
|
|
277
|
-
),
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
const collateralAmtChangePool =
|
|
281
|
-
totalSwapInfo.suppliedCollateralAsset - totalSwapInfo.owedCollateralAsset;
|
|
282
|
-
|
|
283
|
-
const newPsmPoolValue = addAssets(
|
|
284
|
-
stableswapPoolUtxo.assets,
|
|
285
|
-
mkAssetsOf(collateralAc, collateralAmtChangePool),
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
if (assetClassValueOf(newPsmPoolValue, collateralAc) < 0n) {
|
|
289
|
-
throw new Error('Cannot batch more than liquidity allows');
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
const amountToMint =
|
|
293
|
-
totalSwapInfo.owedIasset -
|
|
294
|
-
totalSwapInfo.suppliedIasset +
|
|
295
|
-
totalSwapInfo.mintingFee;
|
|
296
|
-
|
|
297
|
-
const fee = totalSwapInfo.mintingFee + totalSwapInfo.redemptionFee;
|
|
298
|
-
|
|
299
|
-
const tx = lucid
|
|
300
|
-
.newTx()
|
|
301
|
-
.readFrom([
|
|
302
|
-
stableswapScriptRefUtxo,
|
|
303
|
-
cdpScriptRefUtxo,
|
|
304
|
-
iAssetTokenPolicyRefScriptUtxo,
|
|
305
|
-
])
|
|
306
|
-
.collectFrom([stableswapPoolUtxo], {
|
|
307
|
-
kind: 'selected',
|
|
308
|
-
makeRedeemer: (inputIndices) =>
|
|
309
|
-
serialiseCdpRedeemer({
|
|
310
|
-
Stableswap: {
|
|
311
|
-
forwardingInputIndex: inputIndices[0],
|
|
312
|
-
},
|
|
313
|
-
}),
|
|
314
|
-
inputs: [mainOrderUtxo],
|
|
315
|
-
})
|
|
316
|
-
.pay.ToContract(
|
|
317
|
-
stableswapPoolUtxo.address,
|
|
318
|
-
{
|
|
319
|
-
kind: 'inline',
|
|
320
|
-
value: serialiseStableswapPoolDatum(stableswapPoolDatum),
|
|
321
|
-
},
|
|
322
|
-
newPsmPoolValue,
|
|
323
|
-
)
|
|
324
|
-
// This has to be added as otherwise there is the following error:
|
|
325
|
-
// TxBuilderError: { Complete: RedeemerBuilder: Coin selection had to be updated
|
|
326
|
-
// after building redeemers, possibly leading to incorrect indices. Try setting
|
|
327
|
-
// a minimum fee of 1761019 lovelaces. }
|
|
328
|
-
// Trying to set it as low as possible to reduce costs.
|
|
329
|
-
.setMinFee(stableswapOrderOrefs.length > 1 ? 1_498_875n : 1_030_000n);
|
|
330
|
-
|
|
331
|
-
if (amountToMint !== 0n) {
|
|
332
|
-
tx.mintAssets(mkAssetsOf(iassetAc, amountToMint), Data.void());
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
F.pipe(
|
|
336
|
-
ordersInfo,
|
|
337
|
-
A.reduce<StableswapOrderInfo, TxBuilder>(tx, (acc, orderInfo) => {
|
|
338
|
-
return acc
|
|
339
|
-
.collectFrom(
|
|
340
|
-
[orderInfo.order.utxo],
|
|
341
|
-
isSameOutRef(orderInfo.order.utxo, mainOrderUtxo)
|
|
342
|
-
? serialiseStableswapOrderRedeemer('BatchProcessStableswapOrders')
|
|
343
|
-
: {
|
|
344
|
-
kind: 'selected',
|
|
345
|
-
makeRedeemer: (inputIndices: bigint[]) => {
|
|
346
|
-
return serialiseStableswapOrderRedeemer({
|
|
347
|
-
BatchAuxiliary: {
|
|
348
|
-
ownInputIndex: inputIndices[0],
|
|
349
|
-
mainOrderInputIndex: inputIndices[1],
|
|
350
|
-
},
|
|
351
|
-
});
|
|
352
|
-
},
|
|
353
|
-
inputs: [orderInfo.order.utxo, mainOrderUtxo],
|
|
354
|
-
},
|
|
355
|
-
)
|
|
356
|
-
.pay.ToAddressWithData(
|
|
357
|
-
addressToBech32(
|
|
358
|
-
orderInfo.order.datum.destination,
|
|
359
|
-
lucid.config().network!,
|
|
360
|
-
),
|
|
361
|
-
{
|
|
362
|
-
kind: 'inline',
|
|
363
|
-
value: createDestinationDatum(
|
|
364
|
-
orderInfo.order.datum.destinationInlineDatum ?? null,
|
|
365
|
-
orderInfo.order.utxo,
|
|
366
|
-
),
|
|
367
|
-
},
|
|
368
|
-
addAssets(
|
|
369
|
-
// NOTICE: Currently, we always take the max execution fee from the order utxo.
|
|
370
|
-
// This can be improved so that we take the actual execution fee.
|
|
371
|
-
mkLovelacesOf(
|
|
372
|
-
lovelacesAmt(orderInfo.order.utxo.assets) -
|
|
373
|
-
orderInfo.order.datum.maxExecutionFee,
|
|
374
|
-
),
|
|
375
|
-
orderInfo.orderType === 'MINTING'
|
|
376
|
-
? mkAssetsOf(iassetAc, orderInfo.swapInfo.owedIasset)
|
|
377
|
-
: mkAssetsOf(
|
|
378
|
-
collateralAc,
|
|
379
|
-
orderInfo.swapInfo.owedCollateralAsset,
|
|
380
|
-
),
|
|
381
|
-
),
|
|
382
|
-
);
|
|
383
|
-
}),
|
|
384
|
-
);
|
|
385
|
-
if (fee > 0) {
|
|
386
|
-
await treasuryFeeTx(
|
|
387
|
-
iassetAc,
|
|
388
|
-
fee,
|
|
389
|
-
0n,
|
|
390
|
-
lucid,
|
|
391
|
-
sysParams,
|
|
392
|
-
tx,
|
|
393
|
-
stableswapPoolOref,
|
|
394
|
-
treasuryOref,
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
return tx;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
export async function updateStableswapPoolFees(
|
|
401
|
-
stableswapPoolOutRef: OutRef,
|
|
402
|
-
stableswapFeeOutRef: OutRef,
|
|
403
|
-
newMintingFeeRatio: Rational | null,
|
|
404
|
-
newRedemptionFeeRatio: Rational | null,
|
|
405
|
-
sysParams: SystemParams,
|
|
406
|
-
lucid: LucidEvolution,
|
|
407
|
-
): Promise<TxBuilder> {
|
|
408
|
-
const stableswapScriptRefUtxo = matchSingle(
|
|
409
|
-
await lucid.utxosByOutRef([
|
|
410
|
-
fromSystemParamsScriptRef(
|
|
411
|
-
sysParams.scriptReferences.stableswapValidatorRef,
|
|
412
|
-
),
|
|
413
|
-
]),
|
|
414
|
-
(_) => new Error('Expected a single Stableswap Ref Script UTXO'),
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
const cdpScriptRefUtxo = matchSingle(
|
|
418
|
-
await lucid.utxosByOutRef([
|
|
419
|
-
fromSystemParamsScriptRef(sysParams.scriptReferences.cdpValidatorRef),
|
|
420
|
-
]),
|
|
421
|
-
(_) => new Error('Expected a single CDP Ref Script UTXO'),
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
const stableswapPool = matchSingle(
|
|
425
|
-
await lucid.utxosByOutRef([stableswapPoolOutRef]),
|
|
426
|
-
(_) => new Error('Expected a single Stableswap Pool UTXO.'),
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
const stableswapFeeUtxo = matchSingle(
|
|
430
|
-
await lucid.utxosByOutRef([stableswapFeeOutRef]),
|
|
431
|
-
(_) => new Error('Expected a single Stableswap Fee UTXO.'),
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
const stableswapPoolDatum = parseStableswapPoolDatumOrThrow(
|
|
435
|
-
getInlineDatumOrThrow(stableswapPool),
|
|
436
|
-
);
|
|
437
|
-
const newStableswapPoolDatum = {
|
|
438
|
-
...stableswapPoolDatum,
|
|
439
|
-
mintingFeeRatio: newMintingFeeRatio ?? stableswapPoolDatum.mintingFeeRatio,
|
|
440
|
-
redemptionFeeRatio:
|
|
441
|
-
newRedemptionFeeRatio ?? stableswapPoolDatum.redemptionFeeRatio,
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
if (!stableswapPoolDatum.feeManager) {
|
|
445
|
-
throw new Error('Stableswap pool fee manager is not set');
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
return lucid
|
|
449
|
-
.newTx()
|
|
450
|
-
.readFrom([stableswapScriptRefUtxo, cdpScriptRefUtxo])
|
|
451
|
-
.collectFrom([stableswapPool], {
|
|
452
|
-
kind: 'selected',
|
|
453
|
-
makeRedeemer: (inputIndices) =>
|
|
454
|
-
serialiseCdpRedeemer({
|
|
455
|
-
Stableswap: {
|
|
456
|
-
forwardingInputIndex: inputIndices[0],
|
|
457
|
-
},
|
|
458
|
-
}),
|
|
459
|
-
inputs: [stableswapFeeUtxo],
|
|
460
|
-
})
|
|
461
|
-
.collectFrom(
|
|
462
|
-
[stableswapFeeUtxo],
|
|
463
|
-
serialiseStableswapOrderRedeemer('UpdateFees'),
|
|
464
|
-
)
|
|
465
|
-
.pay.ToContract(
|
|
466
|
-
stableswapPool.address,
|
|
467
|
-
{
|
|
468
|
-
kind: 'inline',
|
|
469
|
-
value: serialiseStableswapPoolDatum(newStableswapPoolDatum),
|
|
470
|
-
},
|
|
471
|
-
stableswapPool.assets,
|
|
472
|
-
)
|
|
473
|
-
.addSignerKey(toHex(stableswapPoolDatum.feeManager))
|
|
474
|
-
.setMinFee(1038402n);
|
|
475
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AddressSchema,
|
|
3
|
-
AssetClassSchema,
|
|
4
|
-
OutputReferenceSchema,
|
|
5
|
-
} from '@3rd-eye-labs/cardano-offchain-common';
|
|
6
|
-
import { TSchema, Data } from '@evolution-sdk/evolution';
|
|
7
|
-
import { DEFAULT_SCHEMA_OPTIONS } from '../../types/evolution-schema-options';
|
|
8
|
-
import { option as O, function as F } from 'fp-ts';
|
|
9
|
-
import { Schema } from 'effect';
|
|
10
|
-
import { RationalSchema } from '../../types/rational';
|
|
11
|
-
|
|
12
|
-
const OpaqueData = Schema.typeSchema(Data.DataSchema);
|
|
13
|
-
|
|
14
|
-
export const StableswapOrderDatumSchema = TSchema.Struct({
|
|
15
|
-
iasset: TSchema.ByteArray,
|
|
16
|
-
collateralAsset: AssetClassSchema,
|
|
17
|
-
owner: TSchema.ByteArray,
|
|
18
|
-
destination: AddressSchema,
|
|
19
|
-
destinationInlineDatum: TSchema.NullOr(OpaqueData),
|
|
20
|
-
maxExecutionFee: TSchema.Integer,
|
|
21
|
-
maxFeeRatio: RationalSchema,
|
|
22
|
-
});
|
|
23
|
-
export type StableswapOrderDatum = typeof StableswapOrderDatumSchema.Type;
|
|
24
|
-
|
|
25
|
-
const StableswapOrderRedeemerSchema = TSchema.Union(
|
|
26
|
-
TSchema.Literal('BatchProcessStableswapOrders', { flatInUnion: true }),
|
|
27
|
-
TSchema.Struct(
|
|
28
|
-
{
|
|
29
|
-
BatchAuxiliary: TSchema.Struct(
|
|
30
|
-
{
|
|
31
|
-
ownInputIndex: TSchema.Integer,
|
|
32
|
-
mainOrderInputIndex: TSchema.Integer,
|
|
33
|
-
},
|
|
34
|
-
{ flatFields: true },
|
|
35
|
-
),
|
|
36
|
-
},
|
|
37
|
-
{ flatInUnion: true },
|
|
38
|
-
),
|
|
39
|
-
TSchema.Literal('CancelStableswapOrder', { flatInUnion: true }),
|
|
40
|
-
TSchema.Literal('UpdateFees', { flatInUnion: true }),
|
|
41
|
-
TSchema.Literal('UpgradeVersion', { flatInUnion: true }),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
export type StableswapOrderRedeemer = typeof StableswapOrderRedeemerSchema.Type;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* This is used when order does not require any specific output datum.
|
|
48
|
-
*/
|
|
49
|
-
const StableswapOutputDatumSchema = TSchema.Tuple([
|
|
50
|
-
TSchema.ByteArray,
|
|
51
|
-
OutputReferenceSchema,
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
export type StableswapOutputDatum = typeof StableswapOutputDatumSchema.Type;
|
|
55
|
-
|
|
56
|
-
export function serialiseStableswapOrderDatum(d: StableswapOrderDatum): string {
|
|
57
|
-
return Data.withSchema(
|
|
58
|
-
StableswapOrderDatumSchema,
|
|
59
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
60
|
-
).toCBORHex(d);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function parseStableswapOrderDatum(
|
|
64
|
-
datum: string,
|
|
65
|
-
): O.Option<StableswapOrderDatum> {
|
|
66
|
-
try {
|
|
67
|
-
return O.some(
|
|
68
|
-
Data.withSchema(
|
|
69
|
-
StableswapOrderDatumSchema,
|
|
70
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
71
|
-
).fromCBORHex(datum),
|
|
72
|
-
);
|
|
73
|
-
} catch (_) {
|
|
74
|
-
return O.none;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function parseStableswapOrderDatumOrThrow(
|
|
79
|
-
datum: string,
|
|
80
|
-
): StableswapOrderDatum {
|
|
81
|
-
return F.pipe(
|
|
82
|
-
parseStableswapOrderDatum(datum),
|
|
83
|
-
O.match(() => {
|
|
84
|
-
throw new Error('Expected a Stableswap Order datum.');
|
|
85
|
-
}, F.identity),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function serialiseStableswapOutputDatum(
|
|
90
|
-
d: StableswapOutputDatum,
|
|
91
|
-
): string {
|
|
92
|
-
return Data.withSchema(
|
|
93
|
-
StableswapOutputDatumSchema,
|
|
94
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
95
|
-
).toCBORHex(d);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function serialiseStableswapOrderRedeemer(
|
|
99
|
-
r: StableswapOrderRedeemer,
|
|
100
|
-
): string {
|
|
101
|
-
return Data.withSchema(
|
|
102
|
-
StableswapOrderRedeemerSchema,
|
|
103
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
104
|
-
).toCBORHex(r);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function parseStableswapOrderRedeemer(
|
|
108
|
-
redeemerCborHex: string,
|
|
109
|
-
): O.Option<StableswapOrderRedeemer> {
|
|
110
|
-
try {
|
|
111
|
-
return O.some(
|
|
112
|
-
Data.withSchema(
|
|
113
|
-
StableswapOrderRedeemerSchema,
|
|
114
|
-
DEFAULT_SCHEMA_OPTIONS,
|
|
115
|
-
).fromCBORHex(redeemerCborHex),
|
|
116
|
-
);
|
|
117
|
-
} catch (_) {
|
|
118
|
-
return O.none;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function parseStableswapOrderRedeemerOrThrow(
|
|
123
|
-
redeemerCborHex: string,
|
|
124
|
-
): StableswapOrderRedeemer {
|
|
125
|
-
return F.pipe(
|
|
126
|
-
parseStableswapOrderRedeemer(redeemerCborHex),
|
|
127
|
-
O.match(() => {
|
|
128
|
-
throw new Error('Expected a Stableswap Order redeemer.');
|
|
129
|
-
}, F.identity),
|
|
130
|
-
);
|
|
131
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Data } from '@lucid-evolution/lucid';
|
|
2
|
-
import { AssetClassSchema } from '../../types/generic';
|
|
3
|
-
|
|
4
|
-
const StableswapParamsSchema = Data.Object({
|
|
5
|
-
iassetSymbol: Data.Bytes(),
|
|
6
|
-
cdpToken: AssetClassSchema,
|
|
7
|
-
versionRecordToken: AssetClassSchema,
|
|
8
|
-
cdpValHash: Data.Bytes(),
|
|
9
|
-
treasuryValHash: Data.Bytes(),
|
|
10
|
-
});
|
|
11
|
-
export type StableswapParams = Data.Static<typeof StableswapParamsSchema>;
|
|
12
|
-
export const StableswapParams =
|
|
13
|
-
StableswapParamsSchema as unknown as StableswapParams;
|
|
14
|
-
|
|
15
|
-
export function castStableswapParams(params: StableswapParams): Data {
|
|
16
|
-
return Data.castTo(params, StableswapParams);
|
|
17
|
-
}
|