Skip to content

Commit 55aef4f

Browse files
authored
Merge pull request #8051 from BitGo/fix-consolidate
Fix for "insufficient funds error" while building unsigned consolidation in wallet-recovery-wizard.
2 parents f4dcb79 + ee3b5d9 commit 55aef4f

4 files changed

Lines changed: 96 additions & 123 deletions

File tree

modules/sdk-coin-ada/CHANGELOG.md

Lines changed: 12 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -23,221 +23,119 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
2323

2424
# [4.21.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.8...@bitgo/sdk-coin-ada@4.21.0) (2026-01-22)
2525

26-
2726
### Features
2827

29-
* **sdk-coin-ada:** support for sponsored txns ([cb75eda](https://github.com/BitGo/BitGoJS/commit/cb75edad4850135a92e0c5ea41156491977edf73))
30-
* **sdk-coin-ada:** token sponsorship support ([12e0c78](https://github.com/BitGo/BitGoJS/commit/12e0c78cef2d763d0e6de4bea94973d7b0e1788a))
31-
32-
33-
34-
28+
- **sdk-coin-ada:** support for sponsored txns ([cb75eda](https://github.com/BitGo/BitGoJS/commit/cb75edad4850135a92e0c5ea41156491977edf73))
29+
- **sdk-coin-ada:** token sponsorship support ([12e0c78](https://github.com/BitGo/BitGoJS/commit/12e0c78cef2d763d0e6de4bea94973d7b0e1788a))
3530

3631
## [4.20.8](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.7...@bitgo/sdk-coin-ada@4.20.8) (2026-01-19)
3732

38-
3933
### Bug Fixes
4034

41-
* **sdk-coin-ada:** use derivedFromParentWithSeed in address verification ([852137d](https://github.com/BitGo/BitGoJS/commit/852137d53e5813aaaccc0590379f81aafd708892))
42-
43-
44-
45-
35+
- **sdk-coin-ada:** use derivedFromParentWithSeed in address verification ([852137d](https://github.com/BitGo/BitGoJS/commit/852137d53e5813aaaccc0590379f81aafd708892))
4636

4737
## [4.20.7](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.6...@bitgo/sdk-coin-ada@4.20.7) (2026-01-19)
4838

4939
**Note:** Version bump only for package @bitgo/sdk-coin-ada
5040

51-
52-
53-
54-
5541
## [4.20.6](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.5...@bitgo/sdk-coin-ada@4.20.6) (2026-01-14)
5642

5743
**Note:** Version bump only for package @bitgo/sdk-coin-ada
5844

59-
60-
61-
62-
6345
## [4.20.5](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.4...@bitgo/sdk-coin-ada@4.20.5) (2026-01-07)
6446

6547
**Note:** Version bump only for package @bitgo/sdk-coin-ada
6648

67-
68-
69-
70-
7149
## [4.20.4](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.3...@bitgo/sdk-coin-ada@4.20.4) (2025-12-23)
7250

7351
**Note:** Version bump only for package @bitgo/sdk-coin-ada
7452

75-
76-
77-
78-
7953
## [4.20.3](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.2...@bitgo/sdk-coin-ada@4.20.3) (2025-12-17)
8054

8155
**Note:** Version bump only for package @bitgo/sdk-coin-ada
8256

83-
84-
85-
86-
8757
## [4.20.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.1...@bitgo/sdk-coin-ada@4.20.2) (2025-12-11)
8858

8959
**Note:** Version bump only for package @bitgo/sdk-coin-ada
9060

91-
92-
93-
94-
9561
## [4.20.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.20.0...@bitgo/sdk-coin-ada@4.20.1) (2025-12-05)
9662

9763
**Note:** Version bump only for package @bitgo/sdk-coin-ada
9864

99-
100-
101-
102-
10365
# [4.20.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.19.0...@bitgo/sdk-coin-ada@4.20.0) (2025-12-04)
10466

105-
10667
### Features
10768

108-
* address verification for ada ([b4ed3c5](https://github.com/BitGo/BitGoJS/commit/b4ed3c56739ad94471b3ccd417217ac91ecb573d))
109-
110-
111-
112-
69+
- address verification for ada ([b4ed3c5](https://github.com/BitGo/BitGoJS/commit/b4ed3c56739ad94471b3ccd417217ac91ecb573d))
11370

11471
# [4.19.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.18.3...@bitgo/sdk-coin-ada@4.19.0) (2025-11-26)
11572

116-
11773
### Features
11874

119-
* **sdk-coin-ada:** add build logs and modify token policy id ([8d8482a](https://github.com/BitGo/BitGoJS/commit/8d8482afa50d707bfa69caa6ccbab750a32c76ef))
120-
121-
122-
123-
75+
- **sdk-coin-ada:** add build logs and modify token policy id ([8d8482a](https://github.com/BitGo/BitGoJS/commit/8d8482afa50d707bfa69caa6ccbab750a32c76ef))
12476

12577
## [4.18.3](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.18.2...@bitgo/sdk-coin-ada@4.18.3) (2025-11-19)
12678

12779
**Note:** Version bump only for package @bitgo/sdk-coin-ada
12880

129-
130-
131-
132-
13381
## [4.18.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.18.1...@bitgo/sdk-coin-ada@4.18.2) (2025-11-13)
13482

13583
**Note:** Version bump only for package @bitgo/sdk-coin-ada
13684

137-
138-
139-
140-
14185
## [4.18.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.18.0...@bitgo/sdk-coin-ada@4.18.1) (2025-11-12)
14286

143-
14487
### Bug Fixes
14588

146-
* **sdk-coin-ada:** shouldn't throw insufficient qty for total token spend ([6820999](https://github.com/BitGo/BitGoJS/commit/6820999b2d8ce47110d894875db15a0569f31cba))
147-
148-
149-
150-
89+
- **sdk-coin-ada:** shouldn't throw insufficient qty for total token spend ([6820999](https://github.com/BitGo/BitGoJS/commit/6820999b2d8ce47110d894875db15a0569f31cba))
15190

15291
# [4.18.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.17.4...@bitgo/sdk-coin-ada@4.18.0) (2025-11-06)
15392

154-
15593
### Features
15694

157-
* deserialize signed CIP-8 message hex ([66b973a](https://github.com/BitGo/BitGoJS/commit/66b973a4708e1b96c53c3785c65654a63b0d43bb))
158-
159-
160-
161-
95+
- deserialize signed CIP-8 message hex ([66b973a](https://github.com/BitGo/BitGoJS/commit/66b973a4708e1b96c53c3785c65654a63b0d43bb))
16296

16397
## [4.17.4](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.17.3...@bitgo/sdk-coin-ada@4.17.4) (2025-10-31)
16498

16599
**Note:** Version bump only for package @bitgo/sdk-coin-ada
166100

167-
168-
169-
170-
171101
## [4.17.3](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.17.2...@bitgo/sdk-coin-ada@4.17.3) (2025-10-29)
172102

173103
**Note:** Version bump only for package @bitgo/sdk-coin-ada
174104

175-
176-
177-
178-
179105
## [4.17.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.17.1...@bitgo/sdk-coin-ada@4.17.2) (2025-10-24)
180106

181107
**Note:** Version bump only for package @bitgo/sdk-coin-ada
182108

183-
184-
185-
186-
187109
## [4.17.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.17.0...@bitgo/sdk-coin-ada@4.17.1) (2025-10-21)
188110

189111
**Note:** Version bump only for package @bitgo/sdk-coin-ada
190112

191-
192-
193-
194-
195113
# [4.17.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.16.2...@bitgo/sdk-coin-ada@4.17.0) (2025-10-16)
196114

197-
198115
### Features
199116

200-
* **sdk-coin-ada:** fix ada build signature handling ([34dacbc](https://github.com/BitGo/BitGoJS/commit/34dacbcc1a2e4619503f5a93410b611f55bbc847))
201-
* **sdk-coin-ada:** remove fallback logic for token fee calculation ([daef78e](https://github.com/BitGo/BitGoJS/commit/daef78ea58e9c93c4f1b4e0d78a0249ca6c5f524))
202-
203-
204-
205-
117+
- **sdk-coin-ada:** fix ada build signature handling ([34dacbc](https://github.com/BitGo/BitGoJS/commit/34dacbcc1a2e4619503f5a93410b611f55bbc847))
118+
- **sdk-coin-ada:** remove fallback logic for token fee calculation ([daef78e](https://github.com/BitGo/BitGoJS/commit/daef78ea58e9c93c4f1b4e0d78a0249ca6c5f524))
206119

207120
## [4.16.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.16.1...@bitgo/sdk-coin-ada@4.16.2) (2025-10-13)
208121

209122
**Note:** Version bump only for package @bitgo/sdk-coin-ada
210123

211-
212-
213-
214-
215124
## [4.16.1](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.16.0...@bitgo/sdk-coin-ada@4.16.1) (2025-10-09)
216125

217-
218126
### Bug Fixes
219127

220-
* run check-fmt on code files only ([9745196](https://github.com/BitGo/BitGoJS/commit/9745196b02b9678c740d290a4638ceb153a8fd75))
221-
222-
223-
224-
128+
- run check-fmt on code files only ([9745196](https://github.com/BitGo/BitGoJS/commit/9745196b02b9678c740d290a4638ceb153a8fd75))
225129

226130
# [4.16.0](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.15.2...@bitgo/sdk-coin-ada@4.16.0) (2025-10-08)
227131

228-
229132
### Bug Fixes
230133

231-
* add explicit 'files' in package json ([3b00373](https://github.com/BitGo/BitGoJS/commit/3b0037396f6ac16bb9380bd85bf37f2b133068f4))
232-
134+
- add explicit 'files' in package json ([3b00373](https://github.com/BitGo/BitGoJS/commit/3b0037396f6ac16bb9380bd85bf37f2b133068f4))
233135

234136
### Features
235137

236-
* **sdk-coin-ada:** use 1 ada as min fees ([558f621](https://github.com/BitGo/BitGoJS/commit/558f6213131e75aac3d0cefb12ac7633fe7c9419))
237-
238-
239-
240-
138+
- **sdk-coin-ada:** use 1 ada as min fees ([558f621](https://github.com/BitGo/BitGoJS/commit/558f6213131e75aac3d0cefb12ac7633fe7c9419))
241139

242140
## [4.15.2](https://github.com/BitGo/BitGoJS/compare/@bitgo/sdk-coin-ada@4.15.1...@bitgo/sdk-coin-ada@4.15.2) (2025-10-02)
243141

modules/sdk-coin-ada/src/ada.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,10 @@ export class Ada extends BaseCoin {
382382
seed: params.seed,
383383
};
384384
const { address: senderAddr, accountId } = await this.getAdaAddressAndAccountId(addressParams);
385-
const isUnsignedSweep = !params.userKey && !params.backupKey && !params.walletPassphrase;
385+
const isUnsignedSweep = !params.walletPassphrase;
386386
const { balance, utxoSet } = await this.getAddressInfo(senderAddr);
387387
if (balance <= 0) {
388-
throw new Error('Did not find address with funds to recover');
388+
throw new Error('Did not find address with funds to recover.');
389389
}
390390

391391
// first build the unsigned txn
@@ -407,7 +407,8 @@ export class Ada extends BaseCoin {
407407
(acc: BigNumber, output: { amount: string }) => new BigNumber(acc).plus(output.amount),
408408
new BigNumber(0)
409409
);
410-
if (amount.isLessThan(10000000)) {
410+
411+
if (amount.isLessThan(1000000)) {
411412
throw new Error(
412413
'Insufficient funds to recover, minimum required is 1 ADA plus fees, got ' +
413414
amount.toString() +
@@ -556,7 +557,10 @@ export class Ada extends BaseCoin {
556557
try {
557558
recoveryTransaction = await this.recover(recoverParams);
558559
} catch (e) {
559-
if (e.message === 'Did not find address with funds to recover') {
560+
if (
561+
e.message === 'Did not find address with funds to recover.' ||
562+
e.message.startsWith('Insufficient funds to recover')
563+
) {
560564
lastScanIndex = i;
561565
continue;
562566
}
@@ -572,7 +576,7 @@ export class Ada extends BaseCoin {
572576
}
573577

574578
if (consolidationTransactions.length == 0) {
575-
throw new Error('Did not find an address with funds to recover');
579+
throw new Error('Did not find an address with funds to recover.');
576580
}
577581

578582
if (isUnsignedSweep) {

modules/sdk-coin-ada/test/resources/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export const testnetUTXO = {
373373
UTXO_3: {
374374
tx_hash: '87f6e905a5796277ffb256265fd18d16f84ddb54ec8a841f7d467360c1c9fc2f',
375375
tx_index: 0,
376-
value: 10000000,
376+
value: 1000000,
377377
},
378378
};
379379

modules/sdk-coin-ada/test/unit/ada.ts

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ describe('ADA', function () {
734734
startingScanIndex: 1,
735735
endingScanIndex: 2,
736736
})
737-
.should.rejectedWith('Did not find an address with funds to recover');
737+
.should.rejectedWith('Did not find an address with funds to recover.');
738738
});
739739

740740
it('should throw if startingScanIndex is not ge to 1', async () => {
@@ -763,6 +763,77 @@ describe('ADA', function () {
763763
'Invalid starting or ending index to scan for addresses. startingScanIndex: 1, endingScanIndex: 300.'
764764
);
765765
});
766+
767+
it('should build unsigned consolidation recoveries', async function () {
768+
const res = await basecoin.recoverConsolidations({
769+
userKey: consolidationWrwUser.userKey,
770+
backupKey: consolidationWrwUser.backupKey,
771+
bitgoKey: consolidationWrwUser.bitgoKey,
772+
walletPassphrase: consolidationWrwUser.walletPassphrase,
773+
startingScanIndex: 1,
774+
endingScanIndex: 4,
775+
});
776+
res.should.not.be.empty();
777+
res.transactions.length.should.equal(2);
778+
});
779+
780+
it('should throw error if all addresses have balance less than 1 ADA', async function () {
781+
sandBox.restore();
782+
const callBack = sandBox.stub(Ada.prototype, 'getDataFromNode' as keyof Ada);
783+
callBack.withArgs('address_info', sinon.match.has('_addresses')).resolves({
784+
status: 200,
785+
body: [
786+
{
787+
balance: 500000,
788+
utxo_set: [
789+
{
790+
tx_hash: '8df8d41207980f9e21de698bd5d6c395c39e420f7de27f8539052dd34e3a28d6',
791+
tx_index: 0,
792+
value: 500000,
793+
},
794+
],
795+
},
796+
],
797+
});
798+
callBack.withArgs('tip').resolves(endpointResponses.tipInfoResponse);
799+
800+
await basecoin
801+
.recoverConsolidations({
802+
userKey: consolidationWrwUser.userKey,
803+
backupKey: consolidationWrwUser.backupKey,
804+
bitgoKey: consolidationWrwUser.bitgoKey,
805+
walletPassphrase: consolidationWrwUser.walletPassphrase,
806+
startingScanIndex: 1,
807+
endingScanIndex: 4,
808+
})
809+
.should.be.rejectedWith('Did not find an address with funds to recover.');
810+
});
811+
812+
it('should build even if single address has no funds', async function () {
813+
const res = await basecoin.recoverConsolidations({
814+
userKey: consolidationWrwUser.userKey,
815+
backupKey: consolidationWrwUser.backupKey,
816+
bitgoKey: consolidationWrwUser.bitgoKey,
817+
walletPassphrase: consolidationWrwUser.walletPassphrase,
818+
startingScanIndex: 1,
819+
endingScanIndex: 4,
820+
});
821+
res.should.not.be.empty();
822+
res.transactions.length.should.equal(2);
823+
});
824+
825+
it('should build even if single address has insufficient funds', async function () {
826+
const res = await basecoin.recoverConsolidations({
827+
userKey: consolidationWrwUser.userKey,
828+
backupKey: consolidationWrwUser.backupKey,
829+
bitgoKey: consolidationWrwUser.bitgoKey,
830+
walletPassphrase: consolidationWrwUser.walletPassphrase,
831+
startingScanIndex: 1,
832+
endingScanIndex: 4,
833+
});
834+
res.should.not.be.empty();
835+
res.transactions.length.should.equal(2);
836+
});
766837
});
767838

768839
describe('Recover Transactions Failure:', () => {
@@ -787,7 +858,7 @@ describe('ADA', function () {
787858
walletPassphrase: wrwUser.walletPassphrase,
788859
recoveryDestination: destAddr,
789860
})
790-
.should.rejectedWith('Did not find address with funds to recover');
861+
.should.rejectedWith('Did not find address with funds to recover.');
791862
sandBox.assert.calledOnce(basecoin.getDataFromNode);
792863
});
793864

@@ -806,7 +877,7 @@ describe('ADA', function () {
806877
recoveryDestination: destAddr,
807878
})
808879
.should.rejectedWith(
809-
'Insufficient funds to recover, minimum required is 1 ADA plus fees, got 9834455 fees: 165545'
880+
'Insufficient funds to recover, minimum required is 1 ADA plus fees, got 834455 fees: 165545'
810881
);
811882
sandBox.assert.calledTwice(basecoin.getDataFromNode);
812883
});

0 commit comments

Comments
 (0)