@faremeter/payment-evm 0.14.0 → 0.16.0
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/src/erc20.d.ts +12 -0
- package/dist/src/erc20.d.ts.map +1 -0
- package/dist/src/erc20.js +44 -0
- package/dist/src/exact/facilitator.d.ts +2 -2
- package/dist/src/exact/facilitator.d.ts.map +1 -1
- package/dist/src/exact/facilitator.js +11 -2
- package/dist/src/exact/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type PublicClient } from "viem";
|
|
2
|
+
import { type Address } from "@faremeter/types/evm";
|
|
3
|
+
export interface GetTokenBalanceArgs {
|
|
4
|
+
account: Address;
|
|
5
|
+
asset: Address;
|
|
6
|
+
client: PublicClient;
|
|
7
|
+
}
|
|
8
|
+
export declare function getTokenBalance(args: GetTokenBalanceArgs): Promise<{
|
|
9
|
+
amount: bigint;
|
|
10
|
+
decimals: number;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=erc20.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"erc20.d.ts","sourceRoot":"","sources":["../../src/erc20.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB;;;GA4C9D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {} from "viem";
|
|
2
|
+
import {} from "@faremeter/types/evm";
|
|
3
|
+
export async function getTokenBalance(args) {
|
|
4
|
+
const { account, asset, client } = args;
|
|
5
|
+
const [balance, decimals] = await client.multicall({
|
|
6
|
+
contracts: [
|
|
7
|
+
{
|
|
8
|
+
address: asset,
|
|
9
|
+
abi: [
|
|
10
|
+
{
|
|
11
|
+
name: "balanceOf",
|
|
12
|
+
type: "function",
|
|
13
|
+
stateMutability: "view",
|
|
14
|
+
inputs: [{ type: "address" }],
|
|
15
|
+
outputs: [{ type: "uint256" }],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
functionName: "balanceOf",
|
|
19
|
+
args: [account],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
address: asset,
|
|
23
|
+
abi: [
|
|
24
|
+
{
|
|
25
|
+
name: "decimals",
|
|
26
|
+
type: "function",
|
|
27
|
+
stateMutability: "view",
|
|
28
|
+
inputs: [],
|
|
29
|
+
outputs: [{ type: "uint8" }],
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
functionName: "decimals",
|
|
33
|
+
args: [],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
if (decimals.status !== "success" || balance.status !== "success") {
|
|
38
|
+
throw new Error("failed to query balance");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
amount: balance.result,
|
|
42
|
+
decimals: decimals.result,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ChainInfoWithRPC } from "@faremeter/types/evm";
|
|
2
2
|
import { type FacilitatorHandler } from "@faremeter/types/facilitator";
|
|
3
3
|
import type { Transport } from "viem";
|
|
4
4
|
import { type KnownX402Network, type AssetNameOrContractInfo } from "@faremeter/info/evm";
|
|
@@ -6,6 +6,6 @@ type CreateFacilitatorHandlerOpts = {
|
|
|
6
6
|
network?: KnownX402Network;
|
|
7
7
|
transport?: Transport;
|
|
8
8
|
};
|
|
9
|
-
export declare function createFacilitatorHandler(chain:
|
|
9
|
+
export declare function createFacilitatorHandler(chain: ChainInfoWithRPC, privateKey: string, assetNameOrInfo: AssetNameOrContractInfo, opts?: CreateFacilitatorHandlerOpts): Promise<FacilitatorHandler>;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=facilitator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAQA,OAAO,EAAgB,KAAK,
|
|
1
|
+
{"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/exact/facilitator.ts"],"names":[],"mappings":"AAQA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,MAAM,CAAC;AAapD,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAuB7B,KAAK,4BAA4B,GAAG;IAClC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AACF,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,gBAAgB,EACvB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,uBAAuB,EACxC,IAAI,GAAE,4BAAiC,GACtC,OAAO,CAAC,kBAAkB,CAAC,CAqV7B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPrivateKey } from "@faremeter/types/evm";
|
|
2
2
|
import {} from "@faremeter/types/facilitator";
|
|
3
3
|
import { type } from "arktype";
|
|
4
|
-
import { createPublicClient, createWalletClient, http, verifyTypedData, encodeFunctionData, isAddress, } from "viem";
|
|
4
|
+
import { createPublicClient, createWalletClient, http, verifyTypedData, encodeFunctionData, isAddress, defineChain, } from "viem";
|
|
5
5
|
import { privateKeyToAccount } from "viem/accounts";
|
|
6
6
|
import { lookupX402Network, findAssetInfo, } from "@faremeter/info/evm";
|
|
7
7
|
import { X402_EXACT_SCHEME, TRANSFER_WITH_AUTHORIZATION_ABI, EIP712_TYPES, x402ExactPayload, } from "./constants.js";
|
|
@@ -30,7 +30,17 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
30
30
|
const publicClient = createPublicClient({
|
|
31
31
|
transport,
|
|
32
32
|
});
|
|
33
|
+
// XXX - Temporarily work around typing problems related to trying to have a chain be null.
|
|
34
|
+
const ersatzChain = defineChain({
|
|
35
|
+
...chain,
|
|
36
|
+
nativeCurrency: {
|
|
37
|
+
decimals: 0,
|
|
38
|
+
name: "",
|
|
39
|
+
symbol: "",
|
|
40
|
+
},
|
|
41
|
+
});
|
|
33
42
|
const walletClient = createWalletClient({
|
|
43
|
+
chain: defineChain(ersatzChain),
|
|
34
44
|
account,
|
|
35
45
|
transport,
|
|
36
46
|
});
|
|
@@ -241,7 +251,6 @@ export async function createFacilitatorHandler(chain, privateKey, assetNameOrInf
|
|
|
241
251
|
to: useForwarder ? domain.verifyingContract : asset,
|
|
242
252
|
data,
|
|
243
253
|
account: acct,
|
|
244
|
-
chain: null,
|
|
245
254
|
});
|
|
246
255
|
const serializedTransaction = await walletClient.signTransaction(request);
|
|
247
256
|
const txHash = await publicClient.sendRawTransaction({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exact/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,+BAA+B,EAC/B,YAAY,EACZ,gBAAgB,EAChB,YAAY,GACb,MAAM,aAAa,CAAC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC"}
|
package/dist/src/index.js
CHANGED