@shapeshiftoss/swapper 9.15.1 → 9.16.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 +2 -2
- package/dist/swappers/cow/CowSwapper.js +4 -6
- package/dist/swappers/cow/cowApprovalNeeded/cowApprovalNeeded.js +1 -1
- package/dist/swappers/cow/{cowApproveInfinite/cowApproveInfinite.d.ts → cowApprove/cowApprove.d.ts} +2 -1
- package/dist/swappers/cow/{cowApproveInfinite/cowApproveInfinite.js → cowApprove/cowApprove.js} +26 -1
- package/dist/swappers/thorchain/thorTradeApprovalNeeded/thorTradeApprovalNeeded.js +1 -1
- package/dist/swappers/zrx/zrxApprovalNeeded/zrxApprovalNeeded.js +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { AssetId } from '@shapeshiftoss/caip';
|
|
|
3
3
|
import { ethereum } from '@shapeshiftoss/chain-adapters';
|
|
4
4
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
5
5
|
import Web3 from 'web3';
|
|
6
|
-
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
6
|
+
import { ApprovalNeededInput, ApprovalNeededOutput, ApproveAmountInput, ApproveInfiniteInput, BuildTradeInput, BuyAssetBySellIdInput, ExecuteTradeInput, GetTradeQuoteInput, Swapper, SwapperType, TradeQuote, TradeResult, TradeTxs } from '../../api';
|
|
7
7
|
import { CowTrade } from './types';
|
|
8
8
|
export declare type CowSwapperDeps = {
|
|
9
9
|
apiUrl: string;
|
|
@@ -21,7 +21,7 @@ export declare class CowSwapper implements Swapper<KnownChainIds.EthereumMainnet
|
|
|
21
21
|
executeTrade(args: ExecuteTradeInput<KnownChainIds.EthereumMainnet>): Promise<TradeResult>;
|
|
22
22
|
approvalNeeded(args: ApprovalNeededInput<KnownChainIds.EthereumMainnet>): Promise<ApprovalNeededOutput>;
|
|
23
23
|
approveInfinite(args: ApproveInfiniteInput<KnownChainIds.EthereumMainnet>): Promise<string>;
|
|
24
|
-
approveAmount(): Promise<string>;
|
|
24
|
+
approveAmount(args: ApproveAmountInput<KnownChainIds.EthereumMainnet>): Promise<string>;
|
|
25
25
|
filterBuyAssetsBySellAssetId(args: BuyAssetBySellIdInput): AssetId[];
|
|
26
26
|
filterAssetIdsBySellable(assetIds: AssetId[]): AssetId[];
|
|
27
27
|
getTradeTxs(args: TradeResult): Promise<TradeTxs>;
|
|
@@ -19,7 +19,7 @@ const caip_1 = require("@shapeshiftoss/caip");
|
|
|
19
19
|
const types_1 = require("@shapeshiftoss/types");
|
|
20
20
|
const api_1 = require("../../api");
|
|
21
21
|
const cowApprovalNeeded_1 = require("./cowApprovalNeeded/cowApprovalNeeded");
|
|
22
|
-
const
|
|
22
|
+
const cowApprove_1 = require("./cowApprove/cowApprove");
|
|
23
23
|
const cowBuildTrade_1 = require("./cowBuildTrade/cowBuildTrade");
|
|
24
24
|
const cowExecuteTrade_1 = require("./cowExecuteTrade/cowExecuteTrade");
|
|
25
25
|
const cowGetTradeTxs_1 = require("./cowGetTradeTxs/cowGetTradeTxs");
|
|
@@ -50,12 +50,10 @@ class CowSwapper {
|
|
|
50
50
|
return (0, cowApprovalNeeded_1.cowApprovalNeeded)(this.deps, args);
|
|
51
51
|
}
|
|
52
52
|
async approveInfinite(args) {
|
|
53
|
-
return (0,
|
|
53
|
+
return (0, cowApprove_1.cowApproveInfinite)(this.deps, args);
|
|
54
54
|
}
|
|
55
|
-
async approveAmount() {
|
|
56
|
-
|
|
57
|
-
code: api_1.SwapErrorTypes.RESPONSE_ERROR,
|
|
58
|
-
});
|
|
55
|
+
async approveAmount(args) {
|
|
56
|
+
return (0, cowApprove_1.cowApproveAmount)(this.deps, args);
|
|
59
57
|
}
|
|
60
58
|
filterBuyAssetsBySellAssetId(args) {
|
|
61
59
|
const { assetIds = [], sellAssetId } = args;
|
|
@@ -27,7 +27,7 @@ async function cowApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
27
27
|
});
|
|
28
28
|
const allowanceOnChain = (0, bignumber_1.bnOrZero)(allowanceResult);
|
|
29
29
|
return {
|
|
30
|
-
approvalNeeded: allowanceOnChain.
|
|
30
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
catch (e) {
|
package/dist/swappers/cow/{cowApproveInfinite/cowApproveInfinite.d.ts → cowApprove/cowApprove.d.ts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KnownChainIds } from '@shapeshiftoss/types';
|
|
2
|
-
import { ApproveInfiniteInput } from '../../../api';
|
|
2
|
+
import { ApproveAmountInput, ApproveInfiniteInput } from '../../../api';
|
|
3
3
|
import { CowSwapperDeps } from '../CowSwapper';
|
|
4
4
|
export declare function cowApproveInfinite({ adapter, web3 }: CowSwapperDeps, { quote, wallet }: ApproveInfiniteInput<KnownChainIds.EthereumMainnet>): Promise<string>;
|
|
5
|
+
export declare function cowApproveAmount({ adapter, web3 }: CowSwapperDeps, { quote, wallet, amount }: ApproveAmountInput<KnownChainIds.EthereumMainnet>): Promise<string>;
|
package/dist/swappers/cow/{cowApproveInfinite/cowApproveInfinite.js → cowApprove/cowApprove.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cowApproveInfinite = void 0;
|
|
3
|
+
exports.cowApproveAmount = 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");
|
|
@@ -29,3 +29,28 @@ async function cowApproveInfinite({ adapter, web3 }, { quote, wallet }) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
exports.cowApproveInfinite = cowApproveInfinite;
|
|
32
|
+
async function cowApproveAmount({ adapter, web3 }, { quote, wallet, amount }) {
|
|
33
|
+
try {
|
|
34
|
+
const approvalAmount = amount !== null && amount !== void 0 ? amount : quote.sellAmount;
|
|
35
|
+
const allowanceGrantRequired = await (0, helpers_1.grantAllowance)({
|
|
36
|
+
quote: {
|
|
37
|
+
...quote,
|
|
38
|
+
sellAmount: approvalAmount,
|
|
39
|
+
},
|
|
40
|
+
wallet,
|
|
41
|
+
adapter,
|
|
42
|
+
erc20Abi: erc20_abi_1.erc20Abi,
|
|
43
|
+
web3,
|
|
44
|
+
});
|
|
45
|
+
return allowanceGrantRequired;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (e instanceof api_1.SwapError)
|
|
49
|
+
throw e;
|
|
50
|
+
throw new api_1.SwapError('[cowApproveAmount]', {
|
|
51
|
+
cause: e,
|
|
52
|
+
code: api_1.SwapErrorTypes.APPROVE_AMOUNT_FAILED,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.cowApproveAmount = cowApproveAmount;
|
|
@@ -49,7 +49,7 @@ const thorTradeApprovalNeeded = async ({ deps, input, }) => {
|
|
|
49
49
|
details: { feeData: quote.feeData },
|
|
50
50
|
});
|
|
51
51
|
return {
|
|
52
|
-
approvalNeeded: allowanceOnChain.
|
|
52
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
@@ -44,7 +44,7 @@ async function zrxApprovalNeeded({ adapter, web3 }, { quote, wallet }) {
|
|
|
44
44
|
details: { feeData: quote.feeData },
|
|
45
45
|
});
|
|
46
46
|
return {
|
|
47
|
-
approvalNeeded: allowanceOnChain.
|
|
47
|
+
approvalNeeded: allowanceOnChain.lt((0, bignumber_1.bnOrZero)(quote.sellAmount)),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
catch (e) {
|
package/package.json
CHANGED