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
mfw78 authored Oct 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 92ae3b5 commit 521c551
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
@@ -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",
@@ -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",
@@ -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",
75 changes: 0 additions & 75 deletions src/ts/deploy.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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";
13 changes: 0 additions & 13 deletions src/ts/interaction.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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.
*/
@@ -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.
@@ -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);
}

@@ -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);
@@ -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.
*/
@@ -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.
*/
@@ -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.
@@ -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.

20 changes: 10 additions & 10 deletions src/ts/settlement.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ import { TypedDataDomain } from "./types/ethers";
/**
* The stage an interaction should be executed in.
*/
export enum InteractionStage {
enum InteractionStage {
/**
* A pre-settlement intraction.
*
@@ -100,7 +100,7 @@ export type Trade = TradeExecution &
/**
* Details representing how an order was executed.
*/
export interface TradeExecution {
interface TradeExecution {
/**
* The executed trade amount.
*
@@ -123,7 +123,7 @@ export interface TradeExecution {
* increased again in the future. However, order refunds should not be used in
* an actual settlement.
*/
export interface OrderRefunds {
interface OrderRefunds {
/** Refund storage used for order filled amount */
filledAmounts: BytesLike[];
/** Refund storage used for order pre-signature */
@@ -133,12 +133,12 @@ export interface OrderRefunds {
/**
* Table mapping token addresses to their respective clearing prices.
*/
export type Prices = Record<string, BigNumberish | undefined>;
type Prices = Record<string, BigNumberish | undefined>;

/**
* Encoded settlement parameters.
*/
export type EncodedSettlement = [
type EncodedSettlement = [
/** Tokens. */
string[],
/** Clearing prices. */
@@ -233,7 +233,7 @@ function decodeFlag<K extends FlagKey>(
* @param scheme The signing scheme to encode.
* @return The bitfield result.
*/
export function encodeSigningScheme(scheme: SigningScheme): number {
function encodeSigningScheme(scheme: SigningScheme): number {
return encodeFlag("signingScheme", scheme);
}

@@ -243,7 +243,7 @@ export function encodeSigningScheme(scheme: SigningScheme): number {
* @param flag The encoded order flag.
* @return The decoded signing scheme.
*/
export function decodeSigningScheme(flags: BigNumberish): SigningScheme {
function decodeSigningScheme(flags: BigNumberish): SigningScheme {
return decodeFlag("signingScheme", flags);
}

@@ -253,7 +253,7 @@ export function decodeSigningScheme(flags: BigNumberish): SigningScheme {
* @param flags The order flags to encode.
* @return The bitfield result.
*/
export function encodeOrderFlags(flags: OrderFlags): number {
function encodeOrderFlags(flags: OrderFlags): number {
return (
encodeFlag("kind", flags.kind) |
encodeFlag("partiallyFillable", flags.partiallyFillable) |
@@ -274,7 +274,7 @@ export function encodeOrderFlags(flags: OrderFlags): number {
* @param flags The order flags encoded as a bitfield.
* @return The decoded order flags.
*/
export function decodeOrderFlags(flags: BigNumberish): OrderFlags {
function decodeOrderFlags(flags: BigNumberish): OrderFlags {
return {
kind: decodeFlag("kind", flags),
partiallyFillable: decodeFlag("partiallyFillable", flags),
@@ -306,7 +306,7 @@ export function decodeTradeFlags(flags: BigNumberish): TradeFlags {
};
}

export function encodeSignatureData(sig: Signature): string {
function encodeSignatureData(sig: Signature): string {
switch (sig.scheme) {
case SigningScheme.EIP712:
case SigningScheme.ETHSIGN:
11 changes: 0 additions & 11 deletions src/ts/sign.ts
Original file line number Diff line number Diff line change
@@ -13,17 +13,6 @@ import {
TypedDataDomain,
} from "./types/ethers";

/**
* Value returned by a call to `isValidSignature` if the signature was verified
* successfully. The value is defined in the EIP-1271 standard as:
* bytes4(keccak256("isValidSignature(bytes32,bytes)"))
*/
export const EIP1271_MAGICVALUE = ethers.utils.hexDataSlice(
ethers.utils.id("isValidSignature(bytes32,bytes)"),
0,
4,
);

/**
* The signing scheme used to sign the order.
*/
11 changes: 4 additions & 7 deletions src/ts/swap.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export interface Swap {
* An encoded Balancer swap request that can be used as input to the settlement
* contract.
*/
export interface BatchSwapStep {
interface BatchSwapStep {
/**
* The ID of the pool for the swap.
*/
@@ -68,7 +68,7 @@ export interface BatchSwapStep {
/**
* Swap execution parameters.
*/
export interface SwapExecution {
interface SwapExecution {
/**
* The limit amount for the swap.
*
@@ -81,7 +81,7 @@ export interface SwapExecution {
/**
* Encoded swap parameters.
*/
export type EncodedSwap = [
type EncodedSwap = [
/** Swap requests. */
BatchSwapStep[],
/** Tokens. */
@@ -94,10 +94,7 @@ export type EncodedSwap = [
* Encodes a swap as a {@link BatchSwapStep} to be used with the settlement
* contract.
*/
export function encodeSwapStep(
tokens: TokenRegistry,
swap: Swap,
): BatchSwapStep {
function encodeSwapStep(tokens: TokenRegistry, swap: Swap): BatchSwapStep {
return {
poolId: swap.poolId,
assetInIndex: tokens.index(swap.assetIn),
57 changes: 0 additions & 57 deletions test/encoding.ts

This file was deleted.

621 changes: 41 additions & 580 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 521c551

Please sign in to comment.