Comments (6)
You can run a one-pass filter on the utxos to split off those that have the assets you are looking for, those that contain only Ada, and those that contain Ada and assets your are not looking for.
I also distinguish between utxos that have only the asset I am looking for.
Within those filtered results, you can run your Random Sampling in this order:
Asset(s)
- Random sample through utxos with only the required asset as needed
- Random sample through utxos with the required assed and other assets as needed
Ada
- Random sample (or even largest-first) through the utxos with only ada as needed
- Random sample through all utxos that have not been chosen yet
No improvement step because you are guaranteed to be done as every pick is an improvement...
Important Note: Do not forget to increase the target quantity of Ada within the utxos selection loop to account for the carry necessary to send back the change output. The change output might contain a large number of random assets and the Ada necessary to send it back in change is NOT Ada that can be counted towards your coin selection target.
from lucid.
More opinonated take : At the last step where you need to scrounge for Ada within a bunch of utxos with assets you do not need, I actually do a weighted sorting where the weight is
weight = Ada / (1 + Number of Assets ^ 2)
and pick from those in order from the largest to the smallest so as to minimize my grabbing random junk. But I admit this is might be a matter of (even more) debate.
from lucid.
Did you look at the implementation of the off-chain code handling that IOG provides in the Constraints
module? Or do you see the above problems with that implementation as well?
from lucid.
The Contraints
module helps you to build the tx in the way you need it. Lucid allows you to do exactly the same. So yeah this is covered as well. Basically any kind of transaction should be possible regardless of what you add and the coin selection should be able to find the right inputs.
from lucid.
Was this ever implemented? I would love to have a utils function in Lucid to do random improve coin selection for me, right now it looks like Nami is not really doing it by default with .getUTxOs
from lucid.
I wonder if this proposal could work with Lucid: cardano-foundation/CIPs#785
There is a sample implementation in CardanoSharp (C# library)
Implementation Code Example
An implementation example for all 3 core functions involved in the Optimized Random Improve selection can be found in this fork of the CardanoSharp Library here:
Aggregator Function - https://github.com/Orion-Crypto/cardanosharp-wallet/blob/optimized-coin-selection-example/CardanoSharp.Wallet/CIPs/CIP2/CoinSelectionService.cs Select Inputs Function - https://github.com/Orion-Crypto/cardanosharp-wallet/blob/optimized-coin-selection-example/CardanoSharp.Wallet/CIPs/CIP2/CoinSelectionStrategies/OptimizedRandomImproveStrategy.cs Change Selection Function - https://github.com/Orion-Crypto/cardanosharp-wallet/blob/optimized-coin-selection-example/CardanoSharp.Wallet/CIPs/CIP2/ChangeCreationStrategies/MultiSplitChangeSelectionStrategy.cs
from lucid.
Related Issues (20)
- Wallet from seed doesn't sign transaction spending only UTXOs locked with enterprise address HOT 1
- How to build transaction whose input is from zero address and output is also zero address? HOT 2
- Potential External Memory Leak - External Resources not being collected. HOT 2
- Unclear mapping of data structures between lucid and aiken HOT 1
- Add Docs for Vite/SvelteKit HOT 1
- Nami requests signature fee instead of requesting payment?
- Nami requests signature fee instead of requesting payment? HOT 1
- next 13 and lucid HOT 2
- No "exports" main defined in package.json HOT 2
- Fee Estimation issue when building contract remdemption TX on the backend. HOT 1
- `'amounts-as-strings': 'true'` for Maestro provider endpoints
- "Max collateral inputs reached" HOT 2
- Merging change utxos in minting transaction HOT 1
- No "exports" main defined while using lucid-cardano with typescript.
- vite node vue3 http://127.0.0.1:4001/node_modules/.vite/deps/cardano_multiplatform_lib_bg.wasm 404 (Not Found) HOT 1
- Unlock transaction: Uncaught (in promise) Redeemer (Spend, 0): Failed to deserialise PlutusData using UnConstrData: HOT 7
- Nextjs 14 and context
- How to use blueprint.ts?
- Could not serialize the data: TypeError: Cannot read properties of undefined (reading 'plutuslist_new') HOT 1
- Can't read transactionbuilderconfigbuilder_new in React Vite app HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lucid.