@lombard.finance/sdk 3.2.0 → 3.5.6

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 (58) hide show
  1. package/README.md +2 -0
  2. package/dist/ccip.cjs +0 -1
  3. package/dist/ccip.js +0 -1
  4. package/dist/index.cjs +1 -2
  5. package/dist/index.js +84 -73
  6. package/dist/index2.cjs +54 -55
  7. package/dist/index2.js +7947 -6532
  8. package/package.json +35 -33
  9. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +7 -0
  10. package/src/api-functions/generateDepositBtcAddress/generateDepositBtcAddress.ts +78 -2
  11. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +7 -8
  12. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddress.ts +66 -3
  13. package/src/api-functions/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +4 -0
  14. package/src/api-functions/getDepositsByAddress/getDepositsByAddress.ts +5 -2
  15. package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +2 -0
  16. package/src/api-functions/getUnstakesByAddress/getUnstakesByAddress.ts +35 -6
  17. package/src/api-functions/getUnstakesByAddress/index.ts +1 -1
  18. package/src/bridge/lib/config.ts +127 -112
  19. package/src/bridge/lib/oft-bridge.stories.tsx +9 -9
  20. package/src/bridge/lib/oft-bridge.ts +16 -17
  21. package/src/clients/public-client.ts +9 -1
  22. package/src/clients/rpc-url-config.ts +27 -0
  23. package/src/common/api-config.ts +2 -2
  24. package/src/common/blockchain-identifier.ts +11 -0
  25. package/src/common/chains.stories.tsx +67 -0
  26. package/src/common/chains.ts +83 -0
  27. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +2 -0
  28. package/src/contract-functions/claimLBTC/claimLBTC.stories.tsx +13 -4
  29. package/src/contract-functions/claimLBTC/claimLBTC.ts +50 -10
  30. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +6 -4
  31. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +7 -10
  32. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +45 -6
  33. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +3 -1
  34. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +5 -4
  35. package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +2 -0
  36. package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +15 -4
  37. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +53 -11
  38. package/src/index.ts +1 -0
  39. package/src/rewards/lib/claim-reward.stories.tsx +1 -0
  40. package/src/rewards/lib/claim-reward.ts +5 -0
  41. package/src/rewards/lib/get-reward-signing-data.stories.tsx +1 -0
  42. package/src/rewards/lib/get-reward-signing-data.ts +4 -0
  43. package/src/stories/arg-types.ts +34 -0
  44. package/src/stories/components/decorators/wagmi-decorator.tsx +5 -0
  45. package/src/tokens/abi/BTCK_ABI.ts +1092 -0
  46. package/src/tokens/lbtc-addresses.ts +7 -0
  47. package/src/tokens/token-addresses.ts +97 -10
  48. package/src/tokens/tokens.ts +29 -18
  49. package/src/utils/env.ts +7 -0
  50. package/src/utils/err.ts +14 -0
  51. package/src/utils/gas.ts +36 -0
  52. package/src/vaults/lib/metrics/get-vault-tvl.ts +1 -0
  53. package/dist/ccip.cjs.map +0 -1
  54. package/dist/ccip.js.map +0 -1
  55. package/dist/index.cjs.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/index2.cjs.map +0 -1
  58. package/dist/index2.js.map +0 -1
@@ -11,6 +11,8 @@ const STAGE_LBTC_CONTRACTS = {
11
11
  [ChainId.binanceSmartChainTestnet]:
12
12
  '0x731eFa688F3679688cf60A3993b8658138953ED6',
13
13
  [ChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',
14
+ // https://github.com/lombard-finance/smart-contracts/blob/2-token-model/devnet.json
15
+ [ChainId.katanaTatara]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
14
16
  [ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
15
17
  [ChainId.sonicBlazeTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
16
18
  } as const;
@@ -21,6 +23,8 @@ const TESTNET_LBTC_CONTRACTS = {
21
23
  [ChainId.binanceSmartChainTestnet]:
22
24
  '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
23
25
  [ChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',
26
+ // https://github.com/lombard-finance/smart-contracts/blob/main/gastald.json
27
+ [ChainId.katanaTatara]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
24
28
  [ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
25
29
  [ChainId.sonicBlazeTestnet]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
26
30
  } as const;
@@ -31,6 +35,9 @@ const LBTC_CONTRACTS = {
31
35
  [ChainId.berachain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
32
36
  [ChainId.binanceSmartChain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
33
37
  [ChainId.corn]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
38
+ [ChainId.etherlink]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
39
+ // https://github.com/lombard-finance/smart-contracts/blob/main/mainnet.json
40
+ [ChainId.katana]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
34
41
  [ChainId.morph]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
35
42
  [ChainId.sonic]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
36
43
  [ChainId.swell]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
@@ -1,32 +1,119 @@
1
1
  import { Address } from 'viem';
2
2
  import { ChainId } from '../common/chains';
3
+ import { Env } from '@lombard.finance/sdk-common';
3
4
 
4
5
  export enum Token {
5
6
  LBTC = 'LBTC',
6
7
  BTCB = 'BTCB',
8
+ /** BTCK aka Native LBTC */
9
+ BTCK = 'BTCK',
7
10
  cbBTC = 'cbBTC',
8
11
  eBTC = 'eBTC',
9
12
  wBTC = 'wBTC',
10
13
  wBTCN = 'wBTCN',
11
14
  }
12
15
 
13
- export const TOKEN_ADDRESSES: Partial<
14
- Record<Token, Partial<Record<ChainId, Address>>>
15
- > = {
16
+ type TokenAddresses = Partial<
17
+ Record<
18
+ Token,
19
+ Partial<Record<Env, Partial<Record<ChainId, Address | undefined>>>>
20
+ >
21
+ >;
22
+
23
+ export const TOKEN_ADDRESSES: TokenAddresses = {
24
+ [Token.LBTC]: {
25
+ [Env.prod]: {
26
+ [ChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',
27
+ [ChainId.base]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
28
+ [ChainId.berachain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
29
+ [ChainId.binanceSmartChain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
30
+ [ChainId.corn]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
31
+ [ChainId.katana]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
32
+ [ChainId.morph]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
33
+ [ChainId.sonic]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
34
+ [ChainId.swell]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
35
+ },
36
+ [Env.stage]: {
37
+ [ChainId.baseSepoliaTestnet]:
38
+ '0x731eFa688F3679688cf60A3993b8658138953ED6',
39
+ [ChainId.berachainBartioTestnet]:
40
+ '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
41
+ [ChainId.binanceSmartChainTestnet]:
42
+ '0x731eFa688F3679688cf60A3993b8658138953ED6',
43
+ [ChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',
44
+ // https://github.com/lombard-finance/smart-contracts/blob/2-token-model/devnet.json
45
+ [ChainId.katanaTatara]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
46
+ [ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
47
+ [ChainId.sonicBlazeTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
48
+ },
49
+ [Env.testnet]: {
50
+ [ChainId.berachainBartioTestnet]:
51
+ '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
52
+ [ChainId.binanceSmartChainTestnet]:
53
+ '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
54
+ [ChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',
55
+ [ChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
56
+ [ChainId.sonicBlazeTestnet]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
57
+ [ChainId.katanaTatara]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
58
+ },
59
+ [Env.dev]: {
60
+ // https://github.com/lombard-finance/smart-contracts/blob/2-token-model/devnet-bft.json
61
+ [ChainId.katanaTatara]: '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
62
+ },
63
+ },
16
64
  [Token.BTCB]: {
17
- [ChainId.binanceSmartChain]: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
65
+ [Env.prod]: {
66
+ [ChainId.binanceSmartChain]: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
67
+ },
18
68
  },
19
- [Token.cbBTC]: {
20
- [ChainId.ethereum]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
21
- [ChainId.base]: '0xcbb7c0000ab88b473b1f5afd9ef808440eed33bf',
69
+ [Token.BTCK]: {
70
+ [Env.prod]: {
71
+ [ChainId.katana]: '0xB0F70C0bD6FD87dbEb7C10dC692a2a6106817072',
72
+ [ChainId.katanaTatara]: undefined,
73
+ },
74
+ [Env.stage]: {
75
+ [ChainId.katana]: undefined,
76
+ [ChainId.katanaTatara]: '0x600e4006278EB11FA1691cA0FE6C5fcfC4992d58',
77
+ },
78
+ [Env.testnet]: {
79
+ [ChainId.katana]: undefined,
80
+ [ChainId.katanaTatara]: '0x20eA7b8ABb4B583788F1DFC738C709a2d9675681',
81
+ },
82
+ [Env.dev]: {
83
+ [ChainId.katana]: undefined,
84
+ [ChainId.katanaTatara]: '0xA74D838817f3098166d74a141b7d241efB15F42c',
85
+ },
22
86
  },
23
87
  [Token.eBTC]: {
24
- [ChainId.ethereum]: '0x657e8c867d8b37dcc18fa4caead9c45eb088c642',
88
+ [Env.prod]: {
89
+ [ChainId.ethereum]: '0x657e8c867d8b37dcc18fa4caead9c45eb088c642',
90
+ },
25
91
  },
26
92
  [Token.wBTC]: {
27
- [ChainId.ethereum]: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
93
+ [Env.prod]: {
94
+ [ChainId.ethereum]: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
95
+ },
28
96
  },
29
97
  [Token.wBTCN]: {
30
- [ChainId.corn]: '0xda5dDd7270381A7C2717aD10D1c0ecB19e3CDFb2',
98
+ [Env.prod]: {
99
+ [ChainId.corn]: '0xda5dDd7270381A7C2717aD10D1c0ecB19e3CDFb2',
100
+ },
31
101
  },
32
102
  };
103
+
104
+ // export const TOKEN_ADDRESSES: Partial<
105
+ // Record<Token, Partial<Record<ChainId, Address>>>
106
+ // > = {
107
+ // [Token.BTCB]: {
108
+ // [ChainId.binanceSmartChain]: '0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c',
109
+ // },
110
+ // [Token.eBTC]: {
111
+ // [ChainId.ethereum]: '0x657e8c867d8b37dcc18fa4caead9c45eb088c642',
112
+ // },
113
+ // [Token.wBTC]: {
114
+ // [ChainId.ethereum]: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
115
+ // },
116
+ // [Token.wBTCN]: {
117
+ // [ChainId.corn]: '0xda5dDd7270381A7C2717aD10D1c0ecB19e3CDFb2',
118
+ // },
119
+ // };
@@ -1,11 +1,12 @@
1
- import { Env } from '@lombard.finance/sdk-common';
1
+ import { DEFAULT_ENV, Env } from '@lombard.finance/sdk-common';
2
2
  import { ChainId } from '../common/chains';
3
3
  import { makePublicClient } from '../clients/public-client';
4
4
  import BigNumber from 'bignumber.js';
5
5
  import { Abi, Address, erc20Abi, PublicClient } from 'viem';
6
6
  import { TOKEN_ADDRESSES, Token } from './token-addresses';
7
- import { getLbtcContractAddresses } from './lbtc-addresses';
8
7
  import { LBTC_ABI } from './abi/LBTC_ABI';
8
+ import { TokenContractAddressNotFoundError } from '../utils/err';
9
+ import BTCK_ABI from './abi/BTCK_ABI';
9
10
 
10
11
  export type TokenInfo = {
11
12
  address: Address;
@@ -14,31 +15,41 @@ export type TokenInfo = {
14
15
  decimals: number;
15
16
  };
16
17
 
17
- export function getTokenContractInfo(
18
- token: Token,
18
+ type AbiFor<TToken extends Token> = TToken extends Token.LBTC
19
+ ? typeof LBTC_ABI
20
+ : TToken extends Token.BTCK
21
+ ? typeof BTCK_ABI
22
+ : typeof erc20Abi;
23
+
24
+ type TokenContractInfo<TToken extends Token> = {
25
+ abi: AbiFor<TToken>;
26
+ address: Address;
27
+ chainId: ChainId;
28
+ };
29
+
30
+ export function getTokenContractInfo<TToken extends Token>(
31
+ token: TToken,
19
32
  chainId: ChainId,
20
33
  env?: Env,
21
- ) {
34
+ ): TokenContractInfo<TToken> {
35
+ const environment = env || DEFAULT_ENV;
36
+
37
+ let abi: AbiFor<TToken> | undefined = undefined;
22
38
  if (token === Token.LBTC) {
23
- const addresses = getLbtcContractAddresses(env);
24
- const contractAddress = addresses[chainId];
25
- if (!contractAddress) {
26
- throw new Error(
27
- `Could not determine the LBTC contract address for given chain id: ${chainId} (env: ${env})`,
28
- );
29
- }
30
- return { abi: LBTC_ABI, address: contractAddress, chainId };
39
+ abi = LBTC_ABI as AbiFor<TToken>;
40
+ } else if (token === Token.BTCK) {
41
+ abi = BTCK_ABI as AbiFor<TToken>;
42
+ } else {
43
+ abi = erc20Abi as AbiFor<TToken>;
31
44
  }
32
45
 
33
- const address = TOKEN_ADDRESSES[token]?.[chainId];
46
+ const address = TOKEN_ADDRESSES[token]?.[environment]?.[chainId];
34
47
  if (!address) {
35
- throw new Error(
36
- `Could not determine the ${token} contract address for given chain id: ${chainId}`,
37
- );
48
+ throw new TokenContractAddressNotFoundError(token, chainId, environment);
38
49
  }
39
50
 
40
51
  return {
41
- abi: erc20Abi,
52
+ abi,
42
53
  address,
43
54
  chainId,
44
55
  };
package/src/utils/env.ts CHANGED
@@ -4,7 +4,14 @@ import { Env } from '@lombard.finance/sdk-common';
4
4
  const PROD_NATIVE_MINT_CHAINS = [
5
5
  ChainId.ethereum,
6
6
  ChainId.base,
7
+ ChainId.berachain,
7
8
  ChainId.binanceSmartChain,
9
+ ChainId.corn,
10
+ ChainId.etherlink,
11
+ ChainId.katana,
12
+ ChainId.morph,
13
+ ChainId.sonic,
14
+ ChainId.swell,
8
15
  ] as ChainId[];
9
16
 
10
17
  export const determineEnv = (chainId: ChainId): Env => {
package/src/utils/err.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import { AxiosError } from 'axios';
2
+ import { Token } from '../tokens/token-addresses';
3
+ import { ChainId } from '../common/chains';
4
+ import { Env } from '@lombard.finance/sdk-common';
2
5
 
3
6
  /**
4
7
  * Retrieves the error message from the given error object.
@@ -54,3 +57,14 @@ function getErrorMessageFromObject(error: unknown): string {
54
57
 
55
58
  return 'Unknown error';
56
59
  }
60
+
61
+ export class TokenContractAddressNotFoundError extends Error {
62
+ constructor(
63
+ public readonly token: Token,
64
+ public readonly chainId: ChainId,
65
+ env?: Env,
66
+ ) {
67
+ const message = `Could not determine the ${token} contract address for given chain id: ${chainId} (env: ${env || 'undefined'})`;
68
+ super(message);
69
+ }
70
+ }
@@ -0,0 +1,36 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { parseGwei, PublicClient } from 'viem';
3
+
4
+ export const estimateGasFees = async (
5
+ publicClient: PublicClient,
6
+ callData: Parameters<PublicClient['estimateContractGas']>[0],
7
+ overwriteMaxPriorityFeePerGas?: bigint,
8
+ ) => {
9
+ const fees = await publicClient.estimateFeesPerGas();
10
+
11
+ const multiplier = BigNumber(String(fees.maxFeePerGas)).dividedBy(
12
+ String(fees.maxPriorityFeePerGas),
13
+ );
14
+
15
+ const maxPriorityFeePerGas = overwriteMaxPriorityFeePerGas
16
+ ? overwriteMaxPriorityFeePerGas
17
+ : fees.maxPriorityFeePerGas;
18
+
19
+ const maxFeePerGas = overwriteMaxPriorityFeePerGas
20
+ ? BigInt(
21
+ BigNumber(String(maxPriorityFeePerGas))
22
+ .multipliedBy(multiplier)
23
+ .toFixed(0),
24
+ )
25
+ : fees.maxFeePerGas;
26
+
27
+ const gas = await publicClient.estimateContractGas(callData);
28
+
29
+ const gasEstimationData = {
30
+ gas,
31
+ maxFeePerGas,
32
+ maxPriorityFeePerGas,
33
+ };
34
+
35
+ return gasEstimationData;
36
+ };
@@ -40,6 +40,7 @@ export async function getVaultBtcHolding({
40
40
  for (const [token, chainIds] of Object.entries(vault.tokens)) {
41
41
  for (const chainId of chainIds) {
42
42
  const tokenContract = getTokenContractInfo(token as Token, chainId);
43
+
43
44
  const publicClient = clients[chainId];
44
45
  if (!publicClient) continue;
45
46
 
package/dist/ccip.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ccip.cjs","sources":["../node_modules/viem/_esm/errors/ccip.js","../node_modules/viem/_esm/utils/ccip.js"],"sourcesContent":["import { stringify } from '../utils/stringify.js';\nimport { BaseError } from './base.js';\nimport { getUrl } from './utils.js';\nexport class OffchainLookupError extends BaseError {\n constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {\n super(cause.shortMessage ||\n 'An error occurred while fetching for an offchain result.', {\n cause,\n metaMessages: [\n ...(cause.metaMessages || []),\n cause.metaMessages?.length ? '' : [],\n 'Offchain Gateway Call:',\n urls && [\n ' Gateway URL(s):',\n ...urls.map((url) => ` ${getUrl(url)}`),\n ],\n ` Sender: ${sender}`,\n ` Data: ${data}`,\n ` Callback selector: ${callbackSelector}`,\n ` Extra data: ${extraData}`,\n ].flat(),\n name: 'OffchainLookupError',\n });\n }\n}\nexport class OffchainLookupResponseMalformedError extends BaseError {\n constructor({ result, url }) {\n super('Offchain gateway response is malformed. Response data must be a hex value.', {\n metaMessages: [\n `Gateway URL: ${getUrl(url)}`,\n `Response: ${stringify(result)}`,\n ],\n name: 'OffchainLookupResponseMalformedError',\n });\n }\n}\nexport class OffchainLookupSenderMismatchError extends BaseError {\n constructor({ sender, to }) {\n super('Reverted sender address does not match target contract address (`to`).', {\n metaMessages: [\n `Contract address: ${to}`,\n `OffchainLookup sender address: ${sender}`,\n ],\n name: 'OffchainLookupSenderMismatchError',\n });\n }\n}\n//# sourceMappingURL=ccip.js.map","import { call } from '../actions/public/call.js';\nimport { OffchainLookupError, OffchainLookupResponseMalformedError, OffchainLookupSenderMismatchError, } from '../errors/ccip.js';\nimport { HttpRequestError, } from '../errors/request.js';\nimport { decodeErrorResult } from './abi/decodeErrorResult.js';\nimport { encodeAbiParameters } from './abi/encodeAbiParameters.js';\nimport { isAddressEqual } from './address/isAddressEqual.js';\nimport { concat } from './data/concat.js';\nimport { isHex } from './data/isHex.js';\nimport { stringify } from './stringify.js';\nexport const offchainLookupSignature = '0x556f1830';\nexport const offchainLookupAbiItem = {\n name: 'OffchainLookup',\n type: 'error',\n inputs: [\n {\n name: 'sender',\n type: 'address',\n },\n {\n name: 'urls',\n type: 'string[]',\n },\n {\n name: 'callData',\n type: 'bytes',\n },\n {\n name: 'callbackFunction',\n type: 'bytes4',\n },\n {\n name: 'extraData',\n type: 'bytes',\n },\n ],\n};\nexport async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {\n const { args } = decodeErrorResult({\n data,\n abi: [offchainLookupAbiItem],\n });\n const [sender, urls, callData, callbackSelector, extraData] = args;\n const { ccipRead } = client;\n const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'\n ? ccipRead.request\n : ccipRequest;\n try {\n if (!isAddressEqual(to, sender))\n throw new OffchainLookupSenderMismatchError({ sender, to });\n const result = await ccipRequest_({ data: callData, sender, urls });\n const { data: data_ } = await call(client, {\n blockNumber,\n blockTag,\n data: concat([\n callbackSelector,\n encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),\n ]),\n to,\n });\n return data_;\n }\n catch (err) {\n throw new OffchainLookupError({\n callbackSelector,\n cause: err,\n data,\n extraData,\n sender,\n urls,\n });\n }\n}\nexport async function ccipRequest({ data, sender, urls, }) {\n let error = new Error('An unknown error occurred.');\n for (let i = 0; i < urls.length; i++) {\n const url = urls[i];\n const method = url.includes('{data}') ? 'GET' : 'POST';\n const body = method === 'POST' ? { data, sender } : undefined;\n const headers = method === 'POST' ? { 'Content-Type': 'application/json' } : {};\n try {\n const response = await fetch(url.replace('{sender}', sender.toLowerCase()).replace('{data}', data), {\n body: JSON.stringify(body),\n headers,\n method,\n });\n let result;\n if (response.headers.get('Content-Type')?.startsWith('application/json')) {\n result = (await response.json()).data;\n }\n else {\n result = (await response.text());\n }\n if (!response.ok) {\n error = new HttpRequestError({\n body,\n details: result?.error\n ? stringify(result.error)\n : response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n });\n continue;\n }\n if (!isHex(result)) {\n error = new OffchainLookupResponseMalformedError({\n result,\n url,\n });\n continue;\n }\n return result;\n }\n catch (err) {\n error = new HttpRequestError({\n body,\n details: err.message,\n url,\n });\n }\n }\n throw error;\n}\n//# sourceMappingURL=ccip.js.map"],"names":["OffchainLookupError","BaseError","callbackSelector","cause","data","extraData","sender","urls","_a","url","getUrl","OffchainLookupResponseMalformedError","result","stringify","OffchainLookupSenderMismatchError","to","offchainLookupSignature","offchainLookupAbiItem","offchainLookup","client","blockNumber","blockTag","args","decodeErrorResult","callData","ccipRead","ccipRequest_","ccipRequest","isAddressEqual","data_","call","concat","encodeAbiParameters","err","error","i","method","body","headers","response","HttpRequestError","isHex"],"mappings":"gHAGO,MAAMA,UAA4BC,EAAAA,SAAU,CAC/C,YAAY,CAAE,iBAAAC,EAAkB,MAAAC,EAAO,KAAAC,EAAM,UAAAC,EAAW,OAAAC,EAAQ,KAAAC,GAAS,OACrE,MAAMJ,EAAM,cACR,2DAA4D,CAC5D,MAAAA,EACA,aAAc,CACV,GAAIA,EAAM,cAAgB,IAC1BK,EAAAL,EAAM,eAAN,MAAAK,EAAoB,OAAS,GAAK,CAAE,EACpC,yBACAD,GAAQ,CACJ,oBACA,GAAGA,EAAK,IAAKE,GAAQ,OAAOC,EAAM,OAACD,CAAG,CAAC,EAAE,CAC5C,EACD,aAAaH,CAAM,GACnB,WAAWF,CAAI,GACf,wBAAwBF,CAAgB,GACxC,iBAAiBG,CAAS,EAC7B,EAAC,KAAM,EACR,KAAM,qBAClB,CAAS,CACT,CACA,CACO,MAAMM,UAA6CV,EAAAA,SAAU,CAChE,YAAY,CAAE,OAAAW,EAAQ,IAAAH,GAAO,CACzB,MAAM,6EAA8E,CAChF,aAAc,CACV,gBAAgBC,EAAAA,OAAOD,CAAG,CAAC,GAC3B,aAAaI,EAAAA,UAAUD,CAAM,CAAC,EACjC,EACD,KAAM,sCAClB,CAAS,CACT,CACA,CACO,MAAME,UAA0Cb,EAAAA,SAAU,CAC7D,YAAY,CAAE,OAAAK,EAAQ,GAAAS,GAAM,CACxB,MAAM,yEAA0E,CAC5E,aAAc,CACV,qBAAqBA,CAAE,GACvB,kCAAkCT,CAAM,EAC3C,EACD,KAAM,mCAClB,CAAS,CACT,CACA,CCrCY,MAACU,EAA0B,aAC1BC,EAAwB,CACjC,KAAM,iBACN,KAAM,QACN,OAAQ,CACJ,CACI,KAAM,SACN,KAAM,SACT,EACD,CACI,KAAM,OACN,KAAM,UACT,EACD,CACI,KAAM,WACN,KAAM,OACT,EACD,CACI,KAAM,mBACN,KAAM,QACT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AI,SAAS,QAAQ,EAAI,MAAQ,OAC1C4B,EAAOD,IAAW,OAAS,CAAE,KAAAhC,EAAM,OAAAE,CAAM,EAAK,OAC9CgC,EAAUF,IAAW,OAAS,CAAE,eAAgB,kBAAkB,EAAK,CAAE,EAC/E,GAAI,CACA,MAAMG,EAAW,MAAM,MAAM9B,EAAI,QAAQ,WAAYH,EAAO,YAAa,CAAA,EAAE,QAAQ,SAAUF,CAAI,EAAG,CAChG,KAAM,KAAK,UAAUiC,CAAI,EACzB,QAAAC,EACA,OAAAF,CAChB,CAAa,EACD,IAAIxB,EAOJ,IANIJ,EAAA+B,EAAS,QAAQ,IAAI,cAAc,IAAnC,MAAA/B,EAAsC,WAAW,oBACjDI,GAAU,MAAM2B,EAAS,KAAM,GAAE,KAGjC3B,EAAU,MAAM2B,EAAS,OAEzB,CAACA,EAAS,GAAI,CACdL,EAAQ,IAAIM,EAAAA,iBAAiB,CACzB,KAAAH,EACA,QAASzB,GAAA,MAAAA,EAAQ,MACXC,EAAS,UAACD,EAAO,KAAK,EACtB2B,EAAS,WACf,QAASA,EAAS,QAClB,OAAQA,EAAS,OACjB,IAAA9B,CACpB,CAAiB,EACD,QAChB,CACY,GAAI,CAACgC,EAAAA,MAAM7B,CAAM,EAAG,CAChBsB,EAAQ,IAAIvB,EAAqC,CAC7C,OAAAC,EACA,IAAAH,CACpB,CAAiB,EACD,QAChB,CACY,OAAOG,CACnB,OACeqB,EAAK,CACRC,EAAQ,IAAIM,EAAAA,iBAAiB,CACzB,KAAAH,EACA,QAASJ,EAAI,QACb,IAAAxB,CAChB,CAAa,CACb,CACA,CACI,MAAMyB,CACV","x_google_ignoreList":[0,1]}
package/dist/ccip.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ccip.js","sources":["../node_modules/viem/_esm/errors/ccip.js","../node_modules/viem/_esm/utils/ccip.js"],"sourcesContent":["import { stringify } from '../utils/stringify.js';\nimport { BaseError } from './base.js';\nimport { getUrl } from './utils.js';\nexport class OffchainLookupError extends BaseError {\n constructor({ callbackSelector, cause, data, extraData, sender, urls, }) {\n super(cause.shortMessage ||\n 'An error occurred while fetching for an offchain result.', {\n cause,\n metaMessages: [\n ...(cause.metaMessages || []),\n cause.metaMessages?.length ? '' : [],\n 'Offchain Gateway Call:',\n urls && [\n ' Gateway URL(s):',\n ...urls.map((url) => ` ${getUrl(url)}`),\n ],\n ` Sender: ${sender}`,\n ` Data: ${data}`,\n ` Callback selector: ${callbackSelector}`,\n ` Extra data: ${extraData}`,\n ].flat(),\n name: 'OffchainLookupError',\n });\n }\n}\nexport class OffchainLookupResponseMalformedError extends BaseError {\n constructor({ result, url }) {\n super('Offchain gateway response is malformed. Response data must be a hex value.', {\n metaMessages: [\n `Gateway URL: ${getUrl(url)}`,\n `Response: ${stringify(result)}`,\n ],\n name: 'OffchainLookupResponseMalformedError',\n });\n }\n}\nexport class OffchainLookupSenderMismatchError extends BaseError {\n constructor({ sender, to }) {\n super('Reverted sender address does not match target contract address (`to`).', {\n metaMessages: [\n `Contract address: ${to}`,\n `OffchainLookup sender address: ${sender}`,\n ],\n name: 'OffchainLookupSenderMismatchError',\n });\n }\n}\n//# sourceMappingURL=ccip.js.map","import { call } from '../actions/public/call.js';\nimport { OffchainLookupError, OffchainLookupResponseMalformedError, OffchainLookupSenderMismatchError, } from '../errors/ccip.js';\nimport { HttpRequestError, } from '../errors/request.js';\nimport { decodeErrorResult } from './abi/decodeErrorResult.js';\nimport { encodeAbiParameters } from './abi/encodeAbiParameters.js';\nimport { isAddressEqual } from './address/isAddressEqual.js';\nimport { concat } from './data/concat.js';\nimport { isHex } from './data/isHex.js';\nimport { stringify } from './stringify.js';\nexport const offchainLookupSignature = '0x556f1830';\nexport const offchainLookupAbiItem = {\n name: 'OffchainLookup',\n type: 'error',\n inputs: [\n {\n name: 'sender',\n type: 'address',\n },\n {\n name: 'urls',\n type: 'string[]',\n },\n {\n name: 'callData',\n type: 'bytes',\n },\n {\n name: 'callbackFunction',\n type: 'bytes4',\n },\n {\n name: 'extraData',\n type: 'bytes',\n },\n ],\n};\nexport async function offchainLookup(client, { blockNumber, blockTag, data, to, }) {\n const { args } = decodeErrorResult({\n data,\n abi: [offchainLookupAbiItem],\n });\n const [sender, urls, callData, callbackSelector, extraData] = args;\n const { ccipRead } = client;\n const ccipRequest_ = ccipRead && typeof ccipRead?.request === 'function'\n ? ccipRead.request\n : ccipRequest;\n try {\n if (!isAddressEqual(to, sender))\n throw new OffchainLookupSenderMismatchError({ sender, to });\n const result = await ccipRequest_({ data: callData, sender, urls });\n const { data: data_ } = await call(client, {\n blockNumber,\n blockTag,\n data: concat([\n callbackSelector,\n encodeAbiParameters([{ type: 'bytes' }, { type: 'bytes' }], [result, extraData]),\n ]),\n to,\n });\n return data_;\n }\n catch (err) {\n throw new OffchainLookupError({\n callbackSelector,\n cause: err,\n data,\n extraData,\n sender,\n urls,\n });\n }\n}\nexport async function ccipRequest({ data, sender, urls, }) {\n let error = new Error('An unknown error occurred.');\n for (let i = 0; i < urls.length; i++) {\n const url = urls[i];\n const method = url.includes('{data}') ? 'GET' : 'POST';\n const body = method === 'POST' ? { data, sender } : undefined;\n const headers = method === 'POST' ? { 'Content-Type': 'application/json' } : {};\n try {\n const response = await fetch(url.replace('{sender}', sender.toLowerCase()).replace('{data}', data), {\n body: JSON.stringify(body),\n headers,\n method,\n });\n let result;\n if (response.headers.get('Content-Type')?.startsWith('application/json')) {\n result = (await response.json()).data;\n }\n else {\n result = (await response.text());\n }\n if (!response.ok) {\n error = new HttpRequestError({\n body,\n details: result?.error\n ? stringify(result.error)\n : response.statusText,\n headers: response.headers,\n status: response.status,\n url,\n });\n continue;\n }\n if (!isHex(result)) {\n error = new OffchainLookupResponseMalformedError({\n result,\n url,\n });\n continue;\n }\n return result;\n }\n catch (err) {\n error = new HttpRequestError({\n body,\n details: err.message,\n url,\n });\n }\n }\n throw error;\n}\n//# sourceMappingURL=ccip.js.map"],"names":["OffchainLookupError","BaseError","callbackSelector","cause","data","extraData","sender","urls","_a","url","getUrl","OffchainLookupResponseMalformedError","result","stringify","OffchainLookupSenderMismatchError","to","offchainLookupSignature","offchainLookupAbiItem","offchainLookup","client","blockNumber","blockTag","args","decodeErrorResult","callData","ccipRead","ccipRequest_","ccipRequest","isAddressEqual","data_","call","concat","encodeAbiParameters","err","error","i","method","body","headers","response","HttpRequestError","isHex"],"mappings":";AAGO,MAAMA,UAA4BC,EAAU;AAAA,EAC/C,YAAY,EAAE,kBAAAC,GAAkB,OAAAC,GAAO,MAAAC,GAAM,WAAAC,GAAW,QAAAC,GAAQ,MAAAC,KAAS;;AACrE,UAAMJ,EAAM,gBACR,4DAA4D;AAAA,MAC5D,OAAAA;AAAA,MACA,cAAc;AAAA,QACV,GAAIA,EAAM,gBAAgB;SAC1BK,IAAAL,EAAM,iBAAN,QAAAK,EAAoB,SAAS,KAAK,CAAE;AAAA,QACpC;AAAA,QACAD,KAAQ;AAAA,UACJ;AAAA,UACA,GAAGA,EAAK,IAAI,CAACE,MAAQ,OAAOC,EAAOD,CAAG,CAAC,EAAE;AAAA,QAC5C;AAAA,QACD,aAAaH,CAAM;AAAA,QACnB,WAAWF,CAAI;AAAA,QACf,wBAAwBF,CAAgB;AAAA,QACxC,iBAAiBG,CAAS;AAAA,MAC7B,EAAC,KAAM;AAAA,MACR,MAAM;AAAA,IAClB,CAAS;AAAA,EACT;AACA;AACO,MAAMM,UAA6CV,EAAU;AAAA,EAChE,YAAY,EAAE,QAAAW,GAAQ,KAAAH,KAAO;AACzB,UAAM,8EAA8E;AAAA,MAChF,cAAc;AAAA,QACV,gBAAgBC,EAAOD,CAAG,CAAC;AAAA,QAC3B,aAAaI,EAAUD,CAAM,CAAC;AAAA,MACjC;AAAA,MACD,MAAM;AAAA,IAClB,CAAS;AAAA,EACT;AACA;AACO,MAAME,UAA0Cb,EAAU;AAAA,EAC7D,YAAY,EAAE,QAAAK,GAAQ,IAAAS,KAAM;AACxB,UAAM,0EAA0E;AAAA,MAC5E,cAAc;AAAA,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S;AAAA,UACf,SAASA,EAAS;AAAA,UAClB,QAAQA,EAAS;AAAA,UACjB,KAAA9B;AAAA,QACpB,CAAiB;AACD;AAAA,MAChB;AACY,UAAI,CAACgC,EAAM7B,CAAM,GAAG;AAChB,QAAAsB,IAAQ,IAAIvB,EAAqC;AAAA,UAC7C,QAAAC;AAAA,UACA,KAAAH;AAAA,QACpB,CAAiB;AACD;AAAA,MAChB;AACY,aAAOG;AAAA,IACnB,SACeqB,GAAK;AACR,MAAAC,IAAQ,IAAIM,EAAiB;AAAA,QACzB,MAAAH;AAAA,QACA,SAASJ,EAAI;AAAA,QACb,KAAAxB;AAAA,MAChB,CAAa;AAAA,IACb;AAAA,EACA;AACI,QAAMyB;AACV;","x_google_ignoreList":[0,1]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}