Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Commit

Permalink
Throw if dumping to ETH (#974)
Browse files Browse the repository at this point in the history
* Throw if dumping to ETH

* ETH -> native asset

* Fix broken refactoring
  • Loading branch information
fedgiac committed Feb 12, 2022
1 parent 33c859f commit 4a51c1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/tasks/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,20 @@ async function transferSameTokenToReceiver(
await receipt.wait();
}

export function assertNotBuyingNativeAsset(toToken: string | undefined) {
// This function checks that toToken is not the native asset (e.g., ETH).
// Technically, this script was built to support selling ETH. However, there
// are two requirement from the backend for it to work:
// 1. Sending native assets to smart contracts should be supported. At the
// time of writing, this returns an error when creating the order.
// 2. Selling wrapped native assets for their unwrapped counterpart should be
// supported. It currently returns an error about the fact that the token
// is the same.
if ([undefined, BUY_ETH_ADDRESS].includes(toToken)) {
throw new Error("Receiving native asset is not supported yet.");
}
}

interface DumpInput {
validity: number;
maxFeePercent: number;
Expand Down Expand Up @@ -661,6 +675,9 @@ export async function dump({
}: DumpInput): Promise<void> {
const { ethers } = hre;

// TODO: remove once native asset orders are fully supported.
assertNotBuyingNativeAsset(toTokenAddress);

const [chainId, vaultRelayer] = await Promise.all([
ethers.provider.getNetwork().then((n) => n.chainId),
(await settlement.vaultRelayer()) as string,
Expand Down
9 changes: 8 additions & 1 deletion src/tasks/withdrawService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { BUY_ETH_ADDRESS } from "../ts";
import { Api, Environment } from "../ts/api";

import { dump, MAX_ORDER_VALIDITY_SECONDS } from "./dump";
import {
assertNotBuyingNativeAsset,
dump,
MAX_ORDER_VALIDITY_SECONDS,
} from "./dump";
import {
getDeployedContract,
isSupportedNetwork,
Expand Down Expand Up @@ -544,6 +548,9 @@ const setupWithdrawServiceTask: () => void = () =>
},
hre: HardhatRuntimeEnvironment,
) => {
// TODO: remove once native asset orders are fully supported.
assertNotBuyingNativeAsset(toToken);

const state = await getState(stateFilePath);
console.debug(`Initial state: ${JSON.stringify(state)}`);
const network = hre.network.name;
Expand Down

0 comments on commit 4a51c1d

Please sign in to comment.