@debridge-finance/solana-utils 2.3.0 → 3.0.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.
@@ -0,0 +1,114 @@
1
+ /// <reference types="node" />
2
+ import { AccountInfo, Connection, PublicKey, Transaction, TransactionInstruction } from "@solana/web3.js";
3
+ import BN from "bn.js";
4
+ import { Buffer } from "buffer";
5
+ import { SolanaPubkey } from "./interfaces";
6
+ type AmountType = string | number | BN | number[];
7
+ declare enum AccountState {
8
+ Uninitialized = 0,
9
+ Initialized = 1,
10
+ Frozen = 2
11
+ }
12
+ type RawAccount = {
13
+ mint: PublicKey;
14
+ owner: PublicKey;
15
+ amount: bigint;
16
+ delegateOption: 1 | 0;
17
+ delegate: PublicKey;
18
+ state: AccountState;
19
+ isNativeOption: 1 | 0;
20
+ isNative: bigint;
21
+ delegatedAmount: bigint;
22
+ closeAuthorityOption: 1 | 0;
23
+ closeAuthority: PublicKey;
24
+ };
25
+ export declare enum AccountType {
26
+ System = 0,
27
+ Token = 1,
28
+ CorrectATA = 2,
29
+ Unknown = 3,
30
+ NotExists = 4
31
+ }
32
+ export interface WalletInfo {
33
+ /** Address of the account */
34
+ address: PublicKey;
35
+ /** Mint associated with the account */
36
+ mint: PublicKey;
37
+ /** Owner of the account */
38
+ owner: PublicKey;
39
+ /** Number of tokens the account holds */
40
+ amount: BN;
41
+ decimals: number;
42
+ /** True if the account is initialized */
43
+ isInitialized: boolean;
44
+ /** True if the account is a native token account */
45
+ isNative: boolean;
46
+ }
47
+ /**
48
+ * Builds instruction for creation of associated wallet for specified token
49
+ * @param tokenMint mint account of SPL-token
50
+ * @param associatedAccount associated account address
51
+ * @param owner owner of the associated account
52
+ * @param payer who pays for account creation
53
+ */
54
+ export declare function createAssociatedWalletInstruction(tokenMint: SolanaPubkey, associatedAccount: PublicKey, owner: SolanaPubkey, payer: SolanaPubkey, associatedTokenProramId?: PublicKey): TransactionInstruction;
55
+ export declare function parseSplAccount(data: Buffer): RawAccount | null;
56
+ export declare function isWalletCorrectATA(walletAddress: SolanaPubkey, data: Buffer): boolean;
57
+ /**
58
+ * Requests account from blockchain and returns result with account type
59
+ * @param account address of account
60
+ * @returns account info and account type
61
+ */
62
+ export declare function getAccountWithType(connection: Connection, account: SolanaPubkey): Promise<[AccountInfo<Buffer> | null, AccountType]>;
63
+ /**
64
+ * Returns balance of specified wallet in native tokens
65
+ * @param wallet wallet to inspect
66
+ */
67
+ export declare function getNativeWalletBalance(connection: Connection, wallet: SolanaPubkey): Promise<BN>;
68
+ /**
69
+ * Returns balance of associated wallet in SPL-tokens
70
+ * @param originalWallet native tokens wallet address
71
+ * @param tokenMint mint of SPL-Token
72
+ */
73
+ export declare function getAssocSPLWalletBalance(connection: Connection, originalWallet: SolanaPubkey, tokenMint: SolanaPubkey): Promise<BN>;
74
+ /**
75
+ * Returns balance of specified wallet in SPL-tokens
76
+ * @param wallet spl-tokens wallet address
77
+ */
78
+ export declare function getSPLWalletBalance(connection: Connection, wallet: SolanaPubkey): Promise<BN>;
79
+ /**
80
+ * Gets list of user's SPL-token accounts
81
+ * @param owner owner of the SPL wallets
82
+ * @returns list of accounts with amount on them
83
+ */
84
+ export declare function getAllTokenAccountsWithBalances(connection: Connection, owner: SolanaPubkey): Promise<WalletInfo[]>;
85
+ /**
86
+ * Gets list of user's tokenMint token accounts
87
+ * @param tokenMint
88
+ * @param owner owner of the wallets
89
+ * @returns list of accounts with amount on them
90
+ */
91
+ export declare function getTokenAccountsWithBalance(connection: Connection, tokenMint: SolanaPubkey, owner: SolanaPubkey): Promise<WalletInfo[]>;
92
+ /**
93
+ * Builds transaction to transfer&wrap native sol from src wallet to dst wallet
94
+ * @param amount number of lamports to transfer and wrap
95
+ * @param transferFrom source native account
96
+ * @param transferTo destination wallet
97
+ * @returns transaction to transfer&wrap sol
98
+ */
99
+ export declare function buildReplenishWsolBalanceTransaction(amount: AmountType, transferFrom: SolanaPubkey, transferTo: SolanaPubkey): Transaction;
100
+ /**
101
+ * Builds transaction that wraps specified amount of lamports into spl, if account is missing will create it
102
+ * @param amount lamports to wrap, ATA will contain exact amount of lamports
103
+ * @param owner owner of created wallet
104
+ */
105
+ export declare function updateWsolBalance(connection: Connection, amount: AmountType, owner: SolanaPubkey): Promise<Transaction | null>;
106
+ /**
107
+ * Checks existance of associated wallet for specified token
108
+ * @param mintAccount mint account of SPL-token
109
+ * @param originalWallet account of solana wallet
110
+ * @returns true if account exists
111
+ */
112
+ export declare function checkIfAssociatedWalletExists(connection: Connection, mintAccount: PublicKey, originalWallet: PublicKey): Promise<boolean>;
113
+ export {};
114
+ //# sourceMappingURL=spl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spl.d.ts","sourceRoot":"","sources":["../../src/spl.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAiB,WAAW,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAGzH,OAAO,EAAE,MAAM,OAAO,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC;AAElD,aAAK,YAAY;IAChB,aAAa,IAAI;IACjB,WAAW,IAAI;IACf,MAAM,IAAI;CACV;AAED,KAAK,UAAU,GAAG;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC;IACtB,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,cAAc,EAAE,CAAC,GAAG,CAAC,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,oBAAoB,EAAE,CAA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AOzI;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,EAAE,CAAC,CAKnG;AAED;;;;GAIG;AACH,wBAAsB,+BAA+B,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAsCxH;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAChD,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,YAAY,EACvB,KAAK,EAAE,YAAY,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CAsCvB;AAED;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,eAkB5H;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CA4BpI;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,cAAc,EAAE,SAAS,oBAK5H"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@debridge-finance/solana-utils",
3
3
  "description": "Common utils package to power communication with Solana contracts at deBridge",
4
- "version": "2.3.0",
4
+ "version": "3.0.0",
5
5
  "author": "deBridge",
6
6
  "license": "GPL-3.0-only",
7
7
  "homepage": "https://debridge.finance",
@@ -32,6 +32,7 @@
32
32
  "scripts": {
33
33
  "test:crypto": "mocha -r ts-node/register -b -t 200000 ./tests/crypto.test.ts",
34
34
  "test:accounts": "mocha -r ts-node/register -b -t 200000 ./tests/accounts.test.ts",
35
+ "test:spl": "mocha -r ts-node/register -b -t 200000 ./tests/spl.test.ts",
35
36
  "lint:fix": "prettier src/** tests/** -w",
36
37
  "lint": "prettier src/** tests/** --check",
37
38
  "build:esm": "tsc -p tsconfig.esm.json",
@@ -40,7 +41,9 @@
40
41
  "build": "rimraf dist && npm run build:esm && npm run build:node && npm run build:browser"
41
42
  },
42
43
  "dependencies": {
43
- "@solana/web3.js": "1.73.0",
44
+ "@solana/web3.js": "1.73.2",
45
+ "@solana/buffer-layout": "4.0.0",
46
+ "@solana/buffer-layout-utils": "0.2.0",
44
47
  "bn.js": "5.2.1",
45
48
  "buffer": "6.0.3",
46
49
  "ethers": "5.7.1"