@lombard.finance/sdk 2.2.1 → 2.4.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.
Files changed (51) 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 +2994 -721
  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 +1 -3
  16. package/src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts +4 -4
  17. package/src/sdk/getDepositsByAddress/getDepositsByAddress.stories.tsx +1 -1
  18. package/src/sdk/getDepositsByAddress/getDepositsByAddress.ts +4 -3
  19. package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +3 -3
  20. package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +1 -1
  21. package/src/sdk/getPointsByAddress/getPointsByAddress.stories.tsx +49 -0
  22. package/src/sdk/getPointsByAddress/getPointsByAddress.ts +163 -0
  23. package/src/sdk/getPointsByAddress/index.ts +6 -0
  24. package/src/sdk/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +49 -0
  25. package/src/sdk/getUnstakesByAddress/getUnstakesByAddress.ts +133 -0
  26. package/src/sdk/getUnstakesByAddress/index.ts +1 -0
  27. package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +1 -1
  28. package/src/sdk/index.ts +3 -1
  29. package/src/sdk/internalTypes.ts +3 -0
  30. package/src/sdk/setReferral/setReferral.ts +6 -5
  31. package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +1 -1
  32. package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +1 -1
  33. package/src/sdk/utils/getChainIdByName.ts +12 -6
  34. package/src/sdk/utils/getChainNameById.ts +25 -15
  35. package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +1 -1
  36. package/src/web3Sdk/approveLBTC/approveLBTC.ts +1 -1
  37. package/src/web3Sdk/basculeAddressConfig.ts +7 -8
  38. package/src/web3Sdk/claimLBTC/claimLBTC.stories.tsx +1 -1
  39. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +5 -2
  40. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +1 -2
  41. package/src/web3Sdk/lbtcAddressConfig.ts +6 -8
  42. package/src/web3Sdk/signLbtcDestionationAddr/index.ts +1 -1
  43. package/src/web3Sdk/signLbtcDestionationAddr/{signLbtcDestionationAddr.ts → signLbtcDestinationAddr.ts} +4 -4
  44. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +3 -3
  45. package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +1 -1
  46. package/src/web3Sdk/signStakeAndBake/utils.ts +4 -2
  47. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +1 -1
  48. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +2 -2
  49. package/src/web3Sdk/utils/chainIdToEnv.ts +4 -3
  50. package/src/web3Sdk/utils/getLbtcTokenContract.ts +5 -2
  51. package/src/btcSdk/utils/getOutputScript.ts +0 -67
@@ -0,0 +1,133 @@
1
+ import axios from 'axios';
2
+ import { address, networks } from 'bitcoinjs-lib';
3
+
4
+ import { IEnvParam } from '../../common/types/internalTypes';
5
+ import { SuiChain, TChainId } from '../../common/types/types';
6
+ import { fromSatoshi } from '../../common/utils/convertSatoshi';
7
+ import { getApiConfig } from '../../sdk/apiConfig';
8
+ import { TChainName } from '../../sdk/internalTypes';
9
+ import { getChainIdByName } from '../../sdk/utils/getChainIdByName';
10
+ import BigNumber from 'bignumber.js';
11
+
12
+ interface IUnstakeResponse {
13
+ tx_hash: string;
14
+ blockchain: TChainName;
15
+ block_height: string;
16
+ block_time: string;
17
+ from_address: string;
18
+ output_script: string;
19
+ amount: string;
20
+ payout_txid?: string;
21
+ payout_index?: string;
22
+ sanctioned?: boolean;
23
+ }
24
+
25
+ interface IGetUnstakesResponse {
26
+ unstakes?: IUnstakeResponse[];
27
+ }
28
+
29
+ export interface IUnstake {
30
+ /**
31
+ * The unstake transaction hash.
32
+ */
33
+ txHash: string;
34
+ /**
35
+ * The chain id where unstake transaction happened.
36
+ */
37
+ chainId: TChainId | SuiChain;
38
+ /**
39
+ * The block height.
40
+ */
41
+ blockHeight: number;
42
+ /**
43
+ * The timestamp of the unstake transaction.
44
+ */
45
+ unstakeDate: Date;
46
+ /**
47
+ * The initiator of the unstake transaction.
48
+ */
49
+ fromAddress: string;
50
+ /**
51
+ * The destination address to which the funds (BTC) will be transferred.
52
+ */
53
+ toAddress: string;
54
+ /**
55
+ * The amount of BTC unstaked.
56
+ */
57
+ amount: BigNumber;
58
+ /**
59
+ * The BTC payout transaction hash.
60
+ *
61
+ * If empty then the unstake is still pending. The payout tx hash is only
62
+ * present for the completed unstake transactions.
63
+ *
64
+ * A withdrawal period of 9 days is required by Lombard — daily rebalancing
65
+ * cycle — and Babylon — 7 days unbonding period. After that the payout
66
+ * should be completed.
67
+ */
68
+ payoutTxHash?: string;
69
+ /**
70
+ * The index of the payout transaction corresponding to the unstake.
71
+ */
72
+ payoutTxIndex?: number;
73
+ /**
74
+ * A flag indicating whether the unstake transaction has been sanctioned and
75
+ * flagged as suspicious.
76
+ * See: https://docs.lombard.finance/technical-documentation/sanctions-and-risk-monitoring
77
+ */
78
+ sanctioned?: boolean;
79
+ }
80
+
81
+ export interface IGetUnstakesByAddressParameters extends IEnvParam {
82
+ /**
83
+ * The address of an initiator of the unstake.
84
+ */
85
+ address: string;
86
+ }
87
+
88
+ /**
89
+ * Gets all unstakes initiated by the specified address.
90
+ *
91
+ * @throws {Error} - Throws an error when there's no address specified.
92
+ */
93
+ export async function getUnstakesByAddress({
94
+ address,
95
+ env = 'prod',
96
+ }: IGetUnstakesByAddressParameters): Promise<IUnstake[]> {
97
+ const { baseApiUrl } = getApiConfig(env);
98
+
99
+ if (!address) {
100
+ throw new Error('No address specified.');
101
+ }
102
+
103
+ const {
104
+ data: { unstakes = [] },
105
+ } = await axios.get<IGetUnstakesResponse>(
106
+ `/api/v1/address/unstakes/${address}`,
107
+ {
108
+ baseURL: baseApiUrl,
109
+ },
110
+ );
111
+
112
+ return unstakes.map(unstakeData => mapResponse(unstakeData, env));
113
+ }
114
+
115
+ function mapResponse(data: IUnstakeResponse, env: IEnvParam['env']): IUnstake {
116
+ const btcAddress = address.fromOutputScript(
117
+ Buffer.from(data.output_script, 'hex'),
118
+ env === 'prod' ? networks.bitcoin : networks.testnet,
119
+ );
120
+
121
+ return {
122
+ txHash: data.tx_hash,
123
+ chainId: getChainIdByName(data.blockchain, env),
124
+ blockHeight: +data.block_height,
125
+ unstakeDate: new Date(+data.block_time * 1000),
126
+ fromAddress: data.from_address,
127
+ toAddress: btcAddress,
128
+ amount: fromSatoshi(data.amount),
129
+ payoutTxHash: data.payout_txid,
130
+ payoutTxIndex: data.payout_index ? +data.payout_index : undefined,
131
+ sanctioned: data.sanctioned,
132
+ };
133
+ }
@@ -0,0 +1 @@
1
+ export { getUnstakesByAddress } from './getUnstakesByAddress';
@@ -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';
@@ -7,7 +8,6 @@ import {
7
8
  IGetUserStakeAndBakeSignatureParams,
8
9
  getUserStakeAndBakeSignature,
9
10
  } from './getUserStakeAndBakeSignature';
10
- import { defaultEnv } from '../../common/const';
11
11
 
12
12
  const meta = {
13
13
  title: 'SDK/getUserStakeAndBakeSignature',
package/src/sdk/index.ts CHANGED
@@ -4,9 +4,11 @@ export * from './getDepositBtcAddress';
4
4
  export * from './getDepositsByAddress';
5
5
  export * from './getLBTCExchangeRate';
6
6
  export * from './getNetworkFeeSignature';
7
+ export * from './getPointsByAddress';
8
+ export * from './getUnstakesByAddress';
7
9
  export * from './getUserStakeAndBakeSignature';
10
+ export * from './setReferral';
8
11
  export * from './storeNetworkFeeSignature';
9
12
  export * from './storeStakeAndBakeSignature';
10
13
  export * from './utils/getChainIdByName';
11
14
  export * from './utils/getChainNameById';
12
- export * from './setReferral';
@@ -7,6 +7,9 @@ export const OChainName = {
7
7
 
8
8
  bsc: 'DESTINATION_BLOCKCHAIN_BSC',
9
9
  bscOld: 'BLOCKCHAIN_BSC',
10
+
11
+ sui: 'DESTINATION_BLOCKCHAIN_SUI',
12
+ suiOld: 'BLOCKCHAIN_SUI',
10
13
  } as const;
11
14
 
12
15
  export type TChainName = (typeof OChainName)[keyof typeof OChainName];
@@ -13,17 +13,18 @@ export interface ISetReferralParams extends IEnvParam {
13
13
  */
14
14
  address: string;
15
15
  /**
16
- * The signature of the address. The signature is generated by signing the address using EVM wallet.
16
+ * The signature of the address. The signature is generated by signing the address using wallet.
17
+ * Use `signTermsOfService` or `signLbtcDestinationAddr` functions.
17
18
  */
18
19
  signature: string;
19
- /**
20
- * The typed data object used to generate the signature if using a network fee authorization signature.
21
- */
22
- eip712Data: string;
23
20
  /**
24
21
  * The captcha token.
25
22
  */
26
23
  referrerCode: string;
24
+ /**
25
+ * The typed data object used to generate the signature if using a network fee authorization signature.
26
+ */
27
+ eip712Data?: string;
27
28
  }
28
29
 
29
30
  /**
@@ -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';
@@ -7,7 +8,6 @@ import {
7
8
  IStoreNetworkFeeSignatureParams,
8
9
  storeNetworkFeeSignature,
9
10
  } from './storeNetworkFeeSignature';
10
- import { defaultEnv } from '../../common/const';
11
11
 
12
12
  const meta = {
13
13
  title: 'SDK/storeNetworkFeeSignature',
@@ -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';
@@ -9,7 +10,6 @@ import {
9
10
  signStakeAndBake,
10
11
  } from '../../web3Sdk/signStakeAndBake/signStakeAndBake';
11
12
  import { storeStakeAndBakeSignature } from './storeStakeAndBakeSignature';
12
- import { defaultEnv } from '../../common/const';
13
13
 
14
14
  const meta = {
15
15
  title: 'SDK/storeStakeAndBakeSignature',
@@ -1,23 +1,25 @@
1
- import { defaultEnv } from '../../common/const';
1
+ import { defaultEnv } from '@lombard.finance/sdk-common';
2
2
  import {
3
3
  getBaseNetworkByEnv,
4
4
  getBscNetworkByEnv,
5
5
  getEthNetworkByEnv,
6
+ getSuiNetworkByEnv,
6
7
  OChainId,
8
+ SuiChain,
7
9
  TChainId,
8
- TEnv,
9
10
  } from '../../common/types/types';
11
+ import { Env } from '@lombard.finance/sdk-common';
10
12
  import { OChainName, TChainName } from '../internalTypes';
11
13
 
12
14
  /**
13
- * @param chainId the chain ID
14
- *
15
+ * @param chain the chain ID
16
+ * @param env
15
17
  * @returns the chain name
16
18
  */
17
19
  export function getChainIdByName(
18
20
  chain: string,
19
- env: TEnv = defaultEnv,
20
- ): TChainId {
21
+ env: Env = defaultEnv,
22
+ ): TChainId | SuiChain {
21
23
  switch (chain as TChainName) {
22
24
  case OChainName.eth:
23
25
  case OChainName.ethOld:
@@ -31,6 +33,10 @@ export function getChainIdByName(
31
33
  case OChainName.bscOld:
32
34
  return getBscNetworkByEnv(env);
33
35
 
36
+ case OChainName.sui:
37
+ case OChainName.suiOld:
38
+ return getSuiNetworkByEnv(env);
39
+
34
40
  default:
35
41
  return OChainId.ethereum;
36
42
  }
@@ -1,4 +1,4 @@
1
- import { OChainId, TChainId } from '../../common/types/types';
1
+ import { OChainId, SuiChain, TChainId } from '../../common/types/types';
2
2
  import { OChainName, TChainName } from '../internalTypes';
3
3
 
4
4
  /**
@@ -6,19 +6,29 @@ import { OChainName, TChainName } from '../internalTypes';
6
6
  *
7
7
  * @returns the chain name
8
8
  */
9
- export function getChainNameById(chainId: TChainId): TChainName {
10
- switch (chainId) {
11
- case OChainId.ethereum:
12
- case OChainId.holesky:
13
- case OChainId.sepolia:
14
- return OChainName.eth;
15
- case OChainId.base:
16
- case OChainId.baseSepoliaTestnet:
17
- return OChainName.base;
18
- case OChainId.binanceSmartChain:
19
- case OChainId.binanceSmartChainTestnet:
20
- return OChainName.bsc;
21
- default:
22
- throw new Error(`Unknown chain ID: ${chainId}`);
9
+ export function getChainNameById(chainId: TChainId | SuiChain): TChainName {
10
+ if (
11
+ chainId === OChainId.ethereum ||
12
+ chainId === OChainId.holesky ||
13
+ chainId === OChainId.sepolia
14
+ ) {
15
+ return OChainName.eth;
23
16
  }
17
+
18
+ if (chainId === OChainId.base || chainId === OChainId.baseSepoliaTestnet) {
19
+ return OChainName.base;
20
+ }
21
+
22
+ if (
23
+ chainId === OChainId.binanceSmartChain ||
24
+ chainId === OChainId.binanceSmartChainTestnet
25
+ ) {
26
+ return OChainName.bsc;
27
+ }
28
+
29
+ if (chainId === 'sui:testnet' || chainId === 'sui:mainnet') {
30
+ return OChainName.sui;
31
+ }
32
+
33
+ throw new Error(`Unknown chain ID: ${chainId}`);
24
34
  }
@@ -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';
@@ -31,7 +31,7 @@ export function approveLBTC({
31
31
  }: IApproveLBTCParams): Promise<IWeb3SendResult> {
32
32
  const provider = new Provider(providerParams);
33
33
  const tokenContract = getLbtcTokenContract(provider, env);
34
- const amountSat = toSatoshi(amount);
34
+ const amountSat = toSatoshi(amount).toNumber();
35
35
 
36
36
  const tx = tokenContract.methods.approve(spender, amountSat);
37
37
 
@@ -1,8 +1,7 @@
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
+
4
+ import { Env, defaultEnv } from '@lombard.finance/sdk-common';
6
5
 
7
6
  type BasculeTokenConfig = Record<TChainId, string>;
8
7
 
@@ -76,12 +75,12 @@ const prodConfig: BasculeTokenConfig = {
76
75
  };
77
76
 
78
77
  export function getBasculeAddressConfig(
79
- env: TEnv = defaultEnv,
78
+ env: Env = defaultEnv,
80
79
  ): BasculeTokenConfig {
81
80
  switch (env) {
82
- case OEnv.prod:
81
+ case Env.prod:
83
82
  return prodConfig;
84
- case OEnv.testnet:
83
+ case Env.testnet:
85
84
  return testnetConfig;
86
85
  default:
87
86
  return stageConfig;
@@ -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,10 +1,13 @@
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';
6
6
  import useQuery from '../../stories/hooks/useQuery';
7
- import { getBasculeDepositStatus, ICheckBasculeDepositStatusParams } from './getBasculeDepositStatus';
7
+ import {
8
+ getBasculeDepositStatus,
9
+ ICheckBasculeDepositStatusParams,
10
+ } from './getBasculeDepositStatus';
8
11
 
9
12
  const meta = {
10
13
  title: 'Web3SDK/getBasculeDepositStatus',
@@ -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';
@@ -28,7 +28,6 @@ export const WithParams: Story = {
28
28
  type TotalSupplyLBTCProps = Pick<ILBTCTotalSupplyParams, 'env'>;
29
29
 
30
30
  export function StoryView(props: TotalSupplyLBTCProps) {
31
-
32
31
  const { data: connectData, error: connectError } = useConnect();
33
32
 
34
33
  const request = async () => {
@@ -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
- }