@layerswap/widget 0.1.4 → 0.1.14

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 (267) hide show
  1. package/README.md +78 -3
  2. package/dist/Models/Theme.d.ts +7 -6
  3. package/dist/Models/Theme.js +7 -7
  4. package/dist/Models/WalletProvider.d.ts +0 -4
  5. package/dist/Models/WalletProvider.js +2 -0
  6. package/dist/components/Buttons/copyButton.js +4 -3
  7. package/dist/components/ColorSchema.js +79 -45
  8. package/dist/components/Common/AddressIcon.js +1 -0
  9. package/dist/components/Common/AverageCompletionTime.js +1 -1
  10. package/dist/components/Common/CountDownTimer.js +2 -2
  11. package/dist/components/Common/FormattedAverageCompletionTime.js +1 -1
  12. package/dist/components/HeaderWithMenu/index.js +1 -8
  13. package/dist/components/Input/Address/AddressNote.js +3 -2
  14. package/dist/components/Input/Address/AddressPicker/AddressWithIcon.js +2 -2
  15. package/dist/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.js +12 -5
  16. package/dist/components/Input/Address/AddressPicker/ExchangeNote.d.ts +1 -1
  17. package/dist/components/Input/Address/AddressPicker/ExchangeNote.js +1 -1
  18. package/dist/components/Input/RouteIcon.js +1 -1
  19. package/dist/components/LayerswapMenu/MenuList.js +2 -56
  20. package/dist/components/Pages/404/index.js +1 -0
  21. package/dist/components/Pages/Auth/Steps/CodeStep/VerifyEmailCode.js +1 -0
  22. package/dist/components/Pages/Auth/index.d.ts +1 -1
  23. package/dist/components/Pages/Auth/index.js +3 -2
  24. package/dist/components/Pages/Campaigns/Details/Leaderboard.js +1 -0
  25. package/dist/components/Pages/Campaigns/Details/index.d.ts +1 -1
  26. package/dist/components/Pages/Campaigns/Details/index.js +3 -2
  27. package/dist/components/Pages/Campaigns/index.d.ts +1 -1
  28. package/dist/components/Pages/Campaigns/index.js +3 -2
  29. package/dist/components/Pages/Maintanance/index.js +1 -0
  30. package/dist/components/Pages/NoCookies/index.js +1 -0
  31. package/dist/components/Pages/SwapHistory/History.js +1 -2
  32. package/dist/components/Pages/SwapHistory/index.d.ts +1 -1
  33. package/dist/components/Pages/SwapHistory/index.js +4 -3
  34. package/dist/components/Pages/SwapPages/Form/FeeDetails/Campaign.js +1 -0
  35. package/dist/components/Pages/SwapPages/Form/Form.js +1 -4
  36. package/dist/components/Pages/SwapPages/Form/SecondaryComponents/ValidationError.js +1 -1
  37. package/dist/components/Pages/SwapPages/Form/Select/Popover/PopoverSelect.js +1 -1
  38. package/dist/components/Pages/SwapPages/Form/index.js +1 -0
  39. package/dist/components/Pages/SwapPages/Withdraw/Coinbase/Carousel.js +8 -6
  40. package/dist/components/Pages/SwapPages/Withdraw/Processing/Processing.js +2 -2
  41. package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.d.ts +0 -4
  42. package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.js +159 -125
  43. package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.d.ts +0 -4
  44. package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.js +69 -51
  45. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.d.ts +0 -8
  46. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.js +87 -45
  47. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.d.ts +0 -40
  48. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.js +73 -46
  49. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.d.ts +0 -4
  50. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.js +175 -128
  51. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.d.ts +0 -7
  52. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.js +138 -116
  53. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.d.ts +0 -8
  54. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.js +96 -75
  55. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SophonWalletWithdraw.js +2 -2
  56. package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.d.ts +0 -4
  57. package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.js +88 -71
  58. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.d.ts +0 -4
  59. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.js +146 -136
  60. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.d.ts +0 -4
  61. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.js +120 -99
  62. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/TransferToken.js +3 -3
  63. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/buttons.js +1 -0
  64. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/index.js +1 -1
  65. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/transactionMessage.js +2 -2
  66. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransferContent.js +101 -33
  67. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.d.ts +0 -4
  68. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.js +60 -55
  69. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.d.ts +0 -4
  70. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.js +71 -55
  71. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/buttons.js +1 -0
  72. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.d.ts +0 -4
  73. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.js +56 -52
  74. package/dist/components/Pages/SwapPages/Withdraw/index.d.ts +1 -1
  75. package/dist/components/Pages/SwapPages/Withdraw/index.js +3 -2
  76. package/dist/components/Wallet/WalletModal/Connector.js +1 -1
  77. package/dist/components/Wallet/WalletProviders/FuelProvider.d.ts +0 -5
  78. package/dist/components/Wallet/WalletProviders/FuelProvider.js +25 -20
  79. package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.d.ts +0 -5
  80. package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.js +39 -36
  81. package/dist/components/Wallet/WalletProviders/SolanaProvider.d.ts +0 -5
  82. package/dist/components/Wallet/WalletProviders/SolanaProvider.js +49 -38
  83. package/dist/components/Wallet/WalletProviders/StarknetProvider.d.ts +0 -5
  84. package/dist/components/Wallet/WalletProviders/StarknetProvider.js +112 -117
  85. package/dist/components/Wallet/WalletProviders/TonConnectProvider.d.ts +0 -6
  86. package/dist/components/Wallet/WalletProviders/TonConnectProvider.js +58 -50
  87. package/dist/components/Wallet/WalletProviders/TronProvider.d.ts +0 -3
  88. package/dist/components/Wallet/WalletProviders/TronProvider.js +23 -15
  89. package/dist/components/Wallet/WalletProviders/Wagmi.d.ts +1 -1
  90. package/dist/components/Wallet/WalletProviders/Wagmi.js +20 -10
  91. package/dist/components/Wallet/WalletProviders/index.js +13 -6
  92. package/dist/components/Widget/Footer.d.ts +2 -1
  93. package/dist/components/Widget/Footer.js +13 -4
  94. package/dist/components/Widget/Index.d.ts +1 -1
  95. package/dist/components/Widget/Index.js +1 -1
  96. package/dist/components/WidgetLoading.d.ts +1 -0
  97. package/dist/components/WidgetLoading.js +5 -0
  98. package/dist/components/Wizard/Wizard.js +1 -1
  99. package/dist/components/shadcn/command.js +1 -1
  100. package/dist/components/themeWrapper.js +3 -2
  101. package/dist/context/{LayerswapContext.d.ts → LayerswapProvider.d.ts} +3 -8
  102. package/dist/context/{LayerswapContext.js → LayerswapProvider.js} +8 -9
  103. package/dist/context/authContext.js +1 -0
  104. package/dist/context/walletHooksProvider.js +1 -0
  105. package/dist/hooks/useWallet.js +10 -14
  106. package/dist/index.css +1 -1
  107. package/dist/index.d.ts +3 -5
  108. package/dist/index.js +2 -4
  109. package/dist/index.mjs +19 -0
  110. package/dist/lib/AppSettings.d.ts +7 -3
  111. package/dist/lib/AppSettings.js +8 -7
  112. package/dist/lib/address/formatter/index.js +8 -9
  113. package/dist/lib/address/validator/index.js +18 -20
  114. package/dist/lib/axiosInterceptor.js +1 -2
  115. package/dist/lib/balances/balanceResolver.js +16 -16
  116. package/dist/lib/balances/providers/evmBalanceProvider.js +3 -3
  117. package/dist/lib/balances/providers/loopringBalanceProvider.d.ts +0 -6
  118. package/dist/lib/balances/providers/loopringBalanceProvider.js +56 -43
  119. package/dist/lib/balances/providers/paradexBalanceProvider.d.ts +0 -6
  120. package/dist/lib/balances/providers/paradexBalanceProvider.js +42 -42
  121. package/dist/lib/balances/providers/solanaBalanceProvider.d.ts +0 -6
  122. package/dist/lib/balances/providers/solanaBalanceProvider.js +70 -71
  123. package/dist/lib/balances/providers/starknetBalanceProvider.d.ts +0 -6
  124. package/dist/lib/balances/providers/starknetBalanceProvider.js +48 -45
  125. package/dist/lib/balances/providers/tonBalanceProvider.d.ts +0 -18
  126. package/dist/lib/balances/providers/tonBalanceProvider.js +104 -100
  127. package/dist/lib/balances/providers/tronBalanceResolver.js +2 -3
  128. package/dist/lib/fuels/common/FakeAccount.d.ts +0 -24
  129. package/dist/lib/fuels/common/FakeAccount.js +58 -36
  130. package/dist/lib/fuels/common/PredicateConnector.d.ts +0 -54
  131. package/dist/lib/fuels/common/PredicateConnector.js +292 -205
  132. package/dist/lib/fuels/common/PredicateFactory.d.ts +0 -29
  133. package/dist/lib/fuels/common/PredicateFactory.js +123 -76
  134. package/dist/lib/fuels/common/PredicateWalletAdapter.d.ts +0 -17
  135. package/dist/lib/fuels/common/PredicateWalletAdapter.js +44 -29
  136. package/dist/lib/fuels/common/index.d.ts +0 -4
  137. package/dist/lib/fuels/common/index.js +4 -4
  138. package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.d.ts +0 -51
  139. package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.js +268 -234
  140. package/dist/lib/fuels/connectors/fuel-wallet/index.d.ts +0 -2
  141. package/dist/lib/fuels/connectors/fuel-wallet/index.js +2 -2
  142. package/dist/lib/fuels/connectors/fuel-wallet/types.d.ts +0 -50
  143. package/dist/lib/fuels/connectors/fuel-wallet/types.js +53 -9
  144. package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.d.ts +0 -7
  145. package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.js +20 -19
  146. package/dist/lib/fuels/connectors/fuelet-wallet/index.d.ts +0 -1
  147. package/dist/lib/fuels/connectors/fuelet-wallet/index.js +1 -1
  148. package/dist/lib/gases/gasResolver.d.ts +1 -1
  149. package/dist/lib/gases/gasResolver.js +10 -10
  150. package/dist/lib/gases/providers/evmGasProvider.js +5 -4
  151. package/dist/lib/gases/providers/loopringGasProvider.d.ts +0 -6
  152. package/dist/lib/gases/providers/loopringGasProvider.js +27 -24
  153. package/dist/lib/gases/providers/solanaGasProvider.d.ts +0 -7
  154. package/dist/lib/gases/providers/solanaGasProvider.js +32 -31
  155. package/dist/lib/gases/providers/starknetGasProvider.d.ts +0 -7
  156. package/dist/lib/gases/providers/starknetGasProvider.js +34 -33
  157. package/dist/lib/imtbl.d.ts +0 -69
  158. package/dist/lib/imtbl.js +63 -60
  159. package/dist/lib/internalApiClient.d.ts +0 -2
  160. package/dist/lib/internalApiClient.js +1 -4
  161. package/dist/lib/layerSwapApiClient.js +3 -3
  162. package/dist/lib/logError.js +2 -2
  163. package/dist/lib/nft/nftBalanceResolver.js +1 -2
  164. package/dist/lib/nft/providers/starknetNftProvider.d.ts +0 -6
  165. package/dist/lib/nft/providers/starknetNftProvider.js +49 -50
  166. package/dist/lib/wallets/connectors/EthereumProvider.d.ts +2 -2
  167. package/dist/lib/wallets/connectors/useSyncProviders/store.d.ts +1 -4
  168. package/dist/lib/wallets/fuel/Bako.d.ts +0 -15
  169. package/dist/lib/wallets/fuel/Bako.js +34 -29
  170. package/dist/lib/wallets/fuel/Basko.d.ts +0 -15
  171. package/dist/lib/wallets/fuel/Basko.js +34 -29
  172. package/dist/lib/wallets/fuel/useFuel.d.ts +0 -2
  173. package/dist/lib/wallets/fuel/useFuel.js +211 -192
  174. package/dist/lib/wallets/imtblX/useImtblX.d.ts +0 -2
  175. package/dist/lib/wallets/imtblX/useImtblX.js +87 -87
  176. package/dist/lib/wallets/paradex/Authorize/Ethereum.d.ts +0 -2
  177. package/dist/lib/wallets/paradex/Authorize/Ethereum.js +24 -23
  178. package/dist/lib/wallets/paradex/Authorize/Starknet.d.ts +0 -2
  179. package/dist/lib/wallets/paradex/Authorize/Starknet.js +14 -13
  180. package/dist/lib/wallets/paradex/lib/account.d.ts +0 -28
  181. package/dist/lib/wallets/paradex/lib/account.js +102 -53
  182. package/dist/lib/wallets/paradex/lib/index.d.ts +0 -24
  183. package/dist/lib/wallets/paradex/lib/index.js +20 -20
  184. package/dist/lib/wallets/paradex/lib/paraclear-provider.d.ts +0 -6
  185. package/dist/lib/wallets/paradex/lib/paraclear-provider.js +13 -9
  186. package/dist/lib/wallets/paradex/lib/paraclear.d.ts +0 -137
  187. package/dist/lib/wallets/paradex/lib/paraclear.js +258 -131
  188. package/dist/lib/wallets/paradex/lib/starknet-account-support.d.ts +0 -22
  189. package/dist/lib/wallets/paradex/lib/starknet-account-support.js +296 -220
  190. package/dist/lib/wallets/paradex/lib/starknet-signer.d.ts +0 -15
  191. package/dist/lib/wallets/paradex/lib/starknet-signer.js +120 -94
  192. package/dist/lib/wallets/paradex/useParadex.d.ts +0 -7
  193. package/dist/lib/wallets/paradex/useParadex.js +197 -194
  194. package/dist/lib/wallets/solana/transactionBuilder.d.ts +0 -4
  195. package/dist/lib/wallets/solana/transactionBuilder.js +63 -39
  196. package/dist/lib/wallets/solana/useSVM.d.ts +0 -5
  197. package/dist/lib/wallets/solana/useSVM.js +139 -142
  198. package/dist/lib/wallets/starknet/useStarknet.d.ts +0 -2
  199. package/dist/lib/wallets/starknet/useStarknet.js +139 -139
  200. package/dist/lib/wallets/ton/client.d.ts +0 -3
  201. package/dist/lib/wallets/ton/client.js +7 -7
  202. package/dist/lib/wallets/ton/useTON.d.ts +0 -2
  203. package/dist/lib/wallets/ton/useTON.js +121 -122
  204. package/dist/lib/wallets/tron/connectors/bitkeep.d.ts +0 -61
  205. package/dist/lib/wallets/tron/connectors/bitkeep.js +326 -303
  206. package/dist/lib/wallets/tron/connectors/index.d.ts +0 -4
  207. package/dist/lib/wallets/tron/connectors/index.js +4 -4
  208. package/dist/lib/wallets/tron/connectors/okxWallet.d.ts +0 -66
  209. package/dist/lib/wallets/tron/connectors/okxWallet.js +364 -336
  210. package/dist/lib/wallets/tron/connectors/tokenPocket.d.ts +0 -72
  211. package/dist/lib/wallets/tron/connectors/tokenPocket.js +337 -308
  212. package/dist/lib/wallets/tron/connectors/tronLink/index.d.ts +0 -102
  213. package/dist/lib/wallets/tron/connectors/tronLink/index.js +560 -520
  214. package/dist/lib/wallets/tron/connectors/tronLink/types.d.ts +0 -56
  215. package/dist/lib/wallets/tron/connectors/tronLink/types.js +53 -1
  216. package/dist/lib/wallets/tron/connectors/tronLink/utils.d.ts +0 -14
  217. package/dist/lib/wallets/tron/connectors/tronLink/utils.js +64 -61
  218. package/dist/lib/wallets/tron/useTron.d.ts +0 -2
  219. package/dist/lib/wallets/tron/useTron.js +111 -111
  220. package/dist/lib/wallets/utils/resolveWalletIcon.js +1 -0
  221. package/package.json +26 -77
  222. package/dist/hooks/useCopyClipboard.d.ts +0 -1
  223. package/dist/hooks/useCopyClipboard.js +0 -21
  224. package/dist/index.cjs +0 -125
  225. package/dist/lib/abis/ERC20.json +0 -258
  226. package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.d.ts +0 -42
  227. package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.js +0 -357
  228. package/dist/lib/fuels/connectors/walletConnect/constants.d.ts +0 -6
  229. package/dist/lib/fuels/connectors/walletConnect/constants.js +0 -7
  230. package/dist/lib/fuels/connectors/walletConnect/index.d.ts +0 -3
  231. package/dist/lib/fuels/connectors/walletConnect/index.js +0 -3
  232. package/dist/lib/fuels/connectors/walletConnect/types.d.ts +0 -12
  233. package/dist/lib/fuels/connectors/walletConnect/types.js +0 -1
  234. package/dist/lib/fuels/connectors/walletConnect/utils/index.d.ts +0 -1
  235. package/dist/lib/fuels/connectors/walletConnect/utils/index.js +0 -1
  236. package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.d.ts +0 -2
  237. package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.js +0 -39
  238. package/dist/lib/fuels/connectors/walletConnect/web3Modal.d.ts +0 -10
  239. package/dist/lib/fuels/connectors/walletConnect/web3Modal.js +0 -38
  240. package/dist/lib/loopring/LoopringAPI.d.ts +0 -12
  241. package/dist/lib/loopring/LoopringAPI.js +0 -13
  242. package/dist/lib/loopring/defs.d.ts +0 -425
  243. package/dist/lib/loopring/defs.js +0 -217
  244. package/dist/lib/loopring/eddsa.d.ts +0 -29
  245. package/dist/lib/loopring/eddsa.js +0 -208
  246. package/dist/lib/loopring/field.d.ts +0 -17
  247. package/dist/lib/loopring/field.js +0 -61
  248. package/dist/lib/loopring/formatter.d.ts +0 -137
  249. package/dist/lib/loopring/formatter.js +0 -516
  250. package/dist/lib/loopring/helpers.d.ts +0 -36
  251. package/dist/lib/loopring/helpers.js +0 -140
  252. package/dist/lib/loopring/jubjub.d.ts +0 -19
  253. package/dist/lib/loopring/jubjub.js +0 -79
  254. package/dist/lib/loopring/permutation.d.ts +0 -22
  255. package/dist/lib/loopring/permutation.js +0 -198
  256. package/dist/lib/loopring/poseidon/EDDSAUtil.d.ts +0 -14
  257. package/dist/lib/loopring/poseidon/EDDSAUtil.js +0 -61
  258. package/dist/lib/loopring/poseidon/babyJub.d.ts +0 -6
  259. package/dist/lib/loopring/poseidon/babyJub.js +0 -51
  260. package/dist/lib/loopring/poseidon/eddsa.d.ts +0 -29
  261. package/dist/lib/loopring/poseidon/eddsa.js +0 -210
  262. package/dist/lib/loopring/utils.d.ts +0 -76
  263. package/dist/lib/loopring/utils.js +0 -230
  264. package/dist/styles/dialog-transition.css +0 -28
  265. package/dist/styles/globals.css +0 -372
  266. package/dist/styles/manual-trasnfer-svg.css +0 -299
  267. package/dist/styles/vaul.css +0 -256
@@ -1,131 +1,258 @@
1
- import { BigNumber } from 'bignumber.js';
2
- import * as Starknet from 'starknet';
3
- const MAX_FEE = BigNumber('5e17'); // 5e17 WEI = 0.5 ETH
4
- /**
5
- * Get the Paraclear balance of the given token for the given account.
6
- */
7
- export async function getTokenBalance(params) {
8
- const token = params.config.bridgedTokens[params.token];
9
- if (token == null) {
10
- throw new Error(`Token ${params.token} is not supported`);
11
- }
12
- const result = await params.provider.callContract({
13
- contractAddress: params.config.paraclearAddress,
14
- entrypoint: 'getTokenAssetBalance',
15
- calldata: Starknet.CallData.compile([
16
- params.account.address,
17
- token.l2TokenAddress,
18
- ]),
19
- }, 'latest');
20
- const value = result?.[0];
21
- if (value == null) {
22
- throw new Error('Failed to get token balance');
23
- }
24
- const valueBn = new BigNumber(value);
25
- if (valueBn.isNaN()) {
26
- throw new Error('Failed to parse token balance');
27
- }
28
- const chainSizeBn = valueBn;
29
- const sizeBn = fromChainSize(chainSizeBn, params.config.paraclearDecimals);
30
- return { size: sizeBn.toString() };
31
- }
32
- /**
33
- * Socialized losses happen when Paradex Insurance Fund is bankrupt
34
- * due to large amounts of unprofitable liquidations. When socialized
35
- * losses are active, (socialized loss factor > 0), the amount that
36
- * the user will receive when withdrawing will be smaller than the
37
- * requested amount.
38
- */
39
- export async function getSocializedLossFactor(params) {
40
- const result = await params.provider.callContract({
41
- contractAddress: params.config.paraclearAddress,
42
- entrypoint: 'getSocializedLossFactor',
43
- });
44
- const value = result?.[0];
45
- if (value == null) {
46
- throw new Error('Failed to get socialized loss factor');
47
- }
48
- const valueBn = new BigNumber(value);
49
- if (valueBn.isNaN()) {
50
- throw new Error('Failed to parse socialized loss factor');
51
- }
52
- const chainFactorBn = valueBn;
53
- const factorBn = fromChainSize(chainFactorBn, params.config.paraclearDecimals);
54
- return { socializedLossFactor: factorBn.toString() };
55
- }
56
- /**
57
- * The receivable amount is calculated based on the current
58
- * socialized loss factor: amount * (1 - socializedLossFactor)
59
- *
60
- * If the socialized loss factor is 0, the receivable amount
61
- * will be equal to the requested amount.
62
- */
63
- export async function getReceivableAmount(params) {
64
- const amountBn = new BigNumber(params.amount);
65
- if (amountBn.isNaN()) {
66
- throw new Error('Invalid amount');
67
- }
68
- const token = params.config.bridgedTokens[params.token];
69
- if (token == null) {
70
- throw new Error(`Token ${params.token} is not supported`);
71
- }
72
- const { socializedLossFactor } = await getSocializedLossFactor({
73
- config: params.config,
74
- provider: params.provider,
75
- });
76
- const receivableAmount = amountBn.times(BigNumber(1).minus(socializedLossFactor));
77
- const receivableAmountChainBn = toChainSize(receivableAmount.toString(), token.decimals);
78
- return {
79
- receivableAmount: receivableAmount.toString(),
80
- receivableAmountChain: receivableAmountChainBn.toString(),
81
- socializedLossFactor,
82
- };
83
- }
84
- /**
85
- * Withdraw funds from Paraclear for the given account.
86
- *
87
- * Automatically make a batch transaction with `initiate_withdrawal`
88
- * call to the Paraclear contract along with the transaction passed
89
- * as `params.bridgeCall` The batch call is atomic. If either of
90
- * the transactions fail, the entire batch gets reverted.
91
- *
92
- * If socialized loss is active, the bridge call must be constructed
93
- * with an amount that accounts for the loss. To calculate that amount,
94
- * use {@link getReceivableAmount}. Failing to do so can result in a
95
- * failed withdrawal.
96
- */
97
- export async function withdraw(params) {
98
- const token = params.config.bridgedTokens[params.token];
99
- if (token == null) {
100
- throw new Error(`Token ${params.token} is not supported`);
101
- }
102
- const chainAmountBn = toChainSize(params.amount, params.config.paraclearDecimals);
103
- // ensure unique txn hash on subsequent calls via `intNoise`
104
- const maxFee = MAX_FEE.plus(intNoise(10000));
105
- const result = await params.account.execute([
106
- {
107
- contractAddress: params.config.paraclearAddress,
108
- entrypoint: 'withdraw',
109
- calldata: [token.l2TokenAddress, chainAmountBn.toString()],
110
- },
111
- ...(Array.isArray(params.bridgeCall)
112
- ? params.bridgeCall
113
- : [params.bridgeCall]),
114
- ], undefined, { maxFee: maxFee.toString() });
115
- return { hash: result.transaction_hash };
116
- }
117
- function fromChainSize(size, decimals) {
118
- return new BigNumber(size).div(10 ** decimals);
119
- }
120
- function toChainSize(size, decimals) {
121
- return new BigNumber(size)
122
- .times(10 ** decimals)
123
- .integerValue(BigNumber.ROUND_FLOOR);
124
- }
125
- /**
126
- * Generates a pseudorandom integer between 0 and `max`.
127
- * @param max Maximum value for the noise.
128
- */
129
- function intNoise(max) {
130
- return Math.round(Math.random() * max);
131
- }
1
+ // import { BigNumber } from 'bignumber.js';
2
+ // import * as Starknet from 'starknet';
3
+ // import type { Account } from './account';
4
+ // import type { ParadexConfig } from './config';
5
+ // import type { ParaclearProvider } from './paraclear-provider';
6
+ // import type { Hex } from './types';
7
+ // const MAX_FEE = BigNumber('5e17'); // 5e17 WEI = 0.5 ETH
8
+ // interface GetBalanceParams {
9
+ // readonly config: ParadexConfig;
10
+ // readonly provider: Pick<ParaclearProvider, 'callContract'>;
11
+ // /**
12
+ // * Account to get the balance for.
13
+ // */
14
+ // readonly account: Pick<Account, 'address'>;
15
+ // /**
16
+ // * Token symbol.
17
+ // * @example 'USDC'
18
+ // */
19
+ // readonly token: string;
20
+ // }
21
+ // interface GetBalanceResult {
22
+ // /**
23
+ // * Token balance as a decimal string.
24
+ // * @example '100.45'
25
+ // * @example '45.2'
26
+ // */
27
+ // readonly size: string;
28
+ // }
29
+ // /**
30
+ // * Get the Paraclear balance of the given token for the given account.
31
+ // */
32
+ // export async function getTokenBalance(
33
+ // params: GetBalanceParams,
34
+ // ): Promise<GetBalanceResult> {
35
+ // const token = params.config.bridgedTokens[params.token];
36
+ // if (token == null) {
37
+ // throw new Error(`Token ${params.token} is not supported`);
38
+ // }
39
+ // const result = await params.provider.callContract(
40
+ // {
41
+ // contractAddress: params.config.paraclearAddress,
42
+ // entrypoint: 'getTokenAssetBalance',
43
+ // calldata: Starknet.CallData.compile([
44
+ // params.account.address,
45
+ // token.l2TokenAddress,
46
+ // ]),
47
+ // },
48
+ // 'latest',
49
+ // );
50
+ // const value = result?.[0];
51
+ // if (value == null) {
52
+ // throw new Error('Failed to get token balance');
53
+ // }
54
+ // const valueBn = new BigNumber(value);
55
+ // if (valueBn.isNaN()) {
56
+ // throw new Error('Failed to parse token balance');
57
+ // }
58
+ // const chainSizeBn = valueBn;
59
+ // const sizeBn = fromChainSize(chainSizeBn, params.config.paraclearDecimals);
60
+ // return { size: sizeBn.toString() };
61
+ // }
62
+ // interface GetSocializedLossFactorParams {
63
+ // readonly config: ParadexConfig;
64
+ // readonly provider: Pick<ParaclearProvider, 'callContract'>;
65
+ // }
66
+ // interface GetSocializedLossFactorResult {
67
+ // readonly socializedLossFactor: string;
68
+ // }
69
+ // /**
70
+ // * Socialized losses happen when Paradex Insurance Fund is bankrupt
71
+ // * due to large amounts of unprofitable liquidations. When socialized
72
+ // * losses are active, (socialized loss factor > 0), the amount that
73
+ // * the user will receive when withdrawing will be smaller than the
74
+ // * requested amount.
75
+ // */
76
+ // export async function getSocializedLossFactor(
77
+ // params: GetSocializedLossFactorParams,
78
+ // ): Promise<GetSocializedLossFactorResult> {
79
+ // const result = await params.provider.callContract({
80
+ // contractAddress: params.config.paraclearAddress,
81
+ // entrypoint: 'getSocializedLossFactor',
82
+ // });
83
+ // const value = result?.[0];
84
+ // if (value == null) {
85
+ // throw new Error('Failed to get socialized loss factor');
86
+ // }
87
+ // const valueBn = new BigNumber(value);
88
+ // if (valueBn.isNaN()) {
89
+ // throw new Error('Failed to parse socialized loss factor');
90
+ // }
91
+ // const chainFactorBn = valueBn;
92
+ // const factorBn = fromChainSize(
93
+ // chainFactorBn,
94
+ // params.config.paraclearDecimals,
95
+ // );
96
+ // return { socializedLossFactor: factorBn.toString() };
97
+ // }
98
+ // interface GetReceivableAmountParams {
99
+ // readonly config: ParadexConfig;
100
+ // readonly provider: Pick<ParaclearProvider, 'callContract'>;
101
+ // /**
102
+ // * Token symbol.
103
+ // * @example 'USDC'
104
+ // */
105
+ // readonly token: string;
106
+ // /**
107
+ // * Amount of to withdraw from Paradex, as a decimal string.
108
+ // * The receivable amount will be calculated based on this amount and
109
+ // * can be less than the requested amount if socialized loss is active.
110
+ // */
111
+ // readonly amount: string;
112
+ // }
113
+ // interface GetReceivableAmountResult {
114
+ // /**
115
+ // * Amount that will be received from Paradex, after socialized loss,
116
+ // * if applicable, after a withdrawal of the given amount parameter.
117
+ // * Decimal string.
118
+ // * @example '99.45'
119
+ // */
120
+ // readonly receivableAmount: string;
121
+ // /**
122
+ // * The receivable amount, converted to be used in chain calls,
123
+ // * using the Paraclear decimals.
124
+ // * @example '9945000000'
125
+ // */
126
+ // readonly receivableAmountChain: string;
127
+ // /**
128
+ // * Socialized loss factor used to calculate the receivable amount.
129
+ // * Decimal string.
130
+ // * @example '0.05'
131
+ // */
132
+ // readonly socializedLossFactor: string;
133
+ // }
134
+ // /**
135
+ // * The receivable amount is calculated based on the current
136
+ // * socialized loss factor: amount * (1 - socializedLossFactor)
137
+ // *
138
+ // * If the socialized loss factor is 0, the receivable amount
139
+ // * will be equal to the requested amount.
140
+ // */
141
+ // export async function getReceivableAmount(
142
+ // params: GetReceivableAmountParams,
143
+ // ): Promise<GetReceivableAmountResult> {
144
+ // const amountBn = new BigNumber(params.amount);
145
+ // if (amountBn.isNaN()) {
146
+ // throw new Error('Invalid amount');
147
+ // }
148
+ // const token = params.config.bridgedTokens[params.token];
149
+ // if (token == null) {
150
+ // throw new Error(`Token ${params.token} is not supported`);
151
+ // }
152
+ // const { socializedLossFactor } = await getSocializedLossFactor({
153
+ // config: params.config,
154
+ // provider: params.provider,
155
+ // });
156
+ // const receivableAmount = amountBn.times(
157
+ // BigNumber(1).minus(socializedLossFactor),
158
+ // );
159
+ // const receivableAmountChainBn = toChainSize(
160
+ // receivableAmount.toString(),
161
+ // token.decimals,
162
+ // );
163
+ // return {
164
+ // receivableAmount: receivableAmount.toString(),
165
+ // receivableAmountChain: receivableAmountChainBn.toString(),
166
+ // socializedLossFactor,
167
+ // };
168
+ // }
169
+ // interface WithdrawParams {
170
+ // readonly config: ParadexConfig;
171
+ // /**
172
+ // * Account to withdraw from.
173
+ // */
174
+ // readonly account: Account;
175
+ // /**
176
+ // * Token symbol.
177
+ // * @example 'USDC'
178
+ // */
179
+ // readonly token: string;
180
+ // /**
181
+ // * Amount to withdraw from Paradex.
182
+ // * Note that this amount can be less than the amount that will be
183
+ // * received if socialized loss is active. Use {@link getReceivableAmount}
184
+ // * to calculate the amount that will be received.
185
+ // * Decimal string.
186
+ // * @example '100.45'
187
+ // * @example '45.2'
188
+ // */
189
+ // readonly amount: string;
190
+ // /**
191
+ // * Call to transfer funds to the bridge. This transaction will be called
192
+ // * as the second transaction of the withdrawal transactions batch.
193
+ // *
194
+ // * The bridge call must be made with the receivable amount calculated
195
+ // * using {@link getReceivableAmount}.
196
+ // */
197
+ // readonly bridgeCall: Starknet.Call | readonly Starknet.Call[];
198
+ // }
199
+ // interface TransactionResult {
200
+ // readonly hash: Hex;
201
+ // }
202
+ // /**
203
+ // * Withdraw funds from Paraclear for the given account.
204
+ // *
205
+ // * Automatically make a batch transaction with `initiate_withdrawal`
206
+ // * call to the Paraclear contract along with the transaction passed
207
+ // * as `params.bridgeCall` The batch call is atomic. If either of
208
+ // * the transactions fail, the entire batch gets reverted.
209
+ // *
210
+ // * If socialized loss is active, the bridge call must be constructed
211
+ // * with an amount that accounts for the loss. To calculate that amount,
212
+ // * use {@link getReceivableAmount}. Failing to do so can result in a
213
+ // * failed withdrawal.
214
+ // */
215
+ // export async function withdraw(
216
+ // params: WithdrawParams,
217
+ // ): Promise<TransactionResult> {
218
+ // const token = params.config.bridgedTokens[params.token];
219
+ // if (token == null) {
220
+ // throw new Error(`Token ${params.token} is not supported`);
221
+ // }
222
+ // const chainAmountBn = toChainSize(
223
+ // params.amount,
224
+ // params.config.paraclearDecimals,
225
+ // );
226
+ // // ensure unique txn hash on subsequent calls via `intNoise`
227
+ // const maxFee = MAX_FEE.plus(intNoise(10_000));
228
+ // const result = await params.account.execute(
229
+ // [
230
+ // {
231
+ // contractAddress: params.config.paraclearAddress,
232
+ // entrypoint: 'withdraw',
233
+ // calldata: [token.l2TokenAddress, chainAmountBn.toString()],
234
+ // },
235
+ // ...(Array.isArray(params.bridgeCall)
236
+ // ? params.bridgeCall
237
+ // : [params.bridgeCall]),
238
+ // ],
239
+ // undefined,
240
+ // { maxFee: maxFee.toString() },
241
+ // );
242
+ // return { hash: result.transaction_hash as Hex };
243
+ // }
244
+ // function fromChainSize(size: BigNumber, decimals: number): BigNumber {
245
+ // return new BigNumber(size).div(10 ** decimals);
246
+ // }
247
+ // function toChainSize(size: string, decimals: number): BigNumber {
248
+ // return new BigNumber(size)
249
+ // .times(10 ** decimals)
250
+ // .integerValue(BigNumber.ROUND_FLOOR);
251
+ // }
252
+ // /**
253
+ // * Generates a pseudorandom integer between 0 and `max`.
254
+ // * @param max Maximum value for the noise.
255
+ // */
256
+ // function intNoise(max: number): number {
257
+ // return Math.round(Math.random() * max);
258
+ // }
@@ -1,22 +0,0 @@
1
- import * as Starknet from 'starknet';
2
- interface CheckResult {
3
- readonly ok: boolean;
4
- readonly reason?: string;
5
- }
6
- export declare class AccountSupport {
7
- /** The contract instance of the account. */
8
- private readonly contract;
9
- /** The class hash of the account contract. */
10
- private readonly classHash;
11
- private signatureFormat;
12
- constructor(
13
- /** The contract instance of the account. */
14
- contract: Starknet.Contract,
15
- /** The class hash of the account contract. */
16
- classHash: string);
17
- private testClassHash;
18
- private getFormat;
19
- check(): Promise<CheckResult>;
20
- getSeedFromSignature(signature: Starknet.Signature): string;
21
- }
22
- export {};