@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Reservoir
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<h3 align="center">Relay Solana Wallet Adapter</h3>
|
|
2
|
+
|
|
3
|
+
### Installation
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
yarn add @relayprotocol/relay-svm-wallet-adapter @relayprotocol/relay-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Also make sure to install the peer dependencies required by the adapter if your application doesn't already include them:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
yarn add viem @relayprotocol/relay-sdk
|
|
13
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adaptSolanaWallet = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const relay_sdk_1 = require("@relayprotocol/relay-sdk");
|
|
6
|
+
const adaptSolanaWallet = (walletAddress, chainId, connection, signAndSendTransaction, payerKey) => {
|
|
7
|
+
let _chainId = chainId;
|
|
8
|
+
const getChainId = async () => {
|
|
9
|
+
return _chainId;
|
|
10
|
+
};
|
|
11
|
+
return {
|
|
12
|
+
vmType: 'svm',
|
|
13
|
+
getChainId,
|
|
14
|
+
address: async () => {
|
|
15
|
+
return walletAddress;
|
|
16
|
+
},
|
|
17
|
+
handleSignMessageStep: async () => {
|
|
18
|
+
throw new Error('Message signing not implemented for Solana');
|
|
19
|
+
},
|
|
20
|
+
handleSendTransactionStep: async (_chainId, stepItem) => {
|
|
21
|
+
const client = (0, relay_sdk_1.getClient)();
|
|
22
|
+
const instructions = stepItem?.data?.instructions?.map((i) => new web3_js_1.TransactionInstruction({
|
|
23
|
+
keys: i.keys.map((k) => ({
|
|
24
|
+
isSigner: k.isSigner,
|
|
25
|
+
isWritable: k.isWritable,
|
|
26
|
+
pubkey: new web3_js_1.PublicKey(k.pubkey)
|
|
27
|
+
})),
|
|
28
|
+
programId: new web3_js_1.PublicKey(i.programId),
|
|
29
|
+
data: Buffer.from(i.data, 'hex')
|
|
30
|
+
})) ?? [];
|
|
31
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
32
|
+
payerKey: new web3_js_1.PublicKey(payerKey ?? walletAddress),
|
|
33
|
+
instructions,
|
|
34
|
+
recentBlockhash: await connection
|
|
35
|
+
.getLatestBlockhash()
|
|
36
|
+
.then((b) => b.blockhash)
|
|
37
|
+
}).compileToV0Message(await Promise.all(stepItem?.data?.addressLookupTableAddresses?.map(async (address) => await connection
|
|
38
|
+
.getAddressLookupTable(new web3_js_1.PublicKey(address))
|
|
39
|
+
.then((res) => res.value)) ?? []));
|
|
40
|
+
const transaction = new web3_js_1.VersionedTransaction(messageV0);
|
|
41
|
+
const signature = await signAndSendTransaction(transaction, undefined, instructions, stepItem.data.instructions);
|
|
42
|
+
client.log(['Transaction Signature obtained', signature], relay_sdk_1.LogLevel.Verbose);
|
|
43
|
+
return signature.signature;
|
|
44
|
+
},
|
|
45
|
+
handleConfirmTransactionStep: async (txHash) => {
|
|
46
|
+
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
47
|
+
const result = await connection.confirmTransaction({
|
|
48
|
+
blockhash: blockhash,
|
|
49
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
|
50
|
+
signature: txHash
|
|
51
|
+
});
|
|
52
|
+
if (result.value.err) {
|
|
53
|
+
throw new Error(`Transaction failed: ${result.value.err}`);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
blockHash: result.context.slot.toString(),
|
|
57
|
+
blockNumber: result.context.slot,
|
|
58
|
+
txHash
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
switchChain: (chainId) => {
|
|
62
|
+
_chainId = chainId;
|
|
63
|
+
return new Promise((res) => res());
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
exports.adaptSolanaWallet = adaptSolanaWallet;
|
|
68
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":";;;AAAA,6CASwB;AACxB,wDAKiC;AAW1B,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;QACtB,CAAC;QACD,qBAAqB,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC/D,CAAC;QACD,yBAAyB,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;YACtD,MAAM,MAAM,GAAG,IAAA,qBAAS,GAAE,CAAA;YAE1B,MAAM,YAAY,GAChB,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,CAC/B,CAAC,CAAC,EAAE,EAAE,CACJ,IAAI,gCAAsB,CAAC;gBACzB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,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