@xchainjs/xchain-thorchain-query 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.esm.js CHANGED
@@ -974,6 +974,58 @@ class Thornode {
974
974
  throw new Error(`THORNode not responding`);
975
975
  });
976
976
  }
977
+ /**
978
+ *
979
+ * @param height
980
+ * @param asset
981
+ * @param amount
982
+ * @param targetAsset
983
+ * @param destination
984
+ * @param minOut
985
+ * @param affiliateBps
986
+ * @param affiliate
987
+ * @returns
988
+ */
989
+ getLoanQuoteOpen(asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height) {
990
+ return __awaiter(this, void 0, void 0, function* () {
991
+ for (const api of this.quoteApi) {
992
+ try {
993
+ const resp = (yield api.quoteloanopen(height, asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate)).data;
994
+ return resp;
995
+ }
996
+ catch (e) {
997
+ //console.log(e)
998
+ }
999
+ }
1000
+ throw new Error(`THORNode is not responding`);
1001
+ });
1002
+ }
1003
+ /**
1004
+ *
1005
+ * @param height
1006
+ * @param asset
1007
+ * @param amount
1008
+ * @param targetAsset
1009
+ * @param destination
1010
+ * @param minOut
1011
+ * @param affiliateBps
1012
+ * @param affiliate
1013
+ * @returns
1014
+ */
1015
+ getLoanQuoteClose(asset, amount, fromAddress, loanAsset, loanOwner, minOut, height) {
1016
+ return __awaiter(this, void 0, void 0, function* () {
1017
+ for (const api of this.quoteApi) {
1018
+ try {
1019
+ const resp = (yield api.quoteloanclose(height, asset, amount, fromAddress, loanAsset, loanOwner, minOut)).data;
1020
+ return resp;
1021
+ }
1022
+ catch (e) {
1023
+ // console.log(e)
1024
+ }
1025
+ }
1026
+ throw new Error(`THORNode is not responding`);
1027
+ });
1028
+ }
977
1029
  }
978
1030
 
979
1031
  const SAME_ASSET_EXCHANGE_RATE = new BigNumber(1);
@@ -1996,6 +2048,138 @@ class ThorchainQuery {
1996
2048
  return errors;
1997
2049
  });
1998
2050
  }
2051
+ /**
2052
+ *
2053
+ * @param loanOpenParams - params needed for the end Point
2054
+ * @returns
2055
+ */
2056
+ getLoanQuoteOpen({ asset, amount, targetAsset, destination, minOut, affiliateBps, affiliate, height, }) {
2057
+ return __awaiter(this, void 0, void 0, function* () {
2058
+ const errors = [];
2059
+ const loanOpenResp = yield this.thorchainCache.thornode.getLoanQuoteOpen(`${asset.chain}.${asset.ticker}`, amount.baseAmount.amount().toNumber(), `${targetAsset.chain}.${targetAsset.ticker}`, destination, minOut, affiliateBps, affiliate, height);
2060
+ const response = JSON.parse(JSON.stringify(loanOpenResp));
2061
+ if (response.error)
2062
+ errors.push(`Thornode request quote failed: ${response.error}`);
2063
+ if (errors.length > 0) {
2064
+ return {
2065
+ inboundAddress: '',
2066
+ expectedWaitTime: {
2067
+ outboundDelayBlocks: undefined,
2068
+ outbondDelaySeconds: undefined,
2069
+ },
2070
+ fees: {
2071
+ asset: '',
2072
+ liquidity: undefined,
2073
+ outbound: undefined,
2074
+ total_bps: undefined,
2075
+ },
2076
+ slippageBps: undefined,
2077
+ router: undefined,
2078
+ expiry: 0,
2079
+ warning: '',
2080
+ notes: '',
2081
+ dustThreshold: undefined,
2082
+ memo: undefined,
2083
+ expectedAmountOut: '',
2084
+ expectedCollateralizationRation: '',
2085
+ expectedCollateralUp: '',
2086
+ expectedDebtUp: '',
2087
+ errors: errors,
2088
+ };
2089
+ }
2090
+ const loanOpenQuote = {
2091
+ inboundAddress: loanOpenResp.inbound_address,
2092
+ expectedWaitTime: {
2093
+ outboundDelayBlocks: loanOpenResp.outbound_delay_blocks,
2094
+ outbondDelaySeconds: loanOpenResp.outbound_delay_seconds,
2095
+ },
2096
+ fees: {
2097
+ asset: loanOpenResp.fees.asset,
2098
+ liquidity: loanOpenResp.fees.liquidity,
2099
+ outbound: loanOpenResp.fees.outbound,
2100
+ total_bps: loanOpenResp.fees.total_bps,
2101
+ },
2102
+ slippageBps: loanOpenResp.slippage_bps,
2103
+ router: loanOpenResp.router,
2104
+ expiry: loanOpenResp.expiry,
2105
+ warning: loanOpenResp.warning,
2106
+ notes: loanOpenResp.notes,
2107
+ dustThreshold: loanOpenResp.dust_threshold,
2108
+ memo: loanOpenResp.memo,
2109
+ expectedAmountOut: loanOpenResp.expected_amount_out,
2110
+ expectedCollateralizationRation: loanOpenResp.expected_collateralization_ratio,
2111
+ expectedCollateralUp: loanOpenResp.expected_collateral_up,
2112
+ expectedDebtUp: loanOpenResp.expected_collateral_up,
2113
+ errors: errors,
2114
+ };
2115
+ return loanOpenQuote;
2116
+ });
2117
+ }
2118
+ /**
2119
+ *
2120
+ * @param loanOpenParams - params needed for the end Point
2121
+ * @returns
2122
+ */
2123
+ getLoanQuoteClose({ asset, amount, fromAddress, loanAsset, loanOwner, minOut, height, }) {
2124
+ return __awaiter(this, void 0, void 0, function* () {
2125
+ const errors = [];
2126
+ const loanCloseResp = yield this.thorchainCache.thornode.getLoanQuoteClose(`${asset.chain}.${asset.ticker}`, amount.baseAmount.amount().toNumber(), fromAddress, `${loanAsset.chain}.${loanAsset.ticker}`, loanOwner, minOut, height);
2127
+ const response = JSON.parse(JSON.stringify(loanCloseResp));
2128
+ if (response.error)
2129
+ errors.push(`Thornode request quote failed: ${response.error}`);
2130
+ if (errors.length > 0) {
2131
+ return {
2132
+ inboundAddress: '',
2133
+ expectedWaitTime: {
2134
+ outboundDelayBlocks: undefined,
2135
+ outbondDelaySeconds: undefined,
2136
+ },
2137
+ fees: {
2138
+ asset: '',
2139
+ liquidity: undefined,
2140
+ outbound: undefined,
2141
+ total_bps: undefined,
2142
+ },
2143
+ slippageBps: undefined,
2144
+ router: undefined,
2145
+ expiry: 0,
2146
+ warning: '',
2147
+ notes: '',
2148
+ dustThreshold: undefined,
2149
+ memo: undefined,
2150
+ expectedAmountOut: '',
2151
+ expectedCollateralDown: '',
2152
+ expectedDebtDown: '',
2153
+ errors: errors,
2154
+ };
2155
+ }
2156
+ const loanCloseQuote = {
2157
+ inboundAddress: loanCloseResp.inbound_address,
2158
+ expectedWaitTime: {
2159
+ outboundDelayBlocks: loanCloseResp.outbound_delay_blocks,
2160
+ outbondDelaySeconds: loanCloseResp.outbound_delay_seconds,
2161
+ },
2162
+ fees: {
2163
+ asset: loanCloseResp.fees.asset,
2164
+ liquidity: loanCloseResp.fees.liquidity,
2165
+ outbound: loanCloseResp.fees.outbound,
2166
+ total_bps: loanCloseResp.fees.total_bps,
2167
+ },
2168
+ slippageBps: loanCloseResp.slippage_bps,
2169
+ router: loanCloseResp.router,
2170
+ expiry: loanCloseResp.expiry,
2171
+ warning: loanCloseResp.warning,
2172
+ notes: loanCloseResp.notes,
2173
+ dustThreshold: loanCloseResp.dust_threshold,
2174
+ memo: loanCloseResp.memo,
2175
+ expectedAmountOut: loanCloseResp.expected_amount_out,
2176
+ expectedCollateralDown: loanCloseResp.expected_collateral_down,
2177
+ expectedDebtDown: loanCloseResp.expected_debt_down,
2178
+ errors: errors,
2179
+ };
2180
+ return loanCloseQuote;
2181
+ });
2182
+ }
1999
2183
  }
2000
2184
 
2001
2185
  var TxType;