Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7129aef6e1 | ||
|
|
f50b74819d | ||
|
|
3eba69afd7 | ||
|
|
98c2253e8f | ||
|
|
32d91ef709 | ||
|
|
b79dc18f7a | ||
|
|
4af785c37c | ||
|
|
6f818f393e | ||
|
|
97ed4779a9 | ||
|
|
2d3fca5237 | ||
|
|
7016019f2a | ||
|
|
4e7b293c54 | ||
|
|
c9c0e4ff39 | ||
|
|
06c24c153a | ||
|
|
aa6d9ed75d | ||
|
|
42a606588d | ||
|
|
2820761003 | ||
|
|
5200d5d7e7 | ||
|
|
e731c1a7c3 | ||
|
|
2e8d3fd6e7 | ||
|
|
cc4613b5fd | ||
|
|
78566babaa | ||
|
|
65fc7ba6ff | ||
|
|
1c24c3c3c4 | ||
|
|
408c5a81fa | ||
|
|
352291791e | ||
|
|
aabbb149e8 | ||
|
|
d59450f814 | ||
|
|
7d9a4c6abc | ||
|
|
99806e595d | ||
|
|
21c21c1adf | ||
|
|
4b10719047 | ||
|
|
989cf7347c | ||
|
|
72227b2e16 | ||
|
|
ed6c54f20d | ||
|
|
26116a6f63 | ||
|
|
f11a2719ff | ||
|
|
ef27aad0aa | ||
|
|
b03a902145 | ||
|
|
340605b507 | ||
|
|
15f8006e1f | ||
|
|
811c5a1166 |
@@ -7,7 +7,7 @@
|
|||||||
"access": "public",
|
"access": "public",
|
||||||
"baseBranch": "main",
|
"baseBranch": "main",
|
||||||
"updateInternalDependencies": "patch",
|
"updateInternalDependencies": "patch",
|
||||||
"ignore": [],
|
"ignore": ["e2e-cra-5", "e2e-next-12", "e2e-vite-3"],
|
||||||
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
||||||
"updateInternalDependents": "always",
|
"updateInternalDependents": "always",
|
||||||
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ runs:
|
|||||||
with:
|
with:
|
||||||
node-version: 16
|
node-version: 16
|
||||||
registry-url: "https://registry.npmjs.org"
|
registry-url: "https://registry.npmjs.org"
|
||||||
# cache: "yarn"
|
cache: "yarn"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
run: yarn install --frozen-lockfile
|
run: yarn install
|
||||||
env:
|
env:
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
# timeout-minutes: 15
|
# timeout-minutes: 15
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
||||||
env:
|
env:
|
||||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
integration-tests:
|
integration-tests:
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
@@ -28,9 +27,3 @@ jobs:
|
|||||||
run: yarn e2e
|
run: yarn e2e
|
||||||
env:
|
env:
|
||||||
NODE_OPTIONS: "--max_old_space_size=4096"
|
NODE_OPTIONS: "--max_old_space_size=4096"
|
||||||
- uses: actions/upload-artifact@v2
|
|
||||||
if: always()
|
|
||||||
with:
|
|
||||||
name: playwright-report
|
|
||||||
path: packages/react/playwright-report/
|
|
||||||
retention-days: 30
|
|
||||||
|
|||||||
@@ -40,8 +40,7 @@ jobs:
|
|||||||
comment_body: ${{ github.event.comment.body }}
|
comment_body: ${{ github.event.comment.body }}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
needs: deploy-check
|
needs: deploy-check
|
||||||
if: needs.deploy-check.outputs.triggered == 'true'
|
if: needs.deploy-check.outputs.triggered == 'true'
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout branch
|
- name: Checkout branch
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ on: [pull_request]
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
# try out buildjet to speed up build and test
|
runs-on: ubuntu-latest-32
|
||||||
runs-on: buildjet-32vcpu-ubuntu-2204
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -16,3 +15,5 @@ jobs:
|
|||||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
strip-hash: "\\-(\\w{8})(?:\\.esm|\\.cjs)"
|
strip-hash: "\\-(\\w{8})(?:\\.esm|\\.cjs)"
|
||||||
minimum-change-threshold: 100
|
minimum-change-threshold: 100
|
||||||
|
# exclude source maps, node modules and any test related files
|
||||||
|
exclude: "{**/*.map,**/node_modules/**,**/test/**}"
|
||||||
|
|||||||
@@ -13,3 +13,8 @@ public/dist
|
|||||||
.turbo
|
.turbo
|
||||||
./packages/contracts-js/abis
|
./packages/contracts-js/abis
|
||||||
.idea/
|
.idea/
|
||||||
|
.yalc/
|
||||||
|
yalc.lock
|
||||||
|
build/
|
||||||
|
playwright-report/
|
||||||
|
.vscode/
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
lib
|
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
contracts-js
|
contracts-js
|
||||||
|
|||||||
+5
-9
@@ -8,14 +8,15 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"workspaces": {
|
"workspaces": {
|
||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*",
|
||||||
|
"test/**/*"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "turbo run test test:evm test:solana",
|
"test": "turbo run test test:evm test:solana",
|
||||||
"e2e": "turbo run e2e",
|
"e2e": "turbo run e2e",
|
||||||
"build": "turbo run build",
|
"build": "turbo run build --filter=./packages/*",
|
||||||
"build:release": "turbo run build --force",
|
"build:release": "turbo run build --force --filter=./packages/*",
|
||||||
"dev": "turbo run dev --no-cache --parallel --continue",
|
"dev": "turbo run dev --no-cache --parallel --continue",
|
||||||
"fix:repo": "manypkg fix",
|
"fix:repo": "manypkg fix",
|
||||||
"lint": "turbo run lint",
|
"lint": "turbo run lint",
|
||||||
@@ -27,12 +28,7 @@
|
|||||||
"release": "node ./scripts/pre-release.mjs && changeset publish",
|
"release": "node ./scripts/pre-release.mjs && changeset publish",
|
||||||
"version-packages:nightly": "changeset version --snapshot nightly",
|
"version-packages:nightly": "changeset version --snapshot nightly",
|
||||||
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly",
|
"release:nightly": "node ./scripts/pre-release.mjs && changeset publish --tag nightly",
|
||||||
"push": "turbo run push"
|
"push": "turbo run push --filter=./packages/*"
|
||||||
},
|
|
||||||
"preconstruct": {
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"packageManager": "[email protected]",
|
"packageManager": "[email protected]",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
# @thirdweb-dev/auth
|
# @thirdweb-dev/auth
|
||||||
|
|
||||||
|
## 2.0.29
|
||||||
|
|
||||||
|
## 2.0.28
|
||||||
|
|
||||||
|
## 2.0.27
|
||||||
|
|
||||||
|
## 2.0.26
|
||||||
|
|
||||||
|
## 2.0.25
|
||||||
|
|
||||||
|
## 2.0.24
|
||||||
|
|
||||||
|
## 2.0.23
|
||||||
|
|
||||||
|
## 2.0.22
|
||||||
|
|
||||||
|
## 2.0.21
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
## 2.0.20
|
## 2.0.20
|
||||||
|
|
||||||
## 2.0.19
|
## 2.0.19
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/auth",
|
"name": "@thirdweb-dev/auth",
|
||||||
"version": "2.0.20",
|
"version": "2.0.29",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./next": {
|
"./next": {
|
||||||
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
||||||
|
|||||||
@@ -1,5 +1,70 @@
|
|||||||
# thirdweb
|
# thirdweb
|
||||||
|
|
||||||
|
## 0.8.15
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3eba69a`](https://github.com/thirdweb-dev/js/commit/3eba69afd78b7aa472a9c00c9d4220bb69ad1d3e), [`4af785c`](https://github.com/thirdweb-dev/js/commit/4af785c37c831ecd7087c1c9eb9095922cac0855), [`6f818f3`](https://github.com/thirdweb-dev/js/commit/6f818f393eb9023b53a3358d62d60ec23a9246bd), [`b79dc18`](https://github.com/thirdweb-dev/js/commit/b79dc18f7ab5155bbf4af02dc1a953546160bad0)]:
|
||||||
|
- @thirdweb-dev/sdk@3.5.2
|
||||||
|
|
||||||
|
## 0.8.14
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`4e7b293`](https://github.com/thirdweb-dev/js/commit/4e7b293c543244de79c150ca8c37d941221fc9a3), [`c9c0e4f`](https://github.com/thirdweb-dev/js/commit/c9c0e4ff39b054af746f3aec75fcbd0a3ef7239d)]:
|
||||||
|
- @thirdweb-dev/sdk@3.5.1
|
||||||
|
|
||||||
|
## 0.8.13
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`5200d5d`](https://github.com/thirdweb-dev/js/commit/5200d5d7e730da58bd4d3e7c222e3c661265f913), [`42a6065`](https://github.com/thirdweb-dev/js/commit/42a606588dfed03c67c57357dd0ee1ad19fad6ea)]:
|
||||||
|
- @thirdweb-dev/sdk@3.5.0
|
||||||
|
|
||||||
|
## 0.8.12
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`e731c1a`](https://github.com/thirdweb-dev/js/commit/e731c1a7c341e6f2b9cc42c88d5c1b036dcf4a7c)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.5
|
||||||
|
|
||||||
|
## 0.8.11
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies []:
|
||||||
|
- @thirdweb-dev/sdk@3.4.4
|
||||||
|
|
||||||
|
## 0.8.10
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5), [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.3
|
||||||
|
|
||||||
|
## 0.8.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`21c21c1`](https://github.com/thirdweb-dev/js/commit/21c21c1adfd09b60ad563bfd4c308597140de33c), [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.2
|
||||||
|
|
||||||
|
## 0.8.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.1
|
||||||
|
|
||||||
|
## 0.8.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
|
- Updated dependencies [[`340605b`](https://github.com/thirdweb-dev/js/commit/340605b507f384fbd2999b9c16542af3c53e84a9), [`26116a6`](https://github.com/thirdweb-dev/js/commit/26116a6f637ee845f7bd17f20ffe17caf184658e), [`15f8006`](https://github.com/thirdweb-dev/js/commit/15f8006e1fb22333b7ee239b45e7b1b12d6dccc8), [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5)]:
|
||||||
|
- @thirdweb-dev/sdk@3.4.0
|
||||||
|
|
||||||
## 0.8.6
|
## 0.8.6
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "thirdweb",
|
"name": "thirdweb",
|
||||||
"main": "dist/cli/index.js",
|
"main": "dist/cli/index.js",
|
||||||
"version": "0.8.6",
|
"version": "0.8.15",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
.version(cliVersion, "-v, --version");
|
.version(cliVersion, "-v, --version");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("create")
|
.command("create [projectPath]")
|
||||||
.description(
|
.description(
|
||||||
"Create a web3 app from any of our official templates: https://github.com/thirdweb-example/",
|
"Create a web3 app from any of our official templates: https://github.com/thirdweb-example/",
|
||||||
)
|
)
|
||||||
@@ -66,8 +66,8 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"-t, --template [name]",
|
"-t, --template [name]",
|
||||||
`A template to start your project from. You can use an template repository name from the official thirdweb-example org.`,
|
`A template to start your project from. You can use an template repository name from the official thirdweb-example org.`,
|
||||||
)
|
)
|
||||||
.action(async (options) => {
|
.action(async (path, options) => {
|
||||||
await twCreate(options);
|
await twCreate(path, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ let language: string = "";
|
|||||||
let baseContract: string = "";
|
let baseContract: string = "";
|
||||||
/* let createType: string = "app"; */
|
/* let createType: string = "app"; */
|
||||||
|
|
||||||
export async function twCreate(options: any) {
|
export async function twCreate(pPath: string = "", options: any) {
|
||||||
if (typeof projectPath === "string") {
|
if (typeof pPath === "string") {
|
||||||
projectPath = projectPath.trim();
|
projectPath = pPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.app) {
|
if (options.app) {
|
||||||
|
|||||||
@@ -1,5 +1,19 @@
|
|||||||
# @thirdweb-dev/contracts-js
|
# @thirdweb-dev/contracts-js
|
||||||
|
|
||||||
|
## 1.2.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#376](https://github.com/thirdweb-dev/js/pull/376) [`4af785c`](https://github.com/thirdweb-dev/js/commit/4af785c37c831ecd7087c1c9eb9095922cac0855) Thanks [@adam-maj](https://github.com/adam-maj)! - Update tiered-drop with tokens claimed
|
||||||
|
|
||||||
|
- [#373](https://github.com/thirdweb-dev/js/pull/373) [`6f818f3`](https://github.com/thirdweb-dev/js/commit/6f818f393eb9023b53a3358d62d60ec23a9246bd) Thanks [@adam-maj](https://github.com/adam-maj)! - Update tiered-drop contract version
|
||||||
|
|
||||||
|
## 1.2.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#333](https://github.com/thirdweb-dev/js/pull/333) [`aa6d9ed`](https://github.com/thirdweb-dev/js/commit/aa6d9ed75d126d7a0cca9fb8fc389ff94e9d1e14) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Update to contracts package v3.2.0
|
||||||
|
|
||||||
## 1.1.9
|
## 1.1.9
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-contracts-js-factories-TWMultichainRegistry__factory.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-contracts-js-factories-TWMultichainRegistry__factory.esm.js"
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/contracts-js",
|
"name": "@thirdweb-dev/contracts-js",
|
||||||
"version": "1.1.9",
|
"version": "1.2.1",
|
||||||
"main": "dist/thirdweb-dev-contracts-js.cjs.js",
|
"main": "dist/thirdweb-dev-contracts-js.cjs.js",
|
||||||
"module": "dist/thirdweb-dev-contracts-js.esm.js",
|
"module": "dist/thirdweb-dev-contracts-js.esm.js",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/contracts-js",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/contracts-js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@thirdweb-dev/contracts": "3.1.8-0"
|
"@thirdweb-dev/contracts": "^3.2.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.18.10",
|
||||||
|
|||||||
@@ -1,5 +1,92 @@
|
|||||||
# @thirdweb-dev/react
|
# @thirdweb-dev/react
|
||||||
|
|
||||||
|
## 3.5.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#369](https://github.com/thirdweb-dev/js/pull/369) [`2d3fca5`](https://github.com/thirdweb-dev/js/commit/2d3fca52373046c88392139922e9c9da79f9a2d4) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useClaimerProofs hook
|
||||||
|
|
||||||
|
- [#378](https://github.com/thirdweb-dev/js/pull/378) [`32d91ef`](https://github.com/thirdweb-dev/js/commit/32d91ef709c8fb92a903e52c65b27538a80ea4eb) Thanks [@mykcryptodev](https://github.com/mykcryptodev)! - round borders for buttons and menus on safari
|
||||||
|
|
||||||
|
- [#377](https://github.com/thirdweb-dev/js/pull/377) [`b79dc18`](https://github.com/thirdweb-dev/js/commit/b79dc18f7ab5155bbf4af02dc1a953546160bad0) Thanks [@adam-maj](https://github.com/adam-maj)! - Add event filters
|
||||||
|
|
||||||
|
## 3.5.1
|
||||||
|
|
||||||
|
## 3.5.0
|
||||||
|
|
||||||
|
## 3.4.5
|
||||||
|
|
||||||
|
## 3.4.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#356](https://github.com/thirdweb-dev/js/pull/356) [`cc4613b`](https://github.com/thirdweb-dev/js/commit/cc4613b5fd69840f4f9cfd0ac1c4e6743e62fe52) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add Pack and Multiwrap as NFTContract types
|
||||||
|
|
||||||
|
## 3.4.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
|
||||||
|
|
||||||
|
## 3.4.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#348](https://github.com/thirdweb-dev/js/pull/348) [`7d9a4c6`](https://github.com/thirdweb-dev/js/commit/7d9a4c6abcad1b4f43e431ce7b0b38db9016ea9a) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - [SOL] - add `useUpdateRoyaltySettings()` hook
|
||||||
|
[SOL] - change `useRoyalty()` hook -> `useRoyaltySettings()` for consistency
|
||||||
|
|
||||||
|
- [#352](https://github.com/thirdweb-dev/js/pull/352) [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - expose useExecuteAuctionSale and useAcceptDirectListingOffer
|
||||||
|
|
||||||
|
- [#351](https://github.com/thirdweb-dev/js/pull/351) [`aabbb14`](https://github.com/thirdweb-dev/js/commit/aabbb149e81d6824015a4797b2b6c929ca359545) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - fix wallet connection during dev (hot reload)
|
||||||
|
|
||||||
|
## 3.4.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#343](https://github.com/thirdweb-dev/js/pull/343) [`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose new useOffers and useMakeOffer hooks
|
||||||
|
|
||||||
|
## 3.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - Gnosis Safe and Magic Link connectors are no longer included in the default export. They are now available as named exports instead.
|
||||||
|
|
||||||
|
## Gnosis Safe
|
||||||
|
|
||||||
|
### Connector
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { GnosisSafeConnector } from "@thirdweb-dev/react";
|
||||||
|
+ import { GnosisSafeConnector } from "@thirdweb-dev/react/evm/connectors/gnosis-safe";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hook
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { useGnosis } from "@thirdweb-dev/react";
|
||||||
|
+ import { useGnosis } from "@thirdweb-dev/react/evm/connectors/gnosis-safe";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Magic Link
|
||||||
|
|
||||||
|
### Connector
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { MagicLink } from "@thirdweb-dev/react";
|
||||||
|
+ import { MagicConnector } from "@thirdweb-dev/react/evm/connectors/magic";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hook
|
||||||
|
|
||||||
|
```diff
|
||||||
|
- import { useMagic } from "@thirdweb-dev/react";
|
||||||
|
+ import { useMagic } from "@thirdweb-dev/react/evm/connectors/magic";
|
||||||
|
```
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#339](https://github.com/thirdweb-dev/js/pull/339) [`b03a902`](https://github.com/thirdweb-dev/js/commit/b03a9021451b79f802f682f66e5ae8e9355d7e6f) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix docs for some functions
|
||||||
|
|
||||||
## 3.3.1
|
## 3.3.1
|
||||||
|
|
||||||
## 3.3.0
|
## 3.3.0
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ The `useContractCall` hook to call a smart contract function has been renamed to
|
|||||||
|
|
||||||
### Prebuilt Contract Hooks
|
### Prebuilt Contract Hooks
|
||||||
|
|
||||||
Hooks to connect to prebuilt contracts such as `useNFTDrop` and `useMarketplace` are now deprecated in favour of using the generic `useContract` hook:
|
Hooks to connect to prebuilt contracts such as `useNFTDrop` and `useMarketplace` are now deprecated in favour of using the generic `useContract` hook followed by the contract type:
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- const contract = useNFTDrop("0x...")
|
- const contract = useNFTDrop("0x...")
|
||||||
+ const { contract } = useContract("0x...")
|
+ const { contract } = useContract("0x...", "nft-drop")
|
||||||
```
|
```
|
||||||
|
|
||||||
You can currently still continue to use the prebuilt hooks, however they provide a warning in the console informing you of their deprecation. We will likely remove these hooks in a future version of the SDK.
|
You can currently still continue to use the prebuilt hooks, however they provide a warning in the console informing you of their deprecation. We will likely remove these hooks in a future version of the SDK.
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export default function Home() {
|
|||||||
<div>
|
<div>
|
||||||
{nfts.map((nft) => (
|
{nfts.map((nft) => (
|
||||||
<ThirdwebNftMedia
|
<ThirdwebNftMedia
|
||||||
key={nft.tokenId}
|
key={nft.metadata.id}
|
||||||
metadata={nft.metadata}
|
metadata={nft.metadata}
|
||||||
height={200}
|
height={200}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-react-evm-connectors-gnosis-safe.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-react-evm-connectors-gnosis-safe.esm.js"
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-react-evm-connectors-magic.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-react-evm-connectors-magic.esm.js"
|
||||||
|
}
|
||||||
+19
-18
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react",
|
"name": "@thirdweb-dev/react",
|
||||||
"version": "3.3.1",
|
"version": "3.5.2",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
|
||||||
"author": "thirdweb eng <[email protected]>",
|
"author": "thirdweb eng <[email protected]>",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
@@ -20,6 +20,14 @@
|
|||||||
"module": "./solana/dist/thirdweb-dev-react-solana.esm.js",
|
"module": "./solana/dist/thirdweb-dev-react-solana.esm.js",
|
||||||
"default": "./solana/dist/thirdweb-dev-react-solana.cjs.js"
|
"default": "./solana/dist/thirdweb-dev-react-solana.cjs.js"
|
||||||
},
|
},
|
||||||
|
"./evm/connectors/magic": {
|
||||||
|
"module": "./evm/connectors/magic/dist/thirdweb-dev-react-evm-connectors-magic.esm.js",
|
||||||
|
"default": "./evm/connectors/magic/dist/thirdweb-dev-react-evm-connectors-magic.cjs.js"
|
||||||
|
},
|
||||||
|
"./evm/connectors/gnosis-safe": {
|
||||||
|
"module": "./evm/connectors/gnosis-safe/dist/thirdweb-dev-react-evm-connectors-gnosis-safe.esm.js",
|
||||||
|
"default": "./evm/connectors/gnosis-safe/dist/thirdweb-dev-react-evm-connectors-gnosis-safe.cjs.js"
|
||||||
|
},
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -31,7 +39,8 @@
|
|||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"index.ts",
|
"index.ts",
|
||||||
"solana/index.ts",
|
"solana/index.ts",
|
||||||
"evm/index.ts"
|
"evm/index.ts",
|
||||||
|
"evm/connectors/**.ts"
|
||||||
],
|
],
|
||||||
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
||||||
"exports": true
|
"exports": true
|
||||||
@@ -49,8 +58,6 @@
|
|||||||
"generate-docs:solana": "api-extractor run --local --config ./config/api-extractor-solana.json && api-documenter markdown -i ./temp -o ./docs/solana && rm -rf ./temp-solana && mv ./temp ./temp-solana",
|
"generate-docs:solana": "api-extractor run --local --config ./config/api-extractor-solana.json && api-documenter markdown -i ./temp -o ./docs/solana && rm -rf ./temp-solana && mv ./temp ./temp-solana",
|
||||||
"generate-snippets": "node ./scripts/generate-snippets-evm.mjs && node ./scripts/generate-snippets-solana.mjs && node ./scripts/generate-feature-snippets-evm.mjs",
|
"generate-snippets": "node ./scripts/generate-snippets-evm.mjs && node ./scripts/generate-snippets-solana.mjs && node ./scripts/generate-feature-snippets-evm.mjs",
|
||||||
"build": "tsc && preconstruct build",
|
"build": "tsc && preconstruct build",
|
||||||
"e2e": "yarn test-ct",
|
|
||||||
"test-ct": "playwright test -c playwright-ct.config.ts",
|
|
||||||
"push": "yalc push"
|
"push": "yalc push"
|
||||||
},
|
},
|
||||||
"sideEffects:": false,
|
"sideEffects:": false,
|
||||||
@@ -63,15 +70,11 @@
|
|||||||
"@microsoft/api-documenter": "^7.19.4",
|
"@microsoft/api-documenter": "^7.19.4",
|
||||||
"@microsoft/api-extractor": "^7.29.2",
|
"@microsoft/api-extractor": "^7.29.2",
|
||||||
"@microsoft/tsdoc": "^0.14.1",
|
"@microsoft/tsdoc": "^0.14.1",
|
||||||
"@playwright/experimental-ct-react": "1.25.1",
|
|
||||||
"@playwright/test": "1.25.1",
|
|
||||||
"@preconstruct/cli": "^2.2.1",
|
"@preconstruct/cli": "^2.2.1",
|
||||||
"@solana/wallet-adapter-base": "^0.9.17",
|
"@solana/wallet-adapter-base": "^0.9.17",
|
||||||
"@solana/wallet-adapter-react": "^0.15.19",
|
"@solana/wallet-adapter-react": "^0.15.19",
|
||||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
"@solana/web3.js": "^1.62.0",
|
||||||
"@solana/web3.js": "^1.63.0",
|
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"@thirdweb-dev/solana": "*",
|
|
||||||
"@types/color": "^3.0.3",
|
"@types/color": "^3.0.3",
|
||||||
"@types/mime": "^3.0.1",
|
"@types/mime": "^3.0.1",
|
||||||
"@types/react": "^18.0.5",
|
"@types/react": "^18.0.5",
|
||||||
@@ -93,13 +96,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.10.0",
|
"@emotion/react": "^11.10.0",
|
||||||
"@emotion/styled": "^11.10.0",
|
"@emotion/styled": "^11.10.0",
|
||||||
"@gnosis.pm/safe-core-sdk": "2.1.0",
|
"@gnosis.pm/safe-core-sdk": "^3.1.1",
|
||||||
"@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.9",
|
"@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.11",
|
||||||
"@gnosis.pm/safe-ethers-lib": "1.1.0",
|
"@gnosis.pm/safe-ethers-lib": "^1.6.1",
|
||||||
"@react-icons/all-files": "^4.1.0",
|
"@react-icons/all-files": "^4.1.0",
|
||||||
|
"@solana/wallet-adapter-phantom": "^0.9.17",
|
||||||
"@tanstack/react-query": "^4.0.10",
|
"@tanstack/react-query": "^4.0.10",
|
||||||
"@zag-js/menu": "0.1.14",
|
"@zag-js/menu": "^0.1.16",
|
||||||
"@zag-js/react": "0.1.16",
|
"@zag-js/react": "^0.1.18",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"copy-to-clipboard": "^3.3.2",
|
"copy-to-clipboard": "^3.3.2",
|
||||||
@@ -114,7 +118,7 @@
|
|||||||
"@solana/wallet-adapter-base": "^0.9.17",
|
"@solana/wallet-adapter-base": "^0.9.17",
|
||||||
"@solana/wallet-adapter-react": "^0.15.19",
|
"@solana/wallet-adapter-react": "^0.15.19",
|
||||||
"@solana/wallet-adapter-wallets": "^0.19.0",
|
"@solana/wallet-adapter-wallets": "^0.19.0",
|
||||||
"@solana/web3.js": "^1.63.0",
|
"@solana/web3.js": "^1.62.0",
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"ethers": ">=5.5.1",
|
"ethers": ">=5.5.1",
|
||||||
"react": ">=18.0.0",
|
"react": ">=18.0.0",
|
||||||
@@ -136,9 +140,6 @@
|
|||||||
},
|
},
|
||||||
"@solana/web3.js": {
|
"@solana/web3.js": {
|
||||||
"optional": true
|
"optional": true
|
||||||
},
|
|
||||||
"@thirdweb-dev/solana": {
|
|
||||||
"optional": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
import type { PlaywrightTestConfig } from "@playwright/experimental-ct-react";
|
|
||||||
import { devices } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See https://playwright.dev/docs/test-configuration.
|
|
||||||
*/
|
|
||||||
const config: PlaywrightTestConfig = {
|
|
||||||
testDir: "./",
|
|
||||||
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
|
|
||||||
snapshotDir: "./__snapshots__",
|
|
||||||
/* Maximum time one test can run for. */
|
|
||||||
timeout: 10 * 1000,
|
|
||||||
/* Run tests in files in parallel */
|
|
||||||
fullyParallel: true,
|
|
||||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
||||||
forbidOnly: !!process.env.CI,
|
|
||||||
/* Retry on CI only */
|
|
||||||
retries: process.env.CI ? 2 : 0,
|
|
||||||
/* Opt out of parallel tests on CI. */
|
|
||||||
// workers: process.env.CI ? 1 : undefined,
|
|
||||||
// we can use parallel tests because we have more cores now
|
|
||||||
workers: undefined,
|
|
||||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
||||||
reporter: "html",
|
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
||||||
use: {
|
|
||||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
||||||
trace: "on-first-retry",
|
|
||||||
|
|
||||||
/* Port to use for Playwright component endpoint. */
|
|
||||||
ctPort: 3100,
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Configure projects for major browsers */
|
|
||||||
projects: [
|
|
||||||
{
|
|
||||||
name: "chromium",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Chrome"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "firefox",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Firefox"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "webkit",
|
|
||||||
use: {
|
|
||||||
...devices["Desktop Safari"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
// Import styles, initialize component theme here.
|
|
||||||
// import '../src/common.css';
|
|
||||||
|
|
||||||
export {};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { ConnectWallet } from ".";
|
|
||||||
import { ThirdwebProvider } from "../../providers/full";
|
|
||||||
import { test, expect } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
test.use({ viewport: { width: 500, height: 500 } });
|
|
||||||
|
|
||||||
test("should render the connect wallet button", async ({ mount }) => {
|
|
||||||
const component = await mount(
|
|
||||||
<ThirdwebProvider desiredChainId={1}>
|
|
||||||
<ConnectWallet />
|
|
||||||
</ThirdwebProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
await expect(component).toContainText("Connect Wallet");
|
|
||||||
});
|
|
||||||
@@ -144,7 +144,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
|||||||
},
|
},
|
||||||
connect,
|
connect,
|
||||||
] = useConnect();
|
] = useConnect();
|
||||||
const disconnect = useDisconnect({ reconnectAfterGnosis: false });
|
const disconnect = useDisconnect({ reconnectPrevious: false });
|
||||||
|
|
||||||
const supportedConnectors = connectors.filter((c) =>
|
const supportedConnectors = connectors.filter((c) =>
|
||||||
SUPPORTED_CONNECTORS.includes(c.id as typeof SUPPORTED_CONNECTORS[number]),
|
SUPPORTED_CONNECTORS.includes(c.id as typeof SUPPORTED_CONNECTORS[number]),
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This component can be used to render NFTs from the thirdweb SDK.
|
||||||
|
* Props: {@link ThirdwebNftMediaProps}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```jsx
|
* ```jsx
|
||||||
* import { ThirdwebNftMedia, useNFTCollection, useNFT } from "@thirdweb-dev/react";
|
* import { ThirdwebNftMedia, useContract, useNFT } from "@thirdweb-dev/react";
|
||||||
* export default function NFTCollectionRender() {
|
* export default function NFTCollectionRender() {
|
||||||
* const contract = useNFTCollection(<your-contract-address>);
|
* const { contract } = useContract(<your-contract-address>);
|
||||||
* const { data: nft, isLoading } = useNFT(contract, 0);
|
* const { data: nft, isLoading } = useNFT(contract, 0);
|
||||||
*
|
*
|
||||||
* return (
|
* return (
|
||||||
@@ -32,11 +34,6 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
|
|||||||
* );
|
* );
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
|
||||||
* Use this to get the primary sales recipient of your {@link SmartContract}
|
|
||||||
* @param contract - an instance of a {@link SmartContract}
|
|
||||||
* @returns the wallet address of the primary sales recipient
|
|
||||||
* @beta
|
|
||||||
*/
|
*/
|
||||||
export const ThirdwebNftMedia = React.forwardRef<
|
export const ThirdwebNftMedia = React.forwardRef<
|
||||||
HTMLMediaElement,
|
HTMLMediaElement,
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { Web3Button } from ".";
|
|
||||||
import { ThirdwebProvider } from "../../providers/full";
|
|
||||||
import { test, expect } from "@playwright/experimental-ct-react";
|
|
||||||
|
|
||||||
test.use({ viewport: { width: 500, height: 500 } });
|
|
||||||
|
|
||||||
test("should render the connect wallet button", async ({ mount }) => {
|
|
||||||
const component = await mount(
|
|
||||||
<ThirdwebProvider desiredChainId={1}>
|
|
||||||
<Web3Button contractAddress="0x123" action={() => undefined}>
|
|
||||||
Do the thing
|
|
||||||
</Web3Button>
|
|
||||||
</ThirdwebProvider>,
|
|
||||||
);
|
|
||||||
await expect(component).toContainText("Connect Wallet");
|
|
||||||
});
|
|
||||||
@@ -37,8 +37,19 @@ const BaseButton = styled.button<BaseButtonProps>`
|
|||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: 2px solid ${(props) => (props.theme as TwUiTheme).colors.accent};
|
position: relative;
|
||||||
outline-offset: 1px;
|
border-radius: 0.5em;
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
&:focus:after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: -5px;
|
||||||
|
right: -5px;
|
||||||
|
bottom: -5px;
|
||||||
|
left: -5px;
|
||||||
|
border: 2px solid ${(props) => (props.theme as TwUiTheme).colors.accent};
|
||||||
|
border-radius: 11px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,23 @@ export const Menu = styled.ul<MenuProps>`
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
background: ${(props) => (props.theme as TwUiTheme).colors.background};
|
background: ${(props) => (props.theme as TwUiTheme).colors.background};
|
||||||
color: ${(props) => (props.theme as TwUiTheme).colors.text};
|
color: ${(props) => (props.theme as TwUiTheme).colors.text};
|
||||||
outline-color: ${(props) => (props.theme as TwUiTheme).colors.accent};
|
|
||||||
outline-style: solid;
|
|
||||||
outline-offset: 0px;
|
|
||||||
list-style: none;
|
list-style: none;
|
||||||
border-radius: 0.5em;
|
border-radius: 0.5em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
pointer-events: auto;
|
||||||
|
&:focus {
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
&:after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
border: 1px solid ${(props) => (props.theme as TwUiTheme).colors.accent};
|
||||||
|
border-radius: 0.5em;
|
||||||
|
pointer-events: none;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
import { ChainId } from "@thirdweb-dev/sdk";
|
import { useConnect } from "../hooks/wagmi-required/useConnect";
|
||||||
import { Signer, ethers, utils } from "ethers";
|
import { Signer, ethers, utils } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { Chain, Connector, ConnectorData, normalizeChainId } from "wagmi";
|
import {
|
||||||
|
Chain,
|
||||||
|
Connector,
|
||||||
|
ConnectorData,
|
||||||
|
normalizeChainId,
|
||||||
|
useContext as useWagmiContext,
|
||||||
|
} from "wagmi";
|
||||||
|
|
||||||
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
||||||
[ChainId.Mainnet]: "https://safe-transaction.mainnet.gnosis.io",
|
// mainnet
|
||||||
[ChainId.Avalanche]: "https://safe-transaction.avalanche.gnosis.io",
|
1: "https://safe-transaction.mainnet.gnosis.io",
|
||||||
[ChainId.Polygon]: "https://safe-transaction.polygon.gnosis.io",
|
// avalanche
|
||||||
[ChainId.Goerli]: "https://safe-transaction.goerli.gnosis.io",
|
43114: "https://safe-transaction.avalanche.gnosis.io",
|
||||||
|
// polygon
|
||||||
|
137: "https://safe-transaction.polygon.gnosis.io",
|
||||||
|
// goerli
|
||||||
|
5: "https://safe-transaction.goerli.gnosis.io",
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface GnosisConnectorArguments {
|
export interface GnosisConnectorArguments {
|
||||||
@@ -163,3 +173,67 @@ export class GnosisSafeConnector extends Connector {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { useGnosis } from "@thirdweb-dev/react"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* import { useGnosis } from "@thirdweb-dev/react"
|
||||||
|
*
|
||||||
|
* const App = () => {
|
||||||
|
* const connectWithGnosis = useGnosis()
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button onClick={() => connectWithGnosis({ safeAddress: "0x...", safeChainId: 1 })}>
|
||||||
|
* Connect Gnosis Safe
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useGnosis() {
|
||||||
|
const wagmiContext = useWagmiContext();
|
||||||
|
invariant(
|
||||||
|
wagmiContext,
|
||||||
|
`useGnosis() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||||
|
);
|
||||||
|
const [connectors, connect] = useConnect();
|
||||||
|
if (connectors.loading) {
|
||||||
|
return () => Promise.reject("Gnosis connector not ready to be used, yet");
|
||||||
|
}
|
||||||
|
const connector = connectors.data.connectors.find((c) => c.id === "gnosis");
|
||||||
|
invariant(
|
||||||
|
connector,
|
||||||
|
"Gnosis connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
||||||
|
);
|
||||||
|
|
||||||
|
return async (config: GnosisConnectorArguments) => {
|
||||||
|
const previousConnector = connectors.data.connector;
|
||||||
|
const previousConnectorChain = await previousConnector?.getChainId();
|
||||||
|
invariant(
|
||||||
|
!!previousConnector,
|
||||||
|
"Cannot connect to Gnosis Safe without first being connected to a personal wallet.",
|
||||||
|
);
|
||||||
|
invariant(
|
||||||
|
previousConnectorChain === config.safeChainId,
|
||||||
|
"Gnosis safe chain id must match personal wallet chain id.",
|
||||||
|
);
|
||||||
|
invariant(
|
||||||
|
utils.isAddress(config.safeAddress),
|
||||||
|
"Gnosis safe address must be a valid address.",
|
||||||
|
);
|
||||||
|
(connector as GnosisSafeConnector).setConfiguration(
|
||||||
|
previousConnector,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
return connect(connector);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useConnect } from "../hooks/wagmi-required/useConnect";
|
||||||
import { providers, utils } from "ethers";
|
import { providers, utils } from "ethers";
|
||||||
import type {
|
import type {
|
||||||
LoginWithMagicLinkConfiguration,
|
LoginWithMagicLinkConfiguration,
|
||||||
@@ -5,7 +6,12 @@ import type {
|
|||||||
MagicSDKAdditionalConfiguration,
|
MagicSDKAdditionalConfiguration,
|
||||||
} from "magic-sdk";
|
} from "magic-sdk";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { Chain, Connector, normalizeChainId } from "wagmi";
|
import {
|
||||||
|
Chain,
|
||||||
|
Connector,
|
||||||
|
normalizeChainId,
|
||||||
|
useContext as useWagmiContext,
|
||||||
|
} from "wagmi";
|
||||||
|
|
||||||
export interface MagicConnectorArguments
|
export interface MagicConnectorArguments
|
||||||
extends MagicSDKAdditionalConfiguration {
|
extends MagicSDKAdditionalConfiguration {
|
||||||
@@ -186,3 +192,89 @@ export class MagicConnector extends Connector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook for connecting to an email wallet using magic link.
|
||||||
|
* This enables users without their own wallets to connect to your application and sign transactions securely using their email.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* import { useMagic } from "@thirdweb-dev/react"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* Before using this hook, you first need to set up the magic configuration in your `ThirdwebProvider`, including your magic API key.
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* // Add the magic configuration object to your wallet connectors
|
||||||
|
* const connectors = [
|
||||||
|
* "metamask",
|
||||||
|
* "walletConnect",
|
||||||
|
* "walletLink",
|
||||||
|
* {
|
||||||
|
* name: "magic",
|
||||||
|
* options: {
|
||||||
|
* apiKey: "your-magic-api-key",
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* ]
|
||||||
|
*
|
||||||
|
* // Add the above to the walletConnectors prop of your <ThirdwebProvider />
|
||||||
|
* const Provider = ({ children }) => (
|
||||||
|
* return (
|
||||||
|
* <ThirdwebProvider
|
||||||
|
* walletConnectors={connectors}
|
||||||
|
* // Specify remaining parameters
|
||||||
|
* ...
|
||||||
|
* >
|
||||||
|
* {children}
|
||||||
|
* </ThirdwebProvider>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* In order to use the hook to connect users with magic link, you just need to provide the users email to the connect function.
|
||||||
|
*
|
||||||
|
* You can setup the hook with the following configuration:
|
||||||
|
* ```javascript
|
||||||
|
* import { useMagic } from "@thirdweb-dev/react"
|
||||||
|
* import { useState } from "react"
|
||||||
|
*
|
||||||
|
* const LoginWithMagicLink = () => {
|
||||||
|
* const connectWithMagic = useMagic()
|
||||||
|
* const [email, setEmail] = useState()
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <div>
|
||||||
|
* <input value={email} onChange={(e) => setEmail(e.target.value)} />
|
||||||
|
* <button onClick={() => connectWithMagic({ email })}>Login</button>
|
||||||
|
* </div>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useMagic() {
|
||||||
|
const wagmiContext = useWagmiContext();
|
||||||
|
invariant(
|
||||||
|
wagmiContext,
|
||||||
|
`useMagic() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
||||||
|
);
|
||||||
|
const [connectors, connect] = useConnect();
|
||||||
|
if (connectors.loading) {
|
||||||
|
return () => Promise.reject("Magic connector not ready to be used, yet");
|
||||||
|
}
|
||||||
|
|
||||||
|
const connector = connectors.data.connectors.find((c) => c.id === "magic");
|
||||||
|
|
||||||
|
invariant(
|
||||||
|
connector,
|
||||||
|
"Magic connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
||||||
|
);
|
||||||
|
|
||||||
|
return (configuration: LoginWithMagicLinkConfiguration) => {
|
||||||
|
(connector as MagicConnector).setConfiguration(configuration);
|
||||||
|
return connect(connector);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,17 @@ export const ThirdwebConnectedWalletProvider: React.FC<
|
|||||||
const { rpcUrlMap } = useThirdwebConfigContext();
|
const { rpcUrlMap } = useThirdwebConfigContext();
|
||||||
|
|
||||||
const [contextValue, setContextValue] =
|
const [contextValue, setContextValue] =
|
||||||
useState<ThirdwebConnectedWalletContext>(INITIAL_CONTEXT_VALUE);
|
useState<ThirdwebConnectedWalletContext>({
|
||||||
|
...INITIAL_CONTEXT_VALUE,
|
||||||
|
signer: signer ? signer : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setContextValue((val) => ({
|
||||||
|
...val,
|
||||||
|
signer: signer ? signer : undefined,
|
||||||
|
}));
|
||||||
|
}, [signer]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let s = signer;
|
let s = signer;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export type SetClaimConditionsParams = {
|
|||||||
/** **********************/
|
/** **********************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to get the active claim conditon for ERC20, ERC721 or ERC1155 based contracts. They need to extend the `claimCondition` extension for this hook to work.
|
* Use this to get the active claim condition for ERC20, ERC721 or ERC1155 based contracts. They need to extend the `claimCondition` extension for this hook to work.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
@@ -60,7 +60,7 @@ export type SetClaimConditionsParams = {
|
|||||||
* const { data: activeClaimCondition, isLoading, error } = useActiveClaimCondition(<YourERC1155ContractInstance>, <tokenId>);
|
* const { data: activeClaimCondition, isLoading, error } = useActiveClaimCondition(<YourERC1155ContractInstance>, <tokenId>);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param contract - an instance of a contract that extends the ERC721 or ERC1155 spec and implements the `claimConditions` extension.
|
* @param contract - an instance of a contract that extends the ERC721, ERC1155 or ERC20 spec and implements the `claimConditions` extension.
|
||||||
* @param tokenId - the id of the token to fetch the claim conditions for (if the contract is an ERC1155 contract)
|
* @param tokenId - the id of the token to fetch the claim conditions for (if the contract is an ERC1155 contract)
|
||||||
* @returns a response object with the currently active claim condition
|
* @returns a response object with the currently active claim condition
|
||||||
* @twfeature ERC721ClaimableWithConditions | ERC1155ClaimableWithConditions | ERC20ClaimableWithConditions
|
* @twfeature ERC721ClaimableWithConditions | ERC1155ClaimableWithConditions | ERC20ClaimableWithConditions
|
||||||
@@ -106,7 +106,70 @@ export function useActiveClaimCondition(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to get all claim conditons for ERC20, ERC721 or ERC1155 based contracts. They need to extend the `claimCondition` extension for this hook to work.
|
* Use this to get the claimer proofs for an adddress for ERC20, ERC721 or ERC1155 based contracts. They need to extend the `claimCondition` extension for this hook to work.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: claimerProofs, isLoading, error } = useClaimerProofs(<YourERC20ContractInstance>);
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: claimerProofs, isLoading, error } = useClaimerProofs(<YourERC721ContractInstance>);
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: claimerProofs, isLoading, error } = useClaimerProofs(<YourERC1155ContractInstance>, <tokenId>);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a contract that extends the ERC721, ERC1155 or ERC20 spec and implements the `claimConditions` extension.
|
||||||
|
* @param claimerAddress - the address of the claimer to fetch the claimer proofs for
|
||||||
|
* @param tokenId - the id of the token to fetch the claimer proofs for (if the contract is an ERC1155 contract)
|
||||||
|
* @param claimConditionId - optional the claim condition id to get the proofs for
|
||||||
|
* @returns a response object with the snapshot for the provided address
|
||||||
|
* @twfeature ERC721ClaimableWithConditions | ERC1155ClaimableWithConditions | ERC20ClaimableWithConditions
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useClaimerProofs(
|
||||||
|
contract: RequiredParam<DropContract>,
|
||||||
|
claimerAddress: string,
|
||||||
|
tokenId?: BigNumberish,
|
||||||
|
claimConditionId?: BigNumberish,
|
||||||
|
) {
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||||
|
|
||||||
|
return useQueryWithNetwork(
|
||||||
|
cacheKeys.extensions.claimConditions.getClaimerProofs(
|
||||||
|
contractAddress,
|
||||||
|
tokenId,
|
||||||
|
),
|
||||||
|
() => {
|
||||||
|
if (erc1155) {
|
||||||
|
requiredParamInvariant(
|
||||||
|
tokenId,
|
||||||
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
|
);
|
||||||
|
return erc1155.claimConditions.getClaimerProofs(tokenId, claimerAddress, claimConditionId);
|
||||||
|
}
|
||||||
|
if (erc721) {
|
||||||
|
return erc721.claimConditions.getClaimerProofs(claimerAddress, claimConditionId);
|
||||||
|
}
|
||||||
|
if (erc20) {
|
||||||
|
return erc20.claimConditions.getClaimerProofs(claimerAddress, claimConditionId);
|
||||||
|
}
|
||||||
|
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// Checks that happen here:
|
||||||
|
// 1. if the contract is based on ERC1155 contract => tokenId cannot be `undefined`
|
||||||
|
// 2. if the contract is NOT based on ERC1155 => we have to have either an ERC721 or ERC20 contract
|
||||||
|
enabled: erc1155 ? tokenId !== undefined : !!erc721 || !!erc20,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to get all claim conditions for ERC20, ERC721 or ERC1155 based contracts. They need to extend the `claimCondition` extension for this hook to work.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
@@ -121,7 +184,7 @@ export function useActiveClaimCondition(
|
|||||||
* const { data: claimConditions, isLoading, error } = useClaimConditions(<YourERC1155ContractInstance>, <tokenId>);
|
* const { data: claimConditions, isLoading, error } = useClaimConditions(<YourERC1155ContractInstance>, <tokenId>);
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param contract - an instance of a contract that extends the ERC721 or ERC1155 spec and implements the `claimConditions` extension.
|
* @param contract - an instance of a contract that extends the ERC721, ERC1155 or ERC20 spec and implements the `claimConditions` extension.
|
||||||
* @param tokenId - the id of the token to fetch the claim conditions for (if the contract is an ERC1155 contract)
|
* @param tokenId - the id of the token to fetch the claim conditions for (if the contract is an ERC1155 contract)
|
||||||
* @returns a response object with the list of claim conditions
|
* @returns a response object with the list of claim conditions
|
||||||
* @twfeature ERC721ClaimableWithConditions | ERC1155ClaimableWithConditions | ERC20ClaimableWithConditions
|
* @twfeature ERC721ClaimableWithConditions | ERC1155ClaimableWithConditions | ERC20ClaimableWithConditions
|
||||||
@@ -368,8 +431,6 @@ export function useResetClaimConditions(
|
|||||||
return conditions.map((c) => ({
|
return conditions.map((c) => ({
|
||||||
...c,
|
...c,
|
||||||
price: c.currencyMetadata.displayValue,
|
price: c.currencyMetadata.displayValue,
|
||||||
maxQuantity: c.maxQuantity.toString(),
|
|
||||||
quantityLimitPerTransaction: c.quantityLimitPerTransaction.toString(),
|
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import {
|
|||||||
ContractEvent,
|
ContractEvent,
|
||||||
ContractForPrebuiltContractType,
|
ContractForPrebuiltContractType,
|
||||||
ContractType,
|
ContractType,
|
||||||
EventQueryFilter,
|
EventQueryOptions,
|
||||||
PrebuiltContractType,
|
PrebuiltContractType,
|
||||||
SUPPORTED_CHAIN_ID,
|
SUPPORTED_CHAIN_ID,
|
||||||
ThirdwebSDK,
|
ThirdwebSDK,
|
||||||
@@ -346,7 +346,7 @@ export function useContractMetadataUpdate(
|
|||||||
export function useContractEvents(
|
export function useContractEvents(
|
||||||
contract: RequiredParam<ValidContractInstance>,
|
contract: RequiredParam<ValidContractInstance>,
|
||||||
eventName?: string,
|
eventName?: string,
|
||||||
options: { queryFilter?: EventQueryFilter; subscribe?: boolean } = {
|
options: { queryFilter?: EventQueryOptions; subscribe?: boolean } = {
|
||||||
subscribe: true,
|
subscribe: true,
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -3,13 +3,20 @@ import {
|
|||||||
requiredParamInvariant,
|
requiredParamInvariant,
|
||||||
} from "../../../core/query-utils/required-param";
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDKChainId } from "../../providers/base";
|
||||||
import { BuyNowParams, MakeBidParams } from "../../types";
|
import {
|
||||||
|
AcceptDirectOffer,
|
||||||
|
BuyNowParams,
|
||||||
|
ExecuteAuctionSale,
|
||||||
|
MakeBidParams,
|
||||||
|
MakeOfferParams,
|
||||||
|
} from "../../types";
|
||||||
import {
|
import {
|
||||||
cacheKeys,
|
cacheKeys,
|
||||||
invalidateContractAndBalances,
|
invalidateContractAndBalances,
|
||||||
} from "../../utils/cache-keys";
|
} from "../../utils/cache-keys";
|
||||||
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
import { useQueryWithNetwork } from "../query-utils/useQueryWithNetwork";
|
||||||
import { useAddress } from "../wallet";
|
import { useAddress } from "../wallet";
|
||||||
|
import { useContractEvents } from "./contracts";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type {
|
import type {
|
||||||
AuctionListing,
|
AuctionListing,
|
||||||
@@ -514,6 +521,203 @@ export function useMakeBid(contract: RequiredParam<Marketplace>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to make an offer on direct or auction listing from your marketplace contract.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: makeOffer,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useMakeOffer(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to make a bid", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => makeOffer({ listingId: 1, pricePerToken: 0.5, quantity: 1 })}
|
||||||
|
* >
|
||||||
|
* Bid!
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to make a bid on an auction listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useMakeOffer(contract: RequiredParam<Marketplace>) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: MakeOfferParams) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract, "No Contract instance provided");
|
||||||
|
return await contract.makeOffer(
|
||||||
|
data.listingId,
|
||||||
|
data.pricePerToken,
|
||||||
|
data.quantity,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accept an offer on a direct listing from an offeror, will accept the latest offer by the given offeror.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: acceptOffer,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useAcceptDirectListingOffer(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to accept offer", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => acceptOffer({ listingId: 1, addressOfOfferor: "0x..." })}
|
||||||
|
* >
|
||||||
|
* Accept offer
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to accept an offer on a direct listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useAcceptDirectListingOffer(
|
||||||
|
contract: RequiredParam<Marketplace>,
|
||||||
|
) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: AcceptDirectOffer) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(contract?.direct, "No Direct instance provided");
|
||||||
|
return await contract.direct.acceptOffer(
|
||||||
|
data.listingId,
|
||||||
|
data.addressOfOfferor,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute an auction sale. Can only be executed once the auction has ended and the auction has a winning bid.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* const Component = () => {
|
||||||
|
* const {
|
||||||
|
* mutate: executeAuctionSale,
|
||||||
|
* isLoading,
|
||||||
|
* error,
|
||||||
|
* } = useExecuteAuctionSale(">>YourMarketplaceContractInstance<<");
|
||||||
|
*
|
||||||
|
* if (error) {
|
||||||
|
* console.error("failed to execute sale", error);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* disabled={isLoading}
|
||||||
|
* onClick={() => executeAuctionSale({ listingId: 1 })}
|
||||||
|
* >
|
||||||
|
* Execute sale
|
||||||
|
* </button>
|
||||||
|
* );
|
||||||
|
* };
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @returns a mutation object that can be used to accept an offer on a direct listing
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useExecuteAuctionSale(contract: RequiredParam<Marketplace>) {
|
||||||
|
const activeChainId = useSDKChainId();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const walletAddress = useAddress();
|
||||||
|
return useMutation(
|
||||||
|
async (data: ExecuteAuctionSale) => {
|
||||||
|
invariant(walletAddress, "no wallet connected, cannot make bid");
|
||||||
|
requiredParamInvariant(
|
||||||
|
contract?.auction,
|
||||||
|
"No Auction marketplace instance provided",
|
||||||
|
);
|
||||||
|
return await contract.auction.executeSale(data.listingId);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
invalidateContractAndBalances(
|
||||||
|
queryClient,
|
||||||
|
contractAddress,
|
||||||
|
activeChainId,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the offers for a listing
|
||||||
|
*
|
||||||
|
* @remarks Fetch all the offers for a specified direct or auction listing.
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* const { data: offers, isLoading, error } = useOffers(<YourMarketplaceContractInstance>, <listingId>);
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a Marketplace contract
|
||||||
|
* @param listingId - the id of the listing to fetch offers for
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useOffers(
|
||||||
|
contract: RequiredParam<Marketplace>,
|
||||||
|
listingId: RequiredParam<BigNumberish>,
|
||||||
|
) {
|
||||||
|
const result = useContractEvents(contract, "NewOffer");
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
data: result.data
|
||||||
|
?.filter((ev) => ev.data.listingId.eq(listingId))
|
||||||
|
?.map((ev) => ev.data),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this to buy out an auction listing from your marketplace contract.
|
* Use this to buy out an auction listing from your marketplace contract.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ export function useTransferNFT<TContract extends NFTContract>(
|
|||||||
* @example
|
* @example
|
||||||
* ```jsx
|
* ```jsx
|
||||||
* const Component = () => {
|
* const Component = () => {
|
||||||
* const editionDrop = useEditionDrop(<ContractAddress>);
|
* const editionDrop = useContract(<ContractAddress>, "edition-drop");
|
||||||
* const {
|
* const {
|
||||||
* mutate: airdropNFT,
|
* mutate: airdropNFT,
|
||||||
* isLoading,
|
* isLoading,
|
||||||
|
|||||||
@@ -232,11 +232,9 @@ export function useClaimToken(contract: RequiredParam<TokenContract>) {
|
|||||||
invariant(data.to, 'No "to" address provided');
|
invariant(data.to, 'No "to" address provided');
|
||||||
if (erc20) {
|
if (erc20) {
|
||||||
invariant(erc20?.claimTo, "contract does not support claimTo");
|
invariant(erc20?.claimTo, "contract does not support claimTo");
|
||||||
return await erc20.claimTo(
|
return await erc20.claimTo(data.to, data.amount, {
|
||||||
data.to,
|
checkERC20Allowance: data.checkERC20Allowance,
|
||||||
data.amount,
|
});
|
||||||
data.checkERC20Allowance,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
invariant(false, "Smart contract is not a valid erc20 contract");
|
invariant(false, "Smart contract is not a valid erc20 contract");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import {
|
|
||||||
GnosisConnectorArguments,
|
|
||||||
GnosisSafeConnector,
|
|
||||||
} from "../../connectors/gnosis-safe";
|
|
||||||
import { useConnect } from "../wagmi-required/useConnect";
|
|
||||||
import { utils } from "ethers";
|
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook for connecting to a Gnosis Safe. This enables multisig wallets to connect to your application and sing transactions.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* import { useGnosis } from "@thirdweb-dev/react"
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* ```javascript
|
|
||||||
* import { useGnosis } from "@thirdweb-dev/react"
|
|
||||||
*
|
|
||||||
* const App = () => {
|
|
||||||
* const connectWithGnosis = useGnosis()
|
|
||||||
*
|
|
||||||
* return (
|
|
||||||
* <button onClick={() => connectWithGnosis({ safeAddress: "0x...", safeChainId: 1 })}>
|
|
||||||
* Connect Gnosis Safe
|
|
||||||
* </button>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export function useGnosis() {
|
|
||||||
const wagmiContext = useWagmiContext();
|
|
||||||
invariant(
|
|
||||||
wagmiContext,
|
|
||||||
`useGnosis() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
|
||||||
);
|
|
||||||
const [connectors, connect] = useConnect();
|
|
||||||
if (connectors.loading) {
|
|
||||||
return () => Promise.reject("Gnosis connector not ready to be used, yet");
|
|
||||||
}
|
|
||||||
const connector = connectors.data.connectors.find((c) => c.id === "gnosis");
|
|
||||||
invariant(
|
|
||||||
connector,
|
|
||||||
"Gnosis connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
|
||||||
);
|
|
||||||
|
|
||||||
return async (config: GnosisConnectorArguments) => {
|
|
||||||
const previousConnector = connectors.data.connector;
|
|
||||||
const previousConnectorChain = await previousConnector?.getChainId();
|
|
||||||
invariant(
|
|
||||||
!!previousConnector,
|
|
||||||
"Cannot connect to Gnosis Safe without first being connected to a personal wallet.",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
previousConnectorChain === config.safeChainId,
|
|
||||||
"Gnosis safe chain id must match personal wallet chain id.",
|
|
||||||
);
|
|
||||||
invariant(
|
|
||||||
utils.isAddress(config.safeAddress),
|
|
||||||
"Gnosis safe address must be a valid address.",
|
|
||||||
);
|
|
||||||
(connector as GnosisSafeConnector).setConfiguration(
|
|
||||||
previousConnector,
|
|
||||||
config,
|
|
||||||
);
|
|
||||||
return connect(connector);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
import { MagicConnector } from "../../connectors/magic";
|
|
||||||
import { useConnect } from "../wagmi-required/useConnect";
|
|
||||||
import { LoginWithMagicLinkConfiguration } from "magic-sdk";
|
|
||||||
import invariant from "tiny-invariant";
|
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook for connecting to an email wallet using magic link.
|
|
||||||
* This enables users without their own wallets to connect to your application and sign transactions securely using their email.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* import { useMagic } from "@thirdweb-dev/react"
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* Before using this hook, you first need to set up the magic configuration in your `ThirdwebProvider`, including your magic API key.
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* // Add the magic configuration object to your wallet connectors
|
|
||||||
* const connectors = [
|
|
||||||
* "metamask",
|
|
||||||
* "walletConnect",
|
|
||||||
* "walletLink",
|
|
||||||
* {
|
|
||||||
* name: "magic",
|
|
||||||
* options: {
|
|
||||||
* apiKey: "your-magic-api-key",
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ]
|
|
||||||
*
|
|
||||||
* // Add the above to the walletConnectors prop of your <ThirdwebProvider />
|
|
||||||
* const Provider = ({ children }) => (
|
|
||||||
* return (
|
|
||||||
* <ThirdwebProvider
|
|
||||||
* walletConnectors={connectors}
|
|
||||||
* // Specify remaining parameters
|
|
||||||
* ...
|
|
||||||
* >
|
|
||||||
* {children}
|
|
||||||
* </ThirdwebProvider>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* In order to use the hook to connect users with magic link, you just need to provide the users email to the connect function.
|
|
||||||
*
|
|
||||||
* You can setup the hook with the following configuration:
|
|
||||||
* ```javascript
|
|
||||||
* import { useMagic } from "@thirdweb-dev/react"
|
|
||||||
* import { useState } from "react"
|
|
||||||
*
|
|
||||||
* const LoginWithMagicLink = () => {
|
|
||||||
* const connectWithMagic = useMagic()
|
|
||||||
* const [email, setEmail] = useState()
|
|
||||||
*
|
|
||||||
* return (
|
|
||||||
* <div>
|
|
||||||
* <input value={email} onChange={(e) => setEmail(e.target.value)} />
|
|
||||||
* <button onClick={() => connectWithMagic({ email })}>Login</button>
|
|
||||||
* </div>
|
|
||||||
* )
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export function useMagic() {
|
|
||||||
const wagmiContext = useWagmiContext();
|
|
||||||
invariant(
|
|
||||||
wagmiContext,
|
|
||||||
`useMagic() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own wallet-connection logic.`,
|
|
||||||
);
|
|
||||||
const [connectors, connect] = useConnect();
|
|
||||||
if (connectors.loading) {
|
|
||||||
return () => Promise.reject("Magic connector not ready to be used, yet");
|
|
||||||
}
|
|
||||||
|
|
||||||
const connector = connectors.data.connectors.find((c) => c.id === "magic");
|
|
||||||
|
|
||||||
invariant(
|
|
||||||
connector,
|
|
||||||
"Magic connector not found, please make sure it is provided to your <ThirdwebProvider />",
|
|
||||||
);
|
|
||||||
|
|
||||||
return (configuration: LoginWithMagicLinkConfiguration) => {
|
|
||||||
(connector as MagicConnector).setConfiguration(configuration);
|
|
||||||
return connect(connector);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useConnect } from "../wagmi-required/useConnect";
|
import { useConnect } from "../wagmi-required/useConnect";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
import { useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
if (!globalThis.Buffer) {
|
globalThis.Buffer = Buffer;
|
||||||
globalThis.Buffer = require("buffer/").Buffer;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Hook for connecting to a mobile wallet with Wallet Connect
|
* Hook for connecting to a mobile wallet with Wallet Connect
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useConnect } from "../wagmi-required/useConnect";
|
import { useConnect } from "../wagmi-required/useConnect";
|
||||||
|
import { Buffer } from "buffer";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useContext as useWagmiContext } from "wagmi";
|
import { useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
if (!globalThis.Buffer) {
|
globalThis.Buffer = Buffer;
|
||||||
globalThis.Buffer = require("buffer/").Buffer;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Hook for connecting to a Coinbase wallet.
|
* Hook for connecting to a Coinbase wallet.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const edition = await sdk.useEdition("0x1234...");
|
* - const edition = useEdition("0x1234...");
|
||||||
* + const edition = await sdk.useContract("0x1234...", "edition").contract;
|
* + const edition = useContract("0x1234...", "edition").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useEdition(contractAddress: RequiredParam<string>) {
|
export function useEdition(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const editionDrop = await sdk.useEditionDrop("0x1234...");
|
* - const editionDrop = useEditionDrop("0x1234...");
|
||||||
* + const editionDrop = await sdk.useContract("0x1234...", "edition-drop").contract;
|
* + const editionDrop = useContract("0x1234...", "edition-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useEditionDrop(contractAddress: RequiredParam<string>) {
|
export function useEditionDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const marketplace = await sdk.useMarketplace("0x1234...");
|
* - const marketplace = useMarketplace("0x1234...");
|
||||||
* + const marketplace = await sdk.useContract("0x1234...", "marketplace").contract;
|
* + const marketplace = useContract("0x1234...", "marketplace").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useMarketplace(contractAddress: RequiredParam<string>) {
|
export function useMarketplace(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const multiwrap = await sdk.useMultiwrap("0x1234...");
|
* - const multiwrap = useMultiwrap("0x1234...");
|
||||||
* + const multiwrap = await sdk.useContract("0x1234...", "multiwrap").contract;
|
* + const multiwrap = useContract("0x1234...", "multiwrap").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useMultiwrap(contractAddress: RequiredParam<string>) {
|
export function useMultiwrap(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { useContract } from "../async/contracts";
|
|||||||
* import { useContract } from '@thirdweb-dev/react'
|
* import { useContract } from '@thirdweb-dev/react'
|
||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const { contract } = useNFTCollection("<YOUR-CONTRACT-ADDRESS>", "nft-collection")
|
* const { contract, isLoading, error } = useContract("<YOUR-CONTRACT-ADDRESS>", "nft-collection")
|
||||||
*
|
*
|
||||||
* // Now you can use the nftCollection contract in the rest of the component
|
* // Now you can use the nftCollection contract in the rest of the component
|
||||||
*
|
*
|
||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const nftCollection = await sdk.useNFTCollection("0x1234...");
|
* - const nftCollection = useNFTCollection("0x1234...");
|
||||||
* + const nftCollection = await sdk.useContract("0x1234...", "nft-collection").contract;
|
* + const nftCollection = useContract("0x1234...", "nft-collection").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useNFTCollection(contractAddress: RequiredParam<string>) {
|
export function useNFTCollection(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const nftDrop = await sdk.useNFTDrop("0x1234...");
|
* - const nftDrop = useNFTDrop("0x1234...");
|
||||||
* + const nftDrop = await sdk.useContract("0x1234...", "nft-drop").contract;
|
* + const nftDrop = useContract("0x1234...", "nft-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useNFTDrop(contractAddress: RequiredParam<string>) {
|
export function useNFTDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const pack = await sdk.usePack("0x1234...");
|
* - const pack = usePack("0x1234...");
|
||||||
* + const pack = await sdk.useContract("0x1234...", "pack").contract;
|
* + const pack = useContract("0x1234...", "pack").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function usePack(contractAddress: RequiredParam<string>) {
|
export function usePack(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const signatureDrop = await sdk.useSignatureDrop("0x1234...");
|
* - const signatureDrop = useSignatureDrop("0x1234...");
|
||||||
* + const signatureDrop = await sdk.useContract("0x1234...", "signature-drop").contract;
|
* + const signatureDrop = useContract("0x1234...", "signature-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useSignatureDrop(contractAddress?: RequiredParam<string>) {
|
export function useSignatureDrop(contractAddress?: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const split = await sdk.useSplit("0x1234...");
|
* - const split = useSplit("0x1234...");
|
||||||
* + const split = await sdk.useContract("0x1234...", "split").contract;
|
* + const split = useContract("0x1234...", "split").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useSplit(contractAddress: RequiredParam<string>) {
|
export function useSplit(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const token = await sdk.useToken("0x1234...");
|
* - const token = useToken("0x1234...");
|
||||||
* + const token = await sdk.useContract("0x1234...", "token").contract;
|
* + const token = useContract("0x1234...", "token").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useToken(contractAddress: RequiredParam<string>) {
|
export function useToken(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const token = await sdk.useTokenDrop("0x1234...");
|
* - const token = useTokenDrop("0x1234...");
|
||||||
* + const token = await sdk.useContract("0x1234...", "token-drop").contract;
|
* + const token = useContract("0x1234...", "token-drop").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useTokenDrop(contractAddress: RequiredParam<string>) {
|
export function useTokenDrop(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ import { useContract } from "../async/contracts";
|
|||||||
* @deprecated
|
* @deprecated
|
||||||
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
* This hook is deprecated and will be removed in a future major version. You should use {@link useContract} instead.
|
||||||
* ```diff
|
* ```diff
|
||||||
* - const vote = await sdk.useVote("0x1234...");
|
* - const vote = useVote("0x1234...");
|
||||||
* + const vote = await sdk.useContract("0x1234...", "vote").contract;
|
* + const vote = useContract("0x1234...", "vote").contract;
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function useVote(contractAddress: RequiredParam<string>) {
|
export function useVote(contractAddress: RequiredParam<string>) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { GnosisSafeConnector } from "../../connectors/gnosis-safe";
|
|
||||||
import { useConnect } from "./useConnect";
|
import { useConnect } from "./useConnect";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
import { useAccount, useContext as useWagmiContext } from "wagmi";
|
import { Connector, useAccount, useContext as useWagmiContext } from "wagmi";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook for disconnecting the currently connected wallet
|
* Hook for disconnecting the currently connected wallet
|
||||||
@@ -31,23 +30,22 @@ import { useAccount, useContext as useWagmiContext } from "wagmi";
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function useDisconnect(options?: { reconnectAfterGnosis?: boolean }) {
|
export function useDisconnect(options?: { reconnectPrevious?: boolean }) {
|
||||||
const wagmiContext = useWagmiContext();
|
const wagmiContext = useWagmiContext();
|
||||||
invariant(
|
invariant(
|
||||||
wagmiContext,
|
wagmiContext,
|
||||||
`useDisconnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
|
`useDisconnect() can only be used inside <ThirdwebProvider />. If you are using <ThirdwebSDKProvider /> you will have to use your own connection logic.`,
|
||||||
);
|
);
|
||||||
const optsWithDefaults = { ...{ reconnectAfterGnosis: true }, ...options };
|
const optsWithDefaults = { ...{ reconnectPrevious: true }, ...options };
|
||||||
const [, connect] = useConnect();
|
const [, connect] = useConnect();
|
||||||
const [data, disconnect] = useAccount();
|
const [data, disconnect] = useAccount();
|
||||||
|
|
||||||
return async () => {
|
return async () => {
|
||||||
const previousConnector =
|
// if there is a previous connector get it
|
||||||
(data.data?.connector instanceof GnosisSafeConnector &&
|
const previousConnector: Connector | undefined =
|
||||||
data.data.connector.previousConnector) ||
|
(data?.data?.connector as any)?.previousConnector || undefined;
|
||||||
undefined;
|
|
||||||
// if it's gnosis, just connect the previous connector
|
// if it's gnosis, just connect the previous connector
|
||||||
if (optsWithDefaults.reconnectAfterGnosis && previousConnector) {
|
if (optsWithDefaults.reconnectPrevious && previousConnector) {
|
||||||
try {
|
try {
|
||||||
return await connect(previousConnector);
|
return await connect(previousConnector);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ export * from "./hooks/wagmi-required/useConnect";
|
|||||||
export * from "./hooks/connectors/useMetamask";
|
export * from "./hooks/connectors/useMetamask";
|
||||||
export * from "./hooks/connectors/useWalletConnect";
|
export * from "./hooks/connectors/useWalletConnect";
|
||||||
export * from "./hooks/connectors/useWalletLink";
|
export * from "./hooks/connectors/useWalletLink";
|
||||||
export * from "./hooks/connectors/useGnosis";
|
|
||||||
export * from "./hooks/connectors/useMagic";
|
|
||||||
|
|
||||||
// re-exports
|
// re-exports
|
||||||
export { ChainId } from "@thirdweb-dev/sdk";
|
export { ChainId } from "@thirdweb-dev/sdk";
|
||||||
|
|||||||
@@ -1,90 +1,93 @@
|
|||||||
import { useState, useCallback, useLayoutEffect, useEffect, useRef, PropsWithChildren } from "react";
|
import {
|
||||||
import { createPortal } from "react-dom";
|
useState,
|
||||||
|
useCallback,
|
||||||
|
useLayoutEffect,
|
||||||
|
useEffect,
|
||||||
|
useRef,
|
||||||
|
PropsWithChildren,
|
||||||
|
} from "react";
|
||||||
|
import { createPortal } from "react-dom";
|
||||||
|
|
||||||
|
function canUseDOM() {
|
||||||
function canUseDOM() {
|
|
||||||
return !!(
|
return !!(
|
||||||
typeof window !== "undefined" &&
|
typeof window !== "undefined" &&
|
||||||
window.document &&
|
window.document &&
|
||||||
window.document.createElement
|
window.document.createElement
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces a re-render, similar to `forceUpdate` in class components.
|
* Forces a re-render, similar to `forceUpdate` in class components.
|
||||||
*/
|
*/
|
||||||
function useForceUpdate() {
|
function useForceUpdate() {
|
||||||
const [, dispatch] = useState<{}>(Object.create(null));
|
const [, dispatch] = useState<{}>(Object.create(null));
|
||||||
return useCallback(() => {
|
return useCallback(() => {
|
||||||
dispatch(Object.create(null));
|
dispatch(Object.create(null));
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
|
const useIsomorphicLayoutEffect = canUseDOM() ? useLayoutEffect : useEffect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Portal from `@reach/portal`
|
||||||
|
*
|
||||||
|
* @see Docs https://reach.tech/portal#portal
|
||||||
|
*/
|
||||||
|
const PortalImpl: React.FC<PortalProps> = ({
|
||||||
|
children,
|
||||||
|
type = "reach-portal",
|
||||||
|
containerRef,
|
||||||
|
}) => {
|
||||||
|
const mountNode = useRef<HTMLDivElement | null>(null);
|
||||||
|
const portalNode = useRef<HTMLElement | null>(null);
|
||||||
|
const forceUpdate = useForceUpdate();
|
||||||
|
|
||||||
/**
|
useIsomorphicLayoutEffect(() => {
|
||||||
* Portal from `@reach/portal`
|
// This ref may be null when a hot-loader replaces components on the page
|
||||||
*
|
if (!mountNode.current) {
|
||||||
* @see Docs https://reach.tech/portal#portal
|
return;
|
||||||
*/
|
}
|
||||||
const PortalImpl: React.FC<PortalProps> = ({
|
// It's possible that the content of the portal has, itself, been portaled.
|
||||||
children,
|
// In that case, it's important to append to the correct document element.
|
||||||
type = "reach-portal",
|
const ownerDocument = mountNode.current.ownerDocument;
|
||||||
containerRef,
|
const body = containerRef?.current || ownerDocument.body;
|
||||||
}) => {
|
portalNode.current = ownerDocument?.createElement(type);
|
||||||
const mountNode = useRef<HTMLDivElement | null>(null);
|
body.appendChild(portalNode.current);
|
||||||
const portalNode = useRef<HTMLElement | null>(null);
|
forceUpdate();
|
||||||
const forceUpdate = useForceUpdate();
|
return () => {
|
||||||
|
if (portalNode.current && body) {
|
||||||
|
body.removeChild(portalNode.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [type, forceUpdate, containerRef]);
|
||||||
|
|
||||||
|
return portalNode.current ? (
|
||||||
|
createPortal(children, portalNode.current)
|
||||||
|
) : (
|
||||||
|
<span ref={mountNode} />
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useIsomorphicLayoutEffect(() => {
|
export const Portal: React.FC<PortalProps> = ({
|
||||||
// This ref may be null when a hot-loader replaces components on the page
|
unstable_skipInitialRender,
|
||||||
if (!mountNode.current) {return;}
|
...props
|
||||||
// It's possible that the content of the portal has, itself, been portaled.
|
}) => {
|
||||||
// In that case, it's important to append to the correct document element.
|
const [hydrated, setHydrated] = useState(false);
|
||||||
const ownerDocument = mountNode.current.ownerDocument;
|
useEffect(() => {
|
||||||
const body = containerRef?.current || ownerDocument.body;
|
if (unstable_skipInitialRender) {
|
||||||
portalNode.current = ownerDocument?.createElement(type);
|
setHydrated(true);
|
||||||
body.appendChild(portalNode.current);
|
}
|
||||||
forceUpdate();
|
}, [unstable_skipInitialRender]);
|
||||||
return () => {
|
if (unstable_skipInitialRender && !hydrated) {
|
||||||
if (portalNode.current && body) {
|
return null;
|
||||||
body.removeChild(portalNode.current);
|
}
|
||||||
}
|
return <PortalImpl {...props} />;
|
||||||
};
|
};
|
||||||
}, [type, forceUpdate, containerRef]);
|
|
||||||
|
|
||||||
return portalNode.current ? (
|
export type PortalProps = PropsWithChildren<{
|
||||||
createPortal(children, portalNode.current)
|
type?: string;
|
||||||
) : (
|
containerRef?: React.RefObject<Node>;
|
||||||
<span ref={mountNode} />
|
unstable_skipInitialRender?: boolean;
|
||||||
);
|
}>;
|
||||||
};
|
|
||||||
|
|
||||||
export const Portal: React.FC<PortalProps> = ({
|
|
||||||
unstable_skipInitialRender,
|
|
||||||
...props
|
|
||||||
}) => {
|
|
||||||
const [hydrated, setHydrated] = useState(false);
|
|
||||||
useEffect(() => {
|
|
||||||
if (unstable_skipInitialRender) {
|
|
||||||
setHydrated(true);
|
|
||||||
}
|
|
||||||
}, [unstable_skipInitialRender]);
|
|
||||||
if (unstable_skipInitialRender && !hydrated) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return <PortalImpl {...props} />;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
export type PortalProps = PropsWithChildren<{
|
|
||||||
type?: string;
|
|
||||||
containerRef?: React.RefObject<Node>;
|
|
||||||
unstable_skipInitialRender?: boolean;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
Portal.displayName = "Portal";
|
|
||||||
|
|
||||||
|
Portal.displayName = "Portal";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { Signer } from "ethers";
|
import { Signer } from "ethers";
|
||||||
import { createContext, useContext, useEffect, useMemo } from "react";
|
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
interface TWSDKContext {
|
interface TWSDKContext {
|
||||||
@@ -60,21 +60,36 @@ export const WrappedThirdwebSDKProvider: ComponentWithChildren<
|
|||||||
}) => {
|
}) => {
|
||||||
const { signer } = useThirdwebConnectedWalletContext();
|
const { signer } = useThirdwebConnectedWalletContext();
|
||||||
|
|
||||||
const sdk = useMemo(() => {
|
const [sdk, setSDK] = useState<ThirdwebSDK>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
if (!desiredChainId || typeof window === "undefined") {
|
if (!desiredChainId || typeof window === "undefined") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
const _sdk = new ThirdwebSDK(provider, sdkOptions, storageInterface);
|
||||||
|
// if we already have a signer from the wallet context, use it immediately
|
||||||
|
if (signer) {
|
||||||
|
_sdk.updateSignerOrProvider(signer);
|
||||||
|
}
|
||||||
|
|
||||||
(_sdk as any)._constructedAt = Date.now();
|
(_sdk as any)._constructedAt = Date.now();
|
||||||
(_sdk as any)._chainId = desiredChainId;
|
(_sdk as any)._chainId = desiredChainId;
|
||||||
return _sdk;
|
setSDK(_sdk);
|
||||||
|
|
||||||
|
// explicitly *not* passing the signer, if we have it we use it if we don't we don't
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
}, [provider, sdkOptions, storageInterface, desiredChainId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (signer && sdk && (sdk as any)._chainId === desiredChainId) {
|
if (sdk && (sdk as any)._chainId === desiredChainId) {
|
||||||
sdk.updateSignerOrProvider(signer);
|
if (signer) {
|
||||||
|
sdk.updateSignerOrProvider(signer);
|
||||||
|
} else {
|
||||||
|
sdk.updateSignerOrProvider(provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [signer, sdk, desiredChainId]);
|
}, [signer, sdk, desiredChainId, provider]);
|
||||||
|
|
||||||
const ctxValue = useMemo(
|
const ctxValue = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import {
|
import type { GnosisSafeConnector } from "../connectors/gnosis-safe";
|
||||||
GnosisConnectorArguments,
|
import type { MagicConnector } from "../connectors/magic";
|
||||||
GnosisSafeConnector,
|
|
||||||
} from "../connectors/gnosis-safe";
|
|
||||||
import { MagicConnector, MagicConnectorArguments } from "../connectors/magic";
|
|
||||||
import {
|
import {
|
||||||
Chain,
|
Chain,
|
||||||
SupportedChain,
|
SupportedChain,
|
||||||
@@ -25,6 +22,7 @@ import {
|
|||||||
ProviderProps as WagmiproviderProps,
|
ProviderProps as WagmiproviderProps,
|
||||||
useProvider,
|
useProvider,
|
||||||
useSigner,
|
useSigner,
|
||||||
|
Connector,
|
||||||
} from "wagmi";
|
} from "wagmi";
|
||||||
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
|
import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet";
|
||||||
import { InjectedConnector } from "wagmi/connectors/injected";
|
import { InjectedConnector } from "wagmi/connectors/injected";
|
||||||
@@ -56,26 +54,6 @@ export type WalletLinkConnectorType =
|
|||||||
options: CoinbaseWalletConnector["options"];
|
options: CoinbaseWalletConnector["options"];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export type MagicConnectorType =
|
|
||||||
| "magic"
|
|
||||||
| {
|
|
||||||
name: "magic";
|
|
||||||
options: Omit<MagicConnectorArguments, "network">;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export type GnosisConnectorType =
|
|
||||||
| "gnosis"
|
|
||||||
| {
|
|
||||||
name: "gnosis";
|
|
||||||
options: GnosisConnectorArguments;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@@ -83,8 +61,8 @@ export type WalletConnector =
|
|||||||
| InjectedConnectorType
|
| InjectedConnectorType
|
||||||
| WalletConnectConnectorType
|
| WalletConnectConnectorType
|
||||||
| WalletLinkConnectorType
|
| WalletLinkConnectorType
|
||||||
| MagicConnectorType
|
| GnosisSafeConnector
|
||||||
| GnosisConnectorType;
|
| MagicConnector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@@ -280,6 +258,9 @@ export const ThirdwebProvider = <
|
|||||||
connectors: ({ chainId }: { chainId?: number }) => {
|
connectors: ({ chainId }: { chainId?: number }) => {
|
||||||
return walletConnectors
|
return walletConnectors
|
||||||
.map((connector) => {
|
.map((connector) => {
|
||||||
|
if (connector instanceof Connector) {
|
||||||
|
return connector;
|
||||||
|
}
|
||||||
// injected connector
|
// injected connector
|
||||||
if (
|
if (
|
||||||
(typeof connector === "string" &&
|
(typeof connector === "string" &&
|
||||||
@@ -344,25 +325,7 @@ export const ThirdwebProvider = <
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (typeof connector === "object" && connector.name === "magic") {
|
|
||||||
const jsonRpcUrl = _rpcUrlMap[chainId || desiredChainId || 1];
|
|
||||||
return new MagicConnector({
|
|
||||||
chains: _supporrtedChains,
|
|
||||||
options: {
|
|
||||||
...connector.options,
|
|
||||||
network: { rpcUrl: jsonRpcUrl, chainId: desiredChainId || 1 },
|
|
||||||
rpcUrls: _rpcUrlMap,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
(typeof connector === "string" && connector === "gnosis") ||
|
|
||||||
(typeof connector === "object" && connector.name === "gnosis")
|
|
||||||
) {
|
|
||||||
return new GnosisSafeConnector({
|
|
||||||
chains: _supporrtedChains,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
.filter((c) => c !== null);
|
.filter((c) => c !== null);
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import type {
|
|||||||
ClaimOptions,
|
ClaimOptions,
|
||||||
NFTMetadataOrUri,
|
NFTMetadataOrUri,
|
||||||
Token,
|
Token,
|
||||||
|
Multiwrap,
|
||||||
|
Pack,
|
||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition";
|
import type { Edition } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition";
|
||||||
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop";
|
import type { EditionDrop } from "@thirdweb-dev/sdk/dist/declarations/src/evm/contracts/prebuilt-implementations/edition-drop";
|
||||||
@@ -68,6 +70,8 @@ export type TokenBurnParams = {
|
|||||||
export type NFTContract =
|
export type NFTContract =
|
||||||
| NFTCollection
|
| NFTCollection
|
||||||
| Edition
|
| Edition
|
||||||
|
| Pack
|
||||||
|
| Multiwrap
|
||||||
| Exclude<DropContract, "TokenDrop">;
|
| Exclude<DropContract, "TokenDrop">;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -212,6 +216,18 @@ export type ClaimNFTReturnType =
|
|||||||
// MARKETPLACE //
|
// MARKETPLACE //
|
||||||
|
|
||||||
export type MakeBidParams = { listingId: BigNumberish; bid: Price };
|
export type MakeBidParams = { listingId: BigNumberish; bid: Price };
|
||||||
|
export type MakeOfferParams = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
pricePerToken: Price;
|
||||||
|
quantity?: Amount;
|
||||||
|
};
|
||||||
|
export type AcceptDirectOffer = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
addressOfOfferor: string;
|
||||||
|
};
|
||||||
|
export type ExecuteAuctionSale = {
|
||||||
|
listingId: BigNumberish;
|
||||||
|
};
|
||||||
|
|
||||||
export type BuyNowParams<TListingType = ListingType> =
|
export type BuyNowParams<TListingType = ListingType> =
|
||||||
TListingType extends ListingType.Direct
|
TListingType extends ListingType.Direct
|
||||||
|
|||||||
@@ -287,6 +287,16 @@ export const cacheKeys = {
|
|||||||
? ["claimConditions", "getAll", { tokenId }, options]
|
? ["claimConditions", "getAll", { tokenId }, options]
|
||||||
: ["claimConditions", "getAll", options],
|
: ["claimConditions", "getAll", options],
|
||||||
),
|
),
|
||||||
|
getClaimerProofs: (
|
||||||
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
|
tokenId?: BigNumberish,
|
||||||
|
) =>
|
||||||
|
createContractCacheKey(
|
||||||
|
contractAddress,
|
||||||
|
tokenId
|
||||||
|
? ["claimConditions", "getClaimerProofs", { tokenId }]
|
||||||
|
: ["claimConditions", "getClaimerProofs"],
|
||||||
|
),
|
||||||
getClaimIneligibilityReasons: (
|
getClaimIneligibilityReasons: (
|
||||||
contractAddress: RequiredParam<ContractAddress>,
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
params: { walletAddress?: WalletAddress; quantity: string | number },
|
params: { walletAddress?: WalletAddress; quantity: string | number },
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// at the moment we'll re-export everything from the ethereum package (only!)
|
// at the moment we'll re-export everything from the ethereum package
|
||||||
export * from "./evm";
|
export * from "./evm";
|
||||||
|
|
||||||
// core exports
|
// core exports
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@ export function nftRoyaltyQuery(
|
|||||||
*
|
*
|
||||||
* export default function Component() {
|
* export default function Component() {
|
||||||
* const { program } = useProgram("{{program_address}}");
|
* const { program } = useProgram("{{program_address}}");
|
||||||
* const { data: royalty, isLoading } = useRoyalty(program);
|
* const { data: royalty, isLoading } = useRoyaltySettings(program);
|
||||||
*
|
*
|
||||||
* return (
|
* return (
|
||||||
* <p>{royalty}</p>
|
* <p>{royalty}</p>
|
||||||
@@ -40,6 +40,6 @@ export function nftRoyaltyQuery(
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function useRoyalty(program: RequiredParam<NFTCollection | NFTDrop>) {
|
export function useRoyaltySettings(program: RequiredParam<NFTCollection | NFTDrop>) {
|
||||||
return useQuery(nftRoyaltyQuery(program));
|
return useQuery(nftRoyaltyQuery(program));
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { CreatorInput, NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the creators for an NFT program
|
||||||
|
* @param program - The NFT program instance to update the creators for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useUpdateCreators } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { mutateAsync: updateCreators, isLoading, error } = useUpdateCreators(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* onClick={() => updateCreators([{ address: "0x...", share: 10 }])}
|
||||||
|
* >
|
||||||
|
* Update Creators
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useUpdateCreators(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation(
|
||||||
|
async (creators: CreatorInput[]) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateCreators(creators);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { createSOLProgramQueryKey } from "../../../core/query-utils/query-key";
|
||||||
|
import {
|
||||||
|
requiredParamInvariant,
|
||||||
|
RequiredParam,
|
||||||
|
} from "../../../core/query-utils/required-param";
|
||||||
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the royalty for an NFT program
|
||||||
|
* @param program - The NFT program instance to update the royalty for
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useUpdateRoyaltySettings } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { mutateAsync: updateRoyalties, isLoading, error } = useUpdateRoyaltySettings(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <button
|
||||||
|
* onClick={() => updateRoyalties(300)}
|
||||||
|
* >
|
||||||
|
* Update Royalties
|
||||||
|
* </button>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useUpdateRoyaltySettings(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation(
|
||||||
|
async (sellerFeeBasisPoints: number) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateRoyalty(sellerFeeBasisPoints);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,7 +4,8 @@ import {
|
|||||||
RequiredParam,
|
RequiredParam,
|
||||||
} from "../../../core/query-utils/required-param";
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||||
import type { Amount, Token } from "@thirdweb-dev/sdk/solana";
|
import type { Amount } from "@thirdweb-dev/sdk";
|
||||||
|
import type { Token } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
export type TransferTokenMutationParams = {
|
export type TransferTokenMutationParams = {
|
||||||
amount: Amount;
|
amount: Amount;
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ export * from "./hooks/program/useProgramAccountType";
|
|||||||
export * from "./hooks/nft/useNFTs";
|
export * from "./hooks/nft/useNFTs";
|
||||||
export * from "./hooks/nft/useTransferNFT";
|
export * from "./hooks/nft/useTransferNFT";
|
||||||
export * from "./hooks/nft/useBurnNFT";
|
export * from "./hooks/nft/useBurnNFT";
|
||||||
|
export * from "./hooks/nft/useRoyaltySettings";
|
||||||
|
export * from "./hooks/nft/useUpdateRoyaltySettings";
|
||||||
|
export * from "./hooks/nft/useCreators";
|
||||||
|
export * from "./hooks/nft/useUpdateCreators";
|
||||||
|
|
||||||
// NFT Collection
|
// NFT Collection
|
||||||
export * from "./hooks/nft/collection/useMintNFT";
|
export * from "./hooks/nft/collection/useMintNFT";
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
import { ThirdwebAuthConfig } from "../contexts/thirdweb-auth";
|
||||||
import { ThirdwebSDKProvider } from "./base";
|
import { ThirdwebSDKProvider } from "./base";
|
||||||
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
import type { WalletAdapter } from "@solana/wallet-adapter-base";
|
||||||
|
import { PhantomWalletAdapter } from "@solana/wallet-adapter-phantom";
|
||||||
import {
|
import {
|
||||||
ConnectionProvider,
|
ConnectionProvider,
|
||||||
useWallet,
|
useWallet,
|
||||||
WalletProvider,
|
WalletProvider,
|
||||||
} from "@solana/wallet-adapter-react";
|
} from "@solana/wallet-adapter-react";
|
||||||
import { PhantomWalletAdapter } from "@solana/wallet-adapter-wallets";
|
|
||||||
import { getUrlForNetwork, Network } from "@thirdweb-dev/sdk/solana";
|
import { getUrlForNetwork, Network } from "@thirdweb-dev/sdk/solana";
|
||||||
import { PropsWithChildren } from "react";
|
import { PropsWithChildren } from "react";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,99 @@
|
|||||||
# @thirdweb-dev/sdk
|
# @thirdweb-dev/sdk
|
||||||
|
|
||||||
|
## 3.5.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#380](https://github.com/thirdweb-dev/js/pull/380) [`3eba69a`](https://github.com/thirdweb-dev/js/commit/3eba69afd78b7aa472a9c00c9d4220bb69ad1d3e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose sdk.wallet.getChainId()
|
||||||
|
|
||||||
|
- [#376](https://github.com/thirdweb-dev/js/pull/376) [`4af785c`](https://github.com/thirdweb-dev/js/commit/4af785c37c831ecd7087c1c9eb9095922cac0855) Thanks [@adam-maj](https://github.com/adam-maj)! - Update tiered-drop with tokens claimed
|
||||||
|
|
||||||
|
- [#373](https://github.com/thirdweb-dev/js/pull/373) [`6f818f3`](https://github.com/thirdweb-dev/js/commit/6f818f393eb9023b53a3358d62d60ec23a9246bd) Thanks [@adam-maj](https://github.com/adam-maj)! - Update tiered-drop contract version
|
||||||
|
|
||||||
|
- [#377](https://github.com/thirdweb-dev/js/pull/377) [`b79dc18`](https://github.com/thirdweb-dev/js/commit/b79dc18f7ab5155bbf4af02dc1a953546160bad0) Thanks [@adam-maj](https://github.com/adam-maj)! - Add event filters
|
||||||
|
|
||||||
|
- Updated dependencies [[`4af785c`](https://github.com/thirdweb-dev/js/commit/4af785c37c831ecd7087c1c9eb9095922cac0855), [`6f818f3`](https://github.com/thirdweb-dev/js/commit/6f818f393eb9023b53a3358d62d60ec23a9246bd)]:
|
||||||
|
- @thirdweb-dev/contracts-js@1.2.1
|
||||||
|
|
||||||
|
## 3.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#368](https://github.com/thirdweb-dev/js/pull/368) [`4e7b293`](https://github.com/thirdweb-dev/js/commit/4e7b293c543244de79c150ca8c37d941221fc9a3) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix handling of old allowlist proof format
|
||||||
|
|
||||||
|
- [#365](https://github.com/thirdweb-dev/js/pull/365) [`c9c0e4f`](https://github.com/thirdweb-dev/js/commit/c9c0e4ff39b054af746f3aec75fcbd0a3ef7239d) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - now React Native compatible
|
||||||
|
|
||||||
|
## 3.5.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#329](https://github.com/thirdweb-dev/js/pull/329) [`5200d5d`](https://github.com/thirdweb-dev/js/commit/5200d5d7e730da58bd4d3e7c222e3c661265f913) Thanks [@adam-maj](https://github.com/adam-maj)! - ### Breaking changes:
|
||||||
|
|
||||||
|
1. claim conditions had some changes to support the new drop contracts:
|
||||||
|
|
||||||
|
- `maxClaimablePerTransaction` is now named `maxClaimablePerWallet`
|
||||||
|
- `maxQuantity` is now named `maxClaimable`
|
||||||
|
|
||||||
|
2. signature minting now requires a `to` address to be set for security purposees
|
||||||
|
|
||||||
|
### Main Changes:
|
||||||
|
|
||||||
|
- Support for new optimized Drop contracts
|
||||||
|
- Support for new claim conditions with overrides
|
||||||
|
- Don't allow zero address recipient on signature minting
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#362](https://github.com/thirdweb-dev/js/pull/362) [`42a6065`](https://github.com/thirdweb-dev/js/commit/42a606588dfed03c67c57357dd0ee1ad19fad6ea) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SDK] Fix fetching NFTs with numbers as ids
|
||||||
|
|
||||||
|
- Updated dependencies [[`aa6d9ed`](https://github.com/thirdweb-dev/js/commit/aa6d9ed75d126d7a0cca9fb8fc389ff94e9d1e14)]:
|
||||||
|
- @thirdweb-dev/contracts-js@1.2.0
|
||||||
|
|
||||||
|
## 3.4.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#359](https://github.com/thirdweb-dev/js/pull/359) [`e731c1a`](https://github.com/thirdweb-dev/js/commit/e731c1a7c341e6f2b9cc42c88d5c1b036dcf4a7c) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SDK] Allow fetching claimerProofs from any claim condition
|
||||||
|
|
||||||
|
## 3.4.4
|
||||||
|
|
||||||
|
## 3.4.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#353](https://github.com/thirdweb-dev/js/pull/353) [`1c24c3c`](https://github.com/thirdweb-dev/js/commit/1c24c3c3c48476a824f817e09e7bf0fbe67c1db5) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add useUpdateCreators hook, fix CreatorInput schema
|
||||||
|
|
||||||
|
- [#357](https://github.com/thirdweb-dev/js/pull/357) [`65fc7ba`](https://github.com/thirdweb-dev/js/commit/65fc7ba6fff093a971b53cb0979c39768e090ba1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose claimConditions.getClaimerProofs(address) to get allowlist information for a given address
|
||||||
|
|
||||||
|
## 3.4.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#344](https://github.com/thirdweb-dev/js/pull/344) [`21c21c1`](https://github.com/thirdweb-dev/js/commit/21c21c1adfd09b60ad563bfd4c308597140de33c) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Update internal function resolveContractUriFromAddress -> resolveContractUriFromAddress
|
||||||
|
|
||||||
|
- [#352](https://github.com/thirdweb-dev/js/pull/352) [`3522917`](https://github.com/thirdweb-dev/js/commit/352291791ee900e1500f84f095290497934d2f60) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose marketplace.auction.executeSale(listingId)
|
||||||
|
|
||||||
|
## 3.4.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#343](https://github.com/thirdweb-dev/js/pull/343) [`72227b2`](https://github.com/thirdweb-dev/js/commit/72227b2e166a3a68bbb41cf2b389322f5b7547a2) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose general marketplace.makeOffer() function
|
||||||
|
|
||||||
|
## 3.4.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#337](https://github.com/thirdweb-dev/js/pull/337) [`340605b`](https://github.com/thirdweb-dev/js/commit/340605b507f384fbd2999b9c16542af3c53e84a9) Thanks [@adam-maj](https://github.com/adam-maj)! - Clean native token address in listing
|
||||||
|
|
||||||
|
- [#342](https://github.com/thirdweb-dev/js/pull/342) [`26116a6`](https://github.com/thirdweb-dev/js/commit/26116a6f637ee845f7bd17f20ffe17caf184658e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Add new univeral RPC urls
|
||||||
|
|
||||||
|
- [#335](https://github.com/thirdweb-dev/js/pull/335) [`15f8006`](https://github.com/thirdweb-dev/js/commit/15f8006e1fb22333b7ee239b45e7b1b12d6dccc8) Thanks [@adam-maj](https://github.com/adam-maj)! - Export smart contract
|
||||||
|
|
||||||
|
- [#327](https://github.com/thirdweb-dev/js/pull/327) [`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5) Thanks [@jnsdls](https://github.com/jnsdls)! - enable e2e testing
|
||||||
|
|
||||||
|
- Updated dependencies [[`ef27aad`](https://github.com/thirdweb-dev/js/commit/ef27aad0aafc4577e85f44dc77dfbe880bd239b5)]:
|
||||||
|
- @thirdweb-dev/storage@1.0.6
|
||||||
|
|
||||||
## 3.3.1
|
## 3.3.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/sdk",
|
"name": "@thirdweb-dev/sdk",
|
||||||
"version": "3.3.1",
|
"version": "3.5.2",
|
||||||
"description": "The main thirdweb SDK.",
|
"description": "The main thirdweb SDK.",
|
||||||
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
@@ -65,8 +65,8 @@
|
|||||||
"push": "yalc push"
|
"push": "yalc push"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@metaplex-foundation/amman": "^0.10.0",
|
"@metaplex-foundation/amman": "0.10.0",
|
||||||
"@metaplex-foundation/amman-client": "^0.2.1",
|
"@metaplex-foundation/amman-client": "0.2.1",
|
||||||
"@microsoft/api-documenter": "^7.19.4",
|
"@microsoft/api-documenter": "^7.19.4",
|
||||||
"@microsoft/api-extractor": "^7.29.2",
|
"@microsoft/api-extractor": "^7.29.2",
|
||||||
"@microsoft/tsdoc": "^0.14.1",
|
"@microsoft/tsdoc": "^0.14.1",
|
||||||
@@ -99,16 +99,15 @@
|
|||||||
"ethers": "^5"
|
"ethers": "^5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@metaplex-foundation/js": "^0.15.0",
|
"@metaplex-foundation/js": "0.15.0",
|
||||||
"@metaplex-foundation/mpl-token-metadata": "^2.2.2",
|
"@metaplex-foundation/mpl-token-metadata": "2.2.2",
|
||||||
"@project-serum/anchor": "^0.25.0",
|
"@project-serum/anchor": "0.25.0",
|
||||||
"@solana/spl-token": "^0.2.0",
|
"@solana/spl-token": "0.2.0",
|
||||||
"@solana/web3.js": "^1.50.1",
|
"@solana/web3.js": "1.62.0",
|
||||||
"@thirdweb-dev/contracts-js": "*",
|
"@thirdweb-dev/contracts-js": "*",
|
||||||
"@thirdweb-dev/storage": "*",
|
"@thirdweb-dev/storage": "*",
|
||||||
"bn.js": "^5.2.1",
|
"bn.js": "^5.2.1",
|
||||||
"bs58": "^5.0.0",
|
"bs58": "^5.0.0",
|
||||||
"cbor-x": "^1.4.1",
|
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"eventemitter3": "^4.0.7",
|
"eventemitter3": "^4.0.7",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export const DEFAULT_API_KEY =
|
||||||
|
"c6634ad2d97b74baf15ff556016830c251050e6c36b9da508ce3ec80095d3dc1";
|
||||||
|
|
||||||
|
export function getRpcUrl(network: string) {
|
||||||
|
return `https://${network}.rpc.thirdweb.com/${DEFAULT_API_KEY}`;
|
||||||
|
}
|
||||||
@@ -2,8 +2,14 @@ import BN from "bn.js";
|
|||||||
import { BigNumber } from "ethers";
|
import { BigNumber } from "ethers";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
const isBrowser = () => typeof window !== "undefined";
|
/**
|
||||||
const FileOrBufferUnionSchema = isBrowser()
|
* @internal
|
||||||
|
*/
|
||||||
|
export const isBrowser = () => typeof window !== "undefined";
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export const FileOrBufferUnionSchema = isBrowser()
|
||||||
? (z.instanceof(File) as z.ZodType<InstanceType<typeof File>>)
|
? (z.instanceof(File) as z.ZodType<InstanceType<typeof File>>)
|
||||||
: (z.instanceof(Buffer) as z.ZodTypeAny); // @fixme, this is a hack to make browser happy for now
|
: (z.instanceof(Buffer) as z.ZodTypeAny); // @fixme, this is a hack to make browser happy for now
|
||||||
|
|
||||||
@@ -72,12 +78,12 @@ export const BigNumberTransformSchema = z
|
|||||||
|
|
||||||
export const BasisPointsSchema = z
|
export const BasisPointsSchema = z
|
||||||
.number()
|
.number()
|
||||||
.max(MAX_BPS, "Cannot exeed 100%")
|
.max(MAX_BPS, "Cannot exceed 100%")
|
||||||
.min(0, "Cannot be below 0%");
|
.min(0, "Cannot be below 0%");
|
||||||
|
|
||||||
export const PercentSchema = z
|
export const PercentSchema = z
|
||||||
.number()
|
.number()
|
||||||
.max(100, "Cannot exeed 100%")
|
.max(100, "Cannot exceed 100%")
|
||||||
.min(0, "Cannot be below 0%");
|
.min(0, "Cannot be below 0%");
|
||||||
|
|
||||||
export const HexColor = z.union([
|
export const HexColor = z.union([
|
||||||
@@ -96,6 +102,11 @@ export const AmountSchema = z
|
|||||||
])
|
])
|
||||||
.transform((arg) => (typeof arg === "number" ? arg.toString() : arg));
|
.transform((arg) => (typeof arg === "number" ? arg.toString() : arg));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export type Amount = z.input<typeof AmountSchema>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@@ -103,6 +114,8 @@ export const QuantitySchema = z
|
|||||||
.union([AmountSchema, z.literal("unlimited")])
|
.union([AmountSchema, z.literal("unlimited")])
|
||||||
.default("unlimited");
|
.default("unlimited");
|
||||||
|
|
||||||
|
export type Quantity = z.output<typeof QuantitySchema>;
|
||||||
|
|
||||||
export const RawDateSchema = z.date().transform((i) => {
|
export const RawDateSchema = z.date().transform((i) => {
|
||||||
return BigNumber.from(Math.floor(i.getTime() / 1000));
|
return BigNumber.from(Math.floor(i.getTime() / 1000));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import { Quantity } from "../../core/schema/shared";
|
||||||
import { NATIVE_TOKEN_ADDRESS } from "../constants";
|
import { NATIVE_TOKEN_ADDRESS } from "../constants";
|
||||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||||
import {
|
import {
|
||||||
|
AbstractClaimConditionContractStruct,
|
||||||
ClaimConditionInputArray,
|
ClaimConditionInputArray,
|
||||||
ClaimConditionInputSchema,
|
ClaimConditionInputSchema,
|
||||||
ClaimConditionOutputSchema,
|
ClaimConditionOutputSchema,
|
||||||
@@ -8,7 +10,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
SnapshotEntry,
|
SnapshotEntry,
|
||||||
SnapshotEntryWithProof,
|
SnapshotEntryWithProof,
|
||||||
SnapshotInputSchema,
|
|
||||||
SnapshotSchema,
|
SnapshotSchema,
|
||||||
} from "../schema/contracts/common/snapshots";
|
} from "../schema/contracts/common/snapshots";
|
||||||
import {
|
import {
|
||||||
@@ -25,9 +26,13 @@ import {
|
|||||||
isNativeToken,
|
isNativeToken,
|
||||||
normalizePriceValue,
|
normalizePriceValue,
|
||||||
} from "./currency";
|
} from "./currency";
|
||||||
import { ShardedMerkleTree } from "./sharded-merkle-tree";
|
import {
|
||||||
|
ShardedMerkleTree,
|
||||||
|
SnapshotFormatVersion,
|
||||||
|
} from "./sharded-merkle-tree";
|
||||||
import { createSnapshot } from "./snapshots";
|
import { createSnapshot } from "./snapshots";
|
||||||
import { IDropClaimCondition } from "@thirdweb-dev/contracts-js/dist/declarations/src/DropERC20";
|
import { IDropClaimCondition_V2 } from "@thirdweb-dev/contracts-js/dist/declarations/src/IDropERC20_V2";
|
||||||
|
import { IClaimCondition } from "@thirdweb-dev/contracts-js/src/IDrop";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import {
|
import {
|
||||||
BigNumber,
|
BigNumber,
|
||||||
@@ -52,27 +57,58 @@ export async function prepareClaim(
|
|||||||
contractWrapper: ContractWrapper<any>,
|
contractWrapper: ContractWrapper<any>,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
checkERC20Allowance: boolean,
|
checkERC20Allowance: boolean,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
): Promise<ClaimVerification> {
|
): Promise<ClaimVerification> {
|
||||||
const addressToClaim = await contractWrapper.getSignerAddress();
|
const addressToClaim = await contractWrapper.getSignerAddress();
|
||||||
let maxClaimable = BigNumber.from(0);
|
let maxClaimable = convertQuantityToBigNumber(
|
||||||
|
activeClaimCondition.maxClaimablePerWallet,
|
||||||
|
tokenDecimals,
|
||||||
|
);
|
||||||
let proofs = [utils.hexZeroPad([0], 32)];
|
let proofs = [utils.hexZeroPad([0], 32)];
|
||||||
|
let priceInProof = activeClaimCondition.price; // the price to send to the contract in claim proofs
|
||||||
|
let currencyAddressInProof = activeClaimCondition.currencyAddress;
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
!activeClaimCondition.merkleRootHash
|
!activeClaimCondition.merkleRootHash
|
||||||
.toString()
|
.toString()
|
||||||
.startsWith(constants.AddressZero)
|
.startsWith(constants.AddressZero)
|
||||||
) {
|
) {
|
||||||
const claim = await fetchSnapshotEntryForAddress(
|
const snapshotEntry = await fetchSnapshotEntryForAddress(
|
||||||
addressToClaim,
|
addressToClaim,
|
||||||
activeClaimCondition.merkleRootHash.toString(),
|
activeClaimCondition.merkleRootHash.toString(),
|
||||||
await merkleMetadataFetcher(),
|
await merkleMetadataFetcher(),
|
||||||
|
contractWrapper.getProvider(),
|
||||||
storage,
|
storage,
|
||||||
|
snapshotFormatVersion,
|
||||||
);
|
);
|
||||||
if (!claim) {
|
if (snapshotEntry) {
|
||||||
throw new Error("No claim found for this address");
|
proofs = snapshotEntry.proof;
|
||||||
|
// override only if not default values (unlimited for quantity, zero addr for currency)
|
||||||
|
maxClaimable =
|
||||||
|
snapshotEntry.maxClaimable === "unlimited"
|
||||||
|
? ethers.constants.MaxUint256
|
||||||
|
: ethers.utils.parseUnits(
|
||||||
|
snapshotEntry.maxClaimable,
|
||||||
|
tokenDecimals,
|
||||||
|
);
|
||||||
|
priceInProof =
|
||||||
|
snapshotEntry.price === undefined ||
|
||||||
|
snapshotEntry.price === "unlimited"
|
||||||
|
? ethers.constants.MaxUint256
|
||||||
|
: await normalizePriceValue(
|
||||||
|
contractWrapper.getProvider(),
|
||||||
|
snapshotEntry.price,
|
||||||
|
snapshotEntry.currencyAddress || ethers.constants.AddressZero,
|
||||||
|
);
|
||||||
|
currencyAddressInProof =
|
||||||
|
snapshotEntry.currencyAddress || ethers.constants.AddressZero;
|
||||||
|
} else {
|
||||||
|
// if no snapshot entry, and it's a v1 format (exclusive allowlist) then address can't claim
|
||||||
|
if (snapshotFormatVersion === SnapshotFormatVersion.V1) {
|
||||||
|
throw new Error("No claim found for this address");
|
||||||
|
}
|
||||||
|
// but if its snapshot v2 (override list behavior) then address can still claim with default settings
|
||||||
}
|
}
|
||||||
proofs = claim.proof;
|
|
||||||
maxClaimable = ethers.utils.parseUnits(claim.maxClaimable, tokenDecimals);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// have to handle the valid error case that we *do* want to throw on
|
// have to handle the valid error case that we *do* want to throw on
|
||||||
@@ -87,18 +123,28 @@ export async function prepareClaim(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const overrides = (await contractWrapper.getCallOverrides()) || {};
|
const overrides = (await contractWrapper.getCallOverrides()) || {};
|
||||||
const price = activeClaimCondition.price;
|
// the actual price to check allowance against
|
||||||
const currencyAddress = activeClaimCondition.currencyAddress;
|
// if proof price is unlimited, then we use the price from the claim condition
|
||||||
if (price.gt(0)) {
|
// this mimics the contract behavior
|
||||||
|
const pricePerToken =
|
||||||
|
priceInProof.toString() !== ethers.constants.MaxUint256.toString()
|
||||||
|
? priceInProof
|
||||||
|
: activeClaimCondition.price;
|
||||||
|
// same for currency address
|
||||||
|
const currencyAddress =
|
||||||
|
currencyAddressInProof !== ethers.constants.AddressZero
|
||||||
|
? currencyAddressInProof
|
||||||
|
: activeClaimCondition.currencyAddress;
|
||||||
|
if (pricePerToken.gt(0)) {
|
||||||
if (isNativeToken(currencyAddress)) {
|
if (isNativeToken(currencyAddress)) {
|
||||||
overrides["value"] = BigNumber.from(price)
|
overrides["value"] = BigNumber.from(pricePerToken)
|
||||||
.mul(quantity)
|
.mul(quantity)
|
||||||
.div(ethers.utils.parseUnits("1", tokenDecimals));
|
.div(ethers.utils.parseUnits("1", tokenDecimals));
|
||||||
} else if (checkERC20Allowance) {
|
} else if (checkERC20Allowance) {
|
||||||
await approveErc20Allowance(
|
await approveErc20Allowance(
|
||||||
contractWrapper,
|
contractWrapper,
|
||||||
currencyAddress,
|
currencyAddress,
|
||||||
price,
|
pricePerToken,
|
||||||
quantity,
|
quantity,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
);
|
);
|
||||||
@@ -107,9 +153,9 @@ export async function prepareClaim(
|
|||||||
return {
|
return {
|
||||||
overrides,
|
overrides,
|
||||||
proofs,
|
proofs,
|
||||||
maxQuantityPerTransaction: maxClaimable,
|
maxClaimable,
|
||||||
price,
|
price: priceInProof,
|
||||||
currencyAddress,
|
currencyAddress: currencyAddressInProof,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +185,8 @@ export async function fetchSnapshot(
|
|||||||
return snapshotData.claims.map((claim) => ({
|
return snapshotData.claims.map((claim) => ({
|
||||||
address: claim.address,
|
address: claim.address,
|
||||||
maxClaimable: claim.maxClaimable,
|
maxClaimable: claim.maxClaimable,
|
||||||
|
price: claim.price,
|
||||||
|
currencyAddress: claim.currencyAddress,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +198,9 @@ export async function fetchSnapshotEntryForAddress(
|
|||||||
address: string,
|
address: string,
|
||||||
merkleRoot: string,
|
merkleRoot: string,
|
||||||
merkleMetadata: Record<string, string> | undefined,
|
merkleMetadata: Record<string, string> | undefined,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
): Promise<SnapshotEntryWithProof | null> {
|
): Promise<SnapshotEntryWithProof | null> {
|
||||||
if (!merkleMetadata) {
|
if (!merkleMetadata) {
|
||||||
return null;
|
return null;
|
||||||
@@ -163,7 +213,11 @@ export async function fetchSnapshotEntryForAddress(
|
|||||||
raw,
|
raw,
|
||||||
storage,
|
storage,
|
||||||
);
|
);
|
||||||
return await merkleTree.getProof(address);
|
return await merkleTree.getProof(
|
||||||
|
address,
|
||||||
|
provider,
|
||||||
|
snapshotFormatVersion,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// legacy non-sharded, just fetch it all and filter out
|
// legacy non-sharded, just fetch it all and filter out
|
||||||
const snapshotData = SnapshotSchema.parse(raw);
|
const snapshotData = SnapshotSchema.parse(raw);
|
||||||
@@ -238,6 +292,8 @@ export async function updateExistingClaimConditions(
|
|||||||
* @param tokenDecimals
|
* @param tokenDecimals
|
||||||
* @param merkleMetadata
|
* @param merkleMetadata
|
||||||
* @param storage
|
* @param storage
|
||||||
|
* @param provider
|
||||||
|
* @param snapshotFormatVersion
|
||||||
* @returns - The proof for the current signer for the specified condition.
|
* @returns - The proof for the current signer for the specified condition.
|
||||||
*/
|
*/
|
||||||
export async function getClaimerProofs(
|
export async function getClaimerProofs(
|
||||||
@@ -246,38 +302,63 @@ export async function getClaimerProofs(
|
|||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
merkleMetadata: Record<string, string>,
|
merkleMetadata: Record<string, string>,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
): Promise<{ maxClaimable: BigNumber; proof: string[] }> {
|
provider: ethers.providers.Provider,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
|
): Promise<
|
||||||
|
| {
|
||||||
|
proof: string[];
|
||||||
|
maxClaimable: BigNumber;
|
||||||
|
price: BigNumber;
|
||||||
|
currencyAddress: string;
|
||||||
|
}
|
||||||
|
| undefined
|
||||||
|
> {
|
||||||
const claim = await fetchSnapshotEntryForAddress(
|
const claim = await fetchSnapshotEntryForAddress(
|
||||||
addressToClaim,
|
addressToClaim,
|
||||||
merkleRoot,
|
merkleRoot,
|
||||||
merkleMetadata,
|
merkleMetadata,
|
||||||
|
provider,
|
||||||
storage,
|
storage,
|
||||||
|
snapshotFormatVersion,
|
||||||
);
|
);
|
||||||
if (!claim) {
|
if (!claim) {
|
||||||
return {
|
return undefined;
|
||||||
proof: [],
|
|
||||||
maxClaimable: BigNumber.from(0),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
const price =
|
||||||
|
claim.price === "unlimited" || claim.price === undefined
|
||||||
|
? ethers.constants.MaxUint256
|
||||||
|
: await normalizePriceValue(
|
||||||
|
provider,
|
||||||
|
claim.price,
|
||||||
|
claim.currencyAddress || ethers.constants.AddressZero,
|
||||||
|
);
|
||||||
|
const maxClaimable =
|
||||||
|
claim.maxClaimable === "unlimited"
|
||||||
|
? ethers.constants.MaxUint256
|
||||||
|
: ethers.utils.parseUnits(claim.maxClaimable, tokenDecimals);
|
||||||
return {
|
return {
|
||||||
proof: claim.proof,
|
proof: claim.proof,
|
||||||
maxClaimable: ethers.utils.parseUnits(claim.maxClaimable, tokenDecimals),
|
maxClaimable,
|
||||||
|
price,
|
||||||
|
currencyAddress: claim.currencyAddress || ethers.constants.AddressZero,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and uploads snapshots + converts claim conditions to contract format
|
* @internal
|
||||||
|
* Decorates claim conditions with merkle roots from snapshots if present
|
||||||
* @param claimConditionInputs
|
* @param claimConditionInputs
|
||||||
* @param tokenDecimals
|
* @param tokenDecimals
|
||||||
* @param provider
|
* @param provider
|
||||||
* @param storage
|
* @param storage
|
||||||
* @internal
|
* @param snapshotFormatVersion
|
||||||
*/
|
*/
|
||||||
export async function processClaimConditionInputs(
|
async function processSnapshotData(
|
||||||
claimConditionInputs: ClaimConditionInput[],
|
claimConditionInputs: ClaimConditionInput[],
|
||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
provider: providers.Provider,
|
provider: ethers.providers.Provider,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
) {
|
) {
|
||||||
const snapshotInfos: SnapshotInfo[] = [];
|
const snapshotInfos: SnapshotInfo[] = [];
|
||||||
const inputsWithSnapshots = await Promise.all(
|
const inputsWithSnapshots = await Promise.all(
|
||||||
@@ -285,9 +366,11 @@ export async function processClaimConditionInputs(
|
|||||||
// check snapshots and upload if provided
|
// check snapshots and upload if provided
|
||||||
if (conditionInput.snapshot && conditionInput.snapshot.length > 0) {
|
if (conditionInput.snapshot && conditionInput.snapshot.length > 0) {
|
||||||
const snapshotInfo = await createSnapshot(
|
const snapshotInfo = await createSnapshot(
|
||||||
SnapshotInputSchema.parse(conditionInput.snapshot),
|
conditionInput.snapshot,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
|
provider,
|
||||||
storage,
|
storage,
|
||||||
|
snapshotFormatVersion,
|
||||||
);
|
);
|
||||||
snapshotInfos.push(snapshotInfo);
|
snapshotInfos.push(snapshotInfo);
|
||||||
conditionInput.merkleRootHash = snapshotInfo.merkleRoot;
|
conditionInput.merkleRootHash = snapshotInfo.merkleRoot;
|
||||||
@@ -299,26 +382,54 @@ export async function processClaimConditionInputs(
|
|||||||
return conditionInput;
|
return conditionInput;
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
return { inputsWithSnapshots, snapshotInfos };
|
||||||
|
}
|
||||||
|
|
||||||
|
function compare(a: BigNumberish, b: BigNumberish) {
|
||||||
|
const left = BigNumber.from(a);
|
||||||
|
const right = BigNumber.from(b);
|
||||||
|
if (left.eq(right)) {
|
||||||
|
return 0;
|
||||||
|
} else if (left.gt(right)) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and uploads snapshots + converts claim conditions to contract format
|
||||||
|
* @param claimConditionInputs
|
||||||
|
* @param tokenDecimals
|
||||||
|
* @param provider
|
||||||
|
* @param storage
|
||||||
|
* @param snapshotFormatVersion
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function processClaimConditionInputs(
|
||||||
|
claimConditionInputs: ClaimConditionInput[],
|
||||||
|
tokenDecimals: number,
|
||||||
|
provider: providers.Provider,
|
||||||
|
storage: ThirdwebStorage,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
|
) {
|
||||||
|
const { inputsWithSnapshots, snapshotInfos } = await processSnapshotData(
|
||||||
|
claimConditionInputs,
|
||||||
|
tokenDecimals,
|
||||||
|
provider,
|
||||||
|
storage,
|
||||||
|
snapshotFormatVersion,
|
||||||
|
);
|
||||||
const parsedInputs = ClaimConditionInputArray.parse(inputsWithSnapshots);
|
const parsedInputs = ClaimConditionInputArray.parse(inputsWithSnapshots);
|
||||||
|
|
||||||
// Convert processed inputs to the format the contract expects, and sort by timestamp
|
// Convert processed inputs to the format the contract expects, and sort by timestamp
|
||||||
const sortedConditions: IDropClaimCondition.ClaimConditionStruct[] = (
|
const sortedConditions: AbstractClaimConditionContractStruct[] = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
parsedInputs.map((c) =>
|
parsedInputs.map((c) =>
|
||||||
convertToContractModel(c, tokenDecimals, provider),
|
convertToContractModel(c, tokenDecimals, provider, storage),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
).sort((a, b) => {
|
).sort((a, b) => {
|
||||||
const left = BigNumber.from(a.startTimestamp);
|
return compare(a.startTimestamp, b.startTimestamp);
|
||||||
const right = BigNumber.from(b.startTimestamp);
|
|
||||||
if (left.eq(right)) {
|
|
||||||
return 0;
|
|
||||||
} else if (left.gt(right)) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return { snapshotInfos, sortedConditions };
|
return { snapshotInfos, sortedConditions };
|
||||||
}
|
}
|
||||||
@@ -328,41 +439,106 @@ export async function processClaimConditionInputs(
|
|||||||
* @param c
|
* @param c
|
||||||
* @param tokenDecimals
|
* @param tokenDecimals
|
||||||
* @param provider
|
* @param provider
|
||||||
|
* @param storage
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
async function convertToContractModel(
|
async function convertToContractModel(
|
||||||
c: FilledConditionInput,
|
c: FilledConditionInput,
|
||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
provider: providers.Provider,
|
provider: providers.Provider,
|
||||||
): Promise<IDropClaimCondition.ClaimConditionStruct> {
|
storage: ThirdwebStorage,
|
||||||
|
): Promise<AbstractClaimConditionContractStruct> {
|
||||||
const currency =
|
const currency =
|
||||||
c.currencyAddress === constants.AddressZero
|
c.currencyAddress === constants.AddressZero
|
||||||
? NATIVE_TOKEN_ADDRESS
|
? NATIVE_TOKEN_ADDRESS
|
||||||
: c.currencyAddress;
|
: c.currencyAddress;
|
||||||
let maxClaimableSupply;
|
const maxClaimableSupply = convertQuantityToBigNumber(
|
||||||
let quantityLimitPerTransaction;
|
c.maxClaimableSupply,
|
||||||
if (c.maxQuantity === "unlimited") {
|
tokenDecimals,
|
||||||
maxClaimableSupply = ethers.constants.MaxUint256.toString();
|
);
|
||||||
} else {
|
const maxClaimablePerWallet = convertQuantityToBigNumber(
|
||||||
maxClaimableSupply = ethers.utils.parseUnits(c.maxQuantity, tokenDecimals);
|
c.maxClaimablePerWallet,
|
||||||
}
|
tokenDecimals,
|
||||||
if (c.quantityLimitPerTransaction === "unlimited") {
|
);
|
||||||
quantityLimitPerTransaction = ethers.constants.MaxUint256.toString();
|
let metadataOrUri;
|
||||||
} else {
|
if (c.metadata) {
|
||||||
quantityLimitPerTransaction = ethers.utils.parseUnits(
|
if (typeof c.metadata === "string") {
|
||||||
c.quantityLimitPerTransaction,
|
metadataOrUri = c.metadata;
|
||||||
tokenDecimals,
|
} else {
|
||||||
);
|
metadataOrUri = await storage.upload(c.metadata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
startTimestamp: c.startTime,
|
startTimestamp: c.startTime,
|
||||||
maxClaimableSupply,
|
maxClaimableSupply,
|
||||||
supplyClaimed: 0,
|
supplyClaimed: 0,
|
||||||
quantityLimitPerTransaction,
|
maxClaimablePerWallet,
|
||||||
waitTimeInSecondsBetweenClaims: c.waitInSeconds,
|
|
||||||
pricePerToken: await normalizePriceValue(provider, c.price, currency),
|
pricePerToken: await normalizePriceValue(provider, c.price, currency),
|
||||||
currency,
|
currency,
|
||||||
merkleRoot: c.merkleRootHash,
|
merkleRoot: c.merkleRootHash.toString(),
|
||||||
|
waitTimeInSecondsBetweenClaims: c.waitInSeconds || 0,
|
||||||
|
metadata: metadataOrUri,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function abstractContractModelToLegacy(
|
||||||
|
model: AbstractClaimConditionContractStruct,
|
||||||
|
): IDropClaimCondition_V2.ClaimConditionStruct {
|
||||||
|
return {
|
||||||
|
startTimestamp: model.startTimestamp,
|
||||||
|
maxClaimableSupply: model.maxClaimableSupply,
|
||||||
|
supplyClaimed: model.supplyClaimed,
|
||||||
|
merkleRoot: model.merkleRoot,
|
||||||
|
pricePerToken: model.pricePerToken,
|
||||||
|
currency: model.currency,
|
||||||
|
quantityLimitPerTransaction: model.maxClaimablePerWallet,
|
||||||
|
waitTimeInSecondsBetweenClaims: model.waitTimeInSecondsBetweenClaims || 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function abstractContractModelToNew(
|
||||||
|
model: AbstractClaimConditionContractStruct,
|
||||||
|
): IClaimCondition.ClaimConditionStruct {
|
||||||
|
return {
|
||||||
|
startTimestamp: model.startTimestamp,
|
||||||
|
maxClaimableSupply: model.maxClaimableSupply,
|
||||||
|
supplyClaimed: model.supplyClaimed,
|
||||||
|
merkleRoot: model.merkleRoot,
|
||||||
|
pricePerToken: model.pricePerToken,
|
||||||
|
currency: model.currency,
|
||||||
|
quantityLimitPerWallet: model.maxClaimablePerWallet,
|
||||||
|
metadata: model.metadata || "",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function legacyContractModelToAbstract(
|
||||||
|
model: IDropClaimCondition_V2.ClaimConditionStruct,
|
||||||
|
): AbstractClaimConditionContractStruct {
|
||||||
|
return {
|
||||||
|
startTimestamp: model.startTimestamp,
|
||||||
|
maxClaimableSupply: model.maxClaimableSupply,
|
||||||
|
supplyClaimed: model.supplyClaimed,
|
||||||
|
merkleRoot: model.merkleRoot.toString(),
|
||||||
|
pricePerToken: model.pricePerToken,
|
||||||
|
currency: model.currency,
|
||||||
|
maxClaimablePerWallet: model.quantityLimitPerTransaction,
|
||||||
|
waitTimeInSecondsBetweenClaims: model.waitTimeInSecondsBetweenClaims,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function newContractModelToAbstract(
|
||||||
|
model: IClaimCondition.ClaimConditionStruct,
|
||||||
|
): AbstractClaimConditionContractStruct {
|
||||||
|
return {
|
||||||
|
startTimestamp: model.startTimestamp,
|
||||||
|
maxClaimableSupply: model.maxClaimableSupply,
|
||||||
|
supplyClaimed: model.supplyClaimed,
|
||||||
|
merkleRoot: model.merkleRoot.toString(),
|
||||||
|
pricePerToken: model.pricePerToken,
|
||||||
|
currency: model.currency,
|
||||||
|
maxClaimablePerWallet: model.quantityLimitPerWallet,
|
||||||
|
waitTimeInSecondsBetweenClaims: 0,
|
||||||
|
metadata: model.metadata,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,10 +549,11 @@ async function convertToContractModel(
|
|||||||
* @param provider
|
* @param provider
|
||||||
* @param merkleMetadata
|
* @param merkleMetadata
|
||||||
* @param storage
|
* @param storage
|
||||||
|
* @param shouldDownloadSnapshot
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function transformResultToClaimCondition(
|
export async function transformResultToClaimCondition(
|
||||||
pm: IDropClaimCondition.ClaimConditionStructOutput,
|
pm: AbstractClaimConditionContractStruct,
|
||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
provider: providers.Provider,
|
provider: providers.Provider,
|
||||||
merkleMetadata: Record<string, string> | undefined,
|
merkleMetadata: Record<string, string> | undefined,
|
||||||
@@ -389,8 +566,8 @@ export async function transformResultToClaimCondition(
|
|||||||
pm.maxClaimableSupply,
|
pm.maxClaimableSupply,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
);
|
);
|
||||||
const quantityLimitPerTransaction = convertToReadableQuantity(
|
const maxClaimablePerWallet = convertToReadableQuantity(
|
||||||
pm.quantityLimitPerTransaction,
|
pm.maxClaimablePerWallet,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
);
|
);
|
||||||
const availableSupply = convertToReadableQuantity(
|
const availableSupply = convertToReadableQuantity(
|
||||||
@@ -403,11 +580,11 @@ export async function transformResultToClaimCondition(
|
|||||||
);
|
);
|
||||||
return ClaimConditionOutputSchema.parse({
|
return ClaimConditionOutputSchema.parse({
|
||||||
startTime: pm.startTimestamp,
|
startTime: pm.startTimestamp,
|
||||||
maxQuantity: maxClaimableSupply,
|
maxClaimableSupply,
|
||||||
|
maxClaimablePerWallet,
|
||||||
currentMintSupply,
|
currentMintSupply,
|
||||||
availableSupply,
|
availableSupply,
|
||||||
quantityLimitPerTransaction,
|
waitInSeconds: pm.waitTimeInSecondsBetweenClaims?.toString(),
|
||||||
waitInSeconds: pm.waitTimeInSecondsBetweenClaims.toString(),
|
|
||||||
price: BigNumber.from(pm.pricePerToken),
|
price: BigNumber.from(pm.pricePerToken),
|
||||||
currency: pm.currency,
|
currency: pm.currency,
|
||||||
currencyAddress: pm.currency,
|
currencyAddress: pm.currency,
|
||||||
@@ -416,10 +593,19 @@ export async function transformResultToClaimCondition(
|
|||||||
snapshot: shouldDownloadSnapshot
|
snapshot: shouldDownloadSnapshot
|
||||||
? await fetchSnapshot(pm.merkleRoot, merkleMetadata, storage)
|
? await fetchSnapshot(pm.merkleRoot, merkleMetadata, storage)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
metadata: pm.metadata,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToReadableQuantity(bn: BigNumber, tokenDecimals: number) {
|
/**
|
||||||
|
* @internal
|
||||||
|
* @param bn
|
||||||
|
* @param tokenDecimals
|
||||||
|
*/
|
||||||
|
export function convertToReadableQuantity(
|
||||||
|
bn: BigNumberish,
|
||||||
|
tokenDecimals: number,
|
||||||
|
) {
|
||||||
if (bn.toString() === ethers.constants.MaxUint256.toString()) {
|
if (bn.toString() === ethers.constants.MaxUint256.toString()) {
|
||||||
return "unlimited";
|
return "unlimited";
|
||||||
} else {
|
} else {
|
||||||
@@ -427,6 +613,22 @@ function convertToReadableQuantity(bn: BigNumber, tokenDecimals: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @param quantity
|
||||||
|
* @param tokenDecimals
|
||||||
|
*/
|
||||||
|
export function convertQuantityToBigNumber(
|
||||||
|
quantity: Quantity,
|
||||||
|
tokenDecimals: number,
|
||||||
|
) {
|
||||||
|
if (quantity === "unlimited") {
|
||||||
|
return ethers.constants.MaxUint256;
|
||||||
|
} else {
|
||||||
|
return ethers.utils.parseUnits(quantity, tokenDecimals);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function calculateClaimCost(
|
export async function calculateClaimCost(
|
||||||
contractWrapper: ContractWrapper<any>,
|
contractWrapper: ContractWrapper<any>,
|
||||||
pricePerToken: Price,
|
pricePerToken: Price,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import { AmountSchema } from "../../core/schema/shared";
|
||||||
import {
|
import {
|
||||||
getNativeTokenByChainId,
|
getNativeTokenByChainId,
|
||||||
NATIVE_TOKEN_ADDRESS,
|
NATIVE_TOKEN_ADDRESS,
|
||||||
} from "../constants/currency";
|
} from "../constants/currency";
|
||||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||||
import { AmountSchema } from "../schema/shared";
|
|
||||||
import { Amount, Currency, CurrencyValue, Price } from "../types/currency";
|
import { Amount, Currency, CurrencyValue, Price } from "../types/currency";
|
||||||
import { BaseERC20 } from "../types/eips";
|
import { BaseERC20 } from "../types/eips";
|
||||||
import type { IERC20, IERC20Metadata } from "@thirdweb-dev/contracts-js";
|
import type { IERC20, IERC20Metadata } from "@thirdweb-dev/contracts-js";
|
||||||
@@ -26,6 +26,13 @@ export function isNativeToken(tokenAddress: string): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cleanCurrencyAddress(currencyAddress: string): string {
|
||||||
|
if (isNativeToken(currencyAddress)) {
|
||||||
|
return NATIVE_TOKEN_ADDRESS;
|
||||||
|
}
|
||||||
|
return currencyAddress;
|
||||||
|
}
|
||||||
|
|
||||||
export async function normalizePriceValue(
|
export async function normalizePriceValue(
|
||||||
provider: providers.Provider,
|
provider: providers.Provider,
|
||||||
inputPrice: Price,
|
inputPrice: Price,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from "../constants/contract-features";
|
} from "../constants/contract-features";
|
||||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||||
import { DetectableFeature } from "../core/interfaces/DetectableFeature";
|
import { DetectableFeature } from "../core/interfaces/DetectableFeature";
|
||||||
|
import { decode } from "../lib/cbor-decode.js";
|
||||||
import {
|
import {
|
||||||
AbiEvent,
|
AbiEvent,
|
||||||
AbiFunction,
|
AbiFunction,
|
||||||
@@ -23,7 +24,6 @@ import {
|
|||||||
import { ExtensionNotImplementedError } from "./error";
|
import { ExtensionNotImplementedError } from "./error";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import bs58 from "bs58";
|
import bs58 from "bs58";
|
||||||
import { decode } from "cbor-x";
|
|
||||||
import { BaseContract, BigNumber, ethers } from "ethers";
|
import { BaseContract, BigNumber, ethers } from "ethers";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import IThirdwebContractABI from "@thirdweb-dev/contracts-js/dist/abis/IThirdwebContract.json";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
|
||||||
|
export async function getPrebuiltInfo(
|
||||||
|
address: string,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
|
): Promise<{ type: string; version: number } | undefined> {
|
||||||
|
try {
|
||||||
|
const contract = new ethers.Contract(
|
||||||
|
address,
|
||||||
|
IThirdwebContractABI,
|
||||||
|
provider,
|
||||||
|
);
|
||||||
|
const [type, version] = await Promise.all([
|
||||||
|
ethers.utils
|
||||||
|
.toUtf8String(await contract.contractType()) // eslint-disable-next-line no-control-regex
|
||||||
|
.replace(/\x00/g, ""),
|
||||||
|
await contract.contractVersion(),
|
||||||
|
]);
|
||||||
|
return {
|
||||||
|
type,
|
||||||
|
version,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
|
import { MAX_BPS } from "../../core/schema/shared";
|
||||||
import {
|
import {
|
||||||
InterfaceId_IERC1155,
|
InterfaceId_IERC1155,
|
||||||
InterfaceId_IERC721,
|
InterfaceId_IERC721,
|
||||||
} from "../constants/contract";
|
} from "../constants/contract";
|
||||||
import { SignerOrProvider } from "../core";
|
import { SignerOrProvider } from "../core";
|
||||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||||
import { MAX_BPS } from "../schema/shared";
|
|
||||||
import {
|
import {
|
||||||
NewAuctionListing,
|
NewAuctionListing,
|
||||||
NewDirectListing,
|
NewDirectListing,
|
||||||
|
|||||||
@@ -67,9 +67,9 @@ export async function fetchTokenMetadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return CommonNFTOutput.parse({
|
return CommonNFTOutput.parse({
|
||||||
|
...jsonMetadata,
|
||||||
id: BigNumber.from(tokenId).toString(),
|
id: BigNumber.from(tokenId).toString(),
|
||||||
uri: tokenUri,
|
uri: tokenUri,
|
||||||
...jsonMetadata,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ import {
|
|||||||
ShardedSnapshot,
|
ShardedSnapshot,
|
||||||
SnapshotEntry,
|
SnapshotEntry,
|
||||||
SnapshotEntryWithProof,
|
SnapshotEntryWithProof,
|
||||||
|
SnapshotEntryWithProofSchema,
|
||||||
SnapshotInputSchema,
|
SnapshotInputSchema,
|
||||||
} from "../schema";
|
} from "../schema/contracts/common/snapshots";
|
||||||
import { SnapshotInput } from "../types";
|
import { SnapshotInput } from "../types";
|
||||||
import { hashLeafNode } from "./snapshots";
|
import { convertQuantityToBigNumber } from "./claim-conditions";
|
||||||
|
import { fetchCurrencyMetadata } from "./currency";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { utils } from "ethers";
|
import { ethers, utils } from "ethers";
|
||||||
import { MerkleTree } from "merkletreejs";
|
import { MerkleTree } from "merkletreejs";
|
||||||
|
|
||||||
// shard using the first 2 hex character of the address
|
// shard using the first 2 hex character of the address
|
||||||
@@ -17,6 +19,11 @@ import { MerkleTree } from "merkletreejs";
|
|||||||
// shard files will be 00.json, 01.json, 02.json, ..., ff.json
|
// shard files will be 00.json, 01.json, 02.json, ..., ff.json
|
||||||
const SHARD_NYBBLES = 2;
|
const SHARD_NYBBLES = 2;
|
||||||
|
|
||||||
|
export enum SnapshotFormatVersion {
|
||||||
|
V1 = 1, // address and maxClaimable
|
||||||
|
V2 = 2, // address, maxClaimable, price, currencyAddress
|
||||||
|
}
|
||||||
|
|
||||||
export class ShardedMerkleTree {
|
export class ShardedMerkleTree {
|
||||||
private shardNybbles: number;
|
private shardNybbles: number;
|
||||||
private shards: Record<string, ShardData>;
|
private shards: Record<string, ShardData>;
|
||||||
@@ -73,17 +80,64 @@ export class ShardedMerkleTree {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static hashEntry(entry: SnapshotEntry, tokenDecimals: number): string {
|
static hashEntry(
|
||||||
return hashLeafNode(
|
entry: SnapshotEntry,
|
||||||
entry.address,
|
tokenDecimals: number,
|
||||||
utils.parseUnits(entry.maxClaimable, tokenDecimals),
|
currencyDecimals: number,
|
||||||
);
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
|
): string {
|
||||||
|
switch (snapshotFormatVersion) {
|
||||||
|
case SnapshotFormatVersion.V1:
|
||||||
|
return utils.solidityKeccak256(
|
||||||
|
["address", "uint256"],
|
||||||
|
[
|
||||||
|
entry.address,
|
||||||
|
convertQuantityToBigNumber(entry.maxClaimable, tokenDecimals),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
case SnapshotFormatVersion.V2:
|
||||||
|
return utils.solidityKeccak256(
|
||||||
|
["address", "uint256", "uint256", "address"],
|
||||||
|
[
|
||||||
|
entry.address,
|
||||||
|
convertQuantityToBigNumber(entry.maxClaimable, tokenDecimals),
|
||||||
|
convertQuantityToBigNumber(
|
||||||
|
entry.price || "unlimited",
|
||||||
|
currencyDecimals,
|
||||||
|
),
|
||||||
|
entry.currencyAddress || ethers.constants.AddressZero,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static async fetchAndCacheDecimals(
|
||||||
|
cache: Record<string, number>,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
|
currencyAddress?: string,
|
||||||
|
): Promise<number> {
|
||||||
|
if (!currencyAddress) {
|
||||||
|
return 18;
|
||||||
|
}
|
||||||
|
// cache decimals for each currency to avoid refetching for every address
|
||||||
|
let currencyDecimals = cache[currencyAddress];
|
||||||
|
if (currencyDecimals === undefined) {
|
||||||
|
const currencyMetadata = await fetchCurrencyMetadata(
|
||||||
|
provider,
|
||||||
|
currencyAddress,
|
||||||
|
);
|
||||||
|
currencyDecimals = currencyMetadata.decimals;
|
||||||
|
cache[currencyAddress] = currencyDecimals;
|
||||||
|
}
|
||||||
|
return currencyDecimals;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async buildAndUpload(
|
static async buildAndUpload(
|
||||||
snapshotInput: SnapshotInput,
|
snapshotInput: SnapshotInput,
|
||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
shardNybbles = SHARD_NYBBLES,
|
shardNybbles = SHARD_NYBBLES,
|
||||||
): Promise<ShardedSnapshot> {
|
): Promise<ShardedSnapshot> {
|
||||||
const inputs = SnapshotInputSchema.parse(snapshotInput);
|
const inputs = SnapshotInputSchema.parse(snapshotInput);
|
||||||
@@ -98,13 +152,28 @@ export class ShardedMerkleTree {
|
|||||||
}
|
}
|
||||||
shards[shard].push(snapshotEntry);
|
shards[shard].push(snapshotEntry);
|
||||||
}
|
}
|
||||||
|
const currencyDecimalMap: Record<string, number> = {};
|
||||||
// create shard => subtree root map
|
// create shard => subtree root map
|
||||||
const roots = Object.fromEntries(
|
const subTrees = await Promise.all(
|
||||||
Object.entries(shards).map(([shard, entries]) => [
|
Object.entries(shards).map(async ([shard, entries]) => [
|
||||||
shard,
|
shard,
|
||||||
new MerkleTree(
|
new MerkleTree(
|
||||||
entries.map((entry) =>
|
await Promise.all(
|
||||||
ShardedMerkleTree.hashEntry(entry, tokenDecimals),
|
entries.map(async (entry) => {
|
||||||
|
// cache decimals for each currency to avoid refetching for every address
|
||||||
|
const currencyDecimals =
|
||||||
|
await ShardedMerkleTree.fetchAndCacheDecimals(
|
||||||
|
currencyDecimalMap,
|
||||||
|
provider,
|
||||||
|
entry.currencyAddress,
|
||||||
|
);
|
||||||
|
return ShardedMerkleTree.hashEntry(
|
||||||
|
entry,
|
||||||
|
tokenDecimals,
|
||||||
|
currencyDecimals,
|
||||||
|
snapshotFormatVersion,
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
utils.keccak256,
|
utils.keccak256,
|
||||||
{
|
{
|
||||||
@@ -113,6 +182,7 @@ export class ShardedMerkleTree {
|
|||||||
).getHexRoot(),
|
).getHexRoot(),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
const roots = Object.fromEntries(subTrees);
|
||||||
// create master tree from shard => subtree root map
|
// create master tree from shard => subtree root map
|
||||||
const tree = new MerkleTree(Object.values(roots), utils.keccak256, {
|
const tree = new MerkleTree(Object.values(roots), utils.keccak256, {
|
||||||
sort: true,
|
sort: true,
|
||||||
@@ -155,22 +225,38 @@ export class ShardedMerkleTree {
|
|||||||
|
|
||||||
public async getProof(
|
public async getProof(
|
||||||
address: string,
|
address: string,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
): Promise<SnapshotEntryWithProof | null> {
|
): Promise<SnapshotEntryWithProof | null> {
|
||||||
const shardId = address.slice(2, 2 + this.shardNybbles).toLowerCase();
|
const shardId = address.slice(2, 2 + this.shardNybbles).toLowerCase();
|
||||||
let shard = this.shards[shardId];
|
let shard = this.shards[shardId];
|
||||||
|
const currencyDecimalMap: Record<string, number> = {};
|
||||||
if (shard === undefined) {
|
if (shard === undefined) {
|
||||||
try {
|
try {
|
||||||
shard = this.shards[shardId] =
|
shard = this.shards[shardId] =
|
||||||
await this.storage.downloadJSON<ShardData>(
|
await this.storage.downloadJSON<ShardData>(
|
||||||
`${this.baseUri}/${shardId}.json`,
|
`${this.baseUri}/${shardId}.json`,
|
||||||
);
|
);
|
||||||
this.trees[shardId] = new MerkleTree(
|
const hashedEntries = await Promise.all(
|
||||||
shard.entries.map((entry) =>
|
shard.entries.map(async (entry) => {
|
||||||
ShardedMerkleTree.hashEntry(entry, this.tokenDecimals),
|
// cache decimals for each currency to avoid refetching for every address
|
||||||
),
|
const currencyDecimals =
|
||||||
utils.keccak256,
|
await ShardedMerkleTree.fetchAndCacheDecimals(
|
||||||
{ sort: true },
|
currencyDecimalMap,
|
||||||
|
provider,
|
||||||
|
entry.currencyAddress,
|
||||||
|
);
|
||||||
|
return ShardedMerkleTree.hashEntry(
|
||||||
|
entry,
|
||||||
|
this.tokenDecimals,
|
||||||
|
currencyDecimals,
|
||||||
|
snapshotFormatVersion,
|
||||||
|
);
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
this.trees[shardId] = new MerkleTree(hashedEntries, utils.keccak256, {
|
||||||
|
sort: true,
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("No merkle entry found for address", address);
|
console.warn("No merkle entry found for address", address);
|
||||||
return null;
|
return null;
|
||||||
@@ -182,35 +268,34 @@ export class ShardedMerkleTree {
|
|||||||
if (!entry) {
|
if (!entry) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const leaf = ShardedMerkleTree.hashEntry(entry, this.tokenDecimals);
|
const currencyDecimals = await ShardedMerkleTree.fetchAndCacheDecimals(
|
||||||
|
currencyDecimalMap,
|
||||||
|
provider,
|
||||||
|
entry.currencyAddress,
|
||||||
|
);
|
||||||
|
const leaf = ShardedMerkleTree.hashEntry(
|
||||||
|
entry,
|
||||||
|
this.tokenDecimals,
|
||||||
|
currencyDecimals,
|
||||||
|
snapshotFormatVersion,
|
||||||
|
);
|
||||||
const proof = this.trees[shardId]
|
const proof = this.trees[shardId]
|
||||||
.getProof(leaf)
|
.getProof(leaf)
|
||||||
.map((i) => "0x" + i.data.toString("hex"));
|
.map((i) => "0x" + i.data.toString("hex"));
|
||||||
return {
|
return SnapshotEntryWithProofSchema.parse({
|
||||||
address,
|
...entry,
|
||||||
proof: proof.concat(shard.proofs),
|
proof: proof.concat(shard.proofs),
|
||||||
maxClaimable: entry.maxClaimable,
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAllEntries(): Promise<SnapshotEntry[]> {
|
public async getAllEntries(): Promise<SnapshotEntry[]> {
|
||||||
try {
|
try {
|
||||||
const entries = await this.storage.downloadJSON<SnapshotEntry[]>(
|
return await this.storage.downloadJSON<SnapshotEntry[]>(
|
||||||
this.originalEntriesUri,
|
this.originalEntriesUri,
|
||||||
);
|
);
|
||||||
return entries;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("Could not fetch original snapshot entries", e);
|
console.warn("Could not fetch original snapshot entries", e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private computeAllShardIds(shardNybbles: number) {
|
|
||||||
const max = parseInt(`0x${"f".repeat(shardNybbles)}`, 16);
|
|
||||||
const allShards = [];
|
|
||||||
for (let i = 0; i <= max; i++) {
|
|
||||||
allShards.push(i.toString(16).padStart(shardNybbles, "0"));
|
|
||||||
}
|
|
||||||
return allShards;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,32 @@
|
|||||||
import { SnapshotInputSchema } from "../schema/contracts/common/snapshots";
|
import { SnapshotInputSchema } from "../schema";
|
||||||
import {
|
import {
|
||||||
SnapshotInfo,
|
SnapshotInfo,
|
||||||
SnapshotInput,
|
SnapshotInput,
|
||||||
} from "../types/claim-conditions/claim-conditions";
|
} from "../types/claim-conditions/claim-conditions";
|
||||||
import { DuplicateLeafsError } from "./error";
|
import { DuplicateLeafsError } from "./error";
|
||||||
import { ShardedMerkleTree } from "./sharded-merkle-tree";
|
import {
|
||||||
|
ShardedMerkleTree,
|
||||||
|
SnapshotFormatVersion,
|
||||||
|
} from "./sharded-merkle-tree";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { BigNumber, BigNumberish, utils } from "ethers";
|
import { ethers } from "ethers";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a snapshot (merkle tree) from a list of addresses and uploads it to IPFS
|
* Create a snapshot (merkle tree) from a list of addresses and uploads it to IPFS
|
||||||
* @param snapshotInput - the list of addresses to hash
|
* @param snapshotInput - the list of addresses to hash
|
||||||
* @param tokenDecimals - the token decimals
|
* @param tokenDecimals - the token decimals
|
||||||
|
* @param provider
|
||||||
* @param storage - the storage to upload to
|
* @param storage - the storage to upload to
|
||||||
|
* @param snapshotFormatVersion
|
||||||
* @returns the generated snapshot and URI
|
* @returns the generated snapshot and URI
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function createSnapshot(
|
export async function createSnapshot(
|
||||||
snapshotInput: SnapshotInput,
|
snapshotInput: SnapshotInput,
|
||||||
tokenDecimals: number,
|
tokenDecimals: number,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
|
snapshotFormatVersion: SnapshotFormatVersion,
|
||||||
): Promise<SnapshotInfo> {
|
): Promise<SnapshotInfo> {
|
||||||
const input = SnapshotInputSchema.parse(snapshotInput);
|
const input = SnapshotInputSchema.parse(snapshotInput);
|
||||||
const addresses = input.map((i) => i.address);
|
const addresses = input.map((i) => i.address);
|
||||||
@@ -30,26 +37,12 @@ export async function createSnapshot(
|
|||||||
const tree = await ShardedMerkleTree.buildAndUpload(
|
const tree = await ShardedMerkleTree.buildAndUpload(
|
||||||
input,
|
input,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
|
provider,
|
||||||
storage,
|
storage,
|
||||||
|
snapshotFormatVersion,
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
merkleRoot: tree.shardedMerkleInfo.merkleRoot,
|
merkleRoot: tree.shardedMerkleInfo.merkleRoot,
|
||||||
snapshotUri: tree.uri,
|
snapshotUri: tree.uri,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hash an address and the corresponding claimable amount
|
|
||||||
* @internal
|
|
||||||
* @param address - the address
|
|
||||||
* @param maxClaimableAmount - the amount
|
|
||||||
*/
|
|
||||||
export function hashLeafNode(
|
|
||||||
address: string,
|
|
||||||
maxClaimableAmount: BigNumberish,
|
|
||||||
): string {
|
|
||||||
return utils.solidityKeccak256(
|
|
||||||
["address", "uint256"],
|
|
||||||
[address, BigNumber.from(maxClaimableAmount)],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import {
|
|||||||
FEATURE_NFT_REVEALABLE,
|
FEATURE_NFT_REVEALABLE,
|
||||||
FEATURE_NFT_SIGNATURE_MINTABLE,
|
FEATURE_NFT_SIGNATURE_MINTABLE,
|
||||||
FEATURE_NFT_SUPPLY,
|
FEATURE_NFT_SUPPLY,
|
||||||
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS,
|
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V1,
|
||||||
|
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V2,
|
||||||
|
FEATURE_NFT_TIERED_DROP,
|
||||||
} from "./erc721-features";
|
} from "./erc721-features";
|
||||||
import {
|
import {
|
||||||
FEATURE_EDITION,
|
FEATURE_EDITION,
|
||||||
@@ -59,10 +61,12 @@ export type Feature =
|
|||||||
| typeof FEATURE_NFT_BATCH_MINTABLE
|
| typeof FEATURE_NFT_BATCH_MINTABLE
|
||||||
| typeof FEATURE_NFT_LAZY_MINTABLE
|
| typeof FEATURE_NFT_LAZY_MINTABLE
|
||||||
| typeof FEATURE_NFT_CLAIMABLE
|
| typeof FEATURE_NFT_CLAIMABLE
|
||||||
| typeof FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS
|
| typeof FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V1
|
||||||
|
| typeof FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V2
|
||||||
| typeof FEATURE_NFT_REVEALABLE
|
| typeof FEATURE_NFT_REVEALABLE
|
||||||
| typeof FEATURE_NFT_SIGNATURE_MINTABLE
|
| typeof FEATURE_NFT_SIGNATURE_MINTABLE
|
||||||
| typeof FEATURE_NFT_BURNABLE
|
| typeof FEATURE_NFT_BURNABLE
|
||||||
|
| typeof FEATURE_NFT_TIERED_DROP
|
||||||
| typeof FEATURE_EDITION
|
| typeof FEATURE_EDITION
|
||||||
| typeof FEATURE_EDITION_ENUMERABLE
|
| typeof FEATURE_EDITION_ENUMERABLE
|
||||||
| typeof FEATURE_EDITION_MINTABLE
|
| typeof FEATURE_EDITION_MINTABLE
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ export const NATIVE_TOKENS: Record<
|
|||||||
symbol: "WETH",
|
symbol: "WETH",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
[ChainId.Goerli]: {
|
[ChainId.Goerli]: {
|
||||||
name: "Görli Ether",
|
name: "Görli Ether",
|
||||||
symbol: "GOR",
|
symbol: "GOR",
|
||||||
decimals: 18,
|
decimals: 18,
|
||||||
wrapped: {
|
wrapped: {
|
||||||
address: "0x0bb7509324ce409f7bbc4b701f932eaca9736ab7",
|
address: "0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6",
|
||||||
name: "Wrapped Ether",
|
name: "Wrapped Ether",
|
||||||
symbol: "WETH",
|
symbol: "WETH",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import DelayedRevealAbi from "@thirdweb-dev/contracts-js/dist/abis/DelayedReveal.json";
|
import DelayedRevealAbi from "@thirdweb-dev/contracts-js/dist/abis/DelayedReveal.json";
|
||||||
import DropSinglePhase1155 from "@thirdweb-dev/contracts-js/dist/abis/DropSinglePhase1155.json";
|
|
||||||
import IBurnableERC1155Abi from "@thirdweb-dev/contracts-js/dist/abis/IBurnableERC1155.json";
|
import IBurnableERC1155Abi from "@thirdweb-dev/contracts-js/dist/abis/IBurnableERC1155.json";
|
||||||
import IClaimableERC1155 from "@thirdweb-dev/contracts-js/dist/abis/IClaimableERC1155.json";
|
import IClaimableERC1155 from "@thirdweb-dev/contracts-js/dist/abis/IClaimableERC1155.json";
|
||||||
|
import IDropSinglePhase1155 from "@thirdweb-dev/contracts-js/dist/abis/IDropSinglePhase1155.json";
|
||||||
import Erc1155Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC1155.json";
|
import Erc1155Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC1155.json";
|
||||||
import Erc1155EnumerableAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC1155Enumerable.json";
|
import Erc1155EnumerableAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC1155Enumerable.json";
|
||||||
import ILazyMintAbi from "@thirdweb-dev/contracts-js/dist/abis/ILazyMint.json";
|
import ILazyMintAbi from "@thirdweb-dev/contracts-js/dist/abis/ILazyMint.json";
|
||||||
@@ -27,7 +27,7 @@ export const FEATURE_EDITION_CLAIMABLE_WITH_CONDITIONS = {
|
|||||||
sdk: "sdk.erc1155claimable",
|
sdk: "sdk.erc1155claimable",
|
||||||
contracts: "DropSinglePhase1155",
|
contracts: "DropSinglePhase1155",
|
||||||
},
|
},
|
||||||
abis: [Erc1155Abi, ILazyMintAbi, DropSinglePhase1155],
|
abis: [Erc1155Abi, ILazyMintAbi, IDropSinglePhase1155],
|
||||||
features: {},
|
features: {},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import IBurnableERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/IBurnableER
|
|||||||
import IClaimableERC721 from "@thirdweb-dev/contracts-js/dist/abis/IClaimableERC721.json";
|
import IClaimableERC721 from "@thirdweb-dev/contracts-js/dist/abis/IClaimableERC721.json";
|
||||||
import DelayedRevealAbi from "@thirdweb-dev/contracts-js/dist/abis/IDelayedReveal.json";
|
import DelayedRevealAbi from "@thirdweb-dev/contracts-js/dist/abis/IDelayedReveal.json";
|
||||||
import IDropSinglePhase from "@thirdweb-dev/contracts-js/dist/abis/IDropSinglePhase.json";
|
import IDropSinglePhase from "@thirdweb-dev/contracts-js/dist/abis/IDropSinglePhase.json";
|
||||||
|
import IDropSinglePhaseV1 from "@thirdweb-dev/contracts-js/dist/abis/IDropSinglePhase_V1.json";
|
||||||
import Erc721Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC721.json";
|
import Erc721Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC721.json";
|
||||||
import Erc721EnumerableAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC721Enumerable.json";
|
import Erc721EnumerableAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC721Enumerable.json";
|
||||||
import Erc721SupplyAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC721Supply.json";
|
import Erc721SupplyAbi from "@thirdweb-dev/contracts-js/dist/abis/IERC721Supply.json";
|
||||||
import ILazyMintAbi from "@thirdweb-dev/contracts-js/dist/abis/ILazyMint.json";
|
import ILazyMintAbi from "@thirdweb-dev/contracts-js/dist/abis/ILazyMint.json";
|
||||||
import IMintableERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/IMintableERC721.json";
|
import IMintableERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/IMintableERC721.json";
|
||||||
import MulticallAbi from "@thirdweb-dev/contracts-js/dist/abis/IMulticall.json";
|
import MulticallAbi from "@thirdweb-dev/contracts-js/dist/abis/IMulticall.json";
|
||||||
|
import TieredDropAbi from "@thirdweb-dev/contracts-js/dist/abis/LazyMintWithTier.json";
|
||||||
import SignatureMintERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/SignatureMintERC721.json";
|
import SignatureMintERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/SignatureMintERC721.json";
|
||||||
|
|
||||||
export const FEATURE_NFT_BURNABLE = {
|
export const FEATURE_NFT_BURNABLE = {
|
||||||
@@ -25,15 +27,26 @@ export const FEATURE_NFT_REVEALABLE = {
|
|||||||
name: "ERC721Revealable",
|
name: "ERC721Revealable",
|
||||||
namespace: "nft.drop.revealer",
|
namespace: "nft.drop.revealer",
|
||||||
docLinks: {
|
docLinks: {
|
||||||
sdk: "sdk.drop.delayedreveal",
|
sdk: "sdk.delayedreveal",
|
||||||
contracts: "DelayedReveal",
|
contracts: "DelayedReveal",
|
||||||
},
|
},
|
||||||
abis: [Erc721Abi, ILazyMintAbi, DelayedRevealAbi],
|
abis: [Erc721Abi, ILazyMintAbi, DelayedRevealAbi],
|
||||||
features: {},
|
features: {},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS = {
|
export const FEATURE_NFT_TIERED_DROP = {
|
||||||
name: "ERC721ClaimableWithConditions",
|
name: "ERC721TieredDrop",
|
||||||
|
namespace: "nft.tieredDrop",
|
||||||
|
docLinks: {
|
||||||
|
sdk: "sdk.erc721tiereddrop",
|
||||||
|
contracts: "TieredDrop",
|
||||||
|
},
|
||||||
|
abis: [Erc721Abi, TieredDropAbi],
|
||||||
|
features: {},
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V2 = {
|
||||||
|
name: "ERC721ClaimableWithConditionsV2",
|
||||||
namespace: "nft.drop.claim",
|
namespace: "nft.drop.claim",
|
||||||
docLinks: {
|
docLinks: {
|
||||||
sdk: "sdk.erc721claimable",
|
sdk: "sdk.erc721claimable",
|
||||||
@@ -43,6 +56,17 @@ export const FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS = {
|
|||||||
features: {},
|
features: {},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V1 = {
|
||||||
|
name: "ERC721ClaimableWithConditionsV1",
|
||||||
|
namespace: "nft.drop.claim",
|
||||||
|
docLinks: {
|
||||||
|
sdk: "sdk.erc721claimable",
|
||||||
|
contracts: "DropSinglePhase_V1",
|
||||||
|
},
|
||||||
|
abis: [Erc721Abi, ILazyMintAbi, IDropSinglePhaseV1],
|
||||||
|
features: {},
|
||||||
|
} as const;
|
||||||
|
|
||||||
export const FEATURE_NFT_CLAIMABLE = {
|
export const FEATURE_NFT_CLAIMABLE = {
|
||||||
name: "ERC721Claimable",
|
name: "ERC721Claimable",
|
||||||
namespace: "nft.drop.claim",
|
namespace: "nft.drop.claim",
|
||||||
@@ -65,8 +89,10 @@ export const FEATURE_NFT_LAZY_MINTABLE = {
|
|||||||
features: {
|
features: {
|
||||||
[FEATURE_NFT_REVEALABLE.name]: FEATURE_NFT_REVEALABLE,
|
[FEATURE_NFT_REVEALABLE.name]: FEATURE_NFT_REVEALABLE,
|
||||||
[FEATURE_NFT_CLAIMABLE.name]: FEATURE_NFT_CLAIMABLE,
|
[FEATURE_NFT_CLAIMABLE.name]: FEATURE_NFT_CLAIMABLE,
|
||||||
[FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS.name]:
|
[FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V2.name]:
|
||||||
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS,
|
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V2,
|
||||||
|
[FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V1.name]:
|
||||||
|
FEATURE_NFT_CLAIMABLE_WITH_CONDITIONS_V1,
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
@@ -143,5 +169,6 @@ export const FEATURE_NFT = {
|
|||||||
[FEATURE_NFT_MINTABLE.name]: FEATURE_NFT_MINTABLE,
|
[FEATURE_NFT_MINTABLE.name]: FEATURE_NFT_MINTABLE,
|
||||||
[FEATURE_NFT_LAZY_MINTABLE.name]: FEATURE_NFT_LAZY_MINTABLE,
|
[FEATURE_NFT_LAZY_MINTABLE.name]: FEATURE_NFT_LAZY_MINTABLE,
|
||||||
[FEATURE_NFT_SIGNATURE_MINTABLE.name]: FEATURE_NFT_SIGNATURE_MINTABLE,
|
[FEATURE_NFT_SIGNATURE_MINTABLE.name]: FEATURE_NFT_SIGNATURE_MINTABLE,
|
||||||
|
[FEATURE_NFT_TIERED_DROP.name]: FEATURE_NFT_TIERED_DROP,
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { getRpcUrl } from "../../core/constants/urls";
|
||||||
import { SignerOrProvider } from "../core/types";
|
import { SignerOrProvider } from "../core/types";
|
||||||
import { StaticJsonRpcBatchProvider } from "../lib/static-batch-rpc";
|
import { StaticJsonRpcBatchProvider } from "../lib/static-batch-rpc";
|
||||||
import { ChainId, SUPPORTED_CHAIN_ID, SUPPORTED_CHAIN_IDS } from "./chains";
|
import { ChainId, SUPPORTED_CHAIN_ID, SUPPORTED_CHAIN_IDS } from "./chains";
|
||||||
@@ -7,39 +8,16 @@ import { ethers, providers } from "ethers";
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_IPFS_GATEWAY = "https://gateway.ipfscdn.io/ipfs/";
|
export const DEFAULT_IPFS_GATEWAY = "https://gateway.ipfscdn.io/ipfs/";
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export const PUBLIC_GATEWAYS = [
|
|
||||||
"https://gateway.ipfscdn.io/ipfs/",
|
|
||||||
"https://cloudflare-ipfs.com/ipfs/",
|
|
||||||
"https://ipfs.io/ipfs/",
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export const TW_IPFS_SERVER_URL = "https://upload.nftlabs.co";
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
export const PINATA_IPFS_URL = `https://api.pinata.cloud/pinning/pinFileToIPFS`;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
* This is a community API key that is subject to rate limiting. Please use your own key.
|
|
||||||
*/
|
|
||||||
const DEFAULT_API_KEY = "_gg7wSSi0KMBsdKnGVfHDueq6xMB9EkC";
|
|
||||||
|
|
||||||
type ChainNames =
|
type ChainNames =
|
||||||
| "mumbai"
|
|
||||||
| "polygon"
|
|
||||||
// common alias for `polygon`
|
|
||||||
| "matic"
|
|
||||||
| "goerli"
|
|
||||||
| "mainnet"
|
| "mainnet"
|
||||||
// common alias for `mainnet`
|
// common alias for `mainnet`
|
||||||
| "ethereum"
|
| "ethereum"
|
||||||
|
| "goerli"
|
||||||
|
| "polygon"
|
||||||
|
// common alias for `polygon`
|
||||||
|
| "matic"
|
||||||
|
| "mumbai"
|
||||||
| "fantom"
|
| "fantom"
|
||||||
| "fantom-testnet"
|
| "fantom-testnet"
|
||||||
| "avalanche"
|
| "avalanche"
|
||||||
@@ -105,49 +83,37 @@ export function getProviderForNetwork(network: ChainOrRpc | SignerOrProvider) {
|
|||||||
return network;
|
return network;
|
||||||
}
|
}
|
||||||
switch (network) {
|
switch (network) {
|
||||||
case "mumbai":
|
|
||||||
return `https://polygon-mumbai.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "rinkeby":
|
|
||||||
return `https://eth-rinkeby.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "goerli":
|
|
||||||
return `https://eth-goerli.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "polygon":
|
|
||||||
case "matic":
|
|
||||||
return `https://polygon-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "mainnet":
|
case "mainnet":
|
||||||
case "ethereum":
|
case "ethereum":
|
||||||
return `https://eth-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
return getRpcUrl("ethereum");
|
||||||
|
case "goerli":
|
||||||
|
return getRpcUrl("goerli");
|
||||||
|
case "polygon":
|
||||||
|
case "matic":
|
||||||
|
return getRpcUrl("polygon");
|
||||||
|
case "mumbai":
|
||||||
|
return getRpcUrl("mumbai");
|
||||||
case "optimism":
|
case "optimism":
|
||||||
// TODO test this RPC
|
return getRpcUrl("optimism");
|
||||||
return `https://opt-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "optimism-kovan":
|
|
||||||
// alchemy optimism kovan rpc doesn't link to the testnet sequencer...
|
|
||||||
return "https://kovan.optimism.io";
|
|
||||||
case "optimism-goerli":
|
case "optimism-goerli":
|
||||||
// TODO test this RPC
|
return getRpcUrl("optimism-goerli");
|
||||||
return `https://opt-goerli.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "arbitrum":
|
case "arbitrum":
|
||||||
// TODO test this RPC
|
return getRpcUrl("arbitrum");
|
||||||
return `https://arb-mainnet.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "arbitrum-rinkeby":
|
|
||||||
// TODO test this RPC
|
|
||||||
return `https://arb-rinkeby.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "arbitrum-goerli":
|
case "arbitrum-goerli":
|
||||||
// TODO test this RPC
|
return getRpcUrl("arbitrum-goerli");
|
||||||
return `https://arb-goerli.g.alchemy.com/v2/${DEFAULT_API_KEY}`;
|
|
||||||
case "fantom":
|
case "fantom":
|
||||||
return "https://rpc.ftm.tools";
|
return getRpcUrl("fantom");
|
||||||
case "fantom-testnet":
|
case "fantom-testnet":
|
||||||
return "https://rpc.testnet.fantom.network/";
|
return getRpcUrl("fantom-testnet");
|
||||||
case "avalanche":
|
case "avalanche":
|
||||||
return "https://api.avax.network/ext/bc/C/rpc";
|
return getRpcUrl("avalanche");
|
||||||
case "avalanche-testnet":
|
case "avalanche-testnet":
|
||||||
case "avalanche-fuji":
|
case "avalanche-fuji":
|
||||||
return "https://api.avax-test.network/ext/bc/C/rpc";
|
return getRpcUrl("avalanche-fuji");
|
||||||
case "binance":
|
case "binance":
|
||||||
return "https://bsc-dataseed1.binance.org";
|
return getRpcUrl("binance");
|
||||||
case "binance-testnet":
|
case "binance-testnet":
|
||||||
return "https://data-seed-prebsc-1-s1.binance.org:8545";
|
return getRpcUrl("binance-testnet");
|
||||||
default:
|
default:
|
||||||
if (network.startsWith("http") || network.startsWith("ws")) {
|
if (network.startsWith("http") || network.startsWith("ws")) {
|
||||||
return network;
|
return network;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import { getPrebuiltInfo } from "../common/legacy";
|
||||||
import { ALL_ROLES } from "../common/role";
|
import { ALL_ROLES } from "../common/role";
|
||||||
import { getSignerAndProvider } from "../core/classes/rpc-connection-handler";
|
import { getSignerAndProvider } from "../core/classes/rpc-connection-handler";
|
||||||
import type { ContractType, NetworkOrSignerOrProvider } from "../core/types";
|
import type {
|
||||||
|
ContractType,
|
||||||
|
NetworkOrSignerOrProvider,
|
||||||
|
PrebuiltContractType,
|
||||||
|
} from "../core/types";
|
||||||
import {
|
import {
|
||||||
DropErc1155ContractSchema,
|
DropErc1155ContractSchema,
|
||||||
DropErc721ContractSchema,
|
DropErc721ContractSchema,
|
||||||
@@ -17,6 +22,7 @@ import { CustomContractSchema } from "../schema/contracts/custom";
|
|||||||
import { DropErc20ContractSchema } from "../schema/contracts/drop-erc20";
|
import { DropErc20ContractSchema } from "../schema/contracts/drop-erc20";
|
||||||
import { MultiwrapContractSchema } from "../schema/contracts/multiwrap";
|
import { MultiwrapContractSchema } from "../schema/contracts/multiwrap";
|
||||||
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import type { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
|
||||||
type InitalizeParams = [
|
type InitalizeParams = [
|
||||||
network: NetworkOrSignerOrProvider,
|
network: NetworkOrSignerOrProvider,
|
||||||
@@ -34,8 +40,12 @@ export const EditionDropInitializer = {
|
|||||||
...[network, address, storage, options]: InitalizeParams
|
...[network, address, storage, options]: InitalizeParams
|
||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
|
const contractInfo = await getPrebuiltInfo(address, provider);
|
||||||
|
if (!contractInfo || contractInfo.type !== "DropERC1155") {
|
||||||
|
throw new Error("Contract is not a DropERC1155");
|
||||||
|
}
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
EditionDropInitializer.getAbi(),
|
await EditionDropInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/edition-drop"),
|
import("./prebuilt-implementations/edition-drop"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -49,9 +59,21 @@ export const EditionDropInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json"))
|
const contractInfo = await assertContractType(
|
||||||
.default,
|
address,
|
||||||
|
provider,
|
||||||
|
"edition-drop",
|
||||||
|
);
|
||||||
|
return contractInfo.version > 2
|
||||||
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json"))
|
||||||
|
.default
|
||||||
|
: (
|
||||||
|
await import(
|
||||||
|
"@thirdweb-dev/contracts-js/dist/abis/DropERC1155_V2.json"
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EditionInitializer = {
|
export const EditionInitializer = {
|
||||||
@@ -64,7 +86,7 @@ export const EditionInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
EditionInitializer.getAbi(),
|
EditionInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/edition"),
|
import("./prebuilt-implementations/edition"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -78,9 +100,12 @@ export const EditionInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC1155.json"))
|
await assertContractType(address, provider, "edition");
|
||||||
.default,
|
return (
|
||||||
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC1155.json")
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MarketplaceInitializer = {
|
export const MarketplaceInitializer = {
|
||||||
@@ -93,7 +118,7 @@ export const MarketplaceInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
MarketplaceInitializer.getAbi(),
|
MarketplaceInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/marketplace"),
|
import("./prebuilt-implementations/marketplace"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -107,9 +132,12 @@ export const MarketplaceInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Marketplace.json"))
|
await assertContractType(address, provider, "marketplace");
|
||||||
.default,
|
return (
|
||||||
|
await import("@thirdweb-dev/contracts-js/dist/abis/Marketplace.json")
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MultiwrapInitializer = {
|
export const MultiwrapInitializer = {
|
||||||
@@ -122,7 +150,7 @@ export const MultiwrapInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
MultiwrapInitializer.getAbi(),
|
MultiwrapInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/multiwrap"),
|
import("./prebuilt-implementations/multiwrap"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -136,9 +164,11 @@ export const MultiwrapInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Multiwrap.json"))
|
await assertContractType(address, provider, "multiwrap");
|
||||||
.default,
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Multiwrap.json"))
|
||||||
|
.default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NFTCollectionInitializer = {
|
export const NFTCollectionInitializer = {
|
||||||
@@ -152,7 +182,7 @@ export const NFTCollectionInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
NFTCollectionInitializer.getAbi(),
|
NFTCollectionInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/nft-collection"),
|
import("./prebuilt-implementations/nft-collection"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -166,9 +196,12 @@ export const NFTCollectionInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json"))
|
await assertContractType(address, provider, "nft-collection");
|
||||||
.default,
|
return (
|
||||||
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json")
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NFTDropInitializer = {
|
export const NFTDropInitializer = {
|
||||||
@@ -180,8 +213,12 @@ export const NFTDropInitializer = {
|
|||||||
...[network, address, storage, options]: InitalizeParams
|
...[network, address, storage, options]: InitalizeParams
|
||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
|
const contractInfo = await getPrebuiltInfo(address, provider);
|
||||||
|
if (!contractInfo || contractInfo.type !== "DropERC721") {
|
||||||
|
throw new Error("Contract is not a DropERC721");
|
||||||
|
}
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
NFTDropInitializer.getAbi(),
|
NFTDropInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/nft-drop"),
|
import("./prebuilt-implementations/nft-drop"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -195,9 +232,21 @@ export const NFTDropInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC721.json"))
|
const contractInfo = await assertContractType(
|
||||||
.default,
|
address,
|
||||||
|
provider,
|
||||||
|
"nft-drop",
|
||||||
|
);
|
||||||
|
return contractInfo.version > 3
|
||||||
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC721.json"))
|
||||||
|
.default
|
||||||
|
: (
|
||||||
|
await import(
|
||||||
|
"@thirdweb-dev/contracts-js/dist/abis/DropERC721_V3.json"
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const PackInitializer = {
|
export const PackInitializer = {
|
||||||
@@ -211,7 +260,7 @@ export const PackInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
PackInitializer.getAbi(),
|
PackInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/pack"),
|
import("./prebuilt-implementations/pack"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -225,8 +274,11 @@ export const PackInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Pack.json")).default,
|
await assertContractType(address, provider, "pack");
|
||||||
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Pack.json"))
|
||||||
|
.default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SignatureDropInitializer = {
|
export const SignatureDropInitializer = {
|
||||||
@@ -240,7 +292,7 @@ export const SignatureDropInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
SignatureDropInitializer.getAbi(),
|
SignatureDropInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/signature-drop"),
|
import("./prebuilt-implementations/signature-drop"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -254,9 +306,24 @@ export const SignatureDropInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/SignatureDrop.json"))
|
const contractInfo = await assertContractType(
|
||||||
.default,
|
address,
|
||||||
|
provider,
|
||||||
|
"signature-drop",
|
||||||
|
);
|
||||||
|
return contractInfo.version > 4
|
||||||
|
? (
|
||||||
|
await import(
|
||||||
|
"@thirdweb-dev/contracts-js/dist/abis/SignatureDrop.json"
|
||||||
|
)
|
||||||
|
).default
|
||||||
|
: (
|
||||||
|
await import(
|
||||||
|
"@thirdweb-dev/contracts-js/dist/abis/SignatureDrop_V4.json"
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SplitInitializer = {
|
export const SplitInitializer = {
|
||||||
@@ -270,7 +337,7 @@ export const SplitInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
SplitInitializer.getAbi(),
|
SplitInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/split"),
|
import("./prebuilt-implementations/split"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -284,8 +351,11 @@ export const SplitInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/Split.json")).default,
|
await assertContractType(address, provider, "split");
|
||||||
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Split.json"))
|
||||||
|
.default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TokenDropInitializer = {
|
export const TokenDropInitializer = {
|
||||||
@@ -298,8 +368,12 @@ export const TokenDropInitializer = {
|
|||||||
...[network, address, storage, options]: InitalizeParams
|
...[network, address, storage, options]: InitalizeParams
|
||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
|
const contractInfo = await getPrebuiltInfo(address, provider);
|
||||||
|
if (!contractInfo || contractInfo.type !== "DropERC20") {
|
||||||
|
throw new Error("Contract is not a DropERC20");
|
||||||
|
}
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
TokenDropInitializer.getAbi(),
|
TokenDropInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/token-drop"),
|
import("./prebuilt-implementations/token-drop"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -313,9 +387,18 @@ export const TokenDropInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20.json"))
|
const contractInfo = await assertContractType(
|
||||||
.default,
|
address,
|
||||||
|
provider,
|
||||||
|
"token-drop",
|
||||||
|
);
|
||||||
|
return contractInfo.version > 2
|
||||||
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20.json"))
|
||||||
|
.default
|
||||||
|
: (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20_V2.json"))
|
||||||
|
.default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TokenInitializer = {
|
export const TokenInitializer = {
|
||||||
@@ -328,7 +411,7 @@ export const TokenInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
TokenInitializer.getAbi(),
|
TokenInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/token"),
|
import("./prebuilt-implementations/token"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -342,9 +425,12 @@ export const TokenInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC20.json"))
|
await assertContractType(address, provider, "token");
|
||||||
.default,
|
return (
|
||||||
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC20.json")
|
||||||
|
).default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VoteInitializer = {
|
export const VoteInitializer = {
|
||||||
@@ -358,7 +444,7 @@ export const VoteInitializer = {
|
|||||||
) => {
|
) => {
|
||||||
const [, provider] = getSignerAndProvider(network, options);
|
const [, provider] = getSignerAndProvider(network, options);
|
||||||
const [abi, contract, _network] = await Promise.all([
|
const [abi, contract, _network] = await Promise.all([
|
||||||
VoteInitializer.getAbi(),
|
VoteInitializer.getAbi(address, provider),
|
||||||
import("./prebuilt-implementations/vote"),
|
import("./prebuilt-implementations/vote"),
|
||||||
provider.getNetwork(),
|
provider.getNetwork(),
|
||||||
]);
|
]);
|
||||||
@@ -372,11 +458,25 @@ export const VoteInitializer = {
|
|||||||
_network.chainId,
|
_network.chainId,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async () =>
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
(await import("@thirdweb-dev/contracts-js/dist/abis/VoteERC20.json"))
|
await assertContractType(address, provider, "vote");
|
||||||
.default,
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/VoteERC20.json"))
|
||||||
|
.default;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function assertContractType(
|
||||||
|
address: string,
|
||||||
|
provider: ethers.providers.Provider,
|
||||||
|
type: PrebuiltContractType,
|
||||||
|
) {
|
||||||
|
const contractInfo = await getPrebuiltInfo(address, provider);
|
||||||
|
if (!contractInfo || contractInfo.type !== getContractName(type)) {
|
||||||
|
throw new Error(`Contract is not a ${type}`);
|
||||||
|
}
|
||||||
|
return contractInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a map from contractType -> contract metadata
|
* a map from contractType -> contract metadata
|
||||||
* @internal
|
* @internal
|
||||||
@@ -417,3 +517,11 @@ export function getContractTypeForRemoteName(name: string): ContractType {
|
|||||||
?.contractType || "custom"
|
?.contractType || "custom"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getContractName(
|
||||||
|
type: PrebuiltContractType,
|
||||||
|
): string | undefined {
|
||||||
|
return Object.values(CONTRACTS_MAP).find(
|
||||||
|
(contract) => contract.contractType === type,
|
||||||
|
)?.name;
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ import {
|
|||||||
TransactionResult,
|
TransactionResult,
|
||||||
TransactionResultWithId,
|
TransactionResultWithId,
|
||||||
} from "../../core/types";
|
} from "../../core/types";
|
||||||
import { PaperCheckout } from "../../integrations/paper-xyz";
|
import { PaperCheckout } from "../../integrations/thirdweb-checkout";
|
||||||
import { DropErc1155ContractSchema } from "../../schema/contracts/drop-erc1155";
|
import { DropErc1155ContractSchema } from "../../schema/contracts/drop-erc1155";
|
||||||
import { SDKOptions } from "../../schema/sdk-options";
|
import { SDKOptions } from "../../schema/sdk-options";
|
||||||
import type { DropERC1155 } from "@thirdweb-dev/contracts-js";
|
import { PrebuiltEditionDrop } from "../../types/eips";
|
||||||
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json";
|
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json";
|
||||||
import { ThirdwebStorage, UploadProgressEvent } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage, UploadProgressEvent } from "@thirdweb-dev/storage";
|
||||||
import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
||||||
@@ -39,26 +39,26 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "edition-drop");
|
* const contract = await sdk.getContract("{{contract_address}}", "edition-drop");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class EditionDrop extends StandardErc1155<DropERC1155> {
|
export class EditionDrop extends StandardErc1155<PrebuiltEditionDrop> {
|
||||||
private static contractRoles = ["admin", "minter", "transfer"] as const;
|
private static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||||
|
|
||||||
public abi: typeof ABI;
|
public abi: typeof ABI;
|
||||||
public sales: ContractPrimarySale<DropERC1155>;
|
public sales: ContractPrimarySale<PrebuiltEditionDrop>;
|
||||||
public platformFees: ContractPlatformFee<DropERC1155>;
|
public platformFees: ContractPlatformFee<PrebuiltEditionDrop>;
|
||||||
public encoder: ContractEncoder<DropERC1155>;
|
public encoder: ContractEncoder<PrebuiltEditionDrop>;
|
||||||
public estimator: GasCostEstimator<DropERC1155>;
|
public estimator: GasCostEstimator<PrebuiltEditionDrop>;
|
||||||
public events: ContractEvents<DropERC1155>;
|
public events: ContractEvents<PrebuiltEditionDrop>;
|
||||||
public metadata: ContractMetadata<
|
public metadata: ContractMetadata<
|
||||||
DropERC1155,
|
PrebuiltEditionDrop,
|
||||||
typeof DropErc1155ContractSchema
|
typeof DropErc1155ContractSchema
|
||||||
>;
|
>;
|
||||||
public roles: ContractRoles<
|
public roles: ContractRoles<
|
||||||
DropERC1155,
|
PrebuiltEditionDrop,
|
||||||
typeof EditionDrop.contractRoles[number]
|
typeof EditionDrop.contractRoles[number]
|
||||||
>;
|
>;
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +79,7 @@ export class EditionDrop extends StandardErc1155<DropERC1155> {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public royalties: ContractRoyalty<
|
public royalties: ContractRoyalty<
|
||||||
DropERC1155,
|
PrebuiltEditionDrop,
|
||||||
typeof DropErc1155ContractSchema
|
typeof DropErc1155ContractSchema
|
||||||
>;
|
>;
|
||||||
/**
|
/**
|
||||||
@@ -106,18 +106,18 @@ export class EditionDrop extends StandardErc1155<DropERC1155> {
|
|||||||
* await contract.claimConditions.set(tokenId, claimConditions);
|
* await contract.claimConditions.set(tokenId, claimConditions);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public claimConditions: DropErc1155ClaimConditions<DropERC1155>;
|
public claimConditions: DropErc1155ClaimConditions<PrebuiltEditionDrop>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checkout
|
* Checkout
|
||||||
* @remarks Create a FIAT currency checkout for your NFT drop.
|
* @remarks Create a FIAT currency checkout for your NFT drop.
|
||||||
*/
|
*/
|
||||||
public checkout: PaperCheckout<DropERC1155>;
|
public checkout: PaperCheckout<PrebuiltEditionDrop>;
|
||||||
|
|
||||||
public history: DropErc1155History;
|
public history: DropErc1155History;
|
||||||
public interceptor: ContractInterceptor<DropERC1155>;
|
public interceptor: ContractInterceptor<PrebuiltEditionDrop>;
|
||||||
public erc1155: Erc1155<DropERC1155>;
|
public erc1155: Erc1155<PrebuiltEditionDrop>;
|
||||||
public owner: ContractOwner<DropERC1155>;
|
public owner: ContractOwner<PrebuiltEditionDrop>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
network: NetworkOrSignerOrProvider,
|
network: NetworkOrSignerOrProvider,
|
||||||
@@ -126,7 +126,7 @@ export class EditionDrop extends StandardErc1155<DropERC1155> {
|
|||||||
options: SDKOptions = {},
|
options: SDKOptions = {},
|
||||||
abi: typeof ABI,
|
abi: typeof ABI,
|
||||||
chainId: number,
|
chainId: number,
|
||||||
contractWrapper = new ContractWrapper<DropERC1155>(
|
contractWrapper = new ContractWrapper<PrebuiltEditionDrop>(
|
||||||
network,
|
network,
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "edition");
|
* const contract = await sdk.getContract("{{contract_address}}", "edition");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { DEFAULT_QUERY_ALL_COUNT } from "../../../core/schema/QueryParams";
|
import { DEFAULT_QUERY_ALL_COUNT } from "../../../core/schema/QueryParams";
|
||||||
import { ListingNotFoundError } from "../../common";
|
import { ListingNotFoundError } from "../../common";
|
||||||
|
import { isNativeToken } from "../../common/currency";
|
||||||
import { mapOffer } from "../../common/marketplace";
|
import { mapOffer } from "../../common/marketplace";
|
||||||
import { getRoleHash } from "../../common/role";
|
import { getRoleHash } from "../../common/role";
|
||||||
|
import { NATIVE_TOKENS, SUPPORTED_CHAIN_ID } from "../../constants";
|
||||||
import { ContractEncoder } from "../../core/classes/contract-encoder";
|
import { ContractEncoder } from "../../core/classes/contract-encoder";
|
||||||
import { ContractEvents } from "../../core/classes/contract-events";
|
import { ContractEvents } from "../../core/classes/contract-events";
|
||||||
import { ContractInterceptor } from "../../core/classes/contract-interceptor";
|
import { ContractInterceptor } from "../../core/classes/contract-interceptor";
|
||||||
@@ -17,6 +19,7 @@ import { NetworkOrSignerOrProvider, TransactionResult } from "../../core/types";
|
|||||||
import { ListingType } from "../../enums";
|
import { ListingType } from "../../enums";
|
||||||
import { MarketplaceContractSchema } from "../../schema/contracts/marketplace";
|
import { MarketplaceContractSchema } from "../../schema/contracts/marketplace";
|
||||||
import { SDKOptions } from "../../schema/sdk-options";
|
import { SDKOptions } from "../../schema/sdk-options";
|
||||||
|
import { Price } from "../../types/currency";
|
||||||
import { AuctionListing, DirectListing, Offer } from "../../types/marketplace";
|
import { AuctionListing, DirectListing, Offer } from "../../types/marketplace";
|
||||||
import { MarketplaceFilter } from "../../types/marketplace/MarketPlaceFilter";
|
import { MarketplaceFilter } from "../../types/marketplace/MarketPlaceFilter";
|
||||||
import { UnmappedOffer } from "../../types/marketplace/UnmappedOffer";
|
import { UnmappedOffer } from "../../types/marketplace/UnmappedOffer";
|
||||||
@@ -36,7 +39,7 @@ import invariant from "tiny-invariant";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "marketplace");
|
* const contract = await sdk.getContract("{{contract_address}}", "marketplace");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
@@ -324,22 +327,22 @@ export class Marketplace implements UpdateableNetwork {
|
|||||||
// get only the events for this listing id
|
// get only the events for this listing id
|
||||||
const listingEvents = events.filter((e) => e.data.listingId.eq(listingId));
|
const listingEvents = events.filter((e) => e.data.listingId.eq(listingId));
|
||||||
// derive the offers from the events
|
// derive the offers from the events
|
||||||
const offers = await Promise.all(
|
return await Promise.all(
|
||||||
listingEvents.map(async (e): Promise<Offer> => {
|
listingEvents.map(async (e): Promise<Offer> => {
|
||||||
const offer = await mapOffer(
|
return await mapOffer(
|
||||||
this.contractWrapper.getProvider(),
|
this.contractWrapper.getProvider(),
|
||||||
BigNumber.from(listingId),
|
BigNumber.from(listingId),
|
||||||
{
|
{
|
||||||
quantityWanted: e.data.quantityWanted,
|
quantityWanted: e.data.quantityWanted,
|
||||||
pricePerToken: e.data.totalOfferAmount.div(e.data.quantityWanted),
|
pricePerToken: e.data.quantityWanted.gt(0)
|
||||||
|
? e.data.totalOfferAmount.div(e.data.quantityWanted)
|
||||||
|
: e.data.totalOfferAmount,
|
||||||
currency: e.data.currency,
|
currency: e.data.currency,
|
||||||
offeror: e.data.offeror,
|
offeror: e.data.offeror,
|
||||||
} as UnmappedOffer,
|
} as UnmappedOffer,
|
||||||
);
|
);
|
||||||
return offer;
|
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return offers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ******************************
|
/** ******************************
|
||||||
@@ -391,6 +394,60 @@ export class Marketplace implements UpdateableNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an offer for a Direct or Auction Listing
|
||||||
|
*
|
||||||
|
* @remarks Make an offer on a direct or auction listing
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* // The listing ID of the asset you want to offer on
|
||||||
|
* const listingId = 0;
|
||||||
|
* // The price you are willing to offer per token
|
||||||
|
* const pricePerToken = 0.5;
|
||||||
|
* // The quantity of tokens you want to receive for this offer
|
||||||
|
* const quantity = 1;
|
||||||
|
*
|
||||||
|
* await contract.makeOffer(
|
||||||
|
* listingId,
|
||||||
|
* pricePerToken,
|
||||||
|
* quantity,
|
||||||
|
* );
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public async makeOffer(
|
||||||
|
listingId: BigNumberish,
|
||||||
|
pricePerToken: Price,
|
||||||
|
quantity?: BigNumberish,
|
||||||
|
): Promise<TransactionResult> {
|
||||||
|
const listing = await this.contractWrapper.readContract.listings(listingId);
|
||||||
|
if (listing.listingId.toString() !== listingId.toString()) {
|
||||||
|
throw new ListingNotFoundError(this.getAddress(), listingId.toString());
|
||||||
|
}
|
||||||
|
const chainId = await this.contractWrapper.getChainID();
|
||||||
|
switch (listing.listingType) {
|
||||||
|
case ListingType.Direct: {
|
||||||
|
invariant(
|
||||||
|
quantity,
|
||||||
|
"quantity is required when making an offer on a direct listing",
|
||||||
|
);
|
||||||
|
return await this.direct.makeOffer(
|
||||||
|
listingId,
|
||||||
|
quantity,
|
||||||
|
isNativeToken(listing.currency)
|
||||||
|
? NATIVE_TOKENS[chainId as SUPPORTED_CHAIN_ID].wrapped.address
|
||||||
|
: listing.currency,
|
||||||
|
pricePerToken,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
case ListingType.Auction: {
|
||||||
|
return await this.auction.makeBid(listingId, pricePerToken);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw Error(`Unknown listing type: ${listing.listingType}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Auction bid buffer
|
* Set the Auction bid buffer
|
||||||
* @remarks A percentage (e.g. 5%) in basis points (5% = 500, 100% = 10000). A new bid is considered to be a winning bid only if its bid amount is at least the bid buffer (e.g. 5%) greater than the previous winning bid. This prevents buyers from making very slightly higher bids to win the auctioned items.
|
* @remarks A percentage (e.g. 5%) in basis points (5% = 500, 100% = 10000). A new bid is considered to be a winning bid only if its bid amount is at least the bid buffer (e.g. 5%) greater than the previous winning bid. This prevents buyers from making very slightly higher bids to win the auctioned items.
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import { BigNumberish, CallOverrides, ethers } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "multiwrap");
|
* const contract = await sdk.getContract("{{contract_address}}", "multiwrap");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @beta
|
* @beta
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import { BigNumberish, CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "nft-collection");
|
* const contract = await sdk.getContract("{{contract_address}}", "nft-collection");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import {
|
|||||||
} from "../../../core/schema/QueryParams";
|
} from "../../../core/schema/QueryParams";
|
||||||
import { NFT, NFTMetadata, NFTMetadataOrUri } from "../../../core/schema/nft";
|
import { NFT, NFTMetadata, NFTMetadataOrUri } from "../../../core/schema/nft";
|
||||||
import { getRoleHash } from "../../common";
|
import { getRoleHash } from "../../common";
|
||||||
import { uploadOrExtractURIs } from "../../common/nft";
|
|
||||||
import { FEATURE_NFT_REVEALABLE } from "../../constants/erc721-features";
|
import { FEATURE_NFT_REVEALABLE } from "../../constants/erc721-features";
|
||||||
import { TransactionTask } from "../../core/classes/TransactionTask";
|
import { TransactionTask } from "../../core/classes/TransactionTask";
|
||||||
import { ContractEncoder } from "../../core/classes/contract-encoder";
|
import { ContractEncoder } from "../../core/classes/contract-encoder";
|
||||||
@@ -27,21 +26,14 @@ import {
|
|||||||
TransactionResult,
|
TransactionResult,
|
||||||
TransactionResultWithId,
|
TransactionResultWithId,
|
||||||
} from "../../core/types";
|
} from "../../core/types";
|
||||||
import { PaperCheckout } from "../../integrations/paper-xyz";
|
import { PaperCheckout } from "../../integrations/thirdweb-checkout";
|
||||||
import { DropErc721ContractSchema } from "../../schema/contracts/drop-erc721";
|
import { DropErc721ContractSchema } from "../../schema/contracts/drop-erc721";
|
||||||
import { SDKOptions } from "../../schema/sdk-options";
|
import { SDKOptions } from "../../schema/sdk-options";
|
||||||
|
import { PrebuiltNFTDrop } from "../../types/eips";
|
||||||
import { UploadProgressEvent } from "../../types/events";
|
import { UploadProgressEvent } from "../../types/events";
|
||||||
import type { DropERC721 } from "@thirdweb-dev/contracts-js";
|
|
||||||
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC721.json";
|
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC721.json";
|
||||||
import { TokensLazyMintedEvent } from "@thirdweb-dev/contracts-js/dist/declarations/src/DropERC721";
|
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import {
|
import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
||||||
BigNumber,
|
|
||||||
BigNumberish,
|
|
||||||
CallOverrides,
|
|
||||||
constants,
|
|
||||||
ethers,
|
|
||||||
} from "ethers";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup a collection of one-of-one NFTs that are minted as users claim them.
|
* Setup a collection of one-of-one NFTs that are minted as users claim them.
|
||||||
@@ -52,29 +44,32 @@ import {
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "nft-drop");
|
* const contract = await sdk.getContract("{{contract_address}}", "nft-drop");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class NFTDrop extends StandardErc721<DropERC721> {
|
export class NFTDrop extends StandardErc721<PrebuiltNFTDrop> {
|
||||||
static contractRoles = ["admin", "minter", "transfer"] as const;
|
static contractRoles = ["admin", "minter", "transfer"] as const;
|
||||||
|
|
||||||
public abi: typeof ABI;
|
public abi: typeof ABI;
|
||||||
public encoder: ContractEncoder<DropERC721>;
|
public encoder: ContractEncoder<PrebuiltNFTDrop>;
|
||||||
public estimator: GasCostEstimator<DropERC721>;
|
public estimator: GasCostEstimator<PrebuiltNFTDrop>;
|
||||||
public metadata: ContractMetadata<
|
public metadata: ContractMetadata<
|
||||||
DropERC721,
|
PrebuiltNFTDrop,
|
||||||
typeof DropErc721ContractSchema
|
typeof DropErc721ContractSchema
|
||||||
>;
|
>;
|
||||||
public sales: ContractPrimarySale<DropERC721>;
|
public sales: ContractPrimarySale<PrebuiltNFTDrop>;
|
||||||
public platformFees: ContractPlatformFee<DropERC721>;
|
public platformFees: ContractPlatformFee<PrebuiltNFTDrop>;
|
||||||
public events: ContractEvents<DropERC721>;
|
public events: ContractEvents<PrebuiltNFTDrop>;
|
||||||
public roles: ContractRoles<DropERC721, typeof NFTDrop.contractRoles[number]>;
|
public roles: ContractRoles<
|
||||||
|
PrebuiltNFTDrop,
|
||||||
|
typeof NFTDrop.contractRoles[number]
|
||||||
|
>;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public interceptor: ContractInterceptor<DropERC721>;
|
public interceptor: ContractInterceptor<PrebuiltNFTDrop>;
|
||||||
/**
|
/**
|
||||||
* Configure royalties
|
* Configure royalties
|
||||||
* @remarks Set your own royalties for the entire contract or per token
|
* @remarks Set your own royalties for the entire contract or per token
|
||||||
@@ -93,7 +88,7 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public royalties: ContractRoyalty<
|
public royalties: ContractRoyalty<
|
||||||
DropERC721,
|
PrebuiltNFTDrop,
|
||||||
typeof DropErc721ContractSchema
|
typeof DropErc721ContractSchema
|
||||||
>;
|
>;
|
||||||
/**
|
/**
|
||||||
@@ -118,7 +113,7 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
* await contract.claimConditions.set(claimConditions);
|
* await contract.claimConditions.set(claimConditions);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public claimConditions: DropClaimConditions<DropERC721>;
|
public claimConditions: DropClaimConditions<PrebuiltNFTDrop>;
|
||||||
/**
|
/**
|
||||||
* Delayed reveal
|
* Delayed reveal
|
||||||
* @remarks Create a batch of encrypted NFTs that can be revealed at a later time.
|
* @remarks Create a batch of encrypted NFTs that can be revealed at a later time.
|
||||||
@@ -150,16 +145,16 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
* await contract.revealer.reveal(batchId, "my secret password");
|
* await contract.revealer.reveal(batchId, "my secret password");
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public revealer: DelayedReveal<DropERC721>;
|
public revealer: DelayedReveal<PrebuiltNFTDrop>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checkout
|
* Checkout
|
||||||
* @remarks Create a FIAT currency checkout for your NFT drop.
|
* @remarks Create a FIAT currency checkout for your NFT drop.
|
||||||
*/
|
*/
|
||||||
public checkout: PaperCheckout<DropERC721>;
|
public checkout: PaperCheckout<PrebuiltNFTDrop>;
|
||||||
|
|
||||||
public erc721: Erc721<DropERC721>;
|
public erc721: Erc721<PrebuiltNFTDrop>;
|
||||||
public owner: ContractOwner<DropERC721>;
|
public owner: ContractOwner<PrebuiltNFTDrop>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
network: NetworkOrSignerOrProvider,
|
network: NetworkOrSignerOrProvider,
|
||||||
@@ -168,7 +163,7 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
options: SDKOptions = {},
|
options: SDKOptions = {},
|
||||||
abi: typeof ABI,
|
abi: typeof ABI,
|
||||||
chainId: number,
|
chainId: number,
|
||||||
contractWrapper = new ContractWrapper<DropERC721>(
|
contractWrapper = new ContractWrapper<PrebuiltNFTDrop>(
|
||||||
network,
|
network,
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
@@ -195,7 +190,7 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
this.events = new ContractEvents(this.contractWrapper);
|
this.events = new ContractEvents(this.contractWrapper);
|
||||||
this.platformFees = new ContractPlatformFee(this.contractWrapper);
|
this.platformFees = new ContractPlatformFee(this.contractWrapper);
|
||||||
this.erc721 = new Erc721(this.contractWrapper, this.storage, chainId);
|
this.erc721 = new Erc721(this.contractWrapper, this.storage, chainId);
|
||||||
this.revealer = new DelayedReveal<DropERC721>(
|
this.revealer = new DelayedReveal(
|
||||||
this.contractWrapper,
|
this.contractWrapper,
|
||||||
this.storage,
|
this.storage,
|
||||||
FEATURE_NFT_REVEALABLE.name,
|
FEATURE_NFT_REVEALABLE.name,
|
||||||
@@ -383,44 +378,7 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
onProgress: (event: UploadProgressEvent) => void;
|
onProgress: (event: UploadProgressEvent) => void;
|
||||||
},
|
},
|
||||||
): Promise<TransactionResultWithId<NFTMetadata>[]> {
|
): Promise<TransactionResultWithId<NFTMetadata>[]> {
|
||||||
const startFileNumber =
|
return this.erc721.lazyMint(metadatas, options);
|
||||||
await this.contractWrapper.readContract.nextTokenIdToMint();
|
|
||||||
const batch = await uploadOrExtractURIs(
|
|
||||||
metadatas,
|
|
||||||
this.storage,
|
|
||||||
startFileNumber.toNumber(),
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
// ensure baseUri is the same for the entire batch
|
|
||||||
const baseUri = batch[0].substring(0, batch[0].lastIndexOf("/"));
|
|
||||||
for (let i = 0; i < batch.length; i++) {
|
|
||||||
const uri = batch[i].substring(0, batch[i].lastIndexOf("/"));
|
|
||||||
if (baseUri !== uri) {
|
|
||||||
throw new Error(
|
|
||||||
`Can only create batches with the same base URI for every entry in the batch. Expected '${baseUri}' but got '${uri}'`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const receipt = await this.contractWrapper.sendTransaction("lazyMint", [
|
|
||||||
batch.length,
|
|
||||||
baseUri.endsWith("/") ? baseUri : `${baseUri}/`,
|
|
||||||
ethers.utils.toUtf8Bytes(""),
|
|
||||||
]);
|
|
||||||
const event = this.contractWrapper.parseLogs<TokensLazyMintedEvent>(
|
|
||||||
"TokensLazyMinted",
|
|
||||||
receipt?.logs,
|
|
||||||
);
|
|
||||||
const startingIndex = event[0].args.startTokenId;
|
|
||||||
const endingIndex = event[0].args.endTokenId;
|
|
||||||
const results: TransactionResultWithId<NFTMetadata>[] = [];
|
|
||||||
for (let id = startingIndex; id.lte(endingIndex); id = id.add(1)) {
|
|
||||||
results.push({
|
|
||||||
id,
|
|
||||||
receipt,
|
|
||||||
data: () => this.erc721.getTokenMetadata(id),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,9 +409,9 @@ export class NFTDrop extends StandardErc721<DropERC721> {
|
|||||||
* const quantity = 1; // how many unique NFTs you want to claim
|
* const quantity = 1; // how many unique NFTs you want to claim
|
||||||
*
|
*
|
||||||
* const tx = await contract.claimTo(address, quantity);
|
* const tx = await contract.claimTo(address, quantity);
|
||||||
* const receipt = tx.receipt; // the transaction receipt
|
* const receipt = tx[0].receipt; // the transaction receipt
|
||||||
* const claimedTokenId = tx.id; // the id of the NFT claimed
|
* const claimedTokenId = tx[0].id; // the id of the NFT claimed
|
||||||
* const claimedNFT = await tx.data(); // (optional) get the claimed NFT metadata
|
* const claimedNFT = await tx[0].data(); // (optional) get the claimed NFT metadata
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @param destinationAddress - Address you want to send the token to
|
* @param destinationAddress - Address you want to send the token to
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import { BigNumber, BigNumberish, CallOverrides, ethers } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "pack");
|
* const contract = await sdk.getContract("{{contract_address}}", "pack");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import {
|
|||||||
TransactionResult,
|
TransactionResult,
|
||||||
TransactionResultWithId,
|
TransactionResultWithId,
|
||||||
} from "../../core/types";
|
} from "../../core/types";
|
||||||
import { PaperCheckout } from "../../integrations/paper-xyz";
|
import { PaperCheckout } from "../../integrations/thirdweb-checkout";
|
||||||
import { DropErc721ContractSchema } from "../../schema/contracts/drop-erc721";
|
import { DropErc721ContractSchema } from "../../schema/contracts/drop-erc721";
|
||||||
import { SDKOptions } from "../../schema/sdk-options";
|
import { SDKOptions } from "../../schema/sdk-options";
|
||||||
import { ClaimOptions, UploadProgressEvent } from "../../types";
|
import { ClaimOptions, UploadProgressEvent } from "../../types";
|
||||||
@@ -47,7 +47,7 @@ import { BigNumber, BigNumberish, CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "signature-drop");
|
* const contract = await sdk.getContract("{{contract_address}}", "signature-drop");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { BigNumber, CallOverrides, Contract } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "split");
|
* const contract = await sdk.getContract("{{contract_address}}", "split");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { NetworkOrSignerOrProvider, TransactionResult } from "../../core/types";
|
|||||||
import { DropErc20ContractSchema } from "../../schema/contracts/drop-erc20";
|
import { DropErc20ContractSchema } from "../../schema/contracts/drop-erc20";
|
||||||
import { SDKOptions } from "../../schema/sdk-options";
|
import { SDKOptions } from "../../schema/sdk-options";
|
||||||
import { Amount, CurrencyValue } from "../../types";
|
import { Amount, CurrencyValue } from "../../types";
|
||||||
import type { DropERC20 } from "@thirdweb-dev/contracts-js";
|
import { PrebuiltTokenDrop } from "../../types/eips";
|
||||||
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC20.json";
|
import type ABI from "@thirdweb-dev/contracts-js/dist/abis/DropERC20.json";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { CallOverrides, constants } from "ethers";
|
import { CallOverrides, constants } from "ethers";
|
||||||
@@ -28,24 +28,27 @@ import { CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "token-drop");
|
* const contract = await sdk.getContract("{{contract_address}}", "token-drop");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class TokenDrop extends StandardErc20<DropERC20> {
|
export class TokenDrop extends StandardErc20<PrebuiltTokenDrop> {
|
||||||
static contractRoles = ["admin", "transfer"] as const;
|
static contractRoles = ["admin", "transfer"] as const;
|
||||||
|
|
||||||
public abi: typeof ABI;
|
public abi: typeof ABI;
|
||||||
public metadata: ContractMetadata<DropERC20, typeof DropErc20ContractSchema>;
|
public metadata: ContractMetadata<
|
||||||
|
PrebuiltTokenDrop,
|
||||||
|
typeof DropErc20ContractSchema
|
||||||
|
>;
|
||||||
public roles: ContractRoles<
|
public roles: ContractRoles<
|
||||||
DropERC20,
|
PrebuiltTokenDrop,
|
||||||
typeof TokenDrop.contractRoles[number]
|
typeof TokenDrop.contractRoles[number]
|
||||||
>;
|
>;
|
||||||
public encoder: ContractEncoder<DropERC20>;
|
public encoder: ContractEncoder<PrebuiltTokenDrop>;
|
||||||
public estimator: GasCostEstimator<DropERC20>;
|
public estimator: GasCostEstimator<PrebuiltTokenDrop>;
|
||||||
public sales: ContractPrimarySale<DropERC20>;
|
public sales: ContractPrimarySale<PrebuiltTokenDrop>;
|
||||||
public platformFees: ContractPlatformFee<DropERC20>;
|
public platformFees: ContractPlatformFee<PrebuiltTokenDrop>;
|
||||||
public events: ContractEvents<DropERC20>;
|
public events: ContractEvents<PrebuiltTokenDrop>;
|
||||||
/**
|
/**
|
||||||
* Configure claim conditions
|
* Configure claim conditions
|
||||||
* @remarks Define who can claim Tokens, when and how many.
|
* @remarks Define who can claim Tokens, when and how many.
|
||||||
@@ -68,11 +71,11 @@ export class TokenDrop extends StandardErc20<DropERC20> {
|
|||||||
* await contract.claimConditions.set(claimConditions);
|
* await contract.claimConditions.set(claimConditions);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public claimConditions: DropClaimConditions<DropERC20>;
|
public claimConditions: DropClaimConditions<PrebuiltTokenDrop>;
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
public interceptor: ContractInterceptor<DropERC20>;
|
public interceptor: ContractInterceptor<PrebuiltTokenDrop>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
network: NetworkOrSignerOrProvider,
|
network: NetworkOrSignerOrProvider,
|
||||||
@@ -81,7 +84,7 @@ export class TokenDrop extends StandardErc20<DropERC20> {
|
|||||||
options: SDKOptions = {},
|
options: SDKOptions = {},
|
||||||
abi: typeof ABI,
|
abi: typeof ABI,
|
||||||
chainId: number,
|
chainId: number,
|
||||||
contractWrapper = new ContractWrapper<DropERC20>(
|
contractWrapper = new ContractWrapper<PrebuiltTokenDrop>(
|
||||||
network,
|
network,
|
||||||
address,
|
address,
|
||||||
abi,
|
abi,
|
||||||
@@ -105,7 +108,7 @@ export class TokenDrop extends StandardErc20<DropERC20> {
|
|||||||
this.sales = new ContractPrimarySale(this.contractWrapper);
|
this.sales = new ContractPrimarySale(this.contractWrapper);
|
||||||
this.platformFees = new ContractPlatformFee(this.contractWrapper);
|
this.platformFees = new ContractPlatformFee(this.contractWrapper);
|
||||||
this.interceptor = new ContractInterceptor(this.contractWrapper);
|
this.interceptor = new ContractInterceptor(this.contractWrapper);
|
||||||
this.claimConditions = new DropClaimConditions<DropERC20>(
|
this.claimConditions = new DropClaimConditions<PrebuiltTokenDrop>(
|
||||||
this.contractWrapper,
|
this.contractWrapper,
|
||||||
this.metadata,
|
this.metadata,
|
||||||
this.storage,
|
this.storage,
|
||||||
@@ -210,7 +213,9 @@ export class TokenDrop extends StandardErc20<DropERC20> {
|
|||||||
amount: Amount,
|
amount: Amount,
|
||||||
checkERC20Allowance = true,
|
checkERC20Allowance = true,
|
||||||
): Promise<TransactionResult> {
|
): Promise<TransactionResult> {
|
||||||
return this.erc20.claimTo(destinationAddress, amount, checkERC20Allowance);
|
return this.erc20.claimTo(destinationAddress, amount, {
|
||||||
|
checkERC20Allowance,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import { CallOverrides, constants } from "ethers";
|
|||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk";
|
||||||
*
|
*
|
||||||
* const sdk = new ThirdwebSDK("{{chainName}}");
|
* const sdk = new ThirdwebSDK("{{chainName}}");
|
||||||
* const contract = sdk.getContract("{{contract_address}}", "token");
|
* const contract = await sdk.getContract("{{contract_address}}", "token");
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user