2020-06-20 12:52:59 +02:00
|
|
|
import { ContextType } from 'server/types/apiTypes';
|
|
|
|
import { getLnd } from 'server/helpers/helpers';
|
|
|
|
import { to } from 'server/helpers/async';
|
|
|
|
import { logger } from 'server/helpers/logger';
|
|
|
|
import { AuthType } from 'src/context/AccountContext';
|
|
|
|
|
2020-06-27 11:44:43 +02:00
|
|
|
import { rebalance } from 'balanceofsatoshis/swaps';
|
|
|
|
import { getAccountingReport } from 'balanceofsatoshis/balances';
|
|
|
|
import request from '@alexbosworth/request';
|
|
|
|
|
2020-06-20 12:52:59 +02:00
|
|
|
type RebalanceType = {
|
|
|
|
auth: AuthType;
|
|
|
|
avoid?: String[];
|
|
|
|
in_through?: String;
|
|
|
|
is_avoiding_high_inbound?: Boolean;
|
|
|
|
max_fee?: Number;
|
|
|
|
max_fee_rate?: Number;
|
|
|
|
max_rebalance?: Number;
|
|
|
|
node?: String;
|
|
|
|
out_channels?: String[];
|
|
|
|
out_through?: String;
|
|
|
|
target?: Number;
|
|
|
|
};
|
|
|
|
|
2020-06-27 11:44:43 +02:00
|
|
|
type AccountingType = {
|
|
|
|
auth: AuthType;
|
|
|
|
category?: String;
|
|
|
|
currency?: String;
|
|
|
|
fiat?: String;
|
|
|
|
month?: String;
|
|
|
|
year?: String;
|
|
|
|
};
|
|
|
|
|
2020-06-20 12:52:59 +02:00
|
|
|
export const bosResolvers = {
|
2020-06-27 11:44:43 +02:00
|
|
|
Query: {
|
|
|
|
getAccountingReport: async (
|
|
|
|
_: undefined,
|
|
|
|
params: AccountingType,
|
|
|
|
context: ContextType
|
|
|
|
) => {
|
|
|
|
const { auth, ...settings } = params;
|
|
|
|
const lnd = getLnd(auth, context);
|
|
|
|
|
|
|
|
const response = await to(
|
|
|
|
getAccountingReport({
|
|
|
|
lnd,
|
|
|
|
logger,
|
|
|
|
request,
|
|
|
|
is_csv: true,
|
|
|
|
...settings,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
return response;
|
|
|
|
},
|
|
|
|
},
|
2020-06-20 12:52:59 +02:00
|
|
|
Mutation: {
|
|
|
|
bosRebalance: async (
|
|
|
|
_: undefined,
|
|
|
|
params: RebalanceType,
|
|
|
|
context: ContextType
|
|
|
|
) => {
|
2020-06-27 11:44:43 +02:00
|
|
|
const {
|
|
|
|
auth,
|
|
|
|
avoid,
|
|
|
|
in_through,
|
|
|
|
is_avoiding_high_inbound,
|
|
|
|
max_fee,
|
|
|
|
max_fee_rate,
|
|
|
|
max_rebalance,
|
|
|
|
node,
|
|
|
|
out_channels,
|
|
|
|
out_through,
|
|
|
|
target,
|
|
|
|
} = params;
|
2020-06-20 12:52:59 +02:00
|
|
|
const lnd = getLnd(auth, context);
|
|
|
|
|
2020-06-27 11:44:43 +02:00
|
|
|
const filteredParams = {
|
2020-06-27 19:15:49 +02:00
|
|
|
avoid,
|
|
|
|
out_channels,
|
2020-06-27 11:44:43 +02:00
|
|
|
...(in_through && { in_through }),
|
|
|
|
...(is_avoiding_high_inbound && { is_avoiding_high_inbound }),
|
|
|
|
...(max_fee > 0 && { max_fee }),
|
|
|
|
...(max_fee_rate > 0 && { max_fee_rate }),
|
|
|
|
...(max_rebalance > 0 && { max_rebalance }),
|
|
|
|
...(node && { node }),
|
|
|
|
...(out_through && { out_through }),
|
|
|
|
...(target && { target }),
|
|
|
|
};
|
|
|
|
|
|
|
|
logger.info('Rebalance Params: %o', filteredParams);
|
|
|
|
|
2020-06-20 12:52:59 +02:00
|
|
|
const response = await to(
|
|
|
|
rebalance({
|
|
|
|
lnd,
|
|
|
|
logger,
|
2020-06-27 11:44:43 +02:00
|
|
|
...filteredParams,
|
2020-06-20 12:52:59 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
increase: response.rebalance[0],
|
|
|
|
decrease: response.rebalance[1],
|
|
|
|
result: response.rebalance[2],
|
|
|
|
};
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|