Skip to content

Commit c51b844

Browse files
authored
Merge pull request #5845 from BitGo/coin-3571-fix-fund-forwarders-script
fix: fund forwarders script
2 parents 6f8c034 + 99915c4 commit c51b844

File tree

5 files changed

+72
-5
lines changed

5 files changed

+72
-5
lines changed

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585
/modules/sdk-coin-xtz/ @BitGo/ethalt-team
8686
/modules/sdk-coin-zketh/ @BitGo/ethalt-team
8787

88+
# Examples
89+
/examples/ @BitGo/ethalt-team
90+
8891
# Trade
8992
/modules/sdk-core/src/bitgo/address-book/ @BitGo/prime
9093
/modules/sdk-core/src/bitgo/trading/ @BitGo/prime

examples/ts/apt/fund-forwarders.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Send funds from a gas tank to a BitGo wallet's receive address.
3+
*
4+
* Copyright 2025, BitGo, Inc. All Rights Reserved.
5+
*/
6+
import { BitGoAPI } from '@bitgo/sdk-api';
7+
import { Tapt } from '@bitgo/sdk-coin-apt';
8+
import { FundForwarderParams } from '@bitgo/sdk-core';
9+
10+
const bitgo = new BitGoAPI({
11+
accessToken: '<access token>',
12+
env: 'test',
13+
});
14+
15+
const coin = 'tapt';
16+
bitgo.register(coin, Tapt.createInstance);
17+
18+
const walletId = '<wallet id>';
19+
20+
async function main() {
21+
bitgo.unlock({ otp: '000000' });
22+
const walletInstance = await bitgo.coin(coin).wallets().get({ id: walletId });
23+
24+
const fundForwarderParams: FundForwarderParams = {
25+
forwarders: [
26+
{
27+
forwarderAddress: '<forwarder address>',
28+
amount: '<amount>' // optional field
29+
},
30+
],
31+
}
32+
33+
const response = await walletInstance.fundForwarders(fundForwarderParams);
34+
console.log('Response', response);
35+
}
36+
37+
main().catch((e) => console.error(e));

examples/ts/eth/fund-forwarder.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { FundForwarderParams } from "@bitgo/sdk-core";
2+
13
/**
24
* Send funds from a fee address to a forwarder.
35
*
@@ -28,12 +30,16 @@ async function fundForwarder() {
2830
bitgo.authenticateWithAccessToken({ accessToken });
2931
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
3032

31-
const fundForwarderOptions = {
32-
forwarderAddress: forwarderAddress,
33-
amount: amount,
34-
};
33+
const fundForwarderParams: FundForwarderParams = {
34+
forwarders: [
35+
{
36+
forwarderAddress,
37+
amount, // optional field
38+
},
39+
],
40+
}
3541

36-
const response = await wallet.fundForwarder(fundForwarderOptions);
42+
const response = await wallet.fundForwarders(fundForwarderParams);
3743
console.log('Response', response);
3844
}
3945

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ export interface FundForwardersOptions {
432432
amount?: string;
433433
}
434434

435+
export interface FundForwarderParams {
436+
forwarders: FundForwardersOptions[];
437+
}
438+
435439
export interface FlushForwarderTokenOptions {
436440
address?: string;
437441
id?: string;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import {
9999
BulkWalletShareKeychain,
100100
ManageUnspentReservationOptions,
101101
SignAndSendTxRequestOptions,
102+
FundForwarderParams,
102103
} from './iWallet';
103104
import { GoStakingWallet, StakingWallet } from '../staking';
104105
import EddsaUtils from '../utils/tss/eddsa';
@@ -3629,6 +3630,22 @@ export class Wallet implements IWallet {
36293630
return this._wallet;
36303631
}
36313632

3633+
/**
3634+
* Send funds from a fee address to a forwarder.
3635+
*
3636+
* @param {Object} params - parameters object
3637+
* @param {List} params.forwarders - list of fund forwarder options
3638+
* @returns {*}
3639+
*/
3640+
public async fundForwarders(params: FundForwarderParams): Promise<any> {
3641+
if (_.isUndefined(params.forwarders) || params.forwarders.length == 0) {
3642+
throw new Error('fund forwarder options required');
3643+
}
3644+
const url = this.url('/fundforwarders');
3645+
this._wallet = await this.bitgo.post(url).send(params).result();
3646+
return this._wallet;
3647+
}
3648+
36323649
/**
36333650
* Gets forwarder's balance
36343651
* @param params - optional query parameters

0 commit comments

Comments
 (0)