Skip to content

Commit

Permalink
fix(cip2): change token bundle size constraint arg to CSL.MultiAsset
Browse files Browse the repository at this point in the history
  • Loading branch information
mkazlauskas committed Sep 24, 2021
1 parent 259cc74 commit 4bde8e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/cip2/src/RoundRobinRandomImprove/change.ts
Expand Up @@ -264,7 +264,9 @@ export const computeChangeAndAdjustForFee = async ({

const change = changeBundles.map((bundle) => valueQuantitiesToValue(bundle, csl));
for (const value of change) {
if (tokenBundleSizeExceedsLimit(value)) {
const multiasset = value.multiasset();
if (!multiasset) continue;
if (tokenBundleSizeExceedsLimit(multiasset)) {
// Algorithm could be improved to attempt to rebalance the bundles
throw new InputSelectionError(InputSelectionFailure.UtxoFullyDepleted);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cip2/src/types.ts
Expand Up @@ -48,7 +48,7 @@ export type EstimateTxFee = (selectionSkeleton: SelectionSkeleton) => Promise<bi
/**
* @returns true if token bundle size exceeds it's maximum size limit.
*/
export type TokenBundleSizeExceedsLimit = (tokenBundle: CSL.Value) => boolean;
export type TokenBundleSizeExceedsLimit = (tokenBundle: CSL.MultiAsset) => boolean;

/**
* @returns minimum lovelace amount in a UTxO
Expand Down
4 changes: 2 additions & 2 deletions packages/cip2/test/RoundRobinRandomImprove.test.ts
Expand Up @@ -135,8 +135,8 @@ describe('RoundRobinRandomImprove', () => {
it('Change bundle size exceeds constraint', async () => {
await testInputSelectionFailureMode({
getAlgorithm: getRoundRobinRandomImprove,
createUtxo: (utils) => [utils.createUnspentTxOutput({ coins: 2_000_000n })],
createOutputs: (utils) => [utils.createOutput({ coins: 1_000_000n })],
createUtxo: (utils) => [utils.createUnspentTxOutput({ coins: 2_000_000n, assets: { [TSLA_Asset]: 1000n } })],
createOutputs: (utils) => [utils.createOutput({ coins: 1_000_000n, assets: { [TSLA_Asset]: 500n } })],
constraints: {
...NO_CONSTRAINTS,
tokenBundleSizeExceedsLimit: () => true
Expand Down

0 comments on commit 4bde8e8

Please sign in to comment.