Skip to content

Commit 17080e2

Browse files
mkazlauskasrhyslbw
authored andcommitted
feat(cip2): initial implementation of RoundRobinRandomImprove
1 parent 74a9132 commit 17080e2

19 files changed

+1420
-0
lines changed

Diff for: packages/cip2/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
secrets

Diff for: packages/cip2/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Cardano JS SDK | CIP2 | Input Selection
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 a [Random-Improve] adaptation that handles asset selection.
6+
7+
[cip-0002]: https://cips.cardano.org/cips/cip2/
8+
[random-improve]: https://cips.cardano.org/cips/cip2/#randomimprove

Diff for: packages/cip2/package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@cardano-sdk/cip2",
3+
"version": "0.1.0",
4+
"description": "TypeScript definitions for CIP2 (Coin Selection Algorithms for Cardano)",
5+
"engines": {
6+
"node": "^14"
7+
},
8+
"main": "dist/index.js",
9+
"repository": "https://github.com/input-output-hk/cardano-js-sdk/packages/cip2",
10+
"author": "Martynas Kazlauskas <[email protected]>",
11+
"license": "MPL-2.0",
12+
"scripts": {
13+
"build": "tsc --build ./src",
14+
"tscNoEmit": "shx echo typescript --noEmit command not implemented yet",
15+
"cleanup": "shx rm -rf dist node_modules",
16+
"lint": "eslint --ignore-path ../../.eslintignore \"**/*.ts\"",
17+
"test": "jest -c ./test/jest.config.js",
18+
"test:debug": "DEBUG=true yarn test"
19+
},
20+
"devDependencies": {
21+
"@cardano-ogmios/schema": "^4.0.0-beta.6",
22+
"@emurgo/cardano-serialization-lib-nodejs": "^8.0.0",
23+
"@types/lodash-es": "^4.17.5",
24+
"fast-check": "^2.17.0",
25+
"lodash": "^4.17.21",
26+
"shx": "^0.3.3"
27+
},
28+
"dependencies": {
29+
"@cardano-sdk/cardano-serialization-lib": "0.1.0",
30+
"lodash-es": "^4.17.21"
31+
}
32+
}

Diff for: packages/cip2/src/.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
"extends": ["../../../.eslintrc.js"],
3+
"parserOptions": {
4+
"project": "./tsconfig.json",
5+
"tsconfigRootDir": __dirname
6+
}
7+
}

Diff for: packages/cip2/src/InputSelectionError.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { CustomError } from 'ts-custom-error';
2+
3+
export enum InputSelectionFailure {
4+
/**
5+
* Total value of the entries within the initial UTxO set (the amount of money available)
6+
* is less than the the total value of all entries in the requested output set (the amount of money required).
7+
*/
8+
UtxoBalanceInsufficient = 'UTxO Balance Insufficient',
9+
/**
10+
* The number of entries in the initial UTxO set is smaller than the number of entries in the requested output set,
11+
* for algorithms that impose the restriction that a single UTxO entry can only be used to pay for at most one output.
12+
*/
13+
UtxoNotFragmentedEnough = 'UTxO Not Fragmented Enough',
14+
/**
15+
* The algorithm depletes all entries from the initial UTxO set
16+
* before it is able to pay for all outputs in the requested output set.
17+
* This can happen even if the total value of entries within the initial UTxO set
18+
* is greater than the total value of all entries in the requested output set,
19+
* due to various restrictions that coin selection algorithms impose on themselves when selecting UTxO entries.
20+
*/
21+
UtxoFullyDepleted = 'UTxO Fully Depleted',
22+
/**
23+
* Another input must be selected by the algorithm in order to continue making progress,
24+
* but doing so will increase the size of the resulting selection beyond an acceptable limit,
25+
* specified by the maximum input count parameter.
26+
*/
27+
MaximumInputCountExceeded = 'Maximum Input Count Exceeded'
28+
}
29+
30+
export class InputSelectionError extends CustomError {
31+
public constructor(public failure: InputSelectionFailure) {
32+
super(failure);
33+
}
34+
}

0 commit comments

Comments
 (0)