@maticnetwork/fx-portal
Advanced tools
Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
@@ -118,5 +118,5 @@ module.exports = | ||
__extends(FxPortalToken, _super); | ||
function FxPortalToken(contractParam, client, exitManager) { | ||
function FxPortalToken(contractParam, client, contracts) { | ||
var _this = _super.call(this, contractParam, client) || this; | ||
_this.exitManager = exitManager; | ||
_this.contracts = contracts; | ||
return _this; | ||
@@ -167,2 +167,116 @@ } | ||
/***/ "./src/contracts/child_tunnel.ts": | ||
/*!***************************************!*\ | ||
!*** ./src/contracts/child_tunnel.ts ***! | ||
\***************************************/ | ||
/*! exports provided: ChildTunnel */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "ChildTunnel", function() { return ChildTunnel; }); | ||
/* harmony import */ var _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @maticnetwork/maticjs */ "@maticnetwork/maticjs"); | ||
/* harmony import */ var _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var ChildTunnel = /** @class */ (function (_super) { | ||
__extends(ChildTunnel, _super); | ||
function ChildTunnel(client, address) { | ||
return _super.call(this, { | ||
isParent: true, | ||
address: address, | ||
name: "FxERC20ChildTunnel", | ||
bridgeType: 'fx-portal' | ||
}, client) || this; | ||
} | ||
return ChildTunnel; | ||
}(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["BaseToken"])); | ||
/***/ }), | ||
/***/ "./src/contracts/index.ts": | ||
/*!********************************!*\ | ||
!*** ./src/contracts/index.ts ***! | ||
\********************************/ | ||
/*! exports provided: RootTunnel, ChildTunnel */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony import */ var _root_tunnel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./root_tunnel */ "./src/contracts/root_tunnel.ts"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RootTunnel", function() { return _root_tunnel__WEBPACK_IMPORTED_MODULE_0__["RootTunnel"]; }); | ||
/* harmony import */ var _child_tunnel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./child_tunnel */ "./src/contracts/child_tunnel.ts"); | ||
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "ChildTunnel", function() { return _child_tunnel__WEBPACK_IMPORTED_MODULE_1__["ChildTunnel"]; }); | ||
/***/ }), | ||
/***/ "./src/contracts/root_tunnel.ts": | ||
/*!**************************************!*\ | ||
!*** ./src/contracts/root_tunnel.ts ***! | ||
\**************************************/ | ||
/*! exports provided: RootTunnel */ | ||
/***/ (function(module, __webpack_exports__, __webpack_require__) { | ||
"use strict"; | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RootTunnel", function() { return RootTunnel; }); | ||
/* harmony import */ var _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @maticnetwork/maticjs */ "@maticnetwork/maticjs"); | ||
/* harmony import */ var _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__); | ||
var __extends = (undefined && undefined.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var RootTunnel = /** @class */ (function (_super) { | ||
__extends(RootTunnel, _super); | ||
function RootTunnel(client, address) { | ||
return _super.call(this, { | ||
isParent: true, | ||
address: address, | ||
name: "FxERC20RootTunnel", | ||
bridgeType: 'fx-portal' | ||
}, client) || this; | ||
} | ||
Object.defineProperty(RootTunnel.prototype, "address", { | ||
get: function () { | ||
return this.contractParam.address; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return RootTunnel; | ||
}(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["BaseToken"])); | ||
/***/ }), | ||
/***/ "./src/enums/index.ts": | ||
@@ -235,37 +349,11 @@ /*!****************************!*\ | ||
__extends(ERC20, _super); | ||
function ERC20(_a, client, exitManager) { | ||
function ERC20(_a, client, contracts) { | ||
var tokenAddress = _a.tokenAddress, isParent = _a.isParent; | ||
return _super.call(this, { | ||
isParent: isParent, | ||
tokenAddress: tokenAddress, | ||
abi: client.getABI('ChildERC20', 'pos') | ||
}, client, exitManager) || this; | ||
address: tokenAddress, | ||
name: 'ChildERC20', | ||
bridgeType: 'pos' | ||
}, client, contracts) || this; | ||
} | ||
Object.defineProperty(ERC20.prototype, "rootTunnel", { | ||
get: function () { | ||
if (!this.rootTunnel_) { | ||
this.rootTunnel_ = this.client.parent.getContract(this.client.config.erc20.rootTunnel, this.client.getABI("FxERC20RootTunnel", "fx-portal")); | ||
} | ||
return this.rootTunnel_; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ERC20.prototype, "childTunnel", { | ||
get: function () { | ||
if (!this.childTunnel_) { | ||
this.childTunnel_ = this.client.child.getContract(this.client.config.erc20.childTunnel, this.client.getABI("FxERC20ChildTunnel", "fx-portal")); | ||
} | ||
return this.childTunnel_; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(ERC20.prototype, "rootTunnelAddress", { | ||
get: function () { | ||
return this.rootTunnel_.address; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
/** | ||
@@ -280,5 +368,7 @@ * get balance by user address | ||
ERC20.prototype.getBalance = function (userAddress, option) { | ||
var contract = this.contract; | ||
var method = contract.method("balanceOf", userAddress); | ||
return this.processRead(method, option); | ||
var _this = this; | ||
return this.getContract().then(function (contract) { | ||
var method = contract.method("balanceOf", userAddress); | ||
return _this.processRead(method, option); | ||
}); | ||
}; | ||
@@ -294,9 +384,10 @@ /** | ||
ERC20.prototype.approve = function (amount, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "approve").throw(); | ||
} | ||
var contract = this.contract; | ||
var rootTunnelcontract = this.rootTunnel; | ||
var method = contract.method("approve", this.rootTunnelAddress, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toUint256(amount)); | ||
return this.processWrite(method, option); | ||
return this.getContract().then(function (contract) { | ||
var method = contract.method("approve", _this.contracts.rootTunnel.address, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toHex(amount)); | ||
return _this.processWrite(method, option); | ||
}); | ||
}; | ||
@@ -322,10 +413,10 @@ /** | ||
ERC20.prototype.getAllowance = function (userAddress, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "getAllowance").throw(); | ||
} | ||
var contract = this.contract; | ||
// call rootTunnel | ||
this.rootTunnel; | ||
var method = contract.method("allowance", userAddress, this.rootTunnelAddress); | ||
return this.processRead(method, option); | ||
return this.getContract().then(function (contract) { | ||
var method = contract.method("allowance", userAddress, _this.contracts.rootTunnel.address); | ||
return _this.processRead(method, option); | ||
}); | ||
}; | ||
@@ -342,8 +433,10 @@ /** | ||
ERC20.prototype.deposit = function (amount, userAddress, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "deposit").throw(); | ||
} | ||
var contract = this.rootTunnel; | ||
var method = contract.method("deposit", this.contractParam.tokenAddress, userAddress, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toUint256(amount), "0x"); | ||
return this.processWrite(method, option); | ||
return this.contracts.rootTunnel.getContract().then(function (contract) { | ||
var method = contract.method("deposit", _this.contractParam.address, userAddress, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toHex(amount), "0x"); | ||
return _this.processWrite(method, option); | ||
}); | ||
}; | ||
@@ -358,8 +451,10 @@ /** | ||
ERC20.prototype.mapChild = function (option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "mapChild").throw(); | ||
} | ||
var contract = this.rootTunnel; | ||
var method = contract.method("mapToken", this.contractParam.tokenAddress); | ||
return this.processWrite(method, option); | ||
return this.contracts.rootTunnel.getContract().then(function (contract) { | ||
var method = contract.method("mapToken", _this.contractParam.address); | ||
return _this.processWrite(method, option); | ||
}); | ||
}; | ||
@@ -375,9 +470,25 @@ /** | ||
ERC20.prototype.withdrawStart = function (amount, option) { | ||
var _this = this; | ||
if (this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnChild, "withdrawStart").throw(); | ||
} | ||
var contract = this.childTunnel; | ||
var method = contract.method("withdraw", this.contractParam.tokenAddress, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toUint256(amount)); | ||
return this.processWrite(method, option); | ||
return this.contracts.childTunnel.getContract().then(function (contract) { | ||
var method = contract.method("withdraw", _this.contractParam.address, _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["Converter"].toHex(amount)); | ||
return _this.processWrite(method, option); | ||
}); | ||
}; | ||
ERC20.prototype.withdrawExit_ = function (burnTransactionHash, isFast, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return Promise.all([ | ||
this.contracts.exitManager.buildPayloadForExit(burnTransactionHash, _enums__WEBPACK_IMPORTED_MODULE_2__["LOG_EVENT_SIGNATURE"].Erc20Transfer, isFast), | ||
this.contracts.rootTunnel.getContract() | ||
]).then(function (result) { | ||
var payload = result[0], contract = result[1]; | ||
var method = contract.method("receiveMessage", payload); | ||
return _this.processWrite(method, option); | ||
}); | ||
}; | ||
/** | ||
@@ -392,11 +503,3 @@ * complete withdraw process after checkpoint has been submitted for the block containing burn tx. | ||
ERC20.prototype.withdrawExit = function (burnTransactionHash, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return this.exitManager.buildPayloadForExit(burnTransactionHash, _enums__WEBPACK_IMPORTED_MODULE_2__["LOG_EVENT_SIGNATURE"].Erc20Transfer, false).then(function (payload) { | ||
var contract = _this.rootTunnel; | ||
var method = contract.method("receiveMessage", payload); | ||
return _this.processWrite(method, option); | ||
}); | ||
return this.withdrawExit_(burnTransactionHash, false, option); | ||
}; | ||
@@ -414,11 +517,3 @@ /** | ||
ERC20.prototype.withdrawExitFaster = function (burnTransactionHash, option) { | ||
var _this = this; | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_0__["ERROR_TYPE"].AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return this.exitManager.buildPayloadForExit(burnTransactionHash, _enums__WEBPACK_IMPORTED_MODULE_2__["LOG_EVENT_SIGNATURE"].Erc20Transfer, true).then(function (payload) { | ||
var contract = _this.rootTunnel; | ||
var method = contract.method("receiveMessage", payload); | ||
return _this.processWrite(method, option); | ||
}); | ||
return this.withdrawExit_(burnTransactionHash, true, option); | ||
}; | ||
@@ -438,5 +533,8 @@ /** | ||
} | ||
return this.exitManager.getExitHash(txHash, _enums__WEBPACK_IMPORTED_MODULE_2__["LOG_EVENT_SIGNATURE"].Erc20Transfer).then(function (exitHash) { | ||
_this.rootTunnel; | ||
var method = _this.rootTunnel.method("processedExits", exitHash); | ||
return Promise.all([ | ||
this.contracts.exitManager.getExitHash(txHash, _enums__WEBPACK_IMPORTED_MODULE_2__["LOG_EVENT_SIGNATURE"].Erc20Transfer), | ||
this.contracts.rootTunnel.getContract() | ||
]).then(function (result) { | ||
var exitHash = result[0], rootTunnel = result[1]; | ||
var method = rootTunnel.method("processedExits", exitHash); | ||
return _this.processRead(method); | ||
@@ -468,2 +566,3 @@ }); | ||
/* harmony import */ var _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__); | ||
/* harmony import */ var _contracts__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./contracts */ "./src/contracts/index.ts"); | ||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -508,28 +607,33 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var FxPortalClient = /** @class */ (function () { | ||
function FxPortalClient(config) { | ||
this.config_ = config; | ||
this.client_ = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["Web3SideChainClient"](config); | ||
this.client_.logger.enableLog(config.log); | ||
} | ||
FxPortalClient.prototype.init = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var config, mainPOSContracts, mainFxPortalContracts, childFxPortalContracts; | ||
var config, client; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
config = this.config_; | ||
this.client_ = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["Web3SideChainClient"](config); | ||
mainPOSContracts = this.client_.mainPOSContracts; | ||
mainFxPortalContracts = this.client_.metaNetwork.Main.FxPortalContracts; | ||
childFxPortalContracts = this.client_.metaNetwork.Matic.FxPortalContracts; | ||
Object.assign(config, { | ||
// rootTunnel: | ||
erc20: { | ||
rootTunnel: mainFxPortalContracts.FxERC20RootTunnel, | ||
childTunnel: childFxPortalContracts.FxERC20ChildTunnel | ||
}, | ||
rootChain: this.client_.mainPlasmaContracts.RootChainProxy | ||
}); | ||
this.rootChain = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["RootChain"](this.client_, config.rootChain); | ||
this.exitManager = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["ExitManager"](this.client_.child, this.rootChain, config.requestConcurrency); | ||
this.client_.logger.enableLog(config.log); | ||
Object(_maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["initService"])(this.client_.metaNetwork.Matic.NetworkAPI); | ||
return [2 /*return*/, this]; | ||
client = this.client_; | ||
return [2 /*return*/, client.init().then(function (_) { | ||
var mainFxPortalContracts = client.abiHelper.getAddress("Main.FxPortalContracts"); | ||
var childFxPortalContracts = client.abiHelper.getAddress("Matic.FxPortalContracts"); | ||
config = Object.assign(config, { | ||
// rootTunnel: | ||
erc20: { | ||
rootTunnel: mainFxPortalContracts.FxERC20RootTunnel, | ||
childTunnel: childFxPortalContracts.FxERC20ChildTunnel | ||
}, | ||
rootChain: _this.client_.mainPlasmaContracts.RootChainProxy | ||
}); | ||
_this.rootChain = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["RootChain"](_this.client_, config.rootChain); | ||
_this.exitManager = new _maticnetwork_maticjs__WEBPACK_IMPORTED_MODULE_2__["ExitManager"](_this.client_.child, _this.rootChain, config.requestConcurrency); | ||
_this.rootTunnel = new _contracts__WEBPACK_IMPORTED_MODULE_3__["RootTunnel"](_this.client_, config.erc20.rootTunnel); | ||
_this.childTunnel = new _contracts__WEBPACK_IMPORTED_MODULE_3__["ChildTunnel"](_this.client_, config.erc20.childTunnel); | ||
return _this; | ||
})]; | ||
}); | ||
@@ -550,3 +654,3 @@ }); | ||
isParent: isParent, | ||
}, this.client_, this.exitManager); | ||
}, this.client_, this.getContracts_()); | ||
}; | ||
@@ -563,2 +667,9 @@ /** | ||
}; | ||
FxPortalClient.prototype.getContracts_ = function () { | ||
return { | ||
exitManager: this.exitManager, | ||
childTunnel: this.childTunnel, | ||
rootTunnel: this.rootTunnel | ||
}; | ||
}; | ||
return FxPortalClient; | ||
@@ -565,0 +676,0 @@ }()); |
@@ -1,2 +0,2 @@ | ||
module.exports=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e){t.exports=require("@maticnetwork/maticjs")},function(t,e,r){"use strict";r.r(e),r.d(e,"FxPortalPlugin",(function(){return i})),r.d(e,"FxPortalClient",(function(){return f}));var n,o,i=function(){function t(){}return t.prototype.setup=function(t){var e;e=t.Web3Client,e},t}(),a=r(0),c=(n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),s=function(t){function e(e,r,n){var o=t.call(this,e,r)||this;return o.exitManager=n,o}return c(e,t),e}(a.BaseToken);!function(t){t.Erc20Transfer="0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036"}(o||(o={}));var u=function(){var t=function(e,r){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(e,r)};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),l=function(t){function e(e,r,n){var o=e.tokenAddress,i=e.isParent;return t.call(this,{isParent:i,tokenAddress:o,abi:r.getABI("ChildERC20","pos")},r,n)||this}return u(e,t),Object.defineProperty(e.prototype,"rootTunnel",{get:function(){return this.rootTunnel_||(this.rootTunnel_=this.client.parent.getContract(this.client.config.erc20.rootTunnel,this.client.getABI("FxERC20RootTunnel","fx-portal"))),this.rootTunnel_},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"childTunnel",{get:function(){return this.childTunnel_||(this.childTunnel_=this.client.child.getContract(this.client.config.erc20.childTunnel,this.client.getABI("FxERC20ChildTunnel","fx-portal"))),this.childTunnel_},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"rootTunnelAddress",{get:function(){return this.rootTunnel_.address},enumerable:!1,configurable:!0}),e.prototype.getBalance=function(t,e){var r=this.contract.method("balanceOf",t);return this.processRead(r,e)},e.prototype.approve=function(t,e){this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"approve").throw();var r=this.contract,n=(this.rootTunnel,r.method("approve",this.rootTunnelAddress,a.Converter.toUint256(t)));return this.processWrite(n,e)},e.prototype.approveMax=function(t){return this.approve(a.MAX_AMOUNT,t)},e.prototype.getAllowance=function(t,e){this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"getAllowance").throw();var r=this.contract;this.rootTunnel;var n=r.method("allowance",t,this.rootTunnelAddress);return this.processRead(n,e)},e.prototype.deposit=function(t,e,r){this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"deposit").throw();var n=this.rootTunnel.method("deposit",this.contractParam.tokenAddress,e,a.Converter.toUint256(t),"0x");return this.processWrite(n,r)},e.prototype.mapChild=function(t){this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"mapChild").throw();var e=this.rootTunnel.method("mapToken",this.contractParam.tokenAddress);return this.processWrite(e,t)},e.prototype.withdrawStart=function(t,e){this.contractParam.isParent&&this.client.logger.error(a.ERROR_TYPE.AllowedOnChild,"withdrawStart").throw();var r=this.childTunnel.method("withdraw",this.contractParam.tokenAddress,a.Converter.toUint256(t));return this.processWrite(r,e)},e.prototype.withdrawExit=function(t,e){var r=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"withdrawExit").throw(),this.exitManager.buildPayloadForExit(t,o.Erc20Transfer,!1).then((function(t){var n=r.rootTunnel.method("receiveMessage",t);return r.processWrite(n,e)}))},e.prototype.withdrawExitFaster=function(t,e){var r=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"withdrawExit").throw(),this.exitManager.buildPayloadForExit(t,o.Erc20Transfer,!0).then((function(t){var n=r.rootTunnel.method("receiveMessage",t);return r.processWrite(n,e)}))},e.prototype.isWithdrawExited=function(t){var e=this;if(!t)throw new Error("txHash not provided");return this.exitManager.getExitHash(t,o.Erc20Transfer).then((function(t){e.rootTunnel;var r=e.rootTunnel.method("processedExits",t);return e.processRead(r)}))},e}(s),h=function(t,e,r,n){return new(r||(r=Promise))((function(o,i){function a(t){try{s(n.next(t))}catch(t){i(t)}}function c(t){try{s(n.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(a,c)}s((n=n.apply(t,e||[])).next())}))},p=function(t,e){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},f=function(){function t(t){this.config_=t}return t.prototype.init=function(){return h(this,void 0,void 0,(function(){var t,e,r;return p(this,(function(n){return t=this.config_,this.client_=new a.Web3SideChainClient(t),this.client_.mainPOSContracts,e=this.client_.metaNetwork.Main.FxPortalContracts,r=this.client_.metaNetwork.Matic.FxPortalContracts,Object.assign(t,{erc20:{rootTunnel:e.FxERC20RootTunnel,childTunnel:r.FxERC20ChildTunnel},rootChain:this.client_.mainPlasmaContracts.RootChainProxy}),this.rootChain=new a.RootChain(this.client_,t.rootChain),this.exitManager=new a.ExitManager(this.client_.child,this.rootChain,t.requestConcurrency),this.client_.logger.enableLog(t.log),Object(a.initService)(this.client_.metaNetwork.Matic.NetworkAPI),[2,this]}))}))},t.prototype.erc20=function(t,e){return new l({tokenAddress:t,isParent:e},this.client_,this.exitManager)},t.prototype.isCheckPointed=function(t){return this.exitManager.isCheckPointed(t)},t}()}]); | ||
module.exports=function(t){var r={};function n(e){if(r[e])return r[e].exports;var o=r[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=r,n.d=function(t,r,e){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var o in t)n.d(e,o,function(r){return t[r]}.bind(null,o));return e},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="",n(n.s=1)}([function(t,r){t.exports=require("@maticnetwork/maticjs")},function(t,r,n){"use strict";n.r(r),n.d(r,"FxPortalPlugin",(function(){return i})),n.d(r,"FxPortalClient",(function(){return _}));var e,o,i=function(){function t(){}return t.prototype.setup=function(t){var r;r=t.Web3Client,r},t}(),a=n(0),c=(e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n])})(t,r)},function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),u=function(t){function r(r,n,e){var o=t.call(this,r,n)||this;return o.contracts=e,o}return c(r,t),r}(a.BaseToken);!function(t){t.Erc20Transfer="0x8c5261668696ce22758910d05bab8f186d6eb247ceac2af2e82c7dc17669b036"}(o||(o={}));var s=function(){var t=function(r,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n])})(r,n)};return function(r,n){function e(){this.constructor=r}t(r,n),r.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}}(),l=function(t){function r(r,n,e){var o=r.tokenAddress,i=r.isParent;return t.call(this,{isParent:i,address:o,name:"ChildERC20",bridgeType:"pos"},n,e)||this}return s(r,t),r.prototype.getBalance=function(t,r){var n=this;return this.getContract().then((function(e){var o=e.method("balanceOf",t);return n.processRead(o,r)}))},r.prototype.approve=function(t,r){var n=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"approve").throw(),this.getContract().then((function(e){var o=e.method("approve",n.contracts.rootTunnel.address,a.Converter.toHex(t));return n.processWrite(o,r)}))},r.prototype.approveMax=function(t){return this.approve(a.MAX_AMOUNT,t)},r.prototype.getAllowance=function(t,r){var n=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"getAllowance").throw(),this.getContract().then((function(e){var o=e.method("allowance",t,n.contracts.rootTunnel.address);return n.processRead(o,r)}))},r.prototype.deposit=function(t,r,n){var e=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"deposit").throw(),this.contracts.rootTunnel.getContract().then((function(o){var i=o.method("deposit",e.contractParam.address,r,a.Converter.toHex(t),"0x");return e.processWrite(i,n)}))},r.prototype.mapChild=function(t){var r=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"mapChild").throw(),this.contracts.rootTunnel.getContract().then((function(n){var e=n.method("mapToken",r.contractParam.address);return r.processWrite(e,t)}))},r.prototype.withdrawStart=function(t,r){var n=this;return this.contractParam.isParent&&this.client.logger.error(a.ERROR_TYPE.AllowedOnChild,"withdrawStart").throw(),this.contracts.childTunnel.getContract().then((function(e){var o=e.method("withdraw",n.contractParam.address,a.Converter.toHex(t));return n.processWrite(o,r)}))},r.prototype.withdrawExit_=function(t,r,n){var e=this;return this.contractParam.isParent||this.client.logger.error(a.ERROR_TYPE.AllowedOnRoot,"withdrawExit").throw(),Promise.all([this.contracts.exitManager.buildPayloadForExit(t,o.Erc20Transfer,r),this.contracts.rootTunnel.getContract()]).then((function(t){var r=t[0],o=t[1].method("receiveMessage",r);return e.processWrite(o,n)}))},r.prototype.withdrawExit=function(t,r){return this.withdrawExit_(t,!1,r)},r.prototype.withdrawExitFaster=function(t,r){return this.withdrawExit_(t,!0,r)},r.prototype.isWithdrawExited=function(t){var r=this;if(!t)throw new Error("txHash not provided");return Promise.all([this.contracts.exitManager.getExitHash(t,o.Erc20Transfer),this.contracts.rootTunnel.getContract()]).then((function(t){var n=t[0],e=t[1].method("processedExits",n);return r.processRead(e)}))},r}(u),p=function(){var t=function(r,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n])})(r,n)};return function(r,n){function e(){this.constructor=r}t(r,n),r.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}}(),f=function(t){function r(r,n){return t.call(this,{isParent:!0,address:n,name:"FxERC20RootTunnel",bridgeType:"fx-portal"},r)||this}return p(r,t),Object.defineProperty(r.prototype,"address",{get:function(){return this.contractParam.address},enumerable:!1,configurable:!0}),r}(a.BaseToken),h=function(){var t=function(r,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)r.hasOwnProperty(n)&&(t[n]=r[n])})(r,n)};return function(r,n){function e(){this.constructor=r}t(r,n),r.prototype=null===n?Object.create(n):(e.prototype=n.prototype,new e)}}(),d=function(t){function r(r,n){return t.call(this,{isParent:!0,address:n,name:"FxERC20ChildTunnel",bridgeType:"fx-portal"},r)||this}return h(r,t),r}(a.BaseToken),y=function(t,r,n,e){return new(n||(n=Promise))((function(o,i){function a(t){try{u(e.next(t))}catch(t){i(t)}}function c(t){try{u(e.throw(t))}catch(t){i(t)}}function u(t){var r;t.done?o(t.value):(r=t.value,r instanceof n?r:new n((function(t){t(r)}))).then(a,c)}u((e=e.apply(t,r||[])).next())}))},w=function(t,r){var n,e,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,e&&(o=2&i[0]?e.return:i[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,i[1])).done)return o;switch(e=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,e=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=r.call(t,a)}catch(t){i=[6,t],e=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},_=function(){function t(t){this.config_=t,this.client_=new a.Web3SideChainClient(t),this.client_.logger.enableLog(t.log)}return t.prototype.init=function(){return y(this,void 0,void 0,(function(){var t,r,n=this;return w(this,(function(e){return t=this.config_,[2,(r=this.client_).init().then((function(e){var o=r.abiHelper.getAddress("Main.FxPortalContracts"),i=r.abiHelper.getAddress("Matic.FxPortalContracts");return t=Object.assign(t,{erc20:{rootTunnel:o.FxERC20RootTunnel,childTunnel:i.FxERC20ChildTunnel},rootChain:n.client_.mainPlasmaContracts.RootChainProxy}),n.rootChain=new a.RootChain(n.client_,t.rootChain),n.exitManager=new a.ExitManager(n.client_.child,n.rootChain,t.requestConcurrency),n.rootTunnel=new f(n.client_,t.erc20.rootTunnel),n.childTunnel=new d(n.client_,t.erc20.childTunnel),n}))]}))}))},t.prototype.erc20=function(t,r){return new l({tokenAddress:t,isParent:r},this.client_,this.getContracts_())},t.prototype.isCheckPointed=function(t){return this.exitManager.isCheckPointed(t)},t.prototype.getContracts_=function(){return{exitManager:this.exitManager,childTunnel:this.childTunnel,rootTunnel:this.rootTunnel}},t}()}]); | ||
//# sourceMappingURL=matic-fx-portal.node.min.js.map |
@@ -1,5 +0,6 @@ | ||
import { BaseToken, IContractInitParam, Web3SideChainClient, ExitManager } from "@maticnetwork/maticjs"; | ||
import { BaseToken, IContractInitParam, Web3SideChainClient } from "@maticnetwork/maticjs"; | ||
import { IFxPortalContracts } from "../interfaces"; | ||
export declare class FxPortalToken extends BaseToken { | ||
protected exitManager: ExitManager; | ||
constructor(contractParam: IContractInitParam, client: Web3SideChainClient, exitManager: ExitManager); | ||
protected contracts: IFxPortalContracts; | ||
constructor(contractParam: IContractInitParam, client: Web3SideChainClient, contracts: IFxPortalContracts); | ||
} |
@@ -1,13 +0,9 @@ | ||
import { Web3SideChainClient, ExitManager, ITransactionOption, TYPE_AMOUNT, BaseContract } from "@maticnetwork/maticjs"; | ||
import { Web3SideChainClient, ITransactionOption, TYPE_AMOUNT } from "@maticnetwork/maticjs"; | ||
import { FxPortalToken } from "../common"; | ||
import { IFxPortalContracts } from "../interfaces"; | ||
export declare class ERC20 extends FxPortalToken { | ||
private rootTunnel_; | ||
private childTunnel_; | ||
constructor({ tokenAddress, isParent }: { | ||
tokenAddress: any; | ||
isParent: any; | ||
}, client: Web3SideChainClient, exitManager: ExitManager); | ||
get rootTunnel(): BaseContract; | ||
get childTunnel(): BaseContract; | ||
get rootTunnelAddress(): string; | ||
}, client: Web3SideChainClient, contracts: IFxPortalContracts); | ||
/** | ||
@@ -75,2 +71,3 @@ * get balance by user address | ||
withdrawStart(amount: TYPE_AMOUNT, option?: ITransactionOption): Promise<import("@maticnetwork/maticjs/dist/ts/helpers").ContractWriteResult>; | ||
private withdrawExit_; | ||
/** | ||
@@ -77,0 +74,0 @@ * complete withdraw process after checkpoint has been submitted for the block containing burn tx. |
@@ -5,2 +5,3 @@ export * from "./plugin"; | ||
import { ExitManager, RootChain } from "@maticnetwork/maticjs"; | ||
import { ChildTunnel, RootTunnel } from "./contracts"; | ||
export declare class FxPortalClient { | ||
@@ -11,2 +12,4 @@ rootChain: RootChain; | ||
private config_; | ||
rootTunnel: RootTunnel; | ||
childTunnel: ChildTunnel; | ||
constructor(config: IFxPortalClientConfig); | ||
@@ -31,2 +34,3 @@ init(): Promise<this>; | ||
isCheckPointed(txHash: string): Promise<boolean>; | ||
private getContracts_; | ||
} |
export * from "./client_config"; | ||
export * from "./fx_portal_contracts"; |
{ | ||
"name": "@maticnetwork/fx-portal", | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"description": "", | ||
@@ -35,3 +35,3 @@ "main": "dist/npm.export.js", | ||
"dependencies": { | ||
"@maticnetwork/maticjs": "^3.0.0-beta.0" | ||
"@maticnetwork/maticjs": "^3.0.0-beta.2" | ||
}, | ||
@@ -38,0 +38,0 @@ "devDependencies": { |
@@ -96,3 +96,3 @@ # fx-portal.js | ||
``` | ||
const result = await erc20.deposit(<amount>); | ||
const result = await erc20.deposit(<amount>, <user address>); | ||
const txHash = await result.getTransactionHash(); | ||
@@ -99,0 +99,0 @@ const receipt = await result.getReceipt(); |
import { BaseToken, RootChainManager, IContractInitParam, Web3SideChainClient, ExitManager } from "@maticnetwork/maticjs"; | ||
import { IFxPortalContracts } from "../interfaces"; | ||
@@ -8,3 +9,3 @@ export class FxPortalToken extends BaseToken { | ||
client: Web3SideChainClient, | ||
protected exitManager: ExitManager | ||
protected contracts: IFxPortalContracts | ||
) { | ||
@@ -11,0 +12,0 @@ super(contractParam, client); |
@@ -1,12 +0,8 @@ | ||
import { Web3SideChainClient, ERROR_TYPE, ExitManager, ITransactionOption, Converter, TYPE_AMOUNT, MAX_AMOUNT, BaseContract } from "@maticnetwork/maticjs"; | ||
import { Web3SideChainClient, ERROR_TYPE, ITransactionOption, Converter, TYPE_AMOUNT, MAX_AMOUNT, BaseContract } from "@maticnetwork/maticjs"; | ||
import { FxPortalToken } from "../common"; | ||
import { LOG_EVENT_SIGNATURE } from "../enums"; | ||
import { IFxPortalClientConfig } from "../interfaces"; | ||
import { IFxPortalClientConfig, IFxPortalContracts } from "../interfaces"; | ||
export class ERC20 extends FxPortalToken { | ||
private rootTunnel_: BaseContract; | ||
private childTunnel_: BaseContract; | ||
constructor( | ||
@@ -18,35 +14,12 @@ { | ||
client: Web3SideChainClient, | ||
exitManager: ExitManager | ||
contracts: IFxPortalContracts | ||
) { | ||
super({ | ||
isParent, | ||
tokenAddress, | ||
abi: client.getABI('ChildERC20', 'pos') | ||
}, client, exitManager); | ||
address: tokenAddress, | ||
name: 'ChildERC20', | ||
bridgeType: 'pos' | ||
}, client, contracts); | ||
} | ||
get rootTunnel() { | ||
if (!this.rootTunnel_) { | ||
this.rootTunnel_ = this.client.parent.getContract( | ||
(this.client.config as IFxPortalClientConfig).erc20.rootTunnel, | ||
this.client.getABI("FxERC20RootTunnel", "fx-portal") | ||
); | ||
} | ||
return this.rootTunnel_; | ||
} | ||
get childTunnel() { | ||
if (!this.childTunnel_) { | ||
this.childTunnel_ = this.client.child.getContract( | ||
(this.client.config as IFxPortalClientConfig).erc20.childTunnel, | ||
this.client.getABI("FxERC20ChildTunnel", "fx-portal") | ||
); | ||
} | ||
return this.childTunnel_; | ||
} | ||
get rootTunnelAddress() { | ||
return this.rootTunnel_.address; | ||
} | ||
/** | ||
@@ -61,8 +34,9 @@ * get balance by user address | ||
getBalance(userAddress: string, option?: ITransactionOption) { | ||
const contract = this.contract; | ||
const method = contract.method( | ||
"balanceOf", | ||
userAddress | ||
); | ||
return this.processRead<string>(method, option); | ||
return this.getContract().then(contract => { | ||
const method = contract.method( | ||
"balanceOf", | ||
userAddress | ||
); | ||
return this.processRead<string>(method, option); | ||
}); | ||
} | ||
@@ -83,11 +57,10 @@ | ||
const contract = this.contract; | ||
const rootTunnelcontract = this.rootTunnel; | ||
const method = contract.method( | ||
"approve", | ||
this.rootTunnelAddress, | ||
Converter.toUint256(amount) | ||
); | ||
return this.processWrite(method, option); | ||
return this.getContract().then(contract => { | ||
const method = contract.method( | ||
"approve", | ||
this.contracts.rootTunnel.address, | ||
Converter.toHex(amount) | ||
); | ||
return this.processWrite(method, option); | ||
}); | ||
} | ||
@@ -122,11 +95,10 @@ | ||
const contract = this.contract; | ||
// call rootTunnel | ||
this.rootTunnel; | ||
const method = contract.method( | ||
"allowance", | ||
userAddress, | ||
this.rootTunnelAddress | ||
); | ||
return this.processRead<string>(method, option); | ||
return this.getContract().then(contract => { | ||
const method = contract.method( | ||
"allowance", | ||
userAddress, | ||
this.contracts.rootTunnel.address | ||
); | ||
return this.processRead<string>(method, option); | ||
}); | ||
} | ||
@@ -148,12 +120,12 @@ | ||
const contract = this.rootTunnel; | ||
const method = contract.method( | ||
"deposit", | ||
this.contractParam.tokenAddress, | ||
userAddress, | ||
Converter.toUint256(amount), | ||
"0x" | ||
); | ||
return this.processWrite(method, option); | ||
return this.contracts.rootTunnel.getContract().then(contract => { | ||
const method = contract.method( | ||
"deposit", | ||
this.contractParam.address, | ||
userAddress, | ||
Converter.toHex(amount), | ||
"0x" | ||
); | ||
return this.processWrite(method, option); | ||
}); | ||
} | ||
@@ -173,8 +145,10 @@ | ||
const contract = this.rootTunnel; | ||
const method = contract.method( | ||
"mapToken", | ||
this.contractParam.tokenAddress | ||
) | ||
return this.processWrite(method, option); | ||
return this.contracts.rootTunnel.getContract().then(contract => { | ||
const method = contract.method( | ||
"mapToken", | ||
this.contractParam.address | ||
) | ||
return this.processWrite(method, option); | ||
}); | ||
} | ||
@@ -195,11 +169,32 @@ | ||
const contract = this.childTunnel; | ||
const method = contract.method( | ||
"withdraw", | ||
this.contractParam.tokenAddress, | ||
Converter.toUint256(amount) | ||
); | ||
return this.processWrite(method, option); | ||
return this.contracts.childTunnel.getContract().then(contract => { | ||
const method = contract.method( | ||
"withdraw", | ||
this.contractParam.address, | ||
Converter.toHex(amount) | ||
); | ||
return this.processWrite(method, option); | ||
}); | ||
} | ||
private withdrawExit_(burnTransactionHash: string, isFast: boolean, option?: ITransactionOption) { | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(ERROR_TYPE.AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return Promise.all([ | ||
this.contracts.exitManager.buildPayloadForExit( | ||
burnTransactionHash, | ||
LOG_EVENT_SIGNATURE.Erc20Transfer, | ||
isFast | ||
), | ||
this.contracts.rootTunnel.getContract() | ||
]).then(result => { | ||
const [payload, contract] = result; | ||
const method = contract.method("receiveMessage", payload) | ||
return this.processWrite(method, option); | ||
}); | ||
} | ||
/** | ||
@@ -214,15 +209,7 @@ * complete withdraw process after checkpoint has been submitted for the block containing burn tx. | ||
withdrawExit(burnTransactionHash: string, option?: ITransactionOption) { | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(ERROR_TYPE.AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return this.exitManager.buildPayloadForExit( | ||
return this.withdrawExit_( | ||
burnTransactionHash, | ||
LOG_EVENT_SIGNATURE.Erc20Transfer, | ||
false | ||
).then(payload => { | ||
const contract = this.rootTunnel; | ||
const method = contract.method("receiveMessage", payload) | ||
return this.processWrite(method, option); | ||
}); | ||
false, | ||
option | ||
) | ||
} | ||
@@ -241,15 +228,7 @@ | ||
withdrawExitFaster(burnTransactionHash: string, option?: ITransactionOption) { | ||
if (!this.contractParam.isParent) { | ||
this.client.logger.error(ERROR_TYPE.AllowedOnRoot, "withdrawExit").throw(); | ||
} | ||
return this.exitManager.buildPayloadForExit( | ||
return this.withdrawExit_( | ||
burnTransactionHash, | ||
LOG_EVENT_SIGNATURE.Erc20Transfer, | ||
true | ||
).then(payload => { | ||
const contract = this.rootTunnel; | ||
const method = contract.method("receiveMessage", payload) | ||
return this.processWrite(method, option); | ||
}); | ||
true, | ||
option | ||
) | ||
} | ||
@@ -269,7 +248,10 @@ | ||
} | ||
return this.exitManager.getExitHash( | ||
txHash, LOG_EVENT_SIGNATURE.Erc20Transfer | ||
).then(exitHash => { | ||
this.rootTunnel; | ||
const method = this.rootTunnel.method("processedExits", exitHash) | ||
return Promise.all([ | ||
this.contracts.exitManager.getExitHash( | ||
txHash, LOG_EVENT_SIGNATURE.Erc20Transfer | ||
), | ||
this.contracts.rootTunnel.getContract() | ||
]).then(result => { | ||
const [exitHash, rootTunnel] = result; | ||
const method = rootTunnel.method("processedExits", exitHash) | ||
return this.processRead<boolean>(method); | ||
@@ -276,0 +258,0 @@ }); |
export * from "./plugin"; | ||
import { ERC20 } from "./erc20"; | ||
import { IFxPortalClientConfig } from "./interfaces"; | ||
import { Web3SideChainClient, initService, ExitManager, RootChain } from "@maticnetwork/maticjs"; | ||
import { IFxPortalClientConfig, IFxPortalContracts } from "./interfaces"; | ||
import { Web3SideChainClient, ExitManager, RootChain } from "@maticnetwork/maticjs"; | ||
import { ChildTunnel, RootTunnel } from "./contracts"; | ||
@@ -15,41 +16,55 @@ export class FxPortalClient { | ||
rootTunnel: RootTunnel; | ||
childTunnel: ChildTunnel; | ||
constructor(config: IFxPortalClientConfig) { | ||
this.config_ = config; | ||
this.client_ = new Web3SideChainClient(config); | ||
this.client_.logger.enableLog(config.log); | ||
} | ||
async init() { | ||
const config = this.config_; | ||
this.client_ = new Web3SideChainClient(config); | ||
const mainPOSContracts = this.client_.mainPOSContracts; | ||
const mainFxPortalContracts = this.client_.metaNetwork.Main.FxPortalContracts; | ||
const childFxPortalContracts = this.client_.metaNetwork.Matic.FxPortalContracts; | ||
let config = this.config_; | ||
const client = this.client_; | ||
Object.assign( | ||
config, | ||
{ | ||
// rootTunnel: | ||
erc20: { | ||
rootTunnel: mainFxPortalContracts.FxERC20RootTunnel, | ||
childTunnel: childFxPortalContracts.FxERC20ChildTunnel | ||
}, | ||
rootChain: this.client_.mainPlasmaContracts.RootChainProxy | ||
} as IFxPortalClientConfig | ||
); | ||
return client.init().then(_ => { | ||
const mainFxPortalContracts = client.abiHelper.getAddress("Main.FxPortalContracts"); | ||
const childFxPortalContracts = client.abiHelper.getAddress("Matic.FxPortalContracts"); | ||
this.rootChain = new RootChain( | ||
this.client_, | ||
config.rootChain, | ||
); | ||
config = Object.assign( | ||
config, | ||
{ | ||
// rootTunnel: | ||
erc20: { | ||
rootTunnel: mainFxPortalContracts.FxERC20RootTunnel, | ||
childTunnel: childFxPortalContracts.FxERC20ChildTunnel | ||
}, | ||
rootChain: this.client_.mainPlasmaContracts.RootChainProxy | ||
} as IFxPortalClientConfig | ||
); | ||
this.exitManager = new ExitManager( | ||
this.client_.child, | ||
this.rootChain, | ||
config.requestConcurrency | ||
); | ||
this.rootChain = new RootChain( | ||
this.client_, | ||
config.rootChain, | ||
); | ||
this.client_.logger.enableLog(config.log); | ||
this.exitManager = new ExitManager( | ||
this.client_.child, | ||
this.rootChain, | ||
config.requestConcurrency | ||
); | ||
initService(this.client_.metaNetwork.Matic.NetworkAPI); | ||
this.rootTunnel = new RootTunnel( | ||
this.client_, | ||
config.erc20.rootTunnel, | ||
); | ||
return this; | ||
this.childTunnel = new ChildTunnel( | ||
this.client_, | ||
config.erc20.childTunnel, | ||
); | ||
return this; | ||
}); | ||
} | ||
@@ -72,3 +87,3 @@ | ||
this.client_, | ||
this.exitManager | ||
this.getContracts_() | ||
); | ||
@@ -89,2 +104,10 @@ } | ||
} | ||
private getContracts_() { | ||
return { | ||
exitManager: this.exitManager, | ||
childTunnel: this.childTunnel, | ||
rootTunnel: this.rootTunnel | ||
} as IFxPortalContracts; | ||
} | ||
} |
@@ -1,1 +0,2 @@ | ||
export * from "./client_config"; | ||
export * from "./client_config"; | ||
export * from "./fx_portal_contracts"; |
@@ -1,4 +0,4 @@ | ||
const { use, BaseToken } = require("@maticnetwork/maticjs"); | ||
const { use } = require("@maticnetwork/maticjs"); | ||
const { Web3ClientPlugin } = require("@maticnetwork/maticjs-web3"); | ||
// return console.log("BaseToken", BaseToken) | ||
@@ -13,2 +13,3 @@ const HDWalletProvider = require("@truffle/hdwallet-provider"); | ||
use(FxPortalPlugin); | ||
use(Web3ClientPlugin); | ||
const from = process.env.FROM || user1.address; | ||
@@ -44,7 +45,8 @@ | ||
const result = await rootTokenErc20.deposit(10, from); | ||
// const result = await rootTokenErc20.mapChild(); | ||
// const result = await mumbaiTokenErc20.withdrawStart(10); | ||
// const txHash = await result.getTransactionHash(); | ||
// console.log("txHash", txHash); | ||
// console.log("receipt", await result.getReceipt()); | ||
const txHash = await result.getTransactionHash(); | ||
console.log("txHash", txHash); | ||
console.log("receipt", await result.getReceipt()); | ||
@@ -57,5 +59,5 @@ // const result = await rootTokenErc20.withdrawExit('0xbb9051c6a55ad82122835dd6b656f62f2bf905452e844172f9d8ba6a98137f8c'); | ||
const isCheckpointed = await mumbaiTokenErc20.isWithdrawExited('0xbb9051c6a55ad82122835dd6b656f62f2bf905452e844172f9d8ba6a98137f8c'); | ||
console.log("isWithdrawExited", isCheckpointed); | ||
// const isCheckpointed = await mumbaiTokenErc20.isWithdrawExited('0xbb9051c6a55ad82122835dd6b656f62f2bf905452e844172f9d8ba6a98137f8c'); | ||
// console.log("isWithdrawExited", isCheckpointed); | ||
// console.log("from", from, mumbaiERC20); | ||
// const balanceRoot = await mumbaiTokenErc20.getBalance(from) | ||
@@ -62,0 +64,0 @@ // console.log('balanceRoot', balanceRoot); |
@@ -23,3 +23,5 @@ { | ||
}, | ||
"dependencies": {} | ||
"dependencies": { | ||
"@maticnetwork/maticjs-web3": "^0.1.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
313296
44
6353