Skip to content

Commit

Permalink
chore: clean dead code (#232)
Browse files Browse the repository at this point in the history
## Description

This PR removes extraneous TypeScript that has been left over as a
result of the E2E tests.

## Test Plan

1. Confirm CI/CD green.

## Related Issues

#130
  • Loading branch information
mfw78 authored Oct 9, 2024
1 parent 92ae3b5 commit 521c551
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 918 deletions.
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@
"ethers": "^5.4.0"
},
"devDependencies": {
"@gnosis.pm/safe-contracts": "^1.3.0",
"@nomicfoundation/hardhat-verify": "^2.0.1",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-waffle": "^2.0.5",
"@openzeppelin/contracts": "=3.4.0-solc-0.7",
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.2.0",
"@safe-global/safe-core-sdk-types": "^2.2.0",
"@slack/web-api": "^6.9.0",
"@tenderly/hardhat-tenderly": "~1.1.6",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
Expand All @@ -57,7 +52,6 @@
"@typescript-eslint/parser": "^5.58.0",
"@uniswap/v2-core": "^1.0.1",
"@uniswap/v2-periphery": "^1.1.0-beta.0",
"axios": "^1.3.5",
"canonical-weth": "^1.4.0",
"chai": "^4.3.7",
"chai-as-promised": "^7.1.1",
Expand All @@ -71,7 +65,6 @@
"eslint-plugin-prettier": "^4.2.1",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.7.2",
"globby": "^11.0.4",
"hardhat": "^2.13.1",
"hardhat-deploy": "^0.11.26",
"hardhat-gas-reporter": "^1.0.9",
Expand Down
75 changes: 0 additions & 75 deletions src/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,10 @@ import { utils } from "ethers";
*/
export const SALT = utils.formatBytes32String("Mattresses in Berlin!");

/**
* The contract used to deploy contracts deterministically with CREATE2.
* The address is chosen by the hardhat-deploy library.
* It is the same in any EVM-based network.
*
* https://github.com/Arachnid/deterministic-deployment-proxy
*/
export const DEPLOYER_CONTRACT = "0x4e59b44847b379578588920ca78fbf26c0b4956c";

/**
* Dictionary containing all deployed contract names.
*/
export const CONTRACT_NAMES = {
authenticator: "GPv2AllowListAuthentication",
settlement: "GPv2Settlement",
} as const;

/**
* The name of a deployed contract.
*/
export type ContractName = (typeof CONTRACT_NAMES)[keyof typeof CONTRACT_NAMES];

/**
* The deployment args for a contract.
*/
export type DeploymentArguments<T> =
T extends typeof CONTRACT_NAMES.authenticator
? never
: T extends typeof CONTRACT_NAMES.settlement
? [string, string]
: unknown[];

/**
* Allowed ABI definition types by Ethers.js.
*/
export type Abi = ConstructorParameters<typeof utils.Interface>[0];

/**
* Artifact information important for computing deterministic deployments.
*/
export interface ArtifactDeployment {
abi: Abi;
bytecode: string;
}

/**
* An artifact with a contract name matching one of the deterministically
* deployed contracts.
*/
export interface NamedArtifactDeployment<C extends ContractName>
extends ArtifactDeployment {
contractName: C;
}

type MaybeNamedArtifactArtifactDeployment<C> = C extends ContractName
? NamedArtifactDeployment<C>
: ArtifactDeployment;

/**
* Computes the deterministic address at which the contract will be deployed.
* This address does not depend on which network the contract is deployed to.
*
* @param contractName Name of the contract for which to find the address.
* @param deploymentArguments Extra arguments that are necessary to deploy.
* @returns The address that is expected to store the deployed code.
*/
export function deterministicDeploymentAddress<C>(
{ abi, bytecode }: MaybeNamedArtifactArtifactDeployment<C>,
deploymentArguments: DeploymentArguments<C>,
): string {
const contractInterface = new utils.Interface(abi);
const deployData = utils.hexConcat([
bytecode,
contractInterface.encodeDeploy(deploymentArguments),
]);

return utils.getCreate2Address(
DEPLOYER_CONTRACT,
SALT,
utils.keccak256(deployData),
);
}
1 change: 0 additions & 1 deletion src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function domain(
export * from "./deploy";
export * from "./interaction";
export * from "./order";
export * from "./proxy";
export * from "./settlement";
export * from "./sign";
export * from "./swap";
Expand Down
13 changes: 0 additions & 13 deletions src/ts/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,3 @@ export function normalizeInteraction(
...interaction,
};
}

/**
* Normalizes data for many interactions so that they can be ABI encoded. This
* calls [`normalizeInteraction`] for each interaction.
*
* @param interactions The interactions to normalize.
* @return The normalized interactions.
*/
export function normalizeInteractions(
interactions: InteractionLike[],
): Interaction[] {
return interactions.map(normalizeInteraction);
}
81 changes: 5 additions & 76 deletions src/ts/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,6 @@ export interface Order {
buyTokenBalance?: OrderBalance;
}

/**
* Gnosis Protocol v2 order cancellation data.
*/
export interface OrderCancellations {
/**
* The unique identifier of the order to be cancelled.
*/
orderUids: BytesLike[];
}

/**
* Marker address to indicate that an order is buying Ether.
*
* Note that this address is only has special meaning in the `buyToken` and will
* be treated as a ERC20 token address in the `sellToken` position, causing the
* settlement to revert.
*/
export const BUY_ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";

/**
* Gnosis Protocol v2 order flags.
*/
Expand All @@ -102,12 +83,12 @@ export type OrderFlags = Pick<
/**
* A timestamp value.
*/
export type Timestamp = number | Date;
type Timestamp = number | Date;

/**
* A hash-like app data value.
*/
export type HashLike = BytesLike | number;
type HashLike = BytesLike | number;

/**
* Order kind.
Expand Down Expand Up @@ -168,7 +149,7 @@ export const ORDER_TYPE_FIELDS = [
* @param time The timestamp value to normalize.
* @return Unix timestamp or number of seconds since the Unix Epoch.
*/
export function timestamp(t: Timestamp): number {
function timestamp(t: Timestamp): number {
return typeof t === "number" ? t : ~~(t.getTime() / 1000);
}

Expand All @@ -177,7 +158,7 @@ export function timestamp(t: Timestamp): number {
* @param hashLike A hash-like value to normalize.
* @returns A 32-byte hash encoded as a hex-string.
*/
export function hashify(h: HashLike): string {
function hashify(h: HashLike): string {
return typeof h === "number"
? `0x${h.toString(16).padStart(64, "0")}`
: ethers.utils.hexZeroPad(h, 32);
Expand Down Expand Up @@ -258,21 +239,6 @@ export function hashTypedData(
return ethers.utils._TypedDataEncoder.hash(domain, types, data);
}

/**
* Compute the 32-byte signing hash for the specified order.
*
* @param domain The EIP-712 domain separator to compute the hash for.
* @param order The order to compute the digest for.
* @return Hex-encoded 32-byte order digest.
*/
export function hashOrder(domain: TypedDataDomain, order: Order): string {
return hashTypedData(
domain,
{ Order: ORDER_TYPE_FIELDS },
normalizeOrder(order),
);
}

/**
* The byte length of an order UID.
*/
Expand All @@ -281,7 +247,7 @@ export const ORDER_UID_LENGTH = 56;
/**
* Order unique identifier parameters.
*/
export interface OrderUidParams {
interface OrderUidParams {
/**
* The EIP-712 order struct hash.
*/
Expand All @@ -296,21 +262,6 @@ export interface OrderUidParams {
validTo: number | Date;
}

/**
* Computes the order UID for an order and the given owner.
*/
export function computeOrderUid(
domain: TypedDataDomain,
order: Order,
owner: string,
): string {
return packOrderUidParams({
orderDigest: hashOrder(domain, order),
owner,
validTo: order.validTo,
});
}

/**
* Compute the unique identifier describing a user order in the settlement
* contract.
Expand All @@ -329,25 +280,3 @@ export function packOrderUidParams({
[orderDigest, owner, timestamp(validTo)],
);
}

/**
* Extracts the order unique identifier parameters from the specified bytes.
*
* @param orderUid The order UID encoded as a hexadecimal string.
* @returns The extracted order UID parameters.
*/
export function extractOrderUidParams(orderUid: string): OrderUidParams {
const bytes = ethers.utils.arrayify(orderUid);
if (bytes.length != ORDER_UID_LENGTH) {
throw new Error("invalid order UID length");
}

const view = new DataView(bytes.buffer);
return {
orderDigest: ethers.utils.hexlify(bytes.subarray(0, 32)),
owner: ethers.utils.getAddress(
ethers.utils.hexlify(bytes.subarray(32, 52)),
),
validTo: view.getUint32(52),
};
}
81 changes: 0 additions & 81 deletions src/ts/proxy.ts

This file was deleted.

Loading

0 comments on commit 521c551

Please sign in to comment.