@shapeshiftoss/swapper 5.10.2 → 5.11.0

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.
@@ -1,5 +1,5 @@
1
1
  import { ChainAdapterManager } from '@shapeshiftoss/chain-adapters';
2
- export declare type MidgardResponse = {
2
+ export declare type PoolResponse = {
3
3
  asset: string;
4
4
  assetDepth: string;
5
5
  assetPrice: string;
@@ -0,0 +1,3 @@
1
+ import { AssetId } from '@shapeshiftoss/caip';
2
+ import { ThorchainSwapperDeps } from '../../types';
3
+ export declare const estimateTradeFee: (deps: ThorchainSwapperDeps, buyAssetId: AssetId) => Promise<string>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateTradeFee = void 0;
4
+ const caip_1 = require("@shapeshiftoss/caip");
5
+ const api_1 = require("../../../../api");
6
+ const bignumber_1 = require("../../../zrx/utils/bignumber");
7
+ const thorService_1 = require("../thorService");
8
+ const gweiGasPrecision = 9;
9
+ // https://docs.thorchain.org/how-it-works/fees#outbound-fee
10
+ // estimatedTradeFee = `3 * estimatedFeeOutboundFee`
11
+ // eth txs from thorchain use approx 38383 gas
12
+ const ethEstimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate).times(38383).times(3).times((0, bignumber_1.bn)(10).exponentiatedBy(gweiGasPrecision)).toString();
13
+ // erc20 txs from thorchain use approx 70996 gas
14
+ const erc20Estimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate).times(70996).times(3).times((0, bignumber_1.bn)(10).exponentiatedBy(gweiGasPrecision)).toString();
15
+ // BTC utxo transactions from thorchain are approx 303 bytes long
16
+ const btcEstimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate).times(303).times(3).toString();
17
+ const estimateTradeFee = async (deps, buyAssetId) => {
18
+ const thorId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAssetId });
19
+ if (!thorId)
20
+ throw new api_1.SwapError('[estimateTradeFee] - undefined thorId for given buyAssetId', {
21
+ code: api_1.SwapErrorTypes.VALIDATION_FAILED,
22
+ details: { buyAssetId }
23
+ });
24
+ const thorPoolChainId = thorId.slice(0, thorId.indexOf('.'));
25
+ const { data: inboundAddresses } = await thorService_1.thorService.get(`${deps.midgardUrl}/thorchain/inbound_addresses`);
26
+ const inboundInfo = inboundAddresses.find((inbound) => inbound.chain === thorPoolChainId);
27
+ if (!inboundInfo)
28
+ throw new api_1.SwapError('[estimateTradeFee] - unable to locate inbound pool info', {
29
+ code: api_1.SwapErrorTypes.VALIDATION_FAILED,
30
+ details: { thorPoolChainId }
31
+ });
32
+ const gasRate = inboundInfo.gas_rate;
33
+ const { chainId, assetNamespace } = (0, caip_1.fromAssetId)(buyAssetId);
34
+ switch (chainId) {
35
+ case 'bip122:000000000019d6689c085ae165831e93':
36
+ return btcEstimate(gasRate);
37
+ case 'eip155:1':
38
+ switch (assetNamespace) {
39
+ case 'slip44':
40
+ return ethEstimate(gasRate);
41
+ case 'erc20':
42
+ return erc20Estimate(gasRate);
43
+ default:
44
+ throw new api_1.SwapError('[estimateTradeFee] - unsupported asset namespace', {
45
+ code: api_1.SwapErrorTypes.VALIDATION_FAILED,
46
+ details: { assetNamespace }
47
+ });
48
+ }
49
+ default:
50
+ throw new api_1.SwapError('[estimateTradeFee] - unsupported chain id', {
51
+ code: api_1.SwapErrorTypes.VALIDATION_FAILED,
52
+ details: { chainId }
53
+ });
54
+ }
55
+ };
56
+ exports.estimateTradeFee = estimateTradeFee;
@@ -1,5 +1,6 @@
1
- import { MidgardResponse } from '../../types';
2
- export declare const btcMidgardPool: MidgardResponse;
3
- export declare const ethMidgardPool: MidgardResponse;
4
- export declare const foxMidgardPool: MidgardResponse;
5
- export declare const midgardResponse: MidgardResponse[];
1
+ import { InboundResponse, PoolResponse } from '../../types';
2
+ export declare const btcMidgardPool: PoolResponse;
3
+ export declare const ethMidgardPool: PoolResponse;
4
+ export declare const foxMidgardPool: PoolResponse;
5
+ export declare const mockInboundAdresses: InboundResponse[];
6
+ export declare const poolResponse: PoolResponse[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.midgardResponse = exports.foxMidgardPool = exports.ethMidgardPool = exports.btcMidgardPool = void 0;
3
+ exports.poolResponse = exports.mockInboundAdresses = exports.foxMidgardPool = exports.ethMidgardPool = exports.btcMidgardPool = void 0;
4
4
  exports.btcMidgardPool = {
5
5
  asset: 'BTC.BTC',
6
6
  assetDepth: '91027798705',
@@ -43,4 +43,56 @@ exports.foxMidgardPool = {
43
43
  units: '10568061707512',
44
44
  volume24h: '251596933033'
45
45
  };
46
- exports.midgardResponse = [exports.btcMidgardPool, exports.ethMidgardPool, exports.foxMidgardPool];
46
+ exports.mockInboundAdresses = [
47
+ {
48
+ chain: 'BCH',
49
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
50
+ address: 'qp5a6rn8zmamgmsyspqsl0p6ktk4hrheggdjdvntv0',
51
+ halted: false,
52
+ gas_rate: '3'
53
+ },
54
+ {
55
+ chain: 'BNB',
56
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
57
+ address: 'bnb1d8wsuecklw6xupyqgy8mcw4ja4dca72z7nvqzw',
58
+ halted: false,
59
+ gas_rate: '11250'
60
+ },
61
+ {
62
+ chain: 'BTC',
63
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
64
+ address: 'bc1qd8wsuecklw6xupyqgy8mcw4ja4dca72z2dd88d',
65
+ halted: false,
66
+ gas_rate: '18'
67
+ },
68
+ {
69
+ chain: 'DOGE',
70
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
71
+ address: 'DEnrJfAjC4KMsLsGtoTGSmYaFZLPunWw9q',
72
+ halted: false,
73
+ gas_rate: '550384'
74
+ },
75
+ {
76
+ chain: 'ETH',
77
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
78
+ address: '0x78e4e10dcacb0a8261eb3d5e57ffb98ae8d4dff1',
79
+ router: '0x3624525075b88B24ecc29CE226b0CEc1fFcB6976',
80
+ halted: false,
81
+ gas_rate: '280'
82
+ },
83
+ {
84
+ chain: 'LTC',
85
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
86
+ address: 'ltc1qd8wsuecklw6xupyqgy8mcw4ja4dca72zw3hrla',
87
+ halted: false,
88
+ gas_rate: '60'
89
+ },
90
+ {
91
+ chain: 'TERRA',
92
+ pub_key: 'thorpub1addwnpepqfyppkehky2hn2gy26y8jqyj9fz0rnvau2r7yueawzvc662w0x9s7n4ypra',
93
+ address: 'terra1d8wsuecklw6xupyqgy8mcw4ja4dca72z6nfvpq',
94
+ halted: true,
95
+ gas_rate: '182523800'
96
+ }
97
+ ];
98
+ exports.poolResponse = [exports.btcMidgardPool, exports.ethMidgardPool, exports.foxMidgardPool];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swapper",
3
- "version": "5.10.2",
3
+ "version": "5.11.0",
4
4
  "description": "TODO: description",
5
5
  "repository": "https://github.com/shapeshift/lib",
6
6
  "license": "MIT",