Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sdk/ca-base/abi/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,19 @@ const ERC20PermitEIP2612PolygonType = {
],
} as const;

const ETHEREUM_USDT_APPROVE_ABI = {
name: 'approve',
type: 'function',
stateMutability: 'nonpayable',
inputs: [
{ name: 'spender', type: 'address' },
{ name: 'value', type: 'uint256' },
],
outputs: [],
};

export {
ETHEREUM_USDT_APPROVE_ABI,
ERC20AllowanceABI,
ERC20PermitABI,
ERC20PermitEIP2612PolygonType,
Expand Down
18 changes: 16 additions & 2 deletions src/sdk/ca-base/swap/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ import {
getLogger,
type SBCTx,
type Source,
SUPPORTED_CHAINS,
type SuccessfulSwapResult,
SWAP_STEPS,
type SwapStepType,
TOKEN_CONTRACT_ADDRESSES,
type Tx,
type UnifiedBalanceResponseData,
type UserAssetDatum,
type VSCClient,
} from '../../../commons';
import { ERC20PermitABI, ERC20PermitEIP712Type, ERC20PermitEIP2612PolygonType } from '../abi/erc20';
import {
ERC20PermitABI,
ERC20PermitEIP712Type,
ERC20PermitEIP2612PolygonType,
ETHEREUM_USDT_APPROVE_ABI,
} from '../abi/erc20';
import { getLogoFromSymbol, ZERO_ADDRESS } from '../constants';
import { Errors } from '../errors';
import {
Expand Down Expand Up @@ -353,9 +360,15 @@ export const createPermitAndTransferFromTx = async ({
}

if (shouldUseDirectApproval) {
const abi = equalFold(
TOKEN_CONTRACT_ADDRESSES.USDT[SUPPORTED_CHAINS.ETHEREUM],
contractAddress
)
? [ETHEREUM_USDT_APPROVE_ABI]
: ERC20ABI;
const { request } = await publicClient.simulateContract({
chain,
abi: ERC20ABI,
abi,
account: owner,
address: contractAddress,
args: [spender, amount],
Expand Down Expand Up @@ -1612,4 +1625,5 @@ export const getSwapSupportedChains = (chainList: ChainListType) => {
logo: chain.custom.icon,
}));
};

export { sortSourcesByPriority, sortSourcesByPriorityWithAsset } from './sort';