@shapeshiftoss/swapper 7.7.1 → 7.8.2
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 +5 -0
- package/dist/swappers/cow/CowSwapper.js +6 -6
- package/dist/swappers/cow/{CowApprovalNeeded/CowApprovalNeeded.d.ts → cowApprovalNeeded/cowApprovalNeeded.d.ts} +1 -1
- package/dist/swappers/cow/{CowApprovalNeeded/CowApprovalNeeded.js → cowApprovalNeeded/cowApprovalNeeded.js} +5 -5
- package/dist/swappers/cow/{CowApproveInfinite/CowApproveInfinite.d.ts → cowApproveInfinite/cowApproveInfinite.d.ts} +1 -1
- package/dist/swappers/{zrx/ZrxApproveInfinite/ZrxApproveInfinite.js → cow/cowApproveInfinite/cowApproveInfinite.js} +4 -4
- package/dist/swappers/cow/getCowSwapMinMax/getCowSwapMinMax.js +1 -1
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.d.ts +14 -0
- package/dist/swappers/cow/getCowSwapTradeQuote/getCowSwapTradeQuote.js +109 -0
- package/dist/swappers/cow/types.d.ts +16 -0
- package/dist/swappers/cow/utils/constants.d.ts +10 -0
- package/dist/swappers/cow/utils/constants.js +10 -1
- package/dist/swappers/cow/utils/helpers/helpers.d.ts +1 -1
- package/dist/swappers/cow/utils/helpers/helpers.js +3 -2
- package/dist/swappers/thorchain/thorTradeApproveInfinite/thorTradeApproveInfinite.js +1 -1
- package/dist/swappers/utils/helpers/helpers.d.ts +1 -0
- package/dist/swappers/utils/helpers/helpers.js +8 -1
- package/dist/swappers/utils/test-data/setupDeps.d.ts +1 -0
- package/dist/swappers/utils/test-data/setupDeps.js +2 -1
- package/dist/swappers/zrx/ZrxSwapper.js +4 -4
- package/dist/swappers/zrx/{ZrxApprovalNeeded/ZrxApprovalNeeded.d.ts → zrxApprovalNeeded/zrxApprovalNeeded.d.ts} +1 -1
- package/dist/swappers/zrx/{ZrxApprovalNeeded/ZrxApprovalNeeded.js → zrxApprovalNeeded/zrxApprovalNeeded.js} +7 -7
- package/dist/swappers/zrx/{ZrxApproveInfinite/ZrxApproveInfinite.d.ts → zrxApproveInfinite/zrxApproveInfinite.d.ts} +1 -1
- package/dist/swappers/{cow/CowApproveInfinite/CowApproveInfinite.js → zrx/zrxApproveInfinite/zrxApproveInfinite.js} +4 -4
- package/dist/swappers/zrx/zrxBuildTrade/zrxBuildTrade.js +2 -2
- package/package.json +14 -14
|
@@ -3,10 +3,15 @@ import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
|
3
3
|
import { Asset } from '@shapeshiftoss/types';
|
|
4
4
|
import Web3 from 'web3';
|
|
5
5
|
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, Trade, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
6
|
+
/**
|
|
7
|
+
* CowSwap only supports ERC-20 swaps, hence ETH is not supported
|
|
8
|
+
* In order to get rates correctly, we need WETH asset to be passed as feeAsset
|
|
9
|
+
*/
|
|
6
10
|
export declare type CowSwapperDeps = {
|
|
7
11
|
apiUrl: string;
|
|
8
12
|
adapter: ethereum.ChainAdapter;
|
|
9
13
|
web3: Web3;
|
|
14
|
+
feeAsset: Asset;
|
|
10
15
|
};
|
|
11
16
|
export declare class CowSwapper implements Swapper<'eip155:1'> {
|
|
12
17
|
static swapperName: string;
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CowSwapper = void 0;
|
|
4
4
|
const api_1 = require("../../api");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const cowApprovalNeeded_1 = require("./cowApprovalNeeded/cowApprovalNeeded");
|
|
6
|
+
const cowApproveInfinite_1 = require("./cowApproveInfinite/cowApproveInfinite");
|
|
7
|
+
const getCowSwapTradeQuote_1 = require("./getCowSwapTradeQuote/getCowSwapTradeQuote");
|
|
7
8
|
const blacklist_1 = require("./utils/blacklist");
|
|
8
9
|
const helpers_1 = require("./utils/helpers/helpers");
|
|
9
10
|
class CowSwapper {
|
|
@@ -20,8 +21,7 @@ class CowSwapper {
|
|
|
20
21
|
throw new Error('CowSwapper: buildTrade unimplemented');
|
|
21
22
|
}
|
|
22
23
|
async getTradeQuote(input) {
|
|
23
|
-
|
|
24
|
-
throw new Error('CowSwapper: getTradeQuote unimplemented');
|
|
24
|
+
return (0, getCowSwapTradeQuote_1.getCowSwapTradeQuote)(this.deps, input);
|
|
25
25
|
}
|
|
26
26
|
async getUsdRate(input) {
|
|
27
27
|
return (0, helpers_1.getUsdRate)(this.deps, input);
|
|
@@ -31,10 +31,10 @@ class CowSwapper {
|
|
|
31
31
|
throw new Error('CowSwapper: executeTrade unimplemented');
|
|
32
32
|
}
|
|
33
33
|
async approvalNeeded(args) {
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, cowApprovalNeeded_1.cowApprovalNeeded)(this.deps, args);
|
|
35
35
|
}
|
|
36
36
|
async approveInfinite(args) {
|
|
37
|
-
return (0,
|
|
37
|
+
return (0, cowApproveInfinite_1.cowApproveInfinite)(this.deps, args);
|
|
38
38
|
}
|
|
39
39
|
filterBuyAssetsBySellAssetId(args) {
|
|
40
40
|
const { assetIds = [], sellAssetId } = args;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
|
|
2
2
|
import { CowSwapperDeps } from '../CowSwapper';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function cowApprovalNeeded({ adapter, web3 }: CowSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.cowApprovalNeeded = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
6
|
const erc20Allowance_abi_1 = require("../../utils/abi/erc20Allowance-abi");
|
|
7
7
|
const bignumber_1 = require("../../utils/bignumber");
|
|
8
8
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
9
9
|
const COW_SWAP_VAULT_RELAYER_ADDRESS = '0xc92e8bdf79f0507f65a392b0ab4667716bfe0110';
|
|
10
|
-
async function
|
|
10
|
+
async function cowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
11
11
|
const { sellAsset } = quote;
|
|
12
12
|
const { assetReference: sellAssetErc20Address, assetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
13
13
|
try {
|
|
14
14
|
if (assetNamespace !== 'erc20') {
|
|
15
|
-
throw new api_1.SwapError('[
|
|
15
|
+
throw new api_1.SwapError('[cowApprovalNeeded] - unsupported asset namespace', {
|
|
16
16
|
code: api_1.SwapErrorTypes.UNSUPPORTED_NAMESPACE,
|
|
17
17
|
details: { assetNamespace }
|
|
18
18
|
});
|
|
@@ -33,10 +33,10 @@ async function CowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
33
33
|
catch (e) {
|
|
34
34
|
if (e instanceof api_1.SwapError)
|
|
35
35
|
throw e;
|
|
36
|
-
throw new api_1.SwapError('[
|
|
36
|
+
throw new api_1.SwapError('[cowApprovalNeeded]', {
|
|
37
37
|
cause: e,
|
|
38
38
|
code: api_1.SwapErrorTypes.CHECK_APPROVAL_FAILED
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
exports.
|
|
42
|
+
exports.cowApprovalNeeded = cowApprovalNeeded;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ApproveInfiniteInput } from '../../../api';
|
|
2
2
|
import { CowSwapperDeps } from '../CowSwapper';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function cowApproveInfinite({ adapter, web3 }: CowSwapperDeps, { quote, wallet }: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.cowApproveInfinite = void 0;
|
|
4
4
|
const api_1 = require("../../../api");
|
|
5
5
|
const erc20_abi_1 = require("../../utils/abi/erc20-abi");
|
|
6
6
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
7
7
|
const constants_1 = require("../utils/constants");
|
|
8
|
-
async function
|
|
8
|
+
async function cowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
9
9
|
try {
|
|
10
10
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
11
11
|
quote: {
|
|
@@ -22,10 +22,10 @@ async function ZrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
|
22
22
|
catch (e) {
|
|
23
23
|
if (e instanceof api_1.SwapError)
|
|
24
24
|
throw e;
|
|
25
|
-
throw new api_1.SwapError('[
|
|
25
|
+
throw new api_1.SwapError('[cowApproveInfinite]', {
|
|
26
26
|
cause: e,
|
|
27
27
|
code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
31
|
+
exports.cowApproveInfinite = cowApproveInfinite;
|
|
@@ -12,7 +12,7 @@ const getCowSwapMinMax = async (deps, sellAsset, buyAsset) => {
|
|
|
12
12
|
throw new api_1.SwapError('[getCowSwapMinMax]', { code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR });
|
|
13
13
|
}
|
|
14
14
|
const usdRate = await (0, helpers_1.getUsdRate)(deps, sellAsset);
|
|
15
|
-
const minimum = (0, bignumber_1.bn)(
|
|
15
|
+
const minimum = (0, bignumber_1.bn)(constants_1.MIN_COWSWAP_VALUE_USD).dividedBy((0, bignumber_1.bnOrZero)(usdRate)).toString(); // $10 worth of the sell token.
|
|
16
16
|
const maximum = constants_1.MAX_COWSWAP_TRADE; // Arbitrarily large value. 10e+28 here.
|
|
17
17
|
return {
|
|
18
18
|
minimum,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GetTradeQuoteInput, TradeQuote } from '../../../api';
|
|
2
|
+
import { CowSwapperDeps } from '../CowSwapper';
|
|
3
|
+
export declare type CowSwapQuoteApiInput = {
|
|
4
|
+
appData: string;
|
|
5
|
+
buyToken: string;
|
|
6
|
+
from: string;
|
|
7
|
+
kind: string;
|
|
8
|
+
partiallyFillable: boolean;
|
|
9
|
+
receiver: string;
|
|
10
|
+
sellAmountBeforeFee: string;
|
|
11
|
+
sellToken: string;
|
|
12
|
+
validTo: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function getCowSwapTradeQuote(deps: CowSwapperDeps, input: GetTradeQuoteInput): Promise<TradeQuote<'eip155:1'>>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCowSwapTradeQuote = void 0;
|
|
4
|
+
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
|
+
const api_1 = require("../../../api");
|
|
6
|
+
const bignumber_1 = require("../../utils/bignumber");
|
|
7
|
+
const constants_1 = require("../../utils/constants");
|
|
8
|
+
const helpers_1 = require("../../utils/helpers/helpers");
|
|
9
|
+
const getCowSwapMinMax_1 = require("../getCowSwapMinMax/getCowSwapMinMax");
|
|
10
|
+
const constants_2 = require("../utils/constants");
|
|
11
|
+
const cowService_1 = require("../utils/cowService");
|
|
12
|
+
const helpers_2 = require("../utils/helpers/helpers");
|
|
13
|
+
async function getCowSwapTradeQuote(deps, input) {
|
|
14
|
+
try {
|
|
15
|
+
const { sellAsset, buyAsset, sellAmount, sellAssetAccountNumber, wallet } = input;
|
|
16
|
+
const { adapter, feeAsset } = deps;
|
|
17
|
+
const { assetReference: sellAssetErc20Address, assetNamespace: sellAssetNamespace } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
18
|
+
const { assetReference: buyAssetErc20Address, assetNamespace: buyAssetNamespace } = (0, caip_1.fromAssetId)(buyAsset.assetId);
|
|
19
|
+
if (buyAssetNamespace !== 'erc20' || sellAssetNamespace !== 'erc20') {
|
|
20
|
+
throw new api_1.SwapError('[getCowSwapTradeQuote] - Both assets need to be ERC-20 to use CowSwap', {
|
|
21
|
+
code: api_1.SwapErrorTypes.UNSUPPORTED_PAIR,
|
|
22
|
+
details: { buyAssetNamespace, sellAssetNamespace }
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const { minimum, maximum } = await (0, getCowSwapMinMax_1.getCowSwapMinMax)(deps, sellAsset, buyAsset);
|
|
26
|
+
const minQuoteSellAmount = (0, bignumber_1.bnOrZero)(minimum).times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision));
|
|
27
|
+
// making sure we do not have decimals for cowswap api (can happen at least from minQuoteSellAmount)
|
|
28
|
+
const normalizedSellAmount = (0, helpers_1.normalizeIntegerAmount)((0, bignumber_1.bnOrZero)(sellAmount).lt(minQuoteSellAmount) ? minQuoteSellAmount : sellAmount);
|
|
29
|
+
const apiInput = {
|
|
30
|
+
sellToken: sellAssetErc20Address,
|
|
31
|
+
buyToken: buyAssetErc20Address,
|
|
32
|
+
receiver: constants_2.DEFAULT_ADDRESS,
|
|
33
|
+
validTo: constants_2.DEFAULT_VALIDTO_TIMESTAMP,
|
|
34
|
+
appData: constants_2.DEFAULT_APP_DATA,
|
|
35
|
+
partiallyFillable: false,
|
|
36
|
+
from: constants_2.DEFAULT_ADDRESS,
|
|
37
|
+
kind: constants_2.ORDER_KIND_SELL,
|
|
38
|
+
sellAmountBeforeFee: normalizedSellAmount
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* /v1/quote
|
|
42
|
+
* params: {
|
|
43
|
+
* sellToken: contract address of token to sell
|
|
44
|
+
* buyToken: contractAddress of token to buy
|
|
45
|
+
* receiver: receiver address can be defaulted to "0x0000000000000000000000000000000000000000"
|
|
46
|
+
* validTo: time duration during which quote is valid (eg : 1654851610 as timestamp)
|
|
47
|
+
* appData: appData for the CowSwap quote that can be used later, can be defaulted to "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
48
|
+
* partiallyFillable: false
|
|
49
|
+
* from: sender address can be defaulted to "0x0000000000000000000000000000000000000000"
|
|
50
|
+
* kind: "sell" or "buy"
|
|
51
|
+
* sellAmountBeforeFee / buyAmountAfterFee: amount in base unit
|
|
52
|
+
* }
|
|
53
|
+
*/
|
|
54
|
+
const quoteResponse = await cowService_1.cowService.post(`${deps.apiUrl}/v1/quote/`, apiInput);
|
|
55
|
+
const { data: { quote } } = quoteResponse;
|
|
56
|
+
const rate = (0, bignumber_1.bn)(quote.buyAmount)
|
|
57
|
+
.div(quote.sellAmount)
|
|
58
|
+
.times((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision - buyAsset.precision))
|
|
59
|
+
.toString();
|
|
60
|
+
const receiveAddress = wallet ? await adapter.getAddress({ wallet }) : constants_2.DEFAULT_ADDRESS;
|
|
61
|
+
const [feeDataOptions, wethUsdRate, usdRateSellAsset] = await Promise.all([
|
|
62
|
+
adapter.getFeeData({
|
|
63
|
+
to: constants_2.COW_SWAP_VAULT_RELAYER_ADDRESS,
|
|
64
|
+
value: '0',
|
|
65
|
+
chainSpecific: { from: receiveAddress, contractAddress: sellAssetErc20Address }
|
|
66
|
+
}),
|
|
67
|
+
(0, helpers_2.getUsdRate)(deps, feeAsset),
|
|
68
|
+
(0, helpers_2.getUsdRate)(deps, sellAsset)
|
|
69
|
+
]);
|
|
70
|
+
const feeData = feeDataOptions['fast'];
|
|
71
|
+
const fee = (0, bignumber_1.bnOrZero)(quote.feeAmount)
|
|
72
|
+
.multipliedBy((0, bignumber_1.bnOrZero)(usdRateSellAsset))
|
|
73
|
+
.div((0, bignumber_1.bnOrZero)(wethUsdRate))
|
|
74
|
+
.div((0, bignumber_1.bn)(10).exponentiatedBy(sellAsset.precision - feeAsset.precision))
|
|
75
|
+
.toString();
|
|
76
|
+
return {
|
|
77
|
+
rate,
|
|
78
|
+
minimum,
|
|
79
|
+
maximum,
|
|
80
|
+
feeData: {
|
|
81
|
+
fee,
|
|
82
|
+
chainSpecific: {
|
|
83
|
+
estimatedGas: feeData.chainSpecific.gasLimit,
|
|
84
|
+
gasPrice: feeData.chainSpecific.gasPrice,
|
|
85
|
+
approvalFee: (0, bignumber_1.bnOrZero)(constants_1.APPROVAL_GAS_LIMIT)
|
|
86
|
+
.multipliedBy((0, bignumber_1.bnOrZero)(feeData.chainSpecific.gasPrice))
|
|
87
|
+
.toString()
|
|
88
|
+
},
|
|
89
|
+
tradeFee: '0'
|
|
90
|
+
},
|
|
91
|
+
sellAmount: quote.sellAmount,
|
|
92
|
+
buyAmount: quote.buyAmount,
|
|
93
|
+
sources: constants_2.DEFAULT_SOURCE,
|
|
94
|
+
allowanceContract: '',
|
|
95
|
+
buyAsset,
|
|
96
|
+
sellAsset,
|
|
97
|
+
sellAssetAccountNumber
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
if (e instanceof api_1.SwapError)
|
|
102
|
+
throw e;
|
|
103
|
+
throw new api_1.SwapError('[getCowSwapTradeQuote]', {
|
|
104
|
+
cause: e,
|
|
105
|
+
code: api_1.SwapErrorTypes.TRADE_QUOTE_FAILED
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.getCowSwapTradeQuote = getCowSwapTradeQuote;
|
|
@@ -2,3 +2,19 @@ export declare type CowSwapPriceResponse = {
|
|
|
2
2
|
amount: string;
|
|
3
3
|
token: string;
|
|
4
4
|
};
|
|
5
|
+
export declare type CowSwapQuoteResponse = {
|
|
6
|
+
quote: {
|
|
7
|
+
sellToken: string;
|
|
8
|
+
buyToken: string;
|
|
9
|
+
receiver: string;
|
|
10
|
+
sellAmount: string;
|
|
11
|
+
buyAmount: string;
|
|
12
|
+
validTo: number;
|
|
13
|
+
appData: string;
|
|
14
|
+
feeAmount: string;
|
|
15
|
+
kind: string;
|
|
16
|
+
partiallyFillable: boolean;
|
|
17
|
+
};
|
|
18
|
+
from: string;
|
|
19
|
+
expiration: string;
|
|
20
|
+
};
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
export declare const MAX_ALLOWANCE = "100000000000000000000000000";
|
|
2
2
|
export declare const MAX_COWSWAP_TRADE = "100000000000000000000000000";
|
|
3
|
+
export declare const MIN_COWSWAP_VALUE_USD = 10;
|
|
4
|
+
export declare const DEFAULT_SOURCE: {
|
|
5
|
+
name: string;
|
|
6
|
+
proportion: string;
|
|
7
|
+
}[];
|
|
8
|
+
export declare const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
9
|
+
export declare const DEFAULT_APP_DATA = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
10
|
+
export declare const COW_SWAP_VAULT_RELAYER_ADDRESS = "0xc92e8bdf79f0507f65a392b0ab4667716bfe0110";
|
|
11
|
+
export declare const DEFAULT_VALIDTO_TIMESTAMP = 4294967295;
|
|
12
|
+
export declare const ORDER_KIND_SELL = "sell";
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_COWSWAP_TRADE = void 0;
|
|
3
|
+
exports.ORDER_KIND_SELL = exports.DEFAULT_VALIDTO_TIMESTAMP = 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 = void 0;
|
|
4
4
|
exports.MAX_COWSWAP_TRADE = '100000000000000000000000000';
|
|
5
|
+
exports.MIN_COWSWAP_VALUE_USD = 10;
|
|
6
|
+
exports.DEFAULT_SOURCE = [{ name: 'CowSwap', proportion: '1' }];
|
|
7
|
+
exports.DEFAULT_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
8
|
+
exports.DEFAULT_APP_DATA = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
9
|
+
exports.COW_SWAP_VAULT_RELAYER_ADDRESS = '0xc92e8bdf79f0507f65a392b0ab4667716bfe0110';
|
|
10
|
+
// CowSwap API requires validTo field which specifies a limit date for the order to be valid
|
|
11
|
+
// This is the default value being used by CowSwap exchange, corresponding to a date in year 2106
|
|
12
|
+
exports.DEFAULT_VALIDTO_TIMESTAMP = 4294967295;
|
|
13
|
+
exports.ORDER_KIND_SELL = 'sell';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Asset } from '@shapeshiftoss/types';
|
|
2
2
|
import { CowSwapperDeps } from '../../CowSwapper';
|
|
3
|
-
export declare const getUsdRate: ({ apiUrl }: CowSwapperDeps, input: Asset) => Promise<string>;
|
|
3
|
+
export declare const getUsdRate: ({ apiUrl, feeAsset }: CowSwapperDeps, input: Asset) => Promise<string>;
|
|
@@ -7,8 +7,9 @@ const bignumber_1 = require("../../../utils/bignumber");
|
|
|
7
7
|
const cowService_1 = require("../cowService");
|
|
8
8
|
const USDC_CONTRACT_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
|
|
9
9
|
const USDC_ASSET_PRECISION = 6;
|
|
10
|
-
const getUsdRate = async ({ apiUrl }, input) => {
|
|
11
|
-
|
|
10
|
+
const getUsdRate = async ({ apiUrl, feeAsset }, input) => {
|
|
11
|
+
// Replacing ETH by WETH specifically for CowSwap in order to get an usd rate when called with ETH as feeAsset
|
|
12
|
+
const asset = input.assetId !== caip_1.ethAssetId ? input : feeAsset;
|
|
12
13
|
const { assetReference: erc20Address, assetNamespace } = (0, caip_1.fromAssetId)(asset.assetId);
|
|
13
14
|
if (assetNamespace !== 'erc20') {
|
|
14
15
|
throw new api_1.SwapError('[getUsdRate] - unsupported asset namespace', {
|
|
@@ -32,7 +32,7 @@ const thorTradeApproveInfinite = async ({ deps, input }) => {
|
|
|
32
32
|
catch (e) {
|
|
33
33
|
if (e instanceof api_1.SwapError)
|
|
34
34
|
throw e;
|
|
35
|
-
throw new api_1.SwapError('[
|
|
35
|
+
throw new api_1.SwapError('[zrxApproveInfinite]', {
|
|
36
36
|
cause: e,
|
|
37
37
|
code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
|
|
38
38
|
});
|
|
@@ -37,4 +37,5 @@ export declare const grantAllowance: ({ quote, wallet, adapter, erc20Abi, web3 }
|
|
|
37
37
|
* @param amount
|
|
38
38
|
*/
|
|
39
39
|
export declare const normalizeAmount: (amount: string | number | BN) => string;
|
|
40
|
+
export declare const normalizeIntegerAmount: (amount: string | number | BN) => string;
|
|
40
41
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeAmount = exports.grantAllowance = exports.getAllowanceRequired = exports.getERC20Allowance = void 0;
|
|
3
|
+
exports.normalizeIntegerAmount = exports.normalizeAmount = exports.grantAllowance = exports.getAllowanceRequired = exports.getERC20Allowance = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const web3_utils_1 = require("web3-utils");
|
|
6
6
|
const api_1 = require("../../../api");
|
|
@@ -108,3 +108,10 @@ const normalizeAmount = (amount) => {
|
|
|
108
108
|
return (0, bignumber_1.bnOrZero)(amount).toNumber().toLocaleString('fullwide', { useGrouping: false });
|
|
109
109
|
};
|
|
110
110
|
exports.normalizeAmount = normalizeAmount;
|
|
111
|
+
const normalizeIntegerAmount = (amount) => {
|
|
112
|
+
return (0, bignumber_1.bnOrZero)(amount)
|
|
113
|
+
.integerValue()
|
|
114
|
+
.toNumber()
|
|
115
|
+
.toLocaleString('fullwide', { useGrouping: false });
|
|
116
|
+
};
|
|
117
|
+
exports.normalizeIntegerAmount = normalizeIntegerAmount;
|
|
@@ -30,6 +30,7 @@ exports.setupDeps = void 0;
|
|
|
30
30
|
const chain_adapters_1 = require("@shapeshiftoss/chain-adapters");
|
|
31
31
|
const unchained = __importStar(require("@shapeshiftoss/unchained-client"));
|
|
32
32
|
const web3_1 = __importDefault(require("web3"));
|
|
33
|
+
const assets_1 = require("./assets");
|
|
33
34
|
jest.mock('@shapeshiftoss/chain-adapters');
|
|
34
35
|
jest.mock('web3');
|
|
35
36
|
const setupDeps = () => {
|
|
@@ -44,6 +45,6 @@ const setupDeps = () => {
|
|
|
44
45
|
});
|
|
45
46
|
const ethNodeUrl = 'http://localhost:1000';
|
|
46
47
|
const web3Provider = new web3_1.default.providers.HttpProvider(ethNodeUrl);
|
|
47
|
-
return { web3: new web3_1.default(web3Provider), adapter: ethChainAdapter };
|
|
48
|
+
return { web3: new web3_1.default(web3Provider), adapter: ethChainAdapter, feeAsset: assets_1.WETH };
|
|
48
49
|
};
|
|
49
50
|
exports.setupDeps = setupDeps;
|
|
@@ -5,8 +5,8 @@ const api_1 = require("../../api");
|
|
|
5
5
|
const getZrxTradeQuote_1 = require("./getZrxTradeQuote/getZrxTradeQuote");
|
|
6
6
|
const blacklist_1 = require("./utils/blacklist");
|
|
7
7
|
const helpers_1 = require("./utils/helpers/helpers");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const zrxApprovalNeeded_1 = require("./zrxApprovalNeeded/zrxApprovalNeeded");
|
|
9
|
+
const zrxApproveInfinite_1 = require("./zrxApproveInfinite/zrxApproveInfinite");
|
|
10
10
|
const zrxBuildTrade_1 = require("./zrxBuildTrade/zrxBuildTrade");
|
|
11
11
|
const zrxExecuteTrade_1 = require("./zrxExecuteTrade/zrxExecuteTrade");
|
|
12
12
|
class ZrxSwapper {
|
|
@@ -32,10 +32,10 @@ class ZrxSwapper {
|
|
|
32
32
|
return (0, zrxExecuteTrade_1.zrxExecuteTrade)(this.deps, args);
|
|
33
33
|
}
|
|
34
34
|
async approvalNeeded(args) {
|
|
35
|
-
return (0,
|
|
35
|
+
return (0, zrxApprovalNeeded_1.zrxApprovalNeeded)(this.deps, args);
|
|
36
36
|
}
|
|
37
37
|
async approveInfinite(args) {
|
|
38
|
-
return (0,
|
|
38
|
+
return (0, zrxApproveInfinite_1.zrxApproveInfinite)(this.deps, args);
|
|
39
39
|
}
|
|
40
40
|
filterBuyAssetsBySellAssetId(args) {
|
|
41
41
|
const { assetIds = [], sellAssetId } = args;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ApprovalNeededInput, ApprovalNeededOutput } from '../../../api';
|
|
2
2
|
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function zrxApprovalNeeded({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApprovalNeededInput<'eip155:1'>): Promise<ApprovalNeededOutput>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.zrxApprovalNeeded = void 0;
|
|
4
4
|
const caip_1 = require("@shapeshiftoss/caip");
|
|
5
5
|
const api_1 = require("../../../api");
|
|
6
6
|
const erc20Allowance_abi_1 = require("../../utils/abi/erc20Allowance-abi");
|
|
7
7
|
const bignumber_1 = require("../../utils/bignumber");
|
|
8
8
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
9
|
-
async function
|
|
9
|
+
async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
10
10
|
var _a;
|
|
11
11
|
const { sellAsset } = quote;
|
|
12
12
|
const { assetReference: sellAssetErc20Address } = (0, caip_1.fromAssetId)(sellAsset.assetId);
|
|
13
13
|
try {
|
|
14
14
|
if (sellAsset.chainId !== 'eip155:1') {
|
|
15
|
-
throw new api_1.SwapError('[
|
|
15
|
+
throw new api_1.SwapError('[zrxApprovalNeeded] - sellAsset chainId is not supported', {
|
|
16
16
|
code: api_1.SwapErrorTypes.UNSUPPORTED_CHAIN,
|
|
17
17
|
details: { chainId: sellAsset.chainId }
|
|
18
18
|
});
|
|
@@ -25,7 +25,7 @@ async function ZrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
25
25
|
const bip44Params = adapter.buildBIP44Params({ accountNumber });
|
|
26
26
|
const receiveAddress = await adapter.getAddress({ wallet, bip44Params });
|
|
27
27
|
if (!quote.allowanceContract) {
|
|
28
|
-
throw new api_1.SwapError('[
|
|
28
|
+
throw new api_1.SwapError('[zrxApprovalNeeded] - allowanceTarget is required', {
|
|
29
29
|
code: api_1.SwapErrorTypes.VALIDATION_FAILED,
|
|
30
30
|
details: { chainId: sellAsset.chainId }
|
|
31
31
|
});
|
|
@@ -39,7 +39,7 @@ async function ZrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
39
39
|
});
|
|
40
40
|
const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
|
|
41
41
|
if (!((_a = quote.feeData.chainSpecific) === null || _a === void 0 ? void 0 : _a.gasPrice))
|
|
42
|
-
throw new api_1.SwapError('[
|
|
42
|
+
throw new api_1.SwapError('[zrxApprovalNeeded] - no gas price with quote', {
|
|
43
43
|
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
44
44
|
details: { feeData: quote.feeData }
|
|
45
45
|
});
|
|
@@ -50,10 +50,10 @@ async function ZrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
50
50
|
catch (e) {
|
|
51
51
|
if (e instanceof api_1.SwapError)
|
|
52
52
|
throw e;
|
|
53
|
-
throw new api_1.SwapError('[
|
|
53
|
+
throw new api_1.SwapError('[zrxApprovalNeeded]', {
|
|
54
54
|
cause: e,
|
|
55
55
|
code: api_1.SwapErrorTypes.CHECK_APPROVAL_FAILED
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
exports.
|
|
59
|
+
exports.zrxApprovalNeeded = zrxApprovalNeeded;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ApproveInfiniteInput } from '../../../api';
|
|
2
2
|
import { ZrxSwapperDeps } from '../ZrxSwapper';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function zrxApproveInfinite({ adapter, web3 }: ZrxSwapperDeps, { quote, wallet }: ApproveInfiniteInput<'eip155:1'>): Promise<string>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.zrxApproveInfinite = void 0;
|
|
4
4
|
const api_1 = require("../../../api");
|
|
5
5
|
const erc20_abi_1 = require("../../utils/abi/erc20-abi");
|
|
6
6
|
const helpers_1 = require("../../utils/helpers/helpers");
|
|
7
7
|
const constants_1 = require("../utils/constants");
|
|
8
|
-
async function
|
|
8
|
+
async function zrxApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
9
9
|
try {
|
|
10
10
|
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
11
11
|
quote: {
|
|
@@ -22,10 +22,10 @@ async function CowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
|
22
22
|
catch (e) {
|
|
23
23
|
if (e instanceof api_1.SwapError)
|
|
24
24
|
throw e;
|
|
25
|
-
throw new api_1.SwapError('[
|
|
25
|
+
throw new api_1.SwapError('[zrxApproveInfinite]', {
|
|
26
26
|
cause: e,
|
|
27
27
|
code: api_1.SwapErrorTypes.APPROVE_INFINITE_FAILED
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
31
|
+
exports.zrxApproveInfinite = zrxApproveInfinite;
|
|
@@ -44,7 +44,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
|
|
|
44
44
|
const buyToken = buyAssetNamespace === 'erc20' ? buyAssetErc20Address : buyAsset.symbol;
|
|
45
45
|
const sellToken = sellAssetNamespace === 'erc20' ? sellAssetErc20Address : sellAsset.symbol;
|
|
46
46
|
if (buyAsset.chainId !== 'eip155:1') {
|
|
47
|
-
throw new __1.SwapError('[
|
|
47
|
+
throw new __1.SwapError('[zrxBuildTrade] - buyAsset must be on chainId eip155:1', {
|
|
48
48
|
code: __1.SwapErrorTypes.VALIDATION_FAILED,
|
|
49
49
|
details: { chainId: sellAsset.chainId }
|
|
50
50
|
});
|
|
@@ -133,7 +133,7 @@ async function zrxBuildTrade({ adapter, web3 }, input) {
|
|
|
133
133
|
catch (e) {
|
|
134
134
|
if (e instanceof __1.SwapError)
|
|
135
135
|
throw e;
|
|
136
|
-
throw new __1.SwapError('[
|
|
136
|
+
throw new __1.SwapError('[zrxBuildTrade]', {
|
|
137
137
|
code: __1.SwapErrorTypes.BUILD_TRADE_FAILED
|
|
138
138
|
});
|
|
139
139
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swapper",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.2",
|
|
4
4
|
"description": "An interface and implementations to trade coins via various protocols",
|
|
5
5
|
"repository": "https://github.com/shapeshift/lib",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,26 +27,26 @@
|
|
|
27
27
|
"bignumber.js": "^9.0.2",
|
|
28
28
|
"lodash": "^4.17.21",
|
|
29
29
|
"retry-axios": "^2.6.0",
|
|
30
|
-
"web3": "
|
|
30
|
+
"web3": "1.7.4"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@shapeshiftoss/asset-service": "^
|
|
34
|
-
"@shapeshiftoss/caip": "^6.0
|
|
35
|
-
"@shapeshiftoss/chain-adapters": "^7.0
|
|
36
|
-
"@shapeshiftoss/errors": "^1.1.
|
|
33
|
+
"@shapeshiftoss/asset-service": "^6.2.1",
|
|
34
|
+
"@shapeshiftoss/caip": "^6.2.0",
|
|
35
|
+
"@shapeshiftoss/chain-adapters": "^7.2.0",
|
|
36
|
+
"@shapeshiftoss/errors": "^1.1.2",
|
|
37
37
|
"@shapeshiftoss/hdwallet-core": "^1.23.0",
|
|
38
|
-
"@shapeshiftoss/types": "^
|
|
38
|
+
"@shapeshiftoss/types": "^6.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@shapeshiftoss/asset-service": "^
|
|
42
|
-
"@shapeshiftoss/caip": "^6.0
|
|
43
|
-
"@shapeshiftoss/chain-adapters": "^7.0
|
|
44
|
-
"@shapeshiftoss/errors": "^1.1.
|
|
41
|
+
"@shapeshiftoss/asset-service": "^6.2.1",
|
|
42
|
+
"@shapeshiftoss/caip": "^6.2.0",
|
|
43
|
+
"@shapeshiftoss/chain-adapters": "^7.2.0",
|
|
44
|
+
"@shapeshiftoss/errors": "^1.1.2",
|
|
45
45
|
"@shapeshiftoss/hdwallet-core": "^1.23.0",
|
|
46
|
-
"@shapeshiftoss/types": "^
|
|
46
|
+
"@shapeshiftoss/types": "^6.2.0",
|
|
47
47
|
"@types/readline-sync": "^1.4.4",
|
|
48
48
|
"readline-sync": "^1.4.10",
|
|
49
|
-
"web3-utils": "
|
|
50
|
-
"@shapeshiftoss/unchained-client": "^9.0.
|
|
49
|
+
"web3-utils": "1.7.4",
|
|
50
|
+
"@shapeshiftoss/unchained-client": "^9.0.1"
|
|
51
51
|
}
|
|
52
52
|
}
|