Skip to content

Commit

Permalink
Merge pull request #50 from 0xPolygon/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nitinmittal23 authored Aug 28, 2024
2 parents 4287a9b + 852fa58 commit ec4eaf6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@maticnetwork/lxlyjs",
"version": "2.1.1",
"version": "2.2.1",
"description": "Javascript developer library for interacting with Polygon LxLy Bridge",
"main": "dist/lxly.node.js",
"types": "dist/ts/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/transaction_option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { ITransactionRequestConfig } from "./transaction_config";

export interface ITransactionOption extends ITransactionRequestConfig {
returnTransaction?: boolean;
isRefuel?: boolean;
bridgeIndex?: number;
}
12 changes: 6 additions & 6 deletions src/lxly/bridge_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class BridgeUtil {
return Promise.resolve(result);
}

private getBridgeLogData_(transactionHash: string, networkId: number, isRefuel: boolean) {
private getBridgeLogData_(transactionHash: string, networkId: number, bridgeIndex = 0) {
const client = this.client_.providers[networkId].provider;
return client.getTransactionReceipt(transactionHash)
.then(receipt => {
Expand All @@ -75,7 +75,7 @@ export class BridgeUtil {
throw new Error("Log not found in receipt");
}

const data = logs[isRefuel ? 1 : 0].data;
const data = logs[bridgeIndex].data;
return this.decodedBridgeData_(data, networkId);
});
}
Expand All @@ -91,8 +91,8 @@ export class BridgeUtil {
});
}

getBridgeLogData(transactionHash: string, networkId: number, isRefuel = false) {
return this.getBridgeLogData_(transactionHash, networkId, isRefuel);
getBridgeLogData(transactionHash: string, networkId: number, bridgeIndex = 0) {
return this.getBridgeLogData_(transactionHash, networkId, bridgeIndex);
}

computeGlobalIndex(indexLocal: number, sourceNetworkId: number) {
Expand All @@ -103,8 +103,8 @@ export class BridgeUtil {
}
}

buildPayloadForClaim(transactionHash: string, networkId: number, isRefuel = false) {
return this.getBridgeLogData_(transactionHash, networkId, isRefuel).then((data: IBridgeEventInfo) => {
buildPayloadForClaim(transactionHash: string, networkId: number, bridgeIndex = 0) {
return this.getBridgeLogData_(transactionHash, networkId, bridgeIndex).then((data: IBridgeEventInfo) => {
const {
originNetwork,
originTokenAddress,
Expand Down
4 changes: 2 additions & 2 deletions src/lxly/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export class ERC20 extends Token {
*/
claimCustomERC20(transactionHash: string, sourceNetworkId: number, option?: ITransactionOption) {
return this.bridgeUtil.buildPayloadForClaim(
transactionHash, sourceNetworkId, option.isRefuel || false
transactionHash, sourceNetworkId, option.bridgeIndex || 0
).then((payload: IClaimPayload) => {
return this.bridge.claimMessage(
payload.smtProof,
Expand Down Expand Up @@ -393,7 +393,7 @@ export class ERC20 extends Token {
*/
claimAsset(transactionHash: string, sourceNetworkId: number, option?: ITransactionOption) {
return this.bridgeUtil.buildPayloadForClaim(
transactionHash, sourceNetworkId, option.isRefuel || false
transactionHash, sourceNetworkId, option.bridgeIndex || 0
).then((payload: IClaimPayload) => {
return this.bridge.claimAsset(
payload.smtProof,
Expand Down
15 changes: 10 additions & 5 deletions src/utils/bridge_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ export class BridgeClient {
* check if the bridge is claimable
*
* @param {string} txHash
* @param {string} sourceNetwork
* @param {number} [bridgeIndex=0]
* @returns
* @memberof BridgeClient
*/
isBridgeClaimable(txHash: string, sourceNetwork: number) {
isBridgeClaimable(txHash: string, sourceNetwork: number, bridgeIndex = 0) {
return this.bridgeUtil.getBridgeLogData(
txHash, sourceNetwork
txHash, sourceNetwork, bridgeIndex
).then(result => {
return service.network.getBridgeTransactionDetails(
sourceNetwork,
Expand All @@ -34,14 +36,17 @@ export class BridgeClient {
* check whether deposit is completed
*
* @param {string} txHash
* @param {string} sourceNetwork
* @param {string} destinationNetwork
* @param {string} [bridgeIndex=0]
* @returns
* @memberof BridgeClient
*/
isBridged(txHash: string, sourceNetowrk: number, destinationNetwork: number) {
isBridged(txHash: string, sourceNetwork: number, destinationNetwork: number, bridgeIndex = 0) {
return this.bridgeUtil.getBridgeLogData(
txHash, sourceNetowrk
txHash, sourceNetwork, bridgeIndex
).then(result => {
return this.bridges[destinationNetwork].isClaimed(result.depositCount, sourceNetowrk);
return this.bridges[destinationNetwork].isClaimed(result.depositCount, sourceNetwork);
});
}

Expand Down

0 comments on commit ec4eaf6

Please sign in to comment.