From 88750e00dbd4cddf0e41e543098050d2c8f3a95b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 31 Dec 2023 22:02:06 +0530 Subject: [PATCH 1/2] Automated lint (#1381) Co-authored-by: ChaituVR --- .../index.ts | 94 +++++++++---------- 1 file changed, 42 insertions(+), 52 deletions(-) diff --git a/src/strategies/nation3-passport-coop-with-delegations/index.ts b/src/strategies/nation3-passport-coop-with-delegations/index.ts index 6fd51d1ea..b4eaaa5ef 100644 --- a/src/strategies/nation3-passport-coop-with-delegations/index.ts +++ b/src/strategies/nation3-passport-coop-with-delegations/index.ts @@ -1,6 +1,8 @@ -import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; +import { getAddress } from '@ethersproject/address'; +import { BigNumberish } from '@ethersproject/bignumber'; import { Multicaller } from '../../utils'; import { formatUnits } from '@ethersproject/units'; +import { subgraphRequest } from '../../utils'; export const author = 'nation3'; export const version = '0.3.0'; @@ -11,14 +13,6 @@ const balanceAbi = [ 'function balanceOf(address account) external view returns (uint256)' ]; -const ownerAbi = ['function ownerOf(uint256 id) public view returns (address)']; - -const signerAbi = [ - 'function signerOf(uint256 id) external view returns (address)' -]; - -const lastTokenIdAbi = ['function getNextId() external view returns (uint256)']; - export async function strategy( space, network, @@ -29,67 +23,63 @@ export async function strategy( ): Promise> { const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; - const erc721SignerCaller = new Multicaller(network, provider, signerAbi, { - blockTag - }); - const erc721OwnerCaller = new Multicaller(network, provider, ownerAbi, { - blockTag - }); const erc20BalanceCaller = new Multicaller(network, provider, balanceAbi, { blockTag }); - const erc721LastTokenIdCaller = new Multicaller( - network, - provider, - lastTokenIdAbi, - { blockTag } - ); - erc721LastTokenIdCaller.call('lastTokenId', options.erc721, 'getNextId'); + const erc721BalanceCaller = new Multicaller(network, provider, balanceAbi, { + blockTag + }); - const lastIndex = await erc721LastTokenIdCaller.execute(); - const lastTokenId = BigNumber.from(lastIndex.lastTokenId).toNumber(); + const passportIssuanceSubgrgraph = "https://api.thegraph.com/subgraphs/name/nation3/passportissuance" - for (let i = 1; i < lastTokenId; i++) { - erc721SignerCaller.call(i, options.erc721, 'signerOf', [i]); - erc721OwnerCaller.call(i, options.erc721, 'ownerOf', [i]); - } + const revokedUsersResponse = await subgraphRequest(passportIssuanceSubgrgraph, { + revokes: { + __args: { + where: { _to_in: addresses } + }, + id: true, + _to: true + } + }); - const [erc721Signers, erc721Owners]: [ - Record, - Record - ] = await Promise.all([ - erc721SignerCaller.execute(), - erc721OwnerCaller.execute() - ]); + const revokedUsers: string[] = revokedUsersResponse.revokes.map(revokeObject => { + return getAddress(revokeObject._to); + }); - const erc721SignersArr = Object.entries(erc721Signers); - const erc721OwnersArr = Object.entries(erc721Owners); - const eligibleAddresses = erc721SignersArr.filter(([, address]) => - addresses.includes(address) - ); + const eligibleAddresses: string[] = addresses.filter((address) => { + return !revokedUsers.includes(getAddress(address)); + }); - //create a combined tuple - const eligibleSignerOwner: [string, string, string][] = eligibleAddresses.map( - ([id, signerAddress]) => { - const owner = erc721OwnersArr.find(([ownerId]) => id === ownerId); - return [id, signerAddress, owner ? owner[1] : '0x0']; - } - ); - eligibleSignerOwner.forEach(([, , owner]) => + eligibleAddresses.forEach((owner) => erc20BalanceCaller.call(owner, options.erc20, 'balanceOf', [owner]) ); const erc20Balances: Record = await erc20BalanceCaller.execute(); + + eligibleAddresses.forEach((owner) => + erc721BalanceCaller.call(owner, options.erc721, 'balanceOf', [owner]) + ); + + const erc721Balances: Record = + await erc721BalanceCaller.execute(); + + + const eligibleAddressesWithPassports = eligibleAddresses.filter((owner) => { + const passportBalance = erc721Balances[owner] || 0; + return parseFloat(formatUnits(passportBalance, DECIMALS)) > 0; + }); + //now we have balances, need to check for > 1.5 on all IDs that have voted - const withPower = eligibleSignerOwner.filter(([, , owner]) => { - const balance = erc20Balances[owner] || 0; - return parseFloat(formatUnits(balance, DECIMALS)) > 1.5; + const withPower = eligibleAddressesWithPassports.filter((owner) => { + const veNationBalance = erc20Balances[owner] || 0; + + return parseFloat(formatUnits(veNationBalance, DECIMALS)) > 1.5; }); - return Object.fromEntries(withPower.map(([, signer]) => [signer, 1])) || []; + return Object.fromEntries(withPower.map(([, signer]) => [signer, 1])); } From 6b61b1fa7a3f0a6526544230b50124d666472c07 Mon Sep 17 00:00:00 2001 From: Jamil Bousquet Date: Thu, 4 Jan 2024 08:57:39 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20breaking=20issue=20wit?= =?UTF-8?q?h=20revoked=20passports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.ts | 100 ++++++++++++------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/src/strategies/nation3-passport-coop-with-delegations/index.ts b/src/strategies/nation3-passport-coop-with-delegations/index.ts index b4eaaa5ef..42f56e945 100644 --- a/src/strategies/nation3-passport-coop-with-delegations/index.ts +++ b/src/strategies/nation3-passport-coop-with-delegations/index.ts @@ -1,5 +1,4 @@ -import { getAddress } from '@ethersproject/address'; -import { BigNumberish } from '@ethersproject/bignumber'; +import { BigNumber, BigNumberish } from '@ethersproject/bignumber'; import { Multicaller } from '../../utils'; import { formatUnits } from '@ethersproject/units'; import { subgraphRequest } from '../../utils'; @@ -7,12 +6,22 @@ import { subgraphRequest } from '../../utils'; export const author = 'nation3'; export const version = '0.3.0'; +type Query = {[key: string]: any} + const DECIMALS = 18; const balanceAbi = [ 'function balanceOf(address account) external view returns (uint256)' ]; +const ownerAbi = ['function ownerOf(uint256 id) public view returns (address)']; + +const signerAbi = [ + 'function signerOf(uint256 id) external view returns (address)' +]; + +const lastTokenIdAbi = ['function getNextId() external view returns (uint256)']; + export async function strategy( space, network, @@ -27,59 +36,84 @@ export async function strategy( blockTag }); - const erc721BalanceCaller = new Multicaller(network, provider, balanceAbi, { + const erc721LastTokenIdCaller = new Multicaller( + network, + provider, + lastTokenIdAbi, + { blockTag } + ); + + const erc721SignerCaller = new Multicaller(network, provider, signerAbi, { + blockTag + }); + const erc721OwnerCaller = new Multicaller(network, provider, ownerAbi, { blockTag }); - const passportIssuanceSubgrgraph = "https://api.thegraph.com/subgraphs/name/nation3/passportissuance" + const passportIssuanceSubgrgraph = "https://api.thegraph.com/subgraphs/name/nation3/passportissuance"; - const revokedUsersResponse = await subgraphRequest(passportIssuanceSubgrgraph, { + const revokedQuery: Query = { revokes: { - __args: { - where: { _to_in: addresses } - }, id: true, - _to: true + _to: true, + _tokenId: true, } - }); + } - const revokedUsers: string[] = revokedUsersResponse.revokes.map(revokeObject => { - return getAddress(revokeObject._to); + const revokedUsersResponse = await subgraphRequest(passportIssuanceSubgrgraph, revokedQuery); + + const revokedPassports: number[] = revokedUsersResponse.revokes.map(revokeObject => { + return BigNumber.from(revokeObject._tokenId).toNumber(); }); - const eligibleAddresses: string[] = addresses.filter((address) => { - return !revokedUsers.includes(getAddress(address)); - }); + erc721LastTokenIdCaller.call('lastTokenId', options.erc721, 'getNextId'); + const lastIndex = await erc721LastTokenIdCaller.execute(); + const lastTokenId = BigNumber.from(lastIndex.lastTokenId).toNumber(); - eligibleAddresses.forEach((owner) => - erc20BalanceCaller.call(owner, options.erc20, 'balanceOf', [owner]) - ); + for (let i = 1; i < lastTokenId; i++) { + if (revokedPassports.includes(i)) continue; - const erc20Balances: Record = - await erc20BalanceCaller.execute(); + erc721SignerCaller.call(i, options.erc721, 'signerOf', [i]); + erc721OwnerCaller.call(i, options.erc721, 'ownerOf', [i]); + } + const [erc721Signers, erc721Owners]: [ + Record, + Record + ] = await Promise.all([ + erc721SignerCaller.execute(), + erc721OwnerCaller.execute() + ]); - eligibleAddresses.forEach((owner) => - erc721BalanceCaller.call(owner, options.erc721, 'balanceOf', [owner]) + const erc721SignersArr = Object.entries(erc721Signers); + const erc721OwnersArr = Object.entries(erc721Owners); + + const eligibleAddresses = erc721SignersArr.filter(([, address]) => + addresses.includes(address) ); - const erc721Balances: Record = - await erc721BalanceCaller.execute(); + //create a combined tuple + const eligibleSignerOwner: [string, string, string][] = eligibleAddresses.map( + ([id, signerAddress]) => { + const owner = erc721OwnersArr.find(([ownerId]) => id === ownerId); + return [id, signerAddress, owner ? owner[1] : '0x0']; + } + ); + eligibleSignerOwner.forEach(([, , owner]) => + erc20BalanceCaller.call(owner, options.erc20, 'balanceOf', [owner]) + ); - const eligibleAddressesWithPassports = eligibleAddresses.filter((owner) => { - const passportBalance = erc721Balances[owner] || 0; - return parseFloat(formatUnits(passportBalance, DECIMALS)) > 0; - }); + const erc20Balances: Record = + await erc20BalanceCaller.execute(); //now we have balances, need to check for > 1.5 on all IDs that have voted - const withPower = eligibleAddressesWithPassports.filter((owner) => { - const veNationBalance = erc20Balances[owner] || 0; - - return parseFloat(formatUnits(veNationBalance, DECIMALS)) > 1.5; + const withPower = eligibleSignerOwner.filter(([, , owner]) => { + const balance = erc20Balances[owner] || 0; + return parseFloat(formatUnits(balance, DECIMALS)) > 1.5; }); - return Object.fromEntries(withPower.map(([, signer]) => [signer, 1])); + return Object.fromEntries(withPower.map(([, signer]) => [signer, 1])) || []; }