@talismn/balances 0.0.0-pr2091-20250727112628 → 0.0.0-pr2091-20250728060035

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.
@@ -15,8 +15,9 @@ type EthTransferCallData = {
15
15
  data: `0x${string}`;
16
16
  value?: string;
17
17
  };
18
+ type SolTransferCallData = TransactionInstruction[];
18
19
  export type BalanceTransferType = "keep-alive" | "all" | "allow-death";
19
- type CallDataOf<P extends TokenPlatform<TokenType>> = P extends "ethereum" ? EthTransferCallData : P extends "polkadot" ? DotTransferCallData : P extends "solana" ? TransactionInstruction : never;
20
+ type CallDataOf<P extends TokenPlatform<TokenType>> = P extends "ethereum" ? EthTransferCallData : P extends "polkadot" ? DotTransferCallData : P extends "solana" ? SolTransferCallData : never;
20
21
  export type TokensWithAddresses = Array<[Token, Address[]]>;
21
22
  export type FetchBalanceErrors = Array<{
22
23
  tokenId: TokenId;
@@ -87,6 +88,7 @@ export interface IBalanceModule<Type extends TokenType, TokenConfig = unknown, M
87
88
  to: string;
88
89
  value: string;
89
90
  token: Token;
91
+ connector: PlatformConnector<TokenPlatform<Type>>;
90
92
  } : never) => CallDataOf<TokenPlatform<Type>> | Promise<CallDataOf<TokenPlatform<Type>>>;
91
93
  }
92
94
  export {};
@@ -1572,7 +1572,7 @@ const getTransferCallData$7 = ({
1572
1572
  toPubkey: new web3_js.PublicKey(to),
1573
1573
  lamports: Number(value)
1574
1574
  });
1575
- return transferIx;
1575
+ return [transferIx];
1576
1576
  };
1577
1577
 
1578
1578
  const SUBSCRIPTION_INTERVAL$3 = 6_000;
@@ -1945,27 +1945,44 @@ const getMiniMetadata$6 = () => {
1945
1945
  throw new Error("MiniMetadata is not supported for solana tokens");
1946
1946
  };
1947
1947
 
1948
- const getTransferCallData$6 = () =>
1949
- // {
1950
- // from,
1951
- // to,
1952
- // value,
1953
- // token,
1954
- // }
1955
- {
1956
- throw new Error("Not implemented");
1957
- // if (!isTokenOfType(token, MODULE_TYPE))
1958
- // throw new Error(`Token type ${token.type} is not ${MODULE_TYPE}.`)
1959
- // if (!isEthereumAddress(from)) throw new Error("Invalid from address")
1960
- // if (!isEthereumAddress(to)) throw new Error("Invalid to address")
1961
-
1962
- // const data = encodeFunctionData({
1963
- // abi: erc20Abi,
1964
- // functionName: "transfer",
1965
- // args: [to, BigInt(value)],
1966
- // })
1967
-
1968
- // return { from, to: token.contractAddress, data }
1948
+ const getTransferCallData$6 = async ({
1949
+ from,
1950
+ to,
1951
+ value,
1952
+ token,
1953
+ connector
1954
+ }) => {
1955
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
1956
+ const connection = await connector.getConnection(token.networkId);
1957
+
1958
+ // we use legacy type transaction to ensure Ledger compatibility
1959
+ const instructions = [];
1960
+ const mint = new web3_js.PublicKey(token.mintAddress);
1961
+ const fromWallet = new web3_js.PublicKey(from);
1962
+ const toWallet = new web3_js.PublicKey(to);
1963
+
1964
+ // Get associated token accounts
1965
+ const fromTokenAccount = await splToken.getAssociatedTokenAddress(mint, fromWallet);
1966
+ const toTokenAccount = await splToken.getAssociatedTokenAddress(mint, toWallet);
1967
+
1968
+ // Create the target token account if it doesn't exist
1969
+ if (!(await getAccountExists(connection, toWallet))) {
1970
+ instructions.push(splToken.createAssociatedTokenAccountInstruction(fromWallet,
1971
+ // funder
1972
+ toTokenAccount, toWallet, mint));
1973
+ }
1974
+
1975
+ // Transfer the tokens
1976
+ instructions.push(splToken.createTransferInstruction(fromTokenAccount, toTokenAccount, fromWallet, BigInt(value), [], splToken.TOKEN_PROGRAM_ID));
1977
+ return instructions;
1978
+ };
1979
+ const getAccountExists = async (connection, address) => {
1980
+ try {
1981
+ await splToken.getAccount(connection, address);
1982
+ return true;
1983
+ } catch {
1984
+ return false;
1985
+ }
1969
1986
  };
1970
1987
 
1971
1988
  const SUBSCRIPTION_INTERVAL$2 = 6_000;
@@ -1572,7 +1572,7 @@ const getTransferCallData$7 = ({
1572
1572
  toPubkey: new web3_js.PublicKey(to),
1573
1573
  lamports: Number(value)
1574
1574
  });
1575
- return transferIx;
1575
+ return [transferIx];
1576
1576
  };
1577
1577
 
1578
1578
  const SUBSCRIPTION_INTERVAL$3 = 6_000;
@@ -1945,27 +1945,44 @@ const getMiniMetadata$6 = () => {
1945
1945
  throw new Error("MiniMetadata is not supported for solana tokens");
1946
1946
  };
1947
1947
 
1948
- const getTransferCallData$6 = () =>
1949
- // {
1950
- // from,
1951
- // to,
1952
- // value,
1953
- // token,
1954
- // }
1955
- {
1956
- throw new Error("Not implemented");
1957
- // if (!isTokenOfType(token, MODULE_TYPE))
1958
- // throw new Error(`Token type ${token.type} is not ${MODULE_TYPE}.`)
1959
- // if (!isEthereumAddress(from)) throw new Error("Invalid from address")
1960
- // if (!isEthereumAddress(to)) throw new Error("Invalid to address")
1961
-
1962
- // const data = encodeFunctionData({
1963
- // abi: erc20Abi,
1964
- // functionName: "transfer",
1965
- // args: [to, BigInt(value)],
1966
- // })
1967
-
1968
- // return { from, to: token.contractAddress, data }
1948
+ const getTransferCallData$6 = async ({
1949
+ from,
1950
+ to,
1951
+ value,
1952
+ token,
1953
+ connector
1954
+ }) => {
1955
+ if (!chaindataProvider.isTokenOfType(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
1956
+ const connection = await connector.getConnection(token.networkId);
1957
+
1958
+ // we use legacy type transaction to ensure Ledger compatibility
1959
+ const instructions = [];
1960
+ const mint = new web3_js.PublicKey(token.mintAddress);
1961
+ const fromWallet = new web3_js.PublicKey(from);
1962
+ const toWallet = new web3_js.PublicKey(to);
1963
+
1964
+ // Get associated token accounts
1965
+ const fromTokenAccount = await splToken.getAssociatedTokenAddress(mint, fromWallet);
1966
+ const toTokenAccount = await splToken.getAssociatedTokenAddress(mint, toWallet);
1967
+
1968
+ // Create the target token account if it doesn't exist
1969
+ if (!(await getAccountExists(connection, toWallet))) {
1970
+ instructions.push(splToken.createAssociatedTokenAccountInstruction(fromWallet,
1971
+ // funder
1972
+ toTokenAccount, toWallet, mint));
1973
+ }
1974
+
1975
+ // Transfer the tokens
1976
+ instructions.push(splToken.createTransferInstruction(fromTokenAccount, toTokenAccount, fromWallet, BigInt(value), [], splToken.TOKEN_PROGRAM_ID));
1977
+ return instructions;
1978
+ };
1979
+ const getAccountExists = async (connection, address) => {
1980
+ try {
1981
+ await splToken.getAccount(connection, address);
1982
+ return true;
1983
+ } catch {
1984
+ return false;
1985
+ }
1969
1986
  };
1970
1987
 
1971
1988
  const SUBSCRIPTION_INTERVAL$2 = 6_000;
@@ -12,7 +12,7 @@ import { isNotNil, BigMath, isArrayOf, isBigInt, planckToTokens, isAbortError, g
12
12
  import { parseMetadataRpc, toHex, unifyMetadata, decAnyMetadata, getDynamicBuilder, getLookupFn, decodeScale, getStorageKeyPrefix, Twox128, compactMetadata, encodeMetadata, papiParse, papiStringify } from '@talismn/scale';
13
13
  import { deserializeMetadata } from '@metaplex-foundation/mpl-token-metadata';
14
14
  import { sol, publicKey } from '@metaplex-foundation/umi';
15
- import { MintLayout } from '@solana/spl-token';
15
+ import { MintLayout, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction, createTransferInstruction, TOKEN_PROGRAM_ID, getAccount } from '@solana/spl-token';
16
16
  import { newTokenRates } from '@talismn/token-rates';
17
17
  import { mergeUint8 } from '@polkadot-api/utils';
18
18
  import { Binary, Enum, AccountId } from 'polkadot-api';
@@ -1563,7 +1563,7 @@ const getTransferCallData$7 = ({
1563
1563
  toPubkey: new PublicKey(to),
1564
1564
  lamports: Number(value)
1565
1565
  });
1566
- return transferIx;
1566
+ return [transferIx];
1567
1567
  };
1568
1568
 
1569
1569
  const SUBSCRIPTION_INTERVAL$3 = 6_000;
@@ -1936,27 +1936,44 @@ const getMiniMetadata$6 = () => {
1936
1936
  throw new Error("MiniMetadata is not supported for solana tokens");
1937
1937
  };
1938
1938
 
1939
- const getTransferCallData$6 = () =>
1940
- // {
1941
- // from,
1942
- // to,
1943
- // value,
1944
- // token,
1945
- // }
1946
- {
1947
- throw new Error("Not implemented");
1948
- // if (!isTokenOfType(token, MODULE_TYPE))
1949
- // throw new Error(`Token type ${token.type} is not ${MODULE_TYPE}.`)
1950
- // if (!isEthereumAddress(from)) throw new Error("Invalid from address")
1951
- // if (!isEthereumAddress(to)) throw new Error("Invalid to address")
1952
-
1953
- // const data = encodeFunctionData({
1954
- // abi: erc20Abi,
1955
- // functionName: "transfer",
1956
- // args: [to, BigInt(value)],
1957
- // })
1958
-
1959
- // return { from, to: token.contractAddress, data }
1939
+ const getTransferCallData$6 = async ({
1940
+ from,
1941
+ to,
1942
+ value,
1943
+ token,
1944
+ connector
1945
+ }) => {
1946
+ if (!isTokenOfType(token, MODULE_TYPE$6)) throw new Error(`Token type ${token.type} is not ${MODULE_TYPE$6}.`);
1947
+ const connection = await connector.getConnection(token.networkId);
1948
+
1949
+ // we use legacy type transaction to ensure Ledger compatibility
1950
+ const instructions = [];
1951
+ const mint = new PublicKey(token.mintAddress);
1952
+ const fromWallet = new PublicKey(from);
1953
+ const toWallet = new PublicKey(to);
1954
+
1955
+ // Get associated token accounts
1956
+ const fromTokenAccount = await getAssociatedTokenAddress(mint, fromWallet);
1957
+ const toTokenAccount = await getAssociatedTokenAddress(mint, toWallet);
1958
+
1959
+ // Create the target token account if it doesn't exist
1960
+ if (!(await getAccountExists(connection, toWallet))) {
1961
+ instructions.push(createAssociatedTokenAccountInstruction(fromWallet,
1962
+ // funder
1963
+ toTokenAccount, toWallet, mint));
1964
+ }
1965
+
1966
+ // Transfer the tokens
1967
+ instructions.push(createTransferInstruction(fromTokenAccount, toTokenAccount, fromWallet, BigInt(value), [], TOKEN_PROGRAM_ID));
1968
+ return instructions;
1969
+ };
1970
+ const getAccountExists = async (connection, address) => {
1971
+ try {
1972
+ await getAccount(connection, address);
1973
+ return true;
1974
+ } catch {
1975
+ return false;
1976
+ }
1960
1977
  };
1961
1978
 
1962
1979
  const SUBSCRIPTION_INTERVAL$2 = 6_000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talismn/balances",
3
- "version": "0.0.0-pr2091-20250727112628",
3
+ "version": "0.0.0-pr2091-20250728060035",
4
4
  "author": "Talisman",
5
5
  "homepage": "https://talisman.xyz",
6
6
  "license": "GPL-3.0-or-later",
@@ -38,14 +38,14 @@
38
38
  "scale-ts": "^1.6.1",
39
39
  "viem": "^2.27.3",
40
40
  "zod": "^3.25.62",
41
- "@talismn/chain-connectors": "0.0.0-pr2091-20250727112628",
42
- "@talismn/chaindata-provider": "0.0.0-pr2091-20250727112628",
43
- "@talismn/crypto": "0.0.0-pr2091-20250727112628",
44
- "@talismn/sapi": "0.0.0-pr2091-20250727112628",
41
+ "@talismn/chaindata-provider": "0.0.0-pr2091-20250728060035",
42
+ "@talismn/chain-connectors": "0.0.0-pr2091-20250728060035",
43
+ "@talismn/crypto": "0.0.0-pr2091-20250728060035",
44
+ "@talismn/sapi": "0.0.0-pr2091-20250728060035",
45
45
  "@talismn/scale": "0.2.0",
46
- "@talismn/solana": "0.0.0-pr2091-20250727112628",
47
- "@talismn/token-rates": "0.0.0-pr2091-20250727112628",
48
- "@talismn/util": "0.0.0-pr2091-20250727112628"
46
+ "@talismn/solana": "0.0.0-pr2091-20250728060035",
47
+ "@talismn/token-rates": "0.0.0-pr2091-20250728060035",
48
+ "@talismn/util": "0.0.0-pr2091-20250728060035"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@polkadot/api-contract": "16.1.2",