@swapkit/helpers 3.0.0-beta.11 → 3.0.0-beta.12

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/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +5 -5
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +5 -5
  5. package/dist/{chunk-kr69v1tm.js → chunk-2vqx8ecy.js} +1 -1
  6. package/dist/{chunk-fr86y3rx.js → chunk-3ts9cha8.js} +1 -1
  7. package/dist/{chunk-wrjh857m.js → chunk-4edjz16h.js} +1 -1
  8. package/dist/{chunk-mmwvr2y8.js → chunk-4mz4n5jc.js} +1 -1
  9. package/dist/{chunk-kdcsgh3q.js → chunk-c4ndre32.js} +1 -1
  10. package/dist/{chunk-ekd1k975.js → chunk-frkpmajq.js} +1 -1
  11. package/dist/{chunk-3wnfcm30.js → chunk-ganzk321.js} +1 -1
  12. package/dist/{chunk-3wnfcm30.js.map → chunk-ganzk321.js.map} +1 -1
  13. package/dist/{chunk-ahpfxkx0.js → chunk-hbnf5tky.js} +1 -1
  14. package/dist/{chunk-6vvdbb6s.js → chunk-hk0jx7rp.js} +1 -1
  15. package/dist/{chunk-dbsrwnw2.js → chunk-k2m9hvag.js} +1 -1
  16. package/dist/{chunk-wmxwvv8c.js → chunk-mt3sdnfg.js} +1 -1
  17. package/dist/{chunk-tq87xn7m.js → chunk-prm0g9b0.js} +1 -1
  18. package/dist/{chunk-q8xy3739.js → chunk-qkreqkaa.js} +1 -1
  19. package/dist/{chunk-xyczdrny.js → chunk-qpz3c078.js} +1 -1
  20. package/dist/{chunk-z8emzpyc.js → chunk-zv69dnwn.js} +1 -1
  21. package/dist/contracts/index.js +1 -1
  22. package/dist/index.cjs +3 -3
  23. package/dist/index.cjs.map +6 -6
  24. package/dist/index.js +3 -3
  25. package/dist/index.js.map +6 -6
  26. package/dist/tokens/index.js +1 -1
  27. package/package.json +2 -2
  28. package/src/api/microgard/types.ts +0 -3
  29. package/src/api/midgard/endpoints.ts +48 -71
  30. package/src/api/midgard/types.ts +0 -49
  31. package/src/api/swapkitApi/endpoints.ts +24 -8
  32. package/src/api/thornode/endpoints.ts +26 -8
  33. package/src/modules/swapKitConfig.ts +29 -1
  34. package/src/types/quotes.ts +0 -2
  35. package/src/types/sdk.ts +0 -2
  36. package/src/utils/__tests__/memo.test.ts +0 -20
  37. package/src/utils/memo.ts +0 -31
  38. /package/dist/{chunk-kr69v1tm.js.map → chunk-2vqx8ecy.js.map} +0 -0
  39. /package/dist/{chunk-fr86y3rx.js.map → chunk-3ts9cha8.js.map} +0 -0
  40. /package/dist/{chunk-wrjh857m.js.map → chunk-4edjz16h.js.map} +0 -0
  41. /package/dist/{chunk-mmwvr2y8.js.map → chunk-4mz4n5jc.js.map} +0 -0
  42. /package/dist/{chunk-kdcsgh3q.js.map → chunk-c4ndre32.js.map} +0 -0
  43. /package/dist/{chunk-ekd1k975.js.map → chunk-frkpmajq.js.map} +0 -0
  44. /package/dist/{chunk-ahpfxkx0.js.map → chunk-hbnf5tky.js.map} +0 -0
  45. /package/dist/{chunk-6vvdbb6s.js.map → chunk-hk0jx7rp.js.map} +0 -0
  46. /package/dist/{chunk-dbsrwnw2.js.map → chunk-k2m9hvag.js.map} +0 -0
  47. /package/dist/{chunk-wmxwvv8c.js.map → chunk-mt3sdnfg.js.map} +0 -0
  48. /package/dist/{chunk-tq87xn7m.js.map → chunk-prm0g9b0.js.map} +0 -0
  49. /package/dist/{chunk-q8xy3739.js.map → chunk-qkreqkaa.js.map} +0 -0
  50. /package/dist/{chunk-xyczdrny.js.map → chunk-qpz3c078.js.map} +0 -0
  51. /package/dist/{chunk-z8emzpyc.js.map → chunk-zv69dnwn.js.map} +0 -0
@@ -1,14 +1,45 @@
1
- import { AssetValue, BaseDecimal, Chain, RequestClient, SwapKitNumber } from "@swapkit/helpers";
2
- import type {
3
- BorrowerDetails,
4
- MemberDetailsMayachain,
5
- MemberDetailsThorchain,
6
- SaverDetails,
7
- THORNameDetails,
8
- } from "./types";
1
+ import {
2
+ AssetValue,
3
+ BaseDecimal,
4
+ Chain,
5
+ RequestClient,
6
+ SKConfig,
7
+ StagenetChain,
8
+ SwapKitNumber,
9
+ } from "@swapkit/helpers";
10
+ import type { MemberDetailsMayachain, MemberDetailsThorchain, THORNameDetails } from "./types";
11
+
12
+ // Create extended RequestClient instances for each API
13
+ const getMidgardRequestClient = () => {
14
+ const apiHeaders = SKConfig.get("apiHeaders");
15
+ return RequestClient.extend({
16
+ headers: apiHeaders.midgard || {},
17
+ });
18
+ };
9
19
 
10
20
  function getMidgardBaseUrl(isThorchain = true) {
11
- return isThorchain ? "https://midgard.ninerealms.com" : "https://midgard.mayachain.info";
21
+ const { isStagenet } = SKConfig.get("envs");
22
+ const midgardUrls = SKConfig.get("midgardUrls");
23
+
24
+ if (isThorchain) {
25
+ const chain = isStagenet ? StagenetChain.THORChain : Chain.THORChain;
26
+ // Use the configured URL if available, otherwise use defaults
27
+ if (midgardUrls[chain]) {
28
+ return midgardUrls[chain];
29
+ }
30
+ // Default URLs based on environment
31
+ return isStagenet
32
+ ? "https://stagenet-midgard.ninerealms.com"
33
+ : "https://midgard.ninerealms.com";
34
+ }
35
+
36
+ const chain = isStagenet ? StagenetChain.Maya : Chain.Maya;
37
+ // Use the configured URL if available, otherwise use defaults
38
+ if (midgardUrls[chain]) {
39
+ return midgardUrls[chain];
40
+ }
41
+ // Default URLs based on environment
42
+ return isStagenet ? "https://stagenet-midgard.mayachain.info" : "https://midgard.mayachain.info";
12
43
  }
13
44
 
14
45
  function getNameServiceBaseUrl(isThorchain = true) {
@@ -16,23 +47,12 @@ function getNameServiceBaseUrl(isThorchain = true) {
16
47
  return isThorchain ? `${baseUrl}/v2/thorname` : `${baseUrl}/v2/mayaname`;
17
48
  }
18
49
 
19
- function getBorrowerDetailRaw(baseUrl: string) {
20
- return function getBorrowerDetail(address: string) {
21
- return RequestClient.get<BorrowerDetails>(`${baseUrl}/v2/borrower/${address}`);
22
- };
23
- }
24
-
25
- function getSaverDetailRaw(baseUrl: string) {
26
- return function getSaverDetail(address: string) {
27
- return RequestClient.get<SaverDetails>(`${baseUrl}/v2/saver/${address}`);
28
- };
29
- }
30
-
31
50
  function getLiquidityPositionRaw<Chain extends Chain.THORChain | Chain.Maya>(baseUrl: string) {
32
51
  return function getLiquidityPosition(
33
52
  address: string,
34
53
  ): Promise<Chain extends Chain.THORChain ? MemberDetailsThorchain : MemberDetailsMayachain> {
35
- return RequestClient.get<
54
+ const MidgardRequestClient = getMidgardRequestClient();
55
+ return MidgardRequestClient.get<
36
56
  Chain extends Chain.THORChain ? MemberDetailsThorchain : MemberDetailsMayachain
37
57
  >(`${baseUrl}/v2/member/${address}`);
38
58
  };
@@ -40,43 +60,22 @@ function getLiquidityPositionRaw<Chain extends Chain.THORChain | Chain.Maya>(bas
40
60
 
41
61
  function getNameDetails(baseUrl: string) {
42
62
  return function getNameDetails(name: string) {
43
- return RequestClient.get<THORNameDetails>(`${baseUrl}/lookup/${name}`);
63
+ const MidgardRequestClient = getMidgardRequestClient();
64
+ return MidgardRequestClient.get<THORNameDetails>(`${baseUrl}/lookup/${name}`);
44
65
  };
45
66
  }
46
67
 
47
68
  function getNamesByAddress(baseUrl: string) {
48
69
  return function getNamesByAddress(address: string) {
49
- return RequestClient.get<string[]>(`${baseUrl}/rlookup/${address}`);
70
+ const MidgardRequestClient = getMidgardRequestClient();
71
+ return MidgardRequestClient.get<string[]>(`${baseUrl}/rlookup/${address}`);
50
72
  };
51
73
  }
52
74
 
53
75
  function getNamesByOwner(baseUrl: string) {
54
76
  return function getNamesByOwner(address: string) {
55
- return RequestClient.get<string[]>(`${baseUrl}/owner/${address}`);
56
- };
57
- }
58
-
59
- function getBorrowerDetail(borrowerDetailGetter: ReturnType<typeof getBorrowerDetailRaw>) {
60
- return async function getBorrowerDetail(address: string) {
61
- const rawBorrowerDetail = await borrowerDetailGetter(address);
62
-
63
- return rawBorrowerDetail.pools.map((p) => ({
64
- collateral_deposited: AssetValue.from({
65
- asset: p.collateral_asset,
66
- value: p.collateral_deposited,
67
- fromBaseDecimal: BaseDecimal.THOR,
68
- }),
69
- collateral_withdrawn: AssetValue.from({
70
- asset: p.collateral_asset,
71
- value: p.collateral_withdrawn,
72
- fromBaseDecimal: BaseDecimal.THOR,
73
- }),
74
- debt_issued_tor: SwapKitNumber.fromBigInt(BigInt(p.debt_issued_tor), BaseDecimal.THOR),
75
- debt_repaid_tor: SwapKitNumber.fromBigInt(BigInt(p.debt_repaid_tor), BaseDecimal.THOR),
76
- last_open_loan_timestamp: p.last_open_loan_timestamp,
77
- last_repay_loan_timestamp: p.last_repay_loan_timestamp,
78
- target_assets: p.target_assets.map((asset) => AssetValue.from({ asset })),
79
- }));
77
+ const MidgardRequestClient = getMidgardRequestClient();
78
+ return MidgardRequestClient.get<string[]>(`${baseUrl}/owner/${address}`);
80
79
  };
81
80
  }
82
81
 
@@ -84,22 +83,6 @@ function getPoolAsset({ asset, value }: { asset: string; value: string }) {
84
83
  return AssetValue.from({ asset, value, fromBaseDecimal: BaseDecimal.THOR });
85
84
  }
86
85
 
87
- function getSaverDetail(saverDetailGetter: ReturnType<typeof getSaverDetailRaw>) {
88
- return async function getSaverDetail(address: string) {
89
- const rawSaverPositions = await saverDetailGetter(address);
90
-
91
- return rawSaverPositions.pools.map((p) => ({
92
- assetAdded: getPoolAsset({ asset: p.pool, value: p.assetAdded }),
93
- assetDeposit: getPoolAsset({ asset: p.pool, value: p.assetDeposit }),
94
- assetRedeem: getPoolAsset({ asset: p.pool, value: p.assetRedeem }),
95
- assetWithdrawn: getPoolAsset({ asset: p.pool, value: p.assetWithdrawn }),
96
- assetRegisteredAddress: p.assetAddress,
97
- dateFirstAdded: p.dateFirstAdded,
98
- dateLastAdded: p.dateLastAdded,
99
- }));
100
- };
101
- }
102
-
103
86
  function getLiquidityPosition<IsThorchain extends boolean = true>({
104
87
  liquidityPositionGetter,
105
88
  isThorchain,
@@ -134,15 +117,9 @@ function getMidgardMethodsForProtocol<T extends Chain.THORChain | Chain.Maya>(ch
134
117
  const midgardBaseUrl = getMidgardBaseUrl(isThorchain);
135
118
  const nameServiceBaseUrl = getNameServiceBaseUrl(isThorchain);
136
119
  const liquidityPositionGetter = getLiquidityPositionRaw<T>(midgardBaseUrl);
137
- const borrowerDetailGetter = getBorrowerDetailRaw(midgardBaseUrl);
138
- const saverDetailGetter = getSaverDetailRaw(midgardBaseUrl);
139
120
 
140
121
  return {
141
122
  getLiquidityPositionRaw: liquidityPositionGetter,
142
- getBorrowerDetailRaw: borrowerDetailGetter,
143
- getSaverDetailRaw: saverDetailGetter,
144
- getBorrowerDetail: getBorrowerDetail(borrowerDetailGetter),
145
- getSaversDetail: getSaverDetail(saverDetailGetter),
146
123
  getNameDetails: getNameDetails(nameServiceBaseUrl),
147
124
  getNamesByAddress: getNamesByAddress(nameServiceBaseUrl),
148
125
  getNamesByOwner: getNamesByOwner(nameServiceBaseUrl),
@@ -1,52 +1,3 @@
1
- export type BorrowerDetails = {
2
- /** @description List details of all the loans identified with the given address */
3
- pools: BorrowerPool[];
4
- };
5
-
6
- export type BorrowerPool = {
7
- /** @description The asset that the borrower used as collateral */
8
- collateral_asset: string;
9
- /** @description Int64(e8), The total amount of collateral that user deposited */
10
- collateral_deposited: string;
11
- /** @description Int64(e8), The total amount of collateral the system paid back to the user */
12
- collateral_withdrawn: string;
13
- /** @description Int64(e8), The total amount of debt issued as debt for user. denominated in TOR. */
14
- debt_issued_tor: string;
15
- /** @description Int64(e8), The total amount of debt that the user paid back. denominated in TOR. */
16
- debt_repaid_tor: string;
17
- /** @description Int64, Unix timestamp for the last time borrower opened a loan */
18
- last_open_loan_timestamp: string;
19
- /** @description Int64, Unix timestamp for the last time borrower repayment occurred */
20
- last_repay_loan_timestamp: string;
21
- target_assets: string[];
22
- };
23
-
24
- export type SaverDetails = {
25
- /** @description List details of all the savers identified with the given address */
26
- pools: SaverPool[];
27
- };
28
-
29
- export type SaverPool = {
30
- /** @description Int64(e8), total asset added in the saver pool by member */
31
- assetAdded: string;
32
- /** @description saver address used by the member */
33
- assetAddress: string;
34
- /** @description Int64(e8), total asset that is currently deposited by the member */
35
- assetDeposit: string;
36
- /** @description Int64(e8), total asset can be redeemed from the saver pool by member */
37
- assetRedeem: string;
38
- /** @description Int64(e8), total asset withdrawn from the saver pool by member */
39
- assetWithdrawn: string;
40
- /** @description Int64, Unix timestamp for the first time member deposited into the saver pool */
41
- dateFirstAdded: string;
42
- /** @description Int64, Unix timestamp for the last time member deposited into the saver pool */
43
- dateLastAdded: string;
44
- /** @description The Pool rest of the data are refering to (only those pools can show up which have a corresponding saver pool) */
45
- pool: string;
46
- /** @description Int64, saver liquidity units that belong the the member */
47
- saverUnits: string;
48
- };
49
-
50
1
  export type MemberDetailsMayachain = {
51
2
  /** @MemberPool List details of all the liquidity providers identified with the given address */
52
3
  pools: MemberPoolMayachain[];
@@ -9,6 +9,14 @@ import {
9
9
  isGasAsset,
10
10
  } from "@swapkit/helpers";
11
11
 
12
+ // Create extended RequestClient for swapkitApi with custom headers
13
+ const getSwapkitApiRequestClient = () => {
14
+ const apiHeaders = SKConfig.get("apiHeaders");
15
+ return RequestClient.extend({
16
+ headers: apiHeaders.swapkitApi || {},
17
+ });
18
+ };
19
+
12
20
  import {
13
21
  type BalanceResponse,
14
22
  type BrokerDepositChannelParams,
@@ -29,11 +37,13 @@ import {
29
37
  } from "./types";
30
38
 
31
39
  export function getTrackerDetails(json: TrackerParams) {
32
- return RequestClient.post<TrackerResponse>(getApiUrl("/track"), { json });
40
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
41
+ return SwapkitApiRequestClient.post<TrackerResponse>(getApiUrl("/track"), { json });
33
42
  }
34
43
 
35
44
  export async function getSwapQuote(json: QuoteRequest) {
36
- const response = await RequestClient.post<QuoteResponse>(getApiUrl("/quote"), { json });
45
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
46
+ const response = await SwapkitApiRequestClient.post<QuoteResponse>(getApiUrl("/quote"), { json });
37
47
 
38
48
  if (response.error) {
39
49
  throw new SwapKitError("api_v2_server_error", { message: response.error });
@@ -59,26 +69,30 @@ export async function getChainBalance<T extends Chain>({
59
69
  address,
60
70
  scamFilter = true,
61
71
  }: { chain: T; address: string; scamFilter?: boolean }) {
72
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
62
73
  const url = getApiUrl(`/balance?chain=${chain}&address=${address}`);
63
- const balanceResponse = await RequestClient.get<BalanceResponse>(url);
74
+ const balanceResponse = await SwapkitApiRequestClient.get<BalanceResponse>(url);
64
75
  const balances = Array.isArray(balanceResponse) ? balanceResponse : [];
65
76
 
66
77
  return scamFilter ? filterAssets(balances) : balances;
67
78
  }
68
79
 
69
80
  export function getTokenListProviders() {
81
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
70
82
  const url = getApiUrl("/providers");
71
- return RequestClient.get<TokenListProvidersResponse>(url);
83
+ return SwapkitApiRequestClient.get<TokenListProvidersResponse>(url);
72
84
  }
73
85
 
74
86
  export function getTokenList(provider: ProviderName) {
87
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
75
88
  const url = getApiUrl(`/tokens?provider=${provider}`);
76
- return RequestClient.get<TokensResponseV2>(url);
89
+ return SwapkitApiRequestClient.get<TokensResponseV2>(url);
77
90
  }
78
91
 
79
92
  export async function getPrice(body: PriceRequest) {
93
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
80
94
  const url = getApiUrl("/price");
81
- const response = await RequestClient.post<PriceResponse>(url, {
95
+ const response = await SwapkitApiRequestClient.post<PriceResponse>(url, {
82
96
  json: body,
83
97
  });
84
98
 
@@ -96,8 +110,9 @@ export async function getPrice(body: PriceRequest) {
96
110
  }
97
111
 
98
112
  export async function getGasRate() {
113
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
99
114
  const url = getApiUrl("/gas");
100
- const response = await RequestClient.get<GasResponse>(url);
115
+ const response = await SwapkitApiRequestClient.get<GasResponse>(url);
101
116
 
102
117
  try {
103
118
  const parsedResponse = GasResponseSchema.safeParse(response);
@@ -118,9 +133,10 @@ export async function getChainflipDepositChannel(body: BrokerDepositChannelParam
118
133
  if (!destinationAddress) {
119
134
  throw new SwapKitError("chainflip_broker_invalid_params");
120
135
  }
136
+ const SwapkitApiRequestClient = getSwapkitApiRequestClient();
121
137
  const url = SKConfig.get("integrations").chainflip?.brokerUrl || getApiUrl("/channel");
122
138
 
123
- const response = await RequestClient.post<DepositChannelResponse>(url, { json: body });
139
+ const response = await SwapkitApiRequestClient.post<DepositChannelResponse>(url, { json: body });
124
140
 
125
141
  try {
126
142
  const parsedResponse = DepositChannelResponseSchema.safeParse(response);
@@ -10,6 +10,14 @@ import type {
10
10
  THORNodeType,
11
11
  } from "./types";
12
12
 
13
+ // Create extended RequestClient for thornode with custom headers
14
+ const getThornodeRequestClient = () => {
15
+ const apiHeaders = SKConfig.get("apiHeaders");
16
+ return RequestClient.extend({
17
+ headers: apiHeaders.thornode || {},
18
+ });
19
+ };
20
+
13
21
  function baseUrl(type?: THORNodeType) {
14
22
  const { isStagenet } = SKConfig.get("envs");
15
23
  const nodeUrls = SKConfig.get("nodeUrls");
@@ -35,23 +43,28 @@ function getNameServiceBaseUrl(type?: THORNodeType) {
35
43
  }
36
44
 
37
45
  export function getLastBlock<T extends THORNodeType = "thorchain">(type: T = "thorchain" as T) {
38
- return RequestClient.get<LastBlockItem<T>[]>(`${baseUrl(type)}/lastblock`);
46
+ const ThornodeRequestClient = getThornodeRequestClient();
47
+ return ThornodeRequestClient.get<LastBlockItem<T>[]>(`${baseUrl(type)}/lastblock`);
39
48
  }
40
49
 
41
50
  export function getThorchainQueue(type?: THORNodeType) {
42
- return RequestClient.get(`${baseUrl(type)}/queue`);
51
+ const ThornodeRequestClient = getThornodeRequestClient();
52
+ return ThornodeRequestClient.get(`${baseUrl(type)}/queue`);
43
53
  }
44
54
 
45
55
  export function getNodes(type?: THORNodeType) {
46
- return RequestClient.get<NodeItem[]>(`${baseUrl(type)}/nodes`);
56
+ const ThornodeRequestClient = getThornodeRequestClient();
57
+ return ThornodeRequestClient.get<NodeItem[]>(`${baseUrl(type)}/nodes`);
47
58
  }
48
59
 
49
60
  export function getMimirInfo(type?: THORNodeType) {
50
- return RequestClient.get<MimirData>(`${baseUrl(type)}/mimir`);
61
+ const ThornodeRequestClient = getThornodeRequestClient();
62
+ return ThornodeRequestClient.get<MimirData>(`${baseUrl(type)}/mimir`);
51
63
  }
52
64
 
53
65
  export function getInboundAddresses(type?: THORNodeType) {
54
- return RequestClient.get<InboundAddressesItem[]>(`${baseUrl(type)}/inbound_addresses`);
66
+ const ThornodeRequestClient = getThornodeRequestClient();
67
+ return ThornodeRequestClient.get<InboundAddressesItem[]>(`${baseUrl(type)}/inbound_addresses`);
55
68
  }
56
69
 
57
70
  export async function getTHORNodeTNSDetails({
@@ -59,7 +72,8 @@ export async function getTHORNodeTNSDetails({
59
72
  name,
60
73
  }: { type?: THORNodeType; name: string }): Promise<THORNodeTNSDetails> {
61
74
  try {
62
- const result = await RequestClient.get<THORNodeTNSDetails>(
75
+ const ThornodeRequestClient = getThornodeRequestClient();
76
+ const result = await ThornodeRequestClient.get<THORNodeTNSDetails>(
63
77
  `${getNameServiceBaseUrl(type)}/${name}`,
64
78
  );
65
79
  return result;
@@ -85,12 +99,16 @@ export async function getTNSPreferredAsset({ type, tns }: { type?: THORNodeType;
85
99
  }
86
100
 
87
101
  export function getRunePoolInfo(type?: THORNodeType) {
88
- return RequestClient.get<RunePoolInfo>(`${baseUrl(type)}/runepool`);
102
+ const ThornodeRequestClient = getThornodeRequestClient();
103
+ return ThornodeRequestClient.get<RunePoolInfo>(`${baseUrl(type)}/runepool`);
89
104
  }
90
105
 
91
106
  export function getRunePoolProviderInfo({
92
107
  type,
93
108
  thorAddress,
94
109
  }: { type?: THORNodeType; thorAddress: string }) {
95
- return RequestClient.get<RunePoolProviderInfo>(`${baseUrl(type)}/rune_provider/${thorAddress}`);
110
+ const ThornodeRequestClient = getThornodeRequestClient();
111
+ return ThornodeRequestClient.get<RunePoolProviderInfo>(
112
+ `${baseUrl(type)}/rune_provider/${thorAddress}`,
113
+ );
96
114
  }
@@ -1,5 +1,5 @@
1
1
  import { createStore } from "zustand/vanilla";
2
- import { Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS, WalletOption } from "../types";
2
+ import { Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS, StagenetChain, WalletOption } from "../types";
3
3
 
4
4
  export type SKConfigIntegrations = {
5
5
  chainflip?: { useSDKBroker?: boolean; brokerUrl: string };
@@ -24,6 +24,12 @@ export type SKConfigIntegrations = {
24
24
  };
25
25
  };
26
26
 
27
+ export type SKApiHeaders = {
28
+ midgard?: Record<string, string>;
29
+ thornode?: Record<string, string>;
30
+ swapkitApi?: Record<string, string>;
31
+ };
32
+
27
33
  const initialState = {
28
34
  // TODO: figure out how to type apis without using toolbox directly
29
35
  // Maybe move rpc/toolbox apis to helpers?
@@ -34,6 +40,15 @@ const initialState = {
34
40
  nodeUrls: NODE_URLS,
35
41
  rpcUrls: RPC_URLS,
36
42
 
43
+ midgardUrls: {
44
+ [Chain.THORChain]: "https://midgard.ninerealms.com",
45
+ [Chain.Maya]: "https://midgard.mayachain.info",
46
+ [StagenetChain.THORChain]: "https://stagenet-midgard.ninerealms.com",
47
+ [StagenetChain.Maya]: "https://stagenet-midgard.mayachain.info",
48
+ } as Partial<Record<Chain | StagenetChain, string>>,
49
+
50
+ apiHeaders: {} as SKApiHeaders,
51
+
37
52
  apiKeys: {
38
53
  blockchair: "",
39
54
  keepKey: "",
@@ -65,10 +80,12 @@ type SKState = typeof initialState;
65
80
 
66
81
  export type SKConfigState = {
67
82
  apiKeys?: Partial<SKState["apiKeys"]>;
83
+ apiHeaders?: Partial<SKApiHeaders>;
68
84
  chains?: SKState["chains"];
69
85
  envs?: Partial<SKState["envs"]>;
70
86
  explorerUrls?: Partial<SKState["explorerUrls"]>;
71
87
  integrations?: Partial<SKConfigIntegrations>;
88
+ midgardUrls?: Partial<SKState["midgardUrls"]>;
72
89
  nodeUrls?: Partial<SKState["nodeUrls"]>;
73
90
  rpcUrls?: Partial<SKState["rpcUrls"]>;
74
91
  wallets?: SKState["wallets"];
@@ -76,9 +93,11 @@ export type SKConfigState = {
76
93
 
77
94
  type SwapKitConfigStore = SKState & {
78
95
  setApiKey: (key: keyof SKState["apiKeys"], apiKey: string) => void;
96
+ setApiHeaders: (api: keyof SKApiHeaders, headers: Record<string, string>) => void;
79
97
  setConfig: (config: SKConfigState) => void;
80
98
  setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) => void;
81
99
  setExplorerUrl: (chain: keyof SKState["explorerUrls"], url: string) => void;
100
+ setMidgardUrl: (chain: keyof SKState["midgardUrls"], url: string) => void;
82
101
  setNodeUrl: (chain: keyof SKState["nodeUrls"], url: string) => void;
83
102
  setRpcUrl: (chain: keyof SKState["rpcUrls"], url: string) => void;
84
103
  setIntegrationConfig: (
@@ -91,9 +110,12 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
91
110
  ...initialState,
92
111
 
93
112
  setApiKey: (key, apiKey) => set((s) => ({ apiKeys: { ...s.apiKeys, [key]: apiKey } })),
113
+ setApiHeaders: (api, headers) =>
114
+ set((s) => ({ apiHeaders: { ...s.apiHeaders, [api]: headers } })),
94
115
  setEnv: (key, value) => set((s) => ({ envs: { ...s.envs, [key]: value } })),
95
116
  setExplorerUrl: (chain, url) =>
96
117
  set((s) => ({ explorerUrls: { ...s.explorerUrls, [chain]: url } })),
118
+ setMidgardUrl: (chain, url) => set((s) => ({ midgardUrls: { ...s.midgardUrls, [chain]: url } })),
97
119
  setNodeUrl: (chain, url) => set((s) => ({ nodeUrls: { ...s.nodeUrls, [chain]: url } })),
98
120
  setRpcUrl: (chain, url) => set((s) => ({ rpcUrls: { ...s.rpcUrls, [chain]: url } })),
99
121
  setIntegrationConfig: (integration, config) =>
@@ -101,9 +123,11 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
101
123
  setConfig: (config) =>
102
124
  set((s) => ({
103
125
  apiKeys: { ...s.apiKeys, ...config.apiKeys },
126
+ apiHeaders: { ...s.apiHeaders, ...config.apiHeaders },
104
127
  envs: { ...s.envs, ...config.envs },
105
128
  explorerUrls: { ...s.explorerUrls, ...config.explorerUrls },
106
129
  integrations: { ...s.integrations, ...config.integrations },
130
+ midgardUrls: { ...s.midgardUrls, ...config.midgardUrls },
107
131
  nodeUrls: { ...s.nodeUrls, ...config.nodeUrls },
108
132
  rpcUrls: { ...s.rpcUrls, ...config.rpcUrls },
109
133
  chains: s.chains.concat(config.chains || []),
@@ -118,10 +142,14 @@ export const SKConfig = {
118
142
 
119
143
  setApiKey: <T extends keyof SKState["apiKeys"]>(key: T, apiKey: string) =>
120
144
  swapKitState.getState().setApiKey(key, apiKey),
145
+ setApiHeaders: <T extends keyof SKApiHeaders>(api: T, headers: Record<string, string>) =>
146
+ swapKitState.getState().setApiHeaders(api, headers),
121
147
  setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) =>
122
148
  swapKitState.getState().setEnv(key, value),
123
149
  setExplorerUrl: <T extends keyof SKState["explorerUrls"]>(chain: T, url: string) =>
124
150
  swapKitState.getState().setExplorerUrl(chain, url),
151
+ setMidgardUrl: <T extends keyof SKState["midgardUrls"]>(chain: T, url: string) =>
152
+ swapKitState.getState().setMidgardUrl(chain, url),
125
153
  setNodeUrl: <T extends keyof SKState["nodeUrls"]>(chain: T, url: string) =>
126
154
  swapKitState.getState().setNodeUrl(chain, url),
127
155
  setRpcUrl: <T extends keyof SKState["rpcUrls"]>(chain: T, url: string) =>
@@ -76,7 +76,6 @@ export enum ErrorCode {
76
76
  addressScreeningFailed = "addressScreeningFailed",
77
77
  noLiquidtyProvidersFound = "noLiquidtyProvidersFound",
78
78
  insufficientLiquidity = "insufficientLiquidity",
79
- noSaversFound = "noSaversFound",
80
79
  noInboundDataFound = "noInbounDataFound",
81
80
  noInboundAddressesFound = "noInboundAddressesFound",
82
81
  noInboundAddressFoundForChain = "noInboundAddressFoundForChain",
@@ -110,7 +109,6 @@ export enum ErrorCode {
110
109
  thorchainPoolUnavailable = "thorchainPoolUnavailable",
111
110
  noOhlcvDataFound = "noOhlcvDataFound",
112
111
  noTradingPairs = "noTradingPairs",
113
- noLoanPositionFound = "noLoanPositionFound",
114
112
  noLendingAvailability = "noLendingAvailability",
115
113
  lendingRepayTooSmall = "lendingRepayTooSmall",
116
114
  missingState = "missingState",
package/src/types/sdk.ts CHANGED
@@ -34,8 +34,6 @@ export enum MemoType {
34
34
  LEAVE = "LEAVE",
35
35
  UNBOND = "UNBOND",
36
36
  WITHDRAW = "-",
37
- OPEN_LOAN = "$+",
38
- CLOSE_LOAN = "$-",
39
37
  RUNEPOOL_DEPOSIT = "POOL+",
40
38
  RUNEPOOL_WITHDRAW = "POOL-",
41
39
  }
@@ -8,29 +8,9 @@ import {
8
8
  getMemoForNameRegister,
9
9
  getMemoForRunePoolDeposit,
10
10
  getMemoForRunePoolWithdraw,
11
- getMemoForSaverDeposit,
12
- getMemoForSaverWithdraw,
13
11
  getMemoForWithdraw,
14
12
  } from "../memo";
15
13
 
16
- describe("getMemoForSaverDeposit", () => {
17
- test("returns correct memo for single side", () => {
18
- const result = getMemoForSaverDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
19
- expect(result).toBe("+:ETH/ETH");
20
- });
21
- });
22
-
23
- describe("getMemoForSaverWithdraw", () => {
24
- test("returns correct memo for single side", () => {
25
- const result = getMemoForSaverWithdraw({
26
- basisPoints: 5000,
27
- chain: Chain.Ethereum,
28
- symbol: "ETH",
29
- });
30
- expect(result).toBe("-:ETH/ETH:5000");
31
- });
32
- });
33
-
34
14
  describe("getMemoForLeaveAndBond", () => {
35
15
  test("returns correct memo for Leave", () => {
36
16
  const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.LEAVE });
package/src/utils/memo.ts CHANGED
@@ -16,14 +16,6 @@ export function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>) {
16
16
  return addAffiliate(MemoType.RUNEPOOL_DEPOSIT, affiliate);
17
17
  }
18
18
 
19
- export function getMemoForSaverDeposit({
20
- chain,
21
- symbol,
22
- ...affiliate
23
- }: WithAffiliate<{ chain: Chain; symbol: string }>) {
24
- return addAffiliate(`${MemoType.DEPOSIT}:${chain}/${symbol}`, affiliate);
25
- }
26
-
27
19
  export function getMemoForDeposit({
28
20
  chain,
29
21
  symbol,
@@ -43,14 +35,6 @@ export function getMemoForDeposit({
43
35
  /**
44
36
  * Withdraw
45
37
  */
46
- export function getMemoForSaverWithdraw({
47
- chain,
48
- symbol,
49
- basisPoints,
50
- }: { chain: Chain; symbol: string; basisPoints: number }) {
51
- return `${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`;
52
- }
53
-
54
38
  export function getMemoForWithdraw({
55
39
  chain,
56
40
  symbol,
@@ -92,21 +76,6 @@ export function getMemoForNamePreferredAssetRegister({
92
76
  return `${MemoType.NAME_REGISTER}:${name}:${chain}:${payout}:${owner}:${asset}`;
93
77
  }
94
78
 
95
- export function getMemoForLoan(
96
- memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
97
- {
98
- asset,
99
- address,
100
- minAmount,
101
- ...affiliate
102
- }: WithAffiliate<{ address: string; asset: string; minAmount?: string }>,
103
- ) {
104
- const baseMemo = `${memoType}:${asset}:${address}`;
105
- const minAmountPart = minAmount ? `:${minAmount}` : "";
106
-
107
- return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
108
- }
109
-
110
79
  /**
111
80
  * Internal helpers
112
81
  */