Skip to content

Commit 468dea0

Browse files
authored
Revert "chore: port /contract/write to V5 (#661)" (#670)
This reverts commit 044f922.
1 parent be15b7e commit 468dea0

File tree

10 files changed

+224
-353
lines changed

10 files changed

+224
-353
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"prisma": "^5.14.0",
7070
"prom-client": "^15.1.3",
7171
"superjson": "^2.2.1",
72-
"thirdweb": "^5.56.0",
72+
"thirdweb": "^5.45.1",
7373
"uuid": "^9.0.1",
7474
"winston": "^3.14.1",
7575
"zod": "^3.23.8"

src/server/routes/contract/extensions/erc1155/write/claimTo.ts

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { Address } from "thirdweb";
4+
import { Address, Hex, encode } from "thirdweb";
55
import { claimTo } from "thirdweb/extensions/erc1155";
66
import { getContractV5 } from "../../../../../../utils/cache/getContractv5";
7-
import { queueTransaction } from "../../../../../../utils/transaction/queueTransation";
7+
import { maybeBigInt } from "../../../../../../utils/primitiveTypes";
8+
import { insertTransaction } from "../../../../../../utils/transaction/insertTransaction";
9+
import { createCustomError } from "../../../../../middleware/error";
810
import {
911
erc1155ContractParamSchema,
1012
requestQuerystringSchema,
1113
standardResponseSchema,
1214
transactionWritesResponseSchema,
1315
} from "../../../../../schemas/sharedApiSchemas";
1416
import { txOverridesWithValueSchema } from "../../../../../schemas/txOverrides";
15-
import {
16-
maybeAddress,
17-
requiredAddress,
18-
walletWithAAHeaderSchema,
19-
} from "../../../../../schemas/wallet";
17+
import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
2018
import { getChainIdFromChain } from "../../../../../utils/chain";
2119

2220
// INPUTS
@@ -73,11 +71,10 @@ export async function erc1155claimTo(fastify: FastifyInstance) {
7371
"x-backend-wallet-address": fromAddress,
7472
"x-account-address": accountAddress,
7573
"x-idempotency-key": idempotencyKey,
76-
"x-account-factory-address": accountFactoryAddress,
7774
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7875

7976
const chainId = await getChainIdFromChain(chain);
80-
const contract = getContractV5({
77+
const contract = await getContractV5({
8178
chainId,
8279
contractAddress,
8380
});
@@ -90,19 +87,47 @@ export async function erc1155claimTo(fastify: FastifyInstance) {
9087
tokenId: BigInt(tokenId),
9188
});
9289

93-
const queueId = await queueTransaction({
94-
transaction,
95-
fromAddress: requiredAddress(fromAddress, "x-backend-wallet-address"),
96-
toAddress: maybeAddress(contractAddress, "to"),
97-
accountAddress: maybeAddress(accountAddress, "x-account-address"),
98-
accountFactoryAddress: maybeAddress(
99-
accountFactoryAddress,
100-
"x-account-factory-address",
101-
),
102-
txOverrides,
103-
idempotencyKey,
104-
shouldSimulate: simulateTx,
105-
});
90+
let data: Hex;
91+
try {
92+
data = await encode(transaction);
93+
} catch (e) {
94+
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
95+
}
96+
97+
let queueId: string;
98+
const insertedTransaction = {
99+
chainId,
100+
from: fromAddress as Address,
101+
to: contractAddress as Address | undefined,
102+
data,
103+
value: maybeBigInt(txOverrides?.value),
104+
gas: maybeBigInt(txOverrides?.gas),
105+
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
106+
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
107+
};
108+
109+
if (accountAddress) {
110+
queueId = await insertTransaction({
111+
insertedTransaction: {
112+
...insertedTransaction,
113+
isUserOp: true,
114+
accountAddress: accountAddress as Address,
115+
signerAddress: fromAddress as Address,
116+
target: contractAddress as Address | undefined,
117+
},
118+
shouldSimulate: simulateTx,
119+
idempotencyKey,
120+
});
121+
} else {
122+
queueId = await insertTransaction({
123+
insertedTransaction: {
124+
...insertedTransaction,
125+
isUserOp: false,
126+
},
127+
shouldSimulate: simulateTx,
128+
idempotencyKey,
129+
});
130+
}
106131

107132
reply.status(StatusCodes.OK).send({
108133
result: {

src/server/routes/contract/extensions/erc20/write/claimTo.ts

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { Address } from "thirdweb";
4+
import { Address, Hex, encode } from "thirdweb";
55
import { claimTo } from "thirdweb/extensions/erc20";
66
import { getContractV5 } from "../../../../../../utils/cache/getContractv5";
7-
import { queueTransaction } from "../../../../../../utils/transaction/queueTransation";
7+
import { maybeBigInt } from "../../../../../../utils/primitiveTypes";
8+
import { insertTransaction } from "../../../../../../utils/transaction/insertTransaction";
9+
import { createCustomError } from "../../../../../middleware/error";
810
import {
911
erc20ContractParamSchema,
1012
requestQuerystringSchema,
1113
standardResponseSchema,
1214
transactionWritesResponseSchema,
1315
} from "../../../../../schemas/sharedApiSchemas";
1416
import { txOverridesWithValueSchema } from "../../../../../schemas/txOverrides";
15-
import {
16-
maybeAddress,
17-
requiredAddress,
18-
walletWithAAHeaderSchema,
19-
} from "../../../../../schemas/wallet";
17+
import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
2018
import { getChainIdFromChain } from "../../../../../utils/chain";
2119

2220
// INPUTS
@@ -70,11 +68,10 @@ export async function erc20claimTo(fastify: FastifyInstance) {
7068
"x-backend-wallet-address": fromAddress,
7169
"x-account-address": accountAddress,
7270
"x-idempotency-key": idempotencyKey,
73-
"x-account-factory-address": accountFactoryAddress,
7471
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7572

7673
const chainId = await getChainIdFromChain(chain);
77-
const contract = getContractV5({
74+
const contract = await getContractV5({
7875
chainId,
7976
contractAddress,
8077
});
@@ -85,19 +82,47 @@ export async function erc20claimTo(fastify: FastifyInstance) {
8582
quantity: amount,
8683
});
8784

88-
const queueId = await queueTransaction({
89-
transaction,
90-
fromAddress: requiredAddress(fromAddress, "x-backend-wallet-address"),
91-
toAddress: maybeAddress(contractAddress, "to"),
92-
accountAddress: maybeAddress(accountAddress, "x-account-address"),
93-
accountFactoryAddress: maybeAddress(
94-
accountFactoryAddress,
95-
"x-account-factory-address",
96-
),
97-
txOverrides,
98-
idempotencyKey,
99-
shouldSimulate: simulateTx,
100-
});
85+
let data: Hex;
86+
try {
87+
data = await encode(transaction);
88+
} catch (e) {
89+
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
90+
}
91+
92+
let queueId: string;
93+
const insertedTransaction = {
94+
chainId,
95+
from: fromAddress as Address,
96+
to: contractAddress as Address | undefined,
97+
data,
98+
value: maybeBigInt(txOverrides?.value),
99+
gas: maybeBigInt(txOverrides?.gas),
100+
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
101+
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
102+
};
103+
104+
if (accountAddress) {
105+
queueId = await insertTransaction({
106+
insertedTransaction: {
107+
...insertedTransaction,
108+
isUserOp: true,
109+
accountAddress: accountAddress as Address,
110+
signerAddress: fromAddress as Address,
111+
target: contractAddress as Address | undefined,
112+
},
113+
shouldSimulate: simulateTx,
114+
idempotencyKey,
115+
});
116+
} else {
117+
queueId = await insertTransaction({
118+
insertedTransaction: {
119+
...insertedTransaction,
120+
isUserOp: false,
121+
},
122+
shouldSimulate: simulateTx,
123+
idempotencyKey,
124+
});
125+
}
101126

102127
reply.status(StatusCodes.OK).send({
103128
result: {

src/server/routes/contract/extensions/erc721/write/claimTo.ts

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { Address } from "thirdweb";
4+
import { Address, Hex, encode } from "thirdweb";
55
import { claimTo } from "thirdweb/extensions/erc721";
66
import { getContractV5 } from "../../../../../../utils/cache/getContractv5";
7-
import { queueTransaction } from "../../../../../../utils/transaction/queueTransation";
7+
import { maybeBigInt } from "../../../../../../utils/primitiveTypes";
8+
import { insertTransaction } from "../../../../../../utils/transaction/insertTransaction";
9+
import { createCustomError } from "../../../../../middleware/error";
810
import {
911
contractParamSchema,
1012
requestQuerystringSchema,
1113
standardResponseSchema,
1214
transactionWritesResponseSchema,
1315
} from "../../../../../schemas/sharedApiSchemas";
1416
import { txOverridesWithValueSchema } from "../../../../../schemas/txOverrides";
15-
import {
16-
maybeAddress,
17-
requiredAddress,
18-
walletWithAAHeaderSchema,
19-
} from "../../../../../schemas/wallet";
17+
import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
2018
import { getChainIdFromChain } from "../../../../../utils/chain";
2119

2220
// INPUTS
@@ -69,11 +67,10 @@ export async function erc721claimTo(fastify: FastifyInstance) {
6967
"x-backend-wallet-address": fromAddress,
7068
"x-account-address": accountAddress,
7169
"x-idempotency-key": idempotencyKey,
72-
"x-account-factory-address": accountFactoryAddress,
7370
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7471

7572
const chainId = await getChainIdFromChain(chain);
76-
const contract = getContractV5({
73+
const contract = await getContractV5({
7774
chainId,
7875
contractAddress,
7976
});
@@ -84,19 +81,47 @@ export async function erc721claimTo(fastify: FastifyInstance) {
8481
quantity: BigInt(quantity),
8582
});
8683

87-
const queueId = await queueTransaction({
88-
transaction,
89-
fromAddress: requiredAddress(fromAddress, "x-backend-wallet-address"),
90-
toAddress: maybeAddress(contractAddress, "to"),
91-
accountAddress: maybeAddress(accountAddress, "x-account-address"),
92-
accountFactoryAddress: maybeAddress(
93-
accountFactoryAddress,
94-
"x-account-factory-address",
95-
),
96-
txOverrides,
97-
idempotencyKey,
98-
shouldSimulate: simulateTx,
99-
});
84+
let data: Hex;
85+
try {
86+
data = await encode(transaction);
87+
} catch (e) {
88+
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
89+
}
90+
91+
let queueId: string;
92+
const insertedTransaction = {
93+
chainId,
94+
from: fromAddress as Address,
95+
to: contractAddress as Address | undefined,
96+
data,
97+
value: maybeBigInt(txOverrides?.value),
98+
gas: maybeBigInt(txOverrides?.gas),
99+
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
100+
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
101+
};
102+
103+
if (accountAddress) {
104+
queueId = await insertTransaction({
105+
insertedTransaction: {
106+
...insertedTransaction,
107+
isUserOp: true,
108+
accountAddress: accountAddress as Address,
109+
signerAddress: fromAddress as Address,
110+
target: contractAddress as Address | undefined,
111+
},
112+
shouldSimulate: simulateTx,
113+
idempotencyKey,
114+
});
115+
} else {
116+
queueId = await insertTransaction({
117+
insertedTransaction: {
118+
...insertedTransaction,
119+
isUserOp: false,
120+
},
121+
shouldSimulate: simulateTx,
122+
idempotencyKey,
123+
});
124+
}
100125

101126
reply.status(StatusCodes.OK).send({
102127
result: {

src/server/routes/contract/write/write.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
4-
import { prepareContractCall, resolveMethod } from "thirdweb";
5-
import { getContractV5 } from "../../../../utils/cache/getContractv5";
6-
import { maybeBigInt } from "../../../../utils/primitiveTypes";
7-
import { queueTransaction } from "../../../../utils/transaction/queueTransation";
4+
import { queueTx } from "../../../../db/transactions/queueTx";
5+
import { getContract } from "../../../../utils/cache/getContract";
86
import { abiSchema } from "../../../schemas/contract";
97
import {
108
contractParamSchema,
@@ -15,7 +13,6 @@ import {
1513
import { txOverridesWithValueSchema } from "../../../schemas/txOverrides";
1614
import {
1715
maybeAddress,
18-
requiredAddress,
1916
walletWithAAHeaderSchema,
2017
} from "../../../schemas/wallet";
2118
import { getChainIdFromChain } from "../../../utils/chain";
@@ -69,46 +66,39 @@ export async function writeToContract(fastify: FastifyInstance) {
6966
const { simulateTx } = request.query;
7067
const { functionName, args, txOverrides, abi } = request.body;
7168
const {
72-
"x-backend-wallet-address": fromAddress,
69+
"x-backend-wallet-address": walletAddress,
7370
"x-account-address": accountAddress,
7471
"x-idempotency-key": idempotencyKey,
7572
"x-account-factory-address": accountFactoryAddress,
7673
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7774

7875
const chainId = await getChainIdFromChain(chain);
79-
const contract = getContractV5({
76+
const contract = await getContract({
8077
chainId,
8178
contractAddress,
79+
walletAddress,
80+
accountAddress,
8281
abi,
8382
});
8483

85-
// 3 possible ways to get function from abi:
86-
// 1. functionName passed as solidity signature
87-
// 2. functionName passed as function name + passed in ABI
88-
// 3. functionName passed as function name + inferred ABI (fetched at encode time)
89-
// this is all handled inside the `resolveMethod` function
90-
const transaction = prepareContractCall({
91-
contract,
92-
method: resolveMethod(functionName),
93-
params: args,
94-
gas: maybeBigInt(txOverrides?.gas),
95-
value: maybeBigInt(txOverrides?.value),
96-
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
97-
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
84+
const tx = contract.prepare(functionName, args, {
85+
value: txOverrides?.value,
86+
gasLimit: txOverrides?.gas,
87+
maxFeePerGas: txOverrides?.maxFeePerGas,
88+
maxPriorityFeePerGas: txOverrides?.maxPriorityFeePerGas,
9889
});
9990

100-
const queueId = await queueTransaction({
101-
transaction,
102-
fromAddress: requiredAddress(fromAddress, "x-backend-wallet-address"),
103-
toAddress: maybeAddress(contractAddress, "to"),
104-
accountAddress: maybeAddress(accountAddress, "x-account-address"),
91+
const queueId = await queueTx({
92+
tx,
93+
chainId,
94+
simulateTx,
95+
extension: "none",
96+
idempotencyKey,
97+
txOverrides,
10598
accountFactoryAddress: maybeAddress(
10699
accountFactoryAddress,
107100
"x-account-factory-address",
108101
),
109-
txOverrides,
110-
idempotencyKey,
111-
shouldSimulate: simulateTx,
112102
});
113103

114104
reply.status(StatusCodes.OK).send({

0 commit comments

Comments
 (0)