1
1
import { ContractConfig } from '@moonbeam-network/xcm-builder' ;
2
- import {
3
- Address ,
4
- Hash ,
5
- PublicClient ,
6
- WalletClient ,
7
- createPublicClient ,
8
- http ,
9
- } from 'viem' ;
2
+ import { Address , Hash , PublicClient , createPublicClient , http } from 'viem' ;
3
+ import { EvmParachain } from '@moonbeam-network/xcm-types' ;
10
4
import { EvmSigner } from '../../../sdk.interfaces' ;
11
5
import { TransferContractInterface } from '../../contract.interfaces' ;
12
6
import { XTOKENS_ABI } from './XtokensABI' ;
@@ -15,39 +9,36 @@ export class Xtokens implements TransferContractInterface {
15
9
readonly defaultMoonChainAddress =
16
10
'0x0000000000000000000000000000000000000804' ;
17
11
18
- readonly address : Address ;
12
+ readonly address : string ;
19
13
20
14
readonly #config: ContractConfig ;
21
15
22
16
readonly #publicClient: PublicClient ;
23
17
24
- readonly #walletClient: WalletClient ;
25
-
26
- constructor ( config : ContractConfig , signer : EvmSigner , address ?: Address ) {
18
+ constructor ( config : ContractConfig , chain : EvmParachain , address ?: string ) {
27
19
this . #config = config ;
28
20
this . address = address ?? this . defaultMoonChainAddress ;
29
- this . #walletClient = signer ;
30
21
this . #publicClient = createPublicClient ( {
31
- chain : signer . chain ,
22
+ chain : chain . getViemChain ( ) ,
32
23
transport : http ( ) ,
33
24
} ) ;
34
25
}
35
26
36
- async transfer ( ) : Promise < Hash > {
27
+ async transfer ( signer : EvmSigner ) : Promise < Hash > {
37
28
const { request } = await this . #publicClient. simulateContract ( {
38
29
abi : XTOKENS_ABI ,
39
- account : this . #walletClient . account ,
40
- address : this . address ,
30
+ account : signer . account ,
31
+ address : this . address as Address ,
41
32
// eslint-disable-next-line @typescript-eslint/no-explicit-any
42
33
args : this . #config. args as any ,
43
34
functionName : this . #config. func as 'transfer' ,
44
35
} ) ;
45
- const hash = await this . #walletClient . writeContract ( request ) ;
36
+ const hash = await signer . writeContract ( request ) ;
46
37
47
38
return hash ;
48
39
}
49
40
50
- async getFee ( amount : bigint ) : Promise < bigint > {
41
+ async getFee ( amount : bigint , address : string ) : Promise < bigint > {
51
42
if ( amount === 0n ) {
52
43
return 0n ;
53
44
}
@@ -59,8 +50,8 @@ export class Xtokens implements TransferContractInterface {
59
50
try {
60
51
const gas = await this . #publicClient. estimateContractGas ( {
61
52
abi : XTOKENS_ABI ,
62
- account : this . #walletClient . account ,
63
- address : this . address ,
53
+ account : address as Address ,
54
+ address : this . address as Address ,
64
55
// eslint-disable-next-line @typescript-eslint/no-explicit-any
65
56
args : this . #config. args as any ,
66
57
functionName : this . #config. func as 'transfer' ,
0 commit comments