@maticnetwork/fx-portal
Advanced tools
Comparing version 1.0.0-beta.1 to 1.0.4
{ | ||
"name": "@maticnetwork/fx-portal", | ||
"version": "1.0.0-beta.1", | ||
"description": "", | ||
"main": "dist/npm.export.js", | ||
"types": "dist/ts/index.d.ts", | ||
"version": "1.0.4", | ||
"description": "FxPortal for Polygon chain. No mapping. Seamless.", | ||
"main": "index.js", | ||
"scripts": { | ||
"un:matic": "npm un @maticnetwork/maticjs", | ||
"install:matic": "npm i ../matic.js/maticnetwork-maticjs-2.0.45.tgz -D", | ||
"link:maticjs": "npm link @maticnetwork/maticjs", | ||
"build": "npm run build:dev", | ||
"build:link": "npm run build && npm link", | ||
"build:webpack": "npm run lint && webpack --config webpack/webpack.node.config.js", | ||
"build:pack": "npm run build:dev && npm pack", | ||
"build:dev": "cross-env NODE_ENV=development npm run build:webpack", | ||
"build:prod": "cross-env NODE_ENV=production npm run build:webpack", | ||
"deploy": "npm run build:dev && npm run build:prod", | ||
"prepublishOnly": "npm run deploy", | ||
"lint": "tslint src/**/*.ts", | ||
"lint:fix": "tslint src/**/*.ts --fix", | ||
"test": "npm run build:pack && cd test && npm run install:lib:test", | ||
"debug": "npm run build:pack && cd test && npm run install:lib:debug" | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/maticnetwork/fx-portal.js.git" | ||
"url": "git+https://github.com/fx-portal/contracts.git" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"keywords": [ | ||
"ethereum", | ||
"matic" | ||
], | ||
"author": "Jaynti Kanani <jdkanani@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/maticnetwork/fx-portal.js/issues" | ||
"url": "https://github.com/fx-portal/contracts/issues" | ||
}, | ||
"homepage": "https://github.com/maticnetwork/fx-portal.js#readme", | ||
"homepage": "https://github.com/fx-portal/contracts#readme", | ||
"devDependencies": { | ||
"@nomiclabs/hardhat-ethers": "^2.0.1", | ||
"@nomiclabs/hardhat-etherscan": "^2.1.6", | ||
"@nomiclabs/hardhat-waffle": "^2.0.1", | ||
"chai": "^4.2.0", | ||
"dotenv": "^8.2.0", | ||
"ethereum-waffle": "^3.2.1", | ||
"ethers": "^5.0.24", | ||
"hardhat": "^2.0.7" | ||
}, | ||
"dependencies": { | ||
"@maticnetwork/maticjs": "^3.0.0-beta.2" | ||
}, | ||
"devDependencies": { | ||
"copy-webpack-plugin": "^6.1.1", | ||
"cross-env": "^7.0.3", | ||
"dotenv": "^10.0.0", | ||
"ts-loader": "^7.0.1", | ||
"tslint": "^6.1.3", | ||
"typescript": "^3.8.3", | ||
"web3": "^1.5.0", | ||
"webpack": "^4.43.0", | ||
"webpack-cli": "^4.2.0", | ||
"webpack-merge": "^4.2.2" | ||
"@openzeppelin/contracts": "^4.2.0" | ||
} | ||
} |
160
README.md
@@ -1,150 +0,56 @@ | ||
# fx-portal.js | ||
# fx-portal(Flexible portal) | ||
Library for interacting with fx-portal bridge. | ||
FxPortal for Polygon(prev Matic)Chain. No mapping. Seamless communication with Ethereum Network. | ||
> fx-portal is plugin for maticjs. | ||
Audit - [Fx-Portal Contracts Audit by Halborn](https://github.com/fx-portal/contracts/blob/main/Polygon_FX_Portal_Smart_Contract_Security_Audit_Halborn_v1_0%20(1).pdf) | ||
# Installation | ||
### What is Fx bridge (fx-portal)? | ||
``` | ||
npm i @maticnetwork/fx-portal | ||
``` | ||
**It is a powerful yet simple implementation Polygon [state sync](https://docs.matic.network/docs/contribute/state-sync) mechanism. Polygon PoS bridge is based on it. The code in the `examples` folder are examples of the usage of this methodology. You can use these examples to build your own implementations or own custom bridge.** | ||
# DOCS | ||
In short, it's Meta bridge. This bridge allows any state-syncs without mapping. | ||
## Initiate client | ||
#### Some use-cases of Fx-portal | ||
``` | ||
const { use } = require("@maticnetwork/maticjs"); | ||
const { FxPortalPlugin, FxPortalClient } = require("@maticnetwork/fx-portal"); | ||
* [ERC20 token tranfer from Ethereum to Matic-Chain without mapping request](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/erc20-transfer) | ||
* [Lazy minting of ERC20 tokens on MaticChain](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/mintable-erc20-transfer) | ||
* [State Transfer between Ethereum-Matic](https://github.com/jdkanani/fx-portal/tree/main/contracts/examples/state-transfer) | ||
const HDWalletProvider = require("@truffle/hdwallet-provider"); | ||
**What about [PoS portal](https://docs.matic.network/docs/develop/ethereum-matic/pos/getting-started)?** | ||
// add FxPortal Plugin into maticjs | ||
use(FxPortalPlugin); | ||
PoS Portal is another bridge, but it works only for few ERC standards and requires mappings. It is more developer-friendly, allows customization without much headache. | ||
const fxPortalClient = new FxPortalClient({ | ||
network: 'testnet', | ||
version: 'mumbai', | ||
parent: { | ||
provider: new HDWalletProvider(privateKey, rootRPC), | ||
defaultConfig: { | ||
from | ||
} | ||
}, | ||
child: { | ||
provider: new HDWalletProvider(privateKey, childRPC), | ||
defaultConfig: { | ||
from | ||
} | ||
} | ||
}); | ||
While Fx-portal focuses on permissionless-ness and flexibility, a developer might have to write more code but more customizable than PoS Portal. It requires no mapping. | ||
await fxPortalClient.init(); | ||
**Can I build my bridge?** | ||
``` | ||
Yes. You can check docs here: https://docs.matic.network/docs/develop/l1-l2-communication/ethereum-to-matic | ||
https://docs.matic.network/docs/develop/l1-l2-communication/matic-to-ethereum | ||
## ERC20 | ||
### What are FxChild and FxRoot? | ||
Method `erc20` allows you to interact with erc20 token. | ||
`FxChild` (FxChild.sol) and `FxRoot` (FxRoot.sol) are main contracts on which mapping-less bridge works. It calls and passes data to user-defined methods on another chain without mapping. | ||
``` | ||
const erc20 = fxPortalClient.erc20(<tokenAddress>, <isRoot>); | ||
``` | ||
**Mumbai** | ||
### getBalance | ||
| Contract | Deployed address | | ||
| :----- | :- | | ||
| [FxRoot (Goerli)](https://goerli.etherscan.io/address/0x3d1d3E34f7fB6D26245E6640E1c50710eFFf15bA#code) | `0x3d1d3E34f7fB6D26245E6640E1c50710eFFf15bA` | | ||
| [FxChild (Mumbai)](https://explorer-mumbai.maticvigil.com/address/0xCf73231F28B7331BBe3124B907840A94851f9f11/contracts) | `0xCf73231F28B7331BBe3124B907840A94851f9f11`| | ||
Get balance of a user by supplying user address | ||
**Mainnet** | ||
``` | ||
const balance = await erc20.getBalance(<user address>); | ||
``` | ||
### approve | ||
| Contract | Deployed address | | ||
| :----- | :- | | ||
| [FxRoot (Ethereum Mainnet)](https://etherscan.io/address/0xfe5e5d361b2ad62c541bab87c45a0b9b018389a2#code) | `0xfe5e5D361b2ad62c541bAb87C45a0B9B018389a2` | | ||
| [FxChild (Matic Mainnnet)](https://explorer-mainnet.maticvigil.com/address/0x8397259c983751DAf40400790063935a11afa28a/contracts) | `0x8397259c983751DAf40400790063935a11afa28a`| | ||
Approve required amount for depositing to polygon chain | ||
``` | ||
const approveResult = await erc20.approve(<amount>); | ||
const txHash = await approveResult.getTransactionHash(); | ||
const receipt = await approveResult.getReceipt(); | ||
``` | ||
You can deploy your own `FxChild` and `FxRoot`, but no need. Except you want to have some fun and have extra ETH to throw away. | ||
## approveMax | ||
### What can I build with it? | ||
Approve max amount for depositing to polygon chain | ||
``` | ||
const approveResult = await erc20.approveMax(); | ||
const txHash = await approveResult.getTransactionHash(); | ||
const receipt = await approveResult.getReceipt(); | ||
``` | ||
### getAllowance | ||
Get approve amount of a user by supplying user address | ||
``` | ||
const balance = await erc20.getAllowance(<user address>); | ||
``` | ||
## deposit | ||
Deposit required amount from ethereum to polygon | ||
``` | ||
const result = await erc20.deposit(<amount>, <user address>); | ||
const txHash = await result.getTransactionHash(); | ||
const receipt = await result.getReceipt(); | ||
``` | ||
## withdrawStart | ||
Initiate withdraw process by burning the required amount. | ||
``` | ||
const result = await erc20.withdrawStart(<amount>); | ||
const txHash = await result.getTransactionHash(); | ||
const receipt = await result.getReceipt(); | ||
``` | ||
## isCheckPointed | ||
Check if transaction has been checkpointed or not. | ||
``` | ||
await fxPortalClient.isCheckPointed(<tx hash>); | ||
``` | ||
## withdrawExit | ||
Exit withdraw process by providng txHash received in `withdrawStart` process. | ||
**Note:-** `withdrawExit` can be called after checkpoint has been submitted for `withdrawStart`. | ||
``` | ||
const result = await erc20.withdrawExit(<burn tx hash>); | ||
const txHash = await result.getTransactionHash(); | ||
const receipt = await result.getReceipt(); | ||
``` | ||
## isWithdrawExited | ||
Check if withdraw process has been completed by supplying burn transaction hash. | ||
``` | ||
const balance = await erc20.isExited(<burn tx hash>); | ||
``` | ||
## withdrawExitFaster | ||
Faster exit withdraw process by providng txHash received in `withdrawStart` process. | ||
> It is faster because it uses api to create the proof. | ||
``` | ||
const result = await erc20.withdrawExitFaster(<burn tx hash>); | ||
const txHash = await result.getTransactionHash(); | ||
const receipt = await result.getReceipt(); | ||
``` | ||
* Arbitrary state bridge (examples/state-transfer) | ||
* Normal ERC20 bridge (examples/erc2-transfer) | ||
* ERC20 token generator bridge (example/mintable-erc20-transfer) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 11 instances in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8
51
0
1
165906
199
57
16
2
+ Added@openzeppelin/contracts@4.9.6(transitive)
- Removed@maticnetwork/maticjs@^3.0.0-beta.2
- Removed@ethereumjs/block@5.3.0(transitive)
- Removed@ethereumjs/common@4.4.0(transitive)
- Removed@ethereumjs/rlp@5.0.2(transitive)
- Removed@ethereumjs/trie@6.2.1(transitive)
- Removed@ethereumjs/tx@5.4.0(transitive)
- Removed@ethereumjs/util@9.1.0(transitive)
- Removed@maticnetwork/maticjs@3.9.2(transitive)
- Removed@noble/curves@1.4.2(transitive)
- Removed@noble/hashes@1.4.0(transitive)
- Removed@scure/base@1.1.9(transitive)
- Removed@scure/bip32@1.4.0(transitive)
- Removed@scure/bip39@1.3.0(transitive)
- Removed@types/node@22.10.2(transitive)
- Removed@types/readable-stream@2.3.15(transitive)
- Removedassert@2.1.0(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbn.js@5.2.1(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedcall-bound@1.0.3(transitive)
- Removedcomponent-emitter@2.0.0(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedethereum-cryptography@2.2.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.6(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.2.1(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-arguments@1.2.0(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-generator-function@1.0.10(transitive)
- Removedis-nan@1.3.2(transitive)
- Removedis-typed-array@1.1.15(transitive)
- Removedlru-cache@10.1.0(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedms@2.1.3(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.7(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedrlp@3.0.0(transitive)
- Removedsafe-buffer@5.1.25.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedstream@0.0.3(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedutil@0.12.5(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwhich-typed-array@1.1.18(transitive)