Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update otc for v4 compatibility #945

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/features/orders/ordersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ export const approve =
approveAmount
);

if (isAppError(tx)) {
const appError = tx;
dispatch(setErrors([appError]));

if (appError.error && "message" in appError.error) {
dispatch(declineTransaction(appError.error.message));
}

dispatch(setStatus("failed"));
piersss marked this conversation as resolved.
Show resolved Hide resolved

return;
}

if (!tx.hash) {
console.error("Approval transaction hash is missing.");

Expand Down
34 changes: 20 additions & 14 deletions src/features/orders/ordersHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,25 @@ export async function approveToken(
provider: ethers.providers.Web3Provider,
contractType: "Swap" | "Wrapper",
amount: string | number
) {
const spender =
contractType === "Swap"
? getSwapErc20Address(provider.network.chainId)
: Wrapper.getAddress(provider.network.chainId);
const erc20Contract = new ethers.Contract(
baseToken,
erc20Interface,
// @ts-ignore
provider.getSigner()
);
const approvalTxHash = await erc20Contract.approve(spender, amount);
return approvalTxHash as any as Transaction;
): Promise<Transaction | AppError> {
return new Promise<Transaction | AppError>(async (resolve) => {
try {
const spender =
contractType === "Swap"
? getSwapErc20Address(provider.network.chainId)
: Wrapper.getAddress(provider.network.chainId);
const erc20Contract = new ethers.Contract(
baseToken,
erc20Interface,
// @ts-ignore
provider.getSigner()
);
const approvalTxHash = erc20Contract.approve(spender, amount);
resolve(approvalTxHash);
} catch (error: any) {
resolve(transformUnknownErrorToAppError(error));
}
});
}

export async function takeOrder(
Expand Down Expand Up @@ -203,7 +209,7 @@ export async function check(
provider: ethers.providers.Web3Provider,
isSwapWithWrap?: boolean
): Promise<AppError[]> {
const strings = await (
const [count, strings] = await (
piersss marked this conversation as resolved.
Show resolved Hide resolved
await getSwapErc20Contract(provider, chainId)
).check(senderWallet, ...orderERC20ToParams(order));

Expand Down
6 changes: 6 additions & 0 deletions src/features/transactions/hooks/useLatestSwapFromEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const useLatestSwapFromEvents = (
const handleSwapEvent = async (
nonce: BigNumber,
signerAddress: string,
a: string,
b: number,
c: number,
d: string,
e: string,
f: number,
swapEvent: Event
) => {
const receipt = await swapEvent.getTransactionReceipt();
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/createSwapSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { JsonRpcSigner } from "@ethersproject/providers/src.ts/json-rpc-provider
import { AppError } from "../errors/appError";
import transformUnknownErrorToAppError from "../errors/transformUnknownErrorToAppError";

const SWAP_ERC20_VERSION = "4";

export const createOrderERC20Signature = (
unsignedOrder: UnsignedOrderERC20,
signer: JsonRpcSigner,
Expand All @@ -21,7 +23,8 @@ export const createOrderERC20Signature = (
// @ts-ignore
signer,
swapContract,
chainId
chainId,
SWAP_ERC20_VERSION
);
resolve(signature);
} catch (error: unknown) {
Expand Down
Loading