ethers/lib/utils#keccak256 TypeScript Examples
The following examples show how to use
ethers/lib/utils#keccak256.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sign-utils.ts From shoyu with MIT License | 7 votes |
getDigest = async (
provider: any,
name: string, // name is deprecated
contractAddress: string,
hash: BytesLike
): Promise<string> => {
return keccak256(
solidityPack(
["bytes1", "bytes1", "bytes32", "bytes32"],
["0x19", "0x01", await domainSeparator(provider, name, contractAddress), hash]
)
);
}
Example #2
Source File: signatures.ts From ERC20Permit with GNU General Public License v3.0 | 6 votes |
// Returns the EIP712 hash which should be signed by the user
// in order to make a call to `permit`
export function getPermitDigest(
name: string,
address: string,
chainId: number,
approve: {
owner: string
spender: string
value: BigNumberish
},
nonce: BigNumberish,
deadline: BigNumberish
) {
const DOMAIN_SEPARATOR = getDomainSeparator(name, address, chainId)
return keccak256(
solidityPack(
['bytes1', 'bytes1', 'bytes32', 'bytes32'],
[
'0x19',
'0x01',
DOMAIN_SEPARATOR,
keccak256(
defaultAbiCoder.encode(
['bytes32', 'address', 'address', 'uint256', 'uint256', 'uint256'],
[PERMIT_TYPEHASH, approve.owner, approve.spender, approve.value, nonce, deadline]
)
),
]
)
)
}
Example #3
Source File: signatures.ts From ERC20Permit with GNU General Public License v3.0 | 6 votes |
// Gets the EIP712 domain separator
export function getDomainSeparator(name: string, contractAddress: string, chainId: number) {
return keccak256(
defaultAbiCoder.encode(
['bytes32', 'bytes32', 'bytes32', 'uint256', 'address'],
[
keccak256(toUtf8Bytes('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)')),
keccak256(toUtf8Bytes(name)),
keccak256(toUtf8Bytes('1')),
chainId,
contractAddress,
]
)
)
}
Example #4
Source File: utils.ts From mStable-apps with GNU Lesser General Public License v3.0 | 6 votes |
hashFn = (data: string) => keccak256(data).slice(2)
Example #5
Source File: sign-utils.ts From shoyu with MIT License | 6 votes |
convertToHash = (text: string) => {
return keccak256(toUtf8Bytes(text));
}
Example #6
Source File: sign-utils.ts From shoyu with MIT License | 6 votes |
signAsk = async (
provider: any,
exchangeName: string, //deprecated
exchangeAddress: string,
signer: ethers.Wallet,
proxy: string,
token: string,
tokenId: BigNumberish,
amount: BigNumberish,
strategy: string,
currency: string,
recipient: string,
deadline: BigNumberish,
params: BytesLike
) => {
const hash = getHash(
["bytes32", "address", "address", "address", "uint256", "uint256", "address", "address", "address", "uint256", "bytes32"],
[
ASK_TYPEHASH,
signer.address,
proxy,
token,
tokenId,
amount,
strategy,
currency,
recipient,
deadline,
keccak256(params),
]
);
const digest = await getDigest(provider, exchangeAddress.toLowerCase(), exchangeAddress, hash);
const sig = sign(digest, signer);
const order: AskOrder = {
signer: signer.address,
proxy,
token,
tokenId,
amount,
strategy,
currency,
recipient,
deadline,
params,
v: sig.v,
r: sig.r,
s: sig.s,
};
return { hash, digest, sig, order };
}
Example #7
Source File: sign-utils.ts From shoyu with MIT License | 6 votes |
getHash = (types: string[], values: any[]): string => {
return keccak256(defaultAbiCoder.encode(types, values));
}
Example #8
Source File: signatures.ts From ERC20Permit with GNU General Public License v3.0 | 5 votes |
PERMIT_TYPEHASH = keccak256(
toUtf8Bytes('Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)')
)
Example #9
Source File: analyzeMainBridge.ts From l2beat with MIT License | 5 votes |
/*
Analyze Main Bridge:
1. Analyze Proxy
2. Check owner and implementation for EIP1967 Proxy type
3. Analyze Implementation
4. Query Implementation for parameters
*/
export async function analyzeMainBridge(
provider: providers.Provider,
addressAnalyzer: AddressAnalyzer,
mainBridge: MainBridgeConfig
): Promise<AnalyzedMainBridge> {
const proxyContract = await addressAnalyzer.analyze(
EthereumAddress(mainBridge.proxyAddress)
)
const [implementationSlot, ownerSlot] = await Promise.all([
provider.getStorageAt(
mainBridge.proxyAddress,
'0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
),
provider.getStorageAt(
mainBridge.proxyAddress,
'0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103'
),
])
const implementation = wordToAddress(implementationSlot)
if (implementation != mainBridge.implementation) {
console.log(
`Warning: bridge implementation is not ${mainBridge.implementation}`
)
}
const owner = wordToAddress(ownerSlot)
const implementationContract = await addressAnalyzer.analyze(
EthereumAddress(implementation)
)
const abi = ['function messenger() view returns (address)']
const bridgeContract = new Contract(mainBridge.proxyAddress, abi, provider)
const messenger = await bridgeContract.messenger()
const analyzedMessenger = await addressAnalyzer.analyze(
EthereumAddress(messenger)
)
let libResolvedDelegateProxyImplementationName = ''
let libResolvedDelegateProxyAddressManager = ''
if (analyzedMessenger.name === 'Lib_ResolvedDelegateProxy') {
const slot1 = '0'.padStart(64, '0')
const slot2 = '1'.padStart(64, '0')
const key = messenger.slice(2).toLowerCase().padStart(64, '0')
const [implementationName, addressManagerAddress] = await Promise.all([
provider.getStorageAt(messenger, keccak256('0x' + key + slot1)),
provider.getStorageAt(messenger, keccak256('0x' + key + slot2)),
])
libResolvedDelegateProxyAddressManager = wordToAddress(
addressManagerAddress
)
libResolvedDelegateProxyImplementationName = Buffer.from(
implementationName.slice(2),
'hex'
)
.toString('utf8')
.slice(0, -1)
}
return {
owner,
proxy: proxyContract as AnalyzedAddress,
implementationAddress: implementation,
implementation: implementationContract as AnalyzedAddress,
messengerAddress: messenger,
messenger: analyzedMessenger as AnalyzedAddress,
libResolvedDelegateProxyImplementationName,
libResolvedDelegateProxyAddressManager,
}
}
Example #10
Source File: 001_deploy_gateways.ts From gateway-sol with GNU General Public License v3.0 | 5 votes |
deployGatewaySol = async function (
hre: HardhatRuntimeEnvironment,
config?: NetworkConfig,
logger: ConsoleInterface = console
) {
const { getNamedAccounts, ethers, network } = hre;
logger.log(`Deploying to ${network.name}...`);
const Ox = ethers.utils.getAddress;
config = config || networks[network.name as "hardhat"];
if (!config) {
throw new Error(`No network configuration found for ${network.name}!`);
}
const { mintAuthority, chainName, create2SaltOverride } = config;
const chainId: number = (await ethers.provider.getNetwork()).chainId;
const { deployer } = await getNamedAccounts();
if (Ox(mintAuthority) === Ox0) {
throw new Error(`Invalid empty mintAuthority.`);
}
const create2 = setupCreate2(hre, create2SaltOverride, logger);
const getExistingDeployment = setupGetExistingDeployment(hre);
const waitForTx = setupWaitForTx(logger);
// Deploy RenTimelock ////////////////////////////////////////////////
logger.log(chalk.yellow("RenTimelock"));
const renTimelock = await create2<RenTimelock__factory>("RenTimelock", [0, [deployer], [deployer]]);
let governanceAddress: string;
if (network.name === "hardhat") {
governanceAddress = deployer;
} else {
governanceAddress = renTimelock.address;
}
// Deploy RenProxyAdmin ////////////////////////////////////////////////
logger.log(chalk.yellow("RenProxyAdmin"));
const renProxyAdmin =
(await getExistingDeployment<RenProxyAdmin>("RenProxyAdmin")) ||
(await create2<RenProxyAdmin__factory>("RenProxyAdmin", [governanceAddress]));
const deployProxy = setupDeployProxy(hre, create2, renProxyAdmin, logger);
// This should only be false on hardhat.
const create2IsContract = (await ethers.provider.getCode(CREATE2_DEPLOYER)).replace(/^0x/, "").length > 0;
// Deploy RenAssetProxyBeacon ////////////////////////////////////////////////
logger.log(chalk.yellow("RenAsset beacon"));
const renAssetImplementation = await create2<RenAssetV2__factory>("RenAssetV2", []);
const existingRenAssetProxyBeacon = await getExistingDeployment<RenAssetProxyBeacon>("RenAssetProxyBeacon");
const renAssetProxyBeacon =
existingRenAssetProxyBeacon ||
(await create2<RenAssetProxyBeacon__factory>("RenAssetProxyBeacon", [
// Temporary value, gets overwritten in the next step. This is to
// ensure that the address doesn't change between networks even when
// the implementation changes.
create2IsContract ? CREATE2_DEPLOYER : renAssetImplementation.address,
deployer,
]));
if (Ox(await renAssetProxyBeacon.implementation()) !== Ox(renAssetImplementation.address)) {
logger.log(`Updating RenAsset implementation to ${Ox(renAssetImplementation.address)}`);
await waitForTx(renAssetProxyBeacon.upgradeTo(renAssetImplementation.address));
}
// Deploy MintGatewayProxyBeacon /////////////////////////////////////////////
logger.log(chalk.yellow("MintGateway beacon"));
const mintGatewayImplementation = await create2("MintGatewayV3", []);
const existingMintGatewayProxyBeacon = await getExistingDeployment<MintGatewayProxyBeacon>(
"MintGatewayProxyBeacon"
);
const mintGatewayProxyBeacon =
existingMintGatewayProxyBeacon ||
(await create2<MintGatewayProxyBeacon__factory>("MintGatewayProxyBeacon", [
// Temporary value, gets overwritten in the next step. This is to
// ensure that the address doesn't change between networks even when
// the implementation changes.
create2IsContract ? CREATE2_DEPLOYER : mintGatewayImplementation.address,
deployer,
]));
if (Ox(await mintGatewayProxyBeacon.implementation()) !== Ox(mintGatewayImplementation.address)) {
logger.log(`Updating MintGateway implementation to ${Ox(mintGatewayImplementation.address)}`);
await waitForTx(mintGatewayProxyBeacon.upgradeTo(mintGatewayImplementation.address));
}
// Deploy LockGatewayProxyBeacon /////////////////////////////////////////////
logger.log(chalk.yellow("LockGateway beacon"));
const lockGatewayImplementation = await create2("LockGatewayV3", []);
const existingLockGatewayProxyBeacon = await getExistingDeployment<LockGatewayProxyBeacon>(
"LockGatewayProxyBeacon"
);
const lockGatewayProxyBeacon =
existingLockGatewayProxyBeacon ||
(await create2<LockGatewayProxyBeacon__factory>("LockGatewayProxyBeacon", [
// Temporary value, gets overwritten in the next step. This is to
// ensure that the address doesn't change between networks even when
// the implementation changes.
create2IsContract ? CREATE2_DEPLOYER : lockGatewayImplementation.address,
deployer,
]));
if (Ox(await lockGatewayProxyBeacon.implementation()) !== Ox(lockGatewayImplementation.address)) {
logger.log(`Updating LockGateway implementation to ${Ox(lockGatewayImplementation.address)}`);
await waitForTx(lockGatewayProxyBeacon.upgradeTo(lockGatewayImplementation.address));
}
logger.log(chalk.yellow("Signature Verifier"));
const signatureVerifier = await deployProxy<RenVMSignatureVerifierV1__factory>(
"RenVMSignatureVerifierV1",
"RenVMSignatureVerifierProxy",
{
initializer: "__RenVMSignatureVerifier_init",
constructorArgs: [chainName, mintAuthority, governanceAddress] as Parameters<
RenVMSignatureVerifierV1["__RenVMSignatureVerifier_init"]
>,
},
// isInitialized:
async (signatureVerifier) => Ox(await signatureVerifier.getMintAuthority()) === Ox(mintAuthority)
);
const signatureVerifierOwner = Ox(await signatureVerifier.owner());
if (signatureVerifierOwner !== Ox(governanceAddress)) {
logger.log(
`Transferring RenVMSignatureVerifier ownership to governance address. (Was ${signatureVerifierOwner}, changing to ${Ox(
governanceAddress
)}) Deployer: ${deployer}.`
);
await waitForTx(signatureVerifier.transferOwnership(governanceAddress));
}
logger.log(chalk.yellow("TransferWithLog"));
const transferWithLog = await create2("TransferWithLog", []);
// Deploy GatewayRegistry ////////////////////////////////////////////////////
logger.log(chalk.yellow("GatewayRegistry"));
const gatewayRegistry = await deployProxy<GatewayRegistryV2__factory>(
"GatewayRegistryV2",
"GatewayRegistryProxy",
{
initializer: "__GatewayRegistry_init",
constructorArgs: [
chainId,
signatureVerifier.address,
transferWithLog.address,
renAssetProxyBeacon.address,
mintGatewayProxyBeacon.address,
lockGatewayProxyBeacon.address,
governanceAddress,
[deployer],
] as Parameters<GatewayRegistryV2["__GatewayRegistry_init"]>,
},
async (gatewayRegistry) => {
try {
await gatewayRegistry.getSignatureVerifier();
return true;
} catch (error: any) {
return false;
}
}
);
const existingSignatureVerifier = Ox(await gatewayRegistry.getSignatureVerifier());
if (existingSignatureVerifier !== Ox(signatureVerifier.address)) {
logger.log(
`Updating signature verifier in gateway registry. Was ${existingSignatureVerifier}, updating to ${Ox(
signatureVerifier.address
)}.`
);
await waitForTx(gatewayRegistry.updateSignatureVerifier(signatureVerifier.address));
}
const existingTransferWithLog = Ox(await gatewayRegistry.getTransferContract());
if (existingTransferWithLog !== Ox(transferWithLog.address)) {
logger.log(
`Updating TransferWithLog in gateway registry. Was ${existingTransferWithLog}, updating to ${Ox(
transferWithLog.address
)}.`
);
await waitForTx(gatewayRegistry.updateTransferContract(transferWithLog.address));
}
if (Ox(await gatewayRegistry.getRenAssetProxyBeacon()) !== Ox(renAssetProxyBeacon.address)) {
throw new Error(`GatewayRegistry's renAssetProxyBeacon address is not correct.`);
}
if (Ox(await gatewayRegistry.getMintGatewayProxyBeacon()) !== Ox(mintGatewayProxyBeacon.address)) {
throw new Error(`GatewayRegistry's mintGatewayProxyBeacon address is not correct.`);
}
if (Ox(await gatewayRegistry.getLockGatewayProxyBeacon()) !== Ox(lockGatewayProxyBeacon.address)) {
throw new Error(`GatewayRegistry's lockGatewayProxyBeacon address is not correct.`);
}
if (Ox(await renAssetProxyBeacon.getProxyDeployer()) !== Ox(gatewayRegistry.address)) {
logger.log(`Granting deployer role to gateway registry in renAssetProxyBeacon.`);
await waitForTx(renAssetProxyBeacon.updateProxyDeployer(gatewayRegistry.address));
}
if ((await renAssetProxyBeacon.owner()) !== governanceAddress) {
logger.log(`Transferring renAssetProxyBeacon ownership to timelock.`);
await waitForTx(renAssetProxyBeacon.transferOwnership(governanceAddress));
}
if (Ox(await mintGatewayProxyBeacon.getProxyDeployer()) !== Ox(gatewayRegistry.address)) {
logger.log(`Granting deployer role to gateway registry in mintGatewayProxyBeacon.`);
await waitForTx(mintGatewayProxyBeacon.updateProxyDeployer(gatewayRegistry.address));
}
if ((await mintGatewayProxyBeacon.owner()) !== governanceAddress) {
logger.log(`Transferring mintGatewayProxyBeacon ownership to timelock.`);
await waitForTx(mintGatewayProxyBeacon.transferOwnership(governanceAddress));
}
if (Ox(await lockGatewayProxyBeacon.getProxyDeployer()) !== Ox(gatewayRegistry.address)) {
logger.log(`Granting deployer role to gateway registry in lockGatewayProxyBeacon.`);
await waitForTx(lockGatewayProxyBeacon.updateProxyDeployer(gatewayRegistry.address));
}
if ((await lockGatewayProxyBeacon.owner()) !== governanceAddress) {
logger.log(`Transferring lockGatewayProxyBeacon ownership to timelock.`);
await waitForTx(lockGatewayProxyBeacon.transferOwnership(governanceAddress));
}
logger.log(`Deploying contract verification helper contract.`);
const beaconProxy = await create2<BeaconProxy__factory>("BeaconProxy", [renAssetProxyBeacon!.address, []]);
const renAssetProxy = await getContractAt(hre)<RenAssetV2>("RenAssetV2", beaconProxy.address);
if ((await renAssetProxy.symbol()) === "") {
logger.log(`Initializing contract verification helper contract.`);
await waitForTx(renAssetProxy.__RenAsset_init(0, "1", "TESTDEPLOYMENT", "TESTDEPLOYMENT", 0, deployer));
}
const beaconDeployment = await deployments.get("BeaconProxy");
logger.log(`Handling ${(config.mintGateways || []).length} mint assets.`);
const prefix = config.tokenPrefix;
for (const { symbol, gateway, token, decimals, version } of config.mintGateways) {
logger.log(chalk.yellow(`Mint asset: ${symbol}`));
const existingGateway = Ox(await gatewayRegistry.getMintGatewayBySymbol(symbol));
const existingToken = Ox(await gatewayRegistry.getRenAssetBySymbol(symbol));
if ((await gatewayRegistry.getGatewayBySymbol(symbol)) === Ox0) {
const prefixedSymbol = `${prefix}${symbol}`;
if (!token) {
logger.log(
`Calling deployMintGatewayAndRenAsset(${symbol}, ${prefixedSymbol}, ${prefixedSymbol}, ${decimals}, '1')`
);
await waitForTx(
gatewayRegistry.deployMintGatewayAndRenAsset(
symbol,
prefixedSymbol,
prefixedSymbol,
decimals,
version || "1"
)
);
} else if (!gateway) {
logger.log(`Calling deployMintGateway(${symbol}, ${token}, '1')`);
await waitForTx(gatewayRegistry.deployMintGateway(symbol, token, "1"));
} else {
logger.log(`Calling addMintGateway(${symbol}, ${token}, ${gateway})`);
await waitForTx(gatewayRegistry.addMintGateway(symbol, token, gateway));
}
} else {
logger.log(`Skipping ${symbol} - ${existingGateway}, ${existingToken}!`);
}
const updatedGateway = existingGateway || Ox(await gatewayRegistry.getMintGatewayBySymbol(symbol));
const updatedToken = existingToken || Ox(await gatewayRegistry.getRenAssetBySymbol(symbol));
const gatewayLabel = `ren${symbol}_MintGateway_Proxy`;
await deployments.save(gatewayLabel, {
...beaconDeployment,
address: updatedGateway,
metadata: beaconDeployment.metadata && beaconDeployment.metadata.replace("BeaconProxy", gatewayLabel),
});
const tokenLabel = `ren${symbol}_Proxy`;
await deployments.save(tokenLabel, {
...beaconDeployment,
address: updatedToken,
metadata: beaconDeployment.metadata && beaconDeployment.metadata.replace("BeaconProxy", tokenLabel),
});
// Update signature verifier.
const gatewayInstance = await getContractAt(hre)<MintGatewayV3>("MintGatewayV3", updatedGateway);
const existingSignatureVerifier = Ox(await gatewayInstance.getSignatureVerifier());
if (existingSignatureVerifier !== Ox(signatureVerifier.address)) {
logger.log(
`Updating signature verifier in the ${symbol} mint gateway. Was ${existingSignatureVerifier}, updating to ${Ox(
signatureVerifier.address
)}.`
);
await waitForTx(gatewayInstance.updateSignatureVerifier(signatureVerifier.address));
}
// Update selector hash, by updating symbol.
const expectedSelectorHash = keccak256(
Buffer.concat([Buffer.from(symbol), Buffer.from("/to"), Buffer.from(chainName)])
);
if (expectedSelectorHash !== (await gatewayInstance.getSelectorHash())) {
await gatewayInstance.updateAsset(symbol);
}
}
// Test Tokens are deployed when a particular lock-asset doesn't exist on a
// testnet.
logger.log(`Handling ${(config.lockGateways || []).length} lock assets.`);
for (const { symbol, gateway, token, decimals } of config.lockGateways || []) {
logger.log(chalk.yellow(`Lock asset: ${symbol}`));
const existingGateway = Ox(await gatewayRegistry.getLockGatewayBySymbol(symbol));
const existingToken = Ox(await gatewayRegistry.getLockAssetBySymbol(symbol));
const totalSupply = typeof token === "object" ? token.totalSupply : undefined;
let deployedToken = typeof token === "string" ? token : "";
if (existingGateway === Ox0) {
// Check token symbol and decimals
if (token && typeof token === "string") {
const erc20 = await ethers.getContractAt<ERC20>("ERC20", token);
const erc20Symbol = await erc20.symbol();
if (erc20Symbol !== symbol && symbol !== "FTT") {
console.error(`Expected ${token.slice(0, 10)}...'s symbol to be ${symbol}, got ${erc20Symbol}`);
}
const erc20Decimals = await erc20.decimals();
if (erc20Decimals !== decimals) {
console.error(
`Expected ${token.slice(0, 10)}...'s decimals to be ${decimals}, got ${erc20Decimals}`
);
}
}
if (typeof token !== "string") {
logger.log(`Deploying TestToken(${symbol}, ${decimals}, ${totalSupply})`);
const supply = new BigNumber(
totalSupply !== undefined ? totalSupply.replace(/,/g, "") : 1000000
).shiftedBy(decimals !== undefined ? decimals : 18);
const deployedTokenInstance = await create2<TestToken__factory>("TestToken", [
symbol,
symbol,
decimals,
supply.toFixed(),
deployer,
]);
deployedToken = deployedTokenInstance.address;
}
if (!gateway) {
logger.log(`Calling deployLockGateway(${symbol}, ${deployedToken}, '1')`);
await waitForTx(gatewayRegistry.deployLockGateway(symbol, deployedToken, "1"));
} else {
logger.log(`Calling addLockGateway(${symbol}, ${deployedToken}, ${gateway})`);
await waitForTx(gatewayRegistry.addLockGateway(symbol, deployedToken, gateway));
}
} else {
logger.log(`Skipping ${symbol} - ${existingGateway}, ${existingToken}!`);
}
const updatedGateway = existingGateway || Ox(await gatewayRegistry.getLockGatewayBySymbol(symbol));
const gatewayLabel = `ren${symbol}_LockGateway_Proxy`;
await deployments.save(gatewayLabel, {
...beaconDeployment,
address: updatedGateway,
metadata: beaconDeployment.metadata && beaconDeployment.metadata.replace("BeaconProxy", gatewayLabel),
});
// Update signature verifier.
const gatewayInstance = await getContractAt(hre)<LockGatewayV3>("LockGatewayV3", updatedGateway);
const existingSignatureVerifier = Ox(await gatewayInstance.getSignatureVerifier());
if (existingSignatureVerifier !== Ox(signatureVerifier.address)) {
logger.log(
`Updating signature verifier in the ${symbol} lock gateway. Was ${existingSignatureVerifier}, updating to ${Ox(
signatureVerifier.address
)}.`
);
await waitForTx(gatewayInstance.updateSignatureVerifier(signatureVerifier.address));
}
// Update selector hash, by updating symbol.
const expectedSelectorHash = keccak256(
Buffer.concat([Buffer.from(symbol), Buffer.from("/to"), Buffer.from(chainName)])
);
if (expectedSelectorHash !== (await gatewayInstance.getSelectorHash())) {
await gatewayInstance.updateAsset(symbol);
}
}
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'BTC',
// 'renBTC',
// 'renBTC',
// 8,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'ZEC',
// 'renZEC',
// 'renZEC',
// 8,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'BCH',
// 'renBCH',
// 'renBCH',
// 8,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'DGB',
// 'renDGB',
// 'renDGB',
// 8,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'FIL',
// 'renFIL',
// 'renFIL',
// 18,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'LUNA',
// 'renLUNA',
// 'renLUNA',
// 6,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'DOGE',
// 'renDOGE',
// 'renDOGE',
// 8,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'ETH',
// 'renETH',
// 'renETH',
// 18,
// '1'
// );
// await gatewayRegistry.deployMintGatewayAndRenAsset(
// 'DAI',
// 'renDAI',
// 'renDAI',
// 18,
// '1'
// );
// await usdc.initialize('USDC', 'USDC');
// await gatewayRegistry.deployLockGateway('DAI', usdc.address, '1');
// await usdc.mint(deployer, '100', {from: deployer});
// const usdcLockGatewayAddress = await gatewayRegistry.getLockGatewayBySymbol(
// 'USDC'
// );
// const usdcGateway = await ethers.getContractAt<LockGatewayV3>(
// 'LockGatewayV3',
// usdcLockGatewayAddress,
// deployer
// );
// await usdc.approve(usdcGateway.address, '10', {from: deployer});
// await usdcGateway.lock('8123', 'Bitcoin', [], '10', {from: deployer});
logger.log("mint gateway symbols:", await gatewayRegistry.getMintGatewaySymbols(0, 0));
const lockSymbols = await gatewayRegistry.getLockGatewaySymbols(0, 0);
logger.log("lock gateway symbols:", lockSymbols);
for (const lockSymbol of lockSymbols) {
const lockToken = await gatewayRegistry.getLockAssetBySymbol(lockSymbol);
logger.log(`${lockSymbol}: ${lockToken}`);
}
const basicBridge = await create2<BasicBridge__factory>("BasicBridge", [gatewayRegistry.address]);
return {
gatewayRegistry,
basicBridge,
signatureVerifier,
};
}
Example #11
Source File: deploymentUtils.ts From gateway-sol with GNU General Public License v3.0 | 5 votes |
setupCreate2 =
(hre: HardhatRuntimeEnvironment, create2SaltOverride?: string, logger: ConsoleInterface = console) =>
async <
F extends ContractFactory,
C extends F extends { deploy: (...args: any) => Promise<infer C> } ? C : never = F extends {
deploy: (...args: any) => Promise<infer C>;
}
? C
: never
>(
name: string,
args: F extends { deploy: (...args: infer X) => Promise<any> } ? X : never,
overrides?: CallOptions,
create2SaltOverrideAlt?: string
): Promise<F extends { deploy: (...args: any) => Promise<infer C> } ? C : never> => {
const { deployments, getNamedAccounts, ethers, network } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const salt = keccak256(Buffer.from(create2SaltOverrideAlt || create2SaltOverride || create2Salt(network.name)));
logger.log(`Deploying ${name} from ${deployer} (salt: keccak256(${create2Salt(network.name)}))`);
const result = await deploy(name, {
from: deployer,
args: args,
log: true,
deterministicDeployment: salt,
skipIfAlreadyDeployed: true,
...overrides,
});
logger.log(`Deployed ${name} at ${result.address}.`);
const contract = await ethers.getContractAt<C>(name, result.address, deployer);
let owner;
try {
owner = await (contract as any as Ownable).owner();
} catch (error) {}
if (owner && owner.toLowerCase() === CREATE2_DEPLOYER) {
throw new Error(`${name}'s owner was initialized to CREATE2 deployer!`);
}
let roleAdmin;
try {
roleAdmin = await (contract as any as AccessControlEnumerableUpgradeable).getRoleAdmin(
await (contract as any as AccessControlEnumerableUpgradeable).DEFAULT_ADMIN_ROLE()
);
} catch (error) {}
if (roleAdmin && roleAdmin.toLowerCase() === CREATE2_DEPLOYER) {
throw new Error(`${name}'s role admin was initialized to CREATE2 deployer!`);
}
return contract;
}
Example #12
Source File: transfer.ts From hubble-contracts with MIT License | 5 votes |
hash() {
return keccak256(this.serialize());
}