@lombard.finance/sdk 3.6.0 → 3.6.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 (94) hide show
  1. package/README.md +4 -4
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +83 -85
  4. package/dist/index2.cjs +47 -47
  5. package/dist/index2.js +3060 -3001
  6. package/package.json +1 -1
  7. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +5 -5
  8. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +1 -1
  9. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +5 -5
  10. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +1 -1
  11. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +4 -4
  12. package/src/api-functions/getDepositsByAddress/getDepositsByAddress.stories.tsx +3 -3
  13. package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +5 -5
  14. package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +4 -4
  15. package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +6 -6
  16. package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.ts +2 -2
  17. package/src/api-functions/getPointsByAddress/getPointsByAddress.stories.tsx +3 -3
  18. package/src/api-functions/getPointsByAddress/getPointsByAddress.ts +2 -2
  19. package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +3 -3
  20. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +4 -4
  21. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +2 -2
  22. package/src/api-functions/setReferral/setReferral.ts +1 -1
  23. package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +3 -3
  24. package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +1 -1
  25. package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +1 -1
  26. package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +1 -1
  27. package/src/bridge/lib/bridge.stories.tsx +7 -7
  28. package/src/bridge/lib/bridge.ts +3 -3
  29. package/src/bridge/lib/ccip-bridge.stories.tsx +7 -7
  30. package/src/bridge/lib/ccip-bridge.ts +11 -11
  31. package/src/clients/public-client.ts +3 -3
  32. package/src/clients/wallet-client.ts +3 -3
  33. package/src/common/parameters.ts +1 -1
  34. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +10 -10
  35. package/src/contract-functions/approveLBTC/approveLBTC.ts +7 -7
  36. package/src/contract-functions/claimLBTC/claimLBTC.stories.tsx +8 -8
  37. package/src/contract-functions/claimLBTC/claimLBTC.ts +11 -12
  38. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +3 -3
  39. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +6 -6
  40. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +16 -23
  41. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +3 -4
  42. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +8 -4
  43. package/src/contract-functions/getPermitNonce/getPermitNonce.stories.tsx +2 -2
  44. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +8 -4
  45. package/src/contract-functions/getShareValue/getShareValue.stories.tsx +2 -2
  46. package/src/contract-functions/getShareValue/getShareValue.ts +4 -4
  47. package/src/contract-functions/getSharesByAddress/getSharesByAddress.stories.tsx +5 -5
  48. package/src/contract-functions/getSharesByAddress/getSharesByAddress.ts +4 -4
  49. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +6 -6
  50. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +7 -7
  51. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +1 -1
  52. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +5 -5
  53. package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +7 -7
  54. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +4 -4
  55. package/src/contract-functions/signStakeAndBake/signStakeAndBake.stories.tsx +6 -6
  56. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +7 -7
  57. package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +8 -8
  58. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +10 -10
  59. package/src/metrics/get-lbtc-stats.stories.tsx +1 -1
  60. package/src/metrics/get-lbtc-stats.ts +4 -3
  61. package/src/metrics/get-rewards-info.ts +22 -2
  62. package/src/rewards/lib/claim-reward.stories.tsx +9 -9
  63. package/src/rewards/lib/claim-reward.ts +6 -6
  64. package/src/rewards/lib/get-reward-balances.stories.tsx +4 -4
  65. package/src/rewards/lib/get-reward-balances.ts +4 -4
  66. package/src/rewards/lib/get-reward-signing-data.stories.tsx +4 -4
  67. package/src/rewards/lib/get-reward-signing-data.ts +3 -3
  68. package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +4 -4
  69. package/src/rewards/lib/get-reward-withdrawal-fee.ts +3 -3
  70. package/src/rewards/lib/get-reward-withdrawals.stories.tsx +4 -4
  71. package/src/rewards/lib/get-reward-withdrawals.ts +3 -3
  72. package/src/stories/components/decorators/wagmi-decorator.tsx +1 -1
  73. package/src/stories/hooks/useConnection.ts +2 -2
  74. package/src/tokens/abi/ASSET_ROUTER_ABI.ts +37 -8
  75. package/src/tokens/lbtc-addresses.ts +2 -2
  76. package/src/tokens/token-addresses.ts +0 -8
  77. package/src/tokens/tokens.ts +74 -36
  78. package/src/utils/env.ts +1 -1
  79. package/src/vaults/lib/config.ts +4 -4
  80. package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +3 -3
  81. package/src/vaults/lib/metrics/get-vault-apy.ts +2 -2
  82. package/src/vaults/lib/metrics/get-vault-points.stories.tsx +3 -3
  83. package/src/vaults/lib/metrics/get-vault-points.ts +2 -2
  84. package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +3 -3
  85. package/src/vaults/lib/metrics/get-vault-tvl.ts +8 -8
  86. package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +6 -6
  87. package/src/vaults/lib/ops/deposit.stories.tsx +7 -7
  88. package/src/vaults/lib/ops/deposit.ts +5 -5
  89. package/src/vaults/lib/ops/get-vault-deposits.stories.tsx +5 -5
  90. package/src/vaults/lib/ops/get-vault-deposits.ts +11 -11
  91. package/src/vaults/lib/ops/get-vault-withdrawals.stories.tsx +4 -4
  92. package/src/vaults/lib/ops/get-vault-withdrawals.ts +9 -9
  93. package/src/vaults/lib/ops/withdraw.stories.tsx +7 -7
  94. package/src/vaults/lib/ops/withdraw.ts +5 -5
@@ -1,13 +1,13 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
+ import { ChainId } from '../../common/chains';
2
3
  import { Button } from '../../stories/components/Button';
3
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
+ import { functionType } from '../../stories/components/decorators';
4
6
  import useQuery from '../../stories/hooks/useQuery';
5
7
  import {
6
- getBasculeDepositStatus,
7
8
  IGetBasculeDepositStatusParameters,
9
+ getBasculeDepositStatus,
8
10
  } from './getBasculeDepositStatus';
9
- import { ChainId } from '../../common/chains';
10
- import { functionType } from '../../stories/components/decorators';
11
11
 
12
12
  const meta = {
13
13
  title: 'read/getBasculeDepositStatus',
@@ -1,20 +1,20 @@
1
- import { CommonOptionalWriteParameters } from '../../common/parameters';
2
- import { getErrorMessage } from '../../utils/err';
3
1
  import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
4
- import { IDeposit } from '../../api-functions/getDepositsByAddress/getDepositsByAddress';
5
2
  import {
6
3
  ByteArray,
7
4
  Client,
5
+ PublicClient,
8
6
  getContract,
9
7
  keccak256,
10
- PublicClient,
11
8
  zeroAddress,
12
9
  } from 'viem';
10
+ import { IDeposit } from '../../api-functions/getDepositsByAddress/getDepositsByAddress';
13
11
  import { makePublicClient } from '../../clients/public-client';
14
12
  import { makeWalletClient } from '../../clients/wallet-client';
13
+ import { CommonOptionalWriteParameters } from '../../common/parameters';
15
14
  import LBTC_BASCULE_ABI from '../../tokens/abi/LBTC_BASCULE_ABI.json';
16
- import { getTokenContractInfo } from '../../tokens/tokens';
17
15
  import { Token } from '../../tokens/token-addresses';
16
+ import { getTokenContractInfo } from '../../tokens/tokens';
17
+ import { getErrorMessage } from '../../utils/err';
18
18
 
19
19
  /**
20
20
  * The bascule drawbridge deposit status.
@@ -81,7 +81,7 @@ export async function getBasculeDepositStatus({
81
81
  }
82
82
 
83
83
  const publicClient = makePublicClient({ chainId, rpcUrl, env });
84
- const tokenContractInfo = getTokenContractInfo(token, chainId, env);
84
+ const tokenContractInfo = await getTokenContractInfo(token, chainId, env);
85
85
 
86
86
  const basculeContractAddress = await publicClient.readContract({
87
87
  abi: tokenContractInfo.abi,
@@ -1,11 +1,11 @@
1
1
  import BigNumber from 'bignumber.js';
2
+ import { makePublicClient } from '../../clients/public-client';
2
3
  import { CommonParameters } from '../../common/parameters';
4
+ import ASSET_ROUTER_ABI from '../../tokens/abi/ASSET_ROUTER_ABI';
5
+ import { Token } from '../../tokens/token-addresses';
6
+ import { getTokenContractInfo, isUpgradedAbi } from '../../tokens/tokens';
3
7
  import { determineEnv } from '../../utils/env';
4
8
  import { fromSatoshi } from '../../utils/satoshi';
5
- import { makePublicClient } from '../../clients/public-client';
6
- import { getTokenContractInfo, isSTLBTCAbi } from '../../tokens/tokens';
7
- import { Token } from '../../tokens/token-addresses';
8
- import ASSET_ROUTER_ABI from '../../tokens/abi/ASSET_ROUTER_ABI';
9
9
 
10
10
  /**
11
11
  * Gets LBTC minting fee amount.
@@ -41,12 +41,14 @@ export async function getMintingFee({
41
41
  const environment = env || determineEnv(chainId);
42
42
 
43
43
  const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
44
- const tokenContract = getTokenContractInfo(token, chainId, environment);
44
+ const tokenContract = await getTokenContractInfo(token, chainId, environment);
45
45
  const tokenContractAbi = tokenContract.abi;
46
46
 
47
47
  let rawFeeValue = 0n;
48
48
 
49
- if (isSTLBTCAbi(tokenContractAbi) || token === Token.NativeLBTC) {
49
+ console.log('mint fee', tokenContract);
50
+
51
+ if (isUpgradedAbi(tokenContractAbi) || token === Token.NativeLBTC) {
50
52
  const assetRouterAddress = await publicClient.readContract({
51
53
  abi: tokenContractAbi,
52
54
  address: tokenContract.address,
@@ -62,6 +64,7 @@ export async function getMintingFee({
62
64
  abi: assetRouter.abi,
63
65
  address: assetRouter.address,
64
66
  functionName: 'maxMintCommission',
67
+ args: [tokenContract.address],
65
68
  });
66
69
  } else {
67
70
  rawFeeValue = await publicClient.readContract({
@@ -87,19 +90,10 @@ export async function getRedeemFee({
87
90
  const environment = env || determineEnv(chainId);
88
91
 
89
92
  const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
90
- const tokenContract = getTokenContractInfo(token, chainId, environment);
93
+ const tokenContract = await getTokenContractInfo(token, chainId, environment);
91
94
 
92
95
  let rawFeeValue = 0n;
93
- if (
94
- (token === Token.LBTC && isSTLBTCAbi(tokenContract.abi)) ||
95
- token === Token.NativeLBTC
96
- ) {
97
- const nativeTokenContract = getTokenContractInfo(
98
- Token.NativeLBTC,
99
- chainId,
100
- environment,
101
- );
102
-
96
+ if (isUpgradedAbi(tokenContract.abi) || token === Token.NativeLBTC) {
103
97
  const assetRouterAddress = await publicClient.readContract({
104
98
  abi: tokenContract.abi,
105
99
  address: tokenContract.address,
@@ -111,25 +105,24 @@ export async function getRedeemFee({
111
105
  address: assetRouterAddress,
112
106
  };
113
107
 
108
+ // 1.
114
109
  const toNativeCommissionValue = await publicClient.readContract({
115
110
  abi: assetRouter.abi,
116
111
  address: assetRouter.address,
117
112
  functionName: 'toNativeCommission',
113
+ args: [tokenContract.address],
118
114
  });
119
115
 
116
+ // 2.
120
117
  const [redeemFeeValue /* redeemForBtcMinAmountValue, isRedeemEnabled */] =
121
118
  await publicClient.readContract({
122
119
  abi: assetRouter.abi,
123
120
  address: assetRouter.address,
124
121
  functionName: 'tokenConfig',
125
- args: [nativeTokenContract.address],
122
+ args: [tokenContract.address],
126
123
  });
127
124
 
128
- if (token === Token.LBTC) {
129
- rawFeeValue = toNativeCommissionValue + redeemFeeValue;
130
- } else {
131
- rawFeeValue = redeemFeeValue;
132
- }
125
+ rawFeeValue = toNativeCommissionValue + redeemFeeValue;
133
126
  } else {
134
127
  // legacy (and BTCK v1)
135
128
  rawFeeValue = await publicClient.readContract({
@@ -1,12 +1,11 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
2
+ import { ChainId } from '../../common/chains';
3
+ import { chainSelector, envSelector } from '../../stories/arg-types';
3
4
  import { Button } from '../../stories/components/Button';
4
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
6
+ import { functionType } from '../../stories/components/decorators';
5
7
  import useQuery from '../../stories/hooks/useQuery';
6
8
  import { getLBTCTotalSupply } from './getLBTCTotalSupply';
7
- import { ChainId } from '../../common/chains';
8
- import { functionType } from '../../stories/components/decorators';
9
- import { chainSelector, envSelector } from '../../stories/arg-types';
10
9
 
11
10
  const meta = {
12
11
  title: 'read/getLBTCTotalSupply',
@@ -1,10 +1,10 @@
1
- import { CommonParameters } from '../../common/parameters';
2
1
  import BigNumber from 'bignumber.js';
3
- import { fromSatoshi } from '../../utils/satoshi';
4
2
  import { makePublicClient } from '../../clients/public-client';
5
- import { getTokenContractInfo } from '../../tokens/tokens';
3
+ import { CommonParameters } from '../../common/parameters';
6
4
  import { Token } from '../../tokens/token-addresses';
5
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
6
  import { determineEnv } from '../../utils/env';
7
+ import { fromSatoshi } from '../../utils/satoshi';
8
8
 
9
9
  /**
10
10
  * Get the total supply of LBTC tokens.
@@ -23,7 +23,11 @@ export async function getLBTCTotalSupply({
23
23
  }: CommonParameters): Promise<BigNumber> {
24
24
  const environment = env || determineEnv(chainId);
25
25
  const publicClient = makePublicClient({ chainId, rpcUrl, env: environment });
26
- const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
26
+ const lbtcContract = await getTokenContractInfo(
27
+ Token.LBTC,
28
+ chainId,
29
+ environment,
30
+ );
27
31
 
28
32
  const totalSupplyRaw = await publicClient.readContract({
29
33
  abi: lbtcContract.abi,
@@ -1,9 +1,9 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
- import useQuery from '../../stories/hooks/useQuery';
5
- import { getPermitNonce, IGetPermitNonceParams } from './getPermitNonce';
6
4
  import { functionType } from '../../stories/components/decorators';
5
+ import useQuery from '../../stories/hooks/useQuery';
6
+ import { IGetPermitNonceParams, getPermitNonce } from './getPermitNonce';
7
7
 
8
8
  const meta = {
9
9
  title: 'read/getPermitNonce',
@@ -1,10 +1,10 @@
1
- import { CommonParameters } from '../../common/parameters';
2
- import { determineEnv } from '../../utils/env';
3
1
  import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
4
2
  import { Address } from 'viem';
5
3
  import { makePublicClient } from '../../clients/public-client';
6
- import { getTokenContractInfo } from '../../tokens/tokens';
4
+ import { CommonParameters } from '../../common/parameters';
7
5
  import { Token } from '../../tokens/token-addresses';
6
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
+ import { determineEnv } from '../../utils/env';
8
8
 
9
9
  export interface IGetPermitNonceParams extends CommonParameters {
10
10
  /**
@@ -32,7 +32,11 @@ export async function getPermitNonce({
32
32
  const environment = env || determineEnv(chainId);
33
33
 
34
34
  const publicClient = makePublicClient({ chainId, rpcUrl });
35
- const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
35
+ const lbtcContract = await getTokenContractInfo(
36
+ Token.LBTC,
37
+ chainId,
38
+ environment,
39
+ );
36
40
 
37
41
  const nonce = await publicClient.readContract({
38
42
  abi: lbtcContract.abi,
@@ -2,10 +2,10 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
 
3
3
  import { ChainId } from '../../common/chains';
4
4
  import { Button } from '../../stories/components/Button';
5
+ import { functionType } from '../../stories/components/decorators';
5
6
  import useQuery from '../../stories/hooks/useQuery';
6
- import { getShareValue, IGetShareValueParameters } from './getShareValue';
7
7
  import { Vault } from '../../vaults/lib/config';
8
- import { functionType } from '../../stories/components/decorators';
8
+ import { IGetShareValueParameters, getShareValue } from './getShareValue';
9
9
 
10
10
  const meta = {
11
11
  title: 'read/getShareValue',
@@ -1,10 +1,10 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { getErrorMessage } from '../../utils/err';
3
- import { isVedaVaultChain, Vault, VAULTS } from '../../vaults/lib/config';
4
- import { fromSatoshi } from '../../utils/satoshi';
5
- import { makePublicClient } from '../../clients/public-client';
6
2
  import { getContract } from 'viem';
3
+ import { makePublicClient } from '../../clients/public-client';
7
4
  import { CommonParameters } from '../../common/parameters';
5
+ import { getErrorMessage } from '../../utils/err';
6
+ import { fromSatoshi } from '../../utils/satoshi';
7
+ import { VAULTS, Vault, isVedaVaultChain } from '../../vaults/lib/config';
8
8
 
9
9
  export interface IGetShareValueParameters extends CommonParameters {
10
10
  /**
@@ -2,15 +2,15 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
 
3
3
  import { ChainId } from '../../common/chains';
4
4
  import { Button } from '../../stories/components/Button';
5
+ import { CodeBlock } from '../../stories/components/CodeBlock';
6
+ import { functionType } from '../../stories/components/decorators';
7
+ import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
5
8
  import useQuery from '../../stories/hooks/useQuery';
9
+ import { Vault } from '../../vaults/lib/config';
6
10
  import {
7
- getSharesByAddress,
8
11
  IGetSharesByAddressParameters,
12
+ getSharesByAddress,
9
13
  } from './getSharesByAddress';
10
- import { Vault } from '../../vaults/lib/config';
11
- import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
12
- import { CodeBlock } from '../../stories/components/CodeBlock';
13
- import { functionType } from '../../stories/components/decorators';
14
14
 
15
15
  const meta = {
16
16
  title: 'read/getSharesByAddress',
@@ -1,11 +1,11 @@
1
1
  import BigNumber from 'bignumber.js';
2
+ import { getContract } from 'viem';
3
+ import { makePublicClient } from '../../clients/public-client';
4
+ import { CommonParameters } from '../../common/parameters';
2
5
  import { getErrorMessage } from '../../utils/err';
3
- import { isVedaVaultChain, Vault, VAULTS } from '../../vaults/lib/config';
4
6
  import { fromSatoshi } from '../../utils/satoshi';
7
+ import { VAULTS, Vault, isVedaVaultChain } from '../../vaults/lib/config';
5
8
  import { getShareValue } from '../getShareValue';
6
- import { makePublicClient } from '../../clients/public-client';
7
- import { getContract } from 'viem';
8
- import { CommonParameters } from '../../common/parameters';
9
9
 
10
10
  export interface IGetSharesByAddressParameters extends CommonParameters {
11
11
  /**
@@ -3,16 +3,16 @@ import type { Meta, StoryObj } from '@storybook/react';
3
3
  import { ChainId } from '../../common/chains';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
6
+ import { functionType } from '../../stories/components/decorators';
6
7
  import useQuery from '../../stories/hooks/useQuery';
7
8
  import {
8
- getStakeAndBakeFee,
9
- IGetStakeAndBakeFeeParams,
10
- } from './getStakeAndBakeFee';
11
- import {
12
- Vault,
13
9
  VEDA_VAULT_STAKE_AND_BAKE_CHAINS,
10
+ Vault,
14
11
  } from '../../vaults/lib/config';
15
- import { functionType } from '../../stories/components/decorators';
12
+ import {
13
+ IGetStakeAndBakeFeeParams,
14
+ getStakeAndBakeFee,
15
+ } from './getStakeAndBakeFee';
16
16
 
17
17
  const meta = {
18
18
  title: 'read/getStakeAndBakeFee',
@@ -1,14 +1,14 @@
1
- import { getErrorMessage } from '../../utils/err';
1
+ import BigNumber from 'bignumber.js';
2
+ import { getContract } from 'viem';
3
+ import { makePublicClient } from '../../clients/public-client';
2
4
  import { CommonParameters } from '../../common/parameters';
5
+ import { getErrorMessage } from '../../utils/err';
6
+ import { fromSatoshi } from '../../utils/satoshi';
3
7
  import {
4
- isVedaVaultStakeAndBakeChain,
5
- Vault,
6
8
  VAULTS,
9
+ Vault,
10
+ isVedaVaultStakeAndBakeChain,
7
11
  } from '../../vaults/lib/config';
8
- import { makePublicClient } from '../../clients/public-client';
9
- import { getContract } from 'viem';
10
- import { fromSatoshi } from '../../utils/satoshi';
11
- import BigNumber from 'bignumber.js';
12
12
 
13
13
  export interface IGetStakeAndBakeFeeParams
14
14
  extends Omit<CommonParameters, 'env'> {
@@ -1,5 +1,5 @@
1
- import { CommonWriteParameters } from '../../common/parameters';
2
1
  import { makeWalletClient } from '../../clients/wallet-client';
2
+ import { CommonWriteParameters } from '../../common/parameters';
3
3
 
4
4
  export type SignLbtcDestinationAddrParams = Omit<
5
5
  CommonWriteParameters,
@@ -1,17 +1,17 @@
1
1
  import type { Meta } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
+ import { ConnectButton } from '../../stories/components/ConnectButton';
5
+ import {
6
+ functionType,
7
+ wagmiDecorator,
8
+ } from '../../stories/components/decorators';
4
9
  import {
5
10
  canPerformAction,
6
11
  useConnection,
7
12
  } from '../../stories/hooks/useConnection';
8
13
  import useQuery from '../../stories/hooks/useQuery';
9
14
  import { signLbtcDestinationAddr } from './signLbtcDestinationAddr';
10
- import { ConnectButton } from '../../stories/components/ConnectButton';
11
- import {
12
- functionType,
13
- wagmiDecorator,
14
- } from '../../stories/components/decorators';
15
15
 
16
16
  const meta = {
17
17
  title: 'write/signLbtcDestionationAddr',
@@ -1,19 +1,19 @@
1
+ import { Env } from '@lombard.finance/sdk-common';
1
2
  import type { Meta, StoryObj } from '@storybook/react';
2
3
  import { Button } from '../../stories/components/Button';
3
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
+ import { ConnectButton } from '../../stories/components/ConnectButton';
6
+ import {
7
+ functionType,
8
+ wagmiDecorator,
9
+ } from '../../stories/components/decorators';
4
10
  import {
5
11
  canPerformAction,
6
12
  useConnection,
7
13
  } from '../../stories/hooks/useConnection';
8
14
  import useQuery from '../../stories/hooks/useQuery';
9
- import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
10
15
  import { DAY, now, toUnix } from '../../utils/time';
11
- import { ConnectButton } from '../../stories/components/ConnectButton';
12
- import {
13
- functionType,
14
- wagmiDecorator,
15
- } from '../../stories/components/decorators';
16
- import { Env } from '@lombard.finance/sdk-common';
16
+ import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
17
17
 
18
18
  const meta = {
19
19
  title: 'write/signNetworkFee',
@@ -1,10 +1,10 @@
1
1
  import BigNumber from 'bignumber.js';
2
+ import { Hex } from 'viem';
2
3
  import { makeWalletClient } from '../../clients/wallet-client';
3
4
  import { CommonWriteParameters } from '../../common/parameters';
4
- import { DAY, now, toUnix } from '../../utils/time';
5
- import { Hex } from 'viem';
6
- import { getTokenContractInfo } from '../../tokens/tokens';
7
5
  import { Token } from '../../tokens/token-addresses';
6
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
+ import { DAY, now, toUnix } from '../../utils/time';
8
8
 
9
9
  export interface ISignNetworkFeeParams extends CommonWriteParameters {
10
10
  /**
@@ -52,7 +52,7 @@ export async function signNetworkFee({
52
52
  provider,
53
53
  env,
54
54
  }: ISignNetworkFeeParams): Promise<ISignNetworkFeeResponse> {
55
- const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
55
+ const lbtcContract = await getTokenContractInfo(Token.LBTC, chainId, env);
56
56
  const walletClient = makeWalletClient({
57
57
  chainId,
58
58
  provider,
@@ -1,18 +1,18 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
- import {
5
- canPerformAction,
6
- useConnection,
7
- } from '../../stories/hooks/useConnection';
8
- import useQuery from '../../stories/hooks/useQuery';
9
- import { signStakeAndBake, ISignStakeAndBakeParams } from './signStakeAndBake';
10
4
  import { ConnectButton } from '../../stories/components/ConnectButton';
11
5
  import {
12
6
  functionType,
13
7
  wagmiDecorator,
14
8
  } from '../../stories/components/decorators';
9
+ import {
10
+ canPerformAction,
11
+ useConnection,
12
+ } from '../../stories/hooks/useConnection';
13
+ import useQuery from '../../stories/hooks/useQuery';
15
14
  import { DAY, now, toUnix } from '../../utils/time';
15
+ import { ISignStakeAndBakeParams, signStakeAndBake } from './signStakeAndBake';
16
16
 
17
17
  const { name } = signStakeAndBake;
18
18
 
@@ -1,15 +1,15 @@
1
+ import BigNumber from 'bignumber.js';
1
2
  import { makeWalletClient } from '../../clients/wallet-client';
2
3
  import { CommonWriteParameters } from '../../common/parameters';
4
+ import { Token } from '../../tokens/token-addresses';
5
+ import { getTokenContractInfo } from '../../tokens/tokens';
6
+ import { DAY, now, toUnix } from '../../utils/time';
3
7
  import {
4
- isVedaVaultStakeAndBakeChain,
5
- Vault,
6
8
  VAULTS,
9
+ Vault,
10
+ isVedaVaultStakeAndBakeChain,
7
11
  } from '../../vaults/lib/config';
8
12
  import { getPermitNonce } from '../getPermitNonce/getPermitNonce';
9
- import BigNumber from 'bignumber.js';
10
- import { DAY, now, toUnix } from '../../utils/time';
11
- import { getTokenContractInfo } from '../../tokens/tokens';
12
- import { Token } from '../../tokens/token-addresses';
13
13
 
14
14
  export interface ISignStakeAndBakeParams extends CommonWriteParameters {
15
15
  /**
@@ -79,7 +79,7 @@ export async function signStakeAndBake({
79
79
  );
80
80
  }
81
81
 
82
- const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
82
+ const lbtcContract = await getTokenContractInfo(Token.LBTC, chainId, env);
83
83
  const walletClient = makeWalletClient({ chainId, provider });
84
84
  const spenderContract = vault.spenderContracts[chainId];
85
85
 
@@ -1,20 +1,20 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
1
  import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+ import { makeTokenSelector } from '../../stories/arg-types';
3
4
  import { Button } from '../../stories/components/Button';
4
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
- import useQuery from '../../stories/hooks/useQuery';
6
- import { redeemToken } from './unstakeLBTC';
7
6
  import { ConnectButton } from '../../stories/components/ConnectButton';
8
- import {
9
- canPerformAction,
10
- useConnection,
11
- } from '../../stories/hooks/useConnection';
12
7
  import {
13
8
  functionType,
14
9
  wagmiDecorator,
15
10
  } from '../../stories/components/decorators';
11
+ import {
12
+ canPerformAction,
13
+ useConnection,
14
+ } from '../../stories/hooks/useConnection';
15
+ import useQuery from '../../stories/hooks/useQuery';
16
16
  import { Token } from '../../tokens/token-addresses';
17
- import { makeTokenSelector } from '../../stories/arg-types';
17
+ import { redeemToken } from './unstakeLBTC';
18
18
 
19
19
  const meta = {
20
20
  title: 'write/unstakeLBTC',
@@ -1,14 +1,14 @@
1
1
  import { getOutputScript } from '@lombard.finance/sdk-common';
2
- import type { CommonWriteParameters } from '../../common/parameters';
3
- import { toSatoshi } from '../../utils/satoshi';
4
- import { makeWalletClient } from '../../clients/wallet-client';
2
+ import BigNumber from 'bignumber.js';
3
+ import { Hex, parseGwei } from 'viem';
5
4
  import { makePublicClient } from '../../clients/public-client';
5
+ import { makeWalletClient } from '../../clients/wallet-client';
6
6
  import { CHAIN_ID_TO_VIEM_CHAIN_MAP, isKatanaChain } from '../../common/chains';
7
- import { type Hex, parseGwei } from 'viem';
8
- import type BigNumber from 'bignumber.js';
9
- import { getTokenContractInfo, isSTLBTCAbi } from '../../tokens/tokens';
7
+ import { CommonWriteParameters } from '../../common/parameters';
10
8
  import { Token } from '../../tokens/token-addresses';
9
+ import { getTokenContractInfo, isUpgradedAbi } from '../../tokens/tokens';
11
10
  import { estimateGasFees } from '../../utils/gas';
11
+ import { toSatoshi } from '../../utils/satoshi';
12
12
 
13
13
  /**
14
14
  * The unstake parameters.
@@ -81,7 +81,7 @@ export async function redeemToken({
81
81
  const publicClient = makePublicClient({ chainId, rpcUrl, env });
82
82
  const walletClient = makeWalletClient({ provider, chainId });
83
83
 
84
- const tokenContract = getTokenContractInfo(token, chainId, env);
84
+ const tokenContract = await getTokenContractInfo(token, chainId, env);
85
85
 
86
86
  const callData = {
87
87
  abi: tokenContract.abi,
@@ -89,9 +89,9 @@ export async function redeemToken({
89
89
  account,
90
90
  chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
91
91
  functionName:
92
- isSTLBTCAbi(tokenContract.abi) || token === Token.NativeLBTC
93
- ? 'redeemForBtc'
94
- : 'redeem', // FIXME: Change this to `redeemForBtc` once all contracts are updated.
92
+ isUpgradedAbi(tokenContract.abi) || token === Token.NativeLBTC
93
+ ? 'redeemForBtc' // upgraded
94
+ : 'redeem', // legacy
95
95
  args: [outputScript, BigInt(amountSat)],
96
96
  } as const;
97
97
 
@@ -1,9 +1,9 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../stories/components/Button';
3
3
  import { CodeBlock } from '../stories/components/CodeBlock';
4
- import useQuery from '../stories/hooks/useQuery';
5
4
  import { functionType, wagmiDecorator } from '../stories/components/decorators';
6
5
  import { ErrorBlock } from '../stories/components/error-block';
6
+ import useQuery from '../stories/hooks/useQuery';
7
7
  import { getLBTCStats } from './get-lbtc-stats';
8
8
  import { envSelector } from '../stories/arg-types';
9
9
  import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
@@ -1,7 +1,7 @@
1
1
  import axios from 'axios';
2
+ import BigNumber from 'bignumber.js';
2
3
  import { getApiConfig } from '../common/api-config';
3
4
  import { IEnvParam } from '../common/parameters';
4
- import BigNumber from 'bignumber.js';
5
5
 
6
6
  type LBTCStatsResponse = { price: number; supply: number; tvl: number }[];
7
7
 
@@ -28,10 +28,11 @@ type Stats = {
28
28
 
29
29
  /** Gets the Lombard's TVL. */
30
30
  export async function getLBTCStats(
31
- parameters?: { partnerId?: string } & IEnvParam,
31
+ parameters?: { partnerId?: string; accountAddress?: string } & IEnvParam,
32
32
  ) {
33
33
  const env = parameters?.env;
34
34
  const partnerId = parameters?.partnerId;
35
+ const accountAddress = parameters?.accountAddress;
35
36
 
36
37
  const { bffApiUrl } = getApiConfig(env);
37
38
  if (!bffApiUrl) {
@@ -55,7 +56,7 @@ export async function getLBTCStats(
55
56
  let apr = undefined;
56
57
  try {
57
58
  const { data: stakingStats } = await axios.get<StakingStatsResponse>(
58
- `${bffApiUrl}/lombard-sdk/staking-stats?partnerId=${partnerId || ''}`,
59
+ `${bffApiUrl}/lombard-sdk/staking-stats?partnerId=${partnerId || ''}&accountAddress=${accountAddress}&env=${env}`,
59
60
  );
60
61
  apr = stakingStats.apr;
61
62
  } catch (_err) {
@@ -4,11 +4,12 @@ import { getApiConfig } from '../common/api-config';
4
4
  import { IEnvParam } from '../common/parameters';
5
5
 
6
6
  type Response = {
7
- type: 'BALANCE_TYPE_DEFI';
7
+ type: 'BALANCE_TYPE_DEFI' | 'BALANCE_TYPE_HOLDING';
8
8
  total_lbtc_balance: number;
9
9
  total_lbtc_balance_cost: number;
10
10
  total_rewards: number;
11
11
  total_rewards_cost: number;
12
+ chains: { lbtc_balance: number; chain: string }[];
12
13
  };
13
14
 
14
15
  /**
@@ -22,7 +23,7 @@ export async function getRewardsInfo({
22
23
  }: { account: Address } & IEnvParam) {
23
24
  const { baseApiUrl } = getApiConfig(env);
24
25
 
25
- const url = `${baseApiUrl}/api/v1/rewards/${account}`;
26
+ const url = `${baseApiUrl}/api/v1/rewards/summary/${account}`;
26
27
  const { data } = await axios.get<Response>(url);
27
28
 
28
29
  return {
@@ -30,5 +31,24 @@ export async function getRewardsInfo({
30
31
  totalLbtcBalance: data.total_lbtc_balance,
31
32
  totalRewards: data.total_rewards,
32
33
  totalRewardsCost: data.total_rewards_cost,
34
+ chains: data.chains?.map(cd => ({
35
+ balance: cd.lbtc_balance,
36
+ chain: cd.chain, // TODO: Map this to chain id.
37
+ })),
33
38
  };
34
39
  }
40
+ // Response example:
41
+ //
42
+ // {
43
+ // "type":"BALANCE_TYPE_HOLDING",
44
+ // "total_lbtc_balance":0.00030997,
45
+ // "total_lbtc_balance_cost":36.906438563500004,
46
+ // "total_rewards":3.278178613395223e-8,
47
+ // "total_rewards_cost":0.0039031486142352624,
48
+ // "chains":[
49
+ // {
50
+ // "lbtc_balance":0.00030997,
51
+ // "chain":"ethereum"
52
+ // }
53
+ // ]
54
+ // }