-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
122 lines (109 loc) · 3.67 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { ERC20 } from "./erc20";
import { Contract } from "./contract";
import { Bridge } from "./bridge";
import { BridgeUtil } from "./bridge_util";
import { BridgeExtension } from "./bridge_extension";
import { BridgeClient, setProofApi } from "../utils";
import { IBaseClientConfig, IContracts, IWrappers, IGasPorters } from "../interfaces";
import { config as urlConfig } from "../config";
import { service } from "../services";
import { Wrapper } from "./wrapper";
import { AbiItem } from "../types";
import { GasPorter } from "./gas_porter";
export * from "./bridge";
export * from "./bridge_util";
export * from "./wrapper";
export * from "./bridge_extension";
export * from "./gas_porter";
export class LxLyClient extends BridgeClient {
wrappers: IWrappers = {};
gasPorters: IGasPorters = {};
init(config: IBaseClientConfig) {
const client = this.client;
return client.init(config).then(_ => {
for (const [key, value] of Object.entries(config.providers)) {
if (value.configuration.bridgeAddress) {
this.bridges[key] = new Bridge(
this.client,
value.configuration.bridgeAddress,
Number(key)
);
}
if (value.configuration.wrapperAddress) {
this.wrappers[key] = new Wrapper(
this.client,
value.configuration.wrapperAddress,
Number(key)
);
}
if (value.configuration.bridgeExtensionAddress) {
this.bridgeExtensions[key] = new BridgeExtension(
this.client,
value.configuration.bridgeExtensionAddress,
Number(key)
);
}
if (value.configuration.gasPorterAddress) {
this.gasPorters[key] = new GasPorter(
this.client,
value.configuration.gasPorterAddress,
Number(key)
);
}
}
if (!service.network) {
setProofApi(urlConfig.BridgeService[config.network]);
}
this.bridgeUtil = new BridgeUtil(
this.client
);
return this;
});
}
/**
* creates instance of ERC20 token
*
* @param {string} tokenAddress
* @param {boolean} isParent
*
* @param bridgeAdapterAddress Needed if a custom erc20 token is being bridged
* @returns
* @memberof ERC20
*/
erc20(tokenAddress: string, networkId: number, bridgeAdapterAddress?: string) {
return new ERC20(
tokenAddress,
networkId,
bridgeAdapterAddress,
this.client,
this.getContracts_.bind(this)
);
}
/**
* creates instance of ERC20 token
*
* @param {AbiItem[]} abi
* @param {string} tokenAddress
* @param {number} networkId
*
* @returns
* @memberof Contract
*/
contract(abi: AbiItem[], tokenAddress: string, networkId: number) {
return new Contract(
abi,
tokenAddress,
networkId,
this.client,
);
}
private getContracts_(networkId) {
return {
bridge: this.bridges[networkId],
bridgeUtil: this.bridgeUtil,
wrapper: this.wrappers[networkId],
bridgeExtension: this.bridgeExtensions[networkId],
gasPorter: this.gasPorters[networkId]
} as IContracts;
}
}