@swapkit/wallets 3.0.0-beta.2 → 3.0.0-beta.21
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/dist/chunk-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
- package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
- package/dist/chunk-ebfkk1jn.js +4 -0
- package/dist/{chunk-czhtd6cy.js.map → chunk-ebfkk1jn.js.map} +3 -3
- package/dist/chunk-k9q04afa.js +3 -0
- package/dist/{chunk-qadd75nn.js.map → chunk-k9q04afa.js.map} +3 -3
- package/dist/chunk-x5hgx9x9.js +3 -0
- package/dist/chunk-x5hgx9x9.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +3 -3
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +3 -3
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +3 -3
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +3 -3
- package/dist/src/cosmostation/index.cjs +3 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +3 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +3 -3
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +3 -3
- package/dist/src/evm-extensions/index.cjs +2 -2
- package/dist/src/evm-extensions/index.cjs.map +3 -3
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +3 -3
- package/dist/src/exodus/index.cjs +2 -2
- package/dist/src/exodus/index.cjs.map +3 -3
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +9 -9
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +9 -9
- package/dist/src/keepkey-bex/index.cjs +2 -2
- package/dist/src/keepkey-bex/index.cjs.map +4 -4
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +4 -4
- package/dist/src/keplr/index.cjs +2 -2
- package/dist/src/keplr/index.cjs.map +3 -3
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +3 -3
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +4 -4
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +16 -15
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +16 -15
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +3 -3
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +3 -3
- package/dist/src/onekey/index.cjs +2 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.js +1 -1
- package/dist/src/polkadotjs/index.js +1 -1
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.js +1 -1
- package/dist/src/trezor/index.cjs +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +4 -4
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +4 -4
- package/package.json +32 -27
- package/src/bitget/helpers.ts +4 -4
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +142 -0
- package/src/ctrl/walletHelpers.ts +82 -70
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +8 -9
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +3 -2
- package/src/keepkey/chains/thorchain.ts +3 -2
- package/src/keepkey/chains/utxo.ts +9 -2
- package/src/keepkey/coins.ts +10 -4
- package/src/keepkey/index.ts +15 -7
- package/src/keepkey-bex/index.ts +9 -14
- package/src/keepkey-bex/walletHelpers.ts +1 -1
- package/src/keplr/index.ts +4 -3
- package/src/keystore/helpers.ts +2 -4
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/cosmos.ts +5 -4
- package/src/ledger/clients/evm.ts +7 -6
- package/src/ledger/clients/thorchain/helpers.ts +9 -4
- package/src/ledger/clients/thorchain/index.ts +3 -3
- package/src/ledger/clients/thorchain/lib.ts +3 -2
- package/src/ledger/clients/thorchain/utils.ts +20 -9
- package/src/ledger/clients/utxo.ts +3 -5
- package/src/ledger/clients/xrp.ts +66 -0
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerAddress.ts +12 -3
- package/src/ledger/helpers/getLedgerClient.ts +56 -45
- package/src/ledger/helpers/getLedgerTransport.ts +5 -3
- package/src/ledger/index.ts +18 -7
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
- package/src/okx/helpers.ts +11 -9
- package/src/onekey/index.ts +3 -7
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +4 -4
- package/src/trezor/index.ts +14 -4
- package/src/types.ts +3 -0
- package/src/utils.ts +4 -0
- package/src/walletconnect/evmSigner.ts +6 -2
- package/src/walletconnect/index.ts +4 -4
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-czhtd6cy.js +0 -4
- package/dist/chunk-q81hzyra.js +0 -3
- package/dist/chunk-q81hzyra.js.map +0 -10
- package/dist/chunk-qadd75nn.js +0 -3
package/src/coinbase/signer.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CoinbaseWalletProvider } from "@coinbase/wallet-sdk";
|
|
2
2
|
import type { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk/dist/createCoinbaseWalletSDK.js";
|
|
3
|
-
import { Chain } from "@swapkit/helpers";
|
|
3
|
+
import { Chain, SwapKitError } from "@swapkit/helpers";
|
|
4
4
|
import type { Provider } from "ethers";
|
|
5
5
|
|
|
6
6
|
async function getCoinbaseMobileSigner(
|
|
@@ -22,7 +22,7 @@ async function getCoinbaseMobileSigner(
|
|
|
22
22
|
method: "eth_requestAccounts",
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
if (!accounts[0]) throw new
|
|
25
|
+
if (!accounts[0]) throw new SwapKitError("wallet_coinbase_no_accounts");
|
|
26
26
|
|
|
27
27
|
return accounts[0];
|
|
28
28
|
}
|
|
@@ -41,7 +41,7 @@ async function getCoinbaseMobileSigner(
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
signTypedData = () => {
|
|
44
|
-
throw new
|
|
44
|
+
throw new SwapKitError("wallet_coinbase_method_not_supported", { method: "signTypedData" });
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
connect(provider: Provider) {
|
|
@@ -78,6 +78,6 @@ export const getWalletMethods = async ({
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
default:
|
|
81
|
-
throw new
|
|
81
|
+
throw new SwapKitError("wallet_coinbase_chain_not_supported", { chain });
|
|
82
82
|
}
|
|
83
83
|
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { Keplr } from "@keplr-wallet/types";
|
|
2
|
+
import {
|
|
3
|
+
Chain,
|
|
4
|
+
ChainId,
|
|
5
|
+
ChainToChainId,
|
|
6
|
+
SwapKitError,
|
|
7
|
+
WalletOption,
|
|
8
|
+
createWallet,
|
|
9
|
+
filterSupportedChains,
|
|
10
|
+
} from "@swapkit/helpers";
|
|
11
|
+
|
|
12
|
+
const cosmostationSupportedChainIds = [ChainId.Cosmos, ChainId.Kujira, ChainId.THORChain] as const;
|
|
13
|
+
const cosmostationSupportedEVMChains = [
|
|
14
|
+
Chain.Ethereum,
|
|
15
|
+
Chain.BinanceSmartChain,
|
|
16
|
+
Chain.Avalanche,
|
|
17
|
+
Chain.Polygon,
|
|
18
|
+
Chain.Arbitrum,
|
|
19
|
+
Chain.Optimism,
|
|
20
|
+
Chain.Base,
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
declare global {
|
|
24
|
+
interface Window {
|
|
25
|
+
cosmostation?: {
|
|
26
|
+
providers?: {
|
|
27
|
+
keplr?: Keplr;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function connectCosmosChains(chains: Chain[], addChain: any, keplrProvider: Keplr) {
|
|
34
|
+
await Promise.all(
|
|
35
|
+
chains.map(async (chain) => {
|
|
36
|
+
const chainId = ChainToChainId[chain] as (typeof cosmostationSupportedChainIds)[number];
|
|
37
|
+
|
|
38
|
+
await keplrProvider.enable(chainId);
|
|
39
|
+
const signer = keplrProvider.getOfflineSignerOnlyAmino(chainId);
|
|
40
|
+
if (!signer) throw new SwapKitError("wallet_cosmostation_signer_not_found");
|
|
41
|
+
|
|
42
|
+
const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
43
|
+
|
|
44
|
+
const accounts = await signer.getAccounts();
|
|
45
|
+
if (!accounts?.[0]?.address) throw new SwapKitError("wallet_cosmostation_no_accounts");
|
|
46
|
+
|
|
47
|
+
const [{ address }] = accounts;
|
|
48
|
+
const toolbox = getCosmosToolbox(chain as any, { signer });
|
|
49
|
+
|
|
50
|
+
addChain({
|
|
51
|
+
...toolbox,
|
|
52
|
+
chain,
|
|
53
|
+
address,
|
|
54
|
+
walletType: WalletOption.COSMOSTATION,
|
|
55
|
+
});
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function connectEvmChains(chains: Chain[], addChain: any) {
|
|
61
|
+
const provider = window.ethereum;
|
|
62
|
+
|
|
63
|
+
if (!provider) {
|
|
64
|
+
throw new SwapKitError("wallet_cosmostation_evm_provider_not_found");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const accounts = (await provider.request({
|
|
68
|
+
method: "eth_requestAccounts",
|
|
69
|
+
})) as string[];
|
|
70
|
+
|
|
71
|
+
if (!accounts || accounts.length === 0) {
|
|
72
|
+
throw new SwapKitError("wallet_cosmostation_no_evm_accounts");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
76
|
+
|
|
77
|
+
for (const chain of chains) {
|
|
78
|
+
const toolbox = getEvmToolbox(chain as any, { provider });
|
|
79
|
+
const [address] = accounts;
|
|
80
|
+
|
|
81
|
+
if (!address) {
|
|
82
|
+
throw new SwapKitError("wallet_cosmostation_no_evm_address");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
addChain({
|
|
86
|
+
...toolbox,
|
|
87
|
+
chain,
|
|
88
|
+
address,
|
|
89
|
+
walletType: WalletOption.COSMOSTATION,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const cosmostationWallet = createWallet({
|
|
95
|
+
name: "connectCosmostation",
|
|
96
|
+
supportedChains: [
|
|
97
|
+
Chain.Cosmos,
|
|
98
|
+
Chain.Kujira,
|
|
99
|
+
Chain.THORChain,
|
|
100
|
+
Chain.Ethereum,
|
|
101
|
+
Chain.BinanceSmartChain,
|
|
102
|
+
Chain.Avalanche,
|
|
103
|
+
Chain.Polygon,
|
|
104
|
+
Chain.Arbitrum,
|
|
105
|
+
Chain.Optimism,
|
|
106
|
+
Chain.Base,
|
|
107
|
+
],
|
|
108
|
+
connect: ({ addChain, supportedChains }) =>
|
|
109
|
+
async function connectCosmostation(chains: Chain[]) {
|
|
110
|
+
const filteredChains = filterSupportedChains({
|
|
111
|
+
chains,
|
|
112
|
+
supportedChains,
|
|
113
|
+
walletType: WalletOption.COSMOSTATION,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (!window.cosmostation) {
|
|
117
|
+
throw new SwapKitError("wallet_cosmostation_not_found");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const cosmosChains = filteredChains.filter((chain) =>
|
|
121
|
+
cosmostationSupportedChainIds.includes(ChainToChainId[chain] as any),
|
|
122
|
+
);
|
|
123
|
+
const evmChains = filteredChains.filter((chain) =>
|
|
124
|
+
cosmostationSupportedEVMChains.includes(chain as any),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (cosmosChains.length > 0) {
|
|
128
|
+
const keplrProvider = window.cosmostation.providers?.keplr;
|
|
129
|
+
if (!keplrProvider) {
|
|
130
|
+
throw new SwapKitError("wallet_cosmostation_keplr_provider_not_found");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
await connectCosmosChains(cosmosChains, addChain, keplrProvider);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (evmChains.length > 0) {
|
|
137
|
+
await connectEvmChains(evmChains, addChain);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return true;
|
|
141
|
+
},
|
|
142
|
+
});
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type FeeOption,
|
|
9
9
|
SwapKitError,
|
|
10
10
|
WalletOption,
|
|
11
|
+
providerRequest,
|
|
11
12
|
} from "@swapkit/helpers";
|
|
12
13
|
import { erc20ABI } from "@swapkit/helpers/contracts";
|
|
13
14
|
import type { ApproveParams, CallParams, EVMTxParams } from "@swapkit/toolboxes/evm";
|
|
@@ -59,12 +60,14 @@ export async function getCtrlProvider<T extends Chain>(
|
|
|
59
60
|
Chain.Polygon,
|
|
60
61
|
() => window.xfi?.ethereum,
|
|
61
62
|
)
|
|
62
|
-
.with(Chain.Cosmos, Chain.Kujira,
|
|
63
|
+
.with(Chain.Cosmos, Chain.Kujira, () => window.xfi?.keplr)
|
|
63
64
|
.with(Chain.Bitcoin, () => window.xfi?.bitcoin)
|
|
64
65
|
.with(Chain.BitcoinCash, () => window.xfi?.bitcoincash)
|
|
65
66
|
.with(Chain.Dogecoin, () => window.xfi?.dogecoin)
|
|
66
67
|
.with(Chain.Litecoin, () => window.xfi?.litecoin)
|
|
67
68
|
.with(Chain.Solana, () => window.xfi?.solana)
|
|
69
|
+
.with(Chain.THORChain, () => window.xfi?.thorchain)
|
|
70
|
+
.with(Chain.Maya, () => window.xfi?.mayachain)
|
|
68
71
|
.otherwise(() => undefined);
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -90,55 +93,67 @@ async function transaction({
|
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
export async function getCtrlAddress(chain: Chain) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
errorKey: "wallet_provider_not_found",
|
|
97
|
-
info: { wallet: WalletOption.CTRL, chain },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
|
|
102
|
-
const provider = await getCtrlProvider(Chain.Cosmos);
|
|
103
|
-
if (!provider || "request" in provider) {
|
|
96
|
+
try {
|
|
97
|
+
const eipProvider = (await getCtrlProvider(chain)) as Eip1193Provider;
|
|
98
|
+
if (!eipProvider) {
|
|
104
99
|
throw new SwapKitError({
|
|
105
100
|
errorKey: "wallet_provider_not_found",
|
|
106
101
|
info: { wallet: WalletOption.CTRL, chain },
|
|
107
102
|
});
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
|
|
106
|
+
const provider = await getCtrlProvider(Chain.Cosmos);
|
|
107
|
+
if (!provider || "request" in provider) {
|
|
108
|
+
throw new SwapKitError({
|
|
109
|
+
errorKey: "wallet_provider_not_found",
|
|
110
|
+
info: { wallet: WalletOption.CTRL, chain },
|
|
111
|
+
});
|
|
112
|
+
}
|
|
115
113
|
|
|
116
|
-
|
|
114
|
+
// Enabling before using the Keplr is recommended.
|
|
115
|
+
// This method will ask the user whether to allow access if they haven't visited this website.
|
|
116
|
+
// Also, it will request that the user unlock the wallet if the wallet is locked.
|
|
117
|
+
const chainId = ChainToChainId[chain];
|
|
118
|
+
await provider.enable(chainId);
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
return item?.address;
|
|
120
|
-
}
|
|
120
|
+
const offlineSigner = provider.getOfflineSigner(chainId);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const [item] = await offlineSigner.getAccounts();
|
|
123
|
+
return item?.address;
|
|
124
|
+
}
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
if (EVMChains.includes(chain as EVMChain)) {
|
|
127
|
+
// For CTRL wallet, we need to use the request method directly on the provider
|
|
128
|
+
if ("request" in eipProvider && typeof eipProvider.request === "function") {
|
|
129
|
+
const accounts = await eipProvider.request({ method: "eth_requestAccounts" });
|
|
130
|
+
return accounts[0];
|
|
131
|
+
}
|
|
132
|
+
const { BrowserProvider } = await import("ethers");
|
|
133
|
+
const provider = new BrowserProvider(eipProvider, "any");
|
|
134
|
+
const [response] = await providerRequest({
|
|
135
|
+
provider,
|
|
136
|
+
method: "eth_requestAccounts",
|
|
137
|
+
params: [],
|
|
138
|
+
});
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
127
141
|
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
if (chain === Chain.Solana) {
|
|
143
|
+
const provider = await getCtrlProvider(Chain.Solana);
|
|
130
144
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
145
|
+
const accounts = await provider.connect();
|
|
146
|
+
return accounts.publicKey.toString();
|
|
147
|
+
}
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
149
|
+
const accounts = await eipProvider.request({ method: "request_accounts", params: [] });
|
|
150
|
+
return accounts[0];
|
|
151
|
+
} catch (_error) {
|
|
152
|
+
throw new SwapKitError({
|
|
153
|
+
errorKey: "wallet_provider_not_found",
|
|
154
|
+
info: { wallet: WalletOption.CTRL, chain },
|
|
155
|
+
});
|
|
156
|
+
}
|
|
142
157
|
}
|
|
143
158
|
|
|
144
159
|
export async function walletTransfer(
|
|
@@ -188,8 +203,9 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
188
203
|
if (!contractAddress) {
|
|
189
204
|
throw new SwapKitError("wallet_ctrl_contract_address_not_provided");
|
|
190
205
|
}
|
|
191
|
-
const { createContract, getCreateContractTxObject, isStateChangingCall
|
|
192
|
-
|
|
206
|
+
const { createContract, getCreateContractTxObject, isStateChangingCall } = await import(
|
|
207
|
+
"@swapkit/toolboxes/evm"
|
|
208
|
+
);
|
|
193
209
|
|
|
194
210
|
const isStateChanging = isStateChangingCall({ abi, funcName });
|
|
195
211
|
|
|
@@ -203,14 +219,14 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
203
219
|
txOverrides,
|
|
204
220
|
});
|
|
205
221
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
222
|
+
const signer = await provider.getSigner();
|
|
223
|
+
const tx = await signer.sendTransaction({
|
|
224
|
+
value: BigInt(value || 0),
|
|
225
|
+
from,
|
|
226
|
+
to,
|
|
227
|
+
data: data || "0x",
|
|
228
|
+
});
|
|
229
|
+
return tx.hash as T;
|
|
214
230
|
}
|
|
215
231
|
const contract = createContract(contractAddress, abi, provider);
|
|
216
232
|
|
|
@@ -219,9 +235,7 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
219
235
|
return typeof result?.hash === "string" ? result?.hash : result;
|
|
220
236
|
},
|
|
221
237
|
approve: async ({ assetAddress, spenderAddress, amount, from }: ApproveParams) => {
|
|
222
|
-
const { MAX_APPROVAL, getCreateContractTxObject
|
|
223
|
-
"@swapkit/toolboxes/evm"
|
|
224
|
-
);
|
|
238
|
+
const { MAX_APPROVAL, getCreateContractTxObject } = await import("@swapkit/toolboxes/evm");
|
|
225
239
|
const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];
|
|
226
240
|
const txOverrides = { from };
|
|
227
241
|
|
|
@@ -236,31 +250,29 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
236
250
|
const createTx = getCreateContractTxObject({ provider, chain });
|
|
237
251
|
const { value, to, data } = await createTx(functionCallParams);
|
|
238
252
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
253
|
+
const signer = await provider.getSigner();
|
|
254
|
+
const tx = await signer.sendTransaction({
|
|
255
|
+
value: BigInt(value || 0),
|
|
256
|
+
from,
|
|
257
|
+
to,
|
|
258
|
+
data: data || "0x",
|
|
259
|
+
});
|
|
260
|
+
return tx.hash;
|
|
247
261
|
},
|
|
248
|
-
sendTransaction: async (
|
|
249
|
-
const { from, to, data, value } =
|
|
262
|
+
sendTransaction: async (txParams: EVMTxParams) => {
|
|
263
|
+
const { from, to, data, value } = txParams;
|
|
250
264
|
if (!to) {
|
|
251
265
|
throw new SwapKitError("wallet_ctrl_send_transaction_no_address");
|
|
252
266
|
}
|
|
253
267
|
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
} as any,
|
|
263
|
-
]);
|
|
268
|
+
const signer = await provider.getSigner();
|
|
269
|
+
const tx = await signer.sendTransaction({
|
|
270
|
+
value: BigInt(value || 0),
|
|
271
|
+
from,
|
|
272
|
+
to,
|
|
273
|
+
data: data || "0x",
|
|
274
|
+
});
|
|
275
|
+
return tx.hash;
|
|
264
276
|
},
|
|
265
277
|
};
|
|
266
278
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ChainToHexChainId,
|
|
4
4
|
type EVMChain,
|
|
5
5
|
EVMChains,
|
|
6
|
+
SwapKitError,
|
|
6
7
|
WalletOption,
|
|
7
8
|
createWallet,
|
|
8
9
|
filterSupportedChains,
|
|
@@ -49,7 +50,7 @@ export const getWeb3WalletMethods = async ({
|
|
|
49
50
|
chain: EVMChain;
|
|
50
51
|
provider: BrowserProvider;
|
|
51
52
|
}) => {
|
|
52
|
-
if (!walletProvider) throw new
|
|
53
|
+
if (!walletProvider) throw new SwapKitError("wallet_evm_extensions_not_found");
|
|
53
54
|
const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
54
55
|
|
|
55
56
|
const signer = await provider.getSigner();
|
|
@@ -62,7 +63,7 @@ export const getWeb3WalletMethods = async ({
|
|
|
62
63
|
const networkParams = toolbox.getNetworkParams();
|
|
63
64
|
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
64
65
|
} catch (_error) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new SwapKitError("wallet_evm_extensions_failed_to_switch_network", { chain });
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -89,7 +90,7 @@ export const evmWallet = createWallet({
|
|
|
89
90
|
await Promise.all(
|
|
90
91
|
filteredChains.map(async (chain) => {
|
|
91
92
|
if (walletType === WalletOption.EIP6963) {
|
|
92
|
-
if (!eip1193Provider) throw new
|
|
93
|
+
if (!eip1193Provider) throw new SwapKitError("wallet_evm_extensions_no_provider");
|
|
93
94
|
|
|
94
95
|
const provider = new BrowserProvider(eip1193Provider, "any");
|
|
95
96
|
await provider.send("eth_requestAccounts", []);
|
package/src/exodus/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
prepareNetworkSwitch,
|
|
10
10
|
switchEVMWalletNetwork,
|
|
11
11
|
} from "@swapkit/helpers";
|
|
12
|
-
import
|
|
12
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
13
13
|
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
14
14
|
import {
|
|
15
15
|
AddressPurpose,
|
|
@@ -34,7 +34,6 @@ async function getWalletMethods({
|
|
|
34
34
|
}) {
|
|
35
35
|
switch (chain) {
|
|
36
36
|
case Chain.Bitcoin: {
|
|
37
|
-
const { Psbt } = await import("bitcoinjs-lib");
|
|
38
37
|
const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
39
38
|
|
|
40
39
|
let address = "";
|
|
@@ -50,11 +49,11 @@ async function getWalletMethods({
|
|
|
50
49
|
network: { type: BitcoinNetworkType.Mainnet },
|
|
51
50
|
},
|
|
52
51
|
onFinish: (response: GetAddressResponse) => {
|
|
53
|
-
if (!response.addresses[0]) throw new
|
|
52
|
+
if (!response.addresses[0]) throw new SwapKitError("wallet_exodus_no_address");
|
|
54
53
|
address = response.addresses[0].address;
|
|
55
54
|
},
|
|
56
55
|
onCancel: () => {
|
|
57
|
-
throw new
|
|
56
|
+
throw new SwapKitError("wallet_exodus_request_canceled");
|
|
58
57
|
},
|
|
59
58
|
};
|
|
60
59
|
|
|
@@ -80,7 +79,7 @@ async function getWalletMethods({
|
|
|
80
79
|
signedPsbt = Psbt.fromBase64(response.psbtBase64);
|
|
81
80
|
},
|
|
82
81
|
onCancel: () => {
|
|
83
|
-
throw new
|
|
82
|
+
throw new SwapKitError("wallet_exodus_signature_canceled");
|
|
84
83
|
},
|
|
85
84
|
};
|
|
86
85
|
|
|
@@ -104,7 +103,7 @@ async function getWalletMethods({
|
|
|
104
103
|
case Chain.Ethereum:
|
|
105
104
|
case Chain.Optimism:
|
|
106
105
|
case Chain.Polygon: {
|
|
107
|
-
if (!walletProvider) throw new
|
|
106
|
+
if (!walletProvider) throw new SwapKitError("wallet_exodus_not_found");
|
|
108
107
|
const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
109
108
|
|
|
110
109
|
const jsonRpcProvider = await getProvider(chain);
|
|
@@ -122,13 +121,13 @@ async function getWalletMethods({
|
|
|
122
121
|
await switchEVMWalletNetwork(browserProvider, chain, networkParams);
|
|
123
122
|
}
|
|
124
123
|
} catch (_error) {
|
|
125
|
-
throw new
|
|
124
|
+
throw new SwapKitError("wallet_exodus_failed_to_switch_network", { chain });
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
return { ...prepareNetworkSwitch({ toolbox, chain, provider: browserProvider }), address };
|
|
129
128
|
}
|
|
130
129
|
default:
|
|
131
|
-
throw new
|
|
130
|
+
throw new SwapKitError("wallet_exodus_chain_not_supported", { chain });
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
|
|
@@ -138,7 +137,7 @@ export const exodusWallet = createWallet({
|
|
|
138
137
|
supportedChains: [...EVMChains, Chain.Bitcoin],
|
|
139
138
|
connect: ({ addChain, walletType, supportedChains }) =>
|
|
140
139
|
async function connectExodusWallet(chains: Chain[], wallet: Wallet) {
|
|
141
|
-
if (!wallet) throw new
|
|
140
|
+
if (!wallet) throw new SwapKitError("wallet_exodus_instance_missing");
|
|
142
141
|
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
143
142
|
const { BrowserProvider } = await import("ethers");
|
|
144
143
|
|
|
@@ -21,64 +21,58 @@ export const cosmosWalletMethods = async ({
|
|
|
21
21
|
getFeeRateFromThorswap,
|
|
22
22
|
createStargateClient,
|
|
23
23
|
} = await import("@swapkit/toolboxes/cosmos");
|
|
24
|
+
const derivationPathString = derivationPath
|
|
25
|
+
? derivationPathToString(derivationPath)
|
|
26
|
+
: `${DerivationPath.GAIA}/0`;
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
: `${DerivationPath.GAIA}/0`;
|
|
28
|
+
const { address: fromAddress } = (await sdk.address.cosmosGetAddress({
|
|
29
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
30
|
+
})) as { address: string };
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
address_n: bip32ToAddressNList(derivationPathString),
|
|
32
|
-
})) as { address: string };
|
|
32
|
+
const toolbox = await getCosmosToolbox(Chain.Cosmos);
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
}
|
|
34
|
+
if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
|
|
35
|
+
DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(
|
|
36
|
+
await getFeeRateFromThorswap(ChainId.Cosmos, 500),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
// TODO support other cosmos assets
|
|
41
|
+
const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
|
|
42
|
+
const amount = assetValue.getBaseValue("string");
|
|
43
|
+
const accountInfo = await toolbox.getAccount(fromAddress);
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
type: "cosmos-sdk/MsgSend",
|
|
45
|
+
const keepKeySignedTx = await sdk.cosmos.cosmosSignAmino({
|
|
46
|
+
signerAddress: fromAddress,
|
|
47
|
+
signDoc: {
|
|
48
|
+
fee: DEFAULT_COSMOS_FEE_MAINNET,
|
|
49
|
+
memo: memo || "",
|
|
50
|
+
sequence: accountInfo?.sequence.toString() ?? "",
|
|
51
|
+
chain_id: ChainId.Cosmos,
|
|
52
|
+
account_number: accountInfo?.accountNumber.toString() ?? "",
|
|
53
|
+
msgs: [
|
|
54
|
+
{
|
|
55
|
+
value: {
|
|
56
|
+
amount: [{ denom: "uatom", amount }],
|
|
57
|
+
to_address: recipient,
|
|
58
|
+
from_address: fromAddress,
|
|
63
59
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
type: "cosmos-sdk/MsgSend",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
});
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const decodedBytes = atob(keepKeySignedTx.serialized);
|
|
67
|
+
const uint8Array = new Uint8Array(decodedBytes.length).map((_, i) =>
|
|
68
|
+
decodedBytes.charCodeAt(i),
|
|
69
|
+
);
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const client = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Cosmos]);
|
|
72
|
+
const response = await client.broadcastTx(uint8Array);
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
return response.transactionHash;
|
|
75
|
+
};
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
} catch (e) {
|
|
81
|
-
console.error(e);
|
|
82
|
-
throw e;
|
|
83
|
-
}
|
|
77
|
+
return { ...toolbox, transfer, address: fromAddress };
|
|
84
78
|
};
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
ChainToChainId,
|
|
5
5
|
type DerivationPathArray,
|
|
6
6
|
NetworkDerivationPath,
|
|
7
|
+
SwapKitError,
|
|
7
8
|
derivationPathToString,
|
|
8
9
|
} from "@swapkit/helpers";
|
|
9
10
|
import type { JsonRpcProvider, Provider, TransactionRequest } from "ethers";
|
|
@@ -35,7 +36,7 @@ export class KeepKeySigner extends AbstractSigner {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
signTypedData(): Promise<string> {
|
|
38
|
-
throw new
|
|
39
|
+
throw new SwapKitError("wallet_keepkey_method_not_supported", { method: "signTypedData" });
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
getAddress = async () => {
|
|
@@ -62,14 +63,21 @@ export class KeepKeySigner extends AbstractSigner {
|
|
|
62
63
|
gasPrice,
|
|
63
64
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
|
|
64
65
|
}: TransactionRequest) => {
|
|
65
|
-
if (!to)
|
|
66
|
-
|
|
67
|
-
if (!
|
|
66
|
+
if (!to)
|
|
67
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing to address" });
|
|
68
|
+
if (!gasLimit)
|
|
69
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing gasLimit" });
|
|
70
|
+
if (!data) throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing data" });
|
|
68
71
|
|
|
69
72
|
const isEIP1559 = !!((maxFeePerGas || maxPriorityFeePerGas) && !gasPrice);
|
|
70
|
-
if (isEIP1559 && !maxFeePerGas)
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
+
if (isEIP1559 && !maxFeePerGas)
|
|
74
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing maxFeePerGas" });
|
|
75
|
+
if (isEIP1559 && !maxPriorityFeePerGas)
|
|
76
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", {
|
|
77
|
+
reason: "Missing maxPriorityFeePerGas",
|
|
78
|
+
});
|
|
79
|
+
if (!(isEIP1559 || gasPrice))
|
|
80
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing gasPrice" });
|
|
73
81
|
|
|
74
82
|
const { toHexString } = await import("@swapkit/toolboxes/evm");
|
|
75
83
|
|
|
@@ -100,7 +108,7 @@ export class KeepKeySigner extends AbstractSigner {
|
|
|
100
108
|
};
|
|
101
109
|
|
|
102
110
|
sendTransaction = async (tx: TransactionRequest): Promise<any> => {
|
|
103
|
-
if (!this.provider) throw new
|
|
111
|
+
if (!this.provider) throw new SwapKitError("wallet_keepkey_no_provider");
|
|
104
112
|
|
|
105
113
|
const signedTxHex = await this.signTransaction(tx);
|
|
106
114
|
|