Skip to content

Commit

Permalink
ethers migrated to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtanrikulu committed Dec 1, 2023
1 parent 2b5b1db commit 2159818
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"axios-cache-interceptor": "^0.9.3",
"buffer": "^6.0.3",
"dompurify": "^3.0.6",
"ethers": "^6.9.0",
"is-svg": "^4.3.2",
"multiformats": "^9.6.2",
"url-join": "^4.0.1"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { JsonRpcProvider } from 'ethers';
import ERC1155 from './specs/erc1155';
import ERC721 from './specs/erc721';
import URI from './specs/uri';
Expand All @@ -23,14 +23,14 @@ export interface UnsupportedNamespace {}
export class UnsupportedNamespace extends BaseError {}

export interface AvatarResolver {
provider: BaseProvider;
provider: JsonRpcProvider;
options?: AvatarResolverOpts;
getAvatar(ens: string, data: AvatarRequestOpts): Promise<string | null>;
getMetadata(ens: string): Promise<any | null>;
}

export class AvatarResolver implements AvatarResolver {
constructor(provider: BaseProvider, options?: AvatarResolverOpts) {
constructor(provider: JsonRpcProvider, options?: AvatarResolverOpts) {
this.provider = provider;
this.options = options;
if (options?.cache && options?.cache > 0) {
Expand Down
9 changes: 4 additions & 5 deletions src/specs/erc1155.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import { Contract, Provider } from 'ethers';
import { Buffer } from 'buffer/';
import { fetch, resolveURI } from '../utils';
import { AvatarResolverOpts } from '../types';
Expand All @@ -21,7 +20,7 @@ function getMarketplaceAPIKey(uri: string, options?: AvatarResolverOpts) {

export default class ERC1155 {
async getMetadata(
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand All @@ -32,12 +31,12 @@ export default class ERC1155 {
? tokenID.replace('0x', '').padStart(64, '0')
: tokenID;
const contract = new Contract(contractAddress, abi, provider);
const [tokenURI, balance] = await Promise.all([
const [tokenURI, balance]: [string, bigint] = await Promise.all([
contract.uri(tokenID),
ownerAddress && contract.balanceOf(ownerAddress, tokenID),
]);
// if user has valid address and if token balance of given address is greater than 0
const isOwner = !!(ownerAddress && balance.gt(0));
const isOwner = !!(ownerAddress && balance > BigInt(0));

const { uri: resolvedURI, isOnChain, isEncoded } = resolveURI(
tokenURI,
Expand Down
5 changes: 2 additions & 3 deletions src/specs/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BaseProvider } from '@ethersproject/providers';
import { Contract } from '@ethersproject/contracts';
import { Contract, Provider } from 'ethers';
import { Buffer } from 'buffer/';
import { fetch, resolveURI } from '../utils';
import { AvatarResolverOpts } from '../types';
Expand All @@ -11,7 +10,7 @@ const abi = [

export default class ERC721 {
async getMetadata(
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseProvider } from '@ethersproject/providers';
import { Provider } from 'ethers';

export interface Spec {
getMetadata: (
provider: BaseProvider,
provider: Provider,
ownerAddress: string | undefined | null,
contractAddress: string,
tokenID: string,
Expand Down
50 changes: 50 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
# yarn lockfile v1


"@adraffy/[email protected]":
version "1.10.0"
resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.10.0.tgz#d2a39395c587e092d77cbbc80acf956a54f38bf7"
integrity sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==

"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.16.7", "@babel/code-frame@^7.5.5":
version "7.16.7"
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz"
Expand Down Expand Up @@ -1365,6 +1370,18 @@
"@types/yargs" "^15.0.0"
chalk "^3.0.0"

"@noble/[email protected]":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35"
integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==
dependencies:
"@noble/hashes" "1.3.2"

"@noble/[email protected]":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39"
integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==

"@nodelib/[email protected]":
version "2.1.5"
resolved "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz"
Expand Down Expand Up @@ -1582,6 +1599,11 @@
resolved "https://registry.npmjs.org/@types/node/-/node-17.0.10.tgz"
integrity sha512-S/3xB4KzyFxYGCppyDt68yzBU9ysL88lSdIah4D6cptdcltc4NCPCAMc0+PCpg/lLIyC7IPvj2Z52OJWeIUkog==

"@types/[email protected]":
version "18.15.13"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469"
integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q==

"@types/normalize-package-data@^2.4.0":
version "2.4.1"
resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz"
Expand Down Expand Up @@ -1717,6 +1739,11 @@ acorn@^7.1.0, acorn@^7.1.1:
resolved "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz"
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

[email protected]:
version "4.0.0-beta.5"
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-4.0.0-beta.5.tgz#8d2452c52adedebc3a3e28465d858c11ca315873"
integrity sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==

ajv@^6.10.0, ajv@^6.10.2, ajv@^6.12.3:
version "6.12.6"
resolved "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz"
Expand Down Expand Up @@ -3204,6 +3231,19 @@ esutils@^2.0.2:
resolved "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

ethers@^6.9.0:
version "6.9.0"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-6.9.0.tgz#a4534bdcdfde306aee94ef32f3d5c70d7e33fcb9"
integrity sha512-pmfNyQzc2mseLe91FnT2vmNaTt8dDzhxZ/xItAV7uGsF4dI4ek2ufMu3rAkgQETL/TIs0GS5A+U05g9QyWnv3Q==
dependencies:
"@adraffy/ens-normalize" "1.10.0"
"@noble/curves" "1.2.0"
"@noble/hashes" "1.3.2"
"@types/node" "18.15.13"
aes-js "4.0.0-beta.5"
tslib "2.4.0"
ws "8.5.0"

exec-sh@^0.3.2:
version "0.3.6"
resolved "https://registry.npmjs.org/exec-sh/-/exec-sh-0.3.6.tgz"
Expand Down Expand Up @@ -6755,6 +6795,11 @@ [email protected]:
resolved "https://registry.npmjs.org/tslib/-/tslib-2.0.1.tgz"
integrity sha512-SgIkNheinmEBgx1IUNirK0TUD4X9yjjBRTqqjggWCU3pUEqIk3/Uwl3yRixYKT6WjQuGiwDv4NomL3wqRCj+CQ==

[email protected]:
version "2.4.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==

tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
version "1.14.1"
resolved "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz"
Expand Down Expand Up @@ -7105,6 +7150,11 @@ [email protected], ws@^7.0.0:
resolved "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz"
integrity sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==

[email protected]:
version "8.5.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f"
integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==

xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz"
Expand Down

0 comments on commit 2159818

Please sign in to comment.