Skip to content

Commit

Permalink
Update scripts and add optional vBridgeInput value maxEdges for deplo…
Browse files Browse the repository at this point in the history
…yment (#164)

* Update scripts and add optional vBridgeInput value maxEdges for deployment

* Remove only annotation on bridge tests
  • Loading branch information
nepoche authored Jul 1, 2022
1 parent c161f79 commit d43cf57
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 322 deletions.
13 changes: 10 additions & 3 deletions packages/vbridge/src/VBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ import { CircomUtxo, Utxo } from "@webb-tools/sdk-core";
import { hexToU8a, u8aToHex } from '@polkadot/util';

export type ExistingAssetInput = {
// A record of chainId => address
// A record of chainId => address of wrappable tokens to be supported in the webbToken.
asset: Record<number, string[]>;
}

// Users define an input for a completely new bridge
export type VBridgeInput = {
// The tokens and anchors which should be supported after deploying from this bridge input
// The tokens which should be supported after deploying from this bridge input
vAnchorInputs: ExistingAssetInput,

// The IDs of the chains to deploy to
chainIDs: number[],

// The number of max edges for vanchors, if not provided, maxEdges is derived from passed chainIDs.
maxEdges?: number,

// Existing webb tokens can be connected
webbTokens: Map<number, GovernedTokenWrapper | undefined>;
};

Expand Down Expand Up @@ -106,6 +110,9 @@ export class VBridge {
// and anchors in the subArrays of thhe same index should be linked together
let createdVAnchors: VAnchor[][] = [];

// Determine the maxEdges for the anchors on this VBridge deployment
let maxEdges = vBridgeInput.maxEdges ?? vBridgeInput.chainIDs.length > 2 ? 7 : 1;

for (let chainID of vBridgeInput.chainIDs) {
const initialGovernor = initialGovernors[chainID];
// Create the bridgeSide
Expand Down Expand Up @@ -192,7 +199,7 @@ export class VBridge {
hasherInstance.address,
handler.contract.address,
tokenInstance.contract.address,
vBridgeInput.chainIDs.length > 2 ? 7 : 1,
maxEdges,
smallCircuitZkComponents,
largeCircuitZkComponents,
deployers[chainID],
Expand Down
14 changes: 14 additions & 0 deletions scripts/evm/bridgeActions/changeGovernor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ethers } from "ethers";
import { SignatureBridgeSide } from "@webb-tools/bridges"

export async function changeGovernor(
bridgeAddress: string,
newGovernor: string,
currentGovernor: ethers.Wallet
) {
const bridgeInstance = await SignatureBridgeSide.connect(bridgeAddress, currentGovernor, currentGovernor);
const refreshNonce = await bridgeInstance.contract.refreshNonce();
const tx = await bridgeInstance.transferOwnership(newGovernor, refreshNonce+1);
const receipt = await tx.wait();
console.log(receipt);
}
28 changes: 0 additions & 28 deletions scripts/evm/bridgeActions/depositAndBridgedWithdraw.ts

This file was deleted.

86 changes: 86 additions & 0 deletions scripts/evm/bridgeActions/transactWrapNative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
require('dotenv').config();
import { ethers } from 'ethers';
import { VAnchor } from '@webb-tools/anchors';
import path from 'path';
import { fetchComponentsFromFilePaths, getChainIdType } from '@webb-tools/utils';
import { CircomUtxo, Keypair, randomBN, Utxo } from '@webb-tools/sdk-core';
import { hexToU8a } from '@polkadot/util';

export async function transactWrapNative(anchorAddress: string, sender: ethers.Signer) {
const zkComponentsSmall = await fetchComponentsFromFilePaths(
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_2/8/poseidon_vanchor_2_8.wasm`
),
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_2/8/witness_calculator.js`
),
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_2/8/circuit_final.zkey`
)
);
const zkComponentsLarge = await fetchComponentsFromFilePaths(
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_16/8/poseidon_vanchor_16_8.wasm`
),
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_16/8/witness_calculator.js`
),
path.resolve(
__dirname,
`../../../protocol-solidity-fixtures/fixtures/vanchor_16/8/circuit_final.zkey`
)
);
const anchor = await VAnchor.connect(anchorAddress, zkComponentsSmall, zkComponentsLarge, sender);
const sourceChainId = getChainIdType(5001);
const randomKeypair = new Keypair();

const utxo = await CircomUtxo.generateUtxo({
curve: 'Bn254',
backend: 'Circom',
chainId: sourceChainId.toString(),
originChainId: sourceChainId.toString(),
amount: '1000000000000000',
keypair: randomKeypair,
})

// Build up the inputs for proving manager
const dummyOutputUtxo = await CircomUtxo.generateUtxo({
curve: 'Bn254',
backend: 'Circom',
chainId: sourceChainId.toString(),
originChainId: sourceChainId.toString(),
amount: '0',
keypair: randomKeypair,
});
const inputs: Utxo[] = [];
const outputs: [Utxo, Utxo] = [utxo, dummyOutputUtxo];

while (inputs.length !== 2 && inputs.length < 16) {
inputs.push(
await CircomUtxo.generateUtxo({
curve: 'Bn254',
backend: 'Circom',
chainId: sourceChainId.toString(),
originChainId: sourceChainId.toString(),
amount: '0',
blinding: hexToU8a(randomBN(31).toHexString()),
keypair: randomKeypair,
})
);
}

const tx = await anchor.transactWrap(
'0x0000000000000000000000000000000000000000',
inputs,
outputs,
'0',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
{}
);
}
59 changes: 59 additions & 0 deletions scripts/evm/ethersGovernorWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require('dotenv').config();
import { getChainIdType } from "@webb-tools/utils";
import { ethers } from "ethers";

export const providerRinkeby = new ethers.providers.JsonRpcProvider(`https://rinkeby.infura.io/v3/fff68ca474dd4764a8d54dd14fa5519e`);
export const walletRinkeby = new ethers.Wallet(process.env.PRIVATE_KEY!, providerRinkeby);
export const chainIdTypeRinkeby = getChainIdType(4);

export const providerPolygon = new ethers.providers.JsonRpcProvider(process.env.POLYGON_KEY!);
export const walletPolygon = new ethers.Wallet(process.env.PRIVATE_KEY!, providerPolygon);
export const chainIdTypePolygon = getChainIdType(80001);

export const providerKovan = new ethers.providers.JsonRpcProvider(`https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161`);
export const walletKovan = new ethers.Wallet(process.env.PRIVATE_KEY!, providerKovan);
export const chainIdTypeKovan = getChainIdType(42);

export const providerRopsten = new ethers.providers.JsonRpcProvider(`https://ropsten.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161`);
export const walletRopsten = new ethers.Wallet(process.env.PRIVATE_KEY!, providerRopsten);
export const chainIdTypeRopsten = getChainIdType(3);

export const providerGoerli = new ethers.providers.JsonRpcProvider(`https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161`);
export const walletGoerli = new ethers.Wallet(process.env.PRIVATE_KEY!, providerGoerli);
export const chainIdTypeGoerli = getChainIdType(5);

export const providerOptimism = new ethers.providers.JsonRpcProvider(process.env.OPTIMISM_KEY!);
export const walletOptimism = new ethers.Wallet(process.env.PRIVATE_KEY!, providerOptimism);
export const chainIdTypeOptimism = getChainIdType(69);

export const providerArbitrum = new ethers.providers.JsonRpcProvider(process.env.ARBITRUM_KEY!);
export const walletArbitrum = new ethers.Wallet(process.env.PRIVATE_KEY!, providerArbitrum);
export const chainIdTypeArbitrum = getChainIdType(421611);

export const providerMoonbase = new ethers.providers.JsonRpcProvider('https://moonbeam-alpha.api.onfinality.io/public');
export const walletMoonbase = new ethers.Wallet(process.env.PRIVATE_KEY!, providerMoonbase);
export const chainIdTypeMoonbase = getChainIdType(1287);

export const providerAvalanche = new ethers.providers.JsonRpcProvider(process.env.AVALANCHE_KEY!);
export const walletAvalanche = new ethers.Wallet(process.env.PRIVATE_KEY!, providerAvalanche);
export const chainIdTypeAvalanche = getChainIdType(43113);

export const providerAurora = new ethers.providers.JsonRpcProvider(process.env.AURORA_KEY!);
export const walletAurora = new ethers.Wallet(process.env.PRIVATE_KEY!, providerAurora);
export const chainIdTypeAurora = getChainIdType(1313161555);

export const providerHarmony = new ethers.providers.JsonRpcProvider(process.env.HARMONY_KEY!);
export const walletHarmony = new ethers.Wallet(process.env.PRIVATE_KEY!, providerHarmony);
export const chainIdTypeHarmony = getChainIdType(1666700000);

export const providerAthena = new ethers.providers.JsonRpcProvider(`http://127.0.0.1:5002`);
export const walletAthena = new ethers.Wallet("0x0000000000000000000000000000000000000000000000000000000000000001", providerAthena);
export const chainIdTypeAthena = getChainIdType(5002);

export const providerHermes = new ethers.providers.JsonRpcProvider(`http://127.0.0.1:5001`);
export const walletHermes = new ethers.Wallet("0x0000000000000000000000000000000000000000000000000000000000000001", providerHermes);
export const chainIdTypeHermes = getChainIdType(5001);

export const providerDemeter = new ethers.providers.JsonRpcProvider(`http://127.0.0.1:5003`);
export const walletDemeter = new ethers.Wallet("0x0000000000000000000000000000000000000000000000000000000000000001", providerDemeter);
export const chainIdTypeDemeter = getChainIdType(5003);
13 changes: 0 additions & 13 deletions scripts/evm/setLinkableAnchorBridge.ts

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/evm/setLinkableAnchorHandler.ts

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/evm/setResourceId.ts

This file was deleted.

20 changes: 0 additions & 20 deletions scripts/evm/tokens/inspectWebbInstance.ts

This file was deleted.

2 changes: 2 additions & 0 deletions scripts/evm/tokens/viewTokensInWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export async function viewTokensInWrapper(
const governedTokenWrapper = GovernedTokenWrapper__factory.connect(tokenWrapperAddress, passedProvider);
const tokens = await governedTokenWrapper.functions.getTokens();

const allowedNative = await governedTokenWrapper.isNativeAllowed();
console.log('Tokens in the wrapper: ');
console.log(tokens);
console.log('nativeAllowed? ', allowedNative);
}
8 changes: 0 additions & 8 deletions scripts/evm/tokens/wrapToken.ts

This file was deleted.

16 changes: 16 additions & 0 deletions scripts/evm/viewActions/playground.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require('dotenv').config();
const path = require('path');
import { ethers } from 'ethers';
import { toFixedHex } from '@webb-tools/sdk-core';
import { walletRinkeby, walletGoerli, walletArbitrum, walletMoonbase } from '../ethersGovernorWallets';
import { viewRootAcrossBridge } from './viewRootAcrossBridge';
import { VAnchor } from '@webb-tools/anchors';
import { VAnchor__factory } from '@webb-tools/contracts';

export const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

async function run() {
const anchorGoerli = VAnchor__factory.connect('0xE24A63Ebb690d0d6C241FDd4aA8ad90421f91D8a', walletGoerli);
}

run();
10 changes: 0 additions & 10 deletions scripts/evm/viewActions/viewAnchorHandler.ts

This file was deleted.

14 changes: 14 additions & 0 deletions scripts/evm/viewActions/viewRootAcrossBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('dotenv').config();
import { ethers } from 'ethers';
import { VAnchor } from '@webb-tools/contracts';

export async function viewRootAcrossBridge(merkleRootAnchor: VAnchor, edgeListAnchor: VAnchor) {
const lastMerkleRoot = await merkleRootAnchor.getLastRoot();
const merkleChainId = await merkleRootAnchor.signer.getChainId();

console.log('Latest merkle root on chain: ', lastMerkleRoot);
const merkleRootIndex = await edgeListAnchor.edgeIndex(merkleChainId);
const edgeListEntry = await edgeListAnchor.edgeList(merkleRootIndex);
console.log('edge list entry: ', edgeListEntry);
}

Loading

0 comments on commit d43cf57

Please sign in to comment.