Skip to content

Commit 01d91f9

Browse files
committed
revert: restore x-client and x-provider packages
Revert removal of x-client and x-provider packages and the @imtbl/sdk/x entrypoint. These will be removed in a dedicated follow-up PR to keep the Passport StarkEx cleanup scoped to passport-specific changes.
1 parent 4382042 commit 01d91f9

291 files changed

Lines changed: 32971 additions & 84 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#Obtained at hub.immutable.com
2+
SANDBOX_HUB_IMMUTABLE_API_KEY=
3+
SANDBOX_RPS_IMMUTABLE_API_KEY=
4+
5+
MAINNET_HUB_IMMUTABLE_API_KEY=
6+
MAINNET_RPS_IMMUTABLE_API_KEY=
7+
8+
# Example: file:./allowList.db
9+
DATABASE_URL=
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.env
2+
/node_modules
3+
.DS_Store
4+
prisma/allowList.db
5+
prisma/allowList.db-journal
6+
/logs
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Minting API Backend for conducting a free mint
2+
3+
This project is a backend API for doing a free mint on IMX zkEVM.
4+
5+
## Disclaimer
6+
7+
The sample code provided is for reference purposes only. It has undergone best effort testing by Immutable to ensure basic functionality. However, it is essential that you thoroughly test this sample code within your own environment to confirm its functionality and reliability before deploying it in a production setting. Immutable disclaims any liability for any issues that arise due to the use of this sample code. By using this sample code, you agree to perform due diligence in testing and verifying its suitability for your applications.
8+
9+
## Features
10+
11+
- Uses the Immutable Minting API to ensure that minting is sponsored on top of transaction life cycle monitoring, nonce management etc. is abstracted.
12+
- Async Minting by 1. store minting intention, 2. submit minting to Immutable Minting API in background, 3. listening to webhook for minting status.
13+
- Passport authentication.
14+
- Define phases that the mint should occur in, start times and end times.
15+
- Ability to allowlist addresses for minting for different phases
16+
17+
## Setup Instructions
18+
19+
1. Install the dependencies:
20+
```
21+
npm i
22+
```
23+
2. Copy the example environment file and fill it with your API key, and DB path(should be `file:./allowList.db`):
24+
```
25+
cp .env.example .env
26+
```
27+
3. Make sure to configure `src/config.ts` with collection address etc after deploying the contract on hub.immutable.com. Pay specific attention to the mintPhases parameter:
28+
```
29+
mintPhases: [
30+
{
31+
name: "Presale",
32+
startTime: 1629913600,
33+
endTime: 1629999999,
34+
maxSupply: 1000,
35+
enableAllowList: true,
36+
},
37+
{
38+
name: "Public Sale",
39+
startTime: 1630000000,
40+
endTime: 1719292800,
41+
maxSupply: 9000,
42+
enableAllowList: false,
43+
maxPerWallet: 2,
44+
}],
45+
```
46+
Keep in mind that you can configure a single phase if you're not planning a phased approach but just a start/end time.
47+
48+
This sample app only support the same metadata for all the mints. it is defined in the `metadata` field in the same `src/config.ts` file. Please make amend logic inside `server.ts` for calls to `mintingBackend.recordMint` to give metadata per token.
49+
50+
4. Run the DB migrations:
51+
52+
```
53+
npx prisma migrate dev
54+
```
55+
56+
Every time you change primsa schema you need to run the above.
57+
58+
5. Load your database, https://sqlitebrowser.org/ is great for this. You can also write a script that uses the Prisma client to load the database. Make sure you have your address allowlisted, and quantity is 1, isLocked is 0, hasMinted is 0.
59+
60+
6. Run the development server:
61+
62+
```
63+
npm start
64+
```
65+
66+
7. Create your webhook at https://hub.immutable.com/, use localtunnel for testing webhooks locally:
67+
68+
```
69+
npx localtunnel --port 3000
70+
```
71+
72+
Use the above URL for the webhook endpoint with the path `/api/process_webhook_event`. For example: `https://ten-rooms-vanish.loca.lt/api/process_webhook_event`.
73+
74+
8. Use Postgresql instead of SQLite
75+
This example uses SQLite as database for its portability and self-contain-ness.
76+
However, ** please do not use SQLite in production ** for its weak support of concurrency.
77+
78+
We recommend using postgres for the persistance. Immutable's sdk provides a postgres persistence for this purpose. You can replace `mintingBackend.mintingPersistencePrismaSqlite` with `mintingBackend.mintingPersistencePg` in the `server.ts` and change prisma schema according to the one provided by our sdk: [Postgres seed.sql](https://github.com/immutable/ts-immutable-sdk/blob/main/packages/minting-backend/sdk/src/minting/persistence/pg/seed.sql).
79+
80+
## Utility
81+
82+
Retry failed mints or mints recorded but does not exist in Immutable Minting API.
83+
84+
```
85+
npm run retrymints
86+
```
87+
88+
update minting status according to status from Immutable Minting API.
89+
90+
```
91+
npm run updatemints
92+
```
93+
94+
## To-Do List
95+
96+
- [ ] Add ERC1155 support once the minting API is ready
97+
- [ ] Add the ability to choose whether you want mintByQuantity or mintByID
98+
- [ ] this sample app will be ported over to use postgres in the future.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "minting-api-backend",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "ts-node-dev --respawn --transpile-only src/server.ts",
9+
"updatemints": "ts-node src/utils/updateMintStatus.ts",
10+
"retrymints": "ts-node src/utils/mintFailsAndMissing.ts"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "ISC",
15+
"dependencies": {
16+
"@fastify/cors": "^9.0.1",
17+
"@imtbl/sdk": "latest",
18+
"@prisma/client": "^5.12.1",
19+
"@types/jsonwebtoken": "^9.0.6",
20+
"aws-sdk": "^2.1603.0",
21+
"ethereum-cryptography": "^2.1.3",
22+
"ethers": "^6.12.1",
23+
"fastify": "^4.26.2",
24+
"jsonwebtoken": "^9.0.2",
25+
"jwk-to-pem": "^2.0.5",
26+
"prisma": "^5.12.1",
27+
"sns-validator": "^0.3.5",
28+
"util": "^0.12.5",
29+
"uuid": "^9.0.1",
30+
"viem": "^2.9.29",
31+
"winston": "^3.13.0",
32+
"winston-daily-rotate-file": "^5.0.0"
33+
},
34+
"devDependencies": {
35+
"@types/node": "^20.12.7",
36+
"@types/pg": "^8.11.6",
37+
"@types/sns-validator": "^0.3.3",
38+
"@types/uuid": "^9.0.8",
39+
"artillery": "^2.0.11",
40+
"ts-node-dev": "^2.0.0",
41+
"typescript": "^5.4.5"
42+
}
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- CreateTable
2+
CREATE TABLE "im_assets" (
3+
"id" TEXT NOT NULL PRIMARY KEY,
4+
"assetId" TEXT NOT NULL,
5+
"ownerAddress" TEXT NOT NULL,
6+
"metadata" TEXT,
7+
"tokenId" TEXT,
8+
"contractAddress" TEXT NOT NULL,
9+
"error" TEXT,
10+
"mintingStatus" TEXT,
11+
"metadataId" TEXT,
12+
"triedCount" INTEGER NOT NULL DEFAULT 0,
13+
"lastImtblZkevmMintRequestUpdatedId" TEXT,
14+
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
15+
"updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
16+
);
17+
18+
-- CreateIndex
19+
CREATE UNIQUE INDEX "im_assets_assetId_contractAddress_key" ON "im_assets"("assetId", "contractAddress");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- CreateTable
2+
CREATE TABLE "Allowlist" (
3+
"address" TEXT NOT NULL PRIMARY KEY,
4+
"phase" INTEGER NOT NULL
5+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "sqlite"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5+
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
6+
7+
generator client {
8+
provider = "prisma-client-js"
9+
}
10+
11+
datasource db {
12+
provider = "sqlite"
13+
url = env("DATABASE_URL")
14+
}
15+
16+
model ImAssets {
17+
id String @id @default(uuid())
18+
assetId String // Previously @db.Uuid in Postgres
19+
ownerAddress String
20+
metadata String? // Previously Json? @db.JsonB in Postgres
21+
tokenId String?
22+
contractAddress String
23+
error String?
24+
mintingStatus String?
25+
metadataId String? // Previously @db.Uuid in Postgres
26+
triedCount Int @default(0)
27+
lastImtblZkevmMintRequestUpdatedId String? // Previously @db.Uuid in Postgres
28+
createdAt DateTime @default(now()) // Stored as TEXT
29+
updatedAt DateTime @default(now()) // Stored as TEXT
30+
31+
@@map("im_assets")
32+
@@unique([assetId, contractAddress], name: "im_assets_uindex")
33+
}
34+
35+
model Allowlist {
36+
address String @id
37+
phase Int
38+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import serverConfig, { environment } from "./config";
2+
import { blockchainData } from "@imtbl/sdk";
3+
4+
export const blockchainDataClient = new blockchainData.BlockchainData({
5+
baseConfig: {
6+
environment: environment,
7+
apiKey: serverConfig[environment].HUB_API_KEY,
8+
rateLimitingKey: serverConfig[environment].RPS_API_KEY,
9+
}
10+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { config } from "@imtbl/sdk";
2+
import { ServerConfig } from "./types";
3+
require("dotenv").config();
4+
5+
//config.Environment.SANDBOX or config.Environment.PRODUCTION
6+
export const environment = config.Environment.SANDBOX;
7+
8+
//Used for verification of the Passport JWTs
9+
export const IMX_JWT_KEY_URL = "https://auth.immutable.com/.well-known/jwks.json?_gl=1*1g7a0qs*_ga*NDg1NTg3MDI3LjE2ODU1OTY1Mzg.*_ga_4JBHZ7F06X*MTY4ODUyNjkyNy4xNC4wLjE2ODg1MjY5MjcuMC4wLjA.*_ga_7XM4Y7T8YC*MTY4ODUyNjkyNy4yNy4wLjE2ODg1MjY5MjcuMC4wLjA.";
10+
11+
const serverConfig: ServerConfig = {
12+
[config.Environment.SANDBOX]: {
13+
API_URL: "https://api.sandbox.immutable.com",
14+
HUB_API_KEY: process.env.SANDBOX_HUB_IMMUTABLE_API_KEY!,
15+
RPS_API_KEY: process.env.SANDBOX_RPS_IMMUTABLE_API_KEY!,
16+
HOST_IP: "localhost",
17+
PORT: 3000,
18+
chainName: "imtbl-zkevm-testnet",
19+
collectionAddress: "",
20+
enableFileLogging: true, //Should logs be output to files or just console?
21+
maxTokenSupplyAcrossAllPhases: 1500,
22+
logLevel: "debug",
23+
eoaMintMessage: "Sign this message to verify your wallet address", //The message an EOA signs to verify their wallet address and mint
24+
mintPhases: [
25+
{
26+
name: "Guaranteed",
27+
startTime: 1715743355,
28+
endTime: 1735743376,
29+
},
30+
{
31+
name: "Waitlist",
32+
startTime: 1714916593,
33+
endTime: 1719292800,
34+
},
35+
],
36+
metadata: {
37+
name: "Your NFT name",
38+
description: "Your NFT description",
39+
image: "https://image-url.png",
40+
animation_url: "https://video.mp4",
41+
attributes: [],
42+
},
43+
},
44+
[config.Environment.PRODUCTION]: {
45+
API_URL: "https://api.immutable.com",
46+
HUB_API_KEY: process.env.MAINNET_HUB_IMMUTABLE_API_KEY!,
47+
RPS_API_KEY: process.env.MAINNET_RPS_IMMUTABLE_API_KEY!,
48+
HOST_IP: "localhost",
49+
PORT: 3000,
50+
chainName: "imtbl-zkevm-mainnet",
51+
collectionAddress: "",
52+
enableFileLogging: true, //Should logs be output to files or just console?
53+
maxTokenSupplyAcrossAllPhases: 1500,
54+
logLevel: "debug",
55+
eoaMintMessage: "Sign this message to verify your wallet address", //The message an EOA signs to verify their wallet address and mint
56+
mintPhases: [
57+
{
58+
name: "Guaranteed",
59+
startTime: 1629913600,
60+
endTime: 1714623711,
61+
},
62+
{
63+
name: "Waitlist",
64+
startTime: 1714623712,
65+
endTime: 1719292800,
66+
},
67+
],
68+
metadata: {
69+
name: "Your NFT name",
70+
description: "Your NFT description",
71+
image: "https://image-url.png",
72+
animation_url: "https://video.mp4",
73+
attributes: [],
74+
},
75+
},
76+
};
77+
78+
export default serverConfig;

0 commit comments

Comments
 (0)