@shapeshiftoss/swapper 9.3.0 → 9.4.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.
- package/dist/swappers/cow/CowSwapper.d.ts +0 -4
- package/dist/swappers/cow/CowSwapper.js +5 -3
- package/dist/swappers/cow/cowBuildTrade/cowBuildTrade.js +13 -5
- package/dist/swappers/cow/cowExecuteTrade/cowExecuteTrade.js +13 -5
- package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.js +5 -2
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +13 -5
- package/dist/swappers/cow/utils/constants.d.ts +1 -0
- package/dist/swappers/cow/utils/constants.js +4 -1
- package/dist/swappers/thorchain/ThorchainSwapper.d.ts +4 -2
- package/dist/swappers/thorchain/ThorchainSwapper.js +22 -8
- package/dist/swappers/thorchain/utils/constants.d.ts +5 -2
- package/dist/swappers/thorchain/utils/constants.js +17 -4
- package/dist/swappers/thorchain/utils/estimateTradeFee/estimateTradeFee.js +8 -43
- package/dist/swappers/thorchain/utils/makeSwapMemo/makeSwapMemo.js +2 -1
- package/package.json +1 -1
|
@@ -5,10 +5,6 @@ import { KnownChainIds } from '@shapeshiftoss/types';
|
|
|
5
5
|
import Web3 from 'web3';
|
|
6
6
|
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
7
7
|
import { CowTrade } from './types';
|
|
8
|
-
/**
|
|
9
|
-
* CowSwap only supports ERC-20 swaps, hence ETH is not supported
|
|
10
|
-
* In order to get rates correctly, we need WETH asset to be passed as feeAsset
|
|
11
|
-
*/
|
|
12
8
|
export declare type CowSwapperDeps = {
|
|
13
9
|
apiUrl: string;
|
|
14
10
|
adapter: ethereum.ChainAdapter;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CowSwapper = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
4
6
|
const api_1 = require("../../api");
|
|
5
7
|
const cowApprovalNeeded_1 = require("./cowApprovalNeeded/cowApprovalNeeded");
|
|
6
8
|
const cowApproveInfinite_1 = require("./cowApproveInfinite/cowApproveInfinite");
|
|
@@ -38,15 +40,15 @@ class CowSwapper {
|
|
|
38
40
|
}
|
|
39
41
|
filterBuyAssetsBySellAssetId(args) {
|
|
40
42
|
const { assetIds = [], sellAssetId } = args;
|
|
41
|
-
if (
|
|
43
|
+
if ((0, caip_1.fromAssetId)(sellAssetId).assetNamespace !== 'erc20' ||
|
|
42
44
|
blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(sellAssetId))
|
|
43
45
|
return [];
|
|
44
46
|
return assetIds.filter((id) => id !== sellAssetId &&
|
|
45
|
-
|
|
47
|
+
(0, caip_1.fromAssetId)(id).chainId === types_1.KnownChainIds.EthereumMainnet &&
|
|
46
48
|
!blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(id));
|
|
47
49
|
}
|
|
48
50
|
filterAssetIdsBySellable(assetIds) {
|
|
49
|
-
return assetIds.filter((id) => id.
|
|
51
|
+
return assetIds.filter((id) => (0, caip_1.fromAssetId)(id).assetNamespace === 'erc20' && !blacklist_1.COWSWAP_UNSUPPORTED_ASSETS.includes(id));
|
|
50
52
|
}
|
|
51
53
|
async getTradeTxs(args) {
|
|
52
54
|
return (0, cowGetTradeTxs_1.cowGetTradeTxs)(this.deps, args);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.cowBuildTrade = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
6
|
const api_1 = require("../../../api");
|
|
6
7
|
const erc20Allowance_abi_1 = require("../../utils/abi/erc20Allowance-abi");
|
|
7
8
|
const bignumber_1 = require("../../utils/bignumber");
|
|
@@ -14,13 +15,20 @@ async function cowBuildTrade(deps, input) {
|
|
|
14
15
|
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, wallet } = input;
|
|
15
16
|
const { adapter, web3 } = deps;
|
|
16
17
|
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
17
|
-
const { assetReference: buyAssetErc20Address,
|
|
18
|
-
if (
|
|
19
|
-
throw new api_1.SwapError('[cowBuildTrade] -
|
|
18
|
+
const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
19
|
+
if (sellAssetNamespace !== 'erc20') {
|
|
20
|
+
throw new api_1.SwapError('[cowBuildTrade] - Sell asset needs to be ERC-20 to use CowSwap', {
|
|
20
21
|
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
21
|
-
details: {
|
|
22
|
+
details: { sellAssetNamespace }
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
if (buyAssetChainId !== types_1.KnownChainIds.EthereumMainnet) {
|
|
26
|
+
throw new api_1.SwapError('[cowBuildTrade] - Buy asset needs to be on ETH mainnet to use CowSwap', {
|
|
27
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
28
|
+
details: { buyAssetChainId }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
|
|
24
32
|
const receiveAddress = await adapter.getAddress({ wallet });
|
|
25
33
|
const normalizedSellAmount = (0, helpers_1.normalizeAmount)(sellAmount);
|
|
26
34
|
/**
|
|
@@ -39,7 +47,7 @@ async function cowBuildTrade(deps, input) {
|
|
|
39
47
|
*/
|
|
40
48
|
const quoteResponse = await cowService_1.cowService.post(`${deps.apiUrl}/v1/quote/`, {
|
|
41
49
|
sellToken: sellAssetErc20Address,
|
|
42
|
-
buyToken
|
|
50
|
+
buyToken,
|
|
43
51
|
receiver: receiveAddress,
|
|
44
52
|
validTo: (0, helpers_2.getNowPlusThirtyMinutesTimestamp)(),
|
|
45
53
|
appData: constants_1.DEFAULT_APP_DATA,
|
|
@@ -4,6 +4,7 @@ exports.cowExecuteTrade = void 0;
|
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
6
6
|
const hdwallet_core_1 = require("@shapeshiftoss/hdwallet-core");
|
|
7
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
7
8
|
const ethers_1 = require("ethers");
|
|
8
9
|
const api_1 = require("../../../api");
|
|
9
10
|
const constants_1 = require("../utils/constants");
|
|
@@ -13,17 +14,24 @@ async function cowExecuteTrade({ apiUrl, adapter }, { trade, wallet }) {
|
|
|
13
14
|
const cowTrade = trade;
|
|
14
15
|
const { sellAsset, buyAsset, feeAmountInSellToken, sellAmountWithoutFee } = cowTrade;
|
|
15
16
|
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
16
|
-
const { assetReference: buyAssetErc20Address,
|
|
17
|
-
if (
|
|
18
|
-
throw new api_1.SwapError('[cowExecuteTrade] -
|
|
17
|
+
const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
18
|
+
if (sellAssetNamespace !== 'erc20') {
|
|
19
|
+
throw new api_1.SwapError('[cowExecuteTrade] - Sell asset needs to be ERC-20 to use CowSwap', {
|
|
19
20
|
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
20
|
-
details: {
|
|
21
|
+
details: { sellAssetNamespace }
|
|
21
22
|
});
|
|
22
23
|
}
|
|
24
|
+
if (buyAssetChainId !== types_1.KnownChainIds.EthereumMainnet) {
|
|
25
|
+
throw new api_1.SwapError('[cowExecuteTrade] - Buy asset needs to be on ETH mainnet to use CowSwap', {
|
|
26
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
27
|
+
details: { buyAssetChainId }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
|
|
23
31
|
try {
|
|
24
32
|
const orderToSign = {
|
|
25
33
|
sellToken: sellAssetErc20Address,
|
|
26
|
-
buyToken
|
|
34
|
+
buyToken,
|
|
27
35
|
sellAmount: sellAmountWithoutFee,
|
|
28
36
|
buyAmount: trade.buyAmount,
|
|
29
37
|
validTo: (0, helpers_1.getNowPlusThirtyMinutesTimestamp)(),
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCowSwapMinMax = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
4
6
|
const api_1 = require("../../../api");
|
|
5
7
|
const bignumber_1 = require("../../utils/bignumber");
|
|
6
8
|
const constants_1 = require("../utils/constants");
|
|
7
9
|
const helpers_1 = require("../utils/helpers/helpers");
|
|
8
10
|
const getCowSwapMinMax = async (deps, sellAsset, buyAsset) => {
|
|
9
11
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
const { assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
13
|
+
const { chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
14
|
+
if (sellAssetNamespace !== 'erc20' || buyAssetChainId !== types_1.KnownChainIds.EthereumMainnet) {
|
|
12
15
|
throw new api_1.SwapError('[getCowSwapMinMax]', { code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR });
|
|
13
16
|
}
|
|
14
17
|
const usdRate = await (0, helpers_1.getUsdRate)(deps, sellAsset);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCowSwapTradeQuote = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
6
|
const api_1 = require("../../../api");
|
|
6
7
|
const bignumber_1 = require("../../utils/bignumber");
|
|
7
8
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
@@ -14,20 +15,27 @@ async function getCowSwapTradeQuote(deps, input) {
|
|
|
14
15
|
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, wallet } = input;
|
|
15
16
|
const { adapter, web3 } = deps;
|
|
16
17
|
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
17
|
-
const { assetReference: buyAssetErc20Address,
|
|
18
|
-
if (
|
|
19
|
-
throw new api_1.SwapError('[getCowSwapTradeQuote] -
|
|
18
|
+
const { assetReference: buyAssetErc20Address, chainId: buyAssetChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
19
|
+
if (sellAssetNamespace !== 'erc20') {
|
|
20
|
+
throw new api_1.SwapError('[getCowSwapTradeQuote] - Sell asset needs to be ERC-20 to use CowSwap', {
|
|
20
21
|
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
21
|
-
details: {
|
|
22
|
+
details: { sellAssetNamespace }
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
if (buyAssetChainId !== types_1.KnownChainIds.EthereumMainnet) {
|
|
26
|
+
throw new api_1.SwapError('[getCowSwapTradeQuote] - Buy asset needs to be on ETH mainnet to use CowSwap', {
|
|
27
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
28
|
+
details: { buyAssetChainId }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const buyToken = buyAsset.assetId !== caip_1.ethAssetId ? buyAssetErc20Address : constants_1.COW_SWAP_ETH_MARKER_ADDRESS;
|
|
24
32
|
const { minimum, maximum } = await (0, getCowSwapMinMax_1.getCowSwapMinMax)(deps, sellAsset, buyAsset);
|
|
25
33
|
const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
|
|
26
34
|
// making sure we do not have decimals for cowswap api (can happen at least from minQuoteSellAmount)
|
|
27
35
|
const normalizedSellAmount = (0, helpers_1.normalizeIntegerAmount)((0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount) ? minQuoteSellAmount : sellAmount);
|
|
28
36
|
const apiInput = {
|
|
29
37
|
sellToken: sellAssetErc20Address,
|
|
30
|
-
buyToken
|
|
38
|
+
buyToken,
|
|
31
39
|
receiver: constants_1.DEFAULT_ADDRESS,
|
|
32
40
|
validTo: (0, helpers_2.getNowPlusThirtyMinutesTimestamp)(),
|
|
33
41
|
appData: constants_1.DEFAULT_APP_DATA,
|
|
@@ -15,3 +15,4 @@ export declare const ORDER_KIND_BUY = "buy";
|
|
|
15
15
|
export declare const SIGNING_SCHEME = "ethsign";
|
|
16
16
|
export declare const ERC20_TOKEN_BALANCE = "erc20";
|
|
17
17
|
export declare const ORDER_STATUS_FULFILLED = "fulfilled";
|
|
18
|
+
export declare const COW_SWAP_ETH_MARKER_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ORDER_STATUS_FULFILLED = exports.ERC20_TOKEN_BALANCE = exports.SIGNING_SCHEME = exports.ORDER_KIND_BUY = exports.ORDER_KIND_SELL = exports.WETH_ASSET_ID = exports.COW_SWAP_SETTLEMENT_ADDRESS = exports.COW_SWAP_VAULT_RELAYER_ADDRESS = exports.DEFAULT_APP_DATA = exports.DEFAULT_ADDRESS = exports.DEFAULT_SOURCE = exports.MIN_COWSWAP_VALUE_USD = exports.MAX_COWSWAP_TRADE = exports.MAX_ALLOWANCE = void 0;
|
|
3
|
+
exports.COW_SWAP_ETH_MARKER_ADDRESS = exports.ORDER_STATUS_FULFILLED = exports.ERC20_TOKEN_BALANCE = exports.SIGNING_SCHEME = exports.ORDER_KIND_BUY = exports.ORDER_KIND_SELL = exports.WETH_ASSET_ID = exports.COW_SWAP_SETTLEMENT_ADDRESS = exports.COW_SWAP_VAULT_RELAYER_ADDRESS = exports.DEFAULT_APP_DATA = exports.DEFAULT_ADDRESS = exports.DEFAULT_SOURCE = exports.MIN_COWSWAP_VALUE_USD = exports.MAX_COWSWAP_TRADE = exports.MAX_ALLOWANCE = void 0;
|
|
4
4
|
const constants_1 = require("@ethersproject/constants");
|
|
5
5
|
exports.MAX_ALLOWANCE = '100000000000000000000000000';
|
|
6
6
|
exports.MAX_COWSWAP_TRADE = '100000000000000000000000000';
|
|
@@ -16,3 +16,6 @@ exports.ORDER_KIND_BUY = 'buy';
|
|
|
16
16
|
exports.SIGNING_SCHEME = 'ethsign';
|
|
17
17
|
exports.ERC20_TOKEN_BALANCE = 'erc20';
|
|
18
18
|
exports.ORDER_STATUS_FULFILLED = 'fulfilled';
|
|
19
|
+
// Address used by CowSwap to buy ETH
|
|
20
|
+
// See https://github.com/gnosis/gp-v2-contracts/commit/821b5a8da213297b0f7f1d8b17c893c5627020af#diff-12bbbe13cd5cf42d639e34a39d8795021ba40d3ee1e1a8282df652eb161a11d6R13
|
|
21
|
+
exports.COW_SWAP_ETH_MARKER_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
@@ -5,8 +5,10 @@ import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildT
|
|
|
5
5
|
import { ThorchainSwapperDeps } from './types';
|
|
6
6
|
export declare class ThorchainSwapper implements Swapper<ChainId> {
|
|
7
7
|
readonly name = "Thorchain";
|
|
8
|
-
private
|
|
9
|
-
private
|
|
8
|
+
private sellSupportedChainIds;
|
|
9
|
+
private buySupportedChainIds;
|
|
10
|
+
private supportedSellAssetIds;
|
|
11
|
+
private supportedBuyAssetIds;
|
|
10
12
|
deps: ThorchainSwapperDeps;
|
|
11
13
|
constructor(deps: ThorchainSwapperDeps);
|
|
12
14
|
initialize(): Promise<void>;
|
|
@@ -13,24 +13,38 @@ const thorService_1 = require("./utils/thorService");
|
|
|
13
13
|
class ThorchainSwapper {
|
|
14
14
|
constructor(deps) {
|
|
15
15
|
this.name = 'Thorchain';
|
|
16
|
-
this.
|
|
16
|
+
this.sellSupportedChainIds = {
|
|
17
17
|
[types_1.KnownChainIds.EthereumMainnet]: true,
|
|
18
18
|
[types_1.KnownChainIds.BitcoinMainnet]: true
|
|
19
19
|
};
|
|
20
|
-
this.
|
|
20
|
+
this.buySupportedChainIds = {
|
|
21
|
+
[types_1.KnownChainIds.EthereumMainnet]: true,
|
|
22
|
+
[types_1.KnownChainIds.BitcoinMainnet]: true,
|
|
23
|
+
[types_1.KnownChainIds.DogecoinMainnet]: true,
|
|
24
|
+
[types_1.KnownChainIds.LitecoinMainnet]: true,
|
|
25
|
+
[types_1.KnownChainIds.CosmosMainnet]: true
|
|
26
|
+
};
|
|
27
|
+
this.supportedSellAssetIds = [];
|
|
28
|
+
this.supportedBuyAssetIds = [];
|
|
21
29
|
this.deps = deps;
|
|
22
30
|
}
|
|
23
31
|
async initialize() {
|
|
24
32
|
try {
|
|
25
33
|
const { data: responseData } = await thorService_1.thorService.get(`${this.deps.midgardUrl}/pools`);
|
|
26
|
-
|
|
34
|
+
this.supportedSellAssetIds = responseData.reduce((acc, midgardPool) => {
|
|
35
|
+
const assetId = caip_1.adapters.poolAssetIdToAssetId(midgardPool.asset);
|
|
36
|
+
if (!assetId || !this.sellSupportedChainIds[(0, caip_1.fromAssetId)(assetId).chainId])
|
|
37
|
+
return acc;
|
|
38
|
+
acc.push(assetId);
|
|
39
|
+
return acc;
|
|
40
|
+
}, []);
|
|
41
|
+
this.supportedBuyAssetIds = responseData.reduce((acc, midgardPool) => {
|
|
27
42
|
const assetId = caip_1.adapters.poolAssetIdToAssetId(midgardPool.asset);
|
|
28
|
-
if (!assetId || !this.
|
|
43
|
+
if (!assetId || !this.buySupportedChainIds[(0, caip_1.fromAssetId)(assetId).chainId])
|
|
29
44
|
return acc;
|
|
30
45
|
acc.push(assetId);
|
|
31
46
|
return acc;
|
|
32
47
|
}, []);
|
|
33
|
-
this.supportedAssetIds = supportedAssetIds;
|
|
34
48
|
}
|
|
35
49
|
catch (e) {
|
|
36
50
|
throw new api_1.SwapError('[thorchainInitialize]: initialize failed to set supportedAssetIds', {
|
|
@@ -53,12 +67,12 @@ class ThorchainSwapper {
|
|
|
53
67
|
}
|
|
54
68
|
filterBuyAssetsBySellAssetId(args) {
|
|
55
69
|
const { assetIds = [], sellAssetId } = args;
|
|
56
|
-
if (!this.
|
|
70
|
+
if (!this.supportedSellAssetIds.includes(sellAssetId))
|
|
57
71
|
return [];
|
|
58
|
-
return assetIds.filter((assetId) => this.
|
|
72
|
+
return assetIds.filter((assetId) => this.supportedBuyAssetIds.includes(assetId) && assetId !== sellAssetId);
|
|
59
73
|
}
|
|
60
74
|
filterAssetIdsBySellable() {
|
|
61
|
-
return this.
|
|
75
|
+
return this.supportedSellAssetIds;
|
|
62
76
|
}
|
|
63
77
|
async buildTrade(input) {
|
|
64
78
|
return (0, buildThorTrade_1.buildTrade)({ deps: this.deps, input });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { ChainId } from '@shapeshiftoss/caip';
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
1
3
|
export declare const MAX_THORCHAIN_TRADE = "100000000000000000000000000";
|
|
2
4
|
export declare const MAX_ALLOWANCE = "100000000000000000000000000";
|
|
3
5
|
export declare const THOR_MINIMUM_PADDING = 1.2;
|
|
4
6
|
export declare const THOR_ETH_GAS_LIMIT = "100000";
|
|
5
7
|
export declare const THORCHAIN_FIXED_PRECISION = 8;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const THORCHAIN_AFFILIATE_NAME = "ss";
|
|
9
|
+
export declare const THORCHAIN_AFFILIATE_BIPS = "0";
|
|
10
|
+
export declare const THOR_TRADE_FEE_MULTIPLIERS: Record<ChainId, BigNumber>;
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.THOR_TRADE_FEE_MULTIPLIERS = exports.THORCHAIN_AFFILIATE_BIPS = exports.THORCHAIN_AFFILIATE_NAME = exports.THORCHAIN_FIXED_PRECISION = exports.THOR_ETH_GAS_LIMIT = exports.THOR_MINIMUM_PADDING = exports.MAX_ALLOWANCE = exports.MAX_THORCHAIN_TRADE = void 0;
|
|
4
|
+
const types_1 = require("@shapeshiftoss/types");
|
|
5
|
+
const bignumber_1 = require("../../utils/bignumber");
|
|
4
6
|
exports.MAX_THORCHAIN_TRADE = '100000000000000000000000000';
|
|
5
7
|
exports.MAX_ALLOWANCE = '100000000000000000000000000';
|
|
6
8
|
exports.THOR_MINIMUM_PADDING = 1.2;
|
|
7
9
|
exports.THOR_ETH_GAS_LIMIT = '100000'; // for sends of eth / erc20 into thorchain router
|
|
8
10
|
exports.THORCHAIN_FIXED_PRECISION = 8; // limit values are precision 8 regardless of the chain
|
|
9
|
-
|
|
11
|
+
exports.THORCHAIN_AFFILIATE_NAME = 'ss';
|
|
12
|
+
exports.THORCHAIN_AFFILIATE_BIPS = '0'; // affiliate fee in basis points (100 = 1%)
|
|
10
13
|
// Used to estimate the fee thorchain will take out of the buyAsset
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
// Official docs on fees are incorrect
|
|
15
|
+
// https://discord.com/channels/838986635756044328/997675038675316776/998552541170253834
|
|
16
|
+
// This is still not "perfect" and tends to overestimate by a small randomish amount
|
|
17
|
+
// TODO figure out if its possible to accurately estimate the outbound fee.
|
|
18
|
+
// Neither the discord nor official docs are correct
|
|
19
|
+
exports.THOR_TRADE_FEE_MULTIPLIERS = {
|
|
20
|
+
[types_1.KnownChainIds.BitcoinMainnet]: (0, bignumber_1.bn)(0.00002),
|
|
21
|
+
[types_1.KnownChainIds.DogecoinMainnet]: (0, bignumber_1.bn)(0.00002),
|
|
22
|
+
[types_1.KnownChainIds.LitecoinMainnet]: (0, bignumber_1.bn)(0.000005),
|
|
23
|
+
[types_1.KnownChainIds.CosmosMainnet]: (0, bignumber_1.bn)(0.00000002),
|
|
24
|
+
[types_1.KnownChainIds.EthereumMainnet]: (0, bignumber_1.bn)(0.00024) // A value that "works". Discord recommended value (80,000 gas * 2 or 160k) is often too low
|
|
25
|
+
};
|
|
@@ -1,30 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.estimateTradeFee = void 0;
|
|
4
|
-
const asset_service_1 = require("@shapeshiftoss/asset-service");
|
|
5
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
6
5
|
const api_1 = require("../../../../api");
|
|
7
|
-
const bignumber_1 = require("../../../utils/bignumber");
|
|
8
6
|
const constants_1 = require("../constants");
|
|
9
7
|
const getPriceRatio_1 = require("../getPriceRatio/getPriceRatio");
|
|
10
8
|
const thorService_1 = require("../thorService");
|
|
11
|
-
const gweiGasPrecision = 9;
|
|
12
|
-
// Official docs on fees are incorrect
|
|
13
|
-
// https://discord.com/channels/838986635756044328/997675038675316776/998552541170253834
|
|
14
|
-
// This is still not "perfect" and tends to overestimate by a randomish amount
|
|
15
|
-
// TODO figure out if its possible to accurately estimate the outbound fee.
|
|
16
|
-
// Neither the discord nor official docs are correct
|
|
17
|
-
const ethEstimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate)
|
|
18
|
-
.times(constants_1.THOR_TRADE_FEE_ETH_GAS)
|
|
19
|
-
.times(2)
|
|
20
|
-
.times((0, bignumber_1.bn)(10).exponentiatedBy(gweiGasPrecision))
|
|
21
|
-
.toString();
|
|
22
|
-
const erc20Estimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate)
|
|
23
|
-
.times(constants_1.THOR_TRADE_FEE_ETH_GAS)
|
|
24
|
-
.times(2)
|
|
25
|
-
.times((0, bignumber_1.bn)(10).exponentiatedBy(gweiGasPrecision))
|
|
26
|
-
.toString();
|
|
27
|
-
const btcEstimate = (gasRate) => (0, bignumber_1.bnOrZero)(gasRate).times(constants_1.THOR_TRADE_FEE_BTC_SIZE).times(2).toString();
|
|
28
9
|
const estimateTradeFee = async (deps, buyAsset) => {
|
|
29
10
|
const thorId = caip_1.adapters.assetIdToPoolAssetId({ assetId: buyAsset.assetId });
|
|
30
11
|
if (!thorId)
|
|
@@ -41,7 +22,7 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
41
22
|
details: { thorPoolChainId }
|
|
42
23
|
});
|
|
43
24
|
const gasRate = inboundInfo.gas_rate;
|
|
44
|
-
const { chainId: buyChainId
|
|
25
|
+
const { chainId: buyChainId } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
45
26
|
const buyAdapter = deps.adapterManager.get(buyChainId);
|
|
46
27
|
if (!buyAdapter)
|
|
47
28
|
throw new api_1.SwapError('[estimateTradeFee] - unable to get buy asset adapter', {
|
|
@@ -54,33 +35,17 @@ const estimateTradeFee = async (deps, buyAsset) => {
|
|
|
54
35
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
55
36
|
details: { buyAssetId: buyAsset.assetId }
|
|
56
37
|
});
|
|
57
|
-
const
|
|
38
|
+
const buyFeeAssetRatio = buyAsset.assetId !== buyFeeAssetId
|
|
58
39
|
? await (0, getPriceRatio_1.getPriceRatio)(deps, {
|
|
59
40
|
sellAssetId: buyAsset.assetId,
|
|
60
41
|
buyAssetId: buyFeeAssetId
|
|
61
42
|
})
|
|
62
43
|
: '1';
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case 'slip44':
|
|
70
|
-
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(ethEstimate(gasRate)).times(feeAssetRatio).dp(0), buyFeeAsset.precision);
|
|
71
|
-
case 'erc20':
|
|
72
|
-
return (0, bignumber_1.fromBaseUnit)((0, bignumber_1.bnOrZero)(erc20Estimate(gasRate)).times(feeAssetRatio).dp(0), buyFeeAsset.precision);
|
|
73
|
-
default:
|
|
74
|
-
throw new api_1.SwapError('[estimateTradeFee] - unsupported asset namespace', {
|
|
75
|
-
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
76
|
-
details: { assetNamespace }
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
default:
|
|
80
|
-
throw new api_1.SwapError('[estimateTradeFee] - unsupported chain id', {
|
|
81
|
-
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
82
|
-
details: { chainId: buyChainId }
|
|
83
|
-
});
|
|
84
|
-
}
|
|
44
|
+
if (!constants_1.THOR_TRADE_FEE_MULTIPLIERS[buyChainId])
|
|
45
|
+
throw new api_1.SwapError('[estimateTradeFee] - no trade fee multiplier', {
|
|
46
|
+
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
47
|
+
details: { buyChainId }
|
|
48
|
+
});
|
|
49
|
+
return constants_1.THOR_TRADE_FEE_MULTIPLIERS[buyChainId].times(buyFeeAssetRatio).times(gasRate).toString();
|
|
85
50
|
};
|
|
86
51
|
exports.estimateTradeFee = estimateTradeFee;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makeSwapMemo = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../../api");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
6
7
|
// BTC (and likely other utxo coins) can only support up to 80 character memos
|
|
7
8
|
const MAX_LENGTH = 80;
|
|
8
9
|
/**
|
|
@@ -16,7 +17,7 @@ const makeSwapMemo = ({ buyAssetId, destinationAddress, limit }) => {
|
|
|
16
17
|
code: api_1.SwapErrorTypes.MAKE_MEMO_FAILED,
|
|
17
18
|
details: { buyAssetId }
|
|
18
19
|
});
|
|
19
|
-
const memo = `s:${thorId}:${destinationAddress}:${limit}`;
|
|
20
|
+
const memo = `s:${thorId}:${destinationAddress}:${limit}:${constants_1.THORCHAIN_AFFILIATE_NAME}:${constants_1.THORCHAIN_AFFILIATE_BIPS}`;
|
|
20
21
|
if (memo.length <= MAX_LENGTH)
|
|
21
22
|
return memo;
|
|
22
23
|
const abbreviationAmount = memo.length - MAX_LENGTH;
|
package/package.json
CHANGED