Skip to content

Commit

Permalink
fix(envs): pass brovider url to snapshot.js lib (#4170)
Browse files Browse the repository at this point in the history
* fix(envs): pass brovider url to snapshot.js lib

* fix(deps): upgrade snapshot.js to 0.5.6

---------

Co-authored-by: Chaitanya <yourchaitu@gmail.com>
  • Loading branch information
Todmy and ChaituVR authored Aug 28, 2023
1 parent b76d583 commit 89c9f85
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@shutter-network/shutter-crypto": "0.1.0-beta.3",
"@snapshot-labs/lock": "^0.2.0",
"@snapshot-labs/pineapple": "^0.2.0",
"@snapshot-labs/snapshot.js": "^0.5.5",
"@snapshot-labs/snapshot.js": "^0.5.6",
"@snapshot-labs/tune": "^0.1.33",
"@vue/apollo-composable": "4.0.0-beta.4",
"@vueuse/core": "^10.4.0",
Expand Down
8 changes: 6 additions & 2 deletions src/composables/useDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ export function useDelegate() {
const txPendingId = createPendingTransaction();
try {
let ethAddress = address;
if (validEnsTlds.includes(address.split('.').pop()))
ethAddress = await getProvider('1').resolveName(address);
if (validEnsTlds.includes(address.split('.').pop())) {
const networkId = import.meta.env.VITE_DEFAULT_NETWORK;
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider(networkId, { broviderUrl });
ethAddress = await provider.resolveName(address);
}
const tx = await sendTransaction(
auth.web3,
contractAddress,
Expand Down
3 changes: 2 additions & 1 deletion src/composables/useGnosis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const defaultNetwork = import.meta.env.VITE_DEFAULT_NETWORK;

const getSafeVersion = useMemoize(
async (networkKey: string, account: string) => {
const provider = utils.getProvider(networkKey);
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = utils.getProvider(networkKey, { broviderUrl });
const code = await provider.getCode(account);

if (code === '0x') return undefined;
Expand Down
6 changes: 4 additions & 2 deletions src/composables/useQuorum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface QuorumProps {
results: Results;
}

const broviderUrl = import.meta.env.VITE_BROVIDER_URL;

export function useQuorum(props: QuorumProps) {
const loading = ref(false);
const quorum = ref(0);
Expand Down Expand Up @@ -74,7 +76,7 @@ export function useQuorum(props: QuorumProps) {
);
const requests: Promise<any>[] = strategies.map(s =>
call(
getProvider(s.network),
getProvider(s.network, { broviderUrl }),
[s.methodABI],
[s.address, s.methodABI.name],
{ blockTag: blocks[s.network] }
Expand All @@ -100,7 +102,7 @@ export function useQuorum(props: QuorumProps) {
async function loadQuorum() {
loading.value = true;
quorum.value = await getQuorum(
getProvider(props.space.network),
getProvider(props.space.network, { broviderUrl }),
props.space.plugins.quorum,
props.proposal.snapshot
);
Expand Down
5 changes: 4 additions & 1 deletion src/composables/useSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export function useSnapshot() {
try {
isLoading.value = true;
error.value = false;
const currentBlock = await getBlockNumber(getProvider(network));
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const currentBlock = await getBlockNumber(
getProvider(network, { broviderUrl })
);
console.log('Snapshot block number', currentBlock);
return currentBlock - 4;
} catch (e) {
Expand Down
8 changes: 6 additions & 2 deletions src/composables/useSpaceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const pendingENSRecord = ref(false);
const ensOwner = ref<string | null>(null);
const spaceController = ref<string | null>(null);
const defaultNetwork = import.meta.env.VITE_DEFAULT_NETWORK;
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;

export function useSpaceController() {
const { web3, web3Account } = useWeb3();
Expand Down Expand Up @@ -78,13 +79,16 @@ export function useSpaceController() {
}

async function loadEnsOwner() {
ensOwner.value = await getEnsOwner(ensAddress.value, defaultNetwork);
ensOwner.value = await getEnsOwner(ensAddress.value, defaultNetwork, {
broviderUrl
});
}

async function loadSpaceController() {
spaceController.value = await getSpaceController(
ensAddress.value,
defaultNetwork
defaultNetwork,
{ broviderUrl }
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/composables/useTxStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export function useTxStatus() {
if (Date.now() > tx.createdAt + 1000 * 60)
return removePendingTransaction(tx.id);
try {
const provider = getProvider(tx.network);
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider(tx.network, { broviderUrl });
await provider.waitForTransaction(tx.hash, 1, 1000 * 60 * 4);
} finally {
removePendingTransaction(tx.id);
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/lensResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class LensResolver {

get multi() {
if (!this._multicaller) {
this._multicaller = new Multicaller(network, getProvider(network), abi);
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider(network, { broviderUrl });
this._multicaller = new Multicaller(network, provider, abi);
}
return this._multicaller;
}
Expand Down
10 changes: 8 additions & 2 deletions src/helpers/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import Multicaller from '@snapshot-labs/snapshot.js/src/utils/multicaller';
import { getAddress } from '@ethersproject/address';
import { resolveLensAddresses } from './lensResolver';

const broviderUrl = import.meta.env.VITE_BROVIDER_URL;

async function ensReverseRecordRequest(addresses) {
const network = '1';
const provider = getProvider(network);
const provider = getProvider(network, { broviderUrl });
const abi = [
'function getNames(address[] addresses) view returns (string[] r)'
];
Expand Down Expand Up @@ -46,7 +48,11 @@ async function udReverseRecordRequest(addresses) {
];

try {
const multi = new Multicaller(network, getProvider(network), abi);
const multi = new Multicaller(
network,
getProvider(network, { broviderUrl }),
abi
);
addresses.forEach(address => {
address = getAddress(address);
multi.call(
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export function urlify(text: string, target = '_blank') {

export async function resolveEns(handle: string) {
try {
const provider = getProvider('1');
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider('1', { broviderUrl });
const addressResolved = await provider.resolveName(handle);
if (!addressResolved) throw new Error('Invalid ENS name');
return addressResolved;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/gnosis/components/CustomBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default {
async created() {
this.loading = true;
const network = this.proposalConfig.network || '1';
const provider = getProvider(network);
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider(network, { broviderUrl });
this.baseToken = await this.plugin.getTokenInfo(
provider,
this.proposalConfig.baseTokenAddress
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/safeSnap/components/Modal/OptionApproval.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export default {
try {
this.criteriaLink = await getEnsTextRecord(
this.spaceId,
'daorequirements'
'daorequirements',
'1',
{ broviderUrl: import.meta.env.VITE_BROVIDER_URL }
);
} catch (err) {
console.warn(
Expand Down
11 changes: 6 additions & 5 deletions src/plugins/safeSnap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export * from './utils/realityETH';
export * from './utils/transactions';
export * from './utils/realityModule';

const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
export default class Plugin {
validateTransaction(transaction: SafeTransaction) {
const addressEmptyOrValidate =
Expand Down Expand Up @@ -100,7 +101,7 @@ export default class Plugin {
proposalId: string,
txHashes: string[]
): Promise<Omit<RealityOracleProposal, 'transactions'>> {
const provider: StaticJsonRpcProvider = getProvider(network);
const provider: StaticJsonRpcProvider = getProvider(network, { broviderUrl });
const question = await buildQuestion(proposalId, txHashes);
const questionHash = solidityKeccak256(['string'], [question]);

Expand Down Expand Up @@ -139,14 +140,14 @@ export default class Plugin {
}

async getModuleDetailsReality(network: string, moduleAddress: string) {
const provider: StaticJsonRpcProvider = getProvider(network);
const provider: StaticJsonRpcProvider = getProvider(network, { broviderUrl });
return getModuleDetailsReality(provider, network, moduleAddress);
}

async validateUmaModule(network: string, umaAddress: string) {
if (!isAddress(umaAddress)) return 'reality';

const provider: StaticJsonRpcProvider = getProvider(network);
const provider: StaticJsonRpcProvider = getProvider(network, { broviderUrl });
const moduleContract = new Contract(umaAddress, UMA_MODULE_ABI, provider);

return moduleContract
Expand Down Expand Up @@ -209,7 +210,7 @@ export default class Plugin {
explanation: string,
transactions: any
) {
const provider: StaticJsonRpcProvider = getProvider(network);
const provider: StaticJsonRpcProvider = getProvider(network, { broviderUrl });
try {
// try optimized calls, which use the graph over web3 event queries
return await getModuleDetailsUmaGql(
Expand Down Expand Up @@ -278,7 +279,7 @@ export default class Plugin {
block: string
) {
const contract = new Contract(oracleAddress, ORACLE_ABI, web3);
const provider: StaticJsonRpcProvider = getProvider(network);
const provider: StaticJsonRpcProvider = getProvider(network, { broviderUrl });
const account = (await web3.listAccounts())[0];

const [[userBalance], [bestAnswer], [historyHash], [isFinalized]] =
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/safeSnap/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const mustBeEthereumAddress = memoize((address: string) => {

export const mustBeEthereumContractAddress = memoize(
async (network: string, address: string) => {
const provider = getProvider(network) as JsonRpcProvider;
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = getProvider(network, { broviderUrl }) as JsonRpcProvider;
const contractCode = await provider.getCode(address);

return (
Expand Down
3 changes: 2 additions & 1 deletion src/views/PlaygroundView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ async function loadSnapshotBlockNumber() {
loading.value = true;
scores.value = null;
networkError.value = false;
const provider = await getProvider(form.value.network);
const broviderUrl = import.meta.env.VITE_BROVIDER_URL;
const provider = await getProvider(form.value.network, { broviderUrl });
const blockNumber = await getBlockNumber(provider);
form.value.snapshot = blockNumber.toString();
loading.value = false;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1869,10 +1869,10 @@
dependencies:
cross-fetch "^3.1.5"

"@snapshot-labs/snapshot.js@^0.5.5":
version "0.5.5"
resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot.js/-/snapshot.js-0.5.5.tgz#1ad759ae1c6504ad2d506ddb6f71756151847622"
integrity sha512-JNBGdqim9+IriPRv0R8vhLe3ojVv7i2R1qrx6PxQCbdHwiBr7d7Npei+h8VpnzOKYcVzPAkttOedxDvxxR2wnA==
"@snapshot-labs/snapshot.js@^0.5.6":
version "0.5.6"
resolved "https://registry.yarnpkg.com/@snapshot-labs/snapshot.js/-/snapshot.js-0.5.6.tgz#e8fa4786bfc1fd69c5093d31e65b60ad2f0c5f65"
integrity sha512-5YVgM2V2uhJi3PZfTwSNihcrPa66Wz697IfC8v57enXdYaVYryZnwZfB0A0eahgwdtjBHWlyPOvfRI4Rr7aoTw==
dependencies:
"@ensdomains/eth-ens-namehash" "^2.0.15"
"@ethersproject/abi" "^5.6.4"
Expand Down

1 comment on commit 89c9f85

@vercel
Copy link

@vercel vercel bot commented on 89c9f85 Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.