Skip to content

Commit

Permalink
chrismaree/type export (#21)
Browse files Browse the repository at this point in the history
* feat: add multicall transaction processing logic

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* Update test/Relayer.IterativeFill.ts

Co-authored-by: nicholaspai <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* review nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

* nit

Signed-off-by: chrismaree <[email protected]>

Co-authored-by: nicholaspai <[email protected]>
  • Loading branch information
chrismaree and nicholaspai authored Apr 5, 2022
1 parent 6c80b5d commit 05bb17a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"license": "AGPL-3.0",
"private": true,
"dependencies": {
"@across-protocol/contracts-v2": "^0.0.37",
"@across-protocol/sdk-v2": "^0.0.1",
"@defi-wonderland/smock": "^2.0.7",
"@uma/contracts-node": "^0.3.1",
"@uma/financial-templates-lib": "2.25.0",
"@across-protocol/contracts-v2": "^0.0.36",
"@across-protocol/sdk-v2": "^0.0.1",
"hardhat": "^2.9.0"
},
"files": [
Expand Down Expand Up @@ -52,9 +52,9 @@
"prettier": "^2.3.2",
"prettier-plugin-solidity": "^1.0.0-beta.13",
"pretty-quick": "^2.0.1",
"sinon": "^9.0.2",
"solhint": "^3.3.6",
"solidity-coverage": "^0.7.16",
"sinon": "^9.0.2",
"ts-node": "^10.1.0",
"typechain": "^5.1.2",
"typescript": "^4.5.2"
Expand Down
20 changes: 20 additions & 0 deletions src/interfaces/HubPool.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
import { BigNumber } from "../utils";
// @notice Passed as input to HubPool.proposeRootBundle
export type BundleEvaluationBlockNumbers = number[];

export interface PoolRebalanceLeaf {
chainId: BigNumber;
groupIndex: BigNumber;
bundleLpFees: BigNumber[];
netSendAmounts: BigNumber[];
runningBalances: BigNumber[];
leafId: BigNumber;
l1Tokens: string[];
}

export interface RelayerRefundLeaf {
amountToReturn: BigNumber;
chainId: BigNumber;
refundAmounts: BigNumber[];
leafId: BigNumber;
l2TokenAddress: string;
refundAddresses: string[];
}
13 changes: 13 additions & 0 deletions src/interfaces/SpokePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ export interface SlowFill {
recipient: string;
}

// Used in pool by spokePool to execute a slow relay.
export interface RelayData {
depositor: string;
recipient: string;
destinationToken: string;
amount: BigNumber;
realizedLpFeePct: BigNumber;
relayerFeePct: BigNumber;
depositId: string;
originChainId: string;
destinationChainId: string;
}

export interface UnfilledDeposit {
deposit: Deposit;
unfilledAmount: BigNumber;
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./SpokePool";
export * from "./HubPool";
12 changes: 9 additions & 3 deletions src/utils/ContractInstance.ts → src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { getNetworkName, Contract, Wallet } from "./";
import { getNetworkName, Contract, Wallet } from ".";

import { getContractArtifact } from "@across-protocol/contracts-v2";
import { PublicNetworks } from "@uma/common";
import * as typechain from "@across-protocol/contracts-v2"; //TODO: refactor once we've fixed export from contract repo

// Return an ethers contract instance for a deployed contract, imported from the Across-protocol contracts repo.
export function getDeployedContract(contractName: string, networkId: number, signer: Wallet): Contract {
if (contractName === "SpokePool") contractName = castSpokePoolName(networkId);
console.log("contractName", contractName);

const artifact = getContractArtifact(contractName, networkId);
if (!artifact) throw new Error(`Could not find artifact for contract ${contractName} on ${networkId}`);
return new Contract(artifact.address, artifact.abi, signer);
Expand All @@ -22,3 +22,9 @@ export function castSpokePoolName(networkId: number): string {
if (networkName.includes("-")) networkName = networkName.substring(0, networkName.indexOf("-"));
return `${networkName}_SpokePool`;
}

export function getParamType(contractName: string, functionName: string, paramName: string) {
const artifact: any = typechain[`${[contractName]}__factory`];
const fragment = artifact.abi.find((fragment) => fragment.name === functionName);
return fragment!.inputs.find((input) => input.name === paramName) || "";
}
3 changes: 1 addition & 2 deletions src/utils/ExecutionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import winston from "winston";
import { delay } from "./";
import { delay, winston } from "./";

export async function processEndPollingLoop(logger: winston.Logger, fileName: String, pollingDelay: number) {
if (pollingDelay === 0) {
Expand Down
38 changes: 38 additions & 0 deletions src/utils/MerkleTreeUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { getParamType, utils } from ".";
import { RelayData, PoolRebalanceLeaf, RelayerRefundLeaf } from "../interfaces";
import { MerkleTree } from "@across-protocol/contracts-v2";

export async function buildSlowRelayTree(relays: RelayData[]) {
const paramType = await getParamType("MerkleLibTest", "verifySlowRelayFulfillment", "slowRelayFulfillment");
const hashFn = (input: RelayData) => {
return utils.keccak256(utils.defaultAbiCoder.encode([paramType!], [input]));
};
return new MerkleTree(relays, hashFn);
}

export async function buildPoolRebalanceLeafTree(poolRebalanceLeaves: PoolRebalanceLeaf[]) {
for (let i = 0; i < poolRebalanceLeaves.length; i++) {
// The 4 provided parallel arrays must be of equal length.
if (
poolRebalanceLeaves[i].l1Tokens.length !== poolRebalanceLeaves[i].bundleLpFees.length ||
poolRebalanceLeaves[i].netSendAmounts.length !== poolRebalanceLeaves[i].runningBalances.length
)
throw new Error("Provided lef arrays are not of equal length");
}

const paramType = await getParamType("MerkleLibTest", "verifyPoolRebalance", "rebalance");
const hashFn = (input: PoolRebalanceLeaf) => utils.keccak256(utils.defaultAbiCoder.encode([paramType!], [input]));
return new MerkleTree<PoolRebalanceLeaf>(poolRebalanceLeaves, hashFn);
}

export async function buildRelayerRefundTree(relayerRefundLeaves: RelayerRefundLeaf[]) {
for (let i = 0; i < relayerRefundLeaves.length; i++) {
// The 2 provided parallel arrays must be of equal length.
if (relayerRefundLeaves[i].refundAddresses.length != relayerRefundLeaves[i].refundAmounts.length)
throw new Error("Provided lef arrays are not of equal length");
}

const paramType = await getParamType("MerkleLibTest", "verifyRelayerRefund", "refund");
const hashFn = (input: RelayerRefundLeaf) => utils.keccak256(utils.defaultAbiCoder.encode([paramType!], [input]));
return new MerkleTree<RelayerRefundLeaf>(relayerRefundLeaves, hashFn);
}
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export * from "./EventUtils";
export * from "./ObjectUtils";
export * from "./FormattingUtils";
export * from "./TransactionPropBuilder";
export * from "./ContractInstance";
export * from "./ContractUtils";
export * from "./ExecutionUtils";
export * from "./NetworkUtils";
export * from "./TransactionUtils";
export * from "./MerkleTreeUtils";

export const zeroAddress = "0x0000000000000000000000000000000000000000";
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@across-protocol/contracts-v2@^0.0.36":
version "0.0.36"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts-v2/-/contracts-v2-0.0.36.tgz#33af2952168e5def06c85a2f7fef8c9eece6f163"
integrity sha512-67tYwCbad8Fq+oF82cSYv7Jk0dcba8bmxeNrHkaJIKDEnTTO2vNh3528KMP1COppp4DctFKHfpM2mts26DCYzA==
"@across-protocol/contracts-v2@^0.0.37":
version "0.0.37"
resolved "https://registry.yarnpkg.com/@across-protocol/contracts-v2/-/contracts-v2-0.0.37.tgz#e2cc6bd572d70af2543350db03a354b51662b26e"
integrity sha512-kyXH851PeL/ryEHyTina3YgEfKTookai0/oE4HBK8HEqygtibvpzseUrwahj5xjvDATFi+2gZy9I6FIxmXp9SQ==
dependencies:
"@defi-wonderland/smock" "^2.0.7"
"@eth-optimism/contracts" "^0.5.11"
Expand Down

0 comments on commit 05bb17a

Please sign in to comment.