@lombard.finance/sdk 2.2.1 → 2.4.1

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.
Files changed (52) hide show
  1. package/README.md +38 -37
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +3017 -728
  5. package/dist/index.js.map +1 -1
  6. package/package.json +6 -6
  7. package/src/common/const.ts +0 -4
  8. package/src/common/types/internalTypes.ts +2 -2
  9. package/src/common/types/types.ts +20 -15
  10. package/src/common/utils/convertSatoshi.ts +11 -7
  11. package/src/index.ts +2 -0
  12. package/src/sdk/apiConfig.ts +9 -5
  13. package/src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +1 -1
  14. package/src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.ts +3 -3
  15. package/src/sdk/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +3 -5
  16. package/src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts +137 -75
  17. package/src/sdk/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +54 -0
  18. package/src/sdk/getDepositsByAddress/getDepositsByAddress.stories.tsx +1 -1
  19. package/src/sdk/getDepositsByAddress/getDepositsByAddress.ts +5 -4
  20. package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +3 -3
  21. package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +1 -1
  22. package/src/sdk/getPointsByAddress/getPointsByAddress.stories.tsx +49 -0
  23. package/src/sdk/getPointsByAddress/getPointsByAddress.ts +163 -0
  24. package/src/sdk/getPointsByAddress/index.ts +6 -0
  25. package/src/sdk/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +49 -0
  26. package/src/sdk/getUnstakesByAddress/getUnstakesByAddress.ts +133 -0
  27. package/src/sdk/getUnstakesByAddress/index.ts +1 -0
  28. package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +1 -1
  29. package/src/sdk/index.ts +3 -1
  30. package/src/sdk/internalTypes.ts +3 -0
  31. package/src/sdk/setReferral/setReferral.ts +6 -5
  32. package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +1 -1
  33. package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +1 -1
  34. package/src/sdk/utils/getChainIdByName.ts +12 -6
  35. package/src/sdk/utils/getChainNameById.ts +25 -15
  36. package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +1 -1
  37. package/src/web3Sdk/approveLBTC/approveLBTC.ts +1 -1
  38. package/src/web3Sdk/basculeAddressConfig.ts +7 -8
  39. package/src/web3Sdk/claimLBTC/claimLBTC.stories.tsx +1 -1
  40. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +5 -2
  41. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +1 -2
  42. package/src/web3Sdk/lbtcAddressConfig.ts +6 -8
  43. package/src/web3Sdk/signLbtcDestionationAddr/index.ts +1 -1
  44. package/src/web3Sdk/signLbtcDestionationAddr/{signLbtcDestionationAddr.ts → signLbtcDestinationAddr.ts} +4 -4
  45. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +3 -3
  46. package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +1 -1
  47. package/src/web3Sdk/signStakeAndBake/utils.ts +4 -2
  48. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +1 -1
  49. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +2 -2
  50. package/src/web3Sdk/utils/chainIdToEnv.ts +4 -3
  51. package/src/web3Sdk/utils/getLbtcTokenContract.ts +5 -2
  52. package/src/btcSdk/utils/getOutputScript.ts +0 -67
@@ -1,8 +1,6 @@
1
- import {
2
- defaultEnv,
3
- ZERO_ADDRESS as PLACEHOLDER_ADDRESS,
4
- } from '../common/const';
5
- import { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';
1
+ import { ZERO_ADDRESS as PLACEHOLDER_ADDRESS } from '../common/const';
2
+ import { OChainId, TChainId } from '../common/types/types';
3
+ import { Env, defaultEnv } from '@lombard.finance/sdk-common';
6
4
 
7
5
  type LbtcTokenConfig = Record<TChainId, string>;
8
6
 
@@ -79,11 +77,11 @@ const prodConfig: LbtcTokenConfig = {
79
77
  [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
80
78
  };
81
79
 
82
- export function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {
80
+ export function getLbtcAddressConfig(env: Env = defaultEnv): LbtcTokenConfig {
83
81
  switch (env) {
84
- case OEnv.prod:
82
+ case Env.prod:
85
83
  return prodConfig;
86
- case OEnv.testnet:
84
+ case Env.testnet:
87
85
  return testnetConfig;
88
86
  default:
89
87
  return stageConfig;
@@ -1 +1 @@
1
- export * from './signLbtcDestionationAddr';
1
+ export * from './signLbtcDestinationAddr';
@@ -1,19 +1,19 @@
1
1
  import { Provider } from '../../provider';
2
2
  import { IProviderBasedParams } from '../types';
3
3
 
4
- export type SignLbtcDestionationAddrParams = IProviderBasedParams;
4
+ export type SignLbtcDestinationAddrParams = IProviderBasedParams;
5
5
 
6
6
  /**
7
7
  * Signs the destination address for the LBTC in active chain
8
8
  * in the current account. Signing is necessary for the
9
9
  * generation of the deposit address.
10
10
  *
11
- * @param {SignLbtcDestionationAddrParams} params
11
+ * @param {SignLbtcDestinationAddrParams} params
12
12
  *
13
13
  * @returns {Promise<string>} The signature of the message.
14
14
  */
15
- export async function signLbtcDestionationAddr(
16
- params: SignLbtcDestionationAddrParams,
15
+ export async function signLbtcDestinationAddr(
16
+ params: SignLbtcDestinationAddrParams,
17
17
  ): Promise<string> {
18
18
  const provider = new Provider(params);
19
19
 
@@ -6,9 +6,9 @@ import { CodeBlock } from '../../stories/components/CodeBlock';
6
6
  import { useConnect } from '../../stories/hooks/useConnect';
7
7
  import useQuery from '../../stories/hooks/useQuery';
8
8
  import { fromCamelCase } from '../../stories/utils/fromCamelCase';
9
- import { signLbtcDestionationAddr } from './signLbtcDestionationAddr';
9
+ import { signLbtcDestinationAddr } from './signLbtcDestinationAddr';
10
10
 
11
- const { name } = signLbtcDestionationAddr;
11
+ const { name } = signLbtcDestinationAddr;
12
12
  const nameWithWhitespaces = fromCamelCase(name);
13
13
 
14
14
  const meta = {
@@ -32,7 +32,7 @@ export function StoryView() {
32
32
  return;
33
33
  }
34
34
 
35
- return signLbtcDestionationAddr(connectData);
35
+ return signLbtcDestinationAddr(connectData);
36
36
  };
37
37
 
38
38
  const { data, error, isLoading, refetch } = useQuery(request, [], false);
@@ -1,4 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
+ import { defaultEnv } from '@lombard.finance/sdk-common';
2
3
  import { Button } from '../../stories/components/Button';
3
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
5
  import { useConnect } from '../../stories/hooks/useConnect';
@@ -6,7 +7,6 @@ import useQuery from '../../stories/hooks/useQuery';
6
7
  import { fromCamelCase } from '../../stories/utils/fromCamelCase';
7
8
  import { MS_PER_DAY } from '../const';
8
9
  import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
9
- import { defaultEnv } from '../../common/const';
10
10
 
11
11
  const { name } = signNetworkFee;
12
12
  const nameWithWhitespaces = fromCamelCase(name);
@@ -1,14 +1,16 @@
1
- import { OEnv, TChainId, TEnv } from '../../common/types/types';
1
+ import { TChainId } from '../../common/types/types';
2
2
  import { getLbtcAddressConfig } from '../lbtcAddressConfig';
3
+ import { Env } from '@lombard.finance/sdk-common';
3
4
 
4
5
  /**
5
6
  * Gets the LBTC contract address for a given chain ID
6
7
  * @param chainId The chain ID
8
+ * @param env
7
9
  * @returns The LBTC contract address for the chain
8
10
  */
9
11
  export const getVerifyingContract = (
10
12
  chainId: TChainId,
11
- env: TEnv = OEnv.prod,
13
+ env: Env = Env.prod,
12
14
  ): string => {
13
15
  const lbtcAddressConfig = getLbtcAddressConfig(env);
14
16
  const address = lbtcAddressConfig[chainId];
@@ -1,5 +1,5 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { defaultEnv } from '../../common/const';
2
+ import { defaultEnv } from '@lombard.finance/sdk-common';
3
3
  import { Button } from '../../stories/components/Button';
4
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
5
  import { useConnect } from '../../stories/hooks/useConnect';
@@ -1,4 +1,4 @@
1
- import { getOutputScript } from '../../btcSdk/utils/getOutputScript';
1
+ import { getOutputScript } from '@lombard.finance/sdk-common';
2
2
  import { IEnvParam } from '../../common/types/internalTypes';
3
3
  import { toSatoshi } from '../../common/utils/convertSatoshi';
4
4
  import { IWeb3SendResult, Provider } from '../../provider';
@@ -34,7 +34,7 @@ export function unstakeLBTC({
34
34
  const tokenContract = getLbtcTokenContract(provider, env);
35
35
  const outputScript = getOutputScript(btcAddress, env);
36
36
 
37
- const amountSat = toSatoshi(amount);
37
+ const amountSat = toSatoshi(amount).toNumber();
38
38
 
39
39
  const tx = tokenContract.methods.redeem(outputScript, amountSat);
40
40
 
@@ -1,4 +1,5 @@
1
- import { OChainId, OEnv, TChainId, TEnv } from '../../common/types/types';
1
+ import { OChainId, TChainId } from '../../common/types/types';
2
+ import { Env } from '@lombard.finance/sdk-common';
2
3
 
3
4
  const PROD_NATIVE_MINT_CHAINS = [
4
5
  OChainId.ethereum,
@@ -6,6 +7,6 @@ const PROD_NATIVE_MINT_CHAINS = [
6
7
  OChainId.binanceSmartChain,
7
8
  ] as TChainId[];
8
9
 
9
- export const chainIdToEnv = (chainId: TChainId): TEnv => {
10
- return PROD_NATIVE_MINT_CHAINS.includes(chainId) ? OEnv.prod : OEnv.stage;
10
+ export const chainIdToEnv = (chainId: TChainId): Env => {
11
+ return PROD_NATIVE_MINT_CHAINS.includes(chainId) ? Env.prod : Env.stage;
11
12
  };
@@ -1,11 +1,14 @@
1
1
  import { ReadProvider } from '../../provider/ReadProvider';
2
- import { TEnv } from '../../common/types/types';
2
+ import { Env } from '@lombard.finance/sdk-common';
3
3
  import { isValidChain } from '../../common/utils/isValidChain';
4
4
  import { Provider } from '../../provider';
5
5
  import { getLbtcAddressConfig } from '../lbtcAddressConfig';
6
6
  import { getTokenABI } from './getTokenABI';
7
7
 
8
- export function getLbtcTokenContract(provider: Provider | ReadProvider, env?: TEnv) {
8
+ export function getLbtcTokenContract(
9
+ provider: Provider | ReadProvider,
10
+ env?: Env,
11
+ ) {
9
12
  const lbtcAddressConfig = getLbtcAddressConfig(env);
10
13
  const { chainId } = provider;
11
14
 
@@ -1,67 +0,0 @@
1
- import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';
2
- import {
3
- address as addressUtils,
4
- initEccLib,
5
- networks,
6
- payments,
7
- } from 'bitcoinjs-lib';
8
- import { OEnv, TEnv } from '../../common/types/types';
9
-
10
- initEccLib(ecc);
11
-
12
- type AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';
13
-
14
- /**
15
- * Get output script from address.
16
- *
17
- * @param address - The address.
18
- * @param networkMode - The network mode.
19
- *
20
- * @returns The output script.
21
- */
22
- export function getOutputScript(
23
- address: string,
24
- env: TEnv = OEnv.prod,
25
- ): string {
26
- const addressType = getAddressType(address);
27
-
28
- const payment = payments[addressType]({
29
- address,
30
- network: env === OEnv.prod ? networks.bitcoin : networks.testnet,
31
- });
32
-
33
- const paymentOutputScript = payment.output?.toString('hex');
34
-
35
- if (!paymentOutputScript) {
36
- throw new Error('Output script is not found.');
37
- }
38
-
39
- return `0x${paymentOutputScript}`;
40
- }
41
-
42
- function getAddressType(address: string): AddressType {
43
- const result = addressUtils.fromBech32(address);
44
-
45
- const isP2TR = result.version === 1 && result.data.length === 32;
46
- if (isP2TR) {
47
- return 'p2tr';
48
- }
49
-
50
- const isP2WPKH = result.version === 0 && result.data.length === 20;
51
- if (isP2WPKH) {
52
- return 'p2wpkh';
53
- }
54
-
55
- if (isP2WSHAddressType(address)) {
56
- return 'p2wsh';
57
- }
58
-
59
- throw new Error('Address type is not supported.');
60
- }
61
-
62
- function isP2WSHAddressType(address: string): boolean {
63
- return (
64
- (address.startsWith('bc1') || address.startsWith('tb1')) &&
65
- address.length === 62
66
- );
67
- }