@rango-dev/signer-evm 0.1.15-next.3 → 0.1.15-next.5
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/helper.d.ts +3 -0
- package/dist/helper.d.ts.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/signer.d.ts +10 -2
- package/dist/signer.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/helper.ts +21 -0
- package/src/signer.ts +44 -41
package/dist/helper.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAC;AAE3D,eAAO,MAAM,aAAa,UAAW,GAAG,KAAG,WAkB1C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var E=Object.defineProperty;var o=(t,r)=>E(t,"name",{value:r,configurable:!0});import{SignerError as p,SignerErrorCode as h}from"rango-types";import{providers as l}from"ethers";import{SignerError as w,SignerErrorCode as f}from"rango-types";var d=o(t=>{let r;if(t&&Object.prototype.hasOwnProperty.call(t,"message")&&Object.prototype.hasOwnProperty.call(t,"code")&&Object.prototype.hasOwnProperty.call(t,"reason"))r=`Error sending the tx (code: ${t.code})`;else if(t&&Object.prototype.hasOwnProperty.call(t,"code")&&Object.prototype.hasOwnProperty.call(t,"message")&&t?.code===-32603)return new w(f.SEND_TX_ERROR,void 0,t.message);return new w(f.SEND_TX_ERROR,r,t)},"cleanEvmError");var a=class{constructor(r){this.provider=new l.Web3Provider(r),this.signer=this.provider.getSigner()}async signMessage(r){try{return await this.signer.signMessage(r)}catch(e){throw new p(h.SIGN_TX_ERROR,void 0,e)}}async signAndSendTx(r,e,i){try{let s=a.buildTx(r),n=await this.signer.getChainId(),c=await this.signer.getAddress();if(i&&n&&n.toString().toLowerCase()!==i?.toLowerCase())throw new p(h.UNEXPECTED_BEHAVIOUR,`Signer chainId: '${n}' doesn't match with required chainId: '${i}' for tx.`);if(c&&e&&c.toLowerCase()!==e.toLowerCase())throw new p(h.UNEXPECTED_BEHAVIOUR,`Signer address: '${c.toLowerCase()}' doesn't match with required address: '${e.toLowerCase()}' for tx.`);let g=await this.signer.sendTransaction(s);return{hash:g.hash,response:g}}catch(s){throw d(s)}}async wait(r,e,i){try{if(e)return await e?.wait(i),{hash:r};if(!this.provider)return{hash:r};let s=await this.provider.getTransaction(r);if(!s)throw Error(`Transaction hash '${r}' not found in blockchain.`);return await s.wait(i),{hash:r}}catch(s){let n=s;if(n?.code==="TRANSACTION_REPLACED"&&n?.replacement)return{hash:n?.replacement?.hash,response:n?.replacement};throw d(n)}}static buildTx(r){let e={};return r.from&&(e={...e,from:r.from}),r.to&&(e={...e,to:r.to}),r.data&&(e={...e,data:r.data}),r.value&&(e={...e,value:r.value}),r.nonce&&(e={...e,nonce:r.nonce}),r.gasLimit&&(e={...e,gasLimit:r.gasLimit}),r.gasPrice&&(e={...e,gasPrice:"0x"+parseInt(r.gasPrice).toString(16)}),r.maxFeePerGas&&(e={...e,maxFeePerGas:r.maxFeePerGas}),r.maxPriorityFeePerGas&&(e={...e,maxPriorityFeePerGas:r.maxPriorityFeePerGas}),e}};o(a,"DefaultEvmSigner");export{a as DefaultEvmSigner};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/signer.ts"],
|
|
4
|
-
"sourcesContent": ["import { TransactionRequest } from '@ethersproject/abstract-provider';\nimport { GenericSigner, SignerError, SignerErrorCode } from 'rango-types';\nimport { EvmTransaction } from 'rango-types/lib/api/main';\nimport { providers } from 'ethers';\n\nexport class DefaultEvmSigner implements GenericSigner<EvmTransaction> {\n private signer: providers.JsonRpcSigner;\n\n constructor(provider: providers.ExternalProvider) {\n this.
|
|
5
|
-
"mappings": "+EACA,OAAwB,eAAAA,EAAa,mBAAAC,MAAuB,cAE5D,OAAS,aAAAC,MAAiB,
|
|
6
|
-
"names": ["SignerError", "SignerErrorCode", "providers", "DefaultEvmSigner", "provider", "providers", "msg", "error", "SignerError", "SignerErrorCode", "tx", "address", "chainId", "transaction", "signerChainId", "signerAddress", "
|
|
3
|
+
"sources": ["../src/signer.ts", "../src/helper.ts"],
|
|
4
|
+
"sourcesContent": ["import { TransactionRequest, TransactionResponse } from '@ethersproject/abstract-provider';\nimport { GenericSigner, SignerError, SignerErrorCode } from 'rango-types';\nimport { EvmTransaction } from 'rango-types/lib/api/main';\nimport { providers } from 'ethers';\nimport { cleanEvmError } from './helper';\n\nexport class DefaultEvmSigner implements GenericSigner<EvmTransaction> {\n private signer: providers.JsonRpcSigner;\n private provider: providers.Web3Provider;\n\n constructor(provider: providers.ExternalProvider) {\n this.provider = new providers.Web3Provider(provider);\n this.signer = this.provider.getSigner();\n }\n\n async signMessage(msg: string): Promise<string> {\n try {\n return await this.signer.signMessage(msg);\n } catch (error) {\n throw new SignerError(SignerErrorCode.SIGN_TX_ERROR, undefined, error);\n }\n }\n\n async signAndSendTx(\n tx: EvmTransaction,\n address: string,\n chainId: string | null,\n ): Promise<{ hash: string; response: TransactionResponse }> {\n try {\n const transaction = DefaultEvmSigner.buildTx(tx);\n const signerChainId = await this.signer.getChainId();\n const signerAddress = await this.signer.getAddress();\n if (\n !!chainId &&\n !!signerChainId &&\n signerChainId.toString().toLowerCase() !== chainId?.toLowerCase()\n ) {\n throw new SignerError(\n SignerErrorCode.UNEXPECTED_BEHAVIOUR,\n `Signer chainId: '${signerChainId}' doesn't match with required chainId: '${chainId}' for tx.`,\n );\n }\n if (!!signerAddress && !!address && signerAddress.toLowerCase() !== address.toLowerCase()) {\n throw new SignerError(\n SignerErrorCode.UNEXPECTED_BEHAVIOUR,\n `Signer address: '${signerAddress.toLowerCase()}' doesn't match with required address: '${address.toLowerCase()}' for tx.`,\n );\n }\n const response = await this.signer.sendTransaction(transaction);\n return { hash: response.hash, response };\n } catch (error) {\n throw cleanEvmError(error);\n }\n }\n\n async wait(\n txHash: string,\n txResponse?: TransactionResponse,\n confirmations?: number | undefined,\n ): Promise<{ hash: string; response?: TransactionResponse }> {\n try {\n if (txResponse) {\n await txResponse?.wait(confirmations);\n return { hash: txHash };\n }\n if (!this.provider) return { hash: txHash }; // wallet not connected yet\n const tx = await this.provider.getTransaction(txHash);\n if (!tx) throw Error(`Transaction hash '${txHash}' not found in blockchain.`);\n await tx.wait(confirmations);\n return { hash: txHash };\n } catch (err) {\n const error = err as any; // TODO find a proper type\n if (error?.code === 'TRANSACTION_REPLACED' && error?.replacement)\n return { hash: error?.replacement?.hash, response: error?.replacement };\n throw cleanEvmError(error);\n }\n }\n\n static buildTx(evmTx: EvmTransaction): TransactionRequest {\n let tx: TransactionRequest = {};\n if (evmTx.from) tx = { ...tx, from: evmTx.from };\n if (evmTx.to) tx = { ...tx, to: evmTx.to };\n if (evmTx.data) tx = { ...tx, data: evmTx.data };\n if (evmTx.value) tx = { ...tx, value: evmTx.value };\n if (evmTx.nonce) tx = { ...tx, nonce: evmTx.nonce };\n if (evmTx.gasLimit) tx = { ...tx, gasLimit: evmTx.gasLimit };\n if (evmTx.gasPrice)\n tx = {\n ...tx,\n gasPrice: '0x' + parseInt(evmTx.gasPrice).toString(16),\n };\n if (evmTx.maxFeePerGas) tx = { ...tx, maxFeePerGas: evmTx.maxFeePerGas };\n if (evmTx.maxPriorityFeePerGas)\n tx = { ...tx, maxPriorityFeePerGas: evmTx.maxPriorityFeePerGas };\n return tx;\n }\n}\n", "import { SignerError, SignerErrorCode } from 'rango-types';\n\nexport const cleanEvmError = (error: any): SignerError => {\n let message = undefined;\n if (\n error &&\n Object.prototype.hasOwnProperty.call(error, 'message') &&\n Object.prototype.hasOwnProperty.call(error, 'code') &&\n Object.prototype.hasOwnProperty.call(error, 'reason')\n ) {\n message = `Error sending the tx (code: ${(error as any).code})`;\n } else if (\n error &&\n Object.prototype.hasOwnProperty.call(error, 'code') &&\n Object.prototype.hasOwnProperty.call(error, 'message') &&\n (error as any)?.code === -32603\n ) {\n return new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, (error as any).message);\n }\n return new SignerError(SignerErrorCode.SEND_TX_ERROR, message, error);\n};\n"],
|
|
5
|
+
"mappings": "+EACA,OAAwB,eAAAA,EAAa,mBAAAC,MAAuB,cAE5D,OAAS,aAAAC,MAAiB,SCH1B,OAAS,eAAAC,EAAa,mBAAAC,MAAuB,cAEtC,IAAMC,EAAgBC,EAACC,GAA4B,CACxD,IAAIC,EACJ,GACED,GACA,OAAO,UAAU,eAAe,KAAKA,EAAO,SAAS,GACrD,OAAO,UAAU,eAAe,KAAKA,EAAO,MAAM,GAClD,OAAO,UAAU,eAAe,KAAKA,EAAO,QAAQ,EAEpDC,EAAU,+BAAgCD,EAAc,gBAExDA,GACA,OAAO,UAAU,eAAe,KAAKA,EAAO,MAAM,GAClD,OAAO,UAAU,eAAe,KAAKA,EAAO,SAAS,GACpDA,GAAe,OAAS,OAEzB,OAAO,IAAIE,EAAYC,EAAgB,cAAe,OAAYH,EAAc,OAAO,EAEzF,OAAO,IAAIE,EAAYC,EAAgB,cAAeF,EAASD,CAAK,CACtE,EAlB6B,iBDItB,IAAMI,EAAN,KAAgE,CAIrE,YAAYC,EAAsC,CAChD,KAAK,SAAW,IAAIC,EAAU,aAAaD,CAAQ,EACnD,KAAK,OAAS,KAAK,SAAS,UAAU,CACxC,CAEA,MAAM,YAAYE,EAA8B,CAC9C,GAAI,CACF,OAAO,MAAM,KAAK,OAAO,YAAYA,CAAG,CAC1C,OAASC,EAAP,CACA,MAAM,IAAIC,EAAYC,EAAgB,cAAe,OAAWF,CAAK,CACvE,CACF,CAEA,MAAM,cACJG,EACAC,EACAC,EAC0D,CAC1D,GAAI,CACF,IAAMC,EAAcV,EAAiB,QAAQO,CAAE,EACzCI,EAAgB,MAAM,KAAK,OAAO,WAAW,EAC7CC,EAAgB,MAAM,KAAK,OAAO,WAAW,EACnD,GACIH,GACAE,GACFA,EAAc,SAAS,EAAE,YAAY,IAAMF,GAAS,YAAY,EAEhE,MAAM,IAAIJ,EACRC,EAAgB,qBAChB,oBAAoBK,4CAAwDF,YAC9E,EAEF,GAAMG,GAAmBJ,GAAWI,EAAc,YAAY,IAAMJ,EAAQ,YAAY,EACtF,MAAM,IAAIH,EACRC,EAAgB,qBAChB,oBAAoBM,EAAc,YAAY,4CAA4CJ,EAAQ,YAAY,YAChH,EAEF,IAAMK,EAAW,MAAM,KAAK,OAAO,gBAAgBH,CAAW,EAC9D,MAAO,CAAE,KAAMG,EAAS,KAAM,SAAAA,CAAS,CACzC,OAAST,EAAP,CACA,MAAMU,EAAcV,CAAK,CAC3B,CACF,CAEA,MAAM,KACJW,EACAC,EACAC,EAC2D,CAC3D,GAAI,CACF,GAAID,EACF,aAAMA,GAAY,KAAKC,CAAa,EAC7B,CAAE,KAAMF,CAAO,EAExB,GAAI,CAAC,KAAK,SAAU,MAAO,CAAE,KAAMA,CAAO,EAC1C,IAAMR,EAAK,MAAM,KAAK,SAAS,eAAeQ,CAAM,EACpD,GAAI,CAACR,EAAI,MAAM,MAAM,qBAAqBQ,6BAAkC,EAC5E,aAAMR,EAAG,KAAKU,CAAa,EACpB,CAAE,KAAMF,CAAO,CACxB,OAASG,EAAP,CACA,IAAMd,EAAQc,EACd,GAAId,GAAO,OAAS,wBAA0BA,GAAO,YACnD,MAAO,CAAE,KAAMA,GAAO,aAAa,KAAM,SAAUA,GAAO,WAAY,EACxE,MAAMU,EAAcV,CAAK,CAC3B,CACF,CAEA,OAAO,QAAQe,EAA2C,CACxD,IAAIZ,EAAyB,CAAC,EAC9B,OAAIY,EAAM,OAAMZ,EAAK,CAAE,GAAGA,EAAI,KAAMY,EAAM,IAAK,GAC3CA,EAAM,KAAIZ,EAAK,CAAE,GAAGA,EAAI,GAAIY,EAAM,EAAG,GACrCA,EAAM,OAAMZ,EAAK,CAAE,GAAGA,EAAI,KAAMY,EAAM,IAAK,GAC3CA,EAAM,QAAOZ,EAAK,CAAE,GAAGA,EAAI,MAAOY,EAAM,KAAM,GAC9CA,EAAM,QAAOZ,EAAK,CAAE,GAAGA,EAAI,MAAOY,EAAM,KAAM,GAC9CA,EAAM,WAAUZ,EAAK,CAAE,GAAGA,EAAI,SAAUY,EAAM,QAAS,GACvDA,EAAM,WACRZ,EAAK,CACH,GAAGA,EACH,SAAU,KAAO,SAASY,EAAM,QAAQ,EAAE,SAAS,EAAE,CACvD,GACEA,EAAM,eAAcZ,EAAK,CAAE,GAAGA,EAAI,aAAcY,EAAM,YAAa,GACnEA,EAAM,uBACRZ,EAAK,CAAE,GAAGA,EAAI,qBAAsBY,EAAM,oBAAqB,GAC1DZ,CACT,CACF,EA1Faa,EAAApB,EAAA",
|
|
6
|
+
"names": ["SignerError", "SignerErrorCode", "providers", "SignerError", "SignerErrorCode", "cleanEvmError", "__name", "error", "message", "SignerError", "SignerErrorCode", "DefaultEvmSigner", "provider", "providers", "msg", "error", "SignerError", "SignerErrorCode", "tx", "address", "chainId", "transaction", "signerChainId", "signerAddress", "response", "cleanEvmError", "txHash", "txResponse", "confirmations", "err", "evmTx", "__name"]
|
|
7
7
|
}
|
package/dist/signer.d.ts
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
|
+
import { TransactionRequest, TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
2
|
import { GenericSigner } from 'rango-types';
|
|
3
3
|
import { EvmTransaction } from 'rango-types/lib/api/main';
|
|
4
4
|
import { providers } from 'ethers';
|
|
5
5
|
export declare class DefaultEvmSigner implements GenericSigner<EvmTransaction> {
|
|
6
6
|
private signer;
|
|
7
|
+
private provider;
|
|
7
8
|
constructor(provider: providers.ExternalProvider);
|
|
8
9
|
signMessage(msg: string): Promise<string>;
|
|
9
|
-
signAndSendTx(tx: EvmTransaction, address: string, chainId: string | null): Promise<
|
|
10
|
+
signAndSendTx(tx: EvmTransaction, address: string, chainId: string | null): Promise<{
|
|
11
|
+
hash: string;
|
|
12
|
+
response: TransactionResponse;
|
|
13
|
+
}>;
|
|
14
|
+
wait(txHash: string, txResponse?: TransactionResponse, confirmations?: number | undefined): Promise<{
|
|
15
|
+
hash: string;
|
|
16
|
+
response?: TransactionResponse;
|
|
17
|
+
}>;
|
|
10
18
|
static buildTx(evmTx: EvmTransaction): TransactionRequest;
|
|
11
19
|
}
|
|
12
20
|
//# sourceMappingURL=signer.d.ts.map
|
package/dist/signer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAgC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGnC,qBAAa,gBAAiB,YAAW,aAAa,CAAC,cAAc,CAAC;IACpE,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,QAAQ,CAAyB;gBAE7B,QAAQ,EAAE,SAAS,CAAC,gBAAgB;IAK1C,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzC,aAAa,CACjB,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,mBAAmB,CAAA;KAAE,CAAC;IA4BrD,IAAI,CACR,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,mBAAmB,EAChC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,GACjC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;KAAE,CAAC;IAmB5D,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,GAAG,kBAAkB;CAkB1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/signer-evm",
|
|
3
|
-
"version": "0.1.15-next.
|
|
3
|
+
"version": "0.1.15-next.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
"lint": "eslint \"**/*.{ts,tsx}\" --ignore-path ../../.eslintignore"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@ethersproject/abstract-provider": "^5.7.0",
|
|
20
21
|
"ethers": "^5.7.2",
|
|
21
|
-
"rango-types": "^0.1.
|
|
22
|
+
"rango-types": "^0.1.38"
|
|
22
23
|
},
|
|
23
24
|
"publishConfig": {
|
|
24
25
|
"access": "public"
|
package/src/helper.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SignerError, SignerErrorCode } from 'rango-types';
|
|
2
|
+
|
|
3
|
+
export const cleanEvmError = (error: any): SignerError => {
|
|
4
|
+
let message = undefined;
|
|
5
|
+
if (
|
|
6
|
+
error &&
|
|
7
|
+
Object.prototype.hasOwnProperty.call(error, 'message') &&
|
|
8
|
+
Object.prototype.hasOwnProperty.call(error, 'code') &&
|
|
9
|
+
Object.prototype.hasOwnProperty.call(error, 'reason')
|
|
10
|
+
) {
|
|
11
|
+
message = `Error sending the tx (code: ${(error as any).code})`;
|
|
12
|
+
} else if (
|
|
13
|
+
error &&
|
|
14
|
+
Object.prototype.hasOwnProperty.call(error, 'code') &&
|
|
15
|
+
Object.prototype.hasOwnProperty.call(error, 'message') &&
|
|
16
|
+
(error as any)?.code === -32603
|
|
17
|
+
) {
|
|
18
|
+
return new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, (error as any).message);
|
|
19
|
+
}
|
|
20
|
+
return new SignerError(SignerErrorCode.SEND_TX_ERROR, message, error);
|
|
21
|
+
};
|
package/src/signer.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { TransactionRequest } from '@ethersproject/abstract-provider';
|
|
1
|
+
import { TransactionRequest, TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
2
|
import { GenericSigner, SignerError, SignerErrorCode } from 'rango-types';
|
|
3
3
|
import { EvmTransaction } from 'rango-types/lib/api/main';
|
|
4
4
|
import { providers } from 'ethers';
|
|
5
|
+
import { cleanEvmError } from './helper';
|
|
5
6
|
|
|
6
7
|
export class DefaultEvmSigner implements GenericSigner<EvmTransaction> {
|
|
7
8
|
private signer: providers.JsonRpcSigner;
|
|
9
|
+
private provider: providers.Web3Provider;
|
|
8
10
|
|
|
9
11
|
constructor(provider: providers.ExternalProvider) {
|
|
10
|
-
this.
|
|
12
|
+
this.provider = new providers.Web3Provider(provider);
|
|
13
|
+
this.signer = this.provider.getSigner();
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
async signMessage(msg: string): Promise<string> {
|
|
@@ -21,8 +24,8 @@ export class DefaultEvmSigner implements GenericSigner<EvmTransaction> {
|
|
|
21
24
|
async signAndSendTx(
|
|
22
25
|
tx: EvmTransaction,
|
|
23
26
|
address: string,
|
|
24
|
-
chainId: string | null
|
|
25
|
-
): Promise<string> {
|
|
27
|
+
chainId: string | null,
|
|
28
|
+
): Promise<{ hash: string; response: TransactionResponse }> {
|
|
26
29
|
try {
|
|
27
30
|
const transaction = DefaultEvmSigner.buildTx(tx);
|
|
28
31
|
const signerChainId = await this.signer.getChainId();
|
|
@@ -34,60 +37,60 @@ export class DefaultEvmSigner implements GenericSigner<EvmTransaction> {
|
|
|
34
37
|
) {
|
|
35
38
|
throw new SignerError(
|
|
36
39
|
SignerErrorCode.UNEXPECTED_BEHAVIOUR,
|
|
37
|
-
`Signer chainId: '${signerChainId}' doesn't match with required chainId: '${chainId}' for tx
|
|
40
|
+
`Signer chainId: '${signerChainId}' doesn't match with required chainId: '${chainId}' for tx.`,
|
|
38
41
|
);
|
|
39
42
|
}
|
|
40
|
-
if (
|
|
41
|
-
!!signerAddress &&
|
|
42
|
-
!!address &&
|
|
43
|
-
signerAddress.toLowerCase() !== address.toLowerCase()
|
|
44
|
-
) {
|
|
43
|
+
if (!!signerAddress && !!address && signerAddress.toLowerCase() !== address.toLowerCase()) {
|
|
45
44
|
throw new SignerError(
|
|
46
45
|
SignerErrorCode.UNEXPECTED_BEHAVIOUR,
|
|
47
|
-
`Signer address: '${signerAddress.toLowerCase()}' doesn't match with required address: '${address.toLowerCase()}' for tx
|
|
46
|
+
`Signer address: '${signerAddress.toLowerCase()}' doesn't match with required address: '${address.toLowerCase()}' for tx.`,
|
|
48
47
|
);
|
|
49
48
|
}
|
|
50
|
-
|
|
49
|
+
const response = await this.signer.sendTransaction(transaction);
|
|
50
|
+
return { hash: response.hash, response };
|
|
51
51
|
} catch (error) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
) {
|
|
66
|
-
throw new SignerError(
|
|
67
|
-
SignerErrorCode.SEND_TX_ERROR,
|
|
68
|
-
undefined,
|
|
69
|
-
(error as any).message
|
|
70
|
-
);
|
|
52
|
+
throw cleanEvmError(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async wait(
|
|
57
|
+
txHash: string,
|
|
58
|
+
txResponse?: TransactionResponse,
|
|
59
|
+
confirmations?: number | undefined,
|
|
60
|
+
): Promise<{ hash: string; response?: TransactionResponse }> {
|
|
61
|
+
try {
|
|
62
|
+
if (txResponse) {
|
|
63
|
+
await txResponse?.wait(confirmations);
|
|
64
|
+
return { hash: txHash };
|
|
71
65
|
}
|
|
72
|
-
|
|
66
|
+
if (!this.provider) return { hash: txHash }; // wallet not connected yet
|
|
67
|
+
const tx = await this.provider.getTransaction(txHash);
|
|
68
|
+
if (!tx) throw Error(`Transaction hash '${txHash}' not found in blockchain.`);
|
|
69
|
+
await tx.wait(confirmations);
|
|
70
|
+
return { hash: txHash };
|
|
71
|
+
} catch (err) {
|
|
72
|
+
const error = err as any; // TODO find a proper type
|
|
73
|
+
if (error?.code === 'TRANSACTION_REPLACED' && error?.replacement)
|
|
74
|
+
return { hash: error?.replacement?.hash, response: error?.replacement };
|
|
75
|
+
throw cleanEvmError(error);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
static buildTx(evmTx: EvmTransaction): TransactionRequest {
|
|
77
80
|
let tx: TransactionRequest = {};
|
|
78
|
-
if (
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
82
|
-
if (
|
|
83
|
-
if (
|
|
84
|
-
if (
|
|
81
|
+
if (evmTx.from) tx = { ...tx, from: evmTx.from };
|
|
82
|
+
if (evmTx.to) tx = { ...tx, to: evmTx.to };
|
|
83
|
+
if (evmTx.data) tx = { ...tx, data: evmTx.data };
|
|
84
|
+
if (evmTx.value) tx = { ...tx, value: evmTx.value };
|
|
85
|
+
if (evmTx.nonce) tx = { ...tx, nonce: evmTx.nonce };
|
|
86
|
+
if (evmTx.gasLimit) tx = { ...tx, gasLimit: evmTx.gasLimit };
|
|
87
|
+
if (evmTx.gasPrice)
|
|
85
88
|
tx = {
|
|
86
89
|
...tx,
|
|
87
90
|
gasPrice: '0x' + parseInt(evmTx.gasPrice).toString(16),
|
|
88
91
|
};
|
|
89
|
-
if (
|
|
90
|
-
if (
|
|
92
|
+
if (evmTx.maxFeePerGas) tx = { ...tx, maxFeePerGas: evmTx.maxFeePerGas };
|
|
93
|
+
if (evmTx.maxPriorityFeePerGas)
|
|
91
94
|
tx = { ...tx, maxPriorityFeePerGas: evmTx.maxPriorityFeePerGas };
|
|
92
95
|
return tx;
|
|
93
96
|
}
|