@shogun-sdk/swap 0.0.2-test
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 +274 -0
- package/dist/core.cjs +619 -0
- package/dist/core.d.cts +137 -0
- package/dist/core.d.ts +137 -0
- package/dist/core.js +590 -0
- package/dist/execute-FaLLPp1i.d.cts +147 -0
- package/dist/execute-HX1fQ7wG.d.ts +147 -0
- package/dist/index.cjs +2477 -0
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +2458 -0
- package/dist/react.cjs +2364 -0
- package/dist/react.d.cts +158 -0
- package/dist/react.d.ts +158 -0
- package/dist/react.js +2355 -0
- package/dist/wallet-MmUIz8GE.d.cts +29 -0
- package/dist/wallet-MmUIz8GE.d.ts +29 -0
- package/dist/wallet-adapter.cjs +175 -0
- package/dist/wallet-adapter.d.cts +34 -0
- package/dist/wallet-adapter.d.ts +34 -0
- package/dist/wallet-adapter.js +150 -0
- package/package.json +68 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Transaction as Transaction$1 } from '@mysten/sui/transactions';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { CustomTransport, HttpTransport } from 'viem';
|
|
4
|
+
|
|
5
|
+
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
6
|
+
type EVMTransaction = {
|
|
7
|
+
data: string;
|
|
8
|
+
to: string;
|
|
9
|
+
from: string;
|
|
10
|
+
value: bigint | undefined;
|
|
11
|
+
};
|
|
12
|
+
type AnyTransaction = SolanaTransaction | EVMTransaction | Transaction$1;
|
|
13
|
+
declare enum ChainVM {
|
|
14
|
+
EVM = "EVM",
|
|
15
|
+
SVM = "SVM",
|
|
16
|
+
MVM = "MVM"
|
|
17
|
+
}
|
|
18
|
+
type AdaptedWallet = {
|
|
19
|
+
vmType: ChainVM;
|
|
20
|
+
getChainId: () => Promise<number>;
|
|
21
|
+
address: () => Promise<string>;
|
|
22
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
23
|
+
transport?: CustomTransport | HttpTransport;
|
|
24
|
+
sendTransaction: (transaction: AnyTransaction) => Promise<string>;
|
|
25
|
+
signTypedData?: (signData: any) => Promise<string>;
|
|
26
|
+
rpcUrl?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type { AdaptedWallet as A };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Transaction as Transaction$1 } from '@mysten/sui/transactions';
|
|
2
|
+
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { CustomTransport, HttpTransport } from 'viem';
|
|
4
|
+
|
|
5
|
+
type SolanaTransaction = Transaction | VersionedTransaction;
|
|
6
|
+
type EVMTransaction = {
|
|
7
|
+
data: string;
|
|
8
|
+
to: string;
|
|
9
|
+
from: string;
|
|
10
|
+
value: bigint | undefined;
|
|
11
|
+
};
|
|
12
|
+
type AnyTransaction = SolanaTransaction | EVMTransaction | Transaction$1;
|
|
13
|
+
declare enum ChainVM {
|
|
14
|
+
EVM = "EVM",
|
|
15
|
+
SVM = "SVM",
|
|
16
|
+
MVM = "MVM"
|
|
17
|
+
}
|
|
18
|
+
type AdaptedWallet = {
|
|
19
|
+
vmType: ChainVM;
|
|
20
|
+
getChainId: () => Promise<number>;
|
|
21
|
+
address: () => Promise<string>;
|
|
22
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
23
|
+
transport?: CustomTransport | HttpTransport;
|
|
24
|
+
sendTransaction: (transaction: AnyTransaction) => Promise<string>;
|
|
25
|
+
signTypedData?: (signData: any) => Promise<string>;
|
|
26
|
+
rpcUrl?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type { AdaptedWallet as A };
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/wallet-adapter/index.ts
|
|
21
|
+
var wallet_adapter_exports = {};
|
|
22
|
+
__export(wallet_adapter_exports, {
|
|
23
|
+
adaptEthersSigner: () => adaptEthersSigner,
|
|
24
|
+
adaptSolanaWallet: () => adaptSolanaWallet,
|
|
25
|
+
adaptViemWallet: () => adaptViemWallet
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(wallet_adapter_exports);
|
|
28
|
+
|
|
29
|
+
// src/wallet-adapter/svm-wallet-adapter/adapter.ts
|
|
30
|
+
var import_web3 = require("@solana/web3.js");
|
|
31
|
+
var adaptSolanaWallet = (walletAddress, chainId, rpcUrl, signAndSendTransaction) => {
|
|
32
|
+
let _chainId = chainId;
|
|
33
|
+
const connection = new import_web3.Connection(rpcUrl, { commitment: "confirmed" });
|
|
34
|
+
const getChainId = async () => _chainId;
|
|
35
|
+
const sendTransaction = async (transaction) => {
|
|
36
|
+
const txHash = await signAndSendTransaction(transaction);
|
|
37
|
+
console.log(`\u{1F6F0} Sent transaction: ${txHash}`);
|
|
38
|
+
const maxRetries = 20;
|
|
39
|
+
const delayMs = 2e3;
|
|
40
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
41
|
+
const res = await connection.getSignatureStatus(txHash, { searchTransactionHistory: true });
|
|
42
|
+
if (res?.value?.confirmationStatus === "confirmed" || res?.value?.confirmationStatus === "finalized") {
|
|
43
|
+
return txHash;
|
|
44
|
+
}
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
46
|
+
}
|
|
47
|
+
throw new Error(`Transaction not confirmed after ${maxRetries * (delayMs / 1e3)}s`);
|
|
48
|
+
};
|
|
49
|
+
const signTypedData = async () => {
|
|
50
|
+
throw new Error("signTypedData not implemented for Solana");
|
|
51
|
+
};
|
|
52
|
+
const switchChain = async (newChainId) => {
|
|
53
|
+
_chainId = newChainId;
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
vmType: "SVM" /* SVM */,
|
|
57
|
+
getChainId,
|
|
58
|
+
address: async () => walletAddress,
|
|
59
|
+
sendTransaction,
|
|
60
|
+
switchChain,
|
|
61
|
+
signTypedData,
|
|
62
|
+
rpcUrl
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
67
|
+
var import_ethers = require("ethers/lib/ethers.js");
|
|
68
|
+
var import_utils = require("ethers/lib/utils.js");
|
|
69
|
+
var import_viem = require("viem");
|
|
70
|
+
function isEVMTransaction(tx) {
|
|
71
|
+
return typeof tx.from === "string";
|
|
72
|
+
}
|
|
73
|
+
var adaptEthersSigner = (signer, transport) => {
|
|
74
|
+
const signTypedData = async (signData) => {
|
|
75
|
+
const typedSigner = signer;
|
|
76
|
+
return await typedSigner._signTypedData(
|
|
77
|
+
signData.domain,
|
|
78
|
+
signData.types,
|
|
79
|
+
signData.value
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
const sendTransaction = async (transaction) => {
|
|
83
|
+
if (!isEVMTransaction(transaction)) {
|
|
84
|
+
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
85
|
+
}
|
|
86
|
+
const tx = await signer.sendTransaction({
|
|
87
|
+
from: transaction.from,
|
|
88
|
+
to: transaction.to,
|
|
89
|
+
data: transaction.data,
|
|
90
|
+
value: transaction.value
|
|
91
|
+
});
|
|
92
|
+
return tx.hash;
|
|
93
|
+
};
|
|
94
|
+
const switchChain = async (chainId) => {
|
|
95
|
+
try {
|
|
96
|
+
await window.ethereum.request({
|
|
97
|
+
method: "wallet_switchEthereumChain",
|
|
98
|
+
params: [{ chainId: (0, import_utils.hexValue)(chainId) }]
|
|
99
|
+
});
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error("Failed to switch chain:", error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
return {
|
|
106
|
+
vmType: "EVM" /* EVM */,
|
|
107
|
+
transport,
|
|
108
|
+
getChainId: async () => signer.getChainId(),
|
|
109
|
+
address: async () => signer.getAddress(),
|
|
110
|
+
sendTransaction,
|
|
111
|
+
signTypedData,
|
|
112
|
+
switchChain
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
var adaptViemWallet = (wallet) => {
|
|
116
|
+
const signTypedData = async (signData) => {
|
|
117
|
+
return await wallet.signTypedData({
|
|
118
|
+
account: wallet.account,
|
|
119
|
+
domain: signData.domain,
|
|
120
|
+
types: signData.types,
|
|
121
|
+
primaryType: signData.primaryType ?? "Order",
|
|
122
|
+
message: signData.value
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const sendTransaction = async (transaction) => {
|
|
126
|
+
if (!isEVMTransaction(transaction)) {
|
|
127
|
+
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
128
|
+
}
|
|
129
|
+
const tx = await wallet.sendTransaction({
|
|
130
|
+
from: transaction.from,
|
|
131
|
+
to: transaction.to,
|
|
132
|
+
data: transaction.data,
|
|
133
|
+
value: transaction.value,
|
|
134
|
+
account: wallet.account?.address,
|
|
135
|
+
chain: wallet.chain
|
|
136
|
+
});
|
|
137
|
+
return tx;
|
|
138
|
+
};
|
|
139
|
+
const switchChain = async (chainId) => {
|
|
140
|
+
try {
|
|
141
|
+
await wallet.switchChain({ id: chainId });
|
|
142
|
+
} catch (e) {
|
|
143
|
+
const msg = e?.message || "";
|
|
144
|
+
if (msg.includes("does not support the requested chain")) {
|
|
145
|
+
throw new Error("Wallet does not support this chain");
|
|
146
|
+
}
|
|
147
|
+
if (msg.includes("rejected")) throw e;
|
|
148
|
+
if (msg.includes("already pending")) return;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const address = async () => {
|
|
152
|
+
let addr = wallet.account?.address;
|
|
153
|
+
if (!addr) {
|
|
154
|
+
const addresses = await wallet.getAddresses();
|
|
155
|
+
addr = addresses[0];
|
|
156
|
+
}
|
|
157
|
+
if (!addr) throw new Error("No address found");
|
|
158
|
+
return addr;
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
vmType: "EVM" /* EVM */,
|
|
162
|
+
transport: (0, import_viem.custom)(wallet.transport),
|
|
163
|
+
getChainId: async () => wallet.getChainId(),
|
|
164
|
+
address,
|
|
165
|
+
sendTransaction,
|
|
166
|
+
signTypedData,
|
|
167
|
+
switchChain
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
171
|
+
0 && (module.exports = {
|
|
172
|
+
adaptEthersSigner,
|
|
173
|
+
adaptSolanaWallet,
|
|
174
|
+
adaptViemWallet
|
|
175
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { VersionedTransaction, SendOptions, TransactionSignature } from '@solana/web3.js';
|
|
2
|
+
import { A as AdaptedWallet } from './wallet-MmUIz8GE.cjs';
|
|
3
|
+
import { Signer } from 'ethers/lib/ethers.js';
|
|
4
|
+
import { CustomTransport, HttpTransport, WalletClient } from 'viem';
|
|
5
|
+
import '@mysten/sui/transactions';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a Solana-compatible wallet implementation in the {@link AdaptedWallet} interface.
|
|
9
|
+
*
|
|
10
|
+
* @param walletAddress - The active Solana account public key as a base58 string.
|
|
11
|
+
* @param chainId - Numeric identifier representing the target Solana cluster.
|
|
12
|
+
* @param rpcUrl - RPC endpoint used for follow-on requests (exposed for consumers that need it).
|
|
13
|
+
* @param signAndSendTransaction - Wallet-supplied runner that signs and submits {@link VersionedTransaction}s.
|
|
14
|
+
* @returns An {@link AdaptedWallet} tailored for the Solana virtual machine (SVM).
|
|
15
|
+
*/
|
|
16
|
+
declare const adaptSolanaWallet: (walletAddress: string, chainId: number, rpcUrl: string, signAndSendTransaction: (transaction: VersionedTransaction, options?: SendOptions) => Promise<TransactionSignature>) => AdaptedWallet;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wraps an ethers {@link Signer} in the {@link AdaptedWallet} interface.
|
|
20
|
+
*
|
|
21
|
+
* @param signer - Ethers.js signer instance (e.g. from MetaMask, WalletConnect, JsonRpcProvider).
|
|
22
|
+
* @param transport - Optional transport used for RPC calls when delegating to `viem`.
|
|
23
|
+
* @returns An {@link AdaptedWallet} targeting the EVM.
|
|
24
|
+
*/
|
|
25
|
+
declare const adaptEthersSigner: (signer: Signer, transport?: CustomTransport | HttpTransport) => AdaptedWallet;
|
|
26
|
+
/**
|
|
27
|
+
* Wraps a `viem` {@link WalletClient} instance in the {@link AdaptedWallet} interface.
|
|
28
|
+
*
|
|
29
|
+
* @param wallet - Viem wallet client implementing transaction + signature primitives.
|
|
30
|
+
* @returns An {@link AdaptedWallet} targeting the EVM with viem semantics.
|
|
31
|
+
*/
|
|
32
|
+
declare const adaptViemWallet: (wallet: WalletClient) => AdaptedWallet;
|
|
33
|
+
|
|
34
|
+
export { adaptEthersSigner, adaptSolanaWallet, adaptViemWallet };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { VersionedTransaction, SendOptions, TransactionSignature } from '@solana/web3.js';
|
|
2
|
+
import { A as AdaptedWallet } from './wallet-MmUIz8GE.js';
|
|
3
|
+
import { Signer } from 'ethers/lib/ethers.js';
|
|
4
|
+
import { CustomTransport, HttpTransport, WalletClient } from 'viem';
|
|
5
|
+
import '@mysten/sui/transactions';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a Solana-compatible wallet implementation in the {@link AdaptedWallet} interface.
|
|
9
|
+
*
|
|
10
|
+
* @param walletAddress - The active Solana account public key as a base58 string.
|
|
11
|
+
* @param chainId - Numeric identifier representing the target Solana cluster.
|
|
12
|
+
* @param rpcUrl - RPC endpoint used for follow-on requests (exposed for consumers that need it).
|
|
13
|
+
* @param signAndSendTransaction - Wallet-supplied runner that signs and submits {@link VersionedTransaction}s.
|
|
14
|
+
* @returns An {@link AdaptedWallet} tailored for the Solana virtual machine (SVM).
|
|
15
|
+
*/
|
|
16
|
+
declare const adaptSolanaWallet: (walletAddress: string, chainId: number, rpcUrl: string, signAndSendTransaction: (transaction: VersionedTransaction, options?: SendOptions) => Promise<TransactionSignature>) => AdaptedWallet;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Wraps an ethers {@link Signer} in the {@link AdaptedWallet} interface.
|
|
20
|
+
*
|
|
21
|
+
* @param signer - Ethers.js signer instance (e.g. from MetaMask, WalletConnect, JsonRpcProvider).
|
|
22
|
+
* @param transport - Optional transport used for RPC calls when delegating to `viem`.
|
|
23
|
+
* @returns An {@link AdaptedWallet} targeting the EVM.
|
|
24
|
+
*/
|
|
25
|
+
declare const adaptEthersSigner: (signer: Signer, transport?: CustomTransport | HttpTransport) => AdaptedWallet;
|
|
26
|
+
/**
|
|
27
|
+
* Wraps a `viem` {@link WalletClient} instance in the {@link AdaptedWallet} interface.
|
|
28
|
+
*
|
|
29
|
+
* @param wallet - Viem wallet client implementing transaction + signature primitives.
|
|
30
|
+
* @returns An {@link AdaptedWallet} targeting the EVM with viem semantics.
|
|
31
|
+
*/
|
|
32
|
+
declare const adaptViemWallet: (wallet: WalletClient) => AdaptedWallet;
|
|
33
|
+
|
|
34
|
+
export { adaptEthersSigner, adaptSolanaWallet, adaptViemWallet };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// src/wallet-adapter/svm-wallet-adapter/adapter.ts
|
|
2
|
+
import {
|
|
3
|
+
Connection
|
|
4
|
+
} from "@solana/web3.js";
|
|
5
|
+
var adaptSolanaWallet = (walletAddress, chainId, rpcUrl, signAndSendTransaction) => {
|
|
6
|
+
let _chainId = chainId;
|
|
7
|
+
const connection = new Connection(rpcUrl, { commitment: "confirmed" });
|
|
8
|
+
const getChainId = async () => _chainId;
|
|
9
|
+
const sendTransaction = async (transaction) => {
|
|
10
|
+
const txHash = await signAndSendTransaction(transaction);
|
|
11
|
+
console.log(`\u{1F6F0} Sent transaction: ${txHash}`);
|
|
12
|
+
const maxRetries = 20;
|
|
13
|
+
const delayMs = 2e3;
|
|
14
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
15
|
+
const res = await connection.getSignatureStatus(txHash, { searchTransactionHistory: true });
|
|
16
|
+
if (res?.value?.confirmationStatus === "confirmed" || res?.value?.confirmationStatus === "finalized") {
|
|
17
|
+
return txHash;
|
|
18
|
+
}
|
|
19
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Transaction not confirmed after ${maxRetries * (delayMs / 1e3)}s`);
|
|
22
|
+
};
|
|
23
|
+
const signTypedData = async () => {
|
|
24
|
+
throw new Error("signTypedData not implemented for Solana");
|
|
25
|
+
};
|
|
26
|
+
const switchChain = async (newChainId) => {
|
|
27
|
+
_chainId = newChainId;
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
vmType: "SVM" /* SVM */,
|
|
31
|
+
getChainId,
|
|
32
|
+
address: async () => walletAddress,
|
|
33
|
+
sendTransaction,
|
|
34
|
+
switchChain,
|
|
35
|
+
signTypedData,
|
|
36
|
+
rpcUrl
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/wallet-adapter/evm-wallet-adapter/adapter.ts
|
|
41
|
+
import "ethers/lib/ethers.js";
|
|
42
|
+
import { hexValue } from "ethers/lib/utils.js";
|
|
43
|
+
import {
|
|
44
|
+
custom
|
|
45
|
+
} from "viem";
|
|
46
|
+
function isEVMTransaction(tx) {
|
|
47
|
+
return typeof tx.from === "string";
|
|
48
|
+
}
|
|
49
|
+
var adaptEthersSigner = (signer, transport) => {
|
|
50
|
+
const signTypedData = async (signData) => {
|
|
51
|
+
const typedSigner = signer;
|
|
52
|
+
return await typedSigner._signTypedData(
|
|
53
|
+
signData.domain,
|
|
54
|
+
signData.types,
|
|
55
|
+
signData.value
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
const sendTransaction = async (transaction) => {
|
|
59
|
+
if (!isEVMTransaction(transaction)) {
|
|
60
|
+
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
61
|
+
}
|
|
62
|
+
const tx = await signer.sendTransaction({
|
|
63
|
+
from: transaction.from,
|
|
64
|
+
to: transaction.to,
|
|
65
|
+
data: transaction.data,
|
|
66
|
+
value: transaction.value
|
|
67
|
+
});
|
|
68
|
+
return tx.hash;
|
|
69
|
+
};
|
|
70
|
+
const switchChain = async (chainId) => {
|
|
71
|
+
try {
|
|
72
|
+
await window.ethereum.request({
|
|
73
|
+
method: "wallet_switchEthereumChain",
|
|
74
|
+
params: [{ chainId: hexValue(chainId) }]
|
|
75
|
+
});
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error("Failed to switch chain:", error);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
vmType: "EVM" /* EVM */,
|
|
83
|
+
transport,
|
|
84
|
+
getChainId: async () => signer.getChainId(),
|
|
85
|
+
address: async () => signer.getAddress(),
|
|
86
|
+
sendTransaction,
|
|
87
|
+
signTypedData,
|
|
88
|
+
switchChain
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var adaptViemWallet = (wallet) => {
|
|
92
|
+
const signTypedData = async (signData) => {
|
|
93
|
+
return await wallet.signTypedData({
|
|
94
|
+
account: wallet.account,
|
|
95
|
+
domain: signData.domain,
|
|
96
|
+
types: signData.types,
|
|
97
|
+
primaryType: signData.primaryType ?? "Order",
|
|
98
|
+
message: signData.value
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
const sendTransaction = async (transaction) => {
|
|
102
|
+
if (!isEVMTransaction(transaction)) {
|
|
103
|
+
throw new Error("Expected EVMTransaction but got SolanaTransaction");
|
|
104
|
+
}
|
|
105
|
+
const tx = await wallet.sendTransaction({
|
|
106
|
+
from: transaction.from,
|
|
107
|
+
to: transaction.to,
|
|
108
|
+
data: transaction.data,
|
|
109
|
+
value: transaction.value,
|
|
110
|
+
account: wallet.account?.address,
|
|
111
|
+
chain: wallet.chain
|
|
112
|
+
});
|
|
113
|
+
return tx;
|
|
114
|
+
};
|
|
115
|
+
const switchChain = async (chainId) => {
|
|
116
|
+
try {
|
|
117
|
+
await wallet.switchChain({ id: chainId });
|
|
118
|
+
} catch (e) {
|
|
119
|
+
const msg = e?.message || "";
|
|
120
|
+
if (msg.includes("does not support the requested chain")) {
|
|
121
|
+
throw new Error("Wallet does not support this chain");
|
|
122
|
+
}
|
|
123
|
+
if (msg.includes("rejected")) throw e;
|
|
124
|
+
if (msg.includes("already pending")) return;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const address = async () => {
|
|
128
|
+
let addr = wallet.account?.address;
|
|
129
|
+
if (!addr) {
|
|
130
|
+
const addresses = await wallet.getAddresses();
|
|
131
|
+
addr = addresses[0];
|
|
132
|
+
}
|
|
133
|
+
if (!addr) throw new Error("No address found");
|
|
134
|
+
return addr;
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
vmType: "EVM" /* EVM */,
|
|
138
|
+
transport: custom(wallet.transport),
|
|
139
|
+
getChainId: async () => wallet.getChainId(),
|
|
140
|
+
address,
|
|
141
|
+
sendTransaction,
|
|
142
|
+
signTypedData,
|
|
143
|
+
switchChain
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export {
|
|
147
|
+
adaptEthersSigner,
|
|
148
|
+
adaptSolanaWallet,
|
|
149
|
+
adaptViemWallet
|
|
150
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shogun-sdk/swap",
|
|
3
|
+
"version": "0.0.2-test",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Shogun Network Swap utilities and helpers",
|
|
6
|
+
"author": "Shogun Network",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/shogun-network/shogun-sdk.git"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./core": {
|
|
25
|
+
"types": "./dist/core.d.ts",
|
|
26
|
+
"require": "./dist/core.cjs",
|
|
27
|
+
"import": "./dist/core.js"
|
|
28
|
+
},
|
|
29
|
+
"./react": {
|
|
30
|
+
"types": "./dist/react.d.ts",
|
|
31
|
+
"require": "./dist/react.cjs",
|
|
32
|
+
"import": "./dist/react.js"
|
|
33
|
+
},
|
|
34
|
+
"./wallet-adapter": {
|
|
35
|
+
"types": "./dist/wallet-adapter.d.ts",
|
|
36
|
+
"require": "./dist/wallet-adapter.cjs",
|
|
37
|
+
"import": "./dist/wallet-adapter.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist/**",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "22.13.10",
|
|
48
|
+
"react": "^19.2.0",
|
|
49
|
+
"tsup": "^8.5.0",
|
|
50
|
+
"typescript": "5.8.2",
|
|
51
|
+
"viem": "^2.38.1"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@ethersproject/abstract-signer": "^5.7.0",
|
|
55
|
+
"@mysten/sui": "1.29.1",
|
|
56
|
+
"@solana/web3.js": "^1.98.4",
|
|
57
|
+
"ethers": "^5.6.1",
|
|
58
|
+
"wagmi": "2.18.0",
|
|
59
|
+
"@shogun-sdk/intents-sdk": "1.2.6-test"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"viem": "^2.38.1"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"clean": "rm -rf dist",
|
|
66
|
+
"build": "tsup"
|
|
67
|
+
}
|
|
68
|
+
}
|