Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96d2dfd25d | ||
|
|
5862c558fb | ||
|
|
e913e0daa9 | ||
|
|
f7a74a3b7c | ||
|
|
73883f56d0 | ||
|
|
e47085af92 | ||
|
|
f525e2cc23 | ||
|
|
af85389dc0 | ||
|
|
ccb4ce8d00 | ||
|
|
4cdd0bd634 | ||
|
|
ea95c5f609 | ||
|
|
699a2b16fb | ||
|
|
a8267f912d | ||
|
|
c673e39f23 | ||
|
|
08d04fe4dc | ||
|
|
cbf5508bd5 | ||
|
|
3731459d33 | ||
|
|
64f24f1bb1 | ||
|
|
cac6c30bca | ||
|
|
e7740a59db | ||
|
|
7a37e564fd | ||
|
|
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 |
@@ -13,7 +13,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build and Test
|
name: Build and Test
|
||||||
# timeout-minutes: 15
|
timeout-minutes: 30
|
||||||
runs-on: ubuntu-latest-32
|
runs-on: ubuntu-latest-32
|
||||||
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
integration-tests:
|
integration-tests:
|
||||||
timeout-minutes: 60
|
timeout-minutes: 30
|
||||||
runs-on: ubuntu-latest-32
|
runs-on: ubuntu-latest-32
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: Lint
|
name: Lint
|
||||||
# timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
# try out buildjet to speed up build and test
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
# To use Remote Caching, uncomment the next lines and follow the steps below.
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ jobs:
|
|||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest-32
|
runs-on: ubuntu-latest-32
|
||||||
|
timeout-minutes: 30
|
||||||
needs: deploy-check
|
needs: deploy-check
|
||||||
if: needs.deploy-check.outputs.triggered == 'true'
|
if: needs.deploy-check.outputs.triggered == 'true'
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Release
|
name: Release
|
||||||
|
timeout-minutes: 30
|
||||||
runs-on: ubuntu-latest-32
|
runs-on: ubuntu-latest-32
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout branch
|
- name: Checkout branch
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ on: [pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest-32
|
runs-on: ubuntu-latest-32
|
||||||
|
timeout-minutes: 30
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@
|
|||||||
"@changesets/cli": "^2.24.3",
|
"@changesets/cli": "^2.24.3",
|
||||||
"@manypkg/cli": "^0.19.1",
|
"@manypkg/cli": "^0.19.1",
|
||||||
"@manypkg/get-packages": "^1.1.3",
|
"@manypkg/get-packages": "^1.1.3",
|
||||||
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
|
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
||||||
"eslint": "^8.21.0",
|
"eslint": "^8.21.0",
|
||||||
"postinstall-postinstall": "^2.1.0",
|
"postinstall-postinstall": "^2.1.0",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
# @thirdweb-dev/auth
|
# @thirdweb-dev/auth
|
||||||
|
|
||||||
|
## 2.0.39
|
||||||
|
|
||||||
|
## 2.0.38
|
||||||
|
|
||||||
|
## 2.0.37
|
||||||
|
|
||||||
|
## 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.33
|
||||||
|
|
||||||
## 2.0.32
|
## 2.0.32
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/auth",
|
"name": "@thirdweb-dev/auth",
|
||||||
"version": "2.0.33",
|
"version": "2.0.39",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./next": {
|
"./next": {
|
||||||
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export default async function handler(
|
|||||||
path: "/",
|
path: "/",
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: true,
|
secure: true,
|
||||||
sameSite: "strict",
|
sameSite: "none",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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,77 @@
|
|||||||
# thirdweb
|
# thirdweb
|
||||||
|
|
||||||
|
## 0.9.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`e913e0d`](https://github.com/thirdweb-dev/js/commit/e913e0daa9ece9a6274f7ffa4e66bdcbf32e6ada), [`5862c55`](https://github.com/thirdweb-dev/js/commit/5862c558fb48604b5aca4defd1ccc06fc3536358), [`73883f5`](https://github.com/thirdweb-dev/js/commit/73883f56d0ed0a35ace8b98b96caa782443be22e), [`f7a74a3`](https://github.com/thirdweb-dev/js/commit/f7a74a3b7c489ada5b1ec435632a326334a33c9b)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.9
|
||||||
|
|
||||||
|
## 0.9.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#454](https://github.com/thirdweb-dev/js/pull/454) [`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0) Thanks [@jnsdls](https://github.com/jnsdls)! - upgraded dependencies
|
||||||
|
|
||||||
|
- [#461](https://github.com/thirdweb-dev/js/pull/461) [`af85389`](https://github.com/thirdweb-dev/js/commit/af85389dc07fb163b8f9d70093eb1b691e47561a) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix deprecated links
|
||||||
|
|
||||||
|
- Updated dependencies [[`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0), [`ea95c5f`](https://github.com/thirdweb-dev/js/commit/ea95c5f609e306e333ee0f73f7920503358ca848), [`699a2b1`](https://github.com/thirdweb-dev/js/commit/699a2b16fb991c474ec57db8f178e2601d631f39), [`4cdd0bd`](https://github.com/thirdweb-dev/js/commit/4cdd0bd6348494a256d7c6a2bdf8f7b5c20f6877), [`a8267f9`](https://github.com/thirdweb-dev/js/commit/a8267f912df84c58d3fe3f47b90bd474f73c84ca)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.8
|
||||||
|
|
||||||
|
## 0.9.6
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#441](https://github.com/thirdweb-dev/js/pull/441) [`64f24f1`](https://github.com/thirdweb-dev/js/commit/64f24f1bb167c3d0cb3beca51fd300eaec21cc27) Thanks [@adam-maj](https://github.com/adam-maj)! - CLI autoupdates on run
|
||||||
|
|
||||||
|
- [#447](https://github.com/thirdweb-dev/js/pull/447) [`e7740a5`](https://github.com/thirdweb-dev/js/commit/e7740a59db022a3396194ac66cd195d8ae754d57) Thanks [@adam-maj](https://github.com/adam-maj)! - Detect whether forge is installed
|
||||||
|
|
||||||
|
- Updated dependencies [[`3731459`](https://github.com/thirdweb-dev/js/commit/3731459d33f1ded7ebb69124809449b901b3ad3d), [`cac6c30`](https://github.com/thirdweb-dev/js/commit/cac6c30bca5e17df81d746ef81316af47d5e252e), [`7a37e56`](https://github.com/thirdweb-dev/js/commit/7a37e564fd5d5a9df84c8da44ecaf6c42f67a0e2)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.7
|
||||||
|
|
||||||
|
## 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
|
## 0.9.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ Deploying released contracts give deployers access to automatic SDKs to integrat
|
|||||||
npx thirdweb@latest detect
|
npx thirdweb@latest detect
|
||||||
```
|
```
|
||||||
|
|
||||||
As you're developing your contracts, you may want to implement [Extensions](https://portal.thirdweb.com/extensions) to unlock functionality on the SDKs (ie. nft minting with automatic upload to IPFS) and the dashboard (ie. generated UI to manage permissions). This command will show what extensions were detected on your contract, unlocking the corresponding functionality on the SDKs and dashboard.
|
As you're developing your contracts, you may want to implement [Extensions](https://portal.thirdweb.com/contractkit) to unlock functionality on the SDKs (ie. nft minting with automatic upload to IPFS) and the dashboard (ie. generated UI to manage permissions). This command will show what extensions were detected on your contract, unlocking the corresponding functionality on the SDKs and dashboard.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
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?",
|
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?",
|
||||||
@@ -10,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",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "thirdweb",
|
"name": "thirdweb",
|
||||||
"main": "dist/cli/index.js",
|
"main": "dist/cli/index.js",
|
||||||
"version": "0.9.0",
|
"version": "0.9.8",
|
||||||
"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",
|
||||||
@@ -18,12 +18,12 @@
|
|||||||
"@types/prompts": "^2.0.14",
|
"@types/prompts": "^2.0.14",
|
||||||
"@types/rimraf": "^3.0.0",
|
"@types/rimraf": "^3.0.0",
|
||||||
"@types/tar": "^6.1.2",
|
"@types/tar": "^6.1.2",
|
||||||
"@types/update-notifier": "^5.1.0",
|
"@types/update-notifier": "^6.0.1",
|
||||||
"@types/validate-npm-package-name": "^4.0.0",
|
"@types/validate-npm-package-name": "^4.0.0",
|
||||||
"hardhat": "^2.9.3",
|
"hardhat": "^2.9.3",
|
||||||
"jest": "^28",
|
"jest": "^29",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"ts-jest": "^28.0.8",
|
"ts-jest": "^29.0.3",
|
||||||
"ts-node": "^10.7.0",
|
"ts-node": "^10.7.0",
|
||||||
"tsup": "^6.2.3",
|
"tsup": "^6.2.3",
|
||||||
"typescript": "^4.7.4"
|
"typescript": "^4.7.4"
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
"@thirdweb-dev/sdk": "*",
|
"@thirdweb-dev/sdk": "*",
|
||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"commander": "^9.1.0",
|
"commander": "^9.1.0",
|
||||||
|
"detect-package-manager": "^2.0.1",
|
||||||
"enquirer": "^2.3.6",
|
"enquirer": "^2.3.6",
|
||||||
"ethers": "^5.7.2",
|
"ethers": "^5.7.2",
|
||||||
"got": "11.8.5",
|
"got": "11.8.5",
|
||||||
|
|||||||
+168
-20
@@ -2,37 +2,37 @@
|
|||||||
import { detectExtensions } from "../common/feature-detector";
|
import { detectExtensions } from "../common/feature-detector";
|
||||||
import { processProject } from "../common/processor";
|
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, spinner } from "../core/helpers/logger";
|
||||||
import { twCreate } from "../create/command";
|
import { twCreate } from "../create/command";
|
||||||
import { deploy } from "../deploy";
|
import { deploy } from "../deploy";
|
||||||
|
import { findPackageInstallation } from "../helpers/detect-local-packages";
|
||||||
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";
|
||||||
|
import { exec, spawn } from "child_process";
|
||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import open from "open";
|
import open from "open";
|
||||||
|
import prompts from "prompts";
|
||||||
|
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
|
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||||
|
const skipIntro = process.env.THIRDWEB_CLI_SKIP_INTRO === "true";
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
|
|
||||||
//yes this has to look like this, eliminates whitespace
|
// yes this has to look like this, eliminates whitespace
|
||||||
console.info(`
|
if (!skipIntro) {
|
||||||
$$\\ $$\\ $$\\ $$\\ $$\\
|
console.info(`
|
||||||
$$ | $$ | \\__| $$ | $$ |
|
$$\\ $$\\ $$\\ $$\\ $$\\
|
||||||
$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$$\\
|
$$ | $$ | \\__| $$ | $$ |
|
||||||
\\_$$ _| $$ __$$\\ $$ |$$ __$$\\ $$ __$$ |$$ | $$ | $$ |$$ __$$\\ $$ __$$\\
|
$$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$$$$\\
|
||||||
$$ | $$ | $$ |$$ |$$ | \\__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
|
\\_$$ _| $$ __$$\\ $$ |$$ __$$\\ $$ __$$ |$$ | $$ | $$ |$$ __$$\\ $$ __$$\\
|
||||||
$$ |$$\\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
|
$$ | $$ | $$ |$$ |$$ | \\__|$$ / $$ |$$ | $$ | $$ |$$$$$$$$ |$$ | $$ |
|
||||||
\\$$$$ |$$ | $$ |$$ |$$ | \\$$$$$$$ |\\$$$$$\\$$$$ |\\$$$$$$$\\ $$$$$$$ |
|
$$ |$$\\ $$ | $$ |$$ |$$ | $$ | $$ |$$ | $$ | $$ |$$ ____|$$ | $$ |
|
||||||
\\____/ \\__| \\__|\\__|\\__| \\_______| \\_____\\____/ \\_______|\\_______/ `);
|
\\$$$$ |$$ | $$ |$$ |$$ | \\$$$$$$$ |\\$$$$$\\$$$$ |\\$$$$$$$\\ $$$$$$$ |
|
||||||
console.info(`\n 💎 thirdweb-cli v${cliVersion} 💎\n`);
|
\\____/ \\__| \\__|\\__|\\__| \\_______| \\_____\\____/ \\_______|\\_______/ `);
|
||||||
import("update-notifier").then(({ default: updateNotifier }) => {
|
console.info(`\n 💎 thirdweb-cli v${cliVersion} 💎\n`);
|
||||||
updateNotifier({
|
}
|
||||||
pkg,
|
|
||||||
shouldNotifyInNpmScript: true,
|
|
||||||
// check every time while we're still building the CLI
|
|
||||||
updateCheckInterval: 0,
|
|
||||||
}).notify();
|
|
||||||
});
|
|
||||||
|
|
||||||
program
|
program
|
||||||
.name("thirdweb-cli")
|
.name("thirdweb-cli")
|
||||||
@@ -68,6 +68,10 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"-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.",
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
"-c, --contract-name [name]",
|
||||||
|
"Name of the new smart contract to create",
|
||||||
|
)
|
||||||
.action(async (type, path, options) => {
|
.action(async (type, path, options) => {
|
||||||
await twCreate(type, path, options);
|
await twCreate(type, path, options);
|
||||||
});
|
});
|
||||||
@@ -97,6 +101,14 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"-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",
|
||||||
@@ -116,6 +128,14 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
"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")
|
||||||
@@ -178,6 +198,134 @@ $$$$$$\\ $$$$$$$\\ $$\\ $$$$$$\\ $$$$$$$ |$$\\ $$\\ $$\\ $$$$$$\\ $$$$
|
|||||||
await detectExtensions(options);
|
await detectExtensions(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!skipIntro) {
|
||||||
|
const versionSpinner = spinner("Checking for updates...");
|
||||||
|
await import("update-notifier").then(
|
||||||
|
async ({ default: updateNotifier }) => {
|
||||||
|
const notifier = updateNotifier({
|
||||||
|
pkg,
|
||||||
|
shouldNotifyInNpmScript: true,
|
||||||
|
// check every time while we're still building the CLI
|
||||||
|
updateCheckInterval: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const versionInfo = await notifier.fetchInfo();
|
||||||
|
versionSpinner.stop();
|
||||||
|
|
||||||
|
if (versionInfo.type !== "latest") {
|
||||||
|
const res = await prompts({
|
||||||
|
type: "toggle",
|
||||||
|
name: "upgrade",
|
||||||
|
message: `A new version of the CLI is available. Would you like to upgrade?`,
|
||||||
|
initial: true,
|
||||||
|
active: "yes",
|
||||||
|
inactive: "no",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.upgrade) {
|
||||||
|
const updateSpinner = spinner(
|
||||||
|
`Upgrading CLI to version ${versionInfo.latest}...`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const clonedEnvironment = { ...process.env };
|
||||||
|
clonedEnvironment.THIRDWEB_CLI_SKIP_INTRO = "true";
|
||||||
|
|
||||||
|
const installation = await findPackageInstallation();
|
||||||
|
|
||||||
|
// If the package isn't installed anywhere, just defer to npx thirdweb@latest
|
||||||
|
if (!installation) {
|
||||||
|
updateSpinner.succeed(
|
||||||
|
`Now using CLI version ${versionInfo.latest}. Continuing execution...`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await new Promise((done, failed) => {
|
||||||
|
const shell = spawn(
|
||||||
|
`npx --yes thirdweb@latest ${process.argv
|
||||||
|
.slice(2)
|
||||||
|
.join(" ")}`,
|
||||||
|
[],
|
||||||
|
{ stdio: "inherit", shell: true, env: clonedEnvironment },
|
||||||
|
);
|
||||||
|
shell.on("close", (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
done("");
|
||||||
|
} else {
|
||||||
|
failed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, get the correct command based on package manager and local vs. global
|
||||||
|
let command = "";
|
||||||
|
switch (installation.packageManager) {
|
||||||
|
case "npm":
|
||||||
|
command = installation.isGlobal
|
||||||
|
? `npm install -g thirdweb`
|
||||||
|
: `npm install thirdweb`;
|
||||||
|
break;
|
||||||
|
case "yarn":
|
||||||
|
command = installation.isGlobal
|
||||||
|
? `yarn global add thirdweb`
|
||||||
|
: `yarn add thirdweb`;
|
||||||
|
break;
|
||||||
|
case "pnpm":
|
||||||
|
command = installation.isGlobal
|
||||||
|
? `pnpm add -g thirdweb@latest`
|
||||||
|
: `pnpm add thirdweb@latest`;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.error(
|
||||||
|
`Could not detect package manager in use, aborting automatic upgrade.\nIf you want to upgrade the CLI, please do it manually with your package manager.`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
await new Promise((done, failed) => {
|
||||||
|
exec(command, (err, stdout, stderr) => {
|
||||||
|
if (err) {
|
||||||
|
failed(err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
done({ stdout, stderr });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
updateSpinner.succeed(
|
||||||
|
`Successfully upgraded CLI to version ${versionInfo.latest}. Continuing execution...`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// If the package is installed globally with yarn or pnpm, then npx won't recognize it
|
||||||
|
// So we need to make sure to run the command directly
|
||||||
|
const executionCommand =
|
||||||
|
!installation.isGlobal || installation.packageManager === "npm"
|
||||||
|
? `npx thirdweb`
|
||||||
|
: `thirdweb`;
|
||||||
|
await new Promise((done, failed) => {
|
||||||
|
const shell = spawn(
|
||||||
|
`${executionCommand} ${process.argv.slice(2).join(" ")}`,
|
||||||
|
[],
|
||||||
|
{ stdio: "inherit", shell: true, env: clonedEnvironment },
|
||||||
|
);
|
||||||
|
shell.on("close", (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
done("");
|
||||||
|
} else {
|
||||||
|
failed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await program.parseAsync();
|
await program.parseAsync();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,13 @@ export async function detectExtensions(options: any) {
|
|||||||
const enabledFeatures: Feature[] = features.enabledFeatures.map(
|
const enabledFeatures: Feature[] = features.enabledFeatures.map(
|
||||||
(feature) => ({
|
(feature) => ({
|
||||||
name: feature.name,
|
name: feature.name,
|
||||||
reference: `https://portal.thirdweb.com/extensions/${feature.name.toLowerCase()}`,
|
reference: `https://portal.thirdweb.com/interfaces/${feature.name.toLowerCase()}`,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const suggestedFeatures: Feature[] = features.suggestedFeatures.map(
|
const suggestedFeatures: Feature[] = features.suggestedFeatures.map(
|
||||||
(feature) => ({
|
(feature) => ({
|
||||||
name: feature.name,
|
name: feature.name,
|
||||||
reference: `https://portal.thirdweb.com/extensions/${feature.name.toLowerCase()}`,
|
reference: `https://portal.thirdweb.com/interfaces/${feature.name.toLowerCase()}`,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { findFiles } from "../../common/file-helper";
|
import { findFiles } from "../../common/file-helper";
|
||||||
|
import { hasForge } from "../../create/helpers/has-forge";
|
||||||
import { execute } from "../helpers/exec";
|
import { execute } from "../helpers/exec";
|
||||||
import { logger } from "../helpers/logger";
|
import { logger } from "../helpers/logger";
|
||||||
import { CompileOptions } from "../interfaces/Builder";
|
import { CompileOptions } from "../interfaces/Builder";
|
||||||
import { ContractPayload } from "../interfaces/ContractPayload";
|
import { ContractPayload } from "../interfaces/ContractPayload";
|
||||||
import { BaseBuilder } from "./builder-base";
|
import { BaseBuilder } from "./builder-base";
|
||||||
|
import chalk from "chalk";
|
||||||
import { existsSync, readFileSync } from "fs";
|
import { existsSync, readFileSync } from "fs";
|
||||||
import { basename, join } from "path";
|
import { basename, join } from "path";
|
||||||
|
|
||||||
@@ -11,6 +13,18 @@ export class FoundryBuilder extends BaseBuilder {
|
|||||||
public async compile(options: CompileOptions): Promise<{
|
public async compile(options: CompileOptions): Promise<{
|
||||||
contracts: ContractPayload[];
|
contracts: ContractPayload[];
|
||||||
}> {
|
}> {
|
||||||
|
const isInstalled = await hasForge();
|
||||||
|
if (!isInstalled) {
|
||||||
|
console.error(
|
||||||
|
`\n${chalk.redBright(
|
||||||
|
`error`,
|
||||||
|
)} You don't have forge installed on this machine!\n\nYou can install forge by following these instructions:\n${chalk.blueBright(
|
||||||
|
`https://book.getfoundry.sh/getting-started/installation`,
|
||||||
|
)}\n`,
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
await execute("forge clean", options.projectPath);
|
await execute("forge clean", options.projectPath);
|
||||||
await execute("forge build --extra-output metadata", options.projectPath);
|
await execute("forge build --extra-output metadata", options.projectPath);
|
||||||
|
|
||||||
@@ -88,6 +102,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 +118,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) {
|
||||||
|
|||||||
@@ -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
|
||||||
*/
|
*/
|
||||||
|
|||||||
+217
-128
@@ -2,14 +2,17 @@
|
|||||||
|
|
||||||
/* 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 contractName: string = "";
|
||||||
let projectPath: string = "";
|
let projectPath: string = "";
|
||||||
let projectType: string = "";
|
let projectType: string = "";
|
||||||
let framework: string = "";
|
let framework: string = "";
|
||||||
@@ -27,6 +30,10 @@ export async function twCreate(
|
|||||||
projectPath = pPath;
|
projectPath = pPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof options.contractName === "string") {
|
||||||
|
contractName = options.contractName;
|
||||||
|
}
|
||||||
|
|
||||||
if (pType === "app" || options.app) {
|
if (pType === "app" || options.app) {
|
||||||
projectType = "app";
|
projectType = "app";
|
||||||
} else if (pType === "contract" || options.contract) {
|
} else if (pType === "contract" || options.contract) {
|
||||||
@@ -97,123 +104,210 @@ export async function twCreate(
|
|||||||
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" && !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 (
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +319,9 @@ export async function twCreate(
|
|||||||
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" },
|
||||||
@@ -279,20 +375,11 @@ export async function twCreate(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -324,7 +411,7 @@ export async function twCreate(
|
|||||||
try {
|
try {
|
||||||
if (projectType === "app") {
|
if (projectType === "app") {
|
||||||
await createApp({
|
await createApp({
|
||||||
appPath: resolvedProjectPath,
|
appPath: projectPath,
|
||||||
packageManager,
|
packageManager,
|
||||||
framework,
|
framework,
|
||||||
language,
|
language,
|
||||||
@@ -332,11 +419,13 @@ export async function twCreate(
|
|||||||
chain,
|
chain,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await createContract({
|
await createContractProject({
|
||||||
contractPath: resolvedProjectPath,
|
contractPath: projectPath,
|
||||||
packageManager,
|
packageManager,
|
||||||
framework,
|
framework,
|
||||||
|
contractName,
|
||||||
baseContract,
|
baseContract,
|
||||||
|
onlyContract,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { hasBaseContract, readBaseContract } from "./base-contracts";
|
|||||||
import { DownloadError } from "./create-app";
|
import { DownloadError } from "./create-app";
|
||||||
import { PackageManager } from "./get-pkg-manager";
|
import { PackageManager } from "./get-pkg-manager";
|
||||||
import { tryGitInit } from "./git";
|
import { tryGitInit } from "./git";
|
||||||
|
import { hasForge } from "./has-forge";
|
||||||
import { install } from "./install";
|
import { install } from "./install";
|
||||||
import { isFolderEmpty } from "./is-folder-empty";
|
import { isFolderEmpty } from "./is-folder-empty";
|
||||||
import { getOnline } from "./is-online";
|
import { getOnline } from "./is-online";
|
||||||
@@ -11,22 +12,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 +47,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 +59,179 @@ 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) {
|
|
||||||
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 {
|
} else {
|
||||||
cdpath = contractPath;
|
// Otherwise, create a new contracts project
|
||||||
}
|
const projectName = path.basename(root);
|
||||||
|
|
||||||
console.log(
|
await makeDir(root);
|
||||||
`${chalk.green("Success!")} Created ${projectName} at ${contractPath}`,
|
if (!isFolderEmpty(root, projectName)) {
|
||||||
);
|
process.exit(1);
|
||||||
console.log();
|
}
|
||||||
console.log("Inside that directory, you can run several commands:");
|
|
||||||
console.log();
|
const isOnline = !useYarn || (await getOnline());
|
||||||
console.log(chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} build`));
|
const originalDirectory = process.cwd();
|
||||||
console.log(
|
|
||||||
" Compiles your contracts and detects thirdweb extensions implemented on them.",
|
console.log(
|
||||||
);
|
`Creating a new thirdweb contracts project in ${chalk.green(root)}.`,
|
||||||
console.log();
|
);
|
||||||
console.log(chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} deploy`));
|
console.log();
|
||||||
console.log(" Deploys your contracts with the thirdweb deploy flow.");
|
|
||||||
console.log();
|
process.chdir(root);
|
||||||
console.log(
|
|
||||||
chalk.cyan(` ${packageManager}${useYarn ? "" : " run"} release`),
|
function isErrorLike(err: unknown): err is { message: string } {
|
||||||
);
|
return (
|
||||||
console.log(" Releases your contracts with the thirdweb release flow.");
|
typeof err === "object" &&
|
||||||
console.log();
|
err !== null &&
|
||||||
console.log("We suggest that you begin by typing:");
|
typeof (err as { message?: unknown }).message === "string"
|
||||||
console.log();
|
);
|
||||||
console.log(chalk.cyan(" cd"), cdpath);
|
}
|
||||||
console.log();
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
if (framework === "forge") {
|
||||||
|
const isInstalled = await hasForge();
|
||||||
|
|
||||||
|
if (!isInstalled) {
|
||||||
|
console.log(
|
||||||
|
`\n${chalk.yellowBright(
|
||||||
|
`warning`,
|
||||||
|
)} You don't have forge installed on this machine, and will need it to run this project! \n\nYou can install forge by following these instructions:\n${chalk.blueBright(
|
||||||
|
`https://book.getfoundry.sh/getting-started/installation`,
|
||||||
|
)}\n`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { exec } from "child_process";
|
||||||
|
|
||||||
|
export async function hasForge() {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
return await new Promise((resolve, reject) => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
exec("forge --version", (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { exec } from "child_process";
|
||||||
|
|
||||||
|
type PackageManager = "npm" | "yarn" | "pnpm";
|
||||||
|
|
||||||
|
interface Installation {
|
||||||
|
packageManager: PackageManager;
|
||||||
|
isGlobal: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function findPackageInstallation(): Promise<
|
||||||
|
Installation | undefined
|
||||||
|
> {
|
||||||
|
const isLocal = await isInstalledLocally();
|
||||||
|
if (isLocal) {
|
||||||
|
const packageManager = await import("detect-package-manager").then(
|
||||||
|
({ detect }) => {
|
||||||
|
return detect();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return { packageManager, isGlobal: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGlobalNpm = await isInstalledGloballyWithNpm();
|
||||||
|
if (isGlobalNpm) {
|
||||||
|
return { packageManager: "npm", isGlobal: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGlobalYarn = await isInstalledGloballyWithYarn();
|
||||||
|
if (isGlobalYarn) {
|
||||||
|
return { packageManager: "yarn", isGlobal: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
const isGlobalPnpm = await isInstalledGloballyWithPnpm();
|
||||||
|
if (isGlobalPnpm) {
|
||||||
|
return { packageManager: "pnpm", isGlobal: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For LOCAL packages, npm ls picks up things installed by yarn and pnpm too
|
||||||
|
async function isInstalledLocally(): Promise<boolean> {
|
||||||
|
const packages = await detectPackages("npm ls --depth=0");
|
||||||
|
return containsThirdweb(packages || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
// But for GLOBAL packages, we need to use a separate command for each one
|
||||||
|
async function isInstalledGloballyWithNpm(): Promise<boolean> {
|
||||||
|
const packages = await detectPackages("npm ls -g --depth=0");
|
||||||
|
return containsThirdweb(packages || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isInstalledGloballyWithYarn(): Promise<boolean> {
|
||||||
|
const packages = await detectPackages("yarn --cwd `yarn global dir` list");
|
||||||
|
return containsThirdweb(packages || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function isInstalledGloballyWithPnpm(): Promise<boolean> {
|
||||||
|
const packages: string[] = await new Promise((resolve) => {
|
||||||
|
exec(`pnpm list -g --depth=0`, (err, stdout) => {
|
||||||
|
var pkgs: string[] = [];
|
||||||
|
pkgs = stdout.split("dependencies:")[1]?.trim().split("\n") || [];
|
||||||
|
pkgs = pkgs.map((pkg) => pkg.replace(" ", "@"));
|
||||||
|
resolve(pkgs);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return containsThirdweb(packages || []);
|
||||||
|
}
|
||||||
|
|
||||||
|
function containsThirdweb(packages: string[]) {
|
||||||
|
return packages.some((pkg) => pkg.match(/^thirdweb/));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function detectPackages(cmd: string): Promise<string[]> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
exec(cmd, (err, stdout) => {
|
||||||
|
var packages: string[] = [];
|
||||||
|
packages = stdout.split("\n");
|
||||||
|
// We're one short on '-' to support both yarn and npm
|
||||||
|
packages = packages.filter(function (item) {
|
||||||
|
if (item.match(/^├─.+/g) !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (item.match(/^└─.+/g) !== null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
packages = packages
|
||||||
|
.map(function (item) {
|
||||||
|
if (item.match(/^├─.+/g) !== null) {
|
||||||
|
return item.replace(/(^├──\s|^├─\s)/g, "");
|
||||||
|
}
|
||||||
|
if (item.match(/^└─.+/g) !== null) {
|
||||||
|
return item.replace(/(^└──\s|^├─\s)/g, "");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((item) => !!item) as string[];
|
||||||
|
resolve(packages);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -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,5 +1,11 @@
|
|||||||
# @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
|
## 1.2.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/contracts-js",
|
"name": "@thirdweb-dev/contracts-js",
|
||||||
"version": "1.2.1",
|
"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.2.2"
|
"@thirdweb-dev/contracts": "3.2.8-0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-env": "^7.18.10",
|
"@babel/preset-env": "^7.18.10",
|
||||||
|
|||||||
@@ -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,37 @@
|
|||||||
# @thirdweb-dev/react
|
# @thirdweb-dev/react
|
||||||
|
|
||||||
|
## 3.6.9
|
||||||
|
|
||||||
|
## 3.6.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#454](https://github.com/thirdweb-dev/js/pull/454) [`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0) Thanks [@jnsdls](https://github.com/jnsdls)! - upgraded dependencies
|
||||||
|
|
||||||
|
- [#422](https://github.com/thirdweb-dev/js/pull/422) [`08d04fe`](https://github.com/thirdweb-dev/js/commit/08d04fe4dc74ba0d12625d7d4004c23f7dc330a2) Thanks [@yehia67](https://github.com/yehia67)! - Add `btnTitle` prop to the `ConnectWallet` component. Now you can set customized string or child component to the connect button.
|
||||||
|
|
||||||
|
## 3.6.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#448](https://github.com/thirdweb-dev/js/pull/448) [`7a37e56`](https://github.com/thirdweb-dev/js/commit/7a37e564fd5d5a9df84c8da44ecaf6c42f67a0e2) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - allow `useContract` to fail faster to enable the import case
|
||||||
|
|
||||||
|
## 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.3
|
||||||
|
|
||||||
## 3.6.2
|
## 3.6.2
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/react",
|
"name": "@thirdweb-dev/react",
|
||||||
"version": "3.6.3",
|
"version": "3.6.9",
|
||||||
"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",
|
||||||
@@ -97,19 +97,19 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.10.0",
|
"@emotion/react": "^11.10.0",
|
||||||
"@emotion/styled": "^11.10.0",
|
"@emotion/styled": "^11.10.0",
|
||||||
"@gnosis.pm/safe-core-sdk": "^3.1.1",
|
|
||||||
"@gnosis.pm/safe-ethers-adapters": "0.1.0-alpha.11",
|
|
||||||
"@gnosis.pm/safe-ethers-lib": "^1.6.1",
|
|
||||||
"@react-icons/all-files": "^4.1.0",
|
"@react-icons/all-files": "^4.1.0",
|
||||||
|
"@safe-global/safe-core-sdk": "^3.2.0",
|
||||||
|
"@safe-global/safe-ethers-adapters": "0.1.0-alpha.13",
|
||||||
|
"@safe-global/safe-ethers-lib": "^1.7.0",
|
||||||
"@solana/wallet-adapter-phantom": "^0.9.17",
|
"@solana/wallet-adapter-phantom": "^0.9.17",
|
||||||
"@tanstack/react-query": "^4.0.10",
|
"@tanstack/react-query": "^4.0.10",
|
||||||
"@zag-js/menu": "^0.1.16",
|
"@zag-js/menu": "^0.3.0",
|
||||||
"@zag-js/react": "^0.1.18",
|
"@zag-js/react": "^0.3.1",
|
||||||
"buffer": "^6.0.3",
|
"buffer": "^6.0.3",
|
||||||
"color": "^4.2.3",
|
"color": "^4.2.3",
|
||||||
"copy-to-clipboard": "^3.3.2",
|
"copy-to-clipboard": "^3.3.2",
|
||||||
"detect-browser": "^5.3.0",
|
"detect-browser": "^5.3.0",
|
||||||
"magic-sdk": "^8.1.1",
|
"magic-sdk": "^10.1.0",
|
||||||
"mime": "^3.0.0",
|
"mime": "^3.0.0",
|
||||||
"react-cool-dimensions": "^2.0.7",
|
"react-cool-dimensions": "^2.0.7",
|
||||||
"tiny-invariant": "^1.2.0",
|
"tiny-invariant": "^1.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}>
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ interface ConnectWalletProps extends ThemeProviderProps {
|
|||||||
loginOptional?: boolean;
|
loginOptional?: boolean;
|
||||||
};
|
};
|
||||||
className?: string;
|
className?: string;
|
||||||
|
btnTitle?: JSX.Element | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
let connecting = false;
|
let connecting = false;
|
||||||
@@ -120,6 +121,7 @@ const chainIdToCurrencyMap: Record<
|
|||||||
export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
||||||
auth,
|
auth,
|
||||||
className,
|
className,
|
||||||
|
btnTitle,
|
||||||
...themeProps
|
...themeProps
|
||||||
}) => {
|
}) => {
|
||||||
const id = useId();
|
const id = useId();
|
||||||
@@ -248,7 +250,9 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
|
|||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<span style={{ whiteSpace: "nowrap" }}>Connect Wallet</span>
|
<span style={{ whiteSpace: "nowrap" }}>
|
||||||
|
{btnTitle || "Connect Wallet"}
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -98,12 +98,15 @@ export class GnosisSafeConnector extends Connector {
|
|||||||
invariant(serverUrl, "Chain not supported");
|
invariant(serverUrl, "Chain not supported");
|
||||||
|
|
||||||
const [safeEthersAdapters, safeCoreSdk, safeEthersLib] = await Promise.all([
|
const [safeEthersAdapters, safeCoreSdk, safeEthersLib] = await Promise.all([
|
||||||
import("@gnosis.pm/safe-ethers-adapters"),
|
import("@safe-global/safe-ethers-adapters"),
|
||||||
import("@gnosis.pm/safe-core-sdk"),
|
import("@safe-global/safe-core-sdk"),
|
||||||
import("@gnosis.pm/safe-ethers-lib"),
|
import("@safe-global/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,
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ export function useContract(
|
|||||||
await queryClient.fetchQuery(
|
await queryClient.fetchQuery(
|
||||||
compilerMetadata.cacheKey(contractAddress, activeChainId),
|
compilerMetadata.cacheKey(contractAddress, activeChainId),
|
||||||
() => compilerMetadata.fetchQuery(contractAddress, sdk),
|
() => compilerMetadata.fetchQuery(contractAddress, sdk),
|
||||||
{ cacheTime: Infinity, staleTime: Infinity },
|
{ cacheTime: Infinity, staleTime: Infinity, retry: 0 },
|
||||||
)
|
)
|
||||||
)?.abi;
|
)?.abi;
|
||||||
}
|
}
|
||||||
@@ -258,6 +258,8 @@ export function useContract(
|
|||||||
cacheTime: Infinity,
|
cacheTime: Infinity,
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
enabled: !!contractAddress && !!sdk && !!activeChainId,
|
enabled: !!contractAddress && !!sdk && !!activeChainId,
|
||||||
|
// never retry
|
||||||
|
retry: 0,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
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,76 @@
|
|||||||
# @thirdweb-dev/sdk
|
# @thirdweb-dev/sdk
|
||||||
|
|
||||||
|
## 3.6.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#465](https://github.com/thirdweb-dev/js/pull/465) [`e913e0d`](https://github.com/thirdweb-dev/js/commit/e913e0daa9ece9a6274f7ffa4e66bdcbf32e6ada) Thanks [@adam-maj](https://github.com/adam-maj)! - Fix passing options to factory
|
||||||
|
|
||||||
|
- [`5862c55`](https://github.com/thirdweb-dev/js/commit/5862c558fb48604b5aca4defd1ccc06fc3536358) Thanks [@kumaryash90](https://github.com/kumaryash90)! - update forwarder address
|
||||||
|
|
||||||
|
- [#466](https://github.com/thirdweb-dev/js/pull/466) [`73883f5`](https://github.com/thirdweb-dev/js/commit/73883f56d0ed0a35ace8b98b96caa782443be22e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - workaround for signing typed data with magic.link signers
|
||||||
|
|
||||||
|
- [#468](https://github.com/thirdweb-dev/js/pull/468) [`f7a74a3`](https://github.com/thirdweb-dev/js/commit/f7a74a3b7c489ada5b1ec435632a326334a33c9b) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Expose `sdk.wallet.signTypedData()`
|
||||||
|
|
||||||
|
## 3.6.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#454](https://github.com/thirdweb-dev/js/pull/454) [`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0) Thanks [@jnsdls](https://github.com/jnsdls)! - upgraded dependencies
|
||||||
|
|
||||||
|
- [#421](https://github.com/thirdweb-dev/js/pull/421) [`ea95c5f`](https://github.com/thirdweb-dev/js/commit/ea95c5f609e306e333ee0f73f7920503358ca848) Thanks [@yehia67](https://github.com/yehia67)! - Add new utilities to parse/format currencies. `toEther` & `toWei` as default 18 decimal and `toUnits` & `toDisplayValue` in case of different numbers of decimals.
|
||||||
|
|
||||||
|
- [#456](https://github.com/thirdweb-dev/js/pull/456) [`699a2b1`](https://github.com/thirdweb-dev/js/commit/699a2b16fb991c474ec57db8f178e2601d631f39) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Fix claiming drops with custom currencies
|
||||||
|
|
||||||
|
- [#458](https://github.com/thirdweb-dev/js/pull/458) [`4cdd0bd`](https://github.com/thirdweb-dev/js/commit/4cdd0bd6348494a256d7c6a2bdf8f7b5c20f6877) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fixes for latest wallet package integration
|
||||||
|
|
||||||
|
- [#453](https://github.com/thirdweb-dev/js/pull/453) [`a8267f9`](https://github.com/thirdweb-dev/js/commit/a8267f912df84c58d3fe3f47b90bd474f73c84ca) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - [SOL] Drop fixes for large batch uploads
|
||||||
|
|
||||||
|
## 3.6.7
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#451](https://github.com/thirdweb-dev/js/pull/451) [`3731459`](https://github.com/thirdweb-dev/js/commit/3731459d33f1ded7ebb69124809449b901b3ad3d) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Less strict prebuilt checks to support OSRF variants
|
||||||
|
|
||||||
|
- [#450](https://github.com/thirdweb-dev/js/pull/450) [`cac6c30`](https://github.com/thirdweb-dev/js/commit/cac6c30bca5e17df81d746ef81316af47d5e252e) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fix setting allowance or approvals gaslessly
|
||||||
|
|
||||||
|
- [#448](https://github.com/thirdweb-dev/js/pull/448) [`7a37e56`](https://github.com/thirdweb-dev/js/commit/7a37e564fd5d5a9df84c8da44ecaf6c42f67a0e2) Thanks [@jnsdls](https://github.com/jnsdls)! - [EVM] - allow `useContract` to fail faster to enable the import case
|
||||||
|
|
||||||
|
## 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
|
## 3.6.3
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@thirdweb-dev/sdk",
|
"name": "@thirdweb-dev/sdk",
|
||||||
"version": "3.6.3",
|
"version": "3.6.9",
|
||||||
"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",
|
||||||
@@ -85,7 +85,7 @@
|
|||||||
"@types/deep-equal-in-any-order": "^1.0.1",
|
"@types/deep-equal-in-any-order": "^1.0.1",
|
||||||
"@types/mocha": "^10.0.0",
|
"@types/mocha": "^10.0.0",
|
||||||
"@types/node": "^18.0.0",
|
"@types/node": "^18.0.0",
|
||||||
"@types/uuid": "^8.3.3",
|
"@types/uuid": "^9.0.0",
|
||||||
"@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",
|
||||||
"chai": "^4.3.6",
|
"chai": "^4.3.6",
|
||||||
@@ -97,6 +97,7 @@
|
|||||||
"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.2",
|
"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",
|
||||||
@@ -104,11 +105,15 @@
|
|||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@aws-sdk/client-secrets-manager": "^3.215.0",
|
"@aws-sdk/client-secrets-manager": "^3.215.0",
|
||||||
"ethers": "^5"
|
"ethers": "^5",
|
||||||
|
"ethers-aws-kms-signer": "^1.3.2"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@aws-sdk/client-secrets-manager": {
|
"@aws-sdk/client-secrets-manager": {
|
||||||
"optional": true
|
"optional": true
|
||||||
|
},
|
||||||
|
"ethers-aws-kms-signer": {
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -122,7 +127,7 @@
|
|||||||
"bn.js": "^5.2.1",
|
"bn.js": "^5.2.1",
|
||||||
"bs58": "^5.0.0",
|
"bs58": "^5.0.0",
|
||||||
"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",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export const DEFAULT_API_KEY =
|
export const DEFAULT_API_KEY =
|
||||||
"c6634ad2d97b74baf15ff556016830c251050e6c36b9da508ce3ec80095d3dc1";
|
"c6634ad2d97b74baf15ff556016830c251050e6c36b9da508ce3ec80095d3dc1";
|
||||||
|
|
||||||
export function getRpcUrl(network: string) {
|
export function getRpcUrl(network: string, apikey = DEFAULT_API_KEY) {
|
||||||
return `https://${network}.rpc.thirdweb.com/${DEFAULT_API_KEY}`;
|
return `https://${network}.rpc.thirdweb.com/${apikey}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export async function setErc20Allowance(
|
|||||||
signer || provider,
|
signer || provider,
|
||||||
currencyAddress,
|
currencyAddress,
|
||||||
ERC20Abi,
|
ERC20Abi,
|
||||||
{},
|
contractToApprove.options,
|
||||||
);
|
);
|
||||||
|
|
||||||
const owner = await contractToApprove.getSignerAddress();
|
const owner = await contractToApprove.getSignerAddress();
|
||||||
@@ -151,7 +151,7 @@ export async function approveErc20Allowance(
|
|||||||
signer || provider,
|
signer || provider,
|
||||||
currencyAddress,
|
currencyAddress,
|
||||||
ERC20Abi,
|
ERC20Abi,
|
||||||
{},
|
contractToApprove.options,
|
||||||
);
|
);
|
||||||
const owner = await contractToApprove.getSignerAddress();
|
const owner = await contractToApprove.getSignerAddress();
|
||||||
const spender = contractToApprove.readContract.address;
|
const spender = contractToApprove.readContract.address;
|
||||||
@@ -192,3 +192,19 @@ export async function normalizeAmount(
|
|||||||
const decimals = await contractWrapper.readContract.decimals();
|
const decimals = await contractWrapper.readContract.decimals();
|
||||||
return utils.parseUnits(AmountSchema.parse(amount), decimals);
|
return utils.parseUnits(AmountSchema.parse(amount), decimals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toEther(amount: BigNumberish): string {
|
||||||
|
return utils.formatEther(amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toWei(amount: Amount): BigNumber {
|
||||||
|
return utils.parseEther(AmountSchema.parse(amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toUnits(amount: Amount, decimals: BigNumberish): BigNumber {
|
||||||
|
return utils.parseUnits(AmountSchema.parse(amount), decimals);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function toDisplayValue(amount: BigNumberish, decimals: BigNumberish): string {
|
||||||
|
return utils.formatUnits(amount, decimals);
|
||||||
|
}
|
||||||
|
|||||||
@@ -401,7 +401,9 @@ export async function convertToTWError(
|
|||||||
// 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 = parseMessageParts(/.*?"message[^a-zA-Z0-9]*([^"\\]*).*?/, raw);
|
const reason =
|
||||||
|
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);
|
||||||
|
|||||||
@@ -266,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
|
||||||
@@ -282,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(
|
||||||
@@ -400,6 +442,11 @@ export async function fetchContractMetadata(
|
|||||||
storage: ThirdwebStorage,
|
storage: ThirdwebStorage,
|
||||||
): Promise<PublishedMetadata> {
|
): Promise<PublishedMetadata> {
|
||||||
const metadata = await storage.downloadJSON(compilerMetadataUri);
|
const metadata = await storage.downloadJSON(compilerMetadataUri);
|
||||||
|
if (!metadata || !metadata.output) {
|
||||||
|
throw new Error(
|
||||||
|
`Could not resolve metadata for contract at ${compilerMetadataUri}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
const abi = AbiSchema.parse(metadata.output.abi);
|
const abi = AbiSchema.parse(metadata.output.abi);
|
||||||
const compilationTarget = metadata.settings.compilationTarget;
|
const compilationTarget = metadata.settings.compilationTarget;
|
||||||
const targets = Object.keys(compilationTarget);
|
const targets = Object.keys(compilationTarget);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
InterfaceId_IERC1155,
|
InterfaceId_IERC1155,
|
||||||
InterfaceId_IERC721,
|
InterfaceId_IERC721,
|
||||||
} from "../constants/contract";
|
} from "../constants/contract";
|
||||||
import { SignerOrProvider } from "../core";
|
|
||||||
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
import { ContractWrapper } from "../core/classes/contract-wrapper";
|
||||||
import {
|
import {
|
||||||
NewAuctionListing,
|
NewAuctionListing,
|
||||||
@@ -76,33 +75,38 @@ export async function isTokenApprovedForTransfer(
|
|||||||
/**
|
/**
|
||||||
* Checks if the marketplace is approved to make transfers on the assetContract
|
* Checks if the marketplace is approved to make transfers on the assetContract
|
||||||
* If not, it tries to set the approval.
|
* If not, it tries to set the approval.
|
||||||
* @param signerOrProvider
|
* @param contractWrapper
|
||||||
* @param marketplaceAddress
|
* @param marketplaceAddress
|
||||||
* @param assetContract
|
* @param assetContract
|
||||||
* @param tokenId
|
* @param tokenId
|
||||||
* @param from
|
* @param from
|
||||||
*/
|
*/
|
||||||
export async function handleTokenApproval(
|
export async function handleTokenApproval(
|
||||||
signerOrProvider: SignerOrProvider,
|
contractWrapper: ContractWrapper<any>,
|
||||||
marketplaceAddress: string,
|
marketplaceAddress: string,
|
||||||
assetContract: string,
|
assetContract: string,
|
||||||
tokenId: BigNumberish,
|
tokenId: BigNumberish,
|
||||||
from: string,
|
from: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const erc165 = new Contract(
|
const erc165 = new ContractWrapper<IERC165>(
|
||||||
|
contractWrapper.getSignerOrProvider(),
|
||||||
assetContract,
|
assetContract,
|
||||||
ERC165Abi,
|
ERC165Abi,
|
||||||
signerOrProvider,
|
contractWrapper.options,
|
||||||
) 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>(
|
||||||
signerOrProvider,
|
contractWrapper.getSignerOrProvider(),
|
||||||
assetContract,
|
assetContract,
|
||||||
ERC721Abi,
|
ERC721Abi,
|
||||||
{},
|
contractWrapper.options,
|
||||||
);
|
);
|
||||||
const approved = await asset.readContract.isApprovedForAll(
|
const approved = await asset.readContract.isApprovedForAll(
|
||||||
from,
|
from,
|
||||||
@@ -122,10 +126,10 @@ export async function handleTokenApproval(
|
|||||||
}
|
}
|
||||||
} else if (isERC1155) {
|
} else if (isERC1155) {
|
||||||
const asset = new ContractWrapper<IERC1155>(
|
const asset = new ContractWrapper<IERC1155>(
|
||||||
signerOrProvider,
|
contractWrapper.getSignerOrProvider(),
|
||||||
assetContract,
|
assetContract,
|
||||||
ERC1155Abi,
|
ERC1155Abi,
|
||||||
{},
|
contractWrapper.options,
|
||||||
);
|
);
|
||||||
|
|
||||||
const approved = await asset.readContract.isApprovedForAll(
|
const approved = await asset.readContract.isApprovedForAll(
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export async function signTypedDataInternal(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let signature = "";
|
let signature = "";
|
||||||
|
const signerAddress = (await signer.getAddress()).toLowerCase();
|
||||||
|
|
||||||
// an indirect way for accessing walletconnect's underlying provider
|
// an indirect way for accessing walletconnect's underlying provider
|
||||||
if ((provider as any)?.provider?.isWalletConnect) {
|
if ((provider as any)?.provider?.isWalletConnect) {
|
||||||
@@ -66,11 +67,19 @@ export async function signTypedDataInternal(
|
|||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err?.message?.includes("Method eth_signTypedData_v4 not supported")) {
|
if (err?.message?.includes("Method eth_signTypedData_v4 not supported")) {
|
||||||
signature = await provider.send("eth_signTypedData", [
|
signature = await provider.send("eth_signTypedData", [
|
||||||
(await signer.getAddress()).toLowerCase(),
|
signerAddress,
|
||||||
JSON.stringify(payload),
|
JSON.stringify(payload),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
// magic.link signer only supports this way
|
||||||
|
try {
|
||||||
|
await provider.send("eth_signTypedData_v4", [
|
||||||
|
signerAddress,
|
||||||
|
JSON.stringify(payload),
|
||||||
|
]);
|
||||||
|
} catch (finalErr: any) {
|
||||||
|
throw finalErr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export const CONTRACT_ADDRESSES: Record<
|
|||||||
twBYOCRegistry: "0x3E6eE864f850F5e5A98bc950B68E181Cf4010F23",
|
twBYOCRegistry: "0x3E6eE864f850F5e5A98bc950B68E181Cf4010F23",
|
||||||
},
|
},
|
||||||
[ChainId.Arbitrum]: {
|
[ChainId.Arbitrum]: {
|
||||||
openzeppelinForwarder: OZ_DEFENDER_FORWARDER_ADDRESS,
|
openzeppelinForwarder: "0x8cbc8B5d71702032904750A66AEfE8B603eBC538",
|
||||||
openzeppelinForwarderEOA: "0x4f247c69184ad61036EC2Bb3213b69F10FbEDe1F",
|
openzeppelinForwarderEOA: "0x4f247c69184ad61036EC2Bb3213b69F10FbEDe1F",
|
||||||
biconomyForwarder: "0xfe0fa3C06d03bDC7fb49c892BbB39113B534fB57",
|
biconomyForwarder: "0xfe0fa3C06d03bDC7fb49c892BbB39113B534fB57",
|
||||||
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
|
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
|
||||||
@@ -109,7 +109,7 @@ export const CONTRACT_ADDRESSES: Record<
|
|||||||
twBYOCRegistry: constants.AddressZero,
|
twBYOCRegistry: constants.AddressZero,
|
||||||
},
|
},
|
||||||
[ChainId.Optimism]: {
|
[ChainId.Optimism]: {
|
||||||
openzeppelinForwarder: OZ_DEFENDER_FORWARDER_ADDRESS,
|
openzeppelinForwarder: "0x8cbc8B5d71702032904750A66AEfE8B603eBC538",
|
||||||
openzeppelinForwarderEOA: "0x7e80648EB2071E26937F9D42A513ccf4815fc702",
|
openzeppelinForwarderEOA: "0x7e80648EB2071E26937F9D42A513ccf4815fc702",
|
||||||
biconomyForwarder: "0xefba8a2a82ec1fb1273806174f5e28fbb917cf95",
|
biconomyForwarder: "0xefba8a2a82ec1fb1273806174f5e28fbb917cf95",
|
||||||
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
|
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import ILazyMintAbi from "@thirdweb-dev/contracts-js/dist/abis/ILazyMint.json";
|
|||||||
import IMintableERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/IMintableERC721.json";
|
import IMintableERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/IMintableERC721.json";
|
||||||
import MulticallAbi from "@thirdweb-dev/contracts-js/dist/abis/IMulticall.json";
|
import MulticallAbi from "@thirdweb-dev/contracts-js/dist/abis/IMulticall.json";
|
||||||
import SignatureMintERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/ISignatureMintERC721.json";
|
import SignatureMintERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/ISignatureMintERC721.json";
|
||||||
|
import SignatureMintERC721_V1Abi from "@thirdweb-dev/contracts-js/dist/abis/ISignatureMintERC721_V1.json";
|
||||||
import TieredDropAbi from "@thirdweb-dev/contracts-js/dist/abis/LazyMintWithTier.json";
|
import TieredDropAbi from "@thirdweb-dev/contracts-js/dist/abis/LazyMintWithTier.json";
|
||||||
import TokenERC721Abi from "@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json";
|
|
||||||
|
|
||||||
export const FEATURE_NFT_BURNABLE = {
|
export const FEATURE_NFT_BURNABLE = {
|
||||||
name: "ERC721Burnable",
|
name: "ERC721Burnable",
|
||||||
@@ -163,7 +163,7 @@ export const FEATURE_NFT_SIGNATURE_MINTABLE_V1 = {
|
|||||||
sdk: "sdk.erc721signaturemint",
|
sdk: "sdk.erc721signaturemint",
|
||||||
contracts: "ISignatureMintERC721",
|
contracts: "ISignatureMintERC721",
|
||||||
},
|
},
|
||||||
abis: [TokenERC721Abi],
|
abis: [SignatureMintERC721_V1Abi],
|
||||||
features: {},
|
features: {},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,11 @@ export function getProviderForNetwork(network: ChainOrRpc | SignerOrProvider) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const READONLY_PROVIDER_MAP: Map<
|
||||||
|
string,
|
||||||
|
StaticJsonRpcBatchProvider | providers.JsonRpcBatchProvider
|
||||||
|
> = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param network - the chain name or rpc url
|
* @param network - the chain name or rpc url
|
||||||
@@ -136,11 +141,19 @@ export function getReadOnlyProvider(network: string, chainId?: number) {
|
|||||||
if (match) {
|
if (match) {
|
||||||
switch (match[1]) {
|
switch (match[1]) {
|
||||||
case "http":
|
case "http":
|
||||||
return chainId
|
const seralizedOpts = `${network}-${chainId || -1}`;
|
||||||
|
const existingProvider = READONLY_PROVIDER_MAP.get(seralizedOpts);
|
||||||
|
if (existingProvider) {
|
||||||
|
return existingProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newProvider = chainId
|
||||||
? // if we know the chainId we should use the StaticJsonRpcBatchProvider
|
? // if we know the chainId we should use the StaticJsonRpcBatchProvider
|
||||||
new StaticJsonRpcBatchProvider(network, chainId)
|
new StaticJsonRpcBatchProvider(network, chainId)
|
||||||
: // otherwise fall back to the built in json rpc batch provider
|
: // otherwise fall back to the built in json rpc batch provider
|
||||||
new providers.JsonRpcBatchProvider(network, chainId);
|
new providers.JsonRpcBatchProvider(network, chainId);
|
||||||
|
READONLY_PROVIDER_MAP.set(seralizedOpts, newProvider);
|
||||||
|
return newProvider;
|
||||||
|
|
||||||
case "ws":
|
case "ws":
|
||||||
return new providers.WebSocketProvider(network, chainId);
|
return new providers.WebSocketProvider(network, chainId);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
import { getPrebuiltInfo } from "../common/legacy";
|
import { getPrebuiltInfo } from "../common/legacy";
|
||||||
import { ALL_ROLES } from "../common/role";
|
import { ALL_ROLES } from "../common/role";
|
||||||
import { getSignerAndProvider } from "../core/classes/rpc-connection-handler";
|
import { getSignerAndProvider } from "../core/classes/rpc-connection-handler";
|
||||||
@@ -56,12 +57,8 @@ export const EditionDropInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
const contractInfo = await assertContractType(
|
const contractInfo = await getContractInfo(address, provider);
|
||||||
address,
|
return !contractInfo || contractInfo.version > 2
|
||||||
provider,
|
|
||||||
"edition-drop",
|
|
||||||
);
|
|
||||||
return contractInfo.version > 2
|
|
||||||
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json"))
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC1155.json"))
|
||||||
.default
|
.default
|
||||||
: (
|
: (
|
||||||
@@ -97,7 +94,6 @@ export const EditionInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "edition");
|
|
||||||
return (
|
return (
|
||||||
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC1155.json")
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC1155.json")
|
||||||
).default;
|
).default;
|
||||||
@@ -129,7 +125,6 @@ export const MarketplaceInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "marketplace");
|
|
||||||
return (
|
return (
|
||||||
await import("@thirdweb-dev/contracts-js/dist/abis/Marketplace.json")
|
await import("@thirdweb-dev/contracts-js/dist/abis/Marketplace.json")
|
||||||
).default;
|
).default;
|
||||||
@@ -161,7 +156,6 @@ export const MultiwrapInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "multiwrap");
|
|
||||||
return (await import("@thirdweb-dev/contracts-js/dist/abis/Multiwrap.json"))
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Multiwrap.json"))
|
||||||
.default;
|
.default;
|
||||||
},
|
},
|
||||||
@@ -193,7 +187,6 @@ export const NFTCollectionInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "nft-collection");
|
|
||||||
return (
|
return (
|
||||||
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json")
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC721.json")
|
||||||
).default;
|
).default;
|
||||||
@@ -225,12 +218,8 @@ export const NFTDropInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
const contractInfo = await assertContractType(
|
const contractInfo = await getContractInfo(address, provider);
|
||||||
address,
|
return !contractInfo || contractInfo.version > 3
|
||||||
provider,
|
|
||||||
"nft-drop",
|
|
||||||
);
|
|
||||||
return contractInfo.version > 3
|
|
||||||
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC721.json"))
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC721.json"))
|
||||||
.default
|
.default
|
||||||
: (
|
: (
|
||||||
@@ -267,7 +256,6 @@ export const PackInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "pack");
|
|
||||||
return (await import("@thirdweb-dev/contracts-js/dist/abis/Pack.json"))
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Pack.json"))
|
||||||
.default;
|
.default;
|
||||||
},
|
},
|
||||||
@@ -299,12 +287,8 @@ export const SignatureDropInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
const contractInfo = await assertContractType(
|
const contractInfo = await getContractInfo(address, provider);
|
||||||
address,
|
return !contractInfo || contractInfo.version > 4
|
||||||
provider,
|
|
||||||
"signature-drop",
|
|
||||||
);
|
|
||||||
return contractInfo.version > 4
|
|
||||||
? (
|
? (
|
||||||
await import(
|
await import(
|
||||||
"@thirdweb-dev/contracts-js/dist/abis/SignatureDrop.json"
|
"@thirdweb-dev/contracts-js/dist/abis/SignatureDrop.json"
|
||||||
@@ -344,7 +328,6 @@ export const SplitInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "split");
|
|
||||||
return (await import("@thirdweb-dev/contracts-js/dist/abis/Split.json"))
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/Split.json"))
|
||||||
.default;
|
.default;
|
||||||
},
|
},
|
||||||
@@ -376,12 +359,8 @@ export const TokenDropInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
const contractInfo = await assertContractType(
|
const contractInfo = await getContractInfo(address, provider);
|
||||||
address,
|
return !contractInfo || contractInfo.version > 2
|
||||||
provider,
|
|
||||||
"token-drop",
|
|
||||||
);
|
|
||||||
return contractInfo.version > 2
|
|
||||||
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20.json"))
|
? (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20.json"))
|
||||||
.default
|
.default
|
||||||
: (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20_V2.json"))
|
: (await import("@thirdweb-dev/contracts-js/dist/abis/DropERC20_V2.json"))
|
||||||
@@ -414,7 +393,6 @@ export const TokenInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "token");
|
|
||||||
return (
|
return (
|
||||||
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC20.json")
|
await import("@thirdweb-dev/contracts-js/dist/abis/TokenERC20.json")
|
||||||
).default;
|
).default;
|
||||||
@@ -447,22 +425,20 @@ export const VoteInitializer = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
getAbi: async (address: string, provider: ethers.providers.Provider) => {
|
||||||
await assertContractType(address, provider, "vote");
|
|
||||||
return (await import("@thirdweb-dev/contracts-js/dist/abis/VoteERC20.json"))
|
return (await import("@thirdweb-dev/contracts-js/dist/abis/VoteERC20.json"))
|
||||||
.default;
|
.default;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function assertContractType(
|
async function getContractInfo(
|
||||||
address: string,
|
address: string,
|
||||||
provider: ethers.providers.Provider,
|
provider: ethers.providers.Provider,
|
||||||
type: PrebuiltContractType,
|
|
||||||
) {
|
) {
|
||||||
const contractInfo = await getPrebuiltInfo(address, provider);
|
try {
|
||||||
if (!contractInfo || contractInfo.type !== getContractName(type)) {
|
return await getPrebuiltInfo(address, provider);
|
||||||
throw new Error(`Contract is not a ${type}`);
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
return contractInfo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -536,10 +536,14 @@ export class Pack extends StandardErc1155<PackContract> {
|
|||||||
tokenId: BigNumberish,
|
tokenId: BigNumberish,
|
||||||
amount: BigNumberish = 1,
|
amount: BigNumberish = 1,
|
||||||
): Promise<PackRewards> {
|
): Promise<PackRewards> {
|
||||||
const receipt = await this.contractWrapper.sendTransaction("openPack", [
|
const receipt = await this.contractWrapper.sendTransaction(
|
||||||
tokenId,
|
"openPack",
|
||||||
amount,
|
[tokenId, amount],
|
||||||
]);
|
{
|
||||||
|
// Higher gas limit for opening packs
|
||||||
|
gasLimit: 500000,
|
||||||
|
},
|
||||||
|
);
|
||||||
const event = this.contractWrapper.parseLogs<PackOpenedEvent>(
|
const event = this.contractWrapper.parseLogs<PackOpenedEvent>(
|
||||||
"PackOpened",
|
"PackOpened",
|
||||||
receipt?.logs,
|
receipt?.logs,
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ export class ContractDeployer extends RPCConnectionHandler {
|
|||||||
factoryAddress,
|
factoryAddress,
|
||||||
this.getSignerOrProvider(),
|
this.getSignerOrProvider(),
|
||||||
this.storage,
|
this.storage,
|
||||||
{},
|
this.options,
|
||||||
);
|
);
|
||||||
return await proxyFactory.deployProxyByImplementation(
|
return await proxyFactory.deployProxyByImplementation(
|
||||||
implementationAddress,
|
implementationAddress,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { ContractEvent, EventQueryOptions } from "../../types/index";
|
|||||||
import { ContractWrapper } from "./contract-wrapper";
|
import { ContractWrapper } from "./contract-wrapper";
|
||||||
import { EventFragment } from "@ethersproject/abi";
|
import { EventFragment } from "@ethersproject/abi";
|
||||||
import { BaseContract, Event, providers } from "ethers";
|
import { BaseContract, Event, providers } from "ethers";
|
||||||
import { ListenerFn } from "eventemitter3";
|
import type { EventEmitter } from "eventemitter3";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listen to Contract events in real time
|
* Listen to Contract events in real time
|
||||||
@@ -28,7 +28,7 @@ export class ContractEvents<TContract extends BaseContract> {
|
|||||||
* @param listener - the callback function that will be called on every transaction
|
* @param listener - the callback function that will be called on every transaction
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
public addTransactionListener(listener: ListenerFn) {
|
public addTransactionListener(listener: EventEmitter.ListenerFn) {
|
||||||
this.contractWrapper.addListener(EventType.Transaction, listener);
|
this.contractWrapper.addListener(EventType.Transaction, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ export class ContractEvents<TContract extends BaseContract> {
|
|||||||
* @param listener - the callback function to remove
|
* @param listener - the callback function to remove
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
public removeTransactionListener(listener: ListenerFn) {
|
public removeTransactionListener(listener: EventEmitter.ListenerFn) {
|
||||||
this.contractWrapper.off(EventType.Transaction, listener);
|
this.contractWrapper.off(EventType.Transaction, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { hasFunction } from "../../common";
|
import { detectContractFeature } from "../../common";
|
||||||
import { normalizePriceValue, setErc20Allowance } from "../../common/currency";
|
import { normalizePriceValue, setErc20Allowance } from "../../common/currency";
|
||||||
import { uploadOrExtractURIs } from "../../common/nft";
|
import { uploadOrExtractURIs } from "../../common/nft";
|
||||||
import { FEATURE_NFT_SIGNATURE_MINTABLE_V2 } from "../../constants/erc721-features";
|
import { FEATURE_NFT_SIGNATURE_MINTABLE_V2 } from "../../constants/erc721-features";
|
||||||
@@ -22,7 +22,7 @@ import type {
|
|||||||
} from "@thirdweb-dev/contracts-js";
|
} from "@thirdweb-dev/contracts-js";
|
||||||
import { TokensMintedWithSignatureEvent } from "@thirdweb-dev/contracts-js/dist/declarations/src/SignatureDrop";
|
import { TokensMintedWithSignatureEvent } from "@thirdweb-dev/contracts-js/dist/declarations/src/SignatureDrop";
|
||||||
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
import { BigNumber, ethers } from "ethers";
|
import { BigNumber } from "ethers";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -397,17 +397,9 @@ export class Erc721WithQuantitySignatureMintable implements DetectableFeature {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async isLegacyNFTContract() {
|
private async isLegacyNFTContract() {
|
||||||
if (hasFunction<TokenERC721>("contractType", this.contractWrapper)) {
|
return detectContractFeature<ISignatureMintERC721>(
|
||||||
try {
|
this.contractWrapper,
|
||||||
const contractType = ethers.utils.toUtf8String(
|
"ERC721SignatureMintV1",
|
||||||
await this.contractWrapper.readContract.contractType(),
|
);
|
||||||
);
|
|
||||||
return contractType.includes("TokenERC721");
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ export class MarketplaceAuction {
|
|||||||
validateNewListingParam(listing);
|
validateNewListingParam(listing);
|
||||||
|
|
||||||
await handleTokenApproval(
|
await handleTokenApproval(
|
||||||
this.contractWrapper.getSignerOrProvider(),
|
this.contractWrapper,
|
||||||
this.getAddress(),
|
this.getAddress(),
|
||||||
listing.assetContractAddress,
|
listing.assetContractAddress,
|
||||||
listing.tokenId,
|
listing.tokenId,
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ export class MarketplaceDirect {
|
|||||||
validateNewListingParam(listing);
|
validateNewListingParam(listing);
|
||||||
|
|
||||||
await handleTokenApproval(
|
await handleTokenApproval(
|
||||||
this.contractWrapper.getSignerOrProvider(),
|
this.contractWrapper,
|
||||||
this.getAddress(),
|
this.getAddress(),
|
||||||
listing.assetContractAddress,
|
listing.assetContractAddress,
|
||||||
listing.tokenId,
|
listing.tokenId,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import EventEmitter from "eventemitter3";
|
|||||||
export class RPCConnectionHandler extends EventEmitter {
|
export class RPCConnectionHandler extends EventEmitter {
|
||||||
private provider: providers.Provider;
|
private provider: providers.Provider;
|
||||||
private signer: Signer | undefined;
|
private signer: Signer | undefined;
|
||||||
protected readonly options: SDKOptionsOutput;
|
public readonly options: SDKOptionsOutput;
|
||||||
|
|
||||||
constructor(network: NetworkOrSignerOrProvider, options: SDKOptions) {
|
constructor(network: NetworkOrSignerOrProvider, options: SDKOptions) {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
isNativeToken,
|
isNativeToken,
|
||||||
normalizePriceValue,
|
normalizePriceValue,
|
||||||
} from "../../common/currency";
|
} from "../../common/currency";
|
||||||
|
import { EIP712Domain, signTypedDataInternal } from "../../common/sign";
|
||||||
import { NATIVE_TOKEN_ADDRESS } from "../../constants";
|
import { NATIVE_TOKEN_ADDRESS } from "../../constants";
|
||||||
import { SDKOptions } from "../../schema";
|
import { SDKOptions } from "../../schema";
|
||||||
import { Amount, CurrencyValue } from "../../types";
|
import { Amount, CurrencyValue } from "../../types";
|
||||||
@@ -11,7 +12,7 @@ import { RPCConnectionHandler } from "../classes/rpc-connection-handler";
|
|||||||
import { NetworkOrSignerOrProvider, TransactionResult } from "../types";
|
import { NetworkOrSignerOrProvider, TransactionResult } from "../types";
|
||||||
import type { IERC20 } from "@thirdweb-dev/contracts-js";
|
import type { IERC20 } from "@thirdweb-dev/contracts-js";
|
||||||
import ERC20Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC20.json";
|
import ERC20Abi from "@thirdweb-dev/contracts-js/dist/abis/IERC20.json";
|
||||||
import { ethers, BigNumber, providers, Signer } from "ethers";
|
import { ethers, BigNumber, providers, Signer, TypedDataField } from "ethers";
|
||||||
import EventEmitter from "eventemitter3";
|
import EventEmitter from "eventemitter3";
|
||||||
import invariant from "tiny-invariant";
|
import invariant from "tiny-invariant";
|
||||||
|
|
||||||
@@ -183,6 +184,42 @@ export class UserWallet {
|
|||||||
return await signer.signMessage(message);
|
return await signer.signMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sign a typed data structure (EIP712) with the connected wallet private key
|
||||||
|
* @param domain - the domain as EIP712 standard
|
||||||
|
* @param types - the strcuture and data types as defined by the EIP712 standard
|
||||||
|
* @param message - the data to sign
|
||||||
|
* @returns the payload and its associated signature
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* // This is the message to be signed
|
||||||
|
* // Now we can sign the message with the connected wallet
|
||||||
|
* const { payload, signature } = await sdk.wallet.signTypedData(
|
||||||
|
* {
|
||||||
|
name: "MyEIP721Domain",
|
||||||
|
version: "1",
|
||||||
|
chainId: 1,
|
||||||
|
verifyingContract: "0x...",
|
||||||
|
},
|
||||||
|
{ MyStruct: [ { name: "to", type: "address" }, { name: "quantity", type: "uint256" } ] },
|
||||||
|
{ to: "0x...", quantity: 1 },
|
||||||
|
* );
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public async signTypedData(
|
||||||
|
domain: EIP712Domain,
|
||||||
|
types: Record<string, Array<TypedDataField>>,
|
||||||
|
message: Record<string, any>,
|
||||||
|
): Promise<{ payload: any; signature: string }> {
|
||||||
|
return await signTypedDataInternal(
|
||||||
|
this.requireWallet(),
|
||||||
|
domain,
|
||||||
|
types,
|
||||||
|
message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recover the signing address from a signed message
|
* Recover the signing address from a signed message
|
||||||
* @param message - the original message that was signed
|
* @param message - the original message that was signed
|
||||||
|
|||||||
@@ -1,99 +1,130 @@
|
|||||||
import { providers, utils } from "ethers";
|
import { providers, utils } from "ethers";
|
||||||
|
|
||||||
|
const DEFAULT_BATCH_TIME_LIMIT_MS = 50;
|
||||||
|
const DEFAULT_BATCH_SIZE_LIMIT = 250;
|
||||||
|
|
||||||
|
const DEFAULT_BATCH_OPTIONS = {
|
||||||
|
timeLimitMs: DEFAULT_BATCH_TIME_LIMIT_MS,
|
||||||
|
sizeLimit: DEFAULT_BATCH_SIZE_LIMIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BatchOptions = Partial<typeof DEFAULT_BATCH_OPTIONS>;
|
||||||
|
|
||||||
// mostly copied from ethers.js directly but make it a StaticJsonRpcProvider
|
// mostly copied from ethers.js directly but make it a StaticJsonRpcProvider
|
||||||
export class StaticJsonRpcBatchProvider extends providers.StaticJsonRpcProvider {
|
export class StaticJsonRpcBatchProvider extends providers.StaticJsonRpcProvider {
|
||||||
_pendingBatchAggregator: NodeJS.Timer | null;
|
private _timeLimitMs: number;
|
||||||
_pendingBatch: Array<{
|
private _sizeLimit: number;
|
||||||
request: { method: string, params: Array<any>, id: number, jsonrpc: "2.0" },
|
_pendingBatchAggregator: NodeJS.Timer | null;
|
||||||
resolve: (result: any) => void,
|
_pendingBatch: Array<{
|
||||||
reject: (error: Error) => void
|
request: { method: string; params: Array<any>; id: number; jsonrpc: "2.0" };
|
||||||
}> | null;
|
resolve: (result: any) => void;
|
||||||
|
reject: (error: Error) => void;
|
||||||
|
}> | null;
|
||||||
|
|
||||||
constructor(url: string | utils.ConnectionInfo | undefined, network: providers.Networkish | undefined){
|
constructor(
|
||||||
super(url, network);
|
url: string | utils.ConnectionInfo | undefined,
|
||||||
this._pendingBatchAggregator = null;
|
network: providers.Networkish | undefined,
|
||||||
this._pendingBatch = null;
|
batchOptions: BatchOptions = DEFAULT_BATCH_OPTIONS,
|
||||||
|
) {
|
||||||
|
super(url, network);
|
||||||
|
this._timeLimitMs = batchOptions.timeLimitMs || DEFAULT_BATCH_SIZE_LIMIT;
|
||||||
|
this._sizeLimit = batchOptions.sizeLimit || DEFAULT_BATCH_TIME_LIMIT_MS;
|
||||||
|
this._pendingBatchAggregator = null;
|
||||||
|
this._pendingBatch = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sendCurrentBatch(request: any) {
|
||||||
|
// if we still have a timeout clear that first
|
||||||
|
if (this._pendingBatchAggregator) {
|
||||||
|
clearTimeout(this._pendingBatchAggregator);
|
||||||
}
|
}
|
||||||
|
// Get the current batch and clear it, so new requests
|
||||||
|
// go into the next batch
|
||||||
|
const batch = this._pendingBatch || [];
|
||||||
|
this._pendingBatch = null;
|
||||||
|
this._pendingBatchAggregator = null;
|
||||||
|
|
||||||
send(method: string, params: Array<any>): Promise<any> {
|
// Get the request as an array of requests
|
||||||
const request = {
|
const request_ = batch.map((inflight) => inflight.request);
|
||||||
method: method,
|
|
||||||
params: params,
|
|
||||||
id: (this._nextId++),
|
|
||||||
jsonrpc: "2.0"
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this._pendingBatch === null) {
|
this.emit("debug", {
|
||||||
this._pendingBatch = [ ];
|
action: "requestBatch",
|
||||||
}
|
request: utils.deepCopy(request),
|
||||||
|
provider: this,
|
||||||
|
});
|
||||||
|
|
||||||
const inflightRequest: any = { request, resolve: null, reject: null };
|
return utils.fetchJson(this.connection, JSON.stringify(request_)).then(
|
||||||
|
(result) => {
|
||||||
const promise = new Promise((resolve, reject) => {
|
this.emit("debug", {
|
||||||
inflightRequest.resolve = resolve;
|
action: "response",
|
||||||
inflightRequest.reject = reject;
|
request: request_,
|
||||||
|
response: result,
|
||||||
|
provider: this,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._pendingBatch.push(inflightRequest);
|
// For each result, feed it to the correct Promise, depending
|
||||||
|
// on whether it was a success or error
|
||||||
|
batch.forEach((inflightRequest_, index) => {
|
||||||
|
const payload = result[index];
|
||||||
|
if (payload.error) {
|
||||||
|
const error = new Error(payload.error.message);
|
||||||
|
(error as any).code = payload.error.code;
|
||||||
|
(error as any).data = payload.error.data;
|
||||||
|
inflightRequest_.reject(error);
|
||||||
|
} else {
|
||||||
|
inflightRequest_.resolve(payload.result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.emit("debug", {
|
||||||
|
action: "response",
|
||||||
|
error: error,
|
||||||
|
request: request_,
|
||||||
|
provider: this,
|
||||||
|
});
|
||||||
|
|
||||||
if (!this._pendingBatchAggregator) {
|
// If there was an error, reject all the requests
|
||||||
// Schedule batch for next event loop + short duration
|
batch.forEach((inflightRequest_) => {
|
||||||
this._pendingBatchAggregator = setTimeout(() => {
|
inflightRequest_.reject(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the current batch and clear it, so new requests
|
send(method: string, params: Array<any>): Promise<any> {
|
||||||
// go into the next batch
|
const request = {
|
||||||
const batch = this._pendingBatch || [];
|
method: method,
|
||||||
this._pendingBatch = null;
|
params: params,
|
||||||
this._pendingBatchAggregator = null;
|
id: this._nextId++,
|
||||||
|
jsonrpc: "2.0",
|
||||||
|
};
|
||||||
|
|
||||||
// Get the request as an array of requests
|
if (this._pendingBatch === null) {
|
||||||
const request_ = batch.map((inflight) => inflight.request);
|
this._pendingBatch = [];
|
||||||
|
|
||||||
this.emit("debug", {
|
|
||||||
action: "requestBatch",
|
|
||||||
request: utils.deepCopy(request),
|
|
||||||
provider: this
|
|
||||||
});
|
|
||||||
|
|
||||||
return utils.fetchJson(this.connection, JSON.stringify(request_)).then((result) => {
|
|
||||||
this.emit("debug", {
|
|
||||||
action: "response",
|
|
||||||
request: request_,
|
|
||||||
response: result,
|
|
||||||
provider: this
|
|
||||||
});
|
|
||||||
|
|
||||||
// For each result, feed it to the correct Promise, depending
|
|
||||||
// on whether it was a success or error
|
|
||||||
batch.forEach((inflightRequest_, index) => {
|
|
||||||
const payload = result[index];
|
|
||||||
if (payload.error) {
|
|
||||||
const error = new Error(payload.error.message);
|
|
||||||
(<any>error).code = payload.error.code;
|
|
||||||
(<any>error).data = payload.error.data;
|
|
||||||
inflightRequest_.reject(error);
|
|
||||||
} else {
|
|
||||||
inflightRequest_.resolve(payload.result);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}, (error) => {
|
|
||||||
this.emit("debug", {
|
|
||||||
action: "response",
|
|
||||||
error: error,
|
|
||||||
request: request,
|
|
||||||
provider: this
|
|
||||||
});
|
|
||||||
|
|
||||||
batch.forEach((inflightRequest_) => {
|
|
||||||
inflightRequest_.reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
}, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const inflightRequest: any = { request, resolve: null, reject: null };
|
||||||
|
|
||||||
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
inflightRequest.resolve = resolve;
|
||||||
|
inflightRequest.reject = reject;
|
||||||
|
});
|
||||||
|
|
||||||
|
// if we would go *over* the size limit of the batch with this request, send the batch now
|
||||||
|
if (this._pendingBatch.length === this._sizeLimit) {
|
||||||
|
this.sendCurrentBatch(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._pendingBatch.push(inflightRequest);
|
||||||
|
|
||||||
|
if (!this._pendingBatchAggregator) {
|
||||||
|
// Schedule batch for next event loop + short duration
|
||||||
|
this._pendingBatchAggregator = setTimeout(() => {
|
||||||
|
this.sendCurrentBatch(request);
|
||||||
|
}, this._timeLimitMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,3 +8,4 @@ export * from "./token-erc20";
|
|||||||
export * from "./token-erc721";
|
export * from "./token-erc721";
|
||||||
export * from "./token-erc1155";
|
export * from "./token-erc1155";
|
||||||
export * from "./vote";
|
export * from "./vote";
|
||||||
|
export * from "./custom";
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import { AbstractWallet } from "../types/abstract";
|
||||||
|
import {
|
||||||
|
TypedDataDomain,
|
||||||
|
TypedDataField,
|
||||||
|
} from "@ethersproject/abstract-signer";
|
||||||
|
import { ethers } from "ethers";
|
||||||
|
import { AwsKmsSigner, AwsKmsSignerCredentials } from "ethers-aws-kms-signer";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a wallet instance using a private key stored in AWS KMS.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* ```javascript
|
||||||
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk"
|
||||||
|
* import { AwsKmsWallet } from "@thirdweb-dev/sdk/evm/wallets"
|
||||||
|
*
|
||||||
|
* const wallet = new AwsKmsallet({
|
||||||
|
* region: "us-east-1",
|
||||||
|
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||||
|
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||||
|
* sessionToken: process.env.AWS_SESSION_TOKEN,
|
||||||
|
* keyId: process.env.AWS_KEY_ID,
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* const sdk = await ThirdwebSDK.fromWallet(wallet, "mainnet");
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export class AwsKmsWallet extends AbstractWallet {
|
||||||
|
private cachedSigner: AwsKmsSigner;
|
||||||
|
|
||||||
|
constructor(options: AwsKmsSignerCredentials) {
|
||||||
|
super();
|
||||||
|
this.cachedSigner = this.updateSigner(new AwsKmsSigner(options));
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSigner(
|
||||||
|
provider?: ethers.providers.Provider,
|
||||||
|
): Promise<ethers.Signer> {
|
||||||
|
if (provider) {
|
||||||
|
this.cachedSigner = this.updateSigner(
|
||||||
|
this.cachedSigner.connect(provider),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.cachedSigner;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add _signTypedData method onto the signer for now so we don't need to reimpliment
|
||||||
|
// The entire AWS KMS signer repository and maintain it ourselves.
|
||||||
|
private updateSigner(signer: AwsKmsSigner): AwsKmsSigner {
|
||||||
|
(signer as any)._signTypedData = async function (
|
||||||
|
domain: TypedDataDomain,
|
||||||
|
types: Record<string, Array<TypedDataField>>,
|
||||||
|
value: Record<string, any>,
|
||||||
|
) {
|
||||||
|
const hash = ethers.utils._TypedDataEncoder.hash(domain, types, value);
|
||||||
|
return signer._signDigest(hash);
|
||||||
|
};
|
||||||
|
|
||||||
|
return signer;
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -18,7 +18,7 @@ export type AwsSecretsManagerWalletOptions = {
|
|||||||
* @example
|
* @example
|
||||||
* ```javascript
|
* ```javascript
|
||||||
* import { ThirdwebSDK } from "@thirdweb-dev/sdk"
|
* import { ThirdwebSDK } from "@thirdweb-dev/sdk"
|
||||||
* import { AWSSecretsManagerWallet } from "@thirdweb-dev/sdk/evm/wallets"
|
* import { AwsSecretsManagerWallet } from "@thirdweb-dev/sdk/evm/wallets"
|
||||||
*
|
*
|
||||||
* const wallet = new AwsSecretsManagerWallet({
|
* const wallet = new AwsSecretsManagerWallet({
|
||||||
* secretName: "my-secret",
|
* secretName: "my-secret",
|
||||||
@@ -35,7 +35,7 @@ export type AwsSecretsManagerWalletOptions = {
|
|||||||
* const sdk = await ThirdwebSDK.fromWallet(wallet, "mainnet");
|
* const sdk = await ThirdwebSDK.fromWallet(wallet, "mainnet");
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export class AWSSecretsManagerWallet extends AbstractWallet {
|
export class AwsSecretsManagerWallet extends AbstractWallet {
|
||||||
private secretId: string;
|
private secretId: string;
|
||||||
private secretKeyName: string;
|
private secretKeyName: string;
|
||||||
private client: SecretsManagerClient;
|
private client: SecretsManagerClient;
|
||||||
@@ -1 +1,2 @@
|
|||||||
export * from "./aws";
|
export * from "./aws-secrets-manager";
|
||||||
|
export * from "./aws-kms";
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export type {
|
|||||||
} from "./core/schema/nft";
|
} from "./core/schema/nft";
|
||||||
|
|
||||||
export type { CurrencyValue, TokenMetadata } from "./core/schema/token";
|
export type { CurrencyValue, TokenMetadata } from "./core/schema/token";
|
||||||
|
export { getRpcUrl } from "./core/constants/urls";
|
||||||
|
|
||||||
export type { QueryAllParams } from "./core/schema/QueryParams";
|
export type { QueryAllParams } from "./core/schema/QueryParams";
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ export class ClaimConditions {
|
|||||||
const goLiveDate = candyMachine.goLiveDate
|
const goLiveDate = candyMachine.goLiveDate
|
||||||
? new Date(candyMachine.goLiveDate.toNumber() * 1000)
|
? new Date(candyMachine.goLiveDate.toNumber() * 1000)
|
||||||
: null;
|
: null;
|
||||||
const isWithinGoLiveDate = candyMachine.goLiveDate
|
const isWithinGoLiveDate = goLiveDate ? goLiveDate <= new Date() : true;
|
||||||
? candyMachine.goLiveDate.toNumber() * 1000 >= Date.now()
|
|
||||||
: true;
|
|
||||||
const maxClaimable =
|
const maxClaimable =
|
||||||
candyMachine.endSettings && candyMachine.endSettings.endSettingType === 1
|
candyMachine.endSettings && candyMachine.endSettings.endSettingType === 1
|
||||||
? candyMachine.endSettings.number.toNumber()
|
? candyMachine.endSettings.number.toNumber()
|
||||||
@@ -155,7 +153,7 @@ export class ClaimConditions {
|
|||||||
const parsed = NFTDropUpdateableConditionsInputSchema.parse(metadata);
|
const parsed = NFTDropUpdateableConditionsInputSchema.parse(metadata);
|
||||||
|
|
||||||
// recipients
|
// recipients
|
||||||
const wallet: PublicKey | undefined = parsed.primarySaleRecipient
|
let wallet: PublicKey | undefined = parsed.primarySaleRecipient
|
||||||
? new PublicKey(parsed.primarySaleRecipient)
|
? new PublicKey(parsed.primarySaleRecipient)
|
||||||
: undefined;
|
: undefined;
|
||||||
const sellerFeeBasisPoints = parsed.sellerFeeBasisPoints;
|
const sellerFeeBasisPoints = parsed.sellerFeeBasisPoints;
|
||||||
@@ -165,12 +163,19 @@ export class ClaimConditions {
|
|||||||
? sol(Number(parsed.price))
|
? sol(Number(parsed.price))
|
||||||
: undefined;
|
: undefined;
|
||||||
let tokenMint: PublicKey | undefined = undefined;
|
let tokenMint: PublicKey | undefined = undefined;
|
||||||
if (parsed.currencyAddress && parsed.price) {
|
if (parsed.currencyAddress) {
|
||||||
const fetchedToken = await this.metaplex
|
const fetchedToken = await this.metaplex
|
||||||
.tokens()
|
.tokens()
|
||||||
.findMintByAddress({ address: new PublicKey(parsed.currencyAddress) });
|
.findMintByAddress({ address: new PublicKey(parsed.currencyAddress) });
|
||||||
price = token(Number(parsed.price), fetchedToken.decimals);
|
price = token(Number(parsed.price || 0), fetchedToken.decimals);
|
||||||
tokenMint = fetchedToken.address;
|
tokenMint = fetchedToken.address;
|
||||||
|
wallet = this.metaplex
|
||||||
|
.tokens()
|
||||||
|
.pdas()
|
||||||
|
.associatedTokenAccount({
|
||||||
|
mint: tokenMint,
|
||||||
|
owner: wallet ? wallet : this.metaplex.identity().publicKey,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// dates
|
// dates
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
} from "../../constants/addresses";
|
} from "../../constants/addresses";
|
||||||
import { TransactionResult } from "../../types/common";
|
import { TransactionResult } from "../../types/common";
|
||||||
import { CreatorOutput } from "../../types/programs";
|
import { CreatorOutput } from "../../types/programs";
|
||||||
import { getPublicRpc } from "../../utils/urls";
|
|
||||||
import { parseCreators } from "./creators-helper";
|
import { parseCreators } from "./creators-helper";
|
||||||
import {
|
import {
|
||||||
findMasterEditionV2Pda,
|
findMasterEditionV2Pda,
|
||||||
@@ -96,15 +95,10 @@ export class NFTHelper {
|
|||||||
|
|
||||||
async ownerOf(nftAddress: string): Promise<string | undefined> {
|
async ownerOf(nftAddress: string): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
// TODO switch back to normal connection when alchemy supports getTokenLargestAccounts
|
const largestAccounts = await this.connection.getTokenLargestAccounts(
|
||||||
const connection = new Connection(
|
|
||||||
getPublicRpc(this.metaplex),
|
|
||||||
"confirmed",
|
|
||||||
);
|
|
||||||
const largestAccounts = await connection.getTokenLargestAccounts(
|
|
||||||
new PublicKey(nftAddress),
|
new PublicKey(nftAddress),
|
||||||
);
|
);
|
||||||
const largestAccountInfo = await connection.getParsedAccountInfo(
|
const largestAccountInfo = await this.connection.getParsedAccountInfo(
|
||||||
largestAccounts.value[0].address,
|
largestAccounts.value[0].address,
|
||||||
);
|
);
|
||||||
const parsedData = largestAccountInfo?.value?.data as ParsedAccountData;
|
const parsedData = largestAccountInfo?.value?.data as ParsedAccountData;
|
||||||
|
|||||||
@@ -440,9 +440,9 @@ export class NFTDrop {
|
|||||||
* console.log("Claimed NFT at address", claimedAddresses[0]);
|
* console.log("Claimed NFT at address", claimedAddresses[0]);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
async claim(quantity: Amount): Promise<string[]> {
|
async claim(amount: Amount): Promise<string[]> {
|
||||||
const address = this.metaplex.identity().publicKey.toBase58();
|
const address = this.metaplex.identity().publicKey.toBase58();
|
||||||
return this.claimTo(address, quantity);
|
return this.claimTo(address, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -462,7 +462,7 @@ export class NFTDrop {
|
|||||||
const candyMachine = await this.getCandyMachine();
|
const candyMachine = await this.getCandyMachine();
|
||||||
await this.claimConditions.assertCanClaimable(Number(amount));
|
await this.claimConditions.assertCanClaimable(Number(amount));
|
||||||
const builders = await Promise.all(
|
const builders = await Promise.all(
|
||||||
[...Array(amount).keys()].map(async () => {
|
[...Array(Number(amount)).keys()].map(async () => {
|
||||||
return await this.metaplex
|
return await this.metaplex
|
||||||
.candyMachinesV2()
|
.candyMachinesV2()
|
||||||
.builders()
|
.builders()
|
||||||
|
|||||||
@@ -56,7 +56,16 @@ export type NFTCollectionMetadataInput = z.input<
|
|||||||
*/
|
*/
|
||||||
export const TokenMetadataInputSchema = CommonContractSchema.extend({
|
export const TokenMetadataInputSchema = CommonContractSchema.extend({
|
||||||
decimals: z.number().default(9),
|
decimals: z.number().default(9),
|
||||||
initialSupply: AmountSchema,
|
initialSupply: AmountSchema.superRefine((val, context) => {
|
||||||
|
// TODO remove this limitation when metaplex fixes https://github.com/metaplex-foundation/js/issues/421
|
||||||
|
if (Number(val) > 9999999) {
|
||||||
|
context.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
message: `Initial supply must less than 10M, additional supply can be minted after deployment.`,
|
||||||
|
path: ["initialSupply"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,28 +29,43 @@ export async function sendMultipartTransaction(
|
|||||||
// make the connected wallet sign all transactions
|
// make the connected wallet sign all transactions
|
||||||
const signedTx = await metaplex.identity().signAllTransactions(txns);
|
const signedTx = await metaplex.identity().signAllTransactions(txns);
|
||||||
|
|
||||||
// send the signed transactions
|
// send the signed transactions in batches
|
||||||
let signatures = [];
|
const batchSize = 200; // sends 200 raw tx in parallel
|
||||||
for (const tx of signedTx) {
|
const batches = [];
|
||||||
const signature = await metaplex.connection.sendRawTransaction(
|
for (let i = 0; i < signedTx.length; i += batchSize) {
|
||||||
tx.serialize(),
|
batches.push(signedTx.slice(i, i + batchSize));
|
||||||
|
}
|
||||||
|
let signatures: string[][] = [];
|
||||||
|
for (const txs of batches) {
|
||||||
|
const signature = await Promise.all(
|
||||||
|
txs.map((tx) => metaplex.connection.sendRawTransaction(tx.serialize())),
|
||||||
);
|
);
|
||||||
signatures.push(signature);
|
signatures.push(signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for confirmations in parallel
|
// wait for confirmations in parallel batches
|
||||||
const confirmations = await Promise.all(
|
let confirmations = [];
|
||||||
signatures.map((sig) => {
|
for (let i = 0; i < signatures.length; i += 1) {
|
||||||
return metaplex.rpc().confirmTransaction(sig, {
|
await delay(1000); // add delay to avoid rate limiting
|
||||||
blockhash: block.blockhash,
|
const sigs = signatures[i];
|
||||||
lastValidBlockHeight: block.lastValidBlockHeight,
|
const confirmationBatch = await Promise.all(
|
||||||
});
|
sigs.map((sig) => {
|
||||||
}),
|
return metaplex.rpc().confirmTransaction(sig, {
|
||||||
);
|
blockhash: block.blockhash,
|
||||||
|
lastValidBlockHeight: block.lastValidBlockHeight,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
confirmations.push(...confirmationBatch);
|
||||||
|
}
|
||||||
|
|
||||||
if (confirmations.length === 0) {
|
if (confirmations.length === 0) {
|
||||||
throw new Error("Transaction failed");
|
throw new Error("Transaction failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return signatures.map((signature) => ({ signature }));
|
return signatures.flatMap((sig) => sig).map((signature) => ({ signature }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function delay(delayMs: number) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import {
|
||||||
|
extractMinimalProxyImplementationAddress,
|
||||||
|
ThirdwebSDK,
|
||||||
|
} from "../../src/evm";
|
||||||
|
import { signers, sdk } from "./before-setup";
|
||||||
|
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
|
||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
global.fetch = require("cross-fetch");
|
||||||
|
|
||||||
|
describe("Custom Contracts", async () => {
|
||||||
|
let adminWallet: SignerWithAddress;
|
||||||
|
let realSDK: ThirdwebSDK;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
[adminWallet] = signers;
|
||||||
|
realSDK = new ThirdwebSDK(adminWallet);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
sdk.updateSignerOrProvider(adminWallet);
|
||||||
|
realSDK.updateSignerOrProvider(adminWallet);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract implementation address for eip-1167 minimal proxy", async () => {
|
||||||
|
// https://eips.ethereum.org/EIPS/eip-1167#specification
|
||||||
|
const code =
|
||||||
|
"0x363d3d373d3d3d363d73bebebebebebebebebebebebebebebebebebebebe5af43d82803e903d91602b57fd5bf3";
|
||||||
|
const implementationAddress =
|
||||||
|
extractMinimalProxyImplementationAddress(code);
|
||||||
|
expect(implementationAddress).to.equal(
|
||||||
|
"0xbebebebebebebebebebebebebebebebebebebebe",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract implementation address for minimal proxy with receive", async () => {
|
||||||
|
// https://github.com/0xSplits/splits-contracts/blob/c7b741926ec9746182d0d1e2c4c2046102e5d337/contracts/libraries/Clones.sol#L32
|
||||||
|
const code =
|
||||||
|
"0x36603057343d52307f830d2d700a97af574b186c80d40429385d24241565b08a7c559ba283a964d9b160203da23d3df35b3d3d3d3d363d3d37363d73bebebebebebebebebebebebebebebebebebebebe5af43d3d93803e605b57fd5bf3";
|
||||||
|
const implementationAddress =
|
||||||
|
extractMinimalProxyImplementationAddress(code);
|
||||||
|
expect(implementationAddress).to.equal(
|
||||||
|
"0xbebebebebebebebebebebebebebebebebebebebe",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract implementation address for more minimal proxy", async () => {
|
||||||
|
// https://medium.com/coinmonks/the-more-minimal-proxy-5756ae08ee48
|
||||||
|
const code =
|
||||||
|
"0x3d3d3d3d363d3d37363d73bebebebebebebebebebebebebebebebebebebebe5af43d3d93803e602a57fd5bf3";
|
||||||
|
const implementationAddress =
|
||||||
|
extractMinimalProxyImplementationAddress(code);
|
||||||
|
expect(implementationAddress).to.equal(
|
||||||
|
"0xbebebebebebebebebebebebebebebebebebebebe",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should extract implementation address for older vyper (uniswap v1) proxy", async () => {
|
||||||
|
const code =
|
||||||
|
"0x366000600037611000600036600073bebebebebebebebebebebebebebebebebebebebe5af41558576110006000f3";
|
||||||
|
const implementationAddress =
|
||||||
|
extractMinimalProxyImplementationAddress(code);
|
||||||
|
expect(implementationAddress).to.equal(
|
||||||
|
"0xbebebebebebebebebebebebebebebebebebebebe",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -56,4 +56,25 @@ describe("Wallet", async () => {
|
|||||||
const address = sdk.wallet.recoverAddress(message, signature);
|
const address = sdk.wallet.recoverAddress(message, signature);
|
||||||
expect(address).to.eq(adminWallet.address);
|
expect(address).to.eq(adminWallet.address);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should sign typed data and recover address", async () => {
|
||||||
|
sdk.updateSignerOrProvider(adminWallet);
|
||||||
|
const { payload, signature } = await sdk.wallet.signTypedData(
|
||||||
|
{
|
||||||
|
name: "MyEIP721Domain",
|
||||||
|
version: "1",
|
||||||
|
chainId: 1,
|
||||||
|
verifyingContract: adminWallet.address,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MyStruct: [
|
||||||
|
{ name: "to", type: "address" },
|
||||||
|
{ name: "quantity", type: "uint256" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ to: adminWallet.address, quantity: 1 },
|
||||||
|
);
|
||||||
|
expect(payload !== undefined).to.eq(true);
|
||||||
|
expect(signature !== undefined).to.eq(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -149,16 +149,13 @@ describe("NFTCollection", async () => {
|
|||||||
expect(creators[0].share).to.equal(100);
|
expect(creators[0].share).to.equal(100);
|
||||||
|
|
||||||
const newCreator = Keypair.generate().publicKey.toBase58();
|
const newCreator = Keypair.generate().publicKey.toBase58();
|
||||||
await collection.updateCreators(
|
await collection.updateCreators([
|
||||||
[
|
{
|
||||||
{
|
address: sdk.wallet.getAddress() as string,
|
||||||
address: sdk.wallet.getAddress() as string,
|
share: 75,
|
||||||
share: 75,
|
},
|
||||||
},
|
{ address: newCreator, share: 25 },
|
||||||
{ address: newCreator, share: 25 },
|
]);
|
||||||
],
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
creators = await collection.getCreators();
|
creators = await collection.getCreators();
|
||||||
expect(creators.length).to.equal(2);
|
expect(creators.length).to.equal(2);
|
||||||
@@ -167,16 +164,17 @@ describe("NFTCollection", async () => {
|
|||||||
expect(creators[1].address).to.equal(newCreator);
|
expect(creators[1].address).to.equal(newCreator);
|
||||||
expect(creators[1].share).to.equal(25);
|
expect(creators[1].share).to.equal(25);
|
||||||
|
|
||||||
const all = await collection.getAll();
|
// TODO (adam): fix this test
|
||||||
for (const nft of all) {
|
// const all = await collection.getAll();
|
||||||
// @ts-ignore
|
// for (const nft of all) {
|
||||||
const creatorsOfNft = await collection.nft.creatorsOf(nft.metadata.id);
|
// // @ts-ignore
|
||||||
expect(creatorsOfNft.length).to.equal(2);
|
// const creatorsOfNft = await collection.nft.creatorsOf(nft.metadata.id);
|
||||||
expect(creatorsOfNft[0].address).to.equal(sdk.wallet.getAddress());
|
// expect(creatorsOfNft.length).to.equal(2);
|
||||||
expect(creatorsOfNft[0].share).to.equal(75);
|
// expect(creatorsOfNft[0].address).to.equal(sdk.wallet.getAddress());
|
||||||
expect(creatorsOfNft[1].address).to.equal(newCreator);
|
// expect(creatorsOfNft[0].share).to.equal(75);
|
||||||
expect(creatorsOfNft[1].share).to.equal(25);
|
// expect(creatorsOfNft[1].address).to.equal(newCreator);
|
||||||
}
|
// expect(creatorsOfNft[1].share).to.equal(25);
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should update royalty", async () => {
|
it("Should update royalty", async () => {
|
||||||
@@ -189,13 +187,13 @@ describe("NFTCollection", async () => {
|
|||||||
expect(nft.isMutable).to.equal(true);
|
expect(nft.isMutable).to.equal(true);
|
||||||
expect(nft.sellerFeeBasisPoints).to.equal(0);
|
expect(nft.sellerFeeBasisPoints).to.equal(0);
|
||||||
|
|
||||||
await collection.updateRoyalty(100, true);
|
await collection.updateRoyalty(100);
|
||||||
|
|
||||||
royalty = await collection.getRoyalty();
|
royalty = await collection.getRoyalty();
|
||||||
expect(royalty).to.equal(100);
|
expect(royalty).to.equal(100);
|
||||||
|
|
||||||
// @ts-ignore
|
// TODO (adam): fix this test
|
||||||
nft = await collection.nft.getRaw(mintAddress);
|
// nft = await collection.nft.getRaw(mintAddress);
|
||||||
expect(nft.sellerFeeBasisPoints).to.equal(100);
|
// expect(nft.sellerFeeBasisPoints).to.equal(100);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { NFTDrop, Token } from "../../src/solana";
|
||||||
|
import { sdk } from "./before-setup";
|
||||||
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
describe("NFTDrop ClaimConditions", async () => {
|
||||||
|
let drop: NFTDrop;
|
||||||
|
let token: Token;
|
||||||
|
let primarySaleRecipient: string;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const address = await sdk.deployer.createNftDrop({
|
||||||
|
name: "NFT Drop #1",
|
||||||
|
totalSupply: 5,
|
||||||
|
});
|
||||||
|
const addressToken = await sdk.deployer.createToken({
|
||||||
|
name: "Token #1",
|
||||||
|
initialSupply: 100,
|
||||||
|
});
|
||||||
|
drop = await sdk.getNFTDrop(address);
|
||||||
|
token = await sdk.getToken(addressToken);
|
||||||
|
primarySaleRecipient = Keypair.generate().publicKey.toBase58();
|
||||||
|
await token.mintTo(primarySaleRecipient, 1); // only needed to create the token account / TODO expose utility for it
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should set claim conditions with custom currency and claim", async () => {
|
||||||
|
const metadatas = [...Array(5)].map((_, i) => ({
|
||||||
|
name: `NFT #${i + 1}`,
|
||||||
|
description: `This is the #${i + 1} NFT`,
|
||||||
|
}));
|
||||||
|
await drop.lazyMint(metadatas);
|
||||||
|
expect((await token.balance()).displayValue).to.eq("100.000000000");
|
||||||
|
expect((await token.balanceOf(primarySaleRecipient)).displayValue).to.eq(
|
||||||
|
"1.000000000",
|
||||||
|
);
|
||||||
|
|
||||||
|
await drop.claimConditions.set({
|
||||||
|
maxClaimable: 3,
|
||||||
|
currencyAddress: token.publicKey.toBase58(),
|
||||||
|
price: 1,
|
||||||
|
primarySaleRecipient,
|
||||||
|
});
|
||||||
|
const addresses = await drop.claim(2);
|
||||||
|
expect(addresses.length).to.eq(2);
|
||||||
|
expect((await token.balance()).displayValue).to.eq("98.000000000");
|
||||||
|
expect((await token.balanceOf(primarySaleRecipient)).displayValue).to.eq(
|
||||||
|
"3.000000000",
|
||||||
|
);
|
||||||
|
expect(await drop.balance(addresses[0])).to.eq(1);
|
||||||
|
expect(await drop.balance(addresses[1])).to.eq(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# folders
|
||||||
|
dist/
|
||||||
|
|
||||||
|
# files
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
extends: ["thirdweb"],
|
||||||
|
};
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
# @thirdweb-dev/unity-js-bridge
|
||||||
|
|
||||||
|
## 0.1.5
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`e913e0d`](https://github.com/thirdweb-dev/js/commit/e913e0daa9ece9a6274f7ffa4e66bdcbf32e6ada), [`5862c55`](https://github.com/thirdweb-dev/js/commit/5862c558fb48604b5aca4defd1ccc06fc3536358), [`73883f5`](https://github.com/thirdweb-dev/js/commit/73883f56d0ed0a35ace8b98b96caa782443be22e), [`f7a74a3`](https://github.com/thirdweb-dev/js/commit/f7a74a3b7c489ada5b1ec435632a326334a33c9b)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.9
|
||||||
|
|
||||||
|
## 0.1.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#457](https://github.com/thirdweb-dev/js/pull/457) [`ccb4ce8`](https://github.com/thirdweb-dev/js/commit/ccb4ce8d00f50ff34426a0a5e58c7243e409f706) Thanks [@jnsdls](https://github.com/jnsdls)! - Support for new magic link connector
|
||||||
|
|
||||||
|
- [#454](https://github.com/thirdweb-dev/js/pull/454) [`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0) Thanks [@jnsdls](https://github.com/jnsdls)! - upgraded dependencies
|
||||||
|
|
||||||
|
- [#458](https://github.com/thirdweb-dev/js/pull/458) [`4cdd0bd`](https://github.com/thirdweb-dev/js/commit/4cdd0bd6348494a256d7c6a2bdf8f7b5c20f6877) Thanks [@joaquim-verges](https://github.com/joaquim-verges)! - Fixes for latest wallet package integration
|
||||||
|
|
||||||
|
- Updated dependencies [[`ccb4ce8`](https://github.com/thirdweb-dev/js/commit/ccb4ce8d00f50ff34426a0a5e58c7243e409f706), [`c673e39`](https://github.com/thirdweb-dev/js/commit/c673e39f23ef082097d73d62910580e8fad400a0), [`ea95c5f`](https://github.com/thirdweb-dev/js/commit/ea95c5f609e306e333ee0f73f7920503358ca848), [`699a2b1`](https://github.com/thirdweb-dev/js/commit/699a2b16fb991c474ec57db8f178e2601d631f39), [`4cdd0bd`](https://github.com/thirdweb-dev/js/commit/4cdd0bd6348494a256d7c6a2bdf8f7b5c20f6877), [`a8267f9`](https://github.com/thirdweb-dev/js/commit/a8267f912df84c58d3fe3f47b90bd474f73c84ca)]:
|
||||||
|
- @thirdweb-dev/wallets@0.1.1
|
||||||
|
- @thirdweb-dev/sdk@3.6.8
|
||||||
|
|
||||||
|
## 0.1.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`3731459`](https://github.com/thirdweb-dev/js/commit/3731459d33f1ded7ebb69124809449b901b3ad3d), [`cac6c30`](https://github.com/thirdweb-dev/js/commit/cac6c30bca5e17df81d746ef81316af47d5e252e), [`7a37e56`](https://github.com/thirdweb-dev/js/commit/7a37e564fd5d5a9df84c8da44ecaf6c42f67a0e2)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.7
|
||||||
|
|
||||||
|
## 0.1.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`8c6cdaa`](https://github.com/thirdweb-dev/js/commit/8c6cdaa2887fb2cc40d3ee6991233d195d103805)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.6
|
||||||
|
|
||||||
|
## 0.1.1
|
||||||
|
|
||||||
|
### Patch 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)! - add fundWallet method to bridge
|
||||||
|
|
||||||
|
- Updated dependencies [[`efc56fa`](https://github.com/thirdweb-dev/js/commit/efc56fa5802490ac8ef50037658d046afd89e9a1), [`7269268`](https://github.com/thirdweb-dev/js/commit/72692689e9adb41e92038765fd01a36c2b7457e1)]:
|
||||||
|
- @thirdweb-dev/sdk@3.6.5
|
||||||
|
- @thirdweb-dev/pay@0.1.0
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- [#420](https://github.com/thirdweb-dev/js/pull/420) [`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45) Thanks [@jnsdls](https://github.com/jnsdls)! - Initial Release
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies [[`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45), [`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/wallets@0.1.0
|
||||||
|
- @thirdweb-dev/sdk@3.6.4
|
||||||
@@ -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 Unity JS bridge</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,34 @@
|
|||||||
|
{
|
||||||
|
"name": "@thirdweb-dev/unity-js-bridge",
|
||||||
|
"version": "0.1.5",
|
||||||
|
"main": "dist/thirdweb-unity-bridge.js",
|
||||||
|
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/thirdweb-dev/js/issues"
|
||||||
|
},
|
||||||
|
"author": "thirdweb eng <[email protected]>",
|
||||||
|
"files": [
|
||||||
|
"dist/"
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"@thirdweb-dev/pay": "*",
|
||||||
|
"@thirdweb-dev/sdk": "*",
|
||||||
|
"@thirdweb-dev/storage": "*",
|
||||||
|
"@thirdweb-dev/wallets": "*",
|
||||||
|
"ethers": "^5.7.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"esbuild": "0.15.17",
|
||||||
|
"node-stdlib-browser": "^1.2.0",
|
||||||
|
"typescript": "^4.7.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"format": "prettier --write 'src/**/*'",
|
||||||
|
"lint": "eslint src/",
|
||||||
|
"fix": "eslint src/ --fix",
|
||||||
|
"clean": "rm -rf dist/",
|
||||||
|
"build": "yarn clean && tsc && node scripts/build.js",
|
||||||
|
"push": "yalc push"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
const esbuild = require("esbuild");
|
||||||
|
const plugin = require("node-stdlib-browser/helpers/esbuild/plugin");
|
||||||
|
const stdLibBrowser = require("node-stdlib-browser");
|
||||||
|
|
||||||
|
// const DIST_PATH = path.resolve(process.cwd(), "dist/");
|
||||||
|
|
||||||
|
// fs.rmSync(DIST_PATH, { recursive: true, force: true });
|
||||||
|
|
||||||
|
esbuild.build({
|
||||||
|
jsx: "automatic",
|
||||||
|
entryPoints: ["src/thirdweb-bridge.ts"],
|
||||||
|
bundle: true,
|
||||||
|
minify: true,
|
||||||
|
platform: "browser",
|
||||||
|
target: "es2020",
|
||||||
|
outfile: "dist/thirdweb-unity-bridge.js",
|
||||||
|
splitting: false,
|
||||||
|
write: true,
|
||||||
|
sourcemap: false,
|
||||||
|
inject: [require.resolve("node-stdlib-browser/helpers/esbuild/shim")],
|
||||||
|
define: {
|
||||||
|
process: JSON.stringify({
|
||||||
|
env: "production",
|
||||||
|
}),
|
||||||
|
Buffer: "Buffer",
|
||||||
|
},
|
||||||
|
plugins: [plugin(stdLibBrowser)],
|
||||||
|
});
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
/// --- Thirdweb Brige ---
|
||||||
|
import { CoinbasePayIntegration, FundWalletOptions } from "@thirdweb-dev/pay";
|
||||||
|
import { ChainOrRpc, ThirdwebSDK, getRpcUrl } from "@thirdweb-dev/sdk";
|
||||||
|
import { ThirdwebStorage } from "@thirdweb-dev/storage";
|
||||||
|
import {
|
||||||
|
CoinbaseWallet,
|
||||||
|
MetaMask,
|
||||||
|
WalletConnect,
|
||||||
|
InjectedWallet,
|
||||||
|
MagicAuthWallet,
|
||||||
|
} from "@thirdweb-dev/wallets";
|
||||||
|
import type { AbstractWallet } from "@thirdweb-dev/wallets/dist/declarations/src/wallets/base";
|
||||||
|
import { BigNumber } from "ethers";
|
||||||
|
import type { ContractInterface, Signer } from "ethers";
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
bridge: TWBridge;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const API_KEY =
|
||||||
|
"339d65590ba0fa79e4c8be0af33d64eda709e13652acb02c6be63f5a1fbef9c3";
|
||||||
|
const SEPARATOR = "/";
|
||||||
|
const SUB_SEPARATOR = "#";
|
||||||
|
|
||||||
|
// big number transform
|
||||||
|
const bigNumberReplacer = (_key: string, value: any) => {
|
||||||
|
// if we find a BigNumber then make it into a string (since that is safe)
|
||||||
|
if (
|
||||||
|
BigNumber.isBigNumber(value) ||
|
||||||
|
(typeof value === "object" &&
|
||||||
|
value !== null &&
|
||||||
|
value.type === "BigNumber" &&
|
||||||
|
"hex" in value)
|
||||||
|
) {
|
||||||
|
return BigNumber.from(value).toString();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const WALLETS = [
|
||||||
|
MetaMask,
|
||||||
|
InjectedWallet,
|
||||||
|
WalletConnect,
|
||||||
|
CoinbaseWallet,
|
||||||
|
MagicAuthWallet,
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
type PossibleWallet = typeof WALLETS[number]["id"];
|
||||||
|
|
||||||
|
type FundWalletInput = FundWalletOptions & {
|
||||||
|
appId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface TWBridge {
|
||||||
|
initialize: (chain: ChainOrRpc, options: string) => void;
|
||||||
|
connect: (wallet: PossibleWallet, chainId?: number) => Promise<string>;
|
||||||
|
disconnect: () => Promise<void>;
|
||||||
|
switchNetwork: (chainId: number) => Promise<void>;
|
||||||
|
invoke: (route: string, payload: string) => Promise<string | undefined>;
|
||||||
|
fundWallet: (options: string) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const w = window;
|
||||||
|
|
||||||
|
class ThirdwebBridge implements TWBridge {
|
||||||
|
private walletMap: Map<string, AbstractWallet> = new Map();
|
||||||
|
private activeWallet: AbstractWallet | undefined;
|
||||||
|
private initializedChain: ChainOrRpc | undefined;
|
||||||
|
private activeSDK: ThirdwebSDK | undefined;
|
||||||
|
|
||||||
|
private updateSDKSigner(signer?: Signer) {
|
||||||
|
if (this.activeSDK) {
|
||||||
|
if (signer) {
|
||||||
|
// set signer if we got one
|
||||||
|
this.activeSDK.updateSignerOrProvider(signer);
|
||||||
|
} else if (this.initializedChain) {
|
||||||
|
// reset back to provider only in case signer gets reomved (disconnect case)
|
||||||
|
this.activeSDK.updateSignerOrProvider(this.initializedChain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public initialize(chain: ChainOrRpc, options: string) {
|
||||||
|
this.initializedChain = chain;
|
||||||
|
console.debug("thirdwebSDK initialization:", chain, options);
|
||||||
|
const sdkOptions = JSON.parse(options);
|
||||||
|
const storage =
|
||||||
|
sdkOptions?.storage && sdkOptions?.storage?.ipfsGatewayUrl
|
||||||
|
? new ThirdwebStorage({
|
||||||
|
gatewayUrls: {
|
||||||
|
"ipfs://": [sdkOptions.storage.ipfsGatewayUrl],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: new ThirdwebStorage();
|
||||||
|
const rpcUrl = chain.startsWith("http") ? chain : getRpcUrl(chain, API_KEY);
|
||||||
|
this.activeSDK = new ThirdwebSDK(rpcUrl, sdkOptions, storage);
|
||||||
|
for (let wallet of WALLETS) {
|
||||||
|
const walletInstance = new wallet({
|
||||||
|
appName: sdkOptions.wallet?.appName || "thirdweb powered dApp",
|
||||||
|
...sdkOptions.wallet?.extras,
|
||||||
|
});
|
||||||
|
walletInstance.on("connect", async () =>
|
||||||
|
this.updateSDKSigner(await walletInstance.getSigner()),
|
||||||
|
);
|
||||||
|
walletInstance.on("change", async () =>
|
||||||
|
this.updateSDKSigner(await walletInstance.getSigner()),
|
||||||
|
);
|
||||||
|
walletInstance.on("disconnect", () => this.updateSDKSigner());
|
||||||
|
|
||||||
|
this.walletMap.set(wallet.id, walletInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async connect(
|
||||||
|
wallet: PossibleWallet = "injected",
|
||||||
|
chainId?: number | undefined,
|
||||||
|
) {
|
||||||
|
if (!this.activeSDK) {
|
||||||
|
throw new Error("SDK not initialized");
|
||||||
|
}
|
||||||
|
if (chainId === 0) {
|
||||||
|
chainId = undefined;
|
||||||
|
}
|
||||||
|
const walletInstance = this.walletMap.get(wallet);
|
||||||
|
if (walletInstance) {
|
||||||
|
await walletInstance.connect(chainId);
|
||||||
|
this.activeWallet = walletInstance;
|
||||||
|
this.updateSDKSigner(await walletInstance.getSigner());
|
||||||
|
return await this.activeSDK.wallet.getAddress();
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid Wallet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async disconnect() {
|
||||||
|
if (this.activeWallet) {
|
||||||
|
await this.activeWallet.disconnect();
|
||||||
|
this.activeWallet = undefined;
|
||||||
|
this.updateSDKSigner();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async switchNetwork(chainId: number) {
|
||||||
|
if (chainId && this.activeWallet && "switchChain" in this.activeWallet) {
|
||||||
|
await this.activeWallet.switchChain(chainId);
|
||||||
|
this.updateSDKSigner(await this.activeWallet.getSigner());
|
||||||
|
} else {
|
||||||
|
throw new Error("Error Switching Network");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async invoke(route: string, payload: string) {
|
||||||
|
if (!this.activeSDK) {
|
||||||
|
throw new Error("SDK not initialized");
|
||||||
|
}
|
||||||
|
const routeArgs = route.split(SEPARATOR);
|
||||||
|
const firstArg = routeArgs[0].split(SUB_SEPARATOR);
|
||||||
|
const addrOrSDK = firstArg[0];
|
||||||
|
|
||||||
|
const fnArgs = JSON.parse(payload).arguments;
|
||||||
|
const parsedArgs = fnArgs.map((arg: unknown) => {
|
||||||
|
try {
|
||||||
|
return typeof arg === "string" &&
|
||||||
|
(arg.startsWith("{") || arg.startsWith("["))
|
||||||
|
? JSON.parse(arg)
|
||||||
|
: arg;
|
||||||
|
} catch (e) {
|
||||||
|
return arg;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.debug("thirdwebSDK call:", route, parsedArgs);
|
||||||
|
|
||||||
|
// wallet call
|
||||||
|
if (addrOrSDK.startsWith("sdk")) {
|
||||||
|
let prop = undefined;
|
||||||
|
if (firstArg.length > 1) {
|
||||||
|
prop = firstArg[1];
|
||||||
|
}
|
||||||
|
if (prop && routeArgs.length === 2) {
|
||||||
|
// @ts-expect-error need to type-guard this properly
|
||||||
|
const result = await this.activeSDK[prop][routeArgs[1]](...parsedArgs);
|
||||||
|
return JSON.stringify({ result: result }, bigNumberReplacer);
|
||||||
|
} else if (routeArgs.length === 2) {
|
||||||
|
// @ts-expect-error need to type-guard this properly
|
||||||
|
const result = await this.activeSDK[routeArgs[1]](...parsedArgs);
|
||||||
|
return JSON.stringify({ result: result }, bigNumberReplacer);
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid Route");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// contract call
|
||||||
|
if (addrOrSDK.startsWith("0x")) {
|
||||||
|
let typeOrAbi: string | ContractInterface | undefined;
|
||||||
|
if (firstArg.length > 1) {
|
||||||
|
try {
|
||||||
|
typeOrAbi = JSON.parse(firstArg[1]); // try to parse ABI
|
||||||
|
} catch (e) {
|
||||||
|
typeOrAbi = firstArg[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const contract = typeOrAbi
|
||||||
|
? await this.activeSDK.getContract(addrOrSDK, typeOrAbi)
|
||||||
|
: await this.activeSDK.getContract(addrOrSDK);
|
||||||
|
if (routeArgs.length === 2) {
|
||||||
|
// @ts-expect-error need to type-guard this properly
|
||||||
|
const result = await contract[routeArgs[1]](...parsedArgs);
|
||||||
|
return JSON.stringify({ result: result }, bigNumberReplacer);
|
||||||
|
} else if (routeArgs.length === 3) {
|
||||||
|
// @ts-expect-error need to type-guard this properly
|
||||||
|
const result = await contract[routeArgs[1]][routeArgs[2]](
|
||||||
|
...parsedArgs,
|
||||||
|
);
|
||||||
|
return JSON.stringify({ result: result }, bigNumberReplacer);
|
||||||
|
} else if (routeArgs.length === 4) {
|
||||||
|
// @ts-expect-error need to type-guard this properly
|
||||||
|
const result = await contract[routeArgs[1]][routeArgs[2]][routeArgs[3]](
|
||||||
|
...parsedArgs,
|
||||||
|
);
|
||||||
|
return JSON.stringify({ result: result }, bigNumberReplacer);
|
||||||
|
} else {
|
||||||
|
throw new Error("Invalid Route");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public async fundWallet(options: string) {
|
||||||
|
if (!this.activeSDK) {
|
||||||
|
throw new Error("SDK not initialized");
|
||||||
|
}
|
||||||
|
const { appId, ...fundOptions } = JSON.parse(options) as FundWalletInput;
|
||||||
|
const cbPay = new CoinbasePayIntegration({ appId });
|
||||||
|
|
||||||
|
return await cbPay.fundWallet(fundOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the bridge to the window object type
|
||||||
|
w.bridge = new ThirdwebBridge();
|
||||||
|
|
||||||
|
/// --- End Thirdweb Brige ---
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"extends": "@thirdweb-dev/tsconfig/base.json",
|
||||||
|
"include": ["src", "types"],
|
||||||
|
"exclude": ["dist", "build", "node_modules"]
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user