@relayprotocol/relay-ethers-wallet-adapter 22.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 +44 -0
- package/_cjs/package.json +1 -0
- package/_cjs/src/adapter.js +90 -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 +90 -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 +5 -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 +61 -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,44 @@
|
|
|
1
|
+
<h3 align="center">Adapted Ethers Wallet Adapter</h3>
|
|
2
|
+
|
|
3
|
+
### Installation
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
yarn add @relayprotocol/relay-ethers-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 ethers viem @relayprotocol/relay-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
16
|
+
|
|
17
|
+
To use the adapter simply pass in your ethers signer and receive a normalized AdaptedWallet object:
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
import { getClient } from "@relayprotocol/relay-sdk";
|
|
21
|
+
import { adaptEthersSigner } from "@relayprotocol/relay-ethers-wallet-adapter";
|
|
22
|
+
import { useSigner } from "wagmi";
|
|
23
|
+
|
|
24
|
+
const { data: signer } = useSigner();
|
|
25
|
+
const wallet = adaptEthersSigner(signer);
|
|
26
|
+
|
|
27
|
+
const quote = getClient().actions.getQuote({
|
|
28
|
+
chainId: 7777777,
|
|
29
|
+
toChainId: 8453,
|
|
30
|
+
txs: [{ to: "0x30385bce01da4b415cae1db21d41e9f6eab3ba50", value: "1000000" }],
|
|
31
|
+
wallet: wallet,
|
|
32
|
+
}, true);
|
|
33
|
+
|
|
34
|
+
getClient().actions.execute({
|
|
35
|
+
quote: quote,
|
|
36
|
+
wallet: wallet,
|
|
37
|
+
onProgress: (steps) => {
|
|
38
|
+
console.log(steps);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
In the code snippet above we use the wagmi `useSigner` method, which is not required, you can create your ethers signer however you wish. We then adapt the signer to the AdaptedWallet object and pass this into any of the SDK methods. Here we pass it into the call method along with the other required parameters.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adaptEthersSigner = void 0;
|
|
4
|
+
const relay_sdk_1 = require("@relayprotocol/relay-sdk");
|
|
5
|
+
const utils_js_1 = require("ethers/lib/utils.js");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const adaptEthersSigner = (signer, transport) => {
|
|
8
|
+
return {
|
|
9
|
+
vmType: 'evm',
|
|
10
|
+
transport,
|
|
11
|
+
getChainId: () => {
|
|
12
|
+
return signer.getChainId();
|
|
13
|
+
},
|
|
14
|
+
address: async () => {
|
|
15
|
+
return signer.getAddress();
|
|
16
|
+
},
|
|
17
|
+
handleSignMessageStep: async (stepItem) => {
|
|
18
|
+
const client = (0, relay_sdk_1.getClient)();
|
|
19
|
+
const signData = stepItem.data?.sign;
|
|
20
|
+
let signature;
|
|
21
|
+
if (signData) {
|
|
22
|
+
if (signData.signatureKind === 'eip191') {
|
|
23
|
+
client.log(['Execute Steps: Signing with eip191'], relay_sdk_1.LogLevel.Verbose);
|
|
24
|
+
if (signData.message.match(/0x[0-9a-fA-F]{64}/)) {
|
|
25
|
+
signature = await signer.signMessage((0, utils_js_1.arrayify)(signData.message));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
signature = await signer.signMessage(signData.message);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else if (signData.signatureKind === 'eip712') {
|
|
32
|
+
client.log(['Execute Steps: Signing with eip712'], relay_sdk_1.LogLevel.Verbose);
|
|
33
|
+
signature = await signer._signTypedData(signData.domain, signData.types, signData.value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return signature;
|
|
37
|
+
},
|
|
38
|
+
handleSendTransactionStep: async (_, stepItem) => {
|
|
39
|
+
const stepData = stepItem.data;
|
|
40
|
+
const transaction = await signer.sendTransaction({
|
|
41
|
+
data: stepData.data,
|
|
42
|
+
to: stepData.to,
|
|
43
|
+
from: stepData.from,
|
|
44
|
+
value: (0, viem_1.hexToBigInt)(stepData.value || 0),
|
|
45
|
+
...(stepData.maxFeePerGas && {
|
|
46
|
+
maxFeePerGas: (0, viem_1.hexToBigInt)(stepData.maxFeePerGas)
|
|
47
|
+
}),
|
|
48
|
+
...(stepData.maxPriorityFeePerGas && {
|
|
49
|
+
maxPriorityFeePerGas: (0, viem_1.hexToBigInt)(stepData.maxPriorityFeePerGas)
|
|
50
|
+
}),
|
|
51
|
+
...(stepData.gas && {
|
|
52
|
+
gasLimit: (0, viem_1.hexToBigInt)(stepData.gas)
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
return transaction.hash;
|
|
56
|
+
},
|
|
57
|
+
handleConfirmTransactionStep: async (txHash, chainId, onReplaced, onCancelled) => {
|
|
58
|
+
const client = (0, relay_sdk_1.getClient)();
|
|
59
|
+
const chain = client.chains.find((chain) => chain.id === chainId);
|
|
60
|
+
const viemClient = (0, viem_1.createPublicClient)({
|
|
61
|
+
chain: chain?.viemChain,
|
|
62
|
+
transport: transport ? (0, viem_1.fallback)([transport, (0, viem_1.http)()]) : (0, viem_1.http)()
|
|
63
|
+
});
|
|
64
|
+
const receipt = await viemClient.waitForTransactionReceipt({
|
|
65
|
+
hash: txHash,
|
|
66
|
+
onReplaced: (replacement) => {
|
|
67
|
+
if (replacement.reason === 'cancelled') {
|
|
68
|
+
onCancelled();
|
|
69
|
+
throw Error('Transaction cancelled');
|
|
70
|
+
}
|
|
71
|
+
onReplaced(replacement.transaction.hash);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return receipt;
|
|
75
|
+
},
|
|
76
|
+
switchChain: (chainId) => {
|
|
77
|
+
try {
|
|
78
|
+
return window.ethereum.request({
|
|
79
|
+
method: 'wallet_switchEthereumChain',
|
|
80
|
+
params: [{ chainId: (0, utils_js_1.hexValue)(chainId) }]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error('Failed to switch chain:', error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
exports.adaptEthersSigner = adaptEthersSigner;
|
|
90
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":";;;AACA,wDAIiC;AAEjC,kDAAwD;AACxD,+BAQa;AAEN,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,SAA2C,EAC5B,EAAE;IACjB,OAAO;QACL,MAAM,EAAE,KAAK;QACb,SAAS;QACT,UAAU,EAAE,GAAG,EAAE;YACf,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;QAC5B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,OAAO,MAAM,CAAC,UAAU,EAAE,CAAA;QAC5B,CAAC;QACD,qBAAqB,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;YACxC,MAAM,MAAM,GAAG,IAAA,qBAAS,GAAE,CAAA;YAC1B,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;YACpC,IAAI,SAA6B,CAAA;YACjC,IAAI,QAAQ,EAAE,CAAC;gBAEb,IAAI,QAAQ,CAAC,aAAa,KAAK,QAAQ,EAAE,CAAC;oBACxC,MAAM,CAAC,GAAG,CAAC,CAAC,oCAAoC,CAAC,E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