@faremeter/payment-solana 0.14.0 → 0.15.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/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/src/splToken.d.ts +14 -0
- package/dist/src/splToken.d.ts.map +1 -0
- package/dist/src/splToken.js +42 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -3
|
@@ -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"}
|
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,QAAQ,MAAM,YAAY,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rpc } from "@solana/rpc";
|
|
2
|
+
import type { GetTokenAccountBalanceApi } from "@solana/rpc-api";
|
|
3
|
+
import { Base58Address } from "@faremeter/types/solana";
|
|
4
|
+
export interface GetTokenBalanceArgs {
|
|
5
|
+
asset: Base58Address;
|
|
6
|
+
account: Base58Address;
|
|
7
|
+
rpcClient: Rpc<GetTokenAccountBalanceApi>;
|
|
8
|
+
}
|
|
9
|
+
export declare function isAccountNotFoundError(e: unknown): boolean;
|
|
10
|
+
export declare function getTokenBalance(args: GetTokenBalanceArgs): Promise<{
|
|
11
|
+
amount: bigint;
|
|
12
|
+
decimals: number;
|
|
13
|
+
} | null>;
|
|
14
|
+
//# sourceMappingURL=splToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"splToken.d.ts","sourceRoot":"","sources":["../../src/splToken.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,GAAG,CAAC,yBAAyB,CAAC,CAAC;CAC3C;AAGD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,WAkBhD;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,mBAAmB;;;UA4B9D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { address } from "@solana/addresses";
|
|
2
|
+
import { Base58Address } from "@faremeter/types/solana";
|
|
3
|
+
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS, } from "@solana-program/token";
|
|
4
|
+
// XXX - There has got to be a better way to do this.
|
|
5
|
+
export function isAccountNotFoundError(e) {
|
|
6
|
+
if (!e || !(e instanceof Error)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if ("name" in e &&
|
|
10
|
+
(e.name === "TokenAccountNotFoundError" ||
|
|
11
|
+
e.name === "AccountNotFoundError")) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if ("message" in e && e.message.includes("could not find account")) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
export async function getTokenBalance(args) {
|
|
20
|
+
const { asset, account, rpcClient } = args;
|
|
21
|
+
const owner = address(account);
|
|
22
|
+
const mint = address(asset);
|
|
23
|
+
const [ata] = await findAssociatedTokenPda({
|
|
24
|
+
mint,
|
|
25
|
+
owner,
|
|
26
|
+
tokenProgram: TOKEN_PROGRAM_ADDRESS,
|
|
27
|
+
});
|
|
28
|
+
let balanceInfo;
|
|
29
|
+
try {
|
|
30
|
+
balanceInfo = await rpcClient.getTokenAccountBalance(ata).send();
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
if (isAccountNotFoundError(e)) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
amount: BigInt(balanceInfo.value.amount),
|
|
40
|
+
decimals: balanceInfo.value.decimals,
|
|
41
|
+
};
|
|
42
|
+
}
|