Skip to content

Commit

Permalink
Move to ethers v6
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Jun 21, 2024
1 parent 1559b4a commit 34f964b
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 2,656 deletions.
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "@typechain/hardhat";
import "@nomiclabs/hardhat-ethers";
import "@nomicfoundation/hardhat-ethers";
import "@openzeppelin/hardhat-upgrades";
import {HardhatUserConfig} from "hardhat/config";

Expand All @@ -10,7 +10,7 @@ const coreArtifacts =
const config: HardhatUserConfig = {
"typechain": {
"externalArtifacts": [coreArtifacts],
"target": "ethers-v5"
"target": "ethers-v6"
}
};

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@
"devDependencies": {
"@openzeppelin/contracts-upgradeable": "^4.4.2",
"@tsconfig/recommended": "^1.0.2",
"@typechain/ethers-v5": "^9.0.0",
"@typechain/hardhat": "^8.0.0",
"@typechain/ethers-v6": "^0.5.1",
"@typechain/hardhat": "^9.1.0",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"cspell": "^8.8.3",
"eslint": "^8.15.0",
"install-peers-cli": "^2.2.0",
"ts-node": "^10.5.0",
"typechain": "^8.2.0",
"typechain": "^8.3.2",
"typescript": "^5.1.6"
},
"dependencies": {
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.2.0",
"@safe-global/safe-core-sdk-types": "^2.2.0",
"@skalenetwork/skale-contracts-ethers-v5": "^1.0.1-develop.0",
"@safe-global/api-kit": "^2.4.1",
"@safe-global/protocol-kit": "^4.0.1",
"@safe-global/safe-core-sdk-types": "^5.0.1",
"@skalenetwork/skale-contracts-ethers-v6": "^1.0.0",
"axios": "^1.4.0",
"ethereumjs-util": "^7.1.4"
},
"peerDependencies": {
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-verify": "^1.1.1",
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@openzeppelin/hardhat-upgrades": "^1.14.0",
"@openzeppelin/hardhat-upgrades": "^3.1.1",
"@openzeppelin/upgrades-core": "^1.27.1",
"@types/mocha": "^9.1.0",
"ethers": "^5.7.2",
"hardhat": "^2.16.1"
"ethers": "^6.1.0",
"hardhat": "^2.9.9"
}
}
4 changes: 2 additions & 2 deletions src/abi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Interface} from "ethers/lib/utils";
import {Interface} from "ethers";

export const getAbi = (contractInterface: Interface) => {
const abi = JSON.parse(contractInterface.format("json") as string) as [];
const abi = JSON.parse(contractInterface.formatJson()) as [];

abi.forEach((obj: {type: string}) => {
if (obj.type === "function") {
Expand Down
4 changes: 2 additions & 2 deletions src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const deployLibrary = async (
const Library = await ethers.getContractFactory(libraryName);
const library = await Library.
deploy({"nonce": nonceProvider.reserveNonce()});
await library.deployed();
return library.address;
await library.waitForDeployment()
return await library.getAddress();
};

export const deployLibraries = async (
Expand Down
93 changes: 54 additions & 39 deletions src/gnosis-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,52 @@ import {
SafeTransaction,
SafeTransactionDataPartial
} from "@safe-global/safe-core-sdk-types";
import Safe, {EthersAdapter} from "@safe-global/protocol-kit";
import {Network, Transaction} from "ethers";
import {ethers, network} from "hardhat";
import Safe from "@safe-global/protocol-kit";
import SafeApiKit from "@safe-global/api-kit";
import {UnsignedTransaction} from "ethers";
import chalk from "chalk";
import {ethers} from "hardhat";
import {getNetwork} from "@ethersproject/networks";

// Cspell:words arbitrum celo sepolia xdai


// Constants

const URLS = {
"safe_transaction": {
[getNetwork("mainnet").chainId]:
[Network.from("mainnet").chainId.toString()]:
"https://safe-transaction-mainnet.safe.global",
[getNetwork("goerli").chainId]:
"https://safe-transaction-goerli.safe.global"
[Network.from("arbitrum").chainId.toString()]:
"https://safe-transaction-arbitrum.safe.global",
[Network.from("aurora").chainId.toString()]:
"https://safe-transaction-aurora.safe.global",
[Network.from("avalanche").chainId.toString()]:
"https://safe-transaction-avalanche.safe.global",
[Network.from("base").chainId.toString()]:
"https://safe-transaction-base.safe.global",
[Network.from("base-sepolia").chainId.toString()]:
"https://safe-transaction-base-sepolia.safe.global",
[Network.from("bnb").chainId.toString()]:
"https://safe-transaction-bsc.safe.global",
[Network.from("celo").chainId.toString()]:
"https://safe-transaction-celo.safe.global",
[Network.from("xdai").chainId.toString()]:
"https://safe-transaction-gnosis-chain.safe.global",
[Network.from("optimism").chainId.toString()]:
"https://safe-transaction-optimism.safe.global",
[Network.from("matic").chainId.toString()]:
"https://safe-transaction-polygon.safe.global",
// Polygon zkEVM
"1101":
"https://safe-transaction-zkevm.safe.global",
// ZkSync Era Mainnet
"324":
"https://safe-transaction-zksync.safe.global",
// Scroll
"534352":
"https://safe-transaction-scroll.safe.global",
[Network.from("sepolia").chainId.toString()]:
"https://safe-transaction-sepolia.safe.global",
}
};

Expand All @@ -39,56 +69,45 @@ const defaultOptions = {
* to be used as a refund to the sender,
* if `null` is Ether
*/
"gasToken": ethers.constants.AddressZero,
"gasToken": ethers.ZeroAddress,

// Address of receiver of gas payment (or `null` if tx.origin)
"refundReceiver": ethers.constants.AddressZero,
"refundReceiver": ethers.ZeroAddress,

// Max gas to use in the transaction
"safeTxGas": "0"
};

// Private functions

const getSafeTransactionData = (transactions: UnsignedTransaction[]) => {
const getSafeTransactionData = (transactions: Transaction[]) => {
const safeTransactionData: MetaTransactionData[] = [];
for (const transaction of transactions) {
safeTransactionData.push({
"data": transaction.data?.toString() ?? "0x",
"data": transaction.data,
"operation": OperationType.Call,
"to": transaction.to ?? ethers.constants.AddressZero,
"value": transaction.value?.toString() ?? "0"
"to": transaction.to ?? ethers.ZeroAddress,
"value": transaction.value.toString()
});
}
return safeTransactionData;
};

const getEthAdapter = async (): Promise<EthersAdapter> => {
const
[safeOwner] = await ethers.getSigners();
const ethAdapter = new EthersAdapter({
ethers,
"signerOrProvider": safeOwner
});
return ethAdapter;
};

const getSafeTransactionUrl = (chainId: number) => {
const getSafeTransactionUrl = (chainId: bigint) => {
if (Object.keys(URLS.safe_transaction).includes(chainId.toString())) {
return URLS.safe_transaction[
chainId as keyof typeof URLS.safe_transaction
Number(chainId) as keyof typeof URLS.safe_transaction
];
}
throw Error("Can't get safe-transaction url" +
throw Error("Can't get Safe Transaction Service url" +
` at network with chainId = ${chainId}`);
};

const getSafeService = async () => {
const
{chainId} = await ethers.provider.getNetwork();
const ethAdapter: EthersAdapter = await getEthAdapter();
const safeService = new SafeApiKit({
ethAdapter,
chainId,
"txServiceUrl": getSafeTransactionUrl(chainId)
});
return safeService;
Expand Down Expand Up @@ -122,13 +141,10 @@ const proposeTransaction = async (
safeAddress: string,
safeTransaction: SafeTransaction
) => {
const
[safeOwner] = await ethers.getSigners();
const ethAdapter = await getEthAdapter();
const safeSdk = await Safe.create({ethAdapter,
safeAddress});
const [safeOwner] = await ethers.getSigners();
const safeSdk = await Safe.init({provider: network.provider, safeAddress});
const safeTxHash = await safeSdk.getTransactionHash(safeTransaction);
const senderSignature = await safeSdk.signTransactionHash(safeTxHash);
const senderSignature = await safeSdk.signHash(safeTxHash);
const safeService = await getSafeService();
await safeService.proposeTransaction({
safeAddress,
Expand All @@ -143,7 +159,7 @@ const proposeTransaction = async (

export const createMultiSendTransaction = async (
safeAddress: string,
transactions: UnsignedTransaction[]
transactions: Transaction[]
) => {
const safeTransactionData = getSafeTransactionData(transactions);
const safeService = await getSafeService();
Expand All @@ -165,14 +181,13 @@ export const createMultiSendTransaction = async (
nonce
}
};
const ethAdapter = await getEthAdapter();
const safeSdk = await Safe.create({
ethAdapter,
const safeSdk = await Safe.init({
provider: network.provider,
safeAddress
});
const safeTransaction = await safeSdk.createTransaction({
options,
safeTransactionData
transactions: safeTransactionData
});

await estimateSafeTransaction(
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./abi";
export * from "./deploy";
export * from "./gnosis-safe";
export * from "./multiSend";
export * from "./submitters";
export * from "./verification";
export * from "./version";
Expand Down
63 changes: 0 additions & 63 deletions src/multiSend.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/nonceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class NonceProvider {
}

static async createForWallet (signer: Signer) {
return new NonceProvider(await signer.getTransactionCount());
return new NonceProvider(await signer.getNonce());
}

reserveNonce () {
Expand Down
Loading

0 comments on commit 34f964b

Please sign in to comment.