Skip to content

Commit

Permalink
Merge pull request #2 from 0xPolygon/rmv-files
Browse files Browse the repository at this point in the history
fix: global Index logic
  • Loading branch information
nitinmittal23 authored Feb 14, 2024
2 parents c37d543 + ad67672 commit 3318a84
Show file tree
Hide file tree
Showing 8 changed files with 2,254 additions and 2,453 deletions.
4,439 changes: 2,179 additions & 2,260 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@
"node-fetch": "^2.6.1"
},
"devDependencies": {
"@types/node-fetch": "^2.5.12",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/parser": "^7.0.1",
"copy-webpack-plugin": "^6.1.1",
"cross-env": "^7.0.3",
"husky": "2.4.1",
"husky": "^9.0.11",
"lint-staged": "8.2.1",
"rimraf": "^3.0.2",
"smart-banner-webpack-plugin": "^3.0.1",
"ts-loader": "^8.0.0",
"tslint": "^6.1.3",
Expand Down
1 change: 1 addition & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const DAI_PERMIT_TYPEHASH = "0xea2aa0a1be11a07ed86d755c93467f4f82362b4523
export const EIP_2612_PERMIT_TYPEHASH = "0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9";
export const EIP_2612_DOMAIN_TYPEHASH = "0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f";
export const UNISWAP_DOMAIN_TYPEHASH = "0x8cad95687ba82c2ce50e74f7b754645e5117c3a5bec8151c0726d5857980a866";
export const _GLOBAL_INDEX_MAINNET_FLAG = BigInt(2 ** 64);
export enum Permit {
DAI = "DAI",
EIP_2612 = "EIP_2612",
Expand Down
118 changes: 8 additions & 110 deletions src/lxly/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,62 +55,12 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
});
}

/**
* Claim function to be called on the destination network
*
* @param {string[]} smtProof Merkle Proof
* @param {number} index Deposit Index
* @param {string} mainnetExitRoot Mainnet Exit Root
* @param {string} rollupExitRoot RollUP Exit Root
* @param {number} originNetwork Network at which token was initially deployed
* @param {string} originTokenAddress Address of token at network where token was initially deployed
* @param {string} destinationAddress Address to which tokens will be bridged
* @param {TYPE_AMOUNT} amount amount of tokens
* @param {string} [metadata] Metadata of token
* @param {ITransactionOption} [option]
*
* @returns
* @memberof Bridge
*/
claimAsset(
smtProof: string[],
index: number,
mainnetExitRoot: string,
rollupExitRoot: string,
originNetwork: number,
originTokenAddress: string,
destinationNetwork: number,
destinationAddress: string,
amount: TYPE_AMOUNT,
metadata: string,
option: ITransactionOption
) {
return this.method(
"claimAsset",
smtProof,
index,
mainnetExitRoot,
rollupExitRoot,
originNetwork,
originTokenAddress,
destinationNetwork,
destinationAddress,
amount,
metadata
).then(method => {
return this.processWrite(
method,
option
);
});
}

/**
* Claim function to be called on the destination network
*
* @param {string[]} smtProof Merkle Proof
* @param {string[]} smtProofRollup Roll up Merkle Proof
* @param {number} index Deposit Index
* @param {string} globalIndex Global Index
* @param {string} mainnetExitRoot Mainnet Exit Root
* @param {string} rollupExitRoot RollUP Exit Root
* @param {number} originNetwork Network at which token was initially deployed
Expand All @@ -123,10 +73,10 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
* @returns
* @memberof Bridge
*/
claimAssetNew(
claimAsset(
smtProof: string[],
smtProofRollup: string[],
index: number,
globalIndex: string,
mainnetExitRoot: string,
rollupExitRoot: string,
originNetwork: number,
Expand All @@ -141,7 +91,7 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
"claimAsset",
smtProof,
smtProofRollup,
index,
globalIndex,
mainnetExitRoot,
rollupExitRoot,
originNetwork,
Expand Down Expand Up @@ -187,66 +137,14 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
});
}


/**
* Claim Message function to be called on the destination network
* If the receiving address is an EOA, the call will result as a success
* Which means that the amount of ether will be transferred correctly, but the message
* will not trigger any execution
* @param {string[]} smtProof Merkle Proof
* @param {number} index Deposit Index
* @param {string} mainnetExitRoot Mainnet Exit Root
* @param {string} rollupExitRoot RollUP Exit Root
* @param {number} originNetwork Network at which token was initially deployed
* @param {string} originTokenAddress Address of token at network where token was initially deployed
* @param {string} destinationAddress Address to which tokens will be bridged
* @param {TYPE_AMOUNT} amount amount of tokens
* @param {string} [metadata] Metadata of token
* @param {ITransactionOption} [option]
*
* @returns
* @memberof Bridge
*/
claimMessage(
smtProof: string[],
index: number,
mainnetExitRoot: string,
rollupExitRoot: string,
originNetwork: number,
originTokenAddress: string,
destinationNetwork: number,
destinationAddress: string,
amount: TYPE_AMOUNT,
metadata: string,
option: ITransactionOption) {
return this.method(
"claimMessage",
smtProof,
index,
mainnetExitRoot,
rollupExitRoot,
originNetwork,
originTokenAddress,
destinationNetwork,
destinationAddress,
amount,
metadata
).then(method => {
return this.processWrite(
method,
option
);
});
}

/**
* Claim Message new function to be called on the destination network
* If the receiving address is an EOA, the call will result as a success
* Which means that the amount of ether will be transferred correctly, but the message
* will not trigger any execution. this will work after Etrog changes
* @param {string[]} smtProof Merkle Proof
* @param {string[]} smtProofRollup Roll up Merkle Proof
* @param {number} index Deposit Index
* @param {string} globalIndex Global Index
* @param {string} mainnetExitRoot Mainnet Exit Root
* @param {string} rollupExitRoot RollUP Exit Root
* @param {number} originNetwork Network at which token was initially deployed
Expand All @@ -259,10 +157,10 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
* @returns
* @memberof Bridge
*/
claimMessageNew(
claimMessage(
smtProof: string[],
smtProofRollup: string[],
index: number,
globalIndex: string,
mainnetExitRoot: string,
rollupExitRoot: string,
originNetwork: number,
Expand All @@ -276,7 +174,7 @@ export class Bridge extends BaseToken<IBaseClientConfig> {
"claimMessage",
smtProof,
smtProofRollup,
index,
globalIndex,
mainnetExitRoot,
rollupExitRoot,
originNetwork,
Expand Down
24 changes: 16 additions & 8 deletions src/lxly/bridge_util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Web3SideChainClient } from "../utils";
import { service } from "../services";
import { IBaseClientConfig } from "..";
import { IBaseClientConfig, _GLOBAL_INDEX_MAINNET_FLAG } from "..";
import { TYPE_AMOUNT } from '../types';

interface IBridgeEventInfo {
export interface IBridgeEventInfo {
originNetwork: number;
originTokenAddress: string;
destinationNetwork: number;
Expand All @@ -13,7 +13,7 @@ interface IBridgeEventInfo {
depositCount: number;
}

interface IMerkleProof {
export interface IMerkleProof {
merkle_proof: string[];
rollup_merkle_proof?: string[];
exit_root_num: string;
Expand All @@ -22,10 +22,10 @@ interface IMerkleProof {
rollup_exit_root: string;
}

interface IClaimPayload {
export interface IClaimPayload {
smtProof: string[];
smtProofRollup?: string[];
index: number;
globalIndex: string;
mainnetExitRoot: string;
rollupExitRoot: string;
originNetwork: number;
Expand Down Expand Up @@ -95,8 +95,16 @@ export class BridgeUtil {
return this.getBridgeLogData_(transactionHash, networkId, isRefuel);
}

computeGlobalIndex(indexLocal: number, indexRollup: number, sourceNetworkId: number) {
if (sourceNetworkId === 0) {
return BigInt(indexLocal) + _GLOBAL_INDEX_MAINNET_FLAG;
} else {
return BigInt(indexLocal) + BigInt(indexRollup) * BigInt(2 ** 32);
}
}

buildPayloadForClaim(transactionHash: string, networkId: number, isRefuel = false) {
return this.getBridgeLogData_(transactionHash, networkId, isRefuel).then(data => {
return this.getBridgeLogData_(transactionHash, networkId, isRefuel).then((data: IBridgeEventInfo) => {
const {
originNetwork,
originTokenAddress,
Expand All @@ -105,11 +113,11 @@ export class BridgeUtil {
amount,
metadata,
depositCount } = data;
return this.getProof_(networkId, depositCount).then(proof => {
return this.getProof_(networkId, depositCount).then((proof: IMerkleProof) => {
const payload = {} as IClaimPayload;
payload.smtProof = proof.merkle_proof;
payload.smtProofRollup = proof.rollup_merkle_proof;
payload.index = depositCount;
payload.globalIndex = this.computeGlobalIndex(depositCount, destinationNetwork, networkId).toString();
payload.mainnetExitRoot = proof.main_exit_root;
payload.rollupExitRoot = proof.rollup_exit_root;
payload.originNetwork = originNetwork;
Expand Down
Loading

0 comments on commit 3318a84

Please sign in to comment.