@latticexyz/common 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2 → 2.2.18-c2ad22c7feb566e1731ff16e8be291746bdffb3e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.js +1 -39
- package/dist/actions.js.map +1 -1
- package/dist/chains.js +1 -75
- package/dist/chains.js.map +1 -1
- package/dist/chunk-6FIKI2CG.js +2 -0
- package/dist/{chunk-MYWRXQQH.js.map → chunk-6FIKI2CG.js.map} +1 -1
- package/dist/chunk-DPUUE7NM.js +2 -0
- package/dist/{chunk-Z6SVAIZN.js.map → chunk-DPUUE7NM.js.map} +1 -1
- package/dist/chunk-QQCZY3XJ.js +2 -0
- package/dist/{chunk-MF5NFUW7.js.map → chunk-QQCZY3XJ.js.map} +1 -1
- package/dist/chunk-TCWGPC6G.js +2 -0
- package/dist/{chunk-MK6UECU7.js.map → chunk-TCWGPC6G.js.map} +1 -1
- package/dist/chunk-ZIUX7JCQ.js +2 -0
- package/dist/{chunk-D4GDXAMP.js.map → chunk-ZIUX7JCQ.js.map} +1 -1
- package/dist/chunk-ZV2KGJCD.js +2 -0
- package/dist/{chunk-IYZZFDNO.js.map → chunk-ZV2KGJCD.js.map} +1 -1
- package/dist/codegen.js +49 -706
- package/dist/codegen.js.map +1 -1
- package/dist/errors.js +1 -6
- package/dist/foundry.js +2 -71
- package/dist/foundry.js.map +1 -1
- package/dist/index.js +1 -233
- package/dist/index.js.map +1 -1
- package/dist/internal.js +9 -205
- package/dist/internal.js.map +1 -1
- package/dist/kms.js +1 -168
- package/dist/kms.js.map +1 -1
- package/dist/utils.js +1 -122
- package/dist/utils.js.map +1 -1
- package/package.json +16 -104
- package/dist/actions.cjs +0 -334
- package/dist/actions.cjs.map +0 -1
- package/dist/actions.d.cts +0 -27
- package/dist/chains.cjs +0 -106
- package/dist/chains.cjs.map +0 -1
- package/dist/chains.d.cts +0 -968
- package/dist/chunk-D4GDXAMP.js +0 -64
- package/dist/chunk-IYZZFDNO.js +0 -16
- package/dist/chunk-MF5NFUW7.js +0 -12
- package/dist/chunk-MK6UECU7.js +0 -11
- package/dist/chunk-MYWRXQQH.js +0 -208
- package/dist/chunk-Z6SVAIZN.js +0 -70
- package/dist/codegen.cjs +0 -889
- package/dist/codegen.cjs.map +0 -1
- package/dist/codegen.d.cts +0 -228
- package/dist/errors.cjs +0 -38
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -5
- package/dist/foundry.cjs +0 -105
- package/dist/foundry.cjs.map +0 -1
- package/dist/foundry.d.cts +0 -69
- package/dist/getContract-CA0EdVg6.d.cts +0 -20
- package/dist/index.cjs +0 -597
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -160
- package/dist/internal.cjs +0 -459
- package/dist/internal.cjs.map +0 -1
- package/dist/internal.d.cts +0 -36
- package/dist/kms.cjs +0 -204
- package/dist/kms.cjs.map +0 -1
- package/dist/kms.d.cts +0 -18
- package/dist/type-utils.cjs +0 -19
- package/dist/type-utils.cjs.map +0 -1
- package/dist/type-utils.d.cts +0 -19
- package/dist/utils.cjs +0 -174
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -40
package/dist/chunk-D4GDXAMP.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// src/resourceTypes.ts
|
|
2
|
-
var resourceTypes = ["table", "offchainTable", "namespace", "system"];
|
|
3
|
-
|
|
4
|
-
// src/resourceToHex.ts
|
|
5
|
-
import { stringToHex, concatHex } from "viem";
|
|
6
|
-
var resourceTypeIds = {
|
|
7
|
-
// keep these in sync with storeResourceTypes.sol
|
|
8
|
-
table: "tb",
|
|
9
|
-
offchainTable: "ot",
|
|
10
|
-
// keep these in sync with worldResourceTypes.sol
|
|
11
|
-
namespace: "ns",
|
|
12
|
-
system: "sy"
|
|
13
|
-
};
|
|
14
|
-
function resourceToHex(resource) {
|
|
15
|
-
const typeId = resourceTypeIds[resource.type];
|
|
16
|
-
if (resource.namespace.length > 14) {
|
|
17
|
-
throw new Error(`Namespaces must fit into \`bytes14\`, but "${resource.namespace}" is too long.`);
|
|
18
|
-
}
|
|
19
|
-
return concatHex([
|
|
20
|
-
stringToHex(typeId, { size: 2 }),
|
|
21
|
-
stringToHex(resource.namespace, { size: 14 }),
|
|
22
|
-
stringToHex(resource.name.slice(0, 16), { size: 16 })
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// src/resourceToLabel.ts
|
|
27
|
-
var rootNamespace = "";
|
|
28
|
-
function resourceToLabel({
|
|
29
|
-
namespace,
|
|
30
|
-
name
|
|
31
|
-
}) {
|
|
32
|
-
return namespace === rootNamespace ? name : `${namespace}__${name}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/hexToResource.ts
|
|
36
|
-
import { hexToString, sliceHex } from "viem";
|
|
37
|
-
var resourceTypeIdToType = Object.fromEntries(
|
|
38
|
-
Object.entries(resourceTypeIds).map(([key, value]) => [value, key])
|
|
39
|
-
);
|
|
40
|
-
function getResourceType(resourceTypeId) {
|
|
41
|
-
const type = resourceTypeIdToType[resourceTypeId];
|
|
42
|
-
if (resourceTypes.includes(type)) {
|
|
43
|
-
return type;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function hexToResource(hex) {
|
|
47
|
-
const resourceTypeId = hexToString(sliceHex(hex, 0, 2)).replace(/\0+$/, "");
|
|
48
|
-
const type = getResourceType(resourceTypeId);
|
|
49
|
-
const namespace = hexToString(sliceHex(hex, 2, 16)).replace(/\0+$/, "");
|
|
50
|
-
const name = hexToString(sliceHex(hex, 16, 32)).replace(/\0+$/, "");
|
|
51
|
-
if (!type) {
|
|
52
|
-
throw new Error(`Unknown type (${resourceTypeId}) for resource (${resourceToLabel({ namespace, name })})`);
|
|
53
|
-
}
|
|
54
|
-
return { resourceId: hex, type, namespace, name };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export {
|
|
58
|
-
resourceTypes,
|
|
59
|
-
resourceTypeIds,
|
|
60
|
-
resourceToHex,
|
|
61
|
-
resourceToLabel,
|
|
62
|
-
hexToResource
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=chunk-D4GDXAMP.js.map
|
package/dist/chunk-IYZZFDNO.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/utils/uniqueBy.ts
|
|
2
|
-
function uniqueBy(values, getKey) {
|
|
3
|
-
const map = /* @__PURE__ */ new Map();
|
|
4
|
-
for (const value of values) {
|
|
5
|
-
const key = getKey(value);
|
|
6
|
-
if (!map.has(key)) {
|
|
7
|
-
map.set(key, value);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return Array.from(map.values());
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
uniqueBy
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-IYZZFDNO.js.map
|
package/dist/chunk-MF5NFUW7.js
DELETED
package/dist/chunk-MK6UECU7.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/debug.ts
|
|
2
|
-
import createDebug from "debug";
|
|
3
|
-
var debug = createDebug("mud:common");
|
|
4
|
-
var error = createDebug("mud:common");
|
|
5
|
-
debug.log = console.debug.bind(console);
|
|
6
|
-
error.log = console.error.bind(console);
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
debug
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=chunk-MK6UECU7.js.map
|
package/dist/chunk-MYWRXQQH.js
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
debug
|
|
3
|
-
} from "./chunk-MK6UECU7.js";
|
|
4
|
-
|
|
5
|
-
// src/getNonceManagerId.ts
|
|
6
|
-
import { getAddress } from "viem";
|
|
7
|
-
import { getChainId } from "viem/actions";
|
|
8
|
-
import { getAction } from "viem/utils";
|
|
9
|
-
async function getNonceManagerId({
|
|
10
|
-
client,
|
|
11
|
-
address,
|
|
12
|
-
blockTag
|
|
13
|
-
}) {
|
|
14
|
-
const chainId = client.chain?.id ?? await getAction(client, getChainId, "getChainId")({});
|
|
15
|
-
return `mud:createNonceManager:${chainId}:${getAddress(address)}:${blockTag}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/findCause.ts
|
|
19
|
-
function findCause(error, fn) {
|
|
20
|
-
if (fn?.(error)) return error;
|
|
21
|
-
if (error.cause instanceof Error) return findCause(error.cause, fn);
|
|
22
|
-
return fn ? null : error;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/createNonceManager.ts
|
|
26
|
-
import { getTransactionCount } from "viem/actions";
|
|
27
|
-
import PQueue from "p-queue";
|
|
28
|
-
import { getAction as getAction2 } from "viem/utils";
|
|
29
|
-
var debug2 = debug.extend("createNonceManager");
|
|
30
|
-
function createNonceManager({
|
|
31
|
-
client,
|
|
32
|
-
address,
|
|
33
|
-
// TODO: rename to account?
|
|
34
|
-
blockTag = "latest",
|
|
35
|
-
broadcastChannelName,
|
|
36
|
-
queueConcurrency = 1
|
|
37
|
-
}) {
|
|
38
|
-
const ref = { nonce: -1, noncePromise: null };
|
|
39
|
-
let channel = null;
|
|
40
|
-
if (typeof BroadcastChannel !== "undefined") {
|
|
41
|
-
const channelName = broadcastChannelName ? Promise.resolve(broadcastChannelName) : getNonceManagerId({ client, address, blockTag });
|
|
42
|
-
channelName.then((name) => {
|
|
43
|
-
channel = new BroadcastChannel(name);
|
|
44
|
-
channel.addEventListener("message", (event) => {
|
|
45
|
-
const nonce = JSON.parse(event.data);
|
|
46
|
-
debug2("got nonce from broadcast channel", nonce);
|
|
47
|
-
ref.nonce = nonce;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function hasNonce() {
|
|
52
|
-
return ref.nonce >= 0;
|
|
53
|
-
}
|
|
54
|
-
function getNonce() {
|
|
55
|
-
if (!hasNonce()) throw new Error("call resetNonce before using getNonce");
|
|
56
|
-
return ref.nonce;
|
|
57
|
-
}
|
|
58
|
-
function nextNonce() {
|
|
59
|
-
if (!hasNonce()) throw new Error("call resetNonce before using nextNonce");
|
|
60
|
-
const nonce = ref.nonce++;
|
|
61
|
-
channel?.postMessage(JSON.stringify(ref.nonce));
|
|
62
|
-
return nonce;
|
|
63
|
-
}
|
|
64
|
-
async function resetNonce() {
|
|
65
|
-
ref.noncePromise ??= (async () => {
|
|
66
|
-
ref.nonce = await getAction2(client, getTransactionCount, "getTransactionCount")({ address, blockTag });
|
|
67
|
-
ref.noncePromise = null;
|
|
68
|
-
channel?.postMessage(JSON.stringify(ref.nonce));
|
|
69
|
-
debug2("reset nonce to", ref.nonce);
|
|
70
|
-
})();
|
|
71
|
-
await ref.noncePromise;
|
|
72
|
-
}
|
|
73
|
-
function shouldResetNonce(error) {
|
|
74
|
-
const nonceError = findCause(error, ({ name }) => name === "NonceTooLowError" || name === "NonceTooHighError");
|
|
75
|
-
return nonceError != null;
|
|
76
|
-
}
|
|
77
|
-
const mempoolQueue = new PQueue({ concurrency: queueConcurrency });
|
|
78
|
-
return {
|
|
79
|
-
hasNonce,
|
|
80
|
-
getNonce,
|
|
81
|
-
nextNonce,
|
|
82
|
-
resetNonce,
|
|
83
|
-
shouldResetNonce,
|
|
84
|
-
mempoolQueue
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/getNonceManager.ts
|
|
89
|
-
var nonceManagers = /* @__PURE__ */ new Map();
|
|
90
|
-
async function getNonceManager({
|
|
91
|
-
client,
|
|
92
|
-
address,
|
|
93
|
-
// TODO: rename to account?
|
|
94
|
-
blockTag = "latest",
|
|
95
|
-
...opts
|
|
96
|
-
}) {
|
|
97
|
-
const id = await getNonceManagerId({ client, address, blockTag });
|
|
98
|
-
const nonceManager = nonceManagers.get(id) ?? createNonceManager({ client, address, blockTag, ...opts });
|
|
99
|
-
if (!nonceManagers.has(id)) {
|
|
100
|
-
nonceManagers.set(id, nonceManager);
|
|
101
|
-
}
|
|
102
|
-
if (!nonceManager.hasNonce()) {
|
|
103
|
-
await nonceManager.resetNonce();
|
|
104
|
-
}
|
|
105
|
-
return nonceManager;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/sendTransaction.ts
|
|
109
|
-
import { sendTransaction as viem_sendTransaction } from "viem/actions";
|
|
110
|
-
import pRetry from "p-retry";
|
|
111
|
-
import { parseAccount } from "viem/accounts";
|
|
112
|
-
|
|
113
|
-
// src/getFeeRef.ts
|
|
114
|
-
import { getChainId as getChainId2 } from "viem/actions";
|
|
115
|
-
|
|
116
|
-
// src/createFeeRef.ts
|
|
117
|
-
import { estimateFeesPerGas } from "viem/actions";
|
|
118
|
-
import { getAction as getAction3 } from "viem/utils";
|
|
119
|
-
async function createFeeRef({ client, args, refreshInterval }) {
|
|
120
|
-
const feeRef = { fees: {}, lastUpdatedTimestamp: 0 };
|
|
121
|
-
async function updateFees() {
|
|
122
|
-
const fees = await getAction3(client, estimateFeesPerGas, "estimateFeesPerGas")(args);
|
|
123
|
-
feeRef.fees = fees;
|
|
124
|
-
feeRef.lastUpdatedTimestamp = Date.now();
|
|
125
|
-
}
|
|
126
|
-
setInterval(updateFees, refreshInterval);
|
|
127
|
-
await updateFees();
|
|
128
|
-
return feeRef;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// src/getFeeRef.ts
|
|
132
|
-
import { getAction as getAction4 } from "viem/utils";
|
|
133
|
-
var feeRefs = /* @__PURE__ */ new Map();
|
|
134
|
-
async function getFeeRef(opts) {
|
|
135
|
-
const chainId = opts.args?.chain?.id ?? opts.client.chain?.id ?? await getAction4(opts.client, getChainId2, "getChainId")({});
|
|
136
|
-
const existingFeeRef = feeRefs.get(chainId);
|
|
137
|
-
if (existingFeeRef) {
|
|
138
|
-
return existingFeeRef;
|
|
139
|
-
}
|
|
140
|
-
const feeRef = await createFeeRef(opts);
|
|
141
|
-
feeRefs.set(chainId, feeRef);
|
|
142
|
-
return feeRef;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// src/sendTransaction.ts
|
|
146
|
-
import { getAction as getAction5 } from "viem/utils";
|
|
147
|
-
var debug3 = debug.extend("sendTransaction");
|
|
148
|
-
async function sendTransaction(client, request, opts = {}) {
|
|
149
|
-
const rawAccount = request.account ?? client.account;
|
|
150
|
-
if (!rawAccount) {
|
|
151
|
-
throw new Error("No account provided");
|
|
152
|
-
}
|
|
153
|
-
const account = parseAccount(rawAccount);
|
|
154
|
-
const chain = client.chain;
|
|
155
|
-
const nonceManager = await getNonceManager({
|
|
156
|
-
client: opts.publicClient ?? client,
|
|
157
|
-
address: account.address,
|
|
158
|
-
queueConcurrency: opts.queueConcurrency
|
|
159
|
-
});
|
|
160
|
-
const feeRef = await getFeeRef({
|
|
161
|
-
client: opts.publicClient ?? client,
|
|
162
|
-
refreshInterval: 1e4,
|
|
163
|
-
args: { chain }
|
|
164
|
-
});
|
|
165
|
-
return await nonceManager.mempoolQueue.add(
|
|
166
|
-
() => pRetry(
|
|
167
|
-
async () => {
|
|
168
|
-
const nonce = nonceManager.nextNonce();
|
|
169
|
-
const params = {
|
|
170
|
-
// viem_sendTransaction internally estimates gas, which we want to happen on the pending block
|
|
171
|
-
blockTag: "pending",
|
|
172
|
-
...feeRef.fees,
|
|
173
|
-
...request,
|
|
174
|
-
nonce
|
|
175
|
-
};
|
|
176
|
-
debug3("sending tx to", request.to, "with nonce", nonce);
|
|
177
|
-
return await getAction5(client, viem_sendTransaction, "sendTransaction")(params);
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
retries: 3,
|
|
181
|
-
onFailedAttempt: async (error) => {
|
|
182
|
-
debug3("failed, resetting nonce");
|
|
183
|
-
await nonceManager.resetNonce();
|
|
184
|
-
if (nonceManager.shouldResetNonce(error)) {
|
|
185
|
-
debug3("got nonce error, retrying", error.message);
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (String(error).includes("transaction underpriced")) {
|
|
189
|
-
debug3("got transaction underpriced error, retrying", error.message);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
throw error;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
),
|
|
196
|
-
{ throwOnTimeout: true }
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export {
|
|
201
|
-
getNonceManagerId,
|
|
202
|
-
findCause,
|
|
203
|
-
createNonceManager,
|
|
204
|
-
getNonceManager,
|
|
205
|
-
getFeeRef,
|
|
206
|
-
sendTransaction
|
|
207
|
-
};
|
|
208
|
-
//# sourceMappingURL=chunk-MYWRXQQH.js.map
|
package/dist/chunk-Z6SVAIZN.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getFeeRef,
|
|
3
|
-
getNonceManager
|
|
4
|
-
} from "./chunk-MYWRXQQH.js";
|
|
5
|
-
import {
|
|
6
|
-
debug
|
|
7
|
-
} from "./chunk-MK6UECU7.js";
|
|
8
|
-
|
|
9
|
-
// src/writeContract.ts
|
|
10
|
-
import { writeContract as viem_writeContract } from "viem/actions";
|
|
11
|
-
import pRetry from "p-retry";
|
|
12
|
-
import { parseAccount } from "viem/accounts";
|
|
13
|
-
import { getAction } from "viem/utils";
|
|
14
|
-
var debug2 = debug.extend("writeContract");
|
|
15
|
-
async function writeContract(client, request, opts = {}) {
|
|
16
|
-
const rawAccount = request.account ?? client.account;
|
|
17
|
-
if (!rawAccount) {
|
|
18
|
-
throw new Error("No account provided");
|
|
19
|
-
}
|
|
20
|
-
const account = parseAccount(rawAccount);
|
|
21
|
-
const chain = client.chain;
|
|
22
|
-
const nonceManager = await getNonceManager({
|
|
23
|
-
client: opts.publicClient ?? client,
|
|
24
|
-
address: account.address,
|
|
25
|
-
queueConcurrency: opts.queueConcurrency
|
|
26
|
-
});
|
|
27
|
-
const feeRef = await getFeeRef({
|
|
28
|
-
client: opts.publicClient ?? client,
|
|
29
|
-
refreshInterval: 1e4,
|
|
30
|
-
args: { chain }
|
|
31
|
-
});
|
|
32
|
-
return nonceManager.mempoolQueue.add(
|
|
33
|
-
() => pRetry(
|
|
34
|
-
async () => {
|
|
35
|
-
const nonce = nonceManager.nextNonce();
|
|
36
|
-
const params = {
|
|
37
|
-
// viem_writeContract internally estimates gas, which we want to happen on the pending block
|
|
38
|
-
blockTag: "pending",
|
|
39
|
-
...feeRef.fees,
|
|
40
|
-
...request,
|
|
41
|
-
nonce
|
|
42
|
-
};
|
|
43
|
-
debug2("calling", params.functionName, "at", params.address, "with nonce", nonce);
|
|
44
|
-
return await getAction(client, viem_writeContract, "writeContract")(params);
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
retries: 3,
|
|
48
|
-
onFailedAttempt: async (error) => {
|
|
49
|
-
debug2("failed, resetting nonce");
|
|
50
|
-
await nonceManager.resetNonce();
|
|
51
|
-
if (nonceManager.shouldResetNonce(error)) {
|
|
52
|
-
debug2("got nonce error, retrying", error.message);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (String(error).includes("transaction underpriced")) {
|
|
56
|
-
debug2("got transaction underpriced error, retrying", error.message);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
),
|
|
63
|
-
{ throwOnTimeout: true }
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
writeContract
|
|
69
|
-
};
|
|
70
|
-
//# sourceMappingURL=chunk-Z6SVAIZN.js.map
|