Compare commits
89
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e173636f4b | ||
|
|
8c6cdaa288 | ||
|
|
ad9b3febff | ||
|
|
94f49b1294 | ||
|
|
517e2a75e3 | ||
|
|
72692689e9 | ||
|
|
efc56fa580 | ||
|
|
564b17e760 | ||
|
|
b4507db963 | ||
|
|
f451da6395 | ||
|
|
ee47840767 | ||
|
|
bef97f72f4 | ||
|
|
3e87dd3ccb | ||
|
|
def42511ff | ||
|
|
c42545a647 | ||
|
|
6e20d1f21a | ||
|
|
e684d7e1ca | ||
|
|
f545a67e9f | ||
|
|
034a257442 | ||
|
|
1bfb91dbf3 | ||
|
|
5d95cbcdb2 | ||
|
|
639e535ed5 | ||
|
|
af3acc6b10 | ||
|
|
eca47763cd | ||
|
|
37b5bec897 | ||
|
|
48d91e4431 | ||
|
|
a20be881e3 | ||
|
|
47f8945325 | ||
|
|
1b0bf99da7 | ||
|
|
f03be398e0 | ||
|
|
27996cb4bc | ||
|
|
2eaa67acbe | ||
|
|
aafd7968df | ||
|
|
48797c7cf0 | ||
|
|
4edcb37100 | ||
|
|
83dcaf7058 | ||
|
|
b4e005be7f | ||
|
|
ccb7db4873 | ||
|
|
9151aa7dc8 | ||
|
|
5a01c537e3 | ||
|
|
f09c153ff7 | ||
|
|
15431621fd | ||
|
|
887af24450 | ||
|
|
15514f190a | ||
|
|
72589ec234 | ||
|
|
f8bceec10c | ||
|
|
7c0744a006 | ||
|
|
846022e2cf | ||
|
|
96bd92e724 | ||
|
|
c2b6d977ed | ||
|
|
7cb8e59be4 | ||
|
|
04a47e8971 | ||
|
|
8a6a97a3e9 | ||
|
|
612bcdd16f | ||
|
|
0ed77d2c9e | ||
|
|
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 |
@@ -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
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ runs:
|
|||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
shell: bash
|
shell: bash
|
||||||
run: yarn install
|
run: yarn install --frozen-lockfile
|
||||||
env:
|
env:
|
||||||
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
|
||||||
|
|||||||
@@ -15,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/**}"
|
||||||
|
|||||||
+2
-1
@@ -16,4 +16,5 @@ public/dist
|
|||||||
.yalc/
|
.yalc/
|
||||||
yalc.lock
|
yalc.lock
|
||||||
build/
|
build/
|
||||||
playwright-report/
|
playwright-report/
|
||||||
|
.vscode/
|
||||||
@@ -28,7 +28,6 @@
|
|||||||
| [/storage](./packages/storage) | Best in class decentralized storage SDK for Browser and Node | <a href="https://www.npmjs.com/package/@thirdweb-dev/storage"><img src="https://img.shields.io/npm/v/@thirdweb-dev/storage?color=red&label=npm&logo=npm" alt="npm version"/></a> |
|
| [/storage](./packages/storage) | Best in class decentralized storage SDK for Browser and Node | <a href="https://www.npmjs.com/package/@thirdweb-dev/storage"><img src="https://img.shields.io/npm/v/@thirdweb-dev/storage?color=red&label=npm&logo=npm" alt="npm version"/></a> |
|
||||||
| [/cli](./packages/cli) | Publish and deploy smart contracts without dealing with private keys | <a href="https://www.npmjs.com/package/thirdweb"><img src="https://img.shields.io/npm/v/thirdweb?color=red&label=npm&logo=npm" alt="npm version"/></a> |
|
| [/cli](./packages/cli) | Publish and deploy smart contracts without dealing with private keys | <a href="https://www.npmjs.com/package/thirdweb"><img src="https://img.shields.io/npm/v/thirdweb?color=red&label=npm&logo=npm" alt="npm version"/></a> |
|
||||||
|
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Visit [https://portal.thirdweb.com/](https://portal.thirdweb.com/) to view the full documentation.
|
Visit [https://portal.thirdweb.com/](https://portal.thirdweb.com/) to view the full documentation.
|
||||||
|
|||||||
+3
-3
@@ -15,8 +15,8 @@
|
|||||||
"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",
|
||||||
@@ -28,7 +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/*"
|
||||||
},
|
},
|
||||||
"packageManager": "[email protected]",
|
"packageManager": "[email protected]",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,43 @@
|
|||||||
# @thirdweb-dev/auth
|
# @thirdweb-dev/auth
|
||||||
|
|
||||||
|
## 2.0.36
|
||||||
|
|
||||||
|
## 2.0.35
|
||||||
|
|
||||||
|
## 2.0.34
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#425](https://github.com/thirdweb-dev/js/pull/425) [`f545a67`](https://github.com/thirdweb-dev/js/commit/f545a67e9fb597d27bb39ca515d24d306fbb121a) Thanks [@adam-maj](https://github.com/adam-maj)! - Add sameSite none and include credentials
|
||||||
|
|
||||||
|
## 2.0.33
|
||||||
|
|
||||||
|
## 2.0.32
|
||||||
|
|
||||||
|
## 2.0.31
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#397](https://github.com/thirdweb-dev/js/pull/397) [`72589ec`](https://github.com/thirdweb-dev/js/commit/72589ec234d86939b67b0ca8b3b789f2e9c54cc2) Thanks [@adam-maj](https://github.com/adam-maj)! - Call user callback in getUser
|
||||||
|
|
||||||
|
## 2.0.30
|
||||||
|
|
||||||
|
## 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
|
## 2.0.21
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/auth",
|
"name": "@thirdweb-dev/auth",
|
||||||
"version": "2.0.21",
|
"version": "2.0.36",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./next": {
|
"./next": {
|
||||||
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"eslint-plugin-inclusive-language": "^2.2.0",
|
"eslint-plugin-inclusive-language": "^2.2.0",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"eslint-plugin-tsdoc": "^0.2.16",
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"ethers": "^5.7.1",
|
"ethers": "^5.7.2",
|
||||||
"express": "^4.18.1",
|
"express": "^4.18.1",
|
||||||
"next": "^12.2.0",
|
"next": "^12.2.0",
|
||||||
"next-auth": "^4.10.3",
|
"next-auth": "^4.10.3",
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export default async function handler(
|
|||||||
path: "/",
|
path: "/",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "none",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -40,11 +40,11 @@ export function ThirdwebNextAuth(cfg: ThirdwebNextAuthConfig) {
|
|||||||
path: "/",
|
path: "/",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "none",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
return { address };
|
return { id: address, address };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,13 @@ export function ThirdwebAuth(cfg: ThirdwebAuthConfig) {
|
|||||||
if (token) {
|
if (token) {
|
||||||
try {
|
try {
|
||||||
const address = await sdk.auth.authenticate(domain, token);
|
const address = await sdk.auth.authenticate(domain, token);
|
||||||
user = { address };
|
|
||||||
|
let data = {};
|
||||||
|
if (ctx.callbacks?.user) {
|
||||||
|
data = await ctx.callbacks.user(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
user = { ...data, address };
|
||||||
} catch {
|
} catch {
|
||||||
// No-op
|
// No-op
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export default async function handler(
|
|||||||
path: "/",
|
path: "/",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "none",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,13 @@ export function ThirdwebAuth(cfg: ThirdwebAuthConfig) {
|
|||||||
if (token) {
|
if (token) {
|
||||||
try {
|
try {
|
||||||
const address = await sdk.auth.authenticate(domain, token);
|
const address = await sdk.auth.authenticate(domain, token);
|
||||||
user = { address };
|
|
||||||
|
let data = {};
|
||||||
|
if (ctx.callbacks?.user) {
|
||||||
|
data = await ctx.callbacks.user(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
user = { ...data, address };
|
||||||
} catch {
|
} catch {
|
||||||
// No-op
|
// No-op
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export default async function handler(
|
|||||||
path: "/",
|
path: "/",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "none",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,140 @@
|
|||||||
# thirdweb
|
# thirdweb
|
||||||
|
|
||||||
|
## 0.9.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`8c6cdaa`](https://github.com/thirdweb-dev/js/commit/8c6cdaa2887fb2cc40d3ee6991233d195d103805)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.6
|
||||||
|
|
||||||
|
## 0.9.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#444](https://github.com/thirdweb-dev/js/pull/444) [`94f49b1`](https://github.com/thirdweb-dev/js/commit/94f49b1294bc0208171b16ed413cbb44644af017) Thanks [@adam-maj](https://github.com/adam-maj)! - Add changeset
|
||||||
|
|
||||||
|
## 0.9.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`efc56fa`](https://github.com/thirdweb-dev/js/commit/efc56fa5802490ac8ef50037658d046afd89e9a1)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.5
|
||||||
|
|
||||||
|
## 0.9.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#430](https://github.com/thirdweb-dev/js/pull/430) [`e684d7e`](https://github.com/thirdweb-dev/js/commit/e684d7e1ca16f633bce8698529d16bf60c264aa4) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix uploading contracts with special characters in the comments
|
||||||
|
|
||||||
|
- [#435](https://github.com/thirdweb-dev/js/pull/435) [`bef97f7`](https://github.com/thirdweb-dev/js/commit/bef97f72f4860596b7b70b05e67fcadf2c9a012e) Thanks [@adam-maj](https://github.com/adam-maj)! - Make solc default backup compilation
|
||||||
|
|
||||||
|
- [#432](https://github.com/thirdweb-dev/js/pull/432) [`3e87dd3`](https://github.com/thirdweb-dev/js/commit/3e87dd3ccb04a2b73437357c939a251e83b783b2) Thanks [@adam-maj](https://github.com/adam-maj)! - Display file name on duplicate contract names
|
||||||
|
|
||||||
|
- [#431](https://github.com/thirdweb-dev/js/pull/431) [`c42545a`](https://github.com/thirdweb-dev/js/commit/c42545a64725492136025fa1dcdb4d46ba674a30) Thanks [@adam-maj](https://github.com/adam-maj)! - Add changeset
|
||||||
|
|
||||||
|
- [#428](https://github.com/thirdweb-dev/js/pull/428) [`6e20d1f`](https://github.com/thirdweb-dev/js/commit/6e20d1f21a622f102e94b956f700d0871c0dc779) Thanks [@adam-maj](https://github.com/adam-maj)! - Update CLI to enable create contract inside contracts project
|
||||||
|
|
||||||
|
- Updated dependencies [[`f451da6`](https://github.com/thirdweb-dev/js/commit/f451da6395689a5f89800ee63f34b6175b61f703), [`af3acc6`](https://github.com/thirdweb-dev/js/commit/af3acc6b10751b840e56aef6400da5eea6040df2), [`1bfb91d`](https://github.com/thirdweb-dev/js/commit/1bfb91dbf3a39160c987a425813ac5dbb84703ad), [`ee47840`](https://github.com/thirdweb-dev/js/commit/ee478407673b0416e0c1cfe2be11bd6963395348), [`def4251`](https://github.com/thirdweb-dev/js/commit/def42511ff5a20d83f9094164dafb87e412571b5), [`034a257`](https://github.com/thirdweb-dev/js/commit/034a257442314c67729f7bafcbe3740cff33fa32), [`eca4776`](https://github.com/thirdweb-dev/js/commit/eca47763cd89cc3b7aa57b542971837987540b55), [`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.4
|
||||||
|
|
||||||
|
## 0.9.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#415](https://github.com/thirdweb-dev/js/pull/415) [`48d91e4`](https://github.com/thirdweb-dev/js/commit/48d91e4431a3740d0f98f730ed5abf5b287f92c1) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix mappings for prebuilts redirect on deploy
|
||||||
|
|
||||||
|
## 0.9.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#403](https://github.com/thirdweb-dev/js/pull/403) [`27996cb`](https://github.com/thirdweb-dev/js/commit/27996cb4bc6f054f45b0a66b0a3aca732e0ef610) Thanks [@avneesh0612](https://github.com/avneesh0612)! - Add CLI Support for solana with --solana flag on create command
|
||||||
|
|
||||||
|
- [#283](https://github.com/thirdweb-dev/js/pull/283) [`2eaa67a`](https://github.com/thirdweb-dev/js/commit/2eaa67acbe21464e7715d0b696afdc024460a44d) Thanks [@adam-maj](https://github.com/adam-maj)! - add capability to deploy apps
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#413](https://github.com/thirdweb-dev/js/pull/413) [`1b0bf99`](https://github.com/thirdweb-dev/js/commit/1b0bf99da796df88ff307dd004cdaf239fb2b1ba) Thanks [@furqanrydhan](https://github.com/furqanrydhan)! - small interface tweaks
|
||||||
|
|
||||||
|
- Updated dependencies [[`48797c7`](https://github.com/thirdweb-dev/js/commit/48797c7cf0695965e33eb6bf602be4652f7085a8), [`83dcaf7`](https://github.com/thirdweb-dev/js/commit/83dcaf70584af8c5cdf0427f9fc1ba82d89f0887), [`f03be39`](https://github.com/thirdweb-dev/js/commit/f03be398e0d7b75c9c5b4fb643f35903e89a17e7), [`2eaa67a`](https://github.com/thirdweb-dev/js/commit/2eaa67acbe21464e7715d0b696afdc024460a44d), [`47f8945`](https://github.com/thirdweb-dev/js/commit/47f8945325447874b1ace0359919c1d54fd55436)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.3
|
||||||
|
|
||||||
|
## 0.8.18
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`ccb7db4`](https://github.com/thirdweb-dev/js/commit/ccb7db48739b8dddcb2c032b3b6e3e5200485715), [`9151aa7`](https://github.com/thirdweb-dev/js/commit/9151aa7dc80754a7aa4fd3f6ce0207bccbb6451f), [`5a01c53`](https://github.com/thirdweb-dev/js/commit/5a01c537e30bd7ef562aad1012413990de6faedf)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.2
|
||||||
|
|
||||||
|
## 0.8.17
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`15514f1`](https://github.com/thirdweb-dev/js/commit/15514f190a844d809ae5b1edb580aab46a682485), [`7c0744a`](https://github.com/thirdweb-dev/js/commit/7c0744a006e78987ad8b271b2c64f4bac7759510), [`f8bceec`](https://github.com/thirdweb-dev/js/commit/f8bceec10c60b30dc3d6f45926e2a9e018202578), [`887af24`](https://github.com/thirdweb-dev/js/commit/887af24450e316c2ea390cd49c0563cebe793c0f), [`96bd92e`](https://github.com/thirdweb-dev/js/commit/96bd92e724ec7d880d23348071b26ab8c21dd868)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.1
|
||||||
|
|
||||||
|
## 0.8.16
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`7cb8e59`](https://github.com/thirdweb-dev/js/commit/7cb8e59be48dc923316eb36ab43a1bef7364f6b1), [`0ed77d2`](https://github.com/thirdweb-dev/js/commit/0ed77d2c9e7526444ef660aab82a950865234aa6), [`04a47e8`](https://github.com/thirdweb-dev/js/commit/04a47e8971d28da2532ebd9db824eeb459c17bd4)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.0
|
||||||
|
|
||||||
|
## 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
|
## 0.8.7
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
export const CREATE_MESSAGES = {
|
export const CREATE_MESSAGES = {
|
||||||
typeOfProject: "What type of project do you want to create?",
|
typeOfProject: "What type of project do you want to create?",
|
||||||
projectName: "What is your project named?",
|
projectName: "What is your project named?",
|
||||||
|
contractName: "What will be the name of your new smart contract?",
|
||||||
|
chain: "Which blockchain do you want to use?",
|
||||||
framework: "What framework do you want to use?",
|
framework: "What framework do you want to use?",
|
||||||
language: "What language do you want to use?",
|
language: "What language do you want to use?",
|
||||||
contract: "What type of contract do you want to start from?",
|
contract: "What type of contract do you want to start from?",
|
||||||
@@ -9,5 +11,5 @@ export const CREATE_MESSAGES = {
|
|||||||
|
|
||||||
export const ERROR_MESSAGES = {
|
export const ERROR_MESSAGES = {
|
||||||
noConfiguration:
|
noConfiguration:
|
||||||
"Failed to find a supported project configuration file in current directory",
|
"No contract project configuration file found in current directory",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { CREATE_MESSAGES } from "../constants/constants";
|
|||||||
import { prepareEnvironment } from "@gmrchk/cli-testing-library";
|
import { prepareEnvironment } from "@gmrchk/cli-testing-library";
|
||||||
|
|
||||||
// this creates an app, can take some time that's fine
|
// this creates an app, can take some time that's fine
|
||||||
jest.setTimeout(120_000);
|
jest.setTimeout(150_000);
|
||||||
|
|
||||||
describe("npx thirdweb create", () => {
|
describe("npx thirdweb create", () => {
|
||||||
it("should create app (CRA) successfully", async () => {
|
it("should create app (CRA) successfully", async () => {
|
||||||
@@ -16,6 +16,8 @@ describe("npx thirdweb create", () => {
|
|||||||
await pressKey("enter");
|
await pressKey("enter");
|
||||||
await waitForText(CREATE_MESSAGES.projectName);
|
await waitForText(CREATE_MESSAGES.projectName);
|
||||||
await pressKey("enter");
|
await pressKey("enter");
|
||||||
|
await waitForText(CREATE_MESSAGES.chain);
|
||||||
|
await pressKey("enter");
|
||||||
await waitForText(CREATE_MESSAGES.framework);
|
await waitForText(CREATE_MESSAGES.framework);
|
||||||
// select CRA
|
// select CRA
|
||||||
await pressKey("arrowDown");
|
await pressKey("arrowDown");
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ describe("npx thirdweb deploy", () => {
|
|||||||
`${path}/BasicContract.sol`,
|
`${path}/BasicContract.sol`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { waitForText, waitForFinish, getExitCode, writeText, getStdout } =
|
const { waitForText, waitForFinish, getExitCode, writeText, getStderr } =
|
||||||
await spawn("node", "./dist/cli/index.js deploy");
|
await spawn("node", "./dist/cli/index.js deploy --contract");
|
||||||
|
|
||||||
expect(await exists("BasicContract.sol")).toEqual(true);
|
expect(await exists("BasicContract.sol")).toEqual(true);
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ describe("npx thirdweb deploy", () => {
|
|||||||
// wait for program to finish
|
// wait for program to finish
|
||||||
await waitForFinish();
|
await waitForFinish();
|
||||||
|
|
||||||
expect(getStdout().at(-1)).toContain(
|
expect(getStderr().at(-1)).toContain(
|
||||||
"https://thirdweb.com/contracts/deploy/",
|
"https://thirdweb.com/contracts/deploy/",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ describe("npx thirdweb detect", () => {
|
|||||||
await create.waitForText(CREATE_MESSAGES.framework);
|
await create.waitForText(CREATE_MESSAGES.framework);
|
||||||
// select hardhat
|
// select hardhat
|
||||||
await create.pressKey("enter");
|
await create.pressKey("enter");
|
||||||
|
await create.waitForText(CREATE_MESSAGES.contractName);
|
||||||
|
// set contract name
|
||||||
|
await create.writeText("Contract");
|
||||||
|
await create.pressKey("enter");
|
||||||
await create.waitForText(CREATE_MESSAGES.contract);
|
await create.waitForText(CREATE_MESSAGES.contract);
|
||||||
// select ERC721
|
// select ERC721
|
||||||
await create.pressKey("arrowDown");
|
await create.pressKey("arrowDown");
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe("npx thirdweb release", () => {
|
|||||||
`${path}/BasicContract.sol`,
|
`${path}/BasicContract.sol`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const { waitForText, waitForFinish, getExitCode, writeText, getStdout } =
|
const { waitForText, waitForFinish, getExitCode, writeText, getStderr } =
|
||||||
await spawn("node", "./dist/cli/index.js release");
|
await spawn("node", "./dist/cli/index.js release");
|
||||||
|
|
||||||
expect(await exists("BasicContract.sol")).toEqual(true);
|
expect(await exists("BasicContract.sol")).toEqual(true);
|
||||||
@@ -26,7 +26,7 @@ describe("npx thirdweb release", () => {
|
|||||||
// wait for program to finish
|
// wait for program to finish
|
||||||
await waitForFinish();
|
await waitForFinish();
|
||||||
|
|
||||||
expect(getStdout().at(-1)).toContain(
|
expect(getStderr().at(-1)).toContain(
|
||||||
"https://thirdweb.com/contracts/release/",
|
"https://thirdweb.com/contracts/release/",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "thirdweb",
|
"name": "thirdweb",
|
||||||
"main": "dist/cli/index.js",
|
"main": "dist/cli/index.js",
|
||||||
"version": "0.8.7",
|
"version": "0.9.5",
|
||||||
"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",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gmrchk/cli-testing-library": "^0.1.2",
|
"@gmrchk/cli-testing-library": "^0.1.2",
|
||||||
"@types/async-retry": "1.3.0",
|
"@types/async-retry": "^1.3.0",
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
"@types/inquirer": "^8.2.1",
|
"@types/inquirer": "^8.2.1",
|
||||||
"@types/jest": "^29.0.0",
|
"@types/jest": "^29.0.0",
|
||||||
@@ -33,13 +33,13 @@
|
|||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"commander": "^9.1.0",
|
"commander": "^9.1.0",
|
||||||
"enquirer": "^2.3.6",
|
"enquirer": "^2.3.6",
|
||||||
"ethers": "^5.7.0",
|
"ethers": "^5.7.2",
|
||||||
"got": "11.8.5",
|
"got": "11.8.5",
|
||||||
"inquirer": "^8.2.3",
|
"inquirer": "^8.2.3",
|
||||||
"open": "^8.4.0",
|
"open": "^8.4.0",
|
||||||
"prompts": "^2.4.2",
|
"prompts": "^2.4.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"solc": "0.8.13",
|
"solc": "0.8.17",
|
||||||
"tar": "^6.1.11",
|
"tar": "^6.1.11",
|
||||||
"tslog": "^3.3.3",
|
"tslog": "^3.3.3",
|
||||||
"update-notifier": "^6.0.2",
|
"update-notifier": "^6.0.2",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { processProject } from "../common/processor";
|
|||||||
import { cliVersion, pkg } from "../constants/urls";
|
import { cliVersion, pkg } from "../constants/urls";
|
||||||
import { info, logger } from "../core/helpers/logger";
|
import { info, logger } from "../core/helpers/logger";
|
||||||
import { twCreate } from "../create/command";
|
import { twCreate } from "../create/command";
|
||||||
import generateDashboardUrl from "../helpers/generate-dashboard-url";
|
import { deploy } from "../deploy";
|
||||||
import { upload } from "../storage/command";
|
import { upload } from "../storage/command";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
@@ -40,34 +40,40 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
.version(cliVersion, "-v, --version");
|
.version(cliVersion, "-v, --version");
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("create [projectPath]")
|
.command("create [projectType] [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/",
|
||||||
)
|
)
|
||||||
.option("--app", `Create a web3 app.`)
|
.option("--app", "Create a web3 app.")
|
||||||
.option("--contract", `Create a web3 contract project`)
|
.option("--contract", "Create a web3 contract project")
|
||||||
.option("--ts, --typescript", `Initialize as a TypeScript project.`)
|
.option("--ts, --typescript", "Initialize as a TypeScript project.")
|
||||||
.option("--js, --javascript", `Initialize as a JavaScript project.`)
|
.option("--js, --javascript", "Initialize as a JavaScript project.")
|
||||||
.option("--forge", `Initialize as a Forge project.`)
|
.option("--forge", "Initialize as a Forge project.")
|
||||||
.option("--hardhat", `Initialize as a Hardhat project.`)
|
.option("--hardhat", "Initialize as a Hardhat project.")
|
||||||
.option("--cra", `Initialize as a Create React App project.`)
|
.option("--cra", "Initialize as a Create React App project.")
|
||||||
.option("--next", `Initialize as a Next.js project.`)
|
.option("--next", "Initialize as a Next.js project.")
|
||||||
.option("--vite", `Initialize as a Vite project.`)
|
.option("--vite", "Initialize as a Vite project.")
|
||||||
.option(
|
.option(
|
||||||
"--use-npm",
|
"--use-npm",
|
||||||
`Explicitly tell the CLI to bootstrap the app using npm`,
|
"Explicitly tell the CLI to bootstrap the app using npm",
|
||||||
)
|
)
|
||||||
.option(
|
.option(
|
||||||
"--use-pnpm",
|
"--use-pnpm",
|
||||||
`Explicitly tell the CLI to bootstrap the app using pnpm`,
|
"Explicitly tell the CLI to bootstrap the app using pnpm",
|
||||||
)
|
)
|
||||||
.option("--framework [name]", `The preferred framework.`)
|
.option("--framework [name]", "The preferred framework.")
|
||||||
|
.option("--solana", "Initialize as a Solana project.")
|
||||||
|
.option("--evm", "Initialize as an Ethereum project.")
|
||||||
.option(
|
.option(
|
||||||
"-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 (path, options) => {
|
.option(
|
||||||
await twCreate(path, options);
|
"-c, --contract-name [name]",
|
||||||
|
"Name of the new smart contract to create",
|
||||||
|
)
|
||||||
|
.action(async (type, path, options) => {
|
||||||
|
await twCreate(type, path, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@@ -87,39 +93,33 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
.option("--dry-run", "dry run (skip actually publishing)")
|
.option("--dry-run", "dry run (skip actually publishing)")
|
||||||
.option("-d, --debug", "show debug logs")
|
.option("-d, --debug", "show debug logs")
|
||||||
.option("--ci", "Continuous Integration mode")
|
.option("--ci", "Continuous Integration mode")
|
||||||
|
.option(
|
||||||
|
"--dist-path [distPath]",
|
||||||
|
"Path to the dist folder where the HTML based App is",
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
"-n, --name [name]",
|
"-n, --name [name]",
|
||||||
"Name of the pre-built or released contract (such as nft-drop)",
|
"Name of the pre-built or released contract (such as nft-drop)",
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
"-f, --file [name]",
|
||||||
|
"Filter for contract files that contain this file name",
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"-cn, --contract-name [name]",
|
||||||
|
"Filter for contracts that contain this contract name",
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
"-cv, --contract-version [version]",
|
"-cv, --contract-version [version]",
|
||||||
"Version of the released contract",
|
"Version of the released contract",
|
||||||
)
|
)
|
||||||
|
.option("--app", "Deploy a web app to decentralized storage")
|
||||||
|
.option("--contract", "Deploy a smart contract to blockchains")
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
if (options.name) {
|
const url = await deploy(options);
|
||||||
const url = generateDashboardUrl(options.name, options.contractVersion);
|
if (url) {
|
||||||
|
open(url);
|
||||||
if (!url) {
|
|
||||||
logger.error(
|
|
||||||
chalk.red(
|
|
||||||
`Could not find a contract named ${options.name} ${
|
|
||||||
options.contractVersion || ""
|
|
||||||
}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
info(`Open this link to deploy your contract:`);
|
|
||||||
logger.info(chalk.blueBright(url));
|
|
||||||
open(url.toString());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = await processProject(options, "deploy");
|
|
||||||
info(`Open this link to deploy your contracts:`);
|
|
||||||
logger.info(chalk.blueBright(url.toString()));
|
|
||||||
open(url.toString());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@@ -128,13 +128,24 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"Release your protocol so other devs can deploy them and unlock SDKs, Dashboards and Analytics",
|
"Release your protocol so other devs can deploy them and unlock SDKs, Dashboards and Analytics",
|
||||||
)
|
)
|
||||||
.option("-p, --path <project-path>", "path to project", ".")
|
.option("-p, --path <project-path>", "path to project", ".")
|
||||||
|
.option(
|
||||||
|
"-f, --file [name]",
|
||||||
|
"Filter for contract files that contain the file name",
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
"-cn, --contract-name [name]",
|
||||||
|
"Filter for contracts that contain this contract name",
|
||||||
|
)
|
||||||
.option("--dry-run", "dry run (skip actually publishing)")
|
.option("--dry-run", "dry run (skip actually publishing)")
|
||||||
.option("-d, --debug", "show debug logs")
|
.option("-d, --debug", "show debug logs")
|
||||||
.option("--ci", "Continuous Integration mode")
|
.option("--ci", "Continuous Integration mode")
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
const url = await processProject(options, "release");
|
const url = await processProject(options, "release");
|
||||||
info(`Open this link to release your contracts:`);
|
info(
|
||||||
logger.info(chalk.blueBright(url.toString()));
|
`Open this link to release your contracts: ${chalk.blueBright(
|
||||||
|
url.toString(),
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
open(url.toString());
|
open(url.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -144,13 +155,35 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
.argument("[upload]", "path to file or directory to upload")
|
.argument("[upload]", "path to file or directory to upload")
|
||||||
.action(async (path) => {
|
.action(async (path) => {
|
||||||
const storage = new ThirdwebStorage();
|
const storage = new ThirdwebStorage();
|
||||||
const uri = await upload(storage, path);
|
try {
|
||||||
info(`Files stored at the following IPFS URI:`);
|
const uri = await upload(storage, path);
|
||||||
logger.info(chalk.blueBright(uri.toString()));
|
info(
|
||||||
|
`Files stored at the following IPFS URI: ${chalk.blueBright(
|
||||||
|
uri.toString(),
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
|
||||||
const url = storage.resolveScheme(uri);
|
const url = storage.resolveScheme(uri);
|
||||||
info(`Open this link to view your upload:`);
|
info(
|
||||||
logger.info(chalk.blueBright(url.toString()));
|
`Open this link to view your upload: ${chalk.blueBright(
|
||||||
|
url.toString(),
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (
|
||||||
|
err.toString() === "No files detected in specified directory" ||
|
||||||
|
err.toString() === "Invalid path provided" ||
|
||||||
|
err.toString() === "No path provided"
|
||||||
|
) {
|
||||||
|
logger.error(
|
||||||
|
chalk.redBright(
|
||||||
|
"Please specify a valid file or directory to upload",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logger.error(chalk.redBright("Failed to upload files"), err);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ export async function processProject(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let compiledResult;
|
let compiledResult: { contracts: ContractPayload[] };
|
||||||
const compileLoader = spinner("Compiling project...");
|
const compileLoader = spinner("Compiling project...");
|
||||||
try {
|
try {
|
||||||
compiledResult = await build(projectPath, projectType);
|
compiledResult = await build(projectPath, projectType);
|
||||||
@@ -106,10 +106,47 @@ export async function processProject(
|
|||||||
if (options.ci) {
|
if (options.ci) {
|
||||||
selectedContracts = compiledResult.contracts;
|
selectedContracts = compiledResult.contracts;
|
||||||
} else {
|
} else {
|
||||||
const choices = compiledResult.contracts.map((c) => ({
|
const filtered = compiledResult.contracts
|
||||||
name: c.name,
|
.filter((c) => {
|
||||||
value: c,
|
if (typeof options.file === "string" && options.file.length > 0) {
|
||||||
}));
|
return c.fileName.includes(options.file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.filter((c) => {
|
||||||
|
if (
|
||||||
|
typeof options.contractName === "string" &&
|
||||||
|
options.contractName.length > 0
|
||||||
|
) {
|
||||||
|
return c.name.includes(options.contractName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filtered.length === 0) {
|
||||||
|
logger.error(`No contracts found matching the specified filters.`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const choices = filtered.map((c) => {
|
||||||
|
if (
|
||||||
|
compiledResult.contracts.filter(
|
||||||
|
(other: ContractPayload) => other.name === c.name,
|
||||||
|
).length > 1
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
name: `${c.name} - ${chalk.gray(c.fileName)}`,
|
||||||
|
value: c,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: c.name,
|
||||||
|
value: c,
|
||||||
|
};
|
||||||
|
});
|
||||||
const prompt = createContractsPrompt(
|
const prompt = createContractsPrompt(
|
||||||
choices,
|
choices,
|
||||||
`Choose which contract(s) to ${command}`,
|
`Choose which contract(s) to ${command}`,
|
||||||
@@ -164,7 +201,7 @@ export async function processProject(
|
|||||||
const metadataURIs = await Promise.all(
|
const metadataURIs = await Promise.all(
|
||||||
selectedContracts.map(async (c) => {
|
selectedContracts.map(async (c) => {
|
||||||
logger.debug(`Uploading ${c.name}...`);
|
logger.debug(`Uploading ${c.name}...`);
|
||||||
return await storage.upload(JSON.parse(c.metadata), {
|
return await storage.upload(JSON.parse(JSON.stringify(c.metadata)), {
|
||||||
uploadWithoutDirectory: true,
|
uploadWithoutDirectory: true,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ export class BrownieBuilder extends BaseBuilder {
|
|||||||
metadata: {},
|
metadata: {},
|
||||||
bytecode,
|
bytecode,
|
||||||
sources: [], // TODO
|
sources: [], // TODO
|
||||||
|
fileName: "", // TODO
|
||||||
name: contractName,
|
name: contractName,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -88,6 +88,11 @@ export class FoundryBuilder extends BaseBuilder {
|
|||||||
})
|
})
|
||||||
.filter((path) => path !== undefined) as string[];
|
.filter((path) => path !== undefined) as string[];
|
||||||
|
|
||||||
|
const fileNames = Object.keys(
|
||||||
|
parsedMetadata?.settings?.compilationTarget || {},
|
||||||
|
);
|
||||||
|
const fileName = fileNames.length > 0 ? fileNames[0] : "";
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.shouldProcessContract(
|
this.shouldProcessContract(
|
||||||
contractInfo.abi,
|
contractInfo.abi,
|
||||||
@@ -99,6 +104,7 @@ export class FoundryBuilder extends BaseBuilder {
|
|||||||
name: contractName,
|
name: contractName,
|
||||||
metadata,
|
metadata,
|
||||||
bytecode,
|
bytecode,
|
||||||
|
fileName,
|
||||||
sources,
|
sources,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export class HardhatBuilder extends BaseBuilder {
|
|||||||
//the hardhat extractor **logs out** the runtime config of hardhat, we take that stdout and parse it
|
//the hardhat extractor **logs out** the runtime config of hardhat, we take that stdout and parse it
|
||||||
const stringifiedConfig = (
|
const stringifiedConfig = (
|
||||||
await execute(
|
await execute(
|
||||||
`npx hardhat run ${configExtractorScriptPath} --no-compile`,
|
`npx hardhat run "${configExtractorScriptPath}" --no-compile`,
|
||||||
options.projectPath,
|
options.projectPath,
|
||||||
)
|
)
|
||||||
).stdout;
|
).stdout;
|
||||||
@@ -123,11 +123,17 @@ export class HardhatBuilder extends BaseBuilder {
|
|||||||
})
|
})
|
||||||
.filter((path) => path !== undefined) as string[];
|
.filter((path) => path !== undefined) as string[];
|
||||||
|
|
||||||
|
const fileNames = Object.keys(
|
||||||
|
meta?.settings?.compilationTarget || {},
|
||||||
|
);
|
||||||
|
const fileName = fileNames.length > 0 ? fileNames[0] : "";
|
||||||
|
|
||||||
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
||||||
contracts.push({
|
contracts.push({
|
||||||
metadata,
|
metadata,
|
||||||
bytecode,
|
bytecode,
|
||||||
name: contractName,
|
name: contractName,
|
||||||
|
fileName,
|
||||||
sources,
|
sources,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,11 +140,17 @@ export class SolcBuilder extends BaseBuilder {
|
|||||||
})
|
})
|
||||||
.filter((path) => path !== undefined) as string[];
|
.filter((path) => path !== undefined) as string[];
|
||||||
|
|
||||||
|
const fileNames = Object.keys(
|
||||||
|
parsedMetadata?.settings?.compilationTarget || {},
|
||||||
|
);
|
||||||
|
const fileName = fileNames.length > 0 ? fileNames[0] : "";
|
||||||
|
|
||||||
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
||||||
contracts.push({
|
contracts.push({
|
||||||
metadata,
|
metadata,
|
||||||
bytecode,
|
bytecode,
|
||||||
name: contractName,
|
name: contractName,
|
||||||
|
fileName,
|
||||||
sources: _sources,
|
sources: _sources,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,11 +72,18 @@ export class TruffleBuilder extends BaseBuilder {
|
|||||||
return undefined;
|
return undefined;
|
||||||
})
|
})
|
||||||
.filter((path) => path !== undefined) as string[];
|
.filter((path) => path !== undefined) as string[];
|
||||||
|
|
||||||
|
const fileNames = Object.keys(
|
||||||
|
parsedMetadata?.settings?.compilationTarget || {},
|
||||||
|
);
|
||||||
|
const fileName = fileNames.length > 0 ? fileNames[0] : "";
|
||||||
|
|
||||||
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
if (this.shouldProcessContract(abi, deployedBytecode, contractName)) {
|
||||||
contracts.push({
|
contracts.push({
|
||||||
metadata,
|
metadata,
|
||||||
bytecode,
|
bytecode,
|
||||||
name: contractName,
|
name: contractName,
|
||||||
|
fileName,
|
||||||
sources,
|
sources,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export default async function detect(
|
|||||||
name: "continue",
|
name: "continue",
|
||||||
message:
|
message:
|
||||||
"Do you want to continue and compile this project with solc instead?",
|
"Do you want to continue and compile this project with solc instead?",
|
||||||
|
initial: true,
|
||||||
});
|
});
|
||||||
const shouldCompile = await prompt.run();
|
const shouldCompile = await prompt.run();
|
||||||
if (!shouldCompile) {
|
if (!shouldCompile) {
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { ProjectType } from "../types/ProjectType";
|
||||||
|
import { Detector } from "./detector";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
|
export default class NPMDetector implements Detector {
|
||||||
|
public projectType: ProjectType = "npm";
|
||||||
|
|
||||||
|
public matches(path: string): boolean {
|
||||||
|
return existsSync(path + "/package-lock.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { ProjectType } from "../types/ProjectType";
|
||||||
|
import { Detector } from "./detector";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
|
export default class ViteDetector implements Detector {
|
||||||
|
public projectType: ProjectType = "vite";
|
||||||
|
|
||||||
|
public matches(path: string): boolean {
|
||||||
|
return (
|
||||||
|
existsSync(path + "/vite.config.js") ||
|
||||||
|
existsSync(path + "/vite.config.ts")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { ProjectType } from "../types/ProjectType";
|
||||||
|
import { Detector } from "./detector";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
|
export default class YarnDetector implements Detector {
|
||||||
|
public projectType: ProjectType = "yarn";
|
||||||
|
|
||||||
|
public matches(path: string): boolean {
|
||||||
|
return existsSync(path + "/yarn.lock");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,11 @@ export interface ContractPayload {
|
|||||||
*/
|
*/
|
||||||
metadata: any;
|
metadata: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The file name of the original compiled file
|
||||||
|
*/
|
||||||
|
fileName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The source file paths
|
* The source file paths
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,4 +4,10 @@ export type ProjectType =
|
|||||||
| "hardhat"
|
| "hardhat"
|
||||||
| "truffle"
|
| "truffle"
|
||||||
| "solc"
|
| "solc"
|
||||||
|
| "vite"
|
||||||
|
| "next"
|
||||||
|
| "cra"
|
||||||
|
| "spa-webapp"
|
||||||
|
| "yarn"
|
||||||
|
| "npm"
|
||||||
| "none";
|
| "none";
|
||||||
|
|||||||
+262
-131
@@ -2,60 +2,82 @@
|
|||||||
|
|
||||||
/* eslint-disable import/no-extraneous-dependencies */
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import { CREATE_MESSAGES } from "../../constants/constants";
|
import { CREATE_MESSAGES } from "../../constants/constants";
|
||||||
|
import detect from "../core/detection/detect";
|
||||||
import { DownloadError, createApp } from "./helpers/create-app";
|
import { DownloadError, createApp } from "./helpers/create-app";
|
||||||
import { createContract } from "./helpers/create-contract";
|
import { createContractProject } from "./helpers/create-contract";
|
||||||
import { getPkgManager } from "./helpers/get-pkg-manager";
|
import { getPkgManager } from "./helpers/get-pkg-manager";
|
||||||
import { validateNpmName } from "./helpers/validate-pkg";
|
import { validateNpmName } from "./helpers/validate-pkg";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import prompts from "prompts";
|
import prompts from "prompts";
|
||||||
|
|
||||||
let projectType: string = "";
|
let contractName: string = "";
|
||||||
let projectPath: string = "";
|
let projectPath: string = "";
|
||||||
|
let projectType: string = "";
|
||||||
let framework: string = "";
|
let framework: string = "";
|
||||||
let language: string = "";
|
let language: string = "";
|
||||||
let baseContract: string = "";
|
let baseContract: string = "";
|
||||||
|
let chain: string = "";
|
||||||
/* let createType: string = "app"; */
|
/* let createType: string = "app"; */
|
||||||
|
|
||||||
export async function twCreate(pPath: string = "", options: any) {
|
export async function twCreate(
|
||||||
|
pType: string,
|
||||||
|
pPath: string = "",
|
||||||
|
options: any,
|
||||||
|
) {
|
||||||
if (typeof pPath === "string") {
|
if (typeof pPath === "string") {
|
||||||
projectPath = pPath;
|
projectPath = pPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.app) {
|
if (typeof options.contractName === "string") {
|
||||||
projectType = "app";
|
contractName = options.contractName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.contract) {
|
if (pType === "app" || options.app) {
|
||||||
|
projectType = "app";
|
||||||
|
} else if (pType === "contract" || options.contract) {
|
||||||
projectType = "contract";
|
projectType = "contract";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.typescript) {
|
if (projectType === "app") {
|
||||||
language = "typescript";
|
if (options.typescript) {
|
||||||
|
language = "typescript";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.javascript) {
|
||||||
|
language = "javascript";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.next) {
|
||||||
|
framework = "next";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.cra) {
|
||||||
|
framework = "cra";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.vite) {
|
||||||
|
framework = "vite";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.solana) {
|
||||||
|
chain = "solana";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.evm) {
|
||||||
|
chain = "evm";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.javascript) {
|
if (projectType === "contract") {
|
||||||
language = "javascript";
|
if (options.forge) {
|
||||||
}
|
framework = "forge";
|
||||||
|
}
|
||||||
|
|
||||||
if (options.next) {
|
if (options.hardhat) {
|
||||||
framework = "next";
|
framework = "hardhat";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.cra) {
|
|
||||||
framework = "cra";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.vite) {
|
|
||||||
framework = "vite";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.forge) {
|
|
||||||
framework = "forge";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.hardhat) {
|
|
||||||
framework = "hardhat";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.framework) {
|
if (options.framework) {
|
||||||
@@ -76,103 +98,216 @@ export async function twCreate(pPath: string = "", options: any) {
|
|||||||
if (typeof res.projectType === "string") {
|
if (typeof res.projectType === "string") {
|
||||||
projectType = res.projectType.trim();
|
projectType = res.projectType.trim();
|
||||||
}
|
}
|
||||||
} else if (!projectType && options.template) {
|
} else if (!projectType || options.template) {
|
||||||
// If no project type is specified, but a template is, we assume the user wants to create an app.
|
// If no project type is specified, but a template is, we assume the user wants to create an app.
|
||||||
// We do this so old users can still use the --template flag to create an app.
|
// We do this so old users can still use the --template flag to create an app.
|
||||||
projectType = "app";
|
projectType = "app";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!projectPath) {
|
// Whether to only create a new contract without the project
|
||||||
const defaultName =
|
let onlyContract = false;
|
||||||
projectType === "contract" ? "thirdweb-contracts" : "thirdweb-app";
|
if (projectType === "contract") {
|
||||||
const res = await prompts({
|
const resolvedProjectPath = path.resolve(projectPath);
|
||||||
type: "text",
|
const contractProjectType = await detect(resolvedProjectPath, {});
|
||||||
name: "path",
|
|
||||||
message: CREATE_MESSAGES.projectName,
|
|
||||||
initial: options.template || defaultName,
|
|
||||||
format: (name: string) => name.toLowerCase(),
|
|
||||||
validate: (name: string) => {
|
|
||||||
const validation = validateNpmName(
|
|
||||||
path.basename(path.resolve(name.toLowerCase())),
|
|
||||||
);
|
|
||||||
if (validation.valid) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return "Invalid project name: " + validation.problems?.[0];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof res.path === "string") {
|
|
||||||
projectPath = res.path.trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!projectPath) {
|
|
||||||
console.log(
|
|
||||||
"\nPlease specify the project directory:\n" +
|
|
||||||
` ${chalk.cyan("npx thirdweb create")} ${chalk.green(
|
|
||||||
"<project-directory>",
|
|
||||||
)}\n` +
|
|
||||||
"For example:\n" +
|
|
||||||
` ${chalk.cyan("npx thirdweb create")} ${chalk.green(
|
|
||||||
"my-thirdweb-app",
|
|
||||||
)}\n\n` +
|
|
||||||
`Run ${chalk.cyan("npx thirdweb --help")} to see all options.`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!options.template) {
|
|
||||||
if (projectType === "app" && !framework) {
|
|
||||||
const res = await prompts({
|
|
||||||
type: "select",
|
|
||||||
name: "framework",
|
|
||||||
message: CREATE_MESSAGES.framework,
|
|
||||||
choices: [
|
|
||||||
{ title: "Next.js", value: "next" },
|
|
||||||
{ title: "Create React App", value: "cra" },
|
|
||||||
{ title: "Vite", value: "vite" },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof res.framework === "string") {
|
|
||||||
framework = res.framework.trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (projectType === "app" && !language) {
|
|
||||||
const res = await prompts({
|
|
||||||
type: "select",
|
|
||||||
name: "language",
|
|
||||||
message: CREATE_MESSAGES.language,
|
|
||||||
choices: [
|
|
||||||
{ title: "JavaScript", value: "javascript" },
|
|
||||||
{ title: "TypeScript", value: "typescript" },
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (typeof res.language === "string") {
|
|
||||||
language = res.language.trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
projectType === "contract" &&
|
contractProjectType === "foundry" &&
|
||||||
framework !== "forge" &&
|
fs.existsSync(path.join(resolvedProjectPath, "src"))
|
||||||
framework !== "hardhat"
|
|
||||||
) {
|
) {
|
||||||
|
onlyContract = true;
|
||||||
|
projectPath = path.join(projectPath, "src");
|
||||||
|
} else if (contractProjectType === "hardhat") {
|
||||||
|
if (fs.existsSync(path.join(resolvedProjectPath, "contracts"))) {
|
||||||
|
onlyContract = true;
|
||||||
|
projectPath = path.join(projectPath, "contracts");
|
||||||
|
} else {
|
||||||
|
// If there's no expected contracts folder, check for a directory that has .sol files
|
||||||
|
const directories = fs
|
||||||
|
.readdirSync(resolvedProjectPath)
|
||||||
|
.filter((file) =>
|
||||||
|
fs.lstatSync(path.join(resolvedProjectPath, file)).isDirectory(),
|
||||||
|
);
|
||||||
|
for (const directory of directories) {
|
||||||
|
const files = fs.readdirSync(path.join(projectPath, directory));
|
||||||
|
if (files.some((file) => file.endsWith(".sol"))) {
|
||||||
|
onlyContract = true;
|
||||||
|
projectPath = path.join(projectPath, directory);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!onlyContract) {
|
||||||
|
if (!projectPath) {
|
||||||
|
const defaultName =
|
||||||
|
projectType === "contract" ? "thirdweb-contracts" : "thirdweb-app";
|
||||||
const res = await prompts({
|
const res = await prompts({
|
||||||
type: "select",
|
type: "text",
|
||||||
name: "framework",
|
name: "path",
|
||||||
message: CREATE_MESSAGES.framework,
|
message: CREATE_MESSAGES.projectName,
|
||||||
choices: [
|
initial: options.template || defaultName,
|
||||||
{ title: "Hardhat", value: "hardhat" },
|
format: (name: string) => name.toLowerCase(),
|
||||||
{ title: "Forge", value: "forge" },
|
validate: (name: string) => {
|
||||||
],
|
const validation = validateNpmName(
|
||||||
|
path.basename(path.resolve(name.toLowerCase())),
|
||||||
|
);
|
||||||
|
if (validation.valid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return "Invalid project name: " + validation.problems?.[0];
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof res.framework === "string") {
|
if (typeof res.path === "string") {
|
||||||
framework = res.framework.trim();
|
projectPath = path.join(projectPath, res.path.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!projectPath) {
|
||||||
|
console.log(
|
||||||
|
"\nPlease specify the project directory:\n" +
|
||||||
|
` ${chalk.cyan("npx thirdweb create")} ${chalk.green(
|
||||||
|
"<project-directory>",
|
||||||
|
)}\n` +
|
||||||
|
"For example:\n" +
|
||||||
|
` ${chalk.cyan("npx thirdweb create")} ${chalk.green(
|
||||||
|
"my-thirdweb-app",
|
||||||
|
)}\n\n` +
|
||||||
|
`Run ${chalk.cyan("npx thirdweb --help")} to see all options.`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.template) {
|
||||||
|
if (projectType === "app" && !chain) {
|
||||||
|
const res = await prompts({
|
||||||
|
type: "select",
|
||||||
|
name: "chain",
|
||||||
|
message: CREATE_MESSAGES.chain,
|
||||||
|
choices: [
|
||||||
|
{ title: "EVM", value: "evm" },
|
||||||
|
{ title: "Solana", value: "solana" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.chain === "solana") {
|
||||||
|
chain = "solana";
|
||||||
|
} else {
|
||||||
|
chain = "evm";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectType === "app" && !framework) {
|
||||||
|
const res = await prompts({
|
||||||
|
type: "select",
|
||||||
|
name: "framework",
|
||||||
|
message: CREATE_MESSAGES.framework,
|
||||||
|
choices:
|
||||||
|
// Solana doesn't support Vite just yet:
|
||||||
|
chain === "solana"
|
||||||
|
? [
|
||||||
|
{ title: "Next.js", value: "next" },
|
||||||
|
{ title: "Create React App", value: "cra" },
|
||||||
|
// { title: "Vite", value: "vite" },
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
{ title: "Next.js", value: "next" },
|
||||||
|
{ title: "Create React App", value: "cra" },
|
||||||
|
{ title: "Vite", value: "vite" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof res.framework === "string") {
|
||||||
|
framework = res.framework.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectType === "app" && !language) {
|
||||||
|
const res = await prompts({
|
||||||
|
type: "select",
|
||||||
|
name: "language",
|
||||||
|
message: CREATE_MESSAGES.language,
|
||||||
|
choices: [
|
||||||
|
{ title: "JavaScript", value: "javascript" },
|
||||||
|
{ title: "TypeScript", value: "typescript" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof res.language === "string") {
|
||||||
|
language = res.language.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
projectType === "contract" &&
|
||||||
|
framework !== "forge" &&
|
||||||
|
framework !== "hardhat"
|
||||||
|
) {
|
||||||
|
const res = await prompts({
|
||||||
|
type: "select",
|
||||||
|
name: "framework",
|
||||||
|
message: CREATE_MESSAGES.framework,
|
||||||
|
choices: [
|
||||||
|
{ title: "Hardhat", value: "hardhat" },
|
||||||
|
{ title: "Forge", value: "forge" },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof res.framework === "string") {
|
||||||
|
framework = res.framework.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!framework) {
|
||||||
|
console.log("Please specify a framework");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!language) {
|
||||||
|
// Default = JavaScript
|
||||||
|
language = "javascript";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectType === "contract") {
|
||||||
|
// Select contract name
|
||||||
|
if (!contractName) {
|
||||||
|
const defaultName = "MyContract";
|
||||||
|
const res = await prompts({
|
||||||
|
type: "text",
|
||||||
|
name: "path",
|
||||||
|
message: CREATE_MESSAGES.contractName,
|
||||||
|
initial: defaultName,
|
||||||
|
validate: (name: string) => {
|
||||||
|
const isValid = /(^[a-z0-9A-Z]+$)|(^[a-z0-9A-Z]+\.sol$)/.test(name);
|
||||||
|
if (isValid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `Invalid contract name 'contractName' (only alphanumeric characters allowed)`;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof res.path === "string") {
|
||||||
|
contractName = res.path.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!contractName) {
|
||||||
|
console.log(
|
||||||
|
"\nPlease specify the contract name:\n" +
|
||||||
|
` ${chalk.cyan(
|
||||||
|
"npx thirdweb create --contract --name",
|
||||||
|
)} ${chalk.green("<contract-name>")}\n` +
|
||||||
|
"For example:\n" +
|
||||||
|
` ${chalk.cyan(
|
||||||
|
"npx thirdweb create --contract --name",
|
||||||
|
)} ${chalk.green("MyContract")}\n\n` +
|
||||||
|
`Run ${chalk.cyan("npx thirdweb --help")} to see all options.`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +319,9 @@ export async function twCreate(pPath: string = "", options: any) {
|
|||||||
name: "standard",
|
name: "standard",
|
||||||
message: CREATE_MESSAGES.contract,
|
message: CREATE_MESSAGES.contract,
|
||||||
choices: [
|
choices: [
|
||||||
{ title: "Empty Contract", value: "none" },
|
...(!onlyContract
|
||||||
|
? [{ title: "Empty Contract", value: "none" }]
|
||||||
|
: []),
|
||||||
{ title: "ERC721", value: "erc721" },
|
{ title: "ERC721", value: "erc721" },
|
||||||
{ title: "ERC20", value: "erc20" },
|
{ title: "ERC20", value: "erc20" },
|
||||||
{ title: "ERC1155", value: "erc1155" },
|
{ title: "ERC1155", value: "erc1155" },
|
||||||
@@ -238,20 +375,11 @@ export async function twCreate(pPath: string = "", options: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!framework) {
|
|
||||||
console.log("Please specify a framework");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!language) {
|
|
||||||
// Default = JavaScript
|
|
||||||
language = "javascript";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolvedProjectPath = path.resolve(projectPath);
|
// Resolve project path
|
||||||
const projectName = path.basename(resolvedProjectPath);
|
projectPath = path.resolve(projectPath);
|
||||||
|
const projectName = path.basename(projectPath);
|
||||||
|
|
||||||
const { valid, problems } = validateNpmName(projectName);
|
const { valid, problems } = validateNpmName(projectName);
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
@@ -283,18 +411,21 @@ export async function twCreate(pPath: string = "", options: any) {
|
|||||||
try {
|
try {
|
||||||
if (projectType === "app") {
|
if (projectType === "app") {
|
||||||
await createApp({
|
await createApp({
|
||||||
appPath: resolvedProjectPath,
|
appPath: projectPath,
|
||||||
packageManager,
|
packageManager,
|
||||||
framework,
|
framework,
|
||||||
language,
|
language,
|
||||||
template,
|
template,
|
||||||
|
chain,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await createContract({
|
await createContractProject({
|
||||||
contractPath: resolvedProjectPath,
|
contractPath: projectPath,
|
||||||
packageManager,
|
packageManager,
|
||||||
framework,
|
framework,
|
||||||
|
contractName,
|
||||||
baseContract,
|
baseContract,
|
||||||
|
onlyContract,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ export async function createApp({
|
|||||||
framework,
|
framework,
|
||||||
language,
|
language,
|
||||||
template,
|
template,
|
||||||
|
chain,
|
||||||
}: {
|
}: {
|
||||||
appPath: string;
|
appPath: string;
|
||||||
packageManager: PackageManager;
|
packageManager: PackageManager;
|
||||||
framework?: string;
|
framework?: string;
|
||||||
language?: string;
|
language?: string;
|
||||||
template?: string;
|
template?: string;
|
||||||
|
chain?: string;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
let frameworkPath = "";
|
let frameworkPath = "";
|
||||||
|
|
||||||
@@ -43,7 +45,9 @@ export async function createApp({
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else if (framework) {
|
} else if (framework) {
|
||||||
frameworkPath = `${framework}-${language || "javascript"}-starter`;
|
frameworkPath = `${framework}-${language || "javascript"}-${
|
||||||
|
chain === "solana" ? "solana-" : ""
|
||||||
|
}starter`;
|
||||||
const found = await hasTemplate(frameworkPath);
|
const found = await hasTemplate(frameworkPath);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
|||||||
@@ -11,22 +11,28 @@ import { submodules } from "./submodules";
|
|||||||
import { downloadAndExtractRepo } from "./templates";
|
import { downloadAndExtractRepo } from "./templates";
|
||||||
import retry from "async-retry";
|
import retry from "async-retry";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
|
import fs from "fs";
|
||||||
import { writeFile } from "fs/promises";
|
import { writeFile } from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
interface ICreateContract {
|
interface ICreateContractProject {
|
||||||
contractPath: string;
|
contractPath: string;
|
||||||
packageManager: PackageManager;
|
packageManager: PackageManager;
|
||||||
|
contractName: string;
|
||||||
framework?: string;
|
framework?: string;
|
||||||
baseContract?: string;
|
baseContract?: string;
|
||||||
|
onlyContract: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createContract({
|
export async function createContractProject({
|
||||||
contractPath,
|
contractPath,
|
||||||
packageManager,
|
packageManager,
|
||||||
framework,
|
framework,
|
||||||
|
contractName,
|
||||||
baseContract,
|
baseContract,
|
||||||
}: ICreateContract) {
|
onlyContract,
|
||||||
|
}: ICreateContractProject) {
|
||||||
|
// Check that the selected base contract is valid
|
||||||
if (baseContract) {
|
if (baseContract) {
|
||||||
const found = hasBaseContract(baseContract);
|
const found = hasBaseContract(baseContract);
|
||||||
|
|
||||||
@@ -40,8 +46,8 @@ export async function createContract({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that we have write permission for the specified directory
|
||||||
const root = path.resolve(contractPath);
|
const root = path.resolve(contractPath);
|
||||||
|
|
||||||
if (!(await isWriteable(path.dirname(root)))) {
|
if (!(await isWriteable(path.dirname(root)))) {
|
||||||
console.error(
|
console.error(
|
||||||
"The application path is not writable, please check folder permissions and try again.",
|
"The application path is not writable, please check folder permissions and try again.",
|
||||||
@@ -52,117 +58,165 @@ export async function createContract({
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const projectName = path.basename(root);
|
// Check that the contract name is valid
|
||||||
|
if (!/(^[a-z0-9A-Z]+$)|(^[a-z0-9A-Z]+\.sol$)/.test(contractName)) {
|
||||||
await makeDir(root);
|
console.error(
|
||||||
if (!isFolderEmpty(root, projectName)) {
|
`Contract name ${chalk.red(
|
||||||
|
`"${contractName}"`,
|
||||||
|
)} is not valid (only alphanumeric characters are allowed).`,
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean the contract name
|
||||||
|
contractName = contractName.replace(/\.sol$/, "") + ".sol";
|
||||||
|
|
||||||
const useYarn = packageManager === "yarn";
|
const useYarn = packageManager === "yarn";
|
||||||
const isOnline = !useYarn || (await getOnline());
|
|
||||||
const originalDirectory = process.cwd();
|
|
||||||
|
|
||||||
console.log(
|
if (onlyContract) {
|
||||||
`Creating a new thirdweb contracts project in ${chalk.green(root)}.`,
|
// If we are already in a contracts project, just create a new contract
|
||||||
);
|
if (fs.existsSync(path.join(root, contractName))) {
|
||||||
console.log();
|
console.error(
|
||||||
|
`A contract with the name ${chalk.red(
|
||||||
process.chdir(root);
|
`"${contractName}"`,
|
||||||
|
)} already exists in specified directory.`,
|
||||||
function isErrorLike(err: unknown): err is { message: string } {
|
);
|
||||||
return (
|
|
||||||
typeof err === "object" &&
|
|
||||||
err !== null &&
|
|
||||||
typeof (err as { message?: unknown }).message === "string"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
console.log(`Downloading files. This might take a moment.`);
|
|
||||||
|
|
||||||
let starter = "";
|
|
||||||
if (framework === "hardhat") {
|
|
||||||
starter = "hardhat-javascript-starter";
|
|
||||||
} else if (framework === "forge") {
|
|
||||||
starter = "forge-starter";
|
|
||||||
} else {
|
|
||||||
console.error("Please provide a valid contracts framework.");
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
await retry(
|
|
||||||
() => downloadAndExtractRepo(root, { name: starter, filePath: "" }),
|
|
||||||
{
|
|
||||||
retries: 3,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Modify the /contracts/MyContract.sol contents to match the base contract
|
|
||||||
if (baseContract && baseContract.length > 0) {
|
if (baseContract && baseContract.length > 0) {
|
||||||
const baseContractText = readBaseContract(baseContract);
|
const baseContractText = readBaseContract(baseContract);
|
||||||
|
|
||||||
// Set the contents of the Contract.sol file to the base contract
|
// Set the contents of the Contract.sol file to the base contract
|
||||||
let contractFile = "";
|
let contractFile = "";
|
||||||
if (framework === "hardhat") {
|
contractFile = path.join(root, contractName);
|
||||||
contractFile = path.join(root, "contracts", "Contract.sol");
|
|
||||||
}
|
|
||||||
if (framework === "forge") {
|
|
||||||
contractFile = path.join(root, "src", "Contract.sol");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the base contract to the MyContract.sol file
|
// Write the base contract to the MyContract.sol file
|
||||||
await writeFile(contractFile, baseContractText);
|
await writeFile(contractFile, baseContractText);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("Success!")} Created ${contractName} at ${contractPath}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (reason) {
|
} else {
|
||||||
throw new DownloadError(
|
// Otherwise, create a new contracts project
|
||||||
isErrorLike(reason) ? reason.message : String(reason),
|
const projectName = path.basename(root);
|
||||||
|
|
||||||
|
await makeDir(root);
|
||||||
|
if (!isFolderEmpty(root, projectName)) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const isOnline = !useYarn || (await getOnline());
|
||||||
|
const originalDirectory = process.cwd();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Creating a new thirdweb contracts project in ${chalk.green(root)}.`,
|
||||||
);
|
);
|
||||||
}
|
console.log();
|
||||||
|
|
||||||
console.log("Installing packages. This might take a couple of minutes.");
|
process.chdir(root);
|
||||||
console.log();
|
|
||||||
|
|
||||||
await install(root, null, { packageManager, isOnline });
|
function isErrorLike(err: unknown): err is { message: string } {
|
||||||
console.log();
|
return (
|
||||||
|
typeof err === "object" &&
|
||||||
|
err !== null &&
|
||||||
|
typeof (err as { message?: unknown }).message === "string"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (tryGitInit(root)) {
|
try {
|
||||||
console.log("Initialized a git repository.");
|
console.log(`Downloading files. This might take a moment.`);
|
||||||
|
|
||||||
|
let starter = "";
|
||||||
|
if (framework === "hardhat") {
|
||||||
|
starter = "hardhat-javascript-starter";
|
||||||
|
} else if (framework === "forge") {
|
||||||
|
starter = "forge-starter";
|
||||||
|
} else {
|
||||||
|
console.error("Please provide a valid contracts framework.");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
await retry(
|
||||||
|
() => downloadAndExtractRepo(root, { name: starter, filePath: "" }),
|
||||||
|
{
|
||||||
|
retries: 3,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add in a new contracts file with specific base contract
|
||||||
|
if (baseContract && baseContract.length > 0) {
|
||||||
|
const baseContractText = readBaseContract(baseContract);
|
||||||
|
|
||||||
|
// Set the filename of the new file and delete the dummy Contract.sol file
|
||||||
|
let contractFile = "";
|
||||||
|
if (framework === "hardhat") {
|
||||||
|
fs.unlinkSync(path.join(root, "contracts", "Contract.sol"));
|
||||||
|
contractFile = path.join(root, "contracts", contractName);
|
||||||
|
}
|
||||||
|
if (framework === "forge") {
|
||||||
|
fs.unlinkSync(path.join(root, "src", "Contract.sol"));
|
||||||
|
contractFile = path.join(root, "src", contractName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the base contract to the new file
|
||||||
|
await writeFile(contractFile, baseContractText);
|
||||||
|
}
|
||||||
|
} catch (reason) {
|
||||||
|
throw new DownloadError(
|
||||||
|
isErrorLike(reason) ? reason.message : String(reason),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Installing packages. This might take a couple of minutes.");
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
await install(root, null, { packageManager, isOnline });
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
if (tryGitInit(root)) {
|
||||||
|
console.log("Initialized a git repository.");
|
||||||
|
console.log();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (framework === "forge") {
|
||||||
|
await submodules();
|
||||||
|
}
|
||||||
|
|
||||||
|
let cdpath: string;
|
||||||
|
if (path.join(originalDirectory, projectName) === contractPath) {
|
||||||
|
cdpath = projectName;
|
||||||
|
} else {
|
||||||
|
cdpath = contractPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${chalk.green("Success!")} Created ${projectName} at ${contractPath}`,
|
||||||
|
);
|
||||||
|
console.log();
|
||||||
|
console.log("Inside that directory, you can run several commands:");
|
||||||
|
console.log();
|
||||||
|
console.log(
|
||||||
|
chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} build`),
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
" Compiles your contracts and detects thirdweb extensions implemented on them.",
|
||||||
|
);
|
||||||
|
console.log();
|
||||||
|
console.log(
|
||||||
|
chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} deploy`),
|
||||||
|
);
|
||||||
|
console.log(" Deploys your contracts with the thirdweb deploy flow.");
|
||||||
|
console.log();
|
||||||
|
console.log(
|
||||||
|
chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} release`),
|
||||||
|
);
|
||||||
|
console.log(" Releases your contracts with the thirdweb release flow.");
|
||||||
|
console.log();
|
||||||
|
console.log("We suggest that you begin by typing:");
|
||||||
|
console.log();
|
||||||
|
console.log(chalk.cyan(" cd"), cdpath);
|
||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (framework === "forge") {
|
|
||||||
await submodules();
|
|
||||||
}
|
|
||||||
|
|
||||||
let cdpath: string;
|
|
||||||
if (path.join(originalDirectory, projectName) === contractPath) {
|
|
||||||
cdpath = projectName;
|
|
||||||
} else {
|
|
||||||
cdpath = contractPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
`${chalk.green("Success!")} Created ${projectName} at ${contractPath}`,
|
|
||||||
);
|
|
||||||
console.log();
|
|
||||||
console.log("Inside that directory, you can run several commands:");
|
|
||||||
console.log();
|
|
||||||
console.log(chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} build`));
|
|
||||||
console.log(
|
|
||||||
" Compiles your contracts and detects thirdweb extensions implemented on them.",
|
|
||||||
);
|
|
||||||
console.log();
|
|
||||||
console.log(chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} deploy`));
|
|
||||||
console.log(" Deploys your contracts with the thirdweb deploy flow.");
|
|
||||||
console.log();
|
|
||||||
console.log(
|
|
||||||
chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} release`),
|
|
||||||
);
|
|
||||||
console.log(" Releases your contracts with the thirdweb release flow.");
|
|
||||||
console.log();
|
|
||||||
console.log("We suggest that you begin by typing:");
|
|
||||||
console.log();
|
|
||||||
console.log(chalk.cyan(" cd"), cdpath);
|
|
||||||
console.log();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,26 @@
|
|||||||
import spawn from "cross-spawn";
|
import spawn from "cross-spawn";
|
||||||
|
|
||||||
export async function runCommand(command: string, args: string[]) {
|
export async function runCommand(
|
||||||
|
command: string,
|
||||||
|
args: string[],
|
||||||
|
logging: boolean = false,
|
||||||
|
) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
/**
|
/**
|
||||||
* Spawn the installation process.
|
* Spawn the installation process.
|
||||||
*/
|
*/
|
||||||
const child = spawn(command, args);
|
const child = spawn(command, args);
|
||||||
|
child.stdout?.on("data", (data) => {
|
||||||
|
if (logging) {
|
||||||
|
console.log(data.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
child.stderr?.on("error", (err) => {
|
||||||
|
if (logging) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
child.on("close", (code) => {
|
child.on("close", (code) => {
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
reject({ command: `${command}` });
|
reject({ command: `${command}` });
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import NPMDetector from "../core/detection/npm";
|
||||||
|
import ViteDetector from "../core/detection/vite";
|
||||||
|
import YarnDetector from "../core/detection/yarn";
|
||||||
|
import { runCommand } from "../create/helpers/run-command";
|
||||||
|
import { upload } from "../storage/command";
|
||||||
|
import { DEFAULT_IPFS_GATEWAY } from "@thirdweb-dev/sdk";
|
||||||
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
|
|
||||||
|
export async function deployApp(distPath = "dist", projectPath = ".") {
|
||||||
|
const storage = new ThirdwebStorage();
|
||||||
|
const supportedFrameworks = [new ViteDetector()];
|
||||||
|
|
||||||
|
const possibleProjects = supportedFrameworks
|
||||||
|
.filter((detector) => detector.matches(projectPath))
|
||||||
|
.map((detector) => detector.projectType);
|
||||||
|
|
||||||
|
const hasYarn = new YarnDetector().matches(".");
|
||||||
|
const hasNPM = new NPMDetector().matches(".");
|
||||||
|
|
||||||
|
if (possibleProjects.length === 0) {
|
||||||
|
throw new Error("No supported project detected");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (hasYarn) {
|
||||||
|
await runCommand("yarn", ["build"]);
|
||||||
|
} else if (hasNPM) {
|
||||||
|
await runCommand("npm", ["build"]);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Can't build project");
|
||||||
|
return Promise.reject("Can't build project");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let url = await upload(storage, distPath);
|
||||||
|
url = url.replace("ipfs://", DEFAULT_IPFS_GATEWAY);
|
||||||
|
return `${url}/index.html`;
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Can't upload project");
|
||||||
|
return Promise.reject("Can't upload project");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { processProject } from "../common/processor";
|
||||||
|
import { info, logger } from "../core/helpers/logger";
|
||||||
|
import generateDashboardUrl from "../helpers/generate-dashboard-url";
|
||||||
|
import { deployApp } from "./app";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
|
type DeployOptions = {
|
||||||
|
name: string;
|
||||||
|
contractVersion: string;
|
||||||
|
app: boolean;
|
||||||
|
path?: string;
|
||||||
|
distPath?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function deploy(options: DeployOptions) {
|
||||||
|
if (options.name) {
|
||||||
|
const url = generateDashboardUrl(options.name, options.contractVersion);
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
logger.error(
|
||||||
|
chalk.red(
|
||||||
|
`Could not find a contract named ${options.name} ${
|
||||||
|
options.contractVersion || ""
|
||||||
|
}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info(`Open this link to deploy your contract: ${chalk.blueBright(url)}`);
|
||||||
|
return url.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.app) {
|
||||||
|
try {
|
||||||
|
let url = await deployApp(options.distPath, options.path);
|
||||||
|
info(`Here is the link to your app: ${chalk.blueBright(url.toString())}`);
|
||||||
|
return url.toString();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("Failed to deploy app, No compatible project found", err);
|
||||||
|
return Promise.reject(
|
||||||
|
"failed to deploy app, no compatible project found",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = await processProject(options, "deploy");
|
||||||
|
info(
|
||||||
|
`Open this link to deploy your contracts: ${chalk.blueBright(
|
||||||
|
url.toString(),
|
||||||
|
)}`,
|
||||||
|
);
|
||||||
|
return url.toString();
|
||||||
|
}
|
||||||
@@ -13,18 +13,18 @@ export default function generateDashboardUrl(
|
|||||||
// Pre-built contract
|
// Pre-built contract
|
||||||
else {
|
else {
|
||||||
const mapping = {
|
const mapping = {
|
||||||
"signature-drop": "drop/signature-drop",
|
"signature-drop": "SignatureDrop",
|
||||||
"nft-drop": "drop/nft-drop",
|
"nft-drop": "DropERC721",
|
||||||
"edition-drop": "drop/edition-drop",
|
"edition-drop": "DropERC1155",
|
||||||
"nft-collection": "token/nft-collection",
|
"nft-collection": "TokenERC721",
|
||||||
edition: "token/edition",
|
edition: "TokenERC1155",
|
||||||
"token-drop": "drop/token-drop",
|
"token-drop": "DropERC20",
|
||||||
token: "token/token",
|
token: "TokenERC20",
|
||||||
marketplace: "marketplace/marketplace",
|
marketplace: "Marketplace",
|
||||||
split: "governance/split",
|
split: "Split",
|
||||||
vote: "governance/vote",
|
vote: "VoteERC20",
|
||||||
pack: "token/pack",
|
pack: "Pack",
|
||||||
multiwrap: "token/multiwrap",
|
multiwrap: "Multiwrap",
|
||||||
};
|
};
|
||||||
|
|
||||||
const foundMapping = mapping[name as keyof typeof mapping];
|
const foundMapping = mapping[name as keyof typeof mapping];
|
||||||
@@ -33,6 +33,6 @@ export default function generateDashboardUrl(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `https://thirdweb.com/contracts/new/pre-built/${foundMapping}`;
|
return `https://thirdweb.com/thirdweb.eth/${foundMapping}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { logger } from "../core/helpers/logger";
|
|
||||||
import { spinner } from "../core/helpers/logger";
|
import { spinner } from "../core/helpers/logger";
|
||||||
import { BufferOrStringWithName, ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { BufferOrStringWithName, ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import chalk from "chalk";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
@@ -33,22 +31,12 @@ export async function upload(
|
|||||||
uploadPath: string,
|
uploadPath: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (!uploadPath) {
|
if (!uploadPath) {
|
||||||
logger.error(
|
return Promise.reject("No path provided");
|
||||||
`Please pass a path to a file or directory to upload with the following format:\n ${chalk.blueBright(
|
|
||||||
`npx thirdweb@latest upload path/to/file.jpg`,
|
|
||||||
)}\n`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathExists = fs.existsSync(uploadPath);
|
const pathExists = fs.existsSync(uploadPath);
|
||||||
if (!pathExists) {
|
if (!pathExists) {
|
||||||
logger.error(
|
return Promise.reject("Invalid path provided");
|
||||||
`Invalid path ${chalk.blueBright(
|
|
||||||
uploadPath,
|
|
||||||
)} provided. Please provide a valid path to a file or directory to upload."`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let uri = "";
|
let uri = "";
|
||||||
@@ -57,12 +45,7 @@ export async function upload(
|
|||||||
const files = recurseFiles(uploadPath, uploadPath);
|
const files = recurseFiles(uploadPath, uploadPath);
|
||||||
|
|
||||||
if (files.length === 0) {
|
if (files.length === 0) {
|
||||||
logger.error(
|
return Promise.reject("No files detected in specified directory");
|
||||||
`No files detected in specified directory ${chalk.blueBright(
|
|
||||||
uploadPath,
|
|
||||||
)} to upload.`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const spin = spinner(
|
const spin = spinner(
|
||||||
@@ -82,12 +65,7 @@ export async function upload(
|
|||||||
uri = await storage.upload(file, { uploadWithoutDirectory: true });
|
uri = await storage.upload(file, { uploadWithoutDirectory: true });
|
||||||
spin.succeed("Succesfully uploaded file to IPFS.");
|
spin.succeed("Succesfully uploaded file to IPFS.");
|
||||||
} else {
|
} else {
|
||||||
logger.error(
|
return Promise.reject("Invalid path provided");
|
||||||
`Path ${chalk.blueBright(
|
|
||||||
uploadPath,
|
|
||||||
)} does not point to a valid file or directory. Please provide a valid path to a file or directory to upload`,
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return uri;
|
return uri;
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
# @thirdweb-dev/contracts-js
|
# @thirdweb-dev/contracts-js
|
||||||
|
|
||||||
|
## 1.2.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#438](https://github.com/thirdweb-dev/js/pull/438) [`f451da6`](https://github.com/thirdweb-dev/js/commit/f451da6395689a5f89800ee63f34b6175b61f703) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix SigMint detection for OSRF NFT Collection contracts
|
||||||
|
|
||||||
|
## 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,19 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/contracts-js",
|
"name": "@thirdweb-dev/contracts-js",
|
||||||
"version": "1.1.9",
|
"version": "1.2.2",
|
||||||
"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.8-0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.18.10",
|
||||||
"@babel/preset-typescript": "^7.18.6",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
"@preconstruct/cli": "^2.2.1",
|
"@preconstruct/cli": "^2.2.1",
|
||||||
"@typechain/ethers-v5": "10.0.0",
|
"@typechain/ethers-v5": "10.0.0",
|
||||||
"ethers": "^5.7.0",
|
"ethers": "^5.7.2",
|
||||||
"typechain": "^8.1.0",
|
"typechain": "^8.1.0",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
||||||
"@typescript-eslint/parser": "^5.33.0",
|
"@typescript-eslint/parser": "^5.33.0",
|
||||||
"eslint-config-next": "^12.0.8",
|
"eslint-config-next": "12.3.1",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-config-turbo": "latest",
|
"eslint-config-turbo": "latest",
|
||||||
"eslint-plugin-react": "^7.28.0"
|
"eslint-plugin-react": "^7.28.0"
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
"@babel/preset-typescript",
|
||||||
|
["@babel/preset-env", { "targets": "defaults, not ie 11" }]
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# folders
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# files
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
extends: ["thirdweb"],
|
||||||
|
};
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# @thirdweb-dev/pay
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#433](https://github.com/thirdweb-dev/js/pull/433) [`7269268`](https://github.com/thirdweb-dev/js/commit/72692689e9adb41e92038765fd01a36c2b7457e1) Thanks [@jnsdls](https://github.com/jnsdls)! - Initialize Pay Package
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<p align="center">
|
||||||
|
<br />
|
||||||
|
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/packages/sdk/logo.svg?raw=true" width="200" alt=""/></a>
|
||||||
|
<br />
|
||||||
|
</p>
|
||||||
|
<h1 align="center">thirdweb wallets</h1>
|
||||||
|
<p align="center">
|
||||||
|
<!-- <a href="https://www.npmjs.com/package/@thirdweb-dev/sdk"><img src="https://img.shields.io/npm/v/@thirdweb-dev/sdk?color=red&label=npm&logo=npm" alt="npm version"/></a> -->
|
||||||
|
<!-- <a href="https://github.com/thirdweb-dev/js/actions/workflows/CI.yml"><img alt="Build Status" src="https://github.com/thirdweb-dev/js/actions/workflows/CI.yml/badge.svg"/></a> -->
|
||||||
|
<!-- <a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a> -->
|
||||||
|
|
||||||
|
</p>
|
||||||
|
<!-- <p align="center"><strong>Best in class Web3 SDK for Browser, Node and Mobile apps</strong></p> -->
|
||||||
|
<br />
|
||||||
|
|
||||||
|
### todo
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-pay-integrations-coinbase.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-pay-integrations-coinbase.esm.js"
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"name": "@thirdweb-dev/pay",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"main": "dist/thirdweb-dev-pay.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-pay.esm.js",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"module": "./dist/thirdweb-dev-pay.esm.js",
|
||||||
|
"default": "./dist/thirdweb-dev-pay.cjs.js"
|
||||||
|
},
|
||||||
|
"./integrations/coinbase": {
|
||||||
|
"module": "./integrations/coinbase/dist/thirdweb-dev-pay-integrations-coinbase.esm.js",
|
||||||
|
"default": "./integrations/coinbase/dist/thirdweb-dev-pay-integrations-coinbase.cjs.js"
|
||||||
|
},
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/pay",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/thirdweb-dev/js/issues"
|
||||||
|
},
|
||||||
|
"author": "thirdweb eng <[email protected]>",
|
||||||
|
"files": [
|
||||||
|
"dist/",
|
||||||
|
"integrations/"
|
||||||
|
],
|
||||||
|
"preconstruct": {
|
||||||
|
"entrypoints": [
|
||||||
|
"index.ts",
|
||||||
|
"integrations/**"
|
||||||
|
],
|
||||||
|
"___experimentalFlags_WILL_CHANGE_IN_PATCH": {
|
||||||
|
"exports": true
|
||||||
|
},
|
||||||
|
"exports": true
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"dependencies": {
|
||||||
|
"@coinbase/cbpay-js": "^1.6.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@preconstruct/cli": "^2.2.1",
|
||||||
|
"typescript": "^4.7.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"format": "prettier --write 'src/**/*'",
|
||||||
|
"lint": "eslint src/",
|
||||||
|
"fix": "eslint src/ --fix",
|
||||||
|
"clean": "rm -rf dist/",
|
||||||
|
"build": "tsc && preconstruct build",
|
||||||
|
"push": "yalc push"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from "./integrations/coinbase";
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { initOnRamp, InitOnRampParams } from "@coinbase/cbpay-js";
|
||||||
|
|
||||||
|
interface CoinbasePayOptions extends Pick<InitOnRampParams, "appId"> {}
|
||||||
|
|
||||||
|
const CHAIN_ID_MAP = {
|
||||||
|
[-1]: "solana",
|
||||||
|
1: "ethereum",
|
||||||
|
69: "optimism",
|
||||||
|
137: "polygon",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export type FundWalletOptions = {
|
||||||
|
address: string;
|
||||||
|
chainId: keyof typeof CHAIN_ID_MAP;
|
||||||
|
assets?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export class CoinbasePayIntegration {
|
||||||
|
#appId: string;
|
||||||
|
constructor(options: CoinbasePayOptions) {
|
||||||
|
this.#appId = options.appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fundWallet(opts: FundWalletOptions): Promise<void> {
|
||||||
|
const { address, chainId, assets } = opts;
|
||||||
|
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
initOnRamp(
|
||||||
|
{
|
||||||
|
appId: this.#appId,
|
||||||
|
widgetParameters: {
|
||||||
|
destinationWallets: [
|
||||||
|
{
|
||||||
|
address,
|
||||||
|
assets,
|
||||||
|
supportedNetworks: [CHAIN_ID_MAP[chainId]],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
experienceLoggedIn: "embedded",
|
||||||
|
experienceLoggedOut: "popup",
|
||||||
|
closeOnExit: true,
|
||||||
|
onSuccess: () => {
|
||||||
|
res();
|
||||||
|
},
|
||||||
|
onExit(error) {
|
||||||
|
if (error) {
|
||||||
|
return rej(error);
|
||||||
|
}
|
||||||
|
return res();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
(err, instance) => {
|
||||||
|
if (err || !instance) {
|
||||||
|
return rej(err);
|
||||||
|
}
|
||||||
|
instance.open();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": "@thirdweb-dev/tsconfig/sdk.json",
|
||||||
|
"include": ["src", "types"],
|
||||||
|
"exclude": ["dist", "build", "node_modules"]
|
||||||
|
}
|
||||||
@@ -1,5 +1,90 @@
|
|||||||
# @thirdweb-dev/react
|
# @thirdweb-dev/react
|
||||||
|
|
||||||
|
## 3.6.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#443](https://github.com/thirdweb-dev/js/pull/443) [`8c6cdaa`](https://github.com/thirdweb-dev/js/commit/8c6cdaa2887fb2cc40d3ee6991233d195d103805) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix magic link connector not connecting to the right chain
|
||||||
|
|
||||||
|
## 3.6.5
|
||||||
|
|
||||||
|
## 3.6.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#425](https://github.com/thirdweb-dev/js/pull/425) [`f545a67`](https://github.com/thirdweb-dev/js/commit/f545a67e9fb597d27bb39ca515d24d306fbb121a) Thanks [@adam-maj](https://github.com/adam-maj)! - Add sameSite none and include credentials
|
||||||
|
|
||||||
|
- [#420](https://github.com/thirdweb-dev/js/pull/420) [`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45) Thanks [@jnsdls](https://github.com/jnsdls)! - update deps
|
||||||
|
|
||||||
|
## 3.6.3
|
||||||
|
|
||||||
|
## 3.6.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#405](https://github.com/thirdweb-dev/js/pull/405) [`ccb7db4`](https://github.com/thirdweb-dev/js/commit/ccb7db48739b8dddcb2c032b3b6e3e5200485715) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add updateAll param to creators and royalty update hooks for Solana
|
||||||
|
|
||||||
|
## 3.6.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#392](https://github.com/thirdweb-dev/js/pull/392) [`846022e`](https://github.com/thirdweb-dev/js/commit/846022e2cfb12b846aae029b85899fb72fd2c9ad) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix unlimited price for useActiveClaimConditionForWallet
|
||||||
|
|
||||||
|
- [#388](https://github.com/thirdweb-dev/js/pull/388) [`7c0744a`](https://github.com/thirdweb-dev/js/commit/7c0744a006e78987ad8b271b2c64f4bac7759510) Thanks [@adam-maj](https://github.com/adam-maj)! - Add support for total supply and pagination on get all
|
||||||
|
|
||||||
|
## 3.6.0
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#386](https://github.com/thirdweb-dev/js/pull/386) [`612bcdd`](https://github.com/thirdweb-dev/js/commit/612bcdd16fc242d8b04bc70d609e44b0df47ed3f) Thanks [@jnsdls](https://github.com/jnsdls)! - [Gnosis Connector] - switch to safe.global hostname & add support for bsc and optimism chains
|
||||||
|
|
||||||
|
- [#364](https://github.com/thirdweb-dev/js/pull/364) [`7cb8e59`](https://github.com/thirdweb-dev/js/commit/7cb8e59be48dc923316eb36ab43a1bef7364f6b1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Add experimental `useActiveClaimConditionForWallet()` hook
|
||||||
|
|
||||||
|
## 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
|
## 3.4.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react",
|
"name": "@thirdweb-dev/react",
|
||||||
"version": "3.4.0",
|
"version": "3.6.6",
|
||||||
"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",
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
},
|
},
|
||||||
"sideEffects:": false,
|
"sideEffects:": false,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.18.10",
|
"@babel/core": "^7.19.3",
|
||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.18.10",
|
||||||
"@babel/preset-react": "^7.18.6",
|
"@babel/preset-react": "^7.18.6",
|
||||||
"@babel/preset-typescript": "^7.18.6",
|
"@babel/preset-typescript": "^7.18.6",
|
||||||
@@ -73,6 +73,7 @@
|
|||||||
"@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.62.0",
|
||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"@types/color": "^3.0.3",
|
"@types/color": "^3.0.3",
|
||||||
@@ -87,7 +88,7 @@
|
|||||||
"eslint-plugin-inclusive-language": "^2.2.0",
|
"eslint-plugin-inclusive-language": "^2.2.0",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"eslint-plugin-tsdoc": "^0.2.16",
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"ethers": "^5.7.1",
|
"ethers": "^5.7.2",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
|||||||
@@ -14,19 +14,19 @@ export const SupportedNetworkSelect: React.FC<SupportedNetworkSelectProps> = ({
|
|||||||
const deprecatedNetworks = useMemo(() => {
|
const deprecatedNetworks = useMemo(() => {
|
||||||
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
||||||
return getChainFromChainId(supportedChain);
|
return getChainFromChainId(supportedChain);
|
||||||
}).filter((n) => !!n.deprecated);
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const testnets = useMemo(() => {
|
const testnets = useMemo(() => {
|
||||||
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
||||||
return getChainFromChainId(supportedChain);
|
return getChainFromChainId(supportedChain);
|
||||||
}).filter((n) => n.testnet && !n.deprecated);
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const mainnets = useMemo(() => {
|
const mainnets = useMemo(() => {
|
||||||
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
|
||||||
return getChainFromChainId(supportedChain);
|
return getChainFromChainId(supportedChain);
|
||||||
}).filter((n) => !n.testnet && !n.deprecated);
|
});
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<Select {...selectProps}>
|
<Select {...selectProps}>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export interface ThirdwebNftMediaProps extends SharedMediaProps {
|
|||||||
/**
|
/**
|
||||||
* This component can be used to render NFTs from the thirdweb SDK.
|
* This component can be used to render NFTs from the thirdweb SDK.
|
||||||
* Props: {@link ThirdwebNftMediaProps}
|
* Props: {@link ThirdwebNftMediaProps}
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```jsx
|
* ```jsx
|
||||||
* import { ThirdwebNftMedia, useContract, useNFT } from "@thirdweb-dev/react";
|
* import { ThirdwebNftMedia, useContract, useNFT } from "@thirdweb-dev/react";
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -9,16 +9,21 @@ import {
|
|||||||
useContext as useWagmiContext,
|
useContext as useWagmiContext,
|
||||||
} from "wagmi";
|
} from "wagmi";
|
||||||
|
|
||||||
|
// exerpt from https://docs.gnosis-safe.io/backend/available-services
|
||||||
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
const CHAIN_ID_TO_GNOSIS_SERVER_URL = {
|
||||||
// mainnet
|
// mainnet
|
||||||
1: "https://safe-transaction.mainnet.gnosis.io",
|
1: "https://safe-transaction-mainnet.safe.global",
|
||||||
// avalanche
|
// avalanche
|
||||||
43114: "https://safe-transaction.avalanche.gnosis.io",
|
43114: "https://safe-transaction-avalanche.safe.global",
|
||||||
// polygon
|
// polygon
|
||||||
137: "https://safe-transaction.polygon.gnosis.io",
|
137: "https://safe-transaction-polygon.safe.global",
|
||||||
// goerli
|
// goerli
|
||||||
5: "https://safe-transaction.goerli.gnosis.io",
|
5: "https://safe-transaction-goerli.safe.global",
|
||||||
};
|
// bsc
|
||||||
|
56: "https://safe-transaction-bsc.safe.global",
|
||||||
|
// optimism
|
||||||
|
10: "https://safe-transaction-optimism.safe.global",
|
||||||
|
} as const;
|
||||||
|
|
||||||
export interface GnosisConnectorArguments {
|
export interface GnosisConnectorArguments {
|
||||||
safeAddress: string;
|
safeAddress: string;
|
||||||
@@ -28,6 +33,8 @@ export interface GnosisConnectorArguments {
|
|||||||
const __IS_SERVER__ = typeof window === "undefined";
|
const __IS_SERVER__ = typeof window === "undefined";
|
||||||
|
|
||||||
export class GnosisSafeConnector extends Connector {
|
export class GnosisSafeConnector extends Connector {
|
||||||
|
static supportedChains = Object.keys(CHAIN_ID_TO_GNOSIS_SERVER_URL);
|
||||||
|
public supportedChains = GnosisSafeConnector.supportedChains;
|
||||||
id = "gnosis";
|
id = "gnosis";
|
||||||
ready = __IS_SERVER__;
|
ready = __IS_SERVER__;
|
||||||
name = "Gnosis Safe";
|
name = "Gnosis Safe";
|
||||||
@@ -60,6 +67,11 @@ export class GnosisSafeConnector extends Connector {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isChainSupported(chainId: string | number) {
|
||||||
|
const id = normalizeChainId(chainId);
|
||||||
|
return !this.isChainUnsupported(id);
|
||||||
|
}
|
||||||
|
|
||||||
private async createSafeSigner() {
|
private async createSafeSigner() {
|
||||||
const signer = await this.previousConnector?.getSigner();
|
const signer = await this.previousConnector?.getSigner();
|
||||||
const safeAddress = this.config?.safeAddress;
|
const safeAddress = this.config?.safeAddress;
|
||||||
@@ -91,7 +103,10 @@ export class GnosisSafeConnector extends Connector {
|
|||||||
import("@gnosis.pm/safe-ethers-lib"),
|
import("@gnosis.pm/safe-ethers-lib"),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const ethAdapter = new safeEthersLib.default({ ethers, signer });
|
const ethAdapter = new safeEthersLib.default({
|
||||||
|
ethers,
|
||||||
|
signerOrProvider: signer,
|
||||||
|
});
|
||||||
|
|
||||||
const safe = await safeCoreSdk.default.create({
|
const safe = await safeCoreSdk.default.create({
|
||||||
ethAdapter: ethAdapter as any,
|
ethAdapter: ethAdapter as any,
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ export class MagicConnector extends Connector {
|
|||||||
const { apiKey, ...options } = this.options;
|
const { apiKey, ...options } = this.options;
|
||||||
const configuration = this.getConfiguration();
|
const configuration = this.getConfiguration();
|
||||||
|
|
||||||
|
const chains = Object.entries(this.options.rpcUrls);
|
||||||
|
if (chains.length > 1) {
|
||||||
|
console.warn(
|
||||||
|
`Magic only supports connecting to one chain at a time. Using the first chain specified in rpcUrls: ${chains[0]}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const [chainId, rpcUrl] = chains[0];
|
||||||
|
this.options.network = {
|
||||||
|
chainId: parseInt(chainId),
|
||||||
|
rpcUrl,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
invariant(
|
invariant(
|
||||||
configuration,
|
configuration,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NATIVE_TOKENS, SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk";
|
|||||||
import { ChainId } from "@thirdweb-dev/sdk";
|
import { ChainId } from "@thirdweb-dev/sdk";
|
||||||
import type { Chain as WagmiChain } from "wagmi";
|
import type { Chain as WagmiChain } from "wagmi";
|
||||||
|
|
||||||
export type Chain = WagmiChain & { deprecated?: boolean };
|
export type Chain = WagmiChain;
|
||||||
const chain: Record<string, Chain> = {
|
const chain: Record<string, Chain> = {
|
||||||
mainnet: {
|
mainnet: {
|
||||||
id: ChainId.Mainnet,
|
id: ChainId.Mainnet,
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {
|
|||||||
RequiredParam,
|
RequiredParam,
|
||||||
requiredParamInvariant,
|
requiredParamInvariant,
|
||||||
} from "../../../core/query-utils/required-param";
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useSDKChainId } from "../../providers/base";
|
import { useSDK, useSDKChainId } from "../../providers/base";
|
||||||
import { getErcs, DropContract, WalletAddress } from "../../types";
|
import { getErcs, DropContract, WalletAddress } from "../../types";
|
||||||
import {
|
import {
|
||||||
cacheKeys,
|
cacheKeys,
|
||||||
@@ -14,8 +14,12 @@ import {
|
|||||||
ClaimCondition,
|
ClaimCondition,
|
||||||
ClaimConditionFetchOptions,
|
ClaimConditionFetchOptions,
|
||||||
ClaimConditionInput,
|
ClaimConditionInput,
|
||||||
|
SnapshotEntryWithProof,
|
||||||
|
fetchCurrencyValue,
|
||||||
|
convertToReadableQuantity,
|
||||||
|
fetchCurrencyMetadata,
|
||||||
} from "@thirdweb-dev/sdk";
|
} from "@thirdweb-dev/sdk";
|
||||||
import { BigNumberish } from "ethers";
|
import { BigNumberish, constants, utils } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +49,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 +64,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 +110,80 @@ 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 +198,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
|
||||||
@@ -242,6 +319,136 @@ export function useClaimIneligibilityReasons(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this to check the claim condition for a given wallet address (including checking for overrides that may exist for that given wallet address).
|
||||||
|
*
|
||||||
|
* @param contract - an instance of a contract that extends the ERC20, ERC721 or ERC1155 spec and implements the `claimConditions` extension.
|
||||||
|
* @param walletAddress - the wallet address to check the active claim condition for
|
||||||
|
* @param tokenId - the id of the token to fetch the claim conditions for (if the contract is an ERC1155 contract)
|
||||||
|
* @returns the active claim conditon for the wallet address or null if there is no active claim condition
|
||||||
|
*
|
||||||
|
* @beta
|
||||||
|
*/
|
||||||
|
export function useActiveClaimConditionForWallet(
|
||||||
|
contract: RequiredParam<DropContract>,
|
||||||
|
walletAddress: RequiredParam<WalletAddress>,
|
||||||
|
tokenId?: BigNumberish,
|
||||||
|
) {
|
||||||
|
const sdk = useSDK();
|
||||||
|
const contractAddress = contract?.getAddress();
|
||||||
|
const { erc1155, erc721, erc20 } = getErcs(contract);
|
||||||
|
return useQueryWithNetwork<ClaimCondition | null>(
|
||||||
|
cacheKeys.extensions.claimConditions.useActiveClaimConditionForWallet(
|
||||||
|
contractAddress,
|
||||||
|
walletAddress || "_NO_WALLET_",
|
||||||
|
tokenId,
|
||||||
|
),
|
||||||
|
async () => {
|
||||||
|
// if we do not have a walletAddress just do the same logic as basic useClaimCondition
|
||||||
|
if (!walletAddress) {
|
||||||
|
if (erc1155) {
|
||||||
|
requiredParamInvariant(
|
||||||
|
tokenId,
|
||||||
|
"tokenId is required for ERC1155 claim conditions",
|
||||||
|
);
|
||||||
|
return erc1155.claimConditions.getActive(tokenId);
|
||||||
|
}
|
||||||
|
if (erc721) {
|
||||||
|
return erc721.claimConditions.getActive();
|
||||||
|
}
|
||||||
|
if (erc20) {
|
||||||
|
return erc20.claimConditions.getActive();
|
||||||
|
}
|
||||||
|
throw new Error("Contract must be ERC721, ERC1155 or ERC20");
|
||||||
|
}
|
||||||
|
invariant(sdk, "sdk is required");
|
||||||
|
let activeGeneralClaimCondition: ClaimCondition | null = null;
|
||||||
|
let claimerProofForWallet: SnapshotEntryWithProof | null = null;
|
||||||
|
|
||||||
|
if (erc1155) {
|
||||||
|
requiredParamInvariant(tokenId, "tokenId is required for ERC1155");
|
||||||
|
const [cc, cp] = await Promise.all([
|
||||||
|
erc1155.claimConditions.getActive(tokenId),
|
||||||
|
erc1155.claimConditions.getClaimerProofs(tokenId, walletAddress),
|
||||||
|
]);
|
||||||
|
activeGeneralClaimCondition = cc;
|
||||||
|
claimerProofForWallet = cp;
|
||||||
|
}
|
||||||
|
if (erc721) {
|
||||||
|
const [cc, cp] = await Promise.all([
|
||||||
|
erc721.claimConditions.getActive(),
|
||||||
|
erc721.claimConditions.getClaimerProofs(walletAddress),
|
||||||
|
]);
|
||||||
|
activeGeneralClaimCondition = cc;
|
||||||
|
claimerProofForWallet = cp;
|
||||||
|
}
|
||||||
|
if (erc20) {
|
||||||
|
const [cc, cp] = await Promise.all([
|
||||||
|
erc20.claimConditions.getActive(),
|
||||||
|
erc20.claimConditions.getClaimerProofs(walletAddress),
|
||||||
|
]);
|
||||||
|
activeGeneralClaimCondition = cc;
|
||||||
|
claimerProofForWallet = cp;
|
||||||
|
}
|
||||||
|
// if there is no active claim condition nothing matters, return null
|
||||||
|
if (!activeGeneralClaimCondition) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there is no claimer proof then just fall back to the active general claim condition
|
||||||
|
if (!claimerProofForWallet) {
|
||||||
|
return activeGeneralClaimCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { maxClaimable, currencyAddress, price } = claimerProofForWallet;
|
||||||
|
|
||||||
|
const currencyWithOverride =
|
||||||
|
currencyAddress || activeGeneralClaimCondition.currencyAddress;
|
||||||
|
|
||||||
|
const currencyMetadata = await fetchCurrencyMetadata(
|
||||||
|
sdk.getProvider(),
|
||||||
|
currencyWithOverride,
|
||||||
|
);
|
||||||
|
|
||||||
|
const normalizedPrize = price
|
||||||
|
? price === "unlimited"
|
||||||
|
? constants.MaxUint256
|
||||||
|
: utils.parseUnits(price, currencyMetadata.decimals)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const priceWithOverride =
|
||||||
|
normalizedPrize || activeGeneralClaimCondition.price;
|
||||||
|
|
||||||
|
const maxClaimableWithOverride =
|
||||||
|
// have to transform this the same way that claim conditions do it in SDK
|
||||||
|
convertToReadableQuantity(maxClaimable, currencyMetadata.decimals) ||
|
||||||
|
activeGeneralClaimCondition.maxClaimablePerWallet;
|
||||||
|
|
||||||
|
const currencyValueWithOverride = await fetchCurrencyValue(
|
||||||
|
sdk.getProvider(),
|
||||||
|
currencyWithOverride,
|
||||||
|
priceWithOverride,
|
||||||
|
);
|
||||||
|
return {
|
||||||
|
// inherit the entire claim condition
|
||||||
|
...activeGeneralClaimCondition,
|
||||||
|
// overwrite all keys that could be changed based on overwrites
|
||||||
|
maxClaimablePerWallet: maxClaimableWithOverride,
|
||||||
|
price: priceWithOverride,
|
||||||
|
currency: currencyWithOverride,
|
||||||
|
currencyAddress: currencyWithOverride,
|
||||||
|
currencyMetadata: currencyValueWithOverride,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 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,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** **********************/
|
/** **********************/
|
||||||
/** WRITE HOOKS **/
|
/** WRITE HOOKS **/
|
||||||
/** **********************/
|
/** **********************/
|
||||||
@@ -368,8 +575,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,
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ export function useUnclaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
|||||||
invariant(erc721, "No ERC721 Contract instance provided");
|
invariant(erc721, "No ERC721 Contract instance provided");
|
||||||
return erc721.totalUnclaimedSupply();
|
return erc721.totalUnclaimedSupply();
|
||||||
}
|
}
|
||||||
invariant(false, "Contract is not an instance of ERC721")
|
invariant(false, "Contract is not an instance of ERC721");
|
||||||
},
|
},
|
||||||
{ enabled: !!erc721 },
|
{ enabled: !!erc721 },
|
||||||
);
|
);
|
||||||
@@ -129,7 +129,7 @@ export function useClaimedNFTSupply(contract: RequiredParam<DropContract>) {
|
|||||||
if (erc721) {
|
if (erc721) {
|
||||||
return erc721.totalClaimedSupply();
|
return erc721.totalClaimedSupply();
|
||||||
}
|
}
|
||||||
invariant(false, "Contract is not an instance of ERC721")
|
invariant(false, "Contract is not an instance of ERC721");
|
||||||
},
|
},
|
||||||
{ enabled: !!erc721 },
|
{ enabled: !!erc721 },
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -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.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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");
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ export function useUser() {
|
|||||||
authConfig,
|
authConfig,
|
||||||
"Please specify an authConfig in the ThirdwebProvider",
|
"Please specify an authConfig in the ThirdwebProvider",
|
||||||
);
|
);
|
||||||
const res = await fetch(`${authConfig.authUrl}/user`);
|
const res = await fetch(`${authConfig.authUrl}/user`, {
|
||||||
|
credentials: "include",
|
||||||
|
});
|
||||||
return (await res.json()) as ThirdwebAuthUser;
|
return (await res.json()) as ThirdwebAuthUser;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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(
|
||||||
() => ({
|
() => ({
|
||||||
|
|||||||
@@ -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 },
|
||||||
@@ -303,6 +313,23 @@ export const cacheKeys = {
|
|||||||
]
|
]
|
||||||
: ["claimConditions", "getIneligibilityReasons", params],
|
: ["claimConditions", "getIneligibilityReasons", params],
|
||||||
),
|
),
|
||||||
|
// combinations of queries cache keys
|
||||||
|
useActiveClaimConditionForWallet: (
|
||||||
|
contractAddress: RequiredParam<ContractAddress>,
|
||||||
|
walletAddress: WalletAddress,
|
||||||
|
tokenId?: BigNumberish,
|
||||||
|
) =>
|
||||||
|
createContractCacheKey(
|
||||||
|
contractAddress,
|
||||||
|
tokenId
|
||||||
|
? [
|
||||||
|
"claimConditions",
|
||||||
|
"useActiveClaimConditionForWallet",
|
||||||
|
{ tokenId, walletAddress },
|
||||||
|
,
|
||||||
|
]
|
||||||
|
: ["claimConditions", "getIneligibilityReasons", { walletAddress }],
|
||||||
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
// primary sale contracts
|
// primary sale contracts
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ export function useUser() {
|
|||||||
authConfig,
|
authConfig,
|
||||||
"Please specify an authConfig in the ThirdwebProvider",
|
"Please specify an authConfig in the ThirdwebProvider",
|
||||||
);
|
);
|
||||||
const res = await fetch(`${authConfig.authUrl}/user`);
|
const res = await fetch(`${authConfig.authUrl}/user`, {
|
||||||
|
credentials: "include",
|
||||||
|
});
|
||||||
return (await res.json()) as ThirdwebAuthUser;
|
return (await res.json()) as ThirdwebAuthUser;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,17 +4,22 @@ import {
|
|||||||
RequiredParam,
|
RequiredParam,
|
||||||
} from "../../../core/query-utils/required-param";
|
} from "../../../core/query-utils/required-param";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { QueryAllParams } from "@thirdweb-dev/sdk";
|
||||||
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
export function nftGetAllQuery(
|
export function nftGetAllQuery(
|
||||||
program: RequiredParam<NFTCollection | NFTDrop>,
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
queryParams?: QueryAllParams,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
queryKey: createSOLProgramQueryKey(program, ["getAll"] as const),
|
queryKey: createSOLProgramQueryKey(program, [
|
||||||
|
"getAll",
|
||||||
|
queryParams,
|
||||||
|
] as const),
|
||||||
|
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
requiredParamInvariant(program, "program is required");
|
requiredParamInvariant(program, "program is required");
|
||||||
return await program.getAll();
|
return program.getAll(queryParams);
|
||||||
},
|
},
|
||||||
enabled: !!program,
|
enabled: !!program,
|
||||||
};
|
};
|
||||||
@@ -40,6 +45,9 @@ export function nftGetAllQuery(
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export function useNFTs(program: RequiredParam<NFTCollection | NFTDrop>) {
|
export function useNFTs(
|
||||||
return useQuery(nftGetAllQuery(program));
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
queryParams?: QueryAllParams,
|
||||||
|
) {
|
||||||
|
return useQuery(nftGetAllQuery(program, queryParams));
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-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,8 @@ 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 { useQuery } from "@tanstack/react-query";
|
||||||
|
import type { NFTCollection, NFTDrop } from "@thirdweb-dev/sdk/solana";
|
||||||
|
|
||||||
|
export function nftTotalSupplyQuery(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
return {
|
||||||
|
queryKey: createSOLProgramQueryKey(program, ["supply"] as const),
|
||||||
|
|
||||||
|
queryFn: async () => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return program.totalSupply();
|
||||||
|
},
|
||||||
|
enabled: !!program,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the totaly supply of NFTs on the program
|
||||||
|
* @param program - The NFT program to get the total supply of
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```jsx
|
||||||
|
* import { useProgram, useTotalSupply } from "@thirdweb-dev/react/solana";
|
||||||
|
*
|
||||||
|
* export default function Component() {
|
||||||
|
* const { program } = useProgram("{{program_address}}");
|
||||||
|
* const { data: supply, isLoading } = useTotalSupply(program);
|
||||||
|
*
|
||||||
|
* return (
|
||||||
|
* <pre>{JSON.stringify(supply)}</pre>
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function useTotalSupply(
|
||||||
|
program: RequiredParam<NFTCollection | NFTDrop>,
|
||||||
|
) {
|
||||||
|
return useQuery(nftTotalSupplyQuery(program));
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
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,
|
||||||
|
UpdateCreatorInput,
|
||||||
|
} 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, updateAll }: UpdateCreatorInput) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateCreators(creators, updateAll);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSettled: () =>
|
||||||
|
queryClient.invalidateQueries(createSOLProgramQueryKey(program)),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
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,
|
||||||
|
UpdateRoyaltySettingsInput,
|
||||||
|
} 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, updateAll }: UpdateRoyaltySettingsInput) => {
|
||||||
|
requiredParamInvariant(program, "program is required");
|
||||||
|
return await program.updateRoyalty(sellerFeeBasisPoints, updateAll);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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,11 @@ 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";
|
||||||
|
export * from "./hooks/nft/useTotalSupply";
|
||||||
|
|
||||||
// NFT Collection
|
// NFT Collection
|
||||||
export * from "./hooks/nft/collection/useMintNFT";
|
export * from "./hooks/nft/collection/useMintNFT";
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,5 +1,169 @@
|
|||||||
# @thirdweb-dev/sdk
|
# @thirdweb-dev/sdk
|
||||||
|
|
||||||
|
## 3.6.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#443](https://github.com/thirdweb-dev/js/pull/443) [`8c6cdaa`](https://github.com/thirdweb-dev/js/commit/8c6cdaa2887fb2cc40d3ee6991233d195d103805) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix signature minting from OpenSea Royalty Filter NFT collection contracts
|
||||||
|
|
||||||
|
## 3.6.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#440](https://github.com/thirdweb-dev/js/pull/440) [`efc56fa`](https://github.com/thirdweb-dev/js/commit/efc56fa5802490ac8ef50037658d046afd89e9a1) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - providers are now re-used if the constructor options are identical leading to better batching, also introduced an additional max batch size param (250 by default)
|
||||||
|
|
||||||
|
## 3.6.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#438](https://github.com/thirdweb-dev/js/pull/438) [`f451da6`](https://github.com/thirdweb-dev/js/commit/f451da6395689a5f89800ee63f34b6175b61f703) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix SigMint detection for OSRF NFT Collection contracts
|
||||||
|
|
||||||
|
- [#416](https://github.com/thirdweb-dev/js/pull/416) [`af3acc6`](https://github.com/thirdweb-dev/js/commit/af3acc6b10751b840e56aef6400da5eea6040df2) Thanks [@adam-maj](https://github.com/adam-maj)! - Add support for AWS KMS
|
||||||
|
|
||||||
|
- [#424](https://github.com/thirdweb-dev/js/pull/424) [`1bfb91d`](https://github.com/thirdweb-dev/js/commit/1bfb91dbf3a39160c987a425813ac5dbb84703ad) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Improve error parsing for other wallets
|
||||||
|
|
||||||
|
- [#436](https://github.com/thirdweb-dev/js/pull/436) [`ee47840`](https://github.com/thirdweb-dev/js/commit/ee478407673b0416e0c1cfe2be11bd6963395348) Thanks [@jnsdls](https://github.com/jnsdls)! - fix #429
|
||||||
|
|
||||||
|
- [#434](https://github.com/thirdweb-dev/js/pull/434) [`def4251`](https://github.com/thirdweb-dev/js/commit/def42511ff5a20d83f9094164dafb87e412571b5) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Remove workaround to fetch NFT owners
|
||||||
|
|
||||||
|
- [#429](https://github.com/thirdweb-dev/js/pull/429) [`034a257`](https://github.com/thirdweb-dev/js/commit/034a257442314c67729f7bafcbe3740cff33fa32) Thanks [@jakeloo](https://github.com/jakeloo)! - Extract more minimal proxy impl address
|
||||||
|
|
||||||
|
- [#418](https://github.com/thirdweb-dev/js/pull/418) [`eca4776`](https://github.com/thirdweb-dev/js/commit/eca47763cd89cc3b7aa57b542971837987540b55) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Increase gas limit for opening packs
|
||||||
|
|
||||||
|
- [#420](https://github.com/thirdweb-dev/js/pull/420) [`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45) Thanks [@jnsdls](https://github.com/jnsdls)! - update deps
|
||||||
|
|
||||||
|
- Updated dependencies [[`f451da6`](https://github.com/thirdweb-dev/js/commit/f451da6395689a5f89800ee63f34b6175b61f703)]:
|
||||||
|
- @thirdweb-dev/contracts-js@1.2.2
|
||||||
|
|
||||||
|
## 3.6.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#408](https://github.com/thirdweb-dev/js/pull/408) [`48797c7`](https://github.com/thirdweb-dev/js/commit/48797c7cf0695965e33eb6bf602be4652f7085a8) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - add `Gasless` as a possible extension to feature-detect
|
||||||
|
|
||||||
|
- [#402](https://github.com/thirdweb-dev/js/pull/402) [`83dcaf7`](https://github.com/thirdweb-dev/js/commit/83dcaf70584af8c5cdf0427f9fc1ba82d89f0887) Thanks [@adam-maj](https://github.com/adam-maj)! - Expose sdk.fromWallet and wallet classes
|
||||||
|
|
||||||
|
- [#412](https://github.com/thirdweb-dev/js/pull/412) [`f03be39`](https://github.com/thirdweb-dev/js/commit/f03be398e0d7b75c9c5b4fb643f35903e89a17e7) Thanks [@easonchai](https://github.com/easonchai)! - Correctly handle contracts using the SignatureMintERC1155 ContractKit extension
|
||||||
|
|
||||||
|
- [#283](https://github.com/thirdweb-dev/js/pull/283) [`2eaa67a`](https://github.com/thirdweb-dev/js/commit/2eaa67acbe21464e7715d0b696afdc024460a44d) Thanks [@adam-maj](https://github.com/adam-maj)! - AppURI detection now enabled
|
||||||
|
|
||||||
|
- [#414](https://github.com/thirdweb-dev/js/pull/414) [`47f8945`](https://github.com/thirdweb-dev/js/commit/47f8945325447874b1ace0359919c1d54fd55436) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Improve error parsing
|
||||||
|
|
||||||
|
## 3.6.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#405](https://github.com/thirdweb-dev/js/pull/405) [`ccb7db4`](https://github.com/thirdweb-dev/js/commit/ccb7db48739b8dddcb2c032b3b6e3e5200485715) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Add updateAll param to creators and royalty update hooks for Solana
|
||||||
|
|
||||||
|
- [#404](https://github.com/thirdweb-dev/js/pull/404) [`9151aa7`](https://github.com/thirdweb-dev/js/commit/9151aa7dc80754a7aa4fd3f6ce0207bccbb6451f) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - expose `getDefaultTrustedForwarders` helper function
|
||||||
|
|
||||||
|
- [#305](https://github.com/thirdweb-dev/js/pull/305) [`5a01c53`](https://github.com/thirdweb-dev/js/commit/5a01c537e30bd7ef562aad1012413990de6faedf) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Update to Metaplex 0.17
|
||||||
|
|
||||||
|
## 3.6.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#398](https://github.com/thirdweb-dev/js/pull/398) [`15514f1`](https://github.com/thirdweb-dev/js/commit/15514f190a844d809ae5b1edb580aab46a682485) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - add `defaultValue` to constructorParams schema for releases
|
||||||
|
|
||||||
|
- [#388](https://github.com/thirdweb-dev/js/pull/388) [`7c0744a`](https://github.com/thirdweb-dev/js/commit/7c0744a006e78987ad8b271b2c64f4bac7759510) Thanks [@adam-maj](https://github.com/adam-maj)! - Add support for total supply and pagination on get all
|
||||||
|
|
||||||
|
- [#395](https://github.com/thirdweb-dev/js/pull/395) [`f8bceec`](https://github.com/thirdweb-dev/js/commit/f8bceec10c60b30dc3d6f45926e2a9e018202578) Thanks [@jnsdls](https://github.com/jnsdls)! - [Solana] - fix claim condition reset to native token from custom
|
||||||
|
|
||||||
|
- [#399](https://github.com/thirdweb-dev/js/pull/399) [`887af24`](https://github.com/thirdweb-dev/js/commit/887af24450e316c2ea390cd49c0563cebe793c0f) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - fix custom error handling for null-ish error values
|
||||||
|
|
||||||
|
- [#390](https://github.com/thirdweb-dev/js/pull/390) [`96bd92e`](https://github.com/thirdweb-dev/js/commit/96bd92e724ec7d880d23348071b26ab8c21dd868) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SDK] Expose `getAllDetectedFeatures(ABI)` helper function
|
||||||
|
|
||||||
|
## 3.6.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#364](https://github.com/thirdweb-dev/js/pull/364) [`7cb8e59`](https://github.com/thirdweb-dev/js/commit/7cb8e59be48dc923316eb36ab43a1bef7364f6b1) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Enable new Drop contracts
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#382](https://github.com/thirdweb-dev/js/pull/382) [`0ed77d2`](https://github.com/thirdweb-dev/js/commit/0ed77d2c9e7526444ef660aab82a950865234aa6) Thanks [@jnsdls](https://github.com/jnsdls)! - Add `constructorParams` to `ExtraPublishMetadataSchemaInput` schema to support better deploys from releases.
|
||||||
|
|
||||||
|
- [#385](https://github.com/thirdweb-dev/js/pull/385) [`04a47e8`](https://github.com/thirdweb-dev/js/commit/04a47e8971d28da2532ebd9db824eeb459c17bd4) Thanks [@adam-maj](https://github.com/adam-maj)! - Add retroactive royalty and creator setting
|
||||||
|
|
||||||
|
## 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
|
## 3.4.0
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"main": "dist/thirdweb-dev-sdk-evm-wallets.cjs.js",
|
||||||
|
"module": "dist/thirdweb-dev-sdk-evm-wallets.esm.js"
|
||||||
|
}
|
||||||
+33
-16
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/sdk",
|
"name": "@thirdweb-dev/sdk",
|
||||||
"version": "3.4.0",
|
"version": "3.6.6",
|
||||||
"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",
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
"module": "./solana/dist/thirdweb-dev-sdk-solana.esm.js",
|
"module": "./solana/dist/thirdweb-dev-sdk-solana.esm.js",
|
||||||
"default": "./solana/dist/thirdweb-dev-sdk-solana.cjs.js"
|
"default": "./solana/dist/thirdweb-dev-sdk-solana.cjs.js"
|
||||||
},
|
},
|
||||||
|
"./evm/wallets": {
|
||||||
|
"module": "./evm/wallets/dist/thirdweb-dev-sdk-evm-wallets.esm.js",
|
||||||
|
"default": "./evm/wallets/dist/thirdweb-dev-sdk-evm-wallets.cjs.js"
|
||||||
|
},
|
||||||
"./solana/server": {
|
"./solana/server": {
|
||||||
"module": "./solana/server/dist/thirdweb-dev-sdk-solana-server.esm.js",
|
"module": "./solana/server/dist/thirdweb-dev-sdk-solana-server.esm.js",
|
||||||
"default": "./solana/server/dist/thirdweb-dev-sdk-solana-server.cjs.js"
|
"default": "./solana/server/dist/thirdweb-dev-sdk-solana-server.cjs.js"
|
||||||
@@ -28,6 +32,7 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"dist/",
|
"dist/",
|
||||||
"evm/",
|
"evm/",
|
||||||
|
"wallets/",
|
||||||
"solana/",
|
"solana/",
|
||||||
"server/"
|
"server/"
|
||||||
],
|
],
|
||||||
@@ -35,6 +40,7 @@
|
|||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"index.ts",
|
"index.ts",
|
||||||
"evm/index.ts",
|
"evm/index.ts",
|
||||||
|
"evm/wallets/index.ts",
|
||||||
"solana/index.ts",
|
"solana/index.ts",
|
||||||
"solana/server/index.ts"
|
"solana/server/index.ts"
|
||||||
],
|
],
|
||||||
@@ -57,7 +63,7 @@
|
|||||||
"test:evm:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/evm/.mocharc.json' --timeout 30000 --parallel './test/evm/**/*.test.ts'",
|
"test:evm:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/evm/.mocharc.json' --timeout 30000 --parallel './test/evm/**/*.test.ts'",
|
||||||
"test:evm": "make test-evm",
|
"test:evm": "make test-evm",
|
||||||
"test:evm:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/evm/.mocharc.json' --timeout 30000",
|
"test:evm:single": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/evm/.mocharc.json' --timeout 30000",
|
||||||
"node:solana:start": "DEBUG='amman:(info|error|debug)' amman start",
|
"node:solana:start": "DEBUG='amman:(info|error|debug)' amman start --forceClone",
|
||||||
"node:solana:stop": "amman stop",
|
"node:solana:stop": "amman stop",
|
||||||
"test:solana:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/solana/.mocharc.json' --timeout 30000 --parallel './test/solana/**/*.test.ts'",
|
"test:solana:all": "SWC_NODE_PROJECT=./tsconfig.test.json mocha --config './test/solana/.mocharc.json' --timeout 30000 --parallel './test/solana/**/*.test.ts'",
|
||||||
"test:solana": "make test-sol",
|
"test:solana": "make test-sol",
|
||||||
@@ -65,18 +71,19 @@
|
|||||||
"push": "yalc push"
|
"push": "yalc push"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@metaplex-foundation/amman": "0.10.0",
|
"@aws-sdk/client-secrets-manager": "^3.216.0",
|
||||||
"@metaplex-foundation/amman-client": "0.2.1",
|
"@metaplex-foundation/amman": "^0.12.0",
|
||||||
|
"@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",
|
||||||
"@nomiclabs/hardhat-ethers": "2.0.5",
|
"@nomiclabs/hardhat-ethers": "^2.0.5",
|
||||||
"@preconstruct/cli": "^2.2.1",
|
"@preconstruct/cli": "^2.2.1",
|
||||||
"@swc-node/register": "^1.5.1",
|
"@swc-node/register": "^1.5.1",
|
||||||
"@swc/core": "^1.2.177",
|
"@swc/core": "^1.2.177",
|
||||||
"@types/chai": "^4.3.3",
|
"@types/chai": "^4.3.3",
|
||||||
"@types/deep-equal-in-any-order": "^1.0.1",
|
"@types/deep-equal-in-any-order": "^1.0.1",
|
||||||
"@types/mocha": "^9.1.1",
|
"@types/mocha": "^10.0.0",
|
||||||
"@types/node": "^18.0.0",
|
"@types/node": "^18.0.0",
|
||||||
"@types/uuid": "^8.3.3",
|
"@types/uuid": "^8.3.3",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
"@typescript-eslint/eslint-plugin": "^5.33.0",
|
||||||
@@ -89,28 +96,38 @@
|
|||||||
"eslint-plugin-inclusive-language": "^2.2.0",
|
"eslint-plugin-inclusive-language": "^2.2.0",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
"eslint-plugin-tsdoc": "^0.2.16",
|
"eslint-plugin-tsdoc": "^0.2.16",
|
||||||
"ethers": "^5.7.0",
|
"ethers": "^5.7.2",
|
||||||
|
"ethers-aws-kms-signer": "^1.3.2",
|
||||||
"hardhat": "^2.9.3",
|
"hardhat": "^2.9.3",
|
||||||
"mocha": "^10.0.0",
|
"mocha": "^10.0.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"ethers": "^5"
|
"@aws-sdk/client-secrets-manager": "^3.215.0",
|
||||||
|
"ethers": "^5",
|
||||||
|
"ethers-aws-kms-signer": "^1.3.2"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@aws-sdk/client-secrets-manager": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"ethers-aws-kms-signer": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@metaplex-foundation/js": "0.15.0",
|
"@metaplex-foundation/js": "^0.17.6",
|
||||||
"@metaplex-foundation/mpl-token-metadata": "2.2.2",
|
"@metaplex-foundation/mpl-token-metadata": "^2.3.3",
|
||||||
"@project-serum/anchor": "0.25.0",
|
"@project-serum/anchor": "^0.25.0",
|
||||||
"@solana/spl-token": "0.2.0",
|
"@solana/spl-token": "^0.3.5",
|
||||||
"@solana/web3.js": "1.62.0",
|
"@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": "^5.0.0",
|
||||||
"fast-deep-equal": "^3.1.3",
|
"fast-deep-equal": "^3.1.3",
|
||||||
"merkletreejs": "^0.2.24",
|
"merkletreejs": "^0.2.24",
|
||||||
"tiny-invariant": "^1.2.0",
|
"tiny-invariant": "^1.2.0",
|
||||||
@@ -129,4 +146,4 @@
|
|||||||
"url": "https://github.com/thirdweb-dev/js/issues"
|
"url": "https://github.com/thirdweb-dev/js/issues"
|
||||||
},
|
},
|
||||||
"author": "thirdweb eng <[email protected]>"
|
"author": "thirdweb eng <[email protected]>"
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,25 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export const DEFAULT_QUERY_ALL_COUNT = 100;
|
export const DEFAULT_QUERY_ALL_COUNT = 100;
|
||||||
|
|
||||||
|
export const QueryAllParamsSchema = z
|
||||||
|
.object({
|
||||||
|
start: z.number().default(0),
|
||||||
|
count: z.number().default(DEFAULT_QUERY_ALL_COUNT),
|
||||||
|
})
|
||||||
|
.default({
|
||||||
|
start: 0,
|
||||||
|
count: DEFAULT_QUERY_ALL_COUNT,
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pagination Parameters
|
* Pagination Parameters
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export interface QueryAllParams {
|
export type QueryAllParams = Exclude<
|
||||||
/**
|
z.input<typeof QueryAllParamsSchema>,
|
||||||
* the index to start from (default: 0)
|
undefined
|
||||||
*/
|
>;
|
||||||
start?: number;
|
|
||||||
/**
|
|
||||||
* how many items to return (default: 100)
|
|
||||||
*/
|
|
||||||
count?: number;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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 { IClaimCondition } from "@thirdweb-dev/contracts-js/dist/declarations/src/Drop";
|
||||||
|
import { IDropClaimCondition_V2 } from "@thirdweb-dev/contracts-js/dist/declarations/src/IDropERC20_V2";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import {
|
import {
|
||||||
BigNumber,
|
BigNumber,
|
||||||
@@ -45,6 +50,7 @@ import {
|
|||||||
* @returns - `overrides` and `proofs` as an object.
|
* @returns - `overrides` and `proofs` as an object.
|
||||||
*/
|
*/
|
||||||
export async function prepareClaim(
|
export async function prepareClaim(
|
||||||
|
addressToClaim: string,
|
||||||
quantity: BigNumberish,
|
quantity: BigNumberish,
|
||||||
activeClaimCondition: ClaimCondition,
|
activeClaimCondition: ClaimCondition,
|
||||||
merkleMetadataFetcher: () => Promise<Record<string, string>>,
|
merkleMetadataFetcher: () => Promise<Record<string, string>>,
|
||||||
@@ -52,27 +58,57 @@ 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();
|
let maxClaimable = convertQuantityToBigNumber(
|
||||||
let maxClaimable = BigNumber.from(0);
|
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,11 @@ export async function prepareClaim(
|
|||||||
return {
|
return {
|
||||||
overrides,
|
overrides,
|
||||||
proofs,
|
proofs,
|
||||||
maxQuantityPerTransaction: maxClaimable,
|
maxClaimable,
|
||||||
price,
|
price: pricePerToken,
|
||||||
currencyAddress,
|
currencyAddress: currencyAddress,
|
||||||
|
priceInProof,
|
||||||
|
currencyAddressInProof,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +187,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 +200,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 +215,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);
|
||||||
@@ -231,53 +287,20 @@ export async function updateExistingClaimConditions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the proof for the current signer for a particular wallet.
|
* @internal
|
||||||
*
|
* Decorates claim conditions with merkle roots from snapshots if present
|
||||||
* @param addressToClaim
|
|
||||||
* @param merkleRoot - The merkle root of the condition to check.
|
|
||||||
* @param tokenDecimals
|
|
||||||
* @param merkleMetadata
|
|
||||||
* @param storage
|
|
||||||
* @returns - The proof for the current signer for the specified condition.
|
|
||||||
*/
|
|
||||||
export async function getClaimerProofs(
|
|
||||||
addressToClaim: string,
|
|
||||||
merkleRoot: string,
|
|
||||||
tokenDecimals: number,
|
|
||||||
merkleMetadata: Record<string, string>,
|
|
||||||
storage: ThirdwebStorage,
|
|
||||||
): Promise<{ maxClaimable: BigNumber; proof: string[] }> {
|
|
||||||
const claim = await fetchSnapshotEntryForAddress(
|
|
||||||
addressToClaim,
|
|
||||||
merkleRoot,
|
|
||||||
merkleMetadata,
|
|
||||||
storage,
|
|
||||||
);
|
|
||||||
if (!claim) {
|
|
||||||
return {
|
|
||||||
proof: [],
|
|
||||||
maxClaimable: BigNumber.from(0),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
proof: claim.proof,
|
|
||||||
maxClaimable: ethers.utils.parseUnits(claim.maxClaimable, tokenDecimals),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create and uploads snapshots + converts claim conditions to contract format
|
|
||||||
* @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 +308,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 +324,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 +381,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 +491,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 +508,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(
|
||||||
@@ -401,13 +520,17 @@ export async function transformResultToClaimCondition(
|
|||||||
pm.supplyClaimed,
|
pm.supplyClaimed,
|
||||||
tokenDecimals,
|
tokenDecimals,
|
||||||
);
|
);
|
||||||
|
let resolvedMetadata;
|
||||||
|
if (pm.metadata) {
|
||||||
|
resolvedMetadata = await storage.downloadJSON(pm.metadata);
|
||||||
|
}
|
||||||
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 +539,19 @@ export async function transformResultToClaimCondition(
|
|||||||
snapshot: shouldDownloadSnapshot
|
snapshot: shouldDownloadSnapshot
|
||||||
? await fetchSnapshot(pm.merkleRoot, merkleMetadata, storage)
|
? await fetchSnapshot(pm.merkleRoot, merkleMetadata, storage)
|
||||||
: undefined,
|
: undefined,
|
||||||
|
metadata: resolvedMetadata,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 +559,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";
|
||||||
@@ -33,6 +33,14 @@ export function cleanCurrencyAddress(currencyAddress: string): string {
|
|||||||
return currencyAddress;
|
return currencyAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
* @param inputPrice
|
||||||
|
* @param currencyAddress
|
||||||
|
* @returns
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
export async function normalizePriceValue(
|
export async function normalizePriceValue(
|
||||||
provider: providers.Provider,
|
provider: providers.Provider,
|
||||||
inputPrice: Price,
|
inputPrice: Price,
|
||||||
@@ -42,6 +50,13 @@ export async function normalizePriceValue(
|
|||||||
return utils.parseUnits(AmountSchema.parse(inputPrice), metadata.decimals);
|
return utils.parseUnits(AmountSchema.parse(inputPrice), metadata.decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param provider
|
||||||
|
* @param asset
|
||||||
|
* @returns
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
export async function fetchCurrencyMetadata(
|
export async function fetchCurrencyMetadata(
|
||||||
provider: providers.Provider,
|
provider: providers.Provider,
|
||||||
asset: string,
|
asset: string,
|
||||||
@@ -73,6 +88,14 @@ export async function fetchCurrencyMetadata(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param providerOrSigner
|
||||||
|
* @param asset
|
||||||
|
* @param price
|
||||||
|
* @returns
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
export async function fetchCurrencyValue(
|
export async function fetchCurrencyValue(
|
||||||
providerOrSigner: providers.Provider,
|
providerOrSigner: providers.Provider,
|
||||||
asset: string,
|
asset: string,
|
||||||
|
|||||||
@@ -394,20 +394,16 @@ export async function convertToTWError(
|
|||||||
contractInterface: ethers.utils.Interface,
|
contractInterface: ethers.utils.Interface,
|
||||||
): Promise<TransactionError> {
|
): Promise<TransactionError> {
|
||||||
let raw: string;
|
let raw: string;
|
||||||
if (error.data) {
|
if (typeof error === "object") {
|
||||||
// metamask errors comes as objects, apply parsing on data object
|
// metamask errors comes as objects, apply parsing on data object
|
||||||
// TODO test errors from other wallets
|
raw = JSON.stringify(error);
|
||||||
raw = JSON.stringify(error.data);
|
|
||||||
} else if (error instanceof Error) {
|
|
||||||
// regular ethers.js error
|
|
||||||
raw = error.message;
|
|
||||||
} else {
|
} else {
|
||||||
// not sure what this is, just throw it back
|
// not sure what this is, just throw it back
|
||||||
raw = error.toString();
|
raw = error.toString();
|
||||||
}
|
}
|
||||||
const reason =
|
const reason =
|
||||||
error.reason ||
|
parseMessageParts(/.*?"message[^a-zA-Z0-9]*([^"\\]*).*?/, raw) ||
|
||||||
parseMessageParts(/.*?"message[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
parseMessageParts(/.*?"reason[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
||||||
const data = parseMessageParts(/.*?"data[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
const data = parseMessageParts(/.*?"data[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
||||||
const rpcUrl = parseMessageParts(/.*?"url[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
const rpcUrl = parseMessageParts(/.*?"url[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
||||||
let from = parseMessageParts(/.*?"from[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
let from = parseMessageParts(/.*?"from[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
||||||
@@ -459,9 +455,12 @@ function parseMessageParts(regex: RegExp, raw: string): string {
|
|||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
export function includesErrorMessage(err: any, message: string): boolean {
|
export function includesErrorMessage(err: any, message: string): boolean {
|
||||||
|
if (!err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
(err && err.toString().includes(message)) ||
|
(err && err.toString().includes(message)) ||
|
||||||
(err.message && err.message.toString().includes(message)) ||
|
(err && err.message && err.message.toString().includes(message)) ||
|
||||||
(err.error && err.error.toString().includes(message))
|
(err && err.error && err.error.toString().includes(message))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ 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 {
|
||||||
|
Abi,
|
||||||
AbiEvent,
|
AbiEvent,
|
||||||
AbiFunction,
|
AbiFunction,
|
||||||
AbiSchema,
|
AbiSchema,
|
||||||
@@ -23,7 +25,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";
|
||||||
|
|
||||||
@@ -32,26 +33,57 @@ import { z } from "zod";
|
|||||||
* @param abi
|
* @param abi
|
||||||
* @param feature
|
* @param feature
|
||||||
*/
|
*/
|
||||||
function matchesAbiInterface(
|
function matchesAbiInterface(abi: Abi, feature: Feature): boolean {
|
||||||
abi: z.input<typeof AbiSchema>,
|
|
||||||
feature: Feature,
|
|
||||||
): boolean {
|
|
||||||
// returns true if all the functions in `interfaceToMatch` are found in `contract` (removing any duplicates)
|
// returns true if all the functions in `interfaceToMatch` are found in `contract` (removing any duplicates)
|
||||||
const contractFn = [
|
return hasMatchingAbi(abi, feature.abis);
|
||||||
...new Set(extractFunctionsFromAbi(abi).map((f) => f.name)),
|
}
|
||||||
];
|
|
||||||
const interfaceFn = [
|
|
||||||
...new Set(
|
|
||||||
feature.abis
|
|
||||||
.flatMap((i: any) => extractFunctionsFromAbi(i))
|
|
||||||
.map((f: AbiFunction) => f.name),
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
/**
|
||||||
contractFn.filter((k) => interfaceFn.includes(k)).length ===
|
* @internal
|
||||||
interfaceFn.length
|
* @param contractWrapper
|
||||||
|
* @param abi
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function matchesPrebuiltAbi<T extends BaseContract>(
|
||||||
|
contractWrapper: ContractWrapper<BaseContract>,
|
||||||
|
abi: Abi,
|
||||||
|
): contractWrapper is ContractWrapper<T> {
|
||||||
|
return hasMatchingAbi(contractWrapper.abi as Abi, [abi]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @param contractAbi
|
||||||
|
* @param featureAbis
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function hasMatchingAbi(contractAbi: Abi, featureAbis: readonly Abi[]) {
|
||||||
|
const contractFn = extractFunctionsFromAbi(contractAbi);
|
||||||
|
const interfaceFn = featureAbis.flatMap((i: any) =>
|
||||||
|
extractFunctionsFromAbi(i),
|
||||||
);
|
);
|
||||||
|
// match every function and their arguments
|
||||||
|
const intersection = contractFn.filter((fn) => {
|
||||||
|
const match = interfaceFn.find(
|
||||||
|
(iFn) =>
|
||||||
|
iFn.name === fn.name &&
|
||||||
|
iFn.inputs.length === fn.inputs.length &&
|
||||||
|
iFn.inputs.every((i, index) => {
|
||||||
|
if (i.type === "tuple" || i.type === "tuple[]") {
|
||||||
|
// check that all properties in the tuple are the same type
|
||||||
|
return (
|
||||||
|
i.type === fn.inputs[index].type &&
|
||||||
|
i.components?.every((c, cIndex) => {
|
||||||
|
return c.type === fn.inputs[index].components?.[cIndex]?.type;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return i.type === fn.inputs[index].type;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return match !== undefined;
|
||||||
|
});
|
||||||
|
return intersection.length === interfaceFn.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -145,7 +177,7 @@ export function extractFunctionParamsFromAbi(
|
|||||||
* @param metadata
|
* @param metadata
|
||||||
*/
|
*/
|
||||||
export function extractFunctionsFromAbi(
|
export function extractFunctionsFromAbi(
|
||||||
abi: z.input<typeof AbiSchema>,
|
abi: Abi,
|
||||||
metadata?: Record<string, any>,
|
metadata?: Record<string, any>,
|
||||||
): AbiFunction[] {
|
): AbiFunction[] {
|
||||||
const functions = (abi || []).filter((el) => el.type === "function");
|
const functions = (abi || []).filter((el) => el.type === "function");
|
||||||
@@ -178,7 +210,7 @@ export function extractFunctionsFromAbi(
|
|||||||
* @param metadata
|
* @param metadata
|
||||||
*/
|
*/
|
||||||
export function extractEventsFromAbi(
|
export function extractEventsFromAbi(
|
||||||
abi: z.input<typeof AbiSchema>,
|
abi: Abi,
|
||||||
metadata?: Record<string, any>,
|
metadata?: Record<string, any>,
|
||||||
): AbiEvent[] {
|
): AbiEvent[] {
|
||||||
const events = (abi || []).filter((el) => el.type === "event");
|
const events = (abi || []).filter((el) => el.type === "event");
|
||||||
@@ -234,6 +266,42 @@ function toJSType(
|
|||||||
return jsType;
|
return jsType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @param bytecode
|
||||||
|
*/
|
||||||
|
export function extractMinimalProxyImplementationAddress(
|
||||||
|
bytecode: string,
|
||||||
|
): string | undefined {
|
||||||
|
// EIP-1167 clone minimal proxy - https://eips.ethereum.org/EIPS/eip-1167
|
||||||
|
if (bytecode.startsWith("0x363d3d373d3d3d363d73")) {
|
||||||
|
const implementationAddress = bytecode.slice(22, 62);
|
||||||
|
return `0x${implementationAddress}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minimal Proxy with receive() from 0xSplits - https://github.com/0xSplits/splits-contracts/blob/c7b741926ec9746182d0d1e2c4c2046102e5d337/contracts/libraries/Clones.sol
|
||||||
|
if (bytecode.startsWith("0x36603057343d5230")) {
|
||||||
|
// +40 = size of addr
|
||||||
|
const implementationAddress = bytecode.slice(122, 122 + 40);
|
||||||
|
return `0x${implementationAddress}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0age's minimal proxy - https://medium.com/coinmonks/the-more-minimal-proxy-5756ae08ee48
|
||||||
|
if (bytecode.startsWith("0x3d3d3d3d363d3d37363d73")) {
|
||||||
|
// +40 = size of addr
|
||||||
|
const implementationAddress = bytecode.slice(24, 24 + 40);
|
||||||
|
return `0x${implementationAddress}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// vyper's minimal proxy (uniswap v1) - https://etherscan.io/address/0x09cabec1ead1c0ba254b09efb3ee13841712be14#code
|
||||||
|
if (bytecode.startsWith("0x366000600037611000600036600073")) {
|
||||||
|
const implementationAddress = bytecode.slice(32, 32 + 40);
|
||||||
|
return `0x${implementationAddress}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* @param address
|
* @param address
|
||||||
@@ -250,14 +318,20 @@ export async function resolveContractUriFromAddress(
|
|||||||
`Contract at ${address} does not exist on chain '${chain.name}' (chainId: ${chain.chainId})`,
|
`Contract at ${address} does not exist on chain '${chain.name}' (chainId: ${chain.chainId})`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// EIP-1167 clone proxy - https://eips.ethereum.org/EIPS/eip-1167
|
|
||||||
if (bytecode.startsWith("0x363d3d373d3d3d363d")) {
|
try {
|
||||||
const implementationAddress = bytecode.slice(22, 62);
|
const implementationAddress =
|
||||||
return await resolveContractUriFromAddress(
|
extractMinimalProxyImplementationAddress(bytecode);
|
||||||
`0x${implementationAddress}`,
|
if (implementationAddress) {
|
||||||
provider,
|
return await resolveContractUriFromAddress(
|
||||||
);
|
implementationAddress,
|
||||||
|
provider,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
// EIP-1967 proxy storage slots - https://eips.ethereum.org/EIPS/eip-1967
|
// EIP-1967 proxy storage slots - https://eips.ethereum.org/EIPS/eip-1967
|
||||||
try {
|
try {
|
||||||
const proxyStorage = await provider.getStorageAt(
|
const proxyStorage = await provider.getStorageAt(
|
||||||
@@ -405,7 +479,9 @@ export async function fetchSourceFilesFromMetadata(
|
|||||||
Object.entries(publishedMetadata.metadata.sources).map(
|
Object.entries(publishedMetadata.metadata.sources).map(
|
||||||
async ([path, info]) => {
|
async ([path, info]) => {
|
||||||
const urls = (info as any).urls as string[];
|
const urls = (info as any).urls as string[];
|
||||||
const ipfsLink = urls.find((url) => url.includes("ipfs"));
|
const ipfsLink = urls
|
||||||
|
? urls.find((url) => url.includes("ipfs"))
|
||||||
|
: undefined;
|
||||||
if (ipfsLink) {
|
if (ipfsLink) {
|
||||||
const ipfsHash = ipfsLink.split("ipfs/")[1];
|
const ipfsHash = ipfsLink.split("ipfs/")[1];
|
||||||
// 5 sec timeout for sources that haven't been uploaded to ipfs
|
// 5 sec timeout for sources that haven't been uploaded to ipfs
|
||||||
@@ -423,7 +499,9 @@ export async function fetchSourceFilesFromMetadata(
|
|||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
filename: path,
|
filename: path,
|
||||||
source: "Could not find source for this contract",
|
source:
|
||||||
|
(info as any).content ||
|
||||||
|
"Could not find source for this contract",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -489,7 +567,7 @@ export async function fetchExtendedReleaseMetadata(
|
|||||||
* @returns the nested struct of all features and whether they're detected in the abi
|
* @returns the nested struct of all features and whether they're detected in the abi
|
||||||
*/
|
*/
|
||||||
export function detectFeatures(
|
export function detectFeatures(
|
||||||
abi: z.input<typeof AbiSchema>,
|
abi: Abi,
|
||||||
features: Record<string, Feature> = SUPPORTED_FEATURES,
|
features: Record<string, Feature> = SUPPORTED_FEATURES,
|
||||||
): Record<string, FeatureWithEnabled> {
|
): Record<string, FeatureWithEnabled> {
|
||||||
const results: Record<string, FeatureWithEnabled> = {};
|
const results: Record<string, FeatureWithEnabled> = {};
|
||||||
@@ -506,6 +584,48 @@ export function detectFeatures(
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractFeatures(
|
||||||
|
input: Record<string, FeatureWithEnabled>,
|
||||||
|
enabledExtensions: FeatureWithEnabled[],
|
||||||
|
) {
|
||||||
|
if (!input) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (const extensionKey in input) {
|
||||||
|
const extension = input[extensionKey];
|
||||||
|
// if extension is enabled, then add it to enabledFeatures
|
||||||
|
if (extension.enabled) {
|
||||||
|
enabledExtensions.push(extension);
|
||||||
|
}
|
||||||
|
// recurse
|
||||||
|
extractFeatures(extension.features, enabledExtensions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the detected features in the abi
|
||||||
|
* @param abi - parsed array of abi entries
|
||||||
|
* @returns array of all detected extensions with full information on each feature
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function getAllDetectedFeatures(abi: Abi): FeatureWithEnabled[] {
|
||||||
|
const features: FeatureWithEnabled[] = [];
|
||||||
|
extractFeatures(detectFeatures(abi), features);
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the detected features names in the abi
|
||||||
|
* @param abi - parsed array of abi entries
|
||||||
|
* @returns array of all detected features names
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export function getAllDetectedFeatureNames(abi: Abi): string[] {
|
||||||
|
const features: FeatureWithEnabled[] = [];
|
||||||
|
extractFeatures(detectFeatures(abi), features);
|
||||||
|
return features.map((f) => f.name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given ABI supports a given feature
|
* Checks whether the given ABI supports a given feature
|
||||||
* @internal
|
* @internal
|
||||||
|
|||||||
@@ -3,3 +3,10 @@ export * from "./snapshots";
|
|||||||
export * from "./role";
|
export * from "./role";
|
||||||
export * from "./feature-detection";
|
export * from "./feature-detection";
|
||||||
export * from "./version-checker";
|
export * from "./version-checker";
|
||||||
|
// export helpful util
|
||||||
|
export {
|
||||||
|
fetchCurrencyValue,
|
||||||
|
fetchCurrencyMetadata,
|
||||||
|
normalizePriceValue,
|
||||||
|
} from "./currency";
|
||||||
|
export { convertToReadableQuantity } from "./claim-conditions";
|
||||||
|
|||||||
@@ -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,
|
||||||
@@ -89,13 +89,18 @@ export async function handleTokenApproval(
|
|||||||
tokenId: BigNumberish,
|
tokenId: BigNumberish,
|
||||||
from: string,
|
from: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const erc165 = new Contract(
|
const erc165 = new ContractWrapper<IERC165>(
|
||||||
|
signerOrProvider,
|
||||||
assetContract,
|
assetContract,
|
||||||
ERC165Abi,
|
ERC165Abi,
|
||||||
signerOrProvider,
|
{},
|
||||||
) as IERC165;
|
);
|
||||||
const isERC721 = await erc165.supportsInterface(InterfaceId_IERC721);
|
const isERC721 = await erc165.readContract.supportsInterface(
|
||||||
const isERC1155 = await erc165.supportsInterface(InterfaceId_IERC1155);
|
InterfaceId_IERC721,
|
||||||
|
);
|
||||||
|
const isERC1155 = await erc165.readContract.supportsInterface(
|
||||||
|
InterfaceId_IERC1155,
|
||||||
|
);
|
||||||
// check for token approval
|
// check for token approval
|
||||||
if (isERC721) {
|
if (isERC721) {
|
||||||
const asset = new ContractWrapper<IERC721>(
|
const asset = new ContractWrapper<IERC721>(
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user