Skip to content

Commit 9f2b383

Browse files
authored
Merge pull request #99 from tablelandnetwork/dtb/fix-polygon
fix: mumbai failing to due gas limit issues
2 parents 81d927c + 08b7aa2 commit 9f2b383

10 files changed

Lines changed: 106 additions & 27 deletions

File tree

package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cli/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "@tableland/cli",
3-
"version": "5.4.0",
3+
"version": "5.4.1",
44
"description": "Tableland command line tools",
5-
"repository": "https://github.com/tablelandnetwork/tableland-js",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/tablelandnetwork/tableland-js.git",
8+
"directory": "packages/cli"
9+
},
610
"publishConfig": {
711
"access": "public"
812
},
@@ -46,7 +50,7 @@
4650
"dependencies": {
4751
"@ensdomains/ensjs": "3.0.0-alpha.64",
4852
"@tableland/node-helpers": "^0.0.2",
49-
"@tableland/sdk": "^5.1.0",
53+
"@tableland/sdk": "^5.1.1",
5054
"@tableland/sqlparser": "^1.3.0",
5155
"cli-select-2": "^2.0.0",
5256
"cosmiconfig": "^8.0.0",

packages/local/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "@tableland/local",
33
"version": "2.3.0",
44
"description": "Tooling to start a sandboxed Tableland network.",
5-
"repository": "https://github.com/tablelandnetwork/tableland-js",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/tablelandnetwork/tableland-js.git",
8+
"directory": "packages/local"
9+
},
610
"license": "MIT AND Apache-2.0",
711
"publishConfig": {
812
"access": "public"

packages/node-helpers/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "@tableland/node-helpers",
33
"version": "0.0.2",
44
"description": "Helpers for the @tableland/sdk in a Node.js environment",
5-
"repository": "https://github.com/tablelandnetwork/tableland-js",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/tablelandnetwork/tableland-js.git",
8+
"directory": "packages/node-helpers"
9+
},
610
"license": "MIT AND Apache-2.0",
711
"publishConfig": {
812
"access": "public"

packages/sdk/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "@tableland/sdk",
3-
"version": "5.1.0",
3+
"version": "5.1.1",
44
"description": "A database client and helpers for the Tableland network",
5-
"repository": "https://github.com/tablelandnetwork/tableland-js",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/tablelandnetwork/tableland-js.git",
8+
"directory": "packages/sdk"
9+
},
610
"publishConfig": {
711
"access": "public"
812
},

packages/sdk/src/helpers/ethers.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function getOverrides({
2929
const opts: Overrides = {};
3030
const network = await signer.provider?.getNetwork();
3131
/* c8 ignore next 7 */
32-
if (network?.chainId === 137) {
32+
if (network && isPolygon(network.chainId)) {
3333
const feeData = await signer.getFeeData();
3434
if (feeData.gasPrice != null) {
3535
opts.gasPrice =
@@ -39,6 +39,15 @@ export async function getOverrides({
3939
return opts;
4040
}
4141

42+
/**
43+
* Check if a chain is Polygon.
44+
* @param chainId The chainId of the network.
45+
* @returns A boolean that indicates if the chain is a mainnet/testnet Polygon.
46+
*/
47+
export function isPolygon(chainId: number): boolean {
48+
return chainId === 137 || chainId === 80001;
49+
}
50+
4251
/**
4352
* RegistryReceipt is based on the TransactionReceipt type which defined by the API spec.
4453
* The API v1 has a known problem where it only returns the first tableId from a transaction.

packages/sdk/src/registry/controller.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type SignerConfig } from "../helpers/config.js";
2-
import { type ContractTransaction } from "../helpers/ethers.js";
2+
import { type ContractTransaction, isPolygon } from "../helpers/ethers.js";
33
import { type TableIdentifier, getContractSetup } from "./contract.js";
44

55
export interface SetParams {
@@ -23,6 +23,16 @@ export async function setController(
2323
);
2424
const caller = await signer.getAddress();
2525
const controller = params.controller;
26+
const chainId = await signer.getChainId();
27+
if (isPolygon(chainId)) {
28+
const gasLimit = await contract.estimateGas.setController(
29+
caller,
30+
tableId,
31+
controller,
32+
overrides
33+
);
34+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
35+
}
2636
return await contract.setController(caller, tableId, controller, overrides);
2737
}
2838

@@ -35,6 +45,15 @@ export async function lockController(
3545
tableName
3646
);
3747
const caller = await signer.getAddress();
48+
const chainId = await signer.getChainId();
49+
if (isPolygon(chainId)) {
50+
const gasLimit = await contract.estimateGas.lockController(
51+
caller,
52+
tableId,
53+
overrides
54+
);
55+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
56+
}
3857
return await contract.lockController(caller, tableId, overrides);
3958
}
4059

packages/sdk/src/registry/create.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { normalize } from "../helpers/index.js";
22
import { type SignerConfig } from "../helpers/config.js";
3-
import { type ContractTransaction } from "../helpers/ethers.js";
3+
import { type ContractTransaction, isPolygon } from "../helpers/ethers.js";
44
import { validateTableName } from "../helpers/parser.js";
55
import { getContractAndOverrides } from "./contract.js";
66

@@ -96,6 +96,14 @@ async function _createOne(
9696
signer,
9797
chainId
9898
);
99+
if (isPolygon(chainId)) {
100+
const gasLimit = await contract.estimateGas["create(address,string)"](
101+
owner,
102+
statement,
103+
overrides
104+
);
105+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
106+
}
99107
return await contract["create(address,string)"](owner, statement, overrides);
100108
}
101109

@@ -108,6 +116,14 @@ async function _createMany(
108116
signer,
109117
chainId
110118
);
119+
if (isPolygon(chainId)) {
120+
const gasLimit = await contract.estimateGas["create(address,string[])"](
121+
owner,
122+
statements,
123+
overrides
124+
);
125+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
126+
}
111127
return await contract["create(address,string[])"](
112128
owner,
113129
statements,

packages/sdk/src/registry/run.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type SignerConfig } from "../helpers/config.js";
2-
import { type ContractTransaction } from "../helpers/ethers.js";
2+
import { type ContractTransaction, isPolygon } from "../helpers/ethers.js";
33
import { validateTableName } from "../helpers/parser.js";
44
import {
55
getContractAndOverrides,
@@ -84,6 +84,12 @@ async function _mutateOne(
8484
signer,
8585
chainId
8686
);
87+
if (isPolygon(chainId)) {
88+
const gasLimit = await contract.estimateGas[
89+
"mutate(address,uint256,string)"
90+
](caller, tableId, statement, overrides);
91+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
92+
}
8793
return await contract["mutate(address,uint256,string)"](
8894
caller,
8995
tableId,
@@ -101,6 +107,12 @@ async function _mutateMany(
101107
signer,
102108
chainId
103109
);
110+
if (isPolygon(chainId)) {
111+
const gasLimit = await contract.estimateGas[
112+
"mutate(address,(uint256,string)[])"
113+
](caller, runnables, overrides);
114+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
115+
}
104116
return await contract["mutate(address,(uint256,string)[])"](
105117
caller,
106118
runnables,

packages/sdk/src/registry/transfer.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type SignerConfig } from "../helpers/config.js";
2-
import { type ContractTransaction } from "../helpers/ethers.js";
2+
import { type ContractTransaction, isPolygon } from "../helpers/ethers.js";
33
import { type TableIdentifier, getContractSetup } from "./contract.js";
44

55
export interface TransferParams {
@@ -22,6 +22,13 @@ export async function safeTransferFrom(
2222
params.tableName
2323
);
2424
const caller = await signer.getAddress();
25+
const chainId = await signer.getChainId();
26+
if (isPolygon(chainId)) {
27+
const gasLimit = await contract.estimateGas[
28+
"safeTransferFrom(address,address,uint256)"
29+
](caller, params.to, tableId, overrides);
30+
overrides.gasLimit = Math.floor(gasLimit.toNumber() * 1.2);
31+
}
2532
return await contract["safeTransferFrom(address,address,uint256)"](
2633
caller,
2734
params.to,

0 commit comments

Comments
 (0)