|
|
@@ -23,10 +23,9 @@ import {
|
|
|
* with the deployedCode property generated by truffle builds
|
|
|
*/
|
|
|
export async function getCodeDigestWithoutAddress(
|
|
|
- rpcUrl: string,
|
|
|
+ web3: Web3,
|
|
|
address: string
|
|
|
): Promise<string> {
|
|
|
- const web3 = new Web3(rpcUrl);
|
|
|
const code = await web3.eth.getCode(address);
|
|
|
const strippedCode = code.replaceAll(
|
|
|
address.toLowerCase().replace("0x", ""),
|
|
|
@@ -70,7 +69,7 @@ export class EvmWormholeContract extends WormholeContract {
|
|
|
super();
|
|
|
}
|
|
|
getContract(): Contract {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return new web3.eth.Contract(WORMHOLE_ABI, this.address);
|
|
|
}
|
|
|
|
|
|
@@ -99,7 +98,7 @@ export class EvmWormholeContract extends WormholeContract {
|
|
|
}
|
|
|
|
|
|
async upgradeGuardianSets(senderPrivateKey: PrivateKey, vaa: Buffer) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
const wormholeContract = new web3.eth.Contract(WORMHOLE_ABI, this.address);
|
|
|
const transactionObject = wormholeContract.methods.submitNewGuardianSet(
|
|
|
@@ -222,7 +221,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
): Promise<Buffer> {
|
|
|
// Executor contract is the owner of entropy contract
|
|
|
const executorAddr = await this.getOwner();
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const executor = new web3.eth.Contract(EXECUTOR_ABI, executorAddr);
|
|
|
const data = executor.methods.upgradeTo(newImplementation).encodeABI();
|
|
|
return this.chain.generateExecutorPayload(executorAddr, executorAddr, data);
|
|
|
@@ -252,7 +251,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
}
|
|
|
|
|
|
getContract() {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return new web3.eth.Contract(EXTENDED_ENTROPY_ABI, this.address);
|
|
|
}
|
|
|
|
|
|
@@ -327,7 +326,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
sequenceNumber: number,
|
|
|
senderPrivateKey: PrivateKey
|
|
|
) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
// can not use `this.getContract()` because it uses another web3 instance without the wallet
|
|
|
const contract = new web3.eth.Contract(EXTENDED_ENTROPY_ABI, this.address);
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
@@ -343,7 +342,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
}
|
|
|
|
|
|
generateUserRandomNumber() {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return web3.utils.randomHex(32);
|
|
|
}
|
|
|
|
|
|
@@ -358,7 +357,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
senderPrivateKey: PrivateKey,
|
|
|
withCallback?: boolean
|
|
|
) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const userCommitment = web3.utils.keccak256(userRandomNumber);
|
|
|
const contract = new web3.eth.Contract(EXTENDED_ENTROPY_ABI, this.address);
|
|
|
const fee = await contract.methods.getFee(provider).call();
|
|
|
@@ -392,7 +391,7 @@ export class EvmEntropyContract extends Storable {
|
|
|
sequenceNumber: string,
|
|
|
senderPrivateKey: PrivateKey
|
|
|
) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const contract = new web3.eth.Contract(EXTENDED_ENTROPY_ABI, this.address);
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
const transactionObject = contract.methods.reveal(
|
|
|
@@ -486,7 +485,7 @@ export class EvmExpressRelayContract extends Storable {
|
|
|
}
|
|
|
|
|
|
getContract() {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return new web3.eth.Contract(EXPRESS_RELAY_ABI, this.address);
|
|
|
}
|
|
|
}
|
|
|
@@ -499,7 +498,7 @@ export class EvmExecutorContract {
|
|
|
}
|
|
|
|
|
|
async getWormholeContract(): Promise<EvmWormholeContract> {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
//Unfortunately, there is no public method to get the wormhole address
|
|
|
//Found 251 by using `forge build --extra-output storageLayout` and finding the slot for the wormhole variable.
|
|
|
let address = await web3.eth.getStorageAt(this.address, 251);
|
|
|
@@ -508,7 +507,7 @@ export class EvmExecutorContract {
|
|
|
}
|
|
|
|
|
|
getContract() {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return new web3.eth.Contract(EXECUTOR_ABI, this.address);
|
|
|
}
|
|
|
|
|
|
@@ -542,7 +541,7 @@ export class EvmExecutorContract {
|
|
|
senderPrivateKey: PrivateKey,
|
|
|
vaa: Buffer
|
|
|
) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
const executorContract = new web3.eth.Contract(EXECUTOR_ABI, this.address);
|
|
|
const transactionObject = executorContract.methods.execute(
|
|
|
@@ -589,7 +588,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
|
|
|
}
|
|
|
|
|
|
getContract() {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const pythContract = new web3.eth.Contract(EXTENDED_PYTH_ABI, this.address);
|
|
|
return pythContract;
|
|
|
}
|
|
|
@@ -599,12 +598,12 @@ export class EvmPriceFeedContract extends PriceFeedContract {
|
|
|
*/
|
|
|
async getCode(): Promise<string> {
|
|
|
// TODO: handle proxy contracts
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
return web3.eth.getCode(this.address);
|
|
|
}
|
|
|
|
|
|
async getImplementationAddress(): Promise<string> {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1) according to EIP-1967
|
|
|
const storagePosition =
|
|
|
"0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
|
|
|
@@ -617,11 +616,11 @@ export class EvmPriceFeedContract extends PriceFeedContract {
|
|
|
* Returns the keccak256 digest of the contract bytecode
|
|
|
*/
|
|
|
async getCodeDigestWithoutAddress(): Promise<string> {
|
|
|
- return getCodeDigestWithoutAddress(this.chain.getRpcUrl(), this.address);
|
|
|
+ return getCodeDigestWithoutAddress(this.chain.getWeb3(), this.address);
|
|
|
}
|
|
|
|
|
|
async getTotalFee(): Promise<TokenQty> {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const amount = BigInt(await web3.eth.getBalance(this.address));
|
|
|
return {
|
|
|
amount,
|
|
|
@@ -712,7 +711,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
|
|
|
}
|
|
|
|
|
|
async executeUpdatePriceFeed(senderPrivateKey: PrivateKey, vaas: Buffer[]) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
const pythContract = new web3.eth.Contract(EXTENDED_PYTH_ABI, this.address);
|
|
|
const priceFeedUpdateData = vaas.map((vaa) => "0x" + vaa.toString("hex"));
|
|
|
@@ -732,7 +731,7 @@ export class EvmPriceFeedContract extends PriceFeedContract {
|
|
|
senderPrivateKey: PrivateKey,
|
|
|
vaa: Buffer
|
|
|
) {
|
|
|
- const web3 = new Web3(this.chain.getRpcUrl());
|
|
|
+ const web3 = this.chain.getWeb3();
|
|
|
const { address } = web3.eth.accounts.wallet.add(senderPrivateKey);
|
|
|
const pythContract = new web3.eth.Contract(EXTENDED_PYTH_ABI, this.address);
|
|
|
const transactionObject = pythContract.methods.executeGovernanceInstruction(
|