@cardano-sdk/input-selection 0.6.0-nightly.1
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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +50 -0
- package/dist/cjs/InputSelectionError.d.ts +12 -0
- package/dist/cjs/InputSelectionError.d.ts.map +1 -0
- package/dist/cjs/InputSelectionError.js +19 -0
- package/dist/cjs/InputSelectionError.js.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/change.d.ts +23 -0
- package/dist/cjs/RoundRobinRandomImprove/change.d.ts.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/change.js +227 -0
- package/dist/cjs/RoundRobinRandomImprove/change.js.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/index.d.ts +7 -0
- package/dist/cjs/RoundRobinRandomImprove/index.d.ts.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/index.js +52 -0
- package/dist/cjs/RoundRobinRandomImprove/index.js.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/roundRobin.d.ts +3 -0
- package/dist/cjs/RoundRobinRandomImprove/roundRobin.d.ts.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/roundRobin.js +65 -0
- package/dist/cjs/RoundRobinRandomImprove/roundRobin.js.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/util.d.ts +34 -0
- package/dist/cjs/RoundRobinRandomImprove/util.d.ts.map +1 -0
- package/dist/cjs/RoundRobinRandomImprove/util.js +76 -0
- package/dist/cjs/RoundRobinRandomImprove/util.js.map +1 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/selectionConstraints.d.ts +14 -0
- package/dist/cjs/selectionConstraints.d.ts.map +1 -0
- package/dist/cjs/selectionConstraints.js +43 -0
- package/dist/cjs/selectionConstraints.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/cjs/types.d.ts +40 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/InputSelectionError.d.ts +12 -0
- package/dist/esm/InputSelectionError.d.ts.map +1 -0
- package/dist/esm/InputSelectionError.js +15 -0
- package/dist/esm/InputSelectionError.js.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/change.d.ts +23 -0
- package/dist/esm/RoundRobinRandomImprove/change.d.ts.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/change.js +220 -0
- package/dist/esm/RoundRobinRandomImprove/change.js.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/index.d.ts +7 -0
- package/dist/esm/RoundRobinRandomImprove/index.d.ts.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/index.js +48 -0
- package/dist/esm/RoundRobinRandomImprove/index.js.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/roundRobin.d.ts +3 -0
- package/dist/esm/RoundRobinRandomImprove/roundRobin.d.ts.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/roundRobin.js +61 -0
- package/dist/esm/RoundRobinRandomImprove/roundRobin.js.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/util.d.ts +34 -0
- package/dist/esm/RoundRobinRandomImprove/util.d.ts.map +1 -0
- package/dist/esm/RoundRobinRandomImprove/util.js +63 -0
- package/dist/esm/RoundRobinRandomImprove/util.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/selectionConstraints.d.ts +14 -0
- package/dist/esm/selectionConstraints.d.ts.map +1 -0
- package/dist/esm/selectionConstraints.js +35 -0
- package/dist/esm/selectionConstraints.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/types.d.ts +40 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright © 2021 IOHK
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2021 IOHK
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License”). You may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.txt
|
|
4
|
+
|
|
5
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Cardano JS SDK | Input Selection | CIP-0002
|
|
2
|
+
|
|
3
|
+
This package implements concepts from the draft specification being developed in [CIP-0002].
|
|
4
|
+
|
|
5
|
+
Currently, there is only 1 input selection algorithm: RoundRobinRandomImprove, which is an [Random-Improve] adaptation that handles asset selection.
|
|
6
|
+
|
|
7
|
+
## Usage Example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { roundRobinRandomImprove, defaultSelectionConstraints, InputSelector, SelectionResult, SelectionSkeleton } from '@cardano-sdk/input-selection';
|
|
11
|
+
import { loadCardanoSerializationLib, CSL, CardanoSerializationLib, ProtocolParametersRequiredByWallet } from '@cardano-sdk/core';
|
|
12
|
+
|
|
13
|
+
const demo = async (protocolParameters: ProtocolParametersRequiredByWallet): Promise<SelectionResult> => {
|
|
14
|
+
const csl: CardanoSerializationLib = await loadCardanoSerializationLib();
|
|
15
|
+
const selector: InputSelector = roundRobinRandomImprove(coinsPerUtxoWord);
|
|
16
|
+
// It is important that you use the same instance of cardano-serialization-lib across your application.
|
|
17
|
+
// Bad: TransactionUnspentOutput.new(...)
|
|
18
|
+
// Good: CSL.TransactionUnspentOutput.new(...)
|
|
19
|
+
const utxo: CSL.TransactionUnspentOutput[] = [CSL.TransactionUnspentOutput.new(...), ...];
|
|
20
|
+
const outputs: CSL.TransactionOutput[] = [CSL.TransactionOutput.new(...), ...];
|
|
21
|
+
// Used to estimate min fee and validate transaction size
|
|
22
|
+
const buildTx = (inputSelection: SelectionSkeleton): Promise<CSL.Transaction> => {...};
|
|
23
|
+
const constraints = defaultSelectionConstraints({
|
|
24
|
+
protocolParameters, buildTx,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return selector.select({
|
|
28
|
+
utxo,
|
|
29
|
+
outputs,
|
|
30
|
+
constraints,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Tests
|
|
36
|
+
|
|
37
|
+
Input selection is tested with property-based tests using [fast-check], as well as a few regular example-based tests.
|
|
38
|
+
|
|
39
|
+
Due to nature of property-based tests, code coverage report is slightly different on each build.
|
|
40
|
+
|
|
41
|
+
RoundRobinRandomImprove has 100% code coverage when using high `numRuns` option (e.g. 100_000).
|
|
42
|
+
|
|
43
|
+
Note that to run it with high `numRuns` you need to increase _Jest_ and _fast-check_ timeout.
|
|
44
|
+
|
|
45
|
+
See [code coverage report].
|
|
46
|
+
|
|
47
|
+
[cip-0002]: https://cips.cardano.org/cips/cip2/
|
|
48
|
+
[random-improve]: https://cips.cardano.org/cips/cip2/#randomimprove
|
|
49
|
+
[fast-check]: https://github.com/dubzzz/fast-check
|
|
50
|
+
[code coverage report]: https://input-output-hk.github.io/cardano-js-sdk/coverage/cip2
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomError } from 'ts-custom-error';
|
|
2
|
+
export declare enum InputSelectionFailure {
|
|
3
|
+
UtxoBalanceInsufficient = "UTxO Balance Insufficient",
|
|
4
|
+
UtxoNotFragmentedEnough = "UTxO Not Fragmented Enough",
|
|
5
|
+
UtxoFullyDepleted = "UTxO Fully Depleted",
|
|
6
|
+
MaximumInputCountExceeded = "Maximum Input Count Exceeded"
|
|
7
|
+
}
|
|
8
|
+
export declare class InputSelectionError extends CustomError {
|
|
9
|
+
failure: InputSelectionFailure;
|
|
10
|
+
constructor(failure: InputSelectionFailure);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=InputSelectionError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputSelectionError.d.ts","sourceRoot":"","sources":["../../src/InputSelectionError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,oBAAY,qBAAqB;IAK/B,uBAAuB,8BAA8B;IAKrD,uBAAuB,+BAA+B;IAQtD,iBAAiB,wBAAwB;IAMzC,yBAAyB,iCAAiC;CAC3D;AAED,qBAAa,mBAAoB,SAAQ,WAAW;IACxB,OAAO,EAAE,qBAAqB;gBAA9B,OAAO,EAAE,qBAAqB;CAGzD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InputSelectionError = exports.InputSelectionFailure = void 0;
|
|
4
|
+
const ts_custom_error_1 = require("ts-custom-error");
|
|
5
|
+
var InputSelectionFailure;
|
|
6
|
+
(function (InputSelectionFailure) {
|
|
7
|
+
InputSelectionFailure["UtxoBalanceInsufficient"] = "UTxO Balance Insufficient";
|
|
8
|
+
InputSelectionFailure["UtxoNotFragmentedEnough"] = "UTxO Not Fragmented Enough";
|
|
9
|
+
InputSelectionFailure["UtxoFullyDepleted"] = "UTxO Fully Depleted";
|
|
10
|
+
InputSelectionFailure["MaximumInputCountExceeded"] = "Maximum Input Count Exceeded";
|
|
11
|
+
})(InputSelectionFailure = exports.InputSelectionFailure || (exports.InputSelectionFailure = {}));
|
|
12
|
+
class InputSelectionError extends ts_custom_error_1.CustomError {
|
|
13
|
+
constructor(failure) {
|
|
14
|
+
super(failure);
|
|
15
|
+
this.failure = failure;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.InputSelectionError = InputSelectionError;
|
|
19
|
+
//# sourceMappingURL=InputSelectionError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputSelectionError.js","sourceRoot":"","sources":["../../src/InputSelectionError.ts"],"names":[],"mappings":";;;AAAA,qDAA8C;AAE9C,IAAY,qBAyBX;AAzBD,WAAY,qBAAqB;IAK/B,8EAAqD,CAAA;IAKrD,+EAAsD,CAAA;IAQtD,kEAAyC,CAAA;IAMzC,mFAA0D,CAAA;AAC5D,CAAC,EAzBW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAyBhC;AAED,MAAa,mBAAoB,SAAQ,6BAAW;IAClD,YAA0B,OAA8B;QACtD,KAAK,CAAC,OAAO,CAAC,CAAC;QADS,YAAO,GAAP,OAAO,CAAuB;IAExD,CAAC;CACF;AAJD,kDAIC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Cardano } from '@cardano-sdk/core';
|
|
2
|
+
import { ComputeMinimumCoinQuantity, TokenBundleSizeExceedsLimit } from '../types';
|
|
3
|
+
import { RequiredImplicitValue, UtxoSelection } from './util';
|
|
4
|
+
declare type EstimateTxFeeWithOriginalOutputs = (utxo: Cardano.Utxo[], change: Cardano.Value[]) => Promise<Cardano.Lovelace>;
|
|
5
|
+
interface ChangeComputationArgs {
|
|
6
|
+
utxoSelection: UtxoSelection;
|
|
7
|
+
outputValues: Cardano.Value[];
|
|
8
|
+
uniqueTxAssetIDs: Cardano.AssetId[];
|
|
9
|
+
implicitValue: RequiredImplicitValue;
|
|
10
|
+
estimateTxFee: EstimateTxFeeWithOriginalOutputs;
|
|
11
|
+
computeMinimumCoinQuantity: ComputeMinimumCoinQuantity;
|
|
12
|
+
tokenBundleSizeExceedsLimit: TokenBundleSizeExceedsLimit;
|
|
13
|
+
random: typeof Math.random;
|
|
14
|
+
}
|
|
15
|
+
interface ChangeComputationResult {
|
|
16
|
+
remainingUTxO: Cardano.Utxo[];
|
|
17
|
+
inputs: Cardano.Utxo[];
|
|
18
|
+
change: Cardano.Value[];
|
|
19
|
+
fee: Cardano.Lovelace;
|
|
20
|
+
}
|
|
21
|
+
export declare const computeChangeAndAdjustForFee: ({ computeMinimumCoinQuantity, tokenBundleSizeExceedsLimit, estimateTxFee, outputValues, uniqueTxAssetIDs, implicitValue, random, utxoSelection }: ChangeComputationArgs) => Promise<ChangeComputationResult>;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=change.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change.d.ts","sourceRoot":"","sources":["../../../src/RoundRobinRandomImprove/change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA2B,MAAM,mBAAmB,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEnF,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAoD,MAAM,QAAQ,CAAC;AAKhH,aAAK,gCAAgC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAErH,UAAU,qBAAqB;IAC7B,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IAC9B,gBAAgB,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;IACpC,aAAa,EAAE,qBAAqB,CAAC;IACrC,aAAa,EAAE,gCAAgC,CAAC;IAChD,0BAA0B,EAAE,0BAA0B,CAAC;IACvD,2BAA2B,EAAE,2BAA2B,CAAC;IACzD,MAAM,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC;CAC5B;AAED,UAAU,uBAAuB;IAC/B,aAAa,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC;CACvB;AA0RD,eAAO,MAAM,4BAA4B,qJAStC,qBAAqB,KAAG,QAAQ,uBAAuB,CAuEzD,CAAC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.computeChangeAndAdjustForFee = void 0;
|
|
7
|
+
const core_1 = require("@cardano-sdk/core");
|
|
8
|
+
const InputSelectionError_1 = require("../InputSelectionError");
|
|
9
|
+
const util_1 = require("./util");
|
|
10
|
+
const minBy_1 = __importDefault(require("lodash/minBy"));
|
|
11
|
+
const orderBy_1 = __importDefault(require("lodash/orderBy"));
|
|
12
|
+
const pick_1 = __importDefault(require("lodash/pick"));
|
|
13
|
+
const getLeftoverAssets = (utxoSelected, uniqueTxAssetIDs) => {
|
|
14
|
+
const leftovers = new Map();
|
|
15
|
+
for (const [_, { value: { assets } }] of utxoSelected) {
|
|
16
|
+
if (assets) {
|
|
17
|
+
const leftoverAssetKeys = [...assets.keys()].filter((id) => !uniqueTxAssetIDs.includes(id));
|
|
18
|
+
for (const assetKey of leftoverAssetKeys) {
|
|
19
|
+
const quantity = assets.get(assetKey);
|
|
20
|
+
if (quantity === 0n)
|
|
21
|
+
continue;
|
|
22
|
+
const assetLeftovers = leftovers.get(assetKey) || [];
|
|
23
|
+
leftovers.set(assetKey, [...assetLeftovers, quantity]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return leftovers;
|
|
28
|
+
};
|
|
29
|
+
const redistributeLeftoverAssets = (utxoSelected, requestedAssetChangeBundles, uniqueTxAssetIDs) => {
|
|
30
|
+
const leftovers = getLeftoverAssets(utxoSelected, uniqueTxAssetIDs);
|
|
31
|
+
const resultBundles = [...requestedAssetChangeBundles];
|
|
32
|
+
for (const assetId of leftovers.keys()) {
|
|
33
|
+
const quantities = (0, orderBy_1.default)(leftovers.get(assetId), (q) => q, 'desc');
|
|
34
|
+
if (resultBundles.length === 0) {
|
|
35
|
+
resultBundles.push({ coins: 0n });
|
|
36
|
+
}
|
|
37
|
+
while (quantities.length > resultBundles.length) {
|
|
38
|
+
const smallestQuantity = quantities.pop();
|
|
39
|
+
quantities[quantities.length - 1] += smallestQuantity;
|
|
40
|
+
}
|
|
41
|
+
for (const [idx, quantity] of quantities.entries()) {
|
|
42
|
+
const originalBundle = resultBundles[idx];
|
|
43
|
+
const originalBundleAssets = originalBundle.assets?.entries() || [];
|
|
44
|
+
resultBundles.splice(idx, 1, {
|
|
45
|
+
assets: new Map([...originalBundleAssets, [assetId, quantity]]),
|
|
46
|
+
coins: originalBundle.coins
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return resultBundles;
|
|
51
|
+
};
|
|
52
|
+
const createBundlePerOutput = (outputValues, coinTotalRequested, coinChangeTotal, assetTotals) => {
|
|
53
|
+
let totalCoinBundled = 0n;
|
|
54
|
+
const totalAssetsBundled = new Map();
|
|
55
|
+
const bundles = outputValues.map((value) => {
|
|
56
|
+
const coins = coinTotalRequested > 0n ? (coinChangeTotal * value.coins) / coinTotalRequested : 0n;
|
|
57
|
+
totalCoinBundled += coins;
|
|
58
|
+
if (!value.assets) {
|
|
59
|
+
return { coins };
|
|
60
|
+
}
|
|
61
|
+
const assets = new Map();
|
|
62
|
+
for (const [assetId, outputAmount] of value.assets.entries()) {
|
|
63
|
+
const { selected, requested } = assetTotals.get(assetId);
|
|
64
|
+
const assetChangeTotal = selected - requested;
|
|
65
|
+
const assetChange = (assetChangeTotal * outputAmount) / selected;
|
|
66
|
+
totalAssetsBundled.set(assetId, (totalAssetsBundled.get(assetId) || 0n) + assetChange);
|
|
67
|
+
assets.set(assetId, assetChange);
|
|
68
|
+
}
|
|
69
|
+
return { assets, coins };
|
|
70
|
+
});
|
|
71
|
+
return { bundles, totalAssetsBundled, totalCoinBundled };
|
|
72
|
+
};
|
|
73
|
+
const smallestBundleTokenMap = (bundles) => {
|
|
74
|
+
if (bundles.length === 0) {
|
|
75
|
+
const bundle = { assets: new Map(), coins: 0n };
|
|
76
|
+
bundles.push(bundle);
|
|
77
|
+
return bundle.assets;
|
|
78
|
+
}
|
|
79
|
+
const bundle = (0, minBy_1.default)(bundles, ({ assets }) => assets?.size || 0);
|
|
80
|
+
if (!bundle.assets)
|
|
81
|
+
bundle.assets = new Map();
|
|
82
|
+
return bundle.assets;
|
|
83
|
+
};
|
|
84
|
+
const computeRequestedAssetChangeBundles = (utxoSelected, outputValues, uniqueTxAssetIDs, { implicitCoin, implicitTokens }, fee) => {
|
|
85
|
+
const assetTotals = new Map();
|
|
86
|
+
const utxoSelectedValues = (0, util_1.toValues)(utxoSelected);
|
|
87
|
+
for (const assetId of uniqueTxAssetIDs) {
|
|
88
|
+
assetTotals.set(assetId, {
|
|
89
|
+
requested: (0, util_1.assetQuantitySelector)(assetId)(outputValues) + implicitTokens.spend(assetId),
|
|
90
|
+
selected: (0, util_1.assetQuantitySelector)(assetId)(utxoSelectedValues) + implicitTokens.input(assetId)
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const coinTotalSelected = (0, util_1.getCoinQuantity)(utxoSelectedValues) + implicitCoin.input;
|
|
94
|
+
const coinTotalRequested = (0, util_1.getCoinQuantity)(outputValues) + fee + implicitCoin.deposit;
|
|
95
|
+
const coinChangeTotal = coinTotalSelected - coinTotalRequested;
|
|
96
|
+
const { totalCoinBundled, bundles, totalAssetsBundled } = createBundlePerOutput(outputValues, coinTotalRequested, coinChangeTotal, assetTotals);
|
|
97
|
+
const coinLost = coinChangeTotal - totalCoinBundled;
|
|
98
|
+
if (coinLost > 0) {
|
|
99
|
+
if (bundles.length === 0) {
|
|
100
|
+
bundles.push({ coins: coinLost });
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
bundles[0].coins += coinLost;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const assetId of uniqueTxAssetIDs) {
|
|
107
|
+
const assetTotal = assetTotals.get(assetId);
|
|
108
|
+
const bundled = totalAssetsBundled.get(assetId) || 0n;
|
|
109
|
+
const assetLost = assetTotal.selected - assetTotal.requested - bundled;
|
|
110
|
+
if (assetLost > 0n) {
|
|
111
|
+
const anyChangeTokenBundle = bundles.find(({ assets }) => assets?.has(assetId))?.assets || smallestBundleTokenMap(bundles);
|
|
112
|
+
const assetQuantityAlreadyInBundle = anyChangeTokenBundle.get(assetId) || 0n;
|
|
113
|
+
anyChangeTokenBundle.set(assetId, assetQuantityAlreadyInBundle + assetLost);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return bundles;
|
|
117
|
+
};
|
|
118
|
+
const pickExtraRandomUtxo = ({ utxoRemaining, utxoSelected }, random) => {
|
|
119
|
+
const remainingUtxoOfOnlyCoin = utxoRemaining.filter(([_, { value }]) => !value.assets);
|
|
120
|
+
const pickFrom = remainingUtxoOfOnlyCoin.length > 0 ? remainingUtxoOfOnlyCoin : utxoRemaining;
|
|
121
|
+
const pickIdx = Math.floor(random() * pickFrom.length);
|
|
122
|
+
const newUtxoSelected = [...utxoSelected, pickFrom[pickIdx]];
|
|
123
|
+
const originalIdx = utxoRemaining.indexOf(pickFrom[pickIdx]);
|
|
124
|
+
const newUtxoRemaining = [...utxoRemaining.slice(0, originalIdx), ...utxoRemaining.slice(originalIdx + 1)];
|
|
125
|
+
return { utxoRemaining: newUtxoRemaining, utxoSelected: newUtxoSelected };
|
|
126
|
+
};
|
|
127
|
+
const coalesceChangeBundlesForMinCoinRequirement = (changeBundles, computeMinimumCoinQuantity) => {
|
|
128
|
+
if (changeBundles.length === 0) {
|
|
129
|
+
return changeBundles;
|
|
130
|
+
}
|
|
131
|
+
const noZeroQuantityAssetChangeBundles = changeBundles.map(({ coins, assets }) => ({
|
|
132
|
+
assets: assets ? new Map([...assets.entries()].filter(([_, quantity]) => quantity > 0n)) : undefined,
|
|
133
|
+
coins
|
|
134
|
+
}));
|
|
135
|
+
let sortedBundles = (0, orderBy_1.default)(noZeroQuantityAssetChangeBundles, ({ coins }) => coins, 'desc');
|
|
136
|
+
const stubMaxSizeAddress = core_1.Cardano.Address('addr_test1qqydn46r6mhge0kfpqmt36m6q43knzsd9ga32n96m89px3nuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475qypp3m9');
|
|
137
|
+
const satisfiesMinCoinRequirement = (value) => {
|
|
138
|
+
const stubTxOut = { address: stubMaxSizeAddress, value };
|
|
139
|
+
return value.coins >= computeMinimumCoinQuantity(stubTxOut);
|
|
140
|
+
};
|
|
141
|
+
while (sortedBundles.length > 1 && !satisfiesMinCoinRequirement(sortedBundles[sortedBundles.length - 1])) {
|
|
142
|
+
const smallestBundle = sortedBundles.pop();
|
|
143
|
+
sortedBundles[sortedBundles.length - 1] = (0, core_1.coalesceValueQuantities)([
|
|
144
|
+
sortedBundles[sortedBundles.length - 1],
|
|
145
|
+
smallestBundle
|
|
146
|
+
]);
|
|
147
|
+
sortedBundles = (0, orderBy_1.default)(sortedBundles, ({ coins }) => coins, 'desc');
|
|
148
|
+
}
|
|
149
|
+
if (!satisfiesMinCoinRequirement(sortedBundles[0])) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
return sortedBundles.filter((bundle) => bundle.coins > 0n || (bundle.assets?.size || 0) > 0);
|
|
153
|
+
};
|
|
154
|
+
const computeChangeBundles = ({ utxoSelection, outputValues, uniqueTxAssetIDs, implicitValue, computeMinimumCoinQuantity, fee = 0n }) => {
|
|
155
|
+
const requestedAssetChangeBundles = computeRequestedAssetChangeBundles(utxoSelection.utxoSelected, outputValues, uniqueTxAssetIDs, implicitValue, fee);
|
|
156
|
+
const requestedAssetChangeBundlesWithLeftoverAssets = redistributeLeftoverAssets(utxoSelection.utxoSelected, requestedAssetChangeBundles, uniqueTxAssetIDs);
|
|
157
|
+
const changeBundles = coalesceChangeBundlesForMinCoinRequirement(requestedAssetChangeBundlesWithLeftoverAssets, computeMinimumCoinQuantity);
|
|
158
|
+
if (!changeBundles) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
return { changeBundles, ...utxoSelection };
|
|
162
|
+
};
|
|
163
|
+
const validateChangeBundles = (changeBundles, tokenBundleSizeExceedsLimit) => {
|
|
164
|
+
for (const { assets } of changeBundles) {
|
|
165
|
+
if (!assets)
|
|
166
|
+
continue;
|
|
167
|
+
if (tokenBundleSizeExceedsLimit(assets)) {
|
|
168
|
+
throw new InputSelectionError_1.InputSelectionError(InputSelectionError_1.InputSelectionFailure.UtxoFullyDepleted);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return changeBundles;
|
|
172
|
+
};
|
|
173
|
+
const computeChangeAndAdjustForFee = async ({ computeMinimumCoinQuantity, tokenBundleSizeExceedsLimit, estimateTxFee, outputValues, uniqueTxAssetIDs, implicitValue, random, utxoSelection }) => {
|
|
174
|
+
const recomputeChangeAndAdjustForFeeWithExtraUtxo = (currentUtxoSelection) => {
|
|
175
|
+
if (currentUtxoSelection.utxoRemaining.length > 0) {
|
|
176
|
+
return (0, exports.computeChangeAndAdjustForFee)({
|
|
177
|
+
computeMinimumCoinQuantity,
|
|
178
|
+
estimateTxFee,
|
|
179
|
+
implicitValue,
|
|
180
|
+
outputValues,
|
|
181
|
+
random,
|
|
182
|
+
tokenBundleSizeExceedsLimit,
|
|
183
|
+
uniqueTxAssetIDs,
|
|
184
|
+
utxoSelection: pickExtraRandomUtxo(currentUtxoSelection, random)
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
throw new InputSelectionError_1.InputSelectionError(InputSelectionError_1.InputSelectionFailure.UtxoFullyDepleted);
|
|
188
|
+
};
|
|
189
|
+
const selectionWithChangeAndFee = computeChangeBundles({
|
|
190
|
+
computeMinimumCoinQuantity,
|
|
191
|
+
implicitValue,
|
|
192
|
+
outputValues,
|
|
193
|
+
uniqueTxAssetIDs,
|
|
194
|
+
utxoSelection
|
|
195
|
+
});
|
|
196
|
+
if (!selectionWithChangeAndFee)
|
|
197
|
+
return recomputeChangeAndAdjustForFeeWithExtraUtxo(utxoSelection);
|
|
198
|
+
const fee = await estimateTxFee(selectionWithChangeAndFee.utxoSelected, validateChangeBundles(selectionWithChangeAndFee.changeBundles, tokenBundleSizeExceedsLimit));
|
|
199
|
+
const totalOutputCoin = (0, util_1.getCoinQuantity)(outputValues) + fee + implicitValue.implicitCoin.deposit;
|
|
200
|
+
const totalInputCoin = (0, util_1.getCoinQuantity)((0, util_1.toValues)(selectionWithChangeAndFee.utxoSelected)) + implicitValue.implicitCoin.input;
|
|
201
|
+
if (totalOutputCoin > totalInputCoin) {
|
|
202
|
+
if (selectionWithChangeAndFee.utxoRemaining.length === 0) {
|
|
203
|
+
throw new InputSelectionError_1.InputSelectionError(InputSelectionError_1.InputSelectionFailure.UtxoBalanceInsufficient);
|
|
204
|
+
}
|
|
205
|
+
return recomputeChangeAndAdjustForFeeWithExtraUtxo(selectionWithChangeAndFee);
|
|
206
|
+
}
|
|
207
|
+
const finalSelection = computeChangeBundles({
|
|
208
|
+
computeMinimumCoinQuantity,
|
|
209
|
+
fee,
|
|
210
|
+
implicitValue,
|
|
211
|
+
outputValues,
|
|
212
|
+
uniqueTxAssetIDs,
|
|
213
|
+
utxoSelection: (0, pick_1.default)(selectionWithChangeAndFee, ['utxoRemaining', 'utxoSelected'])
|
|
214
|
+
});
|
|
215
|
+
if (!finalSelection) {
|
|
216
|
+
return recomputeChangeAndAdjustForFeeWithExtraUtxo(selectionWithChangeAndFee);
|
|
217
|
+
}
|
|
218
|
+
const { changeBundles, utxoSelected, utxoRemaining } = finalSelection;
|
|
219
|
+
return {
|
|
220
|
+
change: validateChangeBundles(changeBundles, tokenBundleSizeExceedsLimit),
|
|
221
|
+
fee,
|
|
222
|
+
inputs: utxoSelected,
|
|
223
|
+
remainingUTxO: utxoRemaining
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
exports.computeChangeAndAdjustForFee = computeChangeAndAdjustForFee;
|
|
227
|
+
//# sourceMappingURL=change.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"change.js","sourceRoot":"","sources":["../../../src/RoundRobinRandomImprove/change.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAqE;AAErE,gEAAoF;AACpF,iCAAgH;AAChH,yDAAiC;AACjC,6DAAqC;AACrC,uDAA+B;AAsB/B,MAAM,iBAAiB,GAAG,CAAC,YAA4B,EAAE,gBAAmC,EAAE,EAAE;IAC9F,MAAM,SAAS,GAAwC,IAAI,GAAG,EAAE,CAAC;IACjE,KAAK,MAAM,CACT,CAAC,EACD,EACE,KAAK,EAAE,EAAE,MAAM,EAAE,EAClB,CACF,IAAI,YAAY,EAAE;QACjB,IAAI,MAAM,EAAE;YACV,MAAM,iBAAiB,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5F,KAAK,MAAM,QAAQ,IAAI,iBAAiB,EAAE;gBACxC,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC;gBACvC,IAAI,QAAQ,KAAK,EAAE;oBAA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,CAAC,GAAG,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC;IACvG,IAAI,eAAe,GAAG,cAAc,EAAE;QACpC,IAAI,yBAAyB,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE;YACxD,MAAM,IAAI,yCAAmB,CAAC,2CAAqB,CAAC,uBAAuB,CAAC,CAAC;SAC9E;QAED,OAAO,2CAA2C,CAAC,yBAAyB,CAAC,CAAC;KAC/E;IAED,MAAM,cAAc,GAAG,oBAAoB,CAAC;QAC1C,0BAA0B;QAC1B,GAAG;QACH,aAAa;QACb,YAAY;QACZ,gBAAgB;QAChB,aAAa,EAAE,IAAA,cAAI,EAAC,yBAAyB,EAAE,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;KAClF,CAAC,CAAC;IAEH,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,2CAA2C,CAAC,yBAAyB,CAAC,CAAC;KAC/E;IAED,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,cAAc,CAAC;IAEtE,OAAO;QACL,MAAM,EAAE,qBAAqB,CAAC,aAAa,EAAE,2BAA2B,CAAC;QACzE,GAAG;QACH,MAAM,EAAE,YAAY;QACpB,aAAa,EAAE,aAAa;KAC7B,CAAC;AACJ,CAAC,CAAC;AAhFW,QAAA,4BAA4B,gCAgFvC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InputSelector } from '../types';
|
|
2
|
+
interface RoundRobinRandomImproveOptions {
|
|
3
|
+
random?: typeof Math.random;
|
|
4
|
+
}
|
|
5
|
+
export declare const roundRobinRandomImprove: ({ random }?: RoundRobinRandomImproveOptions) => InputSelector;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/RoundRobinRandomImprove/index.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,aAAa,EAAmB,MAAM,UAAU,CAAC;AAMpF,UAAU,8BAA8B;IACtC,MAAM,CAAC,EAAE,OAAO,IAAI,CAAC,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,uBAAuB,gBAEjC,8BAA8B,KAAQ,aAqDvC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.roundRobinRandomImprove = void 0;
|
|
4
|
+
const InputSelectionError_1 = require("../InputSelectionError");
|
|
5
|
+
const util_1 = require("./util");
|
|
6
|
+
const change_1 = require("./change");
|
|
7
|
+
const core_1 = require("@cardano-sdk/core");
|
|
8
|
+
const roundRobin_1 = require("./roundRobin");
|
|
9
|
+
const roundRobinRandomImprove = ({ random = Math.random } = {}) => ({
|
|
10
|
+
select: async ({ utxo: utxoSet, outputs: outputSet, constraints: { computeMinimumCost, computeSelectionLimit, computeMinimumCoinQuantity, tokenBundleSizeExceedsLimit }, implicitValue: partialImplicitValue = {} }) => {
|
|
11
|
+
const { utxo, outputs, uniqueTxAssetIDs, implicitValue } = (0, util_1.preProcessArgs)(utxoSet, outputSet, partialImplicitValue);
|
|
12
|
+
(0, util_1.assertIsBalanceSufficient)(uniqueTxAssetIDs, utxo, outputs, implicitValue);
|
|
13
|
+
const roundRobinSelectionResult = (0, roundRobin_1.roundRobinSelection)({
|
|
14
|
+
implicitValue,
|
|
15
|
+
outputs,
|
|
16
|
+
random,
|
|
17
|
+
uniqueTxAssetIDs,
|
|
18
|
+
utxo
|
|
19
|
+
});
|
|
20
|
+
const result = await (0, change_1.computeChangeAndAdjustForFee)({
|
|
21
|
+
computeMinimumCoinQuantity,
|
|
22
|
+
estimateTxFee: (utxos, changeValues) => computeMinimumCost({
|
|
23
|
+
change: new Set(changeValues),
|
|
24
|
+
fee: core_1.cslUtil.MAX_U64,
|
|
25
|
+
inputs: new Set(utxos),
|
|
26
|
+
outputs: outputSet
|
|
27
|
+
}),
|
|
28
|
+
implicitValue,
|
|
29
|
+
outputValues: (0, util_1.toValues)(outputs),
|
|
30
|
+
random,
|
|
31
|
+
tokenBundleSizeExceedsLimit,
|
|
32
|
+
uniqueTxAssetIDs,
|
|
33
|
+
utxoSelection: roundRobinSelectionResult
|
|
34
|
+
});
|
|
35
|
+
const inputs = new Set(result.inputs);
|
|
36
|
+
const change = new Set(result.change);
|
|
37
|
+
if (result.inputs.length > (await computeSelectionLimit({ change, fee: result.fee, inputs, outputs: outputSet }))) {
|
|
38
|
+
throw new InputSelectionError_1.InputSelectionError(InputSelectionError_1.InputSelectionFailure.MaximumInputCountExceeded);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
remainingUTxO: new Set(result.remainingUTxO),
|
|
42
|
+
selection: {
|
|
43
|
+
change,
|
|
44
|
+
fee: result.fee,
|
|
45
|
+
inputs,
|
|
46
|
+
outputs: outputSet
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
exports.roundRobinRandomImprove = roundRobinRandomImprove;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/RoundRobinRandomImprove/index.ts"],"names":[],"mappings":";;;AAAA,gEAAoF;AAEpF,iCAA6E;AAC7E,qCAAwD;AACxD,4CAA4C;AAC5C,6CAAmD;AAM5C,MAAM,uBAAuB,GAAG,CAAC,EACtC,MAAM,GAAG,IAAI,CAAC,MAAM,KACc,EAAE,EAAiB,EAAE,CAAC,CAAC;IACzD,MAAM,EAAE,KAAK,EAAE,EACb,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,SAAS,EAClB,WAAW,EAAE,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,2BAA2B,EAAE,EACnH,aAAa,EAAE,oBAAoB,GAAG,EAAE,EACf,EAA4B,EAAE;QACvD,MAAM,EAAE,IAAI,EAAE,OA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