Skip to content

Commit

Permalink
feat(sdk-core): add WalletBalance codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
ericli-bitgo committed Jan 14, 2025
1 parent 9f547c1 commit 9e577e4
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions modules/sdk-core/src/bitgo/lightning/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,82 @@ export const UpdateLightningWallet = t.partial(
);

export type UpdateLightningWallet = t.TypeOf<typeof UpdateLightningWallet>;

const LndAmount = t.strict(
{
sat: t.string,
msat: t.string,
},
'LndAmount'
);

export type LndAmount = t.TypeOf<typeof LndAmount>;

const ChannelBalance = t.strict(
{
/** The balance on your side of the channel and what you the user can spend. */
localBalance: LndAmount,
/** The balance on the other side of the channel, what your channel partner can controls. */
remoteBalance: LndAmount,
/** Sum of local unsettled balances. */
unsettledLocalBalance: LndAmount,
/** Sum of remote unsettled balances. */
unsettledRemoteBalance: LndAmount,
/** Sum of local pending balances. */
pendingOpenLocalBalance: LndAmount,
/** Sum of local remote balances. */
pendingOpenRemoteBalance: LndAmount,
},
'ChannelBalance'
);

export type ChannelBalance = t.TypeOf<typeof ChannelBalance>;

const LndWalletBalance = t.strict(
{
/** Total balance, confirmed and unconfirmed */
totalBalance: t.string,
confirmedBalance: t.string,
unconfirmedBalance: t.string,
},
'LndWalletBalance'
);

export type LndWalletBalance = t.TypeOf<typeof LndWalletBalance>;

/**
The balances as returned from lnd.
Wallet Balance
https://api.lightning.community/api/lnd/lightning/wallet-balance/index.html
Channel Balance
https://api.lightning.community/api/lnd/lightning/channel-balance/index.html
*/
export const LndBalance = t.strict(
{
offchain: ChannelBalance,
onchain: LndWalletBalance,
},
'LndBalance'
);

export type LndBalance = t.TypeOf<typeof LndBalance>;

const LndGetBalancesResponse = t.strict(
{
inboundBalance: t.string,
inboundPendingBalance: t.string,
inboundUnsettledBalance: t.string,
outboundBalance: t.string,
outboundPendingBalance: t.string,
outboundUnsettledBalance: t.string,
// wallet balances, names forced by type in AbstractCoin
spendableBalanceString: t.string,
balanceString: t.string,
confirmedBalanceString: t.string,
},
'LndGetBalancesResponse'
);

export type LndGetBalancesResponse = t.TypeOf<typeof LndGetBalancesResponse>;

0 comments on commit 9e577e4

Please sign in to comment.