diff --git a/example/aggregator/package.json b/example/aggregator/package.json index d50534b..c2eeffd 100644 --- a/example/aggregator/package.json +++ b/example/aggregator/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "@nervina-labs/cota-sdk": "0.4.8", + "@nervina-labs/cota-sdk": "0.5.0", "@types/node": "17.0.21", "ts-node": "10.7.0", "tslib": "2.4.0", diff --git a/example/aggregator/yarn.lock b/example/aggregator/yarn.lock index 4a26040..2a139ce 100644 --- a/example/aggregator/yarn.lock +++ b/example/aggregator/yarn.lock @@ -14,10 +14,10 @@ dependencies: "@cspotcode/source-map-consumer" "0.8.0" -"@nervina-labs/cota-sdk@0.4.8": - version "0.4.8" - resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.4.8.tgz#f70ae1f46e34eb62205db877446a65e6d6aa020e" - integrity sha512-JqtSwcorEzUktZlvtyl4CkpVqeLet+LsWGbeS9QUqrW8iFli8LJLq+H7eDiEkLrlK29HSVn63e+lL6XgLT0XCQ== +"@nervina-labs/cota-sdk@0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.5.0.tgz#8095a3aec3d83c0cc8fc35574d6a4cbfd031b365" + integrity sha512-Yi48wnG+ykXrDYVgvnH3CACovhvTYw766+6qD5LsBalYCs7QWZwhhuaYq43hQb0N8G2xGrbPa0xR/qwZkew3/Q== dependencies: "@nervosnetwork/ckb-sdk-core" "^0.102.3" "@nervosnetwork/ckb-sdk-utils" "^0.102.3" diff --git a/example/mainnet/package.json b/example/mainnet/package.json index d150ab2..4f5633c 100644 --- a/example/mainnet/package.json +++ b/example/mainnet/package.json @@ -4,6 +4,6 @@ "description": "The examples for mainnet", "license": "MIT", "dependencies": { - "@nervina-labs/cota-sdk": "0.4.8" + "@nervina-labs/cota-sdk": "0.5.0" } } \ No newline at end of file diff --git a/example/mainnet/yarn.lock b/example/mainnet/yarn.lock index 56ea2f6..8fa5c8f 100644 --- a/example/mainnet/yarn.lock +++ b/example/mainnet/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@nervina-labs/cota-sdk@0.4.8": - version "0.4.8" - resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.4.8.tgz#f70ae1f46e34eb62205db877446a65e6d6aa020e" - integrity sha512-JqtSwcorEzUktZlvtyl4CkpVqeLet+LsWGbeS9QUqrW8iFli8LJLq+H7eDiEkLrlK29HSVn63e+lL6XgLT0XCQ== +"@nervina-labs/cota-sdk@0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@nervina-labs/cota-sdk/-/cota-sdk-0.5.0.tgz#8095a3aec3d83c0cc8fc35574d6a4cbfd031b365" + integrity sha512-Yi48wnG+ykXrDYVgvnH3CACovhvTYw766+6qD5LsBalYCs7QWZwhhuaYq43hQb0N8G2xGrbPa0xR/qwZkew3/Q== dependencies: "@nervosnetwork/ckb-sdk-core" "^0.102.3" "@nervosnetwork/ckb-sdk-utils" "^0.102.3" diff --git a/package.json b/package.json index f12d570..7b49918 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nervina-labs/cota-sdk", - "version": "0.5.0", + "version": "0.5.1", "description": "The SDK of CoTA", "repository": "git@github.com:nervina-labs/cota-sdk-js.git", "author": "duanyytop ", @@ -40,7 +40,7 @@ "eslint-config-prettier": "8.5.0", "eslint-plugin-import": "2.26.0", "eslint-plugin-prettier": "4.0.0", - "husky": "8.0.0", + "husky": "8.0.1", "prettier": "2.6.2", "ts-node": "10.7.0", "tslib": "2.4.0", diff --git a/src/collector/index.ts b/src/collector/index.ts index 61b4242..4296681 100644 --- a/src/collector/index.ts +++ b/src/collector/index.ts @@ -2,6 +2,7 @@ import axios from 'axios' import CKB from '@nervosnetwork/ckb-sdk-core' import { toCamelcase } from '../utils/case-parser' import { IndexerCell, CollectResult } from '../types/collector' +import { MIN_CAPACITY } from '../constants' export class Collector { private ckbNodeUrl: string @@ -79,13 +80,16 @@ export class Collector { since: '0x0', }) sum = sum + BigInt(cell.output.capacity) - if (sum >= needCapacity + fee) { + if (sum >= needCapacity + MIN_CAPACITY + fee) { break } } if (sum < needCapacity + fee) { throw Error('Capacity not enough') } + if (sum < needCapacity + MIN_CAPACITY + fee) { + throw Error('Capacity not enough for change') + } return { inputs, capacity: sum } } diff --git a/yarn.lock b/yarn.lock index 80863ba..0ac8ae2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1036,10 +1036,10 @@ hmac-drbg@^1.0.1: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -husky@8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.0.tgz#65b2d94765199d651615716a42ea52f3c2d997a0" - integrity sha512-4qbE/5dzNDNxFEkX9MNRPKl5+omTXQzdILCUWiqG/lWIAioiM5vln265/l6I2Zx8gpW8l1ukZwGQeCFbBZ6+6w== +husky@8.0.1: + version "8.0.1" + resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.1.tgz#511cb3e57de3e3190514ae49ed50f6bc3f50b3e9" + integrity sha512-xs7/chUH/CKdOCs7Zy0Aev9e/dKOMZf3K1Az1nar3tzlv0jfqnYtu235bstsWTmXOR0EfINrPa97yy4Lz6RiKw== ignore@^5.2.0: version "5.2.0"