Skip to content

Commit

Permalink
Stop using functions before define
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed Sep 18, 2023
1 parent 4f9982b commit 3683226
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 103 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = {
"never"
],

"no-use-before-define": "warn",
"no-warning-comments": "warn",
"prefer-destructuring": "warn",
"radix": "warn",
Expand Down
56 changes: 27 additions & 29 deletions src/contractFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,34 +73,6 @@ const updateManifest = async (
);
};

export const getContractFactoryAndUpdateManifest = async (contract: string) => {
const {linkReferences} = await artifacts.readArtifact(contract);
if (!Object.keys(linkReferences).length) {
return await ethers.getContractFactory(contract);
}

const manifest = await getSkaleManifest();

const {
librariesToUpgrade,
oldLibraries
} = await getLibrariesToUpgrade(
manifest,
linkReferences
);
const libraries = await deployLibraries(librariesToUpgrade);
await updateManifest(
manifest,
libraries,
oldLibraries
);
return await getLinkedContractFactory(
contract,
libraries
);
};


export const getLibrariesNames = (linkReferences: LinkReferences) => {
const libraryNames = [];
for (const libraryFile of Object.values(linkReferences)) {
Expand All @@ -109,7 +81,6 @@ export const getLibrariesNames = (linkReferences: LinkReferences) => {
return libraryNames;
};


const getLibrariesToUpgrade = async (
manifest: SkaleManifestData,
linkReferences: LinkReferences
Expand All @@ -136,3 +107,30 @@ const getLibrariesToUpgrade = async (
oldLibraries
};
};

export const getContractFactoryAndUpdateManifest = async (contract: string) => {
const {linkReferences} = await artifacts.readArtifact(contract);
if (!Object.keys(linkReferences).length) {
return await ethers.getContractFactory(contract);
}

const manifest = await getSkaleManifest();

const {
librariesToUpgrade,
oldLibraries
} = await getLibrariesToUpgrade(
manifest,
linkReferences
);
const libraries = await deployLibraries(librariesToUpgrade);
await updateManifest(
manifest,
libraries,
oldLibraries
);
return await getLinkedContractFactory(
contract,
libraries
);
};
146 changes: 73 additions & 73 deletions src/gnosis-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,6 @@ const defaultOptions = {
"refundReceiver": ethers.constants.AddressZero
};

// Public functions

export const createMultiSendTransaction = async (
safeAddress: string,
transactions: UnsignedTransaction[]
) => {
const safeTransactionData = getSafeTransactionData(transactions);
const safeService = await getSafeService();
const nonce = await safeService.getNextNonce(safeAddress);
console.log(
"Will send tx to Gnosis with nonce",
nonce
);

const options = {
...defaultOptions,
...{

/*
* Nonce of the Safe,
* Transaction cannot be executed until
* Safe's nonce is not equal to this nonce
*/
nonce
}
};
const ethAdapter = await getEthAdapter();
const safeSdk = await Safe.create({
ethAdapter,
safeAddress
});
const safeTransaction = await safeSdk.createTransaction({
safeTransactionData,
options
});

await estimateSafeTransaction(
safeAddress,
safeTransactionData
);

await proposeTransaction(
safeAddress,
safeTransaction
);
};

// Private functions

const getSafeTransactionData = (transactions: UnsignedTransaction[]) => {
Expand All @@ -109,6 +62,37 @@ const getSafeTransactionData = (transactions: UnsignedTransaction[]) => {
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) => {
if (Object.keys(URLS.safe_transaction).includes(chainId.toString())) {
return URLS.safe_transaction[
chainId as keyof typeof URLS.safe_transaction
];
}
throw Error("Can't get safe-transaction url" +
` at network with chainId = ${chainId}`);
};

const getSafeService = async () => {
const
{chainId} = await ethers.provider.getNetwork();
const ethAdapter: EthersAdapter = await getEthAdapter();
const safeService = new SafeApiKit({
"txServiceUrl": getSafeTransactionUrl(chainId),
ethAdapter
});
return safeService;
};

const estimateSafeTransaction = async (
safeAddress: string,
safeTransactionData: SafeTransactionDataPartial | MetaTransactionData[]
Expand Down Expand Up @@ -154,33 +138,49 @@ const proposeTransaction = async (
});
};

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

const getSafeService = async () => {
const
{chainId} = await ethers.provider.getNetwork();
const ethAdapter: EthersAdapter = await getEthAdapter();
const safeService = new SafeApiKit({
"txServiceUrl": getSafeTransactionUrl(chainId),
ethAdapter
export const createMultiSendTransaction = async (
safeAddress: string,
transactions: UnsignedTransaction[]
) => {
const safeTransactionData = getSafeTransactionData(transactions);
const safeService = await getSafeService();
const nonce = await safeService.getNextNonce(safeAddress);
console.log(
"Will send tx to Gnosis with nonce",
nonce
);

const options = {
...defaultOptions,
...{

/*
* Nonce of the Safe,
* Transaction cannot be executed until
* Safe's nonce is not equal to this nonce
*/
nonce
}
};
const ethAdapter = await getEthAdapter();
const safeSdk = await Safe.create({
ethAdapter,
safeAddress
});
const safeTransaction = await safeSdk.createTransaction({
safeTransactionData,
options
});
return safeService;
};

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

await proposeTransaction(
safeAddress,
safeTransaction
);
};

0 comments on commit 3683226

Please sign in to comment.