@lombard.finance/sdk 2.1.2 → 2.2.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,61 @@
1
+ import axios from 'axios';
2
+ import { IEnvParam } from '../../common/types/internalTypes';
3
+ import { getErrorMessage } from '../../common/utils/getErrorMessage';
4
+ import { getApiConfig } from '../apiConfig';
5
+
6
+ const URL = 'api/v1/referral-system/referrer/';
7
+
8
+ interface ISetReferrerResponse {}
9
+
10
+ export interface ISetReferralParams extends IEnvParam {
11
+ /**
12
+ * The destination EVM user address where LBTC will be claimed.
13
+ */
14
+ address: string;
15
+ /**
16
+ * The signature of the address. The signature is generated by signing the address using EVM wallet.
17
+ */
18
+ 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
+ /**
24
+ * The captcha token.
25
+ */
26
+ referrerCode: string;
27
+ }
28
+
29
+ /**
30
+ * Set a referral code.
31
+ *
32
+ * @param {ISetReferralParams} The parameters for set referral.
33
+ * @returns {Promise<void>} Nothing.
34
+ * @exception {Error}
35
+ */
36
+ export async function setReferral({
37
+ address,
38
+ signature,
39
+ eip712Data,
40
+ referrerCode,
41
+ env,
42
+ }: ISetReferralParams): Promise<void> {
43
+ const { baseApiUrl } = getApiConfig(env);
44
+
45
+ const requestParams = {
46
+ referrer_code: referrerCode,
47
+ signature,
48
+ signature_typed_data: eip712Data,
49
+ };
50
+
51
+ try {
52
+ await axios.post<ISetReferrerResponse>(`${URL}${address}`, requestParams, {
53
+ baseURL: baseApiUrl,
54
+ });
55
+
56
+ return undefined;
57
+ } catch (error) {
58
+ const errorMsg = getErrorMessage(error);
59
+ throw new Error(errorMsg);
60
+ }
61
+ }
@@ -1,5 +1,4 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { OEnv } from '../../common/types/types';
3
2
  import { Button } from '../../stories/components/Button';
4
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
4
  import { useConnect } from '../../stories/hooks/useConnect';
@@ -8,6 +7,7 @@ import {
8
7
  IStoreNetworkFeeSignatureParams,
9
8
  storeNetworkFeeSignature,
10
9
  } from './storeNetworkFeeSignature';
10
+ import { defaultEnv } from '../../common/const';
11
11
 
12
12
  const meta = {
13
13
  title: 'SDK/storeNetworkFeeSignature',
@@ -21,7 +21,7 @@ type Story = StoryObj<typeof meta>;
21
21
 
22
22
  export const WithParams: Story = {
23
23
  args: {
24
- env: OEnv.stage,
24
+ env: defaultEnv,
25
25
  },
26
26
  };
27
27
 
@@ -1,5 +1,4 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { OEnv } from '../../common/types/types';
3
2
  import { Button } from '../../stories/components/Button';
4
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
4
  import { useConnect } from '../../stories/hooks/useConnect';
@@ -10,6 +9,7 @@ import {
10
9
  signStakeAndBake,
11
10
  } from '../../web3Sdk/signStakeAndBake/signStakeAndBake';
12
11
  import { storeStakeAndBakeSignature } from './storeStakeAndBakeSignature';
12
+ import { defaultEnv } from '../../common/const';
13
13
 
14
14
  const meta = {
15
15
  title: 'SDK/storeStakeAndBakeSignature',
@@ -61,7 +61,7 @@ export function StoryView(props: SignStakeAndBakeParams) {
61
61
  await storeStakeAndBakeSignature({
62
62
  signature,
63
63
  typedData,
64
- env: OEnv.stage,
64
+ env: defaultEnv,
65
65
  });
66
66
 
67
67
  return { signature, typedData };
@@ -0,0 +1,15 @@
1
+ [
2
+ {
3
+ "inputs": [],
4
+ "name": "getStakeAndBakeFee",
5
+ "outputs": [
6
+ {
7
+ "internalType": "uint256",
8
+ "name": "",
9
+ "type": "uint256"
10
+ }
11
+ ],
12
+ "stateMutability": "view",
13
+ "type": "function"
14
+ }
15
+ ]
@@ -1,5 +1,6 @@
1
1
  import IERC20 from './IERC20.json';
2
2
  import LBTCABI from './LBTC.json';
3
3
  import BASCULE_ABI from './BASCULE.json';
4
+ import STAKE_AND_BAKE from './STAKE_AND_BAKE.json';
4
5
 
5
- export { IERC20, LBTCABI, BASCULE_ABI };
6
+ export { IERC20, LBTCABI, BASCULE_ABI, STAKE_AND_BAKE };
@@ -7,53 +7,72 @@ import { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';
7
7
  type BasculeTokenConfig = Record<TChainId, string>;
8
8
 
9
9
  const stageConfig: BasculeTokenConfig = {
10
- [OChainId.holesky]: '0x3a0c40c84b5034ed9a98a9a47a02af2b0885246f',
11
10
  [OChainId.ethereum]: PLACEHOLDER_ADDRESS,
11
+ [OChainId.holesky]: '0x3a0c40c84b5034ed9a98a9a47a02af2b0885246f',
12
+ [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
12
13
 
13
- [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
14
14
  [OChainId.binanceSmartChain]: PLACEHOLDER_ADDRESS,
15
+ [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
15
16
 
16
17
  [OChainId.base]: PLACEHOLDER_ADDRESS,
17
18
  [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
18
19
 
20
+ [OChainId.berachain]: PLACEHOLDER_ADDRESS,
19
21
  [OChainId.berachainBartioTestnet]: PLACEHOLDER_ADDRESS,
20
- [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
22
+
21
23
  [OChainId.corn]: PLACEHOLDER_ADDRESS,
22
24
 
23
25
  [OChainId.swell]: PLACEHOLDER_ADDRESS,
26
+
27
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
28
+ [OChainId.morph]: PLACEHOLDER_ADDRESS,
29
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
24
30
  };
25
31
 
26
32
  const testnetConfig: BasculeTokenConfig = {
27
- [OChainId.holesky]: '0x3a0c40c84b5034ed9a98a9a47a02af2b0885246f',
28
33
  [OChainId.ethereum]: PLACEHOLDER_ADDRESS,
34
+ [OChainId.holesky]: '0x3a0c40c84b5034ed9a98a9a47a02af2b0885246f',
35
+ [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
29
36
 
30
- [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
31
37
  [OChainId.binanceSmartChain]: PLACEHOLDER_ADDRESS,
38
+ [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
32
39
 
33
40
  [OChainId.base]: PLACEHOLDER_ADDRESS,
34
41
  [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
35
42
 
43
+ [OChainId.berachain]: PLACEHOLDER_ADDRESS,
36
44
  [OChainId.berachainBartioTestnet]: PLACEHOLDER_ADDRESS,
37
- [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
45
+
38
46
  [OChainId.corn]: PLACEHOLDER_ADDRESS,
39
47
 
40
48
  [OChainId.swell]: PLACEHOLDER_ADDRESS,
49
+
50
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
51
+ [OChainId.morph]: PLACEHOLDER_ADDRESS,
52
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
41
53
  };
42
54
 
43
55
  const prodConfig: BasculeTokenConfig = {
44
- [OChainId.holesky]: PLACEHOLDER_ADDRESS,
45
56
  [OChainId.ethereum]: '0xc750eCAC7250E0D18ecE2C7a5F130E3A765dc260',
57
+ [OChainId.holesky]: PLACEHOLDER_ADDRESS,
58
+ [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
46
59
 
47
- [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
48
60
  [OChainId.binanceSmartChain]: PLACEHOLDER_ADDRESS,
61
+ [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
49
62
 
50
63
  [OChainId.base]: PLACEHOLDER_ADDRESS,
51
64
  [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
52
65
 
66
+ [OChainId.berachain]: PLACEHOLDER_ADDRESS,
53
67
  [OChainId.berachainBartioTestnet]: PLACEHOLDER_ADDRESS,
54
- [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
68
+
55
69
  [OChainId.corn]: PLACEHOLDER_ADDRESS,
70
+
56
71
  [OChainId.swell]: PLACEHOLDER_ADDRESS,
72
+
73
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
74
+ [OChainId.morph]: PLACEHOLDER_ADDRESS,
75
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
57
76
  };
58
77
 
59
78
  export function getBasculeAddressConfig(
@@ -0,0 +1,64 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { OChainId } from '../../common/types/types';
4
+ import { Button } from '../../stories/components/Button';
5
+ import { CodeBlock } from '../../stories/components/CodeBlock';
6
+ import useQuery from '../../stories/hooks/useQuery';
7
+ import {
8
+ getStakeAndBakeFee,
9
+ IGetStakeAndBakeFeeParams,
10
+ } from './getStakeAndBakeFee';
11
+ import BigNumber from 'bignumber.js';
12
+ import { fromSatoshi } from '../../common/utils/convertSatoshi';
13
+
14
+ const meta = {
15
+ title: 'Web3SDK/getStakeAndBakeFee',
16
+ component: StoryView,
17
+ tags: ['autodocs'],
18
+ } satisfies Meta<typeof StoryView>;
19
+
20
+ export default meta;
21
+
22
+ type Story = StoryObj<typeof meta>;
23
+
24
+ export const WithParams: Story = {
25
+ args: {
26
+ chainId: OChainId.binanceSmartChain,
27
+ rpcUrl: 'https://rpc.ankr.com/bsc',
28
+ vaultAddress: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
29
+ },
30
+ };
31
+
32
+ type GetStakeAndBakeFeeProps = Pick<
33
+ IGetStakeAndBakeFeeParams,
34
+ 'chainId' | 'rpcUrl' | 'vaultAddress'
35
+ >;
36
+
37
+ export function StoryView(props: GetStakeAndBakeFeeProps) {
38
+ const request = async () => {
39
+ return getStakeAndBakeFee({
40
+ ...props,
41
+ });
42
+ };
43
+
44
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
45
+
46
+ const value = new BigNumber(fromSatoshi(data || 0)).toString();
47
+
48
+ return (
49
+ <div>
50
+ <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
51
+ Get Stake and Bake Fee
52
+ </Button>
53
+
54
+ <CodeBlock text={error || data?.toString()} />
55
+
56
+ {data && (
57
+ <div className="mt-4 p-4 border rounded">
58
+ <h3 className="text-lg font-bold mb-2">Fee Details</h3>
59
+ <p>Stake and Bak Fee: {value} LBTC</p>
60
+ </div>
61
+ )}
62
+ </div>
63
+ );
64
+ }
@@ -0,0 +1,48 @@
1
+ import { TChainId } from '../../common/types/types';
2
+ import { ReadProvider } from '../../provider/ReadProvider';
3
+ import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
4
+ import { STAKE_AND_BAKE } from '../abi';
5
+ import { getErrorMessage } from '../../common/utils/getErrorMessage';
6
+
7
+ export interface IGetStakeAndBakeFeeParams {
8
+ /**
9
+ * Chain ID
10
+ */
11
+ chainId: TChainId;
12
+ /**
13
+ * RPC URL
14
+ */
15
+ rpcUrl?: string;
16
+ /**
17
+ * Vault Address
18
+ */
19
+ vaultAddress: string;
20
+ }
21
+
22
+ /**
23
+ * Get Stake and bake fee.
24
+ *
25
+ * @param chainId - Chain ID
26
+ * @param rpcUrl - RPC URL (optional)
27
+ * @param vaultAddress - Vault Address
28
+ *
29
+ * @returns Stake and bake fee in satoshis
30
+ */
31
+ export async function getStakeAndBakeFee({
32
+ chainId,
33
+ rpcUrl,
34
+ vaultAddress,
35
+ }: IGetStakeAndBakeFeeParams): Promise<string> {
36
+ const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
37
+ const provider = new ReadProvider({ chainId, rpcUrlConfig });
38
+
39
+ try {
40
+ const contract = provider.createContract(STAKE_AND_BAKE, vaultAddress);
41
+
42
+ const fee: bigint = await contract.methods.getStakeAndBakeFee().call();
43
+ return fee.toString();
44
+ } catch (error) {
45
+ const errorMessage = getErrorMessage(error);
46
+ throw new Error(errorMessage);
47
+ }
48
+ }
@@ -0,0 +1 @@
1
+ export * from './getStakeAndBakeFee';
@@ -12,3 +12,4 @@ export * from './types';
12
12
  export * from './unstakeLBTC';
13
13
  export * from './getBasculeDepositStatus';
14
14
  export * from './getLBTCTotalSupply';
15
+ export * from './getStakeAndBakeFee';
@@ -17,12 +17,17 @@ const stageConfig: LbtcTokenConfig = {
17
17
 
18
18
  [OChainId.base]: PLACEHOLDER_ADDRESS,
19
19
  [OChainId.baseSepoliaTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
20
-
20
+
21
+ [OChainId.berachain]: PLACEHOLDER_ADDRESS,
21
22
  [OChainId.berachainBartioTestnet]:
22
23
  '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
23
24
 
24
25
  [OChainId.corn]: PLACEHOLDER_ADDRESS,
25
26
  [OChainId.swell]: PLACEHOLDER_ADDRESS,
27
+
28
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
29
+ [OChainId.morph]: PLACEHOLDER_ADDRESS,
30
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
26
31
  };
27
32
 
28
33
  const testnetConfig: LbtcTokenConfig = {
@@ -36,11 +41,17 @@ const testnetConfig: LbtcTokenConfig = {
36
41
 
37
42
  [OChainId.base]: PLACEHOLDER_ADDRESS,
38
43
  [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
44
+
45
+ [OChainId.berachain]: PLACEHOLDER_ADDRESS,
39
46
  [OChainId.berachainBartioTestnet]:
40
47
  '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
41
48
 
42
49
  [OChainId.corn]: PLACEHOLDER_ADDRESS,
43
50
  [OChainId.swell]: PLACEHOLDER_ADDRESS,
51
+
52
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
53
+ [OChainId.morph]: PLACEHOLDER_ADDRESS,
54
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
44
55
  };
45
56
 
46
57
  const prodConfig: LbtcTokenConfig = {
@@ -54,10 +65,15 @@ const prodConfig: LbtcTokenConfig = {
54
65
  [OChainId.base]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
55
66
  [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
56
67
 
68
+ [OChainId.berachain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
57
69
  [OChainId.berachainBartioTestnet]: PLACEHOLDER_ADDRESS,
58
70
 
59
71
  [OChainId.corn]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
60
72
  [OChainId.swell]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
73
+
74
+ [OChainId.sonic]: PLACEHOLDER_ADDRESS,
75
+ [OChainId.morph]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
76
+ [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
61
77
  };
62
78
 
63
79
  export function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {
@@ -1,5 +1,4 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
- import { OEnv } from '../../common/types/types';
3
2
  import { Button } from '../../stories/components/Button';
4
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
4
  import { useConnect } from '../../stories/hooks/useConnect';
@@ -7,6 +6,7 @@ import useQuery from '../../stories/hooks/useQuery';
7
6
  import { fromCamelCase } from '../../stories/utils/fromCamelCase';
8
7
  import { MS_PER_DAY } from '../const';
9
8
  import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
9
+ import { defaultEnv } from '../../common/const';
10
10
 
11
11
  const { name } = signNetworkFee;
12
12
  const nameWithWhitespaces = fromCamelCase(name);
@@ -23,7 +23,7 @@ type Story = StoryObj<typeof meta>;
23
23
 
24
24
  export const WithParams: Story = {
25
25
  args: {
26
- env: OEnv.stage,
26
+ env: defaultEnv,
27
27
  },
28
28
  };
29
29
 
@@ -23,13 +23,13 @@ export const STAKE_AND_BAKE_VAULTS: Record<number, IStakeAndBakeVault[]> = {
23
23
  address: '0x4A3cD83CEbb91E0Cd31EdA2Ee0F4AebfcCFCbBb6',
24
24
  },
25
25
  ],
26
- // [OChainId.ethereum]: [
27
- // {
28
- // key: 'veda',
29
- // name: 'Veda / Lombard DeFi Vault',
30
- // address: '0x5401b8620e5fb570064ca9114fd1e135fd77d57c',
31
- // },
32
- // ],
26
+ [OChainId.ethereum]: [
27
+ {
28
+ key: 'veda',
29
+ name: 'Veda / Lombard DeFi Vault',
30
+ address: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
31
+ },
32
+ ],
33
33
  [OChainId.binanceSmartChain]: [
34
34
  {
35
35
  key: 'veda',
@@ -44,13 +44,6 @@ export const STAKE_AND_BAKE_VAULTS: Record<number, IStakeAndBakeVault[]> = {
44
44
  address: '0x72143309A662bDB4aad5cA65Ab59eD8977D047C5',
45
45
  },
46
46
  ],
47
- // [OChainId.base]: [
48
- // {
49
- // key: 'veda',
50
- // name: 'Veda / Lombard DeFi Vault',
51
- // address: '0x5401b8620e5fb570064ca9114fd1e135fd77d57c',
52
- // },
53
- // ],
54
47
  } as const;
55
48
 
56
49
  export const SUPPORTED_STAKE_AND_BAKE_CHAINS = Object.keys(