Skip to content

Commit 108024c

Browse files
Switch wallet configuration to x-wallet-address (#126)
* Replace all server dbOperations with prisma * Update all knex to prisma * Fix sql * getAll now returns all wallets, write uses x-wallet-address header * Fix trigger * checking out the different headers for write operations * file storage * force lowercase local wallet storage * updating write functions with header value * more write calls switching to txOverride * fix some key names and add new writes * way more writes * more general improvements * Fix nonce management * Add import by private key, remove breaking tests * Fix dbOperations * Resolve merge conflicts * Disable e2e testing temporarily * Remove wallet type bug * Update to run prisma commands on deploy --------- Co-authored-by: furqanrydhan <furqan.rydhan@gmail.com>
1 parent d3344e9 commit 108024c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+483
-452
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ Dockerfile
55
.env
66
yarn-error.log
77
.husky
8-
scripts
98
docker-compose*.yml
109
Dockerfile
1110
.DS_Store
1211
swagger.yml
13-
e2e
12+
test

.env.benchmark.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212

1313
THIRDWEB_API_SECRET_KEY = ""
1414

15-
# At minimum, you need to configure a chain
15+
# At minimum, you need to configure a chain and a wallet address
1616
# ============================================================================= #
1717
BENCHMARK_CHAIN = "mumbai"
18+
BENCHMARK_WALLET_ADDRESS = ""
1819

1920
# Then you can configure the contract address and function to call
2021
# NOTE: If you don't configure a contract address and function call, an ERC20

.github/workflows/e2eTest.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ export POSTGRES_PASSWORD=postgres
1010
export POSTGRES_PORT=5432
1111
export POSTGRES_USE_SSL=false
1212
export WALLET_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
13-
export THIRDWEB_API_SECRET_KEY=klRsqmatrdlEpik_pHKgYy_q2YzGe3bTewO1VC26eY_H184Kc7xOVqKVj0mHwOOW2AOx2N-a3GqLCQ7Z9s9-sw
13+
# export THIRDWEB_API_SECRET_KEY=klRsqmatrdlEpik_pHKgYy_q2YzGe3bTewO1VC26eY_H184Kc7xOVqKVj0mHwOOW2AOx2N-a3GqLCQ7Z9s9-sw
1414

1515
test-evm: FORCE
1616
docker compose -f docker-compose-test.yml up -d
1717
./test/e2e/hardhat/waitForHardhatNode.sh
18+
yarn prisma:migrate
1819
yarn test:all
1920
docker compose -f docker-compose-test.yml down
2021

core/helpers/index.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,3 @@ export const isValidHttpUrl = (urlString: string): boolean => {
1717

1818
return url.protocol === "http:" || url.protocol === "https:";
1919
};
20-
21-
export const getWalletType = (): string => {
22-
if (WALLET_PRIVATE_KEY) {
23-
return "ppk";
24-
}
25-
26-
if (AWS_ACCESS_KEY_ID && AWS_SECRET_ACCESS_KEY && AWS_REGION) {
27-
return "aws_kms";
28-
}
29-
30-
if (
31-
env.GOOGLE_APPLICATION_CREDENTIAL_EMAIL &&
32-
env.GOOGLE_APPLICATION_CREDENTIAL_PRIVATE_KEY &&
33-
env.GOOGLE_APPLICATION_PROJECT_ID &&
34-
env.GOOGLE_KMS_KEY_RING_ID &&
35-
env.GOOGLE_KMS_KEY_VERSION_ID &&
36-
env.GOOGLE_KMS_LOCATION_ID
37-
) {
38-
return "aws_kms";
39-
}
40-
41-
// ToDo GCP KMS
42-
return "local";
43-
};

core/schema/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ export const networkResponseSchema = Type.Object({
3636
description: "Chain slug",
3737
}),
3838
});
39+
40+
export const walletAuthSchema = Type.Object({
41+
"x-wallet-address": Type.String({
42+
description: "Wallet address",
43+
}),
44+
});

core/sdk/sdk.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class LocalFileStorage implements AsyncStorage {
2424

2525
getKey(): string {
2626
if (this.walletAddress) {
27-
return `localWallet-${this.walletAddress}`;
27+
return `localWallet-${this.walletAddress.toLowerCase()}`;
2828
}
2929
throw new Error("Wallet Address not set");
3030
}
@@ -246,11 +246,14 @@ export const getSDK = async (
246246
//TODO get private key from encrypted file
247247
wallet = new LocalWallet({
248248
chain,
249-
storage: new LocalFileStorage(walletAddress),
250249
});
250+
console.log(
251+
`Loading local wallet for address ${walletAddress} with key ${THIRDWEB_API_SECRET_KEY}`,
252+
);
251253
await wallet.load({
252254
strategy: "encryptedJson",
253255
password: THIRDWEB_API_SECRET_KEY,
256+
storage: new LocalFileStorage(walletAddress),
254257
});
255258
sdk = await ThirdwebSDK.fromWallet(wallet, chain, {
256259
secretKey: THIRDWEB_API_SECRET_KEY,

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"scripts": {
1010
"docker": "docker compose --env-file ./.env up --remove-orphans",
1111
"docker:build": "docker compose build --no-cache",
12-
"dev": "yarn dev:infra && yarn dev:server & sleep 10 && yarn dev:worker",
13-
"dev:server": "nodemon --watch 'server/**/*.ts' --watch 'core/**/*.ts' --exec 'npx tsx ./server/index.ts' --files server/index.ts",
14-
"dev:worker": "nodemon --watch 'worker/**/*.ts' --watch 'core/**/*.ts' --exec 'npx tsx ./worker/index.ts' --files worker/index.ts",
12+
"dev": "yarn dev:infra && yarn prisma:init && yarn dev:server & sleep 10 && yarn dev:worker",
13+
"dev:server": "yarn prisma:init && nodemon --watch 'server/**/*.ts' --watch 'core/**/*.ts' --exec 'npx tsx ./server/index.ts' --files server/index.ts",
14+
"dev:worker": "yarn prisma:init && nodemon --watch 'worker/**/*.ts' --watch 'core/**/*.ts' --exec 'npx tsx ./worker/index.ts' --files worker/index.ts",
1515
"dev:infra": "docker compose -f ./docker-compose-infra.yml up -d",
1616
"build": "yarn && rm -rf dist && tsc -p ./tsconfig.json --outDir dist",
17-
"start": "yarn start:server & sleep 20 && yarn start:worker",
17+
"prisma:reset": "prisma migrate reset --force && prisma generate",
18+
"prisma:init": "prisma migrate deploy && prisma generate",
19+
"start": "yarn prisma:init && yarn start:server & sleep 20 && yarn start:worker",
1820
"start:server": "node --experimental-specifier-resolution=node ./dist/server/index.js",
1921
"start:worker": "node --experimental-specifier-resolution=node ./dist/worker/index.js",
2022
"start:docker": "docker compose build && docker compose --env-file ./.env up --remove-orphans",

server/api/contract/extensions/erc1155/write/airdrop.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getContractInstance } from "../../../../../../core";
5+
import { walletAuthSchema } from "../../../../../../core/schema";
56
import { queueTx } from "../../../../../../src/db/transactions/queueTx";
67
import {
78
erc1155ContractParamSchema,
89
standardResponseSchema,
910
transactionWritesResponseSchema,
1011
} from "../../../../../helpers/sharedApiSchemas";
11-
import { web3APIOverridesForWriteRequest } from "../../../../../schemas/web3api-overrides";
12+
import { txOverridesForWriteRequest } from "../../../../../schemas/web3api-overrides";
1213
import { getChainIdFromChain } from "../../../../../utilities/chain";
1314

1415
// INPUTS
@@ -28,7 +29,7 @@ const requestBodySchema = Type.Object({
2829
description: "Addresses and quantities to airdrop to",
2930
},
3031
),
31-
...web3APIOverridesForWriteRequest.properties,
32+
...txOverridesForWriteRequest.properties,
3233
});
3334

3435
requestBodySchema.examples = [
@@ -44,9 +45,6 @@ requestBodySchema.examples = [
4445
quantity: "1",
4546
},
4647
],
47-
web3api_overrides: {
48-
from: "0x...",
49-
},
5048
},
5149
];
5250

@@ -64,20 +62,22 @@ export async function erc1155airdrop(fastify: FastifyInstance) {
6462
operationId: "erc1155_airdrop",
6563
params: requestSchema,
6664
body: requestBodySchema,
65+
headers: walletAuthSchema,
6766
response: {
6867
...standardResponseSchema,
6968
[StatusCodes.OK]: transactionWritesResponseSchema,
7069
},
7170
},
7271
handler: async (request, reply) => {
7372
const { network, contract_address } = request.params;
74-
const { token_id, addresses, web3api_overrides } = request.body;
73+
const { token_id, addresses, tx_overrides } = request.body;
74+
const walletAddress = request.headers["x-wallet-address"] as string;
7575
const chainId = getChainIdFromChain(network);
7676

7777
const contract = await getContractInstance(
7878
network,
7979
contract_address,
80-
web3api_overrides?.from,
80+
walletAddress,
8181
);
8282
const tx = await contract.erc1155.airdrop.prepare(token_id, addresses);
8383
const queuedId = await queueTx({ tx, chainId, extension: "erc1155" });

server/api/contract/extensions/erc1155/write/burn.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getContractInstance } from "../../../../../../core";
5+
import { walletAuthSchema } from "../../../../../../core/schema";
56
import { queueTx } from "../../../../../../src/db/transactions/queueTx";
67
import {
78
erc1155ContractParamSchema,
89
standardResponseSchema,
910
transactionWritesResponseSchema,
1011
} from "../../../../../helpers/sharedApiSchemas";
11-
import { web3APIOverridesForWriteRequest } from "../../../../../schemas/web3api-overrides";
12+
import { txOverridesForWriteRequest } from "../../../../../schemas/web3api-overrides";
1213
import { getChainIdFromChain } from "../../../../../utilities/chain";
1314

1415
// INPUTS
@@ -20,16 +21,13 @@ const requestBodySchema = Type.Object({
2021
amount: Type.String({
2122
description: "The amount of tokens to burn",
2223
}),
23-
...web3APIOverridesForWriteRequest.properties,
24+
...txOverridesForWriteRequest.properties,
2425
});
2526

2627
requestBodySchema.examples = [
2728
{
2829
token_id: "0",
2930
amount: "1",
30-
web3api_overrides: {
31-
from: "0x...",
32-
},
3331
},
3432
];
3533

@@ -47,20 +45,22 @@ export async function erc1155burn(fastify: FastifyInstance) {
4745
operationId: "erc1155_burn",
4846
params: requestSchema,
4947
body: requestBodySchema,
48+
headers: walletAuthSchema,
5049
response: {
5150
...standardResponseSchema,
5251
[StatusCodes.OK]: transactionWritesResponseSchema,
5352
},
5453
},
5554
handler: async (request, reply) => {
5655
const { network, contract_address } = request.params;
57-
const { token_id, amount, web3api_overrides } = request.body;
56+
const { token_id, amount, tx_overrides } = request.body;
57+
const walletAddress = request.headers["x-wallet-address"] as string;
5858
const chainId = getChainIdFromChain(network);
5959

6060
const contract = await getContractInstance(
6161
network,
6262
contract_address,
63-
web3api_overrides?.from,
63+
walletAddress,
6464
);
6565
const tx = await contract.erc1155.burn.prepare(token_id, amount);
6666
const queuedId = await queueTx({ tx, chainId, extension: "erc1155" });

0 commit comments

Comments
 (0)