@lombard.finance/sdk 2.2.0 → 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 +7 -7
  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 +10 -9
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lombard.finance/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -26,14 +26,15 @@
26
26
  "build-docs": "rimraf ./sdk-docs && typedoc --out sdk-docs"
27
27
  },
28
28
  "peerDependencies": {
29
- "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
30
29
  "axios": "^1",
31
30
  "bignumber.js": "^9",
32
- "bitcoinjs-lib": "6.1.5",
33
- "web3": "^4"
31
+ "web3": "^4",
32
+ "bitcoinjs-lib": "6.1.5"
33
+ },
34
+ "dependencies": {
35
+ "@lombard.finance/sdk-common": "*"
34
36
  },
35
37
  "devDependencies": {
36
- "@bitcoin-js/tiny-secp256k1-asmjs": "2.2.3",
37
38
  "@chromatic-com/storybook": "1.6.1",
38
39
  "@storybook/addon-essentials": "^8.2.9",
39
40
  "@storybook/addon-interactions": "^8.2.9",
@@ -45,7 +46,6 @@
45
46
  "@storybook/test": "^8.2.9",
46
47
  "axios": "^1.7.4",
47
48
  "bignumber.js": "^9.1.2",
48
- "bitcoinjs-lib": "6.1.5",
49
49
  "bootstrap": "^5.3.3",
50
50
  "rimraf": "^5",
51
51
  "storybook": "^8.2.9",
@@ -54,4 +54,4 @@
54
54
  "web3": "^4.11.1",
55
55
  "web3-validator": "^2.0.6"
56
56
  }
57
- }
57
+ }
@@ -1,7 +1,3 @@
1
- import { OEnv, TEnv } from './types/types';
2
-
3
- export const defaultEnv: TEnv = OEnv.prod;
4
-
5
1
  /**
6
2
  * Address of the zero account.
7
3
  * Can also be used as a placeholder for unknown addresses.
@@ -1,4 +1,4 @@
1
- import { TEnv } from './types';
1
+ import { Env } from '@lombard.finance/sdk-common';
2
2
 
3
3
  export interface IEnvParam {
4
4
  /**
@@ -6,5 +6,5 @@ export interface IEnvParam {
6
6
  *
7
7
  * @default 'prod'
8
8
  */
9
- env?: TEnv;
9
+ env?: Env;
10
10
  }
@@ -1,10 +1,15 @@
1
- export const OEnv = {
2
- prod: 'prod',
3
- testnet: 'testnet',
4
- stage: 'stage',
5
- } as const;
1
+ import { Env } from '@lombard.finance/sdk-common';
2
+
3
+ export const SUI_DEVNET_CHAIN = 'sui:devnet' as const;
4
+ export const SUI_TESTNET_CHAIN = 'sui:testnet' as const;
5
+ export const SUI_LOCALNET_CHAIN = 'sui:localnet' as const;
6
+ export const SUI_MAINNET_CHAIN = 'sui:mainnet' as const;
6
7
 
7
- export type TEnv = (typeof OEnv)[keyof typeof OEnv];
8
+ export type SuiChain =
9
+ | typeof SUI_DEVNET_CHAIN
10
+ | typeof SUI_TESTNET_CHAIN
11
+ | typeof SUI_LOCALNET_CHAIN
12
+ | typeof SUI_MAINNET_CHAIN;
8
13
 
9
14
  export const OChainId = {
10
15
  ethereum: 1,
@@ -14,13 +19,10 @@ export const OChainId = {
14
19
  sepolia: 11155111,
15
20
  base: 8453,
16
21
  baseSepoliaTestnet: 84532,
17
-
18
22
  berachain: 80094,
19
23
  berachainBartioTestnet: 80084,
20
-
21
24
  corn: 21000000,
22
25
  swell: 1923,
23
-
24
26
  sonic: 146,
25
27
  morph: 2818,
26
28
  morphHolesky: 2810,
@@ -35,13 +37,16 @@ export interface IEIP1193Provider {
35
37
  request: (args: any) => Promise<any>;
36
38
  }
37
39
 
38
- export const getEthNetworkByEnv = (env: TEnv) =>
39
- env === OEnv.prod ? OChainId.ethereum : OChainId.holesky;
40
+ export const getEthNetworkByEnv = (env: Env) =>
41
+ env === Env.prod ? OChainId.ethereum : OChainId.holesky;
40
42
 
41
- export const getBscNetworkByEnv = (env: TEnv) =>
42
- env === OEnv.prod
43
+ export const getBscNetworkByEnv = (env: Env) =>
44
+ env === Env.prod
43
45
  ? OChainId.binanceSmartChain
44
46
  : OChainId.binanceSmartChainTestnet;
45
47
 
46
- export const getBaseNetworkByEnv = (env: TEnv) =>
47
- env === OEnv.prod ? OChainId.base : OChainId.baseSepoliaTestnet;
48
+ export const getBaseNetworkByEnv = (env: Env) =>
49
+ env === Env.prod ? OChainId.base : OChainId.baseSepoliaTestnet;
50
+
51
+ export const getSuiNetworkByEnv = (env: Env) =>
52
+ env === Env.prod ? 'sui:mainnet' : 'sui:testnet';
@@ -1,21 +1,25 @@
1
+ import BigNumber from 'bignumber.js';
2
+
1
3
  const BTC_DECIMALS = 8;
2
- export const SATOSHI_SCALE = 10 ** BTC_DECIMALS;
4
+ export const SATOSHI_SCALE = BigNumber(10).pow(BTC_DECIMALS);
3
5
 
4
6
  /**
5
- * Convert Satoshi to BTC
7
+ * Converts Satoshi to BTC
6
8
  * @param amount - Satoshi amount
7
9
  * @returns BTC amount
8
10
  */
9
- export function fromSatoshi(amount: number | string) {
10
- return +amount / SATOSHI_SCALE;
11
+ export function fromSatoshi(amount: number | string | BigNumber) {
12
+ return BigNumber(amount).dividedBy(SATOSHI_SCALE);
11
13
  }
12
14
 
13
15
  /**
14
- * Convert BTC to Satoshi
16
+ * Converts BTC to Satoshi
15
17
  *
16
18
  * @param amount - BTC amount
17
19
  * @returns Satoshi amount
18
20
  */
19
- export function toSatoshi(amount: number | string) {
20
- return Math.floor(+amount * SATOSHI_SCALE);
21
+ export function toSatoshi(amount: number | string | BigNumber) {
22
+ return BigNumber(amount)
23
+ .multipliedBy(SATOSHI_SCALE)
24
+ .decimalPlaces(0, BigNumber.ROUND_HALF_UP);
21
25
  }
package/src/index.ts CHANGED
@@ -4,3 +4,5 @@ export * from './web3Sdk';
4
4
  export * from './common/types/types';
5
5
  export * from './common/utils/convertSatoshi';
6
6
  export * from './common/utils/isValidChain';
7
+ export type { Env as TEnv } from '@lombard.finance/sdk-common';
8
+ export { Env as OEnv } from '@lombard.finance/sdk-common';
@@ -1,27 +1,31 @@
1
- import { defaultEnv } from '../common/const';
2
- import { OEnv, TEnv } from '../common/types/types';
1
+ import { defaultEnv } from '@lombard.finance/sdk-common';
2
+ import { Env } from '@lombard.finance/sdk-common';
3
3
 
4
4
  interface IApiConfig {
5
5
  baseApiUrl: string;
6
+ bffApiUrl: string | undefined;
6
7
  }
7
8
 
8
9
  const stageConfig: IApiConfig = {
9
10
  baseApiUrl: 'https://staging.prod.lombard.finance',
11
+ bffApiUrl: 'https://bff.stage.lombard.finance',
10
12
  };
11
13
 
12
14
  const testnetConfig: IApiConfig = {
13
15
  baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',
16
+ bffApiUrl: undefined,
14
17
  };
15
18
 
16
19
  const prodConfig: IApiConfig = {
17
20
  baseApiUrl: 'https://mainnet.prod.lombard.finance',
21
+ bffApiUrl: 'https://bff.prod.lombard.finance',
18
22
  };
19
23
 
20
- export const getApiConfig = (env: TEnv = defaultEnv): IApiConfig => {
24
+ export const getApiConfig = (env: Env = defaultEnv): IApiConfig => {
21
25
  switch (env) {
22
- case OEnv.prod:
26
+ case Env.prod:
23
27
  return prodConfig;
24
- case OEnv.testnet:
28
+ case Env.testnet:
25
29
  return testnetConfig;
26
30
  default:
27
31
  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 { OChainId } from '../../common/types/types';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { IEnvParam } from '../../common/types/internalTypes';
3
- import { TChainId } from '../../common/types/types';
3
+ import { SuiChain, TChainId } from '../../common/types/types';
4
4
  import { getErrorMessage } from '../../common/utils/getErrorMessage';
5
5
  import { getApiConfig } from '../apiConfig';
6
6
  import { getChainNameById } from '../utils/getChainNameById';
@@ -24,7 +24,7 @@ export interface IGenerateDepositBtcAddressParams extends IEnvParam {
24
24
  /**
25
25
  * The destination chain ID where LBTC will be claimed.
26
26
  */
27
- chainId: TChainId;
27
+ chainId: TChainId | SuiChain;
28
28
  /**
29
29
  * The signature of the address. The signature is generated by signing the address using EVM wallet.
30
30
  */
@@ -105,5 +105,5 @@ export async function generateDepositBtcAddress({
105
105
  }
106
106
 
107
107
  function isSanctioned(errorMsg: string): boolean {
108
- return !!errorMsg.includes(SANCTIONS_MESSAGE);
108
+ return errorMsg.includes(SANCTIONS_MESSAGE);
109
109
  }
@@ -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 { OChainId } from '../../common/types/types';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
@@ -40,8 +40,6 @@ export function StoryView(props: IGetDepositBtcAddressParams) {
40
40
  false,
41
41
  );
42
42
 
43
- const test = true;
44
-
45
43
  return (
46
44
  <>
47
45
  <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
@@ -1,6 +1,6 @@
1
1
  import axios from 'axios';
2
2
  import { IEnvParam } from '../../common/types/internalTypes';
3
- import { TChainId } from '../../common/types/types';
3
+ import { SuiChain, TChainId } from '../../common/types/types';
4
4
  import { getApiConfig } from '../apiConfig';
5
5
  import { TChainName } from '../internalTypes';
6
6
  import { getChainNameById } from '../utils/getChainNameById';
@@ -36,7 +36,7 @@ export interface IGetDepositBtcAddressParams extends IEnvParam {
36
36
  /**
37
37
  * The destination chain ID where LBTC will be claimed.
38
38
  */
39
- chainId: TChainId;
39
+ chainId: TChainId | SuiChain;
40
40
  /**
41
41
  * The referral ID.
42
42
  */
@@ -111,7 +111,7 @@ export async function getDepositBtcAddresses({
111
111
  const { baseApiUrl } = getApiConfig(env);
112
112
  const toBlockchain = getChainNameById(chainId);
113
113
 
114
- const requestrParams = {
114
+ const requestParams = {
115
115
  to_address: address,
116
116
  to_blockchain: toBlockchain,
117
117
  limit: 1,
@@ -122,7 +122,7 @@ export async function getDepositBtcAddresses({
122
122
 
123
123
  const { data } = await axios.get<IDepositAddressesResponse>(ADDRESS_URL, {
124
124
  baseURL: baseApiUrl,
125
- params: requestrParams,
125
+ params: requestParams,
126
126
  });
127
127
 
128
128
  return data?.addresses || [];
@@ -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 { exampleEvmAddress } from '../../stories/const';
@@ -1,10 +1,11 @@
1
1
  import axios from 'axios';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { IEnvParam } from '../../common/types/internalTypes';
4
- import { TChainId, TEnv } from '../../common/types/types';
4
+ import { SuiChain, TChainId } from '../../common/types/types';
5
5
  import { fromSatoshi } from '../../common/utils/convertSatoshi';
6
6
  import { getApiConfig } from '../apiConfig';
7
7
  import { getChainIdByName } from '../utils/getChainIdByName';
8
+ import { Env } from '@lombard.finance/sdk-common';
8
9
 
9
10
  type Address = string;
10
11
  type Seconds = number;
@@ -59,7 +60,7 @@ export interface IDeposit {
59
60
  blockTime?: number;
60
61
  value: BigNumber;
61
62
  address: Address;
62
- chainId: TChainId;
63
+ chainId: TChainId | SuiChain;
63
64
  isClaimed?: boolean;
64
65
  claimedTxId?: string;
65
66
  rawPayload?: string;
@@ -107,7 +108,7 @@ export async function getDepositsByAddress({
107
108
  return outputs.map(mapResponse(env));
108
109
  }
109
110
 
110
- function mapResponse(env?: TEnv) {
111
+ function mapResponse(env?: Env) {
111
112
  return (data: IDepositResponse): IDeposit => ({
112
113
  txid: data.txid,
113
114
  index: data.index ?? 0,
@@ -1,12 +1,12 @@
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 { OChainId } from '../../common/types/types';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import { CodeBlock } from '../../stories/components/CodeBlock';
6
6
  import useQuery from '../../stories/hooks/useQuery';
7
7
  import {
8
- getLBTCExchangeRate,
9
- IgetLBTCExchangeRateParams,
8
+ getLBTCExchangeRate,
9
+ IgetLBTCExchangeRateParams,
10
10
  } from './getLBTCExchangeRate';
11
11
 
12
12
  const meta = {
@@ -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
  getNetworkFeeSignature,
8
9
  IGetNetworkFeeSignatureParams,
9
10
  } from './getNetworkFeeSignature';
10
- import { defaultEnv } from '../../common/const';
11
11
 
12
12
  const meta = {
13
13
  title: 'SDK/getNetworkFeeSignature',
@@ -0,0 +1,49 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { defaultEnv } from '@lombard.finance/sdk-common';
3
+ import { Button } from '../../stories/components/Button';
4
+ import { CodeBlock } from '../../stories/components/CodeBlock';
5
+ import { exampleEvmAddress } from '../../stories/const';
6
+ import useQuery from '../../stories/hooks/useQuery';
7
+ import { fromCamelCase } from '../../stories/utils/fromCamelCase';
8
+ import {
9
+ getPointsByAddress,
10
+ IGetPointsByAddressParameters,
11
+ } from './getPointsByAddress';
12
+
13
+ const { name } = getPointsByAddress;
14
+ const nameWithWhitespaces = fromCamelCase(name);
15
+
16
+ const meta = {
17
+ title: 'SDK/getPointsByAddress',
18
+ component: StoryView,
19
+ tags: ['autodocs'],
20
+ } satisfies Meta<typeof StoryView>;
21
+
22
+ export default meta;
23
+
24
+ type Story = StoryObj<typeof meta>;
25
+
26
+ export const WithParams: Story = {
27
+ args: {
28
+ address: exampleEvmAddress,
29
+ env: defaultEnv,
30
+ },
31
+ };
32
+
33
+ export function StoryView(props: IGetPointsByAddressParameters) {
34
+ const { data, error, isLoading, refetch } = useQuery(
35
+ () => getPointsByAddress(props),
36
+ [props],
37
+ false,
38
+ );
39
+
40
+ return (
41
+ <>
42
+ <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
43
+ {nameWithWhitespaces}
44
+ </Button>
45
+
46
+ <CodeBlock text={error || data} />
47
+ </>
48
+ );
49
+ }
@@ -0,0 +1,163 @@
1
+ import axios from 'axios';
2
+ import { defaultEnv } from '@lombard.finance/sdk-common';
3
+ import { IEnvParam } from '../../common/types/internalTypes';
4
+ import { getApiConfig } from '../apiConfig';
5
+
6
+ export interface IGetPointsByAddressParameters extends IEnvParam {
7
+ /**
8
+ * The address of the points earner.
9
+ */
10
+ address: string;
11
+ }
12
+
13
+ export interface IProtocolPointsBreakdown {
14
+ [protocolIdentifier: string]: number;
15
+ }
16
+
17
+ export interface IPointsByAddress {
18
+ /**
19
+ * The number of points earned by holding LBTC.
20
+ */
21
+ holdingPoints: number;
22
+ /**
23
+ * The number of points earned by taking positions in DeFi vaults.
24
+ */
25
+ protocolPoints: number;
26
+ /**
27
+ * The number of points earned by your referrals.
28
+ */
29
+ referralPoints: number;
30
+ /**
31
+ * The number of points earned in the OKX campaign.
32
+ */
33
+ okxPoints: number;
34
+ /**
35
+ * The number of points earned by participating in the flash events.
36
+ */
37
+ flashEventPoints: number;
38
+ /**
39
+ * The total number of points.
40
+ */
41
+ totalPoints: number;
42
+ /**
43
+ * The breakdown of points earned from each protocol.
44
+ */
45
+ protocolPointsBreakdown: IProtocolPointsBreakdown;
46
+ }
47
+
48
+ interface IPointsResponse {
49
+ holding_points?: number;
50
+ protocol_points?: number;
51
+ referee_points?: number;
52
+ referrals_points?: number;
53
+ total?: number;
54
+ protocol_points_map?: IProtocolPointsBreakdown;
55
+ }
56
+
57
+ interface IOkxPointsResponse {
58
+ data: boolean;
59
+ points?: string | number;
60
+ }
61
+
62
+ interface IFlashEventPointsResponse {
63
+ flashEvent1Points?: {
64
+ result?: {
65
+ rows?: { points?: string }[]; // take first entry
66
+ };
67
+ };
68
+ flashEvent2Points?: {
69
+ result?: {
70
+ rows?: { totalPoints?: string }[]; // take first entry
71
+ };
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Retrieves the points earned by the provided address.
77
+ * @param {IGetPointsByAddressParameters} parameters
78
+ * @throws {Error} - Throws an error when the API endpoints cannot be determined or any of the API calls fail.
79
+ */
80
+ export async function getPointsByAddress({
81
+ address,
82
+ env,
83
+ }: IGetPointsByAddressParameters): Promise<IPointsByAddress> {
84
+ const { baseApiUrl, bffApiUrl } = getApiConfig(env);
85
+ if (!bffApiUrl || !baseApiUrl) {
86
+ throw new Error(
87
+ `Could not determine the API endpoint for the provided environment: ${env || defaultEnv}`,
88
+ );
89
+ }
90
+
91
+ const lombardPointsUrl = `${baseApiUrl}/api/v1/referral-system/season-1/points/${address}`;
92
+
93
+ /**
94
+ * TODO:
95
+ * OKX and flash event points will be a part of the above endpoint soon.
96
+ * Change this once it is implemented on the backend.
97
+ */
98
+
99
+ const okxPointsUrl = `${baseApiUrl}/api/v1/task/okx/user-task-verification?address=${address}&chain=1`;
100
+ const flashEventsPointsUrl = `${bffApiUrl}/sentio-api/flash-event-points/${address}`;
101
+
102
+ const lombardPointsRequest = axios.get<IPointsResponse>(lombardPointsUrl);
103
+ const okxPointsRequest = axios.get<IOkxPointsResponse>(okxPointsUrl);
104
+ const flashEventPointsRequest =
105
+ axios.get<IFlashEventPointsResponse>(flashEventsPointsUrl);
106
+
107
+ const [
108
+ { data: lombardPointsData },
109
+ { data: okxPointsData },
110
+ { data: flashEventPointsData },
111
+ ] = await Promise.all([
112
+ lombardPointsRequest,
113
+ okxPointsRequest,
114
+ flashEventPointsRequest,
115
+ ]);
116
+
117
+ const okxPoints = parse(okxPointsData?.points);
118
+
119
+ const flashEvent1Points = parse(
120
+ flashEventPointsData?.flashEvent1Points?.result?.rows?.[0]?.points,
121
+ );
122
+ const flashEvent2Points = parse(
123
+ flashEventPointsData?.flashEvent2Points?.result?.rows?.[0]?.totalPoints,
124
+ );
125
+ const flashEventPoints = flashEvent1Points + flashEvent2Points;
126
+
127
+ const holdingPoints = parse(lombardPointsData.holding_points);
128
+ const protocolPoints = parse(lombardPointsData.protocol_points);
129
+ const referralPoints =
130
+ parse(lombardPointsData.referee_points) +
131
+ parse(lombardPointsData.referrals_points);
132
+
133
+ const totalPoints =
134
+ holdingPoints +
135
+ protocolPoints +
136
+ referralPoints +
137
+ okxPoints +
138
+ flashEventPoints;
139
+
140
+ const protocolPointsBreakdown = Object.entries(
141
+ lombardPointsData.protocol_points_map || {},
142
+ ).reduce((acc, [k, v]) => {
143
+ acc[k] = parse(v);
144
+ return acc;
145
+ }, {} as IProtocolPointsBreakdown);
146
+
147
+ return {
148
+ holdingPoints,
149
+ protocolPoints,
150
+ referralPoints,
151
+ okxPoints,
152
+ flashEventPoints,
153
+ totalPoints,
154
+ protocolPointsBreakdown,
155
+ };
156
+ }
157
+
158
+ function parse(
159
+ input: string | number | null | undefined,
160
+ defaultValue = 0,
161
+ ): number {
162
+ return Number(input) || defaultValue;
163
+ }
@@ -0,0 +1,6 @@
1
+ export {
2
+ getPointsByAddress,
3
+ type IGetPointsByAddressParameters,
4
+ type IPointsByAddress,
5
+ type IProtocolPointsBreakdown,
6
+ } from './getPointsByAddress';
@@ -0,0 +1,49 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { defaultEnv } from '@lombard.finance/sdk-common';
3
+ import { Button } from '../../stories/components/Button';
4
+ import { CodeBlock } from '../../stories/components/CodeBlock';
5
+ import { exampleEvmAddress } from '../../stories/const';
6
+ import useQuery from '../../stories/hooks/useQuery';
7
+ import { fromCamelCase } from '../../stories/utils/fromCamelCase';
8
+ import {
9
+ getUnstakesByAddress,
10
+ IGetUnstakesByAddressParameters,
11
+ } from './getUnstakesByAddress';
12
+
13
+ const { name } = getUnstakesByAddress;
14
+ const nameWithWhitespaces = fromCamelCase(name);
15
+
16
+ const meta = {
17
+ title: 'SDK/getUnstakesByAddress',
18
+ component: StoryView,
19
+ tags: ['autodocs'],
20
+ } satisfies Meta<typeof StoryView>;
21
+
22
+ export default meta;
23
+
24
+ type Story = StoryObj<typeof meta>;
25
+
26
+ export const WithParams: Story = {
27
+ args: {
28
+ address: exampleEvmAddress,
29
+ env: defaultEnv,
30
+ },
31
+ };
32
+
33
+ export function StoryView(parameters: IGetUnstakesByAddressParameters) {
34
+ const { data, error, isLoading, refetch } = useQuery(
35
+ () => getUnstakesByAddress(parameters),
36
+ [parameters],
37
+ false,
38
+ );
39
+
40
+ return (
41
+ <>
42
+ <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
43
+ {nameWithWhitespaces}
44
+ </Button>
45
+
46
+ <CodeBlock text={error || data} />
47
+ </>
48
+ );
49
+ }