Skip to content

Commit

Permalink
Merge pull request SocketDotTech#109 from SocketDotTech/fix/deployScr…
Browse files Browse the repository at this point in the history
…iptFixes

Fix/deploy script fixes
  • Loading branch information
tHeMaskedMan981 authored Jun 6, 2024
2 parents f1557b7 + 5c2bd82 commit a2203b2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"compile"
],
"dependencies": {
"@socket.tech/dl-core": "^2.7.0",
"@socket.tech/dl-core": "^2.9.0",
"lodash": "^4.17.21",
"prompts": "^2.4.2"
}
Expand Down
33 changes: 29 additions & 4 deletions script/helpers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const getHookContract = async (
) => {
const socketSigner = getSignerFromChainSlug(chain);

let contract: Contract,
let contract: Contract | undefined,
address: string = "",
contractName: string = "";

Expand Down Expand Up @@ -211,8 +211,34 @@ export const checkAndGrantRole = async (
roleHash: string = "",
userAddress: string
) => {
let hasRole: boolean | undefined;

// Do checks first
try {
// Check first if the contract has the function `hasRole`
hasRole = await contract.hasRole(roleHash, userAddress);

// Get owner and signer
const owner = await contract.owner();
const signer = getSignerFromChainSlug(chain);
console.log({ owner, signer });

// Check if the signer is the owner
if (owner !== signer.address) {
console.log(
`✔ Signer is not the owner of the contract, ask the owner to grant the role`
);
return; // Exit the function if the signer is not the owner
}
} catch (error) {
console.log(
"✔ Contract does not have the function `hasRole`, using custom contract, check with owner"
);
return; // Exit the function if the contract does not have the function `hasRole`
}

// Grant the role if the user does not have it
try {
let hasRole = await contract.hasRole(roleHash, userAddress);
if (!hasRole) {
console.log(
`Adding ${roleName} role to signer`,
Expand All @@ -231,8 +257,7 @@ export const checkAndGrantRole = async (
}
} catch (error) {
console.log(
"Error, while granting role. You might be using an already Deployed contract, please ask the owner to grant the role.",
error
"✗ Error, while granting role. You might be using an already Deployed contract, please ask the owner to grant the role."
);
}
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@
"@sentry/types" "5.30.0"
tslib "^1.9.3"

"@socket.tech/dl-core@^2.7.0":
version "2.7.0"
resolved "https://registry.yarnpkg.com/@socket.tech/dl-core/-/dl-core-2.7.0.tgz#4272f8e67561fd38555711c9ae021ede064a9e33"
integrity sha512-sqTobJYfY/hxK7U0IYqtvlMMPJW5rVNTCJEZBIk6UEoj5YcMz7NB6MXSBRvVE0LoZhvEJmgP1EeqSeqZ9tFlBA==
"@socket.tech/dl-core@^2.9.0":
version "2.9.0"
resolved "https://registry.yarnpkg.com/@socket.tech/dl-core/-/dl-core-2.9.0.tgz#676744f3a2cb6b2c07b7bb281154b0e97359f562"
integrity sha512-fdejzQNDrNclT9dqQkUfbeqrn96NkBwiTSfl7GJxRwfC66uY1F+V3+XRyrfO30NKTh+HXHSljkjUo97wLar13Q==
dependencies:
axios "^1.3.6"
prompts "^2.4.2"
Expand Down

0 comments on commit a2203b2

Please sign in to comment.