@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.
- package/README.md +78 -3
- package/dist/Models/Theme.d.ts +7 -6
- package/dist/Models/Theme.js +7 -7
- package/dist/Models/WalletProvider.d.ts +0 -4
- package/dist/Models/WalletProvider.js +2 -0
- package/dist/components/Buttons/copyButton.js +4 -3
- package/dist/components/ColorSchema.js +79 -45
- package/dist/components/Common/AddressIcon.js +1 -0
- package/dist/components/Common/AverageCompletionTime.js +1 -1
- package/dist/components/Common/CountDownTimer.js +2 -2
- package/dist/components/Common/FormattedAverageCompletionTime.js +1 -1
- package/dist/components/HeaderWithMenu/index.js +1 -8
- package/dist/components/Input/Address/AddressNote.js +3 -2
- package/dist/components/Input/Address/AddressPicker/AddressWithIcon.js +2 -2
- package/dist/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.js +12 -5
- package/dist/components/Input/Address/AddressPicker/ExchangeNote.d.ts +1 -1
- package/dist/components/Input/Address/AddressPicker/ExchangeNote.js +1 -1
- package/dist/components/Input/RouteIcon.js +1 -1
- package/dist/components/LayerswapMenu/MenuList.js +2 -56
- package/dist/components/Pages/404/index.js +1 -0
- package/dist/components/Pages/Auth/Steps/CodeStep/VerifyEmailCode.js +1 -0
- package/dist/components/Pages/Auth/index.d.ts +1 -1
- package/dist/components/Pages/Auth/index.js +3 -2
- package/dist/components/Pages/Campaigns/Details/Leaderboard.js +1 -0
- package/dist/components/Pages/Campaigns/Details/index.d.ts +1 -1
- package/dist/components/Pages/Campaigns/Details/index.js +3 -2
- package/dist/components/Pages/Campaigns/index.d.ts +1 -1
- package/dist/components/Pages/Campaigns/index.js +3 -2
- package/dist/components/Pages/Maintanance/index.js +1 -0
- package/dist/components/Pages/NoCookies/index.js +1 -0
- package/dist/components/Pages/SwapHistory/History.js +1 -2
- package/dist/components/Pages/SwapHistory/index.d.ts +1 -1
- package/dist/components/Pages/SwapHistory/index.js +4 -3
- package/dist/components/Pages/SwapPages/Form/FeeDetails/Campaign.js +1 -0
- package/dist/components/Pages/SwapPages/Form/Form.js +1 -4
- package/dist/components/Pages/SwapPages/Form/SecondaryComponents/ValidationError.js +1 -1
- package/dist/components/Pages/SwapPages/Form/Select/Popover/PopoverSelect.js +1 -1
- package/dist/components/Pages/SwapPages/Form/index.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Coinbase/Carousel.js +8 -6
- package/dist/components/Pages/SwapPages/Withdraw/Processing/Processing.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.js +159 -125
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.js +69 -51
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.d.ts +0 -8
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.js +87 -45
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.d.ts +0 -40
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.js +73 -46
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.js +175 -128
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.d.ts +0 -7
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.js +138 -116
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.d.ts +0 -8
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.js +96 -75
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/SophonWalletWithdraw.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.js +88 -71
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.js +146 -136
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.js +120 -99
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/TransferToken.js +3 -3
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/buttons.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/index.js +1 -1
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/transactionMessage.js +2 -2
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransferContent.js +101 -33
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.js +60 -55
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.js +71 -55
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/buttons.js +1 -0
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.d.ts +0 -4
- package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.js +56 -52
- package/dist/components/Pages/SwapPages/Withdraw/index.d.ts +1 -1
- package/dist/components/Pages/SwapPages/Withdraw/index.js +3 -2
- package/dist/components/Wallet/WalletModal/Connector.js +1 -1
- package/dist/components/Wallet/WalletProviders/FuelProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/FuelProvider.js +25 -20
- package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.js +39 -36
- package/dist/components/Wallet/WalletProviders/SolanaProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/SolanaProvider.js +49 -38
- package/dist/components/Wallet/WalletProviders/StarknetProvider.d.ts +0 -5
- package/dist/components/Wallet/WalletProviders/StarknetProvider.js +112 -117
- package/dist/components/Wallet/WalletProviders/TonConnectProvider.d.ts +0 -6
- package/dist/components/Wallet/WalletProviders/TonConnectProvider.js +58 -50
- package/dist/components/Wallet/WalletProviders/TronProvider.d.ts +0 -3
- package/dist/components/Wallet/WalletProviders/TronProvider.js +23 -15
- package/dist/components/Wallet/WalletProviders/Wagmi.d.ts +1 -1
- package/dist/components/Wallet/WalletProviders/Wagmi.js +20 -10
- package/dist/components/Wallet/WalletProviders/index.js +13 -6
- package/dist/components/Widget/Footer.d.ts +2 -1
- package/dist/components/Widget/Footer.js +13 -4
- package/dist/components/Widget/Index.d.ts +1 -1
- package/dist/components/Widget/Index.js +1 -1
- package/dist/components/WidgetLoading.d.ts +1 -0
- package/dist/components/WidgetLoading.js +5 -0
- package/dist/components/Wizard/Wizard.js +1 -1
- package/dist/components/shadcn/command.js +1 -1
- package/dist/components/themeWrapper.js +3 -2
- package/dist/context/{LayerswapContext.d.ts → LayerswapProvider.d.ts} +3 -8
- package/dist/context/{LayerswapContext.js → LayerswapProvider.js} +8 -9
- package/dist/context/authContext.js +1 -0
- package/dist/context/walletHooksProvider.js +1 -0
- package/dist/hooks/useWallet.js +10 -14
- package/dist/index.css +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -4
- package/dist/index.mjs +19 -0
- package/dist/lib/AppSettings.d.ts +7 -3
- package/dist/lib/AppSettings.js +8 -7
- package/dist/lib/address/formatter/index.js +8 -9
- package/dist/lib/address/validator/index.js +18 -20
- package/dist/lib/axiosInterceptor.js +1 -2
- package/dist/lib/balances/balanceResolver.js +16 -16
- package/dist/lib/balances/providers/evmBalanceProvider.js +3 -3
- package/dist/lib/balances/providers/loopringBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/loopringBalanceProvider.js +56 -43
- package/dist/lib/balances/providers/paradexBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/paradexBalanceProvider.js +42 -42
- package/dist/lib/balances/providers/solanaBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/solanaBalanceProvider.js +70 -71
- package/dist/lib/balances/providers/starknetBalanceProvider.d.ts +0 -6
- package/dist/lib/balances/providers/starknetBalanceProvider.js +48 -45
- package/dist/lib/balances/providers/tonBalanceProvider.d.ts +0 -18
- package/dist/lib/balances/providers/tonBalanceProvider.js +104 -100
- package/dist/lib/balances/providers/tronBalanceResolver.js +2 -3
- package/dist/lib/fuels/common/FakeAccount.d.ts +0 -24
- package/dist/lib/fuels/common/FakeAccount.js +58 -36
- package/dist/lib/fuels/common/PredicateConnector.d.ts +0 -54
- package/dist/lib/fuels/common/PredicateConnector.js +292 -205
- package/dist/lib/fuels/common/PredicateFactory.d.ts +0 -29
- package/dist/lib/fuels/common/PredicateFactory.js +123 -76
- package/dist/lib/fuels/common/PredicateWalletAdapter.d.ts +0 -17
- package/dist/lib/fuels/common/PredicateWalletAdapter.js +44 -29
- package/dist/lib/fuels/common/index.d.ts +0 -4
- package/dist/lib/fuels/common/index.js +4 -4
- package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.d.ts +0 -51
- package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.js +268 -234
- package/dist/lib/fuels/connectors/fuel-wallet/index.d.ts +0 -2
- package/dist/lib/fuels/connectors/fuel-wallet/index.js +2 -2
- package/dist/lib/fuels/connectors/fuel-wallet/types.d.ts +0 -50
- package/dist/lib/fuels/connectors/fuel-wallet/types.js +53 -9
- package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.d.ts +0 -7
- package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.js +20 -19
- package/dist/lib/fuels/connectors/fuelet-wallet/index.d.ts +0 -1
- package/dist/lib/fuels/connectors/fuelet-wallet/index.js +1 -1
- package/dist/lib/gases/gasResolver.d.ts +1 -1
- package/dist/lib/gases/gasResolver.js +10 -10
- package/dist/lib/gases/providers/evmGasProvider.js +5 -4
- package/dist/lib/gases/providers/loopringGasProvider.d.ts +0 -6
- package/dist/lib/gases/providers/loopringGasProvider.js +27 -24
- package/dist/lib/gases/providers/solanaGasProvider.d.ts +0 -7
- package/dist/lib/gases/providers/solanaGasProvider.js +32 -31
- package/dist/lib/gases/providers/starknetGasProvider.d.ts +0 -7
- package/dist/lib/gases/providers/starknetGasProvider.js +34 -33
- package/dist/lib/imtbl.d.ts +0 -69
- package/dist/lib/imtbl.js +63 -60
- package/dist/lib/internalApiClient.d.ts +0 -2
- package/dist/lib/internalApiClient.js +1 -4
- package/dist/lib/layerSwapApiClient.js +3 -3
- package/dist/lib/logError.js +2 -2
- package/dist/lib/nft/nftBalanceResolver.js +1 -2
- package/dist/lib/nft/providers/starknetNftProvider.d.ts +0 -6
- package/dist/lib/nft/providers/starknetNftProvider.js +49 -50
- package/dist/lib/wallets/connectors/EthereumProvider.d.ts +2 -2
- package/dist/lib/wallets/connectors/useSyncProviders/store.d.ts +1 -4
- package/dist/lib/wallets/fuel/Bako.d.ts +0 -15
- package/dist/lib/wallets/fuel/Bako.js +34 -29
- package/dist/lib/wallets/fuel/Basko.d.ts +0 -15
- package/dist/lib/wallets/fuel/Basko.js +34 -29
- package/dist/lib/wallets/fuel/useFuel.d.ts +0 -2
- package/dist/lib/wallets/fuel/useFuel.js +211 -192
- package/dist/lib/wallets/imtblX/useImtblX.d.ts +0 -2
- package/dist/lib/wallets/imtblX/useImtblX.js +87 -87
- package/dist/lib/wallets/paradex/Authorize/Ethereum.d.ts +0 -2
- package/dist/lib/wallets/paradex/Authorize/Ethereum.js +24 -23
- package/dist/lib/wallets/paradex/Authorize/Starknet.d.ts +0 -2
- package/dist/lib/wallets/paradex/Authorize/Starknet.js +14 -13
- package/dist/lib/wallets/paradex/lib/account.d.ts +0 -28
- package/dist/lib/wallets/paradex/lib/account.js +102 -53
- package/dist/lib/wallets/paradex/lib/index.d.ts +0 -24
- package/dist/lib/wallets/paradex/lib/index.js +20 -20
- package/dist/lib/wallets/paradex/lib/paraclear-provider.d.ts +0 -6
- package/dist/lib/wallets/paradex/lib/paraclear-provider.js +13 -9
- package/dist/lib/wallets/paradex/lib/paraclear.d.ts +0 -137
- package/dist/lib/wallets/paradex/lib/paraclear.js +258 -131
- package/dist/lib/wallets/paradex/lib/starknet-account-support.d.ts +0 -22
- package/dist/lib/wallets/paradex/lib/starknet-account-support.js +296 -220
- package/dist/lib/wallets/paradex/lib/starknet-signer.d.ts +0 -15
- package/dist/lib/wallets/paradex/lib/starknet-signer.js +120 -94
- package/dist/lib/wallets/paradex/useParadex.d.ts +0 -7
- package/dist/lib/wallets/paradex/useParadex.js +197 -194
- package/dist/lib/wallets/solana/transactionBuilder.d.ts +0 -4
- package/dist/lib/wallets/solana/transactionBuilder.js +63 -39
- package/dist/lib/wallets/solana/useSVM.d.ts +0 -5
- package/dist/lib/wallets/solana/useSVM.js +139 -142
- package/dist/lib/wallets/starknet/useStarknet.d.ts +0 -2
- package/dist/lib/wallets/starknet/useStarknet.js +139 -139
- package/dist/lib/wallets/ton/client.d.ts +0 -3
- package/dist/lib/wallets/ton/client.js +7 -7
- package/dist/lib/wallets/ton/useTON.d.ts +0 -2
- package/dist/lib/wallets/ton/useTON.js +121 -122
- package/dist/lib/wallets/tron/connectors/bitkeep.d.ts +0 -61
- package/dist/lib/wallets/tron/connectors/bitkeep.js +326 -303
- package/dist/lib/wallets/tron/connectors/index.d.ts +0 -4
- package/dist/lib/wallets/tron/connectors/index.js +4 -4
- package/dist/lib/wallets/tron/connectors/okxWallet.d.ts +0 -66
- package/dist/lib/wallets/tron/connectors/okxWallet.js +364 -336
- package/dist/lib/wallets/tron/connectors/tokenPocket.d.ts +0 -72
- package/dist/lib/wallets/tron/connectors/tokenPocket.js +337 -308
- package/dist/lib/wallets/tron/connectors/tronLink/index.d.ts +0 -102
- package/dist/lib/wallets/tron/connectors/tronLink/index.js +560 -520
- package/dist/lib/wallets/tron/connectors/tronLink/types.d.ts +0 -56
- package/dist/lib/wallets/tron/connectors/tronLink/types.js +53 -1
- package/dist/lib/wallets/tron/connectors/tronLink/utils.d.ts +0 -14
- package/dist/lib/wallets/tron/connectors/tronLink/utils.js +64 -61
- package/dist/lib/wallets/tron/useTron.d.ts +0 -2
- package/dist/lib/wallets/tron/useTron.js +111 -111
- package/dist/lib/wallets/utils/resolveWalletIcon.js +1 -0
- package/package.json +26 -77
- package/dist/hooks/useCopyClipboard.d.ts +0 -1
- package/dist/hooks/useCopyClipboard.js +0 -21
- package/dist/index.cjs +0 -125
- package/dist/lib/abis/ERC20.json +0 -258
- package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.d.ts +0 -42
- package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.js +0 -357
- package/dist/lib/fuels/connectors/walletConnect/constants.d.ts +0 -6
- package/dist/lib/fuels/connectors/walletConnect/constants.js +0 -7
- package/dist/lib/fuels/connectors/walletConnect/index.d.ts +0 -3
- package/dist/lib/fuels/connectors/walletConnect/index.js +0 -3
- package/dist/lib/fuels/connectors/walletConnect/types.d.ts +0 -12
- package/dist/lib/fuels/connectors/walletConnect/types.js +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/index.d.ts +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/index.js +0 -1
- package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.d.ts +0 -2
- package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.js +0 -39
- package/dist/lib/fuels/connectors/walletConnect/web3Modal.d.ts +0 -10
- package/dist/lib/fuels/connectors/walletConnect/web3Modal.js +0 -38
- package/dist/lib/loopring/LoopringAPI.d.ts +0 -12
- package/dist/lib/loopring/LoopringAPI.js +0 -13
- package/dist/lib/loopring/defs.d.ts +0 -425
- package/dist/lib/loopring/defs.js +0 -217
- package/dist/lib/loopring/eddsa.d.ts +0 -29
- package/dist/lib/loopring/eddsa.js +0 -208
- package/dist/lib/loopring/field.d.ts +0 -17
- package/dist/lib/loopring/field.js +0 -61
- package/dist/lib/loopring/formatter.d.ts +0 -137
- package/dist/lib/loopring/formatter.js +0 -516
- package/dist/lib/loopring/helpers.d.ts +0 -36
- package/dist/lib/loopring/helpers.js +0 -140
- package/dist/lib/loopring/jubjub.d.ts +0 -19
- package/dist/lib/loopring/jubjub.js +0 -79
- package/dist/lib/loopring/permutation.d.ts +0 -22
- package/dist/lib/loopring/permutation.js +0 -198
- package/dist/lib/loopring/poseidon/EDDSAUtil.d.ts +0 -14
- package/dist/lib/loopring/poseidon/EDDSAUtil.js +0 -61
- package/dist/lib/loopring/poseidon/babyJub.d.ts +0 -6
- package/dist/lib/loopring/poseidon/babyJub.js +0 -51
- package/dist/lib/loopring/poseidon/eddsa.d.ts +0 -29
- package/dist/lib/loopring/poseidon/eddsa.js +0 -210
- package/dist/lib/loopring/utils.d.ts +0 -76
- package/dist/lib/loopring/utils.js +0 -230
- package/dist/styles/dialog-transition.css +0 -28
- package/dist/styles/globals.css +0 -372
- package/dist/styles/manual-trasnfer-svg.css +0 -299
- package/dist/styles/vaul.css +0 -256
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
import * as ethUtil from 'ethereumjs-util';
|
|
2
|
-
import BN from 'bn.js';
|
|
3
|
-
import BigNumber from 'bignumber.js';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
import { MarketStatus, SEP, SoursURL, LOOPRING_URLs } from './defs';
|
|
6
|
-
BigNumber.config({
|
|
7
|
-
EXPONENTIAL_AT: 100,
|
|
8
|
-
RANGE: [-100000, 10000000],
|
|
9
|
-
ROUNDING_MODE: 1,
|
|
10
|
-
});
|
|
11
|
-
/**
|
|
12
|
-
* Returns hex string with '0x' prefix
|
|
13
|
-
* @param input
|
|
14
|
-
* @returns {string}
|
|
15
|
-
*/
|
|
16
|
-
export function addHexPrefix(input) {
|
|
17
|
-
if (typeof input === 'string') {
|
|
18
|
-
return input.startsWith('0x') ? input : '0x' + input;
|
|
19
|
-
}
|
|
20
|
-
throw new Error('Unsupported type');
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param mixed Buffer|number|string (hex string must be with '0x' prefix)
|
|
25
|
-
* @returns {Buffer}
|
|
26
|
-
*/
|
|
27
|
-
export function toBuffer(mixed) {
|
|
28
|
-
if (mixed instanceof Buffer) {
|
|
29
|
-
return mixed;
|
|
30
|
-
}
|
|
31
|
-
else if (typeof mixed === 'string' && !mixed.startsWith('0x')) {
|
|
32
|
-
return Buffer.from(mixed);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return ethUtil.toBuffer(mixed);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
*
|
|
40
|
-
* @param num number|string (hex string must be with '0x' prefix)
|
|
41
|
-
* @param places number of zeros to pad
|
|
42
|
-
* @returns {Buffer}
|
|
43
|
-
*/
|
|
44
|
-
export function zeroPad(num, places) {
|
|
45
|
-
return toBuffer(String(num).padStart(places, '0'));
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
|
|
50
|
-
* @returns {string}
|
|
51
|
-
*/
|
|
52
|
-
export function toHex(mixed) {
|
|
53
|
-
if (typeof mixed === 'number') {
|
|
54
|
-
return addHexPrefix(toBig(mixed).toString(16));
|
|
55
|
-
}
|
|
56
|
-
if (mixed instanceof BigNumber || mixed instanceof BN) {
|
|
57
|
-
return addHexPrefix(mixed.toString(16));
|
|
58
|
-
}
|
|
59
|
-
if (mixed instanceof Buffer || mixed instanceof Uint8Array) {
|
|
60
|
-
return addHexPrefix(mixed.toString('hex'));
|
|
61
|
-
}
|
|
62
|
-
if (typeof mixed === 'string') {
|
|
63
|
-
const regex = new RegExp(/^0x[0-9a-fA-F]*$/);
|
|
64
|
-
return regex.test(mixed) ? mixed : addHexPrefix(toBuffer(mixed).toString('hex'));
|
|
65
|
-
}
|
|
66
|
-
throw new Error('Unsupported type');
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
* @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
|
|
71
|
-
* @returns {number}
|
|
72
|
-
*/
|
|
73
|
-
export function toNumber(mixed) {
|
|
74
|
-
if (typeof mixed === 'number') {
|
|
75
|
-
return mixed;
|
|
76
|
-
}
|
|
77
|
-
if (mixed instanceof BigNumber || mixed instanceof BN) {
|
|
78
|
-
return mixed.toNumber();
|
|
79
|
-
}
|
|
80
|
-
if (typeof mixed === 'string') {
|
|
81
|
-
return Number(mixed);
|
|
82
|
-
}
|
|
83
|
-
if (mixed instanceof Buffer || mixed instanceof Uint8Array) {
|
|
84
|
-
return Number(mixed.toString('hex'));
|
|
85
|
-
}
|
|
86
|
-
throw new Error('Unsupported type');
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
*
|
|
90
|
-
* @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
|
|
91
|
-
* @returns {BigNumber}
|
|
92
|
-
*/
|
|
93
|
-
export function toBig(mixed) {
|
|
94
|
-
if (mixed instanceof BigNumber) {
|
|
95
|
-
return mixed;
|
|
96
|
-
}
|
|
97
|
-
if (typeof mixed === 'number') {
|
|
98
|
-
return new BigNumber(mixed.toString());
|
|
99
|
-
}
|
|
100
|
-
if (typeof mixed === 'string') {
|
|
101
|
-
return new BigNumber(mixed);
|
|
102
|
-
}
|
|
103
|
-
if (mixed instanceof Buffer || mixed instanceof Uint8Array) {
|
|
104
|
-
return new BigNumber(mixed.toString('hex'));
|
|
105
|
-
}
|
|
106
|
-
throw new Error('Unsupported type');
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
*
|
|
110
|
-
* @param mixed number | BigNumber | BN | Buffer | string
|
|
111
|
-
* @returns {BN}
|
|
112
|
-
*/
|
|
113
|
-
export function toBN(mixed) {
|
|
114
|
-
return mixed instanceof BN ? mixed : new BN(toBig(mixed).toString(10), 10);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
* @param value number | BigNumber | Buffer | string
|
|
119
|
-
* @returns {BN}
|
|
120
|
-
*/
|
|
121
|
-
export function fromGWEI(value) {
|
|
122
|
-
return new BigNumber(toBig(value).times(1e9).toFixed(0));
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
* @param value number | BigNumber | Buffer | string
|
|
127
|
-
* @returns {BN}
|
|
128
|
-
*/
|
|
129
|
-
export function toGWEI(value) {
|
|
130
|
-
return toBig(value).div(1e9);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Returns formatted hex string of a given private key
|
|
134
|
-
* @param mixed Buffer | string | Uint8Array
|
|
135
|
-
* @returns {string}
|
|
136
|
-
*/
|
|
137
|
-
export function formatKey(mixed) {
|
|
138
|
-
if (mixed instanceof Buffer || mixed instanceof Uint8Array) {
|
|
139
|
-
return mixed.toString('hex');
|
|
140
|
-
}
|
|
141
|
-
if (typeof mixed === 'string') {
|
|
142
|
-
return mixed.startsWith('0x') ? mixed.slice(2) : mixed;
|
|
143
|
-
}
|
|
144
|
-
throw new Error('Unsupported type');
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Returns hex string of a given address
|
|
148
|
-
* @param mixed Buffer | string |Uint8Array
|
|
149
|
-
* @returns {string}
|
|
150
|
-
*/
|
|
151
|
-
export function formatAddress(mixed) {
|
|
152
|
-
if (mixed instanceof Buffer || mixed instanceof Uint8Array) {
|
|
153
|
-
return ethUtil.toChecksumAddress('0x' + mixed.toString('hex'));
|
|
154
|
-
}
|
|
155
|
-
if (typeof mixed === 'string') {
|
|
156
|
-
return ethUtil.toChecksumAddress(mixed.startsWith('0x') ? mixed : '0x' + mixed);
|
|
157
|
-
}
|
|
158
|
-
throw new Error('Unsupported type');
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Returns hex string without '0x' prefix
|
|
162
|
-
* @param input string
|
|
163
|
-
* @returns {string}
|
|
164
|
-
*/
|
|
165
|
-
export function clearHexPrefix(input) {
|
|
166
|
-
if (typeof input === 'string') {
|
|
167
|
-
return input.startsWith('0x') ? input.slice(2) : input;
|
|
168
|
-
}
|
|
169
|
-
throw new Error('Unsupported type');
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
* @param hex
|
|
174
|
-
* @returns {string}
|
|
175
|
-
*/
|
|
176
|
-
export function padLeftEven(hex) {
|
|
177
|
-
return hex.length % 2 !== 0 ? `0${hex}` : hex;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Returns symbol of a given kind of currency
|
|
181
|
-
* @param settingsCurrency
|
|
182
|
-
* @returns {*}
|
|
183
|
-
*/
|
|
184
|
-
export function getDisplaySymbol(settingsCurrency) {
|
|
185
|
-
switch (settingsCurrency) {
|
|
186
|
-
case 'CNY':
|
|
187
|
-
return '¥';
|
|
188
|
-
case 'USD':
|
|
189
|
-
return '$';
|
|
190
|
-
default:
|
|
191
|
-
return '';
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Returns number in string with a given precision
|
|
196
|
-
* @param number number | BigNumber
|
|
197
|
-
* @param precision number
|
|
198
|
-
* @param ceil bool round up
|
|
199
|
-
* @returns {string}
|
|
200
|
-
*/
|
|
201
|
-
export function toFixed(number, precision, ceil) {
|
|
202
|
-
precision = precision || 0;
|
|
203
|
-
if (number instanceof BigNumber) {
|
|
204
|
-
const rm = ceil ? 0 : 1;
|
|
205
|
-
return number.toFixed(precision, rm);
|
|
206
|
-
}
|
|
207
|
-
if (typeof number === 'number') {
|
|
208
|
-
return ceil
|
|
209
|
-
? (Math.ceil(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision)
|
|
210
|
-
: (Math.floor(number * Number('1e' + precision)) / Number('1e' + precision)).toFixed(precision);
|
|
211
|
-
}
|
|
212
|
-
throw new Error('Unsupported type');
|
|
213
|
-
}
|
|
214
|
-
export function formatEddsaKey(key) {
|
|
215
|
-
const hexKey = clearHexPrefix(key);
|
|
216
|
-
return addHexPrefix(String(hexKey).padStart(64, '0'));
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Returns a number with commas as thousands separators
|
|
220
|
-
* @param number number
|
|
221
|
-
* @returns {*}
|
|
222
|
-
*/
|
|
223
|
-
export function numberWithCommas(number) {
|
|
224
|
-
if (number) {
|
|
225
|
-
number = number.toString().replace(/,/g, '');
|
|
226
|
-
if (isNaN(Number(number))) {
|
|
227
|
-
return '-';
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
const parts = number.toString().split('.');
|
|
231
|
-
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
232
|
-
return parts.join('.');
|
|
233
|
-
}
|
|
234
|
-
catch (err) {
|
|
235
|
-
return '-';
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
-
return number;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
export function sortObjDictionary(obj) {
|
|
243
|
-
const dataToSig = new Map();
|
|
244
|
-
if (obj) {
|
|
245
|
-
Reflect.ownKeys(obj)
|
|
246
|
-
.sort((a, b) => a.toString().localeCompare(b.toString()))
|
|
247
|
-
.forEach((key) => {
|
|
248
|
-
dataToSig.set(key.toString(), obj[key.toString()]);
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
return dataToSig;
|
|
252
|
-
}
|
|
253
|
-
export function makeMarket(raw_data) {
|
|
254
|
-
const coinMap = {};
|
|
255
|
-
const totalCoinMap = {};
|
|
256
|
-
const addressIndex = {};
|
|
257
|
-
const idIndex = {};
|
|
258
|
-
const tokensMap = {};
|
|
259
|
-
if (raw_data instanceof Array) {
|
|
260
|
-
raw_data.forEach((item) => {
|
|
261
|
-
if (item?.symbol.startsWith('LP-')) {
|
|
262
|
-
item.isLpToken = true;
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
item.isLpToken = false;
|
|
266
|
-
}
|
|
267
|
-
tokensMap[item.symbol] = item;
|
|
268
|
-
const coinInfo = {
|
|
269
|
-
icon: SoursURL + `ethereum/assets/${item.address}/logo.png`,
|
|
270
|
-
name: item.name,
|
|
271
|
-
simpleName: item.symbol,
|
|
272
|
-
description: item.type,
|
|
273
|
-
company: item.name,
|
|
274
|
-
};
|
|
275
|
-
if (!item.symbol.startsWith('LP-')) {
|
|
276
|
-
coinMap[item.symbol] = coinInfo;
|
|
277
|
-
}
|
|
278
|
-
totalCoinMap[item.symbol] = coinInfo;
|
|
279
|
-
addressIndex[item.address.toLowerCase()] = item.symbol;
|
|
280
|
-
// @ts-ignore
|
|
281
|
-
idIndex[/vault/gi.test(item.type?.toLowerCase()) ? item?.vaultTokenId : item.tokenId] =
|
|
282
|
-
item.symbol;
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
return {
|
|
286
|
-
tokensMap,
|
|
287
|
-
coinMap,
|
|
288
|
-
totalCoinMap,
|
|
289
|
-
idIndex,
|
|
290
|
-
addressIndex,
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
export function makeAmmPool(raw_data) {
|
|
294
|
-
const ammpools = {};
|
|
295
|
-
const pairs = {};
|
|
296
|
-
if (raw_data?.pools instanceof Array) {
|
|
297
|
-
raw_data.pools.forEach((item) => {
|
|
298
|
-
const market = item.market;
|
|
299
|
-
ammpools[market] = item;
|
|
300
|
-
let base = '', quote = '';
|
|
301
|
-
const ind = market.indexOf('-');
|
|
302
|
-
const ind2 = market.lastIndexOf('-');
|
|
303
|
-
base = market.substring(ind + 1, ind2);
|
|
304
|
-
quote = market.substring(ind2 + 1, market.length);
|
|
305
|
-
if (!pairs[base]) {
|
|
306
|
-
pairs[base] = {
|
|
307
|
-
tokenId: item.tokens.pooled[0],
|
|
308
|
-
tokenList: [quote],
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
pairs[base].tokenList = [...pairs[base].tokenList, quote];
|
|
313
|
-
}
|
|
314
|
-
if (!pairs[quote]) {
|
|
315
|
-
pairs[quote] = {
|
|
316
|
-
tokenId: item.tokens.pooled[1],
|
|
317
|
-
tokenList: [base],
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
pairs[quote].tokenList = [...pairs[quote].tokenList, base];
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
ammpools,
|
|
327
|
-
pairs,
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
export function makeMarkets(raw_data, url = LOOPRING_URLs.GET_MARKETS) {
|
|
331
|
-
const markets = {};
|
|
332
|
-
const pairs = {};
|
|
333
|
-
const isMix = url === LOOPRING_URLs.GET_MIX_MARKETS;
|
|
334
|
-
if (raw_data?.markets instanceof Array) {
|
|
335
|
-
raw_data.markets.forEach((item) => {
|
|
336
|
-
const marketInfo = {
|
|
337
|
-
...item,
|
|
338
|
-
baseTokenId: item.baseTokenId,
|
|
339
|
-
enabled: item.enabled,
|
|
340
|
-
market: item.market,
|
|
341
|
-
orderbookAggLevels: item.orderbookAggLevels,
|
|
342
|
-
precisionForPrice: item.precisionForPrice,
|
|
343
|
-
quoteTokenId: item.quoteTokenId,
|
|
344
|
-
};
|
|
345
|
-
if (isMix) {
|
|
346
|
-
marketInfo.status = item.status;
|
|
347
|
-
marketInfo.isSwapEnabled =
|
|
348
|
-
marketInfo.status === MarketStatus.ALL || marketInfo.status === MarketStatus.AMM;
|
|
349
|
-
marketInfo.createdAt = parseInt(item.createdAt);
|
|
350
|
-
}
|
|
351
|
-
markets[item.market] = marketInfo;
|
|
352
|
-
if (item.enabled) {
|
|
353
|
-
const market = item.market;
|
|
354
|
-
const ind = market.indexOf('-');
|
|
355
|
-
const base = market.substring(0, ind);
|
|
356
|
-
const quote = market.substring(ind + 1, market.length);
|
|
357
|
-
if (!pairs[base]) {
|
|
358
|
-
pairs[base] = {
|
|
359
|
-
tokenId: item.baseTokenId,
|
|
360
|
-
tokenList: [quote],
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
pairs[base].tokenList = [...pairs[base].tokenList, quote];
|
|
365
|
-
}
|
|
366
|
-
if (!pairs[quote]) {
|
|
367
|
-
pairs[quote] = {
|
|
368
|
-
tokenId: item.quoteTokenId,
|
|
369
|
-
tokenList: [base],
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
pairs[quote].tokenList = [...pairs[quote].tokenList, base];
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
const marketArr = Reflect.ownKeys(markets);
|
|
379
|
-
const tokenArr = Reflect.ownKeys(pairs);
|
|
380
|
-
return {
|
|
381
|
-
markets,
|
|
382
|
-
pairs,
|
|
383
|
-
tokenArr,
|
|
384
|
-
tokenArrStr: tokenArr.join(SEP),
|
|
385
|
-
marketArr,
|
|
386
|
-
marketArrStr: marketArr.join(SEP),
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
export function makeMarketsWithIdIndex(raw_data, url = LOOPRING_URLs.GET_MARKETS, idIndex) {
|
|
390
|
-
const markets = {};
|
|
391
|
-
const pairs = {};
|
|
392
|
-
const isMix = url === LOOPRING_URLs.GET_MIX_MARKETS;
|
|
393
|
-
if (raw_data?.markets instanceof Array) {
|
|
394
|
-
raw_data.markets.forEach((item) => {
|
|
395
|
-
const marketInfo = {
|
|
396
|
-
...item,
|
|
397
|
-
baseTokenId: item.baseTokenId,
|
|
398
|
-
enabled: item.enabled,
|
|
399
|
-
market: item.market,
|
|
400
|
-
orderbookAggLevels: item.orderbookAggLevels,
|
|
401
|
-
precisionForPrice: item.precisionForPrice,
|
|
402
|
-
quoteTokenId: item.quoteTokenId,
|
|
403
|
-
};
|
|
404
|
-
if (isMix) {
|
|
405
|
-
marketInfo.status = item.status;
|
|
406
|
-
marketInfo.isSwapEnabled =
|
|
407
|
-
marketInfo.status === MarketStatus.ALL || marketInfo.status === MarketStatus.AMM;
|
|
408
|
-
marketInfo.createdAt = parseInt(item.createdAt);
|
|
409
|
-
}
|
|
410
|
-
const base = idIndex[item.baseTokenId];
|
|
411
|
-
const quote = idIndex[item.quoteTokenId];
|
|
412
|
-
markets[`${base}-${quote}`] = {
|
|
413
|
-
...marketInfo,
|
|
414
|
-
market: `${base}-${quote}`,
|
|
415
|
-
};
|
|
416
|
-
if (item.enabled) {
|
|
417
|
-
if (!pairs[base]) {
|
|
418
|
-
pairs[base] = {
|
|
419
|
-
tokenId: item.baseTokenId,
|
|
420
|
-
tokenList: [quote],
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
pairs[base].tokenList = [...pairs[base].tokenList, quote];
|
|
425
|
-
}
|
|
426
|
-
if (!pairs[quote]) {
|
|
427
|
-
pairs[quote] = {
|
|
428
|
-
tokenId: item.quoteTokenId,
|
|
429
|
-
tokenList: [base],
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
pairs[quote].tokenList = [...pairs[quote].tokenList, base];
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
const marketArr = Reflect.ownKeys(markets);
|
|
439
|
-
const tokenArr = Reflect.ownKeys(pairs);
|
|
440
|
-
return {
|
|
441
|
-
markets,
|
|
442
|
-
pairs,
|
|
443
|
-
tokenArr,
|
|
444
|
-
tokenArrStr: tokenArr.join(SEP),
|
|
445
|
-
marketArr,
|
|
446
|
-
marketArrStr: marketArr.join(SEP),
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
export function makeInvestMarkets(raw_data, types) {
|
|
450
|
-
let markets = {};
|
|
451
|
-
let pairs = {};
|
|
452
|
-
// const isMix = url === LOOPRING_URLs.GET_MIX_MARKETS;
|
|
453
|
-
if (raw_data?.markets instanceof Array) {
|
|
454
|
-
let _markets = [];
|
|
455
|
-
if (types) {
|
|
456
|
-
_markets = raw_data.markets.filter((item) => types.includes(item.type?.toUpperCase()));
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
_markets = raw_data.markets;
|
|
460
|
-
}
|
|
461
|
-
_markets.forEach((item) => {
|
|
462
|
-
const marketInfo = {
|
|
463
|
-
...item,
|
|
464
|
-
};
|
|
465
|
-
markets[item.market] = marketInfo;
|
|
466
|
-
if (item.enabled) {
|
|
467
|
-
const [_markets, type, base, quote] = item.market.match(/^(\w+-)?(\w+)-(\w+)$/i);
|
|
468
|
-
if (type === 'DUAL-' && base && quote) {
|
|
469
|
-
if (!pairs[base]) {
|
|
470
|
-
pairs[base] = {
|
|
471
|
-
tokenId: item.baseTokenId,
|
|
472
|
-
tokenList: [quote],
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
pairs[base].tokenList = [...pairs[base].tokenList, quote];
|
|
477
|
-
}
|
|
478
|
-
if (!pairs[quote]) {
|
|
479
|
-
pairs[quote] = {
|
|
480
|
-
tokenId: item.baseTokenId,
|
|
481
|
-
tokenList: [base],
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
pairs[quote].tokenList = [...pairs[quote].tokenList, base];
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
else if (base && quote) {
|
|
489
|
-
const market = item.market;
|
|
490
|
-
// const ind = market.indexOf("-");
|
|
491
|
-
// const base = market.substring(0, ind);
|
|
492
|
-
// const quote = market.substring(ind + 1, market.length);
|
|
493
|
-
if (!pairs[base]) {
|
|
494
|
-
pairs[base] = {
|
|
495
|
-
tokenId: item.baseTokenId,
|
|
496
|
-
tokenList: [quote],
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
pairs[base].tokenList = [...pairs[base].tokenList, quote];
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
const marketArr = Reflect.ownKeys(markets);
|
|
507
|
-
const tokenArr = Reflect.ownKeys(pairs);
|
|
508
|
-
return {
|
|
509
|
-
markets,
|
|
510
|
-
pairs,
|
|
511
|
-
tokenArr,
|
|
512
|
-
tokenArrStr: tokenArr.join(SEP),
|
|
513
|
-
marketArr,
|
|
514
|
-
marketArrStr: marketArr.join(SEP),
|
|
515
|
-
};
|
|
516
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { AccountInfo, LpFee, OffchainFeeReqType, UnlockedAccount } from "./defs";
|
|
2
|
-
import { Token } from "../../Models/Network";
|
|
3
|
-
import { Config } from "wagmi";
|
|
4
|
-
export declare function unlockAccount(accInfo: AccountInfo, config: Config): Promise<UnlockedAccount>;
|
|
5
|
-
export declare function getOffchainFeeAmt(accountId: number, type: OffchainFeeReqType): Promise<LpFee>;
|
|
6
|
-
type TransferProps = {
|
|
7
|
-
unlockedAccount: UnlockedAccount;
|
|
8
|
-
accInfo: AccountInfo;
|
|
9
|
-
token: Token;
|
|
10
|
-
depositAddress: `0x${string}`;
|
|
11
|
-
amount: string;
|
|
12
|
-
call_data: string | undefined;
|
|
13
|
-
};
|
|
14
|
-
type TransferApiRes = {
|
|
15
|
-
hash: string;
|
|
16
|
-
resultInfo: undefined;
|
|
17
|
-
} | {
|
|
18
|
-
hash: undefined;
|
|
19
|
-
resultInfo: {
|
|
20
|
-
code: number;
|
|
21
|
-
message: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export declare function transfer({ accInfo, amount, depositAddress, call_data, token, unlockedAccount }: TransferProps, config: Config): Promise<TransferApiRes>;
|
|
25
|
-
type ActivateAccountProps = {
|
|
26
|
-
token: {
|
|
27
|
-
symbol: string;
|
|
28
|
-
id: number;
|
|
29
|
-
};
|
|
30
|
-
accInfo: AccountInfo;
|
|
31
|
-
};
|
|
32
|
-
export declare function activateAccount({ token, accInfo }: ActivateAccountProps, config: Config): Promise<{
|
|
33
|
-
x: string;
|
|
34
|
-
y: string;
|
|
35
|
-
}>;
|
|
36
|
-
export {};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { LoopringAPI } from "./LoopringAPI";
|
|
2
|
-
import { sortObjDictionary } from "./formatter";
|
|
3
|
-
import { signTypedData } from '@wagmi/core';
|
|
4
|
-
import { signMessage } from '@wagmi/core';
|
|
5
|
-
import { parseUnits } from 'viem';
|
|
6
|
-
import { KEY_MESSAGE, LOOPRING_URLs, OffchainFeeReqType } from "./defs";
|
|
7
|
-
import { generateKey, getEdDSASig, getTransferTypedData, getUpdateAccountEcdsaTypedData, get_EddsaSig_Transfer } from "./utils";
|
|
8
|
-
export async function unlockAccount(accInfo, config) {
|
|
9
|
-
let keySeed = accInfo.keySeed;
|
|
10
|
-
if (!keySeed) {
|
|
11
|
-
const exchangeInfo = await getExchangeInfo();
|
|
12
|
-
keySeed = KEY_MESSAGE.replace("${exchangeAddress}", exchangeInfo.exchangeAddress).replace("${nonce}", '0');
|
|
13
|
-
}
|
|
14
|
-
const sig = await signMessage(config, { message: keySeed });
|
|
15
|
-
const eddsaKeyData = generateKey(sig);
|
|
16
|
-
const { sk } = eddsaKeyData;
|
|
17
|
-
const { accountId } = accInfo;
|
|
18
|
-
const url = `${LoopringAPI.BaseApi}${LOOPRING_URLs.API_KEY_ACTION}?accountId=${accountId}`;
|
|
19
|
-
const dataToSign = sortObjDictionary({ accountId });
|
|
20
|
-
const eddsa = getEdDSASig("GET", LoopringAPI.BaseApi, LOOPRING_URLs.API_KEY_ACTION, dataToSign, sk);
|
|
21
|
-
const res = await (await fetch(url, {
|
|
22
|
-
headers: {
|
|
23
|
-
'X-Api-Sig': eddsa
|
|
24
|
-
}
|
|
25
|
-
})).json();
|
|
26
|
-
if (res.apiKey) {
|
|
27
|
-
return { eddsaKey: eddsaKeyData, apiKey: res.apiKey };
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw Error(`Could not unlock account, error:${res.resultInfo?.message || ' unknown'}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function getExchangeInfo() {
|
|
34
|
-
const result = await (await fetch(`${LoopringAPI.BaseApi}${LOOPRING_URLs.GET_EXCHANGE_INFO}`)).json();
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
export async function getOffchainFeeAmt(accountId, type) {
|
|
38
|
-
const result = await (await fetch(`${LoopringAPI.BaseApi}${LOOPRING_URLs.GET_OFFCHAIN_FEE_AMT}?accountId=${accountId}&requestType=${type}`)).json();
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
async function getNextStorageId(req, apiKey) {
|
|
42
|
-
const { accountId, tokenId } = req;
|
|
43
|
-
const url = `${LoopringAPI.BaseApi}${LOOPRING_URLs.GET_NEXT_STORAGE_ID}?accountId=${accountId}&sellTokenId=${tokenId}`;
|
|
44
|
-
const result = await (await fetch(url, {
|
|
45
|
-
headers: {
|
|
46
|
-
'X-Api-Key': apiKey
|
|
47
|
-
}
|
|
48
|
-
})).json();
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
export async function transfer({ accInfo, amount, depositAddress, call_data, token, unlockedAccount }, config) {
|
|
52
|
-
const exchangeInfo = await getExchangeInfo();
|
|
53
|
-
const { apiKey, eddsaKey } = unlockedAccount;
|
|
54
|
-
const storageId = await getNextStorageId({
|
|
55
|
-
accountId: accInfo.accountId,
|
|
56
|
-
tokenId: Number(token?.contract),
|
|
57
|
-
}, apiKey);
|
|
58
|
-
const feeData = await getOffchainFeeAmt(accInfo.accountId, OffchainFeeReqType.TRANSFER);
|
|
59
|
-
const fee = feeData.fees.find(f => f.token.toUpperCase() == token.symbol.toUpperCase())?.fee;
|
|
60
|
-
if (!fee) {
|
|
61
|
-
throw new Error(`Could not get fee for ${token.symbol.toUpperCase()}`);
|
|
62
|
-
}
|
|
63
|
-
const req = {
|
|
64
|
-
exchange: exchangeInfo.exchangeAddress,
|
|
65
|
-
payerAddr: accInfo.owner,
|
|
66
|
-
payerId: accInfo.accountId,
|
|
67
|
-
payeeAddr: depositAddress,
|
|
68
|
-
payeeId: 0,
|
|
69
|
-
storageId: storageId.offchainId,
|
|
70
|
-
token: {
|
|
71
|
-
tokenId: Number(token?.contract),
|
|
72
|
-
volume: parseUnits(amount, Number(token?.decimals)).toString(),
|
|
73
|
-
},
|
|
74
|
-
maxFee: {
|
|
75
|
-
tokenId: Number(token?.contract),
|
|
76
|
-
volume: fee,
|
|
77
|
-
},
|
|
78
|
-
validUntil: Math.round(Date.now() / 1000) + 30 * 86400,
|
|
79
|
-
...(call_data ? { memo: call_data } : {}),
|
|
80
|
-
};
|
|
81
|
-
return await submitInternalTransfer(req, apiKey, eddsaKey.sk, config);
|
|
82
|
-
}
|
|
83
|
-
async function submitInternalTransfer(req, apiKey, eddsaKey, config) {
|
|
84
|
-
const typedData = getTransferTypedData(req, LoopringAPI.CHAIN);
|
|
85
|
-
const ecdsaSignature = (await signTypedData(config, typedData)).slice(0, 132);
|
|
86
|
-
const eddsaSignature = get_EddsaSig_Transfer(req, eddsaKey).result;
|
|
87
|
-
return await (await fetch(`${LoopringAPI.BaseApi}${LOOPRING_URLs.POST_INTERNAL_TRANSFER}`, {
|
|
88
|
-
method: "POST",
|
|
89
|
-
body: JSON.stringify({
|
|
90
|
-
...req,
|
|
91
|
-
eddsaSignature,
|
|
92
|
-
ecdsaSignature: ecdsaSignature,
|
|
93
|
-
}),
|
|
94
|
-
headers: {
|
|
95
|
-
'Content-Type': 'application/json',
|
|
96
|
-
'X-Api-Sig': ecdsaSignature,
|
|
97
|
-
'X-Api-Key': apiKey
|
|
98
|
-
}
|
|
99
|
-
})).json();
|
|
100
|
-
}
|
|
101
|
-
export async function activateAccount({ token, accInfo }, config) {
|
|
102
|
-
const exchangeInfo = await getExchangeInfo();
|
|
103
|
-
const message = KEY_MESSAGE.replace("${exchangeAddress}", exchangeInfo.exchangeAddress).replace("${nonce}", accInfo.nonce.toString());
|
|
104
|
-
const sig = await signMessage(config, { message });
|
|
105
|
-
const eddsaKeyData = generateKey(sig);
|
|
106
|
-
const { formatedPx, formatedPy } = eddsaKeyData;
|
|
107
|
-
const publicKey = { x: formatedPx, y: formatedPy };
|
|
108
|
-
const feeData = await getOffchainFeeAmt(accInfo.accountId, OffchainFeeReqType.UPDATE_ACCOUNT);
|
|
109
|
-
const fee = feeData.fees.find(f => f.token.toUpperCase() == token.symbol.toUpperCase())?.fee;
|
|
110
|
-
if (!fee) {
|
|
111
|
-
throw new Error(`Could not get fee for ${token.symbol.toUpperCase()}`);
|
|
112
|
-
}
|
|
113
|
-
const req = {
|
|
114
|
-
exchange: exchangeInfo.exchangeAddress,
|
|
115
|
-
owner: accInfo.owner,
|
|
116
|
-
accountId: accInfo.accountId,
|
|
117
|
-
publicKey,
|
|
118
|
-
maxFee: {
|
|
119
|
-
tokenId: token.id,
|
|
120
|
-
volume: fee,
|
|
121
|
-
},
|
|
122
|
-
keySeed: message,
|
|
123
|
-
validUntil: Math.round(Date.now() / 1000) + 30 * 86400,
|
|
124
|
-
nonce: accInfo.nonce,
|
|
125
|
-
};
|
|
126
|
-
const typedData = getUpdateAccountEcdsaTypedData(req, LoopringAPI.CHAIN);
|
|
127
|
-
const ecdsaSignature = (await signTypedData(config, typedData)).slice(0, 132);
|
|
128
|
-
const activationReq = await (await fetch(`${LoopringAPI.BaseApi}${LOOPRING_URLs.ACCOUNT_ACTION}`, {
|
|
129
|
-
method: "POST",
|
|
130
|
-
body: JSON.stringify({ ...req, ecdsaSignature: ecdsaSignature }),
|
|
131
|
-
headers: {
|
|
132
|
-
'Content-Type': 'application/json',
|
|
133
|
-
'X-Api-Sig': ecdsaSignature
|
|
134
|
-
}
|
|
135
|
-
})).json();
|
|
136
|
-
if (activationReq?.resultInfo?.message) {
|
|
137
|
-
throw new Error(activationReq.resultInfo.message);
|
|
138
|
-
}
|
|
139
|
-
return publicKey;
|
|
140
|
-
}
|