{"_id":"@chargerwallet/cardano-coin-selection","name":"@chargerwallet/cardano-coin-selection","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@chargerwallet/cardano-coin-selection","version":"1.0.0","description":"Minimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for ChargerWallet. Under the hood it leverages Cardano Serialization Lib via WASM module.","keywords":["coin selection"],"license":"MIT","author":{"name":"ChargerWallet"},"homepage":"https://github.com/chargerwallet/coin-selection","repository":{"type":"git","url":"git+https://github.com/chargerwallet/coin-selection.git"},"publishConfig":{"access":"public"},"main":"lib/cjs/index.js","module":"lib/esm/index.js","scripts":{"build":"yarn clean && tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json","clean":"rimraf lib","lint":"eslint ./src/**/*.ts","type-check":"yarn tsc -p tsconfig.types.json","test":"yarn run-s 'test:*'","test:unit":"jest -c ./jest.config.js","test:badges":"make-coverage-badge --output-path ./docs/badge-coverage.svg"},"devDependencies":{"@emurgo/cardano-serialization-lib-nodejs":"11.0.0","@swc-node/jest":"^1.5.2","@types/jest":"^28.1.6","@types/node":"^16.3.2","@typescript-eslint/eslint-plugin":"^5.32.0","@typescript-eslint/parser":"5.32.0","bignumber.js":"^9.0.1","eslint":"8.21.0","eslint-config-prettier":"8.5.0","eslint-plugin-import":"2.26.0","eslint-plugin-prettier":"4.2.1","jest":"^28.1.3","make-coverage-badge":"^1.2.0","npm-run-all":"^4.1.5","prettier":"2.7.1","rimraf":"^3.0.2","typescript":"^4.7.4"},"dependencies":{"@emurgo/cardano-message-signing-browser":"^1.0.1","@emurgo/cardano-serialization-lib-browser":"11.1.0"},"peerDependencies":{"bignumber.js":"^9.0.1"},"packageManager":"yarn@3.2.2","_id":"@chargerwallet/cardano-coin-selection@1.0.0","gitHead":"e412fb961370108756c5618f48ccbffe21798421","types":"./lib/cjs/index.d.ts","bugs":{"url":"https://github.com/chargerwallet/coin-selection/issues"},"_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-VWMHD9gDvB+x6h94xNh29X1BcIlSvkgVGrATMbVQ7MoviOE9GYl2Xbv+Y1KcwmJZ4P6qwqnQVsFdJBjB5+l+uw==","shasum":"a5ccecacde2f566d4417cfe26f9f3b07eefb8342","tarball":"https://registry.npmjs.org/@chargerwallet/cardano-coin-selection/-/cardano-coin-selection-1.0.0.tgz","fileCount":78,"unpackedSize":266094,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDPGvlyWLSHbteEc99Y0QR13OdByv5Jn7g6UD2/p21MTAIgTcpDU+SzFXKLZ7h6mUcjYqXWOWk3sUA4kliSWS0IQcI="}]},"_npmUser":{"name":"lyfeloopinc","email":"dev@chargerwallet.com"},"directories":{},"maintainers":[{"name":"lyfeloopinc","email":"dev@chargerwallet.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cardano-coin-selection_1.0.0_1734463442462_0.3196100214954323"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-17T19:24:02.377Z","1.0.0":"2024-12-17T19:24:02.676Z","modified":"2024-12-17T19:24:03.103Z"},"maintainers":[{"name":"lyfeloopinc","email":"dev@chargerwallet.com"}],"description":"Minimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for ChargerWallet. Under the hood it leverages Cardano Serialization Lib via WASM module.","homepage":"https://github.com/chargerwallet/coin-selection","keywords":["coin selection"],"repository":{"type":"git","url":"git+https://github.com/chargerwallet/coin-selection.git"},"author":{"name":"ChargerWallet"},"bugs":{"url":"https://github.com/chargerwallet/coin-selection/issues"},"license":"MIT","readme":"# coin-selection\n\nMinimal implementation of Cardano coin selection algorithms (see [CIP-2](https://cips.cardano.org/cips/cip2/)) developed solely for ChargerWallet.\nUnder the hood it leverages Cardano Serialization Lib via WASM module.\n\n## Features\n\n- Final tx plan: Compose transaction plan for given inputs (shelley utxos only), certificates (support for stake (de)registration and delegation), withdrawals,...\n- Draft tx plan: Return basic information about potential transaction (such as a size and fee) even for incomplete inputs (without an recipient address or an amount)\n- Set max: Calculate the max amount of an asset that is possible to include in a transaction output\n\n## Usage\n\n```typescript\nconst txPlan = coinSelection(\n\ttxParams: {\n        utxos: Utxo[];\n        outputs: UserOutput[];\n        changeAddress: string;\n        certificates: Certificate[];\n        withdrawals: Withdrawal[];\n        accountPubKey: string;\n        ttl?: number;\n    },\n\toptions: {\n        feeParams?: { a: string };\n        debug?: boolean;\n        forceLargestFirstSelection?: boolean;\n\t}\n);\n```\n\n### `coinSelection(txParams, options)`\n\n#### `txParams`\n\n- `utxos`: Array of account's utxo\n- `outputs`: Requested outputs provided by an user\n- `changeAddress`: An address where the change will be sent\n- `certificates`: Stake registration and/or delegation certificates (stake pool registration is not supported)\n- `withdrawals`: Withdrawal requests\n- `accountPubKey`: Account public key\n- `ttl`: Time-to-live for the transaction\n\n#### `Options`\n\n- `forceLargestFirstSelection`: Always use largest-first algorithm\n- `debug`: print debug information about coin-selection (selected utxos, outputs including change output,...)\n\n## Example\n\n### Final tx plan\n\n```typescript\n\nexport const utxo1 = {\n  address:\n    'addr1q860vxljhadqxnrrsr2j6yxnwpdkyquq74lmghx502aj0r28d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90sp0878u',\n  txHash: '3c388acb799a37a4f1cc99bec7626637b0b80626b9ef7c7a687282cab701178d',\n  outputIndex: 0,\n  amount: [\n    {\n      quantity: '5000000',\n      unit: 'lovelace',\n    },\n  ],\n};\n\nexport const utxo2 = {\n  address:\n    'addr1q860vxljhadqxnrrsr2j6yxnwpdkyquq74lmghx502aj0r28d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90sp0878u',\n  txHash: '9e63fddf20cb7b5472e2c9a1bb4bbe3112b8f2b22e45bc441206bcddde5c58a0',\n  outputIndex: 1,\n  amount: [\n    {\n      quantity: '5000000',\n      unit: 'lovelace',\n    },\n    {\n      quantity: '1000',\n      unit: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a47524943',\n    },\n  ],\n};\n\nconst txPlan = coinSelection(\n\ttxParams: {\n        utxos: Utxo[];\n        outputs: [\n        {\n            address:\n            'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n            amount: '1000000',\n            assets: [],\n            setMax: false,\n        },\n        {\n            address:\n            'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n            amount: undefined,\n            assets: [],\n            setMax: true,\n        },\n        ],\n        changeAddress: `addr1q8u2f05rprqjhygz22m06mhy4xrnqvqqpyuzhmxqfxnwvxz8d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90s22tk0f`,\n        certificates: [],\n        withdrawals: [],\n        accountPubKey:\n        'ec8fdf616242f430855ad7477acda53395eb30c295f5a7ef038712578877375b5a2f00353c9c5cc88c7ff18e71dc08724d90fc238213b789c0b02438e336be07',\n    },\n);\n\n// txPlan\n// {\n//   max: '7480901',\n//   totalSpent: '8655202',\n//   fee: '174301',\n//   inputs: [utxo1, utxo2],\n//   outputs: [\n//     {\n//       address:\n//         'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n//       amount: '1000000',\n//       assets: [],\n//       setMax: false,\n//     },\n//     {\n//       address:\n//         'addr1qya0nkzrf04gmcpu66vdt7sudwptnyg5df6475y7jhtt2wc44vzmgrfy6wwf69xlaszdslksw8evveyykw4c82eavq7sx29tlc',\n//       amount: '7480901',\n//       assets: [],\n//       setMax: true,\n//     },\n//     {\n//       isChange: true,\n//       address: changeAddress,\n//       amount: '1344798',\n//       assets: [\n//         {\n//           quantity: '1000',\n//           unit: '02477d7c23b4c2834b0be8ca8578dde47af0cc82a964688f6fc95a7a47524943',\n//         },\n//       ],\n//     },\n//   ],\n// },\n;\n```\n\n### Draft tx plan\n\n```typescript\n\nconst txPlan = coinSelection(\n\t{\n        utxos: [utxo1];\n        outputs: [\n            {\n                address: undefined, // address not filled\n                amount: '2000000',\n                assets: [],\n                setMax: false,\n            },\n        ],\n        changeAddress: `addr1q8u2f05rprqjhygz22m06mhy4xrnqvqqpyuzhmxqfxnwvxz8d2kd47hsre5v9urjyu8s0ryk38dxzw0t5jesncw4v90s22tk0f`,\n        certificates: [],\n        withdrawals: [],\n        accountPubKey:\n        'ec8fdf616242f430855ad7477acda53395eb30c295f5a7ef038712578877375b5a2f00353c9c5cc88c7ff18e71dc08724d90fc238213b789c0b02438e336be07',\n    },\n);\n\n// txPlan:\n// {\n//     totalSpent: '2168053',\n//     fee: '168053',\n// },\n\n```\n\n## Notes\n\n- If there are certificates present or the transaction includes an output with `setMax: true` then largest-first algorithm will be used instead of random-improve.\n","readmeFilename":"README.md"}