@relayprotocol/relay-svm-wallet-adapter 11.0.0
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/LICENSE +21 -0
- package/README.md +13 -0
- package/_cjs/package.json +1 -0
- package/_cjs/src/adapter.js +68 -0
- package/_cjs/src/adapter.js.map +1 -0
- package/_cjs/src/index.js +5 -0
- package/_cjs/src/index.js.map +1 -0
- package/_cjs/tsconfig.build.tsbuildinfo +1 -0
- package/_esm/package.json +1 -0
- package/_esm/src/adapter.js +75 -0
- package/_esm/src/adapter.js.map +1 -0
- package/_esm/src/index.js +2 -0
- package/_esm/src/index.js.map +1 -0
- package/_esm/tsconfig.build.tsbuildinfo +1 -0
- package/_types/src/adapter.d.ts +15 -0
- package/_types/src/adapter.d.ts.map +1 -0
- package/_types/src/index.d.ts +2 -0
- package/_types/src/index.d.ts.map +1 -0
- package/_types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module","sideEffects":false}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AddressLookupTableAccount, Connection, PublicKey, TransactionInstruction, TransactionMessage, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { LogLevel, getClient } from '@relayprotocol/relay-sdk';
|
|
3
|
+
/**
|
|
4
|
+
* Adapts a Solana wallet to work with the Relay SDK
|
|
5
|
+
* @param walletAddress - The public key address of the Solana wallet
|
|
6
|
+
* @param chainId - The chain ID for the Solana network (e.g., 101 for mainnet, 102 for testnet)
|
|
7
|
+
* @param connection - The Solana web3.js Connection instance for interacting with the network
|
|
8
|
+
* @param signAndSendTransaction - Function to sign and send a transaction, returning a promise with the transaction signature
|
|
9
|
+
* @param payerKey - Optional public key of the account that will pay for transaction fees (defaults to walletAddress)
|
|
10
|
+
* @returns An AdaptedWallet object that conforms to the Relay SDK interface
|
|
11
|
+
*/
|
|
12
|
+
export const adaptSolanaWallet = (walletAddress, chainId, connection, signAndSendTransaction, payerKey) => {
|
|
13
|
+
let _chainId = chainId;
|
|
14
|
+
const getChainId = async () => {
|
|
15
|
+
return _chainId;
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
vmType: 'svm',
|
|
19
|
+
getChainId,
|
|
20
|
+
address: async () => {
|
|
21
|
+
return walletAddress;
|
|
22
|
+
},
|
|
23
|
+
handleSignMessageStep: async () => {
|
|
24
|
+
throw new Error('Message signing not implemented for Solana');
|
|
25
|
+
},
|
|
26
|
+
handleSendTransactionStep: async (_chainId, stepItem) => {
|
|
27
|
+
const client = getClient();
|
|
28
|
+
const instructions = stepItem?.data?.instructions?.map((i) => new TransactionInstruction({
|
|
29
|
+
keys: i.keys.map((k) => ({
|
|
30
|
+
isSigner: k.isSigner,
|
|
31
|
+
isWritable: k.isWritable,
|
|
32
|
+
pubkey: new PublicKey(k.pubkey)
|
|
33
|
+
})),
|
|
34
|
+
programId: new PublicKey(i.programId),
|
|
35
|
+
data: Buffer.from(i.data, 'hex')
|
|
36
|
+
})) ?? [];
|
|
37
|
+
const messageV0 = new TransactionMessage({
|
|
38
|
+
payerKey: new PublicKey(payerKey ?? walletAddress),
|
|
39
|
+
instructions,
|
|
40
|
+
recentBlockhash: await connection
|
|
41
|
+
.getLatestBlockhash()
|
|
42
|
+
.then((b) => b.blockhash)
|
|
43
|
+
}).compileToV0Message(await Promise.all(stepItem?.data?.addressLookupTableAddresses?.map(async (address) => await connection
|
|
44
|
+
.getAddressLookupTable(new PublicKey(address))
|
|
45
|
+
.then((res) => res.value)) ?? []));
|
|
46
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
47
|
+
const signature = await signAndSendTransaction(transaction, undefined, instructions, stepItem.data.instructions);
|
|
48
|
+
client.log(['Transaction Signature obtained', signature], LogLevel.Verbose);
|
|
49
|
+
return signature.signature;
|
|
50
|
+
},
|
|
51
|
+
handleConfirmTransactionStep: async (txHash) => {
|
|
52
|
+
// Solana doesn't have a concept of replaced transactions
|
|
53
|
+
// So we don't need to handle onReplaced and onCancelled
|
|
54
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
55
|
+
const result = await connection.confirmTransaction({
|
|
56
|
+
blockhash: blockhash,
|
|
57
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
|
58
|
+
signature: txHash
|
|
59
|
+
});
|
|
60
|
+
if (result.value.err) {
|
|
61
|
+
throw new Error(`Transaction failed: ${result.value.err}`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
blockHash: result.context.slot.toString(),
|
|
65
|
+
blockNumber: result.context.slot,
|
|
66
|
+
txHash
|
|
67
|
+
};
|
|
68
|
+
},
|
|
69
|
+
switchChain: (chainId) => {
|
|
70
|
+
_chainId = chainId;
|
|
71
|
+
return new Promise((res) => res());
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EAGrB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,QAAQ,EACR,SAAS,EAGV,MAAM,0BAA0B,CAAA;AAEjC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,aAAqB,EACrB,OAAe,EACf,UAAsB,EACtB,sBAOE,EACF,QAAiB,EACF,EAAE;IACjB,IAAI,QAAQ,GAAG,OAAO,CAAA;IACtB,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;QAC5B,OAAO,QAAQ,CAAA;IACjB,CAAC,CAAA;IAED,OAAO;QACL,MAAM,EAAE,KAAK;QACb,UAAU;QACV,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,aAAa,CAAA;Q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