@cityofzion/bs-ethereum 1.1.0 → 1.2.1

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.
Files changed (45) hide show
  1. package/dist/BSEthereum.d.ts +2 -2
  2. package/dist/BSEthereum.js +12 -7
  3. package/dist/BitqueryBDSEthereum.d.ts +2 -3
  4. package/dist/BitqueryBDSEthereum.js +34 -50
  5. package/dist/BitqueryEDSEthereum.d.ts +2 -3
  6. package/dist/BitqueryEDSEthereum.js +27 -27
  7. package/dist/GhostMarketNDSEthereum.d.ts +1 -1
  8. package/dist/GhostMarketNDSEthereum.js +23 -11
  9. package/dist/LedgerServiceEthereum.d.ts +4 -2
  10. package/dist/LedgerServiceEthereum.js +13 -5
  11. package/dist/RpcBDSEthereum.d.ts +1 -1
  12. package/dist/RpcBDSEthereum.js +21 -7
  13. package/dist/constants.d.ts +2 -2
  14. package/dist/constants.js +3 -3
  15. package/package.json +6 -5
  16. package/.eslintignore +0 -13
  17. package/.eslintrc.cjs +0 -22
  18. package/.rush/temp/operation/build/all.log +0 -1
  19. package/.rush/temp/operation/build/state.json +0 -3
  20. package/.rush/temp/package-deps_build.json +0 -30
  21. package/.rush/temp/shrinkwrap-deps.json +0 -531
  22. package/CHANGELOG.json +0 -126
  23. package/CHANGELOG.md +0 -68
  24. package/bs-ethereum.build.log +0 -1
  25. package/dist/graphql.d.ts +0 -124
  26. package/dist/graphql.js +0 -160
  27. package/jest.config.ts +0 -13
  28. package/jest.setup.ts +0 -1
  29. package/src/BSEthereum.ts +0 -208
  30. package/src/BitqueryBDSEthereum.ts +0 -231
  31. package/src/BitqueryEDSEthereum.ts +0 -67
  32. package/src/GhostMarketNDSEthereum.ts +0 -125
  33. package/src/LedgerServiceEthereum.ts +0 -44
  34. package/src/RpcBDSEthereum.ts +0 -88
  35. package/src/__tests__/BSEthereum.spec.ts +0 -172
  36. package/src/__tests__/BitqueryBDSEthereum.spec.ts +0 -106
  37. package/src/__tests__/BitqueryEDSEthereum.spec.ts +0 -55
  38. package/src/__tests__/GhostMarketNDSEthereum.spec.ts +0 -49
  39. package/src/__tests__/RpcBDSEthereum.spec.ts +0 -62
  40. package/src/assets/tokens/common.json +0 -8
  41. package/src/constants.ts +0 -36
  42. package/src/graphql.ts +0 -288
  43. package/src/index.ts +0 -6
  44. package/tsconfig.build.json +0 -4
  45. package/tsconfig.json +0 -15
package/CHANGELOG.json DELETED
@@ -1,126 +0,0 @@
1
- {
2
- "name": "@cityofzion/bs-ethereum",
3
- "entries": [
4
- {
5
- "version": "1.1.0",
6
- "tag": "@cityofzion/bs-ethereum_v1.1.0",
7
- "date": "Thu, 04 Apr 2024 19:52:20 GMT",
8
- "comments": {
9
- "minor": [
10
- {
11
- "comment": "Add ledger support"
12
- }
13
- ],
14
- "patch": [
15
- {
16
- "comment": "Change Goerli to Sepolia and call RPC using testnet instead of Bitquery"
17
- }
18
- ],
19
- "dependency": [
20
- {
21
- "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.10.0`"
22
- }
23
- ]
24
- }
25
- },
26
- {
27
- "version": "1.0.4",
28
- "tag": "@cityofzion/bs-ethereum_v1.0.4",
29
- "date": "Mon, 04 Mar 2024 21:53:09 GMT",
30
- "comments": {
31
- "patch": [
32
- {
33
- "comment": "fix wrong calculated fee"
34
- }
35
- ]
36
- }
37
- },
38
- {
39
- "version": "1.0.3",
40
- "tag": "@cityofzion/bs-ethereum_v1.0.3",
41
- "date": "Wed, 28 Feb 2024 17:43:01 GMT",
42
- "comments": {
43
- "patch": [
44
- {
45
- "comment": "Add creator infomations in nft methods return"
46
- }
47
- ],
48
- "dependency": [
49
- {
50
- "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.9.1`"
51
- }
52
- ]
53
- }
54
- },
55
- {
56
- "version": "1.0.2",
57
- "tag": "@cityofzion/bs-ethereum_v1.0.2",
58
- "date": "Tue, 27 Feb 2024 20:29:09 GMT",
59
- "comments": {
60
- "patch": [
61
- {
62
- "comment": "Remove the mining wait in the transfer method to avoid long promises that take time to resolve."
63
- }
64
- ]
65
- }
66
- },
67
- {
68
- "version": "1.0.1",
69
- "tag": "@cityofzion/bs-ethereum_v1.0.1",
70
- "date": "Thu, 22 Feb 2024 16:49:56 GMT",
71
- "comments": {
72
- "patch": [
73
- {
74
- "comment": "Fix getTokenPrices that is returning a wrong price for ETH token address"
75
- }
76
- ]
77
- }
78
- },
79
- {
80
- "version": "1.0.0",
81
- "tag": "@cityofzion/bs-ethereum_v1.0.0",
82
- "date": "Fri, 16 Feb 2024 16:13:22 GMT",
83
- "comments": {
84
- "major": [
85
- {
86
- "comment": "Change bitquery providers to receive apiKey on class initialization"
87
- }
88
- ]
89
- }
90
- },
91
- {
92
- "version": "0.9.1",
93
- "tag": "@cityofzion/bs-ethereum_v0.9.1",
94
- "date": "Tue, 30 Jan 2024 18:26:00 GMT",
95
- "comments": {
96
- "patch": [
97
- {
98
- "comment": "Fixed bug with repeated ETH token in getBalance method"
99
- }
100
- ]
101
- }
102
- },
103
- {
104
- "version": "0.9.0",
105
- "tag": "@cityofzion/bs-ethereum_v0.9.0",
106
- "date": "Tue, 05 Dec 2023 18:42:10 GMT",
107
- "comments": {
108
- "minor": [
109
- {
110
- "comment": "Inserted within the TokenPricesResponse type the token hash"
111
- }
112
- ],
113
- "patch": [
114
- {
115
- "comment": "Fixed issue with the getBalance method that returned negative numbers and the wrong ETH value"
116
- }
117
- ],
118
- "dependency": [
119
- {
120
- "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.9.0`"
121
- }
122
- ]
123
- }
124
- }
125
- ]
126
- }
package/CHANGELOG.md DELETED
@@ -1,68 +0,0 @@
1
- # Change Log - @cityofzion/bs-ethereum
2
-
3
- This log was last generated on Thu, 04 Apr 2024 19:52:20 GMT and should not be manually modified.
4
-
5
- ## 1.1.0
6
- Thu, 04 Apr 2024 19:52:20 GMT
7
-
8
- ### Minor changes
9
-
10
- - Add ledger support
11
-
12
- ### Patches
13
-
14
- - Change Goerli to Sepolia and call RPC using testnet instead of Bitquery
15
-
16
- ## 1.0.4
17
- Mon, 04 Mar 2024 21:53:09 GMT
18
-
19
- ### Patches
20
-
21
- - fix wrong calculated fee
22
-
23
- ## 1.0.3
24
- Wed, 28 Feb 2024 17:43:01 GMT
25
-
26
- ### Patches
27
-
28
- - Add creator infomations in nft methods return
29
-
30
- ## 1.0.2
31
- Tue, 27 Feb 2024 20:29:09 GMT
32
-
33
- ### Patches
34
-
35
- - Remove the mining wait in the transfer method to avoid long promises that take time to resolve.
36
-
37
- ## 1.0.1
38
- Thu, 22 Feb 2024 16:49:56 GMT
39
-
40
- ### Patches
41
-
42
- - Fix getTokenPrices that is returning a wrong price for ETH token address
43
-
44
- ## 1.0.0
45
- Fri, 16 Feb 2024 16:13:22 GMT
46
-
47
- ### Breaking changes
48
-
49
- - Change bitquery providers to receive apiKey on class initialization
50
-
51
- ## 0.9.1
52
- Tue, 30 Jan 2024 18:26:00 GMT
53
-
54
- ### Patches
55
-
56
- - Fixed bug with repeated ETH token in getBalance method
57
-
58
- ## 0.9.0
59
- Tue, 05 Dec 2023 18:42:10 GMT
60
-
61
- ### Minor changes
62
-
63
- - Inserted within the TokenPricesResponse type the token hash
64
-
65
- ### Patches
66
-
67
- - Fixed issue with the getBalance method that returned negative numbers and the wrong ETH value
68
-
@@ -1 +0,0 @@
1
- Invoking: tsc --project tsconfig.build.json
package/dist/graphql.d.ts DELETED
@@ -1,124 +0,0 @@
1
- type BitqueryNetwork = 'ethereum' | 'goerli';
2
- export type BitqueryTransaction = {
3
- block: {
4
- timestamp: {
5
- unixtime: number;
6
- };
7
- height: number;
8
- };
9
- transaction: {
10
- gasValue: number;
11
- hash: string;
12
- };
13
- amount: number;
14
- currency: {
15
- address: string;
16
- tokenType: string;
17
- decimals: number;
18
- symbol: string;
19
- name: string;
20
- };
21
- sender: {
22
- address: string;
23
- };
24
- receiver: {
25
- address: string;
26
- };
27
- entityId: string;
28
- };
29
- type BitQueryGetTransactionsByAddressResponse = {
30
- ethereum: {
31
- sent: BitqueryTransaction[];
32
- received: BitqueryTransaction[];
33
- sentCount: {
34
- count: number;
35
- }[];
36
- receiverCount: {
37
- count: number;
38
- }[];
39
- };
40
- };
41
- type BitQueryGetTransactionsByAddressVariables = {
42
- address: string;
43
- limit: number;
44
- offset: number;
45
- network: BitqueryNetwork;
46
- };
47
- export declare const bitqueryGetTransactionsByAddressQuery: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<BitQueryGetTransactionsByAddressResponse, BitQueryGetTransactionsByAddressVariables>;
48
- type BitQueryGetTransactionResponse = {
49
- ethereum: {
50
- transfers: BitqueryTransaction[];
51
- };
52
- };
53
- type BitQueryGetTransactionVariables = {
54
- hash: string;
55
- network: BitqueryNetwork;
56
- };
57
- export declare const bitqueryGetTransactionQuery: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<BitQueryGetTransactionResponse, BitQueryGetTransactionVariables>;
58
- type BitQueryGetContractResponse = {
59
- ethereum: {
60
- smartContractCalls: {
61
- smartContract: {
62
- address: {
63
- address: string;
64
- };
65
- currency: {
66
- symbol: string;
67
- name: string;
68
- decimals: number;
69
- tokenType: string;
70
- };
71
- };
72
- }[];
73
- };
74
- };
75
- type BitQueryGetTokenInfoVariables = {
76
- hash: string;
77
- network: BitqueryNetwork;
78
- };
79
- export declare const bitqueryGetTokenInfoQuery: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<BitQueryGetContractResponse, BitQueryGetTokenInfoVariables>;
80
- type BitQueryGetBalanceResponse = {
81
- ethereum: {
82
- address: {
83
- balance: number;
84
- balances: {
85
- currency: {
86
- address: string;
87
- symbol: string;
88
- name: string;
89
- decimals: number;
90
- };
91
- value: number;
92
- }[] | null;
93
- }[];
94
- };
95
- };
96
- type BitQueryGetBalanceVariables = {
97
- address: string;
98
- network: BitqueryNetwork;
99
- };
100
- export declare const bitqueryGetBalanceQuery: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<BitQueryGetBalanceResponse, BitQueryGetBalanceVariables>;
101
- type BitQueryGetTokenPricesResponse = {
102
- ethereum: {
103
- dexTrades: {
104
- baseCurrency: {
105
- address: string;
106
- symbol: string;
107
- };
108
- quoteCurrency: {
109
- address: string;
110
- symbol: string;
111
- };
112
- date: {
113
- date: string;
114
- };
115
- quotePrice: number;
116
- }[];
117
- };
118
- };
119
- export type BitQueryGetTokenPricesVariables = {
120
- after: string;
121
- network: BitqueryNetwork;
122
- };
123
- export declare const bitqueryGetPricesQuery: import("@urql/core/dist/urql-core-chunk").TypedDocumentNode<BitQueryGetTokenPricesResponse, BitQueryGetTokenPricesVariables>;
124
- export {};
package/dist/graphql.js DELETED
@@ -1,160 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bitqueryGetPricesQuery = exports.bitqueryGetBalanceQuery = exports.bitqueryGetTokenInfoQuery = exports.bitqueryGetTransactionQuery = exports.bitqueryGetTransactionsByAddressQuery = void 0;
4
- const core_1 = require("@urql/core");
5
- exports.bitqueryGetTransactionsByAddressQuery = (0, core_1.gql) `
6
- query getTransactions($address: String!, $limit: Int!, $offset: Int!, $network: EthereumNetwork!) {
7
- ethereum(network: $network) {
8
- sent: transfers(
9
- options: { limit: $limit, offset: $offset, desc: "block.timestamp.unixtime" }
10
- sender: { is: $address }
11
- ) {
12
- block {
13
- timestamp {
14
- unixtime
15
- }
16
- height
17
- }
18
- amount
19
- currency {
20
- address
21
- tokenType
22
- symbol
23
- decimals
24
- name
25
- }
26
- sender {
27
- address
28
- }
29
- receiver {
30
- address
31
- }
32
- transaction {
33
- gasValue
34
- hash
35
- }
36
- entityId
37
- }
38
- received: transfers(
39
- options: { limit: $limit, offset: $offset, desc: "block.timestamp.unixtime" }
40
- receiver: { is: $address }
41
- ) {
42
- block {
43
- timestamp {
44
- unixtime
45
- }
46
- height
47
- }
48
- amount
49
- currency {
50
- address
51
- tokenType
52
- }
53
- sender {
54
- address
55
- }
56
- receiver {
57
- address
58
- }
59
- transaction {
60
- gasValue
61
- hash
62
- }
63
- entityId
64
- }
65
- sentCount: transfers(sender: { is: $address }) {
66
- count
67
- }
68
- receiverCount: transfers(receiver: { is: $address }) {
69
- count
70
- }
71
- }
72
- }
73
- `;
74
- exports.bitqueryGetTransactionQuery = (0, core_1.gql) `
75
- query getTransaction($hash: String!, $network: EthereumNetwork!) {
76
- ethereum(network: $network) {
77
- transfers(txHash: { is: $hash }) {
78
- block {
79
- timestamp {
80
- unixtime
81
- }
82
- height
83
- }
84
- amount
85
- currency {
86
- address
87
- tokenType
88
- }
89
- sender {
90
- address
91
- }
92
- receiver {
93
- address
94
- }
95
- transaction {
96
- gasValue
97
- hash
98
- }
99
- entityId
100
- }
101
- }
102
- }
103
- `;
104
- exports.bitqueryGetTokenInfoQuery = (0, core_1.gql) `
105
- query getTokenInfo($hash: String!, $network: EthereumNetwork!) {
106
- ethereum(network: $network) {
107
- smartContractCalls(smartContractAddress: { is: $hash }, options: { limit: 1 }) {
108
- smartContract {
109
- address {
110
- address
111
- }
112
- currency {
113
- symbol
114
- name
115
- decimals
116
- tokenType
117
- }
118
- }
119
- }
120
- }
121
- }
122
- `;
123
- exports.bitqueryGetBalanceQuery = (0, core_1.gql) `
124
- query getBalance($address: String!, $network: EthereumNetwork!) {
125
- ethereum(network: $network) {
126
- address(address: { is: $address }) {
127
- balance
128
- balances {
129
- currency {
130
- address
131
- symbol
132
- name
133
- decimals
134
- }
135
- value
136
- }
137
- }
138
- }
139
- }
140
- `;
141
- exports.bitqueryGetPricesQuery = (0, core_1.gql) `
142
- query getPrice($after: ISO8601DateTime!, $network: EthereumNetwork!) {
143
- ethereum(network: $network) {
144
- dexTrades(options: { desc: "date.date" }, time: { after: $after }) {
145
- quoteCurrency(quoteCurrency: { is: "0xdac17f958d2ee523a2206206994597c13d831ec7" }) {
146
- symbol
147
- address
148
- }
149
- baseCurrency {
150
- symbol
151
- address
152
- }
153
- date {
154
- date
155
- }
156
- quotePrice
157
- }
158
- }
159
- }
160
- `;
package/jest.config.ts DELETED
@@ -1,13 +0,0 @@
1
- import { JestConfigWithTsJest } from 'ts-jest'
2
- const config: JestConfigWithTsJest = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'node',
5
- clearMocks: true,
6
- verbose: true,
7
- bail: true,
8
- testMatch: ['<rootDir>/**/*.spec.ts'],
9
- setupFiles: ['<rootDir>/jest.setup.ts'],
10
- detectOpenHandles: true,
11
- }
12
-
13
- export default config
package/jest.setup.ts DELETED
@@ -1 +0,0 @@
1
- import 'dotenv/config'
package/src/BSEthereum.ts DELETED
@@ -1,208 +0,0 @@
1
- import {
2
- Account,
3
- AccountWithDerivationPath,
4
- BSCalculableFee,
5
- BSWithLedger,
6
- BSWithNameService,
7
- BSWithNft,
8
- BlockchainDataService,
9
- BlockchainService,
10
- ExchangeDataService,
11
- Network,
12
- NftDataService,
13
- PartialBy,
14
- Token,
15
- TransferParam,
16
- } from '@cityofzion/blockchain-service'
17
- import { ethers } from 'ethers'
18
- import * as ethersJsonWallets from '@ethersproject/json-wallets'
19
- import * as ethersBytes from '@ethersproject/bytes'
20
- import * as ethersBigNumber from '@ethersproject/bignumber'
21
- import { DEFAULT_URL_BY_NETWORK_TYPE, DERIVATION_PATH, NATIVE_ASSETS, TOKENS } from './constants'
22
- import { BitqueryEDSEthereum } from './BitqueryEDSEthereum'
23
- import { GhostMarketNDSEthereum } from './GhostMarketNDSEthereum'
24
- import { RpcBDSEthereum } from './RpcBDSEthereum'
25
- import { BitqueryBDSEthereum } from './BitqueryBDSEthereum'
26
- import { LedgerServiceEthereum } from './LedgerServiceEthereum'
27
- export class BSEthereum<BSCustomName extends string = string>
28
- implements BlockchainService, BSWithNft, BSWithNameService, BSCalculableFee, BSWithLedger
29
- {
30
- readonly blockchainName: BSCustomName
31
- readonly feeToken: Token
32
- readonly derivationPath: string
33
- private readonly bitqueryApiKey: string
34
-
35
- blockchainDataService!: BlockchainDataService
36
- exchangeDataService!: ExchangeDataService
37
- ledgerService: LedgerServiceEthereum = new LedgerServiceEthereum()
38
- tokens: Token[]
39
- nftDataService!: NftDataService
40
- network!: Network
41
-
42
- constructor(blockchainName: BSCustomName, network: PartialBy<Network, 'url'>, bitqueryApiKey: string) {
43
- this.blockchainName = blockchainName
44
- this.derivationPath = DERIVATION_PATH
45
- this.tokens = TOKENS[network.type]
46
- this.bitqueryApiKey = bitqueryApiKey
47
-
48
- this.feeToken = this.tokens.find(token => token.symbol === 'ETH')!
49
- this.setNetwork(network)
50
- }
51
-
52
- setNetwork(param: PartialBy<Network, 'url'>) {
53
- const network = {
54
- type: param.type,
55
- url: param.url ?? DEFAULT_URL_BY_NETWORK_TYPE[param.type],
56
- }
57
- this.network = network
58
-
59
- if (network.type !== 'mainnet') {
60
- this.blockchainDataService = new RpcBDSEthereum(network)
61
- } else {
62
- this.blockchainDataService = new BitqueryBDSEthereum(network, this.bitqueryApiKey)
63
- }
64
-
65
- this.exchangeDataService = new BitqueryEDSEthereum(network.type, this.bitqueryApiKey)
66
- this.nftDataService = new GhostMarketNDSEthereum(network.type)
67
- }
68
-
69
- validateAddress(address: string): boolean {
70
- return ethers.utils.isAddress(address)
71
- }
72
-
73
- validateEncrypted(json: string): boolean {
74
- return ethersJsonWallets.isCrowdsaleWallet(json) || ethersJsonWallets.isKeystoreWallet(json)
75
- }
76
-
77
- validateKey(key: string): boolean {
78
- try {
79
- if (!key.startsWith('0x')) {
80
- key = '0x' + key
81
- }
82
- if (ethersBytes.hexDataLength(key) !== 32) return false
83
-
84
- return true
85
- } catch (error) {
86
- return false
87
- }
88
- }
89
-
90
- validateNameServiceDomainFormat(domainName: string): boolean {
91
- if (!domainName.endsWith('.eth')) return false
92
- return true
93
- }
94
-
95
- generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath {
96
- const path = this.derivationPath.replace('?', index.toString())
97
- const wallet = ethers.Wallet.fromMnemonic(Array.isArray(mnemonic) ? mnemonic.join(' ') : mnemonic, path)
98
-
99
- return {
100
- address: wallet.address,
101
- key: wallet.privateKey,
102
- type: 'privateKey',
103
- derivationPath: path,
104
- }
105
- }
106
-
107
- generateAccountFromKey(key: string): Account {
108
- const wallet = new ethers.Wallet(key)
109
-
110
- return {
111
- address: wallet.address,
112
- key,
113
- type: 'privateKey',
114
- }
115
- }
116
-
117
- generateAccountFromPublicKey(publicKey: string): Account {
118
- const address = ethers.utils.computeAddress(publicKey)
119
- return {
120
- address,
121
- key: publicKey,
122
- type: 'publicKey',
123
- }
124
- }
125
-
126
- async decrypt(json: string, password: string): Promise<Account> {
127
- const wallet = await ethers.Wallet.fromEncryptedJson(json, password)
128
- return {
129
- address: wallet.address,
130
- key: wallet.privateKey,
131
- type: 'privateKey',
132
- }
133
- }
134
-
135
- async encrypt(key: string, password: string): Promise<string> {
136
- const wallet = new ethers.Wallet(key)
137
- return wallet.encrypt(password)
138
- }
139
-
140
- async transfer(param: TransferParam): Promise<string> {
141
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
142
-
143
- const signTransactionFunction = param.isLedger
144
- ? await this.ledgerService.getSignTransactionFunction(param.ledgerTransport)
145
- : new ethers.Wallet(param.senderAccount.key, provider).signTransaction
146
-
147
- const decimals = param.intent.tokenDecimals ?? 18
148
- const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals)
149
-
150
- let transactionParams: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
151
-
152
- const isNative = NATIVE_ASSETS.some(asset => asset.hash === param.intent.tokenHash)
153
- if (isNative) {
154
- transactionParams = {
155
- to: param.intent.receiverAddress,
156
- value: amount,
157
- }
158
- } else {
159
- const contract = new ethers.Contract(param.intent.tokenHash, [
160
- 'function transfer(address to, uint amount) returns (bool)',
161
- ])
162
- transactionParams = await contract.populateTransaction.transfer(param.intent.receiverAddress, amount)
163
- }
164
-
165
- const voidSigner = new ethers.VoidSigner(param.senderAccount.address, provider)
166
- const transaction = await voidSigner.populateTransaction(transactionParams)
167
-
168
- const signedTransaction = await signTransactionFunction(transaction)
169
- const transactionResponse = await provider.sendTransaction(signedTransaction)
170
- return transactionResponse.hash
171
- }
172
-
173
- async calculateTransferFee({ intent }: TransferParam): Promise<string> {
174
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
175
-
176
- const gasPrice = await provider.getGasPrice()
177
-
178
- let estimated: ethers.BigNumber
179
-
180
- const isNative = NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash)
181
- const decimals = intent.tokenDecimals ?? 18
182
- const amount = ethersBigNumber.parseFixed(intent.amount, decimals)
183
-
184
- if (!isNative) {
185
- const contract = new ethers.Contract(
186
- intent.tokenHash,
187
- ['function transfer(address to, uint amount) returns (bool)'],
188
- provider
189
- )
190
-
191
- estimated = await contract.estimateGas.transfer(intent.receiverAddress, amount)
192
- } else {
193
- estimated = await provider.estimateGas({
194
- to: intent.receiverAddress,
195
- value: amount,
196
- })
197
- }
198
-
199
- return ethers.utils.formatEther(gasPrice.mul(estimated))
200
- }
201
-
202
- async resolveNameServiceDomain(domainName: string): Promise<string> {
203
- const provider = new ethers.providers.JsonRpcProvider(this.network.url)
204
- const address = await provider.resolveName(domainName)
205
- if (!address) throw new Error('No address found for domain name')
206
- return address
207
- }
208
- }