-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
99 lines (88 loc) · 2.75 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
import { ERC20 } from "./erc20";
import { Contract } from "./contract";
import { Bridge } from "./bridge";
import { BridgeUtil } from "./bridge_util";
import { BridgeClient, setProofApi } from "../utils";
import { IBaseClientConfig, IContracts, IWrappers } from "../interfaces";
import { config as urlConfig } from "../config";
import { service } from "../services";
import { Wrapper } from "./wrapper";
import { AbiItem } from "../types";
export * from "./bridge";
export * from "./bridge_util";
export * from "./wrapper";
export class LxLyClient extends BridgeClient {
wrappers: IWrappers = {};
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 (!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]
} as IContracts;
}
}