Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"packages/*"
],
"scripts": {
"compile": "lerna run compile",
"compile": "lerna run compile --scope=@webb-tools/contracts",
"build": "yarn compile && yarn build:packages",
"setup": "yarn compile && yarn build:circuits && yarn build:ptau",
"test": "yarn workspace @webb-tools/contracts run test",
Expand Down Expand Up @@ -51,6 +51,8 @@
"copyfiles": "^2.4.1",
"eth-proof": "~2.1.6",
"ethers": "5.7.0",
"itertools": "^1.7.1",
"tomlify-j0.4":"^3.0.0",
"ffjavascript": "^0.2.38",
"hardhat": "^2.6.8",
"hardhat-gas-reporter": "^1.0.8",
Expand Down Expand Up @@ -95,4 +97,4 @@
"typechain": "^5.1.2",
"typescript": "4.7.2"
}
}
}
24 changes: 24 additions & 0 deletions packages/anchors/src/AnchorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AnchorHandler as AnchorHandlerContract,
AnchorHandler__factory,
} from '@webb-tools/contracts';
import { Deployer } from './Deployer';

export class AnchorHandler {
contract: AnchorHandlerContract;
Expand All @@ -25,6 +26,29 @@ export class AnchorHandler {
return handler;
}

public static async create2AnchorHandler(
bridgeAddress: string,
initResourceIds: string[],
initContractAddresses: string[],
deployer: Deployer,
saltHex: string,
signer: ethers.Signer
) {
const argTypes = ['address', 'bytes32[]', 'address[]'];
const args = [bridgeAddress, initResourceIds, initContractAddresses];
const { contract: contract } = await deployer.deploy(
AnchorHandler__factory,
saltHex,
signer,
undefined,
argTypes,
args
);

const handler = new AnchorHandler(contract);
return handler;
}

public static async connect(handlerAddress: string, signer: ethers.Signer) {
const handlerContract = AnchorHandler__factory.connect(handlerAddress, signer);
const handler = new AnchorHandler(handlerContract);
Expand Down
2 changes: 1 addition & 1 deletion packages/anchors/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"exclude": [],
"extends": "../../tsconfig.build.json",
"include": [
"./src/**/*.ts",
"./src/*.ts",
]
}
25 changes: 24 additions & 1 deletion packages/bridges/src/SignatureBridgeSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BigNumber, ethers } from 'ethers';
import { SignatureBridge, SignatureBridge__factory } from '@webb-tools/contracts';
import { FungibleTokenWrapper, Treasury } from '@webb-tools/tokens';
import { TokenWrapperHandler } from '@webb-tools/tokens';
import { AnchorHandler } from '@webb-tools/anchors';
import { AnchorHandler, Deployer } from '@webb-tools/anchors';
import { IVAnchor, IBridgeSide, Proposal } from '@webb-tools/interfaces';
import { TreasuryHandler } from '@webb-tools/tokens';
import { getChainIdType } from '@webb-tools/utils';
Expand Down Expand Up @@ -52,6 +52,29 @@ export class SignatureBridgeSide implements IBridgeSide {
return bridgeSide;
}

public static async create2BridgeSide(
deployer: Deployer,
saltHex: string,
admin: ethers.Wallet
): Promise<SignatureBridgeSide> {
const argTypes = ['address', 'uint32'];
const args = [admin.address, 0];
const { contract: deployedBridge } = await deployer.deploy(
SignatureBridge__factory,
saltHex,
admin,
undefined,
argTypes,
args
);
const bridgeSide = new SignatureBridgeSide(deployedBridge, (data: any) => {
return Promise.resolve(signMessage(admin, data));
});
bridgeSide.admin = admin;
bridgeSide.governor = admin;
return bridgeSide;
}

/**
* When an existing SignatureBridge is connected, the governor must be configured.
* In the case of connectMocked, a wallet address is passed which will act as the governor.
Expand Down
8 changes: 1 addition & 7 deletions packages/contracts/test/token/AaveTokenWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ const { BigNumber } = require('ethers');
const bne = (x, e) => BigNumber.from(x + '0'.repeat(parseInt(e)));

// Convenience wrapper classes for contract classes
import { ERC20 as ERC20Class } from '@webb-tools/tokens';
import { IERC20 } from '../../lib/IERC20';
import { AaveTokenWrapper } from '../../lib/AaveTokenWrapper';
import { AaveTokenWrapper__factory } from '../../lib/factories/AaveTokenWrapper__factory';
import { AaveTokenWrapper, AaveTokenWrapper__factory, IERC20 } from '@webb-tools/contracts';
import { expect } from 'chai';

describe('AaveTokenWrapper', () => {
let token: ERC20Class;
let aaveToken: AaveTokenWrapper;
let sender: SignerWithAddress;
const tokenName = 'Token';
const tokenSymbol = 'TKN';
const aaveTokenName = 'Wrapped Token';
const aaveTokenSymbol = 'wTKN';
const aaveLendingPoolAddress = '0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9';
Expand Down
3 changes: 1 addition & 2 deletions packages/contracts/test/trees/MerkleForest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
import { toFixedHex } from '@webb-tools/sdk-core';
import { BigNumber } from 'ethers';
import { ethers } from 'hardhat';
import { poseidon, poseidon_gencontract as poseidonContract } from 'circomlibjs';
import { poseidon_gencontract as poseidonContract } from 'circomlibjs';
import { MerkleTree } from '@webb-tools/sdk-core';
import { PoseidonHasher } from '@webb-tools/anchors';
import {
MerkleForestMock as MerkleForestMockContract,
LinkableIncrementalBinaryTree as LinkableIncrementalBinaryTreeContract,
LinkableIncrementalBinaryTree__factory,
} from '../../lib';
const TruffleAssert = require('truffle-assertions');
const assert = require('assert');
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts/test/vanchor/mocks/SetupTxVAnchorMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
Utxo,
CircomProvingManager,
ProvingManagerSetupInput,
Note,
NoteGenInput,
FIELD_SIZE,
LeafIdentifier,
} from '@webb-tools/sdk-core';
import { IVariableAnchorExtData, IVariableAnchorPublicInputs } from '@webb-tools/interfaces';
import { hexToU8a, u8aToHex, getChainIdType, ZkComponents } from '@webb-tools/utils';
import { VAnchorTree as VAnchorContract } from '../../../typechain';
import { VAnchorTree as VAnchorContract } from '@webb-tools/contracts';

export class SetupTxVAnchorMock extends VAnchor {
private rootsForProof: BigNumber[];
Expand Down
3 changes: 0 additions & 3 deletions packages/contracts/test/vanchor/vanchor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import {
} from '@webb-tools/sdk-core';
import { VAnchor, PoseidonHasher } from '@webb-tools/anchors';
import { Verifier } from '@webb-tools/vbridge';
import { writeFileSync } from 'fs';
import { SetupTxVAnchorMock } from './mocks/SetupTxVAnchorMock';
import { isTupleTypeNode } from 'typescript';
import { TokenWrapper__factory } from 'packages/contracts/typechain';

const BN = require('bn.js');

Expand Down
1 change: 1 addition & 0 deletions packages/tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"compile": "tsc -p tsconfig.build.json"
},
"dependencies": {
"@webb-tools/anchors": "^0.5.4",
"@webb-tools/contracts": "^0.5.4",
"@webb-tools/sdk-core": "0.1.4-119",
"@webb-tools/utils": "^0.5.4",
Expand Down
32 changes: 32 additions & 0 deletions packages/tokens/src/FungibleTokenWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
FungibleTokenWrapper__factory,
} from '@webb-tools/contracts';
import { assert } from 'chai';
import { Deployer } from '@webb-tools/anchors';

export class FungibleTokenWrapper {
contract: FungibleTokenWrapperContract;
Expand Down Expand Up @@ -42,6 +43,37 @@ export class FungibleTokenWrapper {
return tokenWrapper;
}

public static async create2FungibleTokenWrapper(
name: string,
symbol: string,
feePercentage: number,
feeRecipient: string,
handler: string,
limit: string,
isNativeAllowed: boolean,
deployer: Deployer,
saltHex: string,
signer: ethers.Signer
) {
assert(feePercentage <= 10_000, 'feePercentage should be less than 10_000');

const argTypes = ['string', 'string'];
const args = [name, symbol];
const { contract: contract } = await deployer.deploy(
FungibleTokenWrapper__factory,
saltHex,
signer,
undefined,
argTypes,
args
);

// Initialize immediately after deployment as we use an intializer now
await contract.initialize(feePercentage, feeRecipient, handler, limit, isNativeAllowed);
const tokenWrapper = new FungibleTokenWrapper(contract, signer);
return tokenWrapper;
}

public static connect(address: string, signer: ethers.Signer) {
const contract = FungibleTokenWrapper__factory.connect(address, signer);
const tokenWrapper = new FungibleTokenWrapper(contract, signer);
Expand Down
23 changes: 23 additions & 0 deletions packages/tokens/src/TokenWrapperHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TokenWrapperHandler as TokenWrapperHandlerContract,
TokenWrapperHandler__factory,
} from '@webb-tools/contracts';
import { Deployer } from '@webb-tools/anchors';

export class TokenWrapperHandler {
contract: TokenWrapperHandlerContract;
Expand All @@ -25,6 +26,28 @@ export class TokenWrapperHandler {
return handler;
}

public static async create2TokenWrapperHandler(
bridgeAddress: string,
initResourceIds: string[],
initContractAddresses: string[],
deployer: Deployer,
saltHex: string,
signer: ethers.Signer
) {
const argTypes = ['address', 'bytes32[]', 'address[]'];
const args = [bridgeAddress, initResourceIds, initContractAddresses];
const { contract: contract } = await deployer.deploy(
TokenWrapperHandler__factory,
saltHex,
signer,
undefined,
argTypes,
args
);
const handler = new TokenWrapperHandler(contract);
return handler;
}

public static async connect(handlerAddress: string, signer: ethers.Signer) {
const handlerContract = TokenWrapperHandler__factory.connect(handlerAddress, signer);
const handler = new TokenWrapperHandler(handlerContract);
Expand Down
22 changes: 22 additions & 0 deletions packages/tokens/src/Treasury.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BigNumber, ethers } from 'ethers';
import { getChainIdType } from '@webb-tools/utils';
import { toHex, generateFunctionSigHash, toFixedHex } from '@webb-tools/sdk-core';
import { Treasury as TreasuryContract, Treasury__factory } from '@webb-tools/contracts';
import { Deployer } from '@webb-tools/anchors';

export class Treasury {
contract: TreasuryContract;
Expand All @@ -24,6 +25,27 @@ export class Treasury {
return handler;
}

public static async create2Treasury(
treasuryHandler: string,
deployer: Deployer,
saltHex: string,
signer: ethers.Signer
) {
const argTypes = ['string'];
const args = [treasuryHandler];
const { contract: contract } = await deployer.deploy(
Treasury__factory,
saltHex,
signer,
undefined,
argTypes,
args
);

const handler = new Treasury(contract, signer);
return handler;
}

public static connect(address: string, signer: ethers.Signer) {
const contract = Treasury__factory.connect(address, signer);
const treasury = new Treasury(contract, signer);
Expand Down
23 changes: 23 additions & 0 deletions packages/tokens/src/TreasuryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
TreasuryHandler as TreasuryHandlerContract,
TreasuryHandler__factory,
} from '@webb-tools/contracts';
import { Deployer } from '@webb-tools/anchors';

export class TreasuryHandler {
contract: TreasuryHandlerContract;
Expand All @@ -25,6 +26,28 @@ export class TreasuryHandler {
return handler;
}

public static async create2TreasuryHandler(
bridgeAddress: string,
initResourceIds: string[],
initContractAddresses: string[],
deployer: Deployer,
saltHex: string,
sender: ethers.Signer
) {
const argTypes = ['address', 'bytes32[]', 'address[]'];
const args = [bridgeAddress, initResourceIds, initContractAddresses];
const { contract: contract } = await deployer.deploy(
TreasuryHandler__factory,
saltHex,
sender,
undefined,
argTypes,
args
);
const handler = new TreasuryHandler(contract);
return handler;
}

public static async connect(handlerAddress: string, signer: ethers.Signer) {
const handlerContract = TreasuryHandler__factory.connect(handlerAddress, signer);
const handler = new TreasuryHandler(handlerContract);
Expand Down
Loading